akhauriyash/Code-Regression huggingface dataset:
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <array>
#include <cstddef>

using std::size_t;

constexpr size_t SIZE = 200000;

int n, ans;
std::array<int, SIZE> a, b;

int main() {
	std::cin >> n;
	for (int i = 0; i < n; i++) std::cin >> a[i];
	for (int i = 0; i < n; i++) std::cin >> b[i];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			ans ^= (a[i] + b[j]);
		}
	}
	std::cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 5164
#include<iostream>
#include<string>
#include<vector>
using namespace std;




int main(){
	int N;
	cin>>N;
	
	vector<vector<int>> A(2,vector<int>(N,0));
	for(int i = 0; i < 2; i++)
		for(int j = 0; j < N; j++)
			cin >> A[i][j];
	
	
	vector<vector<int>> V(2+1,vector<int>(N+1,0));
	
	
	
	for(int i = 1; i >=0; i--)
		for(int j = N-1; j >= 0; j--){
			V[i][j] = A[i][j] + max(V[i+1][j],V[i][j+1]);
		}
	
	
	cout<< V[0][0] <<"\n";
return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;

int main(){
    int  a[5],k;
    for(int i=0;i<5;i++){
        cin>>a[i];
    }cin>>k;
    for(int i=0;i<5;i++){
        for(int j=i+1;j<5;j++){
            if(abs(a[i]-a[j])>k){
                cout << ":("<<endl;
                return 0;
            }
        }
    }
    cout << "Yay!"<<endl;
    return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=3.141592653589793;
const ll MOD=1e9+7;

template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

int main() {
    int n,q;
    cin>>n>>q;
    UnionFind<int> uf(n+1);
    rep(i,q){
        int a,x,y,z;
        cin>>a;
        if (a==1){
            cin>>x>>y;
            if (uf.issame(x,y)){
                cout<<uf.diff(x,y)<<endl;
            }
            else{
                cout<<"?"<<endl;
            }
        }
        else{
            cin>>x>>y>>z;
            uf.merge(x,y,z);
        }
    }
    

    return 0;
}


Measured memory_bytes: 3856
h,w=map(int,input().split())
a=[list(input()) for i in range(h)]
b=a
for i in range(h):
  for j in range(w):
    if a[i][j]!="#":
      b[i][j]=a[i][max(0,j-1):min(w,j+2)].count("#")
      if i!=0:
        b[i][j]+=a[i-1][max(0,j-1):min(w,j+2)].count("#")
      if i!=h-1:
        b[i][j]+=a[i+1][max(0,j-1):min(w,j+2)].count("#")
for i in range(h):
  print("".join(str(j) for j in b[i]))

Measured memory_bytes: 73956
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;

// I
//
//const int MAX_V = 5010;
//const int INF = 1e9;
//
//int V;
//struct edge { int to, cap, rev; };
//
//vector<edge> G[MAX_V];
//bool used[MAX_V];
//
//void add_edge(int from, int to, int cap) {
//	G[from].push_back(edge{ to, cap, int(G[to].size()) });
//	G[to].push_back(edge{ from, 0, int(G[from].size() - 1) });
//}
//
//int dfs(int v, int t, int f) {
//	if(v == t) return f;
//	used[v] = true;
//	for(edge& e : G[v]) {
//		if(!used[e.to] && e.cap > 0) {
//			int d = dfs(e.to, t, min(f, e.cap));
//			if(d > 0) {
//				e.cap -= d;
//				G[e.to][e.rev].cap += d;
//				return d;
//			}
//		}
//	}
//	return 0;
//}
//
//int max_flow(int s, int t, int lim = INF) {
//	int flow = 0;
//	while(1) {
//		fill(used, used + V, false);
//		int f = dfs(s, t, lim);
//		if(f == 0 || flow == lim) return flow;
//		flow += f;
//		lim -= f;
//	}
//	return -1;
//}
//
//int mod2[5000];

vector<int> G[5010];

int match;

int dfs(int v) {
	int rem = 1;
	for(auto c : G[v]) {
		int res = dfs(c);
		if(res == 1 && rem == 1) {
			rem = 0;
			match++;
		}
	}
	return rem;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;
	for(int i = 1; i <= N; i++) {
		int p;
		cin >> p;
		G[p].push_back(i);
		match = 0;
		dfs(0);
		cout << match << endl;
	}
}

Measured memory_bytes: 3324
#include "bits/stdc++.h"
using namespace std;
#define LL long long

bool Check(string s,LL n){
    string r=s;
    reverse(r.begin(),r.end());
    if(s==r)return true;
    else return false;
}
 

void solve() {
    int n,m;
    cin>>n>>m;
    n=n-1;
    m=m-1;
    cout<<n*(n+1)/2 + m*(m+1)/2<<"\n";
}

int main()
{
      
             solve();
    return 0; 
}

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

using namespace std;

const int N = 100 + 17 , K = 200 + 17;
int dp[N][N][K];
int n , k , a[N];
int main() {

   scanf("%d %d" , & n , & k);
   for(int i = 1;i <= n;++ i)
      scanf("%d" , a + i);
   for(int i = 1;i <= n;++ i)
      for(int f = 1;f <= k;++ f)
         dp[i][i][f] = max(a[i] , 0);
   for(int len = 2;len <= n;++ len)
      for(int le = 1;le + len <= n + 1;++ le)
         for(int i = 1;i <= k;++ i) {
            int ri = le + len - 1;
            dp[le][ri][i] = max(dp[le][ri][i] , dp[le][ri - 1][i - 1] + a[ri]);
            if(i > 1)
               dp[le][ri][i] = max(dp[le][ri][i] , dp[le][ri - 1][i - 2] + max(a[ri] , 0));
            dp[le][ri][i] = max(dp[le][ri][i] , dp[le + 1][ri][i - 1] + a[le]);
            if(i > 1)
               dp[le][ri][i] = max(dp[le][ri][i] , dp[le + 1][ri][i - 2] + max(a[le] , 0));
         }
   printf("%d\n" , dp[1][n][k]);
   return 0;
}


Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

// P と 10が互いに素でない場合,
// つまりP=2 または P=5の場合、フェルマーの小定理や、
// その他逆元を高速に演算する手法が使えなさそうなので注意
// https://twitter.com/satanic0258/status/1236285593677520896
int N; ll P;
const int MAX_N = 200100;
string S;
ll C[MAX_N];

void solve_2() {
    ll res = 0;
    for(int i = 0;i < N; ++i) {
        int c = S[i] - '0';
        if(c%2==0) res += N - i;
    }
    cout << res << endl;
    return ;
}

void solve_5() {
    ll res = 0;
    for(int i = 0; i < N; ++i) {
        int c = S[i] - '0';
        if(c%5==0) res += N - i;
    }
    cout << res << endl;
    return ;
}

int main()
{
    cin >> N >> P;
    cin >> S;

    reverse(S.begin(),S.end());
    if(P == 2) { solve_2(); return 0;}
    if(P == 5) { solve_5(); return 0;}

    ll base = 1;
    map<ll,ll> Map;
    Map[0]++;   // 何も数を選択していないときは0になるため
    for(int i = 0; i < N; ++i) {
        C[i] = (ll)(S[i] - '0')*base%P;
        base *= 10;
        base %= P;
    }
    for(int i = 1; i < N; ++i) {
        C[i] += C[i-1];
        C[i] %= P;
    }
    for(int i = 0; i < N; ++i) {
        Map[C[i]]++;
    }
    ll res = 0;
    for(auto &p : Map) {
        ll num = p.second;
        res += num*(num-1)/2;
    }
    cout << res << endl;
    return 0;

}

Measured memory_bytes: 2564
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#define unordered_map __fast_unordered_map
template<class Key, class Value, class Hash = std::hash<Key>>
using unordered_map = __gnu_pbds::gp_hash_table<Key, Value, Hash>;

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int MaxLen = 1e5 + 10;

int fu_parent[MaxLen];
bool is_gut[MaxLen];
int totals[MaxLen];

int FuFind(int v) {
  if (fu_parent[v] == v)
    return v;
  return fu_parent[v] = FuFind(fu_parent[v]);
}

void FuUnion(int a, int b) {
  a = FuFind(a);
  b = FuFind(b);
  if (a != b) {
    fu_parent[a] = b;
    is_gut[b] |= is_gut[a];
  }
}


int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);

  string s;
  int K;
  int N;

  cin >> s >> K;
  N = SZ(s);

  if (N == 1) {
    cout << "YES\n";
    return 0;
  }

  iota(fu_parent, fu_parent + N, 0);

  vector<int> diffs(N - 1);
  for (int i = 0; i < N - 1; ++i) {
    diffs[i] = (s[i + 1] - s[i] + 26) % 26;
  }

  debug(diffs);

  for (int i = 0; i < K; ++i) {
    int L, R;
    cin >> L >> R;
    if (L == 1 && R == N) { continue; }

    L -= 2;
    --R;
    debug(L, R);

    if (L < 0 || R >= N - 1) {
      int gut = L < 0 ? R : L;
      mini(gut, (N - 2) - gut);
      is_gut[FuFind(gut)] = true;
    } else {
      mini(L, (N - 2) - L);
      mini(R, (N - 2) - R);
      FuUnion(FuFind(L), FuFind(R));
    }
  }

  for (int i = 0; i < N - 1; ++i) {
    const int j = min(i, N - 2 - i);
    totals[FuFind(j)] += diffs[i];
  }

  for (int i = 0; i < N / 2; ++i) {
    if (FuFind(i) != i) { continue; }
    debug(i, totals[i], is_gut[i]);
    if (totals[i] % 26 != 0 && !is_gut[i]) {
      cout << "NO\n";
      return 0;
    }
  }

  cout << "YES\n";
}


