akhauriyash/Code-Regression huggingface dataset:
using System.Collections.Generic;
using static System.Console;
using static System.Math;

class Program {
	static void Main() {
		var N = NextInt();
		var M = NextInt();

		var a = new int[N];
		var b = new int[N];

		for (var i = 0; i < N; i++) {
			a[i] = NextInt();
			b[i] = NextInt();
		}

		var c = new int[M];
		var d = new int[M];

		for (var j = 0; j < M; j++) {
			c[j] = NextInt();
			d[j] = NextInt();
		}

		for (var i = 0; i < N; i++) {
			WriteLine(Calc(a[i], b[i], c, d));
		}
	}

	static int Calc(int a, int b, int[] c, int[] d) {
		int key = 0;
		int val = int.MaxValue;
		var M = c.Length;
		for (var i = 0; i < M; i++) {
			var tmp = Abs(a - c[i]) + Abs(b - d[i]);
			if (tmp < val) {
				val = tmp;
				key = i + 1;
			}
		}
		return key;
	}

	static int NextInt() {
		return int.Parse(NextString());
	}

	static string NextString() {
		var result = new List<char>();
		while (true) {
			int next = Read();
			if (next < 0)
				break;
			var nextChar = (char)next;
			if (!char.IsWhiteSpace(nextChar))
				result.Add(nextChar);
			else if (nextChar != '\r')
				break;
		}
		return string.Join("", result);
	}
}


Measured memory_bytes: 11220
import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

import numpy as np

MOD = 10**9 + 7

N = int(readline())
C = np.array([line.split() for line in readlines()],np.int8)

def rank(A):
    if (A==0).all():
        return 0
    i = np.nonzero(A[:,0])[0]
    if len(i) == 0:
        return rank(A[:,1:])
    i = i[0]
    temp = A[i].copy()
    A[i] = A[0]
    A[0] = temp
    A[1:] ^= A[1:,0][:,None] * A[0][None,:]
    return 1 + rank(A[1:,1:])

def cumprod(arr,MOD):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq)
    for n in range(1,Lsq):
        arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD
    for n in range(1,Lsq):
        arr[n] *= arr[n-1,-1]; arr[n] %= MOD
    return arr.ravel()[:L]

def power_mod(a,n,MOD):
    if n == 0:
        return 1
    x = power_mod(a,n//2,MOD)
    x *= x
    x %= MOD
    return (a*x)%MOD if n&1 else x

r = rank(C)

x = np.full(N*N+100,2,np.int64); x[0] = 1
pow2 = cumprod(x,MOD)

G = np.zeros((N+1,N+1),np.int64)
for n in range(N+1):
    G[n,1:] = pow2[n] - pow2[:N]
G[:,0] = 1
for n in range(1,N+1):
    G[:,n] *= G[:,n-1]; G[:,n] %= MOD

Gd = np.diagonal(G)

D = G * power_mod(Gd,MOD-2,MOD)[None,:] % MOD
F = np.zeros((N+1,N+1),np.int64)
for n in range(N+1):
    F[n,:n+1] = Gd[:n+1] * D[n,n::-1] % MOD

B = D[N] * F[N] % MOD

C = D[N,r] * F[:,r] % MOD * pow2[N*N::-N] % MOD

A = (B[r:N+1] * C[r:N+1] % MOD).sum() % MOD

answer = A * pow(int(B[r]),MOD-2,MOD) % MOD
print(answer)

Measured memory_bytes: 16900
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, Y) for (int(X) = 0; (X) < (Y); ++(X))
#define rrep(X, Y) for (int(X) = (Y)-1; (X) >= 0; --(X))
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

void solve(long long N, std::vector<long long> A) {
  if (A[0] != 0) {
    print(-1);
    return;
  }

  ll ans = 0;
  rep(i, N) {
    while (i < N - 1 && A[i + 1] - A[i] == 1) {
      i++;
    }
    ans += A[i];

    if (i < N - 1 && A[i + 1] - A[i] > 1) {
      print(-1);
      return;
    }
  }

  print(ans);
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, std::move(A));
  return 0;
}


Measured memory_bytes: 1792
using System;
class Program
{
	static void Main(string[] args)
	{
		string[] input = Console.ReadLine().Split(' ');
		// 文字列の入力
        int n = int.Parse(input[0]);
        long k = long.Parse(input[1]);
        input = Console.ReadLine().Split(' ');
        int[] a = new int[n];
        for(int i = 0; i<n;i++) a[i] = int.Parse(input[i]);

        int[] cnt = new int[n];
        cnt[0] = 1;
        int prePos = 1;
        int[] one = new int[n];
        int[] two = new int[n];
        int oneC = 1;
        int twoC = 0;
        while(true)
        {
          cnt[a[prePos-1]-1]++;
          int tmp = cnt[a[prePos - 1]-1];

          if(tmp == 3) break;
          if(tmp == 1)
          {
            one[oneC] = a[prePos - 1];
            oneC++;
          }
          else
          {
            two[twoC] = a[prePos - 1];
            twoC++;
          }
          prePos = a[prePos - 1];
        }
      
        int ans = 0;
        if((long)oneC > k)
        {
          ans = one[(int)k];
        }
        else
        {
          k = k - (long)oneC;
          long index = k % (long)twoC;
          //Console.WriteLine(index);

          ans = two[(int)index];
        }
        Console.WriteLine(ans);
	}
}

