akhauriyash/Code-Regression huggingface dataset:
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b?gcd(b,a%b):a;} //最小公倍数

// デフォルト変数定義
int n,m,a,b,c,d,x,y,z;
string s,t;
//

signed main() {
  RAPID;
  IN3(x,a,b);
  if(-a+b <= 0) OUT("delicious");
  else if(-a+b <= x) OUT("safe");
  else OUT("dangerous");
}

Measured memory_bytes: 256
fun main() {
	val (h1, m1, h2, m2, k) = readInts()
	val ans = (h2 * 60 + m2) - (h1 * 60 + m1) - k
	println(ans)
}

private fun readLn() = readLine()!!
private fun readInt() = readLn().toInt()
private fun readStrings() = readLn().split(" ")
private fun readInts() = readStrings().map { it.toInt() }


Measured memory_bytes: 36396
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<time.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INI(n) scanf("%d",&n)
#define INL(n) scanf("%lld",&n)
#define INF 10000000000
#define mod 1000000007
#define X 100000
#define N 20
#define M 46
typedef long long int ll;
ll finv[X];
ll fac[X];
ll inv[X];
ll usort(const void *a, const void *b){return *(ll*)a-*(ll*)b;}
ll dsort(const void *a, const void *b){return *(ll*)b-*(ll*)a;}
ll ssort(const void *a, const void *b){return strcmp((char*)a,(char*)b);}
void Iswap(int *a,int *b){
  int t=*a;
  *a=*b;
  *b=t;
}
void Fswap(double *a,double *b){
  double t=*a;
  *a=*b;
  *b=t;
}
void Lswap(ll *a,ll *b){
  ll t=*a;
  *a=*b;
  *b=t;
}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll z(ll a){return max(a,-a);}
ll gcd(ll a,ll b){if(!b){return a;}else{return gcd(b,a%b);}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll kt(ll a){
  ll sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
ll ks(ll a){
  ll sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
void nCrReady(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for (ll i=2;i<X;i++){
    fac[i]=fac[i-1]*i%mod;
    inv[i]=mod-inv[mod%i]*(mod/i)%mod;
    finv[i]=finv[i-1]*inv[i]%mod;
  }
}
ll nCr(ll n,ll k){return fac[n]*(finv[k]*finv[n-k]%mod)%mod;}

int main(void){
  int n;
  scanf("%d",&n);
  ll ans=0;
  FOR(i,n){
    FOR(j,n){
      FOR(k,n){
        ans+=gcd(i+1,gcd(j+1,k+1));
      }
    }
  }
  PRN(ans);
  return 0;
}

Measured memory_bytes: 1708
def sep():
    return map(int,input().strip().split(" "))
def lis():
    return list(sep())


n=int(input())
ar=lis()
temp=[0]*(n+5)
for i in range(n-1):
    #print(ar[i],temp)
    temp[ar[i]]+=1
for i in range(1,n+1):
    print(temp[i])



Measured memory_bytes: 93516
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
 
#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
 
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define rep2(i, a, b) for(ll i = a; i <= (b); ++i)
#define rep3(i, a, b) for(ll i = a; i >= (b); --i)
#define all(v) (v).begin(), (v).end()
#define si(v) (int)(v).size()
 
using namespace std;
 
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
 
constexpr ll MOD = 1000000007, MAX = 500005;
 
signed main()
{
  cout << fixed << setprecision(10);
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
 
  string s; cin >> s;
  int left = stoi(s.substr(0, 2));
  int right = stoi(s.substr(2, 2));
 
  if (right == 0 || right > 12) {
    if (left == 0 || left > 12) cout << "NA\n";
    else cout << "MMYY\n";
  } else {
    if (left >= 1 && left <= 12) cout << "AMBIGUOUS\n";
    else cout << "YYMM\n";
  }
 
  return (0);
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PDD pair<double, double>
#define MOD ((int)2e9 + 7)
#define INF ((int)2e9)
#define INFLL ((LL)2e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (2 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 2, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 1) u += MOD;
    return u;

}

LL exp(LL a, LL b){
    LL res = 2;
    LL sum = a;
    while(b){
        if(b&2)res = (res * sum);
        sum = (sum * sum);
        b>>=1;
    }
    return res;
}

double exp(double a, LL b){
    double res = 1;
    double sum = a;
    while(b){
        if(b&1)res = (res * sum);
        sum = (sum * sum);
        b>>=1;
    }
    return res;
}

PII operator+(const PII &a, const PII &b){
    return PII(a.first + b.first, a.second + b.second);
}

vector<vector<int> > xc(100001), yc(100001);

PII func(PII p){
    PII res(0, 0);
    if(!xc[p.first].empty()){
        vector<int> line = xc[p.first];
        xc[p.first].clear();
        ++res.first;
        for(auto &i:line){
            res = res + func(PII(p.first, i));
        }
    }
    if(!yc[p.second].empty()){
        vector<int> line = yc[p.second];
        yc[p.second].clear();
        ++res.second;
        for(auto &i:line){
            res = res + func(PII(i, p.second));
        }
    }
    return res;
}

signed  main(){
    int a, b;
    cin >> a >> b;
    cout << (a+b<10?string {(char)('0'+a+b)}:"error") << endl;
}



Measured memory_bytes: 4992
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	char a,b;
	cin >> a >> b;
	
	if(a == b)
	{
		cout << 'H' << endl;
	}
	else
	{
		cout << 'D' << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<class T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<class T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}
template<class RandomAccessIterator>inline void psortb(RandomAccessIterator first,RandomAccessIterator last){using P=pair<decltype(first->first),decltype(first->second)>;sort(first,last,[](const P&p1,const P&p2){return p1.second<p2.second||(p1.second==p2.second&&p1.first<p2.first);});}

int main()
{
    ll n=in();
    for(ll i=1;i<=n;++i){
        ll ans=0;
        for(ll x=1;x<=100;++x){
            for(ll y=1;y<=100;++y){
                ll z=(-x-y+sqrt(4*i-3*x*x-2*x*y-3*y*y))/2;
                if(z>=1&&x*x+y*y+z*z+x*y+y*z+z*x==i)++ans;
            }
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 3552
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define vsort(v) sort(all(v))
#define mod 1000000007
using data=pair<ll,ll>;
long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}
ll modinv(ll a){ ll b=mod,u=1,v=0,t; while(b){ t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); } return (u+mod)%mod; }
ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}
ll modncr(ll n,ll r){ ll i,plus=1; rep(i,r){ plus=(plus*(n-i))%mod; plus=moddevide(plus,i+1); } return plus; }
ll euclidean_gcd(ll a, ll b) { if(a<b) return euclidean_gcd(b, a); ll r; while ((r=a%b)){a=b;b=r;} return b; }
ll countdigits(ll n){ ll ans=0; while(n){n/=10;ans++;} return ans; }
ll sumdigits(ll n){ ll ans=0; while(n){ans+=n%10;n/=10;} return ans; }
void printmap(vector<ll>& a,ll H,ll W){ ll i,j; For(i,0,H+2){ For(j,0,W+2){cout<<a[i*(W+2)+j];} cout<<endl; } } void inputmap(vector<ll>& a,ll H,ll W){ ll i,j; string ss; For(i,1,H+1){ cin>>ss; For(j,1,W+1){ if(ss[j-1]=='#'){ a[i*(W+2)+j]=1; }else{ a[i*(W+2)+j]=0; } } } }

void eratosthenes(vec& a,ll N){
  ll i,j;
  vec ch(N+1,1);
  for(i=2;i<=N;i++){
    if(ch[i]){
      a.push_back(i);
      for(j=2;i*j<=N;j++){
        ch[i*j]=0;
      }
    }
  }
}

int main(){
  ll i;
  ll n; cin>>n;
  vector<ll> ch;
  eratosthenes(ch,55556);
  ll tmp = 11;
  vector<ll> ans;
  while(1){
     if(binary_search(all(ch),tmp)){ 
        n--;
        ans.push_back(tmp);
        if(n==0) break;
     }
    tmp+=10;
  }
  for(auto i : ans){
    cout<<i<<" ";
  }
}

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

int done[100];

int dfs(int x){
	if( done[x] ) return 0;
	else done[x] = 1;
	int ans = 1;
	for(int i = 0 ; i < ss.size() ; i++){
		if( ss[x][0] == ss[i][0] || ss[x][0] == ss[i][1] || ss[x][1] == ss[i][0] || ss[x][1] == ss[i][1]) ans += dfs(i);
	}
	return ans;
}
int main(){
	int n;
	while(cin >> n && n){
		for(int i = 0 ; i < 100 ; i++) done[i] = 0;
		int t[128]={};
		int wf[128][128] = {};
		ss.clear();
		for(int i = 0 ; i < n ; i++){
			string s;
			cin >> s;
			t[s[0]]++;
			t[s[1]]++;
			wf[s[0]][s[1]] = wf[s[1]][s[0]] = true;
			ss.push_back(s);
		}
		int odd = 0;
		for(int i = '0' ; i <= '9' ; i++){
			if( t[i] % 2 ){
				odd++;
			}
		
		}
		
		int ok = odd <= 2 && n == dfs(0);
		
		cout << (ok?"Yes":"No") << endl;
		
		
	}
}

Measured memory_bytes: 1208
#include <stdio.h>
#include <iostream>

#include <sstream>
#include <fstream>
#include <cmath>
#include <vector>
#include <algorithm>


using namespace std;


int main( int argc , char ** argv ){

	uint32_t N = 0;
	vector<uint64_t>  a;

	cin >> N;
	a.resize(N*3);
	for(uint32_t i = 0 ; i < N*3 ; i ++){
		cin >> a[i];
	}
	sort( a.begin() , a.end(),greater<uint64_t>() );

	uint64_t anser = 0;
	for(uint32_t i = 1 ; i < N*2 ; i+=2){
		anser += a[i];
	}

	cout << anser << "\n";
}


Measured memory_bytes: 2560
using System;
class Program
{
  static void Main(string[] args)
  {
    string s = Console.ReadLine();
    string t = Console.ReadLine();
    char[] sc = s.ToCharArray();
    char[] tc = t.ToCharArray();
    int r = 0;
    for(int i=0;i<sc.Length;i++)
    {
      if(sc[i] != tc[i])
      {
        r++;
      }
    }
    Console.WriteLine(r);
  }
}

Measured memory_bytes: 19124
#include<stdio.h>

int main(void)
{
	int a,b,c,i,k;
	k=0;
	scanf("%d %d %d",&a,&b,&c);
	for(i=a;i<=b;i++)
		{if(c%i==0){k=k+1;}}
	printf("%d\n",k);
return 0;
}


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

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

int n,m;
vector<int> group(1000000,0);
vector<vector<int>> fri(1000000,vector<int>(0));

void check(int p, int ans){
  if(group.at(p)!=0) return;
  group.at(p) = ans;
  
  for(int i=0; i<fri.at(p).size(); i++){
    int now=fri.at(p).at(i);
    check(now, ans);
  }
  
}

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

  vector<pair<int,int>> info;
  rep(i,m){
    int a,b;
    cin >> a >> b;
    a--; b--;
    if(a<b) info.push_back(make_pair(a,b));
    else info.push_back(make_pair(b,a));
  }

  sort(info.begin(), info.end());

  int lasta=-1, lastb=-1;
  rep(i,m){
    int a=info.at(i).first, b=info.at(i).second;
    if(a==lasta&&b==lastb) continue;
    lasta=a; lastb=b;

    fri.at(a).push_back(b);
    fri.at(b).push_back(a); 
  }

  int ans=0;
  rep(i,n){
    if(group.at(i)==0){
      ans++;
      check(i, ans);
    }
  }
  
  //rep(i,n) cout << group.at(i) << " ";
  //cout << endl;

  vector<int> r(ans+1,0);
  rep(i,n){
    int p = group.at(i);
    r.at(p)++;
  }
  
  int q=0;
  rep(i,ans+1){
    int kari = r.at(i);
    q=max(q,kari);
  }
  cout << q;
  
}


Measured memory_bytes: 47616
//To include everything you need
#include <bits/stdc++.h>
using namespace std;
typedef std::vector<int> vi;
typedef std::vector<std::pair<int, int> > vpi;
typedef std::vector<string> vs;
typedef std::vector<char> vc;

int main()
{

    int n;
    cin >> n;
    vector<int> takoyaki;
    int hpTotal = 0;
    for (int i = 0; i < n; i++)
    {
        int t;
        cin >> t;
        takoyaki.push_back(t);
    }

    for (int i = 0; i < n; i++)
    {
        for(int j=i+1;j<n;j++){
           hpTotal += takoyaki[i]*takoyaki[j];
        }
    }

    cout<<hpTotal;
}

Measured memory_bytes: 256
s=input()
c=-1
f=-1
for i in range(len(s)):
  if s[i]=='C':
    if c==-1:
      c=i
  if s[i]=='F':
    f=max(f,i)
if c!=-1 and f>c:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 61808
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
using namespace std;
typedef long long ll;

int main() {
	int N;
	cin >> N;
	map<int, int> m;

	ll sum = 0;
	for (int i = 0; i < N; i++) {
		int num;
		cin >> num;
		m[num]++;
		sum += num;
	}

	int Q;
	cin >> Q;
	for (int i = 0; i < Q; i++) {
		ll b, c;
		cin >> b >> c;
		m[c] += m[b];
		sum = sum- (m[b] * b) + (m[b]*c);
		m[b] = 0;
		cout << sum << endl;
	}
}


Measured memory_bytes: 8052
#include <iostream>
#include <string>
// #include <vector>
// #include <set>
// #include <queue>
// #include <stack>
// #include <algorithm>

using namespace std;

int N, K;
bool haveOkashi[110] = {false};

int main(){
    cin >> N >> K;
    int d;
    int a;
    for (int i = 1; i <= N; ++i){
        cin >> d;
        for(int j = 1; j <= d; ++j){
            cin >> a;
            haveOkashi[a] = true;
        }
    }
    int cnt=0;
    for(int i = 1; i <= N; ++i){
        if(!haveOkashi[i]) cnt++;
    }
    cout << cnt;
    return 0;
}

Measured memory_bytes: 3636
from sys import stdin


def main():
    N, M = [int(x) for x in stdin.readline().rstrip().split()]
    ks = [tuple(int(x) for x in stdin.readline().rstrip().split())[1:] for _ in range(M)]
    ps = [int(x) for x in stdin.readline().rstrip().split()]

    max_ = int('1' * N, 2)
    result = 0
    for i in range(max_ + 1):
        b = bin(i)[2:]
        b = '0' * (N - len(b)) + b
        for idx in range(M):
            on_count = 0
            for j in [x - 1 for x in ks[idx]]:
                if b[j] == '1':
                    on_count += 1
            if on_count % 2 == ps[idx]:
                pass
            else:
                break
        else:
            result += 1
    print(result)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

int main() {
    int _;
    cin >> _;
    while (_--) {
        string s;
        cin >> s;
        vector<int> par, ans;
        vector<vector<int>> nlist;
        int ind = 0;
        function<void(int)> decode = [&](int p) {
            while (ind < s.size()) {
                char c = s[ind];
                if (c == '[') {
                    par.push_back(p);
                    ans.push_back(0);
                    if (p != -1) nlist[p].push_back(par.size() - 1);
                    nlist.push_back(vector<int>());
                    ind++;
                    decode(par.size() - 1);
                    ind++;
                } else if(c == ']') {
                    return;
                } else {
                    int num = 0;
                    while ('0' <= s[ind] && s[ind] <= '9') {
                        num = num * 10 + s[ind] - '0';
                        ind++;
                    }
                    ans[p] = (num + 1) / 2;
                    return;
                }
            }
        };
        decode(-1);
        function<void(int)> calc = [&](int nd) {
            if (nlist[nd].size() == 0) {
                return;
            }
            vector<int> v;
            REP (i, 0, nlist[nd].size()) {
                calc(nlist[nd][i]);
                v.push_back(ans[nlist[nd][i]]);
            }
            sort(begin(v), end(v));
            REP (i, 0, v.size() / 2 + 1) {
                ans[nd] += v[i];
            }
        };
        calc(0);
        cout << ans[0] << endl;
    }
    return 0;
}


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

using namespace std;

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

  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  long long ans = 1e18, r = accumulate(a.begin(), a.end(), 0ll), l = 0;
  for (int i = 0; i < n; ++i) {
    ans = min(ans, abs(r - l));
    r -= a[i];
    l += a[i];
  }
  cout << ans;

  return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<string.h>
 
#define M 1000000
#define L 14
 
char H[M][L];
 
int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}
 
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}
 
