akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <deque>
#include <set>
#include <cstring>
using namespace std;

int w, h;
char field[9][9];

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

int solve(){
	int cargo = -1, man = -1;
	for(int i = 1; i <= h; ++i)
	for(int j = 1; j <= w; ++j){
		if(field[i][j] == 2){
			cargo = i << 8 | j;
		}
		else if(field[i][j] == 4){
			man = i << 8 | j;
		}
	}
	
	set<int> st;
	deque<int> dq;
	dq.push_back(cargo << 16 | man);
	st.insert( dq.front() );
	dq.push_back(-1);

	int ans = 1;
	while(dq.size() > 1){
		int t = dq.front();
		dq.pop_front();
		
		if(t < 0){
			++ans;
			dq.push_back(t);
		}
		else{
			int mx = t & 255;
			int my = (t >> 8) & 255;
			int cx = (t >> 16) & 255;
			int cy = (t >> 24) & 255;

			for(int i = 0; i < 4; ++i){
				int mx2 = mx + dx[i], my2 = my + dy[i];

				if(mx2 == cx && my2 == cy){
					int cx2 = cx + dx[i], cy2 = cy + dy[i];
					if(field[cy2][cx2] == 3){
						return ans;
					}
					if(field[cy2][cx2] != 1){
						int u = cy2 << 24 | cx2 << 16 | my2 << 8 | mx2;
						if( st.insert(u).second ){
							dq.push_back(u);
						}
					}
				}
				else if(field[my2][mx2] != 1){
					int u = cy << 24 | cx << 16 | my2 << 8 | mx2;
					if( st.insert(u).second ){
						dq.push_front(u);
					}
				}
			}
		}
	}
	
	return -1;
}


int main(){
	while( scanf("%d%d", &w, &h), w != 0 ){
		memset(field, 1, sizeof(field));

		int d;

		for(int i = 1; i <= h; ++i)
		for(int j = 1; j <= w; ++j){
			scanf("%d", &d);
			field[i][j] = d;
		}
		
		printf("%d\n", solve());
	}
}

Measured memory_bytes: 1088
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int lim=100000;
bool dp[81][81][lim];
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);

    //できるだけ差を小さくしながらDPするのは最適じゃない
    //一番右下のマスが1,100000とかだったら死ぬから
    //マスで両者の差をとっておいて，正か負かを選べる
    //ルートの総和の最小化

    int h,w;cin>>h>>w;
    int a[h][w],b[h][w],x[h][w];
    rep(i,h){
        rep(j,w){
            cin>>a[i][j];
        }
    }
    rep(i,h){
        rep(j,w){
            cin>>b[i][j];
            x[i][j]=abs(a[i][j]-b[i][j]);
        }
    }

    rep(i,h){
        rep(j,w){
            if(i==0&&j==0){
                dp[i][j][x[i][j]]=true;
            }
            if(i!=0){
                rep(k,lim)if(dp[i-1][j][k]){
                    if(k+x[i][j]<lim) dp[i][j][k+x[i][j]]=true;
                    dp[i][j][abs(x[i][j]-k)]=true;
                }
            }
            if(j!=0){
                rep(k,lim)if(dp[i][j-1][k]){
                    if(k+x[i][j]<lim) dp[i][j][k+x[i][j]]=true;
                    dp[i][j][abs(x[i][j]-k)]=true;
                }
            }
        }
    }
    rep(i,lim){
        if(dp[h-1][w-1][i]){
            cout<<i<<endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 631168
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
#define INF 10000000000000000
#define rep(i,n) for(int i=0;i<n;i++)
int n,a,b;
signed main(){
	cin>>n>>a>>b;
	if(a+b-1>n||a*b<n){
		puts("-1");
		return 0;
	}
	int x=n-a;
	for(int i=n-a+1;i<=n;i++)cout<<i<<" ";
	for(int i=2;i<=b;i++){
		int t=min(x-b+i,a);
		for(int j=x-t+1;j<=x;j++)cout<<j<<" ";
		x-=t;
	}
	return 0;
}


Measured memory_bytes: 2176
#include<stdio.h>


int main (void){

int i,max,min,n,f,t,h,a,s;

scanf("%d",&a);
for(s=0;s<a;s++){
 max = 0;
 min = 0;
 
 scanf("%d",&n);
 scanf("%d",&f);
 
 for(i=0;i<n-1;i++){
 	scanf("%d",&t);
 	h = t-f;
 	f=t;
 	
 	if(max<h){
 		max=h;
 	}else if(min>h){
 		min=h;
 	}else{
 		;
 	}
 }
 	min=(-1)*min;
 	
 	printf("%d %d\n",max,min);
 }
 }

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include<stdlib.h>
#include<iostream>
#include<math.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long
#define INF 2000000000
#define Min(a,b) (a<b?a:b)
#define Max(a,b) (a>b?a:b)
#define PI 3.1415926535897932
using namespace std;




int main()
{
IOS;
string s;
cin>>s;
// cout<<(*(s.end()-1));
if(*(s.end()-1)=='s')
	cout<<(s+"es");
else
	cout<< (s + "s");

return 0;
}

Measured memory_bytes: 3612
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner cro=new Scanner(System.in);
int N,M,i,j,delx,dely,min;
N=cro.nextInt();
M=cro.nextInt();
int students[][]=new int[N][3];
int checkpoints[][]=new int[M][2];
for(i=0;i<N;i++)
{
students[i][0]=cro.nextInt();
students[i][1]=cro.nextInt();
}
for(i=0;i<M;i++)
{
checkpoints[i][0]=cro.nextInt();
checkpoints[i][1]=cro.nextInt();
}
for(i=0;i<N;i++)
{
delx=students[i][0]-checkpoints[0][0];
dely=students[i][1]-checkpoints[0][1];
if(delx<0) delx=-delx;
if(dely<0) dely=-dely;
min=delx+dely;
students[i][2]=1;
for(j=1;j<M;j++)
{
delx=students[i][0]-checkpoints[j][0];
dely=students[i][1]-checkpoints[j][1];
if(delx<0) delx=-delx;
if(dely<0) dely=-dely;
if(delx+dely<min)
{
min=delx+dely;
students[i][2]=j+1;
}
}
}
for(i=0;i<N;i++) System.out.println(students[i][2]);
}
}

