akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

signed main(){
    int n,m;
    cin>>n>>m;
    vector<int> a(m),b(m);
    rep(i,m)cin>>a[i]>>b[i];
    
    int start = 0;
    rep(i,m)start += a[i]+1;
    
    vector<int> im(n);
    rep(i,m){
        int pos = b[i]-a[i]-1;
        while(pos<n){
            im[pos] -= b[i];
            pos+=b[i];
        }
    }
    rep(i,im.size()-1){
        im[i+1] += im[i];
    }
    
    rep(i,n){
        cout<<start+im[i]<<endl;
        start += m;
    }
}



Measured memory_bytes: 5132
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
    FASTINOUT;
    int h1,m1,h2,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;
    int time=(h2-h1)*60+(m2-m1);
    cout<<max(0,time-k)<<endl;
    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++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; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
// 多倍長
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using boost::rational;
using boost::multiprecision::cpp_int;

const double PI = acos(-1);
const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

 

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;


vector<string> split(const string &s, char delim) {
    vector<string> elems;
    string item;
    for (char ch: s) {
        if (ch == delim) {
            if (!item.empty())
                elems.push_back(item);
            item.clear();
        }
        else {
            item += ch;
        }
    }
    if (!item.empty())
        elems.push_back(item);
    return elems;
}



int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n;
    cin >> n;
    int count = 0;
    rep(i, n){
        int a,b;
        cin >> a >> b;
        if(count >= 3){
            print("Yes");
            return 0;
        }
        if(a == b) count++;
        else {
            if(count >= 3){
                print("Yes");
                return 0;
            } else {
                count = 0;
            }
        }
        if(count >= 3){
                print("Yes");
                return 0;
        }
    }
    print("No");
    


}


Measured memory_bytes: 3612
import string
slice_num = int(input())
string_dic = list(input())

omoji = [chr(i) for i in range(65,65+26)]




for i in range(len(string_dic)):
    string_dic[i] = omoji[(omoji.index(string_dic[i])+slice_num)%26]


for i in range(len(string_dic)):
    print(string_dic[i],end="")

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	int n, m; cin >> n >> m;
	map<int, int> dp;
	dp[0] = 0;
	for (int i=0; i<m; i++) {
		int a, b; cin >> a >> b;
		
		int k = 0;
		for (int j=0; j<b; j++) {
			int c; cin >> c;
			k += pow(2, c - 1);
		}

		for (auto p : dp) {
			int nk = k | p.first;
			if (dp.count(nk)) dp[nk] = min(dp[nk], p.second + a);
			else dp[nk] = p.second + a;
		}
	}
	int ret = -1;
	int l = pow(2, n) - 1;
	if (dp[l]) ret = dp[l];
	cout << ret << endl;
	return 0;
}

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


bool prime(int n){
    if(n == 1){
        return false;
    }
    else{
        for(int i=2; i*i<=n; i++){
            if(n % i == 0){
                return false;
            }
        }
        return true;
    }
}


int main(){
    int x;
    cin >> x;
    for(int i=x; 1; i++){
        if(prime(i)){
            cout << i << endl;
            return 0;
        }
    }
}

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

int main(){

  int n;
  cin>>n;
  vector<int64_t> a(n);
  for(int i=0;i<n;++i) cin>>a[i];

  sort(a.begin(),a.end(),greater<int>());
  if(a[0]%2==0){
    int64_t MIN=1000000007;
    int ind=1;
    for(int i=1;i<n;++i){
      if(abs(a[i]-(a[0]/2))<MIN){
        MIN=abs(a[i]-(a[0]/2));
        ind=i;
      }
    }
    cout<<a[0]<<" "<<a[ind]<<endl;
  }
  else{
    int64_t MIN=1000000007;
    int ind=1;
    for(int i=1;i<n;++i){
      if(min(abs(a[i]-(a[0]/2)),abs(a[i]-(a[0]/2)-1))<MIN){
        MIN=min(abs(a[i]-(a[0]/2)),abs(a[i]-(a[0]/2)-1));
        ind=i;
      }
    }
    cout<<a[0]<<" "<<a[ind]<<endl;
  }
}

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

int main() {
	long long n,m,i,j,k,ans;
	cin >> n;
	ans=n-1;
	for(i=1; i*i<=n; i++){
		if(n%i==0){
			ans =min(ans,i+n/i-2);
		}
	}
	cout << ans;
	return 0;
}

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

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
//using pair<T1, T2> = p12;

//container
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
#define ALL(v) v.begin(),v.end()

//repetition
#define REP(n) for(int i=0; i<(n); i++)
#define REPj(n) for(int j=0; j<(n); j++)
#define REPinit(i,a,n) for(int i=(a); i<(n); i++)
#define REPinitj(j,a,n) for(int j=(a); j<(n); j++)

//algorithm
//#define SORT(c) sort((c).begin(),(c).end())

//constant

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//Optimizer
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/* 
	add utility Algorithm
*/

set<int> st[26];
int type[30000];
// type 2
int l[30000];
int r[30000];
// type 1
int idx[30000];
char c[30000];

