akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

const ll INF = 1ll<<60;

typedef pair<ll,ll> P;

int main() {
  ll n, x, d;
  cin >> n >> x >> d;
  if (d==0){
    if(x==0){
      cout<<1;
      return 0;
    }
    else{
      cout<<n+1;
      return 0;
    }
  }

  if (d<0){
    d=-d;
    x=-x;
  }

  map<ll,vector<P>> mp;
  rep(i,n+1){

    ll mink=(i-1)*i/2;
    ll maxk=i*(2*n-i-1)/2;
    ll ix=i*x;
    ll rem=(ix+(d<<30))%d;
    ll front=(ix-rem)/d+mink;
    ll len=maxk-mink;
    ll s = ix+mink*d;//初項
    mp[rem].emplace_back(front,len);

/*
    ll s = x*i;
   ll l = (ll)i*(i-1)/2;//iの和のmin
   ll r = l + (ll)i*(n-i);//iの和のmax
   s += l*d;//初項
   r -= l;//初項から最終項までのながさ（dで割っている）
   mp[(s+(d<<30))%d].emplace_back(s,r);//負の値がかえらないように十分大きくしている
*/
  }


  ll cnt=0;
  
  for(auto a:mp){
    auto A=a.second;
    sort(A.begin(),A.end());
    ll start=A[0].first;

    ll numA=A.size();
    ll now=start+A[0].second;
    //ll end=now;
    ll cnt1=0;
    rep(i,numA-1){
      if (A[i+1].first>now+1){
        cnt1+=A[i+1].first-now-1;
      }
      now=max(now,A[i+1].first+A[i+1].second);
  //    end=max()
    }

    ll sumall=now-start+1;
  //  cout<<sumall<<'s'<<cnt1<<'c'<<endl;
    cnt+=sumall-cnt1;

  }
  /*
  ll ans=0;
  for (auto p : mp) {
    auto a = p.second;//(s,r)
    int m = a.size();
    rep(i,m) a[i].first = (a[i].first-p.first)/d;//初項から初項%dを引いてdで割る
    vector<P> ev;//event first:いつ　second:+1 or -1　
    //１以上になっている区間の長さがわかればok、区間の始まりを+1, 終わりを-1とする

    rep(i,m) {
      ev.emplace_back(a[i].first, 1);//初項を１に
      ev.emplace_back(a[i].first+a[i].second+1, -1);//初項＋長さを−１に
    }
    sort(ev.begin(), ev.end());
    ll cnt = 0, pre = -INF;//cnt:いま何個の区間に覆われているか pre:直前のイベント
    for (auto e : ev) {
      ll len = e.first-pre;//直前のイベントからのながさ
      if (cnt) ans += len;
      cnt += e.second;
      pre = e.first;
    }
  }
cout<<ans;
*/
cout<<cnt;
}


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

int n, m;
std::vector<int> vec, vec2;
std::vector<std::pair<int, int>> query;


int main() {
    std::cin >> n >> m;
    vec2.assign(n, 0);
    for (int i = 0; i < n; i++) {
        std::cin >> vec2[i];
    }
    query.assign(m, {0, 0});
    for (int i = 0; i < m; i++) {
        std::cin >> query[i].second >> query[i].first;
    }
    std::sort(vec2.begin(), vec2.end());
    std::sort(query.begin(), query.end());
    std::reverse(query.begin(), query.end());
    
    auto f = vec2.begin();
    for (int i = 0; i < m; i++) {
        auto it = std::lower_bound(f, vec2.end(), query[i].first);
        auto w = std::distance(f, it);
        if (w == 0) {
            break;
        }
        if (w > query[i].second) {
            w = query[i].second;
        }
        for (int v = 0; v < w; v++) {
            *(f+v) = query[i].first;
        }
        f += w;
    }
    
    long long r = 0;
    for (int j = 0; j < n; j++) {
        r += vec2[j];
    }
    std::cout << r << std::endl;

    
}


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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

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

string str;
ll dp[300030][3][2];

void seica_add(ll &a, ll &b){
	a += b;
	a %= MOD;
}

int main(){
		
	cin >> str;
	
	if(str.size() == 1){
		if(str[0] != '0'){
			cout << 1 << endl;
		}
		else{
			cout << 0 << endl;
		}
		return 0;
	}

	str = '1' + str + '1';
	dp[0][0][0] = 1;
	
	REP(i,str.size()){
		bool A = false, B = false, C = false;
		if(i > 3 && i % 2 == 1)C = true;
		if(str[i] == '?')A = true, B = true;
		if(str[i] == '1')A = true;
		if(str[i] == '0')B = true;
		REP(j,3)REP(k,2)if(dp[i][j]){
			if(A){
				int nj = j;
				if(k){
					if((i % 2 && j == 0) || (i % 2 == 0 && j == 1))nj++;
				}
				seica_add(dp[i+1][nj][1], dp[i][j][k]);
			}
			if(B){
				seica_add(dp[i+1][j][0], dp[i][j][k]);
			}
		}
	}
	
	ll ans = 0;
	seica_add(ans, dp[str.size()][2][0]);
	seica_add(ans, dp[str.size()][2][1]);
		
	cout << ans << endl;
		
	return 0;
}


Measured memory_bytes: 14684
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        string s;
        if(!(cin >> s))
            return 0;
        
        for(int i=9; i>0; --i){
            for(int j=0; j<i; ++j){
                int a = s[j] - '0' + s[j+1] - '0';
                a %= 10;
                s[j] = a + '0';
            }
        }

        cout << s[0] << endl;
    }
}

