akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int M=1e4+10;
typedef long long ll;
const ll mod=1e9+7;
ll gcd(ll a,ll b)
{
	return b==0?a:gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
	return b/gcd(a,b)*a;
}
int a[M],mn,mx;
map<int,int> mp;
ll quick_mod(ll a,ll b){
	ll ans=1;
	a%=mod;
	while(b){
		if(b&1)ans=(ans%mod * a%mod)%mod;
		a=(a%mod * a%mod)%mod;
		b>>=1;
	}
	return ans%mod;
}
ll get_inv(ll x){
	return quick_mod(x,mod-2);
}

void sol(int x){
	for(int i=2;i*i<=x;i++){
		if(x%i==0){
			int c=0;
			mn=min(mn,i);mx=max(mx,i);
			while(x%i==0){c++;x/=i;}
			mp[i]=max(mp[i],c);
		}
	}
	if(x>1){mp[x]=max(1,mp[x]);mn=min(mn,x);mx=max(mx,x);}
	return;
}
int main(int argc, char const *argv[])
{
	mp.clear();mn=1e6+10;mx=-1;
	int n;cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=n;i++)sol(a[i]);
	
	ll sum=1;
	for(int i=mn;i<=mx;i++){
		if(mp[i]>0){
			for(int j=1;j<=mp[i];j++)sum=(sum%mod * i%mod)%mod;
		}
	}
	
	ll ans=0;
	for(int i=1;i<=n;i++){
		ll tmp=(sum%mod * get_inv(a[i])%mod)%mod;
		ans=(ans+tmp)%mod;
	}
	cout<<ans<<endl;
	return 0;
}


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

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VC> VVC;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define LB lower_bound
#define UB upper_bound

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1e9;
const LL MOD = 1e9+7;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

//memo
// setprecision()

LL Gcd(LL a, LL b) {
  return __gcd(a,b);
}

LL Lcm(LL a, LL b) {
  LL abd = Gcd(a,b);
  LL x = a / abd, y = b / abd;
  
  return x*y*abd;
}


LL RepSqu(LL N, LL P, LL M) {
  if(P == 0) {
    return 1;
  }
  if(P%2 == 0) {
    LL t = RepSqu(N, P/2, M);
    return t*t % M;
  }
  return (N * RepSqu(N, P-1, M)) % M;
}

VI Erat(int x, int n) {
  VLL a(x);
  REP(i,x){
    a.at(i) = 1;
  }
  
  for(int i = 2; i < sqrt(x); i++){
    if(a.at(i)) {
      for(int j = 0; i*(j+2) < (x); j++) {
        a.at(i*(j+2)) = 0;
      }
    }
  }
  
  VI b;
  int j = 2;
  
  while(SZ(b) < n){
    if(a.at(j) == 1 && j%5 == 4){
      b.PB(j);
    }
    j++;
  }
  
  return b;
}


int main() {
  
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int N;
  cin >> N;
  
  VI a = Erat(55555,N+1);
  
  REP(i,N){
    cout << a.at(i);
    
    if(i != N-1)cout << endl;
    else cout << " ";
  }
  
  
  return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include <algorithm>
#include <string>
using namespace std;
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(int)(n); i++)
typedef long long ll;
const int INF = numeric_limits<int>::max();
const int MOD = (1e9 + 7);


