akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <unordered_map>
#include <assert.h>
using namespace std;

#define ran(i, a, b) for ((i) = (a); (i) < (b); (i)++)
#define rep(i, a) ran ((i), 0, (a))
#define rep1(i, a) ran ((i), 1, (a)+1)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
#define _0 first
#define _1 second
#define _pb(x) push_back(x)
#define _mp(x, y) make_pair(x, y)
#if defined(SHIROKO1_LOCAL) && !defined(NDEBUG)
#define DEBUG(...) fprintf(stderr, "[DEBUG] " __VA_ARGS__)
#else
#define DEBUG(...) ((void)0)
#endif

int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(0, min(b, d) - max(a, c)) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
#define SIZE 2000//頂点数
int gen;
int mini = 1000000000;
class FOREST
{
public:
	int num;//頂点数
	vector<int>pat[SIZE];
	vector<int>ko[SIZE];
	int depth[SIZE];//深さ
	int ord[SIZE];//ord
	int fin[SIZE];//fin 閉区間
	int rord[SIZE];//ordの逆配列
	bool flag[SIZE];
	int subsiz[SIZE];//部分木サイズ
	int par[SIZE];
	int ordpt;
	void adde(int s, int t)//s-t辺を追加
	{
		pat[s].push_back(t);
		pat[t].push_back(s);
	}
	void initdfs(int node, int d)
	{
		if (flag[node])return;
		flag[node] = true;
		subsiz[node] = 1;
		rord[ordpt] = node;
		ord[node] = ordpt++;
		depth[node] = d;
		for (int i = 0; i < pat[node].size(); i++)
		{
			if (!flag[pat[node][i]])
			{
				initdfs(pat[node][i], d + 1);
				ko[node].push_back(pat[node][i]);
				subsiz[node] += subsiz[pat[node][i]];
				par[pat[node][i]] = node;
			}
		}
		fin[node] = ordpt - 1;
	}
	vector<int>calc(int node)
	{
		vector<int>ret;
		ret.resize(1);
		for (int i = 0; i < ko[node].size(); i++)
		{
			vector<int>t = calc(ko[node][i]);
			vector<int>n;
			n.resize(max(ret.size(), t.size()));
			fill(n.begin(), n.end(), 1000000000);
			for (int j = 0; j < ret.size(); j++)
			{
				for (int k = 0; k < t.size(); k++)
				{
					if (j + k <= gen)
					{
						n[max(j, k)] = min(n[max(j, k)], ret[j] + t[k]);
					}
				}
			}
			ret = n;
		}
		int g = min(gen, int(ret.size()) - 1);
		for (int i = 0; i <= g; i++)mini = min(mini, ret[i] + subsiz[0] - subsiz[node]);
		reverse(ret.begin(), ret.end());
		ret.push_back(subsiz[node]);
		reverse(ret.begin(), ret.end());
		/*printf("%d ", node + 1);
		for (int i = 0; i < ret.size(); i++)printf("  %d", ret[i]); printf("\n");*/
		return ret;
	}
};
FOREST tree;
int main()
{
	int num;
	scanf("%d%d", &num, &gen);
	for (int i = 0; i < num - 1; i++)
	{
		int za, zb;
		scanf("%d%d", &za, &zb);
		za--;
		zb--;
		tree.adde(za, zb);
	}
	tree.initdfs(0, 0);
	vector<int>t = tree.calc(0);
	printf("%d\n", mini);
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
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 ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    ll N;cin>>N;
    vector<vector<double>> dp(N+1,vector<double>(N+1));
    dp[0][0]=1;
    repl(i,1,N+1){
        double p;cin>>p;
        rep(j,N+1){
            if(j)dp[i][j]=dp[i-1][j-1]*p+dp[i-1][j]*(1-p);
            else dp[i][j]=dp[i-1][j]*(1-p);
        }
    }
    double ans=0;
    repl(i,N/2+1,N+1)ans+=dp[N][i];
    CST(10)<<ans<<endl;
    return 0;
}

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

#define rep(i,z) for(int i = 0; i<(int)(z); i++)
#define rep1(i,z) for(int i = 1; i<=(int)(z); i++)
 
using namespace std;

typedef long long ll;
const ll MOD=1e9+7;
using pear = pair<int,int>;




int main(){
    string s; cin>>s;
    int ans = 0;
    rep(i ,6) if(s[i] == '1') ans++;
    cout<<ans<<endl;
}


Measured memory_bytes: 3564
import math
A, B, H, M = (int(x) for x in input().split())
theta = abs(6 * ((H*60 + M)/12 - M))
if theta > 180:
    theta = 360 - theta
x = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(math.radians(theta)))
print(x)


Measured memory_bytes: 62432
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

ll calc(string s){
    ll ret = 0, tmp = 0;
    rep(i, s.size()){
        // +の場合
        if(s[i] == '+'){
            ret += tmp;
            tmp = 0;
        }
        // 1桁目の場合
        else if(tmp == 0){
            tmp = s[i]-'0';
        }
        // それ以外の場合
        else{
            tmp *= 10;
            tmp += s[i]-'0';
        }
    }
    return ret+tmp;
}

