akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
class Main{
	static int BinarySearch(int[] data, int key){
		int result = -1;
		int r = data.length-1;
		int l = 0;
		while(result == -1 && l <= r){
			int middle = (l+r)/2;
			if(data[middle]<key){
			    l = middle + 1;
			}else if(data[middle] > key){
				r = middle - 1;
			}else{
				result = middle ;
			}
		}
		if (result>=0){
			return 1;
		}else{
			return 0;
		}
 
	}
	public static void main(String[] args){
		int count = 0;
		Scanner x=new Scanner(System.in);
	    int s1 = x.nextInt();
		int[] r1=new int[s1+1];
		for(int i=0;i<s1;i++){
		    r1[i]=x.nextInt();
		}
	    int s2 = x.nextInt();
		int[] r2=new int[s2];
		for(int j=0;j<s2;j++){
		    r2[j]=x.nextInt();
		}
		x.close();
		if(s1<s2){
		for(int i=0;i<s1;i++){
			if(BinarySearch(r1,r2[i])==1){
				count++;
			}
		}
		}else if(s1>s2){
			for(int j=0;j<s2;j++){
			    if(BinarySearch(r1,r2[j])==1){
				    count++;	
		       }
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 79724
/*

*/
#include<iostream>
#include<iomanip>
#include<ios>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)
#define MAX_N 10000

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

const int INF = 1<<30;
const ll MOD = ll(1e9+7);

int main(){
  int n;cin>>n;
  bool ans=true;
  rep(i, n){
    int a;cin>>a;
    if(a%2==0){
      if((a%3)*(a%5)!=0)ans=false;
    }
  }
  cout<<(ans?"APPROVED":"DENIED")<<endl;

  // system("read -n 1 -s -p \"Press any key to continue...\"");
}


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

#define PI 4*atan(1)
#define INF 1e8

typedef long long ll;

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

int main(){
  int H, W;
  cin >> H >> W;
  vector<string> a(H);
  for(int i = 0; i < H; i++)cin >> a[i];
  int cnt_a[26] = {0};
  for(auto s : a){
    for(auto ss : s){
      cnt_a[int(ss - 'a')]++; 
    }
  }
  vector<int> cnt_n;
  for(auto c : cnt_a)if(c)cnt_n.push_back(c);


  int cnt_4 = 0, cnt_2 = 0, cnt_1 = 0;
  int w = W / 2, h = H / 2;
  cnt_4 = w * h;
  // if(W % 2 == 1 && H % 2 == 1){
  //   if(W == 1 && H == 1)cnt_2 = 0;
  //   else cnt_2 = max(h, 1) * max(w, 1);
  // }
  if(W % 2 == 1 && H % 2 == 1) cnt_2 = h + w;
  else if(W % 2 == 1) cnt_2 = h;
  else if(H % 2 == 1)cnt_2 = w;

  cnt_1 = max(0, H * W - cnt_4 * 4 - cnt_2 * 2);
  // cout << cnt_4 << " " << cnt_2 << " " << cnt_1 << endl;
  sort(cnt_n.begin(), cnt_n.end(), greater<int>());

  // cout << "cnt_n" << endl;
  // for(auto n : cnt_n)cerr << n << endl;
  // cout << endl << "cnt_4: " << cnt_4 << " cnt_2: " << cnt_2 << " cnt_1: " << cnt_1 << endl;

  while(1){
    int n = cnt_n[0];
    // cout << "n: " << n << endl;
    if(cnt_4){
      if(n / 4 == 0){
        cout << "No" << endl;
        break;
      }else{
        cnt_4--;
        cnt_n[0]-=4;
      }
    }else if(cnt_2){
      if(n / 2 == 0){
        cout << "No" << endl;
        break;
      }else{
        cnt_2--;
        cnt_n[0]-=2;
      }
    }else if(cnt_1){
      if(n < 1){
        cout << "No" << endl;
        break;
      }else{
        cnt_1--;
        cnt_n[0]--;
      }
    }
    if(cnt_4 == 0 && cnt_2 == 0 && cnt_1 == 0 && n == 0){
      cout << "Yes" << endl;
      break;
    }

    sort(cnt_n.begin(), cnt_n.end(), greater<int>());
  }
}


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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main()
{
    string s;
    cin >> s;

    int n = s.size();
    string t1, t2;
    t1 = s.substr(0, (n - 1) / 2);
    t2 = s.substr((n + 1) / 2, (n - 1) / 2);
    string sr = s, t1r = t1, t2r = t2;
    reverse(ALL(sr)), reverse(ALL(t1r)), reverse(ALL(t2r));

    if (sr == s && t1r == t1 && t2r == t2)
        OP("Yes");
    else
        OP("No");

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#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++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    int n,k;cin>>n>>k;
    vll a(n);rep(i,n)cin>>a[i];
    vll tmp(n+1);
    bool ok;int res;
    rep(i,k){
        rep(j,n)tmp[j]=0;
        ok=true;
        rep(j,n){
            if(j-a[j]<0)tmp[0]++;
            else tmp[j-a[j]]++;
            if(j+a[j]+1>n)tmp[n]--;
            else tmp[j+a[j]+1]--;
        }
        a[0]=tmp[0];
        if(a[0]<n)ok=false;
        rep(j,n-1){
            a[j+1]=a[j]+tmp[j+1];
            if(ok&&a[j+1]<n)ok=false;
        }
        if(ok)break;
    }
    rep(i,n-1)cout<<a[i]<<" ";
    cout<<a[n-1]<<endl;
}

Measured memory_bytes: 6428
#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>
#define rep(i,n) for(int (i)=0;(i)<(int)(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 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 123456789
//0x3f3f3f3f
#define INFL 10000000000000000
using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
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;
typedef pair<int,pii> pdii;
long long int MOD = 1000000007;
int main(){
	int N;
	ll K;
	cin>>N>>K;
	vector<pair<int,ll> > data;
	for(int i=0;i<N;i++){
		int x;
		ll num;
		cin>>x>>num;
		data.pb(mp(x,num));
	}
	sort(data.begin(),data.end());
	int ans;
	for(int i=0;i<N;i++){
		ll sc=data[i].second;
		K=K-sc;
		if(K<=0){
			ans=data[i].first;
			break;
		}
	}
	cout<<ans<<endl;
	
	
}



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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, l, r)  (a).begin()+(l),(a).begin()+(r)


int main() {
	int n,m;
	cin >> n >> m;
	int mask[11] = {};
	FOR(i, 1, m) {
		int k;
		cin >> k;
		FOR(j, 1, k) {
			int s;
			cin >> s;
			mask[i] += (1 << (s - 1));
		}
	}
	int p[11] = {};
	FOR(i, 1, m) {
		cin >> p[i];
	}
	
	ll res = 0;

	ll validcnt = 0;
	for(int bit = 0; bit < (1 << n); bit++) {
		FOR(i, 1, m) {
			int temp = mask[i] & bit;
			int oncnt=0;
			while (temp > 0) {
				if (temp % 2 == 1) {
					oncnt++;
				}
				temp >>= 1;
			}
			if (oncnt % 2 == p[i]) {
				validcnt++;
			}
		}
		if (validcnt == m) {
			res++;
		}
		validcnt = 0;
	}

	pv(res)
	return(0);
}

Measured memory_bytes: 256
N, M = map(int, input().split())
P = []
S = []
T = [0 for i in range(N)]
U = [0 for i in range(N)]
ACs = 0
WAs = 0
for i in range(M):
  p, s = input().split()
  p = int(p)
  P.append(p)
  S.append(s)
for i in range(M):
  if S[i] == "AC":
    if U[P[i]-1] != 1:
      U[P[i]-1] += 1
      ACs += 1
      WAs += T[P[i]-1]
  else:
    T[P[i]-1] += 1
print(ACs, WAs)

Measured memory_bytes: 15384
from __future__ import print_function
import numpy as np
import sys
import math,string,itertools,fractions,heapq,collections,re,array,bisect,copy,functools
# from itertools import accumulate
# from collections import deque
import random

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

n = int(input())
if n==3 or n==5 or n==7:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 13704
<?php

fscanf(STDIN,"%d %d",$a,$b);

$alice = [ 'alice' => $a ];
$bob = ['bob' => $b ];

if( $alice['alice'] === $bob['bob'] ){
    echo 'Draw';
}elseif ($bob['bob'] == 1) {
    echo 'Bob';
} elseif ($alice['alice'] == 1 ) {
    echo 'Alice';
}elseif ($alice['alice'] < $bob['bob']) {
    echo 'Bob';
}elseif ($alice['alice'] > $bob['bob']) {
    echo 'Alice';
}

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

int main(void) {
    
    int n;
    cin >> n;
    int as[n];
    for(int i = 0; i < n; i++){
        cin >> as[i];
    }
    sort(as,as+n);
    cout << as[n-1] - as[0] << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int maxi(int a, int b, int c) {
    return max(a,max(b,c));
}
const int maks = 1000005;
int dp[maks][3];
int main() {
   int n; cin >> n;
   for(int i= 1; i <= n; i++) {
    cin >> dp[i][0] >> dp[i][1] >> dp[i][2];
    dp[i][0] += max(dp[i-1][1],dp[i-1][2]);
    dp[i][1] += max(dp[i-1][0],dp[i-1][2]);
    dp[i][2] += max(dp[i-1][1],dp[i-1][0]);
   }
   cout << maxi(dp[n][0],dp[n][1],dp[n][2]);
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    vector<tuple<string, int, int>> SP(N);

    for(int i=0; i<N; i++){
        string S;
        int P;
        cin >> S >> P;
        SP[i] = make_tuple( S, P*(-1), i+1 );
    }

    // sort(SP.begin(),SP.end(),[](pair<string, int> x,pair<string, int> y){return x.first < y.first;});
    sort(begin(SP),end(SP));

    for(int i=0; i<N; i++){
        cout << get<2>( SP[i] ) << endl;
    }

    return 0;
}


Measured memory_bytes: 256
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	if(a<0LL)return 0;
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
// ここから編集しろ

int main(){
	int a,b;scanf("%d%d",&a,&b);
	int ret=1;
	for(int i=1;i*i<=b;i++){
		if(b%i==0){
			if(a<=b/i)ret=max(ret,i);
			if(a<=i)ret=max(ret,b/i);
		}
	}
	printf("%d\n",ret);
}

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define int long long
#define double long long
using namespace std;
signed main() {
	bool X = false;
	vector<int>A(9);
	vector<bool>ans(9, false);
	for (int i = 0; i < 9; i++) {
		cin >> A[i];
	}
	int N;
	cin >> N;
	vector<int>b(N);
	for (int i = 0; i < N; i++) {
		cin >> b[i];
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 9; j++) {
			if (A[j] == b[i]) {
				ans[j] = true;
			}
		}
	}
	
		if (ans[0] == ans[1] && ans[2] == ans[0] && ans[0]==true) {
			X = true;
		}
		if (ans[3] == ans[4] && ans[4] == ans[5] && ans[3] == true) {
			X = true;
		}
		if (ans[6] == ans[7] && ans[7] == ans[8] && ans[6] == true) {
			X = true;
		}
		if (ans[0] == ans[3] && ans[3] == ans[6] && ans[6] == true) {
			X = true;
		}
		if (ans[1] == ans[4] && ans[4] == ans[7] && ans[7] == true) {
			X = true;
		}
		if (ans[2] == ans[5] && ans[2] == ans[8] && ans[8] == true) {
			X = true;
		}
		if (ans[0] == ans[4] && ans[4] == ans[8] && ans[8] == true) {
			X = true;
		}
		if (ans[2] == ans[4] && ans[4] == ans[6] && ans[6] == true) {
			X = true;
		}
		
	
	if (X == true) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int count(int H, int X, int a, int b, string s[]){
  int count = 0;
  for(int i = a; i < a+3; i++){
    if(i-1 >= 0 && i-1 <= H-1){
    	for(int j = b; j < b+3; j++){
      		if(j-1 >= 0 && j-1 <= X-1){
      			if(s[i-1].at(j-1) == '#')
        			count++;
            }
        }
    }
  }
  return count;
}

int main(){
  int H, X;
  cin >> H >> X;
  string S[H];
  for(int i = 0; i < H; i++)
    cin >> S[i];
  for(int i = 0; i < H; i++){
    for(int j=0; j < X; j++){
      if(S[i].at(j) == '#'){
        cout << "#";
      }else 
        cout << count(H, X, i, j, S);
    }
    cout << endl;
  }
}


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

using namespace std;
#define REPP(i,a,b,c) for(int i=a; i<=b; i+=c)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,c) for(int i=a; i>=b; i-=c)
#define REV(i,a,b) REVV(i,a,b,1)
#define FOR(i,a) REP(i,0,(int)a-1)
#define FORD(i,a) REV(i,(int)a-1,0)
#define PB push_back
#define POB pop_back
#define MP make_pair
#define FI first
#define SE second
typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef vector < int > vi;
typedef vector < pii > vii;
typedef vector < ll > vl;

const double EPS = 1e-9;
const double PI = acos(-1);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

ll addMod(ll a, ll b){
	return (a+b) % MOD;
}

ll mulMod(ll a, ll b){
	return (a*b) % MOD;
}

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

const int N = 1e5;

string str;
int flag[N + 5];
bool check(int idx){
	if(idx == 0) return 0;
	if(flag[idx+1] != -1) return flag[idx];
	if(str[idx-1] != str[idx+1]) return flag[idx] = 1;
	return flag[idx] = check(idx-1);
}

bool solve(){
	int ret = 0;
	REP(i,1,str.length()-2){
		if(check(i)){
			ret = str.length()-2;
			break;
		}
	}
	if(str[0] == str[(int)str.length()-1]) ret--;
	return ret % 2 == 1;
}

int main(){
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	memset(flag,-1,sizeof flag);
	cin >> str;
	if(solve()) cout << "First" << endl;
	else cout << "Second" << endl;
	return 0;
}

Measured memory_bytes: 896
def solve():
    n, k = list(map(int, input().split(" ")))
    A, B = [], []
    for _ in range(n):
        tmp_a, tmp_b = list(map(int, input().split(" ")))
        A.append(tmp_a)
        B.append(tmp_b)

    num = [0 for _ in range(10 ** 5 + 1)]
    for a, b in zip(A, B):
        num[a] += b

    summation = 0
    for i, ele in enumerate(num):
        summation += ele
        if summation >= k:
            print(i)
            break


solve()

Measured memory_bytes: 13840
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>

using namespace std;
typedef long long int LL;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int xcomp(vector<int>& a, vector<int>& b) {
	return a[0] < b[0];
}

int ycomp(vector<int>& a, vector<int>& b) {
	return a[1] < b[1];
}

int zcomp(vector<int>& a, vector<int>& b) {
	return a[2] < b[2];
}
#define XSORT(c) sort((c).begin(),(c).end(),xcomp)
#define YSORT(c) sort((c).begin(),(c).end(),ycomp)
#define ZSORT(c) sort((c).begin(),(c).end(),zcomp)

#define ALL(x) (x).begin(),(x).end()
	LL mod = 1000000007;
int main() {
	LL N, A, B;
	cin >> N>>A>>B;
	vector<LL> X(N);
	LL sum = 0;
	REP(i, N) {
		cin >> X[i];
		if (i >= 1) {
			sum += min(B, (X[i]-X[i-1])*A);
		}
	}
	cout << sum << endl;

}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;

signed main(){
  fastio
  int n,m,x;cin>>n>>m>>x;
  int cost[n];
  int a[n][m];
  for(int i=0;i<n;i++){
    cin>>cost[i];
    for(int j=0;j<m;j++)
      cin>>a[i][j];  
  }
  ll ans=1e18;
  for(int mask=0;mask<(1ll<<n);mask++){
    ll have[m]={0},_cost=0;
    for(int bit=0;bit<n;bit++){
      if(mask&(1ll<<bit)){
        _cost+=cost[bit];
        for(int i=0;i<m;i++){
          have[i]+=a[bit][i];
        }
      }
    }
    int fail=0;
    for(int i=0;i<m;i++){
      if(have[i]<x) fail=1;
    }
    if(!fail){
      ans=min(ans,_cost);
    }
  }
  if(ans==1e18) cout<<-1<<"\n";
  else          cout<<ans<<"\n";
  return 0;
}

Measured memory_bytes: 3656
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
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;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);
vector<ll> vectorprime(ll x){
    vector<bool> is_prime(x+1);
    vector<ll> prime;
    rep(i,x+1) is_prime[i]=true;
    is_prime[0]=is_prime[1]=false;
    for(ll i=2;i<=x;i++){
        if(is_prime[i]){
            prime.pb(i);
        }
        for(int j=i*2;j<=x;j+=i) is_prime[j]=false;
    }
    return prime;
}

int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    vector<ll> v=vectorprime(1000ll);
    ll X; cin>>X;
    while(1){
        bool c=true;
        rep(i,sz(v)){
            if(v[i]>=X) break;
            if(X%v[i]==0) c=false;
        }
        if(c) break;
        
        X++;
    }
    cout<<X<<endl;
}



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

using namespace std;
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define MAXN 201010
typedef long long int ll;
typedef pair<int, int> pii;
int n, m, l, r;
vector<pair<int, pii> > eve;
int main(){
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++)
	{
		scanf("%d %d", &l, &r);
		eve.pb({l, {1, i}});
		eve.pb({r, {0, i}});
	}
	sort(eve.begin(), eve.end());
	
	set<int> atv;
	int ans = 0;
	
	for (int i = 0; i < eve.size(); i++)
	{
		if(eve[i].S.F == 1){
			atv.insert(eve[i].S.S);
		}else{
			if(!atv.count(eve[i].S.S)) continue;
			ans++;
			atv.clear();
		}
	}
	printf("%d\n", ans);
	
	
	return 0;
}


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


int N;
vector<string> S;


void input() {
    cin >> N;
    S = vector<string>(N);
    rep(i, N) cin >> S[i];
}


int main() {
    input();
    map<string, int> w;
    rep(i, N) w[S[i]]++;
    vector<pair<int, string>> v;
    for (auto p : w) {
        v.push_back(make_pair(p.second, p.first));
    }
    sort(v.rbegin(), v.rend());
    int x = v[0].first;
    vector<string> ans;
    for (auto p : v) {
        if (p.first == x) ans.push_back(p.second);
    }
    sort(ans.begin(), ans.end());
    for (string s : ans) {
        cout << s << endl;
    }
}


Measured memory_bytes: 34416
#include <iostream>

using namespace std;

typedef long long ll;

int main () {
  ios::sync_with_stdio(false);
  
  int m;
  cin >> m;

  ll sumd = 0, len = 0;
  for (int i = 0; i < m; i++) {
    ll cnt, dg;
    cin >> dg >> cnt;
    sumd += cnt * dg;
    len += cnt;
  }

  ll ans = len - 1 + sumd / 9;
  if (sumd % 9 == 0) ans--;

  cout << ans << endl;
}


Measured memory_bytes: 3560
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < (n);i++)
#define lint long long
const lint mod=1e9+7;
const lint inf=2.19e15+1;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}

