akhauriyash/Code-Regression huggingface dataset:
/*--------------------------------
  Author: The Ace Bee
  Blog: www.cnblogs.com/zsbzsb
  This code is made by The Ace Bee
--------------------------------*/
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#define rg register
using namespace std;
template < typename T > inline void read(T& s) {
	s = 0; int f = 0; char c = getchar();
	while (!isdigit(c)) f |= (c == '-'), c = getchar();
	while (isdigit(c)) s = s * 10 + (c ^ 48), c = getchar();
	s = f ? -s : s;
}

const int _ = 100010;

int n, L, q, x[_], nxt[22][_], pre[22][_];

inline int calc(int a, int b) {
	int res = 0;
	if (a < b) {
		for (rg int i = 20; ~i; --i) {
			if (nxt[i][a] < b)
				a = nxt[i][a], res += 1 << i;
			if (a == b) return res;
		}
	} else {
		for (rg int i = 20; ~i; --i) {
			if (pre[i][a] > b)
				a = pre[i][a], res += 1 << i;
			if (a == b) return res;
		}
	}
	return res + 1;
}

int main() {
	read(n);
	for (rg int i = 1; i <= n; ++i) read(x[i]);
	read(L), read(q);
	
	for (rg int i = 1, to = 0; i <= n; ++i)
	{ while (x[to + 1] - x[i] <= L && to < n) ++to; nxt[0][i] = to; }
	for (rg int i = n, to = n + 1; i >= 1; --i)
	{ while (x[i] - x[to - 1] <= L && to > 1) --to; pre[0][i] = to; }
	
	for (rg int j = 1; j <= 20; ++j)
		for (rg int i = 1; i <= n; ++i) {
			nxt[j][i] = nxt[j - 1][nxt[j - 1][i]];
			if (nxt[j][i] == 0) nxt[j][i] = n;
			pre[j][i] = pre[j - 1][pre[j - 1][i]];
			if (pre[j][i] == 0) pre[j][i] = 1;
		}

	for (rg int a, b, i = 1; i <= q; ++i)
		read(a), read(b), printf("%d\n", calc(a, b));
	
	return 0;
}


