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

#ifdef _PRINTDEBUG
  #include "lib/printdebug.hpp"
#else
  #define printdebug(...) 1
#endif
#define MOD_1_000_000_007 (1000000007LL)
#define LINF (1LL<<60)
#define rep(i, n)   for (long long i = 0; i <  (long long)(n); i++)
#define rep1(i, n)  for (long long i = 1; i <  (long long)(n); i++)
#define rep2(i, n)  for (long long i = 2; i <  (long long)(n); i++)
#define rep0c(i, n) for (long long i = 0; i <= (long long)(n); i++)
#define rep1c(i, n) for (long long i = 1; i <= (long long)(n); i++)
#define rep2c(i, n) for (long long i = 2; i <= (long long)(n); i++)
#define repc0(n, i) for (long long i = (long long)(n); i >= 0; i--)
#define repc1(n, i) for (long long i = (long long)(n); i >= 1; i--)
#define repc2(n, i) for (long long i = (long long)(n); i >= 2; i--)
#define REP(i, n, m) for (long long i = (long long)(n); i < (long long)(m); i++)

namespace solver {
  using namespace std;
  typedef long long ll;

  ll N, A[100010], L[100010], R[100010];

  void init() {
    scanf("%lld", &N);
    rep(i, N) scanf("%lld", A+i);
  }

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

  void solve() {
    rep1c(i, N-1) {
      L[i] = gcd(L[i-1], A[i-1]);
      R[N-i-1] = gcd(R[N-i], A[N-i]);
    }
    ll ans = 0;
    rep(i, N) ans = max(ans, gcd(L[i], R[i]));
    cout << ans << endl;
  }
}

