akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

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

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n;
int h[100005];
int dp[100005];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;
  REP(i, n) {
    cin >> h[i];
  }

  fill(dp, dp + n, INF);
  dp[0] = 0;
  REP(i, n) {
    dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
    dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
  }

  cout << dp[n - 1] << endl;
}


Measured memory_bytes: 1024
#


def main():
    n, m = map(int, input().split(" "))
    a = [int(s) for s in input().split(" ")]
    total = sum(a)
    lim = total / (4 * m)
    a = sorted(a, reverse=True)
    count = 0
    for i in a:
        if i >= lim:
            count += 1
        else:
            break
    if count >= m:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


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

int n,N;
int seg[300100],p[100100][2];

void init(int n){
  N = 1;
  while(N<n)N <<= 1;
  for(int i=0;i<2*N;i++)seg[i] = 0;
}

void add(int a, int b, int k, int l, int r){
  if(b<=l || r<=a)return;
  if(a<=l && r<=b)seg[k]++;
  else{
    add(a,b,2*k+1,l,(l+r)/2);
    add(a,b,2*k+2,(l+r)/2,r);
  }
}

int sum(int v){
  v += N-1;
  int res = seg[v];
  while(v>0){
    v = (v-1)/2;
    res += seg[v];
  }
  return res;
}
    
  

int main(){
  cin >> n;
  for(int i=0;i<n;i++)cin >> p[i][0] >> p[i][1];
  p[n][0] = 1; p[n][1] = 100001;

  init(100001);

  for(int i=0;i<=n;i++){
    add(p[i][0],p[i][1]+1,0,0,N);
  }

  int ans = 1;
  for(int i=0;i<=n+1;i++){
    if(i<=sum(i))ans = i;
  }

  cout << ans-1 << endl;
}

Measured memory_bytes: 2968
x,y,m = map(int,input().split());an=10**9
p=list(map(int,input().split()));q=list(map(int,input().split()))
for i in range(m):
  a,b,c = map(int,input().split())
  an=min(an,p[a-1]+q[b-1]-c)
an=min(an,min(p)+min(q))
print(an)

Measured memory_bytes: 18612
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define ii pair<int,int>
#define mod 1000000007
#define endl '\n'
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll a,ll b){
	ll ans=1;
	while(b>0){
		if(b%2!=0){
			ans=(ans*a)%mod;
		}
		a=((a%mod)*(a%mod))%mod;
		b>>=1;
	}
	return ans;
}

void sieve(int n){
	bool prime[n+1];
	memset(prime,true,sizeof(prime));
	for(int p=2;p*p<=n;p++){
		if(prime[p]){
			for(int i=p*p;i<=n;i+=p)
				prime[i]=false;
		}
	}
	for(int p=2;p<=n;p++){
		if(prime[p])
			cout<<p<<" ";
	}
}

int main() {
	IOS;
	int t=1;
	//cin>>t;
	while(t--){
		int n;
		cin>>n;
		int a[n],b[n];
		for(int i=0;i<n;i++)
			cin>>a[i]>>b[i];
		sort(a,a+n);
		sort(b,b+n);
		if(n%2!=0){
			cout<<b[n/2]-a[n/2]+1;
		}
		else{
			double z1,z2;
			z1=(a[n/2]+a[(n/2)-1])/double(2);
			z2=(b[n/2]+b[(n/2)-1])/double(2);
			int cnt=0;
			cnt=2*(z2-z1)+1;
			cout<<cnt;
		}
	}
	return 0;
}

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

typedef long long int ll;

int gcd(int a, int b){
	return b ? gcd(b, a % b) : a;
}

int main(){
	int n;cin >> n;
	int ans;
	vector<int> v(n);
	for(int i = 0;i < n;i++){
		cin >> v[i];
		if(i == 0)ans = v[0];
		if(i > 0)ans = gcd(ans, v[i]);
	}
	cout << ans;
}


Measured memory_bytes: 640
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

S = str(input())

ans = 0
for i,s in enumerate(S):
    if i%2 == 0:
        if s == 'p':
            ans -= 1
    else:
        if s == 'g':
            ans += 1

print(ans)

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

int main(){
    int w,h,n;
    cin >> w >> h >> n;
    int cam[w][h] = {0};
    int x[n], y[n], a[n];
    for(int i=0; i<n; ++i){
        cin >> x[i] >> y[i] >> a[i];
    }
    for(int i=0; i<n; ++i){
        if(a[i] == 1){
            for(int j = 0; j < x[i]; ++j){
                for(int k = 0; k<h; ++k) cam[j][k] = 1;
            }
        }
        if(a[i] == 2){
            for(int j = x[i]; j<w; j++){
                for(int k = 0; k<h; ++k) cam[j][k] = 1;
            }
        }
        if(a[i] == 3){
            for(int j = 0; j<w; ++j){
                for(int k = 0; k<y[i]; k++) cam[j][k] = 1;
            }
        }
        if(a[i] == 4){
            for(int j = 0; j<w; ++j){
                for(int k = y[i]; k<h; ++k) cam[j][k] = 1;
            }
        }
    }
    int result = 0;
    for(int i = 0; i<w; ++i){
        for(int j = 0; j<h; ++j){
            if(cam[i][j] == 0) ++result;
        }
    }
    cout << result << endl; return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int a, b;
	int i = 0;
	int sum;
	int keta = 1;
	
	while (i <= 200){
		if (scanf("%d", &a) == EOF){
			break;
		}
		scanf("%d", &b);
		sum = a + b;
		while (sum >= 10){
			sum /= 10;
			keta++;
		}
		printf("%d\n", keta);
		i++;
		keta = 1;
	}
	
	return (0);
}

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