bool isok(int mid, vector<int> a, int k){
    int cnt = 0;   
    REP(i, a.size()){
        cnt += (a[i] + mid - 1) / mid;
    }
    return cnt <= k;
}

signed main(){
    int n, k;
    cin >> n >> k;
    vector<int>a(n);
    priority_queue<int> Q;
    REP(i, n){
        cin >> a[i];
        Q.push(a[i]);
    }
    int ok = 1000000000 + 1;
    int ng = 0;
    while (abs(ok - ng) > 1){
        int mid = (ok + ng) / 2;
        if (isok(mid, a, k + a.size())){
            ok = mid;
        }
        else{
            ng = mid;
        }
    }
    cout << ok << endl;
}

Measured memory_bytes: 5488
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    if (n==1 && m==1){
        cout << 1 << endl;
        return 0;
    }
    if (n==1){
        cout << m-2 << endl;
        return 0;
    }
    if (m==1){
        cout << n-2 << endl;
        return 0;
    }
    cout << (n-2) * (m-2);
    return 0;
}


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

int main(void) {
  string S;
  cin >> S;
  long long K;
  cin >> K;
  char ans;
  for (int i = 0; i < S.length() && i < K; i++) {
    ans = S[i];
    if (S[i] != '1') break;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main()
{
	int a;
	scanf("%d", &a);
	if (a<=15)
	{
		int b;
		b = a * 800;
		printf("%d", b);
	}
	if (a > 15)
	{
		int c;
		c = a * 800 - 200 * (a / 15);
		printf("%d", c);
	}
	system("pause");
	return 0;
}

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

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++)cin >> A[i];
    vector<ll> tmp(N-1);
    ll cnt = 0;
    ll total = 0;
    for (int i = N - 1; i > 0; i--) {
      cnt += A[i];
      //cout << "cnt"<<cnt<< endl;
      tmp[i - 1] = cnt % 1000000007;
    }
    for (int i = 0; i < N -1; i++) {
      //cout << "ai "<<A[i] << endl;
      //cout << "tmp " << tmp[i] << endl;
      total += ((A[i]%1000000007) *tmp[i])%1000000007;
      //cout << "total " << total << endl;
    }
    cout << total%1000000007<< endl;
    return 0;
}

