akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <stack>
#include <stdio.h>

using namespace std;

int main(void)
{
  string str;
  int x = 0,y = 0;
  stack <int> data;

  while(cin >> str){
    if(str[0] == '\n'){
      break;
    }
    if(str[0] == '+'){
      x = data.top();
      data.pop();
      y = data.top();
      data.pop();
      data.push(x + y);
    }
    else if(str[0] == '-'){
      x = data.top();
      data.pop();
      y = data.top();
      data.pop();
      data.push(y - x);
    }
    else if(str[0] == '*'){
      x = data.top();
      data.pop();
      y = data.top();
      data.pop();
      data.push(x * y);
    }
    else{
      data.push(atoi(str.c_str()));
    }
  }

  cout << data.top() << endl;
  
  return 0;
}



Measured memory_bytes: 3160
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	int y,m,d,p;
	char s[20];
	scanf("%d/%d/%d",&y,&m,&d);
	sprintf(s,"%04d%02d%02d",y,m,d);
	if(strcmp(s,"20190501")>=0)puts("TBD");
	else puts("Heisei");
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#define ll long long

using namespace std;


int main(void){
    ll n;
    cin >> n;
    ll ans;
    if(n%2==0)
        ans = n/2;
    else if(n%2!=0)
        ans = n/2+1;
    cout << ans << endl;
   return 0;
}


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

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


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<queue>
#include<string>
#include<map>
#include<set>
#include<string>
#include<sstream>
#include<vector>
#include<stack>
#include<ctime>
#include<vector>
#define Accel ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define LL long long
#define Re(a,b) memset(a,b,sizeof(a))
#define scanf scanf_s
using namespace std;
const int N = 1e9 + 1;
const int M = 0;

int n, a;
int main(){
	cin >> n;
	int ans = N;
	for (int i = 0; i < n; i++){
		cin >> a;
		int t = 0;
		while (a % 2 == 0){
			t++;
			a /= 2;
		}
		ans = min(t, ans);
	}
	cout << ans << endl;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
int myctoi(char C) {return C - 48;}
char myitoc(int N) {return '0' + N;}

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

  int ans = 0;
  for (int i = 1; i <= N; i++)
  {
    int n = i;
    int s = 0;
    while (n > 0)
    {
      n /= 10;
      s++;
    }
    if (s % 2 == 1) ans++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

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

		String S = sc.next();

		for(int i = 0;i<19;i++){
			if(i != 5 && i != 13){
				System.out.print(S.charAt(i));
			} else {
				System.out.print(" ");
			}
		}
	}
}



Measured memory_bytes: 21588
#include <stdio.h>
int main(){
    int X, Y;
    
    scanf("%d %d",&X,&Y);
    if(Y%2==1){
      printf("No");
    }else if(2*X<=Y && Y<=4*X){
      printf("Yes");
    }else{
      printf("No");
    }
return 0;
}


Measured memory_bytes: 1712
# coding: utf-8
# ?????????????????¨????????????
class Dice(object):
	def __init__(self):
		# ???????????????????????°
		# ????????¶???
		self.x = [2, 5]
		self.y = [3, 4]
		self.z = [1, 6]
		SN = {'S': 0, 'N': 1}
		WE = {'W': 0, 'E': 1}
		pass

	def rotate(self, _dir):
		def rot(_k, _r):
			return list(reversed(_r)), _k

		if _dir=='N':
			self.x, self.z = rot(self.x, self.z)
		elif _dir=='S':
			self.z, self.x = rot(self.z, self.x)
		elif _dir=='E':
			self.z, self.y = rot(self.z, self.y)
		elif _dir=='W':
			self.y, self.z = rot(self.y, self.z)
		else:
			pass

	def top(self):
		return self.z[0]


if __name__=="__main__":
	dice = Dice()
	val = list(map(int, input().split()))
	dr = input()
	for d in dr:
		dice.rotate(d)
	print(val[dice.top()-1])

