akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int payment(vector<int> p){
	  return 10*p[0] + 50*p[1] + 100*p[2] + 500*p[3];
}
vector<int> charge(int m){
	  vector<int> ans(4);
	  ans[3] = m/500; m -= (m/500)*500;
	  ans[2] = m/100; m -= (m/100)*100;
	  ans[1] = m/50;  m -= (m/50)*50;
	  ans[0] = m/10;
	  return ans;
}
vector<int> _minus(vector<int> a, vector<int> b){
	  vector<int> ans(4);
	  for(int i=0; i<4; i++)
			ans[i] = a[i] - b[i];
	  return ans;
}
vector<int> _plus(vector<int> a, vector<int> b){
	  vector<int> ans(4);
	  for(int i=0; i<4; i++)
			ans[i] = a[i] + b[i];
	  return ans;
}
bool judge(vector<int>& f, vector<int>& ch ){
	  for(int i=0; i<4; i++)
			if( f[i] == 1 and ch[i] > 0)
				  return false;
	  return true;
}

int main(){
	  int N;  cin >> N;
	  while(1){
   
			vector<int> c(4);
			int sum=0;;
			for(int i=0; i<4; i++){
				  cin >> c[i];
				  sum += c[i];
			}
			vector<int> f(4,0);
			int mini = 1e+9;
			vector<int> pay(4);
			vector<int> ans(4);
			for(pay[0]=0; pay[0]<=c[0]; pay[0]++){
				  if(pay[0]>0) f[0] = 1;
				  for( pay[1]=0; pay[1]<=c[1]; pay[1]++){
						if(pay[1]>0) f[1] = 1;
						for(pay[2]=0; pay[2]<=c[2]; pay[2]++){
							  if(pay[2]>0) f[2] = 1;
							  for(pay[3]=0; pay[3]<=c[3]; pay[3]++){
									if(pay[3]>0) f[3] = 1;

									int m_pay = payment(pay);
									int n_pay = accumulate(pay.begin(), pay.end(), 0);
													  
									if( m_pay >= N ){
										  vector<int> ch = charge( m_pay - N );
										  int n_charge = accumulate(ch.begin(), ch.end(), 0);
										  if(mini > sum - n_pay + n_charge){
												if( judge(f,ch) ){
													  ans = pay;
													  mini = sum - n_pay + n_charge;
												}
										  }
									}
									f[3] = 0;
							  }
							  f[2] = 0;
						}
						f[1] = 0;
				  }
				  f[0] = 0;
			}
			
				  
			for(int i=0; i<4; i++){
				  if(ans[i] > 0){
						if(i==0)
							  cout << 10 << " " << ans[i] << endl;
						if(i==1)
							  cout << 50 << " " << ans[i] << endl;
						if(i==2)
							  cout << 100 << " " << ans[i] << endl;
						if(i==3)
							  cout << 500 << " " << ans[i] << endl;

				  }
			}
			cin >> N; if(!N) break;
			cout << endl;
	  }
	  
	  
}

Measured memory_bytes: 1216
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
using namespace std;

int main(){
  int n,m,x[100000],diff[100000],sum=0;

  cin >> n >> m;

  for(int i=0; i < m;i++){
    cin >> x[i];
  }
  sort(x,x+m);
  for(int i=0; i<m-1;i++)
    diff[i]=x[i+1]-x[i];
  

  sort(diff,diff+m-1);
  for(int i=0; i<m-n;i++)
    sum+=diff[i];
  
  if(n>=m)
    cout << 0 <<endl;
  else
    cout << sum <<endl;

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int n; cin >> n;
    vector<int> Num(n);
    int ans = 0;
    REP(i, n) cin >> Num[i];
    whole(sort, Num);
    REP(i, n){
        int count = 0, fix = Num[i];
        while(Num[i] == fix){
            count++;
            i++;
        }
        i--;
        if(count != fix) ans += (count > fix ? count - fix : count);
    }
    cout << ans << endl;
}

