akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

const ll MOD = 1000000007;

// auto mod int
// ref. https://github.com/atcoder-live/library/blob/master/mint.cpp
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const {
    return pow(MOD-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

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

    mint a = mint(10).pow(N);
    mint b = mint(9).pow(N);
    mint c = mint(9).pow(N);
    mint d = mint(8).pow(N);
    mint ans = a - b - c + d;
    cout << ans.x << endl;

    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
std::size_t indexOf(char c) {
	return c - 'a';
}

int main(void) {
	std::string s, t;
	std::cin >> s >> t;

	std::vector<std::vector<int>> map(27);
	for (int i = 0; i < s.size(); i++) {
		map[indexOf(s[i])].push_back(i);
	}
	long long count = 0;
	long long index = -1;
	
	for (std::size_t i = 0; i < t.size(); i++) {
		auto& vec = map[indexOf(t[i])];
		if (vec.size() == 0) {
			std::cout << -1 << std::endl;
			return 0;
		}
	}

	for (std::size_t i = 0; i < t.size(); i++) {
		auto & vec = map[indexOf(t[i])];
		if (vec[vec.size() - 1] <= index) {
			index = vec[0];
			count++;
		}
		else{
			index = *std::upper_bound(vec.begin(), vec.end(), index);
		}
	}
	std::cout << count * s.size() + index + 1 << std::endl;
	return 0;
}

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

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const int MX = 200005;
int n, a[MX], p[MX], x[MX], y[MX], mn[MX];
set<ii> st;
map<int, int> mp;

int parent (int a) {
	return a == p[a] ? a : p[a] = parent(p[a]);
}

void join (int a, int b) {
	a = parent(a), b = parent(b);
	mn[a] = min(mn[a], mn[b]);
	p[b] = a;
}

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> n;
	
	forn (i, n) {
		cin >> x[i] >> y[i];
		x[i]--, y[i]--;
		a[x[i]] = y[i];
	}

	iota(p, p + n, 0);
	forn (i, n) mn[i] = a[i];

	forn (i, n) {
		while (st.size() && st.begin()->fi < a[i]) {
			join(st.begin()->se, i);
			st.erase(st.begin());
		}
		st.emplace(mn[parent(i)], i);
	}

	forn (i, n) mp[parent(i)]++;
	forn (i, n) cout << mp[parent(x[i])] << endl;

	return 0;
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

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

constexpr llong mod = 1e9+7;
constexpr llong inf = mod * mod;

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

  vector<llong> dp(4, 0);
  dp[0] = 1;
  for (int i = 0; i < N; i++) {
    vector<llong> res(4, 0);
    res[0] = dp[0] * 8 % mod;
    res[1] = (dp[0] + dp[1] * 9) % mod;
    res[2] = (dp[0] + dp[2] * 9) % mod;
    res[3] = (dp[1] + dp[2] + dp[3] * 10) % mod;

    swap(dp, res);
  }

  cout << dp[3] << endl;

  return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>
#include<string.h>
typedef long long int lli;
int main() {
  char s1[100];
  char s2[100];
  
  scanf("%s", &s1);
  scanf("%s", &s2);
  
  for(int i=0;i<strlen(s1);i++){
      if(s1[i]!=s2[i]){
          printf("No\n");
          return 0;
      }
  }
  
  printf("Yes\n");

  return 0;
}



Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
int main() {
	// your code goes here
	 set<int> s;
	int x,n;
	cin>>x>>n;
	int a=x,b=x;
	  if(n==0)
	    {cout<<x;
	    return 0;}
	for(int i=0;i<n;i++)
	{   int a;
	    cin>>a;
	    s.insert(a);
	}
	
	while(s.find(a)!=s.end())
	  {
	      a--;
	  }
	 
	while(s.find(b)!=s.end())
	  {
	      b++;
	  }
  int diffa=abs(x-a);
  int diffb=abs(x-b);
         if(diffa<=diffb)
           cout<<a;
            else
          cout<<b;

	return 0;
}


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

int main(){

	while(1){

		int H,W;
		cin >> H >> W;
		if(H == 0 && W == 0)break;

		for(int i=1; H>=i; i++){
			
			for(int j=1; W>=j; j++){

				if( (i+j)%2 == 0)cout << "#";
				else cout << ".";

			}
			
			cout << endl;
		}

		cout << endl;
	}
	
	return 0;
}

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


int main(){
	string S;
	cin >> S;
	LL K;
	cin >> K;
	if(S.size() == 1){
		cout << S[0] << endl;
		return 0;
	}
	else {
		int tmp = 0;
		rep(i,S.size()){
			if(S[i]-'0' != 1) break;
			tmp++;
		}
		if(K<=tmp) {
			cout << 1 << endl;
			return 0;
		}
		else {
			cout << S[tmp] << endl;
			return 0;
		}
	}
	


}














Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main()
{int n,k;
cin>>n>>k;
 double prob=0.0;
 for(int i=0;i<n;i++)
 {
 int s=i+1;
   double c=0.0;
   while(s<k)
   {
   s=s*2;
     c++;
   }
   prob=prob+pow(0.5,c);
 }
 cout<<fixed<<setprecision(12)<<prob/n;
}

Measured memory_bytes: 256
from bisect import *
S = list(str(input()))
K = int(input())

alp = list("abcdefghijklmnopqrstuvwxyz")

for i in range(len(S)):
  b = bisect_left(alp,S[i])

  if i == len(S)-1:
    S[i] = alp[(b+K)%26]
  elif b == 0:
    continue
  elif 26 - b <= K:
    K -= (26 - b)
    S[i] = "a"
  if K == 0:
    break
  
print("".join(S))

Measured memory_bytes: 10064
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int happy = 0;
    int change = 0;
    while (change+500 <= x) {
      happy += 1000;
      change += 500;
    }
    while (change+5 <= x) {
      happy += 5;
      change += 5;
    }
    System.out.println(happy);
    sc.close();
  }
}

