akhauriyash/Code-Regression huggingface dataset:
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

//------------------------- Libraries -------------------------//

vector<int> sieve(int N) {
    vector<int> res;
    vector<int> is_prime(N+1, true);
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i <= N; i++) {
        if (is_prime[i]) {
            res.push_back(i);
            for (int j = 2 * i; j <= N; j+=i) {
                is_prime[j] = false;
            }
        }
    }
    return res;
}

//--------------------------- Solve ---------------------------//

void solve() {
    int X; cin >> X;
    vector<int> prime = sieve(1000000);

    int ans = *lower_bound(prime.begin(), prime.end(), X);

    cout << ans << '\n';
}

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

    solve();

    return 0;
}

Measured memory_bytes: 7796
#include <bits/stdc++.h>
#define y1 __zzd001
using namespace std;
int n,m,q;
const int N=10000000;
inline int P(int i, int j) {
	if(i == 0 || j == 0) return N-1;
	return i*m+j;
}
int read(){
	int x=0; scanf("%d", &x); return x;
}
int g[N],s1[N],s2[N],s3[N];
int main(){
	n=read(),m=read(),q=read();
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++){
			scanf("%1d",&g[P(i, j)]);
			s1[P(i, j)]=s1[P(i, j-1)]+s1[P(i-1, j)]-s1[P(i-1, j-1)]+g[P(i, j)];
			s2[P(i, j)]=s2[P(i, j-1)]+(g[P(i, j)]&&g[P(i-1, j)])
					+s2[P(i-1, j)]-s2[P(i-1, j-1)];
			s3[P(i, j)]=s3[P(i, j-1)]+(g[P(i, j)]&&g[P(i, j-1)])
					+s3[P(i-1, j)]-s3[P(i-1, j-1)];
		}
	while (q--){
		int x1=read(),y1=read(),x2=read(),y2=read();
		int ans=s1[P(x2, y2)]-s1[P(x2, y1-1)]-s1[P(x1-1, y2)]+s1[P(x1-1, y1-1)];
		ans-=s2[P(x2, y2)]-s2[P(x2, y1-1)]-s2[P(x1, y2)]+s2[P(x1, y1-1)];
		ans-=s3[P(x2, y2)]-s3[P(x2, y1)]-s3[P(x1-1, y2)]+s3[P(x1-1, y1)];
		printf("%d\n",ans);
	}
	return 0;
}


Measured memory_bytes: 67328
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[100010];
int main(){
    int n;
    string s;
    while(cin>>s){
        ll ans=0;
        for(int i=0; i<2; ++i){
        	if(s[i]!=s[i+1]){
        		ans=1;
        	}
        }
        if(ans){
        	cout<<"Yes"<<endl;
        }
        else{
        	cout<<"No"<<endl;
        }
    }
  return 0;
}




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


accum = [0] * (N+1)
for i in range(N):
    accum[i+1] = (accum[i] + A[i]) % (10**9+7)

ans = 0
for i in range(N-1):
    ans += (A[i] * (accum[-1] - accum[i+1])) % (10**9+7)

print(ans % (10**9+7))


Measured memory_bytes: 94108
#include <bits/stdc++.h>
#define int long long
#define rep(a,b) for(int (a)=0; (a)<(int)(b); ++(a))
#define all(a) (a).begin(),(a).end()
#define sel(a,b,c) (a).begin()+(b),(a).begin()+(b)+(c)
#define prec(a) fixed<<setprecision(a)
using namespace std;

constexpr int MOD=1000000007;
using ull=unsigned long long;
template<typename T>
using vec=vector<T>;
template<typename T>
using dvec=vector<vec<T>>;
using pint=pair<int,int>;

void print(void){cout<<"\n";}

template<class HEAD,class... TAIL>
void print(HEAD&& head,TAIL&&... tail){
  cout<<head<<" ";
  print(forward<TAIL>(tail)...);
}

template<typename T,typename U,class... TAIL>
void print(pair<T,U> p,TAIL&&... tail){
  cout<<p.first<<" "<<p.second<<" ";
  print(forward<TAIL>(tail)...);
}

signed main(void){
  int N,K; cin>>N>>K;
  vector<int> a(N);
  rep(i,N) cin>>a[i];
  int p=lower_bound(all(a),1)-a.begin();
  cout<<ceil((double)p/(K-1))+ceil((double)(N-p-1)/(K-1));
}


Measured memory_bytes: 1024
N=int(input())
A=[int(input())for _ in range(N)]
A.sort()
ans=0
ptr=0

while(ptr<N):
    cc=A[ptr]
    f=0

    while ptr<N and A[ptr]==cc:
        f += 1
        ptr += 1
    
    ans += f%2

print(ans)


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

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

	if(A == 1)A+=100;
	if(B == 1)B+=100;

	if(A>B){
		cout << "Alice" << endl;
	}else if(A < B){
		cout << "Bob" << endl;
	}else{
		cout << "Draw" << endl;
	}
}


Measured memory_bytes: 256
x,k,d = map(int,input().split())

if x < 0:
    x = -x

p = (x + d - 1) // d

if p <= k:
    if p % 2 == k % 2:
        print(-(x - p * d))
    else:
        print(x-(p-1)*d)
else:
    print(x-k*d)

Measured memory_bytes: 9180
#include<stdio.h>

#define MAX 100010
#define NIL -1

struct Node {int p,l,r;};

struct Node T[MAX];
int n,D[MAX];