Measured memory_bytes: 768
/*
ID: Trump
TASK: 
LANG: C++
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include <iostream>
#include <fstream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
typedef long double lb;
//#define MARK
const ll losn=1e6+5;
const ll maxn=1e5+5;
const ll minn=1e3+5;
const ll tiny=1e2+5;
const ll inf=1e9;
const ll mod=1e9+7;
const ll hmod=4698571;

int main(){
//#ifdef MARK
//    freopen("input.in", "r", stdin);
//    freopen("ouput.out", "w", stdout);
//    freopen("input.in", "r", stdin);
//    freopen("ouput.out", "w", stdout);
//#endif
	ll n;
	cin>>n;
	ll l=0;
	bool is=false;
	for(ll i=1;i<=n;i++){
		ll u,v;
		cin>>u>>v;
		if(u==v){
			l++;
			if(l==3){
				is=true;
			}
		}else l=0;
	}
	if(is){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	
	
	
	
	
	
	
	return 0;
}

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

int main(){
    int a, v;
    int b, w;
    int t;
    cin >> a >> v >> b >> w >> t;
    int d = abs(a-b);
    int dv = v-w;
    double tans = (double)d/dv;
    if(t<tans || dv<0){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }
    return 0;
}

Measured memory_bytes: 3620
#include <cstdio>
int n, t, a[305][305], b[305][305];
long long s;
int main() {
	int i, j, k;
	scanf("%d", &n);
	for(i=0; i<n; i++) for(j=0; j<n; j++) scanf("%d", &a[i][j]);
	for(k=0; k<n; k++) for(i=0; i<n; i++) for(j=0; j<n; j++) {
		t = a[i][k] + a[k][j];
		if(a[i][j]>t) {puts("-1"); return 0;}
		else if(a[i][j]==t && k!=i && k!=j) b[i][j] = 1;
	}
	for(i=0; i<n; i++) for(j=i+1; j<n; j++) s += a[i][j] * !b[i][j];
	printf("%lld", s);
	return 0;
}

Measured memory_bytes: 896
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    static long fib(int n){
        if (n==0) return 1;
        else if (n==1) return 1;
        
        long val = 2;
        long val_pre = 1;
        long val_prepre = 1; 
        for (int i = 2; i < n; i++){
            val_prepre = val_pre;
			val_pre = val;
            val = val_pre + val_prepre;
        }
        return val;
    }
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        System.out.println(fib(n));
    }
}

Measured memory_bytes: 16980
from collections import deque

A=deque(input())
B=deque(input())
C=deque(input())

NOW="a"

while True:
    #print(NOW,A,B,C)
    if NOW=="a" and len(A)>=1:
        NOW=A.popleft()
    elif NOW=="b" and len(B)>=1:
        NOW=B.popleft()
    elif NOW=="c" and len(C)>=1:
        NOW=C.popleft()

    else:
        break

print(NOW.upper())

Measured memory_bytes: 3316
import sys

N,M=map(int,input().split())
a=[int(input()) for i in range(M)]
c=[0]*(N+1)
c[0]=1
MOD=7+10**9
j=0
for i in range(1,N+1):
    if j<M and i==a[j]:
        j+=1
    elif i==1:
        c[i]=1
    else:
        c[i]=(c[i-1]+c[i-2])%MOD
print(c[-1]%MOD)
            

Measured memory_bytes: 7848
def main():
    N = int(input())
    S_list = []
    for _ in range(N):
        S_list.append(input())

    S_dict = {}
    for s in S_list:
        S_dict[s]=0
    for s in S_list:
        S_dict[s]+=1

    max_v = max(S_dict.values())

    max_k_list = [kv[0] for kv in S_dict.items() if kv[1] == max_v]
    max_k_list.sort()
    for k in max_k_list:
        print(k)

if __name__ == '__main__':
     main()

Measured memory_bytes: 153240
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";

int main(){
  ll n,m; cin >> n >> m;
  rep(i,m){
    ll a; cin >> a;
    n-=a;
  }
  if(n<0){
    cout << -1;
  }
  else{
    cout << n;
  }
  return 0;
}


Measured memory_bytes: 3636
from decimal import Decimal as D
mi1,mi2,sa1,sa2,houwa,lim=map(int,input().split())
slim=houwa*lim//(100+houwa)
ws=set(mi1*i+mi2*j for i in range(lim//(100*mi1)+2) for j in range(lim//(100*mi2)+2) if 100*(mi1*i+mi2*j)<=lim)
ss=set(sa1*i+sa2*j for i in range(slim//sa1+2) for j in range(slim//sa2+2) if (sa1*i+sa2*j)<=slim)
ans=D("0")
iw,isa=mi1,0
for s in ss:
  for w in ws:
    if s>houwa*w or w==0:continue
    if ans<D(str(10000*s))/D(str(s+100*w)) and s+100*w<=lim:
      ans=D(str(10000*s))/D(str(s+100*w))
      isa,iw=s,w
print(100*iw+isa,isa)


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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

struct edge {
  int to, et, tr;
  edge(){}
  edge(int to, int et, int tr):to(to), et(et), tr(tr){}
};

int n_railway;
int t_transfer;
string start_st, goal_st;
vector<vector<string> > railway_info_st;
vector<vector<int> > railway_info_t;
int n_node;
map<string, int> conv;
vector<vector<edge> > graph;

using PP = pair<Pi, int>;
Pi dijkstra(int s, int t) {
  vector<Pi> mincost(n_node, Pi(inf, inf));
  priority_queue<PP, vector<PP>, greater<PP> > que;
  mincost[s] = Pi(0, 0);
  que.emplace(Pi(0, 0), s);
  while(!que.empty()) {
    PP p = que.top(); que.pop();
    int v = p.second;
    if(v == t) return mincost[v];
    if(mincost[v] < p.first) continue;
    for(edge e : graph[v]) {
      Pi cost = Pi(mincost[v].first+e.et, mincost[v].second+e.tr);
      if(cost < mincost[e.to]) {
	mincost[e.to] = cost;
	que.emplace(cost, e.to);
      }
    }
  }
  return Pi(inf, inf);
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin >> n_railway >> t_transfer;
  cin >> start_st >> goal_st;

  railway_info_st.resize(n_railway);
  railway_info_t.resize(n_railway);

  for(int i = 0; i < n_railway; ++i) {
    int n_st; cin >> n_st;

    n_node += n_st;

    railway_info_st[i].resize(n_st);
    for(int j = 0; j < n_st; ++j) cin >> railway_info_st[i][j];

    railway_info_t[i].resize(n_st);
    for(int j = 0; j < n_st-1; ++j) cin >> railway_info_t[i][j];
  }

  graph.resize(n_node);

  int sz = 0;
  for(int i = 0; i < n_railway; ++i) {
    for(int j = 0; j < (int)railway_info_st[i].size(); ++j) {
      int u = sz++;
      if(!conv.count(railway_info_st[i][j])) {
	conv[railway_info_st[i][j]] = n_node++;
	graph.emplace_back();
      }
      int x = conv[railway_info_st[i][j]];
      graph[u].emplace_back(x, t_transfer, 1);
      graph[x].emplace_back(u, 0, 0);

      if(j == (int)railway_info_st[i].size()-1) continue;

      int v = sz;
      int t = railway_info_t[i][j];
      graph[u].emplace_back(v, t, 0);
      graph[v].emplace_back(u, t, 0);
    }
  }

  Pi ans = dijkstra(conv[start_st], conv[goal_st]);
  if(ans.first == inf) cout << -1 << endl;
  else cout << ans.first-t_transfer << " " << ans.second-1 << endl;

  return 0;
}



Measured memory_bytes: 35880
#include<bits/stdc++.h>
using namespace std; 
#define mod 1000000007
#define N 100005
#define ll long long
#define ull unsigned long long
#define loop1(i, j, k, step) for (int i=j; i<k; i+=step)
#define loop(i, j, k) for (int i=j; i<k; i++) 
#define rloop1(i, j, k, step) for (int i=j; i>=k; i-=step)
#define rloop(i, j, k) for(int i=j; i>=k; i--)
#define rep(i, k) for(int i = (0); i < (k); i++ )
#define rrep(i, k) for(int i = k-1; i >= 0; i-- )

#define forall(it, l) for(auto it=l.begin(); it != l.end(); it++)
#define mp make_pair
#define pb push_back
#define pop pop_back
#define F first
#define S second
#define sz(x) (int)(x).size()
#define endl "\n"
#define Max (int)INT_MAX
#define Min (int)INT_MIN
#define MEM(a, b) memset(a, (b), sizeof(a))
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;


void solve()
{
	int n,i,j,k,l,d,cnt=0;
	cin>>n>>k;
	int visit[n+1]={0};
	rep(i,k){
		cin>>d;
		rep(i,d){
			cin>>l;
			visit[l]=1;
		}
	}
	loop(i,1,n+1){
		if(visit[i]==0)
			cnt++;
	}
	cout<<cnt<<endl;
}
int  main() 
{
	auto start=clock();
	fast_io;
    int t=1;
    //cin>>t;
    while(t--)
    	solve();
    auto stop =clock();
    cerr<<"time taken:"<<double(stop-start)/double(CLOCKS_PER_SEC)<<" s"<<endl;
	return 0; 
}

Measured memory_bytes: 3808
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using u32 = uint32_t;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define MAXC(c, x) (c = max(c, x))
#define MINC(c, x) (c = min(c, x))

#define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;

int main() {
	#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
	#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);
	ll n, m; cin >> n >> m;
	ll sum = 0;
	if (n * 2 < m) {
		sum += n;
		m -= n * 2;
		cout << sum + m / 4 << endl;
	} else {
		cout << m / 2 << endl;
		return 0;
	}
}

Measured memory_bytes: 256
#include <stdio.h>


int main(void){
    int N,Y;
    scanf("%d %d",&N,&Y);
    Y/=1000;
    for(int i=0;i<=N;i++)for(int j=0;j<=N-i;j++){
        if(i*10+5*j+(N-i-j)==Y){printf("%d %d %d",i,j,(N-i-j));return 0;}
    }
    printf("-1 -1 -1");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define int long long
#define endl '\n'
#define inf 0x3f3f3f3f
#define lb lower_bound
#define db(x) {cout <<"#db " << x << endl;}
#define here() {cout <<"here \n";}
#define mod 1000000007
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int MOD = 1e9 + 7;
const int N = 1e5 + 5;

int par[N];
int n,te,ans = 0,use = 0;
int find(int x){
	if(x == par[x])return x;
	return par[x] = find(par[x]);
}
struct point{
	int id,X,Y;
}p[N];
bool cmpx(point a,point b){
	return a.X <b.X;
}
bool cmpy(point a,point b){
	return a.Y <b.Y;
}
struct edge{
	int u,v;
	int w;
}e[N<<1];
bool cmpe(edge a,edge b){
	return a.w < b.w;
}
signed main(){
	cin >> n;
	for(int i = 0 ; i < n ; i ++){
		par[i] = i;
		int x,y; cin >> x >> y;
		p[i].id = i;
		p[i].X = x;p[i].Y = y;
	}
	sort(p,p+n,cmpx);
	for(int i = 1 ; i < n ; i ++ ){
		e[te].w = p[i].X - p[i-1].X;
		e[te].u = p[i].id;
		e[te].v = p[i-1].id;
		te ++;
	}
	sort(p,p+n,cmpy);
	for(int i = 1 ; i < n ; i ++ ){
		e[te].w = p[i].Y - p[i-1].Y;
		e[te].u = p[i].id;
		e[te].v = p[i-1].id;
		te ++;
	}
	sort(e,e+te,cmpe);
	for(int i = 0 ; i < te ; i ++){
		int st = find(e[i].u);
		int en = find(e[i].v);
		if(st != en){
			ans += e[i].w;
			par[st] = en;
			use ++;
		}
		if(use == n - 1){
			cout << ans;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 8064
import java.util.*;
import java.math.*;
class Main {
	static boolean isPrime(int N)
	{
		for (int i = 2; i <= Math.sqrt(N); i++) 
		{
			if(N % i == 0){return false;}
	    }
		return N!=1;
    }
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int cnt = 0;
		for (int i=0; i<n; i++) {
			if(isPrime(sc.nextInt()))
				cnt++;
		}
		System.out.println(cnt);
	}
    


}





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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;
//const int INF=(1<<30);


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

  vector<int> a(3*N);
  
  REP(i,3*N)cin >> a[i];

  ll sum1=0;
  ll sum2=0;

  vector<ll> v1, v2;

  std::priority_queue< int, std::vector<int>, std::greater<int> > pq1;

  REP(i,N){
    sum1+=a[i];
    pq1.push(a[i]);
  }

  v1.push_back(sum1);
  FOR(i,N,2*N){
    sum1 += a[i];
    pq1.push(a[i]);
    sum1 -= pq1.top();
    pq1.pop();
    v1.push_back(sum1);
  }

  std::priority_queue< int, std::vector<int>, std::less<int> > pq2;

  FOR(i,2*N,3*N){
    sum2+=a[i];
    pq2.push(a[i]);
  }

  v2.push_back(sum2);
  for(int i=2*N-1; N <= i; i--){
    sum2+=a[i];
    pq2.push(a[i]);
    sum2 -= pq2.top();
    pq2.pop();
    v2.push_back(sum2);
  }

  reverse(v2.begin(), v2.end());

  ll ans=-INF;

  REP(i,v1.size()){
    ans=max(ans,v1[i]-v2[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 4852
H, W, M = map(int, input().split())
bombs = set()

H_count = [0 for i in range(H)]
W_count = [0 for i in range(W)]

for i in range(M):
    h, w = map(lambda x:int(x) - 1, input().split())
    bombs.add((h, w))
    H_count[h] += 1
    W_count[w] += 1


A = max(H_count)
B = max(W_count)
Ah = []
Bw = []

for i, count in enumerate(H_count):
    if count == A:
        Ah.append(i)

for i, count in enumerate(W_count):
    if count == B:
        Bw.append(i)

ans = A + B
for h in Ah:
    for w in Bw:
        if (h, w) not in bombs:
            print(ans)
            exit()

print(ans - 1)


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

int main(){
  string s;
  cin >> s;
  int k;
  cin >> k;
  set<string> se;
  for ( int i = 0; i < s.length(); i++){
    string tmp = "";
    int l = min(i+5, (int)s.length());
    for ( int j = i; j < l; j++){
      tmp += s[j];
      se.insert(tmp);
    }
  }

  int i = 0;
  for ( set<string>::iterator it = se.begin(); it != se.end(); it++){
    i++;
    if(i != k )continue;
    cout << *it << endl;
  }

  return 0;
}

Measured memory_bytes: 1664
s=list(input())
t=list(input())

s.sort()
t.sort(reverse=True)

s1=""
t1=""

for i in range(len(s)):
    s1+=s[i]
for g in range(len(t)):
    t1+=t[g]

j=[s1,t1]
jSorted=sorted(j)

if j[0]==j[1]:
    print("No")
    exit()

if j[0]==jSorted[0]:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
s = input()
n = len(s)
p = 10 ** 9 + 7

q = s.count('?')
l_a = [0] * n  # l_a[i] := s[i]より左にあるAの数
l_x = [0] * n  # l_x[i] := s[i]より左にある?の数
r_c = [0] * n  # r_c[i] := s[i]より右にあるCの数
r_x = [0] * n  # r_x[i] := s[i]より右にある?の数

for i in range(1, n):  # 1〜n-1
    l_a[i] = l_a[i - 1] + int(s[i - 1] == 'A')
    l_x[i] = l_x[i - 1] + int(s[i - 1] == '?')
    r_c[n - i - 1] = r_c[n - i] + int(s[n - i] == 'C')
    r_x[n - i - 1] = r_x[n - i] + int(s[n - i] == '?')

ans = 0
pow_q = []
for i in range(0, 4):
    pow_q.append(max(1, 3 ** (q - i) % p))

for i in range(n):
    if s[i] == 'B':
        ans += (l_a[i] * r_c[i] % p) * pow_q[0] % p  # ABC
        ans += (l_x[i] * r_c[i] % p) * pow_q[1] % p # ?BC
        ans += (l_a[i] * r_x[i] % p) * pow_q[1] % p # AB?
        ans += (l_x[i] * r_x[i] % p) * pow_q[2] % p # ?B?
        ans %= p
    elif s[i] == '?':
        ans += (l_a[i] * r_c[i] % p) * pow_q[1] % p # A?C
        ans += (l_x[i] * r_c[i] % p) * pow_q[2] % p # ??C
        ans += (l_a[i] * r_x[i] % p) * pow_q[2] % p # A??
        ans += (l_x[i] * r_x[i] % p) * pow_q[3] % p # ???
        ans %= p

print(ans)

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

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

// chmax, chmin
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;
}

void solve(long long N) {
  for(int i = 1 ; i <= 100000 ; i++){
    if( (long long)(i * 1.08) == N ){
      cout << i << endl;
      return;
    }
  }
  cout << ":(" << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  solve(N);
  return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> H(N+1);
  for(int i = 0; i < N; ++i) cin >> H[i];
  H[N] = 0;
  ++N;
  int ans = 0;
  while(1){
    bool f = true;
    for(int j = 0; j < N; ++j){
      if(f and not H[j]) continue;
      if(not H[j]) break;
      f = false;
      --H[j];
    }
    if(f) break;
    ++ans;
    //for(int j = 0; j < N; ++j) cerr << H[j] << " ";cerr << endl;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
#pragma warning(disable : 4996)
using namespace std;
int n, m;
int main() {
	cin >> n >> m;
	vector<int> x(n);
	for (int i = 0; i < n; i++) cin >> x[i], x[i]--;
	vector<vector<int> > sum(m, vector<int>(n + 1, 0));
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < n; j++) {
			sum[i][j + 1] = sum[i][j] + (x[j] == i ? 1 : 0);
		}
	}
	vector<int> bsum(1 << m, 0);
	for (int i = 0; i < m; i++) {
		for (int j = 1 << i; j < 2 << i; j++) {
			bsum[j] = bsum[j - (1 << i)] + sum[i][n];
		}
	}
	vector<int> dp(1 << m, 999999999); dp[0] = 0;
	for (int i = 1; i < 1 << m; i++) {
		for (int j = 0; j < m; j++) {
			if (!(i & (1 << j))) continue;
			dp[i] = min(dp[i], dp[i - (1 << j)] + (bsum[i] - bsum[i - (1 << j)]) - (sum[j][bsum[i]] - sum[j][bsum[i - (1 << j)]]));
		}
	}
	cout << dp[(1 << m) - 1] << endl;
	return 0;
}

Measured memory_bytes: 19256
using System;
using System.Linq;
using System.Collections.Generic;

class Mondai
{
    static void Main()
    {
        var N = Int32.Parse(Console.ReadLine());
        var A= Console.ReadLine().Split(' ').Select(n => Int32.Parse(n)).OrderBy(x=>x).ToArray();

        var minIndex = 0;
        var maxIndex = N - 1;
        var M = 0;
        for (int i = 1; i < N - 1; ++i) M += Math.Abs(A[i]);
        M = M + A[maxIndex] - A[minIndex];
        Console.WriteLine(M);

        for (int i=1;i<N-1;++i)
        {
            if (A[i] < 0)
            {
                Console.WriteLine($"{A[maxIndex]} {A[i]}");
                A[maxIndex] -= A[i];
            }
            else
            {
                Console.WriteLine($"{A[minIndex]} {A[i]}");
                A[minIndex] -= A[i];
            }
        }
        Console.WriteLine($"{A[maxIndex]} {A[minIndex]}");
    }
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int a, b, c;
  cin >> a >> b >> c;
  
  if((a == b && a != c) || (a == c && b != c) || (c == b && a != c)) cout << "Yes\n";
  else cout << "No\n";
}

Measured memory_bytes: 256
function Main(input) {
	str = input.split(" ");
	var a = parseInt(str[0], 10);
	var b = parseInt(str[1], 10);
  	var s = (a * b) % 2;
  	if (s === 0) {
		console.log("Even");
    } else {
      console.log("Odd");
    }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

const double Pi = acos(-1);

int main() {
    int A, B, H, M;
    cin >> A >> B >> H >> M;
    //cout << Pi << endl;
    complex<double> hour(0, A), minute(0, B);
    complex<double> rot1 = -2.0i * Pi * (H / 12.0 + M / 60.0 / 12.0);
    complex<double> rot2 = -2.0i * Pi * (double)M / 60.0;
    hour *= exp(rot1);
    minute *= exp(rot2);
    complex<double> Sub = hour - minute;
    double D = sqrt(Sub.real() * Sub.real() + Sub.imag() * Sub.imag());
    cout << fixed << setprecision(20) << D << endl;
    return 0;
}

Measured memory_bytes: 4172
#include<iostream>
#include<string>

using namespace std;

 bool isPalindrome(string string) {
	//char str[] = string.c_str();
	bool isPalindrome = true;
	int i = 0, j = string.length() - 1;
	while (isPalindrome && i <= j) {
		isPalindrome &= string[i] == string[j];
		i++;
		j--;
	}
	return isPalindrome;
}

int main() {

	string s;

	cin >> s;
	int n = (int)s.length();
	bool is_ans = true;

	//while (true) {
	//	int i = 0;
	//	if (s[i] != s[n - i - 1])is_ans = false; break;
	//	i++;
	//	if (i > n / 2)break;
	//}

	is_ans &= isPalindrome(s);
	if (n % 2 == 1) {
		string s2 = s.substr(0, (n - 1) / 2 );
		string s3 = s.substr((n + 3) / 2 - 1, n - (n + 3) / 2 + 1);
		
		//while (true) {
		//	int i = 0;
		//	if (s2[i] != s2[(n-1)/2 - i - 1])is_ans = false; break;
		//	i++;
		//	if (i > (n-1) / 2/2)break;
		//}
		//while (true) {
		//	int i = 0;
		//	if (s3[i] != s3[(n - 1) / 2 - i - 1])is_ans = false; break;
		//	i++;
		//	if (i > (n - 1) / 2/2)break;
		//}

		is_ans &= isPalindrome(s2);
		is_ans &= isPalindrome(s3);



	}
	else {
		string s2 = s.substr(0, (n - 2) / 2);
		string s3 = s.substr((n + 4) / 2-1 , n - (n + 4) / 2 +1);
		//while (true) {
		//	int i = 0;
		//	if (s2[i] != s2[(n - 2) / 2 - i - 1])is_ans = false; break;
		//	i++;
		//	if (i >= (n - 2) / 2)break;
		//}
		//while (true) {
		//	int i = 0;
		//	if (s3[i] != s3[(n - 2) / 2 - i - 1])is_ans = false; break;
		//	i++;
		//	if (i >= (n - 2) / 2 )break;
		//}

		is_ans &= isPalindrome(s2);
		is_ans &= isPalindrome(s3);
	}

	if (is_ans)cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;

}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		try (Scanner sc = new Scanner(System.in)) {

			int n = sc.nextInt();
			sc.nextLine();

			Map<String, Long> map = new HashMap<>();
			for (int i = 0; i < n; i++) {

				String s = sc.nextLine();
				if (!s.matches("^[MARCH].*$")) {
					continue;
				}

				inc(map, s.substring(0, 1));

			}

			long ans = 0;
			List<Long> list = new ArrayList<>(map.values());
			for (int i = 0; i < list.size() - 2; i++) {
				for (int j = i + 1; j < list.size() - 1; j++) {
					for (int k = j + 1; k < list.size(); k++) {

						long c = 1;
						c *= list.get(i).longValue();
						c *= list.get(j).longValue();
						c *= list.get(k).longValue();

						ans += c;

					}
				}
			}

			System.out.println(ans);

		}

	}

	private static final <T> void inc(Map<T, Long> map, T key) {

		Long val = map.get(key);

		if (null == val) {
			val = Long.valueOf(1);

		} else {
			val = Long.valueOf(val.longValue() + 1);
		}

		map.put(key, val);

	}

}


Measured memory_bytes: 151872
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int n; cin >> n;
    vint a(n);
    double mean = 0;
    rep(i,n) {
        int x; cin >> x;
        mean += x;
        a[i] = x;
    }
    mean /= n;
    double mn = 100000;
    int ans;
    for (int i = n-1; i >= 0; i--) {
        if (abs(a[i]-mean) <= mn) {
            ans = i;
            mn = abs(a[i]-mean);
        }
    }
    cout << ans << endl;
}

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

#define all(c) (c).begin(),(c).end()
#define FOR(i, x, n) for(int i = x; i < (int)n; i++)
#define REP(i, n) FOR(i, 0, n)
#define debug(x) #x << "=" << (x) << "(L" << __LINE__ << ")"
#define show(x) cout << #x << "=" << x << endl
#define show2(x,y) cout << #x << "=" << x << "," << #y << "=" << y <<  endl
#define show3(x,y,z) cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z <<  endl
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long double> vld;

const ld eps = 1e-9, pi = acos(-1.0);
const ld EPS = 1e-8;
const int INF = INT_MAX/2;
const ll LINF = LONG_MAX/2;
const int MOD = 1000000007;

template<class T> inline void amin(T &a, const T &b) { if (b<a) a=b; }
template<class T> inline void amax(T &a, const T &b) { if (a<b) a=b; }

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 (a>b) { a=b; return 1; } return 0; }

int main(){
    
    ll k,x;
    cin >> k >> x;
    
    ll l = -1000000;
    ll r =  1000000;
	chmax(l, x - k + 1);
	chmin(r, x + k - 1);
	
	FOR(i,l,r){
	    cout << i << " ";
	}
	cout << r << endl;
	
    //cout << fixed << setprecision(10);
    // cout << ans << endl;
    return 0;
}

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

int main() {
    int A, B, K;
    cin >> A >> B >> K;
    for (int i = min(A, B); i > 0; i--) {
        if (A % i == 0 && B % i == 0) K--;
        if (K == 0) {
            cout << i << endl;
            break;
        }
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>

#define ll long long
#define rr register

#define inf 1e9
#define MAXN 200010

using namespace std;

inline int read() {
	int s = 0, f = 0;
	char ch = getchar();
	while (!isdigit(ch)) f |= ch == '-', ch = getchar();
	while (isdigit(ch)) s = s * 10 + (ch ^ 48), ch = getchar();
	return f ? -s : s;
}

void print(int x) {
	if (x < 0) putchar('-'), x = -x;
	if (x > 9) print(x / 10);
	putchar(x % 10 + 48);
}

int n, m, minn = inf, y = inf;

int a[MAXN];

signed main() {
	m = read();
	n = read();
	for (rr int i = 1; i <= n; i++) a[i] = read();
	for (rr int i = 0; i <= 101; i++) {
		bool f = 1;
		for (rr int j = 1; j <= n; j++)
			if (i == a[j]) f = 0;
		if (!f) continue;
		if (minn > abs(m - i)) {
			minn = abs(m - i);
			y = i;
		}
	}
	cout << y;
}

Measured memory_bytes: 3644
import sys
input = sys.stdin.buffer.readline

def main():
    N = int(input())
    a = [list(map(int,input().split())) for _ in range(N)]
    INF = 10**18+1
    memo = [-INF]*(1<<N)
    for i in range(N):
        memo[1<<i] = 0
    
    def point(x):
        if memo[x] != -INF:
            return memo[x]
        con = []
        for i in range(N):
            if (x>>i)&1:
                con.append(i)
        ret = 0
        for i in con:
            for j in con:
                ret += a[i][j]
        ret //= 2
        T = x
        while T > 0:
            T = (T-1)&x
            if T == 0:
                break
            ret = max(ret,point(T)+point(x^T))
        memo[x] = ret
        return ret

    print(point((1<<N)-1))
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 46684
#include <bits/stdc++.h> 
using namespace std;
using ll = long long;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, const T& t){ return v2<T>(r, vector<T>(c, t)); }
#define F first
#define S second

void solve(){
    int n;
    string s, t;
    cin >> n >> s >> t;
    for(int i = 0; i < n; ++i){
        string s1 = s.substr(i), s2 = t.substr(0,n-i);
        if(s1==s2){
            cout << n+i << '\n';
            return;
        }
    }
    cout << 2*n << '\n';
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 3596
////////////////////////////////////////////
///                                      ///
///         Template ver. 1 rapel        ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>
//#include <chrono>
//#include <random>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>

#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define endl '\n'
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

priority_queue<pair<int,int> >pq[2];

map<int,int> ms[2];

void hora(int tc) {
	int n;
	cin>>n;
	for(int i = 1;i <= n;i++) {
		int x;
		cin>>x;
		ms[i%2][x]++;
	}
	pq[0].push(MP(0,0));
	pq[1].push(MP(0,0));
	for(int i = 0;i < 2;i++) {
		for(map<int,int>::iterator it = ms[i].begin();it != ms[i].end();it++) {
			pq[i].push({it->SE,it->FI});
		}
	}
	int res = 2 * n;
	if(pq[0].top().SE != pq[1].top().SE) {
		res = min(res,n - (pq[0].top().FI + pq[1].top().FI));
	}
	else {
		int u0 = pq[0].top().FI;
		int v0 = pq[0].top().SE;
		int u1 = pq[1].top().FI;
		int v1 = pq[1].top().SE;
		pq[0].pop(), pq[1].pop();
		res = min(res,n - (u0 + pq[1].top().FI));
		res = min(res,n - (u1 + pq[0].top().FI));
	}
	cout<<res<<endl;
}

int main(){
	desperate_optimization(10);
	int ntc = 1;
	//cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) hora(tc);
	return 0;
}



Measured memory_bytes: 6140
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    int r; cin >> r;
    cout << 3*r*r << endl;
    return 0;
}


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

using namespace std;

int main()
{
    long long n, d;
    long long x, y;
    int points = 0;
    cin >> n >> d;
    for(int i=0; i<n; i++){
        cin >> x >> y;
        if(x*x + y*y <= d*d)
            points += 1;
        else
            continue;
    }
    cout << points << '\n';
    return 0;
}


Measured memory_bytes: 3632
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
#define ll long long
int main(){
  ll int n,m,q,ans=0,max=0;
  scanf("%lld%lld%lld",&n,&m,&q);
  ll int a[q],b[q],c[q],d[q],A[11];
  for(int i=1;i<=q;i++){
    scanf("%lld%lld%lld%lld",&a[i],&b[i],&c[i],&d[i]);
  }
  for(int i=1;i<=m;i++){
    A[1]=i;
    for(int j=i;j<=m;j++){
      A[2]=j;
      for(int k=j;k<=m;k++){
        A[3]=k;
        for(int l=k;l<=m;l++){
          A[4]=l;
          for(int z=l;z<=m;z++){
            A[5]=z;
            for(int y=z;y<=m;y++){
              A[6]=y;
              for(int o=y;o<=m;o++){
                A[7]=o;
                for(int p=o;p<=m;p++){
                  A[8]=p;
                  for(int r=p;r<=m;r++){
                    A[9]=r;
                    for(int s=r;s<=m;s++){
                      A[10]=s;
  for(int u=1;u<=q;u++){
    if(A[b[u]]-A[a[u]]==c[u]){
      ans+=d[u];
    }
  }
                      if(max<ans){
                        max=ans;
                      }
                      ans=0;
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  printf("%lld",max);
  return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <math.h> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

//F
//遠くにいく
//X,Yのabsの最大
int main(){
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    ll N;
    cin >> N;

    cout << N/3 << endl;


    return 0;    

}



Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var A = int.Parse(Console.ReadLine());

            Console.WriteLine(N*N-A);
        }
    }
}


Measured memory_bytes: 11092
#!/usr/bin/env python
"""<https://github.com/cheran-senthil/PyRival>"""
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase
from collections import Counter

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
else:
    _str = str
    str = lambda x=b"": x if type(x) is bytes else _str(x).encode()

MOD = 10**9 + 7


def main():
    K, d = list(map(int, input())), int(input())
    n = len(K)

    dp = [[0] * d for _ in range(n)]

    dp0 = dp[0]
    for k in range(10):
        dp0[k % d] += 1

    for i in range(n - 1):
        dpi, dpii = dp[i], dp[i + 1]
        for j in range(d):
            dpii[j] = sum(dpi[(j - k) % d] for k in range(10)) % MOD

    res, k = 0, 0
    for i in range(n - 1):
        dpi = dp[-i - 2]
        res = (res + sum(dpi[(-j - k) % d] for j in range(K[i]))) % MOD
        k += K[i]
    res += sum((k + j) % d == 0 for j in range(K[-1] + 1))

    print((res - 1) % MOD)


# region template

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._buffer = BytesIO()
        self._fd = file.fileno()
        self._writable = "x" in file.mode or "r" not in file.mode
        self.write = self._buffer.write if self._writable else None

    def read(self):
        if self._buffer.tell():
            return self._buffer.read()
        return os.read(self._fd, os.fstat(self._fd).st_size)

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()

    def flush(self):
        if self._writable:
            os.write(self._fd, self._buffer.getvalue())
            self._buffer.truncate(0), self._buffer.seek(0)


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", b" "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", b"\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip(b"\r\n")

# endregion

if __name__ == "__main__":
    main()


Measured memory_bytes: 43036
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
typedef long long ll;
#define N 200002
struct edge{int to,nxxt;}e[N<<1];
int n,H,a[N][4],head[N],cnt=1,b[N][2],f[N],rd[N],cd[N],ct[N];
vector<int>v[N];
inline void ins(int u,int v){e[cnt].to=v;e[cnt].nxxt=head[u];head[u]=cnt++;}
int getroot(int t){return f[t]==-1?t:f[t]=getroot(f[t]);}
int main()
{
    scanf("%d%d",&n,&H);
    memset(f,-1,sizeof(f));
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d%d%d",&a[i][0],&a[i][1],&a[i][2],&a[i][3]);
        int x,y;
        if(a[i][2]==0)x=a[i][0];else x=H+a[i][2];
        if(a[i][3]==0)y=H+a[i][1];else y=a[i][3];
        b[i][0]=x,b[i][1]=y;
        if(x==y)ct[x]++;
        ins(x,y),rd[y]++,cd[x]++;
        x=getroot(x);y=getroot(y);
        if(x^y)f[x]=y;
    }
    for(int i=1;i<=2*H;i++)v[getroot(i)].push_back(i);
    //for(int i=1;i<=2*H;i++)printf("%d ",getroot(i));puts("rt");
    //for(int i=1;i<=2*H;i++)printf("%d ",cd[i]);puts("cd");
    //for(int i=1;i<=2*H;i++)printf("%d ",rd[i]);puts("rd");
    for(int i=1;i<=2*H;i++)
    {
        bool flag=false;
        if(v[i].size()==1){if(ct[v[i][0]]){puts("NO");return 0;}}
        if(v[i].size()<=1)continue;
        //printf("%d:",i);
        for(int j=0;j<v[i].size();j++)
        {
            int x=v[i][j];
            if(rd[x]^cd[x]){flag=true;break;}
        }//puts("");
        if(!flag){puts("NO");return 0;}
    }
    bool flag=true;
    for(int i=1;i<=H;i++)
    {
        if(cd[i]<rd[i]){flag=false;break;}
    }
    for(int i=H+1;i<=2*H;i++)
    {
        if(rd[i]<cd[i]){flag=false;break;}
    }
    if(flag)puts("YES");else puts("NO");
}
/*
3 4
1 1 0 0
2 2 0 1
3 3 1 0
*/