int main() {
  solver::init();
  solver::solve();
  return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(0), cin.tie(0) 
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 5;
const ll inf = ~0ull >> 1;
int a[105];
int main() {
    int n;
    cin >> n;
    ll sum = 0;
    for (int i = 0; i <n; ++i) {
        cin >> a[i];
        sum += a[i];
    }
    ll mid = sum / n, mid1 = sum / n + 1;
    ll ans = 0, ans1 = 0;;
    for (int i = 0; i < n; ++i) {
        ans += (a[i] - mid) * (a[i] - mid);
    }
    for (int i = 0; i < n; ++i) {
        ans1 += (a[i] - mid1) * (a[i] - mid1);
    }
    cout << min(ans1, ans) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
class Pair{
	long long int a;
	long long int b;
	Pair(){
		a=0;
		b=0;
	}
	bool operator ()(const Pair x,const Pair y){
		return x.a<y.a;
	}
};
int main(){
	int n;
	cin>>n;
	vector<int>s(n);
	int tmp;
	for(int i=0;i<n;i++){
		cin>>s[i];
	}
	for(int i=0;i<n;i++){
		cin>>tmp;
		s[i]-=tmp;
	}
	long long int sum=0;
	for(int i=0;i<n;i++){
		if(s[i]>0){
			sum+=s[i];
		}
	}
	cout<<sum<<endl;



	return 0;
}

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

using namespace std;
int main(){
    int n;
    cin >> n;
    double t;
    cin >> t;
    double a;
    cin >> a;
    double ans = 10000000000;
    int j = 1;
    for (int i = 0; i < n; ++i) {
        double x;
        cin >> x;
        int tmp = ans;
        ans = min(abs(1000 * t - x * 6 - 1000 * a), ans);
        if(ans != tmp) j = i + 1;
    }
    cout << j << endl;
    return 0;
}

Measured memory_bytes: 764
from heapq import heappush, heappop, heapify
import math

N, M = map(int, input().split())
A = list(map(lambda x: int(x) * -1, input().split()))
heapify(A)
hh = []
for _ in range(M):
    heappush(A, math.ceil(heappop(A) / 2))
print(sum(A) * -1)


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

class queue{
    int *time;
    char (*name)[11];
    int head, tail, size;
public:
    queue(int n){
        size = n;
        time = new int [size];
        name = new char [size][11];
        head = 0;
        tail = 0;
    };
    bool isEmpty(){
        return head==tail;
    };
    bool isFull(){
        return tail==head+size;
    };
    int &push(char *s);
    int pop(char *s);
};

int &queue::push(char *s){
    if(isFull()){
        printf("queue is full.\n");
        exit(1);
    }
    strcpy(name[(tail)%size],s);
    tail = (tail+1) % (2*size);
    return time[(tail-1)%size];
}

int queue::pop(char *s){
    if(isEmpty()){
        printf("queue is empty.\n");
        exit(1);
    }
    strcpy(s,name[(head)%size]);
    head = (head+1) % (2*size);
    return time[(head-1)%size];
}

int main(){
    int time, i, n, q;
    char name[11];
    int total = 0;
    scanf("%d",&n);
    scanf("%d",&q);
    queue ob(n);
    for(i=0;i<n;i++){
        scanf("%s %d",name,&time);
        ob.push(name) = time;
    }
    while(!ob.isEmpty()){
        time = ob.pop(name);
        if(time>q){
            ob.push(name) = time-q;
            total += q;
        }else{
            total += time;
            printf("%s %d\n",name,total);
        }
    }
    return 0;
}



Measured memory_bytes: 3428
package main

import (
	"fmt"
)

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

	n := len(s)
	ret := make([]int, n)
	i := 0
	point := 0
	for i < n {
		start := i
		for s[i] == 'R' {
			i++
		}

		for j := start; j < i; j++ {
			if (i-j)%2 == 0 {
				ret[i]++
			} else {
				ret[i-1]++
			}
		}
		ret[i]++
		point = i
		i++
		if i == n {
			break
		}
		for s[i] == 'L' {
			if (i-point)%2 == 0 {
				ret[point]++
			} else {
				ret[point-1]++
			}
			i++
			if i == n {
				break
			}
		}
	}

	for i := 0; i < n; i++ {
		fmt.Print(ret[i])
		if i != n-1 {
			fmt.Print(" ")
		}
	}
	fmt.Println("")
}


Measured memory_bytes: 4736
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST

bool countup(vector<long>& A, ll i, const ll &N, const ll &M)
{
    bool end = true;
    if(A[i]< M) A[i]++;
    else
    {
        if (i == 0) return false;
        end = countup(A, i-1, N, M);
        A[i] = A[i-1];
    }
    return end;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    ll N, M, Q;
    cin >> N >> M >> Q;
    ll a[Q], b[Q], c[Q], d[Q];
    ll max_total = 0;
    vector<long> A(N);
    for(size_t i=0;i<N; i++)
    {
        A[i] = 1;
    }
    for(size_t i=0;i<Q; i++)
    {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    while(true)
    {
        ll total = 0;
        for(size_t i=0;i<Q; i++)
        {
            if(A[b[i]-1] - A[a[i]-1] == c[i]) total += d[i];
        }
        max_total = max(max_total, total);
        if(!countup(A, N-1, N, M)) break;
    }
    cout << max_total << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl

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

const int MOD = 1e9 + 7;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s, t;
  cin >> s >> t;
  vector<int> cnts(26, 0);
  vector<int> cntt(26, 0);
  for(int i = 0; i < s.size(); i++)
  {
    cnts[s[i] - 'a']++;
    cntt[t[i] - 'a']++;
  }
  sort(cnts.begin(), cnts.end());
  sort(cntt.begin(), cntt.end());
  for(int i = 0; i < 26; i++)
  {
    if(cnts[i] != cntt[i])
    {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";

  return 0;
}


Measured memory_bytes: 916
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m = inpl()
g = [[] for _ in range(n)]
r = dict()
cnt = 0
for _ in range(m):
    a,b = inpl()
    g[a-1].append(b-1)
    g[b-1].append(a-1)
    r[cnt] = (a-1,b-1)
    cnt += 1
res = 0
def chk(g):
    seen = [False] * n
    seen[0] = True
    q = deque([0])
    while q:
        v = q.popleft()
        for nv in g[v]:
            if seen[nv]:
                continue
            seen[nv] = True
            q.append(nv)
    if sum(seen) == n:
        return True
    return False
for i in range(m):
    gg = [[] for _ in range(n)]
    a,b = r[i]
    for j in range(n):
        for k in g[j]:
            if (j,k) == (a,b) or (j,k) == (b,a):
                continue
            gg[j].append(k)
    if not chk(gg):
        res += 1
print(res)    

Measured memory_bytes: 5172
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {
	
	int a, b;
	cin >> a >> b;
	int ans = a + b;

	if (ans % 2)cout << "IMPOSSIBLE" << endl;
	else cout << ans / 2 << endl;

}

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

int n, a[55];
string s[55];
bool vis[55][25][2];
ll dp[55][25][2];

ll fnc(int ke, int pos, bool dik) {
   if(pos == s[ke].size()) return 0;
   bool &done = vis[ke][pos][dik];
   ll &w = dp[ke][pos][dik];
   if(done) return w;
   done = 1, w = 1e18;

   bool pal = 1;
   if(!dik) {
      for(int j=pos, k=s[ke].size()-1; j<k; j++, k--) {
         if(s[ke][j] != s[ke][k]) pal = 0;
      }
   }
   else {
      for(int j=0, k=pos; j<k; j++, k--) {
         if(s[ke][j] != s[ke][k]) pal = 0;
      }
   }
   if(pal) return w = 0;

   for(int i=0; i<n; i++) {
      bool yes = 1;
      int j, k;
      if(!dik) {
         for(j=pos, k=s[i].size()-1; j<s[ke].size() && k>=0 && yes; j++, k--) {
            if(s[ke][j] != s[i][k]) yes = 0;
         }
         if(yes) {
            if(k < 0) w = min(w, a[i] + fnc(ke, j, 0));
            else w = min(w, a[i] + fnc(i, k, 1));
         }
      }
      else {
         for(j=pos, k=0; k<s[i].size() && j>=0 && yes; j--, k++) {
            if(s[ke][j] != s[i][k]) yes = 0;
         }
         if(yes) {
            if(j < 0) w = min(w, a[i] + fnc(i, k, 0));
            else w = min(w, a[i] + fnc(ke, j, 1));
         }
      }
   }
   return w;
}

int main() {
   cin >> n;
   for(int i=0; i<n; i++) cin >> s[i] >> a[i];
   ll ans = 1e18;
   for(int i=0; i<n; i++) ans = min(ans, a[i] + fnc(i, 0, 0));
   if(ans == 1e18) ans = -1;
   cout << ans << endl;
}


Measured memory_bytes: 3640
<?php
// C
fscanf(STDIN, '%d %d', $D, $G);
for ($i = 1; $i <= $D; $i++) {
    fscanf(STDIN, '%d %d', $p, $c);
    for ($j = 0; $j <= $p; $j++) {
        $score[$i][$j] = 100 * $i * $j;
        if ($j === $p) $score[$i][$j] += $c;
    }
}
list($_, $ans) = dp(1, $G);
echo $ans;

function dp($n, $goal)
{
    global $score, $memo, $D;

    if (isset($memo[$n][$goal])) return $memo[$n][$goal];
    if ($goal <= 0) return [0, 0];

    $ressolve = 10000;
    $resscore = -1;
    foreach ($score[$n] as $i => $v) {
        if ($n !== $D) list($nscore, $nsolve) = dp($n + 1, $goal - $v);
        else list($nscore, $nsolve) = [0, 0];
        if ($nscore < 0) continue;
        $cscore = $v + $nscore;
        $csolve = $i + $nsolve;
        if ($cscore < $goal) continue;
        if ($csolve < $ressolve) {
            $ressolve = $csolve;
            $resscore = $cscore;
        }
    }
    $memo[$n][$goal] = [$resscore, $ressolve];
    return $memo[$n][$goal];
}

Measured memory_bytes: 55800
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
template<class T> using vv=vector<vector< T > >;

int main() {
  int n, a;
  scanf("%d%d", &n, &a);
  vi x(n+1);
  FOR (i, 1, n+1) {
    scanf("%d", &x[i]);
  }
  vi sum(n+1, 0);
  FOR (i, 1, n+1) {
    sum[i] = sum[i-1] + x[i];
  }
  // 何枚目までとったか とった枚数 とったカードの合計
  vv<vll> dp(51, vvll(51, vll(2501, 0)));
  dp[0][0][0] = 1;
  FOR (i, 1, n+1) {
    FOR (j, 1, i+1) {
      rep (k, sum[i-1] + 1) {
        dp[i][j][k + x[i]] += dp[i-1][j-1][k];
        dp[i][j-1][k] += dp[i-1][j-1][k];
      }
    }
  }
  ll ans = 0;
  FOR (i, 1, n+1) {
    ans += dp[n][i][i * a];
  }
  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 52352
/*IT'S A VERY LONG ROAD BUT IT WILL BE WORTH IT*/
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define int long long int
signed main() 
{ 
    fast;
    int n,a,b;
    cin>>n>>a>>b;
    int m = (a+b)/(int)2;
    int ans1 = -1,ans2,ans3,ans4,ans5;
    if(m-a == b-m)
        ans1 = m-a;
    ans2 = b-1;
    ans3 = n-a;
    int posa = 1,posb = b-(a-1);
    ans4 = a-1;
    if((posb-posa)%2)
    {
       ans4++;
       posb--;
    }
    int mid = (posb+posa)/2;
        ans4+=mid-1;
    posa = a+(n-b);
    posb = n;
    ans5 = n-b;
    if((posb-posa)%2)
    {
       ans5++;
       posa++;
    }
    mid = (posb+posa)/2;
        ans5+=n-mid;
    if(ans1 == -1)
        cout<<min(ans2,min(ans3,min(ans4,ans5)));
    else
    {
        cout<<min(ans1,min(ans2,min(ans3,min(ans4,ans5))));
    }

} 

Measured memory_bytes: 256
U = 2*10**5
MOD = 10**9+7
 
fact = [1] * (U+1)
fact_inv = [1] * (U+1)

# 階乗のテーブル作成
for i in range(1, U+1):
    fact[i] = (fact[i-1] * i) % MOD

# 階乗の逆元のテーブル作成
fact_inv[U] = pow(fact[U], MOD-2, MOD)
for i in range(U, 0, -1):
    fact_inv[i-1] = (fact_inv[i] * i) % MOD

def comb(n, k):
    if k < 0 or k > n:
        return 0
    x = fact[n]
    x *= fact_inv[k]
    x %= MOD
    x *= fact_inv[n-k]
    x %= MOD
    return x

H, W, A, B = [int(i) for i in input().split(" ")]

ans = 0
# 経路の足し上げ C(縦+横, 縦(or横)) (重複のある組み合わせ)
for i in range(B, W):
    ans += comb((H-A-1) + i, i) * comb((A - 1) + (W-1-i), W-1- i) % MOD
    ans %= MOD
print(ans)

Measured memory_bytes: 42864
n = int(input())
graph = {}
d = [-1] * (n+1)
for i in range(n):
    t = list(map(int, input().split()))
    v = t[0]
    k = t[1]
    graph[v] = [t[i+2] for i in range(k)]

from queue import Queue

def bfs(s):
    d[s] = 0
    q=Queue()
    q.put(s)
    while not q.empty():
        v=q.get()
        for child in graph[v]:
            if d[child] != -1: continue
            d[child] = d[v] + 1
            q.put(child)
bfs(1)
for i in range(1, n+1):print(i,d[i])

Measured memory_bytes: 8724
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define sz(a) ((int)a.size())
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}

ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll div_num(ll n){
  vl div(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      div[i]++;
    }
  }
  if(n!=1)div[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=div[i];
  }
  return num;
}
vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}
long long lopow(ll a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a ;
        a = a * a ;
        n >>= 1;
    }
    return res;
}

        
//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//vc Alp ={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
//cout<<""<<endl;

int main(){
  vl R(200001),W(200001);
  rep(i,200001)R[i]=0,W[i]=0;
  ll N;cin>>N;
  string S;cin>>S;
  if(S[0]=='R')R[0]++;
  else W[0]++;
 ll siz =S.size();
  for(ll i=1; i<siz;i++){
    if(S[i]=='R'){
      R[i]=R[i-1]+1;
      W[i]=W[i-1];
    }
    else{
      W[i]=W[i-1]+1;
      R[i]=R[i-1];
    }
  }
  
  ll v=200001;
  v = min(v,R[siz-1]);
  for(ll i=0; i <siz-1 ;i++){
    ll cnt=max(W[i],R[siz-1LL]-R[i]) ;
    v =min(v,cnt);
  }
  v=min(v,W[siz-1LL]);
  cout <<v<<endl;
}

Measured memory_bytes: 6832
#include<iostream>
  
bool poor(int a, int b, int c) {
  if(a == c || b == c) return a != b;
  return a==b;
}

int main() {
  int A, B, C; std::cin >> A >> B >> C;
  std::cout << (poor(A,B,C)? "Yes": "No") << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using i64 = int64_t;
using ll = long long;
int main() {
  string N;
  cin >> N;
  int p = 0;
  rep(i,N.size()){
    p += int(N.at(i))-48;
    p %= 9;
  }
  if(p == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}

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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

LL modinv(LL a) {
    LL b = MOD, u = 1, v = 0;
    while (b) {
        LL t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= MOD;
    if (u < 0) u += MOD;
    return u;
}

LL moddev(LL a, LL b){
	return a * modinv(b) % MOD;
}

bool check(VI x, VI y){
    REP(i,SIZE(x)){
        if(x[i] != y[i]){
            return false;
        }
    }
    return true;
}

void Main()
{
    int n;cin>>n;
    VI r(n);
    REP(i,n){
        r[i] = i+1;
    }

    VI p(n);
    REP(i, n) cin >> p[i];
    VI q(n);
    REP(i, n) cin >> q[i];
    
    int np=0;
    int nq=0;

    int now=0;
    do {
        if(check(r,p)){
            np = now;
        }
        if(check(r,q)){
            nq = now;
        }
        now ++;
    } while( next_permutation(r.begin(), r.end()) );

    cout << abs(np-nq) << endl; 

	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()

int main(){
    ll N;
    cin >> N;
    vll a(N);
    rep(i, N){
        cin >> a[i];
    }
    vll t;
    rep(i, N){
        ll l = 0, r = (ll)t.size()-1;
        while(l<r){
            ll mid = (l+r) / 2;
            if(t[mid]>=a[i]){
                l = mid+1;
            }
            else{
                r = mid;
            }
        }
        if(r<(ll)t.size() && r>=0 && t[r]<a[i]){
            t[r] = a[i];
        }
        else{
            t.push_back(a[i]);
        }
    }
    cout << t.size() << endl;
}


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

#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<(int)n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fill(a,v) memset(a,v,sizeof(a))
#define d1(a) cout << a << "\n"
#define d2(a,b) cout << a << " " << b << "\n"
#define d3(a,b,c) cout << a << " " << b << " " << c << "\n"
#define d4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << "\n"
#define fast ios:: sync_with_stdio(false),cin.tie(nullptr);

typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;

int32_t main(){
	fast;
	int a,b;
	cin >> a >> b;

	for(int i=0 ; i<=100000 ; i++)
	{
		if(i*8/100 ==a && i*10/100 == b)
		{
			cout << i ;
			return 0;
		}
	}
	cout << "-1";
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int d;

  scanf("%d", &d);

  if (d == 22) {
    printf("Christmas Eve Eve Eve\n");
  }
  else if (d == 23) {
    printf("Christmas Eve Eve\n");
  }
  else if (d == 24) {
    printf("Christmas Eve\n");
  }
  else if (d == 25) {
    printf("Christmas\n");
  }

  return 0;
}


Measured memory_bytes: 128
<?php
list($h, $w, $n) = ints();
list($sr, $sc) = ints();
list($s) = strs();
list($t) = strs();
// マス上に残っていられる範囲を縦横それぞれで求める
$minh = $minw = 1;
$maxh = $h;
$maxw = $w;
for ($i = $n - 1; $i >= 0; --$i) {
    if ($t[$i] === 'D') $minh = max($minh - 1, 1);
    if ($t[$i] === 'U') $maxh = min($maxh + 1, $h);
    if ($t[$i] === 'R') $minw = max($minw - 1, 1);
    if ($t[$i] === 'L') $maxw = min($maxw + 1, $w);

    if ($s[$i] === 'D') --$maxh;
    if ($s[$i] === 'U') ++$minh;
    if ($s[$i] === 'R') --$maxw;
    if ($s[$i] === 'L') ++$minw;

    // マス上に残っていられる最大値より最小値が大きくなる＝その時点でどこにいてもマス上には残れない
    if ($minh > $maxh || $minw > $maxw) exit('NO');
}
// 縦横それぞれでマス上に残っていられる範囲に初期位置が含まれていればOK
echo ($minh <= $sr && $sr <= $maxh) && ($minw <= $sc && $sc <= $maxw) ? 'YES' : 'NO';
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


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

using namespace std;

long long p;
long long mp;
long long a[5000];
long long ans[5000];

long long inq(int a, int x, int mod)
{
    if (x == 0) return 1;
    long long l = inq(a, x / 2, mod);
    if (x % 2) return l * l % mod * a % mod;
    return l * l % mod;
}

long long rev[5000];

struct Poli{
    vector<int> c;
    Poli(vector<int> c_)
    {
        c = c_;
    }
};

Poli operator * (Poli A, Poli B)
{
    Poli C({});
    C.c.resize(A.c.size() + B.c.size() - 1);
    for (int i = 0; i < A.c.size(); i++)
    {
        for (int j = 0; j < B.c.size(); j++)
        {
            C.c[i + j] = (C.c[i + j] + A.c[i] * B.c[j]);
            if (C.c[i + j] >= p || C.c[i + j] < 0) C.c[i + j] = (C.c[i + j] + mp) % p;
        }
    }
    return C;
}

Poli operator / (Poli A, Poli B)
{
    Poli C({});
    reverse(A.c.begin(), A.c.end());
    reverse(B.c.begin(), B.c.end());
    for (int i = 0; i + B.c.size() <= A.c.size(); i++)
    {
        int P = A.c[i];
        int Q = B.c[0];
        int K = P * rev[Q];
        for (int j = 0; j < B.c.size(); j++)
        {
            A.c[i + j] = A.c[i + j] - B.c[j] * K;
            if (A.c[i + j] >= p || A.c[i + j] < 0) A.c[i + j] = (A.c[i + j] + mp) % p; 
        }
        C.c.push_back(K);
    }
    reverse(C.c.begin(), C.c.end());
    return C;
}

int get(Poli A, int x)
{
    int res = 0;
    int F = 1;
    for (int i = 0; i < A.c.size(); i++)
    {
        res += F * A.c[i];
        if (res >= p || res < 0) res = (res + mp) % p;
        F = F * x % p;
    }
    return res;
}

Poli Miay({1});

void construct(int x)
{
    Poli D = Miay;
    Poli E({p - x, 1});

    D = D / E;

    long long value = get(D, x);
    long long multi = inq(value, p - 2, p);

    for (int i = 0; i < D.c.size(); i++)
    {
        ans[i] = ans[i] + multi * D.c[i];
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("text.out", "w", stdout);
    cin >> p;
    for (int i = 1; i < p; i++) rev[i] = inq(i, p - 2, p);
    mp = p * p * p;
    for (int i = 2; i < p; i++)
    {
        if (p % i == 0) 
        {
            cout << "GG not prime! :)";
            return 0;
        }
    }
    for (int i = 0; i < p; i++)
    {
        Poli A({p - i, 1});
        Miay = Miay * A;
    }
    for (int i = 0; i < p; i++) a[i] = 1;
    for (int i = 0; i < p; i++) cin >> a[i];
    for (int i = 0; i < p; i++) if (a[i]) construct(i);
    for (int i = 0; i < p; i++)
    {
        cout << (ans[i] + mp) % p << " ";
    }
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int a[200000];

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n-1; i++) {
        int x;
        cin >> x;
        a[x-1]++;
    }
    for (int i = 0; i < n; i++) {
        cout << a[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 4404
import java.util.*;

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

if(a == b) System.out.println("a == b");
else if(a>b) System.out.println("a > b");
else System.out.println("a < b");
}
}

Measured memory_bytes: 17160
#include<bits/stdc++.h>
using namespace std;
#define y1 A2Dalek
#define y0 Cyberman
#define yn RoseTyler
#define j1 JackHarkness
#define fs first
#define sd second
const int N=300;
const int oo=1e9+5;
int du[]={-1,0,0,1};
int dv[]={0,-1,1,0};
const long long mod=1e9+7;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
long long sqr(long long x) {return x*x;}
int getbit(int state, int i) {return ((state>>i)&1);}

int n,m,res,t,vis[N+5],f[N+5][N+5],c[N+5][N+5],d[N+5];
vector<int> g[N+5];
bool bfs()
{
    for (int i=0;i<=n+m+1;i++) d[i]=0;
    d[0]=1;
    queue<int> q;
    q.push(0);
    while (!q.empty())
    {
        int u=q.front(); q.pop();
        if (u==n+m+1) return true;
        for (int i=0;i<g[u].size();i++)
        {
            int v=g[u][i];
            if (d[v] || f[u][v]>=c[u][v]) continue;
            d[v]=d[u]+1;
            q.push(v);
        }
    }
    return false;
}
int dfs(int u, int Min)
{
    if (u==n+m+1) return Min;
    if (vis[u]!=t) vis[u]=t; else return 0;
    for (int i=0;i<g[u].size();i++)
    {
        int v=g[u][i];
        if (f[u][v]<c[u][v] && vis[v]!=t && d[v]==d[u]+1)
        {
            if (int x=dfs(v,min(Min,c[u][v]-f[u][v])))
            {
                f[u][v]+=x;
                f[v][u]-=x;
                return x;
            }
        }
    }
    return 0;
}
int main()
{
	//freopen("Splay Tree.inp","r",stdin);
	//freopen("Splay Tree.out","w",stdout);
	ios_base::sync_with_stdio(false);
    cin>>n>>m;
    for (int i=1;i<=n;i++) for (int j=1;j<=m;j++)
    {
        char cs;
        cin>>cs;
        if (cs=='S')
        {
            g[0].push_back(i);
            g[0].push_back(j+n);
            g[j+n].push_back(0);
            g[i].push_back(0);
            c[0][i]=oo; c[0][j+n]=oo;
        } else if (cs=='T')
        {
            g[i].push_back(n+m+1);
            g[j+n].push_back(n+m+1);
            g[n+m+1].push_back(i);
            g[n+m+1].push_back(j+n);
            c[i][n+m+1]=oo; c[j+n][n+m+1]=oo;
        } else if (cs=='o')
        {
            g[i].push_back(j+n);
            g[j+n].push_back(i);
            c[i][j+n]=c[j+n][i]=1;
        }
    }
    while (bfs())
    {
        while (int x=(++t,dfs(0,oo))) res+=x;
    }
    if (res>=oo) cout<<-1; else cout<<res;
	return 0;
}


Measured memory_bytes: 896
let inputString = '';

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});
process.stdin.on('end', function() {
    inputString = inputString.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    selectionSort(inputString[1].split(' ').map(str => Number(str)));
});

const selectionSort = (arr) => {
  let swap = 0;

  for (let i=0; i<arr.length; i++) {
    let minj = i;
    for (let j=i; j<arr.length; j++) {
      if (arr[j] < arr[minj]) { minj = j; }
    }
    const a = arr[i];
    const b = arr[minj];
    if (a !== b) {
      arr[minj] = a;
      arr[i] = b;
      swap++;
    }
  }

  console.log(arr.join(' '));
  console.log(swap);
};


Measured memory_bytes: 15588
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] a = new long[3*n];
		for (int i = 0; i < 3*n; i++) a[i] = Long.parseLong(sc.next());
		long max = Long.MIN_VALUE;
		long[] sum1 = new long[n+1], sum2 = new long[n+1];

		PriorityQueue<Long> que = new PriorityQueue<Long>();
		for (int i = 0; i < n; i++) {
			que.add(a[i]);
			sum1[0] += a[i];
		}
		for (int k = 1; k <= n; k++) {
			que.add(a[n-1+k]);
			sum1[k] = sum1[k-1]-que.poll()+a[n-1+k];
		}
		que = new PriorityQueue<Long>();
		for (int i = 3*n-1; i > 2*n-1; i--) {
			que.add(-a[i]);
			sum2[n] += a[i];
		}
		for (int k = n-1; k >= 0; k--) {
			que.add(-a[n+k]);
			sum2[k] = sum2[k+1]+que.poll()+a[n+k];
		}
		for (int k = 0; k <= n; k++) max = Math.max(max,sum1[k]-sum2[k]);
		System.out.println(max);
		sc.close();
	}
}

Measured memory_bytes: 68132
_ = input()
s = input()

max_chars = 0
for i in range(1, len(s)):
    x = s[:i]
    y = s[i:]
    # print(x, y)

    cnt = 0
    for char in set(x):

        if char in y:
            cnt += 1
        max_chars = max(max_chars, cnt)

print(max_chars)


Measured memory_bytes: 2940
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a[] = new int[3];
        for (int i = 0; i < 3; i++) a[i] = sc.nextInt();
        if (a[0] == a[1]) System.out.println(a[2]);
        else if (a[0] == a[2]) System.out.println(a[1]);
        else System.out.println(a[0]);
    }
}