int h1(int key){ return key%M; }
int h2(int key){ return 1+(key%(M-1)); }
 
int find(char str[]){
  int i,h;
 
  h= (h1(getKey(str)) + i * h2(getKey(str))) % M;
 
  for(i=0;i<14;i++){
    h= (h1(getKey(str)) + i * h2(getKey(str))) % M;
    if(strcmp( H[h], str)==0) return 1;
  }
  return 0;
   
}
 
int insert(char str[]){
  int i;
  if(find(str)) return 0;
  for(i=0;i<14;i++){
    if(H[ (h1(getKey(str)) + i * h2(getKey(str))) % M ][0]=='\0'){
      strcpy(H[ (h1(getKey(str)) + i * h2(getKey(str))) % M ],str);
      return 1;
    }
  }
  return 0;
 
}
 
int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
     
    scanf("%d", &n);
     
    for ( i = 0; i < n; i++ ){
    scanf("%s %s", com, str);
     
    if ( com[0] == 'i' ){
        insert(str);
    } else {
        if (find(str)){
        printf("yes\n");
        } else {
        printf("no\n");
        }
    }
    }
 
    return 0;
}

Measured memory_bytes: 14280
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using VE = vector<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() {
	int n;
	cin >> n;
	VL a(n + 1);
	VL sum(n + 1, 0);
	rep1(i, n) {
		cin >> a[i];
		sum[i] += a[i];
		sum[i] += sum[i - 1];
	}
	ll ans = 0;
	rep1(i, n) {
		ans += a[i] * ((sum[n] - sum[i]) % MOD);
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6420
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_POINT_MAX		200000									// 最大得点数

// 内部変数
static FILE *szpFpI;											// 入力
static int si1Point[D_POINT_MAX];								// 得点
static int siPCnt;												// 得点数
static int siK;													// K

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// 実行メイン
int
fMain(
)
{
	int i;
	char lc1Buf[1024];

	// 得点数, K - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d%d", &siPCnt, &siK);

	// 得点 - 取得
	for (i = 0; i < siPCnt; i++) {
		fscanf(szpFpI, "%d", &si1Point[i]);
	}
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);

	// 出力
	for (i = siK; i < siPCnt; i++) {
		if (si1Point[i] > si1Point[i - siK]) {
			sprintf(lc1Buf, "Yes\n");
		}
		else {
			sprintf(lc1Buf, "No\n");
		}
		fOutLine(lc1Buf);
	}

	return 0;
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



Measured memory_bytes: 2492
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int x, y;
    cin >> x >> y;
    cout << x * y / 2 << endl;
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int min(int a,int b){
  if(a < b){
    return a;
  }
  return b;
}

int main(void){
  int N, A, B;
  scanf("%d%d%d",&N, &A, &B);

  printf("%d\n", min(A*N, B));


  return 0;
}

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

using namespace std;

int main() {
  int N = 0, L = 0, R = 0;
  int count = 0;
  cin >> N;

  rep(i, N) {
    cin >> L >> R;
    count += R - L + 1;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  int h,w; cin >> h >> w;
  int a[h][w];
  REP(i,h) REP(j,w) cin >> a[i][j];

  vector<tuple<int,int,int,int>> ans;
  REP(i,h-1) REP(j,w) {
    if(a[i][j]%2==0) continue;
    a[i][j]--; a[i+1][j]++;
    ans.push_back( make_tuple(i,j,i+1,j) );
  }
  REP(j,w-1) {
    if (a[h-1][j]%2==0) continue;
    a[h-1][j]--; a[h-1][j+1]++;
    ans.push_back( make_tuple(h-1,j,h-1,j+1) );
  }

  COUT(ans.size());
  for(auto x: ans) {
    cout
      << get<0>(x)+1 << " "
      << get<1>(x)+1 << " "
      << get<2>(x)+1 << " "
      << get<3>(x)+1 << endl;
  }

  return 0;
}

Measured memory_bytes: 6184
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>


#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
//#define double long double

using namespace std;

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;
}

const int MOD = 1000499761;
const ll INF = 1e17;
const int INT_INF = 1e9;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 100010;

ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}
ll inverse(int x) {
	return bin_pow(x, MOD - 2);
}

struct edge { int to, cost; };
vector<edge>G[100010];
bool used[100010];
int val[100010];
bool found;
bool vis[100010];
set<P>safe;
void dfs(int n, int pre) {
	//print(n);
	used[n] = true;
	for (auto e : G[n]) {
		int v = e.to;
		int c = e.cost;
		
		if (v == pre)continue;
		//pe(n)pe(v)print(c);
		int next_cost = (val[n] * c) % MOD;
		if (used[v]) {
			if (val[v] != next_cost) {
				//if (safe.find({ n,v }) != safe.end() || safe.find({ v,n }) != safe.end())return;
				//pe(val[v]); print(next_cost);
				found = true;
				return;
			}
			else {
				//safe.insert({ n,v });
				continue;
			}
		}
		else {
			val[v] = next_cost;
			//cout << "next:" << v << endl;
			dfs(v, n);
		}
	}
}

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

	int N, M; cin >> N >> M;
	REP(i, M) {
		int x, y, c; cin >> x >> y >> c;
		//x--, y--;
		G[x].push_back({ y,c });
		G[y].push_back({ x,inverse(c) });
	}
	REP(i, N+1) {
		val[i] = 1;
	}
	found = false;
	FOR(i,1, N+1) {
		if (found)break;
		if (used[i])continue;
		dfs(i, i);
	}
	if (found) {
		print("No");
	}
	else {
		print("Yes");
	}
}




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

