akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int X,Y,Z;

signed main(){
	cin>>X>>Y>>Z;
	swap(X,Y);
	swap(X,Z);
	cout<<X<<" "<<Y<<" "<<Z<<endl;
	return 0;
}


Measured memory_bytes: 256
// Author -- Frame

#include<bits/stdc++.h>

#define lowbit(x) ((x)&(-(x)))
#define Finline __inline__ __attribute__ ((always_inline))
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
#define SZ(x) ((int)x.size())
#define mkpr std::make_pair
#define pb push_back

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef std::pair<int,int> pi;
typedef std::pair<ll,ll> pl;
using std::min;
using std::max;

const int inf=0x3f3f3f3f,Inf=0x7fffffff;
const ll INF=0x3f3f3f3f3f3f3f3f;

Finline uint rnd(){static uint seed=416;return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;}
template <typename _Tp>_Tp gcd(const _Tp &a,const _Tp &b){return (!b)?a:gcd(b,a%b);}
template <typename _Tp>Finline _Tp abs(const _Tp &a){return a>=0?a:-a;}
template <typename _Tp>Finline void chmax(_Tp &a,const _Tp &b){(a<b)&&(a=b);}
template <typename _Tp>Finline void chmin(_Tp &a,const _Tp &b){(b<a)&&(a=b);}
template <typename _Tp>Finline void read(_Tp &x)
{
	char ch(getchar());bool f(false);while(!isdigit(ch)) f|=ch==45,ch=getchar();
	x=ch&15,ch=getchar();while(isdigit(ch)) x=(((x<<2)+x)<<1)+(ch&15),ch=getchar();
	f&&(x=-x);
}
template <typename _Tp,typename... Args>Finline void read(_Tp &t,Args &...args){read(t);read(args...);}
template <typename _Tp,typename... Args>Finline _Tp min(const _Tp &a,const _Tp &b,const Args &...args){return a<b?min(a,args...):min(b,args...);}
template <typename _Tp,typename... Args>Finline _Tp max(const _Tp &a,const _Tp &b,const Args &...args){return a<b?max(b,args...):max(a,args...);}
Finline int read_str(char *s)
{
	char ch(getchar());while(ch==' '||ch=='\r'||ch=='\n') ch=getchar();
	char *tar=s;*tar=ch,ch=getchar();while(ch!=' '&&ch!='\r'&&ch!='\n'&&ch!=EOF) *(++tar)=ch,ch=getchar();
	return tar-s+1;
}

