akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
  public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}


void solve(long long N, long long D){
    cout << ceil(N,(2*D+1)) << endl;
        
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long D;
    scanf("%lld",&D);
    solve(N, D);
    return 0;
}


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

int N;
int A[(int)1e5 + 10];

int main() {
   scanf("%d", &N);
   for(int i = 0; i < N; i++) {
      scanf("%d", &A[i]);
   }
   int rs = 0, i = 0;
   while(i < N) {
      rs++;
      // cerr << "[" << i << " ";
      while(i+1 < N && A[i+1] == A[i]) i++;
      if(i+1 == N) break;
      if(A[i] < A[i+1]) {
         while(i+1 < N && A[i] <= A[i+1]) i++;
      } else {
         while(i+1 < N && A[i] >= A[i+1]) i++;
      }
      i++;
   }
   printf("%d\n", rs);
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;

signed main(){
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    while(A > 0 && C > 0){
        C -= B;
        if(C <= 0){
            PRINT("Yes");
            return 0;
        }
        A -= D;
        if(A <= 0){
            PRINT("No");
            return 0;
        }
    }
    return 0;
}

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

int main()
{
  string s;
  int q;
  int rev = 0;
  cin >> s >> q;
  deque<char> dq(s.begin(), s.end());
  for (int i = 0; i < q; i++)
  {
    int query;
    cin >> query;
    if (query == 1)
    {
      rev++;
      continue;
    }

    if (query == 2)
    {
      int f;
      char c;
      cin >> f >> c;
      if (rev % 2 != 0)
      {
        if (f == 2)
        {
          dq.push_front(c);
        }
        else if (f == 1)
        {
          dq.push_back(c);
        }
      }
      else
      {
        if (f == 1)
        {
          dq.push_front(c);
        }
        else if (f == 2)
        {
          dq.push_back(c);
        }
      }
    }
  }
  if (rev % 2 != 0)
  {
    for (auto itr = dq.rbegin(); itr != dq.rend(); itr++)
    {
      cout << *itr;
    }
    cout << endl;
    return 0;
  }
  for (auto itr = dq.begin(); itr != dq.end(); itr++)
  {
    cout << *itr;
  }
  cout << endl;
}


Measured memory_bytes: 4008
#coding: utf-8
x, y = map(int, input().split())

G1 = [1,3,5,7,8,10,12]
G2 = [4,6,9,11]

if (x in G1 and y in G1) or (x in G2 and y in G2):
    print("Yes")
else:
    print("No")

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

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

    int64_t ans = 0;
    rep(i,k){
        rep(j,k){
            rep(l,k){
                ans += __gcd(__gcd(i+1,j+1),l+1);
            }
        }
    }

    cout << ans;
}

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

int main() {
	int N, K; cin >> N >> K;
	int x[110];
	for(int i=0; i<N; ++i) cin >> x[i];
	int S=0;
	for(int i=0; i<N; ++i) S += 2*min(x[i], K-x[i]);
	cout << S << endl;
	return 0;
}


Measured memory_bytes: 256
from _collections import deque
from _ast import Num


def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number)


input_parser = parser()


def gw():
    global input_parser
    return next(input_parser)


def gi():
    data = gw()
    return int(data)


MOD = int(1e9 + 7)

import numpy
from collections import deque
from math import sqrt
from math import floor
import heapq
# https://atcoder.jp/contests/agc033/tasks/agc033_b
# B - LRUD Game
"""
"""
N = gi()
t = [[] for i in range(N + 5)]

for i in range(1, N):
    a = gi()
    b = gi()
    t[a].append(b)
    t[b].append(a)
cs = [0] * N
for i in range(N):
    cs[i] = gi()
cs.sort()
print(sum(cs) - max(cs))
vs = [0] * (N + 5)
ci = N - 1
q = deque()
q.append(1)

while len(q):
    v = q.pop()
    # print(v, ci)
    vs[v] = cs[ci]
    ci -= 1
    for u in t[v]:
        if vs[u]:
            continue
        else:
            q.append(u)
for i in range(1, N + 1):
    print("%d " % (vs[i]), end="")


Measured memory_bytes: 22152
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define ALL(a) (a).begin(), (a).end()

const ll mod = 1000000007;
const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
  for (T& x : vec)
    is >> x;  // for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}

