akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define pb push_back
#define l first
#define r second
#define int long long

const int maxn = 1e6 + 1, mod = 1e9 + 7;

using namespace std;

vector<int> g[maxn];
int dp[maxn], ans[maxn], sz[maxn], vdp[maxn];
int fact[maxn], ifact[maxn];

int bp(int a, int n) {
    if (!n) return 1;
    if (n % 2) return (a * bp(a, n - 1)) % mod;
    return bp((a * a) % mod, n / 2);
}

inline int cnk(int n, int k) {
    return ((fact[n] * ifact[k]) % mod * ifact[n - k]) % mod;
}

void dfs1(int x, int pr) {
    dp[x] = sz[x] = 1;
    for (auto to : g[x]) {
        if (to == pr) continue;
        dfs1(to, x); sz[x] += sz[to];
        dp[x] = (dp[x] * cnk(sz[x] - 1, sz[to])) % mod;
        dp[x] = (dp[x] * dp[to]) % mod;
    }
}

void dfs2(int x, int pr) {
    if (x == 0) {
        ans[x] = dp[x];
        vdp[x] = 1;
    } else {
        vdp[x] = (vdp[pr] * cnk(sz[0] - sz[x] - 1, sz[0] - sz[pr])) % mod;
        vdp[x] = (vdp[x] * dp[pr]) % mod;
        vdp[x] = (vdp[x] * bp(cnk(sz[pr] - 1, sz[x]), mod - 2)) % mod;
        vdp[x] = (vdp[x] * bp(dp[x], mod - 2)) % mod;
        ans[x] = (dp[x] * cnk(sz[0] - 1, sz[0] - sz[x])) % mod;
        ans[x] = (ans[x] * vdp[x]) % mod;
    }
    for (auto to : g[x])
        if (to != pr) dfs2(to, x);
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n; cin >> n;
    fact[0] = ifact[0] = 1;
    for (int i = 1; i <= n; i++) {
        fact[i] = (fact[i - 1] * i) % mod;
        ifact[i] = (ifact[i - 1] * bp(i, mod - 2)) % mod;
    }
    for (int i = 0; i < n - 1; i++) {
        int u, v; cin >> u >> v;
        --u; --v; g[u].pb(v); g[v].pb(u);
    }
    dfs1(0, -1);
    dfs2(0, -1);
    for (int k = 0; k < n; k++)
        cout << ans[k] << '\n';
    return 0;
}


Measured memory_bytes: 55280
#include <iostream>
using namespace std;
int main(){
	int n;
	while(cin>>n,n){
		int p,d1,d2,maxp,maxd;
		maxp=0;
		maxd=0;
		for(int i=0; i<n; i++){
		cin>>p>>d1>>d2;
	if(maxd<d1+d2){
		maxd=d1+d2;
		maxp=p;
			}
		}	
		cout<<maxp<<" "<<maxd<<endl;
	}	
}

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

using namespace std;


int main(){
	#ifdef EVAL
		freopen("input.txt", "r", stdin);
		//freopen("output.txt", "w", stdout);
	#endif
	string S;
	string T;
	cin >> S >> T;
	set <int> s(S.begin(), S.end()), t(T.begin(),T.end());
	bool ok = true;
	for(char c : T){
		if(s.find(c) == s.end()){
			cout << -1;
			return 0;
		}
	}
	int ans = 1, last_index = -1;
	vector <int> cur(28,0);
	vector <int> adj[28];
	for(int i = 0; i < S.size(); i++){
		adj[S[i] - 'a'].push_back(i);
	}
	for(char c : T){
		int index = c - 'a';
		while(cur[index] < adj[index].size() && last_index >= adj[index].at(cur[index])){
			cur[index]++;
		}
		if(cur[index] == adj[index].size()){
			ans++;
			for(int &i : cur){
				i = 0;
			}
		}
		last_index = adj[index][cur[index]];
		cur[index]++;
	}
	cout << (ans * S.size()) - (S.size() - (last_index + 1));
	return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
long long int __lcm(long long int a,long long int b){
  long long int n;
  n=a*b/__gcd(a,b);
  return n;
}
 //__gcd 最大公約数
 //__lcm 最小公倍数
 //double 少数（変数）
//sqrt 平方根
//ceil 天井関数
//floor 床関数
//abs 絶対値
//pow 累乗
//cbrt  立方根
//hypot 平方和の平方根
 
int main() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(b<c)
    cout<<0;
  else if(d<a)
    cout<<0;
  else
    cout<<min(b,d)-max(a,c);
}

Measured memory_bytes: 256
N = int(input())
ha = [[0]*3 for _ in range(N+1)]
for i in range(N):
  a = list(map(int, input().split()))
  for k in range(3):
    ha[i+1][k] = a[k]

dp = [[0]*3 for _ in range(N+1)]
for i in range(1,N+1):
  for j in range(3):
    for k in range(3):
      if j != k:
        dp[i][j] = max(dp[i][j], dp[i-1][k] + ha[i][j])
ans = 0
for i in range(3):
  ans = max(ans,dp[N][i])
print(ans)

Measured memory_bytes: 68332
#n=int(input())
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
import math
import itertools
from collections import defaultdict
from collections import Counter
import numpy as np

import heapq