int main() {
  string n;
  cin >> n;
  if (n[n.length() - 1] == '0' || n[n.length() - 1] == '1' ||
      n[n.length() - 1] == '6' || n[n.length() - 1] == '8') {
    cout << "pon" << endl;
  } else if (n[n.length() - 1] == '3') {
    cout << "bon" << endl;
  } else {
    cout << "hon" << endl;
  }
}

Measured memory_bytes: 3596
#include<iostream>
 
using namespace std;
 
bool isPrime( int x )
{
    if( 2 == x ) { return true; }
    if( 0 == x%2 ) { return false; }
     
    for( int i=3; i*i<=x; i+=2 ) {
        if( 0 == x%i ) { return false; }
    }
    return true;
}
 
int main( )
{
	ios::sync_with_stdio( false );	
    int n;
     
    cin>>n;
     
    int cnt = 0, num;
    while( n-- ) {
        cin>>num;
        cnt += isPrime( num );
    }
    cout<<cnt<<endl;
     
    return 0;
}

Measured memory_bytes: 1200
#include <stdio.h>
int main()
{
    int i, N, s = 0, a[10];
    scanf("%d", &N);
    int N2 = N;
    for (i = 0; N > 0; i++) {
        a[i] = N % 10;
        N /= 10;
        s += a[i];
    }
    if (N2 % s == 0)
        printf("Yes");
    else
        printf("No");
    return 0;
}

Measured memory_bytes: 128
import java.io.*;
public class Main{
	public static void main(String[] args)throws Exception{
		BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb=new StringBuilder();
		int x=0;

		while(true){
		String str=input.readLine();
		String[] str2=str.split(" "); 
		int a=Integer.parseInt(str2[0]);
		int b=Integer.parseInt(str2[1]);
		if(a==0&&b==0){
			break;
		}else{
			if(a>b){
				x=a;
				a=b;
				b=x;
			}
			sb.append(Integer.toString(a)).append(" ").append(Integer.toString(b)).append("\n");
			
		}


		}
		System.out.print(sb);
	}
}

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

#define NIL -1

struct Node {
	int type = NIL;
	bool flag = false;
	vector<int> v;
};

void dfs(vector<Node>& u, int id, int type)
{
	if (u[id].flag) return;

	u[id].flag = true;
	u[id].type = type;
	for (int i = 0; i < u[id].v.size(); i++) dfs(u, u[id].v[i], type);

	return;
}

int main(void)
{
	int i, N, m, l, r, q, type = 0;
	cin >> N >> m;
	vector<Node> u(N);

	for (i = 0; i < m; i++)
	{
		cin >> l >> r;
		u[l].v.push_back(r);
		u[r].v.push_back(l);
	}

	for (i = 0; i < N; i++)
	{
		dfs(u, i, type);
		type++;
	}

	cin >> q;
	for (i = 0; i < q; i++)
	{
		cin >> l >> r;
		cout << ((u[l].type == u[r].type) ? "yes" : "no") << endl;
	}

	return 0;
}


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

using namespace std;

using int64 = long long;
const int mod = (int) (1e9 + 7);

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}


int main() {
  int N;
  cin >> N;
  double sum = 0;
  for(int i = 0; i < N; i++) {
    double x;
    cin >> x;
    sum += 1.0 / x;
  }
  cout << 1 / sum << endl;
}

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

int main() {
    int total = 0, j;
    char topography;
    char ch;
    stack<int> S;
    stack< pair<int, int> > S2;
    for (int i = 0; cin >> topography; i++) {
        if (topography == '\\') {
            S.push(i);
        } else if (topography == '/' && !S.empty()) {
            j = S.top();
            total += i - j;
            int a = i - j;
            S.pop();

            while (!S2.empty() && S2.top().first > j) {
                a += S2.top().second;
                S2.pop();
            }
            S2.push(make_pair(j, a));
        }
    }

	cout << total << endl;
    vector<int> ans;
    while (!S2.empty()) { ans.push_back(S2.top().second); S2.pop(); }
    reverse(ans.begin(), ans.end());

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


Measured memory_bytes: 3160
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		line := scanner.Text()
		n, _ := strconv.Atoi(line)
		var result int
		if 65 <= n && n <= 90 {
			result = 1
		} else if 97 <= n && n <= 122 {
			result = 2
		} else {
			result = 0
		}
		fmt.Printf("%v\n", result)
	}
}