Measured memory_bytes: 18048
ans = [] # 答え
while True:
    N = int(input())
    if not N:
        break
    
    now_cube = int(N ** (1 / 3 + 0.000001))
    now_pyramid = 0
    tmp_ans = now_cube ** 3
    
    # 立方体の一辺を小さくしていく、立方体の辺ごとに四角錐の一辺の長さを求め、容量を求める
    for i in range(now_cube, -1, -1):
        while True:
            # もし次の値が最大容量を超えるならば
            if (now_pyramid + 1) * (now_pyramid + 2) * (now_pyramid + 3) // 6 + i ** 3 > N:
                # 超えない値の時にこれまでの最大値と比較して大きい方を答えとする
                tmp_ans = max(tmp_ans, now_pyramid * (now_pyramid + 1) * (now_pyramid + 2) // 6 + i ** 3)
                break
                
            # 四角錐の一辺を大きくしていく
            now_pyramid += 1
    
    ans.append(tmp_ans)
    
# 出力     
[print(i) for i in ans]



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

int main() {
	int n;
	cin>>n;
	int arr[n][3];
	int a, b, c;
	for(int i = 0;i<n;i++){
	    cin>>a>>b>>c;
	    arr[i][0] = a;
	    arr[i][1] = b;
	    arr[i][2] = c;
	}
	
	int dp[n][3];
	
	dp[0][0] = arr[0][0];
	dp[0][1] = arr[0][1];
	dp[0][2] = arr[0][2];
	
	if(n!=1)
	for(int i = 1;i<n;i++){
	    dp[i][0] = arr[i][0] + max(dp[i-1][1],dp[i-1][2]);
	    dp[i][1] = arr[i][1] + max(dp[i-1][0],dp[i-1][2]);
	    dp[i][2] = arr[i][2] + max(dp[i-1][1],dp[i-1][0]);
	    //cout<<dp[i][0]<<" "<<dp[i][1]<<" "<<dp[i][2]<<endl;
	}
	
	cout<<max(dp[n-1][0],max(dp[n-1][1], dp[n-1][2]))<<endl;
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
    
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define ST first
#define ND second
#define MP make_pair
#define PB push_back
    
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef set<int> SI;
typedef long long LL;
    
#ifdef DEBUG
const bool debug = true;
#else
const bool debug = false;
#endif

// #define MULTI_TASK true

const int inf = 1000 * 1000 * 1000;
const int MAKSN = 1000 * 1000 + 13;
const LL MOD = 123456789LL;
int n, m, k, l, x, y, a, b;
string s;
vector<int> v;


void zeruj() {
    v.clear();
}

void readIn() {
    cin >> n;
    cout << (n / 500) * 1000 + ((n % 500) / 5)* 5 << "\n";
}
        
void solve() {
    
}

int main() {
    ios_base::sync_with_stdio(0);
#ifdef MULTI_TASK
    int test;
    cin >> test;
    while (test--) {
#endif
        zeruj();
        readIn();
        solve();
#ifdef MULTI_TASK
    }
#endif 
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    int biria=0, birib=0; // biri = max(A)
    for (int i = 0; i < N; ++i) {
        int A, B;
        cin >> A >> B;
        if(biria < A){
            biria = A;
            birib = B;
        }
    }

    cout << biria+birib << endl;
}


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

int main() {
	int a, b, m;
	cin >> a >> b >> m;
	vector<int> v1(a+1,0), v2(b+1,0);
	int refmin = INT_MAX, micmin = INT_MAX;
	for(int i =1; i <= a; i++) {
	    cin >> v1[i];
	    refmin = min(refmin,v1[i]);
	}
	for(int i = 1; i <= b; i++) {
	    cin >> v2[i];
	    micmin = min(micmin,v2[i]);
	}
	int ans = INT_MAX;
	for(int i = 1; i <= m; i++) {
	    int x, y, c;
	    cin >> x >> y >> c;
	    ans = min(ans,v1[x]+v2[y]-c);
	}
	cout << min(micmin+refmin,ans) << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

int main()
{
    string A;
    cin >> A;
    lint N = A.length();

    lint k = 0;
    map<char, lint> count;
    for (auto c : A) count[c]++;
    for (auto v : count) k += v.second * (v.second - 1) / 2;
    cout << N * (N - 1) / 2 - k + 1 << endl;
}


Measured memory_bytes: 640
while True:
    h, w = map(int, input().split())
    
    if (h, w) == (0, 0):
        break
    
    for i in range(h):
        if i == 0 or i == h-1:
            print("#" * w)
        else:
            print("#" + "." * (w-2) + "#")
    print()



Measured memory_bytes: 5612
import java.util.Scanner;

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

        int n = sc.nextInt();
        int[] c = new int[n-1];  // 次の駅までの所要時間
        int[] s = new int[n-1];  // 始発時間
        int[] f = new int[n-1];  // 発車間隔

        for (int i = 0; i < n-1; i++) {
            c[i] = sc.nextInt();
            s[i] = sc.nextInt();
            f[i] = sc.nextInt();
        }

        int[] ans = new int[n];
        for (int i = 0; i < n-1; i++) {
            int time = 0;
            for (int j = i; j < n-1; j++) {
                if (time < s[j])  // 一駅運航なので始発まで待つ
                    time = s[j];
                else if (time % f[j] != 0)
                    time += f[j] - (time % f[j]);

                time += c[j];
            }
            ans[i] = time;
        }

        // 出力
        for (int i : ans)
            System.out.println(i);
    }
}


Measured memory_bytes: 26172
#include <cstdio>
#define MAX_N 300000
#define MAX_C 300000
int main(){
  int N, Q;
  scanf("%d %d\n", &N, &Q);
  int card[MAX_N];
  bool has_card[MAX_C+1];


  for(int i = 0; i < N; i++){
    scanf("%d", &card[i]);
  //  printf("card %d ", card[i]);
  }
  for(int i = 0; i <= MAX_C; i++){
    has_card[i] = false;
  }
  for(int i = 0; i < N; i++){
    has_card[card[i]] = true;
  }
//  printf("\n");
  for(int i = 0; i < Q; i++){
    int q;
    scanf(" %d", &q);
  //  printf("q = %d\n", q);
    bool found = false;
    for(int init = q-1; init >= 0; init--){
      for(int j = init; j < MAX_C ; j += q){
        if(has_card[j]){
          printf("%d\n", init);
          found = true;
          break;
        }
      }
      if(found){
        break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 2488
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;


int main() {
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    while (--n){
        ll add = ans / (k-1) + 1;
        ans += add;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3048
import java.io.*;

class Main{
	public static void main(String[] args) {
		try{
			BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
			String str = buf.readLine();
			int cubic = Integer.parseInt(str);
			System.out.println(cubic*cubic*cubic);
		}
		catch(IOException e){
			
		}
	}
}


Measured memory_bytes: 24448
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define iter(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define riter(i, c) for (auto i = (c).rbegin(); i != (c).rend(); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S, T;
    cin >> S >> T;
    cout << T << S << endl;
    return 0;
}

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

def main():
    _ = int(input())
    A = list(map(int, input().split()))
    m = 0
    for i,a in enumerate(A):
        if a < 0:
            m += 1
        A[i] = abs(a)
    if m%2 == 1:
        print(sum(A)-min(A)*2)
    else:
        print(sum(A))

if __name__ == '__main__':
    main()


Measured memory_bytes: 14236
H, W = map(int, input().split())
dist = [list(map(int, input().split())) for _ in range(10)]
for i in range(10):
    for j in range(10):
        for k in range(10):
            dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k])
ans = 0
for _ in range(H):
    for i in list(map(int, input().split())):
        if i == 1 or i == -1:
            continue
        ans += dist[i][1]
print(ans)

Measured memory_bytes: 9128
#include <stdio.h>
int main(){
    int h = 0,m = 0,s = 0,S = 0;
    scanf("%d",&S);
    h = S/3600;
    m = (S-3600*h)/60;
    s = S-(3600*h+60*m);
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}


Measured memory_bytes: 1996
package main

import "fmt"

func match(b byte, matcher []byte) bool {
	for _, v := range matcher {
		if b == v {
			return true
		}
	}
	return false
}

func odd(b byte) bool {
	var matcher = []byte{'R', 'U', 'D'}
	return match(b, matcher)
}

func even(b byte) bool {
	var matcher = []byte{'L', 'U', 'D'}
	return match(b, matcher)
}
func playable(s string) bool {
	for i := 0; i < len(s); i++ {
		if i%2 == 1 {
			if !even(s[i]) {
				return false
			}
		} else {
			if !odd(s[i]) {
				return false
			}
		}
	}
	return true
}

func main() {
	var s string
	fmt.Scanln(&s)
	if playable(s) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        D solver = new D();
        solver.solve(1, in, out);
        out.close();
    }

    static class D {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int H = in.nextInt();
            int W = in.nextInt();
            int[][] a = in.nextIntArray(H, W);
            List<String> ans = new ArrayList<>();
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W - 1; j++) {
                    if (a[i][j] % 2 == 1) {
                        ans.add(String.format("%d %d %d %d", i + 1, j + 1, i + 1, j + 2));
                        a[i][j]--;
                        a[i][j + 1]++;
                    }
                }
            }
            for (int i = 0; i < H - 1; i++) {
                if (a[i][W - 1] % 2 == 1) {
                    ans.add(String.format("%d %d %d %d", i + 1, W, i + 2, W));
                    a[i][W - 1]--;
                    a[i + 1][W - 1]++;
                }
            }
            out.println(ans.size());
            ans.forEach(out::println);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public int[][] nextIntArray(int n, int m) {
            int[][] a = new int[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    a[i][j] = nextInt();
                }
            }
            return a;
        }

    }
}



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

#define TASKNAME ""

using namespace std;

const ll INF = 1e9 + 7;
const ll MAXN = 1e6 + 7;
const double EPS = 1e-8;

int main() {
    #ifdef MY
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #else
        //freopen(TASKNAME".in", "r", stdin);
        //freopen(TASKNAME".out", "w", stdout);
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    #endif // MY
    ll n;
    cin >> n;
    vector <ll> a(n);
    bool res_fl = false;
    ll maxk = -INF, pos = -1;
    ll even = 0, odd = 0;
    for (ll i = 0; i < n; i++) {
        cin >> a[i];
        if (maxk < a[i]) {
            maxk = a[i];
            pos = i;
        }
        if (a[i] > 0) {
            res_fl = true;
            if (i % 2 == 0) {
                odd += a[i];
            } else {
                even += a[i];
            }
        }
    }
    if (!res_fl) {
        cout << maxk << "\n";
        cout << n - 1 << "\n";
        for (ll i = n - 1; i > pos; i--) {
            cout << i + 1 << "\n";
        }
        for (ll i = 0; i < pos; i++) {
            cout << "1\n";
        }
        return 0;
    }
    cout << max(odd, even) << "\n";
    bool fl = (odd > even);
    vector <ll> res;
    while (n > 2) {
        if (n % 2 != fl) {
            if (a[n - 2] < 0) {
                res.push_back(n - 1);
                //cout << n - 1 << "\n";
                a[n - 3] += a[n - 1];
                a.pop_back();
                a.pop_back();
                n -= 2;
                continue;
            }
            res.push_back(n);
            //cout << n << "\n";
            n--;
            a.pop_back();
            continue;
        }
        if (a[n - 1] < 0) {
            res.push_back(n);
            //cout << n << "\n";
            n--;
            a.pop_back();
            continue;
        }
        if (a[n - 3] >= 0) {
            res.push_back(n - 1);
            //cout << n - 1 << "\n";
            a[n - 3] += a[n - 1];
            a.pop_back();
            a.pop_back();
            n -= 2;
            continue;
        }
        if (n == 3) {
            res.push_back(1);
            res.push_back(1);
            n -= 2;
            continue;
        }
        res.push_back(n - 2);
        //cout << n - 2 << "\n";
        a[n - 4] += a[n - 2];
        a[n - 3] = a[n - 1];
        n -= 2;
        a.pop_back();
        a.pop_back();
    }
    if (n == 2) {
        res.push_back(fl + 1);
        //cout << 2 - fl << "\n";
    }
    cout << res.size() << "\n";
    for (ll x : res) {
        cout << x << "\n";
    }
}


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

#define FASTIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
using ll = long long;
#define int ll
int32_t main(){
	int n;
	cin>>n;
	vector<int> a(n);
	for(auto &i : a)
		cin>>i;
	vector<vector<int>> dp(n + 1, vector<int>(n + 1));
	for(int i = n ; i > 0 ; i--){
		for(int j = i ; j <= n ;j++){
			if(i == j){
				dp[i][j] = a[i - 1];
			}else{
				dp[i][j] = max(a[i - 1] - dp[i + 1][j], a[j - 1] - dp[i][j - 1]);
			}
		}
	}
	cout<<dp[1][n]<<endl;
}

Measured memory_bytes: 73736
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define int long long
#define gcd __gcd
const int inf = 0x3f3f3f3f;
const int maxn = 201110;
const int M = 1e9+7;
int n,m,k,ok;

int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

signed main()
{
    cin>>n;
    cout<<a[n-1]<<endl;
    return 0;
}

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

int main(){
  int N;cin>>N;
  vector<ll> A(N);
  for(int i = 0;i < N;i++)cin>>A[i];
  for(int i = 0;i < N;i++){// 0が含まれるか判定
    if(A[i] == 0LL){
      cout << 0 << endl;
      return 0;
    }
  }

  ll ans = 1LL, MAX = 1000000000000000000LL;
  for(int i = 0;i < N;i++){
    if(MAX / ans < A[i]){// 10^18を超えないか判定
      ans = -1LL;
      break;
    }
    ans *= A[i];
  }
  cout << ans << endl;
}



Measured memory_bytes: 3976
#include<cmath>
#include<bits/stdc++.h>
#define MAX(a,b) (a>b? a:b)
#define MIN(a,b) (a>b? b:a)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repr(i,n) for(lint i=(lint)(n);i>0;--i)
#define reps(i,a,b) for(lint i=a;i<=(lint)(b);i++)
typedef long long lint;
typedef long double ld;
using namespace std;
const ld PI = acos(-1.0);

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    cout << sqrt((a+b+c)*(-a+b+c)*(a-b+c)*(a+b-c))/4 << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))[::-1]
last = 10 ** 10
ans = 'Yes'
for hi in H:
    if last >= hi:
        last = hi
    elif last >= hi - 1:
        last = hi - 1
    else:
        ans = 'No'
