akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
  ll cnt[1110]={};
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  vvi E(n+10);
  for(int i=0;i<n;i++){
    for(int j=0;j<n-1;j++){
      ll a;cin>>a;
      E[i].pb(--a);
    }
  }
  ll ans=0;
  ll hoge=0;
  while(hoge<n){
    bool used[n+10]={};
    ll cn=0;
    for(int i=0;i<n;i++){
      if(cnt[i]==n-1)continue;
      ll to=E[i][cnt[i]];
      if(used[i]==false&&used[to]==false){
	if(E[to][cnt[to]] == i){
	  //	  cout<<i<<" "<<E[i][cnt[i]]<<" "<<to<<endl;
	  cnt[to]++;
	  cnt[i]++;
	  used[to]=true;
	  used[i]=true;
	  cn++;
	  if(cnt[to]==n-1)hoge++;
	  if(cnt[i]==n-1)hoge++;
	}
      }
    }
    //    cout<<cnt[0]<<" "<<cnt[1]<<" "<<cnt[2]<<" "<<cnt[3]<<endl;
    if(cn==0){
      cout<<-1<<endl;return 0;
    }
    ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 10368
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);       
		int n = sc.nextInt();
        int q = sc.nextInt();
		int [] L = new int [n];
        String s = sc.next();
        L[0]=0;       
        for(int i=1;i<n;i++){if(s.substring(i-1,i+1).equals("AC")){L[i]=L[i-1]+1;}
                                else{L[i]=L[i-1];}
                            }        
	    for(int i=0;i<q;i++){int l = sc.nextInt();
                             int r = sc.nextInt();
                             System.out.println(L[r-1]-L[l-1]);}
  }
}

Measured memory_bytes: 67240
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<cmath>
 
#define rep(i,x) for(int i=0;i<(int)(x);i++)
#define reps(i,x) for(int i=1;i<=(int)(x);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)
 
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e9
#define MOD 1000000007
 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef std::pair<ll, ll> P;
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}

typedef std::pair<ll, ll> P;

bool pairCompare(const P& firstElof, const P& secondElof)
{
    return firstElof.second < secondElof.second;
}
 
using namespace std;

int main()
{
    ll n;
    cin >> n;
    vector<double> v(n);
    rep(i, n) cin >> v[i];

    sort(all(v));

    double ans = v[0];

    rep(i, n-1){
        ans = (ans + v[i+1])/2.0;
    }

    cout << ans;
}

Measured memory_bytes: 256
def input_from_console():
    a, b = map(int, input().split())
    return a, b


def solve(a, b):
    def check(num):
        if num > 9 or num < 1:
            return 0
        return num
    result = check(a) * check(b)
    if result == 0:
        return -1
    return result


def main():
    a, b = input_from_console()
    print(solve(a, b))


