akhauriyash/Code-Regression huggingface dataset:
# -*- coding:utf-8 -*-
n, m = map(int, input().strip().split())
ans = 0

digit ={}
for i in range(m):
    tmp_d, tmp = map(int, input().strip().split())
       	
    if (tmp_d in digit.keys()) and (digit[tmp_d] != tmp):
        print(-1)
        exit()
    else:
        digit[tmp_d] = tmp
      
      
if not (1 in digit.keys()) and n>=2:
	digit[1] = 1
    
ans = 0
for key in digit.keys():
  ans += digit[key]*(10**(n-key))

if len(str(ans)) == n: 
  print(ans)
else:
  print(-1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define int long long
#define vi vector<int>
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define rep(i, a, b) for(int i = a; i < b; i++)
#define repr(i, a, b) for(int i = a - 1; i >= b; i--)
#define iter(m) for(auto it = m.begin(); it != m.end(); it++)
#define iterr(m) for(auto it = m.rbegin(); it != m.rend(); it++)
#define N 500500
#define PI 3.14159265358979323846264338327950L
#define speed ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
signed main(){
    int n; cin >> n;
    vi v(n);
    rep(i, 0, n) {
        cin >> v[i];
    }
    int prev = v[0];
    int ans = 0;
    rep(i, 1, n) {
        if(prev <= v[i]) {
            prev = v[i];
        } else {
            ans += prev - v[i];
        }
    }
    cout << ans;
}

Measured memory_bytes: 4836
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int DigitSum(LL n){
int res=0;while(n>0){
res+=n%10;n/=10;}
return res;}
main(){
LL n,temp,cnt=1;
cin>>n;
int ans=DigitSum(n);temp=n;
while(temp>=10) {
temp/=10;cnt*=10;}
ans=max(ans,DigitSum(n/cnt*cnt - 1));
cout<<ans<<endl;}

Measured memory_bytes: 256
N=int(input())
A=list(int(x) for x in input().split())
for i in range(N):
    v=A[i]
    j=i-1
    while j>=0 and A[j]>v:
        A[j+1]=A[j]
        j-=1
    A[j+1]=v
    for i in range(N-1):
        print(A[i],end=" ")
    print(A[N-1])


Measured memory_bytes: 5984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll N;
    cin >> N;
    vector<ll> a(3*N);
    rep(i, 0, 3*N) cin >> a[i];
    sort(a.begin(), a.end());
    ll ans = 0;
    for(ll i = N; i < 3*N; i += 2) ans += a[i]; 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>
int main()
{
	int a,b,c,x=0,y=0,z=0;
	scanf("%d %d %d",&a,&b,&c);
	x=a+b;
	y=a+c;
	z=b+c;
	if(x<=y&&x<=z) printf("%d\n",x);
	if(y<x&&y<=z) printf("%d\n",y);
	if(z<x&&z<y) printf("%d\n",z);
	return 0;
}


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

string s;
int n;
int cnt[26];

int main() {
	cin >> s;
	for(char c: s) ++cnt[c-'a'];
	n = s.length();
	long long ans = 1LL*n*(n+1)/2LL+1LL;
	for(int i=0; i< 26; ++i) ans -= 1LL*cnt[i]*(cnt[i]+1)/2LL;
	cout << ans;
	return 0;
}

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

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

    double ans = 0.0;
    for(int i = 1; i <= n; i++){
        int score = i;
        double p = 1.0;
        while(score < k){
            p *= 0.5;
            score *= 2;
        }
        ans += p / n;
    }

    cout << setprecision(12) << ans << endl;
}


Measured memory_bytes: 768
import java.util.Scanner;

public class Main {

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

		int n = Integer.parseInt(sc.next());
		int a = Integer.parseInt(sc.next());

		int cnt = 1;
		
		for(int i = 1; i < n ; i++) {
			int temp = Integer.parseInt(sc.next());
			if(a >= temp) {
				
				a = temp;
				cnt++;
			}
		}
		
		
		
		System.out.println(cnt);
		
	}
	
	
	

}

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

