akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main()
{
    int n, ans = 0;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    rep(i, n)
    {
        if (a[a[i] - 1] == i + 1)
            ans++;
    }
    cout << ans / 2 << endl;
    return 0;
}


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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<long long,long long> Pdd;

int main() {
    ll n,k;cin>>n>>k;
    vector<ll> a(n),f(n);
    rep(i,n) cin>>a[i];
    rep(i,n) cin>>f[i];
    Sort(f);Sort(a);Reverse(f);
    vector<Pdd> af(n);
    rep(i,n)  af[i]=Pdd(a[i]*f[i],f[i]);
    ll left=0,right=2e18;
    int cnt=0;
    while(cnt!=100){
        cnt++;
        ll mid=(left+right)/2;
        ll sum=0;
        rep(i,n){
            if(af[i].first>mid){
                sum+=(af[i].first-mid-1)/af[i].second+1;
            }
        }
        if(sum>k){
            left=mid;
        }
        else if(sum<=k){
            right=mid;
        }
    }
    right=max(0ll,right-500ll);
    while(1){
        ll sum=0;
        rep(i,n){
        if(af[i].first>right){
            sum+=(af[i].first-right-1)/af[i].second+1;
            }
        }
        if(sum<=k){cout<<right<<endl;return 0;}
        right++;   
    }
        
    return 0;
}


Measured memory_bytes: 6656
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc087b
{
    class Program
    {
        static void Main(string[] args) {
            const int valueA = 500;
            const int valueB = 100;
            const int valueC = 50;
            var A = int.Parse(Console.ReadLine());
            var B = int.Parse(Console.ReadLine());
            var C = int.Parse(Console.ReadLine());
            var X = int.Parse(Console.ReadLine());
            var numberOfPattern = 0;
            for(var iA = 0; iA <= A; ++iA) {
                if(valueA * iA > X) {
                    continue;
                }
                for(var iB = 0; iB<=B; ++iB) {
                    var hundreads = valueA * iA + valueB * iB;
                    if(hundreads > X) {
                        break;
                    }
                    if((X - hundreads) / valueC <= C) {
                        ++numberOfPattern;
                    } else {
                        continue;
                    }
                }
            }

            Console.WriteLine(numberOfPattern);
        }
    }
}


Measured memory_bytes: 11220
import sys
input = sys.stdin.readline
n = int(input())
a =[2] + list(map(int,input().split()))

b = [3]*(n+1)