int main(int argc, char const *argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N; cin >> N;
    string S; cin >> S;
    int Q; cin >> Q;

    REPinit(i, 0, Q) {
        cin >> type[i];
        if (type[i] == 1) {
            cin >> idx[i] >> c[i];
        }
        else {
            cin >> l[i] >> r[i];
        }
    }

    string initial = S;
    REPinit(i, 0, 26) {
        st[i].clear();
        st[i].insert(N);
    }

    REPinit(i, 0, N) {
        // i文字目のアルファベットの番号をインデックスとして、iを挿入
        // ababであれば、s[0] = (0,2,4)、s[1] = (1,3,4)
        st[(int)(S[i] - 'a')].insert(i);
    }

    REPinit(i, 0, Q) {
        if (type[i] == 1) {
            // 文字置換
            st[(int)(S[idx[i] - 1] - 'a')].erase(idx[i] - 1);
            S[idx[i] - 1] = c[i];
            st[(int)(S[idx[i] - 1] - 'a')].insert(idx[i] - 1);
        }
        else {
            int ANS = 0;
            REPinit(j, 0, 26) {
                auto itr = st[j].lower_bound(l[i] - 1);
                if (*itr <= r[i] - 1) ANS++;
            }
            cout << ANS << '\n';
        }
    }

    return 0;
}


Measured memory_bytes: 25116
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <cmath>
using namespace std;

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


const int BIG_NUM = 1e8;
const ll INF = 1000000000000000000;

int main() {

	ll a;
	string b;
	cin >> a >> b;


	int c =0;
	for (int i = 0; i < 4; i++) {
		if (i == 1) {
			continue;
		}

		if (i < b.length()) {

			c = c * 10 + (b[i] - '0');
		}
		else {
			c = c * 10;
		}
	}
	
	

	ll ans = (a * c) / 100;
	cout << ans << endl;

	

}

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

int main() {
  int h, w;
  cin >> h >> w;
  int c[50][50];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      char x;
      cin >> x;
      c[i][j] = x - '0';
    }
  }
  int dp[50][50];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) dp[i][j] = 1000000000;
  }
  dp[0][0] = c[0][0];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (i > 0) dp[i][j] = min(dp[i][j], dp[i - 1][j] + c[i][j]);
      if (j > 0) dp[i][j] = min(dp[i][j], dp[i][j - 1] + c[i][j]);
    }
  }
  cout << dp[h - 1][w - 1] << endl;
}

Measured memory_bytes: 3128
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define f first
#define s second
#define pb push_back
#define fix  cout<<std::fixed;
#define mk make_pair
#define N 100005
#define mod 1000000007
#define time  cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
#define IOS        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int main()
{
 ll n,m,y;cin>>n>>m>>y;
 ll c[n],po[m]={0};ll a[n][m];
// for(int i=0;i<m;i++)cout<<po[i]<<" "; 

  for(int i=0;i<n;i++)
 { cin>>c[i];
  for(int j=0;j<m;j++)cin>>a[i][j];
 }  
ll sum=0,f=0;
ll ans=1e18;

for(int j=0;j<(1<<n);j++)
  {int o=0;sum=0;f=0;
    memset(po,0,sizeof(po));
     for(int i=1;i<(1<<n);i=i*2)
     {
        if(j&i)
        {
          for(int k=0;k<m;k++)po[k]+=a[o][k];

          sum+=c[o];
        }
++o;
     }
  //   cout<<sum<<endl;
     for(int i=0;i<m;i++)
     {
      if(po[i]>=y)f++;
     }
     if(f==m && sum<ans)ans=sum; 
  }
if(ans==1e18)cout<<"-1";
else cout<<ans;
}

Measured memory_bytes: 3624
#include "bits/stdc++.h"

#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef long long ll;

void solve() {
#ifdef _WIN32
	istream &cin = ifstream("input.txt");
#endif
	int n;
	cin >> n;
	rep(i, n) {
		vector<int> v1(101), v2(101);
		string s1, s2;
		cin >> s1 >> s2;

		rep(j, s1.size()) v1[j] = s1[s1.size() - j - 1] - '0';
		rep(j, s2.size()) v2[j] = s2[s2.size() - j - 1] - '0';
		
		rep(j, 100) {
			v1[j] += v2[j];
			if (v1[j] >= 10) {
				v1[j] -= 10;
				v1[j + 1]++;
			}
		}
		int digit = 0;
		for (int j = 100; j >= 0; j--) {
			if (v1[j] != 0) {
				digit = j;
				break;
			}
		}
		if (digit >= 80) cout << "overflow" << endl;
		else {
			for (int j = digit; j >= 0; j--) cout << v1[j];
			cout << endl;
		}
	}

}




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


	solve();
	//system("PAUSE");
	return 0;
}

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

int main(void){
    int n, p;
    std::cin >> n >> p;

    long long ans;
    bool check_odd_number = false;

    std::vector<int> a(n);
    for(int i = 0; i < n; i++){
        int b;
        std::cin >> b;
        a[i] = b;
        if(b % 2 == 1) check_odd_number = true;
    }

    if(!check_odd_number && p == 0){
        ans = std::pow(2, n);
        std::cout << ans << std::endl;
        return 0;
    }
    else if(!check_odd_number && p == 1){
        ans = 0;
        std::cout << ans << std::endl;
        return 0;
    }

    //少なくとも１つは奇数がある
    ans = std::pow(2, n-1);
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-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 main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b; cin >> a >> b;
    cout << 6-a-b << endl;
}

