akhauriyash/Code-Regression huggingface dataset:
N = gets.chomp.to_i
a = []
for i in 1..N do
  str = gets.chomp
  a.push str
end
b = []
M = gets.chomp.to_i

for i in 1..M do
  str = gets.chomp
  b.push str
end

best = 0

for str in a do
  price = a.count(str) - b.count(str)
  best = price if price > best
end

puts best


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

#define REP(i, a, b) for (auto i = (a); i < (b); i++)
#define REPR(i, a, b) for (auto i = (a-1); i >= (b); i--)

using namespace std;

int create(int n, map<int, int> m)
{
    if (m.size() < 3)
        return 0;

    int result = 0;
    map<int, int>::iterator last = m.end();
    
    for (auto i = m.begin(); i != prev(last, 2); ++i)
        for (auto j = next(i, 1); j != prev(last, 1); ++j)
            for (auto k = next(j, 1); k != m.end(); ++k)
                if (i->first + j->first > k->first)
                    result += i->second * j->second * k->second;
    
    return result;
}

void solve()
{
    int n; cin >> n;
    map<int, int> m;

    REP(i, 0, n)
    {
        int l; cin >> l;
        m[l]++;
    }

    cout << create(n, m) << "\n";
}

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

    int t = 1; // cin >> t;

    while (t--)
        solve();

    return 0;
}

Measured memory_bytes: 3628
n = int(input())

a, b = [], []
for _ in range(n):
    ta, tb = map(int, input().split())
    a.append(ta)
    b.append(tb)

ans = 0
i = n - 1
while i >= 0:
    a[i] += ans
    r = a[i] % b[i]
    if r != 0:
        ans += b[i] - r
    i -= 1

print(ans)

Measured memory_bytes: 15016
import numpy as np

def solve():
    dp = np.zeros((2, N+1))
#    print(dp)
    ac = 0
    wa = 0
    for i in range(M): 
        if (dp[0][S[i][0]] == 0):
            if(S[i][1] == "WA"):
                dp[1][S[i][0]] += 1
            elif(S[i][1] == "AC"):
                ac += 1
                dp[0][S[i][0]] = 1
                wa += dp[1][S[i][0]]
    print(ac, int(wa))

if __name__=="__main__":

    N, M = list(map(int, input().split()))
    S = []
    for i in range(M):
        a,b = input().split()
        S.append([int(a), b])
#    print(S)
    solve()
    




Measured memory_bytes: 46364
#include<iostream>
#include <math.h>
#include<cstring>

using namespace std;
int main()
{
	int n, a, b;
	cin >> n >> a >> b;
	if (n*a < b) cout << n*a << endl;
	if (n*a > b) cout << b << endl;
	if (n*a == b) cout << b << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<utility>
#include<map>
typedef long long ll;
typedef unsigned long long ull;
typedef std::vector<long long > vi ;
#define F first
#define S second
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define PB push_back
#define MP make_pair
ll pow1(ll n,ll p)
{
	if(p==0)	return 1;
	ll x=pow1(n, p/2);
	x=(x*x)%mod;
	if(p%2==0)
		return x;
	else
		return (x*n)%mod;
}

using  namespace std;

int main()
{
        ll n,i,j;
        std::cin >> n;
        ll a[n],b[n],sum=0;
        for(i=0;i<n;i++)
        {
            std::cin >> a[i];
        }
        b[n-1]=0;
        b[n-2]=llabs(a[n-1]-a[n-2]);
        for(i=n-3;i>=0;i--)
        {
            b[i]=min(llabs(a[i+1]-a[i])+b[i+1],llabs(a[i+2]-a[i])+b[i+2]);
        }
        std::cout << b[0] << std::endl;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {
  public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int a = sc.nextInt();
    	if(a % 2 == 0) {
          System.out.println(a / 2);
        } else {
          System.out.println(a / 2 + 1);
        }
  }
}

Measured memory_bytes: 21844
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();

		int[] H = new int[N];
		int i = 0;
		while(i < N) {
			H[i] = sc.nextInt();
			i++;
		}

		Arrays.sort(H);
		Long sum = (long) 0;

		for(i = 0;i < N-K; i++) {
			sum += H[i];
		}


		System.out.println(sum);
	}

}


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

int main(){
  int N,N3,N5,N15;
  cin>>N;
  N3=N/3;
  N5=N/5;
  N15=N/15;
  long long Ans=0;
  long long Ans3=0;
  long long Ans5=0;
  long long Ans15=0;
  for(int i=1; i<=N;i++ ){
    Ans=Ans+i;
  }
  for(int i=1; i<=N3;i++ ){
    Ans3=Ans3+3*i;
  }
  for(int i=1; i<=N5;i++ ){
    Ans5=Ans5+5*i;
  }
  for(int i=1; i<=N15;i++ ){
    Ans15=Ans15+15*i;
  }
  cout<<Ans-Ans3-Ans5+Ans15<<endl;
}


Measured memory_bytes: 3620
//#pragma comment(linker,"/STACK:102400000,102400000")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
#define _for(i, a, b) for (int i = (a); i < (b); ++i)
#define _rep(i, a, b) for (int i = (a); i <= b; ++i)
const int max_number = 1000000;

// int main() //Print a Chessboard
// {
//     int h, w;
//     while (true) {