Measured memory_bytes: 21844
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdbool.h>
#include<math.h>
#include<sstream>
#include<math.h>
#include<vector>
#include<functional>
#include<queue>
#include<utility>
typedef long long ll;
#define N (1000000000+7)
#define INF 1e10
using namespace std;
typedef pair<ll, ll> P;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

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

int main(void){
	ll a, b, k;
	cin >> a >> b >> k;
	ll count = 0;
	for (int i = 100;i >= 1;i--) {
		if ((a%i == 0) && (b%i == 0))count++;
		if (count == k) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
from itertools import product

H, W, K = map(int, input().split())
l = [[0]*W for _ in range(H)]
for i in range(H):
    for j, s in enumerate(input()):
        if s=="1":
            l[i][j] = 1

dp = [[0]*(W+1) for _ in range(H+1)]
for i in range(1, H+1):
    for j in range(1, W+1):
        dp[i][j] = l[i-1][j-1]+dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]

f=lambda lx,ly,rx,ry:dp[ry][rx]-dp[ly-1][rx]-dp[ry][lx-1]+dp[ly-1][lx-1]

ans = H*W
for i in product(range(2), repeat=H-1):
    candidate = []
    if any(i):
        start = 1
        for j, k in enumerate(i, start=1):
            if k:
                candidate.append((start, j))
                start = j+1
        candidate.append((start, H))
    else:
        candidate.append((1, H))
    
    q = [1]
    cutx = 0

    while q:
        s = q.pop()
        for t in range(s, W+1)[::-1]:
            if all(f(s, j, t, k)<=K for j, k in candidate):
                if t!=W:
                    q.append(t+1)
                    cutx += 1
                break
        else:
            cutx = H*W
    v = cutx+sum(i)
    ans = min(ans, v)

print(ans)

Measured memory_bytes: 48732
#include <stdio.h>
#include <string.h>

int main(void) {
	int datasets;
	int nowset;
	int rui;
	int score;
	int out;
	char event[100];
	scanf("%d",&datasets);
	for(nowset=0;nowset<datasets;nowset++) {
		rui=0;
		score=0;
		out=0;
		while(out<3) {
			scanf("%s",event);
			if(strcmp(event,"HIT")==0) {
				if(rui<3)rui++;
				else score++;
			} else if(strcmp(event,"HOMERUN")==0) {
				score+=rui+1;
				rui=0;
			} else if(strcmp(event,"OUT")==0) {
				out++;
			}
		}
		printf("%d\n",score);
	}
	return 0;
}

Measured memory_bytes: 0
b1 = [int(x) for x in input().split()]
b2 = [int(x) for x in input().split()]
b3 = [int(x) for x in input().split()]
n = int(input())
li = list()
for i in range(n):
    li.append(int(input()))

b1_0 = False
b1_1 = False
b1_2 = False
b2_0 = False
b2_1 = False
b2_2 = False
b3_0 = False
b3_1 = False
b3_2 = False

for name in li:
    for j ,name2 in enumerate(b1):
        if(name2 == name):
            if(j == 0):
                b1_0 = True
            elif(j == 1):
                b1_1 = True
            else:
                b1_2 = True
    for k,name3 in enumerate(b2):
        if(name == name3):
            if(k == 0):
                b2_0 = True
            elif(k == 1):
                b2_1 = True
            else:
                b2_2 = True
    for l,name4 in enumerate(b3):
        if(name == name4):
            if(l == 0):
                b3_0 = True
            elif(l == 1):
                b3_1 = True
            else:
                b3_2 = True
            
if (b1_0 and b1_1 and b1_2):
    print("Yes")
elif (b2_0 and b2_1 and b2_2):
    print("Yes")
elif (b3_0 and b3_1 and b3_2):
    print("Yes")
elif (b1_0 and b2_0 and b3_0):
    print("Yes")
elif (b1_1 and b2_1 and b3_1):
    print("Yes")
elif(b1_2 and b2_2 and b3_2):
    print("Yes")
elif (b1_0 and b2_1 and b3_2):
    print("Yes")
elif (b1_2 and b2_1 and b3_0):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3192
ss = [input() for _ in range(3)]
 
i = 0
while ss[i % 3] != "":
    card = ss[i % 3][0]
    ss[i % 3] = ss[i % 3][1:]
    if card == "a":
        i = 0
    elif card == "b":
        i = 1
    else:
        i = 2
 
if i == 0:
    print("A")
elif i == 1:
    print("B")
else:
    print("C")

Measured memory_bytes: 3064
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int N=Integer.parseInt(sc.nextLine());
		String str=sc.nextLine();
		String[] array_str=str.split(" ");

		ArrayList<Integer> array=new ArrayList<Integer>();
		 for(int i=0;i<array_str.length;i++){
			array.add(Integer.parseInt(array_str[i]));
		}
		int Allice_sum=0;
		int Bob_sum=0;
		int chk;
		int chk2;
		for(int i=0;i<array.size();i++){
			chk=array.get(0);
			chk2=0;
			for(int j=0;j<array.size();j++){
				if(chk<array.get(j)){
					chk=array.get(j);
					chk2=j;
				}
			}
			
			array.set(chk2,0);
			if(i%2==0){
				Allice_sum+=chk;
			}else{
				Bob_sum+=chk;
			}
		}
	System.out.println(Allice_sum-Bob_sum);
	}
}


