akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long L;
using namespace std;
 
#define N 100005
#define U [N]={}
map<L,L> path[N];
L par U,dep U,siz U,hev U,cst U,add U,pos U,hl_par U,bit U,
k,n,q,a,b,c,i,p,r;
char s[5];
void dfs(L a){
    siz[a]=1;
    for(map<L,L>::iterator I=path[a].begin();I!=path[a].end();I++){
        L d=I->first;
        if(d==par[a]) continue;
        par[d]=a;
        dep[d]=dep[a]+1;
        cst[d]=I->second;
        dfs(d);
        siz[a]+=siz[d];
        if(!hev[a] || siz[hev[a]]<siz[d])
            hev[a]=d;
    }
}
   
L edgecost(L a){
    L ret=add[a]+add[par[a]]+cst[a];
    return ret%k ? ret : 0;
}
   
L sum(L i){
    L ret=0;
    while(i){
        ret+=bit[i];
        i-=i&-i;
    }
    return ret;
}
void S(L i, L x){
    x=edgecost(x)-sum(i+1)+sum(i);
    i++;
    while(i<N){
        bit[i]+=x;
        i+=i&-i;
    }
}
 
main(){
    cin >> n >> k;
    for(i=0; i<n-1; i++){
        cin >> a >> b >> c;
        path[a][b]=path[b][a]=c;
    }
    dfs(0);
   
    for(c=i=0; i<n; i++){
        if(i && hev[par[i]]==i) continue;
        L j=i;
        do{
            pos[j]=c++;
            hl_par[j]=i;
        }while(j=hev[j]);
    }
    
    for(i=0; i<n; i++)
        S(pos[i],hev[i]);
    
    cin >> q;
    for(i=0; i<q; i++){
        cin>>s>>a>>b;
        if(*s&2){
            for(c=0;p=hl_par[a],r=hl_par[b],p-r;a=par[p])
                dep[p]<dep[r]?swap(p,r),swap(a,b),0:0,
                c+=sum(pos[a])-sum(pos[p])+edgecost(p);
            cout<<c+abs(sum(pos[a])-sum(pos[b]))<<endl;
        }else{
            add[a]+=b;
            S(pos[a],hev[a]);
            if(a)S(pos[a]-1,a);
        }
    }
}

Measured memory_bytes: 31992
import std.algorithm;
import std.range;
import std.ascii;
import std.array;
import std.container;
import std.conv;
import std.numeric;
import std.stdio;
import std.string;
import std.typecons;

void log(A...)(A arg) {
    stderr.writeln(arg);
}
int size(T)(in T s) {
    return cast(int)s.length;
}

long modPow(long mod)(long x, long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) return modPow!mod(x * x % mod, n / 2);
    return x * modPow!mod(x % mod, n - 1) % mod;
}

long extgcd(long a, long b, ref long x, ref long y) {
    long g = a; x = 1; y = 0;
    if (b != 0) {
        g = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    }
    return g;
}
long inverse(long mod)(long v) {
    long x, y;
    if (extgcd(v, mod, x, y) == 1) return (x + mod) % mod;
    return 0;
}

class RollingHash(long[] Ps, long mod) {
    string s;
    int N;
    long[][] H;
    this(in string s) { 
        this.s = s; 
        this.N = s.size;
        this.H = new long[][](Ps.length, N + 1);
        foreach (k, P; Ps) {
            long x = 1;
            foreach (int i, c; s) {
                H[k][i + 1] = (H[k][i] + x * cast(int)(c - 'a' + 1)) % mod;
                x = (x * P) % mod;
            }
        }
    }
    long[] hash(int l, int r) { // [l, r)
        auto hs = iota(0, Ps.length, 1).map!(delegate(k) {
                      long h = (H[k][r] - H[k][l] + mod) % mod;
                      return h * modPow!mod(inverse!mod(Ps[k]), l) % mod;
                  });
        return hs.array;
    }
}

void main() {
    int N, M; scanf("%d %d\n", &N, &M);
    auto s = readln.chomp;
    auto hasher = new RollingHash!([991, 9999991], cast(long)(1e9+7))(s);
    int l = 0, r = 1;
    bool[long[]] appeared;
    foreach (_; 0 .. M) {
        auto q = readln.chomp;
        switch (q) {
            case "L++": l++; break;
            case "L--": l--; break;
            case "R++": r++; break;
            case "R--": r--; break;
            default: assert(false);
        }
        appeared[hasher.hash(l, r).idup] = true;
    }
    writeln(appeared.keys.size);
}

Measured memory_bytes: 62476
N,M = map(int, input().split())
*A, = map(int, input().split())
vote_sum = sum(A)

sum = 0

for n in range(N):
    a = A[n]

    if (vote_sum*(1/(4*M)))>a:
        continue
    sum = sum + 1

print("Yes" if M<=sum else "No")


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<P>> Graph;


int main(){

  int a,b;
  cin >> a >> b;
  
  if(a-b <0) cout << 0 << endl;
  else cout << a-b << endl;

 return 0;
}

