akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#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++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }


int main() {
    int N, M;
    cin >> N >> M;
    vint L(M), R(M);
    rep(i, M) {
        cin >> L[i] >> R[i];
    }
    auto Lmax = *max_element(L.begin(), L.end());
    auto Rmin = *min_element(R.begin(), R.end());
    cout << max(Rmin - Lmax + 1, 0) << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) < (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pll Dir[8] = { //移動
	{ 0 ,1 },{ -1 ,0 },{ 1 ,0 },{ 0 ,-1 },
	{ 1 ,1 },{ 1 ,-1 },{ -1 ,1 },{ -1 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL

struct Edge {
	int from, to;
	ll w;
};
typedef vector<vector<Edge>> Graph;

int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}


bool BellmanFord(Graph g, int s, vector<ll>& dis) { //is huheiro aru
#define INF 10000000000000LL
	fill(ALL(dis), INF);
	dis[s] = 0;
	REP(cc, g.size()*10) {

		REP(v, g.size()) {
			for (auto e : g[v]) {
				if (cc >= g.size() && e.to == g.size()-1 && dis[e.to] > dis[e.from] + e.w) return 1;
				dis[e.to] = min(dis[e.to], dis[e.from] + e.w);
			}
		}

	}


	return 0;
}

signed main(void) {
	int n, m;
	cin >> n >> m;
	Graph g(n);

	REP(i, m) {
		ll a, b, c;
		cin >> a >> b >> c;
		a--, b--;
		g[a].push_back({ a,b, -c });
	}
	vector<ll> dis(n);
	if (BellmanFord(g, 0, dis)) {
		cout << "inf" << endl;
	}
	else {
		cout << -dis[n - 1] << endl;
	}
	return 0;
}



Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){

    ll N, M;
    cin >> N >> M;
    ll ans = 0;
    ll tmp = 0;
    map<ll, ll>cnt;
    cnt[0] = 1;
    for(ll i = 0; i < N; i++){
        ll x;
        cin >> x;
        tmp = (tmp + x) % M;
        ans += cnt[tmp];
        cnt[tmp]++;
    }
    cout << ans << endl;

    return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> s(pow(2,n));
    rep(i,pow(2,n)) cin >> s.at(i);
    sort(all(s));
    reverse(all(s));
    vector<int> a(0);
    int t=0,nu=1;
    rep(i,pow(2,n)-1){
        if (s.at(i)!=s.at(i+1)){
            a.push_back(nu);
            nu=0;
        }
        nu++;
    }
    a.push_back(nu);
    vector<int> e(n+2,0);
    e.at(n+1)=1;
    rep(i,a.size()){
        vector<int> ee(n+2,0);
        rep(j,n+1){
            if (a.at(i)>e.at(n+1-j)){
                ee.at(n-j)=e.at(n+1-j);
            a.at(i)-=e.at(n+1-j);
                e.at(n+1-j)=0;
            }
            else {
                ee.at(n-j)=a.at(i);
                e.at(n+1-j)-=a.at(i);
                a.at(i)=0;
                break;
            }
        }
        if (a.at(i)!=0) {cout << "No" << endl;return 0;}
        rep(j,n+2){
            rep(k,j){
                e.at(k+1)+=ee.at(j);
            }
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 2424
a = int(input())
def sosutyousa(a):
    src = 2    
    while src <= a:
        if src == a:
            return a
        elif a % src == 0:
            return a + 1
        else:
            src += 1
flag = sosutyousa(a)
while a != flag:
    flag = sosutyousa(flag)
    a += 1
print(a)

Measured memory_bytes: 2940
#include <iostream>
#include <string>
using namespace std;int main(){int b[5][4];int sx,sy;int x,y;string line;while(true){for(int i=0;i<20;i++)b[i%5][i/5]=0;sx=sy=-1;for(y=0;y<8;y++){if (!(cin>>line))break;for(x=0;x<8;x++){if (line[x]=='1'){if (sy==-1){sx=x-1;sy=y;}b[x-sx][y-sy] = 1;}}}if (y<8)break;char a;if(b[2][0]&&b[1][1]&&b[2][1])a='A';if(b[1][3])a='B';if(b[4][0])a='C';if(b[0][2])a='D';if(b[3][1])a='E';if(b[2][2])a='F';if(b[0][1]&&b[2][0])a='G';cout<<a<<endl;}}

Measured memory_bytes: 0
/*#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	char a=0,b=0;
	int aa=0,bb=0;
	cin>>s;
	for(int i=0;i<4;i++)
	if(a==0) a=s[i];
	else if(s[i]==a) aa++;
	else if(b==0) b=s[i];
	else if(s[i]==b) bb++;
	else
	{
		cout<<"No";
		return 0;
	}
	if(aa!=2||bb!=2)
	{
		cout<<"No";
		return 0; 
	}
	cout<<"Yes";
}*/
/*#include<bits/stdc++.h>
using namespace std;
int main()
{
	int f[10010];
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>f[i];
	int ans=0;
	for(int i=2;i<=n-1;i++)
	if(f[i-1]<f[i]&&f[i]<f[i+1]||f[i+1]<f[i]&&f[i]<f[i-1]) ans++;
	cout<<ans<<endl;
}*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int f[800010];
	for(int i=1;i<=n;i++) cin>>f[i];
	sort(f+1,f+n+1);
	if(n%2!=0)
	{
		cout<<0;
		return 0;
	}
	cout<<f[n/2+1]-f[n/2];
}

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

int main() {
  int N;
  cin >> N;
  
  vector<int> cards(N);
  for(int i = 0; i < cards.size(); i++) {
  	cin >> cards.at(i);
  }
  
  sort(cards.begin(), cards.end());
  reverse(cards.begin(), cards.end());
  
  int alice;
  int bob;
  
  for(int i = 0; i < cards.size(); i++) {
    // Alice
  	if(i % 2 == 0) {
      alice += cards.at(i);
    } else { 
      bob += cards.at(i);
    }
  }
  
  int ans = alice - bob;
  cout << ans << endl;
}


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

int num[5] = {0},k;

bool solve(){
    for(int i = 0;i < 5;i++){
        for(int j = i + 1;j < 5;j++){
            if(num[j] - num[i] > k){
                return true;
            }
        }
    }
    return false;
}

int main(){
    for(int i = 0;i < 5;i++){
        cin >> num[i];
    }
    cin >> k;
    if(solve()){
        cout << ":(\n";
    }
    else{
        cout << "Yay!\n";
    }
    return 0;
}


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

int main() {
  int a, b, ans;
  cin >> a >> b;
  if (a <= 5)
    ans = 0;
  else if (a <= 12)
    ans = b / 2;
  else
    ans = b;
  cout << ans << endl;
}

Measured memory_bytes: 256
#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); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9


int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i, N){
    cin >> A[i];
  }
  int maxa = -INF, mina = INF, sum = 0;
  REP(i, N){
    maxa = max(maxa, A[i]);
    mina = min(mina, A[i]);
    sum += abs(A[i]);
  }
  vector<int> plus, minus;
  REP(i, N){
    if(A[i] > 0){
      plus.push_back(A[i]);
    }
    else if(A[i] < 0){
      minus.push_back(A[i]);
    }
    else{
      plus.push_back(A[i]);
    }
  }

  if(maxa < 0 || (plus.size() == 1)){
    if(maxa < 0) sum += maxa * 2;
    cout << sum << endl;
    sort(A.begin(), A.end());
    REP(i, N-1){
      cout << maxa << " " << A[i] << endl;
      maxa = maxa - A[i];
    }
  }
  else if(mina >= 0 || (minus.size() == 1)){
    if(mina > 0) sum -= mina * 2;
    cout << sum << endl;
    sort(A.begin(), A.end());
    if(N == 2){
      cout << A[1] << " " << A[0] << endl;
    }
    else{
      FOR(i, 1, N-1){
        cout << mina << " " << A[i] << endl;
        mina = mina - A[i];
      }
      cout << A[N-1] << " " << mina << endl;
    }
  }
  else{
    cout << sum << endl;
    int p = minus[0];
    FOR(i, 1, plus.size()){
      cout << p << " " << plus[i] << endl;
      p -= plus[i];
    }
    int m = plus[0];
    FOR(i, 1, minus.size()){
      cout << m << " " << minus[i] << endl;
      m -= minus[i];
    }
    cout << m << " " << p << endl;
  }
  

  return 0;
}


Measured memory_bytes: 2808
#include <iostream>
#include <sstream>
#include <cstring>
#include <cstdio>
using namespace std;

#define N 500 //スタックのサイズ

int main(void){
	string str;
	
	while(getline(cin, str)) {
		double num[N] = {};
		int n = 0; //スタック内の要素数
		istringstream iss(str);
		string s;
		while(iss >> s) {
		char ch = s[0];
			switch(ch) {
				case '+' : num[n - 2] += num[n - 1];   num[n - 1] = 0;   --n;   break;
				case '*' : num[n - 2] *= num[n - 1];   num[n - 1] = 0;   --n;   break;
				case '/' : num[n - 2] /= num[n - 1];   num[n - 1] = 0;   --n;   break;
				case '-' : {
					if(s.length() == 1) {
						num[n - 2] -= num[n - 1];
						num[n - 1] = 0;
						--n;
					} else {
						int t = 1;
						for(int i = s.length() - 1; i >= 1; --i) {
							num[n] += (s[i] - '0') * t;
							t *= 10;
						}
						num[n] *= -1;
						++n;
					}
					break;
				}
				default  : {
					int t = 1;
					for(int i = s.length() - 1; i >= 0; --i) {
						num[n] += (s[i] - '0') * t;
						t *= 10;
					}
					++n;
					break;
				}
			}
		}
		printf("%.6lf\n", num[0]);
	}
}


Measured memory_bytes: 3284
# 各々の要素が何番目に何回数えられるかを考える。
import sys

input = sys.stdin.buffer.readline

n = int(input())
C = list(map(int, input().split()))
C.sort(reverse=True)
mod = 10 ** 9 + 7
N = n + 5
bikkuri = [0] * N
bikkuri[0] = 1
gyaku = [0] * N
for i in range(1, N):
    bikkuri[i] = (i * bikkuri[i - 1]) % mod
gyaku[N - 1] = pow(bikkuri[N - 1], mod - 2, mod)
for i in range(N - 1, -1, -1):
    gyaku[i - 1] = (gyaku[i] * i) % mod


def comb(n, r):
    if r < 0 or n - r < 0:
        return 0
    return (bikkuri[n] * gyaku[r] * gyaku[n - r]) % mod


ans = 0
for i in range(n):
    ans += (i + 2) * C[i] * pow(2, 2 * n - 2, mod)
    ans %= mod
print(ans)


Measured memory_bytes: 100408
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

C = S()

print(chr(ord(C)+1))

Measured memory_bytes: 3060
//
//  main.cpp
//  APG4b
//
//  Created by 安藤光希 on 2020/03/21.
//  Copyright © 2020 安藤光希. All rights reserved.
//


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

int main() {
    
    int N;
    cin >> N;
    
    
    vector<int> cards(N);
    
    for (int i = 0; i < N; i++){
        cin >> cards.at(i);
    }
    
    sort(cards.begin(), cards.end());
    
    int alice, bob;
    alice = 0;
    bob = 0;
    
    for (int i = 0; i < N; i++){
        if (i % 2 == 0){
            alice += cards.at(i);
        } else {
            bob += cards.at(i);
        }
    }
    
    
    cout << abs(alice - bob) << endl;
    
}

// cin >> N;
// cout << N << endl;

/*
https://atcoder.jp/contests/apg4b/tasks/APG4b_n
 https://atcoder.jp/contests/apg4b/tasks/APG4b_cq
 https://atcoder.jp/contests/practice
 */


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] srgs) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		ArrayList<Integer> a = new ArrayList<>();
		for (int i = 0; i < N; i++)
			a.add(sc.nextInt());
		HashSet<Integer> h=new HashSet<>(a);
		if((a.size()-h.size())%2==0)System.out.println(h.size());
		else System.out.println(h.size()-1);
		sc.close();
	}
}

