akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <fstream>

using namespace std;

#define ll long long
#define INF 2000000000
#define LINF 9000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define dum(x) cout<<#x<<'='<<x<<endl
#define dum2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define dum3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl
#define ddd ifstream in("Text.txt");cin.rdbuf(in.rdbuf());


struct unionfind {
    vector<int> par; // par[i]:iの親の番号  par[3] = 2 : 3の親が2

    unionfind(int N) : par(N + 1) { //最初は全てが根であるとして初期化
        for (int i = 0; i < N; i++) par[i] = i;
    }

    int parfind(int x) {//親探し、どの集合に属しているか判定(直線DFS)
        if (par[x] == x) return x;
        return par[x] = parfind(par[x]);
    }

    void unite(int x, int y) {//木を併合
        int rx = parfind(x);
        int ry = parfind(y);
        if (rx == ry) return; //そのまま
        par[rx] = ry; //xとyの根が同じでない時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { //2つのデータx, yが属する木が同じならtrueを返す
        int rx = parfind(x);
        int ry = parfind(y);
        return rx == ry;
    }
};

int perm[100001];
int num[100001];

int main() {
    int N, M;
    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        cin >> perm[i];
        perm[i]--;
        num[i] = i;
    }

    unionfind uf(N);
    for (int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        uf.unite(x, y);
    }

    int cou = 0;
    for (int i = 0; i < N; i++) {
        if (uf.same(perm[i], num[i]))cou++;
    }
    cout << cou << endl;

}


Measured memory_bytes: 1408
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
    int a,b;
    cin >>a >>b;
    int c = a / b;
    int d = a % b;
    
    double A,B;
    A = a;
  
    double e = A / b;
    
    printf("%d %d %f", c, d, e);
    return 0;
}


Measured memory_bytes: 3192
Q=int(input())

prime=[1]*100000
sum2017=[0]*100000
count=0
for i in range(2,10**5):
  if prime[i-1]==1:
    for j in range(i-1+i,10**5,i):
      prime[j]=0
