akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }

int N;
vector<vector<int>> roads;
vector<int> c, d;
int cnt = 0;

void dfs(int now, int back){
    d[now] = c[cnt];
    cnt++;
    for(int i: roads[now]){
        if(i != back){
            dfs(i, now);
        }
    }
}

int main(){
    cin >> N;
    roads.resize(N);
    for(int i = 0; i < N - 1; i++){
        int a, b;
        cin >> a >> b;
        a--, b--;
        roads[a].push_back(b);
        roads[b].push_back(a);
    }
    c.resize(N);
    cins(all(c));
    sort(all(c), greater<>());
    d.resize(N);
    dfs(0, -1);
    cout << accumulate(c.begin() + 1, c.end(), 0) << endl;
    array_output(all(d));
}


Measured memory_bytes: 1536
#include <iostream>

using namespace std;

int main(void){
	int r,g,b;
	int num;
	cin >> r >> g >> b;
	num = r*100 + g * 10 + b;

	if( (num % 4) == 0){
		cout << "YES";
	}else {
		cout << "NO";
	}
	cout << '\n';
	return 0;
}

Measured memory_bytes: 256
#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 pb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

#define eps (1e-10)
struct Point{
    double x,y;
    Point(){}
    Point(double x,double y):x(x),y(y){}
    Point operator+(Point p) {return Point(x+p.x,y+p.y);}
    Point operator-(Point p) {return Point(x-p.x,y-p.y);}
    Point operator*(double k){return Point(x*k,y*k);}
    double norm(){return x*x+y*y;}
    double abs(){return sqrt(norm());}
    bool operator == (const Point &p) const{
    return fabs(x-p.x)<eps && fabs(y-p.y)<eps;
  }
  double dot(Point p){return x*p.x+y*p.y;}
  double det(Point p){return x*p.y-y*p.x;}
};
struct Line{
  Point p1,p2;
  Line(){}
  Line(Point p1, Point p2):p1(p1),p2(p2){}
};
int ccw(Point a,Point b,Point c){
  Point t1=b-a,t2=c-a;
  if(t1.det(t2)> eps) return 1;//counter clockwise
  if(t1.det(t2)< -eps) return -1;//clockwise
  if(t1.dot(t2)< -eps) return 2;//c-a-b online
  if(t1.norm()<t2.norm()) return -2;//a-b-c online
  return 0;//a-c-b online
}
bool intersectSS(Point a,Point b,Point c,Point d){
  return (ccw(a,b,c)*ccw(a,b,d)<=0&&ccw(c,d,a)*ccw(c,d,b)<=0);
}
bool intersectSS(Line l1,Line l2){
  return intersectSS(l1.p1,l1.p2,l2.p1,l2.p2);
}
bool isOrthogonal(Point a,Point b){
  return fabs(a.dot(b))<eps;
}
bool isOrthogonal(Point a1,Point a2,Point b1,Point b2){
  return isOrthogonal(a1-a2,b1-b2);
}
bool isParallel(Point a,Point b){
  return fabs(a.det(b))<eps;
}
bool isParallel(Point a1,Point a2,Point b1,Point b2){
  return isParallel(a1-a2,b1-b2);
}
Point CrossPoint(Line l1,Line l2){
    double a=(l1.p2-l1.p1).det(l2.p2-l2.p1);
    double b=(l1.p2-l1.p1).det(l1.p2-l2.p1);
    if(fabs(a)<eps&&fabs(b)<eps) return l2.p1;
    return l2.p1+(l2.p2-l2.p1)*(b/a);
}
Point project(Line l,Point p){
  Point base=l.p2-l.p1;
  double r=(p-l.p1).dot(base)/base.norm();
  return l.p1+base*r;
}
Point reflect(Line l,Point p){
  return p+(project(l,p)-p)*2.0;
}
double distance(Line l,Point p){
    Point r=project(l,p);
    if(abs(ccw(l.p1,l.p2,r))==0) return (p-r).abs();
    else return min((p-l.p1).abs(),(p-l.p2).abs());
}
int main(){
    int q;
    double xp0,yp0,xp1,yp1,xp2,yp2,xp3,yp3;
    cin>>q;
    while(q--){
        cout<<fixed<<setprecision(10);
        cin>>xp0>>yp0>>xp1>>yp1>>xp2>>yp2>>xp3>>yp3;
        Point p0(xp0,yp0),p1(xp1,yp1),p2(xp2,yp2),p3(xp3,yp3);
        if(intersectSS(p0,p1,p2,p3)) cout<<0.0<<endl;
        else cout<<min(min(distance(Line(p0,p1),p2),distance(Line(p0,p1),p3)),
        min(distance(Line(p2,p3),p0),distance(Line(p2,p3),p1)))<<endl;
    }
    return 0;
}


Measured memory_bytes: 3292
#include <stdio.h>


// 配列で小さいうちから2つ選んで、その和を返す
int sumMin(int *arr) {
  if (arr[0] + arr[1] > arr[1] + arr[2]) {
    if (arr[1] + arr[2] > arr[2] + arr[0]) {
      return arr[2] + arr[0];
    } else {
      return arr[1] + arr[2];
    }
  } else {
    if (arr[0] + arr[1] > arr[2] + arr[0]) {
      return arr[2] + arr[0];
    } else {
      return arr[0] + arr[1];
    }
  }
}

int main() {
  int arr[3];
  scanf("%d %d %d", arr, arr+1, arr+2);
  printf("%d\n", sumMin(arr));
  return 0;
}