Measured memory_bytes: 1096
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
  int h, w;
  scanf("%d %d", &h, &w);
  vector<string> str;

  for(int i = 0; i < h; i++) {
    string tmp;
    cin >> tmp;
    str.push_back(tmp);
  }
  
  for(int i = 0; i < h; i++) {
    cout << str[i] << endl;
    cout << str[i] << endl;
  }

  
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int N;
  int a;
  int b;
  scanf("%d",&N);
  a=N%10;
  b=N/100;
  if(a==b){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 1640
// https://atcoder.jp/contests/abc076/tasks/abc076_c

#include <bits/stdc++.h>
#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++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int p, s, k, l;
string S, Sd, T;

int main()
{
  cin >> Sd >> T;

  s = p = 0;
  k = T.length();
  l = Sd.length();
  reverse(ALL(T));
  reverse(ALL(Sd));
  REP(i, l)
  {
    if (Sd[i] == T[p] || Sd[i] == '?')
    {
      if (p == 0)
        s = i;
      p++;
      if (p == k)
        break;
    }
    else if (p != 0)
    {
      i -= p;
      p = 0;
    }
  }

  S = "a";
  if (p == k)
  {
    REP(i, l)
    {
      S += s <= i && i < s + k ? T[i - s] : Sd[i] == '?' ? 'a' : Sd[i];
    }
    S = S.substr(1);
    reverse(ALL(S));
  }
  else
    S = "UNRESTORABLE";

  cout << S << '\n';

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <set>
#include <queue>
#include <stack>
#include <map>

using namespace std;
typedef long long LL;
const int INF = int(1e9);

int a[26] = {0};
char Map[120][120];
int N,M;

int main()
{
    cin>>N>>M;
    for(int i = 1;i<=N;i++)
    for(int j = 1;j<=M;j++){
        char temp;
        cin>>temp;
        a[temp-'a']++;
    }
    int t4 = (N/2)*(M/2);
    int flag = 0;
    for(int i = 0;i<26;i++){
        if(a[i]==0)continue;
        if(a[i]>=4){
            if(a[i]/4<t4){
                t4 -= a[i]/4;
                a[i] = a[i]%4;
            }
            else{
                t4 = 0;
                a[i] = a[i] - t4*4;
            }
        }
        if(a[i]>1)
            a[i]%=2;
      //  cout<<a[i]<<endl;
        if(a[i]==1&&flag==0)
            flag = 1;
        else if(a[i]==1&&flag==1){
            cout<<"No"<<endl;
            return 0;
        }
    }
    if(t4<=0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


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

using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

static const ll INF = 1000000000000000000ll;
static const vector<vector<int>> table = {
	{ 0, 1, 2 },
	{ 0, 2, 1 },
	{ 1, 0, 2 },
	{ 1, 2, 0 },
	{ 2, 0, 1 },
	{ 2, 1, 0 },
};

int main(){
	ios_base::sync_with_stdio(false);
	array<int, 3> xyz;
	cin >> xyz[0] >> xyz[1] >> xyz[2];
	const int n = xyz[0] + xyz[1] + xyz[2];
	vector<array<ll, 3>> abc(n);
	for(int i = 0; i < n; ++i){ cin >> abc[i][0] >> abc[i][1] >> abc[i][2]; }
	priority_queue<pll> pqs[3][3];
	vector<int> location(n, -1);
	ll answer = 0;
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < 3; ++j){
			for(int k = 0; k < 3; ++k){
				while(!pqs[j][k].empty()){
					const auto p = pqs[j][k].top();
					if(location[p.second] == j){ break; }
					pqs[j][k].pop();
				}
			}
		}
		ll best_score = -INF;
		int best_procedure = 0;
		for(int j = 0; j < table.size(); ++j){
			const auto& proc = table[j];
			auto t_xyz = xyz;
			int cur = i;
			ll score = 0;
			for(int k = 0; k < 3; ++k){
				const int p = proc[k];
				score += abc[cur][p];
				if(t_xyz[p] > 0){ break; }
				const int q = proc[k + 1];
				if(pqs[p][q].empty()){
					score = -INF;
					break;
				}
				score -= abc[pqs[p][q].top().second][p];
				cur = pqs[p][q].top().second;
			}
			if(score > best_score){
				best_score = score;
				best_procedure = j;
			}
		}
		{
			const auto& proc = table[best_procedure];
			int cur = i;
			for(int k = 0; k < 3; ++k){
				const int p = proc[k];
				answer += abc[cur][p];
				location[cur] = p;
				for(int q = 0; q < 3; ++q){
					pqs[p][q].emplace(abc[cur][q] - abc[cur][p], cur);
				}
				if(xyz[p] > 0){
					--xyz[p];
					break;
				}
				const int q = proc[k + 1];
				answer -= abc[pqs[p][q].top().second][p];
				cur = pqs[p][q].top().second;
				pqs[p][q].pop();
			}
		}
	}
	cout << answer << endl;
	return 0;
}



Measured memory_bytes: 10584
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#define test ll t; cin>>t; while(t--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
/*int inv[1000001]={0};
void findinverse(){inv[1] = 1;for(int i = 2; i <=1e6 ; ++i)	inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;}
*/
using namespace std;
int a[MAX]={0};
int n,k;
int dp[MAX];
int solve(int k)
{
	if(dp[k]!=-1)
		return dp[k];
	if(k==0)
		return dp[k]=0;
	int ans=0;
	for(int i=1;i<=n;i++){
		if(a[i]>k)
			continue;
		if(solve(k-a[i])==0){
			ans=1;
			break;
		}
	}
	return dp[k]=ans;
}
signed main()
{
	fastio;
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	memset(dp,-1,sizeof(dp));
	if(solve(k))
		cout<<"First"<<endl;
	else
		cout<<"Second"<<endl;
}


Measured memory_bytes: 14532
#include<vector>
#include<iostream>
#include<algorithm>
// #include<queue>
// #include<set>
#include<cmath>

/******/
// during contest

/*
void stupid(){
    int N,K;

    std::cin>>N>>K;
    // std::vector<long double> v(N);
    std::multiplies<long double> v;
    long double buf;

    // std::queue<long double> q;
    for(int i=0;i<N;++i){
        std::cin>>buf;
        v.insert(buf);
    }
    for(int i=0;i<K;++i){
        buf
    }
    std::cout<<(int)(q.front());
}
*/

bool check(std::vector<unsigned long long>v,unsigned long long val,unsigned long long K){
    unsigned long long cnt=0;
    for(unsigned int i=0;i<v.size();++i){
        // if(v[i]%val==0){
        //     cnt+=v[i]/val-1;
        // }else{
        //     cnt+=v[i]/val;
        // }
        // if(v[i]==1)
        //     continue;
        cnt+=(unsigned long long)(ceil(v[i]/(long double)val)-1);
        if(cnt>K)
            break;
    }
    // std::cout<<cnt<<std::endl;
    return cnt<=K;
}

void correct(){
    unsigned long long N,K;
    std::cin>>N>>K;
    std::vector<unsigned long long> v(N);
    for(auto& p:v){
        std::cin>>p;
    }
    auto maxItr=std::max_element(v.begin(),v.end());
    unsigned long long r,median,l;
    for(l=1,r=(*maxItr),median=l+(r-l)/2;r-l>1;){
        // std::cout<<l<<":"<<median<<":"<<r<<std::endl;
        bool isCut=check(v,median,K);
        if(!isCut){
            l=median;
            // median=(r+l)/2;
            median=l+(r-l)/2;
        }else{
            r=median;
            median=l+(r-l)/2;
        }
    }
    if(r-l==1){
        if(check(v,l,K)){
            median=l;
        }else{
            median=r;
        }
    }
    std::cout<<median<<std::endl;
}

/******/
int main(){
    correct();
    return 0;
}

Measured memory_bytes: 6320
//21171_somesh || asomesh999

#include<bits/stdc++.h>
using namespace std;
#define fr(i,a,b) for(long long i=a;i<b;i++)
#define io ios::sync_with_stdio(false);cin.tie(NULL);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
long int mod=1000000007;

vl pr;
void sieve(ll n) {
	bool prime[n + 1];
    memset(prime, true, sizeof(prime));
    for(ll p = 2; p * p <= n; p++) {
        if(prime[p] == true) {
            for(ll i = p * p; i <= n; i += p)
                prime[i] = false;
        }
    }
    for (ll p = 2; p <= n; p++)
        if (prime[p])
        	pr.push_back(p);
} 

int main()
{
	io
	#ifdef CODE
		clock_t startTime = clock();
		freopen("input.txt","r",stdin);
	#endif

	sieve(100010);
	ll x;
	cin >> x;
	cout << *lower_bound(pr.begin(), pr.end(), x);

	#ifdef CODE
		cerr << endl <<setprecision(20)<< double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " seconds." << endl;
	#endif
	return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

int main() {
  ll a,b;
  cin>>a>>b;
  cout << max(a+b,max(a-b,a*b)) << endl;
  return 0;
}

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

#define N_MAX 500001

struct node{
    int key;
    struct node *right;
    struct node *left;
    struct node *parent;
};

typedef struct node *Node;
Node root = NULL;

void insert(int k){
    Node y = NULL;
    Node x = root;
    Node z;
    
    z = malloc(sizeof(struct node));
    z->key = k;
    z->right = NULL;
    z->left = NULL;
    while(x != NULL){
        y = x;
        if(z->key < x->key){
            x = x->left;
        }else{
            x = x->right;
        }
    }
    z->parent = y;

    if(y == NULL){
        root = z;
    }else if(z->key < y->key){
        y->left = z;
    }else{
        y->right = z;
    }
}

/* 中間順アルゴリズム */
#if 0
void inorder(Node u){
    
    if(u->left != NULL){
        inorder(u->left);
    }
    printf(" %d",u->key);

    if(u->right != NULL){
        inorder(u->right);
    }
}
#endif

void inorder(Node u){
    
    if(u == NULL){
        return;
    }
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}

void preorder(Node u){
    
    if(u == NULL){
        return;
    }
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}

int main(){
    int n, i, x;
    char com[20];
    scanf("%d", &n);
    
    
    for ( i = 0; i < n; i++ ){
        scanf("%s", com);
        if ( com[0] == 'i' ){
            scanf("%d", &x);
            insert(x);
        } else if ( com[0] == 'p' ){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        } 
    }
    return 0;
}






Measured memory_bytes: 25204
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ojtEx
{
    class Program
    {
        static void Main(string[] args)
        {
            //int X = int.Parse(Console.ReadLine());
            //int a = int.Parse(Console.ReadLine());
            //string s = Console.ReadLine();

            string[] xa = Console.ReadLine().Split(' ');
            int x = int.Parse(xa[0]);
            int a = int.Parse(xa[1]);


            int ans = Solve(x, a);

            //int x, y, z, w;
            //x = int.Parse(s[0].ToString());
            //y = int.Parse(s[1].ToString());
            //z = int.Parse(s[2].ToString());
            //w = int.Parse(s[3].ToString());


            //string ans = S(x, y, z, w);

            Console.WriteLine(ans);
        }

        //public static int Solve(int X, int A)
        //{
        //    if (X < A)
        //    {
        //        return 0;
        //    }
        //    if (A <= X)
        //    {
        //        return 10;
        //    }

        //    return 0;
        //}

        public static string S(int x, int y,int z,int w)
        {
            if(x!=y && y!=z && z!=w)
                {
                return "Good";
                }
            else
            {
                return "Bad";
            }
        }

        //public static int Solve(int N, int A, int B)
        //{
        //    if (N * A < B)
        //    {
        //        return N * A;
        //    }
        //    if (B < N * A)
        //    {
        //        return B;
        //    }
        //}

        public static int Solve(int A, int B)
        {
            return new int[] { A + B, A - B, A * B }.Max();
        }


    }
}


Measured memory_bytes: 27928
#include <stdio.h>

int main(void) {
	int syakkin = 100000;
	int i, n;

	scanf("%d", &n);
	for (i = 1; i <= n; i++){
		syakkin = syakkin*1.05;
		if (syakkin % 1000 != 0){
			syakkin=syakkin / 1000;
			syakkin++;
			syakkin=syakkin * 1000;
		}
	}

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

	return 0;
}

Measured memory_bytes: 592
import math

def intinput():
    return int(input())

def listintinput():
    return list(map(int,input().split()))

def splitintinput():
    return map(int,input().split())

ans = 0
N,K = splitintinput()
H = listintinput()
H.sort(reverse=True)
for i in range(K,N):
    ans += H[i]

print(ans)



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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;

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

  int n;cin>>n;
  std::vector<int> v(2*n);
  for(int i=0;i<2*n;i++) cin>>v[i];
  sort(v.begin(),v.end());
  int res=0;
  for(int i=0;i<n;i++) res+=v[i*2];
  cout<<res<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < n; ++i)
#define rep(i,n) for(int i = 1; i <= n; ++i)
#define boost ios::sync_with_stdio(0)
#define ms0(s) memset((s), 0, sizeof(s))
#define INF 0x3f3f3f3f
#define ABS(x) ((x)<0 ? (-(x)) : (x))
#define forvec(it,v) for(vector<int>::iterator it = v.begin(); it != v.end(); ++it)

#ifdef LOCAL
#define DEBUG 1
#else
#define DEBUG 0
#endif
#define $ if(DEBUG)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template <typename T>
inline void read(T& x){
	int w = 1; T data = 0;
	char ch = getchar();
	while(!isdigit(ch) && ch != '-') ch = getchar();
	if(ch == '-') w = -1, ch = getchar();
	while(isdigit(ch))
		data = 10 * data + ch - '0', ch = getchar();
	x = data * w;
}
int main()
{
	int a[3];
	REP(i, 3) read(a[i]);
	sort(a, a+3);
	printf("%d\n",a[2] - a[0]);
}



Measured memory_bytes: 256
main=do
 [n,k]<-map read.words<$>getLine
 s<-getLine
 let a=f s
 let b=if head s=='L' then a++[1] else a
 let c=if last s=='R' then b++[1] else b
 let d=drop k c
 print$(n-)$sum$if length d==0 then [1] else d
f('R':'L':x)=2:f x
f(c:x)=f x
f[]=[]

Measured memory_bytes: 7548
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
#define pb push_back
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<vector<pii>> edge(n + 1);
	for (int i = 1; i < n; i++) {
		int u, v, w;
		cin >> u >> v >> w;
		edge[u].pb(pii(v, w));
		edge[v].pb(pii(u, w));
	}
	vector<int> c(n + 1);
	queue<int> q;
	q.push(1);
	c[1] = 1;
	while (!q.empty()) {
		int u = q.front();
		q.pop();
		for (pii p : edge[u]) {
			int w = p.second;
			int uu = p.first;
			if (c[uu]) continue;
			c[uu] = (w % 2) ? -c[u] : c[u];
			q.push(uu);
		}
	}
	for (int i = 1; i <= n; i++) {
		cout << (c[i] == 1 ? 1 : 0) << "\n";
	}
	return 0;
}

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

int main() {
	int n;
	cin>>n;
	vector<int> v(n);
	for(int i=0;i<n;i++)cin>>v[i];
	int dp[n+1];
	dp[0]=0;
	dp[1]=abs(v[1]-v[0]);
	for(int i=2;i<n;i++){
		dp[i]=min(dp[i-1]+abs(v[i]-v[i-1]),dp[i-2]+abs(v[i]-v[i-2]));
	}
	int sum=0;
	for(int i=1;i<n;i++){
		sum=max(dp[i-1],dp[i]);
	}
	cout<<dp[n-1];
}

Measured memory_bytes: 1024
def s():
 n=int(input())+1
 e=[input().split()for _  in[0]*~-n]
 p=[int(e[0][0])]+list(int(x[1])for x in e)
 m=[[0]*n for _ in[0]*n]
 for i in range(n):
  for r in range(n-i-1):
   c=r+i+1
   for j in range(r+1,c):
    x=m[r][j]+m[j][c]+p[r]*p[j]*p[c]
    if not 0<m[r][c]<=x:m[r][c]=x
 print(m[r][c])
if'__main__'==__name__:s()


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

#define pb push_back
#define fi first
#define se second
typedef long long ll;

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);

	int n, r;
	cin >> n >> r;
	if (n < 10)
		cout << r + 100 * (10 - n) << '\n';
	else
		cout << r << '\n';
}


