akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const ll INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A, ll x = 10){cout << fixed << setprecision(x) << A << endl;}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){
  ll res = x / gcd(x, y);
  res *= y;
  return res;
};

//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; 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 comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}




void solve(){
  COMinit();
  ll N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  vector<ll> X(N+10);
  X[0] = 0;

  rep(i, N){
    X[i+1] = (i+1) * X[i] % MOD + fac[i];
    X[i+1] %= MOD;
  }
  ll ans = 0;
  rep(i, N-1){
    ll add = A[i+1] - A[i];
    add = add * X[i+1] % MOD * fac[N-1] % MOD * finv[i+1] % MOD;
    ans += add;
    ans %= MOD;
  }
  cout << ans << endl;
}


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


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

int main()
{
	char ch;//ch:?????????
	
	while(1){
		scanf("%c",&ch);
		if(ch == '\n') break;
		
		if(islower(ch) != 0){ //ch????°???????????????\????°????????????????
			ch = toupper(ch); //?°????????????§??????
			cout << ch;
		}else if(isupper(ch) != 0){ //??§???????????????????????\?????§???????????????
			ch = tolower(ch); //o??????????°???????
			cout << ch;
		}else{ //??±????????\???
			cout << ch;
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1148
#include <stdio.h>
#include <iostream>
using namespace std;

int main(void) {
    int A, B, C, D;
    cin>>A>>B>>C>>D;
    if (A*B >= C*D) {
        printf("%d", A*B);
    }else{
        printf("%d", C*D);
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a[10], i, j;

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

	for (i=1;i<10;i++)
		for (j = i; j < 10; j++)
			if (a[i - 1] < a[j])
			{
				int temp = a[i - 1];
				a[i - 1] = a[j];
				a[j] = temp;
			}

	for (i = 0; i < 3; i++)
		printf("%d\n", a[i]);

	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

int dp[80005][11];

int main(){
	string s;
	while(cin >> s, s[0] != '0'){
		memset(dp, 0, sizeof(dp));
		//dp[0][0] = 1;
		rep(i,s.size()) {
			int d = s[i] - '0';
			if(d) dp[i + 1][d]++;
			rep(j,11) {
				dp[i + 1][(j * 10 + d) % 11] += dp[i][j];
			}
		}

		int sum = 0;
		range(i,1,s.size() + 1) sum += dp[i][0];
		cout << sum << endl;
	}
}

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

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;

    static void solve(InputReader in, PrintWriter out){
        int n = in.ni();
        long[] div = new long[n+1];
        div[0] = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j*i <= n; j++) {
                div[i*j]++;
            }
        }
        long ans = 0;
        for (int i = 1; i <= n; i++) {
            ans += i*div[i];
        }
        out.println(ans);
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 112928
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)
#define repv(x, arr) for (auto &x : arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a, b) make_pair(a, b)
#define op(i) cout << (i) << endl;
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 2147483600;
const ll infl = 1e17;


int main()
{
    int n;
    cin >> n;
    ll c;
    cin >> c;
    vector<pll> tokei(n);
    vector<pll> hanto(n);
    rep(i,n){
        ll x, v;
        cin >> x >> v;
        tokei[i] = mp(x, v);
        hanto[n - 1 - i] = mp(c - x, v);
    }
    ll nowto = 0;
    ll nowha = 0;
    vll right1(n+1,0);
    vll right2(n+1, 0);
    vll left1(n+1, 0);
    vll left2(n+1, 0);
    rep(i,n){
        nowto += tokei[i].S;
        nowha += hanto[i].S;
        //cout << nowto << " " << tokei[i].F << endl;
        //cout << nowha << " " << hanto[i].F << endl;
        right1[i + 1] = nowto - tokei[i].F;
        right2[i + 1] = nowto - 2 * tokei[i].F;
        left1[i + 1] = nowha - hanto[i].F;
        left2[i + 1] = nowha - 2 * hanto[i].F;
    }
    rep(i,n)
    {
        right1[i + 1] = max(right1[i], right1[i + 1]);
        right2[i + 1] = max(right2[i], right2[i + 1]);
        left1[i + 1] = max(left1[i], left1[i + 1]);
        left2[i + 1] = max(left2[i], left2[i + 1]);
    }
    ll ans = 0;
    rep(i,n+1){
        ans = max(ans, max(right1[i] + left2[n - i], right2[i] + left1[n - i]));
    }
    cout << ans << endl;
}

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

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

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

  int min=R[0], max=-1e+9;
  for (int i=1; i<n; i++) {
    if (R[i]-min>max) max=R[i]-min;
    if (R[i]<min) min=R[i];
  }

  cout << max << endl;
}


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

using namespace std;

using ll = long long;

double len[8][8];

int main(){
  int n;
  vector <ll> x;
  vector <ll> y;

  cin >> n;
  cin.ignore();

  ll tmp_x, tmp_y;
  for(int i = 0; i < n; i++){
    cin >> tmp_x >> tmp_y;
    cin.ignore();
    x.push_back(tmp_x);
    y.push_back(tmp_y);
  }
  // 初期化
  for(int i = 0; i < 8; i++){
    for(int j = 0; j < 8; j++){
      len[i][j] = 0;
    }
  }
  double ans = 0;
  if(n == 2){
    ans = sqrt(pow(x[0] - x[1], 2.0) + pow(y[0] - y[1], 2.0));
    printf("%.12f\n", ans);
    return 0;
  }

  // とにかく記憶していく
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      len[i][j] = sqrt(pow(x[i] - x[j], 2.0) + pow(y[i] - y[j], 2.0));
    }
  }

  // 特定の2点を除いた階乗
  ll fact_2 = 1;
  for(int i = 1; i <= n - 2; i++){
    fact_2 *= i;
  }

  ll fact = 1;
  for(int i = 1; i <= n; i++){
    fact *= i;
  }
  
  ll line_n = (n - 1) * fact_2; // 特定の1辺が入る通り方の数

  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      ans += line_n * len[i][j];
    }
  }

  printf("%.12f\n", ans/fact);
  return 0;
}


    


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n,m,a,b,c,mn=1e18;
int main()
{
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++)
	{
		a=i*m;
		b=m*((n-i)/2);
		c=m*(n-i-(n-i)/2);
		mn=min(mn,max(a,max(b,c))-min(a,min(b,c)));
		//printf("%lld %lld %lld\n",a,b,c);
		b=(m/2)*(n-i);
		c=(m-(m/2))*(n-i);
		mn=min(mn,max(a,max(b,c))-min(a,min(b,c)));
		//printf("%lld %lld %lld\n",a,b,c);
	}
	for(int i=1;i<=m;i++)
	{
		a=i*n;
		b=n*((m-i)/2);
		c=n*(m-i-(m-i)/2);
		mn=min(mn,max(a,max(b,c))-min(a,min(b,c)));
		//printf("%lld %lld %lld\n",a,b,c);		
		b=(n/2)*(m-i);
		c=(n-(n/2))*(m-i);
		mn=min(mn,max(a,max(b,c))-min(a,min(b,c)));
		//printf("%lld %lld %lld\n",a,b,c);		
	}
	printf("%lld\n",mn);
}

