akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace AizuOnline
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var a = Console.ReadLine().Split(' ');
            var n = int.Parse(a[0]);
            var m = int.Parse(a[1]);

            var e = new List<string[]>();
            for (int i = 0; i < n; i++)
            {
                e.Add(Console.ReadLine().Split(' '));
            }

            var d = new List<int>();
            for (int i = 0; i < m; i++)
            {
                d.Add(int.Parse(Console.ReadLine()));
            }

            for (int i = 0; i < n; i++)
            {
                var sum = 0;
                for (int j = 0; j < m; j++)
                {
                    sum += Convert.ToInt32(e[i][j]) * d[j];
                }
                Console.WriteLine(sum);
            }
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 9872
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
using namespace std;
// using namespace _gnu_pbds;
#define vb __int128
#define ll long long
#define ld long double
#define full(a) a.begin(),a.end()
#define fr(i,a,b) for(ll i = a ; i < b ; i++)
#define stoink stack<ll>
#define quu queue<ll>
#define quee queue<pair<ll,ll>>
#define vec vector <ll>
#define vg vector<vector<ll> >
#define eg vector<pair<ll,ll>>
#define vgw vector<vector<pair<ll,ll> > >
#define pa pair<ll,ll>
#define pb push_back
#define ff first
#define ss second
#define pre 0.00000000000000000001
#define inf 100000000000000000
#define mod 998244353
#define endl '\n'
int main()
{	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    ll s,n;
        cin >> n >> s;
        vec weight(n+1),val(n+1);
        vec dp(100005,inf);
        fr(i,0,n) cin >> weight[i] >> val[i];
        dp[0] = 0;
            fr(i,0,n)
            for(int j = 100000 ; j >= val[i] ; j--) {
                    dp[j] = min(dp[j],weight[i] + dp[j - val[i]]);
            }
        ll ans = 0;
        fr(i,0,100001) {
            if(dp[i] <= s)
                ans = max(ans,i);
        }
        cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3956
#include <stdio.h>

//acgt
int main(void){
char s[11];
int b[11];
int i;
int count=0;
int result=0;
scanf("%s",s);

for(i=0;i<11;i++){
if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T')
b[i]=1;
else b[i]=0;
}
for(i=0;i<11;i++){
if(b[i]==1)
{count++;if(result<count)result=count;}
else count=0;
}
printf("%d",result);
  return 0;
}

Measured memory_bytes: 128
fun main(args: Array<String>) {

    val bitcoinRate: Double = 380000.0
    var sum: Double = 0.0
    for (i in 1..readLine()!!.toInt()) {
        val (money, unit) = readLine()!!.split(" ")
        if (unit == "JPY") {
            sum += money.toDouble()
        } else {
            sum += money.toDouble() * bitcoinRate
        }

    }
    print(sum)
}

Measured memory_bytes: 37856
package main

import "fmt"

func main() {
	var N, K int
	fmt.Scan(&N, &K)

	h := make([]int, N+K+10)
	for i := 0; i < N; i++ {
		fmt.Scan(&h[i])
	}

	dp := make([]int, N+K+10)
	for i := 1; i < N+K+10; i++ {
		dp[i] = 999999999
	}

	for i := 0; i < N-1; i++ {
		for j := 1; j <= K; j++ {
			dp[i+j] = min(dp[i+j], dp[i]+abs(h[i]-h[i+j]))
		}
	}

	fmt.Println(dp[N-1])
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

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


Measured memory_bytes: 7424
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

bool solve (int n, int [] a)
{
	auto lo = a.reduce !(min);
	auto hi = a.reduce !(max);
	if (hi - lo > 1)
	{
		return false;
	}
	if (hi == lo)
	{
		return lo == n - 1 || lo * 2 <= n;
	}
	auto numLo = a.count (lo);
	auto numHi = a.count (hi);
	auto minHiColors = 1;
	auto maxHiColors = numHi / 2;
	return numLo + minHiColors <= hi && hi <= numLo + maxHiColors;
}

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto a = readln.split.map !(to !(int)).array;
		writeln (solve (n, a) ? "Yes" : "No");
	}
}


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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using ll = long long;
using namespace std;

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

    int n; cin >> n;
    map<int, int> mp;
    REPI(i, n){
        int x; cin >> x;
        mp[x] = i + 1;
    }REPI(i, n) cout << mp[i + 1] << ' ';
}


Measured memory_bytes: 5504
mod=10**9+7

sm=0

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

ans=0

for i in a:
	sm+=i
	sm%=mod

for i in a:
	sm-=i
	sm+=mod
	sm%=mod
	ans+=(i*sm)%mod
	ans%=mod

print(ans)



Measured memory_bytes: 94096
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
#include <map>
#include <cmath>
using namespace std;

#define INF 1e18
#define int long long

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

    if(a * b == 0 || a * b < 0) {
        cout << "Zero" << endl;
        return 0;
    }

    if(a < 0 && b < 0 && (a - b) % 2 == 0) {
        cout << "Negative" << endl;
        return 0;
    }

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


Measured memory_bytes: 256
w, h, n = map(int, input().split())
b = [0, w, 0, h]