int main(){
  string S;
  bool can;
  int ans = 0;
  cin >> S;
  for(int i=S.size()-2; i>=0; i--){
    if(i%2==1){ //iまでで倍列か
      can = true;
      for(int j=i; j>(i/2); j--){
        if(S[(j - ((i+1)/2))] != S[j])
          can = false;
      }
      if(can){
        ans = i+1;
        break;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
while M > 0:
	A = sorted(A, reverse=True)
	M -= 1
	A[0] = mx = A[0]//2
	for i in range(1, N):
		if M > 0:
			if A[i] > mx:
				A[i] = A[i]//2
				M -= 1
			else: break
		else: break
		
print(sum(A))

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    string S; cin >> S;
    vector<int> a(26,0);
    REP(i,S.size()){
        if(a[S[i]-'a'] > 0){
            cout << "no" << endl;
            return 0;
        }else{
            a[S[i]-'a']++;
        }
    }
    cout << "yes" << endl;
    return 0;
}

Measured memory_bytes: 3636
# f = open('input', 'r')
# n, t = map(int, f.readline().split())
# A = list(map(int, f.readline().split()))
n, t = map(int, input().split())
A = list(map(int, input().split()))

ans = 0
max_diff = 0
min_a = A[0]
for a in A:
    min_a = min(min_a, a)
    if (a - min_a) == max_diff:
        ans += 1
    elif (a - min_a) > max_diff:
        ans = 1
        max_diff = (a - min_a)
print(ans)


Measured memory_bytes: 15020
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
using P = pair<int, int>; 
using ll = long long;
 
int main()
{
  string a,b,c;
  cin >> a>> b>> c;
  a[0] = a[0] - 32;
  b[0] -= 32;
  c[0] -= 32;
  cout << a[0] << b[0] << c[0] << endl;
  return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int n, k, arr[100005];
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	sort(arr, arr + n);
	int mn = 2000000000;
	for (int i = 0; i <= n - k; i++)
	{
		mn = min(mn, arr[i + k - 1] - arr[i]);
	}
	cout << mn;
	return 0;
}


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

int main() {
	long long int test,n,i,j,k,x,y,t;
	cin>>n>>k;
	long a[n],dp[n];
	for(i=0;i<n;i++){
	    cin>>a[i];
	}
	dp[0]=0;
	dp[1]=dp[0]+abs(a[1]-a[0]);
//	k=2;
	for(i=2;i<n;i++){
	    dp[i]=1e9;
	    x=k;
	    j=1;
	    while(x--&&(i-j)>=0){
	        dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
	        j++;
	    }
	}
/*	for(i=0;i<n;i++){
	    cout<<dp[i]<<" ";
	}*/
	cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1792
n_a, n_b, m = gets.split.map(&:to_i)
a = []
b = []
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)

price = a.min + b.min
a = [nil] + a
b = [nil] + b

1.upto(m) do |i|
  x, y, c = gets.split.map(&:to_i)
  price = a[x] + b[y] - c if a[x] + b[y] - c < price
end

puts price

Measured memory_bytes: 20252
#include<bits/stdc++.h>
using namespace std;
#define re register
#define in inline
#define ll long long
#define get getchar()
#define mian main
const int _=1e6+10;
const int mod=1e9+7;
ll f[_];
int main()
{
	ll n;
	scanf("%lld",&n);
	f[n]=n;
	f[n-1]=(n*n)%mod;
	ll ans=0;
	for (re int i=n-2; i>=1; i--)
	{
		ans=(ans+f[i+3])%mod;
		f[i]=((((f[i+1]+((n-1)*(n-1))%mod)%mod)+ans)%mod+i+1)%mod;
	}
	cout<<f[1]<<endl;
	return 0;
}


Measured memory_bytes: 8064
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;


int main(int argc, char const *argv[]) {
    int A, B, C;
    scanf("%d %d %d", &A, &B, &C);
    vector<int> v = {A, B, C};
    vector<int>::iterator iter = max_element(v.begin(), v.end());
    int max = *iter;
    size_t index = distance(v.begin(), iter);
    // printf("%d\n", max);
    int x[2];
    int j = 0;
    for (int i = 0; i < 3; i++) {
        if (i != index) {
            x[j] = max - v[i];
            // printf("%d\n", x[j]);
            j++;
        }
    }
    int g = x[0] < x[1] ? 1 : 0;
    int l = x[0] > x[1] ? 1 : 0;
    int d = x[g] - x[l];
    if (d % 2 == 0) {
        printf("%d\n", d / 2 + x[g] - d);
    } else {
        d--;
        printf("%d\n", d / 2 + x[g] - d + 1);
    }
    return 0;
}


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

int main()
{
    int n , i;
    string s;
    cin>>s;
    if(s[0]=='A' && s[1]=='A' &&s[2]=='A' ||  s[0]=='B' && s[1]=='B' &&s[2]=='B')
        cout << "No" << endl;
    else cout<<"Yes"<<endl;
}


Measured memory_bytes: 384
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        String s = scan.next();
        for(int i = 0; i < s.length(); i++){
            if(i % 2 == 0){
                if(s.charAt(i) != 'R' && s.charAt(i) != 'U' && s.charAt(i) != 'D'){
                    System.out.println("No");
                    return;
                }
            }else{
                if(s.charAt(i) != 'L' && s.charAt(i) != 'U' && s.charAt(i) != 'D'){
                    System.out.println("No");
                    return;
                }
            }
        }
        System.out.println("Yes");
        scan.close();
    }
}

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

using namespace std;

#define range(i, m, n) for(int i = m; i < n; i++)
#define husk(i, m, n) for(int i = m; i > n; i--)

string s;

int main() {
  cin >> s;
  int n = s.length();
  vector<int> a(n + 1), b(n + 1);
  range(i, 0, n) {
    if(s[i] == '<') a[i + 1] = a[i] + 1;
  }
  husk(i, n - 1, -1) {
    if(s[i] == '>') b[i] = b[i + 1] + 1;
  }
  long long res = 0;
  range(i, 0, n + 1) res += max(a[i], b[i]);
  cout << res;
  return 0;
}


Measured memory_bytes: 4740
#include <iostream>
#include <vector>
#include <vector>
#include <limits>
#include <algorithm>
using namespace std;

int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> c;
  for(int temp; cin >> temp; )
    c.push_back(temp);
  vector<int> ans;  //n=i??????????????????(????°?????????°)?????????????????¨
  sort(c.begin(), c.end());

  ans.push_back(0);  //ans[0]???0
  
  for(int i=1; i<=n; ++i){
    int minim=numeric_limits<int>::max();
    int j = 0;
    while (c[j] <= i && j<=m-1){
      if(minim >= ans[i-c[j]]+1)
	minim = ans[i-c[j]]+1;
      ++j;
    }
    ans.push_back(minim);
  }

  cout << ans[n] << '\n';
}

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

int main(){
  int x,y,z,minm=100000000,e;
  while(true){
    minm=1000000;
    cin>>e;
    if(e==0)break;
    for(z=0; z<=100; z++){
      for(y=0; y<=1000; y++){
	x = e-y*y-z*z*z;
	if(x>=0) minm = min(minm,x+y+z);
      }
    }
    cout<<minm<<endl;
  }
  return 0;
}



Measured memory_bytes: 3100
import java.util.*;
import java.io.*;