n,k=list(map(int,input().split()))
ans=[True for _ in range(n)]
for _ in range(k):
    c=input()
    a=list(map(int,input().split()))
    for each in a:
        ans[each-1]=False

print(sum(ans))


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

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

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int x;
    cin >> x;
    int ans = 0;
    int a = x / 500;
    ans += a * 1000;
    x -= a * 500;
    ans += (x / 5) * 5;
    cout << ans << endl;
    return 0;
}



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

int main()
{
    string s;

    cin >> s;

    int cnt = 0;
    for( int i = 0; i < s.size(); i++ )
    {
        if( s[i] == '(' )
            cnt++;
        else if( s[i] == ')' )
            cnt--;
        else
            break;
    }
    cout << cnt << endl;
    
    return 0;
}



Measured memory_bytes: 3216
/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
unordered_map<int,unordered_set<int> > R;
unordered_map<int,unordered_set<int> > B;

void solve(){
	int n,ans=0;
	cin >> n;
	vector<pair<int,int> > red(n),blue(n);
	for(int i = 0 ;i < n ; i++)cin >> red[i].second >> red[i].fi;
	for(int i = 0 ;i < n ; i++)cin >> blue[i].se >> blue[i].fi;
	
	sort(all(red));
	sort(all(blue));
	VI u(n,0);
	for(int i=0;i<n;i++){
		int mx=-1e9,tar=-1;
		for(int j=0;j<n;j++){
			if(u[j])continue;
			if(red[j].fi<blue[i].fi&&red[j].se<blue[i].se&&red[j].se>mx){
				mx = red[j].se;
				tar = j;
			}
		}
		if(tar!=-1){
			ans++;
			u[tar]=1;
		}
	} 
	cout<<ans<<endl;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}

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

const int MAX = 1000005;

int main(){
  int n, flag = 0;
  cin >> n;
  vector<int> A(n);
  for(int i = 0; i < n; i++) cin >> A.at(i);
  
  sort(A.begin(),A.end());
  vector<int> B(MAX); 
  for(int i = 0; i < n; i++){
    if(B.at(A[i]) != 0){
      B.at(A[i]) = 2;
      continue;
    }
    for(int j = A[i]; j < MAX; j += A[i]) B.at(j)++;
  }
 
  int ans = 0;
  for(int i = 0; i < n; i++){
    if(B.at(A[i]) == true) ans++;
  }

  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 7836
while True:
    n,x=map(int,input().split())
    if n==0 and x==0:
        break
    sum=0
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            for k in range(j+1,n+1):
                if i+j+k==x:
                    sum+=1
    print(sum)



Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fr first
#define sc second
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=3e5+10;
int main()
{
    FASTINOUT;
    int x;
    cin>>x;
    set<int>s;
    int y;
    while (x--){
        cin>>y;
        if (s.find(y)==s.end())
        s.insert(y);
        else
            s.erase(y);
    }
    cout<<s.size()<<endl;
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,k=0,l=101;
  cin>>N;
  for(int i=0;i<N;i++){
    int j;
    cin>>j;
    k+=j;
    if(j%10!=0)
      l=min(l,j);
  }
  if(l==101)
    cout<<0<<endl;
  else if(k%10==0)
    cout<<k-l<<endl;
  else
    cout<<k<<endl;
}

Measured memory_bytes: 3616
#define _USE_MATH_DEFINES
#include<iostream>
#include<math.h>

using namespace std;

int main()
{
	int walk,ang;
	char c;
	double x=0.0,y=0.0,angle = 90;

	while (cin >> walk >> c >> ang)
	{

		if (walk == 0 && ang == 0) break;
		x += cos(angle*M_PI / 180)*walk;
		y += sin(angle*M_PI / 180)*walk;
		angle -= ang;

	}
	cout << (int)x << endl << (int)y << endl;
}

Measured memory_bytes: 3472
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  ll n;
  cin>>n;
  vector<int> a, b, c;
  int x;
  rep(i,n) {
    cin>>x; a.push_back(x);
  }
  rep(i,n) {
    cin>>x; b.push_back(x);
  }
  rep(i,n) {
    cin>>x; c.push_back(x);
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());
  ll ans = 0;
  rep(i, n) {
    ll up = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
    ll down = c.end() - upper_bound(c.begin(), c.end(), b[i]);
    ans += up * down;
  }
  cout << ans << endl;

  return 0;
}


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

int main() {
  double N;
  cin>>N;
  double a=0;
  float P;
  for(int i=1;i<N+1;i++){
   if(!(i%2==0)){a=a+1;}
  }
  P=a/N;
    printf("%2.8f",P);

  return 0;

  
  
  
}



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