Measured memory_bytes: 44524
#include <algorithm>
#include <iostream>


int main() {
  int n;
  std::cin >> n;
  int a, b, c;
  std::cin >> a >> b >> c;
  int bestA = a, bestB = b, bestC = c;
  for(int i = 1; i < n; i++) {
    std::cin >> a >> b >> c;
    a = std::max(bestB + a, bestC + a);
    b = std::max(bestA + b, bestC + b);
    c = std::max(bestA + c, bestB + c);
    bestA = a; bestB = b; bestC = c;
  }
  std::cout << std::max(bestA, std::max(bestB, bestC)) << "\n";
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  vary(ll,ans,1001,0);
  REP(i,1,1001){
    REP(j,1,(i+1)/2 + 1){
      ll t = j;
      ll num = t;
      while(t <= i){
        ++t;
        if(num + t == i) ans[i]++;
        num += t;
      }
    }
  }
  while(cin >> n && n){
    cout << ans[n] << endl;
  }
  return 0;
}

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

int main(){
long long x; cin >> x;
long long year;
long long balance{100};
for(long long i{}; i<=x; i++){
	balance=balance+balance/100;
	if(balance>=x){
		year = i;
		break;
	}
}

cout << year+1 << "\n";
	return 0;
}




Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
inline int_fast64_t read(){int_fast64_t x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return x*f;}
void Main(){
    int_fast64_t  fav = 753, S = read(), ans = 1000;
    while (S >= 100) {
        ans = min(ans, abs(fav-S%1000));
        S /= 10;
    }
    printf("%lld\n", ans);
}
int main(){cin.tie(nullptr);ios::sync_with_stdio(false);Main();return 0;}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%s", $s);
//1行入力
$single_line_input = trim(fgets(STDIN));
//不要な改行コードを取り除く
$single_line_input = str_replace(array("\r\n","\r","\n"), '', $single_line_input);
//スペースで分解して配列に格納
$a = explode(" ", $single_line_input);

    $value_count = array_count_values($a); // 各値の出現回数を数える
    $max = max($value_count); // 最大の出現回数を取得する
    if ($max == 1) {
        echo('YES');
    } else {
        echo('NO');
    }
    

?>

Measured memory_bytes: 33780
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define STRINGIFY(n) #n
#define TOSTRING(n) STRINGIFY(n)
#define PREFIX "#" TOSTRING(__LINE__) "| "
#define debug(x) \
{ \
  std::cout << PREFIX << #x << " = " << x << std::endl; \
}

std::ostream& output_indent(std::ostream& os, int ind) {
  for(int i = 0; i < ind; i++) os << " ";
  return os;
}

template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p);
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v);

template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p) {
  return (os << "(" << p.first << ", " << p.second << ")");
}
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
  os << "[";
  for(int i = 0;i < v.size();i++) os << v[i] << ", ";
  return (os << "]");
}

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }

int main() {
  i64 H, W, K;
  cin >> H >> W >> K;
  vector<string> f(H);
  rep(i,0,H) {
    cin >> f[i];
  }
  i64 ans = 0;
  for(int s = 0; s < (1 << H); s++) {
    for(int t = 0; t < (1 << W); t++) {
      i64 cnt = 0;
      rep(i,0,H) rep(j,0,W) {
        if(f[i][j] == '#' && !(s & (1 << i)) && !(t & (1 << j))) {
          cnt++;
        }
      }
      if(cnt == K) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3628
N,M,K=map(int,input().split())
A=[0]+list(map(int,input().split()))
B=[0]+list(map(int,input().split()))
for i in range(1,N+1):
  A[i]+=A[i-1]
for i in range(1,M+1):
  B[i]+=B[i-1]

best=0
j=M
for i in range(0,N+1):
  while j>0:
    if A[i]+B[j]<=K:
      break
    else: j-=1
  if A[i]+B[j]<=K:
    best=max(best,i+j)
  pass
print(best)

Measured memory_bytes: 39964
import sys
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
class BIT():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        self.UNITY_SUM = 0
        self.dat = [[self.UNITY_SUM for i in range(n + 1)] for j in range(2)]
    
    def sub_ADD(self, p, a, x):
        i = a
        while i < len(self.dat[p]):
            self.dat[p][i] = self.dat[p][i] + x
            i += i & -i
    
    def ADD(self, a, b, x):
        self.sub_ADD(0, a, x * -(a - 1))
        self.sub_ADD(1, a, x)
        self.sub_ADD(0, b, x * (b - 1))
        self.sub_ADD(1, b, x * (-1))
    
    def sub_SUM(self, p, a):
        res = self.UNITY_SUM
        i = a
        while i > 0:
            res += self.dat[p][i]
            i -= i & -i
        return res
    
    def SUM(self, a, b):
        return self.sub_SUM(0, b - 1) + self.sub_SUM(1, b - 1) * (b - 1) - self.sub_SUM(0, a - 1) - self.sub_SUM(1, a - 1) * (a - 1)
    
    def PRINT(self):
        for i in range(1, len(self.dat[0])):
            print(self.SUM(i, i + 1), end = "")
            print(",", end = "")
        print()
 
def main():
    N, Q = map(int,readline().split())
    C = list(map(int,readline().split()))  #対象のリスト
    S = sys.stdin.readlines()
    lefts = [0] * Q
    rights = [0] * Q
    ids = [0] * Q
    for i in range(Q):
        lefts[i], rights[i] = map(int,S[i].split())
        lefts[i] -= 1
        ids[i] = i
    
    ids = sorted(ids, key=lambda x: rights[x])
 
    bit = BIT(N+5)
    prev = [-1] * 1100000
    res = [0] * Q
    r = 0
    for i in ids:
        while r < rights[i]:
            bit.ADD(prev[C[r]]+2, r+2, 1)
            prev[C[r]] = r
            r += 1
        tmp = bit.SUM(lefts[i]+1, lefts[i]+2)
        res[i] = max(res[i], tmp)
    for i in range(Q):
        print(res[i])
 
main()

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

#include <fstream>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  /*
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
  //*/
  string S, T;
  cin >> S >> T;
  if(T.substr(0, S.size()) == S){
    cout << "Yes"<<endl;
  }
  else {
    cout << "No" <<endl;
  }
}


Measured memory_bytes: 3664
module IntSet = Set.Make (struct
  type t = int
  let compare = compare
end)

let () = Scanf.scanf "%d\n" @@ fun n ->
  let as_ = Array.init n @@ fun _ -> Scanf.scanf "%d\n" @@ fun a -> a in
  let s = Array.fold_right (fun a -> IntSet.add (a lxor (a - 1))) as_ IntSet.empty in
  Printf.printf "%d\n" @@
  match
    Array.fold_left (fun (n, b, sum) i ->
      if sum land (1 lsl i) = 0
      then
        n, b, sum
      else
        n + 1,
        b && IntSet.mem ((1 lsl (i + 1)) - 1) s,
        sum lxor ((1 lsl (i + 1)) - 1))
    (0, true, Array.fold_left ( lxor ) 0 as_) @@
    Array.init 40 @@ ( - ) 39
  with
  | (n, true, _) -> n
  | (_, false, _) -> -1


Measured memory_bytes: 5504
N , K = gets.split.map{|i| i.to_i}
h = gets.split.map{|i| i.to_i}
dp = Array.new(N , 10 ** 19)
dp [0] = 0

for i in 1 .. N - 1
    if i <= K
        dp[i] = (h[i] - h[0]).abs
        next
    end

    for j in 1 .. K
        if (dp[i] > dp[i - j] + (h[i] - h[i - j]).abs)
            dp[i] = dp[i - j] + (h[i] - h[i - j]).abs
        end
    end
end

puts dp[N - 1]

Measured memory_bytes: 11404
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define ll long long
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//オーバーフローに注意 long long　にする
//'1'+=16;      で大文字Aに
//'大文字'+=32;  で小文字に
//string s = to_string(int数);
//int n = stoi(string文字列);


 
int main() {
 
  int n;
  cin >> n;
  
  bool a,b,c;
  a=false;
  b=false;
  c=false;
  
  int ans=1;
  
  while(1) {
    if(n==1 && a) {
    cout << ans << endl;
    return 0;
    }
    else if(n==2 && b) {
    cout << ans << endl;
    return 0;
    }
    else if(n==4 && c) {
    cout << ans << endl;
    return 0;
    }
    else if(n==1) {
    n=4;
    a = true;
    ans++;
    }
    else if(n==2) {
    n=1;
    b = true;
    ans++;
    }
    else if(n==4) {
    n=2;
    c = true;
    ans++;
    }
    else if(n%2==0) {
    n/=2;
    ans++;
    }
    else if(n%2==1) {
    n=3*n+1;
    ans++;
    }
    
  }

  cout << ans << endl;
  
}

Measured memory_bytes: 256
/*************************************************************************
  > File Name: a.cpp
  > Author: Samuel
  > Mail: enminghuang21119@gmail.com
  > Created Time: Sat Mar 21 20:02:54 2020
*************************************************************************/

#include <bits/stdc++.h>
using namespace std;

int in[110][110];
int n, m;
bool vis[110][110];
int dis[110][110];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++) {
            char a;
            cin >> a;
            in[i][j] = a != '.';
        }
    queue<pair<int, int>> q;
    for (int i = 0; i <= n; i++)
        for (int j = 0; j <= m; j++)
            dis[i][j] = 1e9;
    dis[0][1] = 0;
    q.push({0, 1});
    while (!q.empty()) {
        auto cur = q.front();
        q.pop();
        int x = cur.first;
        int y = cur.second;
        int nx, ny;
        for (int i = 0; i < 4; i++) {
            nx = x + dx[i];
            ny = y + dy[i];
            if (nx < 1 || ny < 1 || nx > n || ny > m)
                continue;
            if (in[x][y] == in[nx][ny] || (in[x][y] && !in[nx][ny]))
                dis[nx][ny] = min(dis[nx][ny], dis[x][y]);
            else
                dis[nx][ny] = min(dis[nx][ny], dis[x][y] + 1);
            if (!vis[nx][ny])
                q.push({nx, ny});
            vis[nx][ny] = 1;
        }
    }
    cout << dis[n][m] << '\n';
    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;
//import java.io.*;
//import java.util.Arrays;
public class Main {
	public static void main(String[] args) throws java.io.IOException {
		Scanner scan = new Scanner(System.in);
		//InputStreamReader is = new InputStreamReader(System.in);
		//BufferedReader br = new BufferedReader(is);
		//String text = scan.next();
		int n = scan.nextInt();
		int a[] = new int[n];
		int v[] = new int[n];
		for(int i = 0 ; i < n ; i++){
			a[i] = scan.nextInt();
			v[i] = scan.nextInt();
		}
		int maxA = a[0];
		int maxV = v[0];
		for(int i = 1 ; i < n ; i++){
			if(maxV < v[i]){
				maxA = a[i];
				maxV = v[i];
			}else if(maxV == v[i]){
				if(maxA > a[i]){
					maxA = a[i];
				}
			}
		}
		System.out.println(maxA + " " + maxV);
	}
}

Measured memory_bytes: 26188
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int[][] field = new int[h + 1][w + 1];
		for (int i = 1; i <= h; i++) {
		    for (int j = 1; j <= w; j++) {
		        field[i][j] = sc.nextInt();
		    }
		}
		ArrayList<Graph> list = new ArrayList<>();
		for (int i = 1; i <= h; i++) {
	        for (int j = 1; j < w; j++) {
	            if (field[i][j] % 2 == 1) {
	                field[i][j + 1]++;
	                list.add(new Graph(i, j, i, j + 1));
	            }
	        }
	        if (field[i][w] % 2 == 1 && i < h) {
	            field[i + 1][w]++;
	            list.add(new Graph(i, w, i + 1, w));
	        }
		}
		StringBuilder sb = new StringBuilder();
		sb.append(list.size()).append("\n");
		for (Graph g : list) {
		    sb.append(g);
		}
		System.out.print(sb);
    }
    
    static class Graph {
        int a;
        int b;
        int c;
        int d;
        
        public Graph(int a, int b, int c, int d) {
            this.a = a;
            this.b = b;
            this.c = c;
            this.d = d;
        }
        
        public String toString() {
            return new StringBuilder().append(a).append(" ").append(b).append(" ").append(c).append(" ").append(d).append("\n").toString();
        }
    }
}