int main() {
  ll n;
  cin >> n;
  vector<ll> v(n);
  cin >> v;

  ll ans = LLINF;
  ll sum = 0;
  ll sum2=0;
  for(auto x:v){
    sum+=x;
  }

  for (ll i = 0; i < n; i++){
    if (abs(sum - sum2) < ans){
      ans = abs(sum - sum2);
    }
    sum-=v[i];
    sum2+=v[i];
  }


  cout << ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ff              first
#define ss              second
#define int             long long int
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             (1<<17)
#define vv(type)		vector<vector<type>>
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define db(x) 			cout<<x<<" "
#define db1(x) 			cout<<x<<'\n'
#define db2(x,y) 		cout<<x<<" "<<y<<'\n'
#define db3(x,y,z) 		cout<<x<<" "<<y<<" "<<z<<'\n'
#define rep(i,n) 		for(int i=0;i<(n);++i)
#define repA(i,a,n) 	for(int i=a;i<=(n);++i)
#define repD(i,a,n) 	for(int i=a;i>=(n);--i)
#define so(a) 			sort(a.begin(),a.end())
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
// to find all local maximaa and minima in O(n)
//	 for (int i=1;i<=n;i++)
//        {
//            if (i==1 || i==n || (p[i-1]<p[i])!=(p[i]<p[i+1]))
//           ans.push_back(p[i]);
//        }

int dp1[100001], dp2[100001];
vi tree[100001];
void solve1(int src, bool vis[], int m)
{
	vis[src] = 1;
	dp1[src] = 1;
	for (int child : tree[src])
	{
		if (!vis[child])
		{
			solve1(child, vis, m);
			dp1[src] = (dp1[src] * (1 + dp1[child])) % m;
		}
	}
}
void solve2(int src, bool vis[], int m, int par_ans)
{
	vis[src] = 1;
	dp2[src] = ((1 + par_ans) * dp1[src]) % m;
	vi prefix, suffix;
	for (int child : tree[src])
	{
		if (!vis[child])
		{
			prefix.pb((int)1 + dp1[child]);
			suffix.pb((int)1 + dp1[child]);
		}
	}
	int size1 = prefix.size(), size2 = suffix.size();
	repD(i, size2 - 2, 0)
	{
		suffix[i] = (suffix[i + 1] * suffix[i]) % m;
	}
	repA(i, 1, size1 - 1)
	{
		prefix[i] = (prefix[i - 1] * prefix[i]) % m;
	}
	int cno = 0;
	for (int child : tree[src])
	{
		if (!vis[child])
		{
			int ways = (1 + par_ans) % m;
			ways = (cno > 0) ? (ways * prefix[cno - 1]) % m : ways % m;
			ways = (cno < (size2 - 1)) ? (ways * suffix[cno + 1]) % m : ways % m;
			solve2(child, vis, m, ways);
			cno++;
		}
	}
}
void solve()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, m, u, v;
	cin >> n >> m;
	rep(i, n - 1)
	{
		cin >> u >> v;
		tree[u].pb(v);
		tree[v].pb(u);
	}
	bool vis[n + 1];
	memset(vis, 0, sizeof(vis));
	solve1(1, vis, m);
	memset(vis, 0, sizeof(vis));
	solve2(1, vis, m, 0);
	repA(i, 1, n)
	db1(dp2[i]);
}
int32_t main()
{
	solve();
	return 0;
}


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

const int MAXN = 200005;
const int MAXM = 400015;

int n, xi, yi;
char di;

vector <int> a[6][MAXM], b[6][MAXM];
int calc(int ind, int x){
	sort(a[ind][x].begin(), a[ind][x].end());
	sort(b[ind][x].begin(), b[ind][x].end());
	
	int j = 0, res = -1;
	for(int i = 0; i < (int)b[ind][x].size(); i++){
		while(j < (int)a[ind][x].size() && a[ind][x][j] <= b[ind][x][i]){
			j++;
		}
		
		if(j > 0){
			int cur = 5 * (b[ind][x][i] - a[ind][x][j - 1]);
			if(res == -1 || cur < res)res = cur;
		}
	}
	return res;
}

int main(){
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		scanf("%d %d %c", &xi, &yi, &di);
		
		//(x + y, x - y)
		if(di == 'U'){//(1, -1)
			a[0][xi].push_back(yi);
			b[2][xi + yi].push_back(xi - yi);
			a[4][xi - yi + MAXN].push_back(xi + yi);
		}else if(di == 'R'){//(1, 1)
			a[1][yi].push_back(xi);
			a[2][xi + yi].push_back(xi - yi);
			a[5][xi - yi + MAXN].push_back(xi + yi);
		}else if(di == 'L'){//(-1, -1)
			b[1][yi].push_back(xi);
			b[3][xi + yi].push_back(xi - yi);
			b[4][xi - yi + MAXN].push_back(xi + yi);
		}else{//(-1, 1)
			b[0][xi].push_back(yi);
			a[3][xi + yi].push_back(xi - yi);
			b[5][xi - yi + MAXN].push_back(xi + yi);
		}
	}
	
	long long res = -1;
	for(int i = 0; i < 6; i++)
	for(int j = 0; j < MAXM; j++){
		long long cur = calc(i, j);
		if(cur != -1 && (res == -1 || cur < res))res = cur;
	}
	
	if(res == -1)printf("SAFE\n");
	else printf("%lld\n", res);
	
	return 0;
}


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

int main(){
   int m[4][4];
   for(int i=1;i<=3;i++){
       for(int j=1;j<=3;j++){
           cin >> m[i][j];
       }
   }
   //正しいと前提する
   //a1を決める
   int flag1=0;
   for(int a1=0;a1<=100;a1++){
       int b1=m[1][1]-a1;
       int b2=m[1][2]-a1;
       int b3=m[1][3]-a1;
       int a2=m[2][1]-b1;
       int a3=m[3][1]-b1;
       if(a2+b2==m[2][2] && a2+b3==m[2][3] && a3+b2==m[3][2] && a3+b3==m[3][3]) flag1=1;
   }
    cout << ((flag1==1)? "Yes":"No") << endl;
}


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

using namespace std;

#define ll long long
#define fix cout << fixed; cout << setprecision(0)