Measured memory_bytes: 3828
#[allow(dead_code)]
fn main() {
    let s = i::s();
    let mut ans = s.len();
    for i in 0..26 {
        let c = i + 'a' as u8;
        ans = min(ans, solve(s.clone(), c as char, 0));
    }
    println!("{}", ans);
}
fn solve(s: Vec<char>, c: char, count: usize) -> usize {
    if s.len() <= 1 {
        return count;
    }
    'a: loop {
        for i in 0..s.len() {
            if s[i] != c {
                break 'a;
            }
        }
        return count;
    }
    let mut new = Vec::new();
    for i in 1..s.len() {
        new.push(if s[i - 1] == c || s[i] == c { c } else { '-' })
    }
    solve(new, c, count + 1)
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::num::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }

    pub fn str() -> String {
        read()
    }

    pub fn s() -> Vec<char> {
        str().chars().collect()
    }

    pub fn i() -> i64 {
        read()
    }

    pub fn u() -> usize {
        read()
    }

    pub fn f() -> f64 {
        read()
    }

    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }

    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }

    pub fn iv2(n: usize) -> Vec<(i64, i64)> {
        (0..n).map(|_| iv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }

    pub fn uv2(n: usize) -> Vec<(usize, usize)> {
        (0..n).map(|_| uv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }

    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}


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

void show_array(int n, int num[]) {
    for (int i=0; i<n-1; i++) {
        cout << num[i] << " ";
    }
    cout << num[n-1] << endl;
}

void inset_sor(int n, int num[]) {
    int key;
    show_array(n, num);
    for (int i=1; i<n; i++) {
        key = num[i];
        int j = i-1;
        
        while (j >= 0 && num[j] > key) {
            num[j+1] = num[j];
            j--;
        }
        num[j+1] = key;
        show_array(n, num);
    }
}

int main() {
    int n;
    cin >> n;
    
    int  num[100];
    
    for (int i=0; i<n; i++) {
        cin >> num[i];
    }
    
    inset_sor(n, num);
    
	return 0;
}

Measured memory_bytes: 3076
import math
import itertools
n = int(input())
x = []
y = []
for _ in range(n):
    x1,y1 = map(int,input().split())
    x.append(x1)
    y.append(y1)
ans = 0
l = [int(i) for i in range(n)]
p = list(itertools.permutations(l,n))
for i in range(len(p)):
    for j in range(n-1):
        ans += ((x[p[i][j]]-x[p[i][j+1]])**2 + (y[p[i][j]]-y[p[i][j+1]])**2)**(0.5)
print(ans/math.factorial(n))

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

typedef int INT_;

#define int long long

const int MAX = 1e5 + 10;

INT_ main()
{	
	string a; cin>>a;
	int n=a.length();
	int ans=0;
	int i=0,j=n-1;

	while(i<=j){
		if(a[i]==a[j]){
			i++; j--;
		}
		else{
			if(a[i]=='x') {ans++; i++;}
			else if(a[j]=='x'){ans++; j--;}
			else {cout<<"-1"; return 0;}
		}
	}

	cout<<ans;
}	

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


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

int Z[100];
   for(int i=0;i<n;i++) cin>>Z[i];


   for(int i=0;i<n-1-i;i++) swap(Z[i], Z[n-1-i]);

   for(int i=0;i<n;i++){
   if(i) cout<<" ";
   cout<<Z[i];
   }
 cout<<endl;

 return 0;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll INF = 0x1fffffffffffffff;
int main(){
  ll h,n;
  cin>>h>>n;
  vector<pair<ll,ll>> m(n);
  for(ll i=0;i<n;i++){
    ll a,b;
    cin>>a>>b;
    m[i]=make_pair(a,b);
  }
  vector<ll> dp(h+1,INF);
  dp[0]=0;
  for(ll i=0;i<h;i++){
    for(ll j=0;j<n;j++){
      if(i+m[j].first<h){
          dp[i+m[j].first]=min(dp[i+m[j].first],dp[i]+m[j].second);
      }else{
          dp[h]=min(dp[h],dp[i]+m[j].second);
      }
    }
  }
  //for(ll i=0;i<h+1;i++)cout<<dp[i]<<endl;
  cout<<dp[h]<<endl;
}

Measured memory_bytes: 384
import sys
sys.setrecursionlimit(10 ** 6)

N = int(input())
G = [[] for i in range(N)]
for i in range(N - 1):
    a, b, w = map(int, input().split())
    G[a - 1].append([b, w])
    G[b - 1].append([a, w])
S = [-1] * N

def func(x, w, c):
    if w % 2 != 0:
        c = 1 - c
    S[x] = c
    for i in range(len(G[x])):
        x1 = G[x][i][0] - 1
        if S[x1] != -1:
            continue
        w1 = G[x][i][1]
        func(x1, w1, c)

func(G[0][0][0] - 1, G[0][0][1], 0)
for i in range(N):
    print(S[i])

Measured memory_bytes: 86368
#include <stdio.h>

#define N 100

int main() {
	static int tt[N];
	int n, m, i, x, sum;

	scanf("%d", &n);
	sum = 0;
	for (i = 0; i < n; i++) {
		scanf("%d", &tt[i]);
		sum += tt[i];
	}
	scanf("%d", &m);
	while (m--) {
		scanf("%d%d", &i, &x), i--;
		printf("%d\n", sum - tt[i] + x);
	}
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI=acos(-1);

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

    ll sm = 0;

    for (int bit = 0; bit < (1 << (s.size()-1)); ++bit){
        ll t = 0;
        rep(i, s.size()){
            t = t*10 + s[i] - '0';
            if (bit & (1<<i)){
                sm += t;
                t = 0;
            }
        }
        sm += t;

    }

    cout << sm << endl;

    return 0;
    
}

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

char a[50][50], b[50][50];

int main() {
	int n, m;
	cin >> n >> m;
	
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	
	for(int i = 0; i < m; i++){
		cin >> b[i];
	}
	
	for(int i = 0; i < n-m+1; i++){
		for(int j = 0; j < n-m+1; j++){
			bool flag = true;
			for(int k = 0; k < m; k++){
				for(int l = 0; l < m; l++){
					if(a[i+k][j+l] != b[k][l]){
						flag = false;
					}
				}
			}
			if(flag){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	
	cout << "No" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>

int main(){
	
	char num[1000];
	
	while (1){
		scanf("%s", num);
		if (num[0]==48) break;
		int sum=0;
		int i=0;
		while(num[i]){
			sum += num[i] -48;
			i++;
		} 
		printf("%d\n", sum);
	}
	return 0;
}

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

long long calc_cost(int begin, int end, vector<long long>& a, vector<long long>& a_sum, vector<vector<long long>>& memo){
  //cout << begin << ' ' << end << endl;
  if(end - begin == 1){
    return memo[begin][end] = 0;
  }
  if(memo[begin][end] != -1){
    return memo[begin][end];
  }

  long long ret = 1e15;
  // [begin, end) = [begin, sep) + [sep, end)
  for(int sep = begin + 1; sep < end; sep++){
    calc_cost(begin, sep, a, a_sum, memo);
    calc_cost(sep, end, a, a_sum, memo);
    long long sum = a_sum[end] - a_sum[begin];
    ret = min(ret, memo[begin][sep] + memo[sep][end] + sum);
  }
  //cout << memo[begin][end] << endl;
  return memo[begin][end] = ret;
}

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

  vector<long long> a(N);
  for(auto& x: a){
    cin >> x;
  }

  vector<long long> a_sum(N + 1);
  for(int i = 1; i <= N; i++){
    a_sum[i] = a_sum[i - 1] + a[i - 1];
  }
  
  vector<vector<long long>> memo(N + 1, vector<long long>(N + 1, -1));
  cout << calc_cost(0, N, a, a_sum, memo) << endl;
  
}


Measured memory_bytes: 1536
import java.util.Scanner;

class Main{
public static void main(String[] args){
  Scanner sc = new Scanner(System.in);
  int n = sc.nextInt();
  int ans = 0;
  String[] Psplit = new String[n];
  for(int i = 0; i < n;i++){
    Psplit[i] = sc.next();
  }
  
  for(int i = 0; i < n-2;i++){
  if(Integer.parseInt(Psplit[i]) < Integer.parseInt(Psplit[i+1]) && Integer.parseInt(Psplit[i+1]) < Integer.parseInt(Psplit[i+2])){
   ans = ans + 1;
  }
  if(Integer.parseInt(Psplit[i]) > Integer.parseInt(Psplit[i+1]) && Integer.parseInt(Psplit[i+1]) > Integer.parseInt(Psplit[i+2])){
   ans = ans + 1;
  }
  }
  System.out.println(ans);
 }
}

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

int main() {
	int n;
	cin >> n;
	deque<int> d;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		if (i % 2 == 0)
			d.push_back(x);
		else
			d.push_front(x);
	}
	if (n % 2 == 1) 
		reverse(begin(d), end(d));
	for (int i = 0; i < n; i++) {
		cout << d[i] << ' ';
	}
	return 0;
}

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

int main()
{
	while (true){
		int n, m;
		cin >> n >> m;
		if (!n&&!m){ break; }
		int sugoroku[1001], dice[1001];
		for (int i = 1; i <= n; i++){
			cin >> sugoroku[i];
		}
		for (int i = 1; i <= m; i++){
			cin >> dice[i];
		}

		int p = 1, i = 0;
		while (p < n){
			p += dice[++i];
			p += sugoroku[p];
		}
		cout << i << endl;
	}
	return 0;
}

Measured memory_bytes: 1168
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#define rep(i, a, n) for(int i = a;i < n;++i)
#define repe(i, a, n) for(int i = a;i <= n;++i)
#define repr(i, a, n) for(int i = a;i > n;--i)
#define reper(i, a, n) for(int i = a;i >= n;--i)
using namespace std;


int main(){
	int N, D, X;
	int A[110];
	cin >> N >> D >> X;
	repe(i, 1, N) cin >> A[i];

	int ans = X;
	repe(i, 1, N)
		for(int j = 0;j*A[i]+1 <= D;j++) ans++;

	cout << ans << endl;

	return 0;
}

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

const int INF = 1001001001;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    int ans = 0;
    rep(si,h) rep(sj,w) {
        if (s[si][sj] == '#') continue;
        vector<vector<int>> dist(h, vector<int>(w, INF));
        queue<P> q;
        auto update = [&](int i, int j, int x) {
            if (dist[i][j] != INF) return;
            dist[i][j] = x;
            q.push(P(i,j));
        };
        update(si, sj, 0);
        while (!q.empty()) {
            int i = q.front().first;
            int j = q.front().second; q.pop();
            rep(dir,4) {
                int ni = i+di[dir], nj = j+dj[dir];
                if (ni<0 || ni>=h || nj<0 || nj>=w) continue;
                if (s[ni][nj] == '#') continue;
                update(ni, nj, dist[i][j]+1);
            }
        }
        rep(i,h) rep(j,w) {
            if (dist[i][j] == INF) continue;
            ans = max(ans, dist[i][j]);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)

def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math

n = getN()
nums = getList()
if sum(nums) % ((n * (n+1)) // 2) != 0:
    print("NO")
    sys.exit()
n_operate = sum(nums) // ((n * (n+1)) // 2)

v_valid = n_operate
v_sign = n

for i, j in zip(nums, nums[1:] + [nums[0]]):
    diff = j - i
    if diff > v_valid:
        print("NO")
        sys.exit()
    if (v_valid - diff) % v_sign != 0:
        print("NO")
        sys.exit()
    n_operate -= (v_valid - diff) // v_sign
    # print(n_operate)
if n_operate == 0:
    print("YES")
else:
    print("NO")
# print("YES")

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(M), sum(N);
  for (int i = 0; i < M; i++) cin >> A.at(i);
  for (int i = 0; i < M; i++) {
    int fail = 0;
    for (int j = 0; j < N; j++) {
      int B;
      cin >> B;
      if (B == A.at(i)) sum.at(j)++;
      else fail++;
    }
    sum.at(A.at(i) - 1) += fail;
  }
  for (int i = 0; i < N; i++) cout << sum.at(i) << endl;
}


Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,Q;
    long long K;

    vector<int> A(100000);
    cin >>N>>K>>Q;
    vector<int> M(100000);
    for(int i=0;i<Q;i++){
        cin >>A.at(i);
        M.at(A.at(i)-1)++;
    }
    for(int i=0;i<N;i++){
        if(M.at(i)>Q-K){
            cout<<"Yes"<<endl;
            continue;
        }
        cout <<"No"<<endl;
    }
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,m,i,j,k,l,p;
    cin>>n;
    cin>>m>>k;
    if(n>k)
    {
        cout<<"NG";
    }
    else
    {
        j=n;
        for(i=1; i<=1000; i++)
        {
            if(j>k)
            {
                cout<<"NG";
                return 0;
            }
            j=n*i;
            if(j>=m && j<=k)
            {
                cout<<"OK";
                return 0;
            }
        }

    }
}


Measured memory_bytes: 3632
#include <stdio.h>

int main()
{
    int n,p[20],ans = 0;

    scanf("%d",&n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d",&p[i]);
    }
    
    for (int i = 0; i <= n - 3; i++)
    {
        if (((p[i] > p[i + 1]) && (p[i + 1] > p[i + 2])) || ((p[i + 2] > p[i + 1]) && (p[i + 1] > p[i])))
        {
            ans ++;
        }
        
    }
    printf("%d",ans);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> l(n);
    for(int i=0;i<n;i++){
        cin>>l[i];
    }
    sort(l.begin(),l.end());
    int ans=0;
    int a,b,c;
    for(int i=0;i<n;i++){
        b=l[i];
        for(int j=0;j<i;j++){
            a=l[j];
            int ab=a+b;
            int r=lower_bound(l.begin(),l.end(),ab)-l.begin();
            int l=i+1;
            ans+=max(0,r-l);
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("rng gorilla apple");
            //YES
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("yakiniku unagi sushi");
            //NO
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("a a a");
            //YES
        }
        else if (InputPattern == "Input4") {
            WillReturn.Add("aaaaaaaaab aaaaaaaaaa aaaaaaaaab");
            //NO
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        string[] wkArr = InputList[0].Split(' ');

        string A = wkArr[0];
        string B = wkArr[1];
        string C = wkArr[2];

        bool IsOK = true;
        if (A.Last() != B[0]) IsOK = false;
        if (B.Last() != C[0]) IsOK = false;
        Console.WriteLine(IsOK ? "YES" : "NO");
    }
}


Measured memory_bytes: 11220
# -*- coding: utf-8 -*-
x = int(input())

l = [0]*(x+1)
l[0] = 1
for i in range(1,x+1):
    for j in range(100,106):
        if i-j>=0:
            l[i] += l[i-j]

if l[x]>0:
    print(1)
else:
    print(0)

Measured memory_bytes: 23996
N = gets.to_i
T, A = gets.split.map(&:to_i)
H = gets.split.map(&:to_i).map{|v| T - v * 0.006}
min = 1e6
ans = 0
H.length.times{|i|
    val = (A - H[i]).abs
    if val < min then
        min = val
        ans = i + 1
    end
}
puts ans


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) { rep(_, n) cout << a[_] << " "; cout << endl; }
#define outp(a, n) { cout << endl; rep(_, n) cout << a[_].F << " " << a[_].S << endl; }
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
#define FIX(a) fixed << setprecision(a)
#define LB(v, n) (int)(lower_bound(all(v), n) - v.begin())
#define UB(v, n) (int)(upper_bound(all(v), n) - v.begin())
ll pow(ll a, int b) {return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1;}
ll nck(int n, int k) { ll ret = 1; rep(i, k) {ret *= n - i; ret /= i + 1; } return ret; }
// n <= 60



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    ll n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    
    rep(k, n + 1) {
        if (k * c - (n - 1 - k) * d <= b - a && b - a <= k * d - (n - 1 - k) * c) {
            out("YES");
            return 0;
        }
    }
    out("NO");
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,p,ans = 0,i;
    vector<int>v1,v2;
    cin>>p;
    for(i = 0;i < p;i++)
    {
        cin>>a;
        v1.push_back(a);
    }
    v2 = v1;
    sort(v2.begin(),v2.end());
    for(i = 0;i < p;i++)
    {
        if(v1[i]!=v2[i])
            ans++;
    }
    if(ans>2)
        cout<<"NO\n";
    else
        cout<<"YES\n";
    return 0;
}


Measured memory_bytes: 256
x1, x2, x3, x4, x5 = map(int, input().split())

if x1 == 0:
  print(1)
elif x2 == 0:
  print(2)
elif x3 == 0:
  print(3)
elif x4 == 0:
  print(4)
else:
  print(5)

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

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

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

	int counter = 0;
	for (;;) {
		int count = count_if(A.begin(), A.end(), [](int t) { return t % 2 == 0; });
		if (count != N) {
			break;
		}
		else {
			counter++;
			for (auto& t : A) {
				t = t / 2;
			}
		}
	}

	cout << counter << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<queue>
#include<set>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int> >;
using pii = pair<int, int>;
using ppi = pair<pii, int>;

int f_dir[2][4] = {{-1, 0, 1, 0}, {0, 1, 0, -1}}; //↑→↓←
int e_dir[2][8] = {{-1, -1, -1, 0, 0, 1, 1, 1}, {-1, 0, 1, -1, 1, -1, 0, 1}};
bool is_in_field(int y, int x, int h, int w){
  return (y >= 0 && y < h && x >= 0 && x < w);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  int n; cin >> n;
  set<string> ss;
  for(int i = 0; i < n; i++){
    string s; cin >> s;
    ss.insert(s);
  }
  cout << ss.size() << endl;
  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


Measured memory_bytes: 19244
H, W = map(int, input().split())
state = False
moves = []
ans = []
for i in range(H):
    row = tuple(zip(range(W), map(int, input().split())))
    for j, a in reversed(row) if i & 1 else row:
        if a & 1:
            state = not state
            if not state:
                moves.append((i + 1, j + 1))
                for pair in zip(moves[:-1], moves[1:]):
                    ans.append(sum(pair, tuple()))
                moves = []
        if state:
            moves.append((i + 1, j + 1))
print(len(ans))
for a in ans:
    print(*a)

Measured memory_bytes: 24228
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

int main() {
    int64_t n, x;
    cin >> n >> x;

    int64_t len = 0;
    len += n;
    int64_t bottom = x, side = n - x;
    while (side > 0 && bottom > 0) {
        if (side < bottom) {
            auto m = (bottom - 1) / side;
            len += 2 * m * side;
            bottom -= side * m;
        } else if (side > bottom) {
            auto m = (side - 1) / bottom;
            len += 2 * m * bottom;
            side -= bottom * m;
        } else if (side == bottom) {
            len += bottom;
            side = 0;
        }
    }

    cout << len << endl;

    return 0;
}

Measured memory_bytes: 256
/// Kazuki Hoshino


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define f first
#define ss second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple

vi v;
int x, ans = inf;

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

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);


rep(i, 1, 3){
cin >> x;
v.pb(x);
}
sort(all(v));

do{
    int temp = abs(v[0]-v[1])+abs(v[1]-v[2]);
    ans = min(ans , temp);
}
while (next_permutation(all(v)));

cout << ans << endl;







return 0;}
///.... Maria Otonashi


Measured memory_bytes: 256
/**
 *    author:  FromDihPout
 *    created: 2020-07-23
**/

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


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s, t;
    cin >> s >> t;
    int m = s.length(), n = t.length();
    
    vector<vector<int>> dp(m+1, vector<int> (n+1));
    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= n; j++) {
            if (s[i-1] == t[j-1]) {
                dp[i][j] = dp[i-1][j-1] + 1;
            }
            else {
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }
    
    string ans(dp[m][n], '?');
    int r = m, c = n, index = dp[m][n] - 1;
    while (r > 0 && c > 0) {
        if (s[r-1] == t[c-1]) {
            ans[index] = s[r-1];
            index--;
            r--;
            c--;
        }
        else if (dp[r][c] == dp[r-1][c]) {
            r--;
        }
        else {
            c--;
        }
    }
    
    cout << ans << '\n';
    return 0;
}

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

