akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define at(x,i) get<i>(x);
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n;cin >> n;
    deque<ll> que;
    ll a;cin >> a;
    que.push_front(a);
    rep(i,n-1){
        ll b;cin >> b;
        ll x=que.front();
        if(x>=b)que.push_front(b);
        else{
            auto i=lower_bound(all(que),b)-que.begin();
            que[i-1]=b;
        }
    }
    cout << que.size() <<endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
int main () {
	int card[4][14];
	int cardNum;
	int number;
	char marks[4] = {'S' , 'H' , 'C' , 'D'};
	char mark;
	int i , s;

	for(i = 0; i < 4; i++) {
		for(s = 0; s < 14; s++) {
			card[i][s] = 0;
		}
	}
	scanf("%d" , &cardNum);
	getchar();
	for(i = 0; i < cardNum; i++) {
		scanf("%c %d" , &mark , &number);
		getchar();	
		if (mark == 'S') {
			card[0][number] = 1;
		}
		else if(mark == 'H') {
			card[1][number] = 1;
		}
		else if(mark == 'C') {
			card[2][number] = 1;
		}
		else if(mark == 'D') {
			card[3][number] = 1;
		}
	}

	for(i = 0; i < 4; i++) {
		for(s = 1; s <= 13; s++) {
			if (card[i][s] == 0) {
				printf("%c %d\n" , marks[i] , s);
			}
		}
	}

	return 0;
}

Measured memory_bytes: 600
# coding: utf-8
import sys

# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
#from heapq import heappop, heappush
#from collections import defaultdict

sys.setrecursionlimit(10 ** 7)
# import math
# from itertools import product, accumulate, combinations, product
# import bisect# lower_bound etc
#import numpy as np
# from copy import deepcopy
#from collections import deque
#import numba
#import math

def run():
    N = int(input())
    A = list(map(int, input().split()))
    limit = 10 ** 18
    ret = 1
    if 0 in A:
        print(0)
        return None
    for a in A:
        ret *= a
        if ret > limit:
            print('-1')
            return None
    print(ret)



if __name__ == "__main__":
    run()


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

int main(){
    int N;
    cin >> N;
    long long a[N];
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }

    int minimum = INT_MAX;
    for(int i = 0; i < N; i++){
        int b = 0;
        while(a[i] % 2 == 0){
            b++;
            a[i] /= 2;
        }
        minimum = min(b, minimum);
    }

    cout << minimum << endl;
}

