akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,0,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  int N,M,ans=0;
  cin>>N;
  int T[N+1];
  for(int i=1; i<=N; ++i){
    cin>>T[i];
    ans+=T[i];
  }
  cin>>M;
  int P[M+1],X[M+1];
  for(int i=1; i<=M; ++i) cin>>P[i]>>X[i];
  
  for(int i=1; i<=M; ++i) cout<<ans-T[P[i]]+X[i]<<endl;
}

Measured memory_bytes: 256
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
long long getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      ((a)/GCD((a),(b))*(b))
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;

// code
// ------------------------------------------------
int main() {

  ll n,k;
  cin >> n >> k;

  vector<char> d(k);
  rep(i,k) cin >> d[i];


  for(ll i = n; i < 100000; ++i)
  {
    string s = to_string(i);

    map<char,ll> m;
    rep(j,sz(s))
    {
      m[s[j]]++;
    }

    bool is = true;
    rep(j,k)
    {
      if(m[d[j]] > 0)
        is = false;
    }

    if(is)
    {
      cout << i << endl;
      return 0;
    }

  }


  return 0;
}
// funcの実体
// ------------------------------------------------
ll getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
ll CalcSumOfDigit(ll n)
{
  ll s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)

using namespace std;
int main(){
    string s;
    cin >> s;
    bool flag = true;
    REP(i, s.length()) {
        REP(j, s.length()) {
            if(i==j) continue;
            if(s[i] == s[j]) flag = false;
        }
    }
    if(flag) puts("yes");
    else puts("no");
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
long long mod=(long long)1e09+7;
int inf=1<<29;
long long llinf=1ll<<60;

int in(void){
    int i;scanf("%d",&i);
    return i;
}
long long llin(void){
    long long i;scanf("%lld",&i);
    return i;
}
double din(void){
    double i;scanf("%lf",&i);
    return i;
}
void chin(char s[]){
    scanf("%s",s);
}
void print(int a){
    printf("%d\n",a);
}
void llprint(long long a){
    printf("%lld\n",a);
}
void dprint(double a){
    printf("%.10f\n",a);
}
void print2(int a,int b){
    printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
    return a>b?a:b;
}
long long min(long long a,long long b){
    return a<b?a:b;
}
int cmp(const void *a,const void *b){
    return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
    return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
    return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
    return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
    int t=*a;
    *a=*b;
    *b=t;
}
long long gcd(long long x,long long y){
    return x%y?gcd(y,x%y):y;
}
long long lcm(long long x,long long y){
    return x/gcd(x,y)*y;
}

// write codes below this
// when you use 'sort',
// make sure TYPE macro is correct
char s[10001];
int i;
int solve(void){
    int ret;
    int j;
    int k=0;
    int tmp[10000];
    if(s[i+1]!='['){
        ret=0;
        while(s[++i]!=']')
            ret=ret*10+s[i]-'0';
        return (ret+1)/2;
    }
    i++;
    while(s[i]!=']'){
        tmp[k++]=solve();
        i++;
    }
    sort(tmp,k);
    ret=0;
    rep(j,(k+1)/2)ret+=tmp[j];
    return ret;
}

int main(void){
    int n=in(),j;
    rep(j,n){
        MEMSET(s);
        chin(s);
        i=0;
        print(solve());
    }
    return 0;
}


Measured memory_bytes: 2064
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	
	long pow(long a,long n,long p) {
		long ret=1;
		for (;n>0;n>>=1,a=a*a%p) if(n%2==1) ret=ret*a%p;
		return ret;
	}
	
	long[] reverse(long[] a) {
		int s=0;
		int t=a.length-1;
		long[] b=Arrays.copyOf(a, a.length);
		while (s<t) {
			b[s]^=b[t];b[t]^=b[s];b[s]^=b[t];
			++s;--t;
		}
		return b;
	}
	
	//      * 
	// oxoxoxxoxoxo
	long g(long[] A) {
		int N=A.length;
		long ans=-Long.MAX_VALUE/3;
		long[] a=new long[N];
		long[] b=new long[N];
		for (int i=0;i<N;++i) {
			a[i]=(i%2==0?A[i]:0)+(i>0?a[i-1]:0);
			b[i]=(i%2==0?0:A[i])+(i>0?b[i-1]:0);
		}
		for (int i=0;i<N;++i) {
			if (i%2==1) ans=Math.max(ans, a[i]+(b[N-1]-b[i]));
		}
		return ans;
	}
	
	long f(long[] A) {
		int N=A.length;
		long[] a=new long[N];
		long[] b=new long[N];
		long[] c=new long[N];
		for (int i=0;i<N;++i) {
			a[i]=(i%2==0?A[i]:0)+(i>0?a[i-1]:0);
			b[i]=(i%2==0?0:A[i])+(i>0?b[i-1]:0);
			if (i%2==0&&i>=2) {
				c[i]=Math.max(c[i-2]+A[i-1], a[i-1]);
			}
		}
		long max=-Long.MAX_VALUE/3;
		for (int i=0;i<N;i+=2) {
			max=Math.max(max, a[N-1]-A[i]);
		}
		for (int i=0;i<N;i+=2) {
			max=Math.max(max, (i>0?a[i-1]:0)+(b[N-1]-b[i]));
		}
		for (int i=2;i<N;i+=2) {
			max=Math.max(max, c[i]+a[N-1]-a[i]);
		}
		return max;
	}
	
	final long MOD=(long)1e9+7;

	void run() {
		Scanner sc=new Scanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		int N=sc.nextInt();
		long[] A=new long[N];
		for (int i=0;i<N;++i) A[i]=sc.nextInt();
		if(N%2==0) {
			pw.println(Math.max(g(A),g(reverse(A))));
		} else {
			pw.println(Math.max(f(A),f(reverse(A))));
		}
		pw.close();
	} 
	
	void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
	
    public static void main(String[] args) {
    	new Main().run();
    }
}