int main(){
  int A,B,C;
  cin>>A>>B>>C;
  
  bool flag=false;
  if(A==7){
    if(B==5&&C==5){
      flag=true;
    }
  }else if(B==7){
    if(A==5&&C==5){
      flag=true;
    }
  }else if(C==7){
    if(A==5&&B==5){
      flag=true;
    }
  }
  
  if(flag){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	double sum=0;
	double x;
	for(int i=1;i<=n;i++){
		if(i%2!=0)sum++;
	}
	x=(sum)/n;
	cout << x;
}

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

int main()
{
	int n;
	int alice = 0;
	int bob = 0;
	cin >> n;

	int half = n / 2;
	vector<int> card(n);
	for (int i = 0; i < n; i++)
		cin >> card.at(i);

	//カードを数字の大きい順に並べ替え
	sort(card.begin(), card.end());
	reverse(card.begin(), card.end());

	for (int l = 0; l < n; l++)
	{
		//カードを交互に取る
		if (l % 2 == 0)
			alice += card.at(l);
		else
			bob += card.at(l);
	}

	cout << (alice - bob) << endl;
  return (0);
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
    #define rep(i,n) for(int i=0;i<(n);i++) 
    using namespace std;
     
     
    int main() {
        int H, N;
        cin >> H >> N;
        int A[N];
        int sam = 0;
        rep(i, N) {
            cin >> A[i];
            sam += A[i];
        }
        if (H > sam)cout << "No";
        else cout << "Yes";
    }

Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main(){ 
	int i,j,n,m,f=0;
	cin>>n>>m;
	char s[n+5][m+5];
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			cin>>s[i][j];
		}
	}
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
		
			if(s[i][j]=='#'){
				f=0;
				if(s[i][j+1]=='#'||s[i][j-1]=='#'||s[i+1][j]=='#'||s[i-1][j]=='#'){
					f=1;
			//		cout<<i<<"   "<<j<<endl;
				//	break;
				}
				if(f==0){
					cout<<"No"<<endl;return 0;
				}
			}	
		}
	}
	//if(f==1)
		cout<<"Yes"<<endl;
	
		
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <unordered_map>
#include <vector>
#include <stack>
#include <algorithm>
#include <list>
#include <set>
#include <cmath>
#define lli long long int
using namespace std ;