Measured memory_bytes: 256
/*input
9
9 6 3 2 5 8 7 4 1
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
typedef long long int ll;
#define ld long double
#define pii pair<int,int>
#define f first
#define s second
#define pb emplace_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define sz(_a) (ll)(_a.size())
#define FILL(n) memset(n,0,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
const ll maxn=100005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
ll mypow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
int arr[maxn];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	REP(i,n){
		cin>>arr[i];
	}
	int cnt=0;
	for(int i=1;i<n-1;i++){
		if(arr[i]>arr[i-1] and arr[i]<arr[i+1]) ++cnt;
		if(arr[i]<arr[i-1] and arr[i]>arr[i+1]) ++cnt;
	}
	cout<<cnt;
}

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

int main()
{
	vector<int> vec(3);
	int five_cnt = 0;
	int seven_cnt = 0;

	for (int i = 0; i < 3; i++)
	{
		cin >> vec.at(i);
		if (vec.at(i) == 5)
		{
			five_cnt++;
		}
		else if (vec.at(i) == 7)
		{
			seven_cnt++;
		}
	}
	
	if (five_cnt == 2 && seven_cnt == 1)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x, n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair< int, int > P;   
typedef pair< int, P > PP;

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


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

    int a, b;
    cin >> a >> b;
    cout << a - 1 + (int)(a <= b) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long int lld;
typedef pair<lld, lld> pii;

const lld M = 1000000007;

lld exp(int b, lld e) {
    if (!e) return 1ll;
    lld x = exp(b, e/2);
    x *= x;
    x %= M;
    if (e & 1ll) {
        x *= b;
        x %= M;
    }
    return x;
}

lld gcd(lld a, lld b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a%b);
}

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

    int n;
    cin >> n;
    map<pii, lld> bucket;
    set<pii> procesado;
    lld zeroes = 0;
    for (int i = 0; i < n; ++i) {
        lld a, b;
        cin >> a >> b;
        if (a == 0 && b == 0) {
            zeroes++;
            continue;
        }
        lld g = gcd(abs(a), abs(b));
        a /= g;
        b /= g;
        if (a < 0 || (a == 0 && b < 0)) {
            a *= -1;
            b *= -1;
        }
        bucket[{a, b}]++;
    }

    lld ans = 0;
    for (auto it : bucket) {
        lld a, b, c;
        tie(a, b) = it.first;
        c = it.second;

        lld pa = b;
        lld pb = -a;
        if (pa < 0 || (pa == 0 && pb < 0)) {
            pa *= -1;
            pb *= -1;
        }
        lld pc = 0;
        if (bucket.count({pa, pb})) {
            pc = bucket[{pa, pb}];
        }

        if (procesado.count({a, b}) > 0) continue;
        procesado.insert({a, b});
        procesado.insert({pa, pb});

        //cout << "Procesing " << endl;
        //cout << a << " " << b << " " << c << endl;
        //cout << pa << " " << pb << " " << pc << endl;
        lld curr = ans;
        lld tmp = (exp(2, c) + exp(2, pc) - 2ll + M) % M;
        ans += (curr*tmp + tmp) % M;
        ans %= M;
        //cout << ans << endl;
    }
    ans += zeroes;
    ans %= M;
    cout << ans << "\n";
    return 0;
}

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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  vector<int> diff(n);
  rep(i, n) {
    if (i == 0) {
      diff.at(i) = 0;
    } else {
      diff.at(i) = a.at(i) - a.at(i - 1);
    }
  }
  int res = 0;
  bool isIncrement = false;
  bool initialized = false;
  for (int i = 1; i < n; i++) {
    int d = diff.at(i);
    if (d > 0) {
      if (!initialized) {
        isIncrement = true;
        initialized = true;
        continue;
      }
      if (!isIncrement) {
        res++;
        isIncrement = true;
        initialized = false;
      }
    } else if (d < 0) {
      if (!initialized) {
        isIncrement = false;
        initialized = true;
        continue;
      }
      if (isIncrement) {
        res++;
        isIncrement = false;
        initialized = false;
      }
    } else {
      // 処理なし
    }
  }
  res++;
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 3996
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
using ll = long long;

const long double PI = acos(-1.0);
const int MOD = 1e9 + 7;

int main() {
    ll x, k, d;
    cin >> x >> k >> d;


    ll ans;
    if(x == 0) {
        if(k % 2 == 0) ans = 0;
        else ans = d;
    }

    if(x > 0) {
        if(k < x / d) ans = x - d * k;
        else {
            ll q = (ll) (x / d);
            ll ans1 = x % d;
            ll ans2 = abs(ans1 - d);
            if(q % 2 == 0 && k % 2 == 0) ans = ans1;
            if(q % 2 == 0 && k % 2 != 0) ans = ans2;
            if(q % 2 != 0 && k % 2 == 0) ans = ans2;
            if(q % 2 != 0 && k % 2 != 0) ans = ans1;
        }
    }

    if(x < 0) {
        x = abs(x);
        if(k < x / d) ans = x - d * k;
        else {
            ll q = (ll) (x / d);
            ll ans1 = x % d;
            ll ans2 = abs(ans1 - d);
            if(q % 2 == 0 && k % 2 == 0) ans = ans1;
            if(q % 2 == 0 && k % 2 != 0) ans = ans2;
            if(q % 2 != 0 && k % 2 == 0) ans = ans2;
            if(q % 2 != 0 && k % 2 != 0) ans = ans1;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3552
/* 
	Author: ankrypt
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int
#define ff first
#define ss second
#define all(x) x.begin(), x.end() 
#define ub upper_bound
#define lb lower_bound
#define MAX_INT 200005
#define fi(a, b, c, d) for(int a = b; a < c; a += d)
#define fl(a, b, c, d) for(ll a = b; a < c; a += d)
#define fei(a, b, c, d) for(int a = b; a <= c; a += d)
#define fel(a, b, c, d) for(ll a = b; a <= c; a += d)
#define quit exit(0)

ll N, M, A, B, C;
ll arr[MAX_INT], arr1[MAX_INT], data[MAX_INT];
vector<ll> V;
map<ll, ll> mp;

int main() {
	scanf("%lld", &N);
	fi(i, 0, N - 1, 1) {
		scanf("%lld", &arr[i]);
		mp[arr[i]]++;
	}
	fei(i, 1, N, 1) {
		cout << mp[i] << "\n";
	}
	return 0;
}
/*
	Powered by Buggy Plugin
*/




Measured memory_bytes: 17732
K = int(input())
from collections import deque

queue = deque()
for i in range(1, 10):
    queue.appendleft(i)

for _ in range(K-1):
    p = queue.pop()
    if p%10!=0:
        queue.appendleft(p*10+p%10-1)
    queue.appendleft(p*10+p%10)
    if p%10!=9:
        queue.appendleft(p*10+p%10+1)

print(queue.pop())


Measured memory_bytes: 11908
#include <stdio.h>

