akhauriyash/Code-Regression huggingface dataset:
import sys
from collections import defaultdict, deque
from heapq import *
sys.setrecursionlimit(200000)
input = sys.stdin.readline

# N, M, = map(int, input().split())
N = int(input())
L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip

lc = L.copy()
L.sort()

t = int(N // 2) * -1
center = L[t]
c2 = L[t - 1]
for i in range(N):
    c = lc[i]

    if c < center:
        print(center)
    else:
        print(c2)

Measured memory_bytes: 25476
#include <iostream>

using namespace std;

const long MOD = 1000000007;
long dp[51][51][2501];

int main(){
    int n, K;
    cin >> n >> K;
    dp[1][0][0] = 1;
    dp[1][1][2*n] = 1;
    for(int i = 2; i <= n; i++){
        int m = n-i+1;
        for(int j = 0; j <= i; j++){
            for(int k = 0; k <= 2500; k++){
                dp[i][j][k] += dp[i-1][j][k];
                dp[i][j][k] += dp[i-1][j][k]*2*j;
                if(j > 0 && (k-2*m) >= 0) dp[i][j][k] += dp[i-1][j-1][k-2*m];
                if(j+1 <= 2*n && (k+2*m)<= 2500) dp[i][j][k] += dp[i-1][j+1][k+2*m]*(j+1)*(j+1);  
                dp[i][j][k] %= MOD;     
            }
        }
    }
    cout << dp[n][0][K] << endl;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> P;

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

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

    if (S == "ABC") puts("ARC");
    else puts("ABC");
}

Measured memory_bytes: 3624
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

ll h,w;

void solve(){
    cin >> h >> w;
    if(h==1 || w==1){
        cout << 1 << endl;
        return;
    }
    ll ans=(h/2)*w;
    if(h%2==1) ans+=(w+1)/2;
    cout << ans << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 256
/*
	  Author : @evenbao
	  Created : 2020 / 07 / 30
*/

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;

#define pii pair<int , int>
#define mp make_pair
#define fi first
#define se second

const int MAXN = 2e5 + 10;

int pc;
int pr[MAXN] , f[MAXN];
LL A[MAXN] , B[MAXN];

template <typename T> inline void chkmax(T &x , T y) { x = max(x , y); }
template <typename T> inline void chkmin(T &x , T y) { x = min(x , y); }
template <typename T> inline void read(T &x) {
    T f = 1; x = 0;
    char c = getchar();
    for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
    for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
    x *= f;
}

inline void G(int n) {
		for (int i = 2; i <= n; ++i) {
				if (!f[i]) f[i] = pr[++pc] = i;
				for (int j = 1; j <= pc && i * pr[j] <= n; ++j) {
						f[i * pr[j]] = pr[j];
						if (i % pr[j] == 0) break;
				}
		}
}
int main() {
		
		int n;
		scanf("%d" , &n); G(10000);
		for (int i = 1; i <= n; ++i) A[i] = pr[i & 1 ? i / 2 + 1 : n + n - i / 2 + 1];
		for (int i = 1; i <= n; ++i) B[i] = pr[(i & 1 ? n - i / 2 : n + i / 2) + (n & 1)];
		A[0] = A[n + 1] = B[0] = B[n + 1] = 1;
		for (int i = 1; i <= n; ++i , printf("\n")) 
		for (int j = 1; j <= n; ++j)
				if ((i + j) & 1) printf("%lld " , (LL) A[(i + j) / 2] * A[(i + j) / 2 + 1] * B[(n + i - j + (n & 1)) / 2] * B[(n + i - j + (n & 1)) / 2 + 1] + 1);
				else printf("%lld " , A[(i + j) / 2] * B[(n + i - j + (n & 1)) / 2]); 
	  return 0;
}



Measured memory_bytes: 3908
def main():
  import sys
  input = sys.stdin.readline
  n,m=map(int,input().split())
  if m==0:
    if n==1:
      print(0)
      exit()
    else:
      print(pow(10,n-1))
      exit()
  sc=[list(map(int,input().split())) for _ in range(m)]
  sc=list(map(list, set(map(tuple, sc))))
  sc=sorted(sc,key=lambda x: (x[0],x[1]))
  if len(sc)>n:
    print(-1)
    exit()
  l=['0']*n
  l[0]='1'
  if n==1:
    if sc[0][0]==1:
      print(sc[0][1])
      exit()
    else:
      print(-1)
      exit()
  for i in range(len(sc)):
    if type(l[sc[i][0]-1])==str:
      l[sc[i][0]-1]=sc[i][1]
    else:
      if l[sc[i][0]-1]!=sc[i][1]:
        print(-1)
        exit()
  if len(''.join([str(int(i)) for i in l]))==n and int(''.join([str(int(i)) for i in l]))>=pow(10,n-1):
    print(int(''.join([str(int(i)) for i in l])))
  else:
    print(-1)
  
if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
typedef long long ll ;

bool check(vector<int> &A,vector<int> &ans,int N,int n,int m){
    ans[0]=n;ans[1]=m;
    for(int i=1;i<N-1;i++){
        ans[i+1]=A[i]*ans[i]*ans[i-1];
    }
    int tp=A[N-1]*ans[N-1]*ans[N-2];
    int ty=A[0]*ans[0]*ans[1];
    if(tp==ans[0]&&ty==ans[N-1])return true;
    else return false;
}

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        char c;
        cin>> c;
        if(c=='x')A[i]=-1;
        else A[i]=1;
    }
    vector<int> ans(N);
    if(check(A,ans,N,1,1)){
        for(int i=0;i<N;i++){
            if(ans[i]==1)cout<<'S';
            else cout<<'W';
        }
        return 0;
    }if(check(A,ans,N,1,-1)){
        for(int i=0;i<N;i++){
            if(ans[i]==1)cout<<'S';
            else cout<<'W';
        }
        return 0;
    }if(check(A,ans,N,-1,1)){
        for(int i=0;i<N;i++){
            if(ans[i]==1)cout<<'S';
            else cout<<'W';
        }
        return 0;
    }if(check(A,ans,N,-1,-1)){
        for(int i=0;i<N;i++){
            if(ans[i]==1)cout<<'S';
            else cout<<'W';
        }
        return 0;
    }
    cout<<-1;
    return 0;
}