Measured memory_bytes: 2512
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n,r = inpm()
ans = r
if n < 10:
    ans = r + (100 * (10 - n))
print(ans)

Measured memory_bytes: 31276
#include<bits/stdc++.h>
using namespace std;
int main(){
	string st;cin>>st;
	bool c=false;
	for(int i=0;i<st.size();i++){
		if(st[i]=='C')c=true;
		if(st[i]=='F'&&c){
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
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 (a>b) { a = b; return 1; } return 0; }
 
int main(){
    ll A, B;
    cin >> A >> B;
    bool can = false;
    FOR(C, 1, 4) {
        if ((A*B*C)%2 == 1) can = true;
    }
    if (can) cout << "Yes\n";
    else cout << "No\n";
}


Measured memory_bytes: 256
def updiv(a,b):
    if a % b == 0:
        return a // b
    else:
        return a // b + 1
    
while True:

    r,w,C,R = map(int,input().split())

    if r == 0 and w == 0 and C == 0 and R == 0:
        break

    if r/w >= C:
        print (0)
    else:
        print (updiv(w*C-r,R))



Measured memory_bytes: 5604
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
using namespace std;
int main(){
	int i=0;
	vector<int> a(101),b(101);
	while(cin>>a[i]){
		i++;
	}
	for(int j=1;j<=100;j++){
	b[j-1] = count(a.begin(),a.end(),j);
	}
	int p = *max_element(b.begin(),b.end()) ;

	for(int j=0;j<=100;j++){	
	if(b[j] == p )cout<< j+1<<endl;
	}
		//for(int j=1;j<=100;j++) cout<<j<<"="<<b[j-1]<<endl;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int n;
string s;
string st;

int main(){
	cin>>n>>s;
	for(int i=0;i<n-1;i++){
		cin>>st;
		string sth;
		for(int j=0;j<s.length();j++){
			for(int k=0;k<st.length();k++){
				if(s[j]!=' '&&s[j]==st[k]){
					sth+=s[j];
					s[j]=' ';
					st[k]=' ';
				}
			}
		}
		s=sth;
	}
	sort(s.begin(),s.end());
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
// Author: Ishaan Gupta

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define DEB(x) cout << '>' << #x << ':' << x << endl;
using ll = long long;
using ld = long double;
const ll MOD = 1e9l + 7;
const ll INF = 1e18l + 5;
inline ll add(ll a,ll b){return (a%MOD+b%MOD)%MOD;}
inline ll sub(ll a,ll b){return (a%MOD-b%MOD+MOD)%MOD;}
inline ll mult(ll a,ll b){return ((a%MOD)*(b%MOD))%MOD;}
inline ll power(ll a,ll b){a%=MOD;ll r=1;while(b){if(b&1)r=mult(r,a);a=mult(a,a);b>>=1;}return r;}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed;
#ifdef IG_PC
    freopen("input", "r", stdin);
    freopen("output", "w", stdout);
#endif
    string s, t;
    cin >> s >> t;
    vector<vector<ll>> dp(s.length() + 1,vector<ll>(t.length()+1,0));
    for(ll i = 1; i <= (ll)s.length(); ++i)
    {
        for(ll j = 1; j <= (ll)t.length(); ++j)
        {
            if(s[i-1]==t[j-1])
            {
                dp[i][j] = dp[i-1][j-1] + 1;
            }
            else
            {
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }
    ll i = s.length();
    ll j = t.length();
    string ans;
    while(i > 0 && j > 0)
    {
        if(dp[i][j] == dp[i-1][j])
        {
            i--;
        }
        else if(dp[i][j] == dp[i][j-1])
        {
            j--;
        }
        else
        {
            ans+=s[i-1];
            i--;
            j--;
        }
    }
    reverse(ans.begin(), ans.end());
    cout<<ans;

    
    return 0;
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
int n;
int get(int now)
{
	++now;
	while (now%2!=0&&now%3!=0) ++now;
	return now;
}
int main()
{
	scanf("%d",&n);
	if (n==3)
	{
		printf("%d %d %d\n",2,5,63);
		return 0;
	}
	int s=0,now=0;
	for (int i=1;i<=n-2;i++)
	{
		now=get(now);
		s=(s+now)%6;
		printf("%d ",now);
	}
	++now;
	if (s==0)
	{
		while (now%6!=0) ++now;
		printf("%d %d\n",now,now+6);
	} else if (s==1)
	{
		while (now%6!=2) ++now;
		printf("%d %d\n",now,now+1);
	} else if (s==2)
	{
		while (now%6!=4) ++now;
		printf("%d %d\n",now,now+2);
	} else if (s==3)
	{
		while (now%6!=3) ++now;
		printf("%d %d\n",now,now+3);
	} else if (s==4)
	{
		while (now%6!=2) ++now;
		printf("%d %d\n",now,now+6);
	} else if (s==5)
	{
		while (now%6!=3) ++now;
		printf("%d %d\n",now,now+1);
	}
	return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int i = 1;
        while (true) {
            int x = sc.nextInt();
            if(x == 0) {break;}
            System.out.println("Case " + i + ": " + x);
            i++;
        }
    }
}


Measured memory_bytes: 41616
a=[list(map(int,input().split())) for _ in range(3)]
b=list(zip(*a))
c=a[0]
d=b[0]
f=True

dx1=c[1]-c[0]
dx2=c[2]-c[1]
dy1=d[1]-d[0]
dy2=d[2]-d[1]

for i in range(3):
  c=a[i]
  d=b[i]
  if dx1==c[1]-c[0] and dx2==c[2]-c[1] and dy1==d[1]-d[0] and dy2==d[2]-d[1]:
    f=True
  else:
    f=False
    break
if f:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9088
function readLines(): Promise<string[]> {
    return new Promise<string[]>((resolve) => {
        let inputBuffer = "";
        process.stdin.resume();
        process.stdin.setEncoding("utf8");
        process.stdin.on("data", (chunk) =>
            inputBuffer += chunk.toString()
        );
        process.stdin.on("end", () =>
            resolve(inputBuffer.split("\n"))
        );
    });
}

async function main() {
    const inputs: string[] = await readLines();
    const s: string = inputs[0];
    const k: number = parseInt(inputs[1]);
    
    const notOne = getNotOneIndex(s);

    if (k <= notOne) {
        console.log(1);
    } else {
        console.log(s.charAt(notOne));
    }
}

function getNotOneIndex(source: string): number {
    for (let i = 0; i < source.length; i++) {
        if (source.charAt(i) !== "1") {
            return i;
        }
    }
    return 0;
}

main();


Measured memory_bytes: 7500
import std.stdio: writeln, readln;
import std.string: strip;

void main() {
	string a = readln.strip;
	string b = readln.strip;

	if (a == b)
		writeln("EQUAL");
	else if (a.length > b.length)
		writeln("GREATER");
	else if (b.length > a.length)
		writeln("LESS");
	else if (a > b)
		writeln("GREATER");
	else
		writeln("LESS");
}


Measured memory_bytes: 256
h, w = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(10)]
for k in range(10):
    for i in range(10):
        for j in range(10):
            c[i][j] = min(c[i][j], c[i][k] + c[k][j])
ans = 0
a = [list(map(int, input().split())) for _ in range(h)]
for i in range(h):
    for j in range(w):
        if a[i][j] != -1:
            ans += c[a[i][j]][1]
print(ans)

Measured memory_bytes: 40284
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);

  long double a,b,x,y;
  cin >> a >> b >> x;
  y=2*x/b/a;
  
  if(y<=a){
    cout << fixed << setprecision(12) << atan2(b,y)*180/M_PI << endl;
  }
  else{
    long double l=2*b-2*x/a/a;
    cout << fixed << setprecision(12) << atan2(l,a)*180/M_PI << endl;

  }
  
  return 0;
    

}


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

int main() {
  int  n;
  cin >> n;
  double n2 = n;
  if( n%2 == 0){
    cout << 0.5 << endl;
  }else{
    cout << (n/2)/n2 + (1/n2) << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    
    sort(all(a));
    int ans = a[0];
    
    reps(i, 1, n) {
        ans = gcd(ans, a[i]);
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#include<math.h>
using namespace std;

int main() {

	int H;
	int A;
	cin >> H;
	cin >> A;

	int ans = 0;
	ans = H / A;

	if (H % A == 0) {
		cout << ans << endl;
	}
	else {
		ans += 1;
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 256
from math import factorial
N, A, B = map(int, input().split())
MOD = 10 ** 9 + 7

def calc(n):
    ret = 1
    for i in range(n):
        ret = ret * (N - i) % MOD
    return ret * pow(factorial(n), MOD - 2, MOD) % MOD

print(max(0, (pow(2, N, MOD) - ((calc(A) + calc(B)) % MOD) - 1) % MOD))

Measured memory_bytes: 73180
k = int(input())
a = []


def dfs(x):
    a.append(x)
    if x > 3234566667:
        return
    for i in range(10):
        if abs(x % 10 - i) <= 1:
            dfs(x * 10 + i)


for i in range(1, 10):
    dfs(i)
a = sorted(a)
print(a[k - 1])


Measured memory_bytes: 19996
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;
using pll=pair<ll,ll>;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

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; }

int dp[25][50010];
int main() {
	int N,M;
	cin >> N >> M;
	vector<int> C(M);
	rep(i,M) cin >> C[i];
	rep(i,M+1) rep(j,N+1) dp[i][j] = 1e9;
	dp[0][0] = 0;
	rep(i,M+1) rep(j,N+1) {
		if(i == 0) continue;
		int c = C[i-1];
		if(j < c) dp[i][j] = min({dp[i][j],dp[i-1][j]});
		else dp[i][j] = min({dp[i-1][j], dp[i][j], dp[i-1][j-c] + 1, dp[i][j-c] + 1});
	}
	/*rep(i,M+1) {
		rep(j,N+1) {
			if(dp[i][j] == 1e9) cout << setw(3) << -1;
			else cout << setw(3) << dp[i][j];
		}
		cout << endl;
	}*/
	cout << dp[M][N] << endl;


  return 0;
}


Measured memory_bytes: 7196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define all(x) (x).begin(), (x).end()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end());
// map<int,int> mp;

int main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N - 1);
  REP(i, N - 1) cin >> B[i];

  REP(i, N) A[i]=1000000000;

  for (int i = 0; i < N - 1; i++) {
    A[i] = min(A[i], B[i]);
    A[i + 1] = min(A[i + 1], B[i]);
  }
  int ans = 0;
  REP(i, N) ans += A[i];
  cout << ans << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))

X = 0
town = 1
counted = [0 for _ in range(N)]
List = [0 for _ in range(N)]
for k in range(N):
  X += 1
  counted[k] = town
  town = A[town-1]
  if List[town-1] == 1:
    ini = counted.index(town)
    Q = X - ini
    break
  else:
    List[town-1] = 1
if K >= ini:    
  num = (K-ini) % Q
  print(counted[ini+num])
else:
  print(counted[K])

Measured memory_bytes: 107036
#include<bits/stdc++.h>
using namespace std;
priority_queue<int,vector<int>,greater<int> >pq;
int n,k,v[51];
int solve(int k)
{
	int ans=0;
	if(k<=0) return 0;
	for(int i=0;i<=k/2;++i)//放回去多少 
	{
		int sum;
		int na=k-i;
		if(na>=n)
		{
			sum=0;
			while(!pq.empty()) pq.pop(); 
			for(int j=1;j<=n;++j) pq.push(v[j]),sum+=v[j];
			for(int j=1;j<=i&&j<=n;++j) sum-=pq.top(),pq.pop();
			ans=max(ans,sum);
		}
		else
		{
			for(int j=0;j<=na;++j)//左边拿多少 
			{
				sum=0;
				while(!pq.empty()) pq.pop(); 
				int right=na-j;
				for(int pos=1;pos<=j;++pos) pq.push(v[pos]),sum+=v[pos];
				for(int pos=n;pos>=n-right+1;--pos) pq.push(v[pos]),sum+=v[pos];
				for(int tt=1;tt<=i&&tt<=na;++tt) 
				{
					sum-=pq.top();
					pq.pop();
				}
				ans=max(ans,sum);
			}
		}
		//printf("%d %d\n",i,ans);
	}
	return ans;
}
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		cin>>v[i];
	cout<<max(solve(k),solve(k-1))<<endl;
	return 0;
}


Measured memory_bytes: 256
from sys import exit

sa = input()
sb = input()
sc = input()

turn = 'a'
while True:
  if turn == 'a':
    if len(sa) == 0:
      print('A')
      exit()
    else:
      turn = sa[0]
      sa = sa[1:]
  if turn == 'b':
    if len(sb) == 0:
      print('B')
      exit()
    else:
      turn = sb[0]
      sb = sb[1:]
  if turn == 'c':
    if len(sc) == 0:
      print('C')
      exit()
    else:
      turn = sc[0]
      sc = sc[1:]

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed
#define endl '\n'

const ll MOD = 1e9 + 7;
struct mint {
    ll x;
    mint() : x(0) {}
    mint(ll x) : x((x % MOD + MOD) % MOD) {}
    mint& operator+=(const mint& r) { if ((x += r.x) >= MOD) { x -= MOD; } return *this; }
    mint& operator-=(const mint& r) { if ((x -= r.x) < 0) { x += MOD; } return *this; }
    mint& operator*=(const mint& r) { if ((x *= r.x) > MOD) { x %= MOD; } return *this; }
    mint& operator++() { if ((++x) >= MOD) { x -= MOD; } return *this; }
    mint operator++(int) { mint ret = x; if ((++x) >= MOD) { x-= MOD; } return ret; }
    mint& operator--() { if ((--x) < 0) { x += MOD; } return *this; }
    mint operator--(int) { mint ret = x; if ((--x) < 0) { x += MOD; } return ret; }
    mint operator+(const mint& r) { mint ret; return ret = x + r.x; }
    mint operator-(const mint& r) { mint ret; return ret = x - r.x; }
    mint operator*(const mint& r) { mint ret; return ret = x * r.x; }
    mint operator-() { return mint() - *this; }
    bool operator<(const mint& a) { return x < a.x; }
    bool operator>(const mint& a) { return x > a.x; }
    bool operator<=(const mint& a) { return x <= a.x; }
    bool operator>=(const mint& a) { return x >= a.x; }
    bool operator==(const mint& a) { return x == a.x; }
    bool operator!=(const mint& a) { return x != a.x; }
};
ostream& operator<<(ostream& os, const mint& r) { os << r.x; return os; }
ostream& operator>>(ostream& os, const mint& r) { os >> r.x; return os; }

void solve(istream& cin, ostream& cout) {
  int n;
  string s;
  cin >> n >> s;
  if (s.size() % 2 != 0) {
    cout << "No" << endl;
    return;
  }

  REP(i, s.size() / 2) {
    if (s[i] != s[i + s.size() / 2]) {
      cout << "No" << endl;
      return;
    }
  }
  cout << "Yes" << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
}
#endif


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n = int(input())
Univ = [[[0 for i in range(10)]for j in range(3)]for k in range(4)]
for i in range(n):
    b,f,r,v =[int(i)for i in input().split(' ')]
    Univ[b-1][f-1][r-1] += v

for b in range(4):
    for f in range(3):
        for r in range(10):
            print('',Univ[b][f][r],end="")
        print()
    if b<3:
        print("#"*20)

Measured memory_bytes: 7724
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		sc.nextLine();
		
		String[] map = new String[H];
		for (int i = 0; i < H; i++) {
			map[i] = sc.nextLine();
			if (!map[i].contains("#")) {
				String repeated = new String(new char[W]).replace("\0", " ");
				map[i] = repeated;
			}
		}
		
		for (int i = 0; i < W; i++) {
			boolean linedot = true;
			for (int j = 0; j < H; j++) {
				String s = map[j];
				
				if (s.charAt(i) == '#') {
					linedot = false;
					break;
				}
			}
			
			if (linedot) {
				for (int k = 0; k < H; k++) {
					String str = map[k];
					StringBuilder sb = new StringBuilder(str);
					sb.setCharAt(i, ' ');
					map[k] = sb.toString();
				}
			}
		}
		
		for (int i = 0; i < H; i++) {
			String ans = map[i].replaceAll(" ", "");
			if (ans.length() == 0) 
				continue;
			
			
			System.out.println(ans);
		}
		
	}
}

