akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int A = int.Parse(str[0]);
		int B = int.Parse(str[1]);
		int K = int.Parse(str[2]);
		for(var i=0;i<K;i++){
			if(i%2==0){
				A = A/2*2;
				int C = A/2;
				A -= C;
				B += C;
			} else {
				B = B/2*2;
				int C = B/2;
				B -= C;
				A += C;
			}
		}
		Console.WriteLine(A+" "+B);
	}
}

Measured memory_bytes: 11220
n = int(input())
li = []
ans_li = []
d = {}
for i in range(n):
    buf = list(input())
    li.append("".join(sorted(buf)))
 
for i in range(ord('a'),ord('z')+1):
    tmp = chr(i)
    d[tmp] = 10**5
 
for i in range(n):
    for j in range(ord('a'),ord('z')+1):
        tmp = chr(j)
        if li[i].count(tmp) < d[tmp]:
            d[tmp] = li[i].count(tmp)
 
for kk in d.keys():
    if d[kk] != 0:
        for i in range(d[kk]):
            ans_li.append(kk)
 
print("".join(sorted(ans_li)))



Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <map>
#include <utility>
#include <list>
#include <string>

using namespace std;

int main() {
    string s;
    cin >> s;

    int near = 10000;
    for (int i=0; i < s.length() - 2; i++){
        int a, b, c;
        char t;

        t = s[i];
        a = t - 48;
        b = s[i + 1] - 48;
        c = s[i + 2] - 48;
        int d = a * 100 + b * 10 + c;
        if (abs(d - 753) < near) {
            near = abs(d - 753);
        }
    }
    cout << near << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
import java.util.TreeMap;

public class Main{

    public static void main(String[] args) {

	Scanner sc = new Scanner(System.in);

	TreeMap<String, List<Integer>> index = new TreeMap<>();
	// ??\?????????????´??????¨????????¨????????¨?????????
	while (sc.hasNextLine()) {
	    String[] input = sc.nextLine().split(" ");
	    if ("".equals(input[0])) {
		break;
	    }
	    String name = input[0];
	    Integer page = Integer.parseInt(input[1]);

	    if ("".equals(name)) {
		break;
	    }

	    if (index.containsKey(name)) {
		index.get(name).add(page);
	    } else {
		List<Integer> newInt = new ArrayList<>();
		newInt.add(page);
		index.put(name, newInt);
	    }

	}

	// ????????????????????????????????¨??????
	for (String name : index.keySet()) {
	    Collections.sort(index.get(name));
	    System.out.println(name);
	    StringBuilder sb = new StringBuilder();

	    for (Integer page : index.get(name)) {
		sb.append(page.toString());
		sb.append(" ");
	    }
	    System.out.println(sb.deleteCharAt(sb.length() - 1));
	}

    }
}

Measured memory_bytes: 26340
import sys
n=int(input())
l=[0]*(n+1)
for i in range(n):
    l[i]=int(input())
    if l[i]>i:print(-1);sys.exit()
for i in range(n):
    if l[i]-l[i-1]>=2:print(-1);sys.exit()
ans=0
for i in range(n+1):
    if l[i]<=l[i-1]:
        ans+=l[i-1]
print(ans)


Measured memory_bytes: 11892
package main

import (
	"fmt"
)

func main() {
	var (
		n int
	)

	fmt.Scan(&n)
	d := make([]int, n)
	m := make(map[int]bool)

	for i := 0; i < n; i++ {
		fmt.Scan(&d[i])
		m[d[i]] = true
	}

	fmt.Println(len(m))
}


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

ll N, A, B;
vector<ll> h;

bool enough(int T) {
  ll res = 0;
  ll diff = A - B;
  for (auto&& x : h) {
    res += (max(0LL, x - B * T) + diff - 1) / diff;
  }
  return res <= T;
}

int main() {
  cin >> N >> A >> B;
  h = vector<ll>(N);
  for (int i = 0; i < N; ++i) cin >> h[i];

  int ng = 0;
  int ok = 1e9;
  while (ok - ng > 1) {
    int m = (ok + ng) / 2;
    ( (enough(m)) ? ok : ng ) = m;
  }
  cout << ok << endl;
  return 0;
}


Measured memory_bytes: 1024
import java.io.PrintWriter
val pw = PrintWriter(System.out)
fun main(args: Array<String>) {
    func()
    pw.flush()
}
fun println(value: Any) { pw.println(value) }

data class Restrant(val city: String, val point: Int, val index: Int): Comparable<Restrant> {
    override operator fun compareTo(other: Restrant): Int =
            when {
                this.city != other.city -> this.city.compareTo(other.city)
                this.point != other.point -> other.point - this.point
                else -> 0
            }
}

fun func() {
    val N = nextInt()
    val A: MutableList<Restrant> = arrayListOf()
    for (n in 0 until N) {
        val (s, p) = listOfString();
        A.add(Restrant(s, p.toInt(), n + 1))
    }
    A.sort()
    for (n in 0 until N) {
        println(A[n].index)
    }

}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")


Measured memory_bytes: 38040
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <vector>
using ll = long long;
using namespace std;
#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 < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

int main() {
    int x;
    for(int i = 1;; i++) {
        cin >> x;
        if(!x)
            break;
        cout << "Case " << i << ": " << x << endl;
    }
}


Measured memory_bytes: 3008
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(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 llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

/*
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}
*/

#define ARRAY_MAX 100005
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

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




/******************************************************************************************/



int main() {

	
	ll n, cnt = 0;
	cin >> n;
	vector<ll> a(n + 10), b(n + 10);
	for (int i = 0; i < n+1; i++)
	{
		cin >> a[i];
	}

	for (int i = 0; i < n; i++)
	{
		cin >> b[i];
	}


	ll ans = 0;
	for (int i = 0; i < n; i++)
	{
		ll mini = min(a[i], b[i]);
		ans += mini;
		a[i] -= mini;
		b[i] -= mini;

		mini = min(a[i+1], b[i]);
		ans += mini;
		a[i+1] -= mini;
		b[i] -= mini;
	}
	cout << ans << endl;



	return 0;
}


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

#define ll long long

// ll fact(int n){
// 	ll f=1;
// 	for (int i = 2; i <= n; ++i)
// 	{
// 		/* code */
// 		f*=i;
// 	}
// 	return f;
// }

int main(){
	int n;
	cin>>n;
	ll arr[n];
	for (int i = 0; i < n; ++i)
	{
		/* code */
		cin>>arr[i];
	}
	int max=0,j;
	for (int i = 0; i < n-1; ++i)
	{
		/* code */
		int c=0;
		for (j = i; j < n-1; ++j)
		{
			/* code */
			if(arr[j+1]<=arr[j])
			c++;
		else{
			break;
		}
		}
		if(c>max){
			max=c;
		}
		i=j;
	}
	cout<<max<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
#define rep(i,n) for(i=0;i<n;i++)
#define repl(k,n) for(k=0;k<n;++k)

int main() {
	int N;
	int K;
	int ans=0;
	cin >> N >> K;
	vector<int> p(N);
	int i;
	rep(i, N) {
		cin >> p[i]; 
	}
	sort(p.begin(), p.end());
	rep(i, K) {
		ans = ans + p[i];
	}
	cout << ans;
	return 0;
}

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;

const ll INF=1LL<<60;
const int MOD=1e9+7;

int N;

void dfs(string &S, int N, int val){
    if(N == 0){
        cout << S << endl;
        return;
    }
    for(int i=0; i<=val; i++){
        S.push_back(i+'a');
        dfs(S, N-1, i==val ? i+1:val);
        S.pop_back();
    }
}

int main(){
    cin >> N;
    string S="";
    dfs(S, N, 0);
    return 0;
}

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

using namespace std;
#define ll long long
int main()
{
int n;
cin>>n;
int arr[n];

for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        if(arr[i]%2==0)
        {
            if(arr[i]%3==0 || arr[i]%5==0 )
                continue;
            else
                return cout<<"DENIED",0;
        }
    }
    cout<<"APPROVED"<<endl;
    return 0;
}


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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    
    int ans;
    if(b/a>c) ans = c;
    else ans = b/a;

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<time.h>
#include<string>
#include<cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<stack>
#include<set>
#include <limits>
#include <climits>
#include <numeric>
#include<cassert>
#include<cctype>
#include<iterator>
#include<unordered_map>
#include <cassert>
#include <bit>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=c_max(x,a)
#define chmin(x,a) x=c_min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
const int MOD = 1000000007;
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
#define greater greater<int>()
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
using Edge=pair<int,ll>;
using Graph=vector<vector<ll> >;//ll or Edge
using Edge=pair<int,ll>;
//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// g++ -o a a.cpp -Wall -lm -std=c++17
int main(){
    ll n,k;cin>>n>>k;
    string S;cin>>S;
    int a=0;
    rep(i,n-1){
        if(S[i]!=S[i+1])a++;
    }
    cout<<n-1-max(a-2*k,0LL)<<endl;
}

Measured memory_bytes: 3744
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.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 int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.exe



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


int a,b,p,m,k,ans;
cin >> a >> b;
p = a+b;
m = a-b;
k = a*b;

if (p >= m && p >= k)
{
    cout << p << endl;
}else if (m >= p && m >= k)
{
    cout << m << endl;
}else
{
    cout << k << endl;
}










//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        List<Long> x = new ArrayList<>();
        List<Long> y = new ArrayList<>();
        List<Long> z = new ArrayList<>();
        for(int i = 0;i < n;i++){
            x.add(sc.nextLong());
            y.add(sc.nextLong());
            z.add(sc.nextLong());
        }
        List<Long> w = new ArrayList<>();;
        w.add(-1L);
        w.add(1L);
        long max = 0;
        for(Long it1 : w){
            for(Long it2 : w){
                for(Long it3 : w){
                    List<Long> sum = new ArrayList<>();;
                    for(int i = 0;i < n;i++){
                        long total = it1*x.get(i) + it2*y.get(i) + it3*z.get(i);
                        sum.add(total);
                    }
                    //System.out.printf("w1 = %d,w2 = %d,w3 = %d\n",it1,it2,it3);
                    //System.out.println("sum = " + sum);
                    //System.out.println("sum = " + sum);
                    max = Math.max(max,solve(sum,m));
                }
            }
        }
        System.out.println(max);
    }
    public static long solve(List<Long> sum,int k){
        Collections.sort(sum,Collections.reverseOrder());
        long max = 0;
        for(int i = 0;i < k;i++){
           max += sum.get(i);
        }
        //System.out.println(max);
        return max;
    }
}


