akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int N = sc.nextInt();
		int power[] = new int[N];
		int totalPower = 0;

		for(int i = 0 ;i <= N-1 ;i++) {
			power[i] = sc.nextInt();
			totalPower = totalPower + power[i];
		}
		System.out.println((totalPower>=H)? "Yes":"No");
	}
}



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

int n, m, q;

int a[52], b[52], c[52], d[52];

int ans = 0;

void dfs(int k[], int i){
    if(i == n){
        int s = 0;
        for(int j = 0; j < q; j++){
            if(k[b[j]] - k[a[j]] == c[j]) s += d[j];
        }
        ans = max(ans, s);
        return;
    }
    int j = 1;
    if(i) j = k[i - 1];
    for(; j <= m; j++){
        k[i] = j;
        dfs(k, i + 1);
    }
}

int main()
{
    cin >> n >> m >> q;
    for(int i = 0; i < q; i++){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--; b[i]--;
    }
    int k[12]{0};
    dfs(k, 0);
    cout << ans << endl;
}


Measured memory_bytes: 3624
from collections import deque
n,m = map(int,input().split())
g = [[] for i in range(n)]
h = [[] for i in range(n)]
for i in range(m):
  x,y = map(int,input().split())
  x-=1;y-=1
  g[x].append(y)
  h[y].append(x)
topo = []
hukasa = [0] * n
hairu = [0]*n
que = deque([])
for i in range(n):
  hairu[i] = len(h[i])
  if hairu[i] == 0:
    topo.append(i)
    que.append(i)
def dfs(x):
  for i in g[x]:
    hairu[i]-=1
    if hairu[i] == 0:
      topo.append(i)
      que.append(i)
while que:
  x = que.popleft()
  dfs(x)
def dfs2(x):
  for i in g[x]:
    hukasa[i] = max(hukasa[i],hukasa[x]+1)
for i in topo:
  dfs2(i)
print(max(hukasa))
  

Measured memory_bytes: 76080
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

vector<vector<ll>> com(ll n, ll r)
{
    const long long _MOD = 1000000007;
    vector<vector<ll>> v(n + 1, vector<ll>(n + 1, 0));
    ll tmp = v.size();
    for (int i = 0; i < tmp;i++){
        v[i][0] = 1;
        v[i][i] = 1;
    }
    for (int j = 1; j < tmp;j++){
        for (int k = 1; k < j;k++){
            v[j][k] = v[j - 1][k - 1] + v[j - 1][k];
            if (v[j][k] > _MOD)
                v[j][k] %= _MOD;
        }
    }
    return v;
}

int main(){
    ll N, K;
    ll div_N = 1000000007;

    cin >> N >> K;
    vector<vector<ll>> v(2019, vector<ll>(2019, 0));
    ll tmp = K;
    if(N - K + 1 < K)
        tmp = N - K + 1;
    v = com(2019,2019);
    for (int i = 1; i <= K; i++)
    {
        ll ans = v[N - K + 1][i] * v[K - 1][i - 1];
        if(ans > div_N)
            ans %= div_N;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 64128
#include <iostream>

using namespace std;

int main() {

    int N,count1=0,count2=0,count3=0;
    cin>>N;
    int a[N];
    for(int i=0;i<N;i++){

        cin>>a[i];

    }

    while(count2==0) {

        for (int i = 0; i < N; i++) {

            if (a[i] % 2 == 0)count1++;

        }
        if (count1 == N) {

            for (int i = 0; i < N; i++) {

                a[i] /= 2;


            }
            count3++;
            count1=0;

        } else {

            count2++;

        }
    }
    cout<<count3<<endl;
    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 400005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
    	if(c == '-') f = -1;
    	c = getchar();
    }
    while(c >= '0' && c <= '9') {
    	res = res * 10 +c - '0';
    	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
    	out(x / 10);
    }
    putchar('0' + x % 10);
}
int N;
pii p[MAXN];
multiset<int> sb,sr;
void Solve() {
    read(N);
    int x,y;
    for(int i = 1 ; i <= N ; ++i) {
        read(x);read(y);
        if(x > y) swap(x,y);
        p[i] = mp(x,y);
        sb.insert(x);sr.insert(y);
    }
    sort(p + 1,p + N + 1);
    int64 ans = 1e18;
    for(int i = 1 ; i <= N ; ++i) {
        int a = *(--sr.end()) - *sr.begin();
        int b = *(--sb.end()) - *sb.begin();
        ans = min(ans,1LL * a * b);
        sr.erase(sr.find(p[i].se));
        sr.insert(p[i].fi);
        sb.erase(sb.find(p[i].fi));
        sb.insert(p[i].se);
    }
    out(ans);enter;
}
int main() {
    Solve();
}

Measured memory_bytes: 23864
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include<math.h>
using namespace std;
#define int long long
#define m_p make_pair
#define mod 1000000007
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define all(v)  v.begin(),v.end()
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>vec[i];
using namespace std;

int jousu(int, int);
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int kurai(int x00, int y00) {
	int z00 = (x00 % jousu(10, y00)) / jousu(10, y00 - 1);
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}



signed main() {
	int n, a, b,ans;
	cin >> n >> a >> b;
	ans = n / (a + b) * a;
	ans += min(n % (a + b), a);
	cout << ans << endl;
}


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

using namespace std;

int main() {
    string s,t;
    cin>>s>>t;
    int n = s.size(),m = t.size();
    vector<vector<int>> dp(n+1, vector<int>(m+1, 0));
    string res;
    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;
    while(i>0&&j>0) {
            if(s[i-1] == t[j-1]){
                res = s[i-1]+ res;
                j--;i--;
            } else {
                if(dp[i][j-1] < dp[i-1][j]){
                    i--;
                } else {
                    j--;
                }
            }
    }
    cout<<res<<endl;
}


Measured memory_bytes: 35584
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<set>

int main() {
	int s;
	cin >> s;
	int l, r;
	r = s % 100;
	l = (s - r)/100;
	if (r == 0) {
		if (l == 0 || l >= 13)cout << "NA";
		else cout << "MMYY";
	}
	else if (l==0) {
		if (r >= 13)cout << "NA";
		else cout << "YYMM";
	}
	else if (r >= 13 && l <= 12) {
		cout << "MMYY";
	}
	else if (r <= 12 && l >= 13) {
		cout << "YYMM";
	}
	else if (r >= 13 && l >= 13){
		cout << "NA";
	}
	else{
		cout << "AMBIGUOUS";
	}

	return 0;
}

Measured memory_bytes: 3600
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
import sys
gcd = math.gcd

n = ni()
xpy = []
xmy = []
for i in range(n):
    x,y = ma()
    xpy.append(x+y)
    xmy.append(x-y)
xpy.sort()
xmy.sort()
a1=abs(xpy[0]-xpy[-1])
a2 = abs(xmy[0]-xmy[-1])
print(max(a1,a2))


Measured memory_bytes: 102932
#include <bits/stdc++.h>
using namespace std;
int l,r;
int min1=(int)1e9;
int main()
{
	//std::ios::sync_with_stdio(false);
	cin>>l>>r;
	for(int i=l;i<=r-1;++i)
		for(int j=l+1;j<=r;++j)
		{
			if(i % 2019 == 0 || j % 2019 == 0)
			{
				min1 = 0;
				cout << min1 << endl;
				return 0;
			}
			else	
				min1=min(min1,(((i%2019)*(j%2019))%2019));
		}
	cout<<min1<<endl;
	return 0;
}

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


int gcd(int a,int b){
  if (a>b) swap(a,b);
  if (a==0) return b;
  return gcd(b%a,a);
}


int main(void){
  int n,i,a,d;
  
  cin >> n;
  for (i=0;i<n;i++){
    cin >> a;
    d=gcd(d,a);
  }
  
  cout << d << endl;
  
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		static readonly int mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			//string s = Console.ReadLine();
			//int n = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
			int n = vs[0];
			int k = vs[1];
			int[] h = Console.ReadLine().Split().Select(int.Parse).OrderByDescending(p => p).ToArray();
			long ans = 0;
			for (int i = k; i < n; i++) {
				ans += h[i];
			}
			Console.WriteLine(ans);


			Console.Out.Flush();
		}
	}
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
ll K;
int A[202020];
int is[202020];