int main(void)
{
  int N, A, B;
  cin >> N >> A >> B;
  string S;
  cin >> S;
  int winner = 0;
  int foreigner_winner = 0;
  for (int i=0; i<S.size(); ++i) {
    if (S[i] == 'a' && winner < A+B) {
        cout << "Yes" << endl;
        winner++;
    } else if (S[i] == 'b' && winner < A+B && foreigner_winner < B) {
        cout << "Yes" << endl;
        winner++;
        foreigner_winner++;
    } else {
        cout << "No" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <cmath>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
const int MAX_V=1e5;
const int INF=2e9;

struct edge{int to,dist;};
vector<edge> G[MAX_V+1];
int color[MAX_V+1];

bool dfs(int v,int c){
	color[v]=c;
	rep(i,G[v].size()){
		if(color[G[v][i].to]!=INF&&color[G[v][i].to]!=c+G[v][i].dist) return false;
		if(color[G[v][i].to]==INF&&!dfs(G[v][i].to,c+G[v][i].dist)) return false;
	}
	return true;
}

int main(){
	int N,M;
	cin>>N>>M;
	rep(i,M){
		int L,R,D;
		cin>>L>>R>>D;
		G[L].push_back(edge{R,D});
		G[R].push_back(edge{L,-D});
	}
	rep1(i,N)color[i]=INF;
	rep1(i,N){
		if(color[i]==INF)if(!dfs(i,0)){
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
}

Measured memory_bytes: 12032
#ifdef _MSC_VER
#include "stdc++.h"
#endif
#ifdef __GNUC__
#include<bits/stdc++.h>
#endif
using namespace std;

using ll = long long;

//vector
using vi = vector<int>;
using vii = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;

//constant
const double EPS = 1e-10;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// vector
//template<typename T> vector<vector<T>> vv(ll H, ll W, T v) { return vector<vector<T>> vec(H, vector<T>(W, v)); }

// view vector
template<typename T> void view(T e) { cout << e << endl; }
template<typename T> void view(const vector<T>& v) { for (const auto& e : v) { cout << e << " "; } cout << endl; }
template<typename T> void view(const vector<vector<T> >& vv) { for (const auto& v : vv) { view(v); } }

// DP
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; }




// ***************************************


int main() {

    priority_queue<ll> q;
    ll N;
    cin >> N;
    REP(i, N) {
        int a;
        cin >> a;
        q.push(a);
    }

    ll i = 1;
    ll ans = 0;
    while(i < N){
        ll x = q.top();
        q.pop();
        if (i == 1) {
            ans += x;
            i++;
        }
        else {
            if (i == N - 1) {
                ans += x;
                i++;
            }
            else {
                ans += 2 * x;
                i += 2;
            }
        }
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 5364
#include <stdio.h>
int main(void){
    int a,op,b,i;
    for(i=0; i<20000;i++){
        scanf("%d %c %d",&a,&op,&b);
        if ( op == '+' ){
            printf("%d\n",a+b);
            } else if ( op == '-' ){
                printf("%d\n",a-b);
            } else if ( op == '*' ){
            printf("%d\n",a*b);
            } else if ( op == '/' ){
                printf("%d\n",a/b);
            }
        }
    return 0;
}



Measured memory_bytes: 2044
def main():

    N = int(input())

    S = []
    for i in range(N):
        S.append(input())
    
    S.sort()

    now_name = S[0]
    ans = 1
    for i in range(N):
        if now_name != S[i]:
            ans += 1
            now_name = S[i]
    
    print('{}'.format(ans))



if __name__ == '__main__':
    main()

Measured memory_bytes: 23884
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
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 INF = 1e9;
const LL LLINF = 1e16;

int main(){
    int n;
    cin >> n;
    vector<int> a(n+1, -1);
    rep1(i,n+1) cin >> a[i];

    vector<int> b(n+1, -1);
    int ans = 0;
    for(int now=n; now>=1; now--){
        int tmp = 0;
        for(int j=now*2; j<=n; j+=now){
            // cout << j << " ";
            tmp += b[j];
        }
        // cout << endl;
        b[now] = (tmp+a[now])%2;
        ans += b[now];
    }
    cout << ans << endl;
    rep1(i, n+1)if(b[i] == 1){
        cout << i;
        cout << (--ans == 0 ? "\n" : " ");
    }


}

Measured memory_bytes: 2432
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn dfs(i: usize, a_list: &[usize], acc: usize) -> usize {
    if i == a_list.len() {
        return if acc % 2 == 0 { 1 } else { 0 };
    }
    let a = a_list[i];
    dfs(i + 1, a_list, acc * a)
    + dfs(i + 1, a_list, acc * (a + 1))
    + dfs(i + 1, a_list, acc * (a - 1))
}

fn main() {
    input! {
        n: usize,
        a_list: [usize; n]
    }
    let ans = dfs(0, &a_list, 1);
    println!("{}", ans);
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		sc.close();

		int s = (int) Math.ceil(Math.sqrt(n));
		for (long i = s; i > 0; i--) {
			if (n % i == 0) {
				long l = n / i;
				System.out.println(String.valueOf(l).length());
				return;
			}
		}
	}
}


Measured memory_bytes: 23124
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ std::cin >> head; _cin(std::forward<Tail>(tail)...); }
void _cout(){ std::cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ std::cout << head; _cout(std::forward<Tail>(tail)...); }
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, n, xs, sxs) vector<T> sxs(n+1); For(i, n) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; For(i, n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__);
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Couty(cond) Cout((cond) ? "Yes" : "No")
#define CoutY(cond) Cout((cond) ? "YES" : "NO")

using namespace std;
using ll = long long;

int main(void){
    Cin(int, n, k);
    Cins(int, n, x);
    DeSort(x);
    Cout(accumulate(x.begin(), x.begin() + k, 0));
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}

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

        Map<String,Integer> map = new HashMap<>();
        map.put("AC",0);
        map.put("WA",0);
        map.put("TLE",0);
        map.put("RE",0);
        for(int i=0;i<n;i++){
            String s = sc.next();
            int num = map.get(s);
            num++;
            map.put(s,num);
        }
        System.out.println("AC x " + map.get("AC"));
        System.out.println("WA x " + map.get("WA"));
        System.out.println("TLE x " + map.get("TLE"));
        System.out.println("RE x " + map.get("RE"));


    }

}




Measured memory_bytes: 58152
#include <iostream>
#include <string>
using namespace std;;
int main()
{
    string s;
    int cntc=0, i=0, cnt=0;
    cin >> s ;
    while(s[i]!='\0'){
        cnt++;
        i++;
    }
    if(s[0]!='A'){
            cout << "WA" <<endl;
            return 0;
        }
    if('A'<=s[cnt-1] && s[cnt-1]<='Z'){
        cout << "WA" <<endl;
        return 0;
    }
        i=1;
    while(s[i]!='\0'){
        if('A'<=s[1] && s[1]<='Z'){
            cout << "WA" <<endl;
            return 0;
        }
        if(i>=2 && i<=cnt-2 && s[i]=='C'){
            cntc++;
            if(cntc>=2){
                cout << "WA" <<endl;
                return 0;
            }
        }
        if(s[i]!='C' && 'A'<=s[i] && s[i]<='Z'){
            cout << "WA" <<endl;
            return 0;
        }
        i++;
    }

    if(cntc==1) cout << "AC" <<endl;
    else cout << "WA" <<endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  for ( i = 0; i <= VMAX; i++ ) C[i] = 0;

  for ( i = 0; i < n; i++ ){
    scanf("%hu", &A[i + 1]);
    C[A[i + 1]]++;
  }

  for ( i = 1; i <= VMAX; i++ ) C[i] = C[i] + C[i - 1];

  for ( j = 1; j <= n; j++ ){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for ( i = 1; i <= n; i++ ){
        printf("%d",B[i]);
        if(i!=n){
            printf(" ");
        }
        else{
            printf("\n");
        }
  }

  return 0;
}


Measured memory_bytes: 9640
from string import ascii_lowercase

s = input()
t = input()

d_s2t = dict()
d_t2s = dict()

flg = True
for ss, tt in zip(s, t):
    if d_s2t.get(ss) is None:
        d_s2t[ss] = tt
    else:
        if not d_s2t[ss] == tt:
            flg = False
            break

    if d_t2s.get(tt) is None:
        d_t2s[tt] = ss
    else:
        if not d_t2s[tt] == ss:
            flg = False
            break

if flg:
    if len(set(d_s2t.keys())) != len(set(d_s2t.values())):
        flg = False
    if len(set(d_t2s.keys())) != len(set(d_t2s.values())):
        flg = False

print('Yes' if flg else 'No')


Measured memory_bytes: 4164
def aaa(val):
    val = int(val)
    if val == 0:
        return [0, 1]
    if val == 1:
        return [0, 1, 2]
    if val == 2:
        return [1, 2, 3]
    if val == 3:
        return [2, 3, 4]
    if val == 4:
        return [3, 4, 5]
    if val == 5:
        return [4, 5, 6]
    if val == 6:
        return [5, 6, 7]
    if val == 7:
        return [6, 7, 8]
    if val == 8:
        return [7, 8, 9]
    if val == 9:
        return [8, 9]
        
l = [1, 2, 3, 4, 5, 6, 7, 8, 9]

for i in range(100000):
    # print(aaa(0))
    # print(str(l[i])[-1])
    ll = aaa(str(l[i])[-1])
    for a in ll:
        l.append(int(str(l[i]) + str(a)))
    if len(l) > 100000:
        break
        
# print(l)
k = int(input())
print(l[k - 1])

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


using namespace std;



int main(){

int a,b;


scanf("%d",&a);
scanf("%d",&b);

if(a==1){

    a=14;
}
if(b==1){

    b=14;
}



 if(a>b ){

    printf("Alice\n");


}
else if(b>a){

    printf("Bob\n");
}


else{

    printf("Draw\n");
}






}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    int n;
    cin >> n;
    int a[n];
    vector<int> b;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=1;i<=100;i++){
        int sum = 0;
        for(int j=0;j<n;j++){
            sum += pow(a[j]-i,2);
        }
        b.pb(sum);
    }
    sort(b.begin(),b.end());
    cout << b[0] << endl;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input! {
        n: usize,
        s: chars,
    }
    let mut x = 0;
    let mut max = 0;
    for i in 0..s.len() {
        if s[i] == 'I' {
            x+=1;
        } else {
            x-=1;
        }
        if x > max {
            max = x;
        }
    }
    println!("{}", max);
}

