akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

#define M 100000

void sieve(int pn[M]) {
  int i = 0;
  int j = 0;
  for(i = 2; i <= M; i++) {
    for(j = i+i; j <= M; j+=i) {
      pn[j] = 0;
    }
  }
}

void five_sieve(int pn[M]) {
  int i;
  for(i = 0; i < M; i++) {
    if(pn[i]%5 != 1) {
      pn[i] = 0;
    }
  }
}

int main(void) {
  int i, j;
  int N, pn[M+1];
  scanf("%d", &N);
  for(i = 0; i <= M; i++) {
    pn[i] = i;
  }
  sieve(pn);
  five_sieve(pn);
  j = 0;
  for(i = 0; i < N; i++) {
    while(1) {
      j++;
      if(pn[j] != 0 && pn[j] != 1) {
        printf("%d ", pn[j]);
        break;
      }
    }
  }
  printf("\n");
}

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


def main():
    s = list(input())
    n = len(s) + 1
    ans = [0 for _ in range(n)]

    # See:
    # https://www.youtube.com/watch?v=qIzuNgDV6O8
    # KeyInsight:
    # 不等号を一つずつ扱い，全探索で処理
    # <: a[i + 1] = max(a[i + 1], a[i] + 1)
    # >: a[i - 1] = max(a[i - 1], a[i] + 1)

    # 考察できた部分
    # 0で初期化
    # 愚直にサンプルからシミュレーション

    # 考察できなかった部分
    # 各項の値をどうプログラムで求めるか

    # ギャップ
    # 符号をまとめて処理しようとした
    # 途中で，符号の組み合わせによって，カウントを調整必要があることに気がついたが，法則性が分からず
    for i in range(n - 1):
        if s[i] == '<':
            ans[i + 1] = max(ans[i + 1], ans[i] + 1)

    for i in range(n - 2, -1, -1):
        if s[i] == '>':
            ans[i] = max(ans[i], ans[i + 1] + 1)

    print(sum(ans))


if __name__ == '__main__':
    main()