Measured memory_bytes: 256
//  Copyright © 2020 Diego Garcia Rodriguez del Campo. All rights reserved.
#include<bits/stdc++.h>
#define MAX 1000005
#define optimiza_io cin.tie(0); ios_base::sync_with_stdio(0);
#define what_is(x) cerr << #x << " is " << x << endl;
using namespace std;
typedef long long ll;

struct node {
    int c, o, id;
};

int N, tot;
node a[MAX];
bool vis[MAX];

int suf( string s ) {
    reverse( s.begin(), s.end() );
    int l = 0;
    int ans = 0;
    for( auto v : s ) {
        if( v == ')' )
            l++;
        else if( l > 0 )
            l--;
        else
            ans++;
    }
    return ans;
}

int pref( string & s ) {
    int l = 0;
    int ans = 0;
    for( auto v : s ) {
        if( v == '(' )
            l++;
        else if( l > 0 )
            l--;
        else
            ans++;
    }
    return ans;
}

bool cmp( node a , node b ) {
    if( a.c != b.c )
        return a.c < b.c;
    return a.o > b.o;
}

bool cmp2( node a , node b ) {
    if( a.o != b.o )
        return a.o > b.o;
    return a.c < b.c;
}

void fail() { cout << "No\n"; exit(0); }

int main()
{
    optimiza_io
    cin >> N;
    for( int i = 1; i <= N; i ++ ) {
        string s;
        cin >> s;
        a[i].c = pref( s );
        a[i].o = suf( s );
        a[i].id = i;
        // cout << a[i].c << " " << a[i].o << "\n";
    }
    
    int open = 0;
    sort( a + 1 , a + N + 1 , cmp );
    for( int i = 1; i <= N; i ++ ) 
        if( a[i].c <= open && a[i].c <= a[i].o ) {
            open -= a[i].c;
            vis[a[i].id] = 1;
            tot++;
            open += a[i].o;
        }
    
    sort( a + 1 , a + N + 1 , cmp2 );
    for( int i = 1; i <= N; i ++ ) {
        if( vis[a[i].id] )
            continue;
        vis[a[i].id] = 1;
        tot++;
        open -= a[i].c;
        if( open < 0 )
            fail();
        open += a[i].o;
    }
    
    if( open or tot != N )
        fail();
    cout << "Yes\n";
    return 0;
}

