akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse4")
#include <cassert>
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <bitset>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <math.h>
#include <random>
using namespace std;
typedef long long ll;
typedef unsigned long long  ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef long double ld;
mt19937 rnd(random_device{}());
#define all(a) a.begin(), a.end()
#define fr(i, n) for (ll i = 0; i < n; ++i)
#define fr1(i, n) for (ll i = 1; i <= n; ++i)
const int N = 1000001;
ll p[N], c[N];
void solve() {
    int n, k; cin >> n >> k;
    fr1(i, n) cin >> p[i];
    fr1(i, n) cin >> c[i];
    ll bst = -1000000000000000000ll;
    fr1(i, n) {
        int v = p[i];
        vector<ll> vec = { v };
        while (p[v] != vec[0]) {
            vec.push_back(p[v]);
            v = p[v];
        }

        ll sum = 0;
        for (auto it : vec) sum += c[it];
        ll s = 0, cnt = 0;
        for (auto it : vec) {
            ++cnt;
            s += c[it];
            if (cnt > k) break;
            bst = max(bst, s + (sum < 0 ? 0 : ((k - cnt) / ((int)vec.size())) * sum));
        }
    }
    cout << bst;
}
void pre_calc() {
}
int main() {
    pre_calc();
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef ABCD
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
#endif
    int tst = 1;
    if (tst != 1) cin >> tst;
    while (tst--)
        solve();
}

Measured memory_bytes: 3856
#!/usr/bin/env python3
from functools import reduce
import sys

MOD = 1000000007  # type: int


def solve(N: int, M: int):
    if M > N:
        M, N = N, M
    if M + 1 < N:
        print(0)
        return
    mf = reduce(lambda a, b: a * b % MOD, range(1, M + 1), 1)
    if M == N:
        ans = mf * mf % MOD * 2 % MOD
    else:
        ans = mf * mf % MOD * N % MOD
    print(ans)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    solve(N, M)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
from datetime import date
while True:
    m, d = map(int, input().split())
    if m == 0:
        break
    result = date(2004, m, d).isoweekday()
    print("Mon"*(result==1)+"Tues"*(result==2)+"Wednes"*(result==3)+"Thurs"*(result==4)+"Fri"*(result==5)+"Satur"*(result==6)+"Sun"*(result==7)+"day")

Measured memory_bytes: 7980
#include <iostream>
	#include <vector>
	#include <set>
	#include <cmath>

	using namespace std;

	int main() {
		long long int realt = 1, reala = 1;
		int n;
		cin >> n;
		for(int i = 0; i < n; i++) {
			long long int t, a;
			cin >> t >> a;
			if(reala > a || realt > t) {
				long double mula = ((long double)reala)/a;
				long double mult = ((long double)realt)/t;
				if(mula > mult) {
					long long int increase = (long long int)ceil(mula);
					realt = t*increase;
					reala = a*increase;
				}
				else {
					long long int increase = (long long int)ceil(mult);
					realt = t*increase;
					reala = a*increase;
				}
			}
			else {
				realt = t;
				reala = a;
			}
		}
		long long int ans = realt + reala;
		cout << ans << endl;
	}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int i,n=s.size();
  string t="yes";
  for(i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      if(s.at(i)==s.at(j)){
        t="no";
      }
    }
  }
  cout << t;
}

Measured memory_bytes: 256
<?php
/*
    Problem URL : http://abc051.contest.atcoder.jp/tasks/abc051_b

    Score  :
    Result :
    Time   : ms
    Memory : KB
 */

fscanf(STDIN, "%d %d", $K, $S);

$ans = 0;

for ($x = 0; $x <= $S; $x++) {
    for ($y = $x; $x + $y <= $S; $y++) {
        $z = $S - $x - $y; 
        if ($x > $K || $y > $K || $z > $K) continue;   
        if ($z < $y) continue;    
        // echo "{$x} {$y} {$z}\n";
        $a1 = $x === $y;
        $a2 = $x === $z;
        $a3 = $y === $z;
        $aa = $a1 + $a2 + $a3;
        switch ($aa) {
            case 3:
                $ans += 1;
                break;

            case 1:
                $ans += 3;
                break;

            case 0:
                $ans += 6;
                break;
        }
        // echo "{$x} {$y} {$z} {$aa}\n";
    }
}
echo $ans . PHP_EOL;


Measured memory_bytes: 2936
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int n,a[50]={},t;
	cin>>n;
	if(n==0){
		cout<<n<<endl;
		return 0;
	}
	int idx=0;
	while(n!=0){
		int m=n;
		if(m>0){
			a[idx]=m%2;
			m-=a[idx];
			m/=2;
			n=-m;
		}else{
			a[idx]=(-m)%2;
			m-=a[idx];
			m/=2;
			n=-m;
		}
		idx++;
	}
	FORD(i,idx,0){
		cout<<a[i];
	}
    return 0;
}


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

struct Data {
    int s, t, c;
};
bool compareT(const Data &left, const Data &right) {
    return left.s < right.s;
}