Measured memory_bytes: 128
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int r = sc.nextInt();
    int s = sc.nextInt();
    int p = sc.nextInt();
    char[] c = sc.next().toCharArray();
    int score = 0;
    ArrayList<Character> list = new ArrayList<>();
    for(int i=0;i<n;i++)list.add(c[i]);
    for(int i=k;i<list.size();i++)
      if(list.get(i)==list.get(i-k))list.set(i,'n');
    for(char u:list){
      if(u=='r')score+=p;
      else if(u=='s')score+=r;
      else if(u=='p')score+=s;
    }
    System.out.println(score);
  }
}

Measured memory_bytes: 28140
def nankai(Me):
    cnt = 0
    for j in range(20):
        if K-1 >= Me*(2**j):
            cnt +=1
        else: break
    return cnt

      
N, K = map(int,input().split())
P=[(1/N)*(1/2)**nankai(i) for i in range(1,N+1)]
print(sum(P))

Measured memory_bytes: 6296
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef long long int lli;

int main() {
  int i, j;
  // scanf("%[^\n]%*c", a);
  lli n;
  char str[200001];

  scanf("%[^\n]%*c", str);

  i = 0;
  lli ind_sum = 0;
  lli wc = 0;
  while (str[i] != '\0') {
    if (str[i] == 'W') {
      ind_sum += i;
      wc += 1;
    }
    i++;
  }

  lli mini = (wc - 1) * (wc) / 2;

  printf("%lld", ind_sum - mini);

  return 0;
}

Measured memory_bytes: 384
import sys
import math
def i():return int(sys.stdin.readline().replace("\n",""))
def i2():return map(int,sys.stdin.readline().replace("\n","").split())
def s():return str(sys.stdin.readline().replace("\n",""))
def l():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def lx():return list(map(lambda x:int(x)*-1,sys.stdin.readline().replace("\n","").split()))
def t():return tuple(map(int,sys.stdin.readline().replace("\n","").split()))

def main():
    r = i()
    print(2*math.pi*r)
if __name__ == "__main__":
    main()

Measured memory_bytes: 9080
import sys
dp=[[0]*52 for unused in xrange(100)]
dia=[map(int,line.strip().split(",")) for line in sys.stdin.readlines()]
dp[0][0]=dia[0][0]
for i in xrange(1,len(dia)/2):
    for j in xrange(len(dia[i])):
        #dp[0][-1]==dp[0][51]==0
        dp[i][j]=max(dp[i-1][j-1],dp[i-1][j])+dia[i][j]
for i in xrange(len(dia)/2,len(dia)):
    for j in xrange(len(dia[i])):
        dp[i][j]=max(dp[i-1][j],dp[i-1][j+1])+dia[i][j]
print dp[len(dia)-1][0]

Measured memory_bytes: 4348
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pii pair<int,int>
#define pll pair<lli, lli>
#define vi  vector<int>
#define vii vector<pair<int,int>>
#define vll vector<lli>
#define pb  push_back
#define mpr  make_pair
#define ss  second
#define ff  first
#define INF 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846264338327950L
#define all(x) x.begin(),x.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define testcase() int tc;cin>>tc;while(tc--)
#define clean(x) memset(x,0,sizeof(x))
const lli maxn = 1e5+9;
vector<lli> catlan(int n) {
    vector<lli> dp(n + 1, 0);
    dp[0] = 1;
    dp[1] = 1;
    for (int i = 2; i <= n; i ++) {
        for (int j = 0; j < i; ++ j) {
            dp[i] += dp[j] * dp[i - j - 1];
        }
    }
    return dp;
}
lli b_ex(lli n,lli a){lli res=1;while(n){if(n%2==1)res*=a;n>>=1;a=a*a;}return res;}
lli ncr(lli n,lli k){lli ans=1;if(k>n-k)k=n-k;for(lli i=1;i<=k;i++){ans*=(n-i+1),ans=ans/i;}return ans;}
lli power(lli a , lli n){lli ans = 1;while(n){if(n % 2)ans = (ans * a) % mod;n /= 2;a = (a * a) % mod;}return ans;}
lli set_bits(lli n)
{
    int c=0;
    if(n==0)return 0;
    while(n)
    {
        if((n&1)==1)
        {
           cout<<c<<" ";
        }
        c++;
        n=n>>1;
    }
    return c;
}
lli lcm(lli a,lli b)
{
    lli ans=(a*b)/(__gcd(a,b));
    return ans;
}
///------------------ALWAYS lli-----TEMP TSF99--------------------------------------------------------------------------------------///
bool good(lli mid,lli n)
{
    lli ans=mid*(mid+1)/2;
    if(ans<=n)return true;
    return false;
}
void solve()
{
    lli n;cin>>n;
    lli l=1,r=mod;
    lli ans=0;
    while(l<=r)
    {
        lli mid=(l+r)/2;
        if(good(mid,n))
        {
            ans=mid;
            l=mid+1;
        }
        else r=mid-1;
    }
    if(ans*(ans+1)/2 !=n)ans++;
    cout<<ans<<endl;
}
int main()
{
    FAST;
    //int tc=1;cin>>tc;while(tc--)solve();
    solve();
}



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

int main() {
	double l;
	cin>>l;
	
	cout<<fixed<<setprecision(10)<<l*l*l/27<<endl;
	
}

/*
数学ゲー。相加相乗平均の知識のみ。ok
*/


Measured memory_bytes: 256
#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++)
typedef long long ll;
typedef long double ld;

int  main()
{
	long l,r; cin >> l >> r;
	if (labs(l-r) >= 2019)
	{
		cout << 0 << endl; return 0;
	}
	long m = 2018;
	for (long i = l; i < r; i++)
	{
		for (long j = i + 1; j <= r; j++)
		{
			m = min(m, (i*j%2019));
		}
	}
	cout << m << endl;
	return 0;
}


