akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(){
  int i,N,T,A,H[1000],ans=1;
  double min=100000;
  scanf("%d",&N);
  scanf("%d %d",&T,&A);
  for(i=0;i<N;i++){
    scanf("%d",&H[i]);
    if(min>fabs((double)A-((double)T-(double)H[i]*0.006))){
      min=fabs((double)A-((double)T-(double)H[i]*0.006));
      ans=i+1;
    }
  }
  printf("%d\n",ans);
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <set>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
using namespace std;

lli Lucas(lli n)
{
	lli ans;
	if (n == 0)ans = 2;
	else if (n == 1)ans = 1;
	else {
		lli L_pre = 2;
		lli L_next = 1;
		rep(i, 0, n - 1) {
			ans = L_pre + L_next;
			L_pre = L_next;
			L_next = ans;
		}
	}
	return ans;
}

int main(void)
{
	lli N; cin >> N;
	lli f = Lucas(N);
	cout << f << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
signed main() {
	int n; cin >> n;
	int p = 0, cnt = 0;
	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		p = max(p, a);
		cnt += a;
	}cout << cnt - p / 2 << endl;
}

Measured memory_bytes: 256
X,Y = map(int,input().split())
e = 0
temp_X = X
if Y%2 != 0:
    print("No")
    quit()
else:
    while temp_X >= 0:
        i = (temp_X*2) + (e*4)
        if i == Y:
            print("Yes")
            quit()
        temp_X -= 1
        e += 1
print("No")

Measured memory_bytes: 9184
import heapq

INF = float("inf")

N = int(input())
G = [tuple(map(int, input().split())) for _ in range(N-1)]
Q, K = map(int, input().split())
W = [tuple(map(int, input().split())) for _ in range(Q)]

E = [[] for _ in range(N+1)]
for a,b,c in G:
	E[a].append((c,b))
	E[b].append((c,a))

# Kからの最短距離
# dijkstra_heap
D = [INF,] * (N+1)
visited = [0,] * (N+1)

D[K] = 0
visited[K] = 1
qE = []

for e in E[K]:
	heapq.heappush(qE, e)

while qE:
	# コストが小さい順に取り出す
	c, b = heapq.heappop(qE)
	if visited[b]:
		continue
	D[b] = c
	visited[b] = 1

	# 現在地b → 次のエッジを追加
	for nc, nb in E[b]:
		if not visited[nb]:
			heapq.heappush(qE, (D[b]+nc, nb))

for x, y in W:
	print(D[x]+D[y])


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

int main(){
    int n; cin >> n;
    int b[105],a[105];
    rep(i,n-1) cin >> b[i+1];
    b[0] = b[1];
    b[n] = b[n-1];
    for(int i = 0; i < n; i++){
        int idx = n - 1 - i; 
        a[idx] = b[idx];
        if(a[idx] > b[idx+1] ){
            a[idx] = b[idx+1];
        }
    }
    int ans = 0;
    rep(i,n) ans += a[i];
    cout << ans << endl;
    return 0;
}

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

#define all(v) v.begin(), v.end()
#define mp make_pair
#define EPS (int)1e-9
#define PI acos(-1)
#define endl '\n'
#define pb push_back
#define fi first
#define se second

using namespace std;
using ld = long double;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;

const int mod = 1000000007;


int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n, a;
	cin >> n >> a;

	cout << n*n-a << endl;
	return 0;	
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(){
    int n;
    scanf("%d",&n);
    int* p=(int*)malloc(sizeof(int)*n);
    int sum=0;
    int maxp=0;
    for(int i=0;i<n;i++){
	scanf("%d",&p[i]);
	sum+=p[i];
	if(maxp<p[i])
	    maxp=p[i];
    }
    printf("%d\n",sum-maxp/2);
    return 0;
}


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

int main(){
    int A,B,C,D,E;
    int d;
    int i;
    int d_i;
    int d_max=-1;
    int result=0;
    cin>>A;
    cin>>B;
    cin>>C;
    cin>>D;
    cin>>E;
    vector<int> Input={A,B,C,D,E};
    vector<int> diff={0,0,0,0,0};
    for(i=0;i<5;i++){
        d=10-Input[i]%10;
        if(d==10){
            d=0;
        }
        diff[i]=d;
        if(d>d_max){
            d_max=d;
            d_i=i;
        }
    }
    
    for(i=0;i<5;i++){
        if(i!=d_i){
            result+=Input[i]+diff[i];
        }else{
            result+=Input[i];
        }
    }
    cout<<result<<endl;
    return 0;
}

Measured memory_bytes: 256
from math import log2
import decimal

N, K = map(int, input().split())

decimal.getcontext().prec = 28

ans = decimal.Decimal(0)

for i in range(1, N+1):
    if i < K:
        power = -(-(log2(K) - log2(i))//1)
        prob = decimal.Decimal(1/((2**power) * N))
    else:
        prob = decimal.Decimal(1/N)

    #print(prob)
    ans = decimal.Decimal(ans + prob)
    #print(ans)

print(ans)

Measured memory_bytes: 155564
// clang-format

#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;

using lli = long long int;

void solve(std::vector<long long> T, std::vector<long long> A,
           std::vector<long long> B) {
  lli at = A[0] * T[0] + A[1] * T[1];
  lli bt = B[0] * T[0] + B[1] * T[1];
  if(at==bt){
    cout << "infinity"<<endl;
    return;
  }
  if(at < bt){
    swap(A, B);
    swap(at, bt);
  }
  if(A[0] * T[0] > B[0] * T[0]){
    cout << 0 << endl;
    return ;
  }
  lli diff = at - bt;
  lli up = 1e16;
  lli low = 0;
  while(up-low>1){
    lli mid = (up+low)/2;
    lli d = mid;
    lli att = A[0] * T[0] + d;
    lli btt = B[0] * T[0];
    if(att > btt){
      up = mid;
    }else {
      low = mid;
    }
    //cout << up << " "<< low << endl;
  }
  lli d = low;
  lli num = low/diff;
  lli att = A[0] * T[0] + num * diff;
  lli btt = B[0] * T[0];
  lli ans = 2 * (num+1) - 1;
  if(att==btt) ans--;
  cout << ans << endl;
}

int main() {
  int a;
  std::vector<long long> T(2);
  for (int i = 0; i < 2; i++) {
    scanf("%lld", &T[i]);
  }
  std::vector<long long> A(2);
  for (int i = 0; i < 2; i++) {
    scanf("%lld", &A[i]);
  }
  std::vector<long long> B(2);
  for (int i = 0; i < 2; i++) {
    scanf("%lld", &B[i]);
  }
  solve(std::move(T), std::move(A), std::move(B));
  return 0;
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int L=in();
	auto V=vecin(L);
	stack<int> S;
	set<int> H;
	REP(i,L){
		if(V[i]>0){
			if(H.find(V[i])!=H.end()){
				out(i+1);
				return 0;
			}
			S.push(V[i]);
			H.insert(V[i]);
		}
		else{
			if(S.empty()){
				out(i+1);
				return 0;
			}
			auto P=S.top();
			if(P!=abs(V[i])){
				out(i+1);
				return 0;
			}
			S.pop();
			H.erase(P);
		}
	}
	out("OK");
	return 0;
}


Measured memory_bytes: 3172
import sys
input = sys.stdin.readline

N=int(input())
A=[int(input()) for i in range(N)]
A.sort()
A=[0]+A

XOR=0
for i in range(1,N+1):
    if (A[i]-A[i-1])%2==0:
        continue
    else:
        XOR=XOR^(N-(i-1))

    #print(XOR)

if XOR!=0:
    print("first")
else:
    print("second")

Measured memory_bytes: 7888
//  Created by conan1024hao on 2019/11/24.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll>P;
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define PI acos(-1.0)
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll cmp(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    ll m,n=0,s=0;
    cin>>m;
    for(ll i=0;i<m;i++){
        ll d,c;
        cin>>d>>c;
        n+=c;
        s+=d*c;
    }
    ll ans=n-1+(s-1)/9;
    cout<<ans<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


Measured memory_bytes: 256
n,m = map(int,input().split())
t = False
a = list(map(int,input().split()))
a.sort()
b = []
for i in range(m):
    b.append(list(map(int,input().split())))
b = sorted(b, key=lambda x: x[1],reverse=True)
cnt = 0
for i in range(m):
    for j in range(b[i][0]):
        if cnt > n-1 or b[i][1]<a[cnt]:
            t = True
            break
        a[cnt] = b[i][1]
        cnt+=1
    if t==True:
        break
print(sum(a))
    


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

int main() {
   string w;
   cin >>w;
   map<char,int> mp;
   rep(i,w.size()){
       mp[w[i]]++;
   }
   for(auto x: mp){
       if(x.second%2!=0){
           cout <<"No" << endl;
           return 0; 
       }    
   }
   cout << "Yes" <<endl;
}


Measured memory_bytes: 256
class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
    # ノードxのrootノードを見つける
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def unite(self, x, y):
    # 木の併合、入力は併合したい各ノード⇒(a,b)
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
    # ノードxが属する木のサイズを返す
        return -self.parents[self.find(x)]

    def same(self, x, y):
    # 入力ノード(x,y)が同じグループに属するかを返す
        return self.find(x) == self.find(y)

    def members(self, x):
    #ノードxが属するメンバーをリスト形式で返す
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
    #親全てをリスト形式で返す
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
    #グループ数の合計を返す
        return len(self.roots())

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

n,m=map(int,input().split())
u=UnionFind(n)
for i in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    u.unite(a,b)
ans=u.roots()
print(len(ans)-1)


Measured memory_bytes: 73796
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
// #include <numeric>
#include <complex>

#define FAST ios_base::sync_with_stdio(false); cin.tie(0)
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define repr(i, a, b) for(int i=int(a); i>=int(b); i--)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
typedef long long int ll;
#define iceil(x,y) (x+y-1)/y

using namespace std;
typedef pair<int, int> P;

int N,M,Q;
vector<vector<int>> sum;

int buildSumTable(vector<int> L, vector<int> R) {
	sum = vector<vector<int>>(N+1, vector<int>(N+1,0));
	rep(i,M) sum[L[i]][R[i]]++;

	rep(i,1,N+1) {
		rep(j,1,N+1) {
			sum[i][j] += sum[i-1][j];
			sum[i][j] += sum[i][j-1];
			sum[i][j] -= sum[i-1][j-1];
		}
	}
	return 0;
}

int getSumRange(int L, int R) {
	int ans = sum[R][R] - sum[R][L-1] - sum[L-1][R] + sum[L-1][L-1];
	return ans;
}

int main() {
	FAST;
	cin >> N >> M >> Q;
	vector<int> L(M), R(M), p(Q), q(Q);
	rep(i,M) cin >> L[i] >> R[i];
	rep(i,Q) cin >> p[i] >> q[i];
	buildSumTable(L,R);

	rep(i,Q) {
		int ans = getSumRange(p[i], q[i]);
		cout << ans << "\n";
	}

	return 0;
}

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

int main()
{
  string s;
  cin>>s;
  int c=1;
  for(int i=0;i<s.size();i++)
  {
      if((i+1)%2==0){
            if(s[i]=='R')
                {c=0;}
        }
      else{
            if(s[i]=='L')
                {c=0;}}
  }

  if(c)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
import sys

board=[[0]*10 for i in xrange(10)]

large=[[0,0,1,0,0],
       [0,1,1,1,0],
       [1,1,1,1,1],
       [0,1,1,1,0],
       [0,0,1,0,0],]
middle=[[0,0,0,0,0],
        [0,1,1,1,0],
        [0,1,1,1,0],
        [0,1,1,1,0],
        [0,0,0,0,0],]
small=[[0,0,0,0,0],
       [0,0,1,0,0],
       [0,1,1,1,0],
       [0,0,1,0,0],
       [0,0,0,0,0],]

size=[0,small,middle,large]

def isOnBoard(y,x):
    return 0<=y<10 and 0<=x<10

for line in sys.stdin.readlines():
    x,y,s=map(int,line.strip().split(","))
    for i in xrange(-2,3):
        for j in xrange(-2,3):
            if isOnBoard(y+i,x+j):
                board[y+i][x+j]+=size[s][i+2][j+2]

print len([j for i in board for j in i if j==0])
print max([j for i in board for j in i])

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

using L = long long;
using Matrix = vector<vector<int>>;
constexpr int mod = int(1e9) + 7;

int mult(int a, int b) {
	return a * L(b) % mod;
}
int add(int a, int b) {
	return (a + b) % mod;
}

Matrix mult(Matrix a, Matrix b) {
	int n = int(a.size());
	Matrix c(n, vector<int>(n));

	for(int i = 0; i < n; ++i)
		for(int j = 0; j < n; ++j)
			for(int k = 0; k < n; ++k)
				c[i][j] = add(c[i][j], mult(a[k][j], b[i][k]));
	return c;
}

Matrix pot(Matrix m, L k) {
	int n = int(m.size());
	Matrix pot2 = m;

	Matrix answer(n, vector<int>(n));
	for(int i = 0; i < n; ++i)
		answer[i][i] = 1;

	while(k) {
		if(k % 2 == 1)
			answer = mult(answer, pot2);
		pot2 = mult(pot2, pot2);
		k >>= 1;
	}
	return answer;
}

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

	int n;
	L k;
	cin >> n >> k;
	Matrix graph(n, vector<int>(n));
	for(int v = 0; v < n; ++v)
		for(int u = 0; u < n; ++u)
			cin >> graph[v][u];

	graph = pot(graph, k);

	int sum = 0;
	for(int v = 0; v < n; ++v)
		for(int u = 0; u < n; ++u)
			sum = add(sum, graph[v][u]);
	cout << sum << '\n';
}


Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
#define CRP(t, x) const t &x
#define OPL(t, x) bool operator<(CRP(t, x)) const
#define FIL(x, v) memset(x, v, sizeof(x))
#define CLR(x) FIL(x, 0)
#define NE1(x) FIL(x, -1)
#define INF(x) FIL(x, 0x3f)
#ifndef _DEBUG
#define _DEBUG 0
#endif // !_DEBUG
#define IFD if (_DEBUG)
typedef long long ll, i64;
const int N = 1e6 + 60;
int a[N];
int main()
{
    int n, k;
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++) scanf("%d", a + i);
    printf("%d", (n - 1 + k - 2) / (k - 1));
    return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N, K, S;
    cin >> N >> K >> S;
    vector<int> ans(N);
    rep(i, K) ans[i] = S;
    rep(i, K, N) {
        if (S < 3) ans[i] = 3;
        else ans[i] = S - 1;
    }

    rep(i, N) cout << ans[i] << (i == N - 1 ? '\n' : ' ');
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
//using namespace __gnu_pbds;

typedef long long int ll;
typedef pair<ll,ll> pp;
typedef long double ld;
typedef vector<pp> vpl;
//typedef tree<pair<ll,ll>, null_type, less<pair<ll,ll>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 

 
const ll N = 200005;
const ll mod = 1000000007;
const long long int inf = 1e9;

#define MP make_pair
#define endl "\n"
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define repb(i,n) for(ll i=1;i<n-1;i++) 
#define trace(i,a) for(auto i=a.begin();i!=a.end();i++) 
#define mtrace(i,a) for(auto i=a.begin();i!=a.end();i++)  cout<<i->first<<" "<<i->second<<endl;   
 
const ld pi = 3.14159265359;

mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}

 
void fastIO(void);
void decimal(int);
ll modmulti(ll, ll);
ll modadd(ll, ll);
ll modpower(ll, ll);
ll gcd(ll, ll );
ll modinv(ll);





int main(){
	ll n,k;
	cin>>n>>k;
	ll inv = modinv(2);
	ll sum = 0,c1=0,c2=0,c3=0;
	c1 = modmulti(n,n+1);
	c3 = modmulti(k,k-1);
	//cout<<"c1 = "<<c1<<" c3 = "<<c3<<endl;
	for(ll i = k;i<=n+1;i++){
		c3 = modmulti(i,i-1);
		c2 = modmulti(n-i,n+1-i);
		//cout<<"i = "<<i<<"inti = "<<c2<<endl;
		c2 = modadd(c1,modadd(mod-c2,mod-c3));
		c2 = modmulti(c2,inv);
		c2 = (c2+1)%mod;
		//cout<<"i = "<<i<<"c2 = "<<c2<<endl;
		sum = modadd(sum,c2);
	}
	cout<<sum<<endl;



		



		
	

		
}
	


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
void fastIO(void)
{  ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
}
 
void decimal(int n){
   cout<<fixed;
   cout<<setprecision(n);
}
ll modmulti(ll a, ll b){
   return ((a%mod)*1ll*(b%mod))%mod;
}
ll modadd(ll a, ll b){
   ll asdfgh =  ((a%mod)+(b%mod)+mod+mod)%mod;
   asdfgh = (asdfgh+mod)%mod;
   return asdfgh;
}
ll modpower(ll a, ll n){
   if(n==0) return 1;
   if(n==1) return a%mod;
   ll b = modpower(a,n/2);
   b = modmulti(b,b);
   if(n%2==0) return b;
   return modmulti(a,b);
}
ll gcd(ll a, ll b){
   if(b==0)
      return a;
   return gcd(b,a%b);
}
ll modinv(ll a){
   return modpower(a,mod-2);
}

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

ll mod_pow(ll x, ll p){
	ll res=1;
	ll n=x;
	while(p>0){
		if((p&1)==1)res=(res*n)%MOD;
		n=(n*n)%MOD;
		p=(p>>1);
	}
	return res;
}


ll mygcd(ll a, ll b){
    ll m=max(abs(a),abs(b));
    ll n=min(abs(a),abs(b));
    while(n!=0){
        ll tmp=n;
        n=m%n;
        m=tmp;
    }
    return m;
}
int main() {

    int N;
    cin>>N;
    map<pair<ll,ll>,ll> piwashi;
    map<pair<ll,ll>,ll> miwashi;
    ll zero=0;
    for (int i = 0; i < N; i++){
        ll A,B;
        cin>>A>>B;
        if(A==0&&B==0){
            zero++;
            continue;
        }
        ll g=mygcd(A,B);
        A/=g;B/=g;
        if(A<0){
            A*=-1;B*=-1;
        }
        if(A==0&&B<0)B=1;
        if(B<=0){
            miwashi[make_pair(A,B)]=miwashi[make_pair(A,B)]+1;
        }else{
            piwashi[make_pair(A,B)]=piwashi[make_pair(A,B)]+1;
        }
    }
    ll ans=1;
    for(auto x:piwashi){
        auto key=x.first;
        ll tmp=mod_pow(2,x.second);
        pair<ll,ll> bad=make_pair(key.second,-key.first);
        tmp+=mod_pow(2,miwashi[bad]);
        tmp--;
        tmp%=MOD;
        miwashi.erase(bad);
        ans*=tmp;
        ans%=MOD;
    }
    for(auto x:miwashi){
        ans*=mod_pow(2,x.second);
        ans%=MOD;
    }
    ans--;//choose no iwashi
    ans+=zero;
    ans+=MOD;
    ans%=MOD;
    cout<<ans<<endl;
}

Measured memory_bytes: 15928
fn main() {
    let (n, m) = {
        let v = read_vec::<usize>();
        (v[0], v[1])
    };
    let mut g: Vec<Vec<usize>> = Vec::new();
    let mut seen: Vec<bool> = Vec::new();
    for _ in 0..n {
        g.push(Vec::new());
        seen.push(false);
    }
    for _ in 0..m {
        let (a, b) = {
            let v = read_vec::<usize>();
            (v[0]-1, v[1]-1)
        };
        g[a].push(b);
        g[b].push(a);
    }

    seen[0] = true;
    let ret = dfs(0, 100, &g, &mut seen);
    println!("{}", ret);
}

fn dfs(c: usize, p: usize, g: &Vec<Vec<usize>>, seen: &mut Vec<bool>) -> usize {
    let mut all_visited = true;
    for i in 0..seen.len() {
        if seen[i] == false {
            all_visited = false;
        }
    }
    if all_visited {
        return 1;
    }

    let mut ret = 0;
    for &n in &g[c] {
        if n == p { continue; }
        if seen[n] { continue; }
        seen[n] = true;
        ret += dfs(n, c, g, seen);
        seen[n] = false;
    }
    return ret;
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int flag = 1, count = 0, i;
        int[] a = new int[100];

        for (i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        while (flag == 1) {
            flag = 0;
            for (i = n - 1; i >= 1; i--) {
                if (a[i] < a[i - 1]) {
                    a[i] = a[i] + a[i - 1];
                    a[i - 1] = a[i] - a[i - 1];
                    a[i] = a[i] - a[i - 1];
                    count++;
                    flag = 1;
                }
            }
        }
        for (i = 0; i < n; i++) {
            if(i==n-1){
                System.out.printf("%d\n",a[i]);
            }else{
            System.out.printf("%d ", a[i]);
            }
        }
        System.out.printf("%d\n", count);
        sc.close();
    }
}


Measured memory_bytes: 26572
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
void Say(bool say, string a = "Yes", string b = "No"){cout << (say ? a : b) << endl;};

int main(){

    string s;
    cin >> s;
    sort(s.begin(), s.end());
    Say(s[0] == s[1] && s[1] != s[2] && s[2] == s[3]);

    return 0;
}

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

template <typename T>
T pow(T a, long long n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}

template <int mod>
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long x_) {
        if ((x = x_ % mod + mod) >= mod) x -= mod;
    }
    ModInt& operator+=(ModInt rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    ModInt& operator-=(ModInt rhs) {
        if ((x -= rhs.x) < 0) x += mod;
        return *this;
    }
    ModInt& operator*=(ModInt rhs) {
        x = (unsigned long long)x * rhs.x % mod;
        return *this;
    }
    ModInt& operator/=(ModInt rhs) {
        x = (unsigned long long)x * rhs.inv().x % mod;
        return *this;
    }

    ModInt operator-() const { return -x < 0 ? mod - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return pow(*this, mod - 2); }

    friend ostream& operator<<(ostream& s, ModInt<mod> a) {
        s << a.x;
        return s;
    }
    friend istream& operator>>(istream& s, ModInt<mod>& a) {
        s >> a.x;
        return s;
    }
};

using mint = ModInt<1000000007>;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    vector<vector<mint>> dp(n + 1, vector<mint>(13));
    dp[0][0] = 1;
    for (int i = 0; i < n; i++) {
        if (s[i] == '?') {
            for (int j = 0; j < 13; j++) {
                for (int k = 0; k < 10; k++) {
                    dp[i + 1][(j * 10 + k) % 13] += dp[i][j];
                }
            }
        } else {
            for (int j = 0; j < 13; j++) {
                dp[i + 1][(j * 10 + s[i] - '0') % 13] += dp[i][j];
            }
        }
    }
    cout << dp[n][5] << endl;
}

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