for i in range(n,n//2,-1):
    if a[i] == 1:
        b[i] = 1
    else:
        b[i] = 0
#print(b)
for i in range(n//2,0,-1):
    isum = 0
    for k in range(2,n//i+1):
        isum += b[i*k]
    #print(isum)
    if a[i] == isum%2:
        b[i] = 0
    else:
        b[i] = 1
ans = []

for i in range(1,len(b)):
    if b[i] == 1:
        ans.append(i)
print(sum(b)-3)
for i in ans:
    print(i)




Measured memory_bytes: 68472
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using p = pair<int, int>;
 
int main() {
  string s;
  cin >> s;

  if (s == "AAA" || s == "BBB" ) cout << "No" << endl;
  else cout << "Yes" << endl;

  return 0;
}


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

/* 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
 
template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/

#define ar array
#define ll long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define vt vector 
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
  
#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)
 
template<class T> bool umin(T& a, const T& b) {
	return b<a?a=b, 1:0;
}
template<class T> bool umax(T& a, const T& b) { 
	return a<b?a=b, 1:0;
} 
 
 
template<class A> void read(vt<A>& v);
template<class A, size_t S> void read(ar<A, S>& a);
template<class T> void read(T& x) {
	cin >> x;
}
void read(double& d) {
	string t;
	read(t);
	d=stod(t);
}
void read(long double& d) {
	string t;
	read(t);
	d=stold(t);
}
template<class H, class... T> void read(H& h, T&... t) {
	read(h);
	read(t...);
}
template<class A> void read(vt<A>& x) {
	EACH(a, x)
		read(a);
}
template<class A, size_t S> void read(array<A, S>& x) {
	EACH(a, x)
		read(a);
}
 
string to_string(char c) {
	return string(1, c);
}
string to_string(bool b) {
	return b?"true":"false";
}
string to_string(const char* s) {
	return string(s);
}
string to_string(string s) {
	return s;
}
string to_string(vt<bool> v) {
	string res;
	FOR(sz(v))
		res+=char('0'+v[i]);
	return res;
}
 
template<size_t S> string to_string(bitset<S> b) {
	string res;
	FOR(S)
		res+=char('0'+b[i]);
	return res;
}
template<class T> string to_string(T v) {
    bool f=1;
    string res;
    EACH(x, v) {
		if(!f)
			res+=' ';
		f=0;
		res+=to_string(x);
	}
    return res;
}
 
template<class A> void write(A x) {
	cout << to_string(x);
}
template<class H, class... T> void write(const H& h, const T&... t) { 
	write(h);
	write(t...);
}
void print() {
	write("\n");
}
template<class H, class... T> void print(const H& h, const T&... t) { 
	write(h);
	if(sizeof...(t))
		write(' ');
	print(t...);
}
 
void DBG() {
	cerr << "]" << endl;
}
template<class H, class... T> void DBG(H h, T... t) {
	cerr << to_string(h);
	if(sizeof...(t))
		cerr << ", ";
	DBG(t...);
}
#ifdef _DEBUG
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

const int INF = 1e9 + 10;
const int mod = 1e9 + 7;
const ll LLINF = 1e18 + 10;



void solve()
{
    int a,b,c;
    read(a,b,c);
    if(c*b < a){
        cout << "No\n";
    }
    else{
        cout << "Yes\n";
    }
}
 
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
 
	int t=1;
	//read(t);
	FOR(t) {
		//write("Case #", i+1, ": ");
		solve();
	}
}



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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
import bisect
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#############
# Main Code #
#############

N = inputI()

if N==2:
  print(1)
  exit()

def Base_10_to_n(X, n):
  if (int(X/n)):
     return Base_10_to_n(int(X/n), n)+" "+str(X%n)
  return " "+str(X%n)

def make_divisors(n):
  divisors = []
  for i in range(2, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)

  # divisors.sort()
  return divisors

d = make_divisors(N)+make_divisors(N-1)



ans = 0
for x in d:
  l = list(Base_10_to_n(N, x).split())
  for i in l[::-1]:
    if i == "0":
      continue
    else:
      if i == "1":
        ans += 1
        break
      else:
        break

print(ans+2)


Measured memory_bytes: 74616
#include<bits/stdc++.h>
#define rep(i,l,r) for (int i=l;i<=r;i++)
using namespace std;
typedef long long ll;
ll a,b,c,ans,N,M,T,q[100007],w[100007];
int main(){
	scanf("%lld",&N);
	rep(i,1,N+1) scanf("%lld",&q[i]);
	rep(i,1,N) scanf("%lld",&w[i]);
	ll ans=0;
	rep(i,1,N){
		int mi=min(q[i],w[i]);
		q[i]-=mi;w[i]-=mi;ans+=mi;
		mi=min(q[i+1],w[i]);
		q[i+1]-=mi;ans+=mi;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>

typedef long long ll;

using namespace std;


int main()
{
	int startX, startY;
	while (scanf("%d %d", &startX ,&startY), startX | startY)
	{
		int n;
		scanf("%d", &n);
		int sx[126];
		int sy[126];
		for (int i = 0; i < n; ++i)
		{
			int a, b;
			scanf("%d %d", &a, &b);
			sx[i] = a;
			sy[i] = b;
		}

		bool alive = true;
		bool schrodinger[16][16];
		memset(schrodinger, 0, sizeof(schrodinger));
		schrodinger[startY][startX] = true;
		for (int i = 0; alive && i < n; ++i)
		{
			bool next[16][16];
			memset(next, 0, sizeof(next));
			for (int y = 0; y < 10; ++y)
			{
				for (int x = 0; x < 10; ++x)
				{
					if (!schrodinger[y][x])
						continue;

					int d[] = { -2, 2 };
					for (int j = 0; j < 2; ++j)
					{
						for (int k = -1; k <= 1; ++k)
						{
							int ya = y + d[j];
							int xa = x + k;
							int yb = y + k;
							int xb = x + d[j];
#define in(pos) (0 <= pos && pos < 10)
							if (in(ya) && in(xa))
								next[y+d[j]][x+k] = true;
							if (in(yb) && in(xb))
								next[y+k][x+d[j]] = true;
						}
					}
				}
			}

			alive = false;
			memset(schrodinger, 0, sizeof(schrodinger));
			for (int j = -1; j <= 1; ++j)
			{
				for (int k = -1; k <= 1; ++k)
				{
					int ty = sy[i] + j;
					int tx = sx[i] + k;
					if (in(ty) && in(tx) && next[ty][tx])
					{
						schrodinger[ty][tx] = true;
						alive = true;
					}
				}
			}
		}

		puts(alive ? "OK" : "NA");
	}

	return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)
#define RREP(i, a, n) for(int i=n-1; i>=a; i--)
typedef long long ll;
const int INF = 1e9;

int n, l;
int a[100001];
int mx = 0;
int idx;
int main()
{
	cin >> n >> l;
	REP(i, 0, n) cin >> a[i];

	REP(i, 0, n - 1) {
		if (mx < a[i] + a[i + 1]) {
			mx = a[i] + a[i + 1];
			idx = i + 1;
		}
	}

	if (mx < l) {
		cout << "Impossible" << endl;
		return 0;
	}

	
	cout << "Possible" << endl;
	REP(i, 1, idx) cout << i << endl;
	RREP(i, idx, n) cout << i << endl;

	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#include<iostream>
using namespace std; 
int main(){
int n;
cin>>n;
vector<tuple<string, int ,int > >res;
string s;
int p;
for(int i=0;i<n;i++){
cin>>s>>p;
res.push_back(make_tuple(s,p,i+1));
}
sort(res.begin(),res.end());
for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
    if((get<0>(res[i]).compare(get<0>(res[j])))==0){
        if(get<1>(res[i])<get<1>(res[j])){
            swap(res[i],res[j]);
        }}
    }
}
for(int i=0;i<n;i++){
cout<<get<2>(res[i])<<endl;
}return 0;	
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int a, b, c, d;
bool onlyone(int x){
	int cnt = 0;
	if(a == x) cnt++;
	if(b == x) cnt++;
	if(c == x) cnt++;
	if(d == x) cnt++;
	return cnt == 1;
}

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

	cin >> a >> b >> c >> d;
	if(!onlyone(1)){
		cout << "NO" << endl;
		return 0;
	}

	if(!onlyone(9)){
		cout << "NO" << endl;
		return 0;
	}

	if(!onlyone(7)){
		cout << "NO" << endl;
		return 0;
	}

	if(!onlyone(4)){
		cout << "NO" << endl;
		return 0;
	}

	cout << "YES" << endl;
}


Measured memory_bytes: 256
while True:
    H,W = map(int, input().split())
    if H == 0 and W == 0: break
    for j in range(H):
        for i in range(W):
            if i == 0 or j == 0 or i == W-1 or j == H-1:
                print("#", end="")
            else:
                print(".", end="")
        print()
    print()



Measured memory_bytes: 7008
import bisect

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

    L = sorted(L)
    
    ans = 0
    #for i in range(N-1):
    #    for j in range((i+1), N):    
    #        c = bisect.bisect_left(L, L[i] + L[j], j+1)
    #        print(c)
    #        ans += c - j - 1

    for i in range(N):
        for j in range(i+1, N):
            m = bisect.bisect_right(L, L[j]-L[i])
            ans += max(i-m, 0)

    print(ans)

if __name__ == '__main__':
    main()



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

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

        int h, m, s;
        h=x/3600;
        m=(x-h*3600)/60;
        s=x-h*3600-60*m;

        cout << h << ":" << m <<":" << s << endl;
        return 0;
}

Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const ll mod = 1e9+7;
const int N = 2e5+6;
int bit[55][55];
void add(int x, int y){
	for(int i=x;i>0;i-=(i&-i)){
		for(int j=y;j>0;j-=(j&-j)){
			bit[i][j]++;
		}
	}
}
ll get(int x, int y){
	ll ret =0;
	for(int i=x;i<55;i+=(i&-i)){
		for(int j=y;j<55;j+=(j&-j)){
			ret+=bit[i][j];
		}
	}
	return ret;
}
ll get2(ll x){
	ll ret = 1;
	while(x%2==0){
		ret++;
		x/=2;
	}
	return ret;
}
ll get5(ll x){
	ll ret = 1;
	while(x%5==0){
		ret++;
		x/=5;
	}
	return ret;
}
void solve(){
	int n; 
	cin>>n;
	ll ans = 0; 
	for(int i=1;i<=n;i++){
		ld inp; 
		cin>>inp; 
		ll trt = llround(inp*1e9);
		ll x = get2(trt);
		ll y = get5(trt);
		ll xp = max(1ll,20-x);
		ll yp = max(1ll,20-y);
		ans+=get(xp,yp);
		add(x,y);
	}
	cout<<ans<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1; 
//	cin>>t; 
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define F first
#define S second
#define int long long
#define mod 1000000007
#define mmod 998244353
#define all(v) v.begin(), v.end()
#define INF LLONG_MAX/3
using namespace std;
int mypow(int a, int b, int c) {
	if (b == 0)return 1;
	if (b % 2)return mypow(a, b - 1, c)*a%c;
	int z = mypow(a, b / 2, c);
	return z * z%c;
}
int x[200000], y[200000];
signed main() {
	int n, ans = 0;
	cin >> n;
	f(i, n) {
		cin >> y[i];
		x[y[i] - 1]++;
	}
	f(i, n) {
		ans += x[i] * (x[i] - 1) / 2;
	}
	f(i, n) {
		cout << ans - x[y[i] - 1] + 1 << endl;
	}
}

Measured memory_bytes: 4736
K,N = map(int,input().split())
A = [int(x) for x in input().split()]
B = []
for i in range(N):
    if i != N-1:
        B.append(max(K -abs(A[i]-A[i+1]), abs(A[i]-A[i+1])))
    else:
        B.append(max(K - abs(A[0]-A[N-1]),abs(A[0]-A[N-1])))
print(min(B))

Measured memory_bytes: 26444
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

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

    int k, ans;
    cin >> k;
    if (k % 2 == 0) ans = (k / 2) * (k / 2);
    else ans = (k / 2) * (k / 2 + 1);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>
#define PI 3.14159265358979323846264338327950288L

using namespace std;
int main()
{
  long double A, B, H, M, H_angle, M_angle, HM_angle;
  cin >> A >> B >> H >> M;

  H_angle = (long double)H * 30.0 + (long double)M / 2.0;
  M_angle = (long double)M * 6.0;
  HM_angle = (long double)H_angle - (long double)M_angle;

  cout << fixed;
  cout << setprecision(20);
  cout << sqrtl(powl(A, 2.0) + powl(B, 2.0) - (long double)(2 * A * B * cosl(HM_angle * PI / 180.0))) << endl;
}


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

int d[10][10];
int dp[10][10][51][10][10][2];
#define INF (1<<28)
int F,M,O,H,W;
int dfs(int x,int y,int o,int l,int r,int f){
	int po = o;
	if(x < 0 || x >= W) return INF;
	if(y == H && o >= 0) return 0;
	if(o <= 0) return INF;
	if(dp[x][y][o][l][r][f] != -1) return dp[x][y][o][l][r][f];
	int base = 0;
	int ans = INF;
	if(f == 1){
		if(d[y][x] < 0) base += -(d[y][x]);
		else o = min(M,o+d[y][x]);
	}
	return dp[x][y][po][l][r][f] = min( dfs(x,y+1,o-1,x,x,1) , min( dfs(x-1,y,o-1,min(l,x-1),r,l==x) , dfs(x+1,y,o-1,l,max(r,x+1),r==x) ) ) + base;
}
int main(){
	while(cin >> W >> H && W){
		memset(dp,-1,sizeof(dp));
		cin >> F >> M >> O;
		for(int i = 0 ; i < H ; i++) for(int j = 0 ; j < W ; j++) cin >> d[i][j];
		int ans = INF;
		for(int i = 0 ; i < W ; i++) ans = min(ans,dfs(i,0,O-1,i,i,1));
		if(ans > F) cout << "NA" << endl;
		else cout << ans << endl;
	}
}

Measured memory_bytes: 0
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String args[]) {
		FastScanner scanner = new FastScanner();
		int n=scanner.nextInt();
		int k=scanner.nextInt();
		int h[]=new int[n];
		for(int i=0;i<n;i++){
			h[i]=scanner.nextInt();
		}
		Arrays.sort(h);
		int min=1000000000;
		for(int i=0;i<n-k+1;i++){
			int tmp=Math.abs(h[i]-h[i+k-1]);
			min=Math.min(min, tmp);
			
		}
		System.out.println(min);
	}
}


class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


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

int main(){
	int x1,x2,x3,x4;
  	int y1,y2,y3,y4;
  	cin>>x1;
  	cin>>y1;
  	cin>>x2;
  	cin>>y2;
  	
  	x3 = x2 - (y2 - y1);
	y3 = y2 + (x2 - x1);  	
	x4 = x3 - (y3 - y2);
  	y4 = y3 + (x3 - x2);
	printf("%d %d %d %d",x3,y3,x4,y4);
}

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

int get_iti(bool rev, int F) {
    if (rev) {
        if (F == 1) {
            return -1;
        } else {
            return 0;
        }
    } else {
        if (F == 1) {
            return 0;
        } else {
            return -1;
        }
    }
}

int main() {
    string S;
    cin >> S;
    vector<string>vec(S.size());
    vector<string>sentou;
    vector<string>usiro;
    for (int i=0; i< S.size(); i++) {
        vec.at(i) = S[i];
    }

    int64_t Q;
    cin >> Q;
    bool rev = false;
    for (int64_t i=0; i < Q; i++) {
        int op;
        cin >> op;
        if (op == 1) {
            rev = !rev;
        } else {
            int F;
            cin >> F;
            string C;
            cin >> C;
            int iti = get_iti(rev, F);
            if (iti == 0) {
                sentou.emplace_back(C);
            } else {
                usiro.emplace_back(C);
            }
        }
    }

    if (rev) {
        for (int i=usiro.size()-1; i >= 0; i--) {
            cout << usiro[i];
        }

        for (int i=vec.size()-1; i >= 0; i--) {
            cout << vec[i];
        }

        for (int i=0; i < sentou.size(); i++) {
            cout << sentou[i];
        }
    } else {
        for (int i=sentou.size()-1; i >= 0; i--) {
            cout << sentou[i];
        }
        for (int i=0; i < vec.size(); i++) {
            cout << vec[i];
        }

        for (int i=0; i < usiro.size(); i++) {
            cout << usiro[i];
        }
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 17264
#include <stdint.h>
#include <algorithm>
#include <bitset>
#include <functional>
#include <iostream>
#include <string>
#include <vector>

std::int64_t luca[128];

std::int64_t getLuca(int n) {
  if (luca[n]) return luca[n];
  luca[n] = getLuca(n - 1) + getLuca(n - 2);
  return luca[n];
}

int main(int argc, char *argv[]) {
  int a;
  luca[0] = 2;
  luca[1] = 1;
  std::cin >> a;
  std::cout << getLuca(a) << std::endl;
  ;

  return 0;
}


Measured memory_bytes: 256
x,k,d = map(int, input().split())
x = abs(x)
r = x//d
ans = 0
if r>k:
    ans = abs(x-k*d)
else:
    l = (k-r)%2
    if l==0:
        ans = abs(x-d*r)
    else:
        ans = abs(x-d*(r+1))
print(ans)

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

using namespace std;
using ll = long long;
using ld = long double;

namespace NyaGadget
{
	/**
	@brief 素因数分解ライブラリ
	@note
	 nを素因数分解する。
	 ans[i]がnだったとき、素因数分解して得られた積のなかにn個の素数iが含まれていることを表す。
	 例えば n=12 のとき ans[2] = 2, ans[3] = 1 となるので 12 = 2 * 2 * 3 と分かる。
	**/
	void PrimeFactorization(ll n, map<ll, ll>& ans)
	{
		for (ll i = 2; i * i <= n; i++)
		{
			while (n % i == 0)
			{
				ans[i]++;
				n /= i;
			}
		}
		if (n != 1)
			ans[n]++;
	}
}

#define all(collection) (collection).begin(), (collection).end()  // begin to end
#define ceil(a, b) ceil((ld) a / (ld) b);                         // div ceiling
#define each(e, collection) for(auto& e: collection)              // for each
#define rep(i, begin, end) for (ll i = begin; i < end; i++)       // repeat
#define repr(i, begin, end) for (ll i = begin; end < i; i--)      // repeat reverse
#define size(collection) ((ll) (collection).size())               // collection size

using namespace NyaGadget;


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

	ll max = sqrt(n);
	repr(i, max, 1)
	{
		if (n % i == 0)
		{
			cout << i + (n / i) - 2;
			return 0;
		}
	}
	
	cout << n - 1;
	return 0;
}


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    int i = 0;
    int res = 0;
    while (i < n) {
        int t = 1;
        while (a[i] == a[i + 1]) {
            t++;
            i++;
        }
        res += t % 2;
        i++;
    }
    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 640
import datetime
date_str = input()
heisei_str = "2019/04/30"
date_formatted = datetime.datetime.strptime(date_str, "%Y/%m/%d")
date_formatted_heisei = datetime.datetime.strptime(heisei_str, "%Y/%m/%d")

if date_formatted <= date_formatted_heisei :
    print("Heisei")
else :
    print("TBD")



Measured memory_bytes: 4720
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();
    String s = sc.next();

    for (int i = 0; i < s.length(); i++) {
      if (i == a && s.charAt(i) != '-') {
        System.out.println("No");
        return;
      } else if (i != a && s.charAt(i) == '-') {
        System.out.println("No");
        return;
      }
    }

    System.out.println("Yes");


  }

}


