akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 6;

vector< int > adj[N];
int a[N];
long long dfs(int v = 0, int par = -1) {
  long long sum = (adj[v].size() <= 1) ? a[v] : 0;
  long long ma = sum;
  for (int u : adj[v]) if (u != par) {
    long long cur = dfs(u, v);
    if (cur < 0)
      return -1;
    if (ma < cur)
      ma = cur;
    sum += cur;
  }
  long long up = 2LL * a[v] - sum;
  if (up < (ma - (sum - ma)) || up > sum)
    return -1;
  return up;
}


int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", a+i);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    u--; v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  puts(dfs() == 0 ? "YES" : "NO");
  return 0;
}

Measured memory_bytes: 12800
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <stdio.h>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);++i)
#define urep(i,a,n) for(ll i = (a);i>=(n);--i)
#define all(x) (x).begin(),(x).end()
#define INF 1e18
typedef long long ll;
const ll MAX=510000;
const ll mod = 1e9 + 7;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N,M,X,Y,A,B,C,D,Q,K,R,W,H,P,L,G;
ll ans[101010];
string S,T;
ll h[101010];
ll y[101010];
ll a[201010];
ll k[101010];
ll b[201010];
ll d[101010];
ll t[101010];
ll p[101010];
ll n[101010];
ll l[101010];
ll r[101010];
ll v[101010];
ll s[101010];
ll x[101010];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}
struct Edge{
	ll to,cost;
	 Edge(ll to, ll cost) : to(to), cost(cost) {}
};
typedef vector<vector<Edge> > AdjList;
AdjList graph;
vector<ll> dist;

struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
	vector<ll> size;
    UnionFind(ll N) : par(N),size(N) { //最初は全てが根であるとして初期化
        for(ll i = 0; i < N; i++) par[i] = i;
		for(ll i = 0; i < N; i++) size[i] = 1;
    }

    ll root(ll x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
	ll GetSize(ll x){
		return size[root(x)];
	}

    void unite(ll x, ll y) { // xとyの木を併合
        ll rx = root(x); //xの根をrx
        ll ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
		size[ry]+=size[rx];

    }

    bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};

int main(){
    cin>>S;
    ll left  =0;//hukumu
    ll right =0;//hukumanai
    rep(i,1,S.size()){
        if(S[i]=='L'){
            if(i==S.size()-1){
                right = S.size();
            }
            rep(j,i,S.size()){
                if(S[j]=='R'){
                    right = j;
                    break;
                }
                if(j==S.size()-1){
                    right = j+1;
                }
            }
            rep(j,left,right){
                if(abs(j-i)%2==0){
                    ans[i]++;
                }else{
                    ans[i-1]++;
                }
            }
            left = right;
            i = left-1;
        }
    }
    rep(i,0,S.size()-1){
        cout<<ans[i]<<" ";
    }
    cout<<ans[S.size()-1]<<endl;
    return 0;
}


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

using namespace std;

const int N=1e6+3;

#define pb push_back
#define all(x) (x).begin(),(x).end()
typedef long long ll;

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

const int inf=1e9;

int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans;

char s[N];

void IO(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("test.txt","r",stdin);
	#endif
}

int aa[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};


int main(){
	//IO();
	scanf("%d",&n);
	printf("%d\n",aa[--n]);
}


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

