akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <memory>
#include <memory.h>
#include <cmath>
#include <fstream>
#include <cmath>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <map>
#include <iomanip>
#include <list>
#include <cctype>
#include <algorithm>
#include <complex>
#define USE_MATH_DEFINES
using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 29;
const double EPS = 1E-10;

namespace std{
	bool operator < (const xy_t &a, const xy_t &b){
		return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
	}
}

double cross(const xy_t &a, const xy_t &b){
	return imag(conj(a) * b);
}

double dot(const xy_t &a, const xy_t &b){
	return real(conj(a)*b);
}

int ccw(xy_t a, xy_t b, xy_t c){
	b -= a; c -= a;
	if(cross(b, c) > 0) return 1;
	if(cross(b, c) < 0) return -1;
	if(dot(b, c) < 0) return +2;
	if(norm(b) < norm(c) ) return -2;
	return 0;
}

bool intersectSS(const line &s, const line &t){
	return ccw(s.first, s.second, t.first) * ccw(s.first, s.second, t.second) <= 0 &&
		ccw(t.first, t.second, s.first) * ccw(t.first, t.second, s.second) <= 0;
}

xy_t crosspoint(const line &l, const line &m){
	double a = cross(l.second - l.first, m.second - m.first);
	double b = cross(l.second - l.first, l.second - m.first);
	if(abs(a) < EPS && abs(b) < EPS) return m.first;
	if(abs(a) < EPS) assert(false);
	return m.first + b / a * (m.second - m.first);
}

typedef pair<double, string> data;
data dat[200];
bool comp(const data &d1, const data &d2){
	return abs(d1.first - d2.first) > EPS ? d1.first < d2.first : d1.second  > d2.second;
}

int dp[20001][256];
int C[20];
int X[20001];
int pow(int n){
	return n * n;
}

int main(){
	int n, m;
	while(cin >>n >> m && (n || m)){
		fill(&dp[0][0], &dp[20000][255] + 1, INF);
		for(int i = 0; i < m; i++){
			cin >> C[i];
		}
		for(int i = 1; i <= n; i++){
			cin >> X[i];
		}
		dp[0][128] = 0;
		for(int i = 1; i <= n; i++){
			for(int j = 0; j < 256; j++){
				if(dp[i-1][j] == INF) continue;
				for(int k = 0; k < m; k++){
					if(C[k] < 0){
						dp[i][max(0, j+C[k])] = min(dp[i][max(0, j+C[k])], dp[i-1][j] + pow(X[i] - max(0, j+C[k])));
					}else{
						dp[i][min(255, j+C[k])] = min(dp[i][min(255, j+C[k])], dp[i-1][j] + pow(X[i] - min(255, j+C[k])));
					}
				}
			}
		}
		int res = INF;
		for(int i = 0; i < 256; i++) res = min(res, dp[n][i]);
		cout << res << endl;
	}
	return 0;
}

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

