akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ff first
#define ss second
#define INF (ll) 1e9
#define mod (ll) 1e9 + 7
#define tt ll testcase; cin>>testcase; while(testcase--)
 
int main(){
	fast;
	int H, W;
	//scanf("%d%d", &H, &W);
	cin>>H>>W;
	string s;
	int sq[H+1][W+1]={};
	for(int i = 1; i <= H; i++){
		cin>>s;
		for(ll j = 0; j<W; j++){
			if(s[j]=='.'){
				sq[i][j+1] = 1;
			}
			//cout<<sq[i][j+1]<<" ";
		}
		//cout<<"\n";
	}
	vector<vector<ll>>dp(H+1, vector<ll>(W+1, 0));
	dp[0][1]=1;
	for(int j = 1; j <= W; j++){
		for(int i = 1; i <= H; i ++){
			if(sq[i][j]){
				dp[i][j] = dp[i-1][j] + dp[i][j-1];
				dp[i][j] %= mod;
			}
			else{
				dp[i][j]=0;
			}
		}
	}
	// for(int i = 0; i <= H; i++){
	// 	for(int j = 0; j <= W; j++){
	// 		cout<<dp[i][j]<<" ";
	// 	}
	// 	cout<<"\n";
	// }
	cout<<dp[H][W];
}

Measured memory_bytes: 12032
#include<stdio.h>

int main(void){
    int a,b,ans=0,i;
    scanf("%d%d",&a,&b);
    if(a<b){
        for(i=0;i<b;i++){
            ans *= 10;
            ans +=a;
        }
    }else {
        for(i=0;i<a;i++){
            ans *= 10;
            ans +=b;
        }
    }
    printf("%d",ans);
    return 0;
}



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

using namespace std;

int main() {
	int n, x;
	cin >> n >> x;

	if (x == 1) {
		cout << "No" << endl;
		return 0;
	}
	else if (x == 2 * n - 1) {
		cout << "No" << endl;
		return 0;
	}

	cout << "Yes" << endl;
	for (int i = 0; i < 2 * n - 1; i++) {
		cout << (i + x + n - 1) % (2 * n - 1) + 1 << endl;
	}
	return 0;
}


Measured memory_bytes: 1536
N = int(input())
 
S = {}
max = 0
 
for i in range(N):
  word = input()
  if word in S:
  	S[word] += 1
  else:
    S[word] = 1
  if S[word] > max:
    S_list = []
    max = S[word]
    S_list.append(word)
  elif S[word] == max:
    S_list.append(word)
    
S_list.sort()
for out in S_list:
  print(out)

Measured memory_bytes: 33416
a = input()
a = a[::-1]
k = ["dreamer","dream","erase","eraser"]
for i in range(4):
    k[i] = k[i][::-1]
f = 1
i= 0
while f:
    if a[i:i+5] == k[2] or a[i:i+5] == k[1]:
        i +=5
    elif a[i:i+6] == k[3]:
        i +=6
    elif a[i:i+7] == k[0]:
        i+=7
    else:break
if len(a)==i:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3188
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
local function array(dimensi0n, default_val) assert(type(default_val) ~= 'table') local n=dimensi0n local m={}if default_val~=nil then m[1]={__index=function()return default_val end}end for i=2,n do m[i]={__index=function(p, k)local c=setmetatable({},m[i-1])rawset(p,k,c)return c end}end return setmetatable({},m[n])end
local function tostringxx(o, depth) depth = depth or 0 if depth > 10 then return "<too deep!>" end if o == _G then return "<_G>" end local indent0 = (" "):rep((depth) * 2) local indent1 = (" "):rep((depth+1) * 2) local indent2= (" "):rep((depth+2) * 2) if type(o) == 'table' then local keys = {} local types = {} for k in pairs(o) do types[type(k)] = true table.insert(keys, k) end local types_count = 0 local lasttype for k in pairs(types) do types_count = types_count + 1 lasttype = k end if types_count == 1 and (lasttype == 'string' or lasttype == 'number') then table.sort(keys) end local inside = {} for i=1,#keys do local k = keys[i] local v = o[k] if type(k) == 'string' then k = string.format('%q', k) end table.insert(inside, indent1 .. '['..tostring(k)..'] = ' .. tostringxx(v, depth + 1)) end return '{\n' .. table.concat(inside, ',\n') .. '\n' .. indent0 .. '}' else if type(o) == 'string' then o = string.format('%q', o) end return tostring(o) end end
local function richtraceback() local x = 2 while true do local info = debug.getinfo(x) if not info then break end local fname = '<' .. info.short_src .. ":" .. info.linedefined .. ">" if info.name then fname = info.name end print(info.short_src .. ":" .. info.currentline .. ": in " .. ("%q"):format(fname)) print(" LOCALS:") local p = 1 while true do local name, val = debug.getlocal(x,p) if not name then break end print(" " .. name .. ": " .. tostringxx(val, 3)) p = p + 1 end print(" UPVALUES:") for p=1,info.nups do local name, val = debug.getupvalue(info.func,p) if not name then break end print(" " .. name .. ": " .. tostringxx(val, 3)) end x = x + 1 end end
local function myassert(b) if not b then richtraceback() error("assertion failed") end end 
--
local N, K = read.nn()
local A = read.N(N)
for i=K+1,N do
    local n, o = A[i], A[i-K]
    if n > o then
        print("Yes")
    else
        print("No")
    end