int main(){
  int i, j;
  cin >> i >> j;
  
  vector<string> row( j + 2, "#" );
  for(int n = 0; n < j + 2; n++){
    cout << row.at(n);
  }
  cout <<endl;
  for(int n = 0; n < i; n++){
    string str;
    cin >> str;
    cout << "#" << str << "#" << endl;
  }
  
  for(int n = 0; n < j + 2; n++){
    cout << row.at(n);
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
 
int main() {
	int n;
	int cnt=0;
	int f=0;
	int a[1024]={0};
	cin>>n;
	while(1){
		if(n>0){
			for(int i=0;;i+=2){
				cnt+=pow(-2,i);
				if(cnt>=n){
					n-=pow(-2,i);
					a[i]=1;
					cnt=0;
					break;
				}
			}
		}else if(n<0){
			for(int i=1;;i+=2){
				cnt+=pow(-2,i);
				if(cnt<=n){
					n-=pow(-2,i);
					a[i]=1;
					cnt=0;
					break;
				}
			}
		}else{
			break;
		}
	}
	for(int i=1023;i>=0;i--){
		if(a[i]==1&&f==0){
			cout<<1;
			f=1;
		}else if(f==1){
			cout<<a[i];
		}else if(f==0&&i==0){
 			cout<<0;
        }
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#include <string.h>
#define ll long long
int main()
{
    int N , M;
    scanf("%d %d",&N,&M);
    int array[M];
    int c[M];
    memset(array, 0, sizeof(array[0]) * M);
    memset(c, 0, sizeof(array[0]) * M);
    int K[N];
    int d = 0;
    int j = 0;
    int i = 0;

    for (int i = 0;i<N;i++)
    {
        scanf("%d",&K[i]);
     for (int j = 0;j<K[i];j++)
      {
          scanf("%d",&array[j]);
          c[array[j]]++;
      }

    }
    if (N!=1)
 {
    int count = 0;
    for (int i = 1;i<=M;i++)
    {
     if (c[i]==N)count++;

    }
    printf("%d",count);
 }
 if (N==1)printf("%d",K[0]);


}


Measured memory_bytes: 128
import java.util.Scanner;

class Main {
    static Scanner sc;

    private static void nextArr(int[] h) {
        for(int i = 0; i < h.length; i++) h[i] = sc.nextInt();
    }

    private static int nextInt() {
        return sc.nextInt();
    }

    private static void print(Object... vals) {
        for(int i = 0; i < vals.length; i++) {
            if (i != vals.length - 1) {
                System.out.print(vals[i] + ",");
            } else {
                System.out.print(vals[i]);
            }
        }
        System.out.println();
    }

    public static void main(String[] args) {
        sc = new Scanner(System.in);
        int n = nextInt();
        int[][] cost = new int[n][3];
        for(int i = 0; i < n; i++) nextArr(cost[i]);
        int[][] dp = new int[n][3];

        for(int i = 0; i < 3; i++) dp[0][i] = cost[0][i];
        for(int i = 1; i < n; i++) {
            for(int j = 0; j < 3; j++) {
                for(int k = 0; k < 3; k++) {
                    if (j != k) {
                        dp[i][j] = Math.max(dp[i][j], dp[i - 1][k] + cost[i][j]);
                    }
                }
            }

        }
        int max = Integer.MIN_VALUE;
        for(int i = 0; i < 3; i++) {
            max = Math.max(max, dp[n - 1][i]);
        }
        print(max);


    }
}


Measured memory_bytes: 99484
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();


        int total = 0;

        for (int i = 1; i < n + 1; i++) {
            int sum = sumOfDigits(i);
            if (a <= sum && sum <= b) {
                total += i;
            }
        }
        System.out.println(total);
    }

    public static int sumOfDigits(int n) {
        int sum = 0;
        while (n > 0) {
            sum += n % 10;
            n /= 10;
        }
        return sum;
    }
}


Measured memory_bytes: 22612
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#define MAX 1000
int top=0;
void push(int);
int pop();
int a[MAX];
int main(){
  
  int a;
  char s[100];

  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      push(pop()+pop());

    } else if ( s[0] == '-' ){
      int g=pop(),h=pop();
      
      push(h-g);

    } else if ( s[0] == '*' ){
      push(pop()*pop());

    } else {
      a = atoi(s);
      push(a);

    }
  }
  printf("%d\n",pop());
  return 0;
}
void push(int x){
  top++;
  a[top]=x;
}
int pop(){
  top--;
  return a[top+1];
}



Measured memory_bytes: 2760
#coding:utf-8
import math

def main():
    a, b = map(int, input().split())
    
    for i in range(2000):
        if math.floor(i * 0.08) == a and math.floor(i * 0.1) == b:
            print(i)
            break
    else:
        print(-1)

if __name__ == '__main__':
    main()




Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>

#define X first
#define Y second
#define vsort(v) sort((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())

// stoi(s): string to int
// stod(s): string to double

// INT_MAX
// INT_MIN
// LLONG_MAX
// LLONG_MIN
// DBL_MIN
// DBL_MAX
// LDBL_MIN
// LDBL_MAX

// A-Z: 65~90
// a-z: 97~122
// |a-z| = 26

using namespace std;
using ll = long long;

int main(int argc, const char * argv[]) {
    int n, max = - 1, sum = 0;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        sum += v[i];
        if (v[i] > max) {
            max = v[i];
        }
    }
    cout << sum - (max / 2) << endl;
}


Measured memory_bytes: 256
from sys import stdin
from collections import deque
from collections import Counter
N,X,Y = [int(x) for x in stdin.readline().rstrip().split()] 
ans = Counter()

for k in range(1,N+1):
    dist = [0] + [10**9]*(N)
    visited = [False for i in range(N+1)]
    visit_p = deque()
    visit_p.append((k,0))

    while visit_p:
        #print(visit_p)
        node,cnt = visit_p.popleft()
        dist[node] = min(cnt,dist[node])

        if node == X:
            #print(node,cnt,"s")
            if not visited[Y]:
                visit_p.append((Y,cnt+1))
                visited[Y] = True

        if node == Y:
            #print(node,cnt,"s")
            if not visited[X]:
            #ans[cnt+1] += 1
                visit_p.append((X,cnt+1))
                visited[X] = True
        #print(visit_p,"e")   
        for d in [-1,1]:
            if node + d < 1 or node + d > N:
                continue
            if visited[node+d]:
                continue
            #print(node+d,cnt,"e")
            #ans[cnt+1] += 1
            visited[node+d] = True
            visit_p.append((node+d,cnt+1))
        
    ans += Counter(dist)
    
for i in range(1,N):
    print(ans[i]//2)

Measured memory_bytes: 113884
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0; i<(int)(n); ++i)
#define REP(i,m,n) for(ll i=(ll)(m); i<(ll)(n); ++i)
#define F first
#define S second
const double PI=acos(-1);
//fixed<<setprecision(11)<<