Measured memory_bytes: 256
n=int(input())
node={i:[] for i in range(1,n+1)}
visited=[False for i in range(n+1)]
q=[]
for _ in range(n-1):
    a,b=map(int,input().split())
    node[a].append(b)
    node[b].append(a)
    q.append((a,b))

mother=q[0][0]
visited[mother]=True

d=[]
e=[]


paint={i:{} for i in range(1,n+1)}

mother_paint=[0 for i in range(n+1)]

#使う要素 node visited paint mother_paint の四つのリスト
c=1
for child in node[mother]:
    visited[child]=True
    paint[mother][child]=c
    paint[child][mother]=c
    mother_paint[child]=c
    c+=1
    d.append(child)
    
while d:
    for parent in d:
        p=1 
        for child in node[parent]:
            if visited[child]==False:
                visited[child]=True
                if p!=mother_paint[parent]:
                    paint[parent][child]=p
                    paint[child][parent]=p
                    mother_paint[child]=p
                    p+=1
                    e.append(child)
                else:
                    p+=1
                    paint[parent][child]=p
                    paint[child][parent]=p
                    mother_paint[child]=p
                    p+=1
                    e.append(child)
    if e:
        d=e
        e=[]
    else:
        d=[]
        e=[]
K=0
for i in range(1,n+1):
    K=max(K,len(node[i]))
print(K)
for i in range(n-1):
    s,t=q[i][0],q[i][1]
    print(paint[s][t])

Measured memory_bytes: 119396
import math

A,B,H,M = [int(x) for x in input().split()]

Mdegrees = 360 * (float(M)/60.0)
if H >= 12:
  H -= 12
trueH = H + (float(M)/60.0)
Hdegrees = 360 * (trueH/12.0)

degrees = 0
if Mdegrees <= Hdegrees:
  degrees = Hdegrees - Mdegrees
else:
  degrees = Mdegrees - Hdegrees

radians = math.radians(degrees)
b = math.sqrt(A*A + B*B - 2*A*B*math.cos(radians))
print(b)


Measured memory_bytes: 9512
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

double Xs, Ys, Xt, Yt;
int N;
double X[1010], Y[1010], R[1010];

double dist[1012][1012];

double yosupot(double a, double b)
{
	return sqrt(a * a + b * b);
}

double dij[1020];
bool vis[1020];
int main()
{
	scanf("%lf%lf%lf%lf", &Xs, &Ys, &Xt, &Yt);
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) scanf("%lf%lf%lf", X + i, Y + i, R + i);

	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			double d = yosupot(X[i] - X[j], Y[i] - Y[j]);
			dist[i][j] = max(0.0, d - R[i] - R[j]);
		}
		dist[i][N] = dist[N][i] = max(0.0, yosupot(X[i] - Xs, Y[i] - Ys) - R[i]);
		dist[i][N + 1] = dist[N + 1][i] = max(0.0, yosupot(X[i] - Xt, Y[i] - Yt) - R[i]);
	}
	dist[N][N + 1] = yosupot(Xs - Xt, Ys - Yt);
	for (int i = 0; i < N + 2; ++i) dij[i] = 1e18;
	for (int i = 0; i < N + 2; ++i) vis[i] = false;
	dij[N] = 0;
	for (int i = 0; i < N + 2; ++i) {
		int bp = -1;
		for (int j = 0; j < N + 2; ++j) {
			if (!vis[j] && (bp == -1 || dij[bp] > dij[j])) bp = j;
		}
		vis[bp] = true;
		for (int j = 0; j < N + 2; ++j) dij[j] = min(dij[j], dij[bp] + dist[bp][j]);
	}
	printf("%.10f\n", dij[N + 1]);
	return 0;
}


Measured memory_bytes: 8192
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = 0;
		int b = 0;
		String op = null;
		boolean con = true;
		while (con) {

			a = sc.nextInt();
			op = sc.next();
			b = sc.nextInt();
			if (op.equals("+")) {
				System.out.println(a + b);

			} else if (op.equals("-")) {
				System.out.println(a - b);

			} else if (op.equals("*")) {
				System.out.println(a * b);

			} else if (op.equals("/")) {
				System.out.println(a / b);

			} else if (op.equals("?")) {
				sc.close();
				con = false;
			}
		}
	}
}

Measured memory_bytes: 18056
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
random_device rnd;
mt19937 mt(rnd());

const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;
int mpow(int base, int n)
{
    if (n == 0)
        return 1;
    int prev = mpow(base, n / 2);
    if (n % 2 == 0)
        return (prev * prev) % 2019;
    else
        return (prev * prev * base) % 2019;
}
int main()
{
    string s;
    cin >> s;
    reverse(ALL(s));
    map<int, int> mp;
    int cur = 0;
    rep(i, s.size())
    {
        cur = mpow(10, i) * (s[i] - '0') + cur;
        cur %= 2019;
        // cerr << cur << endl;
        mp[cur]++;
    }
    mp[0]++;
    ll ans = 0;
    rep(i, 2019)
    {
        if (mp[i] != 0)
        {
            //cerr << i << " " << mp[i] << endl;
        }
        ans += mp[i] * (mp[i] - 1);
    }
    cout << ans / 2 << endl;

    return 0;
}

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

using namespace std;
#define ff first
#define ss second
#define pb push_back
#define quicker ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
 
int main()
{
    quicker
    string s, t;
    cin >> s >> t;
    //cout << s.substr(0, t.size)
    if (t.substr(0, t.size() - 1) == s) cout << "Yes";
    else cout << "No";
    return 0;
}


Measured memory_bytes: 3640
import java.util.Scanner;

//C - Modulo Summation
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long ans = 0;
        for (int i = 0; i < n; i++) ans += sc.nextInt();
        System.out.println(ans - n);
        sc.close();
    }
}