Measured memory_bytes: 256
function main(input) {
  const [a, b, c] = input.trim().split(" ").map(n => Number(n));
  const max = Math.max(...[a, b, c]);
  let target = max;
  if (3*max % 2 !== (a+b+c)%2) {
    target++;
  }
  const result = (target*3 - (a+b+c))/2;
  console.log(result);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <cmath>
#include <tuple>
#include <map>
#include <unordered_map>
#include <queue>
using namespace std;
typedef long long ll;

int main(int argc, char *argv[])
{
	int n, m, i, j;
	cin >> n >> m;
	int tmpa, tmpb;
	vector<int> height(n);
	vector< vector<int> > path(n);
	int target, answer;
	bool heighest;

	for (i = 0; i < n; i++)
		cin >> height[i];

	for (i = 0; i < m; i++) {
		cin >> tmpa >> tmpb;
		tmpa--;
		tmpb--;
		path[tmpa].push_back(tmpb);
		path[tmpb].push_back(tmpa);
	}
	answer = 0;

	for (i = 0; i < n; i++) {
		heighest = true;
		target = height[i];
		for (j = 0; j < path[i].size(); j++) {
			if (target <= height[path[i][j]]) {
				heighest = false;
				break;
			}
		}
		if (heighest)
			answer++;
	}

	cout << answer << endl;
	return 0;
}


Measured memory_bytes: 8804
"""import sys
input = sys.stdin.readline()"""
n,m=map(int,input().split())
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)
ab=[]
for i in range(m):
    a,b=map(int,input().split())
    ab.append([a,b])
cnt=0
for i in range(m):
    uf=UnionFind(n+1)
    for j in range(m):
        a=ab[j][0]
        b=ab[j][1]
        if i==j:continue
        uf.union(a,b)
    if not uf.same(ab[i][0],ab[i][1]):
        cnt+=1
print(cnt)


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

using namespace std;

typedef long long ll;

ll mod=1e9+7;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll h,w;
  cin>>h>>w;
  char a[h+1][w+1];
  ll dp[h+1][w+1];
  for(ll i=1;i<=h;i++)
  {
  for(ll j=1;j<=w;j++)
  {
  cin>>a[i][j];
  dp[i][j]=0;
  }
  }
  for(ll i=0;i<=w;i++)
  {
  dp[0][i]=0;
  }
  for(ll i=0;i<=h;i++)
  {
  dp[i][0]=0;
  }
  dp[1][1]=1;
  for(ll i=1;i<=h;i++)
  {
  for(ll j=1;j<=w;j++)
  {
  if(i==1&&j==1) continue;
  if(a[i][j]=='#') dp[i][j]=0;
  else dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
  }
  }
  cout<<dp[h][w];
}


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

using namespace std;
const int maxn = 1e6 + 5;

int n, k;
int a[maxn];

bool check(int mid) {
    int num = 0;
    for (int i = 1; i <= n; i++) {
        num += a[i] / mid + (a[i] % mid != 0) - 1;
        if (num > k) return false;
    }
    return true;
}

int main() {
    int l = 1, r, mid;
    r = 0;
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        r = max(r, a[i]);
    }
    while (l < r) {
        mid = l + r >> 1;
        if (check(mid)) r = mid;
        else l = mid + 1;
    }
    printf("%d\n", l);
    return 0;
}


Measured memory_bytes: 4600
# https://atcoder.jp/contests/abc065/tasks/arc076_b

from heapq import heappush, heappop

class UnionFind(object):
    def __init__(self, n):
        self.n = n
        self.par = [-1] * n
    
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if x == y:
            return False
        else:
            if self.par[x] > self.par[y]:
                x, y = y, x
            self.par[x] += self.par[y]
            self.par[y] = x
            return True

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.par[self.find(x)]

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.par) if x < 0]

    def group_count(self):
        return len(self.roots())

N = int(input())
X, Y = [], []
Loc = []
for n in range(N):
    xi, yi = map(int, input().split())
    X.append((xi, n))
    Y.append((yi, n))
    Loc.append((n, xi, yi))

# LocX = sorted(Loc, key=lambda x: x[1])
# LocY = sorted(Loc, key=lambda x: x[2])

# edges = set({})
# for i in range(1, N - 1):
#     es = [(LocX[i-1][0], LocX[i][0]), \
#           (LocX[i+1][0], LocX[i][0]), \
#           (LocY[i-1][0], LocY[i][0]), \
#           (LocY[i+1][0], LocY[i][0])]
#     for ii, jj in es:
#         if ii < jj:
#             edges.add((ii, jj))

# print(N)
# print(edges)
# pedges = [(min(abs(X[i] - X[j]), abs(Y[i] - Y[j])), i, j) for (i, j) in edges] 
# pedges.sort()
# print(pedges)

# uf = UnionFind(N)
# total = 0
# for (cost, i, j) in pedges:
#     if uf.unite(i, j):
#         total += cost
# print(total)


# Xでソートして隣接，Yでソートして隣接を辺とみなす
edges = []
X.sort()
Y.sort()
for i in range(N - 1):
    wxi = abs(X[i][0] - X[i + 1][0])
    wyi = abs(Y[i][0] - Y[i + 1][0])
    heappush(edges, (wxi, X[i][1], X[i + 1][1]))
    heappush(edges, (wyi, Y[i][1], Y[i + 1][1]))