Measured memory_bytes: 12320
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
ll funca(ll n){
  if(n==0)return 1;
  else return funca(n-1)*2+3;
}
ll funcp(ll n){
  if(n==0)return 1;
  else return funcp(n-1)*2+1;
}
ll funcans(ll n,ll x){
  if(x==1){
   if(n!=0) return 0;
   else return 1;
  }
  else if(x>1&&x<funca(n-1)+2)return funcans(n-1,x-1);
  else if(x==funca(n-1)+2)return funcp(n-1)+1;
  else if(x>funca(n-1)+2&&x<funca(n))return funcp(n-1)+1+funcans(n-1,x-2-funca(n-1));
  else return funcp(n);
}
main(){
  ll n,x;
  cin>>n>>x;
  cout<<funcans(n,x)<<endl;
}


Measured memory_bytes: 256
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int M = in.nextInt();
		Queue<Long> queue = new PriorityQueue<>(Collections.reverseOrder());
		for (int i = 0; i < N; i++) {
			queue.add(in.nextLong());
		}
		for (int i = 0; i < M; i++) {
			queue.add(queue.poll() / 2);
		}
		long ans = 0;
		while (!queue.isEmpty()) {
			ans += queue.poll();
		}
		System.out.println(ans);
		in.close();
	}
}

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


