akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int [] dice = new int [6];
        for(int x = 0; x < 6; x++){
            dice[x] = scan.nextInt();
        }
        String d = scan.nextLine();
        d = scan.nextLine();
        for (int x = 0; x < d.length();x++){
            dice = roll(d.charAt(x),dice);
        }
        System.out.println(dice[0]);
    }
    public static int[] roll(char s, int dice[]){
        if(s == 'E'){
            int hold = dice[0];
            dice[0] = dice[3];
            dice[3] = dice[5];
            dice[5] = dice[2];
            dice[2] = hold;
        }
        else if(s == 'N'){
            int hold = dice[0];
            dice[0] = dice[1];
            dice[1] = dice[5];
            dice[5] = dice[4];
            dice[4] = hold;
        }
        else if(s == 'S'){
            int hold = dice[0];
            dice[0] = dice[4];
            dice[4] = dice[5];
            dice[5] = dice[1];
            dice[1] = hold;
        }
        else if(s == 'W'){
            int hold = dice[0];
            dice[0] = dice[2];
            dice[2] = dice[5];
            dice[5] = dice[3];
            dice[3] = hold;

        }
        return dice;
    }
}


Measured memory_bytes: 26388
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define ll long long int

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(auto &x:a)cin>>x;
    auto get_sum=[&](int l,int r){
        ll s=0;
        for(int i=l;i<=r;i++){
            s+=a[i];
        }
        return s;
    };
    vector<vector<ll>> dp(n+1,vector<ll> (n+1));
    for(int L=n-1;L>=0;L--){
        for(int R=L;R<n;R++){
            debug(L,R);
            if(L==R){
                dp[L][R]=0;
                continue;
            }
            ll su=get_sum(L,R);
            dp[L][R]=1e18;
            for(int i=L;i<R;i++){
                //debug(dp[L][i],dp[i+1][R],su);
                dp[L][R]=min(dp[L][R],dp[L][i]+dp[i+1][R]+su);
            }
        }
    }
    cout<<dp[0][n-1]<<"\n";
    return 0;
}