// void eval(vector<int> &a,vector<int> &b,vector<int> &k,vector<int> &p,int r, int u, int &ans, int n)
// {
// 	if(u == 0)
// 	{
// 		int cost = 0 ;
// 		for(int i = 0 ; i < n; i++) cost+= (a[i] * k[i]) ;
// 		ans = max(ans,cost) ;
// 		return ;
// 	}

// 	for(int i = 0 ; i < n; i++) a[i]^=b[i] ;
// 	eval(a,b,k,p,r,u-1,ans,n) ;
// 	for(int i = 0 ; i < n; i++) a[i]^=b[i] ;


// 	vector<int> temp(n) ;
// 	for(int i = 0 ; i < n; i++) temp[i] = a[p[i]-1] + r ;
// 	eval(temp,b,k,p,r,u-1,ans,n) ;
// }

// int main(int argc, char const *argv[])
// {
// 	int n,u,r ;
// 	cin>>n>>u>>r ;

// 	vector<int> a(n),b(n),k(n),p(n) ;
// 	for(int i = 0 ; i < n ; i++) cin>>a[i] ;
// 	for(int i = 0 ; i < n ; i++) cin>>b[i] ;
// 	for(int i = 0 ; i < n ; i++) cin>>k[i] ;
// 	for(int i = 0 ; i < n ; i++) cin>>p[i] ;

