akhauriyash/Code-Regression huggingface dataset:
#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>
#include <complex>
using namespace std;
using ll = long long;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define INF 1e9+7
#define rep(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
using P=pair<int,int>;

int main(){
    int n;
    cin>>n;
    vector<int>color(n);
    int mx=0;
    int mxc=0;

    vector<vector<int>>num(n);
    map<P,int>mp;
    rep(i,n-1){
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        mp[P(a,b)]=i;
        num[b].push_back(a);
        num[a].push_back(b);
        if(mx<num[a].size()){
            mx=num[a].size();
            mxc=a;
        }
        if(mx<num[b].size()){
            mx=num[b].size();
            mxc=b;
        }
    }
    
    
    
    queue<int>que;
    vector<int>used(n),ans(n);

    que.push(mxc);
    color[mxc]=0;
    while(que.size()){
        int now=que.front();
        used[now]=1;
        que.pop();
        int clnum=1;
        for(int x:num[now]){
            if(used[x]==1)continue;
            if(clnum==color[now])clnum++;
        
            color[x]=clnum;
            que.push(x);
            int a=now;
            int b=x;
            if(b<a)swap(a,b);
            ans[mp[P(a,b)]]=clnum;
            clnum++;
        }
    }
    
    cout<<mx<<endl;
    rep(i,n-1)cout<<ans[i]<<endl;
    return 0;
}

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

int main() {
  int n,m;
  cin>>n>>m;
  vector<int> l(m),r(m);
  for (size_t i = 0; i < m; i++) {
    cin>>l[i]>>r[i];
  }
  sort(l.begin(),l.end());
  sort(r.begin(),r.end());
  int k = r[0]-l[m-1]+1;
  if (k<0) {
    cout<<0;
  }else{
    cout<<k;
  }
}

Measured memory_bytes: 1024
from math import *

EPS = 1e-9

a, b, x = map(int, input().split())
x = x / a
half = a * b / 2
ans = 0

if fabs(x - half) < EPS:
    ans = 45
elif x - half < EPS:
    c = 2 * x / b
    ans = degrees(atan(b / c))
elif x - half > EPS:
    c = 2 * x / a - b
    ans = degrees(atan((b - c) / a))

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vpi = vector<pii>;

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

    ll n, x, y, first = INT64_MAX, first2 = INT64_MAX, second = INT64_MIN, second2 = INT64_MIN;
    cin >> n;
    while (n--) {
        cin >> x >> y;
        first = min(x + y, first);
        second = max(x + y, second);
        first2 = min(x - y, first2);
        second2 = max(x - y, second2);
    }
    cout << max(abs(first - second), abs(first2 - second2)) << "\n";


    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
    int N;
    cin >> N;
    
    for(int i = 1; i <= 10; i++){
        if(i == 10){
            cout << 1111 << endl;
            return 0;
        }
        
        int temp = i;
        for(int j = 1; j <= 2; j++){
            temp += pow(10, j) * i;
        }
        
        if(temp >= N){
            cout << temp << endl;
            return 0;
        }
    }
}

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

int main(int argc, char const *argv[])
{
	string s;
	while(getline(cin,s),s!=".")
	{
		stack<int> q;
		bool f=1;
		for (int i = 0; i < s.size(); ++i)
		{
			if(s.at(i)=='(') q.push(1);
			else if(s.at(i)=='[') q.push(2);
			else if(s.at(i)==')')
			{
				if(q.size()==0||q.top()!=1) f=0,i=s.size();
				else q.pop();
			}
			else if(s.at(i)==']')
			{
				if(q.size()==0||q.top()!=2) f=0,i=s.size();
				else q.pop();
			}
		}
		if(q.size()==0&&f) cout<<"yes\n";
		else cout<<"no\n";
	}
	return 0;
}



Measured memory_bytes: 3168
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

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

  Graph g(n+1);
  for(int i=0;i<m;i++){
    int a,b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  vector<int> dist(n+1,-1);
  queue<int> que;
  vector<int> mark(n+1,-1);

  dist[1] = 0;
  que.push(1);

  while(!que.empty()){
    int v = que.front();
    que.pop();

    for(int nv:g[v]){
      if(dist[nv] != -1) continue;

      dist[nv] = dist[v] + 1;
      mark[nv] = v;
      que.push(nv);
    }
  }

  cout << "Yes\n";
  for(int i=2;i<=n;i++){
    cout << mark[i] << endl;
  }
}


Measured memory_bytes: 10656
using namespace std; 
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include<set>
#define vi vector<int>
#define vc vector<char>
 
int main() {
	string s; cin >> s; 
	int ans = 0 , mx=1;
	for (int i = 1; i < 4; i++) {
		if (s[i] == s[i - 1]) mx++; 
		else {
			ans = max(ans, mx); 
			mx = 1; 
		}
		if (i == 3) {
			ans = max(mx, ans); 
		}
	}
	if (ans >= 3) cout << "Yes";
	else cout << "No"; 
}

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

