akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC optimize("Ofast")
#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;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll long long
#define ld long double
#define pi pair<int,int>
#define pd pair<ld,ld>
#define ft first
#define sd second
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define FOR(i,a,b) for(int i=(a); i<=(b);i++)
#define F(i,a,b) FOR(i,(a),(b)-1)
#define REV(i,a,b) for(int i=(a); i>=(b);i--)
#define VI vector<int>
#define VPI vector<pi>
#define VPD vector<pd>
#define PI 3.14159265
#define all(x) (x).begin(), (x).end()
#define sz(a) (int)((a).size())
#define int long long

template<class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="<<h<<","; _dbg(sdbg+1, a...);
}
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
mt19937 r(chrono::steady_clock::now().time_since_epoch().count());
int rand_range(int a, int b)
{
    assert(a<=b);
    return a+r()%(b-a+1);
}
const long long K = 1000;
const long long KK = K*K;
const long long MIL = KK*K;
const long long INF = MIL*MIL;
const long long MOD = MIL+7;
const long long N = 1e6 + 10, M=10;

int silnia[N], odsilnia[N];

int dwumian(int a, int b) {
    return (((silnia[a] * odsilnia[b]) % MOD) * odsilnia[a - b]) % MOD;
}

int pot(int x, int p) {
    int tmp = 1;
    for(;p;p/=2, x = (x * x) % MOD) {
        if (p & 1)
            tmp = (tmp * x) % MOD;
    }
    return tmp;
}

void solve(){
    silnia[0] = 1;
    F(i, 1, N)
        silnia[i] = (silnia[i - 1] * i) % MOD;


    odsilnia[N - 1] = pot(silnia[N - 1], MOD - 2);
    REV(i, N - 2, 0)
        odsilnia[i] = (odsilnia[i + 1] * (i  + 1)) % MOD;

    int x, y;
    cin >> x >> y;
    if ((x + y) % 3 != 0) {
        cout << "0\n";
        return;
    }
    if (y < x)
        swap(x, y);
    if (2 * x < y) {
        cout << "0\n";
        return;
    }

    int ile = (y + x) / 3;
    int ile1 = y - x + (ile - y + x) / 2;
//    debug(ile1, ile);
    cout << dwumian(ile, ile1) << "\n";
}

int32_t main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cerr.tie(0);
    cout<<setprecision(9)<<fixed;
    cerr<<setprecision(6)<<fixed;
    int test = 1, f;
    //cin>>test;
    F(_test, 0, test){
        //cout<<"Case #"<<_test + 1<<": ";
        solve();
//		if(_test == 1)
//            return 0;
    }
}


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

int N, L;
vector< int > x, a;
const int mod = 1000000007;

class Fenwick_Tree{
private:
  vector< int64 > p;
public:
  Fenwick_Tree(int size){
    p.resize(size + 2, 0);
  }
  void init(){
    for(int i = 0; i < p.size(); i++) p[i] = 0;
  }
  int64 sum(int x){
    int64 ret = 0;
    if(x < 0) return(0);
    for(++x; x > 0; x -= x & -x) (ret += p[x]) %= mod;
    return(ret);
  }
  void add( int k, int a){
    for( ++k; k < p.size(); k += k & -k) (p[k] += a) %= mod;
  }
};

vector< Fenwick_Tree > dp;
int main() {
  cin >> N >> L;
  ++L;
  dp.resize(2, Fenwick_Tree(L + 5));
  x.resize(N), a.resize(N);
  for(int i = 0; i < N; i++) {
    cin >> x[i];
    ++x[i];
  }
  for(int i = 0; i < N; i++) {
    cin >> a[i];
  }
  dp[0].add(0, 1);
  for(int i = 1; i <= N; i++) {
    if(a[i - 1] == 0) {
      dp[i&1].add(x[i - 1], dp[(i - 1)&1].sum(x[i - 1] - 1));
    } else {
      for(int j = L - 1; j >= x[i - 1]; j--){ // ????????????
        if((j - x[i - 1]) % a[i - 1] == 0) { // ?§??????????
          dp[i&1].add(j, dp[(i - 1)&1].sum(j - 1));
        }
      }
    }
    dp[(i - 1)&1].init();
  }
  cout << dp[N&1].sum(L) << endl;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  int pay = 0;
  bool flag = true;
  for(int i = 0; i < n; i++){
    cin >> p[i];
  }
  int e = *max_element(p.begin(), p.end());
  for(int i = 0; i < n; i++){
    if(p[i] == e && flag) {pay += p[i] / 2; flag = false;}
    else pay += p[i];
  }
  cout << pay << endl;
}

Measured memory_bytes: 3560
n=int(input())
aList=[]
for i in range(n):
  aList.append(int(input()))