public class Main{
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    Long[] XAB = Arrays.stream(in.readLine().split(" ")).map(Long::parseLong).toArray(Long[]::new);
    long X = XAB[0];
    long A = XAB[1];
    long B = XAB[2];
    if(A>=B){
      System.out.println("delicious");
    }else if(B<=X+A){
      System.out.println("safe");
    }else{
      System.out.println("dangerous");
    }
  }
}


Measured memory_bytes: 28756
inf=float("inf")  


h,w=map(int,input().split())
s=[["#"]*(w+2) for i in range(h+2)]
for i in range(h):
    s[i+1]=["#"]+list(input())+["#"]

#h,w=3,5
#s=[['#', '#', '#', '#', '#', '#', '#'], ['#', '.', '.', '.', '#', '.', '#'], ['#', '.', '#', '.', '#', '.', '#'], ['#', '.', '#', '.', '.', '.', '#'], ['#', '#', '#', '#', '#', '#', '#']]    

nv=h*w
dp=[[inf]*nv for i in range(nv)] 

def nhw(hi,wi):
    return (hi-1)*w+wi-1

for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j]=="#":
            continue
        vij=nhw(i,j)
        if s[i-1][j]==".":
            vij2=nhw(i-1,j)
            dp[vij][vij2]=1
            dp[vij2][vij]=1
        if s[i+1][j]==".":
            vij2=nhw(i+1,j)
            dp[vij][vij2]=1
            dp[vij2][vij]=1
        if s[i][j-1]==".":
            vij2=nhw(i,j-1)
            dp[vij][vij2]=1
            dp[vij2][vij]=1
        if s[i][j+1]==".":
            vij2=nhw(i,j+1)
            dp[vij][vij2]=1
            dp[vij2][vij]=1
for i in range(nv):
    dp[i][i]=0
           
#print(dp)
for k in range(nv):
    for i in range(nv):
        for j in range(nv):
            dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j])
#    print(dp)
#print(dp)
dpmax=0
for i in range(nv):
    for j in range(nv):
        if dp[i][j]!=inf:
            if dpmax<dp[i][j]:
                dpmax=dp[i][j]
print(dpmax)


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

int main() {
    int n;
    cin >> n;
    int h[n][3];  // h:happy, 3:A or B or C
    rep(i, n) cin >> h[i][0] >> h[i][1] >> h[i][2];

    int dp[n][3] = {0};  // n 日目が A or B or C のときの最大値dp
    rep(i, 3) dp[0][i] = h[0][i];
    rep(i, n) {
        if (i == 0) continue;
        dp[i][0] = h[i][0] + max(dp[i - 1][1], dp[i - 1][2]);
        dp[i][1] = h[i][1] + max(dp[i - 1][0], dp[i - 1][2]);
        dp[i][2] = h[i][2] + max(dp[i - 1][0], dp[i - 1][1]);
    }

    int ans = max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String data = scan.next();
		long dis = Long.parseLong(data);
		int sq = (int) Math.sqrt(dis);
		outside: {
			
		    for (int i=sq; i >=1 ; i--) {
			    if (dis % i ==0) {
				    Long ans = i + dis/i -2;
				    System.out.println(ans);
				    break outside;
			    }
		    }
		}

	}

}


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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORd(i, a, b) for (int i = (a) ; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define sp system("pause")
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;

void TimeExecution() {
    cout << "\n\n===>> Time Execution: " << clock() / (double)1000 << " sec(s).";
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    /*
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    */
    ll n;
    cin >> n;
    cout << (n * (n - 1)) / 2;
    return 0;
}


Measured memory_bytes: 256
import std.stdio;
import std.string;
import std.conv;

void main() {
	int n;
	scanf("%d\n", &n);
	auto s = readln.chomp;
	auto cache = '\n';
	size_t cnt;
	foreach(c; s) {
		if (c != cache) {
			cache = c;
			++cnt;
		}
	}
	cnt.write;
}


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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    string s; cin >> s;
    int n = s.size();
    ll res = 0;
    for(int i = 0;i<(1<<(n-1));i++){
      ll num = s[0] - '0';
      rep(j,n-1){
        if(i & (1<<j)){ // +がはいる
          res += num;
          num = s[j+1]-'0';
        }
        else{
          num = num*10+s[j+1]-'0';
        }
      }
      res+=num;
    }
    out(res);
}


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

int main(){
    string S;
    int K;
    int ind = 0;
    cin >> S >> K;
    for(int i=0; i<S.length(); i++){
        if(S[i] - '0' != 1){
            ind = i;
            break;
        }
    }
    if(K <= ind){
        cout << 1 << endl;
    }else{
        cout << S[ind] << endl;
    }
}


Measured memory_bytes: 256
n = int(input())
S = [input() for _ in range(n)]

alp = 'abcdefghijklmnopqrstuvwxyz'
count = [float('inf') for _ in range(len(alp))]

for s in S:
    for i in range(len(alp)):
        count[i] = min(count[i], s.count(alp[i]))

ans = ''
for i in range(len(alp)):
    ans += alp[i] * count[i]
print(ans)

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

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;

template<class T> bool chmax(T &a, const T &b) { if(a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if(a > b) { a = b; return true; } return false; }

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N; cin >> N;
    string s; cin >> s;
    int nest = 0;
    string ans = "";
    REP(i, N)
    {
        if(s[i] == '(') nest++;
        else nest--;
        if(nest < 0) ans.pb('('), nest++;
    }
    ans += s;
    while(nest > 0) ans.pb(')'), nest--;
    cout << ans << endl;
}

