akhauriyash/Code-Regression huggingface dataset:
//set many funcs template
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}

int main(void){
    int x,a,b,c,d,i,j,k,p;
    char s[4]="+-";
    scanf("%d",&x);
    d=x%10;x/=10;
    c=x%10;x/=10;
    b=x%10;x/=10;
    a=x%10;
    for(i=0;i<=1;i++){
        for(j=0;j<=1;j++){
            for(k=0;k<=1;k++){
                p=a;
                if(i==0){p+=b;}else{p-=b;}
                if(j==0){p+=c;}else{p-=c;}
                if(k==0){p+=d;}else{p-=d;}
                if(p==7){printf("%d%c%d%c%d%c%d=7\n",a,s[i],b,s[j],c,s[k],d);return 0;}
            }
        }
    }
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>

int main(void) {
    int n;
    std::scanf("%d", &n);
    int a[n];
    for (int i = 0; i < n; i++) {
        std::scanf("%d", a + i);
    }
    std::sort(a, a + n, std::greater<int>());
    for (int i = 0; i < n - 1; i++) {
        if (a[i] == a[i + 1]) {
            for (int j = i + 2; j < n - 1; j++) {
                if (a[j] == a[j + 1]) {
                    std::printf("%lld\n", (long long)a[i] * a[j]);
                    return 0;
                }
            }
        }
    }
    std::puts("0");
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define int long long int
#define pb push_back
#define BOOST ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define debugL(i)  cout<<"line no-> "<<i<<" working"<<endl
#define debugVL(i,l)  cout<<"val at line no."<<i<< " ->"<<l<<endl
#define  init(st,et,val,arr) for(int i=st;i<=et;i++)arr[i]=val;
//LLONG_MAX
const int M=1e9 + 7;
const int MAX=1e5+7;
using namespace std;
struct node{
	int l,r,v;
};
int32_t main() 
{
	BOOST;
	int n;cin>>n;
	int* a=new int[n];
	for(int i=0;i<n;i++)cin>>a[i];
	int ans=0;
	for(int i=0;i<n;i++)
	{
	    for(int j=i+1;j<n;j++)
	    {
	    	ans+=(a[i]*a[j]);
		}
	}
	cout<<ans<<endl;
	return 0;
}
 















 
 

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

ll N,W,iw,iv;
ll DP[101][100001];
ll max(ll a, ll b) {
  if (a>b) return a; return b;
}

int main() {
  cin >> N >> W;
  rep(i,N) {
    cin >> iw >> iv;
    rep(w,W+1) {
      if (w < iw) {
        DP[i+1][w] = DP[i][w];
      } else {
        DP[i+1][w] = max(DP[i][w], DP[i][w - iw] + iv);
      }
    }
  }
  cout << DP[N][W] << endl;
}

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

using namespace std;

int main()
{
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
  }
  int count=0;
  for(int i=0;i<n;i++)
  {
    if(a[i]==a[i+1])
    {
      count++;
      i++;
    }
  }
  cout<<count<<endl;
  return 0;
}


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

using namespace std;
 
//#define int long long
using ll = long long;
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define reps(i,n) for(ll i=0;i<=n;i++)


ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
 
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

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

    ll ans,mini=INF;
    string s,t;

    cin >> s >> t;

    for(int i=0;i<=(s.size()-t.size());i++){
        ans=0;
        for(int j=0;j<t.size();j++){
            if(s[j+i]!=t[j]){
                ans++;
            }
        }
        mini = min(ans,mini);
    }

    cout << mini << endl;

    return 0;
}


Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define fr(i,n) for(i=0;i<n;i++)
#define F first
#define S second
#define endl "\n"
#define fast std::ios_base::sync_with_stdio(false)
#define mod 1000000007
#define pi 3.14159265
#define sl(a) (int)a.length()
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
void shikhar7s(int cas)
{
    int n,k;
    cin>>k>>n;
    if(k*500>=n)
        cout<<"Yes";
    else
        cout<<"No";
}
signed main()
{
    fast;
    int t=1;
    //cin>>t;
    int cas=1;
    while(cas<=t)
    {
    shikhar7s(cas);
    cas++;
    }
    return 0;
}

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