if __name__ == "__main__":
    import sys

    if sys.gettrace():  # Check if the python interpreter is in debug mode or not.
        check_cases()
    else:
        main()


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
#define N 4002
int n;
int a[200002],b[200002];
bool jud(int x)
{
	for(int i=1;i<2*n;i++)
	{
		if(a[i]<=x)b[i]=0;
		else b[i]=1;
	}
	if(b[n]==b[n-1]||b[n]==b[n+1])return b[n];
	bool flag=true;
	for(int i=1;i<2*n-1;i++)
	{
		if(b[i]==b[i+1])
		{
			flag=false;
			break;
		}
	}
	if(flag)
	{
		return b[n]^(n%2==0);
	}
	int l=0,r=n*2;
	for(int i=n-1;i;i--)
	{
		if(b[i]==b[i+1])
		{
			l=i;break;
		}
	}
	for(int i=n+1;i<2*n;i++)
	{
		if(b[i]==b[i-1])
		{
			r=i;break;
		}
	}
	if(b[l]==b[r])return b[l];
	else return (n-l+1)<(r-n+1)?b[l]:b[r];
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=2*n-1;i++)
	{
		scanf("%d",&a[i]);
	}
	int l=1,r=100000000,mid,ans=-1;
	while(l<=r)
	{
		mid=(l+r)>>1;
		//printf("%d ",mid);
		if(jud(mid))l=mid+1;
		else ans=mid,r=mid-1;
	}
	printf("%d\n",ans);
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
template<class T,class Y>T LCM(T a,Y b){return (a*b)/GCD(a,b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)


int main(){
    int x,y;
    cin>>x>>y;
    rep(i,x+1){
        if(i*2+(x-i)*4==y){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

//a=97,z=122

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

using namespace std;

vector<int> total(201);

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

double fun(double l,double r,double v,double x){
    if(x <= l){
        return (v + l - x);
    }else if(x < r){
        return v;
    }else{
        return (v - r + x);
    }
}

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

    int n;
    cin >> n;

    vector<int> t(n),v(n);
    for(int i = 0; i < n; i++){
        cin >> t[i];
    }
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }

    double totaltime = 0.0;

    total[0] = 0;

    for(int i = 1; i < n+1; i++){
        total[i] = t[i-1] + total[i-1];
    }

    total[n+1] = total[n];

    totaltime = (double)total[n];

    double prey = 0.0;
    double result = 0.0;
    for(double i = 0; i <= totaltime; i += 0.5){
        double y = min(fun(0,0,0,i),fun(totaltime,totaltime,0,i));

        for(int j = 0; j < n; j++){
            y = min(y,fun(total[j],total[j+1],v[j],i));
        }

        result += 0.5*prey;
        result += 0.25*(y-prey);
        prey = y;
    }

    cout.precision(17);
    cout << fixed;
    cout << result << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize(2)
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<cstring>
#include<bitset>
#include<stack>
#include<time.h>



#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define ALL(x) x.begin(),x.end()
#define sz(a) ((int)a.size())
#define getmid ((l+r)>>1)
#define mst(var,val) memset(var,val,sizeof(var))
#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define lowbit(x) x&(-x)
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ls rt<<1
#define rs rt<<1|1
using namespace std;
#ifdef local
#define dbg(args...) cout << #args << " -> ", err(args);
void err(){ cout << endl; }
template<typename T, typename... Args>
void err(T a, Args... args){ cout << a << ' '; err(args...); }
#else
#define dbg(args...)
#endif // local

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <double, double> pdd;
const int inf=0x3f3f3f3f;
const long long INF=0x3f3f3f3f3f3f3f3fLL;
const double PI=acos(-1.0);
const long double eps=1e-8;
const int mod=1e9+7;
const int MAXN=2e3+100;
const int N=1e6+1000;
const int M=500+10;
const ll mm=(1LL<<32);

template <class T>
inline void read(T &x)
{
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar())
        f ^= c == '-';
    for (; isdigit(c); c = getchar())
        x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x)
{
    if (x < 0)
    {
        putchar('-');
        x = -x;
    }
    T y = 1;
    int len = 1;
    for (; y <= x / 10; y *= 10)
        ++len;
    for (; len; --len, x %= y, y /= 10)
        putchar(x / y + 48);
}
ll qpow(ll a,ll b,ll mod)
{
    ll ans=1;
    while(b)
    {
        if(b&1)
            ans=(ans*a)%mod;
        b>>=1;
        a=(a*a)%mod;
    }
    return ans;
}


int main()
{
#ifdef local
    freopen("in.txt","r",stdin);
#endif // local
    IOS;cout.tie(0);
    int a,b,c;cin>>a>>b>>c;
    int k;cin>>k;
    int tag=0;
    while(b<=a) b*=2,tag++;
    while(c<=b) c*=2,tag++;
    if(tag<=k) cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 3652
var input = '';
var readable = process.stdin;
readable.resume();
readable.setEncoding( 'utf-8' );
readable.on( 'data', function( chunk ) {
  input += chunk;
});

readable.on( 'end', function() {
  var data = input.split( '\n' );
  var output = [];
  var pattern = new Array( 152 ).join( "#." );
  for( var index=0; index<data.length; index++ ) {
    var nums = data[index].split( ' ' ).map( Number );
    if( 0 == nums[0] && 0 == nums[1] ) { break; }
    
    var row = [];
    for( var i=0; i<nums[0]; i++ ) {
      row.push( pattern.substr( i&1, nums[1]) );
    }
    output.push( row.join( '\n' )+'\n' );
  }
  console.log( output.join( '\n' )  );
});

Measured memory_bytes: 9152
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    n,m = map(int, input().split())
    adj = [[] for _ in range(n)] #頂点数, 場合によって変える
    for _ in range(m):
        a,b = map(int, input().split())
        adj[a-1].append(b-1)



    def bfs(start):
        pre = [-1]*n
        d = deque([start])
        res = []

        while d:
            v = d.popleft()
            for nv in adj[v]:
                if nv == start:
                    path = []
                    while v != -1:
                        path.append(v+1)
                        v = pre[v]
                        res = path
                    break

                if pre[nv] != -1:
                    continue
                pre[nv] = v
                d.append(nv)

        return res
    
    res = [0]*(n+1)
    for i in range(n):
        temp = bfs(i)
        if temp and len(res) > len(temp):
            res = temp
    if len(res) <= n:
        print(len(res))
        print(*res, sep='\n')
    else:
        print(-1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 44396
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <algorithm>

#define For(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n)   For(i,0,n)

using namespace std;

int n;
string s;
int c;

void cheak2(vector<int> &v){
	string t;
	for (;; c++){
		if (s[c] == ']'){
			c++; break;
		}
		t += s[c];
	}
	v.push_back(atoi(t.c_str()));
	if (s[c] == ']'){ c++; return; }
	else
	if(s[c] == '['){
		c++; cheak2(v);
	}
}

void cheak(vector<int> &v){

	vector<int> t;
	
	if (s[c] == '[' && s[c+1] >= '0' && s[c+1] <= '9'){
		c++; cheak2(t);
		sort(t.begin(), t.end());
		int sum = 0;
		rep(i, (t.size() + 1) / 2){
			sum += (t[i] + 1) / 2;
		}
		v.push_back(sum);
	}else
	if (s[c] == '['){
		while (s[c] == '['){
			c++; cheak(t);
		}
		c++;
		sort(t.begin(), t.end());
		int sum = 0;
		rep(i, (t.size() + 1) / 2){
			sum += (t[i]);
		}
		v.push_back(sum);
	}
}

int main()
{
	cin >> n;
	
	rep(_, n){
		c = 0;
		cin >> s;
		s += " ";
		vector<int> ans;
		cheak(ans);
		cout << ans[0] << endl;
	}
	return 0;
}

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

using namespace std;

int main() {
  int A, B;
  cin >> A >> B;
  int N = 100;
  vector<vector<bool>> G(N, vector<bool>(N));
  for (int i = 0; i < N / 2; i++) {
    for (int j = 0; j < N; j++) {
      G[i][j] = 1;
    }
  }
  int i = 0, j = 0;
  for (int c = 0; c < A - 1; c++) {
    G[i][j] = 0;
    j += 2;
    if (j >= N) {
      i += 2;
      j = 0;
    }
  }
  i = N / 2 + 1, j = 0;
  for (int c = 0; c < B - 1; c++) {
    G[i][j] = 1;
    j += 2;
    if (j >= N) {
      i += 2;
      j = 0;
    }
  }
  cout << "100 100" << endl;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (G[i][j]) {
        cout << '#';
      } else {
        cout << '.';
      }
    }
    cout << endl;
  }

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 256
// インクルード(GCC only)
#include <bits/stdc++.h>

// 長い型名
using namespace std;
typedef long long LL;

// 省略記法
#define INF 1e9
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(int i##_len=(n), i=(i##_len-1); i>=0; ++i)
#define FOR(i,m,n) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define sizei(x) ((int)(x).size())
#define fill(x,y) memset(x,y,sizeof(x))
#define printvector(x) rep(i,sizei(x)){cout << x[i] << endl;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

// mod付き四則演算(mod関数のオーバーヘッドが重いかも)
// TODO: 二項係数、離散対数、平方剰余の実装
#define MOD 1000000007
inline LL mod(LL const &a) { return (a % MOD + MOD) % MOD; }
inline LL madd(LL const &a, LL const &b) { return mod(mod(a) + mod(b)); }
inline LL msub(LL const &a, LL const &b) { return mod(mod(a) - mod(b)); }
inline LL mmul(LL const &a, LL const &b) { return mod(mod(a) * mod(b)); }
inline LL mpow(LL a, LL b) {
  LL r = 1;
  for (; b > 0; b >>= 1) {
    if (b & 1) (r *= a) %= MOD;
    (a *= a) %= MOD;
  }
  return r;
}
inline LL minv(LL const &a) { return mpow(a, MOD-2); }
inline LL mdiv(LL const &a, LL const &b) { return mod(mod(a) * minv(b)); }


// デバッグ用
#ifdef LOCAL
    #define eprint(...) fprintf(stderr, __VA_ARGS__)
    #define eprintvector(x) printvector(x)
#else
    #define eprint(...) 42
    #define eprintvector(x) 42
#endif

int main(void)
{
  int A, B;
  cin >> A >> B;

  int sum = 0;
  if (A >= B) {
    sum += A;
    A--;
    if (A >= B) {
      sum += A;
    }
    else {
      sum += B;
    }
  }
  else {
    sum += B;
    B--;
    if (A >= B) {
      sum += A;
    }
    else {
      sum += B;
    }
  }

  cout << sum << endl;

  return 0;
}


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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

template<typename T1,typename T2> using P = pair< T1, T2 >;
using Pii = P<int,int>;
using Pll = P<LL,LL>;
using Pdd = P<double,double>;
using Psi = P<string,double>;

int main(){
    LL n,k;
    cin>>n>>k;
    Vll a(n);
    REP(i,n) cin>>a[i];

    Vll k_b2(45);
    LL digit_k = 0;
    LL k_1 = k+1;
    while(k_1>0){
        k_b2[digit_k] += k_1%2;
        k_1 /= 2;
        digit_k++;
    }

    Vll d_num(45);
    LL d_max = 0;
    REP(i,n){
        LL tmp = a[i];
        LL j=0;
        while(tmp>0){
            d_num[j] += tmp%2;
            tmp /= 2;
            j++;
        }
        d_max = max(d_max,j);
    }


    LL x = 0;
    LL ans = 0;
    Vll ni(45);
    ni[0] = 1; 
    REP2(i,1,45) ni[i] = ni[i-1] * 2;
    REPD(i,41){
        if(x+ni[i]>k){
            ans += ni[i] * d_num[i];
        }else{
            if(2*d_num[i] < n) x += ni[i];
            ans += ni[i] * max(d_num[i],n-d_num[i]);
        }
    }

    cout<<ans<<endl;

    return 0;
}

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

string a, b;
int n;

int main() { // claudio van
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  cin >> n;
  cin >> a >> b;
  string ans = "";
  for (int i = 0; i < n; ++i) {
    ans += a[i];
    ans += b[i];
  }
  cout << ans << "\n";
  return 0;
}

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

int main(){

    string s ;
    cin >> s ;
    if(s == "Sunny")
        cout << "Cloudy";
    if(s == "Cloudy")
        cout << "Rainy";
    if(s == "Rainy")
        cout << "Sunny" ;
   
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int K = sc.nextInt();
    int X = sc.nextInt();
		
    for(int i=X-K+1;i<X+K;i++) {
      System.out.println(i);
    }
  }
}

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

using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;

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

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

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

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

			if(j > 0)
				dp[i][j] += dp[i - 1][j - 1] * p[i];

			// cout << i << " " << j << " " << dp[i][j] << endl;
		}
	}

	double ans = 0.0;
	for(int i = n / 2 + 1; i <= n; i++)
		ans += dp[n][i];

	cout.precision(12);
	cout << fixed << ans << endl;
}

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