Measured memory_bytes: 3596
# AOJ 1501: Grid
# Python3 2018.7.13 bal4u

from math import factorial
def comb (n, k):
	return factorial(n)//factorial(n-k)//factorial(k)
	
k = 0
r, c, a1, a2, b1, b2 = map(int, input().split())

dr = abs(a1-b1)
if dr > r-dr: dr = r-dr
if (dr << 1) == r: k += 1

dc = abs(a2-b2)
if dc > c-dc: dc = c-dc
if (dc << 1) == c: k += 1

print((comb(dr+dc, min(dr, dc)) << k) % 100000007)


Measured memory_bytes: 5668
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int N,M;
	cin>>N>>M;
	int sum=0;
	vector<int>A(M);
	for(int i=0; i<M; i++)
	{
		cin>>A[i];
	}
	for(int i=0; i<M; i++)
	{
	sum+=A[i];	
	}
	
	if(sum>N){
		cout<<-1;
	}
	else{
		cout<<N-sum;
	}
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  ll n;
  cin >> n;
  vector<ll> a(n), b(n+1, 0), c(n+1, 0);
  REP(i, n) cin >> a[i];
  ll p = 0, q = 0;
  REP(i, n){
    if(i%2 == 0){
      if(b[i]+a[i] > 0){
        b[i+1] = b[i]+a[i];
      }else{
        p += 1ll - (b[i]+a[i]);
        b[i+1] = 1;
      }

      if(c[i]+a[i] < 0){
        c[i+1] = c[i] + a[i];
      }else{
        q += c[i]+a[i]+1ll;
        c[i+1] = -1;
      }
    }else{
      if(b[i]+a[i] < 0){
        b[i+1] = b[i] + a[i];
      }else{
        p += b[i]+a[i]+1ll;
        b[i+1] = -1;
      }

      if(c[i]+a[i] > 0){
        c[i+1] = c[i] + a[i];
      }else{
        q += 1ll - (c[i]+a[i]);
        c[i+1] = 1;
      }
    }
  }
  cout << min(p, q) << endl;
  return 0;
}

Measured memory_bytes: 2560
import java.util.Scanner;
 
enum Type{
    SAME,
    A_BIG,
    B_BIG
};
 
public class Main {
 
    public static final int BIG_NUM  = 2000000000;
    public static final int MOD  = 1000000007;
 
    public static void main(String[] args) {
 
        Scanner scanner = new Scanner(System.in);
 
        int N = scanner.nextInt();
        String TARO,HANAKO;
        int score_TARO = 0,score_HANAKO = 0;
 
        for(int loop = 0; loop < N; loop++){
 
            TARO = scanner.next();
            HANAKO = scanner.next();
 
            switch(compString(TARO,HANAKO)){
            case SAME:
                score_TARO += 1;
                score_HANAKO += 1;
                break;
            case A_BIG:
                score_TARO += 3;
                break;
            case B_BIG:
                score_HANAKO += 3;
                break;
            }
        }
 
        System.out.printf("%d %d\n", score_TARO,score_HANAKO);
    }
 
    //A基準で比較する関数
    public static Type compString(String A,String B){
        int a_index = 0,b_index = 0;
 
        while(a_index < A.length() && b_index < B.length() && A.charAt(a_index) == B.charAt(b_index)){
            a_index++;
            b_index++;
        }
 
        if(a_index < A.length() && b_index < B.length()){
            if(A.charAt(a_index) > B.charAt(b_index)){
                return Type.A_BIG;
            }else{
                return Type.B_BIG;
            }
 
        }else if(a_index < A.length() && b_index == B.length()){
            return Type.A_BIG;
        }else if(a_index == A.length() && b_index < B.length()){
            return Type.B_BIG;
        }else{
            return Type.SAME;
        }
    }
}


Measured memory_bytes: 30432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i, x) for (long long i = 0; i < x; i++)
#define repn(i, x) for (long long i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
vector<pair<string, P> > vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(long long A, long long B, long long C) {
    if (A % 2 == 0 || B % 2 == 0 || C % 2 == 0) {
        cout << "0" << endl;
    } else {
        cout << min(A * B, min(B * C, C * A)) << endl;
    }
}

int main() {
    long long A;
    long long C;
    long long B;
    scanf("%lld", &A);
    scanf("%lld", &B);
    scanf("%lld", &C);
    solve(A, B, C);
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int[] x = new int[N+1];

    for (int i = 1; i < N+1; i++) {
      x[i] = sc.nextInt();
    }

    sc.close();

    int[] dp = new int[N+1];

    dp[0] = 0;
    dp[1] = 0;
    dp[2] = Math.abs(x[2] - x[1]);

    for (int i = 3; i < N+1; i++) {
      dp[i] = Math.min(dp[i-1] + Math.abs(x[i]-x[i-1]), dp[i-2] + Math.abs(x[i]-x[i-2]));
    }

    System.out.println(dp[N]);

  }

}

Measured memory_bytes: 49652
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1e9+100;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const bool debug = 0;
//------------------------------//

int H, W;
string maps[50];

bool check(int y, int x) {
	return y >= 0 && y < H && x >= 0 && x < W;
}

int count(int y, int x) {
	int res = 0;
	FOR(i, -1, 2) {
		FOR(j, -1, 2) {
			int nx = x + j, ny = y + i;
			if (!check(ny, nx)) continue;
			if (maps[ny][nx] == '#') res++;
		}
	}
	return res;
}