const int N=17;
const int mod=1000000007;
const int MAXN=(1<<16)+5;
template<typename _Tp1,typename _Tp2>Finline void add(_Tp1 &a,_Tp2 b){(a+=b)>=mod&&(a-=mod);}
template<typename _Tp1,typename _Tp2>Finline void sub(_Tp1 &a,_Tp2 b){(a-=b)<0&&(a+=mod);}
int a[N],dp[N][1<<16],cnt[1<<16];
ll fac[MAXN],inv[MAXN],ifac[MAXN];
void init()
{
	fac[0]=fac[1]=inv[0]=inv[1]=ifac[0]=ifac[1]=1;
	for(int i=2;i<MAXN;++i)
	{
		fac[i]=fac[i-1]*i%mod;
		inv[i]=inv[mod%i]*(mod-mod/i)%mod;
		ifac[i]=ifac[i-1]*inv[i]%mod;
	}
}
Finline ll C(int n,int m)
{
	if(n<m) return 0;
	return fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
int main()
{
	init();
	int n,m;read(n,m);
	int tot=1<<n;
	for(int i=1;i<=m;++i) read(a[i]);
	std::sort(a+1,a+m+1,[&](int A,int B)->bool{return A>B;});
	dp[0][0]=1;
	for(int i=0;i<m;++i)
	{
		for(int st=0;st<1<<n;++st)
		{
			add(dp[i+1][st],dp[i][st]);
			for(int j=0;j<n;++j)
			{
				if(!((st>>j)&1))
				{
					add(dp[i+1][st|(1<<j)],1ll*dp[i][st]*C(tot-a[i+1]-st,(1<<j)-1)%mod*fac[1<<j]%mod);
				}
			}
		}
	}
	int ans=0;
	for(int i=0;i<1<<n;++i)
	{
		cnt[i]=cnt[i>>1]+(i&1);
		if(cnt[i]&1) sub(ans,1ll*dp[m][i]*fac[tot-i-1]%mod);
		else add(ans,1ll*dp[m][i]*fac[tot-i-1]%mod);
	}
	printf("%lld\n",1ll*ans*tot%mod);
	return 0;
}


Measured memory_bytes: 9660
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue> //priority_queue
#include <map>
#include <set> //multiset set<int,greater<int>>大到小
#include <vector>// ::iterator it;
#include <stack>
#include <cmath> // auto &Name : STLName  Name.
#include <utility>
#include <sstream>
#include <string>//__builtin_popcount(ans);//获取某个数二进制位1的个数
#define mod 1000000007
#define mod9 998244353
typedef unsigned long long ull;
typedef long long ll;
typedef double db;
typedef long double ld;
const db eps=1e-10;
const int INF = 0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
#define rep(i,be,en) for (ll i=be;i<=en;i++)
#define per(i,be,en) for (int i=en;i>=be;i--)
//ll ksm(ll a,ll b,ll c){ll ans=1;a=a%c;while(b>0){if(b%2) ans=(ans*a)%c;b=b/2;a=(a*a)%c;}return ans;}
using namespace std;

const int N=5e5+7;
ll n,ans=0;
ll a[4005][3]={0};
char s[4005]={0};
int main(){
    scanf("%lld",&n);
    scanf("%s",s+1);
    rep(i,1,n){
        a[i][0]=a[i-1][0];
        a[i][1]=a[i-1][1];
        a[i][2]=a[i-1][2];
        if(s[i]=='R') a[i][0]++;
        if(s[i]=='G') a[i][1]++;
        if(s[i]=='B') a[i][2]++;
    }
    rep(i,2,n-1){
        rep(j,i+1,n){
            if((s[i]=='R'&&s[j]=='G')||(s[i]=='G'&&s[j]=='R')){
                ans+=a[i-1][2];
                if((2*i-j)>0&&s[2*i-j]=='B') ans--;
            }
            if((s[i]=='R'&&s[j]=='B')||(s[i]=='B'&&s[j]=='R')){
                ans+=a[i-1][1];
                if((2*i-j)>0&&s[2*i-j]=='G') ans--;
            }
            if((s[i]=='B'&&s[j]=='G')||(s[i]=='G'&&s[j]=='B')){
                ans+=a[i-1][0];
                if((2*i-j)>0&&s[2*i-j]=='R') ans--;
            }
        }
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 3908
#include<stdio.h>
#include<string.h>
#define MAX 201

int main(){
char str[MAX];
char temp[MAX];
int n,i,x,y,j;

while(1){
 scanf("%s",str);
 if(strcmp(str,"-")==0)break;
 y=strlen(str);
 scanf("%d",&n);
 for(i=0;i<n;i++){
  scanf("%d",&x);
  for(j=0;j<x;j++)temp[j]=str[j];
  for(j=x;j<y;j++)str[j-x]=str[j];
  for(j=y-x;j<y;j++)str[j]=temp[j-(y-x)];
 }
 printf("%s\n",str);
}

return 0;
}


Measured memory_bytes: 2044
#include <stdio.h>
#include <stdlib.h>
#define ll long long int
#define lim 100010
int min(int x, int y){return x<y?x:y;}
int compare_int(const void *a, const void *b){return *(int*)b - *(int*)a;}
typedef struct{
	int num,c;
}data;
int compare(const void *x, const void *y){
	return ((data*)y)->c - ((data*)x)->c;
}
int main(void){
	data odd[lim],even[lim]; 
	int n;
	scanf("%d",&n);
	for(int i=0;i<lim;i++){
		odd[i].c=0;
		even[i].c=0;
	}
	for(int i=0;i<n;i++){
		int v;
		scanf("%d",&v);
		if(i%2){
			odd[v].c++;
			odd[v].num=v;
		}else{
			even[v].c++;
			even[v].num=v;
		}
	}
	qsort(odd, lim, sizeof(data), compare);
	qsort(even, lim, sizeof(data), compare);
	int ans;
	if(odd[0].num==even[0].num){
		ans = min(n-even[0].c-odd[1].c,n-odd[0].c-even[1].c);
	}else{
		ans = n-odd[0].c-even[0].c;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 2352
#include <iostream>
#include <vector>
#include <string>
// #include <map>
// #include <algorithm>
// #include <set>
// #include <cmath>

using namespace std;
// typedef unsigned long long ull;


int main(int argc, char const *argv[]) {
    int N, M;
    cin >> N >> M;
    vector<string> A(N), B(M);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    for (int i = 0; i < M; ++i) {
        cin >> B[i];
    }

    bool hit = false;
    for (int i = 0; i <= N-M; ++i) {
        for (int j = 0; j <= N-M; ++j) {
            bool match = true;
            for (int k = 0; k < M; ++k) {
                for (int l = 0; l < M; ++l) {
                    if (A[i+k][j+l] != B[k][l]) {
                        match = false;
                        break;
                    }
                }
                if (!match) break;
            }
            if (match) {
                hit = true;
                break;
            }
        }
        if (hit) {
            break;
        }
    }

    if (hit) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
n = int(input())
d = {tuple(map(str, input().split())):i for i in range(1,n+1)}
sort_d = sorted(d.items(), key=lambda x:(x[0][0],-int(x[0][1]))) #点数に－で降順でマイナス順になる
r = []
for i in sort_d:
  print(i[1])

Measured memory_bytes: 3060
#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.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 524288
int main() {
	int n, a, b;
	cin >> n >> a >> b;
	cout << min(b, a*n) << endl;
	return 0;
}

Measured memory_bytes: 888
n, m = map(int, input().split())
s = ""

if n == 1:
    s = "0"
elif n == 2:
    s = "10"
else:
    s = "100"

flag = 0
chk = [-1] * n

for _ in range(m):
    a, b = map(int, input().split())

    if n > 1 and a == 1 and b == 0:
        flag = 1

    if chk[a - 1] > -1 and chk[a - 1] != b:
        flag = 1

    chk[a - 1] = int(b)
    s = s[:a-1] + str(b) + s[a:]

if flag == 0:
    if n == 1:
        print(s)
    elif int(s) >= 10 ** (n - 1):
        print(s)
    else:
        print(-1)
else:
    print(-1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch DivisibleSubstring | diff DivisibleSubstring.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address DivisibleSubstring.cpp && ./a.out

/*
 
 3/8/2020
 
 20:57-21:34 WA
 22:01 TLE
 22:16 give up
 
 https://img.atcoder.jp/abc158/editorial.pdf
 https://youtu.be/sv3l8heocMY?t=2794
 
 
 */

int N,P;
string S;

void solve() {
  if (P==2||P==5) {
    LL res=0;
    REP(i,N) if((S[i]-'0')%P==0) {
      res+=i+1;
    }
    cout<<res<<endl;
    return;
  }
  vector<LL> cnt(P,0);
  cnt[0]=1;
  int cur=0;
  LL res=0;
  int pow10=1;
  for(int i=N-1; i>=0; --i) {
    cur=(pow10*(S[i]-'0')+cur)%P;
//    dump(i,cur,cnt[cur])
    res+=cnt[cur];
    cnt[cur]++;
    pow10=pow10*10%P;
  }
  cout<<res<<endl;
}

void solve_tle() {
  unordered_map<int,LL> cnt;
  cnt[0]=1;
  int cur=0;
  LL res=0;
  REP(i,N) {
    cur=(cur*10+S[i]-'0')%P;
//    if(cur==0) res++;
    res+=cnt[cur];
    cnt[cur]++;
    unordered_map<int,LL> cnt2;
    FORR(kvp,cnt) {
      cnt2[kvp.first*10%P]+=kvp.second;
    }
//    dump(i,cur,cnt[cur]);
    swap(cnt,cnt2);
  }
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N>>P>>S;
  solve();
  
  return 0;
}


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



int main(int argc, char *argv[])
{
   
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    
    int n, m;
    cin >> n >> m;
    //vector<int> v(N + 1), w(N + 1);
    int c[110], w[110];
    for (int i = 1; i <= m; i++) {
        cin >> c[i];
    }
    
    vector<vector<int>> Value(m + 1, vector<int>(n + 1));
    //int Value[110][50010] = {0};
    //iota(Value[0].begin(), Value[0].end(), 0);
    for (int i = 1; i <= m; i++) {
        iota(Value[i].begin(), Value[i].end(), 0);
    }
    
    for (int i = 2; i <= m; i++) {
        for (int j = 1; j <= n; j++) {
            if (j >= c[i]) {
                Value[i][j] = min(Value[i - 1][j], Value[i][j - c[i]] + 1);
                
            } else {
                Value[i][j] = Value[i - 1][j];
            }
        }
    }
    
    cout << Value[m][n] << endl;
    
    return 0;
}



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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

template<typename T>
T gcd(T x, T y)
{
	return y ? gcd(y, x % y) : x;
}

void hawawa()
{
	int n[3];
	for (auto&& i : n) {
		cin >> i;
	}
	sort(rbegin(n), rend(n));
	cout << n[0] * 10 + n[1] + n[2] << "\n";
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
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;}

int main() {
    int n;
    cin >> n;
    vector<int>a(n);
    rep(i,n) cin >> a[i];
    int ans = 0;
    rep(i,n) {
        if(a[i]%2==0) {
            while(a[i]%2==0) {
                a[i] /= 2;
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int n, m, x;

  scanf("%d %d %d", &n, &m, &x);

  int d = 0, u = 0;

  for(int i = 0; i < m; i++){
    int a;
    scanf("%d", &a);

    if(a < x){
      d++;
    }else if(x < a){
      u++;
    }
  }

  if(u > d){
    printf("%d", d);
  }else{
    printf("%d", u);
  }
}


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

int main() {
  int N,M;
  cin >> N >> M;
  int sum=0;
  vector<int> A(N);
  rep(i,N){
    cin >> A.at(i);
    sum+=A.at(i);
  }
  int cnt=0;
  rep(i,N){
    if(A.at(i)*4*M<sum) {}
    else cnt++;
  }
  if(cnt>=M) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int n,c=0,k,i;
  string s;
  while(cin>>n,n){
    c=0;
    int a[n];
    for(i=0;i<n;i++)cin>>a[i];
    cin>>s;
  for(i=0;i<s.size();i++){
    k=a[c++%n];
    for(int j=0;j<k;j++){
    if(int(s[i])-1>90&&int(s[i])-1<97)s[i]=s[i]-7;    
    else if(int(s[i])-1<65)s[i]='{'-1;
    else s[i]=s[i]-1;
    }
  }
  cout<<s<<endl;
  }
}

Measured memory_bytes: 3156
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
#define INF 1200000000



int main(){
    
    int N,p;
    int cnt=1;
    cin>>N>>p;
    int MINI=p;
    rep(i,1,N){
        cin>>p;
        if(MINI>=p)cnt++;
        MINI=min(MINI,p);
    }
    cout<<cnt<<endl;
    
}




Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
public class Hello
{

    public static void Main()
    {
        string[] s = Console.ReadLine().Split(' ');
        int X = int.Parse(s[0]);
        int A = -int.Parse(s[1]);
        int B = int.Parse(s[2]);
        string ans = "dangerous";
        if ((A + B) <= 0) ans = "delicious";
        else if ((A + B) <= X) ans = "safe";
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 11092
'use strict'

const main = (input) => {
    const nums = input.split('\n')[1].split(' ').map(v => parseInt(v)).sort((a, b) => a - b)
    console.log(nums[nums.length - 1] - nums[0])
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Measured memory_bytes: 7500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
int dp0[5005][5005], dp1[5005][5005], dp2[5005][5005], sum1[5005][5005];
int main(){
    int n, a, b;
    scanf("%d%d%d", &n, &a, &b);
    if(a > b) swap(a, b);
    dp1[0][0] = 1;
    for(int j=0;j<=n;j++) sum1[0][j] = 1;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=a-1;j++) if(i-j >= 0) dp0[i][0] = (dp0[i][0] + sum1[i-j][n])%mod;
        if(i >= a) for(int j=0;j<=b-a-1;j++) dp2[i][j+a] = (dp2[i][j+a] + dp1[i-a][j])%mod;

        for(int j=0;j<b-1;j++){
            dp2[i][j+1] = (dp2[i][j+1] + dp2[i-1][j])%mod;
        }
        for(int j=0;j<b-1;j++){
            dp1[i][j+1] = (dp1[i][j+1] + dp0[i-1][j])%mod;
            dp1[i][j+1] = (dp1[i][j+1] + dp1[i-1][j])%mod;
            dp1[i][j+1] = (dp1[i][j+1] + dp2[i-1][j])%mod;
        }

        for(int j=0;j<=n;j++){
            if(j == 0) sum1[i][j] = dp1[i][j];
            else sum1[i][j] = (sum1[i][j-1] + dp1[i][j])%mod;
        }
    }
    int ans = 1;
    for(int i=1;i<=n;i++) ans = ans*2%mod;
    for(int j=0;j<=n;j++){
        ans = (ans - dp0[n][j] + mod)%mod;
        ans = (ans - dp1[n][j] + mod)%mod;
        ans = (ans - dp2[n][j] + mod)%mod;
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 317020
import sys,math,copy,queue,itertools,bisect,collections
from heapq import *
sys.setrecursionlimit(10**7)
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
INF = 10**18
MOD = 10**9 + 7
DD = ((1,0),(-1,0),(0,1),(0,-1))

n,a,b,c = LI()
z = [a,b,c]
s = [sys.stdin.readline().rstrip() for _ in range(n)]
ans = []
for i in range(n):
    x = s[i]
    p = -1
    if x == 'AB': j=0;k=1;l=2
    elif x == 'AC': j=0;k=2;l=1
    elif x == 'BC': j=1;k=2;l=0
    if z[j] > z[k]:
        z[j] -= 1; z[k] += 1
        p = k
    else:
        z[j] += 1; z[k] -= 1
        p = j
    if (z[j] == 0 or z[k] == 0) and z[l] == 0:
        if i < n-1:
            y = s[i+1]
            if y == 'AB': j1=0;k1=1;l1=2
            elif y == 'AC': j1=0;k1=2;l1=1
            elif y == 'BC': j1=1;k1=2;l1=0
            if z[j1] == 0 and z[k1] == 0:
                if z[j] == 0:
                    z[j] += 2; z[k] -= 2
                    p = j
                else:
                    z[j] -= 2; z[k] += 2
                    p = k
    if min(z) < 0:
        print('No')
        exit(0)
    if p==0:ans.append('A')
    elif p==1:ans.append('B')
    else: ans.append('C')
print('Yes')
print(*ans,sep='\n')






Measured memory_bytes: 85548
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.IOException;

public class Main{

    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

    static int n, answer;
    static int counting;

    public static void main(String[] args) throws IOException {
        String input;
        while (!(input = br.readLine()).equals("0 0")) {
            String[] st = input.split(" ");
            n = Integer.parseInt(st[0]);
            answer = Integer.parseInt(st[1]);
            counting = 0;
            
            for (int i = 1; i <= n; i++) {
                for (int j = i + 1; j <= n; j++) {
                    for (int k = j + 1; k <= n; k++) {
                        if (i + j + k == answer) {
                            counting++;
                        }
                    }
                }
            }

            bw.append(counting + "\n");
        }
        bw.flush();
    }


}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;

typedef long long LL;
typedef long double ldouble;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    set<int> st;
    map<int, bool> mp;
    int n;
    cin >> n;
    while(n--) {
        int a;
        cin >> a;
        if(mp[a]) mp[a] = false;
        else mp[a] = true;
        st.insert(a);

    }

    int c = 0;
    for(auto it = st.begin(); it != st.end(); ++it) {
        if(mp[*it]) ++c;

    }
    cout << c << endl;
    return 0;
}



Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll a[100000],dp[100000];
ll n,k;
ll frog(ll i){

	 if(i==1)
		return 0;
	if(dp[i]!=1e12+7)
		return dp[i];
	else{
		for(ll j=1;j<=k;j++){
			if(i-j>=1){
			dp[i]=min(dp[i],frog(i-j)+abs(a[i]-a[i-j]));
			}
			}
		return dp[i];
	}
}
int main(){
	ll ans=0;
	cin>>n>>k;
	for(ll i=1;i<=n;i++){
		cin>>a[i];
		dp[i]=1e12+7;
		}
		
	ans=frog(n);
	cout<<ans<<endl;
	}

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

#define rep(i,j,n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
#define LINF 1e18

const int mod = 1e9 + 7;

typedef long long i64;
typedef pair<int, int> pi;

template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;

i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcm(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

  int n;
  cin >> n;
  vt<int> a(n);
  rep(i, 0, n) cin >> a[i];

  i64 ans = 0, sum = 0;
  map<i64, i64> mp;
  mp[0] = 1;
  rep(i, 0, n) {
    sum += a[i];
    ans += mp[sum];
    mp[sum]++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 13568
import java.io.IOException;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;


public class Main {

	
	// a b c    0 1 2
	// d e f => 3 4 5
	// g h i    6 7 8
	public static final int[][] adj = new int[][]{
		{1, 3}, //a 
		{0, 2, 4}, //b
		{1, 5}, //c
		{0, 4, 6}, //d
		{1, 3, 5, 7}, //e
		{2, 4, 8}, //f
		{3, 7}, //g
		{4, 6, 8}, //h
		{5, 7}, //i
	};
	
	public static int trans(char a){
		return a - 'A';
	}
	
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		
		for(int i = 0; i < 1000; i++){
			String input = sc.nextLine();
			
			char prev = 0;
			boolean flag = true;
			for(char in_ch : input.toCharArray()){
				if(prev != 0){
					final int prev_int = trans(prev);
					final int next_int = trans(in_ch);
				
					final int pos = Arrays.binarySearch(adj[prev_int], next_int);
					
					if(pos < 0){
						flag = false;
						break;
					}
				}
				
				prev = in_ch;
			}
			
			if(flag){
				System.out.println(input);
			}
			
		}
		
		
	}

}

Measured memory_bytes: 23912
#include<iostream>
#include<string.h>
using namespace std;
int main()
{	char s[60],t[60];
	int flag,flag2,index,k;
	int l1,l2;
	while(cin>>s>>t)
	{
		l1=strlen(s);
		l2=strlen(t);
		for(int i=l1-l2;i>=0;i--)
		{	
			flag2=0;
			for(int j=0,k=0;j<l2,k<l2;j++,k++)
			{
				flag=1;
				if((s[i+k]!=t[j])&&s[i+k]!='?') 
			{
				flag=0;
				break;
			}
			
			}
			if(flag==1)
			{		
				flag2=1;
				index=i;
				break;
			}
			
		}
		if(flag2==0) 
		{
		cout<<"UNRESTORABLE"<<endl;
		continue;
		}
		
		for(int i=index,k=0;i<index+l2,k<l2;i++,k++)
		s[i]=t[k];
		for(int i=0;i<l1;i++)
		{
			if(s[i]=='?')
			s[i]='a';
			cout<<s[i];
			
		}
		cout<<endl;
	}
	return 0;
}      

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
bool comp1(pair<int,int> &a,pair<int,int> &b)
{
    return a.second>b.second;
}
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int a,b;
    cin>>a>>b;
    cout<<ceil((1.0*a)/b);
}

Measured memory_bytes: 3812
#include <bits/stdc++.h>
#define int long long
#define double long double
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define INF 1e18
#define porc 1000000007
#define ff first
#define ss second
#define ll long long
#define td(v) v.begin(),v.end()
#define tdr(v) v.rbegin(),v.rend()
using namespace std;
bool cmd(pair<int,int> a, pair<int,int> b){
    return a.second<b.second;
}
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int exp(int a, int b,int M){
    int result = 1;
    while (b > 0){
        if (b & 1)
            result = (result*a)%M;
 
        b >>= 1;
        a = (a*a)%M;
    }
    return result;
}
main(){
    int a,b,c; cin>>a>>b>>c;
    if(a+b+c>=22){
        cout<<"bust"<<endl;
    }
    else{
        cout<<"win"<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
typedef long long LL;


void findzero() {
    int ret = 1;
    for (int i = 2; 2*i/2 == i; i *= 10) {
        cout << "? " << i << endl;
        string s;
        cin >> s;
        if (s == "Y") {
            break;
        }
        else ret *= 10;
    }
    cout << "! " << ret << endl;
}
int findbase() {
    for (int i = 100000000; i >= 1; i /= 10) {
        cout << "? " << i << endl;
        string s;
        cin >> s;
        if (s == "Y") {
            return i;
        }
    }
}
void search(LL base) {
    LL left = base + 1;
    LL right = base * 10 - 1;
    while (left < right) {
        LL mid = (left+right) >> 1;
        cout << "? " << mid*10 << endl;
        string s;
        cin >> s;
        if (s == "Y") {
            right = mid;
        }
        else {
            left = mid + 1;
        }
    }
    cout << "! " << left << endl;
}

int main() {
    cout << "? " << 1000000000 << endl;
    string s;
    cin >> s;
    if (s == "Y") {
        findzero();
    }
    else {
        int base = findbase();
        search(base);
    }
    return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <queue>
#include <stack>
#define WHITE -1
#define BLACK 1
using namespace std;

int main(void) {
	//黒と接してる白はすべて黒色になる
	int H,W;
	cin >> H >> W;

	vector<vector<int>> first_stack;
	vector<vector<int>> buffer_stack;
	vector<vector<int>> map(H+2, vector<int>(W+2));
	for (int i = 1; i <= H; i++)
	{
		for (int j = 1; j <= W; j++)
		{
			char tmp;
			cin >> tmp;
			if (tmp == '.')
			{
				map[i][j] = WHITE;
			}
			else
			{
				map[i][j] = BLACK; first_stack.push_back({ i,j });
			}
		}
	}

	vector<int> vector_x({ 1,0,-1,0 });//→　↓　←　↑
	vector<int> vector_y({ 0,1,0,-1 });
	int current_x;
	int current_y;
	int count = -1;
	while(!first_stack.empty())
	{
		current_y = first_stack.back()[0];
		current_x = first_stack.back()[1];
		first_stack.pop_back();

		//周辺の4マスをチェック
		for (int i = 0; i < 4; i++)
		{
			int next_x = current_x + vector_x[i];
			int next_y = current_y + vector_y[i];

			if (map[next_y][next_x] == WHITE)
			{
				map[next_y][next_x] = BLACK;
				buffer_stack.push_back({next_y,next_x});
			}
		}

		if (first_stack.empty())
		{
			first_stack = buffer_stack;
			buffer_stack.clear();
			count++;
		}
	}

	cout << count << endl;
}

Measured memory_bytes: 59944
import java.util.Scanner;

public class Main {
 	public static void main(String[] args) {
 		Scanner scanner = new Scanner(System.in);
 		int N = scanner.nextInt();
 		int K = scanner.nextInt();
 		int Q = scanner.nextInt();
 		int Score[] = new int[N];
 		for (int i = 0; i < N; i++) {
 			Score[i] = 0;
 		}
 		for (int j = 0; j < Q; j++) {
 			int x = scanner.nextInt();
 			Score[x - 1] += 1;
 		}
 		for (int i = 0; i < N; i++) {
 			if (K - Q + Score[i] > 0) {
 				System.out.println ("Yes");
 			} else {
 				System.out.println ("No");
 			}
 		}
 	}
}

Measured memory_bytes: 69536
#include<bits/stdc++.h> 
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
ll gcd(ll a,ll b) 
{ 
	if (a == 0) 
		return b; 
	return gcd(b % a, a); 
} 
bool isprime(ll n)
{
    for(ll i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
            return false;
    }
    return true;
}
int main()
{
	ll n,w,i,j;
	cin>>n>>w;
	ll val[n],weight[n];
	for(i=0;i<n;i++)
	{
		cin>>weight[i]>>val[i];
	}
	ll dp[n+1][w+1];
	/*for(i=0;i<=n;i++)
	{
		dp[i][0]=0;
	}
	for(i=0;i<=w;i++)
	 dp[0][i]=0;*/
	for(i=0;i<=n;i++)
	{
		for(j=0;j<=w;j++)
		{
			if(i==0||j==0)
				dp[i][j]=0;
			else if(j>=weight[i-1])
			dp[i][j]=max(val[i-1]+dp[i-1][j-weight[i-1]],dp[i-1][j]);
			else
			dp[i][j]=dp[i-1][j];
		}
	}
	cout<<dp[n][w];
	return 0;
}

Measured memory_bytes: 79104
cards = list()
suit = ['S', 'H', 'C', 'D']
N = int(input())
for i in range(N):
    m,n = input().split()
    n = int(n)
    if m == "S": cards.append(0 + n)
    elif m == "H": cards.append(13 + n)
    elif m == "C": cards.append(26 + n)
    elif m == "D": cards.append(39 + n)
for i in range(1,53):
    if not (i in cards):
        print(suit[(i-1) // 13], (i-1) % 13 + 1)


Measured memory_bytes: 5616
def open(box, key):
    return (box & (2**N-1 - key))
N, M = map(int, input().split())
INF = 10**8+1
dp = [[INF]*2**N for i in range(M+1)]
for i in range(M+1):
    dp[i][0] = 0
key = []
for i in range(M):
    a, b= map(int, input().split())
    n = 0
    c = list(map(int, input().split()))
    for i in range(b):
        n += 2**(c[i]-1)
    key.append((a,n))
for i in range(1,M+1):
    for j in range(2**N):
        dp[i][j] = min(dp[i-1][j], dp[i-1][open(j, key[i-1][1])]+key[i-1][0])
if dp[M-1][2**N-1] == INF:
    dp[M-1][2**N-1] = -1
print(dp[M-1][2**N-1])

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


int main()
{
	long long x;
	cin >> x;
	long long c = 100;
	long long s = 0;
	while (c < x)
	{
		c = c + (long long)c / 100;
		s++;
	}
	cout << s << "\n";
}

Measured memory_bytes: 3620
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>


using namespace std;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const double PI = acos(-1.0);
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define all(v) v.begin(), v.end()

char alfa[] = { 'A','B' ,'C','D' ,'E' ,'F' ,'G' ,'H' ,'I' ,'J' ,'K' ,'L' ,'M' ,'N' ,'O' ,'P' ,'Q' ,'R' ,'S' ,'T' ,'U' ,'V' ,'W' ,'X' ,'Y','Z' };

inline void finish() {
	cout << -1 << endl;
	exit(0);
}

unsigned GetDigit(unsigned num) {
	return log10(num) + 1;
}

template <typename T>
inline void debug(vector<T> v) {
	cout << "[";
	for (ll i = 0; i < v.size() - 1; ++i) {
		cout << v[i] << ", ";
	}
	cout << v[v.size() - 1] << "]" << endl;
}

void Main();
inline void DebugMain() {
	while (true) {
		Main();
	}
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);

	bool debug = false;
	if (debug) {
		cout << "\x1b[41m" << "Debug Mode " << endl;
	}
	(debug) ? DebugMain() : Main();
	return 0;
}


ll calcC(ld lastNum, ld calcNum, ll A, ll B, ll X) {
	if (calcNum < 1) {
		return 0;
	}

	ll ans;

	ans = A * calcNum + B * GetDigit(calcNum);

	if (calcNum == lastNum) {
		return calcNum;
	}

	if (ans > X) {
		return calcC(calcNum, calcNum - (fabs(calcNum - lastNum) / 2), A, B, X);
	}
	else {
		return calcC(calcNum, calcNum + (fabs(calcNum - lastNum) / 2), A, B, X);
	}

}

inline void Main() {
	ll X, Y, N;
	ll A, B;
	ll M1, D1, M2, D2;
	ll ans;
	string S;
	bool flag = false;


	cin >> X;

	for (int a = 0; a <= 1000; a++) {
		Y = 100 * a ;

		if (Y == X) {
			flag = true;
		}
		else if (Y > X) {
			break;
		}
		for (int b = 0; b < 1000 - a; b++) {
			Y = 100 * a + 101 * b;

			if (Y == X) {
				flag = true;
			}
			else if (Y > X) {
				break;
			}
			for (int c = 0; c < 1000 - a - b; c++) {
				Y = 100 * a + 101 * b + 102 * c;

				if (Y == X) {
					flag = true;
				}
				else if (Y > X) {
					break;
				}
				for (int d = 0; d < 1000 - a - b - c; d++) {
					Y = 100 * a + 101 * b + 102 * c + 103 * d;

					if (Y == X) {
						flag = true;
					}
					else if (Y > X) {
						break;
					}
					for (int e = 0; e < 1000 - a - b - c - d; e++) {
						Y = 100 * a + 101 * b + 102 * c + 103 * d + 104 * e;

						if (Y == X) {
							flag = true;
						}
						else if (Y > X) {
							break;
						}
						for (int f = 0; f < 1000 - a - b - c - d - e; f++) {
							Y = 100 * a + 101 * b + 102 * c + 103 * d + 104 * e + 105 * f;

							if (Y == X) {
								flag = true;
							}
							else if (Y > X) {
								break;
							}
						}
						if (flag) {
							break;
						}
					}
					if (flag) {
						break;
					}
				}
				if (flag) {
					break;
				}
			}
			if (flag) {
				break;
			}
		}
		if (flag) {
			break;
		}
	}

	cout << flag;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

string s;
int n;

bool possible( int k ){
	if( n >= 2*k ) return true;
	else{
		bool res = true;
		for( int i = n-k; i < k-1; ++i ){
			if( s[i] != s[i+1] ) res = false;
		}
		return res;
	}
}

int main(){
	cin >> s;
 	n = s.l_ength();
  	int ok = 1;
	int ng = n+1;
	while( ng-ok > 1 ){
		int mid = (ok+ng)/2;
		if( possible(mid) ){
			ok = mid;
		} else {
			ng = mid;
		}
	}
	cout << ok << endl;
}


Measured memory_bytes: 640
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  std::string S;
  std::cin >> S;
  if (S.size() == 3) std::reverse(S.begin(), S.end());
  std::cout << S << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;
const int MOD = 1000000007; // 計算してからmodで割る ans = (ans * a) % mod
#define int long long
template <typename T = long long > T in () { T x; cin >> x; return(x);}
// int a = in() のように使うlong long以外の型の時はstirng s = in<string>()のように型を指定する

signed main(void){
    int n = in();
    int ans_num;
    for(int i = 1; i <= sqrt(n); i++){
        if(n % i == 0){
            ans_num = i;
        }
    }

    string ans = to_string(n / ans_num);
    cout << ans.size() << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int cnt = 1;

		if(b!=a) cnt++;
		if(c!=b&&c!=a) cnt++;

		System.out.println(cnt);
	}
}

Measured memory_bytes: 9804
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
//typedef pair<int,int> P;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, pair<int, int>>> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2147483600;//10^9
int INFM =100000000;
ll MOD  = 1000000007;
 

 
 
int main(){
  string s;
  int a,b;
  cin >> s;
  a = atoi(s.substr(0, 2).c_str());
  b = atoi(s.substr(2, 2).c_str());
  if(a >= 1 && a <= 12 && b >= 1 && b <= 12){
  	cout << "AMBIGUOUS" << endl;
  }else if(a >= 1 && a <= 12){
    cout << "MMYY" << endl;
  }else if(b >= 1 && b <= 12){
  	cout << "YYMM" << endl;
  }else{
   cout << "NA" << endl; 
  }
  

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline T read(){
	T f=0,x=0;char c=getchar();
	while(!isdigit(c)) f=c=='-',c=getchar();
	while(isdigit(c)) x=x*10+c-48,c=getchar();
	return f?-x:x;
}
#define int long long
namespace run{
	int main(){
		int n=read<int>(),a=read<int>(),b=read<int>();
		if((b-a+1)&1) printf("%lld\n",(b-a)/2);
		else printf("%lld\n",min((a+b-1)/2,(n-a+1+n-b+1-1)/2));
		return 0;
	}
}
#undef int
int main(){
#ifdef my
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
	return run::main();
}

Measured memory_bytes: 256
#import bisect,collections,copy,heapq,itertools,math,numpy,string
#from operator import itemgetter
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
N = I()
S = [S() for _ in range(N)]
dict = {}

for s in S:
	if s not in dict:
		dict[s] = 1
print(len(dict))


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

int main()
{
    int a[5];
    for (int i = 0; i < 5; ++i) std::cin >> a[i];
    std::sort(a, a + 5, std::greater<int>());
    std::cout << a[0];
    for (int i = 1; i < 5; ++i) std::cout << " " << a[i];
    std::cout << std::endl;
}

Measured memory_bytes: 1180
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<cassert>
#include<iomanip>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)
#define eps (1e-8)
#define equals(a,b) (fabs((a)-(b)) < eps)
#define MAX 2000000
#define all(n) (n).begin(),(n).end()
using namespace std;
struct Circle
{
  double x,y,r;
  Circle(double x=inf,double y=inf,double r=inf):x(x),y(y),r(r){}
  bool operator < (const Circle& c)const
  {
    if(!equals(x,c.x))return x < c.x;
    return y < c.y;
  }
};

bool compare_y(Circle a,Circle b)
{
  return a.y < b.y;
}

int N;
Circle A[MAX];

double compute(Circle *a,int n)
{
  if(n <= 1)return inf;
  int m = n/2;
  double x = a[m].x;
  double y = a[m].y;
  double r = a[m].r;
  double d = min(compute(a,m),compute(a+m,n-m));
  inplace_merge(a,a+m,a+n,compare_y);

  vector<Circle> b;

  rep(i,n)
    {
      double nx = a[i].x - x;
      double ny = a[i].y - y;
      double ndist = sqrt(nx*nx + ny*ny) - a[i].r - r;
      //if(equals(ndist,d) || ndist > d)continue;
      //if(nx >= d)continue;
     
      rep(j,(int)min((int)b.size(),5))
	{
	  int last = b.size()-j-1;
	  double dx = a[i].x - b[last].x;
	  double dy = a[i].y - b[last].y;
	  double dist = sqrt(dx*dx + dy*dy) - a[i].r - b[last].r;

	  if(equals(dist,d) || dist > d)continue;
	  d = min(d,sqrt(dx*dx + dy*dy) - a[i].r - b[last].r);
	}
      b.push_back(a[i]);
    }
  return d;
}



int main()
{
  while(cin >> N,N)
    {
      assert(N < MAX);
      rep(i,N)cin >> A[i].r >> A[i].x >> A[i].y;
      sort(A,A+N);


      cout << setiosflags(ios::fixed) << setprecision(8) << compute(A,N) << endl;
    }
  return 0;
}

Measured memory_bytes: 53580
//
//  abc151_c.cpp
//  learningCplusplus
//
//  Created by Tran Duc Chinh on 2020/04/04.
//  Copyright © 2020 Tran Duc Chinh. All rights reserved.
//

#include <iostream>
#include <queue>
#include <map>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
ll mod = 998244353;
ll INF = 1000000007;
#define PI 3.14159265


int main() {
  int n, m;
  std::cin >> n >> m;

  std::vector<string> p[n+1];

  for (int i = 0; i < m; i++) {
    int t;
    string s;
    std::cin >> t;
    std::cin >> s;

    int size = p[t].size();
    if (size > 0) {
      string last = p[t][size-1];
      if (last.compare("AC")) {
        p[t].push_back(s);
      }
    }
    else {
      p[t].push_back(s);
    }
  }

  int pen = 0;
  int ac = 0;
  for (int i = 1; i <= n; i++) {
    int size = p[i].size();
    if (size > 0) {
      string last = p[i][p[i].size()-1];
      if (last.compare("AC") == 0) {
        ac += 1;
        pen += size - 1;
      }
    }
  }

  std::cout << ac << " " << pen << std::endl;

  return 0;
}

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

using namespace std;

    int dist[2000][2000];
    bool vis[2000][2000];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int H, W;
    cin >> H >> W;
    for(int i = 0; i < H; i++)
        for(int j = 0; j < W; j++)
            dist[i][j] = 10000, vis[i][j] = false;
    queue<pair<int,int> > Q;
    for(int i = 0; i < H; i++)
    {
        string s;
        cin >> s;
        for(int j = 0; j < W; j++)
        {
            if(s[j] == '#')
            {
                dist[i][j] = 0;
                vis[i][j] = true;
                Q.push({i, j});
            }
        }
    }
    while(!Q.empty())
    {
        int i = Q.front().first;
        int j = Q.front().second;
        Q.pop();
        vector<pair<int,int> > ngbhs = {{i + 1, j}, {i - 1, j}, {i, j + 1}, {i, j - 1}};
        for(auto f : ngbhs)
        {
            if(f.first < H && f.second < W && f.first >= 0 && f.second >= 0)
                if(!vis[f.first][f.second])
                {
                    vis[f.first][f.second] = true;
                    dist[f.first][f.second] = min(dist[i][j] + 1, dist[f.first][f.second]);
                    Q.push(f);
                }
        }
    }
    int max_dist = 0;
    for(int i = 0; i < H; i++)
        for(int j = 0; j < W; j++)
            max_dist = max(max_dist, dist[i][j]);
    cout << max_dist;
    // system("PAUSE");
    return 0;
}

Measured memory_bytes: 20624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)

class UnionFind{
public:
	vector<int> par;
	vector<long long> g1,g2;
	//0-indexed
	void init(int n = 1) {
		par.resize(n);
		for (int i = 0; i < n; ++i) par[i] = i;
		g1.resize(n,0);
		g2.resize(n,0);
	}
	int root(int x = 1){
		if(par[x]==x)return x;
		else{
			return par[x] = root(par[x]);
		}
	}
	void unite(int x = 1,int y = 1){
		x = root(x);
		y = root(y);
		if(x==y)return;
		g1[y] += g1[x];
		g2[y] += g2[x];
		par[x] = y;
	}
};

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int H,W;
	ll ans=0;
	cin >> H >> W;
	string s[H];
	FOR(i,0,H){
		cin >> s[i];
	}
	UnionFind uf;
	uf.init(H*W);
	// (x,y) -> W*x+y
	FOR(i,0,H){
		FOR(j,0,W){
			if(s[i][j]=='#'){
				uf.g1[W*i+j]=1;
			}else{
				uf.g2[W*i+j]=1;
			}
		}
	}
	FOR(i,0,H){
		FOR(j,0,W){
			int now = W*i+j;
			int to = W*(i-1)+j;
			if(i>0)if(s[i][j]!=s[i-1][j]){
				uf.unite(now,to);
			}
			to = W*(i+1)+j;
			if(i<H-1)if(s[i][j]!=s[i+1][j]){
				uf.unite(now,to);
			}
			to = W*i+j-1;
			if(j>0)if(s[i][j]!=s[i][j-1]){
				uf.unite(now,to);
			}
			to = W*i+j+1;
			if(j<W-1)if(s[i][j]!=s[i][j+1]){
				uf.unite(now,to);
			}
		}
	}
	set<int> se;
	FOR(i,0,H){
		FOR(j,0,W){
			int ro = uf.root(i*W+j);
			if(se.count( ro )==0){
				ans += uf.g1[ro]*uf.g2[ro];
				se.insert(ro);
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 9728
h,w = map(int, raw_input().split())
n = int(raw_input())
l = map(int, raw_input().split())
for i in range(1,n):
    l[i] += l[i-1]
idx = 0
mp = [[0 for _ in range(w)] for _ in range(h)]
for y in range(h):
    for x in range(w):
        p = y * w + x + 1
        if p > l[idx]:
            idx += 1
        if y % 2 == 1:
            x = w - 1 - x
        mp[y][x] = idx + 1
for a in mp:
    print " ".join(map(str,a))


Measured memory_bytes: 3332
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        LightScanner in = new LightScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BCollectingBallsEasyVersion solver = new BCollectingBallsEasyVersion();
        solver.solve(1, in, out);
        out.close();
    }

    static class BCollectingBallsEasyVersion {
        public void solve(int testNumber, LightScanner in, PrintWriter out) {
            int n = in.ints();
            int k = in.ints();
            out.println(2 * IntStream.range(0, n).map(x -> in.ints()).map(y -> Math.min(y, k - y)).sum());
        }

    }

    static class LightScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public String string() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int ints() {
            return Integer.parseInt(string());
        }

    }
}



Measured memory_bytes: 27860