int main(){
    string a,b,c;
    cin >>a>>b>>c;
    cout <<(char)toupper(a[0])<<(char)toupper(b[0])<<(char)toupper(c[0])<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n, t, a;
    cin >> n >> t >> a;
    t *= 1000;
    a *= 1000;

    int ans = 0, mi = 1e9;
    REP(i,n){
        int h = in();
        int x = t - 6 * h;
        if (abs(x - a) < mi){
            mi = abs(x - a);
            ans = i;
        }
    }
    cout << ans + 1 << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int dp[50];

int fibonacci(int n){
  if(n == 0 || n == 1){
    return dp[n] = 1;
  }
  if(dp[n] != -1){
    return dp[n];
  }
  return dp[n] = fibonacci(n-2) + fibonacci(n-1);
}

int main(){
  int n,i;
  for(i = 0;i < 50; i++){
    dp[i] = -1;
  }

    scanf("%d",&n);
    printf("%d\n",fibonacci(n));
    return 0;
  }

Measured memory_bytes: 596
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int H = sc.nextInt();
			final int W = sc.nextInt();
			final int K = sc.nextInt();
			
			int[][] map = new int[H][W];
			
			{
				int id = 1;
				for(int i = 0; i < H; i++) {
					char[] chs = sc.next().toCharArray();
					for(int j = 0; j < W; j++) {
						map[i][j] = chs[j] == '#' ? id++ : 0;
					}
				}
			}
			
			for(int i = 0; i < H; i++) {
				for(int j = 1; j < W; j++) {
					if(map[i][j] != 0) { continue; }
					map[i][j] = map[i][j - 1];
					
				}
				for(int j = W - 2; j >= 0; j--) {
					if(map[i][j] != 0) { continue; }
					map[i][j] = map[i][j + 1];
				}
			}
			
			for(int j = 0; j < W; j++) {
				for(int i = 0; i < H - 1; i++) {
					if(map[i + 1][j] != 0) { continue; }
					map[i + 1][j] = map[i][j];
				}
				for(int i = H - 1; i >= 1; i--) {
					if(map[i - 1][j] != 0) { continue; }
					map[i - 1][j] = map[i][j];
				}

			}
			
			for(int i = 0; i < H; i++) {
				for(int j = 0; j < W; j++) {
					System.out.print((j == 0 ? "" : " ") + map[i][j]);
				}
				System.out.println();
			}
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 48788
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(_,v.size())cout<<" "<<v[_];cout<<endl;
#define show2d(v) rep(__,v.size()){rep(_,v[__].size())cout<<" "<<v[__][_];cout<<endl;}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};

//nCr mod m
#define MOD 1000000007
#define M 1000000
vector<ll> fact;
bool h=false;
void init(){
	h=true;
	fact=vector<ll>(M);
	fact[0]=fact[1]=1;
	loop(i,2,M)fact[i]=fact[i-1]*i%MOD;
}
// a^b mod MOD
ll powmod(ll a,ll b,ll m=MOD){
	ll out=1;
	ll p=a%m;
	while(b){
		if(b&1)out=out*p%m;
		p=p*p%m;
		b>>=1;
	}
	return out;
}
//nCr
ll nCr(ll n,ll r,ll m=MOD){
	if(!h)init();
	if(n<0||r<0||n<r)return 1;//??????
	ll out=fact[n]*powmod(fact[r]*fact[n-r]%m,m-2,m)%m;
	return out;
}
signed main(){
	int out=0,sum=1;
	int n,m,k;
	cin>>n>>m>>k;
	
	loop(i,n-1,n+m+k){
		int t=powmod(3,n+m+k-i-1)*nCr(i,n-1)%MOD;
		(out+=t*sum)%=MOD;
		
		int w=i+1-n;
		(sum*=2)%=MOD;
		if(w>=m)(sum+=MOD-nCr(w,m))%=MOD;
		if(w>=k)(sum+=MOD-nCr(w,k))%=MOD;
	}
	cout<<out<<endl;
}















Measured memory_bytes: 8064
import numpy as np

n, m = map(int, input().split())
suc = np.array([0]*(n+1))
pen = np.array([0]*(n+1))

for _ in range(m):
    p, s = input().split()
    p = int(p)

    if suc[p] == 0 and s == "WA":
        pen[p] += 1
    else:
        suc[p] = 1

print(sum(suc), sum(suc*pen))


Measured memory_bytes: 14784
// AOJ ALDS1_6_A Counting Sort
// 2018.4.27 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

char buf[20];
void mypr(int n)
{
	int i = 0;
	if (n == 0) buf[i++] = '0';
	else while (n) buf[i++] = n%10 + '0', n/=10;
	while (i) pc(buf[--i]);
}

// 計数ソート（整数用）昇順
#define MAX_N 10002
int f[MAX_N];

void counting_sort(int n, int *a, int *b, int max)
{
	int i, x;
//	memset(f, 0, sizeof(f));
	for (i = 0; i < n; i++) f[a[i]]++;
	for (i = 1; i <= max; i++) f[i] += f[i-1];
	for (i = n-1; i >= 0; i--) {
		x = a[i], b[--f[x]] = a[i];
	}
}

int a[2000002], b[2000002];

int main()
{
	int N, i;

	N = in();
	for (i = 0; i < N; i++) a[i] = in();
	counting_sort(N, a, b, 10000);
	mypr(b[0]);
	for (i = 1; i < N; i++) pc(' '), mypr(b[i]);
	pc('\n');
	return 0;
}



Measured memory_bytes: 17224
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int road1[111][111];
  int road2[111][111];
  int n,m;
  int a,b,cost,time;
  int p,q,r;
  int x;
  while(1){
    for(int i=0;i<111;i++){
      for(int j=0;j<111;j++){
	road1[i][j]=road2[i][j]=111111111;
      }
    }
    cin >> n >> m;
    if(n==0 && m==0)break;
    for(int i=0;i<n;i++){
      cin >> a >> b >> cost >> time;
      road1[a][b]=road1[b][a]=cost;
      road2[a][b]=road2[b][a]=time;
    }

    for(int k=1;k<=m;k++){
      for(int i=1;i<=m;i++){
	for(int j=1;j<=m;j++){
	  if(road1[i][j]>road1[i][k]+road1[k][j]){
	    road1[i][j]=road1[i][k]+road1[k][j];
	  }
	  if(road2[i][j]>road2[i][k]+road2[k][j]){
	    road2[i][j]=road2[i][k]+road2[k][j];
	  }
	}
      }
    }
    
    cin >> x;
    for(int i=0;i<x;i++){
      cin >> p >> q >> r;
      cout << (r==0 ? road1[p][q] : road2[p][q]) << endl;
    }
  }
}