ans=0
if n%2==1:
  aList.sort()
  smallList1=aList[:(n+1)//2]
  bigList1=aList[(n+1)//2:]
  ans1=sum(bigList1)*2-sum(smallList1)*2+smallList1[-1]+smallList1[-2]

  smallList2=aList[:(n-1)//2]
  bigList2=aList[(n-1)//2:]
  ans2=sum(bigList2)*2-sum(smallList2)*2-bigList2[0]-bigList2[1]
  ans=max(ans1,ans2)
else:
  aList.sort()
  smallList=aList[:n//2]
  bigList=aList[n//2:]
  ans=sum(bigList)*2-sum(smallList)*2+smallList[-1]-bigList[0]
print(ans)

Measured memory_bytes: 8532
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <queue>
#include <stack>
#include <string.h>
#include <list>
using namespace std;
typedef long long ll;
#define all(a)  (a).begin(), (a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define rep(i,n) for(int i = 0; i < n; i++)
#define repR(i,n) for(int i = n-1; i >= 0; i--)
#define FOR(i,m,n) for(int i = m; i < n; i++)
#define PB push_back
#define MP make_pair
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))


int main() {
    int a = 2,i = 2;
    vector<int> exp = {1};
    while(a*a <= 1000){
        int exnum = pow(a,i);
        exp.PB(exnum);
        i++;
        if(pow(a,i) > 1000){
            i = 2;
            a++;
        }
    }
    int n;
    cin >> n;
    sort(rall(exp));
    rep(i,exp.size()){
        if(exp[i] <= n){
            cout << exp[i] << endl;
            break;
        }
    }
    return 0;
}


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

#define vi vector<int>
#define vvi vector<vector<int>>
#define vpii vector<pair<int, int>>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair<int, int>
#define int long long int
#define inf INT_MAX
#define _inf INT_MIN
#define whilet int t;cin>>t;while(t--)
const int N = 100005;

int max_happines(vvi arr) {

	int n = arr.size();
	vvi dp(n, vi(3));


	dp[0][0] = arr[0][0];
	dp[0][1] = arr[0][1];
	dp[0][2] = arr[0][2];

	for (int i = 1; i < n; i++) {
		dp[i][0] = arr[i][0] + max(dp[i - 1][1], dp[i - 1][2]);
		dp[i][1] = arr[i][1] + max(dp[i - 1][0], dp[i - 1][2]);
		dp[i][2] = arr[i][2] + max(dp[i - 1][0], dp[i - 1][1]);
	}

	return max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));
}

void solve() {

	int n;
	cin >> n;

	vvi arr(n, vi (3));
	for (int i = 0; i < n; i++) {
		cin >> arr[i][0] >> arr[i][1] >> arr[i][2];
	}
	cout << max_happines(arr);
}

void init() {
	ios_base:: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("../input.txt", "r", stdin);
	freopen("../output.txt", "w", stdout);
#endif
}


int32_t main()
{
	init();
	// whilet solve();
	solve();
}

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

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

    int count = 0;

    for(int i = 1; i <= N; i++)
    {
        if(to_string(i).size() % 2 == 1)
        {
            count++;
        }
    }

    cout << count << endl;
    return 0;

}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = 1 << 30;
const ll INFll = 1ll << 60;

int main() {
  int n, x;
  cin >> n >> x;
  vector<int> l(n);
  for (int i = 0; i < n; i++) cin >> l[i];

  int cnt = 1;
  int D = 0;
  for (int i = 0; i < n; i++) {
    D += l[i];
    if (D > x) break;

    cnt++;
  }

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
amari = 10
ab = []
for _ in range(5):
    a=int(input())
    ab.append(a)
    if a%10 == 0:
        continue
    amari = min(amari,a%10)
#print(ab)
ans = 0
for i in range(len(ab)):
    if ab[i]%10 == 0:
        ans += ab[i]
    elif ab[i]%10 == 1:
        ans += ab[i]+9
    elif ab[i]%10 == 2:
        ans += ab[i]+8
    elif ab[i]%10 == 3:
        ans += ab[i]+7
    elif ab[i]%10 == 4:
        ans += ab[i]+6
    elif ab[i]%10 == 5:
        ans += ab[i]+5
    elif ab[i]%10 == 6:
        ans += ab[i]+4
    elif ab[i]%10 == 7:
        ans += ab[i]+3
    elif ab[i]%10 == 8:
        ans += ab[i]+2
    elif ab[i]%10 == 9:
        ans += ab[i]+1
print(ans+amari-10)

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

long long N, K;
vector<long long> sumV(100001);

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

  int A, B, T;
  cin >> A >> B >> T;
  cout << T / A * B <<endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define nl '\n'
#define si(i) scanf("%d", &i)

int n, m;
int pos[100005];
long long gap[100005];
long long sum;

int main() {

    cin >> n >> m;
    if ( n >= m ) {
        cout << 0 << nl;
        exit(0);
    }
    for ( int i = 0; i < m; i++ ) cin >> pos[i];
    sort ( pos + 0, pos + m);
    for ( int i = 0; i < m - 1; i++ ) {
        gap[i] = (long long) pos[i + 1] - pos[i];
    }
    sort ( gap + 0, gap + m - 1 );
    reverse ( gap + 0, gap + m - 1 );
    sum = (long long) pos[m - 1] - pos[0];
    for ( int i = 0; i < n - 1; i++ ) {
        sum -= gap[i];
    }
    cout << sum << nl;
    
}

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

using i64 = int64_t;

int main(){
    int n;
    cin >> n;
    int m = n % 100;
    int cnt = m / 5 + !!(m%5);
    if(100*cnt + m > n)cout << 0;
    else cout << 1;
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x,y) make_pair(x,y)
 ll H,W;
 ll ch,cw,dh,dw;
  char field[10000][10000];
  ll dp[10000][10000];

priority_queue<
pair<ll,pair<ll,ll>>,
vector<pair<ll,pair<ll,ll>>>

> que;
int main(){
 
  cin>>H>>W;
 
  cin>>ch>>cw>>dh>>dw;
ch--;cw--;dw--;dh--;

  for(ll i=0;i<H;i++){
      for(ll j=0;j<W;j++){
          cin>>field[i][j];
      }
  }
  for(ll i=0;i<10000;i++){
      for(ll j=0;j<10000;j++){
          dp[i][j]=1111111122222;
      }
  }

  dp[ch][cw]=0;

  //ser(ch,cw,0);
  que.push(mkpr(0LL,mkpr(ch,cw)));
 while(!(que.empty())){
      pair<ll,pair<ll,ll>> tmpp=que.top();
      que.pop();
      ll nh =tmpp.second.first;
      ll nw = tmpp.second.second;



      if(nh-1>=0&&field[nh-1][nw]=='.'){
            if(dp[nh][nw]<dp[nh-1][nw]){
                dp[nh-1][nw]=dp[nh][nw];
                que.push(mkpr(-dp[nh][nw],mkpr(nh-1,nw)));
            }
        }
        //↓
        if(nh+1<H&&field[nh+1][nw]=='.'){
            if(dp[nh][nw]<dp[nh+1][nw]){
                dp[nh+1][nw]=dp[nh][nw];
                que.push(mkpr(-dp[nh][nw],mkpr(nh+1,nw)));
            }
        }
        //右
        if(nw+1<W&&field[nh][nw+1]=='.'){
            if(dp[nh][nw]<dp[nh][nw+1]){
                dp[nh][nw+1]=dp[nh][nw];
                que.push(mkpr(-dp[nh][nw],mkpr(nh,nw+1)));

            }
        }
        //左
        if(nw-1>=0&&field[nh][nw-1]=='.'){
            if(dp[nh][nw]<dp[nh][nw-1]){
                dp[nh][nw-1]=dp[nh][nw];
                que.push(mkpr(-dp[nh][nw],mkpr(nh,nw-1)));

            }
        }
        //ワープ
        for(ll y=-2;y<=2;y++){
            for(ll x=-2;x<=2;x++){
                if(nw+x>=0&&nw+x<W&&nh+y<H&&nh+y>=0){
                    if(field[nh+y][nw+x]=='.'){
                        if(dp[nh][nw]+1<dp[nh+y][nw+x]){
                            dp[nh+y][nw+x]=dp[nh][nw]+1;
                            que.push(mkpr((-1)*(dp[nh][nw]+1),mkpr(nh+y,nw+x)));
                        }
                    }
                }
            }
        }
  }



 





    if(dp[dh][dw]==1111111122222){
        cout<<-1<<endl;
        return 0;
    }
    else{
        cout<<dp[dh][dw]<<endl;
    }


return 0;








}











Measured memory_bytes: 789920
#include <iostream>
using namespace std;
typedef unsigned long long u64;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  u64 size = s.size();
  while (true) {
    if (s == "") break;
    if (size >= 5 && (s.substr(size-5) == "dream" || s.substr(size-5) == "erase")) {
      s = s.substr(0, size-5);
      size-=5;
    }
    else if (size >= 7 && s.substr(size-7) == "dreamer") {
      s = s.substr(0, size-7);
      size-=7;
    }
    else if (size >= 6 && s.substr(size-6) == "eraser") {
      s = s.substr(0, size-6);
      size-=6;
    }
    else {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	private static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		char c = sc.next().charAt(0);
		System.out.println(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' ? "vowel" : "consonant");
	}
}

Measured memory_bytes: 23252
#include<stdio.h>
int main(void){
	int oturi;
	int mon,i,ans=0;
	int a[5]={500,100,50,10,5};
	while(1){
		ans=0;
		scanf("%d",&mon);
		if(mon==0)break;
		oturi=1000-mon;
		for(i=0;i<5;i++){
			ans+=oturi/a[i];
			oturi%=a[i];
		}
		ans+=oturi;
		printf("%d\n",ans);
	}
}


Measured memory_bytes: 2572
# import bisect
# import heapq
# from copy import deepcopy
# from collections import deque
# from collections import Counter
# from itertools import accumulate
# from itertools import permutations
# import numpy as np
import math
# mod = 10**9 + 7

# n = int(input())
# a = list(map(int, input().split()))
# n = int(input())z
a,b = map(int,input().split())


print(a-2*b if a-2*b>=0 else 0)

Measured memory_bytes: 38384
import java.util.Scanner;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        int c = b - a;
        int res = c * (c + 1) / 2 - b;

        System.out.println(res);
    }

}


Measured memory_bytes: 21332
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    X,N = map(int,input().split())
    p = list(map(int,input().split()))
    p = set(p)

    for diff in range(101):
        test = X - diff
        if test not in p:
            res = test
            break
        test = X + diff
        if test not in p:
            res = test
            break

    print(res)



main()


Measured memory_bytes: 9184
import java.util.Scanner;

class Main
{
	public static void main(String args[])
	{
		boolean not[] = new boolean[1000000];
		not[0] = true;
		not[1] = true;
		for (int i = 2; i * i < 1000000; i++)
		{
			if (not[i]) continue;
			for (int x = (i << 1); x < 1000000; x += i)
			{
				if (not[x]) continue;
				not[x] = true;
			}
		}
		
		Scanner sc = new Scanner(System.in);
		while (true)
		{
			int n = sc.nextInt();
			if (n == 0) break;
			int sum = 0;
			int count = 0;
			int i = 0;
			while (count < n)
			{
				if (!not[i])
				{
					sum += i;
					count++;
				}
				i++;
			}
			System.out.println(sum);
		}
	}
}

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

#define INF (1<<31)//INT_MAX/2
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;

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

   string a,b;
   cin>>a>>b;
   string c = a+b;
   int num = atoi(c.c_str());
   for(int i=0;i*i<=num;i++){
      if(i*i==num){
         cout<<"Yes"<<endl;
         return 0;
      }
   }
   cout<<"No"<<endl;
   return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<cmath>
#include<stack>
#include<algorithm>
#define rg register
#define ll long long
#define LDB long double
#define ull unsigned long long
#define view(i,x) for(rg int i=hd[x];i!=-1;i=e[i].nt)
#define go(i,x,a) for(rg int i=a;i<x;i++)
#define inf 0x3f3f3f3f
#define INF 0x7fffffff
using namespace std;

ll n,p;

inline ll rd(){
	ll ret=0,af=1; char gc=getchar();
	while(gc < '0' || gc > '9'){ if(gc=='-') af=-af; gc=getchar(); }
	while(gc >= '0' && gc <= '9') ret=ret*10+gc-'0',gc=getchar();
	return ret*af;
}

inline ll qpow(ll x,ll k){
	ll ss=1,kx=x;
	while(k > 0){
		if(kx > p) return -1;
		if(k & 1){
			ss*=kx; if(ss > p) return -1;
		}
		k=k/2;
		if(k > 0 && kx > sqrt(p)) return -1;
		kx=kx*kx;
	}
	return ss; 
}

int main(){
	n=rd(); p=rd();
	if(n == 1){
		printf("%lld",p); return 0;
	}
	ll ans=1;
	for(rg ll i=2;;i++){
		ll ss=qpow(i,n);
		if(ss == -1) break;
		if(p % ss == 0) ans=i;
	}
	printf("%lld",ans);
	return 0;
}//Faze


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

class Network{
	private:
	int V;
	struct edge{
		int to,cap,rev;
	};
	vector<vector<edge> > List;
	int DFS(int v,int t,int f,vb& used){
		if(v==t) return f;
		used[v]=1;
		for(int i=0;i<List[v].size();i++){
			edge &e=List[v][i];
			if(!used[e.to]&&e.cap>0){
				int d=DFS(e.to,t,min(f,e.cap),used);
				if(d>0){
					e.cap-=d;
					List[e.to][e.rev].cap+=d;
					return d;
				}
			}
		}
		return 0;
	}
	public:
	Network(int v){
		V=v;
		List=vector<vector<edge> >(v);
	}
	void add_edge(int s,int t,int c){
		List[s].push_back(edge{t,c,(int)List[t].size()});
		List[t].push_back(edge{s,0,(int)List[s].size()-1});
	}
	int MF(int s,int t){
		int ans=0;
		while(1){
			vb used(V);
			int f=DFS(s,t,inf,used);
			if(f==0) return ans;
			ans+=f;
		}
	}
};

int h,w;
vvc a;

inline int f(int x,int y){
	return x*w+y;
}

int main(){
	cin>>h>>w;
	a=vvc(h,vc(w));
	Network nt(2*h*w+2);
	bool flag=1;
	for(int i=0;i<h;i++) for(int j=0;j<w;j++){
		cin>>a[i][j];
		if(a[i][j]=='X') nt.add_edge(2*h*w,h*w+f(i,j),inf);
		else nt.add_edge(f(i,j),h*w+f(i,j),1);
		if(!i||i==h-1||!j||j==w-1){
			nt.add_edge(h*w+f(i,j),2*h*w+1,inf);
			if(a[i][j]=='X') flag=0;
		}
		for(int k=0;k<4;k++){
			int x=i+dx[k],y=j+dy[k];
			if(x>=0&&x<h&&y>=0&&y<w) nt.add_edge(h*w+f(i,j),f(x,y),inf);
		}
	}
	if(!flag){
		cout<<-1<<endl;
		return 0;
	}
	cout<<nt.MF(2*h*w,2*h*w+1)<<endl;
}

Measured memory_bytes: 2688
/*
	Mbak Sana Dong
	Mbak Chaeyoung Dong
*/
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
const ll mod = 1e9+7;
ll arr[100100], fact[100100];
ll power(ll a, ll b)
{
	ll ret = 1;
	while(b>0)
	{
		if(b%2==1)
		{
			ret = (ret*a) % mod;
		}
		b /= 2;
		a = (a*a) % mod;
	}
	return ret % mod;
}
int main()
{
	int n,i,j,k,x,y,ans,curr,temp,m;
	int tc;
	cin >> n >> k;
	for(i=1;i<=n;i++)
	{
		cin >> arr[i];
	}
	fact[0] = 1;
	for(i=1;i<=100000;i++)
	{
		fact[i] = (1LL*i*fact[i-1]) % mod;
	}
	ll mini = 0, maxi = 0;
	sort(arr+1,arr+n+1);
	for(i=1;i<=n-k+1;i++)
	{
		arr[i] += mod;
		arr[i] % mod;
		ll res = (fact[n-i] * (((power(fact[k-1], mod - 2) % mod) * (power(fact[n-i-k+1], mod-2) % mod)) % mod) % mod);
		mini += (res*arr[i]) % mod;
		mini %= mod;
	}
	for(i=n;i>k-1;i--)
	{
		arr[i] += mod;
		arr[i] % mod;
		ll res = (fact[i-1] * (((power(fact[k-1], mod - 2) % mod) * (power(fact[i-k], mod-2) % mod)) % mod) % mod);
		maxi += (res*arr[i]) % mod;
		maxi %= mod;
	}
	maxi -= mini;
	while(maxi < 0LL) maxi += mod;
	cout << maxi << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define lint long long
#define ll long long
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define vl vector<long long>
#define pii pair<long long,long long>
#define all(x) (x).begin(),(x).end()
#define rep(x) for(int i = 0;i < (x);i++)
#define repj(x) for(int j = 0;j < (x);j++)
#define REP(i,x) for(int (i) = 0;(i) < (x);(i)++)
#define rrep(x) for(int i = (x);i >= 0;i--)
#define mod 1000000007
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
long long INF = 1e10;
/************************  DEFINE  ****************************/

/************************ FUNCTION ****************************/

/************************   MAIN   ****************************/
int main(void){
    ll n;cin >> n;
    vector<ll> c(n-1),s(n-1),f(n-1);
    rep(n-1) cin >> c[i] >> s[i] >> f[i];
    ////////////////////////////////////////
   
    for(int i = 0;i < n;i++){
        if(i == n-1){cout << 0 << endl; break;}
        ll time = 0;
        
        for(int j = i;j < n-1;j++){
            if(j == i) time = s[j] + c[j];
            else time = c[j] + max(((time - 1)/f[j] + 1)*f[j],s[j]);
        }
        cout << time << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#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 h,w;cin>>h>>w;
    int a[h][w];
    rep(i,h){
        string s;cin>>s;
        rep(j,w){
            if(s[j]=='#')a[i][j]=1;
            else a[i][j]=0;
        }
    }
    rep(i,h)rep(j,w){
        if(a[i][j]==1){
            if(a[i-1][j]==0 && a[i+1][j]==0 && a[i][j-1]==0 && a[i][j+1]==0){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;    
	return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <tuple>

using namespace std;

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define cina(s, n, a) for(int i = s; i < n; i++) cin >> a[i]
#define couta(n, a) for(int i = 0; i < n; i++) cout << a[i] << ' '
#define copy(s, n, a, b) for(int i = s; i < n; i++) b[i] = a[i]
#define yesno(ok) cout << (ok ? "YES" : "NO")
#define mod(a, b) (b + (a % b)) % b
#define MOD  (ll)1e9 + 7
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<pii> vpii;

void solve(){
    int a, b;
    cin >> a >> b;
    cout << (a + b - 1) / b;
}

int main(){
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int q = 1;
    //cin >> q;
    for(int i = 1; i <= q; i++){
        solve();
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n); for(int i = 0;i < (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> state;
long double pi = acos(-1);
const int INF = 1001001001;


// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}
ll conbination(ll a,ll b){
  ll u = 1;
  ll d = 1;
  while(b != 0){
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int strtoint(char s){
  return (int(s-'0'));
}
char changeS(char alpha){
  if(0x41 <= alpha and alpha <= 0x5A)return (alpha + 0x20);
  else if(0x61 <= alpha and alpha <= 0x7A)return (alpha - 0x20);
  return alpha;
}
int fact(int n){
  if(n == 1)return 1;
  return n * fact(n-1);
  }
int ceil(int a,int b){
  // a/bの切り上げを考える
  return (a+b-1)/b;
}

int main() {
  int n, m;
  cin >> n >> m;
  int s[m];
  int c[m];

  rep(i,m)cin >> s[i] >> c[i];
  int ans = -1;
  rep(i,1000){
    int cnt = 0;
    string i_str = to_string(i);
    if(i_str.length() == n){
      rep(j,m){
        string temp = to_string(c[j]);
        if(i_str[s[j] - 1] == temp[0])cnt++;
      }
      if(cnt == m){
        ans = i;
        break;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define MAX 1000000007
#define ll long long int
#define fo(i,n) for(int i=0;i<n;i++)
#define ull unsigned long long int
#define pb push_back
#define eb emplace_back
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
//    int t;
//    cin>>t;
    int x=1;
//    while(t--) {
     int r;
     cin>>r;
     double circum = 2*r*3.14159265358979323;
     cout<<circum<<endl;



       x++;
//    }
    return 0;
}

Measured memory_bytes: 3804
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repi(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
typedef long long ll;
using namespace std; 
using P = pair<int,int>;
const ll mod = 1e9+7;
const int INF = 1001001001;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
  

int main(){
  int  H1,M1,H2,M2,k;
  int num=0;
  cin >> H1 >> M1 >> H2 >> M2 >> k;
  num+=(H2-H1);
  if(M1>M2){
    num--;
    num*=60;
    num+=60-abs(M1-M2);
  }else{
    num*=60;
    num+=abs(M1-M2);
  }
  cout << num-k << endl;
  
  return 0;
  
}

Measured memory_bytes: 3624
($x,$y,$z,$w)=glob<>;
$ans=-10**18;
if($ans<$x*$z){$ans=$x*$z}
if($ans<$x*$w){$ans=$x*$w}
if($ans<$y*$z){$ans=$y*$z}
if($ans<$y*$w){$ans=$y*$w}
print$ans

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

int main() {
    int N, origN; cin >> N; origN = N;
    vector<int> div;
    for(int d=2; d*d<=N; d++) {
        if(N % d == 0) {
            div.push_back(d);
            while(N % d == 0) N /= d;
        }
    }
    if(N != 1) div.push_back(N);

    int M = div.size(), ans = 0;
    // N と互いに素でないものを数え上げる
    for(int bit=1; bit<(1<<M); bit++) {
        int popcnt = __builtin_popcount(bit);
        int mul = 1;
        for(int i=0; i<M; i++) {
            if(bit >> i & 1) mul *= div[i];
        }
        // 集合の数による場合分け
        if(popcnt % 2 == 1) ans += origN / mul;
        else                ans -= origN / mul;
    }
    // 互いに素なもの = 全体から素でないものを引いたもの
    ans = origN - ans;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int ans=(n+1000-1)/1000*1000;
    cout<<ans-n<<endl;
}

Measured memory_bytes: 3612
#include "bits/stdc++.h"
using namespace std;

#define ul unsigned long long
#define ll long long 

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

  int cs,cc;
  int ds[3]={-1,-1,-1};

  for (int i=0;i<m;i++) {
    cin>>cs>>cc;
    cs--;
    if (ds[cs]<0) ds[cs]=cc;
    else if (ds[cs]!=cc) ds[cs]=11;
  }

  if (n>1&&ds[0]==0) cout <<"-1"<<endl;
  else if (ds[0] > 9 || ds[1] > 9 || ds[2] > 9)
    cout << "-1" << endl;
  else if (n < 3 && ds[2] >= 0)
    cout<< "-1" << endl;
  else if (n < 2 && ds[1] >= 0)
    cout<< "-1" << endl;
  else
  {
    ds[0]=max(ds[0],(int)(n!=1));
    ds[1] = max(ds[1], 0);
    ds[2] = max(ds[2], 0);
    if (n==2)swap(ds[0],ds[1]);
    else if (n==3) swap(ds[0],ds[2]);
    cout << (ds[0]+ds[1]*10+ds[2]*100)<<endl;
  }


  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
 
#include<map>
typedef pair<int,int> P;
 
vector<vector<P> >v;//辺リスト(v[i]には辺が詰まっている
map<int,int> u[100010];//頂点リスト(u[頂点][路線]==vでの番号)
 
priority_queue<P,vector<P>,greater<P> >Q;
int dis[500010];
 
int main(){
	vector<P> emptyvector;
	v.push_back(emptyvector);
	
	int n,m;
	cin>>n>>m;
	int vsize=1;
	for(int i=1;i<=n;i++){
		v.push_back(emptyvector);
		u[i][-1]=vsize;
		vsize++;
	}
	while(m--){
		int a,b,train;
		cin>>a>>b>>train;
		lol(p,2){
			if(u[a][train]==0){
				v.push_back(emptyvector);
				v[vsize].push_back(make_pair(a,0));
				v[a].push_back(make_pair(vsize,1));
				
				u[a][train]=vsize;
				a=vsize;
				vsize++;
			}
			else{
				a=u[a][train];
			}
			swap(a,b);
		}
		v[a].push_back(make_pair(b,0));
		v[b].push_back(make_pair(a,0));
	}
	
	//↓ Dijkstra ↓
	lol(i,vsize)dis[i]=mod;
	Q.push(make_pair(0,1));
	while(!Q.empty()){
		int b=Q.top().first,a=Q.top().second;
		Q.pop();
		if(dis[a]<=b)continue;
		dis[a]=b;
		for(int i=0;i<v[a].size();i++){
			int pnt=v[a][i].first,cost=v[a][i].second+b;
			if(dis[pnt]<=cost)continue;
			Q.push(make_pair(v[a][i].second+b,v[a][i].first));
		}
	}
	int tmp=dis[u[n][-1]];
	cout<<(tmp==mod?-1:tmp)<<endl;
	return 0;
}


Measured memory_bytes: 63144
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FOR(i) for(cin>>i;i>0;i--)
#define elif else if
#define pb push_back
#define ll long long
#define mp make_pair
#define all(x) x.begin(),x.end()
//#define x first
//#define y second

using namespace std;
int n;
int main()
{
	cin>>n;
	cout<<n/2+(n%2==1);
	return 0;}

Measured memory_bytes: 256
/*
 * a.c
 *
 *  Created on: 2017/06/13
 *      Author: AWV060608
 */

#include	<stdio.h>

int		main(void)
{
	int		m, f, r;
	//int		i,j;

	while(1)
	{
		scanf("%d",&m);
		scanf("%d",&f);
		scanf("%d",&r);

		if((m == -1)&&(f == -1)&&(r == -1))
		{
			break;
		}
		if((m == -1)||(f == -1))
		{
			printf("F\n");
		}
		else if( (m + f) >= 80 )
		{
			printf("A\n");
		}
		else if(( 80 > (m + f)) && ((m + f) >= 65 ))
		{
			printf("B\n");
		}
		else if(( 65 > (m + f)) && ((m + f) >= 50) )
		{
			printf("C\n");
		}
		else if((( 50 > (m + f)) && ((m + f) >=30)) && ( r >= 50))
		{
			printf("C\n");
		}
		else if(( 50 > (m + f)) && ((m + f) >=30))
		{
			printf("D\n");
		}
		else
		{
			printf("F\n");
		}
	}
	return 0;
}

Measured memory_bytes: 584
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
//#define fastio; ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vi;

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

    map<string,int> p;
    int cnt=0;
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        if(p[s]==0){
            p[s]=1;
            cnt++;
        }
    }
    cout<<cnt<<endl;

    return 0;
}


Measured memory_bytes: 19224
n,m = map(int,input().split())
A = list(map(int,input().split()))
leng = A[0]
nums = set(A[1:leng+1])

for i in range(n-1):
  B = list(map(int,input().split()))
  leng = B[0]
  new = set(B[1:leng+1])
  nums = nums & new 
print(len(nums))  
      
      

Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;

int main(){
   int A,B;
   cin >> A>> B;
   if(A>=10 || B>=10) cout <<-1 << endl;
   else cout <<A*B<<endl;
   return 0;
}


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    double ans;
    double x, y, z;
    cin >> x >> y >> z;
    ans = (x/z);
    if(ans <= y){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 3688
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int N = 2e5 + 10;

int n, m, E, cnt;
int fir[N], nex[N], arr[N], val[N], vis[N];
LL A, B, C, flag, col[N];

inline void Add_Edge(int x, int y, int w) {
	nex[++E] = fir[x];
	fir[x] = E; arr[E] = y; val[E] = w;
}

void dfs(int x) {
	vis[x] = 1;
	if (col[x] == 0) ++A;
	if (col[x] == 1) ++B;
	if (col[x] == 2) ++C;
	for (int i = fir[x]; i; i = nex[i]) {
		if (val[i] == 1) ++cnt;
		if (vis[arr[i]]) {
			if (col[arr[i]] != (col[x] + val[i]) % 3)
				flag = 1;
		}
		else {
			col[arr[i]] = (col[x] + val[i]) % 3;
			dfs(arr[i]);
		}
	}
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; ++i) {
		int x, y;
		scanf("%d%d", &x, &y);
		Add_Edge(x, y, 1);
		Add_Edge(y, x, 2);
	}
	memset(col, 0xff, sizeof col);
	LL ans = 0;
	for (int i = 1; i <= n; ++i) {
		if (vis[i]) continue;
		A = B = C = cnt = flag = 0;
		col[i] = 0;
		dfs(i);
		if (flag) ans += (A + B + C) * (A + B + C);
		else if (!A || !B || !C) ans += cnt;
		else ans += (A * B) + (B * C) + (A * C);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 8320
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define mod2 998244353
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define sz(v) ((ll)(v).size())
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define pb push_back
	#define f first
	#define s second
	#define dbg(a) cout<<#a<<" --> "<<(a)<<"\n";
	#define forn(i,n) for (ll i=0; i<(n); ++i)
	#define fornd(i,n) for (ll i=(n)-1; i>=0; --i)
	#define forab(i,a,b) for (ll i=(a); i<=(b); ++i)
	#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
	using namespace std;
	bool isPowerOfTwo(int x) {
    return x && (!(x & (x - 1)));
	}
	int takemod(int x) {
    return (x % mod + mod) % mod;
	}
 
	int fpow(int base, int power, int MOD) {
    int result = 1;
    base = base % MOD;
    while (power) {
        if (power & 1)
            result = (result * base) % MOD;
        base = (base * base) % MOD;
        power = power >> 1;
    }
    return result;
	}
 
	int modinv(int x) {return fpow(x, mod - 2, mod);}
	void solve()
	{
		ll n,m,k;
		cin>>n>>m>>k;
		vll A(n+1,0);vll B(m+1,0);
		vll preA(n+1,0);vll preB(m+1,0);

		forab(i,1,n)
		{
			cin>>A[i];

		}
		forab(i,1,m)
		{

			cin>>B[i];
		}
			preA[0]=0;
			preB[0]=0;
			A[0]=0;
			B[0]=0;
		forab(i,1,n)
		{
			
				preA[i]=A[i]+preA[i-1];
				//preB[i]=B[i]+preB[i-1];
			


		}
		forab(i,1,m)
		{
			
				//preA[i]=A[i]+preA[i-1];
				preB[i]=B[i]+preB[i-1];
			
						
		}

		// forn(i,n+1)
		// 	cout<<preA[i]<<" ";
		// cout<<endl;
		// forn(i,m+1)
		// 	cout<<preB[i]<<" ";
		// cout<<endl;
		ll ans=0;
		forab(i,0,n)
		{
			if(preA[i]<=k)
			{	
				
				  ll low = 1, high = m,er=0;
		        while(low <= high){
		            ll mid = (low + high)/2;
		            if(preB[mid] <= k-preA[i]){
		                er = mid;
		                low = mid + 1; 
		            }
		           
		            else
		                high = mid - 1;
		        }	
				if(preA[i]+preB[er]<=k)
					ans=max(ans,i+er);
			}
		}	
		
		
		cout<<ans<<endl;
	}
	int main()
	{	
		#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		#endif
		fast_io;
		int T=1;
	//	cin>>T;
		// cin.ignore(); must be there when using getline(cin, s)
		while(T--)
		{
			solve();
		}
		return 0;
	}


Measured memory_bytes: 9532
import collections

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B_and_C = [list(map(int, input().split())) for _ in range(Q)]
sum_A = sum(A)
collect = collections.Counter(A)
for b_c in B_and_C:
    sum_A -= b_c[0] * collect[b_c[0]]
    if b_c[1] not in collect:
        collect[b_c[1]] = 0
    collect[b_c[1]] += collect[b_c[0]]
    sum_A += b_c[1] * collect[b_c[0]]
    collect[b_c[0]] = 0
    print(sum_A)

Measured memory_bytes: 40484
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  long double A; long double B; cin >> A >> B;
  A *= B;
  cout << (ll)A << endl;
  return 0;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef pair<pii,pii> pippi;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<62;
int iinf=1<<30;
double pi=3.14159265358979323846;
double pi2=pi/2.0;
double eps=1e-8;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto& itr:mp)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
//#define endl "\n"
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umh unordered_map<int,int,custom_hash>
ll gcd(ll a,ll b){
    if(a<0)a=-a;
    if(b<0)b=-b;
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll c=gcd(a,b);
    return a*b/c;
}
ll Pow(ll n,ll k){
    if(k<0)return 0;
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
    now%=md;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;cin>>n;
    int ans=0;
    rep(i,0,n){
        int a;cin>>a;
        if(i%2==0&&a%2)ans++;
        
    }
    cout<<ans<<endl;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
vl ans;
void dfs(ll sum,ll now,ll n,ll a,ll b,ll c,ll d){
    if(now<n){
        dfs(sum+d,n-1,n,a,b,c,d);
    }
}


int main(){
    int a,b,cnt=0,ans=0;
    cin>>a>>b;
    while(cnt<2){
        cnt++;
        if(a<b){
            ans+=b;
            b--;
        }
        else{
            ans+=a;
            a--;
        }
    }
    cout<<ans<<endl;
}

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

int main() {

  int n, m;
  cin >> n >> m;

  vector<int> a(n);

  for(int i = 0; i < m; i++) {
    int k;
    cin >> k;
    for(int j = 0; j < k; j++) {
      int s;
      cin >> s;
      s--;
      a[s] |= 1<<i;
      // cout << s << ": " << bitset<4>(a[s]) << endl;
    }
  }

  int p = 0;
  for(int i = 0; i < m; i++) {
    int x;
    cin >> x;
    p |= x<<i;
  }

  // for(int i = 0; i < n; i++) {
  //   cout << i << ": " << bitset<2>(a[i]) << endl;
  // }

  int ans = 0;
  int cnt = 0;
  for(int s = 0; s < (1<<n); s++) {
    cnt++;
    int t = 0;
    // それぞれの電球の状態のためのfor
    for(int i = 0; i < n; i++) {
      // t = t ^ a[i];
      // cout << "t = " << bitset<2>(t) << " a[i] = " << bitset<2>(a[i]) << endl;
      // そのスイッチが立ってるとき、true
      if(s>>i & 1) {
        // cout << "true" << endl;
        t ^= a[i];
      }
      // cout << s << ": " << bitset<4>(t) << endl;
    }

    // cout << "t: " << bitset<5>(t) << endl;

    if(t == p) ans++;
    // cout << "p: " << bitset<4>(p) << endl;
  }
  cout << ans << endl;
  // cout << cnt << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
const int N = 405;
using namespace std;

map <long long, int> mymap;
int n;
long long a[N], ans;

long long po(int x){
    if (x == 0) return 1;
    if (x == 1) return 1000;
    if (x == 2) return 1000000;
    if (x == 3) return 1000000000;
}

long long rotate(long long x){
    long long t = x % po(1); x /= po(1);
    x += t * po(3);
    return x;
}

long long get(long long a, int num){
    return (a / po(num)) % 1000;
}

long long reverse(long long x){
    long long y = get(x, 0) * po(3) + get(x, 1) * po(2) + get(x, 2) * po(1) + get(x, 3) * po(0);
    return y;
}

int main(){
    cin >> n;
    for (int i = 1; i <= n; i++){
        int x, y, z, t;
        cin >> x >> y >> z >> t;
        a[i] = 1LL * x * 1000000000 + 1LL * y * 1000000 + 1LL * z * 1000 + t;
        mymap[a[i]]++;
    }
    for (int i = 1; i <= n; i++){
        for (int j = 1; j < i; j++){
            mymap[a[i]]--; mymap[a[j]]--;
            long long x = reverse(a[j]);
            for (int k = 0; k < 4; k++){
                long long cnt = 0, mul = 1;
                for (int h = 0; h < 4; h++){
                    long long color = 0;
                    int cnt = 0;
                    color += get(x, (h+1) % 4);
                    color *= 1000; color += get(x, h);
                    color *= 1000; color += get(a[i], h);
                    color *= 1000; color += get(a[i], (h+1) % 4);
                    bool ck = 1;
                    for (int l = 0; l < 4; l++) {
                        if (mymap.count(color)) cnt += mymap[color];
                        color = rotate(color);
                    }
                    for (int l = 0; l < 4; l++) {
                        if (mymap.count(color)) {
                            mymap[color]--; break;
                        }
                        color = rotate(color);
                    }
                    mul *= cnt;
                }
                for (int h = 0; h < 4; h++){
                    long long color = 0;
                    color += get(x, (h+1) % 4);
                    color *= 1000; color += get(x, h);
                    color *= 1000; color += get(a[i], h);
                    color *= 1000; color += get(a[i], (h+1) % 4);
                    for (int l = 0; l < 4; l++) {
                        if (mymap.count(color)) {
                            mymap[color]++; break;
                        }
                        color = rotate(color);
                    }
                }
                ans += mul;
                x = rotate(x);
            }
            mymap[a[i]]++; mymap[a[j]]++;
        }
    }
    ans /= 3;
    cout << ans;
}

Measured memory_bytes: 256
import math
def gcd(a,b,c):
    a = math.gcd(a, b)
    a = math.gcd(a, c)
    return a
ans=0
K=int(input())
for i in range(1,K+1): 
    for j in range(1,K+1):
        for k in range(1, K+1):
            ans+=gcd(i,j,k)
print(ans)

Measured memory_bytes: 68088
# vim: set fileencoding=utf-8 :

def main():
    n = int(raw_input())

    if n <= 8:
        print(0)
        exit()

    ans = 0
    for i in range(1, n + 1)[::2]:
        a = cal_yakusuu(i)
        if a:
            ans += 1

        i += 1

    print(ans)


def cal_yakusuu(odd):
    ret = False
    ct = 0
    for i in range(1, odd + 1):
        if odd % i == 0:
            ct += 1
            if ct > 8:
                ret = False

    if ct == 8:
        ret = True

    return ret


if __name__ == "__main__":
    main()


Measured memory_bytes: 2568