void solve() {

	ll n;
	ll k;
	cin >> n >> k;
	n = n % k;
	while(n > abs(n - k)) {
		n = abs(n - k);
	}
	cout << n << "\n";





	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	fix;
	solve();

	return 0;
}

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

int n, m;
vector<vector<int>> g(101000);
vector<int> deg(101000), depth(101000, -1);
vector<pair<int, int>> ans;

void dfs(int v, int p) {
    for (auto u : g[v]) {
        if (depth[u] == -1) {
            depth[u] = depth[v] + 1;
            dfs(u, v);
        } else if (depth[u] > depth[v]) {
            ans.emplace_back(v, u);
            deg[v]++;
        }
    }
    if (p != -1) {
        if (deg[v] % 2 == 1) {
            ans.emplace_back(v, p);
            deg[v]++;
        } else {
            ans.emplace_back(p, v);
            deg[p]++;
        }
    }
    return;
}

int main() {
    cin >> n >> m;
    if (m % 2) {
        cout << -1 << endl;
        return 0;
    }
    rep(i, 0, m) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        g[x].emplace_back(y);
        g[y].emplace_back(x);
    }
    depth[0] = 0;
    dfs(0, -1);

    for (auto p : ans) {
        cout << p.first + 1 << ' ' << p.second + 1 << endl;
    }
}

Measured memory_bytes: 14836
#include <iostream>
#include <vector>
#include <algorithm>
using std::cin;
using std::cout;
using std::make_pair;

long long int N,M;
typedef std::pair<long long ,long long> shop;
std::vector<shop> shops;
long long int ans;

int main(){
  cin >> N >> M;
  for(int i = 0;i<N;++i){
    int a,b;
    cin>> a >> b;
    shops.push_back(make_pair(a,b));
  }
  std::sort(shops.begin(),shops.end());
  for(int i = 0;i<N;++i){
    if(shops[i].second >= M){
      ans += shops[i].first * M;
      break;
    }else{
      ans += shops[i].first * shops[i].second;
      M -= shops[i].second;
    }
  }
 cout << ans << '\n';
 return 0; 
}


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

struct node{
	int key;
	node *parent,*left,*right;
	node():parent(nullptr),left(nullptr),right(nullptr){}
};

node* insert(node *root,int key){
	node *z=new node;
	z->key=key;
	node *x=root,*y=nullptr;
	while(x!=nullptr){
		y=x;
		if(z->key<x->key)x=x->left;
		else x=x->right;
	}
	if(y==nullptr)root=z;
	else if(z->key<y->key)y->left=z;
	else y->right=z;
	return root;
}

bool search(node *parent,int key){
	if(parent==nullptr)return false;
	if(parent->key==key)return true;
	if(key<parent->key){
		if(search(parent->left,key))return true;
	}else{
		if(search(parent->right,key))return true;
	}
	return false;
}

void find(node *root,int key){
	if(search(root,key))cout<<"yes\n"s;
	else cout<<"no\n"s;
}

void inorder(node *root){
	if(root==nullptr)return;
	inorder(root->left);
	cout<<" "s<<root->key;
	inorder(root->right);
}

void preorder(node *root){
	if(root==nullptr)return;
	cout<<" "s<<root->key;
	preorder(root->left);
	preorder(root->right);
}

void print(node *root){
	inorder(root);
	cout<<"\n"s;
	preorder(root);
	cout<<"\n"s;
}

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int m;
	cin>>m;
	string com;
	node *root=nullptr;
	for(int i=0,k;i<m;++i){
		cin>>com;
		if(com=="print"s)print(root);
		else{
			cin>>k;
			if(com=="find"s)find(root,k);
			else root=insert(root,k);
		}
	}
}


Measured memory_bytes: 21912
n = int(input())
list_i = input().split()
w = [int(s) for s in list_i]
min = sum(w)

for i in range(len(w)):
    if i == len(w)-1: 
        break
    if min > abs(sum(w[:i+1]) - sum(w[i+1:])):
        min = abs(sum(w[:i+1]) - sum(w[i+1:]))
print(min)

Measured memory_bytes: 3064
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

double solve(int k) {
    int A = 0, cp = k;
    for(; cp>0; cp/=10) {
        A += (cp % 10);
    }

    return 1.0 * k / A;
}

bool check(int k) {
    double A = solve(k);
    for(int i=k+1; i<500000; i++) {
        if(A > solve(i)) {
            if(k < 10) printf("k = %lld, i = %lld (%.12f > %.12f)\n", k, i, solve(k), solve(i));
            return false;
        }
    }
    return true;
}
 