int main(void)
{
	int h,w;
	int i,j;

	do{
		scanf("%d%d",&h,&w);
		if(h == 0	&&	w == 0)
		     break;
		
		for(i = 0;	h > i;	i++){
		      for(j = 0;	w > j;	j++){
			if(i == 0 || i == (h-1)  || j == 0 || j == (w-1))
			    	 printf("#");
			    else
				printf(".");
		    }
		      puts("");
		}
		puts("");
	}while(1);
	
	return(0);
}

Measured memory_bytes: 1016
#include <bits/stdc++.h>
#include <algorithm>
#define ull  long long int

using namespace std;
ull ceill (ull a , ull b)
{
  if(a%b==0)
  return a/b;
  else return (a/b + 1);
}

int main()
{
    ull a,b,c,d;
    cin>>a>>b>>c>>d;
    ull range=b-a+1;
    ull lcm=(c*d)/__gcd(c,d);
    ull ans = range-(1 + (b/d-ceill(a,d)) + (b/c-ceill(a,c)) - (b/lcm-ceill(a,lcm)));
    cout<<ans;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int age = sc.nextInt();
		if(age == 1) {
			System.out.println("Hello World");
		}else if(age == 2) {
			System.out.println(sc.nextInt() + sc.nextInt());
		}
	}
}

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


int main() {
#ifdef HOME
    freopen("in", "r", stdin);
#endif

    int n;
    while (scanf("%d", &n) == 1) {
        vector<int> a(n);
        for (int i = 0; i < n; i++) scanf("%d", &a[i]);
        ll all = 1;
        ll odd = 1;
        for (int i = 0; i < n; i++) {
            all *= 3;
            if (a[i] % 2 == 0) odd *= 2;
        }
        cout << all - odd << endl;
    }

#ifdef HOME
    cerr << clock() / (double)CLOCKS_PER_SEC << endl;
#endif
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var a, b, n int
	fmt.Scanf("%d %d %d", &a, &b, &n)

	x := n
	if n > b-1 {
		x = b - 1
	}

	fmt.Printf("%d\n", (a*x)/b-a*(x/b))
}


Measured memory_bytes: 1816
#include<stdio.h>

int main(void){
  int d;
  scanf("%d", &d);
  switch(d){
    case 22: puts("Christmas Eve Eve Eve"); break;
    case 23: puts("Christmas Eve Eve"); break;
    case 24: puts("Christmas Eve"); break;
    case 25: puts("Christmas"); break;
  }
  return 0;
}