Measured memory_bytes: 21844
# https://atcoder.jp/contests/abc123/tasks/abc123_c


N = gets.to_i
A = gets.to_i
B = gets.to_i
C = gets.to_i
D = gets.to_i
E = gets.to_i

m = [A, B, C, D, E].min

puts ((N - 1) / m) + 5


Measured memory_bytes: 1788
def solve(n, m):
    assert m * 2 + 1 <= n
    res = []

    maxi = (n - 1) / 2
    if maxi % 2 == 0:
        maxi -= 1
    p = 1
    for i in xrange(maxi, 0, -2):
        q = p + i
        res.append([p, q])
        p += 1

    p = maxi + 1 + 1
    maxi += 1
    for i in xrange(maxi, 1, -2):
        q = p + i
        if q > n:
            continue
        res.append([p, q])
        p += 1

    st1 = set()
    st2 = set()
    assert len(res) >= m
    for (a, b) in res:
        assert 1 <= a <= n
        assert 1 <= b <= n
        assert a != b
        assert not (set([a, b]) & st1)
        st1 |= set([a, b])
        diff = abs(a - b)
        assert not (set([diff, n - diff]) & st2)
        st2 |= set([diff, n - diff])
    return res[:m]

solve(9, 4)
solve(6, 2)
solve(7, 3)
solve(15, 6)
solve(12, 5)
solve(10000, 4999)