using ll=long long;

int main() {
    int i,j,z;
    ll res=0;
    bool ct=0;
    string S;
    cin >> S;
    vector<int> d, r(S.size()+1, 0);

    if(S.at(0) == '<') {
        d.push_back(i);
        ct = 1;
    }

    for(i=0; i<S.size(); i++)
        if(!ct && S.at(i)=='<') {
            d.push_back(i);
            ct = 1;
        } else if(S.at(i) == '>')
            ct = 0;

    for(int x : d) {
        z = 1;
        for(j=x-1; j>=0; j--) {
            if(S.at(j) == '>')
                r.at(j) = z++;
            else
                break;
        }
    }

    if(S.at(S.size()-1) == '>') {
        z = 1;
        for(i=S.size()-1; i>=0; i--) {
            r.at(i) = z++;
            if(i!=0 && S.at(i-1)=='<')
                break;
        }
    }
    
    for(int x : d) {
        z = 1;
        for(j=x; j<S.size(); j++) {
            if(S.at(j) == '<') {
                if(z+1 <= r.at(j+1))
                    continue;
                r.at(j+1) = z++;
            } else
                break;
        }
    }

    for(int x : r)
        res += x;
    cout << res << endl;
}

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

using namespace std;

typedef long long ll;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define bit(n) (1<<(n))