int main(){
    int n;
    cin>>n;
    vector<string> s(n);
    int cnt1=0;
    int cnt2=0;
    int cnt3=0;
    int cnt4=0;
    rep(i,n){
        cin>>s[i];
        if(s[i]=="AC") cnt1++;
        else if(s[i]=="WA") cnt2++;
        else if(s[i]=="TLE") cnt3++;
        else if(s[i]=="RE") cnt4++;   
    }
    cout<<"AC"<<" x "<<cnt1<<"\n";
    cout<<"WA"<<" x "<<cnt2<<"\n";
    cout<<"TLE"<<" x "<<cnt3<<"\n";
    cout<<"RE"<<" x "<<cnt4<<"\n";
    return 0;
}

Measured memory_bytes: 6348
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
constexpr long MOD = 1e9 + 7;
using namespace std;

long digitsum(long b, long n) {
    if (n < b) return n;
    else return digitsum(b, n / b) + n % b;
}


int main() {
    long n, s;
    cin >> n >> s;
    
    if (s == n) {
        cout << n + 1 << endl;
        return 0;
    }
    
    if (n < s) {
        cout << -1 << endl;
        return 0;
    }
    
    for (int i = 2; i < sqrt(n) + 1; i++) {
        if (digitsum(i, n) == s) {
            cout << i << endl;
            return 0;
        }
    }
    
    long minb = 1e18;
    for (int i = 1; i < sqrt(n); i++) {
        long b = (n - s) / i + 1;
        if (b >= 2 && digitsum(b, n) == s) {
            minb = min(minb, b);
        }
    }
    if (minb != 1e18) {
        cout << minb << endl;
    } else {
        cout << -1 << endl;
    }
}



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

