akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int N=in(),K=in();
	int R=in(),S=in(),P=in();
	string T=in<string>();
	vector<int> F(T.size(),0);

	ll A=0;

	REP(i,N){
		if(i<K){
			if(T[i]=='r') A += P;
			else if(T[i]=='s') A += R;
			else A += S;
		}
		else{
			if(T[i]=='r'){
				if(T[i-K]!='r' || F[i-K]) A += P;
				else if(T[i-K]=='r') F[i]=1;
			}
			else if(T[i]=='s'){
				if(T[i-K]!='s' || F[i-K]) A += R;
				else if(T[i-K]=='s') F[i]=1;
			}
			else{
				if(T[i-K]!='p' || F[i-K]) A += S;
				else if(T[i-K]=='p') F[i]=1;
			}
		}
	}
	out(A);
	return 0;
}


Measured memory_bytes: 848
#!/usr/bin/env python3
# coding: utf-8
import random


class Dice() :

    mask = {'N':(1,5,2,3,0,4), 'E':(3,1,0,5,4,2),
            'W':(2,1,5,0,4,3), 'S':(4,0,2,3,5,1),'CW':(0,2,4,1,3,5)}

    way = ("N","E","W","S","CW","Nop")

    def __init__(self, data):
        self.label = data

    def move(self, data):
        if data == "Nop":
            return
        self.label = [self.label[idx] for idx in self.mask[data]]

    def get_up(self):
        return self.label[0]

    def compare_6sq(self, dice2):
        check = True
        for i in range(6):
            if self.label[i] == dice2.label[i] :
                continue
            else:
                check = False
                break

        return check
    
    def compare_4rot(self, dice2):
        ok = False
        for i in range(4):
            self.move("CW")
            if self.compare_6sq(dice2) :
                ok =True
                break
        return ok
    
    def compare(self,dice2):
        ok = False
        orderway =("Nop","E","N","E","N","E")

        for s in orderway:
            self.move(s)
            if self.compare_4rot(dice2):
                ok = True
                break
        
        return ok





dice1 = Dice(input().split())
dice2 = Dice(input().split())

if dice1.compare(dice2) :
    print ("Yes")
else:
    print ("No")



Measured memory_bytes: 8192
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,x,ans=0,count=0;
  cin >> n >> x;
  vector<int> m(n);
  for(int i=0;i<n;i++){
    cin >> m[i];
    ans+=m[i];
    count++;
  }
  if(ans==x)
    cout << count << endl;
  else{
    sort(m.begin(),m.end());
    int d=(x-ans)/m[0];
    count+=d;
    cout << count << endl;
  }
}


Measured memory_bytes: 256
a, b, m = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
min_cost = min(a_list) + min(b_list)

for _ in range(m):
    x, y, c = map(int, input().split())
    _a = a_list[x-1]
    _b = b_list[y-1]
    cost = _a + _b - c
    min_cost = min(cost, min_cost)
print(min_cost)



Measured memory_bytes: 18736
#include <bits/stdc++.h>
using namespace std;
#define ri register int
typedef long long ll;
const int N=105;
int mod,f[2][N][N],fac[N],ifac[N],power[N][N*N],g[N][N];
inline int mul(ri x,ri y){
	return (ll)x*y%mod; 
}
inline void add(int &x,ri y){
	x=(x+=y)>=mod?x-mod:x;
}
inline int fpow(ri a,ri b){
	ri ans=1;
	for(;b;b>>=1,a=(ll)a*a%mod)
		if(b&1)
			ans=(ll)ans*a%mod;
	return ans;
}
int main(){
	ri n,m,K,lim,i,j,k,c,d;
	scanf("%d%d%d%d",&n,&m,&K,&mod);
	lim=max(n,m);
	fac[0]=1;
	for(i=1;i<=lim;++i) fac[i]=(ll)fac[i-1]*i%mod;
	ifac[lim]=fpow(fac[lim],mod-2);
	for(i=lim;i;--i) ifac[i-1]=(ll)ifac[i]*i%mod; 
	
	power[0][0]=1;
	for(d=1;d<=K;++d){
		power[d][0]=1;
		for(i=1;i<=n*m;++i)
			power[d][i]=mul(power[d][i-1],d);
	}
	
	c=0;
	f[c][0][0]=1;
	for(d=1;d<=K;++d){
		c^=1;memset(f[c],0,sizeof(f[c]));
		for(i=0;i<=n;++i)
			for(j=0;j<=m;++j)
				g[i][j]=mul(mul(ifac[i],power[d-1][i*(m-j)]),mul(power[K-d+1][i*j],i&1?mod-1:1));
				// 相当于是对 c-1 进行容斥
				// (最小值 = c-1 的答案) = (最小值 >= c-1 的答案) - (最小值 >= c 的答案) 
		for(i=0;i<=n;++i)
			for(j=0;j<=m;++j)
				for(k=0;k<=i;++k)
					add(f[c][i][j],mul(f[c^1][i-k][j],g[k][j]));
		
		c^=1;memset(f[c],0,sizeof(f[c]));
		for(i=0;i<=n;++i)
			for(j=0;j<=m;++j)
				g[i][j]=mul(mul(ifac[j],power[d-1][(n-i)*j]),mul(power[K-d+1][i*j],j&1?mod-1:1));
		for(i=0;i<=n;++i)
			for(j=0;j<=m;++j)
				for(k=0;k<=j;++k)
					add(f[c][i][j],mul(f[c^1][i][j-k],g[i][k]));
		
		c^=1;memset(f[c],0,sizeof(f[c]));
		for(i=0;i<=n;++i)
			for(j=0;j<=m;++j)
				g[i][j]=mul(mul(ifac[i],power[d][i*(m-j)]),power[K-d+1][i*j]);
		for(i=0;i<=n;++i)
			for(j=0;j<=m;++j)
				for(k=0;k<=i;++k)
					add(f[c][i][j],mul(f[c^1][i-k][j],g[k][j]));
		
		c^=1;memset(f[c],0,sizeof(f[c]));
		for(i=0;i<=n;++i)
			for(j=0;j<=m;++j)
				g[i][j]=mul(mul(ifac[j],power[d][(n-i)*j]),power[K-d+1][i*j]);
		for(i=0;i<=n;++i)
			for(j=0;j<=m;++j)
				for(k=0;k<=j;++k)
					add(f[c][i][j],mul(f[c^1][i][j-k],g[i][k]));
		
	//	printf("d = %d\n",d);
	//	for(i=0;i<=n;++i)
	//		for(j=1;j<=m;++j)
	//			printf("%d %d %d\n",i,j,f[c][i][j]);
	}
	printf("%d\n",mul(mul(f[c][n][m],fac[n]),fac[m]));
	return 0;
}

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


