akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
using namespace std;

const int divisor = 1000000007;

int main(){
	vector<int> ansvec;

	// 100000!までの数をdivisorで割った余りを格納しておく
	long long* factmodary = new long long[100001];
	long long fact = 1;
	for (int i = 1; i <= 100000; i++){
		fact *= i;
		fact %= divisor;
		factmodary[i] = fact;
	}

	int* word = new int[100000] {0};

	for (;;){
		int N, R;
		cin >> N;
		if (N == 0) break;
		cin >> R;
		
		//まず0番目の単語を入れておく
		for (int i = 0; i < N; i++) word[i] = i + 1;

		for (int i = 0; i < R; i++){
			int s, t;
			cin >> s >> t;
			/* swap */
			int tmp = word[s - 1]; word[s - 1] = word[t - 1]; word[t - 1] = tmp;
		}

		//word[i]をkey, word[i]より小さい数がそれ以前にいくつ使われていたかをvalueとして格納するmap
		map<int, int> bubblehist;
		bubblehist[word[0]] = 0;

		long long ans = factmodary[N-1] * (word[0] - 1);

		for (int i = 1; i < N; i++){
			int facttime = word[i] - 1;
			int bubblenum;
			map<int, int>::iterator it = bubblehist.lower_bound(word[i]);

			if (it != bubblehist.end()){
				bubblenum = it->second;
			}
			else {
				bubblenum = bubblehist.rbegin()->second + 1;
			}
			pair<int, int> p;
			p.first = word[i];
			p.second = bubblenum;
			bubblehist.insert(--it, p);
			//word[i]より大きい数はすべてvalueが1増える
			for (map<int, int>::iterator it2 = bubblehist.upper_bound(word[i]); it2 != bubblehist.end(); it2++) ++(it2->second);

			facttime -= bubblenum;
			ans += factmodary[N - (i + 1)] * facttime;
			ans %= divisor;
		}
		ansvec.push_back((int)ans);
	}

	for (vector<int>::iterator it = ansvec.begin(); it != ansvec.end(); it++) cout << *it << "\n";

	delete[] word;
	delete[] factmodary;
	return 0;
}

Measured memory_bytes: 6816
#include<bits/stdc++.h>
 
using namespace std;
 
struct UnionFind {
	vector<long long> data;
	UnionFind(long long size) : data(size, -1) { }
	
	bool merge(long long x, long long y){
		x = root(x), y = root(y);
		if(x == y) return false;
		if(data[y] < data[x]) swap(x, y);
		data[x] += data[y];
		data[y] = x;
		return true;
	}
	
	long long root(long long x){
		return data[x] < 0 ? x : (data[x] = root(data[x]));
	}
	
	long long size(long long x){
		return -data[root(x)];
	}
};
 
int main(){
	long long N, M;
	cin >> N >> M;
	vector<long long> A(M), B(M);
	for(long long i = 0; i < M; ++i){
		cin >> A[i] >> B[i];
		A[i]--; B[i]--;
	}
	
	UnionFind UF(N);
	vector<long long> result(M, 0);
	result[M-1] = N * (N-1) / 2;
	for(long long i = M - 1; i > 0; --i){
		if(UF.root(A[i]) == UF.root(B[i])){
			result[i-1] = result[i];
			continue;
		}
		result[i-1] = result[i] - 1LL * UF.size(A[i]) * UF.size(B[i]);
		UF.merge(A[i], B[i]);	
	}
	for(long long i = 0; i < M; ++i){
		cout << result[i] << endl;
	}
}

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

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

  if (a % 3 == 0)
    cout << "Possible" << endl;
  else if (b % 3 == 0)
    cout << "Possible" << endl;
  else if ((a + b) % 3 == 0)
    cout << "Possible" << endl;
  else 
    cout << "Impossible" << endl;

  return 0;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int x[10], y[10];

double dist(int i, int j) {
    double dx = x[i] - x[j];
    double dy = y[i] - y[j];
    return pow(dx * dx + dy * dy, 0.5);
}

int main() {
    int N;
    cin >> N;
    rep(i, N) cin >> x[i] >> y[i];

    vector<int> v(N);
    rep(i, N) v[i] = i;
    double sum = 0;
    ll cnt = 0;
    do {
        rep(i, N - 1) sum += dist(v[i], v[i + 1]);
        cnt++;
    } while (next_permutation(v.begin(), v.end()));
    cout << fixed << setprecision(10) << sum / cnt << endl;
}


Measured memory_bytes: 256
eval"N,X,M="+`tr ' ' ,`
r=0...M
t=*r
u=r.map{_1**2%M}
s=0
60.times{|i|N[i]>0&&(s+=t[X]
X=u[X])
t=r.map{|j|t[j]+t[u[j]]}
u=r.map{|j|u[u[j]]}}
p s

Measured memory_bytes: 71216
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    a,b,c = input().split()
    if a[-1] == b[0] and b[-1] == c[0]:
        print("YES")
    else:
        print("NO")
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 38640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    int n,k;cin>>n>>k;
    if(n%k==0)cout<<0<<endl;
    else cout<<1<<endl;
}

Measured memory_bytes: 256
a,b = map(int,input().split())