int main()
{
    int N, Ch;
    cin >> N>> Ch;
    Data D[N];
    map<int, vector<Data>> chData;
    rep(i, N) {
        Data d;
        cin >> d.s >> d.t >> d.c;
        chData[d.c].push_back(d);
    }
    int len = (pow(10, 5) + 1) * 2;
    int counts[len];
    for (int i = 0; i < len; i++) {
        counts[i] = 0;
    }
    for (auto ch : chData) {
        auto v = ch.second;
        sort(v.begin(), v.end(), compareT);
        int last = -1;
        for (auto c: v) {
            int st = c.s * 2;
            int ed = c.t * 2;
            if (st != last) {
                st--;
            }
            last = ed;
            for (int i = st; i < ed; i++) {
                counts[i]++;
            }
        }
    }
    int ans = *max_element(counts, counts + len);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4724
#pragma region head
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define test(s) \
  if (!(s))     \
    cout << "Line " << __LINE__ << ": [" << #s << "] is false" << endl;
#define int long long
typedef long long ll;
#define double long double
typedef double ld;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1.0);

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
#pragma endregion

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

  vector<int> LW(N + 1);
  rep(i, N) {
    LW[i + 1] = LW[i] + (c[i] == 'W');
  }

  vector<int> RR(N + 1);
  repr(i, N, 1) {
    RR[i - 1] = RR[i] + (c[i - 1] == 'R');
  }

  int ans = INF;
  rep(i, N + 1) {
    int temp = max(LW[i], RR[i]);
    chmin(ans, temp);
  }
  cout << ans << endl;
}

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

# 加算・減算の回数を固定すると範囲が決まる

import numpy as np

N,A,B,C,D = map(int,input().split())

# 加算の回数をもとに
rng = np.arange(N,dtype=np.int64)
upper = D*rng - C*rng[::-1]
lower = C*rng - D*rng[::-1]

answer = 'YES' if ((lower <= B-A) & (B-A <= upper)).any() else 'NO'
print(answer)

Measured memory_bytes: 31932
n,m = map(int,input().split())
a = list(map(int,input().split()))
x = []
for i in range(m):
    x.append(list(map(int,input().split())))
x = sorted(x, key=lambda s:s[1], reverse=True)
y = []
for i in range(m):
    b,c = x[i][0],x[i][1]
    y += [c]*b
    if len(y) >= n:
        break
z = a+y
print(sum(sorted(z,reverse=True)[:n]))

Measured memory_bytes: 93080
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
using namespace std;
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007


int main(int argc, char const *argv[]) {
  int n,k;
  std::cin >> n >> k;
  if(n/2+n%2>=k)std::cout << "YES" << '\n';
  else std::cout << "NO" << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=65;
const double eps=1e-6;
int n,k,x[N],y[N],c[N];
double dis(double x1,double y1,double x2,double y2){
	return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int calc(double x1,double y1,double w){
	int num=0;
	for(int i=0;i<n;i++)
		if(dis(x1,y1,x[i],y[i])<=w/c[i]+eps)num++;
	return num;
}
bool work(double x1,double y1,double w1,double x2,double y2,double w2,double w){
	double a=dis(x1,y1,x2,y2);
	if(a>w1+w2+eps)return 0;
	double co=(a*a+w1*w1-w2*w2)/(2*a*w1),l=w1*co,x3=x1+(x2-x1)/a*l,y3=y1+(y2-y1)/a*l,
	h=sqrt(w1*w1-l*l),x4=x3-(y2-y1)/a*h,y4=y3+(x2-x1)/a*h,x5=2*x3-x4,y5=2*y3-y4;
	return calc(x4,y4,w)>=k||calc(x5,y5,w)>=k;
}
bool check(double w){
	for(int i=0;i<n;i++)if(calc(x[i],y[i],w)>=k)return 1;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++)
			if(work(x[i],y[i],w/c[i],x[j],y[j],w/c[j],w))return 1;
	}
	return 0;
}
int main(){
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)scanf("%d%d%d",x+i,y+i,c+i);
	double l=0,r=1e6,mid;
	while(r-l>eps){
		mid=(l+r)/2;
		if(check(mid))r=mid;
		else l=mid;
	}
	printf("%.7lf",l);
	return 0;
} 

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

bool f(int x) {
  int a, b, c, d, e;
  a = x % 10;
  b = (x / 10) % 10;
  c = (x / 100) % 10;
  d = (x / 1000) % 10;
  e = (x / 10000) % 10;
  
  if(a == e && b == d) return true;
  else return false;
}

