akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

string S;
int w;

signed main() {
    cin >> S >> w;
    string ans = "";
    for (int i = 0; i < S.length(); i += w) {
        ans.push_back(S[i]);
    }
    cout << ans << endl;
    return 0;
}
//B


Measured memory_bytes: 256
S = int(input())
p = 10 ** 9 + 7
if S < 3:
  print(0)
else:
  def ModComb(n, r, p):
    N = n%p
    R = r%p
    if N<R:
      return 0
    if N < 2*R:
      R = N-R
    if R == 0:
      return 1
    else:
      return ((n*pow(r, p-2, p))%p*ModComb(n-1, r-1, p))%p
  def cmb(n, r, p):
    a = 1
    b = 1
    r = min(r, n - r)
    for i in range(r):
      a = a * (n-i) % p
      b = b * (i+1) % p
    return a * pow(b, p-2, p) % p
  max_digit = S//3
  ans = 0
  for i in range(1, max_digit + 1):
    remain = S - 3 * i
    ans += ModComb(remain + i - 1, i - 1, p)
    ans = ans % p
  print(ans)
    

Measured memory_bytes: 9332
#include <iostream>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);

	int a, b;

	cin >> a >> b;

	if (a > b)
		for (int i = 0; i < a; i++)
			cout << b;
	else
		for (int i = 0; i < b; i++)
			cout << a;

	return 0;
}

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

using namespace std;

long long int lcm(long long int a, long long int b) {
	if (b == 0) {
		return a;
	}
	else {
		return lcm(b, a%b);
	}
}