//         scanf("%d%d", &h, &w);

//         if (h == 0 && w == 0)
//             return 0;
//         for (int i = 1; i <= h; i++) {
//             for (int j = 1; j <= w; j++) 
//             {
//                 if ((i + j) % 2 == 0) 
//                 {
//                     printf("#");
//                 } else {
//                     printf(".");
//                 }
//             }
//             printf("\n");
//         }

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

int main()
{
    int n;
    scanf("%d",&n);
    vector<int> res(n);
    for (int i=0; i<n; i++)
    {
        scanf("%d", &res[i]);
    }

    for (auto it = res.rbegin(); it != res.rend();it++)
    {
        if(it==res.rend()-1)
            cout << *it;

            else{
        cout << *it << " ";}
    }
    printf("\n");

        return 0;
}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1e9,MOD=998244353;

int main(){
	int x1,x2,y1,y2; cin>>x1>>y1>>x2>>y2;
	int x3,x4,y3,y4;
	int dx=x2-x1,dy=y2-y1;
	x3=x2-dy;
	y3=y2+dx;
	x4=x1-dy;
	y4=y1+dx;
	printf("%d %d %d %d\n",x3,y3,x4,y4);
	return 0;
}


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

#define REP(i,a,b) for(int i=int(a);i<int(b);i++)

using namespace std;

typedef long long int lli;

int main () {
    int N;
    cin >> N;
    vector<lli> v(N);
    REP (i, 0, N) cin >> v[i];
    vector<lli> sum(N, 0);
    sum[0] = v[0];
    REP (i, 1, N) sum[i] += sum[i - 1] + v[i];
    lli ans = 1LL << 60;
    REP (_, 0, 2) {
        int start = _;
        lli carry = 0;
        lli cnt = 0;
        REP (i, 0, N) {
            if (start && (sum[i] + carry <= 0)) {
                cnt += (1 - sum[i] - carry);
                carry += (1 - sum[i] - carry);
            } else if (!start && (sum[i] + carry >= 0)) {
                cnt += (sum[i] + carry + 1);
                carry -= (sum[i] + carry + 1);
            }
            start = 1 - start;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
S = input()

ans = "YES"
while len(S) > 0:
    if S[-5:] == "dream":
        S = S[:-5]
    elif S[-5:] == "erase":
        S = S[:-5]
    elif S[-7:] == "dreamer":
        S = S[:-7]
    elif S[-6:] == "eraser":
        S = S[:-6]
    else:
        ans = "NO"
        break

print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define INF 2e9
#define INFLL 4e18
using namespace std;
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 1e6+1;
const int mod = 998244353;
int main() {
//	freopen(".in","r",stdin);freopen(".out","w",stdout);
	int a,b;
	sd(a);sd(b);
	pd(a*b);
	return 0;
}

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

using namespace std;

using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll h, w;
  cin >> h >> w;
  if (h == 1 || w == 1) {
    cout << 1 << '\n';
    return 0;
  }
  cout << (h * w + 1) / 2 << '\n';
  return 0;
}


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

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main() {
    int N, Q; cin >> N >> Q;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];

    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}


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

using namespace std;

typedef long long ll;
 
const int MOD = 1e9 + 7;
 
ll p[1100][1100],n,m,sol,dp[1100][1100];

char s[1100];

int main() {
	
	scanf("%lld %lld", &n, &m);
	
	for(int i = 1; i <= n; i++) {
		scanf("%s", s);
		
		for(int j = 0; j < m; j++) {
			if(s[j] == '.') p[i][j + 1] = 1;
			else p[i][j + 1] = 0;
		}
	}
	
	dp[1][1] = 1;
	
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			if(i == 1&&j == 1) continue;
			
			if(p[i][j] == 0) continue;
			
			dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
			dp[i][j] += MOD;
			dp[i][j] %= MOD;
		}
	}
	
	/*for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			printf("%lld ",p[i][j]);
		}
		printf("\n");
	}*/
	
	printf("%lld",dp[n][m]);
	
	return 0;
}

Measured memory_bytes: 18688
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};
const long long INF = 1LL << 60;

template<class T> inline bool chmin(T& a, T b){if(a > b){ a = b;return true;} return false;}
template<class T> inline bool chmax(T& a, T b){if(a < b){ a = b;return true;} return false;}