Measured memory_bytes: 27672
# -*- coding: utf-8 -*-

from queue import Queue
import sys
import subprocess
import json
import time
import math
import re
#import sqlite3
import random
import numpy as np
#from sklearn.datasets import fetch_mldata
from statistics import mean, median, variance, stdev
#from chainer import cuda, Variable, FunctionSet, optimizers
#import chainer.functions  as F

def ans():
    remain = X - Y - 2 * Z
    if (remain < 0): return 0
    return 1 + remain // (Y + Z)
    

X, Y, Z = map(int, input().split())
print(ans())

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

int main(void){
	int n,k,cnt[200100],a,ans=0,i;
	fill(cnt,cnt+200100,0);
	cin >> n >> k;
	for(i=0; i<n; i++){
		cin >> a;
		a--;
		cnt[a]++;
	}
	sort(cnt,cnt+n);
	for(i=0; i<(n-k); i++){
		ans += cnt[i];
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

using ll = long long;

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

    int n;
    cin >> n;

    map<int, int> cnt;
    for (int i = 0, a; i < n; ++i) {
        cin >> a;
        ++cnt[a];
    }

    int num = 0;
    for (const auto &it: cnt) {
        if (it.first <= it.second) num += it.second - it.first;
        else num += it.second;
    }

    cout << num << endl;

    return 0;
}


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

int main(){
  int64_t N;
  cin >> N;
  if(N%2==1){
    vector<int64_t> A(N), B(N), sA(N), sB(N);
    for(int64_t i=0; i<N; i++){
      cin >> A.at(i) >> B.at(i);
      sA.at(i)=A.at(i);
      sB.at(i)=B.at(i);
    }
    sort(sA.begin(), sA.end());
    sort(sB.begin(), sB.end());
    cout << sB.at(N/2)-sA.at(N/2)+1 << endl;
  }
  else{
    vector<int64_t> A(N), B(N), sA(N), sB(N);
    for(int64_t i=0; i<N; i++){
      cin >> A.at(i) >> B.at(i);
      sA.at(i)=A.at(i);
      sB.at(i)=B.at(i);
    }
    sort(sA.begin(), sA.end());
    sort(sB.begin(), sB.end());
    cout << sB.at(N/2-1)+sB.at(N/2)-sA.at(N/2-1)-sA.at(N/2)+1 << endl;
  }
}

Measured memory_bytes: 9596
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int N,K,Q;
    scanf("%d",&N);
    scanf("%d",&K);
    scanf("%d",&Q);

    int A[Q];
    for(int i=0;i<Q;i++){
        int tmp;
        scanf("%d",&tmp);
        A[i] = tmp - 1; 
    }

    int answer[N];
    for(int i=0;i<N;i++){
        answer[i] = K - Q;
    }

    for(int i=0;i<Q;i++){
        answer[A[i]] += 1;
    }

    for(int i=0;i<N;i++){
        if(answer[i] <= 0){
            printf("%s\n", "No");
        }else{
            printf("%s\n", "Yes");
        }
    }
    return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void){
    ll A,B,C,K;
    cin >> A >> B >> C >> K;
    ll ans;
    if(K<A){
        ans=K;
    }else if(K<=A+B){
        ans=A;
    }else{
        ans=A-(K-A-B);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static long INF = 1L << 60;
	static long[] h = new long [100010];
	static long[] dp = new long [100100];
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());
		for(int i=0;i<n;i++)h[i] = Long.parseLong(sc.next());
		sc.close();
		//初期化(INF)
		Arrays.fill(dp,INF);
		dp[0] = 0;

		for(int i=1;i<n;i++) {
			 for (int j = 1; j <= k&&j<=i; j++) {
				 	dp[i]=Math.min(dp[i], dp[i-j] + Math.abs(h[i] - h[i - j]));
		        }
		}
		System.out.println(dp[n-1]);

	}

}