Measured memory_bytes: 128
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(all(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define PII         pair<int, int>
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;

mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for(auto &x : a){
        cin >> x;
    }
    int mx = *max_element(ALL(a));
    int mn = *min_element(ALL(a));
    int ans = INT_MAX;
    for(int i = mn; i <= mx; i++){
        int p = i;
        int cur = 0;
        for(auto x : a){
            cur += (p - x) * (p - x);
        }
        ans = min(ans, cur);
    }
    cout << ans;
    return 0;
}


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

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //-----------------------------------------
    int N;
    cin >> N;

    vector<int> F;
    F.resize(N);
    int sum = 0;
    rep(i, N)
    {
        cin >> F[i];
        sum += F[i];
    }
    
    int min = INT_MAX;
    for(int P=1;P<=100;++P)
    {
        int ans = 0;
        rep(i, N)
        {
            ans += (F[i]-P)*(F[i]-P);
        }
        if(ans < min)
        {
            min = ans;
        }
    }

    cout << min << endl;

    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

typedef struct {
	int gold;
	int wight;
} ISLAND;

int island_count;

int main(void)
{
	ISLAND island[25];
	int i;
	int j;
	int have;
	
	while (1){
		scanf("%d", &island_count);
		
		if (island_count == 0){
			break;
		}
		for (i = 0; i < island_count; i++){
			scanf("%d%d", &island[i].gold, &island[i].wight);
		}
		
		for (i = 0; i < island_count; i++){
			for (j = i + 1; j < island_count; j++){
				if (island[i].wight > island[j].wight){
					ISLAND temp;
					temp = island[i];
					island[i] = island[j];
					island[j] = temp;
				}
			}
		}
		
		have = 0;
		for (i = 0; i < island_count; i++){
			have += island[i].gold;
			if (have > island[i].wight){
				break;
			}
		}
		
		if (i == island_count){
			printf("Yes\n");
		}
		else {
			puts("No");
		}
	}
	
	return (0);
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 250200;
typedef long long ll;
const int mod = 998244353;
inline ll pow(ll a,int b,int ans = 1) {
	for(;b;b >>= 1,a = a * a % mod) if(b & 1)
		ans = ans * a % mod;
	return ans;
}
inline ll inverse(int x){ return pow(x, mod - 2); }
typedef std::pair<int,int> pr;
int n, x[maxn];
int ans[maxn];
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	std::vector<pr> v;
	rep(i, 1, n) cin >> x[i], v.emplace_back(x[i], i);
	std::sort(v.begin(), v.end());
	for(auto i:v){ 
		int c=1;
		if(i.second>1) for(int j = 1;j < i.first;++j)
			if(!ans[j]) if(ans[j]=i.second,++c==i.second) break;
		if(c!=i.second||ans[i.first])return cout<<"No"<<'\n',0;
		ans[i.first]=i.second;
	}
	std::reverse(v.begin(), v.end());
	for(auto i:v){ 
		int c = n-i.second;
		if(c) for(int j = n * n;j > i.first;--j)
			if(!ans[j]) if(ans[j]=i.second,--c==0) break;
		if(c)return cout<<"No"<<'\n',0;
	}
	cout<<"Yes"<<'\n';
	rep(i,1,n*n)cout<<ans[i]<<' ';
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;


int main(){
  int n; cin>>n;
  vector<P> x(n);
  rep(i,n){
    int X; cin>>X;
    x[i]={X,i};
  }
  sort(ALL(x));

  int t1=x[n/2].fs;
  int t2=x[n/2-1].fs;
  rep(i,n){
    x[i].fs=x[i].sc;
    if(i<n/2){
      x[i].sc=t1;
    }
    else{
      x[i].sc=t2;
    }
  }
  sort(ALL(x));
  rep(i,n){
    cout<<x[i].sc<<endl;
  }


  return 0;

}


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

int main() {
  string S;
  cin >> S;
  for(int i = 0; i < 3; i++) {
    if(S[i] == '1') S[i] = '9';
    else S[i] = '1';
  }
  cout << S << endl;
}

Measured memory_bytes: 256
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
#define ALL(X) X.begin(), X.end()
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef std::pair<LL,LL> PLL;//
typedef std::pair<int,int> PII;//
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int A,B;
	cin>>A>>B;
	cout << (A+B+1)/2 << endl;
}
#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

printList [a] = print a
printList (a:as) = putStr ( show a ) >> putChar ' ' >> printList as

main = do
	 n <- readInt
	 print $ length $ do
	 	a <- [ 1 .. n ]
		_ <- takeWhile ( \b -> a * b < n ) [ 1 .. n ]
		return ()

Measured memory_bytes: 3880
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int w, h;
  while (cin >> w >> h, w) {
    int si, sj;
    vs m(h);
    rep(i, h) {
      cin >> m[i];
      rep(j, m[i].size()) {
        if (m[i][j] == '@') {
          si = i;
          sj = j;
        }
      }
    }
    int c = 0;
    fn<void(int, int)> f = [&](int i, int j) {
      if (i < 0 || j < 0 || i >= h || j >= w || m[i][j] == '#') return;
      c++;
      m[i][j]  = '#';
      int di[] = {1, 0, -1, 0}, dj[] = {0, 1, 0, -1};
      rep(k, 4) f(i + di[k], j + dj[k]);
    };
    f(si, sj);
    cout << c << endl;
  }
}

Measured memory_bytes: 3028
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	int N=in();
	auto A=vecin(N);
	int ans=0,F=1;
	REP(i,N){
		if(A[i]==F){
			F++;
			ans++;
		}
	}
	out(ans==0?-1:N-ans);
	return 0;
}

Measured memory_bytes: 1024
n, m = map(int, input().split())
A = list(map(int, input().split()))
count = 0
total = 0
for j in range(n):
    total += A[j]
for i in range(n):
    if A[i] >= total *(1/(4*m)):
        count += 1
if count >= m:
    print("Yes")
else:
    print("No")

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

int64_t comb(int64_t a, int64_t b)
{
    if (b == 0)
        return 1;

    return a * comb(a - 1, b - 1) / b;
}