Measured memory_bytes: 27732
import sys
 
N = int(input())
S = list(str(input()))
 
if(N%2==1 or N==0):
    print("No")
    sys.exit()
 
if(N==2 and S[0]!=S[1]):
    print("No")
    sys.exit()
 
for x in range(0, N//2-1):
    if(S[x]!=S[N//2+x]):
        print("No")
        sys.exit()
 
print("Yes")

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <ctime>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	int n; cin >> n;
	vector<int> V(n+1),W(n+1);
	rep(i,n) cin >> V[i+1] >> W[i+1];
	int M = 1024;
	vector<vector<pair<int,int>>> vp(M+1);
	vp[0].emplace_back(0,0);
	REP(i,1,M+1){
		if(i > n) break;
		vector<pair<int,int>> vv;
		for(auto b : vp[i/2]){
			vv.emplace_back(b);
			vv.emplace_back(b.first+W[i], b.second+V[i]);
		}
		sort(all(vv));
		int now = -1;
		for(auto b : vv){
			if(now < b.second){
				vp[i].push_back(b);
				now = b.second;
			}
		}
	}
	int q; cin >> q;
	while(q--){
		int v,L; scanf("%d%d",&v,&L);
		vector<pair<int,int>> acc;
		acc.emplace_back(0,0);
		while(v > M){
			vector<pair<int,int>> tmp;
			for(auto b : acc){
				tmp.emplace_back(b);
				tmp.emplace_back(b.first+W[v], b.second+V[v]);
			}
			acc = tmp;
			v >>= 1;
		}
		int ans = 0;
		for(auto b : acc){
			pair<int,int> pp = {L-b.first, inf};
			auto itr = lower_bound(all(vp[v]), pp);
			if(itr != vp[v].begin()){
				itr--;
				chmax(ans, (*itr).second + b.second);
			}
		}
		cout << ans << "\n";
	}
}

Measured memory_bytes: 10844
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;

int main(void) {
    i64 n, m, ans = 0, p[16];
    bool d[16][16] = {};
    cin >> n >> m;
    for (i64 i = 0; i < m; i++) {
        i64 k;
        cin >> k;
        for (i64 j = 0; j < k; j++) {
            i64 s;
            cin >> s;
            s--;
            d[i][s] = true;
        }
    }
    for (i64 i = 0; i < m; i++) cin >> p[i];
    for (i64 b = 0; b < (1 << n); b++) {
        bool flag = true;
        for (i64 i = 0; i < m; i++) {
            i64 c = 0;
            for (i64 j = 0; j < n; j++) {
                if (d[i][j] && ((b >> j) & 1)) c++;
            }
            if (c % 2 != p[i]) flag = false;
        }
        if (flag) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

const int MAX_N=10000;
struct edge{
    int src,dst,cost;
    edge(int src,int dst,int cost):
    src(src),dst(dst),cost(cost){}
    };
bool operator < (const edge &e,const edge &f){
    return e.cost!=f.cost?e.cost<f.cost:
    e.src!=f.src?e.src<f.src:e.dst<f.dst;
}
struct UnionFind{
    int par[MAX_N]; 
    void init(int n){
        for (int i=0;i<n;i++) par[i] = i;
    } 
    int find(int x){
        if (x==par[x]) return (x);
        return (par[x]=find(par[x]));
    }
    void unite(int x, int y){
        x=find(x);y=find(y);       
        if(x==y) return;
        par[x] = y;
    } 
    bool same(int x, int y){
        return (find(x) == find(y));
    } 
};
vector<edge> ve;
int inf=INT_MAX;
int v,e;
int kruskal(){
    sort(ve.begin(),ve.end());
    UnionFind uf;
    uf.init(v);
    int res=0;
    rep(i,ve.size()){
        edge e=ve[i];
        if(!uf.same(e.src,e.dst)){
            uf.unite(e.src,e.dst);
            res +=e.cost;
        }
    }
    return res;
}
int main(){
    int e,r,s,t,ds;
    cin>>v>>e;
    rep(i,e){
        cin>>s>>t>>ds;
        ve.pb(edge(s,t,ds));
    }
    cout<<kruskal()<<endl;
    return 0;
}

Measured memory_bytes: 4512
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math") 
///#pragma GCC target("avx2")
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <iomanip>
#include <cassert>
#include <functional>
#include <ctime>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <climits>
#include <numeric>

using namespace std;
#define open_streams ifstream fin("olympiad.in");ofstream fout("olympiad.out")
#define close_streams fin.close();fout.close()
#define speed cout.tie(0);cin.tie(0);ios_base::sync_with_stdio(0)
#define ll long long
#define ull unsigned long long
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define UNIQ(a) a.resize(unique(all(a)) - a.begin())
#define eps 1e-6
//const double PI = M_PI;
const int INF = INT_MAX;
const ll limit = 1LL * 4e18;
const int MOD = 1e9 + 711;
const int MOD2 = 1e9 + 933;
//---------------------------------------------------------------------------
const int mod = 1e9 + 7;
const int maxn = 2e5 + 100;





signed main() {
	speed;	
	int a, b, c;
	cin >> a >> b >> c;
	cout << c << ' ' << a << ' ' << b;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>

#define ld  long double
#define ll  long long int
#define ull unsigned long long int
#define pb  push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i,n) for(int i=0;i<n;i++)

const int    INF = 100100100;
const double EPS = 1e-9;

//切り上げ整数除算
int divRoundUp(const int& a, const int& b) { return (a + b - 1) / b; }
//四捨五入
int roundOff(const double& a) { return (int)(a + 0.5); }

using namespace std;

void Main() {
	int N; cin >> N;
	vector<int> ar(N);
	for (auto& a : ar) {
		cin >> a;
	}

	int sum = 0;
	for (int i = 0; i < N; ++i) {
		for (int j = i + 1; j < N; ++j) {
			sum += ar[i] * ar[j];
		}
	}
	cout << sum << "\n";
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	Main();

	return 0;
}

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

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

    if  ( N < 10 ) {
        cout << "Yes" << endl;
        return 0;
    }
    if ( 81 < N) {
        cout << "No" << endl;
        return 0;
    }

    for (int i = 2; i <= 9; i++ ){
        if (N % i == 0 ) {
            if( N / i <= 9 ){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;

    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int a, b, k;
    int n[1000000] = {0};
    int j = 0;
    scanf("%d%d%d", &a, &b, &k);
    for(int i = 1; i <= a || i <= b; i++){
        if(a%i == 0 && b%i == 0){
            n[j] = i;
            j++;
        }
    }
    printf("%d\n",n[j-k]);
    return 0;
}


Measured memory_bytes: 4096
import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)

    val min = scanner.nextInt()
    val max = scanner.nextInt()
    val size = scanner.nextInt()
    val list = mutableListOf<Int>()

    for(i in min until min+size) {
        if (i > max) {
            break
        }
        list.add(i)
    }

    for(i in max-size+1 .. max) {
        if (!list.contains(i) && i > min) {
            list.add(i)
        }
    }

    list.forEach {it -> println(it)}
}

Measured memory_bytes: 31260
n = int(input())
pos = [list(map(int, input().split())) for _ in range(n)]

def func(n, pos):
    c_t, c_x, c_y = 0, 0, 0

    for i in pos:
        d_t = i[0] - c_t
        z = abs(i[1] - c_x) + abs(i[2] - c_y)

        if z > d_t or (d_t - z) % 2 != 0:
            return "No"
        else:
            c_t, c_x, c_y = i[0], i[1], i[2]

    return "Yes"


print(func(n, pos))


Measured memory_bytes: 27008
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int M=1000000007;
int a[100003];
int main()
{
	int n,m;
	cin>>n>>m; a[0]=1;
	for (int i=1; i<=m; i++)
	{
	    int x;
		cin>>x; a[x]=-1;
	}
	if (a[1]==0) a[1]=1;
	for (int i=2; i<=n; i++)
	{
		if (a[i]==-1) continue;
		int res=0;
		if (a[i-1]!=-1) res+=a[i-1];
		if (a[i-2]!=-1) res+=a[i-2];
		a[i]=res%M;
	}

	cout << a[n];
}

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

#define inf 1000000000

int minCost(int n, int* height) {
	int* dp = new int[n + 1];
	dp[1] = 0;
	for (int i = 2; i <= n; i++) {
		int op1 = dp[i - 1] + abs(height[i - 1] - height[i]);
		int op2 = i == 2 ? inf : dp[i - 2] + abs(height[i - 2] - height[i]);
		dp[i] = min(op1, op2);
	}
	// for (int i = 1; i <= n; ++i)
	// {
	// 	cout << dp[i] << ", ";
	// }
	// cout << endl;
	return dp[n];
}

int main() {
	int n;
	cin >> n;
	int* height = new int[n + 1];
	for (int i = 1; i <= n ; ++i)
	{
		cin >> height[i];
	}
	cout << minCost(n, height) << endl;
}

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

#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FILL0(x) memset(x,0,sizeof(x))

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

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; }
 

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int N;
    cin >> N;

    int A[N];
    rep(i, N)
    {
        cin >> A[i];
    }

    int Q;
    cin >> Q;

    P BC[Q];
    rep(i, Q)
    {
        cin >> BC[i].first >> BC[i].second;
    }


    ll ans = 0;
    rep(i, N)
    {
        ans += A[i];
    }

    ll cnt[100010]={0};
    rep(i, N)
    {
        cnt[A[i]]++;
    }

    rep(i, Q)
    {
        ans-=cnt[BC[i].first]*BC[i].first;
        ans+=cnt[BC[i].first]*BC[i].second;
        cnt[BC[i].second]+=cnt[BC[i].first];
        cnt[BC[i].first]=0;

        cout << ans << endl;
    }



    return 0;

}


Measured memory_bytes: 6324
inputs = Array.new
while line = $stdin.gets
  inputs << line.chomp
end

n = inputs[0].to_i
a = inputs[1].split().map{|s| s.to_i }

# p [n, a]

mod = 1000000007

x1 = a.map{ |a| a*a }.inject(&:+)
x2 = a.inject(&:+)
x2 = x2 * x2

ans = (x2 - x1) / 2
ans %= mod

puts ans


Measured memory_bytes: 37320
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN3(x,a,b);
  if(x+min(a,b) >= max(a,b)) OUT(0);
  else OUT(abs(x+min(a,b)-max(a,b)));
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include <limits.h>
#include<stdlib.h>


int main(void) {
	int a;
	int ans;
	scanf("%d", &a);
	ans = a + a * a + a * a * a;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1728
#include <stdio.h>

int main()
{
    int H,W;
    for (;;) {
        scanf("%d %d", &H, &W);

        if ((H == 0)&&(W == 0))
            break;

        int i,j;
        for (i = 0; i < H; i++) {
            if ((i == 0)||(i == H - 1)) {
                for (j = 0; j < W; j++) {
                      printf("#");
                }
            } else {
                for (j = 0; j < W; j++) {
                    if ((j == 0)||(j == W - 1)) {
                        printf("#");
                    } else {
                        printf(".");
                    }

                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return(0);
}



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

int SelectionSort( int* a, int b )
{
    int min, count = 0;

    for( int i = 0; i <= b - 1; i++ )
    {
        min = i;
        for( int j = i; j <= b - 1; j++ )
        {
            if( a[min] > a[j] )
                min = j;
        }
        if( min != i )
        {
            int temp = a[i];
            a[i] = a[min];
            a[min] = temp;
            count++;
        }
    }
    return count;
}

int main()
{
    int n, c;

    cin >> n;

    int r[n];

    for( int i = 0; i < n; i++ )
        cin >> r[i];

    c = SelectionSort( r, n );

    for( int i = 0; i < n - 1; i++ )
        cout << r[i] << " ";
    cout << r[n-1] << endl;

    cout << c << endl;

    return 0;
}


Measured memory_bytes: 3112
n, w = [int(e) for e in input().split()]
d = [[int(e) for e in input().split()] for i in range(n)]
t = {}
t[w] = 0
for i in range(n):
  keys = list(sorted(t.keys())) # sort しないと品物iを複数回ナップサックに詰める可能性がある
  tw, tv = d[i]
  for j in keys:
    nw = j - tw
    if nw < 0:
      continue
    nv = t[j] + tv
    if nw in t:
      if nv > t[nw]:
        t[nw] = nv
    else:
      t[nw] = nv
print(max(t.values()))

Measured memory_bytes: 121348
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    vector<int>n(5);
    int ans=644;
    int num=0;
    int a;
    rep(i,5){
        cin>>n.at(i);
    }
    do{
        for(int i=0;i<5;i++){
            if(num%10==0){
                num+=n.at(i);
            }else{
                num+=10-num%10;
                num+=n.at(i);
            }
        }
        if(num<ans){
            ans=num;
        }
        num=0;
    }while(next_permutation(all(n)));

    cout<<ans<<endl;


}

Measured memory_bytes: 3648
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

int a[555][555];
int cumsum [555][555];

void solve() {
    int N, M, Q; cin >> N >> M >> Q;
    for (int i = 0; i < M; i++) {
        int l, r; cin >> l >> r;
        a[r][l]++;
    }

    for (int r = 1; r <= N; r++) {
        for (int l = 1; l <= N; l++) {
            cumsum[r][l] = cumsum[r-1][l] + cumsum[r][l-1] - cumsum[r-1][l-1] + a[r][l];
        }
    }

    for (int i = 0; i < Q; i++) {
        int l, r; cin >> l >> r;
        cout << cumsum[r][r] - cumsum[r][l-1] - cumsum[l-1][r] + cumsum[l-1][l-1] << '\n';
    }
}

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

    solve();

    return 0;
}

Measured memory_bytes: 5820