Measured memory_bytes: 1252
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define sign(a) ((a>0)-(a<0))

void solve(long long N, long long M, std::vector<long long> x, std::vector<long long> y, std::vector<long long> z){
    LL ans=0;
    for(int i=0; i<8; i++){
        vector<int> d(3);
        for(int j=0; j<3; j++)d[j]=2*((i>>j)&1)-1;

        vector<pair<LL, LL>> ps(N);
        for(LL j=0; j<N; j++){
            auto tmp = d[0]*x[j]+d[1]*y[j]+d[2]*z[j];
            ps[j]=make_pair(tmp, j);
        }

        auto tmp=0ll;
        sort(ps.begin(), ps.end(), greater<pair<LL, LL>>());

        vector<LL> total(3, 0);
        for(LL j=0; j<M; j++){
            auto ind = ps[j].second;
            total[0]+=x[ind];
            total[1]+=y[ind];
            total[2]+=z[ind];
        }

        ans = max(ans, abs(total[0])+abs(total[1])+abs(total[2]));
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> x(N);
    std::vector<long long> y(N);
    std::vector<long long> z(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&x[i]);
        scanf("%lld",&y[i]);
        scanf("%lld",&z[i]);
    }
    solve(N, M, std::move(x), std::move(y), std::move(z));
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stdio.h>

const int Max = 1000;

void view(int A[],int N){
	std::cout<<A[0];
	for(int i=1;i < N;i++){
		std::cout<<" "<<A[i];
	}
	std::cout << std::endl;
}

int Bubble_sort(int A[],int N){
	int sw=0;
	bool flag=true;
	for(int i=0;flag;++i){
		flag=false;
		for(int j=N-1;j >= i+1;j--){
			if(A[j]<A[j-1]){
				std::swap(A[j],A[j-1]);
				++sw;
				flag=true;
			}
		}
	}
	return sw;
}


int main(){
	int N,R[Max];
	
	std::cin>>N;
	for(int i=0;i<N;i++)
		scanf("%d",&R[i]);

	int sw = Bubble_sort(R,N);
	view(R,N);
	std::cout<<sw<<std::endl;

	return 0;
}

Measured memory_bytes: 1248
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AOJ_ITP_1_1_D
{
    class Program
    {
        static void Main(string[] args)
        {
            int x = int.Parse(Console.ReadLine());
            int h, m, s;
            s = x % 60;
            m = x / 60;
            h = m / 60;
            m = m % 60;
            Console.WriteLine(h + ":" + m + ":" + s);
        }
    }
}



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

using namespace std;
typedef long long ll;

struct A{
    int cnt, idx;
    A(){
        cnt = 0;
    }
}x[300001], y[300001];

bool cmp(A a, A b){
    return a.cnt > b.cnt;
}

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

    int h, w, m;
    cin >> h >> w >> m;
    int p, q;
    unordered_set<ll> us;
    while(m--){
        cin >> p >> q;
        ++x[p].cnt;
        ++y[q].cnt;
        us.insert(ll(p) * 4 * 100000 + ll(q));
    }
    for(int i = 1; i <= h; ++i)
        x[i].idx = i;
    for(int i = 1; i <= w; ++i)
        y[i].idx = i;
    sort(x + 1, x + h + 1, cmp);
    sort(y + 1, y + w + 1, cmp);
    int i = 1, j = 1;
    int xmax = x[1].cnt, ymax = y[1].cnt;
    for(i = 1; x[i].cnt == xmax && i <= h; ++i)
        for(j = 1; y[j].cnt == ymax && j <= w; ++j){
            if(!us.count(ll(x[i].idx) * 4 * 100000 + ll(y[j].idx))){
                cout << xmax + ymax << "\n";
                return 0;
            }
        }
    if(xmax + ymax > 0)
        cout << xmax + ymax - 1 << "\n";
    else
        cout << 0 << "\n";
    return 0;
}


Measured memory_bytes: 21908
#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;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/*
    s.find_by_order(k) ---> returns iterator to the element at index(from 0) k
    s.order_of_key(val) ---> number of elements that are strictly smaller than the given value