Measured memory_bytes: 23252
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;

int main()
{
  /*
long long int x,y,z;
cin>>x>>y>>z;
long long int sum1=0,sum2=0,sum=0;
long long int borrow=0;
long long int c1=x/z+y/z,c2=(x+z-x%z)/z+y/z,c3=x/z+(y+z-y%z)/z,b1=z-x%z,b2=z-y%z;
sum=c1;
if(c1>=c2 and c1>=c3)
   ;
 else
{
  int check=0;
  if(b1<=y%z)
  {  borrow=b1;
    check=1;}
  if(b2<=x%z and borrow>b2)
    {borrow=b2;
    check=1;}
  if(check)
    sum=c2;
}
cout<<sum<<" "<<borrow;*/
int n,x;
cin>>n>>x;
int a[n];
for(int i=0;i<n;i++)
  cin>>a[i];
int sum=1,cord=0;
int p=0;
while(p<n and a[p]+cord<=x)
{
  cord+=a[p];
  p++;
  sum++;
}
cout<<sum;
return 0;
}


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

#define printl(s) cout << s << endl;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;
using pii = pair<int, int>;
using si = set<int>;

const ll modSeed = pow(10,9) + 7;
const int INF = 100'000'000;

template <typename T>
vector<T> getVector(ll num){
    vector<T> values(num);
    for(ll i=0;i<num;i++){
        cin >> values.at(i);
    }
    return values;
}