def f(x):
    if x<=0:
        return [0]
    k=2
    l = []
    while True:
        mul = k>>1
        if mul>x:
            fin = mul>>1
            l[-1]=x-fin+1
            break
        fin = mul>>1
        l.append(x//k*mul+max(x%k+1-k//2,0))
        k = k<<1
    l = l[::-1]
    return l
l1 = f(b)
l2 = f(a-1)
k=1
ans=0
while not l1==[]:
    if l2==[]:
        t = l1.pop()
        if t%2==1:
            ans+=k
    else:
        t = l1.pop()-l2.pop()
        if t%2==1:
            ans+=k
    k = k<<1
print(ans)


Measured memory_bytes: 3064
fn main() {
    use std::collections::HashMap;
    let mut m: HashMap<String, i64> = HashMap::new();
    let n: i64 = read();
    let mut max: i64 = 0;
    for _ in 0i64..n {
        let s: String = read();
        let current = match m.get(&s) {
            Some(cnt) => *cnt,
            None => 0,
        };
        let added = current + 1;
        m.insert(s, added);
        if max < added {
            max = added;
        }
    }
    use std::iter::FromIterator;
    let mut vs = Vec::from_iter(&m);
    vs.sort_by(|&(a, _), &(b, _)| a.cmp(&b));
    for (s, n) in vs {
        if *n == max {
            println!("{}", s);
        }
    }
}

use std::io::stdin;
use std::io::Read;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let token: String = cin
        .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")
}


Measured memory_bytes: 23096
#include <bits/stdc++.h>
#define N 100000
#define inf 1e9+7
using namespace std;
typedef vector <int> vi;
int n;
vi iv(N,inf);

int calculation(int l, int r){
    vi cost(N,0);
    vi target(N,inf);
    target[r] = -1;
    for (int i = r - 1; i >= l; i--){
        int a = abs(iv[i] - iv[i+1]) + cost[i+1];
        int b = abs(iv[i] - iv[i+2]) + cost[i+2];
        cost[i] = (a<b)? a:b;
        target[i] = (a<b)? i+1 : i+2;
    }
    return cost[l];
}

int main(){
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> iv[i];
    }
    cout << calculation(0,n-1);
}


Measured memory_bytes: 1408
mm=1000000007

H,W= [int(x) for x in raw_input().split()]
S=["#"*(H+2)]
for i in range(H):
    S.append("#"+ raw_input() +"#")
S.append("#"*(H+2))
A=[ [0 for x in range(W+2)] for y in range(H+2)]
A[1][1]=1
for i in range(1,H+1):
    for j in range(1,W+1):
        if S[i][j]=="." and not (i==1 and j==1):
            A[i][j]= (A[i][j-1]+A[i-1][j])%mm
print(A[H][W])


Measured memory_bytes: 40348
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  replace(ALL(s), '9', '#');
  replace(ALL(s), '1', '9');
  replace(ALL(s), '#', '1');
  cout << s << '\n';
}

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

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int N, K;
    cin >> N >> K;
    vector<PII> ans;
    if (K > ((N - 1) * (N - 2)) / 2) {
        cout << "-1\n";
        return 0;
    }
    for (int i = 2; i <= N; i++) {
        ans.pb({1, i});
    }
    int cur = ((N - 1) * (N - 2)) / 2; 
    for (int i = 2; i <= N - 1; i++) {
        for (int j = i + 1; j <= N; j++) {
            if (cur <= K) {
                break;
            }
            ans.pb({i, j});
            cur--;
        }
    }

    cout << SZ(ans) << "\n";
    REP(i, SZ(ans)) {
        cout << ans[i].first << " " << ans[i].second << "\n";
    }

}

Measured memory_bytes: 384
# coding: utf-8
# Your code here!
# coding: utf-8
from fractions import gcd 
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
from inspect import currentframe


# my functions here!
#標準エラー出力
def printargs2err(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' : '+repr(arg) for arg in args),file=sys.stderr)
def debug(x):
    print(x,file=sys.stderr)
def printglobals():
    for (symbol, value) in globals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
def printlocals():
    for (symbol, value) in locals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)


#入力（後でいじる）
def pin(type=int):
    return map(type,input().split())
#どっかで最悪計算量の入力データを用意する関数を作ろう？
"""
バケットで管理したかったけど数字が多いのでソートして同じ数を固めることに
"""
#solution:
#潜 影 蛇 手 ! !
N=int(input())
A=[(i%4) for i in pin()]
#print(A)
b=[0]*4
for j in A:
    b[j-1]+=1
#print(b)

print(["No","Yes"][(b[3]-b[0]-b[2]-(b[1]%2)+1>=0)])
#print([["NA","YYMM"],["MMYY","AMBIGUOUS"]][cMMYY][cYYMM])



Measured memory_bytes: 93544
#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 factorial(int x) {
    if (x == 0) return 1;
    else if (x < 0) return 0; 
    int ans = 1;
    for (int i = 1; i <= x; ++i) {
        ans *= i;
    }
    return ans;
}

ll combination1(int m, int n) {      // mCn
    if (m < n) swap(m, n);
    ll ans = factorial(m) / (factorial(n) * factorial(m-n));
    return ans;
}

int combination2(int m, int n) {
    if (m < n) swap(m, n);
    int mom = 1; int son;
    for (int i = m; i > m-n; --i) mom *= i;
    son = factorial(n);
    int ans = mom / son;
    return ans;
}