Measured memory_bytes: 27372
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

int main(int argc, char* argv[])
{
    int x;
    scanf("%d", &x);
    printf("%d\n", x*x*x);

    return 0;
}



Measured memory_bytes: 2736
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#pragma GCC target ("sse4")
#pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

#define deb(x) cout << #x << " is " << x << "\n";

using namespace std;
using namespace __gnu_pbds;

const double PI = 2 * acos(0.0);
const long long INF = 1e18L + 5;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, m, s, c;
	cin >> n >> m;
	vector<int> num(n, -1);
	while (m--) {
		cin >> s >> c;
		if (num[--s] != -1 && num[s] != c || n > 1 && !s && !c) {
			cout << -1 << '\n';
			return 0;
		}
		num[s] = c;
	}
	for (int i = 0; i < n; ++i)
		cout << (num[i] == -1 ? (n > 1 && !i) : num[i]);
	cout << '\n';
	return 0;
}


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

int main(){

    string s,t;

    cin >> s >> t;

    bool f;

    for(int i=s.size()-t.size();i>=0;i--){
        string tmp=s.substr(i,t.size());
        f=true;
        for(int j=0;j<t.size();j++){
            if(tmp[j]!=t[j]&&tmp[j]!='?'){
                f=false;
                break;
            }
        }
        if(f){
            for(int j=0;j<t.size();j++){
                s[i+j]=t[j];
            }
            break;
        }
    }

    if(f){
        rep(i,s.size()){
            if(s[i]=='?') s[i]='a';
        }
        cout << s << endl;
    }else{
        cout << "UNRESTORABLE" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import heapq
n, m = map(int, input().split())
lst = list(map(lambda x: -(int(x)), input().split()))
heapq.heapify(lst)
for i in range(m):
  a = heapq.heappop(lst)
  heapq.heappush(lst, a / 2)
res = 0
for i in range(n):
  res += int(-lst[i])
print(res)

Measured memory_bytes: 20436
using System;

class MyClass
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        int Out = 0;
        bool first = false;
        bool second = false;
        bool third = false;
        int point = 0;
        while (Out != n * 3)
        {
            switch (Console.ReadLine())
            {
                case ("HIT"):
                    if (third)
                    {
                        point++;
                        third = false;
                    }
                    if (second)
                    {
                        third = true;
                        second = false;
                    }
                    if (first)
                    {
                        second = true;
                    }
                    first = true;
                    break;
                case ("HOMERUN"):
                    if (first)
                    {
                        first = false;
                        point++;
                    }
                    if (second)
                    {
                        second = false;
                        point++;
                    }
                    if (third)
                    {
                        third = false;
                        point++;
                    }
                    point++;
                    break;
                case ("OUT"):
                    Out++;
                    if (Out % 3 == 0)
                    {
                        Console.WriteLine(point);
                        point = 0;
                        first = false;
                        second = false;
                        third = false;
                    }
                    break;
                default:
                    break;
            }
        }
    }
}


Measured memory_bytes: 5700
N=int(input())
dic={}
ans=0

for i in range(N):
    s=input()
    t=sorted(s)
    word="".join(t)

    if word in dic:
        dic[word]+=1
    else:
        dic[word]=1

for i in dic:
    ans+=dic[i]*(dic[i]-1)//2

print(ans)

Measured memory_bytes: 17892
"use strict";

function main(input){
  const args = input.trim().split(' ');
  if(args[1] == '+') 
    console.log(parseInt(args[0], 10) + parseInt(args[2], 10));
  else
    console.log(parseInt(args[0], 10) - parseInt(args[2], 10));
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));  

Measured memory_bytes: 11468
#include<bits/stdc++.h>
#define LL long long 
using namespace std;
LL n,m,k;
LL a[101001],to[101001],tmp,size,ans[101001],s[101001];
bool vis[101001];

int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		to[i]=i;
	}
	for(int i=n;i>=1;i--)a[i]-=a[i-1];
	scanf("%lld%lld",&m,&k);
	for(int i=1;i<=m;i++)
	{
		scanf("%lld",&tmp);
		swap(to[tmp],to[tmp+1]);
	}
	for(int i=1;i<=n;i++)
	{
		if(vis[i])continue;
		size=0;
		for(int j=i;!vis[j];j=to[j])
		{
			vis[j]=true;
			size++;
			s[size]=j;
		}
		for(int j=1;j<=size;j++)
		{
			ans[s[j]]=a[s[(k+j-1)%size+1]];
		}
	}
	for(int i=1;i<=n;i++)
	{
		ans[i]+=ans[i-1];
		printf("%lld\n",ans[i]);
	}
	return 0;
}

Measured memory_bytes: 4480
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int R[] = {sc.nextInt(),sc.nextInt(),sc.nextInt()};
		sc.close();
		int max = R[0];
		int min = R[0];
		for (int i=0;i<R.length;i++) {
			max = Math.max(max,R[i]);
			min = Math.min(min,R[i]);
		}
		String ans = (R[2]!=max&&R[2]!=min)?"Yes":"No";
		System.out.print(ans+"\n");
	}
}

Measured memory_bytes: 23892
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
 
using namespace std;
 
int32_t main ()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	
	int n;
	cin>>n;
	int ans=0;
	int c=0;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		if(x<c){
			ans+=c-x;
		}
		c=max(c,x);
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 3552
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<set>
const int MAXN=5e5+10;
const double eps=1e-8;
const int MOD=1000000007;
using namespace std;
typedef  long long ll;
int a[200005],b[200005];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b,b+n);
    for(int i=0;i<n;i++)
    {
        if(a[i]==b[n-1])
            cout<<b[n-2]<<endl;
        else
            cout<<b[n-1]<<endl;
    }
    return 0;
}



