akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define ppb pop_back
#define vll vector<ll>
#define vi vector<int>
#define endl "\n"

const ll INF = 1000000007;

/*
const int max_size = 100001;
int parent[max_size];
int Size[max_size];

int root(int x){
	while(x!=parent[x]){
		parent[x] = parent[parent[x]];
		x = parent[x];
	}
	return x;
}

void sunion(int x,int y){
	int rx = root(x);
	int ry = root(y);
	if(rx != ry){
		if(Size[rx] > Size[ry]){
			parent[ry] = parent[rx];
			Size[rx] += Size[ry];
		}
		else{
			parent[rx] = parent[ry];
			Size[ry] += Size[rx];
		}
	}
}
*/

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1;
	//cin >> t;
	while(t--){
		string s;
		cin >> s;
		for(int i=0;i<3;i++){
			if(s[i] == '7'){
				cout << "Yes\n";
				return 0;
			}
		}
		cout << "No\n";
	}
	return 0;
}


Measured memory_bytes: 3652
from sys import stdin
A,B = [int(x) for x in stdin.readline().rstrip().split()]
f = False
if A % 3 == 0:
    f = True
if B % 3 == 0:
    f = True
if (A+B) % 3 == 0:
    f = True
if f:
    print("Possible")
else:
    print("Impossible")

Measured memory_bytes: 3060
#template
def inputlist(): return [int(j) for j in input().split()]
#template
N = int(input())
A = inputlist()
for i in range(N):
    if A[i] == 0:
        print(0)
        exit()
ans = 1
for i in range(N):
    ans *= A[i]
    if ans > 10**18:
        print(-1)
        exit()
print(ans)

Measured memory_bytes: 21724
#include <cstring>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main () {
	int n;
	while (cin >> n, n) {
		vector<int> rems;
		for (int i = 1; i < n; i++) {
			rems.push_back((i * i) % n);
		}
		sort(rems.begin(), rems.end());
		rems.erase(unique(rems.begin(), rems.end()), rems.end());
		vector<int> results((n - 1) / 2 + 1, 0);
		for (unsigned i = 0; i < rems.size(); i++) {
			for (unsigned j = 0; j < rems.size(); j++) {
				if (i == j) continue;
				int x = rems[i] - rems[j];
				if (x < 0) x += n;
				if ((n - 1) / 2 < x) x = n - x;
				results[x]++;
			}
		}
		for (unsigned i = 1; i < results.size(); i++) {
			cout << results[i] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1324
#include <bits/stdc++.h>
using namespace std;

int main() {
    string S, T;
    cin >> S >> T;

    int correct = 0;
    for (int i = 0; i < 3; i++) {
        if (S.at(i) == T.at(i)) {
            correct++;
        }
    }

    cout << correct << endl;

    return 0;
}

Measured memory_bytes: 256
def examA():
    N = I()
    H = LI()
    dp = [inf]*(N)
    dp[0] = 0
    for i in range(N-1):
        dp[i+1] = min(dp[i+1],dp[i]+abs(H[i+1]-H[i]))
        if i<N-2:
            dp[i + 2] = min(dp[i + 2], dp[i]+abs(H[i + 2] - H[i]))
    ans = dp[-1]
    print(ans)
    return

def examB():
    N, K = LI()
    H = LI()
    dp = [inf]*N
    dp[0] = 0
    for i in range(N):
        for k in range(1,K+1):
            if i+k>=N:
                break
            if dp[i+k]>dp[i]+abs(H[i+k]-H[i]):
                dp[i+k] = dp[i]+abs(H[i+k]-H[i])
    ans = dp[-1]
    print(ans)
    return

def examC():
    N = I()
    A = [0]*N; B = [0]*N; C = [0]*N
    for i in range(N):
        A[i],B[i],C[i] = LI()
    dp = [[0]*3 for _ in range(N+1)]
    for i in range(N):
        dp[i+1][0] = max(dp[i][1],dp[i][2]) + A[i]
        dp[i + 1][1] = max(dp[i][0], dp[i][2]) + B[i]
        dp[i + 1][2] = max(dp[i][1], dp[i][0]) + C[i]
    ans = max(dp[N])
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    # LCS
    S = SI(); N = len(S)
    T = SI(); M = len(T)
    dp = [[0] * (M + 1) for _ in range(N + 1)]
    for i in range(N):
        for j in range(M):
            if S[i] == T[j]:
                dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1)
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j], dp[i][j+1])

    i = N; j = M
    ans = []
    while i > 0 and j > 0:
        if dp[i][j] == dp[i-1][j]:
            i -= 1
        elif dp[i][j] == dp[i][j-1]:
            j -= 1
        else:
            ans.append(S[i-1])
            i -= 1
            j -= 1
    print("".join(ans[::-1]))
    return

def examG():
    # http://zehnpaard.hatenablog.com/entry/2018/06/26/201512
    # トポロジカルソート
    def topological_sort(n,outs,ins):
        q = deque(v1 for v1 in range(n) if ins[v1] == 0)
        res = []
        while q:
            v1 = q.popleft()
            res.append(v1)
            for v2 in outs[v1]:
                ins[v2] -= 1
                if ins[v2] == 0:
                    q.append(v2)
        return res
    N, M = LI()
    V = [[]for _ in range(N)]
    start = [0]*N
    for _ in range(M):
        x,y = LI()
        x -= 1; y -= 1
        V[x].append(y)
        start[y] += 1
    Order = topological_sort(N, V, start)