signed main() {
    /*
    for(int i=1; i<500000; i++) {
        // if(i % 10 == 0) printf("\n");
        if(check(i)) {
            printf("i = %lld, %.12f\n", i, solve(i));
        }
    }
    */

    int K; cin >> K;
    int level = 0, base = 1, nines = 0;

    vector<int> elems;

    for(; level < 16; level++) {
        int lb = (level <= 2 ? 1 : level - 1);
        int ub = (level <= 1 ? 0 : level - 1) * 10 + 9;
        for(int i=lb; i<=ub; i++) {
            if(i == 0) continue;

            // if(K == 0) goto end_prog;
            // K--;

            int ans = i * base + nines;
            // cout << ans << endl;
            // cout << i;
            // cout << string(level, '9') << endl;

            // fprintf(stderr, "num = %15lld, solve = %.12f\n", ans, solve(ans));
            elems.push_back(ans);
        }
        base *= 10;
        nines = nines * 10 + 9;
    }

    end_prog:;

    vector<int> ans;
    int N = elems.size();
    for(int i=0; i<N; i++) {
        bool ok = true;
        for(int j=i+1; j<N; j++) {
            if(solve(elems[i]) > solve(elems[j])) {
                ok = false;
            }
        }
        if(ok) ans.push_back(elems[i]); //printf("valid: %16lld\n", elems[i]);
        else {
            // printf("invalid: %16lld\n", elems[i]);
        }
    }

    // cout << ans.size() << endl;

    for(int i=0; i<K; i++) {
        cout << ans[i] << 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);
        long N = sc.nextLong();
        long A = sc.nextLong();
        long B = sc.nextLong();

        if((B - A) % 2 == 0){
            System.out.println((B - A) / 2);
        }else if(N - A < B - 1){
            System.out.println((N - B + 1) + ((B - A - 1) / 2));
        }else{
            System.out.println(A + ((B - A - 1) / 2));
        }
    }
}


Measured memory_bytes: 21972
a,b,c,x,y = map(int,input().split())
if x>y:
    w1,w2 = (a+b)*y, c*2*y
    d1,d2 = a*(x-y), c*2*(x-y)
    print(min(w1+d1, w1+d2, w2+d1, w2+d2))
else:
    w1,w2 = (a+b)*x, c*2*x
    d1,d2 = b*(y-x), c*2*(y-x)
    print(min(w1+d1, w1+d2, w2+d1, w2+d2))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define int long long
int rv[30];
struct node{
  int id,left,right,par;
  node(){par=-1;}
};
node t[30];
void dfs(int v,int p){
  if(p==0){
    cout<<" "<<t[v].id;
    if(~t[v].left)  dfs(rv[t[v].left ],p);
    if(~t[v].right) dfs(rv[t[v].right],p);
  }
  if(p==1){
    if(~t[v].left)  dfs(rv[t[v].left ],p);
    cout<<" "<<t[v].id;
    if(~t[v].right) dfs(rv[t[v].right],p);
  }
  if(p==2){
    if(~t[v].left)  dfs(rv[t[v].left ],p);
    if(~t[v].right) dfs(rv[t[v].right],p);
    cout<<" "<<t[v].id;
  }
}
signed main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++) cin>>t[i].id>>t[i].left>>t[i].right;
  for(int i=0;i<n;i++) rv[t[i].id]=i;
  for(int i=0;i<n;i++){
    //cout<<t[i].id<<":"<<t[i].left<<":"<<t[i].right<<endl;
    if(~t[i].left)  t[rv[t[i].left ]].par=t[i].id;
    if(~t[i].right) t[rv[t[i].right]].par=t[i].id;
  }
  for(int i=0;i<n;i++){
    if(t[i].par==-1){
      cout<<"Preorder"<<endl;
      dfs(i,0);
      cout<<endl;
      cout<<"Inorder"<<endl;
      dfs(i,1);
      cout<<endl;
      cout<<"Postorder"<<endl;
      dfs(i,2);
      cout<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3080
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextLong()

  val mod = 1000000007

  def plus(a: Long, b: Long): Long = (a + b) % mod
  def times(a: Long, b: Long): Long = (a * b) % mod

  val dp = Array.fill(61, 3)(0L)
  dp(60)(0) = 1L

  for (i <- 59 to 0 by -1) {
    if (((n >> i) & 1) == 0) {
      dp(i)(0) = plus(dp(i+1)(0), dp(i+1)(1))
      dp(i)(1) = dp(i+1)(1)
      dp(i)(2) = plus(dp(i+1)(1), times(3, dp(i+1)(2)))
    } else {
      dp(i)(0) = dp(i+1)(0)
      dp(i)(1) = plus(dp(i+1)(0), dp(i+1)(1))
      dp(i)(2) = plus(times(2, dp(i+1)(1)), times(3, dp(i+1)(2)))
    }
  }
  println(dp(0).reduceLeft(plus))
}

Measured memory_bytes: 55500
#include <bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
int main() {
    ll n, d, a;
    cin >> n >> d >> a;
    vector<pair<ll, ll>> xh(n);
    rep(i, n) cin >> xh[i].first >> xh[i].second;
    sort(xh.begin(), xh.end());

    ll ans = 0, running_sum = 0;
    queue<pair<ll, ll>> bombs;
    rep(i, n) {
        while (!bombs.empty() && bombs.front().first < xh[i].first) {
            running_sum -= bombs.front().second * a;
            bombs.pop();
        }
        xh[i].second = max(0ll, xh[i].second - running_sum);
        if (xh[i].second <= 0) continue;

        ll cur_till = xh[i].first + 2 * d;
        ll cur_need = (xh[i].second + a - 1) / a;
        ans += cur_need;
        running_sum += cur_need * a;
        bombs.push({cur_till, cur_need});
    }
    cout << ans << endl;
    return 0;
}


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

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s = br.readLine();
        int f = s.indexOf("A");
        int e = s.lastIndexOf("Z");
        System.out.println(e - f + 1);
    }
}



