akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL N; cin >> N;
		vector<ULL> A(N), B(N); rep(i, N) cin >> A[i] >> B[i];
		vector<ULL> C(N); rep(i, N) C[i] = A[i] + B[i];
		sort(C.rbegin(), C.rend());
		LL ans = 0;
		rep(i, N) ans -= B[i];
		rep(i, N) if (i % 2 == 0) ans += C[i];
		cout << ans << endl;
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

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

const int D[8][2] = { {1, 1}, {1, 0}, {1, -1}, 
		      {0, 1}, {0, -1}, 
		      {-1, 1}, {-1, 0}, {-1, -1} };

char T[10][10];
bool turn = true; // 巴マミのターンのときtrue、お菓子の魔女のターンのときfalse。

char M() {
  return (turn ? 'o' : 'x');
}

char E() {
  return (turn ? 'x' : 'o');
}

bool ok (int i, int j) {
  return 1 <= i && i <= 8 && 1 <= j && j <= 8; 
}

int main() {
  fill(&T[0][0], &T[0][0]+100, '.');
  char s;
  for (int i=1; i<=8; i++) {
    for (int j=1; j<=8; j++) {
      cin >> s;
      T[i][j] = s;
    }
  }
  for (int t=0; t<64; t++) { 
    // 石が置けないときにパスする判定だけは厳密にやって、
    // 決着がついたとしても64ターンやることにする。
    int max = 0;
    int maxx, maxy;
    bool houkou[8];
    for (int i=(turn ? 1 : 8); (turn ? i<=8 : i>=1); (turn ? i++ : i--)) {
      for (int j=(turn ? 1 : 8); (turn ? j<=8 : j>=1); (turn ? j++ : j--)) {
	if (T[i][j] == '.') { // (i,j)が空なら
	  int temp = 0;
	  bool temph[8];
	  fill(temph, temph+8, false);
	  for (int k=0; k<8; k++) {
	    int ishi = 1;
	    while (ok (i + ishi * D[k][0], j + ishi * D[k][1]) 
		   && T[i + ishi * D[k][0]][j + ishi * D[k][1]] == E()) {
	      ishi++;
	    }
	    if (ok (i + ishi * D[k][0], j + ishi * D[k][1]) 
		&& T[i + ishi * D[k][0]][j + ishi * D[k][1]] == M()) {
	      temp += ishi-1;
	      temph[k] = true;
	    }
	  }
	  if (temp > max) {
	    max = temp;
	    maxx = i;
	    maxy = j;
	    for (int k=0; k<8; k++) {
	      houkou[k] = temph[k];
	    }
	  }
	}
      }
    }
    if (max > 0) { // 置ける場所があるとき
      T[maxx][maxy] = M();
      for (int k=0; k<8; k++) {
	if (houkou[k]) {
	  int ishi = 1;
	  while (ok (maxx + ishi * D[k][0], maxy + ishi * D[k][1]) 
		 && T[maxx + ishi * D[k][0]][maxy + ishi * D[k][1]] == E()) {
	    T[maxx + ishi * D[k][0]][maxy + ishi * D[k][1]] = M();
	    ishi++;
	  }
	}
      }
    }
    turn = !turn;
  }
  for (int i=1; i<=8; i++) {
    for (int j=1; j<=8; j++) {
      cout << T[i][j];
      if (j == 8) cout << endl;
    }
  }
}

Measured memory_bytes: 1136
#include<bits/stdc++.h>
using namespace std;
#define flash ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define pb push_back
#define all(v) (v).begin(),(v).end() 
#define endl "\n"
#define int long long int
#define ll long long
#define ld long double
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
const int mod = 1000000007;
const int N=200005;
const int inf=1e18;


bool isPrime(ll n){if(n<2)return false;for(ll i=2;i*i<=n;++i){if(n%i==0){return false;}}return true;}
ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res%mod;}
ll gcd(ll a,ll b){if (a==0)return b;return gcd(b%a,a);}

void fun(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}


signed main(){
    flash;
    fun();
    int t=1;
    //cin>>t;
    while(t--){
        int n,m,z;
        cin>>n>>m;
        if(n<=5)
          cout<<0;
      else if(n<=12)
        	cout<<m/2;
      else
        cout<<m<<endl;
    }
    return 0;
}

Measured memory_bytes: 3608
/*************************************************************************
    > File Name: F.cpp
    > Author: Roundgod
    > Mail: wcysai@foxmail.com 
    > Created Time: 2018-12-23 12:23:22
 ************************************************************************/