Measured memory_bytes: 4352
n = int(input())
a = list(map(int,input().split()))
ok = True
for i in range(n):
    if a[i] % 2 == 0 and a[i] % 3 != 0 and a[i] % 5 != 0:
        ok = False
if ok:
    print("APPROVED")
else:
    print("DENIED")

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

#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using ll = long long;
using ull = unsigned long long;

int main(){
    string s;
    while(cin >> s){
        int k = s.size()-1;
        ll ans = 0;
        rep(S,1<<k){
            ll sum = 0;
            ll c = s[0]-'0';
            rep(i,k){
                if(S>>i&1){
                    c *= 10;
                    c += s[i+1]-'0';
                } else {
                    sum += c;
                    c = s[i+1]-'0';
                }
            }
            sum += c;
            ans += sum;
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 10000000
  
int main()
{
  int n,i,j,k;
  scanf("%d",&n);
  int row[n];
  int column[n];
  int dp[n][n];

  for(i=0;i<n;i++)
    {
      scanf("%d %d",&row[i],&column[i]);
    }
  
  for(i=0;i<n;i++)
    {
      for(j=0;j<n;j++)
	{
	  dp[i][j]=MAX;
	}
    }
  
  for(i=0;i<n;i++)
    {
      dp[i][i]=0;
    }
 
  for(j=0;j<n;j++)
    {
      for(i=0;i<n-j;i++)
	{
	  for(k=i+1;k<=i+j;k++)
	    {
	      dp[i][i+j]=min(dp[i][i+j],dp[i][k-1]+dp[k][i+j]+row[i]*column[k-1]*column[i+j]);
	    }
	}
    }
  printf("%d\n", dp[0][n-1]);
 
  return 0;
}
 
int min(int a,int b)
{
  if(a<b)
    {
      return a;
    }
  return b;
}

Measured memory_bytes: 636
from pprint import pprint

n, w = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(n)]

lim = 1
for i in range(n):
    lim += wv[i][1]

dp = [[float('inf')] * lim for _ in range(n+1)]
dp[0][0] = 0

for i in range(n):
    for j in range(lim):
        if j - wv[i][1] >= 0:
            dp[i+1][j] = min(dp[i][j - wv[i][1]] + wv[i][0], dp[i][j])
        else:
            dp[i+1][j] = min((dp[i][j], dp[i+1][j]))

ans = float('inf')

for i in reversed(range(lim)):
    if dp[-1][i] <= w:
        ans = min(i, ans)
        break
print(ans)

Measured memory_bytes: 334932
#include <cstdio>
#include <cctype>
#include <algorithm>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
#define repe(i,x) for (edge *i=fst[x]; i; i=i->nxt)
using namespace std;

typedef long long LL;
int n,s[200100],mind[200100],max1[200100],max2[200100];
LL ans;
char a[200100];
struct edge
{
    int v;
    edge *nxt;
} pool[400100],*tp=pool,*fst[200100];

int getint()
{
    char ch;
    while (!isdigit(ch=getchar()));
    int x=ch-'0';
    for (; isdigit(ch=getchar()); x=x*10+ch-'0');
    return x;
}

void update(int &x,int &y,int z)
{
    if (z>x)
        y=x,x=z;
    else
        y=max(y,z);
}

void dfs1(int x,int fa)
{
    s[x]=a[x]-'0',mind[x]=n;
    repe(i,x)
        if (i->v!=fa)
        {
            dfs1(i->v,x),s[x]+=s[i->v];
            update(max1[x],max2[x],max1[i->v]+1);
            if (s[i->v])
                mind[x]=min(mind[x],max1[i->v]+1);
        }
}

void dfs2(int x,int fa,int d)
{
    update(max1[x],max2[x],d);
    if (s[1]-s[x])
        mind[x]=min(mind[x],d);
    if (a[x]=='1')
        mind[x]=0;
    repe(i,x)
        if (i->v!=fa)
            dfs2(i->v,x,max1[i->v]+1==max1[x]?max2[x]+1:max1[x]+1);
}

int main()
{
    n=getint();
    repu(i,1,n-1)
    {
        int u=getint(),v=getint();
        *tp=(edge){v,fst[u]},fst[u]=tp++;
        *tp=(edge){u,fst[v]},fst[v]=tp++;
    }
    scanf("%s",a+1);
    dfs1(1,0),dfs2(1,0,0);
    repu(i,1,n)
        ans+=max(0,min(max1[i]-1,max2[i]+1)-mind[i]+1);
    printf("%lld\n",ans+1);
    return 0;
}

Measured memory_bytes: 18432
#include <iostream>
#include <cstdio>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	stack <int> S1;
	stack <pair <int, int> > S2;
	char ch;
	int sum = 0;
	for (int i = 1;cin >> ch; i++){
		if (ch == '\\') S1.push(i);
		else if (ch == '/' && S1.size() > 0){
			int j = S1.top();
			S1.pop();
			sum += i-j;
			int a = i-j;
			while (S2.size() > 0 && S2.top().first > j){
				a += S2.top().second;
				S2.pop();
			}
			S2.push(make_pair(j, a));
		}
	}
	
	vector <int> ans;
	while (S2.size() > 0){
		ans.push_back(S2.top().second);
		S2.pop();
	}
	reverse(ans.begin(),ans.end());
	cout<< sum << endl;
	cout<< ans.size();
	for (int i = 0; i < ans.size(); i++){
		cout<< " ";
		cout<< ans[i];
	}
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
void fast(){
cin.tie(0);
cin.sync_with_stdio(0);
}
 
int main()
{
	fast();
	string s;
	cin>>s;
	if(s.size()==2&&s[1]==s[0]){cout<<"1 2";return 0;}
	for(int i=0;i<s.size()-2;i++){
			int freq[130]={};
		for(int j=i;j<i+3;j++){
			freq[s[j]]++;
			if(j==i+2){for(int k=97;k<=122;k++){
				if(freq[k]>=2){cout<<i+1<<" "<<j+1;return 0;}
 
			}
			}
		}
	}
	cout<<"-1 -1";
    return 0;
}

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

const double EPS=1e-6;

double evaluate(vector<double>&r){
    double res=r[0]+r[r.size()-1];
    for(int i=0;i+1<r.size();i++){
        double h=(r[i]+r[i+1]);
        double s=abs(r[i]-r[i+1]);
        res+=sqrt(h*h-s*s);
    }
    return res;
}

double optimize(vector<double>r){
    double T=10000;
    double cool=0.99;
    double step=1;

    double mi=evaluate(r);

    while(T>0.00001){
        int a,b;
        while(true){
            a=rand()%r.size();
            b=rand()%r.size();
            if(a!=b)break;
        }

        double score=evaluate(r);
        swap(r[a],r[b]);
        double new_score=evaluate(r);

        double p=exp(-abs(new_score-score)/T);

        if(new_score>score || rand()<p*RAND_MAX);
        else{
            swap(r[a],r[b]);
        }

        mi=min(mi,new_score);
        T*=cool;
    }
    return mi;
}

int main(){
    int l;
    while(cin>>l){
        string str;
        getline(cin,str);
        stringstream ss(str);
        vector<double>r;
        while(!ss.eof()){
            double t;
            ss>>t;
            r.push_back(t);
        }

        double ans;
        if(r.size()==1)ans=r[0]*2;
        else ans=optimize(r);

        if(ans<l+EPS)puts("OK");
        else puts("NA");
    }

    return 0;
}

Measured memory_bytes: 3520
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    int n; cin >> n;
    ll t; cin >> t;
    ll prev = 0;
    ll tot = 0;
    REP(i, n) {
        ll tmp; cin >> tmp;
        ll diff = tmp - prev;
        if (i != 0) {
            if (diff < t) {
                tot += diff;
            } else {
                tot += t;
            }
        }
        prev = tmp;
    }
    tot += t;
    cout << tot << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>

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

    std::vector<std::vector<int>> to(n);
    std::map<std::pair<int, int>, int> ord;
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        std::cin >> a >> b;
        a--;
        b--;
        to[a].push_back(b);
        to[b].push_back(a);
        ord[{a, b}] = i;
        ord[{b, a}] = i;
    }

    int max_deg = 0, start = -1;
    for (int i = 0; i < n; i++) {
        if (max_deg < to[i].size()) {
            max_deg = to[i].size();
            start = i;
        }
    }

    std::vector<int> col(n), ans(n - 1);
    auto dfs = [&](auto&& dfs_, int pos) -> void {
        int now_col = 1;
        for (int next: to[pos]) {
            if (next != start && col[next] == 0) {
                if (now_col == col[pos]) {
                    now_col++;
                }
                col[next] = now_col;
                ans[ord[{pos, next}]] = now_col;
                dfs_(dfs_, next);
                now_col++;
            }
        }
    };
    dfs(dfs, start);

    std::cout << max_deg << std::endl;
    for (int i = 0; i < n - 1; i++) {
        std::cout << ans[i] << std::endl;
    }
    return 0;
}


