akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const ll inf = 1e18;

int H[5005], P[5005], n;
ll dp[5005];

void upd(ll &x, ll y)
{
    if(x > y) x = y;
}

int main()
{
//    freopen("input", "r", stdin);
    cin.sync_with_stdio(false); cin.tie(0);

    cin >> n;

    int i;
    for(i=0; i<n; ++i) cin >> H[i] >> P[i];

    vector<int> ord(n);
    iota(ord.begin(), ord.end(), 0);

    sort(ord.begin(), ord.end(), [&] (int x, int y) { return H[x] + P[x] < H[y] + P[y]; } );

    for(i=1; i<=n; ++i) dp[i] = inf;

    for(auto it : ord)
        for(i=n; i>=0; --i)
            if(dp[i] <= H[it]) upd(dp[i+1], dp[i] + P[it]);

    for(i=n; i; --i)
        if(dp[i] != inf) break;

    cout << i << '\n';

    return 0;
}


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

int main(){
string s;
cin>>s;
sort(s.begin(),s.end());
if(s[0]==s[1]&&s[2]==s[3]&&s[1]==s[3])
cout<<"No"<<endl;
else if (s[0]==s[1]&&s[2]==s[3])
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,x,i,j,sum,min;
	sum=0;
	min=41001;
	scanf("%d %d %d",&a,&b,&x);
	for(i=0;i<=21;i++){
		for(j=0;j<=41;j++){
			//printf("i=%d j=%d\n",i,j);
			if(i*1000+j*500>=x){
				sum=i*a+j*b;
				if(min>sum){
					min=sum;
				}
			}
		}
	}
	printf("%d\n",min);
	return 0;
}

	


Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define rep(i,j) for (int (i)=0;(i)<(int)(j);++(i))
#define put(i) cout << (i) << endl
using namespace std;
typedef long long ll;
const int mod = 1e9+7;

ll dp[51][51][50*50+1];

int main() {
    int n, a; cin >> n >> a;
    vector<int> x(n+1); rep(i,n) cin >> x[i]; x[n] = -1;

    sort(x.begin(),x.end());
    int vm = max(x[x.size()-1], a);

    for (int i=0;i<=n;++i) {
        for (int j=0;j<=n;++j) {
            for (int k=0;k<=n*vm;++k) {
                if (!i && !j && !k) {
                    dp[i][j][k] = 1;
                }
                else if (i>=1 && k<x[i]) {
                    dp[i][j][k] = dp[i-1][j][k];
                }
                else if (i>=1 && j>=1 && k>=x[i]) {
                    dp[i][j][k] = dp[i-1][j][k]+dp[i-1][j-1][k-x[i]];
                }
            }
        }
    }

    ll ans=0;
    for (int j=1;j<=n;++j) {
        ans += dp[n][j][j*a];
    }

    cout << ans << endl;

}


Measured memory_bytes: 49280
#include <stdio.h>

int main(void){
	int n, v, t;
	scanf("%d",&n);
	int a[n],i,j;
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		}
		
	for(t=0;t<n;t++){
	printf("%d",a[t]);
		if(t<n-1){
		printf(" ");
		}
		}
		printf("\n");
	
	for(i=1;i<n;i++){
		v=a[i];
		j=i-1;
		while(j>=0&&v<a[j]){
			a[j+1]=a[j];
			j--;
		}
		a[j+1]=v;
		
		
		for(t=0;t<n;t++){
		printf("%d",a[t]);
			if(t<n-1){
				printf(" ");
			}
		}
		printf("\n");
	}

	return 0;
}
		



Measured memory_bytes: 2092
#include <string>
#include <vector>
#include <iostream>
using namespace std;
const int mod = 1000000007;
int n; string s1, s2;
int main() {
	cin >> n >> s1 >> s2;
	vector<int> v;
	for (int i = 0; i < n; i++) {
		if (s1[i] != s2[i]) i++, v.push_back(2);
		else v.push_back(1);
	}
	int ret = (v[0] == 1 ? 3 : 6);
	for (int i = 1; i < v.size(); i++) {
		if (v[i - 1] == 1) ret = 2LL * ret % mod;
		else if (v[i - 1] + v[i] == 4) ret = 3LL * ret % mod;
	}
	cout << ret << endl;
	return 0;
}

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

int main() {
	ios_base::sync_with_stdio( false );

	int N;
	cin >> N;

	vector<int> D( N );
	for( auto& v: D ) { cin >> v; }
	sort( D.begin(), D.end() );

	int M;
	cin >> M;

	bool result = true;

	for( int i = 0; i < M; ++i ) {
		int T;
		cin >> T;

		auto it = lower_bound( D.begin(), D.end(), T );

		if( it != D.end() && *it == T ) {
			D.erase( it );
		}
		else {
			result = false;
			break;
		}
	}

	cout << (result ? "YES" : "NO") << endl;

	return 0;
}


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

const int N = 100000;
const int NIL = -1;

struct Node {
  int parent, left, right;
};

void set_depth(int id, int d, Node T[], int depth[]) {
  depth[id] = d;
  if (T[id].left != NIL) set_depth(T[id].left, d+1, T, depth);
  if (T[id].right != NIL) set_depth(T[id].right, d, T, depth);
}