Measured memory_bytes: 25044
object Main extends App {
  val sc = new java.util.Scanner(System.in) 
  val A, B, M = sc.nextInt()
  val a = Array.fill(A)(sc.nextInt())
  val b = Array.fill(B)(sc.nextInt())
  val m = Array.fill(M)(sc.nextInt(), sc.nextInt(), sc.nextInt())
    .map{ case (x, y, z) => a(x-1) + b(y-1) - z}.min
  var ans = (a.min + b.min).min(m)
  println(ans)
}


Measured memory_bytes: 67020
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    int a = readint;
    int b = readint;
    int c = readint;
    int x = readint;

    int ans = 0;
    for (int i = 0; i <= a; i++) { // 500
        for (int j = 0; j <= b; j++) { // 100
            for (int k = 0; k <= c; k++) { // 50
                int t = 500 * i + 100 * j + 50 * k;
                if (t == x) {
                    ans++;
                }
            }
        }
    }
    writeln(ans);
}


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

bool is_palindrome(string s){
    string t(s.rbegin(),s.rend());
    return s == t;
}

int main(){
    string s;
    cin>>s;
    int n=s.size();
    if(is_palindrome(s) && is_palindrome(s.substr(0,(n-1)/2)) && is_palindrome(s.substr((n+1)/2))){
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
}

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

using namespace std;

int main(void){
  long long H, N = 1;
  cin >> H;
  long long ans = 0;
  while(H > 0){
    ans += N;
    H /= 2;
    N <<= 1;
  }
  cout << ans << endl;
  return 0;
}


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

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i = 0; i < n; i++)
#define MAX 10000
#define NIL -1
typedef long long ll;
// Welcome to my source code!

struct Node { int p, l, r; };

Node T[MAX];

void preorder(int u) {
    if (u == NIL) return;
    cout << ' ' << u;
    preorder(T[u].l);
    preorder(T[u].r);
}

void inorder(int u) {
    if (u == NIL) return;
    inorder(T[u].l);
    cout << ' ' << u;
    inorder(T[u].r);
}

void postorder(int u) {
    if (u == NIL) return;
    postorder(T[u].l);
    postorder(T[u].r);
    cout << ' ' << u;
}


int main() {
    int n, id, l, r, root;
    cin >> n;
    REP(i,n) T[i].p = NIL;

    REP(i,n) {
        cin >> id >> l >> r;
        T[id].l = l;
        T[id].r = r;
        if (l != NIL) T[l].p = id;
        if (r != NIL) T[r].p = id; 
    }

    REP(i,n) if (T[i].p == NIL) root = i;

    cout << "Preorder\n";
    preorder(root);
    cout << "\nInorder\n";
    inorder(root);
    cout << "\nPostorder\n";
    postorder(root);
    cout << endl;
}


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

using namespace std;
using   ll=long long;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int             long long int
#define pll				pair<int , int>

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007
#define hell            998244353 

ll mod_pow(ll a,ll b,ll m) 
{
    ll res = 1;
    while(b)	
    {
        if(b&1) 	
        {
        	res=(res*a) % m;
        }
        a=(a*a) % m;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a) 
{
	return mod_pow(a , mod-2 , mod);
}
 
void solve()
{
	int n;
	
	cin >> n;
	
	int a[n];
	int b[n];
	
	int ans = 0;
	
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	
	for(int i = 0; i < n; ++i) {
		cin >> b[i];
	}
	
	for(int i = 0; i < n; ++i) {
		if(a[i] - b[i] > 0) {
			ans += a[i]-b[i];
		}
	}
	
	cout << ans;
}

signed main() {
    fast;
    
    int t = 1;
    
	//cin >> t;
    
    while(t--) {
        solve();
    }
 
    return 0;
}


Measured memory_bytes: 3532
package main

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

func main() {
	n, m := int64(ScanInt()), int64(ScanInt())
	r := int64(0)

	if n >= 2 {
		r += nCr(n, 2)
	}
	if m >= 2 {
		r += nCr(m, 2)
	}
	P(r)
}

func nCr(n, r int64) int64 {
	p, k := int64(1), int64(1)
	if n-r < r {
		r = n - r
	}

	if r != 0 {
		for r > 0 {
			p = (p * n) % (10e9 + 7)
			k = (k * r) % (10e9 + 7)

			m := GCD(p, k)
			p /= m
			k /= m

			n--
			r--
		}

	} else {
		p = 1
	}

	return p
}

/*********************** I/O ***********************/

var in *bufio.Scanner
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func MnMx(args ...int) (int, int) {
	minVal, maxVal := int(math.MaxInt32), int(math.MinInt32)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int) int { mn, _ := MnMx(args...); return mn }
func Mx(args ...int) int { _, mx := MnMx(args...); return mx }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}


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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descsort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int main(void)
{
    string n1,n2,n3,n4;
    cin>>n1>>n2>>n3>>n4;
    string s=n1+n2+n3+n4;
    if(count(s.begin(),s.end(),'1')==1 &&
        count(s.begin(),s.end(),'9')==1 && 
        count(s.begin(),s.end(),'7')==1 &&
        count(s.begin(),s.end(),'4')==1) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0; i<x; i++)