Measured memory_bytes: 62640
# AtCoder 星には四種類の塩基 A, C, G, T が存在し、A と T、C と G がそれぞれ対になります。
# 文字 bが入力されます。これは A, C, G, T のいずれかです。塩基
# b と対になる塩基を表す文字を出力するプログラムを書いてください。

# 標準入力から 文字列 b を取得する
b = input()

# 塩基 b と対になる塩基を探して出力する
output_srt = 'None'
if b == 'A':
    output_srt = 'T'
elif b == 'C':
    output_srt = 'G'
elif b == 'G':
    output_srt = 'C'
elif b == 'T':
    output_srt = 'A'

print(output_srt)


Measured memory_bytes: 9084
#include<stdio.h>

int main(void)
{
   int a,b,c;
   scanf("%d",&a);
   scanf("%d",&b);
   scanf("%d",&c);
   if(a<b&&a<c&&b<c)
      printf("Yes\n");
    else
       printf("No\n");
 
    return 0;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
using namespace std;
int fun(int dp[][4],int ar[][4],int i,int j)
{
	if(i==0)
		return 0;
	if(j==1)
		return max(ar[i][2]+fun(dp,ar,i-1,2),ar[i][3]+fun(dp,ar,i-1,3));
	if(j==2)
		return max(ar[i][1]+fun(dp,ar,i-1,1),ar[i][3]+fun(dp,ar,i-1,3));
	if(j==3)
		return max(ar[i][1]+fun(dp,ar,i-1,1),ar[i][2]+fun(dp,ar,i-1,2));
}
int main()
{
	int n,i,j;
	scanf("%d",&n);
	int ar[n+1][4];
	int dp[n+1][4];
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=3;j++)
			scanf("%d",&ar[i][j]);
	}
	int ans=0;
	memset(dp,-1,sizeof(dp[n+1]));
	dp[1][1]=ar[1][1];
	dp[1][2]=ar[1][2];
	dp[1][3]=ar[1][3];
	for(i=2;i<=n;i++)
	{
		dp[i][1]=ar[i][1]+max(dp[i-1][3],dp[i-1][2]);
		dp[i][2]=ar[i][2]+max(dp[i-1][1],dp[i-1][3]);
		dp[i][3]=ar[i][3]+max(dp[i-1][1],dp[i-1][2]);
	}
	ans=max(dp[n][1],max(dp[n][2],dp[n][3]));
	printf("%d\n",ans);
}


Measured memory_bytes: 3328
from collections import Counter

n = int(input())
v = list(map(int,input().split()))
v0 = []
v1 = []
for i,ev in enumerate(v):
    if i%2 == 0:
        v0.append(ev)
    else:
        v1.append(ev)

mcv0 = Counter(v0).most_common(2)
mcv1 = Counter(v1).most_common(2)
cmcv0 = mcv0[0][1]
cmcv1 = mcv1[0][1]
ans = n - cmcv0 - cmcv1
if mcv0[0][0] == mcv1[0][0]:
    if (len(mcv0) == 1) and (len(mcv1) == 1):
        ans = int(n/2)
    else:
        ans = min(n - mcv0[1][1] - cmcv1, n - cmcv1 - mcv1[1][1])
print(ans)

Measured memory_bytes: 16092
n = int(input())
a = list(map(int, input().split()))
sm = 0
for i in range(len(a)):
    a[i] -= i + 1
b = sorted(a)
if len(b) % 2 == 0:
    t = b[int(len(b)/2)]
else:
    t = b[int((len(b) - 1) / 2)]
ans = 0
for i in range(len(a)):
    ans += abs(a[i] - t)
print(ans)

Measured memory_bytes: 26184
#include<bits/stdc++.h>
#include<iostream>
#include<stdio.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fr(i,j,n)   for(int i=j;i<(n);++i)
#define bk(i,j,n)   for(int i=j;i>=n;--i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define endl "\n"
#define MOD 1000000007
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;

#define run ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ordered_set tree<ll , null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>

typedef long long ll;
ll modpower(ll a,ll b,ll c)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
			res=(res*a)%c;
		a=(a*a)%c;
		b>>=1;
	}
	return res;
}