Measured memory_bytes: 21844
let () = 
	let s = Array.make 13 false in
	let h = Array.make 13 false in
	let c = Array.make 13 false in
	let d = Array.make 13 false in
	let n = read_int () in
	for i = 1 to n do 
	    let (a, j) = Scanf.scanf "%c %d\n" (fun x y -> (x, y - 1)) in
	    match a with
	        | 'S' -> s.(j) <- true
	        | 'H' -> h.(j) <- true
	        | 'C' -> c.(j) <- true
	        | 'D' -> d.(j) <- true
	        | _   -> ()
	done;
	let f c = 
	    Array.iteri (fun i v -> if not v then Printf.printf "%c %d\n" c (i + 1) ); in
	f 'S' s;
	f 'H' h;
	f 'C' c;
	f 'D' d;
;;


Measured memory_bytes: 2392
#include <bits/stdc++.h>
using  namespace std;
#define    ll  long long int
ll fre[11];
int main( )
{
    ll N, i,k, mx = -1,sum=0, a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;

    ll s = a * x + b * y;

    ll t;
    if (x < y)
    {
        t = 2 * c * x + b * (y-x);
        if (t < s) s = t;

        t = 2 * c * y;
        if (t < s) s = t;
    }
    else
    {
        t = 2 * c * y + a *(x-y);
        if (t < s) s = t;

        t = 2 * c * x;
        if (t < s) s = t;
    }

    cout << s << endl;

    return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
#define MAX_N 1000000
vector<int> par(MAX_N), rnk(MAX_N);//ここでいうrankはノードの数

void init(int n){
  for(int i=0; i<n; i++){
    par[i]=i;
    rnk[i]=1;
  }
}

//木の根を求めながら、収縮もしていく
int find(int x){
  if(par[x]==x){
     return x;
   }else{
     return par[x]=find(par[x]);
   }
}

//xとyの集合を結合する
void merge(int x, int y){
  if(find(x)==find(y)) return;
  if(rnk[find(x)]<rnk[find(y)]){
    rnk[find(y)]+=rnk[find(x)];
    par[find(x)]=find(y);
  }else{
    rnk[find(x)]+=rnk[find(y)];
    par[find(y)]=find(x);
  }
}

int main(){
  int N, M, i, A, B, mx=0;
  cin>>N>>M;
  init(N);
  
  for(i=0; i<M; i++){
    cin>>A>>B;
    merge(A-1, B-1);
  }

  for(i=0; i<N; i++){
    mx=max(mx, rnk[i]);
  }
  cout<<mx<<endl;
  return 0;
}

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

int d,x,y;
string a[20],b[20];
int p[20],q[20];
bool ac[20];

int rec(int depth, int use){
  if(depth == x+2*y){
    int sum = 0;
    for(int i=0;i<x;i++){
      if(ac[i])sum += p[i];
    }
    for(int j=0;j<y;j++){
      if(ac[x+2*j] && ac[x+2*j+1])sum += q[j];
    }
    return sum;
  }

  int res = rec(depth+1,use);
  
  if(use<d){
    if(depth<x){
      if(a[depth][0] == 'D')ac[depth] = true;
    }else{
      if(b[(depth-x)/2][(depth-x)%2] == 'D')ac[depth] = true;
    }
    res = max(res, rec(depth+1,use+1));
    ac[depth] = false;
  }

  return res;
}

int main(){
  cin >> d;
  cin >> x;
  for(int i=0;i<x;i++)cin >> a[i] >> p[i];
  cin >> y;
  for(int j=0;j<y;j++)cin >> b[j] >> q[j];

  for(int i=0;i<x+2*y;i++)ac[i] = false;
  cout << rec(0,0) << endl;
}

Measured memory_bytes: 1204
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int T = sc.nextInt();
		int[] t = new int[N];
		for (int i = 0; i < N; i++)
			t[i] = sc.nextInt();
		int ans = 0;
		for (int i = 0; i < N - 1; i++) {
			if (t[i + 1] - t[i] >= T)
				ans += T;
			else
				ans += t[i + 1] - t[i];
		}
		System.out.println(ans+T);

	}
	//以下、自作ライブラリ

	//最大公約数
	public static long gcd(long a, long b) {
		if (a < b)
			return gcd(b, a);
		long c = 0;
		c = a % b;
		if (c == 0)
			return b;
		return gcd(b, c);
	}

	//最小公倍数
	public static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

	//素数判定
	public static boolean isPrime(int n) {
		if (n < 2)
			return false;
		if (n == 2)
			return true;
		if (n % 2 == 0)
			return false;

		for (int i = 3; i * i <= n; i += 2) {
			if (n % i == 0)
				return false;
		}
		return true;
	}
}

//以下、高速スキャナークラス
class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 23508
#include <iostream>
#include <vector>
using namespace std;
int main() {
    int n, k;
    cin >> n >> k;
    int r, s, p;
    string t;
    cin >> r >> s >> p;
    cin >> t;
    char prevChar[k];
    for (int i=0; i<k; i++) {
        prevChar[i] = 'a';
    }
    int point = 0;
    for (int i=0; i<n; i++) {
        if (t[i] != prevChar[i%k]) {
            if (t[i] == 'r') {
                point += p;
            } else if (t[i] == 's') {
                point += r;
            } else if (t[i] == 'p') {
                point += s;
            }
            prevChar[i%k] = t[i];
        } else {
            //同じものが2回続いた場合、その次はどの手を選ぶこともできる
            prevChar[i%k] = 'a';
        }
    }
    cout << point << endl;
}