#define repn(i,x) for(int i=1; i<=x; i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int main() {
    int data;
    cin >> data;
    int up = data / 100;
    int down = data % 100;
    bool yymm = 1 <= down && down <= 12;
    bool mmyy = 1 <= up && up <= 12;
    if (yymm && mmyy)
        puts("AMBIGUOUS");
    else if (yymm)
        puts("YYMM");
    else if (mmyy)
        puts("MMYY");
    else
        puts("NA");
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);
#define ppp(a) (cout << (a) << endl);
#define cop(a) for(auto x:(a)){cout << x << endl;}


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powmod(ll b, ll e){ll r=1;while(e>0){if(e&1)r=(r%MOD)*(b%MOD)%MOD;b=(b%MOD)*(b%MOD)%MOD;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        // comment this out when you use scanf or printf
        // cin.tie(0); ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(15);
    };
}fastio;

vector<vector<int> > G;
vector<ll> counter;
void rec(int i, int prev){
    for(int v : G[i]){
        if(prev == v) continue;
        counter[v] += counter[i];
        rec(v, i);
    }
}


int main(){

    int n, q;
    cin >> n >> q;
    G.resize(n);
    counter.resize(n, 0);
    rep(i, n-1){
        int a, b;
        cin >> a >> b;
        --a; --b;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }
    rep(i, q){
        ll p, x;
        cin >> p >> x;
        --p;
        counter[p] += x;
    }
    rec(0, -1);
    rep(i, n){
        cout << counter[i] << sp;
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 24320
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  priority_queue<int> q;
  for(int i=0; i<n; i++){
    int a;
    cin >> a;
    q.push(a);
  }
  for(int i=0; i<m; i++){
    // return max value
    int a = q.top();
    q.pop();
    a/=2;
    q.push(a);
  }
  long long ans = 0;
  while(q.size()!=0){
    long long a = q.top();
    q.pop();
    ans += (long long)a;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
ll A, B, C, D;
/* function */
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x;}
ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}
ll f (ll x) {
    ll ret = B / x - (A-1) / x;
    return ret;
}
/* main */
int main(){
    cin >> A >> B >> C >> D;
    ll divCorD = f(C) + f(D) - f(lcm(C, D));
    cout << (B - A + 1) - divCorD << '\n';
}


Measured memory_bytes: 3628
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String ret = "";
        if (s.length() == 2) ret = s;
        else for (int i = 2; i >= 0; i--) ret += s.charAt(i);
        System.out.println(ret);
    }
}