#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define MAXN 100005
#define INF 1000000000
#define MOD 998244353
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,m,ans;
int relate[MAXN][2];
//0: withitself
//1: with a[i-1]
//2: with a[i-2]
int dp[MAXN][2];
void add(int &a,int b) {a+=b; if(a>=MOD) a-=MOD;}
int pow_mod(int a,int i)
{
    int s=1;
    while(i)
    {
        if(i&1) s=1LL*s*a%MOD;
        a=1LL*a*a%MOD;
        i>>=1;
    }
    return s;
}
//1..n: 0
//n+1..2n 1
map<P,int> mp;
int main()
{
    scanf("%d%d",&n,&m);
    int cnt=(1LL*n*(n-1)/2)%(MOD-1);
    for(int i=0;i<m;i++)
    {
        int x,y,z;
        scanf("%d%d%d",&x,&y,&z);
        mp[P(x,y)]=z;
    }
    memset(relate,-1,sizeof(relate));
    for(auto it:mp)
    {
        int x=it.F.F,y=it.F.S,z=it.S;
        if(x>y) 
        {
            if(mp.find(P(y,x))==mp.end()) cnt--;
            continue;
        }
        if(x==y)
        {
            if(relate[x][0]!=-1&&relate[x][0]!=z) {puts("0"); return 0;}
            relate[x][0]=z;
        }
        else 
        {
            cnt--;if(cnt<0) cnt+=MOD;
            if(mp.find(P(y,x))==mp.end()) continue;
            int s=(z+mp[P(y,x)])%2;
            if(y-x>2&&s==1) {puts("0"); return 0;}
            if(y-x==1)
            {
                if(relate[y][1]!=-1&&relate[y][1]!=s) {puts("0"); return 0;}
                relate[y][1]=s;
            }
            else if(y-x==2)
            {
                if(relate[x+1][0]!=-1&&relate[x+1][0]!=s) {puts("0"); return 0;}
                relate[x+1][0]=s;
            }
        }
    }
    memset(dp,0,sizeof(dp));
    if(relate[1][0]!=-1) 
    {
        int x=relate[1][0];
        dp[1][1-x]=0;dp[1][x]=1;
    }
    else {dp[1][0]=dp[1][1]=1;}
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<=1;j++)
        {
            if(!dp[i][j]) continue;
            for(int k=0;k<=1;k++)
            {
                bool f=true;
                if(relate[i+1][0]!=-1&&relate[i+1][0]!=k) f=false;
                if(relate[i+1][1]!=-1&&relate[i+1][1]!=(j+k)%2) f=false;
                if(f) add(dp[i+1][k],dp[i][j]);
            }
        }
    }
    add(ans,dp[n][0]);add(ans,dp[n][1]);
    ans=1LL*ans*pow_mod(2,cnt)%MOD;
    printf("%d\n",ans);
    return 0;
}



Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se seoncd
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=5005;
int f[N][N],s[N][N],n,m,ans,mod;

void add(int &x,int y){
	x=(x+y>=mod?x+y-mod:x+y);
}
int mul(int x,int y){
	return (ll)x*y%mod;
}

int main(){
	read(n),read(mod);
	m=n/2,f[0][0]=1;
	rep(j,0,n) s[0][j]=1;
	rep(i,1,n) rep(j,0,n){
		f[i][j]=f[i-1][j];
		if(j>=i) add(f[i][j],f[i][j-i]);
		s[i][j]=f[i][j];
		if(j) add(s[i][j],s[i][j-1]);
	}
	int R=(n&1?m:m-1);
	rep(h,0,n) rep(x,0,h-1){
		int y=h-1-x,res=f[n-h][y];
		if(y>R&&h<n) add(res,mod-s[n-h-1][y-R-1]);
		add(ans,mul(s[m][x],res));
	}
	cout<<(ans+mod)%mod<<endl;
	return 0;
}

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

int n;
int * a;

void output()
{
  for (int i = 0; i < n; i++)
  {
    if (i) cout << ' ';
    cout << a[i];
  }
  cout << endl;
}

int main()
{
  cin >> n;
  a = new int[n];
  for (int i = 0; i < n; i++)
  {
     cin >> a[i];
  }
  output();

  for (int i = 1; i < n; i++)
  {
    int key = a[i];
    int j = i - 1;
    while (j >= 0 && key < a[j])
    {
      a[j+1] = a[j];
      j--;
    }
    a[j+1] = key;
    output();
  }
  return 0;
}

Measured memory_bytes: 1192
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int area = a * b;
        int length = (a + b) * 2;
        System.out.println(area + " "+length);
    }
}


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

typedef long long ll;

int main(void){
    ll N,W;
    cin >> N >> W;
    
    vector<ll> weight(110),value(110);
    for(int i = 0; i < N; i++){
        cin >> weight[i] >> value[i];
    }
    
    vector<vector<ll>> dp(110,vector<ll>(100100,0));
    
    dp[0][0] = 0;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < 100100; j++){
            if(j - weight[i] >= 0){
                dp[i+1][j] = max(dp[i+1][j], dp[i][j - weight[i]] + value[i]);
            }
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
        }
    }
    
    cout << dp[N][W] << endl;
}

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

const int MAX = 510000;
const int mod = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  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;
  }
}

ll com(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;
}

int main() {
  COMinit();
  int n,k;
  cin >> n >> k;
  rep(i,1,k+1) {
    ll ans = com(n-k+1,i) * com(k-1,i-1) % mod;
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 15596
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

int n;
int a[1 << 18];

pair<int, int> mx[1 << 18];
vector<int> cur;

bool cmp(int x, int y) {
	return a[x] > a[y];
}

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> n;
	for (int i = 0; i < (1 << n); ++i)
		cin >> a[i];
	for (int i = 0; i < (1 << n); ++i) {
		cur.clear();
		cur.push_back(i);
		for (int j = 0; j < n; ++j)
			if ((i >> j) & 1) {
				int x = i ^ (1 << j);
				cur.push_back(mx[x].first);
				if (mx[x].second != -1)
					cur.push_back(mx[x].second);
			}
		sort(cur.begin(), cur.end(), cmp);
		cur.resize(unique(cur.begin(), cur.end()) - cur.begin());
		if (cur.size() == 1)
			mx[i] = {cur[0], -1};
		else
			mx[i] = {cur[0], cur[1]};
	}
	ll now = 0;
	for (int i = 1; i < (1 << n); ++i) {
		now = max(now, ll(a[mx[i].first] + a[mx[i].second]));
		cout << now << "\n";
	}
	return 0;
}




Measured memory_bytes: 6144
import java.util.Scanner;


public class Main
{
	static double a, b, c, d, e, f;
	
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		for(; scanner.hasNext();)
		{
			a = scanner.nextDouble();
			b = scanner.nextDouble();
			c = scanner.nextDouble();
			
			d = scanner.nextDouble();
			e = scanner.nextDouble();
			f = scanner.nextDouble();	

			System.out.printf("%1$.3f %2$.3f\n", getX()+0.00049, getY()+0.00049);
		}
	}
	
	private static double getX()
	{
		if(b == 0)
		{
			return c/a;
		}
		else if(e == 0)
		{
			return f/d;
		}
		else {		
			double a0 = a/b;
			double c0 = c/b;
			
			double d0 = d/e;
			double f0 = f/e;
			
			if(a0-d0==0 || c0-f0==0)
				return 0;
			else
				return (c0-f0)/(a0-d0);
		}
	}
	
	private static double getY()
	{
		if(a == 0)
		{
			return c/b;
		}
		else if(d == 0)
		{
			return f/e;
		}
		else 
		{	
			double b0 = b/a;
			double c0 = c/a;
			
			double e0 = e/d;
			double f0 = f/d;
			
			if(b0-e0==0 || c0-f0==0)
				return 0;
			else
				return (c0-f0)/(b0-e0);
		}
	}
}

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