Measured memory_bytes: 62372
fun main(args: Array<String>) {
    val (n, a,b) = readLine()!!.split(" ").map{i -> i.toInt()}
    var sum = 0
    var ans = 0


    for ( i in 1..n){
        var s = i.toString().split("").filter {it.isNotEmpty()}.map{i -> i.toInt()}

        for( j in 0..s.size-1){
            sum += s[j]

        }
        if( sum >= a && sum <= b) ans += i
        sum = 0
    }
    println(ans)

}

Measured memory_bytes: 44572
#include <iostream>
#include <string>
#include <stack>
#include <cstdlib>
#include <cstdio>
using namespace std;
stack <double> st;
double solve(string);
int main(){
  string str;
  while(cin>>str){
    if(str=="+"||str=="-"||str=="*"||str=="/")
      st.push(solve(str));
    else st.push(atoi(str.c_str()));
    if(getchar()=='\n'){
      printf("%.10f\n",st.top());
      st.pop();
    }
  }
}
double solve(string str){
  double b = st.top(); st.pop();
  double a = st.top(); st.pop();
  if(str=="+")return a+b;
  else if(str=="-")return a-b;
  else if(str=="*")return a*b;
  else if(str=="/")return a/b;
}

Measured memory_bytes: 1248
// https://atcoder.jp/contests/abc152/tasks/abc152_c

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")