int main(){
  int A,B,C,D,E;
  int t = 0;

  cin >> A >> B >> C >> D >> E;

  if(A < 0){
    t += A*(-1)*C;
    A = 0;
  }

  if(A == 0){
    t += D;
    A = 0;
    t += B* E;
  }

  if(A > 0){
    t += (B - A) * E;
  }

  cout << t << endl;

  return 0;
}



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

int main() {
  string s;
  cin>>s;
  int c=0;
  for(int i=1;i<s.size()/2;i++) if(s.substr(0,i)==s.substr(i,i)) c=2*i;
  cout<<c;
}

Measured memory_bytes: 3612
#include <stdio.h>

int main(void){
  int n, i;
  scanf("%d", &n);
  int a[n];
  for(i = 0; i < n; i++) scanf("%d", &a[i]);
  int num = 0;
  int count = 0;
  i = 0;
  while(num < n){
    count = a[i];
    if(count == 2){
      num++;
      printf("%d\n", num);
      break;
    }else{
      i = count - 1;
      num++;
    }
    if(num == n) printf("-1\n");
  }
  return 0;
}


Measured memory_bytes: 512
//set many funcs template
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

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

int main(void){
    int i,j,n,m,t,k,a[262144],b[262144]={0},r=0,l;
    double d;
    char s[262144];
    scanf("%d",&n);
    //l=strlen(s);
    for(i=1;i<=n;i++){scanf("%d",&a[i]);
        b[a[i]]++;
    }
    for(i=1;i<=131072;i++){if(b[i]){r++;}}
    printf("%d\n",r);
    return 0;
}

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

int main()
{
	string input;
	while(1)
	{
		string tmp;
		getline (cin,tmp);
		input += tmp;
		if(cin.eof())
		{
			break;
		}
	}
	for(int i=0; i<input.length(); i++)
	{
		if('A'<=input[i] && input[i]<='Z')
		{
			input[i] = input[i]-'A'+'a';
		}
	}
	for(char i='a'; i<='z'; i++)
	{
		int count=0;
		for(int i2=0; i2<input.length(); i2++)
		{
			if(i == input[i2])
			{
				count +=1;
			}
		}
		cout << i << " : " << count << endl;
	}
	return 0;
}

Measured memory_bytes: 3020
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int A, N; cin >> N >> A;
  if (N%500 <= A) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3112
# python3 (3.4.3)
import sys
input = sys.stdin.readline

# main
N = int(input())
S = int(input())