void set_type(int n, Node T[], string type[]) {
  for (int i = 0; i < n; i++) {
    if (T[i].parent == NIL) type[i] = "root";
    else if (T[i].left == NIL) type[i] = "leaf";
    else type[i] = "internal node";
  }
}

int main() {
  int i, j, n, id, k, c, child;
  Node Tree[N];
  string type[N];
  int depth[N];

  cin >> n;
  
  // init
  for (i = 0; i < n; i++) {
    Tree[i].parent = NIL;
    Tree[i].left = NIL;
    Tree[i].right = NIL;
  }
  
  // 位置関係をセット
  for (i = 0; i < n; i++) {
    cin >> id >> k;
    for (j = 0; j < k; j++) {
      cin >> c;
      Tree[c].parent = id;
      if (j == 0) {
        Tree[id].left = c;
        child = c;
      } else {
        Tree[child].right = c;
        child = c;
      }
    }
  }

  set_type(n, Tree, type);
  int root = 0;
  for (i = 0; i < n; i++) {
    if (type[i] == "root") root = i;
  }
  set_depth(root, 0, Tree, depth);

  // output
  for (i = 0; i < n; i++) {
    cout << "node " << i << ": parent = " << Tree[i].parent << ", depth = " << depth[i] << ", " << type[i] << ", [";
    int cnt = 0;
    int child = Tree[i].left;
    while (child != NIL) {
      if (cnt > 0) cout << ", ";
      cout << child;
      child = Tree[child].right;
      cnt++;
    }
    cout << "]" << endl;
  }
  
  return 0;
}



Measured memory_bytes: 10188
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long 
#define f(j) for(ll i=0;i<j;i++)
#define pb(i) push_back(i)
#define faster ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;    
typedef vector<vector<long long> > matrix; 
int main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
	// faster
	int n,m,a,b;
	cin>>n>>m;
	vector<int> visited(n+1,0),edge[n+1];
	f(m){
		cin>>a>>b;
		edge[a].pb(b);
		edge[b].pb(a);
	}
	int ans=-1;
	for(int i=1;i<=n;i++){
		if(!visited[i]){
			ans++;
			queue<int> q;
			q.push(i);
			while(!q.empty()){
				int node = q.front();
				q.pop();
				visited[node]++;
				for(int j :edge[node])
					if(!visited[j])
						q.push(j);
			}
		}
	}
	cout<<ans<<"\n";
return 0;	
}

Measured memory_bytes: 8856
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>

    #define INF 1e9
    #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 VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))

    using namespace std;
    using ll = long long;
	  
    int main(){
      int n,m;
      int MOD = 1e9+7;
      ll ans = 1,ans2 = 1;
      cin>>n>>m;
      int mx = max(m,n),mn = min(m,n);
      if(mx>mn+1){
        ans = 0;
      }else if(m == n){
        ans *= 2;
        rep(i,m)(ans *= (m-i)) %= MOD;
        rep(i,n)(ans *= (n-i)) %= MOD;
      }else if(mx == mn+1){
        rep(i,mx)(ans *= (mx-i)) %= MOD;
        rep(i,mn)(ans *= (mn-i)) %= MOD;
      }
      
      cout<<ans;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define pob pop_back
#define ff first
#define ss second
#define endl "\n"
#define all(a) a.begin(),a.end()
#define debug(x) cout << x << endl;
#define int long long
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

using namespace __gnu_pbds;
using namespace std;
using LD = long double;

const int N = 2e7+1;
const int mod = 1e9+7;
const int INF = 1e9;

void solve() {
	int n;
	cin >> n;
	map<string,int> MP;
	string s;
	for(int i=0;i<n;i++) {
		cin >> s;
		MP[s]++;
	}
	cout << "AC x " << MP["AC"] << endl;
	cout << "WA x " << MP["WA"] << endl;
	cout << "TLE x " << MP["TLE"] << endl;
	cout << "RE x " << MP["RE"] << endl;
}
 
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t = 1,i = 1;
    //cin >> t;
    while(t--) {
        //cout << "Case #" << i << ": ";
        solve();
        //i++;
    }
    return 0;
}


Measured memory_bytes: 3664
import sys
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def Main():
    n,m = IL()
    sub = [0]*n
    c = 0
    t = 0
    for _ in range(m):
        p,s = SL()
        p = int(p)
        if sub[p-1]==-1: continue

        if s=='AC':
            t += sub[p-1]
            sub[p-1] = -1
            c += 1
        elif s=='WA':
            sub[p-1] += 1
    print(c,t)
    return

if __name__=='__main__':
    Main()

Measured memory_bytes: 9560
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
#define ld long double
#define ft first
#define sd second
using namespace std;

const int N = 3e3 + 9;
ll f[1<<17];
const ll inf = 1e18;
ll dp[1<<17];
ll a[N][N], n;
vector<int> g[1<<17];

ll solve(int msk) {
    if(msk == 0) return 0;
    ll &ret = dp[msk];
    if(ret != -1) return ret;
    ret = -inf;
    for(int m: g[msk]) {
        ret = max(ret, f[msk^m] + solve(m));
    }
    return ret;
}   