# Kruskal
uf = UnionFind(N)
cost = 0
while len(edges) > 0:
    (w, u, v) = heappop(edges)
    if uf.unite(u, v):
        cost += w
print(cost)

Measured memory_bytes: 141068
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)

left = -1
right = 10**12 + 1
while right - left > 1:
    mid = (left + right) // 2
    cnt = 0
    for i in range(N):
        tmp = max(A[i] - mid // F[i], 0)
        cnt += tmp
    if cnt <= K:
        right = mid
    else:
        left = mid
print(right)


Measured memory_bytes: 113892
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define fast ios::sync_with_stdio(false); cin.tie(NULL);
const double eps = 1e-6;

/////////////////////////////////////////////

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

////////////////////////////////

#define int long long
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

int fact[N];

void start(){

	fact[0] = 1;
	for(int i = 1 ; i < N ; ++i)
		fact[i] = (fact[i-1]*i)%mod;
}

int power(int a , int n , int mod){

    int res = 1;
    while(n){

        if(n&1)
            res*=a , res%=mod ;
        a*=a;
        a%=mod;
        n/=2;
    }

    return res;
}

int ncr(int n , int r){

	int res = fact[n];

	int val = fact[r]*fact[n-r];
	val%=mod;
	res*=power(val , mod-2 , mod);
	res%=mod;
	return res;
}

int get(int n , int k){

	int res = ncr(n , k);

	int rem = n - k;
	int nn = n - rem;
	//debug(nn+rem-1 , nn);
	int val = ncr(nn + rem - 1 , nn);
	res*=val;
	res%=mod;

	return res;
}

void solve(){

	int n , k;
	cin>>n>>k;

	start();

	if(k >= n )
		k = n - 1;

	int ans = 1;

	for(int i = 1 ; i <= k ; ++i){

		ans += get(n , i);
		ans%=mod;
	}

	cout<<ans<<endl;
}

signed main(){

    fast;
    int t = 1;
    //cin>>t;
    for(int i = 1 ; i <= t; ++i){

    	solve();
    }
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
#include <cmath>

using namespace std;

int main(){
 int a;
  cin >> a;
  int b[a],c[a];
  int sit =0;
  for(int i=0; i< a; i++){
  	cin >> b[i] >> c[i];
    sit += c[i] -b[i] +1;
  }
  
  
  
  cout << sit << endl;
 
  return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int> A(N);
  for (auto& e : A) {
    cin >> e;
  }
  int64_t cur = 1000;
  for (int i = 0; i < N - 1; i++) {
    int j = i + 1;
    while (j < N && A[j - 1] < A[j]) {
      j++;
    }
    j--;
    if (A[i] < A[j]) cur = (cur / A[i]) * A[j] + (cur % A[i]);
    i = j;
  }
  cout << cur << '\n';
  return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A, B, C, D, N, ans=0;
    vector<int> V(3);
    char tmp, tmp2;
    string S, S2, S3;
    bool flag=true;
    
    cin >> A>>B>>C>>D;
    
    // ans = N/3;
    // cout << S[0]<<S2[1] <<S3[2]<< endl;

    // if(S[1]==S[2] &&(S[0]==S[1] | S[2]==S[3]))
    // 	cout << "Yes" <<endl;
    // else
    // 	cout << "No" <<endl;

    // string S;
    // cin >>S;
    // cout << S + "pp"<<endl;
    if(A+B>=C)
       puts("Yes");
       else
    	puts("No");
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<"!"<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
ll dp[211111];
vvi nxt(211111);
vi po(211111);
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  vi A(n);
  for(int i=0;i<n;i++){
    cin>>A[i];
    nxt[A[i]].pb(i);
  }
  dp[0]=1;
  for(int i=0;i<211111;i++)nxt[i].pb(n);
  for(int i=0;i<n;i++){
    po[A[i]]++;
    ll nx=nxt[A[i]][po[A[i]]];
    if(i!=0)dp[i]+=dp[i-1];
    dp[i]%=MOD;
    if(nx==n){
      /*   dp[nx]+=dp[i];
	   dp[nx]%=MOD;*/
    }else{
      if(nx-i==1){/*
	dp[nx]+=dp[i];
	dp[nx]%=MOD;*/
      }else{
	dp[nx]+=dp[i];
	dp[nx]%=MOD;
      }
    }
    
  }
  //for(int i=0;i<n;i++)cout<<dp[i]<<" ";
  cout<<dp[n-1]%MOD<<endl;
  return 0;
}


Measured memory_bytes: 18688
N, X = map(int, input().split())
pattis = [1]
buns = [0]

for i in range(N):
    pattis.append(pattis[i] * 2 + 1)
    buns.append(buns[i] * 2 + 2)

# print(pattis)
# print(buns)

def dfs(n , x):
    ## 終了条件
    if n == 0:
        return 1


    ## 0次元バーガー前に終了する条件
    burger_high = pattis[n] + buns[n]
    if x == 1:
        return 0
    elif x == burger_high:
        return pattis[n - 1] * 2 + 1
    elif x == burger_high // 2 + 1:
        return pattis[n - 1] + 1

    ## 再帰的に探索を続ける
    if 1 < x <= burger_high // 2:
        return dfs(n - 1, x - 1)
    elif burger_high // 2 < x < burger_high:
        return dfs(n - 1, x - (pattis[n - 1] + buns[n - 1] + 2)) + pattis[n - 1] + 1


print(dfs(N, X))

Measured memory_bytes: 3064
#include<iostream>
#include<set>
#include<string>
#include<algorithm>

using namespace std;

int solve(string str)
{
    int size = str.size();

    set<string> ans{};
    for(int i = 1; i < size; i++)
    {
        string front = str.substr(0, i);
        string back = str.substr(i);

        string r_front = front;
        string r_back = back;

        reverse(r_front.begin(), r_front.end());
        reverse(r_back.begin(), r_back.end());


        ans.insert(front + back);        
        ans.insert(back + front);        
        ans.insert(front + r_back);        
        ans.insert(r_back + front);        
        ans.insert(r_front + back);        
        ans.insert(back + r_front);        
        ans.insert(r_front + r_back);        
        ans.insert(r_back + r_front);        

    }

    return ans.size();
}

int main()
{
    int n{ 0 };
    cin >> n;

    for(int i = 0; i < n; i++)
    {
        string str{ "" };
        cin >> str;
        cout << solve(str) << endl;
    }

    return 0;
}

Measured memory_bytes: 3204
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<i64>();
    let (n, k) = (v[0] as usize, v[1]);
    let a = read_vec::<i64>();
    let a_sum = a.iter().sum::<i64>();
    let mut cands = vec![];
    for i in 1.. {
        if i * i > a_sum {
            break;
        }
        if a_sum % i == 0 {
            cands.push(i);
            cands.push(a_sum / i);
        }
    }
    cands.sort();
    cands.dedup();
    cands.reverse();

    for cand in cands {
        if ok(&a, cand, k) {
            println!("{}", cand);
            return;
        }
    }
}

fn ok(a: &Vec<i64>, cand: i64, k: i64) -> bool {
    let mut a_clone = a
        .iter()
        .cloned()
        .map(|x| x % cand)
        .filter(|&x| x != 0)
        .collect::<Vec<_>>();
    a_clone.sort();

    if a_clone.is_empty() {
        return true;
    }
    // debug!(a_clone);
    let n = a_clone.len();
    let mut minus_from_left = vec![0; n];
    minus_from_left[n - 1] = cand - a_clone[n - 1];
    for i in (0..n - 1).rev() {
        minus_from_left[i] = minus_from_left[i + 1] + (cand - a_clone[i]);
    }
    let mut accum = 0;
    for i in 0..n - 1 {
        accum += a_clone[i];
        if accum == minus_from_left[i + 1] {
            return accum <= k;
        }
    }
    unreachable!();
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

inline long long read(){
    long long s = 0, w = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9'){
        if (ch == '-') w = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9'){
        s = s * 10 + ch - '0';
        ch = getchar();
    }
    return s * w;
}

int gcd (int x, int y, int z){
    int m = __gcd(x, y);
    int n = __gcd(y, z);
    return __gcd(m, n);
}
long long k, ans;
int main(){
    k = read();
    for (int a = 1; a <= k; a++){
        for (int b = 1; b <= k; b++){
            for (int c = 1; c <= k; c++){
                ans += gcd(a, b, c);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
n = int(input())
H = list(map(int, input().split()))

ans = "Yes"
for i in reversed(range(n-1)):
    if H[i] <= H[i+1]:
        continue
    elif H[i] - H[i+1] == 1:
        H[i] -= 1
    else:
        ans = "No"
        break
    
print(ans)

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

struct node{
    // parent　親ノード
    // left 左の子ノード
    // right 右の子ノード
    int parent = -1;
    int left = -1;
    int right = -1;
};

vector<node> tree(MAX);

void preorder(int id, int depth){
    cout << " " <<  id;
    if(tree.at(id).left != -1){
        preorder(tree.at(id).left, depth + 1);
    }
    if(tree.at(id).right != -1){
        preorder(tree.at(id).right, depth + 1);
    }
}

void inorder(int id, int depth){
    if(tree.at(id).left != -1){
        inorder(tree.at(id).left, depth + 1);
    }
    cout << " " << id;
    if(tree.at(id).right != -1){
        inorder(tree.at(id).right, depth + 1);
    }
}

void postorder(int id, int depth){
    if(tree.at(id).left != -1){
        postorder(tree.at(id).left, depth + 1);
    }
    if(tree.at(id).right != -1){
        postorder(tree.at(id).right, depth + 1);
    }
    cout << " " << id;
}

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

    rep(i, n){
        int id;
        int left_child_index;
        int right_child_index;
        cin >> id >> left_child_index >> right_child_index;
        tree.at(id).left = left_child_index;
        tree.at(id).right = right_child_index;

        if(left_child_index != -1){
            tree.at(left_child_index).parent = id;
        }
        if(right_child_index != -1){
            tree.at(right_child_index).parent = id;
        }
    }

    // ルートノードを探す
    int root_index;
    rep(i, n){
        if(tree.at(i).parent == -1){
            root_index = i;
            break;
        }
    }
    
    int depth = 0;
    // depth first searchによって各ノードの深さを計算
    cout << "Preorder" << endl;
    preorder(root_index, depth);
    cout << endl;

    cout << "Inorder" << endl;
    inorder(root_index, depth);
    cout << endl;

    cout << "Postorder" << endl;
    postorder(root_index, depth);
    cout << endl;

    return 0;
}


Measured memory_bytes: 3724
def LI(): return list(map(int, input().split()))

n, l = LI()
apples = []
for i in range(n):
    apples.append(l + i)

minabs = min([abs(a) for a in apples])

if minabs in apples:
    print(sum(apples) - minabs)
else:
    print(sum(apples) + minabs)


Measured memory_bytes: 2940
//
//  ROIGold.cpp
//  Main calisma
//
//  Created by Rakhman on 05/02/2019.
//  Copyright © 2019 Rakhman. All rights reserved.
//

#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>

#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define FOR(i, start, finish, k) for(int i = start; i <= finish; i += k)

const int MXN = 3e5 + 200;
const long long MNN = 5e3 + 100;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const int OO = 1e9 + 500;

typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

llong n, m, p, d[MXN];
vector<pair<llong, pair<llong, llong> > > ls;

int main () {
    ios;
    cin >> n >> m >> p;
    for(int i = 1; i <= m; i++){
        int u, v, c;
        cin >> u >> v >> c;
        ls.pb({p - c, {u, v}});
    }
    for(int i = 1; i <= n; i++) d[i] = INF;
    d[1] = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < ls.size(); j++){
            llong u = ls[j].S.F, v = ls[j].S.S;
            llong c = ls[j].F;
            if(d[u] == INF) continue;
            if(d[u] + c < d[v]){
                d[v] = d[u] + c;
                if(n == i){
                    d[v] = -INF;
                }
            }
        }
    }
    for(int i = 1; i < n; i++){
        for(int j= 0; j < ls.size(); j++){
            llong u = ls[j].S.F, v = ls[j].S.S;
            if(d[u] == -INF) d[v] = -INF;
        }
    }
//    for(int i = 1; i <= n; i++){
//        cout << d[i] << ' ';
//    }
    if(-d[n] == INF) return  cout << -1, 0;
    else cout << max(d[n] * -1, 0LL);
    return 0;
}



Measured memory_bytes: 576
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <deque>
#include <numeric>
#include <map>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF 1000000000000

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

int N;
ll A, B;
ll h[100001];
ll max_health = 0;

bool enough(ll k) {
	ll total = 0;
	for (int i = 0; i < N; ++i) {
		ll after = h[i] - B * k;
		if (after <= 0)
			continue;
		total += after/(A-B) + (after%(A-B) != 0);
	}
	if (total <= k)
		return true;
	else
	{
		return false;
	}
	
}
int main () {	
	cin >> N >> A >> B;
	rep(i,N) {
		cin >> h[i];
		max_health = max(max_health, h[i]);
	}
	ll no = 0;
	ll ok = max_health + 1;
	ll mid;
	while (ok - no > 1) {
		mid = (ok + no)/2;
		if (enough(mid))
			ok = mid;
		else
			no = mid;
	}
	cout << ok << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ADD +
#define SUBTRACT -
#define MULTIPLY *
#define DIVIDE /
#define MOD %
#define INCREMENT(x) ++x
#define DECREMENT(x) --x
#define in(a,b) cin>>a>>b;
#define out(a,b) cout<<a<<endl<<b<<endl;
#define scan(a) scanf("%d",&a);
#define print(a) printf("%d\n",a);
#define scanii(a,b) scanf("%d %d",&a,&b);
#define printii(a,b) printf("%d\n%d\n",a,b);
#define scaniii(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define ll long long
#define ull unsigned long long
#define sll signed long long
#define pi acos(-1)
#define mod 1000000007
#define TRUE 1
#define FALSE 0
#define ZERO 0
#define MP make_pair
#define F first
#define S second
#define f1(i,a) for(int i=0;i<a;++i)
#define f2(i,a) for(int i=a-1;i>=0;--i)
#define en puts("");
#define elif else if
typedef ll int lli;
typedef sll int slli;
typedef ull int ulli;
const int sz=10000;
using namespace std;

int clue();
int result();
void show();
bool check();


bool cmp(pair<int,int>p,pair<int,int>q) {
    // return p.first>q.first;//descending by first
    // return p.first<q.first;//ascending by first
    // return p.second>q.second;//descending by second
    return p.second<q.second;//ascending by second
}

// bool cmp(int p,int q) {
    // return p>q;//descending
    // return p<q;//ascending
// }


int main() {

    int t;
    // cin>>t;
    t=1;
    while(t-->0) {
        clue();
    }

    return 0;
}
int clue() {

    
    int h,a;
    cin>>h>>a;
    double c=ceil(h/(a*1.0));
    cout<<c<<endl;

    // ()?cout<<"YES"<<endl:cout<<"NO"<<endl;
    
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll a;
  unordered_set<ll> st;
  rep(i, 4) cin >> a, st.insert(a);

  cout << ((st.count(1) && st.count(7) && st.count(9) && st.count(4)) ? "YES"
                                                                  : "NO")
       << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
H = [10**5]+list(map(int,input().split()))
L = [0]*(N+1)
for i in range(2,N+1):
    L[i] = min(abs(H[i-1]-H[i])+L[i-1],abs(H[i-2]-H[i])+L[i-2])
print(L[N])

Measured memory_bytes: 13976
//https://beta.atcoder.jp/contests/agc029/tasks/agc029_a
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}}star;
#define DEBUG if(0)
#endif
#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}
class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};


int main(){
    string s;
    cin>>s;
    LL ret=0;
    LL cnt=0;
    for(int i:range(s.size())){
        if(s[i]=='W'){
            ret+=cnt;
        }
        else{
            cnt++;
        }
    }
    cout<<ret<<endl;
    return 0;
}

Measured memory_bytes: 720
N = int(input())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
A.sort()
B.sort()

# Nが奇数の場合
if N % 2 == 1:
    min_med = A[(N - 1) // 2]
    max_med = B[(N - 1) // 2]
    ans = max_med - min_med + 1

# Nが偶数の場合
if N % 2 == 0:
    # 小数は考えにくいので、2倍した値（整数）で考える
    min_med = A[N // 2 - 1] + A[N // 2]
    max_med = B[N // 2 - 1] + B[N // 2]
    ans = max_med - min_med + 1

print(ans)


Measured memory_bytes: 104636
N = list(input())
A = int(N[0])
B = int(N[1])
C = int(N[2])
D = int(N[3])

if A+B+C+D == 7:
    print(str(A)+"+"+str(B)+"+"+str(C)+"+"+str(D)+"=7")
elif A+B+C-D ==7:
    print(str(A)+"+"+str(B)+"+"+str(C)+"-"+str(D)+"=7")
elif A+B-C-D ==7:
    print(str(A)+"+"+str(B)+"-"+str(C)+"-"+str(D)+"=7")

elif A-B-C-D ==7:
    print(str(A)+"-"+str(B)+"-"+str(C)+"-"+str(D)+"=7")
elif A-B+C-D ==7:
    print(str(A)+"-"+str(B)+"+"+str(C)+"-"+str(D)+"=7")
elif A-B-C+D ==7:
    print(str(A)+"-"+str(B)+"-"+str(C)+"+"+str(D)+"=7")
elif A+B-C+D ==7:
    print(str(A)+"+"+str(B)+"-"+str(C)+"+"+str(D)+"=7")
elif A-B+C+D ==7:
    print(str(A)+"-"+str(B)+"+"+str(C)+"+"+str(D)+"=7")






Measured memory_bytes: 3064
#include <iostream>
#include <math.h>

using namespace std;

int main() {
	int N;
	long long A[100100];
	double digit = 0.0;
	long long res = 1;

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		if (A[i] == 0) {
			cout << 0;
			return 0;
		}
	}

	for (int i = 0; i < N; i++) {
		if (A[i] <= (1000000000000000000 / res)) {
			res *= A[i];
		}
		else {
			cout << -1;
			return 0;
		}
	}

	
	cout << res;
	return 0;
}

Measured memory_bytes: 3936
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 1000000007)
	sc.Split(bufio.ScanWords)
	n, _ := strconv.Atoi(Scanner())
	k, _ := strconv.Atoi(Scanner())
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i], _ = strconv.Atoi(Scanner())
	}
	dp := make([]bool, k+1)
	for i := 1; i < k+1; i++ {
		f := false
		for _, j := range a {
			if i >= j {
				if !dp[i-j] {
					f = true
					break
				}
			}
		}
		dp[i] = f
	}
	if dp[k] {
		fmt.Println("First")
	} else {
		fmt.Println("Second")
	}
}


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

