akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#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 repx(i, x, n) for (int i = int(x); i < int(n); ++i)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define ALL(n) begin(n), end(n)
#define IN(a, x, b) ((a) <= (x) && (x) < (b))
#define OUT(a, x, b) ((x) < (a) || (x) < (b))
typedef long long ll;
typedef long double ld;
const ll INF = 1e18;
const ll MOD = 1000000007;

int main()
{
    ll N, D, cnt = 0, x, y;
    cin >> N >> D;
    rep(i, N) {
        cin >> x >> y;
        if (x * x + y * y <= D * D) {
            cnt++;
        }
    }
    cout << cnt << endl;

    return 0;
}


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

using ll = long long;

bool is_all_same(const string &s) {
  for (int i = 1; i < s.size(); i++) {
    if (s.front() != s.at(i)) {
      return false;
    }
  }
  return true;
}

int solve(const string &s) {
  char pre_char = '+';
  int count = 0;
  int num_to_rewrite = 0;
  for (char c : s) {
    if (c == pre_char) {
      count++;
      if (count % 2 == 0) {
        num_to_rewrite++;
      }
    } else {
      pre_char = c;
      count = 1;
    }
  }
  return num_to_rewrite;
}

int main() {
  string S;
  cin >> S;
  int K;
  scanf("%d", &K);

  // Sが1文字で構成される場合は、|S| * K / 2 を求める
  if (is_all_same(S)) {
    printf("%lld", (ll)S.size() * (ll)K / 2LL);
    return 0;
  }

  string SS = S + S;
  // K = 1, 2 ... とし、書き換える操作を並べると等差数列となる
  // そこで、初項と第二項を求め、K番目を求める
  int first = solve(S);
  int second = solve(SS);
  int diff = second - first;
  printf("%lld", (ll)first + ((ll)diff * (ll)(K - 1)));

  return 0;
}


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

#define MAX_N 200005

using namespace std;

struct UnionFind{

  int par[MAX_N];
  int deph[MAX_N];