'''
for i in xrange(1, 100):
    for j in xrange(1, (i - 1) / 2 + 1):
        # print i, j
        solve(i, j)
'''

(n, m) = map(int, raw_input().split())

assert m * 2 + 1 <= n

for a, b in solve(n, m):
    print a, b


Measured memory_bytes: 118324
#include<cstdio>
#include<vector>
#include<algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

vector<int> expr();
vector<int> set1();
vector<int> set2();
vector<int> alpha();

int idx;
char s[2000];

vector<int> S[5],U;

vector<int> calc_c(const vector<int> &A){
	vector<int> B;
	rep(i,U.size()) if(!binary_search(A.begin(),A.end(),U[i])) B.push_back(U[i]);
	return B;
}

vector<int> calc_u(const vector<int> &A,const vector<int> &B){
	vector<int> C;
	rep(i,A.size()) C.push_back(A[i]);
	rep(i,B.size()) C.push_back(B[i]);
	sort(C.begin(),C.end());
	C.erase(unique(C.begin(),C.end()),C.end());
	return C;
}

vector<int> calc_i(const vector<int> &A,const vector<int> &B){
	return calc_c(calc_u(calc_c(A),calc_c(B)));
}

vector<int> calc_d(const vector<int> &A,const vector<int> &B){
	return calc_i(A,calc_c(B));
}