Measured memory_bytes: 736
#include <bits/stdc++.h>
 
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
 
using namespace std;
using ll = long long;
 
int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int N, Q; cin >> N >> Q;
  vector<vector<int>> G(N);
  rep(i, N-1) {
    int a, b; cin >> a >> b; a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<ll> val(N);
  rep(i, Q) {
    int p, x; cin >> p >> x; p--;
    val[p] += x;
  }
  auto dfs = [&](auto dfs, int u, int p) -> void {
    for (int v : G[u]) if (v != p) {
      val[v] += val[u];
      dfs(dfs, v, u);
    }
  };
  dfs(dfs, 0, -1);
  rep(i, N) cout << val[i] << (i == N - 1 ? '\n' : ' ');
}

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

using namespace std;

using ll = long long;

int main(){
    ll n; cin >> n;
    vector<pair<ll, ll> > v;
    for(ll i = 0; i < n; ++i){
        ll x, y; cin >> x >> y;
        v.push_back(make_pair(x, y));
    }
    double ans = 0.0;
    sort(v.begin(), v.end());
    do{
        for(ll i = 0; i < n - 1; ++i){
            ans += sqrt(1.0 * (v[i].first - v[i + 1].first) * (v[i].first - v[i + 1].first) + 1.0 * (v[i].second - v[i + 1].second) * (v[i].second - v[i + 1].second));
        }
    }while(next_permutation(v.begin(), v.end()));
    ll kanta = 1;
    for(ll i = 2; i <= n; ++i){
        kanta *= i;
    }
    cout << fixed <<setprecision(10) << ans / double(kanta);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define pb push_back
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ll long long
using namespace std;
int main(){
  string s;
  cin >> s;
  ll n = s.size(), d = 1000000007, x[n + 1] = {}, a[n + 1] = {}, b[n + 1] = {}, c[n + 1] = {};
  x[0] = 1;
  a[0] = b[0] = c[0] = 0;
  REP(i, n){
    if(s[i] == '?'){
      x[i + 1] = x[i] * 3;
      a[i + 1] = x[i] + a[i] * 3;
      b[i + 1] = a[i] + b[i] * 3;
      c[i + 1] = b[i] + c[i] * 3;
    }else{
      x[i + 1] = x[i];
      a[i + 1] = (s[i] == 'A' ? x[i] : 0) + a[i];
      b[i + 1] = (s[i] == 'B' ? a[i] : 0) + b[i];
      c[i + 1] = (s[i] == 'C' ? b[i] : 0) + c[i];
    }
    x[i + 1] %= d;
    a[i + 1] %= d;
    b[i + 1] %= d;
    c[i + 1] %= d;
  }
  cout << c[n] << endl;
  return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n, a, b;
	cin >> n >> a >> b;

	ll res = n/(a+b) * a;
	n %= a+b;
	res += min(a,n);
	cout << res << endl;
}



Measured memory_bytes: 256
fun abc121c(args: Array<String>) {
    val (N, M) = args[0].split(" ").map { it.toLong() }
    val sortedNumPairList  =
            args.drop(1).map { a -> a.split(" ").map { it.toLong() } }.sortedBy { it.first() }
    var cnt = 0L
    var ans = 0L
    sortedNumPairList.forEach { pair ->
        val (price, num) = pair
        if (cnt < M) {
            if (num > M - cnt) {
                ans += (M - cnt) * price
                cnt += M - cnt
            } else {
                ans += num * price
                cnt += num
            }
        }
    }
    println(ans)
}

fun main(args: Array<String>) {
    abc121c(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}

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

typedef long long ll;
#define rep(i,n) for( ll (i)=0; (i)<(n); ++(i) )
#define rpi(i,n) for( int (i)=0; (i)<(n); ++(i) )
#define rpv(d) for(auto& v:d)
#if __cplusplus < 201703L
  std::ostream& co_(){ return std::cout << std::endl; }
  std::istream& cn_(){ return std::cin; }
  template<class Head, class... Args>
  std::ostream& co_( Head&& head, Args&&... args ){ std::cout << head; return co_(std::forward<Args>(args)...); }
  template<class Head, class... Args>
  std::istream& cn_( Head&& head, Args&&... args ){ std::cin >> head; return cn_(std::forward<Args>(args)...); }
#else
  template<class... Args>
  std::ostream& co_( Args... args ){ return std::cout << ... << args << std::endl; }
  template<class... Args>
  std::istream& cn_( Args... args ){ return std::cin >> ... >> args; }
#endif
#define co(...) co_(__VA_ARGS__);
#define cn(...) cn_(__VA_ARGS__);
#define all(x) (x).begin(), (x).end()
#define rgt(x,i) (x).begin(), (x).begin()+(i)

int main(){
  int n;
  cn(n)
  vector<int> d(n);
  rpv(d){cn(v)}
  rpv(d){int t;cn(t);v-=t;}
  sort(all(d),[](int& a, int& b){return a>b;});
  int ans = 0;
  rpv(d){
    if (v>0){
      ans += v;
    }else {
      break;
    }
  }
  co(ans)
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

public class CSharp
{
    public static void Main()
    {
        Kyopuro chokudai = new Kyopuro();
        chokudai.AtCoder();
    }
}

public class Kyopuro
{
    string s;
    int n, m, k;

    public void AtCoder()
    {
        string[] input;
        input = Console.ReadLine().Split(' ');
        n = int.Parse(input[0]);
        Console.WriteLine((n-2)*180);
    }
    public static void DebugWL(object x) { System.Diagnostics.Debug.WriteLine(x); }
}


Measured memory_bytes: 11092
#include <iostream>
#include <string>
#include <deque>
#include <algorithm>

using namespace std;

struct Task {
    string name;
    int time;
    Task(string name, int time) : name(name), time(time) {}
};

struct RoundRobin {
    const int maxDur;
    int time;
    deque<Task> data;

    RoundRobin(int dur) : maxDur(dur), time(0) {}
    void addTask(Task t) {
        this->data.push_back(t);
    }
    void doSchedule() {
        while (not this->data.empty()) {
            auto task = this->data.front();
            this->time += min(task.time, maxDur);
            int rem = task.time - this->maxDur;
            if (rem > 0) {
                task.time = rem;
                this->data.push_back(task);
            } else {
                cout << task.name << " " << this->time << endl;
            }
            this->data.pop_front();
        }
    }
};

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

    RoundRobin rr(q);

    string name;
    int time;
    for (int i=0; i<n; i++) {
        cin >> name >> time;
        Task t(name, time);
        rr.addTask(t);
    }

    rr.doSchedule();

    return 0;
}

Measured memory_bytes: 6308
#include<stdio.h>
int main(void){
  int N,i,j,k,ans;
  ans=0;
  scanf("%d",&N);
  int h[N];
  for(i=0;i<N;i++){
    scanf("%d",&h[i]);
  }
  int max;
  max=h[0];
  for(i=0;i<N-1;i++){
    if(max<h[i+1]){
      max=h[i+1];
    }
  }
  for(i=0;i<max;i++){
    if(h[0]>0){
        ans=ans+1;
    }
    for(j=0;j<N-1;j++){
      if(h[j]<=0 && h[j+1]>0){
        ans=ans+1;
      }
    }
    for(k=0;k<N;k++){
      h[k]=h[k]-1;
    }
  }
  printf("%d",ans);
  return 0;
}
        

Measured memory_bytes: 128
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int n,m,k;cin>>n>>m>>k;
    bool ans=false;
    for(int i=0;i<=m;i++){
        for(int j=0;j<=n;j++){
            if(k==(i*n+j*m-i*j*2))ans=true;
        }
    }
    if(ans)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
 
#define debug(x) cout << '>' << #x << ':' << x << endl;
 
#define nitro ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
const int mod = 1e9+7;
using namespace std;
using ll = long long int;
const ll invmod = 998244353; 
const int N = 5*(int)(1e5) + 1;
const int MAXN = 1e5+10;
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
 
 
bool compareByfirst(tuple<int, int, int>&a, tuple<int, int, int>&b)
{
	return get<0>(a) > get<0>(b);
}
bool compareBySecond(tuple<int, int, int>&a, tuple<int, int, int>&b)
{
	return get<1>(a) < get<1>(b);
}
 
int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	//clock_t time_req;time_req = clock();
	nitro;
	int x,n;
	cin >> x >> n;
	set<int> s;

	for(int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		s.insert(a);
	}
	int diff = INT_MAX;
	int index;
	for(int i =0; i >= -1000; i--)
	{
		if(s.count(i)==0)
		{
			if(abs(i-x) < diff)
			{

				diff = abs(i-x);
				index = i;
			}
		}
	}

	for(int i = 0; i <= 1000; i++)
	{
		if(s.count(i)==0)
		{
			if(abs(i-x) < diff)
			{
				diff = abs(i-x);
				index = i;
			}
		}
	}

	cout << index << '\n';


	
}

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

const int INF = 0x3f3f3f3f;
using ll = long long;

const int MAX_N = 305;
int f[3];
int N;

double dp[MAX_N][MAX_N][MAX_N];

double do_it(int a, int b, int c)
{
	if(a+b+c==0) return 0;
	double &res = dp[a][b][c];
	if(res > 0) return res;
	res = 0;
	double p = (double)(a+b+c)/N;
	if(a) res += (1.0*a/N)*do_it(a-1,b,c);
	if(b) res += (1.0*b/N)*do_it(a+1,b-1,c);
	if(c) res += (1.0*c/N)*do_it(a,b+1,c-1);
	res=(res+1)/p;
	return res;
}

void solve()
{
	memset(dp, -1, sizeof(dp));
	cout.precision(15);
	cout << do_it(f[0],f[1],f[2]) << endl;
}

int main()
{
	cin >> N;
	int x;
	for(int i=1;i<=N;++i){ 
		cin>> x;
		f[x-1]++;
	}
	solve();
	return 0;
}

Measured memory_bytes: 221952
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
from bisect import bisect_left

N,M = map(int,input().split())
a = [0] * M
for i in range(M):
    a[i] = int(input())
a.sort()
len_a = len(a)

MOD = 10**9 + 7

# dp[i]: i段目の移動方法の合計
dp = [0] * (N+1)

# 初期条件
dp[0] = 1

for i in range(N):
    if i == N-1:
        dp[i+1] = dp[i+1] + dp[i] % MOD
        continue

    index = bisect_left(a,i+1)
    if index == len_a or a[index] != i + 1:
        dp[i+1] = dp[i+1] + dp[i] % MOD
    index = bisect_left(a,i+2)
    if index == len_a or a[index] != i + 2:
        dp[i+2] = dp[i+2] + dp[i] % MOD

print(dp[-1] % MOD)

Measured memory_bytes: 46556
package main

import "fmt"

func main() {
	var n, y int
	fmt.Scan(&n, &y)
	found := false
L:
	for i := 0; i <= n; i++ {
		for j := 0; j <= n-i; j++ {
			if 10000*i+5000*j+1000*(n-i-j) == y {
				fmt.Printf("%d %d %d\n", i, j, n-i-j)
				found = true
				break L
			}
		}
	}
	if !found {
		fmt.Printf("%d %d %d\n", -1, -1, -1)
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <algorithm>  
#include <unordered_set>
#define _USE_MATH_DEFINES
#include <cmath>
#define ll long long

using namespace std;

const double pi = 3.14159265358979323846;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int A, B, H, M;

	cin >> A >> B >> H >> M;


	double hours = ((double)(M)) / (60.0) + H;

	double hourHandDegree = hours / (12.0) * 360;

	double minHandDegree = hours / (1.0) * 360;


	double angle = hourHandDegree > minHandDegree ? hourHandDegree - minHandDegree : minHandDegree - hourHandDegree;

	//angle = angle / 360;
	angle = angle * pi / (180.0);


	double c = sqrt(A * A + B * B - 2 * A * B * cos(angle));

	cout << std::setprecision(10000000) << c << endl;




	return 0;
}

Measured memory_bytes: 43084
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b&&b==c&&c==a) cout<<"Yes";
	else cout<<"No";
	return 0;
}


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