def f(b,n):
    if n < b:
        return n
    else:
        return f(b, n//b) + n%b

ans = -1
if S==N:
    ans = N+1
else:
    # bをN^(1/2)まで全探索
    for b in range(2, int(N**.5)+1):
        if f(b,N)==S:
            ans = b
            break

# まだ答えが見つからなければ
if ans == -1:
    # bがN^(1/2)より大きい可能性が残っており、b進数で表すと2桁
    # 1 <= p < b, N = pb+q <= pb < p^2, p > N^(1/2) なので pで全探索
    # p+q = S より b = (N-S)/p+1
    for p in range(int(N**.5)+1,0,-1):
        b = (N-S)//p + 1
        # bが1のときは対象外にしないと無限ループ！
        if b >= 2 and f(b,N)==S:
            ans = b
            break

print(ans)


Measured memory_bytes: 3064
import java.util.*;
import java.math.*;

public class Main{
    Main(){
	Scanner sc = new Scanner(System.in);
	BigInteger bi;

	while(sc.hasNext()){
	    int cnt = 0;
	    for(int i = sc.nextInt(); i >= 1; --i){
		bi = new BigInteger(sc.next());
		if(bi.isProbablePrime(5)) ++cnt;
	    }
	    System.out.printf("%d\n", cnt);
	}
    }

    public static void main(String[] args){
	new Main();
    }
}

Measured memory_bytes: 13000
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//またはかかつか
//例外処理は最初にする
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll M = (pow(10, 9) + 7);

int main() {
	ll N; cin >> N;
	vector<ll> v(N), c(N);
	rep(i, N) cin >> v[i];
	rep(i,N)cin >> c[i];

	ll ans = 0;
	for (int i = 0; i < N; i++) {
		if (v[i] >= c[i]) ans += (v[i] - c[i]);
	}

	cout << ans << endl;
}

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

int main(){
  int h,w,y,x,d;
  long long l;
  string g[100];

  int vis[100][100][4];
  int px[40100],py[40100],pd[40100];

  char dir[] = {'N','E','S','W'};
  int dy[] = {-1,0,1,0}, dx[] = {0,1,0,-1};

  cin.tie(0);
  std::ios::sync_with_stdio(false);

  while(cin >> h >> w >> l,h){
    rep(i,h)cin >> g[i];

    rep(i,h)rep(j,w)rep(k,4){
      if(g[i][j] == dir[k]){
	y = i; x = j; d = k;
      }
      vis[i][j][k] = -1;
    }

    int step = 0;
    for(;;){
      if(vis[y][x][d]>=0)break;
      vis[y][x][d] = step;
      
      py[step] = y; px[step] = x; pd[step] = d;
      step++;

      rep(i,4){
	int nd = (d+i)%4;
	int ny = y+dy[nd], nx = x+dx[nd];
	if(ny<0 || nx<0 || ny>=h || nx>=w)continue;
	if(g[ny][nx] == '#')continue;
	y = ny; x = nx; d = nd;
	break;
      }
    }

    long long head = vis[y][x][d], now = l;
    if(step<l){
      now -= head;
      now %= step-head;
      now += head;
    }
    cout << py[now]+1 << " " << px[now]+1 << " " << dir[pd[now]] << endl;
  }
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a + b == c + d) {
    cout << "Balanced" << endl;
  }
  else if (a + b > c + d) {
    cout << "Left" << endl;
  }
  else if (a + b < c + d) {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
char a[51],b[51],c[102];
int main(){
    while(cin>>a>>b){
        if(strlen(a)-strlen(b)==1||strlen(a)-strlen(b)==0)
        {int t=0;
            for(int i=0;i<strlen(a);i++)
            {
                c[t]=a[i];
                t=t+2;
            }
            t=1;
            for(int i=0;i<strlen(b);i++)
            {
                c[t]=b[i];
                t=t+2;
            }cout<<c<<endl;

        }            else
                break;

    }

    }


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

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

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

int main(void){
    string s;
    cin >> s;
    s = "0" + s;
    int n = s.size();
    VVI dp(n + 1, VI(2, 1e9));
    dp[0][0] = 0;
    REP(i,n){
        int x = s[i] - '0';
        chmin(dp[i + 1][0], dp[i][0] + x);
        chmin(dp[i + 1][1], dp[i][0] + x + 1);
        chmin(dp[i + 1][0], dp[i][1] + 10 - x);
        chmin(dp[i + 1][1], dp[i][1] + 10 - x - 1);
    }
    cout << dp[n][0] << endl;
    return 0;
}


Measured memory_bytes: 55856
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<math.h>
#include<stdio.h>

using namespace std;

using ll = long long;

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

const ll INF = 1LL << 60;

typedef pair<ll, double> P;

bool pairCompare(const P& firstElof, const P& secondElof)
{
	return firstElof.second < secondElof.second;
}

bool IsPrime(ll num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

signed main() {
	ll ans = 0;

	ll n, m;
	cin >> n >> m;

	while (n > 0) {
		n = n / m;
		ans++;
	}

	cout << ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.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 REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;

int main(){
    
    while(true){
        int n; cin>>n;
        if(n==0)break;
        map<ll,pair<ll,ll>> m;
        REP(i,n){
            ll e,p,q; cin>>e>>p>>q;
            if(m.find(e)==m.end())m[e]=make_pair(p*q,i);
            else m[e].first+=p*q;
        }
        vector<pair<ll,ll>>ans;
        for(auto itr=m.begin();itr!=m.end();itr++){
            if(itr->second.first>=1000000){
                ans.push_back(make_pair(itr->second.second,itr->first));
            }
        }
        if(ans.size()==0)cout<<"NA"<<endl;
        else{
            sort(ans.begin(),ans.end());
            REP(i,ans.size())cout<<ans[i].second<<endl;
        }
    }
    
    
    
    return 0;
}

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

int main(void) {
  int n;
  cin >> n;
  int a[n];
  rep (i, n) cin >> a[i];

  ll ans = 0;

  int now = 1;
  rep (i, n) {
    if (a[i] != now) {
      ans++;
      continue;
    }
    else {
      now++;
    }
  }
  cout << (now == 1 ? -1 : ans) << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(){
  char c[300];
  int m,h,i,j,k,num=0,temp;
  while(1){
    scanf("%s",c);
    if(c[0]=='-')break;
    
      for(num=0; num<300; num++){
          if(c[num]=='\0')break;
      }scanf("%d",&m);
      for(i=0; i<m; i++){
          scanf("%d",&h);
          for(j=0; j<h; j++){
              temp=c[0];
              for(k=0; k<num; k++){
                  c[k]=c[k+1];
              }
              c[num-1]=temp;
          }
      }
    printf("%s\n",c);
  }
  return 0;
}




Measured memory_bytes: 2040
T = int(input())
##-----------------start coding-----------------
from heapq import *

for ti in range(1, T + 1):
    n, a, b, c, d = tuple(map(int, input().split()))
    pq = []
    heappush(pq, (0, n))  # cost, posi
    visited = set()  # positions
    while True:
        top = heappop(pq)
        cost, posi = top
        cost, posi = cost, posi
        if posi in visited:
            continue
        else:
            visited.add(posi)
        if posi == 0:
            print(cost)
            break
        costnaive = cost + d * posi
        heappush(pq, (costnaive, 0))
        for mode, margin in [(2, a), (3, b), (5, c)]:
            modulo = posi % mode
            costdown = cost + margin + modulo * d
            downto = (posi - modulo) // mode
            costup = cost + margin + (mode - modulo) * d
            upto = (posi + (mode - modulo)) // mode
            heappush(pq, (costdown, downto))
            heappush(pq, (costup, upto))


Measured memory_bytes: 14788
import java.util.*;

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

		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if(n == 0 && m == 0) break;

			ArrayList<ArrayList<Edge>> map = new ArrayList<ArrayList<Edge>>();
			for(int i=0;i<n;i++){
				map.add(new ArrayList<Edge>());
			}

			for(int i=0;i<m;i++){
				int a = sc.nextInt();
				int b = sc.nextInt();
				int cost = sc.nextInt();

				map.get(a).add(new Edge(a,b,cost));
				map.get(b).add(new Edge(b,a,cost));
			}

			System.out.println(kruskal(map));
		}
	}

	static int kruskal(ArrayList<ArrayList<Edge>> g){
		int n = g.size();
		UnionFind uf = new UnionFind(n);
		PriorityQueue<Edge> open = new PriorityQueue<Edge>();
		for(int i=0;i<n;i++){
			for(Edge e : g.get(i)) if(i < e.to) open.add(e);
		}

		int cost = 0;
		HashSet<Edge> closed = new HashSet<Edge>();
		while(closed.size() < n - 1 && !open.isEmpty()){
			Edge e = open.poll();
			if(uf.unionSet(e.from,e.to)){
				closed.add(e);
				cost += e.cost;
			}
		}
		return cost;
	}
}

class UnionFind{
	int[] data;

	UnionFind(int n){
		data = new int[n];
		Arrays.fill(data,-1);
	}

	boolean unionSet(int x,int y){
		x = root(x);
		y = root(y);
		if(x != y){
			if(data[y] < data[x]){
				x ^= y;
				y ^= x;
				x ^= y;
			}
			data[x] += data[y];
			data[y] = x;
		}
		return x!=y;
	}

	boolean findSet(int x,int y){
		return root(x) == root(y);
	}

	int root(int x){
		return data[x] < 0 ? x : (data[x] = root(data[x]));
	}

	int size(int x){
		return -data[root(x)];
	}
}

class Edge implements Comparable<Edge>{
	int from,to,cost;

	Edge(int from,int to,int cost){
		this.from = from;
		this.to = to;
		this.cost = cost;
	}

	public int compareTo(Edge e){
		return this.cost - e.cost;
	}
}

Measured memory_bytes: 12000
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <fstream>
#include <bitset>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;
const long long MOD = 1000000007LL;
const long long MAX = 500000LL;
using namespace std;
typedef unsigned long long ull;
typedef  long long ll;

int main()
{
	ll N, W;
	cin >> N >> W;
	vector<ll> v(N), w(N);
	for (ll i = 0; i < N; i++) {
		cin >> v[i] >> w[i];
	}
	vector<vector<ll>> dp(N + 1, vector<ll>(W + 1, -1));
	dp[0][0] = 0;
	for (ll i = 0; i < N; i++) {
		for (ll sum_w = 0; sum_w <= W; sum_w++) {
			if (sum_w < w[i]) {
				dp[i + 1][sum_w] = dp[i][sum_w];
			}
			else {
				dp[i + 1][sum_w] = dp[i][sum_w];
				if (dp[i + 1][sum_w - w[i]] == -1) continue;
				dp[i + 1][sum_w] = max(dp[i + 1][sum_w - w[i]] + v[i], dp[i][sum_w]);
			}
		}
	}

	ll res = 0;

	for (ll i = 0; i <= W; i++) {
		chmax(res, dp[N][i]);
	}

	cout << res << endl;
	return 0;
}



Measured memory_bytes: 10788
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
using namespace std;

int main()
{
	int n;

	string Tarou;
	string Hanako;

	int TarouP = 0;
	int HanakoP = 0;

	cin >> n;

	for (int i = 0; i < n; i++)
	{
		cin >> Tarou >> Hanako;

		int size;

		if (Tarou.size() > Hanako.size())size = Hanako.size();
		else size = Tarou.size();

		for (int j = 0; j < size; j++)
		{
			if (Tarou[j]<Hanako[j])
			{
				HanakoP += 3;
				break;
			}
			else if (Tarou[j]>Hanako[j])
			{
				TarouP += 3;
				break;
			}
			else if (Tarou[j]==Hanako[j]&&j==size-1)
			{
				if (size<Tarou.size())
				{
					TarouP += 3;
					break;
				}
				else if (size < Hanako.size())
				{
					HanakoP += 3;
					break;
				}
				else
				{
					TarouP += 1;
					HanakoP += 1;
				}
			}
		}
	}

	cout << TarouP << " " << HanakoP << endl;

	

	return 0;
}

Measured memory_bytes: 3204
using System;
using System.Collections.Generic;
namespace I_am_the_brown_coder{
    class Inonoa{
        static void Main(){
            string[] w_h_x_y = Console.ReadLine().Split();
            long w = long.Parse(w_h_x_y[0]);
            long h = long.Parse(w_h_x_y[1]);
            long x = long.Parse(w_h_x_y[2]);
            long y = long.Parse(w_h_x_y[3]);

            Console.Write((((double)(w*h))/2.0).ToString()+ " ");
            if(x*2==w && y*2==h){
                Console.WriteLine(1);
            }else{
                Console.WriteLine(0);
            }
        }
    }
}

Measured memory_bytes: 11092
while n=gets.to_i
  exit if n==0
  pipelen = gets.split(nil).inject(0){|sum, e|sum+e.to_i}
  joint = gets.split(nil).map(&:to_i).sort.reverse
  until joint.empty?
    break if pipelen*n > (pipelen+joint[0])*(n-1)
    n-=1
    pipelen+=joint.shift
  end
  puts pipelen*n
end

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

int main() {
	int n;
	cin >> n;
	int a;
	bool ans = true;
	for(int i = 0 ; i < n; i++){
		cin >> a;
		if(a % 2 == 0){
			if(a % 3 != 0 && a % 5 != 0)ans = false;
		}
	}
	if(ans)cout << "APPROVED" << '\n';
	else cout << "DENIED" << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long a;
  cin>>a;
  string b;
  cin>>b;
  string c;
  c.push_back(b[0]);
  c.push_back(b[2]);
  c.push_back(b[3]);
  long long d=std::stol(c);
  long long kotae=a*d;
  kotae/=100;
  cout<<kotae<<endl;
  return 0;
}

    


Measured memory_bytes: 3640
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main(){
    int n, a, b;
    string s;
    cin >> n >> a >> b >> s;

    int x, y;
    x = y = 0;

    REP(i,n){
        bool f = 0;
        if (s[i] == 'a'){
            if (x < a+b){
                f = 1;
                x++;
            }
        }else if (s[i] == 'b'){
            if (x < a+b && y < b){
                f = 1;
                x++;
                y++;
            }
        }

        if (f) printf("Yes\n");
        else printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
template <typename T> bool chmax(T &u, const T z) { if (u < z) {u = z; return true;} else return false; }
template <typename T> bool chmin(T &u, const T z) { if (u > z) {u = z; return true;} else return false; }
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
typedef pair<ll, ll> P;
const ll INF = 1LL << 60;
//const int MOD = 1000000007;
const ll MOD=998244353;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

int main(){
  string s,t;
  cin>>s;
  t="YAKI";
  if(s.substr(0,4)==t)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 3612
#include <iostream>
using namespace std;
int main() {
    int n, k;
    string s;
    cin >> n >> k >> s;
    int i,j;
    for(j=0;j<n;++j) {
        if(s[j] == '0' and (j == 0 or s[j-1] == '1')) --k;
        if (k < 0) {
            if(s[i] == '0' and s[i+1] == '1')++k;
            ++i;
        }
    }
    cout << j - i << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n) - 1; (i) >= 0; --i)
#define SZ(n) (int)(n).size()
#define ALL(n) (n).begin(), (n).end()
#define MOD LL(1e9 + 7)
#define INF 1000000
using namespace std;
using LL = long long;

int main() {
	int r, c;
	cin >> r >> c;
	int a[101][101] = {};
	int sum = 0;
	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			cin >> a[i][j];
			sum += a[i][j];
		}
		a[i][c] = sum;
		sum = 0;
	}
	for (int i = 0; i < c + 1; i++) {
		for (int j = 0; j < r; j++) {
			sum += a[j][i];
		}
		a[r][i] = sum;
		sum = 0;
	}
	for (int i = 0; i < r + 1; i++) {
		for (int j = 0; j < c + 1; j++) {
			cout << a[i][j];
			if (j != c) cout << " ";
		}
		cout << endl;
	}
	return 0;
}



Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int t;
ll n,arr[10005],x,k,d;

int main()
{
    cin>>x>>k>>d;
    x=abs(x);
    ll e = x/d;
    ll left=0;
    ll update=0;

    if(e<=k){
        update=x%d;
        left=k-e;
        if(left%2!=0 && left!=0){
            ll a=abs(d+update);
            ll b=abs(update-d);
            update=min(a,b);
        }

    }
    else{
        update=x-(k*d);
    }
    cout<<update<<endl;

    return 0;
}



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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))