Measured memory_bytes: 6424
import java.util.Scanner;

public class Main {
public static void main(String[]args) {
	Scanner tc = new Scanner (System.in);
	int k, cont=0, cont2=0;
	String S;
	S = tc.next();
	k = S.length();
	if(k>=1&& k<=15) {
	for (int i = 0; i<k; i++) {
		if (S.charAt(i) == 'x') {
			cont++;              
			} 
		if(S.charAt(i)== 'o') {
			cont2++;
		}
	}
	
	if(cont>=1&&cont<=7||cont2>=8) {
		System.out.println("YES");
	}else {
		System.out.println("NO");
	}
	}
}
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int i, o, j, l, trash;
  cin >> i >> o >> trash >> j >> l >> trash >> trash;
  
  long long ans1 = o, ans2 = o;
  o = 0;
  
  ans1 += i / 2 * 2;
  ans1 += j / 2 * 2;
  ans1 += l / 2 * 2;
  
  if (i > 0 && j > 0 && l > 0) {
    ans2 += 3;
    i--;
    j--;
    l--;
  }
  ans2 += i / 2 * 2;
  ans2 += j / 2 * 2;
  ans2 += l / 2 * 2;
  
  cout << max(ans1, ans2) << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#undef int
#define mk make_pair
#define pb push_back
typedef pair<int, int> pii;
const int mod = 1000000007;
const int INF = 1000000009;
const long long INFL = 1000000000000000018ll;

string s;

signed main()
{
    cin >> s;
    int N = s.size();
    if(s == "keyence"){
        printf("YES\n");
        return 0;
    }
    for(int l = 0; l < N; l++){
        for(int r = l; r < N; r++){
            string a;
            for(int i = 0; i < N; i++){
                if(i < l || r < i){
                    a = a + s[i];
                    //printf("a ");
                    //cout << a << endl;
                }
            }
            if(a == "keyence"){
                printf("YES\n");
                return 0;
            }
            //cout << a << endl;
        }
    }
    printf("NO\n");

    return 0;
}
/*



*/




Measured memory_bytes: 256
import java.util.Scanner;

//GCD and LCM
public class Main{