Measured memory_bytes: 4860
#include <iostream>
#include <algorithm>
using namespace std;
double n, m, a[200], sum;
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  sort(begin(a), end(a), greater<>());
  // cout << a[int(m)-1] << ' ' << sum/(4.0*m) << ' ' << sum << endl;
  if (a[int(m)-1] < (sum/(4.0*m))){
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e18;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

int main(){
    ll N, K; cin >> N >> K;
    vl hs(N, 0); REP(i, N) cin >> hs[i];
    sort(hs.begin(), hs.end());
    ll ret = LINF;
    REP(i, N-K+1){
        ret = min(ret, hs[i+K-1]-hs[i]);
    }
    cout << ret << endstr;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
ll const mod=998244353;
const ll MAX=300000;
using vi=vector<int>;
using vc=vector<char>;
using vs=vector<string>;
using vvi =vector<vector<int>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
int main(){
    ll n,m;
    cin>>n>>m;
    int w=0,a=0;
    vi wc(n+1);
    vi test(n+1);
    rep(i,m){
        int num;
        string s;
        cin>>num>>s;
        if(s=="WA"&&test[num]==0){
            wc[num]++;
        }
        if(s=="AC"&&test[num]==0){
            w+=wc[num];
            a++;
            test[num]=1;
        }
        
    }
    cout<<a<<" "<<w<<endl;
    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    
    vector<int> vx(n+1), vy(m+1);
    
    for (int i = 0; i < n; i++) cin >> vx[i];
    for (int i = 0; i < m; i++) cin >> vy[i];
    
    vx[n] = x;
    vy[m] = y;
    
    sort(vx.begin(), vx.end());
    sort(vy.begin(), vy.end());
    
    if (vx[n] < vy[0]) cout << "No War" << endl;
    else cout << "War" << endl;
    
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int n,m,k;
int mp[1005][1005],v[1005][1005];
char s[1005];
int sx,sy;
int k1[]={0,0,1,-1};
int k2[]={1,-1,0,0};
struct node
{
	int x,y;
	node(){;}
	node(int _x,int _y)
	{
		x=_x;y=_y;
	}
};
queue<node>q;
void bfs()
{
	q.push(node(sx,sy));
	int ans=0x3f3f3f3f;
	v[sx][sy]=0;
	while(!q.empty())
	{
		node tmp=q.front();q.pop();
		int step=min(min(tmp.x-1,tmp.y-1),min(n-tmp.x,m-tmp.y));
		if(!step)ans=1;
		else ans=min(ans,(step-1)/k+2);
		if(v[tmp.x][tmp.y]==k)continue;
		for(int i=0;i<=3;i++)
		{
			int xx=tmp.x+k1[i],yy=tmp.y+k2[i];
			if(xx>=1&&xx<=n&&yy>=1&&yy<=m&&!mp[xx][yy]&&v[xx][yy]==-1)
			{
				v[xx][yy]=v[tmp.x][tmp.y]+1;
				q.push(node(xx,yy));
			}
		}
	}
	cout<<ans<<endl;
	return ;
}
int main()
{
	memset(v,-1,sizeof(v));
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%s",s+1);
		for(int j=1;j<=m;j++)
		{
			if(s[j]=='S')sx=i,sy=j;
			else if(s[j]=='#')mp[i][j]=1;
		}
	}
	bfs();
	return 0;
}


Measured memory_bytes: 7296
#include <iostream>
using namespace std;
int main(void){
    int n,k;
    
    cin>>n>>k;
    
    long long x[n], y[n];
    long long xm=0,ym=0;
    
    for (int i=0;i<n;i++){
        cin>>x[i]>>y[i];
        xm=max(xm,abs(x[i]));
        ym=max(ym,abs(y[i]));
    }
    long long ans=xm*ym*4;
    for (int x1=0;x1<n;x1++){
        for (int x2=x1;x2<n;x2++){
            for (int y1=0;y1<n;y1++){
                for (int y2=y1;y2<n;y2++){
                    int cnt=0;
                    for (int i=0;i<n;i++){
                        if (min(x[x1],x[x2])<=x[i] and x[i]<=max(x[x1],x[x2]) and min(y[y1],y[y2])<=y[i] and y[i]<=max(y[y1],y[y2])){
                            cnt+=1;
                        }
                            
                    if (cnt>=k) ans=min(ans,abs(x[x2]-x[x1])*abs(y[y2]-y[y1]));
                    }
                }
            }
        }
    }
 
    cout<<ans<<endl;
}



Measured memory_bytes: 256
#include<stdio.h>

using namespace std;

int addf(int a,int b)
{
    int c;
    c=a+b;
    return c;
}

int digitcountf(int n)
{   int x,count= 0;

    while(n>0)
    {
    x=n%10;
    count++;
    n=n/10;
    }
    return count;
 }

int main ()
{
    long long int n,m,a,d;
    while (scanf("%lld %lld",&n,&m)==2)
    {
        a = addf(n,m);
        d = digitcountf(a);
        printf("%lld\n",d);

    }




return 0;
}

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

typedef unsigned long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;

#define INF (int)(1e9)

#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,start,end) for(int i=(start);i<=(end);i++)
#define all(n) begin(n),end(n)

#define DEBUG

int main()
{
	int a, b;
	cin >> a >> b;

	if(a > b) cout << a-1 << endl;
	else cout << a << endl;
	return 0;
}

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

using namespace std;

int main(){
  long double a,b,c;
  long double sa,sb,sc;

  cin >> a >> b >> c;
  
  long double x = (c-a-b)*(c-a-b) - 4 * a*b;
  
  string ans;
  if(x > 0 && c - a - b > 0){
    ans = "Yes";
  } else { 
    ans = "No";
  }
  cout << ans << endl;
}

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

int main(){
	int N;
	cin >> N;
	int t[N], x[N], y[N], i;
	t[0]=0; x[0]=0; y[0]=0;
	for(i=1; i<=N; i++){
		cin >> t[i] >> x[i] >> y[i];
	}
	int gapt, gapx, gapy, ecount=0;
	
	for(i=0; i<N; i++){
		gapt = t[i+1]-t[i];
		gapx = abs(x[i+1]-x[i]);
		gapy = abs(y[i+1]-y[i]);
		if(gapx+gapy-gapt > 0)	ecount++;
		else if((gapt-(gapx+gapy))%2 == 0);
		else ecount++;
	}
	
	if(ecount==0)	cout << "Yes" << endl;
	else		cout << "No" << endl;
	
	return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#include<stack>
#include<string.h>
#include <iomanip>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
	string s;
	cin >> s;
	int cnt_1 = 0;
	int cnt_0 = 0;
	rep(i,s.size()) {
		if(s[i] == '1') cnt_1++;
		else ++cnt_0;
	}
	int ans = min(cnt_0,cnt_1)*2;
	if(s.size()==1) cout << 0 << endl;
	else cout << ans <<endl;
	
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define int long long
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB push_back
#define PF push_front
#define FILL(a,b) memset(a,b,sizeof(a))
using namespace std;
int dfs(int n){
	if(n==0)return 0;
	int t=dfs(n/2);
	return (t<<1)+1;
}
signed main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
	int n;
	cin>>n;
	cout<<dfs(n);
	RE 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
random_device rnd;
mt19937 mt(rnd());

const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;
int n, m;
int dist(int x, int y)
{
    return min(abs(x - y), n - abs(x - y));
}
int main()
{
    cin >> n >> m;
    int half;
    if (m % 2 == 1)
    {
        half = n / 2 - 1;
    }
    else
    {
        half = n / 2;
    }
    int a = 0, b = half, c = half + 1, d = n - 1;
    if (n % 2 == 0)
        a++;

    rep(i, m)
    {
        if (a + 1 < b)
        {
            cout << a + 1 << " " << b + 1 << endl;
            cerr << dist(a + 1, b + 1) << endl;

            a++;
            b--;
        }
        else
        {
            cout << c + 1 << " " << d + 1 << endl;
            cerr << dist(c + 1, d + 1) << endl;

            c++;
            d--;
        }
    }
    return 0;
}


Measured memory_bytes: 3608
#include<stdio.h>
#include<math.h>
 
int main(){
  double a,b,c,s,l,h;
 
  scanf("%lf%lf%lf",&a,&b,&c);
 
  s=a*b*sin(c/180.0*M_PI)/2.0;
  l=sqrt(a*a+b*b-2.0*a*b*cos(c/180.0*M_PI))+a+b;
  h=2.0*s/a;
 
  printf("%f\n%f\n%f\n",s,l,h);
  return 0;
}

Measured memory_bytes: 648
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <list>
#include <map>

using namespace std;
typedef long long ll;

int main() {
    int N,K;
    cin >> N >> K;
    string S;cin >> S;
    S[K-1]+=-'A'+'a';
    cout << S << endl;
}

Measured memory_bytes: 256
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1;
	while (b) {
		if (b & 1) { res = res * a%MOD; }
		a = a * a%MOD;
		b >>= 1;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑

int main() {
	int n, k[105], ans = 1, mon = INF;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> k[i];
	}
	sort(k, k + n);
	for (int i = 1; i < n; ++i) {
		if (k[i] > k[i - 1]) { ++ans; }
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
  long int a,b;
  long int v,w;
  long int t;
  long int x,y;

  scanf("%ld %ld",&a,&v);
  scanf("%ld %ld",&b,&w);
  scanf("%ld",&t);

  x = a - b;
  if(x<0) x *= -1;

  y = v - w;

  if(y<=0)
  {
    printf("NO\n");
    return 0;
  }

  if(x/y<t || (x/y==t && x%y==0))
  {
    printf("YES\n");
  }
  else
  {
    printf("NO\n");
  }

  return 0;
}

Measured memory_bytes: 1664
n,k = gets.split(' ').map(&:to_i)
nums = gets.split(' ').map(&:to_i)

nums.each_with_index do |num, index|
  if index < k
    next
  end
  if nums[index-k] < num
    puts 'Yes'
  else
    puts 'No'
  end
end

Measured memory_bytes: 33956
#include <iostream>
#include <queue>
using namespace std;
typedef pair<int,int> P;

#define INF 1000000

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int d[1100][1100];
char store[1100][1100];

bool bfs(int w,int h,int sy,int sx,int gy,int gx){
	queue<P> que;
	d[sy][sx]=0;
	que.push(P(sy,sx));
	
	while(que.size()){
		P p=que.front();que.pop();
		if(p.first==gy&&p.second==gx) break;
	
		for(int i=0;i<4;i++){
			int ny=p.first+dy[i],nx=p.second+dx[i];
			if(ny>=0 && nx>=0 && ny<h && nx<w && store[ny][nx]!='#' && d[ny][nx]==INF){
				d[ny][nx]=d[p.first][p.second]+1;
				que.push(P(ny,nx));
			}
		}
	}
	
	return d[gy][gx]!=INF;
}

int main(){
	int w,h,n;
	int gx,gy;
	bool flag=false;
	P open[1100];
	cin>>w>>h;
	
	/*for(int i=0;i<1100;i++){
		for(int j=0;j<1100;j++){
			store[i][j]='#';
		}
	}*/
	
	for(int i=0;i<1100;i++){
		for(int j=0;j<1100;j++){
			d[i][j]=INF;
		}
	}

	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>store[i][j];
			if(store[i][j]=='t'){
				gx=j;gy=i;
			}
		}
	}
	
	cin>>n;
	for(int i=1;i<=n;i++){
		int x,y;
		cin>>x>>y;
		open[i]=P(y,x);
	}
	
	for(int i=0;i<=n;i++){
		if(i>0){
			store[open[i].first][open[i].second]='.';
			for(int j=0;j<4;j++){
				int ny=open[i].first+dy[j],nx=open[i].second+dx[j];
				if(ny>=0 && nx>=0 && ny<h && nx<w && d[ny][nx]!=INF) flag=true;
			}
		}
		if((i==0 && bfs(w,h,0,0,gy,gx)) || (i>0 && flag && bfs(w,h,open[i].first,open[i].second,gy,gx))) {
			cout<<i<<endl;
			return 0;
		}
		flag=false;
	}
	cout<<-1<<endl;
	return 0;
}

			

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

int main(void)
{
    int a[3],b,c,i,j,k,n;
    cin >> a[0] >> a[1] >> a[2] >> n;

    if( abs(a[0]-a[2]) <= n ) cout << "Yes";
    else{
        sort(a,a+3);
        if(a[1]-a[0]>n || a[2]-a[1]>n) cout << "No";
        else cout << "Yes";
    }

    return 0;
}

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

using namespace std;





int  main() {
    
 int n;
 cin>>n;
 vector< int> arr(n);
  long long res =0;
 for(int i=0;i<n;i++)
 {
     cin>>arr[i];
     
 }
 
//   for(int i=0;i<n;i++)
//  {
//      cout<<arr[i];
     
//  }
 
//  cout<<endl;
 
  for(int i=1;i<n;i++)
 {
    if(arr[i] < arr[i-1])
    {
       // cout<<arr[i]<<"--> "<<arr[i-1]<<endl;
        
        int diff = (arr[i-1]- arr[i]) ;
        arr[i] = arr[i-1];
        //cout<<"diff : "<<diff<<endl;
        res = res+diff;
    }
     
 }

cout<<res<<endl;
 
  
    return 0;
   
}

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

using ll = long long;

const ll MOD = 1e9+7;

int main() {
   // 入力
   int H, W, K;
   cin >> H >> W >> K;

   // DPテーブルを初期化する
   ll dp[H+1][W];
   fill(dp[0], dp[H+1], 0);
   dp[0][0] = 1;

   for (int h = 0; h < H; h++) { // それぞれの高さについてループを回す
      for (int mask = 0; mask < (1<<(W-1)); ++mask) { // bit全探索のループ

         // 横線が隣り合っていないかチェック
         bool ok = true;
         for (int i = 0; i < W-2; ++i) {
            // これで末尾が11のときにはじくことが出来る
           if (((mask >> i) & 3) == 3) ok = false;
         }
         // 隣り合っていたらこの先の処理を飛ばす
         if (!ok) continue;

         for (int i = 0; i < W; i++) {
            // 横線を見つける
            if ((i < W) && ((mask >> (W - (i+2)))&1)) { // 右と左の遷移
               // 右への遷移と左への遷移を一気に処理する
               dp[h+1][i+1] += dp[h][i];
               dp[h+1][i+1] %= MOD;
               dp[h+1][i] += dp[h][i+1];
               dp[h+1][i] %= MOD;
               i++;
            } else { // まっすぐの遷移:
               dp[h+1][i] += dp[h][i];
               dp[h+1][i] %= MOD;
            }
         }
      }
   }

   cout << dp[H][K-1] << endl;

   return 0;
}

Measured memory_bytes: 256
N = int(input())

A = []
B = []
for i in range(N):
    a,b = list(map(int,input().split()))
    A.append(a)
    B.append(b)

ans=0    
for i in range(N):
    if (A[N-i-1]+ans)%B[N-i-1]!=0:
        ans += B[N-i-1]-(A[N-i-1]+ans)%B[N-i-1]
print(ans)

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

//#include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// using cint = cpp_int;
//#define input(a) scanf("%lld", &(a))
//#define output(a) printf("%lld\n", (a))

// Define
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll MOD = 1e9 + 7;
const ll INF = LONG_MAX;
const ull MAX = ULONG_MAX;
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define endl '\n'
#define space ' '
#define def inline auto
#define func inline constexpr ll
#define run __attribute__((constructor)) def _
#define all(v) begin(v), end(v)

// Debug
#define debug(...)                                                             \
    {                                                                          \
        cerr << __LINE__ << ": " << #__VA_ARGS__ << " = ";                     \
        for (auto &&X : {__VA_ARGS__}) cerr << "[" << X << "] ";               \
        cerr << endl;                                                          \
    }

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i <= _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i >= _##i; --i)
#define each(i, a) for (auto &&i : a)
#define rep(i, n) inc(i, 0, n - 1)

// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)

// Speed
run() { fasten, fout(10); }
#pragma GCC optimize("O3")
#pragma GCC optimization_level 3
#pragma GCC target("avx")

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

def input() {
    ll A;
    cin >> A;
    return A;
}

ll N, T, A, H[1000];
double D[1000];

signed main() {
    cin >> N >> T >> A;
    rep(i, N) cin >> H[i], D[i] = abs(T - double(H[i]) * 0.006 - A);
    cout << min_element(D, D + N) - D + 1 << endl;
}

// for compilation: g++ -Ofast -march=native -o _ _.cpp -std=c++17


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        long[] b = new long[n];
        long[] c = new long[n];
        long ans = 0;
        for (int i = 0; i < n; i++) a[i] = sc.nextLong();
        for (int i = 0; i < n; i++) b[i] = sc.nextLong();
        for (int i = 0; i < n; i++) c[i] = sc.nextLong();
        Arrays.sort(a);
        Arrays.sort(b);
        Arrays.sort(c);
        int cidx = 0;
        long[] sum = new long[n];
        for (int i = 0; i < n; i++) {
            while(cidx < n && b[i] >= c[cidx]) cidx++;
            sum[i] = n - cidx;
            if(i != 0) sum[i] += sum[i - 1];
        }
        int bidx = 0;
        for (int i = 0; i < n; i++) {
            while(bidx < n && a[i] >= b[bidx]) bidx++;
            if(bidx == n) break;
            ans += sum[n-1];
            if(bidx != 0) ans -=  sum[bidx-1];
        }

        System.out.println(ans);
        sc.close();
    }

}


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