using namespace std;

int main()
{
    string s;
    vector<string> v;
    int k;

    cin >> s >> k;

    for (int i = 1; i <= k && i <= s.length(); i++) {
        for (int j = 0; j <= s.length() - i; j++) {
            v.push_back(s.substr(j, i));
        }
    }

    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());

    cout << v[k - 1];

    return 0;
}


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

int n, a;

int main() {
	cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a;
		if (i % 2 == 1 && a % 2 == 1) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<ll> d1(n), d2(n);
  int x, y;
  for(int i=0; i<n; ++i){
    cin >> x >> y;
    d1[i] = x+y;
    d2[i] = x-y;
  }
  ll ans = 0;
  sort(d1.begin(),d1.end());
  sort(d2.begin(),d2.end());
  ans = max(d1[n-1] - d1[0], d2[n-1] - d2[0]);
  cout << ans << endl;
}

Measured memory_bytes: 6348
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//using ll = long long;
using P = pair<int,int>;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int n,a[100010],b[100010],suma = 0,sumb = 0;
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> a[i];
		suma += a[i];
	}
	for(int i = 0;i < n;i++){
		cin >> b[i];
		sumb += b[i];
	}
	if(suma < sumb){
		cout << -1 << endl;
		return 0;
	}
	int ans = 0,sumMinus = 0;
	vector<int> vecPlus;
	for(int i = 0;i < n;i++){
		if(a[i] >= b[i]) vecPlus.push_back(a[i] - b[i]);
		else{
			sumMinus += b[i] - a[i];
			ans++;
		}
	}
	sort(all(vecPlus),greater<int>());
	for(int i = 0;sumMinus > 0;i++){
		sumMinus -= vecPlus[i];
		ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 2936
t=int(input())
if t>=10000:
    t%=10000
    if t==0:
        print(t)
    else:
        print(1000-t)
else:
    t%=1000
    if t==0:
        print(t)
    else:
        print(1000-t)
import math

#print(math.ceil(t/1000)*1000-t)


Measured memory_bytes: 61908
import math
N=int(input())
def isp(N):
  if N==2:
    return(True)
  k=int(math.sqrt(N))
  
  for i in range(2,k+2):
    if N%i==0:
      return(False)
  return(True)
while isp(N)==False:
  N+=1
print(N)

Measured memory_bytes: 3060
// abc131_d
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N;
    cin >> N;
    vector<P> AB(N);
    REP(i, N) cin >> AB[i].first >> AB[i].second;

    sort(ALL(AB), [](const P& lhs, const P& rhs){return lhs.second < rhs.second;});

    int t = 0;
    REP(i, N){
        t += AB[i].first;
        if (t > AB[i].second){
            print("No");
            return 0;
        }
    }
    print("Yes");

    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cstdlib> 
#include <cmath>
#include <algorithm>
#include <sstream>
#include <string>
using namespace std;

int main() {
	int n, a;
	cin >> n >> a;
	
	int s = n / 500;
	
	if (n - s * 500 <= a) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::pair;

using std::vector;
using std::sort;

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(a+b>c+d){
        cout << "Left" << endl;
    }
    else if(a+b==c+d){
        cout << "Balanced" << endl;
    }
    else{
        cout << "Right" << endl;
    }
    return 0;
}



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

def is_prime(n):
  i=2
  while i*i<=n:
    if n%i==0:
      return False
    i+=1
  return n!=1

l=list()
for i in range(6,55555,5):
  if is_prime(i):
    l.append(i)
    n-=1
  if n==0:
    print(*l)
    exit()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define V vector<int>
using namespace std;
using ll = long long;

int main(){
    vector<string> s(3);
    rep(i,0,3) cin>>s[i];
    int j=0;
    while(1){
        char c=s[j][0];
        s[j].erase(s[j].begin());
        if(c=='a') j=0;
        else if(c=='b') j=1;
        else j=2;
        if(s[j][0]=='\0'){
            if(j==0)cout<<'A'<<endl;
            else if(j==1)cout<<'B'<<endl;
            else cout<<'C'<<endl;
            return 0;
        }
    } 
}

Measured memory_bytes: 256
A, B, K = map(int, input().split())
ans = []
for i in range(K):
  ans.append(A + i)
for i in range(1,K+1):
  if B-(K-i) not in ans:
    ans.append(B-(K-i))
for x in ans:
  if A <= x and x <= B:
    print(x)


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

int gcd(int a, int b) {
    return b ? gcd(b, a%b) : a;
}

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

  vector<int> x(N);
  for (int i = 0; i < N; i++) {
      cin >> x.at(i);
      x.at(i) = abs(x.at(i) - X);
  }

  int ans = x.at(0);

  for (int i = 0; i < N; i++) {
      ans = gcd(ans,x.at(i));
  }

  cout << ans << endl;

}