Measured memory_bytes: 256
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    int x, y;
    cin >> x >> y;
    set<int> a{1, 3, 5, 7, 8, 10, 12}, b{4, 6, 9, 11}, c{2};
    vector<set<int>> n{a, b, c};

    bool ok = false;
    for (auto e : n) {
        if (e.count(x) == 1) {
            if (e.count(y) == 1) {
                cout << "Yes" << endl;
                ok = true;
            }
        }
    }
    if (!ok) {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
long long a, b, c, x, y, count = 1000000000000;
int main(){
    cin >> a >> b >> c >> x >> y;

    for(int i=0;i<=2*max(x,y);i++) {
        int ma = (x-i/2)*a>0?(x-i/2)*a:0;
        int mb = (y-i/2)*b>0?(y-i/2)*b:0;
        count = min(count, c*i+ma+mb);
    }
    cout << count << endl;
    return 0;
}

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

int G[110][110] = {};
int mini[110];
int used[110];

void dijkstra(int n)
{
    //init
    for(int i = 0;i < n;i++){
        mini[i] = INF;
        used[i] = 0;
    }
    mini[0] = 0;

    while(true)
    {
        int v = -1;
        for(int i = 0;i < n;i++){
            if(!used[i] && (v == -1 || mini[i] < mini[v])) v = i;
        }
        if(v == -1) break;
        used[v] = 1;

        for(int i = 0;i < n;i++){
            mini[i] = min(mini[i], mini[v]+G[v][i]);
        }
    }
}

int main()
{
    int n;
    int u, k, v, c;

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

    for(int i = 0;i < n;i++){
        cin >> u >> k;
        for(int j = 0;j < k;j++){
            cin >> v >> c;
            G[u][v] = c; //uiとviをつなぐコストがci
        }
    }
    dijkstra(n);
    
    for(int i = 0;i < n;i++) printf("%d %d\n", i, mini[i]);
    
    return 0;
}


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

#define MAX 1000000

ll L;
vector<ll> A;
ll dp[MAX][5];
ll len;
ll ret = 10000000000000;

void input(){
    cin >> L;
    ll temp;
    for(ll i=0;i<L;i++){
        cin >> temp;
        A.push_back(temp);
    }
    len = L;
}

ll min(ll a, ll b){
    return (a<b)?a:b;
}

void solve(){
    for(ll i=0;i<len;i++){
        for(ll j=0;j<5;j++){
            dp[i][j] = -1;
        }
    }
    for(ll i=0;i<L+1;i++){
        ll a = A[i];
        if(i==0){
            dp[i][0] = a;
            dp[i][1] = a%2;
            dp[i][2] = (a%2==0)?1:0;
            dp[i][3] = a%2;
            dp[i][4] = a;
        }else{
            dp[i][0] = dp[(i-1)][0] + a;
            dp[i][1] = min(dp[(i-1)][1], dp[(i-1)][0]) + a%2 + ((a==0)*2);
            dp[i][2] = min(dp[(i-1)][2], min(dp[(i-1)][1], dp[(i-1)][0])) + (1-(a%2));
            dp[i][3] = min(dp[(i-1)][3], min(dp[(i-1)][2], min(dp[(i-1)][1], dp[(i-1)][0]))) + a%2 + ((a==0)*2);
            dp[i][4] = min(dp[(i-1)][4], min(dp[(i-1)][3], min(dp[(i-1)][2], min(dp[(i-1)][1], dp[(i-1)][0])))) + a;
        }
    }
    
    for(ll j=0;j<5;j++){
        if(ret > dp[(len-1)][j]){
            ret = dp[(len-1)][j];
        }
    }
}

int main(void){
    // Your code here!
    input();
    solve();
    
    // for(ll i=0;i<len;i++){
    //     for(ll j=0;j<5;j++){
    //         cout << dp[i][j];
    //     }
    //     cout << endl;
    // }
    
    cout << ret << endl;
}


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

using namespace std;

int main(int argc, char const *argv[])
{
    int N;
    cin >> N;
    int tmp;
    vector<int> H;
    for (int i = 0; i < N; i++)
    {
        cin >> tmp;
        H.emplace_back(tmp);
    }

    int sum = 0;
    int max = 0;
    for (int i = 1; i < N; i++)
    {
        if (H[i] > H[i - 1])
        {
            if (sum > max) max = sum;
            sum = 0;
        }else
        {
            sum += 1;
        }
        
    }

    if (sum > max) max = sum;
    
    cout << max << endl;
    
    return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n,k,r,s,p,ans=0;
    cin>>n>>k>>r>>s>>p;
    string t,f="";
    cin>>t;
    for(int i=0;i<k;i++){
        int num=1,j=i;;
        for(j=i;j<n-k;j+=k){
            if(t[j]==t[j+k]) num++;
            else {
                if(t[j]=='p'){
                    ans+=s*((num+1)/2);
                }
                if(t[j]=='s'){
                    ans+=r*((num+1)/2);
                }
                if(t[j]=='r'){
                    ans+=p*((num+1)/2);
                }
                num=1;
            }
        }
        if(t[j]=='p'){
            ans+=s*((num+1)/2);
        }
        if(t[j]=='s'){
            ans+=r*((num+1)/2);
        }
        if(t[j]=='r'){
            ans+=p*((num+1)/2);
        }
    }
    cout<<ans<<endl;
}

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

#define int long long
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define ps(x, y) fixed << setprecision(y) << x
#define rep(i, begin, end) for (int i = begin; i < end; i++)
#define all(p) p.begin(), p.end()
#define sz(x) (int)x.size()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int mod = (int)(1e9 + 7);
const int inf = (int)(1e18);
void run()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
void solution()
{
    int a[2], b[2];
    cin >> a[0] >> a[1] >> b[0] >> b[1];
    int ans = -inf;
    rep(i, 0, 2)
    {
        rep(j, 0, 2)
        {
            ans = max(ans, a[i] * b[j]);
        }
    }
    cout << ans << endl;
    return;
}
int32_t main()
{
    run();
    int t;
    t = 1;
    while (t--)
    {
        solution();
    }
    return 0;
}

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

using namespace std;

typedef long long LL;
#define N 12

const LL mod=998244353;
LL n,m,p,ans,a[N][N],f[N][N][3],g[N][N][3],row[N],col[N],C[N][N];
char s[N];

void upd(LL &x,LL y){x=(x+y)%mod;}

bool pd(LL i,LL j){
	if (i==0||j==0) return 1;
	for (LL k=0;k<n;++k)
		if ((i>>k&1)&&((row[k]&j)==j||(row[k]&j)==0)) return 0;
	for (LL k=0;k<m;++k)
		if ((j>>k&1)&&((col[k]&i)==i||(col[k]&i)==0)) return 0;
	return 1;
}

LL pw(LL x,LL k){
	return x==1?1:1<<k;
}

int main(){
	scanf("%lld%lld",&n,&m);
	for (LL i=1;i<=n;++i){
		scanf("%s",s+1);
		for (LL j=1;j<=m;++j) a[i-1][j-1]=s[j]=='.';
	}
	for (LL i=0;i<n;++i){
		for (LL j=0;j<m;++j) row[i]|=a[i][j]<<j;
	}
	for (LL i=0;i<m;++i){
		for (LL j=0;j<n;++j) col[i]|=a[j][i]<<j;
	}
	p=max(n,m);
	for (LL i=0;i<=p;++i){
		C[i][0]=1;
		for (LL j=1;j<=i;++j) C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
	}
	for (LL i=n;i;--i)
		f[i][m][2]=1<<(n-i);
	f[0][m][0]=1<<n;
	for (LL i=n;i;--i)
		for (LL j=m;j;--j){
			for (LL k=1;k<j;++k){
				upd(g[i][j-k][2],f[i][j][2]*((1<<k)-2)%mod*C[m-j+k][k]);
				upd(g[i][j-k][1],(f[i][j][2]*2+f[i][j][1])%mod*C[m-j+k][k]);
			}
			upd(g[i][0][0],f[i][j][2]*((1<<j)-2)%mod*C[m][j]);
			for (LL k=1;k<i;++k){
				upd(f[i-k][j][2],g[i][j][2]*((1<<k)-2)%mod*C[n-i+k][k]);
				upd(f[i-k][j][1],(g[i][j][2]*2+g[i][j][1])%mod*C[n-i+k][k]);
			}
			upd(f[0][j][0],g[i][j][2]*((1<<i)-2)%mod*C[n][i]);
		}			
	for (LL i=0;i<1<<n;++i)
		for (LL j=0;j<1<<m;++j){
			LL ii=0,jj=0;
			for (LL k=0;k<n;++k) ii+=i>>k&1;
			for (LL k=0;k<m;++k) jj+=j>>k&1;
			if (pd(i,j))
				for (LL k=0;k<=2;++k) upd(ans,f[ii][jj][k]+g[ii][jj][k]);
		}
	printf("%lld\n",(ans+mod)%mod);
	
	return 0;
}
			

Measured memory_bytes: 256
n,k=map(int,input().split())
 
 
h=list(int(input()) for _ in range(n))
h.sort()
result=10**9
 
i=0
while i+k-1<n:
  result=min(result,h[i+k-1]-h[i])
  
  i+=1
  
print(result)
    

Measured memory_bytes: 51288
N=int(input())
S=input()
ans=0
for i in range(1000):
    t=str(i).zfill(3)
    a=S.find(t[0])
    b=S.find(t[1],a+1)
    c=S.find(t[2],b+1)
    if a!=-1 and b!=-1 and c!=-1:
        ans+=1
print(ans)

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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define rep(i,n) for(ll i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(ll i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(ll i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;

const ll inf = 1ll<<62;
const ll mod = 1e9+7;

int main(){
  string s; cin >> s;
  int w; cin >> w;
  int i = 0;
  while(i < sz(s)){
    cout << s[i];
    i += w;
  }
  cout << endl;
  return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  int a, b, k; cin >> a >> b >> k;
  int count = 1;
  for(int i = 0; i < k; i++) {
    if(i % 2 == 0) {
      if(a % 2 == 0) {
      } else {
        a = a-1;
      }
      a = a / 2;
      b += a;
    } else {
      if(b % 2 == 1) {
        b -= 1;
      }
      b = b / 2;
      a += b;
    }
  }
  cout << a << " " << b << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
int n;
string s;

void solve() {
	cin >> n;
	cin >> s;
	string front_s, back_s;
	int split = 1;
	int ans = 0;
	int cnt = 0;
	while (split < n) {
		front_s = s.substr(0, split);
		back_s = s.substr(split, n - split);
		set<char> sp_s;
		split++;
		for (int i = 0; i < front_s.length(); ++i) {
			for (int j = 0; j < back_s.length(); ++j) {
				if (front_s[i] == back_s[j]) {
					sp_s.insert(front_s[i]);
				}
			}
		}
		cnt = sp_s.size();
		ans = max(ans, cnt);
	}
	cout << ans << endl;
	return;
}

int main(int args, char* argv[]) {
	solve();
}

Measured memory_bytes: 256
S=list(map(int,list(input())))
N=len(S)

m=[0]*2019
m[0]=1
ans=0

sm=0
d=1
for i in range(N):
    sm=(sm+S[N-1-i]*d)%2019
    m[sm] += 1
    d=(d*10)%2019

for i in m:
    ans += i*(i-1)//2

print(ans)


Measured memory_bytes: 12024
#include <iostream>
#include <algorithm>
using namespace std;
long long a[100010],sum = 0;
int main(){
	int i,j,n;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> a[i];
		sum ^= a[i];
	}
	for(i=0;i<=60;i++){
		long long x = (1LL<<i);
		if(sum & x){
			for(j=0;j<n;j++){
				if(a[j]&x) a[j] ^= x;
			}
		}
	}
	int k = 0;
	for(i=60;i>=0;i--){
		int p = -1;
		long long x = (1LL<<i);
		for(j=k;j<n;j++){
			if(a[j] & x){
				p = j;
				break;
			}
		}
		if(p==-1) continue;
		swap(a[k],a[p]);
		for(j=k + 1;j<n;j++){
			if(a[j] & x) a[j] ^= a[k];
		}
		k++;
	}
	long long ans = 0;
	for(i=0;i<n;i++){
		if(ans<(ans^a[i])) ans ^= a[i];
	}
	ans *= 2;
	cout << ans + sum << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		
		long []a = new long [n+1];
		long node = 0L;
		
		for(int i = 0 ; i <= n ;i++) {
			a[i] = Long.parseLong(sc.next());
			node += a[i];
		}
		
		
		long []b = new long[n+1];
		b[0] = 1L;
		long sum = 1L;
		
		for(int i = 0 ; i < n ;i++) {
			if(b[i] <= a[i]) {
				System.out.println(-1);
				return;
			}			
			node -= a[i];
			b[i+1] = Math.min(node, (b[i] - a[i])*2L);
			sum += b[i+1];
		}
		if(b[n] < a[n]) {
			System.out.println(-1);
			return;
		}
		System.out.println(sum);
		
	}
}


Measured memory_bytes: 60244
import java.io.*
import java.util.*
import java.lang.*
import java.lang.Math.*


fun solve() {
    val S = rd.readString()
    val N = S.length

    val ms = mutableSetOf<Char>()
    ms.addAll(S.toList())
    if (N < 26) {
        for (nc in 'a' .. 'z') {
            if (ms.contains(nc)) continue
            else {
                println(S+nc)
                return
            }
        }
    }
    
    for (i in N-1 downTo 0) {
        ms.remove(S[i])

        for (nc in S[i] + 1 .. 'z') {
            if (ms.contains(nc)) continue
            else {
                println(S.slice(0 until i) + nc)
                return
            }
        }
    }
    
    println(-1)
}


//val rd = debug.Reader("agc", "022", "a", "sample-1")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!! }
    catch (e: Exception) { throw e }
    finally { rd.close() }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
data class IntPair(val first: Int, val second: Int)
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
    val readListIntCol: (Int) -> List<Int> = { N -> (0 until N).map { readInt() } }
    val readListIntCols: (Int) -> List<List<Int>> = { N -> (0 until N).map { br.readLine().split(' ').map { it.toInt() } } }
    val readListLongCol: (Int) -> List<Long> = { N -> (0 until N).map { readLong() } }
    val readListLongCols: (Int) -> List<List<Long>> = { N -> (0 until N).map { br.readLine().split(' ').map { it.toLong() } } }
    val close: () -> Unit = { br.close() }
    protected fun finalize() { close() }
}


Measured memory_bytes: 36612
<?php

while (TRUE) {
    fscanf(STDIN, '%f', $v);
    if (feof(STDIN)) {
        break;
    }
    $t = $v / 9.8;
    $h = 4.9 * $t * $t;
    $N = ceil($h / 5) + 1;
    echo sprintf('%d', $N);
    echo PHP_EOL;
}

Measured memory_bytes: 6592
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int num; //出席番号
    string s;
    char comma;
    int cnt_A = 0, cnt_B = 0, cnt_O = 0, cnt_AB = 0;
    while(cin >> num){
        cin >> comma >> s;
        if(s == "A") cnt_A++;
        if(s == "B") cnt_B++;
        if(s == "O") cnt_O++;
        if(s == "AB") cnt_AB++;
    }
    cout << cnt_A << endl;
    cout << cnt_B << endl;
    cout << cnt_AB << endl;
    cout << cnt_O << endl;
}



Measured memory_bytes: 3080
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		static long mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			//int n = int.Parse(Console.ReadLine());
			ulong[] vs = Console.ReadLine().Split().Select(ulong.Parse).ToArray();
			ulong a = Math.Max(vs[0] - 1, 0);
			ulong b = vs[1];
			ulong c = 0;
			ulong ans = 0;
			for (int i = 0; i < 64; i++) {
				c = Count1(b, i) - Count1(a, i);
				if (c % 2 == 1) {
					ans += (1UL << i);
				}
			}
			Console.WriteLine(ans);


			Console.Out.Flush();
		}

		static ulong Count1(ulong value, int pos)
		{
			ulong x = 1UL << pos;
			ulong y = x << 1;
			ulong a = 0;
			if (y > 0) {
				a = value / y * x;
			}
			ulong z = ~(0xffffffffffffffff << pos);
			ulong b = (value & x) == 0 ? 0 : (value & z) + 1;
			return a + b;
		}

	}
}