int main() {
    int n, m;
    cin >> n >> m;
    int ans;
    ans = combination2(n+m, 2) - n*m;
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
///AJoy Sarker ,CSE JAHANGIRNAGAR UNIVERSITY 48 Batch
#include<bits/stdc++.h>
using namespace std;
#define SORT(c) sort((c).begin(),(c).end());
#define inf INT_MAX/3
#define pb push_back
#define MP make_pair
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 3.141592653589793
#define in scanf
#define out printf
#define ll long long
#define ull unsigned long long
#define w(x) int x;cin>>x;while(x--)
#define fast ios_base::sync_with_stdio(0)
#define FOR(i,a,b) for( int i=(a),_b=(b);i<=_b;i++)
#define DOW(i,b,a) for( int i=(b),_a=(a);i>=_a;i--)
#define sz size()
typedef unsigned long long UL;
template<typename T>inline T  S(T a)
{
    return a*a;
}
template<class T>inline string tostring(T a)
{
    ostringstream os("");
    os << a;
    return os.str();
}
template<typename T>inline ll tolong(T a)
{
    ll res;
    istringstream os(a);
    os>>res;
    return res;
}
template<typename T>inline T gcd(T a, T b)
{
    if (b == 0)return a;
    else return gcd(b, a % b);
}
template<typename T>inline T bigmod(T a, T b, T m)
{
    if (b == 0)return 1;
    else if (b % 2 == 0)return S(bigmod(a, b / 2, m)) % m;
    else return (a % m*bigmod(a, b - 1, m)) % m;
}
#define N 20000009
bool prime[N];
vector<ll> prm;
void seive ()
{

    memset(prime, true, sizeof(prime));

    for( ll i=2; i*i<=N; i++)
    {
        if (prime[i] == true)
        {
            prm.pb(i);
            for (ll j=i*i; j<=N; j += i)
                prime[j] = false;
        }
    }
}
void pr (int f)
{
    if(f==1)
        cout<<"YES\n";
    else
        cout<<"NO\n";
}
map<int,int>mp;
set<int> s;
int main()
{
    fast;
   int c=0;
    string s,ss;cin>>s>>ss;
    for(int i=0;i<s.sz;i++)
    {
        if(s[i]==ss[i])
            c++;
    }
    cout<<c<<endl;

}






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

int a,b,c,d;
int main() {
  cin >> a >> b >> c >> d;
  
  int left = a+b;
  int right = c+d;
  
  if (left>right) {
    cout << "Left";
  } else if (left == right) {
    cout << "Balanced";
  } else {
    cout << "Right";
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <algorithm>
#include <cassert>

using namespace std;


bool solve(){
	int a[4], b[4];
	while(cin>>a[0]){
		cin>> a[1]>> a[2]>> a[3]>> b[0]>> b[1]>> b[2]>> b[3];
		int ans1 = 0;
		int ans2 = 0;
		for(int i=0;i<4;i++){
			if(a[i] == b[i]) ans1++;
			for(int j=0;j<4;j++){
				if(a[i] == b[j]) ans2++;
			}
		}
		ans2 -= ans1;
		cout<< ans1<< " "<< ans2<< endl;
	}
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	solve();

	return 0;
}

 

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

#define ll long long int

int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    if(n == 1)
        cout<<a[0];
    else{
        int gg = __gcd(a[0],a[1]);
        for(int i=2;i<n;i++)
            gg = __gcd(gg,a[i]);
        cout<<gg;
    }
    return 0;
}


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

using namespace std;

const int N = 2e5 + 5;
const int mod = 1e9 + 7;

int n, cnt[N], dp[N], a[N];

void add (int &x, int y) {
    x += y;
    if (x >= mod) x -= mod;
}

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    dp[0] = 1;
    for (int i = 1; i <= n; i++) {
        add(dp[i], dp[i - 1]);
        if (a[i] != a[i - 1]) {
            add(dp[i], cnt[a[i]]);
            cnt[a[i]] = dp[i];
        }
    }
    
    //for (int i = 1; i <= n; i++) cout << dp[i] << " ";
    //cout << "\n";
    cout << dp[n];
    return 0;
}

Measured memory_bytes: 2560
s=input()
rx,ry=map(int,input().split())


if "T" in s:
    x=s.index("T")
else:
    x=len(s)

y=0


runx=rx-x
runy=ry-y
s=s[x:]+"T"

#print(runx,runy,s)


disx=[]
disy=[]
now=0#0がx方向
count=0
for j in range(len(s)):
    if s[j]=="T":
        if now==0:
            disx.append(count)
        else:
            disy.append(count)
        now=(now+1)%2
        count=0
    else:
        count+=1
    
disetx={0}
disety={0}

for i in disx:
    nextsetx=set()
    for j in disetx:
        nextsetx.add(j+i)
        nextsetx.add(j-i)
    disetx=nextsetx

for i in disy:
    nextsety=set()
    for j in disety:
        nextsety.add(j+i)
        nextsety.add(j-i)
    disety=nextsety

#print(disetx,disety)

if runx in disetx and runy in disety:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 3816
#define _CRT_SECURE_NO_DEPRECATE
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <bitset>
#include <cmath>
#include <ctime>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <sstream>
#include <chrono>
#include <functional>
#include <random>
#include <numeric>
#include <tuple>
#include <bitset>
using namespace std;
#define sz(v) ((int)((v).size()))
#define all(v) (v).begin(),(v).end()
typedef long long ll;
typedef pair<int, int> ii;
template<class T> string toString(T x) { ostringstream ss; ss << x; return ss.str(); }
void solve();
int main() {
#ifdef LOCAL_COMP
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);
	solve();
#ifdef LOCAL_COMP
	cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec" << endl;
#endif
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void solve() {
	vector<int> v = { 1, 4, 7, 9 };
	vector<int> a;
	for (int i = 0; i < 4; i++) {
		int x; cin >> x; a.push_back(x);
	}
	sort(all(a));
	if (a == v) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
}


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

const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
const int MOD=1000000007;


ll ppow(ll a,ll b){
	a%=MOD;
	ll res=1;
	while(b){
		if(b&1)res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res;
}

ll nCr(ll n,ll r){
	ll ans=1;
	for(ll i=1;i<=r;i++){
		(ans*=(n-i+1))%=MOD;
		(ans*=ppow(i,MOD-2))%=MOD;
	}
	return ans;
}

int main(){
	int n,a,b;cin>>n>>a>>b;
	ll U=(ppow(2,n)+MOD-1)%MOD;
	(U+=MOD-nCr(n,a))%=MOD;
	(U+=MOD-nCr(n,b))%=MOD;
	cout<<U<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    char s[3];
    int flag=0;

    scanf("%s",s);
    //printf("%s",s);

    for (int i=0;i<3;i++)
        if (s[i]=='7')
            flag=1;

    if (flag==1)
        printf("Yes\n");
    else
        printf("No\n");


    return 0;
}

Measured memory_bytes: 1644
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <numeric>


int main() {
	int n, z, w;

	std::cin >> n >> z >> w;

	std::vector<int> v(n);

	for (size_t i = 0; i < n; i++)
	{
		std::cin >> v[i];
	}

	if (n == 1) {
		std::cout << abs(v[0] - w) << std::endl;
		return 0;
	}

	std::cout << std::max(abs(v[n - 1] - w), abs(v[n - 2] - v[n - 1])) << std::endl;

	return 0;
}

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

using namespace std;

int main()
{
    int N;
    string s;

    cin >> N;
    cin >> s;

    int sum = 0;
    int minv = 0;

    for (int i = 0; i < N;i++)
    {
        sum += s[i] == '(' ? 1 : -1;
        if(minv > sum)
        {
            minv = sum;
        }
    }
    //cout << "minv = " << minv << " sum = " << sum << endl;
    int last = sum;

    string s1(max(-minv, 0), '(');
    string s2(max(last - minv, 0), ')');
    string ans = s1 + s + s2;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include<math.h>
int main(void){
    int N, K, m=pow(10,9)+7;
    long long j, i=0;

    scanf("%d%d" , &N, &K);
    for(j=K ; j<=N+1 ; j++){
        i =i+(j*(N-j+1)%m)%m+1;
        i =i%m;
    }
    printf("%lld" ,i);
    return 0;
}


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

int main()
{
	string s;
	ll x, y;
	cin >> s >> x >> y;
	bool d = true;
	vector<ll> st0, st1;
	ll tmp = 0;
	for (auto c : s) {
		if (c == 'T') {
			(d ? st0 : st1).push_back(tmp);
			d = d != true;
			tmp = 0;
		}
		else {
			tmp++;
		}
	}
	if (tmp) {
		(d ? st0 : st1).push_back(tmp);
	}
	x -= st0[0];
	st0[0] = 0;
	sort(st0.begin(), st0.end());
	sort(st1.begin(), st1.end());
	set<ll> dp0, dp1;
	dp0.insert(0), dp1.insert(0);
	for (auto t : st0) {
		auto tmp = dp0; dp0.clear();
		for (auto v : tmp) {
			dp0.insert(v + t);
			dp0.insert(abs(v - t));
		}
	}
	for (auto t : st1) {
		auto tmp = dp1; dp1.clear();
		for (auto v : tmp) {
			dp1.insert(v + t);
			dp1.insert(abs(v - t));
		}
	}
	cout << (dp0.count(abs(x)) && dp1.count(abs(y)) ? "Yes" : "No") << endl;
	return 0;
}


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

void solve(long long A, long long B){
    cout << (A + B) % 24 << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


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

using namespace std;

int main() {
	//freopen("B.in", "r", stdin);
	//freopen("B.out", "w", stdout);
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	string s;
	cin >> s;
	int cnt1 = 0, cnt2 = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'R') {
			cnt1++;
		} else {
			cnt2++;
		}
	}
	if (cnt1 > cnt2) {
		cout << "Yes\n";
	} else {
		cout << "No\n";
	}
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int n,k;
int main() {
	scanf("%d%d",&n,&k);
	int nn=n<<=1;
	if (k&1) {
		int t=nn/(k<<1);
		ll ans=1ll*t*t*t;
		cout<<ans<<endl;
	}
	else {
		int t=nn/k;
		int ev=t>>1,od=t-ev;
		ll ans=1ll*ev*ev*ev+1ll*od*od*od;
		cout<<ans<<endl;
	}
//	f[1]=1;
//	for (register int i=1;i<=m;++i) {
//		f[i]=f[i-1]<<1;
//	}
	return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    h, w = map(int, input().split())
    a = []
    row_ng = ['.'] * w
    for _ in range(h):
        row = list(input())
        if row == row_ng:
            h -= 1
        else:
            a.append(row)

    a2 = [[] for _ in range(h)]
    for i1 in range(w):
        flag = False
        for i2 in range(h):
            if a[i2][i1] == '#':
                flag = True
                break
        if flag:
            for i3 in range(h):
                a2[i3].append(a[i3][i1])

    for arow in a2:
        print("".join(arow))

if __name__ == '__main__':
    main()

Measured memory_bytes: 66264
#include<iostream>
using namespace std;
int main()
{
   int A,B,X;
   cin>>A>>B>>X;
   int P;
   if(A>=2*B)
   {
       P = (X/500)*B;
 
       if(X%500!=0)
       {
           P += B;
       }
   }
   else
   {
       P = (X/1000)*A;
 
       if(X%1000!=0)
       {
        if(X%1000<=500 && A>B)
        {
            P += B;
        }
        else
        {
            P += A;
        }
         
       }
   }
   cout<<P<<endl;
    
}


Measured memory_bytes: 3088
n = int(input())
a = list(map(int, input().split()))


def diff(now, d):
    return abs(a[now] - a[now - d])

# dp = [None] * n
# def dfs(depth=n - 1):
#     if dp[depth] != None:
#         return dp[depth]
#     if depth == 0:
#         dp[depth] = 0
#         return 0
#     if depth == 1:
#         dp[depth] = dfs(depth=depth - 1) + diff(depth, 1)
#         return dp[depth]
#     dp[depth] = min(dfs(depth=depth - 1) + diff(depth, 1), dfs(depth=depth - 2) + diff(depth, 2))
#     return dp[depth]
#
# print(dfs())

dp = [0] * n
dp[1] = diff(1, 1)
for depth in range(2, n):
    dp[depth] = min(dp[depth - 1] + diff(depth, 1), dp[depth - 2] + diff(depth, 2))
print(dp[-1])


Measured memory_bytes: 13908
#include<bits/stdc++.h>
#define ll long long
#define dl double
#define mp make_pair
#define pb push_back
using namespace std;

//***********************************************************************

// hash struct for unordered_map
struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
};

int MAXNUM = 5e3+5;
vector <int>vis(MAXNUM);
vector<int> pr;
void sieve() {
	pr.push_back(2);
	for(ll i=3;i<MAXNUM;i+=2) if(!vis[i]) {
		pr.push_back(i);
		for(ll j=i*i;j<MAXNUM;j+=2*i) vis[j]=true;
	}
}
//************************************************************************

void solve()
{
    int ans=0;
    for(int i=0;i<5;i++)
    {
        ll x;
        cin >> x;
        if(x==0)
        ans=i+1;
    }
    cout << ans << endl;
}   


int main()
{ 
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
	ll t;
	//cin >> t;
	t=1;
	while(t--)
	{
		solve();
	}

	return 0;
}

Measured memory_bytes: 3620
#include<iostream>

using namespace std;

int main(){
int A,B,C,K,a,b,c,i,j,x;
cin >> A >> B >> C >> K;
a=A;
b=B;
c=C;
x=0;
for(i=0;i<K;i++){if(b<=a){b=b*2;
x++;}

if(b>a)break;}

for(j=0;j<K-x;j++){if(c<=b){c=c*2;}
if(c>b)break;}

if(b<=a||c<=b){cout << "No" << endl;}else{cout << "Yes" <<endl;}







return 0;
}

Measured memory_bytes: 3620
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            int n = int.Parse(str);
            int i = 1;

            do
            {
                
                    int x = i;
                    if (x % 3 == 0)
                    {
                        Console.Write(" {0}",i);
                   
                    }
                    else
                    {
                        do
                        {
                            if ((x % 10) == 3)
                            {
                                Console.Write(" {0}", i);
                                break;
                            }
                            x /= 10;


                        }
                        while (x != 0);
                    }
                   

                    ++i;

            }
            while (i <= n) ;
            
            Console.WriteLine();
        }
    }
}

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