	public static long gcd(long a, long b){
		if(a < b){
			long tmp = a;
			a = b;
			b = tmp;
		}
		while(b!=0){
			long r = a%b;
			a = b;
			b = r;
		}
		return a;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int a = sc.nextInt();
			int b = sc.nextInt();
			long g = gcd(a, b);
			System.out.println(g+" "+a/g*b);
		}
	}
}

Measured memory_bytes: 12000
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
from collections import deque, defaultdict
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N = II()
    A = LI()
    counter = defaultdict(int)
    for a in A:
        counter[a] += 1
    # print(counter)

    odd = 0
    ans = N
    for key, val in counter.items():
        if val > 1:
            c = val - 1
            # print(val, c, c // 2)
            if c % 2 == 1:
                odd += 1
            ans -= (c // 2) * 2
    # print(ans, odd)
    ans = ans - (odd // 2) * 2 - (odd % 2) * 2
    print(ans)

            

    

if __name__ == '__main__':
    solve()



Measured memory_bytes: 22140
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    long long s;
    cin >> s;
    int x1, y1, x2, y2, x3, y3;
    x1 = y1 = 0;
    int v = 1e9;
    x2 = 1e9;
    y2 = 1;
    x3 = (v - s % v) % v;
    y3 = (s + x3) / v;
    printf("%d %d %d %d %d %d\n", x1, y1, x2, y2, x3, y3);
    return 0;
}

Measured memory_bytes: 3764
#include<map>
#include<set>
#include<unordered_map>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<list>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,n) n = unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;


struct edge
{
	long long to; long long len;
	bool operator<(const edge& rhs) const {
		return len > rhs.len;
	}
};

ll const MAX = 200005;
ll a[MAX], b[MAX];
ll n;

bool ok(ll mid) {
	unordered_map<ll, ll> mp;
	stack<ll> st;
	st.push(0);
	REP(i, 1, n) {
		ll cur = b[i];
		if (cur == -1) continue;
		while (st.top() > cur) {
			ll t = st.top();
			st.pop();
			mp[t] = 0;
		}
		if (st.top() < cur) {
			st.push(cur);
		}
		mp[cur]++;
		ll uuu = cur;
		while (mp[uuu] >= mid) {
			mp[uuu] = 0;
			uuu--;
			mp[uuu]++;
			if (uuu <= 0) {
				return false;
			}
		}
	}
	return true;
}

int main() {
	cin >> n;
	REP(i, 1, n) {
		cin >> a[i];
	}
	bool flag = 1;
	REP(i, 1, n - 1) {
		if (a[i] >= a[i + 1]) {
			flag = 0;
		}
	}
	if (flag) {
		cout << 1 << endl;
		return 0;
	}

	ll cur = 0;
	REP(i, 1, n) {
		if (cur >= a[i]) {
			b[i] = a[i];
		}
		else {
			b[i] = -1;
		}
		cur = a[i];
	}
	ll lb = 1; ll ub = 200005;
	while (ub > lb + 1) {
		ll mid = (ub + lb) / 2;
		if (ok(mid)) {
			ub = mid;
		}
		else {
			lb = mid;
		}
	}
	cout << ub << endl;
}




Measured memory_bytes: 13844
#include <iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<math.h>
#include <cstdio>
#include<iomanip>
#include <stdio.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,m,n) for(int i=m;i<(int)(n);i++)
const int inf = 10e9 + 7;
using namespace std;

signed main() {
	int n, k;
	cin >> n >> k;
	if ((n + 1) / 2 >= k)cout << "YES" << endl;
	else cout << "NO" << endl;
}

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

ans = 1
for a in A:
    if a == 0:
        print(0)
        exit()

for a in A:
    ans *= a
    if ans > 1000000000000000000:
        print(-1)
        exit()

print(ans)

    


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

// int func(int i, int j){

//   if (score > goal) {
//     if ( counter < currentmin ) currentmin = counter;
//     return true;
//   }

//   // i問目を0-p[j]-p[n]個のうち何問解くかで探索．
//   // p[j]->p[n]まで進んだらi+1
//   if ( j == p[i] ){
//     score = score + (i+1) * 100;
//     if (j == p[i]) score += c[i];
//     if ( func(i,j+1) ) return true;
//   }
  

  
// }

int main(){
  int n,d;
  int c[11];
  int p[11];
  cin >> n >> d;
  for (int i = 0; i < n; i++) cin >> p[i] >> c[i];

  // printf("goal score = %d\r\n",d);

  // bit全探査
  int score = 0;
  int goal = d;
  int counter = 0;
  int currentmin = 10000;
  bool flag = 0;
  int max = 0;
  for (int bit = 0; bit < (1 << n); bit++){
    // printf("now bit = %d\r\n",bit);
    score = 0;
    counter = 0;
    flag = 0;
    for ( int i = 0; i < n; i++){
      if ( bit & (1 << i) ) score += c[i] + p[i]*100*(i+1), counter += p[i];
    }
    // cout << score << endl;
    // printf("complete score = %d with counter %d\r\n",score,counter);
    if (score < goal){
      // cout << bit << endl;
      for (int i = n-1; i >= 0; i--){
        // cout << (bit & (1 << i)) << endl;
        if (!(bit & (1 << i))) {
          // cout << bit << endl;
          // printf("not using bit = %d\r\n",bit);
          max = p[i];
          while (1) {
            score += 100 * (i + 1);
            max --;
            counter ++;
            if(score >= goal) break;
            if (max == 0) {
              flag = 1;
              break;
            }
          }
        }
        if (score >= goal) break;
        if (flag == 1) break;
      }
    }
    // printf("counter = %d,score = %d in bit %d\r\n",counter,score,bit);
    // if (bit == 0) currentmin = counter;
    if ((counter < currentmin) && (flag == 0)) currentmin = counter;

  }
  cout << currentmin << endl;




  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

n_odd = sum(ai % 2 for ai in a)
n_even = (n - n_odd) + n_odd // 2

if n_even > 0:
    if n_odd % 2 == 0:
        ans = 'YES'
    else:
        ans = 'NO'
else:
    if n_odd % 2 == 0:
        ans = 'NO'
    else:
        ans = 'YES'
print(ans)


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

using namespace std;

typedef long long int lli;

lli employees[4001];
bool checked[4001];

signed main()
{
	lli n;
	while (cin >> n, n) {
		for (lli i = 1; i <= 4000; ++i) employees[i] = checked[i] = false;

		vector<lli> ans;

		for (lli i = 0; i < n; ++i) {
			lli num, a, b; cin >> num >> a >> b;

			if (checked[num]) continue;

			employees[num] += a * b;

			if (employees[num] >= 1000000) {
				ans.push_back(num);
				checked[num] = true;
			}
		}

		if (ans.empty()) cout << "NA" << endl;

		for (lli i = 0; i < ans.size(); ++i) {
			cout << ans[i] << endl;
		}
	}
}

Measured memory_bytes: 1268
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
const int MOD = 1000000007;

ll dp[1010][1010];

void _main()
{
    int H, W;
    cin >> H >> W;
    vector<string> a(H);
    rep(i, 0, H) cin >> a[i];

    dp[0][0] = 1;
    rep(i, 0, H) rep(j, 0, W)
    {
        if (a[i][j] == '#') continue;
        if (j - 1 >= 0) dp[i][j] = (dp[i][j] + dp[i][j - 1]) % MOD;
        if (i - 1 >= 0) dp[i][j] = (dp[i][j] + dp[i - 1][j]) % MOD;
    }
    cout << dp[H - 1][W - 1] << endl;
}


Measured memory_bytes: 9216
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        if (str.charAt(0) == 'A') {
            System.out.println('T');
            return;
        } else if (str.charAt(0) == 'T') {
            System.out.println('A');
            return;
        } else if (str.charAt(0) == 'C') {
            System.out.println('G');
            return;
        } else if (str.charAt(0) == 'G') {
            System.out.println('C');
            return;
        }
    }
}


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