#    print(Order)
    dp = [0]*N
    for i in Order:
        for v in V[i]:
            dp[v] = max(dp[v],dp[i]+1)
    ans = max(dp)
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examG()

"""

"""

Measured memory_bytes: 30412
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
signed main()
{
	ios_base::sync_with_stdio(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{   
		int n;
		cin >> n;
		vector<vector<int>> v;
		rep(i,0,n){
			vector<int> t;
			rep(j,0,3){
				int u;
				cin >> u;
				t.pb(u);
			}
			v.pb(t);
		}
		int dp[n][3];
		rep(j,0,3){
			dp[0][j] = v[0][j];
		}
		rep(i,1,n){
			rep(j,0,3){
				dp[i][j] = -INF;
				rep(k,0,3){
					if(j==k) continue;
					dp[i][j] = max(dp[i][j], dp[i-1][k]+v[i][j]);
				}
			}
		}
		cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
	}
}

Measured memory_bytes: 8752
#include<bits/stdc++.h>
#include <iostream>
#include <list>
#define ll long long int
using namespace std;
int main()
{
    int t,m,i,cnt=0;cin>>t;
    int ara[t];
    for( i=1;i<=t;i++)cin>>ara[i];
    for( i=1;i<=t;i+=2)
    {
        if(ara[i]%2)cnt++;
    }
    cout<<cnt<<"\n";
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define rep(i, a, b) for(int i = a; i < b; i++)
#define repr(i, a, b) for(int i = a - 1; i >= b; i--)
#define iter(m) for(auto it = m.begin(); it != m.end(); it++)
#define iterr(m) for(auto it = m.rbegin(); it != m.rend(); it++)
#define N 500500
#define PI 3.14159265358979323846264338327950L
#define speed ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
	
const ll mod = (ll)1e9 + 7;
	
int main(){
	speed;
	int n; cin >> n;
	bool yes = false;
	int cnt = 0;
	for(int i = 0; i < n; i++) {
		int x, y; cin >> x >> y;
		if(x == y) cnt++;
		else cnt = 0;
		if(cnt == 3) yes = true;
	}
	cout << (yes ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>

using namespace std;
int v[1000];
int main(){
	int n;
	while(cin >> n){
		int s = 0;
		int ans = 0;
		for(int i = 0; i < n; i++) {cin >> v[i]; s+= v[i];}
		int media = round(s/float(n));
		for(int i = 0; i < n; i++) ans += (v[i] - media)*(v[i] - media);
		cout << ans << endl;
	}
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i < n; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define P pair<int, int>
typedef long long ll;
const ll mod = 1e9+7;

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//ngcd n個の最大公約数
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(ll i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
//nlcm n個の最小公倍数
ll nlcm(vector<ll> a) {
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size(); i++) {
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
ll digsum(ll x){
  ll res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int ans = 1001001001;
  bool ok = true;
  rep(i,n){
    int tmp = 0;
    while(a[i] % 2 == 0){
      tmp++;
      a[i] /= 2;
    }
    ans = min(ans, tmp);
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <numeric>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
#define rep(i, a, b) for (register int i = (a); i <= (b); ++i)
#define per(i, a, b) for (register int i = (a); i >= (b); --i)
#define loop(it, v) for (auto it = v.begin(); it != v.end(); it++)
#define cont(i, x) for (register int i = head[x]; i; i = edge[i].nex)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, cnt) memset(a, cnt, sizeof(a))
#define cop(a, b) memcpy(a, b, sizeof(a))
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()
#define SC(t, x) static_cast <t> (x)
#define ub upper_bound
#define lb lower_bound
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define pof pop_front
#define pob pop_back
#define fi first
#define se second
#define y1 y1_
#define Pi acos(-1.0)
#define iv inline void
#define enter putchar('\n')
#define siz(x) ((int)x.size())
#define file(x) freopen(x".in", "r", stdin),freopen(x".out", "w", stdout)
typedef double db ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair <int, int> pii ;
typedef vector <int> vi ;
typedef vector <pii> vii ;
typedef queue <int> qi ;
typedef queue <pii> qii ;
typedef set <int> si ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
const int maxn = 6e3 + 100 ;
const int inf = 0x3f3f3f3f ;
const int iinf = 1 << 30 ;
const ll linf = 2e18 ;
const ll mod = 998244353 ;
const double eps = 1e-7 ;
template <class T = int> T read()
{
	T f = 1, a = 0;
	char ch = getchar() ;
	while (!isdigit(ch)) { if (ch == '-') f = -1 ; ch = getchar() ; }
	while (isdigit(ch)) { a =  (a << 3) + (a << 1) + ch - '0' ; ch = getchar() ; }
	return a * f ;
}

int n, last = 1, lpos = 1;

char s[maxn];

int posa[maxn], posb[maxn], suma, sumb, rnk[maxn];

pair <string, int> c[maxn];

string ans;

int tot;

void solve(int l, int r)
{
	++ tot;
	c[tot].se = tot;
	if(s[l] == 'a')
	{
		int pos = l;
		while(pos < r)
		{
			c[tot].fi += "ab";
			pos = posb[rnk[pos]] + 1;
			while(s[pos] == 'b' && pos <= r) pos ++;
		}
	}
	else
	{
		rep(i, lpos, rnk[r])
		{
			string tmp = "";
			rep(j, l, r) if(rnk[j] >= i) tmp += s[j];
			c[tot].fi = max(c[tot].fi, tmp);
		}
	}
}

signed main()
{
	scanf("%d", &n);
	scanf("%s", s + 1);
	rep(i, 1, 2 * n)
	{
		if(s[i] == 'a') posa[++ suma] = i, rnk[i] = suma;
		else posb[++ sumb] = i, rnk[i] = sumb;
		if(suma == sumb) solve(last, i), last = i + 1, lpos = suma + 1;
	}
	per(i, n, 1) ans = max(ans, c[i].fi + ans);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>
using namespace std;

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
// default_random_engine generator;
// mt19937 rnd(1);

const int MAXN = 222;

int g[MAXN][MAXN];
int d[MAXN];

int main() {
#ifdef LOCAL
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);  
#endif 
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0); 
    cout.precision(12);
    cout << fixed; 

    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        for (int j = 0; j < n; ++j) {
            g[i][j] = s[j] - '0';
        }
    }

    int res = 0;
    bool ok = true;

    for (int v = 0; v < n; ++v) {
        for (int i = 0; i < n; ++i) {
            d[i] = n;
        }
        queue<int> q;
        q.push(v);
        d[v] = 0;

        while (!q.empty()) {
            int u = q.front();
            q.pop();
            for (int w = 0; w < n; ++w) {
                if (!g[u][w]) {
                    continue;
                }
                if (d[w] > d[u] + 1) {
                    d[w] = d[u] + 1;
                    q.push(w);
                }
            }
        }


        for (int i = 0; i < n; ++i) {
            res = max(res, d[i] + 1);

            for (int j = 0; j < n; ++j) {
                if (g[i][j] && d[i] == d[j]) {
                    ok = false;
                }
            }
        }
    }

    cout << (ok ? res : -1) << endl;

#ifdef LOCAL
    cerr << "Time: " << double(clock()) / CLOCKS_PER_SEC << endl;
#endif
}


Measured memory_bytes: 512
// AOJ 2221 KULASIS
// 2018.3.14 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int N;
int map[5][5];
int dp[5][256];
int p[5] = { 0,0,60,70,80 };

int main()
{
	int i, j, k, r, c, s, ss, ans;

	scanf("%d", &N);
	while (N--) {
		memset(dp, 0, sizeof(dp));
		for (r = 0; r < 5; r++) for (c = 0; c < 5; c++) scanf("%d", &map[r][c]);
		for (i = 0; i < 256; i++) {
			dp[0][i] = 0;
			for (c = 0; c < 5; c++) if (map[0][c]) {
				s = map[0][c];
				if (c > 0) s += i >> ((c-1)<<1) & 3;
				if (c < 4) s += i >> ( c   <<1) & 3;
				if (s > 0) { s %= 4; if (s == 0) s = 4; }
				dp[0][i] += p[s];
			}
		}

		for (i = 1; i < 4; i++) for (j = 0; j < 256; j++) {
			for (k = 0; k < 256; k++) {
				ss = dp[i - 1][j];
				for (c = 0; c < 5; c++) if (map[i][c]) {
					s = map[i][c];
					if (c > 0) s += ((j >> ((c - 1) << 1)) & 3) + ((k >> ((c - 1) << 1)) & 3);
					if (c < 4) s += ((j >> (c << 1)) & 3) + ((k >> (c << 1)) & 3);
					if (s > 0) { s %= 4; if (s == 0) s = 4; }
					ss += p[s];
				}
				if (ss > dp[i][k]) dp[i][k] = ss;
			}
		}

		ans = 0;
		for (i = 0; i < 256; i++) {
			ss = dp[3][i];
			for (c = 0; c < 5; c++) if (map[4][c]) {
				s = map[4][c];
				if (c > 0) s += (i >> ((c-1)<<1)) & 3;
				if (c < 4) s += (i >> (c<<1)) & 3;
				if (s > 0) { s %= 4; if (s == 0) s = 4; }
				ss += p[s];
			}
			if (ss > ans) ans = ss;
		}
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 2032
#!/usr/bin python3
# -*- coding: utf-8 -*-

N = list(map(int, list(input())))
N.reverse()
N=N+[0]
cnt = 0
for i in range(len(N)):
    n=N[i]
    if n<5:
        cnt+=n
    elif n==5:
        cnt+=n
        if N[i+1]>=5:
            N[i+1]+=1
    else:
        cnt+=10-n
        N[i+1]+=1
print(cnt)


Measured memory_bytes: 26316
#include<iostream>
#include<set>
using namespace std;

int main(){
    set<int> s;
    int a,b,k;
    cin>>a>>b>>k;
    for(int i=a;(i<a+k)&&(i<=b);i++){
        s.insert(i);
    }
    for(int i=b;(i>b-k)&&(i>=a);i--)
    {
        s.insert(i);
    }
    set<int>::iterator it;
    for(it=s.begin();it!=s.end();it++){
        cout<<*it<<endl;
    }
    s.clear();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main() {
    vector<char> s(6);
    for(int i=0;i<6;i++){
        cin >> s.at(i);
    }
    if(s.at(0)==s.at(5) && s.at(1)==s.at(4) && s.at(2)==s.at(3)){
        cout << "YES";
    }
    else{
        cout << "NO";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
const double PI = acos(-1);

int main(){
	int n;cin>>n;
	int p[n];
	rep(i,n){
		cin>>p[i];
	}
	int ans =0;
	rep(i,n){
		bool f =false;
		if(p[i]==i+1){
			if(i!=n-1){
				if(p[i+1]==i+2){
					swap(p[i+1],p[i]);
					f=true;
				}
				else if(p[i+1]!=i+1){
					f=true;
					swap(p[i+1],p[i]);
				}
			}
			if(!f){
				swap(p[i-1],p[i]);
			}
			ans++;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<int,int>;

ll ketasu(ll a){
   ll num=1;
   while(a/10){
       num++;
       a/=10;
   }
   return num;
}

ll gcd(ll a,ll b){return b ? gcd(b,a%b) :a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

ll kosuu(ll a){
    ll sum=0;
    for(ll i=1;i*i<=a;i++){
        if(a%i==0){
            if(a!=1&&i*i!=a){
            sum+=2;
            }else{
             sum++;   
            }
        }
    }
    return sum;
}



int main()
{
ll n;
cin>>n;
map<ll,ll>mp;
ll a;
rep(i,n){
    cin>>a;
    mp[a]++;
}

ll q;
cin>>q;
ll b;
ll sum=0;
for(auto m:mp){
       sum+=m.first*m.second;
   }
rep(i,q){
   cin>>a>>b;
   sum+=b*mp[a];
   sum-=a*mp[a];
   mp[b]+=mp[a];
   mp[a]=0;
   cout<<sum<<endl;
}

}



Measured memory_bytes: 9356
import sys

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
S_MAP = lambda: map(str, INPUT().split())

sys.setrecursionlimit(10 ** 9)


def main():
    N = INT()
    S, T = S_MAP()

    ans = ""
    for s, t in zip(S, T):
        ans += s + t

    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define prints(x, y) cout<<(x)<<" "<<(y)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long int
#define pb push_back

int main() {
  ll N, ans = 1, tmp;
  cin >> N;
  for(int i = 2; i <= sqrt(N); i++){
    int j = 1; tmp = 0;
    while(tmp <= N){
      tmp = pow(i, j);
      if (tmp <= N) ans = max(ans, tmp);
      j++;
    }
  }
  print(ans);

}


Measured memory_bytes: 256
use std::io;
use std::cmp;


fn main() {
    let n = read_one::<isize>();
    let k = read_one::<isize>();
    let x = read_one::<isize>();
    let y = read_one::<isize>();
    println!("{}", cmp::min(n, k) * x + cmp::max(0, n - k) * y);

}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
m = 10**5
w = []

for i in range(0, 5):
    w.append(int(input()))

def s(c):
    
    global m
    global w
    r = 0
    for i in range(0, 5):
        r += w[c[i]]
        if r % 10 > 0 and i < 4:
            r = (r // 10 + 1) * 10
    if r < m:
        m = r

def t(c, r):
    if len(c) == 5:
        s(c)
    else:
        for i in r:
            nr = r[:]
            nr.remove(i)
            t(c + [i], nr)

t([], [0, 1, 2, 3, 4])
print(m)

Measured memory_bytes: 3064
from collections import defaultdict

N, X, Y = map(int, input().split())
INF = 10**20
ans = {i:0 for i in range(N)}
d = defaultdict(list)

for i in range(1, N):
    d[i].append(i+1)
    d[i+1].append(i)
d[X].append(Y)
d[Y].append(X)

for i in range(1, N+1):
    dist = [-1]*(N+1)
    q = [i]
    dist[i] = 0

    while q:
        a = q.pop()
        for b in d[a]:
            if dist[b]==-1 or dist[b] > dist[a]+1:
                dist[b] = dist[a] + 1
                q.append(b)
    for j in range(i+1, N+1):
        ans[dist[j]] += 1

for i in range(1,N):
    print(ans[i])

Measured memory_bytes: 49500
#include <iostream>

using namespace std;

int main()
{
    int n;
    int k;
    int a[100001];
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    n = n - k;
    k--;
    int p = n / k;
    if (n % k == 0)
        cout << p + 1;
    else
        cout << p + 2;
    return 0;
}


Measured memory_bytes: 640
import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    H,W = map(int, input().split())
    grid = [list(input().rstrip()) for _ in range(H)]
    q = []
    visited = [[False]*W for _ in range(H)]
    for y in range(H):
        for x in range(W):
            if grid[y][x] == '#':
                q.append((y,x))
                visited[y][x] = True
    ans = -1
    while q:
        ans += 1
        nq = []
        for y,x in q:
            if 0 < x and not visited[y][x-1]:
                visited[y][x-1] = True
                nq.append((y,x-1))
            if x < W-1 and not visited[y][x+1]:
                visited[y][x+1] = True
                nq.append((y,x+1))
            if 0 < y and not visited[y-1][x]:
                visited[y-1][x] = True
                nq.append((y-1, x))
            if y < H-1 and not visited[y+1][x]:
                visited[y+1][x] = True
                nq.append((y+1,x))
        if nq:
            q = nq[:]
        else:
            break
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 115624
#include <iostream>

using namespace std;

int main(){
	int n;
	while(cin >> n, n){
		char d[]="123456",s[9];
		int dir,rot=0,res=1,tmp;
		for(int i=0;i<n;i++){
			cin >> s;
			if(*s%6-4){
				dir=(*s-78?*s%5-1:0)+rot&3;
				dir=dir+1+(1-dir%2*2)*(dir/2);
				tmp=*d,*d=d[dir],d[dir]=d[5],d[5]=d[5-dir],d[5-dir]=tmp;
			} else rot+=*s+3;
			res+=*d-48;
		}
		printf("%d\n",res);
	}
}

Measured memory_bytes: 0
from sys import stdin
readline = stdin.readline
def i_input(): return int(readline().rstrip())
def i_map(): return map(int, readline().rstrip().split())
def i_list(): return list(i_map())


def main():
    N = i_input()
    ans = 0
    for a in range(1, N):
        ans += (N - 1) // a
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define int long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BS binary_search
#define all(c) (c).begin(),(c).end()
#define sz(x) (int)(x).size()
#define get(a,t) get<a>(t)
#define EPS 0.000000001 //1e-9
using pii=pair<int,int>;
const int INF=1e18;

void dprint(string s) { cout << endl;}
void dprint() { cout << endl;}
template <class T, class... U> void dprint(string s, T t, U... u) 
{int w=s.find(','); cout <<"["<< s.substr(0,w) << ": " << t << "] " ; dprint(s.substr(w+1, sz(s)-w), u...);} 


#define DEBUG 
#ifdef DEBUG
#define dbg(X...) dprint(#X,X)
#else
#define dbg(X...); 
#endif
const int N=100005;

int32_t main()
{
	IOS;
	int n; cin>>n;
	map<string, int> mm;
	for(int i=0;i<n;i++)
	{
		string t; cin>>t;
		mm[t]++;
	}
	cout<<mm.size();
	return 0;
}

Measured memory_bytes: 19240
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <bitset>
#include <map>

using namespace std;

#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

typedef long long ll;
typedef long double ld;

const ll SZ = 2e5 + 10;

ll n;
vector<vector<ll>> gr;
vector<ll> vec;

void input() {
	cin >> n;
	vec.resize(n);
	for (auto &cur : vec) cin >> cur;

	gr.clear();
	gr.resize(n);
	for (int i = 0; i < n - 1; i++) {
		ll u, v;
		cin >> u >> v;
		u--; v--;
		gr[u].push_back(v);
		gr[v].push_back(u);
	}
}

vector<bool> used;

ll dfs(int v, int nm) {
	used[v] = 1;

	ll c = 1;
	for (auto to : gr[v]) {
		if (vec[to] != nm && !used[to]) {
			c += dfs(to, nm);
		}
	}

	return c;
}

ll check(int nm) {
	used.clear();
	used.resize(n);
	ll bd = 0;
	for (int i = 0; i < n; i++) {
		if (!used[i] && vec[i] != nm) {
			ll q = dfs(i, nm);
			bd += (q * (q - 1)) / 2 + q;
		}
	}

	return (n * (n - 1)) / 2 + n - bd;
}

vector<ll> stresses() {
	vector<ll> ans;
	ans.resize(n);
	for (int i = 0; i < n; i++) {
		ans[i] = check(i + 1);
	}

	return ans;
}

map<ll, ll> tree[SZ];
ll sub[SZ];
vector<ll> bd;

void dp(int v) {
	used[v] = 1;

	sub[v] = 1;
	for (auto to : gr[v]) {
		if (!used[to]) {
			dp(to);
			sub[v] += sub[to];
			ll gd = sub[to] - tree[to][vec[v] - 1];
			bd[vec[v] - 1] += (gd * (gd - 1)) / 2 + gd;
			if (tree[v].size() < tree[to].size()) {
				tree[v].swap(tree[to]);
			}

			for (auto cur : tree[to]) {
				tree[v][cur.first] += cur.second;
			}

			tree[to].clear();
		}
	}

	if (v == 0) {
		for (int i = 0; i < n; i++) {
			if (i != vec[v] - 1) {
				ll gd = sub[v] - tree[v][i];
				bd[i] += (gd * (gd - 1)) / 2 + gd;
			}
		}
	}
	ll gd = sub[v] - 1 - tree[v][vec[v] - 1];
	
	//bd[vec[v] - 1] += (gd * (gd - 1)) / 2 + gd;
	tree[v][vec[v] - 1] += gd + 1;
}

vector<ll> sol() {
	vector<ll> ans(n);
	used.clear();
	used.resize(n);

	bd.clear();
	bd.resize(n);
	for (int i = 0; i < n; i++) {
		tree[i].clear();
		sub[i] = 0;
	}
	dp(0);

	for (int i = 0; i < n; i++) {
		ans[i] = (n * (n - 1)) / 2 + n - bd[i];
	}

	return ans;
}

void rand_test() {
	n = rand() % 50 + 1;
	
	vec.resize(n);
	for (auto &cur : vec) cur = rand() % n + 1;

	gr.clear();
	gr.resize(n);
	for (int i = 1; i < n; i++) {
		ll par = rand() % i;
		gr[par].push_back(i);
		gr[i].push_back(par);
	}
}

int main() {
	fastInp;

	input();
	vector<ll> ans = sol();
	for (auto cur : ans) cout << cur << "\n";

	return 0;
}

Measured memory_bytes: 76588
// comment
// just think then can solve

#include <bits/stdc++.h>

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
using ll = long long;
using pi = pair<int, int>;
const int INF = 0x3f3f3f3f;
const ll LINF = 1ll * INF * INF;

const int MOD = 998244353;
const int MAX_V = 4e3 + 100;

int N, K;
int C[MAX_V][MAX_V];

int getC(int a, int b) {
	if(a < 0) return 0;
	if(b < 0 || b > a) return 0;
	return C[a][b];
}

int getAns(int x, int r, int l) {
	int ans = 0, p = 1;
	for(int y=0; y<=x; y++) {
		ans = (ans + 1ll * getC(x, y) * p % MOD * getC(N+r-1-l, N-y-l) % MOD) % MOD;
		p *= 2;
		p %= MOD;
	}
	return ans;
}

int Ans[MAX_V];
int main() {
	cin >> K >> N;

	for(int i=0; i<MAX_V; i++) {
		C[i][0] = 1;
		for(int j=1; j<=i; j++) C[i][j] = (C[i-1][j-1] + C[i-1][j]) % MOD;
	}
	for(int i=2; i<=K+1; i++) {
		Ans[i] = getAns((i-1)/2, K-i+1, 0);
		if(i%2 == 0) {
			Ans[i] = (Ans[i] + getAns((i-1)/2, K-i+1, 1)) % MOD;
		}
	}
	for(int i=2; i<=2*K; i++) {
		if(i > K+1) printf("%d\n", Ans[2*K+2-i]);
		else printf("%d\n", Ans[i]);
	}
	return 0;
}


Measured memory_bytes: 50896
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#define INF 1e8
using namespace std;
int n;
int dp[5000001];
int dp2[5000001];

int func(int v){
	if(dp[v]!=INF)return dp[v];
	if(v==0)return 0;
	int cnt=INF;
	int j=1;
	while(j*(j+1)*(j+2)/6<=v)j++;
	j--;
	for(int i=j;i>=1;i--){
		cnt=min(cnt,func(v-i*(i+1)*(i+2)/6));
	}
	return (dp[v]=cnt+1);
}

int func2(int v){
	if(dp2[v]!=INF)return dp2[v];
	if(v==0)return 0;
	int cnt=INF;
	int j=1,i;
	while(j*(j+1)*(j+2)/6<=v)j++;
	j--;
	for(i=j;i>=1;i--){
		if((i*(i+1)*(i+2)/6)%2!=1)continue;
		cnt=min(cnt,func2(v-i*(i+1)*(i+2)/6));
	}
	return (dp2[v]=cnt+1);
}

int main(void){
	for(int i=1;i<=2000000;i++)dp[i]=dp2[i]=INF;
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		printf("%d %d\n",func(n),func2(n));
	}
	return 0;
}

Measured memory_bytes: 19456
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>

using namespace std;

typedef long long int ll;
typedef vector<ll> V;
typedef vector<V> VV;

int main() {
  ll h, w;
  ll lh, lw;
  cin >> h >> w;
  cin >> lh >> lw;

  cout << (h-lh) * (w - lw) << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

typedef long long ll;


int main(void) {
  int n;
  string s;
  cin >> n >> s;
  REP(i, s.size()) {
    cout << (char)('A' + (s[i]-'A'+n)%26); 
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = input()
num = int(n)
l = len(n)
li = ['3', '5', '7']
keta = [[] for i in range(l)]
keta[0] = li
for i in range(1, l):
    for kazu in keta[i-1]:
        for n in li:
            keta[i].append(kazu + n)
ct = 0
for i in range(l):
    for n in keta[i]:
        if '3' in n and '5' in n and '7' in n and int(n) <= num:
            ct += 1
print(ct)



Measured memory_bytes: 5356
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

using ll = long long int;

int main() {
    // Input
    int N;
    cin >> N;

    // Process
    string ans;
    int n = N % 10;
    if (n == 3) {
        ans = "bon";
    } else if (n == 0 || n == 1 || n == 6 || n == 8) {
        ans = "pon";
    } else {
        ans = "hon";
    }

    // Output
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define pb push_back
#define INF 0x3f3f3f3
#define LINF 0x3f3f3f3f3f3f3f
#define MAXN int(100005)
#define fim '\n'
#define ll long long
#define f first
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << fim
#define debug2(x, y) cout << "DEBUG " << x << " " << y << fim
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< fim
using namespace std;
typedef pair<ll, pair<int, int> > pii;

int dp[2][MAXN], n, minor = INF, vet[MAXN];


int main() {
    FAST;
    int k;
    cin >> n >> k;
    for(int i = 1; i <= n; i++) {
        cin >> vet[i];
        minor = min(vet[i], minor);
    }

    for(int i = 0; i < 2; i++)
        for(int j = 0; j < minor; j++) {
            if(i == 1) dp[i][j] = 1;
            else dp[i][j] = -1;
        }
    for(int i = 0; i <= k; i++) {
        dp[0][i] = -1;
        dp[1][i] = 1;
        for(int j = 1; j <= n; j++) {
            if(i >= vet[j]) {
                dp[0][i] =  max(dp[0][i], dp[1][i-vet[j]]);
                dp[1][i] = min(dp[1][i], dp[0][i-vet[j]]);
            }
        }
    }
    cout << (dp[0][k] == -1 ? "Second" : "First") << fim;

}



Measured memory_bytes: 1024
import java.util.Scanner;
public class Main{
		
    public void solve(){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		if(a < b && b < c){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
    }		
		
	public static void main(String[] args){
		Main obj = new Main();
		obj.solve();
	}
}
				
			
   

Measured memory_bytes: 17160
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define lint long long

using namespace std;

int main()
{
  string s;
  cin>>s;

  int ans=0,length=s.size();
  for(int i=0;i<length/2;i++){
    if(s.at(i)!=s.at(length-i-1)){
      ans+=1;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
/*
Aaaye mera solution dekhne aaye ho... bdia hai... :P

Swaagat hai aap logo ka!!
*/


#include<bits/stdc++.h>
using namespace std;

#define mod 1000000007
#define pb push_back
#define eb emplace_back
typedef unsigned long long ull;
typedef long long lld;
typedef long ld;
typedef long double ldo;
typedef pair<lld, lld> pll;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    lld a,b,c;
    cin>>a>>b>>c;

    lld ans = b + min(a+b+1, c);

    cout<<ans;
    return 0;
}



Measured memory_bytes: 256
import { isAbsolute } from 'path';

class Scanner {
  private buffer = '';
  private stdinQueue: any = [];

  constructor() {
    process.stdin.resume();
    process.stdin.setEncoding('utf8');
    process.stdin.on(
      'data',
      (chunk): void => {
        this.buffer += chunk;
        while (this.stdinQueue.length > 0) {
          const i = this.buffer.indexOf('\n');
          if (i < 0) {
            break;
          }
          let line = this.buffer.substr(0, i);
          if (line.endsWith('\r')) {
            line = line.slice(0, -1);
          }
          this.buffer = this.buffer.substr(i + 1);
          this.stdinQueue.shift()(line);
        }
      },
    );
  }
  public getLine(): Promise<string> {
    return new Promise((resolve, reject) => {
      const i = this.buffer.indexOf('\n');
      if (i >= 0 && this.stdinQueue.length == 0) {
        let line = this.buffer.substr(0, i);
        if (line.endsWith('\r')) {
          line = line.slice(0, -1);
        }
        this.buffer = this.buffer.substr(i + 1);
        resolve(line);
      } else {
        this.stdinQueue.push(resolve);
      }
    });
  }

  public close(): void {
    process.stdin.pause();
  }
}

async function slove() {
  const sc = new Scanner();
  const [a, b, c, d]: number[] = (await sc.getLine()).split(' ').map((x) => +x);
  if (Math.abs(a - c) <= d || (Math.abs(a - b) <= d && Math.abs(b - c) <= d)) {
    console.log('Yes');
  } else {
    console.log('No');
  }
  sc.close();
}

slove();


Measured memory_bytes: 7500
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <climits>
#include <utility>
typedef long long ll;
using namespace std;

int main(void){
  int n,m;
  cin>>n>>m;

  if(n==m)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;

int main() {
  int n;
  cin >> n;

  int a[n];
  rep (i, n) cin >> a[i];

  int ans = 0;
  for (int i = 0; i < n; i++) {
    while (i+1 < n && a[i] == a[i+1])
      i++;

    if (i+1 < n && a[i] < a[i+1]) {
      while (i+1 < n && a[i] <= a[i+1])
        i++;
    }
    else if (i+1 < n && a[i] > a[i+1]) {
      while (i+1 < n && a[i] >= a[i+1])
        i++;
    }

    ans++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)

int main(){
    int h,w; cin >> h >> w;
    vector<vector<char>> C(h,vector<char>(w));
    rep(i,h){
        rep(j,w){
            cin >> C[i][j];
        }
    }

    rep(i,h){
        rep(j,w){
            cout << C[i][j];
        }
        cout << endl;
        rep(j,w){
            cout << C[i][j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main{
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());
		if(n <= m) ou.print("unsafe\n");
		else ou.print("safe\n");
		ou.flush();
    }
}

Measured memory_bytes: 35512
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
    int ans=0;
    int N;cin>>N;
    for(int i=1;i<=N;i++){
        int cnt=0;
        if(i%2!=0)for(int y=1;y<=i;y++)if(i%y==0)cnt++;
        if(cnt==8)ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

template <typename T>
T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }

template <typename T>
T lcm(T a, T b) { return (a * b) / gcd(a, b); }

int main() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;

	ll x = lcm(c, d);
	ll res = b - a + 1;
	a -= 1;
	res = res - (b / d - a / d) - (b / c - a / c) + (b / x - a / x);
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	static long mod = 1000000007;
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong(), B = sc.nextLong();
		int cnt = 0;
		for(long Ai = A; Ai <= B; Ai *= 2) {
			cnt++;
		}
		System.out.println(cnt);
	}
}


Measured memory_bytes: 23764
#include<stdio.h>

int main(){
    int sx,sy,tx,ty;
    scanf("%d%d%d%d",&sx,&sy,&tx,&ty);

    int i;
    int x=tx-sx;
    int y=ty-sy;
    for(i=0;i<y;i++){
        printf("U");
    }
    for(i=0;i<x;i++){
        printf("R");
    }
    for(i=0;i<y;i++){
        printf("D");
    }
    for(i=0;i<x;i++){
        printf("L");
    }
    printf("L");
    for(i=0;i<y+1;i++){
        printf("U");
    }
    for(i=0;i<x+1;i++){
        printf("R");
    }
    printf("D");
    printf("R");
    for(i=0;i<y+1;i++){
        printf("D");
    }
    for(i=0;i<x+1;i++){
        printf("L");
    }
    printf("U\n");
    return 0;

}

Measured memory_bytes: 1624
#include <bits/stdc++.h>
using namespace std;

int main()
{   
	int a,b;
	cin>>a>>b;

	set<int> s;

	s.insert(a);
	s.insert(b);

	for(int i=1;i<=3;i++)
	{
		if(s.count(i)==0)
		{
			cout<<i;
			return 0;
		}
	}

return 0;
}

Measured memory_bytes: 256
N=int(input())
x,y=0,0
time=0
for i in range(N):
  t,a,b=map(int,input().split())
  if abs(x-a)+abs(y-b)>t-time or (abs(x-a)+abs(y-b)-t+time)%2==1:
    print("No")
    exit()
  time=t
  x=a
  y=b
print("Yes")

Measured memory_bytes: 74196
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 200000000000
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()

bool compare(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}
// 入力



int main() {
    ll N,ans = 0;
    string S;
    cin >>N>>S;
    ll mode = 0;
    rep(i,N){
        if(mode == 0 && S[i] == 'A'){
            mode = 1;
        }else if(mode == 1 && S[i] == 'B'){
            mode = 2;
        }else if(mode == 2 && S[i] == 'C'){
            mode = 0;
            ans++;
        }else if(S[i] == 'A'){
            mode = 1;
        }else{
            mode = 0;
        }
    }
    
    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 3468
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    V<int> a(2 * n);
    V<char> bw(2 * n);
    for (int i = 0; i < 2 * n; i++) cin >> bw[i] >> a[i];

    V< V<int> > black(n + 1, V<int>(n + 1, 0)), white(n + 1, V<int>(n + 1, 0));
    V<int> bcnt(n + 2, 0), wcnt(n + 2, 0);
    for (int i = 0; i < 2 * n; i++) {
        // bacc[j], wacc[j]: 各色の今までに出てきた j 以上の数
        V<int> bacc = bcnt, wacc = wcnt;
        for (int j = n - 1; j >= 0; j--) {
            bacc[j] += bacc[j + 1];
            wacc[j] += wacc[j + 1];
        }
        
        if (bw[i] == 'B') {
            for (int j = 0; j <= n; j++) {
                black[a[i]][j] = bacc[a[i]] + wacc[j + 1];
            }
        } else {
            for (int j = 0; j <= n; j++) {
                white[j][a[i]] = wacc[a[i]] + bacc[j + 1];
            }
        }
        (bw[i] == 'B' ? bcnt : wcnt)[a[i]]++;
    }

    // dp[i][j]: 黒を i 個、白を j 個詰めるための回数
    V< V<int> > dp(n + 1, V<int>(n + 1, INF));
    dp[0][0] = 0;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            if (i == 0 && j == 0) continue;
            if (i > 0) chmin(dp[i][j], dp[i - 1][j] + black[i][j]);
            if (j > 0) chmin(dp[i][j], dp[i][j - 1] + white[i][j]);
        }
    }
    cout << dp[n][n] << '\n';
    return 0;
}


Measured memory_bytes: 50356
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

int n;
bool g[700][700]={};
int num[700]={};
vector<pair<int,int>> sz;
int b,w;

bool dfs(int v,int c){
    if(c==1)++b;
    else ++w;
    num[v]=c;
    rep(i,n){
        if(i==v)continue;
        if(!g[v][i]){
            if(num[i]==c)return false;
            if(num[i]==0&&!dfs(i,-c))return false;
        }
    }
    return true;
}

int main(){
    int m;
    cin>>n>>m;
    rep(i,m){
        int a,b;
        cin>>a>>b;
        --a,--b;
        g[a][b]=g[b][a]=true;
    }
    rep(i,n){
        if(num[i]==0){
            b=0,w=0;
            if(!dfs(i,1)){
                cout<<-1<<endl;
                return 0;
            }
            sz.push_back(make_pair(b,w));
        }
    }
    int s=sz.size();
    bool dp[s+1][n+1]={};
    dp[0][0]=true;
    rep(i,s){
        for(int j=0;j<=n;++j){
            if(j+sz[i].first<=n)dp[i+1][j+sz[i].first]|=dp[i][j];
            if(j+sz[i].second<=n)dp[i+1][j+sz[i].second]|=dp[i][j];
        }
    }
    int mn=inf;
    int ans;
    rep(i,n+1){
        if(dp[s][i]){
            if(abs(n-2*i)<mn){
                mn=abs(n-2*i);
                ans=i;
            }
        }
    }
    cout<<ans*(ans-1)/2+(n-ans)*(n-ans-1)/2<<endl;
}


Measured memory_bytes: 1280
import java.io.*;
import java.util.*;

public class Main {
	public static void main (String[] args) { new Main(); }

	public Main() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("");

		int n = fs.nextInt();
		HashSet<String> set = new HashSet<>();
		while(n-->0) set.add(fs.next());
		out.println(set.size());
		
		
		out.close();
	}

	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) {
			try {
				in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
			}
			catch (Exception e) {
				in = new BufferedInputStream(System.in, BS);
			}
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}                
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
		
		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for(int i = 0; i < n; i++) res[i] = nextInt();
			return res;
		}
		
	}

}

Measured memory_bytes: 59288
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1000000000;

int main() {
    int N;
    cin >> N;
    vector<int>a(N);
    for (int i=0; i<N; i++)cin >> a[i];
    int ans = 0;

    for (int i=0; i<N; i++){
        if (i > 0 and i < N-1){
            if (a[i+1] == a[i] and a[i] == a[i-1]){
                a[i] = -300 + i;
                ans++;
            }
        }   
    }

    for (int i=0; i<N-1; i++){
        if (a[i+1] == a[i]){
            a[i] = -500 + i;
            ans++;
        }
    }


    cout << ans << endl;
}

Measured memory_bytes: 3608