Measured memory_bytes: 46984
// WeirdBugsButOkay

# include <bits/stdc++.h>

# define ll long long
# define ld long double
# define pii pair <int,int>
# define pll pair <ll,ll>
# define mp make_pair
# define pb push_back
# define ff first
# define ss second
# define endl '\n'

using namespace std;

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

void solve()
{
    ll s, w;
    cin >> s >> w;
    if(s <= w)
        cout << "unsafe" << endl;
    else cout << "safe" << endl;
}

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll q = 1;
    //cin >> q;
    for(ll i = 0; i < q; i++)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i,N)
  {
    cin >> A[i];
  }
  vector<int> vec(N);
  rep(i,N)
  {
    vec[i] = A[i];
  }
  sort(RALL(vec));
  rep(i,N)
  {
    if(A[i]==vec[0])
    {
      cout << vec[1] << endl;
    }
    else
    {
      cout << vec[0] << endl;
    }
    
  }
  return 0;
}


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

using namespace std;

typedef pair<int, int> II;
typedef pair<long long, int> LLI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<II> VII;

#define For(i,a,b) for(int i = a;i <= b; i++)
#define Rep(i,a,b) for(int i = a;i >= b; i--)
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, f) for(auto i : f)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define BUG(x) (cerr << #x << " = " << x << "\n")
#define ARRAY(f) {cerr << #f << " = "; FOR(i, f) cout << i << ' '; cout << "\n";}
#define sz(s) int(s.size())
#define reset(f, x) memset(f, x, sizeof(f))
#define all(x) x.begin(), x.end()
#define two(x) (1LL << x)
#define getbit(x, i) ((x >> (i)) & 1LL)
#define onbit(x, i) (x | (1LL << (i)))
#define offbit(x, i) (x & ~(1 << (i)))

const int N = 2e5 + 1;

int n, a[N];
LL s[N];
int f[N], g[N];

LL sum(int i, int j) {
    if (i > j) return 0;
    return s[j] - s[i-1];
}

int main() {
    ios_base::sync_with_stdio(false);
    srand(time(NULL));
    #ifndef ONLINE_JUDGE
        //freopen("in.txt","r",stdin);
        //freopen("","w",stdout);
    #endif
    cin >> n;
    For(i, 1, n) cin >> a[i];
    For(i, 1, n) {
        s[i] = s[i-1] + a[i];
        f[i] = f[i-1];
        while (f[i] < i-1 && abs(2LL*s[f[i]] - s[i]) > abs(2LL*s[f[i]+1])-s[i]) f[i]++;
    }
    g[n+1] = n+1;
    Rep(i, n, 1) {
        s[i] = s[i+1] + a[i];
        g[i] = g[i+1];
        while (g[i] > i+1 && abs(2LL*s[g[i]] - s[i]) > abs(2LL*s[g[i]-1] - s[i])) g[i]--;
    }
    For(i, 1, n) s[i] = s[i-1] + a[i];
    //For(i, 1, n) cout << f[i] << ' '; cout << "\n";
    //For(i, 1, n) cout << g[i] << ' '; cout << "\n";
    LL res = 1e18;
    For(j, 2, n-1) {
        int i = f[j], k = g[j+1]-1;
        LL MAX = max(s[i], s[j]-s[i]), MIN = min(s[i], s[j]-s[i]);
        MAX = max(MAX, max(sum(j+1, k), sum(k+1, n)));
        MIN = min(MIN, min(sum(j+1, k), sum(k+1, n)));
        res = min(res, MAX-MIN);
    }
    cout << res << "\n";
}




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

using namespace std;
typedef long long nagai;

int main()
{
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<nagai> a(n), b(n);
	for (auto& x : a)
		cin >> x;
	for (auto& x : b)
		cin >> x;
	nagai ansich = 0;
	for (int i = 0; i < 31; ++i)
	{
		nagai ans = 0;
		vector<nagai> bs;
		for (nagai x : b)
			bs.push_back(x & (1LL << (i + 1)) - 1);
		sort(bs.begin(), bs.end());
		auto get = [&](nagai l, nagai r)
		{
			return lower_bound(bs.begin(), bs.end(), r) - lower_bound(bs.begin(), bs.end(), l);
		};
		for (nagai x : a)
		{
			x &= (1LL << (i + 1)) - 1;
			ans += get((1LL << i) - x, (1LL << i + 1) - x);
			ans += get((1LL << i + 1) + (1LL << i) - x, 1LL << 40);
		}
		ans &= 1;
		ansich ^= ans << i;
	}
	cout << ansich << '\n';
}


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

int main(){
  string S;
  cin >> S;
  bool ans = true;
  char x=S[0];
  for(int i=1; i<S.size(); i++){
    if(S[i]==x){ans=false;break;}
    x = S[i];
  }
  if(ans)cout << "Good" << endl;
  if(!ans)cout << "Bad" <<endl;
  return 0;
}

Measured memory_bytes: 384
N = int(input())
S = input()

flg = True
if N%2 == 0:
    for i in range(N//2):
        if S[i] != S[i+N//2]:
            flg = False
            break
else:
    flg = False
    
if flg:
    print("Yes")
else:
    print("No")

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

int main() {
    int n, m;
    cin >> n >> m;
    string r(n, 'a');
    for(int i = 0; i < m; i++) {
        int s, c;
        cin >> s >> c;
        if(n != 1 && s == 1 && !c || r[s - 1] != 'a' && r[s - 1] != c + '0') {
            cout << -1 << endl;
            return 0;
        }
        r[s - 1] = c + '0';
    }
    for(int i = 0; i < n; i++)
        if(r[i] == 'a')
            r[i] = n > 1 ? !i + '0' : '0';
    cout << r << endl;
    return 0;
}


Measured memory_bytes: 256
def main():
    # s = int(input())
    # n, k = map(int, input().split())
    # h = list(map(int, input().split()))
    # s = input()

    a = int(input())
    b = int(input())
    c = int(input())
    d = int(input())
    e = int(input())

    total = 0
    li = [a, b, c, d, e]
    mini = 10**10
    ans_idx = 0
    for i, s in enumerate(li):
        last_s = int(str(s)[-1])
        if mini > last_s and last_s != 0:
            mini = last_s
            ans_idx = i

    for i, s in enumerate(li):
        if i != ans_idx:
            if s % 10 != 0:
                total += s // 10 * 10 + 10
            else:
                total += s
        else:
            total += s

    print(total)


if __name__ == '__main__':
    main()


Measured memory_bytes: 62040
N = int(input())

W = []
Se = set()
for i in range(N):
  st = input()
  W.append(st)
  Se.add(st)
  
if len(Se) != N:
  print("No")
  exit(0)

for i in range(N-1):
  if W[i][-1] != W[i+1][0]:
    print("No")
    exit(0)

print("Yes")

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

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v.at(i);
  }
  bool b = true;
  int c = 0;
  while (b) {
    for (int i = 0; i < n; i++) {
      if (v.at(i) % 2 != 0) b = false;
      v.at(i) /= 2;
    }
    c++;
  }
  cout << c - 1 << endl;
}

Measured memory_bytes: 256
import * as fs from "fs";

// inputで受け取り配列化する
const input = fs.readFileSync("/dev/stdin", "utf8").split("\n");
const N = Number(input.shift());
const h = input.map((row) => row.split(" ").map(Number));

const createZeroArray = () => Array(3).fill(0).slice(0, 3);

const dp = [];

for (let n = 0; n < N; n++) {
  const arr = [];
  for (let num = 0; num < 3; num++) {
    arr.push(0);
  }
  dp.push(arr);
}

for (let index = 0; index < 3; index++) {
  dp[0][index] = h[0][index];
}

// present day
for (let i = 1; i < N; i++) {
  // previous select
  for (let j = 0; j < 3; j++) {
    // today's select
    for (let k = 0; k < 3; k++) {
      if (j === k) continue;
      dp[i][k] = Math.max(dp[i][k], dp[i - 1][j] + h[i][k]);
    }
  }
}

console.log(Math.max(...dp[N - 1]));


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

using namespace std;

typedef long long ll;

ll n;

int main(){
	//freopen("input.txt","r",stdin);
	cin >> n;
	ll ans = n/11 * 2 ;
	n -= ans/2 * 11;
	if(n >= 6){
		n -= 6;
		ans++;
	}
	if(n >= 1){
		n = 0;
		ans++;
	}
	cout << ans << endl;;
	return 0;
}

Measured memory_bytes: 384
#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

void Main() {
    double N, K;
    cin >> N >> K;
    double ans = 0;
    rep2(i, 1, N + 1) {
        double p = 1.0 / N;
        if (i >= K) {
            ans += p;
        } else {
            double cnt = ceil(log2(K / i));
            ans += p * pow(0.5, cnt);
        }
    }
    cout << ans << '\n';
}

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


Measured memory_bytes: 384
import java.util.*;
public class Main {
    static int MOD = 1000000007;
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		//String tmp = sc.next();
		//int tmp = sc.nextInt();
		//Long tmp = sc.nextLong();
      Long add = new Long(0);
      int N = sc.nextInt();
      ArrayList<Long> aList = new ArrayList<Long>(N);
      ArrayList<Long> bList = new ArrayList<Long>(N);
      while(sc.hasNext()){
        aList.add(sc.nextLong());
        bList.add(sc.nextLong());
      }
      for(int i = N - 1; i >= 0; i--){
        Long tmpA = aList.get(i) + add;
        Long tmpB = bList.get(i);
        //System.out.println(tmpA + " " + tmpB);
        add += (tmpB - (tmpA % tmpB)) % tmpB;
      }
      System.out.println(add);
	}
}