Measured memory_bytes: 19328
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int,int> Pi;
const ll inf = 1e18 + 1;
const ll limit = 1e9;

int main() {
    int n,m; cin >> n >> m;
    map<int,int> mp;
    for (int i = 1; i <= n; i++) mp[i] = 0;
    int ac = 0;
    int pena = 0;
    for (int i = 0; i < m; i++) {
        int p; cin >> p;
        string s; cin >> s;
        if (mp[p] == -1) continue;
        if (s == "WA") mp[p]++;
        else ac++, pena += mp[p], mp[p]=-1;
    }
    cout << ac << " " << pena << "\n";
}

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>

using namespace std;

int main() {
	int n;
    cin >> n;
    vector< vector<int> > atoz(n, vector<int>(26, 0));
    map<vector<int>, long long> count;

    for (int i=0; i<n; i++) {
        string s;
        cin >> s;
        for (int j=0; j<10; j++)
            atoz[i][s[j]-'a']++;
    }

    vector< vector<int> > group(n, vector<int>(26, 0));
    int group_num = 0;
    for (int i=0; i<n; i++) {
        if (count.count(atoz[i]) == 0) {
            count[atoz[i]] = 1;
            group_num++;
            group.push_back(atoz[i]);
        }
        else
            count[atoz[i]]++;
    }

    long long ans = 0;
    for (int i=0; i<group_num; i++) {
        vector<int> s = group.back();
        group.pop_back();
        if (count[s] >= 2)
            ans += (count[s] * (count[s]-1)) / 2;
    }

    cout << ans << endl;
}


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