for _ in range(n):
    *a, = map(int, input().split())
    s = int((a[2] % 2 - 0.5)*2)
    b[a[2]-1] = s*max(s*a[a[2]//3], s*b[a[2]-1])
print(max((b[1]-b[0]), 0)*max((b[3]-b[2]), 0))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
 
int main(){
 
    int n;
    cin>>n;
    int c0=0,c1=0,c2=0,c3=0;
 
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        if(s=="AC")
            c0++;
        else    
        if(s=="WA")
            c1++;
        else
            if(s=="TLE")
                c2++;
        else
            if(s=="RE") 
                c3++;           
 
    }
    cout<<"AC"<<" x "<<c0<<endl; 
    cout<<"WA"<<" x "<<c1<<endl; 
    cout<<"TLE"<<" x "<<c2<<endl; 
    cout<<"RE"<<" x "<<c3<<endl; 
 
 
    return 0;
}

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

using namespace std;

int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
	
    int N; cin>>N;
    vector<int> D(N);
    for (auto& d : D) cin>>d;
    sort(D.begin(), D.end());
    
    int ans = 0;
    if (N % 2 == 0) {
        ans = D[N/2]-D[N/2-1];
    } 
    cout << ans << endl;
	
    return 0;
}


Measured memory_bytes: 892
import math
X=int(input())
start=math.ceil(math.log(X/100,1.01))
kouza=100
for i in range(0,1000000):
  kouza=math.floor(kouza*1.01)
  #if i % 100 == 0:
    #print(kouza)
  if kouza >= X:
    print(i+1)
    break

Measured memory_bytes: 9236
n = int(raw_input())
a = map(int, raw_input().split())
dp = [0, 0]
p = -1
for x in a:
    if p == x:
        dp = [dp[1], min(dp[0], dp[1]) + 1]
    else:
        dp = [min(dp[0], dp[1]), min(dp[0], dp[1]) + 1]
    p = x
print min(dp)


Measured memory_bytes: 2568
"use strict";

const main =(input)=>{
    let nums = input.split('\n')[1].split(' ').map((n)=>parseInt(n,10));
    let count = 0;

    while(nums.every((n)=> (n%2)===0)){
        count++;
        nums = nums.map((n)=>n/2);
    }
    console.log(count);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7500
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0 ; i < n ; i++) {
            h[i] = sc.nextInt();
        }

        int[] dp = new int[n + 1];
        dp[2] = Math.abs(h[1] - h[0]);
        for (int i =3 ; i < n + 1; i++) {
            dp[i] = Math.min(dp[i - 2] + Math.abs(h[i - 1]-h[i-3]), dp[i - 1] + Math.abs(h[i - 1]-h[i -2]));
        }
        System.out.println(dp[n]);
    }

}

Measured memory_bytes: 50964
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
#include<string>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)

int main(){

	string str;
	cin>>str;

	int N = str.size();
	int start = -1,end= -1;	
	REP(i,N){
		char t = str[i];
		if(str[i+1] == t){
			start = i+1;
			end = i + 2;
			break;
		}
		else if(str[i + 2] == t){
			start = i+1;
			end = i + 3;
		}
	}

	cout<<start<<" "<<end<<endl;
	return 0;


}


Measured memory_bytes: 512
#ifdef __GNUC__
#pragma GCC target("avx2")
#pragma GCC optimize ("O25")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC optimize("unroll-loops")
#define iss std::cin
#endif
#include "bits/stdc++.h"
#define rep(i, times) for(ll i = 0; i < (times); ++i)
#define p(x) (cout << x << "\n")
using ll = long long; using ld = long double; using namespace std;
int main( ) {
	cin.tie(0);	ios::sync_with_stdio(0);
	//class CountOrder a; a.procedures( );
	ll A, B;
	cin >> A >> B;
	p(A * B);

}