using namespace std;
using ll=long long;

int main()
{
    int n,k;cin >>n >> k;
    int d[k];
    for(int i=0;i<k;i++){
        cin >>d[i];
    }
    for(int i=n;;i++){
        int l=i;
        bool flg=true;
        while(l>0){
            int s=l%10;
            for(int j=0;j<k;j++){
                if(s==d[j])flg=false;
            }
            l/=10;
        }
        if(flg){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}
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;
}
int main() {
    int N, M; cin >> N >> M;
    int left = 1;
    int right = N;
    rep(i, 0, M) {
        int a, b; cin >> a >> b;
        left = max(left, a);
        right = min(right, b);
    }
    cout << max(right - left + 1, 0) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    static final Scanner IN = new Scanner(System.in);
    static final int N = Integer.parseInt(IN.next());
    public static void main(String... args) {
        boolean flag = false;     
        for (int c = 0; c <= N; c += 4) {
            if ((N - c) % 7 == 0) {
                flag = true;
                break;
            }
        }
        System.out.println(flag ? "Yes" : "No");
    }
}

Measured memory_bytes: 22612
(N, W), *D = [list(map(int, o.split())) for o in open(0)]
w, v = 0, 1
dp = [[0]*-~W for _ in [0]*-~N]
for i in range(N):
  for j in range(W + 1):
    dp[i + 1][j] = max(dp[i][j], (dp[i][j - D[i][w]] + D[i][v])*(j >= D[i][w]))
print(dp[N][W])

Measured memory_bytes: 152616
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;
typedef long long ll;

template<typename T>
struct Seg{
private:
    vector<T> node;
    int n;
    function<T(T,T)> f;
    T def;

public:
    Seg(int siz, T d, function<T(T,T)> f) : def(d), f(f) {
        n = 1;
        while(n < siz)  n *= 2;
        node.resize(2*n-1, def);
    }
    Seg(vector<T> v, T d, function<T(T,T)> f) : def(d), f(f){
        n = 1;
        while(n < v.size())  n *= 2;
        node.resize(2*n-1);
        for(int i = 0; i < v.size(); i++)   node[n-1+i] = v[i];
        for(int i = n-2; i >= 0; i--)   node[i] = f(node[2*i+1], node[2*i+2]);
    }

    void update(int x, T val){
        x += n-1;
        node[x] += val; /* ! */
        while(x){
            x = (x-1)/2;
            node[x] = f(node[2*x+1], node[2*x+2]);
        }
    }

    T query(int a, int b, int k=0, int l=0, int r=-1){
        if(r < 0)   r = n;
        if(b <= l || r <= a)    return def;
        if(a <= l && r <= b)    return node[k];
        T lx = query(a, b, 2*k+1, l, (l+r)/2);
        T rx = query(a, b, 2*k+2, (l+r)/2, r);
        return f(lx, rx);
    }
};

int main(){
    int n, k;
    cin >> n >> k;
    vector<ll> v(n);
    for(int i = 0; i < n; i++)  cin >> v[i], v[i] -= k;
    for(int i = 1; i < n; i++)  v[i] += v[i-1];
    vector<ll> cp = v;
    cp.push_back(0);
    cp.push_back(-1ll<<60);
    cp.push_back(1ll<<60);
    sort(cp.begin(), cp.end());
    cp.erase(unique(cp.begin(),cp.end()),cp.end());
    auto f = [&](ll x)->int{
        return lower_bound(cp.begin(),cp.end(),x)-cp.begin();
    };
    int siz = cp.size();
    Seg<ll> seg(siz, 0, [](ll x, ll y){return x+y;});
    seg.update(f(0), 1);
    ll ret = 0;
    for(int i = 0; i < n; i++){
        ret += seg.query(0, f(v[i])+1);
        seg.update(f(v[i]), 1);
    }
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 6432
import java.util.HashMap;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        HashMap<String,Integer> hash = new HashMap<>();
        int n = sc.nextInt();
        for (int i=0;i<n;i++)hash.put(sc.next(),1);
        System.out.println(hash.size());
    }
}