Measured memory_bytes: 98860
import java.util.Scanner;

public class Main {
	public static Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		//B
		int N = sc.nextInt();
		int ans = 0;
		for(int i = 8 ; i <= N ; i++){
			if(i % 2 == 1 && yaku(i) == 8){
				ans++;
			}
		}
		System.out.println(ans);
	}

	public static  int yaku(int N){
		int yaku = 0;
		for(int i = 1 ; i <= N; i++){
			if(N % i == 0){
				yaku++;
			}
		}
		return yaku;
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define lli long long int
#define pb push_back
#define mod2 998244353
#pragma GCC optimize("-O2")
#define mod3 127
#define mod 1000000007
#define MAXN 1000000000
#define v32 vector<int>
#define v64 vector<lli>
#define v1024 vector<vector<int>>
#define v4096 vector<vector<lli>>
#define vt vector
#define f(x, y, z) for (lli x = y; x < z; x++)
#define fd(x, y, z) for (lli x = y; x > z; x--)
#define lb lower_bound
#define ld long double
#define m64 map<lli, lli>
#define m32 map<int, int>
#define m64it map<lli, lli>::iterator
#define m32it map<int, int>::iterator
#define fastio                    \
ios_base::sync_with_stdio(0); \
cin.tie(0);                   \
cout.tie(0)
#define ist insert
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define p_q priority_queue
#define min_p_q priority_queue<int, vt<int>, greater<int>>
using namespace std;
using namespace __gnu_pbds;
lli tmod(lli x, lli y)
{
    return (x % y + y) % y;
}
template <typename T>
void DEBUG_ARR(vt<T> a)
{
    f(i, 0, a.size()) cout << a[i] << " ";
    cout << "\n";
}
lli power(lli x, lli y) 
{
    lli res = 1;  
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x)%mod; 
        y = y>>1; 
        x = (x*x)%mod;
    }
    if(res<0)res+=mod;
    return res; 
}
v64 subtree[50];
v64 parent(50);
void dfs(int u,int p,v1024 &Tree){
    subtree[u].pb(u);
    parent[u]=p;
    for(auto x:Tree[u]){
        if(x==p)continue;
        dfs(x,u,Tree);
        for(auto y:subtree[x]){
            subtree[u].pb(y);
        }
    }
}
bool mat[50][50];
lli edge_mask[50];
lli dp[(1<<20)][50];
int m;
lli solve(lli mask,lli pos){
    if(dp[mask][pos]==-1){
        if(pos==0){
            if(mask==0)return dp[mask][pos]=2;
            if((mask|edge_mask[0])==edge_mask[0])return dp[mask][pos]=1;
            return dp[mask][pos]=0;
        }

        dp[mask][pos]=solve(mask-(mask&edge_mask[pos]),pos-1)+solve(mask,pos-1);
    }
    return dp[mask][pos];
}
vt <pair<int,int>> constraints;
int main()
{   
    memset(dp,-1,sizeof dp);
    fastio;
    lli n;
    cin>>n;
    // cout<<solve(n)<<"\n";
    v1024 Tree(n);
    f(i,0,n-1){
        int a,b;cin>>a>>b;
        a--,b--;
        Tree[a].pb(b);
        Tree[b].pb(a);
    }
    cin>>m;
    f(i,0,m){
        int x,y;cin>>x>>y;x--,y--;
        mat[x][y]=mat[y][x]=1;
        constraints.pb({x,y});
    }   
    dfs(0,-1,Tree);
    // f(i,0,n){
    //     f(j,0,subtree[i].size())cout<<subtree[i][j]<<" ";
    //     cout<<"\n";
    // }
    f(i,1,n){
        f(j,0,m){
            int f1=0,f2=0;
            int u=constraints[j].first;
            int v=constraints[j].second;
            for(auto x:subtree[i]){
                if(x==u)f1=1;
                if(x==v)f2=1;
            }
            if(f1+f2==1)edge_mask[i-1]+=(1<<j);
        }
    }
    // f(i,0,n-1)cout<<edge_mask[i]<<" ";
    // cout<<"\n";
    cout<<solve((1<<m)-1,n-2);
    return 0;
}


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