Measured memory_bytes: 27696
#include<bits/stdc++.h>
using namespace std;
#define SZ(v) ((int)(v).size())
#define rep(i,n) for(int i=0;i<(n);i++)
#define foreach(it,c) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)
#define all(v) (v).begin(),(v).end()
typedef long long ll;
typedef unsigned uint;
const int INF=0x3f3f3f3f;
int inline in(){int x=0,c;for(;(uint)((c=getchar())-'0')>=10;)
{if(c=='-')return -in();if(!~c)throw ~0;}do{x=(x<<3)+(x<<1)+(c-'0');}
while((uint)((c=getchar())-'0')<10);return x;}
int n;
vector<int>G[100005];
int dist1[100005],dist2[100005];
void dfs1(int v,int p,int t){
	dist1[v]=t;
	rep(i,SZ(G[v])){
		int to=G[v][i];
		if(to!=p){
			dfs1(to,v,t+1);
		}
	}
}
void dfs2(int v,int p,int t){
	dist2[v]=t;
	rep(i,SZ(G[v])){
		int to=G[v][i];
		if(to!=p){
			dfs2(to,v,t+1);
		}
	}
}
int main(){
    cin.sync_with_stdio(false);cin.tie(0);
	cin>>n;
	rep(i,n-1){
		int u,v;
		cin>>u>>v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs1(1,-1,0);
	dfs2(n,-1,0);
//	for(int i=1;i<=n;i++){
//		cout<<dist1[i]<<' ';
//	}
//	cout<<endl;
//	for(int i=1;i<=n;i++){
//		cout<<dist2[i]<<' ';
//	}
//	cout<<endl;
	int cnt1=0,cnt2=0;
	for(int i=1;i<=n;i++){
		if(dist1[i]<=dist2[i])cnt1++;
		else cnt2++;
	}
	if(cnt1>cnt2)cout<<"Fennec"<<endl;
	else cout<<"Snuke"<<endl;
	return 0;
}

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

int main() {
    int n;
    long long  ans=0;
    cin >> n;
    vector<long long> a(n+1), s(n+1), dp(n+1);
    for(int i=0; i<n+1; i++) cin >> a[i];
    for(int i=n; i>=0; i--){
        if(i==n) s[i]=a[i];
        else {
            s[i]=s[i+1]+a[i];
        }
    }
    bool flag=true;
    if(n==0 && a[0]==1) ans=1;
    else if(a[0]!=0) flag=false;
    else {
        for(int i=0; i<n+1; i++){
            if(i==0){
                dp[i]=1;
                ans+=dp[i];
            }
            else if(i!=n){
                if(2*dp[i-1]-a[i]<=0){
                    flag=false;
                    break;
                }
                dp[i]=min(2*dp[i-1]-a[i], s[i+1]);
                ans+=(dp[i]+a[i]);
            }
            else{
                if(a[n]<dp[i-1] || 2*dp[i-1]<a[n]) flag=false;
                else{
                    dp[i]=a[i];
                    ans+=dp[i];
                }
            }
        }
    }
    if(flag) cout << ans;
    else cout << -1;
}

Measured memory_bytes: 5556
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define MOD 1000000007
#define EPS 10e-8
const int INF=1e9;
int gcd(int a,int b){return b?gcd(b,a%b):a;}    //最大公約数
int lcm(int a, int b) {return a * b / gcd(a, b);}   //最小公倍数

int main(){
    int n;
    cin >> n;
    int s[n];
    rep(i, n)
        cin>>s[i];
    int m;
    cin >> m;
    int t[n];
    rep(i, m)
        cin>>t[i];
    int c = 0;
    rep(i, m)
    {
        rep(j,n){
            if(t[i]==s[j]){
                c++;
                break;
            }
        }
    }
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 3132
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <string>
#include <map>
#include <iterator>


using namespace std;

long gcd(long a, long b) {
    if (a == 0)
        return b;
    if (b == 0)
        return a;


    if (a == b)
        return a;

    if (a > b)
        return gcd(a - b, b);
    return gcd(a, b - a);
}

int main() {

    int K;
    cin >> K;
    long sum = 0;
    for (int a = 1; a <= K; ++a) {
        for (int b = 1; b <= K; ++b) {
            for (int c = 1; c <= K; ++c) {
                sum += gcd(gcd(a, b), c);
            }
        }
    }

    cout << sum << endl;


    return 0;

}

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

int main(){
	int h,w,n ;
	cin >> h >> w >> n ;
	if(n==0){
	    cout << h << endl ;
	    return 0 ;
	}
	vector<pair<int,int>> a ;
	for(int i=0;i<n;i++){
		int x,y ;
		cin >> x >> y ;
		if(x<y) continue ;
		a.push_back(make_pair(x,y)) ;
	}
	if(a.size()==0){
	    cout << h << endl ;
	    return 0 ;
	}
	sort(a.begin(),a.end()) ;
	int ans = 0 ;
	int pos = 0 ;
	int j = 1 ;
	for(int i=1;i<h+10;i++){
	    if(i==h) break ;
	    bool ok = false ;
	    bool right = true ;
	    while(pos!=a.size()&&a.at(pos).first==i+1){
	        if(a.at(pos).second<=j&&ok==false) ok = true ;
	        if(a.at(pos).second==j+1) right = false ;
	        pos++ ;
	        if(pos==a.size()) break ;
	    }
	    if(ok) break ;
	    if(right) j++ ;
	    ans++ ;
	}
	cout << ans+1 << endl ;
}


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

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T>
vector<vector<T> > make_v(size_t a,size_t b){
  return vector<vector<T> >(a,make_v<T>(b));
}
template<typename T>
vector<vector<vector<T> > > make_v(size_t a,size_t b,size_t c){
  return vector<vector<vector<T> > > (a,make_v<T>(b,c));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//INSERT ABOVE HERE
signed main(){
  Int w,h;
  cin>>w>>h;

  auto s=make_v<Int>(h+2,w+2);
  fill_v(s,0);
  for(Int i=1;i<=h;i++)
    for(Int j=1;j<=w;j++)
      cin>>s[i][j];
  
  auto used=make_v<Int>(h+2,w+2);
  fill_v(used,0);

  using P = pair<Int, Int>;
  queue<P> q;
  
  used[0][0]=1;
  q.emplace(0,0);

  Int dy[]={-1,-1,0,1,1,0};
  Int dx[]={0,1,1,1,0,-1};
  Int dx2[]={-1,0,1,0,-1,-1};

  auto in=[&](Int y,Int x){return 0<=y&&y<h+2&&0<=x&&x<w+2;};
  
  while(!q.empty()){
    Int y,x;
    tie(y,x)=q.front();q.pop();
    //if(x&&y) cout<<x<<" "<<y<<endl;
    for(Int k=0;k<6;k++){
      Int ny=y+dy[k],nx=x+(y&1?dx[k]:dx2[k]);
      if(!in(ny,nx)||s[ny][nx]||used[ny][nx]) continue;
      used[ny][nx]=1;
      q.emplace(ny,nx);
    }
  }

  Int ans=0;
  for(Int i=1;i<=h;i++){
    for(Int j=1;j<=w;j++){
      if(!s[i][j]) continue;
      for(Int k=0;k<6;k++){
	Int ny=i+dy[k],nx=j+(i&1?dx[k]:dx2[k]);
	if(!in(ny,nx)||s[ny][nx]) continue;
	ans+=used[ny][nx];
      }
    }
  }

  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3248
#include <bits/stdc++.h>
#include <vector>
#include <cstdlib> //abs(int)
using namespace std;
int main(void){
  int a, b, c;
  cin >> a >> b >> c;
  int A, B, C;
  A = abs(a - b);
  B = abs(b - c);
  C = abs(c - a);
  cout << A + B + C - max(max(A,B),C);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define MAX(a,b) a=a>b?a:b
#define MIN(a,b) a=a<b?a:b
#define REP(i,x,n) for(int i=x;i<n;i++)
#define REPR(i,x,n) for(int i=n-1;i>=x;i--)
#define pb  push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLr(obj) (obj).rbegin(), (obj).rend()
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const double PI=3.14159265358979323846;



int main(){
   ll n,cnt=0;;
   string s;
   int a,b,c;
   cin>>a>>b>>c>>n;
   rep(i,n){
       if(a>=b)b*=2;
       else if(b>=c)c*=2;
   }
   if(a<b&&b<c)cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
   
   
}


Measured memory_bytes: 3620
S = input()

if int(S[0:2]) > 12 or S[0:2] == "00":
    if 0 < int(S[2:4]) <= 12:
        print("YYMM")
    else:
        print("NA")
else:
    if 0 < int(S[2:4]) <= 12:
        print("AMBIGUOUS")
    else:
        print("MMYY")

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

#define f first
#define s second
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int N = (int)2e5 + 123, inf = 1e9, mod = 1e9 + 7;
const ll INF = 1e18;

int main()
{
	int x, y;
	cin >> x >> y;
	if(x == 0){
		if(y > 0)
			cout << y;
		else
			cout << 1 - y;
		return 0;
	}
	if(y == 0){
		if(x < 0)
			cout << -x;
		else
			cout << 1 + x;
		return 0;
	}
	if(x > 0 && y > 0){
		if(x < y)
			cout << y - x;
		else
			cout << x - y + 2;
	}
    if(x <= 0 && y <= 0){
		if(x < y)
			cout << y - x;
		else
			cout << x - y + 2;
	}
    if(x > 0 && y <= 0){
    	if(-x <= y)
    		cout << 1 + y + x;
		else
			cout << 1 - y - x;
	}
    if(x <= 0 && y > 0){
		if(-x <= y)
    		cout << 1 + y + x;
		else
			cout << 1 - y - x;
	}
	return 0;
}


Measured memory_bytes: 256
import Control.Monad
import Control.Applicative
import Data.Array

eps :: Double
eps = 1.0e-8

data Point = Point (Double, Double) deriving (Show)

add :: Point -> Point -> Point
add (Point (x1, y1)) (Point (x2, y2)) = Point (x1 + x2, y1 + y2)

sub :: Point -> Point -> Point
sub (Point (x1, y1)) (Point (x2, y2)) = Point (x1 - x2, y1 - y2)

mul :: Point -> Double -> Point
mul (Point (x, y)) s = Point (x * s, y * s)

nrm :: Point -> Point
nrm (Point (x, y)) = Point (x / n, y / n) where n = sqrt $ (x * x + y * y)

dst :: Point -> Double
dst  (Point (x, y)) = sqrt $ (x * x + y * y)

dst2 :: Point -> Double
dst2 (Point (x, y)) = x * x + y * y

getX :: Point -> Double
getX (Point (x, _)) = x

getY :: Point -> Double
getY (Point (_, y)) = y

parsePoint :: String -> Point
parsePoint str =
    let [x, y] = map read $ words str
    in Point (x, y)

calcCenter :: Point -> Point -> (Point, Point)
calcCenter a b =
    let m = (a `add` b) `mul` 0.5
        d = sqrt (1.0 - ((dst $ a `sub` m) ** 2.0))
        e = a `sub` b
        n = nrm $ Point (negate $ getY e, getX e)
        c1 = m `add` (n `mul` d)
        c2 = m `sub` (n `mul` d)
    in (c1, c2)

solve' :: [Point] -> Int
solve' pts =
    let np    = length pts
        parr  = listArray (0, np-1) pts
        pairs = [ (parr ! i, parr ! j) | i <- [0..np-1], j <- [i+1..np-1] ]
    in if null pairs
        then 1
        else maximum $ map countUp pairs where
            countUp (p, q) =
                if (dst2 $ p `sub` q) >= 4.0 - eps
                    then 1
                    else
                        let (c1, c2) = calcCenter p q
                            m1 = length $ filter (\p -> (dst2 $ p `sub` c1) <= 1.0 + eps) pts
                            m2 = length $ filter (\p -> (dst2 $ p `sub` c2) <= 1.0 + eps) pts
                        in (max m1 m2)

solve :: [String] -> [Int]
solve []   = []
solve cont =
    let n           = read (head cont) :: Int
        (crds, rst) = splitAt n (tail cont)
        pts         = map parsePoint crds
    in if n == 0 then []
                 else (solve' pts) : solve rst

main :: IO ()
main = do
    contents <- getContents
    mapM_ print $ solve $ lines contents

Measured memory_bytes: 30056
def cross(a,b):return a[0]*b[1] - a[1]*b[0]
def dif(a,b):return [x-y for x,y in zip(a,b)]

x = range(int(input()))
t = 1
P,Q = [],[]
for _ in x:P+=[[int(i) for i in input().split()]]
for i in x:Q+=[dif(P[i],P[i-1])]
for i in x:
    if cross(Q[i-1],Q[i]) < 0: t *= False
print(t)

Measured memory_bytes: 7740
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    let answer = 0;

    for(let i=1; i<N; i++) {
        if(N % i === 0) {
            answer += (N / i) - 1;
        } else {
            answer += Math.floor(N / i);
        }
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 33320
using System;

class Program {
  static void Main(string[] args) {
    int judge = 0;
    int c;

    while((c = Console.Read() - 'a') >= 0 && c < 26) {
      judge ^= (1 << c);
    }

    if(judge == 0) Console.WriteLine("Yes");
    else Console.WriteLine("No");
  }
}


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


using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const int  INF = 1 << 29;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;



int main() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << c << ' ' << a << ' ' << b << endl;

}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

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

	ll sum = 0;
	map<ll, ll> m;
	for (ll ii = 0; ii < N; ++ii){
		ll a;
		cin >> a;
		m[a]++;
		sum += a;
	}

	ll Q;
	cin >> Q;
	for (ll ii = 0; ii < Q; ++ii){
		ll B, C;
		cin >> B >> C;
		if (m[B] > 0){
			ll hiku = B * m[B];
			ll tasu = C * m[B];
			sum = sum + tasu - hiku;
			m[C] += m[B];
			m[B] = 0;
		}
		cout << sum << "\n";
	}


	return 0;
}


Measured memory_bytes: 9344
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] S = sc.nextLine().toCharArray();
		
		for (int i = 1; i < S.length; i++) {
			for (int j = i; j < S.length; j++) {
				if(S[i-1] == S[j]) {
					System.out.println("no");
					return;
				}
			}
		}
		
		System.out.println("yes");
		
	}
}





Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S,T;
  cin >> S >> T;
  for (int i = S.length()-T.length(); i+1; i--) {
    bool valid = true;
    for (int j = 0; j < T.length() && valid; j++) {
      if (S[i+j] != T[j] && S[i+j] != '?') {
        valid = false;
      }
    }
    if (valid) {
      for (int j = 0; j < T.length(); j++) {
        S[i+j] = T[j];
      }
      for (int j = 0; j < S.length(); j++) {
        if (S[j] == '?') {
          S[j] = 'a';
        }
      }
      cout << S;
      return 0;
    }
  }
  cout << "UNRESTORABLE";
}

Measured memory_bytes: 3576
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int m = sc.nextInt();
      PriorityQueue pq = new PriorityQueue();
      for(int i = 0;i < n;i++){
        pq.add(-sc.nextInt());
      }
      while(m>0){
      	int k = (int)pq.poll();
        pq.add(k/2);
        m--;
      }
      long sum = 0;
      Iterator<Integer> iterator = pq.iterator();
      while(iterator.hasNext()){
      	sum+=(long)iterator.next();
      }
      System.out.println(-sum);
    }
}