Measured memory_bytes: 13396
n,m = map(int,input().split())

from math import factorial
def combinations_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

if n==0:
    print(combinations_count(m, 2))
elif m == 0:
        print(combinations_count(n, 2))
elif n==1 and m ==1:
    print(0)
elif n==1:
    print(combinations_count(m, 2))

elif m==1:
    print(combinations_count(n, 2))

else:
    print(combinations_count(n, 2)+combinations_count(m, 2))




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

using namespace std;
#define ll long long

ll INF = 1e9 + 7;
const int N = 1e5 + 7;

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    ll a,b,c;
    cin>>a>>b>>c;

    double ans = ((double)a)/c;
    if(ans >b)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;

}


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


int main(){
  int k,a,b;cin>>k>>a>>b;
  int c=(a-1)/k+1;
  cout<<(a<=c*k&&k*c<=b?"OK":"NG");
}

  

Measured memory_bytes: 3632
/*
ID: yzshang1
LANG: C++11
TASK:
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define pb push_back
#define mp make_pair
#define lsh(i) (1 << (i))
#define lshll(i) (1LL << (i))
#define int long long
#define repn(i, n) for (int (i) = 1; (i) <= (int)n; (i)++)
#define rep(i, n) for (int (i) = 0; (i) < (int)n; (i)++)
const int INF = 0x3f3f3f3f;
const long double EPS = 1e-6;
const int N = 200020;
int n, k;
int a[N];
signed main() {
	cin >> n >> k; rep(i, n) cin >> a[i];
	sort(a, a + n); reverse(a, a + n);	int ans = 0;
	if (k >= n) {
		cout << 0 << endl;
		return 0;
	}
	else for (int i = k ; i < n; i++) ans += a[i];
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(register int i = (a), i##_end_ = (b); i <= i##_end_ ; ++i)
#define drep(i, a, b) for(register int i = (a), i##_end_ = (b); i >= i##_end_ ; --i)
#define clear(a, b) memset((a), (b), sizeof(a))
typedef long long LL;
int read() {
	int x = 0, flag = 1;
	char ch = getchar();
	while(!isdigit(ch)) {
		if(ch == '-') flag = -1;
		ch = getchar();
	}
	while(isdigit(ch)) {
		x = (x << 3) + (x << 1) + (ch - 0x30);
		ch = getchar();
	}
	return flag * x;
}

#define Max 109
const int dir[2][2] = {{0, 1}, {1, 0}};
int H, W;
int ap[Max][Max], vis[Max][Max];
int l_ans;
int flag, Ktmp;
void dfs(int a, int b) {
	vis[a][b] = 1, ++Ktmp;
//	printf("(%d %d)\n", a, b);
	if(Ktmp == l_ans) {
		flag = 1;
		return ;
	}
	rep(i, 0, 1) {
		int nex = a + dir[i][0],
			ney = b + dir[i][1];
		if(1 <= nex && nex <= H && 1 <= ney && ney <= W)
			if(!vis[nex][ney] && ap[nex][ney]) dfs(nex, ney);
		if(flag) break;
	}
	vis[a][b] = 0, --Ktmp;
}
int main() {
#ifdef Qrsikno
	freopen("i.in","r",stdin);
	freopen("i.out","w",stdout);
#endif
	H = read(), W = read();
	rep(i, 1, H) {
		rep(j, 1, W) {
			char ch = getchar();
			if(ch == '#') ap[i][j] = 1, ++l_ans;
			if(ch == '.') ap[i][j] = 0;
		}
		getchar();
	}
	dfs(1, 1);
	puts(flag ? "Possible" : "Impossible");
	return 0;
}


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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};



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

  int ans=0;
  for(int t=0;t<=10;t++){
    int temp=pow(2,t);
    bool flag=false;
    for(int i=1;i<=N;i++){
      if(i%temp==0){
        flag=true;
        break;
      }
    }
    if(!flag)break;
    ans++;
  }

  cout<<pow(2,ans-1)<<"\n";
  return 0;
}


Measured memory_bytes: 512
<?php
$n = trim(fgets(STDIN));
for ( $i = 3; $i <= $n ; $i++){
    if( $i%3===0 ){
        echo " ".$i;
    }elseif( $i%10===3 ){
        echo " ".$i;
    }else{
        $pos = strpos($i,"3");
        if($pos!==false){
            echo " ".$i;
        }
    }
}
?>

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

using Graph=vector<vector<int>>;

void dfs(int v,set<int>& s,Graph &g){
    if(s.count(v)) return;
    s.insert(v);
    for(int i=0;i<g[v].size();i++){
        dfs(g[v][i],s,g);
    }
}
void solve(int n,int p1,int p2){
    Graph g(2*(p1+p2));
    for(int i=0;i<n;i++){
        int x,y;
        string a;
        cin>>x>>y>>a;
        x--,y--;
        if(a=="no"){
            g[x].push_back(y+p1+p2);
            g[y].push_back(x+p1+p2);
            g[x+p1+p2].push_back(y);
            g[y+p1+p2].push_back(x);
        }
        else{
            g[x].push_back(y);
            g[y].push_back(x);
            g[x+p1+p2].push_back(y+p1+p2);
            g[y+p1+p2].push_back(x+p1+p2);
        }
    }
    vector<int> used(p1+p2,false);
    vector<vector<int>> c1;
    vector<vector<int>> c2;
    for(int i=0;i<p1+p2;i++){
        if(!used[i]){
            set<int> s;
            dfs(i,s,g);
            vector<int> cc1;
            vector<int> cc2;
            for(auto &e:s){
                if(e<p1+p2){
                    used[e]=true;
                    cc1.push_back(e);
                }else{
                    used[e-p1-p2]=true;
                    cc2.push_back(e-p1-p2);
                }
            }
            c1.push_back(cc1);
            c2.push_back(cc2);
        }
    }
    vector<vector<int>> dp(c1.size()+1,vector<int>(p1+p2+1,0));
    dp[0][0]=1;
    for(int i=0;i<c1.size();i++){
        for(int j=0;j<=p1+p2;j++){
            if(j+c1[i].size()<=p1+p2){
                dp[i+1][j+c1[i].size()]+=dp[i][j];
                dp[i+1][j+c1[i].size()]=min(dp[i+1][j+c1[i].size()],2);
            }
            if(j+c2[i].size()<=p1+p2){
                dp[i+1][j+c2[i].size()]+=dp[i][j];
                dp[i+1][j+c2[i].size()]=min(dp[i+1][j+c2[i].size()],2);
            }
        }
    }
    int pos=c1.size();
    if(dp[pos][p1]>=2){
        cout<<"no"<<endl;
    }
    else{
        int val=p1;
        vector<int> ans;
        while(pos>0){
            if(val-(int)(c1[pos-1].size())>=0 && dp[pos-1][val-c1[pos-1].size()]){
                val-=(int)(c1[pos-1].size());
                for(int i=0;i<c1[pos-1].size();i++) ans.push_back(c1[pos-1][i]+1);
                pos--;
            }
            else{
                val-=(int)(c2[pos-1].size());
                for(int i=0;i<c2[pos-1].size();i++) ans.push_back(c2[pos-1][i]+1);
                pos--;
            }
        }
        sort(ans.begin(),ans.end());
        for(int i=0;i<p1;i++) cout<<ans[i]<<endl;
        cout<<"end"<<endl;
    }

}
int main(){
    int n,p1,p2;
    while(cin>>n>>p1>>p2,!(n==0 && p1==0 && p2==0)){
        solve(n,p1,p2);
    }
    return 0;    
}


Measured memory_bytes: 3220
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=998244353 ;



struct UnionFind{
	vector<int> par,siz;
	UnionFind(int N): par(N), siz(N){
		rep(i, N){
			par[i] = i; siz[i] = 1;
		}
	}
	int root(int x){
		if(par[x]==x) return x;
		else return root(par[x]);
	}
	void unite(int x, int y){
		x=root(x); y=root(y);
		if(x==y) return;
		if(siz[x] < siz[y]) swap(x, y);
		par[y] = x;
		siz[x] += siz[y];
	}
	bool same(int x, int y){
		return root(x)==root(y);
	}
	int size(int x){
		return siz[root(x)];
	}
};


int Color[100000] = {};
vector<int> to[100000];
 
void init(int X) {
	for (int i = 0; i < X; i++) Color[i] = -1;
}
 
bool DFS(int X, int C) {
	Color[X] = C;
	for (int Y : to[X]) {
		if (Color[Y] == -1) {
			if (!DFS(Y, 1 - C)) return false;
		}
		else if (Color[Y] == Color[X]) return false;
	}
	return true;
}

int main(){
  int N, M; cin >> N >> M;
  UnionFind uf(N); init(N);
  rep(i, M){
    int u, v; cin >> u >> v; u--; v--;
    uf.unite(u, v);
    to[u].push_back(v); to[v].push_back(u);
  }
  int cnt = 0, s=0;
  rep(i, N){
    if(uf.root(i)!=i) continue;
    if(uf.size(i)==1) continue;
    if(DFS(i, 0)){
      cnt++;
      s+=uf.size(i);
    }
  }
  init(N);
  //cout << s << endl;
  //cout << cnt << endl;
  ll ans = 0; ans+=((ll)cnt*cnt*2);
  //cout << ans << endl;
  rep(i, N){
    if(uf.root(i)!=i) continue;
    if(uf.size(i)==1) continue;
    if(!(DFS(i, 0))){
      if(uf.size(i)!=1) ans+=((ll)2*cnt+1);
      cnt++;
      s+=uf.size(i);
      //cout << uf.size(i) << endl;
    }
  }
  //cout << cnt << endl;
  rep(i, N){
    if(uf.size(i)==1){
      ans+=(ll)(2*s+1); s++;
    }
  }
  //cout << s << endl;
  cout << ans << endl;
}

Measured memory_bytes: 7936
#include <iostream>
using namespace std;
int main(void){

    int t,n,s,f,sum;
    
    while(true){
        cin >> t;
        
        if(t==0) break;    
    
        cin >> n;

        sum=0;
        
        for(int i=0;i<n;i++){
        cin >> s >> f ;
        sum += f-s;
        }
    if(t<=sum)
        cout << "OK" << endl;
    else
        cout << t-sum <<endl;
    
    }

}



Measured memory_bytes: 3120
#include<stdio.h>

int main(){
  int N,i,j,minj,temp,count=0;
  scanf("%d",&N);
  int A[N];

  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }

  for(i=0;i<N-1;i++){
    minj = i;
    for(j=i;j<=N-1;j++){
      if(A[j] < A[minj]){
	minj = j;
      }
    }
      temp = A[i];
      A[i] = A[minj];
      A[minj] = temp;
      if(i != minj){
      count = count + 1;
      }
    }

  for(i=0;i<N;i++){
    printf("%d",A[i]);
    if(i != N-1){
      printf(" ");
    }
  }

  printf("\n");

  printf("%d\n",count);

  return 0;
}

      



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

int main() {
  int n;
  cin >> n;
  double sum = 0;
  for(int i = 0; i < n; i++) {
    int a;
    cin >> a;
    sum += 1.0/a;
  }
  double ans = 1/sum;
  printf("%.10f\n", ans);
  return 0;
}

Measured memory_bytes: 256
S=gets.chop.chars.map(&:to_i)

pow=[1]
pow<<pow[-1]*10%2019 while pow.size<=S.size

ss=[0]
S.size.times do |i| ss<<(ss[-1]+S[-1-i]*pow[i])%2019 end

h=Hash.new{|h,k|h[k]=0}
ss.each do |i| h[i]+=1 end

ans=0
S.size.times do |i|
  h[ss[S.size-i]]-=1
  ans+=h[ss[S.size-i]]
end
p ans

Measured memory_bytes: 29728
/*bismillah ->                                                                                                         << Suirkhanov Meyirlan >>
  GL HF


                                                                                                                      42

    bless my code =)
                                                                                                            NEVER FOLLOW YOUR RULES :D HAHAHAHA
*/