const int nm = 1e5;
int n;
int a[nm];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	int idx = 0;
	for (int i = 0; i < n - 1; i++)
		if (abs(a[i] * 2 - a[n - 1]) < abs(a[idx] * 2 - a[n - 1]))
			idx = i;
	cout << a[n - 1] << " " << a[idx] << endl;
}


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

int combination(int n, int r, int x)
{
    if (r == 1)
        return (n >= x) ? 1 : 0;

    int count = 0;
    for (int i = n; i > 0; i--)
        if (x - i > 0)
            count += combination(i - 1, r - 1, x - i);

    return count;
}

int main(void)
{
    int n, x;

    while (cin >> n >> x && n || x)
        cout << combination(n, 3, x) << endl;

    return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1e9+7
#define PI acos(-1.0)
#define ll long long
//---------------------------
int H,W,D;
int abs(int x){
  return max(-x,x);
}
int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);



  cin>>H>>W>>D;
  int px[90001],py[90001];
  REP(i,H){
    REP(j,W){
      int A;cin>>A;
      px[A]=i;py[A]=j;
    }
  }
  int Q; cin>>Q;
  int d[90001];
  for(int i=D+1; i<=H*W;i++) {
    d[i] = d[i-D]+abs(px[i]-px[i-D])+abs(py[i]-py[i-D]);
  }
  REP(i,Q){
    int l,r;cin>>l>>r;
    cout << d[r] - d[l]<<endl;
  }
  return 0;
}


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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    vector<int> a(n),cou(n,0);
    int b;
    REP(i,n)cin >> a[i];

    REP(i,m){
        cin >> b;
        int m=0;
        REP(i,n){
            if(m<a[i]&&b>=a[i]){
            cou[i]++;
            m=a[i];
            }
        }
    }
    int ma=0,res;
    REP(i,n){
        if(ma<cou[i]){
            ma=cou[i];
            res=i+1;
        }
    }
    cout << res << endl;
}