using namespace std;

typedef long long LL;
typedef unsigned long long uLL;
typedef long double ldb;
typedef pair<int,int> pii;

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    char c;
    int ans = 0;
    while(cin>>c)
        ans += c-'0';
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 768
//import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;

public class Main<T> {
	public static void main(String[] args) throws NumberFormatException, IOException {
		//System.setIn(new FileInputStream("./input.txt"));
		Reader r = new InputStreamReader(System.in);
		int n = r.read() - 0x30;
		//n = 6;
		//long start = System.nanoTime();
		
		Point[] p = Koch(n);
		//System.out.println((start - System.nanoTime())/ 1000 + " us");
		StringBuilder sb = new StringBuilder();
		for(int i = 0; i < p.length; ++i){
			sb.append(p[i] + "\n");
		}
		System.out.println(sb);
	}

	public static Point[] Koch(int n) {
		Point[] p, p2;
		if(n == 0){
			p = new Point[2];
			p[0] = new Point(0.0f, 0.0f);
			p[1] = new Point(100.0f, 0.0f);
			return p;
		}else{
			p = Koch(n-1);
			p2 = new Point[(p.length - 1)*4 + 1];
			for(int i = 0; i < p.length; ++i) {
				// left edge
				p2[i*4] = new Point(p[i].x, p[i].y);
				if(i == p.length - 1){
					break;
				}
				// 3 middle points
				float mx = (p[i+1].x - p[i].x);
				float my = (p[i+1].y - p[i].y);
				
				p2[i*4 + 1] = new Point(mx / 3.0f + p[i].x, my / 3.0f + p[i].y);
				p2[i*4 + 2] = new Point(mx / 2.0f - my / (2.0f * 1.7320508f) + p[i].x,
						my / 2.0f + mx / (2.0f * 1.7320508f) + p[i].y);
				p2[i*4 + 3] = new Point(mx * 2.0f / 3.0f + p[i].x, my * 2.0f / 3.0f + p[i].y);
			}
			return p2;
		}
	}

	
}
class Point {
	public float x;
	public float y;
	@Override
	public String toString(){
		return String.format("%.5f %.5f", x, y);
	}
	public Point(float x, float y){
		this.x = x;
		this.y = y;
	}
}

