akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

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

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 200000;

int main() {
	int n;
	cin >> n;
	int a[N + 1];
	rep1(i, n) cin >> a[i];
	bool ans[N + 1];
	rep1(i, n) ans[i] = false;
	for(int i = n; i >= 1; i--) {
		int count = 0;
		for(int j = i; j <= n; j += i) {
			if(ans[j]) count++;
		}
		if(a[i] != count % 2) {
			ans[i] = true;
		}
	}
	int m = 0;
	vi v;
	rep1(i, n) {
		if(ans[i]) {
			m++;
			v.push_back(i);
		}
	}
	cout << m << endl;
	if(m == 0) return 0;
	rep(i, v.size() - 1) cout << v[i] << ' ';
	cout << v[v.size() - 1] << endl;
}


Measured memory_bytes: 2552
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

if e-a <= k:
  print('Yay!')
elif b-a > k or c-b > k or d-c > k or e-d > k:
  print(':(')
elif c-a > k or d-b > k or e-c > k:
  print(':(')
elif d-a > k or e-b > k:
  print(':(')
elif e-a > k:
  print(':(')
  

Measured memory_bytes: 3064
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

int n, c;
vector<int> id, ans, cnt;

void construct(int d){
    if(d == n){
        return;
    }

    construct(d + 1);

    ans.push_back(ans.back() ^ (1 << id[d]));
    cnt[d]++;
    if(cnt[d] == (1 << d) && d % 2 == 0 && d <= c - 3){
        swap(id[d+1], id[d+2]);
    }

    construct(d + 1);
}

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

    int a, b;
    cin >> n >> a >> b;

    int x = a ^ b;
    c = 0;
    deque<int> d;
    rep(i, n){
        if((x >> i) % 2){
            c++;
            d.push_front(i);
        }else{
            d.push_back(i);
        }
    }
    if(c % 2 == 0){
        cout << "NO" << endl;
        return 0;
    }

    id = vector<int>(n);
    rep(i, n){
        id[i] = d.front();
        d.pop_front();
    }

    ans.push_back(a);
    cnt = vector<int>(n);

    construct(0);

    cout << "YES" << endl;
    rep(i, SZ(ans)){
        cout << ans[i] << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 2168
#include<cstdio>
#include<algorithm>
#include<vector>
#include <cstdlib>

using namespace std;

int main(){
    
    int ch[50];
    for(int h = 0;h<50;h++){
        ch[h] = 0;
    }
    int nd = 1;
    int i,j;
    int k;
    scanf(" %d", &k);
    for(i = 0;i<k;i++){  
        for( j= 0;j<=nd; j++){
            if(j == nd-1){
                if(ch[j] == 9 ){
                    nd++;
                    ch[nd-1] = 1;
                    j = nd-1;
                    break;
                    
                }
                ch[j]++; 
                break;
            }
            if(abs( (ch[j]+1)%10 -ch[j+1]) <= 1){
                ch[j]++; break;
            }
            
        }
        j--;
        for(;j>=0;j--){
            ch[j] = max(0, ch[j+1]-1);
        }
        // for(int i =nd-1;i>=0;i--){
        //     printf("%d",ch[i]);
        // }
        // printf("  ");
    }
    for(int i =nd-1;i>=0;i--){
        printf("%d",ch[i]);
    }
    printf("\n");
    return 0;
}  

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x)
#define printl(x) cout << (x) << endl
#define rep(i,a,b) for(ll i=a; i<b; i++)
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;

int main(){
    ll S; cin >> S;
    if(S < 1000000000000000000){
    print(0); print(" ");
    print(0); print(" ");
    print(1000000000); print(" ");
    print(1); print(" ");
    print(1000000000 - S%1000000000); print(" ");
    print((S+(1000000000 - S%1000000000))/1000000000); 
    }
    else{
    print(0); print(" ");
    print(0); print(" ");
    print(1000000000); print(" ");
    print(0); print(" ");
    print(1000000000 - S%1000000000); print(" ");
    print((S+(1000000000 - S%1000000000))/1000000000 - 1); 
    }
}

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

using namespace std;

int main() {
  int N, X;
  cin >> N >> X;
  int x = 0;
  int res = 1;
  for (int i = 0; i < N; ++i) {
    int L;
    cin >> L;
    x += L;
    if (x <= X) res++;
    else break;
  }
  cout << res << endl;
}

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