Measured memory_bytes: 95656
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string S;
int x[4];
int main() {
	cin >> S;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'K') { x[0]++; }
		if (S[i] == 'U') { x[1]++; }
		if (S[i] == 'P') { x[2]++; }
		if (S[i] == 'C') { x[3]++; }
	}
	sort(x, x + 4);
	cout << x[0] << endl;
	return 0;
}

Measured memory_bytes: 1204
from numpy.linalg import solve
import math
import sys
input = sys.stdin.readline

MOD = 10 ** 9 + 7



def main():
    X, Y = map(int, input().split())

    if (X + Y) % 3 != 0:
        print(0)
        quit()

    left = [[2, 1], [1, 2]]
    right = [X, Y]

    n, m = map(int, solve(left, right))

    if n < 0 or m < 0:
        print(0)
        quit()

    fact = [1, 1]
    factinv = [1, 1]
    inv = [0, 1]

    def cmb(n, r):
        if (r < 0) or (n < r):
            return 0
        r = min(r, n-r)
        return fact[n] * factinv[r] * factinv[n-r] % MOD

    for i in range(2, n + m + 1):
        fact.append((fact[-1] * i) % MOD)
        inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
        factinv.append((factinv[-1] * inv[-1]) % MOD)

    print(cmb(n+m, n))


if __name__ == "__main__":
    main()


Measured memory_bytes: 93320
fn main() {
    let n: usize = read();
    let d: i32 = read();
    let x: i32 = read();
    let mut a: Vec<i32> = Vec::new();
    for _ in 0..n {
        a.push(read());
    }

    let mut ans = x;
    for i in 0..n {
        ans += (d-1) / a[i] + 1;
    }
    println!("{}", ans);
}

// 以下関数


use std::io::*;
use std::str::FromStr;
pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub const MOD: u64 = 10e9 as u64 + 7;

pub fn is_prime(n: i32) -> bool {
    if n < 2 {
        return false;
    } else if n == 2 {
        return true;
    }
    let mut i = 2;
    while i * i < n {
        if n % i == 0 {
            return false;
        } else {
            i += 1;
            continue;
        }
    }
    true
}

pub fn lcm(mut n: i32, mut m: i32) -> i32 {
    n = if n > m { m } else { n };
    m = if n > m { n } else { m };
    let mut i = n;
    while i % m != 0 {
        i += n;
    }
    i
}

pub fn abs(n: i32) -> i32 {
    if n >= 0 {
        n
    } else {
        -n
    }
}

pub fn max(n: i32, m: i32) -> i32 {
    if n >= m {
        n
    } else {
        m
    }
}

