akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int n,m;
int dp[1<<20];
int count[20][1<<17];
int a[1<<17];
int sum[20];
main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];a[i]--;
		for(int j=0;j<m;j++)count[j][i+1]=count[j][i]+(j==a[i]);
	}
	for(int i=0;i<m;i++)sum[i]=count[i][n];
	for(int i=1;i<1<<m;i++)dp[i]=1e9;
	for(int i=0;i<1<<m;i++)
	{
		int pos=0;
		for(int j=0;j<m;j++)if(i&(1<<j))pos+=sum[j];
		for(int j=0;j<m;j++)
		{
			if(i&(1<<j))continue;
			dp[i|(1<<j)]=min(dp[i|(1<<j)],
					dp[i]+sum[j]-count[j][pos+sum[j]]+count[j][pos]);
		}
	}
	cout<<dp[(1<<m)-1]<<endl;
}

Measured memory_bytes: 15324
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
signed main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    
    ll sum = 0;
    ll cur = 0;
    rep(i, n) {
        if (cur > a[i]) {
            sum += cur - a[i];
        }
        cur = max(cur, a[i]);
    }
    put(sum)

    return 0;
}

Measured memory_bytes: 4816
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define INF 1LL<<62
#define inf 1000000007 

int main() {
	ll n,x;
	cin>>n>>x;
	ll ans=1;
	ll now=0;
	for(ll i=0;i<n;i++){
		ll z;
		cin>>z;
		now+=z;
		if(now<=x){
			ans++;
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
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(){
	cin.tie(0);
	ios::sync_with_stdio(false);

    string s; cin >> s;
	int n = s.size();
	vei cnt(n,0);
	int r = 0; int l = 0; int cntr = 0; int cntl = 0;
	while(r <= n-1) {
		while(s[r] == 'R') { r++; cntr++; }
		cnt[r] += cntr / 2;
		cnt[r-1] += (cntr + 1) / 2;
		l = r;
		while(s[r] == 'L') { r++; cntl++; }
		cnt[l] += (cntl + 1) / 2;
		cnt[l-1] += cntl / 2;
		cntr = 0; cntl = 0;
		l = r;
	}
	rep(i,n) {
		if(i != n-1) cout << cnt[i] << " ";
		else cout << cnt[i] << endl;
	}
	return 0;
    
}

Measured memory_bytes: 1104
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define enld endl

int main() {
	lint H, W;
	while (cin >> H >> W, H != 0) {
		vector<vector<char>>A(H, vector<char>(W));
		rep(i, H) {
			rep(j, W) {
				cin >> A[i][j];
			}
		}
		lint I = 0;
		lint J = 0;
		rep(i, 20000) {
			if (A[I][J] == '>') {
				J++;
			}
			else if (A[I][J] == '<') {
				J--;
			}
			else if (A[I][J] == '^') {
				I--;
			}
			else if (A[I][J] == 'v') {
				I++;
			}
			else if (A[I][J] == '.') {

			}
		}
		if (A[I][J] == '.') {
			cout << J << ' ' << I << endl;
		}
		else {
			cout << "LOOP" << endl;
		}
	}
}


Measured memory_bytes: 3168
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		int tarowSum = 0;

		int hanakoSum = 0;

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

			// 入力を受け取る
			String ta = sc.next();
			String ha = sc.next();

			if(ta.compareTo(ha) > 0)
				tarowSum += 3;

			else if(ta.compareTo(ha) < 0)
				hanakoSum += 3;
			else {	// 引き分けの場合は、プラス1点
				tarowSum++;
				hanakoSum++;
			}
		}
		System.out.println(tarowSum + " " + hanakoSum);
		sc.close();
	}
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int D, N;
  cin >> D >> N;
  int S = 1;
  for(int i = 0; i < D; i++) {
    S *= 100;
  }
  if(N <= 99) {
    cout << S * N << endl;
  } else {
    cout << S * 101 << endl;
  }

  return 0;
}

Measured memory_bytes: 256
/*
  バブルソート
*/
#include <stdio.h>

void swap(int *, int *);

int main()
{
  int i, count = 0, flag = 1, n, ary[100];

  scanf("%d", &n);
  for( i = 0; i<n; i++ )
    scanf("%d", &ary[i]);

  /*バブルソートで昇順にソート*/
  while( flag )
    {
      flag = 0;

      for( i = n-1; i>=1; i-- )
	{
	  if( ary[i] < ary[i-1] )
	    {
	      swap(&ary[i], &ary[i-1]);
	      flag = 1;
	      count++;
	    }
	}
    }

  for( i = 0; i<n; i++ )
    {
      printf("%d", ary[i]);

      if( i != n-1 )
        printf(" ");
    }
  printf("\n%d\n", count);

  return 0;
}

/*引数として与えられた整数 a,b を交換する関数*/
void swap(int *a, int *b)
{
  int tmp;

  tmp = *a;
  *a = *b;
  *b = tmp;
}



Measured memory_bytes: 2104
#include <stdio.h>

int purse[4];//10???,50???,100???,500???
int pay[4];
int bill;