Measured memory_bytes: 76568
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n;
  cin >> n;
  mat a(n,vec(n));
  for(ll i=0;i<n;i++) for(ll j=0;j<n;j++) cin >> a[i][j];
  ll f=0;
  for(ll k=0;k<n;k++) {
    for(ll i=0;i<n;i++) {
      for(ll j=0;j<n;j++) {
        if(a[i][j]>a[i][k]+a[k][j]) f=1;
      }
    }
  }
  if(f) {
    cout << -1 << endl;
    return 0;
  }

  ll ans=0;
  for(ll i=0;i<n;i++) for(ll j=0;j<n;j++) ans+=a[i][j];
  for(ll i=0;i<n;i++) {
    for(ll j=0;j<n;j++) {
      for(ll k=0;k<n;k++) {
        if(i==k||j==k) continue;
        if(a[i][j]==a[i][k]+a[k][j]) {
          ans-=a[i][j];
          break;
        }
      }
    }
  }
  cout << ans/2 << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main()
{
    long long int n, m, h, ans;
    scanf("%lld %lld", &n, &m);
    long long int sum=0;
    while (m--) {
        scanf("%lld", &h);
        sum+=h;
    }
    if (sum>n) ans=-1;
    else ans=n-sum;
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1732
# -*- coding: utf-8 -*-
"""
A - AtCoder Group Contest
https://atcoder.jp/contests/agc012/tasks/agc012_a

"""
import sys


def solve(N, array):
    array.sort(reverse=True)
    ans = 0
    for i in range(1, 2*N, 2):
        ans += array[i]
    return ans


def main(args):
    N = int(input())
    array = [int(a) for a in input().split()]
    ans = solve(N, array)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


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

using ll = long long;
const ll MOD = 1e9 + 7;

int main() {
    int H, W, A, B;
    cin >> H >> W >> A >> B;
    rep(i, H) {
        rep(j, W) {
            if ((i < B && j < A) || (i >= B && j >= A)) {
                cout << 1;
            } else {
                cout << 0;
            }
        }
        cout << endl;
    }
}

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vst = vector<st>;
using vchar = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007;

vll color;
void dfs(vvpll &graph, ll i, ll cur = 0){
  color[i] = cur;
  vrep(j, graph[i]){
    if(color[j.first] == -1){
      if(j.second % 2 == 0) dfs(graph, j.first, cur);
      else dfs(graph, j.first, 1 - cur);
    }
  }
}

int main(){
  ll n;
  cin >> n;
  vvpll graph(n);
  rep(i, 0, n - 1){
    ll u, v, w;
    cin >> u >> v >> w;
    graph[u - 1].push_back(make_pair(v - 1, w));
    graph[v - 1].push_back(make_pair(u - 1, w));
  }
  color.assign(n, -1);
  dfs(graph, 0);
  vrep(i, color) cout << i << endl;
}

Measured memory_bytes: 9984
#include <iostream>
#include <vector>

const int H = 3;
const int W = 3;
const int C_MAX = 100;

int main() {
	std::vector<std::vector<int>> c(H, std::vector<int>(W));
	for(int h = 0; h < H; h++) {
		for(int w = 0; w < W; w++) {
			std::cin >> c[h][w];
		}
	}

	bool result = false;

	for(int i = 0; i <= c[0][0]; i++) {
		std::vector<int> a(H);
		std::vector<int> b(W);
		a[0] = i;
		b[0] = c[0][0] - a[0];

		for(int h = 1; h < H; h++) {
			// 値は負でも構わない
			a[h] = c[h][0] - b[0];
		}
		for(int w = 1; w < W; w++) {
			b[w] = c[0][w] - a[0];
		}

		bool ok = true;
		for(int h = 1; h < H; h++) {
			for(int w = 1; w < W; w++) {
				if(c[h][w] != a[h] + b[w]) {
					ok = false;
					break;
				}
			}
			if(!ok) {
				break;
			}
		}
		if(ok) {
			result = true;
			break;
		}
	}

	std::cout << (result ? "Yes" : "No") << std::endl;

	return 0;
}

Measured memory_bytes: 256
import collections
while 1:
    n=int(input())
    if n==0:break
    words=[]
    words_match=[]
    count=0
    ans=[]
    for i in range(n):
        words+=list(map(str,input().split()))
    keyword=input()
    words.sort()
    for i in words:
        if keyword==i[0]:words_match.append(i)
    count_dict = collections.Counter(words_match)
    ans=count_dict.most_common(5)
    if ans==[]:
        print("NA")
    else:
        for i in range(len(ans)):
            if i>0:print(" ",end="")
            print(ans[i][0],end="")
        print()


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

#define zton(i,n) for(int i=0;i<=n;i++)
#define oneton(i,n) for(int i=1;i<=n;i++)
#define fo(i,n) for(int i=0;i<n;i++)
#define fab(i,a,b) for(int i=a;i<b;i++)
#define loop(i,b,a) for(int i=a;i>=b;i--)
#define dsort(arr,n) sort(arr, arr + n, greater<int>())
#define vsortd(a) sort(a.begin(), a.end(), greater<double>())
#define vsort(a) sort(a.begin(), a.end())
#define ll long long int
#define test int tc;cin>>tc;while(tc--)
#define dbg(x) cout<<#x<<'='<<(x)<<endl;
#define dbg2(x,y) cout<<#x<<'='<<(x)<<endl<<#y<<'='<<(y)<<endl;
#define dbg3(x,y,z) cout<<#x<<'='<<(x)<<endl<<#y<<'='<<(y)<<endl<<#z<<"="<<(z)<<endl;
#define dbg4(x,y,z,w) cout<<#x<<'='<<(x)<<endl<<#y<<'='<<(y)<<endl<<#z<<"="<<(z)<<endl<<#w<<"="<<(w);
#define minheap priority_queue <int, vector<int>, greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define ff first
#define ss second
#define mpr make_pair
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define mkv vector<int>
#define allzero(dp) memset(dp,0,sizeof(dp))
#define endl "\n"
#define print(x) cout<<x<<endl;

const int mod=1e9+7;
using namespace std;
bool sortcol( const vector<int>& v1,const vector<int>& v2 ) {return v1[1] < v2[1];}

void fastio()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

bool sortbysecdesc(const pair<ll,ll> &a,const pair<ll,ll> &b){
    if(a.first>b.first)return true;
    if(a.first==b.first)return a.second<b.second;
    return false;
}

ll power(ll x, ll y){
    ll res = 1;x=x%mod;
    while(y>0){
        if(y&1)res=(res*x)%mod;
        y=y>>1;x=(x*x)%mod;}
    return res;
}


void solve()
{
    ll N;cin>>N;
    ll cnt=0;
    ll dp[N+1]={0};
    for(ll x=1;x<=N;x++)
    {
        for(ll y=1;y<=N;y++)
        {
            for(ll z=1;z<=N;z++)
            {
                ll n=x*x+y*y+z*z+x*y+y*z+z*x;
                if(n>N)
                    break;
                else
                    dp[n]++;
            }
        }
    }
    for(int i=1;i<=N;i++)print(dp[i])
}

int main()
{
   // fastio();
  //  test
    solve();
}


Measured memory_bytes: 3644