int main()
{
    run;

   ll n,k;
   cin>>n>>k;
   ll a[n];
   ll e=0,p=0,z=0;
   fr(i,0,n)
   {
       cin>>a[i];
       if(a[i]<0)
        e++;
       else if(!a[i])
        z++;
       else
        p++;
   }
   sort(a,a+n);
   ll te,tz,tp;
   te=p*e;
   tz=z*(z-1)/2+z*(n-z);
   tp=p*(p-1)/2+e*(e-1)/2;
  // cout<<te;
   if(k<=te)
   {

       vector<ll> x,y;
       fr(i,0,n)
       {
           if(a[i]<0)
           {
               x.pb(a[i]);
           }else if(a[i]>0)
           {
               y.pb(a[i]);
           }


       }
       ll sx=x.size(),sy=y.size();
       ll lo=y[sy-1]*x[0];
       ll hi=x[sx-1]*y[0];
       ll ans;
       reverse(x.begin(),x.end());
      reverse(y.begin(),y.end());
       while(hi>=lo)
       {
           ll c=0;
           ll mi=(hi+lo)/2;
           ll lev=0;
           ll j;
           fr(i,0,sx)
           {
               for(j=lev;j<y.size() && x[i]*y[j]<=mi;j++);
               c+=j;
               lev=j;

           }


           if(c<k)
           {
               lo=mi+1;
           }else{
           hi=mi-1;
           }

       }
       cout<<lo;


   }else if(k<=te+tz)
   {
       cout<<0;
   }else{
       vector<ll> x,y;
       fr(i,0,n)
       {
           if(a[i]<0)
           {
               x.pb(a[i]);
           }else if(a[i]>0)
           {
               y.pb(a[i]);
           }


       }
       ll sx=x.size(),sy=y.size();
       reverse(x.begin(),x.end());
       ll lo=1000000000000000;
       ll hi=-100000000000000;
       if(x.size()>=2)
       {
           lo=min(lo,x[0]*x[1]);
           hi=max(hi,x[sx-1]*x[sx-2]);
       }
       if(y.size()>=2)
       {
           lo=min(lo,y[0]*y[1]);
           hi=max(hi,y[sy-1]*y[sy-2]);
       }
        while (lo <= hi) {
        ll mi = lo + (hi - lo) / 2;
        ll c = 0;
        for (ll i = p - 1, j = 0; i >= 0; --i) {
            for (; j < i && y[i] * y[j] <= mi; ++j);
            c += min(j, i);
        }
        for (ll i = e - 1, j = 0; i >= 0; --i) {
            for (; j < i && x[i] * x[j] <= mi; ++j);
            c += min(j, i);
        }

        if (c < k-te-tz)
            lo = mi + 1;
        else
            hi = mi - 1;
    }
    cout<<lo;




   }




    return 0;
}


Measured memory_bytes: 4084
#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 ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = 1ll<<30;
const ll longINF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

int main() {
	int N;
	cin >> N;
	
	int sum = 0, c = 1;
	while (sum < N) {
		sum += c;
		c++;
	}
	// <cまで加える
	
	vector<vector<int> > ans;
	if (sum == N) {
		ans.resize(c);
		int cur = 1;
		REP(i, c) {
			REP(j, i) {
				ans[j].push_back(cur);
				ans[i].push_back(cur);
				cur++;
			}
		}
	}
	
	
	if (ans.empty()) puts("No");
	else {
		puts("Yes");
		cout << ans.size() << endl;
		REP(i, ans.size()) {
			printf("%d", ans[i].size());
			REP(j, ans[i].size()) printf(" %d", ans[i][j]);
			puts("");
		}
	}
	
	return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
long long ans;
long long N,A,B,C,D;
unordered_map<long long,long long> mp;

long long cost(long long N){
  if (mp.count(N)) return mp[N];
  if(N==0) return 0;
  if(N==1) return D;
  //cout<<N<<"#"<<endl;
  ans=min({abs(D*N),
           abs((N-N/5*5)*D+C+cost(N/5)),
           abs(abs(N-(N+4)/5*5)*D+C+cost((N+4)/5)),
           abs((N-N/3*3)*D+B+cost(N/3)),
           abs(abs(N-(N+2)/3*3)*D+B+cost((N+2)/3)),
           abs((N-N/2*2)*D+A+cost(N/2)),
           abs(abs(N-(N+1)/2*2)*D+A+cost((N+1)/2))});
  //cout<<N<<" "<<A<<B<<C<<D<<" "<<ans<<endl;
  return mp[N]=ans;
}

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

  for(int i=0;i<T;i++){
    cin>>N>>A>>B>>C>>D;
    mp.clear();
    cout<<setprecision(20)<<cost(N)<<endl;
  }
  return 0;
}


Measured memory_bytes: 4128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#include <math.h> /* M_PI */
#define INF 2147483647
int main()
{
    ll n;
    cin >> n;
    vector<vector<ll>> F(n, vector<ll>(10));
    vector<vector<ll>> P(n, vector<ll>(11));
    rep(i, n)
    {
        rep(j, 10)
        {
            cin >> F[i][j];
        }
    }
    rep(i, n)
    {
        rep(j, 11)
        {
            cin >> P[i][j];
        }
    }
    int N = 10;
    ll max1 = -21474813623323247;
    rep(i, 1 << N)
    {
        vector<ll> d(N);
        rep(j, N)
        {
            if (i >> j & 1)
            {
                d[j] = 1; //これは逆に入る。が、d[0]は初めの点という事は一緒
            }
        }
        if (i == 0)
        {
            continue;
        }
        ll ans = 0;

        rep(k, n)
        {
            ll count = 0;
            rep(j, 10)
            {
                if (d[j] == F[k][j] && d[j] == 1)
                {
                    count += 1;
                }
            }

            ans += P[k][count];
        }
        max1 = max(max1, ans);
    }

    cout << max1;
}

Measured memory_bytes: 256
$count=[]

for num in 0..36 do
  $count[num]=0
  for a in 0..9 do
    for b in 0..9 do
      for c in 0..9 do
        for d in 0..9 do
          if a+b+c+d==num then 
            $count[num]+=1
          end
        end
      end
    end
  end
end

def answer(n)
  if n<0 or n>36
    return 0
  else
    return $count[n]
  end
end

while n = gets do
  puts answer(n.to_i)
end

Measured memory_bytes: 6092
#include <stdio.h>
int main()
{
    int i,n,x,min,max;
    long sum=0;
    max = -1000000;
    min = 1000000;

    scanf("%d\n",&x);
    for(i=0;i<x;i++){
          scanf("%d",&n);
          if(n>=max){
               max=n;
          }
          if(n<=min){
               min=n;
          }
          sum=sum+n;
    }
    printf("%d %d %ld\n",min,max,sum);
    
    return 0;
}

Measured memory_bytes: 600
//Created by Kira