Measured memory_bytes: 3660
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
using namespace std;

using VI = vector <int> ;
using VVI = vector <VI> ;
const int MAXS = 1000010;
const int MAXT = 2;
char str[MAXT][MAXS];

inline int countTwo(int n) {
    int ret = 0;

    while (n%2 == 0 && n) {
        n /= 2;
        ++ret;
    }

    return ret;
}

int main() {
    int N;

    scanf("%d", &N);
    scanf("%s", str[0]);

    int mulFactor = 2;

    for (int i = 1; i < MAXT && i < 2; ++i) {
        int len = N-i;

        for (int j = 0; j < len; j++) {
            int diff = abs(str[i-1][j+1] - str[i-1][j]);
            if (diff == 1) {
                mulFactor = 1;
            }
            str[i][j] = (diff + '0');
        }

        str[i][len] = '\0';

        // printf("%s\n", str[i]);
        // 12221121
        // 12201011, 122111

        // 12221121
        // 12021101
        // 10201121
        // 10221121
    }

    int len = N - 1;

    int result = 0;
    int twoCount = 0;

    // cout << "LEN " << len << endl;

    if (mulFactor == 2) {
        for (int i = 0; i < len; ++i) {
            str[1][i] = (str[1][i]/2) + '0';
        }
    }

    for (int i = 0; i < len; ++i) {

        if (twoCount == 0) {
            result = (result + (str[1][i]-'0')%2)%2;
        }

        twoCount += countTwo(len-i-1);
        twoCount -= countTwo(i+1);
    }

    cout << result * mulFactor << endl;

    return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
map<string , long long > m ;
string s;
long long  n , c  ;
long long sun(long long n )
{
    return (n * (n +  1) / 2) ;
}
int main()
{
    cin >> n ;
    for (int i = 0 ; i < n ; i++)
    {
        cin >> s ;
        sort(s.begin() , s.end());
        m[s]++;
    }
     for (auto i : m )
     {

         c += sun(i.second - 1 );
     }
     cout <<c;

    return 0;
}


Measured memory_bytes: 11136
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
inline int read(){
	int x=0,f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar())
		if(c=='-')
			f=-1;
	for(;isdigit(c);c=getchar())
		x=x*10+c-'0';
	return x*f;
}
int main(){
	int A=read(),B=read(),C=read(),D=read(),E=read(),F=read();
	double ans=0;
	int maxw=0,maxs=0;
	for(int d1=0;d1<=F/C;d1++)
		for(int d2=0;d2<=F/D;d2++)
			for(int t1=0;t1<=(F/(A*100.0));t1++)
			    for(int t2=0;t2<=(F/(B*100.0));t2++){
			    	if((double)((d1*C+d2*D))/(t1*A*100.0+t2*B*100.0+d1*C+d2*D)<=(double)(E/(100.0+E))
					&& d1*C+d2*D+t1*A*100+t2*B*100<=F)
			    		if((double)((d1*C+d2*D))/(t1*A*100.0+t2*B*100.0+d1*C+d2*D)>=ans){
			    			ans=(double)((d1*C+d2*D))/(t1*A*100.0+t2*B*100.0+d1*C+d2*D);
			    			maxw=t1*A*100+t2*B*100+d1*C+d2*D;
			    			maxs=d1*C+d2*D;
						}
				}
	printf("%d %d\n",maxw,maxs);
	return 0;
}


