akhauriyash/Code-Regression huggingface dataset:
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-04-26 20:24:54
*/

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

#define all(x) (x).begin(),(x).end()
#define rev(x) greater<x>()
#define MOD 1000000007
#define INF 1000000000

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

LL modpower(LL n, LL m, LL mod)
{
    if (m == 0) {
        return 1;
    } else if (m % 2 == 0) {
        LL p = modpower(n, m/2, mod);
        return p*p % mod;
    } else {
        return n*modpower(n, m-1, mod) % mod;
    }
}

LL modinv(LL n, LL mod)
{
    return modpower(n, mod-2, mod);
}

LL modcombination(LL n, LL r, LL mod)
{
    LL ret = 1;

    for (int i = 0; i < r; i++) {
        ret *= (n-i);
        ret %= mod;
        ret *= modinv(i+1, mod);
        ret % mod;
    }

    return ret % mod;
}

int gcd(int k, int l)
{
    if (l > 0) return gcd(l, k%l);
    else return k;
}

struct UnionFind
{
    vector<int> par;

    UnionFind(int n) : par(n) {
        for (int i = 0; i < n; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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

    int cnt['z'-'a'] = {0};
    for (int i = 0; i < s.length(); i++)
        cnt[s[i]-'a']++;

    int ok = 1;
    for (int i = 0; i < ('z'-'a'); i++)
        if (cnt[i] > 1) ok = 0;

    if (ok) cout << "yes" << endl;
    else cout << "no" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main (){
	int N;
	long long int sum=0;
	scanf("%d", &N);
	for (int i=1 ; i<=N ; i++)
	{
		if (i%3==0 || i%5==0)
		{
			continue;
		}
		else {
			sum+=i;
		}
	}
	printf("%lld", sum);
return 0;
}

Measured memory_bytes: 1732
# 頂点および辺の数を入力
N, M = map(int, input().split())
# 辺のリストを作成
list_edge = [[] for _ in range(N + 1)]
for _ in range(M):
    a, b = map(int, input().split())
    list_edge[a].append(b)
    list_edge[b].append(a)

# パスの数を返す関数を定義
def count_path(node, path, list_edge, N):
    # パスの数を初期化
    count = 0
    # 全ての頂点を訪問した場合、、
    if len(path) == N:
        # パスの数に1を加える
        count += 1
    # 全ての頂点を訪問していない場合、、
    else:
        # 現在の頂点から訪問できる各頂点について、、
        for next_node in list_edge[node]:
            # その頂点にまだ訪問していない場合、、
            if next_node not in path:
                # 再帰
                count += count_path(next_node, path + [next_node], list_edge, N)
    # パスの本数を返す
    return count
# パスの本数を出力する
print(count_path(1, [1], list_edge, N))

Measured memory_bytes: 3064
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int n,len,que,a[2005],tmp[2005],ans=2147483647,ord[2005],top,last[2005],some;
inline int length(int left,int right){
	return right-left+1; 
}
inline void add(int lft,int rht){
	some=0;
	if(lft>rht||length(lft,rht)<len){
		return ;
	}
	for(register int i=lft;i<=rht;i++){
		some++;
		tmp[some]=a[i];
	}
	sort(tmp+1,tmp+some+1);
	for(register int i=rht-lft-len+2;i>=1;i--){
		top++;
		last[top]=tmp[i];
	}
}
inline int deal(int x){
	int p=1;
	top=0;
	for(register int i=1;i<=n;i++){
		if(x>a[i]){
			add(p,i-1);
			p=i+1;
		}
	}
	if(top<que){
		return 2147483647;
	}
	sort(last+1,last+top+1);
	return last[que]-x; 
}
int main(){
	scanf("%d%d%d",&n,&len,&que);
	for(register int i=1;i<=n;i++){	
		scanf("%d",&a[i]);
		ord[i]=a[i];
	}
	sort(ord+1,ord+n+1);
	n++;a[n]=-2147483647;
	for(register int i=1;i<n;i++){
		ans=min(ans,deal(ord[i]));
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3880
#include <algorithm>
#include <stdlib.h>
#include <iostream>
#include <cstdio>
using namespace std;

int main() {
    int N, ans;
    scanf("%d", &N);
    int A[N];

    for (int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }
    sort(A, A + N);             // ソートする。

    ans = abs(A[N - 1]) - abs(A[0]);
    
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long 
using namespace std ;
const int inf = 1e9;

signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n,w;
	cin>>n>>w;

	int val[n],wgh[n];
	for(int i=0;i<n;i++) cin>>wgh[i]>>val[i];

	int sum_val = accumulate(val,val+n,0ll);
	vector<int>dp(sum_val+1,inf);

	dp[0] = 0;
	for(int i=0;i<n;i++){
		for(int j=sum_val-val[i];j>=0;j--){
			dp[j+val[i]] = min(dp[j+val[i]],dp[j]+wgh[i]);
		}
	}
	int ans=0;
	for(int i=0;i<=sum_val;i++){
		if(dp[i]<=w) ans=i;
	}
	cout<<ans<<endl; 

	return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "-1" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    string S;
    int K;
    cin >> S;
    cin >> K;
    int N=S.size();
    if(N==1){
        cout << K/2 << endl;
        return 0;
    }
    int Ans=0;
    vector<int> G;
    int now=1;
    REP(i,N){
        if(i==N-1 || S[i]!=S[i+1]){
            G.push_back(now);
            now=1;
        }else{
            now++;
        }
    }
    //REP(i,G.size()){cout << G[i] << " ";}
    if(S[0]==S[N-1]){
            if(G.size()!=1){
            for(int i=1;i<G.size()-1;i++){
                Ans+=K*(G[i]/2);
            }
            Ans+=(K-1)*((G[0]+G[G.size()-1])/2);
            Ans+=G[0]/2;
            Ans+=G[G.size()-1]/2;
        }else{
            Ans+=(K*N)/2;
        }
    }else{
        REP(i,G.size()){
            Ans+=K*(G[i]/2);
        }
    }
    cout << Ans << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const long double PI = (acos(-1));


signed main() {
	string S;
	cin >> S;
	if (S == "ABC")cout << "ARC";
	else cout << "ABC";
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
const int MOD = int(1e9) + 7;

/* dp[wt] = #ways of distributing wt candies to the kids seen so far */
/* dp[i, wt] = #ways of distributing wt candies to [0,i] kids */
/* dp[i, wt] = dp[i - 1, wt] + dp[i - 1, wt - 1] + dp[i - 1 , wt - 2] + ... + dp[i - 1, wt - ai] (wt - ai or 0, whichever is greater) 

--> i is hidden in the way of iteration, making a dp table of K + 1 size and going back
	dp[wt] of previous indices is preserved (still of previous iteration)
*/

int N, K;
int a[101];
int dp[int(1e5) + 2], cum[int(1e5) + 2];

void solve () {
	int l, r;
	for (int i = 1; i <= K; i++)
		dp[i] = cum[i] = 0;
	dp[0] = 1; // for all i, only 1 way to distribute 0 candies
	cum[0] = 1;
	for (int i = 0; i < N; i++) {
		// get the cumulatives right (according to the dp array now, will be used later)
		for (int j = 1; j <= K; j++) {
			cum[j] = cum[j - 1] + dp[j];
			if (cum[j] >= MOD)
				cum[j] -= MOD;
		}
		for (int wt = 0; wt <= K; wt++) { // going back
			l = wt - a[i];
			r = wt; // [l, r) inclusive (this range be increased by dp[wt])
			if (l <= 0)
				dp[wt] = cum[r];
			else {
				dp[wt] = cum[r] - cum[l - 1];
				if (dp[wt] < 0)
					dp[wt] += MOD;
			}
		}
	}
	cout << dp[K] << "\n";
}

int main () {
	cin >> N >> K;
	for (int i = 0; i < N; i++)
		cin >> a[i];
	solve();
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define vll vector<ll>
#define nloop(i,n) for(int i=0;i<n;i++)
#define loop(i,a,b) for(int i=a;i<=b;i++)
#define rloop(i,a,b) for(int i=a;i>=b;i--)
#define fill(i,n) memset(i,n,sizeof i)
#define all(a) a.begin(),a.end()
#define pb(x) push_back(x)
#define sz() size()
#define T(n) while(n--)
#define pll pair<ll,ll>
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define endl '\n'
#define nfs  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll bin_expo(ll a, ll b, ll m){ll res = 1LL;while (b > 0){if(b % 2 == 1){res = (res * a) % m;}a = (a * a) % m; b = b/ 2;}return res;}

const  int MAXn= 3e5+5;
const  long long INF= 1e18;

int main(){
    int t=1;
    //cin>>t;
    T(t){
    int n; cin>>n;
    int k; cin>>k;
    vll v(n),dp(n,INF);
    for(ll &x: v) cin>>x;
    dp[0]=0; 
        for(int i=0;i<n;i++){
            for(int j=i+1;j<=i+k;j++){
                if(j<n) dp[j]=min(dp[j],dp[i]+abs(v[i]-v[j]));
            }
        }
        cout<<dp[n-1];
    }
}

Measured memory_bytes: 1920
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001

int main(){
        int d, t, s; cin >> d >> t >> s;
        if(s*t >= d){
                cout << "Yes" << endl;
        } else cout << "No" << endl;
        return 0;                                                                                                                                          
}

Measured memory_bytes: 3604
import java.util.Arrays;
import java.util.Scanner;

/**
 * Created by Santa on 2016/10/16.
 */
public class Main {

    static int A;
    static int B;
    static int C;

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


        A = scanner.nextInt();

        int[] map = new int[A];
        int[] map2 = new int[A];

        for (int i = 0; i < A; i++) {
            map[i] = scanner.nextInt();
            map2[i] = map[i];
        }

        Arrays.sort(map);

        B  = map[A / 2 - 1];
        C = map[A / 2];

        for (int i = 0; i < A; i++) {
            if((B + C) / 2 < map2[i]) System.out.println(B);
            else System.out.println(C);
        }





    }





}



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

int main(){
    int n;
    cin >> n;
    vector<int> vec(n);
    for (int i = 0; i < n; i++){
        cin >> vec.at(i);
    }
    sort(vec.begin(), vec.end());
    int sum = 0;
    for (int i = 0; i < n - 1; i++){
        sum += vec.at(i);
    }
    if (sum > vec.at(n - 1)){
        cout << "Yes" << endl;
    }
    else
        cout << "No" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int n;
pair<int,int>p[3005];
int P[3005];
int main(){
	while(1){
	scanf("%d",&n);
	if(!n) break;
	for(int i=0;i<n;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		P[i]=a;
		p[i]=make_pair(a,b);
	}
	sort(p,p+n);
	sort(P,P+n);
	int ans=0;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			int a,b,c,d;
			a=p[i].first;
			b=p[i].second;
			c=p[j].first;
			d=p[j].second;
			if(ans>=(a-c)*(a-c)+(b-d)*(b-d)){
				continue;
			}
			int ro1=lower_bound(P,P+n,a+b-d)-P;
			int rp1=lower_bound(P,P+n,c+b-d)-P;
			int wo1=lower_bound(P,P+n,a-b+d)-P;
			int wp1=lower_bound(P,P+n,c-b+d)-P;
			int ro2=upper_bound(P,P+n,a+b-d)-P;
			int rp2=upper_bound(P,P+n,c+b-d)-P;
			int wo2=upper_bound(P,P+n,a-b+d)-P;
			int wp2=upper_bound(P,P+n,c-b+d)-P;
			bool aa=false,bb=false,cc=false,dd=false;
			for(int k=ro1;k<ro2;k++){
				if(p[k].second==b+c-a){
					aa=true;
					break;
				}
			}
			for(int k=rp1;k<rp2;k++){
				if(p[k].second==d+c-a){
					bb=true;
					break;
				}
			}
			for(int k=wo1;k<wo2;k++){
				if(p[k].second==b-c+a){
					cc=true;
					break;
				}
			}
			for(int k=wp1;k<wp2;k++){
				if(p[k].second==d-c+a){
					dd=true;
					break;
				}
			}
			if((aa&&bb)||(cc&&dd)){
				ans=max(ans,(a-c)*(a-c)+(b-d)*(b-d));
			}
		}
	}
	printf("%d\n",ans);
}
	return 0;
}

Measured memory_bytes: 1080
import numpy as np

number = int(input())

if number == 2:
    print(number)
else:
    first = 0
    for i in range(2, number):
        if number%i == 0:
            first = 1
            break
    if first == 0:
        print(number)
    else:
        for i in range(number + 1, 1000000000000):
            flag = 0
            for j in range(2, i):
                if i % j == 0:
                    flag = 1
                    break
            if flag == 0:
                print(i)
                break


Measured memory_bytes: 12424
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		double r = Double.parseDouble(br.readLine());
		double s = r * r * Math.PI;
		double c = 2 * r * Math.PI;
		System.out.printf("%.6f %.6f", s, c);
	}

}

Measured memory_bytes: 24744
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int modPow(ll a, ll n, ll p) { //繰り返し二乗法 a**n % p
  if(!n) return 1;
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
  long long t = modPow(a, n / 2, p);
  return (t * t) % p;
}
int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll ans = 0;
  rep(i, 60){
    ll num = (1LL << i);
    ll cnt = 0;
    rep(j, n) if(num & a[j]) cnt++;
    ll v = (cnt * (n - cnt)) % mod;
    (v *= num % mod) %= mod;
    ans += v;
    ans %= mod;
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		long ans=1;
		
		for(int i=1;i<=n;i++){
			ans*=i;
			if(ans>1000000000+7){
				ans=ans%(1000000000+7);
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define N 101
#define M 51
using namespace std;
int n,m,l;
double p[N],t[N],d[N],mem[M][M];

double nCr(int n, int r){
  if(mem[n][r]!=0)return mem[n][r];
  double a=1;
  for(int i=0;i<r;i++) a*=(n-i)/(i+1.0);
  return mem[n][r]=a;
}

double DP(){
  double dp[N][M]={};
  for(int i=0;i<=m;i++)dp[0][i]=pow(1-p[0],m-i)*pow(p[0],i)*nCr(m,i);
  
  for(int i=1;i<n;i++)
    for(int j=0;j<=m;j++)
      for(int k=0;k<=m;k++)
	if(d[0]+j*t[0]<d[i]+k*t[i]) 
	  dp[i][j]+=dp[i-1][j]*pow(1-p[i],m-k)*pow(p[i],k)*nCr(m,k);

  double res=0;
  for(int i=0;i<=m;i++)res+=dp[n-1][i];
  return res;
}

int main(){
  cin>>n>>m>>l;
  for(int i=0;i<n;i++){
    cin>>p[i]>>t[i]>>d[i];
    p[i]/=100;
    d[i]=l/d[i];
  }
  
  for(int i=0;i<n;i++){
      printf("%.10f\n",DP());
      swap(p[0],p[i+1]);
      swap(t[0],t[i+1]);
      swap(d[0],d[i+1]);    
  }
  return 0;
}

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

using namespace std;

void solve() {
  int n8, n10;
  cin >> n8 >> n10;

  for (auto price = n10 * 10; price < n10 * 10 + 10; ++price) {
    if (static_cast<int>(price * 0.08) == n8) {
      cout << price << endl;
      return;
    }
  }
  cout << -1 << endl;
}

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



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

using namespace std;

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

template<typename T>
vector<T> divisor(T n) {
    vector<T> res;
    for (T i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res.emplace_back(i);
            if (i != n / i) res.emplace_back(n / i);
        }
    }
    return res;
}

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

    ll ans = (ll)divisor(n - 1).size() - 1;
    vector<ll> v = divisor(n);

    for (ll d : v) {
        if (d == 1) continue;
        ll tmp = n;
        while (tmp % d == 0) tmp /= d;
        ans += (tmp % d == 1);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(v) begin(v), end(v)
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,b) FOR(i,0,b)

const int mod = 1e9+7;

int h,w,a,b,ans;
int d[100010];
int fact[500010],inv_fact[500010];

int mod_fact(int n,int mod){
  if(n==0)return 1;
  return mod_fact(n-1,mod)*n%mod;
}

int mod_pow(int x,int k,int mod){
  if(k==0)return 1;
  if(k==1)return x;
  int ret = 1;
  while(k){
    if(k&1)ret=ret*x%mod;
    x=x*x%mod;
    k>>=1;
  }
  return ret;
}

int mod_comb(int n,int r,int mod){
  int a=(fact[n+r]*inv_fact[r])%mod;
  //FOR(i,0,r)a=a*((n-i)%mod)%mod;
  int b=inv_fact[n];
  return (a%mod)*(b%mod)%mod;
}

signed main(){
  cin>>h>>w>>a>>b;

  fact[0]=fact[1]=1;

  for(int i=2;i<h+w;i++){
    fact[i]=(fact[i-1]*i)%mod;
  }
  for(int i = 0;i<h+w;i++){
    inv_fact[i]=mod_pow(fact[i],mod-2,mod);
  }



  for(int i=b;i<w;i++){
    int temp=((fact[i+h-a-1]*inv_fact[i]%mod)*inv_fact[h-a-1])%mod;
    temp = mod_comb(h-a-1,i,mod);
    temp = (temp*((((fact[a+w-i-2]*inv_fact[a-1])%mod)*inv_fact[w-i-1])%mod))%mod;

    ans=(ans+temp)%mod;
  //  cout<<ans<<endl;
  }
  cout<<ans<<endl;




  return 0;
}


Measured memory_bytes: 5888
// 8/22 リアルタイム参加
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;

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

    int ans = 0;
    for (auto s : N) {
        int x = s - '0';
        ans += x;
        ans %= 9;
    }

    if (ans == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3720
package main

import "fmt"

func main() {
	var x, y int
	fmt.Scan(&x, &y)
	a := [13]int{0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1}

	if a[x] == a[y] {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#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++)
typedef long long ll;

int main() {
  string s; cin >> s;
  int p = 700;
  rep(i, s.size()) {
    if (s[i] == 'o') {
      p += 100;
    }
  }
  cout << p <<endl;
}

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

int n;
long long sum[110000];

bool Func(long long key){

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

		long long* f=lower_bound(sum+i,sum+n+1,key+sum[i-1]);
		long long* g=lower_bound(f,sum+n+1,key+*f);

		if(*g&&*g+key-sum[i-1]<=sum[n]){
			return true;
		}
	}
	return false;
}

int main(){

	cin>>n;
	sum[0]=0;

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

	long long left=0,right=sum[n]/3+1,mid;
	long long ans=0;

	while(left<right){

		mid=(left+right)/2;

		if(Func(mid)){
			left=mid+1;
			ans=max(ans,mid);
		}
		else right=mid;

	}

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

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


int main() {
  int n;
  cin >> n;
  vector<int> b(n);
  vector<bool> flag(n,true);
  vector<int> ans;
  rep(i, n) cin >> b[i];
  rep(i, n){
    int cn = 0;
    int num = -1;
    rep(j, n){
      if(flag[j])cn++;
      if(b[j] == cn)num = j;
    }
    if(num != -1){
      flag[num] = false;
      ans.push_back(b[num]);
    }
  }
  rep(i, n){
    if(flag[i]){
      cout << -1 << endl;
      return 0;
    }
  }
  reverse(ans.begin(), ans.end());
  rep(i, n){
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 3596
#include<stdio.h>
#define ioo 300
int main(){
        int a[500]={0},i,j,n,o,flg=0;
        while(scanf("%d",&n)!=EOF){
        if(n==0){
                for(i=0;i<ioo;i++){
                        if(a[i]==0){
                                o=a[i-1];
                                a[i-1]=0;
                                flg=1;
                                break;
                        }
                }
        }
        else if(n!=0){
                for(j=0;j<ioo;j++){
                        if(a[j]==0){
                                a[j]=n;
                                break;
                        }
                }
        }
        if(flg==1)printf("%d\n",o);
        flg=0;
        }
        return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> 
//using namespace boost::multiprecision; 
using namespace std;
#define ll long long int
#define ld long long double
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int, int>
#define pl pair<ll, ll>
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define nl '\n'
#define mp make_pair
#define debug1(x) cout <<#x<<" "<<x<<'\n';
#define debug2(x,y) cout <<#x<<" "<<x <<" "<<#y<<" "<<y <<'\n';
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<'\n';
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define inf 1e18
const int mod = (int)1e9+7;
pair<ll,ll>s4[4]={{-1,0},{1,0},{0,-1},{0,1}};
pair<ll,ll>s8[8]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,1},{1,0},{1,-1}};

void solve() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    
    vector<int>red;
    vector<int>blue;
    vector<int>green;
    
    for(int i=0;i<s.length();i++) {
        if(s[i]=='R')red.pb(i);
        else if(s[i]=='G')green.pb(i);
        else blue.pb(i);
    }
    
    char sum = 'R'+'G'+'B';
    ll count =0 ;
    for(int i=0;i<s.length();i++) {
        for(int j=i+1;j<s.length();j++) {
            if(s[i]!=s[j]) {
                char x = (char)(sum - s[i]-s[j]);
                
                if(x == 'R') {
                    auto it= lower_bound(red.begin(),red.end(),j+1);
                    int k = it-red.begin();
                    count += red.size()-k;
                    if(binary_search(it,red.end(),2*j-i) == true) {
                        count--;
                    }
                }
                else if(x == 'G') {
                    auto it  = lower_bound(green.begin(),green.end(),j+1);
                    int k = it-green.begin();
                    count += green.size()-k;
                    if(binary_search(it,green.end(),2*j-i) == true) {
                        count--;
                    
                    
                    }
                }
                 else  {
                    auto it = lower_bound(blue.begin(),blue.end(),j+1);
                    int k= it-blue.begin();
                    count += blue.size()-k;
                    if(binary_search(it,blue.end(),2*j-i) == true) {
                        count--;
                    }
                }
            }
            
        }
    }
    cout << count <<endl;

}

signed main() {
    boost;
    solve();
}

Measured memory_bytes: 3668
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
int main()
{
  //int n,p; cin >> n >> p;
  string s;cin >> s;
  int n=s.length();
  int p=2019;
  if(p==2||p==5){
    vector<vector<ll>> dp(n+1,vector<ll>(p,0));
    ll res = 0;
    rep(i,n){
      int c = s[i] - '0';
      dp[i+1][c%p]++;
      rep(j,p){
	if(j==0) res += dp[i][j];
	dp[i+1][(j*10+c)%p] += dp[i][j];
      }
    }
    cout << res+dp[n][0] << "\n";
  }
  else{
    ll x = 1;
    map<ll,ll> mp;
    ll sum = 0;
    mp[0]++;
    for(int i=n-1;i>=0;i--){
      ll c = s[i] - '0';
      sum = (sum+(c*x)%p)%p;
      mp[sum]++;
      x = (x*10)%p;
    }
    ll res = 0;
    for(auto m:mp){
      res += (m.second-1)*m.second/2;
    }
    cout << res << "\n";
  }
  return 0;
}


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

namespace AOJ1_5_D
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            for (int i = 1; i < n + 1; i++)
            {
                if (i % 3 == 0 || i.ToString().Contains("3"))
                {
                    Console.Write(" ");
                    Console.Write(i);
                }
            }
            Console.Write("\n");



            //void call(int n)
            //{
            //    int i = 1;
            //CHECK_NUM:
            //    int x = i;
            //    if (x % 3 == 0)
            //    {
            //        cout << " " << i;
            //        goto END_CHECK_NUM;
            //    }
            //INCLUDE3:
            //    if (x % 10 == 3)
            //    {
            //        cout << " " << i;
            //        goto END_CHECK_NUM;
            //    }
            //    x /= 10;
            //    if (x) goto INCLUDE3;
            //    END_CHECK_NUM:
            //    if (++i <= n) goto CHECK_NUM;

            //    cout << endl;
            //}

        }
    }
}



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

class UnionFind {
public:
    vector<int>rank, parent;
    //初期化
    UnionFind(int size) {
        rank.resize(size, 0);
        parent.resize(size, 0);
        rep(i, size)parent[i] = i;
    }
    //木の根を求める
    int find(int x) {
        if (parent[x] == x)return x;
        else return parent[x] = find(parent[x]);
    }
    //xとyの属する集合を併合
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y)return;
        if (rank[x] < rank[y])
            parent[x] = y;
        else {
            parent[y] = x;
            if (rank[x] == rank[y])rank[x]++;
        }
    }
    //xとyが同じ集合に属するか否か
    bool same(int x, int y) {
        return (find(x) == find(y));
    }
};

int main()
{
    int N, M, K;
    cin >> N >> M >> K;

    UnionFind uf(N);
    map<int, int> size;
    vector<vector<int>> edges(N);
    vector<vector<int>> blocks(N);
    rep(i, M) {
        int A, B;
        cin >> A >> B;
        A--; B--;
        edges[A].push_back(B);
        edges[B].push_back(A);
        uf.unite(A, B);
    }
    rep(i, K) {
        int C, D;
        cin >> C >> D;
        C--; D--;
        blocks[C].push_back(D);
        blocks[D].push_back(C);
    }
    rep(i, N) size[uf.find(i)]++;
    rep(i, N) {
        int tot = size[uf.find(i)] - edges[i].size() - 1;
        for (int block : blocks[i])if (uf.same(i, block))tot--;
        cout << tot << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 13184
package main

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

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func gcd(x, y int) int {
	for y > 0 {
		x, y = y, x%y
	}
	return x
}

func lcm(x, y int) int {
	g := gcd(x, y)
	if x%g == 0 {
		return x / g * y
	}
	return y / g * x
}

func main() {
	n := readInt()
	ans := 1
	for i := 0; i < n; i++ {
		t := readInt()
		ans = lcm(ans, t)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
import scala.io.StdIn.readInt
import scala.io.Source.stdin

object Main {
  def main(args: Array[String]) = {
    val list = stdin.getLines().map { _.toInt }
    val n = list.next()
    val r0 = list.next()
    val r1 = list.next()
    var max = r1 - r0
    var min = if(r0 > r1) r1 else r0
    for( m <- list ) {
      if( max < m - min) {
        max = m - min
        if( min > m )
          min = m
      }
      else if( min > m ) {
        min = m
      }
    }
    println(max)
  }
}

Measured memory_bytes: 64720
#include <bits/stdc++.h>
    #define rep(i,n) for(int i = 0; i < (n); i++)
     
    using namespace std;  
    
    int main() {
     double r;
     cin >> r;
     const double PI=3.141592653589;
     
     double s =r*r*PI;
     double rr = 2*PI*r;
     printf("%lf %lf \n",s,rr);
     return 0;
    }


Measured memory_bytes: 3200
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main
{
	public static void main(String[] args) throws IOException
	{
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt() * 4;
		int b = sc.nextInt() * 2;
		int c = sc.nextInt() * 1;
		int two = sc.nextInt();
		int wanted = sc.nextInt();
		int single = Math.min(a, Math.min(b, c));
		if(single * 2 < two)
		{
			System.out.println(wanted*1l*single);
		}
		else
		{
			long ans = 1l*(wanted/2) * two + 1l*single * (wanted%2);
			System.out.println(ans);
		}
		
		
	}
	static class Scanner{
		StringTokenizer st;BufferedReader br;
		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}
		public String next() throws IOException 
		{while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());return st.nextToken();}
		public int nextInt() throws IOException {return Integer.parseInt(next());}
		public long nextLong() throws IOException {return Long.parseLong(next());}
		public String nextLine() throws IOException {return br.readLine();}
		public double nextDouble() throws IOException {return Double.parseDouble(next());}
		public boolean ready() throws IOException {return br.ready();}
	}
}


Measured memory_bytes: 23252
#include <stdio.h>

int uruu (int i){
    if (i % 400 == 0) {
        return 1;
    }
    else if (i % 100 == 0){
        return 0;
    }
    else if (i % 4 == 0){
        return 1;
    }
    else {
        return 0;
    }
    
}
int main(){
    int a, b, i, j = 0;
    int counter;
    while (1) {
        counter = 0;
        scanf("%d %d",&a, &b);
        if (a == 0 && b == 0) {
            break;
        }
        if (j != 0) {
            printf("\n");
        }
        for (i = a; i <= b; i++) {
            if (uruu (i) == 1) {
                printf("%d\n",i);
                counter++;
            }
        }
        if (counter == 0) {
            printf("NA\n");
        }
        j++;
    }
    return 0;
}

Measured memory_bytes: 616
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--) 
#define Rep(i,a) for(int i = 0; i < a; i++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ab(x) ((x) < 0 ? -(x) : (x))
using namespace std;
typedef long long LL;
typedef map<int, int>::iterator mit;
typedef set<int>::iterator sit;

const int N = 2010, mod = 1e9 + 7;
int f[N << 1][N];

int main() {
	int n, m, k; scanf("%d%d%d",&n,&m,&k);
	rep(j,0,n) f[0][j] = 1; int ans = 0;
	rep(i,1,n + m) rep(j,0,n) {
		int l = max(j - (k - 1), 0), r = j;
		f[i][j] = (f[i - 1][r] - (l > 0 ? f[i - 1][l - 1] : 0)) % mod;
		int rev = (k - 1) * i - j;
		if (rev <= m - 1 && j % (k - 1) == n % (k - 1) && rev % (k - 1) == (m - 1 + (k - 1)) % (k - 1))
			(ans += ((f[i][j] - f[i - 1][j]) % mod + (j ? f[i - 1][j - 1] : 0)) % mod) %= mod;
		if (j) f[i][j] = (f[i][j] + f[i][j - 1]) % mod;
	}
	if (ans < 0) ans += mod;
	cout <<ans<<endl;
	return 0;
}

Measured memory_bytes: 31616
#include<stdio.h>

int main(void){
  int k,a,b;
  scanf("%d",&k);
  scanf("%d %d",&a,&b);
  if(k==1){
    printf("OK\n");
    return 0;
  }else if(k==2){
    if((b-a)==2){
      printf("OK\n");
      return 0;
    }
  }else if(k>b){
    printf("NG\n");
    return 0;
  }else{
    while(a<=b){
      if(a%k==0){
		printf("OK\n");
        return 0;
      }
      a++;
    }
  }
  printf("NG\n");
  return 0;
}

Measured memory_bytes: 1664
#include <iostream>
using namespace std;
int main(){
	int n,m;
	while(cin>>n>>m){
		if(m==0&&n==0)break;
		bool pp[1001];
		for(int i=0;i<n;++i)pp[i]=true;
		for(int i=0,count=0,erase_count=0;erase_count<n-1;i=(i+1)%n){
			if(!pp[i])continue;
			if(count%m==0&&count!=0){
				pp[i]=false;
				erase_count++;
			}
			++count;
		}
		for(int i=0;i<n;++i)if(pp[i])cout<<((i==0)?n:i)<<"\n";
	}
	return 0;
}

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

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())

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



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

  int a[3];
  REP(i, 3) {
    cin >> a[i];
  }
  sort(a, a + 3);

  if((2 * a[2] - a[1] - a[0]) % 2) {
    cout << (2 * a[2] - a[1] - a[0]) / 2 + 2;
  }
  else {
    cout << (2 * a[2] - a[1] - a[0]) / 2;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		while(true){
			long n = stdIn.nextLong();
			if(n == 0){
				break;
			}
			int count = 0;
			while(n != 1){
				if(n % 2 == 0){
					n = n / 2;
				}else if(n % 2 == 1){
					n = n * 3 + 1;
				}
				count++;
			}
			System.out.println(count);
		}
	}
}

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

int main() {
  int n;
  cin >> n;
  string ans = "";
  while (n != 0) {
    if (n % 2 == 0) {
      ans.insert(ans.begin(), '0');
    } else {
      ans.insert(ans.begin(), '1');
      n--;
    }
    n /= -2;
  }
  if (ans == "") ans = "0";
  cout << ans << endl;
}

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

struct Mod
{
    static const auto P = int(1e9+7);
    long long k;

    Mod() = default;
    Mod(const long long k) : k(k%P) {}
};

Mod operator+(const Mod a, const Mod b) { return a.k + b.k; }
Mod operator-(const Mod a, const Mod b) { return a.k - b.k + Mod::P; }
Mod operator*(const Mod a, const Mod b) { return a.k * b.k; }
Mod& operator+=(Mod& a, const Mod b) { return a = a+b; }
Mod& operator-=(Mod& a, const Mod b) { return a = a-b; }

int main()
{
    int N, M; cin >> N >> M;

    N--; M--;

    auto ways = array<vector<Mod>, 2>{};
    for (auto& xs : ways) xs = vector<Mod>(N+1);
    for (auto r = 1; r <= N; r++) ways[false][r] = 1;
    ways[true][0] = 1;

    for (auto m = 0; m < M; m++)
    {
        const auto previous = ways;

        for (const auto minimized : {false, true})
        {
            for (auto r = 0; r <= N; r++)
            {
                ways[minimized][r] = 2*previous[minimized][r];
                if (r+1 <= N) ways[minimized][r] += previous[minimized][r+1];
                if (r-1 >= 0) ways[minimized][r] += previous[minimized][r-1];
            }
        }

        ways[true][0] += previous[false][1];
        ways[false][0] -= previous[false][1];
    }

    cout << (4*accumulate(begin(ways[true]), end(ways[true]), Mod(0))).k << endl;
}


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

bool all_seen(vector<bool> seen) {
  auto f = [](bool v_seen) { return v_seen == true; };
  return all_of(seen.begin(), seen.end(), f);
}

void dfs(int &cnt, vector<vector<int>> &graph, vector<bool> seen, int v) {
  // 頂点vを訪問済みとする
  seen.at(v) = true;

  // ベースケース
  // 全頂点を巡回できる経路の場合、インクリメントする
  if (all_seen(seen)) {
    cnt++;
  }

  // 再帰ステップ
  // 頂点vから行ける各頂点 next_v について DFS で探索する
  for (auto next_v : graph.at(v)) {
    // next_v が探索済みの場合はスキップ
    if (seen.at(next_v) == true) { continue; }
    dfs(cnt, graph, seen, next_v);
  }
}

int main() {
  // 頂点数と辺数
  int n, m;
  cin >> n >> m;

  // グラフ入力受取
  vector<vector<int>> graph(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--; // 0-indexed
    graph.at(a).push_back(b);
    // 無向グラフのため、逆方向の辺も true とする
    graph.at(b).push_back(a);
  }

#ifndef ONLINE_JUDGE
  for (int i = 0; i < n; i++) {
    cout << "# loop start" << endl;
    for (auto a : graph.at(i)) {
      cout << i << " " << a << endl;
    }
  }
#endif

  // 全頂点を「未訪問」に初期化する
  vector<bool> seen(n, false);

  // 頂点0 (0-indexed) を始点として探索を開始
  int cnt = 0;
  dfs(cnt, graph, seen, 0);

  cout << cnt << endl;
  return 0;
}


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

const int INF = 1e9;
using Edge = pair<int,int>;
using Graph = vector<vector<Edge> >; 

template<typename T>
vector<T> dijkstra(const Graph &G, int s){
    vector<T> dist((int)G.size(),INF);
    priority_queue<Edge, vector<Edge>, greater<Edge>> que;
    dist[s] = 0;
    que.push(make_pair(0,s));//頂点と暫定距離

    while(!que.empty()){
        Edge e = que.top();que.pop();
        int v = e.second;
        if(dist[v] < e.first)continue;
        for(auto p : G[v]){
            if(dist[p.first] > dist[v] + p.second){
                dist[p.first] = dist[v] + p.second;
                que.push(make_pair(dist[p.first],p.first));
            }
        }
    } 
    return dist;
}

int main(){ 
  int n, u, v;
  cin >> n >> u >> v;
  u--; v--;
  Graph g(n);
  rep(i,n-1){
    int u,v;
    cin >> u >> v;
    u--;v--;
    g[u].push_back(make_pair(v,1));
    g[v].push_back(make_pair(u,1));
  }
  auto du = dijkstra<int>(g,u);
  auto dv = dijkstra<int>(g,v);
  int res = 0;
  for (int i = 0; i < n; i++) {
    if (du[i] > dv[i]) continue;
    res = max(res, dv[i]-1);
  }
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 7436
#include <cmath>
#include <cstdio>
#include <vector>
#include <list>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stack>
#include <fstream>
#include <queue>
#include <iomanip>
#include <iterator>
#include <map>
#include <unordered_map>
#include <set>
#define fast ios_base::sync_with_stdio(false)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define crz(v,n) v.clear(),v.resize(n+1,0)
#define print(v) for(ll it=0;it<v.size();it++) cout<<v[it]<<" ";cout<<endl
#define printp(v) for(ll it=0;it<v.size();it++) cout<<v[it].first<<" "<<v[it].second<<endl
using namespace std;
int main(){
	ll a,b;cin>>a>>b;cout<<a/b+(a%b>0)<<endl;
}



Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<cassert>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
const int inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<int, P>PP;
int dp[102][100000];
int M2[100005],M3[100005];

signed main() {
	int n, k; cin >> n >> k;
	map<int, int>M, M1;//M1...nub->id
	for (int i = 1; i*i <= n; i++) {
		int x = n / i;
		M[i] = n / i;
		M[x] = n / x;
	}
	vector<int>v;
	for (auto itr = M.begin(); itr != M.end(); itr++) {
		v.push_back(itr->first);
	}
	int ld = 0;
	rep(i, v.size()) {
		dp[0][i] = v[i];
		M1[v[i]] = i;
		M2[i] = v[i];
		M3[i] = v[i] - ld;
		ld = v[i];
	}

	rep(i, k) {
		rep(j, v.size()) {
			dp[i + 1][j] += dp[i][M1[n / M2[j]]]*M3[j];
			dp[i + 1][j] %= mod;
		}
		rep(j, v.size()) {
			dp[i+1][j + 1] += dp[i+1][j];
			dp[i + 1][j + 1] %= mod;
		}
	}
	cout << dp[k - 1][v.size() - 1] << endl;
}


Measured memory_bytes: 88312
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i > b; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define int long long

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

const int kMaxN = 100002;

int N, A[kMaxN];
int ans;

int d[kMaxN];
int sum = 0;

signed main() {
  cin >> N;
  A[0] = 0;
  REP(i, N) { cin >> A[i+1]; }
  A[N+1] = 0;

  REP(i, N+1) { d[i] = ABS(A[i+1]-A[i]); }
  REP(i, N+1) { sum += d[i]; }

  REP(i, N) {
    ans = sum;
    ans -= d[i]+d[i+1];
    ans += ABS(A[i+2]-A[i]);
    cout << ans << endl;
  }

  return 0;
}


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

using namespace std;

#define MAX 110
#define INF 1e9
typedef pair<int,int> pii;
typedef pair<pii,int> State;

struct Edge{
  int to,cost;
  Edge() {}
  Edge(int to,int cost) : to(to),cost(cost) {}
};

int V,E;
vector<Edge> G[MAX];

int dijkstra(){
  priority_queue<State,vector<State>,greater<State> > Q;
  Q.push(State(pii(0,0),0));
  int dp[MAX][2];
  fill(dp[0],dp[0]+MAX*2,INF);
  dp[0][0] = 0;

  while(!Q.empty()){
    State p = Q.top(); Q.pop();
    int v = p.first.second,s = p.second;

    if(dp[v][s] < p.first.first) continue;

    for(int i = 0 ; i < (int)G[v].size() ; i++){
      if(dp[v][s] + G[v][i].cost < dp[G[v][i].to][s]){
        dp[G[v][i].to][s] = dp[v][s] + G[v][i].cost;
        Q.push(State(pii(dp[G[v][i].to][s],G[v][i].to),s));
      }
      if(s) continue;
      int d = G[v][i].to;
      for(int j = 0 ; j < (int)G[d].size() ; j++){
        if(dp[v][0] < dp[G[d][j].to][1]){
          dp[G[d][j].to][1] = dp[v][0];
          Q.push(State(pii(dp[G[d][j].to][1],G[d][j].to),1));
        }
      }
    }
  }
  return min(dp[V-1][0],dp[V-1][1]);
}

int main(){
  int a,b,c;
  while(cin >> V >> E, V){
    for(int i = 0 ; i < V ; i++){
      G[i].clear();
    }
    for(int i = 0 ; i < E ; i++){
      cin >> a >> b >> c;
      a--, b--;
      G[a].push_back(Edge(b,c));
      G[b].push_back(Edge(a,c));
    }
    cout << dijkstra() << endl;
  }
  return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//exist x map o setconst ll MOD = 1e9+7;return fac[n]*(finv[k]*finv[n-k] % MOD) % MOD;

signed main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n,k,x,y;
    cin >> n >> k >> x >> y;
    if(n<=k)cout<<n*x<<endl;
    else cout << (n-k)*y+k*x << endl;
}


Measured memory_bytes: 3548
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstring>
#include <cassert>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
int n;
vector<string>a;
int dfs(int now, int depth, bool flag){
    int res = 0;
    if(flag)res = 1;
    for(int i = now; i < n and depth < a[i].size(); i++){
        int t = 0;
//        cout << i << " " << depth << " " <<  a[i][depth]<< endl;
        if(isdigit(a[i][depth]))t = a[i][depth]-'0';
        else if(a[i][depth] == '+')t = dfs(i+1,depth+1,false);
        else if(a[i][depth] == '*')t = dfs(i+1,depth+1,true);
        else continue;
        if(flag)res *= t;
        else res += t;
    }
//    cout << now << " " << depth << " " << res << endl;
    return res;
}
int main(){
    while(cin >> n and n > 0){
        a.resize(n);
        rep(i,n)cin >> a[i];
        cout << dfs(0,0,0) << endl;
    }
}


Measured memory_bytes: 3156
#include <iostream>
#include <stack>
using namespace std;
static const int N = 100;
static const int WHITE = 0;
static const int GREY = 1;
static const int BLACK = 2;

int n, M[N][N];
int color[N], d[N], f[N], tt;
int nt[N];


int next(int u) {
	for (int v = nt[u]; v < n; v++) {
		nt[u] = v + 1;
		if (M[u][v]) return v;
	}
	return -1;
}


void dfs_visit(int r) {
	for (int i = 0; i < n; i++) nt[i] = 0;

	stack<int> S;
	S.push(r);
	color[r] = GREY;
	d[r] = ++tt;

	while (!S.empty()) {
		int u = S.top();
		int v = next(u);
		if (v != -1) {
			if (color[v] == WHITE) {
				color[v] = GREY;
				d[v] = ++tt;
				S.push(v);
			}
		}
		else {
			S.pop();
			color[u] = BLACK;
			f[u] = ++tt;
		}
	}
}


void dfs() {
	for (int i = 0; i < n; i++) {
		color[i] = WHITE;
		nt[i] = 0;
	}
	tt = 0;

	for (int u = 0; u < n; u++) {
		if (color[u] == WHITE) dfs_visit(u);
	}
	for (int i = 0; i < n; i++) {
		cout << i + 1 << " " << d[i] << " " << f[i] << endl;
	}
}


int main() {
	int u, k, v;

	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) M[i][j] = 0;
	}

	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		u--;
		for (int j = 0; j < k; j++) {
			cin >> v;
			v--;
			M[u][v] = 1;
		}
	}

	dfs();

	return 0;
}

Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
 
#define FAST ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); 
#define ll long long int 

const int INF = 1<<30;
const ll LINF = 1ll<<60;
const int MOD = 1e9 + 7;

const int MAXN = 2e5 + 10;
vector<int> adj[MAXN];
vector<int> add(MAXN), final(MAXN);
int n, Q;

void dfs(int u = 1, int p = -1){
	//cout  << u << " BB "<< final[u] << '\n';
	if(u == 1) final[u] = add[u];
	for( auto & v: adj[u]){
		if( v != p){
			add[v] += add[u];
			//cout << u << " A "<< v << " " << add[v] << " " << add[u] << '\n';
			final[v] = add[v];
			//cout << final[v] << '\n';
			dfs(v, u);
		}
	}
}

void solve(){
	cin >> n >> Q;
	for( int i = 0, x, y; i < n -1 ; ++i){
		cin >> x >> y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	//now add summ
	while( Q-- ){
		int p, x;
		cin >> p >> x;
		add[p] += x;
	}
	//now just sum while traversing dfs
	dfs();
	for( int i = 1; i <= n; ++i){
		cout << final[i] << " ";
	}

	cout << '\n';
}

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

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

#define fo(i,s,t) for(int i = s; i <= t; ++ i)

int n, a, b;

int main()
{
	cin >> n >> a >> b;
	if(n == 1 && a != b) return 0*printf("0");
	if(a > b) return 0*printf("0");
	printf("%lld",(long long)(n-2)*b-(long long)(n-2)*a+1);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=1;i<=n;i++)
#define pb push_back
#define pf push_front
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
int main()
{
	ios::sync_with_stdio(false);
	int n,cnt=0,cnt2=0;
	cin>>n;
	for (int i=1;i<=n;i++){
		int x;
		cin>>x;
		if (x%4==0) cnt++;
		else if (x%2==0) cnt2++;
	}
	if (cnt2==1) cnt2=0;
	if (cnt2+cnt*2>=n/2*2) cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 256