pub fn min(n: i32, m: i32) -> i32 {
    if n <= m {
        n
    } else {
        m
    }
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int main()
{
    int n, m;
    cin >> n >> m;
    Graph G(n);
    rep(i, m)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<int> p(n, -1);
    queue<int> que;
    p[0] = 0;
    que.push(0);
    while (!que.empty()) {
        int v = que.front();
        que.pop();
        for (auto nv : G[v]) {
            if (p[nv] == -1) {
                p[nv] = v;
                que.push(nv);
            }
        }
    }

    for (int i = 0; i < n; i++) {
        if (p[i] == -1) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    for (int i = 1; i < n; i++) {
        cout << p[i] + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 10220
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

  int N;
  cin>>N;
  string S;
  cin>>S;
  if(N%2){
    cout<<"No"<<endl;
    return 0;
  }

  string l=S.substr(0,N/2);
  string r=S.substr(N/2,N/2);
  if(l==r) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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; }

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

int main () {
  string s;
  cin >> s;

  int n = sz(s);
  
  if (n==1) {
    cout << s[0] << endl;
    return 0;
  }

  ll ans = 0;
  rep(b,1<<(n-1)) {
    ll cur = s[0]-'0';
    rep(i,n-1) {
      if (b&(1<<i)) {
        ans += cur;
        cur = s[i+1]-'0';
      }
      else {
        cur = 10*cur + s[i+1]-'0';
      }

      if (i == n-2) ans += cur;
    }
  }

  cout << ans << endl;
}


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

using namespace std;

int main() {
	int n;
	string str1, str2;
	cin >> n >> str1 >> str2;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (0 <= str1.find(str2.substr(0, i + 1)) && str1.find(str2.substr(0, i + 1)) < n) {
			ans++;
		}
	}
	cout << n * 2 - ans << endl;
	system("pause");
	return 0;
}

Measured memory_bytes: 504
import java.util.*;
class P
{
	int first;
	int second;
	P(int first, int second)
	{
		this.first = first;
		this.second = second;
	}
}
public class Main 
{
	static int strToInt(String str)
	{
		int num = 0;
		int multiple = 1;
		for(int i = str.length() - 1; i >= 0; --i)
		{
			num += (str.charAt(i) - '0') * multiple;
			multiple *= 10;
		}
		return(num);
	}
	
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext())
		{
			String tmpStr = stdIn.next();
			int L = stdIn.nextInt();
			if(tmpStr.equals("0") && L == 0)
			{
				break;
			}
			int n = tmpStr.length();
			String str = "";
			for(int i = 0; i < L - n; ++i)
			{
				str += "0";
			}
			for(int i = 0; i < n; ++i)
			{
				str += tmpStr.charAt(i);
			}
			List<P> pairs = new ArrayList<P>();
			pairs.add(new P(strToInt(str), 0));
			int count = 0;
			boolean flag = false;
			while(!flag)
			{
				++count;
				List<Character> c = new ArrayList<Character>();
				for(int i = 0; i < L; ++i)
				{
					c.add(str.charAt(i));
				}
				Collections.sort(c);
				String sMin = "";
				for(int i = 0; i < L; ++i)
				{
					sMin += c.get(i);
				}
				String sMax = "";
				for(int i = sMin.length() - 1; i >= 0; --i)
				{
					sMax += sMin.charAt(i);
				}
				int a = strToInt(sMax) - strToInt(sMin);
				for(int i = 0; i < pairs.size(); ++i)
				{
					if(pairs.get(i).first == a)
					{
						System.out.println(i + " " + a + " " + (count - i));
						flag = true;
						break;
					}
				}
				pairs.add(new P(a, count));
				String temp = "";
				for(int i = 0; i < L; ++i)
				{
					temp += a % 10;
					a /= 10;
				}
				str = temp;
			}
		}
	}
}

Measured memory_bytes: 12000
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

using namespace std;

int main() {
  int w, a, b;
  scanf("%d%d%d", &w, &a, &b);
  printf("%d\n", max(0, max(a, b)-min(a, b)-w));
  return 0;
}


Measured memory_bytes: 128
mod = 10 ** 9 + 7

def main():
    s = input()

    n = len(s)

    dp = [[0 for _ in range(4)] for _ in range(n+1)]
    dp[0][0] = 1
    for i in range(n):
        if s[i] in ('A', '?'):
            dp[i+1][0] = (dp[i+1][0] + dp[i][0]) % mod
            dp[i+1][1] = (dp[i+1][1] + dp[i][1]) % mod
            dp[i+1][2] = (dp[i+1][2] + dp[i][2]) % mod
            dp[i+1][3] = (dp[i+1][3] + dp[i][3]) % mod
            dp[i+1][1] = (dp[i+1][1] + dp[i][0]) % mod
        if s[i] in ('B', '?'):
            dp[i+1][0] = (dp[i+1][0] + dp[i][0]) % mod
            dp[i+1][1] = (dp[i+1][1] + dp[i][1]) % mod
            dp[i+1][2] = (dp[i+1][2] + dp[i][2]) % mod
            dp[i+1][3] = (dp[i+1][3] + dp[i][3]) % mod
            dp[i+1][2] = (dp[i+1][2] + dp[i][1]) % mod
        if s[i] in ('C', '?'):
            dp[i+1][0] = (dp[i+1][0] + dp[i][0]) % mod
            dp[i+1][1] = (dp[i+1][1] + dp[i][1]) % mod
            dp[i+1][2] = (dp[i+1][2] + dp[i][2]) % mod
            dp[i+1][3] = (dp[i+1][3] + dp[i][3]) % mod
            dp[i+1][3] = (dp[i+1][3] + dp[i][2]) % mod

    print(dp[n][3])