Measured memory_bytes: 41332
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,ll>P;

const ll mod = 1e9+7;
const ll INF = ll(1e18)+1;
const ll MAXN = 1e6;

int main()
{
    ll n;
    cin>>n;
    ll a[n];
    ll p[n];
    rep(i,n)
    {
        cin>>a[i];
        p[i]=a[i];
    }
    sort(p,p+n,greater<ll>());
    rep(i,n)
    {
        if(p[0]==a[i])
        {
            cout<<p[1]<<endl;
        }
        else
        {
            cout<<p[0]<<endl;
        }
        
    }

}

Measured memory_bytes: 4736
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

vector<int>E[800];
vector<pair<int, int>>li;
int cnt0, cnt1;
int used[800];
int dp[2500][2500];
void err() {
	puts(-1);
	exit(0);
}

void dfs(int now,int col){
	used[now] = col;
	if (col == 0)cnt0++;
	else cnt1++;
	fore(x, E[now]) {
		if (used[x] == -1)dfs(x,!col);
		else if (used[x] == col)err();
	}
	return;
}

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

	int N, M;
	cin >> N >> M;
	set<pair<int, int>>st;
	for (int i = 0; i < N; i++)for (int j = i + 1; j < N; j++)st.insert({ i,j });
	for (int i = 0; i < M; i++) {
		int A, B;
		cin >> A >> B;
		A--, B--;
		st.erase({min(A,B),max(A,B)});
	}
	fore(x, st) {
		int A = x.first;
		int B = x.second;
		E[A].pb(B);
		E[B].pb(A);
	}
	memset(used, -1, sizeof(used));
	for (int i = 0; i < N; i++) {
		cnt0 = 0;
		cnt1 = 0;
		if (used[i] == -1) {
			dfs(i,0);
			li.pb({cnt0,cnt1});
		}
	}

	dp[0][0] = 1;
	for (int i = 0; i < li.size(); i++) {
		for (int j = 0; j <= N; j++) {
			if (dp[i][j]) {
				dp[i + 1][j + li[i].first] = 1;
				dp[i + 1][j + li[i].second] = 1;
			}
		}
	}

	ll ans = inf;
	for (ll j = 0; j <= N; j++) {
		ll k = N - j;
		if(dp[li.size()][j])ans = min(ans, j*(j-1)/2LL + k*(k-1)/2LL);
	}
	puts(ans);

	return 0;
}

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

