akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
namespace AtCoder.AGC011
{
    static class AirportBus
    {
        static int AddPassenger(this Queue<int> que, int c, int k, int lastTime)
        {
            if (que.Count != 0 && que.Peek() + k < lastTime)
            {
                for (var i = 0; que.Count != 0 && i != c; ++i)
                    que.Dequeue();
                return 1 + AddPassenger(que, c, k, lastTime);
            }
            else
            {
                que.Enqueue(lastTime);
                return 0;
            }
        }
        public static void Main()
        {
int n, c, k;
            Read(ReadLine(), out n, out c, out k);
            var passenger = new int[n];
            for (var i = 0; i < n; ++i)
                passenger[i] = int.Parse(ReadLine().Trim());
            var taiki = new Queue<int>();
            int sum = 0;
            foreach (var p in passenger.OrderBy(i => i))
                sum += taiki.AddPassenger(c, k, p);
            WriteLine(sum + (c - 1 + taiki.Count) / c);
        }
        static void Read(string str, out int n, out int c, out int k)
        {
            var s = str.Trim().Split(' ').Select(i => int.Parse(i)).ToArray();
            n = s[0]; c = s[1]; k = s[2];
        }
    }
}


Measured memory_bytes: 16988
N = int(input())
L = list(map(int,input().split()))
def count(L):
    if L == []:
        return 0
    if 0 in L:
        i = L.index(0)
        return count(L[:i]) + count(L[i+1:])
    else:
        m = min(L)
        L = list(map(lambda x:x-m,L))
        return m + count(L) 
print(count(L))


Measured memory_bytes: 3188
#include <iostream>
#include <string>
using namespace std;
int main(){
  string s;
  cin >> s;
  
  for (char c = 'a'; c <= 'z'; c++){
    if (s.find(c) == string::npos){
      cout << c << endl;
      return 0;
    }
  }
  cout << "None" << endl;
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int a[101010];
int t[101010];
int cmp(const int &x,const int &y)
{
	return a[x]<a[y];
}
int main()
{
	int n;
	int ans=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
		t[i]=i;
	sort(t+1,t+1+n,cmp);
	for(int i=2;i<=n;i+=2)
		ans+=(t[i]&1);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1024
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn main() {
    let mut bingo: Vec<Vec<i32>> = read_vec2(3);
    let n: u32 = read();
    for _ in 0..n {
        let b: i32 = read();
        for i in 0..3 {
            for j in 0..3 {
                if bingo[i][j] == b {
                    bingo[i][j] *= -1;
                }
            }
        }
    }

    for i in 0..3 {
        if bingo[0][i] < 0 && bingo[1][i] < 0 && bingo[2][i] < 0 {
            println!("Yes");
            return;
        }
        if bingo[i][0] < 0 && bingo[i][1] < 0 && bingo[i][2] < 0 {
            println!("Yes");
            return;
        }
    }
    if bingo[0][0] < 0 && bingo[1][1] < 0 && bingo[2][2] < 0 {
        println!("Yes");
        return;
    }
    if bingo[2][0] < 0 && bingo[1][1] < 0 && bingo[0][2] < 0 {
        println!("Yes");
        return;
    }
    println!("No");
}


Measured memory_bytes: 4352
n, k = [int(x) for x  in input().split()]





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)

print(len(Base_10_to_n(n, k)))

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

    int price[n];

    int maxPrice = 0;
    int maxPriceIndex = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> price[i];

        if (maxPrice < price[i])
        {
            maxPrice = price[i];
            maxPriceIndex = i;
        }
    }
    
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        if (maxPriceIndex == i)
        {
            sum += (price[i] / 2);
            continue;
        }

        sum += price[i];
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=1;i<=n;++i)
#define INF (1ll<<60)
#define mod 1000000007
#define P pair<ll,ll>
#define Graph vector<vector<ll>>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main(){
    ll n;cin>>n;

    for(ll n2=1;n2<=n;n2++){
        ll ans=0;
        for(ll x=1;x*x<=n2/6;x++){
            for(ll y=1;y*y<=n2/3;y++){
                
                ll z=1,ng=n2;
                while(ng-z>1){
                    ll mid=(z+ng)/2;
                    if(x*x+y*y+mid*mid+x*y+y*mid+mid*x<=n2){
                        z=mid;
                    }else{
                        ng=mid;
                    }
                }

                //cout<<x<<" "<<y<<" "<<z<<endl;
                if(x*x+y*y+z*z+x*y+y*z+z*x!=n2) continue;
                

                if(x<y && y<z) ans+=6;
                if(x==y && y<z){
                    ans+=3;
                }
                if(x<y && y==z){
                    ans+=3;
                }
                if(x==y && y==z){
                    ans++;
                }    
            }
        }
        
        cout<<ans<<endl;
    }

    return 0;
}

Measured memory_bytes: 3520
#include<iostream>
using namespace std;
char c[51][51];
int H,W,cnt;

