akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin() , v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)


int main(){
    string s; cin >> s;
    bool flg=false;
    rep(i, s.length()){
        if(s[i] == 'C') flg = true;
        if(flg && s[i] == 'F'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define L long long
using namespace std;
int n;
L p;
struct orz;
inline orz minn(orz a,orz b);
struct orz
{
	int a[4];
	inline void in()
	{
		int i;
		for(i=0;i<4;i++)
		  scanf("%d",&a[i]);
	}
	inline orz trans()
	{
		orz x;
		x.a[0]=a[1];
		x.a[1]=a[2];
		x.a[2]=a[3];
		x.a[3]=a[0];
		return x;
	}
	inline bool operator==(orz x)
	{
		return a[0]==x.a[0] && a[1]==x.a[1] && a[2]==x.a[2] && a[3]==x.a[3];
	}
	inline bool operator<(orz x)const
	{
		return minn(*this,x)==*this && !(x==*this);
	}
	inline void print()
	{
		int i;
		for(i=0;i<4;i++)
		  printf("%d ",a[i]);
	    printf("!!\n");
	}
}x[410],a,b,w[4];
map<orz,int> f;
inline int count(orz x)
{
	if(x.a[0]==x.a[2] && x.a[1]==x.a[3])
	  if(x.a[0]==x.a[1])
	    return 4;
	  else
	    return 2;
	return 1;
}
inline orz minn(orz a,orz b)
{
	int i;
	for(i=0;i<4;i++)
	  {
	   if(a.a[i]<b.a[i])
	     return a;
	   if(b.a[i]<a.a[i])
	     return b;
	  }
	return a;
}
inline orz minn(orz a)
{
	orz b=a,c=a;
	int i;
	for(i=1,b=b.trans();i<4;i++,b=b.trans())
	  c=minn(b,c);
	return c;
}
inline void add(orz a,int k)
{
	int i;
	orz b=minn(a);
	f[b]+=count(a)*k;
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j,k,l,u,v;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	  x[i].in();
	for(i=1;i<=n;i++)
	  add(x[i],1);
	for(i=1;i<n;i++)
	  {
	   add(x[i],-1);
	   for(j=0,a=x[i];j<4;j++,a=a.trans())
	     for(k=i+1;k<=n;k++)
	       {
		    b=x[k];
			add(x[k],-1);
			w[0].a[0]=b.a[1];
			w[0].a[1]=a.a[0];
			w[0].a[2]=a.a[3];
			w[0].a[3]=b.a[2];
			w[1].a[0]=b.a[0];
			w[1].a[1]=a.a[1];
			w[1].a[2]=a.a[0];
			w[1].a[3]=b.a[1];
			w[2].a[0]=b.a[3];
			w[2].a[1]=a.a[2];
			w[2].a[2]=a.a[1];
			w[2].a[3]=b.a[0];
			w[3].a[0]=b.a[2];
			w[3].a[1]=a.a[3];
			w[3].a[2]=a.a[2];
			w[3].a[3]=b.a[3];
			L q=1;
			for(l=0;l<4;l++)
			  {
			   w[l]=minn(w[l]);
			   v=f[w[l]];
			   for(u=0;u<l;u++)
			     if(w[l]==w[u])
				   v-=count(w[l]);
			   q*=v;
			  }
			add(x[k],1);
			p+=q;
		   }
	   add(x[i],1);
	  }
	p/=3;
	printf("%lld\n",p);
	return 0;
}


Measured memory_bytes: 80128
long long f(long long b,long long x){return x<b?x:f(b,x/b)+x%b;}
long long g(){
	long long n,s,b=2,r=-1,z;
	scanf("%lld%lld",&n,&s);
	if(n<s)return r;
	if(n==s)return n+1;
	for(;b*b<=n;b++)if(f(b,n)==s)return b;
	for(b=1;b*b<=n;b++)if((n-s)%b==0&&f(z=(n-s)/b+1,n)==s)r=z;
	return r;
}
int main(){printf("%lld\n",g());}

Measured memory_bytes: 128
#include <stdio.h>

#define Mod 998244353

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

long long combination(int n, int k)
{
	if (k == 0) return 1;
	
	static long long ans[300][300] = {};
	if (ans[n][k] != 0) return ans[n][k];
	
	int i;
	long long x, y;
	for (i = n, x = 1; i >= n - k + 1; i--) x = x * i % Mod;
	for (i = 2, y = 1; i <= k; i++) y = y * i % Mod;
	ans[n][k] = div_mod(x, y, Mod);
	return ans[n][k];
}

int main()
{
	int K;
	char S[301];
	scanf("%s %d", S, &K);

	int i, j, k, l, m, count[151][2] = {}, sum[2] = {};
	count[0][S[0] - '0']++;
	for (l = 1, k = 0; S[l] != 0; l++) {
		if (S[l] == S[l-1] || S[l] == '1') count[k][S[l] - '0']++;
		else count[++k][0]++;			
	}
	
	long long dp[151][301][301] = {};
	if (count[0][0] == 0) i = 1;
	else i = 0;
	dp[i][0][count[i][0]+1] = 1;
	for (j = 1; j <= count[i][1]; j++) {
		for (k = 1; k <= count[i][0]; k++) dp[i][j][k] = combination(j + count[i][0] - k - 1, j - 1);
	}
	
	for (sum[0] = count[i][0], sum[1] = count[i++][1]; count[i][1] > 0; i++) {
		for (l = 0; l <= sum[1]; l++) {
			for (k = 1; k <= sum[0] + 1; k++) dp[i][l][k+count[i][0]] = dp[i-1][l][k];
		}
		sum[0] += count[i][0];
		for (j = 1; j <= count[i][1]; j++) {
			for (l = 0; l <= sum[1]; l++) {
				for (k = 1; k <= sum[0]; k++) {
					for (m = sum[0] - count[i][0] + 1; m >= k - count[i][0] + 1 && m >= 1; m--) dp[i][l+j][k] = (dp[i][l+j][k] + dp[i-1][l][m] * combination(j + m + count[i][0] - k - 2, j - 1)) % Mod;
				}
			}
		}
		sum[1] += count[i][1];
	}
	
	long long ans = 0;
	for (j = 0; j <= K && j <= sum[1]; j++) {
		for (k = 1; k <= sum[0] + 1; k++) ans = (ans + dp[i-1][j][k]) % Mod;
	}
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 109212
#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin >> t;
    for(int i=0;i<t;i++){
        int n;
        cin >> n;
        long long int ans=0;
        vector<pair<int,long long int> > left;
        vector<pair<int,long long int> > right;       
        for(int j=0;j<n;j++){
            int k;
            long long int l,r;
            cin >> k >> l >> r;
            k;
            if(l>r){
                ans+=r;
                left.emplace_back(k,l-r);
            }
            else if(r>l){
                ans+=l;
                right.emplace_back(n-k,r-l);
            }
            else ans+=l;
        }
        sort(left.begin(),left.end());
        sort(right.begin(),right.end());
        priority_queue<long long int,vector<long long int>,greater<long long int>> q;
        for(auto u:left){
            q.emplace(u.second);
		    ans+=u.second;
		    while(q.size()>u.first) ans-=q.top(), q.pop();//小さいモノからあきらめていくスタイル
        }
        while(!q.empty())q.pop();
        for(auto u:right){
            q.emplace(u.second);
		    ans+=u.second;
		    while(q.size()>u.first) ans-=q.top(), q.pop();
        }
        cout << ans << endl;
    }
}

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define FORD(i,b,a) for (int i = (int)(b) - 1; i >= a; --i)
#define REP(i,N) FOR(i,0,N)
#define st first
#define nd second
#define pb push_back

typedef pair<int, int> PII;
typedef long long LL;

int main() {
  LL C, S;
  scanf("%lld%lld", &S, &C);
  LL res = min((2 * S + C) / 4, C / 2);
  printf("%lld\n", res);
}


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

using namespace std;

int main(){
	string S;
	cin >> S;
	if(S[0]==S[1]&&S[0]==S[2]) cout << "No" << endl;
	else cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, r;
    cin >> n;
    r = n % 10;
    if (r == 3)
        cout << "bon\n";
    else if (r == 2 || r == 4 || r == 5 || r == 7 || r == 9)
        cout << "hon\n";
    else if (r == 0 || r == 1 || r == 6 || r == 8)
        cout << "pon\n"; 
    return 0;
}

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

#define mod 1000000007

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

using namespace std;
typedef long long ll;
const long long INF = 1000000000000000000;
 
int main(void){
	
	int N;
    cin >> N;
    ll A[N];

    rep(i, N){
        cin >> A[i];
        if(A[i] == 0){
            cout << 0 << endl;
            return 0;
        }
    }

    ll ans = 1;

    rep(i, N){
        if(A[i] * ans > INF){
            cout << -1 << endl;
            return 0;
        }
        ans *= A[i];
        if(ans <= 0LL){
            cout << -1 << endl;
            return 0;
        }
    }   
    
    if(ans <= 0LL)
        cout << -1 << endl;
    else
        cout << ans << endl;
	
	return 0;
}

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

typedef pair<int,int>   II;
typedef vector< II >      VII;
typedef vector<int>     VI;
typedef vector< VI > 	VVI;
typedef long long int 	LL;
typedef unsigned long long int ULL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))
#define LET(x,a) __typeof(a) x(a)

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
//Works for forward as well as backward iteration

#define gu getchar
#define pu putchar
#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)

#define DRT() int t; si(t); while(t--)

#define PlUSWRAP(index,n) index = (index+1)%n		//index++; if(index>=n) index=0
#define MINUSWRAP(index,n) index = (index + n -1)%n 	//index--; if(index<0) index=n-1
#define ROUNDOFFINT(d) d = (int)((double)d + 0.5)	//Round off d to nearest integer

#define FLUSHN while(gu()!='\n')
#define FLUSHS while(gu()!=' ')

#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif

#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int main() {
	/*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif*/
	off;
	int n;
	cin>>n;
	vector<int> arr(n);
	rep(i,0,n)
	cin>>arr[i];
	vector<int> val(n);
	val[n-1]=0;
	rep(i,n-1,0)
	{
		if(arr[i]>=arr[i+1])
			val[i]=val[i+1]+1;
		else
			val[i]=0;
	}
	int ma = -1;
	rep(i,0,n)
	ma = max(ma,val[i]);
	cout<<ma;
  	return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include<iostream>
using namespace std;
int main(){
  int n;
  cin >> n;

  int h[110];
  for(int i = 0; i < n; i++) cin >> h[i];

  int max_h = 0;
  int count = 0;

  for(int i = 0; i < n; ++i){
    if(max_h <= h[i]){
      max_h = h[i];
      count++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int x;
    scanf("%d", &x);
    vector<char> iva(200001, 0);
    iva[0] = 1;
    iva[1] = 1;
    for(int i = 2; i * i <= x; i++) {
        for(int j = 2; i * j <= 200000; j++){
            iva[i * j] = 1;
        }
    }
    for (int i = x; i <= 200000; i++){
        if(iva[i] == 0){
            printf("%d", i);
            break;
        }
    }
  
    return 0;
}


Measured memory_bytes: 3180
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
#include <queue>
#include <cctype>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[100001];
//char str[1010][1010];
//typedef pair<ll,ll> A;
//vector<A> pc;
//int ABS(int a){return max(a,-a);}
int main(){
  string s;
  cin>>s;
  if(s[0]==s[1]||s[1]==s[2]||s[2]==s[3]) cout<<"Bad";
  else cout<<"Good";
  return 0;
}

Measured memory_bytes: 256
n=int(input())
# n,m=map(int,input().split())
# a,b,c=map(int,input().split())
# s=input()
# s,t=map(str,input().split())
# A=list(map(int,input().split()))

if n%2==0:
  print(n//2)
else:
  print(n//2+1)



Measured memory_bytes: 2940
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
using namespace std;

int main(){
  int n; cin>>n;
  string s; cin>>s;
  int count=0;
  for(int i=0;i<n-2;i++){
    if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C') count=count+1;
  }
  cout<<count<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define   sz(s)         s.size()
#define   ll            long long int
#define   ull           unsigned ll
#define   ld            long double
#define   print(v)      for(ll i=0;i<v.size();i++)cout<<v[i]<<" "
#define   printpair(v)  for(ll i=0;i<v.size();i++)cout<<v[i].first<<" "<<v[i].second<<"\n"
#define   bmd           1000000007
#define   bmd1          998244353
#define   umll          unordered_map<ll,ll>
#define   mll           map<ll,ll>
#define   mcl           map<char,ll>
#define   pll           pair<ll,ll>
#define   F             first
#define   S             second
#define   setp(x)       setprecision(x)
#define   pb            push_back
#define   all(v)        v.begin(),v.end()
#define   tr(a)         for(auto it=a.begin();it!=a.end();it++)
#define   trr(a)        for(auto it1=a.begin();it1!=a.end();it1++)
#define   vll           vector<long long int>
#define   sorty(v)      sort(v.begin(),v.end())
#define   rsort(v)      sort(v.rbegin(),v.rend())
#define   unik(v)       v.erase(unique(all(v)),v.end())
#define   PI            3.1415926535897932384626
#define   db()          cout<<"\n"<<"here"<<"\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


//---------------------------------------------------------------------------
const int MOD = bmd;
const int N=2e5+100;
inline  ll sqr(ll x){return x*x;}
inline  void normal(ll &a) { a = (a+MOD)%MOD; }
inline  ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline  ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline  ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline  ll modPow(ll b, ll p) { ll r = 1;b=b%MOD; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline  ll modInv(ll a) { return modPow(a, MOD-2); }
inline  ll modDiv(ll a,ll b) { return modMul(a, modInv(b)); }
//---------------------------------------------------------------------------

void solve()
{
    ll n;
    cin>>n;
    ll a[15];
    ll i=0;
    while(n){
        a[i]=n%26;
        n/=26;
        i++;
    }
    for(ll j=0;j<i-1;j++){
        if(a[j]<=0){
            a[j]+=26;
            a[j+1]--;
        }
    }
    for (ll j = i-1; j >= 0; j--) {
        if (a[j] > 0)
            cout << char('a' + a[j] - 1);
    }
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);//first give all input then gives output
    ll t=1;
    //cin>>t;
    while(t--){
        solve();
    }

    return 0;
}


Measured memory_bytes: 3648
/**
 * author: dannysmyda
 */ 
#include <bits/stdc++.h>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M;
    cin >> N >> M;
    vector<vector<int>> graph(N);
    for(int i = 0; i < N; i++) {
        vector<int> edges;
        graph[i] = edges;
    }
    vector<int> heights(N);
    for(int i = 0; i < N; i++) {
        cin >> heights[i];
    }

    for(int i = 0; i < M; i++) {
        int s,e;
        cin >> s >> e;
        graph[s-1].push_back(e-1);
        graph[e-1].push_back(s-1); 
    }
    
    int ans = 0;
    for(int i = 0; i < N; i++) {
        if(graph[i].size() == 0) {
            ans += 1;
        } else {
            bool ok = true;
            for(int e : graph[i]) {
                if(heights[e] >= heights[i]) {
                    ok = false; 
                    break;
                }
            }
            if(ok) ans += 1;
        }
    } 
    cout << ans << endl;
    return 0;    
}


Measured memory_bytes: 8724
import numpy as np
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
lst = [a, b, c, d, e]
flag = 0
for i in range(0, 4):
    for j in range(1, 5 - i):
        if lst[i + j] - lst[i] > k:
            print(':(')
            flag = 1
            break
    if flag == 1:
        break
    if i == 3:
        print('Yay!')

Measured memory_bytes: 21496
#include <bits/stdc++.h>
#define SORT(x) sort(x.begin(),x.end(),greater<ll>())
#define ALL(x) x.begin(),x.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF 1000000007 //1000000000000000003
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;



void Main(){

  int N;
  cin>>N;
  int M=pow(2,N);

  multiset<ll,greater<ll>> st;
  vector<ll> proded;

  rep(i,M){
    ll a;
    cin>>a;
    st.insert(a);
  }

  auto itr=st.begin();
  proded.emplace_back(*itr);
  st.erase(itr);

  rep(i,N){
    int x=pow(2,i);
    rep(j,x){
      itr=st.upper_bound(proded[j]);
      if(itr==st.end()){
        cout<< "No"<<"\n";
        return;
      }
      proded.emplace_back(*itr);
      st.erase(itr);
    }

  }

  cout<< "Yes"<<"\n";

}


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


Measured memory_bytes: 14708
#include<iostream>

using namespace std;

int main(){
        int n,k;
        int x,y;
        cin >> n >> k >> x >> y;
        int sum = 0;
        if(n >=k){
                sum += k*x + (n-k)*y;
        }else{
                sum += n*x;
        }
        cout << sum << endl;
        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll a, b, c, d, i, j, m, n;
  in2(a, b);
  c = d = 1;
  rep(k, a)
    c = c * 2;
  rep(k, b)
    d = d * 2;
  a = c / 2;
  b = d / 2;
  m = c;
  n = d;
  vector<vector<ll>> g(c, vector<ll> (d, 1));
  while(true){
    i = 0;
    if(a <= 1 || b <= 1)
      break;
    else{
      while(a + m * i < c){
        j = 0;
        while(b + n * j < d){
          g[a + m * i - 1][b + n * j - 1] = 0;
          j++;
        }
        i++;
      }
      if(a > 1){
        a = a / 2;
        m = m / 2;
      }
      if(b > 1){
        b = b / 2;
        n = n / 2;
      }
    }
  }
  rep(k, c - 1){
    rep(l, d - 1)
      out(g[k][l]);
    memi;
  }
}

Measured memory_bytes: 9472
#!/usr/bin/env python3

import sys

sys.setrecursionlimit(10**7)

# Override `input` function because `stdin.readline()` is 10x faster than built-in `input()`
input = sys.stdin.readline


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h(typ) if m > 1 else typ(input()) for _ in range(n)]


def main():
    S, = read_h(typ=str)
    n = len(S)

    MOD = 10**9 + 7

    dp = [[0] * 13 for _ in range(10**5 + 2)]
    dp[0][0] = 1
    #  print('initial dp:', dp)

    for i, s in enumerate(S):
        c = -1 if s == '?' else ord(s) - ord('0')
        #  print('c:', c)

        for j in range(10):
            if c != -1 and c != j:
                continue

            for k in range(13):
                dp[i + 1][(k * 10 + j) % 13] += dp[i][k]

            #  print('updated dp:', dp[:])

        for j in range(13):
            dp[i + 1][j] %= MOD

        #  print('final dp:', dp[:])

    res = dp[n][5]
    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 62556
def solve(low, n, ls):
    dp = [10 ** 20 for i in range(n + 1)]
    dp[0] = low
    for i in range(n):
        length = 0
        for j in range(i, -1, -1):
            length += ls[j]
            if i + 1 == n and j == 0:
                continue
            if length >= low:
                high = max(length, dp[j])
                dp[i+1] = min(dp[i+1], high)
    return dp[n] - low


def main():
    n = int(input())
    ls = [int(input()) for i in range(n)]
    ans = 10 ** 20
    for i in range(n):
        length = 0
        for j in range(i, n):
            length += ls[j]
            ans = min(ans, solve(length, n, ls))

    print(ans)


main()



Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
//cin.tie(0);
//ios::sync_with_stdio(false);



signed main(){
  ll n,m,ans=0;
  cin>>n>>m;
  vector<ll> x(n),y(n),z(n);
  for(int i=0;i < n;i++)
  {
    cin>>x[i]>>y[i]>>z[i];
  }
  
  for(int i=0;i < 2;i++)
  {
    for(int j=0;j < 2;j++)
    {
      for(int k=0;k < 2;k++)
      {
        vector<ll> v(n);
        ll a=0;
        for(int l=0;l < n;l++)
        {
          ll sum=0;
          if(i)sum+=x[l];
          else sum-=x[l];
          
          if(j)sum+=y[l];
          else sum-=y[l];
          
          if(k)sum+=z[l];
          else sum-=z[l];
          v.at(l)=sum;
        }
        sort(v.begin(),v.end());
        reverse(all(v));

        for(int t=0;t < m;t++)
        {
          a+=v[t];
        }
        ans=max(ans,a);
      }
    }
  }

  cout << ans << endl;
}         

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

int main(){
    int N, M;
    cin >> N >> M;
    long long xyz[1000][3];
    for(int i=0;i<N;i++){
        cin >> xyz[i][0] >> xyz[i][1] >> xyz[i][2];
    }
    //2**3のビット全探索
    long long ans = 0;
    int m = (1 << 3);
    for(int i=0;i<m;i++){
        long long sum[1000] = {0};
        for(int j=0; j<N; j++){
            for(int k=0;k<3;k++){
                if(((i >> k) & 1) == 1){
                    sum[j] += xyz[j][k];
                }else{
                    sum[j] -= xyz[j][k];
                }
            }
        }
        sort(sum, sum+N, greater<long long>());
        long long maxv = 0;
        for(int i=0;i<M;i++){
            maxv += sum[i];
        }
        ans = max(ans, maxv);
    }
    cout << ans;
    return EXIT_SUCCESS;
}

Measured memory_bytes: 256
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 19 + 7
EPS = 10 ** -10

S = list(input())
T = list(input())
N = len(S)
M = len(T)

def check(S, T):
    res = 0
    for i in range(M):
        if S[i] != T[i]:
            res += 1
    return res

ans = INF
for i in range(N-M+1):
    ans = min(ans, check(S[i:i+M], T))
print(ans)


Measured memory_bytes: 9544
import numpy as np
import itertools

n, d = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]

cnt = 0
for i1, i2 in itertools.product(range(n), range(n)):
    if i1 == i2:
        continue
    x1 = np.array(x[i1])
    x2 = np.array(x[i2])
    d = sum(list(map(lambda x : x ** 2, list(x1 - x2)))) ** 0.5
    if d == int(d):
        cnt += 1

print(int(cnt / 2))

Measured memory_bytes: 12540
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <assert.h>
#include <sys/time.h>
#include <fstream>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define REP(i,n)  FOR(i,0,n)
#define each(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define deb(x) cerr << #x << " = " << (x) << " , ";
#define debl cerr << " (L" << __LINE__ << ")"<< endl;
#define sz(s) (int)((s).size())


#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define MP(x,y) make_pair((x),(y))

double pi=3.14159265358979323846;

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

template<typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& z){
	os << "[ ";
	REP(i,z.size())os << z[i] << ", " ;
	return ( os << "]" << endl);
}

template<typename T> std::ostream& operator<<(std::ostream& os, const set<T>& z){
	os << "set( ";
	EACH(p,z)os << (*p) << ", " ;
	return ( os << ")" << endl);
}

template<typename T,typename U> std::ostream& operator<<(std::ostream& os, const map<T,U>& z){
	os << "{ ";
	EACH(p,z)os << (p->first) << ": " << (p->second) << ", " ;
	return ( os << "}" << endl);
}

template<typename T,typename U> std::ostream& operator<<(std::ostream& os, const pair<T,U>& z){
	return ( os << "(" << z.first << ", " << z.second << ",)" );
}

double get_time(){
	struct timeval tv;
	gettimeofday(&tv, NULL);
	return tv.tv_sec + tv.tv_usec*1e-6;
}

typedef unsigned int uint32_t;
struct RND{
	uint32_t x;
	uint32_t y;
	uint32_t z;
	uint32_t w;
	RND(){
		x=123456789;
		y=362436069;
		z=521288629;
		w=88675123;
	}
	void init(int seed){
		x=123456789;
		y=362436069;
		z=521288629;
		w=seed+100;
		REP(i,10)get();
	}
	uint32_t get(){
		uint32_t t;
		t=x^(x<<11);
		x=y;y=z;z=w;
		w=(w^(w>>19))^(t^(t>>8));
		return w;
	}
};
RND rnd;

void _main(istream &inp){
	vl seq;
	int n;
	inp >> n;
	rep(i,n){
		ll x;
		inp >> x;
		seq.push_back(x-i);
	}
	sort(seq.begin(), seq.end());
	ll ret = 0;
	rep(i,seq.size())ret += abs(seq[i] - seq[n/2]);
	cout << ret << endl;
}

int main(){
	if(0){
		ifstream ifs("test.txt");
		_main(ifs);
	}
	else{
		_main(cin);
	}
	return 0;
}


Measured memory_bytes: 2420
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);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        private static long MOD = (long) (1e9 + 7);
        private static int MAX = 400000;
        private static long[] xs = new long[MAX + 1];
        private static long[] ys = new long[MAX + 1];
        int N;
        int A;
        int B;
        int C;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            N = in.nextInt();
            A = in.nextInt();
            B = in.nextInt();
            C = in.nextInt();

            long ret = 0;
            long Awin = A * modpow(A + B, MOD - 2) % MOD;
            long Bwin = B * modpow(A + B, MOD - 2) % MOD;
            long num = (A + B + C) * modpow(A + B, MOD - 2) % MOD;

            for (int i = 0; i <= N - 1; i++) {
                ret += comb(N - 1 + i, i) * modpow(Awin, N) % MOD * modpow(Bwin, i) % MOD * (N + i) % MOD;
                ret += comb(N - 1 + i, i) * modpow(Bwin, N) % MOD * modpow(Awin, i) % MOD * (N + i) % MOD;
            }
            out.println(ret % MOD * num % MOD);
        }

        private long comb(int n, int r) {
            if (r < 0 || r > n) return 0;

            if (xs[0] == 0) {
                xs[0] = 1;
                for (int i = 1; i <= MAX; i++) {
                    xs[i] = xs[i - 1] * i % MOD;
                }
                long inv = modpow(xs[MAX], MOD - 2);
                ys[MAX] = inv;
                for (int i = MAX; i >= 1; i--) {
                    inv = inv * i % MOD;
                    ys[i - 1] = inv;
                }
            }

            return xs[n] * (ys[r] * ys[n - r] % MOD) % MOD;
        }

        private long modpow(long a, long n) {
            long r = 1;
            while (n > 0) {
                r = r * ((n % 2) != 0 ? a : 1) % MOD;
                a = a * a % MOD;
                n >>= 1;
            }
            return r;
        }

    }
}