print(ans)


Measured memory_bytes: 14396
import java.util.*;

public class Main {
	final static long MODULO = 1_000_000_000 + 7;
	static ArrayList<Integer> divs;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long K = sc.nextLong();

		divs = new ArrayList<>();
		for (int i = 1; i * i <= N; ++i) {
			if (N % i == 0) {
				divs.add(i);
				if (i * i != N) {
					divs.add(N / i);
				}
			}
		}
		Collections.sort(divs);
		HashMap<Integer, Long> dp = new HashMap<>();
		for (int d : divs) {
			dp.put(d, pow(K, (d + 1) / 2));
			for (int i = 0; divs.get(i) < d; ++i) {
				if (d % divs.get(i) == 0)
					dp.put(d, (dp.get(d) - dp.get(divs.get(i)) + MODULO) % MODULO);
			}
		}

		long ans = 0;
		for (int d : divs) {
			ans = (ans + dp.get(d) * (d % 2 == 0 ? d / 2 : d)) % MODULO;
		}
		System.out.println(ans);
	}

	static class Div {
		int div;
		int num;

		public Div(int div, int num) {
			this.div = div;
			this.num = num;
		}
	}

	static long pow(long a, long n) {
		long ret = 1;
		for (; n > 0; n >>= 1, a = (a * a) % MODULO) {
			if (n % 2 == 1) {
				ret = (ret * a) % MODULO;
			}
		}
		return ret;
	}
}


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