signed main() {

    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            cin >> a[i][j];
        }
    }   
    memset(dp, -1, sizeof dp);
    for(int msk = 1; msk < (1<<n); msk++) {
        vector<int> v;
        for(int bit = 0; bit < n; bit++) {
            if((msk >> bit) & 1) v.pb(bit);
        }

        for(int i = 0; i <(int) v.size(); i++) {
            for(int j = i+1; j <(int) v.size(); j++) {
                f[msk] += a[v[i]][v[j]];
            }
        }
        for(int m = (msk-1) & msk; ; m = (m-1) & msk) {
            g[msk].pb(m);
            if(m == 0) break;
        }
    }

    cout << solve((1<<n) - 1);
    
    return 0;
}

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

using namespace std;

using int64 = long long;

int main() {
  int N;
  cin >> N;
  set< string > s;
  int last = -1;
  for(int i = 0; i < N; i++) {
    string x;
    cin >> x;
    if(last == -1 || last == x[0]) {
      last = x.back();
      if(s.count(x)) {
        cout << "No\n";
        return 0;
      }
      s.emplace(x);
    } else {
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
//typedef pair<int, int> P;
const int INF = 100000000;

struct P
{
   int x,y;
};


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

int main()
{
   int h,w;
   cin >> h >>w;
   vector<string> S(h);
   rep(i,h)cin >> S[i];
   int sx,sy,gx,gy;

   int ans=0;
   rep(i,h)
   {
      rep(j,w)
      {
         rep(ii,h)
         {
            rep(jj,w)
            {
               sx=i;
               sy=j;
               gx=ii;
               gy=jj;
               if(S[sx][sy]=='#'||S[gx][gy]=='#')
               {
                  continue;
               }
               vector<vector<int>> M(h,vector<int>(w,INF));
               queue<P> Q;
               P start;
               start.x=sx;
               start.y=sy;
               M[sx][sy]=0;
               Q.push(start);
               while(!Q.empty())
               {
                  P now = Q.front();
                  int nowcost = M[now.x][now.y];
                  Q.pop();
                  rep(iii,4)
                  {
                     P next;
                     next.x = now.x+dx[iii];
                     next.y = now.y+dy[iii];
                     if(0<=next.x&&next.x<h&&0<=next.y&&next.y<w&&S[next.x][next.y]=='.'
                     &&M[next.x][next.y]==INF)
                     {
                        M[next.x][next.y]=M[now.x][now.y]+1;
                        Q.push(next);
                     }
                  }
               }
               //cout<<M[gx][gy]<<endl;
               ans = max(ans,M[gx][gy]);

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

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main()
{
	int n;
	cin >> n;
	vector<int> l(n);
	for(int i = 0;i<n;i++)cin >> l[i];
	sort(l.begin(),l.end());
	ll ans = 0;
	for(int i = 0;i<n;i++)
	{
		for(int j = i+1;j<n;j++)
		{
			auto a = lower_bound(l.begin(),l.end(),l[j]-l[i]);
			auto b = lower_bound(l.begin(),l.end(),l[i]+l[j]);
			ans += (b-l.begin())-j-1;;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 384
n = int(input())
a = [int(i) for i in input().split()]
b = []
k = (n-1)//2
for i in range(k, 0, -1):
    b.append(a[i*2])
b.append(a[0])
k = n//2
for i in range(k):
    b.append(a[i*2+1])
if n%2 == 0:
    b = b[::-1]
print(*b)

Measured memory_bytes: 26180
import heapq
N = int(input())
A = list(map(int,input().split()))

#前半部分の最適化辞書作成
SUM = sum(A[:N])
firstDic = {N-1:SUM}
que = A[:N]
heapq.heapify(que)
for i in range(N,2*N):
    SUM += A[i]
    heapq.heappush(que,A[i])
    SUM -= heapq.heappop(que)
    firstDic[i] = SUM


#後半部分の最適化辞書作成
SUM = sum(A[2*N:])*-1
latterDic = {2*N-1:SUM*-1}
que = [A[i]*-1 for i in range(2*N,3*N)]
heapq.heapify(que)
for i in range(2*N-1,N-1,-1):
    SUM += A[i]*-1
    heapq.heappush(que,A[i]*-1)
    SUM -= heapq.heappop(que)
    latterDic[i-1] = SUM*-1
ans = -1*float("INF")
for k,v in firstDic.items():
    ans = max(ans,v-latterDic[k])

print(ans)

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

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

    int count = 0;
    bool even = true;
    while (even) {
        for (int i  = 0; i < n; i++) {
            if (a.at(i) % 2 == 0) {
                a.at(i) /= 2;
            } else {
                even = false;
            }
        }
        if (even) {
            count++;
        }
    }
    cout << count << endl;
    
}

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

using namespace std;

long long gcd(long long a, long long b, long long c) {
	return __gcd(a, __gcd(b, c));
}

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

	int N;
	cin >> N;

	long long sum = 0;

	for(int a = 1; a <= N; ++a) {
		for(int b = 1; b <= N; ++b) {
			for(int c = 1; c <= N; ++c) {
				sum += gcd(a, b, c);
			}
		}
	}

	cout << sum << '\n';

	return 0;	
}

Measured memory_bytes: 3592
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

int d, c;

int main()
{
	in >> d >> c;
	out << d * c << std::endl;
	return 0;
}


Measured memory_bytes: 3088
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    string g = s;
    reverse(s.begin(),s.end());
    int cnt=0;
    rep(i,s.size()){
        if(s[i]!=g[i]){
            cnt++;
        }
    }
    if(cnt%2==0){
        cout << cnt/2;
    }
    else{
        cout << cnt/2+1;
    }
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e18;
int mod = 998244353;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    string S,T;
    cin >> S >> T;
    int ans = INF;
    for(int i = 0; i < S.size()-T.size()+1; i++) {
        int cnt = 0;
        for(int j = 0; j < T.size(); j++) {
            if(S[i+j] != T[j]) {
                cnt++;
            }
        }
        ans = min(ans,cnt);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3628
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10**9 + 7

positive = []
negative = []
zero = 0
for t in a:
    if t < 0:
        negative.append(t)
    elif t == 0:
        positive.append(0)
        zero += 1
    else:
        positive.append(t)
if n - zero < k:
    print(0)
    exit()

positive.sort()
negative.sort(reverse=True)

if not positive:
    ans = 1
    if k % 2 == 1:
        if zero != 0:
            print(0)
            exit()
        for i in range(k):
            ans *= negative[i]
            ans %= mod
    else:
        for i in range(k):
            ans *= negative.pop()
            ans %= mod
    print(ans)
    exit()

ans = 1
# negative 処理
check = []
if len(negative) % 2 == 1:
    ww = negative[0]
    negative = negative[1:]
while negative:
    check.append(negative.pop() * negative.pop())

# positive
if k % 2 == 1:
    ans *= positive.pop()
    k -= 1

if len(positive) % 2 == 1:
    w = positive[0]
    positive = positive[1:]
while positive:
    check.append(positive.pop() * positive.pop())
check.sort()


for i in range(k//2):
    if check:
        ans *= check.pop()
    else:
        print(ans*w*ww%mod)
        exit()
    ans %= mod

print(ans)






Measured memory_bytes: 114624
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){std::fill( (T*)array, (T*)(array+N), val );};
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;};



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

  string s;
  cin >> s;
  if(s[0] == 'S') cout << "Cloudy" << endl;
  if(s[0] == 'C') cout << "Rainy" << endl;
  if(s[0] == 'R') cout << "Sunny" << endl;
  return 0;
}


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

int main (int argc, char * argv[])
{
    char W[10];//単語
    char T[1001];
    char t;
    int count = 0;
    scanf("%s",W);
    while (1){
        scanf("%s",T);
        //もし、END_OF_TEXTが入力されたらbreak
        if(strcmp(T, "END_OF_TEXT") == 0){
            break;
        }
        //大文字を小文字に
        for(int i=0;i<T[i]!='\0';i++){
            if('A'<= T[i] && T[i]<='Z'){
            T[i] =T[i]+32;
            }
        }
        
        if(strcmp(W,T) == 0){
            count++;
        }
    }
    printf("%d\n",count);
    
    
    return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 10101;
int n ;
ll x , a[N] , b[N] ;
ll A,B;

int main(){

scanf("%d",&n);
for(int i=0;i<n;i++){
    scanf("%lld",a+i);
}
for(int i=0;i<n;i++){
    scanf("%lld",b+i);
}

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

    if( a[i] < b[i] ){
        ll t = (b[i]-a[i]+1ll)/2ll;
        a[i]+=2ll*t;
        A+=t;
    }
    if( a[i] > b[i] ){
        ll t = (a[i]-b[i]);
        b[i]+=t;
        B+=t;
    }
}

if( A>=B  )printf("Yes\n");
else printf("No\n");

return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<stack>
#include<map>
#include<queue>
#include<vector>
#include<cmath>
#include<set>
#define inf 0x3f3f3f3f
typedef long long ll;

const int maxn=2e3+5;

int father[maxn],value[maxn];
int n,x,y,temp;

using namespace std;
int mp[maxn][maxn];
int cnt[maxn];

int main()
{
    scanf("%d%d%d",&n,&x,&y);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
            mp[i][j]=mp[j][i]=abs(j-i);
    }
    temp=y-x;
    for(int i=1;i<=x;i++)
    {
        for(int j=n;j>=y;j--)
        {
            mp[i][j]=mp[j][i]=mp[i][j]-temp+1;
        }
    }
    for(int i=1;i<y;i++)
    {
        for(int j=n;j>i;j--)
            mp[i][j]=mp[j][i]=min(mp[i][j],1+abs(i-x)+abs(y-j));
    }
    for(int i=1;i<n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            cnt[mp[i][j]]++;
        }
    }
    for(int i=1;i<=n-1;i++)
        printf("%d\n",cnt[i]);
}


Measured memory_bytes: 15872
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ECHO(x) cout<<x<<endl;
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;

int gcd(int x, int y){
  int sm, la, work;
  if(x<y) {
    la = y;
    sm = x;
  }
  else{
    la = x;
    sm = y;
  }

  while(1){
    work= la%sm;
    if(work==0)break;
    la=sm;
    sm=work;
  }
  return sm;
}

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

  int a, b;
  cin>>a;
  REP(i, n-1){
    cin>>b;
    a=gcd(a, b);
  }
  cout<<a<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,i,o;
  cin>>n;
  o=n;
  int a[n],b[o];
  for(i=1;i<=n;i++)
  {
    cin>>a[i];
    b[a[i]]=i;
  }
  for(i=1;i<=n;i++)
  {
    cout<<b[i]<<" ";
  }
}
    
    
    
  

Measured memory_bytes: 1536
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    k = ni()
    a, b = nm()

    for i in range(a, b+1):
        if i % k == 0:
            print('OK')
            exit()
    print('NG')


if __name__ == '__main__':
    main()

Measured memory_bytes: 9736
#include<bits/stdc++.h>
const unsigned int M = 1000000007; 
#define all(v) (v).begin(), (v).end()
#define rall(v) v.rbegin(),v.rend()
#define  pb push_back
#define mpp make_pair
#define int  long long
#define N 100002
#define endl "\n"
#define fr(i,n) for(int i=0;i<n;i++)
int power(int x,int y){int res=1;while(y>0){if(y&1)res=x*res; y=y>>1;x=x*x;}return res;}
int power(int x,int y,int mod){int res=1;while(y>0){if(y&1)res=x*res%mod; y=y>>1;x=x*x%mod;}return res;}

using namespace std;


void nik()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);

	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif
}




 signed main()
{
nik();

int t=1;
//cin>>t;

while(t--)
{
	int n,k,idx,x;
	cin>>n>>k;
	std::vector<int> v(n+1),a,arr;
	map<int,int>mp;
	for(int i=1;i<=n;i++)cin>>v[i];
	x=v[1];
	a.pb(0);
	for(int i=1;i<=n;i++)
	{
		if(mp.count(x))
		{
			idx=mp[x];
			break;
		}
		else mp[x]=i,a.pb(x);

		x=v[x];
	}
	for(int i=idx;i<(int)a.size();i++)arr.pb(a[i]);

	 //  cout<<"idx="<<idx<<endl;
	 // for(int it:arr)cout<<it<<" ";
		int m=a.size();
	int q=arr.size();
//cout<<m<<endl;
  if(k<m)cout<<a[k]<<endl;
  else 
  	{
  		k=k-idx;
  		cout<<arr[k%q]<<endl;
  	}

}
 return 0;
}



Measured memory_bytes: 20712
N,Y=map(int,input().split())
Y=Y//1000
# 1, 5, 10
a=b=c = -1
if N * 10 >= Y or Y < N:
  for x in range(0,N+1):
    for y in range(0,N-x+1):
      if Y == (x + y * 5 + 10 * (N - x - y)):
        a=x
        b=y
        c=(N - x - y)
        break
      if (a != -1):
        break
print('{} {} {}'.format(c, b, a))


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

#define _ << " _ " <<
#define TRACE(x) cout << #x << " = " << x << endl



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

    long long n, m;
    string s, t;

    cin >> n >> m >> s >> t;

    long long l = n * m / __gcd(n, m);

    long long n1 = n / __gcd(n, m);
    long long m1 = m / __gcd(n, m);

    map<long long, char> q;
    for (int i = 0; i < n; i++) q[m1 * i] = s[i];
    for (int i = 0; i < m; i++)
        if (q.find(n1 * i) != q.end() && q[n1 * i] != t[i]) {
            cout << -1;
            return 0;
        }


    cout << l;

    return 0;
}



Measured memory_bytes: 6144
#include<bits/stdc++.h>
using namespace std;
int main(){
  
 //とても大きい値を無限としておく。
  int n;
  cin >> n;  //Vは与えられた頂点数,Eは辺の数
  vector<vector<int>> a(n,vector<int>(n,0));//V*Vを無限で初期化
  for(int i=0;i<n;++i){
    int u,k;
    cin>>u>>k;
    u--;
    for(int j=0;j<k;++j){
      int v;
      cin>>v;
      v--;
      a[u][v]=1;
    }
  }
  for(int i=0;i<n;++i){
    for(int j=0;j<n;++j){
      cout<<a[i][j];
      if(j!=n-1){
        cout<<" ";
      }
    }
    cout<<endl;
  }
}




Measured memory_bytes: 3168
#include <iostream>
#include <math.h>
#include <string>
#include <stdio.h>
#include <algorithm>

using namespace std;

int main()
{
	int n, r, x;
	cin >> n >> r;
	if (n >= 10)
		cout << r << endl;
	else
		cout << r + 100 * (10 - n) << endl;
	return 0;
}


Measured memory_bytes: 256
using System.Linq;
using System.Text;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Diagnostics;
using System.Reflection.Metadata;
using System.Threading;
using System.Runtime.CompilerServices;
using System.IO.Pipes;

namespace AtCoder
{
    class Program
    {

        struct Point
        {
            public int x;
            public int y;

            public Point(int x, int y)
            {

                this.x = x;
                this.y = y;

            }

        }


        const int BiggestMod = 1000000007;

        public static void Main()
        {

            var args = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            var x = Math.Abs(args[0]);
            var k = args[1];
            var d = args[2];
            var ans = 0L;

            var min = x / d;

            if (min >= k)
                ans = x - (k * d);
            else
            {

                var buf = k - min;
                if ((buf & 1) == 0)
                    ans = x - min * d;
                else
                    ans = Math.Abs(x - (min + 1) * d);

            }

            Console.WriteLine(ans);

        }

    }

}

Measured memory_bytes: 28240
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

int main () {
  int n;
  cin >> n;
  vvi a(2,vi(n));
  rep(i,2)rep(j,n) cin >> a[i][j];

  vector<int> s0(a[0].size()+1);
  rep(i,a[0].size()) {
    s0[i+1] = s0[i] + a[0][i];
  }
  vector<int> s1(a[1].size()+1);
  rep(i,a[0].size()) {
    s1[i+1] = s1[i] + a[1][i];
  }

  int ans = 0;
  rep(i,n) {
    ans = max(ans, s0[i+1]-s0[0] + s1[n]-s1[i]);
  }
  cout << ans << endl;
  return 0;
}

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

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define forn(i,n) for(ll i=0;i<n;i++)
#define fore(i,a,b) for(ll i=a;i<=b;i++)
#define ford(i,n) for(ll i=n-1;i>=0;i--)
#define fi first
#define se second
#define endl "\n"
#define all(a) a.begin(),a.end()
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PI 3.14159265

/*************************************************************************************/
void file(){
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
}
/*************************************************************************************/

const ll nax=2e5+1,mod=1e9+7;



int main(){

    sync
   // file();
    ll n;
    cin>>n;
    ll ar[n+1],br[n];
    forn(i,n+1) cin>>ar[i];
    forn(i,n) cin>>br[i];
    ll ans  = 0;
    forn(i,n){
        ll ok = min(ar[i],br[i]);
        ans+=ok;
        br[i]-=ok;
        ok = min(br[i],ar[i+1]);
        ans+=ok;
        ar[i+1]-=ok;
    }
    cout<<ans;

  return 0;
}

Measured memory_bytes: 1792
//#include <bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<string>
#include<queue>
#include<vector>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)//初期値a,i<bの範囲でループ
#define REP(i,n) FOR(i,0,n)//初期値0,i<nの範囲でループ
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;

int m,n;

int main(){
    cin>>n>>m;
    int ans=0;
    int a=pow(2,m);
    ans+=((n-m)*100+1900*m)*a;

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 384
N,M = map(int,input().split())
# ue,sita,uee,sitaa = 0,0,0,0
# tmpN,tmpM = 0,0
# if N != 2:
#     for i in range(N+1):
#         ue *= N-i
#         sita *= N-2-i
#     tmpN = ue/sita
# if M != 2:
#     for i in range(M+1):
#         uee *= N-i
#         sitaa *= N-2-i
#     tmpM = uee/sitaa

# print(tmpN+tmpM)

ans = N*(N-1)/2 + M*(M-1)/2

print(int(ans))

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    ll n;cin>>n;
    ll sum = 0,minus = 0,mi = L_INF;
    rep(i,n){
        ll a;cin>>a;
        if(a<0)minus++;
        sum+=abs(a);
        mi = min(mi,abs(a));
    }
    if(minus & 1)out(sum-2*mi);
    else out(sum);
}


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

//#include <atcoder/all>

using namespace std;
//using namespace atcoder;

//#define int long long
#define ll long long

ll INF = (1LL << 60);
int mod = 998244353;
using P = pair<ll, ll>;

signed main() {
	int n, a, b; cin >> n >> a >> b;
	cout << min(n*a, b) << endl;
	return 0;
}



Measured memory_bytes: 3604
import sys
input = sys.stdin.readline

def main():
    MOD = 1000000007
    N = int(input())
    s = []
    s.append(list(input().strip()))
    s.append(list(input().strip()))

    # pre 0:たて 1:よこ
    i = 0
    if s[0][i] == s[1][i]:
        pre = 0
        ans = 3
        i += 1
    else:
        pre = 1
        ans = 6
        i += 2
    
    while i < N:
        # print(i)
        if s[0][i] == s[1][i]:
            if pre == 0:
                ans *= 2
            else:
                ans *= 1
            i += 1
            pre = 0
        else:
            if pre == 0:
                ans *= 2
            else:
                ans *= 3
            i += 2
            pre = 1
        ans %= MOD
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define DEBUG
#ifdef DEBUG
#define debug_printf printf
#else
#define debug_printf 1 ? 0 : printf
#endif

typedef long long int ll;
typedef vector<ll> Vl;
typedef vector<int> Vi;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pl;

#define FST first
#define SND second

// const int MAX_N = 100000;                  // 10^5
// const int MAX_N = 100000;                  // 10^5
// const int MAX_N = 1000000000;              // 10^9
// const ll  MAX_N = 1000000000000000000;     // 10^18
const int BASE  = 1000000000 + 7;          // 10^9 + 7
// const int INFI  = 1000000000 + 7;          // 10^9 + 7
// const ll INFL  = 1000000000000000000 + 7; // 10^18 + 7

int N, M;

ll perm(int n) {
  ll x = 1;
  for (int i = 0; i < n; i++) x = (x * (i + 1)) % BASE;
  return x;
}

ll calc() {
  if (abs(N - M) > 1) return 0;

  ll pn = perm(N);
  ll pm = perm(M);

  ll ans = 1;
  ans = (ans * pn) % BASE;
  ans = (ans * pm) % BASE;
  if (N == M) ans = (ans * 2) % BASE;

  return ans;
}

void solve() {
  cout << calc() << endl;
}

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

  solve();

  return 0;
}


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

using namespace std;

typedef long long ll;
typedef long long unsigned int llui;
typedef long long int lli;
typedef long double float64;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;

#define INF 1000000000
#define MOD 1000000007
#define EPS 1e-9
#define DEBUG(x) cout<< '>' << #x << ':' << x << "\n";
#define all(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define UNIQUE(x) (x).erase(unique((x).begin(),(x).end()),(x).end())
#define tr(container, it) \
    for(typeof(container.begin()) it = container.begin(); it != container.end(); it++) 

// #define sz(a) int((a).size())
// #define pb push_back
// #define fill(a,v) memset(a,v,sizeof a)


#define trace(x) cout << '>' << #x << ':' << x << endl;
#define trace2(x,y) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y << endl;

#define trace3(x,y,z) cout<< '>' << #x << ':' << x \
        << " | " << #y << ':' << y <<" | " << #z << ':' << z << endl;

#define trace4(x,y,z,w) cout<< '>' << #x << ':' << x \
    << " | " << #y << ':' << y <<" | " << #z << ':' << z << " | " << #w << ':' << w << endl;


inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }

#define LSOne(S) (S&(-S))

const double pi = acos(-1);

/////////////////////////////////////////////////////////////////////

/*bool sortbysec(const pair<int,int> &a,const pair<int,int> &b)
{
    return (a.second < b.second);
}*/

template<class T> inline T gcd(T a,T b)//NOTES:gcd(   __gcd(0,0) gives exception
  {if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}

const int MAX_N = 2345;

int main() {
    string s,t;
    cin>>s>>t;
    for(int i=s.length()-t.length();i>-1;i--){
        bool flag=true;
        for(int j=0;j<t.length();j++){
            if(s[i+j]!='?' && s[i+j]!=t[j])
                flag=false;
        }
        if(flag){
            //DEBUG(i);
            for(int j=0;j<i;j++){
                if(s[j]!='?')
                    printf("%c",s[j]);
                else
                    printf("a");
            }
            //DEBUG(i);
            cout<<t;
            for(int j=i+t.length();j<s.length();j++){
                if(s[j]!='?')
                    printf("%c",s[j]);
                else
                    printf("a");
            }
            printf("\n");
            return 0;
        }
    }
    printf("UNRESTORABLE\n");
    return 0;
}


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

int main() {
	int h, m, s; cin >> s;
	m = (s - (s % 60)) / 60; s %= 60;
	h = (m - (m % 60)) / 60; m %= 60;
	cout << h << ":" << m << ":" << s << endl;
	return 0;
}


Measured memory_bytes: 3096
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e8
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	buf := make([]byte, initialBufSize)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
}

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