int main(){
    Init();
    string s; cin >> s;
    ll ans = 0;
    for(ll bit=0; bit<(1LL<<(s.size()-1)); bit++){
        string t = s.substr(0, 1);
        for(ll mask=0; mask<(s.size()-1); mask++){
            if(bit&(1LL<<mask)) t += '+';
            t += s[mask+1];
        }
        ans += calc(t);
    }
    cout << ans << endl;
}

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

struct Point{
    int x, y, turn;
};

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

int main(){
    int t, n;
    while(cin >> t >> n, t != 0){
        set<pair<int, int> > obstacle;
        for(int i=0;i<n;++i){
            int x, y;
            cin >> x >> y;
            obstacle.insert(make_pair(x, y));
        }
        int sx, sy;
        cin >> sx >> sy;

        set<pair<int, int> > visited;
        visited.insert(make_pair(sx, sy));
        queue<Point> que;
        que.push((Point){sx, sy, 0});
        while(!que.empty()){
            auto curr = que.front(); que.pop();
            for(int i=0;i<6;++i){
                auto next = make_pair(curr.x+dx[i], curr.y+dy[i]);
                if(visited.count(next) || obstacle.count(next) || curr.turn >= t)continue;
                visited.insert(next);
                que.push((Point){next.first, next.second, curr.turn+1});
            }
        }

        cout << visited.size() << endl;
    }

    return 0;
}



Measured memory_bytes: 3280
from typing import Set


if __name__ == "__main__":
    int_set: Set[int] = set()
    num_query = int(input())

    for _ in range(num_query):
        op, v = map(lambda x: int(x), input().split())
        if (0 == op):
            int_set.add(v)
            print(len(int_set))
        else:
            if (v in int_set):
                print(1)
            else:
                print(0)



Measured memory_bytes: 24888
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    int a,b;
    cin >> a >> b;
    cout<<(3*a+b)/2<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define NMAX (int)(3*1e6)

using namespace std;

int main(){
	vector<bool> p(NMAX,true);
	vector<int> prime;
	p[0] = false;
	p[1] = false;
	for(int i = 2; i < NMAX; ++i){
		if(!p[i])continue;
		if(i%7 != 1 && i%7 !=6){
			p[i] = false;
			continue;
		}
		prime.push_back(i);
		for(int j = 2; i*j <= NMAX; ++j){
			p[i*j] = false;
		}
	}

	while(true){
		int n; cin >> n;
		if(n == 1)break;
		cout << n << ":";
		for(int i = 0; i < prime.size(); ++i){
			if(n % prime[i] == 0){
				cout << " " << prime[i];
			}
		}
		cout << endl;
	}

	return 0;
}

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

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

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        
        String s = br.readLine();
        String ans = "Good";
        
        for(int i = 0; i < 3; i++){
            if(s.charAt(i) == s.charAt(i + 1)){
                ans = "Bad";
                break;
            }
        }
        
        out.println(ans);
        out.close();
        
    }
}

Measured memory_bytes: 32700
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
//#define endl '\n'
int row, coloumn, k;
string s[10];
vector<vector<int>> combinations;
void recurse(int indx, vector<int> &v)
{
    if(indx == row - 1)
    {
        combinations.push_back(v);
        return;
    }
    v.push_back(indx);
    recurse(indx + 1, v);
    v.pop_back();
    recurse(indx + 1, v);
}
vector<vector<string>> construct(vector<int> &One)
{
    vector<vector<string>> strings;
    One.push_back(1e9);
    strings.resize(One.size());
    for(int i = 0, j = 0; i < row && j < One.size(); i++)
    {
        if(i <= One[j])
            strings[j].push_back(s[i]);
        else
        {
            j++;
            strings[j].push_back(s[i]);
        }
    }
    return strings;
}
int main()
{
    Hello
    cin >> row >> coloumn >> k;
    for(int i = 0; i < row; i++)
        cin >> s[i];
    vector<int> v;
    recurse(0, v);
    int ans = 1e9;
    for(int comb = 0; comb < combinations.size(); comb++)
    {
        vector<vector<string>> curComb = construct(combinations[comb]);
        vector<int> cntr(curComb.size(), 0);
        int lines = 0;
        bool can = true, vis[coloumn] = {};
        for(int col = 0; col < coloumn; col++)
        {
            bool breakGamed = false;
            for(int block = 0; block < curComb.size(); block++)
            {
                for(int r = 0; r < curComb[block].size(); r++)
                {
                    if(curComb[block][r][col] == '1')
                        cntr[block]++;

                    if(cntr[block] > k)
                    {
                        if(vis[col])
                            can = false;
                        else
                        {
                            lines++;
                            vis[col] = true;
                            breakGamed = true;
                            break;
                        }
                    }
                }
                if(breakGamed)
                    break;
            }
            if(breakGamed)
            {
                for(int j = 0; j < cntr.size(); j++)
                    cntr[j] = 0;
                col--;
            }
        }
        if(can)
            ans = min(ans, lines + (int)combinations[comb].size() - 1);
    }
    cout << ans;
    return 0;
}


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

//座標Pで開催される集会に参加するために消費される体力の総和
int stamina(vector<int> X, int P) {
  int ans = 0;
  for (int i=0; i<X.size(); i++) ans += (X.at(i)-P)*(X.at(i)-P);
  return ans;
}