#define DEBUG(x) cout<<#x<<": "<<(x)<<endl

#define MOD 998244353

int n,k;
vi g[125252];

pair<vi,vi> dfs(int p, int bef){
	vi v0({1});
	vi v1({0,1});
	for(int to : g[p])if(to != bef){
		pair<vi,vi> PVV = dfs(to,p);
		vi w0 = PVV.first;
		vi w1 = PVV.second;
		vi nv0(min(k+1,(int)(v0.size() + max(w0.size(), w1.size()) - 1)));
		vi nv1(min(k+1,(int)(v1.size() + max(w0.size(), w1.size()) - 1)));
		REP(i,v0.size())REP(j,w0.size()){
			if(i+j<nv0.size()){
				(nv0[i+j] += 1ll*v0[i]*w0[j]%MOD) %= MOD;
			}
		}
		REP(i,v0.size())REP(j,w1.size()){
			if(i+j<nv0.size()){
				(nv0[i+j] += 1ll*v0[i]*w1[j]%MOD) %= MOD;
			}
		}
		REP(i,v1.size())REP(j,w0.size()){
			if(i+j<nv1.size()){
				(nv1[i+j] += 1ll*v1[i]*w0[j]%MOD) %= MOD;
			}
		}
		REP(i,v1.size())REP(j,w1.size()){
			if(i+j<nv1.size()){
				(nv1[i+j] += 1ll*v1[i]*w1[j]%MOD) %= MOD;
			}
			if(i+j-1>=0 && i+j-1<nv1.size()){
				(nv1[i+j-1] += 1ll*v1[i]*w1[j]%MOD) %= MOD;
			}
		}
		v0 = nv0;
		v1 = nv1;
	}
	return make_pair(v0,v1);
}