int main(){
	string a, b, c;
	cin >> a >> b >> c;
	if(a[a.size()-1]==b[0] && b[b.size()-1]==c[0])
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdbool.h>
#include<math.h>
#define MAX 1000
#define VMAX 10000
int n,A[MAX],s;
int B[MAX], T[VMAX+1];
 
void swap(int *a,int *b) {
  int temp;
  temp = *a;
  *a = *b;
  *b = temp;
}
void qsort(int X[], int left, int right){
  int i,j;
  int pivot;
  i=left;j=right;
  pivot = X[(left+right)/2];
 
  while(1) {
    while(X[i]<pivot)i++;
    while(pivot<X[j])j--;
    if(i>=j) break;
 
    swap(&X[i],&X[j]);
    i++;  j--;
  }
  if(left < i-1) qsort(X,left,i-1);
  if(j+1<right) qsort(X,j+1,right);
}
int solve() {
  int i;
  int ans = 0;
 
  bool V[MAX];
  for(i=0;i<n;i++){
    B[i] = A[i];
    V[i]=false;
  }
  qsort(B,0,n-1);
  for(i=0;i<n;i++) T[B[i]] = i;
  for(i=0;i<n;i++) {
    if(V[i]) continue;
    int cur=i;
    int S=0;
    int m=VMAX;
    int an=0;
    while(1) {
      V[cur] = true;
      an++;
      int v = A[cur];
      m = fmin(m,v);
      S+=v;
      cur=T[v];
      if(V[cur])break;
    }
    ans+=fmin(S+(an - 2) * m , m+S+(an+1)*s);
 
  }
  return ans;
}
int main(){
  int i;
  scanf("%d",&n);
  s=VMAX;
  for(i=0;i<n;i++) {
    scanf("%d",&A[i]);
    s=fmin(s , A[i]);
  }
  int ans = solve();
  printf("%d\n", ans);
 
  return 0;
}

Measured memory_bytes: 620
#include<cstdio>
#include<cstring>
using namespace std;

int main(){
	int a,b,c;
	while(scanf("%d%d%d",&a,&b,&c)==3){
		if(a==b)printf("%d\n",c);
		else if(a==c)	printf("%d\n",b);
		else printf("%d\n",a);
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2050;
int n = 0, m = 0, fir[maxn], nxt[maxn << 1], to[maxn << 1];
bool hav[maxn]; int hei[maxn], siz[maxn], dp[maxn], tot[maxn];
void dfs1(int x, int fa = 0) {
	hei[x] = hei[fa] + 1, siz[x] = 0;
	if(hav[x]) tot[x] = 1;
	for(int i = fir[x]; i; i = nxt[i]) {
		int y = to[i];
		if(y == fa) continue;
		dfs1(y, x);
		siz[x] += siz[y] + tot[y];
		tot[x] += tot[y];
	}
}
void dfs2(int x, int fa = 0) {
	int t = 0;
	for(int i = fir[x]; i; i = nxt[i]) {
		int y = to[i];
		if(y == fa) continue;
		dfs2(y, x);
		if((siz[y] + tot[y]) > (siz[t] + tot[t])) t = y;
	}
	if((siz[t] + tot[t]) * 2 <= siz[x]) {
		dp[x] = siz[x] / 2;
	} else {
		dp[x] = (siz[x] - (siz[t] + tot[t])) + min(2 * dp[t], (siz[t] + tot[t]) * 2 - siz[x]) / 2;
	}
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> n;
	{
		char str[maxn];
		cin >> str;
		for(int i = 1; i <= n; i++) {
			hav[i] = (str[i - 1] == '1');
			m += (str[i - 1] == '1');
		}
	}
	for(int i = 1, j = 0; i < n; i++) {
		int a = 0, b = 0;
		cin >> a >> b;
		j++, nxt[j] = fir[a], fir[a] = j, to[j] = b;
		j++, nxt[j] = fir[b], fir[b] = j, to[j] = a;
	}
	int ans = 100000000;
	for(int i = 1; i <= n; i++) {
		memset(hei, 0, sizeof hei);
		memset(siz, 0, sizeof siz);
		memset(dp, 0, sizeof dp);
		memset(tot, 0, sizeof tot);
		dfs1(i, 0);
		if(siz[i] & 1) continue;
		dfs2(i, 0);
		if(dp[i] * 2 == siz[i]) ans = min(ans, dp[i]);
	}
	if(ans == 100000000) cout << -1 << endl;
	else cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int count =0;
		String s = sc.next();
		String s1 = "CODEFESTIVAL2016";
		for (int i=0;i<s.length();i++) {
			if (s.charAt(i)!=s1.charAt(i)) {
				count ++;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 21844
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[8] = { 0,0,1,-1, 1,1,-1,-1 };// 前４つで４近傍
const int c_Dy[8] = { 1,-1,0,0 ,1,-1,1,-1};// 全部で８近傍
const int c_div = 1000000007; //10^9 + 7
const double PI = 3.14159265358979323846;


int main() {

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


	int ans = min(B, D) - max(A, C);
	
	if(ans >0)printf("%d", ans);
	else {
		printf("0");
	}










}







Measured memory_bytes: 128
#include <stdio.h>
int main(void)
{
int H, W, i, j;

while(1){
scanf("%d %d",&H, &W);
if(H == 0 && W == 0)break;
for(i = 0;i < H;i++){
  for(j = 0;j < W;j++){
    if(i == 0 || i == H - 1 || j == 0 || j == W - 1)
    printf("#");
    else
    printf(".");
  }
printf("\n");
}
printf("\n");
}
return 0;
}


Measured memory_bytes: 2104
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def R(n): return [sys.stdin.readline().strip() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]

dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD = 1000000007
INF = float("inf")

sys.setrecursionlimit(1000000)

def main():
    N = I()
    A = LI()

    s = 0
    high = 0
    for ai in A:
        if ai < high:
            s += high - ai
        else:
            high = ai

    print(s)

if __name__ == '__main__':
    main()

Measured memory_bytes: 109452
import math
a, b, c, d = map(int, input().split())
e = b - ((b // c) + (b // d) - (b // (c * d // math.gcd(c, d))))
f = (a - 1) - (((a - 1) // c) + ((a - 1) // d) - ((a - 1) // (c * d // math.gcd(c, d))))
ans = e - f
print(ans)

Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
#define MAX 100005

int n,q;
int arr[MAX];


int getValue(int pos, int index, int *st, int ss, int se, int sum){
    if(ss==se && ss==pos){
        return sum+st[index];
    }
    if(pos>=ss && pos<=se){
        int mid = (ss+se)/2;
        if(pos<=mid){
            return getValue(pos, index*2+1, st, ss, mid, sum+st[index]);
        }
        else{
            return getValue(pos, index*2+2, st, mid+1, se, sum+st[index]);
        }
    }
}

void rangeUpdate(int value, int ss, int se, int qs, int qe, int *st, int index){
    if(ss>=qs && se<=qe){
        st[index] += value;
        //printf("change %d to %d\n",index,value);
        return;
    }
    else if(qe>=ss && qs<=se){
        int mid = (ss+se)/2;
        rangeUpdate(value, ss, mid, qs, qe, st, index*2+1);
        rangeUpdate(value, mid+1, se, qs, qe, st, index*2+2);
    }
}


int constructSTUtil(int ss, int se, int *st, int index){
    if(ss==se){
        st[index] = arr[ss];
        return st[index];
    }
    int mid = (ss+se)/2;
    st[index] = constructSTUtil(ss, mid, st, 2*index+1)\
                    + constructSTUtil(mid+1, se, st, 2*index+2);
    return st[index];
}

int* constuctSegTree(){
    int x = (int)(ceil(log2(n)));
    // Maximum size of segment tree
    int max_size = 2*(int)pow(2, x) - 1;
    int *st = new int[max_size];
    constructSTUtil(0, n-1, st, 0);
    return st;
}

int main(){
    int comd, x, y, res, index, value;
    //FILE *fp=fopen("In3.txt","r");
    scanf("%d %d",&n,&q);
    for(int i=0;i<n;++i) arr[i] = 0;
    int *st = constuctSegTree();
    for(int i=0;i<q;++i){
        scanf("%d",&comd);
        if(comd==0){
            scanf("%d %d %d",&x,&y,&value);
            // 有的题目是从下标1开始，有的是从0开始，所以对输入做点变换就好
            x -= 1;
            y -= 1;
            //(int value, int ss, int se, int qs, int qe, int *st, int *ut)
            rangeUpdate(value, 0, n-1, x, y, st, 0);
        }
        if(comd==1){
            scanf("%d",&x);
            x -= 1;
            res = getValue(x, 0, st, 0, n-1, 0);
            printf("%d\n",res);
        }
    }
    return 0;
}



Measured memory_bytes: 4868
! 問題文
! 高橋君はパーティを企画しています。

! パーティーでは参加者に 
! 1
!  人 
! 1
!  個以上のお菓子を配る予定です。

! 高橋君は参加者の人数が 
! A
!  人か 
! B
!  人のどちらかになるだろうという予想を立てました。

! どちらの場合でも均等に配りきることができるようなお菓子の個数の最小値を求めてください。

! ただし、 
! 1
!  個のお菓子を分割して複数人で分けることはできないものとします。

! 制約
! 1
! ≤
! A
! ,
! B
! ≤
! 10
! 5
! A
! ≠
! B
! 入力はすべて整数


program main
    implicit none
    integer(8):: a, b
    integer(8):: div, by

    read*, a, b
    div = 2
    by = 1
    do while( div <= min(a,b))
        ! print*, a, b, by
        if (can_div_xy(a, b, div))then
            a = a / div
            b = b / div
            by = by * div
        else
            div = div + 1
        end if
    end do

    print*, a*b*by
    
contains

function can_div_xy(x, y, div) result(ret)
    integer(8):: x, y, div
    logical:: ret
    if (can_div(x, div) .and. can_div(y, div)) then
        ret = .true.
    else
        ret = .false.
    end if
    return
end function can_div_xy

function can_div(x, div) result(ret)
    integer(8):: x, div
    logical:: ret
    if (mod(x, div) == 0)then
        ret = .true.
    else
        ret = .false.
    end if
    return
end function can_div
end program main

Measured memory_bytes: 256
import java.util.*;
class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
		Dice dice1 = new Dice(sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt());
		int kaburi = 0;
        while (sc.hasNext()) { 
        Dice dice2 = new Dice(sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt());
        boolean a = solv(dice1, dice2, 0);
        if (a == true) kaburi++;
		}
      if (kaburi != 0) {
        System.out.println("No");
      } else {
        System.out.println("Yes");    
      }
	}
      
	public static boolean solv(Dice dice1, Dice dice2,int count) {
		if(dice1.Top == dice2.Top && dice1.S == dice2.S && dice1.Bottom == dice2.Bottom && dice1.E == dice2.E && dice1.N == dice2.N && dice1.W == dice2.W) return true;
		if(count == 6) return false;
		Dice tmp = new Dice(dice2.Top,dice2.S,dice2.E,dice2.W,dice2.N,dice2.Bottom);
		tmp.TurnN();
		if(solv(dice1,tmp,count+1)) {
			return true;
		}
		tmp = new Dice(dice2.Top,dice2.S,dice2.E,dice2.W,dice2.N,dice2.Bottom);
        tmp.TurnS();
		if(solv(dice1,tmp,count+1)) {
			return true;
		}
		tmp = new Dice(dice2.Top,dice2.S,dice2.E,dice2.W,dice2.N,dice2.Bottom);
		tmp.TurnE();
        if(solv(dice1,tmp,count+1)) {
			return true;
		}
		tmp = new Dice(dice2.Top,dice2.S,dice2.E,dice2.W,dice2.N,dice2.Bottom);
		tmp.TurnW();
		if(solv(dice1,tmp,count+1)) {
			return true;
		}
		return false;
	}
}

class Dice {
	int Top; 
	int Bottom; 
	int N; 
	int S; 
	int W; 
	int E; 
	Dice(int a, int b, int c, int d, int e, int f) {
		Top = a;
		S = b;
		E = c;
		W = d;
		N = e;
		Bottom = f;
	}
	public void TurnN() {
		int tmp = Top;
		Top = S;
		S = Bottom;
		Bottom = N;
		N = tmp;
	}
	public void TurnW() {
		int tmp = Top;
		Top = E;
		E = Bottom;
		Bottom = W;
		W = tmp;
	}
	public void TurnE() {
		int tmp = Top;
		Top = W;
		W = Bottom;
		Bottom = E;
		E = tmp;
	}
	public void TurnS() {
		int tmp = Top;
		Top = N;
		N = Bottom;
		Bottom = S;
		S = tmp;
	}
}


Measured memory_bytes: 52796
K = int(input())
K = K - 1
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(a[K])

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define pb push_back
bool isPrime(ll n) 
{ 
    
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
   
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 
ll minthis(ll a, ll b){
if(a < b){
return a;
}
return b;
}
ll maxthis(ll a, ll b){
if(a > b){
return a;
}
return b;
}
int gcd(int a, int b){
    if( a<0 ) a = -a;
    if( b<0 ) b = -b;
    while( b!=0 ){
        a %= b;
        if( a==0 ) return b;
        b %= a;
    }
    return a;
}
 
int findLargestDivisor(int n) 
{ 
	int max = 1;
    for (int i = 2; i < n; i++) {        
        if(n %(i) == 0) { 
            max = i;
        } 
    }
    return max;     
} 
	 
 
ll power(ll x, ll y)  
{  
    ll temp;  
    if(y == 0)  
        return 1;  
    temp = power(x, y / 2);  
    if (y % 2 == 0)  
        return (temp * temp)%1000000007;  
    else
    {  
        if(y > 0)  
            return (x * temp * temp)%1000000007;  
        else
            return (temp * temp)%1000000007 / x;  
    }  
} 
bool sortbysec(const pair<int, int>& a, 
               const pair<int, int>& b) 
{ 
    return (a.second < b.second); 

} 


void solve(){
    int n,m;
    cin >> n >> m;
    if(n > 2*m){
        cout << n-(2*m) << "\n";
    }
    else cout << 0 << "\n";
}


int main(){ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;
    //cin >> t;
    while(t--){
		solve();
	}
    return 0; 
}





Measured memory_bytes: 3588
import bisect
import operator
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

N, M = list(map(int, sys.stdin.readline().split()))
P, Y = list(zip(*[map(int, sys.stdin.readline().split()) for _ in range(M)]))

P = np.array(P)
Y = np.array(Y)
order = np.lexsort((Y, P))
P = P[order]
Y = Y[order]

ans = []
cnt = 1
prev = None
for p, y in zip(P, Y):
    if p == prev:
        cnt += 1
    else:
        cnt = 1
    ans.append('{:06d}{:06d}'.format(p, cnt))
    prev = p
print('\n'.join(map(str, np.array(ans)[order.argsort()])))


Measured memory_bytes: 68976
import math
N = int(input())


def f(n):
    m = int(math.sqrt(n)+0.5)
    res = 0
    for x in range(1, m+1):
        for y in range(x, m+1):
            k = n - (x * x + y * y + x * y)
            if k < 1:
                break
            l = y
            r = m+1
            while r - l > 1:
                z = (r + l) // 2
                tmp = (x + y + z) * z
                if tmp <= k:
                    l = z
                else:
                    if r == z + 1:
                        r -= 1
                    else:
                        r = z + 1
            if (x+y+l) * l == k:
                s = set()
                s.add(x)
                s.add(y)
                s.add(l)
                if len(s) == 3:
                    res += 6
                elif len(s) == 2:
                    res += 3
                else:
                    res += 1
    return res


for i in range(1, N+1):
    print(f(i))


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

static const int N = 100;

int main()
{
  int n, p[N + 1], m[N + 1][N + 1];
  cin >> n;
  for (int i = 1; i <= n; i++)
  {
    cin >> p[i - 1] >> p[i];
  }

  for (int i = 1; i <= n; i++)
  {
    m[i][i] = 0;
  }
  for (int l = 2; l <= n; l++)
  {
    for (int i = 1; i <= n - l + 1; i++)
    {
      int j = i + l - 1;
      m[i][j] = (1 << 21);
      for (int k = i; k <= j - 1; k++)
      {
        m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
      }
    }
  }

  cout << m[1][n] << endl;

  return 0;
}


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

using namespace std;

int main()
{
  uint64_t N, Y;
  cin >> N >> Y;
  
  Y /= 1000;
  
  int64_t p = -1, q = -1, r = -1;
  for (int64_t x = 0; x <= N; ++x) {
    for (int64_t y = 0; y <= N; ++y) {
      int64_t z = N - x - y;
      if (z < 0) { break; }
      
      if (10 * x + 5 * y + z == Y) {
        p = x; q = y; r = z;
      }        
    }
  }
  
  cout << p << ' ' << q << ' ' << r << endl;
  
  return 0;
}

Measured memory_bytes: 256
n=int(input())
l=[]
for i in range(n):
  l.append(input())
a=0
b=0
c=0
d=0
for i in l:
  if i=='AC':
    a+=1
  elif i=='WA':
    b+=1
  elif i=='TLE':
    c+=1
  else:
    d+=1
print('AC x',a)
print('WA x',b)
print('TLE x',c)
print('RE x',d)

Measured memory_bytes: 16260
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main(){
    FIN;

    ll n;  cin >> n;
    ll ans = 0,crn = 1,num;

    rep(i,0,n){
        cin >> num;
        if(num != crn) ans++;
        if(num == crn) crn++;
    }

    if(ans == n) ans = -1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
    int N;
    char S[101];
    while(scanf("%d",&N),N) {
        scanf("%s",S);
        int H[10]={0},F=0,T=0;
        for(int i=0;i<100;i++) {
            if(S[i]=='S') {
                F+=H[T]+1;
                H[T]=0;
            }else if(S[i]=='M') {
                H[T]++;
            }else {
                H[T]+=F+1;
                F=0;
            }
            if(T==N-1) T=0; else T++;
        }
        sort(H,H+N);
        for(int i=0;i<N;i++) {
            printf("%d ",H[i]);
        }
        printf("%d\n",F);
    }
}

Measured memory_bytes: 1052
I = [int(input()) for _ in range(5)]
min_ = 10
cnt = 0
for ii in range(5):
    mod10 = I[ii] % 10
    cnt += I[ii] + (10 - mod10) if mod10 != 0 else I[ii]
    if min_ > mod10 and mod10 != 0: min_ = mod10

print (cnt - (10 - min_))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,l;
  cin >> n >> l;
  vector<string> s(n);
  for(int i = 0; i < n; i++){
    cin >> s[i];
  }
  sort(s.begin(),s.end());
  for(int i = 0; i < n; i++){
    cout << s[i] ;
  }
  puts("");
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

int main(){
  int n;
  cin>>n;
  int ans=0;
  rep(i,n){
    string s=to_string(i+1);
    int n=s.size();
    if(n%2==1)ans++;
  }
  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct vec2
{
    int x;
    int y;
    bool is_used;

    bool operator<(const vec2 &another) const
    {
        return x < another.x;
    }
};

int main(void) {
    int N;
    vector<struct vec2> va;
    int x;
    int y;
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> x >> y;
        vec2 a = {x, y, false};
        va.push_back(a);
    }
    vector<struct vec2> vb;
    for(int i=0;i<N;i++){
        cin >> x >> y;
        vec2 a = {x,y, false};
        vb.push_back(a);
    }
    sort(vb.begin(),vb.end());
    sort(va.begin(),va.end());
    int count=0;
    int max_y;
    for (vector<vec2>::iterator it = vb.begin(); it!=vb.end();it++) {
        max_y=-1;
        int a=-1;
        for (int i=0;i<N-count;i++) {
            if (va.at(i).x < it->x && va.at(i).y < it->y && max_y < va.at(i).y) {
                a=i;
                max_y = va.at(i).y;
            }else if(va.at(i).x > it->x){
                break;
            }
            
        }
        if (a!=-1){
            va.erase(va.begin()+a);
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import deque
n,q = map(int,input().split())
l = [0 for i in range(n)]
l2 = [[] for i in range(n)]
l3 = [0 for i in range(n)]
l3[0] = 1
for i in range(n-1):
    a,b = map(int,input().split())
    l2[b-1].append(a-1)
    l2[a-1].append(b-1)
for i in range(q):
    c,d = map(int,input().split())
    l[c-1] += d
ans = [0 for i in range(n)]
ans[0] = l[0]
q1 = deque()
q1.append((0,-1))
while len(q1) > 0:
    k,g = q1.popleft()
    for j in l2[k]:
        if j == g:
            continue
        ans[j] = ans[k] + l[j]
        q1.append((j,k))
for x in ans:
    print(x,end=" ")

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

#define ll long long
#define pb push_back

const int maxn = 1e5 + 20;

int maxb = 20;

int dp[maxn][20] , tmp[20];

vector<int> adj[maxn];

int last_bits(int x , int i)
{
	return (x >> i) << i;
}

void dfs(int v , int p = -1)
{
	for(int i = 0; i < maxb; i++)
		dp[v][i] = (1 << i);

	for(auto u : adj[v])
		if(u != p)
		{
			dfs(u , v);

			fill(tmp , tmp + maxb , (1 << (maxb + 1)) - 1);
			for(int i = 0; i < maxb; i++)
				for(int j = 0; j < maxb; j++)
					if((dp[v][i] & dp[u][j]) == 0)
						tmp[i] = min(tmp[i] , (dp[v][i] | last_bits(dp[u][j] , i)));

			for(int i = 0; i < maxb; i++)
				dp[v][i] = tmp[i];
		}
}

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

	int n;
	cin >> n;

	for(int i = 0; i < n - 1; i++)
	{
		int a , b;
		cin >> a >> b;
		a-- , b--;
		
		adj[a].pb(b);
		adj[b].pb(a);
	}

	for(maxb = 1; ; maxb++)
	{
		dfs(0);
		if(*min_element(dp[0] , dp[0] + maxb) < (1 << maxb))
			return cout << maxb - 1 << endl , 0;
	}

/*	while(1)
	{
		maxb--;
		dfs(0);

		if(!maxb || *max_element(dp[0] , dp[0] + maxb) == 0)
			return cout << maxb << endl , 0;
	}*/
}












Measured memory_bytes: 19200
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner scanner=new Scanner(System.in);
        String s=scanner.next();
        String p=scanner.next();
        s=s+s;
        int index=s.indexOf(p);
        if(index==-1){
            System.out.println("No");
        }else{
            System.out.println("Yes");
        }

    }

}



Measured memory_bytes: 26300
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
// #define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};
 
const int N=303;
vector<string> f;
int p[N][N];
int n,m,s;
void rot(){
    vector<string> tmp(m,string(n,'?'));
    forn(i,n)forn(j,m)tmp[j][n-1-i]=f[i][j];
    f=tmp;
    swap(n,m);
}
bool g(int x,int y){
    if(0<=x&&x<n&&0<=y&&y<m)return f[x][y]=='#';
    return 0;
}
int w(int x,int y){
    int delta=max(x-n+1,y-m+1);
    upx(delta,0);
    x-=delta;
    y-=delta;
    if(x<0||y<0)return 0;
    return p[x][y];
}
int h(int x1,int y1,int x2,int y2){
    return w(x2,y2)-w(x1-1,y1-1);
}
int solve(){
    int res=0;
    forn(i,n){
        forn(j,m){
            if(i&&j)p[i][j]=p[i-1][j-1];
            else p[i][j]=0;
            if(g(i,j))++p[i][j];
        }
    }
    forn(i,n)forn(j,m)if(g(i,j))for(int d=1;d+d<=s;d++)if(g(i+d,j+d))res+=h(i-d+1,j+d+1,i,j+d+d);
    return res;
}
int32_t main(){
    cin>>n>>m;
    f.resize(n);
    s=n+m;
    forn(i,n)cin>>f[i];
    int ans=0;
    forn(i,4){
        ans+=solve();
        rot();
    }
    cout<<ans<<'\n';
    return 0;
}

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

int main(){
  int r,c;
  cin >> r >> c;
  int a[r+1][c+1];



  for(int i=0;i<r+1;i++){
    for(int j=0;j<c+1;j++){
      if(i == r || j == c){
        a[i][j]=0;
      }else{
        cin >> a[i][j];
      }

    }
  }



  for(int i=0;i<r;i++){
    for(int j=0;j<c;j++){
      a[i][c] += a[i][j];
    }
  }
  for(int i=0;i<=c;i++){
    for(int j=0;j<r;j++){
      a[r][i] += a[j][i];
    }
  }

  for(int i=0;i<r+1;i++){
    for(int j=0;j<c+1;j++){
      if(j!=c){
        cout << a[i][j] << " ";
      }else{
        cout << a[i][j] << endl;
      }  
    }
  }

  return 0;
}



Measured memory_bytes: 3144
S = int(input())
A=list(map(int, input().split()))
LIMIT = 10**18
if 0 in A:
  print(0)
  exit(0)

ans=1
for i in range(len(A)):
  ans = A[i]*ans
  if ans > LIMIT:
    print(-1)
    exit(0)
print(ans)

Measured memory_bytes: 21644