Measured memory_bytes: 256
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2243

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

int panel[10] = {0,1,2,3,1,2,3,1,2,3};

const int LEFT = -1;
const int RIGHT = 1;

bool isValid(int left, int right)
{
	int left_x = panel[left];
	int right_x = panel[right];
	return (left_x > right_x) ? false : true;
}

int main()
{
	string S;
	while(true)
	{
		cin >> S;
		if( S == "#" ){ break; }
		
		vector<int> step;
		rep(i,S.length()){ step.push_back( S[i] - '0' ); }

		if(step.size() <= 2){ cout << 0 << endl; continue; }

		int ans = INT_MAX;
		int state, left, right;	
		rep(nth,2)
		{
			int cnt=0;
			if(nth){ //右足スタートと左足スタート
				left = step[0]; right = step[1]; state = LEFT;  
			}else{ 
				left = step[1]; right = step[0]; state = RIGHT;
			}

			if(!isValid(left,right)){ continue; }//初期配置で駄目な時
			
			REP( i, 2, step.size() )
			{
				if(state == RIGHT) //右足の場合
				{
					if(isValid(left,step[i])){
						right = step[i]; state = LEFT;
					}else{
						left = step[i]; cnt++; state = RIGHT;
					}
				}
				else //左足の場合
				{	
					if(isValid(step[i], right)){
						left = step[i]; state = RIGHT;
					}else{
						right = step[i]; cnt++; state = LEFT;
					}
				}
			}
			ans = min(ans, cnt);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 2084
#include <cstdio>
#include <cstring>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
typedef long long ll;

int vs[100000+10];

int main(void) {
  int n;
  scanf("%d", &n);
  REP(i, n) {
    scanf("%d", &vs[i]);
  }
  // 最初を正にする場合と負にする場合の2通り試せば十分な気がしている
  ll res1 = 0;
  {
    ll cur = 0;
    REP(i, n) {
      cur += vs[i];
      if(i%2 == 0 && cur <= 0) {
        res1 += 1 - cur;
        cur = 1;
      } else if(i%2 == 1 && cur >= 0) {
        res1 += 1 + cur;
        cur = -1;
      }
    }
  }
  ll res2 = 0;
  {
    ll cur = 0;
    REP(i, n) {
      cur += vs[i];
      if(i%2 == 1 && cur <= 0) {
        res2 += 1 - cur;
        cur = 1;
      } else if(i%2 == 0 && cur >= 0) {
        res2 += 1 + cur;
        cur = -1;
      }
    }
  }

  printf("%lld\n", min(res1, res2));
  
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef double ld;
#define pll pair<ll,ll>
#define pii pair<int, int>
#define pb push_back
#define mp(x, y) make_pair((x), (y))
#define F first
#define S second
#define I insert
#define vi vector<int>
#define vll vector<ll>
#define vpll vector<pll>
#define vpii vector<pii>
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()

const ll Mod = 998244353;

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

    ll x;cin>>x;
    ll ans = (x/500)*1000 + ((x%500)/5)*5;
    cout<<ans<<"\n";
    
    return 0;
}

Measured memory_bytes: 256
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys;input = sys.stdin.readline
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]

M = 10**9+7
n = inp()
dp = [0]*2001
if n <= 2:
    print(dp[n])
    exit()
dp[0] = 1
t = 0
for i in range(3,n+1):
    t += dp[i-3]
    dp[i] = t%M
print(dp[n]%M)

Measured memory_bytes: 63516
N, M = gets.split.map(&:to_i)
cities = N.times.map{|n|[n+1,0]}.to_h
M.times do |i|
    a, b = gets.split.map(&:to_i)
    cities[a] = cities[a] + 1
    cities[b] = cities[b] + 1
end
cities.each do |k,v|
    puts v
end

Measured memory_bytes: 1788
from collections import deque

def nearlist(N, LIST):  # 隣接リスト
    NEAR = [[] for _ in range(N)]
    for a, b in LIST:
        NEAR[a - 1].append(b - 1)
        NEAR[b - 1].append(a - 1)
    return NEAR


def bfs(NEAR, S, COLOR, ANS):  # 幅優先探索  # キュー
    # 隣点リスト,始点,数
    que, frag = deque([S]), set([S])

    while len(que) > 0:
        q = que.popleft()
        c, cnt = COLOR[q], 0
        for i in NEAR[q]:  # 移動先の候補
            if i in frag:  # 処理済みか否か
                continue
            cnt += 1 + (cnt == c - 1)
            COLOR[i] = cnt
            ANS[(q, i)], ANS[(i, q)] = cnt, cnt
            que.append(i), frag.add(i)
    return


n = int(input())
ab = [list(map(int, input().split())) for _ in range(n - 1)]

color, ans = [-1] * n, {}
near = nearlist(n, ab)
bfs(near, 0, color, ans)
print(max(ans.values()))
for a, b in ab:
    print(ans[(a - 1, b - 1)])


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

int gcd(int a, int b){return b ? gcd(b, a % b) : a;}
int main(){
	int n, k, i, g, a, mx = 0;
	scanf("%d%d", &n, &k);
	for(i = 1, g = 0; i <= n; ++ i){
		scanf("%d", &a);
		g = gcd(g, a);
		mx = max(mx, a);
	}
	printf("%s\n", k % g == 0 && k <= mx ? "POSSIBLE" : "IMPOSSIBLE");
	return 0;
}

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


int main() {
    ll N, A, B;
    string S;
    cin >> N >> A >> B >> S;

    int pass = 0;
    int pass_B = 0;

    rep(i,S.size()) {
        if (S[i] == 'a') {
             if (pass < A + B) {
                 cout << "Yes" << endl;
                 ++pass;
             } else cout << "No" << endl;
        } else if (S[i] == 'b') { 
            if (pass < A + B && pass_B < B) {
                cout << "Yes" << endl;
                ++pass;
                ++pass_B;
            } else cout << "No" << endl;
        } else cout << "No" << endl;
    }
}



Measured memory_bytes: 3764
#! /usr/bin/perl

use strict;
use warnings;

chomp(my $line = <>);
my @n = split(/\s+/, $line);
chomp($line = <>);
my $k = $line;

foreach my $i (1..$k) {
    @n = e86(@n);
}
my $sum = 0;
foreach my $n (@n) {
    $sum += $n;
}
print $sum, "\n";

sub e86 {
    my @n = @_;
    @n = sort {$b <=> $a} @n;

    my $max = shift @n;
    unshift @n, $max * 2;
    return @n;
}


Measured memory_bytes: 640
def main():
	while True:
		m, f, r = (int(x) for x in input().split())
		if m == -1 and f == -1 and r == -1:
			break
		elif m == -1 or f == -1:
			print('F')
		elif m + f >= 80:
			print('A')
		elif 65 <= m + f < 80:
			print('B')
		elif 50 <= m + f < 65:
			print('C')
		elif 30 <= m +f < 50:
			if 50 <= r:
				print('C')
			else:
				print('D')
		else:
			print('F')

main()



Measured memory_bytes: 5604
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ft first
#define sd second
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

const int maxN = 1 << 19;

int A[maxN];

void solve()
{
	int n, m;
	long long lcm;
	scanf ("%d%d%lld", &n, &m, &lcm);
	A[0] = lcm /= 2;
	FOR(i, 1, n)
	{
		scanf ("%d", A+i);
		A[i] /= 2;
		lcm = lcm / __gcd(lcm, 1ll*A[i]) * A[i];
	}

	long long res = (m / lcm + 1) / 2;
	
	FOR(i, 0, n)
		if (lcm/A[i] % 2 == 0)
			res = 0;
			
	printf("%lld\n", res);
}

int main()
{
	int t;
	t = 1;//scanf ("%d", &t);
	while (t--)
		solve();
	
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime> 
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

const int MOD = 1e9 + 7;

int add(int a, int b) {
	return (a + b) % MOD;
}

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

	int n;
	cin >> n;
	vector<int> dp(n + 1);
	dp[0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j + 3 <= i; j++) {
			dp[i] = add(dp[i], dp[j]);
		}
	}
	cout << dp[n] << '\n';
}

Measured memory_bytes: 3144
#include <bits/stdc++.h>
#define fi first
#define se second
#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(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#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 pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;
#define RET(ans) {cout<<ans<<endl;return 0;} 

    // 二次元ベクターの基本
    /*
    vector<vector<int>> dp; // 宣言
    dp.resize(n); // 1次元めの要素数決定
    dp[i].push_back(int); // プッシュバック
    rep(i,n){
        sort(dp[i].begin(),dp[i].end()); // 二次元めを昇順ソート
    }
    */

    // 整数スキャン（複数）
    /*
    int x,y,z;
    scanf("%d%d%d",&x,&y,&z);

    // n個の整数のスキャン
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // 文字列スキャン
    /*
    string s; cin >> s;
    */

    // n個の文字列スキャン
    /*
    vector<string> slist;
    rep(i,n){
        string s; cin >> s;
        slist.push_back(s);
    }
    */

int main() {
    int n;
    cin >> n;
    ll ans = 1;

    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
        if(a[i]%2==0){
            ans *= 2;
        }
    }
    ans = pow(3,n) - ans;


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


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

int main() {
	long n;
  	cin >> n;
    if(n%111==0){
        cout << n << endl;
    }
    else if(n<=111){
        cout << 111 << endl;
    }
    else{
        cout << (n/111+1)*111 << endl;
    }
}


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

public class MainClass
{
	public const long Giri = 1000000007;
	
	public static void Main(string[] args)
	{
		var s = Input().ToInt();
		Array.Sort(s);
		Array.Reverse(s);
		Console.WriteLine(s[0]*10+s[1]+s[2]);
	}


	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}


Measured memory_bytes: 13140
/* ex 7_3
series2 */
#include <stdio.h>
#include <stdlib.h>

int main(void) {
    int height, width;
    char **cell;
    scanf("%d %d\n", &height, &width);
    //各行の配列へのポインタ分のメモリ領域を確保
    int row_check[width], column_check[height];  //全て.のマスなら0、それ以外は1
    cell = (char **)calloc(height, sizeof(char *));
    if (cell == NULL) {
        fprintf(stderr, "calloc error.\n");
        exit(1);
    }
    //各行の要素分のメモリ領域を確保 同時に横について.が揃っているかチェック
    for (int i = 0; i < height; i++) {
        cell[i] = (char *)calloc(width, sizeof(char));
        if (cell[i] == NULL) {
            fprintf(stderr, "calloc error.\n");
            exit(1);
        }
        int count = 0;
        for (int j = 0; j < width; j++) {
            scanf(" %c", &cell[i][j]);
            if (cell[i][j] == '.') {
                count++;
            }
        }
        if (count == width) {
            row_check[i] = 0;
        } else {
            row_check[i] = 1;
        }
    }
    //縦について.が揃っっているかチェック
    for (int i = 0; i < width; i++) {
        int count = 0;
        for (int j = 0; j < height; j++) {
            if (cell[j][i] == '.') {
                count++;
            }
        }
        if (count == height) {
            column_check[i] = 0;
        } else {
            column_check[i] = 1;
        }
    }
    //表示して良い部分のみ表示しながら、
    //メモリ領域の解放，各行の要素分の領域を開放し，
    //各行の配列へのポインタの領域を解放
    //（メモリ領域の確保と逆順）
    for (int i = 0; i < height; i++) {
        if (row_check[i]) {
            for (int j = 0; j < width; j++) {
                if (column_check[j]) {
                    printf("%c", cell[i][j]);
                }
            }
            printf("\n");
        }
        free(cell[i]);
    }
    free(cell);

    return 0;
}

Measured memory_bytes: 1672
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	scan_init()
	N := scanInt()
	M := scanInt()
	s := make([]int,M)
	c := make([]int,M)
	for i:= 0; i<M;i++ {
		s[i] = scanInt()
		c[i] = scanInt()
	}
	 output := make([]int,N)
	 for i:= 0; i<N; i++ {
	 	output[i] = 10 //10で初期化しとく
	 }
	 umakuita := true
	 for i:= 0; i<M; i++ {
	 	keta := s[i]-1
	 	if output[keta] == c[i] || output[keta] == 10 {
	 		output[keta] = c[i]
		} else {
			umakuita = false
			break
		}
	 }
	 for i:= 0; i<N; i++ {
	 	if output[i] == 10 {
	 		if i== 0 && N != 1{
	 			output[i] = 1
			} else {
				output[i] = 0
			}
	 	}
	 }
	 if output[0] == 0 && N != 1 {
	 	umakuita = false
	 }
	 if umakuita {
	 	for i:= 0; i<N; i++ {
	 		fmt.Print(output[i])
		}
	 } else {
	 	fmt.Println(-1)
	 }
}
var sc = bufio.NewScanner(os.Stdin)
func scan_init () {
	sc.Split(bufio.ScanWords)
}
func scanInt () int{
sc.Scan()
	i,_ := strconv.Atoi(sc.Text())
	return i
}
func scan () string{
 sc.Scan()
	return sc.Text()
}

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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)
int main()
{
   LL x,n;
   cin>>x>>n;
   LL s=0;
   for(int i=0;i<n;i++)
   {
       LL a;
       cin>>a;
       s+=a;
   }
   LL ans=-1;
   if(s<=x)
    ans=x-s;
   cout<<ans;
}