using namespace std;

using int64 = long long;

int main() {
  int H, W;
  cin >> H >> W;
  string S[100];
  bool latte[100] = {}, malta[100] = {};
  for(int i = 0; i < H; i++) {
    cin >> S[i];
    for(int j = 0; j < W; j++) {
      if(S[i][j] == '#') {
        latte[i] = true;
        malta[j] = true;
      }
    }
  }
  for(int i = 0; i < H; i++) {
    bool output = false;
    for(int j = 0; j < W; j++) {
      if(latte[i] && malta[j]) {
        cout << S[i][j];
        output = true;
      }
    }
    if(output) cout << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  char S[50];
  scanf("%s", S);

  int ans = 1, num = 0;
  if(S[num] == 'A') num++;
  if(S[num++] != 'K') ans = 0;
  if(S[num++] != 'I') ans = 0;
  if(S[num++] != 'H') ans = 0;
  if(S[num] == 'A') num++;
  if(S[num++] != 'B') ans = 0;
  if(S[num] == 'A') num++;
  if(S[num++] != 'R') ans = 0;
  if(S[num] == 'A') num++;
  if(S[num++] != '\0') ans = 0;

  if(ans) printf("YES\n");
  else printf("NO\n");

  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll spf[1000005],hell=pow(10,9)+7,res;
map<ll,ll> m;
ll exp(ll x,ll y){
    ll res=1;
    x%=hell;
    while(y>0){
        if(y&1)
        res=(res*x)%hell;
        y>>=1;
        x=(x*x)%hell;
    }
    return res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    spf[1]=1;
    for(ll i=2;i*i<=1000000;i++)
    if(spf[i]==0){
        spf[i]=i;
        for(ll j=i*i;j<=1000000;j+=i)
        if(spf[j]==0)
        spf[j]=i;
    }
    for(ll i=1;i<=1000000;i++)
    if(spf[i]==0)
    spf[i]=i;
    ll n;
    cin>>n;
    for(ll i=0;i<n;i++){
        ll x;
        cin>>x;
        res+=exp(x,hell-2);
        res%=hell;
        map<ll,ll> st;
        while(x>1){
            if(st.find(spf[x])==st.end())
            st.insert({spf[x],0});
            st[spf[x]]++;
            x/=spf[x];
        }
        for(auto it=st.begin();it!=st.end();it++)
        if(m.find(it->first)==m.end())
        m.insert({it->first,it->second});
        else
        m[it->first]=max(m[it->first],it->second);
    }
    for(auto it=m.begin();it!=m.end();it++){
        res*=exp(it->first,it->second);
        res%=hell;
    }
    cout<<res;
} 


Measured memory_bytes: 8704
using System;

class main
{
    public static int n = 1000001;
    static void Main()
    {
        string s;
        int c, q;
        int[] p = new int[n];
        for (int i = 2; i < 1001; ++i)
            for (int j = i * 2; j < n; j += i)
                p[j] = 1;
        while ((s = Console.ReadLine()) != null)
        {
            c = int.Parse(s);
            q = 0;
            for (int i = 2; i <= c; ++i)
                if (p[i] != 1) ++q;
            Console.WriteLine("{0}", q);
        }
    }
}

Measured memory_bytes: 9536
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int abc[][] = new int[4][14];
		int i,x=0;
		for(i=0;i<n;i++) {
			String str=scan.next();
			if(str.equals("S")) {
				x=0;
			}
			else if(str.equals("H")) {
				x=1;
			}
			else if(str.equals("C")) {
				x=2;
			}
			else if(str.equals("D")) {
				x=3;
			}
			int y=scan.nextInt();
			abc[x][y]=1;
		}
		for(x=0;x<4;x++) {
			for(int y=1;y<14;y++) {
				if(abc[x][y] != 1) {
					if(x==0) {
						System.out.println("S "+y);
					}
					else if(x==1) {
						System.out.println("H "+y);
					}
					else if(x==2) {
						System.out.println("C "+y);
					}
					else if(x==3) {
						System.out.println("D "+y);
					}
				}
				
			}
		}
		scan.close();
}
}


Measured memory_bytes: 26240
import sys

def main():
  input = sys.stdin.readline
  N = int(input())
  ans = ''
  if N == 0:
    ans = '0'
  else:
    while N != 0:
      if N % 2 == 0:
        ans = '0' + ans
        N //= -2
      else:
        ans = '1' + ans
        N = (N - 1) // -2
  print(ans)


if __name__ == '__main__':
  main()

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

const int MAX = 1000000;
const int MOD = 1e9 + 7;

long long fact[MAX], fact_inv[MAX], inv[MAX];