int main()
{
    int n, a, b;
    cin >> n >> a >> b;

    vector<int64_t> vs(n);
    for (auto &v: vs)
        cin >> v;

    sort(vs.rbegin(), vs.rend());

    double sum = 0;
    int64_t last = -1, last_cnt = 0;
    for (int i = 0; i < a; i++) {
        sum += vs[i];
        if (vs[i] == last) {
            last_cnt++;
        } else {
            last = vs[i];
            last_cnt = 1;
        }
    }

    if (last == vs[0]) {
        int c = 0;
        for (int i = 0; i < n; i++) {
            if (vs[0] == vs[i]) {
                c = i + 1;
            } else {
                break;
            }
        }

        int64_t pats = 0;
        for (int i = a; i <= min(b, c); i++) {
            pats += comb(c, i);
        }

        printf("%.10f\n", (double)vs[0]);
        printf("%lld\n", pats);
    } else {
        int c = 0;
        for (int i = 0; i < n; i++) {
            if (last == vs[i])
                c++;
        }

        int64_t pats = comb(c, last_cnt);

        printf("%.10f\n", sum / a);
        printf("%lld\n", pats);
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include <iomanip>
#include <math.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60
const double PI = 3.14159265358979323846;

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

	int N; cin >> N;
	queue<int> Q;
	for (int i = 0; i < N; i++) {
		int tmp; cin >> tmp; Q.push(tmp);
	}

	int ans = 0;
	int cnt = 1;
	while (!Q.empty())
	{
		int num = Q.front();
		Q.pop();
		if (num != cnt) ans++;
		else cnt++;
	}
	if (cnt == 1) cout << -1 << endl;
	else cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1152
/**************************************************************************
Coded by: Saba Karimi(_VINTAGE)
Institution: AIT PUNE
***************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define int long long int 
#define F first 
#define S second
/**************************************************************************/
const int N = 12;
int n,m;
int a[1000];
int chabhi[1000][12];
int bn[1000];
int dp[1<<N][1000];
int solve(int mask,int key)
{
    if(key == m)
    {
        if(mask == (1<<n)-1)
            return 0;
        return 1e18;
    }
    if(dp[mask][key]!=-1)
        return dp[mask][key];
    dp[mask][key] = 1e18;
    dp[mask][key] = min(dp[mask][key],solve(mask,key+1));
    dp[mask][key] = min(dp[mask][key],a[key]+solve(mask|bn[key],key+1));
    return dp[mask][key];
}
signed main()
{
    fast;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        cin>>a[i];
        int b;
        cin>>b;
        for(int j=0;j<b;j++)
        {
            int c;
            cin>>c;
            c--;
            chabhi[i][c] = 1;
        }
        int bits = 0;
        for(int j=0;j<12;j++)
        {
            bits+=(chabhi[i][j]*(1<<j));
        }
        bn[i] = bits;
    }
    memset(dp,-1,sizeof(dp));
    int ans = solve(0,0);
    if(ans == 1e18)
        cout<<-1;
    else cout<<ans;
}

Measured memory_bytes: 32384
def main():
    s = input()
    t = input()
    n,m = len(s),len(t)
    c = 0
    for i in range(n-m+1):
        cnt = 0
        for j in range(m):
            if s[i+j] == t[j]:
                cnt += 1
        if cnt > c:
            c = cnt
    print(m-c)

if __name__ == "__main__":
    main()


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

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

int main(){
    int h, w, k;
    cin >> h >> w >> k;
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    x1--, y1--, x2--, y2--;
    vector<string> field(h);
    rep(i,h) cin >> field[i]; 

    vector<vector<int>> dist(h, vector<int>(w, -1));
    dist[x1][y1] = 0;

    queue<pair<int, int>> que;
    que.push(make_pair(x1, y1));

    while(!que.empty()){
        pair<int, int> current_pos = que.front();
        int x = current_pos.first;
        int y = current_pos.second;
        que.pop();
        
        rep(d,4){
            rep(i, k){
                int next_x = x + (i+1)*dx[d];
                int next_y = y + (i+1)*dy[d];
                if(next_x < 0 || next_x >= h || next_y < 0 || next_y >= w) break;
                if(field[next_x][next_y] == '@') break;
                if(dist[next_x][next_y] <= dist[x][y] && dist[next_x][next_y] != -1) break;
                if(dist[next_x][next_y] != -1) continue;

                que.push(make_pair(next_x, next_y));
                dist[next_x][next_y] = dist[x][y] + 1;
            }
        }
    }

    /*for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cout << dist[i][j] << ' ';
        }
        cout << endl;
    }*/
 
    cout << dist[x2][y2] << endl;
}

Measured memory_bytes: 12152
// AtCoder-Template.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second
#define FOR(i,N) for(auto i=0; i<N; ++i)
#define FORREV(i,N,_cnt) for(auto i=N-1,cnt=_cnt; cnt > 0; --i, --cnt)
#define ALL(x) x.begin(), x.end()

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T& a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T& a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
	ifstream ifs("in.txt");
	cin.rdbuf(ifs.rdbuf());
#endif
	ll N; cin >> N;
	vector<ll> A(N); 	FOR(i, N) cin >> A[i];
	auto sum = accumulate(ALL(A), 0LL);
	FOR(i, N - 1) { 		A[i + 1] += A[i];
	}
	ll ans = abs(A[0]*2 - sum);
	FOR(i, N) {
		if (i == 0) continue; if (i == N - 1) continue;
		chmin(ans, abs(A[i] * 2 - sum));
	}
	cout << ans << endl;
	

	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
 
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int H, W;
  cin >> H >> W;
  char A[H+2][W+2] = {};
  for(int i=1;i<=H;i++){
    for(int k=1;k<=W;k++){
      cin >> A[i][k];
    }
  }
  bool ans = true;
  for(int i=1;i<=H;i++){
    for(int k=1;k<=W;k++){
      if(A[i][k] == '#'){
        if(A[i-1][k] == '#' || A[i+1][k] == '#' || A[i][k-1] == '#' || A[i][k+1] == '#'){
          continue;
        }
        else{
          ans = false;
        }
      }
    }
  }
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
typedef long long int ll;
using namespace std;
#define P 1000000007
#define rep(i,n) for(i=0;i<n;++i)
#define repp(i,a,n) for(i=a;i<n;++i)
#define repr(i,a,n) for(i=a;i>=n;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

ll binpowmod(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

ll modInverse(ll n, ll p)
{
    return binpowmod(n, p-2, p);
}

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t,m,n,i,f=0,j,ans=0,k,x,r;
    cin >> n ;
    for(i=1;i<=n;++i)
    {
        if(i%3==0||i%5==0) continue;
        ans+=i;
    }
    cout << ans ;
    
    
    return 0;
}


Measured memory_bytes: 3652
n = int(input())

evidences = [[] for _ in range(n)]
for i in range(n):
   a = int(input())
   for _ in range(a):
      x, y = map(int, input().split())
      evidences[i].append((x-1, y))

ans = 0
for i in range(1, 2**n):
   consistent = True
   for j in range(n):
      if (i >> j) & 1 == 0:
         continue

      for x, y in evidences[j]:
         if (i >> x)  & 1 != y:
            consistent = False
            break

      if not consistent:
         break

   if consistent:
      ans = max(ans, bin(i)[2:].count('1'))

print(ans)


Measured memory_bytes: 3064
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N;
	cin >> N;
	int dp[3][110] = { 0 };

	rep(i, 0, 2)rep(j, 0, N)
	{
		int res = 0;
		if (i > 0)chmax(res, dp[i - 1][j]);
		if (j > 0)chmax(res, dp[i][j - 1]);
		cin >> dp[i][j];
		dp[i][j] += res;
	}

	cout << dp[1][N - 1] << endl;

	return 0;
}