int main() {
	cin >> H >> W;
	REP(i, H) cin >> maps[i];
	
	REP(i, H) {
		string ans = "";
		REP(j, W) {
			if (maps[i][j] == '#') ans += '#';
			else ans += '0' + count(i, j);
		}
		cout << ans << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

typedef struct ppp{ll x,v;}P;

int hikaku(const void*p,const void*q){
	P pp=*(P*)p,qq=*(P*)q;
	if(pp.x<qq.x)return -1;
	return 1;
}

P d[100010];
ll l[100010],r[100010];
ll lM[100010],rM[100010];
int main(){
	ll n,c;
	scanf("%lld%lld",&n,&c);
	rep(i,0,n)scanf("%lld%lld",&(d[i].x),&(d[i].v));
	qsort(d,n,sizeof(P),hikaku);
	
	l[0]=0;
	rep(i,0,n)l[i+1]=l[i]+d[i].v-(i?d[i].x-d[i-1].x:d[i].x);
	lM[0]=0;
	rep(i,0,n)lM[i+1]=max(lM[i],l[i+1]);
	
	r[0]=0;
	rep(i,0,n)r[i+1]=r[i]+d[n-1-i].v-(i?d[n-1-(i-1)].x-d[n-1-i].x:c-d[n-1-i].x);
	rM[0]=0;
	rep(i,0,n)rM[i+1]=max(rM[i],r[i+1]);
	
//	rep(i,0,n)printf("%lld ",l[i]);puts("");
//	rep(i,0,n)printf("%lld ",r[i]);
	
	ll ans=0;
	//順周りから
	rep(i,1,n+1){
		ans=max(ans,l[i]);//ここでやめる
		ans=max(ans,l[i]-d[i-1].x+rM[n-i]);//逆周り開始
	}
	//逆周りから
	rep(i,1,n+1){
		ans=max(ans,r[i]);//ここでやめる
		ans=max(ans,r[i]-(c-d[(n-1)-(i-1)].x)+lM[n-i]);//逆周り開始
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4972
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#define pi acos((long double)-1.0)
#define N 220000
using namespace std;
int x,y,A,B;
int b[N],c[N];
int n,tot,f[N];
struct node{
	int x,y;
}a[N];
long double ans;
bool cmp(node x,node y){
	return x.x<y.x;
}
namespace seg{
	int t[N*4];
	int insert(int i,int l,int r,int x,int a){
		if(l==r)return t[i]=max(t[i],a);
		int mid=(l+r)/2;
		if(x<=mid)insert(i*2,l,mid,x,a);
		else insert(i*2+1,mid+1,r,x,a);
		t[i]=max(t[i*2],t[i*2+1]);
	}
	int query(int i,int l,int r,int x,int y){
		if(y<x)return 0;
		if(x<=l&&y>=r)return t[i];
		int ans=0,mid=(l+r)/2;
		if(x<=mid)ans=max(ans,query(i*2,l,mid,x,y));
		if(y>mid)ans=max(ans,query(i*2+1,mid+1,r,x,y));
		return ans;
	}
}
int main(){
	scanf("%d%d%d%d",&x,&y,&A,&B);
	if(x>A){
		swap(x,A);
		swap(y,B);
	}
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d%d",&a[i].x,&a[i].y);
	sort(a+1,a+1+n,cmp);
	int flag=y<=B;
	for(int i=1;i<=n;i++){
		if(a[i].x>=x&&a[i].x<=A){
			int o=a[i].y-y;
			if(flag){
				if(o>=0&&a[i].y<=B)b[++tot]=o;
			}else{
				if(o<=0&&a[i].y>=B)b[++tot]=-o;
			}
		}
	}
	for(int i=1;i<=tot;i++)c[i]=b[i];
	sort(c+1,c+1+tot);
	long double bns=0;
	for(int i=1;i<=tot;i++){
		b[i]=lower_bound(c+1,c+1+tot,b[i])-c;
		f[i]=seg::query(1,1,N,1,b[i]-1)+1;
		seg::insert(1,1,N,b[i],f[i]);
		bns=max(bns,(long double)f[i]);
	}
	ans=fabs(x-A)+fabs(y-B)-bns*2;
	ans*=100;
	if(bns==fabs(y-B)+1||bns==fabs(x-A)+1){
		bns--;
		ans+=(90+90+pi*10);
	}
	ans+=bns*(90+90+pi*5);
	printf("%.12Lf",ans);
}

Measured memory_bytes: 7680
#include<cstdio>

using namespace std;

int main()
{
	int a;
	int ans;
	while (1)
	{
		ans = 0;
		while (1)
		{
			a = getchar();

			if (a != '\n')
			{
				ans = ans + (a - '0');
			}
			else break;
		}
		if (ans == 0) break;
		else printf("%d\n", ans);
	}

	return 0;
}

Measured memory_bytes: 2716
#include<stdio.h>
#include<iostream>
#include"string"
#include"math.h"
#include <algorithm>
#include<vector>
using namespace std;
bool m;
void m_sort(int a[], int tmp[], int left, int right);
void m_sort(int a[], int tmp[], int left, int right);
void sort(int a[], int total) {
	int tmp;
	for (int i = 0; i < total; i++) {
		for (int j = i + 1; j < total; j++) {
			if (a[i] < a[j]) {
				tmp = a[i];
				a[i] = a[j];
				a[j] = tmp;
			}
		}
	}
 
}
 
void mergeSort(int a[], int tmp[], int size)
{
	m_sort(a, tmp, 0, size - 1);
}
void merge(int a[], int tmp[], int left, int mid, int right)
{
	int i, left_end, num_elements, tmp_pos;
 
	left_end = mid - 1;
	tmp_pos = left;
	num_elements = right - left + 1; // 要素 
 
	while ((left <= left_end) && (mid <= right))
	{
		if (a[left] <= a[mid])
		{
			tmp[tmp_pos] = a[left];
			tmp_pos = tmp_pos + 1;
			left = left + 1;
		}
		else
		{
			tmp[tmp_pos] = a[mid];
			tmp_pos = tmp_pos + 1;
			mid = mid + 1;
		}
	}
 
 
	while (left <= left_end)
	{
		tmp[tmp_pos] = a[left];
		left = left + 1;
		tmp_pos = tmp_pos + 1;
	}
 
	while (mid <= right)
	{
		tmp[tmp_pos] = a[mid];
		mid = mid + 1;
		tmp_pos = tmp_pos + 1;
	}
 
 
	for (i = 0; i <= num_elements; i++)
	{
		a[right] = tmp[right];
		right = right - 1;
	}
}
void m_sort(int a[], int tmp[], int left, int right)
{
	int mid;
 
	if (right > left)
	{
		mid = (right + left) / 2; 
		m_sort(a, tmp, left, mid);
		m_sort(a, tmp, mid + 1, right);
 
		merge(a, tmp, left, mid + 1, right);
	}
}

int abs(int a){
	if(a<0)return -a;
	return a;
}

int N,K,c[4][4],a[4],b[4];

int ans,C[501],S[501],F[501],ti[501],blank;
int main(){
	for(int i=1;i<4;i++){
		cin>>c[i][1];
		cin>>c[i][2];
		cin>>c[i][3];
	}
	a[1]=0;
	b[1]=c[1][1];
	b[2]=c[2][1];
	b[3]=c[3][1];
	a[2]=-b[1]+c[1][2];
	a[3]=-b[1]+c[1][3];
	for(int i=1;i<4;i++){
		for(int j=1;j<4;j++){
			if(c[i][j]!=b[i]+a[j]){
				cout<<"No"<<endl;
				return 0;
			}
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}


Measured memory_bytes: 256
MOD=10**9+7
cnt=0; sum=0; prev=nil; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n, m = gsmi
x = gsmi.sort

if n>=m
  putsend 0
end

# 点間の移動しない距離を最大化する
blank = []
(m-1).times do |i|
  blank << x[i+1]-x[i]
end

puts (x[-1]-x[0])-blank.max(n-1).inject(:+).to_i


Measured memory_bytes: 11896
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
int n, D[101000];
vector<int>E[101000];
void DFS(int a, int pp){
    int i;
    int g=0,h=0,tp=0;
    for(i=0;i<E[a].size();i++){
        int x = E[a][i];
        if(x==pp)continue;
        DFS(x, a);
        h |= g&D[x];
        g |= D[x];
    }
    while(h){
        tp=(h&-h);
        h^=tp;
    }
    if(!tp)tp=1;
    while(tp&g)tp<<=1;
    D[a] = (tp|g)/tp*tp;
}
int main(){
    int i, a, b;
    scanf("%d",&n);
    for(i=1;i<n;i++){
        scanf("%d%d",&a,&b);
        E[a].push_back(b);
        E[b].push_back(a);
    }
    DFS(1,0);
    for(i=30;i>=0;i--)if((1<<i)&D[1])break;
    printf("%d\n",i);
}

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

using namespace std;

int main(void){

char a;
char moji[4] = {'A', 'T', 'G', 'C'};

cin >> a;
if(a == moji[0])
   cout << moji[1] << endl;
if(a == moji[1])
    cout << moji[0]<< endl;
if(a == moji[2])
    cout << moji[3] << endl;
if(a == moji[3])
    cout << moji[2] << endl;

return 0;
}

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

using namespace std;

const int MAXN = 1e5 + 10;
int l[ MAXN ];
int n;
vector <int> memo(MAXN, -1);
int x;
int m;

int dp(int i){
    if(i == 0){
        return 0;
    }
    if(i == 1){
        return abs(l[0]-l[1]);
    }
    if(memo[i] != -1){
        return memo[i];
    }
    memo[i] = min(dp(i-2) + abs(l[i-2]-l[i]) , dp(i-1) + abs(l[i-1]-l[i])  );
    return memo[i];
}

int main (){
    cin >> n;

    for(int i=0;i<n;i++){
        cin >> l[i];
    }
    cout<<dp(n-1);
    return 0;
}


Measured memory_bytes: 5760
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
 
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)

typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD = 1000000007;
//ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
int X,A;
int main(){
	cin>>X>>A;
	if(X<A)cout<<0<<endl;
	else cout<<10<<endl;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int dp[100020][3];
int main() {
    //cout.precision(10);
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        int next[3];
        for(int j = 0; j < 3; j++){
            cin >> next[j];
            for(int k = 0; k < 3; k++){
                if(j == k) continue;
                dp[i][j] = max(dp[i][j], dp[i - 1][k] + next[j]);
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < 3; i++){
        ans = max(ans, dp[n][i]);
    }
    cout << ans << endl;
    return 0;
}


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

// N <= 50, K <= 100 とdequeのサイズと操作の回数が小さい
// 詰め込んでから、その部分をまた取り出すのは最適ではない
// よって、最初に取り出し作業して、後で詰め込む
// 「K回まで操作を行える」ことから、K回以内であればよい
// 取り出し作業をi(0 <= i <= min(N,K))回行って、
// 詰め込み作業を(K-i)(K - min(N, K) <= K - i <= K)回以内で行う
// 取り出す深度と取り出した総和に関しては、累積和を用いる
// 最後に詰め込む作業については、優先度付きキューで小さいやつから取り出していって、総和から引く

const int MAX_N = 60;
ll V[MAX_N]; // 1-indexed
ll left_acum[MAX_N], right_acum[MAX_N]; // 1-indexed
int N, K;

ll score(int pop_num, int left_pop) {
    ll sm = left_acum[left_pop] + right_acum[(N+1)-(pop_num - left_pop)];
    priority_queue<ll,vector<ll>,greater<ll>> que;
    for(int i = 0; i < left_pop; ++i) que.push(V[1 + i]);
    for(int i = 0; i < pop_num-left_pop; ++i) que.push(V[N-i]);
    for(int i = 0; i < K - pop_num && !que.empty(); ++i) {
        ll tmp = que.top(); que.pop();
        if(tmp < 0) sm -= tmp;
    }
    return sm;
}

ll high_score(int pop_num) {
    int left_pop = 0;
    ll sm = 0LL;
    for(int left_pop = 0; left_pop <= pop_num; ++left_pop) {
        sm = max(sm, score(pop_num, left_pop));
    }
    return sm;
}

int main()
{
    scanf("%d %d", &N, &K);
    for(int i = 1; i <= N; ++i){
        scanf("%lld", &V[i]);
        left_acum[i] = right_acum[i] = V[i];
    }
    for(int i = 1; i <= N; ++i) left_acum[i] += left_acum[i-1];
    for(int i = N; i >= 0; --i) right_acum[i] += right_acum[i+1];
    ll res = 0;
    for(int i = 0, i_len = min(N, K); i <= i_len; ++i) {
        res = max(res, high_score(i));
    }
    printf("%lld\n", res);
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
int main()
{
	ios_base :: sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	ll n, m, i, j;
	cin >> n;
	vector <db> p(n);
	for(i = 0; i < n; i++)
		cin >> p[i];
	vector <vector <db> > dp(n + 1);
	for(i = 0; i <= n; i++)
		dp[i].resize(i + 1);
	dp[1][0] = 1 - p[0], dp[1][1] = p[0];
	for(i = 2; i <= n; i++)
	{
		dp[i][0] = (1 - p[i - 1]) * dp[i - 1][0];
		for(ll j = 1; j < i; j++)
			dp[i][j] = p[i - 1] * dp[i - 1][j - 1] + (1 - p[i - 1]) * dp[i - 1][j];
		dp[i][i] = p[i - 1] * dp[i - 1][i - 1];
	}
	db ans = 0;
	for(i = n; i >= 0; i--)
		if(i > n - i)
			ans += dp[n][i];
	printf("%.12lf\n", ans);
	return 0;
}

Measured memory_bytes: 35584
#include <stdio.h>

int main(void)
{
  int n, h, w, a, b;
  int cnt = 0;

  scanf("%d %d %d", &n, &h, &w);
  for (int i=0; i<n; i++) {
    scanf("%d %d", &a, &b);
    if (a >= h && b >= w) cnt++;
  }
  printf("%d\n", cnt);
}

Measured memory_bytes: 128
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
#define fi first
#define se second
map<int,int> mp;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c*d/gcd(c,d);}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
set<ll> s;
int n;
cin>>n;
for(int i=0;i<n;i++){
    ll a;
    cin>>a;
  auto ite=s.find(a);
   if(ite==s.end())s.insert(a);
   else s.erase(a);
}
cout<<s.size()<<endl;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100001;
using ll = long long;

ll a[MAX_N];
ll b[MAX_N];


int main()
{
    ll N, d, e, f;
    e = 0;
    f = 0;
    cin >> N;
    for (int i = 0; i < N + 1; i++)
    {
        cin >> a[i];
    }
    for (int i = 0; i < N; i++)
    {
        cin >> b[i];
    }
    for (int i = 0; i < N; i++)
    {
        d = max(0LL, b[i] - a[i]);
        a[i + 1] -= d;
        if (a[i + 1] < 0)
        {
            e += a[i + 1];
            a[i + 1] = 0;
        }
    }
    for (int i = 0; i < N; i++)
    {
        f += b[i];
    }
    cout << f+e;
    //printf("%lld\n", f + e);
    return 0;
}



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

int main(){
  ll x,y;
  cin >> x >> y;
  ll now = x;
  ll res = 1;
  while(now * 2 <= y) {
    now *= 2;
    res++;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
# ifdef DEB
# define debug(...) fprintf(stderr, __VA_ARGS__)
# else
# define debug(...)
#endif
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define LL long long
#define LD long double
#define PII pair<int, int>
#define PLL pair<LL, LL>
#define pb pop_back
#define VI vector<int> 
#define VPI vector<PII> 
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define FORD(i,a,b) for(int i = (a); i >= (b); i--)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define ALL(x) (x).begin(), (x).end()
#define siz(V) ((int)V.size())

int n, t;
LL res;

int main()
{
  //ios_base::sync_with_stdio(0);
  int prev = 0;
  scanf("%d%d%d", &n, &t, &prev);
  for (int i = 1; i < n; i++)
  {
    int a;
    scanf("%d", &a);
    if (a - prev <= t)
    {
      res += a - prev;
    }
    else
    {
      res += t;
    }
    prev = a;
  }
  res += t;
  printf("%lld\n", res);
  return 0;
}

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

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


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    long long T1, T2;
    while(cin >> T1 >> T2){
        long long A1, A2, B1, B2;
        cin >> A1 >> A2 >> B1 >> B2;
        if(A1 < B1) swap(A1, B1), swap(A2, B2);
        if(T1*A1 + T2*A2 == T1*B1 + T2*B2){
            cout << "infinity" << endl;
            continue;
        }
        if(T1*A1 + T2*A2 > T1*B1 + T2*B2){
            cout << 0 << endl;
            continue;
        }
        long long dif = T1*(B1-A1) + T2*(B2-A2);
        long long difA = T1*(A1-B1);
        long long res = 1;
        res += 2 * ((difA-1)/dif);
        if(difA%dif == 0) res++;
        cout << res << endl;
    }
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

struct ford_fulkerson{
    static const int INF=1001001001;
    static const int MAX_V=1000;
    static const int SOURCE=MAX_V-2;
    static const int SINK=MAX_V-1;

    struct edge{
        int to,cap,rev;
        edge(int to,int cap,int rev):to(to),cap(cap),rev(rev){}
    };
    vector<edge>G[MAX_V];
    bool used[MAX_V];

    void add_edge(int from,int to,int cap){
        G[from].push_back(edge(to,cap,G[to].size()));
        G[to].push_back(edge(from,0,G[from].size()-1));
    }

    int dfs(int v,int t,int f){
        if(v==t)return f;
        used[v]=true;
        for(int i=0;i<G[v].size();i++){
            edge &e=G[v][i];
            if(!used[e.to]&&e.cap>0){
                int d=dfs(e.to,t,min(f,e.cap));
                if(d>0){
                    e.cap-=d;
                    G[e.to][e.rev].cap+=d;
                    return d;
                }
            }
        }
        return 0;
    }

    int max_flow(int s=SOURCE,int t=SINK){
        int flow=0;
        for(;;){
            memset(used,0,sizeof(used));
            int f=dfs(s,t,INF);
            if(f==0)return flow;
            flow+=f;
        }
    }
};

signed main(){
    ford_fulkerson ff;
    int V,E;
    cin>>V>>E;
    for(int i=0;i<E;i++){
        int a,b,c;
        cin>>a>>b>>c;
        ff.add_edge(a,b,c);
    }
    cout<<ff.max_flow(0,V-1)<<endl;
    return 0;
}

Measured memory_bytes: 3172
//luckYrat written
//Twitter: @luckYrat_


//all
//#include <bits/stdc++.h>

//def
#include <iostream>

//array
#include <vector>
#include <set>
#include <stack>
#include <map>

//
#include <cmath>
#include <algorithm>
#include <iomanip>

using namespace std;

typedef pair<int,int> Paint;

bool Pairsecond(const Paint& pf,Paint&ps){//sortCompare
  return pf.second < ps.second;
}

#define anyfill(n,s) setw(n) << setfill(s)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define pb push_back
#define MAX 1000000000
#define MOD 1000000007

/*
確認ポイント
cout<< (char)数値 //数値にあった文字に置き換えられる
cout<< (double)int型/(2など)//小数になる
length(),size()に括弧をつけ忘れてないか;
sort()が使える型//vector,string...
YesNo大文字小文字間違えてないか
cout << fixed << 小数計算//正しい小数表記になる(基本6桁)(e記法回避にも使える)
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
sqrt(数値型)でrootが取れる
vector.unique()は隣接した同じ要素を削除するので先にソートをする
*/
 
int main() { 
  int n;cin>>n;
  vector<int> a;
  vector<int> a2;
  for(int i = 0; n > i; i++){
    int tmp;cin>>tmp;
    a.pb(tmp);
    a2.pb(tmp);
  }
  sort(a.begin(),a.end());
  a.erase(std::unique(a.begin(), a.end()), a.end());
  if(a.size()==1 && a[0]==0){
    cout << "Yes" << endl;
    return 0;
  }
  if(a.size()==2){
    sort(a2.begin(),a2.end());
    bool change = false;
    int nwa = 1;
    int nwb = 0;
    for(int i = 1; n > i; i++){
      if(a2[i-1]!=a2[i])change=true;
      if(change)nwb++;
      else nwa++;
    }
    if(nwa*2==nwb){
      if(a[0]==0)cout << "Yes" << endl;
      else cout << "No" << endl;
    }else{
      cout << "No" << endl;
    }
    return 0;
  }
  if(a.size()!=3){
    cout << "No" << endl;
    return 0;
  }
  int aaa = 0;
  for(int i = 0; a.size() > i; i++){
    aaa= aaa^a[i];
  }
  if(aaa==0){
    sort(a2.begin(),a2.end());
    int change = 0;
    int a = 1;
    int b = 0;
    int c = 0;
    for(int i = 1; n > i; i++){
      if(a2[i-1]!=a2[i])change++;
      if(change ==0)a++;
      else if(change == 1)b++;
      else c++;
    }
    if(a==b&&b==c){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 1276