*/
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvl;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long int, long long int>> vll;
#define fastIO() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test() long long int tc; cin >> tc; cin.ignore(); while(tc--) 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define MOD 1000000007
#define SMOD 998244353
#define HASH 18014398241046527
#define pq priority_queue
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sp " "
#define inp(a) ll a;cin>>a;cin.ignore()
#define inps(a,b) ll a,b;cin>>a>>b;cin.ignore()
#define out(a) cout<<SP(20)<<a<<'\n'
#define outs(a,b) cout<<SP(20)<<a<<" "<<b<<'\n'
#define ins insert
#define er erase
#define lb lower_bound
#define ub upper_bound
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define inpa(a,n) ll a[n]; for(int i=0; i<n; i++){cin>>a[i];}
#define inpv(a,n) vl a; for(int i=0; i<n; i++){inp(x);a.pb(x);}
#define outa(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<'\n';
#define outv(v) for(auto i:v){cout<<i<<" ";}cout<<'\n';
set<char> vow = {'a','e','i','o','u','A','E','I','O','U'};
ll xpow(ll n, ll m){if(m==0){return 1;}else{ll x = xpow(n, m/2);if(m&1){return x*x*n;}else{return x*x;}}}
ll xmod(ll a, ll m){return (((a%m)+m)%m);}
ll xmodpow(ll n, ll m, ll y){if(m==0){return 1;}else{ll x = xmodpow(n, m/2, y);if(m&1){return xmod((xmod((xmod(x,y)*xmod(x,y)),y)*xmod(n,y)),y);}else{return xmod((xmod(x,y)*xmod(x,y)),y);}}}
template <typename T>
ll SIZEOF(T a){return (ll)a.size();}
ll xlcm(ll a, ll b){return (a/__gcd(a, b))*b;}

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


const int N = 100005;


void SOLVE(){
    ll n;
    cin >> n;
    ll curr = 0;
    ll ans = 0;
    for(ll i=0; i<n; i++){
        ll x;
        cin >> x;
        if(x<curr){
            ans += (curr-x);
        }
        else{
            curr = x;
        }
    }
    cout << ans << '\n';
}

int main() {
	fastIO();
	// #ifndef ONLINE_JUDGE
    //     freopen("i.txt", "r", stdin);
    //     freopen("o.txt", "w", stdout);
	// #endif

    ll TC = 1;
    // cin >> TC;
    for(ll tc1=1; tc1<=TC; tc1++){
        // cout << "Case #" << tc1 << ": ";
        SOLVE();
    }
    printclock;
}

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

using namespace std;

int n;
long long f[5];

int main()
{
	cin>>n;
	int x;
	int i;
    for(i=1;i<=n;i++)
    {
    	cin>>x;
        long long minv=f[0]; 
		f[0]+=x;
        minv=min(minv,f[1]),f[1]=minv+(x?x&1:2);
        minv=min(minv,f[2]),f[2]=minv+(x?x+1&1:1);
        minv=min(minv,f[3]),f[3]=minv+(x?x&1:2);
        minv=min(minv,f[4]),f[4]=minv+x;
    }
    cout<<min(f[2],min(f[3],f[4]))<<endl;

    return 0;
}

Measured memory_bytes: 256
function Main(input){
  var inp = input.split('\n');
  var N = parseInt(inp[0].trim());
  var A = parseInt(inp[1].trim());
  
  if(N % 500 <= A ){
    console.log('Yes');
  } else {
    console.log('No');
  }
  
}
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 21064
#include<bits/stdc++.h>
using namespace std;
int main(){
	int C[6]={};
	for(int i=0;i<6;i+=1){
		int a;
		cin >> a;
		C[i]={a};
	}
	int b=(C[0]+C[1]*5+C[2]*10+C[3]*50+C[4]*100+C[5]*500)/1000;
	if(b>=1){printf("1\n");}
	else{printf("0\n");}
	
}


Measured memory_bytes: 3096
N,M,C=map(int,input().split())
B=list(map(int,input().split()))
P=0
for i in range(N) :
  X=0
  A=list(map(int,input().split()))
  for i in range(M) :
    X=X+A[i]*B[i]
  if X+C>0 :
    P=P+1
print(P)


Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<string>

using namespace std;
#define ll long long