#define rep(i,n) for (int i=0;i<(n);i++)
#define repp(i,n) for (int i=0;i<=(n);i++)

int main(){
	int x[4], cnt=0;
	in(n);

	x[0] = n % 10;
	n /= 10;
	x[1] = n % 10;
	n /= 10;
	x[2] = n % 10;
	n /= 10;
	x[3] = n % 10;
	n /= 10;

	rep(i, 4)
		if(x[i] == 2)	++cnt;

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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cstring>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
using namespace std;
#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 LL long long
#define lowbit(x) x &(-x)

inline int read() {
    int x = 0, flag = 1;char ch = getchar();
    while(!isdigit(ch)) {
        if(ch == '-') flag = - 1;
        ch = getchar();
    }
    while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
    return x * flag;
}
const int N = 1e5 + 5;
const int mod = 998244353;
int a[N], n, b[N];
LL ans = 1;
int main() {   
    n = read();
    REP(i, 1, n) {
        a[i] = read(); b[a[i]] ++;
    }
    if(a[1] || b[0] > 1) {
        cout << 0 << endl;
        return 0;
    }
    //cout << "ha" << endl;
    for(int i = 2; i <= n; ++i) {
        int x = b[i];
        while(x --) {
            ans = (ans * b[i - 1]) % mod;
        }
    }
    printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <iostream>
#include <string.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.precision(20);
    
    long long A, B, C, K;
    cin >> A >> B >> C >> K;

    long long ans = A-B;
    if(K%2) ans = -ans;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long ll;

int main(){
    
    ll N,A,B;
    
    cin>>N>>A>>B;
    
    if(N%(A+B)<=A){
        cout<<(N/(A+B))*A+N%(A+B)<<'\n';
    }if(N%(A+B)>A){
        cout<<(N/(A+B))*A+A<<'\n';
    }
    
    
}

Measured memory_bytes: 256
import itertools
import sys
def main():
    n,k = map(int, input().split())
    ds =  list(map(int, input().split()))
    for i in range(n, 10**6):
        s = str(i)
        for d in ds:
            if str(d) in s:
                f = False
                break
            else:
                f = True
        if f:
            print(i)
            sys.exit()
if __name__ == "__main__":
    main()

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

class Program
{
    static void Main(string[] args)
    {
        // 入力
        long n = long.Parse(Console.ReadLine());
        string[] s = new string[n];
        for (int i = 0; i < n; i++)
        {
            s[i] = Console.ReadLine();
        }

        var dic = new SortedDictionary<string, long>(StringComparer.OrdinalIgnoreCase){};
        long max = 0;
        for (int i = 0; i < n; i++)
        {
            if (dic.ContainsKey(s[i]))
            {
                dic[s[i]] += 1;
                max = Math.Max(max, dic[s[i]]);
            }
            else
            {
                dic.Add(s[i], 1);
                max = Math.Max(max, dic[s[i]]);
            }
        }

        foreach (var d in dic.Where(x => x.Value == max))
        {
            Console.WriteLine(d.Key);
        }
    }
}


Measured memory_bytes: 38072
#include <cstdio>
#include <cmath>
int main(){
	double xs[21],ys[21];
	double x,y;
	int n=0;
	while(scanf("%lf,%lf",&x,&y)!=EOF){
		 xs[n]=x,ys[n++]=y;
	}
	x=0;
	for(int i=0;i<n;i++)x+=(xs[i]-xs[(i+1)%n])*(ys[i]+ys[(i+1)%n]);
	printf("%.8f\n",fabs(x/2.0));
}

Measured memory_bytes: 2544
<?php
$a = explode(' ', trim(fgets(STDIN)));
$n = $a[0];
$d = $a[1];
$num = 0;
$d_2 = $d * 2 + 1;
for ($i = 1; $n > $d_2 * $i; $i++) {
}
echo $i . PHP_EOL;


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

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] nr = br.readLine().split(" ");
        int n = Integer.parseInt(nr[0]);
        int r = Integer.parseInt(nr[1]);
        System.out.println(problem156a(n, r));
    }

    private static int problem156a(int n, int r) {
        return (n >= 10) ? r : (r + 100 * (10 - n));
    }
}