Measured memory_bytes: 3200
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
 
##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)
 
##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力
 
# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと
 
##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順
 
# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順
 
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    S = input()
    S = S[:-1]
    
    ans = ""
    for i in S:
        No = ord(i) + N
        if No > 90:
            No = No - 90 + 64
        tmp = chr(No)
        ans += tmp
    
    print(ans)
    
    
if __name__ == "__main__":
	main()


Measured memory_bytes: 41052
#include<stdio.h>

int main(void){
    int N,M,C;
    scanf("%d %d %d",&N,&M,&C);
    int B[M];
    int A[N][M];
    for(int i=0;i<M;i++){
        scanf("%d",&B[i]);
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            scanf("%d",&A[i][j]);
        }
    }
    int count = 0;
    for(int i=0;i<N;i++){
        int ans = 0;
        for(int j=0;j<M;j++){
            ans += A[i][j]*B[j];
        }
        if(ans+C>0){
            count ++;
        }
    }
    printf("%d",count);
    return 0;
}

Measured memory_bytes: 128
/*
ID: zhaowei10
TASK:
LANG: C++14
*/
#include "bits/stdc++.h"

using namespace std;

#ifdef LOCAL
#include "../../_library/cpp/debug.h"
#define FILE "test"
#else
#define debug(...) 0
#define FILE ""
#endif

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  if (fopen(FILE ".in", "r")) {
    freopen(FILE ".in", "r", stdin);
    freopen(FILE ".out", "w", stdout);
  }

  int64_t n, m, k;
  cin >> n >> m >> k;

  vector<int64_t> a(n + 1), b(m + 1);
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    a[i] += a[i - 1];
  }
  for (int i = 1; i <= m; ++i) {
    cin >> b[i];
    b[i] += b[i - 1];
  }

  int64_t best = 0;
  for (int i = 0; i <= n; ++i) {
    int64_t rem = k - a[i];
    if (rem < 0)
      continue;
    auto it = upper_bound(b.begin(), b.end(), rem);
    best = max(best, i + distance(b.begin(), it) - 1);
  }

  cout << best;
}


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

int n,p=0,side[101][101],startTime[101],endTime[101],v[101];

void dfs(int x){
  if(!v[x]) {
    v[x]++; startTime[x]=++p;
	for (int i =1; i<n+1; i++) {
      if(side[x][i]) {
        dfs(i);
      }
    }
	endTime[x]=++p;
  }
}

int main(){
	int a,b,c;
	cin>>n;
	for (int i =0; i<n; i++) {
      cin>> a >> b;
      for (int i =0; i<b; i++) {
        cin >> c;
        side[a][c]++;
      }
    }
  
  for (int i =1; i<n+1; i++) {
    if(!v[i]) dfs(i);
  }
  for (int i =1; i<n+1; i++) {
    cout << i << ' ' << startTime[i] << ' ' << endTime[i] << endl;    
  }
}


Measured memory_bytes: 3152
$\=$/;$L=0,$|=$R=10,$_=${print("? ",($_*10+($M=$L+$R>>1))*1e9),<>=~Y?$R:$L=$M while$R-$L>1;_}*10+$L while$i++<9;
print"? ",++$_+s/0*$//;
print"? ",($_.=0)+1while<>=~(/^9*$/?Y:N);
print"! ",$_

Measured memory_bytes: 980
#include <iostream>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <stdio.h> 
#include <map>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <sstream>
#include <vector>
#include <algorithm>
using namespace std;


int main() {
	int n;
	cin>>n;
	pair<string, int> p[101];
	for (int i=0; i<n; i++) {
		char s[101];
		int t;
		scanf("%s %d",s, &t);
		p[i].first = string(s);
		p[i].second = t;
	}
	char word[101];
	scanf("%s", word);
	string w = string(word);
	bool flag = false;
	int sum = 0;
	for (int i=0; i<n; i++) {
		if(w == p[i].first) {
			flag = true;
			continue;
		}
		
		if(flag) {
			sum+=p[i].second;
		}
	}
	
	cout << sum;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
monster = [int(i) for i in input().split()]
brave_power = [int(i) for i in input().split()]
toubatsu_count = 0

for i in range(N):
    if brave_power[i]>monster[i]:
        toubatsu_count+=monster[i]
        nokori_brave = brave_power[i] - monster[i]
        
        if nokori_brave > monster[i+1]:
            toubatsu_count+=monster[i+1]
            monster[i+1]=0
        else:
            toubatsu_count+=nokori_brave
            monster[i+1]-=nokori_brave
    else:
        toubatsu_count+=brave_power[i]

print(toubatsu_count)

Measured memory_bytes: 18624
#include<stdio.h>

int main(void){
    int n, m, l;
    int A[100][100], B[100][100];
    long int C[100][100] = {};
    scanf("%d %d %d", &n, &m, &l);
    for(int i=0; i<n; i++){
        for(int j=0; j<m ;j++){
            scanf("%d", &A[i][j]);
        }
    }
    for(int i=0; i<m; i++){
        for(int j=0; j<l ;j++){
            scanf("%d", &B[i][j]);
        }
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<l ;j++){
            for(int k=0; k<m; k++){
                C[i][j] += A[i][k]*B[k][j];
            }
            printf("%ld", C[i][j]);
            if(j == l-1){
                printf("\n");
            }else{
                printf(" ");
            }
        }
    }
}


Measured memory_bytes: 2100
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val k = sc.nextInt()
  val n = sc.nextInt()
  val a = (1..n).map {
    sc.nextInt()
  }

  println(abc160c(k, n, a))
}