int main(){
    int n;
    cin >> n;
    int flag = 0;

    for(int i = 1; i < 10; i++){
        if(n % i == 0 && (n / i) <= 9){
            cout << "Yes" << endl;
            flag = 1;
            break;
        }
    }

    if(flag == 0){
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

int main() {
    int N;
    double c, ans;

    cin >> N;

    vector<double> A(N);

    rep(i,N) {
        cin >> A[i];
        c += 1/A[i];
    }

    ans = 1/c;

    cout << fixed << setprecision(10) << ans << endl;

    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i=0, i##_limit=(n); i<i##_limit; ++i)
#define FOR(i, a, b) for (int i=(a), i##_limit=(b); i<i##_limit; ++i)
#define pb push_back
#define mp make_pair
using namespace std;
using ll = long long;
using pi = pair<int, int>;

int main()
{
    int A, B;
    cin >> A >> B;

    int ret = A * B;
    if (A >= 10 || B >= 10) ret = -1;
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        long as = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            as += a[i];
        }
        long bs = 0;
        PriorityQueue<Integer> plus = new PriorityQueue<>(Comparator.reverseOrder());
        PriorityQueue<Integer> minus = new PriorityQueue<>();
        for (int i = 0; i < n; i++) {
            b[i] = sc.nextInt();
            bs += b[i];
            int gap = a[i] - b[i];
            if (gap > 0) {
                plus.add(gap);
            } else if (gap < 0) {
                minus.add(-gap);
            }
        }
        if (bs > as) {
            System.out.println(- 1);
            return;
        }
        if (minus.isEmpty()) {
            System.out.println(0);
            return;
        }
        int ans = 0;
        int yojo = 0;
        while (!minus.isEmpty()) {
            int tarinai = minus.poll();
            while (yojo < tarinai) {
                ans++;
                yojo += plus.poll();
            }
            yojo -= tarinai;
            ans++;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 89516
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	int N, An, count = 1;
	cin >> N;
	vector<int> inputs;
	vector<int> data;
	while(cin >> An){
		inputs.push_back(An);
	}
	sort(inputs.begin(), inputs.end());

	for(int i = 0; i < N - 1; i++){
		if(inputs[i] == inputs[i + 1]){
			count++;
		}
		else {
			data.push_back(count);
			count = 1;
		}
	}
	data.push_back(count);
	bool isOnly;
	int *ptr = 0;
	for(auto x : data){
		if(x % 2 != 0){
			x = 1;
		}
		else{
			x = 2;
			if(ptr == 0){
				ptr = &x;
				isOnly = true;
			}
			else {
				isOnly = false;
				x = 1;
				*ptr = 1;
				ptr = 0;
			}
		}
	}

	if(isOnly){
		//cout << "erase!!" << endl;
		data.erase(data.begin());
		*ptr = 1;
	}

	cout << data.size();

	return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//cout << fixed << setprecision(10);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  int n;
  cin >> n;
  double ans = 0;
  rep(i,n) {
    double x;
    string u;
    cin >> x >> u;
    ans += (u=="JPY"?x:380000.0*x);
  }
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}

Measured memory_bytes: 256
s = input()
n = len(s)
mod = 10**9 + 7

dp = [[0]*13 for _ in range(n+1)]
dp[0][0] = 1

for i in range(n):
    if s[i] == '?':
        c = -1
    else:
        c = int(s[i])
        
    for j in range(10):
        
        if c != -1 and c != j:
            continue
            
        for k in range(13):
            dp[i+1][(k*10 + j)%13] += dp[i][k]
    
    for j in range(13):
        dp[i+1][j] %= mod

res = dp[n][5]
print(res)

Measured memory_bytes: 62172
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int (i) = (a);(i) < (b);(i)++)
#define REP(i,n) FOR(i,0,n)

int main(){
  int n;
  cin >> n;
  double a,b;
  double sum = 0;
  REP(i,n){
    cin >> a;
    b = 1/a;
    sum += b;
  }
  cout << fixed << setprecision(6) << 1/sum << endl;
}

Measured memory_bytes: 256
N = int(input())
a = []
for i in range(3):
    a.append(list(map(int, input().split())))

for i in range(3):
    a[i].sort()

dataa = []
datab = []
memo = 0
#print(a)
for i in range(N):
    flag = 0
    for j in range(memo, N):
        #print(a[0][i], a[1][j])
        if a[0][i] < a[1][j]:
            memo = j
            dataa.append(N - j)
            flag = 1
            break
    if flag == 0:
        for j in range(N - i):
            dataa.append(0)
        break
memo = 0
for i in range(N):
    flag = 0
    for j in range(memo, N):
        if a[1][i] < a[2][j]:
            memo = j
            datab.append(N - j)
            flag = 1
            break
    if flag == 0:
        for j in range(N - i):
            datab.append(0)
        break
ruiseki = []
count = 0
for i in range(len(datab)-1, -1, -1):
    count += datab[i]
    ruiseki.append(count)
count2 = 0
for i in range(len(dataa)):
    if dataa[i] != 0:
        count2 += ruiseki[dataa[i] - 1]



print(count2)


Measured memory_bytes: 27948
from collections import defaultdict


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    X = [0] * (N+1)
    for i, a in enumerate(A):
        X[i+1] = (X[i] + a - 1) % K
    cnt = defaultdict(int)
    ans = 0
    for i in range(N+1):
        if i >= K:
            cnt[X[i-K]] -= 1
        ans += cnt[X[i]]
        cnt[X[i]] += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 111564
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>

using namespace std;

int main(void){
  int N;
  cin>>N;
  vector<int> h(N);
  vector<int> c(N);
  for(int i=0;i<N;i++){
    cin>>h[i];
    c[i]=-1;
  }
  c[0]=0;
  for(int i=0;i<N;i++){
    if(i+1<N){
      if(c[i+1] == -1){
        c[i+1] = c[i] + abs(h[i+1]-h[i]);
      }
      else if(c[i+1] > c[i] + abs(h[i+1]-h[i])){
        c[i+1] = c[i] + abs(h[i+1]-h[i]);
      }
    }
    if(i+2<N){
      if(c[i+2] == -1){
        c[i+2] = c[i] + abs(h[i+2]-h[i]);
      }
      else if(c[i+2] > c[i] + abs(h[i+2]-h[i])){
        c[i+2] = c[i] + abs(h[i+2]-h[i]);
      }
    }

  }

  //for(int i=0;i<N;i++){
    //cout << c[i] << " ";
  //}
  cout << c[N-1] << endl;

  return 0;
}


Measured memory_bytes: 1024
#define Kafuu signed
#define Chino main

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>

#define maxn 20005
#define inf 0x3f3f3f3f
#define px putchar
#define pn px('\n')
#define ps px(' ')
#define pd puts("======================")
#define pj puts("++++++++++++++++++++++")

using namespace std;

inline int read(){
	int x=0,y=0;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')y=1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return y?-x:x;
}
template<typename T>
inline T read(){
	T x=0;
	int y=0;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')y=1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return y?-x:x;
}
#define ls(x) ls[x]
#define rs(x) rs[x]
int h[maxn<<4],dis[maxn<<1],pos[maxn<<1],rpos[maxn<<1],ls[maxn<<4],rs[maxn<<4],p[maxn<<1],cnt,num,rt1,rt2,n;
int seg[maxn<<4],low[maxn<<4],sta[maxn<<4],id[maxn<<4],top,all,scc;
bool vis[maxn<<4];
struct edge{int pre,to;}e[maxn<<7];
inline void add(int from,int to){e[++num]=(edge){h[from],to},h[from]=num;}
inline int rev(int x){return x>n?x-n:x+n;}
inline bool cmp(int x,int y){return p[x]!=p[y]?p[x]<p[y]:x<y;}
void build(int l,int r,int &n1,int &n2){
	n1=++cnt,n2=++cnt;
	if(l==r)return;
	int mid=l+r>>1;
	build(l,mid,ls(n1),ls(n2));
	build(mid+1,r,rs(n1),rs(n2));
}
void init(int l,int r,int n1,int n2){
	if(l==r){
		add(n1,rev(pos[l])+cnt),add(pos[l]+cnt,n2);
		return;
	}
	int mid=l+r>>1;
	init(l,mid,ls(n1),ls(n2));
	init(mid+1,r,rs(n1),rs(n2));
	add(n1,ls(n1)),add(n1,rs(n1)),add(ls(n2),n2),add(rs(n2),n2);
}
void modify(int L,int R,int l,int r,int n1,int n2,int poi){
	if(L<=l&&R>=r){
		add(poi+cnt,n1),add(n2,rev(poi)+cnt);
		return;
	}
	int mid=l+r>>1;
	if(L<=mid)modify(L,R,l,mid,ls(n1),ls(n2),poi);
	if(R>mid)modify(L,R,mid+1,r,rs(n1),rs(n2),poi);
}
void TJ(int node){
	vis[sta[++top]=node]=1;
	seg[node]=low[node]=++all;
	for(register int i=h[node],x;i;i=e[i].pre){
		x=e[i].to;
		if(!seg[x])TJ(x),low[node]=min(low[x],low[node]);
		else if(vis[x])low[node]=min(low[node],seg[x]);
	}
	if(seg[node]==low[node]){
		id[node]=++scc,vis[node]=0;
		while(sta[top]!=node)id[sta[top]]=scc,vis[sta[top--]]=0;
		--top;
	}
}
inline bool check(int len){
	memset(h,0,sizeof h);
	memset(seg,0,sizeof seg);
	num=all=scc=0;
	init(1,n<<1,rt1,rt2);
	for(register int i=1;i<=n<<1;++i){
		int l=lower_bound(dis+1,dis+1+(n<<1),p[i]-len+1)-dis,r=upper_bound(dis+1,dis+1+(n<<1),p[i])-dis-1;
		if(l<=rpos[i]-1)modify(l,rpos[i]-1,1,n<<1,rt1,rt2,i);
		if(rpos[i]+1<=r)modify(rpos[i]+1,r,1,n<<1,rt1,rt2,i);
	}
	for(register int i=1;i<=(n<<1)+cnt;++i)if(!seg[i])TJ(i);
	for(register int i=1;i<=n;++i)if(id[i+cnt]==id[i+cnt+n])return 0;
	return 1;
}
Kafuu Chino(){
	n=read();
	for(register int i=1;i<=n<<1;++i)pos[i]=i;
	for(register int i=1;i<=n;++i)dis[i]=p[i]=read(),dis[i+n]=p[i+n]=read();
	sort(pos+1,pos+1+n+n,cmp),sort(dis+1,dis+1+n+n);
	for(register int i=1;i<=n<<1;++i)rpos[pos[i]]=i;
	build(1,n<<1,rt1,rt2);
	int l=0,r=1e9;
	while(l<r){
		int mid=l+r+1>>1;
		if(check(mid))l=mid;
		else r=mid-1;
	}
	printf("%d\n",l);
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int a,d,n;

bool is_prime[10000010];

int main(){
	cin.sync_with_stdio(false);
	rep(i,10000001)is_prime[i]=true;
	is_prime[0]=is_prime[1]=false;
	repl(i,2,10000001){
		if(is_prime[i]){
			for(int j=i*2;j<=10000000;j+=i)is_prime[j]=false;
		}
	}
	while(1){
		cin>>a>>d>>n;
		if(a==0)break;
		int cnt=0;
		while(cnt<n){
			if(is_prime[a])cnt++;
			a+=d;
		}
		cout<<a-d<<endl;
	}
	return 0;
}

Measured memory_bytes: 12932
#include<iostream>
#include <bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define modn 1000000007
using namespace std;
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int tc;
    //cin>>tc;
    tc = 1;
    while(tc--)
    {
        int n,a;
        cin>>n>>a;
        n = n%500;
        if(a >= n) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}


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

int main()
{
        int N;
        cin >> N;
        int a[N];
        for (int i = 0; i < N; ++i) {
                cin >> a[i];
        }
        vector<int> check(N, 0);
        int p = 0;
        int ans = 1;
        while (1) {
                if (check[p] == 1) {
                        ans = -1;
                        break;
                }
                if (a[p] == 2) {
                        break;
                }
                ans++;
                check[p] = 1;
                p = a[p] - 1;



        }
        cout << ans << endl;


}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	int n, a, b;	cin >> n >> a >> b;
	int cnta = 0, cntb = 0;
	string s;	cin >> s;
	for (int i = 0; i < n; i++) {
		bool flag = false;
		if (s[i] == 'a') {
			if (cnta + cntb < a + b) {
				cnta++;
				flag = true;
			}
		}
		else if (s[i] == 'b') {
			if (cnta + cntb < a + b && cntb < b) {
				cntb++;
				flag = true;
			}
		}
		if (flag) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	return 0;
}

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

int n, m;
int a[1010];
int b[1010];

int main() {
	int count = 0;   // n[i] > n
	vector<int> v;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> a[i] >> b[i];
		if (a[i] >= n) {
			count++;
		} else {
			v.push_back(n - a[i]);
		}
	}
	sort(v.begin(), v.end());
	if (count >= m - 1) {
		cout << "0" << endl;
	} else {
		int ans = 0;
		for (int i = 0; i < m - count - 1; i++) {
			ans += v[i];
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3184
MOD=1000000007
N,K=map(int,input().split())
A=list(map(int,input().split()))
L=[0]*N
R=[0]*N
for i in range(N):
    for j in range(N):
        if A[j] < A[i]:
            if j > i:
                R[i]+=1
            if j < i:
                L[i]+=1

KR=((K*(1+K))//2)%MOD
KL=(((K-1)*K)//2)%MOD

ans=0
for i in range(N):
    ans = (ans + (KR*R[i])%MOD)%MOD
    ans = (ans + (KL*L[i])%MOD)%MOD
print(ans)


Measured memory_bytes: 41836
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
	const int sec = 1900;
	int N, M;
	double ans = 0;
	cin >> N >> M;

	double p = 1.0;
	const double p_ac = 1.0 / (pow(2, -M));
	int time = sec * M + 100 * (N - M);
	while (time * (p * p_ac) > pow(10, -9))
	{
		ans += time * (p * p_ac);
		time += sec * M + 100 * (N - M);
		
		p *= 1.0 - p_ac;
		
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <climits>

using namespace std;

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

  int ans;

  if (N < 105) {
    ans = 0;
  } else if (N < 135) {
    ans = 1;
  } else if (N < 165) {
    ans = 2;
  } else if (N < 189) {
    ans = 3;
  } else if (N < 195) {
    ans = 4;
  } else {
    ans = 5;
  }

  cout << ans << endl;

  return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    cout << a.at((n / 2) ) - a.at(n / 2-1) << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  int flg = 0;
  cin >> s;
  int n = s.size();
  for(int i=1; i<=n; i++){
    if(i % 2 == 0){
      if(s[i-1] == 'R') flg = 1;
    } else {
      if(s[i-1] == 'L') flg = 1;
    }
  }
  if(flg == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

int main() {

  int N, M;
  cin >> N >> M;

  int sum = 0;
  if(N > 0){
    sum += N * (N - 1) / 2;
  }
  if(M > 0){
    sum += M * (M - 1) / 2;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin>>n;
  int a[n+1];
   for(int f=0;f<=n;f++)
  {
     a[f]=0;
  }
  for(int i=2;i<=n;i++)
   {
     int x;
     cin>>x;
     a[x]++;
   }
  for(int j=1;j<=n;j++)
  {
     cout<<a[j]<<endl;
  }
  }

Measured memory_bytes: 4420
#include <bits/stdc++.h>
#define MAXN 100100
#define pii pair<int, int>
#define pb push_back
typedef long long ll;

using namespace std;

int n, t = 0, f[MAXN];
map<int, int> m;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    cin >> n;
    for(int i = 0; i < n; i++){
    	int x;
    	cin >> x;
    	f[x]++;
    }
    for(int i = 0; i < MAXN; i++){
    	if(f[i] > 1){
    		if(f[i] % 2){
    			n -= f[i] - 1;
    			f[i] = 1;
    		} else{
    			n -= f[i] - 2;
    			f[i] = 2;
    			t++;
    		}
    	}
    }
    if(t % 2) n--;
    n -= t;
    cout << n;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <functional>
#include <map>
#include <set>
#include <cmath>
#include <string>
#define SIZE 100005
#define INF 1000000005LL

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

ll K;
ll T[SIZE];
ll S[SIZE];

void solve(int n,int k){
	if(n<=k){
		printf("0\n");
		return;
	}else if(k==1){
		printf("%lld\n",T[n-1]-T[0]);
		return;
	}
	ll road = T[n-1]-T[0];
	for(int i=1;i<n;i++){
		S[i-1]=T[i]-T[i-1];
	}
	sort(S,S+n-1);
	for(int i=0;i<(k-1);i++){
		road -= S[n-2-i];
	}
	printf("%lld\n",road);
}

void imain()
{
	int n,k;
	scanf("%d %d",&n,&k);
	for(int i=0;i<n;i++)scanf("%lld",&T[i]);
	solve(n,k);
}

int main(){
	int N;
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		imain();
	}
}



Measured memory_bytes: 4340
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MM 1000000000
#define MOD MM+7
#define MAX 10000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
ll INF = 1e18;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
int main(){
    ll N,K; cin >> N >> K;
    ll h[N];
    for(ll i = 0; i < N; i++){
        cin >> h[i];
    }
    ll dp[100100];
    for(ll i = 0; i <= 100000; i++){
        dp[i] = INF;
    }
    dp[0] = 0;
    for(ll i = 0; i < N; i++){
        for(ll j = 1; j <= K; j++){
            if(i+j < N){
                dp[i+j] = min(dp[i]+abs(h[i+j]-h[i]), dp[i+j]);
            }
        }
    }
    cout << dp[N-1] << endl;
}


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

// Type alias
using ll=long long;
using ld=double;

using pi=pair<int,int>;
using pll=pair<ll,ll>;
using pld=pair<ld,ld>;
using ti3=tuple<int, int, int>;

using vi=vector<int>;
using vll=vector<ll>;
using vld=vector<ld>;
using vpi=vector<pi>;
using vpll=vector<ll>;
using vpld=vector<ld>;
using vti3=vector<ti3>;

// Constants
const double EPS = 1e-9;
const int inf = numeric_limits<int>::max();

// Macro
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;--i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,a,b) for(int i=int(b-1);i>=int(a);--i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl

#define ALL(a) a.begin(),a.end()

// Funtcions
ll pow(ll base, ll i, ll mod){
  ll a = 1;
  while(i){
    if (i & 1) {
      a *= base;
      a %= mod;
    }
    base *= base;
    base %= mod;
    i >>= 1;
  }
  return a;
}
ll gcd(ll a, ll b){
  while(b){
    ll c = a % b;
    a = b;
    b = c;
  }
  return a;
}
ll lcm(ll a, ll b){
  return a / gcd(a, b) * b;
}
template<typename T> bool chmin(T& a, const T& b) {
  if (a > b) return a = b, true; else return false;
}

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

int dp[41][401][401];

void solve(){
  int N, Ma, Mb;
  cin >> N >> Ma >> Mb;

  int A[45], B[45], C[45];
  rep(i, N) cin >> A[i] >> B[i] >> C[i];

  rep(i, 41) rep(j, 401) rep(k, 401) dp[i][j][k] = inf / 2;
  dp[0][0][0] = 0;

  rep(i, N) rep(ca, 401) rep(cb, 401){
    if(dp[i][ca][cb] == inf / 2) continue;
    dp[i+1][ca][cb] = min(dp[i+1][ca][cb], dp[i][ca][cb]);
    dp[i+1][ca + A[i]][cb + B[i]] = min(dp[i+1][ca + A[i]][cb + B[i]], dp[i][ca][cb] + C[i]);
  }

  int ans = inf / 2;
  REP(ca, 1, 401) REP(cb, 1, 401){
    if(ca * Mb == cb * Ma)
      ans = min(ans, dp[N][ca][cb]);
  }

  if(ans == inf / 2){
    cout << -1 << endl;
    return;
  }

  cout << ans << endl;
}

int main(){
// FastIO
//ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}

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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORd(i, a, b) for (int i = (a) ; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define sp system("pause")
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
const int N = (int) 1e5 + 10;
void TimeExecution() {
    cout << "\n\n===>> Time Execution: " << clock() / (double)1000 << " sec(s).";
}
int t;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    /*
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    */
    int n, m;
    cin >> n >> m;
    int a[n + 1];
    int d = 0;
    int s = 0;
    FOR(i, 1, n)
    {
        cin >> a[i];
        s += a[i];
    }
    double v = (1.0 / (4 * m)) * s;
    //sort(a + 1, a + 1 + n);
    FOR(i, 1, n)
    {
        if(a[i] >= v) d++;
    }
    if(d >= m) cout << "Yes";
    else cout << "No";
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

//Jigsaw Puzzles for Computers
public class Main{

	int trans(char ch){
		return ch=='R'?1:
			ch=='r'?-1:
			ch=='G'?2:
			ch=='g'?-2:
			ch=='B'?3:
			ch=='b'?-3:
			ch=='W'?4:-4;	
	}
	
	class R{
		int a[], top;
		public R(int[] a, int top) {
			this.a = a;
			this.top = top;
		}
	}
	
	R[][] assign;
	boolean[] u;
	int c;
	R[][] piece;
	
	void dfs(int k){
		if(k==9){
			c++;return;
		}
		int i=k/3;
		int j=k%3;
		for(int use=0;use<9;use++){
			if(u[use])continue;
			for(int d=0;d<4;d++){
				R r = piece[use][d];
				if(i>0){
					R up = assign[i-1][j];
					if(r.a[r.top]+up.a[(up.top+2)%4]!=0)continue;
				}
				if(j>0){
					R left = assign[i][j-1];
					if(r.a[(r.top+3)%4]+left.a[(left.top+1)%4]!=0)continue;
				}
				u[use] = true;
				assign[i][j] = r;
				dfs(k+1);
				u[use] = false;
			}
		}
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		while(N--!=0){
			piece = new R[9][4];
			for(int i=0;i<9;i++){
				char[] s = sc.next().toCharArray();
				int[] a = new int[4];
				for(int j=0;j<4;j++)a[j]=trans(s[j]);
				for(int j=0;j<4;j++)piece[i][j]=new R(a, j);
			}
			c = 0;
			u = new boolean[9];
			assign = new R[3][3];
			dfs(0);
			System.out.println(c);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
import numpy as np
n = int(input())
ans = 0

prime = [1]*100
prime = np.array(prime)
for i in range(2,n+1):
    temp = 1
    for j in range(2,100):
        while i%j == 0:
            i //= j
            prime[j] += 1
    # print(i,prime)
p75 = prime//75
p25 = prime//25
p15 = prime//15
p5 = prime//5
p3 = prime//3
for i in range(100):
    if p75[i] >= 1:
        ans += 1
    if p25[i] >= 1:
        for j in range(i+1,100):
            if p3[j] >= 1:
                ans += 1
                # print(i,j)
    if p15[i] >= 1:
        for j in range(i+1,100):
            if p5[j] >= 1:
                ans += 1
    if p5[i] >= 1:
        for j in range(i+1,100):
            if p15[j] >= 1:
                ans += 1
            if p5[j] >= 1:
                for k in range(j+1,100):
                    if p3[k] >= 1:
                        ans += 1
                        # print(i,j,k)
            if p3[j] >= 1:
                for k in range(j+1,100):
                    if p5[k] >= 1:
                        ans += 1 
    if p3[i] >= 1:
        for j in range(i+1,100):
            if p25[j] >= 1:
                ans += 1
            if p5[j] >= 1:
                for k in range(j+1,100):
                    if p5[k] >= 1:
                        ans += 1 
# print(prime)
# print(p5)
print(ans)

Measured memory_bytes: 12492
N=int(input())
sp = []
n = 1
for i in range(N):
  iin = input().split()
  Sin = iin[0]
  Pin = int(iin[1])
  sp.append( [Sin, Pin, n] )
  n+=1
sp = sorted( sp, key=lambda ii:ii[1], reverse=True)
sp = sorted( sp, key=lambda ii:ii[0])
for ss in sp:
  print(ss[2])


Measured memory_bytes: 3064
//Om Sree Sai Ram
#include "bits/stdc++.h"
using namespace std;

template <typename T> void max_self(T& a,T b)
{
  a = max(a,b);
}

const int nax = 305;
double p[nax][nax][nax], ex[nax][nax][nax];


int main() 
{


int n;
cin>>n;
vector<long long> ar(n);
for(int i=0;i<n;i++)
{
  cin>>ar[i];
}

vector<vector<long long>> dp(n,vector<long long>(n));
//dp[L][R] represents score (X-Y) we can obtain from taking array from L to R
for(int L=n-1;L>=0;L--)
{
  for(int R=L;R<n;R++)
  {
    if(L==R)
    {
      dp[L][R] = ar[L];
    }
    else
    {
      //maximizing this gets the answer that's magic..
   dp[L][R] = max(ar[L]-dp[L+1][R],ar[R]-dp[L][R-1]);
    }

  }
}
  cout<<dp[0][n-1]<<endl; 
}


Measured memory_bytes: 70784
import sys
from collections import defaultdict

N, M = map(int, input().split())
d = defaultdict(int)

for i in range(M):
    s, c = map(int, input().split())
    if (d[s] != 0) & (d[s] != c):
        print(-1)
        sys.exit()
    elif ((s == 1) & (c == 0)) & (N > 1):
        print(-1)
        sys.exit()
    elif d[s] == 0:
        d[s] = c
    else:
        continue

if N==1:
    print(d[1])
    sys.exit()

ans = ["1"] + ["0"] * (N - 1)

for s, c in d.items():
    ans[int(s) - 1] = str(c)

print("".join(ans))

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

    using namespace std;

    const int MOD=1e9+7;
    vector<int>dist(200005);
    map<int,int>mp;
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        int n;
        long long k;
        cin>>n>>k;
        vector<int>a(n);
        for(int i=0;i<n;i++){
            cin>>a[i];
            --a[i];
        }
        int x=1;
        mp[0]=0;
        int start=0;
        int l,h;
        for(int i=0;i<=n;i++){
            dist[x]=a[start];
            if(mp.count(dist[x])>0){
                l=mp[dist[x]];
                h=x;
                break;
            }
            else
                mp[dist[x]]=x;
            x++;
            start=a[start];
        }
        if(k<h)
            cout<<dist[k]+1;
        else{
            int loop=h-l;
            k-=l;
            k=k%loop;
            cout<<dist[l+k]+1;
        }
        return 0;
    }


Measured memory_bytes: 13840
package main

import (
	"strings"
	"bufio"
	"fmt"
	"math/big"
	"os"
	"strconv"
)

const (
	//1000000000000000000

	MAX = 1000000000000000000
)
const MaxBuf = 200100

var (
	list []*big.Int = make([]*big.Int, 0)

	bmax = big.NewInt(MAX)
)
var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() string {
    buf := make([]byte, 0, 1000000)
    for {
        l, p, e := rdr.ReadLine()
        if e != nil {
            panic(e)
        }
        buf = append(buf, l...)
        if !p {
            break
        }
    }
    return string(buf)
}

func main() {
	l:= readLine()
	l = readLine()
	l = strings.TrimSpace(l)
l2 := strings.Split(l ," ")
	for i := 0; i < len(l2); i++ {

		a,_ :=  strconv.Atoi(l2[i])
		if a == 0 {
			fmt.Println(0)
			return 
		}
		list = append(list, big.NewInt(int64(a)))
	}
	
//	fmt.Println(list)

	now := big.NewInt(1)
	for i := 0; i < len(list); i++ {
	
	 now = 	 now.Mul(now, list[i])
		 
	 //fmt.Println(now.Cmp(bmax))
	
		if now.Cmp(bmax) == 1 {
			fmt.Println("-1")
		 return 
		}

	}

	fmt.Println(now)
}



Measured memory_bytes: 16104