string str;
int a[4];
int sign[4];
int ans[4];

void dfs(int i){
    if(i==4){
        int sum=0;
        for(int i=0; i<4; i++){
            sum+=sign[i]*a[i];
        }
        //cout<<sum<<endl;
        if(sum==7){
            //cout<<"yattaze"<<endl;
            for(int i=0; i<4; i++){
                ans[i]=sign[i];
            }
        }
    }
    else{
        sign[i]=1;
        dfs(i+1);
        sign[i]=-1;
        dfs(i+1);
    }
}

int main(){

    cin>>str;
    for(int i=0; i<4; i++){
        a[i]=str[i]-'0';
    }
    sign[0]=1;
    dfs(1);
        for(int i=0; i<4; i++){
            if(i!=0){
                //cout<<ans[i];
                cout<<((ans[i]==1)?'+':'-');
            }
            cout<<a[i];
        }
    cout<<"=7"<<endl;

    return 0;
}



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


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

  vector<int> A(N);
  for(int i = 0;i < N;i++) {
      cin >> A.at(i);
  }

  vector<int> copy = (A);
  sort(copy.begin(),copy.end());
  int first = copy.at(N - 1);
  int second = copy.at(N - 2);

  for(int i = 0;i < N;i++) {
      if(A.at(i) == first) {
          cout << second << endl;
      }else {
          cout << first << endl;
      }
  }


 
}