void pre_calculation_combi() { // pre calculation of fact[], fact_inv[], inv[] for combination
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 1; i < MAX - 1; i++) {
        fact[i + 1] = fact[i] * (i + 1) % MOD;
        inv[i + 1] = MOD - inv[MOD % (i + 1)] * (MOD / (i + 1)) % MOD;
        fact_inv[i + 1] = fact_inv[i] * inv[i + 1] % MOD;
    }
}

long long combination_mod(int n, int k) { // return nCk % MOD using fact[] and fact_inv[]
    if (n < k) {
        return 0;
    } else if (n < 0 || k < 0) {
        return 0;
    } else {
        return ((fact[n] * fact_inv[k]) % MOD) * fact_inv[n - k] % MOD;
    }
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    llong X, Y;
    cin >> X >> Y;
    pre_calculation_combi();
    if ((X + Y) % 3 == 0) {
        // nCk
        llong n = (X + Y) / 3;
        if (X >= n && Y >= n) {
            llong k = X - n;
            cout << combination_mod(n, k) << endl;
            return 0;
        }
    }

    cout << 0 << endl;

    return 0;
}


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

int main()
{
    int N, A, break_flag, div_cnt, temp_cnt;
    cin >> N;

    break_flag = 0;
    div_cnt = 100000000;

    for (int i = 0; i < N; i++)
    {
        cin >> A;
        temp_cnt = 0;

        while ((A % 2) == 0){
            temp_cnt++;
            A /= 2;
        }

        if (temp_cnt < div_cnt)
            div_cnt = temp_cnt;
    }

    if (break_flag == 1)
        cout << 0 << endl;
    else
        cout << div_cnt << endl;
}

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