  UnionFind(int n){
    fill(par, par + MAX_N, -1);
    for(int i=0; i<n; i++){
      par[i] = i;
      deph[i] = 0;
    }
  }

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

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

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

int main() {

  int N, K, L;
  cin>>N>>K>>L;

  UnionFind ufl(N);
  UnionFind ufr(N);

  for(int i=0; i<K; i++){
    int x, y;
    cin>>x>>y;
    ufl.unite(x-1,y-1);
  }
  for(int i=0; i<L; i++){
    int x, y;
    cin>>x>>y;
    ufr.unite(x-1,y-1);
  }

  map< pair<int, int>, int > m;

  for(int i=0; i<N; i++){
    m[make_pair(ufl.find(i), ufr.find(i))]++;
  }

  for(int i=0; i<N; i++){
    if(i != 0) cout<<" ";
    cout<<m[make_pair(ufl.find(i), ufr.find(i))];
  }
  cout<<endl;

  return 0;
}


Measured memory_bytes: 15104
#include<bits/stdc++.h>
using namespace std;
int read() {
	int x; scanf("%d", &x); return x;	
}
const int maxn = 2e5 + 10;
const int INF = 1e9;
int A, T, R, W;
char s[100];
int main() {
	#ifdef LOCAL
		freopen("1.in", "r", stdin);
	#endif
	int n = read();
	for (int i = 1; i <= n; ++i) {
		scanf("%s", s);
		if (s[0] == 'A') A++;
		else if (s[0] == 'T') T++;
		else if (s[0] == 'R') R++;
		else W++;	
	}
	cout << "AC x " << A << endl;
	cout << "WA x " << W << endl;
	cout << "TLE x " << T << endl;
	cout << "RE x " << R << endl;

	return 0;		
}

Measured memory_bytes: 3760
#define _USE_MATH_DEFINES

#include <vector>
#include <list>
#include <map>
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <utility>
#include <ctgmath>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll mod = 1000000007;
const ll inf = 10e17;
const ld eps = 10e-9;

ll solve(void);

int main(void)
{
	while (solve())
	{
	}
	return 0;
}

ld f(ld theta, ld a, ld b)
{
	ld pt = M_PI_2 - theta;
	ld t = atanl(b / a);
	if (theta > t + eps)
	{
		return b * a * (b * tanl(pt)) * 0.5;
	}
	else
	{
		ld y = b * a * a - a * a * (a * tanl(theta)) * 0.5;
		return y;
	}
}

ll solve(void)
{
	ld a, b, x;
	cin >> a >> b >> x;

	ld v = a * a * b;
	ld ans, c;

	ld l = 0.0, r = M_PI_2;
	
	while (abs(l - r) > 10e-16)
	{
		ld mid = (l + r) * 0.5;
		((f(mid, a, b) < x) ? r : l) = mid;
	}

	ans = (l+r) * 0.5;
	printf("%.10Lf\n", ans * ld(180.0) / ld(M_PI));

	return 0;
}



Measured memory_bytes: 512
#include <cstdio>
#include <queue>
#include <utility>
typedef std::pair<int,int> P;
typedef std::pair<int,P> node;
const int way[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
char s[1005][1005];
int main() {
	int h,w;scanf("%d%d",&h,&w);
	int ans=0;std::queue<node> q;
	for(register int i=1;i<=h;++i) {
		scanf("%s",s[i]+1);
		for(register int j=1;j<=w;++j) {
			if(s[i][j]=='#') q.push(node(0,P(i,j)));
		}
	}
	while(q.size()) {
		node cur=q.front();q.pop();
		for(register int i=0;i<4;++i) {
			int x=cur.second.first+way[i][0];
			int y=cur.second.second+way[i][1];
			if(1<=x&&x<=h&&1<=y&&y<=w&&s[x][y]=='.') {
				s[x][y]='#';q.push(node(cur.first+1,P(x,y)));
			}
		}
		ans=std::max(ans,cur.first);
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 13328
#include <iostream>

using namespace std;
long long sum,digits;
int main(){
    long long n;
    cin>>n;
    for(long long i=1;i<=n;i++){
        long long d,c;
        cin>>d>>c;
        sum+=d*c;
        digits+=c;
    }
    cout<<digits-1 +((sum-1)/9)<<endl;
}


Measured memory_bytes: 256
N, M = map(int, input().split())

A = [None] * N
B = [None] * N

for i in range(N):
    a, b = map(int, input().split())
    A[i] = a
    B[i] = b

C = zip(A, B)
C = sorted(C)

ans = 0
for a, b in C:
    if b >= M:
        ans += a * M
        break
    else:
        ans += a * b
        M -= b

print(ans)


Measured memory_bytes: 18516
k=int(input())
s=input()
ans=0
mod=1000000007
x=2200000
fact=[0]*x
invfact=[0]*x
fact[0]=1
for i in range(1,x):
    fact[i]=fact[i-1]*i%mod
invfact[x-1]=pow(fact[x-1],mod-2,mod)
for i in range(x-2,-1,-1):
    invfact[i]=invfact[i+1]*(i+1)%mod
def nCk(n,k):
    return(fact[n]*invfact[k]*invfact[n-k])%mod
for i in range(0,k+1):
    # print(nCk(len(s)+i-1,i),pow(25,i,mod),pow(26,k-i,mod))
    ans+=nCk(len(s)+i-1,i)*pow(25,i,mod)*pow(26,k-i,mod)
print(ans%mod)

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


struct UnionFind{
   vector<int> par;
   UnionFind(int n):par(n,-1){}
   int find(int x){
       if(par[x]<0)return x;
       return par[x]=find(par[x]);
   }
   bool unite(int x,int y){
       x=find(x);
       y=find(y);
       if(x==y)return false;
       if(par[x]>par[y]){
           par[y]+=par[x];
           par[x]=y;
       }
       else{
           par[x]+=par[y];
           par[y]=x;
       }
       return true;
   }

   bool same(int x,int y){
       return find(x)==find(y);
   }
   int size(int x){
       return -par[find(x)];
   }
};
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<int> x(n),y(n);
    rep(i,n)cin>>x[i]>>y[i];
    vector<int> ord(n);
    rep(i,n)ord[i]=i;
    sort(ord.begin(),ord.end(),[&](int s, int t){
        return x[s]<x[t];
    });
    UnionFind uf(n);
    set<pair<int,int>> st;
    for(auto i:ord){
        auto it = st.begin();
        int mi = y[i];
        while(it!=st.end() && (*it).first < y[i]){
            mi = min(it->first, mi);
            uf.unite(i,it->second);
            it = st.erase(it);
        }
        st.insert({mi,i});
    }
    rep(i,n)cout<<uf.size(i)<<endl;
    return 0;
}

Measured memory_bytes: 11052
#include <cmath>
#include <vector>
#include <map>
#include <functional>
#include <queue>
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>
#include <sstream>

using namespace std;

#define ll long long int
#define ti4 tuple<int,int,int,int>
#define pii pair<ll,ll>
#define REP(x,n) for(int x = 0;x < n;x++)

struct UnionFind {
    vector<ll> data;
    UnionFind(ll size) : data(size, -1) { }
    bool unionSet(ll x, ll 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;
        }
        return x != y;
    }
    bool findSet(ll x, ll y) {
        return root(x) == root(y);
    }
    ll root(ll x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    ll size(ll x) {
        return -data[root(x)];
    }
};

int main()
{
    ll w,h;
    cin >> w >> h;
    vector<ll> p(w);
    vector<ll> q(h);
    vector<pii> pq(w+h);
    for(int i = 0;i < w;i++)
    {
        cin >> p[i];
        pq[i] = make_pair(p[i], i+1);
    }
    for(int i = 0;i < h;i++)
    {
        cin >> q[i];
        pq[i + w] = make_pair(q[i], -i-1);
    }
    sort(pq.begin(), pq.end());
    ll xSum = 0;
    ll ySum = 0;
    ll cost = 0;
    for(auto e : pq)
    {
        if(e.second < 0)
        {
            ll y = max(1LL, w+1-ySum);
            xSum++;
            cost += e.first * y;
        }
        else
        {
            ll x = max(1LL, h+1-xSum);
            ySum++;
            cost += e.first * x;
        }
    }
    cout << cost << endl;
}

Measured memory_bytes: 5120
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;} 
int main(void)
{
  int n,m,np=0,mp=0;
  
  scanf("%d %d",&n,&m);
  
  for(int i=1;i<n;i++)
   np=np+i;
  
  for(int i=1;i<m;i++)
   mp=mp+i;
  
  printf("%d",np+mp);
}

Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
int n, k, ans;
vector<int> a;
void solve() {
    cin >> n >> k;
    a.resize(n);
    int right = 0;
    while (right < n) {
        if (ans == 0) right += k;
        else right += (k - 1);
        ans++;
    }
    cout << ans << endl;
    return;
}
//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}
int main(int args, char* argv[]) {
    solve();
}

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

int main(){
  long n;
  cin >> n;
  long a[n],sum = 0;
  for(long i = 0;i < n;i++){
    cin >> a[i];
  }
  long kekka = 0;
  for(long i = 0;i < n;i++){
    sum += a[i];
    if(i % 2 == 0 && sum >= 0){
      kekka += sum + 1;
      sum = -1;
    }
    if(i % 2 == 1 && sum <= 0){
      kekka += -sum + 1;
      sum = 1;
    }
  }
  long result = 0;
  sum = 0;
  for(long i = 0;i < n;i++){
    sum += a[i];
    if(i % 2 == 0 && sum <= 0){
      result += -sum + 1;
      sum = 1;
    }
    if(i % 2 == 1 && sum >= 0){
      result += sum + 1;
      sum = -1;
    }
  }
  cout << min(kekka,result) << endl;
}

Measured memory_bytes: 1024
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static long cnt=0;
	public static void main(String[] args) throws Exception {
		solution(args);
		if(in!=null){
			in.close();
		}
	}

	public static void solution(String[] args) throws Exception{

		int N = nextInt();
		Node[] p = new Node[N+1];
		for(int i=0;i<=N;i++){
			p[i] = new Node(i);
		}
		Node[] e = new Node[N+1];
		for(int i=1;i<N;i++){
			int a=nextInt();
			int b=nextInt();
			p[a].addChild(p[b]);
			e[i]=p[b];
		}
		p[1].setColor();
		int colors = p[1].getElem(0);
		System.out.println(colors);
		for(int i=1;i<N;i++){
			System.out.println(e[i].color);
		}
	}


	static class Node {
		public static ArrayDeque<Node> queue = new ArrayDeque<>();
		public int p;
		public int color;
		public ArrayList<Node> child=new ArrayList<>();
		public Node(int p){
			this.p=p;


		}
		public void addChild(Node x){
			child.add(x);
		}

		public void setColor(){


			for(Node node:child){
				queue.add(node);
			}

			int colorIdx = 1;
			//親から子への辺に色付けを行う
			for(Node node:child){
				if(colorIdx==color){
					colorIdx++;
				}
				node.color=colorIdx;
				colorIdx++;
			}
			Node ch = queue.poll();
			if(ch!=null){
				ch.setColor();
			}
		}

		public int getElem(int p){
			int cnt = child.size()+p;
			for(Node node:child){
				cnt=Math.max(cnt, node.getElem(1));
			}
			return cnt;
		}


	}
	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


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

#define i64 long long int
#define ran 101101

i64 q[ran];
int l, r;

int n;

int main() {
	for(int i=1;i<=9;i++)
		q[i] = i;
	l = 1; r = 10;
	
	scanf("%d", &n);
	while(r<=n) {
		i64 cur = q[l++];
		int last = cur % 10;
		for(int i=-1;i<=1;i++) {
			int nxt = last + i;
			if(nxt<0||nxt>9) continue;
			q[r++] = cur*10+nxt;
		}
	}
	printf("%lld\n", q[n]);
	
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef long double ld;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll x;

    cin >> x;

    if(x%11==0){
        cout << x/11*2 << endl;
    }

    else{
        if(x%11<=6){
            cout << x/11*2+1 << endl;
        }
        else{
            cout << x/11*2+2 << endl;
        }
    }

    return 0;
}

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

int main(int argc, char *argv[])
{
	int i, j, k, work[2][200], work2, size;
	

	for (i = 0; i < 200; i++)
		if (scanf("%d %d", &work[0][i], &work[1][i]) == EOF)
			break;
	size = i;

	for (k = 0; k < size; k++) {
		work[0][k] += work[1][k];

		for (i = 0; work[0][k] > 0;i++)
			work[0][k] = work[0][k] / 10;

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

	}

	return 0;
}

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

using namespace std;

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

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(pi c, pi d){
	return c.S < d.S;
}

int main() {
	int N;
	string s, t;
	
	cin >> N >> s >> t;
	int d = N;
	REP(i, 0, N){
		string l = s.substr(i, d);
		string r = t.substr(0, d);
		if(l == r){
			cout << i + (int)l.size() + N-(int)l.size();
			exit(0);
		}
		--d;
	}
	cout << 2*N;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

int N;

int main() {

	scanf("%d", &N);



	printf("%d\n", N*N*3);
	
	return 0;
}


Measured memory_bytes: 764
n = gets.to_i
c = [0, 0, 0]
a = gets.split.map do |e|
    e = e.to_i
    c[e <=> 0] += 1
    e.abs
end

sum = a.inject(:+)
if c[-1].even? || c[0] > 0
    puts sum
else
    puts sum - a.min * 2
end


Measured memory_bytes: 8580
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
#from decimal import *

N, A, B = MAP()
X = LIST()

tmp = X[0]
ans = 0
for x in X:
	ans += min((x-tmp)*A, B)
	tmp = x

print(ans)



Measured memory_bytes: 16324
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

int n;
int main(void) {
	
	cin >> n;
	ll p = 1;
	for (int i = 1; i <= n; i++)
	{
		p = (i * p) % 1000000007;
	}
	cout << p << endl;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int n, a, sum = 0;
  cin >> n;
  rep(i, n) cin >> a, sum += a;

  sum -= n;

  cout << sum << endl;
  return 0;
}


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

using namespace std;
typedef long long ll;

int main() {
    int n;  ll a, b, ans = 0;    cin >> n >> a >> b;
    vector<ll> x(n);
    for (int i = 0; i < n; i++)
        cin >> x[i];

    for (int i = 0; i < n-1; i++)
        ans += min(a*(x[i+1]-x[i]), b);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4048
import math
   
def prime(num):
  if num==1 or num==2 or num==3:
    return True
  for i in range(2,int(math.sqrt(num))+1):
    if num%i==0:
      return False
  else:
    return True
   
n=int(input())
ans=0
for i in range(n):
  tmp=int(input())
  if prime(tmp):
    ans+=1
print(ans)


Measured memory_bytes: 5680
N, M = map(int, input().split())
piys = [[] for _ in range(N + 1)]

for i in range(1, M + 1):
  p, y = map(int, input().split())
  piys[p].append((i, y))

ins = []
for p, iys in enumerate(piys):
  if not len(iys):
    continue
  iys.sort(key=lambda iy:iy[1])
  for x in range(1, len(iys) + 1):
    n = "{:06d}{:06d}".format(p, x)
    ins.append((iys[x - 1][0], n))

ins.sort(key=lambda in_:in_[0])
for i, n in ins:
  print(n)


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

int main(){
  int n, q;
  cin >> n >> q;
  string ans = "kogakubu10gokan";
  for(int i = 0 ; i < n ; i++ ){
    int year;
    string name;
    cin >> year >> name;
    if(year <= q) ans = name;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1208
def kakuritsu(dice_me):
    tokuten = dice_me
    kurikaesi = 0
    while tokuten < K:
        tokuten = tokuten * 2
        kurikaesi += 1
    # print('kurikaesi', kurikaesi)
    test_list.append(1 / N * (1 / 2) ** kurikaesi)


N, K = map(int, input().split())
test_list = []

for i in range(N):
    kakuritsu(i + 1)

print(sum(test_list))


Measured memory_bytes: 6296
#include<bits/stdc++.h>
using namespace std;
const int M=1e5+1;
bool dp[M];
int n,k,a[102];
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=k;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(i>=a[j])
			dp[i]|=!dp[i-a[j]];
		}
	}
	if(dp[k])
	cout<<"First";
	else
	cout<<"Second";
	return 0;
}

Measured memory_bytes: 384
n, k = gets.split.map(&:to_i)
arr = []
n.times do
  ab = gets.split.map(&:to_i)
  arr << ab
end

arr.sort!{|a, b| a[0] <=> b[0] }

require 'irb'
current = 0
arr.each do |ab|
  current += ab[1]
  if current >= k
    puts ab[0]
    exit
  end
end


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

int main(){
    int A,B,ans;
    ans=0;
    cin>>A>>B;

    for(int i=0;i<=B-A;i++){
        if((A+i)/10000==(A+i)%10 && (A+i)/1000%10==(A+i)/10%10)ans++;
    }

    cout<<ans<<endl;
}


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

int main() {
  int N;
  cin >> N;
  
  int sum = 0;
  
  for (int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r;
    
    sum += r - l + 1;
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool vis[200009];
main()
{
    vector<long long int>v;
    long long int n,i,j,k,l,m,cnt=-1;
    cin>>n>>k;
    long long int a[n+1];
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    i=1;
    while(cnt<k)
    {
        if(vis[i]==false)
        {
            v.push_back(i);
            vis[i]=true;
            i=a[i];
            cnt++;
        }
        else
        {
            break;
        }
    }
    if(cnt==k)
    {
        cout<<v[k]<<endl;
    }
    else
    {
        k-=(cnt+1);
        //cout<<k<<endl;
        for(j=0;j<v.size();j++)
        {
            if(v[j]==i)
            {
                break;
            }
        }
        l=v.size()-j;
       // cout<<l<<endl;
        cout<<v[j+(k%l)]<<endl;
    }
}



Measured memory_bytes: 7128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,a,b) for(int i=int(a);i<(int)b;++i)
#define Graph vector<vecctor<ll>>
#define pairs vector<pair<ll,ll>>
#define pb push_back



using namespace std;
using ll = long long;
const ll INF = 1e18;
const double PI = acos(-1);

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







int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<int>dir(n);
    vector<pair<ll,ll>>a(n);
    rep(i,n){
        int x,y;
        char s;
        cin >> x >> y >> s;
        a[i] = make_pair(x,y);
        if(s == 'U'){
            dir[i] = 0;
        }else if(s == 'R'){
            dir[i] = 1;
        }else if(s == 'D'){
            dir[i] = 2;
        }else if(s == 'L'){
            dir[i] = 3;
        }
    }
    ll ans = INF;
    rep(q,4){
        {
        map<ll,vector<pair<ll,ll>>>mp;
        rep(i,n){
            if(dir[i] == 0 || dir[i] == 2){
                mp[a[i].first].pb(make_pair(a[i].second,dir[i]));
            }
        }
        for(auto x : mp){
            sort(x.second.begin(),x.second.end());
            for(int i = 1; i < x.second.size();i++){
                if(x.second[i].second == 2 && x.second[i-1].second == 0){
                    ans = min(x.second[i].first - x.second[i-1].first,ans);
                }
            }
        }
        }
        {
            map<ll,vector<pair<ll,ll>>>mp;
            rep(i,n){
                if(dir[i] == 2 || dir[i] == 3){
                    mp[a[i].first + a[i].second].pb(make_pair(a[i].second,dir[i]));
                }
            }
            for(auto x : mp){
                sort(x.second.begin(),x.second.end());
                for(int i = 1; i < x.second.size();i++){
                    if(x.second[i].second == 2 && x.second[i-1].second == 3){
                        ans = min(ans,x.second[i].first*2-x.second[i-1].first*2);
                    }
                }
            }
        }
        rep(i,n){
            ll tx = a[i].first,ty = a[i].second;
            a[i].first = ty;
            a[i].second = -tx;
            dir[i] = (dir[i] + 1)%4;
        }
        
    }

    if(ans == INF){
        cout << "SAFE" << endl;
    }else{
        cout << ans*5 << endl;
    }
    return 0;
}


Measured memory_bytes: 28568
#include "bits/stdc++.h"

using namespace std;
using ll = long long;

int main() {
    ll n, k, x, y; cin >> n >> k >> x >> y;
    ll m = min(n, k);
    ll ans = m * x;
    n -= m;
    ans += (n * y);
    cout << ans << endl;
}

Measured memory_bytes: 3568
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
#define int long long
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF (long long)(1e18)
#define MOD (int)(1e9+7)
#define MAX_N 103
#define MAX_V 10
#define MAX_M 101
#define yn(f) (f?"Yes":"No")
#define YN(f) (f?"YES":"NO")
#define pro "はいプロ　世界一○○が上手　○○界のtourist　○○時代の終焉を告げる者　実質○○　○○するために生まれてきた男"

signed main(){
	int n, temp[100] = {2,1};
	
	cin>>n;
	for(int i = 2; i <= n; i++){
		temp[i] = temp[i-1] + temp[i-2];
	}
	
	cout<<temp[n]<<endl;
	return 0;
}

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

using namespace std;

const int MAX = 1e9;
int n, k, w[100000], sumw = 0;

bool allocation(int m) {
    int sum = 0, cnt = 0;

    for (int i = 0; i < n; i++) {
        if (w[i] > m) return false;
        if (sum + w[i] > m) {
            if (++cnt >= k) return false;
            sum = w[i];
        } else {
            sum += w[i];
        }
    }
    return true;
}

int main() {
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; i++) {
        scanf("%d", &w[i]);
        sumw += w[i];
    }

    int l = 0, r = sumw + 1, m;
    while (l < r) {
        m = (l + r) / 2;
        if (allocation(m)) {
            r = m;
        } else {
            l = m + 1;
        }
    }
    
    printf("%d\n", l);
    return 0;
}


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" ";
#define LOGE if(DEBUG)cout<<endl;

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


int main(){

	lli n;
	cin>>n;

	vector<lli> a(n);
	lli sum=0;
	REP(i,0,n){
		cin>>a[i];
		sum += a[i];
		a[i]*=n;
	}

	lli ans=INF;
	lli ansI = -1;

	REP(i,0,n){
		if(ans>abs(sum-a[i])){
			ans = abs(sum-a[i]);
			ansI=i;
		}
	}

	cout<<ansI<<endl;



    return 0;
}


Measured memory_bytes: 3568
from collections import Counter
import sys
m =input()

m_list =  list(m)
#print(m_list)
m_dict = Counter(m_list)
#print(m_dict)
ans_list = m_dict.values()
for i,e in enumerate(ans_list):
    if e%2 !=0:
        print("No")
        sys.exit()
print("Yes")
    


Measured memory_bytes: 3316
# ABC136B
N = int(input())
if N < 10:
    print(N)
elif N < 100:
    print(9)
elif N < 1000:
    print(N -90)
elif N < 10000:
    print(909)
elif N < 100000:
    print(N-9090)
elif N < 1000000:
    print(90909)
else:
    print(90910)

Measured memory_bytes: 3060
// latin squares reference https://www.cut-the-knot.org/arithmetic/latin2.shtml
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ldbl;
typedef pair<int,int> P;

#define FOR(i, init, n) for(int i = init; i < (n); i++)
#define pb push_back

// from codeforces
#define what_is(x) cerr << #x << " is " << x << endl;
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))