#include<bits/stdc++.h>
using namespace std;

#define IOS cin.sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int,int> 
#define pb push_back
#define vi vector<int> 
using ll = long long;

const int mod = 1e9 + 7;

ll pwr(ll a, ll b);
    




int main(){
   IOS
    int n; 
   cin>>n;

    ll ans = 0;
    
    for(ll i = 1; i <= n; i++){
        ans += i * (n- i + 1);
    }


   for(int i = 0; i < n-1; i++){
       ll u, v; cin>>u>>v;
        if(u > v)
            swap(u, v);
        ans -= u * (n - v + 1);
   }


   cout<<ans<<"\n"; 
}

ll pwr(ll a, ll b){
   a %= mod;	//Remove mod if not required
   ll res = 1;
   while(b > 0){
    if(b&1) res = res * a % mod;
        a = a * a % mod;
    b >>= 1;
    }

    return res;
}



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

int main(){
	int n;
	cin>>n;
	int px=0, py=0, pt=0;
	int x,y,t;
	for(int i=1;i<=n;i++){
		cin>>t>>x>>y;
		int p=abs(x - px) + abs(y - py);
		int tt=(t-pt)-p;
		if(tt < 0 || tt%2) {
			cout << "No" << endl;
			return 0;
		}
		px=x, py=y, pt=t;
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 3636
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 262144
int main() {
	int h, w, d;
	cin >> h >> w >> d;
	string color = "RYGB";
	for (int i = 0;i < h;++i) {
		for (int q = 0;q < w;++q) {
			int mask = 0;
			mask |= (i + q) / d % 2;
			mask |= ((h - 1 - (i - q)) / d % 2) << 1;
			cout << color[mask];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 512
n, k = map(int, input().split())
s = input()
hand_list = []
for i in range(n):
    if i == 0:
        hand_list.append(i)
    else:
        if s[i] != s[i - 1]:
            hand_list.append(i)
hand_list.append(n)

ans_list = []
if len(hand_list) > 2 * k:
    for i in range(len(hand_list) - 2 * k):
        if s[hand_list[i]] == '1':
            ans = hand_list[min(i + 2 * k + 1, len(hand_list)-1)] - hand_list[i]
        else:
            ans = hand_list[i + 2 * k] - hand_list[i]
        ans_list.append(ans)
else:
    ans_list.append(n)
print(max(ans_list))

Measured memory_bytes: 10236
#include <iostream>
#include <cstdio>
#include <vector>
#include <complex>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <stack>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <cassert>

using namespace std;

typedef long long ll;
typedef ll li;
typedef pair<int,int> PI;
#define EPS (1e-6)
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define REP(i, n) rep (i, n)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(),a.end()
#define CLR(a) memset((a),0,sizeof(a))
#define FOR(it,a) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)
template<typename T,typename U> ostream& operator<< (ostream& out, const pair<T,U>& val){return out << "(" << val.F << ", " << val.S << ")";}
template<class T> ostream& operator<< (ostream& out, const vector<T>& val){out << "{";rep(i,SZ(val)) out << (i?", ":"") << val[i];return out << "}";}
typedef double FP;
typedef complex<FP> pt;
typedef complex<FP> P;
typedef pair<pt,pt> line;
FP dot(P a,P b){return (conj(a)*b).real();}
FP crs(P a,P b){return (conj(a)*b).imag();}
P crspt(P a,P b,P c,P d){b-=a,d-=c;return a+b*crs(d,c-a)/crs(d,b);}
void pkuassert(bool t){t=1/t;};
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};

bool onl(P a1,P a2,P b){
  return abs(b-a1)+abs(b-a2)<abs(a1-a2)+EPS;
}

int xs[100],ys[100],xt[100],yt[100],o[100],l[100];

void solve(){
  int xa,ya,xb,yb;
  cin >> xa >> ya >> xb >> yb;
  vector<pair<FP,int> > arr;
  int n;
  cin >> n;
  rep(i,n) cin >> xs[i] >> ys[i] >> xt[i] >> yt[i] >> o[i] >> l[i];
  rep(i,n){
    P a(xs[i],ys[i]),b(xt[i],yt[i]);
    P c(xa,ya),d(xb,yb);
    P cr=crspt(a,b,c,d);
    if(onl(a,b,cr) && onl(c,d,cr))
      arr.pb(mp(abs(c-cr),o[i]^l[i]));
  }
  sort(ALL(arr));
  int ans=0;
  rep(i,SZ(arr)-1) ans += arr[i].S != arr[i+1].S;
  cout << ans << endl;
}
    

int main(int argc, char *argv[])
{
  int n;
  cin >> n;
  rep(i, n) solve();
  return 0;
}

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

typedef long long int ll;
typedef vector<long long>lve;
typedef vector<pair<ll,ll> > lvp;
typedef vector<pair<string,ll> > svp;

#define spc        ' '
#define endl       '\n'
#define F          first
#define S          second
#define pp         pop_back
#define pb         push_back
#define mp         make_pair
#define GCD(x,y)   __gcd(x,y)
#define PI         2*acos(0.0)
#define lb         lower_bound
#define bs         binary_search
#define LCM(x,y)   ((x*y)/__gcd(x,y))
#define btpc       __builtin_popcountll
#define sp(x)      cout<<fixed<<setprecision(x)

const   long long  cs=2e5+5;
const   long long  inf=1e18;
const   long long  mod=1e9+7;
void solve()
{
    ll t,n,m,a,b,c,d,e,i,j,k,x,y,z,cnt=0,cnt1=0;
    bool flag = false;   vector<long long> v,v1;
    
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a;
        v.pb(a);
    }
    for(i=0;i<n-1;i++)
    {
        if(v[i]>v[i+1])
        {
            cnt+=v[i]-v[i+1];
            v[i+1]=v[i];
        }
    }
    cout<<cnt<<endl;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);    cout.tie(NULL);

    /*freopen ("input.txt","r",stdin);
    freopen ("output.txt","w",stdout);*/

    ll tt;
    /*cin>>tt;
    while(tt--)*/
        solve();

    return 0;
}


Measured memory_bytes: 5336
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    string s;cin>>s;
    string ans="";
    ans+=s;
    if(s.at(s.size()-1)=='s'){
        ans+="es";
    }else{
        ans+="s";
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
ll gcd(ll x, ll y){
  if(y==0) return x;
  gcd(y,x%y);
}
ll lcm(ll x, ll y){
  return x/gcd(x,y)*y;
}
int f(int x){
  int res = 0;
  while(x%2==0){
    x/=2;
    res++;
  }
  return res;
}
int main(){
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  rep(i,n) a[i] /= 2;
  int t = f(a[0]);
  rep(i,n){
    if(f(a[i])!=t){
      cout << 0 << endl;
      return 0;
    }
    a[i] >>= t;
  }
  m >>= t;
  ll l = 1;
  rep(i,n){
    l = lcm(l,a[i]);
    if(l>m){
      cout << 0 << endl;
      return 0;
    }
  }
  m /= l;
  int ans = (m+1)/2;
  cout << ans << endl;
}

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

a_list = [0] if a==0 else range(a+1)
b_list = [0] if b==0 else range(b+1)
c_list = [0] if c==0 else range(c+1)    

count = 0

for n50 in c_list:
    s50 = 50*n50
    if s50==x:
        count += 1
    else:
        for n100 in b_list:
            s100 = s50+100*n100
            if s100==x:
                count += 1
            else:
                for n500 in a_list:
                    s500 = s100 + 500*n500
                    if s500==x:
                        count += 1
print(count)

Measured memory_bytes: 3064
/*

結果:
*/
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>  
#include <stdbool.h>   
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r)
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r)
#define TYPE long long
#define ll long long
#define MEMSET(a) memset(a,0,sizeof(a))
#define MEMSET_U(a) memset(a,-1,sizeof(a))
const int mod = (int)1e09 + 7;

//#define DEBUG1
//#define DEBUG2
//#define DEBUGF

int in(void) { int i; scanf("%d", &i); return i; }
long long llin(void) { long long i; scanf("%lld", &i); return i; }
double din(void) { double i; scanf("%lf", &i); return i; }
void chin(char s[]) { scanf("%s", s); }

void print(int a) { printf("%d\n", a); }
void llprint(long long a) { printf("%lld\n", a); }
void dprint(double a) { printf("%.10f\n", a); }
void print2(int a, int b) { printf("%d %d\n", a, b); }

long long llmax(long long a, long long b) { return a > b ? a : b; }
long long llmin(long long a, long long b) { return a < b ? a : b; }
double dmax(double a, double b) { return a > b ? a : b; }
int cmp(const void *a, const void *b) { return *(TYPE *)a - *(TYPE *)b; }
int cmp_r(const void *a, const void *b) { return *(TYPE *)b - *(TYPE *)a; }
int char_cmp(const void *a, const void *b) { return strcmp((char *)a, (char *)b); }
int char_cmp_r(const void *a, const void *b) { return strcmp((char *)b, (char *)a); }
void swap(int *a, int *b) { int t = *a; *a = *b; *b = t; }

char s[101][101];
int f_w[101] = { -1 };
int f_h[101] = { -1 };

int main() {
	int h, w;
	scanf("%d%d", &h, &w);
	for (int i = 0; i < h; ++i) {
		scanf("%s", &s[i]);
	}
	printf("\n");
#ifdef 	DEBUG1
	for (int i = 0; i < h; ++i) {
		printf("%s\n", &s[i]);
	}
#endif
	//探査
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (s[i][j] == '#') {
				f_h[i] = 1;
				f_w[j] = 1;
			}
		}
	}
	//交点のみ表示
	for (int i = 0; i < h; i++) {
		if (f_h[i] == 1) {
			for (int j = 0; j < w; j++) {
				if (f_w[j] == 1) {
					printf("%c", s[i][j]);
				}
			}
			printf("\n");
		}
	}