Measured memory_bytes: 22732
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define all(x)  (x).begin(), (x).end()
#define MAX 1e18
using namespace std;
typedef long long int ll;

int main(){
  int n;  cin >> n;
  vector<int> vec(n);
  int ans = 0;
  rep(i, 0, n){
    cin >> vec[i];
    ans += vec[i];
  }
  sort(vec.begin(), vec.end());
  if(ans % 10 == 0){
    bool onlyTen = true;
    rep(i, 0, n){
      if(vec[i]%10!=0){
        ans -= vec[i];
        onlyTen = false;
        break;
      }
    }
    if(onlyTen){
      ans = 0;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
INF = 1 << 60
MOD = 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()

prime = 998244353
root = 3
def _fmt(A, inverse = False):
    N = len(A)
    logN = (N - 1).bit_length()
    base = pow(root, (prime - 1) // N * (1 - 2 * inverse) % (prime - 1), prime)
    step = N
    for k in range(logN):
        step >>= 1
        w = pow(base, step, prime)
        wj = 1
        nA = [0] * N
        for j in range(1 << k):
            for i in range(1 << logN - k - 1):
                s, t = i + j * step, i + j * step + (N >> 1)
                ps, pt = i + j * step * 2, i + j * step * 2 + step
                nA[s], nA[t] = (A[ps] + A[pt] * wj) % prime, (A[ps] - A[pt] * wj) % prime
            wj = (wj * w) % prime
        A = nA
    return A

def convolution(f, g):
    N = 1 << (len(f) + len(g) - 2).bit_length()
    Ff, Fg = _fmt(f + [0] * (N - len(f))), _fmt(g + [0] * (N - len(g)))
    N_inv = pow(N, prime - 2, prime)
    fg = _fmt([a * b % prime * N_inv % prime for a, b in zip(Ff, Fg)], inverse = True)
    del fg[len(f) + len(g) - 1:]
    return fg

class modfact(object):
    def __init__(self, n):
        fact, invfact = [1] * (n + 1), [1] * (n + 1)
        for i in range(1, n + 1): fact[i] = i * fact[i - 1] % MOD
        invfact[n] = pow(fact[n], MOD - 2, MOD)
        for i in range(n - 1, -1, -1): invfact[i] = invfact[i + 1] * (i + 1) % MOD
        self._fact, self._invfact = fact, invfact

    def fact(self, n):
        return self._fact[n]

    def invfact(self, n):
        return self._invfact[n]

    def comb(self, n, k):
        return self._fact[n] * self._invfact[k] % MOD * self._invfact[n - k] % MOD if 0 <= k <= n else 0

    def perm(self, n, k):
        return self._fact[n] * self._invfact[n - k] % MOD if 0 <= k <= n else 0

from collections import Counter
def resolve():
    n = int(input())
    H = [int(input()) for _ in range(2 * n)]

    mf = modfact(2 * n)
    doublefact = [1] * (2 * n + 2)
    for i in range(2, 2 * n + 1):
        doublefact[i] = i * doublefact[i - 2] % MOD

    F = [[mf.comb(k, 2 * i) * doublefact[2 * i - 1] % MOD for i in range(k // 2 + 1)] for k in Counter(H).values()]
    for i in range(len(F) - 1):
        F.append(convolution(F[2 * i], F[2 * i + 1]))

    f = F[-1]
    ans = sum(f[i] * doublefact[2 * (n - i) - 1] % MOD * (1 - 2 * (i & 1)) for i in range(len(f))) % MOD
    print(ans)
resolve()

Measured memory_bytes: 133536
import math
import random
from operator import itemgetter
import re
import sys
from itertools import accumulate
from collections import defaultdict
from collections import deque
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import functools
N = int(input())
music = []
for i in range(N):
    music.append(list(map(str,input().split())))
stop = input()
i = 0
while stop != music[i][0]:
    i += 1
ans = 0
for j in range(N-i-1):
    ans += int(music[i+j+1][1])
print(ans)


Measured memory_bytes: 65004
def main():
    n=int(input())
    res = {}
    ans = 0
    for i in range(n):
        c = str(sorted(input()))
        if c not in res.keys():
            res[c] = 1
        else:
            res[c] += 1
    for i in res.values():
        ans += int(i*(i-1)/2)
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 22048
#include <stdio.h>

int main(void)
{
	int num[31];
	int i;
	int x,y;
	int w,n;
	int temp;
	
	for(i = 1;i < 31;i++){
		num[i] = i;
	}
	
	scanf("%d",&w);
	scanf("%d",&n);
	
	for(i = 1;i <= n;i++){
		scanf("%d,%d",&x,&y);
		temp = num[x];
		num[x] = num[y];
		num[y] = temp;
	}
	
	for(i = 1;i <= w;i++){
		printf("%d\n",num[i]);
	}
	
	return(0);
}

Measured memory_bytes: 596
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
count = 0
ans = "No"

N = i()
A = l()

M = 1000
S = 0
P = 0

for i in range(1,N):
    #print(A[i-1],A[i])
    #print(A[i-1] < A[i])
    if A[i-1] < A[i]:
        S += M // A[i-1]
        P = A[i-1]
        if M - S*P >= 0:
            M -= S*P
    elif A[i-1] > A[i]:
        M += S*A[i-1]
        S = 0
    #print(M,S,P)
if S > 0:
    M += S*A[N-1]
print(M)





Measured memory_bytes: 62040
import java.util.Scanner;

class Main {

	public static void main(String args[]){

		Scanner scan = new Scanner(System.in);
		int n,len;
		n = scan.nextInt();
		len = scan.nextInt();

		String s[] = new String[n];
		for(int i = 0; i < n; i++){
			s[i] = scan.next();
		}

		for(int i = 0; i < n; i++){
			for(int j = i; j < n; j++){
				if( s[j].compareTo(s[i]) < 0 ){
					swap(i,j,s);
				}
				
			}
		}
		for(int i = 0; i < n; i++){
			System.out.print(s[i]);
		}
	}

	static void swap(int x, int y, String[] s){
		String buf;
		buf = s[x]; s[x] = s[y]; s[y] = buf;
	}
}

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= 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
  {
    mint res(*this);
    return res /= a;
  }
};

struct edge{int to; ll a_cost, b_cost;};

int main()
{
  ll a, b, c;
  cin >> a >> b >> c;
  ll ans = INF64;
  chmin(ans, abs(a/2*b*c - (a-a/2)*b*c));
  chmin(ans, abs(b/2*a*c - (b-b/2)*a*c));
  chmin(ans, abs(c/2*a*b - (c-c/2)*a*b));

  cout << ans << endl;
}


Measured memory_bytes: 3620
#include<stdio.h>
#include<math.h>
int probA()
{
    int a,b;
    char s[101];
    // 整数の入力
    scanf("%d", &a);
    // スペース区切りの整数の入力
    scanf("%d",&b);
    // 文字列の入力
    scanf("%s",s);
    // 出力
    if(s[b-1]=='A'){s[b-1]='a';}
    if(s[b-1]=='B'){s[b-1]='b';}
    if(s[b-1]=='C'){s[b-1]='c';}
    
    printf("%s\n",s);
    return 0;
}

int probB(){
    int S,AA,BB;
    scanf("%d", &S);
    AA=S/100;
    BB=S%100;
    if(1<=AA && AA<=12){
        if(1<=BB && BB<=12){printf("AMBIGUOUS\n");}
        else{printf("MMYY\n");}
    }
    else{
        if(1<=BB && BB<=12){printf("YYMM\n");}
        else{printf("NA\n");}
    }
    
    
    
    return 0;
}

int Ipow2XK(int i,int K){
    int X;
    for(X=0;i*pow(2,X)<K;X++){
    }
    
    return X;
}

int probC(){
    
    int N,K;
    double R=0;
    scanf("%d %d", &N,&K);
    for(int i=1;i<=N;i++){
        R+=(double)1/(N*pow(2,Ipow2XK(i,K) )  );
    }
    
    
    printf("%1.12lf\n",R);
    return 0;
}

int Ap(){
    int a,b;
    // 整数の入力
    scanf("%d", &a);
    // スペース区切りの整数の入力
    scanf("%d",&b);
    // 文字列の入力
    
    // 出力
    if(a>=13){b=b;}
    else if(6<=a && a<=12){b=b/2;}
    else if(a<=5){b=0;}
    
    printf("%d\n",b);
    
    
    
    return 0;
}

int Bp(){
    int r;
    int D;
    int x[12];
    scanf("%d", &r);
    scanf("%d", &D);
    scanf("%d", &x[0]);
    
    
    for(int i=1;i<11;i++){
        x[i]=r*x[i-1]-D;
        printf("%d\n",x[i]);
    }
    
    return 0;
}


int main(){
    Bp();
    return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll a,b,k;

int main(){
  ll ans=0;
  
  cin >> a;

  // エラトステネスのふるい
    int MAX = 105010;
    vector<int> is_prime(MAX, 1);
    is_prime[0] = 0, is_prime[1] = 0;
    for (int i = 2; i < MAX; ++i) {
        if (!is_prime[i]) continue;
        for (int j = i*2; j < MAX; j += i) is_prime[j] = 0;
    }

    
    for(int i=a;i<MAX;i++){
      if (is_prime[i]){
        cout<<i<<endl;
        return 0;
      }
    }

  return 0;
}

Measured memory_bytes: 640
s = list(input())
s_odd = []
s_even = []

for i in range(len(s)):
  if i % 2 == 0:
    s_even.append(s[i])
  else:
    s_odd.append(s[i])

ans_bool = True

if "L" in s_even:
  print("No")
elif "R" in s_odd:
  print("No")
else:
  print("Yes")

Measured memory_bytes: 3064
n = int(input())
a = []
m1 = int(input())
m2 = -1
f = 0
s = -1
for i in range(n-1):
    q = int(input())
    if m1 <= q:
        m2 = m1
        m1 = q
        s = f
        f = i+1
    elif m2 <= q:
        m2 = q
        s = i

for i in range(n):
    if i == f:
        print(m2)
    else:
        print(m1)

Measured memory_bytes: 55256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

int N, M;

map<string, int> mp;
map<string, vector<string> > recipe;

int rec(string query)
{
  int res = 1000000;
  if (recipe.find(query) != recipe.end()) {
    int tmp = 0;
    for (int i = 0; i < recipe[query].size(); i++) {
      tmp += rec(recipe[query][i]);
    }
    res = min(res, tmp);
  }
  
  res = min(res, mp[query]);
  
  return res;
}

int main()
{
  while (cin >> N && N) {
    mp.clear();
    recipe.clear();
    for (int i = 0; i < N; i++) {
      string key; int val;
      cin >> key >> val;
      mp[key] = val; 
    }
    
    cin >> M;
    for (int i = 0; i < M; i++) {
      int num;
      string key, val;
      vector<string> vs;
      cin >> key >> num;
      for (int j = 0; j < num; j++) {
        cin >> val;
        vs.push_back(val);
      }
      
      recipe[key] = vs;
    }
    
    string q;
    cin >> q;
    cout << min(rec(q), mp[q]) << endl;
  }
}

Measured memory_bytes: 0
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int D = sc.nextInt();
    int G = sc.nextInt();
    int[] p = new int[D+1];
    int[] c = new int[D+1];
    for (int i = 1; i <= D; i++) {
      p[i] = sc.nextInt();
      c[i] = sc.nextInt();
    }
    
    int min = Integer.MAX_VALUE;
    int bit = 1 << D;
    for (int i = 0; i < bit; i++) {
      int num = solve(i, p, c, G);
      if (num < min) {
        min = num;
      }
    }
    
    System.out.println(min);
  }
  
  private static int solve(int i, int[] p, int[] c, int G) {

    int maxUnused = c.length - 1;
    int solved = 0;
    int j = 1;
    int score = 0;
    while (i != 0) {
      if (i % 2 == 1) {
        score += (c[j] + p[j] * 100 * j);
        solved += p[j];
      } else {
        maxUnused = j;
      }
      i /= 2;
      j++;
    }
    if (score >= G) {
      return solved;
    }

    for (int a = 1; a < p[maxUnused]; a++) {
      score += 100*maxUnused;
      solved++;
      if (score >= G) {
        return solved;
      }
    }

    return Integer.MAX_VALUE;
  }
}

Measured memory_bytes: 25172
#!/usr/bin/env python
#pyrival orz
import os
import sys
from io import BytesIO, IOBase

"""
    for _ in range(int(input())):
    n,m=map(int,input().split())
    n=int(input())
    a = [int(x) for x in input().split()]
"""

def main():
    a = [int(x) for x in input().split()]
    for i in range(len(a)):
        if a[i]:
            continue
        print(i+1)
        exit(0)

# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

Measured memory_bytes: 62596
#![allow(unused_imports)]
#![allow(unused_variables)]

use itertools::Itertools;
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        x: i32,
        n: usize,
        p: [i32; n],
    }
    // annotate for rust-analyzer
    let x: i32 = x;
    let n: usize = n;
    let p: Vec<i32> = p;

    let mut ans = 0;
    for i in 0..=100 {
        if !p.contains(&(x - i)) {
            ans = x - i;
            break;
        } else if !p.contains(&(x + i)) {
            ans = x + i;
            break;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 2160
n = input()
a = int(n[-1])
if a == 2 or a == 4 or a == 5 or a == 7 or a == 9:
    print("hon")
elif a == 0 or a == 1 or a == 6 or a == 8:
    print("pon")
else :
    print("bon")

Measured memory_bytes: 9112
// ABC165C - Many Requirements

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

int N, M, Q;
int a[50], b[50], c[50], d[50];
int ans = 0;

void dfs(int i, int A[10]) {
	if (i == N + 1) {
		int t = 0;
		for (int i = 0; i < Q; i++) {
			if (A[b[i]] - A[a[i]] == c[i]) {
				t += d[i];
			}
		}
		ans = max(ans, t);

		return;
	}

	for (int j = 0; A[i-1] + j <= M; j++) {
		A[i] = A[i-1] + j;
		dfs(i+1, A);
	}

	return;
}

int main() {
	cin >> N >> M >> Q;
	for (int i = 0; i < Q; i++) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	}

	int A[N+1];

	A[0] = 1;
	dfs(1, A);

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i,n) for (int i = (int)(n)-1; i>=0; --i)
#define For(i,a,b) for(auto i=(a);i<=(b);++i)
#define rFor(i,a,b) for(auto i=(b);i>=(a);--i)
#define call(var) cerr<<#var<<"="<<var<<"\n";
#define dup(x,y) (((x)+(y)-1)/(y))
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const double pi = acos(-1);
template<class t,class u> inline bool chmax(t&a,u b){if(a<b){a=b;return true;}return false;}
template<class t,class u> inline bool chmin(t&a,u b){if(b<a){a=b;return true;}return false;}
template<class T> istream& operator>>(istream& is, vector<T>& a){rep(i,a.size()) is >> a[i]; return is;}
template<class T> ostream& operator<<(ostream& os, vector<T>& a){rep(i,a.size()) os << a[i] << " "; 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, class U> ostream& operator<<(ostream& os, const pair<T,U>& p){os << "("<< p.first << "," << p.second << ")"; return os;}
template<class T, class U> ostream& operator<<(ostream& os, const map<T,U>& mp){for(auto& t : mp) os << t.first << " " << t.second << "\n"; return os;}

int main(){
    int x,n;cin >> x >> n;
    vb p(101);
    rep(i,n){
        int a;cin >> a;
        p[a] = true;
    }

    int diff = 100;
    int ans = 0;
    for(int i=0;i<=101;++i){
        if(!p[i] && abs(x - i) < diff){
            diff = abs(x-i);
            ans = i;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int a[]=new int[N];
		for (int i=0;i<N;i++) {
			a[i] =sc.nextInt();
		}
		int gcd =a[0];
		Main main = new Main();
		for (int i=1;i<N;i++) {
			gcd = main.gcd(gcd, a[i]);
		}
		System.out.println(gcd);
	}

	public int gcd(int a,int b) {
		if (b==0) {
			return a;
		} else {
			return gcd(b,a%b);
		}

	}
}

Measured memory_bytes: 49800
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

MOD = 10**9+7


def sum_range(l, r):
    return (l+r)*(r-l+1)//2


def main():
    n, k = map(int, input().split())

    ans = 0
    for i in range(k, n+2):
        ans += sum_range(n-i+1, n) - sum_range(0, i-1) + 1
        ans %= MOD
    print(ans)


main()


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

int main() {
    int a, c, i;
    string s, t;
    cin >> s;
    c = s.size();
    i=c;
    i--;
    while(i>2) {
        if(s.at(i)=='m') {
            t="dream"+t;
            i=i-5;
            }
        else if(s.at(i)=='e') {
            t="erase"+t;
            i=i-5;
            }
        else if(s.at(i)=='r') {
            if(s.at(i-2)=='m') {
                t="dreamer"+t;
                i=i-7;
            }
            else if(s.at(i-2)=='s') {
                t="eraser"+t;
                i=i-6;
            }
            else break;
        }
        else {
            break;
        }
    }
    if(s==t) cout << "YES";
    else cout << "NO";
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
#define REP(i, b, e) for ( int i = b; i < (int)e; i++ )
#define rep(i, n) REP(i, 0, n)
static const int DMAX = 200;
static const int NMAX = 200;
static const int INPOS = -1;

main(){
  int D, N, T[DMAX+1], C[NMAX+1], dp[NMAX+1][DMAX+1];
  pair<int, int> AB[NMAX+1];
  cin >> D >> N;
  rep(i, D) cin >> T[i+1]; // +1 for 1 base
  rep(i, N) cin >> AB[i+1].first >> AB[i+1].second >> C[i+1];
  rep(i, N+1) rep(j, D+1) dp[i][j] = INPOS;
  
  REP(i, 1, N+1)
    if ( AB[i].first <= T[1] && T[1] <= AB[i].second ) dp[i][1] = 0;

  REP(j, 2, D+1){
    REP(i, 1, N+1){
      if ( !( AB[i].first <= T[j] && T[j] <= AB[i].second) ) continue;
      REP(k, 1, N+1){
	if ( dp[k][j-1] == INPOS ) continue;
	dp[i][j] = max(dp[i][j], dp[k][j-1] + abs(C[k] - C[i]));
      }
    }
  }

  int ans = 0;
  REP(i, 1, N+1) ans = max(ans, dp[i][D]);
  cout << ans << endl;
}

Measured memory_bytes: 1320
n = int(input())

def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    ret = [2]
    limit = int(n**0.5)
    data = [i for i in range(3, n+1, 2)]
    while True:
        p = data[0]
        if p >= limit:
            break
        else:
            ret.append(p)
            data = [e for e in data if e % p != 0]
    return ret + data

sieve = get_sieve_of_eratosthenes(55555)
ANS = []

for prime in sieve:
    if prime % 5 == 1:
        ANS.append(prime)

print(*ANS[:n])

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

typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define ALL(obj) (obj).begin(), (obj).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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


int main() {
    cout<<fixed<<setprecision(10);

    ll n; cin>>n;
    vint a(n); rep(i,n) cin>>a[i];

    ll maxval = 0;
    ll ans = 0;
    for(auto e:a){
        ans += max(maxval - e, 0ll);
        chmax(maxval, e);
    }
    cout<<ans<<endl;

    return 0;

}

Measured memory_bytes: 4768
#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>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
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 par[30], bro[30], ch[30][2], dep[30], hei[30], chs[30];
int findGrandPar(int v){
  if(par[v] == -1){
    return v;
  }
  return findGrandPar(par[v]);
}

int f(int v) {
  int h = 0;
  FOR(i,0,2){
    if(ch[v][i]!=-1){
      chs[v]++;
      dep[ch[v][i]] = dep[v] + 1;
      h = max(f(ch[v][i])+1, h);
    }
  }
  return hei[v] = h;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  FOR(i,0,30) dep[i] = par[i] = bro[i] = -1;
  FOR(i,0,n){
    int id, l, r;
    cin >> id >> l >> r;
    ch[id][0] = l;
    ch[id][1] = r;
    bro[l] = r;
    bro[r] = l;
    if(l!=-1){
      par[l] = id;
    }
    if(r!=-1){
      par[r] = id;
    }
  }
  int v = findGrandPar(0);
  dep[v] = 0;
  f(v);
  FOR(i,0,n){
    string s = "";
    if(dep[i] == 0) s = "root";
    else if(hei[i] == 0) s = "leaf";
    else s = "internal node";
    cout << "node " << i << ": parent = " << par[i] << ", sibling = " << bro[i] << ", degree = " << chs[i] << ", depth = " << dep[i] << ", height = " << hei[i] << ", " << s << endl;
  }
}


Measured memory_bytes: 3180
from itertools import permutations


class Solver(object):
    def __init__(self):
        self.n = int(input())

    def solve(self):
        number_string = ""
        n = -self.n
        while True:
            remainder = abs(n % (-2))
            number_string = str(remainder) + number_string
            quotient = n // (-2)
            if quotient == 0:
                break
            n = quotient
        if (number_string == "") or (number_string == "0"):
            print("0")
        else:
            print(number_string.lstrip("0"))


if __name__ == "__main__":
    s = Solver()
    s.solve()

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if(a+b+c>=22) printf("bust\n");
	else printf("win\n");
	return 0;
}

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

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int h, w;
int sx, sy, gx, gy;
vector<string> fi;

int main() {
  cin >> h >> w >> sx >> sy >> gx >> gy;
  --sx, --sy, --gx, --gy;
  fi.resize(h);
  rep(i, h) cin >> fi[i];

  deque<pair<int, int>> que;
  vector<vector<int>> dist(h, vector<int>(w, -1));
  dist[sx][sy] = 0;
  que.push_front({sx, sy});
  while (que.size()) {
    auto cur = que.front();
    que.pop_front();
    int x = cur.first, y = cur.second;
    rep(i, 4) {
      int nx = x + dx[i], ny = y + dy[i];
      if (nx < 0 || nx >= h || ny < 0 || ny >= w || fi[nx][ny] == '#') continue;
      if (dist[nx][ny] == -1)
        dist[nx][ny] = dist[x][y], que.push_front({nx, ny});
      else if (dist[nx][ny] > dist[x][y])
        dist[nx][ny] = min(dist[nx][ny], dist[x][y]), que.push_front({nx, ny});
    }
    for (int nx = x - 2; nx <= x + 2; ++nx) {
      for (int ny = y - 2; ny <= y + 2; ++ny) {
        if (nx < 0 || nx >= h || ny < 0 || ny >= w || fi[nx][ny] == '#') continue;
        if (dist[nx][ny] == -1)
          dist[nx][ny] = dist[x][y] + 1, que.push_back({nx, ny});
        else if (dist[nx][ny] > dist[x][y] + 1)
          dist[nx][ny] = dist[x][y] + 1, que.push_front({nx, ny});
      }
    }
  }
  cout << dist[gx][gy] << endl;

  return 0;
}


Measured memory_bytes: 9440
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <queue>
#include <math.h>
#include <assert.h>
#include <set>
#include <map>
#include <bitset>
#include <ctime>
#include <time.h>
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <stack>
#include <ctype.h>
#include <numeric>
#include <sstream>
#include <unistd.h>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <random>
#include <chrono>
#include <iomanip>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
#define endl '\n'
#define debug(name) DEBUG(#name, (name))
template<typename T>
void DEBUG(string label, T value) {
    cerr << "[" << label << " = " << value << "]\n";
}

void solve(){
    int a, b, c;
    cin >> a >> b >> c;
    cout << c << " " <<  a << " " << b << endl;





}
int main(int argv, char **argc){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int t;
    t  = 1;
    while(t--)
        solve();

}


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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 100005

int n , k , x;
int a[MAXX];

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


Measured memory_bytes: 1280
import sys
N = int(input())
A = [int(i) for i in input().split()]
A.sort()
a = A[0]
b = A[-1]
if N == 2:
    print(A[1]-A[0])
    print(A[1],A[0])
    sys.exit()
ans = []
for x in A[1:-1]:
    if x <= 0:
        ans.append([b, x])
        b = b - x
    else:
        ans.append([a, x])
        a = a - x
ans.append([b,a])
M = b-a
print(M)
for x in ans:
    print(x[0], x[1])


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

int n;
char s[111],sav[111];

int f(int l,int r){
  if(l+1==r){
    return s[l]-'0';
  }
  if(s[l]=='-'){
    return 2-f(l+1,r);
  }
  if(s[l]=='('){
    int level=-1;
    repl(i,l,r){
      if(s[i]=='(')level++;
      else if(s[i]==')')level--;
      if(level==0&&s[i]=='+'){
        return max(f(l+1,i),f(i+1,r-1));
      }
      if(level==0&&s[i]=='*'){
        return min(f(l+1,i),f(i+1,r-1));
      }
    }
  }
  return -1;
}

int main(){
	cin.sync_with_stdio(false);
  while(1){
    cin>>s;
    if(s[0]=='.')break;
    int res=0;
    n=strlen(s);
    rep(p,3)rep(q,3)rep(r,3){
      memcpy(sav,s,sizeof(s));
      rep(i,n){
        if(s[i]=='P')s[i]=p+'0';
        if(s[i]=='Q')s[i]=q+'0';
        if(s[i]=='R')s[i]=r+'0';
      }
      if(f(0,n)==2)res++;
      memcpy(s,sav,sizeof(sav));
    }
    cout<<res<<endl;
  }
	return 0;
}

Measured memory_bytes: 3088
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		String T = sc.next();
		for (int i = 0; i < N; i++) {
			System.out.print(S.charAt(i));
			System.out.print(T.charAt(i));
		}
	}
}

Measured memory_bytes: 20052
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define fore(x, a) for(auto &x : a)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
#define F first
#define S second
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};
int N, K;
ll a[1111];
 
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
      cin >> a[i];
      if (i) a[i] += a[i-1];
    }
    vector<ll> cand;
    for (int i = 0; i < N; i++) {
      for (int j = i; j < N; j++) {
        cand.emplace_back(a[j] - (i - 1 >= 0 ? a[i-1] : 0));
      }
    }

    ll ans = 0;
    for (int i = 63; i >= 0; i--) {
      int cnt = 0;
      ll nx = ans | (1LL << i);
      for (int j = 0; j < cand.size(); j++) {
        if ((cand[j] & nx) == nx) cnt++;
      }
      if (cnt >= K) ans = nx;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 5872
#include <iostream>
#include <algorithm>

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

using namespace std;

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

    int A[110];
    REP(i, N)   cin >> A[i];

    sort(A, A+N);

    cout << A[N-1] - A[0] << endl;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num::clamp;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        n: usize,
        s: [String; n],
    }

    let mut map = HashMap::new();
    for s in s {
        *map.entry(s).or_insert(0) += 1i64;
    }
    let mut vec = map.iter().map(|(k, v)| (k, *v)).collect_vec();
    vec.sort_by_key(|&(k, v)| (Reverse(v), k));
    let most = vec[0].1;
    for (k, v) in vec {
        if v != most {
            break;
        }
        println!("{}", k);
    }
}


Measured memory_bytes: 27600
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}

bool isPalindrome(string s){
  int SIZE = s.size();
  for (int i = 0; i < SIZE / 2; ++i) {
    if (s[i] != s[SIZE - 1 - i]) return false;
  }
  return true;
}

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

  string s; cin >> s;
  string t = "";
  int SIZE = s.size();
  for (int i = 0; i < SIZE; ++i) {
    if (s[i] != 'x') {
      t.push_back(s[i]);
    }
  }

  if (!isPalindrome(t)) {
    print(-1); return 0;
  } else {
    int cnt = 0;
    deque<char> dq;
    for (int i = 0; i < SIZE; ++i) {
      dq.push_back(s[i]);
    }
    while (!dq.empty()){
      if (dq.front() == dq.back()) {
        dq.pop_front();
        if (!dq.empty()){
          dq.pop_back();
        }
      } else if (dq.front() == 'x' && dq.back() != 'x') {
        dq.pop_front(); ++cnt;
      } else if (dq.front() != 'x' && dq.back() == 'x') {
        dq.pop_back(); ++cnt;
      }
    }
    print(cnt); return 0;
  }

  return 0;
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define irep(i,a,n) for(int i = a;i < (int)(n);i++)
using namespace std;
typedef long long ll;

int main(){
    int N, K;
    string S;
    cin >> N >> K >> S;

    if(S[K-1] == 'A'){
        S[K-1] = 'a';
    }

    if(S[K-1] == 'B'){
        S[K-1] = 'b';
    }

    if(S[K-1] == 'C'){
        S[K-1] = 'c';
    }

    cout << S << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define sf scanf
#define pf printf
#define pb push_back
#define all(a) a.begin(),a.end()
#define i64 long long int
const double pi = 2*acos(0) ;
const int maxn = (i64)2e5+5;

int main()
{
    int a,b;
    cin>>a>>b;
    if(b == 1) cout<<"0";
    else if(a == b) cout<<"1";
    else
    {
        int s = 1;
        int cnt = 0;
        while(s<b)
        {
            cnt++;
            s += a-1;
        }
        cout<<cnt;
    }


return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

class union_find {
private:
	vector<int> uf;

public:
	union_find(int n):uf(n, -1){}

	inline int find(int x) {
		return uf[x] < 0 ? x : uf[x] = find(uf[x]);
	}

	inline void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if(x == y)
			return;

		if(uf[x] > uf[y])
			swap(x, y);

		else if(uf[x] == uf[y])
			--uf[x];

		uf[y] = x;
	}

	inline int number_of_sets() {
		return count_if(uf.begin(), uf.end(), [](int& x) { return x < 0;});
	}
};

typedef int weight;
struct edge {
	int u, v;
	weight cost;
	edge(int u, int v, weight c):u(u), v(v), cost(c){}

	bool operator< (const edge& o) const {
		return cost < o.cost;
	}
};

int n, m;
vector<edge> es;

bool construct_spanning_tree(int start, int limit) {
	union_find uf(n);
	for(int i = start; i < m; ++i) {
		if(es[i].cost > limit) break;
		uf.unite(es[i].u, es[i].v);
	}

	return uf.number_of_sets() == 1;
}

bool check(int simness) {
	for(int i = 0; i < m - (n - 2); ++i) {
		if(construct_spanning_tree(i, es[i].cost + simness)) return true;
	}

	return false;
}

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

	while(cin >> n >> m && n) {
		es.clear();
		es.reserve(m);
		for(int i = 0; i < m; ++i) {
			int a, b, w;
			cin >> a >> b >> w;
			es.emplace_back(a - 1, b - 1, w);
		}

		sort(es.begin(), es.end());
		const int INF = es.back().cost - es.front().cost + 1;
		int low = -1, high = INF;
		while(low + 1 < high) {
			const int middle = (low + high) / 2;
			if(check(middle)) high = middle;
			else low = middle;
		}

		cout << (high == INF ? -1 : high) << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1264
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    int n,l;

    cin >> n >> l;

    vector<string> s;

    for(int i = 0; i < n ; i++){
        string input;
        cin >> input;
        s.push_back(input);
    }

    sort(s.begin(),s.end());

    for(int i=0;i<n;i++){
        cout << s[i];
    }
    cout << endl;

    return 0;
}

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

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

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  int s;cin>>s;
  set<int> set;
  set.insert(s);
  //cout<<"i: "<<0<<" s:"<<s<<endl;
  rep2(i,1,1e9){
    s=s%2==0? s/=2: 3*s+1;
    //cout<<"i: "<<i<<" s:"<<s<<endl;
    auto r = set.insert(s);
    if(!r.second){
      cout<<++i<<endl;
      return 0;
    }
    set.insert(s);
  }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
 
using namespace std;
 
int modpow(int x, int p)
{
    int t = p - 2;
    int m = x;
    int r = 1;
     
    while (t){
        if (t & 1){
            r = r * m % p;
        }
        m = m * m % p;
        t >>= 1;
    }
    return (r);
}
 
int p;
 
typedef struct {
    int value;
    int pos;
} result;
 
result ng = {-1, -1};
 
result equation(char *s, int pos);
result factor(char *s, int pos);
result term(char *s, int pos);
 
result equation(char *s, int pos)
{
    result temp, next;
    temp = factor(s, pos);
    while (s[temp.pos] == '+' || s[temp.pos] == '-'){
        next = factor(s, temp.pos + 1);
        if (next.pos == -1) return (ng);
        if (s[temp.pos] == '+'){
            temp.value += next.value;
            temp.value %= p;
        }
        else {
            temp.value += (p - next.value);
            temp.value %= p;
        }
        temp.pos = next.pos;
    }
     
    return (temp);
}
 
result factor(char *s, int pos)
{
    result temp, next;
    temp = term(s, pos);
    while (s[temp.pos] == '*' || s[temp.pos] == '/'){
        next = term(s, temp.pos + 1);
        if (next.pos == -1) return (ng);
        if (s[temp.pos] == '/'){
            if (!next.value) return (ng);
            next.value = modpow(next.value, p);
        }
        temp.value *= next.value;
        temp.value %= p;
        temp.pos = next.pos;
    }
     
    return (temp);
}
 
result term(char *s, int pos)
{
    int i;
    int value;
    result temp;
     
    if (s[pos] == '('){
        temp = equation(s, pos + 1);
        if (temp.pos == -1) return (ng);
        temp.pos += 1;
        return (temp);
    }
    else {
        value = 0;
        while ('0' <= s[pos] && s[pos] <= '9'){
            value = value * 10 + (s[pos++] - '0');
        }
        temp.value = value % p;
        temp.pos = pos;
        return (temp);
    }
}
 
 
int main()
{
    result res;
    char exp[100000], str[100000];
    while (scanf("%d:", &p) && p){
        fgets(exp, 100000, stdin);
        int k = 0;
        for (int i = 0; exp[i] != '\0'; i++){
            if (exp[i] == ' ' || exp[i] == '\n'){
                continue;
            }
            str[k++] = exp[i];
        }
        str[k] = '\0';
        res.pos = 0;
        res = equation(str, 0);
        if (res.pos != -1){
            printf("%s = %d (mod %d)\n", str, res.value, p);
        }
        else {
            printf("NG\n");
        }
    }
     
    return (0);
}

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

using namespace std;

typedef long long int ll;
 
template<class T> inline bool chmax(T& a,T b){ if(a<b){ a=b; return true;} return false; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){ a=b; return true;} return false; }
 
typedef pair<int,int> pair;

int main(){
  ll n,k; cin >> n >> k;

  ll mod=n%k;

  ll ans=abs(k-mod);

  if(n<ans) ans=n;
  if(mod==0) ans=0;

  cout << ans << endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
using ll = long long;
using p = pair<int,int>;
using Graph = vector<vector<int>>;
 
const double PI = acos(-1);
 
int main() {
	int N;
    cin >> N;
    int v[N] = {};
    int a;
    rep(i,N-1) {
    	cin >> a;
        v[a-1]++;
    }
    rep(i,N) {
    	cout << v[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 4360
#include <stdio.h>
 
int main(void) 
{
	int n, l, i, sum;
 
	scanf("%d%d", &n, &l);
	sum = 0;
	for (i = 1; i <= n; i++)
		sum += (l + i - 1);
	printf("%d\n", sum - (l > 0 ? l : (l + n - 1 >= 0 ? 0 : l + n - 1)));
	return 0;
}

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

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

	int m = N%10;
	if (m==2||m==4||m==5||m==7||m==9){
		cout << "hon" << endl;
	}else if(m==0||m==1||m==6||m==8){
		cout << "pon" << endl;
	}else if(m==3){
		cout << "bon" <<endl;
	}

	return 0;
}

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

int main(void) {
  int N;
  long long x;
  cin >> N >> x;
  vector<long long> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }

  long long ans = 0;
  for (int i = 1; i < N; i++) {
    long long eat = (a[i - 1] + a[i]) - x;
    if (eat > 0) {
      ans += eat;
      long long tmp = min(a[i], eat);
      a[i] -= tmp;
      eat -= tmp;
      a[i - 1] -= eat;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024