vector<int> calc_s(const vector<int> &A,const vector<int> &B){
	return calc_u(calc_d(A,B),calc_d(B,A));
}

vector<int> expr(){
	vector<int> A=set1();
	while(s[idx] && s[idx]!=')'){
		char op=s[idx++];
		vector<int> B=set1();

		if     (op=='u') A=calc_u(A,B);
		else if(op=='i') A=calc_i(A,B);
		else if(op=='d') A=calc_d(A,B);
		else             A=calc_s(A,B);
	}
	return A;
}

vector<int> set1(){
	if(s[idx]=='c'){
		idx++;
		return calc_c(set1());
	}
	else return set2();
}

vector<int> set2(){
	vector<int> A;
	if(s[idx]=='('){
		idx++;
		A=expr();
		idx++;
	}
	else A=alpha();
	return A;
}

vector<int> alpha(){ return S[s[idx++]-'A']; }

int main(){
	while(1){
		U.clear();
		while(1){
			char c;
			int n;
			if(!~scanf(" %c%d",&c,&n)) return 0;
			if(c=='R') break;

			S[c-'A'].clear();
			rep(i,n){
				int e; scanf("%d",&e);
				S[c-'A'].push_back(e);
				U.push_back(e);
			}
			sort(S[c-'A'].begin(),S[c-'A'].end());
		}
		sort(U.begin(),U.end());
		U.erase(unique(U.begin(),U.end()),U.end());

		scanf("%s",s);
		idx=0;
		vector<int> res=expr();

		if(res.size()==0) puts("NULL");
		else rep(i,res.size()) printf("%d%c",res[i],i<(int)res.size()-1?' ':'\n');
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
using namespace std;

typedef long long ll;
typedef double db;
typedef long double ldb;

template<class T> inline void checkmin(T &a,const T &b){if(b<a) a=b;}
template<class T> inline void checkmax(T &a,const T &b){if(b>a) a=b;}

const int maxn=2e5+10;

vector <int> g[maxn];
bool visited[maxn];
int sum=0,n,ans=0,m;

void dfs(int x){
	visited[x]=true;
	sum++;
	for(int i=0;i<g[x].size();i++){
		int to=g[x][i];
		if(!visited[to]) dfs(to);
	}
}

int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		u--; v--;
		g[u].pb(v);
		g[v].pb(u);
	}
	for(int i=0;i<n;i++) if(!visited[i]){
		sum=0;
		dfs(i);
		ans=max(ans,sum);
	}
	printf("%d\n",ans);
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
using namespace std;
typedef long long ll;

ll a[3005][3005], dp[3005][3005][4];

int main() {
  ll R, C, n, ans = 0, r, c, v;
  cin >> R >> C >> n;
  rep(i, n) cin >> r >> c >> v, a[r][c] = v;

  rep(i, R + 1) rep(j, C + 1) rep(k, 3 + 1) {
    if (i - 1 >= 0) {
      chmax(dp[i][j][0], dp[i - 1][j][k]);
      chmax(dp[i][j][1], dp[i - 1][j][k] + a[i][j]);
    }
    if (j - 1 >= 0) {
      chmax(dp[i][j][k], dp[i][j - 1][k]);
      if (k - 1 >= 0) chmax(dp[i][j][k], dp[i][j - 1][k - 1] + a[i][j]);
    }
  }

  rep(k, 4) chmax(ans, dp[R][C][k]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 355796
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll e=0,f=0;
vector<int> G[200001];
map<P,ll> A;
void dfs(int x,int y,int z=-1){
    if(x==y){
        f=1;
        return;
    }
    for(auto i:G[x]){
        if(i==z) continue;
        if(f==1) continue;
        dfs(i,y,x);
        if(f==1) A[P(min(i,x),max(i,x))]+=1<<e;
    }
}
int main(){
    ll n,m,a[50],b[50],u,v,B[50],ans=0;
    cin>>n;
    rep(i,n-1){
        cin>>a[i]>>b[i];
        G[a[i]].push_back(b[i]);
        G[b[i]].push_back(a[i]);
    }
    cin>>m;
    rep(i,m) cin>>u>>v,dfs(u,v),e++,f=0;
    rep(i,n-1) B[i]=A[P(min(a[i],b[i]),max(a[i],b[i]))];
    for(int i=1;i<(1<<m);i++){
        ll num=0,x=0;
        for(int j=i;j!=0;j>>=1) num+=j&1;
        rep(k,n-1){
            int z=1;
            rep(j,m){
                if(i>>j&1){
                    if(B[k]>>j&1) z=0;
                }
            }
            if(z) x++;
        }
        if(num%2) ans+=ll(1)<<x;
        else ans-=ll(1)<<x;
    }
    cout<<(ll(1)<<n-1)-ans<<"\n";
}

Measured memory_bytes: 4992
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

ll func(int n){
  if(n==1) return 1LL;
  ll ret = n;
  n--;
  while(n != 0){
    ret *= n;
    n--;
  }
  return ret;
}

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(),a.end());
  
  int ma = a.back();
  int target;
  if(ma%2){
    target = ma/2+1;
  }else{
    target = ma/2;
  }
  
  int r=0;
  
  rep(i,n){
    if(abs(target-a[i]) < abs(target-r)){
      r = a[i];
    }
  }
  
  printf("%d %d",ma,r);
  
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>

using namespace std;
typedef long long ll;

int main(){
    ll a;
    string b;
    cin>>a>>b;
    string bsub1=b.substr(b.length()-2);
    string bsub2=b.substr(0,b.length()-2);
    ll ans=a*stoi(bsub2)+a*stoi(bsub1)/100;
    cout<<ans<<endl;
    return 0;
}

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

#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)

typedef long long ll;

int main(){
  int N;
  cin >> N;
  vector<string> S(N);
  vector<int> P(N), B(N);
  REP(i, N){
    cin >> S[i] >> P[i];
    B[i] = i+1;
  }

  while(S.size()){
    int ans = 0;
    for(int i = 1; i < S.size(); ++i){
      if(S[i] < S[ans]){
        ans = i;
      }
      else if((S[i] == S[ans] )&& (P[i] > P[ans])){
        ans = i;
      }
    }
    // cout << "B:"<<endl;
    // REP(i, B.size()){
    //   cout << B[i] << endl;
    // }
    // cout << endl;
    //cout << "ans" << ans << endl;
    cout << B[ans] << endl;
    S.erase(S.begin()+ans);
    P.erase(P.begin()+ans);
    B.erase(B.begin()+ans);


  }
  return 0;
}

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

int main(void) {
    string S;
    cin >> S;
    int k = S.length();
    int w = 0;
    for (int i = 0; i < k; ++i) {
        if (S[i] == 'o') {
            ++w;
        }
    }
    if (15 - k + w >= 8) {
        cout << "YES"
             << "\n";
    } else {
        cout << "NO"
             << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
cin>>s;
long long ans=0;
if(s[2]==s[3]&&s[4]==s[5]){
  ans=1;
}
if(ans==0){
  cout<<"No"<<endl;
}
else{
  cout<<"Yes"<<endl;
}
  return 0;
}


Measured memory_bytes: 256
//include
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath> 
#include <iomanip>
#include <math.h>
#include <utility>
#include <functional>
//using
using namespace std;
/*using vi = vector <int>;
using vs = vector <string>;
using vc = vector <char>;*/
//vector<vector<int> > hyou(N, vector<int>(N));
//define
#define int long long
#define rep(i,n) for(int i=0; i<n; i++)
#define print(n) cout<<n<<endl;
//グローバル変数宣言
int a=0,b=0,c=0,d=0,e=0,n,k;

int sa(int x,int y)
{
if (x>k)
{
   return k;
}else return x;
}

signed main(){
   cin>>n>>k;
   a=n/k;
   if (n-a*k>(a+1)*k-n)
{
   b= (a+1)*k-n;
}else b= n-a*k;

   print(b);
}


Measured memory_bytes: 3608
//=======================//
// coder: Andy - Tohrumi //
//=======================//

#include <bits/stdc++.h>

using namespace std;

#define fastio ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
#define mp make_pair
#define pb emplace_back
#define all(x) x.begin(), x.end()
#define rep(i, a, b) for(__typeof(b) i = a; i < b; i++)
#define Rep(i, a, b) for(__typeof(a) i = a; i > b; i--)

typedef vector<int> vi;		typedef vector<ll> vl;
typedef pair<int, int> ii; 	typedef vector<ii> vii;

// code start here //

int dp[200005][26], pos[200005][26];
string s;

signed main() {
	fastio;
	cin >> s;
	int n = s.length();
	rep(i, 0, 26) 
	{
		dp[n][i] = 1;
		pos[n][i] = n;
	}
	Rep(i, n - 1, -1) {
		rep(j, 0, 26) {
			if((s[i] - 'a') == j) {
				pos[i][j] = i;
				dp[i][j] = 1 + dp[i + 1][0];
				rep(k, 1, 26) {
					dp[i][j] = min(dp[i + 1][k] + 1, dp[i][j]);
				}
			}
			else {
				pos[i][j] = pos[i + 1][j];
				dp[i][j] = dp[i + 1][j];
			}
		}
	}
	int len = *min_element(dp[0], dp[0] + 26);
	int run = 0, c;
	while(len) {
		if(*min_element(dp[run], dp[run] + 26) == len) {
			len--;
			c = min_element(dp[run], dp[run] + 26) - dp[run];
			cout << (char)(c + 'a');
			run = pos[run][c];
		}
		run++;
	}
}


Measured memory_bytes: 44376
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

ll h[123];
ll tmp[123];

signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    int(n);
    if(!n)break;
    rep(i, 123)h[i] = 0;
    rep(i, 123)tmp[i] = 0;
    scn(n + 1, h);

    rep(i, n + 1){
      int hd = 0;
      rep(j, n + 1)if(i != j)tmp[hd++] = h[j];
      ll df = tmp[1] - tmp[0];
      rep1(j, n)if(df != tmp[j] - tmp[j - 1])break;
      if(j == n){
        pri(h[i]);
        break;
      }
    }

//*/

//*/ break;
  }
  return 0;
}

Measured memory_bytes: 3128
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
#include <numeric>

#define rep(i,n) for(int i = 0;i < (n);i++)
#define repp(i,j, n) for(int i = (j);i < (n);i++)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define INF 1e9

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<int, int> > vpi;
typedef vector<pair<ll, ll> > vpl;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  string s;
  cin >> n >> s;
  string ans = s;
  int state = 0;
  rep(i, n){
    if(s[i] == '(') state++;
    else state--;
    if(state < 0) {
      ans = '('+ans;
      state++;
    }
  }
  rep(i, state) ans = ans+')';
  cout << ans << endl;
  return 0;
}


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