int main(){
  int a,b,c,d,x,y;
  cin >>a>>b>>c>>d;
  x = a*b;
  y = c*d;
  if(x>y){
    cout << x<<endl;
  }else if(x==y){
    cout <<y<<endl;
  }else{
    cout << y <<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <unordered_map>
#include <set>

using namespace std;

int main(int argc, char **argv)
{
    int N;
    cin >> N;
    string S[N];
    for (int i = 0; i < N; ++i) cin >> S[i];

    unordered_map<string, int> m;
    int maxApp = 0;
    for (int i = 0; i < N; ++i) {
        auto itr = m.find(S[i]);
        if (itr != m.end()) {
            int cur = ++m[S[i]];
            if (maxApp < cur) {
                maxApp = cur;
            }
        }
        else {
            m[S[i]] = 1;
            if (maxApp < 1) maxApp = 1;
        }
    }
    set<string> ans;
    for (int i = 0; i < N; ++i) {
        if (m[S[i]] == maxApp) {
            ans.insert(S[i]);
        }
    }
    for (auto itr = ans.begin(); itr != ans.end(); ++itr)
        cout << *itr << endl;

    return 0;
}


Measured memory_bytes: 35016
/*
  The Island Was Silent before.
  .....
  And One day again it became Silent.
*/
#include<bits/stdc++.h>
using namespace std;
 
#define endl '\n'
#define ll  long long
#define modd(a,b) ((a+2*b)%b)
#define debug(a) cout << #a << ": " << (a) << "\n"
#define ioso ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define rtt cerr << "Time: " << clock()*1.0 / CLOCKS_PER_SEC << endl;
#define ffe freopen("input.txt","r",stdin), freopen("output.txt","w",stdout);
ll hap[100010][3];
ll dp[100010][3];
ll pp(ll asi, ll nib) {
 // debug(asi); debug(nib);
  if(dp[asi][nib]!=-1) {
    return dp[asi][nib];
  }
  if(asi==0) {
    return dp[asi][nib] = hap[asi][nib];
  }
 
  ll mp = 0;
  ll kk = hap[asi][nib];
  for(int i=0;i<=2;i++) {

    if(i!=nib) {
      mp = max(mp,(pp(asi-1,i)+kk));
    }
  }
  return dp[asi][nib]=mp;
}

int main() {
  ioso
  #ifndef ONLINE_JUDGE
  ffe
  #endif

  ll n; cin >> n;
  ll a,b,c;
  memset(dp,-1,sizeof(dp));
  for(ll i=0;i<n;i++) {
    cin >> a >> b >> c;
    hap[i][0] = a;
    hap[i][1] = b;
    hap[i][2] = c;
  }
   memset(dp,-1,sizeof(dp));
  ll ans = pp(n-1,0);
 memset(dp,-1,sizeof(dp));
 ll ans1 = pp(n-1,1);
  memset(dp,-1,sizeof(dp));
 ll ans2=pp(n-1,2);
  //debug(pp(n-1,0));
  //debug(pp(n-1,1));
  //debug(pp(n-1,2));
  cout << max(ans,max(ans1,ans2)) << endl;
}

Measured memory_bytes: 14432
#include <stdio.h>

int main(){
	int i,A,B,C,D,L,day,x,y,ja,ma;
	scanf("%d\n",&L);
	scanf("%d\n",&A);
	scanf("%d\n",&B);
	scanf("%d\n",&C);
	scanf("%d\n",&D);
	ja=A/C;
	ma=B/D;
	x=A%C;
	y=B%D;
	if(x!=0){
		ja=ja+1;
	}
	if(y!=0){
		ma=ma+1;
	}
	if(ja>ma){
		L=L-ja;
	}else{
		L=L-ma;
	}
	printf("%d\n",L);
	return 0;
}

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

using namespace std;

#define REP(i,m) for(int i=0; i<m; i++)
#define FOR(i,n,m) for(int i=n; i<m; i++)
#define INF 1000000007
#define INFL (1LL << 60)
#define MOD 998244353
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

ll POW(ll a, ll b){
	if(b==0) return 1LL;
	if(b%2==1) return a*POW(a,b-1)%INF;
	return POW(a*a%INF, b/2);
}

int main(){
	ll n, m, k;
	cin >> n >> m >> k;
	ll ans = 0;
	REP(i, n){
		ans += (m*m*(n-i)*i)%INF;
		ans %= INF;
	}
	REP(i, m){
		ans += (n*n*(m-i)*i)%INF;
		ans %= INF;
	}
	FOR(i, n*m-k+1, n*m-1) (ans *= i) %= INF;
	FOR(i, 1, k-1) (ans *= POW(i, INF-2)) %= INF;
	cout << ans << endl;
	return 0;
} 


Measured memory_bytes: 256
from sys import stdin
input = stdin.readline

# map(int, input().rstrip().split())

def VI(N, init=0):
  return [init for _ in range(N)]
def VVI(N, M, init=0):
  return [[init for _ in range(M)] for _ in range(N)]

def VD(N, init=0.0):
  return [init for _ in range(N)]
def VVD(N, M, init=0.0):
  return [[init for _ in range(M)] for _ in range(N)]

N, M = map(int, input().rstrip().split())

A = VI(N)
B = VI(N)
C = VI(M)
D = VI(M)

for i in range(N):
  A[i], B[i] = map(int, input().rstrip().split())

for i in range(M):
  C[i], D[i] = map(int, input().rstrip().split())

INF = int(1e18)

ans = VI(N)
for i in range(N):
  a = A[i]
  b = B[i]
  ddist = INF
  for j in range(M):
    c = C[j]
    d = D[j]
    dist = abs(a-c)+abs(b-d)
    if (dist < ddist):
      ans[i] = j+1
      ddist = dist

for i in range(N):
  print(ans[i])


Measured memory_bytes: 39536
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
#define FOR(I,A,B) for(int I=int(A);I<int(B);++I)
#define FORR(I,A,B) for(int I=int(B-1);I>=int(A);--I)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int m,f,r;
	while(cin>>m>>f>>r,(m+f+r!=-3)){
		if(m==-1||f==-1){
			cout << 'F' << '\n';
		}else if(m+f>=80){
			cout << 'A' << '\n';
		}else if(m+f>=65){
			cout << 'B' << '\n';
		}else if(m+f>=50){
			cout << 'C' << '\n';
		}else if(m+f>=30){
			cout << (r>=50?'C':'D') << '\n';
		}else{
			cout << 'F' << '\n';
		}
	}
}



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

int main(){
	string w;
	cin >> w;
	string sam="abcdefghijklmnopqrstuvwxyz";
	vector<int> num(26);
	for(int i=0; i<w.size(); i++){
		for(int j=0; j<26; j++){
			if(w.at(i)==sam.at(j)){
				num.at(j)++;
			}
		}
	}
	bool judge=true;
	for(int i=0; i<26; i++){
		if(num.at(i)%2==1){
			judge=false;
			break;
		}
	}
	if(judge) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()
using namespace std;
using ll = long long;

struct unionfind {
  vector<int> A;
  int num;

  unionfind(int n) : A(n, -1), num(n) {}

  int find(int x) {
    if (A[x] < 0) return x;
    return A[x] = find(A[x]);
  }

  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (A[x] > A[y]) swap(x, y);
    A[x] += A[y];
    A[y] = x;
    num--;
  }

  int size(int x) {
    return -A[find(x)];
  }
};


int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> x(n), y(n);
  rep(i, n) cin >> x[i] >> y[i];
  int ans = 1e9;
  rep(i, n) rep(j, n) {
    int dy = y[j] - y[i];
    int dx = x[j] - x[i];
    unionfind uf(n);
    rep(k, n) rep(l, n) {
      int yy = y[l] - y[k];
      int xx = x[l] - x[k];
      if (yy == dy && xx == dx) {
        uf.unite(k, l);
      }
    }
    ans = min(ans, uf.num);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
a = []
gets.to_i.times do
  command, num1, num2 = gets.split.map(&:to_i)
  case command
  when 0
    num1 == 0 ? a.unshift(num2) : a.push(num2)
  when 1
    puts a[num1]
  else
    num1 == 0 ? a.shift : a.pop
  end
end


Measured memory_bytes: 11492
k,n = map(int,input().split())
if k %2 ==0:
  ans = []
  ans.append(k//2)
  for i in range(n-1):
    ans.append(k)
  print(*ans)
else:
  ans = []
  for i in range(n):
    ans.append(k//2+1)
  sage = (n)//2
  for i in range(sage):
    if ans[-1] == 1:
      ans.pop()
    else:
      ans[-1] -= 1
      while len(ans) < n:
        ans.append(k)
  print(*ans)

Measured memory_bytes: 72944
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))
#define sz(v) ((LLI)(v).size())

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

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

  string s;
  while(cin >> s){
    sort(ALL(s));
    if(s[0] == s[1] and s[2] == s[3] and s[1] != s[2]){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
    
  }

  
  return 0;
}


Measured memory_bytes: 256
package main

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

func chmin(a *int, b int) bool {
	if *a > b {
		*a = b
		return true
	}
	return false
}

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	var n, w int
	inputLine := strings.Split(newLine(), " ")
	n, _ = strconv.Atoi(inputLine[0])
	w, _ = strconv.Atoi(inputLine[1])

	dp := make([][]int, n+1)
	for i := 0; i < n+1; i++ {
		dp[i] = make([]int, 1000*(n+1))
		dp[i][0] = 0
		for j := 1; j < 1000*(n+1); j++ {
			dp[i][j] = math.MaxInt32
		}
	}

	var weight, value int
	for i := 1; i < n+1; i++ {
		inputLine = strings.Split(newLine(), " ")
		weight, _ = strconv.Atoi(inputLine[0])
		value, _ = strconv.Atoi(inputLine[1])
		for j := 0; j < 1000*(n+1); j++ {
			chmin(&dp[i][j], dp[i-1][j])
			if j-value >= 0 {
				chmin(&dp[i][j], dp[i-1][j-value]+weight)
			}
		}
		//fmt.Println(dp[i][30])
	}
	for i := len(dp[n]) - 1; i >= 0; i-- {
		if dp[n][i] <= w {
			fmt.Println(i)
			return
		}
	}
	fmt.Println(0)
}


Measured memory_bytes: 83200
# coding: utf-8
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a1 = sorted(a)
b1 = sorted(b)
z = [list(map(int, input().split())) for _ in range(M)]

num1 = a1[0] + b1[0]
# print("num1:", num1)
for i in range(M):
    x, y, c = z[i]
    num = a[x - 1] + b[y - 1] - c
    if num < num1:
        num1 = num
print(num1)


Measured memory_bytes: 40096
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <ctype.h>
#include <assert.h>

using namespace std;
typedef long long ll;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define DEC(i, s) for (int i = (s); i >= 0; i--)

#define SIZE(v) (int)((v).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define FIND(m, w) ((m).find(w) != (m).end())

int P, Q, R;
char str[10000];

int parse(int &index) {
  char c = str[index++];
  if (isdigit(c)) { return c - '0'; }
  if (isalpha(c)) {
    if (c == 'P') { return P; }
    if (c == 'Q') { return Q; }
    if (c == 'R') { return R; }
    assert(false);
  }
  if (c == '-') {
    int ans = parse(index);
    if (ans == 0) { return 2; }
    if (ans == 1) { return 1; }
    if (ans == 2) { return 0; }
    assert(false);
  }
  assert(c == '(');
  int l, r;
  l = parse(index);
  char o = str[index++];
  r = parse(index);
  assert(str[index] == ')');
  index++;
  if (o == '+') {
    if (l == 2 || r == 2) { return 2; }
    if (l == 1 || r == 1) { return 1; }
    if (l == 0 || r == 0) { return 0; }
    assert(false);
  } else if (o == '*') {
    if (l == 0 || r == 0) { return 0; }
    if (l == 1 || r == 1) { return 1; }
    if (r == 2 || r == 2) { return 2; }
    assert(false);
  }
  return 0;
}

int main() {
  while (fgets(str, 9999, stdin), str[0] != '.') {
    int ans = 0;
    REP(P, 3) REP(Q,3) REP(R, 3) {
      int index = 0;
      if (parse(index) == 2) { ans++; }
    }
    printf("%d\n", ans);
  }
}

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

using namespace std ;

#define IOS ios::sync_with_stdio(0); cin.tie(0), cout.tie(0)
#define ll long long int 

#define fr first
#define se second

#define all(v) v.begin(),v.end() 
#define rall(v) v.rbegin(),v.rend()
#define sz(v) v.size() 

#define pb push_back
#define mp make_pair 

#define PI 3.141592653589793238



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


//bool valid(int x, int y){return x > 0 && x < 9 && y > 0 && y < 9;}

int cntr = -1, a[11], b[11];
string s;
int main(){
  cin >> s;
  int n = (int)sz(s);
  for(int i = 0 ; i < n ; i++)
    if(s[i] == 'A' || s[i] == 'T' || s[i] == 'C' || s[i] == 'G')
      a[i] = 1;
  for(int i = 0 ; i < n ; i++){
    if(a[i] == 1){
      if(i)
        b[i] = b[i-1] + a[i];
      else
        b[i] = a[i];
    }
    else
      b[i] = 0;
  }
  cout << *max_element(b,b+11);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstdlib>
#include <stack>
#include <queue>
#include <valarray>
#include <utility>

using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define REP2(i,m,n) for(int i=m+1;i<=(int)(n);i++)
#define REP3(i,m,n) for(int i=m;i<=(int)(n);i++)
#define INF 2000000000
#define INFLL 9000000000000000000
#define MOD 1000000007

typedef long long int ll;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << ((b - a == c - b) ? "YES" : "NO") << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
struct node
{
	int key;
	struct node *parent;
	struct node *left;
	struct node *right;
};
char com[500010][10];
int x[500010];
struct node *root;
void insert(int z)
{
	struct node *v;
	if(!root)
	{
		v=(struct node *)malloc(sizeof(struct node));
		v->key=z;
		v->left=v->parent=v->right=NULL;
		root=v;
		return;
	}
	struct node *x,*y;
	y=NULL;
	x=root;
	while(x!=NULL)
	{
		y=x;
		if(z<x->key)
			x=x->left;
		else
			x=x->right;
	}
	v=(struct node *)malloc(sizeof(struct node));
	v->left=v->parent=v->right=NULL;
	v->key=z;
	v->parent=y;
	if(z<y->key)
		y->left=v;
	else
		y->right=v;
	return;
}
void inorder(struct node *u)
{
	if(!u)
		return;
	inorder(u->left);
	printf(" %d",u->key);
	inorder(u->right);
	return;
}
void preorder(struct node *u)
{
	if(!u)
		return;
	printf(" %d",u->key);
	preorder(u->left);
	preorder(u->right);
	return;
}
int main()
{
	int n,i;
	
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%s",com[i]);
		if(strcmp(com[i],"insert")==0)
			scanf("%d",&x[i]);
	}
	for(i=1;i<=n;i++)
	{
		if(strcmp(com[i],"insert")==0)
			insert(x[i]);
		if(strcmp(com[i],"print")==0)
		{
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}
	return 0;
}


Measured memory_bytes: 32024
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    List<int>[] G;
    bool[] us;
    List<int> P;
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.WriteLine(sb.ToString());
    }
    void Calc(){
        string[] str = Console.ReadLine().Split(' ');
        int N = int.Parse(str[0]);
        int M = int.Parse(str[1]);
        G = new List<int>[N];
        for(int i=0;i<N;i++){
            G[i] = new List<int>();
        }
        for(int i=0;i<M;i++){
            str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0])-1;
            int b = int.Parse(str[1])-1;
            G[a].Add(b);
            G[b].Add(a);
        }
        int count = 1;
        us = new bool[N];
        P = new List<int>();
        dfs(0);
        for(int i=P.Count-1;i>=0;i--){
            sb.Append((P[i]+1)+" ");
            count++;
        }
        sb.Append("1 ");
        P = new List<int>();
        dfs(0);
        for(int i=0;i<P.Count;i++){
            sb.Append((P[i]+1)+" ");
            count++;
        }
        Console.Write(count+"\n");
    }
    void dfs(int v){
        us[v] = true;
        for(int i=0;i<G[v].Count;i++){
            int t = G[v][i];
            if(!us[t]){
                P.Add(t);
                dfs(t);
                break;
            }
        }
    }
}

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

