akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define MOD 100000007LL
using namespace std;

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

typedef string::const_iterator State;
int expression(State &begin);

int data[8];
int used[8];
int res;
map<char,int> mp;
string keydata="01()+-*=";


int expression(State &begin);
int number(State &begin){
	int ret=0;
	while(isdigit(*begin)){
		ret*=2;
		ret+=*begin-'0';
		begin++;
	}
	return ret;
}

int factor(State &begin){
	if(*begin=='-'){
		int pm=1;
		while(*begin=='-'){
			begin++;
			pm*=-1;
		}
		int ret;
		if(*begin=='('){
			begin++;
			ret=pm*expression(begin);
			begin++;
		}else{
			ret=pm*number(begin);
		}
		return ret;
	}else if(*begin=='('){
		begin++;
		int ret=expression(begin);
		begin++;
		return ret;
	}else{
		return number(begin);
	}
}

int term(State &begin){
	int ret=factor(begin);
	while(1){
		if(*begin=='*'){
			begin++;
			ret*=factor(begin);
		}else break;
	}
	return ret;
}

int expression(State &begin){
	int ret=term(begin);
	while(1){
		if(*begin=='+'){
			begin++;
			ret+=term(begin);
		}else if(*begin=='-'){
			begin++;
			ret-=term(begin);
		}else break;
	}
	return ret;
}

bool check(string s){
	int cc=0;
	bool bnum=false;
	for(int i=0;i<s.size();i++){
		if(s[i]=='-'){
			if(i+1==s.size())return false;
			if(i==0)continue;
		}
		if(s[i]=='+' || s[i]=='*'){
			if(i==0 || i+1==s.size())return false;
			if(!(isdigit(s[i-1]) || s[i-1]==')'))return false;
		}
		if(s[i]=='('){
			cc++;
			if(i+1==s.size())return false;
			if(i>=1 && (s[i-1]==')' || isdigit(s[i-1])))return false;
		}
		if(isdigit(s[i])){
			if(i>=1 && (s[i-1]==')'))return false;
			if(s[i]=='0'){
				if(i>=1 && isdigit(s[i-1]))continue;
				if(i<s.size() && isdigit(s[i+1]))return false;
			}
		}
		if(s[i]==')'){
			if(cc==0)return false;
			if(s[i-1]=='(')return false;
			if(!(s[i-1]==')' || isdigit(s[i-1])))return false;
			cc--;
		}
	}
	if(cc!=0)return false;
	return true;
}

string str;

void dfs(int v){
	if(v==mp.size()){
		string tmp="";
		for(int i=0;i<str.size();i++){
			if((str[i]>='a' && str[i]<='z') ||(str[i]>='A' && str[i]<='Z')){
				int va=mp[str[i]];
				tmp+=keydata[data[va-1]];
			}else{
				tmp+=str[i];
			}
		}
		string s1="";
		string s2="";
		bool eq=false;
		for(int i=0;i<tmp.size();i++){
			if(tmp[i]=='='){
				if(eq)return;
				eq=true;
			}else{
				if(!eq)s1+=tmp[i];
				else s2+=tmp[i];
			}
		}
		if(!check(s1) || s1.size()==0)return;
		if(!check(s2) || s2.size()==0)return;
		State s=s1.begin();
		int val=expression(s);
		s=s2.begin();
		int val2=expression(s);
		if(val==val2){
			res++;
		}
	}else{
		for(int i=0;i<8;i++){
			if(used[i]==0){
				used[i]=1;
				data[v]=i;
				dfs(v+1);
				used[i]=0;
			}
		}
	}
}

