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

using namespace std;
#define int long long
#define x first
#define y second
#define tm (tl + tr) / 2
#define Point pair<int, int>
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int inf = 1e15;
const int mod = (1e9) + 7;

mt19937 random1(16783849);
int randlr(int l, int r) {
    return random1() % (r - l + 1) + l;
}

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

    int n;
    string s;
    cin >> n >> s;

    vector<int> pref(n + 1);
    vector<int> suff(n + 1);

    for (int i = 0; i < n; i ++) {
        pref[i + 1] = pref[i] + (s[i] == '#');
    }

    for (int i = n - 1; i > -1; i--) {
        suff[i] = suff[i + 1] + (s[i] == '#');
    }

    int answ = inf;
    for (int i = 0; i <= n; i ++) {
        answ = min(answ, pref[i] + (n - i - suff[i]));
    }

    cout << answ;

    return 0;
}


Measured memory_bytes: 4244
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n,m;
    cin >> n >> m;
    pii p[n];
    rep(i,n){
        intl a,b;
        cin >> a >> b;
        p[i] = mp(a,b);
    }
    sort(p,p + n);
    rep(i,n){
        if(p[i].second <= m){
            cout << p[i].first << endl;
            return 0;
        }
    }
    cout << "TLE" << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))

cnt_m, cnt_z = 0, 0

for a in A:
    if a < 0:
        cnt_m += 1
    elif a == 0:
        cnt_z += 1

B = list(map(abs, A))

if cnt_m % 2 == 0 or cnt_z > 0:
    print(sum(B))
else:
    print(sum(B) - min(B)*2)


Measured memory_bytes: 14412
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

X = rl()

for i, x in enumerate(X):
	if i+1 != x:
		print(i+1)
		exit()


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

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

using namespace std;

int main() {
    int N;
    cin >> N;
    multiset<int> s;
    REP(_, 1 << N) {
        int S;
        cin >> S;
        s.insert(-S);
    }

    vector<int> a;

    auto it = s.begin();
    a.push_back(*it);
    s.erase(it);

    REP(k, N) {
        REP(i, 1 << k) {
            auto it = s.upper_bound(a[i]);
            if (it == s.end()) {
                cout << "No" << endl;
                return 0;
            } else {
                a.push_back(*it);
                s.erase(it);
            }
        }
        sort(all(a));
    }
    cout << "Yes" << endl;

    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define FORI(i,v) for (auto i = v.begin(); i != v.end(); i++)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)
#define YES(b) cout << ((b) ? "YES" : "NO") << endl
#define Yes(b) cout << ((b) ? "Yes" : "No") << endl

ll N;

string solve() {
    string ret;
    while (N) {
        ret += 'a' + (N-1)%26;
        N = (N-1)/26;
    }
    reverse(ALL(ret));
    return ret;
}

int main() {
    cout << fixed << setprecision(15);
    cin >> N;
    cout << solve() << endl;
}