#ifdef DEBUGF
	getch();
#endif
	return 0;
}

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

int main() {
  int A=0, B=0;
  string S;
  cin >> S;
  for (int i=0; i<S.size(); i++){
    if (S.at(i)=='S'){
      A+=1;
    }
    else if(S.at(i)=='T' && A>=1){
      A-=1;
      B+=1;
    }
  }
  cout << S.size()-B*2 << endl;
}

Measured memory_bytes: 640
S = [input() for _ in range(3)]

i = 0

while True:
    if S[i][0] == 'a':
        S[i] = S[i][1:]
        i = 0
    elif S[i][0] == 'b':
        S[i] = S[i][1:]
        i = 1
    elif S[i][0] == 'c':
        S[i] = S[i][1:]
        i = 2

    if len(S[i]) == 0:
        if i == 0:
            print('A')
            break
        elif i == 1:
            print('B')
            break        
        elif i == 2:
            print('C')
            break

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0; i<N; i++)

using namespace std;

int main(){
  int n ; cin >> n;
  vector<double> v(n);
  rep(i,n){ cin >> v[i]; }

  while(true){
    sort(v.begin(),v.end());
    if(v[1] == 1e9){
      break;
    }
    double t = (double) (v[0] + v[1]) / 2;
    v[0] = t;
    v[1] = 1e9;
  }

  printf("%lf\n", v[0]);
}