void solve(){
	int i;
	for(i=0;i<4;i++){
		pay[i]=0;
	}
	scanf("%d %d %d %d",&purse[0],&purse[1],&purse[2],&purse[3]);

	if(purse[0]>=(bill%50)/10){
		purse[0]-=(bill%50)/10;
		pay[0]+=(bill%50)/10;
		bill-=(bill%50);

		pay[0]+=(purse[0]/5)*5;
		bill-=(purse[0]/5)*50;
	}else{
		bill+=50-(bill%50);
	}

	if(purse[1]>=(bill%100)/50){
		purse[1]-=(bill%100)/50;
		pay[1]+=(bill%100)/50;
		bill-=(bill%100);

		pay[1]+=(purse[1]/2)*2;
		bill-=(purse[1]/2)*100;
	}else{
		bill+=100-(bill%100);
	}

	if(purse[2]>=(bill%500)/100){
		purse[2]-=(bill%500)/100;
		pay[2]+=(bill%500)/100;
		bill-=(bill%500);

		pay[2]+=(purse[2]/5)*5;
		bill-=(purse[2]/5)*500;
		if(pay[2]<0){
			bill-=pay[2]*100;
			pay[2]=0;
			bill+=500-(bill%500);
			return;
		}
	}else{
		bill+=500-(bill%500);
	}

	if(bill>0)pay[3]=bill/500;
	return;
}

int main(void){
	int flag=0;
	while(scanf("%d",&bill),bill){
		if(flag)printf("\n");
		solve();
		if(pay[0])printf("10 %d\n",pay[0]);
		if(pay[1])printf("50 %d\n",pay[1]);
		if(pay[2])printf("100 %d\n",pay[2]);
		if(pay[3])printf("500 %d\n",pay[3]);
		flag=1;
	}

	return 0;
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<int> V(N);
    rep(i,0,N)cin >> V[i];
    int cnt = 0;
    rep(i,0,N-1){
        if(V[i] == i+1){
            swap(V[i], V[i+1]);
            cnt++;
        }
    }
    if(V[N-1] == N)cnt++;
    cout << cnt << endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

//A Symmetric Point
public class Main{
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			String[] s = sc.next().split(",");
			double x1 = Double.parseDouble(s[0]);
			double y1 = Double.parseDouble(s[1]);
			double x2 = Double.parseDouble(s[2]);
			double y2 = Double.parseDouble(s[3]);
			double x3 = Double.parseDouble(s[4]);
			double y3 = Double.parseDouble(s[5]);
			if(x1==x2){
				x3 = x3+(x1-x3)*2;
				System.out.println(x3+" "+y3);
			}
			else if(y1==y2){
				y3 = y3+(y1-y3)*2;
				System.out.println(x3+" "+y3);
			}
			else{
				double alpha = (y1-y2)/(x1-x2);
				double beta = y1-x1*alpha;
				double x = (2*y3*alpha-2*alpha*beta+x3-alpha*alpha*x3)/(alpha*alpha+1);
				double y = (x3-x)/alpha+y3;
				System.out.println(x+" "+y);
			}
		}
	}
}

Measured memory_bytes: 11000
#include<stdio.h>

int main(){
    int n;
    scanf("%d", &n);
    int h[n];
    for(int i=0; i<n; i++){
        scanf("%d", &h[i]);
    }
    int ans = 0;
    int x=0;
    for(int i=0; i<n; i++){
        if(h[i]>x){
            ans += h[i] - x;
        }
        x = h[i];
    }
    printf("%d", ans);

    return 0;
}

Measured memory_bytes: 128
import sys
import numpy as np 

n = int(sys.stdin.readline().rstrip())
a = np.array(sys.stdin.readline().split(), dtype=np.int64)

def main(a):
    cnt = 0
    while True:
        if np.any(a & 1):
            return cnt
        a //= 2
        cnt += 1

if __name__ == '__main__':
    ans = main(a)
    print(ans)

Measured memory_bytes: 12496
function Main(input){
  // 文字列を格納
  input = input.trim().split('\n');
  tmp = input[1].split(' ');
  let k = parseInt(input[0]);
  let a = parseInt(tmp[0]);
  let b = parseInt(tmp[1]);

  let ans = 'NG';

  for (let i = a; i <= b; i++){
    if (i % k == 0){
      ans = 'OK';
    }
  }

  console.log(ans);
};

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main() {
  string S;
  cin  >> S;
  if(S == "a" || S == "i" || S == "u" || S == "e" || S == "o"){
    cout << "vowel" << endl;
  }else{
    cout << "consonant" << endl; 
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <assert.h>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <math.h>
#include <string>
#include <string.h>
#include <queue>
#include <complex>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
ll mod=998244353;
double eps=1e-7;
ll exp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=(x*x)%mod){if(y&1)ret=(ret*x)%mod;}return ret;}
ull pexp(ull x,ull y){if(y<0) return 0; ull ret=1; for(;y;y>>=1,x=(x*x)){if(y&1)ret=(ret*x);}return ret;}
ll gcd(ll x,ll y){if(!x||!y) return x+y; return x%y==0?y:gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll bsum(ll u,ll b){ll ret=0;if(u<b)return u;while(u){ret+=u%b;u/=b;}return ret;}
ll prival(ll u,ll p){ll cn=0;while(u%p==0){cn++;u=u/p;}return cn;}
ll minv(ll a,ll b){return 1<a?b-minv(b%a,a)*b/a:1;}
ll extm(ll a,ll b){ll ret=0;while(a!=0){if(a%2==1){ret+=b;ret%=mod;}a>>=1;b=(2LL*b)%mod;}return ret;}   
ll eaphi(ll x){ll t=x,ret=x,i;for(i=2;i*i<=x;i++){if(t%i==0){ret-=ret/i;while(t%i==0) t/=i;}}if(t!=1) ret-=ret/t;return ret;}
ll eadivc(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=2;if(x%i==0 && i*i==x) ret+=1;}return ret;}
ll eadivs(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=i+x/i;if(x%i==0 && i*i==x) ret+=i;}return ret;}
ll ndig(ll x, ll b){ll ret=0;while(x){x/=b; ret++;}return ret;}
ll rev(ll n, ll b){ll ret=0;while(n){ret=b*ret+n%b; n/=b;}return ret;}
ll sq(ll x){ll t=(ll)sqrt(x); for(ll i=t-2 ; i<=t+2 ; i++) if(i*i==x) return abs(i); return -1;}
ll extexp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=extm(x,x)){if(y&1)ret=extm(ret,x);}return ret;}
bool isprime(ll x){if(x<=1) return false; for(ll i=2;i*i<=x;i++){if(x%i==0){return false;}}return true;}
char x;