// CHECAR LIMITES 




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

using namespace std;

class Solution {
public:
	void solve() {
		long long n;
		cin >> n;
		queue<long long> q;
		for (int i = 1; i < 10; i++) q.push(i);
		while (--n) {
			auto x = q.front();
			q.pop();
			auto y = x % 10;
			for (auto i = max(y - 1, 0ll); i <= min(y + 1, 9ll); i++) {
				q.push(10 * x + i);
			}
		}
		cout << q.front() << endl;
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
  long int n,k,a,b,c,i,odd,even;
  long int max;
  double ans,O,E;
  scanf("%ld %ld",&n,&k);
  if(k%2==1){
    max = (n-n%k)/k;
    ans = pow(max,3);
  }else{
    max = (2*n-(2*n)%k)/k;
    odd = (max+max%2)/2;
    even = max-odd;
    O = pow(odd,3);
    E = pow(even,3);
    ans = O+E;
  }
  printf("%ld",(long int)ans);
  return 0;
}


Measured memory_bytes: 256
#if defined(DAIJOBU)
#include "/home/ichigo/includes.hpp"
#include "PP.hpp"
#define deb(x...) cerr << "[" << #x << "] = " << x << "\n";
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long lint;
typedef vector<lint> vlint;
typedef vector<vlint> vvlint;
typedef pair<lint, lint> plint;
typedef double ld;

template<class T> bool chmin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool chmax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main() {
    ios::sync_with_stdio(false);
	cin.tie(0);
  	
  	int a[3];
  	cin >> a[0] >> a[1] >> a[2];
  	sort(a, a + 3);
  	cout << a[0] + a[1] << '\n';
	return 0;
}



Measured memory_bytes: 256
//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <cmath>

using namespace std;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mp make_pair
#define all(a) (a).begin(), (a).end()
typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<ll> da(n);
    rip(i,n,0){
        cin >> da[i];
    }
    vector<ll> su(n+1,0);
    rip(i,n,0){
        su[i+1] = su[i] + da[i];
    }
    map<ll,ll> ma;
    rip(i,n+1,0){
        if(ma.count(su[i])){
            ma[su[i]] ++;
        }
        else{
            ma[su[i]] = 1;
        }
    }
    ll  ans = 0;
    for(auto i:ma){
        ans -= i.second*(i.second-1)/2;
    }
    printf("%lld\n",-ans);
}