Measured memory_bytes: 3200
N = int(input())

best = 1
best_count = 0
for n in range(1, N+1):
    i = n
    count = 0
    while True:
        q, mod = divmod(i, 2)
        if mod == 0:
            i = q
            count += 1
        else:
            break
    if count > best_count:
        best = n
        best_count = count

print(best)


Measured memory_bytes: 2940
//Bismillah Hir Rehmanir Rahim
//Allah knows best
using namespace std;
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#define endl "\n"
#define mini -10000000000000000
#define start ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define f(i, a, n) for( i=a; i<n;i++)
#define ll long long
#define pi 3.141592653589793
#define vi              vector<int>
#define si              set<int>
#define pb              push_back
#define mp              make_pair
#define mod             1000000007
#define rr              return 0
#define ff              first
#define in              insert
#define ss              second
#define setbits(x)      __builtin_popcountll(x)
#define zrbits(x)       __builtin_ctzll(x)
#define deb(x)          cout << #x << " = " << x << endl
int main()
{
    //freopen("in.txt","r",stdin);
    start;
    ll i,j,k,n,m;
   cin>>n;
   ll a[n],s[n];
   ll cnt=0;
   ll f=0;
   for(i=0;i<n;i++)
   {
       cin>>a[i]>>s[i];
       if(s[i]==a[i])
        cnt++;
       else
       {
           if(cnt>=3)
            f=1;
           cnt=0;
       }
   }
   if(cnt>=3)
    f=1;
   if(f==1) cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
    rr;
}


Measured memory_bytes: 3660
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
#define MAX 100100
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
int n,m,f[MAX],a[MAX];
int getf(int x){return x==f[x]?x:f[x]=getf(f[x]);}
vector<int> E[MAX];
void dfs(int u,int ff){for(int v:E[u])if(v!=ff)dfs(v,u),a[u]^=a[v];}
int main()
{
	n=read();m=read();
	for(int i=1;i<=n;++i)f[i]=i;
	for(int i=1;i<=m;++i)
	{
		int u=read(),v=read();
		if(getf(u)!=getf(v))
			E[u].push_back(v),E[v].push_back(u),f[getf(u)]=getf(v);
		a[u]^=1;a[v]^=1;
	}
	for(int i=1;i<=n;++i)
		if(getf(i)!=getf(1))E[1].push_back(i),E[i].push_back(1),f[getf(i)]=getf(1);	dfs(1,0);
	for(int i=1;i<=n;++i)if(a[i]){puts("NO");return 0;}
	puts("YES");
	return 0;
}