const long long mod = 998244353;

long long box[200001];
void init(){
    box[0] = 1;
    for(int i = 1; i < 200001; i++){
        box[i] = box[i-1]*i;
        box[i] %= mod;
    }
}

long long powmod(long long a, long long n, long long m){
    long long res = 1;
    while(n > 0){
        if(n & 1) res *= a;
        a = a * a % m;
        res %= m;
        n >>= 1;
    }
    return res;
}

long long C(long long n, long long k){
    return box[n] * powmod(box[k] * box[n-k] % mod, mod-2, mod)%mod;
}

int main(){
    long long n, m, k; cin >> n >> m >> k;
    long long ans = 0;
    init();
    for(long long i = 0; i <= k; i++){
        ans += powmod(m-1, n - i -1, mod) * m % mod * C(n-1, n-i-1) % mod;
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5200
package main

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

var sc = bufio.NewScanner(os.Stdin)
var buff []byte

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buff, bufio.MaxScanTokenSize*1024)
	log.SetFlags(log.Lshortfile)
}

func main() {
	N := nextInt()
	A := nextInts(N)
	ans := 1
	var pre int
	pre = ans
	flag := false
	for i := 0; i < N; i++ {
		ans *= A[i]
		if A[i] == 0 {
			fmt.Println("0")
			return
		}
		if ans/A[i] != pre {
			flag = true
		}
		if ans > 1e18 {
			flag = true
		}
		pre = ans
	}
	if flag {
		fmt.Println("-1")
	} else {
		fmt.Println(ans)
	}
}

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

func nextFloat64() float64 {
	sc.Scan()
	f, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return f
}

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