using namespace std;

pair<string,int> a[100];

int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        string b;
        int c;
        cin>>a[i].first>>a[i].second;
    }
    string b;
    cin>>b;
    int ans=0;
    bool t=false;
    for(int i=0;i<n;i++){
        if(a[i].first==b){
            t=true;
            continue;
        }
        if(t)
        ans+=a[i].second;
    }
    cout<<ans<<endl;


    return 0;
}


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

int main() {
  int n,m,x,y;
  cin>>n>>m>>x>>y;
  int a[n],b[m];
  for(int i=0;i<n;i++)
    cin>>a[i];
  for(int i=0;i<m;i++)
    cin>>b[i];
  sort(a,a+n,greater<int>());
  sort(b,b+m);
  if(max(x,a[0])<min(y,b[0]))
    cout<<"No War";
  else cout<<"War";
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int A = sc.nextInt();
    int B = sc.nextInt();
    if (A > B || (N == 1 && A != B)) {
      System.out.println(0);
    } else {
      System.out.println(A+(long)B*(N-1)-(long)A*(N-1)-B+1);
    }
  }
}

Measured memory_bytes: 21844
def gcd(a, b):
    while b: a, b = b, a % b
    return a
def isPrimeMR(n):
    d = n - 1
    d = d // (d & -d)
    L = [2, 7, 61] if n < 1<<32 else [2, 3, 5, 7, 11, 13, 17] if n < 1<<48 else [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]
    for a in L:
        t = d
        y = pow(a, t, n)
        if y == 1: continue
        while y != n - 1:
            y = y * y % n
            if y == 1 or t == n - 1: return 0
            t <<= 1
    return 1