int first[202020];
int nex[202020];
int idnex[202020];
int pat[202020];
int ne[202020][45];


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K;
	MINUS(first);
	FOR(i,N) {
		cin>>A[i];
		if(first[A[i]]==-1) first[A[i]]=i;
	}
	
	for(i=1;i<=200000;i++) nex[i]=N;
	for(i=N-1;i>=0;i--) {
		idnex[i]=nex[A[i]];
		nex[A[i]]=i;
	}
	pat[N]=0;
	for(i=N-1;i>=0;i--) {
		if(idnex[i]==N) {
			pat[i]=first[A[i]]+1;
		}
		else {
			pat[i]=pat[idnex[i]+1];
		}
	}
	/*
	FOR(i,N) cout<<pat[i]<<" ";
	cout<<endl;
	*/
	FOR(i,N+1) ne[i][0]=pat[i];
	int cur=0;
	K--;
	FOR(i,42) {
		FOR(j,N+1) ne[j][i+1]=ne[ne[j][i]][i];
		if(K&(1LL<<i)) cur=ne[cur][i];
	}
	
	
	vector<int> V;
	//cout<<"!"<<cur<<" "<<pat[cur]<<endl;
	for(i=cur;i<N;i++) {
		if(is[A[i]]) {
			while(V.back()!=A[i]) {
				is[V.back()]=0;
				V.pop_back();
			}
			is[A[i]]=0;
			V.pop_back();
		}
		else {
			is[A[i]]=1;
			V.push_back(A[i]);
		}
	}
	FORR(v,V) cout<<v<<" ";
	cout<<endl;
	/*
	while(K--) {
		FOR(i,N) {
			if(is[A[i]]) {
				while(V.back()!=A[i]) {
					is[V.back()]=0;
					V.pop_back();
				}
				is[A[i]]=0;
				V.pop_back();
			}
			else {
				is[A[i]]=1;
				V.push_back(A[i]);
			}
		}
		FORR(v,V) cout<<v<<" ";
		cout<<endl;
	}
	*/
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 42612
#include <iostream>
 #include <math.h>
 #include <iomanip>

 int main(){
 int R;
 std::cin>>R;
 const double pi=acos(-1.0);

 double answer=2*R*pi;

 std::cout<<std::setprecision(20)<<std::fixed<<answer<<std::endl;
return 0;
 }

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