template <class T>
using lim = numeric_limits<T>;

const int MOD = 1'000'000'007;
int main() {
	ios_base::sync_with_stdio(false) ;
	cin.tie(0);
	
	string s;
	cin >> s;
	
	int n = s.length();
	
	// tracks possibilities 3^(# of ?)
	ll possible = 1;
	
	// how many c's, bc's, and abc's
	ll abc = 0;
	ll bc = 0;
	ll c = 0;
	
	for (int i = n-1; i >= 0; i--){
		if (s[i] == '?'){
			// math
			abc = (abc*3 + bc)%MOD;
			bc = (bc*3 + c)%MOD;
			c = (c*3 + possible)%MOD;
			
			possible = (possible*3)%MOD;
		}
		else if (s[i] == 'C') c = (c+possible)%MOD;
		else if (s[i] == 'B') bc = (bc+c)%MOD;
		else abc = (abc+bc)%MOD;
	}
	
	cout << abc << endl;
}



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

int main() {
  char C;
  cin >> C;
  if (C == 'a' || C == 'e' || C == 'i' || C == 'o' || C == 'u'){
      cout << "vowel" << endl;
  }
  else {
      cout << "consonant" << endl;
  }
}

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

int main() {
  int x,a,b,c,d;
  cin >> x;
  
  a = x / 100;
  b = x / 10;
  c = b % 10;
  d = x % 10;
  
  if (a == 7 || c == 7 || d == 7) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3632
N = int(input())
do = [list(map(int,input().split())) for i in range(N)]

do.sort(key=lambda x:x[1])

t = 0
ans = 'Yes'
for i in range(N):
    t += do[i][0]
    if t > do[i][1]:
        ans = 'No'
        break
print(ans)



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

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

    int a[1000000];
    for (int i = 0; i < k; i++) a[i] = 0;
    a[0] = 7;
    if (k == 7 || k == 1) {
        cout << 1 << endl;
        return 0;
    }
    for (int i = 1; i < k; i++) {
        a[i] = (10 * a[i - 1] + 7) % k;
        if (a[i] == 0) {
            cout << i + 1 << endl;
            return 0;
        }
    }

    cout << -1 << endl;
}