func min(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

func main() {
	var X, K, D int64 = abs(int64(nextInt())), int64(nextInt()), int64(nextInt())
	var r int64 = min(K, X/D)
	var X1 int64 = X - r*D
	if (K-r)%2 == 1 {
		fmt.Println(abs(X1 - D))
	} else {
		fmt.Println(X1)
	}
}


Measured memory_bytes: 1772
main :: IO ()                                                                                                              
main = do                                                                                                                  
  [_, x] <- map (read :: String -> Int) . words  <$> getLine                                                               
  xs <- map (read :: String -> Int) . words  <$> getLine                                                                   
                                                                                                                           
  let diffX = map (abs . ((-) x)) xs                                                                                       
      gcdX = foldr getGcd 0 diffX                                                                                          
                                                                                                                           
  putStrLn $ show gcdX                                                                                                     
                                                                                                                           
getGcd :: Int -> Int -> Int                                                                                                
getGcd a 0 = a                                                                                                             
getGcd a b                                                                                                                 
  | a `mod` b == 0 = b                                                                                                     
  | otherwise = getGcd b $ a `mod` b 

Measured memory_bytes: 58748
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    h = list(map(int, input().split()))
    res = 0
    for i in range(n):
        if h[i] == max(h[:i+1]):
            res += 1
    print(res)

if __name__ == '__main__':
    main()

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

int n;

void dfs(string s,char mx){
    if(s.size() == n){
        cout << s << endl;
        return;
    }
    for(char c = 'a'; c <= mx+1; c++){
        string t = s;
        t += c;
        dfs(t, max(mx,c));
    }
}

int main(){
    cin >> n;
    dfs("",'a'-1);
    return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,y;
  
  cin>>N>>y;
  
  for(int i=N;i>=0 ;i--){
    for(int j=0;j<=N-i;j++){
      
      int k= N-i-j;
        if(y==10000*i+5000*j+1000*k){
          cout <<i<<" "<<j<<" "<<k<<endl;
          return 0;
        }
      }
    }
  
  
  
  
  cout <<"-1 -1 -1" <<endl;
}

Measured memory_bytes: 256
def input_one_number():
    return int(input())

def input_multiple_number():
    return map(int, input().split())

def input_multiple_number_as_list():
    return list(map(int, input().split()))


A,B,C,D = input_multiple_number()

while A > 0 and C > 0:
	C = C- B
	if C <= 0:
		print("Yes")
		exit()

	A = A-D
	if A <=0:
		print("No")
		exit()


Measured memory_bytes: 9188
#include<stdio.h>
#include<string.h>
 
#define M 1076401
#define L 14
 
char H[M][L]; /* Hash Table */
 
int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}
 