Measured memory_bytes: 3152
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder builder = new StringBuilder();

		String str;
		while(!(str = br.readLine()).equals("0")){
			int sum=0;
			for(int i=0; i<str.length();i++){
				sum += Integer.parseInt(str.substring(i, i+1));
			}
			builder.append(sum + "\n");
		}
		builder.delete(builder.length() -1 , builder.length());

		System.out.println(builder);
	}
}

Measured memory_bytes: 24600
#include<stdio.h>
#include<iostream>
using namespace std;

int from[30],to[30];
string S,T;
int main (){
    cin >> S >> T;
    int l = S.length();
    for(int i=0; i<26; i++) from[i]=-1,to[i]=-1;
    for(int i=0; i<l; i++){
        int a = S[i] - 'a';
        int b = T[i] - 'a';
        if( from[a] != -1 || to[b] != -1 ) {
            if( from[a] != b || to[b] != a ) {
                cout << "No" << endl;
                return 0;
            }
        }
        from[a] = b;
        to[b] = a;
    }
    cout << "Yes" << endl;
    return 0;
}


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

int main() {
	int N, o = 0, j = 0, k = 0, l = 0;
	cin >> N;
	string S;
	for(int i = 0; i < N; i++)
	{
		cin >> S;
		if(S == "P")
		{
			o++;
		}
		else if(S == "W")
		{
			j++;
		}
		else if(S == "G")
		{
			k++;
		}
		else if(S == "Y")
		{
			l++;
		}
	}

	if(l == 0)
	{
		cout << "Three" << endl;
	}

	else if(l != 0)
	{
		cout << "Four" << endl;
	}


}