Measured memory_bytes: 3624
from collections import deque
n,m = map(int,input().split())
child = [set() for _ in range(n)]
parent = [set() for _ in range(n)]
root = set(range(n))

for i in range(n+m-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    parent[b].add(a)
    child[a].add(b)
    if b in root:root.remove(b)

root = list(root)[0]
parent[root].add(-1)

que = deque([root])
d = [[-1,-1] for _ in range(n)]
d[root] = [0,-1]
while que:
    p = que.popleft()
    for nxt in child[p]:
        if d[nxt][1] == -1:
            d[nxt] = [d[p][0] + 1,p]
        elif d[nxt][0] > d[p][0] + 1:
            parent[nxt].remove(p)
        else:
            parent[nxt].remove(d[nxt][1])
            d[nxt][0] = d[p][0] + 1
            d[nxt][1] = p
        if len(parent[nxt]) == 1:
            que.append(nxt)
for i in parent:
    print(list(i)[0] + 1)


Measured memory_bytes: 71488
#include <cstdio>

int main(){
    int n,a,b,c,d;
    scanf("%d",&n);
    
    a = n/1000;
    b = n%1000;b /= 100;
    c = n%100;c /= 10;
    d = n%10;

    if(a==b&&b==c||b==c&&c==d){
        printf("Yes");
    }else{
        printf("No");
    }
}

Measured memory_bytes: 128
<?php
list($n) = ints();
for ($i = 0; $i < $n; ++$i) list($a[]) = ints();
if ($n === 1 && $a[0] === 0) exit('0');
if ($a[0] !== 0) exit('-1');
$ans = 0;
for ($i = $n - 1; $i >= 1; --$i) {
    if ($a[$i] > $a[$i - 1] + 1) exit('-1');
    if ($a[$i] === 0) continue;
    ++$ans;
    if ($a[$i] > 1 && $a[$i - 1] >= $a[$i]) $ans += $a[$i] - 1;
}
echo $ans;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 23220
#include<stdio.h>
#include<stdlib.h>
long long int msort(int, int, int*);
main()
{
        int i, n, *a;
        scanf("%d", &n);
        a = (int*)malloc(sizeof(int) * n);
        for (i = 0; i < n; i++) {
                scanf("%d", &a[i]);
        }
        printf("%lld\n", msort(0, n - 1, a));
        free(a);
}
long long int msort(int left, int right, int *a)
{
        int i, j, center, num, base, work[right - left + 1];
        long long int reverse = 0;
        if (left >= right) return 0;
        center = (left + right) / 2;
        reverse += msort(left, center, a);
        reverse += msort(center + 1, right, a);
        for (num = 0, i = left; i <= center; num++, i++) {
                work[num] = a[i];
        }
        j = 0, base = left;
        while (i <= right && j < num) {
                if (a[i] < work[j]) {
                        a[base++] = a[i++];
                        reverse += i - base;
                } else {
                        a[base++] = work[j++];
                }
        }
        while (j < num) {
                a[base++] = work[j++];
        }
        return reverse;
}


Measured memory_bytes: 3072
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
lint x[200100],sum[200100];
lint inf=123456789012345678;
lint mul(lint a,lint b){
	if(a==0LL) return 0LL;
	if(inf/a+1<b) return inf;return a*b;
}
int main()
{
	int n;lint X,out=inf;
	cin>>n>>X;
	rep(i,n) cin>>x[i];
	sum[0]=0;rep(i,n) sum[i+1]=sum[i]+x[i];
	REP(i,1,n+1){
		lint now=i*X;
		REP(j,1,n/i+2){
			int hi=max(0,n-j*i+i),lo=max(0,n-j*i);
			now+=mul(sum[hi]-sum[lo],max(5,j*2+1));
			now=min(now,inf);
		}
		//cout<<i<<' '<<now<<endl;
		out=min(out,now);
	}
	cout<<out+n*X<<endl;
}


Measured memory_bytes: 3328