private fun abc160c(k: Int, n: Int, a: List<Int>): Int {
  val ansList = mutableListOf<Int>()
  for (i in 0 until n) {
    if (i == 0) {
      val v = a.get(n - 1) - a.get(0)
      ansList.add(v)
      continue
    }
    var v = k - a.get(i) + a.get(i - 1)
    ansList.add(v)
  }
  val ans = ansList.min()!!
  return ans
}


Measured memory_bytes: 79348
using System;
using System.Text.RegularExpressions;
using System.Numerics;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine(); //標準入力
            //string str = "31 41 5";
            string[] str2 = str.Split(' ');
            int[] src = new int[3];

            src[0] = int.Parse(str2[0].ToString());
            src[1] = int.Parse(str2[1].ToString());
            src[2] = int.Parse(str2[2].ToString());

            int index = 0;
            int[] tmp = new int[3];
            while(true)
            {
                if (src[0] == src[1] && src[1] == src[2])
                {
                    break;
                }

                Array.Copy(src, tmp, 3);
                Array.Sort(tmp);
                if (tmp[1] - tmp[0] >= 2)
                {
                    tmp[0] = tmp[0] + 2;
                }
                else if(tmp[1] == tmp[2] && tmp[0] + 1 == tmp[1])
                {
                    tmp[1]++;
                    tmp[2]++;
                }
                else
                {
                    tmp[0]++;
                    tmp[1]++;
                }
                src = tmp;
                index++;
            }
            Console.WriteLine(index);
        }
    }
}


Measured memory_bytes: 13140
N=int(input())
A=input()
B=input()
C=input()
count=0
for i in range(N):
    if A[i]!=B[i] and B[i]!=C[i] and C[i]!=A[i]:
        count+=2
    elif A[i]!=B[i] or B[i]!=C[i] or C[i]!=A[i]:
        count+=1
print(count)

Measured memory_bytes: 3064
#include<stdio.h>

int main(){
	int k;
	int i, x = 1;
	long long rnrn[100005] = {0};

	scanf("%d", &k);

	for(i=1; i<10; i++) rnrn[i] = (long long)i;
	while(1){
		if(i > k){
			break;
		}

		int j;
		for(j=-1; j<=1; j++){
			int d = rnrn[x] % 10 + j;

			if(d < 0 || d > 9){
				continue;
			}

			rnrn[i] = rnrn[x]*10 + d;
			i++;
		}
		x++;
	}

	printf("%lld", rnrn[k]);
	return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <math.h>

using namespace std;

long long n,m,a[10005],suma;
int main()
{
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>a[i];
    }
    if(m>n){
        cout<<"-1";
        return 0;
    }
    for(int i=0;i<m;i++){
        suma=suma+a[i];
    }
    if(suma>n){
        cout<<"-1";
        return 0;
    }
    cout<<n-suma;
}