int main(){
  int n, m, sum = 0;
  cin >> n >> m;
  vector<int> a(n);
  rep(i, n){
    cin >> a[i];
    sum += a[i];
  }

  int b = (sum+4*m-0.1)/(4*m);
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());

  if(a[m-1] < b) cout << "No" << endl;
  else cout << "Yes" << endl;
return 0;
}

Measured memory_bytes: 3628
import java.util.*;
public class Main {
  static int H, W, N;
  static int[][] ans;
  // へび
  static void snake(int n, int x){
    int h = n / W;
    int w = n % W;
    if(h % 2 == 1)
      w = W - w - 1;
    ans[h][w] = x + 1;
  }
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    H = sc.nextInt();
    W = sc.nextInt();
    N = sc.nextInt();
    ArrayList<Integer> nums = new ArrayList<>();
    for(int i = 0; i < N; i++) {
      int a = sc.nextInt();
      for(int j = 0; j < a; j++)
        nums.add(i);
    }
    ans = new int[H][W];
    for(int n = 0; n < nums.size(); n++){
      snake(n, nums.get(n));
    }
    for(int i = 0; i < H; i++){
      System.out.print(ans[i][0]);
      for(int j = 1; j < W; j++)
        System.out.print(" " + ans[i][j]);
      System.out.print('\n');
    }
  }
}

Measured memory_bytes: 33564
#include<math.h>
#include<stdio.h>
#include<utility>
#include<algorithm>

int main() {
	int a, b, c, e;
	int d = 0;

	scanf("%d %d %d" , &a, &b, &c);//////////////////////
	
while (d == 0) {
		if (a > b) {
			e = a;
			a = b;
			b = e;
		}
		if (b > c) {
			e = b;
			b = c;
			c = e;
			}
		if (a <= b) {
			if (b <= c) {
				d = 1;
			}
		}
	}
printf("%d %d %d\n", a, b, c);
	return 0;
}

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

using namespace std;

int main(void)
{
	int n,k,cnt=0;

	cin>>n>>k;

	string s;

	cin>>s;

	while(cnt<k){
		if(cnt==k-1){
			if(s[cnt]=='A'){
				s[cnt]='a';
			}
			else if(s[cnt]=='B'){
				s[cnt]='b';
			}
			else if(s[cnt]=='C'){
				s[cnt]='c';
			}
		}
		cnt++;
	}

	cout<<s<<endl;

	return 0;
}


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

int main() {
  string T;
  cin>>T;
  int size=T.size();
  for(int i=0;i<size;i++){
    if(T[i]=='?') T[i]='D';
  }
  cout<<T;
  
}


Measured memory_bytes: 3760
//#include <boost/multiprecision/cpp_int.hpp> 
#include<bits/stdc++.h>
#define ll long long 
#define ull unsigned ll
#define pb push_back
#define mp make_pair
#define in insert
#define F first
#define S second
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define test    ll t=0;cin>>t;while(t--)
#define fast    ios_base::sync_with_stdio(false);cin.tie(NULL)
//using namespace boost::multiprecision; 
using namespace std;

int main(void) {
	fast;
	ll n,ans=0,i,j,k;
	cin>>n;
	ll a[n][3];
	rep(i,0,n){
	rep(j,0,3){
	cin>>a[i][j];}}
	for(i=1;i<n;i++){
	    for(j=0;j<3;j++){
	        ll c=0;
	        for(k=0;k<3;k++){
	            if(k==j)
	            continue;
	            c=max(c,a[i][j]+a[i-1][k]);
	        }
	        a[i][j]=c;
	    }
	}
	cout<<max(a[n-1][0],max(a[n-1][1],a[n-1][2]));
	return 0;
}



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

// bool isPrime(unsigned int n);

int main()
{
    int n;
    while(cin>>n){
        vector<int> primeTable;
        if( n==1 ){ cout << "0" << endl; continue; }
        primeTable.push_back(2);
        vector<int>::iterator j;
        for(int i=3; i<=n; i+=2){
            for(j=primeTable.begin(); j!=primeTable.end(); j++){
                if(!(i%(*j))) break; 
                if( (*j)*(*j) >= i ) {j=primeTable.end();break;} 
            }
            if( j==primeTable.end() ) primeTable.push_back(i);
        }
        cout << primeTable.size() << endl;
    }
    

    return 0;
}

Measured memory_bytes: 1860
s = input()
n = len(s)

boundary = []
res = [0] * n

# LR の位置を特定する
for i in range(n - 1):
	if s[i] == 'L' and s[i + 1] == 'R':
		boundary.append(i)

# 最右端は必ずLなので
boundary.append(n-1)

r = 0
for l in boundary:
	mid = 0
	cnt_odd, cnt_even = 0, 0
	for x in range(r, l + 1):
		if x % 2 == 0: cnt_even += 1
		if x % 2 == 1: cnt_odd += 1
		if x < l and s[x] == 'R' and s[x + 1] == 'L':
			mid = x
	if mid % 2 == 0:
		res[mid] = cnt_even
		res[mid + 1] = cnt_odd
	else:
		res[mid] = cnt_odd
		res[mid + 1] = cnt_even
	r = l + 1