for i in range(0,10**5,2):
  if prime[i]==1 and prime[i//2]==1:
    count+=1
  sum2017[i]=count
  
for i in range(Q):
  l,r=map(int,input().split())
  if l!=1 and sum2017[l-1]!=sum2017[l-3]:
    print(sum2017[r-1]-sum2017[l-1]+1)
  else:
    print(sum2017[r-1]-sum2017[l-1])

Measured memory_bytes: 4980
#include<stdio.h>

int main(){
  int a,i,key,j,N,k;
  int A[1000];
  
  scanf("%d",&N);

  for(i = 0; i <= N-1; i++) scanf("%d",&A[i]);
  
  for(k = 0; k <= N-1; k++){
    if(k > 0) printf(" ");
    printf("%d",A[k]);
  }
  printf("\n");
  
  for(i = 1; i <= N-1; i++){
    key = A[i];
    j = i-1;
    while(j >= 0 && A[j] > key){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = key;

  for(k = 0; k <= N-1; k++){
    if(k > 0) printf(" ");
    printf("%d",A[k]);
  }
  printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2072
#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define mk  make_pair
#define pb  push_back


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    ll n,k,sum=0;
    cin>>n>>k;
    for(ll i=0;i<k;i++){
        ll a;
        cin>>a;
        sum+=a;
    }
    if(sum>n) cout<<-1<<endl;
    else cout<<n-sum<<endl;
    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)(x).size())
#define all(x) x.begin(),x.end()
#define mem0(s) memset(s,0,sizeof(s))
#define meminf(s) memset(s,0x3f,sizeof(s))
#define mp_insert(a,b,c) mp.insert(map<pair<int,int>,int>::value_type(make_pair(a,b),c))
double pi=acos(-1);
typedef long long ll;
typedef unsigned long long ull;
inline ll lowbit(ll x){return x&(-x);}
inline ll min(ll a,ll b){return a<b?a:b;}
inline ll max(ll a,ll b){return a>b?a:b;}
const int INF=0x3f3f3f3f,max_n=200005,mod=998244353;
inline ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
inline ll pow(ll a,ll b,ll mod){ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
deque<char>q;
string s;
int f;
char c;
int fanzhuan=1;//1±íÊ¾Ã»ÓÐ·­×ª£¬-1±íÊ¾ÒÑ¾­·­×ª
int x;
int t;
int main()
{
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		q.pb(s[i]);
	}
	cin>>x;
	for(int i=1;i<=x;i++)
	{
		cin>>t;
		if(t==1)
		{
			fanzhuan=-fanzhuan;
		}
		else if(t==2)
		{
			cin>>f>>c;
			if(f==1)//¼Óµ½¿ªÍ·
			{
				if(fanzhuan==1)
				{
					q.push_front(c);
				}
				else if(fanzhuan==-1)
				{
					q.pb(c);
				}
			}
			else if(f==2)
			{
				if(fanzhuan==1)
				{
					q.pb(c);
				}
				else
				{
					q.push_front(c);
				}
			}
		}
	}
	if(fanzhuan==1)
	{
		for(auto it=q.begin();it!=q.end();it++)
		{
			cout<<*it;
		}
		cout<<endl;
	}
	else if(fanzhuan==-1)
	{
		for(auto it=q.end()-1;it>=q.begin();it--)
		{
			cout<<*it;
		}
		cout<<endl;
	}
}

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

int A, B;

void eatCookieA() {
  if(A % 2 == 1) {
    A--;
    A /= 2;
    B += A;
  } else {
    A /= 2;
    B += A;
  }
}

void eatCookieB() {
  if(B % 2 == 1) {
    B--;
    B /= 2;
    A += B;
  } else {
    B /= 2;
    A += B;
  }
}

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

  int K;
  cin >> A >> B >> K;


  for(int i = 0; i < K; i++) {
    if(i % 2 == 0) eatCookieA();
    else eatCookieB();
  }

  cout << A << " " << B << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(int (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define mp make_pair
const ll MOD=1e9+7;
using namespace std;

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a==b && b==c){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
n = int(input())
d = list(map(int,input().split()))

def po(hiki, rui):
    so = 1
    for i in range(rui):
        so = (so*hiki)%998244353
    return so

max_d = 0
for i in range(n):
    if max_d < d[i]:
        max_d = d[i]


m = [0 for i in range(10**5)]

for i in range(n):
    m[d[i]] += 1

#失敗判定
sip = 0
for i in range(1,max_d+1):
    if m[i] == 0:
        sip = 1
if d[0] != 0:
    sip = 1
if m[0] > 1:
    sip = 1

if sip:
    print(0)
else:
    ans = 1
    for i in range(1,max_d + 1):
        kop = po(m[i-1],m[i])
        ans = (ans * kop)%998244353
    print(ans)

Measured memory_bytes: 56748
#include "bits/stdc++.h"
using namespace std;

int main() {
	
	int t, n;
	cin >> t >> n;
	int arr[n];
	for (int i=0; i<n; i++) cin >> arr[i];
	int sm[n];
	partial_sum(arr, arr+n, sm);
	if (sm[n-1] >= t) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int INF = 0xfffffff;
const int MAXN = 2010;
const int MAXM = 50010;
struct Edge{
    int u, v, f, nxt;
};
int N, M;
int nume;
int g[MAXN];
Edge e[MAXM];
int fa[MAXN];
void addEdge(int u, int v, int c)
{
    e[++nume].v = v;
    e[nume].u = u;
    e[nume].f = c;
    e[nume].nxt = g[u];
    g[u] = nume;
}

bool cmp(Edge a, Edge b)
{
    return a.f < b.f;
}
int getfather(int x)
{
    if(x == fa[x])
        return x;
    else
        return fa[x] = getfather(fa[x]);
}
int kruscal() {
    vector<int> vec;
    sort(e+1, e+nume+1, cmp);
    int cnt = N;
    for(int i = 1; i <= N; i++)  fa[i] = i;
    for(int i = 1; i <= nume; i++) {
        int t1 = getfather(e[i].u);
        int t2 = getfather(e[i].v);
        if(t1 != t2) {
            fa[t1] = t2;
            cnt--;
            vec.push_back(e[i].f);
            if(cnt==1)
                break;
        }
    }
    //for(int i = 0; i < vec.size(); i++)
    //    cout<<vec[i]<<endl;
    //sort(vec.begin(), vec.end());
    return vec[vec.size()/2];
    //if(vec.)
}
int main()
{
    while(cin>>N>>M&&N&&M) {
        nume = 0;
        memset(g, 0, sizeof(g));
        for(int i = 1; i <= M; i++) {
            int x, y, xy;
            cin>>x>>y>>xy;
            addEdge(x, y, xy);
            addEdge(y, x, xy);
        }
        cout<<kruscal()<<endl;
    }
    return 0;
}

Measured memory_bytes: 1560
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf8");

var reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on("line", (line: string): void => {
  const str: string = line.split(/\s/).map((x: string) => parseInt(x)).sort().toString(); 
  console.log(str === '5,5,7' ? 'YES' : 'NO');
});

Measured memory_bytes: 7628
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;

template <typename Tp> inline void getint(Tp &num){
	register int ch, neg = 0;
	while(!isdigit(ch = getchar())) if(ch == '-') neg = 1;
	num = ch & 15;
	while(isdigit(ch = getchar())) num = num * 10 + (ch & 15);
	if(neg) num = -num;
}

struct pair_hash{
	template <typename T1, typename T2>
		size_t operator() (const pair<T1, T2> &p) const
			{return hash<T1>()(p.first) ^ hash<T2>()(p.second);}
};

int N, x[55], y[55], ans = 0;
unordered_map<pair<int, int>, int, pair_hash> mp;

int main(){
	getint(N);
	for(register int i = 1; i <= N; i++) getint(x[i]), getint(y[i]);
	for(register int i = 1; i <= N; i++)
		for(register int j = 1; j <= N; j++) if(i != j)
			ans = max(ans, ++mp[make_pair(x[i] - x[j], y[i] - y[j])]);
	return printf("%d\n", N - ans), 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
#define NIL -1
//#define INFTY 1000000000000000000

int main(){
    LL n;
    LL x;
    LL m;
    cin >> n >> x >> m;
    vector<bool> is_visit(m, false);
    vector<LL> visit_idx(m, NIL);
    is_visit[x]=true;
    visit_idx[x]=1;
    LL first_visit_idx=NIL;
    LL second_visit_val=NIL;
    LL second_visit_idx=NIL;
    LL ans=0;
    LL tmp_x;
    if(n<=m){
        tmp_x=x;
        for(LL i=1; i<=n; i++){
            ans+=tmp_x;
            tmp_x=(tmp_x*tmp_x)%m;
        }
    }else{
        LL tmp_x=x;
        if(m==1){
            second_visit_val=n%m;
            ans=0;
        }else{
            for(LL i=2; i<=m; i++){
                tmp_x=(tmp_x*tmp_x)%m;
                if(is_visit[tmp_x]==true){
                    second_visit_val=tmp_x;
                    second_visit_idx=i;
                    break;
                }else{
                    is_visit[tmp_x]=true;
                    visit_idx[tmp_x]=i;
                }
            }
            first_visit_idx=visit_idx[second_visit_val];
            tmp_x=x;
            for(LL i=1; i<first_visit_idx; i++){
                ans+=tmp_x;
                tmp_x=(tmp_x*tmp_x)%m;
            }
            tmp_x=second_visit_val;
            LL tmp_ans=0;
            for(LL i=first_visit_idx; i<second_visit_idx; i++){
                tmp_ans+=tmp_x;
                tmp_x=(tmp_x*tmp_x)%m;
            }
            LL res=n-(first_visit_idx-1);
            ans=ans+tmp_ans*(res/(second_visit_idx-first_visit_idx));
            res=res%(second_visit_idx-first_visit_idx);
            tmp_x=second_visit_val;
            for(LL i=0; i<res; i++){
                ans+=tmp_x;
                tmp_x=(tmp_x*tmp_x)%m;            
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4044
#include <cstdio>
#define maxn 200005
#define MOD 1000000007LL
using namespace std;

typedef long long LL;

LL a[maxn];

int main(int argc, char** argv)
{
	int n;
	scanf("%d", &n);
	for(int i=0; i<n; i++)
		scanf("%lld", a + i);
	LL sum = a[0], res = 0LL;
	for(int i=1; i<n; i++)
	{
		res += sum * a[i];
		sum += a[i];
		res %= MOD, sum %= MOD;
	}
	printf("%lld\n", res);
	return 0;
}

Measured memory_bytes: 3256
K = int(input())
S = input()

mod = 10**9 + 7

class Combination:
    def __init__(self, n):
        self.facts = [1 for i in range(n+1)]
        self.invs = [1 for i in range(n+1)]
        
        for i in range(1, n+1):
            self.facts[i] = self.facts[i-1] * i % mod
            self.invs[i] = pow(self.facts[i], mod-2, mod)

    def ncr(self, n, r):
        if n < r:
            return 0
        if n < 0 or r < 0:
            return 0
        else:
            return self.facts[n] * self.invs[r] * self.invs[n-r] % mod

    def nhr(self, n, r):
        if n < r:
            return 0
        if n < 0 or r < 0:
            return 0
        else:
            return self.ncr(n+r-1, n-1)

N = K+len(S)
comb = Combination(K+len(S))

ans = 0
for i in range(K+1):
    ans = (ans + comb.ncr(N-i-1, len(S)-1) * pow(25, N-i-len(S), mod) * pow(26, i, mod)) % mod

print(ans)

Measured memory_bytes: 214456
#include <iostream>
#include <vector>
bool input (std::vector<int> & v)
{
	for (std::vector<int>::size_type i = 0; i < v.size(); i++) {
		if(!(std::cin >> v[i])) return false;
	}
	return true;
}
void get_hit_blow(int & hit, int & blow, std::vector<int> a, std::vector<int> b)
{
	for (int i = 0; i < 4; i++) {
		if (a[i] == b[i]) ++hit;
		for (int j = 0; j < 4; j++) {
			if (a[i] == b[j]) ++blow;
		}
	}
}
int main()
{
	std::vector<int> a(4), b(4);
	while (input(a) && input(b)) {
		int hit = 0, blow = 0;
		get_hit_blow(hit, blow, a, b);
		std::cout << hit << ' ' << blow - hit << std::endl;
	}
}

Measured memory_bytes: 1212
import string
h,w = (int(i) for i in input().split())
a = []
for i in range(h):
 a.append(list(input().split()))
query = string.ascii_uppercase
for j in range(h):
  for k in range(w):
    if a[j][k] == 'snuke':
      print(query[k]+str(j+1))
    

Measured memory_bytes: 3772
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class Main {
  public static void main(String[] args){
    new Main();
  }
  public Main(){
    Scanner sc = new Scanner(System.in);
    while(true){
      int n = sc.nextInt();
      if(n==0)break;
      ArrayList<team> tms = new ArrayList<>();
      for(int i=0;i<n;i++){
        tms.add(new team(sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt()));
      }
      Collections.sort(tms, new teamComp());
      int[] count = new int[1001];
      int saiyo = 0;
      for(int i=0;i<n;i++){
        int lim;
        if(saiyo<10)lim = 3;
        else if(saiyo<20)lim = 2;
        else if(saiyo<26)lim = 1;
        else break;
        team tm = tms.get(i);
        if(count[tm.school]>=lim)continue;
        count[tm.school]++;
        saiyo++;
        System.out.println(tm.id);
      }
    }
  }
  private class team{
    public int id, school, ac, penalty;
    public team(int id,int school,int ac,int penalty){
      this.id = id;
      this.school = school;
      this.ac = ac;
      this.penalty = penalty;
    }
  }
  private class teamComp implements Comparator<team>{
    public int compare(team a, team b){
      if(a.ac > b.ac) return -1;
      else if(a.ac < b.ac) return 1;
      else{
        if(a.penalty > b.penalty) return 1;
        else if(a.penalty < b.penalty) return -1;
        else{
          if(a.id > b.id) return 1;
          else return -1;
        }
      }
    }
  }
}

Measured memory_bytes: 29416
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var N = sc.ReadLong();
        var P = sc.ReadLong();
        var pf = PrimeFactors(P);

        var group = pf.GroupBy(p => p).Where(g => g.Count() >= N);
        long ans = 1;
        foreach (var g in group)
        {
            ans *= (long)Math.Pow(g.Key, g.Count() / N);
        }
        Console.WriteLine(ans);
    }

    static List<long> PrimeFactors(long n)
    {
        var res = new List<long>();
        var tmp = n;
        for (long x = 2; x * x <= n; x++)
        {
            while (tmp % x == 0)
            {
                tmp /= x;
                res.Add(x);
            }
        }
        if (tmp != 1) res.Add(tmp);
        return res;
    }

    static int MOD = (int)1e9 + 7;
    static int INF = (int)1e7 + 1;
    static long LINF = (long)1e13 + 1;
    static Scanner sc = new Scanner();
}

class Scanner
{
    string[] S = new string[0];
    int Index = 0;
    char[] Separators = new char[] { ' ' };

    public string Next()
    {
        if (this.Index < this.S.Length) return this.S[this.Index++];
        var line = "";
        while (line == "") line = Console.ReadLine();
        this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
        if (this.S.Length == 0) return this.Next();
        this.Index = 0;
        return this.S[this.Index++];
    }
    public string ReadStr()
    {
        return this.Next();
    }
    public char ReadChar()
    {
        return this.Next()[0];
    }
    public int ReadInt()
    {
        return int.Parse(this.Next());
    }
    public uint ReadUInt()
    {
        return uint.Parse(this.Next());
    }
    public long ReadLong()
    {
        return long.Parse(this.Next());
    }
    public double ReadDouble()
    {
        return double.Parse(this.Next());
    }
    public int[] ReadIntArray(int n)
    {
        var array = new int[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadInt();
        }
        return array;
    }
    public long[] ReadLongArray(int n)
    {
        var array = new long[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadLong();
        }
        return array;
    }
    public double[] ReadDoubleArray(int n)
    {
        var array = new double[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadDouble();
        }
        return array;
    }
    public char[] ReadCharArray(int n)
    {
        var array = new char[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadChar();
        }
        return array;
    }
    public string[] ReadStrArray(int n)
    {
        var array = new string[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadStr();
        }
        return array;
    }
}



Measured memory_bytes: 13524
# coding: utf-8
N, Y = map(int, input().split())
for i in range(N+1):
    for j in range(N + 1 - i):
        if (Y - 10000*i - 5000*j) % 1000 == 0 and (Y - 10000*i - 5000*j) / 1000 == N-i-j:
            print(i, j, N-i-j)
            # print(10000*i + 5000*j + 1000*(N-i-j))
            exit()
            
print(-1, -1, -1)

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

int main(){
	
	int n,p,num,sum;
	int player[50]={};
	
	while(1){
		cin >> n >> p ;
		if( n==0 && p==0 ) break;
		
		num=0; sum=p;
		for( int i=0 ; i<n ; i++ ) player[i] = 0 ;
		
		while(1){
			if( p==0 ){
				p = player[num%n] ;
				player[num%n] = 0 ;
			}else{
				player[num%n]++;
				p--;
			}
			
			if( sum == player[num%n] ) break;
			
			num++;
		}
		
		cout << num%n << endl ;
	}
	
return 0;
}

Measured memory_bytes: 1160
N,P=map(int,input().split())
A=list(map(int,input().split()))

def C(u,d):
    a=1
    b=1
    for i in range(d):
        a*=(u-i)
        b*=(d-i)
    return a//b

odd=0
even=0
for a in A:
    if a%2==1:
        odd+=1
    else:
        even+=1

ans=0
for i in range(odd+1)[P%2::2]:
    ans+=C(odd,i)

temp=0
for i in range(even+1):
    temp+=C(even,i)
    
print(int(ans*temp))


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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair< int , int > P;
typedef tuple<int, int, int> T;
    

int main(){
    int l ,r,d;
    cin>>l>>r>>d;
    int ans=0;
    for(int i=l;i<=r;i++){
        if(i%d==0) ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 3672
#include<stdio.h>
int fp[10001];
main(){
  int n,m,j,i;

  while(1){

    scanf("%d %d",&n,&m);
    
    if(n==0 && m==0) break;
    
    for(i=0;i<n;i++){
      fp[i]=i+1;
    }
    
    i=0;

    m=m-1;
    
    while(1){

      i=(i+m)%n;

      for(j=0;j<(n-1)-i;j++){
	fp[i+j]=fp[i+j+1];
      }
      n--;
      if(n==1) break;
    }
    
    printf("%d\n",fp[0]);
  }
 
  return 0;
}

Measured memory_bytes: 0
k = int(input())

def sunuke(num):
  hoge = num
  result = 0
  while hoge >= 10:
    result += hoge % 10
    hoge /= 10
  result += hoge
  return num / result

s = 1
sukima = 1
count = 0
while count < k:
  print(s)
  after = sunuke(s + sukima * 10)
  before = sunuke(s + sukima)
  if after < before:
    sukima *= 10
  s += sukima
  count += 1

Measured memory_bytes: 3188
#include<iostream>
#include<string>

int main(void){
	std::string S,T;
	std::cin >> S >> T ;
	
	int cnt=0;
	int sSize = S.size();
	bool isSame = false;
	while (isSame==false && cnt<sSize) {
		isSame=true;
		for (int i=0;i<sSize;i++) if (S.at(i)!=T.at((i+cnt)%sSize)) isSame=false;
		cnt++;
	}
	
	if (isSame) std::cout << "Yes" << '\n';
	else std::cout << "No" << '\n';
	
	return 0;
}

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

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

void solve()
{
    int n; cin >> n;
    int mod = 1e9+7;
    ll total = modpow(10, n, mod);
    total -= 2 * modpow(9, n, mod);
    total += modpow(8, n, mod);
    total %= mod;
    if (total < 0) total += mod;
    cout << total << '\n';
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using cmp=complex<double>;
const ll P=200003;
const int lg=19,N=1<<lg;
int n,vl[1<<18],rev[N];
ll ans,cnt[1<<18],rans;
cmp a[N],w[lg][N];
basic_string<int> v;
ll po(ll a,ll b,ll c){ll r=1;for(;b;b/=2,a=a*a%c)if(b&1)r=r*a%c;return r;}
void FFT(cmp*a){
	for(int i=0;i<N;i++)if(i<rev[i])swap(a[i],a[rev[i]]);
	for(int i=0;i<lg;i++)
		for(int j=0;j<N;j++)if(j>>i&1){
			cmp l=a[j^1<<i],r=a[j]*w[i][j&(1<<i)-1];
			a[j^1<<i]=l+r,a[j]=l-r;
		}
}
int main(){
	scanf("%d",&n);
	for(int j=0;j<P-1;j++)vl[po(2,j,P)]=j;
	for(int i=1;i<=n;i++){
		int x;scanf("%d",&x);
		if(x)a[vl[x]]+=1.;
		ans-=1ll*x*x%P;
	}
	for(int i=0;i<N;i++)rev[i]=rev[i/2]/2|i%2<<lg-1;
	for(int i=0;i<lg;i++)
		for(int j=0;j<(1<<i);j++)w[i][j]=exp(acos(-1)*j/(1<<i)*cmp{0.,1.});
	FFT(a);
	for(int i=0;i<N;i++)a[i]=conj(a[i]*a[i]);
	FFT(a);double rv=1./N;
	for(int i=0;i<N;i++)
		cnt[i%(P-1)]+=ll(a[i].real()*rv+.5);
	for(int i=0;i<P-1;i++)
		rans+=cnt[i]*po(2,i,P);
	printf("%lld\n",(rans+ans)/2);
	return 0;
}

Measured memory_bytes: 25004
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

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

  int counter[10][10];
  memset(counter, 0, sizeof(counter));

  for (int n = 1; n <= N; ++n) {
    string s = to_string(n);

    int f = s[0] - '0';
    int l = s[s.size() - 1] - '0';

    ++counter[f][l];
  }

  ll ans = 0;

  for (int i = 1; i <= 9; ++i) {
    for (int j = 1; j <= 9; ++j) {
      ll a = counter[i][j];
      ll b = counter[j][i];

      ans += (a * b);
    }
  }

  cout << ans << endl;

  return 0;
}


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

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

string n;

void rec(int digits, vector<ll> &nums) {
	if (SZ(nums) > 100009) return;
	if (digits == 0) {
		if (SZ(n) > 0) {
			nums.pb(stoll(n));
		}
	} else {
		for (int i = 0; i < 10; i++) {
			if (SZ(n) == 0) {
				if (i > 0) {
					n.pb((char) ('0' +  i));
				}
				rec(digits - 1, nums);
				if (SZ(n)) n.pop_back();
			} else if (abs(*(prev(n.end())) - ('0' + i)) <= 1) {
				n.pb((char) ('0' + i));
				rec(digits - 1, nums);
				if(SZ(n)) n.pop_back();
			}
		}
	}
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int K;
    cin >> K;
	vector<ll> nums;
    rec(10, nums);
    cout << nums[K - 1] << endl;
}

Measured memory_bytes: 1400
import sys
import itertools
import numpy as np
import networkx as nx

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

H, W = map(int, readline().split())
S = np.frombuffer(read(), 'S1').reshape(H, -1)[:, :W].astype('U1')

A = []
B = []
E = []

for i, j in itertools.product(range(H), range(W)):
    if S[i, j] == '#':
        continue
    elif (i + j) & 1:
        A.append(W*i+j)
    else:
        B.append(W*i+j)

for a in A:
    i,j = divmod(a,W)
    for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
        i1, j1 = i + dx, j + dy
        if 0 <= i1 < H and 0 <= j1 < W and S[i1, j1] != '#':
            b = W*i1+j1
            E.append((a,b))

G = nx.Graph()
G.add_nodes_from(A, bipartite=0)
G.add_nodes_from(B, bipartite=1)
G.add_edges_from(E)

M = nx.bipartite.maximum_matching(G, A)
for a, b in M.items():
    i,j = divmod(a,W)
    i1, j1 = divmod(b,W)
    if i1 == i + 1:
        a, b = 'v', '^'
    elif i1 == i - 1:
        a, b = '^', 'v'
    elif j1 == j + 1:
        a, b = '>', '<'
    else:
        a, b = '<', '>'
    S[i, j], S[i1, j1] = a, b

print(len(M) // 2)
for row in S:
    print(''.join(row))

Measured memory_bytes: 67568
#include <bits/stdc++.h>
#define ll long long
using namespace std;
inline char ch(){
	static char s[1<<16],*S,*T;
	return (S==T)?(T=(S=s)+fread(s,1,1<<16,stdin),*S++):*S++;
}
#define ch() getchar()
template<typename T> void read(T &x){
	x = 0; int f(1); char c = ch();
	for(;!isdigit(c);c = ch()) if(c == '-') f = -1;
	for(;isdigit(c);c = ch()) x = x*10+c-'0';
	x *= f;
}
int n,m,X,c[13],ok,ans;
int le[13],a[13][13];
void solve(int,int);
int main(){
	read(n); read(m); read(X);
	for(int i(1);i <= n;++i){
		read(c[i]);
		for(int j(1);j <= m;++j)
			read(a[i][j]);
	}
	ans = 0x3f3f3f3f; solve(1,0);
	if(ok)	printf("%d\n",ans);
	else	printf("-1");
	return 0;
}
void solve(int x,int sum){
	if(x == n+1){
		for(int i(1);i <= m;++i)
			if(le[i] < X)	return;
		ok = 1; ans = min(ans,sum);return;
	}
	for(int i(1);i <= m;++i)
		le[i] += a[x][i];
	solve(x+1,sum+c[x]);
	for(int i(1);i <= m;++i)
		le[i] -= a[x][i];
	solve(x+1,sum);
}

Measured memory_bytes: 3764
#include"bits/stdc++.h"
using namespace std;
int main(){
	int n, k;
	cin >> n >> k;
	double ans = 0;
	for(int i = 1; i <= n; ++i){
		if(i < k)
			ans += pow(0.5, ceil(log2(k * 1.0 / i)));
		else
			ans += 1;
	}
	cout << setprecision(15) << ans / n;
}








Measured memory_bytes: 512
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 27 20:48:33 2019

@author: ctiuser
"""

N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

ans = 0
for i in range(N):
    tmp = B[i] - A[i]
    if tmp > 0:
        tmp2 = A[i+1] - tmp
        if tmp2 > 0:
            ans += B[i]
            A[i+1] = tmp2
        else:
            ans += A[i] + A[i+1]
            A[i+1] = 0
    else:
        ans += B[i]

print(ans)

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    double w,h,x,y;
    cin>> w >>h >> x >>y;
    int f=0;
    if(x==w/2)
    {
        f++;
    }
    if(y==h/2)
    {
        f++;
    }
    if(x*h + w*y == h*w)
    {
        f++;
    }
    if(x*h == y*w)
    {f++;}
    double a = h*w/2.0;
    cout<<a<<endl;
    if(f>1)
    cout<<"1";
    else
    cout<<"0";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <time.h>
#define ll long long
#define mp(a,b) make_pair(a,b)
#define si(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define ss(s) scanf("%s",&s)
#define pi(n) printf("%d\n",n)
#define pl(n) printf("%lld\n",n)
#define newline cout << endl;
using namespace std;

int main(){
  clock_t tStart = clock();
  ll n; sl(n); ll t=  n;
  ll blah = 0;
  while(n){
    blah+=n%10;
    n/=10;
  }
  //pl(blah);
  if(t%blah==0) printf("Yes\n");
  else printf("No\n");
  //printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define pob pop_back
#define vl vector<ll>
#define mp make_pair
#define sz size()
#define fast ios::sync_with_stdio(0)
#define maxx 100005
#define edge pair<ll,ll>
using namespace std;

// ¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++¦¦¦++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++++++¦¦¦¦¦¦¦¦¦¦+++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++¦¦¦¦¦+++++++¦++¦¦
// ¦¦¦¦¦¦¦¦++¦¦¦¦¦¦++++++¦¦¦¦+++++++++++++¦
// ¦¦¦¦¦¦¦++++++¦¦¦++++++¦¦++++++++++++++¦¦
// ¦¦¦¦¦¦¦+++++++¦¦¦+++++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++¦¦¦¦¦¦¦¦¦++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++¦¦¦¦¦¦¦¦+++++++¦ 
// ¦¦¦¦¦¦¦¦¦¦++¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦++++¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦ 
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++++++¦¦+¦++¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++¦¦+++++¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+¦¦¦¦+++¦¦¦¦++++++¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++¦¦+¦¦¦¦¦+++++++¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++++++++++¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++¦¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+¦¦¦+++++++++++¦¦¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++¦¦¦¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++¦¦¦¦¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++¦¦¦¦¦¦¦¦¦¦¦¦


int main()
{
	string s,t;
	cin>>s>>t;
	ll i,j;
	ll m,n;
	m=s.size();
	n=t.size();
	ll lcs[m+1][n+1];
	for(i=0;i<=m;i++)
	{
		for(j=0;j<=n;j++)
		{
			if(i==0 || j==0)
			{
				lcs[i][j]=0;
			}
			else if(s[i-1]==t[j-1])
			{
				lcs[i][j]=lcs[i-1][j-1]+1;
			}
			else
			{
				lcs[i][j]=max(lcs[i-1][j],lcs[i][j-1]);
			}
		}
	}
	ll index=lcs[m][n];
	char v[index+1];
	i=m;
	j=n;
	v[index]='\0';
	while(i>0 && j>0)
	{
		if(s[i-1]==t[j-1])
		{
			v[index-1]=s[i-1];
			i--;j--;
			index--;
		}
		else if(lcs[i-1][j]>lcs[i][j-1])
		i--;
		else
		j--;
	}
	
	
	cout<<v;
	
	cout<<endl;
}


Measured memory_bytes: 70656
#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for(ll i = l; i < (ll)r; i++)
#define per(i, n) for(ll i = (ll)n-1; i >= 0; i--)
#define per3(i, l, r) for(ll i = (ll)r-1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template<class T, class U> inline void cmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> inline void cmin(T &a, U b) { if (a > b) a = b; }
constexpr char el = '\n';
template<class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) os << v[i] << (i+1 != v.size() ? " " : ""); return os; }
template<class T> istream &operator>>(istream &is, vector<T> &v) { for(T &i : v) is >> i; return is; }
struct IoSetup {
  IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15); }
} io_setup;
#line 2 "b.cpp"

int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  ll cnt = 0;
  while (a >= b) {
    b *= 2;
    cnt++;
  }
  while (b >= c) {
    c *= 2;
    cnt++;
  }
  cout << (cnt <= k ? "Yes" : "No") << el;
}


Measured memory_bytes: 3620
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

int main() {
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '1')
      ans++;
  }
  cout << ans << endl;
  
  return 0;
}

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

namespace ConsoleApp22
{
    class Program
    {
        static void Main(string[] args)
        {
            string a = Console.ReadLine();
            int sum = 0;
            for(int i=0;i<a.Length/2;i++)
            {
                if (a[i] != a[a.Length - i - 1])
                {
                    sum++;
                }
            }
            Console.WriteLine(sum);
            Console.Read();
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

int main()
{
    int K, A, B; cin >> K >> A >> B;

    bool ok = (B / K - (A - 1) / K) > 0;
    cout << (ok ? "OK" : "NG") << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main()
{
    char b;
    cin >> b;

    switch (b) {
    case 'A':
        cout << 'T';
        break;
    case 'T':
        cout << 'A';
        break;
    case 'C':
        cout << 'G';
        break;
    case 'G':
        cout << 'C';
        break;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long m = sc.nextLong();
        if(Math.abs(n - m) > 1) {
            System.out.println(0);
            return;
        }
        long nn = 1;
        for (int i = 1; i <= n; i++) {
            nn = (nn * i) % 1000000007;
        }
        long mm = 1;
        for (int i = 1; i <= m; i++) {
            mm = (mm * i) % 1000000007;
        }
        long ans = 0;
        if(n == m) {
            ans = (nn * mm * 2) % 1000000007;
        } else {
            ans = (nn * mm) % 1000000007;
        }
        System.out.println(ans);
    }
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main()
{
int N, M;
	cin >> N >> M;
	priority_queue<int> K;
	fx(N) {
		int y;
		cin >> y;
		K.push(y);
	}
	fx(M) {
		int y = K.top();
		K.pop();
		y /= 2;
		K.push(y);
	}
	ll ans = 0;
	fx(N) {
		ans += K.top();
		K.pop();
	}
	ce(ans)
    return 0;
}



Measured memory_bytes: 892
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,m,p;
  while(cin>>n>>m>>p,n||m||p) {
    int x[p], y[p]; FOR(i,0,p) cin >> x[i] >> y[i];
    int game[n+1][n+1][n+1]; CLR(game);
    bool next = false;
    // ???1???2
    FOR(t,0,p) {
      int sz;
      bool black = t % 2 == 0;
      FOR(j,1,n+1) {
        if(game[x[t]][y[t]][j] == 0) {
          sz = j;
          game[x[t]][y[t]][j] = black ? 1 : 2;
          break;
        }
      }
      FOR(dx,-1,2) {
        FOR(dy,-1,2) {
          FOR(dz,-1,2) {
            if(dx == 0 && dy == 0 && dz == 0) continue;
            int cnt = 1;
            int nx = x[t] + dx;
            int ny = y[t] + dy;
            int nz = sz + dz;
            while(nx > 0 && nx <= n && ny > 0 && ny <= n && nz > 0 && nz <= n) {
              if(black && game[nx][ny][nz] != 1) break;
              if(!black && game[nx][ny][nz] != 2) break; 
              cnt++;
              nx += dx;
              ny += dy;
              nz += dz;
            }
            nx = x[t] - dx;
            ny = y[t] - dy;
            nz = sz - dz;
            while(nx > 0 && nx <= n && ny > 0 && ny <= n && nz > 0 && nz <= n) {
              if(black && game[nx][ny][nz] != 1) break;
              if(!black && game[nx][ny][nz] != 2) break;
              cnt++;
              nx -= dx;
              ny -= dy;
              nz -= dz;
            }
            // ??????
            //cout << "cnt" << cnt << endl;
            if(cnt >= m) {
              cout << (t % 2 == 0 ? "Black " : "White ") << t + 1 << endl;
              next = true;
              break;
            }
          }
          if(next) break;
        }
        if(next) break;
      }
      if(next) break;
    }
    if(!next) cout << "Draw" << endl;
  }
  return 0;
}

Measured memory_bytes: 3036
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
LL gcd(LL a,LL b)
{
	if(b==0)
		return a;
	return gcd(b,a%b);
}
int main()
{
	int times;
	LL A,B,C,D;
	scanf("%d",&times);
	for(int tmn=1;tmn<=times;tmn++)
	{
		scanf("%lld %lld %lld %lld",&A,&B,&C,&D);
		if(A<B)
		{
			printf("No\n");
			continue;
		}
		if(D<B)
		{
			printf("No\n");
			continue;
		}
		if(C>=B)
		{
			printf("Yes\n");
			continue;
		}
		//C<A-x*B+y*D<B->A-B<x*B-y*D<A-C
		LL d=gcd(B,D);
		LL l=A-B,r=A-C;
		LL val=r/d*d;
		if(val==r)
			val-=d;
		if(val>l)
			printf("No\n");
		else
			printf("Yes\n");
	}
	return 0;
}

Measured memory_bytes: 128
#-*-coding:utf-8-*-

def main():
    #入力
    n = int(input())
    lists = list(map(int, input().split()))
    #入力をソートし降順にする
    lists.sort()
    lists.reverse()

    #アリスとボブの点数
    alice_sum = 0
    bob_sum = 0

    for i in range(n):
        #降順のリストの内偶数番目がアリスの得点になる
        #機数番目はボブの得点
        if i % 2 == 0:
            alice_sum += lists[i]
        else:
            bob_sum += lists[i]
    
    print('{}'.format(alice_sum - bob_sum))

if __name__ == '__main__':
    main()
    

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
 
using namespace std;
 
int main(){
    int n, m;
    while(cin >> n >> m && n > 0){
        vector<int> h(n);
        vector<int> w(m);
        for(int i = 0; i < n; i++)
            cin >> h[i];
        for(int i = 0; i < m; i++)
            cin >> w[i];
        int ans = 0;
        int x,y;
        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                int p = i;
                int q = j;
                x = 0;
                y = 0;
                while(true){
                    if(x >= y){
                        y += w[q];
                        q++;
                        if(q > m) break;
                    }else{
                        x += h[p];
                        p++;
                        if(p > n) break;
                    }
              
                    if(x == y){
                        
                        ans++;
                    }
                }
            }
        }
        cout << ans << endl;
    }
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

#define PI (2*acos(0.0))
#define eps 1e-9
#define pb push_back
#define endl "\n"
#define watch(x) cout << (#x) << " is " << (x) << endl;
#define show(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi] << " "; cout << endl;
#define showpair(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi].first << " " << v[fi].second << endl;
#define ff first
#define ss second
#define fu cout << "lol" << endl;
#define precision(n) cout << fixed << setprecision(n);
#define lb lower_bound
#define up upper_bound
#define vscan for(i = 0;i<n;i++){cin>>in; v.pb(in);}
#define all(a) a.begin(), a.end()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define mem(a,val) memset(a,val,sizeof(a))
#define loop(i,n) for(i = 0; i < n; i++)
#define TC ull T; cin>>T; while(T--)
#define IN(x) {scanf("%d",&x);}
#define LL(x) {scanf("%lld",&x);}
#define CC(x) {scanf("%c",&x);}
#define pfl(x) printf("%d\n",x)
#define pfll(x) printf("%lld\n",x)
#define newl puts("")
#define space printf(" ")
#define MOD 1000000007
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL);


int main()
{
    int i = 0, j = 0, cs = 0, in;
    int n; cin>>n;
    vll v(n);
    for(i = 0; i < n; i++) cin>>v[i];
    vll pre(n);
    pre[0] = v[0];
    for(i = 1; i < n; i++) pre[i] = pre[i-1] + v[i];
    ll sum = 0;
    for(i = 0; i < n-1; i++){
        sum += (((pre[n-1] - pre[i])%MOD)*v[i]) % MOD;
        sum %= MOD;
    }
    cout << sum << endl;
    return 0;
}


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

void solve(long long N, vector<long long> A){
	// sort(A.begin(),A.end());
	long long ans = 0;

	for(int i = 0 ; i < N ; i++){
		if( i + 1 < N and A[i] % 2 and A[i+1]){
			A[i+1]--;
			A[i]++;
		}
		ans += A[i] / 2;
	}
	cout << ans << endl;
}



int main(){	
	ios::sync_with_stdio(false);
	long long N;
	cin >> N;
	vector<long long> A(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		cin >> A[i];
	}
	solve(N, A);
	return 0;
}


Measured memory_bytes: 1792
import sys
A=[]
for i in range(3):
  A.append(list(map(int,input().split())))
N=int(input())
for i in range(N):
  b=int(input())
  for j in range(3):
    if b in A[j]:
      for k in range(3):
        if A[j][k]==b:
          A[j][k]=0
if A[0][0] == 0 and A[1][1] ==0 and A[2][2]==0:
  print("Yes")
  sys.exit(0)
elif A[0][2]==0 and A[1][1]==0 and A[2][0]==0:
  print("Yes")
  sys.exit(0)
for i in range(3):
  for j in range(3):
    if A[i][j]==0:
      if j!=2:
        continue
      else:
        print("Yes")
        sys.exit(0)
    else:
      break
for i in range(3):
  for j in range(3):
    if A[j][i]==0:
      if j!=2:
        continue
      else:
        print("Yes")
        sys.exit(0)
    else:
      break
print("No")

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

const int MAX_N = 102400;
const int NUM_B = 320;
const int B_SIZE = 320;
int a[MAX_N];
int b[NUM_B];

int RMQ(const int L, const int R) {
    const int Li = L/NUM_B;
    const int Ri = R/NUM_B;
    int ans = INT_MAX;
    if( Li == Ri ) { // ?????¨???????????±?????????
	for(int i=L; i<=R; i++) ans = min(ans, a[i]);
	return ans;
    }
    else{
	// ??????
	for(int i=L; i<(Li+1)*NUM_B; i++) ans = min(ans,a[i]);
	// ?????±?????????????????§
	for(int i=Li+1; i<Ri; i++)          ans = min(ans,b[i]);
	// ??????
	for(int i=Ri*NUM_B; i<=R; i++)    ans = min(ans,a[i]);
	return ans;
    }
}

void update(const int x, const int y) {
    const int index_b = x/NUM_B;
    a[x] = y;
    if( b[index_b] > y ) {
	b[index_b] = y;
    }
    else{
	b[index_b] = INT_MAX;
	for(int i=index_b*NUM_B; i<(index_b+1)*NUM_B; i++)
	    b[index_b] = min(b[index_b], a[i]);
    }
    
}

int main() {

    int n,q;
    scanf("%d %d",&n,&q);

    for(int i=0; i<MAX_N; i++) a[i] = INT_MAX; 
    for(int i=0; i<NUM_B; i++) b[i] = INT_MAX; 
    
    for(int i=0; i<q; i++) {
	int c,x,y;
	scanf("%d %d %d",&c, &x, &y);
	if( c == 0 ) { // update
	    update(x,y);
	}
	else { // find
	    printf("%d\n",RMQ(x,y));
	}
	
    }

    
}

Measured memory_bytes: 3624
#include <stdio.h>

int A[2000], M[2000];
int n, q;

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

int main(){

    int i;

    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[i]);


    for (i = 0; i < q; i++) {
        if(solve(0, M[i])) printf("yes\n");
        else printf("no\n");
    }

    return 0;
}

Measured memory_bytes: 588
#include <bits/stdc++.h>
using namespace std;
int main(){
	bool f[10];
	string a,b;
	while(1){
		int hit=0,blow=0;
		cin>>a>>b;
		if(a=="0"&&b=="0")break;
		memset(f,false,sizeof(f));
		for(int i=0;i<4;i++){
			f[a[i]-'0']=true;
		}
		for(int i=0;i<4;i++){
			if(b[i]==a[i])hit++;
			else if(f[b[i]-'0'])blow++;
		}
		cout<<hit<<" "<<blow<<endl;
	}
}

Measured memory_bytes: 1184
#include <iostream>
#include <list>
#define END 1000000001
using namespace std;

int main(){

	list<long int> a;
	list<long int>::iterator itr = a.end();
	int q;
	cin >> q;
	int querynum = 0;
	while (querynum < q) {
		int var1;
		cin >> var1;
		if (var1 == 0) {
			int var2;
			cin >> var2;
			itr = a.insert(itr, var2);
		}
		else if (var1 == 1) {
			int var2;
			cin >> var2;
			if (var2 > 0) for (int i = 0; i < var2; i++) ++itr; else for (int i = 0; i < -var2; i++) --itr;
		}
		else {
			itr = a.erase(itr);
		}
		querynum++;
	}

	itr = a.begin();
	while (itr != a.end()) cout << (*(itr++)) << endl;

	return 0;
}


Measured memory_bytes: 18600