int main(){
    char b;
    cin >> b;
    if(b == 'A')cout << 'T' << endl;
    else if(b == 'T')cout << 'A' << endl;
    else if(b == 'C')cout << 'G' << endl;
    else cout << 'C' << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define LI long int
#define FOR(i,a,b) for(int i=a;i<b;i++)
using namespace std;
int main(){
    LI a[100001];
    int n; cin>>n;
    FOR(i,0,n){
        cin>>a[i];
    }
    sort(a,a+n);
    FOR(i,1,n){
        a[i]+=a[i-1];
    }
    int m=-1;
    FOR(i,0,n-1){
        if(3*a[i]<a[i+1]) m=i;
    }
    cout<<n-m-1<<endl;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int cnt = 0;
        for(int i = 1;i <= N;i++){
            if(String.valueOf(i).length() % 2 != 0){
                cnt++;
            }
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 27604
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
signed main(){
  int N; cin>>N;
  int sum=1,ans=1;
  rep(i,0,N){
    ans*=3;
    int A; cin>>A;
    if(A%2==0)
      sum*=2;
  }
  cout<<ans-sum<<endl;
  }


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	void run() {
		FastScanner sc=new FastScanner();
		PrintWriter pw=new PrintWriter(System.out);
		int n=sc.nextInt();
		pw.println(180*(n-2));
		pw.close();
	}
	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public int nextInt() {
    	return Integer.parseInt(next());
    }
    
    public long nextLong() {
    	return Long.parseLong(next());
    }
}

Measured memory_bytes: 19284
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		String S = reader.next();
		String T = reader.next();
		String ans = "No";
		
		for (int i = 0; i < S.length(); i ++) {
			if (S.equals(T)) {
				ans = "Yes";
				break;
			}
			S = S.charAt(S.length()-1) + S.substring(0, S.length()-1);
		}
		

		reader.close();
		System.out.print(ans);
	}
}



Measured memory_bytes: 22868
// Contest.cpp : アプリケーションのエントリ ポイントを定義します。
//

#include"iostream"
#include"string"
#include"vector"
#include"algorithm"

using namespace std;

int main()
{
	/*int n,k;
	cin >> n;
	vector<char>s(n);
	for (int j = 0; j < n; j++)  cin >> s[j];
	cin >> k;
	for (int i = 0; i < n; i++)
	{
		if (s[i] != s[k-1]) {
			s[i] = '*';
		}
	}

	for (int l = 0; l < n; l++)
	{
		cout << s[l] ;
	}*/
	
	int n;
	cin >> n;
	int sum=0;

	sum = n * n*n;
	

	cout << sum << endl;
	
}





Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  }
} initializer;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(n), c(m), d(m);
  for (int i = 0; i < n; ++i) cin >> a[i] >> b[i];
  for (int i = 0; i < m; ++i) cin >> c[i] >> d[i];
  for (int i = 0; i < n; ++i) {
    int r = 0;
    for (int j = 1; j < m; ++j) {
      if (abs(a[i] - c[j]) + abs(b[i] - d[j]) < abs(a[i] - c[r]) + abs(b[i] - d[r])) r = j;
    }
    cout << r + 1 << endl;
  }
}



Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int n,a,i[1010];
    int p[1010],q[1010],r[1010],c[1010];
	int pc,qc,rc,cc;
	int f;
	while (scanf("%d",&n),n!=0){
	    for (a=0;a<n;a++){
		    scanf("%d %d %d %d",&i[a],&p[a],&q[a],&r[a]);
			c[a]=4*p[a]+9*q[a]+4*r[a];
		}
		scanf("%d %d %d %d",&pc,&qc,&rc,&cc);
		f=0;
		for (a=0;a<n;a++){
		    if (pc>=p[a]&&qc>=q[a]&&rc>=r[a]&&cc>=c[a]){
			    printf("%d\n",i[a]);
			    f=1;
			}
		}
		if (f==0){
		    printf("NA\n");
		}
	}
	return 0;
}