if __name__ == '__main__':
    main()


Measured memory_bytes: 27632
s,t=input(),input()
start=len(s)-len(t)
flag=1
if start<0: print("UNRESTORABLE")
else:
    while start>=0:
        flag=1
        for i in range(len(t)):
            if s[start+i]!="?" and s[start+i]!=t[i]:
                flag=0
                break
        if flag:
            s=s[0:start]+t[:]+s[start+len(t):len(s)]
            s=s.replace("?","a")
            break
        start-=1
    if flag: print(s)
    else: print("UNRESTORABLE")

Measured memory_bytes: 9044
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
    string s_str;
    string t_str;
    
    bool is_match = false;
    
    cin >> s_str;
    cin >> t_str;
    
    for(int i = 0; i < s_str.size(); i++)
    {
        if(s_str == t_str)
        {
            is_match = true;
            break;
        }
        s_str = s_str.back() + s_str.substr(0, s_str.size() - 1);
    }
    
    if(is_match)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
N = input()
P = []
for i in xrange(N):
	P.append(input())
Q = {}
for i in xrange(N):
	Q[P[i]-1]=i
longest_length = 0
length_of_sequence = 1
for i in xrange(N-1):
	if Q[i+1] > Q[i]:
		length_of_sequence += 1
	else:
		longest_length = max(longest_length, length_of_sequence)
		length_of_sequence = 1
longest_length = max(longest_length, length_of_sequence)
print N - longest_length


Measured memory_bytes: 35768
#include<iostream>
#include<stdio.h>
#include<vector>//s1.erase(n)=文字列s1の、n文字目以降削除
#include<algorithm>//辞書順=next_permutation
#include<set>
#include<string>//char 小文字のほうが32大きい
#include<sstream>
#include<string.h>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap=数値交換
#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//標準=昇順
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define llcncn llint cnt=0
#define llasas llint ans=0
#define str string
#define please return
#define AC 0
#define ic_a int a;cin>>a;
#define ic_b int b;cin>>b;
#define ic_s string s;cin>>s;
#define Rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define Pi 3.1415926535897932384626
#define nine 1000000000

using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
typedef long double ld;
const ld eps = 1.0e-10; // 許容される誤差
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int keta(int n) {
	int sum = 0;
	while (n != 0) {
		sum += n % 10; n /= 10;
	}
	return sum;//Nanashi,tRue,wai
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */
ld mysqrtl(ld x)
{
	ld a = sqrtl((double)x); // 近似値
	do {
		a = (a + x / a) / 2.0L;
	} while (fabsl(x - a * a) > eps);
	return a;
}
//平方根を求める。sqrtより精度が高い。
//epsを変えて誤差を調整する。
int main(void) {
	Rapid_pleaseAC_fast;
	llint ans=0, n=0,x,y,z;
	llint na=0, nb=0;
	bool check = false;
	vector<llint> p,q,r;
	cin >> x >>y>>z;
	
	cout << z<<" "<<x<<" "<<y << endl;
	please AC;
}


Measured memory_bytes: 256
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

N = int(input())

x = []
for i in range(N):
    x.append(list(map(int, input().split())))

p = [i for i in range(N)]
pp = list(itertools.permutations(p))

ans = 0
for ppp in pp:
    for i in range(1,N):
        ans += math.sqrt((x[ppp[i-1]][0]-x[ppp[i]][0])**2 + (x[ppp[i-1]][1]-x[ppp[i]][1])**2)

print(ans / math.factorial(N))

Measured memory_bytes: 85196
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t a;
  cin >> a;
  cout << (a + a * a + a * a * a) << endl;
  return 0;
}


Measured memory_bytes: 3648
#include <cstdio>
#include <algorithm>

using namespace std;

int main(void)
{
	int n;
	int max, min, box[8];
	int i, j;
	
	while (scanf("%d", &n) != EOF){
		for (i = 0; i < n; i++){
			scanf("%d", &max);
			for (j = 0; j < 8; j++){
				box[j] = max % 10;
				max /= 10;
			}
			
			sort(box, box + 8);
			
			max = min = 0;
			for (j = 0; j < 8; j++){
				min *= 10;
				max *= 10;
				min += box[j];
				max += box[7 - j];
			}
			
			printf("%d\n", max - min);
		}
	}
	return (0);
}

Measured memory_bytes: 1040
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>

using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<int> a(N);
	for (auto &x : a) cin >> x;

	unordered_map<int, int> h;

	for (auto x : a) {
		for (int d = -1; d <= +1; ++d) {
			++h[x + d];
		}
	}

	int ans = 0;
	for (const auto &e : h) {
		ans = max(ans, e.second);
	}

	cout << ans << endl;
}