int main() {
  int a, b;
  cin >> a >> b;
  
  int i, ans = 0;
  for(i = a; i <= b; i++){
    if(f(i)) ans++;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int n, m;
int a;

int main()
{
	scanf("%d%d", &n, &m);
	
	int num;
	int count = 0;
	for (int i = 0 ; i < n ; i++)
	{
		scanf("%d", &num);
		if (num >= m)
			count++;
	}
	
	printf("%d\n", count);
	
	
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define mt make_tuple
typedef long long int ll;

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;

typedef long long int ll;
int a,b,c;
int main(void){
	cin >> a >> b >> c;
	if (a==b && b==c){
		cout << "Yes" << endl;
	}else cout << "No" << endl;
	


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int a[4][13];
string s = "SHCD";

int main() {
    int n, b;
    char c;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> c >> b;
        if (c == 'S') {
            a[0][b - 1]++;
        } else if (c == 'H') {
            a[1][b - 1]++;
        } else if (c == 'C') {
            a[2][b - 1]++;
        } else if (c == 'D') {
            a[3][b - 1]++;
        }
    }
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 13; j++) {
            if (a[i][j] == 0) {
                cout << s[i] << " " << j + 1 << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3184
#include <stdio.h>
int main()
{
    int W, H, x, y, r;
  
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
  
    if (x >= r && y >= r && x <= W - r && y <= H - r){
        printf("Yes\n");
    } else {
        printf("No\n");
    }
  
    return 0;
  
}

Measured memory_bytes: 1716
import java.util.Scanner;
public class Main {
	int n;
	int list[];
	boolean sieve[];
	public static void main(String main[]) {
		new Main();
	}
	Main() {
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		list = new int[n];
		int max = 0;
		for (int i = 0; i < n; i++) {
			list [i] = scan.nextInt();
			max = Math.max(max, list[i]);
		}
		sieve = new boolean[max + 1];
		int sqMax = (int)Math.round(Math.sqrt(max));
		for (int i = 2; i <= sqMax; i++) {
			if (sieve[i])continue;
			int j = 2;
			while (i * j < max + 1) {
				sieve[i * j] = true;
				j++;
			}
		}
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			if (!sieve[list[i]]) {
				cnt++;
			}
		}
		System.out.println(cnt);
	}
}



Measured memory_bytes: 141524
#include<iostream>
#include<queue>
using namespace std;
#define N 100

int graph[N][N];
int dis[N];
int check[N];
int n;
queue<int> q;

void init(){
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            graph[i][j] = 0;  //图初始化
        }
        check[i]=0;           //标记数组初始化
        dis[i] = -1;
    }
    int v,count,x;
    for(int i=0;i<n;i++){
        cin>>v;
        cin>>count;
        for(int i=0;i<count;i++){
            cin>>x;
            graph[v-1][x-1]=1;
        }
    }
    q.push(1);
    check[0]=1;
    dis[0]= 0;
}

int BFS(int v){
    for(int i=0;i<n;i++){
        if(graph[v-1][i]>0&&check[i]==0){
            q.push(i+1);
            check[i]=1;
            dis[i] = dis[v-1]+1;
        }
    }
    q.pop();
}

int main(){
    init();
    while(q.size()>0){
        BFS(q.front());
    }
    for(int i=0;i<n;i++){
        cout<<i+1<<" "<<dis[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 3136
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <algorithm>

using namespace std;

#define INT_MAX 2147483647

int main( void ){

	string str;

	cin >> str;

	int cnt = 0;

	for( int i = 0; i < str.size(); i++ ){
		if(str[i] == '1') cnt++;
	}

	cout << cnt << endl;
	return 0;

}



Measured memory_bytes: 256
import java.util.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.nextLine();
    String T = sc.nextLine();
    String t = T.substring(0, T.length()-1);

    if(S.equals(t)){
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

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

int main() {
  int A, B, C, D;
  cin>>A>>B>>C>>D;
  if (A+B == C+D) {
    cout << "Balanced" << endl;
  }
  else if (A+B > C+D) {
    cout << "Left" << endl;
  }
  else if (A+B < C+D) {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#define LL long long
using namespace std;

bool Prime[1005];
LL Cnt[1005]={0};//记录每个素数的次数 
LL MOD=1e9+7;

int main(){
	memset(Prime,false,sizeof(Prime));
	for(int i=2;i<=sqrt(1005);i++){
		if(!Prime[i]){
			for(int j=i*i;j<=1005;j+=i){
				Prime[j]=true;
			}
		}
	}
	
	int n;
	cin>>n;
	for(int i=2;i<=n;i++){
		
		for(int j=2; j<=i ; j++){
			if(!Prime[j]){
				int temp=i;
				
				while(temp%j==0){
					Cnt[j]++;
					temp /= j;
				}
				//cout<<"i="<<i<<" j="<<j<<endl;
			}
		}
	}
	
	LL ans=1;
	for(int i=2;i<=1000;i++){
		if(Cnt[i]){
			//cout<<"Cut["<<i<<"]="<<Cnt[i]<<endl;
			ans = ans*(Cnt[i]+1) % MOD;
		}
	}
	cout<<ans<<endl;
	return 0;	
} 

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

using namespace std;
typedef pair<int, int> P;

P a[200], b[1000];

int main(){
	int m, n, x, y;
	bool r;

	while(cin >> m, m){
		for(int i = 0;i < m;++i){
			cin >> x >> y;
			a[i] = make_pair(x, y);
		}
		cin >> n;
		for(int i = 0;i < n;++i){
			cin >> x >> y;
			b[i] = make_pair(x, y);
		}
		sort(a, a + m);
		sort(b, b + n);

		P base = a[0];
		for(int i = 0;i < m;++i){
			a[i] = make_pair(a[i].first - base.first, a[i].second - base.second);
//			cout << a[i].first << " " << a[i].second << endl;
		}

		for(int i = 0;i < n;++i){
			P t = b[i];
			r = true;
			for(int j = 1;j < m && r;++j){
				P s = make_pair(t.first + a[j].first, t.second + a[j].second);
				r = r && binary_search(b, b + n, s);
			}
			if(r){
				cout << t.first - base.first << " " << t.second - base.second << endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3092
#include<bits/stdc++.h>
#define ll                 long long int
#define mod                998244353
#define pi                 3.14159265358979323846264338327950288419716939937510
#define setbit(x)          __builtin_popcountll(x)
#define db                 long double
#define pp(x)              pair<x,x>
#define ff                 first
#define ss                 second
#define FIO                ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tc                 ll tc; cin>>tc; for(ll number = 1 ; number <= tc ; number ++ )
#define vv(x)              vector<x>
#define pb                 push_back
#define pob                pop_back
#define pf                 push_front
#define pof                pop_front
#define endl               "\n"
#define pq                 priority_queue
#define dbg(x)             { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y)          { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define bp                 ll kkk; cin >>kkk;
#define dbgArr(a,n)        cout<<"Array "<<#a<<endl; for(ll i=0 ; i<n ; i++) cout<<a[i]<<" "; cout<<endl;
#define maxE(a,n)          *max_element(a,a+n);
#define minE(a,n)          *min_element(a,a+n);
#define forn(i,s,n)        for(ll i=s ; i<n ; i++)
#define fornr(i,e,s)       for(ll i=e-1 ; i>=s ; i--)
#define arr1(a,n)          for(ll i=1;i<=n;i++){ cin>>a[i]; }
#define file freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define print cout<<"Case #"<<number<<": "
#define all(x) x.begin(), x.end()
ll power(ll x, ll b) {ll p = 1;while (b > 0) {if(b&1) {p = p * x; p %= mod;} b >>= 1; x *= x; x %= mod;} return p % mod;}
using namespace std;
# define INF 1e15

struct ppp{
    ll a,b,c;
};

struct lex_compare {
    bool operator() (ppp p1, ppp p2){
        if(p1.a == p2.a){
            if(p1.b == p2.b) return p1.c < p2.c;
            else return p1.b < p2.b;
        }else{
            return p1.a < p2.a;
        }
    }
};

int main(){
    FIO;
    string s; cin >> s;
    if(s[s.size()-1] == 's'){
        cout << s << "es" << endl;
    }else{
        cout << s << "s" << endl;
    }
    return 0;
}


Measured memory_bytes: 3656
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
int main(){
	int x,y,w,h;
	int z;
	cin >> z;
	while(z--){
	    scanf("%d%d%d%d",&x,&y,&w,&h);
        int X = x + w,Y = y + h;
        int n;
        cin >> n;
        int cnt = 0;
        for(int i = 0; i < n; i++){
            int a,b;
            scanf("%d%d",&a,&b);
            if(x <= a && a <= X && y <= b && b <= Y)cnt++;
        }
        cout << cnt << endl;
	}
	return 0;
}

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

#define PB push_back
#define F first
#define S second
#define MP make_pair
#define LL long long
#define ULL unsigned long long
#define LB lower_bound
#define MOD1 1000000007
#define MOD2 1000000009


int main()
{
    static const int _ = []() {
        ios::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        return 0;
    }();
    int n;
    cin >> n;
    vector<int> ht(n);
    for (int i = 0; i < n; i++)
        cin >> ht[i];
    vector<int> dp(n, INT_MAX);
    dp[0] = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j : {i + 1, i + 2})
        {
            if (j < n)
            {
                dp[j] = min(dp[j], dp[i] + abs(ht[i] - ht[j]));
            }
        }
    }

    cout << dp[n - 1];

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll a[200001],b[200001];
int main()
{
	ll n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<n;i++)
	{
		cin>>b[i];
	}
	sort(a,a+n,less<int>());
	sort(b,b+n,greater<int>());
	ll y=-1;
	for(int i=0;i<n;i++)
	{
		y=max(a[i]*b[i],y);
	}
	ll x=0;
	ll time=0;
	while(x<y)
	{
		ll m=x+(y-x)/2;
		ll flag=1;
		ll tmpk=0;
		time++;
		for(int i=0;i<n;i++)
		{
			ll res=m/b[i];
			if(res>a[i])continue;
			tmpk+=a[i]-res;
			if(tmpk>k){
			flag=0;
			break;}
		}
		if(flag)y=m;
		else x=m+1;
	}
	cout<<x;
	return 0;
}

Measured memory_bytes: 3328
/**********************
 * Author: Cloud_     *
 * Date:   27.06.2020 * 
 * Time:   17.56.57   *
 *                    *
***********************/
#include <bits/stdc++.h>
using namespace std;

#define gap " "
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ok cout<<"ok"<<endl
#define dbg(x) cout<<(#x)<<" is "<<x<<endl
#define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);}

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

const int N=100009;

int main()
{
  //fastio; 
  int sum=0,a;
  cin>>a;
  sum=a+(a*a)+(a*a*a);
  cout<<sum<<endl;
  return 0;
}

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

const double EPS = 1e-9;
const int MOD = 1e9+7;
const int INF = 2e5;
const double PI = acos(-1.0);

using namespace std;

struct MinCostFlow {
    struct edge {
        int to;
        int cap;
        int cost;
        int rev;
        bool is_rev;
    };
    const int INF;
    vector<vector<edge>> G;

    MinCostFlow(int n, int inf) : G(n), INF(inf) {
        ;
    }

    void add_edge(int from, int to, int cap, int cost) {
        G[from].push_back((edge){to, cap, cost, (int)G[to].size(), false});
        G[to].push_back((edge){from, 0, -cost, (int)G[from].size()-1, true});
    }

    int minCostFlow(int s, int t, int f) {
        const int N = G.size();
        int cost = 0;
        vector<int> prev_v(N, -1);
        vector<int> prev_e(N, -1);
        while (f > 0) {
            vector<int> dist(N, INF);
            dist[s] = 0;
            bool update = true;
            while (update) {
                update = false;
                for (int v=0; v<N; ++v) {
                    if (dist[v] == INF) continue;
                    for (int i=0; i<G[v].size(); ++i) {
                        edge &e = G[v][i];
                        if (e.cap > 0 && dist[e.to] > dist[v] + e.cost) {
                            dist[e.to] = dist[v] + e.cost;
                            prev_v[e.to] = v;
                            prev_e[e.to] = i;
                            update = true;
                        }
                    }
                }
            }
            if (dist[t] == INF) {
                return -1;
            }
            int d = f;
            for (int v=t; v!=s; v=prev_v[v]) {
                d = min(d, G[prev_v[v]][prev_e[v]].cap);
            }
            f -= d;
            cost += d * dist[t];
            for (int v=t;v!=s;v=prev_v[v]) {
                edge &e = G[prev_v[v]][prev_e[v]];
                e.cap -= d;
                G[v][e.rev].cap += d;
            }
        }
        return cost;
    }
};

int main() {
    int V, E, F;
    cin >> V >> E >> F;
    MinCostFlow mcf(V, INF);
    rep(i, E) {
        int u, v, c, d;
        cin >> u >> v >> c >> d;
        mcf.add_edge(u, v, c, d);
    }
    cout << mcf.minCostFlow(0, V-1, F) << endl;
}



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

int main() {
  int S, W;
  cin >> S >> W;

  if(S <= W) cout << "unsafe" << endl;
  else cout << "safe" << endl;
}


Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cassert>

using namespace std;
using ll = long long;

int main()
{
    int m, d;
    cin >> m >> d;
    int ans = 0;
    for(int i = 1; i <= m; i++){
        for(int j = 1; j <= d; j++){
            if(j / 10 >= 2 && j % 10 >= 2 && (j / 10) * (j % 10) == i){
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
// ITP1_7_A
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    // Configuration
    Scanner scanner = new Scanner(System.in);

    // Initialization
    int m = 0;
    int f = 0;
    int r = 0;

    // score calc
    while(true){
      String[] row = scanner.nextLine().split(" ");
      m = Integer.parseInt(row[0]);
      f = Integer.parseInt(row[1]);
      r = Integer.parseInt(row[2]);

      // stop condition
      if(m==-1 && f==-1 && r==-1){
        break;
      }

      // F rank
      if(m==-1 || f==-1){
        System.out.println("F");
        continue;
      }

      if(m+f>=80){ // A rank
        System.out.println("A");
      }else if(m+f>=65 && m+f<80){ // B rank
        System.out.println("B");
      }else if(m+f>=50 && m+f<65){ // C rank
        System.out.println("C");
      }else if(m+f>=30 && m+f<50){ // D rank
        if(r>=50){
          System.out.println("C");
        }else{
          System.out.println("D");
        }
      }else{
        System.out.println("F");
      }
    }
  }
}



Measured memory_bytes: 26200
#include <bits/stdc++.h>
#define _for(i,b,e) for (common_type_t<decltype(b),decltype(e)> i = (b), i ## __end = (e); i < i ## __end; ++ i)
#define FOR(...)   _for (__VA_ARGS__)
#define rep(i,n)   FOR (i, size_t{}, n)
#define ALL(x)     begin (x), end (x)
using namespace std;
using ll = int64_t;


template <typename T, typename F>
struct segtree_t
{
  size_t n;
  vector <T> nodes;
  F f;

  static constexpr auto nextpow2 (size_t x)
  {
    size_t res = 1;
    if (x == 0) res = 0;
    else while (res < x) res <<= 1;
    return res;
  }

  static constexpr size_t root = 1;
  static auto parent (size_t i)
  {
    return i / 2;
  }
  static auto left (size_t i)
  {
    return i * 2;
  }
  static auto right (size_t i)
  {
    return left (i) + 1;
  }

  segtree_t (const vector <T> v, F f_, T init = T {})
    : n {nextpow2 (v.size ())}
    , nodes (2 * n, init)
    , f {f_}
  {
    rep (i, v.size ()) nodes[i + n] = v[i];
    for (size_t i = n; i -- > root;) nodes[i] = f (nodes[left (i)], nodes[right (i)]);
  }

  auto update (size_t i, T value)
  {
    i += n;
    nodes[i] = move (value);
    while ((i = parent(i)) >= root)
    {
      nodes[i] = f (nodes[left (i)], nodes[right (i)]);
    }
  }

  auto get (int a, int b)
  {
    return get_impl (a, b, root, 0, n);
  }

private:
  auto get_impl(size_t a, size_t b, size_t k, size_t l, size_t r)
  {
    if (r <= a || b <= l) return nodes[0];

    if (a <= l && r <= b) return nodes[k];

    auto mid = (l + r) / 2;
    auto vl = get_impl (a, b, left (k), l, mid);
    auto vr = get_impl (a, b, right (k), mid, r);
    return f (vl, vr);
  }
};

template <typename T, typename F>
auto make_segtree (const vector <T> & v, F f, T init = T {})
{
  return segtree_t <T, F> (v, f, init);
}

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

  size_t n;
  string s;
  size_t q;
  cin >> n >> s >> q;

  vector <set <char>> aa (n);
  rep (i, n) aa[i].insert (s[i]);

  auto st = make_segtree (aa, [](set <char> l, auto && r){
    for (auto && elem : r) l.insert (elem);
    return l;
  });

  rep (q_, q)
  {
    int t;
    cin >> t;
    if (t == 1)
    {
      size_t i;
      char c;
      cin >> i >> c;
      -- i;
      st.update (i, set <char> {c});
    }
    else
    {
      int l, r;
      cin >> l >> r;
      -- l;
      auto ans = st.get (l, r);
      cout << ans.size () << endl;
    }
  }
}


Measured memory_bytes: 282396
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		String a, b;
		long n;
		try (Scanner sc = new Scanner(System.in)) {
			a = sc.next();
			b = sc.next();
			n = Long.parseLong(a) & Long.parseLong(b);
			System.out.println(String.format("%32s", Long.toBinaryString(n)).replace(' ', '0'));
			n = Long.parseLong(a) | Long.parseLong(b);
			System.out.println(String.format("%32s", Long.toBinaryString(n)).replace(' ', '0'));
			n = Long.parseLong(a) ^ Long.parseLong(b);
			System.out.println(String.format("%32s", Long.toBinaryString(n)).replace(' ', '0'));
		}
	}
}



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

int A, B;

int main() {
    cin >> A >> B;

    if (A == B) {
        cout << "Draw" << endl;
    }
    else if (A == 1) {
        cout << "Alice" << endl;
    }
    else if (B == 1) {
        cout << "Bob" << endl;
    }
    else {
        if (A < B) {
            cout << "Bob" << endl;
        }
        else {
            cout << "Alice" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 764
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yassin
 */

#include <fstream>

#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <tuple>
#include <queue>
#include <functional>
#include <stack>
#include <cassert>

using namespace std;


class atD {
private:
    int N;
    inline char opp(char c) {
        return c == 'W' ? 'S' : 'W';
    }
    bool check(string &res, const string &s) {
        for (int i = 1; i < N-1; ++i) {
            if (s[i] == 'o') {
                if (res[i] == 'W') {
                    res[i+1] = opp(res[i-1]);
                } else if (res[i] == 'S') {
                    res[i+1] = res[i-1];
                }
            } else if (s[i] == 'x') {
                if (res[i] == 'W') {
                    res[i+1] = res[i-1];
                } else if (res[i] == 'S') {
                    res[i+1] = opp(res[i-1]);
                }
            }
        }
        
        bool flag = true;
        if (s[0] == 'o') {
            if (res[0] == 'W') {
                flag = res[N-1] == opp(res[1]);
            } else if (res[0] == 'S') {
                flag = res[N-1] == res[1];
            }
        } else if (s[0] == 'x') {
            if (res[0] == 'W') {
                flag = res[N-1] == res[1];
            } else if (res[0] == 'S') {
                flag = res[N-1] == opp(res[1]);
            }
        }
        if (s[N-1] == 'o') {
            if (res[N-1] == 'W') {
                return flag && res[N-2] == opp(res[0]);
            } else if (res[N-1] == 'S') {
                return flag && res[N-2] == res[0];
            }
        } else if (s[N-1] == 'x') {
            if (res[N-1] == 'W') {
                return flag && res[N-2] == res[0];
            } else if (res[N-1] == 'S') {
                return flag && res[N-2] == opp(res[0]);
            }
        }
        assert(true);
        return true;
    }
public:
    void solve(istream& in, ostream& out) {
        string s;
        in >> N >> s;
        
        string res(N, ' ');
        res[0] = 'S'; res[1] = 'S';
        if (check(res, s)) {
            out << res << "\n";
            return;
        }
        
        res.assign(N, ' ');
        res[0] = 'S'; res[1] = 'W';
        if (check(res, s)) {
            out << res << "\n";
            return;
        }
        
        res.assign(N, ' ');
        res[0] = 'W'; res[1] = 'S';
        if (check(res, s)) {
            out << res << "\n";
            return;
        }
        
        res.assign(N, ' ');
        res[0] = 'W'; res[1] = 'W';
        if (check(res, s)) {
            out << res << "\n";
            return;
        }
        
        out << "-1\n";
    }
};


int main() {
	std::ios::sync_with_stdio(false);

	atD solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 640
import math
a,b,c,d = map(int,input().split())

def death_time(hp,atack):
    if hp%atack == 0:
        return hp/atack
    else:
        return hp//atack + 1

takahashi_death = death_time(a,d)
aoki_death = death_time(c,b)

if aoki_death<=takahashi_death:
    print("Yes")
else:
    print("No")

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

int main(){
  int n,i,j;
  cin >> n;
  vector<int> a(n),b(n);
  for(i=0;i<n;i++){
    cin >> a.at(i);
  }
  j=0;
  for(i=n-1;i>=0;i=i-2){
    b.at(j)=a.at(i);
    j++;
  }
  j=n-1;
  for(i=n-2;i>=0;i=i-2){
    b.at(j)=a.at(i);
    j--;
  }
  for(i=0;i<n;i++){
    cout << b.at(i) << " ";
  }
}

Measured memory_bytes: 4856
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAX = 100005;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if(b-a == c-b)
        puts("YES");
    else
        puts("NO");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
 
int main()
{
  int N;
  cin >> N;
  string S;
  cin >> S;

  int x = 0;
  int MAX = 0;
  REP(i,N){
    if(S.at(i) == 'I'){
      x++;
    }else{
      x--;
    }
    MAX = max(MAX,x);
  }

  cout << MAX << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


int gcd(int a,int b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(a%b,b);
}
//FUNCTION
void solve(void)
{
  int N; cin>>N;
  int X; cin>>X;
  for (int i = 0; i < N-1; i++)
  {
    int A;cin>>A;
    X = gcd(X,A);
  }
  cout<<X<<endl;
  
  

  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(15);
  solve();

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void){
  string s;
  cin >> s;
  
  int retval;
  if(s == "SUN"){
    retval = 7; 
  } else if (s == "MON"){
    retval = 6;
  } else if (s == "TUE"){
    retval = 5;
  } else if (s == "WED"){
    retval = 4;
  } else if (s == "THU"){
    retval = 3;
  } else if (s == "FRI"){
    retval = 2;
  } else if (s == "SAT"){
    retval = 1;
  }
  cout << retval;
  return 0;
}


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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;

vector<int> g[maxn];
int n, k;

int dfs(int u, int p = -1) {
    int init, ans = 1;
    if (p == -1)init = k - 1;
    else init = k - 2;

    if (init + 1 < g[u].size())
        return 0;
    for (auto x : g[u]) {
        if (x != p) {
            ans *= init--;
            ans %= MOD;
            ans *= dfs(x, u);
            ans %= MOD;
        }
    }
    return ans;
}

void solve() {
    cin >> n >> k;

    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;

        g[a].push_back(b);
        g[b].push_back(a);
    }
    cout << (k * dfs(1)) % MOD << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

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

    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 11648
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        try(Scanner sc = new Scanner(System.in)){
        	while(sc.hasNext()) {
        		
        		String b = sc.next();
        		int c  = Integer.parseInt(b);
        		char[] str = b.toCharArray();
        		int a = 0;
        		for(int i=0;i<str.length;i++) {
        			a += Integer.parseInt(String.valueOf(str[i]));
        		}
        		if(c%a==0) System.out.println("Yes");
        		else System.out.println("No");
        	}
        }
    }
}


Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define Endl cout << endl
#define SIZE(s) (int)s.size()
#define Cout(n) cout<<(n)<<endl

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

bool substring_search(string s,string key){
    int count=0;
    for(int i=0;i<(int)s.size();i++){
        if(s[i]==key[count]) count++;
        if(count==(int)key.size()) return true;
    }
    return false;
}

int main()
{
    ll n,l=0,r=0,sum=99999999999999999;
    cin >> n;
    vll a(n);
    rep(i,n){
        cin >> a[i];
        r+=a[i];
    }
    rep(i,n-1){
        l+=a[i];
        r-=a[i];
        sum=min(sum,abs(l-r));
    }
    Cout(sum);
    return 0;
}


Measured memory_bytes: 1792
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
#dt = {k:v for k,v in sorted(x.items(), key=lambda i: i[1])}
ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda :int(input())
ip = lambda :[int(w) for w in input().split()]
mp = lambda :map(int,input().split())


a = input()
b = input()
if a == b[:-1]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 61792
#include<bits/stdc++.h>
using namespace std;
int main(){
  int X,Y,Z,K;
  cin>>X>>Y>>Z>>K;
  vector<long long>A(X);
  vector<long long>B(Y);
  vector<long long>C(Z);
  for(int i=0;i<X;i++){
    cin>>A.at(i);
  }
  for(int i=0;i<Y;i++){
    cin>>B.at(i);
  }
  for(int i=0;i<Z;i++){
    cin>>C.at(i);
  }
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  sort(B.begin(),B.end());
  reverse(B.begin(),B.end());
  sort(C.begin(),C.end());
  reverse(C.begin(),C.end());
  int N;
  N=X*Y;
  vector<long long>D(N);
  int k;
  for(int i=0;i<X;i++){
    for(int j=0;j<Y;j++){
      D.at(k)=A.at(i)+B.at(j);
      k=k+1;
    }
  }
  sort(D.begin(),D.end());
  reverse(D.begin(),D.end());
  int M;
  M=K*Z;
  vector<long long>E(M);
  int l=0;
  for(int i=0;i<min(N,K);i++){
    for(int j=0;j<Z;j++){
      E.at(l)=D.at(i)+C.at(j);
      l=l+1;
    }
  }
  sort(E.begin(),E.end());
  reverse(E.begin(),E.end());
  for(int i=0;i<K;i++){
    cout<<E.at(i)<<endl;
  }
}

Measured memory_bytes: 31616
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef pair<int, int> pii;
// #define INF __INT32_MAX__
#define INF 1e9
#define LINF __LONG_LONG_MAX__

int main() {
    int N; cin >> N;
    int x = N;

    int sum = 0;
    while (x > 0) {
        sum += x % 10;
        x /= 10;
    }

    if (N % sum == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3564
#include <stdio.h>
long long int gcd( long long int a, long long int b )
{
	if ( a%b == 0 ) {
		return b;
	} else {
		return gcd( b, a%b );
	}
}

long long int lcm( long long int a, long long int b )
{
	return ( a*b ) / gcd( a, b );
}
int main()
{
	long long int x=1, y=1, z=1;
	long long int a1, a2, a3;
	long long int m1, m2, m3;
	long long int cnt1 = 0, cnt2 = 0, cnt3 = 0;

	while ( scanf( "%llu %llu %llu %llu %llu %llu", &a1, &m1, &a2, &m2, &a3, &m3 ) == 6 ) {
		if ( a1 == 0 && m1 == 0 && a2 == 0 && m2 == 0 && a3 == 0 && m3 == 0 ) { break; }

		cnt1 = 0, cnt2 =0, cnt3 = 0;
		x = y = z = 1;
		// x1, y1, z1が同時に1になる場合を探索するとTLEするため, 
		// 個別に1となる回数をカウントしたのち, それぞれのカウントの
		// 最小公倍数を求める.
		while ( 1 ) {
			x = ( a1 * x ) % m1;
			cnt1++;	
			if ( x == 1 ) { break; }
		}
		while ( 1 ) {
			y = ( a2 * y ) % m2;
			cnt2++;
			if ( y == 1 ) { break; }
		}
		while ( 1 ) {
			z = ( a3 * z ) % m3;
			cnt3++;
			if ( z == 1 ) { break; }
		}
		printf( "%llu\n", lcm( lcm( cnt1, cnt2 ), cnt3 ) );
	}

	return 0;
}



Measured memory_bytes: 2040
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

use std::cmp::{max, min};

fn main() {
  let n = read::<i64>();
  let d = read::<i64>();
  let x = read::<i64>();
  let mut ans = 0;
  // let mut a = vec![];
  for _ in 0..n {
    let a = read::<i64>();
    ans += ((d - 1) / a) + 1;
  }

  println!("{}", ans + x);
}



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

bool ispossible(long long n, long long k, long long* arr, long long piecelen) {
	long long curr = 0; for (long long i = 0; i < n; i ++) {
		long long numpiece = arr[i] / piecelen; if (numpiece * piecelen < arr[i]) numpiece++; curr += (numpiece-1);
	} if (curr <= k) return true; else return false;
}

int main() {
	long long n, k; cin >> n >> k; long long arr[n]; for (long long i = 0; i < n; i ++) cin >> arr[i];
	long long low = 1, mid, high = 1000000000000, ans = 1000000000000;
	while(low <= high) {
		mid = (low + high) / 2;
		if (ispossible(n, k, arr, mid)) { 
			ans = mid; 
			high = mid-1;
		} else low = mid+1;
	} cout << ans << endl;
}

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

int main() {
  int64_t A, B, K;
  cin >> A >> B >> K;
  if(A + B <= K) cout << 0 << " " << 0 << endl;
  else if(A <= K) cout << 0 << " " << A + B - K << endl;
  else cout << A - K << " " << B << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define gc getchar()
#define ll long long
#define pb push_back
#define mk make_pair
#define rint register int
#define debug(x) cerr<<#x<<"="<<x<<"\n"
#define pa pair<ll,int>
#define fir first
#define sec second
#define paa pair<pa,pa>
using namespace std;
inline int read(){int w=1,s=0;char ch=getchar();while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}while(isdigit(ch)){s=s*10+ch-'0';ch=getchar();}return  w*s;}
struct node{int to,next,w;} e[410100];
struct edge{int u,v;ll w;} ed[5010000];
inline bool operator < (edge p,edge q){return p.w<q.w;}
int h[201010],tot,n,w[201010],f[201000],vis[201000],rt,sz[201010],Min,cur,used[201001],cnt;
inline paa operator + (pa p,paa q){
    pa a=p;
    if(a.first<q.first.first){
        if(q.first.second!=a.second)
		swap(q.first,q.second),swap(q.first,a);
        else swap(q.first,a);
    }
    else if(a.first<q.second.first){
        if(q.first.second!=a.second) swap(q.second,a);
    }
    return q;
}
inline void add(int from,int to,int w){e[++tot].next=h[from];h[from]=tot;e[tot].to=to;e[tot].w=w;}
inline int find(int x){if(x==f[x]) return x;else return f[x]=find(f[x]);}
inline void get_rt(int now,int ffa){
    sz[now]=1;int Max=0;
    for(rint i=h[now];i;i=e[i].next){
        int to=e[i].to;if(to==ffa) continue;if(used[to]) continue;
        get_rt(to,now);sz[now]+=sz[to];Max=max(Max,sz[to]);
    }Max=max(Max,cur-sz[now]);
    if(Max<Min) Min=Max,rt=now;
}
ll dep[200100],Val,pos;
inline void DFS(int now,int ffa){
    for(rint i=h[now];i;i=e[i].next){
        int to=e[i].to;if(to==ffa) continue;if(used[to]) continue;
        dep[to]=dep[now]+e[i].w;DFS(to,now);
    }
    if(dep[now]+w[now]<Val) Val=dep[now]+w[now],pos=now;
}
inline void DFS2(int now,int ffa){
	sz[now]=1;
	ed[++cnt]=(edge){now,pos,w[now]+Val+dep[now]};
    for(rint i=h[now];i;i=e[i].next){
        int to=e[i].to;if(to==ffa) continue;if(used[to]) continue;
        DFS2(to,now);sz[now]+=sz[to];
    }
}
inline void Solve(int now){
	used[now]=1;
    dep[now]=0;
    Val=2e18;
    DFS(now,0);
    DFS2(now,0);
    for(rint i=h[now];i;i=e[i].next){
        int to=e[i].to;if(used[to]) continue;
        cur=sz[to];Min=1e9;
        get_rt(to,now);
        Solve(rt);
    }
}
int main()
{//	freopen("a.in","r",stdin);
    n=read();
    for(rint i=1;i<=n;++i) w[i]=read();
    for(rint i=1;i<n;++i){
        int u=read(),v=read(),w=read();
        add(u,v,w);add(v,u,w);
    }
    for(rint i=1;i<=n;++i) f[i]=i;
    ll res=0;
	Min=1e9,cur=n;
    get_rt(1,0);
    Solve(rt);
    sort(ed+1,ed+cnt+1);
    for(rint i=1;i<=cnt;++i){
    	int x=ed[i].u,y=ed[i].v;
    	x=find(x),y=find(y);
    	if(x!=y) f[x]=y,res+=ed[i].w;
	}
    cout<<res<<endl;	
    return 0;
}			


Measured memory_bytes: 70400