Measured memory_bytes: 62900
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  int N;
  cin >> N;
  vector<int> a;
  for (int i = 0; i < N; i++) {
    int v; cin >> v; a.push_back(v);
  }
  sort(a.begin(), a.end());
  bool ok = true;
  if (a[0] < a[1]) {
    int m = a[0];
    int p = 0;
    if (a[1] != m+1) {ok = false;}
    
    for (int i = 1; i < N-1; i++) {
      if (a[i] < a[i+1]) {
        if (i-p < 2 || a[i]+1 != a[i+1]) {ok = false;}
        p = i;
      }
    }
    if (a[N-1] != 2*m || a[N-2] != 2*m) {ok = false;}
  }
  
  if (a[0] == a[1] && N > 2) {
    int m = a[0];
    int p = 1;
    if (a[2] != m+1) {ok = false;}
    for (int i = 2; i < N-1; i++) {
      if (a[i] < a[i+1]) {
        if (i-p < 2 || a[i]+1 != a[i+1]) {ok = false;}
        p = i;
      }
    }
    if (a[N-1] != 2*m-1 || a[N-2] != 2*m-1) {ok = false;}
  }
  
  if (a[0] == a[1] && N == 2) {
    if (a[0] != 1) {ok = false;}
  }
  
  if (ok) {cout << "Possible" << endl;}
  else {cout << "Impossible" << endl;}
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define N 100000
int main()
{
	int i, len;
	char ch, s[N];
	scanf("%s", s);
	len = strlen(s);
	
	for (ch = 'a'; ch <= 'z'; ch++) {
		for (i = 0; i <= len; i++) {
			if (ch == s[i])
				break;
			else if (i == len) {
				printf("%c", ch);
				goto label;
			}	
		}
		if (ch == 'z')
			printf("None");
	}
	
	label : ;
	
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;

//-----------------------------------------------------------------------

const int MAX_N=1<<17;
const int INF=INT_MAX;
int N,dat[2*MAX_N-1];

void init(int n)
{   
    N=1; while(N<n) N*=2;
    REP(i,2*N-1) dat[i]=0;
}

void add(int k,int val)
{
    k+=N-1; dat[k]+=val;
    while(k>0){
        k=(k-1)/2;
        dat[k]=dat[2*k+1]+dat[2*k+2];
    }
}

int getSum(int a,int b,int k,int l,int r)
{
    if(r<=a or b<=l) return 0;
    if(a<=l and r<=b) return dat[k];

    int vl=getSum(a,b,2*k+1,l,(l+r)/2);
    int vr=getSum(a,b,2*k+2,(l+r)/2,r);
    return vl+vr;
}

signed main()
{
    int n,q; cin>>n>>q;
    init(n);
    REP(i,q){
        int com,x,y; cin>>com>>x>>y;
        if(com==0) add(x-1,y);
        else cout<<getSum(x-1,y,0,0,N)<<endl;
    }

}



Measured memory_bytes: 5136
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << '[' << #x << " is: " << x << "] " <<"\n";
#define imod(a , n) (a % n + n ) % n ;
#define int long long
const double eps = 1e-9 , PI = acos(-1) ;
const int N = 100;
int n , w , wt[N] , val[N] ;
vector<vector<int>> dp(101 , vector<int> (1e5 + 1 , -1));
int calc(int idx , int cap){
    if(idx == n || cap == 0)return  0 ;
    if(dp[idx][cap] != -1)return dp[idx][cap];
    int a1 = 0 , a2 = 0 ;
    if(cap >= wt[idx])a1 = val[idx] + calc(idx + 1 , cap - wt[idx]);
    a2 = calc(idx + 1 , cap);
    return dp[idx][cap] = max(a1 , a2);

}
int32_t main(){
    cin >> n >> w ;
    for(int x = 0 ;x < n ;x++){
        cin >> wt[x] >> val[x] ;
    }
    cout << calc(0 , w);





        return 0;
}


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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
ostream &operator<<(ostream &os, pair<ll, ll>&p){
  return os << p.first << " " << p.second;
}  
template<typename T>
void pr(T a){
  cout<<a<<endl;
}
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  //ll a;cin>>a;
  //ll a,b;cin>>a>>b;
  //ll a,b,c;cin>>a>>b>>c;
  //ll a,b,c,d;cin>>a>>b>>c>>d;
  //string s;cin>>s;
  //ll n;cin>>n;string s;cin>>s;
  char c;cin>>c;
  cout<<char(c+1)<<endl;
  return 0;
}

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

