akhauriyash/Code-Regression huggingface dataset:
import sys
import numpy as np
import random
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache

sys.setrecursionlimit(10**9)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007

def main():
	s = S()
	total = int(s)
	s_list = [s[:i+1] + '+' + s[i+1:] for i in range(len(s)-1)]
	while s_list:
		new_s_list = []
		for s_tmp in s_list:
			total += eval(s_tmp)
			plus = s_tmp.rfind('+')
			if plus < len(s_tmp)-2:
				new_s_list += [s_tmp[:plus+i+2] + '+' + s_tmp[plus+i+2:] for i in range(len(s_tmp)-plus-2)]
		s_list = new_s_list.copy()
	print(total)


if __name__ == '__main__':
    main()

Measured memory_bytes: 14688
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<bitset>
#include<bits/stdc++.h>

#define ll long long int
#define N 1000000
using namespace std;

main()
{
char c;
cin>>c;
if(c>='A' && c<='Z')
	cout<<"A"<<endl;
else
	cout<<'a'<<endl;	
}

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

int main(){
    int x,y;
    cin>>x>>y;
    for(int i=0;i<x;i++){
       if(4*x-2*i==y){
           cout<<"Yes"<<endl;
           return 0;
       }
       if(2*i+2*x==y){
           cout<<"Yes"<<endl;
           return 0;
       }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3632
#include <cstdio>

int main()
{
	int k;
	scanf("%d", &k);
	
	int ans;
	ans = k / 2;
	
	if (k % 2 == 0)
		ans = ans * (k / 2);
	else
		ans = ans * (k / 2 + 1);
		
	printf("%d\n", ans);
	
	return 0;
}

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

int main() {
  long a, b;
  int ans = 0;
  b = 100;
  cin >> a;
  for(int i = 0; a > b; i++) {
    b += b * 0.01;
    ans++;
   }
  cout << ans << endl;
}


Measured memory_bytes: 3624
//cara pikir 
//pake recursive tapi gak 3 x
// C++ program for implementation of Ford Fulkerson algorithm 
#include <iostream> 
#include <limits.h> 
#include <string.h> 
#include <queue> 
#include <iostream> 
#include <set> 
#include <iterator> 
#include <algorithm>
#include <map>
typedef long long int ll;
using namespace std; 
long long int n[100];
ll lucas(ll l0,ll l1,int str,ll targt){
  
  n[str]=n[str-2]+n[str-1];
  if(str>targt)
  return n[targt];

  lucas(l0,l1,str+1,targt);

}

int main(){
int64_t lo=2;
int64_t l1=1;
n[0]=2;
n[1]=1;
int target=0;
cin>>target;
ll y=lucas(lo,l1,2,target);
cout<<y;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iterator>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <string>
#include <vector>
#include <limits>
#include <queue>
#include <cmath>
#include <map>
#include <set>

using namespace std;

using ll = unsigned long long;

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

    map<string, ll> cnt;

    ll out = 0;
    for(int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        sort(s.begin(), s.end());

        out += cnt[s];
        ++cnt[s];
    }

    cout << out << endl;

    return 0;
}


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


int main()
{
	auto& in = cin;

	int N;
	in >> N;
	vector<long long> As(N);
	for (int i = 0; i < N; ++i) {
		in >> As[i];
	}
	sort(As.begin(), As.end());
	deque<long long> confs;
	confs.push_back(As.back());
	As.pop_back();
	long long sum = 0;
	for (auto it = As.rbegin(); it != As.rend(); ++it) {
		sum += confs.front();
		confs.pop_front();
		confs.push_back(*it);
		confs.push_back(*it);
	}
	cout << sum;

	return 0;
}


Measured memory_bytes: 6424
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define MOD 1000000007
#define ALL(obj) (obj).begin(),(obj).end()
template<class T>inline bool chmax(T& a,T b){if (a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if (a>b){a=b;return 1;}return 0;}
const long long INF = 1LL << 60;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

ll x[1010000];
ll fib(ll b){
    if (b==1)return 0;
    if (b==2)return 0;
    if (b==3)return 1;
    if (x[b]!=-1)return x[b];
    x[b]=(fib(b-1)+fib(b-2)+fib(b-3))%10007;
    return x[b];
}

int main() {
    ll n;
    cin >> n;
    ll a[n];
    for (ll i=0;i<n;i++)cin >> a[i];
    sort(a,a+n);
    ll ans=1,c=0;
    for (ll i=1;i<n;i++){
        if (a[i-1]!=a[i])ans++;
        else{
            c++;
        }
    }
    if (c%2)ans--;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4388
def main():
    N, K, Q = map(int, input().split())
    point = [K - Q for _ in range(N)]

    for i in range(Q):
        p = int(input()) - 1
        point[p] += 1

    for i in range(N):
        if point[i] > 0:
            print('Yes')
        else:
            print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 51016
#include <utility>
#include <iostream>
#include <cmath>
#include <cstdio>

// ax + by = e1
// cx + dy = e2
auto solve (double a , double b , double c , double d , double e1 , double e2) -> std::pair <double , double>
{
    auto delta = a * d - b * c;
    auto x = (d * e1 - b * e2) / delta;
    auto y = (a * e2 - c * e1) / delta;
    return std::make_pair (std::move (x) , std::move (y));
}

auto distance (const std::pair <double , double> & a , const std::pair <double , double> & b) -> double
{
    auto dx = a.first  - b.first;
    auto dy = a.second - b.second;
    return std::sqrt (dx * dx + dy * dy);
}

auto show (double v) -> std::string
{
    if (-0.0005 < v && v < 0.0005)
    {
        return "0.000";
    }
    char s [100];
    std::sprintf (s , "%.3f" , v);
    return s;
}

auto main () -> int
{
    int n;
    std::cin >> n;
    for (auto i = 0; i < n; ++ i)
    {
        double x1 , y1 , x2 , y2 , x3 , y3;
        std::cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
        auto b1 = (y2 - y1) * (y1 + y2) / 2 + (x2 - x1) * (x1 + x2) / 2;
        auto b2 = (y3 - y1) * (y1 + y3) / 2 + (x3 - x1) * (x1 + x3) / 2;
        auto p = solve ((x2 - x1) , (y2 - y1) , (x3 - x1) , (y3 - y1) , b1 , b2);
        auto r = distance (p , std::make_pair (x1 , y1));
        std::cout << show (p.first) << ' ' << show (p.second) << ' ' << show (r) << std::endl;
    }
}

Measured memory_bytes: 3248
#include <iostream>
using namespace std;
#define rep(i,s,n)for(int i=s;i<n;i++)
typedef long long  ll;

int main()
{
	ll a, b; cin >> a >> b;
	ll cnt = 0;
	rep(i, a, b + 1)
		if (i / 10000 == i % 10 &&
			((i / 1000) % 10) == ((i / 10) % 10)) cnt++;

	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();

    if (a*b % 2 == 0) {
      System.out.println("Even");
    } else {
      System.out.println("Odd");
    }
  }

}


Measured memory_bytes: 23636
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

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

__attribute__((constructor))
void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main() {
    int S, W;
    cin >> S >> W;
    if (W >= S) {
        cout << "unsafe" << endl;
    } else {
        cout << "safe" << endl;
    }
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long n,m,q,r=0;cin >> n >> m >> q;
  vector<long long> x(n,1);
  vector<long long> a(q),b(q),c(q),d(q);
  for (int i=0;i<q;i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  long long a3=0;
	for (int j=0;j<q;j++) {
	  if (x[b[j]-1]-x[a[j]-1]==c[j]) a3+=d[j];
	}
  r=max(r,a3);
  while (x[0]!=m) {
    long long z=0;
    for (int j=n-1;j>=0;j--) {
	  if (x[j]<m && z==0) {
	  x[j]++;
	  for (int i2=j+1;i2<n;i2++) x[i2]=x[j];
	  z++;
	  }
	}
    long long a2=0;
	for (int j=0;j<q;j++) {
	  if (x[b[j]-1]-x[a[j]-1]==c[j]) a2+=d[j];
	}
	r=max(r,a2);
  }
  cout << r << endl;
}

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

int main() {
  int A;
  int B;
  string S;
  string T;
  string U;
  cin >> S >> T >> A >> B >>U;
  
  if(S == U){
    A--;
  }else{
    B--;
  }
  cout << A << " " << B <<endl;
}


Measured memory_bytes: 256
#include<map>
#include<list>
#include<cmath>
#include<stack>
#include<string>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;

int A[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int cunt = 0;

void depth(int n, int s, int i){
	
	if (n == 0 && s == 0){
		cunt++;
		return;
	}
	else if (n == 0) return;
	else if (s < 0) return;
	else if (i == 10) return;


	depth(n - 1, s - A[i],i+1);
	depth(n, s, i+1);

}

int main(){
	int n, s;
	while (cin >> n >> s){
		if (n == 0 && s == 0) break;
		depth(n, s, 0);
		cout << cunt << endl;
		cunt = 0;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define MOD (long long)1000000007
using namespace std;

int main(void){
    vector<int> a(5);
    for(int i=0; i<5; i++)cin >> a[i];
    int ans=0,rem=10;
    for(int i=0; i<5; i++){
        ans+=(a[i]+9)/10*10;
        if(a[i]%10)rem=min(rem,a[i]%10);
    }
    ans+=rem-10;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%s", $string);

preg_match_all("/[ATCG]+/",$string,$matches,PREG_SET_ORDER);

$length=0;

foreach ($matches as $match) {
    $tmpLength=strlen($match[0]);
    if($tmpLength > $length){
        $length=$tmpLength;
    }
}
print $length;



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

template<typename T>
void fin (T a){
    cout<<a<<endl;
    exit(0);
}

template<typename S>
void print(S a){
    cout<<a<<endl;
}

template<typename U>
void pprint(U a){
    cout<<a;
}


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

    ull n;
    cin>>n;
    vector<ull> a(n);
    ull tmp;
    ull sum = 0;
    ull ans = 0;
    ull tmpmod;
    const ull mod =  1000000007;
    rep(i,n){
        cin>>tmp;
        tmpmod = (sum*tmp)%mod;
        ans +=tmpmod;
        ans%=mod;
        sum += tmp;
        sum%=mod;
    }


    fin(ans) ;

    return 0;
}




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

int main(){
    int a,b,k;
    cin>>a>>b>>k;
    vector<int>sei;
    for(int i=1;i<=min(a,b);i++){
        if(a%i==0 && b%i==0){
            sei.push_back(i);
        }
    }
    sort(sei.begin(),sei.end());
    reverse(sei.begin(),sei.end());
    cout<<sei.at(k-1)<<endl;
}

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

char aeiou[5] = {'a','e','i','o','u'};

int main(){
    char c;
    cin >> c;
    for(int i=0;i<5;i++){
        if(c==aeiou[i]){
            cout << "vowel" << endl;
            return 0;
        }
    }
    cout << "consonant" << endl;
    return 0;
}

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

int main() {
    int x, y;
    cin >> x >> y;

    int a = (4 * x - y) / 2;
    int b = (y - 2 * x) / 2;

    if (a + b != x || (a < 0 || b < 0))
        cout << "No";
    else
        cout << "Yes";
    cout << endl;

    return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define out(a) cout << a << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)

int main() {
    int n; cin >> n;
    for (int i = n; i >= 0; --i) {
        if (sqrt(i) == (int)sqrt(i)) {
            out(i);
            break;
        }
    }
}




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

int main(){
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    
    while(k > 0) {
        if(b <= a) {b *=2; k--; continue;}
        if(c <= b) {c *=2; k--; continue;}
        k--;
    }
    
    if(a < b && b < c) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(0)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<piii> viii;

const int MAXN = 1000100, MAXK = 30;
const ll MOD = 1e9+7;
const ll INF = 1e18;
const ld PI = asin(1) * 2;

ll dp[10100];
ll a[10100], b[10100];

int main()
{
    FAST_IO;

    int h; cin >> h;
    int n; cin >> n;
    FOR(i, 0, h) dp[i] = INF;
    dp[h] = 0;
    FOR(i, 1, n) cin >> a[i] >> b[i];

    ll ans = INF;
    for (int i = h; i > 0; i--) {
        FOR(j, 1, n) {
            if (i-a[j] <= 0) ans = min(ans, dp[i]+b[j]);
            else dp[i-a[j]] = min(dp[i-a[j]], dp[i]+b[j]);
        }
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 384
import java.util.*;
import java.math.BigDecimal;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int v = sc.nextInt();
        int b = sc.nextInt();
        int w = sc.nextInt();
        BigDecimal t = sc.nextBigDecimal();

        BigDecimal diff = BigDecimal.valueOf(Math.abs(b-a));
        BigDecimal c = BigDecimal.valueOf(v-w);

        diff = diff.subtract(c.multiply(t));
        if(diff.compareTo(BigDecimal.valueOf(0))<=0) {
            System.out.print("YES");
            return;
        }

        System.out.print("NO");
    }
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
bool initialized = false;

/**
 * @fn
 * This function must be called at first.
 */
void combination_init() {
    initialized = true;
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

/**
 * @fn
 * Calculates the combination  ( nCK % p: N choose K mod p).
 *
 * @brief constraint: 1 ≤ k ≤ n ≤ 10^7
 * @return nCK % MOD
 */
long long combination(int n, int k) {
    assert(initialized);
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

/**
 * @fn
 * Calculates the factorial of the number.
 *
 * @return N! % MOD
 */
long long factorial(int n) {
    assert(initialized);
    if (n < 0) return 0;
    return fac[n] % MOD;
}

/**
 * @fn
 * Calculates the combination ( nCK % p: N choose K mod p).
 *
 * @brief constraint: 1 ≤ k ≤ 10^7 and 1 ≤ n ≤ 10^9
 * @return nCK % MOD
 */
long long combination2(int n, int k) {
    assert(initialized);
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    ll res = 1;
    k = min(k, n - k);
    for (long long x = 1; x <= k; x++) {
        res *= (n - x + 1);
        res %= MOD;
        res *= inv[x];
        res %= MOD;
    }
    return res;
}


void Main() {
    ll N, K;
    cin >> N >> K;
    combination_init();
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    sort(A.begin(), A.end());

    ll p = 0;
    ll m = 0;
    rep2(i, K - 1, N) {
        ll a = A[i];
        p += (a * combination(i, K - 1)) % MOD;
        p %= MOD;
    }

    rep(i, N - K + 1) {
        ll a = A[i];
        m += (a * combination(N - i - 1, K - 1)) % MOD;
        m %= MOD;
    }

    ll ans = p - m;
    ans %= MOD;
    if (ans < 0) ans += MOD;
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 13056
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
//最大公約数
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int x, y;
  cin >> x >> y;
  cout << x + y - gcd(x, y) + 1 << endl;
}



Measured memory_bytes: 3192
/*                          The four Truths of Life

                                    CKMKB
                                    PKMKB

                                    CKMKC
                                    PKMKC
*/


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <climits>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define ye cout<<"YES";
#define no cout<<"NO";
#define ln cout<<"\n";
// cout<<"Case #"<<ts<<": “;
//priority_queue < pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;


using namespace std;

ll mod(ll x, ll m) {
	return (x % m + m) % m;
}

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

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

	ll t = 1, r, n, a, d, c, b, x, y, sum, cnt, i, j, k, m, l, q, maxx, minn, temp, ans, flag, g, ts;
	ll mod = 1000000007;
	char ch, chh;
	double dans;
	string str, ttr;

	//cin >> t;


	for (ts = 1; ts <= t; ts++)
	{
		flag = 0; sum = 0; cnt = 0; ans = 0; k = 0; maxx = 0; minn = 0; a = 0; b = 0; temp = 0;

		cin >> n;

		ll brr[100001];
		memset(brr, 0, sizeof(brr));

		for (i = 0; i < n; i++)
		{
			cin >> x;
			sum += x;
			brr[x]++;
		}

		cin >> q;

		while (q--)
		{
			cin >> a >> b;

			temp = brr[a];

			brr[a] = 0;
			brr[b] += temp;

			sum += (temp * b);
			sum -= (temp * a);
			cout << sum;
			ln
		}








	}
	return 0;
}


Measured memory_bytes: 4432
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define pb push_back
#define all(v) v.begin(), v.end()
#define _GLIBCXX_DEBUG
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int N; cin>>N;
    int sum=0;
    rep(i,N+1) {
        sum+=i;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAXN 200005
int n,i,cnt,hd[MAXN],v[MAXN],nxt[MAXN],w[MAXN],d[MAXN];
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
inline void print(int x)
{
    if (x<0)
        putchar('-'),x=-x;
    if(x>9)
        print(x/10);
    putchar(x%10+'0');
}
inline void dfs(int u,int fa)
{
    for(int i=hd[u];i;i=nxt[i])
	{
	    if(v[i]!=fa)
		{
	        d[v[i]]=d[u]+w[i];
	        dfs(v[i],u);
	    }
	}
}
signed main(void)
{
    read(n);
    for(i=1;i<n;i++)
	{
		int x,y,z;
		read(x),read(y),read(z);
		v[++cnt]=y;
		nxt[cnt]=hd[x];
		w[cnt]=z;
		hd[x]=cnt;
		v[++cnt]=x;
		nxt[cnt]=hd[y];
		w[cnt]=z;
		hd[y]=cnt;
	}
    dfs(1,0);
    for(i=1;i<=n;i++)
		print(d[i]&1),putchar('\n');
	return 0;
}

Measured memory_bytes: 4480
s = list(input())
t = list(input())

s.sort()
t.sort()

i = 0
j = len(t) - 1
while True:
    if s[i] < t[j]:
        print('Yes')
        exit()
    elif s[i] > t[j]:
        print('No')
        exit()
    else:
        i += 1
        j -= 1
        if j < 0:
            print('No')
            exit()
        if i >= len(s):
            print('Yes')
            exit()


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

using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep3(i, n) for (int i = 1; i < (int)(n+1); i++)
#define rep4(i, s, n) for (int i = (s); i < (int)(n+1); i++)
#define repr(i,n) for (int i = (n-1); i>=0;i--)
#define repr3(i,n) for(int i = (n);i>0;i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;



int main() {
const ll INF = 1001001001;
const ld PI = 3.14159265358979323846;
int A,B,K,count=0,ans;
cin>>A>>B>>K;
repr3(i,min(A,B)){
    if((A%i==0)&&(B%i==0)){
        count++;
        if(count==K){
            ans=i;
            break;
        }
    }
}
cout<<ans<<endl;
return 0;
}



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

using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;

#define out(a) cout << a << endl
#define out1(a) cout << a
#define in(a) cin >> a
#define in2(a, b) cin >> a >> b
#define in3(a, b, c) cin >> a >> b >> c
#define rep(i, N) for (ll i = 0; i < (ll)N; i++)
#define rep1(i, N) for (ll i = 1; i <= (ll)N; i++)
#define repi(i, j, N) for (ll j = (ll)i + 1; j < (ll)N; j++)
#define all(v) v.begin(), v.end()

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

constexpr int inf = 1e9;
constexpr ll linf = 1e18;
constexpr ll mod = 1e9 + 7;

void solve();

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

void solve()
{
    int a, b, c;
    in3(a, b, c);
    int ans = max(b + c - a, 0);
    out(ans);
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int i,j,n,m,cn;
  char c,s[5]={'S','H','C','D','\0'};
  static int card[4][13];
  scanf("%d\n",&n);

  for(i=0;i<n;i++){
    scanf("%c %d\n",&c,&m);
    for(j=0;j<4;j++)
      if(s[j]==c)
        card[j][m-1]=1;
  }
  
  for(i=0;i<4;i++)
    for(j=0;j<13;j++)
      if(card[i][j]==0)
        printf("%c %d\n",s[i],j+1);

  return 0;
}


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

using namespace std;

int main()
{
    string S;
    cin >> S;
    int ramen = 700;

    for (int i = 0; i < 3; i++){
        if (S.at(i) == 'o'){
            ramen += 100;
        }
    }
    cout << ramen << endl;
}

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

const int MAXN = 2e5+5;
const int INF = 1e9+7;
#define ll long long
#define pb push_back
#define endl '\n'
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F first
#define S second

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

ll MOD(ll a){
    return ((a%INF)+INF)%INF;
}

int a[MAXN],b[MAXN];

int main()
{
    fast_io;
    //cout << fixed << setprecision(15);

    int n;cin >> n;
    string s,t;cin >> s >> t;
    for(int i=0;i<n;++i) cout << s[i] << t[i];
}


Measured memory_bytes: 256
def solve?(n, sequence, index)
	return true if n == 0
	return false if index >= sequence.size
	solve?(n, sequence, index + 1) || # sequence[index]を選択ないパターン
		solve?(n - sequence[index], sequence, index + 1) # sequence[index]を選択するパターン
end

n = STDIN.gets.to_i
sequence = STDIN.gets.split[0...n].map(&:to_i)
m = STDIN.gets.to_i
questions = STDIN.gets.split[0...m].map(&:to_i)

sequence.sort!
questions.each do |q|
	puts solve?(q, sequence, 0) ? "yes" : "no"
end

Measured memory_bytes: 6100
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	char c;
	cin >> c;
	if (c == 'a' || c == 'i' || c == 'u'
		|| c == 'e' || c == 'o') {
		cout << "vowel" << endl;
	}
	else {
		cout << "consonant" << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <utility>
#include <vector>


struct Node {
  int value;
  Node *rightNode, *leftNode;

  Node(int value): value(value) {
    rightNode = nullptr;
    leftNode=  nullptr;
  }

  bool rightEmpty() {
    return rightNode == nullptr;
  }

  bool leftEmpty() {
    return leftNode == nullptr;
  }

  void attachNodeToLeft(Node* node) {
    leftNode = node;
  }

  void attachNodeToRight(Node* node) {
    rightNode = node;
  }

};

class Tree {
private:
  Node* rootNode;
public:
  void setRoot(Node *rootNode){
    this->rootNode = rootNode;
  }

  void addNode(Node *newNode) {
    Node* comparingNode = rootNode;
    while(1) {
      if(comparingNode->value > newNode->value) {
        if(comparingNode->leftEmpty()) {
          comparingNode->attachNodeToLeft(newNode);
          break;
        }else {
          comparingNode = comparingNode->leftNode;
        }
      }else {
        if(comparingNode->rightEmpty()) {
          comparingNode->attachNodeToRight(newNode);
          break;
        }else {
          comparingNode = comparingNode->rightNode;
        }
      }
    }
  }

  std::vector<int> inOrder(Node* targetNode) {
    std::vector<int> ret;
    if(!targetNode->leftEmpty()) {
      std::vector<int> left = inOrder(targetNode->leftNode);
      ret.insert(ret.end(), left.begin(), left.end());
    }
    ret.push_back(targetNode->value);
    if(!targetNode->rightEmpty()) {
      std::vector<int> right = inOrder(targetNode->rightNode);
      ret.insert(ret.end(), right.begin(), right.end());
    }
    return ret;
  }

  std::vector<int> preOrder(Node* targetNode) {
    std::vector<int> ret;
    ret.push_back(targetNode->value);

    if(!targetNode->leftEmpty()) {
      std::vector<int> left = preOrder(targetNode->leftNode);
      ret.insert(ret.end(), left.begin(), left.end());
    }
    if(!targetNode->rightEmpty()) {
      std::vector<int> right = preOrder(targetNode->rightNode);
      ret.insert(ret.end(), right.begin(), right.end());
    }
    return ret;
  }

  void printInOrder() {
    for(int i: inOrder(rootNode)) {
      std::cout << ' ' << i;
    }

  }
  void printPreOrder() {
    for(int i: preOrder(rootNode)) {
      std::cout << ' ' << i;
    }

  }
};

int main() {
  Tree tree;

  int n;
  std::cin >> n;

  for(int i = 0; i < n; i++) {
    std::string command;
    int key;
    std::cin >> command;
    if(i == 0) {
      std::cin >> key;
      tree.setRoot(new Node(key));
      continue;
    }
    if(command[0] == 'i') {
      std::cin >> key;
      tree.addNode(new Node(key));
    }else {
      tree.printInOrder();
      std::cout << std::endl;
      tree.printPreOrder();
      std::cout << std::endl;

    }
  }
}

Measured memory_bytes: 24284
/**
*author: Ritchie Zhang
*date:2020/5/2
**/

#include <stdio.h>
#define LL long long
int main() {
	LL x, y;
	int i;
	scanf("%lld", &x);
	y = 100;
	for (i = 1; i <= 4000; i++) {
		y = y + y * 0.01;
		if (y >= x)break;
	}
	printf("%d\n", i);
	return 0;
}

Measured memory_bytes: 1728
# include <bits/stdc++.h>
#define INF 1e9
using namespace std;

int main(){
  int N, M;
  cin >> N >> M;
  long int dp[N+1];
  fill(dp, dp+N+1, 0);
  long int mod = pow(10, 9) + 7;
  dp[0] = 1;
  dp[1] = 1;
  for(int i=0; i < M; i++){
    int j; cin >> j;
    dp[j] = -1;
  }

  for(int i=2; i < N+1; i++){
    if(dp[i] != -1){
      if(dp[i-1] != -1){
        dp[i] += dp[i-1];
      }
      if(dp[i-2] != -1){
        dp[i] += dp[i-2];
      }
      dp[i] %= mod;
    }
    // cout << dp[i] << endl;
  }

  cout << dp[N] << endl;

}

Measured memory_bytes: 1024
import sys
from collections import Counter, deque, defaultdict, OrderedDict
from math import factorial
from fractions import Fraction
import heapq, bisect
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
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()))

r = INT()
print(r**2)

Measured memory_bytes: 63980
// C - HonestOrUnkind2
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
using BITS = bitset<15>;

int N, A[15], X[15][15], Y[15][15];

int check(BITS bits){
	rp(i, 0, N)
		if(bits[i])
			rp(j, 0, A[i]) if(bits[X[i][j]] != Y[i][j]) return 0;
	return bits.count();
}

int main(){
	scanf("%d",&N);
	rp(i, 0, N){ scanf("%d",A+i); rp(j, 0, A[i]){ scanf("%d%d",X[i]+j,Y[i]+j); X[i][j]--; } }
	int ans = 0;
	rp(bits, 1, 1<<N) ans = max(ans, check(bits));
	printf("%d\n", ans);
}

Measured memory_bytes: 256
use std::io;


fn main() {
    let (h, w, d) = {
        let i = read::<usize>();
        (i[0], i[1], i[2])
    };
    let mut pos = vec![(0, 0); h * w + 1];
    for i in 0..h {
        let ln = read::<isize>();
        let mut j = 0;
        for a in ln.iter() {
            pos[a.clone() as usize] = (i as isize, j as isize);
            j += 1;
        }
    }

    let mut cost = vec![0; h * w + 1];
    for i in d..(h * w + 1) {
        cost[i] = cost[i - d] + ((pos[i].0 - pos[i - d].0) as isize).abs() + ((pos[i].1 - pos[i - d].1) as isize).abs();
    }

    let q = read_one::<usize>();
    for _ in 0..q {
        let (s, t) = {
            let i = read::<usize>();
            (i[0], i[1])
        };
        println!("{}", cost[t] - cost[s]);
    }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 7292
#include<stdio.h>
#include<stdlib.h>
#define NIL -1

typedef struct{
  int right,left;
}Node;

int Depth(int);
int Height(int);

Node node[25];
int n=0;

int main()
{
  int i,j,k=0,l=0,m=0,C=0,c;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      node[i].right=NIL;
      node[i].left=NIL;
    }
  for(i=0;i<n;i++)
    {
      scanf("%d",&m);
      for(j=0;j<2;j++)
        {
          scanf("%d",&C);
          if(j==0)
            {
              k=C;
            }
          else
            {
              node[C].left=k;
              node[k].left=C;
            }
          node[C].right=m;
        }
    }
  for(i=0;i<n;i++)
    {
      c=0;
      printf("node %d: parent = %d, sibling = %d, ",i,node[i].right,node[i].left);
      for(j=0;j<n;j++)
        {
          if(node[j].right==i)
            c++;
        }
      printf("degree = %d, depth = %d, height = %d, ",c,Depth(i),Height(i));
      if(node[i].right==NIL)
        {
          printf("root\n");
        }
      else if(c>0)
        {
          printf("internal node\n");
        }
      else printf("leaf\n");
    }
  return 0;
}

int Depth(int x)
{
  if(node[x].right==NIL)
    {
    return 0;
    }
  else return Depth(node[x].right) + 1;
}

int Height(int y)
{
  int i,a=NIL,b=NIL;
  for(i=0;i<n;i++)
    {
      if(node[i].right==y)
        {
          if(b==NIL)
            b=Height(i);
          else a=Height(i);
        }
    }
  if(a>b)
    {
      return a+1;
    }
  else return b+1;
}
              



Measured memory_bytes: 2108
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int N, X, sm = 0, mn = 1000;
cin >> N >> X;
vector<int> m(N);
for (int i = 0; i < N; ++i) cin >> m[i];
for (int i : m) {
        sm += i;
        mn = min(mn, i); 
}
cout << N + (X - sm) / mn << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
#define pll pair<ll,ll>
#define INF 1000000007



int main()
{
	ll n,i,j,k;
	cin>>n;
	ll arr[n+1];
	for(i=1;i<=n;i++)
	{
		cin>>arr[i];
	}
	ll dp[n+1];
	for(i=1;i<=n;i++)
	{
		dp[i]=INF;
	}
	dp[1] = 0;

	for(i=2;i<=n;i++)
	{
		if(i==2)
		{
			dp[i] = min(dp[i],dp[1] + abs(arr[i]-arr[1]));
		}
		else{
		for(j=i-1;j>=i-2;j--)
		{
			dp[i] = min(dp[i],dp[j] + abs(arr[i] - arr[j]));
		}
	}
	}
	cout<<dp[n]<<endl;
}

Measured memory_bytes: 1792
// Ala be zekrellah tatmaenolgholoob ...
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
#define F first
#define S second
#define MP make_pair
const int maxn = 1e6+9;
const ll mod = 1e9+7;

vector <int> ans;

int main () {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	if (n == 3) {
		cout << "2 5 63\n";
		return 0;
	}
	ans.push_back(2);
	ans.push_back(3);
	ans.push_back(9);
	n -= 3;
	if (n >= 1) {
		ans.push_back(4);
		n -= 1;
	}
	int cur = 15;
	while (n >= 2 && cur <= 30000) {
		ans.push_back(cur);
		cur += 6;
		ans.push_back(cur);
		cur += 6;
		n -= 2;
	}
	cur = 8;
	while (n >= 2 && cur <= 30000) {
		ans.push_back(cur);
		cur += 2;
		ans.push_back(cur);
		cur += 4;
		n -= 2;
	}
	cur = 6;
	while (n) {
		ans.push_back(cur);
		cur += 6;
		n -= 1;
	}
	// ans
	for (auto x : ans)
		cout << x << " ";
	cout << "\n";
}

Measured memory_bytes: 640
#include <iostream>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdarg>
#include <set>
#include <limits>
#include <iomanip>

using namespace std;
#define INF 2e9 + 9
#define MOD 1000000007
#define ALL(v) v.begin() , v.end()
#define Int int64_t
#define pll pair<Int,Int>
template<class T> using pql = priority_queue<T, vector<T>>;
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;
#define ll(n) Int n; cin >> n;
#define LL(...) Int __VA_ARGS___; cin >> __VA_ARGS___;
#define OUT(...) cout << __VA_ARGS___;
#define RP(n, i, s) for(Int i = s ;i < n ;i++)
#define REP(n, i) for (Int i = 0; i < n; i++)
#define REPe(n, i) for (Int i = 1; i <= n; i++)
#define RPe(n, i, s) for (Int i = s; i <= n; i++)
#define upd_max(maxer, updater) if (maxer < updater) maxer = updater;
#define upd_min(miner, updater) if (miner > updater) miner = updater;

void ansYes(bool flag) {
    if (flag) cout << "Yes" << endl; else cout << "No" << endl;
}

void ansYES(bool flag) {
    if (flag) cout << "YES" << endl; else cout << "NO" << endl;
}

struct node {
    Int to;
    Int length;
};


vector<Int> divisor(Int n) {
    vector<Int> ret;
    for (Int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    return (ret);
}

/*
vector<vector<int>> to;
vector<int> flag;
vector<int> c;


Int dfs(int from, int mae) {
    flag[from] = 1;
    Int mini = 0;
    for (auto next : to[from]) {
        if (next == mae) continue;
        if (flag[next] == 1) {
            return -1;
        } else {
            mini = min(mini, dfs(next, from));
        }
    }
    return mini;
}*/

int dx8[8] = {0, -1, -1, -1, 0, 1, 1, 1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};

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

struct datas {
    Int max;
    Int size;
};

class ContainChecker {
protected:
    Int minx, miny, maxx, maxy;
public:
    ContainChecker(Int minx, Int miny, Int maxx, Int maxy) : minx(minx), miny(miny), maxx(maxx), maxy(maxy) {};

    bool in(Int x, Int y) {
        return (minx <= x && miny <= y && x <= maxx && y <= maxy);
    }
};





int main(void) {
    Int x;
    cin >> x;
    Int sum = 0;
    for (int i = 1; i <= x;i++){
        sum += i;
        if (sum >= x) {
            cout << i << endl;
            return 0;
        }
    }

}




Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();
		int d = scanner.nextInt();

		if (a + b == c + d) {
			System.out.println("Balanced");
		} else if (a + b < c + d) {
			System.out.println("Right");
		} else {
			System.out.println("Left");
		}

	}

}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <bitset>
#include <math.h>

using namespace std;

int main()
{
	int n, m;
	long long ans=0;
	cin >> n >> m;
	vector<bitset<10>> lit(m, bitset<10>(0));
	vector<int> p(m);
	for (int i = 0; i < m; i++)
	{
		int k;
		cin >> k;
		for (int j = 0; j < k; j++)
		{
			int buf;
			cin >> buf;
			lit[i][buf - 1] = 1;
		}
	}
	for (int i = 0; i < m; i++) cin >> p[i];

	for (int i = 0; i < pow(2, n); i++)
	{
		bool flag = true;
		bitset<10> bit(i),buf(0);
		for (int j = 0; j < m; j++)
		{
			buf = lit[j]&bit;
			if (buf.count() % 2 != p[j]) flag = false;
		}
		if (flag) ans++;
	}
	cout << ans;
}

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

long long dp[510][510];

void solve(long long N, long long M_a, long long M_b, vector<long long> a, vector<long long> b, vector<long long> c){
	for(int i = 0; i < 500; ++i) for(int j = 0; j < 500; ++j) {
		dp[i][j] = 1000000;
	}
	dp[0][0] = 0;
	for(int i = 0; i < N; ++i) {
		for(int j = 500; j >= a[i]; --j) for(int k = 500; k >= b[i]; --k) {
			dp[j][k] = min(dp[j][k], dp[j - a[i]][k - b[i]] + c[i]);
		}
	}
	long long res = 1000000;
	for(int i = 1; i < 500; ++i) for(int j = 1; j < 500; ++j) {
		if (i * M_b == j * M_a) {
			res = min(res, dp[i][j]);
		}
	}
	cout << (res == 1000000 ? -1 : res) << endl;
}

int main(){	
	long long M_b;
	long long M_a;
	long long N;
	scanf("%lld",&N);
	vector<long long> c(N-1+1);
	vector<long long> b(N-1+1);
	vector<long long> a(N-1+1);
	scanf("%lld",&M_a);
	scanf("%lld",&M_b);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&a[i]);
		scanf("%lld",&b[i]);
		scanf("%lld",&c[i]);
	}
	solve(N, M_a, M_b, a, b, c);
	return 0;
}



Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<62;

int main() {
  ll n;
  cin >> n;
  vec a(n+1);
  for(ll i=0;i<=n;i++) cin >> a[i];
  vec ans(n+1);
  ans[n]=a[n];
  ll f=0;
  for(ll i=n;i;i--) {
    ll res=ans[i]+a[i-1];
    ans[i-1]=res;
  }
  ans[0]=1;
  for(ll i=0;i<n;i++) {
    ll res=(ans[i]-a[i])*2;
    ans[i+1]=min(ans[i+1],res);
  }
  ll res=0;
  for(ll i=0;i<=n;i++) {
    res+=ans[i];
    if(ans[i]<=0) f=1;
    if(i==n&&ans[i]!=a[i]) f=1;
  }
  if(f) res=-1;
  cout << res << endl;
}

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

struct fast_io {
    fast_io() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
    }
} __fast_io;

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

    vector<int> A(N);
    for (int &x : A)
        cin >> x;

    ll total = 0;
    for (int i = 1; i < N; i++) {
        if (A[i] < A[i - 1]) {
            total += A[i - 1] - A[i];
            A[i] = A[i - 1];
        }
    }

    cout << total << endl;
}


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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 1000007;
const int MOD = SC ( int, 1e9 + 7 );

int n;
LL frac[MAXN], rf[MAXN];

void init ();
void input ();
void work ();

int add ( int x, int y )
{
	x += y;
	if ( x >= MOD ) x -= MOD;
	return x;
}

void addv ( int &x, int y )
{
	x += y;
	if ( x >= MOD ) x -= MOD;
}

int dec ( int x, int y )
{
	x -= y;
	if ( x < 0 ) x += MOD;
	return x;
}

int qpow ( int a, int b )
{
	LL base = a, ans = 1;
	while ( b ){
		if ( b & 1 ) ( ans *= base ) %= MOD;
		( base *= base ) %= MOD;
		b >>= 1;
	}
	return SC ( int, ans );
}

int C ( int n, int m )
{
	return ( n >= m ) ? SC ( int, frac[n] * rf[m] % MOD * rf[n-m] % MOD ) : 0;
}



int main()
{
	init();
	input();
	work();
}



void init ()
{
	// Init Everything Here
	
	ios::sync_with_stdio ( false );
	
	frac[0] = 1;
	lp ( i, 1, MAXN ) frac[i] = frac[i-1] * i % MOD;
	rf[MAXN-1] = qpow ( frac[MAXN-1], MOD-2 );
	lpdi ( i, MAXN-2, 0 ) rf[i] = rf[i+1] * ( i + 1 ) % MOD;
}

void input ()
{
	// input method
	
	cin >> n;
}

void work ()
{
	// main work
	
	--n;
	
	int ans = 0;
	lp ( i, 0, n ){
		addv ( ans, dec ( C ( n, i ), C ( i - 1, n - i ) ) * frac[i] % MOD * frac[n-i] % MOD );
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 15872
#include<stdio.h>
#define max(a,b) (a)>(b)?(a):(b)
#define min(a,b) (a)<(b)?(a):(b)
int main(void)
{
  int n,m,min,max;
  scanf("%d%d",&n,&m);
  int l[m],r[m];
  min=1;max=n;
  for(int i=0;i<m;i++){
    scanf("%d%d",&l[i],&r[i]);
    min=max(min,l[i]);
    max=min(max,r[i]);
  }
  if(max>=min){
    printf("%d",max-min+1);
  }else{
    puts("0");
  }
  return 0;
}
  
    

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(...) out(__VA_ARGS__);cout<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void out(){} template<class T,class... U> void out(T t,U ...u){cout<<t<<" ";out(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(int, N, K);
  VEC(int, l, N);
  sort(all(l), greater<>());
  print(accumulate(l.begin(), l.begin() + K, 0));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define repeat(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main(){
    int N, T;
    cin >> N >> T;
    P a[N];
    rep(i, N){
        a[i].first = INF;
        a[i].second = INF;
    }
    int res = 0;
    rep(i, N){
        int c, t;
        cin >> c >> t;
        if(t <= T){
            a[i].first = c;
            a[i].second = t;
        }else res ++;

    }
    if(res == N) cout << "TLE" << endl;
    else{
    sort(a, a + N);
    cout << a[0].first << endl;

}}


Measured memory_bytes: 256
import java.util.*;
public class Main {

	public void doIt(){
		Scanner sc = new Scanner(System.in);

		int [] array = new int[10];
		for(int i=0; i < 10; i++){
			array[i] = sc.nextInt();
		}
		Arrays.sort(array);
		for(int i= 10-1; i > 10-1-3; i--){
			System.out.println(array[i]);
		}
	}
	public static void main(String[] args) {
		Main obj = new Main();
		obj.doIt();

	}

}

Measured memory_bytes: 0