akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0593

"""
import sys
from sys import stdin
from collections import namedtuple, Counter
input = stdin.readline


class RMQ(object):
    INT_MAX = 2**31 - 1

    def __init__(self, nn, init_val=0):
        self.n = 1
        while self.n < nn:
            self.n *= 2
        self.dat = [init_val] * ((2 * self.n)-1)

    def update(self, k, a):
        # A[k]???a?????´??°?????????????????°???????????¨?????´??°
        k += (self.n - 1)
        self.dat[k] = a

        while k > 0:
            k = (k - 1) // 2        #  ??????index??????
            self.dat[k] = min(self.dat[k * 2 + 1], self.dat[k * 2 + 2]) #  ???????????¨??????????????????????°?????????????????????´??°

    def query(self, a, b, k, l, r):
        # [a, b)???????°????????±??????? (0????????§b???????????????)
        # ??????????????¨?????????query(a, b, 0, 0, n)?????¢??§??????????????????k, l, r???????????????????????´??°?????????
        if r <= a or b <= l:        #  ?????????????????§??¨??????????????????
            return RMQ.INT_MAX
        if a <=l and r <= b:
            return self.dat[k]           #  ???????????°???????????????????????§????????°????????¨??????????????????????°?????????????????????????
        else:
            vl = self.query(a, b, k*2+1, l, (l+r)//2) #  ????????°????????????????°????
            vr = self.query(a, b, k*2+2, (l+r)//2, r) #  ????????°????????????????°????
            return min(vl, vr)

    def find(self, s, t):
        return self.query(s, t+1, 0, 0, self.n)


event = namedtuple('event', ['num', 'cost'])
def main(args):
    N, M = map(int, input().split())
    rq = RMQ(1001, 999999)
    events = [event(i+1, int(input())) for i in range(N)] #  ??¶????????????1??????????????§???i+1???????????????
    events.reverse()            #  ??¢?????????????????????????????¶???????????¨?????????????????????
    #  ?????????(e.cost)??§????????§????????¶????????????(e.num)??§RMQ?????´??°????????????
    # events???????´????????????????????????¢??????????????\??£??????????????§???????????????????????¶???????????£?????´????????¢??????????????¶???????????§??????????????????
    for e in events:
        rq.update(e.cost, e.num)

    # ????\¨
    votes = []
    for _ in range(M):
        v = int(input())
        result = rq.find(0, v)  #  ?????????v?????§???????????????????????§??????????????¢????????¶????????????
        votes.append(result)
    ans = Counter(votes).most_common(1)[0][0]
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 8320
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define MOD 1000000007
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
const ll INF = 1LL << 60;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H, N;
    cin >> H >> N;
    vector<int> A(N), B(N);
    rep(i,N)cin>>A[i]>>B[i];
    vector<vector<ll>> dp(N+1,vector<ll>(H+1,INF));
    
    dp[0][0] = 0;
    rep(i, N)
    {
        rep(w, H + 1)
        {
            dp[i + 1][w] = min(dp[i + 1][w], dp[i][w]);
            ll _h = min((ll)w + A[i], H);
            dp[i + 1][_h] = min(dp[i + 1][_h], dp[i+1][w]+B[i]);
        }
    }
    cout<<dp[N][H]<<endl;
 //   system("pause");
    return 0;
}

Measured memory_bytes: 78592
#include <iostream>
#include <string>
#include <map>
using namespace std;

int main()
{
	long q;
	cin >> q;

	multimap <string, long> mp;

	for (long i = 0; i < q; i++) {
		int t;
		cin >> t;

		string s;
		cin >> s;

		if (t == 0) {
			long x;
			cin >> x;
			mp.insert(std::make_pair(s, x));
		}
		else if (t == 1) {
			std::map<string, long>::iterator itr = mp.find(s);
			if (itr != mp.end()) {
				while (itr != mp.end() && itr->first == s) {
					cout << itr->second << endl;
					itr++;
				}
			}
		}
		else if (t == 2)
			mp.erase(s);
		else if (t == 3) {
			string r;
			cin >> r;
			std::map<string, long>::iterator itr;
			for (itr = mp.lower_bound(s); itr != mp.upper_bound(r); itr++)
				cout << itr->first << " " << itr->second << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 24884
a = int(input())
A = list(map(int,input().split() ) )
count = 0
flag = 0
while flag == 0 and count < 10000:
    for i in range(len(A)):
        if A[i] %2 !=0 or A[i] == 0:
            flag = 1
    if flag == 0:        
        for i in range(len(A)):
            A[i] = int(A[i]/2)
        count += 1
print(count)

Measured memory_bytes: 3060
#include<stdio.h>
#include <sysexits.h>
#include<stdlib.h>
#include<math.h>

int main(void){
  int a,b,n,k,m,sum,i,L,p[100],ans;
  //printf("error");
  if(scanf("%d %d",&a,&b)>2){
    exit(0);
  }
  ans=0;
  if(a>b){
    ans=b;
    for(i=1;i<a;i++){
      ans+=(pow(10,i))*b;
    }
    printf("%d",ans);
  }
  else{
    ans =a;
    for(i=1;i<b;i++){
      ans+=(pow(10,i))*a;
    }
    printf("%d",ans);
  }
  return 0;
}


Measured memory_bytes: 128
n = int(input())
s = list(input())

A_Z = [chr(ord('A') + i) for i in range(26)]

for i in range(len(s)):
    idx = A_Z.index(s[i])
    if idx + n > 25:
        ret = (idx + n) % 26
        rep = A_Z[ret]
        s[i] = rep
    else:
        rep = A_Z[idx + n]
        s[i] = rep
print(''.join(s))

Measured memory_bytes: 3064
def main():
    from math import atan2, degrees
    a, b, x = map(int, input().split())

    if x * 2 >= a * a * b:
        # 断面は台形
        d = (a * a * b - x) * 2 / (a * a)
        ans = degrees(atan2(d, a))
        print(ans)
        return

    else:
        # 断面は三角形
        d = (x * 2) / (a * b)
        ans = degrees(atan2(b, d))
        print(ans)
        return


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <stdio.h>

int main(void) {
  int i, sx, sy, tx, ty;
  scanf("%d%d%d%d", &sx, &sy, &tx, &ty);
  for(i = sy; i < ty; ++i) printf("U");
  for(i = sx; i < tx; ++i) printf("R");
  for(i = sy; i < ty; ++i) printf("D");
  for(i = sx; i < tx; ++i) printf("L");
  printf("L");
  for(i = sy; i <= ty; ++i) printf("U");
  for(i = sx; i <= tx; ++i) printf("R");
  printf("D");
  printf("R");
  for(i = sy; i <= ty; ++i) printf("D");
  for(i = sx; i <= tx; ++i) printf("L");
  printf("U");
  return 0;
}

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


int main()
{
    ll a,v,b,w,t;
    cin >> a >> v >> b >> w >> t;
    if(abs(a-b)<=(v-w)*t)
        cout << "YES";
    else
        cout << "NO";
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
int main(){
int N,l[1000],r[1000],a=0;
std::cin >> N;
 for(int i=0;i<N;i++)
	std::cin >> l[i] >> r[i];
 for(int i=0;i<N;i++)
	a+=(r[i]-l[i]+1);
std::cout << a << std::endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define ll long long
#define rep(i, a, b) for(int i = a; i < b; i++)
using namespace std;

int main() {
  string s;
  cin >> s;
  int a = 0;
  rep(i, 0, 4) {
    if(s[i] == '+') a++;
    else a--;
  }
  cout << a << "\n";
}

Measured memory_bytes: 3548
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n, r, in;
    scanf("%d%d",&n,&r);
    
    if ( n<=9 ){
        in = r + 100*(10-n);
    } else {
        in = r;
    }
    
    printf("%d\n",in);
    return 0;
    
}



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


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

    cout<< n*(n+1)/2 <<endl;


    return 0;

}



Measured memory_bytes: 256
#include<iostream>
#include<deque>
#include<algorithm>
#include<math.h>
#include<string>
using namespace std;
int main() {
	int n, m, ans = 1;
	cin >> n >> m;
	deque<pair<int, int>> p(m);
	for (int i = 0; i < m; i++)
		cin >> p[i].first >> p[i].second;
	sort(p.begin(), p.end());
	int r = p[0].second;
	for (int i = 1; i < m; i++) {
		if (p[i].second <= r) {
			r = p[i].second;
		}
		if (p[i].first >= r) {
			ans++;
			r = p[i].second;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

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

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

    if(v[0] + v[1] == v[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

int main()
{
	using vi = std::vector<int64_t>;

	int N, W;
	scanf("%d%d", &N, &W);
	vi dp(W + 1, -1);
	dp[0] = 0;
	std::vector<int> v(N), w(N);
	for (int i{}; i < N; i++) scanf("%d%d", &v[i], &w[i]);
	for (int i{}; i < N; i++)
		for (int j{W}; j - w[i] >= 0; j--)
			if (dp[j - w[i]] >= 0)
				dp[j] = std::max(dp[j], dp[j - w[i]] + v[i]);
	printf("%lld\n", *std::max_element(dp.begin(), dp.end()));

	return 0;
}


Measured memory_bytes: 3288
import java.util.Arrays;
import java.util.Scanner;

public class Main {
  private static Scanner sc;

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


  private void solve() {
    int[] inp = new int[3];
    for (int i = 0; i < 3; i++) {
      inp[i] = sc.nextInt();
    }

    Arrays.sort(inp);

    int ans = 0;
    ans += Math.abs(inp[0] - inp[1]);
    ans += Math.abs(inp[1] - inp[2]);

    System.out.println(ans);
  }
}


Measured memory_bytes: 23636
package main

import "fmt"

func main() {
	var s, t string
	fmt.Scan(&s, &t)
	var a, b int
	fmt.Scan(&a, &b)
	var u string
	fmt.Scan(&u)

	if s == u {
		a--
	} else {
		b--
	}

	fmt.Println(a, b)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*----------------------------------------------*/
vi to[200200];
int cnt[200200];

void dfs(int v,int p=-1){
  for(int u:to[v]){
    if(u==p) continue;
    cnt[u]+=cnt[v];
    dfs(u,v);
  }
}

signed main(){
  int n,q;
  cin>>n>>q;
  rep(i,n-1){
    int a,b;
    cin>>a>>b;
    a--;b--;
    to[a].pb(b);
    to[b].pb(a);
  }
  rep(i,q){
    int p,x;
    cin>>p>>x;
    p--;
    cnt[p]+=x;
    // dfs(p);
  }
  dfs(0,-1);
  rep(i,n){
    cout<<cnt[i];
    if(i<n-1) cout<<" ";
  }
  cout<<endl;

  return 0;
}


Measured memory_bytes: 24320
a,b,c=gets.split(" ").map(&:to_i)
require 'prime'
k = a.gcd(b)
d = [1]
p = []
Prime.prime_division(k).each do |pr|
  pr[1].times {p << pr[0]}
end

1.upto(p.size) do |i|
  p.combination(i) do |prime|
    d << prime.inject{|ka,kb| ka *= kb}
  end
end

p d.uniq.sort.reverse[c-1]

Measured memory_bytes: 2044
from math import ceil
# 小数点以下を繰り上げた値を出力するので，最大長さを整数の中 (0からmax(A)の間) から探す． (これをxとする)
# すべての本数をxより小さくするまでの回数がK以下であれば良い．

def main(N, K, A):
    # 二分探索内で用いる判定用関数
    def check(x):   # すべての長さをx以下にするための回数
        cnt = 0 # すべての長さをx以下にするために何回切ったか
        for a in A:
            cnt += ceil(a / x) - 1  # 切り口は1つ少ない
        return cnt <= K # K回以内で操作を終えることができたかどうか．

    l, r = 0, max(A)    # この中をxが動く．
    while l < r - 1:    # 差が1未満 == lとrが隣り合わせ == rができる最小， lができない最大を示し，それらが隣り合わせ
        mid = (l + r) // 2
        if check(mid): # 真ん中の条件でも終えることができるならそれよりも小さくできるので， r (最大方向) を縮める．
            r = mid
        else:
            l = mid
    print(r)


if __name__ == '__main__':
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    main(N, K, A)

Measured memory_bytes: 31072
N = int(input())
Pls = [0]*(10**4+1)
for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            k = x**2+y**2+z**2+x*y+y*z+z*x
            if k <= 10**4:
                Pls[k] = Pls[k] + 1
Pls.pop(0)
for i in range(N):
    print(Pls[i])

Measured memory_bytes: 69396
void main()
{
    long n = rdElem;

    Edge[][] tree = new Edge[][](n);
    foreach (i; 0 .. n-1)
    {
        long a, b, c;
        rdVals(a, b, c);
        --a, --b;
        tree[a] ~= Edge(b, c), tree[b] ~= Edge(a, c);
    }

    long q, k;
    rdVals(q, k);

    --k;
    long[] dist = new long[n];
    void DFS(long u, long v, long w)
    {
        dist[u] = w;
        foreach (t; tree[u])
        {
            if (t.to == v) continue;
            DFS(t.to, u, w+t.cost);
        }
    }

    DFS(k, -1, 0);
    foreach (i; 0 .. q)
    {
        long x, y;
        rdVals(x, y);
        --x, --y;
        writeln(dist[x] + dist[y]);
    }
}

struct Edge
{
    long to, cost;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 34940
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int l,r,d;
int main()
{
    IO;
    cin>>l>>r>>d;
    if(r<l) swap(l,r);
    int res=r/d-l/d;
    if(l%d==0) res++;
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 3648
# include <bits/stdc++.h>
using namespace std;
double a[55];
int main(){
	int n;
	cin >> n;
	for(int i = 1; i <= n; i ++) cin >> a[i];
	sort(a + 1 , a + n + 1);
	double res = a[1];
	for(int i = 2; i <= n; i ++) res = (res + a[i]) / 2;
	cout << setprecision(10) << res << "\n";
}

Measured memory_bytes: 256
A, B, C = map(int, input().split())

seen = {}
find_flag = 0
for i in range(1, 100):
    rest = A * i % B
    if rest == C:
        find_flag += 1
        break
    if seen.get(rest):
        break
    else:
        seen[rest] = 1

if find_flag:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3060
//There was and will always be only one Chester
//RIP legend
#include<bits/stdc++.h>
#define Nilesh ios_base::sync_with_stdio(false)
using namespace std;
int main()
{
    string a;
    cin>>a;
    if(a[0]=='9' || a[1]=='9')
        cout<<"Yes";
    else
        cout<<"No";

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define REP1(i,n) for(int i=1; i<=(int)(n); i++)
#define SORT(v) sort(v.begin(), v.end())
#define REVERSE(v)  reverse(v.begin(), v.end())
using namespace std;

int main() {
  int H,W; cin>>H>>W;
  int a[H+2][W+2];
  int N = 0;
  int p[250010],q[250010],r[250010],s[250010];
  REP1(i,H) {
    REP1(j,W) {
      cin>>a[i][j];
    }
  }

  REP1(i,H-1) {
    REP1(j,W) {
      if(a[i][j] % 2 == 1) {
        N++;
        a[i+1][j]++;
        p[N]=i;
        q[N]=j;
        r[N]=i+1;
        s[N]=j;
        // cout<<a[i]<<" "<<a[j]<<" "<<a[i+1]<<" "<<a[j]<<endl;
      }
    }
  }

  REP1(j,W-1) {
    if(a[H][j] % 2 == 1) {
      N++;
      a[H][j+1]++;
      p[N]=H;
      q[N]=j;
      r[N]=H;
      s[N]=j+1;
      // cout<<a[H]<<" "<<a[j]<<" "<<a[H]<<" "<<a[j+1]<<endl;
    }
  }

  cout<<N<<endl;
  REP1(i,N) {
    cout<<p[i]<<" "<<q[i]<<" "<<r[i]<<" "<<s[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 7424
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;


int main(){
    llong a;
    cin >> a;
    llong ans = 10000;
    while(a >99){
        llong tmp = a%1000;
        ans = min( ans, abs( tmp -753));
        a/=10;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int x1, y1, x2, y2, x3, y3, x4, y4, dx, dy;
	cin >> x1 >> y1 >> x2 >> y2;

	dx = x2 - x1;
	dy = y2 - y1;
	swap(dx, dy);
	dx = -dx;
	x3 = x2 + dx;
	y3 = y2 + dy;
	x4 = x1 + dx;
	y4 = y1 + dy;

	cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
    ll n,m,c,count=0;
    cin>>n>>m>>c;
    ll b[m];
    for(int i=0;i<m;i++)
    {
        cin>>b[i];
    }
    for(int i=0;i<n;i++)
    {ll s=0;

        for(int j=0;j<m;j++)
        {
                ll x;
                cin>>x;
                s+=(x*b[j]);
        }
        if(s+c>0)
            count++;
    }
    cout<<count<<endl;
}
return 0;
}

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

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

ll factorial(ll x) {
	ll f=1;
	for(ll i=2; i<x; i++) {
		f*=i;
	}
	return f;
}

ll npr(ll n, ll r) {
	ll result=1;
	for(ll i=r+1; i<=n; i++) result*=i;
	return result;
}

bool IsPrime(ll num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (ll i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}



int main() {
	int n,k; cin>>n>>k;
	int len[n]; for(int &l: len) cin>>l;
	sort(len,len+n,greater<>());
	cout << accumulate(len,len+k,0) << endl;
}


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

int main()
{
    int A, B, C;
    std::cin >> A >> B >> C;
    int mx = A;
    if(mx < B) {mx = B;}
    if(mx < C) {mx = C;}
    int ans = A + B + C + 9 * mx;
    std::cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int n, ans;

int is_valid(int x) {
  int t = x;
  int f[3] = {0};
  while (t != 0) {
    int a = t%10;
    if (a == 7) { f[0] = 1; }
    if (a == 5) { f[1] = 1; }
    if (a == 3) { f[2] = 1; }
    t /= 10;
  }
  if ( x <= n && f[0] && f[1] && f[2]) { return 1; }
  else { return 0; }
}

// cur: 現在(current)の数字
void dfs(int cur, int depth) {
  if (depth == 10) { return; }
  if ( is_valid(cur) ) {
    ans++;
  }
  // 3つに分岐
  dfs(cur*10+7, depth+1);
  dfs(cur*10+5, depth+1);
  dfs(cur*10+3, depth+1);
}

int main () {
  scanf("%d", &n);
  dfs(0, 0);
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
  int id;
  struct node *next;
} *nodePointer;
nodePointer *headArr;
nodePointer *tailArr;
void pushBack(int,int);
void dump(int);
void clear(int);
nodePointer make1node(int);
void init(int);
int main(void)
{
  int i;
  int n,q;
  int x1,x2,x3;
  scanf("%d",&n);
  init(n);
  scanf("%d",&q);
  for(i=0;i<q;i++)
    {
      scanf("%d",&x1);
      switch(x1)
        {
        case 0:
          scanf("%d%d",&x2,&x3);
          pushBack(x2,x3);
          break;
        case 1:
          scanf("%d",&x2);
          dump(x2);
          break;
        case 2:
          scanf("%d",&x2);
          clear(x2);
          break;
        }
    }
  return 0;
}
void pushBack(int t,int x)
{
  nodePointer p=make1node(x);
  if(headArr[t]==NULL)
    {
      headArr[t]=p;
      tailArr[t]=p;
    }
  else
    {
      tailArr[t]->next=p;
      tailArr[t]=p;
    }
}
void dump(int t)
{
  nodePointer p;
  for(p=headArr[t];p!=NULL;p=p->next)
    {
      printf("%d",p->id);
      if(p->next!=NULL) printf(" ");
    }
  printf("\n");
}
void clear(int t)
{
  headArr[t]=NULL;
  tailArr[t]=NULL;
}
nodePointer make1node(int x)
{
  nodePointer p=(nodePointer)malloc(sizeof(struct node));
  p->id=x;
  p->next=NULL;
  return p;
}
void init(int n)
{
  int i;
  headArr=(nodePointer*)malloc(sizeof(nodePointer)*n);
  for(i=0;i<n;i++) headArr[i]=NULL;
  tailArr=(nodePointer*)malloc(sizeof(nodePointer)*n);
  for(i=0;i<n;i++) tailArr[i]=NULL;
}


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

using namespace std;
 
typedef pair<string, int> P;
 
int main()
{
    string str;
    int page, cnt = 0;
    vector<P> v;
 
    while (cin >> str >> page) {
	v.push_back(P(str, page));
	cnt++;
    }
 
    sort(v.begin(), v.end());
    for (int i = 0; i < cnt; i++) {
	if (i == 0) {
	    cout << v[i].first << endl;
	    cout << v[i].second;
	    continue;
	}
 
	if (v[i].first == v[i-1].first && v[i].second!=v[i-1].second) {
	    cout << ' ' << v[i].second;
	    continue;
	} else {
            cout << endl;
        }
	cout << v[i].first << endl;
	cout << v[i].second;
    }
    puts("");
    return 0;
}

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

using namespace std;

int h, w, u[2005][2005], d[2005][2005], l[2005][2005], r[2005][2005];
char s[2005][2005];

int main() {
	scanf("%d%d", &h, &w);
	
	for (int i = 0; i < h; i++) scanf("%s", s[i]);
	
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (s[i][j] == '#') continue;
			
			if (i == 0) u[i][j] = 1;
			else u[i][j] = u[i - 1][j] + 1;
			
			if (j == 0) l[i][j] = 1;
			else l[i][j] = l[i][j - 1] + 1;
		}
	}
	
	for (int i = h - 1; i >= 0; i--) {
		for (int j = w - 1; j >= 0; j--) {
			if (s[i][j] == '#') continue;
			
			if (i == h - 1) d[i][j] = 1;
			else d[i][j] = d[i + 1][j] + 1;
			
			if (j == w - 1) r[i][j] = 1;
			else r[i][j] = r[i][j + 1] + 1;
		}
	}
	
	int res = 0;
	
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (s[i][j] == '#') continue;
			res = max(res, u[i][j] + d[i][j] + l[i][j] + r[i][j] - 3);
		}
	}
	
	printf("%d\n", res);
}


Measured memory_bytes: 66944
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define INF 1000000000000000000
#define all(x) x.begin(), x.end()
#define PI 3.141592653589793

int main() {
    string s;
    cin >> s;
    int N = s.size();
    vector<ll> A(N + 1, 0);
    rep(i, N) {
        if (s[i] == '<') {
            A[i + 1] = A[i] + 1;
        }
    }

    for (int i = N - 1; i >= 0; i--) {
        if (s[i] == '>') {
            A[i] = max(A[i], A[i + 1] + 1);
        }
    }

    ll sum = accumulate(all(A), (ll)0);
    cout << sum << endl;
}


Measured memory_bytes: 4740
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = int64_t;
using ull = uint64_t;
using PLL = pair<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
// #include "../debug/debug.cpp"
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

int main() {
    string S;
    cin >> S;
    ll ans = 0;
    ll sum = 0;
    ll rest = S.size();
    for(char c : S) {
        rest--;
        if(c == '0') continue;
        chmax(ans, sum + (c - '1') + 9 * rest);
        sum += (c - '0');
    }
    chmax(ans, sum);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define K 2000
#define N 2000
#define MD 1000000007

int main() {
	static int choose[N + 1][N + 1];
	int n, k, i, j;

	scanf("%d%d", &n, &k);
	choose[0][0] = 1;
	for (i = 1; i <= n; i++) {
		choose[i][0] = 1;
		for (j = 1; j <= i; j++)
			choose[i][j] = (choose[i - 1][j - 1] + choose[i - 1][j]) % MD;
	}
	for (i = 1; i <= k; i++)
		printf("%lld\n", (long long) choose[n - k + 1][i] * choose[k - 1][i - 1] % MD);
	return 0;
}


Measured memory_bytes: 14976
#include "bits/stdc++.h"

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;

constexpr size_t    operator""_sz(unsigned long long value) { return value; };
constexpr intmax_t  operator""_im(unsigned long long value) { return value; };
constexpr uintmax_t operator""_um(unsigned long long value) { return value; };
// }}} End

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

    string s;
    cin >> s;

    vector<intmax_t> a(s.length() + 1);
    int cnt = 0;
    for (int i = 0; i < s.length(); ++i) {
        if (s[i] == '<') {
            a[i] = cnt;
            cnt++;
        } else {
            a[i] = cnt;
            cnt = 0;
        }
    }
    a[s.length()] = cnt;

    dump(a);

    cnt = 0;
    for (int i = s.length() - 1; i >= 0; --i) {
        if (s[i] == '>') {
            chmax(a[i + 1], cnt);
            cnt++;
        } else {
            chmax(a[i + 1], cnt);
            cnt = 0;
        }
    }
    a[0] = cnt;

    dump(a);

    intmax_t res = 0;
    for (auto &ai : a) {
        res += ai;
    }

    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 4764
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#define ll long long
#define ull unsigned long long
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define FOR(i,start,stop)  for(int i=(start); i < (stop); i++)
#define FORD(i,start,stop) for(int i=(start); i >= (stop); i--)
#define RIP(i,stop) FOR(i,0,stop)
#define PI 3.141592653589793
#define PRECISION(c,f) fixed << setprecision(c) << f
using namespace std;

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

  if(s == "ABC") cout << "ARC" << endl;
  else cout << "ABC" << endl;

  return 0;
}


Measured memory_bytes: 3620
#include<stdio.h> 
#include<math.h> 
int main()
{
    int i, j, n, x[100], y[100];
    double p, max;   
     
    scanf("%d", &n);
    for(i=0; i<n; i++)
    {
        scanf("%d", &x[i]);  
    }
     
    for(i=0; i<n; i++)
    {
        scanf("%d", &y[i]);
    }
     
    for(j=1; j<=3; j++)
    {
        p=0.0; 
        for(i=0; i<n; i++)
        { 
            p += pow((abs(x[i]-y[i])), j);
        } 
        p = pow(p,1.0 / j);
        printf("%f\n", p); 
    }
     
    max = abs(x[0]-y[0]);
     
    for(i=1; i<n; i++)
    {
        if(max < abs(x[i]-y[i]))
        {
            max = abs(x[i]-y[i]); 
        }
    }
     
    printf("%f\n", max); 
     
    return 0; 
}

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

int main() {
  string S;
  cin >> S;

  int n = S.size();
  int cnt = 0;
  string ans = "WA";

  if (S[0] != 'A') {
    cout << ans << endl;
    return 0;
  }

  for (int i = 1; i < n; i++) {
    char c = S[i];
    if ('a' <= c && c <= 'z')
      continue;
    else {
      if (S[i] == 'C' && 2 <= i && i <= n - 2)
        cnt++;
      else {
        cout << ans << endl;
        return 0;
      }
    }
  }

  if (cnt == 1)
    ans = "AC";

  cout << ans << endl;
}

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

ll N, C, W[105], V[105];
ll dp[105][100005], ans;

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

	cin >> N >> C;
	for (ll i = 0; i < N; i++) {
		cin >> W[i] >> V[i];
	}

	memset(dp, -1, sizeof(dp));
	dp[0][C] = 0;
	dp[0][C-W[0]] = V[0];
	ans = V[0];

	for (ll i = 1; i < N; i++) {
		for (ll j = 0; j <= C; j++) {
			dp[i][j] = dp[i-1][j];
			if (j+W[i] <= C && dp[i-1][j+W[i]] != -1) {
				dp[i][j] = max(dp[i][j], dp[i-1][j+W[i]] + V[i]);
			}
			ans = max(ans, dp[i][j]);
		}
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 82304
N, Y = map(int, input().split())
Y = Y//1000
for a in range(N+1):
    for b in range(N+1-a):
        if Y == a*10 + b*5 + (N - a - b):
            print(a,b,N-a-b)
            exit(0)
else:
    print(-1,-1,-1)

Measured memory_bytes: 9136
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>

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

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

using std::min;
using std::max;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()

long long dp[303][303];
int n, k;
long long h[500];

signed main()
{
    srand(time(NULL));
    //freopen("", "r", stdin);
    //freopen("", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> h[i + 1], h[i + 1]++;
    h[0] = 1;
    h[n + 1] = 1;
    for (int i = 0; i <= 302; i++) for (int j = 0; j <= 302; j++) dp[i][j] = 1e18;
    dp[0][0] = 1;
    for (int i = 1; i <= n + 1; i++)
    {
        for (int j = 0; j <= k; j++)
        {
            for (int last = 0; last < i; last++)
            {
                int cnt = i - last - 1;
                //cout << i << " " << j << " " << last << endl;
                if (cnt <= j)
                {
                    dp[i][j] = min(dp[i][j], dp[last][j - cnt] + max(0LL, h[i] - h[last]));
                }
            }
        }
    }
    ll ans = 1e18;
    for (int i = 0; i <= k; i++) ans = min(ans, dp[n + 1][i]);
    cout << ans - 1;
}


Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <iomanip>
#include <limits>
#include <stack>

#define roop(i, n) for(int i=0;i<n;i++)
#define DIV 1000000007
//static const long double pi = 3.1415926535897932;

using namespace std;
using ll = long long int;
using ull = unsigned long long;

char toSmall(char c) { // 大文字を小文字へ
	return (c + 0x20);
}

char toLarge(char c) { // 小文字を大文字へ
	return (c - 0x20);
}

float myPower(int a, int n) { // aのn乗の計算
	float x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

ll combination(ll n, ll r) { // nCr の計算
	if (n < 0 || r < 0 || r > n) return -1;

	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> num(r);
	vector<ll> den(r);

	for (ll i = 0; i < r; i++) {
		num[i] = n - r + i + 1;
		den[i] = i + 1;
	}

	for (ll p = 2; p <= r; p++) {
		ll pivot = den[p - 1];
		if (pivot > 1) {
			ll offset = (n - r) % p;
			for (ll k = p - 1; k < r; k += p) {
				num[k - offset] /= pivot;
				den[k] /= pivot;
			}
		}
	}
	ll result = 1;
	for (ll k = 0; k < r; k++) {
		if (num[k] > 1) result *= num[k];
	}
	return result;
}

vector<string> split(const string& src, const char* delim = ",") { //カンマ区切り
	vector<string> vec;
	string::size_type len = src.length();

	for (string::size_type i = 0, n; i < len; i = n + 1) {
		n = src.find_first_of(delim, i);
		if (n == string::npos) {
			n = len;
		}
		vec.push_back(src.substr(i, n - i));
	}

	return vec;
}

bool check_int(string str)
{
	if (all_of(str.cbegin(), str.cend(), [](char ch) { return isdigit(ch);}))
	{
		return true;
	}
	return false;
}

struct rest {
	string s;
	int p;
	int num;

	/* -------------------------------------
	sort関数を使用したときのソートの定義をする。
	まずは文字列sでソートする。
	文字列sが同じだった場合、pでソートする。
	この条件を参考演算子で表現(ifでもOK)
	-------------------------------------*/
	bool operator<(const rest& right) const {
		return s == right.s ? p > right.p : s < right.s;
	}
};

int main() {
	string s;
	cin >> s;
	for (int i = 0; i < s.length(); i++) {
		cout << "x";
	}
	cout << endl;
	return 0;
}

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

int main(void) {
    int d[3];
    for (int i = 0; i < 3; i++) cin >> d[i];
    sort(d, d + 3);
    cout << d[0] << ' ' << d[1] << ' ' << d[2] << endl;
    return 0;
}

Measured memory_bytes: 1176
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>

using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7; 
const int MINF = -1050000000;


int main() {
	int n;
	cin >> n;
	map<int, int> mp;
	
	for (int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		mp[i] = x;
	}
	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		int a = mp[i];
		int b = mp[a];
		if (i == b) cnt++;
	}
	cout << cnt/2 << endl;
	return 0;
}


Measured memory_bytes: 4992
import sys
import math
import fractions
from collections import deque
from collections import defaultdict
sys.setrecursionlimit(10**7)

N, M = map(int, input().split())
H = list(map(int, input().split()))
good = [True] * N
for i in range(M):
    A, B = map(int, input().split())
    A -= 1
    B -= 1
    if H[A] <= H[B]:
        good[A] = False
    if H[B] <= H[A]:
        good[B] = False

cnt = 0
for g in good:
    if g:
        cnt += 1

print(cnt)


Measured memory_bytes: 87044
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++) 
#define all(v) begin(v),end(v)
using ll = long long;

int main() {
  int n,d,x;cin>>n>>d>>x;
  vector<int>a(n+1);
  for(int i=1;i<=n;i++)cin>>a[i];
  int cnt=0;
  for(int i=1;i<=n;i++){
    int ans=1;
    for(int j=1;;j++){
      if(ans>d)break;
      cnt++;
      ans=j*a[i]+1;
    }
  }
  cout<<cnt+x<<endl;
}

Measured memory_bytes: 3636
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)

	N := getInt()
	a := make([]int, N)
	b := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = getInt()
	}
	for i := 0; i < N; i++ {
		b[i] = getInt()
	}

	sum := 0
	d := make([]int, N)
	for i := 0; i < N; i++ {
		d[i] = a[i] - b[i]
		sum += d[i]
	}

	// out(d, sum)

	if sum < 0 {
		out(-1)
		return
	}

	sort.Ints(d)
	sum0 := 0
	pos0 := 0
	sum1 := 0
	pos1 := len(d) - 1
	for i := 0; i < N; i++ {
		if d[i] < 0 {
			sum0 -= d[i]
			pos0++
		}
	}
	cnt := 0
	for i := 0; i < N; i++ {
		if sum1 >= sum0 {
			break
		}
		sum1 += d[pos1]
		pos1--
		cnt++
	}

	out(cnt + pos0)
}


Measured memory_bytes: 5888
#include<cstring>
#include<iostream>
using namespace std;
string s1;
int k;
int main() {
    cin>>k;
    cin>>s1;
    if(s1.length()>k) {
        for(int i=0;i<k;i++) cout<<s1[i];
        cout<<"...";
    }
    else cout<<s1;
    return 0;
}

Measured memory_bytes: 3128
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <deque>
#include <utility>
#include <algorithm>
using namespace std;

int main(void){

    int n;
    cin>>n;
    
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    
    sort(a.begin(), a.end(), greater<int>());
    
    int al=0, bob=0;
    for(int i=0; i<n; i++){
        if(i%2==0){
            al+=a[i];
        }else{
            bob+=a[i];
        }
    }
    
    cout<<al-bob<<endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public final class Main {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final int n = Integer.parseInt(in.nextLine());
        int[] arr = new int[n];
        int res = 0;
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
            res += arr[i] - 1;
        }
        System.out.println(res);
    }
}


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

int main(){
  vector<int> X(3);
  
  for(int i=0;i<3;i++){
    cin >> X.at(i);
  }
  
  sort(X.begin(),X.end());
  
  cout << X.at(0)+X.at(1) <<endl;

}

Measured memory_bytes: 256
import java.util.Iterator;
import java.util.PrimitiveIterator;
import java.util.Scanner;
import java.util.function.BinaryOperator;
import java.util.stream.IntStream;
import java.util.stream.Stream;

class Main{

	private void solve(){
		int n=gInt();
		int[][]open=REPS(n).mapToObj(i->ints(10).toArray()).toArray(int[][]::new);
		int[][]v   =REPS(n).mapToObj(i->ints(11).toArray()).toArray(int[][]::new);

		Merger<Integer>max=new Merger<>(Integer.MIN_VALUE,Math::max);

		for(int b:rep(1,0b1111111111)) {
			boolean f=false;
			int sum=0;
			for(int i:rep(n)) {
				int c=(int)REPS(10)
						.filter(j->((1<<j)&b)>0&&open[i][j]==1)
						.count();
				f|=c!=0;
				sum+=v[i][c];
			}
			if(f)
				max.update(sum);
		}
		System.out.println(max.get());
	}

	public static class Merger<T>{
		private T v;
		private BinaryOperator<T>f;
		public Merger(T init,BinaryOperator<T>merge){
			v=init;
			f=merge;
		}
		public T update(T t) {
			return v=f.apply(v,t);
		}
		public T get() {
			return v;
		}
	}

	public static void main(String[]$){
		new Main().solve();
	}

	static Scanner s=new Scanner(System.in);


	static int gInt(){
		return s.nextInt();
	}

	static long gLong(){
		return s.nextLong();
	}

	static long gDouble(){
		return s.nextLong();
	}


	static Range rep(int i){
		return new Range(i);
	}
	static Range rep(int f,int t,int d){
		return new Range(f,t,d);
	}
	static Range rep(int f,int t){
		return rep(f,t,1);
	}
	static Range rrep(int f,int t){
		return rep(f,t,-1);
	}

	static class Range implements Iterable<Integer>,PrimitiveIterator.OfInt{

		int to,cur,d;

		Range(int from,int to,int d){
			this.cur=from-d;
			this.to=to;
			this.d=d;
		}

		Range(int n){
			this(0,n-1,1);
		}

		@Override
		public Iterator<Integer> iterator(){
			return this;
		}

		@Override
		public boolean hasNext(){
			return cur+d==to||(cur!=to&&(cur<to==cur+d<to));
		}

		@Override
		public int nextInt(){
			return cur+=d;
		}
	}


	static IntStream REPS(int v){
		return IntStream.range(0,v);
	}

	static IntStream REPS(int l,int r){
		return IntStream.rangeClosed(l,r);
	}


	static IntStream ints(int n){
		return REPS(n).map(i->gInt());
	}

	static Stream<String> strs(int n){
		return REPS(n).mapToObj(i->s.next());
	}

}

Measured memory_bytes: 47884
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
  int X, A, B;
  cin >> X >> A >> B;
  if (A - B >= 0) cout << "delicious" << endl;
  else if ((X + A) - B >= 0) cout << "safe" << endl;
  else cout << "dangerous" << endl;
}


Measured memory_bytes: 256
import java.awt.geom.*;
import java.util.*;
public class Main{
	double EPS = 1.0e-08;
	int INF = 1 << 24;
	//1240 start
	//1333 cording end
	//2325 restart
	//0007 sample match
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n == 0) break;
			Circle [] clist = new Circle[n];
			for(int i = 0; i < n; i++){
				Point2D p = new Point2D.Double(sc.nextInt(), sc.nextInt());
				clist[i] = new Circle(p, sc.nextInt());
			}
			
			ArrayList<Point2D> cand = new ArrayList<Point2D>();
			cand.add(clist[0].p);
			for(int i = 0; i < n-1; i++){
				Point2D [] res = intersectPtCC(clist[i], clist[i+1]);
				cand.add(res[0]);
				cand.add(res[1]);
			}
			cand.add(clist[n-1].p);
			
			int len = cand.size();
			double [][] dp = new double[len][len];
			for(int i = 0 ; i < len; i++){
				Arrays.fill(dp[i], INF);
				dp[i][i] = 0.0;
			}
			for(int i = 0; i < len; i++){
				for(int j = i + 1; j < len; j++){
					boolean isOK = true;
					Line2D m = new Line2D.Double(cand.get(i), cand.get(j));
					for(int k = j - 2; k > i; k -= 2){
						Line2D l;
						if(k % 2 == 0){
							l = new Line2D.Double(cand.get(k-1), cand.get(k));
						}
						else{
							l = new Line2D.Double(cand.get(k), cand.get(k + 1));
						}
						if(! m.intersectsLine(l)){
							isOK = false;
							break;
						}
					}
					if(isOK){
						dp[i][j] = cand.get(i).distance(cand.get(j));
						dp[j][i] = cand.get(i).distance(cand.get(j));
					}
				}
			}
			if(dp[0][len-1] == INF){
				for(int j = 0; j < len; j++){
					for(int i = 0; i < len; i++){
						for(int k = 0; k < len; k++){
							dp[i][k] = Math.min(dp[i][k], dp[i][j] + dp[j][k]);
						}
					}
				}
			}
			System.out.printf("%.6f\n",dp[0][len-1]);
		}
	}
	
	public class Circle{
		Point2D p;
		double r;
		public Circle(Point2D p, double r) {
			this.p = p; this.r = r;
		}
	}
	
	//円と円の交点
	Point2D [] intersectPtCC(Circle a,Circle b) {
		double dis = a.p.distance(b.p);
		Point2D v = sub(b.p, a.p);
		double rc = (dis * dis + a.r * a.r - b.r * b.r) / (2 * dis);
		double rate = rc / dis;
		v = mul(v, rate);
		Point2D c = add(v, a.p);
		double disC2c = c.distance(b.p);
		double disqc = Math.sqrt(b.r * b.r - disC2c * disC2c);
		Point2D v2 = sub(b.p, c);
		v2 = mul(v2, disqc / disC2c);
		Point2D [] res = new Point2D[2];
		res[0] = add(normalV1(v2), c);
		res[1] = add(normalV2(v2), c);
		return res;
	}
	
	private Point2D normalV1(Point2D p) {
		return new Point2D.Double(-p.getY(), p.getX());
	}
	
	private Point2D normalV2(Point2D p) {
		return new Point2D.Double(p.getY(), -p.getX());
	}

	private Point2D add(Point2D p1, Point2D p2) {
		double x = p1.getX() + p2.getX();
		double y = p1.getY() + p2.getY();
		return new Point2D.Double(x,y);
	}

	private Point2D mul(Point2D v, double rate) {
		return new Point2D.Double(v.getX() * rate, v.getY() * rate);
	}

	private Point2D sub(Point2D p1, Point2D p2) {
		double x = p1.getX() - p2.getX();
		double y = p1.getY() - p2.getY();
		return new Point2D.Double(x,y);
	}
	
	public static void main(String [] args){
		new Main().doit();
	}
}

Measured memory_bytes: 17000
#include <stdio.h>

int main() {

  int h,w,x,i,j,minx,mini,minj;

  while(scanf("%d%d",&h,&w),h){

    x = h*h +w*w;
    minx=100000000;
    
    for( i=1;i<100;i++){
      for(j=1;;j++){
	if(i>=j)continue;
	if((i*i+j*j > x) || (i*i+j*j==x && i>h )){
	  if(minx > i*i +j*j){
	    minx=i*i+j*j;
	    mini=i;
	    minj=j;
	  }
	  break;
	}
      }
    }

    printf("%d %d\n",mini,minj);

  }

  return 0;

}

Measured memory_bytes: 600