Measured memory_bytes: 7800
#include<iostream>
using namespace std;
int main()
{
    string a,b;
    cin >> a;

    for(int i=0;i<a.size();i=i+2){
    if(a.at(i) == 'L'){
        b="No";
    }
    }

    for(int i=1;i<(a.size()-1);i=i+2){
    if(a.at(i) == 'R'){
        b="No";
    }
    }
    if(b != "No"){
        b="Yes";
    }
    cout << b <<endl;
    
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n,m;
  cin>>n>>m;
  vi a(n+1);
  a[0]=m;
  bool ans=true;
  rep(i,n){
    int in,out;
    cin>>in>>out;
    a[i+1]=a[i]+in-out;
    if(a[i+1]<0)ans=false;
  }
  sort(all(a));
  if(ans)cout<<a[n]<<endl;
  else cout<<0<<endl;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
#define rep(i,start,lim) for(lld i=start;i<lim;i++)
#define repd(i,start,lim) for(lld i=start;i>=lim;i--)
#define scan(x) scanf("%lld",&x)
#define print(x) printf("%lld ",x)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define br printf("\n")
#define sz(a) lld((a).size())
#define YES printf("Yes\n")
#define NO printf("No\n")
#define all(c) (c).begin(),(c).end()
using namespace std;
#define INF         1011111111
#define LLINF       1000111000111000111LL
#define EPS         (double)1e-10
#define MOD         1000000007
#define PI          3.14159265358979323
using namespace std;
typedef long double ldb;
typedef long long lld;
lld powm(lld base,lld exp,lld mod=MOD) {lld ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
typedef vector<lld> vlld;
typedef pair<lld,lld> plld;
typedef map<lld,lld> mlld;
typedef set<lld> slld;
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl '\n'
#define N 1000005
#define fre freopen("1.in","r",stdin); freopen("1.out","w",stdout);
lld p[N],pr[N];
int main()
{
  sync;
  rep(i,2,N) if(pr[i]==0) for(lld j=i*i;j<N;j+=i) pr[j]=1;
  pr[1]=1;
  rep(i,1,N) if(pr[i]==0 and pr[(i+1)/2]==0) p[i]=1;
  rep(i,1,N) p[i]+=p[i-1];
  lld q,l,r;
  cin>>q;
  while(q--) {
    cin>>l>>r;
    cout<<(p[r]-p[l-1])<<endl;
  }  
  return 0;
}

Measured memory_bytes: 16256
#include <set>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
    int M;
    cin >> M;
    for (int i=0; i<M; ++i) {
        string S;
        cin >> S;
        typedef set<string> set_t;
        set_t all;
        all.insert(S);
        for (int j=1; j<S.size(); ++j) {
            string L;
            for (int k=0; k<j; ++k){
                L += S[k];
            }
            string R;
            for (int k=j; k<S.size(); ++k){
                R += S[k];
            }
            string L2=L, R2=R;
            reverse(L2.begin(),L2.end());
            reverse(R2.begin(),R2.end());
            all.insert(L+R2);
            all.insert(L2+R);
            all.insert(L2+R2);
            all.insert(R+L);
            all.insert(R+L2);
            all.insert(R2+L2);
            all.insert(R2+L);
        }
        cout << all.size() << endl;
    }
}

Measured memory_bytes: 3148
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
typedef long long ll;
typedef pair<int,int> P;
#define F first
#define S second
const double PI=acos(-1);
//fixed<<setprecision(11)<<

int main(){
  int n;
  cin>>n;
  vector<int> L(n);
  rep(i,n) cin>>L[i];

  sort(L.begin(),L.end());
  int sum=0;
  rep(i,n-1) sum+=L[i];

  if(L[n-1]<sum) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
return 0;
}

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

int main(){
    int n,k;
    cin>>n>>k;
    int arr[n];
    for(int i = 0; i < n; i++)cin>>arr[i];
    int dp[k+1];
    for(int i = 0; i <= k; i++){
        dp[i] = 0;
        for(int j = 0; j < n; j++){
            // if(arr[j]<=i && !dp[i-arr[j]]){
            //     dp[i] = 1;
            // }
            if(arr[j]<=i){
                dp[i] |= 1-dp[i-arr[j]];
            }
        }
    }
    if(dp[k] == 1)
        cout<<"First";
    else
        cout<<"Second";
}

Measured memory_bytes: 640
#include<cstdio>
using namespace std;

int main(){
    int n, m;
    scanf("%d %d", &n, &m);

    int a;
    for(int i=0; i<m; i++){
        scanf("%d", &a);
        n -= a;
        if(n<0){
            n = -1;
            break;
        }
    }
    printf("%d\n", n);
    return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int a, b, c; cin >> a >> b >> c;
    int jud = b*10 + c;

    if(jud %4 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
}
    

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

#define N 1000
#define M 500

#define MAX(A,B) ((A) < (B) ? (B) : (A))

static int n;
static int m;
static int d[M][2];

int compare(const void *a, const void *b) {
  if (*(const int*)a < *(const int*)b)
    return -1;
  if (*(const int*)b < *(const int*)a)
    return 1;
  return 0;
}

static void read(void) {
  int i, sp;
  
  scanf("%d%d", &n, &m);
  for (i = 0; i < m; ++i) {
    scanf("%d%d", &d[i][0], &d[i][1]);
  }
  qsort(d, m, sizeof(int) * 2, compare);
  
  sp = 0;
  for (i = 1; i < m; ++i) {
    if (d[i][0] <= d[sp][1]) {
      d[sp][1] = MAX(d[sp][1], d[i][1]);
    } else {
      ++sp;
      d[sp][0] = d[i][0];
      d[sp][1] = d[i][1];
    }
  }
  m = sp + 1;
}

static int eval(void) {
  int pos, rval;
  int i;
  
  pos = 0;
  rval = 0;
  for (i = 0; i < m; ++i) {
    rval += d[i][1] - pos;
    rval += (d[i][1] - d[i][0]) * 2;
    pos = d[i][1];
  }
  rval += n - pos + 1;
  
  return rval;
}

int main(void) {
  read();
  printf("%d\n", eval());

  return EXIT_SUCCESS;
}

Measured memory_bytes: 648
#pragma GCC optimize(2)
#include <iostream>
#include <cstdio>
using namespace std;

long long n,m,k,ans;

int main()
{
	scanf("%lld%lld",&n,&m);
	k=(m-2*n)/4,ans=min(n,m/2);
	if(k<=0) { printf("%lld\n",ans); return 0; }
	n+=k,m-=2*k;
	ans=max(ans,min(n,m/2));
	printf("%lld\n",ans);
	return 0;
}

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

int main(){
  int a[3];
  int k;
  cin >> a[0] >> a[1] >> a[2];
  cin >> k;
  sort(a,a+3);
  for(int i = 0 ; i < k ; i++){
    a[2] *= 2;
  }
  cout << a[0] + a[1] + a[2] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

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




Measured memory_bytes: 3616
N, Ma, Mb=map(int,input().strip().split(' '))
inf=10**8
a=[]
b=[]
c=[]
for i in range(N):
    at,bt,ct=map(int,input().strip().split(' '))
    a.append(at)
    b.append(bt)
    c.append(ct)
suma=sum(a)
sumb=sum(b)
dp=[[[inf]*(sumb+1) for i in range(suma+1)]for j in range(N+1)]
dp[0][0][0]=0
for i in range(N):
    for j in range(suma+1):
        for k in range(sumb+1):
            if a[i]<=j and b[i]<=k:
                dp[i+1][j][k]=min(dp[i][j][k],dp[i][j-a[i]][k-b[i]]+c[i])
            else:
                dp[i+1][j][k]=dp[i][j][k]
            
m=min(suma//Ma,sumb//Mb)
ans=-1
for i in range(1,m):
    #if dp[N][i*Ma][i*Mb]!=inf and dp[N][i*Ma][i*Mb]!=0:
    if dp[N][i*Ma][i*Mb]!=inf:
        if ans==-1:
            ans=dp[N][i*Ma][i*Mb]
        else:
            ans=min(ans,dp[N][i*Ma][i*Mb])
        #break
print(ans)

Measured memory_bytes: 25140
//ナイーブで間に合わなかったので、queueを使って、変化があった選手についてだけ翌日見ることにした。
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A[][] = new int[N][N-1];
		for(int i=0;i<N;i++) {
			for(int j=0;j<N-1;j++) {
				A[i][j]=sc.nextInt()-1;
			}
		}
		sc.close();
		int cnt[] = new int[N]; //各選手の次の対戦相手を表すポインタがどこにあるか
		int p[] = new int[N]; //各選手の次の対戦相手
		for(int i=0;i<N;i++) {
			p[i] = A[i][0];
		}
		
		Queue<Integer> q = new ArrayDeque<>();
		Queue<Integer> q_check = new ArrayDeque<>();
		Set<Integer> set = new HashSet<>();
		
		//日にち
		int day = 0;

		for(;day<1000000;day++) {
			if(day==0) {
				for(int j=0;j<N;j++) {
					if(p[p[j]]==j) {
						//マッチング成功
						q_check.offer(j);
					}
				}
			}
			else {
				while(!q.isEmpty()) {
					int now = q.poll();
					if(p[now]==-1)continue;
					if(p[p[now]]==now) {
						//マッチング成功 //二重で追加しないように、含んでいない場合だけ、追加する。
						if(!set.contains(now)) {
							q_check.offer(now);
							set.add(now);
						}
						if(!set.contains(p[now])) { 
							q_check.offer(p[now]);
							set.add(p[now]);
						};
					}
				}
			}

			boolean isStop = true;
			while(!q_check.isEmpty()) {
				int now = q_check.poll();
				cnt[now]++;
				if(cnt[now]!=N-1) p[now]=A[now][cnt[now]];
				else p[now]=-1;
				q.add(now);

				isStop = false;//一回でも入れば、進んでいる
				}
			set.clear();
			if(isStop)break;
		}
		
		for(int i=0;i<N;i++) {
			if(cnt[i]!=N-1) {
				System.out.println(-1);
				return;
			}
		}
		System.out.println(day);
	}
}


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

int main()
{
    ll n, m;
    cin >> n >> m;
    vector<ll> H(n + 1);

    rep(i, m)
    {
        int a, b;
        cin >> a >> b;
        H[a]++;
        H[b]++;
    }

    rep(i, n + 1)
    {
        if (H[i] % 2 == 1)
        {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;
}

Measured memory_bytes: 4012
#include<bits/stdc++.h>
using namespace std;
bool u[100001];
vector<int> g[100001];
vector<int> path[2];
void dfs(int t,int cnt){
    for(int i=0;i<g[t].size();i++){
        if(u[g[t][i]])
            continue;
        u[g[t][i]]=1;
        path[cnt].push_back(g[t][i]);
        dfs(g[t][i],cnt);
        return;
    }
}
int main(){
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    srand(n);
    unsigned int o=rand();
    o%=n;
    o++;
    path[0].push_back(g[o][0]);
    path[1].push_back(o);
    u[o]=1,u[g[o][0]]=1;
    dfs(g[o][0],0);
    dfs(o,1);
    cout<<path[0].size()+path[1].size()<<endl;
    for(int i=path[0].size()-1;i>=0;i--)
        cout<<path[0][i]<<" ";
    for(int i=0;i<path[1].size();i++)
        cout<<path[1][i]<<" ";
    return 0;
}

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

  int N;
  cin >> N;
  vector<int> buttons(N);
  for(int i=0;i<N;i++){
    cin >> buttons.at(i);
  }
  
  vector<int> flags(N);
  int on=1;
  int count=0;
  while(true){
	on = buttons.at(on-1);
    count++;
    
    if(on==2){
      cout << count << endl;
      break;
    }
    
    if(flags.at(on-1)){
      cout << -1 << endl;
      break;
    }
    else
      flags.at(on-1)=1;
  }
}


Measured memory_bytes: 1152
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <cmath>
#include <string>
#include <set>
#include <map>
#define SIZE 200005

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

int A[SIZE];
int cost[SIZE];
int n,X;

ull solve(int k)
{
	ull ret=(ll) k*(ll) X;
	for(int i=n-1;i>=0;i--)
	{
		int c=n-i-1;
		ret+=(ll) cost[c/k]*(ll) A[i];
	}
	return ret;
}
int main()
{
	scanf("%d %d",&n,&X);
	for(int i=0;i<n;i++) scanf("%d",&A[i]);
	cost[0]=5;
	for(int i=1;i<=n;i++) cost[i]=2*i+3;
	int l=1,r=n;
	while(r-l>5)
	{
		int d=(l+r)/2;
		if(solve(d)<solve(d+1)) r=d+1;
		else l=d;
	}
	ull ret=solve(l);
	for(int i=l;i<r;i++) ret=min(ret,solve(i));
	printf("%llu\n",ret+(ll) n*(ll) X);
	return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

#include <cstdio>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int A[100000];
int ans[100000];
int bet[100000];

int main()
{
	int N;
	ll sum = 0;
	ll a0;

	cin >> N;
	rep(i, N) {
		cin >> A[i];
		sum += A[i];
	}

	a0 = sum;
	rep(i, N / 2) {
		a0 -= 2 * A[2 * i + 1];
	}

	ans[0] = (int)a0;
	repc(i, 1, N - 1) {
		ans[i] = 2 * A[i - 1] - ans[i - 1];
	}

	cout << ans[0];
	repc(i, 1, N - 1) cout << ' ' << ans[i];
	cout << endl;

	return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define print(A,n) for(ll i=0;i<n;++i)cout<<A[i]<<' ';cout<<endl;
#define take(A,n) for(ll i=0;i<n;++i)cin>>A[i];
ll mulmod(ll a,ll b,ll c) 
{ 
    if (b==0) 
        return 0; 
    ll s = mulmod(a, b/2, c); 
    if (b%2==1) 
        return (a%c+2*(s%c)) % c; 
 
    else
        return (2*(s%c)) % c; 
} 
 
  
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);}
int main()
{ll int tc;
//t=1;
tc=1;
 
while(tc--)
{string s,t,u;ll int a,i,b;
cin>>s;
for(i=0;i<s.size();i++)
cout<<"x";
   
}
 
    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()
r = list()
g = list()
b = list()
for i in range(N):
  if(S[i] == 'R'):
    r.append(i)
  elif(S[i] == 'G'):
    g.append(i)
  else:
    b.append(i)
ans = len(r) * len(g) * len(b)
for i in range(1, N//2 +1):
  j = 0
  while(j + 2*i < N):
    A = [S[j], S[j+i], S[j+i+i]]
    if ('R' in A) and ('G' in A) and ('B' in A):
      ans -= 1
    j += 1
print(ans)

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

const int maxN=4010;
const int Mod=1e9+7;

int n,m,K,L;
int F[maxN][maxN];

void Plus(int &x,int y);
int main(){
    scanf("%d%d%d",&n,&m,&K);--m;L=(n+m)/(K-1);
    F[0][0]=1;int Ans=0;
    for (int i=1;i<=L;i++)
        for (int j=0;j<=min(i*(K-1),n);j++){
            for (int k=0;k<=K-1&&k<=j;k++)
                Plus(F[i][j],F[i-1][j-k]);
            if (j%(K-1)==n%(K-1)&&(K-1)*i-j<=m&&((K-1)*i-j)%(K-1)==m%(K-1)) Plus(Ans,F[i][j]-F[i-1][j]);//,cout<<i<<" "<<j<<endl;
        }
    printf("%d\n",Ans);return 0;
}
void Plus(int &x,int y){
    x+=y;
    if (x>=Mod) x-=Mod;
    if (x<0) x+=Mod;
    return;
}

Measured memory_bytes: 61056
def main():
    x = int(input())
    ans = 1
    for i in range(2, int(x**0.5)+1):
        n = 2
        while i**n <= x:
            n += 1
        if ans < i**(n-1):
            ans = i**(n-1)
    print(ans)
    

if __name__ == "__main__":
    main()

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

void show(int H, int W){
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++)
            cout << "#";
        cout << endl;
    }
    cout << endl;
}

int main(){
    int H, W;
    while(cin >> H >> W, H|W)
        show(H, W);
    return 0;
}



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

int main(){
    int n;
    while(cin >> n){
        int p = 1;
        bool f = false;
        while(n){
            if(n & 1){ if(f) cout << " "; cout << p; f = true; }
            p *= 2; n >>= 1;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

ll eval(ll N, string &S) {
	ll ret=0;
	for (int i=0; i<N; i++)
		if((S[i]-'0')%2==0)
			ret+=i+1;
	return ret;
}

ll eval2(ll N, string &S) {
	ll ret=0;
	for (int i=0; i<N; i++)
		if((S[i]-'0')%5==0)
			ret+=i+1;
	return ret;
}

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	ll N,P; cin>>N>>P;
	string S; cin>>S;

	if(P==2) {
		cout<<eval(N,S)<<"\n";
		return 0;
	}

	if(P==5) {
		cout<<eval2(N,S)<<"\n";
		return 0;
	}
	map<int,ll> rem;
	ll cur=0, mul=1, ret=0;
	for (int i=N-1; i>=0; i--)
		cur=cur+mul*(S[i]-'0'), cur%=P, ret+=rem[cur]++, mul=(mul*10)%P;
	ret+=rem[0];
	cout<<ret<<"\n";
	return 0;
}

Measured memory_bytes: 1044
#include <bits/stdc++.h>
#include <set>
#include <numeric>
#define rep(i,n) for (int i=0; i < (n); ++i)
#define all(a) a.begin(), a.end()
using ll = long long;
using namespace std;
 
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }


// const double PI = acos(-1);
// int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
// int a[12][12];



void solve() {
  int x; cin >> x;
  if (x==3 || x==5 || x==7 ) cout << "YES" << endl;
  else cout << "NO" << endl;
}

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


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
char a[100010],b[100010];
int n;
void f()
{
	int i;
	for(i=2;i<=n-2;i++)
	{
		if(a[i]=='o')
		{
			if(b[i]=='S')
			b[i+1]=b[i-1];
			else
			{
				if(b[i-1]=='S')
				b[i+1]='W';
				else
				b[i+1]='S';
			}
		}
		if(a[i]=='x')
		{
			if(b[i]=='S')
			{
				if(b[i-1]=='S')
				b[i+1]='W';
				else
				b[i+1]='S';
			}
			else
			b[i+1]=b[i-1];
		}
	}
}
int ff()
{
	int m,k;
	m=0,k=0;
	if(a[n]=='o')
	{
		if(b[n]=='S')
		{
			if(b[n-1]==b[1])
			m=1;
			else
			m=0;
		}
		else
		{
			if(b[n-1]==b[1])
			m=0;
			else
			m=1;
		}
	}
	if(a[n]=='x')
	{
		if(b[n]=='S')
		{
			if(b[n-1]==b[1])
			m=0;
			else
			m=1;
		}
		else
		{
			if(b[n-1]==b[1])
			m=1;
			else
			m=0;
		}
	}
	if(a[n-1]=='o')
	{
		if(b[n-1]=='S')
		{
			if(b[n-2]==b[n])
			k=1;
			else
			k=0;
		}
		else
		{
			if(b[n-2]==b[n])
			k=0;
			else
			k=1;
		}
	}
	if(a[n-1]=='x')
	{
		if(b[n-1]=='S')
		{
			if(b[n-2]==b[n])
			k=0;
			else
			k=1;
		}
		else
		{
			if(b[n-2]==b[n])
			k=1;
			else
			k=0;
		}
	}
	if(m==1&&k==1)
	return 1;
	else
	return 0;
}
int main(void)
{
	int i,j,k;
	scanf("%d",&n);
		getchar();
		for(i=1;i<=n;i++)
		scanf("%c",&a[i]);
		k=0;
		for(i=1;i<=4;i++)
		{
			if(k==1)
			break;
			if(i==1&&k==0)
			{
				b[1]='S',b[2]='S';
				if(a[1]=='o')
				b[n]='S';
				else
				b[n]='W';
				f();
				if(ff()==1)
				{
					for(i=1;i<=n;i++)
					printf("%c",b[i]);printf("\n");
					k=1;
				}
			}
			else if(k==0&&i==2)
			{
				b[1]='S',b[2]='W';
				if(a[1]=='o')
				b[n]='W';
				else
				b[n]='S';
				f();
				if(ff()==1)
				{
					for(i=1;i<=n;i++)
					printf("%c",b[i]);
					printf("\n");
					k=1;
				}
			}
			else if(k==0&&i==3)
			{
				b[1]='W',b[2]='W';
				if(a[1]=='o')
				b[n]='S';
				else
				b[n]='W';
				f();
				if(ff()==1)
				{
					for(i=1;i<=n;i++)
					printf("%c",b[i]);
					printf("\n");
					k=1;
				}
			}
			else if(k==0&&i==4)
			{
				b[1]='W',b[2]='S';
				if(a[1]=='o')
				b[n]='W';
				else
				b[n]='S';
				f();
				if(ff()==1)
				{
					for(i=1;i<=n;i++)
					printf("%c",b[i]);
					printf("\n");
					k=1;
				};
			}
		}
		if(k==0)
		printf("-1\n");
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

int main(){
    int N;
    string S, T;
    cin >> N >> S >> T;
    for(int i=0; i<N; i++){
        cout << S[i] << T[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
ww = str(input())

a = 0
b = 0
c = 0
d = 0
e = 0
f = 0
g = 0
h = 0
i = 0
j = 0
k = 0
l = 0
m = 0
n = 0
o = 0
p = 0
q = 0
r = 0
s = 0
t = 0
u = 0
v = 0
w = 0
x = 0
y = 0
z = 0

for ii in range(len(ww)):
    if ww[ii] == "a":
        a +=1
    if ww[ii] == "b":
        b+=1
    if ww[ii] == "c":
        c +=1
    if ww[ii] == "d":
        d +=1
    if ww[ii] == "e":
        e+=1
    if ww[ii] == "f":
        f +=1
    if ww[ii] == "g":
        g +=1
    if ww[ii] == "h":
        h +=1
    if ww[ii] == "i":
        i +=1
    if ww[ii] == "j":
        j +=1
    if ww[ii] == "k":
        k +=1
    if ww[ii] == "l":
        l +=1
    if ww[ii] == "m":
        m +=1
    if ww[ii] == "n":
        n +=1
    if ww[ii] == "o":
        o +=1
    if ww[ii] == "p":
        p +=1
    if ww[ii] == "q":
        q +=1
    if ww[ii] == "r":
        r +=1
    if ww[ii] == "s":
        s +=1
    if ww[ii] == "t":
        t +=1
    if ww[ii] == "u":
        u +=1
    if ww[ii] == "v":
        v +=1
    if ww[ii] == "w":
        w +=1
    if ww[ii] == "x":
        x +=1
    if ww[ii] == "y":
        y +=1
    if ww[ii] == "z":
        z +=1

if a%2==0 and b%2==0 and c%2==0 and d%2==0 and e%2==0 and f%2==0 and g%2==0 and h%2==0 and i%2==0 and j%2==0 and k%2==0 and l%2==0 and m%2==0 and n%2==0 and o%2==0 and p%2==0 and q%2==0 and r%2==0 and s%2==0 and t%2==0 and u%2==0 and v%2==0 and w%2==0 and x%2==0 and y%2==0 and z%2==0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9140
// https://atcoder.jp/contests/abc131/tasks/abc131_a
#include <bits/stdc++.h>
using namespace std;

int main(void){
  string s;
  cin >> s;
  string ans = "Good";
  for (int i = 0; i < 3; i++){
    if (s[i] == s[i+1]){
      ans = "Bad";
    break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<string.h>
int main() {
	int i, j, H, W, h, w,b[100][100],flg;
	char board[100][101];
	while (fscanf(stdin, "%d%d", &H, &W),(H || W)) {
		memset(board, '\0', sizeof(board));
		memset(b, 0, sizeof(b));
		h = w = flg = 0;
		
		for (i = 0; i < H; i++)
			fscanf(stdin, "%s", board[i]);
		while (board[h][w] != '.') {
			if (flg==1) break;
			b[h][w] = 1;
			if (board[h][w] == '>') {
				w++;
				if (b[h][w] == 1) flg = 1;
			}
			else if (board[h][w] == '^') {
				h--;
				if (b[h][w] == 1) flg = 1;
			}
			else if (board[h][w] == '<') {
				w--;
				if (b[h][w] == 1) flg = 1;
			}
			else if (board[h][w] == 'v') {
				h++;
				if (b[h][w] == 1) flg = 1;
			}
		}
		if (flg) fprintf(stdout, "LOOP\n");
		else  fprintf(stdout, "%d %d\n", w, h);
	}
	return 0;
}

Measured memory_bytes: 672
#include <stdio.h>
int main(void){
    int n,ans=0 ;
    scanf ("%d",&n) ;
    for (int i=1; i<=n; i++) {
        if (i*i<=n) {
            ans=i*i ;
        } else {
            break ;
        }
    }
    printf ("%d\n",ans) ;
    return 0 ;
}

Measured memory_bytes: 128
/*
  Contest 091
  A - Two Coins
  Rakesh Kumar --> 21/09/2020
 */

#include <bits/stdc++.h>

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

    int a = 0, b = 0, c = 0;
    std::cin >> a >> b >> c;
    std::cout << ((a + b >= c) ? "Yes" : "No") << std::endl;

    return 0;
}


Measured memory_bytes: 3644
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;


const long long int mod = 1000000007;
const long long int INF = 1e18;


long long  int N,M,K,A[200050],sum=0,res=0;

int main()
{
    cout << fixed << setprecision(18);
    
    cin>>N;
    cout<<N*N*N<<endl;
    
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
alice = 0
bob = 0
turn = 0
for i in range(n):
    if turn % 2 == 0:
        alice += a[i]
        turn += 1
    else:
        bob += a[i]
        turn += 1
print(alice - bob)

Measured memory_bytes: 38256
N,K = map(int,input().split())
A = list(map(int,input().split()))
import heapq
a = list(map(lambda x: x*(-1), A))  # 各要素を-1倍

heapq.heapify(a)
for i in range(K):
  num = heapq.heappop(a)*(-1)
  heapq.heappush(a, -1*(int(num/2)))
  #print(num,a)
  if num == 0:
    break
print(-sum(a))
  

Measured memory_bytes: 20096
import java.io.PrintWriter
import java.util.*
import java.math.*
import java.lang.*

val pw = PrintWriter(System.out)
val MOD: Long = (1e+9 + 7).toLong()

fun main(args: Array<String>) {
    val (n, m) = readListOfInt() 
    println((n-1) * (m-1))
    pw.flush()
}

/****** Declared Functions and Data Structures ******/
// IO
fun read() = readLine()!!
fun readInt() = read().toInt()
fun readLong() = read().toLong()
fun readDouble() = read().toDouble()
fun readListOfString() = read().split(" ")
fun readListOfInt() = readListOfString().map { it.toInt() }
fun readListOfLong() = readListOfString().map { it.toLong() }
fun readListOfDouble() = readListOfString().map { it.toDouble() }

fun Double.format(digits: Int) = String.format("%.${digits}f", this)
fun Float.format(digits: Int) = String.format("%.${digits}f", this)

fun print(value: Any) { pw.print(value) }
fun println(value : Any) { pw.println(value) }

fun<T> permutations(src: List<T>): List<List<T>> {
    if(src.size == 1) return listOf(src)
    val perms = mutableListOf<List<T>>()
    val insertElement = src[0]
    permutations(src.drop(1)).forEach { perm ->
        for(i in 0..perm.size) {
            val newPerm = perm.toMutableList()
            newPerm.add(i, insertElement)
            perms.add(newPerm.toList())
        }
    }
    return perms
}

// return nCr, if you want nCr, please access v[n][r]
fun combinations(n: Long): List<List<Long>> {
    val v = (0..n).map { (0..n).map{0L}.toMutableList() }.toMutableList()
    for(i in 0 until v.size) {
        v[i][0] = 1L
        v[i][i] = 1L
    }
    for(i in 0 until v.size) {
        for(j in 1 until i) {
            v[i][j] = (v[i-1][j-1] + v[i-1][j] % MOD)
        }
    }
    return v.map { it.toList() }.toList()
}

// should be a >= b
fun gcd(a: Long, b: Long): Long = 
    if(b == 0L) a else gcd(b, a % b)

// shoud be a >= b
fun lcm(a: Long, b: Long): Long = 
    a / gcd(a, b) * b

fun sumDigits(num_: Long): Long {
    var num = num_
    var rtn: Long = 0
    while(num != 0.toLong()) {
        val tmp = num % 10
        rtn += tmp
        num /= 10
    }
    return rtn
}

fun isDecimal(v: Double): Boolean = ((v - Math.floor(v)) != 0.0)

// Data Structures
class Stack<T>(private var st: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = st.isEmpty()
    fun top(): T = st.last()
    fun push(e: T) { st.add(e) }
    fun pop() { st = st.dropLast(1).toMutableList() }
}

class Queue<T>(private var que: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = que.isEmpty()
    fun top(): T = que.first()
    fun push(e: T) { que.add(e) }
    fun pop() { que = que.drop(1).toMutableList() }
}


Measured memory_bytes: 37684
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 262144
vector<int> vertexs[2000] = {};
long long required[2000] = {};
long long failed = 0;
pair<long long, long long> solve(long long now, long long back) {
	if (vertexs[now].size() == 1 && vertexs[now][0] == back) {
		return make_pair(required[now], 0);
	}
	long long backing = 0;
	long long geko[5001] = {};
	geko[0] = 1;
	for (int i = 0;i < vertexs[now].size();++i) {
		if (vertexs[now][i] != back) {
			pair<long long, long long> nya = solve(vertexs[now][i], now);
			backing += nya.first + nya.second;
			for (int j = 5000;j >= 0;--j) {
				if (geko[j] == 1) {
					geko[j] = 0;
					if (j + nya.first <= 5000) {
						geko[nya.first + j] = 1;
					}
					if (j + nya.second <= 5000) {
						geko[nya.second + j] = 1;
					}
				}
			}
		}
	}
	for (int j = required[now];j >= 0;--j) {
		if (geko[j] == true) {
			return make_pair(required[now], backing - j);
		}
	}
	failed = true;
	return make_pair(LONG_INF, LONG_INF);
}
int main() {
  iostream::sync_with_stdio(false);
  cin.tie(0);
	int n;
	cin >> n;
	for (int i = 2;i <= n;++i) {
		int a;
		cin >> a;
		vertexs[i].push_back(a);
		vertexs[a].push_back(i);
	}
	for (int i = 1;i <= n;++i) {
		cin >> required[i];
	}
	solve(1, -1);
	if (failed == 0) {
		cout << "POSSIBLE" << endl;
	}
	else {
		cout << "IMPOSSIBLE" << endl;
	}
	return 0;
}

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

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

  bool ans = false;
  
  for(int i=0; i<=N; i++){
    for(int j=0; j<=M; j++){
      if(i + j > (N + M) / 2){
        break;
      }
      else{
        int black = 0;
        black += i * (M - j);
        black += j * (N - i);
        if(black == K){
          ans = true;
          break;
        }
      }
    }
    if(ans){
      break;
    }
  }
  
  if(ans){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
from sys import stdin

def main():

    input = stdin.readline

    H,W = map(int,input().split())

    ans = H * W

    if H == 1 or W == 1:
        print("1")
    elif ans % 2 == 0:
        print(ans//2)
    else:
        print(ans//2+1)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        _n: usize,
        a: i64,
        b: i64,
    }
    if (a - b).abs() % 2 == 0 {
        println!("{}", "Alice");
    } else {
        println!("{}", "Borys");
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
   char a;
   cin >> a;
   if(isupper(a)){
       cout << "A" << endl;
   }else{
       cout << "a" << endl;
   }
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<algorithm>
using namespace std;
int mod=10007;
int dp[1010][8];
char str[1010];
int main(){
	int a;
	scanf("%d",&a);
	scanf("%s",str);
	for(int i=0;i<8;i++){
		if((i&1)==0)continue;
		if(str[0]=='O'&&(i&2)==0)continue;
		if(str[0]=='I'&&(i&4)==0)continue;
		dp[0][i]=1;
	}
	for(int i=1;i<a;i++){
		for(int j=0;j<8;j++){
			if(str[i]=='J'&&(j&1)==0)continue;
			if(str[i]=='O'&&(j&2)==0)continue;
			if(str[i]=='I'&&(j&4)==0)continue;
			for(int k=0;k<8;k++){
				if(j&k)dp[i][j]=(dp[i][j]+dp[i-1][k])%mod;
			}
		}
	}
	int ret=0;
	for(int i=0;i<8;i++)ret=(ret+dp[a-1][i])%mod;
	printf("%d\n",ret);
}

Measured memory_bytes: 1056
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int suffix[200100],a[200010];
map<int,int> mp;
int main() {
    int n;
    cin>>n;
    for(int i=1;i<=n ;i++){
        cin>>a[i];
    }
    ll ans=0;
    for(int i=n;i>=1;i--){
        if(mp.find(a[i]+i)!=mp.end())
            ans+=mp[a[i]+i];
        mp[i-a[i]]++;
    }
    cout<<ans;
}


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

#define REP(i,a,b) for(int i=int(a);i<int(b);i++)

using namespace std;

typedef long long int lli;

int main () {
    int N;
    lli K;
    cin >> N >> K;
    map<int, lli> m;
    REP (i, 0, N) {
        int a, b;
        cin >> a >> b;
        m[a] += b;
    }
    lli cnt = 0;
    for (auto it : m) {
        cnt += it.second;
        if (cnt >= K) {
            cout << it.first << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 4224
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(llint i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define Pll pair<llint,llint>
#define keta(a)  fixed << setprecision(a)
const ll mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
const ll INF = 1000000000;



int main() {
	int x;
	cin >> x;
	cout << 1 - x << endl;
    return 0;
}

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

int main(){
    ll n, k;    cin >> n >> k;
    vector<ll> a(n);
    for(int i=0; i<n; i++)  cin >> a.at(i);
    k--; n--;
    ll ans = n/k + min(1LL, n%k);
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>

using namespace std;
typedef unsigned long ul;
typedef pair<ul, ul> P;

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

int main(){
  char s[100],t[100];
  cin >> s >> t;

  sort(s,s+strlen(s));
  sort(t,t + strlen(t), greater<char>());

  if (strcmp(s,t)<0) cout << "Yes" << endl;
  else cout << "No" << endl;


  return 0;

}


Measured memory_bytes: 256
def re(x,y,a,rect):
    if a==1:
        for i in range(1,len(rect)):
            rect[i][1:x+1]=[0]*x
    elif a==2:
        for i in range(1,len(rect)):
            rect[i]=rect[i][:x+1]+[0]*(len(rect[i])-x-1)
    elif a==3:
        for i in range(1,y+1):
            rect[i]=[0]*(len(rect[y]))
    else:
        for i in range(y+1,len(rect)):
            rect[i]=[0]*(len(rect[y]))
        
    return rect



w,h,n=map(int,input().split())
rect=[[0]*(w+1)]
for i in range(h):
    rect+=[[0]+[1]*w]

for j in range(n):
    x,y,a=map(int,input().split())
    rect=re(x,y,a,rect)


cnt=0
for k in range(h+1):
    cnt+=sum(rect[k])
print(cnt)



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

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 10000000000
using namespace std;
typedef long long ll;

int main(){
  ll N;  cin >> N;
  ll M = MAX+1;
  rep(i, 1, sqrt(N)+1){
    if(N%i==0)  M = min(M, N/i);
  }
  ll a = to_string(M).length();
  ll b = to_string(N/M).length();
  cout << max(a, b) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vs = vector<string>;
#define rep(i,n)  for(ll i = 0; i < (n); ++i)
#define red(i,n)  for(ll i = (n)-1; i >= 0; --i)
#define all(a)    begin(a),end(a)
#define pb(a)     push_back(a)
#define yn(a)     cout << ( (a)?"Yes\n":"No\n" )
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
ll INF = 1e9+7, LINF = 1e18;


int main()
{
    vs a={"SUN","MON","TUE","WED","THU","FRI","SAT"};
    reverse(all(a));
    string s;
    cin>>s;
    rep(i,7)if(s==a[i])cout<<i+1<<endl;
    
    return 0;
}


Measured memory_bytes: 256
q, p, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = min(a) + min(b)
for i in range(m):
    x, y, c = map(int, input().split())
    ans = min(ans, a[x - 1] + b[y - 1] - c)
print(ans)


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

int main() {
  int N;
  cin>>N;
  vector<int> a(N+2);
  for(int i=1;i<N+1;i++) cin>>a[i];
  vector<int> d(N+1);
  for(int i=0;i<N+1;i++) d[i]=abs(a[i+1]-a[i]);
  long sum=0;
  for(int i=0;i<N+1;i++) sum+=d[i];
  //for(int i=0;i<N+1;i++) cout<<d[i]<<endl;
  //cout<<sum<<endl;
  for(int i=1;i<N+1;i++){
    long si=sum;
    si -= d[i-1];
    si -= d[i];
    si +=abs(a[i+1]-a[i-1]);
    //cout<<d[i]<<d[i+1]<<abs(a[i+2]-a[i]);
    cout<<si<<endl;
  }

}


Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

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

	int Slen = S.length();

	if (S[0] != 'A'){
		cout << "WA" << endl;
		return 0;
	}

	int cnum = 0;

	for (int i = 1; i < Slen; ++i){
		if (i >= 2 && i <= Slen-2 && S[i] == 'C'){
			cnum++;
		}
		else if (S[i] < 'a' || S[i] > 'z'){
			cout << "WA" << endl;
			return 0;
		}
	}
	if (cnum == 1)
		cout << "AC" << endl;
	else
		cout << "WA" << endl;

	return 0;
}

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

void fnInput(vector<vector<char>>& rvvcColor, int& rnRemain)
{
  int nySiz, nxSiz;
  cin >> nySiz >> nxSiz >> rnRemain;
  rvvcColor.resize(nySiz);

  for (int ny = 0; ny < rvvcColor.size(); ny++)
  {
    rvvcColor[ny].resize(nxSiz);

    for (int nx = 0; nx < rvvcColor[ny].size(); nx++)
      cin >>  rvvcColor[ny][nx];
  }
}

void fnColoringRed(int nEach, vector<vector<char>>& rvvcColor)
{
  if (nEach < rvvcColor.size())
  {
    for (int nx = 0; nx < rvvcColor[nEach].size(); nx++)
      rvvcColor[nEach][nx] = ' ';
  }
  else
  {
    nEach -= rvvcColor.size();
    for (int ny = 0; ny < rvvcColor.size(); ny++)
      rvvcColor[ny][nEach] = ' ';
  }
}

int fnNumOfCase(const vector<vector<char>>& cnrvvcColor, int nRemain)
{
  int nNumOfCase = 0;
  int nSize = cnrvvcColor.size() + cnrvvcColor[0].size();

  for (int nCtl = 0; nCtl < ( 1 << nSize ) ; nCtl++)
  {
    vector<vector<char>> vvcColor(cnrvvcColor);

    for (int nEach = 0; nEach < nSize; nEach++)
      if (nCtl & ( 1 << nEach ))
        fnColoringRed(nEach, vvcColor);

    int nCntTrg = 0;

    for (int ny = 0; ny < vvcColor.size(); ny++)
      for (int nx = 0; nx < vvcColor[ny].size(); nx++)
        if (vvcColor[ny][nx] == '#') nCntTrg++;

    if (nCntTrg == nRemain) nNumOfCase++;
  }
  return nNumOfCase;
}
 
int main()
{
  vector<vector<char>> vvcColor;
  int nRemain;

  fnInput(vvcColor, nRemain);
  cout << fnNumOfCase(vvcColor, nRemain) << endl;

  return 0;
}

Measured memory_bytes: 3660
using System;

public class hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var ans = 0;
        for (int i = 0; i < n; i++)
        {
            var a = long.Parse(Console.ReadLine().Trim());
            if (IsPrime(2 * a + 1) )
            {
                ans++;
            }
        }
        Console.WriteLine(ans);
    }
    public static bool IsPrime(long n)
    {
        if (n < 2) return false;
        else if (n == 2) return true;
        else if (n % 2 == 0) return false; 
        double sqrtN = Math.Sqrt(n);
        for (int i = 3; i <= sqrtN; i += 2)
            if (n % i == 0) return false;
        return true;
    }
}

Measured memory_bytes: 9164