Measured memory_bytes: 256
n = int(input())
b = list(map(int,input().split()))
a = []
for i in range(n,0,-1):
  flag = 1
  for j in range(i-1,-1,-1):
    if b[j] == j+1:
      a.append(b.pop(j))
      flag = 0
      break
  if flag:
    print(-1)
    quit()
for i in a[::-1]:
  print(i)

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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    string S;
    cin >> S;

    int a = (S[0] - '0') * 10 + (S[1] - '0');
    int b = (S[2] - '0') * 10 + (S[3] - '0');

    if (a <= 12 && 0 < a)
    {
        if (0 < b && b <= 12)
        {
            cout << "AMBIGUOUS";
        }
        else
        {
            cout << "MMYY" << endl;
        }
    }
    else
    {
        if (0 < b && b <= 12)
        {
            cout << "YYMM";
        }
        else
        {
            cout << "NA";
        }
    }
    cout << endl;

    return 0;
}

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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class A, class B>
bool chmax(A &a, const B &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class A, class B>
bool chmin(A &a, const B &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int a;
  cin >> a;
  cout << a + a * a + a * a * a << '\n';
  return 0;
}

Measured memory_bytes: 3504
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin>>s>>t;
  int ans=0;
  for(int i=0;i<s.size();i++){
    if(s[i]!=t[i]){
      ans++;
    }
  }
  cout<<ans<<endl;
}


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

using ll = long long;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, sum[2] = {0};
	cin >> n;
	vector <int> a(n);
	for (int i=0; i<n; i++) {
		cin >> a[i];
	}
	sort (a.begin(), a.end());
	reverse (a.begin(), a.end());
	for (int i=0; i<n; i++) {
		sum[i&1] += a[i];
	}
	cout << sum[0]-sum[1];
	return 0;
}


Measured memory_bytes: 256
function main(input) {
  const args = input.split('\n')
  const nums = args[0].split(' ')
  const n = Number(nums[0])
  const m = Number(nums[1])
  const x = Number(nums[2])
  const books = args.slice(1, args.length).map(b => b.split(' ').map(v => Number(v)))
  let sumM = []
  let count
  let sum
  for (let i=0; i < 2**n; i++) {
    let sumA = Array(m).fill(0)
    count = 0
    sum = 0
    for (let k=0; k < n; k++) {
      if((i >> k) & 1 === 1 ) {
        for (let j=0; j < m; j++) {
          sumA[j] += books[k][j+1]
        }
        sum += books[k][0]
      }
    }
    if (sumA.filter(v => v >= x).length === m) {
      sumM.push(sum)
    }
  }
  if (sumM.length === 0) {
    console.log(-1)
  } else {
    console.log(Math.min(...sumM))
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))

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

#define int long long
#define ll long long
#define vll vector<int>
#define mset(a) memset(a,0,sizeof(a))
#define pb push_back
#define range(c) c.begin() , c.end()
#define forn(i,n) for(ll i=0; i<(int)n; ++i)
#define for1(i,n) for(ll i=1; i<(int)n; ++i)
#define endl '\n'
#define MOD 1000000007
#define pii pair<int,int>
#define test ll t;cin>>t;while(t--)
using namespace std;

vector<bool> sieve(ll n){
    vector<bool>prime(n+1,true);
    prime[0]=prime[1]=false;
    for(ll i=2; i<=n; ++i){
        if(prime[i]&&(i*i)<=n)
        for(ll j=i*i; j<=n; j+=i)prime[j]=false;
    }
    return prime;
}

ll power(ll a, ll b, ll m = MOD) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

//////////////////////////////////////////////////////////////

int dp[105][100005];

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

    

    int n,tar;
    cin>>n>>tar;
    vll wt(n), val(n);
    forn(i,n) cin>>wt[i]>>val[i];

    // int dp[n+1][tar+1];
    mset(dp);

    for1(i,n+1) {
        for1(j,tar+1) {
            if(j<wt[i-1]) dp[i][j] = dp[i-1][j];
            else {
                dp[i][j] = max(dp[i-1][j], val[i-1]+dp[i-1][j-wt[i-1]]);
            }
        }
    }    

    cout<<dp[n][tar];

    return 0;
}


Measured memory_bytes: 82304
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(j,n) for(int j = 0; j < (n); ++j)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define drep2(j,n) for(int j = (n)-1; j >= 0; --j)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define srep2(j,s,t) for (int j = s; j < t; ++j)
#define srep3(k,s,t) for (int k = s; j < t; ++k)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}

int gcd(int a, int b) { // a > b
  int c = -1;
  while(c != 0){
    c = a % b;
    a = b;
    b = c;
  }
  return a;
}

int N;
int A[100010];

int dfs(int n,bool used,int index) {
  if(index == N) {
    return n;
  }
  int newgcd = gcd(n,A[index]);
  if(newgcd < n && !used) {
    return max(dfs(n,true,index+1),dfs(newgcd,false,index+1));
  }
  return dfs(newgcd,used,index+1);
}
  