///scanf ("%d%d", &x, &y);
///printf("%d", &a)

#include <bits/stdc++.h>

#define fast ios_base::sync_with_stdio();   cin.tie(0);   cout.tie(0);
#define randoperation srand(time(0));
#define pii pair < int , int >
#define pll pair < ll, ll >
#define pb push_back
#define pf psuh_front
#define mp make_pair
#define fi first
#define se second
#define fast ios_base::sync_with_stdio();   cin.tie(0);   cout.tie(0);
#define randoperation srand(time(0));
#define eb emplace_back

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const ll N = 2 * 1e3 + 7;
const ld pi = 3.14159265359;
const int INF = 1e20 + 7;
const double eps = 1e-9;

const int xi[4] = {-1, 0, +1, 0};
const int yj[4] = {0, +1, 0, -1};
const int xxi[4] = {+1, 0, -1, 0};
const int yyj[4] = {0, -1, 0, +1};

ld n, a[N], sum;

ll ans;

int main(){

  //freopen("bridge.in", "r", stdin);
  //freopen("bridge.out", "w", stdout);

  fast
  randoperation;

  ///           ||
  ///start here \/

  cin >> n;

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

  ll ave = 0;

  if(double(sum / n) > 0){
    ave = ll(double(sum / n) + 0.5);
  }

  else if(double(sum / n) < 0){
    ave = ll(double(sum / n) - 0.5);
  }

  for(int i = 1; i <= n; i++){
    ll x = ll(a[i]);
    if(x == ave){
      continue;
    }
    ans += (a[i] - ave) * (a[i] - ave);
  }

  cout << ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define speed ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ub(a,x) upper_bound(a.begin(),a.end(),x)-a.begin()
#define lb(a,x) lower_bound(a.begin(),a.end(),x)-a.begin()
#define ALL(v)   v.begin(),v.end()
int main()
	{
		speed
		string s;
		cin >> s;
		bool r = true;
		for(auto s1 : s)
		{
			if(count(s.begin(), s.end() , s1) != 2)
				r = false;
		}
		if(r)
			cout << "Yes";
		else
			cout << "No";

		
	}	


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int sets, i, j, k, side[3], tmp;
	scanf("%d", &sets);
	for(k = 0; k < sets; k++) {
		for(i = 0; i < 3; i++) {
			scanf("%d", &side[i]);
		}
		for(i = 0; i < 3; i++) {
			for(j = 0; j < 2; j++) {
				if(side[j] >= side[j + 1]) {
					tmp = side[j + 1];
					side[j + 1] = side[j];
					side[j] = tmp;
				}
			}
		}
		if(side[0] * side[0] + side[1] * side[1] == side[2] * side[2]) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 580
#include <stdio.h>
 
int main(void){
	
	int a,b,c,x,y;
	
	scanf("%d %d %d",&a,&b,&c);
	
	x = a - b;
	y = a - c;
	if(abs(x) > abs(y)){
	printf("B\n");
	} else {
	printf("A\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
typedef pair<int,int>par;
set<par>st;
int main(){
    int h,w,n;
    scanf("%d%d%d",&h,&w,&n);
    vector<par>ve;
    for(int i=0;i<n;i++){
        int a,b;
        scanf("%d%d",&a,&b);a--;b--;
        st.insert(par(a,b));
        for(int x=0;x<3;x++)
            for(int y=0;y<3;y++)
                ve.push_back(par(a-x,b-y));
        }
    sort(ve.begin(),ve.end());
    ve.resize(unique(ve.begin(),ve.end())-ve.begin());
    long long int ans[10]={0};
    ans[0]=1ll*(h-2)*(w-2);
    for(par p:ve){
        if(p.f<0||p.s<0||p.f+2>=h||p.s+2>=w)continue;
        int cnt=0;
        for(int x=0;x<3;x++)
            for(int y=0;y<3;y++)
                if(st.find(par(p.f+x,p.s+y))!=st.end())
                    cnt++;
        ans[0]--;
        ans[cnt]++;
        }
    for(int i=0;i<10;i++)
        printf("%lld\n",ans[i]);
    }


Measured memory_bytes: 12008
/* ex3_4
   kohei0713 */

#include <stdio.h>
#include <stdbool.h>

int main(void){
    
    int number;
    bool answer = false;
    
    //input
    scanf("%d", &number);

    //1から9まで繰り返す
    for(int i = 1; i < 10; i++){
        //numberがiで割り切れ,商が9以下のときanswerをtrueにし,ループから抜け出す
        if(number % i == 0 && number / i < 10){
            answer = true;
            break;
        }
    }

    //answerがtrueなら"Yes",falseなら"No"を出力
    if(answer){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;
}

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

int main() {
  int N,M;
  cin >> N >> M;
  
  vector<int> Li,Ri;
  
  rep(i,M){
    int tmpLi,tmpRi;
    cin >> tmpLi >> tmpRi;
    Li.push_back(tmpLi);
    Ri.push_back(tmpRi);
  }
  
  int passmin = 0;
  int passmax = pow(10,5);
  
  int ans = 0;
  rep(i,M){
    if(passmin < Li.at(i)) passmin = Li.at(i);
    if(passmax > Ri.at(i)) passmax = Ri.at(i);
    
    if(passmin > passmax) break;
  }

  passmax = min(N, passmax);
  
  ans = (passmax - passmin) + 1;
  if(ans <= 0) ans = 0;
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 1276
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
	int N, K;
	cin >> N >> K;
	vector<int> H(N);
	for (int i = 0; i < N; ++i) {
		cin >> H[i];
	}
	sort(H.begin(), H.end(), greater<int>());
	long long sum = 0;
	for (int i = K; i < N; ++i) {
		sum += H[i];
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1024
n = gets.to_i
points = (1..n).map{ gets.split(' ').map(&:to_i) }
points.unshift([0,0,0])

result = points.each_cons(2) do |p1, p2|
  d = (p2[1] - p1[1]).abs + (p2[2] - p1[2]).abs
  t = p2[0] - p1[0]
  if (d > t) or ((t-d)%2 == 1)
    break true
  end
end
if result
  puts 'No'
else
  puts 'Yes'
end



Measured memory_bytes: 9724
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

int num, ac, query;
char comma;
map<int, vector<int> > m;
map<int, int> rank;

int main()
{
	while (cin>>num>>comma>>ac, num|ac)
	{
		//printf("num = %d, ac = %d\n", num, ac);
		m[ac].pb(num);
	}

	int r = 1;
	for (int i=30; i>=0; i--)
	{
		if (m[i].size() > 0)
		{
			for (int j=0; j<m[i].size(); j++)
			{
				rank[m[i][j]] = r;
			}
			r++;
		}
	}

	while (cin >> query)
	{
		cout << rank[query] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1220
S = input()
A = 'No'
if len(S) == 2:
    if S == 'hi':
        A = 'OK'
if len(S) == 4:
    if S == 'hihi':
        A = 'OK'
if len(S) == 6:
    if S == 'hihihi':
        A = 'OK'
if len(S) == 8:
    if S == 'hihihihi':
        A = 'OK'
if len(S) == 10:
    if S == 'hihihihihi':
        A = 'OK'

if A == 'OK':
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
import java.util.ArrayList;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
	
	public static class Walk implements Comparable<Walk>{
		int cost;
		int sanso;
		int x,y;
		boolean[][] visited;
		
		public Walk(int cost, int sanso,int x, int y, int h, int w) {
			super();
			this.cost = cost;
			this.sanso = sanso;
			this.x = x;
			this.y = y;
			visited = new boolean[h][w];
		}
		
		public Walk(Walk w){
			this.cost = w.cost;
			this.sanso = w.sanso;
			this.x = w.x;
			this.y = w.y;
			visited = new boolean[w.visited.length][w.visited[0].length];
			for(int i = 0; i < w.visited.length; i++){
				System.arraycopy(w.visited[i], 0, this.visited[i], 0, w.visited[i].length);
			}
		}

		@Override
		public int compareTo(Walk arg0) {
			return this.cost - arg0.cost;
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int dir[][] = {{-1,0},{1,0},{0,1}};
		
		while (true) {
			final int w = sc.nextInt();
			final int h = sc.nextInt();
			
			if(w == 0 && h == 0){
				break;
			}
			
			final int amount = sc.nextInt();
			final int capacity = sc.nextInt();
			final int init = sc.nextInt();
			
			int[][] map = new int[h][w];
			
			for(int i = 0; i < h; i++){
				for(int j = 0; j < w; j++){
					map[i][j] = sc.nextInt();
				}
			}
			
			PriorityQueue<Walk> queue = new PriorityQueue<Walk>();
			for(int i = 0; i < w; i++){
				Walk walk = new Walk(0, init, i, 0, h, w);
				walk.sanso--;
				queue.add(walk);
			}
			
			boolean flag = false;
			while(!queue.isEmpty()){
				Walk walk = queue.poll();
				
				//System.out.println(walk.x + " " + walk.y + " " + walk.cost + " " + walk.sanso);
				
				if(walk.sanso <= 0){
					continue;
				}else if(walk.y >= h){
					flag = true;
					System.out.println(walk.cost);
					break;
				}
				
				walk.visited[walk.y][walk.x] = true;

				if(map[walk.y][walk.x] <= 0){
					walk.cost += (-map[walk.y][walk.x]);
				}else{
					walk.sanso = Math.min(map[walk.y][walk.x] + walk.sanso, capacity);
				}
				
				if(walk.cost > amount){
					continue;
				}
				
				
				for(int i = 0; i < 3; i++){
					if(walk.x + dir[i][0] >= 0 && walk.x + dir[i][0] <= w-1
						&& walk.y + dir[i][1] >= 0 && walk.y + dir[i][1] <= h-1
						&& !walk.visited[walk.y + dir[i][1]][walk.x + dir[i][0]]){
						
						Walk wa = new Walk(walk);
						wa.x += dir[i][0];
						wa.y += dir[i][1];
						wa.sanso--;
						queue.add(wa);
					}else if(i == 2 && walk.y == h-1){
						Walk wa = new Walk(walk);
						wa.y++;
						queue.add(wa);
					}
				}
			}
			
			if(!flag){
				System.out.println("NA");
			}
			
		}
	}

}

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

int main (void){

    int N,i,j;
    cin >> N;
    int A[2][N],B[N] = {0};
    for(i = 0; i < 2; i++){
        for(j = 0; j < N; j++){
            cin >> A[i][j];
        }
    }
    for(i = 0; i < N; i++) {
        for (j = 0; j < i+1; j++) {
            B[i] += A[0][j];
        }
    }
    for(i = 0; i < N; i++){
        for(j = i; j < N; j++){
            B[i] += A[1][j];
        }
    }
    sort(B,B+N);
    reverse(B,B+N);
    cout << B[0] << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    //Divide the Problems
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] A = new int[n];
        for (int i = 0; i < n; i++) A[i] = sc.nextInt();
        System.out.println(sln(A));
        sc.close();
    }

    static int sln(int[] A) {
        int n = A.length / 2;
        Arrays.sort(A);
        return A[n] - A[n - 1];
    }
}


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

int main() {
  string S;
  ll K;
  cin >> S >> K;
  
  ll ans = 0;
  int tmp = 1;
  for (int i = 1; i < S.size(); i++) {
    if (S[i] == S[i - 1]) {
      tmp++;
    } else {
      ans += tmp / 2;
      tmp = 1;
    }
  }
  ans += tmp / 2;
  
  if (S[0] == S[S.size() - 1]) {
    int cnt = 0;
    for (int i = 0; i < S.size(); i++) {
      if (S[i] == S[0]) cnt++;
      else break;
    }
    
    int cnt2 = 0;
    for (int i = S.size() - 1; i >= 0; i--) {
      if (S[i] == S[0]) cnt2++;
      else break;
    }
    
    if (cnt == S.size()) {
      cout << S.size() * K / 2 << endl;
    } else if (cnt % 2 == 0 || cnt2 % 2 == 0) {
      cout << ans * K << endl;
    } else {
      cout << (ans + 1) * K - 1 << endl;
    }
  } else {
    cout << ans * K << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
import math
def Sieve_of_Eratosthenes(N):
    prime=set(i for i in range(2,N+1))
    for i in range(2,math.ceil(N**0.5)+1):
        tmp=set()
        for j in prime:
            if j>i and j%i==0: tmp.add(j)
        for j in tmp:
            prime.remove(j)

    return(prime)

N=10**5+1
s=Sieve_of_Eratosthenes(N)
a=[0]*(N)
for i in range(2,N):
	if i in s and (i+1)//2 in s: a[i]=a[i-1]+1
	else: a[i]=a[i-1]

for i in range(int(input())):
	l,r=map(int,input().split())
	print(a[r]-a[l-1])

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

using namespace std;

int main() {
    string t;
    cin >> t;
    for (int i = 0; i < t.size(); ++i) {
        if (t[i] == 'A') t[i] = 'X';
        else if (t[i] == 'B') t[i] = 'Y';
        else if (t[i] == 'C') t[i] = 'Z';
        else t[i] -= 3;
    }
    cout << t << '\n';
}


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

int main() {
	long long n, m, ans = 1;
	cin >> n >> m;
	for(long long i = 1; i * i <= m; ++i){
		if(m%i) continue;
		long long f = m/i;
		if(n*f <= m) ans = max(ans, f);
		if(n*i <= m) ans = max(ans, i);
	}
	cout << ans;
	
	return 0;
}

Measured memory_bytes: 256
N = int(input())
a = [int(input())-1 for i in range(N)]

count=0
next_push=0
while(next_push != 1 and count < 1e5+1):
    next_push = a[next_push]
    count += 1

if count > 1e5:
    print(-1)
else:
    print(count)

Measured memory_bytes: 7084
#include <bits/stdc++.h>
using namespace std;
int main(){
  int ans = 0;
  int n, m; cin >> n >> m;
  for(int i = 1; i*i <= m; i++){
    if(m%i) continue;
  	if(m/i >= n) ans = max(ans, i);
    if(i >= n) ans = max(ans, m/i);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#define int long long
using namespace std;

inline int min(int x, int y) {return x<y? x:y;}

int n, m, M, ans = 1e9;
int c[15], a[15][15], z[15], f[15];

inline void dfs(int x, int now)
{
    if(x > n)
    {
        memset(f, 0, sizeof(f));
        for(int i=1; i<=n; i++) 
            if(z[i]) 
            {
                for(int j=1; j<=m; j++) 
                    f[j] += a[i][j];
            }
        for(int i=1; i<=m; i++) if(f[i] < M) return ; 
        ans = min(ans, now);
        return ;
    }
    z[x] = 1;
    dfs(x + 1, now + c[x]);
    z[x] = 0;
    dfs(x + 1, now);
}  

signed main()
{
    scanf("%lld%lld%lld", &n, &m, &M);
    for(int i=1; i<=n; i++)
    {
        scanf("%lld", &c[i]);
        for(int j=1; j<=m; j++)
        {
            scanf("%lld", &a[i][j]);
        }
    }
    dfs(1, 0);
    if(ans == 1e9) printf("%d", -1);
    else printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 1708