Measured memory_bytes: 15872
n = int(input())
red = []
blue = []
for i in range(n):
    x,y =map(int,input().split())
    red.append([x,y])
for i in range(n):
    x,y =map(int,input().split())
    blue.append([x,y])

ans=0
for i in range(2*n):
    now = 2*n -1 -i
    for redpoint in red:
        if redpoint[0] == now:
            value=300
            add=[]
            for bid,bluepoint in enumerate(blue):
                if (bluepoint[0]>redpoint[0])and(bluepoint[1]>redpoint[1]):
                    if value>bluepoint[1]:
                        value =bluepoint[1]
                        add =bluepoint
            if add:
                blue.remove(add)
                red.remove(redpoint)
                ans +=1
            if redpoint[0]==redpoint[1] and add:
                break
        if redpoint[1] == now:
            value=300
            add=[]
            for bid,bluepoint in enumerate(blue):
                if (bluepoint[0]>redpoint[0])and(bluepoint[1]>redpoint[1]):
                    if value>bluepoint[0]:
                        value =bluepoint[0]
                        add =bluepoint
            if add:
                blue.remove(add)
                red.remove(redpoint)
                ans +=1
                        
print(ans) 
        
                
                    
                

Measured memory_bytes: 3064
//ITP1_3_D
#include<iostream>
using namespace std;

int main(){
	int a,b,c,s=0;
	
	cin>>a>>b>>c;
	
	do{

	if(0==c%a)
	s++;
	a++;
	
	}while(a<=b);
	
	cout<<s<<endl;
	
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=int(l);i<int(r);i++)
#define put(x) cout<<#x<<" = "<<x<<endl;
#define X first
#define Y second
#define pb push_back
#define pp pop_back
#define int num
using namespace std;
typedef long long num;
typedef pair<int,int> point;
const int maxn=1e5+10;

int k,A[maxn];

int check(int x){
    rep(i,0,k){
	x=x/A[i]*A[i];
    }
    return x;
}

int BS1(int l,int r){
    if(r-l==1){
	return r;
    }
    int mid=(l+r)>>1;
    if(check(mid)>=2){
	return BS1(l,mid);
    }else{
	return BS1(mid,r);
    }
}

