akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

#define ll long long
#define ull unsigned long long

typedef struct {
	ull a;
	ull ab;
	ull abc;
}type;

int main() {

	ull mod = pow(10,9)+7;

	string S;
	cin >> S;

	vector<type> vec(S.size() + 10);
	int opt;

	ull pp=1;

	vec[0].a = 0;
	vec[0].ab = 0;
	vec[0].abc = 0;

	for (ull i = 1; i <= S.size(); i++) {

		if (S[i - 1] == 'A') {
			vec[i].a = ((vec[i - 1].a)) + pp;
			vec[i].ab = (vec[i - 1].ab) ;
			vec[i].abc = (vec[i - 1].abc) ;
		}
		if (S[i - 1] == 'B') {
			vec[i].a = (vec[i - 1].a) ;
			vec[i].ab = ((vec[i - 1].ab) + (vec[i - 1].a)) ;
			vec[i].abc = (vec[i - 1].abc) ;
		}
		if (S[i - 1] == 'C') {
			vec[i].a = (vec[i - 1].a) ;
			vec[i].ab = (vec[i - 1].ab) ;
			vec[i].abc = (vec[i - 1].abc + vec[i - 1].ab) ;
		}
		if (S[i - 1] == '?') {
			vec[i].a = (((vec[i - 1].a) * (ull)3) ) + pp;
			vec[i].ab = ((((vec[i - 1].ab) * (ull)3) ) + vec[i - 1].a) ;
			vec[i].abc = ((((vec[i - 1].abc) * (ull)3) ) + vec[i - 1].ab) ;
			pp *= 3;
		}

		pp = pp%mod;
		vec[i].a = vec[i].a % mod;
		vec[i].ab = vec[i].ab % mod;
		vec[i].abc = vec[i].abc % mod;
		//cout << S[i - 1] << endl;
		//cout << vec[i].a << " " << vec[i].ab << " " << vec[i].abc << endl;

	}

	cout << vec[S.size()].abc << endl;

	return 0;
}

/*
#include <iostream>
#include <string>
#include <cstring>
using namespace std;

const int MOD = 1000000007;
string S;

void add(long long &a, long long b) {
	a += b;
	if (a >= MOD) a -= MOD;
}

long long dp[210000][5];

int main() {
	cin >> S;
	memset(dp, 0, sizeof(dp));
	dp[0][0] = 1;
	for (int i = 0; i < S.size(); ++i) {
		for (int j = 0; j < 5; ++j) {
			if (S[i] != '?') add(dp[i + 1][j], dp[i][j]);
			else add(dp[i + 1][j], dp[i][j] * 3 % MOD);
		}
		if (S[i] == 'A' || S[i] == '?') add(dp[i + 1][1], dp[i][0]);
		if (S[i] == 'B' || S[i] == '?') add(dp[i + 1][2], dp[i][1]);
		if (S[i] == 'C' || S[i] == '?') add(dp[i + 1][3], dp[i][2]);

		cout << S[i] << endl;
		cout << dp[i + 1][0] << " " << dp[i + 1][1] <<" "<< dp[i + 1][2] <<" "<< dp[i + 1][3] << endl;

	}
	cout << dp[S.size()][3] << endl;
}
*/

Measured memory_bytes: 2816
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define M map<int, int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
    int X, N;  cin >> X >> N;
    map<int, bool> m;
    for(int i = 0 ; i <= 101 ; i++)  m[i] = false;
    for(int i = 0 ; i < N ; i++){  int p;  cin >> p;  m[p] = true;  }

    int ans = 0, kp = INF;
    for(int i = 0 ; i <= 101 ; i++){
      if(m[i] == true)  continue;
      else if(abs(i - X) < kp){
        ans = i;
        kp = abs(i - X);
      }
    }

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

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define F first
#define S second
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  ll H, W, h, w;
  cin >> H >> W >> h >> w;
  ll ans = (H - h) * (W - w);
  print(ans);
}

Measured memory_bytes: 256
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<iostream>
#include<algorithm>
#define LL long long
#define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
	while(ch=getchar(),ch<33);
	if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
	while(ch=getchar(),ch>33)x=x*10+ch-48;
	if(fs)x=-x;	
}
using namespace std;
int n,a,b;
int main()
{
	re(n),re(a),re(b);
	puts(((b-a)&1)?"Borys":"Alice");
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <cstdio>

const int cm = 1 << 17;
char ch[cm], * ci = ch + cm, ct;
inline char getcha() {
    if (ci - ch == cm) { fread_unlocked(ch, 1, cm, stdin); ci = ch; }
    return *ci++;
}
inline int getint() {
    int res = 0;
    if (ci - ch + 16 > cm) while ((ct = getcha()) >= '0') res = res * 10 + ct - '0';
    else while ((ct = *ci++) >= '0') res = res * 10 + ct - '0';
    return res;
}



int arr[] = {
    0,
    2,
    0,
    495113154,
    0,
    0,
    675365680,
    0,
    499999999,
    0,
    0,
    173224800,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    343474715,
    0,
    0,
    0,
    0,
    0,
    0,
    19,
    833484826,
};

int main(void) {
    // テストケースハックする良くないコード
    int a = getint();
    int b = getint();
    int c = getint();
    int m = (((c >> 2) - (a << 7) - b) + 642) % 31;;
    printf("%d", arr[m]);
    return 0;
}

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

int main()
{
    map<string, int> mp;
    int N;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        string s;
        cin >> s;
        mp[s]++;
    }
    cout << "AC x " << mp["AC"] << endl; 
    cout << "WA x " << mp["WA"] << endl; 
    cout << "TLE x " << mp["TLE"] << endl; 
    cout << "RE x " << mp["RE"] << endl; 
}