Measured memory_bytes: 22484
#include<bits/stdc++.h>
#define ll long long
#define dbl double
#define forn(i,n,k) for(int i=0;i<n;i=i+k)
#define forpn(p,n,k) for(int i=p;i<n;i+=k)
#define for0(i,n) for(int i=0;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
using namespace std;
int a[500000],b[500000];
int no_of_bits(long long n)
{
    int count=0;
    while(n>0)
    {
        n=n>>1;
        count++;
    }
    return count;
}
long long gcd(int a,int b)
{
    if(b==0) return a;
    else return gcd(b,a%b);
}
void primeFactors(int n,int p)  
{  
    
   if(n%2==0){ a[p]=2;}
    while (n % 2 == 0)  
    {  
        // cout << 2 << " ";
        
        // a[p]=2;
        n = n/2;  
    }  
  
    for (int i = 3; i <= sqrt(n); i = i + 2)  
    {  
     if(n%i==0){ if(a[p]>0) b[p]=i;
         else a[p]=i;
     }
        while (n % i == 0)  
        {  
            // cout << i << " ";  
            n = n/i;  
        }  
    }  
    
}
void solve(){
   for(int i=0;i<5;i++){
       int x;
       cin>>x;
       if(x==0) cout<<i+1;
   }
}
int main()
{   ios::sync_with_stdio(0);
    int t;
    // cin>>t;
    t=1;
    cin.tie(0);
    cout.tie(0);
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
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;
}
const long long INF = 1LL << 60;
long long dp[110][100100]={0};
int main(void){
	
    int N;cin>>N;
  	int W;cin>>W;
	long long weight[N];
	long long value[N];
	for(int i=0;i<N;i++){
    	cin>>weight[i];
    	cin>>value[i];
    }  
  	for(int i=0;i<N;i++){
    	for(int j=0;j<=W;j++){
			if(j>=weight[i]){
               chmax(dp[i+1][j],dp[i][j-weight[i]]+value[i]);
            }
            chmax(dp[i+1][j],dp[i][j]);
            
        }
    }
  	cout<<dp[N][W]<<endl;
    return 0;
}