int main(){
	scanf("%d%d",&n,&k);
	REP(i,n-1){
		int a,b;
		scanf("%d%d",&a,&b);
		--a; --b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	pair<vi,vi> ans = dfs(0,-1);
	int sum = 0;
	if(ans.first.size() > k)sum += ans.first[k];
	if(ans.second.size() > k)sum += ans.second[k];
	printf("%d\n",sum%MOD);
	return 0;
}


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

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
ll const MOD = 1000000007;

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    // 前処理
    COMinit();
  int n, m; cin >> n >> m;
  vector<pair<int, int>> fact;
  //Factorization
  int k = m;
  for(int i = 2; i*i <= m; i++){
    if(k % i == 0){
      int cnt = 0;
      while(k % i == 0){
        cnt++;
        k /= i;
      }
      fact.push_back({i,cnt});
    }
  }
  if(k != 1) fact.push_back({k,1});
  
  ll ans = 1;
  for(int i = 0; i < fact.size(); i++){
    ans *= COM(fact.at(i).second + n - 1, n - 1);
    ans %= MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 15536
#include <cstdio>
#include <iostream>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

typedef long long ll;

int n, m, q;

int as[51];
int bs[51];
int cs[51];
int ds[51];

int vs[15];

int go(int pos, int prev) {
  int res = 0;
  if(pos == n) {
    REP(i, q) {
      if(vs[bs[i]] - vs[as[i]] == cs[i]) {
        res += ds[i];
      }
    }
    return res;
  } else {
    for(int x = prev; x <= m; ++x) {
      vs[pos] = x;
      res = max(res, go(pos+1, x));
    }
  }
  return res;
}

int main(void) {
  cin >> n >> m >> q;
  REP(i, q) {
    cin >> as[i] >> bs[i] >> cs[i] >> ds[i];
    as[i]--;
    bs[i]--;
  }
  int res = go(0, 1);
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 3228
#include<bits/stdc++.h>
using namespace std;
#define itn int
#define int long long
#define mod 1000000007
#define fi first
#define se second
#define be begin()
#define en end()
#define re reverse
#define Set setprecision
#define NO cout<<"NO\n"
#define YES cout<<"YES\n"
#define No cout<<"No\n"
#define Yes cout<<"Yes\n"
const int INFi=2147483647;
const long long INFl=9223372036854775807LL;
template<typename T> T abs(T a,T b){
    return max(a,b)-min(a,b);
}
template<typename T> T lcm(T a,T b){//最小公倍数
    return (a*b)/gcd(a,b);
}
int gcd(int a,int b){//最大公約数
    int c=a%b;
    while(true){
	if(c==0) break;
	a=b;
	b=c;
	c=a%b;
    }
    return b;
}
bool IsPrime(int num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
    double sqrtNum = sqrt(num);
    for(int i=3;i<=sqrtNum;i+=2){
	if(num%i==0){
	    return false;
	}
    }
    return true;
}
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //int a,b;
    //string a,b;
    int n;
    int x[1000];
    int a=0,b=0,c=0;
    int sum=INFi;
    cin>>n;
    for(int i=0;i<n;i++){
	cin>>x[i];
    }
    sort(x,x+n);
    for(int i=0;i<=100;i++){
	a=0;
	for(int j=0;j<n;j++){
	    a+=(i-x[j])*(i-x[j]);
	}
	sum=min(a,sum);
    }
    cout<<sum<<"\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long int ll;
typedef unsigned long long ull;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
typedef pair<ll,ll> P;


int main()
{
   int n,k;
   cin>> n >>k;
   vector<int> p(n);
   rep(i,n)cin>>p[i];
   sort(p.begin(),p.end());
   int sum=0;
   rep(i,k)sum+=p[i];
   cout<<sum<<endl;
   return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  cout << fixed << setprecision(12);
  int n,k;
  cin>>n>>k;
  vector<double> vec(n);
  for(int i=0;i<n;i++){
    cin>>vec.at(i);
    vec.at(i)++;
  }
  double s=0;
  double mx=0;
  queue<double> q;
  rep(i,n){
    s+=vec.at(i);
    q.push(vec.at(i));
    if(q.size()>k){
      s-=q.front();
      q.pop();      
    }
    if(q.size()==k){
      mx=max(s,mx);
    }
  }
  double ans = mx/2;
  cout<< ans <<endl;
}









Measured memory_bytes: 3456
#include <bits/stdc++.h>
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() {
    ll N, K;
    cin >> N >> K;
    vector<ll>A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end(), greater<ll>());
    
    if (A[0] < K || (N == 1 && A[0] != K)) {
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }

    int p = A[0];
    for (int i = 1; i < N; i++) {
        p = gcd(A[i], p);
    }
    for (int i = 0; i < N; i++) {
        if (A[i]-K < 0) {
            break;
        }
        if ((A[i]-K) % p == 0) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
}



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

grid = []
for i in range(n+1):
  grid.append(input())

b = grid[-1]
flag = True
work_time = 0
total_time = 0

for i in grid:
  if i == b:
    break
  c,d = i.split()
  total_time += int(d)
  if c == b:
    work_time += int(d)
    flag = False
  if flag:
    work_time += int(d)

print(str(total_time - work_time))


Measured memory_bytes: 3060
import java.util.*;

public class Main{
	//2006 start

	int [] vx = {0,1,0,-1};
	int [] vy = {1,0,-1,0};
	int w, h;

	class State {
		int x,y,pos,step;
		StringBuilder dice;
		public State(int x, int y, int pos, int step, StringBuilder dice) {
			this.x = x;
			this.y = y;
			this.pos = pos;
			this.step = step;
			this.dice = dice;
		}
		@Override
		public String toString() {
			return "State [x=" + x + ", y=" + y + ", pos=" + pos + ", step="
					+ step + ", dice=" + dice + "]";
		}

	}

	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			w = sc.nextInt();
			h = sc.nextInt();
			if((w|h) == 0) break;
			char [][] data = new char[h][w];
			int sx = -1, sy = -1;
			for(int i = 0; i < h; i++){
				String s = sc.next();
				if(s.indexOf("#") >= 0){
					sx = s.indexOf("#");
					sy = i;
					s = s.replace('#', 'w');
				}
				data[i] = s.toCharArray();
			}
			String order = sc.next();

			LinkedList<State> open = new LinkedList<State>();
			String dice = "rcgmby";
			open.add(new State(sx, sy, 0, 0, new StringBuilder(dice)));

			HashSet<String> close = new HashSet<String>();
			close.add(dice + " " + sx + " " + sy);

			int ans = -1;
			while(! open.isEmpty()){
				State now = open.poll();
				//System.out.println(now);
				if(now.pos == order.length()){
					ans = now.step;
					break;
				}

				for(int i = 0; i < 4; i++){
					int xx = now.x + vx[i];
					int yy = now.y + vy[i];
					StringBuilder nextd = new StringBuilder(now.dice.toString());
					nextd = rotate(nextd, i);
					String nextc = nextd.toString() + " " + xx + " " + yy+ " " + (now.pos);


					if(! isOK(xx,yy)) continue;
					char next = data[yy][xx];
					if(close.contains(nextc)) continue;
					if(next == 'w'){
						close.add(nextc);
						open.add(new State(xx, yy, now.pos, now.step + 1, nextd));
					}
					else if(next == order.charAt(now.pos) && order.charAt(now.pos) == nextd.charAt(0)){
						close.add(nextc);
						open.add(new State(xx, yy, now.pos + 1, now.step + 1, nextd));
					}
				}
			}
			System.out.println(ans == -1 ? "unreachable" : ans);
		}
	}

	private boolean isOK(int xx, int yy) {
		if(0 <= yy && yy < h && 0<= xx && xx < w){
			return true;
		}
		return false;
	}

	private StringBuilder rotate(StringBuilder dice, int i) {
		switch(i){
		case 0:
			//down
			swap(dice, 0,2,1,3);
			break;
		case 1:
			//right
			swap(dice, 0,5,1,4);
			break;
		case 2:
			//up
			swap(dice, 0,3,1,2);
			break;
		case 3:
			//left
			swap(dice, 0,4,1,5);
			break;
		}
		return new StringBuilder(dice.toString());
	}

	private void swap(StringBuilder dice, int i, int j, int k, int l) {
		char c = dice.charAt(i);
		dice.setCharAt(i, dice.charAt(j));
		dice.setCharAt(j, dice.charAt(k));
		dice.setCharAt(k, dice.charAt(l));
		dice.setCharAt(l, c);
	}

	public static void main(String[] args) {
		new Main().doit();
	}
}

Measured memory_bytes: 21000
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;

string S;

int main() {
    cin >> S;
    int ret;
    int L = S.length();

    for(int i = 0; i <=100; i++){
        for(char c = 'a'; c <= 'z'; c++){

            bool flagc = true;

            rep(j, L-i){
                bool flag = false;
                rep(k, i+1){
                    if(S[j + k] == c) flag = true;
                }

                if(!flag){
                   flagc = false;
                   break;
                }
            }

            if(flagc){
                ret = i;
                goto goto1;
            }
        }
    }

goto1:
    cout << ret << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
main(){
int h,w,n;
while(cin>>h>>w&&h!=0&&w!=0){
  for(int i=0;i<h;i++){
    if(i%2){
      if(w==1){cout<<".";}
      for(int j=0;j<w-1;j+=2){
        cout<<".#";
        n=j;
      }
      if(n==w-3){cout<<".";}
    }
    else{
      if(w==1){cout<<"#";}
      for(int j=0;j<w-1;j+=2){
        cout<<"#.";
        n=j;
      }
      if(n==w-3){cout<<"#";}
    }
    cout<<endl;
  }
  cout<<endl;
}
return 0;
}



Measured memory_bytes: 3072
#include<bits/stdc++.h>
#include<unordered_map>	
#include<unordered_set>
#define pb emplace_back
#define rt(v) return cout<<v,0
#define sz(v) (int)(v.size())
#define all(a) a.begin(),a.end()
#define endl '\n'
#define space " "
typedef long long ll;
typedef unsigned long long ull;
const int N = 10 + 1e5;
const int mod = 1e9 + 7;
/*

███╗   ███╗███████╗███╗   ███╗███████╗    ██╗      ██████╗ ██████╗ ██████╗
████╗ ████║██╔════╝████╗ ████║██╔════╝    ██║     ██╔═══██╗██╔══██╗██╔══██╗
██╔████╔██║█████╗  ██╔████╔██║█████╗      ██║     ██║   ██║██████╔╝██║  ██║
██║╚██╔╝██║██╔══╝  ██║╚██╔╝██║██╔══╝      ██║     ██║   ██║██╔══██╗██║  ██║
██║ ╚═╝ ██║███████╗██║ ╚═╝ ██║███████╗    ███████╗╚██████╔╝██║  ██║██████╔╝
╚═╝     ╚═╝╚══════╝╚═╝     ╚═╝╚══════╝    ╚══════╝ ╚═════╝ ╚═╝  ╚═╝╚═════╝

*/

using namespace std;
void Ferrari() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
int main() {
	Ferrari();
	int k, s; cin >> k >> s;
	int ans = 0;
	for(int i = 0 ; i <= k ; ++i)
		for (int j = 0; j <= k; ++j)
		{
			if (i + j <= s && s - (i + j) <= k) ++ans;
		}
	cout << ans;
	return 0;
}





/* stuff you should look for
	* keepin sharp mind.
	* int overflow, array bounds.
	* special cases (n=1?), set tle , make sure you understand the problem correctly.
	* don`t stuck in a problem.
	* test the idea on samples.
	*/

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

#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,a,n) for(ll i=a;i<n;i++)

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tiii;
typedef pair<ll, ll> pll;

const int INF = 100000000;
const ll LINF = 1e18+5;

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    vector<ll> F(N);
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> F[i];
    sort(A.begin(), A.end());
    sort(F.begin(), F.end(), greater<ll>());
    ll Asum = 0;
    rep(i,N) Asum += A[i];
    if(K>=Asum) {
        cout << 0 << endl;
        return 0;
    }
    ll lhs = 0;
    ll rhs = 1000000000001;
    rep(i,50) {
        ll P = (lhs + rhs - 1) / 2;
        ll delnum = 0; 
        rep(j,N) {
            if(A[j]*F[j] > P) {
                delnum += (A[j] * F[j] - P + F[j] - 1) / F[j];
            }
        }
        if(delnum > K) lhs = P+1;
        else rhs = P+1;
    }
    cout << lhs << endl;

    return 0;
}

Measured memory_bytes: 3328
N = int(input())
p = [int(input()) for i in range(N)]
q = [0]*N
for i in range(N):
  q[p[i]-1] = i

cnt = 1
max_cnt = 1
for i in range(N-1):
    if q[i+1] > q[i]:
        cnt += 1
    else:
        max_cnt = max(max_cnt, cnt)
        cnt = 1
max_cnt = max(max_cnt, cnt)
print(N - max_cnt)

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

signed main()
{
  int N; cin >> N;
  int ans = 0;
  REP(n,N) {
    int a; cin >> a;
    if ((n+1)%2 == 1 && a%2 == 1) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define int long long
typedef long long ll;
using namespace std;

ll N, K, D[200001], flag=0;
vector<ll> C;
set<ll> S;
signed main(){
    cin >> N >> K;
    for(ll i=0;i<N;i++) {
        cin >> D[i+1];
    }
    S.insert(1);
    C.push_back(1);
    
    for(ll i=0;i<K;i++) {
        C.push_back(D[C[i]]);
        /*
        for(int i=0;i<C.size();i++) cout << " " << C[i];
        cout << endl;
        */
        if(S.find(C[i+1])!=S.end()) {
            flag=1;
            break;
        }
        else S.insert(C[i+1]);
    }
    ll a = C[C.size()-1];
    ll b, d;
    for(ll i=0;i<C.size();i++) {
        if(C[i]==a) {
            b = C.size()-1-i;
            d = i;
            break;
        }
    }
    //cout << a << endl;
    //cout << b << endl;

    if(flag==0) cout << a << endl;
    else {
        ll e = K%b;
        e -= d;
        while(e<0){
            e += b;
        }
        cout << C[d+e] << endl;
    }
    return 0;
}

Measured memory_bytes: 13508
// editorial
#include<iostream>
#include<vector>
using namespace std;

int main(){
    int n, k, c;
    cin >> n >> k >> c;
    string s;
    cin >> s;
    vector<int> r(n, -1), l(n, -1);
    int tim = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'x') continue;
        r[tim++] = i;
        i += c;
    }
    tim = k-1;
    for(int i = n-1; i >= 0; i--){
        if(s[i] == 'x') continue;
        l[tim--] = i;
        if(tim < 0) break;
        i -= c;
    }
    for(int i = 0; i < k; i++){
        if(r[i] == l[i])    cout << r[i]+1 << endl;
    }
    return 0;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

const int MOD = 1000000007;

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

    int ans = 0;
    rep(i, N - 1) {
        int count = 0;
        vector<bool> chars(26, false);
        for (int j = 0; j <= i; j++) {
            chars[S[j] - 'a'] = true;
        }

        for (int j = i + 1; j < N; j++) {
            if (chars[S[j] - 'a']) {
                chars[S[j] - 'a'] = false;
                count++;
            }
        }
        chmax(ans, count);
    }

    cout << ans << endl;
}

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

int a[100010];
int b[100010];
map<int, int> m;
int main(){
    int N;
    cin >> N;

    for(int i = 0; i < N; ++i){
        cin >> a[i];
    }

    int ckaz = 0;
    bool check = false;
    for(int i = 0; i < N; ++i){
        if(a[i] != a[N-i-1]){
            if(m[a[i]] == -1) ckaz--;
            if(m[a[N-i-1]] == 1) ckaz--;
            if(m[a[i]] == 0) ckaz++;
            if(m[a[N-i-1]] == 0) ckaz++;
            m[a[i]]++;
            m[a[N-i-1]]--;
        }
        
        if(ckaz == 0){
            if(check){
                cout << " ";
            }
            check = true;
            cout << i+1;
        }
    }
    cout << endl;
}


Measured memory_bytes: 5808