Measured memory_bytes: 1152
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------

signed main() {
	int h, w;
	while (cin >> h >> w && h + w) {
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (i == 0 || i == h - 1 || j == 0 || j == w - 1) cout << "#";
				else cout << ".";
			}
			cout << endl;
		}
		cout << endl;
	}
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
#define PI 3.141592653589
#define ll long long
using namespace std;

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

int  main(){
  int n, d, x;
  cin >> n >> d >> x;
  vector<int> a(n);
  for(int i=0; i<n; ++i) cin >> a[i];
  int cnt = 0, cnt1 = 0;
  for(int i=0; i<n; ++i){
    int res = 1;
    while(res<=d){
      if(res==0) break;
      if(res>0){
        ++cnt;
        res += a[i];
      }
    }
    cnt1 += cnt;
    cnt = 0;
  }

  cout << cnt1 + x << endl;

  return 0;
}

Measured memory_bytes: 256
A,B,Q=gets.split.map(&:to_i)
S=A.times.map{gets.to_i}.sort
T=B.times.map{gets.to_i}.sort
Q.times do
  x=gets.to_i
  ar=S.bsearch_index{|i|x<=i}
  ar=A-1 unless ar
  al=[ar-1,0].max
  br=T.bsearch_index{|i|x<=i}
  br=B-1 unless br
  bl=[br-1,0].max
  ans=10**11
  [S[al],S[ar]].each do |a|
    [T[bl],T[br]].each do |b|
      l=[a,b].min
      r=[a,b].max
      d=r-l
      d+=l-x if x<l
      d+=x-r if r<x
      d+=[x-l,r-x].min if l<x && x<r
      ans=[ans,d].min
    end
  end
  p ans
end


Measured memory_bytes: 7152
import java.util.*;

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

        int k = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        for(int i = a; i <= b; i++){
            if(i % k == 0){
                System.out.println("OK");
                return;
            }
        }
        System.out.println("NG");

    }
}


Measured memory_bytes: 35844
S = input()
T = input()


dS = {}
dT = {}
for i in range(len(S)):
    dS.setdefault(T[i], S[i])
    if dS[T[i]] != S[i]:
        print("No")
        exit()
    dT.setdefault(S[i], T[i])
    if dT[S[i]] != T[i]:
        print("No")
        exit()
        


print("Yes")

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

#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
const int mod = 1e9 + 7;
int main() {
	char c[100005]; scanf("%s", c);
	int n = 0;
	for(int i = 0; c[i]; i++) n++;
	ll dp[n + 1][13]{0};
	dp[0][0] = 1;
	for1(i, n) {
		if(c[i - 1] == '?') {
			forn(j, 13) {
				forn(k, 10) {
					dp[i][(j * 10 + k) % 13] += dp[i - 1][j];
				 	int x = dp[i][(j * 10 + k) % 13];
				 	dp[i][(j * 10 + k) % 13] = x % mod;
				}
			}
		} else {
			forn(j, 13) {
				dp[i][(j * 10 + (c[i - 1] - '0')) % 13] += dp[i - 1][j];
				int x = dp[i][(j * 10 + (c[i - 1] - '0')) % 13];
				dp[i][(j * 10 + (c[i - 1] - '0')) % 13] = x % mod;
			}
		} 
	}
	printf("%lld", dp[n][5]);
	return 0;
}