Measured memory_bytes: 3808
// ARC087F.cpp
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 5050, mod = 1e9 + 7;

int n, head[MAX_N], current, siz[MAX_N], gcnt, fac[MAX_N], fac_inv[MAX_N], gpt, dp[MAX_N];

struct edge
{
    int to, nxt;
} edges[MAX_N << 1];

void addpath(int src, int dst)
{
    edges[current].to = dst, edges[current].nxt = head[src];
    head[src] = current++;
}

void getSiz(int u, int fa)
{
    int max_part = 0;
    siz[u] = 1;
    for (int i = head[u]; i != -1; i = edges[i].nxt)
        if (edges[i].to != fa)
        {
            getSiz(edges[i].to, u), max_part = max(max_part, siz[edges[i].to]);
            siz[u] += siz[edges[i].to];
        }
    max_part = max(max_part, n - siz[u]);
    if (max_part <= (n >> 1))
        gcnt++, gpt = u;
}

void dfs(int u, int fa)
{
    siz[u] = 1;
    for (int i = head[u]; i != -1; i = edges[i].nxt)
        if (edges[i].to != fa)
            dfs(edges[i].to, u), siz[u] += siz[edges[i].to];
}

int binomial(int n_, int k_) { return (n_ < k_) ? 0 : 1LL * fac[n_] * fac_inv[k_] % mod * fac_inv[n_ - k_] % mod; }

int permutation(int n_, int k_) { return (n_ < k_) ? 0 : 1LL * fac[n_] * fac_inv[n_ - k_] % mod; }

int main()
{
    memset(head, -1, sizeof(head));
    scanf("%d", &n);
    for (int i = 1, u, v; i <= n - 1; i++)
        scanf("%d%d", &u, &v), addpath(u, v), addpath(v, u);
    getSiz(1, 0);
    for (int i = fac[0] = 1; i < MAX_N; i++)
        fac[i] = 1LL * fac[i - 1] * i % mod;
    fac_inv[0] = fac_inv[1] = 1;
    for (int i = 2; i < MAX_N; i++)
        fac_inv[i] = 1LL * (mod - mod / i) * fac_inv[mod % i] % mod;
    for (int i = 2; i < MAX_N; i++)
        fac_inv[i] = 1LL * fac_inv[i - 1] * fac_inv[i] % mod;
    if (gcnt == 2)
    {
        printf("%lld\n", 1LL * fac[n >> 1] * fac[n >> 1] % mod);
        return 0;
    }
    dfs(gpt, 0), dp[0] = 1;
    int tot_siz = 0;
    for (int i = head[gpt]; i != -1; i = edges[i].nxt)
    {
        tot_siz += siz[edges[i].to];
        for (int j = tot_siz; j >= 0; j--)
            for (int k = 1; k <= min(siz[edges[i].to], j); k++)
            {
                int tmp = 1LL * dp[j - k] * binomial(siz[edges[i].to], k) % mod * permutation(siz[edges[i].to], k) % mod;
                dp[j] = (0LL + dp[j] + tmp) % mod;
            }
    }
    int ans = 0;
    for (int i = 0, opt = 1; i <= n; i++, opt = mod - opt)
        ans = (0LL + ans + 1LL * opt * dp[i] % mod * fac[n - i] % mod) % mod;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 4032
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int N,W;
  cin>>N>>W;
  lint w[N];
  int v[N];
  int M=1000*N+1;
  REP(i,N)cin>>w[i]>>v[i];
  lint dp[M];
  REP(i,M)dp[i]=W+1;
  dp[0]=0;
  REP(i,N){
    for(int j=M-1-v[i];j>=0;j--){
      dp[j+v[i]]=min(dp[j+v[i]],dp[j]+w[i]);
    }
  }
  for(int j=M-1;j>=0;j--)if(dp[j]<=W){
    cout<<j<<endl;
    break;
  }
  // REP(i,M-1)if(dp[i]<=W)cerr<<i<<" "<<dp[i]<<endl;
  return 0;
}


Measured memory_bytes: 1024
use num_bigint::{BigInt, ToBigInt};
fn combination(n: usize, take: usize) -> BigInt {
    let a = (1..n + 1)
        .rev()
        .take(take)
        .fold(ToBigInt::to_bigint(&1).unwrap(), |sum, i| {
            sum * ToBigInt::to_bigint(&i).unwrap()
        });
    let b = (1..n + 1)
        .take(take)
        .fold(ToBigInt::to_bigint(&1).unwrap(), |sum, i| {
            sum * ToBigInt::to_bigint(&i).unwrap()
        });
    a / b
}
fn f(n: usize) -> BigInt {
    (0..=n).fold(ToBigInt::to_bigint(&0).unwrap(), |sum, item| {
        sum + combination(n, item)
    })
}
fn feven(n: usize) -> BigInt {
    (0..=n)
        .step_by(2)
        .fold(ToBigInt::to_bigint(&0).unwrap(), |sum, item| {
            sum + combination(n, item)
        })
}
fn fodd(n: usize) -> BigInt {
    (1..=n)
        .step_by(2)
        .fold(ToBigInt::to_bigint(&0).unwrap(), |sum, item| {
            sum + combination(n, item)
        })
}
fn main() {
    proconio::input! {
        n: usize,
        p: usize,
        a_s: [usize; n],
    }
    // p == 0
    // evens + even odds
    //
    // p == 1
    // evens + odd odds
    let (evens, odds) = (
        a_s.iter().filter(|x| **x % 2 == 0).count(),
        a_s.iter().filter(|x| **x % 2 != 0).count(),
    );
    let ans = if p == 0 {
        f(evens) * feven(odds)
    } else {
        f(evens) * fodd(odds)
    };
    println!("{}", ans);
}