Measured memory_bytes: 256
N=int(input())
a_list=[]
for i in range(N):
    a_list.append(int(input()))

tmp=sorted(a_list)[::-1]
one=tmp[0]
two=tmp[1]
for i in range(len(a_list)):
    if a_list[i]==one:
        print(two)
    else:
        print(one)

Measured memory_bytes: 14160
#include<stdio.h>

int main() {
	int n,i,y,a,b,c,cnt=0,d=0,e=0,f=0;
	
	scanf("%d %d", &n, &y);
	
		for (a = 0; a <= n; a++) 
			for (b = 0; b <= n-a; b++){ 
				 c=n-a-b;
					if ( 10000 * a + 5000 * b + 1000 * c == y) {
						printf("%d %d %d", a, b, c);
						cnt++;
						return 0;
					}
            }


				
			
		
	
	if (cnt == 0)printf("%d %d %d", -1, -1, -1);
	
	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#define LEN 100005

typedef struct pp{
  char name[1000];
  int t;
}P;

P dequeue (void);
void enqueue (P);
int min(int,int);

P Q[LEN+1];
int head,tail,n;

int main(){
  int i,q,c,elaps=0;
  P u;
  scanf("%d %d",&n,&q);
  for(i=1;i<=n;i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].t);
  }
  head=1;
  tail=n+1;
  while(head!=tail){
    u=dequeue();
    c=min(q,u.t);
    u.t -= c;
    elaps += c;
    if(u.t>0){
      enqueue(u);
    }
    else{
      printf("%s %d\n",u.name,elaps);
    }
  }
  return 0;
}

P dequeue(void){
  P x=Q[head];
  head=(head+1)%100000;
  return x;
}

void enqueue(P x){
  Q[tail]=x;
  tail=(tail+1)%100000;
}

int min(int a,int b){
  return a<b?a:b;
}


Measured memory_bytes: 99748
#include <stdio.h>

void sum(int);

int main(void)
{
    int n;
    
    while (scanf("%d", &n) != EOF){
                
        sum(n);
        printf("\n");
    }

    return (0);
}

void sum(int n){
    int i,j;
    int sum;
    int count;
    int w[10] = {1,2,4,8,16,32,64,128,256,512};
    int num[10] = {0};

    sum = 0;
    for (i = 9; i>= 0; i--){
        if (w[i] < n){
            sum += w[i];
            num[i] = 1;
            if (sum > n){
                sum -= w[i];
                num[i] -= 1;
            }else if (sum == n){
                break;
            }
        }else if (w[i] == n){
            num[i] = 1;
            break;
        }
    }
    count = 0;
    for (i = 0; i < 10; i++){
        if (num[i] == 1){
            if (count == 0){
                printf("%d", w[i]);
                count++;
            }else{
                printf(" %d", w[i]);
            }
        }
    }
    return;
}