int main(){
	ios::sync_with_stdio(0);
	cin>>H>>W;
	for(int i=1;i<=H;++i){
		for (int j=1;j<=W;++j){
			cin>>c[i][j];
		}
	}
	for(int i=1;i<=H;++i){
		for(int j=1;j<=W;++j){
			if(c[i][j]=='#'&&c[i][j-1]!='#'&&
			c[i-1][j]!='#'&&c[i][j+1]!='#'&&
			c[i+1][j]!='#')++cnt;
		}
	}
	if(cnt==0)cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 256
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (int i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

ll A;
ll B;
ll C;
ll N;
ll M;
ll K;

int main(){

    
    cin >> N;
    cin >> M;

    if(N>=10){
        cout << M << endl;
    }else{
        cout << M + 100 * (10-N) << endl;
    }

    

}

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

int main()
{
	int a,b,c,d,sum=0;
	string s;
    cin>>a>>b;
    if(a-b<0)
        cout<<'0';
    else
    {
        cout<<a-b;
    }
	
	
	return 0;
}
	

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <vector>
#define N 200005
using namespace std;

int n, m, s;
bool v[N];
vector<int> a[N];
void f(int p, int q) {
	int i;
	if (q > 2) return;
	if (v[p]) return;
	v[p] = true;
	for (i = 0; i < a[p].size(); i++) {
		f(a[p][i], q + 1);
	}
}
int main()
{
	int i, t1, t2;
	cin >> n >> m;
	for (i = 0; i < m; i++) {
		scanf ("%d %d", &t1, &t2);
		a[t1].push_back(t2);
		a[t2].push_back(t1);
	}
	f(1, 0);
	if (v[n]) cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;
    return 0;
}


Measured memory_bytes: 12144
import copy

def solve():
    N,M = map(int, input().split())
    graph = {i:[] for i in range(1,N+1)}
    for _ in range(M):
        a,b = map(int, input().split())
        graph[a].append(b)
        graph[b].append(a)
        
    stack = [1]
    ret = 0
    searched = [False]*(N+1)
    searched[1] = True
    
    def dfs(dom, searched, prev=-1):
        searched[dom] = True
        ret = 0
        
        if all(searched[1:]): 
            # print(dom,searched,ret)
            return ret+1
        
        for cod in graph[dom]:
            # print(dom,cod)
            if not searched[cod]:
                ret += dfs(cod, copy.copy(searched),dom)
        
        return ret
            
    ret = dfs(1, searched)
    print(ret)
    
solve()

Measured memory_bytes: 3444
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author apurba_debnath
 */

#include <bits/stdc++.h>

#define ll long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl

using namespace std;

class AAirConditioner {
public:
    void solve(std::istream &in, std::ostream &out) {
        int t;
        in >> t;
        if (t >= 30)
            out << "Yes";
        else
            out << "No";
    }
};


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

    AAirConditioner solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);

    return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>

int main() {
  int N, verdict[4] = {0}; // AC, WA, TLE, RE
  scanf("%d", &N);

  for(int i = 0; i < N; i++) {
    char str[5];
    scanf("%s", str);
    switch(str[0]) {
      case 'A':
        verdict[0]++;
        break;
      case 'W':
        verdict[1]++;
        break;
      case 'T':
        verdict[2]++;
        break;
      case 'R':
        verdict[3]++;
        break;
    }
  }

  printf("AC x %d\n", verdict[0]);
  printf("WA x %d\n", verdict[1]);
  printf("TLE x %d\n", verdict[2]);
  printf("RE x %d\n", verdict[3]);
  return 0;
}

Measured memory_bytes: 2152
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;


int main() {
    ll n, m; cin >> n >> m;
    vector<ll> a(n), b(n);
    ll x =0;
    for (int i=0; i<m; i++) {
        ll p; string s; cin >> p >> s; p--;
        if (a[p] == -1) continue;
        if (s == "AC") {
            x++; a[p] = -1;
        } else {
            if (a[p] != -1) b[p]++;
        }
    }
    ll ret = 0; for(int i=0; i<n; i++) if (a[i] == -1) ret += b[i];
    cout << x << " " << ret << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
int myctoi(char C) {return C - 48;}
char myitoc(int N) {return '0' + N;}

signed main()
{
  int N, A, B;
  cin >> N >> A >> B;

  string ans = "Borys";
  if ((B - A) % 2 == 0) ans = "Alice";
  
  cout << ans << endl;
}

Measured memory_bytes: 384
{-# LANGUAGE OverloadedStrings #-}

import qualified Data.ByteString.Char8 as B
import Data.Attoparsec.ByteString.Char8

type Input  = (Int, Int, Int, Int)
type Output = Int

input :: Parser Input
input = do
  (_H, _W) <- decimalPair
  (_h, _w) <- decimalPair
  return (_H, _W, _h, _w)

decimalPair :: Parser (Int, Int)
decimalPair = (,) <$> decimal <* space <*> decimal <* endOfLine

main :: IO ()
main = B.interact
  $ B.pack . show . either (error "parse err") solve . parseOnly input

solve :: Input -> Output
solve (_H, _W, _h, _w) = (_H - _h) * (_W - _w)

Measured memory_bytes: 508
k = int(input())
a, b = map(int, input().split())
if b % k == 0:
    ans = 'OK'
elif a % k == 0:
    ans = 'OK'
elif (b // k) - (a // k) > 0:
    ans = 'OK'
else:
    ans = 'NG'

print(ans)


Measured memory_bytes: 9192
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
//#include <conio.h>
using namespace std;

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

#define rep(i,n)	for(ll i=0;i<(n);i++)
#define SZ(x) ((ll)x.size())
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define F first
#define S second
#define int ll
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// const ll MOD = INT_MAX;
const double PI = acos(-1);

void openfile(){
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
}
const int N = 105,K = 2e5+5,MOD = 1e9+7;
int dp[N][K];
int a[N];

int func(int l,int r){
	if(dp[l][r] != 0)	return dp[l][r];
	if(r-l == 0)	return dp[l][r] = a[l];
	if(r-l == 1)	return dp[l][r] = max(a[l],a[r]);
	return dp[l][r] = 
		max(min(func(l+2,r), func(l+1,r-1)) + a[l],min(func(l+1,r-1),func(l,r-2)) + a[r]);
}

signed main(){
	IOS
	int n,k;	cin >> n >> k;
	rep(i,n)	cin >> a[i];
	dp[0][k] = 1;
	rep(i,n+1){
		for(int j = k;i != 0 && j >= 0;j--){
			dp[i][j] = (dp[i-1][j] - dp[i-1][j + a[i-1]+ 1] + MOD) % MOD;
			if(j != k)	dp[i][j] = (dp[i][j] + dp[i][j+1]) % MOD;
		}
	}
	/*
	rep(i,n+1){
		rep(j,k+1)	cout << dp[i][j] << ' ';
		cout << endl;
	}
	*/
	cout << dp[n][0] << endl;
}


Measured memory_bytes: 156416
#include<iostream>
#include<string>
using namespace std;
int main(){
  int n,m,s,max,cnt;
  string  str,str1;
  cin>>n;
  for(int i=0;i<n;i++){
     cin>>str;
     cnt=0;
     while(1){
       if(str.size()==1) break;
       str1=str[0],max=0;
     for(int j=0;j<str.size()-1;j++){
       if(j>0) str1+=str[j];
       m=stoi(str1),s=stoi(&str[j+1]);
       if(max<m*s) max=m*s;
     }
     str=to_string(max),cnt++;
     }
     cout<<cnt<<endl;    
  }
  return 0;
}

Measured memory_bytes: 3276
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int n, m, x;
int c[12];
int a[12][12];

int answer = INT32_MAX;

void Compute(int num, vector<bool> isusing) {
    if (num < n) {
        isusing[num] = false;
        Compute(num + 1, isusing);
        isusing[num] = true;
        Compute(num + 1, isusing);
        return;
    }

    int rikaido[12];
    for (int i = 0; i < 12; i++) rikaido[i] = 0;
    int ans = 0;

    for (int i = 0; i < n; i++) {
        if (!isusing[i]) continue;
        for (int j = 0; j < m; j++) {
            rikaido[j] += a[i][j];
        }
        ans += c[i];
    }

    bool canuse = true;
    for (int i = 0; i < m; i++) {
        if (rikaido[i] < x) canuse = false;
    }

    if(canuse) answer = min(ans, answer);
}



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

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

    vector<int> rikaido(m);
    vector<bool> isusing(n);

    Compute(0, isusing);

    if (answer == INT32_MAX) {
        cout << -1 << endl;
    }
    else {
        cout << answer << endl;
    }

    return 0;
}

Measured memory_bytes: 3636
import itertools
def main():
    N,M,X = map(int, input().split())
    C = [0 for i in range(N)]
    A = [[0]*M for i in range(N)]
    for i in range(N):
        tmp = list(map(int, input().split()))
        C[i] = tmp[0]
        A[i] = tmp[1:(M+1)]

    texts_no = [i for i in range(N)]
    price_min = 0
    for i in range(1,N+1):
        # 教科書i冊(0~i-1)を選ぶ組み合わせ
        cmb = list(itertools.combinations(texts_no,i))
        for cmbset in cmb:
            # 理解度all0に初期化
            understand = [0 for _ in range(M)]
            price_tmp = 0
            for text in cmbset:
                understand = [understand[j]+A[text][j] for j in range(M)]
                price_tmp += C[text]
            # 条件を満たすなら最小値を更新
            joken = [True if n>=X else False for n in understand]
            if False not in joken:
                if price_min==0: price_min = price_tmp
                else: price_min = min(price_min, price_tmp)

    if price_min!=0: print(price_min)
    else: print(-1)


main()


Measured memory_bytes: 9316
#include<bits/stdc++.h>
using namespace std;
int main ()
{
    int n,i;
    int a[1000];
    cin>>n;
    for(i=0; i<n; i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    int mn;
    /*int j;
    for(i=0; i<n; i++)
    {
        for(j=0; j<i; j++)
        {
            if(a[i]==a[j])
            {
                mn=j-i;
            }
        }
    }*/
    mn=a[n-1]-a[0];

    cout<<mn<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;

int main() {
  int W, a, b; cin >> W >> a >> b;
  int ans = 0;
  if (a+W < b) {
    ans = b - (a+W);
  }
  else if (b+W < a) {
    ans = a - (b+W);
  }
  else {
    ans = 0;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner scn = new Scanner(System.in);
        String[] NM = (scn.nextLine()).split(" ");
        int N = Integer.valueOf(NM[0]);
        int M = Integer.valueOf(NM[1]);
        String[] Am = (scn.nextLine()).split(" ");
        int sum = 0;
        int result = 0;
        for(int i=0;i<M;i++){
            sum += Integer.valueOf(Am[i]);
        }
        if(sum <= N){
            result = N -sum;
        }else{
            result = -1;
        }
        System.out.println(result);

    }
}

Measured memory_bytes: 39444
import numpy as np

N = int( input() )
A = np.array(list( map( int, input().split() ) ))

"""
任意の2組みの数字の符号を変えることができる
したがって負の数が偶数個の場合全てを正にして総和をとれば良い
負の数が奇数個の場合絶対値の最小のもののみ負にして総和をとればよい
0が存在する場合はすべて正にできる
"""

A_abs = np.abs(A)

if 0 in A:
    print(np.sum(A_abs))

else:
    num = 0
    for i in range(N):
        if A[i] < 0:
            num += 1

    if num % 2 == 0:
        print(np.sum(A_abs))
    else:
        print(np.sum(A_abs) - 2 * min(A_abs))


Measured memory_bytes: 25060
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
#define PI 3.14159265358979323846264338327950L
using namespace std;
using P = pair<int,int>;
using ll = long long;
using namespace std;
int main(void){
    // Your code here!
    ll x;
    cin >> x;
    ll ans = x / 500;
    x -= 500*ans;
    ll ans2 = x / 5;
    ll happy = 1000*ans + ans2*5;
    cout << happy  << endl;
    return 0;
}

Measured memory_bytes: 3576
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
char x[200100];
int main(int argc, char** argv) {
	scanf("%s",x);
	int len=strlen(x);
	int ans=len;
	int s=0;
	for(int i=0;i<len;i++){
		if(x[i]=='S'){
			s++;
		}else{
			if(s!=0){
				s--;ans-=2;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+50,mo=1e9+7;
int gi(){
    char ch=getchar(); int x=0,q=0;
    while(ch<'0'||ch>'9') q=ch=='-'?1:q,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return q?-x:x;
}
int fap(int a,int b){
    int s=1;
    for (; b; b>>=1,a=1ll*a*a%mo)
	if (b&1) s=1ll*s*a%mo;
    return s;
}
vector<int>f[N];
int sum=1,num[N],pl[N],nl[N],lmn[N],rmn[N];
int main(){
    int n=gi(),x=gi(),y=gi(),c,w;
    for (int i=1; i<=n; ++i)
	c=gi(),w=gi(),f[c].push_back(w);
    int mn=mo;
    memset(lmn,100,sizeof(lmn));
    memset(rmn,100,sizeof(rmn));
    for (int i=1; i<=n; ++i){
	if (f[i].size()>1)
	    sort(f[i].begin(),f[i].end());
	lmn[i]=lmn[i-1];
	if (f[i].size())
	    mn=min(mn,f[i][0]),lmn[i]=min(lmn[i],f[i][0]);
    }
    for (int i=n; i>=1; --i){
	rmn[i]=rmn[i+1];
	if (f[i].size())
	    rmn[i]=min(rmn[i],f[i][0]);
    }
    for (int i=1; i<=n; ++i)
	if (f[i].size()){
	    num[i]=1;
	    int val=min(lmn[i-1],rmn[i+1]);
	    while(num[i]<f[i].size()&&(f[i][num[i]]+f[i][0]<=x||f[i][num[i]]+val<=y))
		++num[i];
	}
    pl[0]=nl[0]=1;
    for (int i=1; i<=n; ++i)
	pl[i]=1ll*pl[i-1]*i%mo;
    nl[n]=fap(pl[n],mo-2);
    for (int i=n-1; i; --i)
	nl[i]=1ll*nl[i+1]*(i+1)%mo;
    int ans=0;
    if (2*mn>y) ans=1;
    for (int i=1; i<=n; ++i)
	if (num[i]&&f[i][0]+mn<=y)
	    ans+=num[i],sum=1ll*sum*nl[num[i]]%mo;
    sum=1ll*sum*pl[ans]%mo;
    cout<<sum;
    return 0;
}


Measured memory_bytes: 13184
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let mut a: Vec<i32> = (0..n + 1).map(|_| input()).collect();
    let mut b: Vec<i32> = (0..n).map(|_| input()).collect();

    let mut ans = 0i64;
    for i in 0..n {
        let t = std::cmp::min(a[i], b[i]);
        ans += t as i64;
        a[i] -= t;
        b[i] -= t;
        let t = std::cmp::min(a[i + 1], b[i]);
        ans += t as i64;
        a[i + 1] -= t;
        b[i] -= t;
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
result = []
m,f,r=[int(x) for x in input().split()]
while not m==f==r==-1:
    if (m == -1 or f == -1):
        res = "F"
    elif (m + f >= 80):
        res = "A"
    elif (65 <= m + f < 80):
        res = "B"
    elif (50 <= m + f < 65):
        res = "C"
    elif (30 <= m + f < 50):
        res = "D"
        if (50 <= r):
            res = "C"
    else :
        res = "F"
    result.append(res)
    m,f,r=[int(x) for x in input().split()]
for i in result:
    print(i)

Measured memory_bytes: 7704
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;






int main(){
    ll q;
    cin>>q;
    while(q--){
        ll fd=E,mx=-1,mx2=-1;
        string s,t;
        cin>>s>>t;
        if(s==t){cout<<0<<endl; continue;}
        for(int i=0;i<s.size();i++){
            if(s[i]!=t[i]){fd=min(fd,(ll)i);}
            if(s[i]=='1'){mx=max(mx,(ll)i);}
            if(t[i]=='1'){mx2=max(mx2,(ll)i);}
        }
        cout<<abs(fd-mx)+abs(mx2-fd)<<endl;
    }
    
    
    
    return 0;
}


Measured memory_bytes: 3220
use proconio::input;

fn main() {
    input! {
        n: i64
    }

    let max = {
        let mut max:i64 = 1;
        let mut k = 1;
        while k < n {
            k = (max+1).pow(5) - max.pow(5);
            max += 1;
        }
        max
    };
    
    let mut a: i64 = 0;
    let mut b: i64 = 0;
    let mut flag = false;
    for i in -max..=max {
        for j in -max..=max {
            if n == i.pow(5) - j.pow(5) {
                a = i as i64;
                b = j as i64;
                flag = true;
                break;
            }
        if flag {
            break;
        }
        }
    }

    println!("{} {}",a,b)
}

Measured memory_bytes: 2132
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]


class UnionFind:
    def __init__(self, n):
        self.par = [-1]*n
        self.size = [1]*n
        self.point = n*(n-1) // 2

    def root(self, x):
        if self.par[x] < 0:
            return x
        self.par[x] = self.root(self.par[x])
        return self.par[x]

    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx == ry:
            return False
        if self.size[rx] < self.size[ry]:
            rx, ry = ry, rx
        self.point -= self.size[rx]*self.size[ry]
        self.size[rx] += self.size[ry]
        self.par[ry] = rx
        return True

    def is_same(self, x, y):
        rx, ry = self.root(x), self.root(y)
        return rx == ry

    def get_size(self, x):
        return self.size[self.root(x)]


uf = UnionFind(N)
results = []
for a, b in AB[::-1]:
    results.append(uf.point)
    x, y = a-1, b-1
    uf.unite(x, y)

print(*results[::-1], sep="\n")

Measured memory_bytes: 37600
#include<stdio.h>

int main(){
int H,W,i,j;


while(1){
scanf("%d %d",&H,&W);
  if(H == W && H == 0){
  break;
  }else{
    for(j = 0; j < H ;j++){
      for(i = 0; i < W;i++){
      printf("#");
      }
    printf("\n");
    }
   printf("\n");
  }
}
return 0;
}


Measured memory_bytes: 2064
require 'prime'
require 'set'
require 'tsort'
include Math
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def pr?(num);              Prime.prime?(num)                          end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end


n = gif
s = gc
c = []
n.times do |i|
c << (s[0..i] & s[(i+1)..n])
end

puts c.map { |cc| cc.uniq.length }.max


Measured memory_bytes: 2428
//Heaplax
//别让自己后悔
#include<bits/stdc++.h>
#define N 2005
#define LL long long
#define LOG(x) cerr<<#x<<" = "<<x<<endl
#define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
	while(ch=getchar(),ch<33);
	if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
	while(ch=getchar(),ch>33)x=x*10+ch-48;
	if(fs)x=-x;
}
using namespace std;
int n,a[N];
int cnt,head[N],nxt[N*N],to[N*N];
bool vis[N];
void dfs(int u)
{
	vis[u]=1;
	for(int i=head[u],v;i;i=nxt[i])
		if(!vis[v=to[i]])
			dfs(v);
}
vector<int> solve(int u)
{
	vis[u]=1;
	vector<int> son;
	for(int i=head[u],v;i;i=nxt[i])
		if(!vis[v=to[i]])
			son.push_back(v);
	sort(son.begin(),son.end());
	vector<vector<int>> que;
	for(int v:son)if(!vis[v])
		que.push_back(solve(v));
	for(vector<int>& i:que)
		reverse(i.begin(),i.end());
	vector<int> res;
	res.push_back(a[u]);
	while(1)
	{
		int mx=0;
		vector<int> *num;
		for(vector<int> &i:que)
			if(!i.empty() && *i.rbegin()>mx)
				mx=*i.rbegin(),num=&i;
		if(!mx)break;
		(*num).pop_back();
		res.push_back(mx);
	}
	return res;
}
int main()
{
	re(n);++n;
	for(int i=2;i<=n;++i)re(a[i]);
	sort(a+2,a+n+1);
	for(int i=2;i<=n;++i)
		for(int j=i+1;j<=n;++j)
			if(__gcd(a[i],a[j]) != 1)
				add_edge(i,j),add_edge(j,i);
	for(int i=2;i<=n;++i)
		if(!vis[i])
		{
			add_edge(1,i);
			dfs(i);
		}
	memset(vis,0,sizeof vis);
	vector<int> ans=solve(1);
	for(int i=1;i<n;++i)
		printf("%d ",ans[i]);
	puts("");
}


Measured memory_bytes: 30336
#include <bits/stdc++.h>
#define rep0(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define mREP(i,a,b) for (int i = a; i > (b); --i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int main(){
  int n;
  cin >> n;
  int temp;
  map<int,int>anser;
  int count = 0;
  rep0(i,n){
    cin >> temp;
    if(temp >= 3200)count++;
    else if(temp >= 2800)anser[8]++;
    else if(temp >= 2400)anser[1]++;
    else if(temp >= 2000)anser[2]++;
    else if(temp >= 1600)anser[3]++;
    else if(temp >= 1200)anser[4]++;
    else if(temp >= 800)anser[5]++;
    else if(temp >= 400)anser[6]++;
    else anser[7]++;
  }
  if(anser.size() == 0){
    cout << 1 << " " << count<< endl;
  }
  else{
    cout << anser.size() << " " << (int)anser.size() + count << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#define taskname "test"

#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)x.size()
#define fi first
#define se second

typedef long long lli;
typedef pair<int, int> pii;

char c;

void read_input()
{
    cin >> c;
}

void solve()
{
    if('A' <= c && c <= 'Z')
        cout << "A\n";
    else cout << "a\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    read_input();
    solve();
}



Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
inline int read()
{
	int s=0,f=1;char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')ch=getchar(),f=-1;
	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
	return ~f?s:-s;
}

const int maxn=1e5+20;
const int mod=1e9+7;

inline void pls(int &a,int b){ a+=b;if(a>=mod)a-=mod;}

int n;
char str[maxn];
int s[maxn];

int nxt[maxn][3],num[3];

inline void init()
{
	scanf("%s",str+1);
	n=strlen(str+1);
	REP(i,1,n)s[i]=(s[i-1]+str[i]-'a'+1)%3;
	REP(j,0,2)num[j]=n+1;
	DREP(i,n,0)
	{
		num[s[i]]=i;
		REP(j,0,2)nxt[i][j]=num[j];
	}
	int flg=1;
	REP(i,1,n-1)if(str[i]!=str[i+1]);else flg=0; 
	if(flg)puts("1"),exit(0);
}

int dp[maxn];
int ans=0;

inline void doing()
{
	dp[0]=1;
	REP(i,0,n-1)
	{
		REP(j,1,2)
		{
			int k=nxt[i+1][(s[i]+j)%3];
			if(k<=n)pls(dp[k],dp[i]);
		}
	}
	REP(i,1,n)if(s[i]==s[n])pls(ans,dp[i]);
	printf("%d\n",ans);
}

int main()
{
	init();
	doing();
	return 0;
}


Measured memory_bytes: 2304
// AGC025A - Digits Sum

#include <bits/stdc++.h>
using namespace std;

int SumOfDigits(int n) {
	int ans = 0;

	while (n > 0) {
		ans += n % 10;
		n /= 10;
	}

	return ans;
}

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

	int minT = 1000;
	for (int i = 1; i < N; i++) {
		int temp;
		temp = SumOfDigits(i) + SumOfDigits(N - i);
		minT = min(minT, temp);
	}

	cout << minT << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
#include <cstring> 
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define LLONG_MAXs 9223372036854775800

#include <iostream>
#include <cmath>
using namespace std;
 

 
bool isPrimeNum( ll x ){ // 素数である場合 true を返す
  if( x <= 1 ){ // 1以下である場合は素数でないことがすぐにわかる
    return false;
  }
  // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
  int n = (int)sqrt( (double)x );
  for( int i = 2; i <= n; i++ ){
    if( x % i == 0 ){ // 割り切る整数がある場合、即判定終了
      return false;
    }
  }
  return true; // 割り切る整数がない場合、素数である
}

constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
constexpr ll min(ll a,ll b){
if(a>=b)return b;
if(a<b)return a;
}

constexpr ll max(ll a,ll b){
if(a>=b)return a;
if(a<b)return b;
}

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

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
  ll N;
  cin>>N;
    ll ans=0;
  FOR(i,0,N-1){
    ll tmp;
    cin>>tmp;
    while(tmp%2==0){
      tmp=tmp/2;
      ans++;
    }

  }


  cout<<ans<<endl;


}
 


Measured memory_bytes: 256
MOD = 10 ** 9 + 7


def prepare(n):
    global MOD
    modFacts = [0] * (n + 1)
    modFacts[0] = 1
    for i in range(n):
        modFacts[i + 1] = (modFacts[i] * (i + 1)) % MOD

    invs = [1] * (n + 1)
    invs[n] = pow(modFacts[n], MOD - 2, MOD)
    for i in range(n, 1, -1):
        invs[i - 1] = (invs[i] * i) % MOD

    return modFacts, invs


def comb(n, r):
    global MOD, modFacts, invs
    return (modFacts[n] * invs[n - r] * invs[r]) % MOD


def perm(n, r):
    global MOD, modFacts, invs
    return (modFacts[n] * invs[n - r]) % MOD


S = int(input())
modFacts, invs = prepare(S)
ans = 0
for k in range(1, S // 3 + 1):
    s = S - 3 * k
    cnt = comb(k - 1 + s, s)
    ans += cnt
    ans %= MOD
print(ans)


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

def count(s, word_list, max_count, word_count):
    if s not in word_count:
        word_count[s] = 0
    word_count[s] += 1

    if word_count[s] >= max_count:
        if word_count[s] > max_count:
            word_list = []
            max_count = word_count[s]
        word_list.append(s)
    else:
        pass

    return word_list, max_count, word_count

        
word_list = []
max_count = 0
word_count = {}
for _ in range(N):
    s = input()
    word_list, max_count, word_count = count(s, word_list, max_count, word_count)

for w in sorted(word_list):
    print(w)


Measured memory_bytes: 33416
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    cin>>s;
    std::deque<char> deq;
    int flag=0;
    for (int i=0;i<s.size();i++) {
        if (find(deq.begin(),deq.end(),s.at(i))!=deq.end()) {
            cout<<"no"<<endl;
            flag=1;
            break;
        } else {
            deq.emplace_back(s.at(i));
        }
    }
    if (flag==0) {
        cout<<"yes"<<endl;
    }
}


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

typedef unsigned int uint;

int main() {
	uint n,temp;
	vector<uint> a;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> temp;
		a.push_back(temp);
	}

	uint sum_a = accumulate(a.begin(), a.end(), 0);
	uint sum_even_a=0;
	for (int i = 1; i <= n - 2; i += 2)
		sum_even_a += a[i];

	vector<uint> rain;
	rain.push_back(sum_a - 2 * sum_even_a);
	for (int i = 1; i < n; i++)
		rain.push_back(2 * a[i-1] - rain[i - 1]);
	
	for (auto& num : rain)
		cout << num <<" ";

	return 0;
}

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

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define deb(x)	cout << #x << " " << x << endl;
#define pi 3.141

typedef long long int ll;

int main() {

	IOS

	int r;
	cin >> r;

	cout << 2 * M_PI * r << endl;
	return 0;
}

Measured memory_bytes: 3800
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
typedef long long ll;
using namespace std;

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

int main(void){
  ll a,b,i,cnt;
  cin>>a>>b;
  
  ll g=gcd(a,b);

  cnt=1;
  for(i=2;i*i<=g;i++) {
    
    if(g%i==0){
      while(g%i==0) {
        g/=i;
      }
      cnt++;
    }
  }
  if(g!=1){
    cnt++;
  }

  cout<<cnt<<endl;

  return 0;
}


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

int64_t Calc_Target(int64_t n, int64_t t)
{
	int64_t ans = 0;
	int64_t tick = 0;
	// 厚さの計算
	tick = 4 * pow(2, n) - 3;

	if (n == 0)
	{
		if (t > 0)
		{
			ans = 1;
		}
	}
	else
	{
		if (((tick + 1) / 2) <= t)
		{
			// 指定場所が厚さの1/2より大きければひとつ下のレベルのパティはまるまる食べることができる
			ans = (pow(2, n + 1 - 1) - 1) + 1 + Calc_Target(n - 1, t - (tick + 1) / 2);
		}
		else
		{
			// 指定場所が厚さの1/2より小さい時はひとつ下のレベルで再計算
			ans = Calc_Target(n - 1, t - 1);
		}
	}
	return(ans);
}


int main()
{
	int64_t N, X;
	int64_t ans = 0;

	cin >> N >> X;

	if (N > 0)
	{
		ans = Calc_Target(N, X);
	}

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


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

int main(void){
    int N,M;
    cin >> N >> M;
    vector<int> vec(M);
    for (int i = 0; i < M; i++){
        cin >> vec.at(i);
    }
    int sum = 0;
    for (int i = 0; i < M; i++){
        sum += vec.at(i);
    }
    
    if(sum <= N){
        N -=sum;
        cout << N << endl;
    }else{
        cout << "-1" << endl;
    }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	double md,s=0;
	cin>>n;
	double a[n],b[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		a[i]=a[i]-i-1;
		b[i]=a[i];
	}
	sort(b,b+n);
	if(n%2==1) md=b[(n-1)/2];
	else md=(b[n/2]+b[n/2-1])/2;
	for(int i=0;i<n;i++)
	{
		if(a[i]>md) s+=(a[i]-md);
		else s+=(md-a[i]);
	}
	cout<<(long long)s;
    return 0;
}

Measured memory_bytes: 6836
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    string s; cin >> s;
    int a = 0, m = 0;
    rep (i, n) {
        a += s[i] == '(' ? 1 : -1; 
        chmin(m, a);
    }
    rep (i, -min(0, m)) cout << '(';
    a = -m;
    rep (i, n) {
        a += s[i] == '(' ? 1 : -1; 
        cout << s[i];
    }
    rep (i, a) cout << ')';
    cout << "\n";
    return 0;
}

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

struct P {
	int k;
	ll l, r;
	P(int k, ll l, ll r): k(k), l(l), r(r) {}
	P() {}
	bool operator < (const P &p) const {
		if (k != p.k) return k < p.k;
		if (l != p.l) return l < p.l;
		return r < p.r;
	}
};

const int N = 2e5 + 7;
std::vector<P> vec;
int X, D, n;

int main() {
	scanf("%d%d%d", &n, &X, &D);
	if (D == 0) {
		if (!X) puts("1");
		else printf("%d\n", n + 1);
		return 0;
	}
	if (D < 0) D = -D, X = -X;
	for (int k = 0; k <= n; k++) {
		ll l = 1LL * (k - 1) * k / 2;
		ll r = 1LL * (n - k + n - 1) * k / 2;
		ll kk = 1LL * k * X;
		l += kk / D, r += kk / D;
		vec.push_back(P(kk % D, l, r));
	}
	ll ans = 0;
	std::sort(vec.begin(), vec.end());
	for (int i = 0, j; i <= n; i = j) {
		j = i;
		while (j <= n && vec[i].k == vec[j].k) j++;
		for (int p = i, q; p < j; p = q) {
			q = p;
			ll r = vec[p].r;
			while (q < j && vec[q].l <= r) {
				r = std::max(r, vec[q].r);
				q++;
			}
			ans += r - vec[p].l + 1;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

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

#define rep(i, s, n) for(int i = s; i < n; ++i)
#define rrep(i, n) for(int i = n - 1; i > -1; --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
const long long INF = 1000000000;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int n, d;
    cin >> n >> d;
    if(n % (2 * d + 1) == 0){
        cout << n / (2 * d + 1) << endl;
    }else{
        cout << n / (2 * d + 1) + 1 << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <cstdlib>
#include <fstream>
#include <climits>
#include <queue>

using namespace std;

int main(int argc, char **argv) {
    int n, m;
    scanf("%d%d", &n, &m);
    vector<vector<int> > g(n);
    for (int i = 0; i < m; ++i) {
        int from, to;
        scanf("%d%d", &from, &to);
        --from, --to;
        g[from].push_back(to);
    }
    int src, dest;
    scanf("%d%d", &src, &dest);
    --src, --dest;
    queue<pair<int, int> > qu;
    vector<vector<bool> > visit(n, vector<bool>(3, false));
    qu.push(make_pair(src, 0));
    visit[src][0] = true;
    int answer = -1;
    while (!qu.empty()) {
        int node = qu.front().first;
        int cost = qu.front().second;
        qu.pop();
        if (node == dest && cost % 3 == 0) {
            answer = cost / 3;
            break;
        }
        for (int to : g[node]) {
            int cost_mod = (cost + 1) % 3;
            if (visit[to][cost_mod])
                continue;
            visit[to][cost_mod] = true;
            qu.push(make_pair(to, cost + 1));
        }
    }
    printf("%d\n", answer);
    return 0;
}

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

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

	string x = "";
	
	int l = 0;
	while (l<r)
	{
		x+= s[l];
		x+= t[l];
		
		l++;
	}
	cout<<x<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

int main(void) {
	int num, i;
	string s;
	cin >> s;
	if (s[0] == s[1] && s[1] == s[2])
		printf("No\n");
	else
		printf("Yes");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>

using namespace std;

int main(){
   int n;
   int t,a;
   cin >> n;
   cin >> t >> a;

   int ans = 0;
   long current = -1;
   for(int i=0;i<n;i++){
      int x;
      cin >> x;
      if(current == -1){
         ans = i + 1;
         current = 1000 * t - x * 6;
      }else {
         long tgt = 1000 * t - x * 6;
         if(labs(1000 * a - tgt) < labs(1000 * a - current)){
            ans = i + 1;
            current = tgt;
         }
      }
   }

   cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
vector <vector <int> > A(4);
int main () {
	long long k, a, b;
	cin >> k >> a >> b;
	if(a >= b - 2)
	{
		cout << k + 1;
		return 0;
	}
	else 
	{
		long long count = a;
		k -= a - 1;
		count += k / 2 * (b - a);
		if(k % 2 !=0)
		{
			count++;
		}
		cout << count;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> 
//using boost::multiprecision::cpp_int;
using namespace std;
#define ll long long int
#define F first
#define S second
//#define endl "\n"
//#define nl cout<<endl;
#define pb push_back
#define ull unsigned long long 
#define f(i,a,b) for(ll i=a;i<b;i++)
#define Knucklehead ios_base::sync_with_stdio(false);cin.tie(NULL);
//#define mod 100000007
#define mat vector<vector<ll>>
mat cn(ll n, ll m){return vector< vector<ll> >(n, vector<ll>(m));}
bool compare(char &s1,char &s2){return s1 > s2;} 
bool sortmahstyle(const pair<ll,ll> &a,  const pair<ll,ll> &b) 
{ 
    if(a.second > b.second )
        return true;
    if( a.second==b.second && a.first > b.second )
       return true;
    return false;
}
bool cmp(int n, pair<int, int> const& p)
{
    return (p.first < n);
}
//me
ll const mod = 1e9+7;//998244353;
ll const inf = 1e18;
ll const maxn = 1e5+1;
array<ll,2> A[maxn], B[maxn];
void solve()
{    
     
     ll n; cin >> n;

     
     f(i,0,n){
          ll xx; cin >> xx;
          if(i&1)A[xx][0]++,A[xx][1]=xx;
          else B[xx][0]++,B[xx][1]=xx;
     }

     sort(A,A+maxn);
     sort(B,B+maxn);
     reverse(A,A+maxn);
     reverse(B,B+maxn);

     ll larAval = A[0][1], larAcnt = A[0][0];
     ll larBval = B[0][1], larBcnt = B[0][0];
     ll seclarAcnt=A[1][0], seclarBcnt=B[1][0];
    

     if( larAval!=larBval )
          cout << n - (larAcnt+larBcnt);
     else{
          ll x = n - (larAcnt + seclarBcnt );
          ll y = n - (larBcnt + seclarAcnt );
          cout << min(x,y);
     }
 
}

int main() {
Knucklehead 
//*
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
/**/ 
          
          ll t;
          /**/t=1;
          /*/cin>>t;/**/
          f(testcases,0,t){
               //cout << "Case #" <<testcases+1<<": ";
               solve();
          }
 
 
    return 0;
}

Measured memory_bytes: 6752
/*#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
*/

#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define fi first
#define se second
#define pf push_front
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define debug(x) cerr<<#x<<": "<<(x)<<'\n'
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9+7;
const ll inf = 0x3f3f3f3f;
const ll nax = 0;
ll n, ans=0;

int main(){
	IOS
	string s; cin >> s;
	int n=s.length();
	for(int i=0;i<n;++i){
		ans+=(s[i]-'0');
	}
	//debug(ans);
	if(ans%9==0){
		cout << "Yes" << '\n';
	}
	else cout << "No" << '\n';
}


Measured memory_bytes: 3756
#include<bits/stdc++.h>
#define maxn 100000+6
using namespace std;
int n,num,w[maxn];
int check(long long p){
	int k=0;
	for(int i=0;i<num;i++){
		long long sum=0;
		while(sum+w[k]<=p){
			sum+=w[k];
			k++;
			if(k==n)return n;
		} 
	}
	return k;
}
int binarySearch(int left,int right){
	while(right>left){
		int mid=(left+right)>>1;
		int num=check(mid);
		if(num==n)right=mid;
		else left=mid+1;
	}
	return right;
}
int main(){
	
	while(scanf("%d%d",&n,&num)==2){
		for(int i=0;i<n;i++){
			scanf("%d",&w[i]);
		}
//		sort(w,w+n);
		cout<<binarySearch(0,100000*10000)<<endl;
	}
	return 0;
} 


Measured memory_bytes: 3524