int main() {
  int p, q, r, a;
  cin >> p >> q >> r;
  
  a = p + q;
  if(a > (p + r))
    a = p + r;
  if(a > (q + r))
    a = q + r;

  cout << a << endl;
  return 0;
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1073741824
#define ll long long
#define PI (2*acos(0.0))
#define Hare printf("here\n")
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define x first
#define y second
#define on(val,pos) val|(1<<pos)
#define off(val,pos) val&(~(1<<pos))
#define check(val,pos) (val&(1<<pos))

//first four adjacent,second four corner
//int row[8]={0,-1,0,1,1,-1,-1,1};
//int col[8]={-1,0,1,0,-1,-1,1,1};
using namespace std;

int main(){
    int i,j,k,n,m,val,t=0,cnt,test;
    //freopen("000input.txt","r",stdin);
	cin>>k>>m;

  cnt=0;
  int ans=1;
  int p=0,q=0;
  while(cnt<100000){
  	ans++;
    p=ans*0.08;
    q=ans*0.1;
    cnt++;
    if(p==k and q==m)break;
  }

  if(cnt<100000)cout<<ans<<endl;
  else cout<<-1<<endl;
    //free();   //if pointer array
    return 0;
}


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

int main(){
    int n, k; cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a.at(i);
    }
    
    vector<int> b(n, 0);

    int kind = 0;
    for (int i = 0; i < n; i++)
    {
        if(b.at(a.at(i)-1) == 0) kind++;
        b.at(a.at(i) - 1)++;
    }

    int ans = 0;
    if(kind <= k) ans = 0;
    else{
        int amari = kind - k;

        sort(b.begin(), b.end());
        int count = 0;
        for (int i = 0; i < n; i++)
        {
            if(b.at(i) != 0){
                count++;
                ans += b.at(i);
                if(count == amari) break;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main() {

	int n, a, b, c, d;

	while(1) {
		cin >> n;
		if(n==0)
			break;
		a=0;
		b=0;
		while(n!=0) {
			cin >> c >> d;
			if(c>d)
				a+=c+d;
			else if(c<d)
				b+=c+d;
			else {
				a+=c;
				b+=d;
			}
	
			n--;
		}
		cout << a << " " << b << endl;
	}


	return 0;

}

Measured memory_bytes: 0
import java.util.*;
 
public class Main{
  public static void main(String[]args){
    Scanner sc =  new Scanner(System.in);
    String[] S = sc.nextLine().split(" ");
    String[] T = sc.nextLine().split(" ");
    int N = Integer.parseInt(S[0]);
    long x = Long.parseLong(S[1]);
    long[] candies = new long[N];
    
   for(int i = 0; i < N; i++){
     candies[i] = Long.parseLong(T[i]);
   }
    
    long ans = 0;
    for(int i = 0; i < N-1; i++){
      long sum = candies[i] + candies[i+1];
      if(sum <= x){
        continue;
      }else{
        ans += sum-x;
        if(candies[i] <= x){
          candies[i+1] -= sum-x;
        }else{
          candies[i] = sum-x-candies[i+1];
          candies[i+1] = 0;
        }
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 53040
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define fore(x, c) for(auto &&x : c)
#define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i)
#define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i)
#define sz(c) ((int)c.size())
#define contains(c, x) (c.find(x) != end(c))
#define inseg(l, x, r) ((l) <= (x) && (x) < (r))
#define dump(...)
#define pb push_back
#define eb emplace_back
#define _ 0
const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL;
const int DX[9] = {0,1,0,-1,1,1,-1,-1,0}, DY[9] = {-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
  is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a, const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a, const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap = priority_queue<T, deque<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
      cin.tie(nullptr); ios::sync_with_stdio(0);
      cout << setprecision(15) << fixed;
  }
} before_main_function;
// clang-format on
//------------------8<------------------------------------8<--------------------

int gcd(int a, int b) { return a ? gcd(b % a, a) : b; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main() {
  int a, b;
  cin >> a >> b;
  cout << lcm(a, b) << endl;
  return (0 ^ _ ^ 0);
}



Measured memory_bytes: 256
#include<stdio.h>
main()
{
    int a,b,i,min,max;
    scanf("%d%d",&a,&b);
    min=a;max=b;
    if(a>=b){min=b;max=a;}
    for(i=0;i<max;i++){
        printf("%d",min);
    }
    printf("\n");
}


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


 int main(){
  

  char s[3];
  

  scanf("%s", s);
  
  
  if (!strcmp(s, "RRR")){
    printf("%d", 3);
    
  }else if(!strcmp(s, "RRS")){
    printf("%d", 2);
    
  }else if(!strcmp(s, "SRR")){
    printf("%d", 2);
      
  }else if(!strcmp(s, "SSS")){
    printf("%d", 0);
    
  }else{
    printf("%d", 1);
    
    
    
  }

  
}

Measured memory_bytes: 1736
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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



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

  ll N; cin>>N;
  string S; cin>>S;
  vector<ll> vec(26,0);
  for(auto cha:S) vec[cha-'a']++;
  
  ll ans=1;
  rep(i,26) ans=ans*(vec[i]+1)%MOD;
  
  cout<<ans-1<<endl;
      
  return 0;
}

Measured memory_bytes: 3740
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int main(){
	int n; cin >> n;
	repn(x,100000){
		int k = x*108/100;
		if(n == k){
			cout<<x<<endl; return 0;
		}
	}
	cout<<":("<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
const int maxn=1e5+10;
int n;
ll m;
ll dpin[maxn],dpout[maxn];
vector<int> g[maxn];
inline ll quickpow(ll base,ll ind)
{
	ll ans=1;
	while(ind>0)
	{
		if(ind&1)ans=ans*base%m;
		ind>>=1;
		base=base*base%m;
	}
	return ans;
}
void dp1(int x,int fa)
{
	dpin[x]=1;
	for(int i=0;i<g[x].size();i++)
	{
		if(g[x][i]==fa)continue;
		dp1(g[x][i],x);
		dpin[x]=dpin[x]*1ll*((dpin[g[x][i]]+1)%m)%m;
	}
}
vector<ll> mulpre,mulsuf,valson;
void dp2(int x,int fa)
{
	mulpre.clear();mulsuf.clear();valson.clear();
	for(int i=0;i<g[x].size();i++)
	{
		if(g[x][i]==fa)continue;
		valson.push_back((dpin[g[x][i]]+1)%m);
	}
	mulpre=valson;
	for(int i=1;i<mulpre.size();i++)
	{
		mulpre[i]=mulpre[i-1]*mulpre[i]%m;
	}
	mulsuf=valson;
	for(int i=mulsuf.size()-2;i>=0;i--)
	{
		mulsuf[i]=mulsuf[i+1]*mulsuf[i]%m;
	}
	int c=0;
	for(int i=0;i<g[x].size();i++)
	{
		if(g[x][i]==fa)continue;
		dpout[g[x][i]]=(dpout[x]+1)%m*(c?mulpre[c-1]:1ll)%m*(c+1<mulsuf.size()?mulsuf[c+1]:1ll)%m;
		c++;
	}
	for(int i=0;i<g[x].size();i++)
	{
		if(g[x][i]==fa)continue;
		dp2(g[x][i],x);
	}
}
int main()
{
	scanf("%d%lld",&n,&m);
	for(int i=1;i<n;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dp1(1,0);
	dp2(1,0);
	for(int i=1;i<=n;i++)
	{
		printf("%lld\n",dpin[i]*1ll*((dpout[i]+1)%m)%m);
	//	cout<<dpin[i]<<" "<<dpout[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 14976
import java.util.Scanner;

class Main{
  public static void main(String[] args){
  	Scanner sc = new Scanner(System.in);
    String con = "ABC";
    String input = sc.next();
    if(con.equals(input)){
      con = "ARC";
    }
    System.out.println(con);
    
    
  }
}

Measured memory_bytes: 35672
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(),x.end()
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
const int mod = 1e9+7;
const int INF = 2e9;
// const ll INF = 1e12;
const int MAX = 1e6;
// const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

// struct edge {int to, cost;}; // 辺
// vector<edge> graph[MAX]; // 隣接リスト
// bool visited[MAX]; // 訪問状況

ll dp[51][51][2501];

int main() {
    // input
    int n, a;
    cin >> n >> a;
    vi x(n+1);
    rep(i, n+1) {
        if (i > 0) cin >> x[i];
    }
    // solve
    rep(i, n+1) {
        rep(j, n+1) {
            rep(k, 50*n+1) {
                // if (i == 0 and j == 0 and k == 0) {
                //     dp[i][j][k] = 1;
                // } else if (i >= 1 and k < x[i]) {
                //     dp[i][j][k] = dp[i-1][j][k];
                // } else if (i >= 1 and j >= 1 and k >= x[i]) {
                //     dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k-x[i]];
                // } else {
                //     dp[i][j][k] = 0;
                // }
                if (i == 0 and j == 0 and k == 0) {
                    dp[i][j][k] = 1;
                } else if (i > 0) {
                    dp[i][j][k] = dp[i-1][j][k];
                    if (j > 0 and k-x[i] >= 0) {
                        dp[i][j][k] += dp[i-1][j-1][k-x[i]];
                    }
                } else {
                    dp[i][j][k] = 0;
                }
            }
        }
    }
    ll sum = 0;
    rep(i, n+1) {
        if (i > 0) sum += dp[n][i][i*a];
    }
    // output
    cout << sum << endl;
}

Measured memory_bytes: 54404
N=int(input())
D=[int(i) for i in input().split()]
ans=1
mod=998244353
M=max(D)+1
X=[0 for i in range(M)]
for i in range(N):
    X[D[i]]+=1
if X[0]!=1:
    print(0)
    exit()
if D[0]!=0:
    print(0)
    exit()
if N==1:
    print(1)
    exit()
if N==2:
    if D[0]==0 and D[1]==1:
        print(1)
    else:
        print(0)
    exit()
#print(X)
for i in range(1,M-1):
    #print(X[i],X[i+1])
    ans=ans*pow(X[i],X[i+1],mod)
    ans%=mod
print(ans)


Measured memory_bytes: 57388
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const int inf = 1012345678;
int main() {
	int N, M, R;
	cin >> N >> M >> R;
	vector<int> r(R);
	for (int i = 0; i < R; ++i) {
		cin >> r[i]; --r[i];
	}
	vector<vector<int> > d(N, vector<int>(N, inf));
	for (int i = 0; i < N; ++i) {
		d[i][i] = 0;
	}
	for (int i = 0; i < M; ++i) {
		int A, B, C;
		cin >> A >> B >> C; --A, --B;
		d[A][B] = C;
		d[B][A] = C;
	}
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			for (int k = 0; k < N; ++k) {
				d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
			}
		}
	}
	sort(r.begin(), r.end());
	int ans = inf;
	do {
		int cost = 0;
		for (int i = 1; i < R; ++i) {
			cost += d[r[i - 1]][r[i]];
		}
		ans = min(ans, cost);
	} while (next_permutation(r.begin(), r.end()));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <iostream>
#include <ctime>
using namespace std;
#define _LL long long
#define rep(i, n) for (_LL i = 0; i < (_LL)(n); i++)
#define vecrep(itr, v) for (auto itr = (v).begin(); itr != (v).end(); itr++)

int main()
{
    int n; cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);
    rep(i, n) { cin >> a[i]; a[i]--; }
    rep(i, n) cin >> b[i];
    rep(i, n - 1) cin >> c[i];

    int ans = 0;
    rep(i, n)
    {
        ans += b[a[i]];
        if( i > 0 && a[i - 1] + 1 == a[i] ) ans += c[a[i - 1]];
    }
    cout << ans << endl;
    return 0;    
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int prime(int z)
{
    for(int i=2;i<z;i++) if(z%i==0) return 0;
    return 1;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    while(1)
    {
        int n,i;
        cin >> n;
        if(n==0) break;
        if(n%2 == 0)n-=1;
        for(i=n;i>=2;i-=2)
        {
            if(prime(i) && prime(i-2))
            {
                cout << i-2 << " " << i << "\n";
                break;
            }
        }
    }

    return 0;
}




Measured memory_bytes: 3136
N,K=[int(x) for x in input().split()]
if K>(N-2)*(1+N-2)//2:
	print(-1)
else:
	print(((N-2)*(1+N-2)//2)+((N-1)-K))
	counter=0
	for i in range(2,N+1):
		print(1,i)
		counter+=1
	for i in range(2,N+1):
		for j in range(i+1,N+1):
			if counter==((N-2)*(1+N-2)//2)+((N-1)-K):
				exit()
			else:
				print(i,j)
				counter+=1

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

int findSumOfDigits(int n){
 int sum=0;
  while(n>0){
  sum+=n%10;
    n/=10;
 }
  return sum;
}

int main() {
int  N;
    cin >> N ;
  if (findSumOfDigits(N)==1){
  cout << 10 << endl;
  }
  else
  cout << findSumOfDigits(N) << endl;  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 (a>b) { a=b; return 1; } return 0; }



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

  ll asum = 0, bsum = 0;
  rep(i, n) asum += a[i];
  rep(i, n) bsum += b[i];
  if (asum < bsum) {
    cout << -1 << endl;
    return 0;
  }
  priority_queue<ll> pq;
  rep(i, n) {
    if (a[i] > b[i]) pq.push(a[i] - b[i]);
  }
  int ans = 0;
  ll res = 0;
  rep(i, n) {
    if (a[i] >= b[i]) continue;
    ans++;
    ll lack = b[i] - a[i];
    while (lack > 0) {
      if (res >= lack) {
        res -= lack;
        break;
      }
      lack -= res;
      res = pq.top();
      pq.pop();
      ans++;
    }
  }
  cout << ans << endl;


  
  return 0;
}

Measured memory_bytes: 2556
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    ll n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    rep(i,n) a[i]--;
    vector<int> ans(n);
    rep(i,n) ans[a[i]] += i+1;
    rep(i,n) cout << ans[i] << " ";
    cout << endl;
    return 0;
}

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

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

  if (A+B < C+D)
    cout << "Right" << endl;
  else if (A+B > C+D)
    cout << "Left" << endl;
  else if (A+B == C+D)
    cout << "Balanced" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
  /*#ifndef ONLINE_JUDGE
      // for getting input from input.txt
      freopen("input.txt", "r", stdin);
      // for writing output to output.txt
      freopen("output.txt", "w", stdout);
  #endif*/
fast();
//ll  t;cin>>t;while(t--)
{
  ll a,b,h,n=3;
  set<ll>s;
  for(int i=0;i<n;i++)
  {
    ll x;
    cin>>x;
    s.insert(x);
  }
  cout<<s.size()<<endl;

  
  
  

}
return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<map>
#include<cmath>
#include<iomanip>

using namespace std;

typedef long long ll;

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
 
 bool flag = false;
 if(a > b){
   for(int i = a; i >= b; i--){
     if(i == c) flag = true;
     }
 }
 else{
   for (int i = a; i <= b; i++)
   {
     if(i == c) flag = true;
   }
   
 }

  if(flag == true) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int N, i, j;
	scanf("%d", &N);
	char s[N + 2], a[N + 2], str[8] = "SSSWWSWW";
	scanf("%s", s);
	s[N] = s[0];
	s[N + 1] = s[1];
	for(j = 0; j < 4; j++){
		a[0] = str[2*j + 0];
		a[1] = str[2*j + 1];
		for(i = 1; i < N + 1; i++){
			if((a[i] == 'S' && ((s[i] == 'o' && a[i-1] == 'S') || (s[i] == 'x' && a[i-1] == 'W')))
				|| (a[i] == 'W' && ((s[i] == 'o' && a[i-1] == 'W') || (s[i] == 'x' && a[i-1] == 'S')))){
				a[i + 1] = 'S';
			}
			else{
				a[i + 1] = 'W';
			}
		}
		if(a[0] == a[N] && a[1] == a[N + 1]){
			a[N] = '\0';
			printf("%s\n", a);
			return 0;
		}
	}
	printf("-1\n");
	return 0;
}

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

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

  int b = 0,w = 0;
  for(int i=0;i<s.size();i++){
    if(i%2 == 0){
      if(s[i] == '0') w++;
      else b++;
    }
    else{
      if(s[i] == '0') b++;
      else w++;
    }
  }

  cout << min(b,w) << endl;
  return 0;

}


Measured memory_bytes: 512
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define NUM 999999

int *dp_single,*dp_all;
int N,monster[100];

void func(){

	int max_hp = 0;

	for(int i = 0; i < N; i++){
		scanf("%d",&monster[i]);
		max_hp = max(max_hp,monster[i]);
	}

	for(int i = 1; i <= NUM; i++){
		dp_single[i] = BIG_NUM;
		dp_all[i] = BIG_NUM;
	}

	int M;
	scanf("%d",&M);

	int mp,damage,single_count = 0,all_count = 0;
	char buf[17],target[7];

	for(int loop = 0; loop < M; loop++){
		scanf("%s %d %s %d",buf,&mp,target,&damage);
		if(damage == 0)continue;

		if(target[0] == 'S'){
			single_count++;
			for(int i = damage; i <= NUM; i++){
				if(dp_single[i-damage] != BIG_NUM){
					dp_single[i] = min(dp_single[i],dp_single[i-damage]+mp);
				}
			}
		}else{
			all_count++;
			for(int i = damage; i <= NUM; i++){
				if(dp_all[i-damage] != BIG_NUM){
					dp_all[i] = min(dp_all[i],dp_all[i-damage]+mp);
				}
			}
		}
	}

	for(int i = NUM-1; i >= 1; i--){
		dp_single[i] = min(dp_single[i],dp_single[i+1]);
		dp_all[i] = min(dp_all[i],dp_all[i+1]);
	}

	int minimum = BIG_NUM,tmp_hp,tmp_minimum;

	if(single_count > 0 && all_count > 0){

		for(int all_damage = 0; all_damage <= max_hp; all_damage++){
			tmp_minimum = dp_all[all_damage];

			for(int i = 0; i < N; i++){
				tmp_hp = monster[i] - all_damage;
				if(tmp_hp > 0){
					tmp_minimum += dp_single[tmp_hp];
				}
			}

			minimum = min(minimum,tmp_minimum);
		}

	}else if(single_count == 0){
		minimum = dp_all[max_hp];
	}else{ //all_count = 0;
		minimum = 0;
		for(int i = 0; i < N; i++){
			minimum += dp_single[monster[i]];
		}
	}

	printf("%d\n",minimum);
}

int main(){

	dp_single = new int[NUM+1];
	dp_all = new int[NUM+1];

	dp_single[0] = 0;
	dp_all[0] = 0;

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}

Measured memory_bytes: 10980
#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(){
    string c;
    cin >> c ;
    vector <string> p;
    p.push_back("a");
    p.push_back("b");
    p.push_back("c");
    p.push_back("d");
    p.push_back("e");
    p.push_back("f");
    p.push_back("g");
    p.push_back("h");
    p.push_back("j");
    p.push_back("k");
    p.push_back("l");
    p.push_back("m");
    p.push_back("n");
    p.push_back("o");
    p.push_back("p");
    p.push_back("q");
    p.push_back("r");
    p.push_back("s");
    p.push_back("t");
    p.push_back("u");
    p.push_back("v");
    p.push_back("w");
    p.push_back("x");
    p.push_back("y");
    p.push_back("z");
    
    rep(i,26){
        if (p[i]==c){
            p[0]=p[i+1];
            break;
        }
    }

    
    cout << p[0] << endl;
    return 0;
}

Measured memory_bytes: 256
s=input()

NOW=0
SCORE=0
for i in range(len(s)):
    if NOW==i-NOW:
        if s[i]=="g":
            SCORE+=0
        else:
            SCORE-=1

    else:
        if s[i]=="g":
            SCORE+=1
            NOW+=1
        else:
            SCORE+=0
            NOW+=1

print(SCORE)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int digit(int n){
  int ans=0;
  while(n!=0){
    ans+=n%10;
    n=n/10;
  }
  return ans;
}
int main(){
  int n;
  cin >> n;
  if(n % digit(n)==0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

int main(){
    int n,k,d,tmp,cnt=0;
    cin >> n >> k;
    vector<int> a(n);

    for(int i=0;i<k;i++){
        cin >> d;
        for(int j=0;j<d;j++){
            cin >> tmp;
            a.at(tmp-1)++;
        }
    }

    for(int i=0;i<n;i++){
        if(a.at(i)==0) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>

using namespace std;
typedef long long ll;

int main()
{
	int N, M;
	scanf("%d%d", &N, &M);

	vector<pair<int, int>> info[100000];
	for (int i = 0; i < M; i++) {
		int L, R, D;
		scanf("%d%d%d", &L, &R, &D);
		L--;
		R--;
		info[L].push_back(make_pair(R, D));
		info[R].push_back(make_pair(L, -D));
	}

	bool used[100000];
	for (int i = 0; i < N; i++)
		used[i] = false;

	for (int i = 0; i < N; i++) {
		if (used[i] || info[i].size() < 1)
			continue;

		queue<int> q;
		q.push(i);
		map<int, int> dist;
		dist[i] = 0;
		while (!q.empty()) {
			int node = q.front(); q.pop();
			if (used[node])
				continue;
			used[node] = true;

			for (int i = 0; i < (int)info[node].size(); i++) {
				int next_node = info[node][i].first;
				int next_dist = info[node][i].second;
				if (dist.count(next_node) == 0)
					dist[next_node] = dist[node] + next_dist;
				else if (dist[next_node] != dist[node] + next_dist) {
					printf("No\n");
					return 0;
				}
				q.push(next_node);
			}
		}
	}

	printf("Yes\n");

	return 0;
}


Measured memory_bytes: 15232
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class D
{
	public static void Main()
	{
		int H = GetInt();
		int W = GetInt();
		int K = GetInt();

		if(W == 1)
		{
			Console.WriteLine(1);
			return;
		}

		// hereafter, W >= 2
		long mod = 1000000007;
		long[,] A = new long[H+1, W+1];
		A[0, 1] = 1;
		for(int h = 0; h < H; h++)
		{
			for(int s = 0; s < (1 << (W-1)); s++)
			{
				if(!isCorrectAmida(W-1, s))
					continue;
				
				int t = s << 1;
				for(int w = 1; w <= W; w++)
				{
					if((w != 1) && ((t >> (w-1)) & 1) == 1)
					{
						A[h+1, w-1] = (A[h+1, w-1] + A[h, w]) % mod;
						continue;
					}

					if((w != W) && ((t >> w) & 1) == 1)
					{
						A[h+1, w+1] = (A[h+1, w+1] + A[h, w]) % mod;
						continue;
					}
					
					A[h+1, w] = (A[h+1, w] + A[h, w]) % mod;					
				}				
			}
		}

		Console.WriteLine(A[H,K]);
	}

	private static bool isCorrectAmida(int W, int s)
	{
		int t = s << 1;

		for(int i = 1; i <= W; i++)
		{
			if((((s >> i) & 1) & ((s >> (i + 1)) & 1)) == 1)
				return false;

			if((((s >> i) & 1) & ((s >> (i - 1)) & 1)) == 1)
				return false;
		}

		return true;
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}





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

int SnakeIsA(const char* str)
{
	int eq_cnt=0;
	if( strncmp(str, ">'", 2) != 0 )
		return 0;
	str+=2;
	while(1) // left
	{
		if(*str != '=')return 0;
		
		eq_cnt++;
		str++;
		if(*str == '#')break;
	}
	str++;
	while(1) // right
	{
		if(*str != '=' || eq_cnt==0)return 0;

		eq_cnt--;
		str++;
		if(*str == '~')break;
	}
	return (eq_cnt==0) ? 1 : 0;
}

int SnakeIsB(const char* str)
{
	if( strncmp(str, ">^", 2) != 0 )
		return 0;
	str += 2;
	while(1)
	{
		if( strncmp(str, "Q=", 2) != 0 )return 0;

		str += 2;
		if( strncmp(str, "~~", 2) == 0 )break;
	}
	return 1;
}

int main(void)
{
	int i, n;
	char get[201];
	scanf("%d", &n);
	for(i=0; i<n; i++)
	{
		scanf("%s", get);
		     if( SnakeIsA(get) )printf("A\n");
		else if( SnakeIsB(get) )printf("B\n");
		else printf("NA\n");
	}
	return 0;
}

Measured memory_bytes: 584
s = input()
# 長さが奇数である文字列S

def check_palindrome(s):
    i = 0
    j = len(s) - 1
    while i <= j:
        if s[i] != s[j]:
            return False
        i += 1
        j -= 1
    return True
t = (len(s) - 1) // 2
u = (len(s) + 3) // 2 - 1
if check_palindrome(s) and check_palindrome(s[:t]) and check_palindrome(s[u:]):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38388
// inputに入力データ全体が入る
function Main(input) {
    var ans = 0;
    var map = {};
    input[1].split(" ").forEach(v=>{
        if(!map[v]) ans++;
        map[v] = true;
    });
    console.log(ans==3?"Three":"Four")
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").split("\n"));

Measured memory_bytes: 7372
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<utility>
using namespace std;
#define int long long
#define veb vector<bool>
#define vveb vector<veb>
#define vel vector<long long>
#define vvel vector<vel>
#define vvvel vector<vvel>
void mmin(int &a, int b) { a = min(a, b); }
void mmax(int &a, int b) { a = max(a, b); }
void sor(vel &v) { sort(v.begin(), v.end()); }
void rev(vel &v) { reverse(v.begin(), v.end()); }
int zero(void) { return 0; }
int gcd(int a, int b) {
	if (b > a) { swap(a, b); }
	if (b == 0) { return a; }
	int r = a % b;
	return gcd(b, r);
}
signed main() {
	int n, x; cin >> n >> x;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int x0; cin >> x0;
		ans=gcd(abs(x0 - x), ans);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
#define INF 1000000000

int main(){
  int N;
  long K;
  int A[200001];
  cin >> N>>K;
  for(int i=1; i<=N; i++){
   cin >> A[i]; 
  }
  if(A[1] == 1){
    cout << 1 << endl;
    return 0;
  }
  
  int log[200001] = {0};
  
  int pos=1;
  int step=0;
  while(step<K){
    step++;
    pos = A[pos];
    if(log[pos]==0){
    	 log[pos] = step;
    }else{
     int period = step-log[pos];
     K -= ((K-step)/period)*period; 
    }
  }
  cout << pos << endl;
  return 0;
}


Measured memory_bytes: 5184
/*****************************************************
 *     created by: nayakashutosh9
 * "Winners Never Quit and Quitters Never Win".
*****************************************************/
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast")
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define endl '\n'
#define mod 1000000007
#define inf 1e18
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
const int N = 300005;
/**********************************************************************************************/


void solve() {
	int n, m; cin >> n >> m;
	int ans = 0;
	if (n >= 2) ans += (n * (n - 1) / 2);
	if (m >= 2) ans += (m * (m - 1) / 2);
	cout << ans << endl;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int t = 1, z = 1;
	// cin >> t; cin.ignore();
	while (t--) {
		// cout << "Case #" << (z++) << ": ";
		// clock_t start = clock();
		solve();
		// clock_t end = clock();
		// cout << (end-start) << endl;
		//print execution time in ms
	}

	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define L "\n"
#define S " "
#define ll long long
#define pb push_back
#define mp make_pair
#define vi std::vector<int>
#define si std::set<int>
#define vl std::vector<long long>
#define qi std::queue<int>
#define de(a) cout << #a << "  ------>  " << a << "\n"
#define SIZE 3002
#define INF INT_MAX
#define FOR(i, n) for (i = 0; i < n; i++)
#define FASTIO                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

using namespace std;
int dp[SIZE][SIZE];
bool flag[SIZE][SIZE];
string s, t;
vi findlcs()
{
    vi c;
    int i = 0, j = 0;
    while(s[i] && t[j]){
        if(dp[i][j] == dp[i][j + 1]){
            j++;
        }
        else if(dp[i][j] == dp[i + 1][j]) i++;
        else {
            c.pb(i);
            i++; j++;
        }
    }
    return c;
}

int lcs(int i, int j)
{
    int res, res1, res2;
    flag[i][j] = 1;
    if (s[i] == 0 || t[j] == 0)
        return dp[i][j] = 0;
    if (s[i] == t[j])
    {
        if (flag[i + 1][j + 1])
            res = 1 + dp[i + 1][j + 1];
        else
            res = 1 + lcs(i + 1, j + 1);
        return dp[i][j] = res;
    }
    else
    {
        if (flag[i + 1][j])
            res1 = dp[i + 1][j];
        else
            res1 = lcs(i + 1, j);
        if (flag[i][j + 1])
            res2 = dp[i][j + 1];
        else
            res2 = lcs(i, j + 1);
        return dp[i][j] = max(res2, res1);
    }
}

void solve()
{
    cin >> s >> t;
    lcs(0, 0);
    vi res = findlcs();
    for(int i : res)
        cout << s[i];

    cout << L;
}
int main()
{
    FASTIO;
// #ifndef ONLINE_JUDGE
//     freopen("in.txt", "r", stdin);
// #endif
    int t;
    // cin >> t;
    // while (t--)
    solve();
    return 0;
}

Measured memory_bytes: 44544
import java.util.Scanner

fun main(args: Array<String>){
    val scanner = Scanner(System.`in`)
    val sa = scanner.next()
    val sb = scanner.next()
    val a = Integer.parseInt(sa)
    val b = Integer.parseInt(sb)
    val c = a/b
    if(a%b == 0){
        println(c)
    } else {
        println(c + 1)
    }
}

Measured memory_bytes: 29476
// https://atcoder.jp/contests/

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

ll N, sum, M, cnt[26];
string S, t;
char n;

int main()
{
  M = 1e9 + 7;
  cin >> N >> S;

  t = "";
  REP(i, N)
  {
    cnt[S[i] - 'a']++;
  }

  sum = 1;
  REP(i, 26)
  {
    sum *= (cnt[i] + 1);
    sum %= M;
  }

  cout << sum - 1 << '\n';

  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>

int main(){
    int a,b,e,n,m,k;
    std::vector<int> vec1{};
    std::vector<int> vec2{};
    
    std::cin>>n;
    for(int i=0;i<n;i++){
        std::cin>>a;
        vec1.push_back(a);
    }

    std::cin>>m;
    for(int i=0;i<m;i++){
        std::cin>>b;
        vec2.push_back(b);
    }

    if(std::lexicographical_compare(vec1.begin(),vec1.end(),vec2.begin(),vec2.end()))
    {
        std::cout<<"1"<<std::endl;
    }else{
        std::cout<<"0"<<std::endl;
    }

    return 0;

}


Measured memory_bytes: 3152
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
#include<queue>
#include<numeric>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

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

int main()
{
  int n;
  string s;
  cin >> n >> s;

  int count = 0;
  vector<int> zumi(10, 0); // 1はずみ
  vector<int> zumi2(10, 0);
  for (int i = n-1; i >= 0; i--) {
    if (zumi[s[i] - '0']) {
      continue;
    } else {
      zumi[s[i] - '0'] = 1;
    }
    vector<int> zumi1(10, 0);
    for (int j = i-1; j >= 0; j--) {
      if (zumi1[s[j] - '0']) {
        continue;
      } else {
        zumi1[s[j] - '0'] = 1;
      }
      vector<int> zumi2(10, 0);
      for (int k = j-1; k >= 0; k--) {
        if (zumi2[s[k] - '0']) {
          continue;
        } else {
          zumi2[s[k] - '0'] = 1;
          count++;
        }
      }
    }
  }
  cout << count << endl;
}  


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ll long long
#define  mod 1000000007
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n];
	int ct[n]={0};
	int f=1;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		ct[a[i]]++;
	}
	if(n%2==0)
	{
		for(int i=0;i<n;i++)
		{
			if(i!=0&&i%2==1&&ct[i]!=2){f=0;break;}
			if(i==0&&ct[i]>0){f=0;break;}
		}
	}
	else if(n%2==1)
	{
		for(int i=0;i<n;i++)
		{
			if(i==0&&ct[i]>1){f=0;break;}
			if(i!=0&&i%2==0&&ct[i]!=2){f=0;break;}
		}
	}
	if(f==0)cout<<0;
	else{
		ll res=1LL;
		ll b=n/2;
		ll a=2LL;
		while(b>0)
		{
			if(b&1)res=(res*a)%mod;
			a=(a*a)%mod;
			b>>=1;
		}
		cout<<res;
	}
}

Measured memory_bytes: 1024
import sys
import numpy as np
input = sys.stdin.readline

_n, _t = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(_n)]
AB.sort()


def dp(t, ablist):
    ans = 0
    table = np.zeros(t, int)
    for a, b in ablist:
        ans = max(ans, max(table) + b)
        np.maximum(table[:-a] + b, table[a:], out=table[a:])

    return ans


print(dp(_t, AB))


Measured memory_bytes: 12760
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <iostream>
#include <algorithm>
#include <cstdio>
#define N 100020
using namespace std;

bool f[N];

int main(void)
{
    int n;
    int i, j;

    cin >> n;
    f[0] = true;
    for(i = 1; i <= n; i ++)
        for(j = 100; j <= 105; j ++)
            if(i >= j)
                f[i] |= f[i - j];
    printf("%d\n", f[n]);

    return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
typedef long long ll;
vector<int> ans;
void solve(int n){
    if(n == 0) return;
    int M = 0;
    while(n > M*(M+1)/2) M++;
    ans.push_back(M);
    solve(n-M);
}
int main(){
    int N;
    cin >> N;
    solve(N);
    REP(i,ans.size()) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 512