func nextUint64() uint64 {
	sc.Scan()
	i, err := strconv.ParseUint(sc.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func nextInts(n int) (r []int) {
	r = make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}


Measured memory_bytes: 5844
import java.util.*;
import java.io.*;

public class Main {
	static final int mod = (int) 1e9 + 7;
	static final int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };
	static final int INF = Integer.MAX_VALUE / 3;
	static final long LINF = Long.MAX_VALUE / 3;
	static final String nextLine = "\n";

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		int n = fs.nextInt();
		long a[] = fs.nextLongArray(n);
		long x[] = new long[n];
		for(int i=0;i<n;i++) {
			if(i%2==0) {
				x[0] += a[i];
			}
			else {
				x[0] -= a[i];
			}
		}
		
		for(int i=0;i<n-1;i++) {
			x[i + 1] = 2 * a[i] - x[i];
		}
		for(int i=0;i<n;i++) {
			System.out.print(x[i] + " ");
		}
		System.out.println();
	}

	//MOD culculations
	static long plus(long x, long y) {
		long res = (x + y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long sub(long x, long y) {
		long res = (x - y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long mul(long x, long y) {
		long res = (x * y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long div(long x, long y) {
		long res = x * pow(y, mod - 2) % mod;
		return res < 0 ? res + mod : res;
	}

	static long pow(long x, long y) {
		if (y < 0)
			return 0;
		if (y == 0)
			return 1;
		if (y % 2 == 1)
			return (x * pow(x, y - 1)) % mod;
		long root = pow(x, y / 2);
		return root * root % mod;
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

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

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

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

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}

Measured memory_bytes: 50496
// g++ macro.cpp -std=c++14
#include <bits/stdc++.h> //STL include
typedef long long ll;// long long int
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;//namespace

#define dump(x)  cout << #x << " = " << (x) << endl;// debug cout
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;

#define SANKOU(n,a,b) cout << ((n) ? (a) : (b) ) << endl;

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);// warshall-floyd

#define CIN(x) int x;cin>>x;
#define SCIN(x) string x;cin>>x;
#define COUT(x) cout<<(x)<<endl;
#define SCOUT(x) cout<<(x)<<" ";
#define ENDL cout<<endl;

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_;
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl;

#define ALL(obj) (obj).begin(),(obj).end()// iterator

#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end());

#define P pair<int,int>
#define V vector<int>
#define M map<int,int>

#define pb(a) push_back(a)//push_back
#define mp make_pair// make_pair


int main(){

    CIN(sx);CIN(sy);CIN(tx);CIN(ty);
    int x=tx-sx;
    int y=ty-sy;
    V a;
    REP(i,x)a.pb(3);
    REP(i,y)a.pb(0);
    REP(i,x)a.pb(2);
    REP(i,y+1)a.pb(1);
    REP(i,x+1)a.pb(3);
    REP(i,y+1)a.pb(0);
    a.pb(2);
    a.pb(0);
    REP(i,x+1)a.pb(2);
    REP(i,y+1)a.pb(1);
    a.pb(3);
    REP(i,a.size()){
        if(a[i]==0)cout<<"U";
        if(a[i]==1)cout<<"D";
        if(a[i]==2)cout<<"L";
        if(a[i]==3)cout<<"R";
    } 
    cout<<endl;

    return 0;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;


void swap(int& a, int&b)
{
    
    int temp=a;
    a=b;
    b=temp;
}

int main()
{
    
    int a,b,c;
    
    cin>>a>>b>>c;
    
    swap(a,b);
     swap(a,c);
    
    cout<<a<<" "<<b<<" "<<c;

    return 0;
}


Measured memory_bytes: 384
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	c := scanInts(n)
	cv := make([][]int, n)
	for i := 0; i < n; i++ {
		cv[c[i]-1] = append(cv[c[i]-1], i)
	}
	g := make([][]int, n)
	for i := 0; i < n-1; i++ {
		a, b := scanInt()-1, scanInt()-1
		g[a] = append(g[a], b)
		g[b] = append(g[b], a)
	}

	l, r := make([]int, n), make([]int, n)
	y := 0
	var dfs func(v, p int)
	dfs = func(v, p int) {
		l[v] = y
		y++
		for _, to := range g[v] {
			if to == p {
				continue
			}
			dfs(to, v)
		}
		r[v] = y
	}
	dfs(0, 0)

	tot := n * (n + 1) / 2
	bit := make(binaryIndexedTree, n+1)
	for i := 0; i < n; i++ {
		bit.add(i, 1)
	}

	for i := 0; i < n; i++ {
		ans := tot
		sort.Slice(cv[i], func(j, k int) bool { return l[cv[i][j]] > l[cv[i][k]] })
		his := []pair{}

		for j := 0; j < len(cv[i]); j++ {
			cnt := 1
			v := cv[i][j]

			for _, to := range g[v] {
				if l[to] < l[v] {
					continue
				}
				num := bit.sum(r[to]-1) - bit.sum(l[to]-1)
				ans -= num * (num + 1) / 2
				cnt += num
			}

			bit.add(l[v], -cnt)
			his = append(his, pair{l[v], cnt})
		}

		num := bit.sum(n-1) - bit.sum(-1)
		ans -= num * (num + 1) / 2
		fmt.Fprintln(wr, ans)
		for i := 0; i < len(his); i++ {
			bit.add(his[i].a, his[i].b)
		}
	}

}

type pair struct{ a, b int }

type binaryIndexedTree []int

func (t binaryIndexedTree) sum(i int) int {
	s := 0
	for i++; i > 0; i -= i & -i {
		s += t[i]
	}
	return s
}
func (t binaryIndexedTree) add(i, x int) {
	for i++; i < len(t); i += i & -i {
		t[i] += x
	}
}


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

using namespace std;
using ll = long long;

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n;
	cin >> n;
	vector<ll> v(n);
	for(int i = 0; i < n; ++i){
		cin >> v[i];
	}
	ll ans = 1e9 + 7;
	for(int i = -40000; i < 40000; ++i){
		ll ac = 0;
		for(int j = 0; j < n; ++j){
			ac += ((v[j] - i) * (v[j] - i));
		}
		ans = min(ans, ac);
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3668
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	int N;
	while(~scanf("%d", &N)) {
		vector<int> a(N);
		for(int i = 0; i < N; ++ i)
			scanf("%d", &a[i]);
		bool ans = true;
		int diam = *max_element(a.begin(), a.end());
		ans &= diam >= (N == 2 ? 1 : 2);
		vector<int> cnt(N);
		rep(i, N) ++ cnt[a[i]];
		rep(i, diam + 1)
			ans &= -- cnt[diam - i / 2] >= 0;
		rep(i, N) if(cnt[i] > 0)
			ans &= i >= (diam + 1) / 2 + 1;
		puts(ans ? "Possible" : "Impossible");
	}
	return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    int a, b, c;
    cin >> a >> b >> c;
    cout << min(c, b / a) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int H,W,i,j;
    
    while(1){
    scanf("%d %d",&H,&W);
    if(H==0&&W==0){break;}
    
    for(i=0;i<H;i++){
        for(j=0;j<W;j++){
            if((j+i)%2==1){
                printf(".");
            }
            else{printf("#");}
        }
        printf("\n");
    }
     printf("\n");
    }
    return 0;
}



Measured memory_bytes: 2588
import sys
def main():
    n = int(input())
    t, a = map(int, input().split())
    h = list(map(int, input().split()))

    min_abs = sys.maxsize
    min_abs_idx = -1
    for idx, item in enumerate(h):
        tmp_tmp = t - item * 0.006
        tmp_abs = abs(tmp_tmp - a)
        if tmp_abs < min_abs:
            min_abs = tmp_abs
            min_abs_idx = idx

    print(min_abs_idx + 1)
    return

main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int INF=1<<29,MOD=1e9+7;

int main(){
	long long a,b,x; cin>>a>>b>>x;
	long long ans;
	if(a==0) ans=b/x+1;
	else ans=b/x-(a-1)/x;
	cout<<ans<<endl;
	return 0;
}


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



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

    string ans = "";
    rep(i,s.size()){
        int d = 26 - (s[i]-'a');

        if(i == s.size()-1){
            char ch = (s[i] - 'a' + k%26)%26 + 'a';
            ans.push_back(ch);
            break;
        }
        if(k >= d && d != 26){
            ans.push_back('a');
            k -= d;
        }else{
            ans.push_back(s[i]);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3764
import java.util.*;

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

    int n = sc.nextInt();
    int max = sc.nextInt();

    int jump = 1;
    int position = 0;
    for (int i = 0; i < n; i++) {
      int move = sc.nextInt();
      position += move;

      if(position <= max) {
        jump++;
      }
    }

    System.out.println(jump);
  }
}


Measured memory_bytes: 22996
from typing import List, Any


def read_int() -> int:
    return int(input().strip())


def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' ')))


def solve2() -> Any:
    N = read_int()
    A = read_ints()
    S = 0
    xorS = 0
    l = 0
    answer = 0
    for r in range(N):
        S += A[r]
        xorS ^= A[r]
        while l < r and xorS != S:
            S -= A[l]
            xorS ^= A[l]
            l += 1
        answer += (r-l+1)
    return answer


if __name__ == '__main__':
    print(solve2())


Measured memory_bytes: 96200
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000009LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

#define MN 75

int N_;
ll A[MN][MN];
ll B[MN][MN];
ll work[MN][MN];

const ll LIM=LLONG_MAX-(MOD-1)*(MOD-1);

// a := a*b
void matmul(ll a[][MN], ll b[][MN]){
	memset(work,0,sizeof(work));
	rep(i,N_)rep(k,N_)rep(j,N_){
		work[i][j]+=a[i][k]*b[k][j];
		if(work[i][j]>LIM)work[i][j]%=MOD;
	}
	rep(i,N_)rep(j,N_)a[i][j]=work[i][j]%MOD;
}

// a := b*a
void matmulleft(ll a[][MN], ll b[][MN]){
	memset(work,0,sizeof(work));
	rep(i,N_)rep(k,N_)rep(j,N_){
		work[i][j]+=b[i][k]*a[k][j];
		if(work[i][j]>LIM)work[i][j]%=MOD;
	}
	rep(i,N_)rep(j,N_)a[i][j]=work[i][j]%MOD;
}

// a := a^2
void matsq(ll a[][MN]){
	memset(work,0,sizeof(work));
	rep(i,N_)rep(k,N_)rep(j,N_){
		work[i][j]+=a[i][k]*a[k][j];
		if(work[i][j]>LIM)work[i][j]%=MOD;
	}
	rep(i,N_)rep(j,N_)a[i][j]=work[i][j]%MOD;
}

// A := A^n
void matpow(ll a[][MN],ll n){
	memset(B,0,sizeof(B));
	rep(i,N_)B[i][i]=1;
	while(n){
		if(n&1)matmul(B,A);
		matsq(A);
		n>>=1;
	}
	rep(i,N_)rep(j,N_)A[i][j]=B[i][j];
}

ll W,H,n;
map<ll,vi> M;
ll ans[MN][MN];

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	int caseno=1;
	while(cin>>W>>H>>n && W){
		N_=W;
		M.clear();
		rep(i,n){
			ll x,y;
			cin>>x>>y;
			x--;y--;
			if(y==0)continue;
			if(M.find(y)==M.end()){
				M[y]=vi(W,1);
			}
			M[y][x]=0;
		}
		M[H]=vi();
		memset(ans,0,sizeof(ans));
		rep(i,W)ans[i][i]=1;
		ll pre=0;
		foreach(it,M){
			ll y=it->fir;
			rep(i,W)rep(j,W){
				A[i][j]=abs(i-j)<=1;
			}
			matpow(A,y-pre-1);
			matmulleft(ans,A);
			if(it->fir==H)continue;
			rep(i,W)rep(j,W){
				A[i][j]=it->sec[i] && abs(i-j)<=1;
			}
			matmulleft(ans,A);
			pre=it->fir;
		}
		cout<<"Case "<<caseno++<<": "<<ans[W-1][0]<<endl;
	}
}

Measured memory_bytes: 1420
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String f = s.substring(0,1);
        char g = s.charAt(s.length()-1);
        int h = s.length() -2;
        System.out.print(f + h + g);
    }
}