void print(int u){
  int i,c;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].p);
  printf("depth = %d, ",D[u]);

  if(T[u].p==NIL)printf("root, ");
  else if(T[u].l==NIL)printf("leaf, ");
  else printf("internal node, ");

  printf("[");

  for( i=0,c=T[u].l ; c!=NIL ; i++, c=T[c].r ){
    if(i)printf(", ");
    printf("%d",c);
  }
  printf("]\n");
}

void dep(int u,int p){
  D[u]=p;
  if(T[u].r!=NIL)dep(T[u].r,p);
  if(T[u].l!=NIL)dep(T[u].l,p+1);
}

int main(){
  int i,j,d,v,c,l,r;

  scanf("%d",&n);
  for(i=0;i<n;i++) T[i].p =T[i].l = T[i].r= NIL;
  for(i=0;i<n;i++){
    scanf("%d%d",&v,&d);
    for(j=0;j<d;j++){
      scanf("%d",&c);
      if(j==0)T[v].l=c;
      else T[l].r=c;
      l=c;
      T[c].p=v;
    }
  }
  for(i=0;i<n;i++){
    if(T[i].p==NIL)r=i;
  }
  dep(r,0);

  for(i=0;i<n;i++)print(i);

  return 0;
}
  



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

char al[]="abcdefghijklmnopqrstuvwxyz";

int al_num(char a){
	int i;
	for(i=0;i<26;i++){
		if(al[i]==a){
			return i+1;
		}
	}
	return 0;
}

int min(int a,int b){
	if(a>b){
		return b;
	}
	return a;
}

int main(){
	int i,j,num,taroumaru=0,hanako=0;
	char input[256],word_1[128],word_2[128],*p;
	
	
	fgets(input,sizeof input,stdin);
	sscanf(input,"%d",&num);
	
	
	
	for(i=0;i<num;i++){
		fgets(input,sizeof input,stdin);
		p=strtok(input," ");
		sprintf(word_1,"%s",p);
		p=strtok(NULL," ");
		sprintf(word_2,"%s",p);
		
		
		//word_1[strlen(word_1)-1]='\0';
		word_2[strlen(word_2)-1]='\0';
		
		
		for(j=0;j<min(strlen(word_1),strlen(word_2));j++){
			if(al_num(word_1[j])>al_num(word_2[j])){
				taroumaru+=3;
				break;
			}else if(al_num(word_1[j])<al_num(word_2[j])){
				hanako+=3;
				break;
			}
			
			if(j==min(strlen(word_1),strlen(word_2))-1){
				if(strcmp(word_1,word_2)==0){
					taroumaru++;
					hanako++;
				}else{
					if(strlen(word_1)>strlen(word_2)){
						taroumaru+=3;
					}else{
						hanako+=3;
					}
				}
			}
			
		}
		
	}
	printf("%d %d\n",taroumaru,hanako);
	
	return 0;
}

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

namespace AtcoderTemplateForCSharp
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());

            var sides = Console.ReadLine()
                .Split(' ')
                .Select(int.Parse);

            var sortedSides = sides.OrderBy(side => side);

            // 実装1（愚直に。遅いと思ったらこっちのほうが速かった。）
            //if (sortedSides.Last() < sortedSides.Sum() - sortedSides.Last())
            //{
            //    Console.WriteLine("Yes");
            //}
            //else
            //{
            //    Console.WriteLine("No");
            //}

            // 実装2（こっちのほうが効率がいいかも？実際はこっちのほうが遅かった。範囲を足し合わせる処理があるから？）
            if (sortedSides.Last() < sortedSides.Take(sortedSides.Count() - 1).Sum())
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 13396
sentence = input()

count = 0
maxcount = 0
for i in range(len(sentence)):
    if sentence[i] == "A" or sentence[i] == "G" or sentence[i] == "C" or sentence[i] == "T":
        count+=1
    else:
        count = 0
    if count > maxcount:
        maxcount = count
        
print(maxcount)

Measured memory_bytes: 3060
from math import *

def isprime(n):
  if n<10: return n in (2,3,5,7)
  for i in range(2,int(sqrt(n)+1)):
    if n%i==0:
      return False
  return True

x = int(input())
for d in range(x, x+300):
  if isprime(d):
    print(d)
    break

