akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;

int N, M, V, P; 
vector<int> A;

bool f(int x){
  // M人がV問の点数を1上げる
  // 上位P-1個と自分に点数を上げる
  // 残りは小さいところから上げていく
  if(N-P <= x) return true;
  
  if(A[x]+M < A[N-P]) return false;
  // 残りM*Vまで上げなければいけない
  // 1個につき上げれる点数はM
  // A[x]+Mになるまで上げれば良い
  int cnt = 0;
  REP(i, N-P+1){
    if(i == x) continue;
    cnt += min(M, A[x]+M-A[i]);
  }
  if(cnt >= M*V) return true;
  return false;
}

signed main() {
  cin >> N >> M >> V >> P;
  V -= P;

  A.resize(N);
  REP(i, N) cin >> A[i];

  sort(ALL(A));

  vector<int> B = A;
  B.resize(unique(ALL(B))-B.begin());

  int ok = B.size()-1;
  int ng = -1;
  while(ok-ng > 1){
    int mid = (ok+ng)/2;
    int t = upper_bound(ALL(A), B[mid])-A.begin()-1;
    if(f(t)) ok = mid;
    else ng = mid;
  }

  cout << A.end()-lower_bound(ALL(A), B[ok]) << endl;

  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define N 300005
#define int long long
using namespace std;
int n,x,a[N];
signed main(){
	cin>>x;
	for(int i=1;i<=300000;i++) a[i]=a[i-1]+i;
	cout<<lower_bound(a+1,a+1+300000,x)-a;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define loop(i,a,n) for(int i=a; i<n; i++)
#define rloop(i,a,n) for(int i=a; i>=n; i--)
#define lli long long int
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ff first
#define ss second
#define pb push_back

lli dp[3001][3001];
bool visited[3001][3001];

lli func(lli v[],int beg,int end,int cnt){
	if(visited[beg][end]!=0)
		return dp[beg][end];
	else if(beg==end)
	{
		if(cnt%2)
			return v[beg];
		else{
			return v[beg]*(-1);
		}
	}
	else{
		visited[beg][end]=1;
		if(cnt%2){
			dp[beg][end]=max(v[beg]+func(v,beg+1,end,cnt+1),v[end]+func(v,beg,end-1,cnt+1));
		}
		else{
			dp[beg][end]=min((-1*v[beg])+func(v,beg+1,end,cnt+1),(-1*v[end])+func(v,beg,end-1,cnt+1));
		}
		return dp[beg][end];
	}
}

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

	lli v[n+1];

	loop(i,1,n+1){
		cin>>v[i];
	}

	cout<<func(v,1,n,1);
}

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

int main() {
  int A, B;
  int count = 0;
  cin >> A >> B;
  for(int i = A; i <= B; i++) {
    if(i/10000 == i%10 && (i-10000*(i/10000))/1000 == (i%100-i%10)/10) {
      count++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
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;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  ll a, b, c, d; cin >> a >> b >> c >> d;
  cout << (a*b < c*d ? c*d: a*b) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <list>

using namespace std;

typedef pair<int, int> edge;

struct Node {
	list<edge> neighbors;
	int pos;
	bool checked;
	bool visited;
};

Node x[100001];

int main(int argc, char *argv[]) {
	int N, M;
	cin >> N >> M;

	list<int> open;
	for (int i = 0; i < M; i++) {
		int L, R, D;
		cin >> L >> R >> D;
		x[L].neighbors.push_back(edge(R, D));
		x[R].neighbors.push_back(edge(L, -D));
		open.push_back(L);
	}

	while (!open.empty()) {
		int p = open.front(); open.pop_front();
		if (x[p].visited) continue;
		x[p].visited = true;
		if (!x[p].checked) {
			x[p].checked = true;
			x[p].pos = 0;
		}

		for (edge e : x[p].neighbors) {
			if (x[e.first].checked && x[e.first].pos != x[p].pos + e.second) {
				cout << "No" << endl;
				return 0;
			}
			x[e.first].pos = x[p].pos + e.second;
			x[e.first].checked = true;
			open.push_front(e.first);
		}
	}

	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 26880
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int min=1000, max=0;
        for(int i=0;i<3;i++){
        	int task=sc.nextInt();
        	if(min>task) min=task;
        	if(max<task) max=task;
        }
        System.out.println(max-min);
    }
}

Measured memory_bytes: 22228
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <set>
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
#define ms(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define mp make_pair
#define eps 0.0000000001
#define IOS ios::sync_with_stdio(0);cin.tie(0);
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;
const int maxn = 50000+10;
LL a[60];
int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
//        freopen("output.txt", "w", stdout);
#endif
//    IOS
    LL k;scanf("%lld", &k);
    if(k==0)    cout << "2\n1 1\n";
    else{
        int N = 50;
        LL t = (k-1)/N + 1;
        for(int i = 1;i<=N;i++) a[i] = i-1;
        for(int i = 1;i<=N;i++) a[i] += (t-1);
        int hh = k%N;
        if(hh==0){
            for(int i = 1;i<=N;i++) a[i]++;
        }
        for(int i = 1;i<=hh;i++){
            for(int j = 1;j<=N;j++){
                if(i==j)    a[i] += N;
                else    a[j]--;
            }
        }
        printf("%d\n", N);
        for(int i = 1;i<=N;i++)
            printf("%lld ", a[i]);
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
    ll n,x,sum,n2;
    sum=0;
    cin>>n;
    n2=n;
    for(int i=9;i>=0;i--){
      x=n2/pow(10,i);
      sum+=x;
      n2-=x*pow(10,i);
    }
    if(n%sum==0){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
class Node:
	def __init__(self, id):
		self.id = id
		self.parent_id = -1
		self.left = -1
		self.right = -1
		self.sibling = -1
		self.depth = -1
		self.height = -1
	def get_type(self):
		if self.parent_id == -1:
			return 'root'
		elif self.left == -1 and self.right == -1:
			return 'leaf'
		return 'internal node'
	def get_degree(self):
		ret = 0
		if self.left != -1: ret += 1
		if self.right != -1: ret += 1
		return ret
	def __str__(self):
		strNode = 'node ' + str(self.id) + ': '
		strNode += 'parent = ' + str(self.parent_id) + ', '
		strNode += 'sibling = ' + str(self.sibling) + ', '
		strNode += 'degree = ' + str(self.get_degree()) + ', '
		strNode += 'depth = ' + str(self.depth) + ', '
		strNode += 'height = ' + str(self.height) + ', '
		strNode += self.get_type()
		return strNode

def calc_depth(nodes):
	stack = []
	for i in range(len(nodes)):
		if nodes[i].parent_id == -1:
			nodes[i].depth = 0
			stack.append(nodes[i].id)
			break
	while len(stack) != 0:
		node = nodes[stack.pop()]
		if node.left != -1:
			nodes[node.left].depth = node.depth + 1
			stack.append(node.left)
		if node.right != -1:
			nodes[node.right].depth = node.depth + 1
			stack.append(node.right)

def calc_height(nodes):
	stack = []
	for i in range(len(nodes)):
		if nodes[i].left == -1 and nodes[i].right == -1:
			nodes[i].height = 0
			stack.append(nodes[i].id)
	while len(stack) != 0:
		node = nodes[stack.pop()]
		if node.parent_id != -1:
			parent = nodes[node.parent_id]
			parent.height = max(parent.height, node.height + 1)
			stack.append(node.parent_id)

n = int(input())
nodes = [Node(i) for i in range(n)]
for i in range(n):
	id, left, right = map(int, input().split())
	nodes[id].left = left
	nodes[id].right = right
	if left != -1:
		nodes[left].parent_id = id
		nodes[left].sibling = right
	if right != -1:
		nodes[right].parent_id = id
		nodes[right].sibling = left

calc_depth(nodes)
calc_height(nodes)

for i in range(n):
	print(nodes[i])



Measured memory_bytes: 5620
#include <iostream>
using namespace std;
int main(){
  int s;
  cin >> s;
  if(s == 0)cout << 0;
  if(s == 1 || s == 10 || s == 100)cout << 1;
  if(s == 11 || s == 110 || s == 101)cout << 2;
  if(s == 111)cout << 3;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <iomanip>
#include <vector>
#include <functional>
#include <algorithm>
#include <cstdio>
#include <random>
#include <ctime>
#include <cstdlib>
#include <unordered_map>
#include <string.h>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    string w;
    cin >> w;
    map<char, int> mp;
    rep(0, i, w.size())
    {
        mp[w.at(i)]++;
    }
    for (auto m : mp)
    {
        if (m.second % 2 != 0)
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    vector<int> A(N);

    for(int i = 0; i < N - 1; i++) {
        int a;
        cin >> a;
        A[a - 1]++;
    }

    for(int i = 0; i < N; i++) {
        cout << A[i] << endl;
    }
}

Measured memory_bytes: 3988
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

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

        int a = scanner.nextInt();
        int b = scanner.nextInt();
        if (a < b) {
            System.out.println("a < b");
        } else if (a > b) {
            System.out.println("a > b");
        } else {
            System.out.println("a == b");
        }
    }
}



Measured memory_bytes: 26264
s = 0
def concat(a, b):
    res = 0
    for i in range(len(a)):
        res += a[i] * b[i]
    return res
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
for _ in range(N):
    A = list(map(int, input().split()))
    s += concat(A, B) + C > 0
print(s)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr long long INF = 2147483647;
constexpr long long INFF = 92233720368547758;

long long Mapping1(long long ball,long long box){
    long long MOD = 998244353;
    long long A = 1;
    for(long long i = 0; i < ball;++i){
        A *= box;
        A %= MOD;
    }
    return A;
}

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    long long N;cin >> N;
    vector<long long> V(N),W;
    bool flag = 0;
    REP(i,N){
        cin >> V[i];W.pb(V[i]);
        if(V[0] != 0){
            cout << 0 << endl;
            return 0;
        }
        if(V[i] == 0 && flag == 0) flag = 1;
        else if(V[i] == 0 && flag == 1){
            cout << 0 << endl;
            return 0;
        }
    }
    sort ALL(V);sort ALL(W);W.pb(INF);
    V.erase(unique(V.begin(), V.end()), V.end());
    REP(i,V.size()){
        if(V[i] != i){
            cout << 0 << endl;
            return 0;
        }
    }
    long long ball = 0,ans = 1,box = -1;
    vector<long long> A;
    REP(i,N){
        auto low = lower_bound(W.begin(),W.end(),i);
        auto hi = upper_bound(W.begin(),W.end(),i);
        A.pb(hi - low);
    }
    REPP(i,1,A.size()){
        ans *= Mapping1(A[i],A[i-1]);
        ans %= 998244353;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3316
import sys
sys.setrecursionlimit(4100000)

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)


def resolve():
    N, D = [int(x) for x in sys.stdin.readline().split()]

    logger.debug('{} {}'.format(N, D))

    def ceil_int(a, devider):
        """
        floor は a // devider でいい。
        math.floor(a / divedier)　だとオーバーフローしちゃう。
        """

        if (a % devider > 0):
            a_ceil = a // devider + 1
        else:
            a_ceil = a // devider

        return a_ceil

    print(ceil_int(N, 2 * D + 1))


if __name__ == "__main__":
    resolve()

# AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す
# python -m unittest template/template.py で実行できる
# pypy3 -m unittest template/template.py で実行できる

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """6 2"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """14 3"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """20 4"""
        output = """3"""
        self.assertIO(input, output)

    def test_入力例_4(self):
        input = """1 1"""
        output = """1"""
        self.assertIO(input, output)


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

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

    string input;
    while (true) {
        int sum = 0;
        cin >> input;
        if (input == "0")
            break;
            
        for (int i = 0; i < input.size(); i++) {
            sum += input[i] - '0';
        }
        cout << sum << endl;
    }
}


Measured memory_bytes: 3204
k,n = map(int,input().split())
li = list(map(int,input().split()))

li_diff = []
for i in range(len(li) - 1):
    li_diff.append(li[i + 1] - li[i])
li_diff.append(k + li[0] - li[len(li) - 1])

ans = sum(li_diff) - max(li_diff)
print(ans)

Measured memory_bytes: 87244
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
ll gcd(ll a,ll b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

//最小公倍数
ll lcm(ll a,ll b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

// 素因数分解
vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

// 10進数から2進数
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}









int main() {
  ll n,d;
  cin >> n >> d;
  ll x ,y;
  long double dis[n];
  rep (i,n){
    cin >> x >> y;
    dis[i]=sqrt((x*x)+(y*y));
  }
  ll cnt=0;
  for (auto t : dis){
    //cout << t << endl;
    if(t <= d) cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 6728
#!/usr/bin/env python3
import sys


def solve(S_A: str, S_B: str, S_C: str):
    a_index = 0
    b_index = 0
    c_index = 0
    cur = 'a'
    while True:
        if cur == "a":
            if a_index < len(S_A):
                cur = S_A[a_index]
                a_index += 1
            else:
                print('A')
                return
        elif cur == "b":
            if b_index < len(S_B):
                cur = S_B[b_index]
                b_index += 1
            else:
                print('B')
                return
        elif cur == "c":
            if c_index < len(S_C):
                cur = S_C[c_index]
                c_index += 1
            else:
                print('C')
                return

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S_A = next(tokens)  # type: str
    S_B = next(tokens)  # type: str
    S_C = next(tokens)  # type: str
    solve(S_A, S_B, S_C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

#define INF 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

/* Union-Find-Tree */
/* 必ず要素数をコンストラクタに入れること */
template <class T = long long>
class Union_Find {
    using size_type = std::size_t;
    using _Tp = T;
public:

    vector<_Tp> par;
    vector<_Tp> rnk;

    // 親の根を返す。値の変更は認めない。
    const _Tp & operator[] (size_type child) {
        find(child);
        return par[child];
    }

    Union_Find (size_type n) {
        par.resize(n), rnk.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rnk[i] = 0;
        }
    }

    // 木の根を求める
    _Tp find(_Tp x) {
        if (par[x] == x)
            return x;
        else
            return par[x] = find(par[x]);
    }

    // xとyの属する集合を併合
    void merge(_Tp x, _Tp y) {
        x = find(x);
        y = find(y);
        if (x == y) return;

        if (rnk[x] < rnk[y]) {
            par[x] = y;
        } else {
            par[y] = x;
            if (rnk[x] == rnk[y]) rnk[x]++;
        }
    }

    // xとyが同じ集合に属するか否か
    bool same(_Tp x, _Tp y) {
        return find(x) == find(y);
    }
};

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

    int n, m;
    cin >> n >> m;

    vector<int> a(m), b(m), c(m);
    Union_Find<ll> uf(n);
    map<int, bool> mp;

    rep(i, m) {
        cin >> a[i] >> b[i] >> c[i];
        a[i] --, b[i] --;
        uf.merge(a[i], b[i]);
    }

    rep(i, n) {
        auto t = uf.find(i);
        mp[t] += 1;
    }

    cout << mp.size() << endl;
}

Measured memory_bytes: 7680
from collections import deque

N = int(input())
A = [int(n) for n in input().split()]

def calc(a, positive):
    curr = 0
    ans = 0
    while a:
        curr += a.popleft()
        if (positive and curr <= 0) or\
           ((not positive) and curr >= 0):
            ans += abs(curr) + 1
            curr = 1 if positive else -1
        positive = not positive
    return ans

def main():
    ans = min(calc(deque(A), True), calc(deque(A), False))
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 14580
#include <bits/stdc++.h>  // ver2.2.2
#define int long long
#define endl "\n"
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define VVi vector<Vi>
#define Vs vector<string>
#define Pii pair<int,int>
#define VPii vector<Pii>
#define Tiii tuple<int,int,int>
#define PQi priority_queue<int>
#define PQir priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define itos to_string
#define stoi stoll
#define FI first
#define SE second
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define sortr(v) sort(v,greater<>())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define dem(a,b) ((a+b-1)/(b))
#define Vin(a) rep(iI,0,a.size())cin>>a[iI]
#define Vout(a) rep(lZ,0,a.size()-1)cout<<a[lZ]<<' ';cout<<a.back()<<endl
#define VVout(a) rep(lY,0,a.size()){Vout(a[lY]);}
#define VPout(a) rep(lX,0,a.size())cout<<a[lX].FI<<' '<<a[lX].SE<<endl
#define INF 3000000000000000000  //  3.0*10^18(MAXの1/3くらい)
#define MAX LLONG_MAX
#define MOD 1000000007  //  10^9 + 7
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm
void uniq(Vi &v){sort(ALL(v)); v.erase(unique(ALL(v)),v.end());}  //  uniqのやつ

int mypow(int x, int n, int m){  //  累乗x^n(mod m)  O(log(n))
if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}



signed main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
  int n;
   cin >> n;
   vector<VPii> a(n,VPii(0));
   int qw,er,ty;
   
   rep(i,0,n-1){
     cin >> qw >> er >> ty;
     qw--,er--;
     a[qw].pb(mp(er,ty));
     a[er].pb(mp(qw,ty));
   }
   
  int Q,K;
  cin >> Q >> K;
  K--;
  
   Vi dis(n,-1);
   dis[K]=0;
   queue<int> next;
   next.push(K);
   
   while(!next.empty()){
     qw = next.front();
     next.pop();
     rep(i,0,a[qw].size()){
       if(dis[a[qw][i].FI]==-1){
         next.push(a[qw][i].FI);
         dis[a[qw][i].FI] = dis[qw]+a[qw][i].SE;
       }
     }
   }
  //Vout(dis);
  
  rep(i,0,Q){
    cin >> qw >> er;
    qw--,er--;
    cout << dis[qw]+dis[er] << endl;
  }
  return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define LL long long

template<const int MAX_V=100000,const int INF = 1000000000>
class Flow {
public:
  struct edge {int to,cap,rev;};

  std::vector<edge> G[MAX_V];
  bool used[MAX_V];

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

  int dfs(int v,int t,int f){
    if(v==t) return f;
    used[v]=true;
    for(int i=0;i<G[v].size();i++){
      edge &e = G[v][i];
      if(!used[e.to] && e.cap > 0){
	int d = dfs(e.to,t,min(f,e.cap));
	if(d>0){
	  e.cap -= d;
	  G[e.to][e.rev].cap += d;
	  return d;
	}
      }
    }
    return 0;
  }

  int max_flow(int s,int t){
    int flow = 0;
    while(true){
      memset(used,0,sizeof(used));
      int f = dfs(s,t,INF);
      if(f == 0)return flow;
      flow+=f;
    }
  }
};

int n,m;

int main(){
  int u,v,c;
  Flow<> g;
  cin>>n>>m;
  REP(i,m){
    cin>>u>>v>>c;
    g.add(u,v,c);
  }
  cout<<g.max_flow(0,n-1)<<endl;
  return 0;
}



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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  set<ll> s{1,2,3};
  ll a,b; cin >> a; cin >> b;
  s.erase(a); s.erase(b);
  cout << *s.begin() << endl;

  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.Scanner;
import java.lang.*;
import java.io.*;
import java.util.*;
import java.lang.Integer;
import java.util.HashMap;

class Main
{
    // driver function to test the above functions
    public static void main(String args[]) throws IOException
    {
        Reader.init(System.in);
        long n = Reader.nextLong();
        long a = Reader.nextLong();
        long b = Reader.nextLong();

        long tot=a+b;
        long ans=0;
        long base = n%tot;

        if (base>a){
            ans=ans+a;
        }

        else {
            ans=base;
        }

        long div = n/tot;
        ans=ans+(div*a);
        System.out.println(ans);


    }

}

class solu{

}

/** Class for buffered reading int and double values */
class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    /** call this method to initialize reader for InputStream */
    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }

    /** get next word */
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                    reader.readLine() );
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }

    static long nextLong() throws IOException {
        return Long.parseLong( next() );
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }
}

Measured memory_bytes: 22612
#include<iostream>
#include<algorithm>
#include<functional>
#include <string>
#include<cstdio>
#include<math.h>
#include<stack>
#include<queue>
#include<cstring>
#include<vector>
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define EREP(i,n) for(int i=(n-1);i>=0;--i)
#define D(n,retu) REP(i,n){cin>>retu[i];}
#define mod 1000000007
#define MIN -93193111451418101
#define INF 931931114518101
using namespace std;
typedef long long int ll;
template<typename T>
void fill_all(T& arr, const T& v) {
	arr = v;
}
template<typename T, typename ARR>
void fill_all(ARR& arr, const T& v) {
	for (auto& i : arr) { fill_all(i, v); }
}
#define MAX_NUM 50
long long comb[MAX_NUM + 1][MAX_NUM + 1];

static void calc_comb()
{
	for (uint32_t i = 0; i <= MAX_NUM; i++) {
		for (uint32_t j = 0; j <= i; j++) {
			if ((j == 0) || (i == j)) {
				comb[i][j] = 1;
			}
			else {
				comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
			}
		}
	}
}

//------------------変数-----------------------//
ll n, m, a, b;
typedef pair<ll, ll> P;
vector<vector<ll>> way(2001), money(2001);
ll maxa = 0, moto = 0;
ll v[11451] = {};
queue <ll>q;
ll bitmax = 0;
//-------------------関数----------------------//

int main() {
	cin >> n >> a >> b; double hoge = a;
	calc_comb();
	REP(i, n) {
		cin >> v[i];
	}
	sort(v, v + n);
	double heikin = 0;
	bool onaji = true;
	ll mae = v[n - 1];
	ll saigo = v[n - a];
	for (ll i = n - 1; i >= n - a; i--)
	{
		if (v[i] != mae) { onaji = false; }
		heikin += v[i];
	}
	heikin /= hoge;
	ll cnt = 0;
	ll goukei = 0;
	if (onaji == false) {
		ll wei = 0;
		REP(i, n) {
			if (v[i] == saigo) { cnt++; if (i > n - a - 1) { wei++; } }
		}
		printf("%0.7f\n", heikin);
		cout<<  comb[cnt][wei] << endl;
	}
	else {
		for (ll i = n - 1; i >= 0; i--)
		{
			if (v[i] == mae) { cnt++; }
		}
		for (int i = a; i <= b; i++)
		{
			goukei += comb[cnt][i];
		}
		printf("%0.7f\n", heikin);
		cout << goukei << endl;
	}
}

Measured memory_bytes: 384
#include<iostream>
#include<sstream>
#include<fstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
using namespace std;

int main(){
	bool mat[] = {1,0,0};
	string line;
	while(getline(cin,line)){
		bool tmp = mat[line[0]-65];
		mat[line[0]-65] = mat[line[2]-65];
		mat[line[2]-65] = tmp;
	}

	if(mat[0]){
		cout<<"A"<<endl;
	}else if(mat[1]){
		cout<<"B"<<endl;
	}else{
		cout<<"C"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1168
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<math.h>
#include<string>
#include <cctype>
#include <cstdlib>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1ll<<60;

using namespace std;
using ll = long long;
typedef pair<int, int> P;

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

    ll count=0;
    if(a<k){
        count += a;
        k = k - a; 
        if(b<k){
            k = k-b;
            if(k<0) {out(count);return 0;}
            else{
                count-=k;
                out(count);
                return 0;
            }
        }
        else {out(count); return 0;}
    }
    else out(k);
}

Measured memory_bytes: 3620
#include<stdio.h>
#include <math.h>
int main()
{
    int n,k,i,s=0,rem;
    scanf("%d %d",&n,&k);
    for(i=1;n>=0;i++)
    {
       rem=n%k;s++;
       n=n/k;
       if(n==0)
        break;

    }
    printf("%d",s);
}


Measured memory_bytes: 128
/*
* ID: juryc
* PROG: Double Factorial
* LANG: C++
*/

#include<bits/stdc++.h>
using namespace std;
int main(){
int64_t n; cin>>n;
if(n%2) cout<<0<<"\n";
else{
n/=2; 
int64_t g=5;
int64_t cnt=0;
while(n/g){
cnt=(cnt+n/g);
g*=5; 
}
cout<<cnt<<"\n"; 
}
return 0;
}

Measured memory_bytes: 3624
import numpy as np
N = int(input())
X = [int(i) for i in input().split()]
X = np.array(X)
res = 100**100
for i in range(max(X+1)):
    tmp = sum((abs(X-i))**2)
    #print(tmp)
    if res > tmp:
        res = tmp
print(res)

Measured memory_bytes: 12384
N=int(input())
A=list(map(int,input().split()))

a=A[0]
b=A[1]
gcd=1
for i in range(1,N):
  while 1:
    if a%b == 0:
      gcd=b
      break
    else:
      r = a%b
      a = b
      b = r
  a=gcd
  b=A[i]

print(gcd)

Measured memory_bytes: 14252
#include <iostream>
#include <string.h>

#define INC(i, a, b) for(int i = a; i < b; ++i)
#define DEC(i, a, b) for(int i = a; i > b; --i)
#define REP(i, n)    for(uint i = 0; i < n; ++i)

typedef unsigned int uint;
typedef unsigned long ul;
typedef long long  ll;
typedef unsigned long long ull;

using namespace std;

void TFprint(bool b, std::string T, std::string F){
    if(b){
        cout << T << endl;
    }else{
        cout << F << endl;
    }
}

int main(){
    char s[5];
    bool a = false, b = false, c = false;
    cin >> s;
    REP(i, 3){
        if(s[i] =='a'){
            a = true;
        }
        if(s[i] =='b'){
            b = true;
        }
        if(s[i] =='c'){
            c = true;
        }
    }
    TFprint(a && b && c, "Yes", "No");
    return 0;
}

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

int main(){
  char retu[10000];
  int i,j,k;
  int a,b;
  while(cin >> retu){
    i=0;
    j=1;
    k=2;
    a=0;
    b=0;
    while(1){
      if(retu[k] == '\0')break;
      if(retu[i] == 'J' && retu[j] == 'O' && retu[k] == 'I'){
	a++;
      }
      else if(retu[i] == 'I' && retu[j] == 'O' && retu[k] == 'I'){
	b++;
      }
      i++;
      j++;
      k++;
    }
    cout << a << endl << b << endl;
  }
}

Measured memory_bytes: 1148
N, K = map(int, input().split())
A = list(map(int, input().split()))

isMax = False
while K > 0 and not isMax:
    isMax = True
    B = [0] * N
    for i, d in enumerate(A):
        l = max(0, i - d)
        B[l] += 1
        r = i + d + 1
        if r < N:
            B[r] -= 1
    for i in range(N - 1):
        isMax &= (B[i] >= N)
        B[i + 1] += B[i]
    A = B
    K -= 1

print(*A[:N])


Measured memory_bytes: 152772
#include <bits/stdc++.h>
#define ll long long

using namespace std;

ll INF = 100000000000000;
ll dp[105][100005];
int N;

int main(){
    std::ios_base::sync_with_stdio(false); std::cin.tie(0);
    int W;
    cin >> N >> W;
    int total_value = 0;
    ll weight,value;
    for(int i= 0; i < 105; i++ ){
        for(int j=0 ; j < 100005; j++){
            dp[i][j] = INF;
        }
    }
    //cout << dp[1][30];
    for(int i=1; i <= N; i++){
        cin >> weight >> value;
        total_value += value;
        for(int j=1; j <= 100005; j++) dp[i][j] = dp[i-1][j]; //copy
        //cout << i << " " << value << " " << dp[i][value] << endl;
        dp[i][value] = min( dp[i][value], weight ); //cout << dp[i][value];
        for(int j=100005; j >=1; j-- ){
            if( j-value >= 1 && dp[i-1][j-value] != INF ) dp[i][j] = min( dp[i-1][j-value] + weight, dp[i][j] );

        }

    }
    int v = total_value;
    //cout << dp[1][30] << endl;
    while( true ){
        if( dp[N][v] <= W ) {/*cout << v << " " << dp[N][v] << endl;*/ break;}
        --v;
    }
    cout << v;
}


Measured memory_bytes: 82432
import sys
def t(A,p,r):
 x=A[r][1];i=p-1
 for j in range(p,r):
  if A[j][1]<=x:i+=1;A[i],A[j]=A[j],A[i]
 A[i+1],A[r]=A[r],A[i+1]
 return i+1
def k(A,p,r):
 if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)
def s(A):
 for i in range(n-1):
  if A[i][1]==A[i+1][1]:
   if A[i][2]>A[i+1][2]:return 0
 return 1
n=int(input())
f=lambda x,y:(x,int(y))
A=[(*f(*sys.stdin.readline().split()),i)for i in range(n)]
k(A,0,n-1)
print(['Not s','S'][s(A)]+'table')
for e in A:print(*e[:2])


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

int main() {
    // 制約見て！！！デカかったらlong longにすること！
    int a, b, c, x;
    cin >> a >> b >> c >> x;
    int ans = 0;
    rep(i, a + 1) rep(j, b + 1) rep(k, c + 1) if(500 * i + 100 * j + 50 * k == x) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 3588
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int d[] = new int[12];
		for(int i=0; i<12; i++){
			d[i] = sc.nextInt();
		}
		int sd1ary[] = {d[0], d[5], d[1], d[2], d[4], d[3]};
		int sd2ary[] = {d[6], d[7], d[8], d[9], d[10], d[11]};
		int sd3ary[][] = 
			   {{d[6], d[11], d[7], d[8], d[10], d[9]}, 
				{d[7], d[10], d[6], d[9], d[11], d[8]}, 
				{d[8], d[9], d[10], d[6], d[7], d[11]},  
				{d[9], d[8], d[10], d[11], d[7], d[6]},  
				{d[10], d[7], d[8], d[11], d[9], d[6]},  
				{d[11], d[6], d[9], d[10], d[8], d[7]}};
		int count = 0;
		int add = 0;
		
  out : for(int k=0; k<6; k++){
			if(sd1ary[0] == sd2ary[k]){
				for(int j=2; j<6; j++){
					count=0;
					if(sd1ary[2]==sd3ary[k][j]){
						for(int n=0; n<4; n++){
							add = j+n;
							if(add>5) add=add-4;

							if(sd1ary[n+2]==sd3ary[k][add]){
								count++;
								if(count==4)break out;
							}
						}
					}
				}
			}
		}
		if(count==4){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

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

#define INTINF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	ll ans = 0;
	ll tmp;
	ll x, y;
	cin >> x >> y;
	tmp = x;
	while(tmp<=y){
		ans ++;
		tmp *=2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int zorocount = 0;
        for (int i = 0; i < N; i++){
            int d1 = sc.nextInt();
            int d2 = sc.nextInt();
            if (d1 == d2){
                zorocount++;
            }else {
                zorocount = 0;
            }
            if (zorocount > 2){
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
    }
}


Measured memory_bytes: 36060
while True:
  N = int(raw_input())
  if N==0: break
  n = 2
  count = 0
  while n <= N:
    if n % 2 == 0:
      if N/n*n != N and N*2/n*n == N*2:
        if N/n >= n/2:
          count += 1
    else:
      if N/n*n == N:
        if N/n > n/2:
          count += 1
    n += 1
  print count

Measured memory_bytes: 6348
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, a, r = 0;
  cin >> n >> a;
 
  r = n % 500;
  
  if (r > a) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define all(x) (x).begin() , (x).end()
#define f first
#define s second
#define pr(x) cout<<x<<endl;
#define pr2(x,y) cout<<x<<" "<<y<<endl;
#define pr3(x,y,z) cout<<x<<" "<<y<<endl;
#define prv(v) for(auto x:v) cout<<x<<" ";
#define ffs fflush(stdout);
#define int ll
using namespace std;
 
const ll N =(1e5+5);
const ll MOD = 1e9+7;
const ll INF = LLONG_MAX;
const ll LOG = 29;
#define PI 3.141592653589793238 


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

void solve(){
    ll k,a,b;
    cin>>k>>a>>b;
    for(int i= a;i<=b;i++){
        if(i%k==0){
             cout<<"OK\n";
             return;
        }
    }
    cout<<"NG\n";
    
}   
 
 
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
     
    ll t=1;
    while(t--){
        solve();
    }    
}

Measured memory_bytes: 3652
#include <iostream>
#include<algorithm>
#include<string>
#include<vector>
#include <math.h>
#include <iomanip>

using namespace std;

int main()
{
	string s;
	cin >> s;
	s.replace(5, 1, " ");
	s.replace(13, 1, " ");
	cout << s << endl;
}

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

// double ended queueのこと

int main(void){
    deque<int> a;

    int q;
    cin >> q;

    for(int i=0; i<q; i++){
        int query_num;
        cin >> query_num;
        if(query_num==0){
            int d,x;
            cin >> d >> x;
            if(d==0) a.push_front(x);
            else a.push_back(x);
        }
        else if(query_num==1){
            int p;
            cin >> p;
            cout << a[p] << "\n";
        }
        else{
            int d;
            cin >> d;
            if(d==0) a.pop_front();
            else a.pop_back();
        }
    }

    return 0;
}


Measured memory_bytes: 4576
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


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


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


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    n = INT()
    s = input()

    lw = [0]*n
    le = [0]*n
    rw = [0]*n
    re = [0]*n

    for i in range(n-1):
        if s[i] == 'W':
            lw[i+1] = lw[i] + 1
            le[i+1] = le[i]
        else:
            lw[i+1] = lw[i]
            le[i+1] = le[i] + 1

    for i in range(n-1, 0, -1):
        if s[i] == 'W':
            rw[i-1] = rw[i] + 1
            re[i-1] = re[i]
        else:
            rw[i-1] = rw[i]
            re[i-1] = re[i] + 1

    ans = INF

    for i in range(n): 
        #print([lw[i], re[i]] , [le[i], rw[i]])

        ans = min(ans, lw[i]+re[i])

    print(ans)


if __name__ == '__main__':
    main()


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

int main()
{
    int n;
    scanf("%d",&n);
    long long sum = 0LL;
    vector <int> a(n);
    for(int&i : a)
        scanf("%d",&i) ,sum += i;

    if((2*sum)%(n*(n+1LL))){
        cout << "NO" << endl;
        return 0;
    }

    int ops = 2*sum/n/(n+1) ,st = a[0];
    for(int i=0; i<n; i++)
        a[i] = -a[i]+(i<n-1? a[i+1] : st);

    int tot_end = 0;
    for(int&i : a){
        if((i+(n-1LL)*ops)%n || (i+(n-1LL)*ops)>1LL*n*ops){
            cout << "NO" << endl;
            return 0;
        }
        tot_end += ops-(i+(n-1LL)*ops)/n;
    }

    cout << (tot_end==ops? "YES" : "NO") << endl;
}


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

vector<int> ct;
Graph g;

void dfs(int v, int p = -1) {
    for (int n_v: g[v]) {
        if (n_v == p) continue;
        ct[n_v] += ct[v];
        dfs(n_v,v);
    }
}

int main() {
    int n, q;
    cin >> n >> q;
    g.resize(n);
    ct.resize(n);
    rep(i,n-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    rep(i,q) {
        int p, x;
        cin >> p >> x;
        p--;
        ct[p] += x;
    }
    dfs(0);
    rep(i,n) cout << ct[i] << endl;
}

Measured memory_bytes: 23552
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>

using namespace std;
int main()
{
    /*
    cin>>x;
    cout<<x<<endl;
    */
    int n,m,i,j,ans,sum;
    string now="2019/04/30";
    string s;
    cin>>s;
    if(s.compare(now)>0)
        cout<<"TBD"<<endl;
    else
        cout<<"Heisei"<<endl;
    return 0;
}


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

int main() {
    int N;
    while (cin >> N) {
        vector<int> v(N);
        for (int i=0; i<N; ++i) cin >> v[i];
        sort(v.begin(), v.end());
        int score = v[0];
        for (int i=1; i<N; ++i) {
            v[i] += v[i-1];
            score += v[i];
        }
        cout << score << endl;
    }
    return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
//ranker
using namespace std;

#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using psi = pair<string, int>;
using D = double;


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

  int num;
  while(1){
    cin >> num;
    if(num == 0) break;

    int m = 2;
    int cnt = 0;
    double ch;
    while((num-m*(m-1)/2)>0){
      ch = (num-m*(m-1)/2)*1.0/m;
      if(ceil(ch)==floor(ch)) cnt++;
      m++;
    }
    cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 3032
/*author @dhanush*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define se second
#define fi first
ll MOD = 1e9 + 7;
ll solve(ll a1, ll a2, ll b1, ll b2)
{
  if (a2 >0 && b2 > 0)
  {
    return max(a2 * b2, a1 * b1);
  }
  if (a1 >= 0 && b2 <= 0)
  {
    return a1 * b2;
  }
  if (a2 <= 0 && b2 <= 0)
  {
    return a1 * b1;
  }
}
void  icchhipadey()
{
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll ans1 = solve(a, b, c, d);
  ll ans2 = solve(c, d, a, b);
  cout << max(ans1, ans2) << endl;

}
int main()
{


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

  boost;

  icchhipadey();




}









Measured memory_bytes: 3648
import itertools

N=int(input())
P=tuple(map(int,input().split()))
Q=tuple(map(int,input().split()))
X=[i for i in range(1,N+1)]


c = list(itertools.permutations(X,N))

a=0
b=0
for i in range(len(c)):
    if c[i]==P:
        a=i+1
    if c[i]==Q:
        b=i+1

print(abs(a-b))



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

using namespace std;

int main() {
    long N;
    cin >> N;
    vector<long> A(N+1);
    for (int i = 1; i <= N; ++i) {
        cin >> A[i]; 
    }
    long port = 0;
    long value = 1000;
    for (long i = 1; i <= N-1; ++i) {
        port = (long)(value / A[i]);
        long v = value + port * (A[i+1] - A[i]);
        value = max(value, v);
    }
    cout << value << endl;
    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    int n; cin >> n;
    int d; cin >> d;
    cout << (n-1)/(1+2*d) + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as B
import Data.Maybe

main = do
    [_, x] <- map read . words <$> getLine :: IO [Int]
    as <- map (fst . fromJust . B.readInt) . B.words <$> B.getLine :: IO [Int]
    print $ f x as

f x (y:y':ys) = let a = if y + y' > x then (y + y') - x else 0
                    b = max 0 (y' - a)
                in a + f x (b:ys)
f x [y] = max 0 $ y - x
f x []  = 0


Measured memory_bytes: 4092