Measured memory_bytes: 21844
#include <cstdio>
#include <string.h>
#include <vector>

using namespace std;

namespace {

class Dictionary {
 private:
  struct Node {
    Node* children[4];
    char flags[4];
    char padding[4];

    Node() {
      children[0] = NULL;
      children[1] = NULL;
      children[2] = NULL;
      children[3] = NULL;
      flags[0] = 0;
      flags[1] = 0;
      flags[2] = 0;
      flags[3] = 0;
    }
  };

 public:
  Dictionary()
      : root_(new Node),
        block_size_(1048576), // N.B.
        pool_index_(0),
        block_index_(0) {
    pool_.push_back(new Node[block_size_]);
  }

  ~Dictionary() {
    for (size_t i = 0; i < pool_.size(); ++i) {
      delete[] pool_[i];
    }
    delete root_;
  }

  void insert(const char* k, size_t n) {
    Node* p = root_;
    int id = 0;
    for (size_t i = 0; i < n; ++i) {
      const char c = k[i];
      id = Id(c);
      if (!p->children[id]) {
        p->children[id] = Alloc();
      }
      p = p->children[id];
    }
    p->flags[id] = 1;
  }

  bool find(const char* k, size_t n) const {
    Node* p = root_;
    int id = 0;
    for (size_t i = 0; i < n; ++i) {
      const char c = k[i];
      id = Id(c);
      p = p->children[id];
      if (!p) {
        return false;
      }
    }
    if (!p) {
      return false;
    }
    return p->flags[id];
  }

 private:
  Node* root_;

  static int Id(char c) {
      switch (c) {
        case 'A':
          return 0;
        case 'C':
          return 1;
        case 'G':
          return 2;
        case 'T':
          return 3;
      }
      // should not reach here.
      return 0;
  }

