akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define fs first
#define sc second

int main(void){
    int n,r;
    cin >> n >> r;
    if(n < 10) r+= 100*(10-n);
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>

typedef long long ll;
using namespace std;

ll Mod = 1e9 + 7;
int main()
{
    int N, r=0, b=0;
    char a;
    cin >> N;

    for (int i = 0; i < N; i++) {
        cin >> a;
        if (a == 'R')r++;
        else b++;
    }
    if (r > b) cout << "Yes" << endl;
    else cout << "No" << endl;
 
    return 0;
}

Measured memory_bytes: 256
*D, = open(0)

n = int(D[0])
data = []
for i in range(n):
    city, score = D[i+1].split()
    data.append([i+1, city, int(score)])

data.sort(key=lambda x:x[2], reverse=True)
data.sort(key=lambda x:x[1])
for it in data:
    print(it[0])

Measured memory_bytes: 3064
N = int(input())

cnt = 0
judge = False

for _ in range(N):
    D1, D2 = map(int, input().split())
    if D1 == D2:
        cnt += 1
    else:
        cnt = 0

    if cnt == 3:
        judge = True

if judge:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9184
//2018-1-28
//miaomiao
//
#include <bits/stdc++.h>
using namespace std;

#define For(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define Forr(i, a, b) for(int i = (a); i >= (int)(b); --i)

#define N (100 + 5)

int a1[N], a2[N];
int pre[N], suf[N];

int main(){
	int n;

	scanf("%d", &n);
	For(i, 1, n) scanf("%d", &a1[i]);
	For(i, 1, n) scanf("%d", &a2[i]);

	For(i, 1, n) pre[i] = pre[i - 1] + a1[i];
	Forr(i, n, 1) suf[i] = suf[i + 1] + a2[i];

	int ans = 0;
	For(i, 1, n) ans = max(ans, pre[i] + suf[i]);
	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define INF 1000000000
int cnt=0;
void merge(int *,int,int,int);
void mergeSort(int *,int,int);
int main(){
  int n;
  int S[500001];
  int i;
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&S[i]);
  mergeSort(S,0,n);
  for(i=0;i<n;i++){
    printf("%d",S[i]);
    if(i!=n-1) printf(" ");
  }
  printf("\n");
  printf("%d\n",cnt);
  return 0;
}
 
void merge(int S[],int left,int mid,int right){
  int n1 = mid - left;
  int n2 = right - mid;
  int L[n1+1],R[n2+1];
  int i,j,k;
  for(i=0;i<n1;i++) L[i] = S[left + i];
  for(i=0;i<n2;i++) R[i] = S[mid + i];
  L[n1] = INF;
  R[n2] = INF;
  i = 0;
  j = 0;
  for(k = left; k< right;k++){
    if(L[i] <= R[j]){
      S[k] = L[i];
      i++;
    }
    else {
      S[k] = R[j];
      j++;
    }
    cnt++;
  }
}
 
void mergeSort(int S[],int left,int right){
  int mid;
  if(left + 1 < right){
    mid = (left + right) / 2;
    mergeSort(S,left,mid);
    mergeSort(S,mid,right);
    merge(S,left,mid,right);
  }
}


Measured memory_bytes: 5640
n,m=map(int,input().split())
l=[]
for i in range(m):
    x=list(map(int,input().split()))
    l.append(x)
p=list(map(int,input().split()))

sum=0
for i in range(2**n):
    sum1=0
    ll = [0] * (n)
    for j in range(n+1):
        if i >> j & 1:
            ll[j] = 1
    for h in range(m):
        k=l[h][0]
        total=0
        for x in range(1,k+1):
            total+=ll[l[h][x]-1]
        if total%2==p[h]:
            sum1+=1
    if sum1==m:
        sum+=1
print(sum)

Measured memory_bytes: 3064
def solve():
    N, M = map(int, input().split())
    if N > 0:
        return 'Positive'
    elif N <= 0 <= M:
        return 'Zero'
    else:
        
        if (-(N-M)+1) % 2 == 0:
            return 'Positive'
        else:
            return 'Negative'
            
    return 0

print(solve())


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

typedef long long LL;

int main(){
  LL a,b,c,d;
  scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
  printf("%lld\n",max(max(a*c,a*d),max(b*c,b*d)));
  return 0;
}

Measured memory_bytes: 3784
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(auto i=0;i<n;++i)
#define REPR(i,n) for(auto i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

using namespace std;

typedef pair<int,int> pii;

int main(){

  int n;
  cin >> n;

  if(n % 1000 == 0) cout << 0 << endl;
  else cout << 1000 - n % 1000 << endl;
  return 0;

}





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

using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	vector<long long> now;
	for (int i = 0; i < n; i++)
	{
		long long sum = 0;
		for (int j = i; j < n; j++)
		{
			sum += a[j];
			now.push_back(sum);
		}
	}
	sort(now.begin(), now.end(), greater<long long>());
	for (int b = 50; 0 <= b; b--)
	{
		vector<long long> next;
		for (long long tmp : now)
			if (tmp & ((long long)1 << b))
				next.push_back(tmp);
		if (k <= next.size())
			now = next;
	}
	long long ans = now[0];
	for (int i = 1; i < k; i++)
		ans &= now[i];
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 6516
#12:48

def MMcheck(n):
    return True if 0 < n <= 12 else False

n = str(input())
f2 = int(n[0:2])
l2 = int(n[2:5])
f2check = MMcheck(f2)
l2check = MMcheck(l2)

if f2check == True and l2check == True:
    print('AMBIGUOUS')
elif f2check == True and l2check == False:
    print('MMYY')
elif f2check == False and l2check == True:
    print('YYMM')
else:
    print('NA')

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

int memo[100000];

int solve(int n){

  if(memo[n] > 0) return memo[n];

  if(n == 0) return 1;
  if(n == 1) return 1;
  if(n == 2) return 2;
 
  return memo[n] = solve(n - 1) + solve(n - 2) + solve(n - 3);
}

int main(){

  unsigned long long int n,a;

  while(cin >> n, n){

    a = solve(n);

    if(a % 3650 > 0) cout << a/3650+1 << endl;
    else cout << a/3650 << endl;
  }
}

Measured memory_bytes: 1148
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;

int main() {
  
  int a,b,c,d,x;
  long long la,lb;
  double da,db;
  string s,ss,sss;
  
  int ans = 0;
  string anss = "";
  
  cin >> a >> b;
  
  int ab [] = {0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1};
  int result3 = std::max({a, b, c});
//--------------------------------------------------------------------------------

  if(a*500 >= b) anss = "Yes";
  else anss = "No";

  cout << anss << endl;

}

Measured memory_bytes: 256
h,w = [int(x) for x in input().split()]
if w%2==1:
  a = (w+1)//2
  b = w-a
else:
  a=w//2
  b=w-a
ans = 0
if w==1:
  print(1)
  exit()
if h%2==1:
  ans+=(a+b)*(h//2)
  ans+=a if h!=1 else 1
else:
  ans+=(a+b)*(h//2)
print(ans)

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

int main() {
  int N;
  double ans;
  cin >> N;
  if (N % 2==0) {
    ans = 0.5;
  } else {
    double a;
    a = (double)N;
    ans = (a+1)/(2*a);
  }
  cout << fixed << setprecision(10);
  cout << ans << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>

using namespace std;

#define D(x) x
#define REP(i,a,b) for (int i = (a); i < (b); ++i)
#define REPR(i,a,b) for (int i = (b) - 1; i >= (a); --i)
#define mp make_pair

typedef unsigned long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<vector<int> > VII;

void solve() {
    int N; cin >> N;
    ll a, b; cin >> a >> b;
    ll lastc = a, lastd = b;
    REP(i,1,N) {
        ll c, d; cin >> c >> d;
        if (lastc * d >= c * lastd) {
            a = ((a + c - 1) / c) * c;
            b = a / c * d;
        } else {
            b = ((b + d - 1) / d) * d;
            a = b / d * c;
        }
//        cout << "a: " << a << ", b: " << b << endl;
        lastc = c;
        lastd = d;
    }
    cout << a + b << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12) << fixed;

    solve();

	return 0;
}


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

int month[]={0,31,29,31,30,31,30,31,31,30,31,30,31};

int main(){
	
	int m,d;
	
	while(scanf("%d %d",&m,&d),(m!=0)){
		for(int i=0;i<m;i++){
			d=d+month[i];
		}
		d=d%7;
		
		switch(d){
		case 0:
			cout<<"Wednesday"<<endl;
			break;
		case 1:
			cout<<"Thursday"<<endl;
			break;
		case 2:
			cout<<"Friday"<<endl;
			break;
		case 3:
			cout<<"Saturday"<<endl;
			break;
		case 4:
			cout<<"Sunday"<<endl;
			break;
		case 5:
			cout<<"Monday"<<endl;
			break;
		case 6:
			cout<<"Tuesday"<<endl;
		}
	}
	return 0;
}
  

Measured memory_bytes: 1200
#include <stdio.h>
#include <stdlib.h>

int main(void){
	int n,x,l[101],i,d[101],cnt=1;
	scanf("%d %d",&n,&x);
	for(i=0;i<n;i++){
		scanf("%d",&l[i]);
	}
	
	d[0] = 0;
	for(i=1;i<n+1;i++){
		d[i] = d[i-1] + l[i-1];
		if(d[i] <= x){
			cnt++;
		}
	}
	printf("%d\n",cnt);
	
	
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  int C[N-1], S[N-1], F[N-1];
  rep(i, N-1){
    cin >> C[i] >> S[i] >> F[i];
  }
  int ans[N];
  rep(i, N-1){
    ans[i] = S[i];
    for(int j=i; j<N-1; j++){
      ans[i] += C[j];
      if(j < N-2){
        if(ans[i] < S[j+1])
          ans[i] = S[j+1];
        else if(ans[i]%F[j+1] != 0) ans[i] += (F[j+1] - ans[i]%F[j+1]);
      }
    }
  }
  ans[N-1] = 0;
  rep(i, N){
    cout << ans[i] << endl;
  }
  
  
    

}

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

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

    int N;
    cin >> N;
    vector<int> V;
    for (int i = 0; i < N; i++) {
        int v;
        cin >> v;
        V.push_back(v);
    }
    vector<int> C;
    for (int i = 0; i < N; i++) {
        int c;
        cin >> c;
        C.push_back(c);
    }
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        if (V[i] - C[i] > 0) cnt += V[i] - C[i];
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.read
from itertools import accumulate
def main():
    n, k, *p = map(int, read().split())
    p2 = [(1 + pe) /2 for pe in p]
    p2a = tuple(accumulate(p2))
    r = p2a[k-1]
    for i1 in range(k, n):
        r = max(r, p2a[i1] - p2a[i1-k])
    print(r)

if __name__ == '__main__':
    main()

Measured memory_bytes: 34700
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i <= (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;

int main() {
  int N; cin >> N;
  vi V(N); rep(i,N) cin >> V.at(i);
  vi C(N); rep(i,N) cin >> C.at(i);
  
  int ans = 0;
  rep(i,N) {
    if (V.at(i) > C.at(i)) {
      ans += V.at(i) - C.at(i);
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
s = input()
a = int(s[0]) * 10 + int(s[1])
b = int(s[2]) * 10 + int(s[3])
if (b > 12 or b <= 0) and (a > 12 or a <= 0):
    print('NA')
elif 12 >= b >= 1 and 12 >= a >= 1:
    print('AMBIGUOUS')
elif 12 >= a >= 1:
    print('MMYY')
else:
    print('YYMM')

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  int dp[10][10] = {};
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    string s = to_string(i);
    dp[s[0]-'0'][s.back()-'0']++;
  }

  for (int i=1; i<10; i++) {
    for (int j=1; j<10; j++) {
      ans += dp[i][j] * dp[j][i];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

class UnionFind {
    public:
        vector<int> data;
        UnionFind(int size) : data(size,-1){}
        void make(int x){
             data[x] =x;
        }
        bool unite(int x, int y) {
            x = root(x); 
            y = root(y);
            if (x != y){
                data[x]=y;
            }
            return x != y;
        }
        bool find(int x, int y) {
            return root(x) == root(y);
        }
        int root(int x) {
            if(data[x]==x)
                return x;
            else{
                data[x] = root(data[x]);
                return data[x];
            }
        }
};
int main(){
    int n, q;
    int c, x, y;
    cin>>n;
    UnionFind* tree = new UnionFind(n);
    for(int i=0;i<n;i++)
        tree->make(i);
    cin>>q;
    for(int i=0;i<q;i++){
        cin>>c>>x>>y;
        if(c==0){
            tree->unite(x,y);
        }else{
            if(tree->find(x,y)){
                cout<<1<<endl;
            }else{
                cout<<0<<endl;
            }
        }
    }
    delete tree;
    return 0;
}

Measured memory_bytes: 1404
#include<bits/stdc++.h>
using namespace std;
#define INFTY 1<<20
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long int ll;
const int MOD=1000000007;
int main(){

    int n,k;
    string s;
    cin >>n>>k>>s;
    vector<int> cnt(n,0);
    int g=1;cnt[0]=1;
    for (int i = 1; i < n; i++)
    {
        if(s[i]!=s[i-1])g++;
        else cnt[g]++;
    }
    if(g<=2){
        cout<<n-1<<endl;
    }
    else {
        int ans = min(n-g+2*k,n-1);
        cout<<ans<<endl;;
    }
    return 0;   
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=5e5;

  ll n,L=2,R=2;
  ll a[N];

void GG()
{
  puts("-1");
  exit(0);
}

int main()
{
  cin>>n;
  for (ll i=0;++i<=n;)
    scanf("%lld",a+i);
  for (ll i=n;i;--i)
    {
      L=(L-1)/a[i]*a[i]+a[i];
      R=R/a[i]*a[i]+a[i]-1;
      if (L>R) GG();
    }
  cout<<L<<' '<<R;
  exit(0);
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>							
typedef long long ll;
#define pb push_back
#define mod 1000000007ll
const ll maxn = 9e18;
using namespace std;
const ll maxsize = 100000009;


int wa[100005];
void solve() {
	int n, cnt = 0;
	string s;
	cin >> n >> s;
	for(int i = 0; i < n - 2;) {
		if(s.substr(i, 3) == "ABC") cnt++, i += 3;
		else i++;
		}
		cout << cnt << endl;
		return;
}


int main() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cout.precision(35);
	solve();
	return 0;
}
 
 
 



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

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)

int main(){
  int n;
  cin >> n;
  vector<pair<int, int> > p;
  vector<pair<int, int> > m;
  REP(i, n){
    string s;
    cin >> s;
    int d = 0;
    int mini = 0;
    for(char c: s){
      c == '(' ? ++d : --d;
      if(d < mini) mini = d;
    }
    if(d >= 0){
      p.push_back(make_pair(-mini, d));
    }else{
      m.push_back(make_pair(d - mini, -d));
    }
  }
  sort(p.begin(), p.end());
  sort(m.begin(), m.end());
  int g = 0;
  for(auto& v: p){
    if(g - v.first < 0){
      cout << "No" << endl;
      return 0;
    }
    g += v.second;
  }
  int h = 0;
  for(auto& v: m){
    if(h - v.first < 0){
      cout << "No" << endl;
      return 0;
    }
    h += v.second;
  }
  cout << (g == h ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 11332
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std;
#define maxn 10000000


int main()
{
	int a,b,c,ans=0;
	cin>>a>>b>>c;
	rep(i,a,b+1)
		if(i%c==0) ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
const int MAXN = 1e3 + 5, MAXM = 2e5 + 5, BOUND = 1e7, MOD = 1073741824, INF = 0x3f3f3f3f, base = 10000;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0), eps = 1e-9;
#define mid l + ((r-l)>>1)
#define lson o<<1,l,m
#define rson o<<1|1,m+1,r
#define lc(x) ch[x][0]
#define pii pair<int,int>
#define vi vector<int>
#define RR register int
#define rc(x) ch[x][1]
#define rep(i,a,b) for(RR i=(a);i<=(b);++i)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
int n, m;
char mp[MAXN][MAXN];
struct Node {
	int x, y, step;
}cur, nxt;
int dx[4] = { -1,1,0,0 };
int dy[4] = { 0,0,-1,1 };
bool vis[MAXN][MAXN];
bool bound(int x, int y) {
	return x >= 1 && x <= n && y >= 1 && y <= m;
}
int bfs() {
	int ans = 0;
	queue<Node> q;
	rep(i, 1, n) {
		rep(j, 1, m) {
			if (mp[i][j] == '#')q.push({ i,j,0 }), vis[i][j] = 1;
		}
	}
	while (q.size()) {
		cur = q.front(); q.pop();
		ans = max(ans, cur.step);
		rep(i, 0, 3) {
			nxt.x = cur.x + dx[i];
			nxt.y = cur.y + dy[i];
			nxt.step = cur.step + 1;
			if (!bound(nxt.x, nxt.y) || vis[nxt.x][nxt.y])continue;
			vis[nxt.x][nxt.y] = 1;
			q.push(nxt);
		}
	}
	return ans;
}
int main() {
	cin >> n >> m;
	rep(i, 1, n) {
		cin >> (mp[i] + 1);
	}
	cout << bfs() << '\n';
	return 0;
}

Measured memory_bytes: 14352
<?php
$input = trim(fgets(STDIN));
$array = explode(" ", $input);
list($cityCount, $roadCount) = $array;
$cities = array($cityCount);

for ($i = 0; $i < $cityCount; $i++) {
  $cities[$i] = 0;
}

for ($i = 0; $i < $roadCount; $i++) {
  $input = trim(fgets(STDIN));
  $array = explode(" ", $input);
  list($start, $end) = $array;
  $cities[$start - 1] += 1;
  $cities[$end - 1] += 1; 
}

for ($i = 0; $i < count($cities); $i++) {
  echo $cities[$i] . "\n";
}

Measured memory_bytes: 4732
#include<iostream>
using namespace std;
int main()
{
	int n,a[51],b=0;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++)
	{
		if(a[i]!=i) b++;
	}
	if(b>2) cout<<"NO";
	else cout<<"YES";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>

int main(int argc, char* argv[])
{
  std::string s, t;
  std::cin >> s >> t;

  int ans_idx = -1;
  for (std::string::iterator it = s.begin(); it != s.end(); it++) {
    int idx = std::distance(s.begin(), it);
    std::string sub = s.substr(idx, t.size());

    if (sub.size() != t.size()) {
      continue;
    }

    bool judge = true;
    for (std::string::iterator sub_it = sub.begin(); sub_it != sub.end(); sub_it++) {
      int sub_idx = std::distance(sub.begin(), sub_it);
      if (sub[sub_idx] != '?' && sub[sub_idx] != t[sub_idx]){
	judge = false;
      }
    }
    if (judge == true) {
      ans_idx = idx;
    }
  }

  if (ans_idx == -1) {
    s = "UNRESTORABLE";
  } else {
    s.replace(ans_idx, t.size(), t.c_str());
    std::replace(s.begin(), s.end(), '?', 'a');
  }
  std::cout << s << std::endl;

  return 0;
}


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

void solve() {
        long long a, b;
        int p;
        cin >> a >> b;
        if (a == b) {
                cout << 1 << endl;
                return;
        }
        for (int i = 61; i >= 0; i --) {
                if (a >= (1LL << i)) {
                        a -= (1LL << i);
                        b -= (1LL << i);
                }
                if (b >= (1LL << i)) {
                        p = i;
                        break;
                }
        }
        b -= (1LL << p);
        int q = 0;
        while (true) {
                if ((1LL << q) > b) break;
                q ++;
        }
        //cerr << p << ' ' << q << endl;
        long long mi = a, ma = (1LL << q);
        long long ans = (1LL << p) - mi;
        //cerr << ans << endl;
        if (ma > mi) ans += (1LL << p);
        else ans += ma + (1LL << p) - mi;
        cout << ans << endl;
        return;
}

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



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

int gcd(int x, int y){
  return x%y ? gcd(y,x%y):y;
}
  


int main()
{
  int N;
  cin>>N;
  int A[N];
  for(int i=0;i<N;i++) {
    cin>>A[i];
  }
  
  /*
  cout<<"A: ";
  for(int i=0;i<N;i++){
    cout<<A[i]<<" ";
  }
  cout<<endl;
  */
  
  int L[N],R[N];
  L[0]=A[0];
  R[N-1]=A[N-1];
  for(int i=1;i<N;i++) {
    L[i]=gcd(L[i-1],A[i]);
    R[N-1-i]=gcd(R[N-1-i+1],A[N-1-i]);
  }
  
  /*
  cout<<"L: ";
  for(int i=0;i<N;i++){
    cout<<L[i]<<" ";
  }
  cout<<endl;
  cout<<"R: ";
  for(int i=0;i<N;i++){
    cout<<R[i]<<" ";
  }
  cout<<endl;
  */
  
  set<int> st;
  st.insert(R[1]);
  st.insert(L[N-2]);
  for(int i=1;i<N-1;i++) {
    st.insert(gcd(L[i-1],R[i+1]));
  }
  
  /*
  cout<<"st: ";
  for(auto itr=st.begin();itr!=st.end();++itr){
    cout<<*itr<<" ";
  }
  cout<<endl;
  */
  
  auto itr=st.end();
  cout<<*(--itr);
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {

    int N, K;
    cin >> N >> K;
    vector<int> H(N);
    rep(i,N) cin >> H[i];

    sort(H.begin(), H.end(), greater<int>());

    long long ans = 0;
    rep(i,N) {
        if (i >= K) ans += H[i];
    }

    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 1024
o = input().strip()
e = input().strip()

a = ''

if len(o)-len(e) == 0:
    for i in range(len(o)):
        a += o[i]
        a += e[i]
    print(a)
else:
    for i in range(len(e)):
        a += o[i]
        a += e[i]
    a += o[len(o)-1]
    print(a)

Measured memory_bytes: 3060
def main():
    N = int(input())
    A = list(map(int,input().split()))
    if 0 in A:
        print(0)
        return

    ans = 1
    for i in A:
        ans *= i
        if ans > 1000000000000000000:
            print(-1)
            return
    print(ans)
main()

Measured memory_bytes: 21508
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long int ll;

int main()
{
	int n;
	cin>>n;
	int ans = 0;
	int *a = new int[n];
	map<int,int> histogram;
	for(int i = 0; i < n; i++){
		cin>>a[i];
		for(int j = -1; j <= 1; j++){
			if( histogram.count(a[i]+j) == 0){
				histogram.insert(make_pair(a[i]+j,1));
			}else{
				histogram[a[i]+j]++;
			}
		}
	}
	for(auto iter = histogram.begin(); iter != histogram.end(); iter++){
		ans = max(ans,iter->second);
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 5120
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=m-1; i>=n; i--)
#define SORT(v,n) do{sort(v,v+n);reverse(v,v+n);}while(0)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x,n/2)%MOD;
  return x%MOD*POW(x,n-1)%MOD;
}

ll POW2(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW2(x*x,n/2);
  return x*POW2(x,n-1);
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll KAI2(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI2(m-1);
}

ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll COM2(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI2(m)/KAI2(n)/KAI2(m-n);
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}

ll ORD(ll x,ll n)
{
  if(x==0)return INF;
  if(x%n!=0)return 0;
  return 1+ORD(x/n,n);
}

int main()
{
  ll a,b,c;
  cin >> a >> b >> c;
  printf("%lld",c/a*b);
}

Measured memory_bytes: 256
#include<iostream>
#include<bitset>
#include<string>
using namespace std;
int main() {
    int n, a,j=0;
    bool bo = false;
    int ans[102] = { 0 },ans1=0;
    bitset <101> bset;
    while (1) {
		cin >> n;
		if(n==-1){
			break;
		}
        bset = n;
        for (int i = bset.size() - 1; i >= 0; i--) {
            if (i % 2 == 0) {
                if (1 & bset[i] == 1) {
                    ans[j] += 1;
                }
                if (i != 0) {
                    j++;
                }
            }
            else {
                if (1 & bset[i] == 1) {
                    ans[j] += 2;
                }
            }
        }
        for (int i = 0; i <= j; i++) {
            if (ans[i] != 0) {
                bo = true;
            }
            if (bo) {
                cout << ans[i];
            }
        }
		if(bo==false){
			cout<<0;
		}
		cout << endl;
        bo = false;
        for (int i = 0; i < 102; i++) {
            ans[i] = 0;
        }
        j = 0;
        bset = 0;
    }
    return 0;
}

Measured memory_bytes: 3044
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int x = scan.nextInt();

        if (x >= a && x <= a + b) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}


Measured memory_bytes: 23764
#include<iostream>
#include<string>
#include<map>
using namespace std;

int main(){
    int n;
    string str1, str2;
    map<string, int> dic;
    cin >> n;

    for( int i = 0; i < n; i++ ){
        cin >> str1 >> str2;
        if( str1 == "insert" )
            dic[str2] = 1;
        else{
            if( dic[str2] == 1 ) cout << "yes" << endl;
            else cout << "no" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 52568
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define F(i,a,n) for(int i=a; i<n; i++)
#define INF 100000000000 // long only


int main(){
  int n;
  long a,b,c;
  scanf("%d%ld%ld%ld",&n,&a,&b,&c);
  char s[n][3];
  F(i,0,n) scanf("%s",s[i]);
  int fab=0,fbc=0,fca=0;
  char ans[n];
  F(i,0,n){
    if(strcmp(s[i],"AB")==0){
      if(a==0 && b==0){
        printf("No\n");
        return 0;
      }
      if(a>b){
        ans[i]='B';
        a--;
        b++;
      }else if(a<b){
        ans[i]='A';
        a++;
        b--;
      }else{
        if(i+1<n && strcmp(s[i+1],"BC")==0 && a==1 && b==1 && c==0){
          ans[i]='B';
          a--;
          b++;
        }else{
          ans[i]='A';
          a++;
          b--;
        }
      }
    }else if(strcmp(s[i],"BC")==0){
      if(c==0 && b==0){
        printf("No\n");
        return 0;
      }
      if(b>c){
        ans[i]='C';
        b--;
        c++;
      }else if(b<c){
        ans[i]='B';
        b++;
        c--;
      }else{
        if(i+1<n && strcmp(s[i+1],"AC")==0 && a==0 && b==1 && c==1){
          ans[i]='C';
          c++;
          b--;
        }else{
          ans[i]='B';
          b++;
          c--;
        }
      }
    }else{
      if(a==0 && c==0){
        printf("No\n");
        return 0;
      }
      if(a>c){
        ans[i]='C';
        a--;
        c++;
      }else if(a<c){
        ans[i]='A';
        a++;
        c--;
      }else{
        if(i+1<n && strcmp(s[i+1],"AB")==0 && a==1 && b==0 && c==1){
          ans[i]='A';
          a++;
          c--;
        }else{
          ans[i]='C';
          c++;
          a--;
        }
      }
    }
  }
  printf("Yes\n");
  F(i,0,n)printf("%c\n",ans[i]);
  return 0;
}

Measured memory_bytes: 2116
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int N; cin>>N;
    vector<uint64_t> A(N);
    rep(n,0,N) cin>>A.at(n);

    sort(ToEnd(A),greater<uint64_t>());
    if(A.back()==0){
        cout<<0<<endl;
        return 0;
    }

    double Dans=1;
    uint64_t ans=1;
    for(auto a:A){
        Dans*=(double)a;
        if(Dans>1e18){
            cout<<-1<<endl;
            return 0;
        }
        ans*=a;
        if(ans>(uint64_t)1e18){
            cout<<-1<<endl;
            return 0;
        }
    }
    
    cout<<ans<<endl;
}

Measured memory_bytes: 4048
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <string>
#include <cstring>
using namespace std;
const int N = 1e5 + 5;
#define ll long long

int main() {
	int n,k,s;
	scanf("%d %d %d",&n,&k,&s);
	if(s<=2)
		for(int i=1;i<=n;i++)
			printf("%d%c",i<=k?s:3,i==n?'\n':' ');
	else
		for(int i=1;i<=n;i++)
			printf("%d%c",i<=k?s:s-1,i==n?'\n':' ');
	return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <iomanip>
//#include <bits/stdc++.h>
using namespace std;

using ll = long long;
const ll INF = 1e18L + 5;

struct Line {
    ll a, b;
    ll value(ll x){
        return a * x + b;
    }
    pair<ll, ll> inter(const Line& he) const {
        ll one = he.b - b;
        ll two = a - he.a;
        if(two < 0){
            one *= -1;
            two *= -1;
        }
        return {one, two};
    }
};

ll square(ll a){
    return a * a;
}


int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    
    int n;
    ll C;
    cin >> n >> C;
    vector<int> h(n);
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    
    vector<Line> lines;
    int start = 0;
    for(int i = 0; i < n; i++){
        
        while(start <= (int) lines.size() - 2){
            Line A = lines[start];
            Line B = lines[start + 1];
            if(A.value(h[i]) >= B.value(h[i])){
                start++;
            }
            else{
                break;
            }
        }
        ll best = 0; //dp[i]
        if(i != 0){
            best = lines[start].value(h[i]) + square(h[i]) + C;
        }
        Line line{-2 * h[i], best + square(h[i])};
        
        while(start <= (int) lines.size() - 2){
            Line A = lines.end()[-2];
            Line B = lines.end()[-1];
            pair<ll, ll> one = A.inter(B);
            pair<ll, ll> two = B.inter(line);
            
            if((__int128) one.first * two.second >= (__int128) one.second * two.first){
                lines.pop_back();
            }
            else{
                break;
            }
        }
        lines.push_back(line);
        if(i == n - 1){
            cout << best;
        }
    }
    
    
}



Measured memory_bytes: 7152
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int n,m;
cin >> n >> m;
int s;
int c;
char ans[n];
REP(i,n) ans[i]='x';
char x;
bool flg = true;
REP(i,m) {
  cin >> s >> c;
  s--;
  x = '0' + c;
  if(ans[s]=='x'||ans[s]==x) {
    ans[s]=x;
  } else {
    flg = false;
  }
}
if(n!=1&&ans[0]=='0') flg=false;
if(flg==true) {
  REP(i,n) {
    if(ans[i]=='x') {
      if(i==0&&n!=1) {
        cout << "1";
      } else {
        cout << "0";
      }
    } else {
      cout << ans[i];
    }
  }
  cout << endl;
} else {
  cout << "-1" << endl;
}
return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

ll dp[110][100100];

int main() {
    int N, W;
    cin >> N >> W;
    vector<int> w(N);
    vector<ll> v(N);
    rep(i,N) cin >> w[i] >> v[i];

    rep(i,N) {
        for(int j = 0; j<=W; ++j) {
            dp[i+1][j] = dp[i][j];
            if (j-w[i]>=0) dp[i+1][j] = max(dp[i+1][j],dp[i][j-w[i]]+v[i]);
        }
    }
    cout << dp[N][W] << endl;
    return 0;
}


Measured memory_bytes: 79360
n=int(input())
a=list(map(int,input().split()))
a.sort()
if n%2==0:
  for i in range(0,n,2):
    if a[i]!=i+1 or a[i+1]!=i+1:
        print(0)
        exit()
else:
  if a[0]!=0:
    print(0)
    exit()
  for i in range(2,n,2):
    if a[i-1]!=i or a[i]!=i:
      print(0)
      exit()
      
print((2**(n//2))%(10**9+7))

Measured memory_bytes: 13880
import java.util.*;

class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] a = new int[k];
		long sum = 0;
	    for(int i=0;i<k;i++)
	    {
	    	a[i] = sc.nextInt();
	    	sum = sum + a[i];
	    }
	    if(sum>=n)
	    {
	    	System.out.println("Yes");
	    }
	    else
	    {
	    	System.out.println("No");
	    }
	}
}

Measured memory_bytes: 49612
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define DEBUG
#define PI 3.141592653589793238462643383279
 
#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...) show(__VA_ARGS__);cout<<endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);}
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define REP1(i, n) for(ll i = 1; i <= n; i++)
#define REPR1(i, n) for(ll i = n; i >= 1; i--)
#define FOR1(i, m, n) for(ll i = m; i <= n; i++)
const ll INF = LLONG_MAX;
const ll MOD = 1000000007;
#define VEC(type,A,N) vector<type> A(N)
#define VECi(type,A,N,i) vector<type> A(N,i)
#define VEC2(type,A,N,M) vector<vector<type>> A(N,vector<type>(M))
#define VEC2i(type,A,N,M,i) vector<vector<type>> A(N,vector<type>(M,i))
#define ALL(v) v.begin(), v.end()
ll frac(ll k){
    int s = 1;
    for (ll i=1; i<=k; ++i)s *= i;
    return s;
}
ll gcd(ll a, ll b){
   if (a%b==0)return(b);
   else return(gcd(b, a%b));
}
ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}
ll antidiv(ll N,ll C,ll D){
    return N-floor(N/C)-floor(N/D)+floor(N/lcm(C,D));
}
vector<ll> yakusuu(ll N){
    vector<ll> ret;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            ret.push_back(i);
            if (i * i != N) ret.push_back(N / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}
int main(){
    ll N;
    cin>>N;
    
    vector<ll> a ={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51}; 
    cout<<a[N-1];
    //cout<<fixed<<setprecision(32)<<m;
    //sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];});
    //if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

//------------------------------------------------------

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

    int n, m, c;
    cin >> n >> m >> c;
    int b[m];
    rep(i, m) cin >> b[i];
    int cnt = 0;

    rep(i, n) {
        int sum = c;

        rep(j, m) {
            int a;
            cin >> a;
            sum += a * b[j];
        }
        if (sum > 0) cnt++;
    }
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;

const int MAX = 1e5 + 5;
int cnt[MAX];
int main()
{
	boost;
	int n, q, i;
	cin >> n;
	int arr[n];
	fo(i, 0, n)
	cin >> arr[i];
	ll sum = 0;
	
	for(int x : arr) {
		cnt[x]++;
		sum += x;
	}
	cin >> q;
	while(q--) {
		int x, y;
		cin >> x >> y;
		sum -= 1ll * cnt[x] * x;
		sum += 1ll * cnt[x] * y;
		cnt[y] += cnt[x];
		cnt[x] = 0;
		cout << sum << '\n';
	}
}


Measured memory_bytes: 4420
#include <stdio.h>
int main(void){
    int H, W, h, w, ans = 0;
    
    scanf("%d %d %d %d", &H, &W, &h, &w);
    
    ans = (H * W) - ((h * W) + ((w * H) - (w * h)));
    printf("%d\n", ans);
    
}


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

int main(){
int A, B;
string S;
  cin >> A >> B >> S;
bool a = true;  
  
  for(int i = 0;i < A;i++){
  if(!('0' <= S.at(i)) && (S.at(i) <= '9')){
  a = false;
    }
  }
  
  if(!(S.at(A) == '-')) a = false;
  
  for(int i = A + 1;i < S.size();i++){
  if(!('0' <= S.at(i)) && (S.at(i) <= '9')){
  a = false;
    }
  }
  
  if(a) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
  
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    
    n, k = map(int, input().split())
    
    fact = [1] * 2010
    inv = [1] * 2010
    for i in range(1, 2010):
        fact[i] = (i * fact[i - 1]) % 1000000007
        inv[i] = pow(fact[i], 1000000005, 1000000007)
    
    for j in range(1, k + 1):
        if n + 1 < k + j:
            print(0)
        else:
            ans = (fact[k - 1] * fact[n - k + 1] * inv[j - 1] * inv[k - j] * inv[j] * inv[n - k - j + 1]) % 1000000007
            print(ans)
    
    return 0

main()

Measured memory_bytes: 42480
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;

const long long MAXN = 1e12;
long long x,y;

void Slove(){
	long long xx,yy,sum1,sum2,sum3,ma_x,mi_n,ans,tot = MAXN;
	xx = x;
	yy = y;
	for(int i = 1;i <= yy - 1;i++){
		sum1 = i * xx;
		sum2 = (yy - i) * (xx / 2);
		sum3 = (yy - i) * ((xx + 1) / 2);
		ma_x = max(sum1,sum2) , ma_x = max(ma_x,sum3);
		mi_n = min(sum1,sum2) , mi_n = min(mi_n,sum3);
		ans = ma_x - mi_n;
		tot = min(tot,ans);
	}
	for(int i = 1;i <= yy - 1;i++){
		sum1 = i * xx;
		sum2 = ((yy - i) / 2) * xx;
		sum3 = yy * xx - (sum1 + sum2);
		ma_x = max(sum1,sum2) , ma_x = max(ma_x,sum3);
		mi_n = min(sum1,sum2) , mi_n = min(mi_n,sum3);
		ans = ma_x - mi_n;
		tot = min(tot,ans);
	}
	swap(xx,yy);
	for(int i = 1;i <= yy - 1;i++){
		sum1 = i * xx;
		sum2 = (yy - i) * (xx / 2);
		sum3 = (yy - i) * ((xx + 1) / 2);
		ma_x = max(sum1,sum2) , ma_x = max(ma_x,sum3);
		mi_n = min(sum1,sum2) , mi_n = min(mi_n,sum3);
		ans = ma_x - mi_n;
		tot = min(tot,ans);
	}
	for(int i = 1;i <= yy - 1;i++){
		sum1 = i * xx;
		sum2 = ((yy - i) / 2) * xx;
		sum3 = yy * xx - (sum1 + sum2);
		ma_x = max(sum1,sum2) , ma_x = max(ma_x,sum3);
		mi_n = min(sum1,sum2) , mi_n = min(mi_n,sum3);
		ans = ma_x - mi_n;
		tot = min(tot,ans);
	}

	printf("%lld\n",tot);
}

int main(){
	scanf("%lld %lld",&x,&y);
	if(x % 3 == 0 || y % 3 == 0) printf("0\n");
	else Slove();
}

Measured memory_bytes: 128
void main() {
	auto N = ri;
	int[] s;
	foreach(i; 0..N) {
		s ~= ri;
	}
	auto all = s.sum;
	if(all % 10 != 0) {
		writeln(all);
		return;
	} else {
		s.sort();
		foreach(i; s) {
			if(i % 10 != 0) {
				writeln(all - i);
				return;
			}
		}
	}
	writeln(0);
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

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;


void solve(long long S, long long W){
    if (W >= S)
        cout << "unsafe" << endl;
    else
        cout << "safe" << endl;

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long S;
    scanf("%lld",&S);
    long long W;
    scanf("%lld",&W);
    solve(S, W);
    return 0;
}


Measured memory_bytes: 3760
#include<stdio.h>
 
int main()
{
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if (W>=x+r && H>=y+r && r<=x && r<=y && x>=0 && y>=0){
        printf("Yes\n");}
        else {
            printf("No\n");}
             
    return 0;
}


Measured memory_bytes: 2128
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define eps 1e-10
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

double a,b,p1,p2,p3,p4;

int main()
{
	cin>>a>>b;
    for(int i=1;i<=1000;i++)
    {
        double x=i*0.08,y=i*0.1;
        x=(int)x; y=(int)y;
        if(x==a&&y==b) {cout<<i<<endl; return 0;}
    }
    puts("-1");
	return 0;
}

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

int main(){
    int s;
    cin>>s;
    int y1=s/100;
    int y2=s%100;
    if(y1>=1&&y1<=12){
        if(y2>=1&&y2<=12)cout<<"AMBIGUOUS"<<endl;
        else cout<<"MMYY"<<endl;
    }else{
        if(y2>=1&&y2<=12)cout<<"YYMM"<<endl;
        else cout<<"NA"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3636