string S;
ll N,ans;

int main(){
  cin >> N;
  auto inputs = getVector<int>(N);
  sort(inputs.begin(),inputs.end());
  int mid_1 = N/2;
  int mid_2 = mid_1-1;
  ans = inputs[mid_1] - inputs[mid_2];
  printl(ans);
}


Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,k;cin >> n >> k;
	if(n%k==0) cout << 0 << endl;
	else cout << 1 << endl;
}

Measured memory_bytes: 256
// review
#include <iostream>

using namespace std;

const int MAXN = 1010;
const int MAXH = 100000;
const int INF = 1e9+7;
int h, n;

int dp[MAXH];
int a[MAXN], b[MAXN];

void solve() {
  int amax = 0;
  for (int i=0;i<n;i++) {
    amax = max(amax, a[i]);
  }
  for (int i=0;i<=h+amax;i++) {
    dp[i] = INF;
  }
  dp[0] = 0;
  for (int i=0;i<n;i++) {
    for (int j=0;j<=h+amax-a[i];j++) {
       dp[a[i] + j] = min(dp[j] + b[i], dp[a[i] + j]);
    }
  }
  int ans = INF;
  for (int i=h;i<=h+amax;i++) {
    ans = min(ans, dp[i]);
  }
  cout << ans << endl;
}

