akhauriyash/Code-Regression huggingface dataset:
/*
 *  Created on: 22-December-2019
 *      Author: ankur314
 */
#include <bits/stdc++.h>
#define lli long long int
#define li long int
#define db double
#define ldb long double
#define vr vector
#define it iterator
#define fi(i,a,n) for(int i=a;i<n;i++)
#define fli(i,a,n) for(long int i=a;i<n;i++)
#define flli(i,a,n) for(long long int i=a;i<n;i++)
#define pb(n) push_back(n)
#define ppf() pop_front()
#define pii pair<int,int>
#define MOD 1000000007
#define INF 1000000005
 
#define debug1(x) cout<<x<<"\n"
#define debug2(x,y) cout<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define debug4(x,y,z,w) cout<<x<<" "<<y<<" "<<z<<" "<<w<<"\n"
 
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    /*freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);*/
    lli n; cin>>n;
    if(n % 2 != 0)
    {
    	cout<<0;
    }
    else
    {
    	n /= 2LL;
    	lli ans = 0;
    	lli num = 5;
    	while(n/num)
    	{
    		ans += n/num;
    		num *= 5;
    	}
    	cout<<ans;
    }
    return 0;
}   

Measured memory_bytes: 256
N = int(input())
h_list = list(map(int,input().split()))
INF = 10**9 + 7
DP = [INF]*N
DP[0] = 0
DP[1] = abs(h_list[0]-h_list[1])
for i in range(2,N):
    DP[i] = min(DP[i-1]+abs(h_list[i]-h_list[i-1]),DP[i-2]+abs(h_list[i]-h_list[i-2]))
print(DP[-1])

Measured memory_bytes: 13980
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

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

    string str;
    cin >> str;

    vector<LL> count(3,0);

    for(int i = 0; i < str.size(); i++){
        count[str[i]-'a']++;
    }

    LL tmp1 = count[1] - count[0];
    LL tmp2 = count[2] - count[0];

    if(abs(tmp1) <= 1 && abs(tmp2) <= 1 && abs(tmp1-tmp2) <= 1){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;
}

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

int main(){
	int a,b,c;
  	cin >> a >> b >> c;
  	if ((a==5 && b==5 && c==7)||(a==5 && b==7 && c==5)||(a==7 && b==5 && c==5)) cout << "YES" << endl;
  	else cout << "NO" <<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int total = 1;
        for(int i = 0; i < 3; i++) {
            total *= a;
        }
        System.out.println(total);
    }

}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

ll modpow(ll N, ll P,ll M){
    if(P==0) return 1;
    if(P%2==0){
        ll t =modpow(N, P/2,M);
        return t*t % M;
    }
    return N * modpow(N, P-1, M)%M;
}

int main(){
    ll n;cin >>n;
    map<P,ll>mp;
    for (int i = 0; i < n; ++i) {
        ll a,b;cin >>a>>b;
        if(a==0&&b==0){
            mp[{0,0}]++;
            continue;
        }
        ll g=__gcd(a,b);
        a/=g;b/=g;
        if(a<0){
            a*=-1;b*=-1;
        }
        if(a==0){
            if(b>0)b*=-1;
        }
        mp[{a,b}]++;
    }
    ll ans=1LL;
    for(auto p:mp){
        if(p.second==0)continue;
        if(p.first.first==0&&p.first.second==0){
            continue;
        }
        if(p.first.second<0){
            if(mp[{-p.first.second,p.first.first}]!=0)continue;
        }
        ll r = modpow(2, p.second, mod) - 1LL;
        r += modpow(2, mp[{p.first.second, -p.first.first}], mod)- 1LL;
        r+=mod;
        r %= mod;
        r++;
//        cout <<r<<endl;
        ans *= r;
        ans %= mod;
    }
    ans+=mp[{0,0}]%mod;
    ans--;
    ans+=mod;
    ans%=mod;
    cout <<ans <<endl;
    return 0;
}



Measured memory_bytes: 34724
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>

using namespace std;