int main() {
  int N;
  cin >> N;
  vector<int> X(N);
  for (int i=0; i<N; i++) cin >> X.at(i);
  int ans = 10000000;
  sort(X.begin(), X.end());
  for (int P=X.at(0); P<=X.at(N-1); P++) ans = min(ans, stamina(X, P));
  cout << ans << endl;
}

Measured memory_bytes: 256
def dist_bfs(N,E,start):
    d = [-1]*N
    d[start] = 0
    q = [start]
    while q:
        qq = []
        for i in q:
            di = d[i]
            for j in E[i]:
                if d[j]!=-1:continue
                d[j] = di+1
                q.append(j)
        q = qq
    return d

N,M = map(int,input().split())
UV = [list(map(int,input().split())) for _ in [0]*M]
S,T = map(int,input().split())

S-=1;T-=1
E = [[] for _ in [0]*3*N]
for u,v in UV:
    u-=1;v-=1
    for i in range(3):
        v = (v+N)%(3*N)
        E[u+i*N].append(v)

print(dist_bfs(3*N,E,S)[T]//3)

Measured memory_bytes: 81852
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,x,sum =0,mn =1001 ;
  int a[1001];

  cin >> n >> x;

  for(int i=0;i<n;i++)
    {
      cin >> a[i];
      sum += a[i];
      mn = min(mn,a[i]);
    }
  x -=sum;

  x /= mn;

  cout << x + n << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
double dis(double x,double y)
{
    if(x<=0 && y>=0)
    {
        return abs(x)+y;
    }
    if(x>=0 && y<=0)
    {
        return abs(x)+abs(y);
    }
    return abs(abs(x)-abs(y));
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    double t,mn=INT_MAX,ans,x,y;
    int n;
    cin>>n;
    cin>>x>>y;
    for(int i=1; i<=n; i++)
    {
        double a,cur;
        cin>>a;
        cur=x-(a*0.006);
        cur=dis(y,cur);
        if(cur<mn){
            mn=cur;
            ans=i;
        }
    }
    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 3796
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::collections::HashMap;
use std::cmp::{max,min};
fn main(){
    input!{
        s:chars,
    }
    let zero = s.iter().filter(|&c| *c == '0').count();
    let one = s.len() - zero;
    let ans = min(zero,one);
    println!("{}",ans*2);
}

Measured memory_bytes: 4352
#include <iostream>
#include<algorithm>
#include<vector>
#include<deque>
#include <numeric>
#include<cmath>
#include<string>
using namespace std;
#define ll long long
typedef pair<ll,ll> p;
int main(void){
    int n;
    cin >> n;
    std::vector<int> p(n);
    for(int i=0;i<n;i++){
        cin >> p[i];
    }
    int cnt=0;
    for(int i=1;i<n-1;i++){
        if((p[i]<p[i-1] and p[i+1]<p[i]) or(p[i]>p[i-1] and p[i+1]>p[i])){
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
p = list(map(int, input().split()))

# 累積和
c = [0] * (n+1)
for i in range(n):
  c[i+1] = c[i] + p[i]
#print(c)
mx = 0
mx_i = -1
for i in range(n-k+1):
  st = c[i+k] - c[i]
  if st > mx:
    mx = st
    mx_i = i
ans = 0
for i in range(mx_i, mx_i+k):
  a = p[i]
  ans += ((a * (a+1)) // 2) / a
print(ans)
# print(mx_a)

Measured memory_bytes: 91800
using System;

class Sample28
{
    static void Main()
    {
        string[] input = Console.ReadLine().Split(' ');
        int n = int.Parse(input[0]);
        int m = int.Parse(input[1]);
        int l = int.Parse(input[2]);

        int[,] A = new int[n, m];
        int[,] B = new int[m, l];
        long[,] C = new long[n, l];

        int i;
        int j; 

        //バリデーション
        if(n < 1 || m < 1 || l < 1 || 100 < n || 100 < m || 100 < m)
        {
            Console.WriteLine("n、m、lいずれかの要素が範囲外です。");
            Environment.Exit(0);
        }
        
        //行列Aを作成
        for (i = 0; i < n; i++)
        {
            string[] inputMatrixA = Console.ReadLine().Split(' ');
            for (j = 0; j < m; j++)
            {
                int matrixAItem = int.Parse(inputMatrixA[j]);
            
            //バリデーション
            if(matrixAItem < 0 || 10000 < matrixAItem)
            {
                Console.WriteLine("行列Aの要素が範囲外です。");
                Environment.Exit(0);
            }
                A[i, j] = matrixAItem ;
            }
        }

        //行列Bを作成
        for (i = 0; i < m; i++)
        {
            string[] inputMatrixB = Console.ReadLine().Split(' ');
            for (j = 0; j < l; j++)
            {
                
                int matrixBItem = int.Parse(inputMatrixB[j]);
                
                if(matrixBItem < 0 || 10000 < matrixBItem)
                {
                    Console.WriteLine("行列Bの要素が範囲外です。");
                    Environment.Exit(0);
            }
                B[i, j] = matrixBItem;
            }
        }

        //行列Cを作成
        for (i = 0; i < n; i++)
        {
            for (j = 0; j < m; j++)
            {
                int k;
                for (k = 0; k < l; k++)
                {
                    C[i, k] += A[i, j] * B[j, k];
                }
            }
        }

        //出力
        for (i = 0; i < n; i++)
        {
            for (j = 0; j < l - 1; j++)
            {
                Console.Write(C[i, j] + " ");
            }
            Console.WriteLine(C[i, l - 1]);
        }
    }
}


Measured memory_bytes: 18040
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    N = int(input())
    C = input()[:-1]
    
    m = C.count("R")
    r = 0
    w = 0
    for i in range(m):
        if C[i] == "W":
            w += 1
    for i in range(m, N):
        if C[i] == "R":
            r += 1
    
    print(max(r, w))


if __name__ == '__main__':
    main()

Measured memory_bytes: 73224
try:
    inp = input().split()
    L = int(inp[0])
    R = int(inp[1])
    d = int(inp[2])
    
    if L >= 1 and R >= 1 and L <= R and L<=100 and R<=100 and d>=1 and d<=100:
        counter = 0
        for i in range(L,R+1):
            if i%d == 0:
                counter += 1
        print(counter)
        
except Exception as e:
    print(e)

Measured memory_bytes: 9156
/**
 * @brief  : c++ code for AtCoder
 * @author : rk222
 * @created: 2019.05.09 19:19:37
 */

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (ll i = 0; i < x; i++)
#define rep1(i, x) for (ll i = 1; i <= x; i++)
#define rrep(i, x) for (ll i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (ll i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

#define disp(x) cout << #x << ": " << x << endl
#define disp_vec(v)                                                                           \
    cout << #v << ":";                                                                        \
    rep(i, v.size()) cout << " " << v[i];                                                     \
    cout << endl

const int INF = 100000000;
const int M = 100000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/* ------------------------------------- */
ll cnt[60];

ll solve(ll lv, ll x) {
    if (lv == 0)
        return 1LL;
    ll cn = cnt[lv];
    if (x == 1) {
        return 0LL;
    } else if (1LL < x && x <= cn / 2) {
        return solve(lv - 1, x - 1);
    } else if (x == cn / 2 + 1) {
        return solve(lv - 1, cnt[lv - 1]) + 1;
    } else if (x > cn / 2 + 1 && x < cn) {
        return solve(lv - 1, cnt[lv - 1]) + solve(lv - 1, x - cn / 2 - 1) + 1;
    } else if (x >= cn) {
        return solve(lv - 1, cnt[lv - 1]) * 2 + 1;
    }
    return -1LL;
}

int main() {
    ll n, x;
    scanf("%lld%lld", &n, &x);

    cnt[0] = 1;
    rep1(i, n) {
        cnt[i] = 2 * cnt[i - 1] + 3;
    }

    printf("%lld\n", solve(n, x));

    /* --------------------------------- */
    return 0;
}

Measured memory_bytes: 256
n = int(input())
Taro = 0
Hanako = 0

for i in range(n):
    x = 0
    t,h = input().split()
    for j in range(min(len(t),len(h))):
        if t == h:
            Hanako += 1
            Taro += 1
            x = 1 
            break
        if ord(t[j:j+1]) > ord(h[j:j+1]):
            Taro += 3
            x = 1
            break
        if ord(t[j:j+1]) < ord(h[j:j+1]):
            Hanako += 3
            x = 1
            break
    if x == 0:
        if len(t) > len(h):
            Taro += 3
        elif len(t) < len(h):
            Hanako += 3
	

print("{} {}".format(Taro,Hanako))

Measured memory_bytes: 7632
#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=1e9;
const int MOD=1e9+7;

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

Measured memory_bytes: 6436
#include <stdio.h>
#define isACGT(a) ((a) == 'A' || (a) == 'C' || (a) == 'G' || (a) == 'T')

char S[10];

int main() {
        scanf("%s", S);

        register int i = 0, acc = 0, ret = 0;
        do {
                if (isACGT(S[i])) {
                        acc++;
                } else {
                        if (acc > ret) {
                                ret = acc;
                        }
                        acc = 0;
                }
        } while (S[i++]);

        printf("%d", ret);

        return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main (void) {
    int n;
    long long a[100010];
    long long result = 1;
    scanf("%d", &n);
    for (int i=0; i<n; i++) {
        long long input;
        scanf("%lld", &input);
        a[i] = input;
        if (input == 0) {
            result = 0;
        }
    }

    if (result == 0) {
        printf("%d\n", 0);
        return 0;
    }

    for (int i=0; i<n; i++) {
        if (a[i] <= 1000000000000000000/result) {
            result *= a[i];
        } else {
            printf("-1\n");
            return 0;
        }
    }

    printf("%lld\n", result);
    return 0;
}

Measured memory_bytes: 2516
N=int(input())

IJ = [[0] * 10 for i in range(10)]
ans = 0

for i in range(1,N+1):
    Top = str(i)[0]
    Btm = str(i)[-1]

    if Btm == '0':
        continue
    
    IJ[int(Top)][int(Btm)] += 1

for i in range(1, 10):
    for j in range(1, 10):
        ans += IJ[i][j] * IJ[j][i]
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>

int main(void) {
    int n;

    scanf("%d\n", &n);

    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9; j++) {
            if (i * j == n) {
                fprintf(stdout, "Yes\n");
                return 0;
            }
        }
    }

    fprintf(stdout, "No\n");
    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;

int main() {
    int n;
    cin >> n;
    int m = 1;
    while (m <= n) {
        m *= 2;
    }
    cout << m / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
/**
 * The man who codes no bugs
 * McCheng is the man studying Maths in CUHK with IQ200
 * @author McCheng
 */

#include <bits/stdc++.h>
#define int long long
using namespace std;
#undef int
class ERedScarf {
public:
    static constexpr int kStressCount = 0;
    static void generateTest(ostream& test) {}
	void solve(istream& cin, ostream& cout) {
int n;
cin>>n;
        vector<int> a(n);
        for (int i = 0; i < n; i++) {
            cin>>a[i];
        }
        int tmp=0;
        for (int i = 0; i < n; i++) {
            tmp=tmp^a[i];
        }
        for (int i = 0; i <n; i++) {
            int ans = tmp^a[i];
            cout<<ans<<" ";
        }
	}
};

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream &in(cin);
    ostream &out(cout);
    out << fixed;
    out.precision(20);
    ERedScarf solver;
    solver.solve(in, out);
}


Measured memory_bytes: 3888
n,l = map(int,input().split())

b = [i for i in range(l,n+l)]
# print(b)
m = 1000
t = 1
for i in b:
    if m > abs(i):
        m = abs(i)
        if i<0:
            t = -1
        else:
            t = 1
print(sum(b)-m*t)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
typedef long long ll;
typedef pair<ll,ll> PP;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false

signed main(void){
    int A,B,C,K;
    cin >> A >>B >> C >> K;
    int Ans=0;
    if(K>=A){
        Ans+=A;
        K-=A;
    }else{
        Ans+=K;
        K=0;
    }
    
    if(K>=B){
        K-=B;
    }else{
        K=0;
    }
    
    if(K>=C){
        Ans-=C;
        K-=C;
    }else{
        Ans-=K;
        K=0;
    }
    
    cout << Ans << endl;
    return 0;
}




Measured memory_bytes: 3636
#include <stdio.h>
int main(void)
{
	int n,m[10],l,s;
	for(n=0;n<10;n++)
	{
		scanf("%d",&m[n]);
	}
	for(n=0;n<10;n++)
	{
		for(l=n+1;l<10;l++)
		{
			if(m[n]<m[l])
			{
				s=m[n];
				m[n]=m[l];
				m[l]=s;
			}
		}
	}
	printf("%d\n%d\n%d\n",m[0],m[1],m[2]);
	return 0;
}

Measured memory_bytes: 2604
def main():

    H, W, A, B = map(int, input().split())
    mod = pow(10, 9) + 7

    v = 1
    fs = [v]
    for i in range(1, H+W-1):
        v = (v * i) % mod
        fs.append(v)

    v = invfactorial(H+W-2, mod)
    invfs = [v]
    for i in range(H+W-2, 0, -1):
        v = (v * i) % mod
        invfs.append(v)
    invfs = invfs[::-1]

    tot = (fs[H+W-2] * invfs[H-1] * invfs[W-1] ) % mod
    subtract = 0
    for b in range(B):
        v1 = (fs[H-1-A+b]*invfs[b]*invfs[H-1-A]) % mod
        v2 = (fs[A-1+W-1-b] * invfs[A-1] * invfs[W-1-b]) % mod
        subtract += v1 * v2
        subtract %= mod
    # print(tot, subtract)
    return (tot - subtract) % mod


def powquick(x, y, mod):
    if y == 0: return 1
    elif y == 1: return x % mod
    elif y % 2 == 0: return pow(powquick(x, y // 2, mod) , 2) % mod
    elif y % 2 == 1: return (x * pow(powquick(x, y // 2, mod), 2)) % mod

def invfactorial(x, mod):
    v = 1
    for i in range(1, x+1):
        v = (v * i) % mod
    return powquick(v, mod-2, mod)



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

Measured memory_bytes: 65008
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/abc068/tasks/arc079_b
# 重要な考察
# すべての要素が等しい数列に関しては,N回操作を行うと必ずすべての要素が-1される

# K//N回 操作したことにして
# のこりのK%N回は愚直に操作したことにする

K = read_a_int()
N = 50

kn = K // N
A = [N - 1 + kn] * N

rest = K % N
# 愚直に残りの回数シミュレーション
for i in range(rest):
    mi = min(A)
    idx = A.index(mi)
    for j in range(N):
        if idx == j:
            A[j] += N
        else:
            A[j] -= 1

print(N)
print(*A)


Measured memory_bytes: 9508
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";

int main(){
  string s; cin >> s;
  if(s.size()==1){
    cout << s;
    return 0;
  }
  ll ans = 0;
  for(ll i=0; i < (ll)(1<<s.size()-1);i++){
    ll prev=0;
    ll c=1;
    rep(j,s.size()){
      if(j==s.size()-1){
        ans+=stoll(s.substr(prev));
        continue;
      }
      if(i & (1<<j)){
        ans+=stoll(s.substr(prev,c));
        prev+=c;
        c=1;
      }else{
        c++;
      }
    }
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main()
{
    int N,X;
    cin >> N >> X;
    int m[100] = {};
    int moto = 0;
    
    for(int i=0;i<N;i++){
        cin >> m[i];
        moto = moto+m[i];
    }
    
    sort(m,m+N);
    
    cout << N+((X-moto)/m[0]) << endl;
    
        return 0;
}


Measured memory_bytes: 256
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N = int(input())
A = [0] + list(map(int,input().split())) + [0]
 
total = 0
for i in range(N+1):
    total += abs(A[i+1]-A[i])
 
for i in range(N):
    print(total - abs(A[i+1]-A[i]) - abs(A[i+2]-A[i+1]) + abs(A[i+2]-A[i]))

Measured memory_bytes: 13924
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);++i)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
  
const int MOD=1e9+7;
const ll INF=1e18;
const ll inf=1e9;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
 
const int MAX=510000;

 
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
   
  ll k,a,b;
  cin >> k >> a >> b;
  ll now = 1;
  if(b<=a+2 || k<a-1)now+=k;
  else{
    now = a;
    k -= a-1;
    now += (b-a)*(k/2);
    now += k%2;
  }
  cout << now << endl;
  return 0;
}


Measured memory_bytes: 3612
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

	void run() {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] a = new int[n];
		float sum = 0;
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			sum += (float) a[i];
		}

		BigDecimal bd = new BigDecimal((float) sum / n);
		int ave = bd.ROUND_HALF_UP;

		System.out.println(sum);
		System.out.println(ave);

		int ans = 0;
		for (int i = 0; i < n; i++) {
			int tmp = ave - a[i];
			ans += tmp * tmp;
		}
		System.out.println(ans);

	}

	void run1() {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		int min = Integer.MAX_VALUE / 2;
		for (int i = -100; i <= 100; i++) {
			int sum = 0;
			for (int j = 0; j < n; j++) {
				int tmp = i - a[j];
				sum += tmp * tmp;
			}
			min = Math.min(min, sum);
		}
		System.out.println(min);
	}

	public static void main(String[] args) {
		new Main().run1();
	}

}


Measured memory_bytes: 9556
#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>

using namespace std;

const double EPS=(1e-10);
typedef long long ll;
typedef pair<int,int> pii;
bool EQ(double a,double b){
  return abs((a)-(b))<EPS;
}
void fast_stream(){
	std::ios_base::sync_with_stdio(0);
}

int N;
int A[3001];
int B[3001];
int T;
int S;

int dp[3001][3001];

int calc(){
    for(int pos=N;pos>=0;pos--){
        for(int tm=T;tm>=0;tm--){
            int res=0;
            if(pos==N||tm==T)res=0;
            else{
                // テつ催つ。テつ嘉δアテつづδ古つ要テつ素テつづδーテつ偲δヲテつづδゥテつづつゥテつ偲δヲテつづδァテつづδ暗つづつ「テつづつゥテつづδつ湘δェテつ催つつづδュテつづつッ
                // テつ偲つ榲つ甘δ氾つづδーテつ進テつづδ淌つづδゥ
                res=max(res,dp[pos][tm+1]);
                // テつ要テつ素テつづδーテつステつキテつッテつプ
                res=max(res,dp[pos+1][tm]);
                // テつ要テつ素テつづδーテつ偲δヲテつづδゥ
                if((tm+B[pos]<=S||tm>=S)&&tm+B[pos]<=T)res=max(res,dp[pos+1][tm+B[pos]]+A[pos]);
            }
            dp[pos][tm]=res;
        }
    }
    return dp[0][0];
}

void solve(){
    cin>>N>>T>>S;
    for(int i=0;i<N;i++){
        cin>>A[i]>>B[i];
    }
    cout<<calc()<<endl;
}
int main(){

    solve();

    return 0;
}

Measured memory_bytes: 0
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, VecDeque};

fn main() {
    input!(n: usize, ps: [i64; n]);

    let mut cnt = 0;
    for i in 0..n - 2 {
        if ps[i] < ps[i + 1] && ps[i + 1] < ps[i + 2] {
            cnt += 1;
        } else if ps[i + 2] < ps[i + 1] && ps[i + 1] < ps[i] {
            cnt += 1;
        }
    }
    println!("{}", cnt);
}


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

using namespace std;

const long long MOD = 1000000007;

int GCD(int a, int b){return b == 0 ? a : GCD(b, a % b);}

vector<pair<int, pair<int, int>>> edges;

vector<pair<int, int>> hor, ver;

int dsu[100002], ranks[100002];

int FIND(int node){
    if(node == dsu[node])
        return node;
    return dsu[node] = FIND(dsu[node]);
}

void UNION(int a, int b){
    a = FIND(a); b = FIND(b);
    if(a == b) return;
    if(ranks[a] < ranks[b]){
        dsu[a] = b;
    } else if(ranks[b] < ranks[a]){
        dsu[b] = a;
    } else {
        dsu[a] = b;
        ++ranks[b];
    }
}


int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

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

    int n;
    cin >> n;

    for(int i = 0; i < n; ++i){
        int x, y;
        cin >> x >> y;
        hor.push_back(make_pair(x, i));
        ver.push_back(make_pair(y, i));
        dsu[i] = i;
    }

    sort(hor.begin(), hor.end());
    sort(ver.begin(), ver.end());

    pair<int, int> prev = make_pair(-1, -1);
    for(pair<int, int> cur : hor){
        if(prev.first != -1){
            edges.push_back(make_pair(abs(prev.first - cur.first), make_pair(prev.second, cur.second)));
        }
        prev = cur;
    }

    prev = make_pair(-1, -1);
    for(pair<int, int> cur : ver){
        if(prev.first != -1){
            edges.push_back(make_pair(abs(prev.first - cur.first), make_pair(prev.second, cur.second)));
        }
        prev = cur;
    }

    sort(edges.begin(), edges.end());

    long long cost = 0, nodes = 1;

    for(auto i : edges){
        if(FIND(i.second.first) == FIND(i.second.second))
            continue;
        ++nodes;
        cost += i.first;
        if(nodes == n)
            break;
        UNION(i.second.first, i.second.second);
    }

    cout << cost;

    return 0;
}


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

int main() {
  int a,b;
  string op;
  cin >> a >> op >> b; 

  // ここにプログラムを追記
  if (op == "+"){
    cout << a + b << endl;
  }
  else if (op == "-"){
    cout << a - b << endl;
  }
}

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

const int N = 1e5;

map <int, int> dic;
int tot = 0;

int main() {
	//freopen("F:\\rush.txt", "r", stdin);
	ios::sync_with_stdio(0);
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		dic[x] = 1- dic[x];
		if (dic[x] & 1)
			tot++;
		else
			tot--;
	}
	cout << tot << endl;
	return 0;
}

Measured memory_bytes: 4992
n = int(input())
s = input()
t = input()
k = n
for i in range(n):
  if t == s:
    print(2*n-k)
    exit()
  else:
    t = list(t)
    s = list(s)
    t.pop()
    s.pop(0)
    str(s)
    str(t)
    k -= 1
print(2*n)
    

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<vector>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<climits>
#include<algorithm>
#include<functional>
#include<iomanip>
#define LL long long
using namespace std;

int n,m,cnt,book[110][110],dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
char a[110][110];

bool judge(int x,int y,char c){
    if(x>=0 && x<n && y>=0 && y<m && !book[x][y] && a[x][y]==c){
        return true;
    }
    return false;
}

void dfs(int x,int y){
    book[x][y]=1;
    int i;
    for(i=0;i<4;i++){
        int dx=x+dir[i][0];
        int dy=y+dir[i][1];
        if(judge(dx,dy,a[x][y])) dfs(dx,dy);
    }
}

int main(void){
    while(scanf("%d %d",&n,&m)!=EOF && (n || m)){
        int i,j;
        for(i=0;i<n;i++){
            scanf("%s",a[i]);
        }
        memset(book,0,sizeof(book));
        cnt=0;
        for(i=0;i<n;i++){
            for(j=0;j<m;j++){
                if(!book[i][j]){
                    cnt++;
                    dfs(i,j);
                }
            }
        }
        printf("%d\n",cnt);
    }
    return 0;
}




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

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

    if(n % 2){
        cout << 0 << endl;
    }else{
        long long int res = 0;
        n /= 2;
        n /= 5;
        while(n){
            res += n;
            n /= 5;
        }
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define forn(i,a,b) for(int i=a; i<=b; i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
void min_self(ll &a, ll b){
	a=min(a,b);
}
const ll INF = 1e18L + 5;
int main(){
	int n,w;
	cin>>n>>w;
	vector<int> weight(n),value(n);
	forn(i,0,n-1) cin>>weight[i]>>value[i];
	int sum=0;
	for(int x:value) sum+=x;
	vector<ll> dp(sum+1,INF);
	dp[0]=0;
	forn(item,0,n-1){
		for(int value_already = sum-value[item]; value_already>=0; --value_already){
			min_self(dp[value_already+value[item]],dp[value_already]+weight[item]);
		}
	}
	ll answer=0;
	forn(i,0,sum){
		if(dp[i]<=w) answer=max(answer,(ll) i);
	}
	cout<<answer<<"\n";
}

Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")  
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long 
#define endl "\n"
#define all(x) (x).begin(),(x).end()
const int MOD = 1e9+7;
const int mxN = 2e5+3;

int powmod(int x, int y){
	int res = 1;
	while(y > 0){
		if(y & 1) res = (res * x) % MOD;
		y /= 2;
		x = (x * x) % MOD;
	}
	return res % MOD;
}

void solve(){
	int n;
	cin >> n;
	int t1 = powmod(10,n);
	int t2 = powmod(9,n);
	int t3 = powmod(8,n);
	t2 = (2 * t2) % MOD;
	int ans = t1 + t3 - t2;
	ans = (ans + MOD) % MOD;
	cout << ans << endl;
}

int32_t main(){
	IO;
	
	int nT = 1;
	//cin >> nT;
	for(int i = 1; i <= nT; ++i)
		solve();
	return 0;
}


Measured memory_bytes: 3644
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<string>
#include<vector>
#include<functional>

using namespace std;

const double EPS=1e-12;
const double INF=1e12;

typedef complex<double>Point;

namespace std{
    bool operator<(const Point &P,const Point &Q){
        return real(P)!=real(Q)?real(P)<real(Q):imag(P)<imag(Q);
    }
}

double dot(const Point &P,const Point &Q){
    return real(P)*real(Q)+imag(P)*imag(Q);
}

double cross(const Point &P,const Point &Q){
    return real(P)*imag(Q)-real(Q)*imag(P);
}

struct Line{
    Point a,b;
    Line(Point P,Point Q){
        a=P;b=Q;
    }
    Line(){}
};

struct Segment{
    Point a,b;
    Segment(Point P,Point Q){
        a=P;b=Q;
    }
    Segment(){}
};

struct Circle{
    Point c;
    double r;
    Circle(Point P,double l){
        c=P;r=l;
    }
};

typedef vector<Point>Polygon;

int ccw(Point A,Point B,Point C){
    B-=A;C-=A;
    if(cross(B,C)>0)return 1; //ccw
    if(cross(B,C)<0)return -1; //cw
    if(dot(B,C)<0)return 2; //c-b-a
    if(norm(B)<norm(C))return -2; //a-b-c
    return 0; //a-c-b
}
inline bool Parallelism(const Line &L,const Line &M){
    return fabs(cross(L.a-L.b,M.a-M.b))<EPS;
}

inline bool Orthogonal(const Line &L,const Line &M){
    return fabs(dot(L.a-L.b,M.a-M.b))<EPS;
}

inline bool intersect(const Line &L,const Line &M){
    return cross(L.a-L.b,M.a-M.b)>EPS ||cross(L.a-L.b,M.a-M.b)<-EPS;
}

inline bool intersect(const Line &L,const Segment &S){
    return cross(L.b-L.a,S.a-L.a)*cross(L.b-L.a,S.b-L.a)<-EPS;
}

inline bool intersect(const Line &L,const Point &P){
    return abs(ccw(L.a,L.b,P))!=1;
}

inline bool intersect(const Segment &S, const Segment &T){
    return ccw(S.a,S.b,T.a)*ccw(S.a,S.b,T.b)<=0&&
        ccw(T.a,T.b,S.a)*ccw(T.a,T.b,S.b) <= 0;
}

inline bool intersect(const Segment &S,const Point &P){
    return ccw(S.a,S.b,P)==0;
}

inline bool intersect(const Circle &C,const Point &P){
    return abs(C.c-P)<=C.r+EPS;
}

inline bool intersect(const Circle &C,const Circle &D){
    return abs(C.c-D.c)<=C.r+D.r&&abs(C.c-D.c)>=fabs(C.r-D.r);
}

inline Point crossPoint(const Line &L,const Line &M){

}
double areaTriangle(Point A,Point B,Point C){
    B-=A;C-=A;
    return fabs(cross(B,C))*0.5;
}

double areaPolygon(Polygon &g){
    const int Sz=g.size();
    if(Sz<3)return 0;
    if(Sz==3)return areaTriangle(g[0],g[1],g[2]);

    double res=cross(g[Sz-1],g[0]);
    for(int i=1;i<Sz;i++)res+=cross(g[i-1],g[i]);

    return fabs(res)*0.5;
}



int main(){
    Polygon g;
    double x,y;
    while(scanf("%lf,%lf",&x,&y)!=EOF){
        g.push_back(Point(x,y));
    }
    printf("%f\n",areaPolygon(g));
    return 0;
}

Measured memory_bytes: 1236
#include <iostream>
using namespace std;
int main(void){
    long long n, m, ans = 0;
    cin >> n >> m;
    if(n == 1 && m == 1) ans = 1;
    else if(n == 1) ans = m - 2;
    else if(m == 1) ans = n - 2;
    else ans = n * m - n*2 - m*2 + 4;
    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
A = [0] + list(map(int,read().split()))

for n in range(N//2,0,-1):
    A[n] = sum(A[n::n])&1

I = [i for i, x in enumerate(A) if x]

print(len(I))
if len(I) > 0:
    print(' '.join(map(str,I)))

Measured memory_bytes: 18428
## coding: UTF-8
from itertools import product
import copy

H,W,K = map(int,input().split())

#sheet = [ [1] * W for _ in range(H)]
sheet = []
for i in range(H):
    s = input()
    ret = []
    for j in range(W):
        if(s[j] == '#'):
            ret.append(1)
        else:
            ret.append(0)
    sheet.append(ret)

#print(sheet)

pattern = list(product('YN', repeat = H+W))
#print(pattern)


ans = 0
for _ in range(len(pattern)):
    #town = []
    #for i in range(H):
        #town.append(sheet[i])
    town = copy.deepcopy(sheet)
    #print(town, sheet)
    now = pattern[_]
    #print(now)
    for i in range(H):
        #yoko
        if(now[i] == 'Y'):
            town[i] = [0] * W
    #print(town)
    for i in range(H, H+W):
        #tate
        if(now[i] == 'Y'):
            for j in range(H):
                town[j][i-H] = 0
    #print(town)
    #print('~~~~~~~~~~~~~')
    su = 0
    for i in range(H):
        su += sum(town[i])
    if(su == K):
        ans += 1

    
print(ans)



Measured memory_bytes: 74060
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t a, b, x;
  cin >> a >> b >> x;
  if (x == 1) {
    cout << b - (a - 1) << endl;
  } else {
    int64_t bb = static_cast<int64_t>(b / x);
    int64_t aa = max(static_cast<int64_t>((a - 1) / x), 0L);
    int64_t result = bb - aa;
    if (a == 0) {
      ++result;
    }
    cout << result << endl;
  }
  return 0;
}


Measured memory_bytes: 3620