int main() {
  int N, ma, mb;
  cin >> N >> ma >> mb;
  auto a = vector<int>(N);
  auto b = vector<int>(N);
  auto c = vector<int>(N);
  for (int i = 0; i < N; ++i) cin >> a[i] >> b[i] >> c[i];

  int SZ = 401;
  int INF = 4001;
  auto dp = vector<vector<int>>(SZ, vector<int>(SZ, INF));
  dp[0][0] = 0;
  for (int k = 0; k < N; ++k) {
    for (int i = SZ - 1; i >= a[k]; --i) {
      for (int j = SZ - 1; j >= b[k]; --j) {
        if (dp[i - a[k]][j - b[k]] < INF) {
          dp[i][j] = min(dp[i][j], dp[i - a[k]][j - b[k]] + c[k]);
        }
      }
    }
  }

  int ans = INF;
  for (int i = 1; i <= N; ++i) ans = min(ans, dp[i * ma][i * mb]);
  cout << ( (ans == INF) ? -1 : ans ) << endl;
  return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    double s=0,n,v1[200001],v2[200001],T[200],V[200],ans=0;
    cin>>n;
    rep(i,n){
        cin>>T[i],s+=T[i];
        if(i>0) T[i]+=T[i-1];
    }
    rep(i,n) cin>>V[i];
    double t;
    int x=0;
    rep(i,2*s+1){
        t=double(i)/2;
        if(t==0) v1[i]=0;
        else v1[i]=min(v1[i-1]+0.5,V[x]);
        if(x<n-1&&t==T[x]) x++;
    }
    x=n-1;
    for(int i=2*s;i>=0;i--){
        t=double(i)/2;
        if(t==s) v2[i]=0;
        else v2[i]=min(v2[i+1]+0.5,V[x]);
        if(x>0&&t==T[x-1]) x--;
    }
    rep(i,2*s) ans+=(min(v1[i],v2[i])+min(v1[i+1],v2[i+1]))/4;
    cout<<setprecision(10)<<ans;
}

Measured memory_bytes: 2432
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