Measured memory_bytes: 10496
#include <stdio.h>

int main(){

  int i,k,n;

  scanf("%d",&n);

  int a[n];

  for(i=1;i<=n;i++){

    scanf("%d",&a[i-1]);

  }

  for(k=n;k>=1;k--){

    printf("%d",a[k-1]);

  	if(k==1)
  		break;
  	
  	printf(" ");
  	
  } 

  printf("\n"); 

  return 0;

}

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

int max(int a,int b){
  int num= a + b;
  if(num<=a+b){
    num=a+b;
  }
  if(num<=a*b){
    num=a*b;
  }
  if(num<=a+(-1)*b){
    num=a+(-1)*b;
  }
  return num;
}

int main(){
  int a=0;
  int b=0;
  cin>>a>>b;
  cout<<max(a,b)<<endl;
  return 0;
}
  


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int K = sc.nextInt();
		String D[] = new String[K];
		
		for(int i=0; i<K; i++){
			D[i] = String.valueOf(sc.nextInt());
		}
		
		String moji;
		for(;;){
			moji = String.valueOf(N);
			
			boolean ret = true;
			for(int j=0; j<K; j++){
				if(moji.indexOf(D[j]) != -1){
					ret = false;
				}
			}
			
			if (ret){
				break;
			}
			N++;
		}
		
		

		
		
		System.out.println(N);


	}
}


Measured memory_bytes: 14540
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const ll MOD = 1000000007;
using namespace std;

class UnionFind{
    vector<int> par;
    vector<int> rank;
    
public:
    UnionFind(int n): par(n), rank(n){
        REP(i, n){
            par[i] = i;
            rank[i] = 0;
        }
    }
    
    int find(int x){
        if(x == par[x]) return x;
        else return par[x] = find(par[x]);
    }
    
    void unit(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return;
        
        if(rank[x] < rank[y]){
            par[x] = y;
        }else{
            par[y] = x;
            if(rank[x] == rank[y]) ++rank[x];
        }
    }
    
    bool same(int x, int y){
        return find(x) == find(y);
    }
};

int main(){
    int n, m; cin >> n >> m;
    vector<int> p(n);
    UnionFind tree(n);
    REP(i, n){
        cin >> p[i]; --p[i];
    }
    
    REP(i, m){
        int x, y; cin >> x >> y; --x; --y;
        tree.unit(x, y);
    }
    int cnt=0;
    REP(i, n) if(tree.same(i, p[i])) ++cnt;
    cout << cnt << endl;
    return 0;
}

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

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

    int n;
    cin >> n;

    map<int, int> res;
    for (int j = 2; j <= n; ++j) {
        int k = j;
        for (int i = 2; i * i <= k; ++i) {
            if (k % i != 0) continue;
            while (k % i == 0) {
                ++res[i];
                k /= i;
            }
        }
        if (k != 1) res[k]++;
    }

    int more_2 = 0;
    int more_4 = 0;
    int more_14 = 0;
    int more_24 = 0;
    int more_74 = 0;
    for (auto r: res) {
        if (r.second >= 74)
            more_74++;
        else if (r.second >= 24)
            more_24++;
        else if (r.second >= 14)
            more_14++;
        else if (r.second >= 4)
            more_4++;
        else if (r.second >= 2)
            more_2++;
    }

    // more_24 += more_74;
    // more_14 += more_24;
    // more_4 += more_14;
    // more_2 += more_4;
    // int total = more_4 * max(more_4 - 1, 0) / 2 * (more_2 + max(more_4 - 2, 0));
    int total = more_74 +
            (more_74 + more_24) * (more_14 + more_4 + more_2 + more_74 + more_24 - 1) +
            (more_74 + more_24 + more_14) * (more_4 + more_74 + more_24 + more_14 - 1) +
            (more_74 + more_24 + more_14 + more_4) * max(more_74 + more_24 + more_14 + more_4 - 1, 0) / 2 * (more_2 + max(more_74 + more_24 + more_14 + more_4 - 2, 0));

    cout << total << '\n';

    return 0;
}


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