long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}
 
int h1(long long key){ return key%M; }
int h2(long long key){ return 1+key%(M-1); }
 
int find(char str[]){
  int sum;
  int f1,f2;
  long long a;
  a=getKey(str);
  f1=h1(a);
  f2=h2(a);
  
    if(strcmp(H[f1],str)==0){
      return 1;
    }
    if(H[f1][0]=='\0'){
      return 0;
    }
   sum=f1;
 
   while(1){
      sum=(sum+f2)%M;
   if(H[sum][0]=='\0'){
      return 0;
    }
    else if(strcmp(H[sum],str)==0){
      return 1;
    }
     
     
  }
  return 0;
   
}
void insert(char str[]){
  int sum;
  int f1,f2;
  long long a;
  a=getKey(str);
  f1=h1(a);
  f2=h2(a);
    if(H[f1][0]=='\0'){
      strcpy(H[f1],str);
      return;
    }
    sum=f1;
 
    while(1){
     sum=(sum+f2)%M;
   if(H[sum][0]=='\0'){
       strcpy(H[sum],str);
 
      break;
    }
  }
}
 
int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
     
    scanf("%d", &n);
     
    for ( i = 0; i < n; i++ ){
    scanf("%s %s", com, str);
     
    if ( com[0] == 'i' ){
        insert(str);
    } else {
        if (find(str)==1){
        printf("yes\n");
        } else {
        printf("no\n");
        }
    }
    }
 
    return 0;
}