int main()
{
    int A,B,C, K;
    cin >> A >> B >> C >> K;
    int count = 0;
    int sum = 0;
    while(true)
    {
        for (int i = 0; i < A; i++)
        {
            sum++;
            count++;
            if(count == K)
            {
                cout << sum << endl;
                return 0;
            }
        }
        for (int i = 0; i < B; i++)
        {
            count++;
            if (count == K)
            {
                cout << sum << endl;
                return 0;
            }
        }
        for (int i = 0; i < C; i++)
        {
            sum--;
            count++;
            if (count == K)
            {
                cout << sum << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 3532
function Main(input) {
    input = input.trim().split("\n").map(function(x) { return x.split(" ")});
    var finishedLine = 0;
    while (true){
        var n = parseInt(input[0 + finishedLine][0], 10);
        var k = parseInt(input[0 + finishedLine][1], 10);
        if ((n + k) === 0) break;
        var vec_a = [];
        var vec_s = [0];
        for (var i = 0; i < n; i++){
            vec_a.push(parseInt(input[i + 1 + finishedLine][0], 10));
            vec_s.push(vec_s[i] + vec_a[i]);
        }
        finishedLine += n + 1;
        var ans = -10000 * k;
        for (var i = 0; i <= (n - k); i++){
            ans = Math.max(ans, vec_s[i + k] - vec_s[i])
        }
        console.log(ans);
    }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8")); 


Measured memory_bytes: 41044
import java.util.Scanner;

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

        int K = sc.nextInt();
        String S = sc.next();

        System.out.println(solve(K, S));

        sc.close();
    }

    static String solve(int K, String S) {
        return (S.length() <= K) ? S : String.format("%s...", S.substring(0, K));
    }
}

Measured memory_bytes: 35876
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
using namespace std;
typedef long long ll;

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

    int odd = 0;
    int even = 0;
    int a;
    for (int i = 0; i < N; i++)
    {
        cin >> a;
        if (a % 2 == 0)
            even++;
        else
            odd++;
    }

    if (odd % 2 == 0)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}

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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int n; cin >> n;
    int ans = 0;
    vector<int> s(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        ans += s[i];
    }
    if (ans % 10 == 0) {
        sort(s.begin(), s.end());
        for (int i = 0; i <= n; i++) {
            if (i == n) {
                ans = 0;
                break;
            }

            if (s[i] % 10 != 0) {
                ans -= s[i];
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

#define ll long long
#define endl "\n"

const int MOD = 1e9+7;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n,k,a=0;
    cin>>n>>k;
    for (int i=k; i<=n+1; ++i){
        a += (n-i+1)*i + 1;
        a%=MOD;
    }
    cout<<a;
    return 0;
}

Measured memory_bytes: 3636
<?php
$input = fgets(STDIN);
$array = explode(" ", $input);
// echo (int)$array[1];
// exit;
if(is_int(((int)$array[0] + (int)$array[1]) / 2)){
  echo ((int)$array[0] + (int)$array[1]) / 2;
  exit;
}

echo "IMPOSSIBLE";

Measured memory_bytes: 4604
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		Integer N = Integer.parseInt(sc.next());
		int[] D = new int[N];
		int[] count = new int[N];
		long result = 1;
		for(int i=0;i<N;i++) {
			D[i] = Integer.parseInt(sc.next());
			count[D[i]] ++;
		}
		if(D[0] != 0 || count[0] != 1) {
			out.println(0);
		}
		else {
			for (int i=1;i<N;i++) {
				for(int j=0;j<count[i];j++) {
					result *= count[i-1];
					result %= 998244353;
				}
			}
			out.println(result);
		}

		out.flush();
	}
}

Measured memory_bytes: 47768
def calc_rev_polish(exp, stack)
  # puts "#{exp} #{stack}"

  if exp.empty?
    return stack.pop if stack.size == 1
    return nil
  end

  val = exp.shift
  return nil if val.nil?
  if val.class == Fixnum
    stack.push(val)
    return calc_rev_polish(exp, stack)
  end

  a = stack.pop
  b = stack.pop
  return nil if b.nil?
  if val == "+"
    stack.push(b+a)
  elsif val == "-"
    stack.push(b-a)
  else
    stack.push(b*a)
  end
  return calc_rev_polish(exp, stack)
    
end

def find_prev_term(exp, pos)
  par_count = 0
  pos.downto(0){|p|
    if p <= 0
      return p
    end

    if exp[p].class == Fixnum && par_count == 0
      return p
    end

    if exp[p] == ")"
      par_count += 1
    end

    if exp[p] == "("
      par_count -= 1
      if par_count == 0
        return p
      end
    end
  }

end

def rev2norm(rev)
  norm = []

  rev.each{|v|
    if v.class == Fixnum
      norm.push(v)
      next
    end

    pos1 = find_prev_term(norm, norm.size-1)
    norm.insert(pos1, v)

    pos2 = find_prev_term(norm, pos1-1)
    norm.insert(pos2, "(")
    norm.push(")")

    # p norm
  }
  return norm
end

ARGF.each{|line|
  break if line.chomp == "0 0 0 0"

  nums = line.chomp.split(/ /).map{|c| c.to_i}
  ops = " +-*".split(//)

  out = nil
  nums.permutation(4){|num_seq|
    ops.repeated_permutation(6){|ops_seq|
      exp = []
      exp << num_seq[0]
      exp << num_seq[1]
      exp << ops_seq[0]
      exp << num_seq[2]
      exp << ops_seq[1]
      exp << ops_seq[2]
      exp << num_seq[3]
      exp << ops_seq[3]
      exp << ops_seq[4]
      exp << ops_seq[5]

      # p exp
      exp.delete_if{|c| c == " "}
      exp2 = exp.dup
      if calc_rev_polish(exp, []) == 10
        out = exp2
        break
      end
    }
    break unless out.nil?
  }
  if out.nil?
    puts "0"
  else
    # p out
    puts rev2norm(out).join("")
  end
}
  

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

#define fa(x,v) for(auto x:v)
#define f(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define spc " "
#define endl '\n'
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(s) (ll)int(s.length())
#define sz(v) (ll)int(v.size())
#define MOD 1000000007

void Fast_IO() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    freopen("debug.out","w",stderr);
    #endif
} 

// Code Here

#define MAX 10000001

ll spf[MAX+1];

void buildSPF()
{
	f(i,0,MAX) spf[i] = 0;
	f(i,2,MAX) {
		if(spf[i] == 0) {
			spf[i] = i;
			for(ll j = i + i; j <= MAX; j += i)
				if(spf[j] == 0)
					spf[j] = i;
		}
	}
}

vector < pair<ll,ll> > primeFactorsWithCountOf(ll n)
{
	 vector < pair<ll,ll> > ret;
	 while(n > 1) {
	 	ll currentFactor = spf[n];
	 	ll currentCount = 0;
	 	while(n % currentFactor == 0) n /= currentFactor, currentCount++;
	 	ret.pb(mp(currentFactor,currentCount));
	 }
	 return ret;
}

ll F[10000001];

int main()
{
    // Fast_IO();
    buildSPF();
    f(i,1,10000000) {
    	vector < pair<ll,ll> > v = primeFactorsWithCountOf(i);
    	F[i] = i;
    	fa(x,v) F[i] *= (x.ss+1);
    }
    ll n; cin >> n;
    ll ans = 0;
    f(i,1,n) ans += F[i];
    cout << ans;
    return 0;
}

Measured memory_bytes: 159876
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main {

  public static void main(String[] args) throws Exception {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String str = br.readLine();
    StringTokenizer st = new StringTokenizer(str);

    int a = Integer.parseInt(st.nextToken());
    int b = Integer.parseInt(st.nextToken());

    System.out.println(Hoge.isProductPositive(a, b));
  }
}

class Hoge {

  static String isProductPositive(int a, int b) {
    return a * b % 2 == 0 ? "Even" : "Odd";
  }
}

Measured memory_bytes: 21204
//Written by Zhu Zeqi
//Come on,baby
//Hack,please
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define CLR(x) memset(x,0,sizeof x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define MAX 100000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 1000000000
typedef long long ll;
//orz yht
using namespace std;
string i_s(int x){
	if(x==0)
	return "0";
	string ret="";
	while(x){
		ret=ret+(char)(x%10+'0');
		x/=10;
	}
	reverse(ret.begin(),ret.end());
	return ret;
}
string add(string a,string b){
	if(a=="")
	a="0";
	if(b=="")
	b="0";
	if(a.length()<b.length())
	swap(a,b);
	while(b.length()<a.length()){
		b='0'+b;
	}
	for(int i=0;i<a.length();i++){
		a[i]=a[i]+(b[i]-'0');
	}
	bool big=false;
	for(int i=a.length()-1;i>=0;i--){
		if(big){
			a[i]++;
		}
		big=false;
		if(a[i]>'9'){
			a[i]=a[i]-10;
			big=true;
		}
	}
	if(big)
	a='1'+a;
	return a;
}
string mul(string a,string b){
	vector<int> va,vb;
	if(a=="0" || b=="0")
	return "0";
	string ans;
	for(int i=0;i<a.length();i++){
		va.push_back(a[i]-'0');
	}
	for(int i=0;i<b.length();i++){
		vb.push_back(b[i]-'0');
	}
	reverse(va.begin(),va.end());
	reverse(vb.begin(),vb.end());
	vector<int> res;
	res.clear();
	res.resize(1005);
	for(int i=0;i<a.length();i++){
		for(int j=0;j<b.length();j++){
			res[i+j]+=(va[i]*vb[j]);
		}
	}
	for(int i=0;i<1005;i++){
		if(res[i]>9){
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	for(int i=0;i<1005;i++){
		ans+=(res[i]+'0');
	}
	reverse(ans.begin(),ans.end());
	int k=0;
	while(ans[k]=='0'){
		k++;
	}
	ans=ans.substr(k);
	return ans;
}
bool is_prime(int n){
	if(n<2)
    return false;
    for(int i=2;i*i<=n;i++)
    if(n%i==0)
    return false;
    return true;
}

int main(){
	//freopen("wireless.in","r",stdin);
	//freopen("wireless.out","w",stdout);
	string s;
	cin>>s;
	cout<<s[0];
	cout<<s.size()-2;
	cout<<s[s.size()-1];
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
import itertools
import math
import sys
from collections import Counter
from fractions import gcd
from functools import reduce
import sys
sys.setrecursionlimit(4100000)

mod = 10 ** 9 + 7
n, m = map(int, input().split())
maximum = max(n, m)
minimum = min(n, m)
ans = math.factorial(maximum) % mod
if maximum - minimum >= 2:
    ans = 0
elif maximum - minimum == 1:
    ans *= math.factorial(minimum) % mod
else:
    ans *= ((math.factorial(minimum - 1) % mod) * 2 * minimum) % mod
print(ans % mod)


Measured memory_bytes: 6096
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<map>
#include <algorithm>
#include<cstdlib>
#include<cmath>
#include<deque>
#include <numeric>
#include<valarray>
typedef unsigned long long ull;
typedef  long long ll;

int main() {
	std::string  b ;
	std::cin >> b ;
	if(b[0] == 'A')
	{
		std::cout << 'T' << std::endl;
	}
	else if (b[0] == 'C')
	{
		std::cout << 'G' << std::endl;
	}
	else if(b[0] == 'T')
	{ 
		std::cout << 'A' << std::endl;
	}
	else if(b[0] == 'G')
	{ 
		std::cout << 'C' << std::endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

using namespace std;
int a[100005];
int dp[100005];


int _gcd(int a,int b)
{
	return (b==0?a:_gcd(b,a%b));
}
bool cmp(int a,int b)
{
	return a>b;
}



int solve(ll n,ll k)
{
	
	dp[0]=dp[1]=0;
	dp[2]=abs(a[1]-a[2]);
	for(int i=3;i<=n;++i)
	{
		dp[i]=INT_MAX;
		for(int j=i-1;j>=1 && (i-j)<=k;--j)
		{
			dp[i]=min(dp[i],abs(a[i]-a[j])+dp[j]);
		}
	}
	return dp[n];


}

int main()
{
	fast;
	#ifndef ONLINE_JUDGE
	    freopen("input.txt", "r", stdin);
	    freopen("output.txt", "w", stdout);
	#endif
				ll n;
				cin>>n;
				ll k;
				cin>>k;
				for(int i=1;i<=n;++i)
				{
					cin>>a[i];
				}
				cout<<solve(n,k)<<endl;

	return 0;
}


Measured memory_bytes: 4400
#include<stdio.h>

int main(void){
    int a,b,d,r;
    double f;
    scanf("%d %d",&a,&b);
    d=a/b;
    r=a%b;
    f=(double)a/(double)b;
    printf("%d %d %f",d,r,f);
    return 0;
}


Measured memory_bytes: 2684
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define uint unsigned long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) {
    return a / gcd(a, b) * b;
}
int sigma(int n){
    int sum=0;
    for (int i=1; i<=(n); i++){
        sum+=i;
    }
    return sum;
}
int distance(int yo,int xo,int yi,int xi){
    return (yo-yi)*(yo-yi)+(xo-xi)*(xo-xi);
}
signed main(){
    int K,X;
    cin >> K >> X;
    if((500*K)>=X){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
N=int(input())
S=input()
ans=S.count("R")*S.count("G")*S.count("B")

for i in range(N):
  for j in range(i+1,N):
    k=j+(j-i)
    if k<=N-1:
      if S[j]!=S[i] and S[j]!=S[k] and S[k]!=S[i]:
          ans-=1
print(ans)

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

using namespace std;

// Repetitions
#define FOR(i,a,n) for(ll i = ((ll) a); i < ((ll) n); ++i)
#define FORR(i, s, g) for(ll i = ((ll)s - 1); i >= ((ll) g); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)

// Container Utils
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SORTALL(v) sort(ALL(v))
#define SZ(a) int((a).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

// For Debug
#define DMP(x)  cerr << #x << " = " << (x) << endl
#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

// Aliases
#define PB push_back
#define MP make_pair
using ll = long long;
using ld = long double;
using str = string;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vs = vector<str>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;

// Constant variables
const ld PI = (acos(-1));
const ll MOD = 1000000007;

// I/O Asynchronizing
struct __io_async{
    __io_async(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
};

int main() {
    ll a, b, k;
    cin >> a >> b >> k;
    a -= k;
    if(a < 0) b += a;
    cout << max(0LL, a) << " " << max(0LL, b) << "\n";

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<utility>
#include<sstream>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = 1005;
int dp[1000005];
bool leap[1000005];
int main()
{
	#ifdef LOCAL
	freopen("C:\\Users\\巍巍\\Desktop\\in.txt","r",stdin);
	//freopen("C:\\Users\\巍巍\\Desktop\\out.txt","w",stdout);
	#endif // LOCAL
	memset(leap,false,sizeof(leap));
	memset(dp,0,sizeof(dp));
    for(ll i = 2;i <= 999999;i++)
    {
        if(leap[i])continue;
        dp[i] = 1;
        for(ll j = i*i;j <= 999999;j = j + i)
            leap[j] = true;
    }
    for(int i = 1;i <= 999999;i++)dp[i] = dp[i] + dp[i - 1];
    int n;
    while(scanf("%d",&n) != EOF)
    {
        printf("%d\n",dp[n]);
    }
	return 0;
}

Measured memory_bytes: 6076
s = input()
q = int(input())
 
count = 0
s_f = ""
for i in range(q):
    q_i = input()
    if len(q_i) == 1:
        count += 1
    else:
        lis = [i for i in q_i.split()]
        x = count
        x += int(lis[1])
        if x % 2 == 0:
            s += lis[2]
        else:
            s_f += lis[2]

ans = ""
if count % 2 == 1:
    for i in range(len(s)):
        ans += s[-i-1]
    ans += s_f
else:
    s_f_ = ""
    for i in range(len(s_f)):
        s_f_ += s_f[-i-1]
    ans = s_f_ + s
print(ans)

Measured memory_bytes: 4596
import copy

N, M, C = map(int, input().split())
B = list(map(int, input().split()))
As = []
for i in range(N):
    As.append(list(map(int, input().split())))

correct_answer_num = 0
for A in As:
    result = 0

    for j in range(M):
        result += A[j] * B[j]

    result += C
    if result > 0:
        correct_answer_num += 1

print("{}".format(correct_answer_num))


Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, a, r;
  cin >> n >> a;
  r = n % 500; 
   if (a >= r){ 
  cout << "Yes" << endl;
   }
   else 
   {cout << "No" << endl; 
   }
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
struct sir
{
    int val,poz;
};
sir a[100001];
int n,arb[1<<19],pozitie,valoare,start,finish,maxim,l,d[100001],r[100001],nr;
bool cmp(sir a, sir b)
{
    if(a.val==b.val)
    {
        return a.poz<b.poz;
    }
    else
    {
        return a.val>b.val;
    }
}
void actualizare(int nod,int st,int dr)
{
    int mij;
    if(st==dr)
    {
        arb[nod]=valoare;
        return;
    }
    mij=(st+dr)/2;
    if(pozitie<=mij)
    {
        actualizare(2*nod,st,mij);
    }
    else
    {
        actualizare(2*nod+1,mij+1,dr);
    }
    arb[nod]=max(arb[2*nod],arb[2*nod+1]);
}
void interogare(int nod,int st,int dr)
{
    int mij;
    if(start<=st && dr<=finish)
    {
        if(arb[nod]>maxim)
        {
            maxim=arb[nod];
        }
        return;
    }
    mij=(st+dr)/2;
    if(start<=mij)
    {
        interogare(2*nod,st,mij);
    }
    if(mij<finish)
    {
        interogare(2*nod+1,mij+1,dr);
    }
}
int main()
{
    int i;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a[i].val;
        a[i].poz=i;
    }
    sort(a+1,a+n+1,cmp);
    for(i=1;i<=n;i++)
    {
        if(a[i].poz-1>=1)
        {
            maxim=0;
            start=1;
            finish=a[i].poz;
            interogare(1,1,n);
            d[i]=maxim+1;
            pozitie=a[i].poz;
            valoare=d[i];
            actualizare(1,1,n);
            if(d[i]>l)
            {
                l=d[i];
            }
        }
        else
        {
            d[i]=1;
            pozitie=a[i].poz;
            valoare=d[i];
            actualizare(1,1,n);
        }
    }
    cout << l << '\n';
    return 0;
}

Measured memory_bytes: 5776
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

const int CASES = 3;

vector<long long> calc_divisor(long long n) {
    vector<long long> res;
    for (long long i = 1LL; i*i <= n; ++i) {
        if (n % i == 0) {
            res.push_back(i);
            long long j = n / i;
            if (j != i) res.push_back(j);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

void solve() {
    ll N; cin >> N;
    if(N==2){
        cout << 1 << endl;
        return;
    }
    ll ans = 0;

    auto vec = calc_divisor(N);
    for(auto K : vec){
        if(K==1) continue;
        ll target = N;
        while(target >= K){
            if(target % K== 0) target /= K;
            else target %= K;
        }
        if(target==1){
            ++ans;
        }
    }

    auto vec2 = prime_factorize(N-1);
    ll tmp = 1;
    for(auto K : vec2){
        tmp *= (K.second+1);
    }
    ans += tmp-1;
    cout << ans << endl;
}

int main() {
#ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt", "input5.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
#else

    solve();

#endif
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;
int main(){
    int h,w,a,b; cin >> h >> w >> a >> b;
    rep(i,h){
        rep(j,w) cout << ((i<b && j<a) || (i>=b && j>=a) ? 0 : 1);
        cout << endl;
    }
}

Measured memory_bytes: 3608
#include <iostream>
#include <cstring>
#include <algorithm>
#include <deque>
using namespace std;

#define rep(i, N) for(int (i) = 0; (i) < N; (i) ++)
#define rrep(i, N) for(int (i) = (N); (i) >= 0; (i) --)
#define pint pair<int, int>
#define INF 1e9

#include <vector>
#include <stack>

using namespace std;
typedef long long ll;
int dy[4] = {0, 1, 0, -1};
int dx[4] = {1, 0, -1, 0};

ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

int main(){
    int N;
    cin >> N;
    ll ans = 1;
    rep(i, N){
        ll tmp;
        cin >> tmp;
        ll d = gcd(tmp, ans);
        ans *= tmp / d;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
#define     mod            (int)1e9+7
#define     MOD             998244353
#define     ll              long
#define     mp              make_pair
#define     F               first
#define     S               second
#define     t()             int test;cin>>test;while(test--)
#define     ii              pair<int,int>
#define     que_max         priority_queue <int>
#define     IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define     endl            "\n"
#define     sz(x)           (int)(x).size()
#define     grid            vector<vector<ll> >
typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << endl;
  //use cerr if u want to display at the bottom
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define trace(...)
#endif


int main()
{
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif

  IOS;

  int n;

  cin >> n;

  std::vector<ll double> p(n + 1, 1);

  for (int i = 1; i <= n; i++)cin >> p[i];

  vector<vector<ll double> > dp(n + 1, vector<ll double>(n + 1, 0));

  dp[0][0] = p[0];

  for (int i = 1; i <= n; i++)
  {
    for (int j = 1 ; j <= i; j++)
    {
      dp[i][j] = dp[i - 1][j - 1] * (1 - p[i]);

      if (j != i)
        dp[i][j] += dp[i - 1][j] * p[i];
    }

    dp[i][0] = dp[i - 1][0] * p[i];
  }

  ll double sum = 0;

  for (int i = 0; i < (n + 1) / 2; i++)
  {
    sum += dp[n][i];
  }

  cout.precision(10) ;

  cout << sum << endl;





}

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

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define X first
#define Y second
#define MP make_pair
#define umap unordered_map

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> P;
typedef unsigned int uint;

int v[110][110];
int main(){
	ios::sync_with_stdio(false);

	int n, m, s, g1, g2;
	while (cin >> n >> m >> s >> g1 >> g2, n){
		--s, --g1, --g2;
		MEMSET(v, 0x7f);
		rep(i, n) v[i][i] = 0;
		rep(i, m){
			int a, b, c;
			cin >> a >> b >> c;
			v[a - 1][b - 1] = c;
		}

		rep(i, n) rep(j, n) rep(k, n) v[j][k] = min((ll)v[j][k], (ll)v[j][i] + v[i][k]);

		ll ans = 1e8;
		rep(i, n){
			ans = min(ans, (ll)v[s][i] + v[i][g1] + v[i][g2]);
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1244
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    string K;
    int D;
    cin >> K >> D;
    int N = K.size();
    for (auto&& c : K) c -= '0';

    vv<vector<ll>> dp = vvec(N + 1, 2, vector<ll>(D));
    dp[0][1][0] = 1;
    rep(i, N) rep(j, 10) rep(k, D) {
        dp[i + 1][0][(j + k) % D] = (dp[i + 1][0][(j + k) % D] + dp[i][0][k]) % MOD;
        if (j < K[i]) dp[i + 1][0][(j + k) % D] = (dp[i + 1][0][(j + k) % D] + dp[i][1][k]) % MOD;
        else if (j == K[i]) dp[i + 1][1][(j + k) % D] = (dp[i + 1][1][(j + k) % D] + dp[i][1][k]) % MOD;
    }

    write((dp[N][0][0] + dp[N][1][0] - 1 + MOD) % MOD);
}

Measured memory_bytes: 17024
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

const INF: i64 = 1 << 60;

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let L: i64 = sc.get();
    let R: i64 = sc.get();
    if R - L + 1 >= 2019 {
        println!("0");
        return;
    }
    let mut ans = INF;
    for i in L..R {
        for j in i+1..R+1 {
            ans = min(ans, (i * j) % 2019);
        }
    }
    println!("{}", ans);
}


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

int main() {
  int N;
  int K;
  cin>>N>>K;
  int sum=1;
  int i=0;
  
  while (i<N) {
    int A=sum*2;
    int B=sum+K;
    if (A<B) {
      sum *= 2;
    }
    
    else {
      sum += K;
    }
    
    i++;
  }
  
  cout<<sum<<endl;
}
      

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

using namespace std;

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

    int x = a-b;
    int y = c-x;

    if(y<0)
        cout<<0<<endl;
    else
        cout<<y<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007;
struct edge {int to,costa,costb;};

signed main() {
int n;
cin>>n;
int x[n][n];
for(int i=0;i<n;i++)fill(x[i],x[i]+n,2);
int a,p,q;
for(int i=0;i<n;i++){
    cin>>a;
    for(int j=0;j<a;j++){
        cin>>p>>q;
        x[i][p-1]=q;
    }
}
int ans=0,t;
for(int i=0;i<(1ll<<n);i++){
    t=1;
    for(int j=0;j<n;j++){
        if(i&(1ll<<j)){
            for(int k=0;k<n;k++){
                if(i&(1ll<<k)){
                    if(x[j][k]==0)t=0;
                }else if(x[j][k]==1)t=0;
            }
        }
    }
    if(t==1){
        t=0;
        for(int j=0;j<n;j++)if(i&(1ll<<j))t++;
        ans=max(ans,t);
    }

}
cout<<ans;

return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  vector<int> A, B;
  A = {1, 3, 5, 7, 8, 10, 12};
  B = {4, 6, 9, 11};
  int C = 12;
  int X, Y;
  cin >> X >> Y;
  int Xa = 0;
  int Xb = 0;
  int Xc = 0;
  rep(i, 6) {
    if(A.at(i) == X) {
      Xa++;
    }
  }
  rep(i,3) {
    if(B.at(i) == X) {
      Xb++;
    }
  }
  if(C == X) {
    Xc++;
  }
  rep(i, 6) {
    if(A.at(i) == Y) {
      Xa++;
    }
  }
  rep(i,3) {
    if(B.at(i) == Y) {
      Xb++;
    }
  }
  if(C == Y) {
    Xc++;
  }
  if(Xa == 2) {
    cout << "Yes" << endl;
  }
  else if(Xb == 2) {
    cout << "Yes" << endl;
  }
  else if(Xc == 2) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N, D, X;
  cin >> N >> D >> X;
  D--;
  int ans = N + X;
  for (int i = 0; i < N; i++)
  {
    int A;
    cin >> A;
    ans += D / A;
  }
  cout << ans << endl;
  return 0;
}


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

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

struct CumulativeSum {
    int n;
    vector<long long> nums;
    vector<long long> s;
    CumulativeSum(int n) : n(n), s(n + 1, 0) { }
    void add(long long num) {
        nums.push_back(num);
    }
    void build() {
        for (int i = 0; i < n; ++i) s[i+1] = s[i] + nums[i];
    }
    // [l, r), l and r is 0-indexed.
    long long sum(int l, int r) {
        return s[r] - s[l];
    }
};

template<typename T>
struct BIT {
    int n;
    vector<T> bit;
    BIT(int _n) : n(_n), bit(_n + 1) { }
    // [0, i], i is 0-indexed.
    T sum(int i) {
        T s = 0;
        for (i++; i > 0; i -= i & -i) s += bit[i];
        return s;
    }
    // [l, r), l and r is 0-indexed.
    T sum(int l, int r) {
        return sum(r - 1) - sum(l - 1);
    }
    void add(int i, T x) {
        for (i++; i <= n; i += i & -i) bit[i] += x;
    }
};

void Main() {
	int N;
	ll K;
	cin >> N >> K;
	vl A(N);
	CumulativeSum cs(N);
	REP(i,N) {
		cin >> A[i];
		cs.add(A[i]);
	}
	cs.build();
	vl SK(N + 1);
	REP(i,N + 1) {
		SK[i] = cs.sum(0, i) - K * i;
	}

	// zaatsu
	vl sortSK;
	for (auto v : SK) sortSK.push_back(v);
	sort(ALL(sortSK));
	sortSK.erase(unique(ALL(sortSK)), sortSK.end());
	vl compSK;
	for (auto v : SK) compSK.push_back(lower_bound(ALL(sortSK), v) - sortSK.begin());

	BIT<int> bit(N + 1);
	ll res = 0;
	REP(i,N + 1) {
		res += bit.sum(0, compSK[i] + 1);
		bit.add(compSK[i], 1);
	}
	cout << res << endl;
}

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


Measured memory_bytes: 13012
n = int(input())
F = [tuple(int(x) for x in input().split()) for _ in range(n)]
P = [tuple(int(x) for x in input().split()) for _ in range(n)]
ans = -10**18
for bit in range(1, 1<<10):
    A = [0] * n  # 被り数
    for i in range(10):
        if bit & (1<<i):  # 開店
            for j in range(n):
                if F[j][i] == 1:
                    A[j] += 1
    profit = 0
    for j in range(n):
        profit += P[j][A[j]]
    ans = max(ans, profit)
print(ans)


Measured memory_bytes: 74136
#include <iostream>
#include <vector>
#include <set>
#include <string>

int main(int argc, const char * argv[]) {
    // for read a input.txt
    
    int N;
    std::cin >> N;
    std::set<std::string> st;
    std::string S;
    for (int i=0; i<N; ++i) {
        std::cin >> S;
        st.insert(S);
    }
    std::cout << st.size() << "\n";
    return 0;
}

Measured memory_bytes: 15744
//#define LOCAL

#include <fstream>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <cstring>
#include <climits>
#include <set>

//#define int long long
//typedef long long ll;
using ll = long long;
//using R = double;

//#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)

#define MOD 1000000007

const int INF = int(1e9);

using namespace std;

typedef vector<int> V;
typedef vector<V> VV;

int N, W;
int v[110], w[110];
int dp[100][10001];

signed main()
{
    cin >> N >> W;
    REP(i,N) cin >> v[i] >> w[i];

    REP(i,W+1) {
        if (i >= w[0]) dp[0][i] = v[0];
    }
    for (int i=1; i<N; i++) {
        REP(j,W+1) {
            if (w[i] <= j) {
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]] + v[i]);
            } else {
                dp[i][j] = dp[i-1][j];
            }
        }
    }

    /*
    REP(i,N) {
        REP(j,W+1) {
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
    cout << endl;
    */

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

    return 0;
}

Measured memory_bytes: 6984
import heapq as hp
n,m=map(int,input().split())
a=list(map(int,input().split()))
a=[-x for x in a]
hp.heapify(a)

for i in range(m):
    t=hp.heappop(a)
    hp.heappush(a,-(-t//2))

print(-sum(a))


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

int main() {
  int x, n;
  cin >> x >> n;
  vector<int> d(102);
  rep(i, n) {
    int p;
    cin >> p;
    d[p] = 1;
  }
  P ans(99999, -1);
  for (int i = 0; i <= 101; ++i) {
    if (d[i] == 1) continue;
    int dif = abs(x - i);
    ans = min(ans, P(dif, i));
  }
  cout << ans.second << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <random>

// boost
//#define USE_BOOST_IN_CODE
#ifdef USE_BOOST_IN_CODE
#include <boost/range.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/strided.hpp>
#include <boost/range/adaptor/transformed.hpp>
#include <boost/format.hpp>
#endif


using ll = long long;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vv = vec<vec<T>>;

//namespace std
//{
//    template<>
//    class hash<Key>
//    {
//    public:
//        size_t operator() (const Key& key) const
//        {
//            size_t seed = 0;
//            auto i_hash = hash<int>()(key.i_th);
//            auto w_hash = hash<int>()(key.W);
//
//            seed ^= i_hash + 0x9e3779b9 + (seed << 6) + (seed >> 2);
//            seed ^= w_hash + 0x9e3779b9 + (seed << 6) + (seed >> 2);
//
//            return seed;
//        }
//    };
//}

void solve()
{
    using namespace std;
    int n;

    while (cin >> n)
    {
        if (n == 0)
            break;

        int p;
        cin >> p;

        vec<int> v(n);
        int stoneNum = p;

        for (int i = 0;; i = (i + 1) % n)
        {
            if (stoneNum == 0)
            {
                stoneNum += v[i];
                v[i] = 0;
            }
            else if (stoneNum == 1 && stoneNum + v[i] == p)
            {
                cout << i << endl;
                break;
            }
            else
            {
                ++v[i];
                --stoneNum;
            }
        }
    }

}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 3084
n = int(input())
h = list(map(int, input().split()))
dp = [0]*n
dp[1] = abs(h[1]-h[0])
for i in range(2,n):
    dp[i] = min(abs(h[i]-h[i-1])+dp[i-1], abs(h[i]-h[i-2])+dp[i-2])
        
print(dp[n-1])

Measured memory_bytes: 20448
#include <bits/stdc++.h>
#define pb emplace_back
#define mp make_pair
#define int long long

using namespace std;

int mod = 1000000007;

bool nok[1000000] = {};
int w[1000000] = {};
int32_t main()
{
	ios::sync_with_stdio(false); cin.tie(NULL); cout.precision(10);
	int n; cin >> n;
	int m; cin >> m;
	w[0] = 1;
	for (int i = 0; i < m; ++i) {
		int o; cin >> o; nok[o] = true;
	}
	if (!nok[1]) {
		w[1] = w[0];
	} 
	for (int i = 2; i <= n; ++i) {
		if (!nok[i]) {
			w[i] = (w[i - 1] + w[i - 2]) % mod;
		} 
	}
	cout << w[n];
}

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

typedef long long ll;
ll n, a[100010], q;
ll v[100010], w[100010], u[100010];

ll func(ll x){
	int l = 0, r = n;
	while(l+1 != r){
		int m = (l + r) / 2;
		ll c = abs(x - (n-1-2*m<0?1e18:a[n-1-2*m]));
		ll d = abs(x - a[n-1-m]);
//		cout << m << " " << c << " " << d << " " << c - d << "\n";
		if(c - d > 0) r = m;
		else l = m;
	}
//	cout << x << " " << r << "\n";
	return u[n-1] - (n-r-1<0?0:u[n-r-1]) + (n-1-2*r<0?0:(n-1-2*r)%2==0?v[n-1-2*r]:w[n-1-2*r]);
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> q;
	for(int i=0; i<n; ++i) cin >> a[i];
	v[0] = a[0];
	for(int i=1; i<n; ++i){
		v[i] = v[i-1];
		w[i] = w[i-1];
		if(i % 2 == 0) v[i] += a[i];
		else w[i] += a[i];
	}
	u[0] = a[0];
	for(int i=1; i<n; ++i)
		u[i] = u[i-1] + a[i];
//	for(int i=0; i<n; ++i)
//		cout << i << " " << v[i] << " " << w[i] << " " << u[i] << "\n";
	while(q--){
		ll x;
		cin >> x;
		cout << func(x) << "\n";
	}
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init));

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

const int PrimeMax = 1500001;
int is_prime[PrimeMax];
void Eratosthenes(int N){
  for(int i = 0; i < N; i++){
    is_prime[i] = 1;
  }
  is_prime[0] = 0;
  is_prime[1] = 0;
  for(int i = 2; i*i < N ; i++){
    if(is_prime[i]){
      for(int j = 0; i * (j + 2) < N; j++){
        is_prime[i *(j + 2)] = 0;
      }
    }
  }
}
ll n,x;
vector<ll> v;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  Eratosthenes(PrimeMax);
  while(cin >> n >> x && n && x){
    v.clear();
    v.resize(n);
    vector<ll> c(x+1,0);
    rep(i,n){
      cin >> v[i];
    }
    sort(all(v));
    rep(i,n){
      rep(j,x+1){
        if(j > v[i]){
          c[j] += c[j-v[i]];
        }
        else if(j == v[i]){
          c[j]++;
        }
      }
    }
    bool f =false;
    for(int i = x; i >= 0; --i){
      if(c[i] != 0 && is_prime[i] == 1){
        cout << i << endl;
        f = true;
        break;
      }
    }
    if(!f) cout << "NA"<<endl;
  }
  return 0;
}

Measured memory_bytes: 22660
import Data.List

main::IO()
main = do
    _ <- getLine
    s <- sort . words <$> getLine
    putStrLn $ checkunique s
    
checkunique :: [String] -> String
checkunique (x:y:ys) = if x == y then "NO" else checkunique (y:ys)
checkunique (x:[]) = "YES"

Measured memory_bytes: 145904
#include <cstdio>
#include <algorithm>
using namespace std;
bool binarySearch(int a[],int key,int n)
{
	int left,right,min;
	left=0;
	right=n;
	while(left<right)
	{
		min=(left+right)/2;
		if(a[min]==key) return true;
		else if(a[min]<key) left=min+1;
		else right=min;
	}
	return false;
}

int main()
{
	int s[100001],t[50001];
	int i,j,sum=0,n,q;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&s[i]);
	sort(s,s+n);
	scanf("%d",&q);
	for(i=0;i<q;i++)
		scanf("%d",&t[i]);
	for(i=0;i<q;i++)
		if(binarySearch(s,t[i],n) ) sum++;
	printf("%d\n",sum);
	return 0;
}


Measured memory_bytes: 3184
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long N = sc.nextLong();
    long A = sc.nextLong();
    long B = sc.nextLong();
    long C = sc.nextLong();
    long D = sc.nextLong();
    long t = Math.abs(A - B);
    String ans = "NO";
    for(long i = 0; i <= N - 1; i++) {
      if((t <= i * D - (N - 1 - i) * C) && (t >= i * C - (N - 1 - i) * D)) ans = "YES";
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23764