int main(){
    int n;
    cin>>n;
    vector<int> v(n+1);
    for(int i = 1; i <= n; i++) cin>>v[i];
    bool f = false;
    int cnt = 1;
    int idx = 1;
    while(n--){
        if(v[idx] == 2){
            f = true;
            break;
        }
        idx = v[idx];
        cnt++;
    }
    cout << (f ? cnt : -1) << endl;
}


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

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define RREP(i, N) for (int i =(int)N-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<int,string> Pis;

int main(){
  int n;
  string s;
  cin>>n;
  cin>>s;
  int sum=0;
  REP(i,n){
    if(s[i]=='A'){
      if(s[i+1]=='B'&&s[i+2]=='C'){
        sum++;
      }
    }
  }
  cout<<sum<<endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename T>
map<T, Int> factorize(T x){
  map<T, Int> res;
  for(Int i=2;i*i<=x;i++){
    while(x%i==0){
      x/=i;
      res[i]++;
    }
  }
  if(x!=1) res[x]++;
  return res;
}

//INSERT ABOVE HERE
signed main(){
  Int a,b;
  cin>>a>>b;

  Int g=__gcd(a,b);
  auto m=factorize(g);
  cout<<m.size()+1<<endl;
  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll N;

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

  cin>>N;
  rep(i,1000000){
    if((ll)floor(1.08*i)==N){
      cout<<i<<endl;
      return 0;
    }
  }
  cout<<":("<<endl;

  return 0;
}


Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}

//-----------------------ここから-----------

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

    vector<string> s(n);

    for(int i = 0; i < n; i++) cin >> s[i];

    ll abcnt = 0;
    ll afin = 0;
    ll d = 0;
    ll bsta = 0;

    for(int i = 0; i < n; i++){
        if(s[i][s[i].size() - 1] == 'A' && s[i][0] == 'B'){
            d++;
        } else if(s[i][s[i].size() - 1] == 'A'){
            afin++;
        } else if(s[i][0] == 'B'){
            bsta++;
        }
        for(int j = 1; j < s[i].size(); j++){
            if(s[i][j - 1] == 'A' && s[i][j] == 'B'){
                abcnt++;
            }
        }
    }

    ll ad = 0;
    if(d == 0){
        ad = min(afin, bsta);
    } else if(afin + bsta > 0){
        ad = d + min(afin, bsta);
    } else if(afin + bsta == 0){
        ad = d - 1;
    }
    cout << abcnt + ad << endl;


}