Measured memory_bytes: 6656
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
template <class T>
using Vec2 = vector<vector<T>>;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for(ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for(ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <class T1, class T2>
bool chmax(T1 &a, const T2 b){if(a < b){a = b; return true;} return false;}
template <class T1, class T2>
bool chmin(T1 &a, const T2 b){if(a > b){a = b; return true;} return false;}
ll pow2(const int n){return (1LL << n);}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for (T &i : v) os << i << ' ';
    return os;
}
void co() { cout << endl; }
template <class Head, class... Tail>
void co(Head&& head, Tail&&... tail) {
    cout << head << ' ';
    co(forward<Tail>(tail)...);
}
void ce() { cerr << endl; }
template <class Head, class... Tail>
void ce(Head&& head, Tail&&... tail) {
    cerr << head << ' ';
    ce(forward<Tail>(tail)...);
}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const int n){cout << fixed << setprecision(n);}
constexpr int INF = 1000000001;
constexpr ll LINF = 1000000000000000001;
constexpr ll MOD = 1000000007;
constexpr ll MOD_N = 998244353;
constexpr ld EPS = 1e-11;
const double PI = acos(-1);

int main(void) {
    ll n, m;
    cin >> n >> m;
    scc_graph scc(n);
    while (m--) {
        ll a, b;
        cin >> a >> b;
        scc.add_edge(a, b);
    }

    auto v = scc.scc();
    co(v.size());
    for (auto &i : v){
        cout << i.size() << ' ';
        for (auto &j : i) cout << j << ' ';
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 40608
#include<cstdio>
class UnionFind{
private:
    int length;
    //parent[x]=xの親の番号 ............. xに親が存在する場合,
    //parent[x]=-(xを含む集合の要素数) ... xが親である場合
    int *parent;
    int *rank;
public:
    UnionFind(int l);
    ~UnionFind();
    int root(int x);
    void unite(int x,int y);
    bool isSameTree(int x,int y);
    int sizeOf(int x);
    int count();
};
UnionFind::UnionFind(int l){
    length=l;
    parent=new int[l];
    for(int i=0;i<l;i++)parent[i]=-1;
    rank=new int[l];
    for(int i=0;i<l;i++)rank[i]=0;
}
UnionFind::~UnionFind(){
    delete[] parent;
    delete[] rank;
}
int UnionFind::root(int x){
    if(parent[x]<0)return x;
    return parent[x]=root(parent[x]);
}
void UnionFind::unite(int x,int y){
    int rx=root(x),ry=root(y);
    if(rank[rx]>rank[ry]){
        parent[rx]+=parent[ry];
        parent[ry]=rx;
    }
    else if(rank[rx]<rank[ry]){
        parent[ry]+=parent[rx];
        parent[rx]=ry;
    }
    else if(rx!=ry){
        parent[rx]+=parent[ry];
        parent[ry]=rx;
        rank[rx]+=1;
    }
}
bool UnionFind::isSameTree(int x,int y){
    return root(x)==root(y);
}
int UnionFind::count(){
    int *tmp=new int[length];
    for(int i=0;i<length;i++)tmp[i]=0;
    for(int i=0;i<length;i++)tmp[root(i)]=1;
    int ans=0;
    for(int i=0;i<length;i++)ans+=tmp[i];
    return ans;
}
int UnionFind::sizeOf(int x){
    return -parent[root(x)];
}
int const maxN=100001;
int a[maxN],b[maxN];
long long w[maxN];
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    UnionFind uf(n+1);
    for(int i=0;i<m;i++)scanf("%d%d",&a[i],&b[i]);
    for(int i=m-1;i>=0;i--){
        if(uf.isSameTree(a[i],b[i]))w[i]=0;
        else w[i]=((long long)uf.sizeOf(a[i]))*uf.sizeOf(b[i]);
        uf.unite(a[i],b[i]);
    }
    long long sum=0;
    for(int i=0;i<m;i++){
        sum+=w[i];
        printf("%lld\n",sum);
    }
    return 0;
}

Measured memory_bytes: 3712
//do not think about past and stay in this moment
//organize and work - Abhinav IIITA
#include <bits/stdc++.h>
#include <ctime>
using namespace std;
#define int long long
#define ld long double
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end() 
const ld pi = acos(-1.0);
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int mod;
int h,w;
int mx=-1;
vector<int> adj[1000];
bool vis[20][20];
int level[20][20];
string s[20];
int zrr[100005];
void fact(){
	zrr[0]=1;
	for(int i=1;i<100005;++i){
		zrr[i]=i*zrr[i-1];
		zrr[i]%=mod;
	}
}
int modexp(int x){
	int y=mod-2;
	int res=1;
	while(y>0){
		if(y&1){
			res*=x;
			res%=mod;
		}
		x*=x;
		x%=mod;
		y/=2;
	}
	return res;
}
void dfs(int x,int y){
	queue<pair<int,int>> q;
	q.push({x,y});
	queue<int> r;
	r.push(0);
	while(!q.empty()){
		pair<int,int> xp = q.front();	q.pop();
		int lpp=r.front(); r.pop();
		int cor[4][2];
		cor[0][0]=xp.first-1 ;cor[0][1]=xp.second ;
		cor[1][0]=xp.first+1 ;cor[1][1]=xp.second ;
		cor[2][0]=xp.first ;cor[2][1]=xp.second-1 ;
		cor[3][0]=xp.first ;cor[3][1]=xp.second+1 ;
		for(int i=0;i<4;++i){
				if(cor[i][0]<0 || cor[i][0]>=h)
				continue;
				if(cor[i][1]<0 || cor[i][1]>=w)
				continue;
				if(s[cor[i][0]][cor[i][1]]=='#')
				continue;
				if(!vis[cor[i][0]][cor[i][1]]){
					q.push({cor[i][0],cor[i][1]});
					r.push(lpp+1);
				}
		}
		level[xp.first][xp.second]=lpp;
		vis[xp.first][xp.second]=true;
	}
	/*for(int i=0;i<h;++i){
		for(int j=0;j<w;++j)
		cout<<vis[i][j]<<" ";
		cout<<endl;
	}*/
}
void solve(){	
	cin>>h>>w;
	for(int i=0;i<h;++i)
		cin>>s[i];
	for(int i=0;i<h;++i)
	for(int j=0;j<w;++j)	
	if(s[i][j]=='.'){
		for(int ii=0;ii<h;++ii)
		for(int jj=0;jj<w;++jj)
		{vis[ii][jj]=false; level[ii][jj]=0;}
		dfs(i,j);
		for(int ii=0;ii<h;++ii){
		for(int jj=0;jj<w;++jj){
		mx=max(mx,level[ii][jj]);
		//cout<<level[ii][jj]<<" ";
		}//cout<<endl;}
	}
	}
	cout<<mx;
}

// -----------------------------------------------------------------------


void spp(){
	// the point is that given element will be maximum in how many sets .. sum that up
	// is minimum in how many set ... sum that up
	// subtract the above two
	int n,k;
	cin>>n>>k;
	int arr[n];
	for(int i=0;i<n;++i)
	cin>>arr[i];
	sort(arr,arr+n);
	fact();
	int mxs=0;
	for(int i=k-1;i<n;++i){
		int res=(((zrr[i]*modexp(zrr[k-1]))%mod)*modexp(zrr[i-k+1]))%mod;
		//cout<<res<<" res is\n";
		mxs+=(res*arr[i])%mod;
		//cout<<mxs<<" mxs is\n";
		mxs%=mod;
	}
	int mns=0;
	for(int i=n-k;i>=0;--i){
		int res=(((zrr[n-i-1]*modexp(zrr[k-1]))%mod)*modexp(zrr[n-i-k]))%mod;
		mns+=(res*arr[i])%mod;
		mns%=mod;
	}
	//cout<<mxs<<" "<<mns<<endl;
	cout<<(mxs-mns+mod)%mod<<endl;
}

int32_t main()
{
	mod=1e9+7;
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); 	
	int t=1;
	//cin>>t;
	while(t--)
	spp();
	return 0;
}