Measured memory_bytes: 29140
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n, k; cin >> n >> k;
	vi a(n);
	rep(i, n) cin >> a[i];
	int g = 0;
	rep(i, n) g = __gcd(g, a[i]);
	rep(i, n) if(k <= a[i] && (a[i] - k) % g == 0){
		cout << "POSSIBLE" << endl;
		return 0;
	}
	cout << "IMPOSSIBLE" << endl;
	
	return 0;
}

Measured memory_bytes: 640
#pragma GCC optimize("O3")
#pragma GCC optimize("O1")
#pragma GCC optimize("O2")
#pragma GCC optimize("Os")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);
#define FO cout.tie(NULL);
#define FI cin.tie(NULL);
#define IN cin>>
#define OUT cout<<
#define loop(i,a,n) for(int i=a; i<n; i++)
#define rloop(i,a,n) for(int i=a; i>=n; i--)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define set_bits(a) __builtin_popcountll(a)
#define ll long long int
#define ld long double
#define vll vector<long long int>
#define pll pair<long long int, long long int>
#define mod 1000000007
#define M 998244353
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo)
{
    ll ans=1LL;
    while(power>0LL)
    {
        if(power%2LL==1LL)
        {
            ans=(ans*B)%modulo;
        }
        B=(B*B)%modulo;
        power/=2LL;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1LL)
    {
        return false;
    }
    if(n<=3LL)
    {
        return true;
    }
    if(n%2==0LL || n%3==0LL)
    {
        return false;
    }
    for(ll i=5LL; (i*i)<=n; i+=6LL)
    {
        if(n%i==0LL || n%(i+2LL)==0LL)
        {
            return false;
        }
    }
    return true;
}
using namespace std;
bool sortbysec(const pair<pair<int,int>,int> &a, const pair<pair<int,int>,int> &b)
{
    return (a.first.second<b.first.second);
}
bool sortbysecll(const pll &a, const pll &b)
{
    return (a.second<b.second);
}
ll modinv(ll x, ll y, ll modulo)
{
    return ((x%modulo)*(P(y,modulo-2LL,modulo)%modulo))%modulo;
}
void vok()
{
    FAST
    FO
    FI
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt","r",stdin);
    //     freopen("output.txt","w",stdout);
    // #endif
}
int main()
{
    vok();
    ll x;
    IN x;
    ll curr=100;
    ll ans=0;
    while(x>curr)
    {
        curr+=(curr*0.01);
        ans++;
    }
    OUT ans<<endl
    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define MAX 1000000007
using namespace std;
int main()
{
	int n,i,j,k;
	cin>>n;
	long long a[n+1][n+1];
	for(i=1;i<=n;i++)for(j=1;j<=n;j++)cin>>a[i][j];
	long long ans=0;
	
	for(k=1;k<=n;k++)
	{
		for(i=1;i<=n;i++)
		{
			for(j=1;j<=n;j++)
			{
				if(a[k][i]>a[k][j]+a[j][i])
				{
					cout<<"-1";
					return 0;
				}
			}
		}
	}
	
	for(i=1;i<=n;i++)
	{
		for(j=i+1;j<=n;j++)
		{
			ans+=a[i][j];
			for(k=1;k<=n;k++)
			{
				if(k!=i and k!=j and a[i][k]+a[k][j]==a[i][j])
				{
					ans-=a[i][j];
					break;
				
				}
			}	
		}
	}
	
	cout<<ans;
}

Measured memory_bytes: 1024
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args){
		
		long sunuke = 0;
		long arai = 0;
		long Min,Min0=0;
		long sum=0;
		Scanner sc =new Scanner(System.in);
		String Ns = sc.nextLine();
		int N = Integer.parseInt(Ns);
		String[] a = new String[N];
		String line = sc.nextLine();
		a = line.split(" ");
		
		long[] ia = new long[N];
		for(int j =0;j<N;j++){
		ia[j] = Long.parseLong(a[j]);
		sum = ia[j] + sum;
		}
		

		for(int i=0;i<N-1;i++){ 
			
			sunuke = ia[i] + sunuke;
			arai = sum - sunuke;			
			long sa = Math.abs(sunuke-arai);
			if(i==0){Min0 = sa;}
			Min = Math.min(Min0,sa);
			//if(Min==sa){Indexi = i;Indexj = j;}
			Min0 = Min;			
		}System.out.println(Min0);
		sc.close();
	}
}