Measured memory_bytes: 2024
import itertools 
import math

def length(x1, y1, x2, y2):
  return math.sqrt((x1-x2)**2+(y1-y2)**2)

n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
num = [i for i in range(n)]
li = list(itertools.permutations(num))
ans = 0
for per in li:
  for i in range(len(per)-1):
    ans += length(xy[per[i]][0], xy[per[i]][1], xy[per[i+1]][0], xy[per[i+1]][1])

print(ans/len(li))

Measured memory_bytes: 7972
#include<iostream>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;

main(){
    string s;
    cin>>s;
    int n=s.size();
    int memo=s[0];
    int ans=n;
    for(int i=0;i<n;i++){
        if(memo!=s[i]){
            if(ans>max(i,n-i)) ans=max(i,n-i);
        }
        memo=s[i];
    }
    cout<<ans;
    return 0;
}

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

int main() {
    int n; cin >> n;
    int f, a, t;
    double x, y;
    cin >> f >> a >> t >> x >> y;
    double T[2] = {-1, -1}, L[2] = {-1, -1};
    for(int i = 1; i < n; i++) {
        int f_, a_, t_;
        double x_, y_;
        cin >> f_ >> a_ >> t_ >> x_ >> y_;
        if(t == t_ && a != a_) {
            double len = (x - x_) * (x - x_) + (y - y_) * (y - y_);
            double flames = f_ - f;
            if(L[t] < len) {
                L[t] = len;
                T[t] = flames;
            } else if (L[t] == len && T[t] > flames) {
                T[t] = flames;
            }
        }
        f = f_, a = a_, t = t_, x = x_, y = y_;
    }
    if(L[0] > 0)
        printf("%.8f %.8f\n", sqrt(L[0]), (T[0] / 60));
    else
        cout << -1 << " " << -1 << endl;
    if(L[1] > 0)
        printf("%.8f %.8f\n", sqrt(L[1]), (T[1] / 60));
    else
        cout << -1 << " " << -1 << endl;

    return 0;
}

Measured memory_bytes: 1296
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdlib>
#include <algorithm>