int main(){
    int n; cin >> n;
    ll a[100005][3];
    rep(i,n) rep(j,3) cin >> a[i][j];

    ll dp[100005][3];
    rep(i,100005) rep(j,3) dp[i][j] = 0;

    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(j != k){
                    chmax(dp[i+1][j],dp[i][k] + a[i][j]);
                }
            }
        }
    } 
    ll ans = 0;  
    rep(i,3){
        ans = max(ans,dp[n][i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int a,b,c;
    cin>>a>>b>>c;
    if (c>=a && c<=b)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int i, j, n, x, card[4][13];  /* ?????????S,H,C,D ????????? */
  char mark;

  /* ????????? */
  for(i = 0; i < 4; i++){
    for(j = 0; j < 13; j++){
      card[i][j] = 0;
    }
  }

  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%*c%c %d", &mark, &x);
    switch(mark){
    case 'S':
      card[0][x-1] = 1;
      break;
    case 'H':
      card[1][x-1] = 1;
      break;
    case 'C':
      card[2][x-1] = 1;
      break;
    case 'D':
      card[3][x-1] = 1;
      break;
    }
  }

  for(i = 0; i < 4; i++){
    for(j = 0; j < 13; j++){
      if(card[i][j] == 0){
	switch(i){
	case 0:
	  printf("S %d\n", j+1);
	  break;
	case 1:
	  printf("H %d\n", j+1);
	  break;
	case 2:
	  printf("C %d\n", j+1);
	  break;
	case 3:
	  printf("D %d\n", j+1);
	  break;
	}
      }
    }
  }
  return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t r;
    cin >> r;
    if(r<1200){
        cout << "ABC" << endl;
    }else if(r<2800){
        cout << "ARC" << endl;
    }else{
        cout << "AGC" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N;
bool bw[100010], used[100010];
struct edge{
    int to, cost;
};

vector<edge> G[100010];
void dfs(int n){
    used[n] = true;
    for(auto u : G[n]){
        if(used[u.to]) continue;
        if(u.cost % 2 == 0) bw[u.to] = bw[n];
        else bw[u.to] = !bw[n];
        dfs(u.to);
    }
}

int main(){
    cin >> N;
    for(int i = 1; i < N; i++){
        int u, v, w;
        cin >> u >> v >> w;
        G[u].push_back(edge{v,w});
        G[v].push_back(edge{u,w});
    }
    dfs(1);
    for(int i = 1; i <= N; i++){
        cout << bw[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 7424
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	int p[101];
	int pmax=0;
	int psum=0;
	scan(N);
	rep(i,N){
		scan(p[i]);
		pmax=max(p[i],pmax);
		psum+=p[i];
	}
	prin(psum-pmax/2);
	return 0;
}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;


long long int n,cnt=0,ans=0,a,b,c,d,cmp[101][101],cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

      
      cin>>w>>h>>n;
      rep(i,n){
        cin>>x>>y>>a;
        if(a==1){
          rep(j,h){
            rrep(k,0,x){
              cmp[j][k]=1;
            }
          }
        }
        
        else if(a==2){
          rep(j,h){
            rrep(k,x,w){
              cmp[j][k]=1;
            }
          }
        }

        else if(a==3){
          rrep(j,0,y){
            rep(k,w){
              cmp[j][k]=1;
            }
          }
        }

        else{
          rrep(j,y,h){
            rep(k,w){
              cmp[j][k]=1;
            }
          }
        }
      }

     ll xmin=INF,xmax=0,ymin=INF,ymax=0;
     fl=false;

     rep(i,h){
       rep(j,w){
         if(cmp[i][j]==0){
           fl=true;
           xmin=min(xmin,j);
           xmax=max(xmax,j);
           ymin=min(ymin,i);
           ymax=max(ymax,i);
         }
       }
     }
     if(!fl){
       Cout(0);
       return 0;
     }

     //cout<<xmax<<" "<<xmin<<" "<<ymax<<" "<<ymin<<"\n";
     Cout((xmax-xmin+1)*(ymax-ymin+1));
     

       
return 0;
}


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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
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; }
typedef long long ll;

const long long INF = 1LL << 60;
const long long INF1 = 1LL << 9;

int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

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

    vector<int> A(N), L(N), R(N);
    rep(i, N) {
        cin >> A[i];
        L[i] = R[i] = A[i];
    }

    repd(i, 1, N) {
        L[i] = gcd(L[i-1], L[i]);
    }

    for (int i = N - 2; i >= 0; i--) {
        R[i] = gcd(R[i+1], R[i]);
    }

    int ans = 0;
    rep(i, N) {
        if (i == 0) {
            ans = max(ans, R[i + 1]);
        }
        else if (i == N - 1) {
            ans = max(ans, L[i - 1]);
        }
        else {
            ans = max(ans, gcd(L[i - 1], R[i + 1]));
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1408
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

if A < B and (A + V*T >= B + W*T):
    print('YES')
elif B < A and (A - V*T <= B - W*T):
    print('YES')
else:
    print('NO')


Measured memory_bytes: 9132
def main():
    n, m = map(int, input().split())
    left = 1
    right = n
    is_shift = False
    ans = []
    while left < right:
        if right - left <= n // 2 and not is_shift and n % 2 == 0:
            left += 1
            is_shift = True
        ans.append([left, right])
        left += 1
        right -= 1

    for l in range(m):
        print(*ans[l])


if __name__ == "__main__":
    main()


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

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

	for(int i = 0; i < N; i++) {
		int in[16][16] = {0};
		int react[3][3] = {{0,1,0},{1,1,1},{0,1,0}};

		/* input */
		for(int j = 0; j < 10; j++) {
			for(int k = 0; k < 10; k++) {
				cin >> in[j + 1][k + 1];
			}
		}

		/* search */
		for(int j = 0; j < 1U << 10; j++) {
			int ans[16][16] = {0};
			int table[16][16] = {0};
			memcpy(table, in, sizeof(in));
			for(int k = 0; k < 10; k++) {
				if(j & (1U << k)) {
					for(int l = 0; l < 3; l++) {
						for(int m = 0; m < 3; m++) {
							table[l][k + m] ^= react[l][m];
						}
					}
					ans[0][k] = 1;
				}
				else
					ans[0][k] = 0;
			}
			for(int k = 1; k < 10; k++) {
				for(int l = 0; l < 10; l++) {
					if(table[k - 1 + 1][l + 1] == 1) {
						for(int m = 0; m < 3; m++)
							for(int n = 0; n < 3; n++)
								table[k + m][l + n] ^= react[m][n];
						ans[k][l] = 1;
					}
					else
						ans[k][l] = 0;
				}
			}
			bool flag = true;
			for(int k = 0; k < 10; k++)
				if(table[10][k + 1]) {
					flag = false;
				}
			if(flag) {
				for(int k = 0; k < 10; k++) {
					for(int l = 0; l < 10; l++) {
						if(l)
							cout << " ";
						cout << ans[k][l];
					}
					cout << endl;
				}
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

vector<vector<int>> to(100005);
vector<int> ok(100005, -1);

void dfs(int v)
{
    ok.at(v) = 1;
    for(int u:to.at(v)){
        if(ok.at(u)!=-1) continue;
        dfs(u);
    }
}

int main() {
    int n, m; cin >> n >> m;
    vector<int> x(m+1), y(m+1), z(m+1);
    rep(i,m) cin >> x.at(i) >> y.at(i) >> z.at(i);


    for(int i=0; i<m; i++){
        to.at(x.at(i)).push_back(y.at(i));
        to.at(y.at(i)).push_back(x.at(i));
    }

    ll cnt = 0;
    #if 1
    for(int i=1; i<=n; i++){
        if(ok.at(i)!=-1){
            continue;
        }
        else{
            cnt++;
            if(to.at(i).size()==0) continue;
            dfs(i);
        }
    }
    #endif

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


Measured memory_bytes: 10368
#include<iostream>
using namespace std;
int n, arr[4];
int main()
{
	cin>>n;
	string str;
	for(int x = 0; x < n; x++){
		cin>>str;
		if(str == "AC") arr[0]++;
		else if(str == "WA") arr[1]++;
		else if(str == "TLE") arr[2]++;
		else if(str == "RE") arr[3]++;

	}

	cout<<"AC x "<<arr[0]<<endl;
	cout<<"WA x "<<arr[1]<<endl;
	cout<<"TLE x "<<arr[2]<<endl;
	cout<<"RE x "<<arr[3]<<endl;

	return 0;
}


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

typedef long long LL;

int main(){
    LL N, K, sum;
    cin >> N >> K;
    if (K == 0) sum = N*N;
    else{
        sum = 0;
        for (int b=1; b<=N; b++){
            int p = int((N+1) / b);
            int r = N + 1 - p*b;
            sum += p * max(0LL, b-K) + max(0LL, r-K);
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#ABC070.B
A,B,C,D = map(int,input().split())
L1 = [A,C]
L2 = [B,D]
L1.sort()
L2.sort()
x = L2[0]-L1[1]
if x <0:
    print(0)
elif x >=0:
    print(x)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<28)-1
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n;
    vector<int> t(n), x(n), y(n);
    rep(i, 0, n) { 
        cin >> t[i] >> x[i] >> y[i];
    }
    if (n == 1) {
        if (t[0] - (x[0] + y[0]) >= 0 && (t[0] - (x[0] + y[0])) % 2 == 0) 
            cout << "Yes" << endl;
        else 
            cout << "No" << endl;
        return 0;
    }
    rep(i, 1, n) {
        int dist = abs(x[i-1]-x[i]) + abs(y[i-1]-y[i]);
        if (t[i]-t[i-1]-dist < 0 || (t[i]-t[i-1]-dist) % 2) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


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

using namespace std;
const int N = 100010;
int _w;

int n, m, eu[N], ev[N], flip[N], deg[N];

namespace G {
	int head[N], nxt[N*2], to[N*2], id[N*2], eid;
	void init() {
		eid = 0;
		memset(head, -1, sizeof head);
	}
	void link( int u, int v, int w ) {
		to[eid] = v, id[eid] = w, nxt[eid] = head[u], head[u] = eid++;
		to[eid] = u, id[eid] = w, nxt[eid] = head[v], head[v] = eid++;
	}
}

namespace DSU {
	int pa[N];
	void init() {
		for( int i = 0; i < N; ++i )
			pa[i] = i;
	}
	int find( int u ) {
		return u == pa[u] ? u : pa[u] = find( pa[u] );
	}
	bool link( int u, int v ) {
		u = find(u), v = find(v);
		if( u == v ) return false;
		return pa[u] = v, true;
	}
}

void dfs( int u, int fa, int w ) {
	using namespace G;
	for( int i = head[u]; ~i; i = nxt[i] ) {
		int v = to[i];
		if( v == fa ) continue;
		dfs(v, u, id[i]);
	}
	if( deg[u] % 2 == 1 ) {
		flip[w] ^= 1;
		++deg[u], ++deg[fa];
	}
}

int main() {
	_w = scanf( "%d%d", &n, &m );
	for( int i = 1; i <= m; ++i ) {
		_w = scanf( "%d%d", eu+i, ev+i );
		flip[i] = 0;
		++deg[eu[i]];
	}
	G::init();
	DSU::init();
	for( int i = 1; i <= m; ++i ) {
		int u = eu[i], v = ev[i];
		if( DSU::link(u, v) ) {
			G::link(u, v, i);
		}
	}
	int cnt_odd = 0;
	for( int i = 1; i <= n; ++i )
		if( deg[i] % 2 == 1 )
			++cnt_odd;
	if( cnt_odd % 2 == 1 ) {
		puts("-1");
		return 0;
	}
	dfs(1, 0, 0);
	for( int i = 1; i <= m; ++i ) {
		if( flip[i] ) swap( eu[i], ev[i] );
		printf( "%d %d\n", eu[i], ev[i] );
	}
	return 0;
}


Measured memory_bytes: 15036
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(),b = sc.nextInt(),c = sc.nextInt();
		if(a+b==c || a+c==b || b+c == a) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}


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

bool isprime(int n){
    double rootn = sqrt(n);
    if (n < 2){
        return false;
    }
    else if (n == 2){
        return true;
    }
    else if (n % 2 == 0){
        return false;
    }
    else{
        for(int i = 3; i <= rootn; i += 2){
            if(n % i == 0){
                return false;
            }
        }
        return true;
    }
}

int popcount(int n){
    int ans = 0;
    while(n != 0){
        if(n % 2 == 1){
            ans++;
        }
        n /= 2;
    }
    return ans;
}

int mod_pow(int n, int e, int mod){
    int ans = 1;
    while(e != 0){
        if(e % 2 == 1){
            ans = (ans * n) % mod;
        }
        e /= 2;
        n = (n*n) % mod;
    }
    return ans % mod;
}

signed main(){
    int N;
    cin >> N;
    string s;
    cin >> s;
    vector<int> X(N);
    int pc = 0;
    for(int i=0; i<N; i++){
        X[i] = s[i] - '0';
        if(X[i] == 1){
            pc++;
        }
    }

    // rem[0] が 1 引いた後
    int rem[2] = {0, 0};
    for(int j=0; j<N; j++){
        if(pc > 1){
            rem[0] = (rem[0]*2 + X[j]) % (pc-1);
        }
        rem[1] = (rem[1]*2 + X[j]) % (pc+1);
    }

    for(int i=0; i<N; i++){
        X[i] = 1 - X[i];
        pc = pc + 2*X[i]-1;

        if(pc == 0){
            cout << 0 << endl;
            pc = pc - 2*X[i]+1;
            X[i] = 1 - X[i];
            continue;
        }

        int r = rem[X[i]], c = 1;
        // r + (2*X[i] - 1) * 2**(N-1-i)
        int fugou = 1;
        if(X[i] == 0){
            fugou = pc-1;
        }
        r = (r + fugou * mod_pow(2, N-1-i, pc)) % pc;
        while(r != 0){
            c++;
            r = r % popcount(r);
        }
        cout << c << endl;
        
        pc = pc - 2*X[i]+1;
        X[i] = 1 - X[i];
    }
    return 0;
}

Measured memory_bytes: 5300
N = int(input())
x_u = [input().split() for _ in range(N)]
otoshidama = []

for i in range(N):
    if x_u[i][1] == "JPY":
        otoshidama.append(eval(x_u[i][0]))
    else:
        otoshidama.append(eval(x_u[i][0])*380000.0)
        
print(sum(otoshidama))

Measured memory_bytes: 3060
#include <stdio.h> 
int main() {
    long long int A,B,C,D,N,M;
    char ss;
    scanf("%c", &ss);
  if ('a' <= ss && ss <= 'z') {
    printf("a\n", ss);
  } else {
    ss += 1;
    printf("A\n", ss);
  }
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

#define X first
#define Y second

const int MAXN = 100010;

int n;
vector<int> v[MAXN];
int F[MAXN];

void dfs(int x, int p)
{
	F[x] = 0;
	for (auto y : v[x])
	{
		if (y == p) continue;
		dfs(y, x);
		F[x] ^= (F[y]+1);
	}
}

int main()
{
	
	scanf("%d", &n);
	for (int i = 1; i < n; ++ i)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		v[x].push_back(y);
		v[y].push_back(x);
	}
	dfs(1, 0);
	puts(F[1] ? "Alice" : "Bob");
	
	return 0;
}
 


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

typedef long long ll;

const int N = 101;
int n;
int x[N];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> x[i];
    }
    int res = INT_MAX;
    for (int i = 0; i < N; ++i) {
        int sum = 0;
        for (int j = 0; j < n; ++j) {
            sum += (i - x[j]) * (i - x[j]);
        }
        res = min(res, sum);
    }
    cout << res << endl;

    return 0;
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;
int main()
{
    const double EPS = 1.0e-10;
    double a,b,c,d,e,f;
    double x1,x2,x3,y1,y2,y3;
    double x,y;
    int n;
	cin >> n;
    for(int i = 0; i < n; i++){
    	cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
        a = x1 - x2;
        b = y1 - y2;
        c = (x1 * x1 + y1 * y1 - x2 * x2 - y2 * y2) / 2;
        d = x1 - x3;
        e = y1 - y3;
        f = (x1 * x1 + y1 * y1 - x3 * x3 - y3 * y3) / 2;
        x = (e * c - b * f) / (a * e - b * d);
        y = (a * f - d * c) / (a * e - b * d);
        if(-0.0005 < x && x < 0.0+EPS) x = 0.0;
        if(-0.0005 < y && y < 0.0+EPS) y = 0.0;
 
        printf("%.3f %.3f %.3f\n",x,y,sqrt((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y)));
    }
    return 0;
}


Measured memory_bytes: 3068
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
  int a,b,c;
  C3(a,b,c);
  if(c >= a && c <= b)
    Yes;
  else
    No;
  ret 0;
}

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

signed main() {
    int n,x,y;
    cin>>n>>x>>y;
    int dis;
    map<int,int> m;
    m[y-x]++;
    for(int i=1;i<=n-1;i++)
    {
        m[i]=0;
        
        for(int x1=1;x1<=n-i;x1++)
        {
            int y1=x1+i;
            if(x1<=x || y<=y1)
            {
                if(x1<=x && y<=y1)
                dis = (x-x1+y1-y+1);
                else if(x1<=x)
                dis = min(y1-x1,x-x1+y-y1+1);
                else if(y<=y1)
                dis = min(x1-x+1+y1-y,y1-x1);
                m[dis]++;
            }
            else if(x<=x1 && y1<=y)
            {
                dis = min(x1-x+1+y-y1,y1-x1);
                m[dis]++;
            }
            else
            {
                dis = (y1-x1);
                m[dis]++;
            }
        }
    }
    for(auto i:m)
    cout<<i.second<<endl;
    }

Measured memory_bytes: 3724
#include <stdio.h>

int a[1010];
int lim[1010];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",lim+i);
	int q;
	scanf("%d",&q);
	int ans=0;
	while(q--){
		int t,x,d;
		scanf("%d%d%d",&t,&x,&d);
		if(t==1)a[x]+=d;
		else a[x]-=d;
		if(a[x]<0||a[x]>lim[x]){
			ans=x;
			break;
		}
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 2128
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define double long double
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    ll n,m;cin>>n>>m;
    ll ans=(n-m)*100+m*1900;
    while(m){
        ans*=2;
        m--;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
 
typedef tree<pair<long long,int>, null_type, less<pair<long long,int>>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
 
#define f first
#define se second
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define pi pair<int, int>
#define all(num) num.begin(), num.end()
#define lp(i, nodess) for (int i = 0; i < nodess; i++)
#define mem(u, vis) memset(u, vis, sizeof(u))
#define X real()
#define Y imag()
#define angle(u) (atan2(u.Y, u.X))
#define vec(u, v) ((v) - (u))
//#define length(u) (hypot(u.Y , u.X))
#define normalize(u) (u) / length(u)
#define dotP(u, v) ((conj(u) * v).X)
#define crossP(u, v) ((conj(u) * v).Y)
#define same(p1, p2) (dotP(vec(p1, p2), vec(p1, p2)) < EPS)
#define lengthSqr(u) dotP(u, u)
#define rotate0(p, ang) ((p)*exp(point(0, ang)))
#define rotateA(p, ang, about) (rotate0(vec(about, p), ang) + about)
#define reflect0(vis, m) conj(vis / m) * m
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
const double PI = acos(-1.0);
const double EPS = (1e-10);
const long long int INF = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
typedef long long int ll;
typedef unsigned long long ull;
typedef complex<double> point;
long long fastpow(ll nodess, ll num, ll m) {
  if (!num)
    return 1;
  if (num % 2)
    return nodess * fastpow(nodess, num - 1, m)%m;
  ll p = fastpow(nodess, num / 2, m);
  p %= m;
  p *= p;
  p %= m;
  return p;
}
 
ll my_mod(ll num, ll mod) {
  ll reto = num % mod;
  while (reto < 0)
    reto += mod;
  return reto;
}
 
ll gcd(ll u, ll v) { return !u ? v : gcd(v % u, u); }
/*long long dist(pair<ll, ll> u, pair<ll, ll> v) {
  return 
      abs(u.f - v.f)  + abs(u.se - v.se);
}*/
long long getDist(pair<ll, ll> &u, pair<ll, ll> &v) {
  return 
     (u.f - v.f)*(u.f - v.f)  + (u.se - v.se)*(u.se-v.se);
}
 
 
 
/*vector<int> ap;
int np[MX+5];
void s(){
    mem(np , 1);
    np[1] = np[0] = 0;
    for(ll i = 2 ; i*i<= MX ;i++){
        if(np[i]){
            for(ll j= i*i ; j <=MX; j+=i) np[j] = 0;
        }
    }
    int idx = 1;
    for(ll i = 2 ; i<= MX ; i++){
		if(np[i]){
			np[i] = idx;
			idx++; 
			ap.pb(i);
		}
	}
	//cout<<idx;
}*/

#define int ll
const int MX = 1e3 +9;

int32_t main(){
    IO;
	int a,b,m;
	cin>>a>>b>>m;
	vector<int> arr1(a), arr2(b);
	for(int i =0 ;i < a; i++){
		cin>>arr1[i];
	}
	for(int i =0 ;i < b; i++){
		cin>>arr2[i];
	}
	int ans = *min_element(all(arr1)) + *min_element(all(arr2));
	while(m--){
		int x,y,c;
		cin>>x>>y>>c;
		ans = min(ans, arr1[x-1] + arr2[y-1] - c);
	}
	cout<<ans;
	return 0;
}


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

int main()
{
	int n, k;
	string s;

	cin >> n >> s >> k;

	char a = s[k - 1];
	for (int i = 0; i < n; i++)
		if (s[i] != a)
			s[i] = '*';

	cout << s << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = Integer.parseInt(sc.next());
		int w = Integer.parseInt(sc.next());
		String[][] s = new String[h][w];
		int count = 0;
		for (int i = 0; i < h; i++) {
			s[i] = sc.next().split("");
			for (int j = 0; j < w; j++)
				if (s[i][j].equals(".")) count++;
		}
		int ans = bfs(s, h, w);
		if (ans != -1)
			ans = count - ans;
		System.out.println(ans);
	}

	public static int bfs(String[][] s, int h, int w) {
		int[][] d = new int[h][w];
		for (int i = 0; i < h; i++)
			Arrays.fill(d[i], -1);
		int[] dx = {1, 0, -1, 0};
		int[] dy = {0, 1, 0, -1};
		int sx = 0, sy = 0, gx = h - 1, gy = w - 1;
		Deque<Point> p = new ArrayDeque<Point>();
		p.push(new Point(sx, sy));
		d[sx][sy] = 1;
		while (!p.isEmpty()) {
			Point q = p.pop();
			int x = q.x;
			int y = q.y;
			for (int i = 0; i < 4; i++) {
				int nx = x + dx[i];
				int ny = y + dy[i];
				if (nx < 0 || h <= nx || ny < 0 || w <= ny || s[nx][ny].equals("#"))
					continue;
				if (d[nx][ny] != -1)
					continue;
				d[nx][ny] = d[x][y] + 1;
				p.add(new Point(nx, ny));
			}
		}
		return d[gx][gy];
	}

	public static class Point {
		int x;
		int y;
		public Point(int x, int y) {
			this.x = x;
			this.y = y;
		}
	}
}


Measured memory_bytes: 22100
#K, X = map(int, input().split())
# T = input()
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
p = [1 for _ in range(N)]
q = [1 for _ in range(N)]


def kaizyo(n):
    if n == 0:
        ans = 1
    else:
        ans = 1
    for i in range(1, n+1):
        ans *= i
    return ans

ansA = 0
ansB = 0
for i in range(N-1):
    p[P[i]-1] = 0
    q[Q[i]-1] = 0
    ansA += sum(p[:P[i]-1]) * kaizyo(N-1-i)
    ansB += sum(q[:Q[i]-1]) * kaizyo(N-1-i)

#print(ansA,ansB)
print(abs(ansA-ansB))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
typedef long long int ll;
#define f(i, n) for(int i = 0; i < n; ++i)
#define pb push_back
bool check(int x, int sum, vector<int>&a, int n, int k){
    vector<int>v;
    f(i, n)v.push_back(a[i] % x);
    sort(v.begin(), v.end());

    int steps = 0;
    int temp = 0;
    int l = 0, r = n - 1;
    while(l <= r){
        if(temp <= 0){
            temp += v[l];
            steps += v[l];
            ++l;
        }else{
            temp -= (x - v[r]);
            steps += (x - v[r]);
            --r;
        }
    }
    if(steps > 2 * k)return false;
    if(temp != 0)return false;
    return true;
}

void input(){
    int n, k; cin >> n >>k;
    vector<int>a(n);
    int sum = 0;
    f(i, n){
        cin >> a[i]; sum += a[i];
    }
    if(n == 1){
        cout << a[0] << endl;return;
    }
    int ans = 1;
    for(int i = 1; i * i <= sum; ++i){
        if(sum % i == 0){
            if(check(i, sum, a, n, k))ans = max(ans, i);
            if(check(sum / i, sum, a, n, k))ans = max(ans, sum / i);
        }
    }
    cout << ans << endl;
}
int main()
{
 input();
 return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

  vector<ll> trans(5);
  rep(i, 5) cin >> trans[i];
  sort(trans.begin(), trans.end());
  ll ans = (N - 1) / trans[0] + 5;

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




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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  ll N, K, S; cin >> N >> K >> S;
  ll cnt = 0;
  vector<ll> A;
  while(true) {
    if(cnt == K) break;
    A.push_back(S);
    cnt++;
  }
  for(int i = 0; i < N - K; ++i) {
    if(S == 1000000000) A.push_back(S - 1);
    else A.push_back(S + 1);
  }
  REP(i, A.size()) {
    cout << A[i] << " ";
  }
  cout << endl;
}

Measured memory_bytes: 2292
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <stack>
#include <vector>

#define FOR(i,k,n) for(int (i) = (k); (i) < (n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x,y) cerr << #x << ": " << x << ", " << #y << ": " << y << endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
template<class T> using vv=vector<vector<T>>;
typedef deque<int> di;
typedef deque<deque<int>> ddi;

int main() {
    short r[101] = {};
    int a, b;
    while(cin >> a >> b) {
        r[a]++; 
        r[b]++;
        if(a == 0) {
            bool f = true;
            FOR(i,1,101) {
                if(i == 1 || i == 2) {
                    if(r[i] % 2 == 0) {
                        f = false;
                        break;
                    }
                } else if(r[i] % 2 == 1) {
                    f = false;
                    break;
                }
            }

            if(!f) {
                cout << "NG" << endl; 
            } else {
                cout << "OK" << endl;
            }
            rep(i,101) r[i] = 0; 
        }
    }
    return 0;
}

Measured memory_bytes: 3096
from collections import deque
import bisect
s = input()
t = input()
N = len(s)
dict = {}
for i in range(N):
  if s[i] in dict.keys():
    dict[s[i]].append(i)
  else:
    dict[s[i]] = [i]
cur = -1
count = 1
for i in range(len(t)):
  if t[i] not in dict.keys():
    print(-1)
    exit()
  if cur <= dict[t[i]][-1]:
    tmp = bisect.bisect_left(dict[t[i]],cur)
    cur = dict[t[i]][tmp] + 1
  else:
    count += 1
    cur = dict[t[i]][0] + 1
#  print("t[i] {} count {}, cur {}".format(t[i],count,cur))
ans = (count-1)*N + cur
print(ans if count <= 10**100 else -1)

Measured memory_bytes: 7924
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<n;++i)
#define REP(i, k, n) for(int i=k; i<=n; ++i)
#define REPR(i, k, n) for(int i=k; i>=n; --i)
#define MAX 2001
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define r return
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int long long uill;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);

	

	string input;
	string f = "";

	getline(cin, input);

	rep(i, input.length()){
		if(input[i] == '0'){
			f.push_back('0');
		}else if(input[i] == '1'){
			f.push_back('1');
		}else if(input[i] == 'B' && f[0] != '\0'){
            f.pop_back();
		}else if(input[i] == 'B'){
			continue;
		}
	}

	cout << f << "\n";


     r 0;
}

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

int main()
{
    int n;
    scanf("%d", &n);
    vector<int> a(n);
    int s = 0;
    for (auto& i : a) scanf("%d", &i), s ^= i;
    for (auto& i : a) printf("%d ", i ^ s);
    printf("\n");
    return 0;
}

Measured memory_bytes: 4028
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long double DD;
const int inf = 1e9;
const int mo= 1e9+7;
const int N = 2e5+10;
int n, fa[N], dep[N], S[N];

int cc = 0, to[N << 1], nex[N << 1], o[N];
void add(int x,int y){
	to[++cc] = y; nex[cc] = o[x]; o[x] = cc;
	to[++cc] = x; nex[cc] = o[y]; o[y] = cc;
}

void dfs(int x){
	S[x] = 1;
	for(int k = o[x]; k; k = nex[k]){
		int y = to[k];
		if(fa[x] == y)
			continue;
		dep[y] = dep[x] + 1;
		fa[y] = x;
		dfs(y);
		S[x] += S[y];
	}
}


int main(){
	scanf("%d", &n);
	for(int i = 1; i < n; i++){
		int x,y;
		scanf("%d%d", &x, &y);
		add(x,y);
	}
	fa[1] = 0;
	dep[1] =  1;
	dfs(1);
	int low = dep[n] >> 1;
	int t = n;
	for(int i = 1; i < low; i++)
		t = fa[t];
	int num1 = n - S[t];
	int num2 = S[t];
//	printf("%d %d\n",num1,num2);
	if(num1 > num2)
		puts("Fennec");
	else
		puts("Snuke");
	return 0;
}




Measured memory_bytes: 10240
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  i64 N, K;
  std::cin >> N >> K;
  std::vector<i64> A;
  tools::read(A, N);

  std::transform(A.begin(), A.end(), A.begin(), [](const i64& A_i) { return A_i - 1; });
  std::vector<i64> cumsum({0});
  std::partial_sum(A.begin(), A.end(), std::back_inserter(cumsum));
  std::transform(cumsum.begin(), cumsum.end(), cumsum.begin(), [&K](const i64& cumsum_i) { return cumsum_i % K; });

  std::queue<i64> queue;
  std::unordered_map<i64, i64> map;

  i64 answer = 0;
  for (const i64& cumsum_i : cumsum) {
    if (static_cast<i64>(queue.size()) >= K) {
      --map[queue.front()];
      queue.pop();
    }

    answer += map[cumsum_i];

    queue.push(cumsum_i);
    ++map[cumsum_i];
  }

  std::cout << answer << std::endl;
  return 0;
}

Measured memory_bytes: 13296
#include <iostream>
using namespace std;
int main()
{
    int N,X,i;
    cin >> N >> X;
    int L[N],D[N+1];
    for(i=0;i<N;i++)cin >> L[i];
    D[0]=0;
    for(i=0;i<=N;i++)
    {
        if(D[i]>X)break;
        D[i+1]=D[i]+L[i];
    }
    cout << i << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;
typedef vector<double> vec3;

int main() {
  string s;
  cin >> s;
  int start = s.find("A"),
      end   = s.rfind("Z");

  cout << (end + 1) - start << endl;
}

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

m = [[0 for j in range(n)] for i in range(n)]
for i in range(n):
    if Adj[i][1]>0:
        for a in Adj[i][2:]:
            m[i][a-1] = 1
for e in m:
    print(*e)


Measured memory_bytes: 6388
N,M,X,Y = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))

x = sorted(x)[::-1]
y = sorted(y)

if x[0] < y[0] and x[0] < Y and X < y[0]:
    print("No War")
else:
    print("War")

Measured memory_bytes: 38256