Measured memory_bytes: 3060
/*input

*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

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

vector<pair<pll,ll>> edge;

ll dis[maxn];
bool neg[maxn];
int main()
{
	int n,m;
	cin>>n>>m;
	REP(i,m){
		ll u,v,x;
		cin>>u>>v>>x;
		u--;v--;
		edge.pb(MP(MP(u,v),-x));
	}
	REP(i,n) dis[i]=INF64;
	dis[0]=0;

	REP(i,n) REP(j,m){
		ll u=edge[j].F.F,v=edge[j].F.S,d=edge[j].S;
		dis[v]=min(dis[v],dis[u]+d);
	}
	REP(i,n) REP(j,m){
		ll u=edge[j].F.F,v=edge[j].F.S,d=edge[j].S;
		if(dis[v]>dis[u]+d||neg[u]==1){
			neg[v]=1;
		}
	}
	if(neg[n-1]){
		cout<<"inf\n";
		return 0;
	}
	cout<<-dis[n-1]<<'\n';
	return 0;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  vector<bool> have(N, false);
  vector<vector<int>> vec(K, vector<int>());

  for (int i = 0; i < K; i++) {
    int d;
    cin >> d;
    for (int j = 0; j < d; j++) {
      int a;
      cin >> a;
      vec[i].push_back(a);
      have[a - 1] = true;
    }
  }
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (have[i] == false) {
      count++;
    }
  }

  cout << count << endl;
}


Measured memory_bytes: 3640
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s;
  cin >> s;
  string a = "CODEFESTIVAL2016";
  int count = 0;
  for(int i=0;i<16;i++)
    if(s[i]!=a[i]) count++;
  cout << count << endl;
 return 0;
}


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

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

int main(void){
    int N, M, K; cin >> N >> M >> K;
    bool res = false;
    for(int i = 0; i <= N; i++){
        for(int j = 0; j <= M; j++){
            int num = 0;
            num += M*i;
            num -= i*j;
            num += (N-i)*j;
            if(num == K){
                res = true;
            }
        }
    }
    if(res)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class CLamps {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int N, K;
        in>>N>>K;
        vc<int> A(N+1), B(N+1);
        REP(i, N) in>>A[i];
        while(K--){
            REP(i, N){
                B[max(i-A[i], 0)]++;
                B[min(N, i+A[i]+1)]--;
            }
            REP(i, N) B[i+1] += B[i];
#ifdef DEBUG
            REP(i, N) out<<B[i]<<' ';
            out<<'\n';
#endif
            swap(A, B);
            fill(ALL(B), 0);
            bool ok = true;
            REP(i, N) ok &= (A[i]==N);
            if(ok) break;
        }
        REP(i, N) out<<A[i]<<' ';
        out<<'\n';
    }
};


int main() {
	CLamps solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 4780
#include<bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
using namespace std;
inline int read(){
	int v=0,f=1;
	char c=getchar();
	while (c<'0' || c>'9'){
		if (c=='-') f=-1;
		c=getchar();
	}
	while (c>='0' && c<='9'){
		v=v*10+c-'0';
		c=getchar();
	}
	return v*f;
}
LL T=1e9;
int main(){
	LL S;
	cin>>S;
	LL Su=(S+T-1)/T;
	LL Rem=Su*T-S;
	printf("%d %d %d %d %d %d\n",0,0,T,1,Rem,Su); 
} 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include<iomanip>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60

int a[200009]; // a[i] : 1～i番目までの石のうち黒の個数

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

	int N; cin >> N;
	a[0] = 0;
	for (int i = 1; i <= N; i++) {
		a[i] = a[i - 1];
		char tmp; cin >> tmp;
		if (tmp == '#') a[i]++;
	}


	int ans = INF;
	// すべて同じ色なら0
	if (a[N] == N) ans = 0;
	if (a[N] == 0) ans = 0;

	// i番目以降すべて黒
	for (int i = 1; i <= N+1; i++) {
		int tmp = a[i - 1] + N - i + 1 - (a[N] - a[i - 1]);
		ans = min(ans, tmp);
	}
	cout << ans << endl;

	return 0;
}

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

using namespace std;

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

    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    for (int i = 0; i < H; ++i) {
        cin >> S[i];
    }
    vector<vector<int>> row(H, vector<int>(W, 0));
    vector<vector<int>> col(row);

    for (int i = 0; i < H; ++i) {
        for (int j = 0, k = 0, cnt = 0; j < W; ++j) {  
            if (k <= j) {
                k = j;
                cnt = 0;
                while (k < W && S[i][k] == '.') {
                    ++cnt;
                    ++k;
                }
            }
            row[i][j] = cnt;
        }
    }
    for (int j = 0; j < W; ++j) {
        for (int i = 0, k = 0, cnt = 0; i < H; ++i) {
            if (k <= i) {
                k = i;
                cnt = 0;
                while (k < H && S[k][j] == '.') {
                    ++cnt;
                    ++k;
                }
            }
            col[i][j] = cnt;
        }
    }
    int res = 0;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            res = max(res, row[i][j] + col[i][j] - 1);
        }
    }
    cout << res << "\n";
    
    return 0;
}

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

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define hash sodnf9843bsd
#define ll long long
#define INF (1<<29)
#define INFF 0x7fffffff
#define LINF (1ll<<60)
#define LINFF 0x7fffffffffffffff
#define PI 3.14159265359
#define _fi(n) for(int i = 0;i < n;i++)
#define _fj(n) for(int j = 0;j < n;j++)
#define _fk(n) for(int k = 0;k < n;k++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define YESNO(ans) cout << (ans?"YES":"NO") << endl
#define prec(x) cout << fixed << setprecision(x)
#define pqueue priority_queue
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define endl '\n'

const ll maxn = 100;
const ll maxv = 100000;
ll iw[maxn+7];
ll dp[maxn+7][maxv+7] = {};
int iv[maxn+7];
int n, w;

ll solve(int i, int j){
    if (j <= 0) return 0;
    if (i == n) return LINF;

    if (dp[i][j] == 0){
        dp[i][j] = min(solve(i+1, j-iv[i])+iw[i], solve(i+1, j));
    }
    return dp[i][j];
}

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

    cin>>n>>w;
    _fi(n) cin>>iw[i]>>iv[i];

    int ans = 0;
    for(int i = 0;i <= maxv;i++){
        if (solve(0, i) <= w) ans = i;
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 80128
n,a,b = map(int,input().split())
su = 0
co = 0
for i in range(1,n+1):
  ii = list(map(int,list(str(i))))
  for j in range(len(ii)):
    co += ii[j]
  if co <= b and co >= a:
    su += i
  co = 0
print(su)


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

typedef long long ll;

ll memo[10000] = {0};

ll lucas(int x) {
    if (x == 0) return 2;
    else if (x == 1) return 1;
    else if (memo[x] != 0) return memo[x];
    return memo[x] = lucas(x - 2) + lucas(x - 1);
}

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

    // solve
    ll ans = lucas(N);

    // output
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
# coding: UTF-8
# ???????????´??° x ???????????????????????????????????????????????????????????°?????????????????????????????????

data_set = []
while True:
	n = input()
	if n == 0:
		break
	data_set.append(n)

case = 1
for n in data_set:
	print "Case %d: %d" %(case, n)
	case +=	1

Measured memory_bytes: 6516
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
long long fac(ll a){
    long long ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
int main(){
    int h,w;
    cin >> h >> w;
    vector<string> field(h);
    rep(i,h)cin >> field[i];
    vvl dist(h,vl(w,-1));
    dist[0][0]=0;
    queue<pl> que;
    que.push(mp(0,0));
    while(!que.empty()){
        pl cur=que.front();
        ll y=cur.fi;
        ll x=cur.se;
        que.pop();
        for(ll dir=0;dir<4;dir++){
            ll nx=x+dx[dir];
            ll ny=y+dy[dir];
            if(nx<0||nx>=w||ny<0||ny>=h)continue;
            if(field[ny][nx]=='#')continue;
            if(dist[ny][nx]==-1){
                que.push(mp(ny,nx));
                dist[ny][nx]=dist[y][x]+1;
            }
        }
    }
    if(dist[h-1][w-1]==-1){
        cout << -1 << endl;
        return 0;
    }
    ll count=0;
    rep(i,h){
        rep(j,w){
            if(field[i][j]=='.')count++;
        }
    }
    cout << count-dist[h-1][w-1]-1 << endl;
}

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

int paper[100][100];
void init(){
    for(int i = 0; i < 100; i++){
        for(int j = 0; j < 100; j++){
            paper[i][j] = 0;
        }
    }
}

void adjust(){
    for(int x = 0; x < 100; x++){
        queue<int>Q;
        for(int y = 0; y < 100; y++){
            if(paper[y][x]){
                Q.push(paper[y][x]);
                paper[y][x] = 0;
            }
        }
        for(int y = 0; y < 100; y++){
            if(Q.empty())break;
            paper[y][x] = Q.front();
            Q.pop();
        }
    }
    for(int y = 0; y < 100; y++){
        queue<int>Q;
        for(int x = 0; x < 100; x++){
            if(paper[y][x]){
                Q.push(paper[y][x]);
                paper[y][x] = 0;
            }
        }
        for(int x = 0; x < 100; x++){
            if(Q.empty())break;
            paper[y][x] = Q.front();
            Q.pop();
        }
    }
}

void turn(){
    int d, c;
    cin >> d >> c;
    if(d == 2){
        for(int y1 = 0; y1 < c; y1++){
            int y2 = 2 * c - 1 - y1;
            for(int x = 0; x < 100; x++){
                paper[y2][x] += paper[y1][x];
                paper[y1][x] = 0;
            }
        }
    }
    else{
        for(int x1 = 0; x1 < c; x1++){
            int x2 = 2 * c - 1 - x1;
            for(int y = 0; y < 100; y++){
                paper[y][x2] += paper[y][x1];
                paper[y][x1] = 0;
            }
        }
    }
    adjust();
}

int main(){
    
    for(int w, h, t, p; cin >> w >> h >> t >> p, w;){
        init();
        for(int y = 0; y < h; y++){
            for(int x = 0; x < w; x++){
                paper[y][x] = 1;
            }
        }
        for(int i = 0; i < t; i++){
            turn();
        }
        for(int i = 0; i < p; i++){
            int x, y;
            cin >> x >> y;
            cout << paper[y][x] << endl;            
        }
    }    

    return 0;
}



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

int main() {
    int n, k;
    vector<int> ds;
    cin >> n >> k;
    for(int i = 0; i < k; i++) {
        int d;
        cin >> d;
        ds.push_back(d);
    }
    
    while(1) {
    
        bool ok = 1;
        for(int m = n; m; m /= 10) {
            for(int d : ds)
                if(m % 10 == d) ok = 0;
        }
        
        if(ok) {
            cout << n << "\n";
            return 0;
        }
        
        n++;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
long long N, ans;
vector<long long>A, L, R;
void solve() {
    cin >> N;
    A.resize(N);
    L.resize(N + 1);
    R.resize(N + 1);
    L[0] = 0;
    R[N] = 0;
    ans = -INFL;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++) {
        L[i + 1] = __gcd(L[i], A[i]);
    }
    reverse(A.begin(), A.end());
    for (int i = 0; i < N; i++) {
        R[i + 1] = __gcd(R[i], A[i]);
    }
    for (int i = 0; i < N; i++) {
        ans = max(ans, __gcd(L[i], R[N - 1 -i]));
    }
    cout << ans << endl;
    return;
}
//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
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(int args, char* argv[]) {
    solve();
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+5;
signed main(){
	int n;cin>>n; int sb[N];int sum=0;
	for(int i=1;i<=n;i++)cin>>sb[i];
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			for(int z=j+1;z<=n;z++){
				if(sb[i]+sb[j]>sb[z]&&sb[i]+sb[z]>sb[j]&&sb[j]+sb[z]>sb[i]&&sb[i]!=sb[j]&&sb[i]!=sb[z]&&sb[j]!=sb[z])sum++;
			}
		}
	}
	cout<<sum<<"\n";
}

Measured memory_bytes: 3640
let s = read_line ()
let n = String.length s
let fs, is, i = Array.(make 26 false, make 26 0, ref 0)
let _ = String.(Char.(iter (fun c -> let n = code c - 97 in fs.(n) <- true; is.(!i) <- n; incr i) s;
  if n < 26 then (i := 0; while fs.(!i) do incr i done; Printf.printf "%s%c\n" s (chr (!i + 97)))
  else (for j = n - 1 downto 0 do i := code s.[j] - 96; while !i < 26 && fs.(!i) do incr i done; if !i < 26 then (Printf.printf "%s%c\n" (sub s 0 j) (chr (!i + 97)); exit 0) else (fs.(is.(j)) <- false) done; print_endline "-1")))

Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
const int inf = 1 << 30;
const ll linf = 1e18;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int N;
int G[200010];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N;
    for(int i = 1; i < N; i++){
        int A;
        cin >> A;
        G[A]++;
    }
    for(int i = 1; i <= N; i++){
        cout << G[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 4396
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define modn 1000000007
 
#define SZ 300005
using namespace std;
 
int main()
{
    ll d,n;
    cin>>d>>n;
    if(n == 100)
    {
        if(d == 0) cout<<101;
        else if(d == 1) cout<<100*101;
        else cout<<100*100*101;
    }
    else
    {
        if(d == 0) cout<<n;
        else if(d == 1) cout<<100*n;
        else cout<<100*100*n;
    }
    return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <functional>
# include <utility>
# include <queue>
# include <stack>
# define MOD 1000000007
# define INF 2000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
int main() {
	int ans = 0, counter = 0, maxi = -1, mini = INF;
	//new
	int a = 0;
	int deli[51];
	cin >> a;
	rep(i, a) {
		cin >> deli[i];
	}
	for(int i=0;i<a-1;i++){
		for (int j = i + 1; j < a; j++) {
			ans += deli[i] * deli[j];
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
import sys
import os

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B, C = list(map(int, sys.stdin.buffer.readline().split()))
    print('Yes' if A+B>=C else 'No')


if __name__ == '__main__':
    main()


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

using namespace std;
typedef long long ll;
const int MAXN = 2000 + 5;
const int N2 = 2000 * 2000 + 10;
const int MOD = 1e9 + 7;
int n, k;
ll dp[MAXN][MAXN], fac[N2], inv[N2];

ll c(int m, int k){
	if( m < k) return 0;
	return fac[m]*inv[k]%MOD*inv[m - k]%MOD;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n >> k;
	if( k == 1)
		return cout << 1 << endl, 0;
	fac[0] = 1, inv[0] = 1,inv[1] = 1, fac[1] = 1;
	for(int i = 2; i < N2; i++){
		fac[i] = fac[i - 1]*i%MOD;
		inv[i] = (MOD - MOD/i) * inv[MOD % i] % MOD;
	}
	for(int i = 1; i < N2; i ++)
		inv[i] = inv[i] * inv[i - 1] % MOD;
	dp[0][0] = 1;
	for(int i = 1; i <= n; i ++){
		for(int j = i; j>= 0 ;j --){
			dp[i][j] = dp[i][j + 1] % MOD;
			if( j ) dp[i][j] = (dp[i][j] + (dp[i - 1][j - 1] * c(i*k - j - 1, k - 2)) % MOD) % MOD;
			dp[i][j] %= MOD;
		}
	}
	cout << dp[n][0] * fac[n] % MOD << endl;
	return 0;
}

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

using namespace std;
using ll = long long;
const int maxn = 1e5 + 5;

ll up[maxn], down[maxn], L[maxn], R[maxn];

vector<int> adj[maxn];
int n, mod;

void dfsDown(int u, int p){
    down[u] = 1;
    for (auto v : adj[u]){
        if (v != p){
            dfsDown(v, u);
            down[u] = down[u] * (1 + down[v]) % mod;
        }
    }
}

void dfsUp(int u, int p){
    if (p != -1)
        adj[u].erase(remove(adj[u].begin(), adj[u].end(), p), adj[u].end());
    int sz = adj[u].size();
    for (int i = 0; i < sz; i++){
        L[i] = R[i] = 1;
    }
    if (sz){
        L[0] = down[adj[u][0]] + 1;
        R[sz - 1] =  down[adj[u][sz - 1]] + 1;
        for (int i = 1; i < sz; i++){
            L[i] = L[i - 1] * (1 + down[adj[u][i]]) % mod;
        }
        for (int i = sz - 2; i >= 0; i--){
            R[i] = R[i + 1] * (1 + down[adj[u][i]]) % mod;
        }
        for (int i = 0; i < sz; i++){
            up[adj[u][i]] = 1 + up[u] * (i - 1 >= 0 ? L[i - 1] : 1) % mod * (i + 1 < sz ? R[i + 1] : 1) % mod;
        }
    }
    for (auto v : adj[u]){
        dfsUp(v, u);
    }
}

int main()
{
    cin >> n >> mod;
    for (int i = 0; i < n - 1; i++){
        int a, b;
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    dfsDown(1, -1);
    up[1] = 1;
    dfsUp(1, -1);
    for (int i = 1; i <= n; i++){
        ll ans = up[i] * down[i];
        ans %= mod;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 14208
n, k = map(int, input().split())

if 2 * k > n + 1:
    print(-1)
    exit(0)

ans = []
for i in range((n+1)//2):
    ans.append((k+i, k+n+i+n//2, k+2*n+2*i))
for i in range(n//2):
    ans.append((k+(n+1)//2+i, k+n+i, k+2*n+2*i+1))


for x in ans:
    print(*x)


Measured memory_bytes: 60432
#include  <bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

using namespace std;

#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define allarr(a) a , a + n
#define ll long long
#define ull unsigned long long 
#define pb push_back
#define fastio ios_base::sync_with_stdio(false) ; cin.tie(NULL); cout.tie(NULL)
typedef pair<int, int> pi;
typedef pair<ll,ll> pll; 
typedef pair<int,pi> trp ;
typedef vector<pi> vpi;
typedef vector<pll> vpll ;
// int ab  (int  x ) { return (x>0?x:-x); }

const int N = 5005; 
int dp[N][N]; 
int main(){
	int n ; 
	cin >> n ; 
	string s; 
	cin >> s ; 
	int ans=0;	
	for(int i = 0 ; i < n ; i++ ){
		for(int j = i+1 ; j < n ; j++ ){
			if( i && s[i]==s[j] && j-dp[i-1][j-1]>i)dp[i][j] = 1 + dp[i-1][j-1];
			if( !i && s[i]==s[j]) dp[i][j]=1;
			ans = max( ans , dp[i][j] ); 
		}
	}
	cout << ans << endl; 
}


Measured memory_bytes: 96768
import java.util.*;


class Main {
        public static int dp[];
        public static int MM = 1000001;
        public static void main(String args[]) {
                Scanner sc = new Scanner(System.in);
                dp = new int[MM];
                for (int i = 0; i < MM; i++) {
                        dp[i] = -1;
                }
                while (true) {
                        int N = sc.nextInt();
                        if (N == 0) {
                                break;
                        }
                        System.out.println(recursion(N));
                }
        }
        public static int recursion(int in) {
                if (in == 1) {
                        return 0;
                }
                if (in < MM) {
                        if (dp[in] != -1) {
                                return dp[in];
                        } else {
                                if (in % 2 == 1) {
                                        return dp[in] = recursion(in * 3 + 1) + 1;
                                } else {
                                        return dp[in] = recursion(in / 2) + 1;
                                }
                        }
                } else {
                        if (in % 2 == 1) {
                                return recursion(in * 3 + 1) + 1;
                        } else {
                                return recursion(in / 2) + 1;
                        }
                }
        }
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int mod = 1e9+7;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<60;

int main(){
    cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    string s;
    cin>>s;
    cout << s.substr(0,3) << endl;
    return 0;
}

Measured memory_bytes: 3640
/*
[arc064] F - Rotated Palindromes
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define ALL(c) (c).begin(), (c).end()

const int MAX_D = 1400;
const int MOD = 1e9 + 7;

class gf {
public:
    int n;
    gf() : n(0) {}
    gf(int n) : n(n < 0 ? n % MOD + MOD : n % MOD) {}
    gf operator+(gf x) { return gf((n + x.n) % MOD); }
    gf operator-(gf x) { return gf((n - x.n + MOD) % MOD); }
    gf operator*(gf x) { return gf((1LL * n * x.n) % MOD); }
    gf& operator+=(gf x) { return *this = (*this + x); }
    gf& operator-=(gf x) { return *this = (*this - x); }
    gf& operator*=(gf x) { return *this = (*this * x); }
};

int N, K;
gf dp[MAX_D];

vector<int> divisors(int n) {
    vector<int> ret;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) {
                ret.push_back(n / i);
            }
        }
    }
    return ret;
}

ll mod_pow(ll a, ll n, ll m) {
    ll ret = 1;
    for (; n > 0; n >>= 1) {
        if (n & 1) {
            (ret *= a) %= m;
        }
        (a *= a) %= m;
    }
    return ret;
}

ll solve() {
    auto divs = divisors(N);
    int D = divs.size();
    sort(divs.begin(), divs.end());

    for (int i = 0; i < D; i++) {
        dp[i] = mod_pow(K, (divs[i] + 1) / 2, MOD);
        for (int j = 0; j < i; j++) {
            if (divs[i] % divs[j] == 0) {
                dp[i] -= dp[j];
            }
        }
    }

    gf ans = 0;
    for (int i = 0; i < D; i++) {
        if (divs[i] % 2) {
            ans += dp[i] * divs[i];
        } else {
            ans += dp[i] * (divs[i] / 2);
        }
    }

    return ans.n;
}

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

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 256
"use strict";
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var n = o.a();
  var s = o.a(1);
  if(n&1)return "No";
  var m = n/2;
  if(s.slice(0,m) === s.slice(m,n))return "Yes";
  return "No";
}

Measured memory_bytes: 21956
package main

import (
	"fmt"
)

func main() {

	var n, taro, hanako int

	fmt.Scan(&n)

	for i := 0; i < n; i++ {

		var a, b string
		fmt.Scan(&a, &b)

		if a > b {
			taro += 3
		} else if a < b {
			hanako += 3
		} else {
			taro++
			hanako++
		}

	}
	fmt.Println(taro, hanako)

}



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

int main()
{
  
    int arr[4];
    for(int i=0;i<3;i++)
        cin>>arr[i];
    swap(arr[0],arr[1]);
    swap(arr[0],arr[2]);
    for(int i=0;i<3;i++)
        cout<<arr[i]<<" ";

    cout<<endl;



}



Measured memory_bytes: 256
using System;
using System.Linq;

public class Program
{
	public static void Main()
	{
		int[] HW = Console.ReadLine().Split().Select(int.Parse).ToArray();
		int H = HW[0];
		int count = 0;
		for (int i = 0; i < H; i++)
		{
			var line = Console.ReadLine().ToCharArray();
			count += line.Count(ch => ch == '#');
		}
		Console.WriteLine(count == HW.Sum() - 1 ? "Possible" : "Impossible");
	}
}

Measured memory_bytes: 3032
N = int(input())
ans = []
for i in range(1,N):
    for j in range(i+1,N+1):
        ans.append([i,j])
if N % 2 == 1:
    i = 0
    while i < len(ans):
        if ans[i][0] + ans[i][1] == N:
            ans.pop(i)
        else:
            i += 1
    M = len(ans)
    print(M)
    for i in range(M):
        print(str(ans[i][0])+' '+str(ans[i][1]))
else:
    i = 0
    while i < len(ans):
        if ans[i][0] + ans[i][1] == N+1:
            ans.pop(i)
        else:
            i += 1
    M = len(ans)
    print(M)
    for i in range(M):
        print(str(ans[i][0])+' '+str(ans[i][1]))


Measured memory_bytes: 43632
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
//#include "C:\code\all.h"
#define rep(i,n) for(i = 0; i < n; i++)
using namespace std;


int main(){
  int i,j,k;
  int sx,tx,sy,ty;
  cin>>sx >> sy>>tx>>ty;

  string ans = "";
  int tempx = sx, tempy= sy;
  while(tempx < tx){
    cout << 'R'; tempx++;
  }
  while(tempy < ty){
    cout << 'U'; tempy++;
  }
  cout << 'R'; tempx++;
  while(tempy >= sy){
    cout << 'D'; tempy--;
  }
  while(tempx > sx){
    cout << 'L'; tempx--;
  }
  cout << 'U'; tempy++;

  while(tempy < ty){
    cout << 'U'; tempy++;
  }
  while(tempx < tx){
    cout << 'R'; tempx++;
  }

  cout << 'U'; tempy++;
  while(tempx >= sx){
    cout << 'L'; tempx--;
  }
  while(tempy > sy){
    cout << 'D'; tempy--;
  }
  cout << 'R'; tempx++;

}




Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>

using namespace std;
const double PI = (acos(-1));
const long long MOD = pow(10, 9) + 7;
long long kaizyou(int N);
long long POW(int J);

bool judge(int dt, int dx, int dy);

int main()
{
    int P,Q,R;
    cin >> P >> Q >> R;

    int s[3];
    s[0] = P + Q;
    s[1] = P + R;
    s[2] = Q + R;

    int mini = s[0];
    for(int i=1; i<3; i++)
    {
        if(mini > s[i])
        {
            mini = s[i];
        }
    }

    cout << mini;
    
}


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

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;

int main() {
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    if (e - a <= k) {
        cout << "Yay!" << endl;
    } else {
        cout << ":(" << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> pi;
typedef pair<int,int> vi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(vi c, vi d){
	return c.S < d.S;
}

int main() {
	ll N, ans=0;
	cin >> N;
	int m[N+1];
	REP(i, 0, N+1) cin >> m[i];
	
	int s;
	REP(i, 0, N){
		cin >> s;
		ans += (s > m[i]?m[i]:s);
		s = (s > m[i]?s-m[i]:0);
		ans += (s > m[i+1]?m[i+1]:s);
		m[i+1] = (s > m[i+1]?0:m[i+1]-s);
	}
	cout << ans;

}


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

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

  auto ok = [&](auto k) {
    auto l = 0, m = 0, r = 0;
    for(auto i = N - 1; 0 <= i; --i) {
      if(S[i] == 'J') if(l < m) ++l;
      if(S[i] == 'O') if(m < r) ++m;
      if(S[i] == 'I') {
        if(r < k)      ++r;
        else if(l < m) ++l;
      }
    }
    return l == k;
  };

  auto l = 0, h = N;
  while(l + 1 < h) {
    auto m = (l + h) / 2;
    if(ok(m)) l = m;
    else      h = m;
  }
  cout << l << endl;
}

Measured memory_bytes: 3880
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}


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

  return 0 ;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int H, W, K; cin >> H >> W >> K;
    vector<vector<char>> c(H, vector<char>(W));
    int ans = 0;
    rep(i, H)rep(j, W) cin >> c[i][j];
    for(int tate = 0; tate < 1 << H; tate++){
        for(int yoko = 0; yoko < 1 << W; yoko++){
            vector<vector<char>> tmp = c;
            for(int i = 0; i < H; i++){
                if(tate & 1 << i){
                    for(int k = 0; k < W; k++) tmp[i][k] = ':';
                }
                for(int j = 0; j < W; j++){
                    if(yoko & 1 << j){
                        for(int l = 0; l < H; l++) tmp[l][j] = ':';
                    }
                }
            }
            int cnt = 0;
            rep(i, H)rep(j, W) if(tmp[i][j] == '#') cnt++;
            if(cnt == K) ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
N, M = map(int, input().split())
A = list(map(int, input().split()))

C = [None,2,5,5,4,5,6,3,7,6]
#使ったマッチの本数
dp = [-1 for _ in range(N+7)]
dp[0] = 0

for i in range(N+1):
  for j in A:
    if C[j] <= i:
      dp[i] = max(dp[i-C[j]]*10 + j, dp[i])

print(dp[N])

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

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

int mod = 1000000007;
int64_t large = 9223372036854775807;
#define PI 3.14159265359

int main()
{
    int A, B, H, M;
    cin >> A >> B >> H >> M;

    double longg = 6 * M;
    double shortt = 30 * H + 0.5 * M;
    double kakudo = abs(longg - shortt);
    kakudo = min(kakudo, 360 - kakudo);
    kakudo = kakudo * (PI / 180);
    cout << fixed << setprecision(15) << sqrt(A * A + B * B - 2 * A * B * cos(kakudo));
}

Measured memory_bytes: 4224
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String args[]) throws IOException{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String data[] = reader.readLine().split(" ");
		int a= Integer.parseInt(data[0]);
		int b= Integer.parseInt(data[1]);
		int c= Integer.parseInt(data[2]);
			
		int ans=0;
		for(int i=a; i<=b; i++){
			if(c%i==0)
				ans++;
		}
		System.out.println(Integer.toString(ans));
	}
}

Measured memory_bytes: 17040
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <bitset>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;
int simple_case[] = {2, 5, 63, 70, 140, 210, 280, 350, 420, 490};

int main(int argc, char const *argv[]) {
  ll N, S=0;
  std::cin >> N;
  if(N<10){
    for(int i=0;i<N;i++){
      std::cout << simple_case[i] << (i==N-1?"":" ");
    }
    std::cout <<'\n';
    return 0;
  }
  std::vector<int> next;
  for(int i=1;i<15001;i++) next.push_back(i*2);
  for(int i=1;i<10001;i++) if(i%2!=0) next.push_back(i*3);
  sort(next.begin(), next.end());
  for(int i=0;i<N;i++) S+=next[i];
  switch(S%6){
    case 2: next[4] = 30000;
            break;
    case 3: next[5] = 30000;
            break;
    case 5: next[5] = 29998;
            break;
  }
  //S=0;
  for(int i=0;i<N;i++) {
    std::cout << next[i] << (i==N-1?"":" ");
    //S+=next[i];
  }
  //std::cout << S%6 << '\n';
  std::cout << '\n';
  return 0;
}


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

#define watch(x) cout << (#x) << " is " << (x) << endl
#define fr(i,n) for(int i=0; i<n; i++)
#define rep(i, st, en) for(int i=st; i<=en; i++)
#define repn(i, st, en) for(int i=st; i>=en; i--)
#define sq(a) (a*a)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll mod = 1e9+7;

ll gcdll(ll a, ll b){
    if(!b) return a;
    return gcdll(b, a%b);
}

void seive(int n){
    vector<bool> is_prime(n+1, true);
    is_prime[0] = is_prime[1] = false;

    for(int i=2; i*i<=n; i++){
        if(is_prime[i]){
            for(int j=i*i; j<=n; j+=i){
                is_prime[j] = false;
            }
        }
    }
}

vector<int> constructZFunc(string s){
    int n = s.size();
    vector<int> z(n);
    int l, r;
    l = r = 0;
    z[0] = 0;
    rep(i, 1, n-1){
        z[i] = 0;
        if(i<=r){
            z[i] = min(r-i+1, z[i-l]);  /// initialization, req. for linear time approach.
        }
        while(i+z[i] < n && s[z[i]] == s[i+z[i]])
            ++z[i];
        if(i+z[i]-1 > r){
            r = i+z[i]-1;
            l = i;
        }
    }
    return z;
}

void solve(){
    ll n;
    cin>>n;
    pll a[n];
    fr(i, n) {
        cin>>a[i].first;
        a[i].second = i;
    }

    sort(a, a+n, greater<pll>());

    ll res = 0ll;
    ll st = 0, en = n-1, pos;

    map<pii, ll> mp;    /// ans
    mp[{0, n}] = a[0].first*(llabs(a[0].second - 0));   /// placing in the start
    mp[{-1, n-1}] = a[0].first*(llabs(a[0].second - n + 1));    /// placing in the last

    rep(i, 1, n-1){
        map<pii, ll> tmp;   /// temp map

        for(auto it: mp){
            /// there are 2 choices to place new element for this pair
            st = it.first.first + 1;
            en = it.first.second - 1;


            if(st + n - 1 - en != i) continue;


            tmp[{st, en + 1}] = max(tmp[{st, en + 1}], it.second + a[i].first*(llabs(a[i].second - st)));
            tmp[{st - 1, en}] = max(tmp[{st - 1, en}], it.second + a[i].first*(llabs(a[i].second - en)));
        }

        mp = tmp;
        /*
        for(auto it: tmp){
            mp[it.first] = max(it.second, mp[it.first]);
        }
        */
    }

    ll ans = 0;

    for(auto it: mp){
        ans = max(ans, it.second);
    }

    cout<<ans;

}

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

    ll t = 1;
    //  cin>>t;
    while(t--){
        solve();
    }

    return 0;
}



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

