#include<bits/stdc++.h>
using namespace std;
int main() {
cout << "fahr = 100, celsius = " << (int)(5 * (100 - 32) / 9);
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int x[]={7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
char m[]={'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'};
bool flag = true;
string s;
int n;
bool check(string& s, int res = 0) {
for(int i = 0; i < 17; ++i) {
if(!isdigit(s[i])) return false;
res += (s[i] - '0') * x[i];
}
return m[res % 11] == s[17];
}
int main() {
cin >> n;
while(n--) {
cin >> s;
if(!check(s)) {
cout << s << endl;
flag = false;
}
}
if(flag) {
cout << "All passed";
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int n, k;
unordered_set<string> st;
string s;
int main() {
cin >> n;
for(int i = 0; i < n; ++i) {
cin >> k;
for(int j = 0; j < k; ++j) {
cin >> s;
if(k > 1) st.insert(s);
}
}
cin >> n;
k = 0;
for(int i = 0; i < n; ++i) {
cin >> s;
if(!st.count(s)) {
cout << (k++ ? " " : "") << s;
st.insert(s);
}
}
if(!k) cout << "No one is handsome";
return 0;
}
#include<bits/stdc++.h>
using namespace std;
string s;
unordered_map<char, int> mp;
int cnt, i;
char f[5] = "GPLT";
int main() {
cin >> s;
for(auto& x : s) {
x = toupper(x);
++mp[x];
if(x == 'G' || x == 'P' || x == 'L' || x == 'T') ++cnt;
}
while(cnt > 0) {
if(mp[f[i]] > 0) {
cout << f[i];
--mp[f[i]];
--cnt;
}
++i;
if(i >= 4) {
i = 0;
}
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
long long n, x;
string check(long long x) {
if(x < 2) return "No\n";
for(int i = 2; i <= sqrt(x); ++i) {
if(!(x % i)) {
return "No\n";
}
}
return "Yes\n";
}
int main() {
cin >> n;
while(n--) {
cin >> x;
cout << check(x);
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
double n, h;
char c;
int main() {
cin >> n;
for(int i = 0; i < n; ++i) {
cin >> c >> h;
printf("%.2f\n", (c == 'M' ? h / 1.09 : h * 1.09));
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
long long n, maxx, flag;
int main() {
cin >> n;
for(int i = 2; i <= sqrt(n); ++i) {
if(n % i) continue;
long long now = n, check = 0, j = i;
while(!(now % j)) {
now /= j;
++check, ++j;
}
if(check > maxx) {
maxx = check, flag = i;
}
}
if(maxx) {
cout << maxx << endl;
for(int i = 0; i < maxx; ++i) {
cout << (i ? "*" : "") << flag + i;
}
} else {
cout << 1 << endl << n;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int y, n;
int main() {
cin >> y >> n;
for(int i = y;;++i) {
unordered_set<char> st;
string s = to_string(i);
if(s.length() < 4) st.insert('0');
for(auto& x : s) {
st.insert(x);
}
if((int)st.size() == n) {
cout << i - y << " ";
printf("%04d", i);
break;
}
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int n, m, u, v, last_cnt, last;
bool vis[505];
int mp[505][505];
void dfs(int x) {
vis[x] = true;
for(int i = 0; i < n; ++i) {
if(mp[x][i] && !vis[i]) dfs(i);
}
}
int main() {
cin >> n >> m;
last = n;
while(m--) {
cin >> u >> v;
mp[u][v] = mp[v][u] = 1;
}
for(int i = 0; i < n; ++i) {
if(!vis[i]) {
dfs(i), ++last_cnt;
}
}
cin >> m;
while(m--) {
cin >> u;
--last;
for(int i = 0; i < n; ++i) {
if(mp[u][i]) {
mp[u][i] = mp[i][u] = 0;
}
vis[i] = false;
}
int cnt = 0;
for(int i = 0; i < n; ++i) {
if(!vis[i]) {
dfs(i), ++cnt;
}
}
if(last_cnt + 1 < cnt) {
printf("Red Alert: City %d is lost!\n", u);
} else {
printf("City %d is lost.\n", u);
}
last_cnt = cnt;
}
if(!last) {
puts("Game Over.");
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int n, m, k, x, a, b;
string s;
double relationship[1005][1005], max_a, max_b;
int photo[505];
vector<int> sex(1005, -1);
vector<int> ans_a, ans_b;
int main(){
scanf("%d%d", &n, &m);
while(m--) {
scanf("%d", &k);
for(int i = 0; i < k; ++i) {
cin >> s;
x = fabs(stoi(s));
sex[x] = (s[0] == '-' ? 1 : 0);
photo[i] = x;
}
for(int i = 0; i < k; ++i) {
for(int j = i + 1; j < k; ++j) {
if(sex[photo[i]] ^ sex[photo[j]]) {
relationship[photo[i]][photo[j]] += 1.0 / k;
relationship[photo[j]][photo[i]] += 1.0 / k;
}
}
}
}
scanf("%d%d", &a, &b);
int na = fabs(a), nb = fabs(b);
for(int i = 0; i < n; ++i) {
if(relationship[na][i] > max_a) {
ans_a.clear();
ans_a.emplace_back(i);
max_a = relationship[na][i];
} else if(relationship[na][i] == max_a) {
ans_a.emplace_back(i);
}
if(relationship[nb][i] > max_b) {
ans_b.clear();
ans_b.emplace_back(i);
max_b = relationship[nb][i];
} else if(relationship[nb][i] == max_b) {
ans_b.emplace_back(i);
}
}
if(relationship[na][nb] == max_a && relationship[na][nb] == max_b) {
if(sex[na]) printf("-");
printf("%d ", na);
if(sex[nb]) printf("-");
printf("%d", nb);
} else {
for(auto& x : ans_a) {
if(sex[na]) printf("-");
printf("%d ", na);
if(sex[x]) printf("-");
printf("%d\n", x);
}
for(auto& x : ans_b) {
if(sex[nb]) printf("-");
printf("%d ", nb);
if(sex[x]) printf("-");
printf("%d\n", x);
}
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int n, m, k, x, last = INT_MAX;
queue<int> ans;
deque<int> lt;
stack<int> st;
void print(int cnt = 0) {
while(!ans.empty()) {
cout << (cnt++ ? " " : "") << ans.front();
ans.pop();
}
putchar('\n');
last = INT_MAX;
}
int main() {
cin >> n >> m >> k;
while(n--) {
cin >> x;
lt.push_back(x);
}
while(!lt.empty() || !st.empty()) {
if(!st.empty() && st.top() <= last) {
ans.push(st.top());
last = st.top();
st.pop();
if(ans.size() == k) print();
} else {
if(lt.empty()) {
print();
} else {
x = lt.front();
lt.pop_front();
if(x <= last) {
ans.push(x);
last = x;
if(ans.size() == k) print();
} else {
if(st.size() < m) {
st.push(x);
} else {
print();
lt.push_front(x);
}
}
}
}
}
if(!ans.empty()) print();
return 0;
}
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<int> a[N];
unordered_map<int, int> mp;
int n, m, k, x, now = 1;
int main() {
cin >> n >> m;
for(int i = 1; i <= n; ++i) {
cin >> k;
for(int j = 1; j <= k; ++j) {
cin >> x;
a[i].push_back(x);
}
}
while(m--) {
cin >> k >> x;
if(k == 0) {
now = a[now][x - 1];
} else if(k == 1) {
mp[x] = now;
cout << now << endl;
} else {
now = mp[x];
}
}
cout << now;
return 0;
}