using namespace std;
int main() {
    int n;
    string s;
    cin >> n >> s;

    if (n >= 3200) {
        cout << s;
    }
    else
    {
        cout << "red";
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
const ll INF=1LL<<30;
const ll LINF=1LL<<61;
const double eps=1e-9;
const ll MOD=1e9+7;
int main(){
    ll n,p;cin>>n>>p;
    ll ans=1;
    ll e=sqrt(p);
    for(ll i=2;i<=e+1;i++){
        ll co=0;
        while(p%i==0){
            p/=i;
            co++;
        }
        if(co>=n){
            for(ll j=0;j<(co/n);j++)ans*=i;
        }
    }
    if(n==1)ans*=p;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define all(v) v.begin(),v.end()
#define mem(v,x) memset(v,x,sizeof(v))
#define N 200005

using namespace std;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	int n,W;
	cin>>n>>W;
	int w[n+1];
	ll v[n+1];
	for(int i=1;i<=n;i++){
        cin>>w[i]>>v[i];
	}
	ll dp[n+1][W+1];
	mem(dp,0);
	for(int i=1;i<=n;i++){
        for(int j=1;j<=W;j++){
            if(w[i]<=j){
                dp[i][j] = max({dp[i][j], v[i]+dp[i-1][j-w[i]], dp[i-1][j]});
            }
            else{
                dp[i][j] = max(dp[i][j], dp[i-1][j]);
            }
        }
	}
	cout<<dp[n][W];
	return 0;
}


Measured memory_bytes: 79232
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v, w, c; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;
int INF = INT_MAX / 100;

int f(int v, vector<int>& p, vector<bool>& m) {
	if (m[v]) return v;
	return p[v] = f(p[v], p, m);
}

int main() {
	for (;;) {
		int N, Q; cin >> N >> Q;
		if (N == 0) break;
		vector<int> p(N + 1);
		for (int i = 2; i <= N; i++)
			cin >> p[i];
		vector<bool> m(N + 1);
		m[1] = true;
		vector<string> q; vector<int> v;
		while (Q--) {
			string s; int x; cin >> s >> x;
			if (s == "M") {
				if (m[x]) continue;
				m[x] = true;
			}
			q.push_back(s);
			v.push_back(x);
		}
		ll sum = 0;
		for (int i = q.size() - 1; i >= 0; i--) {
			if (q[i] == "M")
				m[v[i]] = false;
			else if (q[i] == "Q")
				sum += f(v[i], p, m);
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 6844
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
void LinearSearch(unsigned int p[], unsigned int key, unsigned int*,unsigned int);
int main() {
	unsigned int n, S[10000] = { 0 }, T[500] = { 0 }, q, i, cnt = 0;
	unsigned int *p, *key;
	p = S; key = T;
	scanf("%d", &n);
	for (i = 0; i < n; i++) scanf("%d", p + i);
	scanf("%d", &q);
	for (i = 0; i < q; i++) scanf("%d", key + i);
	for (i = 0; i < q; i++) LinearSearch(p, *(key + i), &cnt,n);
	printf("%d\n", cnt);
	return 0;
}

void LinearSearch(unsigned int p[], unsigned int key, unsigned int *cnt, unsigned int n){
	unsigned int i;
	for (i = 0; i < n; i++) if (*(p + i) == key) { *(cnt) += 1; break; }
}

Measured memory_bytes: 648
N = int(input())
B = list(map(int,input().split()))

ans = []
while B:
    for i in range(len(B)-1, -1, -1):
        b = B[i]
        if i == b-1:
            ans.append(i+1)
            break
    else:
        print(-1)
        exit()
    del B[i]
print(*list(reversed(ans)),sep='\n')

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

int main(){
  int N,A,B;
  cin >> N >> A >> B;
  int sum=0;
  int SUM=0;
  string s;
  for(int i=1;i<=N;i++){
    s=to_string(i);
    for(char c:s){
      sum+=c-48;
    }
    if((sum<=B)&&(sum>=A)){
      SUM+=i;
    }
    sum=0;
  }
  cout << SUM << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.{BufferedReader, InputStream, InputStreamReader, PrintWriter}
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Sorting
import math.{abs, max, min}
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.reflect.ClassTag

object Main {
  val MOD = 1000000007
  val out = new PrintWriter(System.out)
  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N = sc.nextInt()
    val A, B = map(N) { _ =>
      val x, y = sc.nextInt()
      (x, y)
    }

    Sorting.quickSort(B)(Ordering.by(_._1))
    val used = Array.ofDim[Boolean](N)

    def step(i: Int, cnt: Int): Int = {
      if (i == N) cnt
      else {
        val (bx, by) = B(i)
        val filtered = A.zipWithIndex.filter {
          case ((ax, ay), j) => !used(j) && ax < bx && ay < by
        }
        filtered.maxByOpt(_._1._2) match {
          case Some((_, j)) =>
            used(j) = true
            step(i + 1, cnt + 1)

          case None => step(i + 1, cnt)
        }
      }
    }
    val ans = step(0, 0)

    out.println(ans)
  }


  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = null

    def next: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next.toInt
    def nextLong(): Long = next.toLong
    def nextChar(): Char = next.charAt(0)
  }

  private def rep(n: Int)(f: Int => Unit): Unit = {
    var i = 0
    while(i < n) {
      f(i)
      i += 1
    }
  }

  private def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    var i = 0
    while(i < n) {
      res(i) = f(i)
      i += 1
    }
    res
  }

  private implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {
    def maxByOpt[B: Ordering](f: A => B): Option[A] = {
      if (as.nonEmpty) Some(as.maxBy(f)) else None
    }
  }
}


Measured memory_bytes: 27320
N=gets.to_i
ps=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47]
def com(n,k)
  return 0 if n<=0 || k<=0
  k=n-k if 2*k > n
  return 1 if k == 0
  ((n-k+1)..n).reduce(&:*)/((1..k).reduce(&:*))
end
hs=Hash.new{0}
for i in 1..N
  ps.each do |e|
    a=i
    while true
      break if a%e!=0
      a/=e
      hs[e]+=1
    end
  end
end
ns=Array.new(105,0)
ps.each do |e|
  hs[e].times do |i|
    ns[i+1]+=1
  end
end
puts com(ns[4],2)*com(ns[2]-2,1)+com(ns[14],1)*com(ns[4]-1,1)+com(ns[24],1)*com(ns[2]-1,1)+com(ns[74],1)


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




int main(){
  int n,m;
  cin >>n >>m;
  vector<int>s(n);
  for(int i=0;i<m;i++){
    int a,b;
    cin >> a>>b;
    if(a==1||b==1){
      s.at(max(a,b))++;        
    }
    if(a==n||b==n){
      s.at(min(a,b))++;
    }
  }
  for(int i=0;i<n;i++){
    if(s.at(i)==2){
      cout <<"POSSIBLE";
      return 0;
    }
  }
  cout << "IMPOSSIBLE";
  
    
}

Measured memory_bytes: 1024