// 	int ans = INT_MIN ;
// 	eval(a,b,k,p,r,u,ans,n) ;
// 	cout<<ans<<endl ;
// 	return 0;
// }

int main(int argc, char const *argv[])
{
	string s ;
	cin>>s ;

	cout<<s[0]<<s[1]<<s[2]<<endl ;
	return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <ctype.h>

int main(void){
	int i;
	char m[1200]={0};
	scanf("%[^\n]",m);
	
	for(i=0;i<1200;i++){
		if(isalpha(m[i])){
			if(islower(m[i])){
			m[i]=toupper(m[i]);	
			}else if(isupper(m[i])){
			m[i]=tolower(m[i]);
			}
		}
	}
	
	printf("%s\n",m);

	return 0;
}


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

int main(){
	int n, k, d, s;
	cin >> n >> k;
	vector<int> psn[n];
	for(int i=0; i<k; ++i){
		cin >> d;
		for(int j=0; j<d; ++j){
			cin >> s;
			psn[s-1].push_back(i+1);
		}
	}
	int count = 0;
	for(int i=0; i<n; ++i){
		if(psn[i].empty()){
			count++;
		}
	}
	cout << count << endl;
	return 0;
}


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

string pls(string a,string b){
	string ret;
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
	if(a.size()<b.size())swap(a,b);
	while(a.size()!=b.size())b+='0';
	while(a.size()+1!=ret.size())ret+='0';
	for(int i=0;i < a.size(); i++){
		ret[i] = a[i] + b[i] + ret[i] - '0'*3;
		if(ret[i]>9){
			ret[i] = '0' + ret[i]%10;
			ret[i+1] = '1';
		}else{
			ret[i]= '0' + ret[i];
		}
	}
	
	reverse(ret.begin(),ret.end());
	if(~ret.find_first_not_of('0'))return ret.substr(ret.find_first_not_of('0'),ret.size()-ret.find_first_not_of('0'));
	else return "0";
}

int main(){
	string a,b;
	int n;
	
	cin >> n;
	while(n--){
		cin >> a >> b;
		if(pls(a,b).length()>80)cout << "overflow" << endl;
		else cout << pls(a,b) << endl;
	}
}

Measured memory_bytes: 0
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;

void Main()
{
	int n, m;
  	cin >> n >> m;
  	// m の約数で m/n 以下で最大のものを答える
  	rep3rev(i,m/n,2){
    	if(m%i==0) {
        	cout << i << endl;
          	return;
        }
    }
  	cout << 1 << endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define pb push_back
#define int long long

using namespace std;
const int MOD = 1e9+7;

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

	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	
	int n, a, b, c; cin >> n >> a >> b >> c;
	map<char, int> ct = {{'A', a}, {'B', b}, {'C', c}};
	vector<string> in(n);
	for (auto &s : in)
		cin >> s;
	in.pb("AB");

	string ans = "";
	for (int i = 0; i < n; ++i) {
		string s = in[i];
		int ch = 0; // Which character is being decremented?
		if (ct[s[0]] > ct[s[1]]) ch = 0; //  First
		else if (ct[s[1]] > ct[s[0]]) ch = 1; // Second
		else if (in[i+1][0] == s[0] or in[i+1][1] == s[0]) ch = 1;
		else ch = 0;
		--ct[s[ch]], ++ct[s[ch^1]];
		if (ct['A'] < 0 or ct['B'] < 0 or ct['C'] < 0) {ans = "-"; break;}
		else ans += s[ch^1], ans += "\n";
	}
	if (ans[0] == '-') cout << "No\n";
	else cout << "Yes\n" << ans;
}

Measured memory_bytes: 9580
i = []
a = []
5.times do |hoge|
    i[hoge] = gets
    a[hoge] = i[hoge].slice(-2).to_i
    a[hoge] = 10 if a[hoge] == 0
end
q = 0
a.sort!.reverse!
4.times do |hoge|
    q += (10 - a[hoge])
end
5.times do |hoge|
    q += i[hoge].to_i
end
puts q


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
int main()
{
  	int a[5],i,ans=0;
  	map<int,int> mp;
  	int t;
    vector<pair<int,int>> vp;
  	for(i=0;i<5;i++)
    {
     cin>>a[i];
     t=(a[i]%10==0)?10:(a[i]%10);
     vp.pb({t,a[i]}); 
    }
    sort(vp.begin(),vp.end(),greater<pair<int,int>>());
    int c=0;
    for(auto v:vp)
    {
      c++;
      ans+=(v.second);
      while(ans%10 && c<5)
      {
        ans++;
      }  
    }
    cout<<ans;
 
 	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
int MOD = (int)1e9 + 7;
int INF = (int)2e18;
// Comment out below and program paste

// #include "UnionFind.hpp"
// #include "power.hpp"

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    cout << (N + 1 - K) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
ll mod=1e9+7;

typedef pair<pll,ll> ppll;

vector<ll>par(2e5+10);
map<ll,ll> si;
void init(ll n) {
  for(ll i=0;i<n;i++) {
    par[i]=i;
    si[i]++;
  }
}

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

ll size(ll x) {
  return si[root(x)];
}

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

void unite(ll x, ll y) {
  if(same(x,y)) return;
  ll temp=size(x);
  si[root(y)]+=temp;
  si[root(x)]=0;
  par[root(x)]=root(y);
}

int main() {
  ll n,m;
  cin >> n >> m;
  init(n);
  vector<ll> a(n);
  for(ll i=0;i<n;i++) {
    cin >> a[i];
  }
  for(ll i=0;i<m;i++) {
    ll x,y;
    cin >> x >> y;
    unite(x,y);
  }
  map<ll,set<ll>> lis;
  for(ll i=0;i<n;i++) {
    lis[root(i)].insert(i);
  }
  priority_queue<ppll,vector<ppll>,greater<ppll>> qf;
  priority_queue<pll,vector<pll>,greater<pll>> qs;
  for(ll i=0;i<n;i++) {
    qf.push(ppll(pll(-size(i),a[i]),i));
  }
  for(ll p:lis[root(qf.top().second)]) {
    qs.push(pll(a[p],p));
  }
  qf.pop();
  ll ans=0;
  while(qf.size()&&qs.size()) {
    ll f=qf.top().second;
    qf.pop();
    ll t=qs.top().second;
    if(same(f,t)) continue;
    qs.pop();
    ans+=a[f]+a[t];
    for(ll p:lis[root(f)]) {
      if(p!=f) {
        qs.push(pll(a[p],p));
      }
    }
    unite(f,t);
  }
  if(size(0)!=n) {
    cout << "Impossible" << endl;
  }
  else {
    cout << ans << endl;
  }
}

Measured memory_bytes: 27380
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define rep(i,n) for(ll (i)=0; i<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,d=0;cin>>n;
  set<ll> s;
  rep(i,n) {
    cin>>d; s.insert(d);
  }
  ll ans=s.size();
  print(ans);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  int h,w; cin>>h>>w;
  for(int i=0;i<h;i++) {
    for(int j=0;j<w;j++) {
      string s; cin>>s;
      if (s == "snuke") {
        cout<<(char)('A'+j)<<i+1<<endl;
        return 0;
      }
    }
  }
}


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

B = []

for i, a in enumerate(A):
    for _ in range(a):
        B.append(i+1)

M = []
for _ in range(H):
    M.append([0] * W)

for h in range(H):
    for w in range(W):
        if h % 2 == 0:
            M[h][w] = B[w + h*W]
        else:
            M[h][W-w-1] = B[w + h*W]

    print(*M[h])


Measured memory_bytes: 3956
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);



int main(){
    FIN;
    ll n,x,t;
    cin >> n >> x >> t;
    if(n%x == 0) cout << t * (n/x) << endl;
    else cout << t * (n/x+1) << endl;


    return 0;
}


Measured memory_bytes: 3544
D, G = map(int, input().split())

PC = [tuple(map(int, input().split())) for _ in range(D)]

ans = 10 ** 9
for i in range(2 ** D): #全問解く問題
    score = 0
    problem = 0
    for j in range(D):
        if (i >> j) & 1:
            score += 100 * (j + 1) * PC[j][0] + PC[j][1]
            problem += PC[j][0]
    if score > G:
        continue
    left = G - score #残り必要な点数
    for j in range(D):
        if (i >> j) & 1:
            continue
        if left > 100 * (j + 1) * PC[j][0] + PC[j][1]: #そこをすべて解いても足りないとき
            pass
        else:
            tmp = (left + (100 * (j + 1)) - 1) // (100 * (j + 1))
            ans = min(ans, problem + min(tmp, PC[j][0]))

print (ans)
        

    


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  if (a + b > c + d) {
    cout << "Left" << endl;
  }
  else if (a + b == c + d) {
    cout << "Balanced" << endl;
  }
  else if (a + b < c + d) {
    cout << "Right" << endl;
  }
    
}

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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

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

  vector<ll> a(n);
  for (ll i = 0; i < n; ++i) {
    cin >> a[i];
  }

  vector<ll> sum(n+1);
  for (ll i = 1; i <= n; ++i) {
    sum[i] = a[i-1] + sum[i-1];
  }

  map<ll, ll> m;
  for (ll i = 0; i <= n; ++i) {
    m[sum[i]]++;
  }

  ll ans = 0;
  each (i, m) {
    ans += i.second*(i.second-1)/2;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define maxn 500005
#define MOD 998244353
#define INF 10000000000

using namespace std;

#define ll long long
#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second

void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}