Measured memory_bytes: 1920
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define yes "Yes\n"
#define no "No\n"
int r;
//int m,n;
//int i,j,k,l;
//int a,b,c,d,e,f,g;
//int sum,total;
//long long int ;
//float ;
//double ;
//char a[101],b[101],s[101],t[101],u[101];
int main(void){
    scanf("%d",&r);
    printf("%f",2*r*M_PI);
    return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define endl "\n"     
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

const int N=2e5+5;
const int mod=1e9+7;
const int M=3e3+5;

int h,w,n;
int fact[N],inv[N];
int reach[M];
pair <int,int> a[M];

int power(int a, int b, int m)
{
	int ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}

void precompute()
{
     fact[0]=1;
     for(int i=1;i<N;i++)
          fact[i]=(i*fact[i-1])%mod;
     inv[N-1]=power(fact[N-1],mod-2,mod);
     for(int i=N-2;i>=0;i--)
          inv[i]=(inv[i+1]*(i+1))%mod;
}

int nCr(int n,int r)
{
     if(r>n || r<0)
          return 0;
     
     int ans=fact[n];
     ans*=inv[r];
     ans%=mod;
     ans*=inv[n-r];
     ans%=mod;
     return ans;
}

int formula(int x1, int y1, int x2, int y2)
{
	if(x1>x2)
		return 0;
	if(y1>y2)
		return 0;
	return nCr(x2-x1+y2-y1, x2-x1);
}

void compute()
{
     for(int i=1;i<=n;i++)
     {
          reach[i]=formula(1,1,a[i].ff,a[i].ss);
          int sub=0;
          for(int j=1;j<i;j++)
          {
               sub+=(reach[j]*formula(a[j].ff,a[j].ss,a[i].ff,a[i].ss));
               sub%=mod;
          }
          reach[i]-=sub;
          reach[i]+=mod;
          reach[i]%=mod;
     }
}

int32_t main()
{
     IOS;
     
     precompute();
     cin>>h>>w>>n;
     for(int i=1;i<=n;i++)
          cin>>a[i].ff>>a[i].ss;
     sort(a+1,a+1+n);
     n++;
     a[n].ff=h;
     a[n].ss=w;
     compute();
     cout<<reach[n];
}


Measured memory_bytes: 3456
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;
    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }
    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}
#[allow(unused_macros)]
macro_rules ! get { ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ;; ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; }
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { println ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }

fn main() {
    let (n, k) = get!(usize, usize);
    let seq = util::gets::<usize>();
    let mut memo = vec![0; k + 1];
    let mut m = 0;

    let mut r = 0;
    let mut ans = n + 1;

    for l in 0..n {
        while m < k && r < n {
            let x = seq[r];
            if x <= k {
                if memo[x] == 0 {
                    m += 1;
                }
                memo[x] += 1;
            }
            r += 1;
        }
        if m == k {
            ans = min(ans, r - l);
        }

        let x = seq[l];
        if x <= k {
            if memo[x] == 1 {
                m -= 1;
            }
            memo[x] -= 1;
        }
    }

    println!("{}", if ans > n { 0 } else { ans });
}