int main(int argc, char const *argv[]) {
  string O, E;
  cin >> O >> E;
  string ans;
  if (O.size() == E.size()) {
    for (int i = 0; i < O.size(); i++) {
      ans += O[i];
      ans += E[i];
    }
  } else {
    for (int i = 0; i < O.size() - 1; i++) {
      ans += O[i];
      ans += E[i];
    }
    ans += *(O.end() - 1);
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;


int main(){
    
    long int n,a,b,c,d,e;cin>>n>>a>>b>>c>>d>>e;
    long int ans = 0;
    long int mi = min(a,b);
    mi = min(mi, c);
    mi = min(mi, d);
    mi = min(mi, e);
    
    if (n%mi == 0) {
        cout << 4+n/mi << endl;
    }else{
        cout << 5+n/mi << endl;
    }
    
    
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;


ll calc(char s[], int l)
{
	ll ret=0;
	int c=1;
	for(int i=1;i<l;i++)
	{
		if(s[i]==s[i-1])
		{
			c++;
		}
		else
		{
			ret+=c/2;
			c=1;
		}
	}
	ret+=c/2;
	return ret;
}


int main(void)
{
	char s[200+2];
	int k;

	while(scanf("%100[a-z]\n%d\n", s, &k)==2)
	{
		int l=strlen(s);
		int is_loop=0;

		for(int i=0;i<l;i++) s[i+l]=s[i];

		int p=-1;
		for(int i=0;i<l;i++)
		{
			if(s[l+i]!=s[l+i-1])
			{
				p=i;
				break;
			}
		}
		ll ans=(ll)l*k/2;
		if(p>=0) ans=calc(s, l)+calc(s+p, l)*(k-1);

		printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;
import java.util.Stack;

/**
 * https://abc064.contest.atcoder.jp/tasks/abc064_d
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		char[] s = sc.next().toCharArray();
		sc.close();
		
		Stack<String> stack = new Stack<>();
		for(int i=N-1; i>=0; i--){
			stack.push(Character.toString(s[i]));
		}
		
		StringBuilder sb = new StringBuilder();
		int current = 0;
		while(!stack.isEmpty()){
			String c = stack.pop();
			if(c.equals("(")){
				current++;
				sb.append(c);
			}else{
				if(current>0){
					sb.append(c);
					current--;
				}else{
					sb = new StringBuilder("("+ sb.toString()+")");
				}
			}
		}
		for(int i=0; i<current; i++){
			sb.append(")");
		}
		
		System.out.println(sb);

	}

}


Measured memory_bytes: 21844
while gets do
  c1, c2, c3 = $_.chomp.split(' ').map(&:to_i)
  rem = (1..10).to_a - [c1, c2, c3]
  per = rem.map{ |i| c1 + c2 + i <= 20 ? 1 : 0 }.inject(:+)/7.0
  puts per >= 0.5 ? 'YES' : 'NO'
end

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

int N, K;
vector<int64_t> V[200000];

priority_queue<int64_t> Q;
priority_queue<int64_t, vector<int64_t>, greater<int64_t>> P, R;
priority_queue<pair<int64_t, int>> T;

vector<int> c_order;
bitset<200000> c_used;
int co = 0;

int64_t irregular = 0;

int64_t pick(){
    if(irregular){
        int64_t ret = irregular;
        R.push(2*ret);
        for(int i=2; i<V[c_order[co]].size(); i++) Q.push(V[c_order[co]][i]);
        c_used[c_order[co]] = 1;
        while(T.size() && c_used[T.top().second]) T.pop();
        co++;
        irregular = 0;
        return ret;
    }

    int64_t a = (Q.size() ? Q.top() : 0);
    int64_t b = (co < K ? V[c_order[co]][0] : 0);
    if(a > b){
        Q.pop();
        P.push(a);
        return a;
    }else{
        irregular = b;
        return b;
    }
}

int main(){
    cin >> N >> K;
    for(int i=0; i<N; i++){
        int c, v;
        cin >> c >> v;
        V[c-1].push_back(2*v);
    }

    for(int c=0; c<K; c++){
        sort(V[c].rbegin(), V[c].rend());
        V[c][0] = V[c][1] = (V[c][0] + V[c][1]) / 2;
    }

    for(int i=0; i<K; i++) c_order.push_back(i);
    sort(c_order.begin(), c_order.end(), [&](int a, int b){return V[a][0] > V[b][0];});
    c_used[c_order[0]] = 1;
    for(int c=0; c<K; c++) if(V[c].size() >= 3) T.push({V[c][0] + V[c][1] + V[c][2], c});

    int64_t sum = 0;
    for(int i=0; i<N; i++){
        int64_t add = pick();
        int64_t ans;
        if(irregular){
            ans = -2;
            if(Q.size()) ans = max(ans, sum + Q.top());
            if(P.size()) ans = max(ans, sum - P.top() + 2*add);
            if(R.size() && T.size()) ans = max(ans, sum - R.top() + T.top().first);
        }else{
            ans = sum + add;
        }
        cout << ans/2 << endl;
        sum += add;
    }
    return 0;
}

Measured memory_bytes: 15536
N = int(input())
a = list(map(int, input().split()))
from collections import deque
kisuu = deque([])
bai4 = deque([])
sonota = deque([])
for ai in a:
    if ai % 4 == 0:
        bai4.append(ai)
    elif ai % 2 == 0:
        sonota.append(ai)
    else:
        kisuu.append(ai)

ans = deque([])
if kisuu:
    s = kisuu.pop()
    ans.append(s)
elif sonota:
    s = sonota.pop()
    ans.append(s)
else:
    s = bai4.pop()
    ans.append(s)        

for i in range(1, N + 1):
    if i == N:
        print('Yes')
        quit()
    if ans[i - 1] % 2 == 1:
        if bai4:
            s = bai4.pop()
            ans.append(s)
        else:
            break
    elif ans[i - 1] % 2 == 0 and ans[i - 1] % 4 != 0:
        if sonota:
            s = sonota.pop()
            ans.append(s)
        elif bai4:
            s = bai4.pop()
            ans.append(s)
        else:
            break
    elif ans[i - 1] % 4 == 0:
        if kisuu:
            s = kisuu.pop()
            ans.append(s)
        elif sonota:
            s = sonota.pop()
            ans.append(s)
        elif bai4:
            s = bai4.pop()
            ans.append(s)
        else:
            break
print('No')           

Measured memory_bytes: 14252
X, N = map(int, input().split())

P = list(map(int, input().split()))

ans_l = X
ans_h = X
h_s = 0
l_s = 0

while True:
    if l_s == 0 and ans_l not in P:
        print(ans_l)
        break
    else:
        ans_l -= 1
    
    if ans_h not in P:
        print(ans_h)
        break
    else:
        ans_h += 1
        
    if ans_h > 100:
        h_s = 1
    
    if ans_l < 0:
        l_s = 1
    
    if l_s and h_s == 1:
        break

Measured memory_bytes: 61948
#include<bits/stdc++.h>
using namespace std;
int main(){
int N,M;
  cin>>N>>M;
  vector<set<int>>A(M);
  for(int i=0;i<M;i++){
  int k;
    cin>>k;
    for(int j=0;j<k;j++){
    int s; cin>>s; s--;
      A.at(i).insert(s);
    }
  
  }vector<int>p(M);
  for(int i=0;i<M;i++)
    cin>>p.at(i);
  int ans=0;
  for(int bit=0;bit<(1<<N);bit++){
   vector<int>q(M,0);
    for(int i=0;i<N;i++)
      if(bit & (1<<i)){
      for(int j=0;j<M;j++)
        if(A.at(j).count(i))
          q.at(j)++;
      } bool x=true;
    for(int i=0;i<M;i++){
    if((p.at(i)%2)!=q.at(i)%2){
    x=false; break;
    }
      
    } if(x)ans++;
  
 }cout<<ans<<endl;
  return 0;
}

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

const int MAX = 100000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    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;
    }
}

// 二項係数計算
long long COM(int n, int k, int l){
    if (n < k || n < l) return 0;
    if (n < 0 || k < 0 || l<0) return 0;
    return (fac[n] * (finv[k] * (finv[l] * finv[n - k - l])%MOD)%MOD)% MOD;
}

int main(){
  int N;cin >> N;
  vector<int> cnt(3,0);
  long long ans = 1;
  //COMinit();
  for(int i=0;i<N;i++){
    int a;cin >> a;
    int index = -1;
    int kk = 0;
    for(int j=0;j<3;j++)
      if(cnt[j]==a){
        if(index==-1){
          cnt[j]++;
          index++;
        }
        kk++;
      }
    ans = (ans*kk)%MOD;
  }
  cout << ans << endl;
}
      
      
      

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,max=0;
    long long int ans=0;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    max=a[0];
    for(int i=1;i<n;i++){
        if(a[i]>max)max=a[i];
        else ans+=max-a[i];
    }
    cout<<ans<<endl;
    return 0;
}

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

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;++i) cin >> a[i];
    vector<int> l(a),r(a);
    for(int i=1;i<n;++i){
        l[i]=gcd(l[i],l[i-1]);
        r[n-1-i]=gcd(r[n-i],r[n-1-i]);
    }
    int M=0;
    for(int i=1;i<n-1;++i){
        if(gcd(l[i-1],r[i+1]) > M)
            M = gcd(l[i-1],r[i+1]);
    }
    if(max(l[n-2],r[1])>M)
        M = max(l[n-2],r[1]);
    cout << M << endl;
    return 0;
}

Measured memory_bytes: 1408