Measured memory_bytes: 7548
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

string IntToString(ll int number){
  stringstream ss;
  ss << number;
  return ss.str();
}

string tmp;
string tmp2;

int main(){
	int q,cnt;
	cin >> q;
	REP(i,q){
		
		cin >> tmp;
		tmp2 = tmp;
		cnt = 0;
		while(tmp.size()!=1){
			int mmax = -1;
			FOR(i,1,tmp.size()){
				string st1,st2;
				FOR(j,0,i) st1 += tmp[j];
				FOR(j,i,tmp.size()) st2 += tmp[j];
				mmax = max(mmax,stoi(st1)*stoi(st2));
			}
			cnt++;
			tmp = IntToString(mmax);
			if(tmp==tmp2){
				cnt = -1;
				break;
			}
		}
		
	cout << cnt << endl;
	}
	return 0;
}

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

#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define inf  1e18
#define mk(arr,n,type) type *arr=new type[n];
#define ti(arr,n) for(ll i=0;i<n;++i)cin>>a[i];
#define ot(arr,n) for(ll i=0;i<n;++i)cout<<a[i]<<" ";
#define str(a) string a;cin>>a;
#define w(x) int x;cin>>x;while(x--)
int main()
{
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  ll ans[4];
  ans[0]=a*c;ans[1]=a*d;ans[2]=b*c;ans[3]=b*d;
  cout<<*max_element(ans,ans+4);
}

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

int main(void) {
    int h,w;
    cin >> h >> w;

    vector<vector<int>> c(10, vector<int>(10));
    for(auto &l: c)
        for(auto &c: l)
            cin >> c;

    vector<vector<int>> dis(10, vector<int>(10));
    for(int i=0; i<10; i++)
        for(int j=0; j<10; j++)
            dis[i][j] = c[i][j];

    for(int k=0; k<10; k++)
        for(int i=0; i<10; i++)
            for(int j=0; j<10; j++)
                dis[i][j] = min(dis[i][k]+dis[k][j], dis[i][j]);

    vector<int> a(10);
    for(int i=0; i<h; i++)
        for(int j=0; j<w; j++) {
            int aa;
            cin >> aa;
            if(aa != -1)
                a[aa]++;
        }

    long res = 0;
    for(int i=0; i<10; i++)
        res += a[i]*dis[i][1];

    cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define show(x) cout << #x << " = " << (x) << endl;
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl;
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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; }

//ll dp[i][j][k]: 1,..,i からj枚選んで合計をkにするような選び方の総数
ll dp[55][55][2550];
ll x[55];

int main () {
  int n, a;
  cin >> n >> a;
  rep(i,n) cin >> x[i];
  
  rep(i,55)rep(j,55)rep(k,2550) dp[i][j][k] = 0;
  dp[0][0][0] = 1;
  rep(i,50) {
    rep(j,50) {
      rep(k,2501) {
        if (dp[i][j][k] == 0) continue;
        dp[i+1][j][k] += dp[i][j][k];
        dp[i+1][j+1][k+x[i]] += dp[i][j][k];
      }
    }
  }

  ll ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans += dp[n][i][i*a];
  }
  cout << ans << endl; 
  return 0;
}

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

int main()
{
	int n;
	cin>>n;
	int arr[n];
	
	for(int i=0;i<n;i++)
	cin>>arr[i];
	
	int dp[n];
	dp[0]=0;
	dp[1]=abs(arr[1]-arr[0]);
	for(int i=2;i<n;i++)
	{
		dp[i]=min(abs(arr[i]-arr[i-1])+dp[i-1],abs(arr[i]-arr[i-2])+dp[i-2]);
	}
	cout<<dp[n-1]<<"\n";
}
	
	
				


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

int main() {

    string s; cin >> s;
    const int p = 26;
    vector<int> num(p, 0);
    for (int i = 0; i < s.size(); i++) num[s[i] - 'a']++;

    for (int i = 0; i < p; i++) {

        if (num[i] == 0) {
            char tmp = (char)(i + 'a');
            cout << tmp << endl;
            return 0;
        }

    }
    cout << "None" << endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define MAX 100000
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b and b==c and c==a) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
N, M = (int(x) for x in input().split(' '))
TMP = ['*'] * N
ans = 0