int big_number = 1<<30;
ll mod = 1e9+7;
const int N = 100005;

int n, k, a[N], t, ans, temp;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n >> k;
	for (int i = 0; i < n; i++) {cin >> a[i]; if(a[i]==1) t = i;}

	ans = mod;

	for (int i = t-(k-1); i <= t; i++) {
		temp = 1+(i/(k-1))+(i%(k-1)!=0?1:0)+(i+k-1<n?(n-1-(i+k-1))/(k-1)+((n-1-(i+k-1))%(k-1)!=0?1:0):1);
		ans = min(ans,temp);
	}

	cout << ans << endl;

	return 0;
}
// notes
//


Measured memory_bytes: 640
import java.util.Scanner;

public class Main { 
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] A1 = new int[N];
    int[] A2 = new int[N];
    for (int i =0; i<N; i++) {
      A1[i] = sc.nextInt();
    }
    for (int i =0; i<N; i++) {
      A2[i] = sc.nextInt();
    }
    int max =0;
    for (int k =0; k<N; k++) { //2行目に行くタイミング
      int ans =0;
      for (int i =k; i<N; i++) {
        ans += A2[i];
      }
      for (int j =0; j<=k; j++) {
        ans += A1[j];
      }
      max = Math.max(ans,max);
    }
    System.out.println(max);  
  }
}    

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

