akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000

struct Bitset{
	using ull =  __uint128_t;//unsigned long long;
	vector<ull> b;
	int n;
	Bitset(int x){
		n = x;
		b.resize((n+127)/128,0);
	}
	
	int get(int x){
		return (b[x>>7]>>(x&127))&1;
	}
	
	void set(int x,int y){
		b[x>>7] |= 1ULL<<(x&127);
		if(!y)b[x>>7] ^= 1ULL<<(x&127);
	}
	
	Bitset &operator&=(const Bitset &another){
		rep(i,b.size()){
			b[i] &= another.b[i];
		}
		return (*this);
	}
	
	Bitset operator&(const Bitset &another)const{
		return (Bitset(*this)&=another);
	}
	
	Bitset &operator|=(const Bitset &another){
		rep(i,b.size()){
			b[i] |= another.b[i];
		}
		return (*this);
	}
	
	Bitset operator|(const Bitset &another)const{
		return (Bitset(*this)|=another);
	}
	
	Bitset &operator^=(const Bitset &another){
		rep(i,b.size()){
			b[i] ^= another.b[i];
		}
		return (*this);
	}
	
	Bitset operator^(const Bitset &another)const{
		return (Bitset(*this)^=another);
	}
	
	Bitset &operator>>=(int x){
		if(x&63){
			rep(i,b.size()-1){
				b[i] >>= (x&63);
				b[i] ^= (b[i+1]<<(64-(x&63)));
			}
			b.back() >>= (x&63);
		}
		
		x>>=6;
		rep(i,b.size()){
			if(i+x<b.size())b[i] = b[i+x];
			else b[i]=0;
		}
		return (*this);
	}
	
	Bitset operator>>(int x)const{
		return (Bitset(*this)>>=x);
	}
	
	Bitset &operator<<=(int x){
		if(x&127){
			for(int i=b.size()-1;i>=1;i--){
				b[i] <<= (x&127);
				b[i] ^= b[i-1]>>(128-(x&127));
			}
			b[0] <<= x&127;
		}
		
		x>>=7;
		for(int i=b.size()-1;i>=0;i--){
			if(i-x>=0)b[i] = b[i-x];
			else b[i] = 0;
		}
		return (*this);
	}
	
	Bitset operator<<(int x)const{
		return (Bitset(*this)<<=x);
	}
	
};

int main(){
	
	int N;
	cin>>N;
	
	vector<int> A(N);
	int S = 0;
	
	for(int i=0;i<N;i++){
		cin>>A[i];
		S += A[i];
	}
	
	
	Bitset B(4000001);
	B.set(0,1);
	
	for(int i=0;i<N;i++){
		B |= (B<<A[i]);
	}
	
	int k = (S+1)/2;
	
	for(int i=k;true;k++){
		if(B.get(k)){
			cout<<k<<endl;
			return 0;
		}
	}
 
	
	return 0;
}
 


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


int main(){
	ll n;
	string s;
	cin>>n>>s;
	ll bc=0,rc=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='B')bc++;
		else rc++;
	}
	cout<<(rc>bc?"Yes":"No");
	return 0;
}


Measured memory_bytes: 256
// Enjoy your stay.

#include <bits/stdc++.h>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

typedef istringstream iss;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;

int n;

int f(int cur,int n,int pre){
	int res = n == 0;
	if(cur==4)return res;
	rep2(i,pre,INF){
		if(i*i > n)break;
		res += f(cur+1,n-i*i,i);
	}
	return res;
}

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

	while(cin>>n && n){
		cout<<f(0,n,1)<<endl;
	}
}

Measured memory_bytes: 1188
/// Thank you tanakh!!!
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn f(b: usize, mut n: usize) -> usize {
    let mut result = 0;
    while n > 0 {
        result += n % b;
        n /= b;
    }
    result
}

fn main() {
    input!(n: usize, s: usize);
    for b in 2..1000000 {
        if f(b, n) == s {
            println!("{}", b);
            return;
        }
    }

    if n > s {
        for p in (1..1000000).rev() {
            if (n - s) % p != 0 {
                continue;
            }
            let b = (n - s) / p + 1;
            if f(b, n) == s {
                println!("{}", b);
                return;
            }
        }
    }

    if s == 1 {
        println!("{}", n);
    } else if n == s {
        println!("{}", n + 1);
    } else {
        println!("-1");
    }
}


Measured memory_bytes: 4352
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
int V,E;
vector<int> g[100100];
int dep[100100],low[100100],ord[100100],par[100100];
vector<int> child[100100];
int cnt = 0;
void dfs(int v,int p,int d){
	par[v] = p;
	dep[v] = d;
	ord[v] = cnt++;
	low[v] = ord[v];
	for(int i=0;i<g[v].size();i++){
		if(g[v][i]==p)continue;
		int ch = g[v][i];
		if(ord[ch]==-1){
			child[v].pb(ch);
			dfs(ch,v,d+1);
			low[v] = min(low[v],low[ch]);
		}else{
			low[v] = min(low[v],ord[ch]);
		}
	}
}
int main(){
	scanf("%d %d",&V,&E);
	vector<P> es(E);
	for(int i=0;i<E;i++){
		int s,t;
		scanf("%d %d",&s,&t);
		g[s].pb(t);
		g[t].pb(s);
		if(s>t)swap(s,t);
		es[i]=P(s,t);
	}
	memset(ord,-1,sizeof(ord));
	dfs(0,-1,0);
	/* bridge
	vector<P> ans;
	for(int i=0;i<E;i++){
		int s = es[i].fi,t = es[i].sec;
		if(dep[s]>dep[t])swap(s,t);
		if(ord[s]<low[t])ans.pb(es[i]);	
	}
	sort(all(ans));
	for(int i=0;i<ans.size();i++)printf("%d %d\n",ans[i].fi,ans[i].sec);
	*/
	vector<int> res;
	if((int)child[0].size()>1)res.pb(0);
	for(int i=1;i<V;i++){
		bool flag = false;
		for(int j=0;j<child[i].size();j++){
			if(ord[i]<=low[child[i][j]]){
				flag = true;
				break;
			}
		}
		if(flag)res.pb(i);
	}
	for(int i=0;i<res.size();i++)printf("%d\n",res[i]);
	return 0;
}