#ループで探しながら置き換え処理 
for i in range(M):
  s, c = (int(x) for x in input().split(' '))

  #既に異なる値が指定されている場合はエラー(-1)とする
  if TMP[s-1] == '*' or TMP[s-1] == c:
    TMP[s-1] = c
  else:
    ans = -1
    break    

# 例外判定。桁数が2桁以上で先頭桁に0が指定された場合。0で始まる2桁以上数は-1とする。
if N > 1 and TMP[0] == 0:
  ans = -1

#未指定文字の置き換え。最上位桁は"1"に、以外は"0"に置き換える。
if ans != -1:
  for x in range(N):
    #先頭の未指定文字は1に置き換え
    if TMP[x] == '*' and x == 0:
      if N == 1 and M == 0: 
        TMP[x] = 0
      else:
      	TMP[x] = 1

    #以外の未指定文字は0に置き換え
    if TMP[x] == '*' and x > 0:
      TMP[x] = 0


if ans != -1:
  ans = int(''.join(map(str, TMP)))
  print(ans)
else:
  print(-1)


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

int main() {
  string S;
  cin >> S;
  int N = S.size();
  bool b = true;
  while (b) {
    N -= 2;
    S = S.substr(0,N);
    if (S.substr(0,N/2) == S.substr(N/2)) {
      b = false;
    }
  }
  cout << N << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

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

	map<ll, ll> mp;
	for(int i = 0; i < n; ++i) {
		ll a, b;
		cin >> a >> b;
		mp[a] += b;
	}
	
	int ans = 0;
	for(auto& x : mp) {
		if( x.second >= k ) {
			ans = x.first;
			break;
		}
		
		k -= x.second;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 7460
#include <stdio.h>
#define MAX 500001

void maxHeapify(int);
void swap(int *, int *);
int N[MAX],H;

int main(){
  int i;

  scanf("%d",&H);
  for(i = 1; i <= H; i++){
    scanf("%d", &N[i]);
  }
   for(i = H /2; i > 0; i--){
    maxHeapify(i);
  }
   for(i = 1; i <= H; i++){
    printf(" %d", N[i]);
  }
  printf("\n");
  return 0;
}

void maxHeapify(int n){
  int max_i;
  max_i = n;
  if(H >= (2 * n) && N[n] < N[2*n]){
    max_i = 2 * n;
  }
  if(H >= (2 * n + 1) && N[max_i] < N[2*n+1]){
    max_i = 2 * n + 1;
  }

  if(max_i != n){
    swap(&N[n],&N[max_i]);
    maxHeapify(max_i);
  }
  return;
}

void swap(int *a, int *b){
  int c;

  c = *a;
  *a = *b;
  *b = c;
  return;
}



Measured memory_bytes: 3668
#include <iostream>

using namespace std;

int main()
{
  string line;
  getline(cin, line);
  int count = 0;
  char state = line[0];
  for(auto ch : line) {
    if(ch != state) {
      state = ch;
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 512
h,w,m=map(int,input().split())

xsct=[0]*w
ysct=[0]*h
ips=set()
xsmx=ysmx=0
for _ in range(m):
    y,x=map(int,input().split())
    x,y=x-1,y-1
    xsct[x]+=1
    ysct[y]+=1
    ips.add((x,y))
    xsmx=max(xsmx,xsct[x])
    ysmx=max(ysmx,ysct[y])

xs=[x for x in range(w) if xsct[x]==xsmx]
ys=[y for y in range(h) if ysct[y]==ysmx]

ans=xsmx+ysmx-1
ok=False
for y in ys:
    for x in xs:
        if (x,y) not in ips:
            ans+=1
            ok=True
            break
    if ok:
        break

print(ans)


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

int main() {
	int N, L;
	int min = 500;
	int sum = 0;
	cin >> N >> L;
	for (int i = 0; i < N; i++) {
		int z_min = min;
		min = std::min(abs(min), abs(L+i));
		if (min == abs(z_min)) {
			min = z_min;
		} else if (min == abs(L+i)){
			min = L+i;
		}
		sum += L+i;
	}
	cout << sum-min << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
  int D;
  scanf("%d", &D);
  if (D==25){
    printf("Christmas");
  }
  else if (D==24){
    printf("Christmas Eve");
  }
  else if (D==23){
    printf("Christmas Eve Eve");
  }
  else if (D==22){
    printf("Christmas Eve Eve Eve");
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MP make_pair
#define INF 0x3f3f3f3f
#define sz(x) (x).size()
#define fi first
#define se second
const int N = 1e5 + 5;

int n, k;
vector <pair<int, int>> v[N];
ll dp[N];

struct BIT {
    ll c[N];
    void init() {
        for (int i = 1; i <= n; i++) {
            c[i] = 1e18;
        }
    }
    int lowbit(int x) {
        return x & (-x);
    }
    void update(int x, ll v) {
        x = n - x + 1;
        for (; x <= n; x += lowbit(x)) {
            c[x] = min(c[x], v);
        }
    }
    ll query(int x) {
        x = n - x + 1;
        ll res = 1e18;
        for (; x; x -= lowbit(x)) {
            res = min(res, c[x]);
        }
        return res;
    }
}bit;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
  ll a,b,c;
  cin>>a>>b>>c;
  cout<<(b/c)-(a-1)/c;

    return 0;
}
/*
4 6
3 3 -10
4 4 8
2 3 -2
4 4 -10
4 4 5
1 4 2
*/


Measured memory_bytes: 5956
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
void solve() {
	bool b[20][20][20][20];
	int gx, gy; cin >> gx >> gy;
	for (int i = 0; i < gx; i++)for (int j = 0; j <= gy; j++)b[i][j][i + 1][j] = 1;
	for (int i = 0; i <= gx; i++)for (int j = 0; j < gy; j++)b[i][j][i][j + 1] = 1;
	int k; cin >> k;
	for (int i = 0; i < k; i++) {
		int p, q, r, s; cin >> p >> q >> r >> s;
		if (p > r || q > s) { swap(p, r); swap(q, s); }
		b[p][q][r][s] = 0;
	}
	int ans[20][20]; ans[0][0] = 1;
	for (int i = 1; i <= gx; i++)ans[i][0] = ans[i - 1][0] * b[i - 1][0][i][0];
	for (int i = 1; i <= gy; i++)ans[0][i] = ans[0][i - 1] * b[0][i - 1][0][i];
	for (int i = 1; i <= gx; i++) 
		for (int j = 1; j <= gy; j++) 
			ans[i][j] = ans[i - 1][j] * b[i - 1][j][i][j] + ans[i][j - 1] * b[i][j - 1][i][j];
	if (ans[gx][gy] == 0) { cout << "Miserable Hokusai!\n"; }
	else cout << ans[gx][gy] << endl;
}
signed main() {
	int wq; cin >> wq;
	for (int i = 0; i < wq; i++)solve();
}


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

using namespace std;
using ll = long long;

const ll mod = 1000000007;

auto main (void) -> int {
  int n;
  cin >> n;

  vector<ll> a (n);
  for (auto i = 0; i < n; i++) cin >> a[i];

  ll tmp_0 = 0;
  ll tmp_1 = 0;

  for (auto i = 0; i < n; i++) {
    ll a_i = a[i] % mod;
    tmp_0  = (tmp_0 + a_i) % mod;
    tmp_1  = (tmp_1 + a_i * a_i) % mod;
  }

  tmp_0 = (tmp_0 * tmp_0) % mod;

  ll b = tmp_0 < tmp_1 ? tmp_0 - tmp_1 + mod : tmp_0 - tmp_1;

  if (b % 2 != 0) {
    cout << (b + mod) / 2 << endl;
  }
  else {
    cout << b / 2 << endl;
  }

  return 0;
}


Measured memory_bytes: 4784
//-------All power is within you,you can do Anything and Everything.---------//
 
    #include <bits/stdc++.h>
    using namespace std;
  
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ M $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//

    #define pb push_back
    #define MP make_pair
    #define F first
    #define S second
    #define int long long
    #define fo(i,a,b) for(int i=a;i<b;i++)
    #define rfo(i,b,a) for(int i=b;i>=a;i--)
    #define deb(x) cout<<#x<<" "<<x<<endl;
    #define mem( a, val ) memset(a, val, sizeof( a ) )
    #define deci( x ) cout<<fixed<<setprecision( x );
    #define bitcount( x ) __builtin_popcountll( x )
 
    
    typedef vector<int> vi;
    typedef pair<int,int> pi; 
    
    const int MOD =  1000000007 ;
    const int MAX = 2e6 + 7;
    const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
    const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};

//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ V $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//  
    
    int i,j,k,t,n,q,l,r,mid;
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ F $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
    
    map<int,int> mp,ps;
    int ex,pos,h,x,d,a,cnt,prpos,findpos;
    vector<int> v;
    void solve()
    {
        cin>>n>>d>>a;
        fo(i,0,n)
        {
            cin>>x>>h;
            mp[x]=h;
            v.pb(x);
        }
        sort(v.begin(),v.end());

        for(auto x: mp)
        {
            pos=x.F;
            h=x.S;
            ps[pos]+=ps[prpos];
            // deb(ps[pos])
            if(h+ps[pos]>0)
            {
                ex=(h+ps[pos]+a-1)/a;
                ps[pos]-=ex*a;
                findpos=pos+2*d+1;
                findpos=lower_bound(v.begin(),v.end(),findpos)-v.begin();
                
                ps[v[findpos]]+=ex*a;
                cnt+=ex;
            }
            prpos=pos;
        }
        cout<<cnt<<endl;

    }
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
//                          GAME STARTS FROM HERE                            //

    int32_t main() 
      {
        
        // int start,stop=clock();
        // cout<<"time:"<<(stop-start)/double(CLOCKS_PER_SEC)*1000<<endl;
        ios_base::sync_with_stdio(0);
        cin.tie(NULL);
        
        // cin>>t;while(t--)
        solve();
        
      return 0;
      }

Measured memory_bytes: 26864
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let mut n: i64 = sc.cin();
    let k: i64 = sc.cin();
    n %= k;
    put!(min!(n, (n-k).abs()));
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


Measured memory_bytes: 4352