int main(void){
	cin >> str;
	for(int i=0;i<str.size();i++){
		if((str[i]>='a' && str[i]<='z') ||(str[i]>='A' && str[i]<='Z')){
			if(mp.find(str[i])==mp.end()){
				mp[str[i]]=mp.size();
			}
		}
	}
	dfs(0);
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 3356
import numpy as np
n = int(input())

x = [0] * n
y = [0] * n
for i in range(n):
    x[i], y[i] = map(int, input().split())

cnt = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        cnt += np.sqrt((x[i] - x[j]) ** 2 + (y[i] - y [j]) ** 2)
        
ans = cnt * 2 / n

print(ans)

Measured memory_bytes: 12732
// Problem: C - Sum of product of pairs
// Contest: AtCoder - AtCoder Beginner Contest 177
// URL: https://atcoder.jp/contests/abc177/tasks/abc177_c
// Parsed on: 2020-08-29 17:30:03
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

#define fastio  ios_base::sync_with_stdio(false); cin.tie(0);

using namespace std;

int main()
{
	using ll = unsigned long long;
	ll n;
	cin>>n;
	vector<ll> arr(n);
	for(auto&e : arr) cin >> e;
	vector<ll> suffix(n);
	suffix[n-1] = arr[n-1];
	for(int a = n-2; a >= 0; a--){
		suffix[a] = (suffix[a+1]%1000000007 + arr[a])%1000000007;
	}
	
	ll ans = 0;
	for(int a=0;a<n-1;a++)
	{
		ans = (ans%1000000007 + (arr[a]*suffix[a+1])%1000000007)%1000000007;
	}
	cout << ans;
	
	return 0;
}


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

int main() {
  int n, x;
  cin >> n >> x;
  vector<int> l(n);
  for(int i = 0; i < n; i++)
    cin >> l.at(i);
  
  vector<int> bound(n+1);
  bound.at(0) = 0;
  int ans = 1;
  for(int i = 1; i < n+1; i++) {
    bound.at(i) = bound.at(i-1) + l.at(i-1);
    if(bound.at(i) <= x) {
      ans++;
    }
  }
  cout << ans << endl;
}


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

struct tree {
	int key, parent, left, right;
};

void setChildrenAndParent(std::vector<tree> &v, int tree_num) {
	for (int i = 1; i <= tree_num; i++) {
		if (i * 2 <= tree_num) {
			v[i].left = v[i * 2].key;
			v[i * 2].parent = v[i].key;
		}
		if (i * 2 + 1 <= tree_num) {
			v[i].right = v[i * 2 + 1].key;
			v[i * 2 + 1].parent = v[i].key;
		}
	}
}

int main() {
	int node_num;

	std::cin >> node_num;
	std::vector<tree> v(node_num + 1);
	for (int i = 1; i <= node_num; i++) {
		int number;
		std::cin >> number;
		v[i].key = number;
		v[i].parent = 3000000;
		v[i].left = 3000000;
		v[i].right = 3000000;
	}

	setChildrenAndParent(v, node_num);

	for (int i = 1; i <= node_num; i++) {
		std::cout << "node " << i << ": ";
		std::cout << "key = " << v[i].key << ", ";
		if (v[i].parent != 3000000) std::cout << "parent key = " << v[i].parent << ", ";
		if (v[i].left != 3000000) std::cout << "left key = " << v[i].left << ", ";
		if (v[i].right != 3000000) std::cout << "right key = " << v[i].right << ", ";
		std::cout << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1196
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
char st[1005],x[1005],y[1005];
int n,color[1005];
long long dp[105][105],ans;
void dfs(int t)
{
	if (t>n)
	{
		int len1=0,len2=0;
		for (int i=1;i<=n;i++)
			if (color[i]==1)
				x[++len1]=st[i];
		for (int i=1;i<=n;i++)
			if (color[i]==2)
				y[++len2]=st[i];
		dp[0][0]=1;
		for (int i=0;i<=n-len1;i++)
			for (int j=0;j<=n-len2;j++)
			{
				if (i+j==0) continue;
				dp[i][j]=0;
				if (i>=1 && st[n+n-i-j+1]==y[i]) dp[i][j]+=dp[i-1][j];
				if (j>=1 && st[n+n-i-j+1]==x[j]) dp[i][j]+=dp[i][j-1];
			}
		ans+=dp[n-len1][n-len2];
		return;
	}
	color[t]=1;
	dfs(t+1);
	color[t]=2;
	dfs(t+1);
}
int main()
{
	scanf("%d",&n);
	scanf("%s",st+1);
	dfs(1);
	printf("%lld\n",ans);
	return 0;
}


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

class C {
    static void Main(string[] args) {
        int N = int.Parse(Console.ReadLine());

        var A = Console.ReadLine().Split().Select(int.Parse).ToArray();

        if (A.Distinct().Count() == N) {
            Console.WriteLine("YES");
        } else {
            Console.WriteLine("NO");
        }

    }
}

Measured memory_bytes: 42824
#include<set>
#include<map>
#include<stack>
#include<ctime>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<climits>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
LL read(){
	bool f=0;LL x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return !f?x:-x;
}
#define MAXN 100000
#define INF 0x3f3f3f3f
struct Query{
	int opt,u,v;
}Q[MAXN+5];
int fa[MAXN+5];
inline int Find(int x){return fa[x]==x?x:(fa[x]=Find(fa[x]));}
int main(){
	//freopen("tour.in","r",stdin);
	//freopen("tour.out","w",stdout);
	LL n=read(),m=read(),q=read();
	for(int i=0;i<n;i++)
		fa[i]=i;
	for(int t=1;t<=q;t++){
		int u=read(),v=read(),opt=read();
		Q[t]=(Query){opt,u,v};
	}
	int cnt=0,s=n;
	for(int t=1;t<=q;t++)
		if(Q[t].opt==0){
			int fu=Find(Q[t].u),fv=Find(Q[t].v);
			if(fu!=fv)
				fa[fu]=fv,s--;
		}
	for(int t=1;t<=q;t++)
		if(Q[t].opt==1){
			cnt++;
			int fu=Find(Q[t].u),fv=Find(Q[t].v);
			if(fu==fv){
				puts("No");
				return 0;
			}
		}
	if(cnt==0)
		puts((n-1<=m&&m<=n-s+1ll*s*(s-1)/2)?"Yes":"No");
	else puts((n<=m&&m<=n-s+1ll*s*(s-1)/2)?"Yes":"No");
    return 0;
}


Measured memory_bytes: 1792
n=int(input())
x=list(input().split())
for i in range(n):
  x[i]=int(x[i])
xsort=sorted(x)
flag=0
for i in range(n):
  if x[i]!=xsort[i]:
    flag+=1

if flag==0 or flag==2:
  print('YES')
else:
  print('NO')

Measured memory_bytes: 38384
#include<iostream>
using namespace std;
int main()
{
    int a, b;
    cin >> a >> b;

    int result;
  
    if (a >= 13) result = b;
    else if (a >= 6) result = b/2;
    else result = 0;
  
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5+5;
int n;
int h[maxN];
int f[maxN];
int main() {
    cin >> n;
    for(int i = 1; i <= n; ++i) cin >> h[i];
    f[1] = 0;
    f[2] = abs(h[1] - h[2]);
    for(int i = 3; i <= n; ++i)
        f[i] = min(f[i-1]+abs(h[i-1]-h[i]), f[i-2]+abs(h[i-2]-h[i]));
    cout << f[n] << endl;
}


Measured memory_bytes: 1024
import java .util.*;		
class Main {
	public static void main(String...args) {
		Scanner scan = new Scanner(System.in);
		String[] diceNum = scan.nextLine().split(" ");
		String[] commands = scan.nextLine().split("");
		String[] copyDiceNum = new String[6];
		for(int i = 0; i < commands.length; i++ ) {

			switch(commands[i]) {

				case "N":
					System.arraycopy(diceNum , 0 ,copyDiceNum ,0 ,6);
					diceNum[0] = copyDiceNum[1];
					diceNum[1] = copyDiceNum[5];
					diceNum[2] = copyDiceNum[2];
					diceNum[3] = copyDiceNum[3];
					diceNum[4] = copyDiceNum[0];
					diceNum[5] = copyDiceNum[4];
				break;
				case "S":
					System.arraycopy(diceNum , 0 ,copyDiceNum ,0 ,6);
					diceNum[0] = copyDiceNum[4];
					diceNum[1] = copyDiceNum[0];
					diceNum[2] = copyDiceNum[2];
					diceNum[3] = copyDiceNum[3];
					diceNum[4] = copyDiceNum[5];
					diceNum[5] = copyDiceNum[1];
				break;
				case "W":
					System.arraycopy(diceNum , 0 ,copyDiceNum ,0 ,6);
					diceNum[0] = copyDiceNum[2];
					diceNum[1] = copyDiceNum[1];
					diceNum[2] = copyDiceNum[5];
					diceNum[3] = copyDiceNum[0];
					diceNum[4] = copyDiceNum[4];
					diceNum[5] = copyDiceNum[3];
				break;
				case "E":
					System.arraycopy(diceNum , 0 ,copyDiceNum ,0 ,6);
					diceNum[0] = copyDiceNum[3];
					diceNum[1] = copyDiceNum[1];
					diceNum[2] = copyDiceNum[0];
					diceNum[3] = copyDiceNum[5];
					diceNum[4] = copyDiceNum[4];
					diceNum[5] = copyDiceNum[2];
				break;
			}
		}
		System.out.println(diceNum[0]);
	}
}


Measured memory_bytes: 26252
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,k,x;
  cin >> n >> k;
  x=n/k;
  cout << min({n-k*x,abs(n-k*(x+1))}) << endl;
}

Measured memory_bytes: 256
# ABC155B

def f(a):
    for i in a:
        if i % 2 == 0 and (i % 3 != 0 and i % 5 != 0):
            print('DENIED')
            break
    else:
        print('APPROVED')

n = int(input())
a = list(map(int, input().split()))
f(a)


Measured memory_bytes: 9128
#include<bits/stdc++.h>
#define N 100
using namespace std;
string s[N];
int n,y;
 
int dfs(int x){
  int res;
  if('0'<=s[y][x]&&s[y][x]<='9')
    return s[y][x]-'0';
  if(s[y][x]=='+'){
    res=0;
    while(x+2<=s[y+1].size())
      y++,res+=dfs(x+1);
  }
  if(s[y][x]=='*'){
    res=1;
    while(x+2<=s[y+1].size())
      y++,res*=dfs(x+1);
  }
  return res;
}
 
int main(){
  while(1){
    cin>>n;
    if(!n)break;
    for(int i=0;i<N;i++)s[i]="";
    for(int i=0;i<n;i++)
      cin>>s[i];
    y=0;
    cout<<dfs(0)<<endl;
  }
  return 0;
}

Measured memory_bytes: 3120
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <utility>
#include <numeric>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <limits>
#include <cassert>
#include <bitset>

#define for0(i, N)    for (int i = 0  ; i <  (N); ++i)
#define for1n(i, N)   for (int i = 1  ; i <= (N); ++i)
#define for1(i, N)    for (int i = 1  ; i <  (N); ++i)
#define forn(i, N)    for (int i = 0  ; i <= (N); ++i)
#define forx(i, N, x) for (int i = (x); i <  (N); ++i)
#define forl(i, N, x, a) for (int i = (x), a = 0; a < (N);  \
                              i = (i + 1) % (N), ++a)

template<size_t i>
std::bitset<i> operator++(std::bitset<i> b, int){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    return b = (unsigned long long)b + 1;
}

template<size_t i>
std::bitset<i> operator++(std::bitset<i> b){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    auto temp = b;
    b++;
    return temp;
}

template<size_t i>
std::bitset<i> operator--(std::bitset<i> b, int){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    return b = (unsigned long long)b - 1;
}

template<size_t i>
std::bitset<i> operator--(std::bitset<i> b){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    auto temp = b;
    b--;
    return temp;
}

using namespace std;

typedef long long ll;
typedef long double ld;
typedef priority_queue<ll> pq;
typedef priority_queue<ll,vector<ll>, greater<ll>> pql;
typedef stack<ll> stk;
typedef queue<ll> qu;
typedef pair<ll, ll> pll;
typedef map<ll, ll> mll;
typedef unordered_map<ll, ll> umll;
typedef set<ll> sll;
typedef unordered_set<ll> usll;


int main(void){
    cin.tie(0); ios::sync_with_stdio(false);
    ll n;
    cin >> n;

    if (n & 1) {
        cout << 0;
        return 0;
    }

    ll x = n / 2;

    ll result = 0;

    while (x) {
        result += x / 5;
        x /= 5;
    }

    cout << result;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void){
    int x,x2,a,i,count;
    a = count = 0;
    scanf("%d\n",&x);
    for (i = 0; i < x; i++){
        scanf("%d\n",&x2);
        if (a == 0){
            a = x2;
        }
        if (a <= x2){
            count++;
            a = x2;
        }
    }
    printf("%d",count);
    return 0;
}

Measured memory_bytes: 128
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    a = LI()
    t = max(a)
    m = -1
    r = -1
    for c in a:
        if min(c,t-c) > m and c != t:
            r = c
            m = min(c,t-c)

    return '{} {}'.format(t,r)


print(main())




Measured memory_bytes: 16764
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

ll d[55][2555];

void Main() {
  ll n,m,s;
  cin >> n >> m >> s;
  s=min(s,2500LL);
  vector<PP> v[n];
  rep(i,m) {
    ll x,y,a,b;
    cin >> x >> y >> a >> b;
    x--,y--;
    v[x].pb(PP(y,P(a,b)));
    v[y].pb(PP(x,P(a,b)));
  }
  P a[n];
  rep(i,n) cin >> a[i].F >> a[i].S;
  priority_queue<PP,vector<PP>,greater<PP> > que;
  rep(i,n)rep(j,2555) d[i][j]=MAXL;
  d[0][s]=0;
  que.push(PP(0,P(0,s)));
  while(!que.empty()) {
    PP p=que.top();que.pop();
    ll x=p.S.F,c=p.F,k=p.S.S;
    if(d[x][k]<c) continue;
    if(k+a[x].F<=2500&&d[x][k+a[x].F]>c+a[x].S) {
      d[x][k+a[x].F]=c+a[x].S;
      que.push(PP(c+a[x].S,P(x,k+a[x].F)));
    }
    rep(i,v[x].size()) {
      ll y=v[x][i].F,cc=v[x][i].S.S;
      if(k>=v[x][i].S.F&&d[y][k-v[x][i].S.F]>c+cc) {
        d[y][k-v[x][i].S.F]=c+cc;
        que.push(PP(c+cc,P(y,k-v[x][i].S.F)));
      }
    }
  }
  REP(i,1,n) {
    ll ans=MAXL;
    rep(j,2555) ans=min(ans,d[i][j]);
    pr(ans);
  }
}

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


Measured memory_bytes: 7272
def main():
    n = int(input())

    c = 1
    while c * c <= 8 * n + 1:
        if c * c == 8 * n + 1:
            break
        c += 1
    else:
        print("No")
        exit()

    k, cnt = (c+1) // 2, 1
    ans = [set() for i in range(k)]
    for i in range(k):
        for j in range(i+1, k):
            ans[i].add(cnt)
            ans[j].add(cnt)
            cnt += 1

    print("Yes")
    print(k)
    for i in range(k):
        print(len(ans[i]), end=" ")
        for j in ans[i]:
            print(j, end=" ")
        print()


if __name__ == '__main__':
    main()


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

set<string> resultList;
int k = 0;
void subString(string s, int n)
{
    for (int i = 0; i < n; i++){
        string sub;
        for (int len = 1; len <= n - i && len <= k; len++){
            int end = i + len - 1;
            sub += s[end];
            resultList.insert(sub);
        }
    }
}

int main() {
    set<string>::iterator it;
    string s = "";
    cin >> s;
    cin >> k;
    if(s.length() == 1)
        cout << s << endl;
    else{
        subString(s, s.length());
        string fini = "";
        int counter = 1;
        for(it = resultList.begin(); it != resultList.end(); ++it){
            if(counter == k){
                fini = *it;
                it = resultList.end();
            }
            counter++;
        }
        cout << fini << endl;
    }


    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
int main() {
  int n, k, s = 0;
  cin >> n >> k;
  vector<int> p(n);
  for (int i=0; i<n; i++) {
    cin >> p[i];
  }
  sort(p.begin(), p.end());
  for (int i=0; i<k; i++) {
    s += p[i];
  }
  cout << s << endl;
}

Measured memory_bytes: 3172
n,maxw=map(int,input().split())
nap=[0]*n
for i in range(n):
    nap[i]=list(map(int,input().split()))
dp=[[0]*(maxw+1) for _ in range(n)]
for i in range(n):
    for j in range(maxw+1):
        if nap[i][0]>j:
            dp[i][j]=dp[i-1][j]
        else:
            dp[i][j]=max(dp[i-1][j],dp[i-1][j-nap[i][0]]+nap[i][1])
print(dp[n-1][maxw])

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

int main() {
    int N,K,a,r=1;
    cin >> N >> K;
    rep(i,N)
        cin >> a;
    
    r += (N-K)/(K-1);
    if((N-K)%(K-1))
        r++;
    cout << r << endl;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

ll modpow(ll a, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

mint C(ll n, ll r) {
  mint res = 1;
  rep(i, r) res *= n-i;
  rep(i, r) res /= i+1;
  return res;
}

int main()
{
  ll n, a, b;
  cin >> n >> a >> b;
  mint ans = modpow(2, n);
  ans -= C(n, a) + C(n, b) + 1;
  cout << ans.x << endl;
}

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

#define REP(i, n) for(int i=0; i<n;i++)
#define REPR(i, n) for(int i=n-1 ; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)

#define INF 2e9
#define ll long long

int main(){
    int k, s;
    cin>>k>>s;
    int ans = 0;
    int x, y, z;
    for(x=0; x<=k; x++){
        for(y=0; y<=k; y++){
            z = s - x - y;
            if(0<=z && z<= k){
                ans++;
            }
        }
    }

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

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

#define int long long
#define pb emplace_back
#define f(i,n) for(int i=0 ; i<n ; i++)
#define F first
#define S second
#define fast ios:: sync_with_stdio(false),cin.tie(0);

int32_t main(){
	fast;
	int n;  cin >> n;
	vector<pair<int,int>>v(n);
	f(i,n) cin >> v[i].S >> v[i].F;
	
	sort(v.begin(),v.end());
	
	int current = 0;
	for(int i=0 ;i<n ; i++)
	{
		if(current + v[i].S > v[i].F)
		{
			cout << "No";
			return 0;
		}
		
		current += v[i].S;
	}
	cout << "Yes";
}







Measured memory_bytes: 3328
#include <stdio.h>
int T,F,R,c,a,t;char s[9];
main()
{
for(;c+21&&scanf("%s",s);a+=T)
c=*s-69,
c<0?a&&printf("%d\n",a),a=0,T=1,F=2,R=3:0,
c==9?t=T,T=F,F=7-t:0,
c==14?t=F,F=T,T=7-t:0,
!c?t=R,R=T,T=7-t:0,
c==18?t=T,T=R,R=7-t:0,
c==13?t=F,F=R,R=7-t:0,
c==7?t=R,R=F,F=7-t:0;
}

Measured memory_bytes: 0
import java.util.*; 
class Main
{
public static void main(String []args) 
{
Scanner sc = new Scanner(System.in); 
char c = sc.next().charAt(0); 

if(c>='a' && c<='z') 
{
System.out.println("a");
}
else 
{
System.out.println("A");
}
}
}


Measured memory_bytes: 35524
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;
int main(void){
    int e;
    while(1){
        cin>>e;
        if(e==0)break;
        int ans=1000000000;
        for(int i=pow(e,0.334);i>=0;i--){
            for(int j=pow(e,0.5);j>=0;j--){
                if(e-i*i*i-j*j>=0){
                    ans=min(ans,i+j+(e-i*i*i-j*j));
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}



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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; i++) {
		cin >> a.at(i);
	}
	for(int i = 0; i < n; i++) {
		cout << a.at(n-i-1);
		if(i != n -1) {
			cout << " ";
		}
	}
	cout << endl;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
#define pb push_back
 
#define sec second
#define fir first
#define mo 1000000007
#define inf 1e18
#define rep(i, s, n) for (ll i = s; i < n; i = i + 1)
#define rrep(i,s,n) for(ll i=s;i>=n;i--)

ll mod(ll n) { return (n % (ll)mo + (ll)mo)%(ll)mo;}
int main(){
	ll n;
	cin>>n;
	
	ll cnt = 0;
	rep(i,1,n+1){
		ll x;
		cin>>x;
		if(i%2 && x%2) ++cnt;
	}
	cout<<cnt;
}
		 

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#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)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const int MOD = 1000000007; 

int main() {
    int n;
    cin >> n;
    int tp = 0, ap = 0, bp = 0;
    string ret = "Yes"; 
    rep(i, n) {
        int t, a, b;
        cin >> t >> a >> b;
        int d = abs(a - ap) + abs(b - bp);
        int dt = t - tp;
        if (d > dt || (dt - d)%2) ret = "No"; 
        tp = t; ap = a; bp = b;
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define sorv(V) sort(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define rb(x) ((x)&(-(x)))
using namespace std;
typedef pair<int, int> pii;

const int MOD = 1000000007;
const int MAXN = 100055;
const int MAXM = 100055;

void add(int &a, int b) { a += b; if(MOD <= a) a -= MOD; }

struct BIT {
	int d[MAXN];
	void upd(int x, int r) {
		for(x += 5; x < MAXN; x += rb(x))
			add(d[x], r);
	}
	int get(int x) {
		int r = 0; for(x += 5; x; x -= rb(x))
			add(r, d[x]);
		return r;
	}
} bit;

vector<pii> TV;
int A[MAXN], B[MAXM];

int N, M;

int main() {
	ios::sync_with_stdio(false);

	cin >> N >> M;
	for(int i = 1; i <= N; i++) cin >> A[i];
	for(int i = 1; i <= M; i++) cin >> B[i];

	for(int i = 1, j = 1; i <= N; i++) {
		for(; j <= M && B[j] <= A[i]; j++);
		if(1 < j && j <= M)
			TV.eb(A[i]-B[j-1], B[j]-A[i]);
	}
	N = sz(TV);

	{
		vector<int> V;
		for(auto &v : TV) V.eb(v.second);
		sorv(V); univ(V);
		for(auto &v : TV)
			v.second = int(lower_bound(allv(V), v.second) - V.begin()) + 1;
	}

	sort(allv(TV), [&](pii a, pii b) {
		if(a.first != b.first) return a.first < b.first;
		return a.second > b.second;
	});
	univ(TV);

	bit.upd(0, 1);
	for(auto &ev : TV)
		bit.upd(ev.second, bit.get(ev.second-1));
	
	cout << bit.get(N+5) << endl;
	return 0;
}

Measured memory_bytes: 2676
w = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]
w.reverse()
def weight(x):
    res = []
    for i in range(len(w)):
        if w[i] <= x:
           res.append(i)
           x = x-w[i]
    return res
while True:
    try:
        x = int(input())
        res = weight(x)
        res.reverse()
        print(w[res[0]],end = '')
        for i in range(1,len(res)):
            print(' ',w[res[i]],sep = '',end = '')
        print('')
    except EOFError:
        break

Measured memory_bytes: 7664
import sys

def readQuestion():
    line = sys.stdin.readline()
    sline = line.rstrip()
    [sa,sb] = sline.split()
    a = int(sa)
    b = int(sb)
    return(a,b)

def solve(a,b):
    if a <= b:
        return(a)
    else:
        return(a-1)

def main():
    a,b = readQuestion()
    answer = solve(a,b)
    print(answer)
    
    # mainを呼び出す
if __name__ == '__main__':
    main()

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

#define W_MAX 1000000001

long long solve(vector<vector<long long>>&dp, vector<int>&w, vector<int>&v, int i, int &n, int value){
    if(value <= 0){
        return 0;
    }
    if(i == n){
        return W_MAX;
    }
    if(dp[value][i] != 0){
        return dp[value][i];
    }
    dp[value][i] = min(solve(dp,w,v,i+1,n,value),w[i]+solve(dp,w,v,i+1,n,value-v[i]));
    return dp[value][i];
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    // int t; cin>>t;
    // while(t--){
        int n,W; cin>>n>>W;
        vector<int>w(n),v(n);
        for(int i=0;i<n;i++){
            cin>>w[i]>>v[i];
        }
        vector<vector<long long>>dp(100001, vector<long long>(n+1, 0));
        int ans = 0;
        for(int i=100000;i>=0;i--){
            if(solve(dp,w,v,0,n,i) <= W){
                ans = i;
                break;
            }
        }
        cout<<ans<<"\n";
    // }
}


Measured memory_bytes: 85260
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(){
    char ch;
    int frequency[26];
    int i;
    for(i=0; i<26; i++)
        frequency[i] = 0;
    while(scanf("%c", &ch) != EOF){
        if(isupper(ch))
            ch = tolower(ch);
        frequency[ch - 'a'] += 1;
    }
    for(i=0; i<26; i++){
        printf("%c : %d\n", i+'a', frequency[i]);
    }
}



Measured memory_bytes: 2064
#include <iostream>
#include<algorithm>
using namespace std;
const int P=1000000007;
int main() {
  int n;
  cin>>n;
  
  int a[n];
  for(int i=0;i<n;i++){
  	cin>>a[i];
  }
  sort(a,a+n);
  if(n%2==0){
  	int x=1;
  	for(int i=0;i<n;i+=2){
  	  if(a[i]==i+1 and a[i+1]==i+1){
  	  	x*=2;
  	  	x%=P;
  	  }else{
  	  	x=0;
  	  	break;
  	  }
  	}
  	cout<<x<<endl;
  }else{
  	int x=1;
  	if(a[0]!=0){
  	  cout<<0<<endl;
  	}else{
	  	for(int i=1;i<n;i+=2){
	  	  if(a[i]==i+1 and a[i+1]==i+1){
	  	  	x*=2;
	  	  	x%=P;
	  	  }else{
	  	  	x=0;
	  	  	break;
	  	  }
	  	}
	  	cout<<x<<endl;  		
  	}
  	
  }
}

Measured memory_bytes: 640
process.stdin.setEncoding('utf-8');
process.stdin.on('data', input => {
  const s = parseInt(input);
  var hour = Math.floor(s / 3600);
  var minute = Math.floor( (s % 3600) / 60 );
  var second = Math.floor(s % 60);
  console.log(hour + ":" + minute + ":" + second);
});


Measured memory_bytes: 15296
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1e9;

int main() {
    int n;
    string s;
    cin >> n >> s;
    if (n % 2) {
        cout << "No" << endl;
    } else if (s.substr(0, n / 2) == s.substr(n / 2, n / 2)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()

for i in range(1, int(N**(1/2)+5)):
    if i**2 > N:
        print((i-1)**2)
        break


Measured memory_bytes: 5400
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	string s;
	cin>>s;
	int a[30]={};
	int l=s.length();
	FOR(i,0,l){
		a[s[i]-'a']++;
	}
	int f=0;
	string ne=s+"Z";
	if(l!=26){
		FOR(j,0,'z'-'a'+1){
			if(a[j]==0){
				char cc='a'+j;
				s+=cc;
				f=1;

			}
			if(f)break;
		}
		f=1;
	}else FORD(i,l,0){
		//cout<<"te "<<s<<" s[i]:"<<s[i]<<endl;
		int t=s[i]-'a';
		FOR(j,t,'z'-'a'+1){
			if(a[j]==0){
				s[i]=j+'a';
				f=1;

			}
			if(f)break;
		}
		if(f)break;
		/*
		FOR(j,t,'z'-'a'+1){
			if(a[j]==0){
				s[i]=j+'a';
				f=1;

			}
		}//*/
		ne=s;
		s="";
		FOR(i,0,l-1){
			s+=ne[i];
		}
		a[t]--;
		l--;
	}
	if(f)cout<<s<<endl;
	else cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,m=0,s,l=0,c=0,i,k,b;
    cin>>n;
    m=n-1;
    for(i=1;i<=sqrt(n);i++){
        if(!(n % i)){
            k=i;
            s=n/k;
            m=min(m,(k-1)+(s-1));
            l=1;
        }
    }
    if(l)
        cout<<m;
    else
        cout<<n-1;
}


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

const long long INF = 1LL << 60;
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; }

typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define vi vector<int>
#define vii vector< vector<int> >

int N, M;

int main() {

	cin >> N >> M;
	if (M / N) cout << "Yes" << endl;
	else cout << "No" << endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define reps(i, a, n) for (int i = (a); i < (n); ++i)
#define rep(i, n) reps(i, 0, n)
#define deps(i, a, n) for (int i = (a); i >= (n); --i)
#define dep(i, n) deps(i, n, 0)
#define inf 2147483647
#define int long long

signed main(void)
{
	int n; cin >> n;
	int x, y;
	cin >> x >> y;
	int max0, max1, min0, min1;
	max0 = min0 = x - y;
	max1 = min1 = x + y;
	reps (i, 1, n)
	{
		cin >> x >> y;
		if (x - y > max0) max0 = x - y;
		if (x - y < min0) min0 = x - y;
		if (x + y > max1) max1 = x + y;
		if (x + y < min1) min1 = x + y;
	}
	int ans;
	ans = max0 - min0;
	if (max1 - min1 > ans) ans = max1 - min1;
	cout << ans << endl;
}


Measured memory_bytes: 3668
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		System.out.println(Math.min(a, b) + " " + Math.max(0, a + b - N));
	}
}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define f(i,x,n) for(int i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
const int MOD = 1e9 + 7, N = 5e5 + 10;
const int LINF = LLONG_MAX;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<int>v(n);
    f(i,0,n){
        cin >> v[i];
    }
    int ans = 0;
    f(i,1,n){
        if(v[i] < v[i-1]){
            ans += abs(v[i] - v[i-1]);
            v[i] = v[i-1];
        }
    }
    cout << ans << "\n";
    return 0;
}
 

Measured memory_bytes: 4744
#include <iostream>
#include <string>

using namespace std;

int N;
string input;
long long Cnt[5]={0, 0, 0, 0, 0};
char Ch[5]={'M', 'A', 'R', 'C', 'H'};
long long Temp;
long long Ans=0LL;

int main(){
	ios_base::sync_with_stdio(false);
	
	cin >> N;
	while(N--){
		cin >> input;
		for(int i=0;i<5;++i)
			if(input[0]==Ch[i])
				Cnt[i]+=1LL;
	}
	
	for(int i=0;i<4;++i){
		for(int j=i+1;j<5;++j){
			Temp=1LL;
			for(int k=0;k<5;++k){
				if(k==i || k==j)	continue;
				Temp*=Cnt[k];
			}
			Ans+=Temp;
		}
	}
	
	cout << Ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
def solve():
    s = int(input())
    collatz = [s]
    now = s
    for _ in range(10 ** 6):
        a_i1 = 3 * now + 1 if now % 2 else now // 2
        now = a_i1
        if a_i1 in collatz:
            return len(collatz) + 1
        collatz.append(a_i1)


if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 2940
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	void run(){
		for(;;){
			String r = sc.next();
			String a = sc.next();
			if(r.equals("0")){
				break;
			}
			
			int blow = 0;
			for(char c : r.toCharArray()){
				if(a.indexOf(c) >= 0){
					blow++;
				}
			}
			int hit = 0;
			for(int i= 0; i <4;i++){
				if(r.charAt(i) == a.charAt(i)){
					hit++;
					blow--;
				}
			}
			
			System.out.println(hit + " "+ blow);
		}
		
	}
	public static void main(String[] args){
		Main m = new Main();
		m.run();
	}
}

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

int main(){
  int N;
  cin >> N;
  int value[N];
  int weight[N];
  for(int i=0;i<N;i++){
    int tmp1,tmp2;
    cin >> tmp1 >> tmp2;
    value[i]=tmp1;
    weight[i]=tmp2;
  }
  int DP[512+1][100000+1];
  for(int i=0;i<512+1;i++){
    for(int j=0;j<100000+1;j++){
      DP[i][j]=0;
    }
  }
  for(int i=1;i<min(N,512)+1;i++){
    int v,w;
    v=value[i-1];
    w=weight[i-1];
    for(int j=100000;j>w-1;j--){
      DP[i][j]=max(DP[i/2][j],DP[i/2][j-w]+v);
    }
    for(int j=w-1;j>-1;j--){
      DP[i][j]=DP[i/2][j];
    }
  }
  int Q;
  cin >> Q;
  for(int i=0;i<Q;i++){
    int v,l;
    cin >> v >> l;
    if(v<=512){
      cout << DP[v][l] << endl;
    }
    else{
      int vs[10];
      int cnt;
      cnt=0;
      while(v>512){
        vs[cnt]=v;
        v=v/2;
        cnt++;
      }
      int ans=0;
      for(int i=0;i<(1<<cnt);i++){
        int wei=0;
        int val=0;
        for(int j=0;j<cnt;j++){
          if(i&(1<<j)){
            wei+=weight[vs[j]-1];
            val+=value[vs[j]-1];
          }
        }
        if(wei>l){
          continue;
        }
        ans=max(ans,DP[v][l-wei]+val);
      }
      cout << ans << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 205836
import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;


public class Main {
	 static class FastReader 
	    { 
	        BufferedReader br; 
	        StringTokenizer st; 
	       
	  
	        public FastReader() 
	        { 
	            br = new BufferedReader(new
	                     InputStreamReader(System.in)); 
	        } 
	  
	        String next() 
	        { 
	            while (st == null || !st.hasMoreTokens()) 
	            { 
	                try
	                { 
	                    st = new StringTokenizer(br.readLine()); 
	                } 
	                catch (IOException  e) 
	                { 
	                    e.printStackTrace(); 
	                } 
	            } 
	            return st.nextToken();
	            
	        } 
	  
	        int nextInt() 
	        { 
	            return Integer.parseInt(next()); 
	        } 
	  
	        long nextLong() 
	        { 
	            return Long.parseLong(next()); 
	        } 
	  
	        double nextDouble() 
	        { 
	            return Double.parseDouble(next()); 
	        } 
	  
	        String nextLine() 
	        { 
	            String str = ""; 
	            try
	            { 
	                str = br.readLine(); 
	            } 
	            catch (IOException e) 
	            { 
	                e.printStackTrace(); 
	            } 
	            return str; 
	        }

			public Character charAt(int i) {
				// TODO Auto-generated method stub
				return null;
			} 
	    } 
	
	public static void main(String[] args)throws IOException  {
		FastReader s=new FastReader();		
		int n = s.nextInt();
		int t = (int)Math.pow(n, 3);
		int p =  Math.abs(t);
		System.out.println(p);
		
	}
}

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

#define ll long long

int n;
double dp[3000][3000], p[3000];
bool vis[3000][3000];

double pound(int heads = 0, int tails = 0)
{
    if (tails > n / 2)
        return 0;
        
    if (heads + tails == n)
        return 1;
    
    if (vis[heads][tails])
        return dp[heads][tails];
        
    vis[heads][tails] = 1;
    
    return dp[heads][tails] = pound(heads + 1, tails) * p[heads + tails] + pound(heads, tails + 1) * (1 - p[heads + tails]);
}

int main()
{
    cin >> n;
    
    for (int i = 0; i < n; ++i)
        cin >> p[i];
        
    cout << setprecision(9) << fixed << pound();
    
    return 0;
}


Measured memory_bytes: 78464
#include <iostream>
using namespace std;
int main()
{
	double n,m,cnt = 0,total = 0;
	double votes[110];
	cin >> n >> m; 
	for(int i = 1; i <= n; i++)
	{
		cin >> votes[i];
		total += votes[i];
	}
	double thresold = 0.25 * total * (1 / m);
	for(int i = 1; i <= n; i++)
	{
		if(votes[i] >= thresold) cnt+=1;
	}
	if(cnt >= m) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
a = [0] * 5
a[0] = int(input())
a[1] = int(input())
a[2] = int(input())
a[3] = int(input())
a[4] = int(input())

b = [0] * 5
for i in range(5):
    if a[i] % 10 == 0:
        b[i] = a[i]
    else:
        b[i] = (a[i] // 10 + 1) * 10

time = sum(b)

ans = float("inf")
for i in range(5):
    temp = time - b[i] + a[i]
    ans = min(temp,ans)

print(ans)


Measured memory_bytes: 3064
s = list(input())
alphabet = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v' ,'w', 'x', 'y', 'z'}
ans = sorted(list(alphabet - set(s)))
if len(ans) == 0:
    ans = 'None'
else:
    ans = ans[0]
print(ans)

Measured memory_bytes: 3956
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
using ll = long long;
using PII = pair<int, int>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

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

	ll x, t;
	cin >> x >> t;
	cout << max(x-t, (ll)0) << endl;
}


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

using namespace std;

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

    cin >> n;

    string s;

    cin >> s >> q;

    vector<set<int>> place(26);
    
    for(int i = 0; i < n; ++i) {
        place.at(s.at(i) - 'a').emplace(i);
    }
    
    int soq, iq, lq, rq, ans;
    char cq;

    for(int i = 0; i < q; ++i) {
        cin >> soq;
        if(soq == 1) {
            cin >> iq >> cq;
            --iq;
            place.at(s.at(iq) - 'a').erase(iq);
            s.at(iq) = cq;
            place.at(cq - 'a').emplace(iq);
        } else {
            cin >> lq >> rq;
            --lq;
            --rq;
            ans = 0;
            for(int i = 0; i < 26; ++i) {
                auto itr = place.at(i).lower_bound(lq);
                if(*itr <= rq && itr != place.at(i).end()) ++ans;
            }
            printf("%d\n", ans);
        }
    }

    return 0;
}

Measured memory_bytes: 26268
import java.util.Scanner;

class Main {
    public static void main(String... args) {        
        int N = IN.nextInt();
        int K = IN.nextInt();
        int[] x = new int[N];
        for (int i = 0; i < N; i++) {
            x[i] = IN.nextInt();
        }
        int ans = Integer.MAX_VALUE;
        int j;
        int dist;
        for (int i = 0; i <= N - K; i++) {
            j = i + K - 1;
            if (x[j] <= 0) {
                ans = Math.min(ans, -x[i]);
            } else if (0 <= x[i]) {
                ans = Math.min(ans, x[j]);
            } else {
                dist = Math.min(Math.abs(x[i]), x[j]);
                ans = Math.min(ans, x[j] - x[i] + dist);
            }
        }
        System.out.println(ans);
    }
    final static Scanner IN = new Scanner(System.in);
}

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

typedef long long ll;
#define MOD = 1000000007;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) { s >> x; } return s;}
template<class T> inline bool chmin(T& a, T b){return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b){return a<b?a=b,true:false;}
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
#define ANS(a) cout<<a<<endl
void yes(bool f){cout<<(f?"yes":"no")<<endl;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

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

    string O, E;
    cin >> O >> E;

    string ans(O.size()+E.size(), ' ');
    rep(i, ans.size()) {
        if (i%2)    ans[i] = E[i/2];
        else        ans[i] = O[i/2];
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
//gcc 5.4.0

#include  <stdio.h>

int main(void)
{
    int R, G, B, N;
    int i, j, k;
    int cnt = 0;
    scanf("%d %d %d %d", &R, &G, &B, &N);
    for(i = 0; i <= (int)(N/R); i++){
        for(j = 0; j <= (int)((N-i*R)/G); j++){
            int rest = N - i*R - j*G;
            if(rest % B == 0){
                cnt ++;
            }
        }
    }
    printf("%d", cnt);
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>
#include <limits>
#include <cmath>
#include <iomanip>
#include <sstream>
 
#define ALL(a)  (a).begin(),(a).end()
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
 

 
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    ll ans = 0;
    string s; cin >> s;
    if (s[1] == 'B') cout << "ARC" << endl; 
    else cout << "ABC" << endl;

} 

Measured memory_bytes: 3636