Measured memory_bytes: 768
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
////////////////////////////////////////

int main() {
	int H, W, D; cin >> H >> W >> D;
	vector<pii>place(H*W + 1);//各数値の座標を記録
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			int A; cin >> A;
			place[A] = { i,j };
		}
	}

	vector<int>mp(H*W + 1);
	for (int i = 1; i <= H * W; ++i) {
		if (i <= D) {
			mp[i] = 0;//始点なので消費魔力0
		}
		else {
			int y1 = place[i - D].first;
			int x1 = place[i - D].second;
			int y2 = place[i].first;
			int x2 = place[i].second;
			mp[i] = mp[i - D] + abs(y1 - y2) + abs(x2 - x1);
		}
	}
	int Q; cin >> Q;
	for (int i = 0; i < Q; ++i) {
		int L, R; cin >> L >> R;
		cout << mp[R] - mp[L] << endl;
	}
	return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
 
const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; //最大値
 
ll dp[MX][MX];
inline void chmax(ll& a, ll b) {
  a = max(a, b);
}
 
#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define PB push_back
 
 
int main(){
    ll a,b,c,d,e;
    cin >> a >> b >> c >> d >> e;
    if (a==0) cout  << 1 << endl;
    else if (b==0) cout  << 2 << endl;
    else if (c==0) cout  << 3 << endl;
    else if (d==0) cout  << 4 << endl;
    else if (e==0) cout  << 5 << endl;
}

Measured memory_bytes: 3592