const int N_MAX = 2*1e5;

int N;
int P[N_MAX];

void solve() {
  int pi = N + 1;
  int ans = 0;
  REP(i, N) {
    if (P[i] < pi) ans++;
    pi = min(pi, P[i]);
  }
  printf("%d\n", ans);
}

void input() {
  scanf("%d", &N);
  REP(i, N) scanf("%d", P + i);
}

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


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

ll cnt[10][10];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    
    for(int i=1;i<=N;i++){
        int pre = i % 10;
        int top = i;
        while(top >= 10) top /= 10;
        cnt[top][pre]++;
    }
    ll ans = 0;
    for(int i=1;i<=9;i++) for(int j=1;j<=9;j++) ans += cnt[i][j] * cnt[j][i];
    cout << ans << endl;
}

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

// g == 0
// p == 1

int main() {
    string s;
    cin >> s;
    int N, P = 0;
    N = s.length();
    for (int i = 0; i < N; i++) {
        if (s.at(i) == 'p') {
            P++;
        }
    }
    int point;
    point = N/2 - P;
    cout << point << endl;
    return 0;
}


Measured memory_bytes: 512
#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;

int main() {
    int H, W, K; cin >> H >> W >> K;
    char s[H][W];
    vector<int> check(H);
    rep(i, H){
        rep(j, W){
            cin >> s[i][j];
            if(s[i][j] == '#'){
                check[i]++;
            }
        }
    }

    int ans[H][W];
    int num = 1;
    rep(i, H){
        if(check[i] == 0)continue;
        int cnt = 0;
        rep(j, W){
            if(s[i][j] == '#' && cnt != 0){
                ans[i][j] = ++num;
            } else if(s[i][j] == '#'){
                ans[i][j] = num;
                cnt++;
            } else {
                ans[i][j] = num;
            }
        }
        num++;
    }

    int mi = H;
    int ma = -1;
    rep(i, H){
        if(check[i] != 0){
            mi = min(mi, i);
            ma = max(ma, i);
        }
    }

    if(mi != 0){
        for (int i = mi-1; i >= 0; i--){
            rep(j, W){
                ans[i][j] = ans[i+1][j];
            }
        }
    }

    if(ma != H-1){
        for (int i = ma+1; i < H; i++){
            rep(j, W){
                ans[i][j] = ans[i-1][j];
            }
        }
    }

    for (int i = mi+1; i < ma; i++){
        if(check[i] == 0){
            rep(j, W){
                ans[i][j] = ans[i-1][j];
            }
        }
    }

    rep(i, H){
        rep(j, W){
            cout << ans[i][j];
            if(j != W-1)cout << " ";
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 4068
#include <stdio.h>
#include <stdlib.h>

int main(void){
    int N, L;
    scanf("%d %d", &N, &L);
    int val[N], i, j;
    int applepie0 = 0, applepie1;
    int diff_lst[N], argmin;
    int sum, ans;
    for(i = 0; i < N; i++){
        val[i] = L + i;
        applepie0 += val[i];
    }
    for(i = 0; i < N; i++){
        sum = 0;
        for(j = 0; j < N; j++){
            sum += (i == j) ? 0 : val[j];
        }
        diff_lst[i] = abs(applepie0 - sum);
        if(i == 0) argmin = 0;
        else if(diff_lst[i] < diff_lst[argmin]){
            argmin = i;
        }
    }
    ans = 0;
    for(i = 0; i < N; i++){
        ans += (i == argmin) ? 0 : val[i];
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 128
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def gcd(a, b):
    if a < b:
        a, b = b, a
    while b:
        a, b = b, a % b
    return a


A, B, K = map(int, input().split())
cnt = 0
gc = gcd(A, B)

ans = []
cnt = 0
for i in reversed(range(1, gc+1)):
    if A % i == 0 and B % i == 0:
        cnt += 1
    if cnt == K:
        print(i)
        break


Measured memory_bytes: 3064
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
 
def main():
  n = int(input())
  d,x = map(int,input().split())
  
  a = [int(input()) for _ in range(n)]
  #cnt = 0
  ans = 0
  for i in range(n):
    j = 0
    cnt = 0
    while 1 + a[i]*j <= d:
      j += 1
      cnt += 1
    #print(j,cnt)
    ans += cnt
  print(ans + x)
if __name__ == '__main__':
  main()

Measured memory_bytes: 3064
#include <stdio.h>

typedef struct{
  char name[11];
  int time;
}process;

int main(){
  long long  n, q, i, j, sp, ep, stime = 0;
  process p[520000];
  scanf("%lld%lld", &n, &q);
  for(i = 0; i < n; ++i) scanf("%s%d", p[i].name, &p[i].time);

  sp = 0; ep = n - 1;
  while(sp <= ep){
    if(p[sp].time > q){
      stime += q;
      p[sp].time -= q;
      p[++ep] = p[sp];
    }
    else{
      stime += p[sp].time;
      printf("%s %lld\n", p[sp].name, stime);
    }
    sp++;
  }
  //  for(i = 0; i < n; ++i) printf("%s %d\n", p[i].name, p[i].time);
  return 0;
}

Measured memory_bytes: 3648
#include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <cstdio>
#include <cctype>
#include <queue>
#include <complex>
#include <climits>

typedef long long ll;

using namespace std;

int n, s, res = 0;

void dfs(int num, int i, int sum){
	if(sum > s || 10 - i < n - num) return ;
	if(num == n){
		if(sum == s){
			res++;
			return ;
		} else {
			return ;
		}
	}
	dfs(num, i+1, sum);
	dfs(num+1, i+1, sum+i);

	return ;
}


int main(void){
	while(cin >> n >> s){
		if(n == 0 && s == 0) break;
		dfs(0, 0, 0);
		cout << res << endl;
		res = 0;
	}

	return 0;
}

Measured memory_bytes: 1160
// --------------
// Tejas Pandey  |
// 11 - 07 - 20  |
// AIsing ABC    |
// --------------

#include <bits/stdc++.h>
using namespace std;
     
#define mod 1000000007
#define vi vector<int>
typedef long long int ll;
     
int main (void){
  //freopen("in.txt","r",stdin);
  //freopen("out.txt","w",stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  int ans = 0;
  for(int i = 1;i <= n;i++){
	int k;
	cin >> k;
	ans += ((k&1)&(i&1));
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 3608
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n;
    cin >>n;
    vector<long long> arr(n);
    for(long long i = 0; i < n; i++)
        cin >>arr[i];
    long long mx = 0;
    for(long long i = 0; i < n; i++){
        mx = max(mx, arr[i]);
        if(abs(mx - arr[i]) >= 2){
            cout <<"No";
            return 0;
        }
    }
    cout <<"Yes";
    return 0;
}


Measured memory_bytes: 1024
H, W, K = map(int, input().split())
s = []
for _ in range(H):
    *row, = map(int, input())
    s.append(row)

ret = H * W
for bits in range(1 << (H - 1)):
    # 水平カットで生成される2枚目以降の開始行
    # 0行目は確定で, 残りのカットを調べる
    # 次の変換が必要
    # [0,H) -> [1,H]

    group = [0] * H
    for j in range(H - 1):
        group[j + 1] = group[j] + (1 if (bits >> j) & 1 else 0)
    # group = [0,0,1,1,1,2,...]

    ctr = [0] * H
    add_v = [0] * H
    c, pc = 0, -1
    cut = bin(bits).count('1')
    while c < W:
        need_cut = False
        for r in range(H):
            g = group[r]
            add_v[g] += s[r][c]
            if ctr[g] + add_v[g] > K:
                need_cut = True
                break

        if need_cut:
            if pc == c:
                cut = H * W
                break
            ctr = [0] * H
            add_v = [0] * H
            cut += 1
            pc = c
            if cut >= ret:
                break
            continue

        for g, _add_v in enumerate(add_v):
            ctr[g] += _add_v
        add_v = [0] * H
        pc = c
        c += 1

    ret = min(ret, cut)

print(ret)


Measured memory_bytes: 46044
using System;
using System.Collections.Generic;

namespace ConsoleApp8
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] nk = Array.ConvertAll(System.Console.ReadLine().Split(' '), long.Parse);
            long[] p = Array.ConvertAll(System.Console.ReadLine().Split(' '),long.Parse);
            long[] c = Array.ConvertAll(System.Console.ReadLine().Split(' '), long.Parse);
            long[] rui1 = new long[nk[0]];
            long ans = -100000000000000000;
            for (int i = 0; i < p.Length; i++)
            {
                p[i] = p[i] - 1;
            }
            for(long i=0;i<nk[0];i++) //スタート位置からの探索
            {
                long j = i;
                long shuu = 0;
                long sum = 0;
                List<long> cl = new List<long>();
                List<long> clr = new List<long>();
                do
                {
                    shuu += c[j];
                    cl.Add(c[j]);
                    if (clr.Count != 0)
                    {
                        clr.Add(clr[clr.Count - 1] + c[j]);
                    }
                    else
                    {
                        clr.Add(c[j]);
                    }
                    j = p[j];
                } while (i != j);

                if(shuu>0)
                {
                    long shuukai = Math.Max((nk[1] / cl.Count)-1,0);
                    
                   for(long k=1;k<= nk[1] - shuukai*cl.Count;k++)
                    {
                        sum = shuu * shuukai;
                        if (k <= clr.Count)
                        {
                            sum += clr[(int)k-1];
                        }
                        else
                        {
                            sum += clr[(int)k - 1- (clr.Count)] + shuu;
                        }
                        ans = Math.Max(sum, ans);
                    }
                }
                else
                {
                    for(long k=1;k<= clr.Count;k++)
                    {
                        sum = clr[(int)k -1];
                        ans = Math.Max(sum, ans);
                    }

                }



            }
            Console.WriteLine(ans);

           
        }
    }
}


Measured memory_bytes: 48736
def f(e)
  a,b,c,d = e
  case 7
  when a+b+c+d
    "#{a}+#{b}+#{c}+#{d}"
  when a+b+c-d
    "#{a}+#{b}+#{c}-#{d}"
  when a+b-c+d
    "#{a}+#{b}-#{c}+#{d}"
  when a+b-c-d
    "#{a}+#{b}-#{c}-#{d}"
  when a-b+c+d
    "#{a}-#{b}+#{c}+#{d}"
  when a-b+c-d
    "#{a}-#{b}+#{c}-#{d}"
  when a-b-c+d
    "#{a}-#{b}-#{c}+#{d}"
  when a-b-c-d
    "#{a}-#{b}-#{c}-#{d}"
  end
end
puts f(gets.chop.split('').map(&:to_i)) + '=7'


Measured memory_bytes: 3836
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int w,h;
char ba[20][20];

int const dx[] = {0,1,0,-1};
int const dy[] = {-1,0,1,0};
int go(int sx, int sy) {
  int ans = 0;
  REP(i,4) {
    int xx = sx+dx[i];
    int yy = sy+dy[i];
    if (xx<0||xx>=w||yy<0||yy>=h) continue;
    if (ba[xx][yy] == '.') {
      ba[xx][yy] = '#';
      ans++;
      ans += go(xx,yy);
    }
  }
  return ans;
}

int main() {
  while(cin >> w >> h, w+h) {
    int sx, sy;
    REP(y,h) {
      REP(x,w) {
        cin >> ba[x][y];
        if (ba[x][y]=='@') {
          sx = x;
          sy = y;
        }
      }
    }
    cout << go(sx,sy)+1 << endl;
    
  }
}

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

int main() {
  int N, K;
  cin >> N >> K;
  int A = 1;
  for (int i = 0; i < N; i++) {
    if (A <= K) {A *= 2;} 
    else {A += K;}
  }
  cout << A << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,r,l) for(int i=(r);i>=(l);--i)
#define pb push_back
using namespace std;
const int maxn=2e5+10;
int n,x,y,u[maxn],v[maxn],dep[maxn],fa[maxn][19],len[maxn],ans;
vector<int> G[maxn],H[maxn];bool vis[maxn],hry[maxn];
void dfs(int u){for(int v:G[u]) if(v^fa[u][0]) dep[v]=dep[u]+1,fa[v][0]=u,dfs(v);}
int lca(int u,int v){
	if(dep[u]<dep[v]) swap(u,v);
	if(dep[u]^dep[v]){int t=dep[u]-dep[v];rep(i,0,18) if(t&(1<<i)) u=fa[u][i];}
	if(u==v) return u;
	per(i,18,0) if(fa[u][i]^fa[v][i]) u=fa[u][i],v=fa[v][i];
	return fa[u][0];
}
int dis(int x,int y){return dep[x]+dep[y]-2*dep[lca(x,y)];}
void dfs2(int u){
	vis[u]=1;
	for(int v:H[u]) if(!vis[v]&&(dep[v]>len[u]+1)) len[v]=len[u]+1,dfs2(v);
}
int main(){
	scanf("%d%d%d",&n,&x,&y);
	rep(i,1,n-1) scanf("%d%d",&u[i],&v[i]);
	rep(i,1,n-1){int u,v;scanf("%d%d",&u,&v);G[u].pb(v);G[v].pb(u);}
	dfs(y);rep(i,1,18) rep(j,1,n) if(fa[j][i-1]) fa[j][i]=fa[fa[j][i-1]][i-1];
	rep(i,1,n-1) 
		if(dis(u[i],v[i])<=2) H[u[i]].pb(v[i]),H[v[i]].pb(u[i]);
		else hry[u[i]]=hry[v[i]]=1;
	dfs2(x);
	rep(i,1,n)
		if(vis[i]&&hry[i]) return puts("-1"),0;
		else if(vis[i]) ans=max(ans,dep[i]<<1);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 48384
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

class Vec2;

double SqrMagnitude(const Vec2& v);

double Magnitude(const Vec2& v);

double Dot(const Vec2& v1, const Vec2& v2);


struct Vec2 {
    double x, y;
    Vec2() = default;
    Vec2(double in_x, double in_y)
        : x {in_x}, y {in_y} {};
    Vec2(const Vec2&) = default;
    Vec2(Vec2&&) = default;

    Vec2 normalized() {
        double mag = Magnitude(*this);
        return {x /= mag, y /= mag};
    }

    Vec2 operator-() {
        return {-x, -y};
    }

    Vec2 operator+(const Vec2& rhs) {
        return {x + rhs.x, y + rhs.y};
    }

    Vec2 operator-(const Vec2& rhs) {
        return {x - rhs.x, y - rhs.y};
    }

    Vec2 operator*(double rhs) {
        return {x * rhs, y * rhs};
    }

    Vec2 operator/(double rhs) {
        return {x / rhs, y / rhs};
    }

    Vec2& operator+=(const Vec2& rhs) {
        x += rhs.x;
        y += rhs.y;
        return *this;
    }

    Vec2& operator-=(const Vec2& rhs) {
        x -= rhs.x;
        y -= rhs.y;
        return *this;
    }

    Vec2& operator*=(double rhs) {
        x *= rhs;
        y *= rhs;
        return *this;
    }

    Vec2& operator/=(double rhs) {
        x /= rhs;
        y /= rhs;
        return *this;
    }
};

inline Vec2 operator*(double s, const Vec2& v) {
    return {s * v.x, s * v.y};
}



inline double SqrMagnitude(const Vec2& v) {
    return Dot(v, v);
}

inline double Magnitude(const Vec2& v) {
    return sqrt(SqrMagnitude(v));
}

inline double Dot(const Vec2& v1, const Vec2& v2) {
    return v1.x * v2.x + v1.y * v2.y;
}

int main() {
    Vec2 p1, p2;
    cin >> p1.x >> p1.y >> p2.x >> p2.y;

    Vec2 p_12 {(p2 - p1).normalized()};

    int n;
    cin >> n;

    cout << fixed << setprecision(10);

    for(Vec2 q_in; cin >> q_in.x >> q_in.y;) {
        Vec2 v_p1_q = q_in - p1;
        Vec2 q_proj = p1 + p_12 * Dot(v_p1_q, p_12);

        cout << q_proj.x << ' ' << q_proj.y << '\n';
    }

    return 0;
}

Measured memory_bytes: 3272
N = int(input())
ans = 0
S = [input() for i in range(N)]
S.sort()
A = [0 for j in range(5)]
for i in range(N):
	if S[i][0] == 'M':
		A[0] += 1
	if S[i][0] == 'A':
		A[1] += 1
	if S[i][0] == 'R':
		A[2] += 1
	if S[i][0] == 'C':
		A[3] += 1
	if S[i][0] == 'H':
		A[4] += 1
for i in range(5):
	for j in range(5) [i + 1:5]:
		for k in range(5) [j + 1:5]:
			ans += A[i] * A[j] * A[k]
print(ans)


Measured memory_bytes: 10212
/*
    Life Before Death, Strength Before Weakness, Journey Before Destination
    ------------------------------------------------------------------------
    You don't become great by trying to be great.
    You become great by wanting to do something,
    and then doing it so hard that you become great in the process.
    */
 
    //#pragma comment(linker, ack:200000000")
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #include <bits/stdc++.h>
    using namespace std;
    
    #define TRACE
    
    #ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
      cerr << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
      const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
    #else
    #define trace(...)
    #endif
    
    #define rep(i, n)    for(ll i = 0; i < (n); ++i)
    #define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
    #define repD(i, a, n)  for(ll i = a; i >= (n); --i)
    #define trav(a, x) for(auto& a : x)
    #define all(x) x.begin(), x.end()
    #define sz(x) (int)(x).size()
    #define fill(a)  memset(a, 0, sizeof (a))
    #define fst first
    #define snd second
    //#define mp make_pair
    #define pb push_back
    #define PI           3.141592653589793238462643383279502884197169399  /* pi */
    #define te  ll ti;   cin >> ti;  while(ti--) solve();  
    typedef long double ld;
    typedef long long ll;
    typedef unsigned long long ull;
    typedef pair<ll, ll> pii;
    typedef vector<ll> vi;
    const int maxN = 200100;

    void solve(){
        ll n;
        cin >> n;
        cout << n*(n-1)/2 << endl;
    }
 
    int main() {
      cin.sync_with_stdio(0); cin.tie(0);
      cin.exceptions(cin.failbit);
     /*
      #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
      #endif
     */
      //te
      solve();
      return 0;
    } 


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

void read(int &x) {
    x=0;int f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}

void print(int x) {
    if(x<0) putchar('-'),x=-x;
    if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf double
#define ll long long 

#define pii pair<int,int >
#define vec vector<int >

#define pb push_back
#define mp make_pair
#define fr first
#define sc second

#define data asd09123jdf02i3h

#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)

const int maxn = 1e6+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7;

int main() {
    int a,b,c;read(a),read(b),read(c);
    for(int i=0;i<=1e7;i++) {
        if(a&1||b&1||c&1) return write(i),0;
        // printf("%d %d %d\n",a,b,c);
        int aa=(b+c)/2,bb=(a+c)/2,cc=(a+b)/2;
        a=aa,b=bb,c=cc;
    }
    puts("-1");
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
#include<numeric>
#include<stack>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};

// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------


int main(){
  ll N,K;
  cin >> N >> K;
  vector<ll> H(N);
  for(ll i=0; i<N; i++){
    cin >> H[i];
  }
  ll ans = INF;
  for(ll bit=0; bit<(1LL<<N); bit++){
    if(__builtin_popcount(bit) < K) continue;
    ll sum = 0;
    vector<ll> temp;
    temp = H;
    for(ll i=0; i<N; i++){
      if(bit & (1LL<<i)){
          ll h = temp[i];
          bool changed = false;
          for(ll j=0; j<i; j++){
            if(h <= temp[j]){
              h = temp[j];
              changed = true;
            }
          }
          if(changed){
            temp[i] = h+1LL;
          }
          sum += temp[i] - H[i];
      }
    }
    chmin(ans,sum);
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
    int n;
    cin >> n;
    int c[n-1], s[n-1], f[n-1];
    for(int i=0;i<n-1;i++)cin >> c[i] >> s[i] >> f[i];

    for(int i=0;i<n;i++){
        int ans = 0;
        for(int j=i;j<n-1;j++){
            int tmp = s[j];
            while(ans>tmp)tmp += f[j];
            ans = tmp;
            ans += c[j];
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string S;
    int K;
    cin >> S >> K;
    int a=0;
    char b='1';
    for (int i=0;i<S.length();i++){
        if (S[i]=='1'){
            a=i+1;
        }
        else{
            b=S[i];
            break;
        }
    }
    //cout << a << " " << b << endl;
    if (K<=a){
        cout << 1 << endl;
    }
    else{
        cout << b << endl;
    }
    return 0;
}


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

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll init = 100;
    int count = 0;
    ll x;
    cin >> x;
    while(init < x){
        init = init + (1*init)/100;
        //cout << floor(((double)(init)*(double)(1.01))) << " \n";
        count++;
    }
    cout << count << "\n";
    

    return 0;
}

Measured memory_bytes: 3640
N = int(input())
li =[]
for i in range(N):
    s, n = input().split()
    li.append([s, int(n), i+1])
li2 = sorted(li, key=lambda x: x[1], reverse=True)
li3 = sorted(li2, key=lambda x: x[0])
for i in range(N):
    print(li3[i][2])

Measured memory_bytes: 3060
import java.util.Scanner;
 
class Main{
    static Scanner in = new Scanner(System.in);
     public static void main(String[] args){
         int i = Integer.parseInt(in.nextLine());
         String s = in.nextLine();
         int max = 0;
         i = 0;
         for(char c : s.toCharArray()){
             if(c == 'I'){
                 i++;
             }else{
                 i--;
             }
             max = Math.max(max, i);
         }
         System.out.println(max);
     }
}

Measured memory_bytes: 21972
#include<stdio.h>
int main(void)
{
 int W,H,x,y,r;
 scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
 if((x >= r && x <= W-r) && (y >= r && y <= H-r))
  printf("Yes\n");
 else
  printf("No\n");
 return 0;
}



Measured memory_bytes: 2692
r1,c1,r2,c2 = map(int, input().split())
mod = int(1e9+7)

# f(i,j) = cmb(i+j,i)

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

def init_cmb(Nmax):
    #mod = 10**9+7 #出力の制限
    g1 = [1, 1] # 元テーブル
    g2 = [1, 1] # 逆元テーブル
    inverse = [0, 1] #逆元テーブル計算用テーブル

    for i in range(2, Nmax + 1):
        g1.append((g1[-1] * i) % mod)
        inverse.append((-inverse[mod % i] * (mod//i)) % mod)
        g2.append((g2[-1] * inverse[-1]) % mod)
    return g1, g2
  
g1, g2 = init_cmb(max(r1,r2) + max(c1,c2) + 10)

def solve(r1,c1,r2,c2):
  def f(r,c):
    return cmb(r+c,min(r,c))
  
  res = 0
  # S[r2,c2] - S[r2,c1-1] - S[r1-1,c2] + S[r1-1,c1-1]
  # S[r2,c2] = cmb(r2,0) + cmb(r2+1,1) + ... + cmb(r2+c2, c2)
  r2,c2 = r2, c2
  res += f(r2,c2)
  res -= f(r2,c1)
  res -= f(r1,c2)
  res += f(r1,c1)
  
  """
  for c in range(0,c2+1):
    res += (c+1) * cmb(r2+c, c)
    res %= mod
  for c in range(0,c1):
    res -= (c+1) * cmb(r2+c, c)
    res %= mod
  for r in range(0,r1):
    res -= (r+1) * cmb(c2+r,r)
    res %= mod
  for r in range(0,r1):
    res += (r+1) * cmb(c1-1+r,r)
    res %= mod
  """  
  return res % mod

def solve2(r1,c1,r2,c2):
  res = 0
  for r in range(r1,r2+1):
    for c in range(c1,c2+1):
      res += cmb(c+r,c)
      res %= mod
  return res

#print(solve(r1,c1,r2,c2))
print(solve(r1,c1,r2+1,c2+1))
#print(solve2(r1,c1,r2,c2))

Measured memory_bytes: 246296
#include <vector>
#include <iostream>
#define int long long
using namespace std;

const int N = 50, MOD = 1e9 + 7;

int n, k, a[N][N] = {0};

struct Matrice {
  int val[N][N];
  
  int mulLenByTwo() {
    int res[n][n];
  	for(int i = 0; i < n; i++)
      for(int j = 0; j < n; j++)
        res[i][j] = 0;
    for(int i = 0; i < n; i++)
      for(int j = 0; j < n; j++)
        for(int k = 0; k < n; k++) {
          res[i][k] += val[i][j] * val[j][k];
          res[i][k] %= MOD;
        }
  	for(int i = 0; i < n; i++)
      for(int j = 0; j < n; j++)
        val[i][j] = res[i][j];
  }
  
  int incLen() {
    int res[n][n];
  	for(int i = 0; i < n; i++)
      for(int j = 0; j < n; j++)
        res[i][j] = 0;
    for(int i = 0; i < n; i++)
      for(int j = 0; j < n; j++)
        for(int k = 0; k < n; k++) {
          res[i][k] += val[i][j] * a[j][k];
          res[i][k] %= MOD;
        }
  	for(int i = 0; i < n; i++)
      for(int j = 0; j < n; j++)
        val[i][j] = res[i][j];
  }
};
  
Matrice mat;

void setLen(int len) {
  if(len == 1)
    return;
  setLen(len / 2);
  mat.mulLenByTwo();
  if(len % 2 == 1)
    mat.incLen();
}

int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  
  cin >> n >> k;
  for(int i = 0; i < n; i++)
    for(int j = 0; j < n; j++) {
      cin >> a[i][j];
      mat.val[i][j] = a[i][j];
    }
  
  setLen(k);
  
  int sum = 0;
  for(int i = 0; i < n; i++)
    for(int j = 0; j < n; j++)
      sum = (sum + mat.val[i][j]) % MOD;
  cout << sum;
}

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

int a[10000];

signed main(){

  int H,W,N;
  cin >> H >> W >> N;
  for(int i = 0; i < N; i++){
    cin >> a[i];
  }

  int ans[H][W] = {};
  int h = 0,w = 0,cnt = 0;
  for(int i = 0; i < N; i++){
    for(int j = 0; j < a[i]; j++){
      if(h%2 == 0){
        ans[h][w++] = i+1;
        cnt++;
        if(cnt%W == 0) h++,w = 0;
      }
      else {
        ans[h][(W-1)-w] = i+1;
        w++;
        cnt++;
        if(cnt%W == 0) h++,w = 0;
      }
    }
  }

  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cout << ans[i][j] << " ";
    }
    cout << endl;
  }

  return 0;
}


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

//-----------------------------------LIBRARY OF INPUT-----------------------------------
void reader(int *x) {
	int k = getchar_unlocked(); *x = k - '0';
	while (true) {
		k = getchar_unlocked();
		if (k < '0' || k > '9') break;
		*x = ((*x) << 1) + ((*x) << 3) + k - '0';
	}
}

#pragma warning(disable:4996)
int n, m, q, dist[110000], mark[110000], u[210000], v[210000];
vector<pair<int, int>>x[110000], y[110000], z[110000]; bool used[210000];
bool isgood(int f) {
	for (int i = 0; i < z[f].size(); i++) {
		if (mark[z[f][i].first] == 0 && used[z[f][i].second] == false)return true;
	}
	return false;
}
int main() {
	reader(&n); reader(&m); reader(&q); queue<int>Q;
	for (int i = 0; i < m; i++) {
		int a = 0, b = 0;
		reader(&a);
		reader(&b);
		u[i + 1] = a; v[i + 1] = b;
		x[a].push_back(make_pair(b, i + 1)); x[b].push_back(make_pair(a, i + 1));
	}
	Q.push(1); for (int i = 1; i <= n; i++)dist[i] = 999999; dist[1] = 0;
	while (!Q.empty()) {
		int a1 = Q.front(); Q.pop();
		for (int i = 0; i < x[a1].size(); i++) {
			if (dist[x[a1][i].first] > dist[a1] + 1) { dist[x[a1][i].first] = dist[a1] + 1; Q.push(x[a1][i].first); }
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < x[i].size(); j++) {
			if (dist[i] < dist[x[i][j].first]) { y[i].push_back(x[i][j]); }
			if (dist[i] > dist[x[i][j].first]) { z[i].push_back(x[i][j]); }
		}
	}
	int cnt = 0;
	for (int i = 0; i < q; i++) {
		int a = 0;
		reader(&a);
		used[a] = true;
		int E1 = u[a], E2 = v[a];
		if (dist[E1] == dist[E2]) { cnt += 0; }
		else {
			int a1 = 0; if (dist[E1] < dist[E2])a1 = E2; else a1 = E1;
			if (isgood(a1) == false && mark[a1] == 0) {
				queue<int>Q; Q.push(a1); cnt++; mark[a1] = 1;
				while (!Q.empty()) {
					int a2 = Q.front(); Q.pop();
					for (int j = 0; j < y[a2].size(); j++) {
						if (mark[y[a2][j].first] == 0 && isgood(y[a2][j].first) == false) {
							mark[y[a2][j].first] = 1; Q.push(y[a2][j].first); cnt++;
						}
					}
				}
			}
		}
		printf("%d\n", cnt);
	}
	return 0;
}

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

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            var a = cin.ReadInt;
            var b = cin.ReadInt;
            WriteLine(a * b % 2 == 0 ? "Even" : "Odd");
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 11348
#include <stdio.h>

int n;
int A[25];


int solve(int i, int m) {
    if (m == 0) {
        return 1;
    }
    if (i >= n)
        return 0;
    int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
    return res;
}

int main() {
    int q;
    int B[205];
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }
    scanf("%d", &q);
    for (int i = 0; i < q; i++) {
        scanf("%d", &B[i]);
    }
    for (int i = 0; i < q; i++) {
        if (solve(0, B[i])) {
            printf("yes\n");
        }
        else {
            printf("no\n");
        }
    }
    return 0;
}


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

#define Bye return 0
#define ll long long

using namespace std;
ll s;
const ll M = 1e9+7;

vector<ll> dp (2010, -1);

int rec(ll sum){
    if(sum>s) return 0;
    if(sum == s) return 1;

    if(dp[sum] != -1) return dp[sum];

    ll total = 0;
    for (ll i=3; i<=s; i++)
        if(i+sum<=s)
            total = (total + rec((sum+i)%M))%M;

    return (dp[sum] = total);
}

void solve(){
    cin>>s;
    ll res = rec(0);
    cout<<res<<endl;
}

int main(){
    solve();
    Bye;
}

Measured memory_bytes: 3656