Measured memory_bytes: 2728
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;

int h,w,a,b,fac[200006],ans=0,inv_fac[200006];
int binpow(int x,int y){
	if(y==0) return 1;
	else{
		long long tmp=binpow(x,y/2);
		if(y%2==1) return ((tmp*tmp)%mod*x)%mod;
		else return (tmp*tmp)%mod;
	}
}

int C(int k,int n) {
	return fac[n]*inv_fac[k]%mod*inv_fac[n-k]%mod;
}

int path(int x1,int y1,int x2,int y2) {
	if(x1>x2||y1>y2) return 1;
	return  C(x2-x1,x2-x1+y2-y1)%mod;
}

signed main() {
	cin>>h>>w>>a>>b;
	fac[0]=1;
	inv_fac[0]=1;
	for(int i=1;i<=200005;++i) 
	{
		fac[i]=((i % mod)*fac[i-1])%mod;
		inv_fac[i]=binpow(fac[i],mod-2)%mod;
	}
	for(int i=1;i<=h-a;++i) {
		ans+=((path(1,1,i,b)%mod)*(path(i,b+1,h,w)%mod))%mod;
	}
	cout<<ans%mod;
}

Measured memory_bytes: 3328
#include <iostream>
using namespace std;
int main(){
    long long int N,K;
    cin  >> N >> K;
    long long int ans=0;
    long long int mod=1000000007;
    for(long long int i=K;i<=N+1;i++){
        ans+=N*i-i*(i-1)+1;
        ans=ans%mod;
    }
    std::cout << ans%mod << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstddef>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

#define int long long
#define YES "Yes"
#define NO  "No"

using namespace std;

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

  // int num = 0;

  int x, y, z, k;
  cin >> x >> y >> z >> k;
  vector<int> a(x);
  vector<int> b(y);
  vector<int> c(z);

  for (int i = 0; i < x; ++i) cin >> a[i];
  for (int i = 0; i < y; ++i) cin >> b[i];
  for (int i = 0; i < z; ++i) cin >> c[i];

  sort(a.begin(), a.end(), greater<int>());
  sort(b.begin(), b.end(), greater<int>());
  sort(c.begin(), c.end(), greater<int>());


  vector<int> e(x * y);
  for (int i = 0; i < x; ++i) {
    for (int j = 0; j < y; ++j) {
      e[i * y + j] = a[i] + b[j];
    }
  }

  sort(e.begin(), e.end(), greater<int>());

  vector<int> g(k * z);
  for (int i = 0; i < min(x * y, k); ++i) {
    for (int j = 0; j < z; ++j) {
      g[i * z + j] = e[i] + c[j];
    }
  }


  sort(g.begin(), g.end(), greater<int>());

  for (int i = 0; i < k; ++i) cout << g[i] << endl;
  
  // cout << num << endl;
  
  return 0;
}


Measured memory_bytes: 31616
#include <iostream>
#include<vector>
using namespace std;
int main(void){
    int a,b,c;
    cin >> a >> b >> c;
    int k;
    cin >> k;
    
    for(int i = 0;i < k;i++){
          if(a >= b){
                b <<= 1;
          }else{
                c <<= 1;
          }
    }
    
    if(a < b && b < c){
          cout << "Yes" << endl;
    }else{
          cout << "No" << endl;
    }
}


Measured memory_bytes: 3624
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

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

    char s[n+2];
    s[0] = '1';
    scanf("%s", &s[1]);

    int i;
    int merged_idx=0;
    char s_merged[n+2];
    memset(s_merged, '\0', sizeof(char)*(n+2));
    s_merged[0] = s[0];

    for ( i=1; i<=n; i++ ) {
        if ( s[i] != s_merged[merged_idx] ) {
            merged_idx++;
            s_merged[merged_idx] = s[i];
        }
    }
    s_merged[merged_idx+1] = '\0';

    int ans = strlen(&s_merged[1]);

    printf("%d\n", ans);
    return EXIT_SUCCESS;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#define llint long long
#define inf 1e18
#define mod 998244353
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)

using namespace std;
typedef pair<llint, llint> P;

int n;
vector<llint> G[100005];
map<P, llint> mp;
int dif[100005];

int parent[500005];
llint dp[500005], dp2[500005];

const llint e = 0; //
llint ope(llint a, llint b)
{
	return max(a, b); //
}

llint get(int u, int v)
{
	if(parent[u] == v) return dp2[u];
	else return dp[v];
}

void dfs(int v, int p)
{
	parent[v] = p;
	for(int i = 0; i < G[v].size(); i++){
		if(G[v][i] == p) continue;
		dfs(G[v][i], v);
	}
	
	llint sum = e;
	for(int i = 0; i < G[v].size(); i++){
		int u = G[v][i];
		if(u == p) continue;
		sum = ope(sum, get(v, u)); //
	}
	dp[v] = sum+1; //
}