int main() {
	string S;

	cin >> S;

	string ans = "Good";
	for( int i = 0; i < S.size() - 1; i++ ) {
		if( S[i] == S[i + 1] ) {
			ans = "Bad";
			break;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int arr[101][2],n,m,i,j,maxx=0;
int main ()
{
cin>>n;
for (i=1;i<=n;i++) cin>>arr[i][0];
for (i=1;i<=n;i++) cin>>arr[i][1];
for (i=1;i<=n;i++)
{
int sum=0;
for (j=1;j<=i;j++) sum+=arr[j][0];
for (j=i;j<=n;j++) sum+=arr[j][1];
if (maxx<sum) maxx=sum;
}
cout<<maxx;
}

Measured memory_bytes: 3564
#include<iostream>
using namespace std;
int main(){
	int N;
	long A[200000];
	long long sum=0,pre=0,x,y,min,d;
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>A[i];
		sum += A[i];
	}
	min=sum;
	for(int i=0;i<N;i++){
		pre += A[i];
		x=pre;
		y=sum-pre;
		
		if(x<y)d = y-x;
		else if(x>y)d = x-y;
		else d = 0;
		
		if(min>d)min=d;
	}
	cout<<min;
	return 0;
}

Measured memory_bytes: 1792
#define ll long long int
#define pb push_back
#define mp make_pair
#define ln cout<<"\n";
#include <bits/stdc++.h>
using namespace std;

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

	 ll t=1,r,n,a,b,c,x,y,sum,cnt,i,j,k,m,l,q,maxx,minn,temp,ans,flag,g,ts;
	
	 char ch;
	 double dans;
	 string str,ttr;
	 
//	 cin >> t;

	
//	for(ts=1;ts<=t;ts++)
//	{
	     flag=0;sum=0;cnt=0;ans=0;k=0;maxx=0;minn=0;a=0;b=0;temp=0;
	    
	     cin >> n;
	    // ll arr[n];
	    
	    dans=(double)((double)22/7)*2*n;
	    
	     printf("%0.4lf",dans);
	     //ln
	 //}
	return 0;
}


Measured memory_bytes: 3776
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N;
map<int, int> M;
priority_queue<int> que;
int D[2];

int main() {
  INCANT;
  cin >> N;
  int a;
  rep(i, N) {
    cin >> a;
    M[a-1]++; 
  }
  for (auto p: M) {
    int cnt = p.second;
    while(cnt>2) {
      cnt = cnt/3+cnt%3;
      M[p.first] = cnt;
    }
    D[cnt-1]++;
  }
  int SUM = D[0]+D[1];
  SUM-=D[1]%2;
  cout << SUM << "\n";
  return 0;
}

Measured memory_bytes: 4992
/*
 * ARC097_D.cpp
 *
 *  Created on: May 14, 2018
 *      Author: 13743
 */

#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
using namespace std;
typedef long long llong;

#define PB push_back
#define SZ(a) int((a).size())
#define ALL(a) (a).begin(), (a).end
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

int seqP[100001];
vector<int> adjL[100001];
int comps[100001];

void connected(int v, int num) {
	if(comps[v] > 0) return;
	comps[v] = num;
	REP(i, SZ(adjL[v])) {
		connected(adjL[v][i], num);
	}
}

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

	int N, M;
	cin >> N >> M;
	REP(i, N) {
		cin >> seqP[i+1];
	}
	REP(i, M){
		int u, v;
		cin >> u >> v;
		adjL[u].PB(v);
		adjL[v].PB(u);
	}

	int numC = 1;
	FOR(i, 1, N+1) {
		if(comps[i] > 0) continue;
		connected(i, numC);
		++numC;;
	}

	int ans = 0;
	FOR(i, 1, N+1) {
		if(comps[seqP[i]] == comps[i]) {
			++ans;
		}
	}

	cout << ans << endl;
}




Measured memory_bytes: 9600
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
 
bool codejam = 0;
 
typedef long long li;
typedef long double ld;
 
void solve();

int32_t main () {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(20);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	int t = 1; 
	// cin >> t;
	int tt = t;
	while (t--) { 
		if (codejam) cout << "Case #" << tt - t << ": ";
		solve();
	}
	return 0;
}

void solve() {
	int a, b;
	cin >> a >> b;
	if ((a + b) % 2) {
		cout << "IMPOSSIBLE";
	}	
	else {
		cout << (a + b) / 2;
	}
}	

Measured memory_bytes: 256
from collections import deque
N, M = map(int, input().split())
g = [[] for i in range(N+1)]
for _ in range(M):
    A, B = map(int, input().split())
    g[A].append(B)
    g[B].append(A)
Q = deque()
vstd = [0]*(N+1)
mark = [0]*(N+1)
vstd[1] = 1
Q.append(1)
while Q:
    par = Q.popleft()
    for r in g[par]:
        if vstd[r]:
          continue
        else:
          mark[r]=par
          vstd[r]=1
          Q.append(r)
print('Yes')
for mk in mark[2:]:
    print(mk)


Measured memory_bytes: 35716
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<cmath>
#include<bitset>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
const int N=3010,mod=998244353;
int A,B,C,D;
ll f[N][N],sum;
ll ksm(ll x,ll k){ll re=1;for(;k;k>>=1,x=x*x%mod)if(k&1)re=re*x%mod;return re;}
int main(){
	//freopen("a.in","r",stdin);
	scanf("%d%d%d%d",&A,&C,&B,&D);
	f[A][C]=1;
	for(int i=A+1;i<=B;i++){sum=0;
		for(int j=C;j<=D;j++){
			f[i][j]=(f[i-1][j]*j+sum*(i-1))%mod;
			sum=(sum*(i-1)+f[i-1][j])%mod;
		}
	}sum=0;
	for(int i=C;i<=D;i++)sum=(sum+f[B][i]*ksm(B,D-i))%mod;
	cout<<sum;
}