Measured memory_bytes: 10224
#include<iostream>
#include<algorithm>
using namespace std;
int n;
int a[100010];
int main()
{
	ios::sync_with_stdio(false);
	int sum = 0;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		sum += abs(a[i] - a[i-1]);
	}
	sum += abs(a[n ] - a[0]);
	for (int i = 1; i <= n; i++)
	{
		cout << sum - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]) + abs(a[i + 1] - a[i - 1]) << endl;
	}
	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <cmath>
#include <string>

int main() {
	double a;
	std::string str;
	str.reserve(13);

	while (std::cin >> a) {
		if (a < 0)
			break;

		for (int i = 7; i >= -4; --i) {
			double b = std::pow(2.0, i);
			if (a >= b) {
				a -= b;
				str += '1';
			}
			else
				str += '0';

			if (i == 0)
				str += '.';
		}

		if (a < 0.000001)
			std::cout << str << std::endl;
		else
			std::cout << "NA" << std::endl;

		str.clear();
	}

	return 0;
}

Measured memory_bytes: 1216
import sys
sys.setrecursionlimit(10**7)

road_par = []
road_rank = []
rail_par = []
rail_rank = []
c1 = []
c2 = []

def init(par, rank, c, n):
    for i in range(n):
        par.append(i)
        rank.append(0)
        c.append(0)


def find(par,x):
    if par[x] == x:
        return x
    par[x] = find(par, par[x])
    return par[x]


def unite(par, rank, x, y):
    x = find(par, x); y = find(par, y)
    if x == y:
        return
    if rank[x] < rank[y]:
        par[x] = y
    elif rank[y] < rank[x]:
        par[y] = x
    else:
        par[y] = x
        rank[x] += 1


N, K, L = map(int, input().split())
init(road_par, road_rank, c1, N)
init(rail_par, rail_rank, c2, N)


for i in range(K):
    f, t = map(int, input().split())
    unite(road_par, road_rank, f-1, t-1)

for i in range(L):
    f,t = map(int, input().split())
    unite(rail_par, rail_rank, f-1, t-1)

for i in range(N):
    c1[find(road_par, i)] += 1
    c2[find(rail_par, i)] += 1

ans = [0 for i in range(N)]

"""
for i in range(N):
    for j in range(N):
        if find(road_par, i) == find(road_par, j) and find(rail_par, i) == find(rail_par, j):
            ans[i] += 1
"""
from collections import defaultdict
ans = defaultdict(int)
for i in range(N):
    ans[(find(road_par, i), find(rail_par, i))] += 1

for i in range(N):
    print(ans[(find(road_par, i), find(rail_par, i))], end=' ')
print('')

Measured memory_bytes: 61988
using System;
using System.Linq;

namespace paizaTest
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var readLine = Console.ReadLine().Split(' ').Select(int.Parse).OrderBy(x => x).ToArray();
            Console.WriteLine(string.Join(" ", readLine.Select(x => x.ToString()).ToArray()));
        }
    }
}

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

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