Measured memory_bytes: 3652
def main():
    a,b=map(int,input().split())
    def cal(x):
        if x%2==0:
            return ((x+1)//2)%2^x
        else:
            return ((x+1)//2)%2
    
    print(cal(a-1)^cal(b))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <cstring> 
#include <malloc.h> 
#include <iostream> 
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <cstdio>
using namespace std;

int main(){
	float r,g;
	cin>>r>>g;
	cout<<g * 2 - r<<endl;
	return 0;
}

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

int partition(vector<int> &A, int p, int r) {
  int x = A[r];
  int i = p - 1;
  for (int j = p; j < r; j++) {
    if (A[j] <= x) {
      i++;
      swap(A[i], A[j]);
    }
  }
  swap(A[i+1], A[r]);
  return i + 1;
}

int main() {
  int n;
  cin >> n;
  vector<int> A(n);
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  int pivot = partition(A, 0, n - 1);
  for (int i = 0; i < n; i++) {
    if (i) {
      cout << " ";
    }
    if (i == pivot) {
      cout << "[" << A[i] << "]";
    }
    else {
      cout << A[i];
    }
  }
  cout << endl;
}


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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

ll x, y;

int main() {
	cin >> x >> y;
	if (x % y == 0) {
		puts("-1");
	} else {
		cout << x << endl;
	}
	return 0;
}

Measured memory_bytes: 256
S = input()
flag = 0
for i in range(1,len(S)+1):
    if i%2 == 1:
        if S[i-1] in 'RUD':
            continue
        else:
            flag =1
            print("No")
            break
    else:
        if S[i-1] in 'LUD':
            continue
        else:
            flag = 1
            print("No")
            break
if flag == 0:
    print("Yes")

Measured memory_bytes: 61920
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <queue>
#include <deque>
#include <vector>

auto main() -> int {
  std::uint64_t N, M;
  std::cin >> N >> M;

  using value_type = std::pair<std::uint64_t, std::uint64_t>;
  auto cmp = [](const auto& a, const auto& b) { return a.first > b.first; };
  std::priority_queue<value_type, std::vector<value_type>, decltype(cmp)> q(cmp);

  for (auto i = 0ul; i < N; ++i) {
    std::uint64_t Ai, Bi;
    std::cin >> Ai >> Bi;
    q.emplace(Ai, Bi);
  }

  std::uint64_t rem = M;
  std::uint64_t total = 0;
  while (rem != 0 || !q.empty()) {
    const auto v = q.top();
    q.pop();

    const auto n = std::min(v.second, rem);

    total += v.first * n;
    rem -= n;
  }

  std::cout << total << std::endl;
}


Measured memory_bytes: 3444
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num,init) vector<ll> name((num),(init));
#define op(i) cout<<(i)<<endl;
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define mat(name,fnum,snum,init); vector<vector<ll>> name((fnum),vector<ll>((snum),(init)));

int main(){
    ll x,y;
    cin>>x>>y;
    ll cnt=1;
    while(1){
        if(x*2<=y){
            cnt++;
            x*=2;
        }else break;
    }
    op(cnt);
    return 0;

}

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

int main() {
  char S;
  cin >> S;
  if(S=='a'||S=='i'||S=='u'||S=='e'||S=='o'){
    cout << "vowel" << endl;
  }else{
    cout << "consonant" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005


int main() {
    int n;
    cin >> n;
    int p[n];
    int q[n];
    rep(i,n)cin >> p[i];
    rep(i,n)cin >> q[i];
    int x[n];
    rep(i,n)x[i] = i + 1;
    int a, b;
    int cnt = 0;
    do{
        cnt++;
        int flag = 1;
        rep(i,n)if(p[i] != x[i])flag = 0;
        if(flag) a = cnt;
        flag = 1;
        rep(i,n)if(q[i] != x[i])flag = 0;
        if(flag) b = cnt;
    }while(next_permutation(x,x+n));
    cout << abs(a - b) << endl;
}
 
 


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <sstream>

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

int main() {
    ll N=0;
    string atai;

    cin >> atai;

    for(int i = 0; i < (int)atai.size(); ++i){
        N += (int)atai[i]-48;
    }


    
    if(N%9 == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;    
    }

    return 0;

}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define rep(i,s,e) for (int64_t i=s; i<e; i++)
#define pi 3.14159265358979323846264338327950L
using namespace std;

int main() {
  int64_t N, ans;
  cin >> N;
  vector<int64_t> x(N);
  vector<int64_t> y(N);
  vector<int64_t> a(N);
  vector<int64_t> b(N);
  rep(i,0,N) {
    cin >> x[i] >> y[i];
    a[i]=x[i]+y[i];
    b[i]=x[i]-y[i];
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  ans=max((a[N-1]-a[0]),(b[N-1]-b[0]));
  cout << ans << endl;
}

Measured memory_bytes: 9596
import sys
import copy

N,M = map(int, input().split())

V = []
E = []
seen = [False]*N
count = 0

for _ in range(N):
    V.append(set())

for _ in range(M):
    *l, = map(int, input().split())
    V[l[0]-1].add(l[1]-1)
    V[l[1]-1].add(l[0]-1)
    E.append([l[0]-1,l[1]-1])

V_copy = copy.deepcopy(V)
seen_copy = copy.deepcopy(seen)

def dfs(node):
    if seen[node]==True:
        return
    seen[node]=True

    for next_node in V[node]:
        dfs(next_node)

for i in range(len(E)):
    V[E[i][1]].remove(E[i][0])
    V[E[i][0]].remove(E[i][1])
    dfs(0)

    if (False in seen)==True:
        count = count + 1
    seen = copy.deepcopy(seen_copy)
    V = copy.deepcopy(V_copy)

print(count)

Measured memory_bytes: 3572
import java.util.Scanner;

public class Main {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int predict = m / n;
        int max = 1;
        for (int i = predict; i > 0; i--) {
            if (m % i == 0 && m / i >= n) {
                max = i;
                break;
            }
        }

        System.out.println(max);
    }
}

Measured memory_bytes: 23764
/**
 *   author: Shubham Srivastava
 *   created: 11 January 2020  16:28:00
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define MOD 1000000007
#define INF 0x7fffffff
#define sorti(v) sort(v.begin(),v.end())
#define sortd(v) sort(v.rbegin(),v.rend())
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll n;cin>>n;
    vector <pair<string,ll> > v;
    for(int i=0;i<n;i++){
    	string s;cin>>s;
    	ll a;cin>>a;
    	v.push_back({s,a});
    }
    string p;cin>>p;
    bool flag = 0;
    ll ans = 0;
    for(int i=0;i<n;i++){
    	if(flag)
    		ans += v[i].second;
    	if(v[i].first == p)
    		flag = 1;
    }
    cout<<ans;
return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define LL long long int
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define cls(s,v) memset(s,v,sizeof(s))
#define mp(a,b) make_pair<int,int>(a,b)
#define cp pair<int,int>
using namespace std;
const int maxn = 100005,maxm = 100005,INF = 0x3f3f3f3f;
inline int read(){
	int out = 0,flag = 1; char c = getchar();
	while (c < 48 || c > 57){if (c == '-') flag = 0; c = getchar();}
	while (c >= 48 && c <= 57){out = (out << 1) + (out << 3) + c - 48; c = getchar();}
	return flag ? out : -out;
}
int main(){
	int n = read(),d = read(),ans = 0;
	double x,y;
	while (n--){
		x = read(); y = read();
		if (sqrt(x * x + y * y) <= d) ans++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3620
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def Yes(): print("Yes"); return
def No(): print("No"); return

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def Base_10_to_n(X, n):
  if X//n:
    return Base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def Base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N = inputI()
a = inputIL()

print(max(a)-min(a))

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

using namespace std;
long long x[10000010], y[10000010];
#define rep(i, n) for (int i = 0; i < (n); i++)
#define lep(j, n) for (int j = 0; j < (n); j++)
#define reps(i, n) for (int i = 1; i < (n); i++)
#define leps(i, n) for (int j = 1; j < (n); j++)
#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>
#define int long long
#define gsort(x, n) sort((x), (x) + (n), greater<int>());
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10);
const long long mod = 1e9 + 7;

signed main()
{

   cin.tie(0);
   ios::sync_with_stdio(false);

   string s;
   cin>>s;
   int a=0;

   rep(i,s.size()){
      if(s[i]=='2') a++;
   }
   cout<<a<<'\n';
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int AN, BN;
    cin >> AN >> BN;
    string s;
    for(int i = 0; i < AN; i++){
        
        cin >> s;
        
        cout << s << endl;
        cout << s << endl;
    }
}


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

int main() {
    ll a;
    string b, ib;
    cin >> a >> b;

    for (int i = 0; i < b.size(); i++)
    {
        if (b[i] != '.') ib.push_back(b[i]);
    }
    
    ll ans = a * stoi(ib) / 100;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3544
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define all(a) (a).begin(),(a).end()
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=10000000000000000;

int main() {
    int m,k;
    cin >> m >> k;
    if (m==0) {
        if (k==0) cout << 0 << " " << 0 << endl;
        else cout << -1 << endl;
        return 0;
    }
    if (m==1){
        if (k==0) cout << "0 0 1 1" << endl;
        else cout << -1 << endl;
        return 0;
    }
    int u=pow(2,m);
    if (u<=k) {cout << -1 << endl;return 0;}
    cout << k << " ";
    rep(i,u){
        if (i==k) continue;
        cout << i << " ";
    }
    cout << k << " ";
    rep(i,u){
        if (u-i-1==k) continue;
        cout << u-i-1 << " ";
    }
    cout << endl;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>

int main()
{
    int n;
    int a[100000];
    scanf("%d", &n);
    long long int sum = 0;
    int min = 1000000001;
    bool b = true;
    for (int i = 0; i < n; i++)
    {
        scanf("%d", a + i);
        int tmp = abs(a[i]);
        sum += tmp;
        if (tmp < min)
        {
            min = tmp;
        }
        if (a[i] < 0)
        {
            b = !b;
        }
    }

    if (b)
    {
        printf("%lld\n", sum);
    }
    else
    {
        printf("%lld\n", sum - 2 * min);
    }

    return 0;
}

Measured memory_bytes: 512
my $n := get;
my ($a, $b) := get.split(' ');
my @problems = get.split(' ');
my @a = @problems.grep({ $_ <= $a });
my @b = @problems.grep({ $_ >= $a + 1 && $_ <= $b });
my @c = @problems.grep({ $_ >= $b + 1 });
say [ @a.elems, @b.elems, @c.elems ].min;


Measured memory_bytes: 67476
#include <iostream>
#include <cstdlib>
#include <string>
#include <algorithm>

using namespace std;

int main() {
    int N;
    cin >> N;
    while(N--) {
        string str;
        cin >> str;
        sort(str.begin(), str.end());
        int min = atoi(str.c_str());
        reverse(str.begin(), str.end());
        int max = atoi(str.c_str());
        cout << max-min << endl;
    }
    return 0;
}

Measured memory_bytes: 0
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
	"time"
)

func main() {
	now := time.Now()
	var n int
	fmt.Scanf("%d", &n)
	s := bufio.NewScanner(os.Stdin)
	xs := make([][]int, n+1)
	for i := 1; i <= n; i++ {
		s.Scan()
		xs[i] = readInts(s.Text())
	}
	var m int
	for {
		var matches int
		done := make([]bool, n+1)
		for i := 1; i <= n; i++ {
			if done[i] || len(xs[i]) == 0 {
				continue
			}
			if m := xs[i][0]; xs[m][0] == i && !done[m] {
				done[m] = true
				done[i] = true
				xs[i] = xs[i][1:]
				xs[m] = xs[m][1:]
				matches++
			}
		}
		if matches == 0 {
			break
		}
		m++
		if time.Now().Sub(now) > time.Duration(1900)*time.Millisecond {
			fmt.Printf("%d\n", n*(n-1)/2)
			return
		}
	}
	for i := 1; i <= n; i++ {
		if len(xs[i]) > 0 {
			fmt.Printf("-1\n")
			return
		}
	}
	fmt.Printf("%d\n", m)
}

func readInts(s string) []int {
	xs := strings.Fields(s)
	ys := make([]int, len(xs))
	for i, x := range xs {
		ys[i], _ = strconv.Atoi(x)
	}
	return ys
}


Measured memory_bytes: 17280
#include<stdio.h>
void swap(int *xp, int *yp)  
{  
    int temp = *xp;  
    *xp = *yp;  
    *yp = temp;  
}  
  
// A function to implement bubble sort  
void bubbleSort(int arr[], int n)  
{  
    int i, j;  
    for (i = 0; i < n-1; i++)      
    {
    // Last i elements are already in place  
    for (j = 0; j < n-i-1; j++)  
    {
        if (arr[j] > arr[j+1])  
            swap(&arr[j], &arr[j+1]);  
    }
    } 
}
int main()
{
  int n,k;
  int a[1000];
  long int sum=0;
  scanf("%d %d",&n,&k);
  for(int i=0;i<n;i++)
    scanf("%d",&a[i]);
  bubbleSort(a,n);
  for(int i=0;i<k;i++)
    sum+=a[i];
  printf("%ld",sum);
  return 0;
}


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

#define int long long
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template<typename T, typename U> inline bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> inline bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
struct Init {
    Init() {
        cout << fixed << setprecision(20);
    };
} init;

int N;
int H[110000];
signed main() {
    cin >> N;
    for (int i = 0; i < N; i++) { cin >> H[i]; }
    int ans = 0, cur = 0;
    for (int i = 0; i < N - 1; i++) {
        if (H[i] >= H[i + 1]) {
            cur++;
            chmax(ans, cur);
        } else { cur = 0; }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(int argc, char const *argv[]) {
  int w,a,b;
  int move=0;

  scanf("%d %d %d",&w,&a,&b );

  if( a > b){
    //aがbの右側
    if((move = (a - (b + w))) < 0)move = 0;
  }else{
    //aがbの左側
    if((move = (b - (a + w))) < 0)move = 0;

  }

  printf("%d\n",move );
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<cassert>
using namespace std;
int inf = 1000000000;
int func(vector<int> a){
  bool f = true;
  for(int i=0; i<a.size(); i++){
    if( a[i] != 0 ) f = false;
  }
  if( f ) return 1;

  for(int i=1; i<=9; i++){
    if( a[i] >= 3 ){
      a[i] -= 3;
      if( func(a) == 1 ) return 1;
      a[i] += 3;
    }
  }
  for(int i=1; i<=7; i++){
    if( a[i] >= 1 && a[i+1] >= 1 && a[i+2] >= 1 ){
      a[i] -= 1; a[i+1] -= 1; a[i+2] -= 1;
      if( func(a) == 1 ) return 1;
      a[i] += 1; a[i+1] += 1; a[i+2] += 1;
    }
  }
  return 0;
}

bool check(string s, int n){
  vector<int> a(10, 0);
  for(int i=0; i<s.size(); i++){
    a[ s[i]-'0' ]++;
  }
  if( a[n] == 4 ) return false;
  a[n]++;
  for(int i=1; i<=9; i++){
    if( a[i] >= 2 ){
      a[i] -= 2;
      if(func(a) == 1) return true;
      a[i] += 2;
    }
  }
  return false;
}



int main(void) {

  string s;
  while(cin >> s){
    vector<int> ans;
    for(int i=1; i<=9; i++){
      if( check(s, i) ) ans.push_back(i);
    }

    if( ans.size() == 0 ) cout << 0 << endl;
    else{
      for(int i=0; i<ans.size()-1; i++) cout << ans[i] << " ";
      cout << ans[ans.size()-1] << endl;      
    }

  }


  return 0;
}


// EOF

Measured memory_bytes: 3168
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int n   = Integer.parseInt(scanner.nextLine());
		String[] tmp = scanner.nextLine().split(" ");
		char[] s = tmp[0].toCharArray();
		char[] t = tmp[1].toCharArray();
		StringBuilder sb = new StringBuilder();

		for (int i = 0; i < n; i++){

			sb.append(s[i]);
			sb.append(t[i]);

		}

		System.out.println(sb.toString());
	}
}

Measured memory_bytes: 23380
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, INF = 1e9;
int mask[N];
char s[N];
unordered_map<int, int> dp;
int &f(int x) {
	if (!dp.count(x)) dp[x] = INF;
	return dp[x];
}
int main() {
	scanf("%s", s);
	int n = (int) strlen(s);
	int ma = 0;
	for (int i = 0; i < n; ++ i) {
		ma ^= (1 << (s[i] - 'a'));
		mask[i] = ma;
	}
	f(0) = 0;
	int las = n;
	for (int i = 0; i < n; ++ i) {
		int ma = mask[i], dp = i + 1;
		dp = min(dp, f(ma) + 1);
		for (int j = 0; j < 26; ++ j) {
			int ma = mask[i] ^ (1 << j);
			dp = min(dp, f(ma) + 1);
		}
		las = dp;
		f(ma) = min(f(ma), dp);
	}
	printf("%d\n", las);
}


Measured memory_bytes: 171096
N, M = map(int, input().split())
A = []
for i in range(M):
    L, R = map(int, input().split())
    if i == 0:
        Lmax = L
        Rmin = R
    else:
        Lmax = max(L, Lmax)
        Rmin = min(R, Rmin)

# L = set(A[0])
# for i in range(1, M):
#     L = L & set(A[i])

if Rmin-Lmax < 0:
    print(0)
else:
    print(Rmin-Lmax+1)


Measured memory_bytes: 3060
import { readFileSync } from "fs";

const { cin, nCin, biCin } = (() => {
  const inputs = readFileSync("/dev/stdin", "utf-8").split(/[\n|\s]+/);
  let count = 0;
  const cin = () => inputs[count++];
  return { cin: cin, nCin: () => Number(cin()), biCin: () => BigInt(cin()) };
})();

const range = (n: number | bigint) => [...Array(Number(n))].map((_, i) => i);

type Color = "Black" | "White";

{
  const [H, W, K] = [nCin(), nCin(), nCin()];

  const cnt = (() => {
    const css: Color[][] = range(H).map(() =>
      cin()
        .split("")
        .map((c) => (c === "#" ? "Black" : "White") as Color)
    );

    const initialBlackCnt = css
      .map((cs) => cs.reduce((acc, c) => (c === "Black" ? acc + 1 : acc), 0))
      .reduce((acc, x) => acc + x, 0);

    const pickHFn = (n: number, picksH: [number, boolean][]): number => {
      const pickWFn = (picksH: [number, boolean][]): number => {
        const pickWFn = (n: number, picksW: [number, boolean][]): number =>
          n >= W
            ? (() => {
                const getBlackCnt = (picksH: [number, boolean][], picksW: [number, boolean][]): number =>
                  picksH
                    .filter(([, b]) => b)
                    .map(([i]) =>
                      picksW
                        .filter(([, b]) => b)
                        .map(([j]) => (css[i][j] === "Black" ? 1 : 0) as number)
                        .reduce((acc, x) => acc + x, 0)
                    )
                    .reduce((acc, x) => acc + x, 0);

                const cntH = getBlackCnt(
                  range(H).map((i) => [i, true]),
                  picksW
                );
                const cntW = getBlackCnt(
                  picksH,
                  range(W).map((j) => [j, true])
                );
                const cntHW = getBlackCnt(picksH, picksW);

                return initialBlackCnt - (cntH + cntW - cntHW);
              })() === K
              ? 1
              : 0
            : pickWFn(n + 1, picksW) +
              pickWFn(
                n + 1,
                picksW.map(([j, b]) => (j === n ? [j, true] : [j, b]))
              );

        return pickWFn(
          0,
          range(W).map((j) => [j, false] as [number, boolean])
        );
      };

      return n >= H
        ? pickWFn(picksH)
        : pickHFn(n + 1, picksH) +
            pickHFn(
              n + 1,
              picksH.map(([i, b]) => (i === n ? [i, true] : [i, b]))
            );
    };

    return pickHFn(
      0,
      range(H).map((i) => [i, false] as [number, boolean])
    );
  })();

  console.log(cnt);
}


Measured memory_bytes: 40860
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;
#define int ll

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll k; cin >> k;
    ll a,b; cin >> a >> b;
    bool ok = false;
    for(int i = a; i <= b; i++){
        if(i % k == 0)ok = true;
    }

    cout << (ok ? "OK" : "NG") << endl;
}

Measured memory_bytes: 3636
# -*- coding: utf-8 -*-

N = int(input())
H = list(map(int, input().split()))

INF = float('inf')
dp = [INF] * N

dp[0] = 0
for i in range(1, N):
    dp[i] = min(dp[i], dp[i - 1] + abs(H[i] - H[i - 1]))
    if i > 1:
        dp[i] = min(dp[i], dp[i - 2] + abs(H[i] - H[i - 2]))

print(dp[-1])


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

using namespace std;

#define ll long long
#define endl '\n'
const int N = 1e6 + 5;
ll dp[3005][3005], a[3005];
ll mod = 998244353;
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        if (fopen("BONUS.INP", "r")){
                freopen("BONUS.INP", "r", stdin);
                freopen("BONUS.OUT", "w", stdout);
        }
        ll n, s;
        cin >> n >> s;
        for (int i = 1; i <= n; i++){
                cin >> a[i];
        }
        dp[0][0] = 1;
        for (int i = 0; i < n; i++){
                for (int j = 0; j <= s; j++){
                        dp[i + 1][j] = (dp[i + 1][j] + dp[i][j] * 2) % mod;
                        if ((j + a[i + 1]) <= s){
                                dp[i + 1][j + a[i + 1]] = (dp[i + 1][j + a[i + 1]] + dp[i][j]) % mod;
                        }
                }
        }
        cout << dp[n][s];
}


Measured memory_bytes: 74088
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    cin>>s;
    long long int sum=0;
    int countB=0;
    for (int i=0;i<s.size();i++) {
        if (s[i]=='B') {
            countB++;
        } else {
            sum+=countB;
        }
    }
    cout<<sum<<endl;
}

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

struct Node{
    int key;
    struct Node *parent,*right,*left;
};

struct Node *root,*NIL;

struct Node *find(struct Node *x, int y){
    while(x!=NIL && y!=x->key){
        if(y<x->key)x=x->left;
        else x=x->right;
    }
    return x;
}

void insert(int k){
struct Node *y=NIL;
struct Node *x=root;
struct Node *z;

z=(struct Node *)malloc(sizeof(struct Node));
z->key=k;
z->left=NIL;
z->right=NIL;

while(x!=NIL){
    y=x;
    if(z->key<x->key){
        x=x->left;
    }
    else x=x->right;
}
z->parent=y;
if(y==NIL){
    root=z;
}
else{
    if(z->key<y->key){
        y->left=z;
    }
    else y->right=z;
}
}
void inorder(struct Node *u){
    if(u==NIL) return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}

void preorder(struct Node *u){
    if(u==NIL)return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}
int main(){
    int n,i,x;
    char str[10];
   scanf("%d",&n);

    for(i=0;i<n;i++){
        scanf("%s",str);
       
        if(str[0]=='i'){
            scanf("%d",&x);
            insert(x);
        }
        
        else if(str[0]=='p'){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
        else if(str[0]=='f'){
            scanf("%d",&x);
            struct Node *f=find(root,x);
            if(f!=NIL)printf("yes\n");
            else printf("no\n");
        }
    }
    return 0;
}



Measured memory_bytes: 21348
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#define RANGE_1(e) (boost::irange(0,(e)))
#define RANGE_2(s,e) (boost::irange((s),(e)))
#define RANGE_3(s,e,step) (boost::irange((s), (e), (step)))
#define RANGE_SELECTER(_1,_2,_3,SELECT,...) SELECT
#define range(...) RANGE_SELECTER(__VA_ARGS__, RANGE_3, RANGE_2, RANGE_1) (__VA_ARGS__)
#define guard(x) if(x);
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define CALL(x) (x).cbegin(),(x).cend()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define BIT(n) (1LL<<(n))

using namespace std;
using lint = long long;

// template<class T>class irange{private:struct I{T x;T operator*(){return x;}bool operator!=(I&lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;public:irange(T i,T n):i({i}),n({n}){}I&begin(){return i;}I&end(){return n;}};
// template<class T>class srange{private:struct I{T x,s;T operator*(){return x;}bool operator!=(I&lhs){if(s<(T)0)return x>lhs.x;return x<lhs.x;}void operator++(){x=x+s;}};I i,n;public:srange(T i,T n,T s):i({i,s}),n({n,s}){}I&begin(){return i;}I&end(){return n;}};
// template<class T>irange<T>range(T n){return irange(0,n);}template<class T>irange<T>range(T i,T n){return irange(i,n);}template<class T>srange<T>range(T i,T n,T s){return srange(i,n,s);}
template<class T>bool amax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool amin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}

struct initialize{initialize(){cin.tie(nullptr);ios::sync_with_stdio(false);};}__ini__;

int main(){
    /* Code Area */
    for (auto&& i : range(1, 5)) {
        int a;
        cin >> a;
        if (a != i) {
            cout << i << endl;
            return 0;
        }
    }

    cout << 5 << endl;
}


Measured memory_bytes: 3624
import numpy as np

x, y, a, b, c = map(int, input().split())

p = np.array(list(map(int, input().split())))
q = np.array(list(map(int, input().split())))
r = np.array(list(map(int, input().split())))

p.sort()
q.sort()
r.sort()

ans = p[-x:].sum()+q[-y:].sum()

p_cnt = 0
q_cnt = 0
r_cnt = 0
while not(-x+p_cnt == 0 and -y+q_cnt == 0) and -1-r_cnt >= -c:
  if -x+p_cnt == 0:
    if r[-1-r_cnt] > q[-y+q_cnt]:
      ans += r[-1-r_cnt] - q[-y+q_cnt]
      q_cnt += 1
      r_cnt += 1
    else:
      break
  
  elif -y+q_cnt == 0:
    if r[-1-r_cnt] > p[-x+p_cnt]:
      ans += r[-1-r_cnt] - p[-x+p_cnt]
      p_cnt += 1
      r_cnt += 1
    else:
      break

  elif p[-x+p_cnt] <= q[-y+q_cnt] and r[-1-r_cnt] > p[-x+p_cnt]:
    ans += r[-1-r_cnt] - p[-x+p_cnt]
    p_cnt += 1
    r_cnt += 1

  elif p[-x+p_cnt] > q[-y+q_cnt] and r[-1-r_cnt] > q[-y+q_cnt]:
    ans += r[-1-r_cnt] - q[-y+q_cnt]
    q_cnt += 1
    r_cnt += 1

  else:
    break

print(ans)

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

void reverse(char *str){
	int len = strlen(str);
	for(int i=0; i < len / 2; i++) {
		char temp = str[i];
		str[i] = str[len-1-i];
		str[len-1-i] = temp;
	}
}

int main(void){
	int len, beAble;
	char str[100001];

	unsigned char candsLen[4] = {5, 7, 5, 6};
	char cands[4][8] = {
		{"dream"},
		{"dreamer"},
		{"erase"},
		{"eraser"},
	};

	scanf("%s", str);

	reverse(str);
	for(int i=0; i < 4; i++) {
		reverse(cands[i]);
	}

	len = strlen(str);
	for(int i=0; i < len;) {
		beAble = 0;
		for(int j=0; j < 4; j++) {
			if(!strncmp(str+i, cands[j], candsLen[j])) {
				beAble = 1;
				i += candsLen[j];
				break;
			}
		}
		if(!beAble) {
			printf("NO");
			return 0;
		}
	}
	printf("YES");

	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<map>
#define F(a) for(register int (i)(0);(i)<(a);(i)++)
int n,a[100010];
std::map<int,int> m;
signed main(){scanf("%d",&n);int t,now(0),ans(0);F(n){scanf("%d",&t);if(!m[t]){a[now++]=t;}m[t]++;}F(now){(ans+=m[a[i]])-=a[i]*(m[a[i]]>=a[i]);}return printf("%d\n",ans),0;}

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

using namespace std;
using ll =long long;
constexpr int mod = 1e9+7;
constexpr int md = mod;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    string str;
    cin>>n>>str;
    int ans = 0;
    int black ,white;
    black = white = 0;
    for(int i=0;i<n;++i){
        if(str[i] == '#')black++;
        else white++;
    }
    ans = min(black,white);
    vector<int> dp(n+1);
    dp[0] = white;
    for(int i=1;i<=n;++i){
        if(str[i-1] == '#'){
            dp[i] = dp[i-1] + 1;
        }else{
            dp[i] = dp[i-1] - 1;
        }
    }
    for(int i=0;i<n;++i){
        ans = min(ans,dp[i]);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1428
n, m = map(int, input().split())
S = [list(map(int, input().split()[1:])) for i in range(m)]
P = list(map(int, input().split()))

s_cands = [[]]
for i in range(1, n+1):
  temp = []
  for cand in s_cands:
    temp.append(cand + [i])
    temp.append(cand)
  s_cands = temp

correct_pat = 0
for light_pat in s_cands:
  for i, s in enumerate(S):
    swicth_on = len(list(set(light_pat) & set(s)))
    if swicth_on % 2 != P[i]:
      break
  else:
    correct_pat += 1
print(correct_pat)
    

Measured memory_bytes: 3064
#高さは後から決まりそう、中心を決める
#x,y,nで動かす三重ループ

n=int(input())
xyh=[list(map(int,input().split())) for i in range(n)]
XYH=[i for i in xyh if i[2]!=0]
n=len(XYH)
d=[0,0]
f=0
if n==1:
    d=[XYH[0][0],XYH[0][1],XYH[0][2]]
    print(" ".join(map(str,d)))
else:
    n=len(XYH)
    d=[0,0]
    f=0
    for i in range(101):
        for j in range(101):
            l=abs(XYH[0][0]-i)+abs(XYH[0][1]-j)+XYH[0][2]
            for k in range(n):
                if l!=abs(XYH[k][0]-i)+abs(XYH[k][1]-j)+XYH[k][2]:
                    break
            else:
                f=1
                d=[i,j]

            if f==1:
                break

        if f==1:
            break

    d.append(abs(XYH[0][0]-i)+abs(XYH[0][1]-j)+XYH[0][2])
    print(" ".join(map(str,d)))


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

int main() {
    long long h, w, n; cin >> h >> w >> n; long long cnts[10]; memset(cnts, 0, sizeof(cnts)); 
    set< pair<long long,long long> > s; long long zer = 0; cnts[0] = max(zer, (h-2)*(w-2));
    for (long long i = 0; i < n; i ++){
        long long x, y; cin >> x >> y; s.insert({x,y});
        long long arr[5][5]; memset(arr, -1, sizeof(arr));
        for (long long j = -2; j <= 2; j ++) {
            for (long long k = -2; k <= 2; k ++) {
                if (x+j <= 0 || y+k <= 0 || x+j > h || y+k > w) continue;
                if (j == 0 && k == 0) {arr[j+2][k+2] = 0; continue;}
                arr[j+2][k+2] = s.count({x+j, y+k});
            }
        }
        for (long long j = 0; j <= 2; j ++) {
            for (long long k = 0; k <= 2; k ++) {
                if (arr[j][k] == -1 || arr[j+2][k] == -1 || arr[j][k+2] == -1 || arr[j+2][k+2] == -1) continue;
                long long numzers = arr[j][k] + arr[j][k+1] + arr[j][k+2] + arr[j+1][k] + arr[j+1][k+1] + arr[j+1][k+2] + arr[j+2][k] + arr[j+2][k+1] + arr[j+2][k+2];
                cnts[numzers]--; cnts[numzers+1]++;
            }
        }
    } for (long long i = 0; i < 10; i ++) cout << cnts[i] << endl;
}

Measured memory_bytes: 9880
import sys
import math
from itertools import permutations
from itertools import combinations
#input = sys.stdin.readline
sys.setrecursionlimit(10**9)

X, Y = map(int, input().split())

if (X + Y) % 3:
    print(0)
    exit()

n = (2*X - Y) // 3
m = (-X + 2*Y) // 3

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9 + 7
N = (n + m)
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

a = cmb(n+m, m, mod)

print(a)


Measured memory_bytes: 118764
def divisors(n):
    d=[]
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            d.append(i)
            if i!=n//i:
                d.append(n//i)
    d.sort()
    return d

n = int(input())
li = divisors(n)
if len(li) % 2 == 0:
    a,b = li[len(li)//2-1],li[len(li)//2]
    print(a-1+b-1)
else:
    a = li[len(li)//2]
    print(2*a-2)

Measured memory_bytes: 3264
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putln(x) cout << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

void solve(void){

	int H, W;
	cin >> H >> W;

	vector <string> maze(H);

	rep(H, i) cin >> maze[i];

	rep(H, i) {
		rep(W, j) {

			if (maze[i][j] == '#')
			{
				put('#');
				continue;
			}

			int cnt = 0;

			rep(9, d)
			{
				int x = j + d / 3 - 1;
				int y = i + d % 3 - 1;

				if (0 <= x && x < W && 0 <= y && y < H)
				{

					cnt += maze[y][x] == '#';

				}


			}

			put(cnt);

		}

		put('\n');

	}

}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var l = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = l[0], W = l[1];

            var dp = new long[N + 1, W + 1];
            for (var i = 0; i < N; i++)
            {
                var wv = Console.ReadLine().Split().Select(int.Parse).ToArray();
                for (var j = 0; j <= W; j++)
                {
                    if (j - wv[0] >= 0)
                    {
                        dp[i + 1, j] = Math.Max(dp[i, j - 1], dp[i, j - wv[0]] + wv[1]);
                    }
                    else
                    {
                        dp[i + 1, j] = dp[i, j];
                    }
                }
            }

            Console.WriteLine(dp[N, W]);
        }
    }
}


Measured memory_bytes: 90976
#include <bits/stdc++.h>
#ifdef dbg
#include "./printer.hpp"
#else
#define dump(x) void(0)
#endif

#define MOD 1000000007
using namespace std;
#define ll long long
inline long  toInt(string s) {long  v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

int main(){
  ll n;
  while(cin >> n && n){
    vector<ll> a(n);
    for(ll i = 0; i < n; i++){
      cin >> a[i];
    }
    vector<ll> b(n);
    b[0] = a[0];
    for(ll i = 1; i < n; i++){
      b[i] = max(b[i-1] + a[i], a[i]);
    }

    ll ans = -MOD;
    for(ll i = 0; i < n; i++){
      ans = max(ans, b[i]);
    }
    cout << ans << '\n';
    
  }

}

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


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
 
    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    set<ll> st;
    for(int i=0;i<n;i++){
        st.insert(a[i]);
    }
    if(st.size()==n){
        cout << "YES\n";
    }
    else cout << "NO\n";
}

Measured memory_bytes: 11264
//abc048_b.cpp
//Sun Oct 21 11:32:12 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	ll a,b,x;
	cin >> a >> b >> x;

	ll ans = b/x - a/x;
	if (a%x == 0){
		ans++;
	}

	cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MIN(a, b) ((a) <= (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
void search(int n,int m,char**field){
	
}
int main(){
	int n,k,ans;
	//string ans="No";
	cin >> n >> k;
	ans = n - k + 1;
	cout << ans << endl;
	//cout << maxt << endl;
}

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

int main() {
	string ans="Yay!";
	vector<int>A(5);
	for(int i=0;i<5;i++)cin>>A.at(i);
	sort(A.begin(),A.end());
	
	int K;
	cin>>K;
	
	if(A.at(4)-A.at(0)>K) ans=":(";
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lln long long int
#define llu unsigned lln
#define sc(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define scd(n) scanf("%lf",&n);
#define pf(res) printf("%d\n",res);
#define pfl(res) printf("%lld\n",res);
#define pfd(res) printf("%lf\n",res);
#define pb(n) push_back(n);
#define maxii 200005
using namespace std;
typedef pair<int,int> pii;
typedef pair<lln,lln> pll;
vector<int> vi;
vector<lln> vl;
vector<pii> vii;
vector<pll> vll;


lln arr[maxii];
lln arr2[maxii];
//bool check[maxii];
bool check2[1000][1000];
//lln n,m;

int main()
{
  string a,b;
  cin>>a;
  b=a;
  reverse(b.begin(),b.end());
  if(a==b)
  {
      printf("Yes\n");
  }
  else cout<<"No";

}






Measured memory_bytes: 3584
// first second push_back unordered return continue break vector visited check flag bool while iterator begin end lower_bound upper_bound temp true false ll_MAX ll_MIN insert erase clear pop push compare ll64_MAX ll64_MIN  reverse replace stringstream string::npos length substr front
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()
const ll mod = 1e9 + 7 ;
void add_self(ll& a , ll b){a =  (a + b)%mod;}
// #define a(x)  get<0>(x) 
// #define b(x)  get<1>(x)
//#define (x)  get<2>(x)
signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll n , w ;cin>>n>>w ; 
ll arr[n] ,brr[n];
for(ll i = 0 ; i<n ; i++)cin>>arr[i]>>brr[i] ; 

vector<ll> a(w+1) , b(w+1) ; 

for(ll i = arr[0] ; i<=w ; i++)a[i] = brr[0] ; 

for(ll i = 1 ; i<n ; i++){
for(ll j  = 1  ; j<=w ; j++ ){

	if(j-arr[i]>=0){
		b[j] = a[j];
		// b[j] =  max(a[j] ,brr[i] + a[j-arr[i]]);
		if(brr[i] + a[j-arr[i]]>a[j])
			b[j] = brr[i] + a[j-arr[i]];

	}
	else b[j] = a[j];

	

}

a= b; 
}
// for(auto i:dp){
// 	for(auto j:i)cout<<j<<" ";
// 		cout<<endl;
// }

cout<<a[w];




	
}

Measured memory_bytes: 1792