akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 2e5+1;
ll f[N], r[N];
ll n, m, k;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  f[0] = 1;
  FOR(i, 1, N) f[i]=f[i-1]*i%MOD;
  r[N-1]=modInv(f[N-1], MOD);
  FORR(i, N-2, 0) r[i]=r[i+1]*(i+1)%MOD;
  cin >> n >> m >> k;
  ll z, ans = 0, x = k*(k-1)%MOD* f[n*m-2] %MOD* r[n*m-k] %MOD;
  z = x*m %MOD* m %MOD;
  FOR(i, 1, n) ans += z*i%MOD*(n-i)%MOD;
  z = x*n %MOD* n %MOD;
  FOR(i, 1, m) ans += z*i%MOD*(m-i)%MOD;
  cout << ans % MOD * r[k] % MOD << endl;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9+7;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int H,W,M; cin >> H >> W >> M;
  vi cnth(H),cntw(W),h(M),w(M);
  set<pair<int,int>> s;
  rep(i,M){
    cin >> h[i] >> w[i];
    h[i]--;  w[i]--;
    cnth[h[i]]++;
    cntw[w[i]]++;
    s.insert({h[i],w[i]});
  }
  int mxy = 0, mxx = 0;
  rep(i,H) chmax(mxy,cnth[i]);
  rep(i,W) chmax(mxx,cntw[i]);
  vi y,x;
  rep(i,H) if(mxy == cnth[i]) y.push_back(i);
  rep(i,W) if(mxx == cntw[i]) x.push_back(i);
  int ans = mxy+mxx;
  for(auto a : y) for(auto b : x){
    if(s.count({a,b})) continue;
    cout << ans;
    return 0;
  }
  cout << ans-1;
  cout << "\n";
  return 0;
}


Measured memory_bytes: 26116
#include<iostream>

using namespace std;

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

int n;
int a[100000];
int c[100001];

