akhauriyash/Code-Regression huggingface dataset:
#include<iostream> 
#include<string>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<sstream>
using namespace std;

#define sf scanf
#define pf printf
#define pfn printf("\n");
#define pfk printf(" ");
#define pf0 printf("0");
#define pf1 printf("1");
#define ll long long
#define ull unsigned long long
#define sfd(n) scanf("%d",&n);
#define sfdd(n,m) scanf("%d%d",&n,&m);
#define sfld(n) scanf("%lld",&n);
#define sfldd(n,m) scanf("%lld%lld",&n,&m);
#define sflf(n) scanf("%lf",&n);
#define sflff(n,m) scanf("%lf%lf",&n,&m);
#define sfc(n) scanf("%c",n);
#define sfcc(n,m) scanf("%c%c",n,m);
#define sfs(n) scanf("%s",n);
#define sfss(n,m) scanf("%s%s",n,m);
#define pfd(n) printf("%d",n);
#define pfld(n) printf("%lld",n);
#define pflf(n) printf("%lf",n);
#define pfc(n) printf("%c",n);
#define pfs(n) printf("%s",n);

#define csh(a,n) memset(a,n,sizeof(a));
int main(){
	int n;
	cin>>n;
	map<string,int>mp;
	for(int i=0;i<n;i++){
		string a;
		cin>>a;
		mp[a]++;
	}
	int maxn=0;
	for(map<string,int>::iterator it=mp.begin();it!=mp.end();it++){
		if(it->second>maxn){
			maxn=it->second;
		}
	}
	for(map<string,int>::iterator it=mp.begin();it!=mp.end();it++){
		if(it->second==maxn){
			cout<<it->first<<endl;
		}
	}
}

Measured memory_bytes: 17664
x, n = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
q = []
for i in range(102):
	if i not in p:
		q.append(i)
q.sort(key=lambda z: abs(z-x))
if len(q) < 2:
	print(q[0])
else:
	if abs(q[0] - x) == abs(q[1] - x):
		print(min(q[0], q[1]))
	else:
		print(q[0])

Measured memory_bytes: 61764
from collections import deque
s = deque(input())
n = int(input())
initial = True
for i in range(n):
    order = list(input().split())
    if len(order) == 3:
        if initial:
            if int(order[1]) == 1:
                s.appendleft(order[2])
            else:
                s.append(order[2])
        else:
            if int(order[1]) == 1:
                s.append(order[2])
            else:
                s.appendleft(order[2])
    else:
        initial = not initial
    
if initial:
    print(''.join(s))
else:
    print(''.join(s)[::-1])

Measured memory_bytes: 8692
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(13)
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> Q;
//ll longinf=1ll<<60;
int inf=1<<29;
int dn[4]={-1,1,0,0};
int dm[4]={0,0,-1,1};
ll longinf=(1ll<<60);
char w[1001][1001];

int main(){
      ll x,y;
      cin>>x>>y;
      if(abs(x-y)<=1) cout<<"Brown"<<endl;
      else{
            cout<<"Alice"<<endl;
      }
      return 0;
}

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

#define EPS 1e-6
#define INF 0x3f3f3f3f
#define ll long long
#define ull unsigned long long
#define debug(x) cerr<<#x<<'='<<x<<' '
#define FOR(a,b,c) for(int a=(b),a##_end=(c);a<=a##_end;++a)
#define ROF(a,b,c) for(int a=(b),a##_end=(c);a>=a##_end;--a)
using namespace std;
template<class T>void Rd(T &res){
	char c;int f=1;res=0;
	while((c=getchar())<48)if(c=='-')f=-1;
	do res=(res<<1)+(res<<3)+(c^48);
	while((c=getchar())>47);
	res*=f;
}
ll n,A,B,C,D;
int main(){
	ll tmp;
	Rd(n),Rd(A),Rd(B),Rd(C),Rd(D);
	n--;
	tmp=B-A;
	FOR(i,0,n){
		ll fmin=-D*i,fmax=-C*i;
		ll zmin=C*(n-i),zmax=D*(n-i);
		if(zmin+fmin<=tmp&&zmax+fmax>=tmp){
			printf("YES\n");
			return 0;
		}
	}
	printf("NO\n");
	return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
p=[list(input().split())for _ in range(m)]
q=[0]*n
c=0
wc=0
for i in range(m):
  if p[i][1] == "WA":
    q[int(p[i][0])-1] += 1
  else:
    if q[int(p[i][0])-1] >= 0:
      c += 1
      wc += q[int(p[i][0])-1]
      q[int(p[i][0])-1] -= 10**6

print(c,wc)

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

#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

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

const int N = 1e3 + 5, M = 1e4 + 5;

ll DP[N * M];
int W[N], S[N], V[N], P[N];

int CMP(int i, int j) { return W[i] + S[i] < W[j] + S[j]; }

int main() {

	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	int n; cin >> n;
	for (int i = 0; i < n; i++) cin >> W[i] >> S[i] >> V[i], P[i] = i;
	sort(P, P + n, CMP);
	for (int i = 0; i < n; i++) {
		for (int j = S[P[i]]; j >= 0; j--) {
			DP[j + W[P[i]]] = max(DP[j + W[P[i]]], DP[j] + V[P[i]]);
		}
	}
	cout << *max_element(DP, DP + N * M) << endl;

	return 0;
}


Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
  int n,np,count=0,ans=0;
  while(cin>>n){
    if(n==0) break;
    n -= n%5;
    while(n!=0){
      np = n;
      while(np%5==0){
	count++;
	np /= 5;
      }
      ans += count;
      n -= 5;
      count = 0;
    } 
      cout << ans << endl;
      ans = 0; 
    }
  }