Measured memory_bytes: 21844
#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#define meow(args...) fprintf(stderr, args)
#define GG exit(puts("-1")&0)
const int N=2e5;
int n, a[N], b[N], val[1<<18], cho[1<<19], off;
int choose(int x, int y) {return val[x]>val[y]?x:y;}
void update(int x, int v) {
	val[x]=v;
	for(x|=off; x>>=1; ) cho[x]=choose(cho[x<<1], cho[x<<1|1]);
}
int main() {
	assert(scanf("%d", &n)==1);
	for(int i=0; i<n; ++i) assert(scanf("%d", a+i)==1);
	for(int i=0; i<n; ++i) assert(scanf("%d", b+i)==1);
	for(off=1; off<n; off<<=1);
	for(int i=0; i<off; ++i) {
		val[i]=i<n?b[i]:-1;
		cho[i+off]=i;
	}
	for(int i=off; --i; ) cho[i]=choose(cho[i<<1], cho[i<<1|1]);
	long long ans=0;
	while(true) {
		int x=cho[1];
		if(val[x]==-1) break;
		if(b[x]<a[x]) GG;
		int l=b[(x+n-1)%n], r=b[(x+1)%n], s=l+r;
		if(a[x]>=s) {
			if(a[x]%s!=b[x]%s) GG;
			ans+=(b[x]-a[x])/s;
			b[x]=a[x];
			update(x, -1);
		} else {
			ans+=b[x]/s;
			b[x]%=s;
			if(b[x]==a[x]) {
				update(x, -1);
				continue;
			}
			if(b[x]<a[x]||(b[x]>l&&b[x]>r)) GG;
			update(x, b[x]);
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 4736
#include <iostream>
#include <cstdio>
#include <set>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <fstream>
#include <iomanip>
//#include <unordered_map>
using namespace std;
#define dbg(x) cerr << #x " = " << x << endl;
typedef pair<int, int> P;
typedef long long ll;
const int MAXN = 2e5 + 5;
int a[MAXN];
int sum[MAXN];
const int mod = 2019;
int poww(int a, int b)
{
    int ans = 1, base = a;
    while(b)
    {
        if(b & 1)
        {
            ans = ans * base % mod;
        }
        base = base * base % mod;
        b >>= 1;
    }
    return ans % mod;
}
int main()
{
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string op;
    cin >> op;
    int n = op.size();
    for(int i = 0; i < op.size(); i++)
    {
        a[i + 1] = op[i] - '0';
    }
    for(int i = n; i >= 1; i--)
    {
        if(i == n)
        {
            sum[i] = a[i];
        }
        else
        {
            sum[i] = poww(10, n - i) * a[i] + sum[i+1];
            sum[i] %= 2019;
        }
        
    }
    map<int, int> m;
    int ans = 0;
    for(int i = n; i >= 1; i--)
    {
        ans += m[sum[i]];
        m[sum[i]]++;
    }
    ans += m[0];
    cout << ans << endl;

}

Measured memory_bytes: 4716
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        double x_p1 = scan.nextDouble();
        double y_p1 = scan.nextDouble();
        double x_p2 = scan.nextDouble();
        double y_p2 = scan.nextDouble();
        
        double vx = x_p2 - x_p1;
        double vy = y_p2 - y_p1;
        
        int q = scan.nextInt();
        double l = norm(x_p1, y_p1, x_p2, y_p2);
        
        for(int i = 0; i < q; i++) {
            double x = scan.nextDouble();
            double y = scan.nextDouble();
            double ux = x - x_p1;
            double uy = y - y_p1;
            
            double t = dot(ux, uy, vx, vy);
            
            double k = t / l;
            double ax = k * vx + x_p1;
            double ay = k * vy + y_p1;
            
            double bx = 2 * ax - x;
            double by = 2 * ay - y;
            System.out.println(bx + " " + by);
        }
        scan.close();
    }
    
    static double dot(double x1, double y1, double x2, double y2) {
        return x1 * x2 + y1 * y2;
    }
    
    static double norm(double x1, double y1, double x2, double y2) {
        return (x1 - x2) * (x1 - x2) + (y1 -y2) * (y1 - y2);
    }
}


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

int main() {
  vector<int> a(3);
  cin >> a.at(0) >> a.at(1) >> a.at(2);
  
  sort(a.begin(), a.end());
  
  cout << a.at(2)*10+a.at(0)+a.at(1) << endl;
}

Measured memory_bytes: 256
import sys
def inpl(): return [int(i) for i in input().split()]

mod = 10**9+7
N, M = inpl()
A = [0] + sorted(inpl())
B = [0] + sorted(inpl())
row, column = 0, 0
ans = 1
for i in range(N*M,0,-1):
    if A[-1] == i:
        if B[-1] == i:
            row += 1 
            column += 1
            A.pop()
            B.pop()
        else:
            ans = ans * column % mod
            row += 1
            A.pop()
    else:
        if B[-1] == i:
            ans = ans * row % mod
            column += 1
            B.pop()
        else:
            ans = ans * (column * row - N*M + i) % mod
print(ans)


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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> s(m);
    vector<int> c(m);
    rep(i, m) cin >> s[i] >> c[i];
    bool flag1 = false;
    for (int i = 0; i < m-1; i++) {
        rep(j, m) {
            if (i != j && s[i] == s[j] && c[i] != c[j]) flag1 = true;
        }
    }
    rep(i, m) {
        if ((s[i] == 1 && c[i] == 0 && n != 1) || (s[i] > n)) flag1 = true;
    }
    if (flag1) {
        cout << -1 << endl;
    }else {
        vector<int> x(n, 0);
        rep(i, m) x[s[i] - 1] = c[i] * pow(10, n-s[i]);
        if (n == 3 && x[0] == 0) x[0] = 100;
        if (n == 2 && x[0] == 0) x[0] = 10;
        int ans = 0;
        rep(i, n) {
            // ans += x[i] * pow(10, n-(1+i));
            // cout << x[i] * pow(10, n-(1+i)) << endl;
            ans += x[i];
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double lld;
ll MOD = (1e9)+7;
const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int kx[] = {+1, +2, -1, -2, +1, +2, -1, -2};
const int ky[] = {+2, +1, +2, +1, -2, -1, -2, -1};
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
inline void fastIO(){
  ios_base::sync_with_stdio(0);cin.tie(0);
}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif

int main(){
  fastIO();
  ll s;
  cin>>s;
  vector<ll>partitions(2020);
  vector<ll>coins;
  for(int i=3;i<2020;i++){
    coins.push_back(i);
    partitions[i]=1;
  }
  for(int i=3;i<=s;i++){
    for(int j=3;j<=2000;j++){
      if(i>=j){
        partitions[i]+=partitions[i-j];
        partitions[i]%=MOD;
      }
    }
  }
  cout<<partitions[s]%MOD<<endl;
  return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define i64 long long
#define N (int)(1e5)
#define pii pair<int,int>
#define L first 
#define R second
#define all(x) x.begin(),x.end()
using namespace std;
string grid[52];
int dx[] = {1,-1,0,0,1,1,-1,-1};
int dy[] = {0,0,1,-1,1,-1,1,-1};
int R,C;

bool valid(int i, int j){
	return ((i>=0 and i<R) and (j>=0 and j<C)); 
}
int main() {
	// your code goes here
	cin>>R>>C; getchar();
	for(int i=0;i<R;i++) cin>>grid[i];
	char ans[R+1][C+1]; //data type is char because count will be <=8 , a sigle digit
	int cnt,nx,ny;
	for(int i=0;i<R;i++){
		for(int j=0;j<C;j++){
			if(grid[i][j]=='#') {
				//ans[i][j] = '#';
				printf("#");
				continue;
			}
			cnt = 0;
			for(int k=0;k<8;k++){
				nx = i+dx[k], ny = j+dy[k];
				if(valid(nx,ny) and grid[nx][ny]=='#') cnt++;
			}
			//ans+=cnt;
			//ans[i][j] = (cnt+'0');
			printf("%d",cnt);
		}
		printf("\n");
	}
	printf("\n");
	
	/*for(int i=0;i<R;i++){
		for(int j=0;j<C;j++) printf("%c",ans[i][j]);
	}
	printf("\n");*/
	
	return 0;
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define maxs(a,b) a=max(a,b)
#define mins(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

int main(){

    int a,b;cin>>a>>b;

    if(b<a)swap(a,b);
    if(a==1 && b==2)cout<<3<<"\n";
    else if(a==1 && b==3)cout<<2<<"\n";
    else cout<<1<<"\n";

}

Measured memory_bytes: 256
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W, x, y, z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

char mp[1000][1000];
ll val[1000][1000];

int main() {
	cin >> H >> W >> N;
	Pa start_p;
	rep(i, H) {
		rep(j, W) {
			cin >> mp[i][j];
			if (mp[i][j] == 'S') start_p = Pa(i, j);
		}
	}
	int dx[4] = { 0, 1, 0, -1 }, dy[4] = { 1, 0, -1, 0 };
	int ans = 0;
	rep(i, N) {
		queue<Pa> que;
		que.push(start_p);
		rep(y, H) {
			rep(x, W) {
				val[y][x] = MAX;
			}
		}
		val[start_p.first][start_p.second] = 0;
		while (!que.empty()) {
			Pa curr = que.front(); que.pop();
			int x = curr.second, y = curr.first;
			char c = '1' + i;
			if (mp[y][x] == (char)('1' + i)) {
				start_p = Pa(y, x);
				ans += val[y][x];
				break;
			}
			rep(j, 4) {
				int next_x = x + dx[j], next_y = y + dy[j];
				if (0 <= next_x && next_x < W && 0 <= next_y && next_y < H && mp[next_y][next_x] != 'X' && val[y][x] + 1 < val[next_y][next_x]) {
					que.push(Pa(next_y, next_x));
					val[next_y][next_x] = val[y][x] + 1;
				}
			}
		}
	}
	cout << ans << endl;
        return 0;
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int A,B,C;
  cin>>A>>B>>C;
  cout<<B+min(A+B+1,C)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
const long long MOD = 1000000007;
int main() {
    int n, m;
    cin >> n >> m;
    long x[100000];
    long y[100000];
    for (int i = 0; i < n; ++i) {
        cin >> x[i];
    }
    for (int i = 0; i < m; ++i) {
        cin >> y[i];
    }
    int lenW = n - 1;
    int lenH = m - 1;
    unsigned long w[99999];
    unsigned long h[99999];
    for (int i = 0; i < lenW; ++i) {
        w[i] = x[i + 1] - x[i];
    }
    for (int i = 0; i < lenH; ++i) {
        h[i] = y[i + 1] - y[i];
    }

    unsigned long totalW = 0, totalH = 0;
    for (int i = 0; i < lenW; ++i) {
        int tmpi = i + 1;
        if (lenW / 2 + lenW % 2 < tmpi) {
            tmpi = (lenW + 1 - tmpi);
        }
        totalW += w[i] * (tmpi) * (lenW - (tmpi - 1));
    }
    for (int i = 0; i < lenH; ++i) {
        int tmpi = i + 1;
        if (lenH / 2 + lenH % 2 < tmpi) {
            tmpi = (lenH + 1 - tmpi);
        }
        totalH += h[i] * (tmpi) * (lenH - (tmpi - 1));
    }
    unsigned long amariH = (totalH % (MOD));
    unsigned long amariW = (totalW % (MOD));
    cout << (amariH * amariW) % (MOD) << endl;
    return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)    FOR (i,0,n)
#define ALL(f,x,...) ([&](decltype((x)) ALL) {                          \
            return (f)(begin(ALL), end(ALL), ## __VA_ARGS__); })(x)

using namespace std;

vector<int> X;

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

    X.resize(3);
    X[0] = A;
    X[1] = B;
    X[2] = C;

    int mx = 0;
    int ix = 0;
    if (B <= A && C <= A)
    {
        ix = 0;
        mx = A;
    }
    else if (A <= B && C <= B)
    {
        ix = 1;
        mx = B;
    }
    else
    {
        ix = 2;
        mx = C;
    }

    int cnt = 0;
    while(true)
    {
        int fix = 0;
        int six = 0;
        int fdif = -1;
        int sdif = -1;
        REP(i, 3)
        {
            if (i == ix) continue;
            if (fdif < 0)
            {
                fix = i;
                fdif = mx - X[i];
            }
            else if (sdif < 0)
            {
                six = i;
                sdif = mx - X[i];
            }
        }

        if (fdif == 0 && sdif == 0)
        {
            break;
        }
        else if (0 < fdif && 0 < sdif)
        {
            X[fix]++;
            X[six]++;
            cnt++;
        }
        else if (fdif == 0 && 2 <= sdif)
        {
            X[six]++;
            X[six]++;
            cnt++;
        }
        else if (sdif == 0 && 2 <= fdif)
        {
            X[fix]++;
            X[fix]++;
            cnt++;
        }
        else if (fdif == 0 && sdif == 1)
        {
            cnt++;
            cnt++;
            break;
        }
        else if (sdif == 0 && fdif == 1)
        {
            cnt++;
            cnt++;
            break;
        }
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256