Measured memory_bytes: 3668
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int T[] = new int[N];
		int sum = 0;
		for(int i=0;i<N;i++){
			T[i] = sc.nextInt();
			sum += T[i];
		}
		int M = sc.nextInt();
		int P[] = new int[M];
		int X[] = new int[M];
		for(int i=0;i<M;i++){
			P[i] = sc.nextInt();
			X[i] = sc.nextInt();
		}
		for(int i=0;i<M;i++){
			sum -=T[P[i] - 1];
			sum += X[i];
			System.out.println(sum);
			sum -= X[i];
			sum += T[P[i] - 1];
		}
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> VI;
typedef vector<VI> VVI;
typedef pair<ll, ll> P;
#define FOR(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const ll INF = numeric_limits<ll>::max();
int main()
{
    ll n; cin >> n;
    ll d;
    map<ll, ll> a;
    ll s = 0;
    rep(i, n) {
        cin >> d;
        s += d;
        ++a[d];
    }
    ll q; cin >> q;
    ll b, c;
    VI ans;
    rep(i, q){
        cin >> b >> c;
        s += (c - b)*a[b];
        ans.push_back(s);
        a[c] += a[b];
        a[b] = 0;
    } 
    rep(i, q){
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 9896
N,M=map(int,input().split())
import collections
table=collections.defaultdict(int)
table2=collections.defaultdict(int)
for i in range(M):
  a,b=map(int,input().split())
  if a==1:
    table[b]+=1
  if b==N:
    table2[a]+=1
for x in table:
  if x in table2:
    print("POSSIBLE")
    exit(0)
print("IMPOSSIBLE")
    

Measured memory_bytes: 24380
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

// Solving the maze using bfs
#define WALL '#'
#define PATH '.'
class coord{
	public:
	coord(){}
	coord(int _x,int _y):x(_x),y(_y){}
	int x,y;
};

class maze{
	public:
		maze(int _h,int _w):h(_h),w(_w){
			m = vector<vector<char>>(h,vector<char>(w));
			d = vector<vector<int>>(h,vector<int>(w,-1));
		}
		void input_map(){
			rep(i,h){
				string si; cin >> si;
				rep(j,w){
					m[i][j] = si[j];
					if(si[j]==WALL) wall_n++;
					if(si[j]==PATH) path_n++;
				}
			}
		}
		void set_start(coord _s){ s = _s; }
		void calc_distance(){
			queue<coord> q;
			q.push(s);
			d[s.x][s.y]=0;
			while(q.size()){
				coord u = q.front(); q.pop();
				rep(ix,3)rep(jx,3){
					if(abs(ix-1)+abs(jx-1)==2) continue;					
					int i = ix-1 + u.x;
					int j = jx-1 + u.y;					
					if(i>=0&&i<h&&j>=0&&j<w&&d[i][j]==-1&&m[i][j]==PATH){
						d[i][j] = d[u.x][u.y]+1;
						q.push(coord(i,j));
					}
				}
			}				
		}
		int distance(coord g){return d[g.x][g.y];}
		int number_of_wall(){return wall_n;}
		int number_of_path(){return path_n;}
		void print_map(){
			rep(i,h){
				rep(j,w) cout << m[i][j];
				cout << endl;
			}
		}		
		void print_distance(){
			rep(i,h){
				rep(j,w) cout << d[i][j] << " ";
				cout << endl;
			}
		}
	private:
		int h,w;
		vector<vector<char>> m;
		vector<vector<int>> d;
		coord s;
		int wall_n = 0;
		int path_n = 0;
};

int main(void) {
	int h,w; cin >> h >> w;
	maze mz(h,w);
	coord s(0,0);
	mz.set_start(s);
	mz.input_map();
	mz.calc_distance();
//	mz.print_distance();
	coord g(h-1,w-1);
	int dis = mz.distance(g);
	if(dis==-1){
		cout << -1 << endl;
		return 0;
	}
	int ans = h*w-mz.number_of_wall()-(dis+1);
	cout << ans << endl;
}




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

using namespace std;

int a[200005];

int main(){
	int n;
	scanf("%d", &n);

	long long sum1 = 0;

	for(int i=0;i<n;i++) scanf("%d", &a[i]), sum1 += a[i];

	long long sum2 = 0;

	long long ans = 1e18;
	for(int i=0;i<n-1;i++){
		sum2 += a[i];

		ans = min(ans, abs(sum2 - (sum1-sum2)));
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
long long x1[100];
long long x2[100];
long long y1[100];
long long y2[100],dist,cnt,n,m;
long long mn=1e9;
cin>>n>>m;
for(int i=0;i<n;i++)
cin>>x1[i]>>y1[i];
for(int i=0;i<m;i++)
cin>>x2[i]>>y2[i];
for(int i=0;i<n;i++){
    for(int j=0;j<m;j++)
        {
            dist=abs(x1[i]-x2[j])+abs(y1[i]-y2[j]);
            if(dist<mn){
                mn=dist;
                cnt=j+1;
                }
        }
        mn=1e9;
        cout<<cnt<<"\n";
}
}


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





template<int um> struct UF {
	vector<int> par; UF() { clear(); }
	int operator[](int x) { return par[x] == x ? x : par[x] = operator[](par[x]); }
	void operator()(int x, int y) { x = operator[](x); y = operator[](y); if (x != y) par[x] = y; }
	void clear() { par = vector<int>(um, 0); rep(i, 0, um) par[i] = i; }
};
int mod = 1000000007;
int add(int x, int y) { return (x += y) >= mod ? x - mod : x; }
int mul(int x, int y) { return 1LL * x * y % mod; }
int modpow(int a, long long b) {
	int ret = 1;
	while (b > 0) { if (b & 1) ret = 1LL * ret * a % mod; a = 1LL * a * a % mod; b >>= 1; }
	return ret;
}
int modinv(int a) { return modpow(a, mod - 2); }
int fac[201010], ifac[201010];
void initfac() {
	fac[0] = ifac[0] = 1;
	rep(i, 1, 201010) fac[i] = 1LL * i * fac[i - 1] % mod;
	rep(i, 1, 201010) ifac[i] = modinv(fac[i]);
}
//-----------------------------------------------------------------------------------
int N, X, Y, C[201010], W[201010];
UF<201010> uf;
void naive_merge() {
	rep(a, 0, N) rep(b, a + 1, N) {
		if (C[a] == C[b] && W[a] + W[b] <= X) uf(a, b);
		if (C[a] != C[b] && W[a] + W[b] <= Y) uf(a, b);
	}
}
//-----------------------------------------------------------------------------------
void optimized_merge() {
	map<int, vector<pair<int, int>>> color;
	rep(i, 0, N) color[C[i]].push_back({ W[i], i });
	for (auto& g : color) sort(g.second.begin(), g.second.end());

	// same color
	for (auto& g : color) {
		auto v = g.second;
		rep(i, 1, v.size()) if (v[0].first + v[i].first <= X) uf(v[0].second, v[i].second);
	}
	
	// different color
	vector<int> order;
	for (auto& g : color) order.push_back(g.first);
	sort(order.begin(), order.end(), [&](int a, int b) {
		return color[a][0].first < color[b][0].first;
	});
	rep(i, 0, N) { //color[order[0]][0] -> any
		auto p = color[order[0]][0];
		if (p.first + W[i] <= Y && order[0] != C[i]) uf(p.second, i);
	}
	if (2 <= order.size()) rep(i, 0, N) { //color[order[1]][0] -> any
		auto p = color[order[1]][0];
		if (p.first + W[i] <= Y && order[1] != C[i]) uf(p.second, i);
	}
}
//-----------------------------------------------------------------------------------
int count() {
	map<int, vector<int>> group;
	rep(i, 0, N) group[uf[i]].push_back(i);

	int res = 1;
	for (auto g : group) {
		auto v = g.second;
		int com = fac[v.size()];

		map<int, int> cnt;
		for (int i : v) cnt[C[i]]++;
		for (auto p : cnt) com = mul(com, ifac[p.second]);

		res = mul(res, com);
	}

	return res;
}
//-----------------------------------------------------------------------------------
int main() {
	initfac();
	cin >> N >> X >> Y;
	rep(i, 0, N) scanf("%d%d", &C[i], &W[i]);

	//naive_merge();
	optimized_merge();
	cout << count() << endl;
}

Measured memory_bytes: 25352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;


int main(){
    int K;
    cin >> K;
    vector<int> vec(32);
    vec = {1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51};


    cout << vec.at(K-1) << endl;

    
}


Measured memory_bytes: 256
var x , y , i , n , m : longint;
	a , b : array[1..200000] of boolean;
	ok : boolean;

begin
	readln(n , m);
	for i := 1 to m do begin
		readln(x , y);
		if x = 1 then a[y] := true;
		if y = n then b[x] := true;
	end;
	ok := false;
	for i := 2 to n - 1 do
		ok := ok or (a[i] and b[i]);
	if ok then writeln('POSSIBLE') else writeln('IMPOSSIBLE');	
end.

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

using namespace std;

int gcd(int a, int b) {
	if (b == 0)
		return a;
	if (a < b) {
		int buf = a;
		a = b;
		b = buf;
	}
	return gcd(b, a % b);
}

int main(void) {
	int num, i, ans;
	cin >> num;
	vector<int> d(num), l(num), r(num);
	cin >> d[0];
	l[0] = d[0];
	for (i = 1; i < num; i++) {
		scanf("%d", &d[i]);
		l[i] = gcd(l[i - 1], d[i]);
	}
	r[num - 1] = d[num - 1];
	for (i = num - 2; i > 0; i--)
		r[i] = gcd(r[i + 1], d[i]);
	ans = max(r[1], l[num - 2]);
	for (i = 1; i < num - 1; i++)
		ans = max(ans, gcd(l[i - 1], r[i + 1]));
	cout << ans << "\n";
	return 0;
}

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

int main() {
  long long n,k,ans=0;
  cin>>n>>k;
  long long a[n];
  for(int i=0;i<n;i++){
    long long l;
    cin>>l;
    a[i]=l;
  }
  sort(a,a+n);
  if(k>=n)ans=0;
  else{
    for(int i=0;i<n-k;i++)ans+=a[i];
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1792
n,k,i,y;d['   '];c(int*z){y=*1[&z]-*z;}main(x){for(scanf("%*d");~scanf("%d%d",&n,&k);printf("%d\n",i)){for(i=n--;i;y=x)scanf("%d",&x),d[--i]=x-y;for(qsort(d,n,4,c);n>=k;i+=d[--n]);}}

Measured memory_bytes: 1184
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <vector>
#include <map>
#include <ctime>
#include <cmath>
#include <string.h>
#define inf 0x7fffffff
using namespace std;
struct P
{

    int x,y;

    bool operator<(const P &a)const{
       // if(y!=a.y)
       // return y>a.y;
       return x>a.x;
//        return z>a.z;
    }
};
vector<P> v[1010];

int a,b,c,o[2000000],i,k,d,n,m,e,dy[15]={0,0,-1,1,-1,1,-1,1},dx[15]={-1,1,0,0,1,1,-1,-1};
int l[3500005];

long long x,y,z[52],v1,v2;
//P u[100600];
int j[6000000];
queue<P> q,q1;
stack<int> s;
//queue<P> q;

//deque<int> d;
//'1'==49;
//'A'==65;
//'a'==97;
map<string, int > p;
string r,r1,r2;
//char r[1010];





//2147483647
int main()
{
    cin>>r;
    for(int t=1;t<r.size();t++)
        if(r[t-1]=='A'&&r[t]=='C')
        i=1;
    if(i) puts("Yes");
    else puts("No");

}


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

int a[100005], cnt[100005];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, q, b, c;
    long long tot = 0;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        cnt[a[i]]++;
        tot += a[i];
    }
    cin >> q;
    while (q--)
    {
        cin >> b >> c;
        tot += cnt[b]*(c-b);
        cnt[c] += cnt[b];
        cnt[b] = 0;
        cout << tot << '\n';
    }
}

Measured memory_bytes: 4400
import java.util.*;

public class  Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        if(a+b>c+d){
            System.out.println("Left");
        }else if(a+b<c+d){
            System.out.println("Right");
        }else{
            System.out.println("Balanced");
        }
    }
}

Measured memory_bytes: 22868
#include<bits/stdc++.h>
#define M 1<<17
using namespace std;
int g(int a,int b){return b?g(b,a%b):a;}
int N,A[M],L[M],R[M],i,ans;
int main(){
	cin>>N;
	for(i=0;i<N;i++)cin>>A[i];
	for(i=0;i<N;i++)L[i+1]=g(L[i],A[i]);
	reverse(A,A+N);
	for(i=0;i<N;i++)R[i+1]=g(R[i],A[i]);
	for(i=0;i<N;i++)ans=max(ans,g(L[i],R[N-1-i]));
	cout<<ans<<endl;
}


Measured memory_bytes: 1408
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");

		int n = Integer.parseInt(str[0]);
		long k = Long.parseLong(str[1]);

		int a[] = new int[n];

		str = br.readLine().split(" ");
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(str[i]) - 1;
		}

		List<Integer> path = new ArrayList<>();

		Set<Integer> set = new HashSet<>();
		int next = 0;

		while (!set.contains(next)) {
			path.add(next);
			set.add(next);
			next = a[next];
		}

		int size = path.size();
		int primalyCount = path.indexOf(next);
		int loopCount = size - primalyCount;

		long num = k;
		if (primalyCount < num) {
			num = ((num - primalyCount) % loopCount) + primalyCount;
		}

		int result = path.get((int) num) + 1;
		System.out.println(result);
	}
}


Measured memory_bytes: 71116
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	int A, B, C;
	
	cin >> A >> B >> C;

	if ((A -C) * (B-C) < 0)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n,m;
    cin>>n>>m;
    map<int,int>mp;
    rep(i,m){
        int a,b;
        cin>>a>>b;
        mp[a]++;
        mp[b]++;
    }
    for(int i=1; i<=n; ++i){
        cout<<mp[i]<<endl;
    }
}


Measured memory_bytes: 256