end

Measured memory_bytes: 21992
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
typedef unsigned long long ull;
typedef pair<bool,ull> P;
const ull B = 100000007;
ull pwB[2000];
string s,t;
int N;

bool isAl(char ch){
  return ('a'<=ch&&ch<='z');
}
bool isAL(char ch){
  return ('A'<=ch&&ch<='Z');
}
map<ull,bool> used;
vector<string> ans,ans2;

P check(int l,int r){
  //cout<<l<<" "<<r<<endl;
  if(t[l]!=t[r])return P(false,0);
  if(l==r)return P(true,t[l]-'A'+1);
  P res=check(l+1,r-1);
  //if(res.first)cout<<res.second<<"=";
  res.second*=B;
  res.second+=(t[r]-'A'+1);
  res.second+=(t[l]-'A'+1)*pwB[r-l];
  //if(res.first)cout<<res.second<<endl;
  if(res.first&&!used[res.second]){
    used[res.second]=true;
    return res;
  }
  //  cout<<l<<"-"<<r<<endl;
  return P(false,0);
}

P check2(int l,int r){
  if(t[l]!=t[r])return P(false,0);
  if(l+1==r){
    if(t[l]==t[r])return P(true,B*(t[l]-'A'+1)+(t[r]-'A'+1));
    else return P(false,0);
  }

  P res=check2(l+1,r-1);
  res.second*=B;
  res.second+=(t[r]-'A'+1);
  res.second+=(t[l]-'A'+1)*pwB[r-l];
  if(res.first&&!used[res.second]){
    used[res.second]=true;
    return res;
  }
  return P(false,0);
}

void solve(){
  used.clear();
  ans.clear();
  
  for(int i=N;i>=3;i--){
    if(i%2==0)continue;
    for(int j=0;j+i-1<N;j++){
      P p=check(j,j+i-1);
      if(p.first==false)continue;
      ans.push_back(t.substr(j,i));
    }
  }

  used.clear();
  for(int i=N;i>=4;i--){
    if(i%2==1)continue;
    for(int j=0;j+i-1<N;j++){
      P p=check2(j,j+i-1);
      if(p.first==false)continue;
      ans.push_back(t.substr(j,i));
    }
  }

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

}


int main(){
  pwB[0]=1;
  for(int i=1;i<2000;i++)pwB[i]=pwB[i-1]*B;

  while(getline(cin,s)){
    int len=s.size();
    t="";
    for(int i=0;i<len;i++){
      if(isAL(s[i]))t.push_back(s[i]);
      else if(isAl(s[i]))t.push_back(s[i]-'a'+'A');
    }
    N=t.size();
    solve();
  }
  return 0;
}

Measured memory_bytes: 1220
#include <stdio.h>

int main(void)
{
	int c1, c5, c10, c50, c100, c500;
	int sum;
	
	scanf("%d %d %d %d %d %d", &c1, &c5, &c10, &c50, &c100, &c500);
	
	c5   = c5   * 5;
	c10  = c10  * 10;
	c50  = c50  * 50;
	c100 = c100 * 100;
	c500 = c500 * 500;
	
	sum = c1 + c5 + c10 + c50 + c100 + c500;
	
	if ((sum / 1000) >= 1){
		printf("1\n");
	}
	else {
		printf("0\n");
	}
	
	return (0);
}

Measured memory_bytes: 584
#include <iostream>