  Node* Alloc() {
    if (block_index_ >= block_size_) {
      pool_.push_back(new Node[block_size_]);
      pool_index_++;
      block_index_ = 0;
    }
    Node* r = &pool_[pool_index_][block_index_];
    block_index_++;
    return r;
  }

  size_t block_size_;
  size_t pool_index_; // pos in pool
  size_t block_index_; // pos in the block
  vector<Node* > pool_;
};

} // namespace

int main() {
  int n;
  scanf("%d", &n);

  Dictionary d;
  char op[7];
  char str[13];
  for (int i = 0; i < n; ++i) {
    scanf("%s ", op);
    scanf("%s", str);
    const char c = op[0];
    const size_t len = strnlen(str, 13);
    if (c == 'i') {
      d.insert(str, len);
      continue;
    }

    if (d.find(str, len)) {
      printf("yes\n");
    } else {
      printf("no\n");
    }
  }

  return 0;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> pic(H);
  
  for (int i=0; i<H; i++){
    cin >> pic.at(i);
  }
  
  W += 2;

  for(int i=0; i<W; i++) {
    cout << "#";
  }
  cout << endl;
  
  for(int i=0; i<H; i++) {
    cout << "#" << pic.at(i) << "#" << endl;
  }
  
  for(int i=0; i<W; i++) {
    cout << "#";
  }
  cout << endl;
    
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
// #define int long long

using namespace std;

int main(){
	int N;
	int a[100000];
	int b;
	int cou=0;
	int coun=0;
	cin >> N;
	for(int i=0;i<N;i++){
		cin >> b;
		if(b%4==0){
			a[i]=2;
			cou++;
		}
		else if (b%2==0){
			a[i]=1;
			coun++;
		}
	}
	if(cou*2+coun >= N || (N%2==1 && cou*2+coun >= N-1)){
		cout << "Yes";
	}else{
		cout << "No";
	}

}


/*
偶数 1 0 1 0 > N/2
奇数 0 1 0 > (N-1)/2
*/


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

using namespace std;

int n;
const int64_t M = 1000000007;
const int MAX_N = 1000000;
int64_t fact[MAX_N];
int64_t inv[MAX_N];

int64_t mod_pow(int64_t a, int64_t b)
{
  if (b == 0) return 1;
  int64_t ret = mod_pow(a, b/2);
  ret = ret * ret % M;
  if (b % 2 == 1) ret = a * ret % M;
  return ret;
}

int64_t comb(int64_t n, int64_t k)
{
  return (fact[n] * inv[n-k] % M) * inv[k] % M;
}

int main()
{
  cin >> n;

  fact[0] = inv[0] = 1;
  for (int i = 1; i < n; i++) {
    fact[i] = fact[i-1] * i % M;
    inv[i] = mod_pow(fact[i], M-2);
  }

  int64_t sum = 0;

  int64_t prev_c = 0;
  for (int k = 1; k <= n-1; k++) {
    if (k - 1 >= n - 1 - k) {
      int64_t c = (comb(k-1, n-1-k) * fact[k] % M) * fact[n-1-k] % M;
      sum = (sum + k * ((c - prev_c + M) % M) % M) % M;
      prev_c = c;
    }
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 15872
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pi pair<int,int>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=2e5+10,size=1<<20;

//char buf[size],*p1=buf,*p2=buf;
template<class o> void qr(o &x) {
	char c=gc; x=0; int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=gc;}
	while(isdigit(c)) x=x*10+c-'0',c=gc;
	x*=f;
}
template<class o> void qw(o x) {
	if(x/10) qw(x/10);
	putchar(x%10+'0');
}
template<class o> void pr1(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); putchar(' ');
}
template<class o> void pr2(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); puts("");
}

int T,a,b,c;

int main() {
	qr(a); qr(b); qr(c);
	if((b-1)/a!=c/a) puts("OK");
	else puts("NG");
	return 0;
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(){
  char c;
  cin >> c;
  if(c == 'a'||c == 'e'||c == 'i'||c == 'o'||c == 'u'){
    cout << "vowel";
  }
  else{
    cout << "consonant";
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

const int MOD = 1e9 + 7;
const int MAX = 1e5 + 10;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    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;
    }
}

// 二項係数計算
long long COM(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;
}

int main() {
	int n, k;

	cin >> n >> k;
	vector<long long> a(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());

	COMinit();
	long long sum_maxi = 0;
	long long sum_mini = 0;

	for (int i = 0; i < n; i++) {
		if (n - i - 1 >= k - 1) {
			long long mini = COM(n - i - 1, k - 1);
			sum_mini += mini * a[i];
			sum_mini %= MOD;
			// printf("  mini %dC%d = %lld, %lld\n", n - i - 1, k - 1, mini, mini * a[i]);
		}

		if (i >= k - 1) {
			long long maxi = COM(i, k - 1);
			sum_maxi += maxi * a[i];
			sum_maxi %= MOD;
			// printf("  maxi %dC%d = %lld, %lld\n", i, k - 1, maxi, maxi * a[i]);
		}
	}


	long long ans = sum_maxi + MOD - sum_mini;
	ans %= MOD;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
int main()
{
    string s;
    cin>>s;
    long long  cnt1=0,cnt2=0;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]=='0')
            cnt1++;
        else if(s[i]=='1')
            cnt2++;
    }
    long long minn=0;
    if(cnt1>=cnt2)
        minn=cnt2;
    else
        minn=cnt1;
    printf("%d\n",2*minn);
    return 0;
}


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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

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