def findFactorRho(n):
    m = 1 << n.bit_length() // 8
    for c in range(1, 99):
        f = lambda x: (x * x + c) % n
        y, r, q, g = 2, 1, 1, 1
        while g == 1:
            x = y
            for i in range(r):
                y = f(y)
            k = 0
            while k < r and g == 1:
                ys = y
                for i in range(min(m, r - k)):
                    y = f(y)
                    q = q * abs(x - y) % n
                g = gcd(q, n)
                k += m
            r <<= 1
        if g == n:
            g = 1
            while g == 1:
                ys = f(ys)
                g = gcd(abs(x - ys), n)
        if g < n:
            if isPrimeMR(g): return g
            elif isPrimeMR(n // g): return n // g
            return findFactorRho(g)
def primeFactor(n):
    i = 2
    ret = {}
    rhoFlg = 0
    while i * i <= n:
        k = 0
        while n % i == 0:
            n //= i
            k += 1
        if k: ret[i] = k
        i += i % 2 + (3 if i % 3 == 1 else 1)
        if i == 101 and n >= 2 ** 20:
            while n > 1:
                if isPrimeMR(n):
                    ret[n], n = 1, 1
                else:
                    rhoFlg = 1
                    j = findFactorRho(n)
                    k = 0
                    while n % j == 0:
                        n //= j
                        k += 1
                    ret[j] = k

    if n > 1: ret[n] = 1
    if rhoFlg: ret = {x: ret[x] for x in sorted(ret)}
    return ret
def sqrt(n):
    x = 1 << (n.bit_length() + 1) // 2
    y = (x + n // x) // 2
    while y < x:
        x = y
        y = (x + n // x) // 2
    return x
def calc(k):
    return (sqrt(8*k+1) - 1) // 2

N  = int(input())
cnt = 0
for i in range(1, N):
    tmp = 1
    pf = primeFactor(i)
    for v in pf.values():
        tmp *= v + 1
    cnt += tmp
print(cnt)


Measured memory_bytes: 68724
# Minesweeper
h,w = list(map(int, input().split()))
s = []
for i in range(h):
    s.append(input())
    
ss = [[0]*(w +2) for i in range(h+2)]
#print(ss)

for i in range(h):
    for j in range(w):
        if s[i][j]=="#":
            ss[i+1][j+1]+=9
            ss[i][j]+=1
            ss[i][j+1]+=1
            ss[i][j+2]+=1
            ss[i+1][j]+=1
            ss[i+1][j+2]+=1
            ss[i+2][j]+=1
            ss[i+2][j+1]+=1
            ss[i+2][j+2]+=1

for i in range(h):
    l = ss[i+1][1:w+1]
    #print(l)
    l = [str(l[i]) if l[i]<9 else "#" for i in range(w)]
    print("".join(l))

Measured memory_bytes: 3064
def mcxi2num (mcxi):
	changer = {"m":1000, "c":100, "x":10, "i":1}
	num = 0
	prefix = 1
	for s in mcxi:
		if s in "mcxi":
			num += prefix * changer[s]
			prefix = 1
		else :
			prefix = int(s)
	return num

def num2mcxi (num):
	changer = ["i", "x", "c", "m"]
	mcxi = ""
	numstr = str(num)
	length = len(numstr)
	for i in range(length):
		if numstr[i] == "0":
			pass
		elif numstr[i] == "1":
			mcxi += changer[length-i-1]
		else:
			mcxi += numstr[i] + changer[length-i-1]
	return mcxi

n = int(raw_input())
for i in range(n):
	s1, s2 = raw_input().split(" ")
	print num2mcxi(mcxi2num(s1) + mcxi2num(s2))

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

int main(){

  int n;
  int dp[100001] = {};
  int a[100001] = {};

  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  int len = 1;
  dp[0] = a[0];
  for(int i = 1; i < n; i++){
    if(dp[len-1] < a[i]){
      dp[len++] = a[i];
    }else{
      *lower_bound(dp, dp+len, a[i]) = a[i];
    }
  }
  cout << len << endl;
  return 0;
}


Measured memory_bytes: 3840
#include "bits/stdc++.h"
using namespace std;

#define Rep(i,n) for(int i=0;i<(n);i++)
#define For(i,n1,n2) for(int i=(n1);i<(n2);i++)
#define REP(i,n) for(ll i=0;i<(n);i++)
#define RREP(i,n) for(ll i=(n-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(n1);i<(n2);i++)
#define put(a) cout<<(a)<<"\n";
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define TDARRAY(int,a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()

typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

int n;
string s;

int main(){
    cin >> s;
    n = s.size();
    if(n==2){
        if(s[0]==s[1]){
            cout << 1 << " " << 2 << endl;
            return 0;
        }else{
            cout << -1 << " " << -1 << endl;
            return 0;
        }
    }
    REP(i,n-2){
        int m=0;
        if(s[i]==s[i+1]){
            m++;
        }
        if(s[i]==s[i+2]){
            m++;
        }
        if(s[i+1]==s[i+2]){
            m++;
        }
        if(m>=1){
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }
    cout << -1 << " " << -1 << endl;
    return 0;
}



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

int64_t calc(string s) {
  int64_t ans = 0, tmp = 0;

  for (char c : s) {
    if (c == '+') {
      ans += tmp;
      tmp = 0;
    } else {
      tmp = tmp * 10 + c - '0';
    }
  }
  ans += tmp;

  // cout << s << "=" << ans << endl;
  return ans;
}

int64_t dfs(string s, int x, string &S) {
  if (x == (int)S.size()) return calc(s);
  if (x > 0)
    return dfs(s + "+" + S.at(x), x + 1, S) + dfs(s + S.at(x), x + 1, S);

  // x == 0
  return dfs(s + S.at(x), x + 1, S);
}

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

  cout << dfs("", 0, S) << endl;
  return 0;
}


Measured memory_bytes: 256