int main() {
  cin >> h >> n;
  for (int i=0;i<n;i++) {
    cin >> a[i] >> b[i];
  }
  solve();
}


Measured memory_bytes: 384
n = int(input())
A = tuple(map(int, input().split()))

d = dict()
for a in A:
    d.setdefault(a, 0)
    d[a] += 1

c = 0
for i, count in d.items():
    rem = count - i
    if rem < 0:
        c += count
    else:
        c += rem
print(c)


Measured memory_bytes: 18172
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
using namespace std;
int check_cnt(int n){
    int cnt = 0;
    while(n%2 == 0){
        cnt++;
        n /= 2;
    }
    return cnt;
}
int main(void){
    int n;
    cin >> n;
    int cnt = 0, ans = 1;
    for(int i=1;i<=n;i++){
        int tmp = check_cnt(i);
        if(cnt < tmp){
            ans = i;
            cnt = tmp;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> 
#define ff first 
#define endl "\n"
#define ss second 
#define li list<int>
#define vi vector<int>
#define ll long long int
#define pii pair<int,int>
#define vii vector<pair<int,int> >
#define mp make_pair
#define pb push_back
#define setbits(x) __builtin_popcountll(x)
#define custom  pair<int,pair<int,int> >
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> pbds; 
#define mod 1000000007
ll power(int a,int n,int m){
    ll ans=1;
    while(n>0){
        if(n&1){
            ans=(ans*a)%m;
        }
        n=n>>1;
        a=((a%m)*(a%m))%m;
    }
    return ans;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    string s,t;
    cin>>s>>t;
    int slength=s.length();
    int tlength=t.length();
    int matrix[slength+1][tlength+1];
    memset(matrix,0,sizeof matrix);
    for(int i=1;i<=slength;i++){
        for(int j=1;j<=tlength;j++){
            if(s[i-1]==t[j-1]){
                matrix[i][j]=1+matrix[i-1][j-1];
            }
            else{
                matrix[i][j]=max(matrix[i-1][j],matrix[i][j-1]);
            }
        }
    }
    string k="";
    int i=slength;int j=tlength;
    while(i>0 && j>0){
        if(s[i-1]==t[j-1]){
            k+=s[i-1];
            i--;j--;
        }
        else{
            int temp=max(matrix[i][j-1],matrix[i-1][j]);
            if(temp==matrix[i][j-1])
            j--;
            else{
                i--;
            }
        }
    }
    reverse(k.begin(),k.end());
    cout<<k;
    return 0;
}

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

int main()
{
    long long n, d;
    cin >> n >> d;
    long long max = d * d;
    int ans = 0;

    for (int i = 0; i < n; i++)
    {
        long long x, y;
        cin >> x >> y;

        long long dist = x * x + y * y;
        if (dist <= max)
        {
            ans++;
        }
    }

    cout << ans << endl;
}



Measured memory_bytes: 3616
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <random>
#include <functional>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;

ll min(ll a, ll b) {return a < b ? a : b;}
ll min(int a, ll b) {return a < b ? a : b;}
ll min(ll a, int b) {return a < b ? a : b;}
ll min(int a, int b) {return a < b ? a : b;}

ll max(ll a, ll b) {return a > b ? a : b;}
ll max(int a, ll b) {return a > b ? a : b;}
ll max(ll a, int b) {return a > b ? a : b;}
ll max(int a, int b) {return a > b ? a : b;}

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()
#define int long long

const int N = 2000;
const int MOD = 1e9 + 7;

int n, k;
int a[N];

int dp[30][N];

int fact[N], ufact[N], r[N];

int cnk(int n, int k)
{
    return fact[n] * ufact[k] % MOD * ufact[n - k] % MOD;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    for (int i = 0; i < k; i++) cin >> a[i];
    r[1] = 1;
    for (int i = 2; i < N; i++) r[i] = MOD - r[MOD % i] * (MOD / i) % MOD;
    fact[0] = 1, ufact[0] = 1;
    for (int i = 1; i < N; i++) fact[i] = fact[i - 1] * i % MOD, ufact[i] = ufact[i - 1] * r[i] % MOD;
    dp[0][0] = fact[n];
    for (int i = 1; i <= k; i++)
    {
        for (int st = 0; st < N - a[i - 1] - 1; st++)
        {
            for (int fn = st; fn <= st + a[i - 1]; fn++)
            {
                int x = fn - st;
                dp[i][fn] = (dp[i][fn] + dp[i - 1][st] * ufact[x] % MOD * cnk(n - x, a[i - 1] - x)) % MOD;
            }
        }
    }
    long long ans = 0;
    for (int st = n; st <= n; st++) ans = (ans + dp[k][st]) % MOD;
    cout << ans;
}


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

int main(){
    int n,m;
    cin>>n>>m;
    vector<int> a(n);
    double sum=0;
    rep(i,n){
        cin>>a.at(i);
        sum+=a.at(i);
    }
    int ans=0;
    rep(i,n){
        if(4*m*a.at(i)>=sum)
            ans++;
    }
    if(ans>=m) cout<<"Yes"<<endl;
    else       cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
using namespace std;

#include <iostream>

int main(
){
    char    str[6];
    string  ans = "No";
    std::cin >> str;

    if(str[2] == str[3]){
        if(str[4] == str[5]){
            ans = "Yes";
        }
    }

    std::cout << ans << std::endl;
    return 0;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
  int n; cin>>n;
  string s; cin>>s;
  int f = 0; int b = 0;
  string ans1 = "";
  string ans2 = "";
  REP(i,n){
    if(s[i]=='(') f++;
    else b++;
    if(f>b){
      ans2 += ')'; f--;
    }
  }
  rep(i,b-f){
    ans1 += '(';
  }
  cout << ans1 << s << ans2 << endl;

  return 0;
}


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

int gcd_1(int a, int b){
    if (b == 0)
        return a;
    return gcd_1(b, a % b);
}
int main()
{
    int n, t;
    cin >> n;
    vector<int> a;
    for(int i = 0; i < n; ++i){
        cin >> t;
        a.push_back(t);
    }
    sort(a.begin(), a.end());
    double c = a[0];
    for(int i = 1; i < n; i++){
        c = (c + a[i])/2.0;
    }
    cout << c << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <class T> using oset = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

void usaco(string name = "")
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if(name.size())
    {
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}

#define int long long
#define x first
#define y second

const int mod = 1e9+7;

int32_t main()
{
    usaco();
    int n;
    cin >> n;
    vector <pair <int, int>> pt(n);
    for (int i = 0; i < n; ++i) cin >> pt[i].x >> pt[i].y;
    sort(begin(pt), end(pt));
    int m1 = 1e18, m2 = 1e18, ans = 0;
    for (auto i : pt)
    {
        m1 = min(m1, i.x+i.y);
        m2 = min(m2, i.x-i.y);
        ans = max({ans, i.x+i.y-m1, i.x-i.y-m2});
    }
    cout << ans << '\n';
}


Measured memory_bytes: 6340
#include "iostream"
#include "vector"
#include "string"

using namespace std;

int main() {
	int A,B,C,K;
	int total;
	int leftN;

	cin >> A >> B >> C >> K;
	
	total = 0;
	leftN = K;

	if (A < K) {
		total += A;
		leftN -= A;
	}
	else {
		total = leftN;
		cout << total;
		return 0;
	}

	if (B < leftN) {
		leftN -= B;
	}
	else {
		cout << total;
		return 0;
	}

	if (C < leftN) {
		total -= C;
	}
	else {
		total -= leftN;
	}

	cout << total;
	return 0;

}

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

N = INT()
A = LIST()

num = [0]*(N+1)  # 各層で葉を除いたとれるノードの限界

ma = 1
for i, a in enumerate(A):
	if i == N and a <= ma:
		num[i] = ma-a
	elif a <= ma-1:
		num[i] = ma-a
		ma = (ma-a)*2
	else:
		print(-1)
		exit()

tmp = 0
ans = 0
for i, a in enumerate(A[::-1]):
	d = N-i
	if tmp > num[d]:
		tmp = num[d]
	tmp += a
	ans += tmp

print(ans)


Measured memory_bytes: 706408
#include <stdio.h>
int main(void) {
  int N;
  int M;
  int i;
  int sum = 0;

  scanf("%d", &N);
  scanf("%d", &M);

  int A[M];
  for (i = 0; i < M; i++) {
    scanf("%d", &A[i]);
    sum += A[i];
  }
  if (N < sum) {
    printf("%d\n", -1);
  } else {
    printf("%d\n", N - sum);
  }
  return 0;
}

Measured memory_bytes: 1708
from collections import defaultdict
A, B = map(int, input().split())
ls = defaultdict(int)
ans = 0
for i in range(1, max(int(A**0.5)+1, int(B**0.5)+1)):
  if A%i==0 and B%i==0:
    if ls[i]==0:
      ls[i]=1
      for n in range(2,int(i**0.5)+1):
        if i%n==0:
          break
      else:
        ans += 1
  if A%i==0:
    j = A//i
    if B%j!=0:
      continue
  elif B%i==0:
    j = B//i
    if A%j!=0:
      continue
  else:
    continue
  if ls[j]==0:
    ls[j] = 1
  else:
    continue
  for n in range(2,int(j**0.5)+1):
    if j%n==0:
      break
  else:
    ans += 1
print(ans)

Measured memory_bytes: 4156