void main_()
{
    string S;
    cin >> S;
    int digit_num = S.size(); // 桁数

    int msd = S[0] - '0';
    int ans1 = (msd - 1) + 9 * (digit_num - 1); // 最上位桁繰り下がり、残り桁9
    int ans2 = accumulate(begin(S), end(S), 0,
        [](int acc, int ch) { return acc + (ch - '0'); });
    cout << max(ans1, ans2) << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
#include <unordered_set>

using namespace std;
using Int = long long;

constexpr double EPS = 1e-10;
constexpr long long MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for (int i = 0;i < 60; i++) {
        if (n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

long long my_mod_pow(long long x, long long n) {
	long long ret = 1;
	for (; n > 0; n >>= 1, x = x * x % MOD) {
		if (n & 1) {
			ret = ret * x % MOD;
		}
	}
	return ret;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fastInput() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

Int ans[200005];
Int cnt[200005];
Int ans_all;

int main(void) {
    int N; cin >> N;
    vector<Int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        cnt[A[i]]++;
    }

    for (int i = 0; i < 200005; i++) {
        ans_all += cnt[i] * (cnt[i]-1) / 2;
    }
    for (int i = 0; i < N; i++) {
        cout << ans_all - (cnt[A[i]] * (cnt[A[i]] - 1) / 2) + ((cnt[A[i]] - 1) * (cnt[A[i]] - 2) / 2) << endl; 
    }
}

Measured memory_bytes: 4736
#include<stdio.h>

int main(){
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

    if(x-r>=0 && x+r<=W && y-r>=0 && y+r<=H){
	    printf("Yes\n");
    }else{ printf("No\n");
	}
    return 0;
}


Measured memory_bytes: 2108
n, m = map(int, input().split())
pn = list(map(lambda x:int(x)-1, input().split()))
ls = [-1] * n
for i in pn:
    ls[pn[i]] = i
#print(ls)

par = [i for i in range(n)]

def find(x):
    if par[x] == x:
        return x
    else:
        s = find(par[x])
        par[x] = s
        return s

def unite(x,y):
    s = find(x)
    t = find(y)
    if s>t:
        par[s] = t
    else:
        par[t] = s


for _ in range(m):
    x, y = map(lambda x:int(x)-1, input().split())
    unite(ls[x],ls[y])


ans2 = 0
for i in range(n): # i番目の数字がいる場所の親とiの場所
    place1 = ls[pn[i]]
    place2 = ls[i]

    if find(place1)==find(place2):
       ans2+=1
print(ans2)

Measured memory_bytes: 20276
import java.nio.charset.IllegalCharsetNameException;
import java.util.*;
import java.lang.*;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextLong();
		}
		long oddsum = 0;
		long oddcount = 0;
		for (int i = 0; i < n / 2; i++) {
			oddsum += a[2 * i];
			if (oddsum <= 0) {
				oddcount += Math.abs(1 - oddsum);
				oddsum = 1;
			}
			oddsum += a[2 * i + 1];
			if (oddsum >= 0) {
				oddcount += Math.abs(-1 - oddsum);
				oddsum = -1;
			}
		}
		long evensum = 0;
		long evencount = 0;
		for (int i = 0; i < n / 2; i++) {
			evensum += a[2 * i];
			if (evensum >= 0) {
				evencount += Math.abs(-1 - evensum);
				evensum = -1;
			}
			evensum += a[2 * i + 1];
			if (evensum <= 0) {
				evencount += Math.abs(1 - evensum);
				evensum = 1;
			}
		}
		if (n % 2 != 0) {
			oddsum += a[n - 1];
			if (oddsum <= 0) {
				oddcount += Math.abs(1 - oddsum);
				oddsum = 1;
			}
			evensum += a[n - 1];
			if (evensum >= 0) {
				evencount += Math.abs(-1 - evensum);
				evensum = -1;
			}
		}
		System.out.println(Math.min(oddcount, evencount));
	}
}

Measured memory_bytes: 50140
#include <sstream>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int add(string s) {
	int num = 0;
	string tmp = "";
	for (int i=0; i<s.length(); i++) {
		if (isdigit(s[i])) {
			tmp += s[i];
		} else if (!tmp.empty()) {
			stringstream ss;
			ss.str(tmp);
			int t; ss >> t;
			num += t;
			tmp = "";
		}
	}
	if (!tmp.empty()) {
		stringstream ss;
		ss.str(tmp);
		int t; ss >> t;
		num += t;
	}
	return num;
}

int main() {
	string s;
	int num=0;
	while (cin>>s) {
		num += add(s);
	}
	cout << num << endl;
}

Measured memory_bytes: 0
#include<stdio.h>