Measured memory_bytes: 15324
#include <stdio.h>
#define MAX 500000
#define INFTY 2000000000
 
void mergesort(int *,int,int);
void merge(int *,int,int,int);
 
int l[MAX/2+2],r[MAX/2+2];
int count;
int s[MAX];
 
int main()
{
 
  int n,i;
  count=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&s[i]);
  }
 
  mergesort(s,0,n);
 
  for(i=0;i<n;i++){
    if(i>0) printf(" ");
    printf("%d",s[i]);
  }
  printf("\n");
  printf("%d\n",count);
 
  return 0;
}
 
 
 
void mergesort(int a[],int left,int right)
{
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergesort(a,left, mid);
    mergesort(a,mid,right);
    merge(a,left,mid,right);
  }
}
 
void merge(int a[],int left,int mid,int right)
{
  int i,j,k,n1,n2;
  n1=mid-left;
  n2=right-mid;
  for(i=0;i<n1;i++)
    l[i]=a[left+i];
  for(i=0;i<n2;i++)
    r[i]=a[mid+i];
  l[n1]=INFTY;
  r[n2]=INFTY;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    count++;
    if(l[i]<=r[j]) {
      a[k]=l[i];
      i=i+1;
    }
    else {
      a[k]=r[j];
      j=j+1;
    }
  }
}

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