Measured memory_bytes: 256
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define ms multiset
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("board.in");ofstream out("board.out");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); //uid<int> u1(5, 10); u1(rnd);

ll a,k,mod = 1e9+7;
vec<vec<int>> l;
vec<ll> o;

void dfs(int v, int p, int d, int num){
    if(d==0) o[v] = k;
    else o[v] = k-l[p].size()+num;
    int n = 0;
    for(int h : l[v]){
        if(h==p) continue;
        dfs(h,v,d+1, n++);
    }
}

int main() {
    fast;
    cin>>a>>k;
    o = vec<ll>(a);
    l = vec<vec<int>>(a, vec<int>());
    for(int q=0; q<a-1; q++){
        int x,y; cin>>x>>y; x--; y--;
        l[x].pb(y);
        l[y].pb(x);
    }
    dfs(0, -1, 0, 0);
    ll ans = 1;
    for(ll i : o) ans = (ans*max(0LL, i))%mod;
    cout<<ans;
}

Measured memory_bytes: 9216
#!/usr/bin/env python3
import sys


def solve(N: int, W: "List[int]"):
    import bisect
    ans = 100000000
    # W.sort()
    for i in range(1,N):
        # x = bisect.bisect_right(W,i)
        # if(W[x] == 'T'):
        #     x += 1
        ans = min(ans, abs(sum(W[:i])-sum(W[i:])))

    print(ans)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    W = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, W)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