int main(){
    int a, b, c; cin >> a >> b >> c;
    vector<int> div;
    div=divisor(c);
    int res=0;
    for(auto &x: div){
        if(x >= a && x <= b){
            res++;
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3172
import numpy as np

A = [ list(map(int,input().split(" "))) for i in range(3)]
N = int(input())
X = np.ones((3,3))
for num in range(N):
  b_num = int(input())
  for i in range(3):
    for j in range(3):
      X[i,j] = X[i,j] * ( A[i][j] - b_num )
      
sum = 1
for n in range(3):
  sum = sum * ( X[n,0]**2 + X[n,1]**2 + X[n,2]**2 )
  sum = sum * ( X[0,n]**2 + X[1,n]**2 + X[2,n]**2 )
sum = sum * ( X[0,0]**2 + X[1,1]**2 + X[2,2]**2 )
sum = sum * ( X[0,2]**2 + X[1,1]**2 + X[2,0]**2 )

if sum == 0:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 12444
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include<math.h>
#include<bitset>
#include<iomanip>
using namespace std;

int main() {
	int N; cin >> N;
	vector<long long>a(N);
	long long y=0;
	for (int i = 0; i < N; i++) { cin >> a[i];y += a[i]; }
	y -= a[N - 1];
	long long x=a[N-1],ans = abs(y - x) ;
	for (int i = N-2; i >0; i--) {
		y -= a[i];
		x += a[i];
		ans = min(abs(y-x), ans);
	}
	cout << ans << endl;
}



Measured memory_bytes: 1792
#include <iostream>

using namespace std;
int main() {
    unsigned long long int n,k,a,b;
    cin>>n>>k;
    a=n%k;
    b=k-a;
    if(b<0)
        b=-b;
    if(a<b)
        cout<<a;
    else
        cout<<b;

    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
 
public class Main{
   public static void main(String[] args) {
      MyScanner sc = new MyScanner();
      out = new PrintWriter(new BufferedOutputStream(System.out));
      
      //begin
      int n = sc.nextInt();
      int d = sc.nextInt();
      int[] coords = new int[n * d];
      int match = 0;
      for(int i = 0; i < coords.length; i++)
        coords[i] = sc.nextInt();
      for(int i = 0; i <= coords.length - 2 * d; i += d)
      {
          for(int j = i + d; j <= coords.length - d; j += d)
          {
              int sum = 0;
              for(int k = 0; k < d; k++)
                sum += Math.pow(Math.abs(coords[i + k] - coords[j + k]), 2);
              double dist = Math.sqrt(sum);
              if(dist == (int) (dist))
                match++;
          }
      }
      out.println(match);      
      //end
      out.close();
   }
 
   public static PrintWriter out;
      
   public static class MyScanner {
      BufferedReader br;
      StringTokenizer st;
 
      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }
 
      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }
 
      int nextInt() {
          return Integer.parseInt(next());
      }
      long nextLong() {
          return Long.parseLong(next());
      }
      double nextDouble() {
          return Double.parseDouble(next());
      }
      String nextLine(){
          String str = "";
	  try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  }
	  return str;
      }
   }
}

Measured memory_bytes: 21332
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int main()
{
    int n,m;
    cin>>n>>m;
    vector<int> s(n);
    REP(i,m){
        int k;
        cin>>k;
        REP(j,k){
            int temp;
            cin>>temp;
            temp--;
            s[temp]|=1<<i;
        }
    }
    // REP(i,n) cout<<s[i]<<endl;
    int p;
    REP(i,m){
        int temp;
        cin>>temp;
        p|=temp<<i;
    }
    // cout<<p<<endl;

    int ans=0;
    REP(i,1<<n){
        int res=0;
        REP(j,n){
            if(i&1<<j) res^=s[j];
        }
        if(res==p) ans++;
    }
    cout<<ans<<endl;

	return 0; 
}

Measured memory_bytes: 256
import queue


def get_longest(s_tmx, i, j, h, w):
    q = queue.Queue()
    q.put((i, j))
    dist_mtx = [[-1] * w for a in range(h)]
    dist_mtx[i][j] = 0
    while not q.empty():
        pnt = q.get()
        y = pnt[0]
        x = pnt[1]
        if x - 1 >= 0 and dist_mtx[y][x-1] == -1 and s_mtx[y][x-1] == 1:
            dist_mtx[y][x-1] = dist_mtx[y][x] + 1
            q.put((y, x-1))
        if y - 1 >= 0 and dist_mtx[y-1][x] == -1 and s_mtx[y-1][x] == 1:
            dist_mtx[y-1][x] = dist_mtx[y][x] + 1
            q.put((y-1, x))
        if x < w - 1 and dist_mtx[y][x+1] == -1 and s_mtx[y][x+1] == 1:
            dist_mtx[y][x+1] = dist_mtx[y][x] + 1
            q.put((y, x+1))
        if y < h - 1 and dist_mtx[y+1][x] == -1 and s_mtx[y+1][x] == 1:
            dist_mtx[y+1][x] = dist_mtx[y][x] + 1
            q.put((y+1, x))
    ret = 0
    for item in dist_mtx:
        for item_item in item:
            if item_item > ret:
                ret = item_item
    return ret


h, w = map(int, input().split())
s_mtx = []

for i in range(h):
    s_list = [0] * w
    tmp = input()
    for j in range(len(tmp)):
        if tmp[j] == ".":
            s_list[j] = 1
        else:
            s_list[j] = 0
    s_mtx.append(s_list)

ret = 0

for i in range(h):
    for j in range(w):
        if s_mtx[i][j] == 1:
            tmp = get_longest(s_mtx, i, j, h, w)
            if tmp > ret:
                ret = tmp

print(ret)


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

void push(int A);
int pop(void);

int S[1000];
int Top = 0;

int main(void) {

	char str[100];
	int a, b;
	Top = 0;
	while (scanf("%s", str) != EOF) {

		if (str[0] == '+') {
			a = pop();
			b = pop();
			push(a + b);
		}
		else if (str[0] == '-') {
			b = pop();
			a = pop();
			push(a - b);
		}
		else if (str[0] == '*') {
			a = pop();
			b = pop();
			push(a * b);
		}
		else {
			push(atoi(str));
		}
	}
	printf("%d\n", pop());

	return 0;
}

void push(int A) {
	S[++Top] = A;
}

int pop(void) {
	Top--;
	return S[Top+1];
}


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

int main(){
    ll n;
    cin>>n;
    ll cnt=0,nn=n,f2=0;
    for(ll i=0;i<n;++i){
        ll t;
        cin>>t;
        if(t%4==0){
            cnt++;
        }else if(t%2==0){
            f2++;
            if(f2==2){
                nn-=2;
            }else if(f2>2){
                nn-=1;
            }
        }
    }
    if((nn+(f2>1?1:0))/2<=cnt){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
}

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

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


Measured memory_bytes: 256
from __future__ import print_function

import sys
input = sys.stdin.readline

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

# import math
# import string
# import fractions
# from fractions import Fraction
# from fractions import gcd

# def lcm(n,m):
#     return int(n*m/gcd(n,m))

# import re
# import array
# import copy
# import functools
# import operator

# import collections
# import itertools
# import bisect
# import heapq


# from heapq import heappush
# from heapq import heappop
# from heapq import heappushpop
# from heapq import heapify
# from heapq import heapreplace

# from queue import PriorityQueue as pq

# def reduce(p, q):
#     common = fractions.gcd(p, q)
#     return (p//common , q//common )
# # from itertools import accumulate
# # from collections import deque

# from operator import mul
# from functools import reduce

# def combinations_count(n, r):
#     r = min(r, n - r)
#     numer = reduce(mul, range(n, n - r, -1), 1)
#     denom = reduce(mul, range(1, r + 1), 1)
#     return numer // denom

# import random

def main():
    n = int(input().strip())
    l1,l2 = map(list, input().strip().split())

    for i in range(n):
        print(l1[i],end="")
        print(l2[i],end="")
    print()
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
import math
s = int(input())
def f(n):
    if n%2 == 1:
        return 3*n+1
    else:
        return math.floor(n/2)
a = [s]
t = 1
a.append(f(a[0]))
while not a[t] in a[:(t-1)]:
    a.append(f(a[t]))
    t += 1
print(t+1)
    

Measured memory_bytes: 3060
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

using namespace std;

int main(){
	int cnt=0,sum=0;
	char str;
	while(str = getchar(),~str){
		if(str >= '0' && str <= '9'){
			cnt *= 10;
			cnt += str-'0';
		}else{
			sum += cnt;
			cnt = 0;
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1120
n = int(input())
s = input()
a,b,c,d,x = 0,0,0,0,s
for i in s:
	if i=="(": a+=1
	else: b+=1
	if a<b:
		x = "("+x
		a+=1
x = x[::-1]
answer = x
for i in x:
	if i==")": c+=1
	else: d+=1
	if c<d:
		answer = ")"+answer
		c+=1
answer = answer[::-1]
print(answer)

Measured memory_bytes: 3064
i = j = k = 0
n = ''
m = ''
l = ''

line = input()

while line[i] != ' ':
    n = n + line[i]
    i += 1
    
i += 1
while line[i] != ' ':
    l = l + line[i]
    i += 1

while i < len(line):
    m = m + line[i]
    i += 1
    
n = int(n)
l = int(l)
m = int(m)

min = n
if min > l:
	min = l
if min > m:
	min = m

max = n
if max < l:
	max = l
if max < m:
	max = m

if min < n <max:
	cen = n
elif min < l < max:
	cen = l
else: 
	cen = m

print(min,end=' ')
print(cen,end=' ')
print(max)

Measured memory_bytes: 7708
#include<bits/stdc++.h>//把万能头建好
using namespace std;
string s;//定义好字符串
char a[100010];//定义好字符数组
int main(){
     cin>>s;//输入
     int k=0;//再来个记录字符数组的小K
     for(int i=0;i<s.size();i++){
        if(s[i]!='B') a[++k]=s[i];//一旦是B就转换
        else{k--;//不然就要-1
            if(k<0) k=0;}}//还有一种就是清零
     for(int i=1;i<=k;i++)
        cout<<a[i];//输出
     cout<<endl;//别忘了回车
 return 0;//完美结束
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e16
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define M 1000010

int main(){
	IOS;
	ll h,w,a,b;cin>>h>>w>>a>>b;
	ll m[h+1][w+1];
	rep(i,0,h+1)rep(j,0,w+1){
		if(i<=b)m[i][j]= (j<=a)?1:0;
		else m[i][j]= (j<=a)?0:1;
	}
	rep(i,1,h+1){rep(j,1,w+1)cout<<m[i][j];cout<<"\n";}
	return 0;
}



Measured memory_bytes: 9088
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int S(lint N){
  int r=0;
  while(N>0){
    r+=N%10;
    N/=10;
  }
  return r;
}

lint N_max(lint N){
  lint r=1;
  while(N>0){
    r*=10;
    N/=10;
  }
  return r;
}

int main(){
  lint K;
  cin>>K;
  lint A=1;
  REP(i,K){
    cout<<A<<endl;
    lint B=A+1;
    lint M=N_max(B);
    lint C=B;
    lint base=1;
    while(B<M){
      if(C*S(B)>B*S(C))C=B;
      if(B%(base*10)==base*10-1)base*=10;
      B+=base;
    }
    A=C;
  }
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(double x){
  printf("%.15f",x);
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
int N;
int K;
int P[200000];
int main(){
  int i;
  int mx;
  int tmp = 0;
  double res;
  rd(N);
  rd(K);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(P[Lj4PdHRW]);
    }
  }
  for(i=(0);i<(K);i++){
    tmp += P[i];
  }
  mx = tmp;
  for(i=(K);i<(N);i++){
    tmp += P[i] - P[i-K];
    chmax(mx, tmp);
  }
  res = (double) (mx + K) / 2;
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200119-1

// --- original code ---
// int N, K, P[2d5];
// {
//   int mx, tmp = 0;
//   double res;
//   rd(N,K,P(N));
//   rep(i,K) tmp += P[i];
//   mx = tmp;
//   rep(i,K,N){
//     tmp += P[i] - P[i-K];
//     mx >?= tmp;
//   }
//   res = (double) (mx + K) / 2;
//   wt(res);
// }


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
int main(void){
  int n,m,sum,a;
  cin>>n;
  cin>>m;
 // cout<<n<<" ";
 // cout<<m<<endl;
  int arr[m];
  sum=0;a=0;
  for(int i=0;i<=m-1;i++){
      cin>>arr[i];
      sum=sum+arr[i];
  }//cout<<sum<<endl;
  a=abs(n-sum);
  //cout<<a<<endl;
 if(sum==n){cout<<"0\n";}
  else {
  if(sum>n){cout<<"-1\n";}
  else {
     cout<<a<<endl;
  }
  }
}

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

#define st first
#define nd second
#define ll long long
#define ld long double
#define pb push_back
#define emp emplace_back
#define pii pair<int, int>
#define usg unsigned
#define sg signed
#define mp make_pair

using namespace std;

void setIO(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

const ld PI = 4*atan((ld)1);
const int INF = 1e9+7;

int main(){
	setIO();
	int x, y; cin >> x >> y;
	ld tur = (ld)(y-2*x)/2;
	if (tur == (int)tur && tur >= 0 && x-tur >= 0)
		cout << "Yes\n";
	else cout << "No\n";
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  ll h[n];
  REP(i, n) {
    cin >> h[i];
  }

  int maxCount = 0, count = 0;
  REP(i, n - 1) {
    if (h[i] >= h[i + 1]) count++;
    else {
      if (maxCount <= count) {
        maxCount = count; 
      }
      count = 0;
    }
  }
  cout << max(maxCount, count) << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
static const int dx[4] = { 0, 1, 0, -1 };
static const int dy[4] = { 1, 0, -1, 0 };
static const char dir[4] = { 'u', 'r', 'd', 'l' };
static const ll INF = 1 << 21;
static const ll MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for (int x = 1; x <= 50000; x++) {
        if ((int)floor(x * 1.08) == n) {
            cout << x << endl;
            return 0;
        }
    }
    puts(":(");
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

vector<int> G[200010];

int main(void){
	          int i;

	          int N,M;
	          cin >> N >> M;
	          for(i=0;i<M;i++){
	        	  int a,b;
	        	  cin >> a >> b;
	        	  if(a==1){
	        		  G[a].push_back(b);
	        	  }else{
	        		  if(b==N) G[a].push_back(b);
	        	  }
	          }

	          int m=G[1].size();
	          for(i=0;i<m;i++){
	        	  if((int)G[G[1][i]].size()!=0){
	        		  cout << "POSSIBLE" << endl;
	        		  return 0;
	        	  }
	          }

	          cout << "IMPOSSIBLE" << endl;

	          return 0;
}



Measured memory_bytes: 8440
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, string.sub(k, i, i)) end local r = io.read local u = table.unpack return function() return r(u(a)) end end})
local N, K, Q = read.nnn()
local A = {}
for i=1, Q do
    A[i] = read.n()
end
local P = {}
for i=1,N do
    P[i] = K
end
for i=1,N do
    P[i] = P[i] - Q
end
for i=1,Q do
    P[A[i]] = P[A[i]] + 1
end
for i=1,N do
    print(P[i] > 0 and "Yes" or "No")
end

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

An = sorted(map(int, input().split()), reverse=True)
Bn = sorted(map(int, input().split()), reverse=True)
Cn = sorted(map(int, input().split()), reverse=True)


def f(xn, yn, zn):
    tn = [0] * N
    num = 0
    j = 0

    for i in range(N):
        while j <= N - 1 and xn[i] < yn[j]:
            num += zn[j]
            j += 1
        tn[i] = num

    return tn


def main():
    Zn = [1] * N

    Zn = f(Bn, Cn, Zn)
    Zn = f(An, Bn, Zn)

    print(sum(Zn))
    return


main()


Measured memory_bytes: 23924
n, x, y = gets.chomp.split.map(&:to_i)

h = Hash.new(0)

def min(a,b)
  a < b ? a : b
end

# iとjの距離
1.upto(n) do |i|
  i.upto(n) do |j|
    next if i == j
    len = min(min((j-i).abs, (x-i).abs + 1 + (y-j).abs), (x-j).abs + 1 + (y-i).abs)
    h[len] += 1
  end
end

(n-1).times do |i|
  puts h[i+1]
end







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

using namespace std;

int main(){
        int N, M;
        cin>>N;
        vector <string> s(N);
        for(int i=0;i<N;i++){
                cin>>s[i];
        }
        int res=0;
        cin>>M;
        vector <string> t(M);
        for(int i=0;i<M;i++){
                cin>>t[i];
        }
        for(int i=0;i<N;i++){
                int vres=0;
                string taka=s[i];
                for(int j=0;j<N;j++){
                        if(taka==s[j]){
                                vres++;
                        }
                }
                for(int j=0;j<M;j++){
                        if(taka==t[j]){
                                vres--;
                        }
                }
                res=max(vres, res);
        }
        cout<<res<<endl;
        return 0;
}


Measured memory_bytes: 256
a=int(input())
b=int(input())
c=int(input())
x=int(input())
d=0
for i in range(a+1):
    for j in range(b+1):
        if (x-500*i-100*j)%50==0 and (x-500*i-100*j)/50<=c and (x-500*i-100*j)>=0:
            d+=1
print(d)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL maxcha(LL a,LL b,LL c)
{
	return max(a,max(b,c))-min(a,min(b,c));
}
LL cal(LL n,LL m)
{
    LL ans=1e18;
    for(int i=1; i<n; i++)
    {
        LL h=(n-i)/2;
        ans=min(ans,maxcha(i*m,h*m,(n-i-h)*m));
			
		LL w=m/2;
		ans=min(ans,maxcha(i*m,(n-i)*w,(n-i)*(m-w)));
    }
    //cout<<ans<<endl;
    return ans;
}
int main()
{
    LL n,m;
    cin>>n>>m;
    LL  maxx=max(n,m),minn=min(n,m);
    if(maxx%3==0||minn%3==0)
    {
        cout<<0<<endl;
    }
    else
    {
        cout<<min(cal(n,m),cal(m,n))<<endl;;
    }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){
	
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ld i,j,k,l,n;
	cin>>n;
	ld an; ll v=n;
	if(v%3==0){
		an=(n/3);
		cout<<fixed<<setprecision(10);
		cout<<(an*an*an)<<endl;
	}
	else{
		ld r=(n/3.0);
		an=(r*r*r);
		cout<<fixed<<setprecision(10);
		cout<<an<<endl;
	}
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <queue>
#include <vector>
#include <utility>
#define INF 10000000
using namespace std;
typedef pair<int,int> p;
struct edge{
  int to,cost;
};
vector<edge> V[10];
int d[10];

void dijkstra(int s) {
  priority_queue< p,vector<p>,greater<p> > que;
  for(int i=0;i<10;i++) {
    d[i] = INF;
  }
  d[s] = 0;
  que.push(p(0,s));

  while(!que.empty()) {
    p v = que.top();que.pop();
    int x = v.second;
    if(d[x] < v.first) continue;
    for(unsigned int i=0;i<V[x].size();i++) {
      edge e = V[x][i];
      if(d[e.to] > d[x] + e.cost) {
	d[e.to] = d[x] + e.cost;
	que.push(p(d[e.to], e.to));
      }
    }
  }
}

int main() {
  int n,sum=0;

  while(cin >> n) {
    if(n == 0) break;
    for(int i=0;i<10;i++) {
      V[i].clear();
    }
    for(int i=0;i<n;i++) {
      int a,b,c;
      edge es;
      cin >> a >> b >> c;
      es.to = b;
      es.cost = c;
      V[a].push_back(es);
      es.to = a;
      V[b].push_back(es);
    }
    int top = INF,topnum = 0;
    for(int i=0;i<10;i++) {
      dijkstra(i);
      for(int j=0;j<10;j++) {
	if(d[j] != INF) {
	  sum += d[j];
	}
      }
   
      if(sum != 0 && sum < top) {
	top = sum;
	topnum = i;
      }
      sum = 0;
    }
    cout << topnum << " " << top << endl;
  }
}

Measured memory_bytes: 0
import itertools
import math
n = int(input())
x,y = [0] * n, [0] * n
for i in range(n):
  dx,dy = map(int,input().split())
  x[i], y[i] = dx, dy
ans = 0
for i in itertools.permutations(range(n)):
  i = list(i)
  for j in range(n - 1):
    ans += math.sqrt(pow(x[i[j]] - x[i[j + 1]], 2) + pow(y[i[j]] - y[i[j + 1]], 2))
num = 1
for i in range(n):
  num *= i + 1
print(ans / num)

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

typedef long long ll;

int main()
{
    ll a = 100, count = 0, x;
    cin >> x;

    while (a < x)
    {
        count++;
        a *= 1.01;
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int main()
{
	FastIO;
	string s;
	cin>>s;
	int a=(s[0]-'0')*10+s[1]-'0';
	int b=(s[2]-'0')*10+s[3]-'0';
	if(a<=12&&b<=12&&a!=0&&b!=0)cout<<"AMBIGUOUS";
	else if(a<=12&&a!=0)cout<<"MMYY";
	else if(b<=12&&b!=0)cout<<"YYMM";
	else if(a>12&&b>12||a==0||b==0)cout<<"NA";

}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <sstream>
#include <climits>
#include <map>
#include <stack>
using namespace std;
#define M_PI 3.141592
#define toRad 2.0*M_PI/360.0
#define inin(x) int x;cin>>x;
#define all(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" "<<x<<endl;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define pri_max 60000
typedef pair<int, int> pii;

bool memo[pri_max] = {};
vector<int> pri;
void calc()
{
	for (int i = 2; i < pri_max; i++)
	{
		if (memo[i] == false)
		{
			pri.push_back(i);
			for (int l = i; l < pri_max; l += i)
			{
				memo[l] = true;
			}
		}
	}
}
int main()
{
	calc();
	int n;
	while (cin >> n&&n)
	{
		int ans = 0;
		for (int i = 0; i < pri.size(); i++)
		{
			if (n - pri[i] <= 0)break;
			ans += binary_search(all(pri), n - pri[i]);
		}
		ans /= 2;
		if (n % 2 == 0 && binary_search(all(pri), n / 2))ans++;
		cout << ans << endl;
	}
}

Measured memory_bytes: 1328
import java.util.*

fun main(args: Array<String>) {
    val mod = 1000000007L

    when (readInt()) {
        1 -> println("Hello World")
        2 -> println(readInt()+readInt())
    }
}

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toInt)


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

int main(){
  
  string s,t;
  int isOK = 1;
  
  cin >> s >> t;
  
  for(int i=0; i<s.length(); i++){
    if(s[i]!=t[i]){
      isOK = 0;
      break;
    }
  }
  
  if(isOK==1){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }
  
  return 0;
}

Measured memory_bytes: 3628
#include <iostream>
    using namespace std;
     
    long long gcd ( long long n , long long x)
    {
    if( x == 0)return n;
    gcd(x,n%x);
    }
     
    int main()
    {
    long long n , x;
    cin >> n >> x;
    cout << 3 * ( n - gcd( n , x) ) << endl;
    return 0;
    }

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

def main():
    N = int(input())
    a = list(map(int, input().split()))

    left = [0] * N
    left[0] = a[0]
    for i in range(1, N):
        left[i] = left[i-1] + a[i]
    # print(left)
    ans = abs(left[-1] - 2 * left[0])
    for i in range(1, N-1):
        ans = min(ans, abs(left[-1] - 2 * left[i]))
    print(ans)

if __name__ == "__main__":
    main()

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

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, __VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

#define MOD 1000000007
#define INF 1000000000
#define MAX_N 200010

// 二次元のマス目を左上から右下へ移動するときのパターン数
// DP で考えると各マス目にパスカルの三角形が現れることがわかる
// つまり組み合わせで、 nCr の形で表すことができることがわかる
// nCr は今回は n = H-1+W-1, r = W-1(またはH-1) となる
// A, B で制限された領域の直前のところの nCr をもとめ、
// そこから一つ下への移動は 1 パターン。
// そこから左下へまた nCr を使って組み合わせを求め、
// それらの積を各列に関して足した和が答え

ll H, W, A, B;

// 0! ～ N! までの階乗を保管する配列の作成 (mod MOD をとってある)
// O(n)
// 大体 N <=10^5 && 10^9+7 の mod を求める時に必要になるはず
// fact[i] で i! にアクセス
ll fact[MAX_N];
ll fact_inv[MAX_N];
ll N;  // あらかじめ N に値を入れておく

// x の n 乗 を m で余りをとったもの
ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while ( n > 0) {
        if (n & 1) { res = res * x % mod; } // 最下位ビットが立っているときに x^(2^i) を掛ける
        x = x * x % mod;                    // x を順次 2 乗していく
        n >>= 1;
    }
    return res;
}

// nCr
ll combination(ll n, ll r, ll mod) {
    assert(n <= N);
    assert(r <= n);
    ll ret = (fact[n] * fact_inv[n - r]) % mod;
    ret = (ret * fact_inv[r]) % mod;
    return ret;
}
ll combination(ll n, ll r) {
    return combination(n, r, MOD);
}

int main()
{
    cin >> H >> W >> A >> B;

    N = H + W;

    // 階乗の作成
    fact[0] = 1;
    for(int i = 1; i <= N; ++i) {
        fact[i] = (fact[i-1] * i) % MOD;
    }
    // N! の逆元 1/N! を二分累乗法で求める
    // フェルマーの小定理より a^-1 = a^(p-2) mod p -> (N!)^-1 = (N!)^(p-2) mod p
    fact_inv[N] = mod_pow(fact[N], MOD-2, MOD);     // mod_pow の定義は↑の方にある
    // 以下 1 / (N-1)! = N / N! であることを利用
    for(int i = N - 1; i >= 0; --i) {
        fact_inv[i] = (fact_inv[i + 1] * (i + 1)) % MOD;
    }

    ll ans = 0;
    for(ll i = B + 1; i <= W; ++i) {
        ll tmp_h = H - A;
        ll tmp_w = W - i + 1;
        ll pat1 = combination(i - 1 + tmp_h - 1, i - 1);
        pat1 %= MOD;
        ll pat2 = combination(tmp_w - 1 + A - 1, tmp_w - 1);
        pat2 %= MOD;
        ans += pat1 * pat2;
        ans %= MOD;
    }
    printf("%lld\n", ans);

    return 0;
}


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

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] vow = {"a","e","i","o","u"};
    String str = in.readLine();
    boolean vowFlg = false;
    for(int i=0; i<5; i++) {
      if(str.equals(vow[i]))
        vowFlg = true;
    }
    System.out.println(vowFlg==true?"vowel":"consonant");
  }
}

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

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

    stack<char> s;
    for (int i = 0; i < N; i++) {
        if (s.empty()) {
            s.push(S[i]);
        } else {
            if (s.top() == '(' && S[i] == ')') {
                s.pop();
            } else {
                s.push(S[i]);
            }
        }
    }

    string left, right;
    while (!s.empty()) {
        char c = s.top(); s.pop();
        if (c == '(') right += ')';
        if (c == ')') left += '(';
    }

    cout << left + S + right << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    int c=sc.nextInt();

    int o1=a-b;
    int o2=c-o1;
    if(o2>0){
      System.out.println(o2);
    }else{
      System.out.println(0);
    }
  }
}


Measured memory_bytes: 21844
import heapq

INF = 1000000000


def dijkstra(G, d, s):
    h = []
    d[s] = 0
    heapq.heappush(h, (0, s))

    while len(h) != 0:
        p = heapq.heappop(h)
        v = p[1]
        if d[v] < p[0]:
            continue
        for e in G[v]:
            if d[e[0]] > d[v] + e[1]:
                d[e[0]] = d[v] + e[1]
                heapq.heappush(h, (d[e[0]], e[0]))


def main():
    N, M = map(int, input().split())
    p = [0] * M
    q = [0] * M
    c = [0] * M
    for i in range(M):
        p[i], q[i], c[i] = map(int, input().split())
        p[i] -= 1
        q[i] -= 1
    plat = []
    for i in range(N):
        plat.append(dict())
    v_count = 0
    for i in range(M):
        p1 = plat[p[i]]
        if not c[i] in p1:
            p1[c[i]] = v_count
            v_count += 1
        p2 = plat[q[i]]
        if not c[i] in p2:
            p2[c[i]] = v_count
            v_count += 1
    for i in range(N):
        plat[i][-1] = v_count
        v_count += 1

    G = [[] for _ in range(v_count)]
    for i in range(M):
        p1 = plat[p[i]][c[i]]
        q1 = plat[q[i]][c[i]]
        G[p1].append((q1, 0))
        G[q1].append((p1, 0))
    for i in range(N):
        out = plat[i][-1]
        for v in plat[i].values():
            if v == -1:
                continue
            G[v].append((out, 0))
            G[out].append((v, 1))

    start = plat[0][-1]
    goal = plat[N - 1][-1]

    d = [INF for _ in range(v_count)]

    dijkstra(G, d, start)

    if d[goal] == INF:
        print(-1)
    else:
        print(d[goal])


if __name__ == '__main__':
    main()


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

int main(void) {
	int x, a, b;

	cin >> x >> a >> b;
	int da = (x - a) * (x - a);
	int db = (x - b) * (x - b);
	if (da < db)
		cout << "A\n";
	else
		cout << "B\n";

	return 0;
}


Measured memory_bytes: 256
import math

n, h = list(map(int, input().split()))
a, b = [], []
for _ in range(n):
    a_i, b_i = list(map(int, input().split()))
    a.append([a_i, 'a'])
    b.append([b_i, 'b'])
damages = sorted(a+b, reverse = True)

ans = 0
for d, is_ab in damages:
    if is_ab == 'a':
        ans += math.ceil(h/d)
        break
    else:
        h -= d
        ans += 1
        if h <= 0:
            break

print(ans)

Measured memory_bytes: 34500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9;
const ll MOD = 1e9 + 7;

//累積二乗法

ll mod_pow(ll x, ll n){
  if(n == 0) return 1;
  ll res = mod_pow(x * x % MOD, n / 2);
  if(n & 1) res = res * x % MOD;
  return res;
}

//階乗
ll mod_fact(ll n){
  ll result = 1;
  for(ll i = 1; i <= n; i++){
    result = result * i % MOD;
  }
  return result;
}

int main(){
  ll n, a ,b;
  cin >> n >> a >> b;
  ll ans;
  ll x1 = n, x2 = n;
  for(ll i = 1;i <= a-1; i++) {
    x1 = x1 * (n - i) % MOD;
  }
  for(ll i = 1;i <= b-1; i++) {
    x2 = x2 * (n - i) % MOD;
  }
  ans = (mod_pow(2, n) - 1 - x1 * mod_pow(mod_fact(a), MOD-2) % MOD - x2*mod_pow(mod_fact(b), MOD-2) % MOD) % MOD;
  if(ans < 0) ans += MOD;
  cout << ans <<endl;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define MAX 100000
typedef long long llong;

int n, k; 
llong T[MAX];

int check(llong P) {
    int i = 0;
    for(int j = 0; j < k; j++){
        llong s = 0; 
        while(s + T[i] <= P){
            s += T[i];
            i++;
            if ( i == n ) return n;
        } 
        
    }
    return i;
}

int solve() {
    llong left = 0; 
    llong right = 100000 * 10000;
    llong mid;
    while(right-left>1){
        mid = (left + right) / 2;
        int v = check(mid); 
        if(v >= n) right = mid;
        else left = mid;
    }
    return right;
}
        
int main() {
    cin>>n>>k;
    for(int i = 0; i < n; i++) cin>>T[i];  
    llong ans = solve();
    cout << ans << endl;
    return 0;
}


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

#define ipr pair<int, int>
#define pb push_back
#define ff first
#define ss second
#define fr(i, j, k) for (int i = j; i < k; i++)
#define rf(i, j, k) for (int i = j; i >= k; i--)
#define ll unsigned long long
#define int long long
#define ld long double
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mp make_pair
#define cnt_ones(x) __builtin_popcountll(x)

#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

const int Maxn = (int)1e5 + 1;
const ld pi = acos(-1);
const int mod = (int)1e9 + 7;
const int inf = (int)1e18;

template <class T>
ostream &operator<<(ostream &out, vector<T> &A) {
    fr(i, 0, (int)A.size()) out << A[i] << " ";
    return out;
}


int fastmod(int e, int x) {
    int res = 1;
    e %= mod;
    if (e == 0) return 0;
    while (x > 0) {
        if (x & 1) res = (res * e) % mod;
        x >>= 1;
        e = (e * e) % mod;
    }
    return res;
}

int modulo_inverse(int a) { return fastmod(a, mod - 2); }

int cal_factorial(int n) {
    int ans = 1;
    fr(i,2,n+1){
        ans = ans*i;
        ans %= mod;
    }
    return ans;
}

int binent(int n, int r) {
    int ans = 1;
    fr(i,n-r+1,n+1){
        ans = (ans*i)%mod;
    }
    //cout << ans << " guess " << endl;
    return ans;
}

int32_t main() {
    IOS     int n,a,b;  cin>>n>>a>>b;
    int temp1 = fastmod(2,n)-1;
    //cout << binent(5,2) << " ok " << endl;
    int temp2 = ((binent(n,a)*modulo_inverse(cal_factorial(a))) % mod + 
                (binent(n,b)*modulo_inverse(cal_factorial(b)))%mod)%mod;
                //cout << temp2 << " ok " << endl;
    int ans = (temp1-temp2 + mod)%mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624
from collections import deque
N = int(input())
a = list(map(int, input().split()))
ans = deque([])
for i in range(N):
    if (i+1) % 2 == N % 2:
        ans.appendleft(a[i])
    else:
        ans.append(a[i])
print(*ans, sep=" ")


Measured memory_bytes: 25416
#include <bits/stdc++.h>
    using namespace std;
     
    const int maxn = 1e5 + 20;
     
    bool visited[maxn];
    int n, m, a, b, outDegree[maxn], dis[maxn];
    vector<int> graph[maxn];
     
    void dfs(int i) {
        visited[i] = 1;
        for (int x : graph[i]) {
            if (!visited[x]){
                dis[x] = dis[i] + 1; 
                dfs(x);
            }
            if (dis[x] > dis[i]) {
                if (outDegree[x] % 2 == 0){
                    outDegree[i]++;
                    cout << i << " " << x << endl;
                }
                else{
                    outDegree[x] ++;
                    cout << x << ' '  << i << endl;
                }
            }
        }
    }
    int main() {
      
      ios_base::sync_with_stdio(false);
      cin.tie(0);
        int n, m;
        cin >> n >> m;
        if (m % 2 == 1)
            return cout << -1 << endl, 0;
        for (int i = 0; i < m; i++) {
            cin >> a >> b;
            graph[a].push_back(b);
            graph[b].push_back(a);
        }
     
        dfs(1);    
    }

Measured memory_bytes: 15616
a,b,c = input().split()
a = int(a)
b = int(b)
c = int(c)
L = []
L.append(a)
L.append(b)
L.append(c)
L.sort(reverse=True)
K = int(input())
ans = L[0]*2**K + L[1] + L[2]
print(ans)


Measured memory_bytes: 3060
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let a: usize = scan(tokens);
    let b: usize = scan(tokens);
    println!("{}", 6 - a - b);
}


Measured memory_bytes: 4352
/**********************************JAI SAI RAM*****************************************/
//HELP IN CODEFORCES ROUND 638 DIV 2

#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int ll;
ll P=1000000007;
ll MAX=P*(P-7);
ll MIN=-1*MAX;
const int sizes=100001;
const int BLK = 1200;

int main()
{
    ll i,j,k,l,m,n,o,p,q,r,s,t;
    string a;
    cin>>a;
    if(a=="ABC")
    {
        cout<<"ARC\n";
    }
    else 
    cout<<"ABC\n";
    return 0;
}


Measured memory_bytes: 3628