Measured memory_bytes: 1160
"use strict";
    
const main = arg => {
    const N = parseInt(arg.split("\n")[0]);
  	let ans = 0;
 	let m = 0;
  	let roopNum = Math.sqrt(N);
  	for(let i = 1; i <= roopNum; i++){
    	if(N % i == 0){
        	m = i
        }
    }
  	// 約数同士でどちらが大きいかを比較
	ans = N/m > m ? N/m : m;
  	console.log(String(ans).length);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
#include <stdio.h>

int main(void){
	long n, m, l, i, j, k, a[101][101] = {}, b[101][101] = {}, c[101][101] = {};
	scanf("%ld %ld %ld", &n, &m, &l);
	for(i = 0; i < n; i++){
		for(j = 0; j < m; j++){
			scanf("%ld", &a[i][j]);
		}
	}
	for(i = 0; i < m; i++){
		for(j = 0; j < l; j++){
			scanf("%ld", &b[i][j]);
		}
	}
	for(i = 0; i < n ; i++){
		for(j = 0; j < l ; j++){
			for(k = 0; k < m; k++){
				c[i][j] += a[i][k] * b[k][j];
			}
		}
	}
	for(i = 0; i < n; i++){
		for(j = 0; j < l; j++){
			if(j != l -1){
				printf("%ld ", c[i][j]);
			} else {
				printf("%ld\n", c[i][j]);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 848
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.HashSet;
import java.math.BigDecimal;

public class Main {
    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        String S = fs.next();
        System.out.println(S.substring(0,3)); 

        
  }
  public static int calcMin(int[] array) {

    int intMin = array[0];

    for (int i = 1; i < array.length; i++ ) {
        if(intMin > array[i]) {
            intMin = array[i];
        }
    }
    return intMin;
}
}
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 long nextLong(){
        if(!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        if(b < '0' || '9' < b){
            throw new NumberFormatException();
        }
        while(true){
            if('0' <= b && b<='9'){
                n*=10;
                n+=b-'0';
            }else if(b==-1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt(){
        long nl = nextLong();
        if(nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDoutble(){return Double.parseDouble(next());}
}


Measured memory_bytes: 32324
n,m=map(int,input().split())
G=[[] for _ in range(1+n)]
for i in range(m):
    a,b=map(int,input().split())
    G[a].append(b)
    G[b].append(a)

from collections import deque
vis=[0]*(1+n)

q=deque([1])
while q:
    now=q.popleft()
    for next in G[now]:
        if vis[next]==0:
            vis[next]=now
            q.append(next)
print('Yes')
for i in range(2,n+1):
    print(vis[i])


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

using namespace std;

int main(){

       string s;
       cin>>s;
       if(s=="SSS"){
        cout<<0<<endl;
       }
       else if(s=="SSR"){
            cout<<1<<endl;
       }
        else if(s=="SRS"){
            cout<<1<<endl;
       }
       else if(s=="SRR"){
            cout<<2<<endl;
       }
       else if(s=="RSS"){
            cout<<1<<endl;
       }
       else if(s=="RSR"){
            cout<<1<<endl;
       }
       else if(s=="RRS"){
            cout<<2<<endl;
       }
       else if(s=="RRR"){
            cout<<3<<endl;
       }

}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;
long long sum,r[40][100010];//a_jから2^i日で行ける最大距離がr[i][j]で位置を返す

int solve(int s, int t){
    int i,k;
    for(int i=0;i<40;i++){
        if(r[i][s]>=t){
            k = i;
            break;
        }
    }
    if(k==0){
        return sum;
    }else{
        sum += pow(2,k-1);
        solve(r[k-1][s],t);
    }
}

int main(){
    int i,j,n,q,s,t;
    vector<long long> a,b;
    long long x,l;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> x;
        a.push_back(x);
    }
    cin >> l >> q;
    for(i=0;i<n;i++){
        int y = upper_bound(a.begin(),a.end(),a[i]+l)-a.begin()-1;
        b.push_back(y);
    }
    for(i=0;i<n;i++){
        //cout << b[i] << endl;
    }

    for(i=0;i<40;i++){
        for(j=0;j<n;j++){
            if(i==0){
                r[i][j] = b[j];
            }else{
            r[i][j] = r[i-1][r[i-1][j]];
            }
        }
    }
    for(i=0;i<5;i++){
        for(j=0;j<n;j++){
            //cout << r[i][j] <<" " << i << " " << j << endl;
        }
    }
    for(i=0;i<q;i++){
        cin >> s >> t;
        if(s>t){
            int z = s;
            s = t;
            t = z;
        }
        s--; t--;
        sum = 1;
        solve(s,t);
        cout << sum << endl;
    }
}

Measured memory_bytes: 33780
#include<iostream>
#include<sstream>
#include<fstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
using namespace std;

int main(){
	int n;
	int tai[] = {512,256,128,64,32,16,8,4,2,1};
	while(scanf("%d",&n)==1){
		vector<int> sol;
		for(int x=0;x<10 && n>0;++x){
			if(n-tai[x]>=0){
				n -= tai[x];
				sol.push_back(tai[x]);
			}
		}
		for(int x=sol.size()-1;x>0;--x){
			cout<<sol[x]<<" ";
		}
		cout<<sol[0]<<endl;
	}
	return 0;
}

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

using namespace std;

int memo[100][100][2][2];

int w, h;

int rec(int i, int j, int vec, int f)
{
    if (i < 0 || i >= w) return 0;
    if (j < 0 || j >= h) return 0;

    if (i == w - 1 && j == h - 1) return 1;

    if (memo[i][j][vec][f] >= 0) return memo[i][j][vec][f];

    int res;

    if (vec == 0) { // ??????????????§?????´???
        if (f) { // ????????£???
            res = rec(i + 1, j, 0, 0);
        } else {
            res = rec(i + 1, j, 0, 0) + rec(i, j + 1, 1, 1);
        }
    } else { // ??????????????§?????´???
        if (f) { // ????????£???
            res = rec(i, j + 1, 1, 0);
        } else {
            res = rec(i + 1, j, 0, 1) + rec(i, j + 1, 1, 0);
        }
    }

    return memo[i][j][vec][f] = res % 100000;
}

int main()
{
    while (cin >> w >> h, w || h) {
        memset(memo, -1, sizeof(memo));

        cout << (rec(1, 0, 0, 0) + rec(0, 1, 1, 0)) % 100000 << endl;
    }
}

Measured memory_bytes: 1336
#include <bits/stdc++.h>
using namespace std;
#define double long double
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define debug(x) cerr<<#x<<": "<<x<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define vout(v) for(int i=0;i<(int)v.size()-1;i++){cout<<v[i]<<" ";}cout<<v[v.size()-1]<<"\n";
#define debg(a) cout<<#a<<" "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> V;
const long long MOD=1000000007;
const long long INF = 1e18;
vector <ll> dp;

const string YES = "YES";
const string NO = "NO";

void solve_old(std::string S){
    regex re("(dreamer|dream|eraser|erase)*");
    if(regex_match(S, re)){
        cout << YES << "\n";
    }else{
        cout << NO << "\n";
    }
}

void solve_old2(std::string S){
    regex re("(dreamer|dream|eraser|erase)*");
    cout << (regex_match(S, re) ? YES : NO) << "\n";
}

void solve(std::string S){
    cout << (regex_match(S, regex("(dream(er)?|eraser?)*")) ? YES : NO) << "\n";
}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 40960
#include "bits/stdc++.h"

typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define REP(i,n) for (int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
 
using namespace std;

signed main(){
    
    int  n,x;
    cin >> n >> x;
    int a[101];
    REP(i,n){
        cin >> a[i];
    }
    sort(a,a+n);
    
    int ans = 0;

    REP(i,n){
        if(i == n-1 && a[i] != x){
            break;
        }
        else if(a[i] <= x){
            x -= a[i];
            ans++;
        }else{
            break;
        }
        
    }
    cout << ans << endl;
    
    return 0;
}
//g++ -std=c++14 code1.cpp


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

using namespace std;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int test,l;
	cin >> test >> l;
	string t;
	vector<string> temp;
	for(int i = 0;i<test;i++) {
		cin >> t;
		temp.push_back(t);	
	}
	sort(temp.begin(), temp.end());
	for(int i = 0 ;i<test;i++) {
		cout << temp[i];
	}
}	

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std; 
#define int int64_t
#define itn int
#define fi first
#define se second
vector<int> v[20];
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,d,ans=0;
  int x,y;
  cin>>n>>d;
  for(int i=0;i<n;i++){
    cin>>x>>y;
    if(x*x+y*y<=d*d) ans++;
  }
  cout<<ans<<"\n";
}


Measured memory_bytes: 3644
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<functional>
#include<cstring>
using namespace std;
const int N=6,nC=324;
int n,C,L[N];
int f[1<<N-1][nC];
unsigned long long ans;
int main(){
	scanf("%d%d",&n,&C);
	for(int i=0;i<n;++i)scanf("%d",L+i);
	sort(L,L+n);
	int tot=0;
	do{
		++tot;
		memset(f,0,sizeof f);
		f[0][n*L[n-1]]=1; 
		for(int i=1;i<=n*C;++i)if(i%n){
			const int id=i%n-1,t=min(i+L[id]*n,n*C);
			for(int S=0;S<1<<n-1;++S)
			if(!(S>>id&1))
			for(int k=i;k<=n*C;++k)
			f[S|1<<id][max(k,t)]+=f[S][k];
		}
		ans+=f[(1<<n-1)-1][n*C];
	}while(next_permutation(L,L+n-1));
	printf("%.16g\n",1.*ans/tot/pow(C,n-1));
	return 0;
}

Measured memory_bytes: 256
object Main extends App {
  def calc(formula: List[(Char, Char)]): Int =
    formula.foldLeft(0) { case (acc, (op, number)) =>
      val int = number.toString.toInt
      if (op == '+') acc + int else acc - int
    }

  val sc = new java.util.Scanner(System.in)
  val numbers = sc.next().toCharArray
  val calcPatterns = for {
    ab <- List('+', '-')
    bc <- List('+', '-')
    cd <- List('+', '-')
  } yield {
    List('+', ab, bc, cd)
  }
  calcPatterns
    .map(_.zip(numbers))
    .collectFirst {
      case formula if calc(formula) == 7 =>
        formula.flatMap {
          case (op, number) => List(op, number)
        }.mkString("", "", "=7").tail
    }
    .foreach(println)
}


Measured memory_bytes: 55592
S=str(input())

Ans=[int(S[0]+S[1]),int(S[2]+S[3])]

if 0<Ans[0]<13 and 0<Ans[1]<13:
    print("AMBIGUOUS")
elif 0<Ans[0]<13:
    print("MMYY")
elif 0<Ans[1]<13:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3060
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
using namespace std;

int main(){
  long long n;
  cin >> n;
  long long p[n+1];
  long long pos[n+1];
  p[0] = 0;
  for(int i=1;i<n+1;i++){
    cin >> p[i];
    pos[p[i]] = i;
  }
  sort(p,p+n+1);
  reverse(p,p+n+1);
  multiset<int> s;
  s.insert(0);
  s.insert(0);
  s.insert(n+1);
  s.insert(n+1);
  s.insert(pos[p[0]]);
  long long ans = 0;

  for(int i=1;i<n;i++){
    int id;
    id = pos[p[i]];
    auto it = s.lower_bound(id);
    long long R1 = *it;
    it++;
    long long R2 = *it;
    it--;
    it--;
    long long L1 = *it;
    it--;
    long long L2 = *it;
    ans += p[i]*((L1-L2)*(R1-id)+(R2-R1)*(id-L1));
    s.insert(id);
  }
  cout << ans << endl;

  return 0;

}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a;cin>>a;
    if(a<2) cout<<1<<endl;
    else if(a<4)  cout<<2<<endl;
    else if(a<8)  cout<<4<<endl;
    else if(a<16) cout<<8<<endl;
    else if(a<32) cout<<16<<endl;
    else if(a<64) cout<<32<<endl;
    else          cout<<64<<endl;
    return 0;
} 

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

const int mod = 1000000007;


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

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

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};


int main(void){
    int N,K;
    cin >> N >> K;
    vector<int> vec(N);
    combination c(100005);
    for(int i=0;i<N;i++) cin >> vec[i];
    sort(vec.begin(),vec.end());

    mint ans = 0;
    for(int i=0;i<N;i++){
        ans += c(i,K-1) * vec[i];
    }

    reverse(vec.begin(),vec.end());
    for(int i=0;i<N;i++){
        ans -= c(i,K-1) * vec[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 2176
#!/usr/bin/env python3
import sys


def solve(N: int, d: "List[int]"):
    print(len(list(set(d))))
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    d = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, d)

if __name__ == '__main__':
    main()


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

#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (ll i = m; i < (n); i++)

using ll = long long;
using pii = pair<int, int>;
using Vi = vector<int>;

int main() {
  string s,t;
  cin >> s >> t;
  if(s[0]==t[2]&&s[1]==t[1]&&s[2]==t[0]){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 3624
#include "bits/stdc++.h"
#define all(v) v.begin(),v.end()
#define SZ(x) (int)x.size()
#define endl "\n"
#define thunder ios::sync_with_stdio(false);cin.tie(0);cout<<fixed<<setprecision(15);
using namespace std;
typedef long long int ll;
#ifdef ONLINE_JUDGE
#define debug(...)
#else
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#endif
void debug_out() { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return (size_t) x.first * 37U + (size_t) x.second;
  }
};
vector<pair<int,int>>vp;
unordered_map<pair<int,int>,ll,HASH>mp;
ll dp(int weight,int index)
{
    if(weight<0||index<0)return 0;
    if(mp[{weight,index}])return mp[{weight,index}];
    ll ans1=0;
    if(vp[index].first<=weight)
    {
        ans1+=(max(ll(vp[index].second)+dp(weight-vp[index].first,index-1),dp(weight,index-1)));
    }
    else
        ans1=dp(weight,index-1);
    mp[{weight,index}]=ans1;
    return ans1;


}
int main()
{
    thunder
    auto start = chrono::high_resolution_clock::now();
    mp.max_load_factor(0.25);
    mp.reserve(2048);
    int n,w;cin>>n>>w;
    vp.assign(n,{0,0});
    for(int i=0;i<n;++i)
    {
        cin>>vp[i].first>>vp[i].second;
    }

   cout<<dp(w,n-1);
   





   auto end = chrono::high_resolution_clock::now(); 
   double time_taken = chrono::duration_cast<chrono::nanoseconds>(end - start).count(); 
   time_taken *= 1e-9;
   debug(time_taken);
}

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

bool is_palindrome(string s) {
    string t(s.rbegin(), s.rend());
    return s == t;
}

int main() {
    string s;
    cin >> s;
    int n = s.size();
    if (is_palindrome(s) && is_palindrome(s.substr(0, (n-1)/2)) && is_palindrome(s.substr((n+1)/2))) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
fn main() {
    let x = read::<u32>();
    let a = read::<u32>();
    let b = read::<u32>();
    println!("{}", (x - a) % b);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

int main(){
    int n;
    while(cin>>n,n){
        char c[1000][1000];
        int dp[1000][1000]={0};
        int m=0;
        for(int i=0;i<n;i++){
            cin>>c[i];
            for(int j=0;j<n;j++){
                if(!i||!j){
                    if(c[i][j]=='.'){dp[i][j]=1;}
                    else dp[i][j]=0;
                }
            }
        }
        for(int i=1;i<n;i++){
            for(int j=1;j<n;j++){
                if(c[i][j]=='.'){
                    dp[i][j]=min(dp[i-1][j],min(dp[i][j-1],dp[i-1][j-1]))+1;
                    m=max(m,dp[i][j]);
                }
            }
        }
        cout<<m<<endl;
    }
}

Measured memory_bytes: 6052
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main() {
  int R[MAX], n;
  
  cin >> n;
  for ( int i = 0; i < n; i++ ) cin >> R[i];
  
  int maxv = -2000000000;
  int minv = R[0];
  
  for ( int i = 1; i < n; i++ ) {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }
  
  cout << maxv << endl;
  
  return 0;
}

Measured memory_bytes: 3868
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long lint;

const int maxn = 300;
const int mod = 1000099871, base = 31;

int hashes[maxn][maxn], inv_hashes[maxn][maxn];

int main() {
  int n;
  scanf("%d", &n);
  vector<string> board(n, string(n, ' '));
  for (int y = 0; y < n; ++y)
    scanf(" %s", &board[y][0]);

  for (int y = 0; y < n; ++y)
    for (int dx = 0; dx < n; ++dx) {
      int hash = 0;
      for (int x = 0; x < n; ++x) {
        int x2 = x + dx;
        if (x2 >= n) x2 -= n;
        hash = ((lint)hash * base + (board[y][x2] - 'a' + 1)) % mod;
      }
      hashes[y][dx] = hash;
    }

  for (int x = 0; x < n; ++x)
    for (int dy = 0; dy < n; ++dy) {
      int hash = 0;
      for (int y = 0; y < n; ++y) {
        int y2 = y + dy;
        if (y2 >= n) y2 -= n;
        hash = ((lint)hash * base + (board[y2][x] - 'a' + 1)) % mod;
      }
      inv_hashes[x][dy] = hash;
    }

  int base_pow_n = 1;
  for (int i = 0; i < n; ++i)
    base_pow_n = (lint)base_pow_n * n % mod;

  int result = 0;
  for (int dy = 0; dy < n; ++dy)
    for (int dx = 0; dx < n; ++dx) {
      int full_hash = 0;
      for (int y = 0; y < n; ++y) {
        int y2 = y + dy;
        if (y2 >= n) y2 -= n;
        full_hash = ((lint)full_hash * base_pow_n + hashes[y2][dx]) % mod;
      }

      int inv_full_hash = 0;
      for (int x = 0; x < n; ++x) {
        int x2 = x + dx;
        if (x2 >= n) x2 -= n;
        inv_full_hash =
            ((lint)inv_full_hash * base_pow_n + inv_hashes[x2][dy]) % mod;
      }

      if (full_hash == inv_full_hash) ++result;
    }
  printf("%d\n", result);

  return 0;
}


Measured memory_bytes: 1152
a,b,k = map(int,input().split())
small = [i for i in range(a,a+k) if a <= i <= b]
big = [i for i in range(b-k+1,b+1) if a <= i <= b]
for i in range(len(small)):
  if small[i] not in big:
    big.append(small[i])
big.sort()
for i in range(len(big)):
  print(big[i])

Measured memory_bytes: 9096
#include <stdio.h>

int n,A[20];

int solve(int,int);

int main(){
  int i,m,q;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&m);
    if(solve(0,m)==1) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}

int solve(int i,int m){
  int res;
  if(m==0)
    return 1;
  if(i>=n)
    return 0;
  res=solve(i+1,m) || solve(i+1,m-A[i]);
  return res;
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];
    int sum = accumulate(a.begin(), a.end(), 0);
    int maxE = *max_element(a.begin(), a.end());
    if ((sum - maxE)> maxE) cout << "Yes" << '\n';
    else cout << "No" << '\n';
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int c(char *p,int d){return ((26+*p-*(p+1))%26==d);}
int a(char *p){return((*p<'a')||(*p>'z'));}
char *decode (char *inbuf, int s) {
  int p = 0;
  while (inbuf[p] != 0) {
    if ((inbuf[p] >= 'a')&&(inbuf[p]<='z')) {
      int t = inbuf[p] + s;
      //inbuf[p] = inbuf[p] + (char)s;
      if (t > 'z')      inbuf[p] = (char)(t - 26);
      else if (t < 'a') inbuf[p] = (char)(t + 26);
      else              inbuf[p] = (char)t;
    }
    p++;
  }
  return (inbuf);
}

int main(){
  char inbuf[82];
  while(fgets(inbuf,80,stdin)){
    int s;
    char *p=inbuf;
    while(*p){
      s = 0;
      if(c(p,12)){
	if(c(p+1,3)){
	  if(a(p+3))
	    s = 't' - *p;
	}
	/* that */
	else if(c(p+1,7)){
	  if(c(p+2,7))
	    //	  if (*p-*(p+3) == 0)
	  if(a(p+4))
	      s = 't' - *p;
	}
	/* this */
	else if(c(p+1,25)){
	  if(c(p+2,16))
	    //	  if (((*p-*(p+3))==1)||((*p-*(p+3))==-25))
	  if(a(p+4))
	      s = 't' - *p;
	}
      }
      if (s) break;
      p++;
    }
    printf("%s",decode(inbuf, s));
  }
  return 0;
}

Measured memory_bytes: 524
#include<cstdio> 
#include<algorithm>
#define ll long long
#define MN 110001
using namespace std;
int read_p,read_ca,read_f;
inline int read(){
    read_p=0;read_ca=getchar();read_f=1;
    while(read_ca<'0'||read_ca>'9') {if (read_ca=='-') read_f=-1;read_ca=getchar();}
    while(read_ca>='0'&&read_ca<='9') read_p=read_p*10+read_ca-48,read_ca=getchar();
    return read_p*read_f;
}
int n,m; 
int abs(int x){return x<0?-x:x;}
ll min(ll a,ll b){return a<b?a:b;}
bool mmh[1000][1000],vis[1000][1000];
void dfs(int a,int b){
	if (vis[a][b]) return;
	vis[a][b]=1;
	for (int i=1;i*2<=a;i++)
	if (dfs(a-i-i,b+i),!mmh[a-i-i][b+i]) {mmh[a][b]=1;return;}
	for (int i=1;i*2<=b;i++)
	if (dfs(a+i,b-i-i),!mmh[a+i][b-i-i]) {mmh[a][b]=1;return;}
	mmh[a][b]=0;
}
ll x,y;
int main(){
	x=read();y=read();
	puts((y-x>=2||y-x<=-2)?"Alice":"Brown");
}

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

using namespace std;

#define N 16

const int mod=1000000007;
int n,m,ans,f[1<<N],ppc[1<<N],g[N];

void upd(int &x,int y){x=(x+y)%mod;}

int main(){
	scanf("%d%d",&n,&m);
	ans=1;
	for (int i=1;i<=m;++i){
		ans=ans*2%mod;
		int x,y; scanf("%d%d",&x,&y);
		--x; --y; g[x]|=1<<y;
	}
	for (int i=0;i<1<<n;++i)
		for (int j=0;j<n;++j) ppc[i]+=i>>j&1;
	f[0]=1;
	for (int i=1;i<1<<n;++i){
		for (int j=i;j;j=i&(j-1)){
			if ((j&1)^(j>>1&1)) continue;
			long long tmp=f[i^j];
			int k=i^j;
			for (int l=0;l<n;++l){
				if (j>>l&1){
					tmp=tmp*(1<<ppc[g[l]&k])%mod;
				}
				if (k>>l&1){
					tmp=tmp*((1<<ppc[g[l]&j])-1)%mod;
				}
			}
			upd(f[i],tmp);
		}
	}
	printf("%d\n",(ans-f[(1<<n)-1]+mod)%mod);
	
	return 0;
}
			

Measured memory_bytes: 512
#include <cstdio>
#include <string.h>
#include <array>

int main()
{
    std::array<char, 128> S;
    scanf("%s", S.data());

    std::string s(S.data());

    for (auto& c : s)
    {
        c = 'x';
    }
    printf("%s\n", s.c_str());
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
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<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

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

int main() {
    int m, d;
    cin >> m >> d;
    int ans = 0;
    FOR(x,1,d){
        int p = x % 10;
        int q = x / 10;
        int y = p * q;
        if (p >= 2 && q >= 2 && y >= 1 && y <= m) ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
//============================================================================
// Name        : Graph.cpp
// Author      : Ken
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

struct Node{
	int id;
	vector<int> adjNodes;
	bool isFound;
	int discover_time;
	int finish_time;
};

class Graph{
public:
	vector<Node> nodeList;
	Graph():nodeList(){}

	void insert(Node& i){
		nodeList.push_back(i);
	}

	void SearchDepthFirst(int source_id, int& timer){
		Node& source_node = nodeList.at(source_id);
		source_node.isFound = true;
		source_node.discover_time = timer;
		for(int i=0; i<source_node.adjNodes.size(); i++){
			if(nodeList.at(source_node.adjNodes.at(i)).isFound == false){
				timer ++;
				nodeList.at(source_node.adjNodes.at(i)).isFound = true;
				nodeList.at(source_node.adjNodes.at(i)).discover_time = timer;
				SearchDepthFirst(source_node.adjNodes.at(i), timer);
				nodeList.at(source_node.adjNodes.at(i)).finish_time = timer;
			}
		}
		timer++;

		source_node.finish_time = timer;
	}

	void SearchDepthFirstAll(int& timer){
		for(int i=0; i<nodeList.size(); i++){
			if(nodeList.at(i).isFound == false){
				SearchDepthFirst(i, timer);
				timer++;
			}
		}
	}

	void writeSearchResult(){
		for(int i=0; i<nodeList.size(); i++){
			cout << nodeList.at(i).id+1 << " " << nodeList.at(i).discover_time << " " << nodeList.at(i).finish_time << "\n";
		}
	}


	void write(){
		for(int i=0; i<nodeList.size(); i++){
			Node& node = nodeList.at(i);
			cout << node.id << " " << node.adjNodes.size() << " ";

			for(int j=0; j<node.adjNodes.size(); j++){
				cout << node.adjNodes.at(j) << " ";
			}
			cout << "\n";
		}

	}
};

void writeMatrix(vector<vector<int> > matrix){
	for(int i=0; i<matrix.size(); i++){
		for(int j=0; j<matrix.at(i).size()-1; j++){
			cout << matrix.at(i).at(j) << " ";
		}
		cout << matrix.at(i).at(matrix.at(i).size()-1);
		cout << "\n";
	}
}

int main() {
	int n;
	cin >> n;
	Graph g;

	for(int i=0; i<n; i++){
		int id, k;
		cin >> id >> k;
		vector<int> adjNodes;
		for(int j=0; j<k; j++){
			int input;
			cin >> input;
			adjNodes.push_back(input-1);
		}
		sort(adjNodes.begin(), adjNodes.end());
		Node node = {id-1, adjNodes, false, -1, -1};
		g.insert(node);
	}

	//g.write();
	int timer = 1;
	g.SearchDepthFirstAll(timer);
	g.writeSearchResult();

	return 0;
}



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

void wf(vector<vector<int>> &graph)
{
    int n = graph.size();
    for (int i = 0; i < n; i++)
        graph[i][i] = 0;
    for (int k = 0; k < n; k++)
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]);
}

int main()
{
    const int UNREACH = 1e9 + 1;
    int N, M, L;
    cin >> N >> M >> L;
    vector<vector<int>> g(N, vector<int>(N, UNREACH));
    int A, B, C;
    for (int i = 0; i < M; i++)
    {
        cin >> A >> B >> C;
        g[A - 1][B - 1] = C;
        g[B - 1][A - 1] = C;
    }

    wf(g);

    for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++)
            if (g[i][j] <= L)
                g[i][j] = 1;
            else
                g[i][j] = UNREACH;
    wf(g);

    int Q, s, t;
    cin >> Q;
    for (int i = 0; i < Q; i++)
    {
        cin >> s >> t;
        int ans;
        if (g[s - 1][t - 1] == UNREACH)
            ans = -1;
        else
            ans = g[s - 1][t - 1] - 1;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 896
str = input().split(" ")
h = int(str[0])
w = int(str[1])
A = [0 for i in range(h)]

# x yの値は0から始まる　一番北の時　y = 0
def sigma(x, y):
    sum = 0
    for i in range(h):
        for l in range(w):
            sum += min(abs(i-y), abs(l-x)) * A[i][l]
    return sum

for i in range(h):
    str = input().split(" ")
    A[i] = [int(str[l]) for l in range(w)]

minimum = float('inf')
for i in range(h):
    for l in range(w):
        s = sigma(l, i)
        if s < minimum:
            minimum = s
print(minimum)




Measured memory_bytes: 5612
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int h = sc.nextInt();
        int w = sc.nextInt();
        sc.nextLine();

        char s[][] = new char[h+2][w+2];
        for (int i = 1; i <= h; i++) {
            String line = sc.nextLine();
            for (int j = 1; j <= w; j++) {
                s[i][j] = line.charAt(j-1);
            }
        }

        int count = 0;
        for (int i = 1; i <= h; i++) {
            for (int j = 1; j <= w; j++) {
                if (s[i][j] == '#') {
                    if (s[i][j-1] == '#') continue;
                    if (s[i-1][j] == '#') continue;
                    if (s[i+1][j] == '#') continue;
                    if (s[i][j+1] == '#') continue;
                    System.out.println("No");
                    return;
                }
            }
        }
        System.out.println("Yes");
    }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
struct _I { _I() {cin.tie(0);ios::sync_with_stdio(false);}} __I;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) begin(a),end(a)
template<class F, class S> istream& operator >> (istream& s, pair<F, S>& p)
{ cin >> p.first >> p.second; return s;}
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

int main()
{
    int N; cin >> N;
    vpii AB(N); cin >> AB;
    sort(all(AB), [](const pii& x, const pii& y){return x.first+x.second > y.first+y.second;});

    ll ans = 0;
    rep(i, N) {
        if (i % 2 == 0) {
            ans += AB[i].first;
        } else {
            ans -= AB[i].second;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 1024
from copy import deepcopy
import sys
def main():
  input=sys.stdin.readline
  h,w,k=map(int,input().split())
  grid=[]
  for _ in range(h):
    s=input().rstrip()
    s=list(s)
    s=list(map(int,s))
    grid.append(s)
  def score(t):
    total=0
    for i in range(1,h):
      for j in range(w-1):
        cnt=1
        ten=gc[i][j]
        while gc[i][j+1]==gc[i][j]:
          cnt+=1
          j+=1
          if j==w-1:
            break
        if cnt>=k:
          total+=2**t*(ten*cnt)
          gc[i][j-cnt+1:j+1]=[0]*cnt
    return total
  def upd():
    while 1:
      ok=True
      for i in range(1,h):
        for j in range(w):
          if gc[i][j]==0 and gc[i-1][j]!=0:
            x=gc[i-1][j]
            gc[i-1][j]=0
            gc[i][j]=x
            ok=False
      if ok:
        return
  ans=0
  for i in range(1,h):
    for j in range(w):
      gc=deepcopy(grid)
      gc[i][j]=0
      t=0
      res=0
      while 1:
        upd()
        total=score(t)
        if total==0:
          break
        t+=1
        res+=total
      ans=max(ans,res)
  return print(ans)
if __name__=='__main__':
  main()

Measured memory_bytes: 55388
# A - Restricted

# 二つの整数 A B を入力
# A + B を出力
# A + B >= 10 の時 error と出力

# A B を標準入力から得る
A, B = map(int, input().split())
# print(A, B)

# A + B < 10 の時 A + B を代入
# それ以外は error を代入

if (A + B) < 10:
    answer = A + B
else:
    answer = "error"

# 結果を出力
print(answer)


Measured memory_bytes: 9152
n=int(input())
s=input().split()
s=[int(o) for o in s]
left=dict()
right=dict()
def count_nums(mydict,o):
  if o in mydict.keys():
    mydict[o]+=1
  else:
    mydict[o]=1
flag=True
for o in s:
  if flag:
    count_nums(left,o)
    flag=False
  else:
    count_nums(right,o)
    flag=True
myleft=sorted(left.keys(),key=lambda x: left[x])
myright=sorted(right.keys(),key=lambda x: right[x])
if myleft[-1]!=myright[-1]:
  print( len(s)-left[myleft[-1]]-right[myright[-1]])
else:
  a0,b0=left[myleft[-1]],right[myright[-1]]
  a1=0 if len(myleft)==1 else left[myleft[-2]]
  b1=0 if len(myright)==1 else right[myright[-2]]
  print( len(s)-max(a0+b1,a1+b0))

Measured memory_bytes: 17568
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);


 int main(){

    IOS;
	
   #ifndef ONLINE_JUDGE
     freopen("input1.txt","r",stdin);
     freopen("output1.txt","w",stdout);
   #endif

     int n,c;
   	cin>>n;
    c=n%1000;
    if(c)
      cout<<1000-c;
    else
      cout<<0;
   

   return 0;
 }   


Measured memory_bytes: 3548
const lines=readlines()
#input()=popfirst!(lines)
input()=shift!(lines)
int(s::String)=parse(Int,s)
intSub(s)=parse(Int,s)
intSplit(s::Array{SubString{String},1})=map(intSub,s)
intLine()=input()|>split|>intSplit
function main()
    n,k=intLine()
    if k>(n-2)*~-n//2
        println(-1)
        exit()
    end
    d=[[i,j] for i=1:n for j=i+1:n][1:end-k]
    println(length(d))
    for (i,j) in d
        println(i,' ',j)
    end
end
main()

Measured memory_bytes: 118856
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back;
#define IOS ios_base::sync_with_stdio(NULL);cin.tie(0);cout.tie(0)
using namespace std;
int main(){
    IOS;
    long long a,b;
    cin>>a>>b;
    cout<<min(a%b, b- a%b)<<endl;

}

Measured memory_bytes: 256
N,Q = map(int,input().split())
S = input()
lr = []
for i in range(Q):
    l,r = map(int,input().split())
    lr.append((l-1,r-1))
AC = [0]*N
for i in range(1,N):
    if S[i-1:i+1] == "AC":
        AC[i] = AC[i-1]+1
    else:
        AC[i] = AC[i-1]
for l,r in lr:
    print(AC[r]-AC[l])

Measured memory_bytes: 21960
#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;

int M;

inline int madd(int x,int y) {
	if (x+y<M) return x+y; else return x+y-M;
}
inline int msub(int x,int y) {
	if (x-y>=0) return x-y; else return x-y+M;
}
inline int mmul(int x,int y) {
	return int(ll(x)*y % M);
}

template<class T,int N,int P,int M>
void matmul(T res[N][M], const T A[N][P], const T B[P][M]) { // res=A*B
	static T tmp[N][M];
	rep(i,0,N) rep(j,0,M) tmp[i][j]=0;
	rep(i,0,N) rep(j,0,M) rep(k,0,P) {
		tmp[i][j]=madd(tmp[i][j], mmul(A[i][k],B[k][j]));
	}
	rep(i,0,N) rep(j,0,M) res[i][j]=tmp[i][j];
}

template<class T,int N,int M>
void matpow(T res[N][M], const T A[M][M], ll p) { // res=res*A^p
	static T tmp[M][M];
	rep(i,0,M) rep(j,0,M) tmp[i][j]=A[i][j];
	while (p>0) {
		if (p%2) matmul<T,N>(res,res,tmp);
		matmul<T,M>(tmp,tmp,tmp);
		p/=2;
	}
}

int len(ll x) {
	assert(x>0);
	int res=0;
	while (x>0) {
		x/=10;
		res++;
	}
	return res;
}

ll find_len(ll L,ll A,ll B) {
	int z=len(A);
	ll l=0,r=L;
	while (l<r) {
		ll m=l+(r-l)/2;
		if (z==len(A+B*m)) l=m+1; else r=m;
	}
	return l;
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	ll L,A,B;
	cin>>L>>A>>B>>M;
	
	int sum=0;
	while (L>0) {
		ll k=find_len(L,A,B);
		int p=1;
		rep(i,0,len(A)) p=mmul(p,10);
		int r[1][3]={{sum,int(A%M),1}};
		int X[3][3]={{p,0,0},
		             {1,1,0},
		             {0,int(B%M),1}};
		matpow<int,1>(r,X,k);
		
		sum=r[0][0];
		L-=k;
		A+=B*k;
	}
	
	cout<<sum<<"\n";
}


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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef _DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif



signed main() {

    int N;
    cin>>N;
    vector<int> a(N);
    rep(i,N) cin >> a[i];
    sort(a.begin(), a.end(), greater<int>());
    
    int x=0, y=0;
    rep(i,N){
        if(i%2==0)x+=a[i];
        else y+=a[i];
    }
    cout << x-y << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <set>
using namespace std;
int main(){
    long long N, M;
    cin >> N >> M;
    vector<long long> p(M);
    vector<string> S(M);
    set<int> s;
    vector<int> cnt(100010, 0);
    int cntac = 0, cntwa = 0;
    for(int i = 0; i < M; i++) {
        cin >> p[i] >> S[i];
        if(!s.count(p[i]) && S[i] == "AC") {
            cntac++;
            s.insert(p[i]);
        }
        if(!s.count(p[i]) && S[i] == "WA") {
            cnt[p[i]]++;
        }
    }
    for(int i = 0; i < 100010; i++){
        if(s.count(i)) cntwa += cnt[i];
    }
    cout << cntac << ' ' << cntwa << endl; 
}

Measured memory_bytes: 12028