struct Edge {
    ll to, rev;
    long double cap;
    Edge(ll _to, long double _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph &G, ll from, ll to, long double cap, bool revFlag,
              long double revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

ll dp[110][10101];
void solve() {
    ll n, W;
    cin >> n >> W;
    vec<ll> v(n), w(n);
    REP(i, n) {
        cin >> v[i] >> w[i];
    }

    REP(i, n + 1) {
        REP(j, W + 1) {
            dp[i][j] = -INF;
        }
    }
    dp[0][0] = 0;
    REP(i, n) {
        REP(j, W + 1) {
            if(dp[i][j] == -INF)
                continue;
            chmax(dp[i + 1][j], dp[i][j]);
            if(j + w[i] <= W)
                chmax(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
        }
    }

    ll ans = 0;
    REP(i, W + 1) { chmax(ans, dp[n][i]); }
    cout << ans << en;
}

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

    solve();

    /*
    ll t;
    cin >> t;
    REP(i, t) { solve();}
    */

    return 0;
}



Measured memory_bytes: 11184
using System;
using System.Collections.Generic;
using System.Linq;

namespace abc148_a
{
    class Program
    {
        static void Main(string[] args)
        {
            HashSet<String> hashSet = new HashSet<String>();
            hashSet.Add("1");
            hashSet.Add("2");
            hashSet.Add("3");

            hashSet.Remove(Console.ReadLine());
            hashSet.Remove(Console.ReadLine());

            Console.WriteLine(hashSet.First());
        }
        
   }
}


Measured memory_bytes: 13280
N=int(input())
a=list()

for i in range(N):
  a.append(int(input()))

#print(a[0])

count=1
b=1
cond=0

if a[0]==2:
  cond=1
  count=1
else:
 for j in range(N):
   count=count+1
   b=a[b-1]
   #print(b)
   if a[b-1] ==2:
     cond=1
     break

if cond==0:
  print(-1)
else:
  print(count)

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

using namespace std;

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

int main()
{
  int N, X[500];
  int Z[250000], ev[250000];
  memset(Z, -1, sizeof(Z));
  memset(ev, -1, sizeof(ev));

  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> X[i];
    --X[i];
    ev[X[i]] = i + 1;
  }

  queue< int > unhappy, happy;

  for(int i = 0; i < N * N; i++) {
    if(~ev[i]) {
      if(ev[i] - 1 > unhappy.size()) fail();
      for(int j = 0; j < ev[i] - 1; j++) {
        Z[unhappy.front()] = ev[i];
        unhappy.pop();
      }
      Z[i] = ev[i];
    } else unhappy.push(i);
  }
  
  for(int i = N * N - 1; i >= 0; i--) {
    if(~ev[i]) {
      if(N - ev[i] > happy.size()) fail();
      for(int j = 0; j < N - ev[i]; j++) {
        Z[happy.front()] = ev[i];
        happy.pop();
      }
    } else if(Z[i] == -1) happy.push(i);
  }

  cout << "Yes" << endl;
  for(int i = 0; i < N * N; i++) {
    cout << Z[i] << " ";
  }
  cout << endl;

}

Measured memory_bytes: 4224
// AOJ 1308 Awkward Lights
// 2018.3.8 bal4u

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

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

#define N 630
#define ABS(a)	((a)>=0?(a):-(a))
#define p(r,c)	((r)*m+(c))

int main()
{
	int m, n, mn, d, i, j, r, c, ans;

	while (m = in()) {
		n = in(), d = in(), mn = m*n;

bitset <N> B[N];

		for (i = 0; i < n; i++) for (j = 0; j < m; j++) {
			if (in()) B[p(i, j)][mn] = 1;
			for (r = 0; r < n; r++) for (c = 0; c < m; c++) {
				if (r == i && c == j || ABS(r-i) + ABS(c-j) == d)
					B[p(i, j)][p(r, c)] = 1;
			}
		}

		n = mn;
		for (i = 0; i < n; i++) {
			for (j = i; j < n; j++) if (B[j][i]) break;
			if (j == n) continue;
			swap(B[j], B[i]);
			for (j = 0; j < n; j++) if (i != j && B[j][i]) B[j] ^= B[i];
		}

		ans = '1';
		for (i = 0; i < n; i++) if (!B[i][i] && B[i][n]) { ans = '0'; break; }
		putchar(ans), putchar('\n');
	}
	return 0;
}


Measured memory_bytes: 3016
#include<bits/stdc++.h>
using namespace std;
#define ran 100010
int n,U,W;
vector<int> e[ran];
int d[ran],fat[ran];
bool in[ran];int mp[ran],sz[ran],lg;
void dfs(int x){
	if(d[x] > d[W])W = x;
	for(auto y : e[x]){
		if(y == fat[x])continue;
		d[y] = d[x] + 1;
		fat[y] = x;
		dfs(y);
	}
}
int A[ran],B[ran];
void doit(int*A){
	int w = 0,l = 0;
	for(int i=0; i<lg; i++){
		for(int j=0; j<sz[i]; j++)
			A[l++] = w + 2 + j;
		A[l++] = w + 1;
		w += 1 + sz[i];
	}
}
bool chk(){
	lg = 0;
	while(1){
		in[W] = true;
		mp[W] = lg++;
		if(W == U)break;
		W = fat[W];
	}
	for(int i=1; i<=n; i++){
		if(!in[i]){
			if(!in[fat[i]])
				return false;
			sz[mp[fat[i]]] ++;
		}
	}
	doit(A);
	reverse(sz,sz+lg);
	doit(B);
	if(memcmp(A,B,sizeof(int)*n) > 0)
		memcpy(A,B,sizeof(int)*n);
	for(int i=0; i<n; i++)
		printf("%d%c",A[i],i<n-1?' ':'\n');
	return true;
}
int main(){
	scanf("%d",&n);
	for(int i=1; i<n; i++){
		int x,y;
		scanf("%d%d",&x,&y);
		e[x].push_back(y);
		e[y].push_back(x);
	}
	fat[1] = W = 1;
	d[1] = 0;
	dfs(1);
	U = W;
	fat[U] = U; d[U] = 0;
	dfs(U);
	if(!chk()){
		puts("-1");
		return 0;
	}
	return 0;
}


Measured memory_bytes: 13440
#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 rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;

int main() {
	int n, k, s;
	cin >> n >> k >> s;

	vector<int> ans;
	rep (i, k) ans.pb(s);
	rep (i, n - k) ans.pb((s == 1000000000 ? 1000000000 - 1 : 1000000000));
	rep (i, n) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 1784
if __name__ == '__main__':
    N = int(input())
    T = list(map(int, input().split()))
    A = list(map(int, input().split()))
    ans = 1
    if T[0] > A[0] or T[N-1] < A[N-1]:
        ans = 0
    for i in range(N-1):
        if T[i] > T[i+1]:
            ans = 0
        if T[i] < T[i+1] and T[i+1] > A[i+1]:
            ans = 0
    for i in range(N-1, 0, -1):
        if A[i] > A[i-1]:
            ans = 0
        if A[i] < A[i-1] and A[i-1] > T[i-1]:
            ans = 0
    for i in range(1, N-1):
        if T[i] != T[i-1] or A[i] != A[i+1]:
            continue
        else:
            ans *= min(A[i], T[i])
            ans %= int(1e9+7)
    print(ans)

Measured memory_bytes: 18756
# -*- coding: utf-8 -*-
# !/usr/bin/env python
# vim: set fileencoding=utf-8 :

"""
#
# Author:   Noname
# URL:      https://github.com/pettan0818
# License:  MIT License
# Created: 日 12/ 2 22:05:15 2018

# Usage
#
"""
PREFERRED = 753
def parse_3num(string):
    """
    >>> parse_3num('1234')
    """
    parsed = []
    temp = list(string)
    counted = len(string) - 2
    for i in range(counted):
        parsed.append(temp[i:i+3])

    return [int(''.join(x)) for x in parsed]


def checker(parsed):
    """
    >>> checker([123,234])
    """
    return min([abs(PREFERRED - i) for i in parsed])

if __name__ == '__main__':
    print(checker(parse_3num(input())))


Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node{
  struct node *prev;
  struct node *next;
  long key;
};
typedef struct node * NP;
NP MN(long);
void IN(NP);
void DN(NP);
void FI(long);
NP dummy;
 
int main(){
  long int val,i,n;
  char op[12];
  NP roop;
 
  scanf("%ld",&n);
  dummy = MN(0);
 
   
 
  for(i=0;i<n;i++){
    scanf("%s",op);
     
    if(strcmp(op,"insert") == 0){
      scanf("%ld",&val);
      IN(MN(val));
    }
    else if(strcmp(op,"delete") == 0){
      scanf("%ld",&val);
      FI(val);
    }
    else if(strcmp(op,"deleteFirst") == 0){
      DN(dummy->next);
    }
    else if(strcmp(op,"deleteLast") == 0){
      DN(dummy->prev);
    }
  }
 
  for(roop=dummy->next;roop!=dummy;roop =roop->next){
    printf("%ld",roop->key);
    if(roop->next != dummy)printf(" ");
  }  
  printf("\n");
 
  return 0;
}
 
 
void FI(long value){
  NP n;
  dummy->key = value;
  for(n = dummy->next;;n=n->next){
    if(n->key == value)break;
  }
  if(n != dummy)DN(n);
     
}
 
 
void DN(NP th){
  th->prev->next = th->next;
  th->next->prev = th->prev;
  th->prev = th->next = th;
  free(th);
  //delete th;
}
 
 
void IN(NP newn){
  newn->next = dummy->next;
  newn->next->prev = newn;
  dummy->next = newn;
  newn->prev = dummy;
}
 
NP MN(long key){
  NP no = (NP)malloc(sizeof(struct node));
  //n = new struct node();
  no->prev = no;
  no->next = no;
  no->key = key;
  return no;
} 


Measured memory_bytes: 32940
a = []
a = input().split()
N = int(a[0])
K = int(a[1])

i = 1
s = 1
d = 0

while s > 0:
  s = N // i
#  print('s=', s)
  i = i * K
#  print('i=', i)
  d += 1
#  print('d=', d)

if s == 0:
  d -= 1

print(d)



Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
    int a, b, c;
    cin >> a >> b >> c;  // a < b となっている
    int divisor = 0;  // divisor = 約数
    
    for(int i = a; i <= b; i++){ // a+1ずつするようになっている
        if((c % i) == 0) divisor += 1;
        else continue;
    }
    
    cout << divisor << endl;
    
    
    return 0;
}


Measured memory_bytes: 3112
n=input()
m=len(n)-1

ans=0
for i in range(2**m):
    num=format(i,"b").zfill(m)
    N=list(n)
    for j,k in enumerate(num):
        if k=="1":N[j]=N[j]+"+"
    ans +=eval("".join(N))
print(ans)

Measured memory_bytes: 39152
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner stdIn = new Scanner(System.in);
		
		int A = stdIn.nextInt();
		int B = stdIn.nextInt();
		
		if(A % 3 == 0 || B % 3 == 0 || (A+B) % 3 == 0)
		{
			System.out.println("Possible");
		}
		else
		{
			System.out.println("Impossible");
		}

	}

}


Measured memory_bytes: 35564