Measured memory_bytes: 4644
//This program is written by Brian Peng.
#pragma GCC optimize("Ofast","inline","no-stack-protector")
#include<bits/stdc++.h>
using namespace std;
#define Rd(a) (a=read())
#define Gc(a) (a=getchar())
#define Pc(a) putchar(a)
int read(){
	int x;char c(getchar());bool k;
	while(!isdigit(c)&&c^'-')if(Gc(c)==EOF)exit(0);
	if(c^'-')k=1,x=c&15;else k=x=0;
	while(isdigit(Gc(c)))x=(x<<1)+(x<<3)+(c&15);
	return k?x:-x;
}
void wr(int a){
	if(a<0)Pc('-'),a=-a;
	if(a<=9)Pc(a|'0');
	else wr(a/10),Pc((a%10)|'0');
}
signed const INF(0x3f3f3f3f),NINF(0xc3c3c3c3);
long long const LINF(0x3f3f3f3f3f3f3f3fLL),LNINF(0xc3c3c3c3c3c3c3c3LL);
#define Ps Pc(' ')
#define Pe Pc('\n')
#define Frn0(i,a,b) for(int i(a);i<(b);++i)
#define Frn1(i,a,b) for(int i(a);i<=(b);++i)
#define Frn_(i,a,b) for(int i(a);i>=(b);--i)
#define Mst(a,b) memset(a,b,sizeof(a))
#define File(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
string s;
int q,f;
char c;
bool r;
signed main(){
	cin>>s,Rd(q);
	list<char>l(s.begin(),s.end());
	while(q--){
		if(read()==1)r^=1;
		else{
			f=read()-1,cin>>c;
			f^r?l.push_back(c):l.push_front(c);
		}
	}
	if(r)reverse(l.begin(),l.end());
	for(char i:l)Pc(i);
	exit(0);
}


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

int main() {
  
  vector<int> vec(9);
  for (int i = 0; i<9; i++) {
    cin >> vec.at(i);
  }
  
  int N;
  cin >> N;
  vector<int> num(N);
  for (int i = 0; i<N; i++) {
    cin >> num.at(i);
  }
  vector<int> check(9);
  check = {1, 1, 1, 1, 1, 1, 1, 1, 1};
    
  for (int j =0; j<9; j++) {
    for (int i =0; i<N; i++) {
      if (vec.at(j)/num.at(i) == 1 && vec.at(j)%num.at(i) == 0){
        check.at(j) -= 1;
        break;
      }
    }
  }
  if (check.at(0) == 0 && check.at(1) == 0 && check.at(2) == 0){
    cout << "Yes" <<endl;
    return 0;
  }
  else if (check.at(3) == 0 && check.at(4) == 0 && check.at(5) == 0){
    cout << "Yes" <<endl;
    return 0;
  }
  else if (check.at(6) == 0 && check.at(7) == 0 && check.at(8) == 0){
    cout << "Yes" <<endl;
    return 0;
  }
  else if (check.at(0) == 0 && check.at(3) == 0 && check.at(6) == 0){
    cout << "Yes" <<endl;
    return 0;
  }
  if (check.at(1) == 0 && check.at(4) == 0 && check.at(7) == 0){
    cout << "Yes" <<endl;
    return 0;
  }
  else if (check.at(2) == 0 && check.at(5) == 0 && check.at(8) == 0){
    cout << "Yes" <<endl;
    return 0;
  }
  else if (check.at(0) == 0 && check.at(4) == 0 && check.at(8) == 0){
    cout << "Yes" <<endl;
    return 0;
  }
  else if (check.at(2) == 0 && check.at(4) == 0 && check.at(6) == 0){
    cout << "Yes" <<endl;
    return 0;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    // Your code here!
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    if(s[k-1] >= 'a' && s[k-1] <= 'z'){
        s[k-1] = toupper(s[k-1]);
    }else{
        s[k-1] = tolower(s[k-1]);
    }
    cout << s << endl;
    
}


Measured memory_bytes: 256
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

struct Data {
    int d, s;
    Data(int d = 0, int s = 0) : d(d), s(s) {}
};

bool operator< (Data a, Data b) {
    if (a.d == b.d) return a.s > b.s;
    return a.d < b.d;
}

int n;
string s;
vector<Data> a, b;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    int e = 0;
    FOR(i,1,n) {
        cin >> s;
        int deep = 0, sum = 0;
        FOR(j,0,SZ(s)-1) {
            if (s[j] == '(') sum++;
            else sum--;
            deep = min(deep, sum);
        }
        if (sum >= 0) a.push_back(Data(-deep, sum));
        else b.push_back(Data(sum-deep, -sum));
        e += sum;
    }
    if (e) {
        cout << "No";
        return 0;
    }
    sort(ALL(a));
    int sum = 0;
    for (Data x : a) {
        if (abs(x.d) > sum) {
            cout << "No";
            return 0;
        }
        sum += x.s;
    }
    sort(ALL(b));
    sum = 0;
    for (Data x : b) {
        if (abs(x.d) > sum) {
            cout << "No";
            return 0;
        }
        sum += x.s;
    }
    cout << "Yes";
    return 0;
}


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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define ll long long
#define all(x) x.begin(), x.end()
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 2010
#define inf 1e14
#define MOD 1000000007

bool ispal(ll x)
{

    string ss;
    while(1)
    {

        if(x==0) break;
        char c = '0'+(x%10);
        x/=10;
        ss.pb(c);
    }
    string kk = ss;
    reverse(all(ss));
    return (ss==kk);
}

int main()

{

    ll n, m;
    cin >> n >> m;
    if(n==2 || m==2)
    {

        cout << 0;
    }
    else if(n==1 || m==1)
    {
        if(n==1&&m==1) cout << 1;
        else cout << max(n,m)-2;
    }
    else cout << (n*m)-(n*2)-(m*2)+4;
}


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