using namespace std;


int a,b,c;

typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<double> vdb;
typedef vector<bool> vbol;
typedef vector<string> vstr;

#define vvll(a,b,c) vector<vector<long long>> c(a,vector<long long>(b,0))
#define vvit(a,b,c) vector<vector<int>> c(a,vector<int>(b,0))
#define vvstr(a,b,c) vector<vector<string>> c(a,vector<string>(b,0))
#define vvbol(a,b,c) vector<vector<bool>> c(a,vector<bool>(b,0))
#define vvdb(a,b,c) vector<vector<double>> c(a,vector<double>(b,0))
#define fi(a,b) for(int i=a;i<b;i++)
#define fj(a,b) for(int j=a;j<b;j++)
#define f_i(a,b) for(int i=0;i<=b;i++)
#define f_j(a,b) for(int j=0;j<=b;j++)


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

    int a,b;
    cin >> a >> b;
    cout << max(a+b,max(a-b,a*b))  << endl;
    return(0);

}

Measured memory_bytes: 3600
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T>using vv = vector<vector<T>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 28, MOD = 1e9 + 7; constexpr ll LINF = 1ll << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int main() {
    ll K;
    cin >> K;

    deque<pair<ll, int>> dq;
    dq.emplace_front(1, 1);
    vector<bool> visited(K);    
    int ans = INF;
    while (!dq.empty()) {
        ll n = dq.front().first;
        int sum = dq.front().second;
        dq.pop_front();
        visited[n] = true;

        if (n % K == 0) {
            ans = sum;
            break;
        }

        if (!visited[n + 1]) {
            dq.emplace_back(n + 1, sum + 1);
        }
        if (!visited[n * 10 % K]) {
            dq.emplace_front(n * 10 % K, sum);
        }
    }

    write(ans);
}