int main()
{
	int n, l, ans = 0, i;
	scanf("%d %d", &n, &l);
	for (i = 1; i < n; i++) {
		if (l <= 0) {
			ans = l + i - 1 + ans;
		}
		if (l > 0) {
			ans = l + i + ans;
		}
		if (l + i - 1 == 0) {
			n += 1;
		}
	}

	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
   
int n,a,b,A[8],B[8],C[33],D[33],M[8][8],IN[8];

void dfs(int x){

  if(x==8){
    for(int i=0;i<8;i++){
      for(int j=0;j<8;j++)
        if(M[i][j])cout<<'Q';
        else cout<<'.';
      cout<<endl;
    }
    exit(0);
  }

  for(int j=0;j<8;j++){
    if( (IN[x]&&j!=IN[x]-1) ||B[j]==1||C[x+j]==1||D[x-j+10]==1)continue;
    M[x][j]=A[x]=B[j]=C[x+j]=D[x-j+10]=1;
    dfs(x+1);
    M[x][j]=A[x]=B[j]=C[x+j]=D[x-j+10]=0;
  }
   

}
   
main(){
  cin>>n;
  while(n--){
    cin>>a>>b;
    M[a][b]=1;
    IN[a]=b+1;
  }
  dfs(0);
}


Measured memory_bytes: 3092
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define ushi int
#define tapu main
#define nichia (
#define kunn void
#define wara )

using ll = long long;

const int INF = 1073741823;
const int MINF = -1073741823;
const ll LINF = ll(4661686018427387903);
const ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/

int main(){

	int a, b;
	scanf("%d%d", &a, &b);
	if (a < b)swap(a, b);
	int ans = a;
	--a;
	printf("%d\n", ans + max(a, b));

	Please AC;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<cmath>

using namespace std;

int main() {

	int n;
	cin >> n;
	vector<int> x(n);
	float s = 0;
	for (int &i : x) {
		cin >> i;
		s += i;
	}
	int p = round(s / n);
 // cout<<p<<endl;
	int ans=0;
	for (int i=0;i<n;i++) {
		ans += (x[i] - p)*(x[i] - p);
     // cout<<ans<<endl;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>

using namespace std;
template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}

#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define REV(v) reverse(v.begin(),v.end())
#define SRTV(v) sort(v.begin(),v.end())
#define SRTAG(a,n) sort(a,a+n,greater<>())
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;

int atcoder(){
    //入力
    int n;
    cin >> n;
  	int mina = INT_MAX;
  	int maxa = 0;
    REP(i,0,n){
      int tmp;
      cin >> tmp;
      maxa = max(maxa,tmp);
      mina = min(mina,tmp);
    }
    //処理
  
    //出力
    cout << maxa-mina << ENT;
    return 0;
}

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


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

typedef long long ll;
typedef pair<int,int> ii;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	while(n>=0) {
		if(n%7==0) {
			cout << "Yes" << endl;
			return 0;
		}
		n-=4;
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// x ** n % mods を求める
pub fn mod_pow(x: i64, n: i64, mods: i64) -> i64 {
    if n == 0 {
        return 1;
    }
    let mut res = mod_pow(x * x % mods, n / 2, mods);
    if n % 2 == 1 {
        res = res * x % mods;
    }
    return res;
}

// (1/n) % mods を求める
pub fn mod_inv(n: i64, mods: i64) -> i64 {
    return mod_pow(n, mods-2, mods);
}

// nCk % mods を求める
pub fn mod_comb(n: i64, k: i64, mods: i64) -> i64 {
    let sum1 = (n-k+1..n+1).fold(1, |ac, x| ac * x % mods);
    let sum2 = (1..k+1).fold(1, |ac, x| ac * x % mods);
    return sum1 * mod_inv(sum2, mods) % mods;
}


fn main() {
    input!{
        k: usize,
    }
    let a: [i32; 32] = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51];
    println!("{}", a[k-1]);
}


Measured memory_bytes: 4476
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] A = new int[N];
		for(int i=0; i<N; i++) {
			A[i] = (sc.nextInt()+K-1)%K;
		}
		
		HashMap<Integer, ArrayList<Integer>> p = new HashMap<>();

		long ans = 0;
		int sum = 0;
		ArrayList<Integer> list = new ArrayList<>();
		list.add(0);
		p.put(0, list);
		for(int i=0; i<N; i++) {
			sum = (sum + A[i])%K;
			if(p.containsKey(sum)) {
				list = p.get(sum);
				int idx = Collections.binarySearch(list, i+1-(K-1));
				if(idx<0)
					idx = -idx-1;
				ans += list.size()-idx;
				list.add(i+1);
				p.put(sum, list);
				
			} else {
				list = new ArrayList<>();
				list.add(i+1);
				p.put(sum, list);
			}
		}

		System.out.println(ans);
		
		sc.close();
	}
}



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

