akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
using namespace std;

int main(){
	//\W×Hのマスの周を"."で囲んでやり、中身だけを出力;
	int h,w,count[55][55];
	char s[55][55];

	cin>>h>>w;	//s[i][j]=マス(i,j);
	for(int i=1;i<h+1;i++){
		for(int j=1;j<w+1;j++){
			cin>>s[i][j];
		}
	}

	for(int i=0;i<h+2;i++){
		for(int j=0;j<w+2;j++){
			count[i][j]=0;
		}
	}
	
	for(int i=0;i<h+2;i+=h+1){
		for(int j=0;j<w+2;j++){
			s[i][j]='.';
		}
	}
	for(int i=0;i<h+2;i++){
		for(int j=0;j<w+2;j+=w+1){
			s[i][j]='.';
		}
	}

	for(int i=1;i<h+1;i++){
		for(int j=1;j<w+1;j++){
			if(s[i][j+1]=='#')count[i][j]++;
			if(s[i][j-1]=='#')count[i][j]++;
			if(s[i+1][j]=='#')count[i][j]++;
			if(s[i-1][j]=='#')count[i][j]++;
			if(s[i+1][j+1]=='#')count[i][j]++;
			if(s[i-1][j-1]=='#')count[i][j]++;
			if(s[i+1][j-1]=='#')count[i][j]++;
			if(s[i-1][j+1]=='#')count[i][j]++;
		}
	}
	for(int i=1;i<h+1;i++){
		for(int j=1;j<w+1;j++){
			if(s[i][j]=='#')cout<<"#";
			else cout<<count[i][j];
		}
		cout<<endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N,M;
int64_t dp[ 100005 ];
int64_t md = 1000000007;
bool chk_dbl( int s ) {
  if ( (dp[s+1]==md+1) && (dp[s+2] == md+1) )
    return 1;
  else
    return 0;
}

int main() {
  cin >> N >> M;
  for (int i=0;i<M;i++ ) {
    int ain;
    cin >> ain;
    dp[ain] = md+1;
  }
  if ( chk_dbl(0) ) {
    cout << "0" << endl;
    return 0;
  }
  if (dp[1] == md+1 ) dp[1] = 0;
  else dp[1] = 1;
  if (dp[2] == md+1 ) dp[2] = 0;
  else dp[2] = dp[1] + 1;

  for (int i=3;i<N+2;++i){
    if ( chk_dbl(i-2) ) {
      cout << "0" << endl;
      return 0;
    }
    if( dp[i] == md+1 ) {
      dp[i] = 0;
    } else {
	  dp[i] = (dp[i-2] + dp[i-1]) % md;
    }
  }
  cout << dp[N] << endl;
}
  


Measured memory_bytes: 1024
import java.util.*;
import java.io.*;
public class Main{
    static PrintWriter out;
    static InputReader in;
    public static void main(String args[]){
        out = new PrintWriter(System.out);
        in = new InputReader();
        new Main();
        out.flush(); out.close();
    }   
    Main(){
        solve();
    }
    class pair{
        long F, S;
        pair(long a, long b){
            F = a; S = b;
        }
    }
    final int max = 1000100;
    final long maxv = (long)2e18;
    int n; long c;
    long h[];
    pair seg[] = new pair[4 * max];
    // TreeSet<pair> ts = new TreeSet<>((A, B) -> A.F == B.F ? Long.compare(B.S, A.S) : Long.compare(B.F, A.F));
    long find(pair p, long x){
        return p.F * x + p.S;
    }
    void upd(int n, int s, int e, pair u){
        if(seg[n] == null || s == e){
            seg[n] = u;
            return;
        }
        int mid = (s + e) >> 1;
        boolean lowL = find(seg[n], s) > find(u, s);
        boolean lowM = find(seg[n], mid) > find(u, mid);
        if(lowL && lowM){
            pair f = seg[n];
            seg[n] = u;
            upd(2 * n + 2, mid + 1, e, f);
        }else if(!lowL && !lowM){
            upd(2 * n + 2, mid + 1, e, u);
        }else if(lowL && !lowM){
            upd(2 * n + 1, s, mid, u);
        }else{
            pair f = seg[n];
            seg[n] = u;
            upd(2 * n + 1, s, mid, f);
        }
    }
    long query(int n, int s, int e, long x){
        if(seg[n] == null)return maxv;
        if(s == e)return find(seg[n], x);
        int mid = (s + e) >> 1;
        if(x <= mid)return Math.min(find(seg[n], x), query(2 * n + 1, s, mid, x));
        else return Math.min(find(seg[n], x), query(2 * n + 2, mid + 1, e, x));
    }
    void solve(){
        n = in.nextInt(); c = in.nextLong();
        h = new long[n];
        for(int i = 0; i < n; i++)h[i] = in.nextLong();
        upd(0, 0, max - 1, new pair(-2 * h[0], h[0] * h[0]));
        for(int i = 1; i < n; i++){
            long val = query(0, 0, max - 1, h[i]) + h[i] * h[i] + c;
            if(i == n - 1){
                out.println(val);
                return;
            }
            upd(0, 0, max - 1, new pair(-2 * h[i], val + h[i] * h[i]));
        }
    }
    public static class InputReader{
        BufferedReader br;
        StringTokenizer st;
        InputReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public int nextInt(){
            return Integer.parseInt(next());
        }
        public long nextLong(){
            return Long.parseLong(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
        public String next(){
            while(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch(IOException e){}
            }
            return st.nextToken();
        }
    }
}
        

Measured memory_bytes: 66400
def is_acgt(s):
    for c in s:
        if c not in ["A", "C", "G", "T"]:
            return False
    return True


S = input()
ml = 0
for l in range(len(S)+1):
    for r in reversed(range(len(S)+1)):
        if l <= r and is_acgt(S[l:r]):
            ml = max(ml, r-l)
print(ml)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    vector<int> data(n);
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        if((a==1&&b==0)&&n!=1)
        {
            cout<<"-1";
            return 0;
        }
        if(data[a-1]==0||data[a-1]==b) data[a-1]=b;
        else
        {
            cout<<"-1";
            return 0;
        }
    }
    if(data[0]==0&&n!=1) data[0]=1;
    for(int i=0;i<n;i++)
        cout<<data[i];
}

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

int Bob, Alice, Draw, x ,y;

int main () {
    cin >> x >> y;
    if (x==y){
        cout << "Draw" << endl;
    }else if (y==1){
        cout << "Bob" << endl;
    }else if ((x>y)||(x==1)){
        cout << "Alice" << endl;
    }else if (x==1){
        cout << "Alice" << endl;
    }else{
        cout << "Bob" << endl;
}
}


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

int main(){

    vector<int> v(5);
    int d;

    for(int i = 0; i < 5; i++){
        cin >> v[i];
    }
    cin >> d;

    if(v[4] - v[0] > d) cout << ":(" << endl;
    else cout << "Yay!" << endl;

}

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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359
#define inf (1 << 21)
#define mod 1000000007

int main() {
    int X, Y; cin >> X >> Y;
    cout << X + Y / 2 << endl;
    return 0;
}

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

int main(){
    int N;
    cin >> N;
    int cnt = 0;
    int goukei = 0;
    for(int i = 0; i < N; i++) {
        int L;
        cin >> L;
        cnt = max(cnt,L);
        goukei += L;
    }
    if(cnt < goukei-cnt) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
const int maxn = 100005;
 
int X,Y,Z;
int n;
struct P {
    ll x,y,z;
    bool operator<(const P&a)const {
        return x+a.y>y+a.x;
    }
} p[maxn];
 
struct cmp1 {
    bool operator()(int x,int y) {
        return p[x].x+p[y].z>p[y].x+p[x].z;
    }
};
struct cmp2 {
    bool operator()(int x,int y) {
        return p[x].y+p[y].z<p[x].z+p[y].y;
    }
};
 
bool in_silver[maxn];
int main() {
   // freopen("in.cpp","r",stdin);
    cin>>X>>Y>>Z;
    n=X+Y+Z;
    for(int i=0; i<n; i++)cin>>p[i].x>>p[i].y>>p[i].z;
    sort(p,p+n);
    ll ret=0;
    priority_queue<int,vector<int>,cmp1>left_gold;
    priority_queue<int,vector<int>,cmp2>right_bronze;
    for(int i=0; i<X; i++) {
        ret+=p[i].x;
        left_gold.push(i);
    }
    for(int i=n-1; i>=X; i--) {
        ret+=p[i].z;
        right_bronze.push(i);
        if(right_bronze.size()>Z) {
            int tt=right_bronze.top();
            right_bronze.pop();
            ret-=p[tt].z;
            ret+=p[tt].y;
            in_silver[tt]=true;
        }
    }
    ll cur=ret;
    for(int i=X; i<X+Z; i++) {
        ll tmp=cur;
        tmp+=p[i].x;
        left_gold.push(i);
        int tt=left_gold.top();
        left_gold.pop();
        tmp-=p[tt].x;
        tmp+=p[tt].z;
        if(in_silver[i]) {
            tmp-=p[i].y;
            while(!right_bronze.empty()) {
                int tt=right_bronze.top();
                if(tt<=i) {
                    right_bronze.pop();
                } else {
                    right_bronze.pop();
                    in_silver[tt]=true;
                    tmp-=p[tt].z;
                    tmp+=p[tt].y;
                    break;
                }
            }
        } else {
            tmp-=p[i].z;
        }
        ret=max(ret,tmp);
        cur=tmp;
    }
    cout<<ret<<endl;
    return 0;
}


Measured memory_bytes: 3196
#include <stdio.h>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
 
#define N 112345
#define LO 18
class sbit{
public:
	ll bit[100005];
	void add(int i, ll x){
		i++;
		while(i<100005){
			bit[i]+=x;
			i+=i&-i;
		}
	}
	void add(int l, int r, ll x){
		add(l, x);
		add(r, -x);
	}
	ll get(int i){
		i++;
		ll ret=0;
		while(i){
			ret+=bit[i];
			i-=i&-i;
		}
		return ret;
	}
};

ll k;
vector<pair<int, ll> > path[100005];

int f[100005]; // original node index -> on the list
int c[100005]; // size of subtree
int d[100005]; // depth in tree
int p[100005][LO]; // parent doubling
// int dmm[N];
sbit csm, dsm, qry;

void dfs(int nw, int par, int dep, int ind){
	// printf("dfs(nw=%d, par=%d, dep=%d, ind=%d)\n", nw, par, dep, ind);
	f[nw]=ind;
	d[ind]=dep;
	p[ind][0]=par;
	for(int i=1; i<LO; i++)
	 	p[ind][i]=p[p[ind][i-1]][i-1];
	int sm=1;
	for(int i=0; i<path[nw].size(); i++){
		pair<int, ll> &pr=path[nw][i];
		if(f[pr.first]==par) continue;
		dfs(pr.first, ind, dep+1, ind+sm);
		csm.add(ind+sm, ind+sm+c[ind+sm], pr.second);
		if(pr.second%k==0){
			dsm.add(ind+sm, ind+sm+c[ind+sm], pr.second);
			// dmm[ind+sm]=pr.second;
		}
		sm+=c[ind+sm];
	}
	c[ind]=sm;
}

int lsc(int x, int y){
	if(d[x]<d[y]) swap(x, y);
	int dif=d[x]-d[y];
	for(int i=0; i<LO; i++)
	 	if(dif&(1<<i)) x=p[x][i];
	// printf(" %d %d\n", x, y);
	if(x==y) return x;
	int ret=0;
	for(int i=LO-1; i>=0; i--){
		// printf("(%d, %d)->(%d, %d)\n", x, y, p[x][i], p[y][i]);
		if(p[x][i]==p[y][i]) ret=p[x][i];
		else{
			x=p[x][i];
			y=p[y][i];
		}
	}
	return ret;
}

ll clc(int x){
	int q;
	while((q=qry.get(x))){
		int y=x;
		for(int i=LO-1; i>=0; i--){
			if(qry.get(p[y][i])==q) y=p[y][i];
		}
		dsm.add(y, y+c[y], -(dsm.get(y)-dsm.get(p[y][0])));
		ll r=csm.get(y)-csm.get(p[y][0]);
		if(r%k==0){
			dsm.add(y, y+c[y], r);
		}
		qry.add(y, y+c[y], -(qry.get(y)-qry.get(p[y][0])));
	}
	return csm.get(x)-dsm.get(x);
}

int main(){
	int n;
	cin >> n >> k;
	for(int i=0; i<n-1; i++){
		int a, b;
		ll c;
		cin >> a >> b >> c;
		path[a].push_back(make_pair(b, c));
		path[b].push_back(make_pair(a, c));
	}
	for(int i=0; i<n; i++) f[i]=-1;
	dfs(0, 0, 0, 0);

	int q;
	cin >> q;
	for(int i=0; i<q; i++){
		string s;
		ll x, y;
		cin >> s >> x >> y;
		if(s[0]=='a'){
			x=f[x];
			if(x){
			 	csm.add(x, x+c[x], y);
				qry.add(x, x+c[x], 1);
			}
			csm.add(x+1, x+c[x], y);
			qry.add(x+1, x+c[x], 1);
		}else{
			x=f[x];
			y=f[y];
			int z=lsc(x, y);
			ll ans=clc(x)+clc(y)-2*clc(z);
			cout << ans << endl;
		}
	}
}

Measured memory_bytes: 28436
//https://atcoder.jp/contests/abc165/tasks/abc165_c
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
const ll LINF = 0x1fffffffffffffff;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
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;}
int main(){
#if LOCAL&01
  std::ifstream in("./test/sample-1.in");
  //std::ifstream in("./input.txt");
  std::cin.rdbuf(in.rdbuf());
#else
  cin.tie(0);
  ios::sync_with_stdio(false);
#endif
  ll N,M,Q; cin>>N>>M>>Q;
  vector<tuple<ll,ll,ll,ll>>tbl(Q);
  REP(i,Q){
    auto& [a,b,c,d]=tbl.at(i);
    cin>>a>>b>>c>>d;
  }

  auto check=[&](const auto& an){
    ll ret=0;
    for(auto& tp:tbl){
      auto [a,b,c,d]=tp;
      if (an[b]-an[a]==c){
        ret += d;
      }
	  }
    return ret;
  };

  ll ans=0;
  auto dfs = [&](auto&& self, ll pos, ll v, vector<ll> lst){
    if(pos>=N+1){
      dump(lst);
      chmax(ans,check(lst));
      return;
    }
    FOR(i,v,M+1){
      lst[pos]=i;
      self(self,pos+1,i,lst);
    }
  };
  auto l=vector<ll>(N+1);
  dfs(dfs, 1, 1, l);
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <sstream>
#include <fstream>
#include <string.h>

#define X first
#define Y second
#define MP make_pair
typedef long long ll;
using namespace std;
const int MAX = 101;

template<class T, class U>
void convert(T &t, U &u){
	stringstream ss;
	ss << t;
	ss >> u;
}

int main(){
	int n;
	while(cin >> n && n!=0){
		map<int, ll> ans;
		vector<int> idx;
		int id, price, num;
		for(int i = 0; i < n; i++){
			cin >> id >> price >> num;
			if(!ans.count(id)) idx.push_back(id);
			ans[id] += (ll)price*num;
		}

		vector<int> ans_id;
		for(int i = 0; i < idx.size(); i++){
			if(ans[idx[i]]>=1000000) ans_id.push_back(idx[i]);
		}
		if(ans_id.size()==0){
			cout << "NA" << endl;
		}else{
			for(int i = 0; i < ans_id.size(); i++){
				cout << ans_id[i] << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1288
#!/usr/bin/env python3
n, m = map(int, input().split())
h = list(map(int, input().split()))
not_good = []
for i in range(m):
    a, b = map(int, input().split())
    if h[a - 1] > h[b - 1]:  # bはダメ
        not_good.append(b)
    elif h[a - 1] == h[b - 1]:
        not_good.append(a)
        not_good.append(b)
    else:
        not_good.append(a)
ans = 0
not_good = list(set(not_good))
not_good.sort()
# print(not_good)
idx = 0
for i in range(1, n + 1):
    if i < not_good[idx]:
        ans += 1
        # print(i, end=" ")
    elif i == not_good[idx]:
        idx += 1
        if idx == len(not_good):
            ans += n - i
            break
    else:
        pass
print(ans)


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  int K,A,B;
  cin>>K>>A>>B;
  for(int i=A;i<=B;i++)if(i%K==0){
    cout<<"OK"<<endl;
    return 0;
  }
  cout<<"NG"<<endl;
  return 0;
}


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

#define initialMax -1000000000

using namespace std;

int main(int argc,char* argv[]){
  vector<int> values;
  int number,input;
  cin>>number;
  for(int i=0;i<number;i++){
    cin>>input;
    values.push_back(input);
  }
  int minv=values[0],maxv=initialMax;
  for(int i=1;i<number;i++){
    maxv = max(maxv,values[i]-minv);
    minv = min(minv,values[i]);
  }
  cout << maxv << endl;
}

Measured memory_bytes: 3852
//おまじないc++
#include <iostream>
#include<cmath>
#include<vector>
using namespace std;
 
int main() {
int x,y;
  cin>>x>>y;
  int sum=0;
  
  if(x==1){
	sum+=300000;
  }
  
  else if(x==2){
    sum+=200000;
  }
  
  else if(x==3){
    sum+=100000;
  }
  
  if(y==1){
	sum+=300000;
  }
  
  else if(y==2){
    sum+=200000;
  }
  
  else if(y==3){
    sum+=100000;
  }
  
  
  if(x==1&&y==1){
    sum+=400000;
  }
  
  cout<<sum<<endl;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
	int H, W, M; cin >> H >> W >> M;
	vector<pair<int, int>> hw(M);
	vector<int> yoko(H), tate(W);
	for(int i = 0; i < M; i++) {
		cin >> hw[i].first >> hw[i].second;
		hw[i].first--; hw[i].second--;
		yoko[hw[i].first]++; tate[hw[i].second]++;
	}
	int yokoM = 0, tateM = 0;
	set<int> yokos, tates;
	for(int i = 0; i < H; i++) {
		if(yoko[i] > yokoM) {
			yokoM = yoko[i];
			while(!yokos.empty()) yokos.erase(yokos.begin(), yokos.end());
			yokos.insert(i);
		}
		else if(yoko[i] == yokoM) yokos.insert(i);
	}
	for(int i = 0; i < W; i++) {
		if(tate[i] > tateM) {
			tateM = tate[i];
			while(!tates.empty()) tates.erase(tates.begin(), tates.end());
			tates.insert(i);
		}
		else if(tate[i] == tateM) tates.insert(i);
	}
	int ans = yokoM + tateM;
	int judge = 0;
	for(int i = 0; i < M; i++) {
		if(yokos.count(hw[i].first) && tates.count(hw[i].second)) judge++;
	}
	if(judge == yokos.size() * tates.size()) ans--;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 35824
#include <iostream>
using namespace std;
typedef long long int ll;
const ll mod=1000000007;

ll p(ll m,ll n)
{
	if(n==1)return m%mod;
	if(n%2)return ((p((m*m)%mod,n/2)%mod)*m)%mod;
	else return p((m*m)%mod,n/2)%mod;
}

int main() {
	ll m,n;cin>>m>>n;cout<<p(m%mod,n)%mod<<endl;
	return 0;
}

Measured memory_bytes: 3112
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<string>
#include<vector>

typedef unsigned long long ULL;
typedef long long LL;

using namespace std;

int main(){
    int N;
    ULL i;
    ULL ans = 0;

    cin >> N;
    for(i=0;i<N-1;i++){
        ans +=  (i+1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

// 逆順文字列を取得する
func reverse(s string) string {
	newstr := ""
	for i := 0; i < len(s); i++ {
		newstr = s[i:i+1] + newstr
	}

	return newstr
}

// 文字列を置き換える
func replace(s string, a int, b int, p string) string {
	return s[:a] + p + s[b+1:]
}

func main() {
	var str string
	var q int
	var a, b int
	var p string
	var cmd string

	fmt.Scanf("%s", &str)
	fmt.Scanf("%d", &q)

	for i := 0; i < q; i++ {
		fmt.Scanf("%s", &cmd)
		switch cmd {
		case "print":
			fmt.Scanf("%d %d", &a, &b)
			fmt.Println(str[a : b+1])
		case "reverse":
			fmt.Scanf("%d %d", &a, &b)
			p = reverse(str[a : b+1])
			str = replace(str, a, b, p)
		case "replace":
			fmt.Scanf("%d %d %s", &a, &b, &p)
			str = replace(str, a, b, p)
		}
	}
}


Measured memory_bytes: 3380
#pragma GCC optimize ("O3")
#pragma GCC target("avx512f")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

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

  int N;
  int a[200000], b[200000];
  cin >> N;
  rep(i, N) cin >> a[i];
  rep(i, N) cin >> b[i];
  int ans = 0;
  rep(i, N) rep(j, N) ans ^= a[i] + b[j];
  cout << ans << endl;
}

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

bool hash[1024*1024*16];

unsigned int trans( char c ){
	if( c == 'A' )	return 1;
	if( c == 'C' )	return 2;
	if( c == 'G' )	return 3;
	if( c == 'T' )	return 4;
 }

unsigned int makeHash( char str[] ){
	unsigned int ret = 0;
	for( int i=0; i<strlen(str); i++ ){
		ret <<= 2;
		ret += trans(str[i]);
	}
	return ret;
}

int main(){
	int n;
	memset( hash, 0, sizeof(hash) );
	cin >> n;
	while(n--){
		char command[16], word[16];
		cin >> command >> word;
		if( command[0] == 'i' ){
			hash[makeHash(word)] = true;
		}else{
			cout << (hash[makeHash(word)] ? "yes" : "no") << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 17556
#include <bits/stdc++.h>
using namespace std;
int N;
vector<int> A;
vector<int> B;
long  solve(int as, int ae){
    if(as >= ae) return 0;
    long sum = 0;
    int ds = min(A[as], B[as]);
    A[as] -= ds;
    B[as] -= ds;
    sum += ds;
    int de = min(A[ae], B[ae-1]);
    A[ae] -= de;
    B[ae-1] -= de;
    sum += de;

    ds = min(A[as+1], B[as]);
    A[as+1] -= ds;
    B[as] -= ds;
    sum += ds;
    de = min(A[ae-1], B[ae-1]);
    A[ae-1] -= de;
    B[ae-1] -= de;
    sum += de;

    return sum + solve(as+1, ae-1);
}
int main(){
    cin >> N;
    A.resize(N+1);
    for(int i = 0; i < N+1; ++i){
        cin >> A[i];
    }
    B.resize(N);
    for(int i = 0; i < N; ++i){
        cin >> B[i];
    }
    cout << solve(0, N);
    return 0;
}

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

#define EPS (1.0e-10F)
#define equals(a, b) (fabs((a) - (b)) < EPS)

class Point{
public:
	double x, y;

	Point(double x = 0, double y = 0) : x(x), y(y) {}

	Point operator + (Point p) { return Point(x + p.x, y + p.y); }
	Point operator - (Point p) { return Point(x - p.x, y - p.y); }
	Point operator * (Point p) { return Point(x * p.x, y * p.y); }
	Point operator / (Point p) { return Point(x / p.x, y / p.y); }

	double abs() { return sqrt(norm()); }
	double norm() { return x * x + y * y; }

	bool operator < (const Point &p) const {
		return x != p.x ? x < p.x : y < p.y;
	}

	bool operator == (const Point &p) const{
		return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
	}

};

struct Segment {
	Point p1, p2;
};


typedef Point Vector;

double dot(Vector a, Vector b) {
	return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b) {
	return a.x * b.y - a.y * b.x;
}

bool isOrthogonal(Vector a, Vector b){
	return equals(dot(a, b), 0.0);
}

bool isOrthogonal(Point a1, Point a2, Point b1, Point b2){
	return isOrthogonal(a1 - a2, b1 - b2);
}

bool isOrthogonal(Segment s1, Segment s2){
	return equals(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}

bool isParallel(Segment s1, Segment s2){
	return equals(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}

int main(int argc, char* argv[]){
	int q;
	int x1, y1, x2, y2, x3, y3, x4, y4;
	Segment s1, s2;
	cin >> q;

	for (int i = 0; i < q; i++){
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
		s1.p1 = Point(x1, y1);
		s1.p2 = Point(x2, y2);
		s2.p1 = Point(x3, y3);
		s2.p2 = Point(x4, y4);

		if (isOrthogonal(s1, s2) == true){
			printf("1\n");
			continue;
		}
		else if (isParallel(s1, s2) == true){
			printf("2\n");
			continue;
		}
		else {
			printf("0\n");
		}
	}

	return 0;
}

Measured memory_bytes: 1120
#include<stdio.h>



int main()
{
	int n ;
	while( scanf( "%d" ,&n ) )
	{
		if( n == 0 )
		{
			return 0 ;
		}


		int ice[ 10 ] = { 0 } ;

		int i ,p ;
		for( i = 0 ; i < n ; ++i )
		{
			scanf( "%d" ,&p ) ;


			++ice[ p ] ;
		}


		int j ;
		for( i = 0 ; i < 10 ; ++i )
		{
			for( j = 0 ; j < ice[ i ] ; ++j )
			{
				printf( "*" ) ;
			}


			if( ice[ i ] > 0 )
			{
				puts( "" ) ;
			}

			else
			{
				puts( "-" ) ;
			}
		}
	}


	return 0 ;
}

Measured memory_bytes: 584
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <set>
#include <map>
#define INF 100000
using namespace std;

int main(){
    for (int i=1; i<10; i++) {
        for (int j=1; j<10; j++) {
            cout << i <<'x' << j<<'='<<i*j<<endl;
        }
    }
}

Measured memory_bytes: 1116
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>

#define REP(n) for(int i = 0;i < n;i++)
#define LLREP(n) for(long long int  i = 0;i < n;i++)
typedef long long int ll;
using namespace std;
#define MAX_A 100005

int main(){

    ll n;
    cin >> n;
    vector<ll> a(n);
    ll count = 0;
    for(int i = 0;i < n;i++){
        cin >> a[i];
        //cout << a[i] << endl;
    }


    for(int i = 0;i < n;i++){


        if(a[i]%2 == 0){
            //cout << "a" << endl;
            while(a[i]%2 == 0){
                a[i]/=2;
                count++;
            }
        }
        //cout << count << endl;


    }
    cout << count << endl;
    
    return 0;
}

Measured memory_bytes: 384
// BEGIN CUT HERE
#ifdef _MSC_VER
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <array>
#include <climits>
#include <bitset>
#include <cassert>
#include <unordered_map>
#include <agents.h>
#else
// END CUT HERE
#include <bits/stdc++.h>
// BEGIN CUT HERE
#endif
// END CUT HERE

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define UNIQUE(v) (v).erase(unique(ALL(v)), (v).end())
#define MP make_pair
#define MT make_tuple

using namespace std;

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

const int N = 1e5;
int x[N];
int sum[4][44];

int main(){
	vector<int> num = { 13, 17, 19, 23 };

	int n;
	while (cin >> n, n){
		MEMSET(x, 0);
		MEMSET(sum, 0);
		rep(i, n){
			int d, t;
			cin >> d >> t;
			vector<int> q(d);
			rep(j, d) cin >> q[(j - t + d) % d];
			int id = [&](){rep(j, 4) if (num[j] == d) return j; return -1; }();
			if (id >= 0){
				rep(j, d) sum[id][j] += q[j];
			}
			else{
				rep(j, N){
					x[j] += q[j%d];
				}
			}
		}
		int ans = *max_element(x, x+N);
		rep(i, 4) ans += *max_element(sum[i], sum[i] + 44);
		cout << ans << endl;
	}

}

Measured memory_bytes: 1592
H,W = (int(i) for i in input().split())
grid = ['#'*(W+2)]+['#'+input()+'#' for i in range(H)]+['#'*(W+2)]
smap = [[-1 for i in range(W+2)] for i in range(H+2)]
q = []
dot = 0
angle = [[1,0],[-1,0],[0,1],[0,-1]]

for i in grid:
  dot += i.count('.')

smap[1][1] = 1
q.append([1,1])

while len(q) > 0:
  pos = q.pop(0)
  cnt = smap[pos[0]][pos[1]] + 1
  for a in angle:
    if grid[pos[0]+a[0]][pos[1]+a[1]] == '.' and smap[pos[0]+a[0]][pos[1]+a[1]] == -1:
      q.append([pos[0]+a[0],pos[1]+a[1]])
      smap[pos[0]+a[0]][pos[1]+a[1]] = cnt

print(-1) if smap[H][W] == -1 else print(dot - smap[H][W])

Measured memory_bytes: 3188
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

int main() {
  i64 K;
  std::cin >> K;

  std::vector<i64> snuke;
  for (i64 i = 1ll; i <= 9ll; ++i) snuke.push_back(i);
  for (i64 i = 19ll; i <= 99ll; i += 10ll) snuke.push_back(i);
  for (i64 i = 199ll; i <= 1999ll; i += 100ll) snuke.push_back(i);
  for (i64 i = 2999ll; i <= 29999ll; i += 1000ll) snuke.push_back(i);
  for (i64 i = 39999ll; i <= 399999ll; i += 10000ll) snuke.push_back(i);
  for (i64 i = 499999ll; i <= 4999999ll; i += 100000ll) snuke.push_back(i);
  for (i64 i = 5999999ll; i <= 59999999ll; i += 1000000ll) snuke.push_back(i);
  for (i64 i = 69999999ll; i <= 699999999ll; i += 10000000ll) snuke.push_back(i);
  for (i64 i = 799999999ll; i <= 7999999999ll; i += 100000000ll) snuke.push_back(i);
  for (i64 i = 8999999999ll; i <= 89999999999ll; i += 1000000000ll) snuke.push_back(i);
  for (i64 i = 99999999999ll; i <= 999999999999ll; i += 10000000000ll) snuke.push_back(i);
  for (i64 i = 1099999999999ll; i <= 9999999999999ll; i += 100000000000ll) snuke.push_back(i);
  for (i64 i = 10999999999999ll; i <= 109999999999999ll; i += 1000000000000ll) snuke.push_back(i);
  for (i64 i = 119999999999999ll; i <= 999999999999999ll; i += 10000000000000ll) snuke.push_back(i);

  for (i64 i = 0; i < K; ++i) {
    std::cout << snuke[i] << std::endl;
  }
  return 0;
}

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

void digit(float num, int &n);

void digit(float num, int &n){

	if(static_cast<float>(num)/10.0 >= 1){
		++n;
		digit(num/10, n);
	}else{
		return;
	}

}

int main(){

	int a,b;
	int n;

	while(cin>>a>>b){

		n=1;
		digit(a+b,n);
		cout<<n<<"\n";
	}
	return 0;

}

Measured memory_bytes: 1160
import sys
MOD = 10**9+7
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
used_a = [False for _ in range(n)]
used_b = [False for _ in range(m)]
u_a_num = 0
u_b_num = 0
if len(set(a)) != n or len(set(b)) != m:
	print(0)
	sys.exit()

def search(num):
	x, y = -1, -1
	for i in range(n):
		if a[i] == num:
			x = i
			break
	for i in range(m):
		if b[i] == num:
			y = i
			break
	return x, y

ans = 1
zero_count = n+m
one_hidden = 0
for i in range(n*m, 0, -1):
	x, y = search(i)
	if x>=0 and y>=0:
		if used_a[x] == True or used_b[y] == True:
			ans *= 0
		else:
			used_a[x] = True
			used_b[y] = True
			u_a_num += 1
			u_b_num += 1
	elif x>=0 and y<0:
		ans = (ans*u_b_num) % MOD
		used_a[x] = True
		u_a_num += 1
	elif x<0 and y>=0:
		ans = (ans*u_a_num) % MOD
		used_b[y] = True
		u_b_num += 1
	else:
		ans = (ans* max(0, (u_a_num*u_b_num - (n*m - i)))) % MOD

	if u_a_num+u_b_num == n+m:
		J = i
		break

for j in range(J-1, 0, -1):
	ans = (ans*j) % MOD

print(ans)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
struct edge{int to,cost;};
int V;
vector<edge> G[200001];
int d[200001],INF=1e9,pre[200001];
int dijkstra(int s){
    priority_queue<P,vector<P>,greater<P>> que;
    fill(d,d+V+1,INF);
    fill(pre,pre+V+1,-1);
    d[s]=0;
    que.push(P(0,s));
    while(!que.empty()){
        P p=que.top();que.pop();
        int v=p.second;
        if(d[v]<p.first) continue;
        rep(i,G[v].size()){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost) d[e.to]=d[v]+e.cost,que.push(P(d[e.to],e.to)),pre[e.to]=v;
        }
    }
}
vector<int> get_path(int t){
    vector<int> path;
    for(;t!=-1;t=pre[t]) path.push_back(t);
    reverse(all(path));
    return path;
}
int main(){
    int n,m,A[2000],B[2000];
    vector<int> ans;
    cin>>n>>m;
    V=n+1;
    rep(i,m) cin>>A[i]>>B[i];
    rep(i,n){
        rep(j,n+1) G[j].clear();
        rep(j,m){
            G[A[j]].push_back({B[j],1});
            if(B[j]==i+1) G[A[j]].push_back({0,1});
        }
        dijkstra(i+1);
        if(d[0]!=INF){
            if(get_path(0).size()<ans.size()||ans.size()==0) ans=get_path(0);
        }
    }
    if(ans.size()==0) cout<<-1<<"\n";
    else{
        cout<<ans.size()-1<<"\n";
        rep(i,ans.size()-1) cout<<ans[i]<<"\n";
    }
}

Measured memory_bytes: 4992
n, x = map(int, input().split())
a = [int(s) for s in input().split()]
count = 0

a.sort()
for i in range(n):
    if x >= a[i] and i < n - 1:
        x -= a[i]
        count += 1
    elif x == a[i] and i == n - 1:
        count += 1
print(count)

Measured memory_bytes: 9124
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  cout << max(C-(A-B), 0) << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _81
{
	class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());

			string ans = "No";

			for (int i = 0; i < 10; i++)
			{
				for (int j = 0; j < 10; j ++)
				{
					if (n == i * j)
					{
						ans = "Yes";
						break;
					}
				}
			}
			Console.WriteLine(ans);
			Console.ReadKey(true);
		}
	}
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int k;
int nzd(int x, int y) {
    if(y==0) return x;
    return nzd(y, x%y);
}
ll suma;
int main() {
    IOS; cin >> k;
    for(int i=1; i<=k; ++i) {
        for(int j=1; j<=k; ++j) {
            for(int l=1; l<=k; ++l) {
                suma += (ll)(nzd(nzd(i, j), l));
            }
        }
    }
    cout << suma;
    return 0;
}


Measured memory_bytes: 3660
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

int main() {
	int a, b, c,n;
	cin >> a >> b >> c;

	if (a <= b) {
		if (b <= c) {
			n = c * 10 + a + b;
		}
		else {
			n = b * 10 + a + c;
		}
	}
	else {
		if (a <= c) {
			n = c * 10 + a + b;
		}
		else {
			n = a * 10 + c + b;
		}
	}

	cout << n;
	return 0;
}

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

int main() {
  int H,W;
  cin >> H >> W;
  vector<string> a(H);
  rep(i,W+2){
  cout << "#";
  }
  cout << endl;
  rep(i,H){
   cin >> a.at(i);
   a.at(i).push_back('#');
   cout << "#" << a.at(i) << endl;
  }
   rep(i,W+2){
  cout << "#";
  }
  

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

struct RollingHash {
    using T = long long;
    using hash_type = pair<T, T>;
    const T mod1 = 1000000007, mod2 = 1000000009;
    int base1, base2;
    vector<T> hash1, hash2, pow1, pow2;

    RollingHash(const string &s){
        int n = s.size();
        std::random_device rnd;     // 非決定的な乱数生成器を生成
        std::mt19937 mt(rnd());
        base1 = mt()%(mod1-2)+2;
        base2 = mt()%(mod2-2)+2;

        hash1.assign(n+1,0);
        hash2.assign(n+1,0);
        pow1.assign(n+1,1);
        pow2.assign(n+1,1);
        for(int i=0; i<n; i++){
            hash1[i+1] = (hash1[i]*base1+s[i])%mod1;
            hash2[i+1] = (hash2[i]*base2+s[i])%mod2;
            pow1[i+1]=pow1[i]*base1%mod1;
            pow2[i+1]=pow2[i]*base2%mod2;
        }
    }

    hash_type get(int l,int r){
        T res1 = ((hash1[r] - hash1[l]*pow1[r-l]) % mod1 + mod1) % mod1;
        T res2 = ((hash2[r] - hash2[l]*pow2[r-l]) % mod2 + mod2) % mod2;
        return make_pair(res1, res2);
    }

    hash_type concat(hash_type h1, hash_type h2, int h2len) {
        T res1 = (h1.first*pow1[h2len] + h2.first) % mod1;
        T res2 = (h1.second*pow2[h2len] + h2.second) % mod2;
        return make_pair(res1, res2);
    }
};

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

    RollingHash rh(s);

    int ok = 0, ng = s.size()+1;
    while (abs(ok - ng) > 1) {
        LL mid = (ok + ng) / 2;
        bool f = 0;
        map<RollingHash::hash_type, int> mp;
        for(int i=0; i+mid<=s.size(); i++){
            auto tmp = rh.get(i, i+mid);
            if(mp.count(tmp)){
                if(i-mp[tmp] >= mid){
                    f = 1;
                    break;
                }
            }
            else mp[tmp] = i;
        }
        if(f) ok = mid;
        else ng = mid;
    }

    cout << ok << endl;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=3e4+7;
int dp[maxn],a[maxn];
vector<int> vec[20];
const int mod=1e9+7;
int main()
{
	int n;cin>>n;string s;cin>>s;int len=s.length();
	memset(dp,0,sizeof dp);
	for(int i=1;i<=n;i++) a[i]=(s[i-1]-'0'),vec[a[i]].push_back(i);
	for(int i=0;i<=9;i++)
	{
		if(vec[i].size()==0) continue;
		int pos_i=vec[i][0];
		for(int j=0;j<=9;j++)
		{
			if(lower_bound(vec[j].begin(),vec[j].end(),pos_i+1)==vec[j].end()) continue;
			int pos_j=lower_bound(vec[j].begin(),vec[j].end(),pos_i+1)-vec[j].begin();
			pos_j=vec[j][pos_j];
			for(int k=0;k<=9;k++)
			{
				if(lower_bound(vec[k].begin(),vec[k].end(),pos_j+1)==vec[k].end()) continue;
				//cout<<i<<" "<<j<<" "<<k<<endl;
				dp[i*100+j*10+k]=1;
			}
		}
	}
	int ans=0;
	for(int i=0;i<=999;i++) if(dp[i]) ans++;
	cout<<ans<<endl;
	return 0;
 } 
 /*

*/

Measured memory_bytes: 768
#include <bits/stdc++.h>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef int64_t Int;
const double pi = M_PI;

int main()
{
    int n, ans = INT_MAX;
    cin >> n;
    int x[n];
    for (Int i = 0; i < n; i++)
    {
        cin >> x[i];
    }

    for (int p = 0; p < 100 + 1; p++)
    {
        int temp = 0;
        for (int i = 0; i < n; i++)
        {
            temp += (x[i] - p) * (x[i] - p);
        }
        if (temp <= ans)
        {
            ans = temp;
        }
    }

    cout << ans << endl;
}


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

int main() {
	int h, w;
	cin >> h >> w;

	string pixel;
	for (int i = 0; i < w+2; i++) cout << '#';
	cout << endl;
	for (int i = 0; i < h; i++)
	{
		cin >> pixel;
		cout << '#' << pixel << '#' << endl;
	}
	for (int i = 0; i < w+2; i++) cout << '#';
	cout << endl;

}


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

using namespace std;
typedef long long ll;
ll par[200010],ran[200010];
void init(int n){
	for(int i=0;i<=2*n;i++){
		par[i] = i;
		ran[i] = i;
	}
}

ll find(ll x){
	if(par[x]==x) return x;
	else return par[x] = find(par[x]);
}

void unite(ll x, ll y){
	x = find(x); y = find(y);
	if(x==y) return;
	if(ran[x]<ran[y]){
		par[x] = y;
	}else{
		par[y] = x;
		if(ran[x]==ran[y]) ran[x]++;
	}
}

bool same(ll x, ll y){
	return find(x)==find(y);
}

struct edge{ll u,v,cost;};
ll n,m,k,c[100010];
vector<edge> E;
bool comp(const edge& e1, const edge& e2){
	return e1.cost<e2.cost;
}

ll kruscal(){
	sort(E.begin(),E.end(),comp);
	init(n);
	ll res = 0;
	int cnt = 0,j = k + 1;
	for(int i=0;i<E.size();i++){
		edge e = E[i];
		if(c[e.u]==0){
			c[e.u] = j; j++;
		}
		if(c[e.v]==0){
			c[e.v] = j; j++;
		}
		if(!(same(c[e.u],c[e.v]))){
			unite(c[e.u],c[e.v]);
			res += e.cost;
			cnt++;
		}
		if(cnt==k-1) return res;
	}
	return -1;
}

int main(){
	cin >> n >> m >> k;
	int i;
	for(i=1;i<=n;i++){
		cin >> c[i];
	}
	for(i=0;i<m;i++){
		ll a,b,w;
		cin >> a >> b >> w;
		E.push_back({a,b,w});
	}
	cout << kruscal() << endl;
}

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

int main() {
 int N;
 cin >> N;
 for (int i = 0; i < N; i++){
     string S;
     cin >> S;
     if (S == "Y"){
         cout << "Four" << endl;
         break;
     }
     else if (i == (N - 1)){
         cout << "Three" << endl;
     }
 }
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

const int N=201000;
int stk[N],top,a[N],l[N],r[N],sz[N],rt[N],n,u;
ll ret;
void build() {
	int top=0;
	rep(i,1,n+1) {
		int k=top;
		while (k>0&&a[stk[k-1]]>a[i]) --k;
		if (k) r[stk[k-1]]=i;
		if (k<top) l[i]=stk[k];
		stk[k++]=i;
		top=k;
	}
	rep(i,1,n+1) rt[i]=1;
	rep(i,1,n+1) rt[l[i]]=0,rt[r[i]]=0;
	rep(i,1,n+1) if (rt[i]) u=i;
}
void dfs(int u) {
	sz[u]=1;
	if (l[u]) dfs(l[u]),sz[u]+=sz[l[u]];
	if (r[u]) dfs(r[u]),sz[u]+=sz[r[u]];
	ret+=(ll)a[u]*(sz[l[u]]+1)*(sz[r[u]]+1);
}
int main() {
	scanf("%d",&n);
	rep(i,1,n+1) scanf("%d",a+i);
	build();
	dfs(u);
	printf("%lld\n",ret);
}


Measured memory_bytes: 7168
#include <iostream>
#include <string>
using namespace std;
string str;

int main() {
    while (cin >> str) {
        int nump=0;
        int ans=0;
        for (int i = 0; i < str.size(); ++i) {
            if(str[i]=='g'){
                if(nump>=1){
                    nump--;
                    ans++;
                } else{
                    nump++;
                }
            } else{
                if(nump>=1){
                    nump--;
                } else{
                    ans--;
                    nump++;
                }
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 512
import java.util.*;
import java.io.*;
class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int H = sc.nextInt();
        int N = sc.nextInt();
        int[] a = new int[N];
        for(int i = 0; i<N; i++) {
            a[i] = sc.nextInt();
            H -=a[i];
        }
        if(H<=0) p("Yes");
        else p("No");
    }
    public static <T> void p(T element) {
	System.out.println(element);
    }
    public static int min(int a, int b, int c) {
	int min = Math.min(a,b);
	min = Math.min(min,c);
	return min;
    }
    public static int max(int a, int b,int c) {
	int max= Math.max(a,b);
	max = Math.max(max,c);
        return max;
    }
}
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
 
    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }
 
    private boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
 
    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }
 
    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
 
    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
 
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
 
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 22356
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  cout << a*b/2 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void)
{
  char S[1000];
  int i,w,len;
  scanf("%s", S);
  scanf("%d", &w);
  len = strlen(S);
  i=0;
  while (i<len) {
    printf("%c", S[i]);
    i += w;
  }
  /*
  for(i=0;i=i+w;i<=len){
      printf("%c", S[i]);
  }*/
  return 0;
}


Measured memory_bytes: 128
a, b, c, x = readlines.map(&:chomp).map(&:to_i)
n = 0
(0..a).each do |a|
    (0..b).each do |b|
        (0..c.to_i).each do |c|
         n += 1 if a*500 + b*100 + c* 50 == x
        end
    end
end
p n

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

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define mp make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define MOD 1000000007

int main(){
  int a,b;
  cin >> a >> b;
  cout << a*b <<" " <<2*(a+b) <<endl;
  return 0;
}



Measured memory_bytes: 3072
#include<cstdio>
#include<cstdlib>
#include<map>
using namespace std;
int m,n,i,j;
#define maxn 200010
long long a[maxn],sum[maxn],k,ans;
map<long long,long long>mp;
int main()
{
	scanf("%d%lld",&n,&k);
	for(i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		sum[i]=sum[i-1]+a[i];
	}
	for(i=n;i>=1;i--)
	{
		mp[(sum[i]-i)%k]++;
		if(n-i+1>=k)
		{
			int p=i+k-1;
			mp[(sum[p]-p)%k]--;
		}
		ans+=mp[(sum[i-1]-i+1)%k];
	}

	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
 
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,K,Q;
    ll ans = 1e10;
    cin >> N >> K >> Q;
    vector<ll> A(N);
    REP(i,N){
        cin >> A[i];
    }

    REP(i,N){
        ll Y = A[i];
        vector<ll> con;
        vector<ll> C;

        REP(j,N+1){
            if (A[j] >= Y and j < N){
                C.PB(A[j]);
            }else{
                int M = C.size();
                sort(ALL(C));
                if (M < K){
                    C.clear();
                    continue;
                }

                REP(k,M-K+1){
                    con.PB(C[k]);
                }
                C.clear();
            }


        }

        sort(ALL(con));
        if (con.size() >= Q) {
            chmin(ans, con[Q - 1] - con[0]);
        }

    }

    cout << ans << endl;

}






Measured memory_bytes: 256