int main(void)
{
	cin>>x;
	if(x=='a' || x=='e' || x=='i' || x=='o' || x=='u') cout<<"vowel";
	else cout<<"consonant"; return 0;
}
// 제출하기 전에 생각햇나요?
// it may be easier/harder than you think
// ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

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

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

    bool s[30] = {};
    int i = 0;
    long long mod = 2;

    while (n != 0) {
        if (n % mod) {
            s[i] = true;
            n -= pow(-2, i);
        }
        i++;
        mod *= 2;
    }

    for (i -= 1; i > 0; i--) cout << s[i];
    cout << s[0] << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s=scan.nextLine();
		int c=0;
		for(int i=0;i<s.length();i++) {
			if(s.charAt(i)=='1') c++;
		}
		System.out.println(c);
	}

}


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

typedef long long ll;

int main()
{
    ll n,a,b,i;
    ll ans = 0;
    cin >> n >> a >> b;
    vector<ll> x(n);
    for(i = 0;i < n;++i){
        cin >> x.at(i);
    }
    for(i = 1;i < n;++i){
        ans += min(a*(x.at(i)-x.at(i-1)),b);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
a, b, c, x, y = map(int, input().split())

ans = 0
if a + b >= 2 * c:
  ans += 2 * c * min(x, y)
  
  if x > y:
    
    if a >= 2 * c:
      ans += (x - y) * 2 * c
    else:
      ans += (x - y) * a
      
  elif x < y:
    
    if b >= 2 * c:
      ans += (y - x) * 2 * c
    else:
      ans += (y - x) * b
      
else:
  ans += a * x + b * y
  
print(ans)

Measured memory_bytes: 3064
num = int(input())
seqs = list(map(int,input().split()))
count = 0
for i in range(num):
    minIndex = i
    for j in range(i,num):
        if seqs[j] < seqs[minIndex]:
            minIndex = j
    if minIndex != i:
        seqs[i],seqs[minIndex]=seqs[minIndex],seqs[i]
        count+=1

print(" ".join(map(str, seqs)))
print(count)



Measured memory_bytes: 5596
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 5011
#define mod 1000000007

int n, i, x, y;
int down[maxN];
vector<int> list[maxN], aux;

ll ans;
ll dp[maxN], loc[maxN], rez[maxN];

void compute_loc(int cnt) {
    int i, j;

    for (i = 0; i <= cnt; i++) loc[i] = 0;
    loc[0] = 1;

    for (i = 1; i <= cnt; i++) {
        for (j = i; j > 0; j--) {
            loc[j] += loc[j - 1] * (cnt - j + 1);
            loc[j] %= mod;
        }
    }
}

void solve() {
    int i, j, cnt;

    dp[0] = 1;
    for (auto v : aux) {
        cnt = v;

        compute_loc(cnt);
        for (i = 0; i <= n; i++) {
            rez[i] = dp[i];
            dp[i] = 0;
        }

        for (i = 0; i <= n; i++) {
            for (j = 0; j <= cnt && j <= i; j++) {
                dp[i] += rez[i - j] * loc[j];
                dp[i] %= mod;
            }
        }
    }

    for (i = 0; i <= n; i++) {
        for (j = 1; i + j <= n; j++)
            dp[i] = (dp[i] * j) % mod;

        if (i % 2 == 1) dp[i] = mod - dp[i];
        ans += dp[i];
    }

    ans %= mod;
    cout << ans;
}

void dfs(int node, int root) {
    bool ok = true;
    down[node] = 1;
    for (auto to : list[node]) {
        if (to == root) continue;
        dfs(to, node);
        down[node] += down[to];
        if (down[to] > n / 2) ok = false;
    }

    if (n - down[node] > n / 2) ok = false;

    if (ok) {
        if (down[node] * 2 == n) {
            ans = 1;
            for (i = 1; i <= down[node]; i++)
                ans = (ans * i) % mod;
            ans = (ans * ans) % mod;
            cout << ans;
            exit(0);
        } else {
            for (auto to : list[node])
                if (to != root)
                    aux.pb(down[to]);
            aux.pb(0);
            if (down[node] != n) aux.pb(n - down[node]);
            solve();
            exit(0);
        }
    }
}

int main()
{
  //  freopen("test.in","r",stdin);

    cin >> n;
    for (i = 1; i < n; i++) {
        cin >> x >> y;
        list[x].pb(y);
        list[y].pb(x);
    }

    dfs(1, 0);


    return 0;
}


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

const int Nmax=200010;

int main() {
	ll Q,H,S,D,N,ans=0;
	cin >> Q >> H >> S >> D >> N;
	D = min(2*S,D);
	D = min(4*H,D);
	D = min(8*Q,D);
	S = min(2*H,S);
	S = min(4*Q,S);
	H = min(2*Q,H);
	for(;;){
      	if(N<2) break;
		N-=2;
		ans += D;
	}
	for(;;){
		if(N<1) break;
		N-=1;
		ans += S;
	}
	N*=4;
	for(;;){
		if(N<2) break;
		N-=2;
		ans += H;
	}
	for(;;){
		if(N<1) break;
		N-=1;
		ans += Q;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<ll>())
#define vfind(v, target) find(v.begin(), v.end(), target)
#define notFound(v, target) (vfind(v, target) == v.end())
#define maxIndex(v) max_element(v.begin(), v.end()) - v.begin()
#define maxElement(v) *max_element(v.begin(), v.end())
#define minIndex(v) min_element(v.begin(), v.end()) - v.begin()
#define minElement(v) *min_element(v.begin(), v.end())
#define ll long long
#define rep(i, s, g) for (ll i = (s); i < (g); i++)
#define MOD 1000000007
using namespace std;

int main()
{
  ll N; cin >> N;
  vector<ll> A(N);
  rep(i, 0, N) cin >> A[i];
  int updown = 0;
  ll ans = 1;
  rep(i, 0, N - 1) {
  	if (updown == 0 && A[i] < A[i + 1]) {
    	updown = 1;
    } else if (updown == 0 && A[i] > A[i + 1]) {
    	updown = -1;
    } else if (updown == -1 && A[i] < A[i + 1]) {
    	ans++;
      	updown = 0;
    } else if (updown == 1 && A[i] > A[i + 1]) {
    	ans++;
      	updown = 0;
    }
  }
  cout << ans << endl;
}

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

using namespace std;

typedef long long ll;

const ll MOD = 1e9+7;

signed main()
{
    string s;
    int d;
    cin >> s >> d;
    int n = s.size();
    vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(d, vector<int>(2, 0)));
    dp[0][0][1] = 1;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < d; ++j){
            for(int k = 0; k < s[i] - '0'; ++k){
                dp[i + 1][(j + k) % d][0] += dp[i][j][1];
                dp[i + 1][(j + k) % d][0] %= MOD;
            }
            dp[i + 1][(j + (s[i] - '0')) % d][1] += dp[i][j][1];
            dp[i + 1][(j + (s[i] - '0')) % d][1] %= MOD;
            for(int k = 0; k < 10; ++k){
                dp[i + 1][(j + k) % d][0] += dp[i][j][0];
                dp[i + 1][(j + k) % d][0] %= MOD;
            }
        }
    }
    cout << (dp[n][0][1] + dp[n][0][0] - 1 + MOD) % MOD << endl;
}


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