Measured memory_bytes: 73708
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

const mod = 1000000007

var dp []int

func rec(i, N int, m []int) int {
	if dp[i] != -1 {
		return dp[i]
	}
	if i == N {
		return 1
	}
	var r0, r1 int
	if i < N && m[i+1] != 1 {
		r0 = rec(i+1, N, m)
	}

	if i < N-1 && m[i+2] != 1 {
		r1 = rec(i+2, N, m)
	}

	dp[i] = (r0 + r1) % mod
	return dp[i]
}

func main() {
	sc.Split(bufio.ScanWords)

	N, M := getInt(), getInt()
	m := make([]int, N+1)
	dp = make([]int, N+1)
	for i := 0; i <= N; i++ {
		dp[i] = -1
	}

	for i := 0; i < M; i++ {
		a := getInt()
		m[a] = 1
	}

	out(rec(0, N, m))
}


Measured memory_bytes: 18688
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

char s[100];
int main(){
    int n;
    scanf("%s",s);
    n=strlen(s);
    int flag=n%2==0;
    rep(i,0,n){
        flag&=(s[i]==(i%2?'i':'h'));
    }
    puts(flag?"Yes":"No");
}


Measured memory_bytes: 128
def main():
    N,W=map(int,input().split())
    w=[0]*(N+1)
    v=[0]*(N+1)
    for i in range(1,N+1):
        a,b=map(int,input().split())
        w[i]=a
        v[i]=b
    v_sum=sum(v)
    inf=10**12
    dp=[[inf]*(v_sum+1) for _ in range(N+1)]
    for i in range(N+1):
        dp[i][0]=0
    
    for i in range(1,N+1):
        for j in range(1,v_sum+1):
            dp[i][j]=min(dp[i-1][j],dp[i-1][max(0,j-v[i])]+w[i])

    for j in range(v_sum+1):
        if dp[N][j]>W:
            result=j-1
            break
        if j==v_sum:
            result=j
    print(result)

if __name__=="__main__":
    main()

Measured memory_bytes: 119016
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
print(10-n//200)

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    ans += n / i * i * (1 + n / i) / 2;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3616
#include<stdio.h>

int main()
{
	int n = 0,count = 0,result = 0;
	scanf("%d", &n);

	for (int i = 1; i <= n; i += 2)
	{
		for (int j = 1; j <= n; j++)
		{
			if (i % j == 0)
			{
				count++;
			}
		}
		if (count == 8)
		{
			result++;
		}
		count = 0;
	}

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

	return 0;
}

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

using namespace std;

typedef long long lli;

const int N = 200000 + 10;

struct Item
{
	int x, h;
};

Item monster[N];
lli add[N];

bool cmp(const Item& a, const Item& b)
{
	return a.x < b.x;
}

int main()
{
	lli res, s;
	int n, d, a, x, i, j;
	cin>>n>>d>>a;
	d *= 2;
	for (i=0; i<n; i++) 
	{
		cin>>monster[i].x>>monster[i].h;
		if (monster[i].h % a) monster[i].h = monster[i].h / a + 1; else monster[i].h /= a;
	}
	sort(monster, monster + n, cmp);
	res = s = 0;
	for (i=0,j=1; i<n; i++)
	{
		s += add[i];
		if (monster[i].h > s)
		{
			x = monster[i].h - s;
			res += x;
			add[i+1] += x;
			for (; j<n&&monster[j].x-monster[i].x<=d; j++);
			add[j] -= x;
		}
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 3328
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
#include <climits>
#include <chrono>
#include <fstream>
using namespace std;

#pragma region

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

const double PI = acos(-1.0);

using ll = long long;
using P = pair<int, int>;

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter = " ") { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

#pragma endregion


int main() {
    int n, x, t;
    cin >> n >> x >> t;
    int ans = (n + x - 1) / x * t;
    cout << ans << endl;
}

Measured memory_bytes: 3592
h,w=map(int,input().split())
s=h*w
p=s//3
if h%3==0 or w%3==0:
  ans1=0
else:
  ans1=min(h,w)
tw=p//h
s1=tw*h
if h%2==0:
  s2=h//2*(w-tw)
  s3=s2
else:
  s2=h//2*(w-tw)
  s3=s2+(w-tw)
ans2=max(s1,s2,s3)-min(s1,s2,s3)
tw+=1
s1=tw*h
if h%2==0:
  s2=h//2*(w-tw)
  s3=s2
else:
  s2=h//2*(w-tw)
  s3=s2+(w-tw)
ans2=min(ans2,max(s1,s2,s3)-min(s1,s2,s3))
th=p//w
s1=th*w
if w%2==0:
  s2=w//2*(h-th)
  s3=s2
else:
  s2=w//2*(h-th)
  s3=s2+(h-th)
ans3=max(s1,s2,s3)-min(s1,s2,s3)
th+=1
s1=th*w
if w%2==0:
  s2=w//2*(h-th)
  s3=s2
else:
  s2=w//2*(h-th)
  s3=s2+(h-th)
ans3=min(ans3,max(s1,s2,s3)-min(s1,s2,s3))
ans=min(ans1,ans2,ans3)
print(ans)

Measured memory_bytes: 3064
import Control.Applicative
import Control.Monad
import Data.List
import Data.Array
import Data.Char

main = do
  n <- (read::String -> Int) <$> getLine
  let digitSum = sumDigit n
  putStrLn $ if n `mod` digitSum == 0 then "Yes" else "No"

sumDigit::Int -> Int
sumDigit n
  | n == 0 = 0
  | otherwise = n `mod` 10 + sumDigit (n `div` 10)

Measured memory_bytes: 508
import java.util.*;

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

        if((A-B) % 2 == 0)
            System.out.println(Math.abs((A+B)) / 2);
        else
            System.out.println("IMPOSSIBLE");
       
    }
}

Measured memory_bytes: 22356
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		long N = sc.nextLong();
		long K = sc.nextLong();
		//(N/K)回操作を行うことで整数がN%K(NをKで割った余り）となる
		//例：10と3の場合、10/3の3回操作を行うと整数は1となる
		long a = N%K;
		//余りaに対して-KをするとK-aと同じになる
		//（K-a)-Kの操作を行ってもaに戻るだけなので
		//よって答えがaかK-aの小さい方となる
		System.out.println(Math.min(a, K-a));
	}
}