Measured memory_bytes: 3648
def isGuumozi(s):
    if len(s) % 2 == 1:
        return False
    elif s[:len(s) // 2] == s[len(s) // 2:]:
        return True
    else:
        return False


S = input()

for i in range(len(S)-1,0,-1):
    if isGuumozi(S[:i]):
        print(len(S[:i]))
        break


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;
const int mod = 1e9+7;

int main() {
    int n; cin >> n;
    vll a(n);
    rep(i,n) {
        ll x; cin >> x;
        a[i] = x;
        if (x == 0) {cout << 0 << endl; return 0;}
    }
    ll sum = 1;
    rep(i,n) {
        if (sum >= inf_l/a[i]+1) {cout << -1 << endl; return 0;}
        else sum *= a[i];
    }
    cout << sum << endl;
}


Measured memory_bytes: 3996
N=io.read"*n"
A={}
t={}
for i=2,N do A[i]=io.read"*n"end
for i=2,N do
if(t[A[i]])then t[A[i]]=t[A[i]]+1
else t[A[i]]=1 end
end
for i=1,N do
print(t[i]or 0)
end


Measured memory_bytes: 6652
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const int n = 3;
int a[n][n];

int main() {
    REP(i,n) REP(j,n) cin >> a[i][j];

    VI x(n), y(n);
    REP(i,101) REP(j,101) REP(k,101){
        x[0] = i;
        x[1] = j;
        x[2] = k;
        y[0] = a[0][0] - x[0];
        y[1] = a[0][1] - x[0];
        y[2] = a[0][2] - x[0];

        bool ok = true;
        REP(p,n) REP(q,n){
            if (x[p] + y[q] != a[p][q]) ok = false;
        }

        if (ok){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}


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

using namespace std;

int main(){
    int n;
    int a[101];
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int j = n-1; j > 0; j--){
        printf("%d ", a[j]);
    }
    printf("%d\n", a[0]);
    return 0;
}


Measured memory_bytes: 3156
/*input
16
0 5 -4 -5 -8 -4 7 2 -4 0 7 0 2 -3 7 7
5 0 8 -9 3 5 2 -7 2 -7 0 -1 -4 1 -1 9
-4 8 0 -9 8 9 3 1 4 9 6 6 -6 1 8 9
-5 -9 -9 0 -7 6 4 -1 9 -3 -5 0 1 2 -4 1
-8 3 8 -7 0 -5 -9 9 1 -9 -6 -3 -8 3 4 3
-4 5 9 6 -5 0 -6 1 -2 2 0 -5 -2 3 1 2
7 2 3 4 -9 -6 0 -2 -2 -9 -3 9 -2 9 2 -5
2 -7 1 -1 9 1 -2 0 -6 0 -6 6 4 -1 -7 8
-4 2 4 9 1 -2 -2 -6 0 8 -6 -2 -4 8 7 7
0 -7 9 -3 -9 2 -9 0 8 0 0 1 -3 3 -6 -6
7 0 6 -5 -6 0 -3 -6 -6 0 0 5 7 -1 -5 3
0 -1 6 0 -3 -5 9 6 -2 1 5 0 -2 7 -8 0
2 -4 -6 1 -8 -2 -2 4 -4 -3 7 -2 0 -9 7 1
-3 1 1 2 3 3 9 -1 8 3 -1 7 -9 0 -6 -8
7 -1 8 -4 4 1 2 -7 7 -6 -5 -8 7 -6 0 -9
7 9 9 1 3 2 -5 8 7 -6 3 0 1 -8 -9 0
*/
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const ll INF64=4e18;
const int INF=1e6+1;
const ll MOD=1e9+7;
const ld PI=2*acos(0);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
ll mult(ll a,ll b){
    return ((a%MOD)*(b%MOD))%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}

// default code end
const ll maxn=16;
const ll maxlg=__lg(maxn)+2;
ll arr[maxn][maxn];
ll pre[(1<<maxn)];
vector<ll> dp;
void rec(int i,vector<int>& v,ll score,int msk,int group){
    if(i==sz(v)){
        MXTO(dp[msk],score+pre[group]);
        return;
    }
    rec(i+1,v,score,msk,group);
    rec(i+1,v,score,(msk^(1<<v[i])),(group^(1<<v[i])));
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    REP(i,n) REP(j,n) cin>>arr[i][j];

    REP(i,(1<<n)){
        vector<int> v;
        REP(j,n){
            if(i&(1<<j)) v.pb(j);
        }
        REP(j,sz(v)){
            for(int k=j+1;k<sz(v);k++){
                pre[i]+=arr[v[j]][v[k]];
            }
        }
    }
    dp.resize((1<<n),-INF);
    dp[0]=0;
    REP(i,(1<<n)){
        vector<int> v;
        REP(j,n){
            if(!(i&(1<<j))){
                v.pb(j);
            }
        }
        rec(0,v,dp[i],i,0);
    }
    cout<<dp[(1<<n)-1];
}

Measured memory_bytes: 1280
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
#define du3(a,b,c) scanf("%d %d %d",&(a),&(b),&(c))
#define du2(a,b) scanf("%d %d",&(a),&(b))
#define du1(a) scanf("%d",&(a));
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) { if (a == 0ll) {return 0ll;} a %= MOD; ll ans = 1; while (b) {if (b & 1) {ans = ans * a % MOD;} a = a * a % MOD; b >>= 1;} return ans;}
void Pv(const vector<int> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%d", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
void Pvl(const vector<ll> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%lld", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
inline long long readll() {long long tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
inline int readint() {int tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int n;
ll h[maxn];
ll b, a;
bool check(ll x)
{
	ll res = x;
	repd(i, 1, n)
	{
		ll temp = h[i] - x * b;
		if (temp > 0)
		{
			ll need = temp / (a - b);
			if (temp % (a - b) != 0)
			{
				need++;
			}
			res -= need;
			if (res < 0)
			{
				break;
			}
		}
	}
	return res >= 0;
}
int main()
{
	//freopen("D:\\code\\text\\input.txt","r",stdin);
	//freopen("D:\\code\\text\\output.txt","w",stdout);
	n = readint();
	a = readll();
	b = readll();
	repd(i, 1, n)
	{
		h[i] = readll();
	}
	ll l = 1ll;
	ll r = inf;
	ll mid;
	ll ans;
	while (l <= r)
	{
		mid = (l + r) >> 1;
		if (check(mid))
		{
			ans = mid;
			r = mid - 1;
		} else
		{
			l = mid + 1;
		}
	}
	printf("%lld\n", ans );
	return 0;
}




Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

ll min_self(ll a, ll b){
    return a < b? a:b;
}
int main(){
	FAST_IO;
    ll n,W;
    cin >> n >> W;
    ll w[n+1], v[n+1];
    ll V = 0; 
    w[0] = 0; 
    v[0] = 0;  
    for(int i=1; i <= n; i++){
        cin >> w[i] >> v[i];
        V += v[i];
    }
    //cout << V << endl; 
    ll dp[n+1][V+1]; // minm total weights of items with value exactly v
    
    for(int i=1; i <= n; i++){
        dp[i][0] = 0;
    }
    for(int i=0; i <=V; i++)
        dp[0][i] = INT_MAX; 
    dp[0][0] = 0; 
    for(int i =1; i <= n; i++){
       //trace1(i);
        for(int val = 1; val <= V; val++){
            if(val - v[i] >= 0){
                dp[i][val] = min_self( (dp[i-1][val - v[i]] + w[i]) , (dp[i-1][val]));
            }
            else{
                dp[i][val] = dp[i-1][val]; 
            }
        }
    }

    //cout << dp[n][V] << endl; 
    int ans = -1;
    for(int j=1; j <= n; j++){
        for(int i=1; i <= V; i++){
            //cout << dp[j][i] << " ";
            if(dp[j][i] <= W && dp[j][i] > 0){
                if(i > ans){
                    ans = i;
                }
            }
        }
        //cout << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 79232
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<string>
#include<utility>
#include<algorithm>
#include<stack>
#include<queue>

#define numof(array) (sizeof (array) / sizeof *(array))
using namespace std;

#define INF (1 << 29)
static const int dx[] = {1, 0, -1, 0};
static const int dy[] = {0, 1, 0, -1};

#define MAX_R 10
#define MAX_C 10000

int original_osenbei[MAX_R][MAX_C];
int osenbei[MAX_R][MAX_C];
int R;
int C;

void yoko_uragaeshi(int line)
{
    for (int i = 0; i < C; i++) {
        osenbei[line][i] = (osenbei[line][i] + 1) % 2;
    }

}

// void tate_uragaeshi(int line)
// {
//     for (int i = 0; i < R; i++) {
//         osenbei[i][line] = (osenbei[i][line] + 1) % 2;
//     }

// }

int tate_count(int line)//0をカウント
{
    int cnt = 0;
    for (int i = 0; i < R; i++) {
        if (osenbei[i][line] == 0) cnt++;
    }

    return cnt;
}

void print_senbei(int index)
{
    cout << endl <<"==========" << index << endl;
    for (int i = 0; i < R; i++) {
        for (int j = 0; j < C; j++) {
            cout << osenbei[i][j];
    
        }
        cout << endl;
    }
}

void copy_osenbei(void)
{
    for (int i = 0; i < R; i++) {
        for (int j = 0; j < C; j++) {
            osenbei[i][j] = original_osenbei[i][j];
        }
    }    


}

int uragaeshi(void)
{
    int max_num = 0;
    
    for (int i = 0; i < (1 << R); i++) {//2^R通り
        int osenbei_count = 0;
        copy_osenbei();
        for (int j = 0; j < R; j++) {
            if (i & (1 << j)) yoko_uragaeshi(j);        
        }

        
        int count_tmp = 0;
        for (int k = 0; k < C; k++) {
            count_tmp = tate_count(k);//ひっくり返す前の0の個数

            if (count_tmp * 2 < R) {
                osenbei_count += R -count_tmp;
            } else {
                osenbei_count += count_tmp;
            }
        }
        max_num = max(max_num, osenbei_count); 

    }

    return max_num;

}


int main(void)
{
    while (cin >> R >> C) {
        if (R == 0 && C == 0) break;
        
        for (int i = 0; i < MAX_R; i++) {
            for (int j = 0; j < MAX_C; j++) {
                original_osenbei[i][j] = 0;
            }
        }

        for (int i = 0; i < R; i++) {
            for (int j = 0; j < C; j++) {
                cin >> original_osenbei[i][j];
            }
        }

        cout << uragaeshi() << endl;
    }
        return 0;
}

Measured memory_bytes: 1940
#include <iostream>
#include <math.h>
#include <algorithm>
#define ll long long int
#define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n)

using namespace std;

int main()
{
    string b;
    cin >> b;
    if (b == "A")
        cout << "T" << endl;
    else if (b == "T")
        cout << "A" << endl;
    else if (b == "C")
        cout << "G" << endl;
    else
        cout << "C" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int a=0,b=0;
    cin>>a;
    cin>>b;
    int c=0;
    while(a>=0){
        a=a-b;
        if(a==0){
            c-=1;
        }
        c+=1;
    }
    cout<<c;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<ll(n); i++)
#define REPR(i, n) for(ll i=n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=m; i<ll(n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(x) ll(x.size()) 
using P = pair<int, int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 2e9;
const ll LINF = (1LL<<60);

int dp[1005][4100];

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,m; cin >> n >> m;
  vector<int> a(m), key(m, 0);
  REP(i,m){
    int b; cin >> a[i] >> b;
    REP(k,b){
      int c; cin >> c; c--;
      key[i] |= (1<<c);
    }
  }

  REP(i,m+1) REP(j,(1<<n)) dp[i][j] = INF;
  dp[0][0] = 0;
  REP(i,m) REP(j,(1<<n)){
    chmin(dp[i+1][j], dp[i][j]);
    chmin(dp[i+1][j | key[i]], dp[i][j] + a[i]);
  }
  cout << (dp[m][(1<<n)-1]== INF ? -1 : dp[m][(1<<n)-1]) << endl;
  return 0;
}


Measured memory_bytes: 19580
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vll a(n+1);
    vll sum(n+2,0LL);
    REP(i,n+1){
        cin >> a[i];
        sum[i+1] = sum[i]+a[i];
    }
    if(n==0){
        if(a[0]==1){
            cout << 1 << endl;
        }else{
            cout << -1 << endl;
        }
        return 0;
    }
    if(a[0]>0){
        cout << -1 << endl;
        return 0;
    }
    ll mx = 2;
    if(sum[n+1]==1){
        mx = 1;
    }
    ll ans = 1;
    for(ll dp = 1;dp<=n;++dp){
        if(a[dp]>mx){
            cout << -1 << endl;
            //cout << dp << endl;
            return 0;
        }
        ans += mx;
        mx -= a[dp];
        //cout << dp << ":" << mx << endl;
        mx = min(mx*2, sum[n+1]-sum[dp+1]);
        //cout << dp << "-" << mx << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4780
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

int main() {

    int N;
    cin >> N;

    vector<int> v(N);
    for (int i = 0; i < N; i++)cin >> v[i];

    map<int, int> even_m1, odd_m1;
    for (int i = 0; i < N; i++) {
        if (i % 2 == 0) even_m1[v[i]]++;
        if (i % 2 == 1) odd_m1[v[i]]++;
    }

    vector<pair<int, int>> even_p, odd_p;
    for (auto x: even_m1) even_p.push_back(make_pair(N / 2 + N % 2 - x.second, x.first));
    for (auto x: odd_m1) odd_p.push_back(make_pair(N / 2 - x.second, x.first));
    even_p.push_back(make_pair(N / 2 + N % 2, 83981123));
    odd_p.push_back(make_pair(N / 2, 83981121));
    sort(even_p.begin(), even_p.end());
    sort(odd_p.begin(), odd_p.end());

    if (even_p.front().second != odd_p.front().second) {
        long long ans = even_p.front().first + odd_p.front().first;
        cout << ans << endl;
    } else {
        long long ans1 = even_p[1].first + odd_p[0].first;
        long long ans2 = even_p[0].first + odd_p[1].first;
        cout << min(ans1, ans2 ) << endl;
    }

}


























































Measured memory_bytes: 6520
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N=2e5+10;
int a[N];
int main()
{
	ios::sync_with_stdio(0);
    int n,k; cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>a[i];
    sort(a+1,a+1+n,greater<int>() );
    LL sum=0;
    for(int i=k+1;i<=n;i++)
		sum+=a[i];
	cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(n) n.begin(),n.end()
struct P{
	int x,y;
	P(){}
	P(int a,int b){x=a,y=b;}
};

vector< pair<P,P> > data;

int compress(vector<int> &ux,int W,char type){
	int width = 0;
	sort(all(ux));
	ux.erase(unique(all(ux)),ux.end());
	int st = (ux[0]?1:0);
	for(int i=1;i<ux.size();i++){
		rep(j,data.size()){
			if(type == 'x'){
				if(data[j].first.x == ux[i-1])
					data[j].first.x = st;
				if(data[j].second.x == ux[i-1])
					data[j].second.x = st;
			}else{
				if(data[j].first.y == ux[i-1])
					data[j].first.y = st;
				if(data[j].second.y == ux[i-1])
					data[j].second.y = st;
			}
		}
		if(ux[i]-1 == ux[i-1]) st += 1;
		else st += 2;
	}
	
	rep(j,data.size()){
		if(type == 'x'){
			if(data[j].first.x == ux.back())
				data[j].first.x = st;
			if(data[j].second.x == ux.back())
				data[j].second.x = st;
		}else{
			if(data[j].first.y == ux.back())
				data[j].first.y = st;
			if(data[j].second.y == ux.back())
				data[j].second.y = st;
		}
	}
	return st+(ux.back()!=W);
}
int main(){
	int W,H;
	while(cin >> W >> H , W){
		int ret = 0;
		vector<int> ux,uy;
		int n; cin >> n;
		data.resize(n);
		rep(i,n){
			cin >> data[i].first.x >> data[i].first.y >> data[i].second.x >> data[i].second.y;
			ux.push_back(data[i].first.x) , ux.push_back(data[i].second.x);
			uy.push_back(data[i].first.y) , uy.push_back(data[i].second.y);
		}
		W = compress(ux,W,'x');
		H = compress(uy,H,'y');
		bool get[1000][1000]={0};
		rep(i,n){
			for(int x = data[i].first.x ; x < data[i].second.x ; x++){
				for(int y = data[i].first.y ; y < data[i].second.y ; y++){
					get[y][x] = 1;
				}
			}
		}
		stack<pair<int,int> > S;
		static const int dx[] = {0,0,-1,1} , dy[]={1,-1,0,0} ;
		rep(i,H)rep(j,W){
			if(get[i][j] == 0){
				ret++;
				S.push(make_pair(i,j));
				while(S.size()){
					int x = S.top().second, y = S.top().first; S.pop();
					rep(i,4){
						int tx = x + dx[i] , ty = y + dy[i];
						if(ty >= 0 && tx >= 0 && ty < H && tx < W && get[ty][tx] == 0){
							get[ty][tx] = 1;
							S.push(make_pair(ty,tx));
						}
					}
				}
			}
		}
		cout << ret << endl;
	}
}

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

int main() {
    vector<int> a(9);
    for(int i = 0; i < 9; i++) {
        cin >> a[i];
    }
    
    int n;
    cin >> n;
    int b;
    for(int i = 0; i < n; i++) {
        cin >> b;
        for(int j = 0; j < 9; j++) {
            if(a[j] == b) {
                a[j] = 0;
                break;
            }
        }
    }

    /*
    for(int i = 0; i < 3; i++) {
        for(int j = 0; j < 3; j++) {
            cout << a[i * 3 + j] << " ";
        }
        cout << endl;
    }
    */

    bool is_bingo = false;
    if((a[0] + a[1] + a[2] == 0) || (a[3] + a[4] + a[5] == 0) || (a[6] + a[7] + a[8] == 0)
    || (a[0] + a[3] + a[6] == 0) || (a[1] + a[4] + a[7] == 0) || (a[2] + a[5] + a[8] == 0)
    || (a[0] + a[4] + a[8] == 0) || (a[2] + a[4] + a[6] == 0)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
using namespace std;

int main(){
  
    int x,a,b;
    cin>>x>>a>>b;
    int ans=(x-a)%b;
    cout<<ans<<endl;
   


return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int sum[2][4];
int main(void)
{
	float sl[40], sr[40];
	int i = 0;
	
	while (scanf("%f %f", &sl[i], &sr[i]) != EOF){
		if (sl[i] >= 1.1){
			sum[0][0]++;
		}
		else if (sl[i] >= 0.6){
			sum[0][1]++;
		}
		else if (sl[i] >= 0.2){
			sum[0][2]++;
		}
		else {
			sum[0][3]++;
		}
		
		if (sr[i] >= 1.1){
			sum[1][0]++;
		}
		else if (sr[i] >= 0.6){
			sum[1][1]++;
		}
		else if (sr[i] >= 0.2){
			sum[1][2]++;
		}
		else {
			sum[1][3]++;
		}
		
		i++;
	}
	
	for (i = 0; i < 4; i++){
		printf("%d %d\n", sum[0][i], sum[1][i]);
	}
	
	return 0;
}

Measured memory_bytes: 624
n = int(input())
txy = [[0,0,0]]+[list(map(int,input().split())) for i in range(n)]

for i in range(n):
  if txy[i+1][0] - txy[i][0] < abs(txy[i+1][1] - txy[i][1]) + abs(txy[i+1][2] - txy[i][2]):
    print('No')
    exit()
  else:
    if (txy[i+1][0] - txy[i][0])%2 == 0 and (abs(txy[i+1][1] - txy[i][1]) + abs(txy[i+1][2] - txy[i][2]))%2 != 0:
      print('No')
      exit()
    elif (txy[i+1][0] - txy[i][0])%2 != 0 and (abs(txy[i+1][1] - txy[i][1]) + abs(txy[i+1][2] - txy[i][2]))%2 == 0:
      print('No')
      exit()
      
print('Yes')
      
    

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

int main() {
  int A1, A2, A3;
  cin >> A1 >> A2 >> A3;
  int wa = A1 + A2 + A3;
  string ans;
  if(wa >= 22) ans = "bust";
  else         ans = "win";

  cout << ans << endl;
}


Measured memory_bytes: 256
def resolve():
    '''
    code here
    '''
    N, K = [int(item) for item in input().split()]
    As = [int(item) for item in input().split()]

    for i in range(K,N):
        if 1 < As[i] / As[i - K]:
            print('Yes')
        else:
            print('No')
        

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 94256
import sys,queue,math,copy,itertools,bisect,collections,heapq
LI = lambda : [float(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
N = NI()
p = LI()
dp = [[0] * (N+1) for _ in range(N+1)]
dp[0][0] = 1
for i in range(1,N+1):
    for j in range(0,i+1):
        if j > 0: dp[i][j] = dp[i-1][j-1] * p[i-1]
        dp[i][j] += dp[i-1][j] * (1-p[i-1])

print(sum(dp[-1][N//2+1:]))


Measured memory_bytes: 255240
#include <iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<string>
#include<queue>
#include<set>
#include<vector>
#include<cmath>
#include<stack>
#include<map>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
double na,nb;
int a,b;
int main()
{
    cin>>a>>b;
    na=a*12.5;
    nb=b*10.0;
    if(nb>=na+12.5||na>=nb+10)
    {
        cout<<-1<<endl;
        return 0;
    }
    int flag=0;
    for(int i=0;i<10;i++)
    {
        if(nb<(na+12.5)&&nb>=na)
        {
            flag=1;
            break;
        }
        nb++;
    }
    if(flag)cout<<nb<<endl;
    else cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
#define ll long long int
using namespace std;
int main(){
    string s1,s2;
    cin>>s1>>s2;
    s1="*"+s1;
    s2="*"+s2;
    ll sl1=s1.length();
    ll sl2=s2.length();
    ll dp[sl1][sl2];
    for(ll i=0;i<sl1;i++)
    {
        for(ll j=0;j<sl2;j++)
        {

            if((i==0) || (j==0))   dp[i][j]=0;
            else if( s1[i]==s2[j]) dp[i][j]=1+dp[i-1][j-1];
            else                   dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
        }
    }
    /*
    for(ll i=0;i<sl1;i++)
    {
        for(ll j=0;j<sl2;j++)
        {
                cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }
    */

    string ans="";

    for(ll i=sl1-1,j=sl2-1 ;  ;)
	{
		if(dp[i][j]==1+dp[i-1][j-1] && s1[i]==s2[j])
		{
		    char y=s1[i];
			ans = y+ans;
			i--;j--;
		}
		else if(dp[i][j]==dp[i-1][j])  i--;

		else                           j--;


		if(i<=0 || j<=0)   break ;
	}
    cout<<ans<<endl;
}


Measured memory_bytes: 70656
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int a,b,k,cnt=0; cin>>a>>b>>k;
    for(int i=100;i>0;i--){
        if(a%i==0 && b%i==0) cnt++;
        if(cnt==k){
            cout<<i<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3588
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<iomanip>
#include<map>
#include<cstring>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const ll LLINF = 4 * 1e18;
/* -- template -- */
int main() {
    int N, K; cin >> N >> K;
    int cnt[N + 1];
    rep(i, N + 1)cnt[i] = INF;
    rep(i, N) {
        int a; cin >> a;
        if(cnt[a] == INF)cnt[a] = 1;
        else ++cnt[a];
    }
    sort(cnt, cnt + N + 1);
    int kk = 0;
    rep(i, N + 1){
        if(cnt[i] == INF)break;
        ++kk;
    }
    int ans = 0;
    rep(i, kk - K)
        ans += cnt[i];
    cout << ans << endl;
}


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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const int MOD = 1000000007;
const int MX = 100010;

inline void add(int &x, int y) { x += y; if (x >= MOD) x -= MOD; }

const int MN = 100010;

// 1-indexed, [1, n]
template<class T>
class BIT {
	T bit[MN];
	int n;

public:
	BIT() {
		n = MN;
		memset(bit, 0, sizeof(bit));
	}

	T sum(int i) {
		++i;
		T s = 0;
		while (i > 0) {
			s += bit[i];
			s %= MOD;
			i -= i & -i;
		}
		return s;
	}

	void add(int i, T x) {
		++i;
		while (i < n) {
			bit[i] += x;
			bit[i] %= MOD;
			i += i & -i;
		}
	}
};

int N, M;
int x[MX], y[MX];

int main() {
	scanf("%d%d", &N, &M);

	rep(i, N) {
		scanf("%d", &x[i]);
	}

	rep(i, M) {
		scanf("%d", &y[i]);
	}

	vector<pii> vec;
	vi ys;

	rep(i, N) {
		int lo = upper_bound(y, y + M, x[i]) - y;
		if (lo == 0) {
			continue;
		}
		--lo;
		int l = x[i] - y[lo];

		lo = lower_bound(y, y + M, x[i]) - y;
		if (lo == M) {
			continue;
		}
		int r = y[lo] - x[i];

		if (l == 0 || r == 0) {
			continue;
		}
		vec.eb(l, r);
		ys.eb(r);
	}

	sort(ALL(vec));
	sort(ALL(ys));
	ys.erase(unique(ALL(ys)), ys.end());
	vec.erase(unique(ALL(vec)), vec.end());
	N = vec.size();

	rep(i, N) {
		int y = vec[i].se;
		vec[i].se = lower_bound(ALL(ys), y) - ys.begin();
	}

	BIT<int> T;
	T.add(0, 1);

	int i;
	int now = 0;

	for (i = 0; i < N;) {
		int j = i;
		while (j < N && vec[j].fi == vec[i].fi) {
			++j;
		}

		for (int k = j-1; k >= i; --k) {
			int r = T.sum(vec[k].se);
			T.add(vec[k].se + 1, r);
		}

		++now;
		i = j;
	}

	cout << T.sum(N + 1) << endl;
	return 0;
}

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

#define loop(s, e, i) for (int i=s; i<e; ++i)
#define print(s) cout << s << endl;
using namespace std;
using ll = long long;

/*
浮動小数点の入力
cout << fixed << setprecision(9) << endl;
*/

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  while(b != 0) {
    ll tmp = b;
    b = a % b;
    a = tmp;
  }
  return a;
}

int main() {
  ll A, B, C, D;
  cin >> A >> B >> C >> D;

  // CかDで割り切れるものの数
  ll g = C*D/gcd(C, D);
  ll n1 = (A-1)/C + (A-1)/D - (A-1)/g;
  ll n2 = B/C + B/D - B/g;
  print(B-n2-(A-1-n1));
}

Measured memory_bytes: 3600
#include<iostream>
#include<cstdio>
using namespace std;
int n,a[200001];
bool checx(int x)
{
    if((a[n-1]<=x&&a[n]<=x)||(a[n]<=x&&a[n+1]<=x))return 1;
    if((a[n-1]> x&&a[n]> x)||(a[n]> x&&a[n+1]> x))return 0;
    for(int i=1;i<n-1;i++){
        if((a[n+i]<=x&&a[n+i+1]<=x)||(a[n-i]<=x&&a[n-i-1]<=x))return 1;
        if((a[n+i]> x&&a[n+i+1]> x)||(a[n-i]> x&&a[n-i-1]> x))return 0;
    }
    return a[1]<=x;
}

int main(){
    cin>>n;
    for(int i=1;i<n<<1;i++)cin>>a[i];
    int l=1,r=(n<<1)-1;
    while(l<r)
	{
        int mid=(l+r)/2;
        if(checx(mid))r=mid;
        else l=mid+1;
    }
    cout<<l;
}


Measured memory_bytes: 1024
object Main extends App {

  val Array(a,b,c,x,y) = scala.io.StdIn.readLine().split(" ").map(_.toInt)

  def solve(): Long = {
    val AandB = a * x + b * y
    val z = Math.max(x, y) * 2
    val AB = c * z
    val defaultMin = Math.min(AandB, AB)
    (z-2 to 2 by -2).foldLeft(defaultMin) { case (acc, i) =>
      val priceAB = c * i
      val priceA = Math.max(0, x - i / 2) * a
      val priceB = Math.max(0, y - i / 2) * b
      Math.min(acc, priceA + priceB + priceAB)
    }
  }
  println(solve)

}

Measured memory_bytes: 31788
a = input()
N = len(a)
c = []
temp = int(1)
ans = int(0)
for i in range(N):
    if i != N-1:
      if a[i] == a[i+1]:
        temp += 1
      else:
        c.append(temp)
        temp = 1
    else:
      if a[i-1] == a[i]:
        c.append(temp)
      else:
        c.append(1)

clen = len(c)

if a[0] == "<" and clen % 2 == 1:
    c.append(0)
elif a[0] == ">" and clen % 2 == 0:
    c.append(0)

if a[0] == "<":
    for i in range(0,clen,2):
        maxi = max([c[i],c[i+1]])
        mini = min([c[i],c[i+1]])
        ans += maxi*(maxi+1)/2
        ans += mini*(mini-1)/2
else:
    ans += c[0]*(c[0]+1)/2
    for i in range(1,clen,2):
        maxi = max([c[i],c[i+1]])
        mini = min([c[i],c[i+1]])
        ans += maxi*(maxi+1)/2
        ans += mini*(mini-1)/2
    
print(int(ans))

Measured memory_bytes: 11880
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) int((a).size())

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    ll n,a,b,i;
    cin>>a>>b;
    ll n1,n2;
    for(i=1;i<=10000;i++)
    {
        n1 = floor(0.08*i);
        n2 = floor(0.1*i);
        if(n1==a && n2==b) {cout<<i;return 0;}
    }
    cout<<-1;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();

		String[] WHxyr = line.split(" ");
		int[] Z = new int[WHxyr.length];

		for (int i = 0; i < WHxyr.length; i++) {
			Z[i] = Integer.parseInt(WHxyr[i]);
		}

		if (Z[2] - Z[4] >= 0 && (Z[2] + Z[4]) <= Z[0] && Z[3] - Z[4] >= 0
				&& Z[3] + Z[4] <= Z[1]) {
			System.out.println("Yes");

		} else {
			System.out.println("No");
		}

	}

}



Measured memory_bytes: 26352
h,w,k=map(int,input().split())
c=[list(input()) for i in range(h)]
ans=0
for maskR in range(1<<h):
    for maskC in range(1<<w):
        black=0
        for i in range(h):
            for j in range(w):
                if ((maskR>>i)&1)==0 and ((maskC>>j)&1)==0 and c[i][j]=='#':
                    black+=1
        if black==k:
            ans+=1
print(ans)

Measured memory_bytes: 9092
#include <iostream>
#include <cstring>
#include<vector>
#include <algorithm>
#include<cstdlib>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)

int main()
{
    ll n, d;
    cin >> n >> d;
    vector<vector<ll>> k(n, vector<ll>(2));
    int ans = 0;
    rep(i, n)
    {
        cin >> k[i][0] >> k[i][1];
    }
    rep(i, n)
    {
        if (k[i][0] * k[i][0] + k[i][1] * k[i][1] <= d * d)
        {
            ans++;
        }
    }

    cout << ans << "\n";

    
    return 0;
}

Measured memory_bytes: 14008
import java.util.Scanner;

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

        String s = sc.next();

        System.out.println(solve(s));

        sc.close();
    }

    static String solve(String s) {
        StringBuilder result = new StringBuilder();
        for (char ch : s.toCharArray()) {
            if (ch == 'B') {
                if (result.length() != 0) {
                    result.deleteCharAt(result.length() - 1);
                }
            } else {
                result.append(ch);
            }
        }

        return result.toString();
    }
}

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

int main(){
while(1){
int H,W;
cin>>H>>W;

if(H==0 && W==0) break;

for(int i=0; i<H; i++){
for(int j=0; j<W; j++){
if(i==0 ||i==H-1 ||j==0 || j==W-1)
cout<<"#";
else cout<<".";
}
cout<<endl;
}
cout<<endl;
}

return 0;
}


Measured memory_bytes: 3068
#include <iostream> 
#include <vector> 
#include <algorithm> 
#include <bits/stdc++.h> 
#include <stdlib.h> 
#include <stdio.h> 
#include <functional> 
#include<math.h> 
#include<cstring>
using namespace std;
int main(void){
    // Your code here!
    int N;
    string S_1,S_2;
    cin >> N >> S_1 >> S_2;
    long long count = 3;
    int mae = 0; //0なら縦　1なら横
    int i = 1;
    if(N > 1 && S_1.at(0) == S_1.at(1)){
        mae = 1;
        i = 2;
        count *= 2;
    }
    
    
    while(i < N){
        if(i+1 < N && S_1.at(i) == S_1.at(i+1)){ //横
            if(mae == 1){
                i += 2;
                count *= 3;
                count %= 1000000007;
                mae = 1;
            }
            else{
                i += 2;
                count *=2;
                count %= 1000000007;
                mae = 1;
            }
        }
        else{ // 縦
            if(mae == 1){
                i++;
                mae = 0;
            }
            else{
                i++;
                count *= 2;
                count %= 1000000007;
                mae = 0;
            }
            
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner (System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		Integer[] arr = new Integer[n];
		int sum = 0;
		for (int i=0; i<n; i++) {
			arr[i] = sc.nextInt();
			sum += arr[i];
		}
		
		Arrays.sort(arr, Collections.reverseOrder());
		double limit = (double) sum/(4*m);

		if (arr[m-1] >= limit) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
	}
}


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

int n, m, x;
int c[12], a[12][12];
bool read[12];
int ans;

void dfs(int depth, int pre) {
    if (depth == n - 1) {
        int skill[12];
        for (int i = 0; i < m; i++) skill[i] = 0;

        for (int i = 0; i < n; i++) {
            if (read[i]) {
                for (int j = 0; j < m; j++) skill[j] += a[i][j];
            }
        }

        for (int i = 0; i < m; i++) {
            if (skill[i] < x) return;
        }

        ans = min(pre, ans);
        return;
    }

    read[depth + 1] = true;
    dfs(depth + 1, pre + c[depth + 1]);
    read[depth + 1] = false;
    dfs(depth + 1, pre);
}

int main() {
    cin >> n >> m >> x;
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }

    ans = 1200001;
    read[0] = true;
    dfs(0, c[0]);
    read[0] = false;
    dfs(0, 0);

    if (ans == 1200001) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
}

Measured memory_bytes: 3592
from fractions import gcd
# from datetime import date, timedelta
# from heapq import *
import heapq
import math
from collections import defaultdict, Counter, deque
from bisect import *
import itertools
import fractions
import sys
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
# input = sys.stdin.readline


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

import random
def main():
    s = list(input())
    n = len(s)
    if n == 3:
        if s[0] == s[2]:
            print("Yes")
        else:
            print("No")
        exit()
    
    a = s[:(n - 1) // 2]
    b = s[(n + 3) // 2-1:]
    # print(a,b)
    for i in range(len(a) // 2):
        if (a[i] != a[len(a) - 1 - i]):
            print("No")
            exit()


    for i in range(len(b) // 2):
        if (b[i] != b[len(b) - 1 - i]):
            print("No")
            exit()

    for i in range(len(s) // 2):
        if (s[i] != s[len(s) - 1 - i]):
            print("No")
            exit()
    print("Yes")

if __name__ == '__main__':
    main()


Measured memory_bytes: 6620