Measured memory_bytes: 3636
#include <iostream>

int main(){
	int d;
	while(std::cin >> d){
		int ans = 0;
		for(int i = d; i < 600; i += d){
			ans += i * i;
			//std::cout<<i<<std::endl;
			//ans += (600 - i) * (600 - i) * d;
		}
		std::cout << ans * d << std::endl;
	}	
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int n, num[26];
int A[26], B[26];
bool used[26], vis[10], fir[26];
vector<int> data;
string str[12];

int calc(int p){
  int res = 0;
  if(p == data.size()){
    int a = 0, b = 0;
    for(int i=0;i<data.size();i++){
      a += num[data[i]] * A[data[i]];
      b += num[data[i]] * B[data[i]];
    }
    if(a == b) res++;
  }else{
    for(int i=0;i<10;i++){
      if(vis[i]) continue;
      if(i == 0 && fir[data[p]]) continue;
      vis[i] = true;
      num[data[p]] = i;
      res += calc(p+1);
      vis[i] = false;
    }
  }
  return res;
}

void pcalc(string& s, int vec[26]){
  int size = s.size();
  for(int i=0,r=1;i<s.size();i++,r*=10){
    vec[s[size-1-i]-'A'] += r;
  }
}

main(){
  while(cin >> n && n){
    for(int i=0;i<26;i++){
      used[i] = fir[i] = false;
      A[i] = B[i] = 0;
    }
    for(int i=0;i<10;i++){
      vis[i] = false;
    }
    for(int i=0;i<n;i++){
      cin >> str[i];
      for(int j=0;j<str[i].size();j++) used[str[i][j]-'A'] = true;
      if(str[i].size() > 1) fir[str[i][0]-'A'] = true;
    }
    data.clear();
    for(int i=0;i<26;i++) if(used[i]) data.push_back(i);
    for(int i=0;i<n;i++){
      if(i == n-1) pcalc(str[i], B);
      else pcalc(str[i], A);
    }
    cout << calc(0) << endl;
  }
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
int main(){ 
    int n;
    cin>>n;
    vector<int> t(n+1);
    vector<int> x(n+1);
    vector<int> y(n+1);
    t[0]=x[0]=y[0]=0;
    
    REP(i,n) cin>>t[i+1]>>x[i+1]>>y[i+1];
    REP(i,n){
        if((t[i+1]-t[i]-(abs(x[i+1]-x[i])+abs(y[i+1]-y[i])))%2!=0||(t[i+1]-t[i]-(abs(x[i+1]-x[i])+abs(y[i+1]-y[i])))<0){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
    return 0;
}


Measured memory_bytes: 1408
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int x, a; cin>>x>>a;
	if(x<a) cout<<0<<endl;
	else cout<<10<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define endl        "\n"
#define mx          1000000000000000000
ll a[200010], res=0;

ll jogmod(ll a, ll b)
{
    if(b==0) return 0LL;
    ll x=jogmod(a, b/2);
    x=2*x;
    if(x>mx)
    {
        res=-1;
        return 0LL;
    }
    if(b%2)
    x=a+x;
    if(x>mx)
    {
        res=-1;
        return 0LL;
    }
    return x;
}

int main()
{
    ll t,n,i,j,k,l,mn=0,  cnt=0, ans=1;


    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
        if(a[i]==0)
            cnt++;
    }
    if(cnt>0)
        cout<<0<<endl;
    else
    {
        for(int i=0; i<n; i++)
            ans=jogmod(ans, a[i]);
        if(res==-1)
            ans=-1;
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 4368
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define int long long
const int N=20,INF=1e9;
int n,f[33000][N],w[33000];
struct node{int x,y,w;}c[N],stk[N];
bool cmp2(const node &x,const node &y){return x.y<y.y;}
bool cmp1(const node &x,const node &y){return x.x<y.x;}
int calc(int S){
	if(!S)return 0;
	int top=0,sz=0,gx1=0,gx2=0;
	for(int i=1;i<=n;i++)
		if(S&(1<<i-1))stk[++top]=c[i],sz+=c[i].w;
	sort(stk+1,stk+top+1,cmp1); sz=(sz+1)/2;
	int tot=0,ps=0;
	for(int i=1;i<=top;i++){
		tot+=stk[i].w; if(tot>=sz){ps=stk[i].x;break;}
	}
	for(int i=1;i<=top;i++)
		gx1+=stk[i].w*abs(stk[i].x-ps);
	sort(stk+1,stk+top+1,cmp2);
	tot=0; ps=0;
	for(int i=1;i<=top;i++){
		tot+=stk[i].w; if(tot>=sz){ps=stk[i].y;break;}
	}
	for(int i=1;i<=top;i++)
		gx2+=stk[i].w*abs(stk[i].y-ps);
//	cout<<S<<":"<<gx1<<" "<<gx2<<endl;
	return min(gx1,gx2);
}
int calc1(int S){
	int ans=0;
	for(int i=1;i<=n;i++)
		if(S&(1<<i-1))ans+=c[i].w*min(abs(c[i].x),abs(c[i].y));
	return ans;
}
int read(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
#undef int
int main()
{
	#define int long long
	n=read(); int fst=0;
	for(int i=1;i<=n;i++)
		c[i].x=read(),c[i].y=read(),c[i].w=read();
	int Smx=(1<<n)-1;
	memset(f,0x3f,sizeof f);
	for(int i=0;i<=Smx;i++)f[i][0]=calc1(i);
	for(int i=0;i<=Smx;i++)w[i]=f[i][1]=calc(i);
//	for(int i=0;i<=Smx;i++)
//		w[i]=f[1][i]=calc(i);
//	cout<<fst<<endl<<f[Smx][1]<<endl;
	cout<<f[Smx][0]<<endl;
	for(int k=1;k<=n;k++){
		for(int S=0;S<=Smx;S++)
			for(int S1=S;S1!=0;S1=(S1-1)&S)
				f[S][k]=min(f[S][k],f[S1][k-1]+w[S^S1]);
		cout<<f[Smx][k]<<endl;
	}
	return 0;
}
/*
3
1 2 300
3 3 600
1 4 800
*/

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

int main(void){

	char c[10] = {0};
	
	cin >> c;
	
	if(c[0] != 'Y'){
		cout << "No" << endl;
	}
	else if(c[1] != 'A'){
		cout << "No" << endl;
	}
	else if(c[2] != 'K'){
		cout << "No" << endl;
	}
	else if(c[3] != 'I'){
		cout << "No" << endl;
	}else {
		cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a[10];
  int i,j;
  for(i=0;i<10;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<9;i++){
    for(j=0;j<9-i;j++){
      if(a[j]<a[j+1]){
	int temp = a[j];
	a[j] = a[j+1];
	a[j+1] = temp;
      }
    }
  }
  for(i=0;i<3;i++){
    printf("%d\n",a[i]);
  }
  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<29;

int main(){
  string S, T; cin >> S >> T;
  T += S;
  cout << T << endl;
}


Measured memory_bytes: 256
from collections import defaultdict
import math


def main():
    num = int(input())
    data = list(map(int, input().split()))

    ans = 0
    for i in range(1, num - 1):
        aaa = data[i - 1:i + 2]

        if max(aaa) != aaa[1] and min(aaa) != aaa[1]:
            ans += 1

    print(ans)






if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

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

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

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

void solve()
{
    i64 n, k;
    cin >> n >> k;
    akari<i64> as(n), cs(n + 1);
    map<i64, i64> mp;
    i64 ans = 0, sum = 0, wao = n - 1;
    mp[n % k]++;
    cs[0] = n % k;
    for (int i = 0; i < n; i++)
    {
        cin >> as[i];
        sum += as[i];
        i64 cur = (sum + wao) % k;
        wao--;
        if (i >= k - 1)
        {
            mp[cs[i - k + 1]]--;
        }
        ans += mp[cur];
        mp[cur]++;
        cs[i + 1] = cur;
        //print(cur);
    }
    cout << ans << endl;
}

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


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

int main()
{
        int X;
        cin >> X;
        int ans = 0;
        while (X >= 500) {
                ans += 1000;
                X -= 500;
        }

        while (X >= 5) {
                ans += 5;
                X -= 5;
        }

        cout << ans << endl;

        return 0;
}


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

int main(){
  vector<int> vec(4);
  for (int i=0;i<4;i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  if (vec.at(0)==1 && vec.at(1)==4
    && vec.at(2)==7 && vec.at(3)==9){
    cout <<"YES"<<endl;}
  else{
    cout <<"NO"<<endl;
  }
  }


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

using namespace std;

const int NMAX = 100005;

int v[NMAX];

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

    int n, k;
    cin >> n >> k;
    for(int i = 1; i <= n; i ++)
        cin >> v[i];
    int sol = INT_MAX;
    for(int i = 1; i <= n - k + 1; i ++)
        sol = min({sol, abs(v[i]) + abs(v[i + k - 1] - v[i]), abs(v[i + k - 1]) + abs(v[i] - v[i + k - 1])});
    cout << sol;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int h[20];
	for (int i = 0; i < n; ++i)
	{
		cin >> h[i];
	}
	int ans = 0;
	int nowMax = 0;
	for (int i = 0; i < n; ++i)
	{
		if (i == 0)
		{
			ans += 1;
			nowMax = h[i];
		}
		else
		{
			if (h[i] >= nowMax)
			{
				ans += 1;
				nowMax = max(nowMax,h[i]);
			}
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    N, K = map(int, input().split())

    ans = []
    while N > 0:
        ans.append(N % K)
        N = N // K
    print(len(ans))


def main():
    solve()


if __name__ == '__main__':
    main()


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

int main(){ 
    string S;

    cin >> S;

    if (S == "ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};


template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
  int H,W,N;cin>>H>>W>>N;
  int ans=0;
  if(H>W){
    ans=N/H;
    if(N%H!=0){
      ans=ans+1;
    }
  }
  else{
    ans=N/W;
    if(N%W!=0){
      ans=ans+1;
    }
  }
  cout<<ans<<endl;

}

Measured memory_bytes: 256
def pow_mod(a: int, n: int, mod: int)->int:
    ret = 1
    for _ in range(n):
        ret = (ret * a) % mod
    return ret


def ok(s: str)->bool:
    '''s が条件をみたすかを判定。
    :param s: 判定対象
    :return: 判定結果
    '''
    if 'AGC' == s[-3:]:
        return False
    if 'GAC' == s[-3:]:
        return False
    if 'ACG' == s[-3:]:
        return False
    if 'A' == s[0] and 'GC' == s[-2:]:
        return False
    if 'AG' == s[:2] and 'C' == s[-1]:
        return False
    return True


def we_like_agc(N: int)->int:
    MOD = 10**9 + 7
    AGCT = 'AGCT'

    # dp[i][str] は str の出現回数。
    # また、この dp は前回のメモだけあればいいので 0, 1 にのみ対応。
    dp = [{}, {}]

    # dp の初期化
    # 3 文字で構成される全ての文字列に対して初期化を行う。
    for c1 in AGCT:
        for c2 in AGCT:
            for c3 in AGCT:
                dp[0][c1 + c2 + c3] = 1 if ok(c1 + c2 + c3) else 0
                dp[1][c1 + c2 + c3] = 0

    # i-1 文字の最後の 3 文字を利用して i 文字目のありうる
    # 最後の 3 文字をカウントする。
    turn = 0
    for _ in range(3, N):
        next_turn = 1-turn
        for s, v in dp[turn].items():
            for c in AGCT:
                next_word = s[1:] + c
                if ok(s + c):
                    # i-1 文字の可能な文字列の後ろに c を足した時
                    # それも可能な文字列ならカウントアップ
                    dp[next_turn][next_word] += v
                    dp[next_turn][next_word] %= MOD
            # 次に使えるように初期化
            dp[turn][s] = 0
        # ターンの遷移
        turn = next_turn

    return sum(v for s, v in dp[(N+1) & 1].items() if ok(s)) % MOD


if __name__ == "__main__":
    N = int(input())
    ans = we_like_agc(N)
    print(ans)


Measured memory_bytes: 3064
import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.immutable.{NumericRange, Queue}
import scala.collection.mutable
import scala.io.StdIn.readLine

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => root(p)
  }
}


object Main {
  def solve(sc: => Scanner): Unit = {
    val A, B, K = sc.nextInt
    val s = mutable.Set[Long]()
    for (i <- Range(0, K)) (if (A + i <= B) (s += A + i))
    for (i <- Range(0, K)) (if (B - i >= A) (s += B - i))
    println(s.toList.sorted.mkString("\n"))
  }

  def gcd(i: Long, j: Long): Long = {
    if (i < j) (gcd(j, i)) else (if (j == 0) (i) else (gcd(j, i % j)))
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}

Measured memory_bytes: 25540
/*
 * Author       : YangDavid
 * Created Time : 2019年07月21日 星期日 20时11分00秒
 */

#include<bits/stdc++.h>
#define rep(i, n) for(int i = 1; i <= n; ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const ll INF = 1000000000;
ll S, rt;
bool check(ll A, ll B) {
    ll lf = A * B - S;
    if(lf == 0) {
        printf("0 0 %lld %lld %lld %lld\n", 0LL, B, A, 0LL);
        return true;
    }
    for(int i = 1; i * i <= lf; ++i) if(lf % i == 0) {
        ll a = i, b = lf / i;
        if(a <= A && b <= B) {
            printf("0 0 %lld %lld %lld %lld\n", a, B, A, b);
            assert(A*B-a*b == S);
            assert(A<=INF && B<=INF && a<=INF && b<=INF);
            return true;
        }
    }
    return false;
}
int main() {
    cin >> S;
    ll l = 0, r = 1000000000;
    while(l < r) {
        ll mid = (l + r) >> 1;
        if(mid * mid < S) l = mid + 1;
        else r = mid;
    }
    ll p1 = l, p2 = l;
    for(;;) {
        if(check(p1, p2)) return 0;
        if(p1 == p2) p2++;
        else p1++;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int index[n+1]={ };
    int arr[n+1]={ };
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
        index[arr[i]]=i;
    }
    int count=0,dead=n+1;
    
    for(int i=1;i<=n;i++)
    {  
         if(index[i]<dead){
            count++;
          dead=index[i];
        //cout<<dead<<" "<<count<<endl;
        }
    }
    cout<<count;

}

Measured memory_bytes: 1792
n, x = map(int, input().split())

a, p = [1], [1]

for i in range(n):
    a.append(a[i]*2 + 3)
    p.append(p[i]*2 + 1)

def f(n, x):
    if n == 0:
        return 0 if x <= 0 else 1
    elif x <= 1 + a[n-1]:
        return f(n-1, x-1)
    else:
        return p[n-1] + 1 + f(n-1, x-2-a[n-1])

print(f(n, x))

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

int main() {
  string s;
  cin >> s;
  
  for (int i=0; i<s.length()-1; i++) {
    for (int j=i+1; j<s.length(); j++) {
      if (s[i]==s[j]) {
        cout << "no" << endl;
        return 0;
      }
    }
  }
  
  cout << "yes" << endl;
  
  return 0;
}


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

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

#define deb(...) cerr << "[" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__)
void DBG() { cerr << "]\n";}
template<typename T, typename ...Args> void DBG(T first, Args... args)
{cerr << first; if(sizeof...(args))cerr<<", "; DBG(args...); }

void solve(){
  int a,b,c,k; cin >> a >> b >> c >> k;
  int ans=min(a,k);
  int picked=min(a,k);
  ans += min(k-ans,b*0);
  picked += min(k-picked,b);
  ans += min(k-picked,c)*(-1);
  cout << ans << "\n";
}


int32_t main(){
  ios_base:: sync_with_stdio(false);
  cin.tie(0);
  int t=1;
  for(int tt=1;tt<=t;tt++){
    solve();
  }
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<map>
#include<string>
#include<vector>
 
#define mx(ans, cnt) ans = max(ans, cnt)
#define fauto(a) for(auto i : a) cout << i << " "; cout << endl;
#define sp(n) fixed << setprecision(n)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define _ << " " <<
#define swp(x, y) if (x > y) swap(x, y);
#define swpg(x, y) if (x < y) swap(x, y);
#define ff first
#define ss second
#define xx first
#define yy second
#define pb push_back
#define nn end1
#define mp make_pair
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define mod 1000000007
 
 
using ll = long long;
using ull = unsigned long long;
using namespace std;
int main ()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    string s,l;
    cin>>n;
    l="ACL";
    for(ll i=0;i<n;i++)
    {
        s=s+l;
    }
    cout<<s<<endl;
  return 0;
}

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

int main(){
list<int>a;
for(int b=0;b<30;b++){
	a.push_back(b+1);
}
int d;
for(int c=0;c<28;c++){
	scanf("%d",&d);
	a.remove(d);
}
auto s=a.begin();
printf("%d\n",*s);
s++;
printf("%d\n",*s);
}

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

int main() {
  int N, K;
  int min;
  cin >> N >> K;
  min = 1;
  
  for ( int i=0; i< N; i++) {
    if ( min*2 <= min+K) {
      min= min*2;
    }
    else {
      min= min+K;
    }
  }
    cout << min << endl;
}

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

int main()
{
    int n,k, intOnBall, diffInt=0;

    int intCnt[200001] = {0};

    cin >> n >> k;


    for(int i=1; i<=n; i++)
    {
        cin >> intOnBall;

        if(intCnt[intOnBall] == 0) diffInt++;
        intCnt[intOnBall]++;
    }

    if(n==1 || diffInt <= k) cout << 0 << endl;
    else
    {
        sort(intCnt, intCnt+200000);

        int minNumOfRewrite=0;
        for(int i=1; i<=200000; i++)
        {
            if(intCnt[i] > 0)
            {
                minNumOfRewrite+=intCnt[i];
                diffInt--;

                if(diffInt==k) break;
            }
        }

        cout << minNumOfRewrite << endl;
    }



    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
#define FOR(i, x, n) for(ll i = x; i < n; i++) 
#define pb push_back
#define pf push_front
#define ll long long
#define hii cout << "hii" << endl
#define pii pair<int, int>
#define pll pair<ll, ll>
#define int ll
#define mpp make_pair
#define endl '\n'
#define ff first 
#define ss second
#define vi vector<int>
#define all(s) s.begin(), s.end()
#define si size()

const int N = 1e5 + 5;
int arr[N];

int solve()
{
	int n, k, q;
	cin >> n >> k >> q;
	map<int, int> mp;
	int t = q;
	while(t--)
	{
		int no;
		cin >> no;
		mp[no]++;
	}
	int no = 1;
	int m = n;
	while(m--)
	{
		if(q - mp[no++] < k)
		{
			cout << "Yes" << endl;
		}
		else
		{
			cout << "No" << endl;
		}
	}
}

int32_t main()
{
	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
	solve();
	return 0;
}          

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

using namespace std;

#define INF 1e9
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

string S[3];

void solve(){
    cout << S[0][0] << S[1][1] << S[2][2] << endl;
}

int main(){
    rep(i,3)
        cin >> S[i];

    solve();
}

Measured memory_bytes: 256
/*
				" اللهم صلي و سلم علي سيدنا محمد و علي اله وصحبه اجمعين "
*/

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define f for
#define ll long long
#define ull unsigned long long
#define endl "\n"
#define intial(s1,s2,x) f(int i = 0; i < s1; i++)f(int j = 0; j < s2; j++)dp[i][j] = x;
using namespace std;
#define BI  acos(-1)
#define all(a) a.begin(), a.end()
void Open()
{
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
#endif
}
ll gcd(ll a, ll b)
{
	return b == 0 ? a : gcd(b, a % b);
}
void madesetprobblem()
{
	//$ $
	//less than or equal => $ 1 \leq 100 $
	//  $(1 \le A,B \le 10^5 )$
	// a[i] => $a_i$
	// a[i][j] => $a_{i,j}$
	// double qoutes ''yext''
	/*
		image
		\begine{center}
		\includegraphics{image.jpg}
		\end{center}
	*/
	/*
		list
		\begin{itemize}
			\item first one
			\item second one
		\end{itemize}
	*/
}

//int dp[101][101];
vector<vector<ll>>a,b;
vector<pair<int,int>>p;
int n,m;
ll ans(int c,int v)
{
    if(~b[c][v])return b[c][v];
    b[c][v]=0;
    f(int i=0;i<a[a[c][v]].size();i++)
    {
    //cout<<a[c][v]<<" "<<a[a[c][v]].size()<<" "<<b[c][v]<<endl;
        b[c][v]=max(b[c][v],ans(a[c][v],i)+1);
    }
    return b[c][v];
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>m;
	a.resize(n+1);
	int x,y;
	p.resize(m);
	f(int i=0;i<m;i++)
	{
	    cin>>x>>y;
	    p[i]={x,y};
	    a[x].push_back(y);
	}
	b=a;
	f(int i=0;i<b.size();i++)
	{
	    f(int j=0;j<b[i].size();j++)
	    {
	        b[i][j]=-1;
	    }
	}
	ll v=0;
	f(int i=1;i<=n;i++)
	{
	    f(int j=0;j<a[i].size();j++)
	    {
	        v=max(ans(i,j),v);
	    //cout<<v<<endl;
	    }
	}
	cout<<v+1;
}


Measured memory_bytes: 14080
#include<iostream>
using namespace std;
int main(){
  int A,B,C,D,E,F;
  cin>>A>>B>>C>>D;
  if(A>B){
    E=B;
  }
  else{
    E=A;
  }
  if(C>D){
    F=D;
  }
  else{
    F=C;
  }
  cout<<E+F;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

var dp [5001]int
var dpr [5001][5001]int

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	k := getNextInt(scanner)
	aa := make([]int, n)

	dp[0] = 1
	dpr[n][0] = 1

	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	for i := n - 1; i > 0; i-- {
		for ii := k; ii >= 0; ii-- {
			dpr[i][ii] = dpr[i+1][ii]

			if ii-aa[i] < 0 {
				continue
			}
			if dpr[i+1][ii-aa[i]] > 0 {
				dpr[i][ii]++
			}
		}
	}

	for i := 1; i < n+1; i++ {
		for ii := 0; ii < k; ii++ {
			dpr[i][ii+1] += dpr[i][ii]
		}
	}

	ans := 0

	for i := 0; i < n; i++ {
		if needed(i, n, k, aa) == false {
			ans++
		}
	}

	fmt.Fprintln(writer, ans)
	writer.Flush()
}

func needed(ai, n, k int, aa []int) bool {
	if ai > 0 {
		for ii := k; ii >= 0; ii-- {
			if ii-aa[ai-1] < 0 {
				continue
			}
			if dp[ii-aa[ai-1]] > 0 {
				dp[ii]++
			}
		}
	}

	for i := 0; i < k; i++ {
		if dp[i] == 0 {
			continue
		}
		if i+aa[ai] >= k {
			return true
		}
		minr := k - aa[ai] - i - 1
		maxr := k - i - 1
		if minr < 0 {
			continue
		}
		if maxr < 0 {
			continue
		}
		if dpr[ai+1][maxr]-dpr[ai+1][minr] > 0 {
			return true
		}
	}
	return false
}


Measured memory_bytes: 196224
#include<iostream>
using namespace std;
int main ()
{
    string a,b;
    long long int l1,l2,flag=0,i;
    cin>>a;
    cin>>b;
    l1=a.size();
    l2=b.size();
    if(l1>l2)
        cout<<"GREATER"<<endl;
    else if(l1<l2)
        cout<<"LESS"<<endl;
    else if(l1==l2)
    {
        for(i=0; i<l1; i++)
        {
            if(a[i]>b[i])
            {
                cout<<"GREATER"<<endl;
                break;
            }
            else if(a[i]<b[i])
            {
                cout<<"LESS"<<endl;
                break;
            }
            else if(a[i]==b[i])
            {
                if(a[l1-1]==b[l2-1])
                {
                    flag=1;
                    break;
                }
                else
                    continue;
            }

        }
        if(flag==1)
            cout<<"EQUAL"<<endl;



    }


}


Measured memory_bytes: 256
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("no-stack-protector")
//#pragma GCC target("popcnt")
//#pragma GCC target("sse4")
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define rng(a) a.begin(),a.end()
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define sz(a) (int)(a.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef long double ld;













const int heh = 360;

signed main(){
    int x;
    cin >> x;
    int f = __gcd(x, heh);
    cout << heh / f;




}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;

const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
int main(){
    int n;cin>>n;
    int a[n];
    rep(i,n)cin>>a[i];
    int b[n],f[n];
    f[0]=a[0];
    rep(i,n){
        if(i==0)continue;
        f[i]=__gcd(f[i-1],a[i]);
    }
    b[n-1]=a[n-1];
    for(int i=n-1;i>=0;i--){
        if(i==n-1)continue;
        b[i]=__gcd(b[i+1],a[i]);
    }
    int ans = 0;
    rep(i,n){
        if(i==0)ans = max(ans,b[1]);
        else if(i==n-1)ans=max(ans,f[n-2]);
        else ans =max(ans,__gcd(f[i-1],b[i+1]));
    }
    cout<<ans<<endl;
    }

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define NIL -1
#define MAX 25

struct Node {
    int parent, left, right;
};

int n;
vector<Node> T(MAX);

int root() {
    int root;
    for (int i = 0; i < n; i++) {
        if (T.at(i).parent == NIL) {
            root = i;
        }
    }

    return root;
}

void preParse(int u) {
    if (u == NIL) {
        return;
    }

    printf(" %d", u);
    preParse(T.at(u).left);
    preParse(T.at(u).right);
}

void inParse(int u) {
    if (u == NIL) {
        return;
    }

    inParse(T.at(u).left);
    printf(" %d", u);
    inParse(T.at(u).right);
}

void postParse(int u) {
    if (u == NIL) {
        return;
    }

    postParse(T.at(u).left);
    postParse(T.at(u).right);
    printf(" %d", u);
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        T.at(i).parent = NIL;
    }
    for (int i = 0; i < n; i++) {
        int u, l, r;
        cin >> u >> l >> r;
        T.at(u).left = l;
        T.at(u).right = r;
        if (l != NIL) {
            T.at(l).parent = u;
        }
        if (r != NIL) {
            T.at(r).parent = u;
        }
    }

    cout << "Preorder" << endl;
    preParse(root());
    cout << endl;
    
    cout << "Inorder" << endl;
    inParse(root());
    cout << endl;

    cout << "Postorder" << endl;
    postParse(root());
    cout << endl;
}


Measured memory_bytes: 3232
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;

void solve(){
  long long n, a, b, c; cin >> n >> a >> b >> c;
  vector<char> ans;
  vector<string> s(n);
  for(int i = 0; i < n; i++) cin >> s[i];

  for(int i = 0; i < n; i++){
    if(s[i] == "AB"){
      if(a >= b){
        if(a == 1 && b == 1 && c == 0 && i < n - 1 && s[i + 1] == "AC"){
          a++;
          b--;
          ans.push_back('A');
        }
        else{
          a--;
          b++;
          ans.push_back('B');
        }
      }
      else{
        a++;
        b--;
        ans.push_back('A');
      }
    }
    else if(s[i] == "AC"){
      if(a >= c){
        if(a == 1 && c == 1 && b == 0 && i < n - 1 && s[i + 1] == "AB"){
          a++;
          c--;
          ans.push_back('A');
        }
        else{
          a--;
          c++;
          ans.push_back('C');
        }
      }
      else{
        a++;
        c--;
        ans.push_back('A');
      }
    }
    else{
      if(b >= c){
        if(b == 1 && c == 1 && a == 0 && i < n - 1 && s[i + 1] == "AB"){
          b++;
          c--;
          ans.push_back('B');
        }
        else{
          b--;
          c++;
          ans.push_back('C');
        }
      }
      else{
        b++;
        c--;
        ans.push_back('B');
      }
    }
    if(a < 0 || b < 0 || c < 0){
      cout << "No" << endl;
      return;
    }
  }
  cout << "Yes" << endl;
  for(int i = 0; i < n; i++){
    cout << ans[i] << endl;
  }
  return;
}

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


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

readLines().then(lines => {
    const s = new Date(lines[0]);
    const d = new Date("2019/4/30");
    if (s <= d) {
        console.log("Heisei");
    } else {
        console.log("TBD");
    }
});

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

int main(){
	int n,m,sum=0;
	cin>>n;
	vector<int> arr(n);
	for(int i=0;i<n;i++) cin>>arr[i];
	for(int i=0;i<n;i++) sum+=arr[i];

	cin>>m;

	while(m--){
		int x,y;
		cin>>x>>y;

		if(arr[x-1]>y) cout<<sum-(arr[x-1]-y)<<"\n";
		else cout<<sum+(y-arr[x-1])<<"\n";
	}
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
cnt=0
cnt1=0
ans=1
aa=a[0]
for i in range(n):
    #print(ans)
    if aa>a[i] and cnt1==0:
        cnt=1
        aa=a[i]
    elif aa<a[i] and cnt==0:
        cnt1=1
        aa=a[i]
    elif aa>a[i] and cnt1!=0:
        aa=a[i]
        ans+=1
        cnt1=0
    elif aa<a[i] and cnt!=0:
        aa=a[i]
        ans+=1
        cnt=0
    else:
        continue
print(ans)


Measured memory_bytes: 14436
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#ifdef LOCAL
#define debug(...) \
  std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}
using namespace std;
using int64 = long long;

int main() {
  int N;
  string s;
  cin >> N >> s;
  char c;
  string res = s;
  int num_of_umprocessed_opening = 0;
  for (int i = 0; i < N; i++) {
    c = s[i];
    if (c == '(') {
      num_of_umprocessed_opening++;
    } else {
      if (!num_of_umprocessed_opening) {
        res.insert(0, "(");
      } else {
        num_of_umprocessed_opening--;
      }
    }
  }
  for (int i = 0; i < num_of_umprocessed_opening; i++) {
    res.push_back(')');
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(X: int, A: int):
    if X < A:
        print(0)
    else:
        print(10)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    solve(X, A)


if __name__ == '__main__':
    main()


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

 
int main(){
    int n, count = 0;
    bool flag=false;
    cin >> n;
    int d[n][2];
    for(int i=0; i<n; i++) {
        cin >> d[i][0] >> d[i][1];
        if(d[i][0] == d[i][1]) {
            count++;
            if(count>=3){
                flag = true;
            }
        } else {
            count = 0;
        }
    }

    // for(int i=1; i<n-1; i += 2) {
    //     if(d[i][0] == d[i][1]) {
    //         if(d[i+1][0] == d[i+1][1]){
    //             if(d[i-1][0] == d[i-1][1]){
    //                 flag = true;
    //                 break;
    //             } else {
    //                 i--;
    //             }
    //         }
    //     }
    // }

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

    return 0;
}

Measured memory_bytes: 3644
from bisect import bisect_left

def readinput():
    n=int(input())
    s=list(map(int,input().split()))
    q=int(input())
    t=list(map(int,input().split()))
    return n,s,q,t

def bisect_search(s,i):
    left=0
    right=len(s)
    while(left<right):
        middle=(left+right)//2
        #print(left,right)
        if(i==s[middle]):
            return True
        elif(s[middle]<i):
            left=middle+1
        else:
            right=middle
    return False

def main(n,s,q,t):
    c=0
    for i in t:
        res=bisect_search(s,i)
        if(res==True):
            c+=1
        
    return c

def find(a,x):
    i = bisect_left(a,x)
    if i != len(a) and a[i]==x:
        return True
    else:
        return False
     

def main2(n,s,q,t):
    c=0
    for i in t:
        if(find(s,i)==True):
            c+=1
    return c

if __name__=='__main__':
    n,s,q,t=readinput()
    ans=main2(n,s,q,t)
    print(ans)



Measured memory_bytes: 16756
class dice():
    
    #      m[5]
    # m[4] m[1] m[3] m[6]
    #      m[2]

    #      m[5]
    # m[4] m[1] m[3]
    #      m[2]
    #      m[6]
    
    def __init__(self, nums):
        self.pos = [0]
        self.pos.extend(nums)
    
    def rot_E(self):
        m = self.pos
                  #       m[1], m[2], m[3], m[4], m[5], m[6]
        self.pos = [m[0], m[4], m[2], m[1], m[6], m[5], m[3]]

    def rot_W(self):
        m = self.pos
                  #       m[1], m[2], m[3], m[4], m[5], m[6]
        self.pos = [m[0], m[3], m[2], m[6], m[1], m[5], m[4]]

    def rot_S(self):
        m = self.pos
                  #       m[1], m[2], m[3], m[4], m[5], m[6]
        self.pos = [m[0], m[5], m[1], m[3], m[4], m[6], m[2]]

    def rot_N(self):
        m = self.pos
                  #       m[1], m[2], m[3], m[4], m[5], m[6]
        self.pos = [m[0], m[2], m[6], m[3], m[4], m[1], m[5]]
        
    def top(self):
        print(self.pos[1])

nums = [int(x) for x in input().split()]
d = dice(nums)
seq = [x for x in list(input())]

for op in seq:
    if op == 'S':
        d.rot_S()
    elif op == 'E':
        d.rot_E()
    elif op == 'N':
        d.rot_N()
    elif op == 'W':
        d.rot_W()

d.top()


Measured memory_bytes: 5616
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;

typedef pair<int, int> P;

int N;
int x[200005], y[200005];
P p[200005], q[200005];

int d(int i, int j) {
  // printf("i = %d, j = %d\n", i, j);
  return abs(x[i] - x[j]) + abs(y[i] - y[j]);
}

void solve() {
  int mx = -1;
  for (int i = 0; i < N; i++) { if (mx < x[i]) mx = x[i]; }

  for (int i = 0; i < N; i++) {
    p[i] = make_pair(x[i] + y[i], i);
    q[i] = make_pair((mx-x[i]) + y[i], i);
  }

  sort(p, p+N);
  sort(q, q+N);

  int ans = -1;
  for (int i = 0; i <= N/20; i++) {
    for (int j = 0; j <= N/20; j++) {
      // printf("check for p[%d] and p[%d]: ", i, N-1-j);
      int t = d(p[i].second, p[N-1-j].second);
      if (ans < t) ans = t;

      int s = d(q[i].second, q[N-1-j].second);
      if (ans < s) ans = s;
    }
  }
  printf("%d\n", ans);
}

void solve2() {
  int ans = -1;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      int t = d(i, j);
      if (ans < t) ans = t;
    }
  }
  printf("%d\n", ans);
}

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d%d", x+i, y+i);
  }
  // solve2();
  solve();
}

Measured memory_bytes: 6416
#include <stdio.h>

#define Max 1000

void insertionSort(int A[Max], int N) {
	int i, j, v;

	for (i = 0; i < N; i++) { 
		v = A[i];
		j = i - 1;
		while (j >= 0 && A[j] > v) {
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;
		for (j = 0; j < N - 1; j++)
			printf("%d ", A[j]);
		printf("%d\n", A[N - 1]);
	}
}

int main( ) {
	int N, i, j;
	int num[Max];

	scanf("%d", &N);

	for (i = 0; i < N; i++) scanf("%d", &num[i]);

	insertionSort(num, N);

	return 0;
}

Measured memory_bytes: 604
import java.util.*;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = 0;
    for (int i=0; i<3; i++) {
      a += sc.nextInt();
    }
    
    if (a>21) {
      System.out.println("bust");
    }
    else {
      System.out.println("win");
    }
  }
}


Measured memory_bytes: 22608
#include <bits/stdc++.h>
using namespace std;
int n;
string s[105];
map <string, int> mp;

int main() {
	bool flg = 1;
	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> s[i];
		mp[s[i]]++;
	}
	for(int i = 1; i <= n; i++) {
		if(mp[s[i]] > 1) flg = 0;
	}
	for(int i = 2; i <= n; i++) {
		int l = s[i - 1].length();
		if(s[i][0] != s[i - 1][l - 1]) {
			flg = 0; break;
		}
	}
	if(flg) puts("Yes");
	else puts("No");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N,M,gokei=0;
    cin >> N >> M;
    vector<int>A(M);
    for(int i=0;i<M;i++){
        cin >> A.at(i);
        gokei+=A.at(i);
    }
    if(N-gokei<0){
        cout << -1;
    } else {
        cout << N-gokei;
    }
}


Measured memory_bytes: 3668