Measured memory_bytes: 35652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n;
  cin >> n;
  ll ans=1;
  for(ll i=1;i*i<=n;i++) {
    ans=i*i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <algorithm>

#define ll long long

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<vector<ll>> v(n, vector<ll>(3));
    for (int i = 0; i < n; i++) {
        cin >> v[i][1] >> v[i][2];
        v[i][0] = v[i][1] + v[i][2];
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    long long ret = 0;
    for (int i = 0; i < n; i++) ret += (i % 2 == 0 ? v[i][1] : -v[i][2]);
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
long long dp[42][(1 << 17) + 2];
int main(){
    long long mod = 1e9 + 7;
    int n, x, y, z;
    cin >> n >> x >> y >> z;
    long long ans = 1;
    dp[0][0] = 1;
    int forbidden = (1 << (x + y + z - 1)) + (1 << (y + z - 1)) + (1 << (z - 1));
    for(int i = 1; i <= n; i++){
    	ans = (ans * 10) % mod;
    	for(int k = 1; k <= 10; k++){
    		for(int mask = 0; mask < (1 << 17); mask++){
    			int now =((mask << k) + (1 << (k - 1))) & ((1 << 17) - 1);
    			if((now & forbidden) != forbidden){
    				dp[i][now] = (dp[i][now] + dp[i - 1][mask]) % mod;
    			}
    		}
    	}
    }
    for(int i = 0;i < (1 << 17); i++){
    	ans = (ans - dp[n][i] + mod) % mod;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 44496
#include <iostream>
#include <fstream>
#include <unistd.h>
#include <sys/stat.h>
#include <stdio.h>
#include <vector>
#include <cmath>
#include <random>
#include <string.h>      //文字列の代入に使う
#include <bits/stdc++.h> //piの利用で必要(M_PI)
#include <algorithm>
#include <climits>
#define rep(i, c) for (int i = 0; i < (int)c; i++) //atcoderの解説コードに利用されていたので，ある程度一般生があるかと思われる．
#define ll long long

//from https://qiita.com/asksaito/items/76b71602dd956b79dbf7
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main()
{
    ll int X;
    std::cin >> X;

    for (int i = X; i < 10000000; i++)
    {
        if (IsPrime(i))
        {
            std::cout << i << std::endl;
            return 0;
        }

    }

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main() {
  int X, A, B;
  scanf("%d %d %d", &X, &A, &B);

  int C = B - A;
  if (C > X) {
    puts("dangerous");
  } else if (C <= 0) {
    puts("delicious");
  } else {
    puts("safe");
  }
}

Measured memory_bytes: 128
import java.util.*;

class Main{
	
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int T = sc.nextInt();
		int min = 1001;
	

		for(int n=0;n<N;n++){
			int c = sc.nextInt();
			int t = sc.nextInt();
			if(t<=T && c<min){
				min = c;
			}
		}
		if(min==1001) System.out.println("TLE");
		else System.out.println(min);
	}
}

Measured memory_bytes: 22608
N, = [int(x) for x in input().split()]
A = [0]*N
B = [0]*N
C = [0]*N
for i in range(N):
  A[i], B[i] = [int(x) for x in input().split()]
  C[i] = A[i]+B[i]
jti = list(range(N))
jti.sort(key=lambda i: C[i])
print(sum([A[i] for i in jti[-1::-2]])-sum([B[i] for i in jti[-2::-2]]))

Measured memory_bytes: 20520
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;


import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;


public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			long N = sc.nextLong() - 1;
			
			LinkedList<Character> s = new LinkedList<Character>();
			while(N >= 0) {
				s.addFirst((char)('a' + (N % 26)));
				N /= 26;
				N -= 1;
			}
			
			for(char c : s) { System.out.print(c); }
			System.out.println();
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}


Measured memory_bytes: 32848
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
 
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int> > VVI;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<bool> VB;
 
int main() {
    int n,p;
    string s;
    cin >> n >> p >> s;
    if(10%p == 0) {
        LL ans = 0;
        rep(i,n) {
            if((s[i] - '0') % p == 0) {
                ans += i + 1;
            }
        }
        cout << ans << endl;
        return 0;
    }

    vector<int> d(n+1);
    int ten = 1;
    for(int i = n-1; i>=0; --i) {
        int a = (s[i]-'0') * ten % p;
        d[i] = (d[i+1]+a) % p;
        ten *= 10; ten %= p; 
    }
    vector<int> cnt(p);
    LL ans = 0;
    for(int i = n;i >= 0 ; --i) {
        ans += cnt[d[i]];
        cnt[d[i]]++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1412
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }

int main(){
    ll A, B;
    cin >> A >> B;
    ll max = -1e18;
    chmax(max, A+B);
    chmax(max, A-B);
    chmax(max, A*B);
    cout << max << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 1000000009
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

int main(){
  ll N;
  cin >> N;
  vector<ll> X(N);
  rep(i, N){
    cin >> X.at(i);
  }
  ll ans = INF;
  rep2(i, 1, 101){
    ll tmp = 0;
    rep(j, N){
      tmp += pow((X.at(j)-i), 2);
    }
    chmin(ans, tmp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
/****************************
*  Developer : joshi08
*  Date  :  22-06-2020
*  Year  :  2020
****************************/

#include <bits/stdc++.h>

#define lli long long int
#define mod 1000000007
#define fi first
#define se second
#define ii pair<lli, lli>
#define mp make_pair
#define endl '\n'
const double PI = 3.141592653589793238460;
lli gcd(lli a, lli b) { if (a == 0) return b; return gcd(b % a, a);}
lli max(lli a, lli b) {if (a > b) return a; else return b;}
lli min(lli a, lli b) {if (a < b) return a; else return b;}
lli power(lli a,lli b) {lli i,p=1; for(i=0;i<b;i++){p*=a;} return p;}

using namespace std;

int main()
{
    ios::sync_with_stdio(false);

	string s;
	cin>>s;
	
	lli i,j,n=0;
	
	for(i=1;i<s.size();i++)
	{
		if(s[i]!=s[i-1])
		{
			break;
		}
	}
	if(i==s.size())
	{
		cout<<"No";
	}
	else
	cout<<"Yes";

    return 0;
}



Measured memory_bytes: 3632
import numpy as np
n,w=map(int,input().split())
wv=[list(map(int,input().split())) for _ in range(n)]
dp=np.zeros(w+1,np.int64)
# dp[j]:重さがwを超えないようにカバンに入れた時の価値の最大
# dp[0]=0
for i in range(n):
      w_=wv[i][0]
      v_=wv[i][1]
      dp[w_:]=np.maximum(dp[w_:],dp[:-w_]+v_)
print(dp[-1])

Measured memory_bytes: 15516
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <string>

const int mod = 1e9+7;

using namespace std;

int main(void){
    int n;
    cin >> n;
    long long ans=0;
    for(int i=0; i<n; i++){
        int l, r;
        cin >> l >> r;
        ans += r-l+1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <array>
#include <valarray>

using namespace std;

int main()
{
    int N;
    scanf("%d\n", &N);
    vector<int> A_inv(N);
    for (int i = 0; i < N; ++i){
        int Ai;
        scanf("%d", &Ai); --Ai; getchar();
        A_inv[Ai] = i;
    }
    set<int, greater<int>> lower;
    set<int> upper;
    long long result = 0;
    for (int i = 0; i < N; ++i){
        int l, u;
        {
            auto lit = lower.upper_bound(A_inv[i]);
            if (lit == lower.end()){
                l = -1;
            }else{
                l = *lit;
            }
            auto uit = upper.upper_bound(A_inv[i]);
            if (uit == upper.end()){
                u = N;
            }else{
                u = *uit;
            }
        }
        result += static_cast<long long>(i + 1) * (A_inv[i] - l) * (u - A_inv[i]);
        lower.emplace(A_inv[i]);
        upper.emplace(A_inv[i]);
    }
    printf("%lld\n", result);
}


Measured memory_bytes: 19712
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <tuple>
#include <queue>
#include <bitset>
#include <unordered_map>
#include <tuple>
#include <utility>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <sys/time.h>

using namespace std;

int main(){
  long long N, Q;
  std::cin >> N >> Q;
  string s;
  std::cin >> s;
  vector<char> t(Q), d(Q);
  for (int i = 0; i < Q; i++) {
    std::cin >> t[i] >> d[i];
  }

  long long l, r;
  l = 0;
  r = N + 1;
  for (int i = Q-1; i >= 0; i--) {
    if (d[i] == 'L') {
      if (s[l-1+1] == t[i]) {
        l++;
      }
      if (r == N+1) {
        continue;
      }
      if (s[r-1] == t[i]) {
        r++;
      }
    } else {
      if (s[r-1-1] == t[i]) {
        r--;
      }
      if (l == 0) {
        continue;
      }
      if (s[l-1] == t[i]) {
        l--;
      }
    }
  }
  std::cout << N - min(N, l + (N+1-r)) << std::endl;
  return 0;
}


Measured memory_bytes: 900
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b)      for(int i=a;i<=b;i++)
#define revp(i,b,a)     for(int i=b;i>=a;i--)
#define endl '\n'

#define ull unsigned long long int

ull n,k,mini,temp;
int main()
{
    
    
    cin>>n>>k;
    if(n%k)
    {
    	n=n%k;
    	while(true)
    	{
    		if(n>k)
    			temp=n-k;
    		else
    			temp=k-n;

    		if(temp<n)
    			n=temp;
    		else
    			break;
    	}
    	cout<<n;
    }
    else
    	cout<<0;
}
	

Measured memory_bytes: 3620
import sys
sys.setrecursionlimit(10**5)
def solve(cake, start, end, n): #end is not included
  s_1 = None
  s_2 = None
  y = start[0]
  while y < end[0] and (not s_1 or not s_2):
    x = start[1]
    while x < end[1] and (not s_1 or not s_2):
      if cake[y][x] == "#":
        if not s_1:
          s_1 = (y, x)
        elif not s_2:
          s_2 = (y, x)
      x += 1
    y += 1
  rtn = 0
  if s_2:
    if s_1[0] != s_2[0]:
      rtn = solve(cake, (s_2[0], start[1]), end, solve(cake, start, (s_2[0], end[1]), n))
    else:
      rtn = solve(cake, (start[0], s_2[1]), end, solve(cake, start, (end[0], s_2[1]), n))
  else:
    y = start[0]
    while y < end[0]:
      x = start[1]
      while x < end[1]:
        cake[y][x] = n
        x += 1
      y += 1
    rtn = n+1
  return rtn
      
H, W, K = map(int, input().split())
C = [list(input()) for _ in range(H)]
k = solve(C, (0, 0), (H, W), 1)
print("\n".join([" ".join([str(x) for x in c]) for c in C]))

Measured memory_bytes: 8872
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
// #include<boost/multiprecision/cpp_int.hpp>
// namespace multiprecisioninteger = boost::multiprecision;
// using cint=multiprecisioninteger::cpp_int;
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
// using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
#define For(i,a,b) for(i=a;i<(ll)b;++i)
#define bFor(i,b,a) for(i=b,--i;i>=(ll)a;--i)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N,0)
#define brep1(i,N) bFor(i,N,1)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define eb emplace_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
#define matoutput(v) do{for(auto outimat:v)output(outimat);}while(0)
const ll mod=1000000007;
// const ll mod=998244353;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}
ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}
ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}
datas solve(datas a,datas b){
  vec v={a.first,a.second,b.first,b.second};
  vrsort(v);
  return datas(v[0],v[1]);
}
int main(){
  ll i,j,N,M;
  cin>>N;
  M=1<<N;
  vec v(M),ans(M);
  pvec ma(M);
  rep(i,M){
    cin>>v[i];
    ma[i]=datas(v[i],0);
  }
  rep(j,N)rep(i,M){
    if(i&(1<<j)){
      ma[i]=solve(ma[i],ma[i^(1<<j)]);
    }
  }
  rep(i,M){
    ans[i]=ma[i].first+ma[i].second;
    if(i)chmax(ans[i],ans[i-1]);
  }
  rep1(i,M)print(ans[i]);
}

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

const int N = 200000;

int n;
int a[N + 5], b[N + 5];

#define lst(x) (x == 1 ? n : x - 1)
#define nxt(x) (x == n ? 1 : x + 1)

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", a + i);
  for (int i = 1; i <= n; ++i) scanf("%d", b + i);

  long long ans = 0;
  for (bool flag = 1; flag; ) {
    flag = false;
    for (int i = 1; i <= n; ++i) if (b[i] > a[i] && b[i] - a[i] >= b[lst(i)] + b[nxt(i)]) {
      flag = true;
      ans += (b[i] - a[i]) / (b[lst(i)] + b[nxt(i)]);
      b[i] = (b[i] - a[i]) % (b[lst(i)] + b[nxt(i)]) + a[i];
    }
  }

  for (int i = 1; i <= n; ++i) {
    if (a[i] != b[i]) {
      printf("-1\n");
      return 0;
    }
  }
  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 1792
n = int(input())

h_list = list(map(int, input().split()))

h_last = 10 ** 9
answer = 'Yes'
for i in range(n):
  h = h_list[n-i-1]
  if h <= h_last:
    h_last = h
  elif h - 1 == h_last:
    h_last = h - 1
  else:
    answer = 'No'
    break

print(answer)

Measured memory_bytes: 14224
#include <cstdio>

int gcd(int a, int b)
{
    int r = -1;
    if(a < b){ //swap
        r = a;
        a = b;
        b = r;
    }
    while(a % b != 0){
        r = a % b;
        a = b;
        b = r;
    }
    return b;
}

int main()
{
    int N;
    scanf("%d", &N);
    int A[N];
    for(int i=0; i<N; i++)
        scanf("%d", &A[i]);
    int gcd_left[N], gcd_right[N];
    gcd_left[0] = A[0];
    gcd_right[N-1] = A[N-1];
    for(int i=1; i<N; i++){
        gcd_left[i] = gcd(A[i], gcd_left[i-1]);
        gcd_right[N-i-1] = gcd(A[N-i-1], gcd_right[N-i]);
    }
    int max = gcd_right[1];
    for(int i=1; i<N-1; i++){
        int r;
        if((r = gcd(gcd_left[i-1], gcd_right[i+1])) > max)
            max = r;
    }
    if(gcd_left[N-2] > max)
        max = gcd_left[N-2];
    printf("%d\n", max);
    return 0;
}


Measured memory_bytes: 1280
#include"bits/stdc++.h"
using namespace std;
int main(){
	string a;
	cin>>a;
	int flag1=0,flag2=0;
	for(int i=0;i<a.length();i++){
		if(a[i]=='A')flag1=1;
		if(a[i]=='B')flag2=1;
	}
	if(flag1==1&&flag2==1)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int N;
int nums[109];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N;
    rep(i,N) cin>>nums[i];
    
    int cnt=0;
    bool flag=1;
    rep(k,100){
        rep(i,N){
            if(nums[i]){
                nums[i]--;
                if(flag){
                    cnt++;
                    flag=0;
                }
            }else{
                flag=1;
            }
        }
        flag=1;
    }
    
    cout1(cnt)
}

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

int main()
{
    ll n;
    cin>>n;
    ll cost[n+1];
    ll dp[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>cost[i];

    }
    dp[n]=0;
    dp[n-1]=abs(cost[n]-cost[n-1]);

    for(int i=n-2;i>0;i--)
    {
        //if(i!=(n-1))
        dp[i]=min((dp[i+1]+abs(cost[i+1]-cost[i])),(dp[i+2]+abs(cost[i+2]-cost[i])));
    }
    //
    cout<<dp[1]<<endl;
}


Measured memory_bytes: 5092
using System;
using System.Linq;
    class Program
    {
        static void Main(string[] args)
        {
            var abk = Console.ReadLine().Split(' ').Select(s=>int.Parse(s)).ToArray();
            var res = 1;
            for(int i=abk[0]; ;i--)
            {
                if(abk[0]%i==0&& abk[1] % i == 0)
                {
                    if(abk[2]==res)
                    {
                        Console.WriteLine(i);
                        return;
                    }
                    res++;
                }
            }
             }
    }

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

using namespace std;

template <class T> inline bool chmax(T &a, T b) { /* {{{ */
  if (a < b) {
    a = b;
    return true;
  }
  return false;
} /* }}} */

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  long long sum_a = 0;
  for (auto &a : A) {
    cin >> a;
    sum_a += a;
  }
  long long ans = 0;
  auto test = [&](long long n) {
    vector<int> M(N);
    for (int i = 0; i < N; i++) {
      M[i] = A[i] % n;
    }
    sort(M.begin(), M.end());
    vector<long long> MS(N);
    MS[0] = M[0];
    for (int i = 1; i < N; i++) {
      MS[i] = MS[i - 1] + M[i];
    }
    vector<long long> MSR(N + 1);
    for (int i = N - 1; i >= 0; i--) {
      MSR[i] = MSR[i + 1] + (n - M[i]);
    }
    long long k = 1e9 + 5;
    for (int i = 0; i < N; i++) {
      if (MS[i] == MSR[i + 1]) {
        k = MS[i];
        break;
      }
    }
    if (k <= K) {
      chmax(ans, n);
    }
  };
  for (long long i = 1; i * i <= sum_a; i++) {
    if (sum_a % i != 0) {
      continue;
    }
    test(i);
    if (sum_a / i != i) {
      test(sum_a / i);
    }
  }
  cout << ans << endl;

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 256
import sys
from operator import itemgetter

input = sys.stdin.readline


def main():
    N = int(input())
    xlr = []
    for i in range(N):
        x, l = [int(x) for x in input().split()]
        xlr.append([x - l, x + l])

    xlr.sort()

    ans = N
    mi = xlr[0][1]
    for i in range(N - 1):
        if xlr[i + 1][0] < mi:
            mi = min(xlr[i + 1][1], mi)
            ans -= 1
        else:
            mi = xlr[i + 1][1]


    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 20128
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
typedef long long ll;

int main(){
    string s; cin>>s;
    int ls = s.size();
    if(s[ls-1]=='s'){
        cout << s << "es" << endl;
    }else{
        cout << s << 's' << endl;
    }
}

Measured memory_bytes: 3604
import java.util.Scanner;


	public class Main {
		
		
		static int n;
		static int m;
		static int x;
		static int[] c = new int[12];
		static int[][] a = new int[12][12];
		static int cur_price;
		static int[] cur_a = new int[12];
		static int ret = Integer.MAX_VALUE;

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
	        
			n = sc.nextInt();
			m = sc.nextInt();
			x = sc.nextInt();
			
			for(int i=0;i<n;i++) {
				c[i] = sc.nextInt();
				for(int j=0;j<m;j++) {
					a[i][j] = sc.nextInt();
				}
			}
			
			dfs(0);
			
			if(ret == Integer.MAX_VALUE) {
				System.out.println(-1);
			}else {
				System.out.println(ret);
			}
			
		}
		
		static void dfs(int i) {
			if(i==n) {
				return;
			}
			
			cur_price += c[i];
			
			boolean isOk = true;
			
			for(int j=0;j<m;j++) {
				cur_a[j] += a[i][j];
				if(cur_a[j]<x) {
					isOk = false;
				}
			}
			
			if(isOk) {
				ret = Math.min(ret, cur_price);
			}
			
			dfs(i+1);
			
			cur_price -= c[i];
			
			for(int j=0;j<m;j++) {
				cur_a[j] -= a[i][j];
			}
			
			dfs(i+1);
		}
		
		
	}


Measured memory_bytes: 37804