void solve(void)
{
    ll a, b;
    cin >> a >> b;
    string ans;
    if (a > 0)
    {
        ans = "Positive";
    }
    else if (a < 0 && b > 0)
        ans = "Zero";
    else
    {
        if (b > 0)
        {
            if (abs(a) % 2 == 1)
                ans = "Positive";
            else
                ans = "Negative";
        }
        else
        {
            if (abs(a - b) % 2 == 1)
                ans = "Positive";
            else
                ans = "Negative";
        }
    }
    cout << ans << endl;
}
int main(void)
{
    solve();
}

Measured memory_bytes: 3540
#!/usr/bin/env python3
import sys

def factoring(n: int):
    factors = []
    p = 1
    while p * p <= n:
        if n % p == 0:
            factors.append(p)
            if n != p * p:
                factors.append(n // p)
        p += 1
    return factors

def solve(N: int, M: int):
    if N == 1:
        print(M)
        return
    F = factoring(M)
    F.sort()
    for f in F:
        if f >= N:
            print(M // f)
            break
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    solve(N, M)

if __name__ == '__main__':
    main()


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

int main() {
	int64_t a,b,n;
	cin >> a >> b >> n;
	if(n >= b-1){
		cout << a*(b-1)/b << endl;
	}
	else{
		cout << a*n/b << endl;
	}
}


Measured memory_bytes: 3636
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

killed = 0
remain = 0
b.insert(0, 0)
for monstar, hero in zip(a[::-1], b[::-1]):
    if monstar <= remain:
        killed += monstar
        monstar = 0
    else:
        killed += remain
        monstar -= remain

    if monstar <= hero:
        killed += monstar
        remain = hero - monstar
    else:
        killed += hero
        remain = 0

print(killed)


Measured memory_bytes: 18596
NUM = int(input())

#print(NUM)


A = list(map(int,input().split()))
#print(A)


COUNT = 0
for i in range(NUM):
    PRECOUNT = 0
    
    for j in range(NUM-i):
        if A[NUM - i - 1] >= A[j]:
            PRECOUNT += 1
   
    if PRECOUNT == NUM-i:
        COUNT += 1
print(COUNT)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define endl "\n"
using namespace std;

string s;
char ope[3];
int main() {
	cin >> s;

	rep(bit, 0, 1 << 3){
		int sum = s[0] - '0';
		rep(i, 0, 3){
			int tmp = s[i+1] - '0';
			if(bit >> i & 1) sum += tmp;
			else sum -= tmp;
		}

		if(sum == 7) {
			rep(i, 0, 3) ope[i] = (bit >> i & 1) ? '+' : '-';
			break;
		}
	}

	rep(i, 0, 3) cout << s[i] << ope[i];
	cout << s[3] << "=7" << endl;

    return 0;
}


Measured memory_bytes: 3104
#include <iostream>

int main()
{
  int a, b, c;
  std::cin >> a >> b >> c;

  int ans = 0;
  while (true) {
    if (c <= 0) {
      break;
    }
    c -= a;
    ans += 1;
    if (ans % 7 == 0) {
      c -= b;
    }
  }

  std::cout << ans << std::endl;

  return (0);
}


Measured memory_bytes: 3100
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(intl i=0;i<(intl)(n);i++)
#define Rep1(i,n) for(intl i=1;i<(intl)(n)+1;i++)
#define vec vector
#define fi first
#define se second
#define pub push_back
#define pob pop_back
#define SortA(v) sort(v.begin(), v.end())
#define SortD(v) sort(v.rbegin(), v.rend())
#define All(a) (a).begin(),(a).end()
using intl = int64_t;
using vi = vec<intl>;
using vvi = vec<vi>;
using pi = pair<intl,intl>;
using vpi = vec<pi>;
vec<intl> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<intl> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr intl INF = 9223372036854775807;


int main(){
  int H,W,N;
  cin >>H>>W>>N;
  intl use = max(H,W);
  cout << N/use + ((N%use)?1:0) ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 2 * (1e5 + 5), INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
string S;
vi va, vb;

void input() {
  ;
  ;
  cin >> N;
  va.resize(N);

  rep(i, 0, N - 1) { cin >> va[i]; }
}
void solve() {
  int now = 1;
  for (auto ss : va) {
    if (ss == now) {
      now++;
    }
  }

  int ans = N - now + 1;
  if (ans == N) {
    cout << -1 << endl;
    return;
  } else {
    cout << N - now + 1 << endl;
  }

  ;
}
signed main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 1792
N, K = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
C = [[0]*2 for i in range(40)]
for i in range(40):
  cc = 0
  for a in A:
    if a & (2**(39-i)):
      cc += 1
  C[i][0] = cc * 2**(39-i)
  C[i][1] = (N-cc) * 2**(39-i)
INF = float("inf")
dp = [[-INF]*2 for i in range(41)]
dp[0][0] = 0
for i in range(40):
  d = (K>>(39-i))&1
  dp[i+1][0] = dp[i][0] + C[i][d]
  dp[i+1][1] = dp[i][1] + max(C[i])
  if d == 1:
    dp[i+1][1] = max(dp[i][0] + C[i][0], dp[i+1][1])
print(max(dp[40]))

Measured memory_bytes: 14840