int main(){
    cin >> n;
    REP(i, n){
        cin >> a[i];
    }
    REP(i, 100001) c[i] = 0;

    REP(i, n){
        for(int j=max(0, a[i]-1); j<=min(100000, a[i]+1); j++){
            c[j] += 1;
        }
    }

    int output = 0;
    REP(i, 100001){
        output = max(output, c[i]);
    }
    cout << output << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

int main() {
  int a, b, count = 0, sum = 0;
  cin >> a >> b;
  sum++;
  while (sum < b) {
    count++;
    sum += a - 1;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int main(){
  int H, W;
  cin >> H >> W;
  vector<vector<char>> a(H + 1, vector<char>(W + 1, '#'));
  for (int i = 1; i <= H; i++){
    for (int j = 1; j <= W; j++){
      cin >> a[i][j];
    }
  }
  vector<vector<long long>> dp(H + 1, vector<long long>(W + 1, 0));
  dp[1][1] = 1;
  for (int i = 1; i <= H; i++){
    for (int j = 1; j <= W; j++){
      if (i == 1 && j == 1) continue;
      if (a[i][j] == '.'){
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
        dp[i][j] %= MOD;
      }
    }
  }
  cout << dp[H][W];
}

Measured memory_bytes: 9088
#include <iostream>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>

#define rep(i,n)	for(int i = 0;i < n;i++)
#define rep2(i,n)	for(int i = 1;i <= n;i++)
#define each(i,x)	for(auto & i : x)

using namespace std;

int main()
{
	int a,l;
	while(1)
	{
		cin >> a >> l;
		if(!a && !l)
			break;
		int i = 0;
		map<int,int> st;
		st.insert(make_pair(a,0));
		while(true)
		{
			i++;
			vector<int> str(l,0);
			int d = 1;
			rep(j,l)
			{
				str[j] = (a/d)%10;
				d *= 10;
			}
			sort(str.begin(),str.end());
			vector<int> bgg(str);
			reverse(bgg.begin(),bgg.end());
			int b = 0;
			int s = 0;
			rep(j,l)
			{
				b *= 10;
				s *= 10;
				b += bgg[j];
				s += str[j];
			}
			auto it = st.find(b-s);
			if(it != st.end())
			{
				cout << it -> second << ' ' << b-s << ' ' << (st.size() - it -> second) << endl;
				break;
			}
			else
			{
				a = b-s;
				st.insert(make_pair(a,i));
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
 
#define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define pb push_back
#define ll long long
 
#define vi vector<int>
#define vl vector<long>
#define vll vector<long long>
 
#define infi INT_MAX
#define infl LONG_MAX
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi(i,a,b) for(ll i=(b-1);i>=a;i--)
#define F first
#define S second
#define G(a,b) get<a>(b)
#define MP make_pair
#define MT make_tuple

void func()
{
  ll n;
  cin>>n;
  if(n%2!=0)
  {
    cout<<"0\n";
    return;
  }
  n=(n/2);
  ll ans=0,p=5;
  while(n/p>0)
  {
    ans+=(n/p);
    p*=5;
  }
  cout<<ans<<endl;
}
 
int main() 
{
    fast
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    
    ll q=1;
    //cin>>q;
    while(q)
    {
      func();
      q--;
    }
 
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 250

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

  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&num[i]);
  }
  for(i=1;i<=n;i++){
    printf("node %d: key = %d, ",i,num[i]);
    if(i/2>=1) printf("parent key = %d, ",num[i/2]);
    if(n>=2*i) printf("left key = %d, ",num[2*i]);
    if(n>=2*i+1) printf("right key = %d, ",num[2*i+1]);
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h> 
using namespace std; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
int main()
{
  //flash;
    ll n,k;
    cin>>n>>k;
    swap(n,k);
    ve kol;
    for (int i = 0; i < n; ++i)
    {
       ll yo;
       cin>>yo;
       kol.pb(yo);
    }
    sort(kol.begin(),kol.end());
    ll ans=0;
    ve fark;
    for (int i = 1; i < n; ++i)
    {
        //debugs(kol[i],kol[i-1])
        fark.pb(abs(kol[i]-kol[i-1]));
        ans+=(abs(kol[i]-kol[i-1]));
    }
    fark.pb(abs(k-kol[n-1]+kol[0]));
    ans+=(abs(k-kol[n-1]+kol[0]));
    //debug(ans);
    sort(fark.begin(),fark.end());
    reverse(all(fark));
    ans-=fark[0];
    cout<<ans;
  return 0;
}
//code the AC sol !
// BS/queue/map

Measured memory_bytes: 4848
//Tarun_SPARTAN
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define rlop(i,n) for(int i=n;i>0;i--)
#define lli long long int
#define se ios::sync_with_stdio(false); cin.tie(NULL);
#define mod 1000000000
#define ainp(a,n) for(int i=0;i<n;i++)cin>>a[i];
#define aout(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" ";
#define f(i, a, b) for(int i=a; i<b; i++)
#define lop(a,b) for(int i=a;i<b;i++)
#define ln cout<<"\n"
int main(){
    se;
   /* #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    freopen("op.txt","w",stdout);
    #endif*/
    
    int n,k;
    cin>>n>>k;
    int a[n];

    ainp(a,n)
        vector<int> dp(n, INT_MAX);
        dp[0]=0;
        dp[1]=abs(a[1]-a[0]);
        for(int i=2;i<n;i++){
            //int k=INT_MAX;
            for(int j=i-1,jp=0;j>=0&&jp<k;j--,jp++){
                dp[i]=min(dp[i],abs(a[i]-a[j])+dp[j]);
            }
            //dp[i]=min(abs(a[i]-a[i-2])+dp[i-2],dp[i-1]+abs(a[i]-a[i-1]));
        }
        //aout(dp,n)ln;
        cout<<dp[n-1];

    
}




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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;


bool check(int n, vector<int> t, vector<char> s){
  int l,r;
  l = (n == 0 ? t.size()-1 : n-1);
  r = (n == t.size() - 1 ? 0 : n+1);

  bool flag=true;
  if(t[n] == 0){
    if(s[n]=='o'){
      if(t[l] != t[r])flag=false;
    }else{
      if(t[l] == t[r])flag=false;
    }
  }else{
    if(s[n]=='x'){
      if(t[l] != t[r])flag=false;
    }else{
      if(t[l] == t[r])flag=false;
    }
  }

  return flag;
}

void printAns(vector<int> v){
  REP(i,v.size()){
    cout << (v[i] == 0 ? "S" : "W");
  }
  cout << endl;
  exit(0);
}

int main(){
  int N;
  cin >> N;
  
  vector<char> s(N);
  REP(i,N){
    char c;
    cin >> c;
    s[i] = c;
  }

  // 羊：0、狼：1
  REP(i,4){
    vector<int> t(N);
    t[0] = i&1;
    t[1] = (i>>1)&1;

    FOR(i,1,N-1){
      if(t[i] == 0){
        if(s[i]=='o') t[i+1] = t[i-1];
        else t[i+1] = t[i-1]^1;
      }else{
        if(s[i]=='o') t[i+1] = t[i-1]^1;
        else t[i+1] = t[i-1];
      }
    }

    if(check(0,t,s) && check(N-1,t,s))printAns(t);

  }
  cout << -1 << endl;
}

Measured memory_bytes: 1688
h,w = map(int,input().split())
l = [list(map(int,input().split())) for i in range(10)]
a = [list(map(int,input().split())) for i in range(h)]
ans = 0
for rep in range(10):
    for i in range(10):
        for j in range(10):
            for k in range(10):
                if l[i][j] > l[i][k]+l[k][j]:
                    l[i][j] = l[i][k]+l[k][j]
num = [i[1] for i in l] + [0]
for i in a:
    for j in i:
        ans += num[j]
print(ans)

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

int main(){
  long long i,n,ans;
  long long mod=1000000000+7;
  ans=1;
  cin >> n;
  for(i=1;i<=n;++i){
    ans=ans*i%mod;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
p = int(input().split()[1])
s = input()
if 10 % p == 0:
  r = sum(i for i, x in enumerate(s, 1) if int(x) % p == 0)
else:
  d = [1] + [0] * (p - 1)
  t, y = 0, 1
  for x in reversed(s):
    t = (t + int(x) * y) % p
    d[t] += 1
    y = y * 10 % p;
  r = sum(i * (i - 1) for i in d) // 2
print(r)

Measured memory_bytes: 3500
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define MOD 1000000007LL

using namespace std;
using llong = long long;

int main()
{
	IOS;
	
	char a;
	cin >> a;
	cout << (char)(a + 1);

	return 0;	
}



Measured memory_bytes: 3596
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int N = in.nextInt();
    char[] c = in.next().toCharArray();

    int count = 0;
    for (int i = 2; i < N; i++) {
      if (c[i - 2] == 'A' && c[i - 1] == 'B' && c[i] == 'C') {
        count++;
      }
    }
    System.out.println(count);
  }
}

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

typedef long long int llint;

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

  int a[101];

  for(int i = 0; i < n; i++) cin>> a[i];

  sort(a, a + n);

  int cnt = 0;

  for(int i = 0; i < n; i++) {
    if(x >= a[i]) {
      cnt++;
      x -= a[i];
    } else {
      break;
    }
  }

  if(x > 0 && cnt > 0 && cnt == n) cnt--;

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


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

using namespace std;

int N,K;
long long v[50];

int main(){
    long long max = -20000000;
    cin >> N >> K;
    for(int i=0;i<N;i++) cin >> v[i];
    for(int i=K/2;i<=K;i++){
        for(int j=0;j<=i;j++){
            vector<long long> w;
            if(i >= N){
                for(int x=0;x<N;x++) w.push_back(v[x]);
            }else{
                for(int x=0;x<j;x++) w.push_back(v[x]);
                for(int x=0;x<(i-j);x++) w.push_back(v[N-1-x]);
            }
            sort(w.begin(),w.end());
            for(int x=0;x<K-i && x<w.size();x++){
                if(w[x] < 0) w[x] = 0;
                else break;
            }
            long long sum = 0;
            for(int i=0;i<w.size();i++) sum += w[i];
            if(max < sum) max = sum;
        }
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define db(x) cout<<#x<<"="<<x<<endl
#define deb(x) each(x.begin(),x.end(),(int& y){cout << y <<" ";})
template<class T>bool maxi(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool mini(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;


void Main(){

  int N; cin>>N;

  int ans[N+1];

  reps(i,1,N+1){
    int a; cin>>a;
    ans[a]=i;
  }

  reps(i,1,N+1){
    cout<< ans[i] <<" ";
  }
  cout<<"\n";

}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 1280
#include <stdio.h>
#include <stdlib.h>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define max(l,r) ((l)>(r)?(l):(r))
#define min(l,r) ((l)<(r)?(l):(r))

int main(){
    int n; scanf("%d", &n);
    
    ll ans = (n==1?0:1);

    printf("%lld\n", ans);
    //rep(i, n) scanf("%lld", ans+i);
    //if(ans){ puts("YES"); rep(i,n) printf("%lld ", a[i]);}else puts("NO");
}


Measured memory_bytes: 1732
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        int max = 100;
        for (int i = 0 ; i < N ; i++) {
            int a = sc.nextInt();
            int count = 0;
            while (a % 2 == 0) {
                a /= 2;
                count++;
            }
            max = Math.min(max, count);
        }
        System.out.println(max);
    }

}

Measured memory_bytes: 22996
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>

using namespace std;

#define rep(i,a,b) for(int i=int(a),nn=int(b);i<=nn;++i)
#define vep(i,a,b) for(int i=int(a),nn=int(b);i>=nn;--i)
#define xep(i, b) for(int i=0,nn=int(b);i<nn;++i)

const int N = 500100;

int d[N], n, lw[N], ds[N], dis, qy;

inline void in(int &x) {
  	char c=getchar(); int f= 1;
	for (;c<'0'||c>'9';c=getchar()) f=(c=='-'?-1:f);
	for (x=0; c>='0'&&c<='9';c=getchar()) x=x*10+c-48;
	x *= f;
}
inline int go(int d, int x) {
  	return (d-x<0?x-d : d-x);
}
int main() {
	in(n), in(dis);
	rep(i, 1, n) in(d[i]);
	lw[n+1] = 1;
	vep(i, n, 1) {
	  	if (lw[i+1] <= d[i]/2)
		  	lw[i] = lw[i+1];
		else lw[i] = lw[i+1]+d[i];
	}
	ds[0] = dis;
	rep(i, 1, n) ds[i] = min(ds[i-1], go(ds[i-1],d[i]));
	in(qy); int q;
	while (qy--) {
	  	in(q);
		if (ds[q-1] < lw[q+1]) puts("NO");
		else puts("YES");
	}
	return 0;
}



Measured memory_bytes: 7808
def main():
    H, W = map(int, input().split())
    m = []
    m.append([True] * (W + 2))
    for _ in range(H):
        m.append([True] + [c == '#' for c in input()] + [True])
    m.append([True] * (W + 2))
    queue = []
    for i in range(1, H + 1):
        for j in range(1, W + 1):
            if m[i][j]:
                queue.append((i, j))
    ans = -1
    while queue:
        ans += 1
        tmp = []
        for x, y in queue:
            if not m[x - 1][y]:
                m[x - 1][y] = True
                tmp.append((x - 1, y))
            if not m[x + 1][y]:
                m[x + 1][y] = True
                tmp.append((x + 1, y))
            if not m[x][y - 1]:
                m[x][y - 1] = True
                tmp.append((x, y - 1))
            if not m[x][y + 1]:
                m[x][y + 1] = True
                tmp.append((x, y + 1))
        queue = tmp
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 105976
#include <stdio.h>
#define N 1000000000
#define M 500000

int cnt = 0, s[M];

void merge(int left, int mid, int right)
{
    int i, j, k;
    int n1 = mid - left, n2 = right - mid;
    int L[n1 + 1], R[n2 + 1];

    for (i = 0; i < n1; i++)
        L[i] = s[left + i];
    for (i = 0; i < n2; i++)
        R[i] = s[mid + i];
    L[n1] = R[n2] = N;
    i = j = 0;
    for (k = left; k < right; k++)
    {
        cnt++;
        if(L[i] <= R[j])
            s[k] = L[i++];
        else
            s[k] = R[j++];
    }
}

void mergesort(int left, int right)
{
    if (left + 1 < right)
    {
        int mid = (left + right) / 2;
        mergesort(left, mid);
        mergesort(mid, right);
        merge(left, mid, right);
    }
}

int main()
{
    int n, i;

    scanf("%d", &n);
    for (i = 0; i < n; i++)
        scanf("%d", &s[i]);
    mergesort(0, n);
    for (i = 0; i < n - 1; i++)
        printf("%d ", s[i]);
    printf("%d\n", s[i]);
    printf("%d\n", cnt);
    return 0;
}



Measured memory_bytes: 5600
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std;
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
int main() {
  int N,X;
  cin >> N >> X;
  if(N>X){
    cout << "safe";
  }
  else{
    cout << "unsafe";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define mem(ar,num) memset(ar,num,sizeof(ar))
#define me(ar) memset(ar,0,sizeof(ar))
#define lowbit(x) (x&(-x))
#define Pb push_back
#define  FI first
#define  SE second
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define IOS ios::sync_with_stdio(false)
#define DEBUG cout<<endl<<"DEBUG"<<endl; 
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int    prime = 999983;
const int    INF = 0x7FFFFFFF;
const LL     INFF =0x7FFFFFFFFFFFFFFF;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-6;
const LL     mod = 1e9 + 7;
LL qpow(LL a,LL b){LL s=1;while(b>0){if(b&1)s=s*a%mod;a=a*a%mod;b>>=1;}return s;}
LL gcd(LL a,LL b) {return b?gcd(b,a%b):a;}
int dr[2][4] = {1,-1,0,0,0,0,-1,1};
typedef pair<int,int> P;
LL MOD = 1e10;
const int maxn = 1e5+10;
P p[maxn];
int main(void)
{
	int N,M;
	int A,B;
	cin>>N>>M;
	priority_queue<P> Q;
	for(int i = 1;i <= N; ++i){
		// cout<<N<<endl;
		scanf("%d%d",&A,&B);
		// Q.push(P(B,A));
		p[i] = P(A,B);
	}
	int ans = 0;
	sort(p+1,p+N+1);
	int j  = 1;
	for(int i = M-1;i >= 0; --i){
		for(;j <= N; ++j){
			if(p[j].first + i <= M)
				Q.push(P(p[j].second,p[j].first));
			else
				break;
		}
	    if(Q.empty()) continue;
	    ans += Q.top().first;Q.pop();
	}
	cout<<ans<<endl;

   return 0;
}

Measured memory_bytes: 2168
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<set>


// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
//const int mod = 998244353;
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; }
    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 ans(1);

void  ch(int x, int y) {
	int cnt(0);
   
	while (1) {
		ans *= x;
		x--;
        //cout << cnt;
		cnt++;
        //cout << cnt << endl;
		if (cnt == y) {
			break;
		}
	}
    
	while (1) {
        ans /= y;
        y--;
        if (y == 0)break;
	}
}
int main() {
	int x, y;
	cin >> x >> y;
	int d = abs(x - y);
	int c = x + y;
   
    if (c % 3 != 0) {
        cout << 0;
        return 0;
    }
    c /= 3;
    
    int t = (c - d) / 2;
    if (t == 0) {
        cout << 1;
        return 0;
    }
    if (t < 0) {
        cout << 0;
        return 0;
    }
	ch(c, t);
    cout << ans;
	return 0;
}
//103078 214577


Measured memory_bytes: 3624
#include <stdio.h>
#include <string>
#include <iostream>

int main() {
    std::string s;
    std::cin >> s;
    for (int i = 1; i<s.length(); ++i) {
        if (s[i] == s[i-1]) {
            std::cout << "Bad" << "\n";
            return 0;
        }
    }
    std::cout << "Good" << "\n";
    return 0;
}


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

int main(){
int a,b,c;
int n ;
scanf("%d %d %d",&a,&b,&c);
if(a==b && b==c)  n=1;
else if(a==b ||b==c||c==a)n=2;
else n=3;
printf("%d",n);
return 0;

}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<stack>
using namespace std;
static const int NIL = -1;
static const int MAX = 100000;

int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r, int c) {
    stack<int> S;
    S.push(r);
    color[r] = c;
    while (!S.empty()) {
        int u = S.top(); S.pop();
        for (int i=0; i<G[u].size(); i++) {
            int v = G[u][i];
            if ( color[v] == NIL) {
                color[v] = c;
                S.push(v);
            }
        }
    }
}

void assignColor() {
    int id = 1;
    for ( int i = 0; i<n; i++) color[i] = NIL;
    for ( int u = 0; u<n; u++) {
        if (color[u] == NIL) dfs(u, id++);
    }
}

int main() {
    int s, t, m, q;

    cin >> n >> m;

    for ( int i=0; i<m; i++) {
        cin >>s >> t;
        G[s].push_back(t);
        G[t].push_back(s);
    }

    assignColor();

    cin >> q;

    for (int i=0; i<q; i++) {
        cin >> s >> t;
        if (color[s] == color[t]) {
            cout << "yes" <<endl;
        } else {
            cout << "no" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 8976
#include<iostream>
#include<string.h>
#include<math.h>

using namespace std;

int main(){

    int res,i,j,ans,ac=0,wa=0,tle=0,re=0,n,t;
    char s[1000001];
    cin >> n;
    while(n--){
        cin >> s;
        if(s[0]=='A') ac++;
        else if(s[0]=='T') tle++;
        else if(s[0]=='W') wa++;
        else re++;
    }
    cout << "AC x " << ac << "\n";
    cout << "WA x " << wa << "\n";
    cout << "TLE x " << tle << "\n";
    cout << "RE x " << re << "\n";
}


Measured memory_bytes: 3592
codes = input().split()

stack = []
for index in range(len(codes)):
    num_or_operator = codes[index]
    if num_or_operator.isdigit():
        stack.append(int(num_or_operator))
    else:
        rhs = stack.pop()
        lhs = stack.pop()
        if num_or_operator == "+":
            stack.append(lhs + rhs)
        elif num_or_operator == "-":
            stack.append(lhs - rhs)
        else:
            stack.append(lhs * rhs)

print(stack.pop())


Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=998244353;
const LL LINF=1ll<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};



int main(){
    LL n,x,m;cin >> n >> x >> m;
    if(n <= 1000000){
        LL ans = 0;
        LL a = x;
        for (int i = 0; i < n; i++) {
            ans += a;
            a = a * a % m;
        }
        cout << ans << endl;
    }
    else{
        vector<LL> a(1000001);
        a[0] = x;
        for (int i = 0; i < 1000000; i++) {
            a[i+1] = a[i] * a[i] % m;
        }
        vector<int> s(1000000, -1);
        LL l, r;
        for (int i = 0; i < 1000000; i++) {
            if(s[a[i]] != -1){
                l = s[a[i]];
                r = i;
                break;
            }
            else s[a[i]] = i;
        }
        LL ans = 0;
        for (int i = 0; i < l; i++) {
            ans += a[i];
        }
        LL rs = 0;
        for (int i = l; i < r; i++) {
            rs += a[i];
        }
        n -= l;
        LL t = r - l;
        LL q = n / t;
        ans += q * rs;
        n -= q * t;
        for (int i = 0; i < n; i++) {
            ans += a[l + i];
        }
        cout << ans << endl;
    }
    return 0;
}


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

#define INF 2e9
#define endl "\n"
#define mp make_pair

const int maxn = 12;

vector <vector <int> > pond(maxn, vector <int> (maxn, 0)); 
vector <vector <int> > moves(maxn, vector <int> (maxn, INF));
vector <vector <bool> > visited(maxn, vector <bool> (maxn, false));

int h, w, k;
int x, y, xx, yy;

bool valid(int row, int col){
	return (row >= 0 and row < h and col >= 0 and col < w and pond[row][col] == 1);
}

void bfs(int source_row, int source_col){
	moves[source_row][source_col] = 0;
	queue <pair <int, int> > q;
	q.push(mp(source_row, source_col));

	while (!q.empty()){
		int now1 = q.front().first;
		int now2 = q.front().second;
		q.pop();
		visited[now1][now2] = true;

		for (int i=1; i<=k; i++){
			
			int row = now1;
			int col = i + now2;

			if (valid(row, col) == false or moves[row][col] < moves[now1][now2] + 1) break;
			if (visited[row][col] == false){
				q.push(mp(row, col));
				visited[row][col] = true;
				moves[row][col] = moves[now1][now2] + 1;
			}
		}

		for (int i=1; i<=k; i++){
			
			int row = now1;
			int col = now2 - i;

			if (valid(row, col) == false or moves[row][col] < moves[now1][now2] + 1) break;
			if (visited[row][col] == false){
				q.push(mp(row, col));
				visited[row][col] = true;
				moves[row][col] = moves[now1][now2] + 1;
			}
		}

		for (int i=1; i<=k; i++){
			
			int row = now1 - i;
			int col = now2;

			if (valid(row, col) == false or moves[row][col] < moves[now1][now2] + 1) break;
			if (visited[row][col] == false){
				q.push(mp(row, col));
				visited[row][col] = true;
				moves[row][col] = moves[now1][now2] + 1;
			}
		}

		for (int i=1; i<=k; i++){
			
			int row = now1 + i;
			int col = now2;

			if (valid(row, col) == false or moves[row][col] < moves[now1][now2] + 1) break;
			if (visited[row][col] == false){
				q.push(mp(row, col));
				visited[row][col] = true;
				moves[row][col] = moves[now1][now2] + 1;
			}
		}
	}
}

int main ()
{
	
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //#define int ll

	cin >> h >> w >> k;
	cin >> x >> y >> xx >> yy;
	
	vector <vector <int> > aaa(h+5, vector <int> (w+5, 0)); 
	vector <vector <int> > hhh(h+5, vector <int> (w+5, INF));

	for (int i=0; i<h; i++){
		for (int j=0; j<w; j++){
			char c;
			cin >> c;
			if (c == '.')
			aaa[i][j] = 1;
			else aaa[i][j] = 0;
			hhh[i][j] = INF;
		}
	}

	swap(aaa, pond);
	swap(hhh, moves);
	vector <vector <bool> > ww(h, vector <bool> (w, false));
	swap(visited, ww);
	
	
	x--;
	xx--;
	y--;
	yy--;

	

	bfs(x, y);


	if (moves[xx][yy] == INF){
		cout << -1 << endl;
	}

	else cout << moves[xx][yy] << endl;

		   
	return 0;
}

Measured memory_bytes: 54016
def main():
    cards = {i: input() for i in 'abc'}
    # cards = {'a': '', 'b': '', 'c': ''}
    # 
    # cards['a'] = input()
    # cards['b'] = input()
    # cards['c'] = input()

    current = 'a'
    # next = ''

    while True:
        if not cards[current]:
            print(current.upper())
            return
        next = cards[current][0]
        cards[current] = cards[current][1:]
        current = next

if __name__ == "__main__":

    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    string s, t;
    cin >> s  >> t;
    int c = 0;
    rep(i, s.size()) {
        if (s[i] != t[i]) c++;
    }
    println(c)
    return 0;
}

Measured memory_bytes: 3920
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <vector>
#include <chrono>
#include <cstdlib>
#include <bitset>
using namespace std;

int main(){
    string s; 
    cin >> s;
    if(s ==  "Sunny") cout << "Cloudy" << endl;
    else if(s == "Cloudy") cout << "Rainy" << endl;
    else cout << "Sunny" << endl;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const ll mod = 1e9+7;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  s.resize(s.size() - 8);
  std::cout << s << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ls id << 1
#define rs id << 1 | 1
#define mem(array, value, size, type) memset(array, value, ((size) + 5) * sizeof(type))
#define memarray(array, value) memset(array, value, sizeof(array))
#define pb(x) push_back(x)
#define st(x) (1LL << (x))
#define pii pair<int, int>
#define mp(a, b) make_pair((a), (b))
#define Flush fflush(stdout)
using namespace std;
const int N = 500050;
const int inf = 0x3f3f3f3f;
const ll llinf = 0x3f3f3f3f3f3f;
const ll mod = 998244353LL;
clock_t TIME_START, TIME_END;
void program_end()
{
#ifdef ONLINE
    printf("\nTime used: %.6lf(s)\n", ((double)TIME_END - TIME_START) / CLOCKS_PER_SEC);
    system("pause");
#endif
}
int n;
int a[2050];
ll ans;
ll sum[4050];

void solve()
{
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> a[i], sum[a[i]]++;
    for (int i = 1; i <= 4000; ++i)
        sum[i] += sum[i - 1];
    for (int i = 1; i <= n; ++i)
        for (int j = i + 1; j <= n; ++j)
        {
            ans += sum[a[i] + a[j] - 1] - sum[abs(a[i] - a[j])] - (a[i] > abs(a[i] - a[j])) - (a[j] > abs(a[i] - a[j]));
        }
    cout << ans / 3;
}

int main()
{
    TIME_START = clock();
    int Test = 1;
    // cin >> Test;
    while (Test--)
        solve();
    TIME_END = clock();
    program_end();
    return 0;
}

Measured memory_bytes: 3672
import java.util.Scanner;

public class Main {

    public static void main(final String[] args) {
        final Scanner sc = new Scanner(System.in);
        int paramN = sc.nextInt();
        int paramY = sc.nextInt();
        System.out.println(judgeOtoshidama(paramN, paramY));
        sc.close();
    }

    public static String judgeOtoshidama(int N, int Y){
        for(int cnt10=0; cnt10<=N; cnt10++){
            for(int cnt5=0; cnt5<=N-cnt10; cnt5++){
                int cnt1 = N - (cnt10 + cnt5);
                if(Y == (cnt10 * 10000 + cnt5 * 5000 + cnt1 * 1000)){
                    return cnt10 + " " + cnt5 + " " + cnt1;
                }
            }
        }
        return "-1 -1 -1";
    }
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<vector<int>> a(n+1);
    for(int i = 2; i <= n; i++)
    {
        int d;
        cin >> d;
        a[d].push_back(i);
    }
    vector<int> dp(n+1);

    function<int(int)> dfs = [&](int v)
    {
        if(a[v].empty())
        {
          return dp[v] = 0;
        }
        vector<int> tmp;
        for(int child : a[v])
        {
            tmp.push_back(dfs(child));
        }
        sort(tmp.begin(), tmp.end());
        reverse(tmp.begin(), tmp.end());
        int high = 0;
        for(int i = 0; i < a[v].size(); i++)
        {
            high = max(high, tmp[i] + i+1);
        }
        return dp[v] = high;
    };
    dfs(1);
    cout << dp[1] << endl;
}


Measured memory_bytes: 17024
#include<stdio.h>
#define N 251
int A[N];
int main(){
  int total,i;
  scanf("%d",&total);
  for(i=1;i<=total;i++){
    scanf("%d",&A[i]);
  }
  for(i=1;i<=total;i++){
    printf("node %d: ",i);
    printf("key = %d, ",A[i]);
    if(i!=1)printf("parent key = %d, ",A[i/2]);
    if(i*2<=total)printf("left key = %d, ",A[i*2]);
    if(i*2+1<=total)printf("right key = %d, ",A[i*2+1]);
    printf("\n");
  }
  return 0;
}




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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    string s;
    getline(cin, s);

    while (s.find("apple") != string::npos)
    {
        int a = s.find("apple");
        s.replace(a, 5, "00000");
    }
    while (s.find("peach") != string::npos)
    {
        int p = s.find("peach");
        s.replace(p, 5, "11111");
    }

    while (s.find("00000") != string::npos)
    {
        int a = s.find("00000");
        s.replace(a, 5, "peach");
    }
    while (s.find("11111") != string::npos)
    {
        int p = s.find("11111");
        s.replace(p, 5, "apple");
    }

    OP(s);

    return 0;
}


Measured memory_bytes: 3032
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if(n==0 && m==0) break;
			
			int[][] map = new int[n][n];
			for(int i=0;i<n;i++) Arrays.fill(map[i], Integer.MAX_VALUE);
			int p, q;
			for(int i=0;i<m;i++){
				p = sc.nextInt();
				q = sc.nextInt();
				map[p][q] = sc.nextInt();
				map[q][p] = map[p][q];
			}
			
			ArrayList<Integer> list = new ArrayList<Integer>();
			list.add(0);
			int sum = 0;
			int r = 0;
			for(int i=1;i<n;i++){
				q = Integer.MAX_VALUE;
				for(int j=0;j<i;j++){
					p = list.get(j);
					for(int k=0;k<n;k++){
						if(list.contains(k)==false && q>map[p][k]){
							q = map[p][k];
							r = k;
						}
					}
				}
				list.add(r);
				sum += q;
			}
			
			System.out.println(sum);
		}	
	}	
}

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

int main(){
  int n;
  cin >> n;
  vector<long long> a(n);
  long long sum = 0;
  const long long MOD = 1000000007;

  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
    sum += a[i];
  }
  sum%=MOD;

  long long ans = 0;
  for (int i = 0; i < n-1; i++)
  {
    sum+=MOD - a[i];
    sum%=MOD;
    long long add = (a[i]*sum)%MOD;
    ans+=add;
    ans%=MOD;
  }
  cout << ans << endl;
}

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

int main() {
  int L,R,d;
  cin >> L >> R >> d;
  if(L%d != 0)cout << R/d - L/d << endl;
  if(L%d == 0)cout << R/d - L/d + 1 << endl;
  return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main()
{
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    ll ans = 0;
    ll num = min(a, k);
    ans += num;
    if(a >= k)
    {
        cout << ans << endl;
        return 0;
    }
    k -= num;
    num = min(b, k);
    if(b >= k)
    {
        cout << ans << endl;
        return 0;
    }
    k -= num;
    cout << ans - k << endl;
}


Measured memory_bytes: 3640
function main(arg) {
	arg = arg.split("\n")[1].split(" ").map(e => Number(e))
	var sum = 0
	for (var i = 0; i < arg.length; i++) {
		sum += arg[i]
	}
	var avg = sum / arg.length

	var n_min
	var n = 0

	for (var i = 0; i < arg.length; i++) {
		if (i ===0 ) {
			n = i
			n_min = Math.abs(arg[i] - avg)
			continue;
		}

		if (Math.abs(arg[i] - avg) < n_min) {
			n = i
			n_min = Math.abs(arg[i] - avg)
		}
	}

	console.log(n)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
<?php

fscanf(STDIN, "%d", $n);
$pri = array_fill(0, 100, 0);
for ($i = 1; $i <= $n; ++$i) {
    $tmp = $i;
    $is_prime = true;
    for ($j = 2; $j <= sqrt($tmp); ++$j) {
        if ($i % $j == 0) {
            $is_prime = false;
            // jは約数
            $ex = 0;
            while ($tmp % $j == 0) {
                $tmp /= $j;
                ++$ex;
            }
            $pri[$j] += $ex;
        }
    }
    if ($tmp != 1) ++$pri[$tmp];
}

function num($m) {
    global $pri;
    $cnt = 0;
    foreach ($pri as $key => $val) {
        if ($val >= $m - 1) ++$cnt;
    }
    return $cnt;
}

echo num(75) + num(25) * (num(3) - 1) + num(15) * (num(5) - 1) + num(5) * (num(5) - 1) * (num(3) - 2) / 2;


Measured memory_bytes: 16064
from operator import itemgetter

h, n = map(int, input().split())
ABs = [list(map(int, input().split())) for i  in range(n)] 

#  dp[i][h] 最初の i 種類の魔法でモンスターに h のダメージを与える場合の、消費魔力の最小値
dp = [[10**9]*(h+1)]*(n+1)
dp[0][0] = 0

for i in range(n):
    for j in range(h):
        a = ABs[i][0]
        b = ABs[i][1]
        # i種類目の魔法を使わない場合
        dp[i+1][j] = min(dp[i][j], dp[i+1][j])

        # i種類目の魔法を使う場合
        #min(j+A[i], H) -> hより大きいダメージを与える場合は、与えるダメージをhとして計算する。
        # dp[i+1][j] + b -> i+1種類目の魔法を使った場合の消費魔力
        dp[i+1][min([j+a,h])] = min([ dp[i+1][j] + b, dp[i+1][min([j+a,h])] ])

print(min([row[j+1] for row in dp]))

Measured memory_bytes: 45356
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
      // 積が奇数なら Odd と、 偶数なら Even と出力  
      if((a*b)%2 == 0){
		System.out.println("Even");
	   }else {
        System.out.println("Odd");
       }
    }
}

Measured memory_bytes: 35728
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x)+modulo)%modulo)
#define Inf 1000000000000

int main() {
	
	int N,M;
	cin>>N>>M;
	
	int dp[3001][3001][2];
	
	for(int i=0;i<3001;i++){
		for(int j=0;j<3001;j++){
			for(int k=0;k<2;k++){
				dp[i][j][k] = 0;
			}
		}
	}
	
	dp[0][0][1] = 1;
	for(int i=1;i<=N;i++){
		dp[0][i][0] = 1;
	}
	
	for(int i=0;i<M;i++){
		for(int j=0;j<=N;j++){
			for(int k=0;k<2;k++){
				if(dp[i][j][k]==0)continue;
				int R = j;
				int B = N-j;
				
				if(R>0){
					if(j==1){
						dp[i+1][j][1] = mod(dp[i+1][j][1] + dp[i][j][k]);
						dp[i+1][j-1][1] = mod(dp[i+1][j-1][1] + dp[i][j][k]);
					}
					else{
						dp[i+1][j][k] = mod(dp[i+1][j][k] + dp[i][j][k]);
						dp[i+1][j-1][k] = mod(dp[i+1][j-1][k] + dp[i][j][k]);
					}
				}
				if(B>0){
					dp[i+1][j][k] = mod(dp[i+1][j][k] + dp[i][j][k]);
					dp[i+1][j+1][k] = mod(dp[i+1][j+1][k] + dp[i][j][k]);
				}
			}
		}
	}
	
	int ans = 0;
	
	for(int i=0;i<=N;i++){
		ans = mod(ans + dp[M][i][1]);
	}
	
	
	cout<<ans<<endl;
	
    return 0;
}


Measured memory_bytes: 70656
#include<stdio.h>
#include<string.h>
int out_cnt;
int base[4];
int point;
//■HITの処理
void hit()
{
	int temp[4];
	for(int f1=0;f1<3;f1++){
		temp[f1+1]=base[f1];
	}
	for(int f1=0;f1<4;f1++){
		base[f1]=temp[f1];
	}
	base[0]=1;
	if(base[3]==1){
		point++;
		base[3]=0;
	}
}
//■HOMERUNの処理
void homerun()
{
	for(int f1=0;f1<3;f1++){
		if(base[f1]==1){
			base[f1]=0;
			point++;
		}
	}
	point++;
}
//■OUTの処理
void out()
{
	out_cnt++;
}
//■データの表示
void show()
{
	printf("一塁:%d 二塁%d 三塁%d\n",base[0],base[1],base[2]);
	printf("得点:%d アウト数:%d\n",point,out_cnt);
}
//■メイン関数
int main(void)
{
	int inning;
	scanf("%d",&inning);
	while(inning>0){
		char temp[10];
		scanf("%s",temp);
		if(strcmp(temp,"HIT")==0){
			hit();
		}
		else if(strcmp(temp,"HOMERUN")==0){
			homerun();
		}
		else{
			out();
		}
		if(out_cnt==3){
			printf("%d\n",point);
			inning--;
			out_cnt=0;
			point=0;
			for(int f1=0;f1<4;f1++){
				base[f1]=0;
			}
		}
		//show();
	}
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(){
    int x,i,n;
    scanf("%d",&n);
    for(i=1; i<=n; i++){
        x = i;
        if(x%3==0){
            printf(" %d",i);
        }else if(x%10==3){
            printf(" %d",i);
        }else{
            while(x!=0){
                x=x/=10;
                if(x%10==3){
                    printf(" %d",i);
                    break;
                }
            }
        }
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2104
#include <stdio.h>
#define M 100000

int parent (int);
int left (int);
int right (int);

int main () {
  int h, i, a[M+1];

  scanf("%d", &h);
  for(i = 1 ; i <= h ; i++) {
    scanf("%d", &a[i]);
  }

  for(i = 1 ; i <= h ; i++) {
    printf("node %d: key = %d, ", i, a[i]);
    if(parent(i) >= 1) printf("parent key = %d, ", a[parent(i)]);
    if(left(i) <= h) printf("left key = %d, ", a[left(i)]);
    if(right(i) <= h) printf("right key = %d, ", a[right(i)]);
    printf("\n");
  }

  return 0;
}

int parent (int i) {
  return i / 2;
}

int left (int i) {
  return 2 * i;
}

int right (int i) {
  return 2 * i + 1;
}

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

// See debug.cc for usage etc
#define DEBUG 0

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#if DEBUG
  #define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
  #define DCALL(func, ...) func(__VA_ARGS__)
#else
  #define DLOG(...)
  #define DCALL(func, ...)
#endif

ll mPrime = int(1e9) + 7;
ll N;
vector<ll> tbl0(64);

inline int enc(int j1, int j2, int j3) { return 16*j1 + 4*j2 + j3; }

void mAdd(ll& x, ll y) {
  x = (x + y) % mPrime;
}

const int iA = 0;
const int iG = 1;
const int iC = 2;
const int iT = 3;

int main() {
#if !DEBUG
  ios_base::sync_with_stdio(false);
#endif

  cin >> N;
  vector<ll> src(tbl0);
  vector<ll> dest(tbl0);
  dest.at(enc(iT,iT,iT)) = 1;

  for (int i = 0; i < N; i++) {
    src = dest;
    dest = tbl0;

    for (int j1 = 0; j1 < 4; j1++) {
      for (int j2 = 0; j2 < 4; j2++) {
	for (int j3 = 0; j3 < 4; j3++) {
	  for (int j4 = 0; j4 < 4; j4++) {
	    if (j2 == iA && j3 == iG && j4 == iC) continue;
	    if (j2 == iA && j3 == iC && j4 == iG) continue;
	    if (j2 == iG && j3 == iA && j4 == iC) continue;
	    if (j1 == iA && j2 == iG && j4 == iC) continue;
	    if (j1 == iA && j3 == iG && j4 == iC) continue;
	    mAdd(dest.at(enc(j2,j3,j4)), src.at(enc(j1,j2,j3)));
	  }
	}
      }
    }
  }
  ll ans = 0;
  for (int j1 = 0; j1 < 4; j1++) {
    for (int j2 = 0; j2 < 4; j2++) {
      for (int j3 = 0; j3 < 4; j3++) {
	mAdd(ans, dest.at(enc(j1,j2,j3)));
      }
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M = map(int, readline().split())
AB = [tuple(map(int, readline().split())) for _ in range(N)]

AB.sort()

ans = 0
while M != 0:
    for yen, cnt in AB:
        ans += yen * min(cnt, M)
        M -= min(cnt, M)
print(ans)

Measured memory_bytes: 17068
S = input()

if S[0] != 'A':
        print("WA")
        exit()


if not S[1].islower() or not (S[-1].islower()):
        #wether second charcter lowercase 
        print("WA")
        exit()


flag = False
for i in range(2, len(S)-1):
        if flag == True and S[i] == "C":
                print("WA")
                exit()
        if flag == False and S[i] == "C":
                flag = True
                continue
        if not S[i].islower():
                print("WA")
                exit()
if flag:
        print("AC")
else:
        print("WA")

Measured memory_bytes: 38384