akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
int main() {//言語変えろ言語変えろ言語変えろ言語変えろ言語変えろ
            
int a,b; cin>>a>>b;
  if(a>b){cout<<"safe"<<endl;}
  else{cout<<"unsafe"<<endl;}

}

Measured memory_bytes: 3636
t, x, y = 0, 0, 0
n = int(input())
for i in range(n):
    next_t, next_x, next_y = map(int, input().split())
    diff = abs(x - next_x) + abs(y - next_y)
    if diff > (next_t - t) or (diff - (next_t - t)) % 2 == 1:
        print('No')
        exit()
    t, x, y = next_t, next_x, next_y
print('Yes')

Measured memory_bytes: 3060
/**
*	  Name: Ajay Subhash Jadhav
*	  Institute: International Institute of Technology Hyderabad 
*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <ctime>
#include <string.h>
#define LL long long
#define inf 0x7fffffff
#define mod 1000000007
#define pb push_back
#define ppi pair<int,int>
#define vi vector<int>
#define vii vector<ppi>
#define vll vector<LL>
#define mp make_pair
using namespace std;

void fastio()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void inputread()
{
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
}
string convert(int n)
{
	if(n==0)
		return "0";
	string ans;
	while(n!=0)
	{
		int rem=n%2;
		if(rem<0)
			rem+=2;
		n=(n-rem)/(-2);
		ans+=rem+'0';
	}
	reverse(ans.begin(),ans.end());
	return ans;
}
int main(){
      
  fastio();
  int n,m,i,j,t;
  cin>>n;
  cout<<convert(n)<<endl;
  return 0;
}

Measured memory_bytes: 256
import math
N=int(input())
min_a=1
min_b=1
for i in range(N):
  a,b=map(int,input().split())
  at=min_a//a
  if min_a%a!=0:
    at+=1
  bt=min_b//b
  if min_b%b!=0:
    bt+=1
  n=max(at,bt)
  min_a=a*n
  min_b=b*n
print(min_a+min_b)

Measured memory_bytes: 3064
abck=list(map(int,input().split()))
a=abck[0]
b=abck[1]
c=abck[2]
k=abck[3]

if a>=k:
    print(k)
elif a<k:
    if a+b>=k:
        print(a)
    else:
        print(a-(k-a-b))
    


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

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

  int maxx = max(a, max(b, c));

  for(int i = maxx; i < 60; ++i) {
    int diff = i * 3 - a - b - c;
    if(diff % 2 == 0) {
      cout << diff / 2;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n,i,j,k,t;

int main() {
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++)
    cin>>a[i];
    ll c=0;
    
    sort(a,a+n);
    
    
    for(i=0;i<n-2;i++)
    {
        for(j=i+1;j<n-1;j++)
        {
            for(k=j+1;k<n;k++)
            {
                if(a[i]!=a[j] && a[j]!=a[k] && a[i]!=a[k])
                {
                    if(a[i]+a[j]>a[k])
                    {
                    //cout<<a[i]<<" "<<a[j]<<" "<<a[k]<<"\n";
                    
                    c++;
                    
                    }
                }
            }
        }
    }
    
    
    cout<<c<<"\n";
    
  
  
  
  
  
  
  
  
      
    
   return 0;   
}
    


Measured memory_bytes: 3640
#include<set>
#include<iostream>
int main(){
int l,r;for(;;){std::cin>>l>>r;if(!(l+=r))break;std::set<int> p;int m;p.insert(0);for(r=0;r<l;r++)std::cin>>m,p.insert(m);std::set<int>::iterator a;for(a=p.begin(),m=0;a!=--p.end();++a)if(*(++a)-*(--a)>m)m=*(++a)-*(--a);std::cout<<m<<"\n";}}

Measured memory_bytes: 0
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

flg = 0

if e-a > k:
    flg = -1
elif d-a > k:
    flg = -1
elif c-a > k:
    flg = -1
elif b-a > k:
    flg = -1

if flg == 0:
    print("Yay!")
else:
    print(":(")

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;

int main(){
    long long M=-1000000, m=1000000, a;
    long long s=0;
int n;
    cin >> n;
    for (int i=0; i<n; i++){
        cin >> a;
        if (a > M) M = a;
        if (a < m) m = a;
        s += a;

    }
    cout <<m<<" "<<M <<" "<<s<<endl;
}


Measured memory_bytes: 3096
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <boost/math/common_factor_rt.hpp>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;

using namespace std;
// namespace mp = boost::multiprecision;
// namespace mt = boost::math
// using Bint = mp::cpp_int;
typedef pair<int, int> P;

int main() {
    int n, ans = 0;
    cin >> n;
    rep(i, n) {
        if (i == 9) {
            i += 89;
            continue;
        }
        if (i == 999) {
            i += 8999;
            continue;
        }
        if (i == 99999) {
            i += 899999;
            continue;
        }
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,D,sum=0;
    cin>>N>>D;
  double x[N+5]={};
  double y[N+5]={};
  double z[N+5]={};
  for(int i=0;i<N;i++){
    cin>>x[i]>>y[i];
    z[i]=hypot(x[i],y[i]);
    if(z[i]<=D){
      sum++;
    }
  }
  cout<<sum<<'\n';
  return(0);
}

Measured memory_bytes: 8448
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int r,g,b;
    int Z;
    cin>>r>>g>>b;
    Z = (g * 10) + b;
    //条件分岐→[if]
    if(Z % 4 == 0){
        cout << "YES" <<endl;
    }
    else{
        cout <<"NO" <<endl;
    }
}


//=代入
// == 

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i<(int)n; ++i)
#define forr(i, t, n) for (int i = t; i<n; ++i)
#define rmod(x, y) (((x%y)+y)%y)
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int maxn = 100;

int n, cap;
int vs;
int w[maxn], v[maxn];
vector<ll> dp;
const ll decoy = 1e10;
int solve()
{
	dp[0] = 0;
	forn(i, n)
	{
		for (int j = vs-v[i]; j>=0; j--)
		{
			dp[j+v[i]] = min(dp[j+v[i]], dp[j] + ll(w[i]));
		}
	}
	int ans = 0;
	forn(i, vs+1) if (dp[i]<=cap) ans = max(ans, i);
	return ans;
}

int main() {
	ios_base::sync_with_stdio(0);
	//cin.tie(0);
	cin >> n >> cap;
	forn(i, n)
	{
		cin >> w[i] >> v[i];
		vs += v[i];
	}
	forn(i, n+1) dp.resize(vs+1, decoy);
	cout << solve();
	
	return 0;
}

Measured memory_bytes: 1024
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,M,K = map(int, readline().split())
AB = np.array(read().split(), np.int64)

A = AB[:N]
B = AB[N:]

Acum = np.zeros(N+1, np.int64)
Acum[1:] = np.cumsum(A)
Bcum = np.zeros(M+1, np.int64)
Bcum[1:] = np.cumsum(B)

Acum = Acum[Acum <= K]
Bcum = Bcum[Bcum <= K]

x = np.searchsorted(Acum, K - Bcum, side='right') - 1
x += np.arange(len(Bcum))
print(x.max())



Measured memory_bytes: 54148
h,w=map(int,input().split())
ss=[list(input()) for i in range(h)]
f=True
s=[["."]*(w+2)]
s.extend(ss)
for i in range(1,h+1):
    s[i].insert(0,".")
    s[i].append(".")
s.append(["."]*(w+2))

for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j]=="#":
            if s[i-1][j]!="#" and s[i+1][j]!="#" and s[i][j-1]!="#" and s[i][j+1]!="#":
                f=False
if f:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 39024
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */

int n;
vector<vector<vector<double>>> memo(330, vector<vector<double>>(330, vector<double>(330, -1)));

double rec(int i, int j, int k){
    if(i==0 && j==0 && k==0) return 0.0;
    if(memo[i][j][k] != -1) return memo[i][j][k];

    double res = 0.0;
    if(i) res += i * (rec(i-1, j, k));
    if(j) res += j * (rec(i+1, j-1, k));
    if(k) res += k * (rec(i, j+1, k-1));
    res += n;
    res /= (i+j+k);

    return memo[i][j][k] = res;
}

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

    cin >> n;
    int c1 = 0, c2 = 0, c3 = 0;
    rep(i, n){
        int a; cin >> a;
        if(a == 1) ++c1;
        else if(a == 2) ++c2;
        else if(a == 3) ++c3;
    }

    cout << setprecision(15) << rec(c1, c2, c3) << endl;

    return 0;
}

Measured memory_bytes: 286208
#include<bits/stdc++.h>
using namespace std;
int n,a[20];
long long solve(int l,int r,int L,int R){
    if(l>r) return 0;
    long long ans=1e18;
    for(int i=l;i<=r;i++){
        ans=min(ans,solve(l,i-1,L,L+R)+1ll*(L+R)*a[i]+solve(i+1,r,L+R,R));
    }
    return ans;
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    printf("%lld",a[1]+a[n]+solve(2,n-1,1,1));
    return 0;
}

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

using namespace std;

string a,b="CODEFESTIVAL2016";
int c=16;