int main()
{
    map<string,int>m;
    m["SUN"]=7;
    m["MON"]=6;
    m["TUE"]=5;
    m["WED"]=4;
    m["THU"]=3;
    m["FRI"]=2;
    m["SAT"]=1;
    string temp;
    cin>>temp;
    cout<<m[temp]<<endl;
    return 0;
}

Measured memory_bytes: 384
N = int(input())
S = []
for _ in range(N):
    S.append(input())
from collections import defaultdict as ddict
cnt = ddict(int)
max_cnt = 0
for s in S:
    cnt[s] += 1
    max_cnt = max(max_cnt,cnt[s])
ans = []
for key in cnt.keys():
    if max_cnt == cnt[key]:
        ans.append(key)
for a in sorted(ans):
    print(a)

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


int main(){
    int N; cin >> N;
    for(int i = 1; i < 10; ++i){
        if(N % i == 0 && N/i < 10){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func max(a ...int) int {
	m := a[0]
	for i, v := range a {
		if i == 0 {
			continue
		}
		if m < v {
			m = v
		}
	}
	return m
}
func main() {
	// Code for B - K Cakes
	var K, T int
	fmt.Scan(&K, &T)

	a := make([]int, T)
	var maxNum int
	for i := 0; i < T; i++ {
		fmt.Scan(&a[i])
		maxNum = max(maxNum, a[i])
	}

	ans := max(0, maxNum-(K-maxNum)-1)
	fmt.Println(ans)
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>

using namespace std;

/////////////////////////////////////////////////////
#define MOD (ll)(1e9+7)

ll N;
pll XY[55];
ll Fa[101010];

ll i, j, k;


bool ck(pdd xy,double r){
    //printf("%lf,%lf ", xy.first, xy.second);
    ll i;
    fornum(i,0,N){
        double rr = sqrt(pow(xy.first - XY[i].first, 2) + pow(xy.second - XY[i].second, 2));
        if (rr > r + 5e-10){
            //printf("%lld ", i);
            return false;
        }
    }
    return true;
}

bool ck2(pdd a,pdd b,double r){
    pdd abc = {(a.first + b.first) / 2.0, (a.second + b.second) / 2.0};
    double aaa = sqrt(pow(a.first - b.first, 2) + pow(a.second - b.second, 2));
    pdd gg = {(b.second - a.second) / aaa, -(b.first - a.first) / aaa};
    double bb = pow(abc.first - a.first, 2) + pow(abc.second - a.second, 2);
    double aa = pow(r, 2) - bb;
    if (aa < 0){
        //printf("a");
        return false;
    }
    aa = sqrt(aa);
    //printf("%lf,%lfa%lf,%lfb%lfc\n", abc.first, abc.second, gg.first, gg.second,aa);
    pdd xy = {gg.first * aa + abc.first, gg.second * aa + abc.second};
    //printf("%lf,%lf\n", xy.first, xy.second);
    if(ck(xy,r))
        return true;
    
    pdd xy2 = {gg.first * -aa + abc.first, gg.second * -aa + abc.second};
    if(ck(xy2,r))
        return true;
    return false;
}


int main(){
    scanf("%lld", &N);
    
    fornum(i,0,N){
        ll x, y;
        scanf("%lld%lld", &x, &y);
        XY[i] = {x, y};
    }

    double l = 0, r = 1e4;
    while(true){
        //printf("%lf,%lf\n", l, r);
        double c = (l + r) / 2;
        fornum(i,0,N){
            fornum(j,i+1,N){
                //printf("%lld,%lld:", i, j);
                if(ck2(XY[i], XY[j], c))
                    break;
            }
            if(j<N)
                break;
        }
        //printf("\n");
        if(i==N){
            if(l==c)
                break;
            l = c;
        }else{
            if(r==c){
                break;
            }
            r = c;
        }
    }
    printf("%.9lf", r);
    return 0;
}

Measured memory_bytes: 256
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int n;cin>>n;
    bool f[101][10];
    for(int i=0;i<n;i++){
        for(int j=0;j<10;j++)
            cin>>f[i][j];
    }
    ll p[100][10];
    for(int i=0;i<n;i++){
        for(int j=0;j<=10;j++)
            cin>>p[i][j];
    }
    ll ans=-INF;
    for(int bit=1;bit<(1<<10);bit++){
        int sum=0;
        for(int i=0;i<n;i++){
            int cnt=0;
            for(int j=0;j<10;j++){
                if(bit&(1<<j)&&f[i][j])cnt++;
            }
            sum+=p[i][cnt];
        }
        chmax(ans,sum);
    }
    cout<<ans<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


Measured memory_bytes: 256