akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main{
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for(int i=0; i<n; i++){
            a[i] = sc.nextLong();
        }
        Arrays.sort(a);
        long side1 = 0;
        long side2 = 0;
        
        for(int i=n-1; i>0; i--){ //　i=0の時終了しないとa[i-1]を検証してしまう
            if(a[i] == a[i-1]){
                if(side1 == 0){
                    side1 = a[i];
                    i--;
                }else{
                    side2 = a[i];
                    break;
                }
            }
        }
        System.out.println(side1 * side2);
    }
}


Measured memory_bytes: 49692
#include <bits/stdc++.h>
using namespace std;
int main() {
	int X, A, B;
	cin >> X >> A >> B;
	if(A >= B){
		cout << "delicious" << endl;
	}
	else if(A + X >= B){
		cout << "safe" << endl;
	}
	else{
		cout << "dangerous" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
s = input()
q = int(input())
qs = [input().split() for i in range(q)]
n = False
left= right = ""
for operation in qs:
    if operation[0] == '1':
        n = not n
    if operation[0] == '2':
        t , f, c = operation
        f = int(f)
        if n:
            f = 1 if f != 1 else 2
        if f == 1:
            left=c+left
        elif f == 2:
            right+=c
s = left+s+right
print(s[::-1] if n else s)

Measured memory_bytes: 40648
import sys
readline = sys.stdin.readline

N,M,K = map(int,readline().split())

A = [0] + list(map(int,readline().split()))
B = [0] + list(map(int,readline().split()))

for i in range(1, len(A)):
  A[i] += A[i - 1]

for i in range(1, len(B)):
  B[i] += B[i - 1]
  
import bisect

ans = 0
for i in range(len(A)):
  rest = K - A[i]
  if rest < 0:
    continue
  if ans < i:
    ans = i
  b_read = bisect.bisect_right(B, rest)
  if ans < i + b_read - 1:
    ans = i + b_read - 1
    
print(ans)

Measured memory_bytes: 40860
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    int n,x;
    cin>>n>>x;
    int cur=0,ai;
    rep(i,n){
        cin>>ai;
        cur=__gcd(cur,abs(ai-x));
    }
    cout<<cur<<endl;
    return 0;
}

Measured memory_bytes: 256
//ITP 1_10_C

#include<iostream>
#include<cmath>

using namespace std;
int main(){
    while(1){
        int n;
        cin >> n;
        if(n==0) break;
        int sum = 0,s[n];
        for(int i=0; i<n; i++){
            cin >> s[i];
            sum += s[i];
        }
        double sd, k = 0.0;
        sd = double(sum) / double(n);
        
        for(int i=0; i<n; i++) 
            k +=(double(s[i])-sd)*(double(s[i])-sd);
            cout << sqrt( k / double(n)) << endl;
    }
    return 0;
}




Measured memory_bytes: 3280
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  if(s.at(2) == s.at(3)){
    if(s.at(4) == s.at(5)){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int solve(int n,int k,int m) {
	int i,s=0;
	if (n==0) { if (k==0) return 1; else return 0;}
	for (i=m;i<11-n;i++) s+=solve(n-1,k-i,i+1);
    return s;
}
int main() {
  int n,k;
  while(cin >> n >> k) {
	if (n==0 && k==0) break;  
    cout << solve(n,k,0) << endl;
  }
  return 0;
}

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

class Procon
{
    public Procon() { }
    static void Main(string[] agrs)
    {
        new Procon().Do();
    }

    Scanner cin;

    public void Do()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int K = cin.nextInt();
        int[] V = cin.arrayInt();

        int upper = Math.Min(N, K);
        int max = 0;
        for (int i = 0; i <= upper; i++)
        {
            for (int a = 0; a <= i; a++)
            {
                int b = i - a;
                var tmp = new int[i];
                Array.Copy(V, 0, tmp, 0, a);
                Array.Copy(V, V.Length - b, tmp, a, b);
                Array.Sort(tmp);
                int calc = 0;
                for (int j = 0; j < i; j++)
                {
                    if (tmp[j] < 0 && j < K - i)
                    {
                        continue;
                    }
                    calc += tmp[j];
                }
                if (max < calc)
                {
                    max = calc;
                }
            }
        }
        Console.WriteLine(max);
    }
}

class Scanner
{
    string[] s;
    int i;
    int max_i;

    public Scanner()
    {
        s = new string[0];
        max_i = 0;
        i = 0;
    }

    public string nextString()
    {
        if (i >= s.Length)
        {
            s = Console.ReadLine().Split(' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0)
            {
                return "";
            }
            return s[i++];
        }
        else
        {
            return s[i++];
        }
    }

    public int nextInt()
    {
        return int.Parse(nextString());
    }

    public long nextLong()
    {
        return long.Parse(nextString());
    }

    public double nextDouble()
    {
        return double.Parse(nextString());
    }

    public string[] arrayString()
    {
        return Console.ReadLine().Split(' ');
    }

    public int[] arrayInt()
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] array = new int[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = int.Parse(str[i]);
        }
        return array;
    }

    public long[] arrayLong()
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] array = new long[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = long.Parse(str[i]);
        }
        return array;
    }

    public double[] arrayDouble()
    {
        string[] str = Console.ReadLine().Split(' ');
        double[] array = new double[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = double.Parse(str[i]);
        }
        return array;
    }
}


Measured memory_bytes: 13268
#include<iostream>
#include <string>
#include <vector>
#include <cmath>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define ll = long long;
// #define P = pair<int,int>;

const int INF = 1001001001;

int a[12][12], c[12];