int main(){
    int N; ll C;
    cin >> N >> C;
    vector<ll> x(N+1,0), v(N+1,0);
    for(int i=1; i<=N; i++) cin >> x[i] >> v[i];

    vector<ll> calc(N+1,0), cala(N+1,0);
    for(int i=1; i<=N; i++){
        calc[i] = calc[i-1] + v[i] - (x[i] - x[i-1]);
    }
    cala[N] = v[N] - (C - x[N]);
    for(int i=N-1; i>=1; i--){
        cala[i] = cala[i+1] + v[i] - (x[i+1] - x[i]);
    }

    vector<ll> calcM(N+1), calaM(N+1);
    for(int i=1; i<=N; i++) calcM[i] = max(calcM[i-1], calc[i]);
    calaM[N] = max((ll)0, cala[N]);
    for(int i=N-1; i>=1; i--) calaM[i] = max(calaM[i+1], cala[i]);

    ll ans = 0;
    for(int i=1; i<=N; i++){
        ans = max(ans, calc[i]);
        ans = max(ans, cala[i]);
    }

    for(int i=1; i<N; i++){
        ans = max(ans, calc[i] - x[i] + calaM[i+1]);
    }
    for(int i=N; i>1; i--){
        ans = max(ans, cala[i] - (C - x[i]) + calcM[i-1]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 4992