Measured memory_bytes: 6964
(defmacro let-if (nv c true false)
  `(let (,nv) (if ,c ,true ,false)))

(defun daydream-with (str start)
  (let-if (len (- (length str) start))
    (< len 5)
    nil
    (let-if (dream (string= #.(reverse "dream")
                       (subseq str start (+ start 5))))
      dream 5
      (let-if (erase (string= #.(reverse "erase")
                       (subseq str start (+ start 5))))
        erase 5
        (if (< len 6)
          nil
          (let-if (eraser (string= #.(reverse "eraser")
                            (subseq str start (+ start 6))))
            eraser 6
            (if (< len 7)
              nil
              (let-if (dreamer (string= #.(reverse "dreamer")
                                 (subseq str start (+ start 7))))
                dreamer 7
                nil))))))))

(let* ((s (reverse (read-line)))
       (len (length s))
       (r 0))
  (loop for i = (daydream-with s r)
        if (null i) do (return)
        else do (incf r i)
        while (>= len r))
  (if (>= r len)
    (format t "YES~%")
    (format t "NO~%")))

Measured memory_bytes: 12772
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

signed main() {
#ifdef LOCAL
  assert(freopen("c.in", "r", stdin));
#endif
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; ++i) {
    cin >> d[i];
  }
  if (n >= 24) {
    cout << 0 << '\n';
    return 0;
  }
  if (n >= 12) {
    map<int, int> cnt;
    cnt[0]++;
    cnt[0]++;
    cnt[12]++;
    for (int x : d) {
      if (++cnt[x] > 2) {
        cout << 0 << '\n';
        return 0;
      }
    }
    cout << 1 << '\n';
    return 0;
  }
  int res = 0;
  for (int mask = 0; mask < (1 << n); ++mask) {
    vector<int> pos(n + 1);
    pos[n] = 0;
    for (int i = 0; i < n; ++i) {
      if (mask & (1 << i)) {
        pos[i] = d[i];
      } else {
        pos[i] = 24 - d[i];
      }
    }
    sort(pos.begin(), pos.end());
    int cur = 24;
    for (int i = 0; i < n; ++i) {
      cur = min(cur, pos[i + 1] - pos[i]);
    }
    cur = min(cur, 24 - pos[n]);
    res = max(res, cur);
  }
  cout << res << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <algorithm>
#include <array>

using namespace std;


template<typename T>
void execute(T& cin) {
	size_t n;
	cin >> n;
	vector< vector<int> > grapthMatrix(n, vector<int>(n,0));
	for (size_t i = 0; i != n; ++i) {
		size_t u;
		size_t k;
		cin >> u >> k;
		for (size_t j = 0; j != k; ++j){
			size_t v;
			cin >> v;
			grapthMatrix.at(u - 1).at(v - 1) = 1;
		}
	}
	for (size_t i = 0; i != n; ++i) {
		const vector<int>& adj = grapthMatrix.at(i);
		cout << adj.front();
		for (size_t j = 1; j != n; ++j) {
			cout << " " << adj.at(j);
		}
		cout << endl;
	}

}

int main()
{
	execute(cin);

	return 0;
}


Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
const double PI=3.14159265358979323846;
int main(){
    int n;cin>>n;
    vector<int> v(n-1);
    vector<int> ans(2*100000+1,0);
    for(int i=0;i<n-1;i++)cin>>v[i];
    for(int i=0;i<n-1;i++){
        ans[v[i]]++;
    }

    for(int i=1;i<n+1;i++){
        cout<<ans[i]<<endl;
    }

    return 0;
}

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

int H, W, x, y, ans = 0, flag = 0;
queue<int> Qx, Qx_next; queue<int> Qy, Qy_next;

bool can_go(int x, int y){
    return (1 <= x && x <= H && 1 <= y && y<= W);
}

void f(vector<vector<int>>& A, int x, int y){
    if(can_go(x,y)){
        if(A[x][y] == 1){
            flag = 1;
            A[x][y] = -1;
            Qx_next.push(x);
            Qy_next.push(y);
        }
    }
}

void visit(vector<vector<int>>& A, int x, int y){
    f(A, x-1, y);
    f(A, x+1, y);
    f(A, x, y-1);
    f(A, x, y+1);
}

int main(){
    cin >> H >> W;
    vector<vector<int>> A(H+1, vector<int>(W+1, 1));
    char buf;
    for(int i = 1; i <= H; ++i){
        for(int j = 1; j <= W; ++j){
            cin >> buf;
            if(buf == '#'){
                A[i][j] = -1; //黒色ならfalse, 白色ならtrue
                Qx.push(i);
                Qy.push(j);
            }
        }
    }
    while(!Qx.empty()){
        x = Qx.front();
        y = Qy.front();
        Qx.pop();
        Qy.pop();
        visit(A, x, y);
        if(Qx.empty()){
            while(!Qx_next.empty()){
                Qx.push(Qx_next.front()); Qx_next.pop();
                Qy.push(Qy_next.front()); Qy_next.pop();
            }
            if(flag == 1)++ans;
            flag = 0;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 15412
#include <iostream>
using namespace std;
int function(int n) {
    return ((n%2==0)? n/2 : 3*n+1);
}
int main() {
    int s;
    cin >> s;
    int result;
    if (s == 1 || s == 2 || s == 4) {
        result = 4;
    } else {
        int cnt = 1;
        while (s != 4) {
            s = function(s);
            cnt++;
        }
        result = cnt + 3;
    }
    cout << result << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define int long long

int N;
vector<int> P;

signed main() {
  cin >> N;
  P.resize(N);
  for(int i=0; i<N; i++) cin >> P[i];

  int ans = 0;
  int minp = N+1;

  for(int i=0; i<N; i++) {
    if(minp >= P[i]) ans++;
    minp = min(P[i], minp);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792