/*
K回の必殺技は、最も体力の多いK匹のモンスターに使う
Hを昇順ソートして頭からN-K匹のモンスターの体力を足していけばよい。
*/

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

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

    sort(H.begin(), H.end());
    long ans = 0;
    for (int i = 0; i < N - K; i++)
    {
        ans += H[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int R,G,B,N;
int main(){
	cin>>R>>G>>B>>N;
	int sum=0;
	for(int i=0;i<=N/R;i++){
		for(int j=0;j<=N/G;j++){
			int k=N-i*R-j*G;
			if(k>=0 && k%B==0) sum++;
		}
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
n, m, x = map(int, input().split())
li = list(map(int, input().split()))
left_c = 0
right_c = 0
for i in range(x, 0, -1):
  if i in li:
    left_c += 1
  
for i in range(x, n+1):
  if i in li:
    right_c += 1
    
print(min(left_c, right_c))

Measured memory_bytes: 3064
using System;
class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            char[] data = new char[line.Length];
            for (int i = 0; i < line.Length; i++)
            {   
                data[i] = 'x';
            }
            Console.WriteLine(string.Join("", data).ToString());
        }
	}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll c2(ll x) {
	return x * (x - 1) / 2;
}
void solve() {
	int n;
	scanf("%d", &n);
	ll ans = 0;
	for (int i = 1; i <= n; ++i) {
		int cou = n / i;
		ans += i * c2(cou + 1);
	}
	printf("%lld\n", ans);
}
int main() {
	solve();
}


Measured memory_bytes: 3768
coin_500 = int(input())
coin_100 = int(input())
coin_50 = int(input())

goal_money = int(input())

count = 0

if goal_money < 100:
    count = 1 if coin_50 else 0
elif goal_money < 500:
    for n_50 in range(coin_50+1):
        for n_100 in range(coin_100+1):
            sum_money = 50 * n_50 + 100 * n_100

            if sum_money == goal_money:
                count += 1
else:
    for n_50 in range(coin_50+1):
        for n_100 in range(coin_100+1):
            for n_500 in range(coin_500+1):
                sum_money = 50 * n_50 + 100 * n_100 + 500 * n_500

                if sum_money == goal_money:
                    count += 1
print(count)


Measured memory_bytes: 3064
#include <stdio.h>

int main(void) {

    int a;
    int b;
    int c;
    int tmp;

    scanf("%d %d %d", &a, &b, &c);

    if(a > b) {
        tmp = a;
        a = b;
        b = tmp;
    }

    if(b > c) {
        tmp = b;
        b = c;
        c = tmp;
    }

    if(a > b) {
        tmp = a;
        a = b;
        b = tmp;
    }

    printf("%d %d %d\n", a, b, c);

    return 0;
}

Measured memory_bytes: 596
//84104971101048411497 - Can you guess what does this mean?
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define maxN 100005
#define MOD 1000000007
#define sz(a) (int)a.size()

const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

struct point {int x, y, id;};
bool cmpX(const point &a, const point &b) {return (a.x < b.x);}
bool cmpY(const point &a, const point &b) {return (a.y < b.y);}

struct edge {int u, v, w;};
bool cmpW(const edge &a, const edge &b) {return (a.w < b.w);}

struct UFDS {
private: vector<int> pset; int n;
public:
    UFDS(int n): n(n) {
        pset.resize(n);
        fto(i, 0, n-1) pset[i] = i;
    }
    int findSet(int i) {return (pset[i] == i) ? i : pset[i] = findSet(pset[i]);}
    bool unionSet(int i, int j) {
        int p = findSet(i), q = findSet(j);
        if (p == q) return false;
        pset[p] = q;
        return true;
    }
};

int main () {
    int n; scanf("%d", &n);
    vector<edge> e;
    point p[n];
    fto(i, 0, n-1) scanf("%d%d", &p[i].x, &p[i].y), p[i].id = i;

    sort(p, p+n, cmpX);
    fto(i, 0, n-2) e.pb({p[i].id, p[i+1].id, p[i+1].x-p[i].x});
    sort(p, p+n, cmpY);
    fto(i, 0, n-2) e.pb({p[i].id, p[i+1].id, p[i+1].y-p[i].y});

    sort(e.begin(), e.end(), cmpW);

    UFDS s(n);
    int ans = 0;
    for (edge p: e) {
//        printf("%d %d %d\n", p.u, p.v, p.w);
        if (s.unionSet(p.u, p.v)) ans += p.w;
    }
    printf("%d", ans);

    return 0;
}


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

int main() {
    string s,t;
    cin >> s >> t;
    int n=s.length(); int m=t.length();
    int dp[n+1][m+1];
    
    for(int i=0; i<n+1; i++){
        for(int j=0; j<m+1; j++){
            dp[i][j]=0;
        }
    }
    for(int i=1; i<n+1; i++){
        for(int j=1; j<m+1; j++){
            if(s[i-1]==t[j-1]){
                dp[i][j]=dp[i-1][j-1]+1;
            }else{
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    int i=n,j=m;
    string ans="";
    /*for(int i=1; i<n+1; i++){
        for(int j=1; j<m+1; j++){
            cout<<dp[i][j]<< " ";
        }cout << endl;
    }*/
    while(i>0&&j>0){
        if(s[i-1]==t[j-1]){
            ans+=s[i-1];
            i--;
            j--;
        }else if(dp[i][j]==dp[i-1][j]){
            i--;
            
        }else if(dp[i][j]==dp[i][j-1]){
            j--;
        }
    }
    reverse(ans.begin(),ans.end());
    cout << ans << endl;
    
}

Measured memory_bytes: 35456
/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#pragma comment("-Wl,--stack=1024000000")
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#define eprintf(...) 0
#else
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#endif
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){int ret=1;do{if(y&1)ret=(ll)ret*x%md;x=(ll)x*x%md;}while(y>>=1);return ret;}
inline int Rand(){return rand()*32768+rand();}
string s;
string mul(string t,int k){
	vector<int>dat(t.size()+5,0);
	for(int i=0;i<t.size();i++){
		dat[i]=(t[i]-'0')*k;
	}
	for(int i=0;i<t.size()+2;i++){
		if(dat[i]>=10){
			dat[i+1]+=dat[i]/10;
			dat[i]%=10;
		}
	}
	string ret="";
	int high=t.size()+4;
	while(!dat[high])high--;
	for(int i=0;i<=high;i++)ret+=('0'+dat[i]);
	return ret;
}
int add(string t,int k){
	vector<int>dat(t.size()+5,0);
	for(int i=0;i<t.size();i++){
		dat[i]=(t[i]-'0')+k%10;k/=10;
	}
	for(int i=0;i<t.size()+2;i++){
		if(dat[i]>=10){
			dat[i+1]+=dat[i]/10;
			dat[i]%=10;
		}
	}
	return accumulate(dat.begin(),dat.end(),0);
}
bool check(int times){
	if(add(s,times)<=times)return true;
	else return false;
}
int main(){
	cin>>s;
	reverse(s.begin(),s.end());
	s=mul(s,9);
	int l=0,r=1e6;
	while(r-l>1){
		int mid=(l+r)/2;
		if(check(mid*9))r=mid;
		else l=mid;
	}
	cout<<r<<endl;
	return 0;
}

Measured memory_bytes: 3972
#include <stdio.h>

int main(void) {
    int a,b;
 
    scanf("%d %d",&a,&b);
 
    if(a%3 == 0 ||b%3 == 0 ||(a+b)%3 == 0) {
        printf("Possible\n");
    } else {
	printf("Impossible\n");
    }
}

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10**7)

def dfs(G,v):
    seen[v] = True 
    for next_v in G[v]:
        if seen[next_v]:
            continue
        dfs(G,next_v)
            
N,M = map(int,input().split())
G = [[]  for _ in range(N)]
seen= [False] * N 
cnt = 0

for i in range(M):
    x,y,z = map(int,input().split())
    G[x-1].append(y-1)
    G[y-1].append(x-1)
    
for v in range(N):
    if seen[v]:
        continue
    dfs(G,v)
    cnt += 1
    
print(cnt)    


Measured memory_bytes: 110208
#include <stdio.h>
int max(int a,int b){return a>b?a:b;}
int main(void){
    int n,ans=0,tmp=1;
    scanf("%d",&n);
    int p[n],q[n];
    for (int i=0; i<n; i++){
        scanf("%d",&p[i]);
        q[p[i]-1]=i+1;
    }
    for (int i=0; i<n-1; i++){
        if (q[i]<q[i+1]){
            tmp++;
        } else {
            ans=max(ans,tmp);
            tmp=1;
        }
    }
    printf("%d\n",n-max(ans,tmp));
    return 0;
}

Measured memory_bytes: 1664
#include<iostream> 
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <sstream>
#include <vector>
#include<math.h>

using namespace std;
#define rep(i, n) for ( int i = 0; i < ( int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < ( int)(n); i++)

int main() {
	int n, x, t;
	cin >> n >> x >> t;
	int a = n / x;
	int b = n % x;
	if(b > 0) {
		a++;
	}
	cout << a*t << endl;

	return 0;
}


Measured memory_bytes: 3560
#include<iostream>
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<cstring>
#include<climits>
#include<sstream>
#include<deque>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<bitset>
 
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
 
using namespace std;
 
typedef long long ll;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
 
 
bool check(string s,int rem) {
  map<char,int> mp;
  int n = s.size();
  rep(i,n) ++mp[s[i]];
  int cnt = 0;
  for(auto v : mp) {
    if( v.second % 2 != 0 ) ++cnt;
  }
  if( n % 2 == 0 ) {
    return cnt == 0;
  } else {
    return cnt == 1;
  }
}
 
bool compute(vector<int> &vec,int h,int w) {
  int f = ( h & 1 ) + ( w & 1 );
  if( f == 0 ) {
    int need = ( h / 2 ) * ( w / 2 );
    rep(i,(int)vec.size()) if( vec[i] ) {
      if( vec[i] % 4 ) return false;
      vec[i] /= 4;
      need -= vec[i];
    }
    return need == 0;
  } else if( f == 1 ) {

    int tw = 0;
    int fw = 0;
    rep(i,(int)vec.size()) if( vec[i] ) {
      int v = vec[i];
      int tmp = v / 4;
      fw += tmp;
      v -= tmp * 4;
      tmp = v / 2;
      tw += tmp;
      v -= tmp * 2;
      if( v ) return false;
    }
    int rem = ( h & 1 ) ? w : h;
    rem /= 2;
    while( rem - tw > 0 ) {
      --fw;
      tw += 2;
    }
    if( fw < 0 ) return false;
    return rem == tw;
  } else {
    int on = 0;
    int tw = 0;
    int fr = 0;
    rep(i,(int)vec.size()) if( vec[i] ) {
      int v = vec[i];
      int tmp = v / 4;
      fr += tmp;
      v -= tmp * 4;
      tmp = v / 2;
      tw += tmp;
      v -= tmp * 2;
      on += v;
    }
    if( on != 1 ) return false;
    int rem = ( h - 1 ) / 2 + ( w - 1 ) / 2;
    int rem4 = (int)( ( h - 1 ) / 2 ) * (int)((w-1)/2);
    if( tw > rem ) return false;
    if( tw < rem ) {
      while( rem - tw > 0 ) {
	--fr;
	if( fr < 0 ) return false;
	tw += 2;
      }
    }
    //cout << rem << " " << rem4 << endl;
    assert(rem*2+rem4*4+1 == h*w);
    return tw == rem && fr == rem4;
  }
  return true;
}
 
int main(){
  int h,w;
  cin >> h >> w;
  vector<int> vec(30,0);
  string tmp ="";
  rep(i,h) {
    string s;
    cin >> s;
    tmp += s;
    rep(j,w) ++vec[s[j]-'a'];
  }
 
  if( h == 1 || w == 1 ) {
    if( check(tmp,((h==1)?w:h)) ) {
      puts("Yes");
    } else {
      puts("No");
    }
    return 0;
  }
  puts(compute(vec,h,w)?"Yes":"No");
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
	char a[100], p[250];
	int n, k,m,count=0;
	cin >>a>> n;
	for (int i = 0; i < n; i++){
		cin >> p;
		for (int i2 = 0; i2 < strlen(p); i2++){
			m = 100;
			if (p[i2] == a[0]){
				m = i2;
				for (int i3 = 1; i3 < strlen(a); i3++){
					if (m + i3 >= strlen(p))m = i3*-1;
					if (p[m + i3] == a[i3]){}
					else {
						m = 100; break;
					}
				}
			}
			else m = 100;
			if (m != 100){
				count++; break;
			}
		}
	}
		cout << count<<endl;
}

Measured memory_bytes: 1164
// AOJ 1306
#include<iostream>
#include<map>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;

int n;
const int NMAX = 100;
int p[NMAX], t[NMAX];
int dp[NMAX][4];
const int INF = 1e6;

int quo(int a, int b) {
  return (a / b) + (a % b != 0 ? 1 : 0);
}

pair<bool,int> solve() {
  dp[0][0] = 0;

  for (int i = 0; i < n; i++) {
    for (int b = 0; b < 4; b++) {
      if (p[i] * (b+1) + p[i + 1] <= t[i+1] - t[i]) {
        dp[i+1][1] = min(dp[i+1][1], dp[i][b] + p[i] + p[i+1]);
      }
    }
    for (int b = 0; b < 3; b++) {
      if (abs(p[i+1]-p[i]) * (b+1) <= t[i+1] - t[i]) {
        dp[i+1][b+1] = min(dp[i+1][b+1], 
            dp[i][b] + abs(p[i+1] - p[i]));
      }
    }
    if (dp[i][0] == INF and dp[i][1] == INF and 
        dp[i][2] == INF and dp[i][3] == INF) {
      return make_pair(false, i);
    }
  }

  if (dp[n][0] == INF and dp[n][1] == INF and 
      dp[n][2] == INF and dp[n][3] == INF) {
    return make_pair(false, n);
  }
  int mim = min(dp[n][0], min(dp[n][1], min(dp[n][2], dp[n][3])));
  return make_pair(true, mim + p[n]);
}

void init() {
  REP(i, n + 3) {
    p[i] = t[i] = 0;
  }
  REP(i,n + 3) REP(b,4) {
    dp[i][b] = INF;
  }
}

int main() {
  while (cin >> n and n) {
    init();
    for (int i = 1; i <= n; i++) { cin >> p[i] >> t[i]; }
    pair<bool,int> ans = solve();

/*    REP(i, n+1) {
      REP(b, 4) {
        cout << dp[i][b] << "\t";
      }
      cout << endl;
    }
*/
    cout << (ans.first ? "OK " : "NG ") << ans.second << endl;
  }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) ((x)&(-x))
typedef long long LL;

int d[5005];

void run_case() {
    int k, q;
    cin >> k >> q;
    for(int i = 0; i < k; ++i) cin >> d[i];
    while(q--) {
        int n, x, m;
        cin >> n >> x >> m;
        x %= m;
        LL sum = 0, zero = 0;
        for(int i = 0; i < k; ++i) {
            sum += (d[i] % m);
            zero += (d[i] % m == 0);
        }
        LL large = 1LL*((n-1)/k)*sum;
        zero = zero*((n-1)/k);
        for(int i = 0; i < n-1-((n-1)/k)*k; ++i) {
            large += (d[i] % m);
            zero += (d[i] % m == 0);
        }
        cout << n-1-(large+x)/m-zero << "\n";
    }

}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cout.flags(ios::fixed);cout.precision(10);
    run_case();
    cout.flush();
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rp(i,k,n) for(int i=(k); i<(n); i++)
int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int maxx = max({a, b, c});
  if(a==maxx){
    rp(i,0,k){
      maxx = maxx * 2;
    }
    int sum = maxx + b + c;
    cout << sum << endl;
  }
  if(b==maxx){
    rp(i,0,k){
      maxx = maxx * 2;
    }
    int sum = maxx + a + c;
    cout << sum << endl;
  }
  if(c==maxx){
    rp(i,0,k){
      maxx = maxx * 2;
    }
    int sum = maxx + a + b;
    cout << sum << endl;
  }
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n,i,temp,tot=0;
    cin>>n;
    ll arr[n];
    map<ll,ll> m1,m2,m3;
    map<ll,ll>::iterator it;
    for(i=0;i<n;i++){
        cin>>arr[i];
        m1[arr[i]]+=1;
    }
    for(it=m1.begin();it!=m1.end();it++){
        temp=it->second;
        tot+=(temp*(temp-1))/2;
        m3[it->first]=(temp*(temp-1))/2;
        temp-=1;
        m2[it->first]=(temp*(temp-1))/2;
    }
    for(i=0;i<n;i++)
        cout<<tot-m3[arr[i]]+m2[arr[i]]<<endl;
    return 0;
}


Measured memory_bytes: 26880
#include <stdio.h>
#define NUM 3
int main(void)
{
    int a,b,c;
    int d,e,f;
    int test[NUM];
   
    scanf("%d %d %d",&a,&b,&c);
    test[0] = a;
    test[1] = b;
    test[2] = c;
    {
        for(d=0; d<NUM-1; d++){
            for(e=d+1; e<NUM; e++){
                if(test[d] > test[e]){
                    f = test[d];
                    test[d] = test[e];
                    test[e] = f;
                }
            }
        }
    }
    printf("%d %d %d\n", test[0], test[1], test[2]);
    return 0;
}


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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	int a[n],f=1;
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
		if (a[i]%2==1)
		{
			f=0;
		}
	}
	if (f)
	{
		cout<<"second\n";
	}
	else
	{
		cout<<"first\n";
	}
	return 0;
}