int main() {
  int n, m, x, ans = INF;
  bool ok = true;
  cin >> n >> m >> x;

  rep(i, n){
    cin >> c[i];
    rep(j, m){
      cin >> a[i][j];
    }
  }

  rep(s,1<<n) {
    int cost = 0;
    ok = true;
    rep(i,m){
      int und = 0;
      cost = 0;
      rep(j,n){
        if (s>>j & 1) {
          cost += c[j];
          und += a[j][i];
        }
      }
      if (und < x) {
        ok = false;
      }
    }
    if (ok) {
      ans = min(ans, cost);
    }
  }
  if (ans == INF) {
    cout << "-1" << endl;
  }else{
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3624
N, M = map(int, input().split())
s_list = []
c_list = []
isFirstZero = True
for i in range(M):
    s, c = map(int, input().split())
    s_list.append(s - 1)
    c_list.append(c)
    if s == 1:
        isFirstZero = False
l = [-1] * N
isNG = False
if M == 0 and N == 1:
    print(0)
else:
    for i in range(M):
        if s_list[i] == 0 and c_list[i] == 0 and not(N == 1 and c_list[0] == 0):
            isNG = True
            break
        if l[s_list[i]] == -1:
            l[s_list[i]] = c_list[i]
        else:
            if l[s_list[i]] != c_list[i]:
                isNG = True
                break
    if isFirstZero and not (len(l) == 1 and l[0] == 0):
        l[0] = 1
    elif l[0] == -1:
        isNG = True
    if isNG:
        print(-1)
    else:
        for i in range(N):
            if l[i] == -1:
                l[i] = 0
            print(l[i], end="")


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

void  base_num(ll data,ll base){
    if(data==0) return;
    ll next=abs(data)%abs(base);
    if(data<0) next=(abs(base)-next)%abs(base);
    base_num((data-next)/base,base);
    cout << next;
}


int main(){
    ll n,k;
    cin >> n >> k;
    ll a[n];
    for (ll i=0;i<n;i++)cin >> a[i];
    queue<ll> que;
    que.push(1);
    ll i=0,visited[n];
    fill(visited,visited+n,-1);
    bool flag=true;
    while(i<k){
        i++;
        ll c=que.front();
        if (visited[c-1]!=-1 and flag){
            k=(k-i)%(i-visited[c-1]);
            i=0;
            flag=false;
            que.pop();
            que.push(a[c-1]);
            continue;
        }
        visited[c-1]=i;
        que.pop();
        que.push(a[c-1]);
    }
    cout << que.front() << endl;
    return 0;
}
 
 

Measured memory_bytes: 6328
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

const ll mod=1e9+7;

int main(){
    string s;
    cin >> s;
    ll n=s.length();
    ll x,y;
    cin >> x >> y;
    vector<ll> pre1(2*n+1),pre2(2*n+1),cur1(2*n+1),cur2(2*n+1); //1は左右、2は上下
    ll pos=-1;
    ll cnt=0;
    rep(i,n){
        if(s[i]=='F') cnt++;
        else{
            pos=i+1;
            break;
        }
    }
    pre1[cnt+n]=1;
    pre2[n]=1;
    cnt=0;
    ll turn=1;
    for(ll i=pos;i<n;i++){
        if(pos==-1) break;
        if(s[i]=='F') cnt++;
        else{
            if(turn==0){
                for(ll j=0;j<=2*n;j++){
                    if(pre1[j]){
                        cur1[j-cnt]=1;
                        cur1[j+cnt]=1;
                    }
                }
                pre1=cur1;
                cur1=vector<ll>(2*n+1,0);
            }
            else{
                for(ll j=0;j<=2*n;j++){
                    if(pre2[j]){
                        cur2[j-cnt]=1;
                        cur2[j+cnt]=1;
                    }
                }
                pre2=cur2;
                cur2=vector<ll>(2*n+1,0);
            }
            cnt=0;
            turn=(turn+1)%2;
        }
    }
    if(cnt){
        if(turn==0){
            rep(j,2*n+1){
                if(pre1[j]){
                    cur1[j-cnt]=1;
                    cur1[j+cnt]=1;
                }
            }
            pre1=cur1;
        }
        else{
            rep(j,2*n+1){
                if(pre2[j]){
                    cur2[j-cnt]=1;
                    cur2[j+cnt]=1;
                }
            }
            pre2=cur2;
        }
    }
    if(pre1[n+x] && pre2[n+y]){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 4028
#include <iostream>
#include <vector>
using namespace std;
int EditNums(int n){
    if(n % 10 == 0){
        return n;
    }else{
        return (n / 10 + 1) * 10;
    }
}

int main(void){
    int nums[5];
    int Enums[5];
    int sum = 0;
    int ans = 10000;
    
    for(int i = 0;i < 5;i++){
        cin >> nums[i];
        Enums[i] = EditNums(nums[i]);
        sum += Enums[i];
    }
    
    for(int i = 0;i < 5;i++){
        ans = min(ans,sum - Enums[i] + nums[i]);
    }
    cout << ans << endl;
}




Measured memory_bytes: 256
h, w = map(int, input().split(" "))
s = []
for i in range(h):
    s.append(str(input()))
d = [(1, 0), (0, 1), (-1, 0), (0, -1)]
ss = ["" for i in range(h)]
for i in range(h):
    for j in range(w):
        f = False
        if s[i][j] == ".":
            f = True
            continue
        for dy, dx in d:
            if 0 <= i + dy < h and 0 <= j + dx < w:
                if s[i + dy][j + dx] == "#":
                    f = True
                    break
        if not f:
            break
    if not f:
        break

if f:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9220
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

struct edge{
	int to,cap,rev;
	edge(){}
	edge(int tt,int cc,int rr){
		to=tt;
		cap=cc;
		rev=rr;
	}
};

int n,m;
vector<edge> G[105];
int cnt[101];


void add_edge(int from,int to,int cap){
	G[from].push_back(edge(to,cap,G[to].size()));
	G[to].push_back(edge(from,0,G[from].size()-1));
}

vector<int> vec;
bool used[101];

int dfs(int v,int t,int f){
	if(v==t)return f;
	used[v]=true;
	for(int i=0;i<G[v].size();i++){
		edge &e=G[v][i];
		if(!used[e.to] && e.cap>0){
			int d=dfs(e.to,t,min(f,e.cap));
			if(d>0){
				e.cap-=d;
				G[e.to][e.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}

void solve(){
	for(int i=0;i<n;i++){
		G[i].clear();
	}
	memset(cnt,0,sizeof(cnt));
	for(int i=0;i<m;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		u--;
		v--;
		add_edge(u,v,1);
		cnt[u]++;
	}
	bool update=true;
	while(update){
		update=false;
		int p_min=0,p_max=0;
		for(int i=1;i<n;i++){
			if(cnt[p_min]>cnt[i]){
				p_min=i;
			}
			if(cnt[p_max]<cnt[i]){
				p_max=i;
			}
		}

		for(int i=0;i<n;i++){
			if(!update && cnt[p_min]+1<cnt[i]){
				memset(used,false,sizeof(used));
				int val=dfs(i,p_min,1);
				if(val==1){
					update=true;
					cnt[i]--;
					cnt[p_min]++;
				}
			}
		}
		for(int i=0;i<n;i++){
			if(!update && cnt[i]+1<cnt[p_max]){
				memset(used,false,sizeof(used));
				int val=dfs(p_max,i,1);
				if(val==1){
					update=true;
					cnt[p_max]--;
					cnt[i]++;
				}
			}
		}
		if(!update){
			printf("%d %d\n",cnt[p_min],cnt[p_max]);
			return;
		}
	}
}

int main(void){
	while(1){
		scanf("%d%d",&n,&m);
		if(n==0 && m==0)break;
		solve();
	}
	return 0;
} 


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

int main(void){
        char a[1000];
        int n;
        scanf("%s %d",&a,&n);

        for(int i=0;i*n<strlen(a);i++){
                printf("%c",a[i*n]);
        }
        printf("\n");
        return 0;
}

Measured memory_bytes: 128
#include <cmath>
#include <iostream>
#include <vector>

int main(int argc, char *argv[]) {
  int n, d;
  std::cin >> n >> d;
  std::vector<std::vector<int>> x(n, std::vector<int>(d));
  for (int j = 0; j < n; ++j)
    for (int i = 0; i < d; ++i)
      std::cin >> x.at(j).at(i);

  int cnt = 0;
  for (int i = 0; i < n; ++i)
    for (int j = i + 1; j < n; ++j) {
      int sum = 0;
      for (int k = 0; k < d; ++k) {
        int a = x.at(i).at(k);
        int b = x.at(j).at(k);
        sum += (a - b) * (a - b);
      }
      if ((int)sqrt(sum) == sqrt(sum))
        cnt++;
    }

  std::cout << cnt << std::endl;
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
#define testing 1
#define FOR(i,s,e) for(ll i = s; i <= (ll)e; ++i)
#define DEC(i,s,e) for(ll i = s; i >= (ll)e; --i)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << "\n"
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << "\n"
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<"\n"
#define dbv(v) cerr << #v << ":"; for (auto ite : v) cerr << ite << ' '; cerr <<"\n"
#define dbvp(v) cerr << #v << ":"; for (auto ite : v) cerr << "{"  << ite.f << ',' << ite.s << "} "; cerr << "\n"
#define dba(a,ss,ee) cerr << #a << ":"; FOR(ite,ss,ee) cerr << a[ite] << ' '; cerr << "\n"
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long 
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "LINE: " << __LINE__ << "\n";
typedef pair <int, int> pi;
typedef tuple<int,int,int> ti3;
string cts(char x) {string t(1,x); return t;}
ll rand(ll a, ll b) { return a + rng() % (b-a+1); }
const int MOD = 1e9 + 7;
const int inf = (int)1e9 + 500;
const long long oo = (ll)1e18 + 500;
template <typename T> void chmax(T& a, T b) { a = max(a, b); }
template <typename T> void chmin(T& a, T b) { a = min(a, b); }
#define MAXN (int)()
#if !testing
#define cerr if(0)cout
#endif
int n,m; 
int A[305];
vector<pi> V[305];
ll dp[305][305][305];
bool fail[305][305][305];
ll ans = 0;

ll dpdp(int r, int g, int b) {
	if(~dp[r][g][b]) return dp[r][g][b];
	int x = max({r,g,b});
	int z = min({r,g,b});
	int y = r+g+b-x-z;
	if(fail[x][y][z])return dp[r][g][b] = 0;
	if (x == n) return dp[r][g][b] = 1;
	ll &res = dp[r][g][b];
	res = 0;
	res += dpdp(x+1,g,b);
	res %= MOD;
	res += dpdp(r,x+1,b);
	res %= MOD;
	res += dpdp(r,g,x+1);
	res %= MOD;
	return res;
}

int32_t __attribute__((optimize("Ofast"), target("arch=sandybridge"))) main() 
{
	IAMSPEED
	cin >> n >> m;
	FOR(xx,1,m) {
		int a,b,c; cin >> a >> b >> c;
		FOR(i,0,b) {
			FOR(j,0,i) {
				int sum = 1;
				if(i>=a)++sum;
				if(j>=a)++sum;
				if(sum!=c)fail[b][i][j] = 1;
			}
		}
	}
	memset(dp,-1,sizeof dp);
	cout << dpdp(0,0,0);
}



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

using namespace std;

const int N = 105, K = 1e5 + 5, MOD = 1e9 + 7;
int n, p, dp[N][K], prefix[N][K], a[N];

inline int add(int a, int b){
	a += b;
	if(a >= MOD)a -= MOD;
	return a;
}

inline int sub(int a, int b){
	a -= b;
	if(a < 0)a += MOD;
	return a;
}

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

	cin>>n>>p;
	for(int i=1;i<=n;++i)cin>>a[i];

	for(int i=0;i<=n;++i)dp[i][0] = prefix[i][0] = 1;
	for(int j=0;j<=p;++j)prefix[0][j] = 1;

	for(int i=1;i<=n;++i)
		for(int j=1;j<=p;++j){
			// coefficient of x^j is prefix[i - 1][j - a[i] : j];

			int first = (j - a[i] - 1 >= 0)? prefix[i - 1][j - a[i] - 1] : 0;
			int last = prefix[i - 1][j];
			dp[i][j] = add(0, sub(last, first));
			prefix[i][j] = add(prefix[i][j - 1], dp[i][j]);
		}

	cout<<dp[n][p]<<"\n";
	return 0;
}


Measured memory_bytes: 82176
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = a; i < n; i++)
#define Repr(i, n, a) for (int i = n; i >= a; i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int l;
    cin >> l;
    vector<int> a(l);
    rep(i, l) cin >> a[i];
    vector<int> b(l);
    b[0] = a[0];
    Rep(i, 1, l) b[i] = b[i - 1] + a[i];
    vector<int> c(l);
    c[l - 1] = a[l - 1];
    repr(i, l - 2) c[i] = c[i + 1] + a[i];
    vector<int> x1(l + 1), x2(l + 1);
    x1[l] = 0;
    x2[0] = 0;
    vector<int> y1(l + 1), y2(l + 1);
    y1[l] = 0;
    y2[0] = 0;
    Rep(i, 1, l + 1)
    {
        if (a[i - 1] % 2 == 1)
        {
            x2[i] = min(x2[i - 1], y2[i - 1]);
            y2[i] = y2[i - 1] + 1;
        }
        else if (a[i - 1] == 0)
        {
            x2[i] = min(x2[i - 1], y2[i - 1]) + 1;
            y2[i] = y2[i - 1] + 2;
        }
        else
        {
            x2[i] = min(y2[i - 1], x2[i - 1] + 1);
            y2[i] = y2[i - 1];
        }
        x2[i] = min(x2[i], b[i - 1]);
        y2[i] = min(y2[i], b[i - 1]);
    }
    repr(i, l - 1)
    {
        if (a[i] % 2 == 1)
        {
            x1[i] = min(x1[i + 1], y1[i + 1]);
            y1[i] = y1[i + 1] + 1;
        }
        else if (a[i] == 0)
        {
            x1[i] = min(x1[i + 1], y1[i + 1]) + 1;
            y1[i] = y1[i + 1] + 2;
        }
        else
        {
            x1[i] = min(y1[i + 1], x1[i + 1] + 1);
            y1[i] = y1[i + 1];
        }
        x1[i] = min(x1[i], c[i]);
        y1[i] = min(y1[i], c[i]);
    }
    int ans = INF;
    rep(i, l + 1)
    {
        ans = min(min(ans, y1[i] + y2[i]), min(x1[i] + y2[i], x2[i] + y1[i]));
        //cout << x1[i] << " " << y2[i] << " : " << x2[i] << " " << y1[i] << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 11264
N, C = gets.chomp.split.map(&:to_i)
d = []
C.times do
    d << gets.chomp.split.map(&:to_i)
end
t = Array.new(3).map{Array.new(C,0)}
N.times do |i|
    gets.chomp.split.map(&:to_i).each_with_index do |v, j|
        t[(i+j)%3][v-1] += 1
    end
end

ans = 1000 * 500 * 500
(0..C-1).to_a.permutation(3) do |arry|
    tmp = 0
    0.upto(2) do |i|
        t[i].each_with_index do |v, j|
            tmp += d[j][arry[i]] * v
        end
    end
    ans = tmp if ans > tmp
end

puts ans


Measured memory_bytes: 2428
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = (1e9)+7;
void fastIO(){
  ios_base::sync_with_stdio(0); cin.tie(0);
}


int main(){
  fastIO();
  ll home;
  cin>>home;
  ll time = 1 , pos = 0;
  while(pos<home){
  	pos+=time;
  	time++;
  }
  cout<<min(time-1,home)<<endl;
}  


Measured memory_bytes: 256
#!/usr/bin/env python3
#ABC132 C

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
d = LI()
d.sort()
ans = d[n//2] - d[n//2 -1]
print(ans)


Measured memory_bytes: 52636
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
 
#define pb push_back
#define mk make_pair
#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define sf(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define pf(a) printf("%d\n",a);
#define pfl(a) printf("%lld\n",a);
#define TEST int test; cin >> test;while(test--)
#define ii pair<int,int>
#define iil pair<ll,ll>
#define loop(i,a,b) for(int i = a ; i < b ; i++)
#define INF 2147483647
 
 
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const double pi = acos(-1.0);
 
map<ll,ll>mp;
void solve()
{
    int n, a, b, c;
    cin >> n >> a >> b >> c;
    char c1[n+10], c2[n+10];
    for(int i = 0 ; i < n ; i++)
    {
       cin >> c1[i] >> c2[i];
       //cout << c1[i] << " " << c2[i] << endl;
    }
    vector<char> v;
 
    for(int i = 0 ; i < n ; i++)
    {
      if((c1[i] == 'A' && c2[i] == 'B')  or (c1[i] == 'B' && c2[i] == 'A'))
      {
         if(a == 0 && b == 0) {cout << "No" << endl; return;}
         else if( a > b) a--,b++ , v.pb('B');
         else if( b > a ) b--,a++, v.pb('A');
         else{
           if(c1[i+1] == 'A' or c2[i+1] == 'A') b--,a++, v.pb('A');
           else  a--,b++ , v.pb('B');
         }
      }
      else if((c1[i] == 'A' && c2[i] == 'C')  or (c1[i] == 'C' && c2[i] == 'A'))
      {
         if(a == 0 && c == 0) {cout << "No" << endl; return;}
         else if( a > c) a--,c++ , v.pb('C');
         else if( c > a ) c--,a++, v.pb('A');
         else{
           if(c1[i+1] == 'A' or c2[i+1] == 'A') c--,a++, v.pb('A');
           else  a--,c++ , v.pb('C');
         }
      }
      else if((c1[i] == 'B' && c2[i] == 'C')  or (c1[i] == 'C' && c2[i] == 'B'))
      {
         if(b == 0 && c == 0) {cout << "No" << endl; return;}
         else if( b > c) b--,c++ , v.pb('C');
         else if( c > b ) c--,b++, v.pb('B');
         else{
           if(c1[i+1] == 'B' or c2[i+1] == 'B') c--,b++, v.pb('B');
           else b--,c++ , v.pb('C');
         }
      }
    }
    cout << "Yes" << endl;
    int sz = v.size();
    for(int i = 0 ; i < sz ; i++)
    {
      cout << v[i] << endl;
    }
}
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //TEST
    solve();
    return 0;
}

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

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

using ll = long long;
using pii = pair<int, int>;
using Vi = vector<int>;

int main() {
  int a,b;
  cin >> a >> b;
  if(a>b){
    cout << a-1 << endl;
  }
  else{
    cout << a << endl;
  }
}      
       



Measured memory_bytes: 3564
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] x = line.split(" ");
		int a = Integer.parseInt(x[0]);
		int b = Integer.parseInt(x[1]);
		int c = Integer.parseInt(x[2]);
		if (a < b && b < c) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}

}

Measured memory_bytes: 25984
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
using namespace std;
typedef long long ll;
int main(){
  ll n = 0;
  cin >> n;
  string s;
  cin >> s;
  vector<ll> count(26);
  for(int i = 0;i < n;i++){
    count[s[i] - 'a']++;
  }
  //cout << count[0] << endl;
  ll res = 0;
  vector<ll> mae(26);
  for(int i = 0;i < 26;i++)mae[i] = 0;
  for(int i = 0;i < n;i++){
    ll now = 0;
      count[s[i] - 'a']--;
      mae[s[i] - 'a']++;
    for(int j = 0;j < 26;j++){
      if(mae[j] > 0 && count[j] > 0)now++;
    }  
    //cout << mae[0] << " " << count[0] << endl;
    res = max(res,now);
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define s second
#define f first
long long const mod = 1000000007; 
#define inf 1000000000000000000
inline ll add(ll a, ll b){ return ((a%mod)+(b%mod)+mod)%mod;}
inline ll mul(ll a, ll b){ return (((a%mod)*(b%mod))%mod+mod)%mod;}
inline ll sub(ll a, ll b){ return ((a%mod)-(b%mod)+mod)%mod;}

ll power(ll x,ll y,ll m) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2, m) % m; 
    p = (p * p) % m; 
    return (y%2 == 0)? p : (x * p) % m; 
}

ll modInv(ll x)
{
    return power(x,mod-2,mod)%mod;
}

ll dp[1000][10001];
ll func(ll h,ll i,ll n,ll a[],ll b[])
{
    if(h<=0)
        return 0;
    
    if(i==n)
        return inf;
        
    if(dp[i][h]!=-1)
        return dp[i][h];
    
    ll ans1=func(h-a[i],i,n,a,b);
    if(ans1!=inf)
        ans1=ans1+b[i];
    ll ans2=func(h,i+1,n,a,b);
    dp[i][h]=min(ans1,ans2);
    return min(ans1,ans2);
}

struct st
{
    ld x,h;
};
bool compare(st s1,st s2)
{
    return s1.x<s2.x;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    
    ll n,d,a;
    cin>>n>>d>>a;
    ll ans=0;
    st s[n];
    for(int i=0;i<n;i++)
        cin>>s[i].x>>s[i].h;
    sort(s,s+n,compare);
    
    ll j=0;
    ll dp[n+1]={0};
    ll sum=0;
    for(int i=0;i<n;)
    {
        //if(i-1>=0)
        sum=sum+dp[i];
        //cout<<i<<" sum "<<sum<<endl;
        ld z=s[i].h+sum;
        if(s[i].h+sum<=0)
        {
            i++;
            continue;
        }
        while(true && j<n)
        {
            if(s[j].x-s[i].x<=2*d)
                j++;
            else
                break;
        }
        //cout<<i<<" ij "<<j<<endl;
       
        ans=ans+ceil(z/a);
        dp[j]=dp[j]+a*ceil(z/a);
        dp[i]=dp[i]-a*ceil(z/a);
        sum=sum-a*ceil(z/a);
        //cout<<ans<<" "<<dp[i]<<" "<<dp[j]<<endl;
       // cout<<i<<" sum "<<sum<<endl;
        i++;
        
    }
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 8064
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <map>

#define ST_ARR_LEN(array) (sizeof(array)/sizeof(*array))

using namespace std;

using ll = long long;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;
typedef vector<int> IntVector;
typedef list<int> IntList;

typedef struct S{
  int a;
  int b;
} Object;

int main(){
  int N;
  cin >> N;
  int ans[N];
  for(int i=0;i<N;i++){
    ans[i] = 0;
  }
  int a;
  for(int i=0;i<N-1;i++){
    cin >> a;
    ans[a-1]++;
  }
  
  for(int i=0;i<N;i++){
    cout << ans[i] << endl;
  }
}

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

using namespace std;
# define MAX1 100
#define nn 101
#define ww 100000
typedef long long ll ;
ll  arr[MAX1][2];
ll  n,w;
ll  dp[nn][ww];
ll  func(ll ind,ll weight)
{
    if(weight==0||ind==n)
    return 0;
    if(dp[ind][weight]!=-1)
    return dp[ind][weight];
    if(weight<arr[ind][0])
   return  dp[ind][weight]=func(ind+1,weight);
    return dp[ind][weight]=max(func(ind+1 ,weight),func(ind+1 ,weight-arr[ind][0])+arr[ind][1]);
}
int main()
{
    cin>>n;
    cin>>w;
    
    for(int i=0;i<n;i++)
    {
        for (int j=0;j<2;j++)
        cin>>arr[i][j];
    }
    memset(dp,-1,sizeof dp);
     ll ans=func(0,w);
    cout<<ans<<endl;
    
    return 0;
}



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

#define MOD (int)(1e9+7)

int main()
{
	string S, T; cin >> S >> T;
	vector<pair<int, int>>S_ABcnt(S.size()+1),T_ABcnt(T.size()+1);
	int a = 0, b = 0;
	S_ABcnt[0] = make_pair(0, 0);
	T_ABcnt[0] = make_pair(0, 0);
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'A')a++;
		else b++;
		S_ABcnt[i+1] = make_pair(a, b);
	}
	a = 0, b = 0;
	for (int i = 0; i < T.size(); i++) {
		if (T[i] == 'A')a++;
		else b++;
		T_ABcnt[i+1] = make_pair(a, b);
	}

	int Q; cin >> Q;

	for (int i = 0; i < Q; i++) {
		int a, b, c, d; cin >> a >> b >> c >> d;
		
		pair<int, int>s_ABcnt, t_ABcnt;
		s_ABcnt = make_pair(S_ABcnt[b].first - S_ABcnt[a-1].first, S_ABcnt[b].second - S_ABcnt[a-1].second);
		t_ABcnt = make_pair(T_ABcnt[d].first - T_ABcnt[c-1].first, T_ABcnt[d].second - T_ABcnt[c-1].second);

		if ((s_ABcnt.first % 3 - s_ABcnt.second % 3 + 3)%3 == (t_ABcnt.first % 3 - t_ABcnt.second % 3 + 3)%3)cout << "YES" << endl;
		else cout << "NO" << endl;
	}

    return 0;
}



Measured memory_bytes: 2560
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Maybe

readInt = fst . fromJust . BS.readInt

getInt = readInt <$> BS.getLine

powerJoin :: Int -> Int -> Int -> [Int]
powerJoin b p n
  | b ^ p > n = []
  | otherwise = b ^ p : powerJoin (b + 1) p n

calc :: Int -> Int -> [Int]
calc k n
  | k > n = []
  | otherwise = powerJoin 2 k 1000 ++ calc (k + 1) n

main = do
  x <- getInt
  let ns = 1 : calc 2 9
  print $ last (takeWhile (\y -> y <= x) (sort (nub ns)))


Measured memory_bytes: 3796
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int> ;
using vi = vector<int> ;
using vll = vector<long long>;

int main(){
  string s; cin >> s;
  int n = s.size();
  if(n < 26){
    bool fin = false;
    string t;
    for(int i = 0; i < 26; i++){
      for(int j = 0; j < n; j++){
        if(s[j] == 'a' + i){break;}
        if(j == n-1){t.push_back('a' + i); fin = true;}
      }
      if(fin){break;}
    }
    cout << s+t << endl;
  }
  else{
    bool fin = false;
    string t;
    char c = s[n-1];
    vector<char> v(1, c);
    for(int i = n-2; i >= 0; i--){
      if((int)s[i] < (int)c){t = s.substr(0, i+1); fin = true; break;}
      else{v.push_back(s[i]); c = s[i];}
    }
    if(!fin){cout << -1 << endl;}
    else{
      auto itr = lower_bound(v.begin(), v.end(), t[t.size()-1]);
      t[t.size()-1] = *itr;
      cout << t << endl;
      }
  }
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var k int
	var s int
	fmt.Scanf("%d %d", &k, &s)

	var count int
	for x := 0; x <= k; x++ {
		for y := 0; y <= k; y++ {
			z := s - x - y
			if z <= k && z >= 0 {
				count++
			}
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 1832
s = input()

divides = ['dream', 'dreamer', 'erase', 'eraser']

s0 = s
while len(s0) > 0:
    is_divided = False
    for divide in divides:
        if len(s0) > 7 and s0[-len(divide):] == divide:
            s0 = s0[:-len(divide)]
            is_divided = True
            break
        elif s0 == divide:
            s0 = ''
            is_divided = True
            break
        
    if not is_divided:
        break

if len(s0) > 0:
    print('NO')
else:
    print('YES')

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

int main() {
  long long n;
  cin >> n;
  
  string ans = "";
  while(1){
    if(n == 0) break;
    int k = (n-1) % 26;
    char c = 'a' + k;
    n = (n-1) / 26;
    ans.push_back(c);
  }
  
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
}

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

int main(){
	string s;
	cin >> s;
	int n = s.size();
	vector<int> a(n,0),aq(n,0),c(n,0),cq(n,0);
	for(int i(1);i<n;++i){
		a[i] = a[i-1];
		aq[i] = aq[i-1];
		if(s[i-1] == 'A') a[i]++;
		if(s[i-1] == '?') aq[i]++;
	}
	for(int i(n-2);i >= 0; --i){
		c[i] = c[i+1];
		cq[i] = cq[i+1];
		if(s[i+1] == 'C') c[i]++;
		if(s[i+1] == '?') cq[i]++;
	}
	ll ans(0), num(pow(10,9)+7);
	vector<ll> pow3(n+10);
	rep(i,n+1){
		if(i == 0) pow3[i] = 1;
		else pow3[i] = 3 * pow3[i-1] % num;
	}
	for(int i(1);i < n-1; ++i){
		if(s[i] == 'B' | s[i] == '?'){
			ll ap = a[i] * pow3[aq[i]] % num;
			if(aq[i] >= 1) ap += (aq[i] * pow3[aq[i]-1]) % num;
			ll cp = c[i] * pow3[cq[i]] % num;
			if(cq[i] >= 1) cp += (cq[i] * pow3[cq[i]-1]) % num;
			ans += (ap * cp) % num;
			ans %= num;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2816
#include"bits/stdc++.h"
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9

typedef pair<ll,ll> P;

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


int main() {
	ll n, m;
	cin >> n >> m;
	vector<ll> a;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		a.push_back(x);
	}
	sort(a.begin(), a.end(), greater<int>());

	vector<P> p;
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		p.push_back(make_pair(x, y));
	}
	p.push_back(make_pair(0,0));
	sort(p.begin(), p.end(),pairCompare);

	ll ans = 0;
  ll mm = 0, nn = 0;
	for (int i = 0; i < n; i++) {
		
		if (p[mm].second > a[nn]) {
			if (p[mm].first > (n - i)) { ans += (p[mm].second)*(n - i); i = n; }
			else {
				ans += (p[mm].first)*(p[mm].second);
				i += p[mm].first - 1;
				mm++;
			}
		
		}
		else {
			ans += a[nn];
			nn++;
		}
      //cout<<ans<<endl;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4340
//https://atcoder.jp/contests/dp/tasks/dp_m
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}}star;
#define DEBUG if(0)
#endif
#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}
class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

LL as[1123456];
int N,K;
int a[1123];
constexpr int mod = 1e9+7;
inline LL sum(int l,int r){
    return (as[r]+mod-as[l])%mod;
}
int main(){
    cin>>N>>K;
    for(int i:range(N))cin>>a[i];
    vector<LL> dp(K+1);
    dp[0]=1;
    for(int i:range(N)){
        vector<LL> nxt(K+1);
        for(int k:range(K+1)){
            as[k+1]=as[k]+dp[k];
            nxt[k]=sum(max(0,k-a[i]),k+1);
        }

        swap(dp,nxt);
    }
    cout<<dp.back()<<endl;
    return 0;
}

Measured memory_bytes: 2672
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		int sum = Integer.MAX_VALUE;
		int maxAbs = 0;

		for (int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
			maxAbs = Math.max(maxAbs, Math.abs(a[i]));
		}

		int now = 0;
		for (int i = -maxAbs; i <= maxAbs; i++) {
			now = 0;
			for (int j = 0; j < N; j++) {
				now += Math.pow(i - a[j], 2);
			}
			sum = Math.min(sum, now);
		}

		System.out.println(sum);
	}
}


Measured memory_bytes: 21844
def f(A,B,C,M):
    X=C
    for i in range(M):
        X+=A[i]*B[i]
    return X

K=0
N,M,C=map(int,input().split())
B=list(map(int,input().split()))
for _ in range(N):
    A=list(map(int,input().split()))
    K+=f(A,B,C,M)>0
print(K)


Measured memory_bytes: 62196
#include <iostream>
#include <string>
#define SIZE 100002

using namespace std;
typedef long long int ll;

int main()
{
	int N, Q, A;
	ll K;
	int score[SIZE];
	cin >> N >> K >> Q;
	for (int i = 0; i < SIZE; i++)
	{
		score[i] = 0;
	}
	for (int i = 0; i < Q; i++)
	{
		cin >> A;
		score[A-1]++;
	}
	for (int i = 0; i < N; i++)
	{
		if (K - (ll)Q + (ll)score[i] > 0)
		{
			cout << "Yes" << endl;
		}
		else
		{
			cout << "No" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1024
package main

import "fmt"

func main() {
	s := [...] int{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51}
	var k int
	fmt.Scan(&k)
	fmt.Println(s[k-1])
}

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

int main(){
  int S, A, B;
  cin >> S;
  A = S % 100;
  B = (S - A)/100;
  if(1 <= A && A <= 12 && 1 <= B && B <= 12){
    cout << "AMBIGUOUS" << endl;
  }
  else if(1 <= A && A <= 12 && 0 <= B && B <= 99){
    cout << "YYMM" << endl;
  }
  else if(1 <= B && B <= 12 && 0 <= A && A <= 99){
    cout << "MMYY" << endl;
  }
  else{
    cout << "NA" << endl;
  }
}


Measured memory_bytes: 256
#include <cstdint>
#include <iostream>
#include <string>

using namespace std;

int32_t main()
{
  string N;
  cin >> N;
  if ((N[0] == '9') || (N[1] == '9')) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll n, m, wa[110000], a, b;
bool ac[110000];
int main() {
	cin >> n >> m;
	REP(i, m) {
		ll c;
		string s;
		cin >> c >> s;
		if (s == "WA")wa[c]++;
		else if (!ac[c]) {
			ac[c] = true;
			a++;
			b += wa[c];
		}
	}
	cout << a << " " << b << endl;
}


Measured memory_bytes: 1152
#-*- using:utf-8 -*-

alphabet = "abcdefghijklmnopqrstuvwxyz"

def alphabet_decimal(n):
    def convert(n):
        while n > 0:
            yield alphabet[(n - 1) % len(alphabet)]
            n = (n - 1) // len(alphabet)
    return ''.join(convert(n))[::-1]

if __name__ == '__main__':
    N = int(input())
    print(alphabet_decimal(N))

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

using namespace std;

int main(int argc, char *argv[]) {
	int a, b;
	cin >> a >> b;

	int target = stoi(to_string(a) + to_string(b));
	double target_sqrt = sqrt(target);
	double sub = target_sqrt - (static_cast<int>(target_sqrt));
	
	cout << ((sub > 0) ? "No" : "Yes") << endl;
	return 0;
}


Measured memory_bytes: 256
typedef long long ll;

#define shi5 100000+10
#define MOD 1000000007

#include <bits/stdc++.h>
using namespace std;
struct mystruct{
  long long v;
  mystruct * next;
};
int structcmp(const void *v1,const void *v2){return ((mystruct *)v1)->v - ((mystruct *)v2)->v;}
int intcmp(const void *v1,const void *v2){return *(int *)v1-*(int *)v2;}
long long minn(long long v1,long long v2){return v1<v2?v1:v2;}
long long maxx(long long v1,long long v2){return v1>v2?v1:v2;}

// a1 , x y -> abs(a1-y)
// a1 a2, x y -> max(a2-y,a2-a1)
// a1 a2 a3, x y -> max(a3-y,a2-a3,min(a1-a3,a2-a3))
// a1 a2 a3 a4, x y -> max(a4-y,a3-a4,min(a2-a4,a3-a4),min(a1-a4,a3-a4,y=a2 & arr=[a3,a4]))
//

map<pair<ll,int>,ll > yansrecord;

ll cards[2010]={0};
int n;

ll xturn(ll y,int offset);

ll yturn(ll x,int offset){
  if(yansrecord.count(make_pair(x,offset)))
    return yansrecord[make_pair(x,offset)];
  ll * arr = &cards[offset];
  int len = n - offset;
  ll ret = abs( x - arr[len -1]);
  for(int i=len-2;i>=0;i--){
    ll recv = yturn(arr[i],offset+i+1);
    ret= minn(ret,recv);
  }
  yansrecord[make_pair(x,offset)];
  return ret;
}

map<pair<ll,int>,ll > xansrecord;
ll xturn(ll y,int offset){
  if(xansrecord.count(make_pair(y,offset)))
    return yansrecord[make_pair(y,offset)];
  ll * arr = &cards[offset];
  ll len = n - offset;
  ll ret = abs( y - arr[len -1]);
  for(int i=len-2;i>=0;i--){
    ll recv = yturn(arr[i],offset+i+1);
    ret= maxx(ret,recv);
  }
  xansrecord[make_pair(y,offset)] = ret;
  return ret;
}

int main(){
  int x,y;
  cin>>n>>x>>y;
  int i;
  for(i=0;i<n;i++)
    cin>>cards[i];
  cout<<xturn(y,0)<<endl;
  return 0;
}


Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()
	k := nextInt()
	a := make([]int, n)

	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}

	//ans := (float64(n) - 1.0) / (float64(k) - 1.0)
	fmt.Println(kiriage(n-1, k-1))

}
func kiriage(a int, b int) int {
	return (a + b - 1) / b // a/bを切り上げ
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string l[]={"No","Yes"};
	int n;
	string str;
	cin>>n;
	cin>>str;
	cout<<l[count(str.begin(),str.end(),'R')>count(str.begin(),str.end(),'B')]<<endl; 
	return 0;	
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define MAXN 500010
#define LL long long


using namespace std;

char ss[MAXN],s[MAXN];
int n,sum[MAXN];

int main()
{
    int ans=inf;
	cin >> n;
	cin >> s+1;
	for (int i = 1;i <= n;i++)
        sum[i]=sum[i-1]+(s[i]=='.');

	sum[n+1]=sum[n];

	for (int i=0;i<=n;i++)
        ans=min(ans,i-sum[i]+sum[n+1]-sum[i+1]);

	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <cmath>
#include <string>

using namespace std;
int main(){
    string s,t;
    int n;
    cin >> n;
    cin >> s >> t;
    for (int i = 0; i < n; i++){
        cout << s[i] << flush;
        cout << t[i] << flush;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,x,y) for(int i=x,i##end=y;i<=i##end;++i)
#define _rep(i,x,y) for(int i=x,i##end=y;i>=i##end;--i)
#define ll long long 
#define N 1000005
typedef std::pair<int,int> pii;
int n,a[N],c[N],cpy[N],cnt,sum[N],up;
struct tree{
	void clear(){memset(c,0,sizeof(c));}
	inline void upd(int x,int v){for(;x<=up;x+=x&-x) c[x]+=v;}
	inline int qry(int x,int ret=0){for(;x;x-=x&-x) ret+=c[x]; return ret;}
} T;
bool check(int mid){
	T.clear();
	ll ret=0; up=0;
	rep(i,1,n) sum[i]=a[i]>=mid?1:-1;
	rep(i,1,n) sum[i]+=sum[i-1],ret+=sum[i]>=0;
	rep(i,1,n) up=std::max(up,sum[i]+=n+1);
	rep(i,1,n) ret+=T.qry(sum[i]),T.upd(sum[i],1);
	return 1ll*n*(n+1)/2-ret<(1ll*n*(n+1)/2)/2+1;
}
int main(){
	std::ios::sync_with_stdio(0);
	std::cin.tie(0),std::cout.tie(0);
	std::cin>>n;
	rep(i,1,n) std::cin>>a[i],cpy[i]=a[i];
	std::sort(cpy+1,cpy+n+1);
	cnt=std::unique(cpy+1,cpy+n+1)-cpy-1;
	rep(i,1,n) a[i]=std::lower_bound(cpy+1,cpy+cnt+1,a[i])-cpy;
	int l=1,r=cnt,ans=-1;
	while(l<=r){
		int mid=l+r>>1;
		if(check(mid)) l=mid+1,ans=mid;
		else r=mid-1;
		
	}
	std::cout<<cpy[ans]<<'\n';
	return 0;
}

Measured memory_bytes: 8704
N = int(input())
H = list(map(int, input().split()))
cnt = 0
while True:
    if len(H) == 1:
        break
    for i in range(len(H)):
        if H[i] == 0:
            if i == 0:
                H.pop(i)
                cnt -= 1
            break
        H[i] -= 1
    cnt += 1

print(cnt+H[0])

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define tr(ds, it) for(auto it=ds.begin(); it!=ds.end(); it++)
#define rtr(ds, it) for(auto it=ds.rbegin(); it!=ds.rend(); it--)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef priority_queue <int> pq;
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
#define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 


const ll mod = 1000000007;
ll po(ll x, ll n ){ 
	ll ans=1;
     while(n>0){
     	if(n&1) ans=(ans*x)%mod;
     	x=(x*x)%mod;
     	n/=2;
     }
     return ans;
}



int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r" , stdin);
	// freopen("output.txt", "w" , stdout);
	// #endif
	int T=1;
	//cin >> T;
	while(T--){
		ll n,k;
		cin>>n>>k;
		ll a[n];
		rep(i,n) cin>>a[i];
		ll p[n]={0};
		p[0]=a[0];
		rep_a(i,1,n) p[i]=p[i-1]+a[i];
		ll d[n];
		rep(i,n) d[i]=p[i]-i-1;
		ll r[n+1];
		r[0]=0;
		rep(i,n) r[i+1]=d[i]%k;
		// rep(i,n+1) cout<<r[i]<<" ";
		// cout<<el;
		map<ll,ll>m;
		ll ans=0;
		rep(i,min(k,n+1)){ 
			m[r[i]]++;
		}
		tr(m,h){
			ans+=((h->ss)*((h->ss)-1))/2;
		}
		rep_a(i,k,n+1){
			m[r[i-k]]--;
			if(m[r[i-k]]==0) m.erase(r[i-k]);
			if(m.find(r[i])!=m.end()) ans+=m[r[i]];
			m[r[i]]++;
		}
		cout<<ans<<el;
	}

	return 0;
}

Measured memory_bytes: 19072