Measured memory_bytes: 57488
import collections
N = int(input())
s = [input() for i in range(N)]

c = collections.Counter(s)
values, counts = zip(*c.most_common())

ss = []
for i in range(counts.count(max(counts))):
	ss.append(values[i])

ss.sort()

for sss in ss:
	print(sss)

Measured memory_bytes: 59504
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int N, M;
  cin >> N >> M;
  int MAX_X = 100000;
  vector<int> X(N);
  vector<int> cnt(MAX_X+1);
  rep(i, N) {
    cin >> X[i];
    cnt[X[i]]++;
  }
  vector<vector<deque<int>>> cnt2(M, vector<deque<int>>(2));
  rep(i, MAX_X+1) {
    rep(j, cnt[i]%2) cnt2[i%M][0].push_back(i);
    rep(j, cnt[i]/2*2) cnt2[i%M][1].push_back(i);
  }
  rep(i, M) {
    while(!cnt2[i][1].empty()) {
      cnt2[i][0].push_back(cnt2[i][1].front());
      cnt2[i][1].pop_front();
    }
  }
  int ans = 0;
  for(int i=0; i<=M/2; i++) {
    if(i == 0 || i == M-i) {
      while(cnt2[i][0].size() >= 2) {
        ans++;
        cnt2[i][0].pop_front();
        cnt2[i][0].pop_front();
      }
    } else {
      while(!cnt2[i][0].empty() && !cnt2[M-i][0].empty()) {
        ans++;
        cnt2[i][0].pop_front();
        cnt2[M-i][0].pop_front();
      }
    }
  }
  rep(i, M) {
    map<int, int> cnt3;
    while(!cnt2[i][0].empty()) {
      cnt3[cnt2[i][0].front()]++;
      cnt2[i][0].pop_front();
    }
    for(auto m: cnt3) {
      ans += m.second / 2;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int gcd(int a, int b) {
	if(b > a){
		int j = a;
		a = b;
		b = j;
	}
	int r;
	while((r = a % b) != 0)
		{ a = b; b = r; }
	return b;
}

int main(void){
    int a, b;
    while(cin >> a >> b) {
      int lcm = a / gcd(a,b) * b;
      cout << gcd(a,b) << " " << lcm << endl;
    }
    return 0;
}



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

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

  vector<int> cnt(M);
  for (int i = 0; i < N; i++) {
    int K;
    cin >> K;
    for (int j = 0; j < K; j++) {
      int A;
      cin >> A;
      A--;
      cnt[A]++;
    }
  }

  int ans = 0;
  for (int i = 0; i < M; i++) {
    if (cnt[i] == N) {
      ans++;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
import numpy as np
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    md = 998244353
    n = int(input())
    mx = 90005
    dp = np.zeros(mx, dtype="i8")
    dp2 = np.zeros(mx, dtype="i8")
    dp[0] = 1
    dp2[0] = 1
    sum_a = 0
    for _ in range(n):
        a = int(input())
        sum_a += a
        dp[mx - 1:a - 1:-1] = dp[mx - 1:a - 1:-1] * 2 + dp[mx - a - 1::-1]
        dp[:a] *= 2
        dp %= md
        dp2[mx - 1:a - 1:-1] += dp2[mx - a - 1::-1]
        dp2 %= md
    ng = np.sum(dp[(sum_a + 1) // 2:]) - np.sum(dp2[(sum_a + 1) // 2:]) * 2 + 1
    ng %= md
    total = (pow(3, n, md) - 3 * pow(2, n, md) + 3) % md
    print((total - ng * 3) % md)
    # ALL-NG（NG…最大辺が周の半分以上になる）で求める
    # 最大辺を赤として、dp[r] 赤の和がrのパターンを求める
    # 「赤だけ」、「赤と他一色だけ」(両方dp2に含まれる)のパターンは除く必要がある
    # 赤の和が総和の半分以上になるパターンを考えるので、
    # 赤以外の色だけになるパターンは除く必要がない
    # その後、緑、青が最大の辺になる場合も考えて3倍

main()


Measured memory_bytes: 24200
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    int A, B, C;

    scanf("%d%d%d", &A, &B, &C);

    if(A == B){
        printf("%d\n", C);
    }else if(B == C){
        printf("%d\n", A);
    }else{
        printf("%d\n", B);
    }

    return 0;
}

Measured memory_bytes: 1728
N,M,C = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)
res = 0
N.times do |i|
    w = gets.split.map(&:to_i)
    x = C
    w.each_with_index do |a,j|
        x += a * B[j]
    end
    res += 1 if x > 0
end
puts res

Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF=1e18,MOD=1e9+7;
int main(){
	ll 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)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>

using namespace std;
#define copy(a, b) number[a - 1] = temp[b - 1];

class Dice {
public:
	Dice() {
		for (int i = 0; i < 6; i++)
			cin >> number[i];
	}

	void rotate(char c) {
		int temp[6];
		for(int i = 0; i < 6; i++)
			temp[i] = number[i];
		switch (c) {
		case 'E':
			copy(1, 4);
			copy(4, 6);
			copy(6, 3);
			copy(3, 1);
			break;
		case 'W':
			copy(1, 3);
			copy(3, 6);
			copy(6, 4);
			copy(4, 1);
			break;
		case 'N':
			copy(5, 1);
			copy(1, 2);
			copy(2, 6);
			copy(6, 5);
			break;
		case 'S':
			copy(2, 1);
			copy(1, 5);
			copy(5, 6);
			copy(6, 2);
			break;
		}
	}
	void print(int x) {
		cout << number[x - 1] << endl;
	}

private:
	int number[6];
};

int main() {
	Dice d;
	char com[101];
	cin >> com;

	for (int i = 0; i < strlen(com); i++) 
		d.rotate(com[i]);
	d.print(1);

}
		


Measured memory_bytes: 3104
#include<cstdio>
using namespace std;
typedef long long ll;

ll n, p[100], q[100], r[100], b[100];
bool isTop[100];

ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}

ll check(ll num) {
  ll left = 1, right = 1;
  if (r[num] != -1) left = check(r[num]);
  if (b[num] != -1) right = check(b[num]);
  ll g = gcd(p[num], q[num]);
  p[num] /= g;
  q[num] /= g;
  left /= gcd(q[num], left);
  right /= gcd(p[num], right);
  ll temp = left * right / gcd(left, right);
  return (p[num] + q[num]) * temp;
}

int main() {
  while (1) {
    scanf("%lld", &n);
    if (n == 0) break;
    for (ll i = 0; i < n; i++) isTop[i] = true;
    for (ll i = 0; i < n; i++) {
      scanf("%lld%lld%lld%lld", &p[i], &q[i], &r[i], &b[i]);
      r[i]--, b[i]--;
      if (r[i] != -1) isTop[r[i]] = false;
      if (b[i] != -1) isTop[b[i]] = false;
    }
    ll top;
    for (ll i = 0; i < n; i++) if (isTop[i]) { top = i; break; }
    printf("%lld\n", check(top));
  }
}



Measured memory_bytes: 2620
#include<stdio.h>
int main(){
	char a[110];
	int i, b[50]={},t=1;
	scanf("%s",a);
	for(i=0;a[i]!='\0';i++){
		b[a[i]-'a']++;
	}
	for(i=0;i<40;i++){
		if(b[i]%2!=0) t=0;
	}
	if(t==1)printf("Yes\n");
	else printf("No\n");
}

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

using namespace std;
typedef long long ll;

#define out(ans) cout << ans << endl
#define in(n) cin >> n
#define floop(i, N) for (ll i = 0; i < N; i++)
#define floop1(i, N) for (ll i = 1; i <= N; i++)
#define floopi(i, j, N) for (ll j = i + 1; j < N; j++)

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

constexpr int inf = 1e9;
constexpr ll linf = 1e18;

void solve();

int main()
{
    solve();
}

void solve()
{
    int n;
    string s, t;
    cin >> n >> s >> t;
    floop(i, n)
    {
        cout << s[i] << t[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.stream.*;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = in.nextInt();
		}
		Arrays.sort(a);
		System.out.println(a[n - 1] - a[0]);
	}
}

Measured memory_bytes: 23764
#include<cstdio>
#include<algorithm>

using namespace std;

int dp[150][150000];
int sum[150][150000];

int a[150];

const int MOD=1e9+7;

int main()
{
  int n=0,k=0;scanf("%d%d",&n,&k);for(int i=1;i<=n;i++)scanf("%d",&a[i]);
  dp[0][0]=1;for(int i=0;i<=k;i++)sum[0][i]=1;
  for(int i=1;i<=n;i++)
  {
    for(int j=0;j<=k;j++)
    {
      int l=max(0,j-a[i]);
      if(l==0)dp[i][j]=sum[i-1][j];
      else dp[i][j]=(sum[i-1][j]+MOD-sum[i-1][l-1])%MOD;
    }
    sum[i][0]=dp[i][0];for(int j=1;j<=k;j++)sum[i][j]=(sum[i][j-1]+dp[i][j])%MOD;
  }
  printf("%d",dp[n][k]);
  return 0;
}

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

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

  int n, a[3];
  cin >> n >> a[0] >> a[1] >> a[2];

  vector<string> q(n);
  for (auto& e: q) cin >> e;

  vector<char> result;

  for (int i = 0; i < n; ++i) {
    string s = q[i];

    int x = s[0] - 'A';
    int y = s[1] - 'A';
    if (!a[x] && !a[y]) {
      result.clear();
      break;
    }

    if (a[x] > a[y]) {
      --a[x]; ++a[y];
      result.push_back(s[1]);
      continue;
    }

    if (a[x] < a[y]) {
      ++a[x]; --a[y];
      result.push_back(s[0]);
      continue;
    }

    if (i + 1 < n && q[i + 1].find(s[0]) != string::npos) {
      ++a[x]; --a[y];
      result.push_back(s[0]);
      continue;
    }

    --a[x]; ++a[y];
    result.push_back(s[1]);
  }

  if (result.empty()) {
    cout << "No\n";
    return 0;
  }

  cout << "Yes\n";
  for (char c: result)
    cout << c << '\n';
}


Measured memory_bytes: 6672
A, B, C, K = map(int, input().split())

if K % 2 == 0:
    if abs(A - B) >= int(1e18):
        print("Unfair")
    else:
        print(A - B)
else:
    if abs(A - B) >= int(1e18):
        print("Unfair")
    else:
        print(B - A)

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

typedef long long ll;

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

    int N;
    cin >> N;

    vector<int> s(N + 1);

    for(int i = 2; i <= N; i++) {
        int x = i;
        for(int j = 2; j * j <= x; j++) {
            if(x % j == 0) {
                while(x % j == 0) {
                    x /= j;
                    s[j]++;
                }
            }
        }
        if(x != 1) s[x]++;
    }

    vector<vector<int> > dp(N + 1, vector<int>(76));

    dp[1][1] = 1;

    for(int i = 2; i <= N; i++) {
        for(int j = 1; j < 76; j++)
            dp[i][j] = dp[i - 1][j];
        
        for(int j = 0; j < s[i]; j++) {
            for(int k = 1; k < 76; k++) {
                int x = k * (j + 2);
                if(x > 75) break;
                dp[i][x] += dp[i - 1][k];
            }
        }
    }

    cout << dp[N][75] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=3e5;
const int inf=1e9;
int N,M;
vector<pair<int,int>> g[size];
int d[size] = {};
void dijkstra(int* dist, int a){// O(NlogN+M)
	priority_queue<pair<int,int>> pq;
	rep(i,0,3*N){
		dist[i] = inf;
		pq.push({-dist[i], i});
	}
	dist[a] = 0; pq.push({0, a});
	int v,m; int temp;
	while(!pq.empty()){
		v = pq.top().second / 3;
		m = pq.top().second % 3;
		pq.pop();
        int u;
		for(pair<int,int> p:g[v]){
            u = 3 * p.first + (m + 1) % 3;
			temp = dist[3 * v + m] + p.second;
			if(dist[u] > temp){
				dist[u] = temp;
				pq.push({-dist[u], u});
			}
		}
	}return;
}
int main(){
    cin>>N>>M;
	int a,b;
	rep(i,0,M){
		cin>>a>>b; a--; b--;
		g[a].push_back({b, 1});
	}
	int s,t; cin>>s>>t; s--; t--;
	dijkstra(d, 3 * s);
	if(d[3 * t] == inf) cout<<-1<<endl;
    else cout<<d[3 * t] / 3<<endl;
}

Measured memory_bytes: 17260
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)

	r, g, b := getInt(), getInt(), getInt()

	n := r*100 + g*10 + b

	if n%4 == 0 {
		out("YES")
	} else {
		out("NO")
	}

}


Measured memory_bytes: 640
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int main()
{
	int h,n,a;cin>>h>>n;
	rep(i,n){
		cin>>a;h-=a;
	}
	if(h<=0) cout<<"Yes"<<endl;else cout<<"No"<<endl;
}


Measured memory_bytes: 256
import numpy as np
from numba import *

@njit('i8(i8,i8[:])', cache=True)
def solve(x,count):
    for i in range(2,x+1):
        for j in range(i,x+1,i):
            count[j] += 1
    return int(np.sum(np.arange(x+1)*count))

if __name__== "__main__":
    x = int(input())
    count = np.ones(x + 1, dtype=np.int64)
    print(solve(x,count))

Measured memory_bytes: 340884