int BS2(int l,int r){
    if(r-l==1){
	return l;
    }
    int mid=(l+r)>>1;
    if(check(mid)>2){
	return BS2(l,mid);
    }else{
	return BS2(mid,r);
    }
}

int32_t main(){
    cin>>k;
    rep(i,0,k){
	cin>>A[i];
    }
    int mn=BS1(0,1e15+10),mx=BS2(0,1e15+10);
    if(check(mn)!=2 || check(mx)!=2){
	cout<<"-1\n";
    }else{
	cout<<mn<<' '<<mx<<endl;
    }
}


Measured memory_bytes: 1024
function bomb(y,x){
   cnt++;
   var dx=[0,-1,1,0];
   var dy=[-1,0,0,1];
   for(var i=0;i<4;i++){
      var X=x+dx[i];
      var Y=y+dy[i];
      if(Y>=h || Y<0 || X>=w || X<0)continue;
      if(yx[Y][X]=="S")continue;
      else if(yx[Y][X]=="."){yx[Y][X]="S";bomb(Y,X);}
      else {
         if(color=="" || color==yx[Y][X])color=yx[Y][X];
         else color="bad";
      }
   }
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
while(true){
   var wh=arr.shift();
   if(wh=="0 0")break;
   wh=wh.split(" ").map(Number);
   var w=wh[0];
   var h=wh[1];
   var yx=[];
   for(var i=0;i<h;i++)yx.push(arr.shift().split(""));
   var ans=[0,0];
   for(var y=0;y<h;y++){
      for(var x=0;x<w;x++){
         var color="";
         var cnt=0;
         if(yx[y][x]=="."){yx[y][x]="S";bomb(y,x);}
         if(color=="B")ans[0]+=cnt;
         else if(color=="W")ans[1]+=cnt;
      }
   }
   console.log(ans[0]+" "+ans[1]);
}

Measured memory_bytes: 18328
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
//#define MOD 1000000007
#define EPS 0.000000001
using namespace std;




#define MOD 998244353
#define SIZE 3005

ll N,S;
ll A[SIZE];
ll dp[SIZE][SIZE][3];


int main(){

	scanf("%lld %lld",&N,&S);

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

		scanf("%lld",&A[i]);
	}

	for(int i = 0; i <= N; i++){
		for(int k = 0; k <= S; k++){
			for(int a = 0; a < 3; a++){

				dp[i][k][a] = 0;
			}
		}
	}

	/*
	 * 0:両方未定
	 * 1:左端決定(初めて足す時に左端が決定する)
	 * 2:両方決定(足し終わるまで右端は確定しない)
	 * */

	dp[0][0][0] = 1;

	for(int i = 0; i < N; i++){
		for(int k = 0; k <= S; k++){

			//未定→未定(0以外ありえない)
			if(k == 0){
				dp[i+1][k][0] += dp[i][k][0];
				dp[i+1][k][0] %= MOD;
			}
			//未定→左端決定
			if(k+A[i] <= S){
				dp[i+1][k+A[i]][1] += (dp[i][k][0]*(i+1))%MOD;
				dp[i+1][k+A[i]][1] %= MOD;
			}
			//未定→一気に両端決定
			if(k+A[i] <= S){
				dp[i+1][k+A[i]][2] += (((dp[i][k][0]*(i+1))%MOD)*(N-i))%MOD;
				dp[i+1][k+A[i]][2] %= MOD;
			}
			//左端決定→左端決定
			//足さない
			dp[i+1][k][1] += dp[i][k][1];
			dp[i+1][k][1] %= MOD;
			//足す
			if(k+A[i] <= S){
				dp[i+1][k+A[i]][1] += dp[i][k][1];
 				dp[i+1][k+A[i]][1] %= MOD;
			}

			//左端決定→両方決定
			if(k+A[i] <= S){

				dp[i+1][k+A[i]][2] += dp[i][k][1]*(N-i)%MOD;
				dp[i+1][k+A[i]][2] %= MOD;
			}
			//両方決定→両方決定
			dp[i+1][k][2] += dp[i][k][2];
			dp[i+1][k][2] %= MOD;
		}
	}

	printf("%lld\n",dp[N][S][2]);

	return 0;
}


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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007

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

    int t=0,ans=0;
    while (ans<x) {
        t++;
        ans+=t;
    }
    cout<<t<<endl;
}



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

line = list(input().split(" "))

total = 0
ans = 0
for i in range(n):
    if total > x:
        break
    else:
        total += int(line[i])
        ans += 1

if total <= x:
    print(n + 1)
else:
    print(ans)


