akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <algorithm>

#define MOD_BIG 1000000007
using std::string;
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
using ll = long long;
using std::vector;
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) {
    vec.resize(len);
    for (auto &v : vec) ndarray(v, args...);
}

//////////////////////////////////////



//////////////////////////////////////

int main() {
    
    int N;
    cin >> N;
    
    vector<int> A(N+1), B(N+1);
    for (int i = 0; i < N+1; i++) {
        int a;
        cin >> a;
        A[i] = a;
    }
    for (int i = 0; i < N; i++) {
        int b;
        cin >> b;
        B[i] = b;
    }
    B[N] = 0;
    ll ans = 0;
    int b = 0;
    for (int i = 0; i < N+1; i++) {
        int beat;
        beat = std::min(A[i], b);
        ans += beat;
        beat = std::min(A[i]-beat, B[i]);
        b = std::max(B[i] - beat, 0);
        ans += beat;
        //cerr << beat << ", " << ans << ", " << b << endl;
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define all(v) v.begin(),v.end()
#define vi vector<int> 
#define mod 1000000007
#define inf 1e17
#define fs first
#define ss second

template <typename T> 
void amax(T& x, T y) 
{ 
    if( x < y) x = y;
} 

template <typename T> 
void amin(T& x, T y) 
{ 
    if( x > y) x = y;
} 



int main(){
     
   int n;
   cin >> n;
   int arr[n];
   set<int> s;
   
   int ans =1;
   cin >> arr[0];
   s.insert(arr[0]);
   for(int i =1;i<n;i++){
	   
	   cin >> arr[i];
	  // cout << *s.begin() << " " << arr[i] <<endl;
	   if( *s.begin() >= arr[i]) ans++;
	   s.insert(arr[i]);
   }
   cout << ans << endl;

}


Measured memory_bytes: 10368
#include <bits/stdc++.h> 
#define ll long long
#define F first
#define FF first.first
#define FS first.second
#define S second
#define pb push_back
using namespace std;
const ll N=1000006, INF=1e16;
 
ll n, q=1, m, a[N], b[N], f[N], o, k, t, x, y, z, u, h, mx, mn, ans, Ans;
pair<ll,ll> p[N];
string s;
vector<int> v[N];
 
main(){ios_base::sync_with_stdio(false), cin.tie(0);
   	
	cin>>n>>m;
	
	for (int i=1; i<=n; i++){
		cin>>a[i];
	}
	
	for (int i=1; i<=m; i++){
		cin>>x>>y;
		if(a[x]<=a[y])f[x]=1;
		if(a[y]<=a[x])f[y]=1;
	}
	for (int i=1; i<=n; i++)if(!f[i])ans++;
	
	cout<<ans;
	
}

Measured memory_bytes: 28668
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll, ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define pdd pair<double, double>
#define f first
#define s second
#define MOD 1000000007
#define mkp make_pair
#define M_PI 3.14159265358979323846
#define FOR(i,l,r) for (int i=l;i<=r;i++)
#define LOR(i,l,r) for (ll i=l;i<=r;i++)
#define FORD(i,r,l) for (int i=r;i>=l;i--)
#define LORD(i,r,l) for (ll i=r;i>=l;i--)
#define INF 1000000000
#define CL(x) memset(x,0,sizeof(x))
#define DEB(x) cout << #x << " : " << x << '\n'
#define ALL(x) x.begin(), x.end()
#define SZ(x) x.size()
#define UI(x) (int)(x-'A')
#define LI(x) (int)(x-'a')
typedef long long ll;

#define MXN 2505
int N,M;
ll T,P;
ll dis[MXN];
vector<pil> G[MXN];
typedef pair<pii,ll> ppl;
ppl E[MXN*2];
ll inf = (1LL<<60);

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

    cin>>N>>M>>P;
    int a,b;
    ll c;
    FOR(i,1,M)
    {
        cin>>a>>b>>c;
        G[a].pb(mkp(b, -(c-P) ));
        E[i]=mkp( mkp(a,b),-(c-P) );
    }

    dis[1]=0;
    FOR(i,2,N)dis[i]=inf;

    bool negc=false;
    FOR(i,1,3*N)
    {
        FOR(j,1,M)
        {
            int u=E[j].f.f, v=E[j].f.s;
            ll c=E[j].s;
            if( dis[u]+c<dis[v] )
            {
                dis[v]=dis[u]+c;
                if( i>N && v==N )negc=true;
            }
        }
    }

    if(negc)
    {
        cout<<-1<<'\n';
        return 0;
    }
    cout<<max(0LL,-dis[N])<<'\n';

    return 0;
}



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

int N;

int main() {
	cin >> N;
	int buf = N;
	int sum = 0;
	while (buf > 0) {
		sum += buf % 10;
		buf = buf / 10;
	}
	if (N%sum == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
N = input()
L = list(map(int,input().split()))
n=0
m=0
p=0
for a in range(int(N)):
  if L[a]%2 != 0:
    n+=1
  elif L[a]%2 == 0 and L[a]%4 != 0:
    m+=1
  else:
    p+=1
if int(N)%2==1 and (n>p+1 or p==0 and n==1):
  print("No")
elif int(N)%2==0 and n>p:
  print("No")
else:
  print("Yes")


Measured memory_bytes: 20148
package main

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

func main() {
	io, flush := NewIO()
	defer flush()

	n := io.ScanInt()
	edges := io.ScanInts(n)
	sort.Ints(edges)

	var totalLength int
	for i := 0; i < n-1; i++ {
		totalLength += edges[i]
	}

	if edges[n-1] < totalLength {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

type IO struct {
	scanner *bufio.Scanner
	writer  *bufio.Writer
}

func NewIO() (*IO, func()) {
	io := &IO{
		scanner: newScanner(),
		writer:  newWriter(),
	}
	return io, func() { io.writer.Flush() }
}

func newScanner() *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Buffer(make([]byte, 10000000), 10000000)
	s.Split(bufio.ScanWords)
	return s
}

func newWriter() *bufio.Writer {
	return bufio.NewWriter(os.Stdout)
}

func (io *IO) ScanBytes() []byte {
	if !io.scanner.Scan() {
		panic("scan string failed")
	}
	return io.scanner.Bytes()
}

func (io *IO) ScanString() string {
	if !io.scanner.Scan() {
		panic("scan string failed")
	}
	return io.scanner.Text()
}

func (io *IO) ScanStrings(n int) []string {
	strs := make([]string, n)
	for i := 0; i < n; i++ {
		strs[i] = io.ScanString()
	}
	return strs
}

func (io *IO) Scan2DStrings(y, x int) [][]string {
	strings := make([][]string, y)
	for i := 0; i < y; i++ {
		strings[i] = io.ScanStrings(x)
	}
	return strings
}

func (io *IO) Scan2DGraph(y int) [][]string {
	strs := make([][]string, y)
	for i := 0; i < y; i++ {
		strs[i] = strings.Split(io.ScanString(), "")
	}
	return strs
}

func (io *IO) ScanInt() int {
	return int(io.ScanInt64())
}

func (io *IO) ScanInt2() (int, int) {
	return int(io.ScanInt64()), int(io.ScanInt64())
}

func (io *IO) ScanInt3() (int, int, int) {
	return int(io.ScanInt64()), int(io.ScanInt64()), int(io.ScanInt64())
}

func (io *IO) ScanInt4() (int, int, int, int) {
	return int(io.ScanInt64()), int(io.ScanInt64()), int(io.ScanInt64()), int(io.ScanInt64())
}

func (io *IO) ScanInts(n int) []int {
	ints := make([]int, n)
	for i := 0; i < n; i++ {
		ints[i] = io.ScanInt()
	}
	return ints
}

func (io *IO) Scan2DInts(y, x int) [][]int {
	ints := make([][]int, y)
	for i := 0; i < y; i++ {
		ints[i] = io.ScanInts(x)
	}
	return ints
}

func (io *IO) ScanInt64() int64 {
	i, err := strconv.ParseInt(io.ScanString(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *IO) ScanFloat64() float64 {
	i, _ := strconv.ParseFloat(io.ScanString(), 64)
	return i
}

func (io *IO) ScanFloat64s(n int) []float64 {
	floats := make([]float64, n)
	for i := 0; i < n; i++ {
		floats[i] = io.ScanFloat64()
	}
	return floats
}

func (io *IO) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


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

int main(void){
    int h,w,k;
    cin >> h >> w >> k;
    vector< vector<int> > cell; //0:white,red 1:black
    rep(i,h){
        cell.push_back({});
        rep(j,w){
            char c;
            cin >> c;
            if(c=='.')cell.at(i).push_back(0);
            else{
                cell.at(i).push_back(1);
            }
        }
    }
    int ans = 0;
    for(int hbit = 0; hbit < (1<<h); hbit++){
        for(int wbit = 0; wbit < (1<<w); wbit++){
            int temp;
            temp = 0;
            rep(i,h){
                rep(j,w){
                    if(!(hbit & (1<<i) || wbit & (1<<j)))temp += cell.at(i).at(j);
                }
            }
            if(temp == k)ans++;
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define MAXN 100100
#define pii pair<int, int>
#define pb push_back
typedef long long ll;

using namespace std;

int n, a[MAXN], mi = 1e7, ma = -1e7, x;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    cin >> n;
    for(int i = 0; i < n; i++){
    	cin >> a[i];
    	mi = min(mi, a[i]);
    	ma = max(ma, a[i]);
    }
    cout << 2 * n << endl;
    if(ma > -mi){
    	for(int i = 0; i < n; i++)
    		if(a[i] == ma) x = i + 1;
    	cout << x << " " << 1 << endl;
    	cout << x << " " << 1 << endl;
    	for(int i = 2; i <= n; i++){
    		cout << i - 1 << " " << i << endl;
    		cout << i - 1 << " " << i << endl;
    	}
    } else{
    	for(int i = 0; i < n; i++)
    		if(a[i] == mi) x = i + 1;
    	cout << x << " " << n << endl;
    	cout << x << " " << n << endl;
    	for(int i = n; i > 1; i--){
    		cout << i << " " << i - 1 << endl;
    		cout << i << " " << i - 1 << endl;
    	}
    }
}

Measured memory_bytes: 256
h,w = gets.split.map(&:to_i)
a,b = 2.times.map{(1..h).map{gets.split.map(&:to_i)}}
ab = a.zip(b).map{|ta,tb|ta.zip(tb).map{|ua,ub|(ua-ub).abs}}

max = ab.map(&:max).max
zero = 1 << (h+w)*max/2

ans = ab.each_with_object([zero]+[0]*(w-1)){|di,dp|
  pre = 0
  dp.map!.with_index{|dpi,i|
    dt = di[i]
    s = dpi | pre
    pre = (s << dt) | (s >> dt)
  }
}[-1]

p (0..max).find{|i|ans & ((zero << i)|(zero >> i)) > 0}

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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	int ans = 0;
	rep(i, n) {
		for (int j = i + 1; j < n; j++) {
			if (i != j) {
				ans += a[i] * a[j];
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import numpy as np
a1 = [int(x.strip()) for x in input().split()]
a2 = [int(x.strip()) for x in input().split()]
a3 = [int(x.strip()) for x in input().split()]
a = np.array([a1,a2,a3])
n = int(input())
bingo = 0
for i in range(n):
  b = int(input())
  if b in a:
    ch = np.argwhere(a==b)
    a[ch[0][0]][ch[0][1]] = 0 #該当する文字をゼロでパンチング
sum_col = np.sum(a, axis=0)
sum_row = np.sum(a, axis=1)
bingo = np.count_nonzero(sum_col==0) + np.count_nonzero(sum_row==0)
if a[0,0]==0 and a[1,1]==0 and a[2,2]==0:
  bingo += 1
if a[2,0]==0 and a[1,1]==0 and a[0,2]==0:
  bingo += 1
if bingo > 0:
  ans = 'Yes'
else:
  ans = 'No'
print(ans)

Measured memory_bytes: 27164
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, c;
  string b;
  cin >> b;
  a = b.size();
  c = 0;
  for (int i = 0; i < a; i++) {
    if (b.at(i) == 'x') {
      c++;
    }
  }
  if (c > 7) {
    cout << "NO" << endl;
  }
  else {
    cout << "YES" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define reg(i,a,b) for(int i=a;i<=b;i++)
#define reh(i,a,b) for(int i=b;i>=a;i--)
#define in(x) scanf("%d",&x)
#define fro freopen("D:\\testdata.in", "r", stdin)
#define il inline
#define lson(q) q<<1
#define rson(q) q<<1|1
using namespace std;
typedef long long ll;
const int mx=1e5+10;
int main() {
	int a,b,t;
	cin>>a>>b;
	t=max(a+b,a-b);
	cout<<max(t,a*b)<<endl;
	return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>

#define REP(i,n) for(int i=0; i<n; i++)
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define ll long long int

using namespace std;

int main(void) {
    int n,k;
    while(cin>>n>>k && n>0){
        vector<ll> a(n);
        REP(i,n){
            cin >> a[i];
        }
        ll s=0;
        REP(i,k){
            s+=a[i];
        }
        ll ans=s;
        FOR(i,k,n-1){
            s+=a[i];
            s-=a[i-k];
            ans=max(ans,s);
        }
        cout << ans << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

int sign(long long int a){
	if (a > 0)
		return 1;
	else
		if (a < 0)
			return -1;
		else
			return 0;
}

int main(void){
	int n;

	cin >> n;

	long long int sum = 0, s = 1;


	long long int num = 0;

	vector<int> a(n);

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


	for (int i = 0; i < n; i++){
		sum += a[i];

		if (i != 0 && (sign(s) == sign(sum) || sum == 0)){
			num += abs(sum) + 1;
			sum = sign(s) * (-1);
			s *= -1;
		}
		else if (i == 0 && a[i] == 0){
			num++;
			sum++;
			s = 1;
		}
		else {
			s = sign(sum);
		}
	}

	long long int m = num;

	sum = 0;

	num = 0;

	num += abs(a[0]) + 1;
	if (a[0] >= 0)
		sum = -1;
	else
		sum = 1;

	s = sum;

	for (int i = 1; i < n; i++){
		sum += a[i];

		if (i != 0 && (sign(s) == sign(sum) || sum == 0)){
			num += abs(sum) + 1;
			sum = sign(s) * -1;
			s *= -1;
		}
		else {
			s = sign(sum);
		}
	}

	m = min(num, m);

	cout << m << endl;
}

Measured memory_bytes: 768
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

A,B,X = I()
if X < A:
    print('NO')
elif A+B < X:
    print('NO')
else:
    print('YES')

Measured memory_bytes: 10036
import bisect
n = int(input())
l = list(map(int, input().split()))
count = 0
l.sort()
for i in range(len(l)-1, 1, -1):
  for j in range(i-1, 0, -1):
    count += max(j - (bisect.bisect_right(l, l[i] - l[j])), 0)
print(count)



Measured memory_bytes: 3188
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<random>
using namespace std;

int n,t;
struct Tmp
{
    int cost,time;
}route[1200];

void init()
{
    scanf("%d %d",&n,&t);
    for (int i=0; i<n; ++i)
    {
        scanf("%d %d",&route[i].cost,&route[i].time);
    }
}

void work()
{
    int minCost=1001;
    for (int i=0; i<n; ++i)
    {
        if (route[i].time<=t) minCost=min(minCost,route[i].cost);
    }
    if (minCost<=1000) printf("%d\n",minCost); else printf("TLE\n");
}


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

    return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    def main():

        n=int(input())
        d=list(map(int,input().split()))
        m=int(input())
        t=list(map(int,input().split()))
        from collections import Counter
        dd=Counter(d)
        tt=Counter(t)
        for key,value in tt.items():
            if dd[key]<value:
                return 'NO'
        return 'YES'
    print(main())
resolve()

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

int main(){
  int r,g,b;
  cin >> r >> g >> b;
  
  int num = 100*r + 10*g + b;
  if(num%4 == 0){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  
}

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

//#pragma GCC optimize("Ofast")

using namespace std;

typedef long long ll;
typedef long double ld;

mt19937 rnd(time(0));

#define ioss ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("lights.in", "r", stdin); freopen("lights.out", "w", stdout);
#define s second
#define f first
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define pll pair<ll,ll>
#define pii pair<int,int>

const ll INF = 1e18;
constexpr ll mod = 1e9 + 7;

ll x0r(ll x, ll y) { return (x | y) & (~x | ~y); }


void solve() {
    ll n, ans = 0, k = 1;
    cin >> n;
    while (n) {
        if (n == 1) {
            n = 0, ans += k;
        } else {
            ans += k;
            k *= 2;
            n /= 2;
        }
    }
    cout<<ans<<'\n';
}


signed main() {
    //ioss
    //clock_t time = clock();
    //if ((double) (clock() - time) / CLOCKS_PER_SEC > 0.96) {
    //file
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2　//1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) (max(x,y)-min(x,y))
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;

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

    int n;
    cin >> n;
    int a[n + 3], x[n + 3][n + 3], y[n + 3][n + 3];
    rep(i,n){
      cin >> a[i];
      rep(j, a[i]){
	cin >> x[i][j] >> y[i][j];
      }
    }
    int ans = 0;
    for(int bit = 0;bit < (1 << n);bit ++){
      bool out = false;
      rep(i, n){
	if(bit & (1 << i)){
	  rep(j, a[i]){
	    if(y[i][j] == 1){
	      if(!(bit & (1 << x[i][j] - 1))){
		out = true;
	      }
	    } else {
	      if(bit & (1 << x[i][j] - 1)){
		out = true;
	      }
	    }
	  }
	}
      }
      if(!out){
	//	cout << bit << " ";
	ans = max(ans, __builtin_popcount(bit));
      }
    }
    cout << ans << '\n';
    return 0;
}


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

ll keta(ll n) {
    ll res = 0;
    ll p = 1;
    while(n >= p) {
        p *= 10;
        res++;
    }
    return res;
}

int gcd(int p, int q) {
    while(q != 0) {
        int r = p % q;
        p = q;
        q = r;
    }
    return p;
}
int main() {
    int n, m;
    cin >> n >> m;
    vector<int> ans(n, 1);
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    vector<int> a(m), b(m);
    rep(i, m) cin >> a[i] >> b[i];
    rep(i, m) {
        if(h[a[i] - 1] > h[b[i] - 1]) {
            ans[b[i] - 1] = 0;
        } else if(h[a[i] - 1] < h[b[i] - 1]) {
            ans[a[i] - 1] = 0;
        } else {
            ans[a[i] - 1] = 0;
            ans[b[i] - 1] = 0;
        }
    }
    int cnt = 0;
    rep(i, n) {
        if(ans[i]) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 4844
ary = Array.new(26,0)
until (s = gets) == nil
  l = s.chomp.length
  for i in 1..l
    n = s[i-1].downcase.ord - "a".ord
    ary[n] += 1 if 0 <= n && n < 26
  end
end
ch = "abcdefghijklmnopqrstuvwxyz"
for i in 1..26
  puts ch[i-1] + " : " + ary[i-1].to_s
end

Measured memory_bytes: 6100
import sys
input=sys.stdin.readline
from collections import deque
from heapq import heappush,heappop
import re

def int_raw():
    return int(input())
 
def ss_raw():
    return input().split()
 
def ints_raw():
    return tuple(map(int, ss_raw()))


DIV=10**9+7

def mod_invs(n,mod=DIV):
    inv=[0]*(n+1)
    inv[0]=1
    inv[1]=1
    for i in range(2,n+1):
        inv[i] = (-(mod//i)*inv[mod%i]) % mod
    return inv

N,A,B,C = ints_raw()

def main():
    invs = mod_invs(N*2+100)
    a = A*invs[A+B]%DIV
    b = B*invs[A+B]%DIV
    powas = [1]*(N+1)
    powbs = [1]*(N+1)
    for i in range(N):
        powas[i+1] = powas[i]*a%DIV
        powbs[i+1] = powbs[i]*b%DIV
    inv_perC = 100*invs[100-C]%DIV
    ans = 0
    ncr = 1
    for i in range(N,2*N):
        ncr *= i*invs[i-N]
        ncr %= DIV
        ans += ncr *(powas[N]*powbs[i-N]+powas[i-N]*powbs[N])
        ans %=DIV
    return (ans*inv_perC%DIV)

print(main())


Measured memory_bytes: 44780
#include<bits/stdc++.h> //ABC 164_d
#define ll long long
using namespace std;
string s;
ll ans,cnt[2200],num,t=1;
int main(){
	cin>>s;
	for(int i=s.size()-1;i>=0;i--){
	num=(num+(s[i]-'0')*t)%2019;
	cnt[num]++;
	t=t*10%2019;		
	}
	for(int i=1;i<2019;i++){
		if(cnt[i]>1)
			ans+=(cnt[i]-1)*cnt[i]/2;
	}
	ans+=cnt[0]*(cnt[0]+1)/2;
	cout<<ans;
	return 0;
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;


#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
void warshall_floyd(Matrix< T > &g, T INF) {
  for(int k = 0; k < g.size(); k++) {
    for(int i = 0; i < g.size(); i++) {
      for(int j = 0; j < g.size(); j++) {
        if(g[i][k] == INF || g[k][j] == INF) continue;
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
};

int h,w;

bool inside(int y,int x)
{
    return 0<=y && y<h && 0<=x && x<w;
}

int calcV(int y,int x)
{
    return y*w+x;
}

int main()
{
    int doty,dotx;
    cin>>h>>w;
    int V=h*w;
    vector<string> s(h);
    for (int i = 0; i < h; i++)
    {
        cin>>s[i];
    }
    Matrix< int > mat(h*w, vector< int >(h*w, INT_MAX));
    for(int i = 0; i < h*w; i++) mat[i][i] = 0;
    for (int y = 0; y < h; y++)
    {
        for (int x = 0; x < w; x++)
        {
            if(s[y][x]=='#') continue;
            for (int i = 0; i < 4; i++)
            {
                int nexty= y+dy4[i];
                int nextx= x+dx4[i];
                if(inside(nexty,nextx)==true && s[nexty][nextx]=='.')
                {
                    mat[calcV(y,x)][calcV(nexty,nextx)]=1;
                }
            }
            doty=y;
            dotx=x;
        }
    }

    warshall_floyd(mat, INT_MAX);

    int ans=0;
    for (int i = 0; i < V; i++)
    {
        for (int j = 0; j < i; j++)
        {
            if(mat[i][j]!=INT_MAX)
            {
                ans=max(ans,mat[i][j]);
            }
        }
    }
    cout<<ans<<endl;
    

    /*
    int v1=calcV(doty,dotx);
    int v2=calcV(doty,dotx);
    int dmax=0;
    for (int i = 0; i < h*w; i++)
    {
        if(mat[calcV(doty,dotx)][i]==INT_MAX) continue;
        if(mat[calcV(doty,dotx)][i]>dmax)
        {
            v1=i;
            dmax=mat[calcV(doty,dotx)][i];
        }
    }
    for (int i = 0; i < h*w; i++)
    {
        if(mat[v1][i]==INT_MAX) continue;
        if(mat[v1][i]>dmax)
        {
            v2=i;
            dmax=mat[v1][i];
        }
    }
    cout<<dmax<<endl;


    for(int i = 0; i < h*w; i++) {
        for(int j = 0; j < h*w; j++) {
            if(j > 0) putchar('\t');
            if(mat[i][j] == INT_MAX) printf("INF");
            else printf("%d", mat[i][j]);
        }
        putchar('\n');
    }
    cout<<endl;
    cout<<v1<<"\t"<<v2<<endl;
    */

    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define inf 1e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int mod = 1000000007;

vector<int> job[100005];

int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0;i < n;i++) {
    int a, b;
    cin >> a >> b;
    job[a].push_back(b);
  }
  priority_queue<int> pq;
  int ans = 0;
  for (int i = 1;i <m+1;i++) {
    for (int s: job[i]) {
      pq.push(s);
    }
    if (!pq.size()) continue;
    else {
      ans += pq.top();
      pq.pop();
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 5632
#include <stdio.h>
#include <stdlib.h>

#define HASH 1000003

typedef struct List {
	struct List *next;
	char *s;
	int l;
} list;

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

int hash_string(char* s)
{
	int i, x = 0;
	for (i = 0; s[i] != 0; i++) x = ((x << 5) + s[i] - 'a') % HASH;
	return x;
}

int lex_smaller(char* s1, char* s2)
{
	int i;
	for (i = 0; s1[i] != 0 && s2[i] != 0; i++) {
		if (s1[i] < s2[i]) return 1;
		else if (s1[i] > s2[i]) return -1;
	}
	if (s1[i] == s2[i]) return 0;
	else if (s1[i] == 0) return 1;
	else return -1;
}

int main()
{
	int i, j, l[200001], N;
	char *S[200001], T[1000001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		scanf("%s", T);
		for (l[i] = 0; T[l[i]] != 0; l[i]++);
		S[i] = (char*)malloc(sizeof(char) * (l[i] + 1));
		for (j = 0; j <= l[i]; j++) S[i][j] = T[j];
	}
	
	int h[200001];
	list *p, *hash[HASH], d[200001];
	for (i = 1; i <= N; i++) {
		h[i] = hash_string(S[i]);
		d[i].s = S[i];
		d[i].l = l[i];
		d[i].next = hash[h[i]];
		hash[h[i]] = &(d[i]);
	}
	
	int k, m, dp[2][26];
	long long ans = 0, tmp, pow[32];
	const long long inv = div_mod(1, 32, HASH);
	for (k = 1, pow[0] = 32; k < 32; k++) pow[k] = pow[k-1] * pow[k-1] % HASH;
	for (i = 1; i <= N; i++) {
		if (l[i] <= 1) continue;
		for (j = 0; j <= l[i]; j++) T[j] = S[i][j];
		for (j = l[i] - 1, k = 0, tmp = 1; j > 0; j >>= 1, k++) if ((j & 1) == 1) tmp = tmp * pow[k] % HASH;
		h[i] = (h[i] - tmp * (T[0] - 'a') % HASH + HASH) % HASH;
		tmp = tmp * inv % HASH;
		h[i] = (h[i] - tmp * (T[1] - 'a') % HASH + HASH) % HASH;
		for (j = 0; j < 26; j++) dp[0][j] = 0;
		dp[0][S[i][0] - 'a'] = 1;
		dp[1][0] = S[i][0] - 'a';
		for (j = 1, m = 1; j < l[i]; j++) {
			if (dp[0][S[i][j] - 'a'] == 0) {
				dp[0][S[i][j] - 'a'] = 1;
				dp[1][m++] = S[i][j] - 'a';
			}
			for (k = 0; k < m; k++) {
				T[j] = 'a' + dp[1][k];
				h[0] = (tmp * dp[1][k] + h[i]) % HASH;
				for (p = hash[h[0]]; p != NULL; p = p->next) if (p->l == l[i] - j && p->s[0] == T[j] && p->s[p->l - 1] == T[l[i] - 1] && lex_smaller(p->s, &(T[j])) == 0) break;
				if (p != NULL) ans++;
			}
			tmp = tmp * inv % HASH;
			h[i] = (h[i] - tmp * (S[i][j+1] - 'a') % HASH + HASH) % HASH;
		}
	}
	
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 23572
# vim: set fileencoding=utf-8:
import numpy as np


def main():
    N = input()
    a = np.array([int(ele) for ele in raw_input().split()])
    avg = sum(a) / float(N)
    a = a - np.array([avg] * N)
    a = map(abs, list(a))
    print(a.index(min(a)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 19184
main :: IO ()
main = do
  n <- readLn
  putStrLn $ if f n then "No" else "Yes"

f :: Int -> Bool
f n =  null [(a,b) | a <- [0.. aa]
                   , b <- [0.. bb]
                   , 4*a + 7*b == n
                   ]
  where
    aa = n `div` 4
    bb = n `div` 7

Measured memory_bytes: 508
import java.util.Scanner;

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

                String S = scan.next();
                String T = scan.next();

                int output = T.length();

                for (int i = 0; i <= S.length() - T.length(); i++) {
                	String tempS = S.substring(i,i+T.length());
                	int tempCount = 0;
                	for (int k = 0; k < T.length(); k++) {
                		if (!tempS.substring(k,k+1).equals(T.substring(k,k+1))) {
                			tempCount++;
                		}
                	}
                	if (tempCount < output) {
                		output = tempCount;
                	}

                }

                System.out.println(output);

                scan.close();

        }

}

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

long long int W, H, x, y;

int main() {
    cin >> W >> H >> x >> y;
    cout << fixed << setprecision(10) << (double)W * H / 2 << " ";
    if (x * 2 == W && y * 2 == H) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 256
# ALC 005 D

N = int(input())
list_p = list(map(int, input().split()))
swapCount = 0

for i in range(N):
    if list_p[i] == i+1:
        temp = list_p[i]
        
        if i == len(list_p)-1:
            list_p[i] = list_p[i-1]
            list_p[i-1] = temp
        else:
            list_p[i] = list_p[i+1]
            list_p[i+1] = temp
        
        swapCount += 1

print(swapCount)

Measured memory_bytes: 14008
import io.StdIn

object Main extends App {
  val out = new java.io.PrintWriter(System.out)
  val Array(n, m) = StdIn.readLine.split(" ").map(_.toInt)
  val st = Iterator.continually(StdIn.readLine)
    .take(n)
    .map(_.split(" ").map(_.toInt))
    .toArray
  val cp = Iterator.continually(StdIn.readLine)
    .take(m)
    .map(_.split(" ").map(_.toInt))
    .toArray

  st.map(es => {
    cp./:(Int.MaxValue, 0, 0)((min, ep) => {
      val d = (es(0) - ep(0)).abs + (es(1) - ep(1)).abs
      if(min._1 > d) (d, min._3 + 1, min._3 + 1)
      else (min._1, min._2, min._3 + 1)
    })._2
  })
    .foreach(out.println)

  out.flush
}

Measured memory_bytes: 27312
import math

n, d = map(int, input().split())

points = [list(map(int, input().split())) for i in range(n)]

cnt = 0
for i in range(n):
    if math.sqrt(points[i][0] ** 2 + points[i][1] ** 2) <= d:
        cnt += 1

print(cnt)


Measured memory_bytes: 45384
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


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

    ll a,b;
    ll k;
    cin >> a>>b>> k;
    ll d = __gcd(a,b);
    FORd(i,1,d+1){
      if(k == 1  && d%i==0) {cout << i << endl;return 0;}
      if(d%i==0) k--;
    }
    
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
import java.util.Scanner;

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

			int[] value = new int[9];
			boolean[] flags = new boolean[9];

			for(int i = 0; i < 9; i++)
			{
				value[i] = sc.nextInt();
			}

			int N = sc.nextInt();

			for(int i = 0; i < N; i++)
			{
				int num = sc.nextInt();
				for(int j = 0; j < 9; j++)
				{
					if(num == value[j])
					{
					   flags[j] = true;
				    }
				}
			}
          
			if((flags[0]== true && flags[1] == true && flags[2] == true)
				|| (flags[3] == true &&  flags[4] == true && flags[5] == true)
				|| (flags[6] == true &&  flags[7] == true && flags[8] == true)
				|| (flags[0] == true &&  flags[3] == true && flags[6] == true)
				|| (flags[1] == true &&  flags[4] == true && flags[7] == true)
				|| (flags[2] == true &&  flags[5] == true && flags[8] == true)
				|| (flags[0] == true &&  flags[4] == true && flags[8] == true)
				|| (flags[2] == true &&  flags[4] == true && flags[6] == true))
			{
				System.out.println("Yes");
			}
			else
			{
				System.out.println("No");
			}
		}
}


Measured memory_bytes: 22612
import sys
from itertools import permutations

def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    if N >= M // 2: print(M // 2)
    else:
        leftC = M - N * 2
        print(N + leftC // 4)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 9176
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<cmath>
using namespace std;
long long gcd(long long x,long long y)
{
	return y?gcd(y,x%y):x;
}
long long lcm (long long a,long long b)
{
	return a/gcd(a,b)*b;
}
int main()
{	
	int n;
	while(cin>>n)
	{
		long long a[105]; 
		long long Lcm = 1;
		int i=0;
		for(i;i<n;i++)
		{
			scanf("%lld",&a[i]) ;
			Lcm = lcm(Lcm,a[i]);
		}
		printf("%lld\n",Lcm);
	}
	return 0;
}

Measured memory_bytes: 256
def f_c():
    n, k, q = map(int, input().split())
    a = [0]*n
    for _ in range(q):
        a[int(input())-1] += 1
    for ai in a:
        if k-q+ai<=0:
            print("No")
        else:
            print("Yes") 

if __name__ == "__main__":
    f_c()

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

using namespace std;

const int max_n = 100111;
const long long inf = 1000111222000111222LL;

struct tree {
    long long a[4 * max_n];

    tree() {
        for (int i = 0; i < 4 * max_n; ++i) {
            a[i] = inf;
        }
    }

    void update(int v, int tl, int tr, int l, int r, long long value) {
        if (tl == l && tr == r) {
            //cout << "upd " << v << " " << l << " " << r << ": " << value << endl;
            a[v] = min(a[v], value);
            return;
        }
        int mid = (tl + tr) / 2;
        if (r <= mid) {
            update(2 * v, tl, mid, l, r, value);
        } else if (l > mid) {
            update(2 * v + 1, mid + 1, tr, l, r, value);
        } else {
            update(2 * v, tl, mid, l, mid, value);
            update(2 * v + 1, mid + 1, tr, mid + 1, r, value);
        }
    }

    long long get(int v, int l, int r, int pos) {
        //cout << v << " " << l << " " << r << " " << pos << ": " << a[v] << endl;
        if (l == r) {
            return a[v];
        }
        long long res = a[v];
        int mid = (l + r) / 2;
        if (pos <= mid) {
            res = min(res, get(2 * v, l, mid, pos));
        } else {
            res = min(res, get(2 * v + 1, mid + 1, r, pos));
        }
        return res;
    }
};

struct edge {
    int l, r, c;

    bool operator < (const edge &e) const {
        return l < e.l;
    }
};

int n, m;
tree dist;
edge e[max_n];

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    scanf("%d%d", &n, &m);
    for (int i = 0; i < m; ++i) {
        scanf("%d%d%d", &e[i].l, &e[i].r, &e[i].c);
        --e[i].l;
        --e[i].r;
    }
    sort(e, e + m);
    dist.update(1, 0, n - 1, 0, 0, 0);
    int pos = 0;
    for (int i = 0; i < n; ++i) {
        long long d = dist.get(1, 0, n - 1, i);
        //cout << "#" << i << ": " << d << endl;
        if (d == inf) {
            continue;
        }
        while (pos < m && e[pos].l <= i) {
            if (e[pos].r >= i) {
                dist.update(1, 0, n - 1, i, e[pos].r, d + e[pos].c);
            }
            ++pos;
        }
    }
    long long ans = dist.get(1, 0, n - 1, n - 1);
    if (ans == inf) {
        ans = -1;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 4608
#include <iostream>
#include <string>

using namespace std;

bool match(const string & a, const string & b) {
if (a.size() != b.size())
return false;
for (size_t i = 0; i < a.size(); ++i)
if (a[i] != '?' && b[i] != '?' && a[i] != b[i])
return false;
return true;
}

int main()
{
string s, t;
cin >> s >> t;
int n = s.size(), m = t.size();
bool suc = false;
for (int i = n - m; i >= 0; --i)
if (match(s.substr(i, m), t)) {
suc = true;
for (int j = 0; j < m; ++j)
s[i+j] = t[j];
break;
}
if (!suc)
cout << "UNRESTORABLE" << endl;
else {
for (auto & c : s)
if (c == '?')
c = 'a';
cout << s << endl;
}
return 0;
}

Measured memory_bytes: 888
w = input()

cher_count = {}

for c in w:
    if c in cher_count:
        cher_count[c] += 1
    else:
        cher_count[c] = 1

for num in cher_count.values():
    if num % 2 != 0:
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 9000
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

ans = 0
S = [0]*N
T = [0]*N
for i, a in enumerate(A):
    for j, a_ in enumerate(A):
        if a_<a: S[i]+=1
        if j>i and a_<a: T[i]+=1

print((K*(K-1)//2*sum(S) + sum(T)*K)%(10**9+7))

Measured memory_bytes: 3316
#include <bits/stdc++.h>
const char nl = '\n';
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> pt;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int N = 1e5+10;

int n;
int v[N][3];
int dp[N][3];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> v[i][0] >> v[i][1] >> v[i][2];
  }
  for (int j = 0; j < 3; j++) {
    dp[0][j] = v[0][j];
  }
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        if (j == k) continue;
        dp[i][j] = max(dp[i][j], dp[i-1][k] + v[i][j]);
      }
    }
  }
  cout << *max_element(dp[n-1], dp[n-1] + 3) << nl;
  return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD (long long)1e9+7
#define LINF (long long)4e18



int main(){
    vector<vector<int>> c(3,vector<int>(3));
    rep(i,3)rep(j,3){
        cin >> c[i][j];
    }
    bool ok = true;
    rep(i,2){
        if(c[i][1] - c[i][0] != c[i+1][1] - c[i+1][0]) ok = false;
        if(c[i][2] - c[i][1] != c[i+1][2] - c[i+1][1]) ok = false;
        if(c[1][i] - c[0][i] != c[1][i+1] - c[0][i+1]) ok = false;
        if(c[2][i] - c[1][i] != c[2][i+1] - c[1][i+1]) ok = false;
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}
   

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mxn= 5e5+5;
#define mod 1000000007
#define endl '\n'
void rishabh(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int get(int n){
    if(n%2==0)return n/2;
    else return 3*n+1;
}
bool vis[mxn];
int arr[mxn];
void dfs(int i=1, int dist=0){
    vis[i]=true;
    if(i==2){
        cout<<dist;
        exit(0);
    }
    if(!vis[arr[i]])dfs(arr[i],dist+1);
}
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>arr[i];
    dfs();
    cout<<-1;
}



Measured memory_bytes: 4108
ans=[1, 1, 1,2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K=int(input())
print(ans[K-1])

Measured memory_bytes: 3060
#include <stdio.h>

int main(void){
  int a,b,c,str;
  scanf("%d %d %d",&a,&b,&c);

    str=a;
    a=b;
    b=str;
  
    str=a;
    a=c;
    c=str;
    
  printf("%d %d %d\n",a,b,c);
  return 0;
  }

Measured memory_bytes: 128
#![allow(unused_imports)]
use std::io;
use std::cmp::*;
use std::collections::*;
#[allow(dead_code)]
const M: i64 = 1e9 as i64 + 7;

fn read_line() -> String {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();
    buf
}
#[allow(dead_code)]
fn read<T>() -> T where T: std::str::FromStr, T::Err : std::fmt::Debug {
    read_line().trim().parse().unwrap()
}
#[allow(dead_code)]
fn readv<T>() -> Vec<T> where T: std::str::FromStr, T::Err : std::fmt::Debug {
    read_line().split(' ').map(|a| a.trim().parse().unwrap()).collect()
}

fn main() {
    let _: i32 = read();
    let s: String = read();
    let mut cnt = 0;
    let mut pre = 0;
    for c in s.bytes() {
        // let c = c as char;
        if c == b'(' {
            cnt += 1;
        } else {
            if cnt == 0 {
                pre += 1;
            } else {
                cnt -= 1;
            }
        }
    }
    // println!("{}{}{}",
    //          String::from_utf8(vec![b'(';pre]).unwrap(),
    //          s,
    //          String::from_utf8(vec![b')';cnt]).unwrap());
    print!("{}", String::from_utf8(vec![b'(';pre]).unwrap());
    print!("{}", s);
    print!("{}", String::from_utf8(vec![b')';cnt]).unwrap());
    // let mut ans = String::new();
    // for _ in 0..pre {
    //     ans.push('(');
    // }
    // ans += &s;
    // for _ in 0..cnt {
    //     ans.push(')');
    // }
    // println!("{}", ans);
}


Measured memory_bytes: 4352
#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>;
using vii=vector<vector<int>>;

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


int main(){
    ll K; cin >> K;
    ll num=7, ans=1;
    bool ok=false;
    for(int i=0; i<K; i++){
        if(num%K == 0){
            ok=true;
            break;
        }
        ans++;
        num=(10*num%K+7)%K;
    }
    cout << (ok ? ans:-1) << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

#define MAX_N 5010
#define INF 1e9

struct edge{int from,to,w;};
bool operator < (const edge &e, const edge &f) {
  return e.w != f.w ? e.w > f.w :
    e.from != f.from ? e.from < f.from : e.to < f.to;
}

vi befg[MAX_N];
vector<edge> g[MAX_N];
int n,m;
pii taxi[MAX_N];
// http://www.prefield.com/algorithm/graph/dijkstra.html
vi dijkstra(int s) {
  vi dist(MAX_N);
  dist.assign(n, INF); dist[s] = 0;
  priority_queue<edge> Q; // "e < f" <=> "e.weight > f.weight"
  for (Q.push((edge){-2, s, 0}); !Q.empty(); ) {
    edge e = Q.top(); Q.pop();
    // if (prev[e.to] != -1) continue;
    REP(i,g[e.to].size()){
      edge f = g[e.to][i];
      if (dist[f.to] > e.w+f.w) {
        dist[f.to] = e.w+f.w;
        Q.push((edge){f.from, f.to, e.w+f.w});
      }
    }
  }
  return dist;
}

#define MP make_pair

int main(){
  cin>>n>>m;
  REP(i,n){
    int cst,lim;
    cin>>cst>>lim;
    taxi[i] = MP(cst,lim);
  }
  REP(i,m){
    int u,v;
    cin>>u>>v;--u;--v;
    befg[u].push_back(v);
    befg[v].push_back(u);
  }
  vector<bool> used(n);
  REP(i,n){
    // bfs
    queue<pii> q;
    int cost = taxi[i].first;
    int lim = taxi[i].second;
    q.push(MP(lim,i));
    REP(j,n)used[j]=false;
    used[i] = true;
    while(!q.empty()){
      pii p = q.front();q.pop();
      int nowpos = p.second;
      int cnt = p.first;
      if(cnt == 0)continue;
      REP(j,befg[nowpos].size()){
        int dst = befg[nowpos][j];
        if(used[dst])continue;
        q.push(MP(cnt-1,dst));
        used[dst] = true;
        g[i].push_back((edge){i,dst,cost});
      }
    }
  }
  int res = dijkstra(0)[n-1];
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 182900
//circle.cpp
#include<iostream>
using namespace std;

int main()
{
    int w,h,x,y,r;
    cin>>w>>h>>x>>y>>r;
    if (x>=r && y>=r && x<=w-r && y<=h-r)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 3120
island, fune = map(int, input().split(" "))
route = []
for i in range(fune):
    route.append(list(map(int, input().split(" "))))
temp = []
for i in range(fune):
    if route[i][0] == 1:
        temp.append(route[i][1])
for j in range(fune):
    if route[j][1] == island:
        temp.append(route[j][0])
 
 
print("POSSIBLE") if len(temp) != len(list(set(temp))) else print("IMPOSSIBLE")

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

#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ll IINF = INT_MAX;

int cnt[1000005];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    ll a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        cnt[a[i]]++;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        bool can = true;
        for (ll j = 1; j * j <= a[i]; j++) {
            if (a[i] % j == 0) {
                if (j == a[i]) {
                    if (cnt[j] - 1 > 0) {
                        can = false;
                        break;
                    }    
                } else {
                    if (cnt[j] > 0) {
                        can = false;
                        break;
                    }
                }
                int lol = a[i] / j;
                if (lol == a[i]) {
                    if (cnt[lol] - 1 > 0) {
                        can = false;
                        break;
                    }    
                } else {
                    if (cnt[lol] > 0) {
                        can = false;
                        break;
                    }
                }
            }
        }
        if (can) ans++;
    }
    cout << ans << '\n';
    return 0;
}

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

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

    int ans = 0;
    for (int n=1; n<=N; n+=2) {
        int div_num = 0;
        for (int x=1; x<=n; x++) {
            if (n%x==0) div_num++;
        }
        if (div_num == 8) ans++;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
 
int main(){
    int N,a=0;
    cin >> N ;
    int M[N],I[N];
for(int i=0; i<N;i++){
cin >> M[i];
I[i]=M[i];
}
 sort(M,M+N);
 for(int i=0; i<N;i++){
if(M[i]!=I[i])a++;
}

if(a<3) cout <<"YES";
else cout <<"NO";
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>

using namespace std;

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

#define PI 3.1415926535897932384626433832795

int main(void)
{
	int a, b;
	while(scanf("%d%d", &a, &b)==2)
	{
		int xa=(a*100+8-1)/8;
		int xb=(b*100+10-1)/10;
		int x=max(xa, xb);

		if(x*8/100!=a || x*10/100!=b) x=-1;
		printf("%d\n", x);
	}
	return 0;
}


Measured memory_bytes: 128
from collections import deque
Q = deque()
q = int(input())
for i in range(q):
	a = input()
	if a[0] == '0':  # pushBack
		if a[2] == '0':
			Q.appendleft(a[4:])
		else:
			Q.append(a[4:])
	elif a[0] == '1':
		print(Q[int(a[2:])])  # randomAccess
	else:  # popBack
		if a[2] == '0':
			Q.popleft()
		else:
			Q.pop()


Measured memory_bytes: 34600
#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() {
    int A, B;
    cin >> A >> B;
    int n = B - A;
    int count = 0;
    rep(i, n+1) {
        int a1 = A / 10000;
        int a2 = A % 10000 / 1000;
        int a4 = A % 10000 % 1000 % 100 / 10;
        int a5 = A % 10000 % 1000 % 100 % 10;
        if (a1 == a5 and a2 == a4) count += 1;
        A += 1;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3604