int main() {
	long long int n, xx;
	cin >> n >> xx;

	vector<long long int> x(n);
	for (long long int i = 0; i < n; i++) {
		cin >> x[i];
	}

	vector<long long int> y;
	y = x;
	y.push_back(xx);

	sort(y.begin(), y.end());

	long long int ans = y[1] - y[0];
	for (long long int i = 1; i < n; i++) {
		ans = lcm(ans, y[i + 1] - y[i]);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2560
n = int(input())
a = list(map(int, input().split()))

v = [-1 for _ in range(n+1)]
for i in range(n+1):
  if v[a[i]] >= 0:
    A = v[a[i]]
    C = n-i
    break
  v[a[i]] = i

MAX_NUM = n+100
MOD = 10**9+7

fac  = [0 for _ in range(MAX_NUM)]
finv = [0 for _ in range(MAX_NUM)]
inv  = [0 for _ in range(MAX_NUM)]

fac[0]  = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1

for i in range(2,MAX_NUM):
    fac[i] = fac[i-1] * i % MOD
    inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i-1] * inv[i] % MOD

def comb(n,k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD

for k in range(1,n+2):
  print((comb(n+1, k) - comb(A+C, k-1)) % MOD)


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

long long int n,a[100100],i,dp[100100],x,k;

signed main()
{
    ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n>>k;
	for (i=1;i<n+1;i++) cin>>a[i];
	dp[1]=0;
	dp[2]=abs(a[1]-a[2]);
	if (n>2) for (i=3;i<n+1;i++)
	{
		dp[i]=dp[i-1]+abs(a[i]-a[i-1]);
		if (k>1) for (x=2;x<min(k+1,i);x++)
		dp[i]=min(dp[i],dp[i-x]+abs(a[i]-a[i-x]));
	}
	cout<<dp[n];
}


Measured memory_bytes: 1792
import java.util.*;

public class Main{
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        
        if(a.charAt(a.length() - 1) == b.charAt(0) && b.charAt(b.length() - 1) == c.charAt(0)){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 35564
/*
Author : shah_entrance
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n;
    cin>>n;
    if(n==7 || n==5 || n==3)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
 
int main(){
    int H, W, M;
    cin >> H >> W >> M;
    typedef pair<int, int> pair_items;
    set<pair_items> st;
    REP(i,M){
        int a, b;
        cin >> a >> b;
        st.insert({a, b});
    }
    map<int, int> mph, mpw;
    int hmax_value = 0;
    int wmax_value = 0;
    
    for(auto tmp: st){
        chmax(hmax_value, ++mph[tmp.first]);
        chmax(wmax_value, ++mpw[tmp.second]);
    }
 
    vector<int> h_maxes, w_maxes;
 
    for(auto h_item: mph){
        if(h_item.second == hmax_value){
            h_maxes.push_back(h_item.first);
        }
    }
 
    for(auto w_item: mpw){
        if(w_item.second == wmax_value){
            w_maxes.push_back(w_item.first);
        }
    }
 
    for(auto hval: h_maxes){
        for(auto wval : w_maxes){
            if(st.find({hval, wval})==st.end()){
                cout << hmax_value + wmax_value << endl;
                return 0;
            }
        }
    }
    cout << hmax_value + wmax_value - 1 << endl;
    return 0;
 
}

Measured memory_bytes: 49636
import java.util.BitSet;
import java.util.Scanner;

/**
 * Created by sotetsuk on 2015/07/18.
 */
public class Main {

    static Scanner sc = new Scanner(System.in);
    static final int MAX_R = 15, MAX_C = 1005;
    static int R, C;
    static BitSet[] o = new BitSet[MAX_R];

    public static boolean read() {
        R = sc.nextInt();
        C = sc.nextInt();
        if(R == 0 && C == 0) return false;
        for(int i = 0; i < R; i++) {
            o[i] = new BitSet(MAX_C);
            for(int j = 0; j < C; j++) {
                if(sc.nextInt() == 1) o[i].set(j);
            }
        }
        return true;
    }

    public static void flip(int i) {
        for(int j = 0; j < R; j++) {
            if((i >> j & 1) == 1) {
                o[j].flip(0, C);
            }
        }
    }

    public static int count() {
        int ret = 0;
        for(int j = 0; j < C; j++) {
            int s = 0;
            for(int i = 0; i < R; i++) {
                s += o[i].get(j) ? 1 : 0;
            }
            ret += Math.max(s, R - s);
        }
        return ret;
    }

    public static void solve() {
        int ans = 0;
        // search all 2^R patterns
        for(int i = 0; i < (1 << R); i++) {
            flip(i);
            ans = Math.max(ans, count());
            flip(i);
        }
        System.out.println(ans);
    }

    public static void main(String[] args) {
        while(read()) {
            solve();
        }
    }
}

Measured memory_bytes: 64216
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

int main()
{
  int i,j,k;
  int d,D;
  cin >> D;
  ll c[27];
  ll s[D+1][27];
  ll t[27];
  ll sum=0;
  int last[27];
  for(i=0;i<27;i++){
    last[i] = -1;
  }
  
  vector<int> vec;
  for(i=0;i<26;i++){
    cin >> c[i]; 
  }
  for(i=0;i<D;i++){
    for(j=0;j<26;j++){
      cin >> k;
      vec.push_back(k);
      //cout << vec[j] << endl;
    }
    auto itr = max_element(vec.begin(), vec.end());
    size_t index = std::distance(vec.begin(), itr);
    cout << index+1 << endl;
    vec.clear();
  }
  for(i=0;i<D;i++){
    cin >> t[i];
  }
  
  for(i=0;i<D;i++){
    d = t[i]-1;
    last[d] = i;
    sum += s[i][d];
    for(j=0;j<26;j++){
      sum -= c[j]*( i-last[j] );
    }
    //cout << sum << endl;
  }
  
  
  return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int main(){
 int h,w; cin >> h >>w;
  vector<string> a(h);
  
  for(int i = 0 ;i < h; i++){cin >> a[i];}
  
  vector<bool> row(h); vector<bool> col(w); 
  for(int i = 0; i < h;i++){
    for(int j = 0; j < w; j++){
      if(a[i][j] == '#'){ row[i] = true; col[j] = true;}}}
    
    for(int i = 0; i < h; i++){
      if(row[i]){
        for(int j = 0; j < w; j++){
          if(col[j]){ cout << a[i][j];}}
      cout << endl;}}
    
    return 0;}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<unsigned char, unsigned char> pcc;
typedef pair<double, double> pdd;
typedef vector<vector<ll>> matrix;

pll d[1000000];
int parent[1000000];
int treesz[1000000];
ll dp[1000000];
int n;
int s;

vector<int> edges[1000000];
void check() {
  memset(dp, 0, sizeof(dp));
  queue<pii> q;
  q.push({s, -1});
  ll amt = 0;
  while(!q.empty()) {
    pii curr = q.front(); q.pop();
    amt += dp[curr.first];
    for(int out: edges[curr.first]) {
      if(out == curr.second) continue;
      dp[out] = dp[curr.first]+1;
      q.push({out, curr.first});
    }
  }
  if(amt != d[0].first) {
    cout << "-1\n";
    exit(0);
  }
}

void solve() {
  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> d[i].first;
    d[i].second = i;
  }
  sort(d, d+n);
  map<ll, int> from;
  for(int i = 0; i < n; i++) from[d[i].first] = i;
  for(int i = 0; i < n; i++) treesz[i] = 1;
  for(int qq = n-1; qq > 0; qq--) {
    int realVertex = d[qq].second;
    ll currDist = d[qq].first;
    ll want = currDist - n + 2 * treesz[realVertex];
    if(!from.count(want)) {
      cout << "-1\n";
      return;
    }
    int fromInD = from[want];
    int actualVertex = d[fromInD].second;
    if(actualVertex == realVertex) {
      cout << "-1\n";
      return;
    }
    parent[realVertex] = actualVertex;
    edges[realVertex].push_back(actualVertex);
    edges[actualVertex].push_back(realVertex);
    treesz[actualVertex] += treesz[realVertex];
    s = actualVertex;
  }
  check();
  for(int i = 0; i < n; i++) {
    for(int out: edges[i]) {
      if(out > i) {
        cout << (i+1) << " " << (out+1) << "\n";
      }
    }
  }
}

void casesolve() {
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ":" << "\n";
    solve();
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  // casesolve();
}


Measured memory_bytes: 47744
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, k;
    cin >> n >> k;
    int pre = 0;
    int suf = 0;
    for(int i = 0; i < k; i++){
        pre += i;
    }
    for(int i = n; i > (n - k); i--){
        suf += i;
    }
    int ans = 0;
    while(k <= (n + 1)){
       ans = (ans + (suf - pre + 1) % mod) % mod;
       pre += k;
       suf += (n - k);
       k++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3648
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	ll N;
	string S; 
	cin >> N >> S;
	int ans = 0;
	bool f = false;
	for (int i = 0; i < N;i++) {
		if (S[i] == 'o') {
			f = false; ans++;
		}
		else {
			if (f) break;
			f = true; ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3348
#include <stdio.h>
int main(void){
    int N,l,r;
    int k=0;
    int h[100]={};
    scanf("%d",&N);
    for(int i=0;i<N;i++){
        scanf("%d",&h[i]);
    }
    while (1) {
        for(l=0;h[l]==0;l++){
            if(l==N){
                printf("%d\n",k);
                return 0;
            }
        }
        for(r=l;h[r]!=0;r++){
            h[r]--;
        }
        k++;
    }
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(){
  int N;
  cin >> N;
  vector<ll> A(N);
  int minus_cnt = 0;
  for(int i = 0;i < N;i++){
    cin >> A[i];
    if(A[i] < 0)minus_cnt++;
    A[i] = max(A[i],-A[i]);
  }

  if(minus_cnt%2 == 1){
    ll ans = 0;
    for(int i = 0;i < N;i++)ans += A[i];
    ll min_A = *min_element(A.begin(),A.end());
    cout << ans - 2 * min_A << endl;
  }
  else{
    ll ans = 0;
    for(int i = 0;i < N;i++)ans += A[i];
    cout << ans << endl;
  }


}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};

const int N=2e5+5,B=30;
int a[N],b[N];
int mat[B][N];
int inv[B][N];
int s[N*3],z[N*3];
void zz(int n){
    int left=0,right=0;
    for(int i=1;i<n;++i){
        z[i]=0;
        if(i<right)z[i]=min(z[i-left],right-i);
        while((s[z[i]]==s[i+z[i]])&&(i+z[i]<n))++z[i];
        if(i+z[i]>right)left=i,right=i+z[i];
    }
}

int32_t main(){
    int n;
    cin>>n;
    forn(i,n)cin>>a[i];
    forn(i,n)cin>>b[i];
    forn(j,B){
        {
            forn(i,n)s[i]=b[i]>>j&1;
            s[n]=8;
            forn(i,n)s[i+n+1]=a[i]>>j&1;
            forn(i,n)s[i+n+n+1]=a[i]>>j&1;
            zz(n+n+n+1);
            for(int i=n+1,k=0;k<n;++i,++k){
                if(z[i]==n)
                    mat[j][k]=1;
            }
        }
        {
            forn(i,n)s[i]=1-(b[i]>>j&1);
            s[n]=8;
            forn(i,n)s[i+n+1]=a[i]>>j&1;
            forn(i,n)s[i+n+n+1]=a[i]>>j&1;
            zz(n+n+n+1);
            for(int i=n+1,k=0;k<n;++i,++k){
                if(z[i]==n)
                    inv[j][k]=1;
            }
        }
    }
    forn(i,n){
        int ok=1,x=0;
        forn(j,B){
            if(inv[j][i])x^=1<<j;
            else if(!mat[j][i])ok=0;
        }
        if(ok)cout<<i<<' '<<x<<'\n';
    }

    return 0;
}


Measured memory_bytes: 103680
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int A, B, C;
	cin >> A >> B >> C;

	cout << C-min(C, A - B) << endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define eps 1e-9
#define oo 1e7+5

using namespace std;

typedef unsigned long long ull;
typedef vector<pair<int,pair<int,int>>> dirgraph;
typedef vector<vector<int>> graph;

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	
	char A='A';
	char a='a';
	char k;
	cin>>k;
	if(k>='a' && k<='z')
		cout<<a<<endl;
	else cout<<A<<endl;

	return 0;
}

Measured memory_bytes: 3656
import fractions
from functools import reduce
 
n = int(input())
a = list(map(int,input().split()))

left = [0] * (n+1)
right = [0] * (n+1)
for i in range(n):
    left[i+1] = fractions.gcd(left[i],a[i])
    right[n-i-1] = fractions.gcd(right[n-i],a[n-1-i])
    
ans = 0
for i in range(n):
    ans = max(ans,fractions.gcd(left[i],right[i+1]))
print(ans)

Measured memory_bytes: 16148
import java.util.*;
public class Main{
    static int gcd(int a,int b)
    {
       int tmp;
		if(b > a) {
			tmp = a;
			a = b;
			b = tmp;
		}
 
		if(b == 0) {
			return a;
		}
 
	    int r = -1;
	    do{
	        r = a % b;
	        a = b;
	        b = r;
	    }while (r != 0);
 
	    return a;
	
    }
    public static void main(String[] args) {
      
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int a[] = new int[n];
        for (int i = 0; i < n; ++i){
            a[i] = in.nextInt();
        }
       int l[]=new int[n];
       int r[]=new int[n];
       l[0]=a[0];
       r[n-1]=a[n-1];
       for(int i=1;i<n;i++)
       {
           l[i]=gcd(l[i-1],a[i]);
       }
       for(int i=n-2;i>=0;i--)
       {
           r[i]=gcd(r[i+1],a[i]);
       }
       int x=Math.max(l[n-2], r[1]);
      for(int i = 1 ; i < n-1 ; i++) {
          x = Math.max(x, gcd(l[i-1], r[i+1]));
      }
        System.out.println(x);
    }
}

Measured memory_bytes: 50404
a,b,c,x,y=map(int,input().split())
p_=a*x+b*y
for i in range(10**5+1):
  p=i*2*c+a*max(0,x-i)+b*max(0,y-i)
  if p<p_:
    p_=p
print(p_)

Measured memory_bytes: 2940
def main():
    a, b = [int(x) for x in input().split()]
    if b == 1:
        print(0)
        return
    n = 1
    b -= a
    while b > 0:
        b -= a-1
        n += 1
    print(n)
    return


if __name__ == "__main__":
    main()

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

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#pragma GCC optimize("Ofast")
//1.0 * clock() / CLOCKS_PER_SEC

#define fi first
#define se second
#define ll long long
#define dl double long

using namespace std;

const int NN = 1e6 + 7;
const int N = 2e5 + 7;
const int M = 20;
const int mod = 998244353;
const ll inf = 1e18 + 7;
const dl rf = 1e-14;

void solve1()
{
    int n;
    cin >> n;
    cout << (n + 1) / 2;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0); srand(time(0));
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    int cghf = 1;//cin >> cghf;
    while( cghf-- ){
        solve1();
    }
}


Measured memory_bytes: 256
import collections
n,m = (int(i) for i in input().split())
h = [int(i) for i in input().split()]
ab =[[0]]*n

for _ in range(m):
	a,b = (int(i) for i in input().split())
	if h[a-1]-h[b-1]>0:
		ab[b-1]=["a"]

	elif h[a-1]-h[b-1]<0:
		ab[a-1]=["a"]

	else:
		ab[a-1]=["a"]
		ab[b-1]=["a"]


print(ab.count([0]))

Measured memory_bytes: 20480
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n;
    cin>>n;
    vl as(n);
    cin>>as;

    vl ss(n + 1);
    rep(i, n) ss[i + 1] = ss[i] + as[i];
    ll ans = LINF;
    rep(i, n - 1) {
        chmin(ans, abs(ss.back() - 2 * ss[i + 1]));
    }
    cout<<ans<<endl;
}

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

const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;
const int MOD = 1000000007;

typedef long long ll;

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

ll LCM(ll x, ll y)
{
    return x * y / GCD(x, y);
}

using Graph = vector<vector<int>>;

typedef pair<int, int> P;
int main()
{
    ll n;
    cin >> n;
    cout << n * (n - 1) / 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 99999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(150) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  lli A,B,C,D,E,F,N,M,K,L,R,X,Y,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> S;
  N=S.size();
  T=S;
  if(S=="keyence")sum++;
  rep(i,0,N)rep(j,i,N){
    S=T;
    S.erase(S.begin()+i,S.begin()+j+1);
    if(S=="keyence")sum++;
  }
  if(sum)Out("YES");
  else Out("NO");
}
  

Measured memory_bytes: 256
/*input
RRR
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld double
#define pii pair<int,int>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=3e3+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=3.14159265358979323846;
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define MP make_pair
ll mult(ll a,ll b){
    ll res=0LL;
    while(b){
        if(b&1) res=(res+a)%MOD;
        a=(a+a)%MOD;
        b>>=1;
    }
    return res%MOD;
}
ll mypow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    string s;
    cin>>s;
    int ans=0;
    int cur=0;
    REP(i,sz(s)){
        if(s[i]=='R') ++cur;
        else{
            MXTO(ans,cur);
            cur=0;
        }
    }
    MXTO(ans,cur);
    cout<<ans;
}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			final int one = sc.nextInt();
			if(one == 0){
				break;
			}
			
			final int two = sc.nextInt();
			final int three = sc.nextInt();
			final int four = sc.nextInt();
			final int five = sc.nextInt();
			
			int[] hands = new int[4];
			hands[one]++;
			hands[two]++;
			hands[three]++;
			hands[four]++;
			hands[five]++;
			
			int count = 0;
			int first = -1;
			int second = -1;
			for(int i = 1; i < 4; i++){
				if(hands[i] != 0){
					if(first == -1){
						first = i;
					}else if(second == -1){
						second = i;
					}
					count++;
				}
			}
			
			if(count == 3 || count == 1){
				for(int i = 0; i < 5; i++){
					System.out.println(3);
				}
			}else{
				if(first == 1 && second == 3){
					first = 3;
					second = 1;
				}
				
				System.out.println(one == first ? 1 : 2);
				System.out.println(two == first ? 1 : 2);
				System.out.println(three == first ? 1 : 2);
				System.out.println(four == first ? 1 : 2);
				System.out.println(five == first ? 1 : 2);
			}
		}
		
	}

}

Measured memory_bytes: 12000
#include <stdio.h>

int max(int x, int y)
{
	return x > y ? x : y;
}

int min(int x, int y)
{
	return x < y ? x : y;
}

int main(void)
{
	int A1, A2, A3;
	scanf("%d %d %d", &A1, &A2, &A3);

	int res = max(max(A1, A2), A3) - min(min(A1, A2), A3);
	printf("%d\n", res);
	return 0;
}


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

int main() {
    string s, t;
    cin >> s >> t;

    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());
    cout << (s < t ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

class program
{
    static void Main()
    {
        List<int> H = new List<int>();
        List<int> W = new List<int>();

        while (true)
        {
            string[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);

            if (a==0 && b==0)
            {
                break;
            }
            else
            {
                H.Add(a);
                W.Add(b);
            }
        }

        for (int i = 0; i < W.Count; i++)
        {



            for (int w1 = 0; w1 < W[i]; w1++)
            {
                Console.Write("#");
            }

            Console.WriteLine();

            for (int h1 = 1; h1 < H[i] - 1; h1++)
            {
                Console.Write("#");
                for (int w2 = 1; w2 < W[i] - 1; w2++)
                {
                    Console.Write(".");
                }
                Console.WriteLine("#");
            }

            for (int w3 = 0; w3 < W[i]; w3++)
            {
                Console.Write("#");
            }

            Console.WriteLine();
            Console.WriteLine();
        }
        
    }
}

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

using namespace std;

using LL = long long;

template<typename T>
ostream& operator << (ostream& out, const vector<T>& v) {
    out << "[";
    for(const auto& x : v) {
        out << x << ", ";
    }
    return out << "]";
}

template<typename S, typename T>
ostream& operator << (ostream& out, const pair<S, T>& p) {
    return out << "{" << p.first << ", " << p.second << "}";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int N;
    cin >> N;
    string S;
    cin >> S;
    int i = 0, j = N - 1;
    int ans = 0;
    while(true) {
        while(i < j and S[i] == 'R') {
            ++i;
        }
        while(i < j and S[j] == 'W') {
            --j;
        }
        if(i >= j) {
            cout << ans << "\n";
            return 0;
        } else {
            ++ans;
            ++i;
            --j;
        }
    }
    
    
    return 0;
}


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

const int MAX_N = 210;
int A[MAX_N];

void finish(){
  cout <<"Impossible" << endl; exit(0);
}

signed main(void){
  
  int N; cin >> N;
  int K = 0;
  for(int i = 0; i < N; i++){ 
    int a; cin >> a; A[a]++;
    K = max(K,a);
  }
  
  //次に直径パスを構築
  if(K%2 == 0){
   for(int i = K; i >= K/2; i--){ 
     
     if(i==K/2){ 
       if( A[i] == 0 ){ finish();}
       else{ A[i]--;}
     }
     else{
       if( A[i] <= 1 ){ finish();}
       else{ A[i]-=2;}
     }
     
   }
    
    for(int i = 1; i <= K/2; i++){
      if( A[i] > 0 ){ finish();}
    }
    
    cout << "Possible" << endl;
    
    
  }//偶数
  else{
    
    for(int i = K; i >= (K+1)/2; i--){
      
      if( A[i] <= 1 ){ finish();}
      else{ A[i] -= 2;}
    }
  
  
    for(int i = 1; i <= (K+1)/2; i++){
    if(A[i] > 0 ){ finish();}
      
  
     
      
    }
    
    cout << "Possible" << endl;
    
  }
  
  return 0;
}
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define vi vector<int>
template <class t, class u>
bool chmax(t &a, u b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class t, class u>
bool chmin(t &a, u b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}

signed main()
{
    int n;
    cin >> n;
    map<string, int> m;
    rep(i, n)
    {
        string s;
        cin >> s;
        m[s]++;
    }
    cout << "AC x " << m["AC"] << endl;
    cout << "WA x " << m["WA"] << endl;
    cout << "TLE x " << m["TLE"] << endl;
    cout << "RE x " << m["RE"] << endl;
    return 0;
}

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

int main() {

  int N;
  int max = -2000001000;
  int min =  2000001000;
  int temp;

  std::cin >> N;
  for(int i = 0; i < N; ++i) {
    std::cin >> temp;
    max = std::max(max, temp-min);
    min = std::min(min, temp);
  }

  std::cout << max << std::endl;

  
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
const long long INF = LLONG_MAX / 2;
#define FOR(i, r, n) for(int i=(r); i<(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ll long long int

template <typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

using namespace std;
ll ans = 0, sum = 0, n, k, t, counter = 0;
string s;

set<ll> st;
vector<ll> v;

int main()
{
	cin >> n;
	v.resize(n);
	REP(i,n)
	{
		cin >> v[i];
	}
	REP(i,n)
	{
		if (v[v[i] - 1] == i + 1 && !st.count(i)) {
			counter++;
			st.insert(v[i] - 1);
		}
		st.insert(i);
	}
	cout << counter << endl;
}


Measured memory_bytes: 5760
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
int num;
int mini=1000;

int main(){
  	string st;
  	cin>>st;
  	for(int i=0;i<st.size()-2;i++){
		num= (st[i] -'0')*100;
        num+=(st[i+1] - '0')*10;
        num+=(st[i+2] -'0');	
    	mini=min(mini,abs(num-753));
    }
  	cout <<mini <<endl;
	return 0;
}


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

using namespace std;

int main() {
    vector<vector<int>> q;
    int n;
    cin >> n;
    q.resize(n);
    int T;
    cin >> T;
    while (T--) {
        int x; cin >> x;
        if(x==0) {
            int a,b;
            cin >> a >> b;
            q[a].push_back(b);
        }
        if (x==1) {
            int t;
            cin >> t;
            int size = q[t].size();
            for (int i = 0; i < size; i++) {
                cout << q[t][i];
                if (i!=size-1) cout << " ";
            }
            cout << endl;
        }
        if (x==2) {
            int t;
            cin >> t;
            q[t].clear();
        }
    }
    return 0;
}


Measured memory_bytes: 5800
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int dp[100000+5][3];
void solve(){
	int n; cin>>n;
	int a1[n],a2[n],a3[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>a1[i]>>a2[i]>>a3[i];
	}
	dp[0][0]=a1[0];
	dp[0][1]=a2[0];
	dp[0][2]=a3[0];
	for (int i = 1; i < n; ++i)
	{
		dp[i][0] = max(dp[i-1][1], dp[i-1][2])+a1[i];
		dp[i][1] = max(dp[i-1][0], dp[i-1][2])+a2[i];
		dp[i][2] = max(dp[i-1][0], dp[i-1][1])+a3[i];
	}
	cout<<max({dp[n-1][0], dp[n-1][1], dp[n-1][2]})<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    // ll t; cin>>t;
    // while(t--)
        solve();
    return 0;
}



Measured memory_bytes: 5976
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    
    ll A, B, N;
    cin >> N >> A >> B;
    if(A % 2 == B % 2) {
        output((B - A) / 2);
    }
    else {
        ll a = (A + B - 1) / 2;
        ll b = (2 * N - B + 1 - A) / 2;
        output(min(a, b));
    }
    
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define endl "\n"
typedef long long ll;
#define traceV(v) for(auto x:v)cout<<x<<" ";cout<<endl
#define traceM(mp) for(auto x:mp)cout<<x.first<<" "<<x.second<<endl

bool judge(vector<int> v_now, vector<pair<int,int>> v_ref) {
  if(v_now[0]!=1)return false;

  rep(i, v_now.size()-1) {
    bool ok = false;
    int p1=v_now[i], p2=v_now[i+1];
    rep(j, v_ref.size()) {
      int a=v_ref[j].first, b=v_ref[j].second;
      if((p1==a&&p2==b)||(p1==b&&p2==a)) {ok = true; break;}
    }
    if(!ok)return false;
  }
  return true;
}

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

  int N,M; cin>>N>>M;
  vector<pair<int,int>> v(M);
  rep(i,M) cin >> v[i].first >> v[i].second;

  vector<int> v_now(N); rep(i,N) v_now[i]=i+1;

  int res = 0;
  do {
    if(judge(v_now, v))++res;
  } while(next_permutation(ALL(v_now)));

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <math.h>
using namespace std;

int main() {
    int a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    int i;
    int v;
    v=a*x+b*y;
    int u=max(x,y);
    int s;
    for(i=0;i<=2*u;i+=2){
        s=c*i;
        if(i/2<x){
            s+=a*(x-i/2);
        }
        if(i/2<y){
            s+=b*(y-i/2);
        }
        if(s<v) v=s;
    }
    cout<<v<<endl;
    
    return 0;
}

Measured memory_bytes: 256
use proconio::input;
use proconio::marker::{Bytes, Chars};

// x ** n % mods を求める
pub fn mod_pow(x: i64, n: i64, mods: i64) -> i64 {
    if n == 0 {
        return 1;
    }
    let mut res = mod_pow(x * x % mods, n / 2, mods);
    if n % 2 == 1 {
        res = res * x % mods;
    }
    return res;
}

// (1/n) % mods を求める
pub fn mod_inv(n: i64, mods: i64) -> i64 {
    return mod_pow(n, mods-2, mods);
}

// nCk % mods を求める
pub fn mod_comb(n: i64, k: i64, mods: i64) -> i64 {
    let sum1 = (n-k+1..n+1).fold(1, |ac, x| ac * x % mods);
    let sum2 = (1..k+1).fold(1, |ac, x| ac * x % mods);
    return sum1 * mod_inv(sum2, mods) % mods;
}

// nCk の組み合わせを列挙する
pub fn combination(n: usize, k: usize) -> Vec<Vec<usize>> {
    let mut ans = Vec::new();
    if k == 1 {
        for i in 1..n+1 {
            let mut tmp = Vec::new();
            tmp.push(i);
            ans.push(tmp);
        }
    }
    else {
        for iter in combination(n-1, k-1) {
            let max = iter.iter().max().unwrap();
            for j in *max+1..n+1 {
                let mut tmp = iter.clone();
                tmp.push(j);
                ans.push(tmp);
            }
        }
    }
    ans
}


fn main() {
    input!{
        a: usize,
    }
    println!("{}", a + a*a + a*a*a);
}


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

int main(void) {
  int N; cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) cin >> a.at(i);

  int c = (int)round((double)accumulate(a.begin(), a.end(), 0)/(double)N);
  int ret = 0;
  for (int a_i : a) ret += (a_i - c)*(a_i - c);
  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N,Q=map(int,input().split())
a=tuple(map(int1,input().split()))
lr=[() for i in range(Q)]
for i in range(Q):
    l,r=map(int1,input().split())
    lr[i]=(l,r,i)
lr.sort(key=lambda t: t[1],reverse=1)
class BIT:
    def __init__(self,n):
        self.num=n
        self.dat=[0]*(self.num+1)
        self.depth=n.bit_length()
    
    def add(self,i,x):
        i+=1
        while i<=self.num:
            self.dat[i]+=x
            i+=i&-i
    
    def sum(self,i):
        i+=1
        s=0
        while i>0:
            s+=self.dat[i]
            i-=i&-i
        return s
    
    def lower_bound(self,x):
        sum_=0
        pos=0
        for i in range(self.depth,-1,-1):
            k=pos+(1<<i)
            if k<=self.num and sum_+self.dat[k]<x:
                sum_+=self.dat[k]
                pos+=1<<i
        return pos, sum_

b=BIT(N)
lastap=[-1]*N
ans=[-1]*Q
l,r,j=lr.pop()
for i,x in enumerate(a):
    if lastap[x]!=-1:
        b.add(lastap[x],-1)
    b.add(i,1)
    lastap[x]=i
    while r==i:
        ans[j]=b.sum(r)-b.sum(l-1)
        if lr:
            l,r,j=lr.pop()
        else:
            l,r,j=-1,-1,-1
for x in ans:
    print(x)

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

using namespace std;

typedef pair<int, bool> Link;
typedef vector<vector<Link> > Graph;

int main () {
    int V, E, r;
    cin >> V >> E >> r;

    vector<pair<bool, int> > distances(V);
    vector<pair<pair<int, int>, int> > edges;

    // Init source to a distance of 0
    distances[r] = make_pair(true, 0);

    // Set known edges
    for(int i=0; i<E; i++) {
        int s, t, d;
        cin >> s >> t >> d;
        edges.push_back(make_pair(make_pair(s, t), d));
    }

    // Run Ford-Bellman
    for(int _=0; _<V; _++)
        for(int i=0; i<E; i++){
            int v1 = edges[i].first.first;
            int v2 = edges[i].first.second;
            int d = edges[i].second;

            if (distances[v1].first) {
                // If distance to v1 is Inf, ignore
                if (distances[v2].first) {
                    // If distance is defined, then check
                    if (distances[v2].second > distances[v1].second + d)
                        distances[v2] = make_pair(true, distances[v1].second + d);
                } else {
                    // If distance to v2 is Inf, force set
                    distances[v2] = make_pair(true, distances[v1].second + d);
                }
            }
        }

    // Detect loop
    for(int i=0; i<E; i++){
        int v1 = edges[i].first.first;
        int v2 = edges[i].first.second;
        int d = edges[i].second;

        if (distances[v1].first)
            if (distances[v2].first)
                if (distances[v2].second > distances[v1].second + d) {
                    cout << "NEGATIVE CYCLE" << endl;
                    return 0;
                }
    }

    // Log
    for(int i=0; i<V; i++) {
        bool isDefined = distances[i].first;
        int d = distances[i].second;

        if (isDefined)
            cout << d << endl;
        else
            cout << "INF" << endl;
    }
}



Measured memory_bytes: 3128
#include<stdio.h>
int main(){
	int t[101],pt[101][101],ans[101]={0},n,k,i,j,x;
	scanf("%d%d",&n,&k);
	for(i=0;i<k;i++)scanf("%d",&t[i]);
	for(i=0;i<k;i++){
		for(j=0;j<n;j++)scanf("%d",&pt[i][j]);
	}
	for(i=0;i<k;i++){
		x=0;
		for(j=0;j<n;j++){
			if(pt[i][j]==t[i])++ans[j];
			else ++x;
		}
		ans[t[i]-1]=ans[t[i]-1]+x;
	}
	for(i=0;i<n;i++)printf("%d\n",ans[i]);
	return 0;
}


Measured memory_bytes: 2112
#include <cstdio>
using namespace std;
int main() {
    int N; scanf("%d", &N);
    int a[N+1];
    for(int i = 1; i <= N; i++) scanf("%d", &a[i]);
    for(int i = 1, p = 1; i <= N; i++) {
        if(2 == (p = a[p])) {
            printf("%d", i);
            return 0;
        }
    }
    printf("%d", -1);
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <cstdlib>
#include <math.h>

using namespace std;

typedef long long ll;
#define rep(i, n) for(long (i) = 0; (i) < (long) (n); (i)++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,a,b) for(long i=(a);i<(b);i++)
#define rrep1(i,a,b) for(long i=(a);i<=(b);i++)
#define rrrep(i,a,b) for(long i=(a);i>=(b);i--)
#define define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define X first
#define Y second
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int> >
#define vpl vector<pair<long, long> >
#define vppl vector<pair<long, pair<long, long> > >

const int INF = 100100100;
const long LONG_INF = 2147483647;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const ll LINF = 1e18;


int pow(int x) {
	if (x == 0) {
		return 1;
	}
	else {
		return pow(x - 1) * 2;
	}
}

int main(int argc, char const *argv[])
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll a[n+1],b[n+1];
    b[1]=0;
    rep1(i,n){
        cin>>a[i];
        if (i%2==1)
        {
            b[1]+=a[i];
        } else
        {
            b[1]-=a[i];
        }
    }
    rrep1(i,2,n){
        b[i] = 2*a[i-1] - b[i-1];
    }
    rep1(i,n){
        cout << b[i] << " ";
    }

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int N;
  cin >> N;
  vector<int> a(3 * N);
  REP(i, 3 * N) cin >> a[i];
  sort(ALL(a));
  reverse(ALL(a));
  ll ans = 0;
  int cnt = 0;
  REP(i, 3 * N) {
    if (i % 2 == 1) {
      ans += a[i];
      cnt++;
    }
    if (cnt == N) break;
  }
  cout << ans << endl;
  return 0;
}

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

int main()
{
    int k = 0;
    char s[101];


    scanf("%d", &k);
    scanf("%s", s);

    // printf("k = %d\n", k);
    // printf("s = %s\n", s);


    if(strlen(s) <= k){
        printf("%s\n", s);
    }
    else{
        for(int i = 0; i < k; i++){
            printf("%c", s[i]);
        }
        printf("...\n");
    }


    return 0;
}



Measured memory_bytes: 3764
from itertools import combinations_with_replacement

N, M, Q = map(int, input().split())
L = []
for i in range(Q):
    ai, bi, ci, di = map(int, input().split())
    ai -= 1
    bi -= 1
    L.append((ai, bi, ci, di))

ans = 0
for A in combinations_with_replacement(range(M), N):
    r = 0
    for Li in L:
        if A[Li[1]] - A[Li[0]] == Li[2]:
            r += Li[3]
    ans = max(ans, r)

print(ans)


Measured memory_bytes: 9192
import math
import numpy as np

def main():
    n = int(input())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))

    pe = getal(p)+1
    qe = getal(q)+1
    print(abs(pe-qe))

def getal(arr):
    tarr = arr.copy()
    arg = [None]*len(arr)
    
    c = 0
    for i in range(len(arr)):
        arg[arr.index(min(tarr))] = c
        tarr.remove(min(tarr))
        c += 1

    x = math.factorial(len(arr)-1)

    v = arg[0]*x
    # print(arr, arg, v)

    if len(arr) == 2:
        return v
    else:
        ne = arr[1:]
        return v + getal(ne)

if __name__ == "__main__":
    main()

Measured memory_bytes: 12504
#include <iostream>

using namespace std;

int main() {
    long long int D, N;
    cin >> D >> N;
    
    long long int ans=N;
    if(ans==100) ans++;
    for(int i=0; i<D; i++) {
        ans *= 100;
    }
    cout << ans << endl;


    return 0;
    
}

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

const int mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  
  bool operator<(const mint a) const { return mint(*this).x < a.x;}
  bool operator>(const mint a) const { return mint(*this).x > a.x;}
  bool operator<=(const mint a) const { return mint(*this).x <= a.x;}
  bool operator>=(const mint a) const { return mint(*this).x >= a.x;}
  bool operator==(const mint a) const { return mint(*this).x == a.x;}

  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


mint combi(int n, int r){
    mint upper = n;
    mint bottom = r;
    for(int i=1;i<r;i+=1){
        upper *= n-i;
        bottom *= r-i;
    }
    return upper / bottom;
}




int main(void){
    int n,a,b;
    cin >> n >> a >> b;
    mint jou2 = 2;
    mint ans = jou2.pow(n);
    ans -= combi(n,a);
    ans -= combi(n,b);
    ans -= 1;
    cout << ans << endl;
}   

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int N,P;
  string S;
  cin >> N >> P >> S;
  if (P == 2) {
    ll res = 0;
    for (int i = 0; i < N; i++) {
      if (S[i] == '2' || S[i] == '4' || S[i] == '6' || S[i] == '8' || S[i] == '0') {
        res += i+1;
      }
    }
    cout << res << endl;
    return 0;
  }
  if (P == 5) {
    ll res = 0;
    for (int i = 0; i < N; i++) {
      if (S[i] == '5' || S[i] == '0') {
        res += i+1;
      }
    }
    cout << res << endl;
    return 0;
  }
  ll modP[P];
  for (int i = 0; i < P; i++) modP[i] =0;
  ll R[N+1];
  ll power10[300000];
  power10[0] = 1;
  for (int i = 1; i < 300000; i++) {
    power10[i] = power10[i-1] * 10;
    power10[i] %= P;
  }
  R[0] = 0;
  modP[0]++;
  for (int i = 0; i < N; i++) {
    int num = S[N-i-1] - '0';
    R[i+1] = (R[i] + (power10[i] * num)) % P;
    modP[R[i+1]]++;
  }
  ll ans = 0;
  for (int i = 0; i < P; i++) {
    if (modP[i] > 0) {
      ans += (modP[i] * (modP[i] - 1)) / 2;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 7688