int main() {
	int N, M;
	cin >> N >> M;
	vector<pair<int, int>> stu(N);
	for (int i = 0;i < N;++i) {
		cin >> stu[i].first >> stu[i].second;
	}
	vector<pair<int, int>> che(M);
	for (int i = 0;i < M;++i) {
		cin >> che[i].first >> che[i].second;
	}
	for (int i = 0;i < N;++i) {
		int man = -1;
		int ans;
		for (int j = 0;j < M;++j) {
			int way = abs(che[j].first - stu[i].first) + abs(che[j].second - stu[i].second);
			if (man < 0) {
				man = way;
				ans = j + 1;
			}
			else if (man > way) {
				man = way;
				ans = j + 1;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

public class Test
{
	public static void Main()
	{
		
		var a = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
		int n = a[0];
		int k = a[1];
		var p = Console.ReadLine().Split().Select(y => int.Parse(y)).ToArray();
		Array.Sort(p);
		int ans = 0;
		for(int i=0;i!=k;i++){
			ans += p[i];
		}
		Console.WriteLine(ans);
		
		
	}
}

Measured memory_bytes: 28656
//Md. Shajibul Islam..
//East West University, CSE Department'19

#include<bits/stdc++.h>
using namespace std;
#define FAST       ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define loop(i,n)        for(int i=0;i<n;i++)
#define CASE_PRINT       cout<<"Case "<<C<<": "
#define CASE_PRINT2       cout<<"Case "<<C<<":"<<endl
#define ll               long long
#define ld               long double
#define Pi               2*acos(0.0) // acos(-1.0)

int main()
{
    FAST;
   ll n,d;cin>>n>>d;
   int cnt=0;
   ll num = d*d;
   while(n--)
   {
       ll a,b;cin>>a>>b;
       a=abs(a);b=abs(b);
       a*=a;b*=b;

       if(a+b<=num)cnt++;
   }

   cout<<cnt<<endl;
}





Measured memory_bytes: 3624
#include<stdio.h>
#include<vector>
#include<cmath>

using namespace std;

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

int main(){
  int n;
  long long sum,ans=9999999999999999;
  scanf("%d",&n);
  vector<long long> vi(n,0);
  vector<long long> va(n,0);
  REP(i,n) scanf("%lld",&vi[i]);
  REP(i,n) va[i] = vi[i];
  REP(i,n-1) va[i+1] += va[i];
  for(int i=n-1;i>0;--i) vi[i-1] += vi[i];
  REP(i,n-1){
    sum = abs(va[i]-vi[i+1]);
    if(ans > sum) ans = sum;
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    string a,b,c;
    cin >> a >> b >> c;
    vector<string>hoge = {a,b,c};
    sort(all(hoge),greater<string>());
    a = hoge.front();
    b = hoge[1];
    c = hoge[2];
    cout << max((stoi(a+b) + stoi(c)),stoi(a) + stoi(b + c)) << endl;
}




Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<cmath>
#include<limits>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 100000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
using namespace std;

template<typename T>
T gcd(T a, T b) {
    if (a > b) {
        T c = a;
        a = b;
        b = c;
    }
    if (a == 0) {
        return b;
    }

    return gcd(b % a, a);
}
template<typename T>
T gcd_of_all(vector<T> v) {
    T temp = v[0];
    for (T elem : v) {
        temp = gcd(temp, elem);
    }

    return temp;
}
int main() {
	int K; cin >> K;
	ll cnt = 0;
	for (int i = 1; i <= K; i++) {
		for (int j = 1; j <= K; j++) {
			for (int k = 1; k <= K; k++) {
				vi vec = { i,j,k };
				cnt += gcd_of_all(vec);
			}
		}
	}

	cout << cnt << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define LLI long long int

int main() {
    // freopen("in.txt", "r", stdin);

    int n, x, c = 0;
    for (cin >> n; n--; ) {
        cin >> x;
        if (!(x & 1) && x != 2) {
            continue;
        }
        bool f = false;
        for (int i = 3; i <= sqrt(x) + 1; i += 2) {
            if (x % i == 0) {
                f = true;
                continue;
            }
        }
        if (!f) c++;
    }
    cout << c << endl;

    return 0;
}



Measured memory_bytes: 3092
H,W = map(int,input().split())
S = [list(input()) for _ in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            cnt = 0
            for di in [-1,0,1]:
                for dj in [-1,0,1]:
                    if di == 0 and dj == 0:
                        continue
                    ni = i + di; nj = j + dj
                    if not(0 <= ni <= H-1 and 0 <= nj <= W-1):
                        continue
                    if S[ni][nj] == "#":
                        cnt += 1
            S[i][j] = str(cnt)

for line in S:
    print("".join(line))

Measured memory_bytes: 3188
// One Batch Two Batch Penny and Dime

#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define hii cout << "hii" << endl
#define int long long
#define endl '\n'
#define all(s) s.begin(), s.end()
 
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE

const int N = 5e5 + 5;
const int MAXN = 1e6 + 5;
const int M = 1e6 + 5;
const int mod = 998244353;
const int MOD = 998244353;
const int INF = 1e18 + 8;
const int LG = 21;

int arr[M];
int cnt[M];

void solve()
{
	int n, x, m;
	cin >> n >> x >> m;
	vector<int> v;
	v.push_back(x);
	cnt[x] = 1;
	int no = -1;
	for(int i = 1; i < n and no == -1; i++)
	{
		int now = (v[i - 1] * v[i - 1]) % m;
		if(cnt[now]) no = now;
		else v.push_back(now);
		cnt[now]++;
	}
	int sum = 0;
	if(v.size() >= n)
	{
		for(int x : v)
		{
			sum += x;
		}
		cout << sum << endl;
		return;
	}
	else
	{
		bool yep = 0;
		vector<int> cycle;
		for(int i = 0; i < v.size(); i++)
		{
			if(cnt[v[i]] == 1 and !yep)
			{
				sum += v[i];
				n--;
			}
			else
			{
				cycle.push_back(v[i]);
				yep = 1;
			}
		}
		int len = cycle.size();
		int mul = n / len;
		for(int i = 0; i < len; i++)
		{
			sum += (mul) * cycle[i];
			n -= mul;
		}
		for(int i = 0; i < n; i++)
		{
			sum += cycle[i];
		}
		cout << sum << endl;
	}

}


 
int32_t main() 
{	
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	    int t = 1;
	    // cin >> t;
	while(t--)solve();
	return 0;
}

Measured memory_bytes: 4996
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (1E9+7)
#define PI 3.1415926535897932384

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

std::ostream &operator<<(std::ostream &out, const vector<ll> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

int main() {
	ll n, ans = 0, in;
	vector<ll> a, b, c;
	cin >> n;
	vector<ll> d(n), e(n);
	rep(i, n) {
		cin >> in;
		a.push_back(in);
	}
	rep(i, n) {
		cin >> in;
		b.push_back(in);
	}
	rep(i, n) {
		cin >> in;
		c.push_back(in);
	}
	sort(all(a));sort(all(b));sort(all(c));
	int t = 0;
	rep(i, n) {
		while (t < n && a[t] < b[i]) {
			t++;
		}
		d[i] = t;
	}
	t = 0;
	rep(i, n) {
		int j = n - i - 1;
		while (t < n && c[n - t - 1] > b[j]) {
			t++;
		}
		e[j] = t;
	}
	//cout << a << endl << b << endl << c <<endl;
	//cout << d << endl << e << endl ;
	rep(i, n) {
		ans += d[i] * e[i];
	}
	cout << ans << endl;
}


Measured memory_bytes: 4852
#include <iostream>

using namespace std;

long long int a[3005], dp[3005][3005][2];

//dp[l][r][p] = optimal value of (X-Y) when array is from l to r and
//it is players p's turn
long long int solve(int l, int r, int p)
{
    if(dp[l][r][p] != (long long int)(1e15))
        return(dp[l][r][p]);
    if(l == r)
    {
        if(p == 1) return(-a[l]);
        return(a[l]);
    }
    if(p == 0)
        dp[l][r][p] = max(a[l]+solve(l+1, r, 1-p), a[r]+solve(l, r-1, 1-p));
    else
        dp[l][r][p] = min(-a[l]+solve(l+1, r, 1-p), -a[r]+solve(l, r-1, 1-p));
    return(dp[l][r][p]);
}

int main()
{
    int n;
    long long int ans;
    cin >> n;
    for(int i=0;i<n;i++)
        cin >> a[i];
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            dp[i][j][0] = dp[i][j][1] = (long long int)(1e15);
    ans = solve(0, n-1, 0);
    cout << ans << endl;
    return(0);
}

Measured memory_bytes: 141312
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

alphabet={}
("a".."z").to_a.each do|key|
    alphabet[key]=0
end
W=get_nsp
W.each do|w|
    alphabet[w]+=1
end
flag=true
alphabet.each do|key,i|
  unless i.even? 
      flag=false
      break
  end
end
puts yn_judge(flag)

Measured memory_bytes: 2044
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 100005

ll N,X;
ll A[SIZE];

int main(){

	scanf("%lld %lld",&N,&X);

	scanf("%lld",&A[0]);

	ll ans = 0;

	//より右のキャンディを多く食べるのが適切なはず

	for(int i = 1; i < N; i++){

		scanf("%lld",&A[i]);
		if(A[i]+A[i-1] > X){
			ll diff = (A[i]+A[i-1]-X);
			if(A[i] >= diff){

				A[i] -= diff;
				ans += diff;
			}else{

				ans += A[i];
				diff -= A[i];
				A[i] = 0;

				A[i-1] -= diff;
				ans += diff;
			}
		}
	}

	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 1024
N = int(input())
B = list(map(int,input().split()))

n = N-1
aSum = 0

for i in range(n):

	if i == 0:
		aSum = B[i]
	elif i == n:
		break
	else:
		aSum = min(B[i],B[i-1])+aSum
aSum = B[n-1]+aSum



print(aSum)

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    sort(a.rbegin(), a.rend());

    ll ans = 0;
    int lim;
    int t = n-1;
    rep(i,n) {
        
        if (i == 0) {
            lim = 1;    
        }
        else {
            lim = 2;
        }
        rep(j,lim) {
            if (t > 0) {
                ans += a[i];
                t--;
            }

        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 4000
#include<iostream>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;

int main()
{
    int K,X;
    cin>>K>>X;
    if(500*K>=X)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
const int INT_INF = 1001001001;
//stoi(s) : string→int stoll(s) :string→longlong
const double PI=3.14159265358979323846;


int main(){
    int n,x,y;
    cin >> n >> x >> y;
    x--;
    y--;
    Graph G(n);
    G[0].push_back(1);
    G[n-1].push_back(n-2);
    for(int i=1;i<n-1;i++){
        G[i].push_back(i+1);
        G[i].push_back(i-1);
    }    
    G[x].push_back(y);
    G[y].push_back(x);
    /*
    for(int i=0;i<n;i++){
        for(auto x:G[i]){
            cout << x+1 << " ";
        }
        cout << endl;
    }
    */

    vector<int> ans(n,0);
    for(int i=0;i<n;i++){
        vector<int> dist(n,-1);
        queue<int> que;

        dist[i] = 0;
        que.push(i);

        while(!que.empty()){
            int v = que.front();
            que.pop();
            for(int nv:G[v]){
                if(dist[nv] != -1) continue;
                dist[nv] = dist[v] + 1;
                que.push(nv);
            }
        }

        for(int j=0;j<n;j++){
            ans[dist[j]]++;
        }
    }

    for(int i=1;i<n;i++){
        cout << ans[i] / 2 << endl;
    }


}

Measured memory_bytes: 384
#include <stdio.h>

int main() {
  int number_of_questions, i, sum = 0, kind_of_drinks, i_th_question, i_th_question_time;
  scanf("%d", &number_of_questions);
  int time[number_of_questions];
  for(i = 0; i < number_of_questions; i++) {
    scanf("%d", &time[i]);
    sum += time[i];
  }
  scanf("%d", &kind_of_drinks);
  for(i = 0; i < kind_of_drinks; i++) {
    scanf("%d %d", &i_th_question, &i_th_question_time);
    i_th_question--;
    printf("%d\n", sum + i_th_question_time - time[i_th_question]);
  }
  return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
int n,a[105],sum = 0, num = 0,cnt = 0,vis[10];

int main(){
	scanf("%d",&n);
	for(int i = 1; i <= n; i++){
		scanf("%d",&a[i]);
		if(a[i] >= 1 && a[i] <= 399) vis[1] = 1;
		if(a[i] >= 400 && a[i] <= 799) vis[2] = 1;
		if(a[i] >= 800 && a[i] <= 1199) vis[3] = 1;
		if(a[i] >= 1200 && a[i] <= 1599) vis[4] = 1;
		if(a[i] >= 1600 && a[i] <= 1999) vis[5] = 1;
		if(a[i] >= 2000 && a[i] <= 2399) vis[6] = 1;
		if(a[i] >= 2400 && a[i] <= 2799) vis[7] = 1;
		if(a[i] >= 2800 && a[i] <= 3199) vis[8] = 1;
		if(a[i] >= 3200) cnt++;
	}
	for(int i = 1; i <= 8; i++) if(vis[i]) num++;
    sum = cnt + num;
    if(cnt == n) printf("1 %d", cnt);
    else
	printf("%d %d", num , sum);
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void){
  int a;
  int cnt[2] = {0,0};

  for(int i = 0;i < 3;i++){
    scanf("%d",&a);
    if(a == 5) cnt[0]++;
    if(a == 7) cnt[1]++;
  }

  if(cnt[0] == 2 && cnt[1] == 1) printf("YES\n");
  else printf("NO\n");


  return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

	int c[3][3];

	for (int i = 0;i < 3;i++){
		for (int j = 0;j < 3;j++){
			cin >> c[i][j];
		}
	}

	int a[3]; a[0] = 0;
	a[1] = c[0][1] - c[0][0]; a[2] = c[0][2] - c[0][0];

	int b[3]; b[0] = 0;
	b[1] = c[1][0] - c[0][0]; b[2] = c[2][0] - c[0][0];

	bool ans = true;

	for (int i = 0;i < 3;i++){
		for (int j = 0;j < 3;j++){
			if(c[i][j] != c[0][0]+a[j]+b[i]) ans = false;
		}
	}

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

	return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,x,y,z,e,b;
    cin>>a>>b;
    x=a+b;
    y=a-b;
    z=a*b;
    e=max(x,y);
    cout<<max(e,z);


  return 0;
}


Measured memory_bytes: 256