int main() {
  int N, A;
  1 <= N <= 10000,0 <= A <= 1000;
  cin >> N >> A;
  if (N%500 <= A) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

match_num = {1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}

dp = [-1] * (n+10)
dp[0] = 0

for i in range(n):
    for j in range(m):
        nxt = match_num[a[j]]
        if dp[i]>=0:
            dp[i+nxt] = max(dp[i+nxt], dp[i]*10 + a[j])
print(dp[n])

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

int main(){
    int H,W;
    while(1<2){
    cin>>H>>W;
    if(H==0&&W==0)break;
    for(int j=1;j<=H;j++){
        for(int i=1;i<=W;i++){
            cout<<"#";
        }
        cout<<endl;
    }
        cout<<endl;
    }
}


Measured memory_bytes: 3112
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  std::string S, T;
  std::cin >> S >> T;
  std::cout << T << S << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll tmp1,tmp2,tmp3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}
vector<ll> visited(100,0);
vector<ll> vec[100];
vector<ll> cou_l(100,0);
vector<ll> cou_f(100,0);
ll sum = 0;
void dfs(ll k){
  //cout << k << endl;
  if(visited[k]){return;}
  visited[k] = 1;
  sum++;
  cou_f[k] = sum;
  for(auto itr : vec[k]){
    //cout << itr << endl;
    dfs(itr);
  }
  sum++;
  cou_l[k] = sum;
}
int main(){
  ll n;
  cin >> n;
  ll u,k,v;
  rep(i,n){
    cin >> u >> k;
    u--;
    rep(j,k){
      cin >> v;
      v--;
      vec[u].push_back(v);
    }
  }
  rep(i,n){
    if(visited[i] == 0){
      dfs(i);
    }
  }
  rep(i,n){
    cout << i+1 << " " << cou_f[i] << " " << cou_l[i] << endl;
  }
}



Measured memory_bytes: 3152
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <limits.h>
#include <map>
#include <numeric>

namespace test {
  std::string to_string(char val) {
    return std::string(1, val);
    // return std::string{val};
  }
}

using namespace std;



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

  int n = s.size();

  int count_1 = 0, count_0 = 0;

  for(int i = 0; i < n ; i++){
    if(s[i] == '1'){
      count_1++;
    } else if(s[i] == '0'){
      count_0++;
    }
  }

  int result = min(count_1, count_0) * 2;

  cout << result << endl;

  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  int l = k, r = k + n - 1, ans;
  if (l <= 0 and 0 <= r)
    ans = (l + r) * (n) / 2;
  else if (l > 0)
    ans = (l + 1 + r) * (n - 1) / 2;
  else
    ans = (l + r - 1) * (n - 1) / 2;
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define $ ios::sync_with_stdio(0);
#define endl '\n'
using namespace std;
using ll = long long int;
using ii = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<ii>;
using graph = vector<vi>;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
const int MAXN = 212345;
const ll mod = 1000000007;
int fq[30];
int main() {
    int n , m;
    string s;
    cin >> s;
    n = s.size();
    if (n == 2 && s[0] == s[1]) {
        cout << "1 2\n";
    } else {
        for (int i = 0; i<3; ++i) {
            auto x = s[i]-'0';
            fq[x]++;
            if (fq[x] == 2) {
                cout << "1 3\n";
                return 0;
            }
        }

        for (int i = 3; i<n; ++i) {
            auto x = s[i] - '0', y = s[i-3]-'0';
            fq[y]--;
            fq[x]++;
            if (fq[x] == 2) {
                cout << i-1 << ' ' << i+1 << endl;
                return 0;
            }
        }
        cout <<"-1 -1\n";
    }

}


Measured memory_bytes: 512
#include<stdio.h>
int main()
{
    int K,A,B,i;
    scanf("%d", &K);
    scanf("%d %d",&A,&B);
  for(i=K;i<A;i += K){
  }
  K = i;
  if ((A <= K) && (K <= B)){
    printf("OK");
  }
  else{
    printf("NG");
  }
  
  return 0;
}

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

int main(){
  ll n, p;
  cin >> n >> p;
  ll w[n], b[n], v[n];
  rep(i,n) cin >> w[i] >> b[i];
  ll sum = 0;
  rep(i,n) {
    w[i] *= (100-p);
    b[i] *= p;
    v[i] = w[i] + b[i];
    sum += b[i];
  }
  sort(v,v+n,greater<ll>());
  for(int i = 1; i < n; i++) v[i] += v[i-1];
  int ans = lower_bound(v,v+n,sum) - v;
  cout << ans+1 << endl;
}


Measured memory_bytes: 5944
import java.util.*;
import java.io.*;
public class Main
{
    static BufferedWriter bw;
    static BufferedReader br;
    static void solve()throws Exception
    {
        int n = Integer.parseInt(br.readLine());
        int A[] = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        int count[] = new int[n+1];
        for(int temp:A)
        {
            count[temp]++;
        }
        for(int i=1;i<count.length;i++)
        {
            bw.write(Integer.toString(count[i]));
            bw.newLine();
        }
    }
    public static void main(String []args)throws Exception
    {
        br=new BufferedReader(new InputStreamReader(System.in));
        bw=new BufferedWriter(new OutputStreamWriter(System.out));
        // int t = Integer.parseInt(br.readLine());
        // for(int i=0;i<t;i++)
        // {
        //     bw.write("Case #"+(i+1)+": ");
            solve();
        // }
        br.close();
        bw.close();
    }
}


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