int main(){
  string s;
  cin >> s;
  long ans=0;
  for(int i=0;i<s.size()/2;i++){
  	if(s[i]!=s[s.size()-1-i])ans++;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(void){
	int h,w,i,j;
	cin>>h>>w;
	int ans[h][w];
	char ma[h][w];
	for(i=0;i<h;i++){
		for(j=0;j<w;j++) cin>>ma[i][j];
	}
  	for(i=0;i<h;i++){
		for(j=0;j<w;j++) ans[i][j]=0;
	}
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			if(i+1<h&&ma[i+1][j]=='#') ans[i][j]++;
			if(i-1>=0&&ma[i-1][j]=='#') ans[i][j]++;
			if(j+1<w&&ma[i][j+1]=='#') ans[i][j]++;
			if(j-1>=0&&ma[i][j-1]=='#') ans[i][j]++;
			if(i+1<h&&j+1<w&&ma[i+1][j+1]=='#') ans[i][j]++;
			if(i+1<h&&j-1>=0&&ma[i+1][j-1]=='#') ans[i][j]++;
			if(i-1>=0&&j+1<w&&ma[i-1][j+1]=='#') ans[i][j]++;
			if(i-1>=0&&j-1>=0&&ma[i-1][j-1]=='#') ans[i][j]++;
		}
	}
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			if(ma[i][j]=='#') cout<<ma[i][j];
			else cout<<ans[i][j];
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define gt getchar()
#define ll long long
#define File(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
inline int in()
{
	int k=0;char ch=gt;
	while(ch<'-')ch=gt;
	while(ch>'-')k=k*10+ch-'0',ch=gt;
	return k;
}
const int YL=924844033,N=2e6+5;
int rev[N];
inline int ksm(int a,int k){int r=1;while(k){if(k&1)r=1ll*r*a%YL;a=1ll*a*a%YL,k>>=1;}return r;}
inline int MO(const int &a){return a>=YL?a-YL:a;}
#define Wn (ksm(5,opt==1?(YL-1)/st:YL-1-(YL-1)/st))

void ntt(int *a,int len,int opt=1)
{
    for(int i=0;i<len;++i)if(i<rev[i])std::swap(a[i],a[rev[i]]);
    for(int st=2,m=1;st<=len;st<<=1,m<<=1)
        for(int *p=a,x,y,wn=Wn;p!=a+len;p+=st)
            for(int k=0,wnk=1;k<m;++k,wnk=1ll*wnk*wn%YL)
                x=p[k],y=1ll*wnk*p[k+m]%YL,p[k]=MO(x+y),p[k+m]=MO(x-y+YL);
    if(opt==1)return;int inv=ksm(len,YL-2);
    for(int i=0;i<len;++i)a[i]=1ll*a[i]*inv%YL;
}

int fac[N],fnv[N],a[N],b[N],num[N],head[N],to[N<<1],nxt[N<<1],cnt,siz[N],n;
inline int C(int x,int y){return y>x?0:1ll*fac[x]*fnv[y]%YL*fnv[x-y]%YL;}
inline void add(int u,int v)
{
	to[++cnt]=v,nxt[cnt]=head[u],head[u]=cnt;
	to[++cnt]=u,nxt[cnt]=head[v],head[v]=cnt;
}
void dfs(int u,int pa=0)
{
	siz[u]=1;
	for(int i=head[u],v;i;i=nxt[i])
		if((v=to[i])!=pa)
			dfs(v,u),++num[siz[v]],++num[n-siz[v]],siz[u]+=siz[v];
}
int main()
{
	n=in();fac[0]=1;
	for(int i=2;i<=n;++i)add(in(),in());dfs(1);
	for(int i=1;i<=n;++i)fac[i]=1ll*fac[i-1]*i%YL;fnv[n]=ksm(fac[n],YL-2);
	for(int i=n;i>=1;--i)fnv[i-1]=1ll*fnv[i]*i%YL;
	for(int i=0;i<=n;++i)a[i]=1ll*num[i]*fac[i]%YL;
	for(int i=0;i<=n;++i)b[i]=fnv[n-i];int len=1,qwq=0;
	while(len<(n<<1))len<<=1,++qwq;--qwq;
	for(int i=0;i<len;++i)rev[i]=(rev[i>>1]>>1)|((i&1)<<qwq);
	ntt(a,len),ntt(b,len);
	for(int i=0;i<len;++i)a[i]=1ll*a[i]*b[i]%YL;
	ntt(a,len,-1);
	for(int i=1;i<=n;++i)
		printf("%d\n",MO(1ll*n*C(n,i)%YL-1ll*fnv[i]*a[n+i]%YL+YL));
	return 0;
}


Measured memory_bytes: 41600
#include <stdio.h>
#include <math.h>

int main(){
  double x, y, r;
  x = y = 0;
  r = -M_PI/2;
  while(1){
    int n,m;
    scanf("%d,%d", &n, &m);
    if(n==0&&m==0) break;

    x += n*cos(r);
    y += n*sin(r);
    r -= m*M_PI/180;
  }
  printf("%d\n%d\n", (int)x*-1,(int)y*-1);
}

Measured memory_bytes: 0
//------------------------------------------
// C++ templete 
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

//REPEAT
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

//debug
//------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//grobal variable
//------------------------------------------
int N,M;
VI Vec;


int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int N, n;   
    cin >> N;
    n = N;
    int x=0;
    while(N>=1)
    {
        x += N%10;
        N /= 10;
    }
    string s = n%x==0 ? "Yes" : "No";
    cout << s << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
 using namespace std;
 int main(){
 string s;
 cin>>s;
 if(s=="Sunny"s) cout<<"Cloudy"<<endl;
 if(s=="Cloudy"s) cout<<"Rainy"<<endl;
 if(s=="Rainy"s) cout<<"Sunny"<<endl;
 return 0;
 }

Measured memory_bytes: 3636
#include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 2010
using namespace std;
char a[maxn],b[maxn],c[maxn];
bool ab[maxn+maxn+maxn+maxn+maxn],ac[5*maxn],bc[5*maxn];//bca,cba,abc,acb
int match(char a,char b){
	if(a==b||a=='?'||b=='?')return 1;
	return 0;
}
int main(){
	int i,j,A,B,C,L,R,ans=5*maxn;
	scanf("%s%s%s",a,b,c);
	A=strlen(a),B=strlen(b),C=strlen(c);
	for(i=0;i<A;i++)
		for(j=0;j<B;j++)
			if(!match(a[i],b[j]))ab[i-j+2*maxn]=1;//标记不匹配位置
	for(i=0;i<A;i++)
		for(j=0;j<C;j++)
			if(!match(a[i],c[j]))ac[i-j+2*maxn]=1;
	for(i=0;i<B;i++)
		for(j=0;j<C;j++)
			if(!match(b[i],c[j]))bc[i-j+2*maxn]=1;
	for(i=-(B+C);i<=A+max(B,C);i++)//i记录b串首字母相对a串位置
		for(j=-(B+C);j<=A+max(B,C);j++)//j记录c串首字母相对a串位置
			if(!ab[i+2*maxn]&&!ac[j+2*maxn]&&!bc[j-i+2*maxn]){//j-i记录c串首字母相对b串位置
				L=min(0,min(i,j)),R=max(A,max(B+i,C+j));//min(i,j)>0表示在a串内部匹配，故取0;B+i,或C+j可能还小于A
				ans=min(ans,R-L);
			}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


char buf[10005];

int main(){

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

	scanf("%s",buf);

	for(int i = 0; buf[i] != '\0'; i++){

		buf[i] = 'A'+(buf[i]-'A'+N)%26;
		printf("%c",buf[i]);
	}
	printf("\n");

	return 0;
}


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

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

  for(int i=0; i<N.size(); i++){
    if     (N.at(i)=='1') N.at(i)= '9';
    else if(N.at(i)=='9') N.at(i)= '1';
  }

  cout << N << endl;
}

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

typedef struct vector{
	int x;
	int y;
} vector;

int comp(const void *a,const void *b){
	return (*((vector**)a))->x - (*((vector**)b))->x;
}

int main(void){
	int n;
	vector *a;
	vector **p;
	int i;
	int res = 0;
	scanf("%d",&n);
	a = calloc(sizeof(vector),n);
	p = calloc(sizeof(vector*),n);
	for(i = 0;i < n;i++){
		scanf("%d",&a[i].x);
		p[i] = &a[i];
	}
	qsort(p,n,sizeof(vector*),comp);
	for(i = 0;i < n;i++){
		p[i]->y = i;
	}
	for(i = 0;i < n;i+=2){
		if(a[i].y % 2){
			res++;
		}
	}
	printf("%d\n", res);
	return 0;
}


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

int main() {
    int d, g;
    cin >> d >> g;

    vector<int> p(d), c(d);
    rep(i, d) {
        cin >> p[i] >> c[i];
    }
    
    long long sum, cnt, ans = 1LL << 60;
    rep(bit, 1 << d) {
        sum = 0;
        cnt = 0;
        rep(i, d) {
            if (bit >> i & 1) {
                sum += p[i] * (i + 1) * 100 + c[i];
                cnt += p[i];
            }
        }
        
        if (sum >= g) {
            ans = min(ans, cnt);
        } else {
            rep(i, d) {
                int j = d - 1 - i;
                if (bit >> j & 1) continue;

                rep(k, p[j]) {
                    if (sum >= g) break;

                    sum += 100 * (j + 1);
                    cnt++;
                }
            }

            ans = min(ans, cnt);
        }
    }

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

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

for n in range(N):
  data_set = map(int, raw_input().split())
  a = data_set[0]
  b = data_set[1]
  c = data_set[2]

  if (a ** 2 + b ** 2) == (c ** 2) or (a ** 2 + c ** 2) == (b ** 2) or (b ** 2 + c ** 2) == (a ** 2):
    print "YES"
  else:
    print "NO"

Measured memory_bytes: 6332
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
using namespace std;
#define INT(x) int x; scanf("%d",&x)
#define INPUT(x) scanf("%d",&x)
#define REP1(x,n) for(int x = 0; x < n; x++)
#define REP2(x,s,e) for(int x = s; x <= e; x++)
#define RREP1(x,n) for(int x = n-1; x >= 0; x--)
#define RREP2(x,s,e) for(int x = s; x >= e; x--)
#define BR printf("\n")
#define INF 2000000000

typedef long long ll;

int main(){
    INT(N);
    int sum = 0;
    REP2(i,1,N) sum += i;
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    cin >> N;
    vector<int> input(N);
    for(auto& inp: input){
        cin >> inp;
    }
    input.push_back(0);
    sort(input.begin(), input.end(), greater<int>());
    deque<int> dque;
    int cnt = 0;
    while(input.size()){
        if(cnt++ % 2 == 0){
            dque.push_back(input.back());
            input.pop_back();
        }else{
            dque.push_front(-(input.back()));
            input.pop_back();
        }
    }
    vector<int> res(N + 1);
    for(int i = 0; i < N; i++){
        res[i] = min(dque[i + 1] - dque[i], 24 - (dque[i + 1] - dque[i]));
    }
    res[N] = min(dque[N] - dque[0], 24 - (dque[N] - dque[0]));
    cout << *min_element(res.begin(), res.end()) << endl; 
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < int(n); i++)
#define FOR(i,n,m) for(int i = int(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = MOD - 1;
const ll LLINF = 4e18;

int main() {
    int n; cin >> n;
    string s; cin >> s;
    vector<ll> dm(n + 1, 0), d(n + 1, 0), m(n + 1, 0);
    REP(i, n) {
        d[i + 1] = d[i];
        m[i + 1] = m[i];
        dm[i + 1] = dm[i];
        if (s[i] == 'D') d[i + 1]++;
        if (s[i] == 'M') {
            m[i + 1]++;
            dm[i + 1] += d[i + 1];
        }
    }
    int q; cin >> q;
    REP(i, q) {
        int b; cin >> b;
        b--;
        ll ans = 0;
        REP(j, n) {
            if (s[j] == 'C') {
                ans += dm[j + 1] - dm[max(0, j - b)] - (d[max(0, j - b)])*(m[j + 1] - m[max(0, j - b)]);
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 24836
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
 
//#define int ll
 
typedef int64_t ll;
static const int MOD = 1000000007;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,0,1,-1}, dy4[4] = {1,-1,0,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define NP next_permutation
#define PQ priority_queue
#define UB upper_bound
#define LB lower_bound
#define SZ(a) signed((a).size())
#define LEN(a) signed((a).length())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).begin(),(c).end());reverse((c).begin(),(c).end());
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
#define ALL(x) (x).begin(),(x).end()
#define YESNO(x) puts((x)?"YES":"NO")
#define YesNo(x) puts((x)?"Yes":"No")

signed main(){
    int N;
    vector<int> A,B;
    cin >> N;
    REP(i,N){
        int x;
        cin >> x;
        A.PB(x);
        B.PB(x);
    }

    SORT(B);
    int L = B[N/2-1], U = B[N/2];

    if(L==U){
        REP(i,N){
            printf("%d\n",L);
        }
        return 0;
    }

    REP(i,N){
        if(A[i]<=L) printf("%d\n",U);
        else printf("%d\n",L);
    }

    return 0;
}








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


using namespace std;

typedef long long ll;

const ll INF = (ll) (1e18+5);

int main()
{
    /* ios::sync_with_stdio(0); */
    /* cin.tie(0); */
    ll N, W; cin >> N >> W;
    vector <ll> weight(N), value(N);
    for (ll i = 0; i < N; ++i){
        ll w, v; cin >> w >> v;
        weight[i] = w; value[i] = v;
        /* weight.push_back(w); value.push_back(v); */
    }
    ll sum = 0;
    for(ll x : value){
        sum += x;
    }
    //dp table needs only to be as long as the sum of the values of all items combined
    vector <ll> dp(sum + 1, INF);
    dp[0] = 0;
    // dp[i] - the minimum total weight of items with value exactly i
    for (ll item = 0; item < N; ++item){
        for (ll excess_value = sum - value[item]; excess_value >= 0; --excess_value){
            dp[value[item] + excess_value] = min(dp[value[item] + excess_value], dp[excess_value] + weight[item]);
        }
    }
    ll ans = 0;
    for (ll i = 0; i <= sum; ++i){
        if (dp[i] <= W){
            ans = max(ans, i);
        }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Library;
using static Library.Input;

namespace AtCoderTemplate
{
    class ProgramA
    {
        static void Main()
        {
            var s = Line;
            System.Console.WriteLine(Line.Select((c, i) => c == s[i]).Count(b => b));
        }
    }
}

namespace Library
{
    class Input
    {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line => Console.ReadLine();

        public static string[] StrArr => Line.Split(' ');

        public static int NextInt => int.Parse(NextWord());

        public static long NextLong => long.Parse(NextWord());

        public static List<int> IntList => StrArr.Select(int.Parse).ToList();

        public static List<long> LongList => StrArr.Select(long.Parse).ToList();

        public static IEnumerable<long[]> TakeLine(int N)
        {
            return Enumerable.Repeat(0, N).Select(_ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray());
        }

        public static string NextWord()
        {
            while (!enumerator.MoveNext())
            {
                enumerator = StrArr.AsEnumerable().GetEnumerator();
            }
            return enumerator.Current;
        }
    }
}


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

#define INF 1e9
#define llINF 1e18
#define MOD 1e9+7
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
using namespace std;
int main(){
  int h,w;cin>>h>>w;
  int n;cin>>n;
  int ans[h][w]={};
  bool muki=true;
  int cnt=0;
  int gyou=0;
  for(int i=0;i<n;i++){
    int num;cin>>num;
    for(int j=0;j<num;j++){
      char c='0'+i+1;
      if(muki){
	ans[gyou][cnt]=i+1;
	cnt++;
	if(cnt==w){
	  muki=false;
	  cnt=0;
	  gyou++;
	}
      }else{
	ans[gyou][w-cnt-1]=i+1;
	cnt++;
	if(cnt==w){
	  muki=true;
	  cnt=0;
	  gyou++;
	}
      }
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cout<<ans[i][j];
      if(j!=w-1)
	cout<<" ";
    }
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
bool so[10000003];
int main(void)
{
	int i,j,cnt,n;
	scanf("%d",&n);
	for(i=2;i<=n+2;i++)	so[i]=true;
	for(i=2;i*i<=n+2;i++)	{
		if(so[i]==true)	{
			for(j=2;j*i<=n+2;j++)	so[i*j]=false;
		}
	}
	cnt=0;
	for(i=3;i<=n;i++)	{
		if(so[i]==true && so[i+2]==true)	cnt++;
	}
	printf("%d\n",cnt*2);
	return 0;
}


Measured memory_bytes: 12364
#include <bits/stdc++.h>
#define pb(x) push_back(x)
#define pii pair <int,int>

using namespace std;
typedef long long int lli;

int func(lli a, lli b)
{
    ostringstream oss1; oss1 << a; string p = oss1.str();
    ostringstream oss2; oss2 << b; string q = oss2.str();

    return max((int)p.size(),(int)q.size());
}

int main()
{
    lli n; cin >> n;

    vector < pair <lli,lli> > v;

    for(lli i=1;i<=ceil(sqrt(n));i++){
        if(n%i == 0)v.pb(make_pair(i,n/i));
    }
    vector <int> f;

    for(pair <lli,lli> x : v){
        //cout << func(x.first,x.second) << endl;
        f.pb(func(x.first,x.second));
    }

    sort(f.begin(),f.end());

    cout << f.front() << endl;

    return 0;
}


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

dp =[0]*40

if n ==0:
    print(0)

elif n >0:
    x = bin(n)
    bx = x[2:]
    lx = len(bx)
    for i in range(lx-1,-1,-1):
        dp[i] = int(bx[lx-1-i])
    for i in range(40):
        if i % 2 ==1 and dp[i]==1:
            dp[i+1] +=1
    while max(dp) >1:
        for i in range(40):
            if dp[i] >=2:
                dp[i] -=2
                if dp[i+1] >0:
                    dp[i+1] -=1
                else:
                    dp[i+1] +=1
                    dp[i+2] +=1
    dpr = list(reversed(dp))
    dprs = list(map(lambda x :str(x),dpr))
    dprj = "".join(dprs)
    print(int(dprj))    

else:
    x = bin(-n)
    bx = x[2:]
    lx = len(bx)
    for i in range(lx-1,-1,-1):
        dp[i] = int(bx[lx-1-i])
    for i in range(40):
        if i % 2 ==0 and dp[i]==1:
            dp[i+1] +=1
    while max(dp) >1:
        for i in range(40):
            if dp[i] >=2:
                dp[i] -=2
                if dp[i+1] >0:
                    dp[i+1] -=1
                else:
                    dp[i+1] +=1
                    dp[i+2] +=1
    dpr = list(reversed(dp))
    dprs = list(map(lambda x :str(x),dpr))
    dprj = "".join(dprs)
    print(int(dprj))    

Measured memory_bytes: 9136
import numpy as np

n = int(input())
s = list(map(str, input().rstrip()))

dp_e = np.array([0] + [int(x == "E") for x in s])
dp_e = (dp_e.sum() - dp_e.cumsum())[1:]
dp_s = np.array([0] + [int(x == "W") for x in s])
dp_s = dp_s.cumsum()[:-1]

ans = (dp_e + dp_s).min()

print(ans)

Measured memory_bytes: 26224
n = int(input())
for i in range(n):
    num = input()
    n = [i for i in num]
    n_sort = sorted(n)
    n_sort2 = sorted(n, reverse=True)
    n_sort = "".join(n_sort)
    n_sort2 = "".join(n_sort2)
    print(int(n_sort2) - int(n_sort))

Measured memory_bytes: 7552
s=input()
if s.count("x") >= 8:
    print("NO")
else:
    print("YES")
    
#YesにしたらWAになったああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああ

Measured memory_bytes: 9092
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int(i)=0;i<(n);i++)
typedef long long ll;
set<ll> x;

void dfs(ll keta, ll i, ll n, ll num){
  if(i==keta){
    x.insert(num);
    return;
  }
  if(n>=1) dfs(keta,i+1,n-1,num+(n-1)*pow(10,i+1));
           dfs(keta,i+1,n  ,num+ n   *pow(10,i+1));
  if(n<=8) dfs(keta,i+1,n+1,num+(n+1)*pow(10,i+1));      
}

int main(){
  int k;cin>>k;
  REP(i,10) x.insert(i);

  for(ll keta=1;keta<=9;keta++) for(ll i=0;i<=9;i++) dfs(keta,0,i,i);
  int count=0;
  for(auto p:x){
    if(count==k) cout<<p;
    count++;
  }
}

Measured memory_bytes: 10112
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <math.h>
#include <string>
using namespace std;
typedef long long int ll;

int main(){
	int a,b; cin >> a >> b;
	if(a+b==15){
		cout << "+" << endl;
	}
	else if(a*b==15){
		cout << "*" << endl;
	}
	else{
		cout << "x" << endl;
	}
}

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

int main() {
  int A;
  int B;
  char op;
  
  cin >> A >> op >> B;
  
  int sum;
  
  if (op == '+') {
     sum = A + B;
  } else {
     sum = A - B; 
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <complex>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <valarray>

using namespace std;

int cnt[3<<17];
int cnt2[3<<17];

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

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

    vector<int> cnt3;
    for(int a=n; a; --a)
    {
        for(int k=0; k<cnt2[a]; ++k)
        {
            cnt3.emplace_back(a);
        }
    }


    int m=cnt3.size();
    vector<int> suf(m+1);
    for(int i=m; i--; ) suf[i]=suf[i+1]+cnt3[i];

    vector<int> ans(n);
    for(int k=n,j=m,c=0; k; ans[--k]=c-1)
    {
        while((k-j)*c<=suf[j])
        {
            ++c;
            while(j and cnt3[j-1]<c) --j;
        }
        // while(true)
        // {
        //     while(j and a[j-1]<c) --j;
        //     if((k-j)*c>suf[j]) break;
        //     else c++;
        // }
    }
    for(int x:ans) cout << x << "\n";
}

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

const int MAX_N = int(5e2) + 10;

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

int n;
int d[MAX_N][MAX_N], vis[MAX_N][MAX_N];

void dfs(int x, int y) {
	for (int k = 0; k < 4; ++k) {
		int _x = x + dx[k], _y = y + dy[k], w = d[x][y] + 1 - vis[_x][_y];
		if (w < d[_x][_y]) {
			d[_x][_y] = w;
			dfs(_x, _y);
		}
	}
}

int x[MAX_N * MAX_N], y[MAX_N * MAX_N];

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n * n; ++i) {
		int p;
		scanf("%d", &p);
		x[i] = (p + n - 1) / n;
		y[i] = p - (x[i] - 1) * n;
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j) {
			d[i][j] = std::min(std::min(i, j), std::min(n - i + 1, n - j + 1));
		}
	}
	int ans = 0;
	for (int i = 1; i <= n * n; ++i) {
		ans += d[x[i]][y[i]] - 1;
		vis[x[i]][y[i]] = 1;
		for (int k = 0; k < 4; ++k) {
			int _x = x[i] + dx[k], _y = y[i] + dy[k];
			d[x[i]][y[i]] = std::min(d[x[i]][y[i]], d[_x][_y]);
		}
		dfs(x[i], y[i]);
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 23148
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,p;

int main(){
    ll a,b,x;
    cin >> a >> b >> x;
    if(a==0)cout << b/x + 1 << endl;
    else cout << b/x - (a-1)/x << endl;
    return 0;
}

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

int main(){
	int a;
	cin >> a;
	string s;
	cin >> s;
	if(a<3200) cout << "red" << endl;
	else cout << s << endl;
	return 0;
}



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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define PI acos(-1)

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

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

  double ans;
  // 台形
  if (2 * x >= a * a * b) {
    ans = atan(2 * (a * a * b - x) / (a * a * a)) * 180 / PI;
  } else {
    ans = atan(a * b * b / (2 * x)) * 180 / PI;
  }

  printf("%.10f\n", ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main() {
string S; 
cin >> S; 
int L = S.size(); 
int A[30] = {}; 
for(int i = 0; i < L; i++){
A[S.at(i) - 'a'] ++; 
}
string ans = "Yes"; 
for(int i = 0; i < 26; i++){
if(A[i] % 2 == 1){
ans = "No"; 
break; 
}
}
cout << ans << endl; 
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>

#define X first
#define Y second
#define int long long

using namespace std;

void pudge(){
    int a, b;
    cin >> a >> b;
    cout << 6 - a - b;
}

signed main(){
#ifdef LOCAL
    freopen("pudge.in", "r", stdin);
    freopen("pudge.out", "w", stdout);
#endif
    ios_base::sync_with_stdio;
    cin.tie(0);
    cout.tie(0);

    pudge();

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>

#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define show(n) cerr<<#n<<" = "<<n<<endl
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl

//ここからAtCoder向けdefine
#define yes cout << "YES" << endl
#define no cout << "NO" << endl

using namespace std;

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using pint = pair<int,int>;

const int INF = ~(1 << 31);

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

    int n;
    cin >> n;
    set<char> s;
    char c;
    rep(i, n){
        cin >> c;
        s.insert(c);
    }
    if(s.size() == 3){
        cout << "Three" << endl;
    }else{
        cout << "Four" << endl;
    }

    return 0;
}

Measured memory_bytes: 888
from collections import deque
N = int(input())
ab = [list(map(lambda x:int(x)-1,input().split())) for i in range(N-1)]
T = [[] for i in range(N)]
for a,b in ab:
    T[a].append(b)
q = deque([0])
color = [0]*N
while q:
    x = q.popleft()
    c = 1
    for y in T[x]:
        if c==color[x]:
            c+=1
        color[y] = c
        c+=1
        q.append(y)
print(max(color))
for i in range(N-1):
    print(color[ab[i][1]])

Measured memory_bytes: 36820
// -----------------------------------
// Author     : MatsuTaku
// Affiliation: Tokushima University
// Country    : Japan
// Date       : 04/03/2020
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int N; cin>>N;
  string a,b,c; cin>>a>>b>>c;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    auto s = a[i];
    auto t = b[i];
    auto u = c[i];
    if (s == t and t == u) {
      
    } else if ((s == t and t != u) or (t == u and u != s) or (u == s and s != t)) {
      ans += 1;
    } else {
      ans += 2;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;

bool dfs(vector<vecint>& g, vecint& vis, int i) {
  vis[i] = 1;
  for (int ch : g[i]) {
    if (vis[ch] == 1) return false;
    else if (vis[ch] == 0) {
      if (!dfs(g, vis, ch)) return false;
    }
  }
  vis[i] = 2;
  return true;
}

bool is_dag(vector<vecint>& g) {
  int n = g.size();
  vecint vis(n, 0);
  for(int i:irange(0,n)) {
    if (!vis[i]) {
      if (!dfs(g, vis, i)) return false;
    }
  }
  return true;
}

int get_idx(int x, int y, int n) {
  if (x > y) swap(x, y);
  return x*n + y;
}

int main()
{
  int n;
  cin>>n;
  vector<vecint> after(n*n);
  vecint cnt(n*n);
  for (int i : irange(0,n)) {
    vecint order(n-1);
    for (int j : irange(0, n-1)) cin>>order[j];
    for (int j : irange(0, n-2)) {
      int o1 = order[j]-1;
      int o2 = order[j+1]-1;
      after[get_idx(i, o1, n)].push_back(get_idx(i, o2, n));
      ++cnt[get_idx(i, o2, n)];
    }
  }
  if (!is_dag(after)) {
    cout<<-1<<endl;
    return 0;
  }
  queue<int> st;
  for(auto&& p : index(cnt)) {
    if (p.value() == 0) st.push(p.index());
  }
  vecint distmx(n*n, 1);
  while (!st.empty()) {
    int idx = st.front();
    st.pop();
    for (int ch : after[idx]) {
      --cnt[ch];
      distmx[ch] = max(distmx[ch], distmx[idx] + 1);
      if (cnt[ch] == 0) st.push(ch);
    }
  }
  cout<<*max_element(distmx)<<endl;
  return 0;
}


Measured memory_bytes: 49212
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define rrep(i,n) for (int i = (n - 1);i >= 0;i--)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;

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

    int k,x;
    cin >> k >> x;
    if(500 * k >= x) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

#define int long long
#define ii pair<int, int>

signed main() {
#ifdef _DEBUG
	freopen("in", "r", stdin);
#endif
	int x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	vector<ii> v;
	for (int i = 1; i <= a; i++) {
		int u; cin >> u;
		v.push_back(ii(u, 1));
	}
	for (int i = 1; i <= b; i++) {
		int u; cin >> u;
		v.push_back(ii(u, 2));
	}
	for (int i = 1; i <= c; i++) {
		int u; cin >> u;
		v.push_back(ii(u, 3));
	}
	sort(v.begin(), v.end(), greater<ii>());
	int no = 0, sum = 0;
	for (int i = 0; i < (int) v.size(); i++) {
		int f = v[i].first, s = v[i].second;
		if (s == 1) {
			if (x > 0 && x + y - 1 >= no) {
				x--;
				sum += f;
			}
		}
		if (s == 2) {
			if (y > 0 && x + y - 1 >= no) {
				y--;
				sum += f;
			}
		}
		if (s == 3) {
			if (x + y - 1 >= no) {
				no++;
				sum += f;
			}
		}
	}
	cout << sum << '\n';
}


Measured memory_bytes: 10476
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

const int INF = 1e9 + 5;

int main() {

  int t;
  cin>>t;
  vector<int> val(t);
  vector<int> dp(t,INT_MAX);
  for(int i=0;i<t;i++){
    cin>>val[i];
  }
  dp[0]=0;
  for (int i = 0; i < t; i++)
  {
    for(int j:{i+1,i+2}){
      if(j<t){
        dp[j] = min(dp[j],dp[i]+abs(val[j]-val[i]));
      }
    }
  }
  cout<<dp[t-1]<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int a, b, m;
	cin >> a >> b >> m;
	vector<int> aa(a), bb(b);
	vector<vector<int>> price(m, vector<int>(3));
	for (int i = 0; i < a; i++) {
		cin >> aa[i];
	}
	for (int i = 0; i < b; i++) {
		cin >> bb[i];
	}
	for (int i = 0; i < m; i++) {
		cin >> price[i][0] >> price[i][1] >> price[i][2];
	}

	int min_a = aa[0], min_b = bb[0];
	for (int i = 1; i < a; i++) {
		if (min_a > aa[i]) {
			min_a = aa[i];
		}
	}
	for (int i = 1; i < b; i++) {
		if (min_b > bb[i]) {
			min_b = bb[i];
		}
	}

	int ans = min_a + min_b;
	for (int i = 0; i < m; i++) {
		int t = aa[price[i][0] - 1] + bb[price[i][1] - 1] - price[i][2];
		if (ans > t) {
			ans = t;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 6528
def solve():
    from collections import namedtuple
    import sys

    input = sys.stdin.readline
    Dish = namedtuple('Dish', 'idx cost pt')

    n, t = map(int, input().split())
    dishes = []
    for idx in range(1, n + 1):
        cost, pt = map(int, input().split())
        dishes.append(Dish(idx=idx, cost=cost, pt=pt))

    dp = [[0] * 2 for _ in range(t)]
    # dp[完食にかかる総時間][最後の皿を選んだか]:= 美味しさの最大値

    for dish in dishes:
        for cost_ in range(t - 1, -1, -1):
            dp[cost_][True] = max(dp[cost_][True], dp[cost_][False] + dish.pt)
            if cost_ >= dish.cost:
                dp[cost_][False] = max(dp[cost_][False], dp[cost_ - dish.cost][False] + dish.pt)
                dp[cost_][True] = max(dp[cost_][True], dp[cost_ - dish.cost][True] + dish.pt)

    return max(dp[cost_][True] for cost_ in range(t))


print(solve())

# 最後の皿を選んだかフラグを設ける
# https://sen-comp.hatenablog.com/entry/2019/11/17/003150


Measured memory_bytes: 46960
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<list>
#include<string>
#include<algorithm>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back

#define ll __int64
#define P pair<ll,ll>
//#define __int64 long long

int a,b,c,k,ans;

int main(){	
	cin>>a>>b>>c>>k;
	int e,f;

	int ma;
	if(a>=b&&a>=c)ma=a,e=b,f=c;
	if(b>=a&&b>=c)ma=b,e=a,f=c;
	if(c>=b&&c>=a)ma=c,e=a,f=b;

	int x=1;
	rep(i,k)ma*=2;

	cout<<ma+e+f<<endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  string a,b,c;
  cin>>a>>b>>c;
  cout<<(char)(a[0]-32)<<(char)(b[0]-32)<<(char)(c[0]-32)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lld long long int
#define M 1000000007
#define fors(i,n) for(int i=0;i<n;++i)
#define fore(i,a,b) for(int i=a;i<=b;++i)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define vv vector<int>
#define endl "\n"
#define test(i) cout<<i<<endl
#define itrt int t; cin>>t; fors(i,t)
#define itr1 int t; cin>>t;
#define ff first
#define ss second
#define pb push_back
#define vmp make_pair
#define ppb pop_back
#define sorta(a,n) sort(arr,arr+n)
#define sortv(x) sort(x.begin(),x.end())
void file(){
    #ifdef LOCAL
    freopen("demo.in","r",stdin);
    freopen("demo.out","w",stdout);
    #endif
}
int main(){
    fastio;
    file();
    lld n,k;
    cin>>n>>k;
    vv v(n);
    for(lld i=0;i<n;++i){
      cin>>v[i];
    }
    sortv(v);
    lld cnt=0;
    for(lld i=0;i<n-k;++i){
      cnt+=v[i];
    }
    test(cnt);
}

// 3 0
// 1000000000 1000000000 1000000000

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    long long sum1=0;
    for(int i=0;i<s.size();i++)
    {
        sum1=sum1+s[i]-'0';
    }
    if(sum1%9==0)
    cout<<"Yes";
    else
    cout<<"No";
    cout<<endl;
}

Measured memory_bytes: 3672
N = int(input())
A = []
B = []
out = 0
for n in range(N):
    line = [int(i) for i in input().split()]
    A.append(line[0])
    B.append(line[1])
for index in range(0, N)[::-1]:
  A[index] += out
  mod = A[index] % B[index]
  if mod:
    out += B[index] - mod 
print(out)


Measured memory_bytes: 15060
#include <bits/stdc++.h>
using namespace std;
int N;
typedef pair<long long, long long> P;
vector<P> g;
long long solve_( long long k ){
  long long r = 0;
  for( auto p : g ){
    if( (k | p.first) == k ){
      r += p.second;
    }
  }
  return r;
}
long long solve( long long K ){
  long long ans = solve_(K);
  for(long long t = 2; t <= K; t *= 2 ){
    if( ((K-t) | (t-1)) < K )
      ans = max( ans, solve_( (K-t) | (t-1) ) );
  }
  return ans;
}
int main(){
  long long K;
  cin >> N;
  cin >> K;
  g.resize(N);
  for(int i = 0; i < N; i++){
    cin >> g[i].first >> g[i].second;
  }
  
  cout << solve(K) << endl;
}


Measured memory_bytes: 1792
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <list>

using namespace std;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

typedef pair<long long int, long long int> P;

int main(){
	
	int N, L[100];
	
	cin >> N;
	
	for(int i = 0; i < N; i++){
		cin >> L[i];
	}
	
	vector<int> v;
	
	for(int i = 0; i < N; i++){
		int S = 0;
		for(int j = i; j < N; j++){
			S += L[j];
			v.push_back(S);
		}
	}
	
	sort(v.begin(), v.end());
	v.pop_back();
	
	int ans = 100000;
	for(int i = 0; i < v.size(); i++){
		int DP[60] = {};
		for(int j = 1; j <= N; j++){
			DP[j] = 100000;
		}
		for(int j = 0; j < N; j++){
			int S = 0;
			for(int k = j; k < N; k++){
				if(j == 0 && k == N - 1){
					break;
				}
				S += L[k];
				if(S >= v[i]){
					DP[k + 1] = min(max(DP[j], S), DP[k + 1]);
				}
			}
		}
		ans = min(ans, DP[N] - v[i]);
	}
	
	cout << ans << endl;
	
	return 0;
}



Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long i = 0; i < n; i++)
#define erep(i, n) for(long i = 1; i <= n; i++)

int main(){long N;
cin >> N;
vector<long> a(N + 1);
erep(i, N) cin >> a.at(i);
vector<long> color(9);
long cnt = 0;
erep(j, N){
for(long i = 0; i <= 7; i++){
    if(a.at(j) >= i * 400 && a.at(j) < (i + 1) * 400){
        color.at(i) = 1;
    }
}
if(a.at(j) >= 3200) color.at(8)++;
}
for(long i = 0; i <= 7; i++){
    if(color.at(i) == 1) cnt++;
}
// cout << fac[N] << endl;
// cout << (4 - n / 2) * 2 - 1 << endl;
long eight = 8;
long one = 1;
long x = cnt + color.at(8);
cout << max(cnt, one) << ' ' << x << endl;
return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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


int main() {

  ll n;
  cin >> n;

  vector<ll> array(n);
  REP(i, n){
    cin >> array[i];
    array[i] = array[i] - (i + 1);
    //tmp += array[i] - (i + 1);
  }
  sort(array.begin(), array.end());

  ll tmp;
  if (n % 2 == 0) {
    tmp = (array[n / 2] + array[n / 2 - 1]) / 2;
  } else {
    tmp = array[n / 2];
  }

  ll ans = 0;
  REP(i, n) ans += llabs(array[i] - tmp);

  cout << ans << endl;

  return 0;
}


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

static const int now = -1;

int ans = 0,a,b,graph[20][20] = {{}};


void bfs(int i,int j){
  graph[j][i] = now;
  if(graph[j][i+1] == 0 && i < a - 1) {
    //cout << 'a' << endl;
    graph[j][i] = 0;
    /*
      for(int v = 0;v < 5;v++){
      for(int s = 0;s < 5 ;s++){
      cout << graph[v][s] << ' ';
      }
      cout << endl;
      }
      cout << endl;
    */
    bfs(i+1,j);
  }
  if(graph[j+1][i] == 0 && j < b - 1){
    graph[j][i] = 0;
    /* cout << 'b' << endl;
       for(int v = 0;v < 5;v++){
       for(int s = 0;s < 5 ;s++){
       cout << graph[v][s] << ' ';
       }
    
       cout << endl;
       }
       cout << endl;
    */
    bfs(i,j+1);
  }
  
  if(graph[b - 1][a - 1] == now) {
    graph[b - 1][a - 1] = 0;
    ans++;
    //cout << "ans =" << ans << endl;  
  }
}

int main(){

  int i,j,x,y,n; 

  while(true){
    
    for(int i = 0;i < 20;i++){
      for(int j = 0;j < 20;j++){
	graph[i][j] = 3;
      }
    }

    cin >> a >> b;
    if(a == 0 && b == 0) break;
    for(int i = 0;i < b;i++){
      for(int j = 0;j < a;j++){
	graph[i][j] = 0;
      }
    }

    cin >> n;
  
    for(int i = 0;i < n;i++){
      cin >> x >> y;
      graph[y - 1][x - 1] = 1;
    }
    /*
      for(int i = 0;i < 5;i++){
      for(int j = 0;j < 5 ;j++){
      cout << graph[i][j] << ' ';
      }
      cout << endl;
      }
    */
  
    bfs(0,0);

    /*cout << endl;
      cout << endl;
      for(int i = 0;i < 5;i++){
      for(int j = 0;j < 5 ;j++){
      cout << graph[i][j] << ' ';
      }
      cout << endl;
      }


    */
    cout << ans << endl;
    ans = 0;
  }
}
  

Measured memory_bytes: 1160
N = int(input())
c = [[0 for i in range(10)] for j in range(10)]

for i in range(1,N+1):
    i = [int(j) for j in list(str(i))]
    c[i[0]][i[-1]] += 1

ans = 0
for i in range(10):
    for j in range(10):
        ans += c[i][j]*c[j][i]

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define CFS cin.tie(nullptr);ios::sync_with_stdio(false);
#define CST(x) cout<<fixed<<setprecision(x);
using namespace std;
const int IINF = 1 << 30;
const long LINF = 1LL << 60;
const int MOD = (int) 1e9 + 7;
// const int MOD = 998244353;

inline long ith_digit(long n, long k) {
    return (n % (long)pow(10, k + 1)) / (long)pow(10, k);
}

int dfs(int n, int k) {
    if (k == 1) {
        if (n == 0 || n == 9) {
            return 2;
        }
        else {
            return 3;
        }
    }
    else {
        if (n == 0) {
            return dfs(0, k - 1) + dfs(1, k - 1);
        }
        else if (n == 9) {
            return dfs(8, k - 1) + dfs(9, k - 1);
        }
        else {
            return dfs(n - 1, k - 1) + dfs(n, k - 1) + dfs(n + 1, k - 1);
        }
    }
}

int main(){
    int n;
    cin >> n;
    queue<long> q;
    for (int i = 1; i <= 9; i++) {
        q.push(i);
    }

    int count = 1;
    while(true) {
        long value = q.front();
        q.pop();
        if (count == n) {
            cout << value << "\n";
            return 0;
        }
        long t = value % 10;
        if (t != 0) {
            q.push(value * 10 + t - 1);
        }
        q.push(value * 10 + t);
        if (t != 9) {
            q.push(value * 10 + t + 1);
        }
        count++;
    }
}

Measured memory_bytes: 1792
import sys
from operator import itemgetter
import collections


def r(a, b, k):
    l = []
    for i in range(1, 100+1):
        if a % i == 0 and b % i == 0:
            l.append(i)
    l.sort(reverse=True)
    return l[k-1]


def main():
    input = sys.stdin.readline
    a, b, k = list(map(int, input().split()))

    print(r(a, b, k))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3516
#include <bits/stdc++.h>
using namespace std;
 
int main(void){
    int a,b;
    cin >> a >> b;
    int sum = 1;
    int count = 0;
    while(sum < b){
        sum--;
        sum += a;
        count++;
    }
    cout << count << endl;
    
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
//	final static int MOD = 1000000007;

	public static long ans = 0;

	public static void main(String[] args) {

//		int ans = 0;
		Scanner sc = new Scanner(System.in);
		boolean f = false;

		int n = sc.nextInt();
		double d = sc.nextDouble();

		long[] a = new long[n];
		long[] b = new long[n];
		for (int i = 0; i < n; i++) {
			a[i]= sc.nextLong();
			b[i]= sc.nextLong();
		}


		//-------------------------------------------------------------------------------------

		for(int i = 0; i < n; i++) {
			long tmpa = (a[i] * a[i]);
			long tmpb = (b[i] * b[i]);
			long tmp = tmpa + tmpb;
			double calc = Math.sqrt(tmp);
			System.err.println(tmpb);
			if(d * d >= tmp) {
				ans++;
			}
		}


		//-------------------------------------------------------------------------------------

//		if(f) {
//			System.out.println("Yes");
//		} else {
//			System.out.println("No");
//		}

		System.out.println(ans);

		sc.close();
	}



}

Measured memory_bytes: 64248