int main(){
 int a,c;
  cin>>a;
  vector<int>b(a);
  c=0;
  for(int i=0;i<a;i++){
    cin>>b[i];
    if(i>0){
      if(b[i]>=b[i-1]){
c++;
  }
      b[i]=max(b[i],b[i-1]);
    }
     }

       cout<<c+1<<endl;
}


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

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

const ll mod=1e9+7;
const ll inf=1e15;
const int INF=1e9;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<int> a(n);
	double ave=0;
	rep(i,n){
		cin>>a[i];
		ave+=a[i];
	}
	ave/=(double)n;
	double diff=INF;
	rep(i,n){
		chmin(diff,abs(ave-a[i]));
	}
	rep(i,n){
		if(abs(ave-a[i])==diff){
			cout<<i<<endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
// Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
#include<iomanip>
typedef long long ll;
typedef unsigned long long ul;
#define pi acos(-1)
#define ll long long
#define ull unsigned long long
#define vec vector<ll>
#define f1(i,n) for(i=1;i<n;i++)
int i,j;
using namespace std;
int main()
{
   //freopen("a.txt","r",stdin);
   ll a,b,c,k,x,sum=0;
   cin>>a>>b>>c>>k;
   if(a<=k)
   {
       sum+=a;
      k-=a;
   }
   else
   {
       sum+=k;
       k=0;
   }

   if(k>0)
   {
       k-=b;
   }
   if(k>0)
   {
       sum+=k*(-1);
   }
   cout<<sum<<endl;
}



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

int main(){
    int n; cin >> n;
    vector<int> A(n),B(n);
    for (int i=0; i<n; i++){
        cin >> A[i];
        B[i]=A[i];
    }
    
    sort(A.begin(),A.end(),greater<int>());
    int MAX_1=A[0];
    int MAX_2=A[1];
    for (int i=0; i<n; i++){
        if (B[i]==MAX_1) cout << MAX_2 << endl;
        else cout << MAX_1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3200
import itertools
N, M, Q = map(int,input().split())
ABCD_list = [[int(_) for _ in input().split()] for i in range(Q)]
combs = itertools.combinations_with_replacement(range(1,M+1),N)
points = []
for comb in combs:
    A_list = list(comb)
    point = 0
    for inner in ABCD_list:
        if A_list[inner[1]-1]-A_list[inner[0]-1] == inner[2]:
            point += inner[3]
        points.append(point)
print(max(points))

Measured memory_bytes: 74152
from sys import stdin
import sys
import copy
sys.setrecursionlimit(200000)
N,M,K=list(map(int,input().split()))
counter=[[None,None] for i in range(N+1)]
friend_list=[set() for _ in range(N+1)]
block_list=[set() for _ in range(N+1)]
def friend_tansaku(i,j):
    color.add(j)
    cnt[0]+=1
    for friend in friend_list[j]:
        if friend not in color :
            friend_tansaku(i,friend)





for _ in range(M):
   a,b= list(map(int, input().split()))
   friend_list[a].add(b)
   friend_list[b].add(a)
for _ in range(K):
    a, b = list(map(int, input().split()))
    block_list[a].add(b)
    block_list[b].add(a)
for i in range(1,N+1):
    cnt=[0]
    color =set()
    if counter[i][0] is None:
        friend_tansaku(i,i)
        cnt=cnt[0]
        for aa in color:
            counter[aa]=[color,cnt]
    color,cnt =counter[i][0],counter[i][1]
    for k in block_list[i]:
        if k not in color:
            cnt+=1

    count=cnt-(len(friend_list[i])+len(block_list[i]))-1
    if i==N:print(count)
    else:print(count,end=" ")

Measured memory_bytes: 109812
#include<bits/stdc++.h>
#pragma GCC optimize("O999")
#define long long ll
const int INF = 0x3f3f3f3f;
int maxn=5000005;
using namespace std;
int main()
{
 	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(0);
    int n;
    cin>>n;
    int a[n+1],b[n+1],c[n],ans=0;
    
    for(int i=1;i<=n;i++)
    {
    	cin>>a[i];
	}
	for(int i=1;i<=n;i++)
	{
		cin>>b[i];
	}
	for(int i=1;i<n;i++)
	{
		cin>>c[i];
	}
	ans+=b[1];
	for(int i=2;i<=n;i++)
	{
		ans+=b[i];
		if(a[i]==a[i-1]+1)
		ans+=c[a[i-1]];
		
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class29
    {
        static void Main()
        {
            var NH = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = NH[0], H = NH[1];
            long[] a = new long[N], b = new long[N];

            for(int i = 0; i < N; i++)
            {
                var read = Console.ReadLine().Split().Select(int.Parse).ToArray();
                a[i] = read[0];
                b[i] = read[1];
            }
            Array.Sort(b);
            Array.Reverse(b);
            long am = a.Max();
            long sum = 0;
            int count = 0;
            for(int i = 0; i < N&&sum<H; i++)
            {
                if (b[i] > am)
                {
                    sum += b[i];
                    count++;
                }
                
            }
            if (sum< H)
            {
                 count +=(int)Math.Ceiling((decimal)(H - sum) / am);
            }
                
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 16964
"
キーエンスプログラミングコンテスト2020
B - Robot Arms
https://atcoder.jp/contests/keyence2020/tasks/keyence2020_b
"

# 定数
MINUSINF = -10e9

# 入力
N = gets.to_i
x = []
l = []
N.times do |i|
  x[i], l[i] = gets.split.map(&:to_i)
end

s = [] # 開始座標
t = [] # 終了座標
# ac = [] # s, tのペア
#開始座標と終了座標をメンバ変数として持つ構造体を宣言
Robo = Struct.new(:s, :t)
robos = [] #Robo構造体の配列
N.times do |i|
  robos[i] = Robo.new(x[i]-l[i], x[i]+l[i])
end

# 終了座標で配列robosを昇順ソート
robos = robos.sort{
  |r1, r2| r1.t <=> r2.t
}

# このソートが多分遅い
# N.times do |i|
#   (i+1).upto(N-1) do |j|
#     if ac[i].last > ac[j].last
#       ac[i], ac[j] = ac[j], ac[i]
#     end
#   end
# end

# greedy
n = MINUSINF
ans = 0
N.times do |i|
  # 開始時間がn以上で、終了時間の最も早いものを選ぶ
  if robos[i].s >= n
    n = robos[i].t
    ans += 1
  end
end
puts ans

Measured memory_bytes: 9944
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

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

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

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func gcd(a, b int) int {
	for a%b != 0 {
		a, b = b, a%b
	}
	return b
}

// bが非負の既約分数
func cut(a, b int) (int, int) {
	g := gcd(abs(a), abs(b))
	if b < 0 {
		return -a / g, -b / g
	}
	return a / g, b / g
}

func modPow(a, n, mod int) int {
	ret := 1
	for n > 0 {
		if n&1 == 1 {
			ret = (ret * a) % mod
		}
		a = (a * a) % mod
		n >>= 1
	}
	return ret
}

type Pair struct {
	a, b int
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	const mod = 1000000007

	n := nextInt()

	zero := 0
	m := map[Pair]Pair{}
	for i := 0; i < n; i++ {
		a, b := nextInt(), nextInt()
		if a == 0 && b == 0 {
			zero++
			continue
		} else if a == 0 {
			p := m[Pair{0, 1}]
			p.a++
			m[Pair{0, 1}] = p
			continue
		} else if b == 0 {
			p := m[Pair{0, 1}]
			p.b++
			m[Pair{0, 1}] = p
			continue
		}

		a, b = cut(a, b)
		if a < 0 {
			p := m[Pair{b, -a}]
			p.a++
			m[Pair{b, -a}] = p
		} else {
			p := m[Pair{a, b}]
			p.b++
			m[Pair{a, b}] = p
		}
	}

	ans := 1
	for _, p := range m {
		a := (modPow(2, p.a, mod) + modPow(2, p.b, mod) + mod - 1) % mod
		ans = (ans * a) % mod
	}
	ans = (ans + zero - 1 + mod) % mod

	puts(ans)
}


Measured memory_bytes: 24560
import java.util.Scanner;
//import java.io.*;

 class Main {
    public static void main(String[] args){ 
    	Scanner scan = new Scanner(System.in);
    	   	                                                 
    	String str;
    	
    	while(true){
    		str = scan.next();
    		if(str.equals("0")){
    			break;
    		}else{       
    			char[] charA;
    			charA = str.toCharArray();   //char????????????
    			int intt = 0;
    			for(int keta = 0; keta < charA.length; keta++){
    				char charAB = charA[keta];
    				intt += Integer.parseInt(""+charAB);   //int??????
    			}
    			System.out.println(intt);
    		}    			
    	}  	
     }
}

Measured memory_bytes: 26996
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
    int n;
    cin >> n;
    if (n%2 == 1){
        cout << n/2+1 << endl;
    }
    else{
        cout << n/2 << endl;
    }
}

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * c.cc: E: Finite Encyclopedia of Integer Sequences
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 300000;

/* typedef */

/* global variables */

int ds[MAX_N];

/* subroutines */

/* main */

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

  int kh = (k + 1) / 2;

  if (! (k & 1)) {
    printf("%d", kh);
    for (int i = 1; i < n; i++) printf(" %d", k);
  }
  else {
    fill(ds, ds + n, kh);
    int nh = n / 2;
    int li = n - 1;

    while (nh--) {
      if (ds[li] == 1)
	ds[li--] = k;
      else {
	ds[li]--;
	li = n - 1;
      }
    }

    for (int i = 0; i <= li; i++) {
      if (i) putchar(' ');
      printf("%d", ds[i]);
    }
  }
  putchar('\n');
  return 0;
}


Measured memory_bytes: 3456
from math import sqrt

N = int(input())
xy = [list(map(int,input().split())) for _ in range(N)]

result = 0
for i in range(N):
    for j in range(N):
        if i != j :
            result += sqrt((xy[i][0]-xy[j][0])**2+(xy[i][1]-xy[j][1])**2)

print(result/N)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define WATCH(x) cout << (#x) << " is " << (x) << endl

#define PB push_back
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define flash ios_base::sync_with_stdio(false); cin.tie(NULL),cout.tie(NULL);

int main()
{   
    flash

    string s1 , s2;
    cin >> s1 >> s2;
    int ct=0;
    for(int i=0 ; i<3 ; i++) {
        if(s1[i]==s2[i]) ct++;
    }
    cout << ct;
    
}

Measured memory_bytes: 256
#: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

input = sys.stdin.readline

########################################
ans = 0
n = int(input())
for i in range(1,n+1):
	for j in range(1,n+1):
		if i*j >= n:
			break
		ans+=1
print(ans)








'''
# Wrap solution for more recursion depth
#submit as python3
import collections,sys,threading
sys.setrecursionlimit(10**9)
threading.stack_size(10**8)



threading.Thread(target=solve).start()
'''


Measured memory_bytes: 68544
#include"bits/stdc++.h"
using namespace std;

void Main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  if (A >= K) cout << K << endl;
  else if (A + B >= K) cout << A << endl;
  else cout << A - (K - B - A)  << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}



Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define fast ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL)
double dp[3001][3001] ;

int main(){
int n ;
cin >> n ;
double a[n] , res = 0.00;
for(int i=1;i<=n;i++)
cin >> a[i] ;

dp[0][0] = 1 ;
for(int i=1;i<=n;i++){
	for(int j=0;j<=i;j++){
		dp[i][j] = (double)dp[i-1][j]*(1-a[i]) ;
		if(j>0)
		dp[i][j] += (double)dp[i-1][j-1]*a[i] ;
	}
}
for(int i=n;i>n/2;i--)
res += dp[n][i] ;
printf("%.10f",res) ;
}



Measured memory_bytes: 68992
#include<stdio.h>
int N, M, L, f, lx, ly, x, y, i;
char A[51][51], B[51][51];
int main(void){
	scanf("%d %d\n", &N, &M);
	for(i=0; i<N; i++){
		scanf("%s\n", A[i]);
	}
	for(i=0; i<M; i++){
		scanf("%s\n", B[i]);
	}
	L=N-M+1;
	for(ly=0; ly<L; ly++){
		for(lx=0; lx<L; lx++){
			f=1;
			for(int y=0;y<M;++y){
				for(int x=0;x<M;++x){
					if(A[ly+y][lx+x]!=B[y][x]){f=0;}
				}
			}
			if(f){
				printf("Yes\n");
				return 0;
			}
		}
	}
	printf("No\n");
	return 0;
}


Measured memory_bytes: 128
using System;
using System.Linq;

namespace ABC115_D
{
    class Program
    {
        static long[] a;
        static long[] p;
        static void Main(string[] args)
        {
            var NX = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var N = NX[0];
            var X = NX[1];

            a = new long[N];
            p = new long[N];
            a[0] = 1;
            p[0] = 1;
            for (int i = 1; i < N; i++)
            {
                a[i] = a[i - 1] * 2 + 3;
                p[i] = p[i - 1] * 2 + 1;
            }

            Console.WriteLine(Calc(N, X));
        }

        static long Calc(long n, long x)
        {
            if (n == 0) return x <= 0 ? 0 : 1;
            else if (x <= 1 + a[n - 1]) return Calc(n - 1, x - 1);
            else return p[n - 1] + 1 + Calc(n - 1, x - 2 - a[n - 1]);
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define pb(a) push_back(a)

typedef long long ll;
using namespace std;

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

//const int dy[] = { 0, 0, 1, -1 };
//const int dx[] = { 1, -1, 0, 0 };
const int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
ll gcd(ll a, ll b);
ll lcm(ll x, ll y);

vector<ll> a,b;
vector<pair<ll, ll>> mypair;

int main()
{
	ll n, m;
	ll s = 0;
	ll ans = 0;
	cin >> n >> m;
	for (ll i = 0; i < n; i++){
		ll tmp1,tmp2;
		cin >> tmp1 >> tmp2;
		a.push_back(tmp1);
		b.push_back(tmp2);
		mypair.push_back(make_pair(a[i], b[i]));
	}

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

	ll cnt = 0;
	bool flag = false;
	for (ll i = 0; i < n; i++) {
		for (ll j = 0; j < mypair[i].second; j++) {
			ans += mypair[i].first;
			cnt++;
			if (cnt >= m) {
				flag = true;
				break;
			}
		}
		if (flag == true) {
			break;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3676
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
typedef vector<tint> vtint;
typedef vector<vint> vvint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=200050;
//↑templete
signed main(){

    ll A, B, N;
    cin>>A>>B>>N;
    // for(int x=0;x<=N;x++)
    //     cout<<x<<" "<<(A*x/B)-A*(x/B)<<endl;

    ll X=min(B-1, N);
    cout<<(A*X/B)-A*(X/B)<<endl;

    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include<ctype.h>
# define pb push_back
#define fst first
#define sec second
#define For(i,a,b) for(int i=a;i<b;i++)
#define ll long long int
#define ull unsigned long long int
#define mod 1000000007
#define fo(i,n) for(ll i=0;i<n;i++)
#define endl "\n"
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define fo1(i,n) for(ll i=1;i<=n;i++)
#define boolsize 1000001
#define pi pair<ll,ll>
#define vi vector<ll>
#define vii vector<pi>
using namespace std;
template<typename T>
void showvector(vector <T> v)
{
    for(T x:v)
        cout<<x<<" ";
    cout<<endl;

}
template<typename T>
void showvector1(vector <T> v)
{
    ll n=v.size();
    fo1(i,n-1)
        cout<<v[i]<<endl;

}
template<typename T>
void showset(set <T> s)
{
    for(T x: s)
        cout<<x<<" ";
    cout<<endl;
}
template<class T>
void showvectorpair(vector<T> v)
{
    for(auto it=v.begin();it!=v.end();it++)
        cout<<it->first<<" "<<it->second<<endl;
    cout<<endl;
}
template<typename T,typename P>
void showmap(map <T,P> m)
{
    for(auto it=m.begin();it!=m.end();it++)
        cout<<it->first<<" "<<it->second<<endl;
    cout<<endl;
}
template<typename T>
bool comp(T a,T b)
{
    return (a>b);
}
template<class T>
bool comppair(T a,T b)
{
    if(a.first==b.first)
        return(a.second>b.second);
    return (a.first>b.first);
}
bool sameparity(ll a,ll b)
{
    return (a%2==b%2);
}
bool difparity(ll a,ll b)
{
    return !(a%2==b%2);
}
bool isprime(ll x)
{   if(x<=1)
     return false;
    for(ll i=2;i<=sqrt(x);i++)
    {
        if(x%i==0)
            return false;
    }
    return true;
}
bool iseven(ll x)
{
    return !(x%2);
}
bool isodd(ll x)
{
    return (x%2);
}
/// check for test case before submitting
void vfun()
{
    ll n,k;
    cin>>n;
    vector <ll> v(n);
    fo(i,n)
    cin>>v[i];

}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("inputh.txt", "r", stdin);
    freopen("outputh.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0); ///cant use scanf, printf
    cin.tie(0);cout.tie(0); /// no longer auto flush cout before each cin, remove for interactive
    //cout << fixed << setprecision(11); /// no scientific output
    ll test=1;
    //cin>>test;
    while(test--)
    {
            ll n,k,start=0,ans=0;;
            cin>>n>>k;
            vector <ll> v(n);
            fo(i,n)
                cin>>v[i];
            fo(i,n)
            {
                if(i==n-1)
                {
                    ans+=v[i]-v[start]+k;
                    break;
                }
                if(v[i]+k < v[i+1])
                {
                    ans+=v[i]+k-v[start];
                    start=i+1;
                }

            }
        cout<<ans;
//         if(vfun())
//            cout<<"YES\n";
//         else
//            cout<<"NO\n";
    }
}
///before sub
/// check for value of zero and single input in array
///loop vars,1LL in mult, equal, one, bounds, int v ll, endl, finish taking inputs
/// check whether test cases are given or not





Measured memory_bytes: 4692
#include<bits/stdc++.h>
using namespace std;
int gcd(int a, int b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
int findGCD(int arr[], int n)
{
    int result = arr[0];
    for (int i = 1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}
int main()
{
int n,k;
cin>>n>>k;
int arr[n],temp,te;
for(int i=0;i<n;i++)
{cin>>temp;
te=abs(temp-k);
arr[i]=te;
}
cout << findGCD(arr, n);

}


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

#define mp make_pair
#define pb push_back

#define int int64_t
#define ld long double

const int MOD = 1e9+7;
const int N = 1e6+5;

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int d,s,t;
	cin>>d>>s>>t;

	if(s*t>=d) {
		cout<<"Yes";
	}
	else {
		cout<<"No";
	}

	return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

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

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

int main() {
//	cout << fixed << setprecision(15);
	int n, m;
	cin >> n >> m;
	cout << (n+m)*(n+m-1)/2 - n*m << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
 
#define ll long long int
#define pb push_back
#define rep(i , j , n) for(ll i = j ; i < n ; i++)
#define per(i , j , n) for(ll i = j ; i >= n ; i--)
#define all(x) x.begin(), x.end()
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vll;



 
int main(){
    string s;
    cin >> s;
    cout << s[0] << s[1] << s[2] << endl;
    
}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s,t;
  cin >> s >> t;
  int q;
  int n = s.size();
  int m = t.size();

  VLL ss(n,0);
  VLL tt(m,0);

  rep(i,n){
    if(s[i] == 'A') ss[i] = 1;
    if(s[i] == 'B') ss[i] = 2;
  }

  rep(i,m){
    if(t[i] == 'A') tt[i] = 1;
    if(t[i] == 'B') tt[i] = 2;
  }

  rep(i,n-1){
    ss[i+1] += ss[i];
  }
  rep(i,m-1){
    tt[i+1] += tt[i];
  }
  cin >> q;

  rep(i,q){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    a--,b--,c--,d--;

    ll ansS = ss[b];
    ll ansT = tt[d];
    if(a > 0) ansS -= ss[a-1];
    if(c > 0) ansT -= tt[c-1];

    if( (ansS % 3) == (ansT % 3) ) {
      cout << "YES" << "\n";
    }else{
      cout << "NO" << "\n";
    }
  }
  return 0;
}


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

using namespace std;

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

    vector<int> L;
    L.reserve(N);

    int data;
    for (int n = 0; n < N; n++) {
        cin >> data;
        L.push_back(data);
    }
    sort(L.begin(), L.end());
    
    auto itr = L.rbegin();

    int sum = 0;
    for (int n = 0; n < K; n++) {
        sum += *itr;
        itr++;
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int hp = scanner.nextInt();
        int attack = scanner.nextInt();
        int result = hp / attack;
        int remain = hp % attack;
        if(remain != 0) result +=1;

        scanner.close();
        System.out.println(result);
    }
}

Measured memory_bytes: 23764
#define taskname ""
#include <bits/stdc++.h>

using namespace std;

const int maxN = 2e5 + 1;

int n;
int a[maxN];

int m = 0, hm = 0;

int idx;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
    }
    idx = max_element(a + 1, a + n + 1) - a;
    m = a[idx];
    for (int i = 1; i <= n; ++i)
    {
        if (i != idx)
        {
            hm = max(hm, a[i]);
        }
    }
    for (int i = 1; i <= n; ++i)
    {
        if (i == idx)
        {
            cout << hm << '\n';
        }
        else
        {
            cout << m << '\n';
        }
    }
    return 0;
}


Measured memory_bytes: 2432
# BFS
from collections import deque
def bfs(x):
    q = deque()
    for i in range(1, 10):
        q.append((i, i))
    #(a,b):=(ルンルン数,末尾の数)
    cnt=9
    while q:
        # qの先頭を取り出す
        num, back_number = q.popleft()
        for i in [-1, 0, 1]:
            temp = back_number + i
            if temp == -1: continue
            if temp == 10: continue
            cnt += 1
            q.append((num * 10 + temp, temp))
            if cnt == x :
                return q[-1][0]

x = int(input())
if x <= 9:
    print(x)
else:
    print(bfs(x))



Measured memory_bytes: 10356