using namespace std;

typedef long long ll;

#define MOD 998244353
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>b;--i)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);


ll arr[100001];
bool vis[100001];
ll lvl[100001];



ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1;
  while(b>0)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }

return ans;
}

ll pow(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }

return ans;
}


/*const int N=200000;

ll fac[N+1];
ll inv[N+1];
ll p=998244353;

ll c(ll a, ll b,ll m)
{
  if(a<b)return 0;
  return (fac[a]*inv[b]%m)*(inv[a-b])%m;
}

void fill()
{
inv[0]=1;
fac[0]=1;

for(int i=1;i<=N;i++)
{
  fac[i]=fac[i-1]*i%p;
  inv[i]=powM(fac[i],p-2,p);
}

}
*/
//ld dp[2001][2001];




int main()
{  fast

ll n;cin>>n;

vl a(n+1),b(n+1);

for(int i=1;i<=n;i++)
{
  cin>>a[i]>>b[i];
}

sort(all(a)),sort(all(b));

ll l,r;

if(n&1)
{
   l=a[(n+1)/2];
   r=b[(n+1)/2];
}
else
{
  l=a[n/2]+a[n/2+1];
  r=b[n/2]+b[n/2+1];
}

ll x=r-l+1;

cout<<x<<"\n";


 return 0;

}


Measured memory_bytes: 6368
#include<bits/stdc++.h>
#define PI acos(-1.0)
#define pb push_back
#define F first
#define S second
using namespace std;
typedef long long ll;
const int N=2e5+5;
const int MOD=1e9+7;
//ll a[N],sum[N];
char s[N];
int main(void){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);

    int d;
    cin >>s+1 >> d;
    int n=(int)strlen(s+1);
    for(int i=1;i<=n;i+=d)   cout << s[i];

    return 0;
}


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

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

int main() {
  ll N, M;
  cin >> N >> M;
  if (M < N) {
    swap(N, M);
  }
  if (N == 1 && M == 1) {
    cout << 1 << endl;
  } else if (N == 1 && M >= 2) {
    cout << M - 2 << endl;
  } else {
    cout << (N - 2) * (M - 2) << endl;
  }
  return 0;
}


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



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }


    Scanner cin;



    void calc()
    {
        cin = new Scanner();
        setFact(250000);
        int H = cin.nextInt();
        int W = cin.nextInt();
        long ans = getC(H - 1 + W - 1, W - 1);
        int A = cin.nextInt();
        int B = cin.nextInt();
        for (int i = 0; i < B; i++)
        {
            ans -= getC(H - 1 - A + i, i) * getC(A - 1 + W - 1 - i, W - 1 - i);
            ans %= mod;
            ans += mod;
            ans %= mod;
        }
        Console.WriteLine(ans);
    }

    long mod = 1000000007;
    long powmod(long a, long p)
    {
        long ans = 1;
        long mul = a;
        for (; p > 0; p >>= 1, mul = (mul * mul) % mod)
        {
            if ((p & 1) == 1) ans = (ans * mul) % mod;
        }
        return ans;
    }


    long[] fact; //階乗
    long[] revFact; //階乗の逆元
    void setFact(int N)
    {
        fact = new long[N];
        revFact = new long[N];
        fact[0] = 1;
        for (int i = 1; i < N; i++)
        {
            fact[i] = fact[i - 1] * i;
            fact[i] %= mod;
        }
        revFact[N - 1] = powmod(fact[N - 1], mod - 2);
        for (int i = N - 2; i >= 0; i--)
        {
            revFact[i] = revFact[i + 1] * (i + 1);
            revFact[i] %= mod;
        }
    }


    long getC(int a, int b)
    {
        return (((fact[a] * revFact[b]) % mod) * revFact[a - b]) % mod;
    }

}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 14816
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

long long n, x, m;
long long nextX[100010];
long long ans;