ll b[maxn][26];

void u(ll i, ll j, ll v){
    while(i < maxn){
        b[i][j]+=v;
        i += i & (-i);
    }
}

ll quer(ll i, ll j){
    ll res = 0;
    while(i > 0){
        res += b[i][j];
        i -= i & (-i) ;
    }
    return res;
}

void solve(){
    ll n;
    cin >> n;
    string s;
    cin >> s;
    for(ll i = 0; i < n; i++){
        ll c = s[i] - 'a';
        u(i+1, c, 1);
    }
    ll q;
    cin >> q;
    while(q--){
        ll x;
        cin >> x;
        if(x == 1){
            ll p; char c;
            cin >> p >> c;p--;
            if(s[p] != c){
                u(p+1, s[p]-'a', -1);
                u(p+1, c-'a', 1);
                s[p] = c;
            }
        }
        else{
            ll l , r; cin >> l >> r;
            ll tmp = 0;
            for(ll i = 0; i < 26; i++){
                //cout << i << " " << quer(r, i) << " " <<  quer(l-1, i) << endl;
                if(quer(r, i) - quer(l-1, i) > 0) tmp++;
            }
            cout << tmp << endl;
        }
    }

}

int main()
{
    fast();
    int t= 1; //cin >> t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 102556
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? 1e9:1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){int b=0;for(auto itr :a){if(b++!=0)cout << " "; cout << itr;} }
using ll  = long long;
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
#define int ll
struct P{
    int ly,lx,ry,rx;
};