print(*res)


Measured memory_bytes: 50364
# cook your dish here
n,k=input().split()
n=int(n)
k=int(k)
l=list(map(int,input().split()))
for j in range(n):
    if k+j==n:
        break
    if l[k+j]>l[j]:
        print("Yes")
    else:
        print("No")
    
      
   


    


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

using namespace std;

int main(){
    string s;
    int n = 0;
    cin >> s;
    for (int i = 0; i < s.size(); ++i) {
        if(s[i] == 'o'){
            n++;
        }
    }
    cout << 700 + 100 * n << endl;
}

Measured memory_bytes: 256
package main

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

type bit []int

func newBIT(n int) bit {
	return make([]int, n+1)
}

func (b *bit) add(i, x int) {
	for i++; i <= len(*b)-1; i += i & -i {
		(*b)[i] += x
	}
}

func (b *bit) sum(i int) int {
	x := 0
	for i++; i != 0; i -= i & -i {
		x += (*b)[i]
	}
	return x
}

type t struct {
	X int
	H int
}
type byX []t

func (a byX) Len() int           { return len(a) }
func (a byX) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a byX) Less(i, j int) bool { return a[i].X < a[j].X }

func main() {
	N := readInt()
	D := readInt()
	A := readInt()
	XH := make([]t, N)
	for i := 0; i < N; i++ {
		XH[i].X = readInt()
		XH[i].H = (readInt() + A - 1) / A
	}

	sort.Sort(byX(XH))
	result := 0
	b := newBIT(N + 1)
	for i := 0; i < N; i++ {
		x, h := XH[i].X, XH[i].H
		h -= b.sum(i)
		if h <= 0 {
			continue
		}
		result += h
		b.add(i, h)

		ok := i
		ng := N
		for ng-ok != 1 {
			m := ok + (ng-ok)/2
			if XH[m].X <= x+2*D {
				ok = m
			} else {
				ng = m
			}
		}
		b.add(ng, -h)
	}
	fmt.Println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


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

typedef long long int ll;

void iterate(vector<ll> &v) {
    for(int i = 0; i < v.size(); ++i) {
        cout << v[i] << " ";
    }
    cout << endl;
}

int main() {
    ll N, C; cin >> N >> C;
    vector<ll> dist(N, 0), value(N, 0);

    for(int i = 0; i < N; ++i) {
        cin >> dist[i] >> value[i];
    }

    vector<ll> left(N, 0), leftReturn(N, 0);
    ll val = 0, dst = 0;
    for(int i = 0; i < N; ++i) {
        val += value[i];
        dst = dist[i];
        left[i] = val - dst;
        leftReturn[i] = val - dst * 2;
    }
    leftReturn[0] = max(leftReturn[0], 0LL);
    for(int i = 1; i < N; ++i) {
        leftReturn[i] = max(leftReturn[i], leftReturn[i-1]);
    }


    vector<ll> right(N, 0), rightReturn(N, 0);
    val = 0, dst = 0;
    for(int i = N - 1; i >= 0; --i) {
        val += value[i];
        dst = C - dist[i];
        right[i] = val - dst;
        rightReturn[i] = val - dst * 2;
    }
    rightReturn[N-1] = max(rightReturn[N-1], 0LL);
    for(int i = N - 2; i >= 0; --i) {
        rightReturn[i] = max(rightReturn[i], rightReturn[i+1]);
    }

    ll result = 0;
    for(int i = 0; i + 1 < N; ++i) {
        result = max(result, left[i] + rightReturn[i+1]);
    }
    result = max(result, left[N-1]);

    for(int i = N-1; i - 1 >= 0; --i) {
        result = max(result, right[i] + leftReturn[i-1]);
    }
    result = max(result, right[0]);

    cout << result << endl;

    return 0;
}

Measured memory_bytes: 4992
import sys
input = sys.stdin.buffer.readline
 
h,n = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(n)]

inf=float("inf")
dp=[inf]*(h+1)
 
dp[0]=0

for a,b in AB:
    for i in range(h):
        if dp[i]!=float("inf"):
            dp[min(i+a,h)]=min(dp[min(i+a,h)],dp[i]+b)
print(dp[-1])
            

Measured memory_bytes: 69092
#include <bits/stdc++.h>
using namespace std;
using Int = unsigned long long;

int n,ans;
void dfs(Int res,int p,int q,int r){
    if(res>n)return;
    if(p&&q&&r)ans++;
    dfs(res*10+3,1,q,r);
    dfs(res*10+5,p,1,r);
    dfs(res*10+7,p,q,1);
    return;
}

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

    cin>>n;
    dfs(0,0,0,0);
    cout<<ans<<'\n';
}

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

int main(){
  int N,K,X,Y,anc =0;
  cin >> N >> K >> X >> Y;
  for(int i =0; i < N; i++){
    anc += X;
  }
  for( int i=0; i < N-K; i++){
    anc -= (X-Y);
  }
  cout << anc << endl;
    

 
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    int dp[n+1]={0};
    dp[1]=abs(arr[1]-arr[0]);
    for(int i=2;i<n;i++)
    {
        dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
    }
    cout<<dp[n-1];
}