int main()
{
	scanf("%lld%lld%lld", &n, &x, &m);
	
	for (int i = 0 ; i < m ; i++) {
		nextX[i] = -1;
	}
	
	
	ans = x;
	long long nLeft = n - 1;
	long long newX;
	std::vector<long long> cycle;
	while (nLeft > 0) {
		nLeft--;
		newX = (x * x) % m;
		nextX[x] = newX;

		if (nextX[newX] != -1) {
			long long px = newX;
			cycle.push_back(px);
			while (px != x) {
				px = nextX[px];
				cycle.push_back(px);
			}
			
			break;
		}
		ans = ans + newX;		
		x = newX;
	}
	
	if (nLeft >= 0) {
		if (cycle.size() != 0) {
			long long sz = cycle.size();
	//		printf("%d\n", sz);
			
			long long sect = 0;
			for (int i = 0 ; i < cycle.size() ; i++) {
	//			printf("%d ", cycle[i]);
				sect = sect + cycle[i];
			}
	//		printf("\n");
				
				
			long long count = nLeft / sz;
			long long r = nLeft % sz;
			ans = ans + sect * count;
			for (int i = 0 ; i <= r ; i++)
				ans = ans + cycle[i];
			
		}
	}
	
	printf("%lld\n", ans);
	
	return 0;
}




Measured memory_bytes: 4132
import java.util.Scanner;
import java.lang.Math;

public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int K = scanner.nextInt();
        int[] stones = new int[N];
        for(int i = 0; i < N; i++) stones[i] = scanner.nextInt();

        int[] dp = new int[N];
        for(int i = 1; i < N; i++) {
            dp[i] = dp[i - 1] + Math.abs(stones[i] - stones[i - 1]);
            for(int j = Math.max(0, i - K); j < i - 1; j++) {
                dp[i] = Math.min(Math.abs(stones[i] - stones[j]) + dp[j], dp[i]);
            }
        }
        System.out.println(dp[N - 1]);
    }
}

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

#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

char mas[20][1010];

signed main(){
	int h, w, K;
	cin >> h >> w >> K;

	for(int i = 0;i < h;i++){
		cin >> mas[i];
	}

	int ans = INT_MAX;
	for(int i = 0;i < (1 << (h-1));i++){
		int x[20][1010] = {};
		int idx = 0;
		int bit = (i << 1);
		for(int j = 0;j < h;j++){
			if(bit & (1 << j)){
				idx++;
			}
			for(int k = 0;k < w;k++){
				x[idx][k] += mas[j][k] - '0';
			}
		}

		int tmp = idx;
		int le = 0;
		int now[20] = {};
		int n = idx+1;
		for(int j = 0;j < w;j++){
			for(int k = 0;k < n;k++){
				now[k] += x[k][j];
			}
			bool f = false;
			for(int k = 0;k < n;k++){
				if(now[k] > K){
					f = true;
				}
			}

			if(f){
				if(le == 0){
					tmp = INT_MAX;
					break;
				}
				for(int k = 0;k < n;k++){
					now[k] = 0;
				}
				tmp++;
				j--;
				le = 0;
			}else{
				le++;
			}
		}
		ans = min(ans, tmp);
	}

	cout << ans << endl;

	return 0;
}


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

int main() {
  
  int n;
  cin >> n;
  
  int num = 0;
  int ans = 0;
  
  for(int i = 0; i < n; i++){
    int x,y;
    cin >> x >> y;
    
    if(x == y){
      num = num + 1;
    }
    else{
      num = 0;
    }
    
    if(num == 3){
      ans = 1;
      break;
    }
    
  }
  
  if(ans == 1){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
  
}



Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(),(v).end()
#define out(a) cout << (a) << endl
using namespace std;
using ll = long long;
int main(){
    string s;
    cin >> s;
    int a=0, z=0;
    for (int i=0; i<s.size(); i++){
        if(s[i] == 'A') break;
        a++;
    }
    for (int i=s.size(); 0<i; i--){
        if(s[i] == 'Z') break;
        z++;
    }
    out(s.size()-a-z+1);
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass
{
    static void Main()
    {
        int N = int.Parse(ReadLine());
        if (N % 2 == 0)
        {
            WriteLine(N);
        }
        else
        {
            WriteLine(N*2);
        }
    }
}


Measured memory_bytes: 27316
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
int main() {
  int n,k,d[10]={},a[10]={};
  cin >> n >> k;
  for(int i=0; i<k; i++) {
    cin >> d[i];
    a[d[i]]=1;
  }
  for(int i=n; ; i++) {
    int b=i;
    while(b>0) {
      int c=b%10;
      if(a[c]==1) {
        break;
      }
      b/=10;
    }
    if(b==0) {
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;

public static class P
{
    public static void Main()
    {
        var s = Console.ReadLine().Select(x => x - '0').ToArray();
        int[] count = new int[2019];
        long res = 0;
        int cur = 0;
        count[cur]++;
        foreach (var c in s)
        {
            cur = (cur * 10 + c) % 2019;
            res += count[cur];
            count[cur]++;
            int[] newCount = new int[2019];
            for (int i = 0; i < count.Length; i++)
            {
                newCount[i * 10 % 2019] += count[i];
            }
            count = newCount;
        }
        Console.WriteLine(res);
    }
}

Measured memory_bytes: 47328