import itertools
n,m,q=map(int,input().split())
qs = [list(map(int,input().split())) for i in range(q)]

max_ans = 0
for mid in itertools.combinations_with_replacement(range(1,m+1), n):
    sum_ans=0
    for q in qs:
        if mid[q[1]-1]-mid[q[0]-1] == q[2]:
            sum_ans += q[3]
    if sum_ans > max_ans:
        max_ans = sum_ans
        
print(max_ans)

Measured memory_bytes: 9136
#include <cstdio>
#include <string>
#include <iostream>
using namespace std;

int main(){
	string str;
	while (cin >> str){
		int joi = 0, ioi = 0;
		for (int i = 0; i < str.size() - 2; i++){
			if (str[i] == 'J' && str[i + 1] == 'O' && str[i + 2] == 'I') joi++;
			if (str[i] == 'I' && str[i + 1] == 'O' && str[i + 2] == 'I') ioi++;
		}
		cout << joi << endl;
		cout << ioi << endl;
	}
	return 0;
}

Measured memory_bytes: 1196
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main() {
	char a[N];
	f(i, N)a[i] = 0;
	long long b[30];
	int n, k;
	int x, y, z;
	long long s, ans;
	bool v = true;
	ans = 0;
	scanf("%d", &n);
	scanf("%s", a);
	f(i, 30)b[i] = 0;
	f(i, n) {
		b[a[i] - 97]++;
	}
	ans = 1;
	f(i, 30) {
		ans = ans * (b[i] + 1);
		ans = ans % MOD;
	}
	ans = (ans + MOD - 1) % MOD;
	printf("%lld\n", ans);


	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int main(void){
   double t, v, y;
   int N;
   while ( scanf("%lf", &v) != EOF ) {
      t = v / 9.8;
      y = 4.9 * t * t;
      y = y;
      N = ( y + 5 ) / 5;
      printf("%d\n", N + 1);
   }
   return 0;
}

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

const int N = 1005;

int main() {

	FAST;

	string s;
	cin >> s;
	if (s[0] == s[1] && s[1] == s[2]) {
		cout << "No\n";
	}
	else {
		cout << "Yes\n";
	}
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;

class Prog
{
    public Prog() { }
    public static int Main()
    {
        new Prog().calc();
        return 0;
    }

    Scanner cin;

    public void calc()
    {
        cin = new Scanner();
        int x = cin.nextInt();
        int y = cin.nextInt();

        if (x == 0)
        {
            if (y > 0) Console.WriteLine(y);
            else Console.WriteLine(Math.Abs(y) + 1);
            return;
        }
        if(y == 0)
        {
            if (x > 0) Console.WriteLine(x+1);
            else Console.WriteLine(Math.Abs(x));
            return;
        }

        if (large(x, y) && ((sei(x) && sei(y)) || (!sei(x) && !sei(y))))
        {
            Console.WriteLine(y - x);
            return;
        }

        if (!large(x, y) && ((sei(x) && sei(y)) || (!sei(x) && !sei(y))))
        {
            Console.WriteLine(x - y + 2);
            return;
        }

        int absmax = Math.Max(Math.Abs(x), Math.Abs(y));
        int absmin = Math.Min(Math.Abs(x), Math.Abs(y));

        Console.WriteLine(absmax - absmin + 1);

    }

    bool large(int x,int y) { return x < y; }
    bool sei(int x) { return x > 0; }
  }


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

}

Measured memory_bytes: 2648
#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <cmath>
#include <ctime>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector< vector<int> > vvi;
typedef vector<ll> vl;
typedef vector< vector<ll> > vvl;

#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define forv(i, v) forn(i, v.size())
#define all(v) v.begin(), v.end()
#define mp make_pair
#define pb push_back

int main() {
#ifdef NEREVAR_PROJECT
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int a, b;
    cin >> a >> b;
    if (a <= 0 && b >= 0) {
        cout << "Zero" << endl;
        return 0;
    }
    
    if (a > 0 || (b - a + 1) % 2 == 0) {
        cout << "Positive" << endl;
    } else {
        cout << "Negative" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {

		var inputArray = retreiveLongArray();
			var inputCount = 1;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			long K = inputArray[0];
			var inputArray2 = retreiveLongArray();
			long A = inputArray2[0];
			long B = inputArray2[1];

			if(A % K == 0) {
				Console.WriteLine("OK");
				return;
			}

			if (B % K == 0) {
				Console.WriteLine("OK");
				return;
			}

			if(B/K != A / K) {
				Console.WriteLine("OK");
				return;
			}

			//答えの出力
			Console.WriteLine("NG");

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}
	}
}


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

using ll = long long;
const int INF = 1e9+7;

void solve()
{
	map<ll,ll> hash;
	ll n;cin >> n; 
	ll sum = 0;
	for(int i=0;i<n;++i){
		int x;cin >> x;
		hash[x]++;
		sum+=x;
	}
	int q;cin >> q;
	while(q--)
	{
		ll a,b;cin >> a >> b;
		sum-=hash[a]*a;
		sum+=b*hash[a];
		hash[b]+=hash[a];
		hash[a]=0;
		cout << sum << '\n';
	}
}

int main()
{
	int t=1;
	while(t--) solve();
}	

Measured memory_bytes: 9524
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

string S,T;
int x[10000],y[10000];
int dp[10000][10000];
char U[53]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
int MAXN;

int main(){
	int q;
	cin>>q;
	for(int i=0;i<q;i++){
		MAXN=0;
		cin>>S>>T;
		for(int i=0;i<S.size();i++){
			for(int j=0;j<52;j++){
				if(S[i]==U[j]){
					x[i+1]=j;
				}
			}
		}
		for(int i=0;i<T.size();i++){
			for(int j=0;j<52;j++){
				if(T[i]==U[j]){
					y[i+1]=j;
				}
			}
		}
		for(int i=0;i<=T.size();i++){
			for(int j=0;j<=S.size();j++){
				if(i==0 || j==0){
					dp[i][j]=0;
				}
				else if(x[j]==y[i]){
					dp[i][j]=dp[i-1][j-1]+1;
				}
				else{
					dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
				}
			}
		}
		for(int i=0;i<=T.size();i++){
			for(int j=0;j<=S.size();j++){
				MAXN=max(MAXN,dp[i][j]);
			}
		}
		cout<<MAXN<<endl;
	}
	return 0;
}

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


int x[20][20];
int y[20][20];
int A[20];

int counter(int x) {
    if(x == 0) return 0;
    return counter(x >> 1) + (x & 1);
}

int main() {
  int N;
  cin >> N;
  
  for(int i = 1;i <= N;i++){
  	cin >> A[i];
    for(int j = 1;j <= A[i];j++){
	    cin >> x[i][j] >> y[i][j];
    }
  }
  
  // bit全探索パターン:Nビットのビット列をすべて列挙する
  // tmpの1のビットが正直者と仮定したもの
  // Ex:110/3,2人目が正直者
  int ans = 0;
  for (int tmp = 0; tmp < (1 << N); tmp++) {
	bool ok = true;
    
    //i人目の発言をチェック
    for(int i = 1;i <= N;i++){
      bool Person_i_kind = tmp & (1 << (i - 1));
      if(!(Person_i_kind)) continue; //i人目が不親切ものなら確認不要
      
      //証言jがビットパターンと矛盾していないかチェック
      for(int j = 1;j <= A[i];j++){
        bool talk_j =  tmp & (1 << (x[i][j] - 1));
        if((talk_j & 1) ^ y[i][j]) ok = false; 
      }
    }
    //1の数を記録,前回値と比較
    if(ok) ans = max(ans,counter(tmp));
  }
  
  cout << ans << endl;
  
  return 0; 
}


Measured memory_bytes: 256
import math
a,b = map(int,input().split())
a1 = math.ceil((25*a)/2)
a2 = (25*(a+1))/2
b1 = 10*b
b2 = 10*(b+1)
f = max(a1,b1)
if f < a2  and f < b2:
  print(f)
else:
  print(-1)

Measured memory_bytes: 38384
using System;

namespace ABC174.Problems
{
    class A
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            int n = int.Parse(Console.ReadLine());
            Console.WriteLine(n >= 30 ? "Yes" : "No");

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 27432
#include<iostream>
#include<string.h>

int main()
{
	int a, b, c;
	bool used[10];

	while( std::cin >> a >> b >> c )
	{
		memset( used, false, sizeof( used ) );

		used[a-1] = used[b-1] = used[c-1] = true;

		double p = 0.0;

		for( int i = 0; i < 10; i++ )
		{
			if( !used[i] )
			{
				if( a + b + i + 1 <= 20 )
					p++;
			}
		}

		p /= 7.0;

		if( p >= 0.5 )
			std::cout << "YES" << std::endl;
		else
			std::cout << "NO" << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1148
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  int n; cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  vector<int> b(0);
  while(a.size()){
    for(int i=a.size()-1;i>=0;i--){
      if(a[i]==i+1){
        b.push_back(a[i]);
        for(int j=i;j<a.size()-1;j++){
          swap(a[j],a[j+1]);
        }
        a.pop_back();
        break;
      }
      if(i==0&&a[i]!=i+1){
        cout << -1 << endl;
        return 0;
      }
    }
  }
  reverse(all(b));
  rep(i,b.size()){
    cout << b[i] << endl;
  }
  
}

Measured memory_bytes: 256
import math
a,b,n = list(map(int,input().split()))
x = 1
temp = 0
res = 0

if (b - 1) > n:
    x = n
    # for i in range(n):
    #     temp = math.floor((a*x)/b) - a * math.floor(x/b)
    #     print(str(x) + " " + str(temp))
    #     if res < temp:
    #         res = temp
    #     x += 1
else:
    x = (b - 1)

res = math.floor((a*x)/b) - a * math.floor(x/b)
print(res)

Measured memory_bytes: 9132
#include<iostream>
using namespace std;
long gcd(long a,long b){return b?gcd(b,a%b):a;}
long a,b;
main()
{
	cin>>a>>b;
	b/=gcd(a,b);
	for(long i=2;i*i<=b;i++)
	{
		while(b%(i*i)<1)b/=i;
	}
	cout<<b<<endl;
}



Measured memory_bytes: 3104
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
//ABC110A問題
int main(void) {
	//変数の宣言
	vector<int> input(3);
	int result;
	
	//入力
	cin >> input[0] >> input[1] >> input[2];

	//ソートする
	sort(input.begin(), input.end());

	//答えを求める
	result = input[0] + input[1] + input[2] * 10;

	//出力
	cout << result << endl;

	//終了
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
inline void read (int &x) {
        char ch = getchar(); x = 0;
        while (!isdigit(ch)) ch = getchar();
        while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
}
const int N = 1e5 + 10;
int n, m, a, b, vis[N], s[N];
char ch[3];
signed main() {
        read (n), read (m);
        for (int i = 1; i <= m; ++i) {
                int x;
                read (x); scanf ("%s", ch);
                if (ch[0] == 'A') a += vis[x] ^ 1, vis[x] = 1;
                else if (!vis[x]) ++s[x];
        }
        for (int i = 1; i <= n; ++i) b += s[i] * vis[i];
        printf ("%d %d\n", a, b);
        return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
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; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

int main(){
  int n,a,b,c,d;
  cin>>n>>a>>b>>c>>d;
  --a;--b;--c;--d;
  string s;cin>>s;
  if(c>d){
    rep(i,b-1,d){
      if(s[i]=='.'&&s[i+1]=='.'&&s[i+2]=='.'){
        break;
      }
      if(i==d-1){
        cout<<"No"<<endl;
        exit(0);
      }
    }
    rep(i,a,c){
      if(s[i]=='#'&&s[i+1]=='#'){
        cout<<"No"<<endl;
        exit(0);
      }
    }
    cout<<"Yes"<<endl;
  }
  else{
    rep(i,a,d){
      if(s[i]=='#'&&s[i+1]=='#'){
        cout<<"No"<<endl;
        exit(0);
      }
    }
    cout<<"Yes"<<endl;
  }
}





Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args)
	        throws IOException {
		BufferedReader br = new BufferedReader(
		        new InputStreamReader(System.in));
		int v = Integer.parseInt(br.readLine());
		int m = 100000;
		for (int i = 0; i < v; i++) {
			m *= 1.05;
			if ((m % 1000) > 0) {
				m += 1000 - m % 1000;
			}
		}
		System.out.println(m);
	}
}

Measured memory_bytes: 8796