using namespace std;

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

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//
ll H, W;
string S[105];
ll dp[105][105];
void dfs(ll h, ll w,  bool changed){
    if(h<H-1&&S[h+1][w]=='.'){
        if (chmin(dp[h + 1][w], dp[h][w])) dfs(h + 1, w, 0);
    }else if(h<H-1){
        if(changed){
            if (chmin(dp[h + 1][w], dp[h][w])) dfs(h + 1, w, true);
        }else{
            if (chmin(dp[h + 1][w], dp[h][w] + 1)) dfs(h + 1, w, true);
        }
    }

    if(w<W-1&&S[h][w+1]=='.'){
        if (chmin(dp[h][w + 1], dp[h][w])) dfs(h, w+1, 0);
    }else if(w<W-1){
        if(changed){
            if (chmin(dp[h][w + 1], dp[h][w])) dfs(h, w + 1, true);
        }else{
            if (chmin(dp[h][w + 1], dp[h][w] + 1)) dfs(h, w + 1, true);
        }
    }
}
int main() {
    init();
    cin >> H >> W;
    rep(i, H) cin >> S[i];
    rep(i, H) rep(j, W) dp[i][j] = INF;
    dp[0][0] = (S[0][0] == '#' ? 1 : 0);

    dfs(0, 0, S[0][0]=='#');

    // rep(i,H){
    //     rep(j, W) cout << dp[i][j] << " ";
    //     cout << endl;
    // }
    // rep(i, H) cout << S[i] << endl;

    cout << dp[H-1][W-1] << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <map>
using namespace std;

int main() {
	long long A, B; int cnt = 0;
	cin >> A >> B;
	for (int i = A; i <= B; i++) {
		string S = to_string(i);
		string T = S; reverse(T.begin(), T.end());
		if (S == T) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

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

int main() {
    int A;
    int B;
    int C;
    int D;


    cin >> A >> B >> C >> D;

    int L = A + B;
    int R = C + D;

    if (L > R) {
        cout << "Left" << endl;
    } else if(L < R) {
        cout << "Right" << endl;
    } else {
        cout << "Balanced" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(b);i>=(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
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;}
template<class T>
ll sum(const T& a){return accumulate(all(a),0LL);}

ll partition(vl &a,ll p,ll r){
    ll x=a[r];
    ll i=p-1;
    fore(j,p,r-1){
        if(a[j]<=x){
            ++i;
            swap(a[i],a[j]);
        }
    }
    swap(a[i+1],a[r]);
    return i+1;
}
void solve(){
    ll n;cin>>n;
    vl a(n);rep(i,n)cin>>a[i];
    ll idx=partition(a,0,a.size()-1);
    rep(i,n){
        if(i>0)cout<<" ";
        if(i==idx)cout<<"["<<a[i]<<"]";
        else cout<<a[i];
    }
    cout<<endl;
}

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



Measured memory_bytes: 3620
#include <iostream>
#include<algorithm>
#include <stdio.h>
#include <string>
#include <string.h>
#include <map>
#include <math.h>
#include <vector>
#include <set>
#include <map>
#include <deque>
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e3+7;
int gcd(int a,int b)
{
    return b?gcd(b,a%b):a;
}
map<int,int>mp;
int p[N],k[N],s[N][N];
int get_bit(int x,int i){return (x>>i)&1;}

int main()
{
     int n,m;
     cin>>n>>m;
     for(int i=1;i<=m;i++) {
         scanf("%d",&k[i]);
         for (int j = 1; j <=k[i];j++)
             scanf("%d",&s[i][j]);
     }
     for(int i=1;i<=m;i++)cin>>p[i];
     int sum=0;
     for(int i=0;i<pow(2,n);i++)
     {
         int f=1;
         for(int r=1;r<=m;r++) {
             int ans=0;
            for(int l=1;l<=k[r];l++)
                if (get_bit(i,s[r][l]-1))
                    ans++;
                if(ans%2!=p[r])
                {
                    f=0;
                    break;
                }
        }
         if(f==1)
             sum++;
     }
     cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

const int N=3005;
const int mod=1000000007;

int n,m,ans;
int dp[2][N][2];

void add(int &x,int y){
	x+=y;
	(x>=mod)?x-=mod:0;
}

int main(){
	int i,j,k,now,pre,cur;
	scanf("%d%d",&n,&m);
	for (i=1;i<=n;i++) dp[0][i][0]=1;
	dp[0][0][1]=1; now=0; pre=1;
	for (i=1;i<=m;i++){
		now^=1; pre^=1;
		for (j=0;j<=n;j++){
			for (k=0;k<2;k++) if (dp[pre][j][k]){
				cur=dp[pre][j][k];
				if (j){
					add(dp[now][j][k|(j==1)],cur);
					add(dp[now][j-1][k|(j==1)],cur);
				}
				if (n-j){
					add(dp[now][j][k],cur);
					add(dp[now][j+1][k],cur);
				}
			}
		}
		memset(dp[pre],0,sizeof(dp[pre]));
	}
	for (i=0;i<=n;i++) add(ans,dp[now][i][1]);
	printf("%d\n",ans);
	return 0;
}

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

#define REP(i,n) for(int i = 0;i < n;++i)
#define PB(s) push_back(s)
#define ST(n) sort(n.begin(),n.end())

using namespace std;
typedef long long ll;

int main(){
	int N;
	ll ANS=0;
	cin >> N;
	vector<ll> A,B,C;
	A.resize(N);
	B.resize(N);
	C.resize(N);
	REP(i,N)
		cin >> A[i];
	REP(i,N)
		cin >> B[i];
	REP(i,N)
		cin >> C[i];

	ST(A);
	ST(B);
	ST(C);
	REP(i,N){
		//Bより小さいA
		ll a_sec = lower_bound(A.begin(),A.end(),B[i]) - A.begin();
		//Bより大きいC
		ll c_sec = N - (upper_bound(C.begin(),C.end(),B[i]) - C.begin());
		ANS+=a_sec*c_sec;
	}
	cout << ANS << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}
const int INF = 1<<30;
const int MOD = 1000000007;
int dx[4] = {0,0,-1,1};
int dy[4] = {-1,1,0,0};

int main(){
  string s,t; cin>> s >>t;
  cout << t+s << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int now = a[0];
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    if (now < a[i]) {
      now = a[i];
    } else {
      ans += now - a[i];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4044
#include<iostream>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

int main(){
  string s,t; cin >>s >>t;
  int n=s.size();
  rep(i,n){
    if(s[i]!=t[i]){
      print("No");
      return 0;
    }
  }
  print("Yes");
}


Measured memory_bytes: 3628
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,b,n) for(int i=b;i<n;i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

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

int main(){
	int sum[3000];
	memset(sum,0,sizeof(sum));
	for(int i=0;i <=1000;i++){
		for(int j=0;j <=1000;j++){
			sum[i+j]++;
		}
	}
	int n;
	while(scanf("%d",&n)!=EOF){
		ll ans=0;
		for(int i=0;i <=2000;i++){
			int a =n-i;
			if(a<0)break;
			if(a>2000)continue;
			ans +=sum[i] * sum[a];
		}
		cout <<ans<<endl;
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)

#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define _repis(i,a,b,s) for(int i=a, i##_len(b); i<i##_len; i+=s)
#define REP(...) _overload3(__VA_ARGS__,_repis,_repi,_rep,)(__VA_ARGS__)

#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < sz(v);++i)

#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))

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

#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl
#define POSS(n) cout<<((n)?"POSSIBLE":"IMPOSSIBLE")<<endl



int main(){
    map<string,int> cnt;
    int n;
    string s;

    cin>>n;
    REP(i,n){
        cin>>s;
        cnt[s]++;
    }

    cin>>n;
    REP(i,n){
        cin>>s;
        cnt[s]--;
    }
    int ma=0;
    for(pair<string,int> p:cnt){
        chmax(ma,p.second);
    }
    cout<<ma<<endl;

    return 0;
}


Measured memory_bytes: 256
function Main(s){
  s = s.split("\n");
  var n = +s[0];
  s = s[1];
  var r = s.split("").reverse().join("");
  var k = 1 << n;
  var a = {}, b = {};
  for(var i = 0; i < k; i++){
    var t = "", u = "", v = "", w = "";
    for(var j = 0; j < n; j++){
      if(i & (1 << j)){t += s[j]; v += r[j];}
      else{u += s[j]; w += r[j];}
    }
    t += "," + u; v += "," + w;
    if(!a[t])a[t] = 1; else a[t]++;
    if(!b[v])b[v] = 1; else b[v]++;
  }
  var ans = 0;
  for(i in a){
    if(!b[i])continue;
    ans += a[i] * b[i];
  }
  console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 102688
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ull, ull> UP;
typedef tuple<int, int, int> T;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
ll digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
ll countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}


int main() {
	IOS;
	int a, b, c;
	cin >> a >> b >> c;
	cout << (b - a == c - b ? "YES" : "NO") << endl;
}



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

typedef long long  ll;

ll MOD = 1000000007;
ll INF = 100000000;
double PI = 3.1415926535;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<pair<ll,ll>>>;

int main(){
  ll A,B,C;cin >> A >> B >> C;
  ll ans = 0;
  for(int i = 0;i < 10000000;i++){
    if(A % 2 == 0 && B % 2 == 0 && C % 2 == 0){
      ans++;
      ll a = A / 2,b = B / 2,c = C / 2;
      A = b+c;
      B = a+c;
      C = a+b;
    }else{
      cout << ans << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}

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

int main() {
    int N; cin >> N;
    vector<int> C(N);
    for(int i=0; i<N; ++i) cin >> C[i];
    C.erase(unique(begin(C), end(C)), end(C));

    const long long MOD = 1000000007;
    long long sum[200001] = {};
    sum[C[0]] = 1;
    for(int i=1; i<C.size(); ++i) {
        sum[C[i]] = (sum[C[i]] + sum[C[i - 1]]) % MOD;
    }
    cout << sum[*rbegin(C)] << endl;
}

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

using namespace std;

int main(){
    string buf;
    cin >> buf;
    if(buf.size() > 26) {
        cout << -1 << endl;
    } else if (buf.size() < 26){
        int f[26];
        memset(f, 0, sizeof(f));
        for(int i = 0; i < buf.size(); i++) {
            f[buf[i] - 'a']++;
        }
        cout << buf;
        for(int i = 0; i < 26; i++){
            if(f[i] == 0) {
                cout << (char)('a' + i) <<endl;
                break;
            }
        }
    } else {
        string res = buf;
        if(next_permutation(buf.begin(), buf.end())){
            int i = 0;
            string r = "";
            for(int j = 0; j < 26; j++){
                r += buf[j];
                if(res[j] != buf[j]){
                    break;
                }
            }
            cout << r << endl;
        }
        else cout << -1 << endl;
    }
    return 0;

}


Measured memory_bytes: 256
N, K = map(int, input().split())
*P, = map(int, input().split())
*C, = map(int, input().split())

def get(pos):
    used = [-1] * N
    cost = [0] * (N+1)

    for k in range(N+1):
        if k:
            cost[k] = cost[k-1] + C[pos]
        if used[pos] >= 0:
            loop_size = k-used[pos]
            break
        used[pos] = k
        pos = P[pos] - 1
    if cost[loop_size] <= 0:
        return max(cost[1:K+1])
    else:
        v2 = cost[loop_size] * (K//loop_size) + max(cost[:(K%loop_size)+1])
        if K//loop_size:
            v1 = cost[loop_size] * ((K//loop_size)-1) + max(cost[:K+1])
            return max(v1, v2)
        else:
            return v2

ans = max([get(i) for i in range(N)])
print(ans)


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

typedef long long LL;

template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar.size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}


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

    int w;
    cin >> w;

    for (int i = 0; i < (int)s.size(); i++) {
        if (i % w == 0) {
            cout << s[i];
        }
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include <math.h>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <iomanip>
#include <iterator>
#include <algorithm>
#include <functional>
#include <typeinfo>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>

using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)
#define mp(a, b) make_pair(a, b)
#define all(vec) (vec).begin(), (vec).end()
#define yn(formula) (formula) ? (cout << "Yes" << endl) : (cout << "No" << endl)
#define YN(formula) (formula) ? (cout << "YES" << endl) : (cout << "NO" << endl)
#define MIN(a, b) ((a) < (b)) ? (a) : (b)
#define LLONG_MAX     9223372036854775807i64

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pii> vp;
typedef vector<pll> vpl;
typedef vector<vi> vvi;
typedef vector<vll> vvl;
typedef vector<vb> vvb;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vp> vvp;
typedef vector<vpl> vvpl;

constexpr double PI = 3.14159265358979323846;
constexpr ll INF = 1 << 29;
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-7;
constexpr int dy[4] = { 0, 1, 0, -1 };
constexpr int dx[4] = { 1, 0, -1, 0 };

struct edge { ll to; ll cost; };

/*<ここから>***********************************************************/


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

	if (abs(a - c) <= d) cout << "Yes" << endl;
	else if (abs(a - b) <= d && abs(b - c) <= d) cout << "Yes" << endl;
	else cout << "No" << endl;



	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

int a, b, c;

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> a >> b >> c;
	if ((a*100+b*10+c) % 4 == 0) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	double r,l;
	int eyesight[4][2];
	for(int i=0; i<4; i++){
		eyesight[i][0]=0;
		eyesight[i][1]=0;
	}
	
	while(cin >> r >> l){
		if(r >= 1.1)
			eyesight[0][0]++;
		if(l >= 1.1)
			eyesight[0][1]++;
		if(r >= 0.6 && r < 1.1)
			eyesight[1][0]++;
		if(l >= 0.6 && l < 1.1)
			eyesight[1][1]++;
		if(r >= 0.2 && r < 0.6)
			eyesight[2][0]++;
		if(l >= 0.2 && l < 0.6)
			eyesight[2][1]++;
		if(r < 0.2)
			eyesight[3][0]++;
		if(l < 0.2)
			eyesight[3][1]++;
	}
	
	for(int i=0; i<4; i++){
		cout << eyesight[i][0] << " " << eyesight[i][1] << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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() {
  ll N, M;
  cin >> N >> M;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];

  vector<ll> sum(N);
  sum[0] = A[0] % M;
  repp(i, 1, N - 1) {
    sum[i] = sum[i - 1] + A[i];
    sum[i] %= M;
  }
  // rep(i, N) {
  //   cout << sum[i] << ' ';
  // }
  // cout << endl;
  map<ll, ll> m;
  vector<ll> dupl;
  rep(i, N) {
    if (m[sum[i]] == 1)
      dupl.pb(sum[i]);
    m[sum[i]]++;
  }

  ll ans = 0;
  ans += m[0];
  rep(i, dupl.size()) {
    ll d = m[dupl[i]];
    ans += d * (d - 1) / 2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 6144
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import itertools
import math
from collections import Counter, defaultdict

class Main(object):
    
    def __init__(self):
        pass

    def solve(self):
        '''
        insert your code
        '''
        t = {
            0: [],
            1: ['.', ',', '!', '?', ' '],
            2: ['a', 'b', 'c'],
            3: ['d', 'e', 'f'],
            4: ['g', 'h', 'i'],
            5: ['j', 'k', 'l'],
            6: ['m', 'n', 'o'],
            7: ['p', 'q', 'r', 's'],
            8: ['t', 'u', 'v'],
            9: ['w', 'x', 'y', 'z']
        }
        n = input()
        for i in range(n):
            ans = ''
            prev = 0
            count = 0
            for c in raw_input():
                if c == '0':
                    if prev == 0:
                        continue
                    ans += t[prev][count-1]
                    prev = 0
                    count = 0
                else:
                    prev = int(c)
                    count += 1
                    count %= len(t[prev])
                    # print prev, count
            print ans
        
        return None

if __name__ == '__main__':
    m = Main()
    m.solve()

Measured memory_bytes: 4676
def getinputdata():

    array_result = []    
    array_result.append(input().split(" "))

    flg = True

    try:
        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

a = int(arr_data[0][0])
b = int(arr_data[0][1])

print("No" if a*b%2==0 else "Yes")

Measured memory_bytes: 3060
#include <iostream>
int a[15];
bool dfs(int prev_b , int prev_c , int p){
    if(p == 10){
        return true;
    }
    bool tf = false;
    if(a[p] > prev_b){
        tf = dfs(a[p] , prev_c , p + 1);
    }
    if(tf){
        return true;
    }
    if(a[p] > prev_c){
        tf = dfs(prev_b , a[p] , p + 1);
    }
    return tf;
}
int main(){
    int n;
    std::cin >> n;
    while(n--){
        for(int i = 0;i < 10;i++){
            std::cin >> a[i];
        }
        if(dfs(-1 , -1 , 0)){
            std::cout << "YES\n";
        }else{
            std::cout << "NO\n";
        }
    }
}


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

using namespace std;
typedef long long ll;

struct SegTree {
	int n = 1 << 18;
	ll data[1 << 19];
	
	SegTree() {
		for (int i = 0; i < (1 << 19); i++)data[i] = 0;
	}

	void set(int pos, ll value) {
		int a = pos + n - 1;
		data[a] = value;
		while (a > 0) {
			a = (a - 1) / 2;
			data[a] = max(data[a * 2 + 1], data[a * 2 + 2]);
		}
	}

	//[l,r)
	ll get(int l, int r, int k, int a, int b) {
		if (a >= r || b <= l)return 0;
		if (l <= a && b <= r)return data[k];
		else {
			ll v1, v2;
			v1 = get(l, r, k * 2 + 1, a, (a + b) / 2);
			v2 = get(l, r, k * 2 + 2, (a + b) / 2, b);
			return max(v1, v2);
		}
	}

};

SegTree st;
ll N;

int main() {
	cin >> N;
	ll ans = N * (N + 1) / 2;

	for (int i = 0; i < N; i++) {
		ll a;
		cin >> a;
		st.set(a, st.get(0, a, 0, 0, 1 << 18) + a);
	}

	ans -= st.get(0, (1 << 18), 0, 0, 1 << 18);

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 7212
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <queue>
#include <stack>
#include <string.h>
#include <list>
using namespace std;
typedef long long ll;
#define all(a)  (a).begin(), (a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define rep(i,n) for(int i = 0; i < n; i++)
#define repR(i,n) for(int i = n-1; i >= 0; i--)
#define FOR(i,m,n) for(int i = m; i < n; i++)
#define PB push_back
#define MP make_pair
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main(){
    ll n, x, cnt = 0, minv = INF;
    cin >> n >> x;
    vector<ll> m(n);
    rep(i,n){
        cin >> m[i];
        x -= m[i];
        cnt++;
        minv = min(minv,m[i]);
    }
    cnt += x / minv;
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>

using namespace std;
int N;

void solve() {
    int ans = 0;
    for (int i = 1; i <= N; ++i) {
        if (i % 2 == 0) continue;
        int count = 0;
        for (int j = 1; j <= N; ++j) {
            if (i % j == 0) count++;
        }
        if (count == 8) ans++;
    }
    printf("%d\n", ans);
}

int main() {
    cin >> N;
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define min(a, b) (a > b ? b : a)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) { rep(_, n) cout << a[_] << " "; cout << endl; }
#define outp(a, n) { cout << endl; rep(_, n) cout << a[_].F << " " << a[_].S << endl; }
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
#define FIX(a) fixed << setprecision(a)
#define LB(v, n) (int)(lower_bound(all(v), n) - v.begin())
#define UB(v, n) (int)(upper_bound(all(v), n) - v.begin())
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll nck(int n, int k) { ll ret = 1; rep(i, k) {ret *= n - i; ret /= i + 1; } return ret; } // n <= 60
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    
    string str;
    cin >> str;
    
    vector<string> v;
    string tmp;
    tmp += str[0];
    v.eb(tmp);
    tmp = "";
    rep3(i, 1, SZ(str)) {
        tmp += str[i];
        if (tmp != v.back()) {
            v.eb(tmp);
            tmp = "";
        }
    }
    out(SZ(v));
}


Measured memory_bytes: 11016
#include <bits/stdc++.h>
using namespace std;
#define N 30
typedef long long ll;
bool compatible[N][N];
int n;
ll memo[N][(1 << 21) + 500];
const ll m = 1e9 + 7;

ll add(ll a , ll b) {
    return ((a % m) + (b % m)) % m;
}

ll dp(int curr , int mask) {
    if (curr >= n) return 1;
    ll &sol = memo[curr][mask];
    if (sol != -1) return sol;
    ll sum = 0;
    for (int i = 0 ; i < n ; i++)
        if (compatible[curr][i] && (mask & (1 << i)) == 0)
            sum = add(sum , dp(curr + 1 , mask | (1 << i)));
    return sol = sum;
}

int main() {
    scanf("%d" , &n);
    for (int i = 0 ; i < n ; i++)
        for (int j = 0 ; j < n ; j++) {
            int b; scanf("%d" , &b);
            compatible[i][j] = b;
        }
    memset (memo , -1 , sizeof memo);
    printf("%lld\n" , dp(0 , 0));
}


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

int main()

{
	
	int a,b;
	cin >> a >> b;
	if (a+b >= a-b and a+b>= a*b)
	cout<< a+b;
	else if (a-b >= a+b and a-b>= a*b)
	cout<< a-b;
	else if (a*b >= a-b and a*b>= a+b)
	cout<< a*b;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>

using namespace std;

int main(void)
{
    long long X, i, judge=0, j;

    cin >> X;

    i = X;

    if(X==2){
        cout << 2 << endl;
    }

    else{
        while(judge==0){
            judge = 1;
            for(j=2; j<i; j++){
                if(i % j == 0){
                    judge = 0;
                }
            }

            if(judge == 1){
                break;
            }

            i++;
        }

        cout << i << endl;
    }

    return 0;
}

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

namespace AtCoder
{
    class B055
    {
        static void Main()
        {
            int mod = (int)Math.Pow(10, 9) + 7;
            int N = int.Parse(Console.ReadLine());
            long ans = 1;
            for (int i = 1; i <= N; i++)
                ans = (ans * i) % mod;
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
#define RI(x) x = rit()
#define RII(a,b) a = rit(), b = rit()
#define RIII(a,b,c) a = rit(), b = rit(), c = rit()
#define REP(I, N) for(int I=0;I<int(N);I++)
#define REPP(I, N) for(int I=1;I<=int(N);I++)
#define ll long long
#define SZ(x) (int)(x).size()
#define F first
#define S second
#define PB(x) push_back(x)
inline int rit(){
    int f=0,key=1;
    char ch;
    do{
        ch = getchar();
        if(ch=='-') key=-1;;
    }while(ch<'0'||ch>'9');
    do{
        f = f*10+ch-'0';
        ch = getchar();
    }while(ch>='0'&&ch<='9');
    return f*key;
}
using namespace std;
typedef pair<int,int> P;
map<multiset<int>,bool>mp;
int a,b,c,ans,ha,hb,hc;
int main(void){
	RIII(a,b,c);
	while(a%2+b%2+c%2==0){
		multiset<int> ms;
		ha = a>>1, hb = b>>1, hc = c>>1;
		ms.insert(hb+hc), ms.insert(ha+hc), ms.insert(ha+hb);
		if(mp.find(ms)!=mp.end()){
			printf("-1\n");
			return 0;
		}
		mp[ms] = true;
		ans++;
		a = hb+hc, b = ha+hc, c = ha+hb;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    ArrayList<Integer> list = new ArrayList<Integer>();
    list.add(N);
    while (true) {
      if (N % 2 == 0) {
        N /= 2;
      } else {
        N = N * 3 + 1;
      }
      if (list.contains(N)) {
        list.add(N);
        System.out.println(list.size());
        break;
      } else {
        list.add(N);
      }
    }
  }
}


Measured memory_bytes: 23124
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

//根なら-size,子なら親の頂点を示す
vector<int> par(100000,-1);

//xの根を求める
int find(int x){
    if(par[x]<0)return x;
    else{
        par[x]=find(par[x]);
        return par[x];
    }
}

//xとyの属する集合の合体
bool merge(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y)return false;
    else{ //sizeの大きい方をxとする
        if(par[x]>par[y])swap(x,y);
        par[x]+=par[y];
        par[y]=x;
        return true;
    }
}

//xとyが同じ集合に属するかの判定
bool same(int x,int y){
    if(find(x)==find(y))return true;
    else return false;
}

//xが属する集合の個数
int size(int x){
    return -par[find(x)];
}

//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main(){
    int n,m,k,x,y,tmp;cin>>n>>m>>k;
    vector<int> friends(n);
    vector<vector<int>> block(n,vector<int>(0));
    for(int i=0;i<m;i++){
        cin>>x>>y;
        merge(x-1,y-1);
        friends[x-1]++;
        friends[y-1]++;
    }
    for(int i=0;i<k;i++){
        cin>>x>>y;
        block[x-1].pb(y-1);
        block[y-1].pb(x-1);
    }
    for(int i=0;i<n;i++){
        tmp=size(i)-1-friends[i];
        for(int x:block[i]){
            if(same(x,i))tmp--;
        }
        if(i==n-1)cout<<tmp<<endl;
        else cout<<tmp<<" ";
    }
}


Measured memory_bytes: 9072
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll INF = 1e12;
const ll MOD = 1000000000 + 7;
#define PB push_back
#define PF push_front
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vpi vector<pii>
#define vll vector<ll>
#define vpl vector<pll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define mii map<int, int>
#define mci map<char, int>
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pr_d(x) cout << fixed << setprecision(15) << x << endl
#define ud(c, x) distance(c.begin(), upper_bound(all(c), x))
#define ld(c, x) distance(c.begin(), lower_bound(all(c), x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep3(i, n) for (int i = (n - 1); i >= 0; --i)
#define rep4(i, a, b) for (int i = (a); i > (b); --i)
#define pb push_back
#define out(x) cout << x << "\n"
bool odd(int i) { return i % 2; }

#define all(v) v.begin(), v.end()
#define size(x) int(x.size())

int gcd(int a, int b) { return __gcd(a, b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
void Yes_No(bool f) {
  if (f)
    printf("Yes\n");
  else
    printf("No\n");
}
void YES_NO(bool f) {
  if (f)
    printf("YES\n");
  else
    printf("NO\n");
}

template <typename T>
void deb1(T x) {
  cout << "debug: " << x << "\n";
}

template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
//-------------------ここから回答する-----------------------

void solve(void) {
  ll n, k;
  cin >> n >> k;
  vll a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];
  map<ll, ll> mp;
  rep(i, n) mp[a[i]] += b[i];
  ll cta = 0;
  for (auto i : mp) {
    cta += i.se;
    if (cta >= k) {
      out(i.fi);
      return;
    }
  }
}
int main(void) { solve(); }


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

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

using namespace std;
using ll = long long;
int mod = 1000000007;

void solve();

int main(void){
    int n; cin >> n;
    //長さn(n <= 55)の互いに異なる素数列から5つを選んでその和が合成数
    //55,555以下の素数はいくつ? -> 5637個
    int max_prime = 55555;    
    int prime[max_prime];
    vector<int> ans(n+1);
    int cur_prime = 53;
    ans[0] = 2; ans[1] = 7; ans[2] = 17; ans[3] = 37; ans[4] = 47;
    rep(i, max_prime) prime[i] = 1;
    prime[0] = 0; prime[1] = 0;
    for(int i = 2; i < max_prime; i++){
        for(int j = i << 1; j < max_prime; j+=i){
            prime[j] = 0;
        }
    }
    /*
    //解法: 今の長さkの数列が条件を満たしている
    //その数列から長さ4の数列の和(kC4)を抽出
    //現在の数列の最大の素数の次に大きな素数から始めて、だめだったら次の素数へ
    vector<int> kc1, kc2, kc3, kc4;
    kc1.push_back(2); kc1.push_back(3); kc1.push_back(5); kc1.push_back(7); kc1.push_back(11);
    kc2.push_back(5); kc2.push_back(7); kc2.push_back(9); kc2.push_back(13); kc2.push_back(8); kc2.push_back(10); kc2.push_back(14); kc2.push_back(12); kc2.push_back(16); kc2.push_back(18);
    int inisum = 28;
    rep(i, 10) kc3.push_back(inisum - kc2[i]);
    rep(i, 5) kc4.push_back(inisum - kc1[i]);
    int loop = n-5;
    rep(i, loop){
        cout << "cur_prime is " << cur_prime << endl;
        bool ok = false;
        while(!ok){
            ok = true;
            rep(j, kc4.size()){
                if(prime[kc4[j] + cur_prime] == 1){
                    cout << kc4[j] + cur_prime << endl;
                    ok = false;
                    break;
                } 
            }
            if(ok){
                vector<int> temp2, temp3, temp4;
                //kC4+kC3が(k+1)C4, kC3+kC2 = (k+1)C3, kC2+kC1 = (k+1)C2
                kc1.push_back(cur_prime);
                rep(j, kc1.size()) temp2.push_back(kc1[j] + cur_prime);
                rep(j, kc2.size()){
                    temp2.push_back(kc2[j]);
                    temp3.push_back(kc2[j] + cur_prime);
                } 
                rep(j, kc3.size()){
                    temp3.push_back(kc3[j]);
                    temp4.push_back(kc3[j] + cur_prime);
                }
                rep(j, kc4.size()) temp4.push_back(kc4[j]);
                kc2 = temp2; kc3 = temp3; kc4 = temp4;
            }
            while(prime[++cur_prime] == 0);
        }
    }
    rep(i, kc1.size()){
        if(i == kc1.size()-1) cout << kc1[i] << endl;
        else cout << kc1[i] << " ";
    }
    */

    //mod5が同じものを集めればいいじゃないか。55555までで5000個以上の素数があるのだからなんだって見つかるさ
    int loop = n-5;
    int idx = 5;
    rep(i, n){
        while(idx < n){
            if(cur_prime % 5 == 2) ans[idx++] = cur_prime;
            while(prime[++cur_prime] == 0);
        }
    }
    rep(i, n){
        if(i == n-1) cout << ans[i] << endl;
        else cout << ans[i] << " ";
    }
    return 0;
}

void solve(){}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <bitset>
#include <limits>

using ld = long double;
using ll = long long int;
using ul = unsigned long long int;

namespace lamlib
{
	/* constant */
	constexpr double epsilon = std::numeric_limits<double>::epsilon();

	/* math */
	template<class T> inline T abs(const T &a){ return (a>0) ? a : -a; }
	ul inline digit(const ul &num){ return static_cast<ul>(std::log10(num+epsilon))+1; }

	/* algorithm */
	ul gcd(const ul &a,const ul &b) { return (!b) ? a : gcd(b,a%b); } // NOTE: a > b

	/* string */
	inline ul same_char_count(const std::string s,const char &ch){ return std::count(std::cbegin(s),std::cend(s),ch); }
}

// std::cout << std::fixed << std::setprecision(15) << std::endl;

int main(int argc,char *argv[])
{
	ll n,y;
	std::cin >> n >> y;

	auto expr = [&](const ll &x, const ll &y) { return n-(x+y); };

	ll ans_1 = 0, ans_2 = 0, ans_3 = 0;
	for(ll i = 0;i <= n;++i)
	{
		for(ll j = 0;j <= n;++j)
		{
			auto k = expr(i,j);
			auto money = i*10000 + j*5000 + k*1000;
			if(k >= 0 && money == y)
			{
				std::cout << i << " " << j << " " << k << std::endl;
				return 0;
			}
		}
	}

	std::cout << -1 << " " << -1 << " " << -1 << std::endl;

	return 0;
}

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


#define long long long int

using namespace std;


typedef vector<int> vi;
typedef pair<int, int> pi;

void print(const vector<long> &a) {
    for (auto item : a) {
        cout << item << " ";
        flush(cout);
    }
}

int main() {

    int n;
    long k;
    cin >> n >> k;
    vector<long> a(n);
    vector<long> f(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    for (int i = 0; i < n; ++i) cin >> f[i];

    sort(a.begin(), a.end());
    sort(f.rbegin(), f.rend());
    long l = -1;
    long r = 1000000000000ll;
    while (r > l + 1) {
        long m = l + (r - l) / 2;
        long s = 0;
        for (int i = 0; i < n; ++i) {
            long aa = m / f[i];
            if (a[i] > aa) {
                s += a[i] - aa;
            }
        }
        if (s > k) {
            l = m;
        } else {
            r = m;
        }
    }
    cout << r;
    return 0;
}

Measured memory_bytes: 3328
/**
 *      ABC 52 D
 *      author  : kyomukyomupurin
 *      created : 2018-09-16 07:16:01
**/

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

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

    int N, A, B; cin >> N >> A >> B;
    ll X[N] = {};
    for (int i = 0; i < N; ++i) {
        cin >> X[i];
    }

    ll teleport = 0; 
    ll walk = 0;
    for (int i = 0; i < N - 1; ++i) {
        if (A * (X[i + 1] - X[i]) > B){
            ++teleport;
        }
        else {
            walk += A * (X[i + 1] - X[i]);
        }
    }
    ll answer = B * teleport + walk;
    cout << answer << endl;

    return 0;

}

Measured memory_bytes: 1024