Measured memory_bytes: 1408
import java.util.Scanner;
 
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s1 = sc.next();
    String s2 = sc.next();
    String s3 = sc.next();
    s1 = s1.toUpperCase();
    s2 = s2.toUpperCase();
    s3 = s3.toUpperCase();
    
    System.out.print(s1.charAt(0));
    System.out.print(s2.charAt(0));
    System.out.print(s3.charAt(0));
  }
}

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

int main() {
  int N,count;
  count=0;
  cin>>N;
  vector<string>vec(N);
  vector<int>time(N);
  for(int i=0;i<N;i++){
    string s;
    int a;
    cin>>s>>a;
    vec.at(i)=s;
    time.at(i)=a;
  }
  string last;
  cin>>last;
  for(int i=0;i<N-1;i++){
    if(vec.at(i)==last){
      for(int j=i+1;j<N;j++){
        count+=time.at(j);
      }
    }
  }
  cout<<count<<endl;
  
      
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
 public static void main(String[] args){
    
    Scanner s=new Scanner(System.in);
    
    int A=s.nextInt();
    int B=s.nextInt();
    int C=s.nextInt();
    int m=0;
    
    if(A+B-C>=0)System.out.print(B+C);
    else{
     m=C-(B+A);
     System.out.print(B+C-m+1);
    }
  }
}

Measured memory_bytes: 21844
//JSD
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[n];
	vector<int > v;
	int count=0;
	for(int i=0;i<n;i++) {
		cin>>a[i];
		if(a[i]!=(i+1)) count++,v.push_back(i);
	}
	if(count>2){
		cout<<"NO\n";	
	}
	else{
		cout<<"YES\n";
	}
}


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

int main(){
    ll S;  cin >> S;
    int n = log10(S) + 1;
    ll ans = 0;
    for(int i=0; i<pow(2,n-1); i++){
        ll S_memo = S;
        ll tmp = i;
        ll base = 1;
        for(int j=0; j<n-1; j++){
            ans += (S_memo%10)*base;
            if(tmp%2==0) base*=10;
            else base = 1;
            tmp/=2;
            S_memo/=10;
        }
        ans += (S_memo%10)*base;
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

int main(){
  string s;
  cin>>s;
  string t = "keyence";

  bool ok = false;
  int n = s.size();
  rep(i,n) rep(j,i,n){
    string u = s.substr(0,i) + s.substr(j);
    if(t == u) ok = true;
  }

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

  return 0;
}


Measured memory_bytes: 256
x = int(input())

n1 = 0
while True:
    x = x - 500
    if x < 0:
        x += 500
        break
    else:
        n1 += 1

n2 = 0
while True:
    x = x - 5
    if x < 0:
        x += 5
        break
    else:
        n2 += 1

print(n1*1000 + n2*5)

Measured memory_bytes: 3060