Measured memory_bytes: 2940
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define rep(i,n) for(int i=0;i<n;i++)
int gcd(int a, int b){
    int r=1;
    while(r!=0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
typedef long long ll;
void revStr(char* str){
    int size = strlen(str);
    int i,j;
    char tmp = {0};
    for(i = 0, j = size - 1; i < size / 2; i++, j--){
        tmp = str[i];
        str[i] = str[j];
        str[j] = tmp;
    }return;
}
typedef struct{
    int p;
    int q;
}data;

//昇順
int compare_int(const void *a, const void *b)
{
    return *(int*)b - *(int*)a;
}
int asc(const void *a, const void *b) {
  long *A = (long *)a;
  long *B = (long *)b;
  if (*A > *B) return 1;
  if (*A < *B) return -1;
  return 0;
}

int kai(int n){
    if(n==0){
        return 1;
    }
    int sum=1;
    for(int i=1;i<=n;i++){
        sum*=i;
    }
    return sum;
}
//構造体の.pを降順
int comp( const void *c1, const void *c2 )
{ data test1 = *(data *)c1;
  data test2 = *(data *)c2;
  int tmp1 = test1.p;   /* b を基準とする */
  int tmp2 = test2.p;
    return tmp2 - tmp1;}




int main(){
    int x;
    scanf("%d",&x);
    ll pw=1;
    for(int i=1;i<=x;i++){
        pw*=i;
        if(pw>1000000007){
            pw=pw%1000000007;
        }else{
            ;
        }
    }
    printf("%lld",pw);
}


Measured memory_bytes: 1708
#include <iostream>                                                  
#include <string>                                                    
#include <cctype>                                                    
using namespace std;                                                 
                                                                     
int main() {                                                         
  string str;                                                        
  int count[26] = {};                                                
  int num = 0;                                                       
  while (getline(cin, str)) {                                        
    for (int i=0; i<str.length(); i++) {                             
      if (islower(str[i])) {                                         
        num = str[i]-'a';                                            
        count[num]++;                                                
      } else if (isupper(str[i])) {                                  
        str[i] = tolower(str[i]);                                    
        num = str[i]-'a';                                            
        count[num]++;                                                
      }                                                              
    }                                                                
  }                                                                  
  for (int i=0; i<26; i++) {                                         
    cout << char(i+'a') << " : " << count[i] << endl;                
  }                                                                  
  return 0;                                                          
}                                                                    
         

Measured memory_bytes: 3164
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define ld long double
#define pll pair<ll, ll>
#define pii pair<int, int>
#define f first
#define se second
#define pb push_back
#define ft fflush(stdout)
 
 
using namespace std;
 
 
const int N = 3e6;
const int PLS = 3e5 + 123;
const ll mod = 1e9 + 7;
const ll inf = 1e16;


ll n, dp[N][2];
vector <ll> g[N];


void dfs(ll u, ll p=-1) {
    dp[u][0] = dp[u][1] = 1;
    for (int i = 0; i < g[u].size(); i++) {
        if (g[u][i] == p)
            continue;
        dfs(g[u][i], u);
        dp[u][0] = (dp[u][0] * ((dp[g[u][i]][0] + dp[g[u][i]][1]) % mod)) % mod;
        dp[u][1] = (dp[u][1] * dp[g[u][i]][0]) % mod;
    }
}


int main() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL); cout.tie(NULL);
    cin >> n;
    ll u, v;
    for (int i = 1; i < n; i++) {
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    if (n == 1)
        return cout << 2, 0;
    dfs(1);
    cout << (dp[1][0] + dp[1][1]) % mod;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = 1000003;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

// factorial(階乗)の計算
const int N_MAX = pow(10,6)*2;
ll fac[N_MAX+1] ={};
ll c_fac(int n=N_MAX) {
  if (fac[n]!=0) return fac[n];
  if (n==0) return fac[n]=1;
  return fac[n] = (c_fac(n-1)*n)%MOD;
}

// inverse(逆元)の計算
ll inv(ll a,ll m=MOD) {
  ll b = m, x = 1, y = 0;
  while (b!=0) {
    ll d = a/b;
    a -= b*d; swap(a, b);
    x -= y*d; swap(x, y);
  }
  return x>=0 ? x : x+m;
}

int main() {
  c_fac();
  int Q; cin >> Q;
  rep(i,Q) {
    ll x, d, n; cin >> x >> d >> n;
    ll result = 1;
    if (d==0) {
      ll num = x;
      rep(i,30) {
        if (n&(1<<i)) { result *= num; result %= MOD; }
        num *= num; num %= MOD;
      }
    }
    else {
      ll num = (x*inv(d))%MOD;
      ll dn = 1, nn = d;
      rep(i,30) {
        if (n&(1<<i)) { dn *= nn; dn %= MOD; }
        nn *= nn; nn %= MOD;
      }
      if (num==0||num+(n-1)>=MOD) result = 0;
      else result = (((fac[num+(n-1)]*inv(fac[num-1]))%MOD)*dn)%MOD;
    }
    cout << result << endl;
  }
  return 0;
}

Measured memory_bytes: 49536
n,k=map(int,input().split())
a=list(map(int,input().split()))
visit=[0]*n
visit[0]=1
now=0
c=0
for i in range(k):
  now_=now
  now=a[now]-1
  if visit[now]==0:
    visit[now]=visit[now_]+1
  else:
    c=1
    break
if c==1:
  t=(k+2-visit[now])%(visit[now_]-visit[now]+1)
  if t==0:
    print(now_+1)
  else:
    i=now
    for _ in range(t-1):
      i=a[i]-1
    print(i+1) 
else:
  u=now+1
  print(u)
  

Measured memory_bytes: 32176
#define  _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
#pragma comment (linker, "/STACK:526000000")

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}


void solve() {
	map<int, int> go;
	REP(i, 3) {
		int a;
		cin >> a;
		go[a]++;
	}
	for (auto x : go) {
		if (x.second == 2) {
			cout << "Yes" << endl;
			return;
		}
	}
	cout << "No" << endl;
	return;
}

#undef int
int main() {
	init();
	solve();
}

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

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

	int a=0, b=0, ab=0, cnt=0;
	REP(i, n) {
		string s;
		cin >> s;

		if (s.at(0) == 'B' && s.at(s.size()-1) == 'A')	ab++;
		else if (s.at(0) == 'B')	b++;
		else if (s.at(s.size()-1) == 'A')	a++;

		REP(j, s.size()-1) {
			if (s.at(j) == 'A' && s.at(j+1) == 'B') cnt++;
		}
	}
	if (a == 0 && b == 0)	cout << min(a, b) + max(ab-1, 0) + cnt << endl;
	else cout << min(a, b) + ab + cnt << endl;
}


Measured memory_bytes: 256