signed main(){
    while(cin >> W >> H ,W+H){
        vector<string>Le(H);
        vector<string>Re(H);
        rep(i,H) cin >> Le[i] >> Re[i];
        int lx,ly,rx,ry;
        rep(i,H)rep(j,W){
            if(Le[i][j] == 'L'){
                lx = j; ly = i;
            }
            if(Re[i][j] == 'R'){
                rx = j;ry = i;
            }
        }
        auto used = vectors(H,W,H,W,false);
        queue<P>que;
        que.push(P{ly,lx,ry,rx});
        bool flag = false;
        while(!que.empty()){
            P t = que.front();
            que.pop();
            if(used[t.ly][t.lx][t.ry][t.rx])continue;
            used[t.ly][t.lx][t.ry][t.rx] = true;
            if(Le[t.ly][t.lx] == '%' &&  Re[t.ry][t.rx] == '%'){
                flag = true;
                break;
            } if(Le[t.ly][t.lx] == '%' or  Re[t.ry][t.rx] == '%'){
                continue;
            }
            int nly,nlx,nry,nrx;
            rep(k,4){
                nly = t.ly +dy[k]; nlx = t.lx + dx[k];
                nry = t.ry + dy[k]; nrx = t.rx -dx[k];
                if(!valid(nlx,nly) || Le[nly][nlx] == '#'){
                    nly = t.ly; nlx = t.lx;
                }
                if(!valid(nrx,nry) || Re[nry][nrx] == '#'){
                    nrx = t.rx; nry = t.ry;
                }
                
                que.push(P{nly,nlx,nry,nrx});
            }
        }
        if(flag)cout << "Yes"<< endl;
        else cout << "No" << endl;
    }
}




Measured memory_bytes: 18384
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	p := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&p[i])
	}

	sort.Sort(sort.IntSlice(p))

	ans := 0
	for i := 0; i < k; i++ {
		ans += p[i]
	}

	fmt.Println(ans)
}


Measured memory_bytes: 1892
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e9+7;

ll dp[55][55][3000];

int main()
{
    ll n,a;
    cin >> n >> a;
    vector<ll> x(n);
    rep(i,n){
        cin >> x[i];
    }
    dp[0][0][0]=1;
    rep(i,n){
        rep(k,n){
            rep(j,3000){
                if(x[i]+j<3000){
                    dp[i+1][k+1][x[i]+j]+=dp[i][k][j];
                }
                dp[i+1][k][j]+=dp[i][k][j];
            }
        }
    }
    ll ans=0;
    rep(i,n){
        ans+=dp[n][i+1][(i+1)*a];
    }
    cout << ans << endl;
    return 0;
} 


Measured memory_bytes: 66560