int main() {
  cin >> N;
  rep(i,N) {
    cin >> A[i];
  }
  cout << max(dfs(A[0],false,0),dfs(A[1],true,1)) << endl; 
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cmath>

using namespace std;

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

    int sum = 0;
    for (int i = 0; i < n; i++) {
        sum += x[i];
    }
    int mid1 = sum/n, mid2 = sum/n+1, mid3 = sum/n-1;
    int sum1 = 0, sum2 = 0, sum3 = 0;
    for (int i = 0; i < n; i++) sum1 += (x[i]-mid1)*(x[i]-mid1);
    for (int i = 0; i < n; i++) sum2 += (x[i]-mid2)*(x[i]-mid2);
    for (int i = 0; i < n; i++) sum3 += (x[i]-mid3)*(x[i]-mid3);
    sum2 = min(sum2, sum3);
    cout << min(sum1, sum2) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[100001];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+n+1);
	cout<<a[n]-a[1];
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main (String[] args) {
		Scanner scan = new Scanner(System.in);
		int a=scan.nextInt(),b=scan.nextInt(),c=scan.nextInt();

		System.out.println((a+b==c || a+c==b || b+c==a)?"Yes":"No");
	}

}

Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

#define DEBUG

#ifdef DEBUG
#define var_dump(...) fprintf(stdout, __VA_ARGS__)
#define dump(a) cout << a << "\n";
#else
#define var_dump(...) 42
#define dump(a) 42
#endif

// https://beta.atcoder.jp/contests/abc057/tasks/abc057_b

int main() {
    int N, M;
    cin >> N >> M;
    int a[N];
    int b[N];
    int c[M];
    int d[M];
    REP(i, N) cin >> a[i] >>b[i];
    REP(i, M) cin >> c[i] >>d[i];

    REP(i, N) {
        int min = INF;
        int p = 0;

        REP(j, M) {
            int dst = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            if (dst < min) {
                min = dst;
                p = j + 1;
            }
        }

        cout << p << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		if(N<105) {
			System.out.println(0);
		}else if(N<135) {
			System.out.println(1);
		}else if(N<165) {
			System.out.println(2);
		}else if(N<189) {
			System.out.println(3);
		}else if(N<195) {
			System.out.println(4);
		}else {
			System.out.println(5);
		}
	}

}

Measured memory_bytes: 23124
#include<iostream>
#include<queue>
using namespace std;
int main()
{
	int n,q,opt,t,x;
	cin >> n;
	queue<int> a[n];
	cin >> q;
	while (q--)
	{
		cin >> opt;
		if (opt == 0)
		{
			cin >> t >> x;
			a[t].push(x); 
		}
		if (opt == 1)
		{
			cin >> t;
			if (!a[t].empty())
			cout << a[t].front() << endl;
		}
		if (opt == 2)
		{
			cin >> t;
			if (!a[t].empty())
			a[t].pop();
		}
	}
	return 0;
}


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

using ll = long long;
using namespace std;
const int INFint = 1e9+1;
const ll INFll = (ll)1e18+1;
ll MOD=1e9+7;


int dp[3001][3001] = {0};
int main(){
  int N,T;
  cin>>N>>T;
  vector<pair<int,int>> A;
  for(int i(0);i<N;i++){
    int a,b;
    cin>>a>>b;
    A.push_back({a,b});
  }
  sort(A.rbegin(),A.rend());
  for(int i(0);i<N;i++){
    for(int t(0);t<=T;t++){
      dp[i+1][t] = max(dp[i+1][t],dp[i][t]);
      if(t != 0){
        dp[i+1][t] = max(dp[i+1][t],dp[i+1][t-1]);
      }
      if(dp[i][t] == 0){
        if(t+1 <= T){
          dp[i+1][t+1] = max(dp[i+1][t+1],A[i].second);
        }
      } else {
        if(t+A[i].first <= T){
          dp[i+1][t+A[i].first] = max(dp[i+1][t+A[i].first],dp[i][t] + A[i].second);
        }
      }
    }
  }
  // for(int i(0);i<N;i++){
  //   for(int t(1);t<=T;t++){
  //     cout << dp[i][t] << " ";
  //   }
  //   cout << endl;
  // }
  cout << dp[N][T] << endl;
  return 0;
}



Measured memory_bytes: 38688
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define INF (int)1e9+1
#define INFLL (int)1e18+1
#define sz(bb) (int)bb.size()
#define all(qq) qq.begin(), qq.end() 
#define Max(a, b, c) max(a, max(b, c))
#define Min(a, b, c) min(a, min(b, c))
const double PI=acos(-1);
// #define int unsigned long long int//used when x<=2^64-1 && x>0
#define int long long//used when x<=2^63-1
//bool cmp if returns true it keeps 1st as first else swaps
typedef long long  ll;