long long N;
long long B[100];

int main(){
	cin >> N;
	for(long long i = 0; i < N-1; i++){
		cin >> B[i];
	}

	long long count = B[0] + B[N-2];
	for(long long i = 1; i < N - 1; i++){
		count += min(B[i-1], B[i]);
	}
	cout << count << endl;
}

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

const int INF = 1 << 30;
const int dx[] = { 1, 0, -1, 0 };
const int dy[] = { 0, -1, 0, 1 };

int main()
{
	int N, M;
	while (scanf("%d", &N) != EOF) {
		if (N == 0)
			break;

		set<pair<int, int> > juel;
		for (int i = 0; i < N; ++i) {
			pair<int, int> p;
			scanf("%d %d", &p.first, &p.second);
			juel.insert(p);
		}

		scanf("%d", &M);
		int ans = 0;
		pair<int, int> s = pair<int, int>(10, 10);
		for (int i = 0; i < M; ++i) {
			pair<char, int> d;
			cin >> d.first >> d.second;
			int dir;
			switch (d.first) {
			case 'N':
				dir = 3;
				break;
			case 'E':
				dir = 0;
				break;
			case 'S':
				dir = 1;
				break;
			case 'W':
				dir = 2;
				break;
			}

			for (int j = 0; j < d.second; ++j) {
				s.first += dx[dir];
				s.second += dy[dir];

				set<pair<int, int> >::iterator it = juel.find(s);
				if (it != juel.end()) {
					++ans;
					juel.erase(it);
				}
			}
		}

		if (ans == N)
			printf("Yes\n");
		else
			printf("No\n");

	}

	return 0;
}

Measured memory_bytes: 0
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [0]*N
count = 0

def a_x_b(ab):
  a, b = ab
  return a*b

for n in range(N):
  A[n] = list(map(int, input().split()))
  AB = [(A[n][i], B[i]) for i in range(M)]
  if sum(list(map(a_x_b, AB)))+C > 0:
    count += 1
  else:
    continue
    
print(count)

Measured memory_bytes: 9216
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        double f=1.0*a/b;
        System.out.println(a/b+" "+a%b+" "+String.format("%.8f", f));
    }
}



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

#define rep(i, N) for(int i = 0; i < (int)N; i++)
#define ll long long
const ll INF = 2LL<<60;