Measured memory_bytes: 1060
//written by libra9z
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <valarray>
#include <utility>
#include <numeric>
#include <memory>
#include <functional>
#include <stdexcept>
#include <typeinfo>
#include <limits>
#include <complex>
#include <locale>
using namespace std;
int N;
int main()
{
	scanf("%d",&N);
	for (int i=1;i<=3500;i++)
	{
		for (int j=1;j<=3500;j++)
		{
			long long A=4ll*(long long)i*(long long)j-(long long)N*(long long)(i+j);
			long long B=(long long)N*(long long)i*(long long) j;
			if (A>0 && B%A==0)
			{
				printf("%d %d %lld\n",i,j,B/A);
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#define f first
#define s second
#define mp make_pair

using namespace std;

const int MAX = 1000 * 1000 + 10;
long long dp[MAX];
vector<bool> isp(MAX, true);
vector<int> prime;

void solve(int now, int mul, int f){
  if(now == prime.size()) return;

  long long next = (long long)mul * prime[now];
  long long tmp = next;
  if(next >= MAX) return;

  solve(now + 1, mul, f);
  solve(now + 1, next, f ^ 1);
  
  int cnt = 0;
  for(; next < MAX; next += tmp){
    if(f == 0) dp[next] -= cnt++;
    else       dp[next] += cnt++;
  }
}

int main(){
  int t; scanf("%d", &t);
  isp[0] = isp[1] = false;
  prime.push_back(2);
  for(int i = 2; i < MAX; i += 2) isp[i] = false;
  for(int i = 3; i < MAX; i += 2)
    if(isp[i]){
      prime.push_back(i);
      for(int j = i + i; j < MAX; j += i)
	isp[j] = false;
    }

  REP(i,MAX) dp[i] = i - 1;
  dp[0] = 0;
  dp[1] = 2;
  solve(0, 1, 0);
  REP(i,MAX - 1) dp[i + 1] = dp[i] + dp[i + 1];

  while(t --> 0){
    int n; scanf("%d", &n);
    cout << dp[n] << endl;
  }

  return 0;
}

Measured memory_bytes: 12000
N = input()


def check(n, ln):
    if ln == 0:
        if int(N) >= int(n) and all(n.count(s) > 0 for s in '357'):
            return 1
        else:
            return 0
    cnt = 0
    for i in '357':
        cnt += check(n + i, ln - 1)
    return cnt


def main():
    cnt = 0
    for l in range(3, len(N) + 1):
        cnt += check('', l)
    print(cnt)


if __name__ == '__main__':
    main()


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

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;


signed main(){
    int n, d, x;
    cin >> n >> d >> x;
    for(int i = 0; i < n; ++i){
        int a;
        cin >> a;
        for(int j = 0; j < d; j += a)
            ++x;
    }
    cout << x << endl;
}


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

using namespace std;

int main() {
    int n;
    cin >> n;
    for (int i = 111; i <= 999; i += 111) {
        if (i >= n) {
            cout << i << endl;
            break;
        }
    }
    return 0;
}

static int speedUp = []() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    return 0;
}();

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int h[100000];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> h[i];

    h[0]--;
    for (int i = 1; i < n; ++i)
        if (h[i] > h[i - 1])
            h[i]--;
    cout << (is_sorted(h, h + n) ? "Yes" : "No");
}


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

INF = 10 ** 9
dp = [INF] * (H+1)
dp[0] = 0
for i in range(H):
    for j in range(N):
        idx = min(H, i+ab[j][0])
        dp[idx] = min(dp[idx], dp[i]+ab[j][1])
print(dp[-1])

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

int main() {
  int N;

  cin >> N;

  int fx = 0;
  for (int n = N; n > 0; n = n / 10) {
    fx += n - (n / 10 * 10);
  }

  if (N % fx == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

int main(){
    int x, a[4], op[3];
    cin >> x;

    for(int i = 3; i >= 0; i--){
        a[i] = x%10;
        x /= 10;
    }

    for(int i = 0; i < (1<<3); i++){
        int accum = a[0];
        for(int j = 2; j >= 0; j--){
            op[2-j] = ((i&(1<<j)) != 0);
            if(op[2-j] == 1)  accum += a[3-j];
            else              accum -= a[3-j];    
        }

        if(accum == 7){
            for(int i = 0; i < 3; i++){
                cout << a[i];
                if(op[i] == 1)  cout << "+";
                else            cout << "-";
            }
            cout << a[3] << "=7" << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>  
#include <memory>
using namespace std;  
#define INF 0x3f3f3f3f  
typedef long long ll;  
const int N =  100005;  
#define FI first
#define SE second
typedef pair<int, int>pii;
int mod = 1000000007;
vector<int> tr[N];
int dep, n;
int nxt[N];
bool vis[N];
void dfs(int u, int pre, int d)
{
   
   if (u == n)
   {
      dep = d;
      nxt[pre] = u;
   }
   for (int i = 0; i < tr[u].size(); i++)
   {
      int v = tr[u][i];
      if (pre != v)
      {
         dfs(v, u, d + 1);
         if (~nxt[v])
            nxt[u] = v;
      }
   }

}
void white(int u, int pre, int &cnt)
{
   cnt++;
   for (int i = 0; i < tr[u].size(); i++)
   {
      int v = tr[u][i];
      if (!vis[v] && v != pre)
         white(v, u, cnt);
   }
}
int main()  
{  

   // ios::sync_with_stdio(0);
   while (~scanf("%d", &n))
   {
      int a, b;
      for (int i = 0; i < n; i++)
         tr[i].clear();
      memset(nxt, -1, sizeof(nxt));
      memset(vis, 0, sizeof(vis));
      for (int i = 1; i < n; i++)
      {
         scanf("%d%d", &a, &b);
         tr[a].push_back(b);
         tr[b].push_back(a);
      }
      dep = 0;
      dfs(1, -1, 1);
      dep -= 2;
      dep = (dep&1) + (dep>>1);
      int cur = 1;
      vis[1] = true;
      while (dep--)
      {
         vis[nxt[cur]] = true;
         cur = nxt[cur];
      }
      int cnt = 0;
      white(n, -1, cnt);
      int f = n - cnt;
      cnt--;
      f--;
      // printf("f:%d s:%d\n", f, cnt);
      printf("%s\n", f <= cnt?"Snuke":"Fennec");
   }
   return 0;
}  

Measured memory_bytes: 14080
a = int(input())
b = int(input())
c = int(input())
x = int(input())

num = 0
for i_a in range(a + 1):
  for j_b in range(b + 1):
    for k_c in range(c + 1):
      total = 500 * i_a + 100 * j_b + 50 * k_c
      if total == x:
        num += 1
print(num)

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

int main()
{
    int n;
    string t, h;
    int tScore = 0;
    int hScore = 0;

    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> t >> h;

        if (t.compare(h) > 0) {
            tScore += 3;
        } else if (t.compare(h) < 0) {
            hScore += 3;
        } else {
            tScore += 1;
            hScore += 1;
        }
    }

    cout << tScore << " " << hScore << endl;

    return 0;
}

Measured memory_bytes: 1208
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<utility>
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define ll long long
using namespace std;
bool search(int* t,int n,int num) {
	for (int i = 0; i < n;i++) {
		if (t[i]==num) {
			return true;
		}
	}
	return false;
}
int main() {
	std::ios::sync_with_stdio(false);
	int s[3][3];
	for (int i = 0; i < 3;i++) {
		for (int j = 0; j < 3;j++) {
			cin >> s[i][j];
		}
	}
	int t[100];
	int n;
	cin >> n;
	for (int i = 0; i < n;i++) {
		cin >> t[i];
	}
	bool flag = false;
	for (int i = 0; i < 3;i++) {
		bool rf = false;
		if (search(t,n,s[i][0])==true&& search(t, n, s[i][1]) == true&&search(t, n, s[i][2]) == true) {
			flag = true;
			break;
		}
	}
	if (!flag) {
		for (int i = 0; i < 3;i++) {
			if (search(t, n, s[0][i]) == true && search(t, n, s[1][i]) == true && search(t, n, s[2][i]) == true) {
				flag = true;
				break;
			}
		}
	}
	if (!flag) {
		if (search(t,n,s[0][0])&&search(t, n, s[1][1])&&search(t, n, s[2][2])) {
			flag = true;
		}
		if (search(t, n, s[0][2]) && search(t, n, s[1][1]) && search(t, n, s[2][0])) {
			flag = true;
		}
	}
	if (flag) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


n = ni()
d = list(li())
d.sort()

print(d[n//2] - d[n//2 - 1])

Measured memory_bytes: 14044
#include<bits/stdc++.h>
#define N 100010
using namespace std;
char s[N];
int n;
int main(){
	scanf("%s",s+1);
	int n=strlen(s+1);
	if(s[n]=='1'){cout<<-1<<endl;return 0;}
	if(s[1]=='0'){cout<<-1<<endl;return 0;}
	for(int i=1;i<=n/2;i++){
		if(s[i]!=s[n-i]){
			cout<<-1<<endl;
			return 0; 
		}
	}
	int now=1,cnt=2;
	printf("%d %d\n",1,2);
	for(int i=2;i<n;i++){
		if(s[i]=='0')printf("%d %d\n",now,++cnt);
		else {
			printf("%d %d\n",++cnt,now);
			now=cnt;
		}
	}
	return 0;
}

Measured memory_bytes: 1536
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import java.util.function.BiFunction;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		Integer n = Integer.valueOf(scanner.nextLine());
		Integer a = n / 1000;
		n %= 1000;
		Integer b = n / 100;
		n %= 100;
		Integer c = n / 10;
		n %= 10;
		Integer d = n;
		BiFunction<Integer, Integer, Integer> adder = (a1, a2) -> { return a1 + a2; };
		BiFunction<Integer, Integer, Integer> suber = (a1, a2) -> { return a1 - a2; };
		ArrayList<BiFunction<Integer, Integer, Integer>> ops = new ArrayList(Arrays.asList(adder, suber));
		ArrayList<String> opsStr = new ArrayList(Arrays.asList("+", "-"));
		Boolean hasFound = false;
		for(int i = 0; i < 2; i++) {
			if (hasFound) break;
			for(int j = 0; j < 2; j++) {
				if (hasFound) break;
			    for(int k = 0; k < 2; k++) {
			    	if (hasFound) break;
			       Integer temp = ops.get(i).apply(a, b);
				   temp = ops.get(j).apply(temp, c);
				   temp = ops.get(k).apply(temp, d);
				   if(temp == 7) {
					  System.out.println(a + opsStr.get(i) + b + opsStr.get(j) + c + opsStr.get(k) + d +"=7");
					  hasFound = true;
					  break;
				   }
			   }
			}
		}
	}
}


Measured memory_bytes: 28500
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
 
#define vi vector<int> 
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >   
#define vpl vector< pair<ll,ll> >   
typedef pair<pair<int, ll>,int> P;
 #define mod %1000000007
// #define p 41
bool less_vectors(const vector<int>& a,const vector<int>& b) 
{
   return a.size() > b.size();
}
 
ll gcd(ll a,ll b)
{
if(a%b==0)
   return b;
   else
        return gcd(b,a%b);
}
class compr
{
   public:
bool operator()(pair<pair<int,ll>,int>  p1,pair<pair<int,ll>,int> p2)
{
   if(p1.ff.ss!=p2.ff.ss)
        return p1.ff.ss>p2.ff.ss;
        else
             if(p1.ss!=p2.ss)
             return p1.ss>p2.ss;
             else
                  return p1.ff<p2.ff;
             
}

};
ll fastexpo(ll a,ll b)
{
   //trace2(a,b);
   ll res=1;
   while(b>0)
   {
        if(b%2==1)
             res=(((res)mod)*((a)mod))mod;
        a=(((a)mod)*((a)mod))mod;
        b/=2;
   }
   //trace1(res);
   return res;
}
ll fastexpom(ll a,ll b,ll m)
{
ll res=1;
   while(b>0)
   {
        if(b%2==1)
             res=(((res)%m)*((a)%m))%m;
        a=(((a)%m)*((a)%m))%m;
        b/=2;
   }
   return res;
}
ll modinv(ll a,ll m=1000000007)
{
return fastexpom(a,m-2,m);
}
bool cmp(pair<int,int> p1,pair<int,int> p2)
{
	if((p1.ss-p1.ff)!=(p2.ss-p2.ff))
		return p1.ss-p1.ff<p2.ss-p2.ff;
	else
		return p1.ff<p2.ff;
}
bool cmp(string s1,string s2)
{
	if(s1.length()!=s2.length())
		return s1.length()>s2.length();
	else
		return s1<s2;
}
int main()
{
  	IOS;
 	/*#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif*/
	int n;
	cin>>n;
	vl a(n);
	vl b(n);
	ll cnt=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i]>>b[i];
	}
	for(int i=n-1;i>=0;i--)
	{
		//trace3(a[i],b[i],cnt);
		if(((a[i]+cnt)%b[i]))
			cnt+=b[i]-(a[i]+cnt)%b[i];
	}
	cout<<cnt;
  return 0;
}  

Measured memory_bytes: 1792
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int q = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        StringBuilder sbF = new StringBuilder();
        sb.append(s);
        boolean start = true;
        for (int i = 0; i < q; i++) {
            int t = sc.nextInt();
            if (t == 1) {
                start = !start;
            } else {
                int f = sc.nextInt();
                String c = sc.next();
                if (start) {
                    if (f == 1) {
                        //sb.insert(0, c);
                        sbF.append(c);
                    } else {
                        sb.append(c);
                    }
                } else {
                    if (f == 1) {
                        sb.append(c);
                    } else {
                        sbF.append(c);
                    }                   
                }
            }
        }
        String result;
        if (!start) {
            result = sb.reverse().append(sbF).toString();
        } else {
            result = sbF.reverse().append(sb).toString();
        }
        System.out.println(result);
        sc.close();
    }
}

Measured memory_bytes: 117436
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
#define downque(que)  priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;

//137c
//TLEしないためにはunordered_mapを使う。初めて

int main(){
  int n; cin>>n;
  unordered_map<string,int> mp; //stringそのものが配列
  ll ans=0;
  string str;
  REP(i,n){
      cin>>str;
      sort(ALL(str));
      if (mp.count(str)==0){
       //もしstrがほかのどのキーstrとも一致しないなら 
        mp[str]=1;
      }else{
        mp[str]++;
        
      }
  }//これですべてが整列し終わる
  //あとはコンビネーションでかいけつ

  for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
      ll a=itr->second; 
    ans+=(a*(a-1))/2;
  }
  cout<<ans<<endl;

}

Measured memory_bytes: 10660
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <string>
using namespace std;
typedef long long ll;
ll INF=1<<29;

bool check(string a,string b){
	if(a.length()==b.length()) return a>b;
	else if(a.length()>b.length()) return true;
	else return false;
}

int main(){
	ios::sync_with_stdio(false);
	int N,M;
	cin>>N>>M;
	vector<pair<string,int>> A(M);
	vector<string> dp(N+10);
	fill(dp.begin(),dp.end(),"0");
	for(int i=0;i<M;i++){
		string a;
		int b;
		cin>>a;
		if(a=="1") b=2;
		else if(a=="7") b=3;
		else if(a=="4") b=4;
		else if(a=="2" || a=="3" || a=="5") b=5;
		else if(a=="6" || a=="9") b=6;
		else b=7;
		A[i]=make_pair(a,b);
	}
	for(int i=0;i<=N;i++){
		for(int j=0;j<M;j++){
			if(dp[i]=="0" && i!=0) continue;
			if(check(dp[i]+A[j].first, dp[i+A[j].second])) dp[i+A[j].second]=dp[i]+A[j].first;
			else dp[i+A[j].second]=dp[i+A[j].second];
		}
	}
	for(int i=1;i<dp[N].length();i++) cout<<dp[N][i];
	return 0;
}

Measured memory_bytes: 43776
s = []
judge = True

for i in range(3):
    s.append(list(map(int, input().split())))

for i in range(3):
    for j in range(3):
        for k in range(3):
            for l in range(3):
                if i != k and k != l:
                    a = s[i][j] + s[k][l]
                    b = s[i][l] + s[k][j]
                    if a != b:
                        judge = False
                        break

if judge == True:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064