const int N=200005;
int fact[N];
int power(int a, int b)
{
    int res=1;
    while(b)
    {
        if(b&1)
        {
            res=res*a;
            res%=mod;
        }
        a*=a;
        a%=mod;
        b/=2;
    }
    return res;
}
void precompute()
{
    fact[0]=1;
    for(int i=1;i<N;i++)
        fact[i]=(i*fact[i-1])%mod;
}
int inv(int x)
{
    return power(x, mod-2);
}
int nCr(int n, int r)
{
    int a=fact[n];
    int b=fact[n-r];
    int c=fact[r];
    b=inv(b);
    c=inv(c);
    int ans=(b*c)%mod;
    ans=(ans*a)%mod;
    return ans;
}
int fun(int x1, int y1, int x2, int y2)
{
    int x=x2-x1;
    int y=y2-y1;
    int a=fact[x+y];
    int b=fact[x];
    int c=fact[y];
    b=inv(b);
    c=inv(c);
    int ans=(b*c)%mod;
    ans=(ans*a)%mod;
    return ans;
}
void solve()
{
    precompute();
    int p, q, n;
    cin>>p>>q>>n;
    vector<pair<int, int>> v;
    for(int i=0;i<n;i++)
    {
        int a, b;
        cin>>a>>b;
        v.pb({a, b});
    }
    v.pb({p, q});
    sort(all(v));
    int dp[n+1];
    for(int i=0;i<=n;i++)
    {
        dp[i]=fun(1, 1, v[i].ff, v[i].ss);
    }
    for(int i=0;i<=n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            if(v[j].ff<v[i].ff || v[j].ss<v[i].ss)
                continue;
            dp[j]-=(dp[i]*fun(v[i].ff, v[i].ss, v[j].ff, v[j].ss))%mod;
            dp[j]=(dp[j]+1000LL*mod)%mod;
        }
    }
    cout<<dp[n]<<"\n";
}
int32_t main()
{
    IOS;
    int t;
    // cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 5328
/*@author Vipen Loka*/
#include <bits/stdc++.h>
#define endl '\n'
#define ff first
#define ss second
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define deb(x) cout << #x << ':' << x << '\n';

using namespace std;

void solve(){
	int i,j;
	int n,k;
	cin >> n >> k;
	vector<int> v(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> v[i];
	}

	vector<int>dp(n,INT_MAX);
	dp[0]=0;
	for (int i = 1; i < n; ++i)
	{
		for (int j = i-1; j > max(i-k-1,-1); --j)
		{
			dp[i]=min(dp[i],dp[j]+abs(v[i]-v[j]));
		}
	}

	printf("%d\n",dp[n-1]);
}


int main(){
	int T=1;
	// cin >> T;
	while (T--){
		solve();
	}
}


Measured memory_bytes: 3976
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define double long double
using namespace std;
signed main() {
	string s, memo;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'B') {
			if (i >= 3 && s[i - 3] == 'B'&&s[i - 2] == 'B'&&s[i - 1] == 'B')memo[memo.size() - 4] = ' ';
			else if (i >= 2 && s[i - 2] == 'B'&&s[i - 1] == 'B')memo[memo.size() - 3] = ' ';
			else if (i >= 1 && s[i - 1] == 'B')memo[memo.size() - 2] = ' ';
			else memo[memo.size() - 1] = ' ';
		}
		if (s[i] == '0')memo += '0';
		if (s[i] == '1')memo += '1';
	}
	for (int i = 0; i < memo.size(); i++) {
		if (memo[i] != ' ')cout << memo[i];
	}
	cout << endl;
	getchar(); getchar(); return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    int n, k, x, y;
    cin >> n >> k >> x >> y;
    if(n > k)
        cout << x * k + y * (n - k) << endl;
    else
        cout << x * n << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000)
def resolve():
    s = input()
    K = int(input())
    mem = []
    for i in range(1, K+1): # window size
        for j in range(len(s)): # window starts at
            subs = s[j:j+i]
            if subs not in mem:
                mem.append(subs)
    mem.sort()
    # print(mem)
    print(mem[K-1])
    
    
if '__main__' == __name__:
    resolve()

Measured memory_bytes: 38768
s = input()
n = len(s)

ans = 0
for bit in range(1 << n-1):
    tmp = s[0]
    for i in range(n-1):
        if bit & (1 << i):
            tmp += "+"
        tmp += s[i+1]
    
    ans += sum(map(int,tmp.split("+")))

print(ans)

Measured memory_bytes: 9096
s = raw_input()
if s.count('S') > 0 and s.count('N') == 0:
    print "No"
    exit()
if s.count('N') > 0 and s.count('S') == 0:
    print "No"
    exit()
if s.count('W') > 0 and s.count('E') == 0:
    print "No"
    exit()
if s.count('E') > 0 and s.count('W') == 0:
    print "No"
    exit()
print "Yes"

Measured memory_bytes: 2568
#include <bits/stdc++.h>
#define int long long

using namespace std;

int n; string s;

int32_t main(){
        ios::sync_with_stdio(0), cin.tie(0);
        cin >> n >> s;
        for(int i = 0 ; i < (int)s.size(); i++ ){
                if(s[i]+n<='Z') s[i] += n;
                else s[i] = 'A' + n - ('Z'-s[i]) - 1 ;
        }
        cout << s << endl ;
        return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    int N;
    while(scanf("%d",&N)!=EOF)
    {
        int buf[N];
        for(int i = 0; i<N; i++)
        {
            scanf("%d",&buf[i]);
        }
        sort(buf,buf+N);
        int ptr = 0;
        int res = 0;
        //以下为找相同元素个数的方法
        while(ptr<N)
        {

            int lastNumber = buf[ptr];
            int countSum = 0;
            while(buf[ptr]==lastNumber&&ptr<N)
            {
                ptr++;
                countSum++;
            }
            res+=countSum%2;
        }
        printf("%d\n",res);
    }
    return 0;
}


Measured memory_bytes: 640
n = int(input())
P = [int(x) for x in input().split()]
Q = [int(x) for x in input().split()]

count = 0
p = -1
q = -1

A = [0 for _ in range(n)]
def calc(i):
    global p, q, count
    if p != -1 and q != -1:
        return
    if i == n:
        count += 1
        if A == P:
            p = count
        if A == Q:
            q = count
        return
    for j in range(1, n+1):
        A[i] = j
        flag = 0
        for k in range(i):
            if A[k] == j:
                flag = 1
        if flag == 0:
            calc(i + 1)

calc(0)
print(abs(p - q))

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

int main()
{
	int N, ans=0, tmp=0, cnt=0; cin >> N;
	vector<int> H(N); rep(i, N) cin >> H[i]; 
	
	rep(i, N) {
		if(tmp >= H[i]) {
			cnt++;
			tmp = H[i];
		}
		else {
			ans = max(ans, cnt);
			tmp = H[i];
			cnt = 0;
		}
		ans = max(ans, cnt);
	}
	cout << ans << endl;
}


Measured memory_bytes: 640