int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s,t;
	cin >> s >> t;
	int n = s.size(), m = t.size();
	vector<vector<int>> dp(n+1,vector<int>(m+1));
	for (int i=1; i<=n; ++i){
		for (int j=1; j<=m; ++j){
			if (s[i-1] == t[j-1]){
				dp[i][j] = dp[i-1][j-1]+1;
			}
			else{
				dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
/*	for (int i=1; i<=n; ++i){
		for (int j=1; j<=m; ++j){
			cout << dp[i][j] << ' ';
		}
		cout << '\n';
	}
*/	int x = n, y = m;
	vector<char> ans;
	while (dp[x][y] != 0){
		if (x-1 >= 0 and y-1 >= 0 and s[x-1] == t[y-1]){
			ans.emplace_back(s[x-1]);
			x--; y--;
		}
		else if (x-1 >= 0 and dp[x-1][y] == dp[x][y]){
			x--;
		}
		else if (y-1 >= 0 and dp[x][y-1] == dp[x][y]){
			y--;
		}
		else break;
	}
//	ans.emplace_back(dp[x][y]);
	reverse(ans.begin(),ans.end());
	for (char c:ans) cout << c;
	return 0;
}


Measured memory_bytes: 73644
#include<bits/stdc++.h>
using namespace std;
long long q,h,s,d,n,x;
int main() {
	ios::sync_with_stdio(false);
	cin >> q >> h >> s >> d >> n;
	x = min(q * 4,min(h * 2,s));
	cout << min(x * n,n / 2 * d + (n & 1) * x) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
struct S{
  double d;
  int u, v, x;
  S(double d, int u, int v, int x) : d(d), u(u), v(v), x(x) {}
};
bool operator < (const S& s, const S& t){
  return s.d > t.d;
}
double sq(double x, double y){
  return x*x + y*y;
}

int main(){
  int N;
  while(cin>>N && N){
    double r, a; cin>>r>>a;
    double x[20], y[20];
    double d[20][20];
    bool ok[20][20][20] = {};
    REP(i, N) cin>>x[i]>>y[i];
    REP(u, N)FOR(v, u, N){
      d[u][v] = d[v][u] = sqrt(sq(x[u] - x[v], y[u] - y[v]));
    }
    REP(u, N)REP(v, N)REP(t, N){
      if(u == v || v == t || t == u) ok[u][v][t] = false;
      else{
        double cot = (x[v] - x[u]) * (x[t] - x[v]) + (y[v] - y[u]) * (y[t] - y[v]);
        cot /= d[u][v];
        cot /= d[v][t];
        /*
        printf("(%.2lf, %.2lf) -> (%.2lf, %.2lf) -> (%.2lf, %.2lf) : cot = %.2lf arccos = %.2lf a = %.2lf cos(a) = %.2lf\n",
            x[u], y[u], x[v], y[v], x[t], y[t], cot, acos(cot), a, cos(a));
            */
        ok[u][v][t] = (cos(a*M_PI/180.0) < cot + EPS);
      }
    }
    priority_queue<S> que;
    FOR(i, 1, N){
      que.push(S(d[0][i], 0, i, 1));
    }
    bool used[20][20][10001] = {};
    int ans = 0;
    while(!que.empty()){
      S s = que.top(); que.pop();
      if(s.d > r + EPS) break;
      if(used[s.u][s.v][s.x]) continue;
      else used[s.u][s.v][s.x] = true;
      ans = max(ans, s.x);
      REP(to, N)if(ok[s.u][s.v][to]){
        que.push(S(s.d + d[s.v][to], s.v, to, s.x + 1));
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()

Int INF = 1e18;
Int mod = 1e9+7;
//Int mod = 998244353;

typedef struct {
    double y, x;
} p_t;

string to_str(Int x) {
    string s = "";
    while (x > 0) {
        char a = '0' + (x % 10);
        s = a + s;
        x /= 10;
    }
    return s;
}

int main() {
    Int h, n;
    cin >> h >> n;
    vector<Int> a(n);
    for (Int i = 0; i < n; i++) {
        cin >> a[i];
    }
    Int sum = 0;
    for (Int i = 0; i < n; i++) {
        sum += a[i];
    }
    dump(h <= sum ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 1024
import sys
from collections import Counter
from collections import deque
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,m=mp()
edge=[lmp() for i in range(m)]
ans=0
for _ in range(m):
    l=[[] for i in range(n+1)]
    que=deque()
    ch=[0]*(n+1)
    ch[0]=1
    for i in range(m):
        if i!=_:
            l[edge[i][0]].append(edge[i][1])
            l[edge[i][1]].append(edge[i][0])
    q=1
    que.append(l[q])
    ch[1]=1
    while len(que):
        q=que.pop()
        for j in range(len(q)):
            if ch[q[j]]==0:
                que.append(l[q[j]])
                ch[q[j]]=1
    b=0
    for k in range(n+1):
        if ch[k]==0:
            b=1
    if b==1:
        ans+=1
print(ans)

Measured memory_bytes: 40944
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
using namespace std;
typedef pair<int, int> P;

signed main(){
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    rep(i, 0, n) cin >> a[i] >> b[i];
    int ans = 0;
    repb(i, n - 1, 0){
        a[i] += ans;
        // cout << a[i] << endl;
        ans += (b[i] - a[i] % b[i]) % b[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
 
using namespace std;
 
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define endl '\n'
#define debug(n1) cout<<n1<<endl
ll x,y;
 
int main() {
cin>>x>>y;
ll z=(x*y)/__gcd(x,y);
if(__gcd(x,y)==y)
    return plld(-1ll),0;
plld(z-x);
    return 0;
           } 

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var (
		a      int
		strict int
	)
	fmt.Scan(&a, &strict)
	count := 0
	for i := 0; i < a; i++ {
		var b int
		fmt.Scan(&b)
		if strict <= b {
			count++
		}
	}
  fmt.Println(count)
}


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

#define ll long long

int main() {
  int n;

  cin >> n;
  for (int i = 1; i <= n; i++) {
    if (i % 3 == 0) {
      cout << " " << i;
      continue;
    }
    int x = i;
    while (x > 0) {
      if (x % 10 == 3) {
        cout << " " << i;
        break;
      }
      x /= 10;
    }
  }
  cout << endl;

  return 0;
}
  

Measured memory_bytes: 1160
n, m = gets.split.map(&:to_i)
as   = m.times.map{ gets.to_i }

MOD = 1000000007

if as.size > 0 and as[0] == 1
  dp = [1, 0]
  j = 1
else
  dp = [1, 1]
  j = 0
end

#
# i: dpを探索
# j: asを探索(なので一致したらインクリメント)
2.upto(n) do | i |
  if j < as.size and as[j] == i
    dp[i] = 0
    j += 1
  else
    dp[i] = (dp[i-1] + dp[i-2])
  end
end

p dp[n] % MOD

Measured memory_bytes: 433020
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	string st;
	cin>>st;
	long j,s,t,ans=0,a[11],i,n=st.size();
	for(i=0;i<n;i++)a[i]=st[i]-48;
	for(i=0;i<1<<n-1;i++)
	{
		s=0;
		t=a[0];
		for(j=0;j<n-1;j++)
		{
			if(i&1<<j)
			{
				t=t*10+a[j+1];
			}
			else
			{
				s+=t;
				t=a[j+1];
			}
		}
		ans+=s+t;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define vi2 vector<vector<int>>
#define vl vector<long long>
#define vl2 vector<vector<long long>>

template <class T> T maxAny(T a, T b){
    if(a > b) return a;
    else return b;
}

template <class T> T minAny(T a, T b){
    if(a > b) return b;
    else return a;
}

int main(){
    int n;
    cin >> n;
    vi2 lst(10, vi(10,0));
    int div = 1;
    rep1(i, n){
        if(div*10==i) div *= 10;
        lst[i/div][i%10]++;
    }
    int ans = 0;
    rep1(i, 9){
        rep1(j, 9){
            ans += lst[i][j]*lst[j][i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
N, W = map(int, input().split())
L = sorted( [ [int(i) for i in input().split()] for _ in range(N) ] )

dp = [0] * (W + 1)
cnt = 0

for w, v in L:
    #重さを足し合わせていき合計を求める
    cnt = cnt + w
    #W=重さの制約とこれまでの重さの合計のうち、
    #小さい方から品物iの重さまで、逆順にfor文を回す
    ##3,8-5,...15-7
    for i in range(min(cnt, W), w - 1, -1):
        #同じ重さでより価値が高い組み合わせがあれば価値を更新する
        ## w < Wの制約があり、i - wとその値を参照してから更新しているため、
        ## Wの制約を満たさない値を持つことはない
        ### 方法上、持ち得ない重さに持ち得ない値がつくことがあるが、
        ### それらが解 = 最大値になることはない
        ### (解を求める過程でついでに足されたり足されなかったりするだけなので)
        if dp[i] < dp[i - w] + v:
            dp[i] = dp[i - w] + v

print(max(dp))


Measured memory_bytes: 9656
from bisect import bisect, bisect_left

n = int(input())
s = list(map(int,input().split()))
s.sort()

ans = 0
for i in range(n-2):
    a = s[i]
    for j in range(i+1,n-1):
        b = s[j]
        k = bisect_left(s,a+b)
        ans += k -j -1
print(ans)

Measured memory_bytes: 3188
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc=new Scanner(System.in);
    	int[] x=new int[10];
    	boolean can = true;
    	for(int i=0;i<3;i++) {
    		x[sc.nextInt()]++;
    	}
    	for(int i=0;i<10;i++) {
    		if(x[i]==2) {
    			can = false;
    			break;
    		}
    	}
    	String s = can?"No":"Yes";
    	System.out.println(s);
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

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

    int a, b;
    cin >> a >> b;

    int ans = 0;
    for(int i = a; i <= b; i++){
        if(i/10000 == i%10 && i/1000%10 == i%100/10) ans++;
    }
    cout << ans << endl;
}


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


int main() {
    int x, y;
    cin >> x >> y;
    if (2 * x <= y&&y<= 4 * x && y % 2 == 0) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
int gcd( int x, int y ){ return y ? gcd(y, x%y) : x; }
signed main() {
int x=0,y=0,z=0,w=0,n=0,m=0;
int a=0,b=0;
std::cin >> a;
rep(i,a){
  std::cin >> x>>y>>z>>w;
  n=x*z+y*w;
  if(z>=5&&w>=2)  m=0.8*x*z+0.8*y*w;
  else if(z>=5) m=0.8*x*z+0.8*y*2;
  else if(w>=2) m=0.8*x*5+0.8*y*w;
  else m=0.8*x*5+0.8*y*2;
  if(n>m)std::cout << m << '\n';
  else std::cout << n << '\n';
}
}



Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

struct state{int to,w;};

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<vector<state>> g(n);
	rep(i,n-1){
		int s,t,w;
		cin>>s>>t>>w;
		g[s].push_back({t,w});
		g[t].push_back({s,w});
	}
	vector<int> dp(n);
	auto dfs1=[&](auto &&dfs1,int v,int pre)->int{
		int ret=0;
		for(auto itr:g[v]){
			if(itr.to==pre) continue;
			chmax(ret,dfs1(dfs1,itr.to,v)+itr.w);
		}
		return dp[v]=ret;
	};
	int ans=dfs1(dfs1,0,-1);
	auto dfs2=[&](auto &&dfs2,int v,int pre)->void{
		int sz=g[v].size();
		vector<int> left(sz+1,0),right(sz+1,0);
		rep(i,sz){
			left[i+1]=max(left[i],dp[g[v][i].to]+g[v][i].w);
		}
		for(int i=sz-1;i>=0;i--){
			right[i]=max(right[i+1],dp[g[v][i].to]+g[v][i].w);
		}
		rep(j,sz){
			if(g[v][j].to==pre) continue;
			int ne=g[v][j].to,w=g[v][j].w;
			int cnt1=dp[v],cnt2=dp[ne];
			dp[v]=max(left[j],right[j+1]);
			chmax(dp[ne],dp[v]+w);
			chmax(ans,dp[ne]);
			//cout<<ne<<' '<<dp[ne]<<endl;
			dfs2(dfs2,ne,v);
			dp[v]=cnt1;
			dp[ne]=cnt2;
		}
	};
	dfs2(dfs2,0,-1);
	cout<<ans<<endl;
}


Measured memory_bytes: 24244
_n = gets.to_i
a = gets.split.map(&:to_i)
max = a.max
sieve = Array.new(max + 1) { |i| i }
prime_division = Array.new(max + 1)

2.upto(Math.sqrt(max).to_i) do |i|
  (max / i).times do |j|
    sieve[i * (j + 1)] = i if i < sieve[i * (j + 1)]
  end
end

2.upto(max) do |i|
  h = Hash.new(0)
  j = i

  while j != 1
    h[sieve[j]] += 1
    j /= sieve[j]
  end

  prime_division[i] = h
end

h = {}
a.each do |e|
  next if e == 1

  prime_division[e].each_key do
    if h[_1]
      puts a.inject(:gcd) == 1 ? 'setwise coprime' : 'not coprime'
      exit
    end

    h[_1] = 1
  end
end

puts 'pairwise coprime'


Measured memory_bytes: 263928
#include <stdio.h>
int main()
{
	int i,j,x,y;
	int sum1,sum2,sum;
	scanf("%d",&i); 
	scanf("%d",&j);
	scanf("%d",&x);
	scanf("%d",&y);
	if(i<=j)
	{
	sum1=i*x;
	sum2=0;		
	}
	if(i>j)
	{
	sum1=j*x;
	sum2=(i-j)*y;	
	}
	sum=sum1+sum2;
	printf("%d\n",sum);
	return 0;
		
}

Measured memory_bytes: 128
#include <iostream>

int main() {
	int r, g, b;
	std::cin >> r >> g >> b;
	if ((r * 100 + g * 10 + b) % 4 == 0) {
		std::cout << "YES" << std::endl;
	}else {
		std::cout << "NO" << std::endl;
	}
	return 0;
}


Measured memory_bytes: 256
N, K = tuple(map(int, input().split(" ")))
P = list(map(int, input().split(" ")))

V = []
for i, p in enumerate(P):
    V.append((p + 1) / 2)

psum = sum(V[:K])
ans = psum
for i in range(K, len(V)):
    psum -= V[i - K]
    psum += V[i]
    ans = max(ans, psum)
print(ans)

Measured memory_bytes: 25060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define nl "\n"
#define rep(i,n) for(ll i=0; i<(n); i++)
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sortup(V) sort(V.begin(), V.end())
#define sortdown(V) sort(V.rbegin(), V.rend())
#define MOD 998244353 //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 (b<a) { a=b; return 1; } return 0; }



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

    // solution comes here

    double N, M;
    cin >> N >> M;
    double T=1900*M + (N-M)*100,  a=0;
    for(ll i=1; i<=1e6; i++) {
        a += i * pow( (pow(2,M)-1)/pow(2,M) , i-1);
    }
    cout << T*a*pow(2,-M) << nl;
}

Measured memory_bytes: 256
import java.util.Map.Entry;
import java.io.*;
import java.util.*;

public class Main {
	
	public static void main(String[] args) throws IOException {
		FastScanner sc = new FastScanner(System.in);
		
		int N = sc.nextInt();
		if(N == 3 || N == 5 || N == 7) System.out.println("YES");
		else System.out.println("NO");
	}
}

class FastScanner {
    private InputStream in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    public FastScanner(InputStream in) {
		this.in = in;
	}
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
    	if (hasNextByte()) return buffer[ptr++];
    	else return -1;
    }
    private static boolean isPrintableChar(int c){
    	return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
    	while(hasNextByte() && !isPrintableChar(buffer[ptr]))
    		ptr++; return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
    	return Double.parseDouble(next());
    }
}


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

#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORD(i, b, a) for (int i = b; i >= a; --i)

#define sz(v) ((int) v.size())
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())

using namespace std;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    int n, w; cin >> n >> w;
    vector<array<int, 2>> a(n);
    REP(i, n) {
        cin >> a[i][0] >> a[i][1];
    }
    vector<long long> dp(100100, (long long) 1e18);
    dp[0] = 0;
    REP(i, n) {
        FORD(j, sz(dp) - 1 - a[i][1], 0)
            dp[j + a[i][1]] = min(dp[j + a[i][1]], dp[j] + a[i][0]);
    }
    FORD(i, sz(dp) - 1, 0) if (dp[i] <= w) {
        cout << i << "\n";
        return 0;
    }
    return 0;
}


Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Out.Flush();
            Read();
        }
        static void Solve()
        {
            var NK = Sarray();
            var N = NK[0];
            var K = NK[1];
            var Ai = Sarray();
            Array.Sort(Ai);
            var cmb = new Combination(N, Mod);
            var rui = new long[N + 1];
            for (var i = 1; i < N + 1; ++i)
                rui[i] += rui[i - 1] + Ai[i - 1];
            var ans = 0L;
            for (var l = K - 2; l <= N - 2; ++l)
            {
                var dai2 = ((rui[N + 1 - 1] - rui[l + 2 - 1]) - (rui[N - 1 - l + 1 - 1] - rui[0])) % Mod;
                ans = ans + cmb.nCk((int)l, (int)K - 2) * dai2 % Mod;
                ans %= Mod;
            }
            WriteLine(ans);
        }
        public class Combination
        {
            readonly long mod;
            readonly long[] fac, finv, inv;
            public Combination(long n, long mod = 1000000007)
            {
                long max = n + 1;
                this.mod = mod;
                fac = new long[max];
                finv = new long[max];
                inv = new long[max];
                fac[0] = fac[1] = 1;
                finv[0] = finv[1] = 1;
                inv[1] = 1;
                for (int i = 2; i < max; ++i)
                {
                    fac[i] = fac[i - 1] * i % mod;
                    inv[i] = mod - inv[mod % i] * (mod / i) % mod;
                    finv[i] = finv[i - 1] * inv[i] % mod;
                }
            }
            public long nCk(int n, int k)
            {
                if (n < k) return 0;
                if (n < 0 | k < 0) return 0;
                return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
            }
        }
    }
}

Measured memory_bytes: 31580
#include <iostream>
using namespace std;
int main(void)
{
	int y,m,d;
	int ymd[4]={18680908,19120730,19261225,19890108};
	int year[4]={1868,1912,1926,1989};
	char gengou[4][10]={"meiji","taisho","showa","heisei"};
	while(cin >> y >> m >> d){
		int judge = 10000*y +100*m + d;
		if(judge<ymd[0]){
			cout << "pre-meiji" << endl;
		}if(judge>=ymd[3]){
			printf("%s %d %d %d\n",gengou[3],y-year[3]+1,m,d);
		}else{
			for(int i= 0; i < 3; i++){
				if(ymd[i] <= judge && judge < ymd[i+1]){
					printf("%s %d %d %d\n",gengou[i],y-year[i]+1,m,d);
					break;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

struct mint{
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){};
    mint operator-() const{
        return mint(-x);
    }
    mint& operator+=(const mint a){
        if((x+=a.x) >= mod) x -= mod;
        return *this;
    } 
    mint& operator-=(const mint a){
        if((x+= mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a){
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const{
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const{
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const{
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const{
        if(!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if(1&t) a *= *this;
        return a;
    }

    mint inv() const{
        return pow(mod-2);
    }
    mint& operator/=(const mint a){
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const{
        mint res(*this);
        return res /= a;
    }
};

struct combination{
    vector<mint> fact, ifact;
    combination(int n):fact(n+1), ifact(n+1){
        assert(n < mod);
        fact[0] = 1;
        for(int i=1; i<=n; i++) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for(int i=n; i>=1; i--) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k){
        if(k<0 || k>n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

vvi g(15, vi(15, -1));

int main(){
    int n;
    cin >> n;
    rep(i, n){
        int a;
        cin >> a;
        rep(j, a){
            int x;
            int y;
            cin >> x >> y;
            x--;
            g[i][x] = y;
        }
    }

    int ans = 0;

    rep(i, 1<<n){
        vi d(n, 0);
        rep(j, n){
            if(i>>j & 1) d[j] = 1;
        }

        bool ok = true;

        rep(j, n){
            if(d[j]==0)continue;
            rep(k, 15){
                if(g[j][k]==-1)continue;
                if(g[j][k]!=d[k]) ok = false;
            }
        }

        if(ok){
            ans = max(ans, __builtin_popcount(i));
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using std::cin;
using std::cout;

int main(int argc, char* argv[]) {
  int k, x;
  cin >> k >> x;

  for (int i = std::max(-1000000, x - k + 1); i <= std::min(x + k - 1, 1000000); ++i) {
    cout << i << " ";
  }

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<map>
#define ll long long
using namespace std;
int read(){
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
int min(int a,int b){return a<b?a:b;}
int max(int a,int b){return a<b?b:a;}
int abs(int x){return x>0?x:-x;}
void mins(int &a,int b){if(a>b)a=b;}
void maxs(int &a,int b){if(a<b)a=b;}
//void insert(int u,int v){tot++;e[tot].v=v;e[tot].from=first[u];first[u]=tot;}
/*------------------------------------------------------------*/
const int inf=0x3f3f3f3f,maxn=200010,maxN=70000010;

int n,p[maxN],f[maxn],sum;
char s[maxn];

int main(){
    scanf("%s",s+1);
    n=strlen(s+1);
    f[0]=0;
    memset(p,0x3f,sizeof(p));
    p[0]=0;
    for(int i=1;i<=n;i++){
    	int x=1<<(s[i]-'a');
    	sum^=x;
    	f[i]=inf;
    	f[i]=min(f[i],p[sum]+1);
    	for(int j=0;j<26;j++)f[i]=min(f[i],p[sum^(1<<j)]+1);
		p[sum]=min(p[sum],f[i]);
		//printf("p[%d]=%d\n",sum,p[sum]);
	}
    printf("%d",f[n]);
    return 0;
}

Measured memory_bytes: 274560
#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 18;
int col[N], ans, n;
vector<int> G[N];
void DFS(int v = 1, int par = 0) {
	int mx = 0, b = 0;
	for (auto u : G[v])
		if (u ^ par) 
			DFS(u, v), mx |= col[v] & col[u], col[v] |= col[u];
	while ((1 << b) <= mx || col[v] & (1 << b)) b ++;
	ans = max(ans, 31 - __builtin_clz(col[v] = col[v] & ~((1 << b) - 1) | (1 << b)));
}
int main () {
	scanf("%d", &n);
	for (int i = 1, v, u; i < n; i ++) {
		scanf("%d%d", &v, &u);
		G[v].push_back(u);
		G[u].push_back(v);
	}
	DFS();
	printf("%d", ans);
}

Measured memory_bytes: 15616
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string.h>
#define _USE_MATH_DEFINES
#define LL long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
using namespace std;

int max(int *ary) {
	int max = 0;
	for (int i = 0; i < sizeof(ary) / sizeof(ary[0]); i++)
		if (max < ary[i]) max = ary[i];
	return max;
}

int nmax(int *ary) {
	int max = 0, num;
	for (int i = 0; i < sizeof(ary) / sizeof(ary[0]); i++)
		if (max < ary[i]) {
			max = ary[i];
			num = i;
		}
	return max, num;
}

int main() {
	LL n, m, ans = 1, ans2 = 1;
	cin >> n >> m;
	if (abs(n - m) >= 2) {
		cout << 0 << endl;
		return 0;
	}
	if (n == m) {
		for (int i = 1; i <= n; i++) {
			ans *= i;
			ans %= 1000000000 + 7;
		}
		ans = ans*ans * 2;
		ans %= 1000000000 + 7;
		cout << ans << endl;
	}
	else {
		for (int i = 1; i <= n; i++) {
			ans *= i;
			ans %= 1000000000 + 7;
		}
		for (int i = 1; i <= m; i++) {
			ans2 *= i;
			ans2 %= 1000000000 + 7;
		}
		ans = ans*ans2;
		ans %= 1000000000 + 7;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>

using namespace std;

int main()
{
    vector<long long> a;
    vector<long long> b;
    vector<long long> c;
    long long ans = 0;
    int n;
    
    cin >> n;
    int x;
    for(int i = 0;i < n;i++){
        cin >> x;
        a.push_back(x);
    }
    for (int i = 0;i < n;i++){
        cin >> x;
        b.push_back(x);
    }
    for (int i = 0;i < n;i++){
        cin >> x;
        c.push_back(x);
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    
    for (int i = 0;i < n;i++){
        auto citer = upper_bound(c.begin(),c.end(),b[i]);
        auto aiter = lower_bound(a.begin(),a.end(),b[i]);
        
        ans += (aiter-a.begin())*(c.end()-citer);
    }
    
    cout << ans << endl;
}


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

int main() {
    int n;
    cin>>n;
    vector<int> a(n);
    for (int i=0;i<n;i++){
        cin>>a.at(i);
        // cout<<a.at(i)<<endl;
    }
    sort(a.begin(),a.end());
  	reverse(a.begin(),a.end());
    // for (int i=0;i<n;i++){
    //     cout<<a.at(i)<<endl;
    // }
    int alice=0,bob=0;
    for (int i=0 ;i<n;i++){
        if(i %2==0){
        bob+=a.at(i);
        }else{
        alice+=a.at(i);    
        }
        // cout<<bob<<endl;
    }
    
    cout<<max(bob-alice,alice-bob)<<endl;
    
    return 0;
}


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

int main(){
  int i,j,n=0,ans=0;
  char str[81];
  while(cin >> str){
    for(i=0;str[i]!='\0';i++){
      if('0' <= str[i] && str[i] <= '9'){
	n += str[i] - '0';
	if(str[i+1] != '\0' && '0' <= str[i+1] && str[i+1] <= '9'){
	  n *= 10;
	}
	else if(str[i+1] == '\0' || '0' > str[i+1] || str[i+1] > '9'){
	  ans += n;
	  n = 0;
	}
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

using ll = long long int;
using vi = vector<int>;
#define f(n) for(int i = 0; i < n; i++)
#define fj(n) for(int j = 0; j < n; j++)
#define fk(n) for(int k = 0; k < n; k++)
#define ci(n) cin >> n;
#define ic(n) int n; cin >> n;
#define lc(n) int n; cin >> n;
#define all(a) a.begin(), a.end()
#define pri(a, n) for(int i = 0; i < n; i++) cout << a[i] << " "; cout << "\n";
#define scl(a, n) ll a[n] = {0}; for(int i = 0; i < n; i++) cin >> a[i];
#define pb push_back
#define eb emplace_back
#define sc second
#define ft first
#define int long long
void prip(int a[], int n){f(n) cout << a[i] << ' '; cout << '\n';}

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1}, h, w;
bool ok(int x, int y)
{
    return x >= 0 && x < w && y >= 0 && y < h;
}
main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int k;
    cin >> h >> w >> k;
    int x1, y1, x2, y2;
    cin >> y1 >> x1 >> y2 >> x2;
    y1--, x1--, x2--, y2--;
    char a[h][w];
    int d[h][w];
    f(h) fj(w) cin >> a[i][j], d[i][j] = -1;
    queue<int> qx, qy;
    qx.push(x1), qy.push(y1);
    d[y1][x1] = 0;
    while(!qx.empty())
    {
        int cx = qx.front(), cy = qy.front();
        qx.pop(), qy.pop();
        f(4)
        {
            for(int l = 1; l <= k && ok(cx + l * dx[i], cy + l * dy[i]) && (d[cy + l * dy[i]][cx + l * dx[i]] == -1 || d[cy + l * dy[i]][cx + l * dx[i]] > d[cy][cx])  && a[cy + l * dy[i]][cx + l * dx[i]] == '.'; l++)
            {
                if(d[cy + l * dy[i]][cx + l * dx[i]] == -1)
                {
                    d[cy + l * dy[i]][cx + l * dx[i]] = d[cy][cx] + 1;
                    qx.push(cx + l * dx[i]);
                    qy.push(cy + l * dy[i]);
                }
                else d[cy + l * dy[i]][cx + l * dx[i]] = min(d[cy + l * dy[i]][cx + l * dx[i]], d[cy][cx] + 1);
            }
        }
    }

    cout << d[y2][x2];
}


Measured memory_bytes: 14004
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rep2(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define pb push_back
int main(int argc, char** argv) {
	ll x;
	scanf("%lld",&x);
	ll p=100,ans=0;
	while(p<x)
	{
		ans++;
		p=p*0.01+p;
	}
	cout<<ans;
	return 0;
}



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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int n, W;
	cin >> n >> W;

	vector<ll> dp(101000, 1e18);
	dp[0] = 0;
	for (int i = 1; i <= n; i++) {
		int w, v;
		cin >> w >> v;
		for (int j = 1000 * i; j >= v; j--) {
			dp[j] = min(dp[j], dp[j - v] + w);
		}
	}

	ll res = 0;
	for (int i = 0; i <= 100000; i++) {
		if (dp[i] <= W) {
			res = i;
		}
	}

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
	long n,x,i;
	long sum=0,max=-1000001,s=1000001;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>x;
		if(x>max) max=x;
		if(s>x) s=x;
		sum+=x;
	}
	cout<<s<<" "<<max<<" "<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3088
mininf = -10**8
inf = 10**8
count = 0

while(1):
    count += 1
    W = int(input())
    if W == 0:
        break
    N = int(input())

    dp = [0 for j in range(W+1)]
    for _ in range(N):
        v,w = [int(i) for i in input().split(",")]
        for i in range(w,W+1)[::-1]:
            dp[i] = max(dp[i], dp[i-w]+v)
    value = 0
    weight = 0
    for i in range(W+1):
        if value < dp[i]:
            value = dp[i]
            weight = i

    print("Case {}:".format(count))
    print(value)
    print(weight)



Measured memory_bytes: 5624
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))  // xが範囲内か
#define sort_u(x) sort((x).begin(),(x).end())
#define sort_d(x) sort((x).begin(),(x).end(), greater<int>())
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()  // 配列のサイズ
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cerr<<#x<<" = "<<x<<endl;  // 確認したいとき
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))  // 切り上げたいとき
#define newline puts("")
#define v(T) vector<T>  // Tはどんな型でもいい
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;  // ******
typedef vector<vi> vvi;
typedef vector<ll> vl;  // ******
typedef vector<P> vp;
typedef vector<T> vt;
int getInt(){int x;scanf("%d",&x);return x;}
template<typename T>istream& operator>>(istream&i,v(T)&v){rep(j,sz(v))i>>v[j];return i;}  // vi a(n); cin>>a;
template<typename T>string join(const v(T)&v){stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const v(T)&v){if(sz(v))o<<join(v);return o;}  // cout<<a;  aの中身全部出す
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.fi<<","<<v.se;}
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
template<typename T>ll suma(const v(T)&a){ll res(0);for(auto&&x:a)res+=x;return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
//mins(ans,now);  ansに最小値が入る
//if(max(ans,now)) ansが小さければ更新して実行。cnt++とか。
//ll sum = suma(a);

int main() {
    int n, k; cin >> n;
    vi a(n); cin>>a;
    vi ans(n);
    rep(i,n) ans[a[i]-1] = i+1;
    cout<<ans;
}

/*
g++ a.cpp
./a.out

oj d
oj t

debug:ctrl+shift+B+./problem.exe
problem.in+f5

*/


Measured memory_bytes: 5872
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int dp[100010];

int main(){
  int n,k;
  cin >> n >> k;
  int a[n];
  rep(i,n)cin >> a[i];
  sort(a,a+n);
  int g=a[0];
  rep(i,n)g=__gcd(g,a[i]);
  if(k%g==0 && k<=a[n-1])cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
return 0;}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<stack>
#include<queue>

using namespace std;

int main(){
	int N,K;
	int dp[11][2001];
	int c,g;
	vector<int> tp[11];
	
	scanf("%d %d",&N,&K);
	for(int i=0;i<N;i++){
		scanf("%d %d",&c,&g);
		tp[g].push_back(c);
	}
	for(int i=1;i<=10;i++){
		sort(tp[i].begin(),tp[i].end());
		reverse(tp[i].begin(),tp[i].end());
		for(int j=1;j<=K;j++){
			int sum=0;
			for(int k=0;k<=(int)tp[i].size();k++){
				if(j-k<0)
				break;
				if(k)
				sum+=tp[i][k-1];
				dp[i][j]=max(dp[i][j],dp[i-1][j-k]+(k-1)*k+sum);
			}
		}
	}
	printf("%d\n",dp[10][K]);
}


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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct Edge{ll from, to, cost;};
struct node{ll cost, to;
  bool friend operator>(node a, node b){
    return a.cost>b.cost;
  }
};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

ll gcd(ll a, ll b){
  ll r = a%b;
  if(r==0) return b;
  else return gcd(b, a%b);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

ll N, A[3];
llvec l;
llvec num[4];
ll ans = 1e15;

void dfs(ll n){
  if(n==N){
    ll tmp = 0;
    if(num[0].size()==0 or num[1].size()==0 or num[2].size()==0)return;
    rep(i, 3){
      tmp += 10 * (num[i].size()-1);
      tmp += abs(accumulate(ALL(num[i]), 0LL) - A[i]);
    }
    ans = min(ans, tmp);
    return;
  }else{
    rep(i, 4){
      num[i].push_back(l[n]);
      dfs(n+1);
      num[i].pop_back();
    }
  }
}

/**************************************
** A main function starts from here  **
***************************************/
int main(){
  cin >> N >> A[0] >> A[1] >> A[2];
  rep(i, N){
    ll tmp;cin >> tmp;
    l.push_back(tmp);
  }
  dfs(0);
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>  
 #include <stdio.h>
using namespace std;
int main(){
int n;
std::string a;
cin >> n;
cin >> a;
size_t size = a.length();
for (int i=0;i<size;i++){
    int f=a[i]-'A';
    f= (f+n)%26;
   putchar('A'+f);

}
}

Measured memory_bytes: 256
def draw_check_line(h, w, i)
	pattern = ['#', '.']
	if i%2 == 1
		p_index = 0
	else
		p_index = 1
	end

	w.times do
		print("#{pattern[p_index%2]}")
		p_index += 1
	end
	puts ""
end
def draw_check(h, w)
	for i in 1..h
		draw_check_line(h, w, i)
	end
	puts ""
end

inputs = gets.strip().split(" ")
h  = inputs[0].to_i
w  = inputs[1].to_i
until h == 0 && w == 0
	draw_check(h, w)
	inputs = gets.strip().split(" ")
	h  = inputs[0].to_i
	w  = inputs[1].to_i		
end


Measured memory_bytes: 6852