Measured memory_bytes: 79360
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;

void main() {
    auto S = readln.chomp;
    iota(S.length-2).map!(i => S[i..i+3]).map!(s => abs(753-s.to!int)).reduce!min.writeln;
}



Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
ab = [LI() for _ in range(n)]
ab.sort(key = itemgetter(1))
print(sum(ab[0]))
 

Measured memory_bytes: 91828
#include<iostream>
#include<vector>
using namespace std;
int main(void){
    string w;
    cin>>w;
    int m;
    m=w.size();   

    for(int i=0;i<m;i++){
       int con=1;
       for(int j=i+1;j<m;j++){

           if(w[i]==w[j]){
               if(w[j]!=9){
              con++;
              w[j]=9;
               }
           }
       }
       if(w[i]!=9){
       if(con%2!=0){
           cout<<"No"<<endl;
           return 0;
       }
       }
    }
    cout <<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
#define DEBUG 0

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

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------
#define MOD 1000000007

char S[200000];
int fib[200005],dp[200005];
int main() {
    int i;
    int N,M;
    scanf("%d %d",&N,&M);
    for (i = 0; i < M; i++) scanf(" %c",&S[i]);

    for (i = 0; i < M; i++) {
        if (S[i] != S[0]) break;
    }
    if (i == M) {
        fib[0] = fib[1] = 1;
        for (i = 2; i < N+5; i++) fib[i] = (fib[i-1]+fib[i-2]) % MOD;
        printf("%d\n",(fib[N-2]+fib[N]) % MOD);
    }
    else {
        if (N & 1) printf("0\n");
        else {
            N /= 2;
            int B = 1e9,c = 0,f = 1;
            for (i = 0; i < M; i++) {
                if (S[i] == S[0]) c++;
                else {
                    if (f) B = min(B,(c & 1) ? c:c+1),f = 0;
                    else if (c & 1) B = min(B,c);
                    c = 0;
                }
            }
            B = (B+1)/2;
            dp[0] = 1;
            int sum = 1;
            for (i = 1; i < N+5; i++) {
                dp[i] = sum;
                sum += dp[i],sum %= MOD;
                if (i >= B) sum -= dp[i-B],sum %= MOD;
            }
            int ans = dp[N];
            for (i = 1; i < B; i++) {
                if (N-i-1 >= 0) {
                    ans += ((LLI) i*dp[N-i-1]) % MOD;
                    ans %= MOD;
                }
            }
            ans = (2*ans) % MOD;
            if (ans < 0) ans += MOD;
            printf("%d\n",ans);
        }
    }

    return 0;
}



Measured memory_bytes: 1280
n,m=map(int,input().split())
mmin=0
mmax=n
for  i in range(m):
  l,r=map(int,input().split())
  if l>mmin:
    mmin=l
  if r<mmax:
    mmax=r
ans=0
if mmax-mmin+1>0:
  ans=mmax-mmin+1
print(ans)



Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
	int cnt=0;
	double a,b,c;
	char s,t;
	while(cin>>a>>s>>b>>t>>c){
		if(b/(c*c)>=25){
			cout<<a<<endl;
			cnt++;
		}
	}
	if(cnt==0){
		cout<<"該当なし"<<endl;
	}
	return 0;
}

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

const int MAX_N = 1<<17;
const int INF_MAX=1<<32-1;

//minに対するsegtree

int n, dat[2*MAX_N-1];
void init(int n_){
    n=1;
    while( n< n_) n*=2;
    for(int i=0; i<2*n-1; i++) dat[i]=INT_MAX;
}

void update(int k, int a){
    k += n-1;
    dat[k]=a;
    while(k >0){
        k= (k-1)/2;
        dat[k] = min(dat[k*2+1], dat[k*2+2]);
    }
}

int query (int a, int b, int k, int l, int r){
    if(r <=a || b <=l) return INT_MAX;
    if(a <=l && r <=b ) return dat[k];
    int vl =query(a,b,k*2+1,l,(l+r)/2);
    int vr =query(a,b,k*2+2,(l+r)/2,r);
    return min(vl, vr);
}

int main(){
    int N, q; cin >> N >> q; init(N);
    for(int i=0; i<q; i++){
        int c, x, y; cin >> c >> x >> y;
        if(c==0){
            update(x,y);
        }
        if(c==1){
            cout << query(x,y+1,0,0,n) << endl;
        }
    }
}


Measured memory_bytes: 4088