Measured memory_bytes: 640
from bisect import bisect_left, bisect_right

N = int(input())
A = list(map(int, input().split()))

A.sort()

ans = 0
for a in range(100000):
    k = bisect_right(A, a+2) - bisect_left(A, a)
    ans = max(ans, k)

print(ans)

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

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    int i, j;
    for(i = 0; i < n; i++){
        cin >> a.at(i);
    }
    int ans = 0;
    for(int x : a){
        if(x >= k){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 1000000007
using namespace std;
using ll = long long;
using ldb = long double;

vector<pair<pair<int, int>, pair<int, ll>>> q;
ll scores(vector<int>& X) {
    int Q = q.size();
    ll res = 0;
    for (int i = 0; i < Q; i++) {
        int a = q[i].first.first-1, b = q[i].first.second-1, c = q[i].second.first;
        ll d = q[i].second.second;
        if (X[b] - X[a] == c) res += d;
    }
    return res;
}

vector<int> arr(vector<int> X,int M){
    int N = X.size();
    vector<int> Y(N);
    int id = -1;
    for (int i = N - 1; i >= 0; i--) {
        if (X[i] != M) {
            id = i;
            break;
        }
    }
    if (id == -1) return Y;
    for (int i = 0; i < id; i++) Y[i] = X[i];
    Y[id] = X[id] + 1;
    for (int i = id + 1; i < N; i++) Y[i] = Y[id];
    return Y;
}
int main() {
    int N, M, Q;
    cin >> N >> M >> Q;
    q = vector < pair<pair<int, int>, pair<int, ll>>>(Q);
    for (int i = 0; i < Q; i++)
        cin >> q[i].first.first >> q[i].first.second >> q[i].second.first >> q[i].second.second;
    vector<int> X(N, 1);
    //stack<vector<int>> st;
    ll ans = 0;
    while (X[0]!=0) {
        ans = max(ans, scores(X));
        X = arr(X, M);       
        //cout << ans << endl;
        //for (int i = 0; i < X.size(); i++)cout << X[i] << " ";
        //cout << endl;
    }
   
    cout << ans << endl;
}

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

int main () {
  ll X;
  cin >> X;

  ll deposit = 100;
  int count = 0;
  while (1) {
    deposit *= 1.01;
    count++;
    if (X <= deposit) {
        cout << count;
        return 0;
    }
  }
}

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

int main() {
    string S;
    int N, K, A;
    cin >> N >> K >>S;
    A = K -1;
    if (S.at(A) == 'A'){
        S.at(A) = 'a';
    }
    else if (S.at(A) == 'B'){
        S.at(A) = 'b';
    }
    else if (S.at(A) == 'C'){
        S.at(A) = 'c';
    }
    cout << S <<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
int main(void){
    ll N ;
    cin >> N ;
    ll a[N] ;
    ll cnt  = 0 ;
    for(int i = 0; i < N ; i++){
        cin >> a[i] ;
        if(a[i] %2 != 0){
            if(i % 2 == 0){
                cnt++ ;
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)
char mp1[100][100];
char mp2[100][100];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  int n,m; cin>>n>>m;
  rep(i,n) {
    string t;cin>>t;
    rep(j,n) mp1[i][j] = t[j];
  }
  rep(i,m) {
    string t;cin>>t;
    rep(j,m) mp2[i][j] = t[j];
  }
  rep(i,n-m+1) {
    rep(j,n-m+1) {
      rep(ii,m) {
        rep(jj,m) {
          if(mp1[i+ii][j+jj]!=mp2[ii][jj]) goto NEXT;
        }
      }
      cout << "Yes" << endl;
      return 0;
      NEXT:;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#define _GIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double EPS = 1e-10;


int main(void) {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;

  ll num1 = max(a * c, a * d);
  ll num2 = max(b * c, b * d);

  ll ans = max(num1, num2);

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

Measured memory_bytes: 3648
# nまでの自然数が素数かどうかを表すリストを返す
def makePrimeChecker(n):
	isPrime = [True] * (n + 1)
	isPrime[0] = False
	isPrime[1] = False
	for i in range(2, int(n ** 0.5) + 1):
		if isPrime[i]:
			for j in range(i * i, n + 1, i):
				isPrime[j] = False
	return isPrime



isPrime = makePrimeChecker(100000)
Q = int(input())
L=[0]

#2017nunberの累積和
for i in range(1, 100000):
	if i&1==1 and isPrime[i] and isPrime[(i+1)//2]:
		L.append(L[-1]+1)
	else:
		L.append(L[-1])

for i in range(Q):
	l, r = map(int, input().split())
	print(L[r] - L[l-1])


Measured memory_bytes: 80532
#include <iostream>

bool
is_echo(const std::string &s) {
    const int sz = s.length();
    if (0 != (sz & 0x01)) return false;

    const int wsz = sz / 2;
    for( int i = 0; i < wsz; i++) {
        if (s[i] != s[i + wsz]) return false;
    }
    return true;
}

int
main(int argc, char** argv) {
    int n;
    std::string s;

    std::cin >> n;
    std::cin >> s;
    std::printf("%s\n", is_echo(s) ? "Yes" : "No");
    return 0;
}



Measured memory_bytes: 384
#pragma GCC optimize "03"
#include "bits/stdc++.h"
using namespace std;
 
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;

int a[N], dp[102][N];
 
signed main() {
	IOS;
	#ifdef LOCAL
		freopen("input.txt","r", stdin);
		freopen("output.txt","w",stdout);
	#endif
	int n, k;
	cin >> n >> k;
	dp[0][0] = 1;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		for(int j = 0; j <= k; j++){
			dp[i][j] += dp[i-1][j];
			dp[i][j] %= mod;
			if(j+a[i]+1 <= k)
				dp[i][j+a[i]+1] = (dp[i][j+a[i]+1] - dp[i-1][j] + mod) % mod;
		}
		for(int j = 1; j <= k; j++){
			dp[i][j] += dp[i][j-1];
			dp[i][j] %= mod;
		}
	}
	cout << dp[n][k];
	return 0;
}

Measured memory_bytes: 79360
n,m=io.read("*n","*n","*l")
t={}
for i=1,m do
    x=io.read()
    p,s=x:match("(%d+) (%u+)")
    if not t[p] then
        t[p]={}
    end
    table.insert(t[p],s)
end

ac_counter=0
wa_counter=0
for k in pairs(t) do
    for i=1,#t[k] do
        if t[k][i]=="AC" then
            ac_counter=ac_counter+1
            wa_counter=wa_counter+i-1
            break
        end
    end
end

print(ac_counter.." "..wa_counter)

Measured memory_bytes: 15524
#include <stdio.h>

int main(void) {
  int a, b, c, ct;

  while (scanf("%d %d", &a, &b) != EOF) {
    ct = 0;
    c = a + b;
    while (c != 0) {
      c /= 10;
      ct++;
    }
    printf("%d\n", ct);
  }
  return (0);
}

Measured memory_bytes: 596
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class Diverta_1 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int K = in.nextInt();

            out.println(N - (K - 1));

        }

    }
}



Measured memory_bytes: 23252
#include<iostream>
using namespace std;
int main()
{
    int a,b,c,k,sum=0;
    cin>>a>>b>>c>>k;
    if(k<=a) sum=k;
    else if(k<=a+b) sum=a;
    else sum=a-(k-a-b);
    cout<<sum;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int n;
    cin >> n;
    int cnt = 0;
    for(int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if(a&1) cnt++;
    }
    if(cnt&1) cout << "NO";
    else cout << "YES";
}

Measured memory_bytes: 256
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_B&lang=jp
#  Queue : python3
#  2018.11.26 yonezawa

from collections import deque
import sys
input = sys.stdin.readline

def calc(t,q):
    tq = deque()
    counter = 0
    while len(q) > 0:
#        print ("count",counter,q)
        (i1,i2) = q.popleft()
        if (i2 > t):
            i2 = i2 - t
            q.append((i1,i2)) 
            counter = counter + t
        else:
            i2 = counter + i2
            tq.append((i1,i2))
            counter = i2
    return tq
def main():
    (n,t) = map(int,input().split())
    q = deque()
    for i in range(n):
        (a,b) = map(str,input().split())
        q.append((a,int(b)))
    for a,b in calc(t,q):
        print (a,b)
if __name__ == '__main__':
    main()


Measured memory_bytes: 14068
#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;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

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);

    int A, B, C;
    cin >> A >> B >> C;

    int t = A;
    while(t <= 100000) {
        if(t % B == C) {
            cout << "YES" << endl;
            return 0;
        }
        t += A;
    }
    cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 256
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

A, B, C, D = [int(x) for x in stdin.readline().rstrip().split()]

A -= 1
z = (C*D) // fractions.gcd(C, D)

b_num = B - (B // C + B // D - B // (C*D))
a_num = A - (A // C + A // D - A // (C*D))

b_num2 = B // z - B // (C*D)
a_num2 = A // z - A // (C*D)



print(b_num - a_num + (b_num2 - a_num2))

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

int main() 
{
	long long x;
	scanf("%lld", &x);
	long long t = 100;
	int i;
	for (i = 0; t < x; ++i) t += t / 100;
	printf("%d\n", i);
	return 0;
}


Measured memory_bytes: 1732
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9+7
MAX = 10**18
MIN = -10**18

n,k= map(int,input().split())
d = list(map(int,input().split()))
able = [True]*10
for i in range(k):
    able[d[i]] = False
use = []
for i in range(len(able)):
    if able[i] == True:
        use.append(i)
flag = False
while True:
    s = str(n)
    for i in range(len(s)):
        c = int(s[i])
        if c in use:
            flag = True
        else:
            flag = False
            break
    if flag:
        print(n)
        sys.exit()
    n += 1

Measured memory_bytes: 3316
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.buffer.readline

n, m, q = [int(i) for i in input().strip().split()]
abcd = []
canditates = []
ans = 0


for _ in range(q):
    abcd.append([int(i) for i in input().strip().split()])


def helper(_min, _max, cur, res):
    if res == 0:
        canditates.append(list(cur))
    else:
        for i in range(_min, _max):
            cur.append(i)
            helper(i, _max, cur, res - 1)
            cur.pop()


helper(1, m + 1, [], n)

for A in canditates:
    _temp = 0
    for a, b, c, d in abcd:
        if A[b - 1] - A[a - 1] == c:
            _temp += d

    ans = max(ans, _temp)

print(ans)


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

int main()
{
    int n;
    cin >> n;
    vector<long> a(n + 1);
    vector<long> b(n);
    for (int i = 0; i < n + 1; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    long ans = 0;
    for (int i = 0; i < n; i++) {
        long n = min(a[i], b[i]);
        a[i] -= n;
        b[i] -= n;
        ans += n;
        n = min(a[i + 1], b[i]);
        a[i + 1] -= n;
        b[i] -= n;
        ans += n;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
""" ABC070D Transit Tree Path
"""
from collections import deque
from heapq import heapify, heappop, heappush, heappushpop


class PriorityQueue:
    """
    優先度付きキューの
    """
    def __init__(self, heap):
        self.heap = heap
        heapify(self.heap)
    
    def push(self, item):
        heappush(self.heap, item)
    
    def pop(self):
        return heappop(self.heap)
    
    def pushpop(self, item):
        return heappushpop(self.heap, item)
    
    def __call__(self):
        return self.heap
    
    def __len__(self):
        return len(self.heap)


N = int(input())
G = [[] for _ in range(N)]
for _ in range(N-1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append((b, c))
    G[b].append((a, c))

Q, K = map(int, input().split())
INF = float("inf")


def dijkstra(adj: list, s: int):
    Color = [0]*N # 0: 未訪問 1: Seen 2: Visited
    D = [INF]*N #始点からの距離(重み)
    P = [None]*N #親

    D[s] = 0
    P[s] = None
    PQ = PriorityQueue([(0, s)]) #(Cost, Node)を格納し、PQにする。

    while PQ: # PQに候補がある限り

        min_cost, u = PQ.pop() # 最小コストなノードu

        Color[u] = 2 # uをVisitedに。

        if D[u] < min_cost:
            # 更新の必要なし.
            continue

        for adj_idx, adj_w in adj[u]:
            if Color[adj_idx] != 2: #訪問済みでないなら
                if D[u] + adj_w < D[adj_idx]: #最小コストを更新できるなら、
                    D[adj_idx] = D[u] + adj_w
                    P[adj_idx] = u
                    # PQに(隣接要素のコスト, 隣接要素の番号)を容れる
                    PQ.push((D[adj_idx], adj_idx))
                    Color[adj_idx] = 1
    
    return D, P

D, P = dijkstra(G, s=K-1)
for q in range(Q):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    print(D[x]+D[y])

Measured memory_bytes: 108144
import java.util.Scanner;

public class Main {
  static Scanner sc = new Scanner(System.in);
  static final long MOD = 998244353;

  public static void main(String[] args) {
    char[] S = sc.next().toCharArray();
    int N = S.length;
    boolean all = true;
    boolean any = false;
    int sum = S[N - 1] - '0';
    for (int i = 0; i < N - 1; i++) {
      if (S[i] != S[i + 1]) {
        all = false;
      } else {
        any = true;
      }
      sum += S[i] - '0';
    }
    sum %= 3;
    if (all) {
      System.out.println(1);
      return;
    }
    if (N == 2) {
      System.out.println(2);
      return;
    }
    if (N == 3 && !any && S[0] != S[2]) {
      System.out.println(3);
      return;
    }
    long[][][] dp = new long[3][3][N];
    for (int i = 0; i < 3; i++) {
      dp[i][i][0] = 1;
    }
    for (int i = 0; i < N - 1; i++) {
      for (int j = 0; j < 3; j++) {
        for (int k = 0; k < 3; k++) {
          for (int l = 0; l < 3; l++) {
            if (l == k) continue;
            dp[(j + l) % 3][l][i + 1] += dp[j][k][i];
            if (dp[(j + l) % 3][l][i + 1] >= MOD) dp[(j + l) % 3][l][i + 1] -= MOD;
          }
        }
      }
    }
    long ans = 1;
    for (int i = 0; i < N - 1; i++) {
      ans *= 3;
      ans %= MOD;
    }
    for (int i = 0; i < 3; i++) {
      ans += MOD - dp[sum][i][N - 1];
    }
    if (!any) ++ans;
    System.out.println(ans % MOD);
  }

}


Measured memory_bytes: 53060
N, Q = map(int, input().split())
S = "*" + input()

ac_cum_count = [0] * (N+1)
for i in range(1, N):
    if S[i] == "A" and S[i+1] == "C":
        ac_cum_count[i+1] = ac_cum_count[i] + 1
    else:
        ac_cum_count[i+1] = ac_cum_count[i]

for q in range(Q):
    l, r = map(int, input().split())
    ans = ac_cum_count[r] - ac_cum_count[l]
    print(ans)
    

Measured memory_bytes: 57304
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    s=chomp(readline())
    first=parseInt(s[1:2])
    second=parseInt(s[3:4])
    if 0<first<13
        if 0<second<13
            println("AMBIGUOUS")
        else
            println("MMYY")
        end
    elseif 0<second<13
        println("YYMM")
    else
        println("NA")
    end
end
main()

Measured memory_bytes: 107644
/***********************************************************
 *This code By @1353055672(Ligen)                          *
 *[Warning]You're not excepted to understand this code!    *
 *CSP-S 2019 RP++                                          *
 ***********************************************************/
//#pragma GCC optimize(3)
#define ADD_STACK int size = 512 << 20;\
	char *pp = (char*)malloc(size) + size;  \
	__asm__("movl %0, %%esp\n" :: "r"(pp))
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<fstream>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<bitset>
#include<ctime>
#include<vector>
#define ll long long
#define ull unsigned long long
#define mn 200020
#define Max(x,y) (((x)>(y))?(x):(y))
#define Min(x,y) (((x)<(y))?(x):(y))
#define Abs(x) (((x)<(0))?(-(x)):(x))
#define infll (ll)(1e18)
#define infint (1<<30)
#define mod (int)(1e9+7)
#define FOR(a,b,c) for (register int a=b;a<=c;++a)
#define FORD(a,b,c) for (register int a=b;a>=c;--a)
using namespace std;
//char buf[1<<20],*p1=buf,*p2=buf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++)
inline ll read(){
	ll x=0,f=1;char c;
	for(c=getchar();c<'0'||c>'9';f=((c=='-')?-1:f),c=getchar());
	for(;c>='0'&&c<='9';x=x*10+c-'0',c=getchar());
	return x*f;
}
template<typename T>
inline void write(T a){
	if(a==0){putchar('0');return;}if(a<0)putchar('-'),a=-a;char c1[120];int h=0;
	while(a)c1[++h]=a%10+'0',a/=10;FORD(i,h,1)putchar(c1[i]);
}
inline void write_(){return;}
template<typename T,typename... Args>
inline void write_(T a,Args... b){write(a);putchar(' ');write_(b...);}
inline void writeln(){putchar('\n');return;}
template<typename T,typename... Args>
inline void writeln(T a,Args... b){write(a);putchar(' ');writeln(b...);}
//need c++11

//inline void write(ll a){
//    if(a==0){putchar('0');return;}if(a<0)putchar('-'),a=-a;char c1[120];int h=0;
//    while(a)c1[++h]=a%10+'0',a/=10;FORD(i,h,1)putchar(c1[i]);
//}
//inline void write_(ll a){write(a);putchar(' ');}
//inline void writeln(ll a){write(a);putchar('\n');}
inline ll gcd(ll a,ll b){return a==0?b:gcd(b%a,a);}
inline ll lcm(ll a,ll b){return 1ll*a/gcd(a,b)*b;}
inline ll Pow(ll n,ll a){ll b=1;while(a){if(a&1)b=1ll*b*n%mod;n=1ll*n*n%mod;a>>=1;}return b;}
//---------------------Head Files--------------------------//
char s[1020];
signed main(){
#ifdef LOCAL_LIGEN
	// freopen("0.in","r",stdin);
	// freopen("0.out","w",stdout);
	double be=clock();
#endif
	scanf("%s",s+1);
	int n=strlen(s+1);
	FOR(i,1,n){
		// if(s[i]!='U'||s[i]!='D'){
			if((i&1)&&(s[i]!='R'&&s[i]!='U'&&s[i]!='D'))return puts("No"),0;
			if(!(i&1)&&(s[i]!='L'&&s[i]!='U'&&s[i]!='D'))return puts("No"),0;
		// }
	}
	puts("Yes");
#ifdef LOCAL_LIGEN
	double en=clock();
	printf("Time: %.0lfms\n",en-be);
	fclose(stdin);fclose(stdout);
#endif
	return 0;
}

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

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


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

int main(){
 int n;
 
 while(1){
  cin >> n;
  if(n==0) break;

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

  int min = 1000000;
  for(int j=0; j<n-1; j++){
   for(int i=j+1; i<n; i++){
    if(a[j]>=a[i] && a[j]-a[i]<min){
     min = a[j]-a[i];
    }else if(a[j]<a[i] && a[i]-a[j]<min){
     min = a[i]-a[j];
    }
   }
  }

  cout << min <<endl;
 }

 return 0;
}

 

Measured memory_bytes: 3076
// -*- coding:utf-8-unix -*-

use proconio::input;
use std::collections::HashSet;

fn main() {
    input! {
        n: usize,
        m: usize,
    }

    let mut ball_num = vec![1; n + 1];
    let mut hs = HashSet::new();
    hs.insert(1);
    for _ in 0..m {
        input! {
            x: usize,
            y: usize,
        }

        if hs.contains(&x) {
            hs.insert(y);
            ball_num[x] -= 1;
            ball_num[y] += 1;
            if ball_num[x] == 0 {
                hs.remove(&x);
            }
        } else {
            ball_num[x] -= 1;
            ball_num[y] += 1;
        }
    }
    println!("{}", hs.len());
}


Measured memory_bytes: 5420
def gs() STDIN.gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end
 
def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

n,x = gsmi
xs = gsmi

subs = Array.new(n){|i| (xs[i]-x).abs }

def gcd(x,y)
    while y!=0
      x,y=y,x%y
		end
    return x
end

puts subs.inject(subs[0]){|ret,n| gcd(ret,n) }

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

#define mod 1'000'000'007
typedef long long ll;

template<typename T>
void deb(initializer_list<T> l)
{
	for (auto &e : l)
		cout << e << ' ';
	cout << endl;
}

void solve()
{
	int a[6];
	for (int i = 1; i <= 5; ++i)
		cin >> a[i];
	for (int i = 1; i <= 5; ++i)
		if (!a[i])
			cout << i;
}

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

	int t = 1;
	// cin >> t;
	while (t--)
		solve();

	return 0;
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

int n,a[50],ans;
bool f=true;

signed main() {
    cin >> n;
    rep(i,n) cin >> a[i];
    while(f) {
        f = false;
        int sum = 0;
        rep(i,n) sum += a[i]/n;
        rep(i,n) {
            int tmp = a[i]/n;
            a[i] += sum-a[i]/n*(n+1);
        }
        ans += sum;
        rep(i,n) if (a[i] >= n) f = true;
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b+1;i++)
#define Per(i,b,a) for(int i=b;i>=a;i--)
int main(){
    string S;
    cin>>S;
    if(S[2]==S[3] && S[4]==S[5]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
require 'prime'
n, p = gets.chomp.split(" ").map(&:to_i)

gcd = p.prime_division.select{|array| array[1] >= n}.flatten.first

while gcd && a = (p / gcd ** n).prime_division.select{|array| array[1] >= n}.flatten.first do
  gcd = gcd * a
end

puts gcd || 1

Measured memory_bytes: 2300
#include <stdio.h>

int main(void){
	int n,k;
	scanf("%d%d", &n, &k);
	int a[100005];
	for(int i=0; i<n; i++){
		scanf("%d", &a[i]);
	}

	int count=0;
	count += (n-1)/(k-1);
	if((n-1) % (k-1) != 0)count++;
	printf("%d\n",count);
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(void){
	int prime[10002];
	int sum[10002];
	prime[1] = 2;
	prime[2] = 3;
	sum[1] = 2;
	sum[2] = 5;
	int ptr=3;
	for(int num=5; ptr<=10000; num++){
		bool f = false;
		for(int i=1; i<ptr; i++){
			if(num%prime[i]==0) {
				f = true;
				break;
			}
		}
		if(!f) {
			prime[ptr++] = num;
			sum[ptr-1] = sum[ptr-2] + prime[ptr-1];
		}
	}
	int n;
	while(cin >> n){
		if(!n) break;
		cout << sum[n] << endl;
	}
	return 0;
}

Measured memory_bytes: 824
#include<iostream>

int main() {
	int K;
	int A, B;
	bool dochi = false;
	std::cin >> K;
	std::cin >> A >> B;
	for (int i = A; i < B + 1; i++) {
		if (i % K == 0) {
			dochi = true;
			break;
		}
	}
	if (dochi == true) {
		std::cout << "OK" << std::endl;
	}
	else {
		std::cout << "NG" << std::endl;
	}
}

Measured memory_bytes: 3620