int main(){
    cin>>a;
    for(int i=0;i<16;i++)
        c-=(a[i]==b[i])?1:0;
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
typedef long long lint;
const int N=2e5+5;
int n,nxt[N],len[N],ed[N];
char str[N];

namespace utils{
	template <class T> inline void apn(T &x,const T y){x>y?x=y:0;}
	template <class T> inline void apx(T &x,const T y){x<y?x=y:0;}
	inline int nxi(){
		int x=0;
		char c;
		while(((c=getchar())>'9'||c<'0')&&c!='-');
		const bool f=(c=='-')&&(c=getchar());
		while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
		return f?-x:x;
	}
}
using namespace utils;

int main(){
	static int tr[26];
	scanf("%s",str+1);
	n=strlen(str+1);
	for(int i=0; i<26; ++i)
		tr[i]=n+1;
	for(int i=n; i>=0; --i){
		int nlen=n+2,nc=0;
		for(int j=0; j<26; ++j){
			if(len[tr[j]]<nlen){
				nlen=len[tr[j]],nc=j;
			}
		}
		len[i]=nlen+1;
		ed[i]=nc;
		nxt[i]=tr[nc];
		if(i){
			tr[str[i]-'a']=i;
		}
	}
	for(int i=0; i<=n; i=nxt[i]){
		putchar(ed[i]+'a');
	}
	puts("");
	return 0;
}


Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
#define MOD (long long)(1e9+7)
typedef long long int ll;
typedef unsigned long long int ull;

ll modularExponentiation(ll x, ll y, ll  p){
  ll res = 1;
  x = x % p;
  while (y > 0){
      if (y & 1) res = (res*x) % p;
      y = y>>1;
      x = (x*x) % p;
  }
  return res;
}

bool isPrime(ll n){
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll T=1;
  // cin>>T;
  for(int t=0;t<T;t++){
    ll n, k;
    cin>>n>>k;
    n%=k;
    cout<<min(n, abs(n-k))<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define p push
#define ll long long
#define f first
#define s second
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int,int>
#define plli pair<ll,int>
#define pill pair<ill>
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define endl '\n'
using namespace std;

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int a, b, k; cin >> a >> b >> k;
    set<int> st, st2;
    vector<int> vec, vec2;
    for(int i = 1; i*i <= a; i++){
        if(a%i != 0)continue;
        st.insert(i); st.insert(a/i);
    }
    for(int i = 1; i*i <= b; i++){
        if(b%i != 0)continue;
        st2.insert(i);
        st2.insert(b/i);
    }
    for(auto i : st)vec.pb(i); for(auto i : st2)vec2.pb(i);
    vector<int> ans;
    for(auto i : vec){
        for(auto j : vec2){
            if(i == j)ans.pb(i);
        }
    }
    sort(ans.begin(), ans.end());
    reverse(ans.begin(), ans.end());
    cout << ans[k-1] << endl;
    return 0;
}



Measured memory_bytes: 3504
s=input()
n=len(s)
k=1000
l=int(s)
for i in range(n-2):
    x=(l-(l//10**(n-i))*10**(n-i))//10**(n-3-i)
    if abs(x-753)<k:
        k=abs(x-753)
print(int(k))

Measured memory_bytes: 3060
#include <stdio.h>

int
main(void)
{
	char s[1600];
	scanf("%[^\1]", s);

	for (char *c = s; *c != '\0'; c++)
		printf("%c",
		       ('A' <= *c && *c <= 'Z') ? *c - 'A' + 'a':
		       ('a' <= *c && *c <= 'z') ? *c - 'a' + 'A': *c);

	return 0;
}



Measured memory_bytes: 2048
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 200
#define INF 1000002
typedef pair<int, int> pii;
 
int H, W, N;
int X1[MAX], X2[MAX], Y1[MAX], Y2[MAX];
bool fld[MAX*6][MAX*6];
 
int compress(int *x1, int *x2)
{
    vector<int> xs;
    for (int i = 0; i < N; i++) {
        for (int d = -1; d <= 1; d++) {
            int tx1 = x1[i] + d, tx2 = x2[i] + d;
            xs.push_back(tx1);
            xs.push_back(tx2);
        }
    }
    sort(xs.begin(), xs.end());
    xs.erase(unique(xs.begin(), xs.end()), xs.end());
 
    for (int i = 0; i < N; i++) {
        x1[i] = find(xs.begin(), xs.end(), x1[i]) - xs.begin();
        x2[i] = find(xs.begin(), xs.end(), x2[i]) - xs.begin();
    }
    return xs.size();
}
 
int solve()
{
    W = compress(X1, X2);
    H = compress(Y1, Y2);
     
    memset(fld, 0, sizeof(fld));
    for (int i = 0; i < N; i++) {
        for (int y = Y1[i]; y <= Y2[i]; y++) {
            for (int x = X1[i]; x <= X2[i]; x++) {
                fld[y][x] = 1;
            }
        }
    }
     
    const int dx[] = {-1, 0, 1, 0};
    const int dy[] = {0, -1, 0, 1};
     
    int res = 0;
    for (int y = 0; y < H; y++) {
        for (int x = 0; x < W; x++) {
            if (fld[y][x]) continue;            
            res++;
 
            queue<pii> Q;
            Q.push(pii(x, y));
            while (!Q.empty()) {
                pii p = Q.front(); Q.pop();
                int sx = p.first, sy = p.second;
 
                for (int i = 0; i < 4; i++) {
                    int tx = sx + dx[i], ty = sy + dy[i];
                    if (tx < 0 || W <= tx || ty < 0 || H <= ty || fld[ty][tx]) {
                        continue;
                    }
 
                    Q.push(pii(tx, ty));
                    fld[ty][tx] = 1;
                }
 
            }
        }
 
    }
    return res;
}
 
int main()
{
    while (cin >> N, N) {
        H = W = INF;
        int x[2], y[2];
        for (int i = 0; i < N; i++) {
            cin >> x[0] >> y[0] >> x[1] >> y[1];
            for (int j = 0; j < 2; j++) {
                x[j] = x[j] * 2 + 1;
                y[j] = y[j] * 2 + 1;
            }
            int dj[] = {1, 0, 0, -1}, dk[] = {0, -1, 1, 0};
            for (int j = 0; j < 2; j++) {
                for (int k = 0; k < 2; k++) {
                    int l = j * 2 + k, m = i * 4 + l;
                    int nj = j + dj[l];
                    int nk = k + dk[l];
                    X1[m] = x[j];  Y1[m] = y[k];
                    X2[m] = x[nj]; Y2[m] = y[nk];
                    if (X1[m] > X2[m]) swap(X1[m], X2[m]);
                    if (Y1[m] > Y2[m]) swap(Y1[m], Y2[m]);
                }
            }                        
        }
        N *= 4;
        cout << solve() << endl;
    }
    return 0;
}

Measured memory_bytes: 2652
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <utility>
#include <stdio.h>

using namespace std;

struct Page {
    string name;
    vector<int> p;

    Page(string _name, int v) {
        name = _name;
        p = vector<int>();
        p.push_back(v);
    }

    bool operator<(const Page& p) const {
        return name < p.name;
    }
};

vector<Page> v;

int main(void) {
    string style;

    v.clear();

    int i, j, page;
    while(cin >> style >> page) {
        int index = -1;
        for(i = 0; i < (int) v.size(); i++) {
            if(v[i].name == style) {
                index = i;
                v[i].p.push_back(page);
                break;
            }
        }
        if(index == -1) {
            v.push_back(Page(style, page));
        }
    }
    sort(v.begin(), v.end());

    for(i = 0; i < (int) v.size(); i++) {
        cout << v[i].name << endl;
        sort(v[i].p.begin(), v[i].p.end());
        for(j = 0; j < (int) v[i].p.size() - 1; j++) {
            cout << v[i].p[j] << " ";
        }
        cout << v[i].p[j] << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

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

  cout << (n < 1000 ? "ABC" : "ABD") << endl;

  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Shell Sort
?¬????????????°?????????????????\?????????????????¨?????? n ????????´??°???????????°??? A ??????????????´?????????????????°????????§??????

1  insertionSort(A, n, g)
2      for i = g to n-1
3          v = A[i]
4          j = i - g
5          while j >= 0 && A[j] > v
6              A[j+g] = A[j]
7              j = j - g
8              cnt++
9          A[j+g] = v
10
11 shellSort(A, n)
12     cnt = 0
13     m = ?
14     G[] = {?, ?,..., ?}
15     for i = 0 to m-1
16         insertionSort(A, n, G[i])

shellSort(A, n) ????????????????????? g ????????¢??????????´??????????????±???¨???????????\???????????§??????
 insertionSort(A, n, g) ?????????????????§??????????????? g ????????????????????°??????????????????
 ??????????????§??????????????¨?¨?????????????

???????????????????????? ? ??????????????????????????°???????????????????????????????????????
n ??¨??°??? A ???????????????????????§????????????????????????m??? m ????????´??° Gi(i=0,1,...,m???1)???
??\??? A????????????????????????????????????????????°????????????????????????????????????
???????????????????????\???????????¶????????????????????????????????????

1???m???100
0???Gi???n
cnt ????????? [n^1.5] ????¶??????????????????????
"""
import sys

def insertionSort(A, n, g):
    """ ?????\????????? """
    c = 0
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >=0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            c += 1
        A[j+g] = v
    return c

def shellSort(A, n):
    cnt = 0
    G = []
    i = 1
    while i <= n:
        G.insert(0,i)
        i = i * 3 + 1
    
    m = len(G)
    for i in range(0, m):
        cnt += insertionSort(A, n, G[i])
    
    # ??????
    print(m)
    print(" ".join(map(str,G)))
    print(cnt)
    for i in A:
        print(i)

# ?????????
n = int(input().strip())
a = []
for i in range(n):
    a.append(int(input().strip()))
shellSort(a,n)

Measured memory_bytes: 47484
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  
  
  int n=s.size();
  int sum1=0;
  int sum2=0;
  for(int i=0; i<(n-1)/2; i++){
  if(s.at(i)==s.at((n-3)/2-i) && s.at((n+1)/2+i)==s.at(n-1-i)){
    sum1++;
}
  }
    for(int j=0; j<n; j++){
    if(s.at(j)==s.at(n-1-j)){
      sum2++;
    }
    }
    
  if(sum1==(n-1)/2 && sum2==n){
    cout << "Yes" << endl;
  }
  else{
  cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


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

	vector<tuple<ll, ll, string, ll, string>> a(n);

	for (int i = 0; i < n; i++)
	{
		ll v, w, d;
		string t, s;
		
		cin >> v >> w >> t >> d >> s;

		a[i] = make_tuple(v, w, t, d, s);
	}

	sort(all(a), [](auto &a, auto &b)
		{
			if (get<0>(a) == get<0>(b))
			{
				if (get<1>(a) == get<1>(b))
				{
					if (get<2>(a) == get<2>(b))
					{
						if (get<3>(a) == get<3>(b))
						{
							return get<4>(a) < get<4>(b);
						}
						return get<3>(a) < get<3>(b);
					}
					return get<2>(a) < get<2>(b);
				}
				return get<1>(a) < get<1>(b);
			}
			return get<0>(a) < get<0>(b);
		}
	);

	for (auto t : a)
	{
		println(get<0>(t) << " " << get<1>(t) << " " << get<2>(t) << " " << get<3>(t) << " " << get<4>(t));
	}
}



Measured memory_bytes: 17688
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ini(a,i) memset(a,i,sizeof(a))
#define pb push_back
#define ll long long

int main()
{
	std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//ll tt;	cin>>tt;	while(tt--)
	{
		ll n,a,b,k;
		cin>>k>>a>>b;

		for(ll i=a;i<=b;i++)
		{
			if(i%k==0)	{cout<<"OK";return 0;}
		}

		cout<<"NG";
 	
 	}
	cerr<<" Execution : "<<(1.0*clock())/CLOCKS_PER_SEC<<"s \n";
		
		
return 0;
}

Measured memory_bytes: 3704
#include <iostream>
#include <numeric>

int main(){
    int k;
    int ans;
    scanf("%d", &k);
    for(int i = 1; i <= k; i++){
        for(int j = 1; j <= k; j++){
            for(int l = 1; l <= k; l++){
                ans += std::gcd(std::gcd(i, j), l);
            }
        }
    }
    std::cout << static_cast<long>(ans) << std::endl;
}

Measured memory_bytes: 3656
#16:15
n = int(input())
xyi = []
for i in range(n):
  xyi.append(list(map(int,input().split())) + [i])
xyi.sort()
road = []
for j in range(n-1):
  road.append([xyi[j+1][0]-xyi[j][0],xyi[j][2],xyi[j+1][2]])
xyi.sort(key = lambda x: x[1])
for j in range(n-1):
  road.append([xyi[j+1][1]-xyi[j][1],xyi[j][2],xyi[j+1][2]])
road.sort()
pre = [i for i in range(n)]
ans = 0
for k in range(2*n-2):
  d,I,J = road[k]
  ii = []
  jj = []
  while pre[I] != I:
    ii.append(I)
    I = pre[I]
  for Is in ii:
    pre[Is] = I
  while pre[J] != J:
    jj.append(J)
    J = pre[J]
  for Js in jj:
    pre[Js] = J
  if I != J:
    pre[J] = I
    ans += d
print(ans)

Measured memory_bytes: 98468
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

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

bool check(string s, string t){
	rep(i, 8){
		if(s[i] == '*') continue;
		if(s[i] != t[i]) return false;
	}
	return true;
}

int main(){
	int n, m;
	while(cin >> n >> m, n|m){
		vector<string> v(n);
		vector<int> cost(n);
		rep(i, n) cin >> v[i] >> cost[i];
		vector<string> v2(m);
		rep(i, m) cin >> v2[i];

		int ans = 0;
		rep(j, m){
			rep(i, n){
				if(check(v[i], v2[j])){
					ans += cost[i];
					break;
				}
			}
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1272
#include <vector>
#include <iostream>
using namespace std;
int main(){
	int h;
	while(cin >> h,h){
		vector<int> mp(6*h);
		for(int i=0;i<h;i++){
			cin >> mp[6*i] >> mp[6*i+1] >> mp[6*i+2] >> mp[6*i+3] >> mp[6*i+4];
			mp[6*i + 5] = -1;
		}
		bool del = true;
		int ct =0;
		while(del){
			del = false;
			int ketsu = 0;
			int point = 0;
			for(int i=0;i<6*h-2;i++){
				if(mp[i] == mp[i+1] && mp[i+1] == mp[i+2] && mp[i] !=0){
					if(ketsu == 0){
						ketsu = 3;
						point = mp[i];
					}else{
						ketsu++;
					}
				}else if(ketsu > 0){
					ct += point * ketsu;
					del = true;
					for(int ki = 0;ki<ketsu;ki++){
						mp[i + 1 - ki] = 0;
					}
					ketsu = 0;//init
					point = 0;
				}
			}
			/*			for(int i = 0;i<6*h;i++){
				cout << mp[i] << " ";
				if(i%6 == 0 && i>0)cout << endl;
			}
			cout << endl;*/
			if(del){//fall
				for(int i=0;i<5;i++){//line number
					int fall_ct = 0;
					for(int j=h-1;j>=0;j--){//direction is up
						if(mp[j*6 + i] == 0){
							fall_ct++;
						}else if(fall_ct > 0){
							mp[(j + fall_ct)*6 + i ] = mp[j * 6 + i];
							mp[j*6 + i ] = 0;
						}
					}
				}
				
			}
			
			/*			for(int i = 0;i<6*h;i++){
				cout << mp[i] << " ";
				if(i%6 == 0 && i>0)cout << endl;
			}
			cout << endl;*/
			}

		cout << ct << endl;
	}
	return 0;
}
			
				

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll N;
    cin >> N;

    cout << 0 << endl;

    string r0;
    cin >> r0;

    if (r0 == "Vacant") {
        return;
    }

    string r;
    int left = -1, right = N;
    while (right - left > 1) {
        int mid = (left + right) >> 1;
        cout << mid << endl;
        cin >> r;
        if (r == "Vacant") {
            return;
        }

        if (mid & 1) {
            if (r == r0) {
                right = mid;
            }
            else {
                left = mid;
            }
        }
        else {
            if (r == r0) {
                left = mid;
            }
            else {
                right = mid;
            }
        }
    }

    int cur = left + 1;
    while (true) {
        cout << cur << endl;
        cin >> r;
        if (r == "Vacant") break;
        ++cur;
    }
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 852
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class A9x9 {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt(), b = in.nextInt();

            if (a < 10 && b < 10)
                out.println(a * b);
            else
                out.println(-1);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 21460
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		// N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		int A = Integer.parseInt(strArr[0]);
		int B = Integer.parseInt(strArr[1]);
		int ans = (A + B) % 24;
		System.out.println(ans);
	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}
}


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

int main(){
    while(1){
        int n,x;
        cin >> n >> x;
        if ( n == 0 && x == 0){
            break;
        }
        int count = 0;
        for (int i = 1; i <= n; i++){
            for (int j = i + 1; j <= n; j++){
                for (int k = j + 1; k <= n; k++){
                    if (i + j + k == x){
                        count += 1;
                        break; 
                    }
                }
            }
        }
        cout << count << endl;
    }
    return 0;
}


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

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

    string s, t;
    int count = 0;
    cin >> s >> t;
    for(int i = 0; i < s.size(); i++) {
        if(s[i] == t[i]) {
            count++;
        }
    }
    cout << count;

    return 0;
}



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

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

typedef vector<int> vi;
typedef long long ll;

void solve() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a + b + c <= 21) {
    cout << "win" << endl;
  } else {
    cout << "bust" << endl;
  }
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int  N;
  cin >> N;
  
  if( (N/10)%111==0  ){
    cout << "Yes" << endl;
  }
  
  else if ((N%1000)%111==0){
    cout << "Yes" << endl;
  }
  
  else {
    cout << "No" << endl;
  }
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,w,i,j,k=0;
  cin>>n>>w;
  w=w+1;
  long value[n],weight[n],dp[n][w];
  for(i=0;i<n;i++)
    cin>>weight[i]>>value[i];
  for(i=0;i<n;i++)
  {
    for(j=0;j<w;j++)
    {
      if(i==0)
      {
        if(weight[i]<=j)
	        dp[0][j]=value[0];
        else
	        dp[0][j]=0;
        continue;
      }
      if(weight[i]<=j)
      {
      	    dp[i][j]=max(dp[i-1][j],value[i]+(dp[i-1][j-weight[i]]));
      }
      else
        dp[i][j]=dp[i-1][j];
    }
  }/*
  for(i=0;i<n;i++)
  {
    cout<<weight[i]<<" "<<value[i]<<endl;
    for(j=0;j<w;j++)
    {
      cout<<dp[i][j]<<" ";
    }
    cout<<endl;
  }*/
  cout<<dp[n-1][w-1];
  return 0;
}

Measured memory_bytes: 78336
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define dd(x) cout << #x << " = " << x << ", "
#define de(x) cout << #x << " = " << x << endl
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	int t = (n - m) * 100 + m * 1900;
	ll two = 1,i = 1;
	rep(i,0,m) two *= 2;
	double p = 0,sum = 0,ans = 0;
	while(1){
		p = (1 - sum) / two;
		sum += p;
		ans += t * i * p;
		i++;
		//de(p);
		//de(t * i * p);
		if(t * i * p - 0.0000001 < 0.00000001) break;
	}
	cout<<(int)(ans + 0.001)<<endl;
	return 0;
} 

Measured memory_bytes: 256
n = int(input())
left = 0
right = n
print(left)
sl = input()
if sl[0] == "V":
    quit()
while True:
    mid = (left + right) // 2
    print(mid)
    sm = input()
    if sm[0] == "V":
        quit()
    if ((mid - left) % 2 == 1) ^ (sl == sm):
        left = mid
        sl = sm
    else:
        right = mid


Measured memory_bytes: 9180
N, M, X, Y = map(int, input().split())
x_array = list(map(int, input().split()))
y_array = list(map(int, input().split()))
x_array.append(X)
y_array.append(Y)
if max(x_array)<min(y_array):
    print('No War')
else:
    print('War')

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

using namespace std;

const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;

int dp[MAXN][120][3];

int main() {
    #ifdef BLAT
        freopen("input", "r", stdin);
    #endif

    string s;
    cin >> s;

    int d;
    cin >> d;

    s = ' ' + s;
    dp[0][0][1] = 1;
    for(int i = 1; i < s.size(); ++i) {
    	/// Pt Fiecare rest
    	for(int j = 0; j < d; ++j) {
    		/// Pun la obligatea
    		dp[i][(j+s[i]-'0') % d][1] += dp[i-1][j][1];
    		if(dp[i][(j+s[i]-'0') % d][1] >= MOD) dp[i][(j+s[i]-'0') % d][1] -= MOD;

    		/// Pun ca sa ma eliberez
    		for(int k = 0; '0' + k < s[i]; ++k) {
    			dp[i][(j+k)%d][0] += dp[i-1][j][1];
    			if(dp[i][(j+k)%d][0] >= MOD) dp[i][(j+k)%d][0] -= MOD;
    		}


    		/// Sunt deja liber
    		for(int k = 0; k < 10; ++k) {
    			dp[i][(j+k)%d][0] += dp[i-1][j][0];
    			if(dp[i][(j+k)%d][0] >= MOD) dp[i][(j+k)%d][0] -= MOD;
    		}

    	}
    }
    cout << ((dp[s.size() - 1][0][0] + dp[s.size() - 1][0][1] - 1 % MOD) + MOD) % MOD << '\n';
}   	

Measured memory_bytes: 14592
n, y = map(int, input().split())

yukichi = -1
ichiyo = -1
hideyo = -1
for i in range(n+1):
    for j in range(n-i+1):
        k = n - i - j
        total = i*10000 + j*5000 + k*1000
        if total == y:
            yukichi = i
            ichiyo = j
            hideyo = k

print("{} {} {}".format(yukichi, ichiyo, hideyo))


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var NR = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var (N, R) = (NR[0], NR[1]);

        var ans = R + ((N < 10) ? 100 * (10 - N) : 0);

        WriteLine(ans);
    }
}


Measured memory_bytes: 28268
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

int main(void)
{
    vector<int>v;
    int n,k,tmp,ans = 0;
    cin >> n >> k;
    for(int i = 0;i < n;i++){cin >> tmp; v.push_back(tmp);}
    sort(v.begin(),v.end());
    for(int i = 1;i <= k;i++)
    {
        ans += v[v.size() - i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,ans[9];
vector<pair<int,int> >sc;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for(int i=0;i<m;i++) {
		int s,c;
		cin>>s>>c;
		if(s==1&&c==0&&n>1) {
			cout<<-1<<endl;
			return 0;
		}
		bool put=1;
		for(int j=0;j<sc.size();j++)
			if(s==sc[j].first)
				if(c==sc[j].second) put=0;
				else {
					cout<<-1<<endl;
					return 0;
				}
		if(put) sc.push_back(make_pair(s,c));
	}
	if(n==1) {
		if(m==0) cout<<0<<endl;
		else cout<<sc[0].second<<endl;
		return 0;
	}
	if(m==0) {
		cout<<1;
		while(n>1) cout<<0,n--;
		return 0;
	}
	memset(ans,-1,sizeof(ans));
	m=sc.size();
	sort(sc.begin(),sc.end());
	for(int i=1;i<sc[0].first;i++) ans[i]=(i==1?1:0);
	for(int i=0;i<m-1;i++)
		if(ans[sc[i].first]==-1) {
			ans[sc[i].first]=sc[i].second;
			for(int j=sc[i].first+1;j<sc[i+1].first;j++) ans[j]=0;
		}
	ans[sc[m-1].first]=sc[m-1].second;
	int pos=sc[m-1].first;
	while(pos<n) ans[++pos]=0;
	for(int i=1;i<=n;i++) cout<<ans[i];
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

public class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		int A=sc.nextInt();
		int B=sc.nextInt();
		int C=sc.nextInt();
		int D=sc.nextInt();
		int P=sc.nextInt();
		int ASYA=A*P;
		int BSYA=0;
		if(C>=P) {
			BSYA=B;
		}
		else {
			BSYA=B+(P-C)*D;
		}
		pl(Math.min(ASYA, BSYA));
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
}



Measured memory_bytes: 24224
#include <iostream>
#include <queue>
#include <vector>
#include <map>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

const int INF = 1e+9 * 2;
typedef pair<int, int> P;

struct edge {
	int to, c;
	edge(int _to, int _c) : to(_to), c(_c){} 
};

int N, M, d[3001];
vector<edge> G[3001];

int main() {
	int k, shop, a, b, l;
	cin >> N >> M >> k;
	for(int i = 0; i < M; ++i){
		scanf("%d %d %d", &a, &b, &l);
		G[a].push_back(edge(b, l));
		G[b].push_back(edge(a, l));
	}
	
	priority_queue<P, vector<P>, greater<P> > que;
	fill(d, d + N + 1, INF);
	for(int i = 0; i < k; ++i){
		scanf("%d", &shop);
		d[shop] = 0;
		que.push(P(0, shop));
	}
	while(!que.empty()){
		P p = que.top();
		que.pop();
		int v = p.second;
		if(d[v] < p.first)
			continue;
		for(int i = 0; i < G[v].size(); ++i){
			edge e = G[v][i];
			if(d[e.to] > d[v] + e.c){
				d[e.to] = d[v] + e.c;
				que.push(P(d[e.to], e.to));
			}
		}
	}
	double ans = 0;
	
	for(int i = 1; i <= N; ++i){
		for(int j = 0; j < G[i].size(); ++j){
			ans = max(ans, (G[i][j].c + d[i] + d[G[i][j].to]) / 2.0);
		}
	}
	cout << round(ans) << endl;
	return 0;
}

Measured memory_bytes: 4308
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  vector<vl> g(n);
  rep(i, n - 1) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vl v(n, -1e18);
  ll k;
  cin >> k;
  priority_queue<P> q;
  rep(i, k) {
    ll u, p;
    cin >> u >> p;
    u--;
    v[u] = p;
    q.push({p, u});
  }
  bool ok = true;
  while(!q.empty()) {
    ll p = q.top().first;
    ll i = q.top().second;
    q.pop();
    for(auto u : g[i]) {
      if(v[u] != -1e18) {
        if(abs(v[u] - p) != 1) ok = false;
        continue;
      }
      v[u] = p - 1;
      q.push({v[u], u});
    }
  }
  if(ok) {
    cout << "Yes" << '\n';
    rep(i, n) cout << v[i] << '\n';
  } else
    cout << "No" << '\n';
}

Measured memory_bytes: 12236
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    LL N, K;
    cin >> N >> K;

    if (K < N) {
        N = N % K;
    }

    LL ans = min(N, K-N);
    cout << ans << endl;

    return 0;
}


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

//諸機能
#pragma region MACRO 
#define putans(x)  cerr << "answer: " ; cout << (x) << endl
#define dputans(x) cerr << "answer: "; cout << setprecision(10) << (double)(x) << endl
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define RREP(i,a,n) for(int i=(int)(n-1); i>= a; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) begin((a)),end((a))
#define mp make_pair
#define exist(container, n) ((container).find((n)) != (container).end())
#define substr(s,i,l) string((s), (i), (l))
#define tos(x) (to_string((x)))
#ifdef _DEBUG //ファイルからテストデータを読み込む
std::ifstream ifs("data.txt");
#define input ifs >>
#else //いい感じにやる
#define input cin >>
#endif
#pragma endregion
//デバッグなどの支援
#pragma region CODING_SUPPORT
#define dbg(var0) { std::cerr << ( #var0 ) << "=" << ( var0 ) << endl; }
#define dbg2(var0, var1) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg(var1); }
#define dbg3(var0, var1, var2) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg2(var1, var2); }
#define dbgArray(a,n) {std::cerr << (#a) << "=";  rep(i,n){std::cerr <<(a[i])<<",";} cerr<<endl;} 
#ifndef _DEBUG
#define dbg1 {}
#define dbg2 {}
#define dbg3 {}
#define dbgArray {}
#endif 
#pragma endregion 
//typedef（書き換える、書き足す可能性ある）
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii; typedef pair<string, string> pss; typedef pair<int, string>pis;
typedef vector<string> vs; typedef vector<int> vi;
#pragma endregion
//諸々の定数(書き換える可能性ある)
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-9)
#define MOD (ll)(1e9 + 7)
#define INF (ll)(1e9)
#pragma endregion

int main() {
	ll n, x; input n >> x;
	vector<ll> a;
	vector<ll> b;
	rep(i, n) {
		ll k; input k;
		a.push_back(k);
		b.push_back(k);
	}
	
	int index = 0;
	int tmp = INF;
	rep(i, n) {
		if (tmp > a[i]) {
			index = i;
			tmp = a[i];
		}
	}
	rotate(a.begin(), a.begin() + index, a.end());
	rotate(b.begin(), b.begin() + index, b.end());
	ll ans = 0;
	ll ma = a[0];
	ll mi = 0;
	ll msize = -1;
	rep(i, n) {
		ans += a[i];
	}
	REP(i,1,n) {
		ll tmp = i * x;
		RREP(j, 1 , n) {
			if (b[j] > b[j - 1]) {
				b[j] = b[j-1];
			}
			tmp += b[j];
		}
		tmp += b[0];
		ans = min(ans, tmp);
	}
	putans(ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n;
char A[300010];
int DrE[300010];
int StW[300010];
int main()
{
    cin>>n;
    for (int i=1; i<=n; i++)
        cin>>A[i];
    for (int i=1; i<=n; i++)
    {

        if (A[i-1]=='W')
        {
            StW[i]=StW[i-1]+1;
        }
        else
            StW[i]=StW[i-1];
    }
    for (int i=n; i>=1; i--)
    {

        if (A[i+1]=='E')
         {
            DrE[i]=DrE[i+1]+1;
         }
         else
            DrE[i]=DrE[i+1];
    }
    int mini=9999999999;
    for (int i=1; i<=n; i++)
    {
        mini=min(mini,StW[i]+DrE[i]);
    }
    cout<<mini<<' ';
}


Measured memory_bytes: 2944
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 ts = System.currentTimeMillis();
		long f[] = new long[N + 1];
		Arrays.fill(f, 1);
		for(int i = 2 ; i <= N ; ++i){
			for(int j = i ; j <= N ; j += i){
				f[j]++;
			}
		}
		long ret = 0;
		for(int i = 1 ; i <= N ; ++i){
			ret += i * f[i];
		}
		System.out.println(ret);
//		long te = System.currentTimeMillis();
//		System.out.println(te - ts);
	}
}


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

using namespace std;
typedef long long LL;
const LL INF=1000000000000;

int main(){
  int A, B, Q;
  cin >> A >> B >> Q;
  vector<LL> s(A), t(B), x(Q);
  rep(i,A) cin >> s[i];
  rep(i,B) cin >> t[i];
  rep(i,Q) cin >> x[i];
  rep(i,Q){
    LL X=x[i];
    int s_num=lower_bound(s.begin(),s.end(),X)-s.begin()-1;
    int t_num=lower_bound(t.begin(),t.end(),X)-t.begin()-1;
    LL ans=INF;
    if(s_num>=0&&t_num>=0) ans=min(ans,max(X-s[s_num],X-t[t_num]));
    if(s_num+1<A&&t_num+1<B) ans=min(ans,max(s[s_num+1]-X,t[t_num+1]-X));
    if(s_num>=0&&t_num+1<B) ans=min(ans,(X-s[s_num])*2+t[t_num+1]-X);
    if(s_num+1<A&&t_num>=0) ans=min(ans,(X-t[t_num])*2+s[s_num+1]-X);
    if(s_num+1<A&&t_num>=0) ans=min(ans,(s[s_num+1]-X)*2+X-t[t_num]);
    if(s_num>=0&&t_num+1<B) ans=min(ans,(t[t_num+1]-X)*2+X-s[s_num]);
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3712
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};

struct union_find{
    vector<int> par;
    vector<int> depth;
    vector<int> siz;
    int kid;

    union_find(int n) : par(n) , depth(n,0) , siz(n,1){
        rep(i,n) par[i]=i;
        kid=n;
    }

    int find(int x){
        if(par[x]==x) return x;
        return par[x]=find(par[x]);
    }

    void unite(int x,int y){
        x=find(x);
        y=find(y);
        if(x==y) return;
        kid --;
        siz[x] +=siz[y];
        siz[y] =siz[x];
        if(depth[x]<depth[y]) par[x]=par[y];
        else{
            par[y]=par[x];
            if(depth[x]==depth[y]) depth[x] ++;
        }
    }

    bool same(int x,int y){
        return find(x)==find(y);
    }
    int size(int x){
        return siz[find(x)];
    }
    int kind(){
        return kid;
    }
};

int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int n,q;
    cin>>n>>q;
    union_find uf(n);
    int x,y,z;
    rep(i,q){
        cin>>x>>y>>z;
        if(x) cout<<uf.same(y,z)<<endl;
        else uf.unite(y,z);
    }
}/*
./problem.exe
*/

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

int main() {
    int a, b;
    cin >> a >> b;
    if (a <= 0 && b >= 0) {
        cout << "Zero\n";
        return 0;
    }
    if (a > 0 && b > 0) {
        cout << "Positive\n";
        return 0;
    }
    cout << ((b - a) % 2 ? "Positive" : "Negative") << '\n';
    return 0;
}


Measured memory_bytes: 3616