Measured memory_bytes: 1024
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

N,M=LI()
BS=list(map(lambda x: x//2, LI()))

LCM=1
GCD=BS[0]
for i in range(N):
    LCM = LCM*BS[i]//gcd(LCM, BS[i])
    GCD = gcd(GCD, BS[i])

# print("LCM:{}".format(LCM))

if (LCM//GCD) % 2 == 0:
    print(0)
else:
    print(M//LCM//2 + (M//LCM)%2)


Measured memory_bytes: 14372
<?php

$result = array();
while (($line = trim(fgets(STDIN))) !== '') {
    sscanf($line, '%d,%f,%f', $n, $kg, $m);
    if ($kg / pow($m, 2) >= 25.0) {
        $result[] = $n;
    }
}
echo count($result) > 0 ? implode(PHP_EOL, $result) : '該当なし', PHP_EOL;

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

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

const ll MOD = 1000000007;

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

    int cnt[3] = {0};
    ll ans = 1;
    for (int i = 0; i < n; i++) {
        int num;
        scanf("%d", &num);

        int tmp = 0;
        for (int j = 0; j < 3; j++) {
            if (cnt[j] == num)
                tmp++;
        }

        ans = (ans * tmp) % MOD;

        for (int j = 0; j < 3; j++)
            if (cnt[j] == num) {
                cnt[j]++;
                break;
            }
    }

    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp make_pair
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main(){
  int n;
  cin>>n;
  vector<int> c(n);
  rep(i,n) cin>>c[i];

  vector<int> cur(n,0);
  int q;
  cin>>q;
  rep(i,q){
    int t,x,d;
    cin>>t>>x>>d;
    x--;
    if(t==1){
      if(cur[x]+d <= c[x]) cur[x] += d;
      else {cout << x+1 <<endl; return 0;}
    }
    else if(t==2){
      if(d<=cur[x]) cur[x] -= d;
      else{cout << x+1 << endl; return 0;}
    }
  }

  cout << 0 << endl;

  return 0;
}



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

int SelectionSort(int A[],int N){
  int minj;
  int sw = 0 ;
     for(int i = 0; i < N-1; i++){
         minj = i;
       for(int j = i; j < N; j++){
           if(A[j] < A[minj]) minj = j;     
       }
     swap(A[i], A[minj]);           // t = A[i];A[i] = A[minj];A[minj] = t;
       if(i != minj) sw++;
     }
  return sw;
}


int main(){
   int n, A[100], sw;
  cin >> n;
  for(int i = 0; i < n; i++) cin >> A[i];
  
  sw = SelectionSort(A,n);
  
  for(int i = 0; i < n; i++){
     if(i) cout << " ";         //if(i > 0) printf(" ");
    cout << A[i];               //printf("%d", A[i]);
  }
  cout << endl;                 //printf("\n");
  cout << sw << endl;           //printf("%d\n", sw);
  
  return 0;
}


Measured memory_bytes: 3108
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;
int f[50];
int main()
{
    int n;
    cin >>n;
    for(int i=0;i<n;i++)
        cin >> f[i];
    int cnt=0;
    int minn=f[0];
    for(int i=0;i<n;i++){
        if(f[i]>=minn){
            cnt++;
            minn=f[i];
        }
    }
    cout << cnt <<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int main()
{
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<pair<long long,int>>e;
	map<long long,int>ret;
	for(int i=0;i<n;i++)
	{
		long long x;
		cin>>x;
		ret[x]=i;
		e.push_back({x,i});
	}
	sort(e.rbegin(),e.rend());
	long long x=e.back().first;
	vector<int>sz(n,1);
	vector<long long>dp(n,0);
	vector<pair<int,int>>ans;
	for(auto c:e)
	{
		if(c.first!=x)
		{
			if(sz[c.second]*2>=n)
			{
				cout<<-1<<endl;
				return 0;
			}
			long long need=c.first-(n-2*sz[c.second]);
			if(!ret.count(need))
			{
				cout<<-1<<endl;
				return 0;
			}
			int par=ret[need];
			dp[par]+=dp[c.second]+sz[c.second];
			sz[par]+=sz[c.second];
			ans.push_back({c.second+1,par+1}); 
		}
	}
	if(dp[e.back().second]!=x)
	{
		cout<<-1<<endl;
		return 0;
	}
	for(auto c:ans)
		cout<<c.first<<' '<<c.second<<endl;
	return 0;
}


Measured memory_bytes: 12272
import Control.Monad (replicateM)

f :: [[Integer]] -> Integer -> Integer
f [] _ = 0
f ([a, b]:abs) acc =
    c + f abs (acc + c)
  where c = (-a - acc) `mod` b

main = do
    n <- readLn :: IO Int
    ab <- reverse <$> replicateM n ((map read . words) <$> getLine) :: IO [[Integer]]
    print $ f ab 0

Measured memory_bytes: 127740
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll i = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll i = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll i = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll i = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
// constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

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

	ll ans = 0;
	for (ll i = 1; i * i < n; ++i){
		if (n % i == 0 && i < n / i - 1) ans += n / i - 1;
	}
	co(ans);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;            //

int main(void)
{
    int H, W;
    cin >> H >> W;

    H += 2;
    W += 2;
    vector<vector<char>> S(H, vector<char>(W));
    // init
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            S[i][j] = '.';
        }
    }

    // input
    for (int i = 1; i < H - 1; i++)
    {
        for (int j = 1; j < W - 1; j++)
        {
            cin >> S[i][j];
        }
    }

    // debug
    // for (int i = 0; i < H; i++)
    // {
    //     for (int j = 0; j < W; j++)
    //     {
    //         printf("%c", S[i][j]);
    //     }
    //     printf("\n");
    // }
    int counter;
    for (int i = 1; i < H - 1; i++)
    {
        for (int j = 1; j < W - 1; j++)
        {
            counter = 0;
            if (S[i][j] == '.')
            {
                if (S[i - 1][j - 1] == '#')
                    counter++;
                if (S[i - 1][j] == '#')
                    counter++;
                if (S[i - 1][j + 1] == '#')
                    counter++;
                if (S[i][j - 1] == '#')
                    counter++;
                if (S[i][j + 1] == '#')
                    counter++;
                if (S[i + 1][j - 1] == '#')
                    counter++;
                if (S[i + 1][j] == '#')
                    counter++;
                if (S[i + 1][j + 1] == '#')
                    counter++;

                S[i][j] = counter + '0';
            }
        }
    }
    for (int i = 1; i < H - 1; i++)
    {
        for (int j = 1; j < W - 1; j++)
        {
            cout << S[i][j];
        }
        cout << endl;
    }
    return (0);
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Sparsh Sanchorawala
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CMaximumVolume solver = new CMaximumVolume();
        solver.solve(1, in, out);
        out.close();
    }

    static class CMaximumVolume {
        public void solve(int testNumber, InputReader s, PrintWriter w) {
            double l = s.nextInt();
            double a = l / 3;
            w.println(a * a * a);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 22868
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

	static enum alp {
		a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z
	}

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

		/*	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String teststr = null;
		
			if (br.ready()) {
				teststr += br.readLine();
				System.out.println(teststr);
			}
			System.out.println("endloop");
		*/
		Scanner sc = new Scanner(System.in);

		String str = "";
		
		while (sc.hasNext()) {
			String tmp = sc.nextLine();//文字列入力
			str += tmp;//文字列入力

			if (tmp.equals("")) {
				break;
			}

			//		System.out.println(str);
		}

		//	System.out.println("end:"+str);

		//拡張for文　enum型の中身を1つずつ呼び出し
		for (alp a : alp.values()) {

			//入力を文字単位に分解
			char[] ch = str.toCharArray();//文字単位でリスト化

			int count = 0;

			for (char c : ch) {//配列を呼び出し

				//配列内の文字を文字列に再変換
				String c_str = String.valueOf(c);

				//enumの中身のアルファベットと上で変換した文字列が同じかを比較
				if (a.toString().equalsIgnoreCase(c_str)) {

					count++;
				}

			}

			System.out.println(a.toString() + " : " + count);

		}

	}

}



Measured memory_bytes: 29352
H, W = map(int, input().split())
grid = [list(map(int, input().split())) for _ in range(H)]
ope = []
for y in range(H):
    for x in range(W):
        if grid[y][x] % 2 != 0 and (y, x) != (H - 1, W - 1):
            # grid[y][x] -= 1
            grid[y + (W == x + 1)][x + (W != x + 1)] += 1
            ope.append((y + 1, x + 1, y + 1 + (W == x + 1), x + 1 + (W != x + 1)))

print(len(ope))
for o in ope:
    print(*o)


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

int main(){
  int n, k; cin >> n >> k;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  int ok = *max_element(a.begin(), a.end()) , ng = 0;
  while(ok - ng > 1){
    int cnt = 0;
    int mid = (ok + ng) / 2;
    for(int i = 0; i < n; i++){
      cnt += (a[i] - 1) / mid;
    }
    if(cnt <= k) ok = mid;
    else ng = mid;
  }
  cout << ok << endl;
}

Measured memory_bytes: 4048
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
map<int,int> M;
int a[110000],tot=0;
int main()
{
//	freopen("in.txt","r",stdin);
//	freopen("out.txt","w",stdout);
	int n,x;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		if(!M.count(x)) a[++tot]=x;
		M[x]++;
	}
	int ans=0;
	for(int i=1;i<=tot;i++)
	if(M[a[i]]&1) ans++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 5376
def input_from_console():
    k = int(input())
    s = input()
    return k, s


def solve(k, s):
    if len(s) > k:
        return s[0:k] + "..."
    return s


def main():
    k, s = input_from_console()
    print(solve(k, s))


if __name__ == "__main__":
    import sys

    if sys.gettrace():  # Check if the python interpreter is in debug mode or not.
        check_cases()
    else:
        main()


Measured memory_bytes: 9180
N, W = map(int, input().split())
dp = [[0 for i in range(W + 1)] for j in range(N+1)]

for j in range(N):
    w, v = map(int, input().split())
    for k in range(W + 1):
        if k >= w:
            dp[j+1][k] = max(dp[j][k-w] + v, dp[j][k])
        else:
            dp[j+1][k] = dp[j][k]

print(dp[N][W])


Measured memory_bytes: 173448
h,w,a,b=map(int,input().split())
a-=1
b-=1
ans=[[0 for i in range(w)] for j in range(h)]
for i in range(h):
  for j in range(w):
    if (i>b and j>a) or (i<=b and j<=a):
      ans[i][j]=1
for x in ans:
  print(*x,sep="")

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

using namespace std;
       
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> h(n);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}      
	if (n == 2) {
		cout << abs(h[1] - h[0]) << endl;
	} else {
		vector<int> dp(n);
		dp[1] = abs(h[1] - h[0]);
		for (int i = 2; i < n; i++) {
			dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]));
		}
		cout << dp[n - 1] << endl;
	}
	return 0;
}




Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int a,b;
	cin >> a >> b; --a; --b;
	cout << (b+a-1)/a << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1012345678;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