int main()
{
    int N, A, B;
    cin >> N >> A >> B;

    int ans = min(N * A, B);
    cout << ans << endl;
}

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

int N;
int A[200000];

signed main() {
  cin >> N ;
  for(int i=0; i<N; i++) cin >> A[i];

  map<int,int> L;
  int ans = 0;
  for(int i=0; i<N; i++) {
    int l = i + A[i];
    int r = i - A[i];
    ans += L[r];
    L[l]++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 27776
#include<iostream>
#include<vector>
using namespace std;
int main() {
	vector<int> a(5);
	for (int i = 0; i < 5; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < 5; i++) {
		if (a[i] == 0) {
			cout << i + 1;
		}
	}
}

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

#ifndef ONLINE_JUDGE 
const bool DEBUG = true;
#else
const bool DEBUG = false;
#endif

// Reads a 1D vector
template <class T>
void read1d(vector<T> & arg) {
	const int l = arg.size();
	for (int i = 0; i < l; ++i) cin >> arg[i];
}

void read() {}
// Reads arbitrary values
template <class T1, class... T2>
void read(T1& var1, T2&... var2) { cin >> var1; read(var2...); }



void pln() { cout << (DEBUG ? "]\n" : "\n"); }
template <class T1, class... T2>
void pln(const T1& var1, const T2& ... var2) { cout << var1 << " "; pln(var2...); }

// Prints arbitrary values and goes to next line
template <class T1, class... T2>
constexpr void print(const T1& var1, const T2& ... var2) { cout << (DEBUG ? " [ " : ""); pln(var1, var2...); }

// Prints arbitrary values and goes to next line ONLY IF IN DEBUG MODE
template <class T1, class... T2>
constexpr void debug(const T1& var1, const T2& ... var2) { if (!DEBUG) return;  cout << " debug : [ "; pln(var1, var2...); }





using ll = long long;
using ull = unsigned long long;


#define all(x) begin(x), end(x)

const bool MULTIPLE_TEST_CASES = 0;

void exec() 
{
	int n;
	read(n);
	if (n % 2 == 0 || n == 5) {
		print(-1); return;
	}

	if (n % 7 == 0) n /= 7;

	int m = 1 % n;
	int ans = 1;
	int tenmod = 10 % n;
	int prev_ten = 1;

	unordered_set<int> remainders;
	remainders.insert(m);

	while (m != 0) {
		prev_ten = (prev_ten * tenmod) % n;
		m = (m + prev_ten) % n;

		if (remainders.count(m)) { print(-1); return; }
		remainders.insert(m);

		++ans;
	}

	print(ans);
}

















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

	if (!MULTIPLE_TEST_CASES)
		exec();
	else {
		int n;
		cin >> n;

		while (n--)
			exec();
	}

    return 0;
}

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

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

typedef struct node * Node;

Node root,NIL;
int maxh;


void insert(int k)
{
  int H;
  Node y=NIL;
  Node x=root;
  Node z;

  z=malloc(sizeof(struct node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;

  while(x!=NIL)
    {
      y=x;
      if(z->key < x->key)
	{
	  x=x->left;
	}
      else
	{
	  x=x->right;
	}
    }

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

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

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

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



Measured memory_bytes: 25152
p = [1]*300003
p[0] = p[1] = 0
for i in xrange(2,300003):
    if p[i] and i%7 == 1 or i%7 == 6:
        p[2*i::i] = [0]*len(p[2*i::i])
    else:
        p[i] = 0
primes = [i for i in xrange(2,300003) if p[i]]

while 1:
    N = int(raw_input())
    if N == 1: break
    ans = []
    for prime in primes:
        if prime > N: break
        if N%prime == 0: ans.append(prime)
    print "%d: %s"%(N," ".join(map(str,ans)))

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

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main() {
    int N,Q; cin >> N>>Q;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];
    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}

Measured memory_bytes: 21736
n = input()
a = len(n)
c = 0
for i in range(a - 1):
    if i % 2 == 0:
        c += 9 * 10 ** i
n = int(n)
if a % 2:
    c += n - 10 ** (a - 1 ) + 1
print(c)

Measured memory_bytes: 2940
n = int(input())
a = list(map(int, input().split()))
cnt_odd = 0
cnt_4 = 0
for i in range(n):
    if a[i] % 2 == 1:
        cnt_odd += 1
    elif a[i] % 4 == 0:
        cnt_4 += 1
if len(a) % 2 == 1 and (cnt_odd - 1) <= cnt_4:
    print('Yes')
elif len(a) % 2 == 0 and cnt_odd <= cnt_4:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 14252
#include <iostream>
#include <string>
using namespace std;
int main()
{
  string w;
  cin>>w;
  for(int i=0;w[i];i++)
    if((('a'<=w[i])&&(w[i]<='z'))||(('A'<=w[i])&&(w[i]<='Z')))
    w[i]=w[i]-'a'+(('A'<=w[i])&&(w[i]<='Z'))*('a'-'A');
  string t;
  int n=0;
  while(1)
  {
    cin>>t;
    if(t=="END_OF_TEXT") break;
    for(int i=0;t[i];i++)
      if((('a'<=t[i])&&(t[i]<='z'))||(('A'<=t[i])&&(t[i]<='Z')))
        t[i]=t[i]-'a'+(('A'<=t[i])&&(t[i]<='Z'))*('a'-'A');

    if(t==w) n++;
  }
  cout<<n<<endl;
}

Measured memory_bytes: 3160
#include <stdio.h>
#include <string.h>
int main(void){
    int i,a=0;
    char s[1000000];
    scanf("%s",s);
    for(i=0;i<strlen(s)-1;i++){
        if(s[i]==s[i+1]){
            if(s[i]=='0'){
                s[i+1]='1';
                a++;
            }
            else{
                s[i+1]='0';
                a++;
            }
        }
    }
    printf("%d",a);
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define base 1000000007LL
#define ll long long
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define CLR(a) memset(a,0,sizeof(a))
#define FOR(i,a,b) for(ll i=(a),_b=(b); i<=_b; i++)
#define FORE(i,a,b) for(ll i=(a),_b=(b); i>=_b; i--)

using namespace std;

typedef pair<ll, ll> II;
typedef vector<II> vi;

set<int> s;
int a, b, c;

int main()
{
    ios::sync_with_stdio(0);
    //freopen("inp.txt", "r", stdin);
    cin >> a >> b >> c;
    s.insert(a);
    s.insert(b);
    s.insert(c);
    cout << s.size();
    return 0;
}


Measured memory_bytes: 256
//2008dC
I;int parse(char *p){switch(*p){
	case'F':return 0;
	case'T':return 1;
	case'-':return!parse(p+1);
	case'(':{
		int x=0;
		char*q=++p;
		for(;;p++){
			if(*p=='(')x++;
			if(*p==')')x--;
			if(x==0&&*p!='-')break;
		}
		switch(*(++p)){
			case'*':return parse(q)&parse(p+1);
			case'+':return parse(q)|parse(p+1);
			case'-':return!parse(q)|parse(p+2);
		}
	}
}return(I>>(*p-97))&1;}
char p[1001],*q;main(){for(;scanf("%s",p),*p-'#';puts(I==2048?"YES":"NO")){for(q=strchr(p,'=')+1,I=0;I<2048;I++)if(parse(p)!=parse(q))break;}exit(0);}

Measured memory_bytes: 552
N,T = gets.split.map(&:to_i)
A = gets.split.map(&:to_i).reverse

maxv = A[0]
V = A[1..-1].map{ |v|
  profit = maxv - v
  maxv = v if v > maxv
  profit
}.max

#p V

vh = {}
puts A.map{ |v|
  vh[v] = 1
  vh[v+V] ? 1 : 0
}.inject(:+)


Measured memory_bytes: 17284
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if((a==1 || b==1) && (a==3 || b==3))
		cout<<2;
	if((a==2 || b==2) && (a==3 || b==3))
		cout<<1;
	if((a==2 || b==2) && (a==1 || b==1))
		cout<<3;
	
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <list>
#include <limits>
#include <numeric>
#include <utility>
#include <deque>
#include <valarray>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#include <array>
#include <bitset>
#include <complex>
#include <string>
#include <tuple>

using namespace std;
using ll = long long;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  int n, k;
  cin >> n >> k;
  cout << n - k + 1 << endl;

  return 0;
}


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

int main(){
  int n;
  cin >>n;
  int num[8]={0};
  int cnt = 0;
  rep(i,n){
    int a; cin >>a;
    if(a<=399) num[0]++;
    else if(a<=799) num[1]++;
    else if(a<=1199) num[2]++;
    else if(a<=1599) num[3]++;
    else if(a<=1999) num[4]++;
    else if(a<=2399) num[5]++;
    else if(a<=2799) num[6]++;
    else if(a<=3199) num[7]++;
    else if(a>=3200) cnt++;
  }
  int ans = 0;
  rep(i,8){
    if(num[i]>0) ans++;
  }
  if(ans==0) cout << 1 << " " << cnt << endl;
  else cout << ans << " " << ans+cnt << endl;
  return 0;
}


Measured memory_bytes: 256
N,M = list(map(int, input().split()))
remove = []
for _ in range(M):
  remove.append(list(map(int, input().split())))

remove = sorted(remove, key=lambda x: x[1])

cnt = 1
for i in range(1,M):
  if remove[i-1][1] > remove[i][0]:
    remove[i][1] = remove[i-1][1]
  else:
    cnt += 1

print(cnt)

Measured memory_bytes: 29844
s = input()
t = input()
idx = 0
ans = 1000
for i in range(len(s) - len(t) + 1):
    k = s[i:i + len(t)]
    cnt = 0
    for j in range(len(t)):
        if t[j] != k[j]:
            cnt += 1
    ans = min(ans, cnt)
print(ans)


Measured memory_bytes: 67380
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others

//Hang in there!

using namespace std;


int main() {
	int N;
	string S;
	cin >> N >> S;
	int ans = 0;
	int sum = 0;
	for (int i = 0; i < N; i++) {
		if (S[i] == 'I') {
			sum++;
		}
		else if (S[i] = 'D') {
			sum--;
		}
		ans = max(ans, sum);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

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

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


int n;
vector<int> E[202020];
VI v(202020);
VI w(202020,0);
VI cnt(2,0);

void dfs(int cu, int pa = -1) {
  for(int to:E[cu]) {
    if (to != pa) {
      v[to]=1-v[cu];
      cnt[v[to]]++;
      dfs(to,cu);
      //
    }
  }
}
int main(){
  int i,j;
  cin>>n;
  for(i=0;i<n-1;i++){
    int a,b;
    cin>>a>>b;
    a--; b--;
    E[a].pb(b);
    E[b].pb(a);
  }
  v[0]=0;
  cnt[0]++;
  dfs(0);
  //for(i=0;i<n;i++) cout<<i+1<<" "<<v[i]<<endl;
  VI r(3);
  r[0]=n/3;
  r[1]=(n+2)/3;
  r[2]=(n+1)/3;
  if(cnt[0]<=r[0]){
    int st=1;
    vector<bool> used(n+1,0);
    for(i=0;i<n;i++){
      if(v[i]==0){
        w[i] = st*3;
        used[st*3]=1;
        st++;
      }
    }
    st=1;
    for(i=0;i<n;i++){
      if(v[i]==1){
        while(used[st]) st++;
        used[st]=1;
        w[i]=st;
      }
    }
  }
  else if(cnt[1]<=r[0]){
    int st=1;
    vector<bool> used(n+1,0);
    for(i=0;i<n;i++){
      if(v[i]==1){
        w[i] = st*3;
        used[st*3]=1;
        st++;
      }
    }
    st=1;
    for(i=0;i<n;i++){
      if(v[i]==0){
        while(used[st]) st++;
        used[st]=1;
        w[i]=st;
      }
    }
  }
  else{
    int s3=3;
    int s0=1;
    int s1=2;
    vector<bool> used(n+1,0);
    for(i=0;i<n;i++){
      if(v[i]==0){
        if(s0<=n) {
          w[i]=s0;
          used[s0]=1;
          s0+=3;
        }
      }
      else {
        if(s1<=n) {
          w[i]=s1;
          used[s1]=1;
          s1+=3;
        }
      }
    }
    int q=1;
    for(i=0;i<n;i++){
      if(w[i]==0){
        while(used[q]) q++;
        used[q]=1;
        w[i]=q;
      }
    }
  }
  for(i=0;i<n;i++){
    cout<<w[i];
    if(i!=n-1) cout<<" ";
    else cout<<endl;
  }
}

Measured memory_bytes: 23424
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


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

  vector<pair<int, int>> v(N);
  REP(i, N) cin >> v[i].first >> v[i].second;

  sort(ALL(v), [](pair<int, int> const & l, pair<int, int> const & r){
      return l.first < r.first;
      });

  int ans = 0;
  REP(i, N){
    if(v[i].second <= M){
      M -= v[i].second;
      ans += v[i].second*v[i].first;
    }else{
      ans += v[i].first*M;
      break;
    }
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    string S;
    cin >> N >> S;
    if(N % 2 == 1) cout << "No" << endl;
    else{
        bool a = true;
        for(int i = 0; i < N / 2; i++){
            if(S[i] != S[i + N / 2]) a = false;
        } 
        if(a == true) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	while(true){
		int n,m; cin>>n>>m;
		if(n==0&&m==0)break;
		vector<int>p(n); for(auto&&i:p)cin>>i; p.emplace_back(0);
		vector<int>b;
		for(int i=0;i<=n;++i){
			for(int j=i;j<=n;++j){
				b.emplace_back(1L*p.at(i)+p.at(j));
			}
		}
		sort(b.begin(),b.end());
		int ans=0;
		for(int i=0;i<n;++i){
			for(int j=i;j<n;++j){
				int L=0,R=b.size(),score=p.at(i)+p.at(j),mx=m-score;
				if(mx<0)continue;
				while(R-L>1){
					int mid=(L+R)/2;
					if(b.at(mid)>mx)R=mid;
					else L=mid;
				}
				score+=b.at(L);
				if(score<=m)ans=max(ans,score);
			}
		}
		cout<<ans<<"\n"s;
	}
}



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

int main() {
  long A, V;
  long B, W;
  long T;
  cin >> A >> V >> B >> W >> T;
  
  long d;
  d = abs(A - B);
  
  if(V - W == 0)
  {
    cout << "NO" << endl;
  }
  else if(W > V)
  {
    cout << "NO" << endl;
  }
  else if( d <= T * (V - W))
  {
    cout << "YES" << endl;
  }
  else
  {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 3636
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef priority_queue<int> p_que;
typedef priority_queue<int, vector<int>, greater<int>()> p_que_rev;
// const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

lint gcd(lint a, lint b) {
    lint r;
    while (b != 0) {
        r = a % b;
        a = b; 
        b = r;
    }
    return a;
}

lint lcm(lint a, lint b) {
    return (a / gcd(a, b)) * b;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<lint> a(n);
    for (int i=0; i<n; ++i){
        cin >> a[i];
    }
    vector<lint> u(n);
    vector<lint> v(n);
    u[0] = a[0];
    v[n-1] = a[n-1];
    lint num = a[0];
    for (int i=1; i<n; ++i){
        u[i] = gcd(u[i-1], a[i]);
    }
    num = a[n-1];
    for (int i=n-2; i>=0; --i){
        v[i] = gcd(v[i+1], a[i]);
    }
    /*
    for (int i=0; i<n; ++i){
        cout << u.at(i) << " ";
    }
    cout << endl;
    for (int i=0; i<n; ++i){
        cout << v.at(i) << " ";
    }
    cout << endl;
    */
    lint ans = a[0];
    for (int i=1; i<n; ++i){
        ans = gcd(ans, a[i]);
    }
    num = a[1];
    for (int i=1; i<n; ++i){
        num = gcd(num, a[i]);
    }
    ans = max(ans, num);
    num = a[0];
    for (int i=1; i<n-1; ++i){
        num = gcd(num, a[i]);
    }
    ans = max(ans, num);
    for (int i=1; i<n-1; ++i){
        ans = max(ans, gcd(u[i-1], v[i+1]));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <functional>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define P(r) do{for(auto i:r){cout<<i<<' ';}cout<<'\n';}while(0)
int main()
{
    int N, M; cin >> N >> M;
    vector<tuple<int, int, int>> edge(M);
    int F[101][101];
    REP(i, N) REP(j, N) F[i][j] = 1000000;
    REP(i, N) F[i][i] = 0;
    REP(i, M) {
        int a, b, c; cin >> a >> b >> c;
        a--, b--;
        edge.emplace_back(a, b, c);
        F[a][b] = min(F[a][b], c);
        F[b][a] = min(F[b][a], c);
    }
    REP(k, N) REP(i, N) REP(j, N) {
        F[i][j] = min(F[i][j], F[i][k] + F[k][j]);
    }
    int ans = 0;
    for(auto tup : edge) {
        int a, b, c;
        tie(a, b, c) = tup;
        if (c > F[a][b]) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int solve(int c, int a, int n){

  if(c < 0 || a < 0 || n < 0) return 0;
  if(c-1 >= 0 && a-1 >= 0 && n-1 >= 0) return  solve(c-1,a-1,n-1)+1;
  else if(c-2 >= 0 && a-1 >= 0) return  max(solve(c-2,a-1,n),solve(c-1,a-1,n-1))+1;
  else if(c-3 >= 0) return  max(solve(c-3,a,n),max(solve(c-2,a-1,n),solve(c-1,a-1,n-1)))+1;
  else return 0;

}

int main(){

  int q;
  int c,a,n;
  cin >> q;
  while(q--){
    cin >> c >> a >> n;
    cout << solve(c,a,n) << endl;
  }
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define deb(x) cout<<#x<<" "<<x<<endl;
#define deb2(x, y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define deb3(x, y, z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define all(x) x.begin(), x.end()
#define sz(a) int((a).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

template <typename T>void print(T v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<v.size(); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto i= v.begin(); i!=v.end(); i++)cout<<setw(w)<<*i<<" ";cout<<endl;}
template <typename T>void print_vv(T v){if(v.size()==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<v[0].size(); j++)cout<<setw(w)<<j<<" ";cout<<endl;for(auto i= 0; i<v.size(); i++){cout<<i<<" {";for(auto j = 0; j!=v[i].size(); j++){cout<<setw(w)<<v[i][j]<<",";}cout<<"},"<<endl;}cout<<endl;}
template <class T, class U> void print_m(map<T,U> m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}

const int nax = 2e5+10;
ll n,u,v;
vvl adj(nax);
vl val(nax), ans(nax), tail;

void dfs(ll x, ll par){
    ll prev = -1;
    auto it = lower_bound(all(tail),val[x]);
    ll idx = it - tail.begin();
    if(it!=tail.end()){
        prev = *it;
        *it = val[x];
    }else{
        tail.push_back(val[x]);
    }

    ans[x] = (int)tail.size();

    for(auto ad: adj[x]){
        if(ad==par) continue;
        dfs(ad, x);
    }

    if(prev!=-1){
        tail[idx] = prev;
    }else{
        tail.pop_back();
    }
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n;
    fore(i,1,n+1) cin>>val[i];
    forn(i,n-1){
        cin>>u>>v;
        adj[u].pb(v), adj[v].pb(u);
    }

    dfs(1,-1);

    fore(i,1,n+1)
        cout<<ans[i]<<endl;

    return 0;
}

Measured memory_bytes: 31580
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int N,K;
    char S[322];
    Scs(S);
    N = strlen(S);
    Scd(K);

    if( K >= N/2 ) {
        printf ("%d\n", N);
        return 0;
    }

    static int dp[301][301][302] = {};

    Rep(ni,N) Rep(mi,N) {
        int mir = N-1-mi;
        bool same = S[ni] == S[mir];
        RRep(ki,K+1){
            // 無変換
            dp[ni+1][mi+1][ki] = max( dp[ni][mi+1][ki], dp[ni+1][mi+1][ki] );
            dp[ni+1][mi+1][ki] = max( dp[ni+1][mi][ki], dp[ni+1][mi+1][ki] );
            dp[ni+1][mi+1][ki] = max( dp[ni][mi][ki]+same, dp[ni+1][mi+1][ki] );
            // 変換
            dp[ni+1][mi+1][ki+1] = max( dp[ni][mi][ki]+1, dp[ni+1][mi+1][ki+1] );
        }
    }

    // Rep(ki,K+1){
    //     Rep(ni,N+1) Rep(mi,N+1){
    //         printf ("%d%s", dp[ni][mi][ki], mi!=N?",":"\n" );
    //     }
    //     printf ("---\n");
    // }

    int ans = 0;
    Rep(ni,N+1) Rep(mi,N+1){
        if( ni + mi > N ) break;
        Rep(ki,K+1){
            ans = max( dp[ni][mi][ki]*2+(ni+mi<N), ans );
        }
    }
    printf ("%d\n", ans );

    return 0;
}

/**
atcodergrandcontest
atcoder
g
atsetnocdn
 *
 */



Measured memory_bytes: 106752