// 解説AC

int main(){ 
  
  int N; cin >> N;
  
  vector<vector<int>> to(N);
  
  for(int i = 0; i < N-1; i++){ 
    int a,b; cin >> a >> b; 
    a--; b--;
    
    to[a].push_back(b);
    to[b].push_back(a);
    
  }

  // 0を頂点としてもっとも遠い点を探す
  
  vector<int> dist(N,-1);
  dist[0] = 0;
  
  queue<int> Q; Q.push(0);
  
  while(!Q.empty()){ 
    int p = Q.front(); Q.pop();
    
    for(int i = 0; i < (int)to[p].size(); i++){ 
      
      int q = to[p][i];
      
      if( dist[q] != -1 ){ continue;}
      else{ dist[q] = dist[p]+1; Q.push(q);}
      
    }
   
    
  }
  
  int u = 0; int res = 0;
  
  for(int i = 0; i < N; i++){ 
    
    if( dist[i] > res ){ res = dist[i]; u = i;}
    
  }
  
  vector<int> dist2(N,-1); dist2[u] = 0;
  
  queue<int> Q2; Q2.push(u);
  
  while(!Q2.empty()){
    
    int p = Q2.front(); Q2.pop();
    
    for(int i = 0; i < (int)to[p].size(); i++){
      
      int q = to[p][i];
      
      if( dist2[q] != -1){ continue;}
      else{
        dist2[q] = dist2[p]+1; 
        Q2.push(q);
        
      }
    }
  }
  
  res = 0; int v = 0;

  for(int i = 0; i < N; i++){ 
    
    if( dist2[i] > res ){ v = i; res = dist2[i];}
    
  }

  // uとvの距離はres;
  
  if( res % 3 == 1 ){ cout << "Second" << endl;}
  else{ cout << "First" << endl;}
  
  return 0;
} 
    
    
    
  

Measured memory_bytes: 14452