// int gcd(int a, int b){
//   if (a%b==0){
//     return(b);
//   }
//   else{
//     return(gcd(b,a%b));
//   }
// }





int main(){
  int N;
  double t,a;
  cin >>N>>t>>a;
  double ans = 10000000;
  int idx = 0;
  rep(i,N){
    double c;
    cin >> c;
    double tmp = t-c*0.006;
    double diff = abs(tmp - a);
    if(diff < ans){
      ans = diff;
      idx = i;
    }
  }
  cout << ++idx << endl;
  return 0;
}




Measured memory_bytes: 256
a,b,c,d=map(int,input().split())
if a%d==0:
  T=a//d
else:
  T=(a//d)+1
if c%b==0:
  A=c//b
else:
  A=(c//b)+1
if A>T:
  print('No')
else:
  print('Yes')

Measured memory_bytes: 61756
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6;
int x[N];
int main(){
	int n, k;
	scanf("%d %d",&n,&k);
		memset(x,0,sizeof(x));
		int r, s, p;
		string str;
		scanf("%d %d %d",&r,&s,&p);
		getchar();
		cin >> str;
		long long ans = 0;
		for(int i = 0; i < n; i++){
			if(str[i] == 'r'){
				if(i < k || x[i-k] != 1) {
					ans += p;
					x[i] = 1;
				}
				else x[i] = 0;				
			}
			else if(str[i] == 's'){
				if(i < k || x[i-k] != 2) {
					ans += r;
					x[i] = 2;			
				}
				else x[i] = 0;
			}
			else if(str[i] == 'p'){
				if(i < k || x[i-k] != 3) {
					ans += s;
					x[i] = 3;					
				}
				else x[i] = 0;
			}
		}
		printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4352
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
const ll maxn=500500;
typedef pair<ll,ll>q;
q pos[100005];
int main()
{
    ll n,k,s;
    cin>>n>>k>>s;
    if(s!=1000000000)
    {
        for(ll i=0; i<k; i++)
        {
            cout<<s;
            if(i!=k-1)
                cout<<" ";
        }
        if(k!=n)
            cout<<" ";
        for(ll i=k; i<n; i++)
        {
            cout<<s+1;
            if(i!=n-1)
                cout<<" ";
        }
    }
    else
    {
           for(ll i=0; i<k; i++)
        {
            cout<<s;
            if(i!=k-1)
                cout<<" ";
        }
        if(k!=n)
            cout<<" ";
        for(ll i=k; i<n; i++)
        {
            cout<<s-1;
            if(i!=n-1)
                cout<<" ";
        }
    }







}
/*
2

6
-45 22 42 -16
-41 -27 56 30
-36 53 -37 77
-36 30 -75 -46
26 -38 -10 62
-32 -54 -6 45

6
-45 22 42 -16
-41 -27 56 30
-36 53 -37 77
-36 30 -75 -46
26 -38 -10 62
-32 -54 -6 45
*/


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define MAXN 100
#define MAXW 10000


int main() {
	int N, W;
	int I[MAXN + 1][2], C[MAXN + 1][MAXW + 1];
	cin >> N >> W;
	for (int i = 1; i <= N; i++) {
		cin >> I[i][0] >> I[i][1];
	}
	for (int i = 0; i <= N; i++) {
		C[i][0] = 0;
	}
	for (int w = 0; w <= W; w++) {
		C[0][w] = 0;
	}
	for (int i = 1; i <= N; i++) {
		for (int w = 1; w <= W; w++) {
			if (w < I[i][1])
				C[i][w] = C[i - 1][w];
			else
				C[i][w] = max(C[i - 1][w], C[i - 1][w - I[i][1]] + I[i][0]);
		}
	}
	cout << C[N][W] << endl;
	return 0;
}



Measured memory_bytes: 7048
#include <iostream>
#include <vector>

int main(void)
{

	while(true){
		int n, m;
		std::cin >> n >> m;
		if ( n == 0 && m == 0 ) break;

		std::vector<int> taro(n);
		std::vector<int> hanako(m);

		int sum_taro = 0;
		int sum_hanako = 0;
		for ( int i = 0; i < n; ++i ) {
			std::cin >> taro[i];
			sum_taro += taro[i];
		}
		for ( int i = 0; i < m; ++i ) {
			std::cin >> hanako[i];
			sum_hanako += hanako[i];
		}

		int min = 0xffff;
		int a = -1, b = -1;
		for ( int i = 0; i < n; ++i ) {
			for ( int j = 0; j < m; ++j ) {
				if ( (sum_taro - taro[i] + hanako[j]) == (sum_hanako - hanako[j] + taro[i]) ) {
					if ( min > taro[i] + hanako[j] ) {
						min = taro[i] + hanako[j];
						a = taro[i];
						b = hanako[j];
					}
				}
			}
		}
		if ( a != -1 ) {
			std::cout << a << " " << b << std::endl;
		} else {
			std::cout << -1 << std::endl;
		}

	}
	return 0;
}

Measured memory_bytes: 3096
N = int(input())
A = list(map(int, input().split()))

a0 = A[0]
if a0 > 0:
    S1, cnt1 = a0, 0
    S2, cnt2 = -1, abs(a0) + 1
elif a0 < 0:
    S1, cnt1 = 1, abs(a0) + 1
    S2, cnt2 = a0, 0
else:
    S1, cnt1 = 1, 1
    S2, cnt2 = -1, 1

S = S1
cnt = cnt1
for i in range(1, N):
    nS = S + A[i]
    if S > 0:
        if nS > 0:
            cnt += abs(nS) + 1
            nS = -1
    elif S < 0:
        if nS < 0:
            cnt += abs(nS) + 1
            nS = 1
    S = nS
ans = cnt

S = S2
cnt = cnt2
for i in range(1, N):
    nS = S + A[i]
    if S > 0:
        if nS >= 0:
            cnt += abs(nS) + 1
            nS = -1
    elif S < 0:
        if nS <= 0:
            cnt += abs(nS) + 1
            nS = 1
    S = nS
ans = min(cnt, ans)
print(ans)


Measured memory_bytes: 14212
#include<bits/stdc++.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
int x[4]={6000,4000,3000,2000};
int main(){
	int t,n,d[4];
	for(int i=0;i<4;i++){ scanf("%d%d",&t,&n); printf("%d\n",n*x[t-1]);}
}

Measured memory_bytes: 1188
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def Yes(): print("Yes"); return
def No(): print("No"); return

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def Base_10_to_n(X, n):
  if (int(X/n)):
    return Base_10_to_n(int(X/n), n)+[X%n]
  return [X%n]


#############
# Main Code #
#############

a,b = inputIL()

d = b-a

print((d+1)*d//2-d-a)

Measured memory_bytes: 38424
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;

int main()
{	
	int t;
	cin >> t;
	ll a=1, b=1, t1, t2, n;
	while (t--)
	{
		cin >> t1 >> t2;
		n = max(a / t1, b / t2);
		if (n * t1 < a || n * t2 < b)n++;
		a = n * t1, b = n * t2;
	}
	cout << a + b;
}

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

int main(){
    int H,R;
    cin>>H>>R;
    if(H+R==0){
        cout<<0<<endl;
    }else if(H+R>0){
        cout<<1<<endl;
    }else{
        cout<<-1<<endl;
    }

    return 0;
}


Measured memory_bytes: 3092
// Etavioxy
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#define il inline
#define ll long long
#define rep(i,s,t) for(register int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(register int i=(s);i>=(t);i--)
#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)
#define file(s) freopen(s".in" ,"r",stdin),freopen(s".out","w",stdout)
#define pt(x) putchar(x)
using namespace std;
il int ci(){
	register char ch;int f=1;
	while(!isdigit(ch=getchar()))f=ch=='-'?-1:1;
	register int x=ch^'0';
	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');
	return f*x;
}

enum{N=23};
char g[N][N];
int f[N][N];

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

int main(){
	int n=ci(), m=ci();
	rep(i,1,n){
		scanf("%s",g[i]+1);
	}
	rep(i,1,n) g[i][0]= g[i][m+1]='#';
	rep(j,1,m) g[0][j]= g[n+1][j]='#';
	int ans= 0;
	rep(i,1,n) rep(j,1,m) if( g[i][j]=='.' ){
		memset(f,0,sizeof(f));
		queue<int> q;
		f[i][j]=1;
		q.push(i*40+j);
		while( q.empty()==0 ){
			int x=q.front()/40, y=q.front()%40;
			q.pop();
			rep(s,0,3){
				int tx=x+dx[s], ty=y+dy[s];
				if( g[tx][ty]=='#' || f[tx][ty]!=0 ) continue;
				f[tx][ty] = f[x][y]+1;
				ans=max(ans,f[tx][ty]-1);
				q.push(tx*40+ty);
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256