llint lsum[500005], rsum[500005];
void dfs2(int v, int p)
{
	llint m = G[v].size(), sum;
	
	sum = lsum[0] = e;
	for(int i = 0; i < m; i++){
		int u = G[v][i];
		sum = ope(sum, get(v, u)); //
		lsum[i+1] = sum;
	}
	sum = rsum[m+1] = e;
	for(int i = m-1; i >= 0; i--){
		int u = G[v][i];
		sum = ope(sum, get(v, u)); //
		rsum[i+1] = sum;
	}
	for(int i = 0; i < m; i++){
		if(G[v][i] == p) continue;
		dp2[G[v][i]] = ope(lsum[i], rsum[i+2])+1; //
	}
	
	for(int i = 0; i < G[v].size(); i++){
		if(G[v][i] == p) continue;
		dfs2(G[v][i], v);
	}
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	int u, v;
	for(int i = 0; i < n-1; i++){
		cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	
	dfs(1, -1);
	dfs2(1, -1);
	
	/*for(auto it = mp.begin(); it != mp.end(); it++){
		cout << it->first.first << " " << it->first.second << " " << it->second << endl;
	}*/
	
	vector<llint> vec;
	for(int i = 1; i <= n; i++){
		if(G[i].size() < 3) continue;
		vec.clear();
		for(int j = 0; j < G[i].size(); j++){
			vec.push_back(get(i, G[i][j]));
		}
		sort(vec.rbegin(), vec.rend());
		llint x = vec[0], y = vec[2], l, r;
		//cout << i << " " << x << " " << y << endl;
		if(y == 0 || x+y < 3) continue;
		
		if(x > y) l = 3, r = x+y;
		else l = 3, r = 2*x-1;
		dif[l]++, dif[r+1]--;
	}
	
	llint sum = 0;
	for(int i = 1; i <= n; i++){
		sum += dif[i];
		if(sum) cout << 0;
		else cout << 1;
	}
	cout << endl;

	return 0;
}



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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30


int main() {
    int n, x; cin >> n >> x;
    V<int> l(n);
    for(int i = 0; i < n; i++) cin >> l[i];

    int ans = 1;
    int d = 0;
    for(int i = 0; i < n; i++){
        d += l[i];
        if(d <= x) ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
<?php
// $n = (int)trim(fgets(STDIN));
$input = explode(' ', trim(fgets(STDIN)));
 
$a = $input[0];
$b = $input[1];
$c = $input[2];
 
if (($a === $b && $a !== $c) || ($a === $c && $a !== $b)  || ($b === $c && $a !== $b)) {
	echo 'Yes';
}else{
	echo 'No';
}

Measured memory_bytes: 4604
# B - Trick or Treat

n, k = map(int, input().split())
safe = set()  # お菓子を持っているすぬけ
for i in range(k):
    d = int(input())
    a = list(map(int, input().split()))
    assert len(a) == d
    safe.update(a)

x = sum(1 for s in range(1, n+1) if s not in safe)
print(x)


Measured memory_bytes: 9180
x, y = map(int, input().split())
ax = abs(x)
ay = abs(y)
if ax == ay:
    print(int(x != y))
elif ax > ay:
    if y <= 0:
        if x > 0:
            print(1 + ax - ay)
        else:
            print(ax - ay)
    else:
        if x > 0:
            print(2 + ax - ay)
        else:
            print(1 + ax - ay)
else:
    if y > 0:
        if x >= 0:
            print(ay - ax)
        else:
            print(1 + ay - ax)
    else:
        if x >= 0:
            print(1 + ay - ax)
        else:
            print(2 + ay - ax)


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

using namespace std;

double p[302][302][302];	//p[a][b][c] = prob to get to a,b,c
double ev[302][302][302];	//ev[a][b][c] = expected numbers of move to get to a,b,c

int main() {
	int n; cin >> n;
	vector<int> count(4);
	for (int i = 0; i < n; i++) {
		int cur; cin >> cur;
		count[cur]++;
	}

	p[count[1]][count[2]][count[3]] = 1;
	//We start from the end since our start state is with big numbers
	//Better to start with c since c never increases whereas a and b do increase in the next state
	//When eating from a 3-plate or 2-plate
	for (int c = n; c >= 0; c--) {
		for (int b = n; b >= 0; b--) {
			for (int a = n; a >= 0; a--) {
				if (a + b + c > n) { continue; }
				if (a == 0 && b == 0 && c == 0) { continue; }

				double pWaste = (double) (n - (a + b + c)) / n;	
				//eWaste = pWaste + pWaste^2 + ... = 1/(1-pWaste)-1
				double evWaste = 1 / (1 - pWaste) - 1.0;
				ev[a][b][c] += (evWaste ) * p[a][b][c];		//+1 is for getting to a,b,c

				//We get the probabilities assuming we don't waste the move
				//For the ev, we can't say (ev[a][b][c]+1)*curP because it is like saying the weight for an additional
				//move is 1 whereas it is actually p[a][b][c]
				if (a) {
					double curP = (double)a / (a + b + c);
					p[a - 1][b][c] += p[a][b][c] * curP;
					ev[a - 1][b][c] += (ev[a][b][c] + p[a][b][c]) * curP;
				}
				if (b) {
					double curP = (double)b / (a + b + c);
					p[a+1][b-1][c] += p[a][b][c] * curP;
					ev[a + 1][b - 1][c] += (ev[a][b][c] + p[a][b][c]) * curP;
				}
				if (c) {
					double curP = (double)c / (a + b + c);
					p[a][b+1][c-1] += p[a][b][c] * curP;
					ev[a][b+1][c-1] += (ev[a][b][c] + p[a][b][c]) * curP;
				}
			}
		}
	}

	cout << setprecision(9) << fixed << ev[0][0][0] << endl;
}

Measured memory_bytes: 430336
using System;
using System.Collections.Generic;

class Q
{
	static void Main()
	{
		Func<int[]> read = () => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
		var n = int.Parse(Console.ReadLine());
		var h = read();
		var a = read();

		var l = new List<int>() { 0 };
		var dp = new long[n + 1];
		for (int i = 0; i < n; i++)
		{
			var li = ~l.BinarySearch(h[i]);
			var v = dp[l[li - 1]] + a[i];
			while (li < l.Count && dp[l[li]] <= v) l.RemoveAt(li);
			l.Insert(li, h[i]);
			dp[h[i]] = v;
		}
		Console.WriteLine(dp[l[l.Count - 1]]);
	}
}


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

   typedef long long ll;
   typedef pair<ll, ll> Pii;
   typedef vector<ll> Vi;
   typedef vector<Vi> VVi;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define RSORT(x) sort((x).rbegin(), (x).rend())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   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; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}
   ll pow(ll a, ll b, ll m){if (b == 0) return 1; else if (a == 0) return 0; else if (b % 2 == 0) return (pow((a * a) % m, b / 2, m) % m); else return (pow((a * a) % m, b / 2, m) * a) % m;}
   ll residue(ll a, ll m){return ((a % m) + m) % m;};

   ll dx[4]={1,0,-1,0};
   ll dy[4]={0,1,0,-1};

int main(){
   ll k; cin >> k;
   if(k == 1){
      cout << 1 << endl;
      cout << 1 << endl;
      return 0;
   }
   ll n = (k + 3) / 4 * 2;
   VVi c(n, Vi(n));
   REP(i, n){
      REP(j, n){
         (i % 2) ? c[i][j] = (i + j) % n + n + 1 : c[i][j] = (i + j) % n + 1;
         if(c[i][j] > k) c[i][j] -= n;
      }
   }
   cout << n << endl;
   REP(i, n){
      REP(j, n){
         if(j) cout << ' ';
         cout << c[i][j];
      }
      cout << endl;
   }
}


Measured memory_bytes: 3200
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	s = reverse(s)

	var t string
	strs := []string{"maerd", "remaerd", "esare", "resare"}

	start := 0
	for len(t) < len(s) {
		flag := false
		for i := 0; i < len(strs); i++ {
			if len(s) < start+len(strs[i]) {
				continue
			}
			if s[start:start+len(strs[i])] == strs[i] {
				t = t + strs[i]
				start += len(strs[i])
				flag = true
			}
		}
		if !flag {
			break
		}
	}

	if t == s {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func reverse(s string) string {
	rs := []rune(s)
	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
		rs[i], rs[j] = rs[j], rs[i]
	}
	return string(rs)
}


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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 29)
#define MOD 1000000007
//int dx[4] = {1,0,0,-1};
//int dy[4] = {0,1,-1,0};

bool is_prime(int n){
  for(int i = 2;i*i <= n;i++){
    if(!(n % i))return false;
  }
  return true;
}

int main(){
  
  int n;
  cin >> n;
  vector<int> v;
  for(int i = 11;i < 55555;i++){ 
    if(is_prime(i) && i % 5 == 1)v.push_back(i);
    if(v.size() == n)break;
  }


  for(auto au : v)cout << au << " ";

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int N = 5e5 + 54;
int n, q, type, x, k, s[N << 2][30], seg[N << 2], pre[N << 2];
char S[N];
int ans, A;
void pushup(int x) {
	for (int i = 0; i < 26; ++i) s[x][i] = s[x << 1][i] + s[x << 1 | 1][i];
	seg[x] = seg[x << 1] | seg[x << 1 | 1];
}
void build(int l, int r, int x) {
	if (l == r) {
		s[x][S[l] - 97] = 1;
		seg[x] = 1 << (S[l] - 97);
		pre[x] = S[l] - 97;
		return;
	}
	int mid = l + r >> 1;
	build(l, mid, x << 1); build(mid + 1, r, x << 1 | 1);
	pushup(x);
}
void modify(int l, int r, int x, int id, int k) {
	if (l == r) {
		int p = pre[x];
		--s[x][p];
		if (s[x][p] == 0) seg[x] -= (1 << p);
		++s[x][k];
		if (s[x][k] == 1) seg[x] += (1 << k);
		pre[x] = k;
		return;
	}
	int mid = l + r >> 1;
	if (id <= mid) modify(l, mid, x << 1, id, k);
	else modify(mid + 1, r, x << 1 | 1, id, k);
	pushup(x);
}
int query(int l, int r, int x, int ql, int qr, int ret = 0) {
	if (ql <= l && r <= qr) return seg[x];
	int mid = l + r >> 1;
	if (ql <= mid) ret |= query(l, mid, x << 1, ql, qr);
	if (qr > mid) ret |= query(mid + 1, r, x << 1 | 1, ql, qr);
	return ret;
}
int main() {
	std::cin >> n;
	std::cin >> S + 1;
	build(1, n, 1);
	for (std::cin >> q; q; --q) {
		std::cin >> type;
		if (type & 1) {
			char y[3];
			std::cin >> x >> y;
			modify(1, n, 1, x, y[0] - 97);
		} else {
			int l, r;
			std::cin >> l >> r;
			ans = query(1, n, 1, l, r), A = 0;
			for (int i = 25; i >= 0; --i) 
				if (ans & (1 << i)) ++A;
			std::cout << A << '\n';
		}
	}
}

Measured memory_bytes: 136448
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vll l(n), r(n);
    for (int i = 0; i < n; i++) {
        cin >> l[i] >> r[i];
        if (!(n & 1)) l[i] <<= 1LL,  r[i] <<= 1LL;
    }
    sort(ALL(l)), sort(ALL(r));
    ll lmed, rmed;
    if (n & 1) {
        lmed = l[n / 2], rmed = r[n / 2];
    } else {
        lmed = (l[n / 2 - 1] + l[n / 2]) >> 1, rmed = (r[n / 2 - 1] + r[n / 2]) >> 1;
    }
    cout << rmed - lmed + 1 << '\n';
    return 0;
}


Measured memory_bytes: 6340
import java.util.*;
import java.math.*;

public class Main{
    public static void main(final String[] args){
        final Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        int ans = 0;
        long q = 2;
        int e = 1;
        long div;

        if(N == 1){
            System.out.println(0);
            return;
        }

        while(true){
            div = (long) Math.pow(q, e);
            if(N % div == 0){
                N /= div;
                ans++;
                e++;
                continue;
            }

            while(N % q == 0){
                N /= q;
            }
            if(q == 2) q ++;
            else q += 2;
            e = 1;
            if(q * q > N) break;
        }

        if(N != 1){
            ans++;
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 35952
/* #8173006が嘘解法なので修正
 * 入力例: 4 -> 2 (3)
 */

#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs

using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }

int main()
{
  fastio();

  ll n;
  cin >> n;

  ll ans = n - 1;
  for (ll i = 1; i*i <= n; i++) {
    if (n % i == 0) {
      if (n/i - 1 + i - 1 < ans) {
        ans = n/i - 1 + i - 1;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


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

struct list{
	char name[15];
	int time;
};
struct list node[100005];

int main()
{
	int n,ti,T=0;
	int i=0;
	scanf("%d%d",&n,&ti);
	int coun=n;
	while(coun--)
	{
		scanf("%s %d",&node[i].name,&node[i].time);
		i++;
	}
	for(int head=0,tail=n;head!=tail;head=(head+1)%(n+1))
	{
		i=head;
		if(node[i].time<=ti)
		{
			T+=node[i].time;
			printf("%s %d\n",node[i].name,T);
			node[i].time=0;
		}
		else
		{
			T+=ti;
			node[tail].time=node[i].time-ti;
			strcpy(node[tail].name,node[i].name);
			tail=(tail+1)%(n+1);
		}
	}
	return 0;
}


Measured memory_bytes: 2684
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,q=map(int,input().split())
    E=[[] for _ in range(n)]
    for _ in range(n-1):
        a,b=map(int,input().split())
        a-=1; b-=1
        E[a].append(b)
        E[b].append(a)
    ans=[0]*n
    for _ in range(q):
        p,x=map(int,input().split())
        p-=1
        ans[p]+=x

    def dfs(v,p=-1):
        for u in E[v]:
            if u==p: continue
            ans[u]+=ans[v]
            dfs(u,v)

    dfs(0)
    print(*ans)

resolve()

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

int main() {
    int a,b;
    cin >> a >> b;
    int count = 0;
    for (int i = a;i < b+1;i++){
        if(i%10 == i/10000 && (i%100) /10 == (i/1000) % 10){
            count ++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
/*...........................
.........tank.jpg............
...........................*/

//PointBlank's code (⌐■_■)

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
 
ll power(ll x, ll y); 
#define repp(I, A, B) for(int I = A; I <= B; I++)
#define rep(I, A, B) for(int I = A; I < B; I++)
#define rrep(I, B, A) for(int I = B; I >= A; I--)
#define pb emplace_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define LB lower_bound
#define UB upper_bound
#define MP make_pair
#define quickio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n"
#define bitcount(n) __builtin_popcountll(n)
#define in_edges(M) repp(I, 1, M){int A, B; cin >> A >> B; v[A].pb(B), v[B].pb(A);}
#define in_dedges(M) repp(I, 1, M){int A, B; cin >> A >> B; v[A].pb(B);}
#define in_wedges(M) repp(I, 1, M){int A, B, C; cin >> A >> B >> C; v[A].pb(B, C), v[B].pb(A, C);}
#define in_dwedges(M) repp(I, 1, M){int A, B, C; cin >> A >> B >> C; v[A].pb(B, C);}
#define endl "\n"

const ll MOD = 1e9 + 7;
const ll INF = 1e18 + 18;
const int inf = 2e9;
 
int main() //PointBlank's code ¯\_(ツ)_/¯
{
    quickio
    int k;
    cin >> k;
    while(k--) cout << "ACL";
}

ll power(ll x, ll y){ 
    ll res = 1; x %= MOD;
    while(y > 0){if(y & 1) res = (res*x) % MOD; y = y>>1, x = (x*x) % MOD;} 
    return res; 
}

Measured memory_bytes: 3640
// AtCoder template
// sabaより胡蝶しのぶさんの方が可愛いのではないか？
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; ++i)

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

    int a,b; cin >> a >> b;
    string ans = "";
    if(a < b){
        rep(i,b) ans += char(a+'0');
    }else{
        rep(i,a) ans += char(b+'0');
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
 
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main() {
    string a, b; cin >> a >> b;
    int aa, bb; cin >> aa >> bb;
    string u; cin >> u;

    if(a == u) aa--;
    else bb--;
    cout << aa << " " << bb << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner reader = new Scanner(System.in);
    
       String input=reader.next().toLowerCase();
       
       if(input.equals("a")|| input.equals("e")|| input.equals("i")|| input.equals("o")|| input.equals("u") )
        {
        System.out.println("vowel");
       
       }
        else
        {
            System.out.println("consonant");
        }
    }}

Measured memory_bytes: 35624
import sys
import numpy as np

I = np.array(sys.stdin.read().split(), dtype=np.int64)
n = I[0]
a = I[1:]

def main():
    c = np.bincount(a, minlength=np.amax(a)+1) 
    tot = np.sum(c * (c - 1) // 2)
    res = tot - (c[a] - 1)
    return res
        
if __name__ == "__main__":
    ans = main()
    print(*ans, sep='\n')

Measured memory_bytes: 32540