akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pp pair<ll,ll>
#define ppp pair<ll,pp >
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
typedef tree<pp,null_type,less<pp>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rep(i,a,b) for(ll i=a;i<b;i+=1)
#define sz(v) (ll)(v.size())
#define hell (ll)998244353
#define slld(x) scanf("%lld",&x)
ll t=1, tt;
const ll nax=3005, N=nax;
ll dp[3005][3005];
ll fact[N], invFact[N];
ll add(ll x,ll y){x+=y;return x%hell;}
ll mult(ll x,ll y){return (1LL*x*y)%hell;}
ll powMod(ll base,ll expo){
	ll ans=1;
	while(expo){
		if(expo&1)ans=mult(ans,base);
		base=mult(base,base);
		expo>>=1;
	}
	return ans;
}
ll C(ll x,ll y){
	if(x<0 || y<0 || x<y)return 0;
	return mult(fact[x],mult(invFact[y],invFact[x-y]));
}
ll get(ll x){
	return powMod(powMod(2,x),hell-2);
}
void solve(){
	ll n, s;
	cin>>n>>s;
	vector<ll> v(n), cnt(nax,0);
	rep(i,1,n+1){
		cin>>v[i-1];
		cnt[v[i-1]]++;
	}
	dp[0][0]=powMod(2,n);
	rep(i,1,n+1){
		rep(j,0,nax){
			dp[i][j]=add(dp[i-1][j],dp[i][j]);
			if(j+v[i-1]<nax)dp[i][j+v[i-1]]=add(dp[i][j+v[i-1]],mult(dp[i-1][j],get(1)));
		}
	}
	cout<<dp[n][s];
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    fact[0]=1;
    rep(i,1,N)fact[i]=mult(fact[i-1],i);
    invFact[N-1]=powMod(fact[N-1],hell-2);
    for(ll i=N-2;i>=0;i--)invFact[i]=mult(invFact[i+1],i+1);
   	//cin>>t;
   	tt=t;
    while(t--){
        solve();
        if(t)cout<<"\n";
    }
    return 0 ;
}


Measured memory_bytes: 74136
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include <functional>
#include <set>
#include <map>
#include <queue>
#include <math.h>
#include <stack>

using namespace std;


int main() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << (a + b) * c / 2;
}

Measured memory_bytes: 256
///mAAria...
#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long
typedef pair<int,int> pii;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define inf 1000000000

const long double PI = acos(-1);

int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

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


void solve(){
   int n;
  cin >> n;
  int cur = 0;
  
  for(int i = 1;i<=n;i++){
    int a;
    cin >> a;
    if(a==cur+1){
      cur+=1;
    }
  }
  if(n-cur<=n-1)
   cout << n-cur << endl;
  else
    cout << -1 << endl;
  
}

signed main() 
{   
    IOS;
    int t = 1;
    //cin >> t;

    for(int i = 1;i<=t;i++){
        solve();
    }
    return 0;
} 

 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;

const int MAX_V = 500;
const int INF = 100000;

// 辺を表す構造体（行き先，容量，逆辺）
struct edge { int to, cap, rev; };

vector<vector<edge>> G(MAX_V);
vector<bool> used(MAX_V);

// fromからtoへ向かう容量capの辺をグラフに追加する
void add_edge(int from, int to, int cap) {
    G[from].push_back((edge){to, cap, G[to].size()});
    G[to].push_back((edge){from, 0, G[from].size() - 1});
}

// 増加パスをDFSで探す
int dfs(int v, int t, int f) {
    if (v == t) return f;
    used[v] = true;
    for (int i = 0; i < G[v].size(); i++) {
        edge &e = G[v][i];
        if (!used[e.to] && e.cap > 0) {
            int d = dfs(e.to, t, min(f,e.cap));
            if (d > 0) {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

// sからtへの最大流を求める
int max_flow(int s, int t) {
    int flow = 0;
    for (;;) {
        for(int j=0; j<used.size(); j++) used[j] = 0;
        int f = dfs(s, t, INF);
        if (f == 0) return flow;
        flow += f;
    }
    return 0;
}

int main() {
    int N; cin >> N;
    vector<int> a(N), b(N), c(N), d(N);

    rep(i,N) cin >> a[i] >> b[i];
    rep(i,N) cin >> c[i] >> d[i];
    rep(i,N) {
        rep(j,N) {
            if (a[i] < c[j] && b[i] < d[j]) add_edge(i+1,j+201,1);
        }
    }
    rep(i,N) add_edge(0,i+1,1);
    rep(i,N) add_edge(i+201,401,1);

    cout << max_flow(0,401) << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n, d;
  cin >> n >> d;
  int x[n][d];
  for(int i=0;i<n;i++){
      for(int j=0;j<d;j++){
          cin >> x[i][j];
      }
  }  
  int ans = 0;
  for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
          double dist = 0;
          for(int dx =0;dx<d;dx++){
              dist += pow(x[i][dx]-x[j][dx], 2);
          }
          if(dist == pow((int)sqrt(dist),2))
            ans ++;
      }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    private const long INFINITY = 9223372036854775807;
    public static void Main()
    {
        int A = NextInt();
        int B = NextInt();
        int C = NextInt();
        Console.WriteLine(Math.Min((B/A),C));
    }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

Measured memory_bytes: 13268
import itertools
import math
n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
res = 0
for v in itertools.combinations(x, 2):
    dist = 0
    for i in range(d):
        dist += abs(v[0][i]-v[1][i])**2
    if math.sqrt(dist).is_integer():
        res += 1
print(res)


Measured memory_bytes: 38324
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str;
		while ((str = br.readLine()) != null) {
			String inputs[] = str.split(" ");
			int a = Integer.parseInt(inputs[0]);
			int b = Integer.parseInt(inputs[1]);
			int count = 0;
			for (int i = 1; i <= a; i++) {
				if (i == a && a > b) {
					break;
				}
				count++;
			}
			System.out.println(count);
		}
	}
}


Measured memory_bytes: 23124
n = int(input())
TC = []
for i in range(n-1):
  TC.append(list(map(int, input().split())))


def time_calc(TC):
  pl = 0
  time = 0
  for info in TC:
    c, s, f = info
    if time <= s:
      time = s
    elif (time - s) % f != 0:
      time = time + f - (time % f)
    time += c
  return time
for i in range(n):
  print(time_calc(TC[i:]))

Measured memory_bytes: 41328
h, w = map(int, input().split())
canvas = [list(input()) for _ in range(h)]

flag = True
for i in range(h):
    for j in range(w):
        now = canvas[i][j]
        if now == '#':
            left = canvas[i][max(0, j - 1)]
            right = canvas[i][min(w - 1, j + 1)]
            up = canvas[max(0, i - 1)][j]
            down = canvas[min(h - 1, i + 1)][j]
            if left == right == up == down == '.':
                flag = False

print('Yes') if flag else print('No')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define inf (int)(1e9)

int main(){
	int N, M, i, j;
	scanf("%d%d", &N, &M);
	vector<vector<int>> dp(M + 1, vector<int>(1 << N, inf));
	dp[0][0] = 0;
	for(i = 0; i < M; i++){
		int a, b, c = 0;
		scanf("%d%d", &a, &b);
		for(j = 0; j < b; j++){
			int c_sub;
			scanf("%d", &c_sub);
			c_sub--;
			c |= (1 << c_sub);
		}
		for(j = 0; j < (1 << N); j++){
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
			dp[i + 1][j | c] = min(dp[i + 1][j | c], dp[i][j] + a);
		}
	}
	if(dp[M][(1 << N) - 1] >= inf){
		printf("-1\n");
	}
	else{
		printf("%d\n", dp[M][(1 << N) - 1]);
	}
	return 0;
}

Measured memory_bytes: 16256
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.HashMap;

class Main{

    static long C=20000*20000;
    static long B=20000;
    static long A=1;

    static long baseC = (long)1e8;
    static long baseB = (long)1e4;
    static long baseA = (long)1e4;

    static long mod =998244353;

    static int gcd(int x, int y){
        return y==0 ? x : gcd( y, x%y);
    }

    static long getVal(int a, int b,int c){
        int m = gcd(a, gcd(Math.abs(b),Math.abs(c)));
        a/=m; b/=m; c/=m;
        return ((long)c+baseC)*C + ((long)b + baseB)*B +((long)a + baseA)*A;
    }

    static long getLine(int x1,int y1,int x2, int y2){
        if(x1==x2)return getVal(1, 0, -x1);
        
        if(y2-y1<0){
            int tmp = y1;y1=y2;y2=tmp;
            tmp=x1;x1=x2;x2=tmp;
        }else if(y2-y1==0 && x2-x1<0){
            int tmp = x1;x1=x2;x2=tmp;
        }
        return getVal(y2-y1, x2-x1, y2*x1-y1*x2);
    }

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int[] x = new int[N];
        int[] y = new int[N];
        for(int i=0;i<N;++i){
            x[i]=scan.nextInt();
            y[i]= scan.nextInt();
        }
        long two[] = new long[N+1];
        two[0]=1;
        for(int i=1;i<=N;++i)two[i]=(two[i-1]*2)%mod;

        long ans = two[N];
        ans = (ans - (N*(N-1)/2) - N -1 +mod)%mod;

        Set<Long> used = new HashSet<>();
        for(int i=0;i<N;++i){
            Map<Long, Integer> line = new HashMap<>();
            for(int j=i+1;j<N;++j){
                long l = getLine(x[i], y[i], x[j], y[j]);
                if(used.contains(l))continue;
                if(!line.containsKey(l))line.put(l,0);
                line.put(l, line.get(l)+1);
            }
            for(Map.Entry<Long, Integer> entry : line.entrySet()){
                if(entry.getValue() >1){
                    int k = entry.getValue()+1;
                    ans = (ans - (two[k] - (k*(k-1)/2 +k +1) +mod)%mod +mod)%mod;
                    used.add(entry.getKey());
                }
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 27968
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>

using namespace std;
int main(){
	double v;
	while(cin >> v){
		double t = v / 9.8;
		double y = (v*v) / 19.6;
		double N = y/5 + 1;
		int n = (int)(N+1);

		cout << n << endl;
	}
	return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
 
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
//const ll mod =  1000000007;
//const ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvll = vector<vll>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------

int main(){
    ll a,ans=0;
    cin>>a;
    rep(i,a){
        rep(j,a){
            rep(k,a){
                ans+=gcd(gcd(i+1,j+1),k+1);
            }
        }
       
    }
    cout<<ans<<endl;
}
   



Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
#define INF 999999999
using namespace std;
int main() {
  int n, m;
  while (cin >> m >> n, m) {
    bool a[7654321] = {};
    int k = 0;
    int i = m;
    for (; k <= n; i++) {
      if (!a[i]) {
        int w = i;
        for (int j = 2; j * w < 7654321; j++) {
          a[j * w] = 1;
        }
        k++;
      }
    }
    cout << i - 1 << endl;
  }
  return 0;
}

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

using namespace std;

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

    string ans="Good";
    if(s[0]==s[1]) ans="Bad";
    if(s[2]==s[1]) ans="Bad";
    if(s[2]==s[3]) ans="Bad";
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e15+9
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n, k;
vector < int > vi;

bool check(int num){
	while (num != 0){
		REP(i, vi.size()){
			if (num % 10 == vi[i])return false;
		}
		num /= 10;
	}
	return true;
}

int main(){
	int ans = 99999;
	cin >> n >> k;
	REP(i, k){
		int num;
		cin >> num;
		vi.push_back(num);
	}
	for (int i = 99999; i >= n; i--){
		if (check(i)){
			ans = i;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		int a = sc.nextInt();
		int b = sc.nextInt();
		String u = sc.next();
		if (u.equals(s))
			a--;
		else b--;
		System.out.println(a + " " + b);
	}
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <tuple>

#define rep(i,n) for(ll i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;
//	std::cout<<std::fixed<<std::setprecision(10);

int main() {
	ll N;
	cin >> N;
	vector<int> L(N);
	rep(i, N) cin >> L[i];
	sort(L.begin(), L.end());

	vector<ll> dp; // dp[i]: L[i+2] までの棒を使用する．

	// dp[i+1] = (i+1番目を必ず使用) + dp[i];
	if(L[0]+L[1]>L[2]) dp.push_back(1);
	else dp.push_back(0);

	for(int i=1; i<N-2; i++) {
		int cnt = 0;

		/* 打ち切りや2分探索で高速化できる */
		for(int j = i-1+2; j>0; j--) {
			if(L[j]+L[j-1]<=L[i+2]) continue; // 打ち切り
			for(int k = j-1; k>=0; k--) {
				if(L[j]+L[k]>L[i+2]) cnt++;
				else break; // 打ち切り
				// cout << "cnt " << cnt << ' ' << L[i+2] << ' '<< L[j] << ' '<< L[k] << endl;
			}
		}

		dp.push_back(dp[i-1] + cnt);
		
	}

	cout << dp[N-3] << endl;

	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
class Pair:
    x = 0
    y = 0
    def __init__(self, x, y):
        self.x = x
        self.y = y

import queue

# input
h, w = map(int, input().split())
grid = [input() for _ in range(h)]

# calc
def bfs():
    que = queue.Queue()
    d = [[-1 for _ in range(w)] for _ in range(h)]
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]
    que.put(Pair(0, 0))
    d[0][0] = 0
    
    while not que.empty():
        p = que.get()
        
        for i in range(4):
            q_x = p.x + dx[i]
            q_y = p.y + dy[i]
            if q_x == w - 1 and q_y == h - 1:
                return d[p.y][p.x] + 1
            if 0 <= q_x < w and 0 <= q_y < h and grid[q_y][q_x] == "." and d[q_y][q_x] < 0:
                que.put(Pair(q_x, q_y))
                d[q_y][q_x] = d[p.y][p.x] + 1
    
    return -1

white = 0
for i in range(h):
    for j in range(w):
        if grid[i][j] == ".":
            white += 1

result = bfs()

# output
if result == -1:
    print(-1)
else:
    print(white - 1 - result)

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

int main(){

  int N;
  for(;;){
    int p[100][100]={{0}};
    cin >> N;
    if(!N)break;
    for(int i=0;i<N;++i){
      int M;
      cin >> M;
      int pnum;
      for(int j=0;j<M;++j){
	cin >> pnum;
	p[i][pnum-1]=1;
      }
    }

    int K;
    cin >> K;
    int l[100];
    for(int i=0;i<K;++i){
      cin >> l[i];
    }

    int lnum[100]={0};
    int criminal;
    for(int i=0;i<K;++i)
      for(int j=0;j<N;j++)
	if(p[j][l[i]-1]){
	  int tmp=1;
	  for(int k=0;k<K;k++){
	    lnum[k] += p[j][l[k]-1];
	    tmp *= p[j][l[k]-1];
	    p[j][l[k]-1] = 0;
	  }
	  if(tmp)
	    criminal = j+1;
	}
    int is1 = 0;
    for(int i=0;i<K;++i){
      if(lnum[i]==0){
	criminal = -1;
	break;
      }
      if(lnum[i]==1){
	is1 = 1;
	break;
      }
    }

    if(!is1) criminal = -1;

    cout << criminal << endl;
  }
}

Measured memory_bytes: 1208
/*{{{*/
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <stdlib.h>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
#include <complex>

using namespace             std;
typedef long long           ll;
typedef unsigned long long  ull;
typedef pair<ll, ll>        P;
const double                PIE = 3.141592;

#define rep_n(i, a, b)  for (int i=a; i<b; i++)
#define rep(i, n)       rep_n(i, 0, n)
#define all(v)          (v).begin(), (v).end()
#define item(v)         sizeof(v)/sizeof(v[0])
#define tov(v)          v, v+item(v)
#define mp(x, y)        make_pair(x, y)
#define mset(x, y)      memset(x, y, sizeof(x))
#define chmin(x,y)      (x=min(x, y))
#define chmax(x,y)      (x=max(x, y))
#define SORTI(v)        sort(v, v+item(v))
#define SORT(v)         sort(d.begin(), d.end());
#define UNIQUE(x)       x.erase(unique(all(x)), x.end())
#define ins(x, y, z)    x.insert(x.begin()+y, z)
#define era(x, y)       x.erase(x.begin()+y)
#define era1(x, y, z)   x.erase(x.begin()+y, x.begin()+z)
#define COUNT(x, y)     count(all(x), y)
#define FIND(x, y)      find(all(x), y) - x.begin()
#define ASSIGN(x, y)    x.assign(&a[0], &a[item(a)-1])

#define ci1(a)          cin>>a 
#define ci2(a, b)       cin>>a>>b
#define ci3(a, b, c)    cin>>a>>b>>c
#define ci4(a, b, c, d) cin>>a>>b>>c>>d
#define co1(a)          cout<<a<<endl;
#define co2(a, b)       cout<<a<<" "<<b<<endl;
#define co3(a, b, c)    cout<<a<<" "<<b<<" "<<c<<endl;
#define co4(a, b, c, d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
/*}}}*/

ll x, y, z, ans;
vector<ll> v;

int main() {
    ci3(x, y, z);
    int a[x];
    rep(i, x) ci1(a[i]); 

    if (x==1)                                    {co1((int)abs(a[0]-z));}
    else if (abs(a[x-2]-a[x-1]) > abs(a[x-1]-z)) {co1((int)abs(a[x-2]-a[x-1]));}
    else                                         {co1((int)abs(a[x-1]-z));}

}

///*debug*/co1();


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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  string s;
  cin >> s;
  int red = 0;
  int blue = 0;
  for (char c : s) {
    if (c == '0') {
      red++;
    } else if (c == '1') {
      blue++;
    }
  }
  cout << min(red, blue) * 2 << endl;
  return 0;
}


Measured memory_bytes: 3740
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
using namespace std;
int gcd(int x, int y) {
  if(x < y) {
    swap(x, y);
  }
  if(x % y == 0) {
    return y;
  }
  gcd(y, x % y);
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x, y, res;
  cin >> x >> y;
  res = gcd(x, y);
  cout << res << endl;
  return 0;
}


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

#define pb      push_back
#define all(v)  v.begin(),v.end()
#define endl    "\n"
#define FAST    ios_base::sync_with_stdio(0);cin.tie(0);

typedef long long     ll;
typedef long double   ld;
typedef pair<int,int> ii;

const int    inf = 2e9;
const ll     INF = 4e17;
const int    mod = 1e9+7;
const double eps = 1e-9;

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



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

int main() {
  // 入れ変えるカードを一度他のvectorに入れておくやり方
  int n,r;
  while(cin >> n >> r) {
    if(n == 0 && r == 0) break;
    // カードの山の生成
    vector<int> v;
    for(int i = 0; i < n; i++) v.insert(v.begin()+0,i+1);
    // for(int k = 0; k < v.size(); k++) {
    // cout << v.at(k) << " ";
    // }
    // cout << endl;

    for(int i = 0; i < r; i++) {
      int p,c;
      cin >> p >> c;

      // // 先に後ろに移動するはずのカードを追加
      // for(int j = 0; j < c; j++) v.insert(v.begin()+j,v[p+j-1]);
      //
      // // 移動したカードを削除
      // for(int j = 0; j < c; j++) v.erase(v.begin() + ((c+p-1)+j));
      vector<int> tmp;
      // 移動するカードをtmpに追加
      for(int j = 0; j < c; j++) tmp.push_back(v[p+j-1]);
      // for(int k = 0; k < tmp.size(); k++) {
      // cout << tmp.at(k) << " ";
      // }
      // cout << endl;

      // 移動するカードを削除
      for(int j = 0; j < c; j++) v.erase(v.begin() + (p-1));
      // cout << "移動カード削除：";
      // for(int k = 0; k < v.size(); k++) {
      // cout << v.at(k) << " ";
      // }
      // cout << endl;

      // vにtmpを追加
      int tmp_size = tmp.size();
      //  tmp.insert(tmp.end(),v.begin(),v.end());
      for(int j = 0; j < tmp_size; j++) {
        v.insert(v.begin()+0,tmp.back());
        tmp.pop_back();
      }
      // cout << "tmp追加：　";
      // for(int k = 0; k < v.size(); k++) cout << v.at(k) << " ";
      // cout << endl;
      // vector<int> v = tmp;
      //for(int j = 0; j < tmp.size(); j++) v.insert(v.begin()+0 )
    }
    cout << v.front() << endl; 
    //   for(int k = 0; k < v.size(); k++) {
    //   cout << v.at(k) << endl;
    // }
    // 初期化
    //  vector<int> v;
  }
  // for(int i = 0; i < v.size(); i++) {
  // cout << v.at(i) << endl;
  //}
}



Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;cin>>s;
    int MAX = 0, now = 0;
    rep(i,3){
        if(s[i]=='R')now++;
        else now = 0;
        MAX = max(now, MAX);
    }
    cout<<MAX<<endl;
    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;

/*
int main(){

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	return 0;
}

*/

//problem - M

/* int main() {

#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif

int n, k;
cin >> n >> k;
vector<int> a(n + 1, 0);
for (int i = 1; i <= n; i++)
	cin >> a[i];
vector<vector<long long>> dp(n + 1, vector<long long>(k + 1, 0));

for (int i = 0; i <= k; i++)
	dp[1][i] = (i <= a[1]) ? 1 : 0;

for (int i = 2; i <= n; i++) {
	for (int j = 0; j <= k; j++) {
		if (j == 0)
			dp[i][j] = dp[i - 1][j];
		else
			dp[i][j] = (mod + dp[i][j - 1] + dp[i - 1][j] - ((j - 1 - a[i]) >= 0 ? dp[i - 1][j - 1 - a[i]] : 0) ) % mod;
	}
}


cout << dp[n][k] << endl;
return 0;
} */

// problem - N

//long long dp[402][402];
//long long  sum[402];
/*#define inf (1ll)<<60

long long solve(vector<long long> &a, vector<vector<long long>> &dp, vector<long long> &sum, int i, int j) {

	if (i == j)
		return 0;
	if (dp[i][j] != -1)
		return dp[i][j];
	//long long _min = 400ll * 1000000007;
	long long _min = inf;
	for (int k = i; k < j; k++) {
		_min = min(_min, sum[j] - sum[i - 1] + solve(a, dp, sum, i, k) + solve(a, dp, sum, k + 1, j));
	}
	return dp[i][j] = _min;
}

int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n;
	cin >> n;
	vector<long long> a(n + 1, 0);
	vector<vector<long long>> dp(n + 1, vector<long long>(n + 1, -1));
	vector<long long> sum(n + 1, 0);
	//memset(dp, sizeof dp, -1);
	//memset(sum, sizeof sum, 0);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		sum[i] = sum[i - 1] + a[i];
	}
	cout << solve(a, dp, sum, 1, n) << endl;
	return 0;
}

*/

//Problem O

int n;

long long solve(vector<vector<int>> &compat, vector<vector<int>> &dp, int m, int mask) {
	if (m == (n + 1)) {
		if (mask == 0)
			return 1;
		return 0;
	}
	if (dp[m][mask] != -1)
		return dp[m][mask];

	long long ans = 0;

	for (int w = 0; w < n; w++) {
		if ( compat[m][w + 1] && ((1 << w)&mask) )
			ans = (ans + solve(compat, dp, m + 1, (1 << w)^mask) ) % mod;
	}
	return dp[m][mask] = ans;
}

int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	cin >> n;
	vector<vector<int>> compat(n + 1, vector<int>(n + 1, 0));
	vector<vector<int>> dp(22, vector<int>((1 << 22), -1));
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			cin >> compat[i][j];
	cout << solve(compat, dp, 1, (1 << n) - 1) << endl;
	return 0;
}




Measured memory_bytes: 380196
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int count = 0;
    for(char c :s.toCharArray()){
      if(c == '1')
        count++;
    }
    System.out.println(count);
  }
}

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

// ただの辺
struct edge {
    int to;
    long long cost;
    // 引数一つの時は距離1
    edge(int t, long long c = 1) : to(t), cost(c) {}
};

// 辺の長さを無視した距離
// depend:edge
vector<int> distance_nonweight(vector<vector<edge>> &g, int start) {
    vector<int> res(g.size(), INT_MAX);
    res[start] = 0;
    queue<int> bfs;
    bfs.push(start);
    while (!bfs.empty()) {
        int now = bfs.front();
        bfs.pop();
        for (auto e : g[now]) {
            int next = e.to;
            if (res[next] > res[now] + 1) {
                res[next] = res[now] + 1;
                bfs.push(next);
            }
        }
    }
    return res;
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<edge>> g(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    auto dist = distance_nonweight(g, 0);
    vector<int> ans(n);
    for (int i = 1; i < n; i++) {
        for (auto e : g[i]) {
            if (dist[i] == dist[e.to] + 1) {
                ans[i] = e.to;
                break;
            }
        }
    }
    cout << "Yes" << endl;
    for (int i = 1; i < n; i++) {
        cout << ans[i] + 1 << endl;
    }
}

Measured memory_bytes: 16584
#include<stdio.h>
int main()
{
    int n,r;
    scanf("%d%d",&n,&r);
    if(n>=10)
    {
        printf("%d\n",r);
    }
    else
    {
        int s=r+100*(10-n);

        printf("%d\n",s);
    }
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { cout << p.first << ' ' << p.second; return os; }

void solve() {
  int H, W; cin >> H >> W;
  vector<vi32> d(10, vi32(10));
  rep(i, 10) cin >> d[i];
  vector<vi32> a(H, vi32(W));
  rep(i, H) cin >> a[i];

  rep(k, 10) rep(i, 10) rep(j, 10) amin(d[i][j], d[i][k] + d[k][j]);

  int ans = 0;
  rep(i, H) rep(j, W) if (a[i][j] != -1) ans += d[a[i][j]][1];
  cout << ans << '\n';
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<vector>
using ll = unsigned long long;
using namespace std;


int main(void) {
    int r, d, sp;
    cin >> r >> d >> sp;
    int *x = new int[11];
    x[0] = sp;

    for(int i = 1; i < 2011; ++i) {
        x[i] = r * x[i-1] - d;
    }

    for(int u = 1; u < 11; ++u) {
        cout << x[u] << endl;
    }

    return 0;
}

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

using namespace std;

const int MAX=100;
const int MAX_cap=10000;

class edge
{
public:
	int to,cap,rev;
	edge(){}
	edge(int to,int cap,int rev):to(to),cap(cap),rev(rev){}
};

vector<edge> G[MAX];
bool used[MAX];

void add_edge(int from,int to,int cap)
{
	G[from].push_back(edge(to,cap,G[to].size()));
	G[to].push_back(edge(from,0,G[from].size()-1));
	return;
}

int dfs(int v,int t,int f)
{
	if(v==t)return f;
	used[v]=true;
	for(int i=0;i<G[v].size();i++)
	{
		edge &e=G[v][i];
		if(!used[e.to]&&e.cap>0)
		{
			int d=dfs(e.to,t,min(f,e.cap));
			if(d>0)
			{
				e.cap-=d;
				G[e.to][e.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}

int maxflow(int s,int t)
{
	int flow=0;
	while(1)
	{
		for(int i=0;i<MAX;i++)used[i]=false;
		int f=dfs(s,t,MAX_cap);
		if(f==0)return flow;
		flow+=f;
	}
}

int main()
{
	int V,E;
	cin>>V>>E;
	int u,v,c;
	for(int i=0;i<E;i++)
	{
		cin>>u>>v>>c;
		add_edge(u,v,c);
	}
	cout<<maxflow(0,V-1)<<endl;
	return 0;
}

Measured memory_bytes: 3152
S = int(input())
MOD = 10**9 + 7

dp = [0] * (S + 1)
dp[0] = 1

for i in range(S):
    for j in range(3, S + 1):
        if i + j <= S:
            dp[i + j] = (dp[i + j] + dp[i]) % MOD
print(dp[S])


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

using namespace std;
typedef long long ll;
#define MOD 1000000007

ll a, b, n;
ll f(ll x)
{
  return (a * x) / b - a * (x / b);
}

int main()
{

  cin >> a >> b >> n;
  ll l = 0, r = n;

  // ll max = -1;
  // while(l + 1 < r) {
  //   ll mid = (l + (r - l)) / 2;
  //   ll cur =
  //   if (f(mid - 1) < )

  // }

  if (b > n)
  {
    cout << f(n) << endl;
  }
  else
  {
    cout << f(b - 1) << endl;
  }

  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using pll = pair<long long,long long>;
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
const long long INF = 1LL << 60;
const long long MOD = 1000000007;

//最大最小の入れ替え
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
//コンビネーション
ll nCr(ll n, ll r) {
    ll ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
//素因数分解
map< ll, ll > prime_factor(ll n) {
  map< ll, ll > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

//以下回答
int main(){
    ll K;
    cin>>K;
    ll A,B;
    cin>>A>>B;
    rep(i,1001){
        if(K*i<=B&&K*i>=A){
            cout<<"OK"<<endl;
            return 0;
        }
    }
    cout<<"NG"<<endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 2;

signed main() {
    int n;
    string s;
    cin >> n;
    cin >> s;
    int a[n];
    bool one = false;
    rep(i, n) {
        a[i] = s[i] - '1';
        if (a[i] == 1) one = true;
    }
    if (!one) {
        rep(i, n) {
            a[i] /= 2;
        }
    }
    int dp[n] = {};
    for (int i = 1; i < n; i++){
        int t = i, cnt = 0;
        while(t % 2 == 0){
            t /= 2;
            cnt++;
        }
        dp[i] = dp[i - 1] + cnt;
    }
    int ans = 0;
    rep(i, n) {
        ans += a[i] * !(dp[n - 1] - dp[i] - dp[n - 1 - i] > 0);
        ans %= 2;
    }
    if (!one) ans *= 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9220
import math
import sys

max=0
N = int(input())
dict = {}
for _ in range(N):
    S = input()
    # print(S)
    if S in dict:
        dict[S] = dict[S] + 1
    else:
        dict[S] = 1

    if max < dict[S]:
        max = dict[S]

    # print(S,dict[S])

lists = []
for s, n in dict.items():
    if n == max:
        lists.append(s)

lists.sort()
for s in lists:
    print(s)
    

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

bool any_negatives(string& str){
    int depth = 0;
    for(const auto x : str){
        if(x == '(') ++depth;
        else --depth;
        if(depth < 0) return true; }
    return false; }

int main(){
    int n;
    string str;
    cin >> n >> str;
    while(any_negatives(str)) str.insert(begin(str), '(');
    while(count(begin(str), end(str), '(') != count(begin(str), end(str), ')'))str.push_back(')');
    cout << str << endl;
    return 0; }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
using namespace std;
const int MAXN = 405;
const LL MOD = 998244353;

int N;
LL dp[MAXN][MAXN], sum[MAXN];

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> sum[i + 1];
		sum[i + 1] += sum[i];
	}
	
	for (int l = N - 1; l >= 0; l--) {
		for (int r = l + 2; r <= N; r++) {
			dp[l][r] = 1e18;
			for (int m = l + 1; m < r; m++) {
				dp[l][r] = min(dp[l][r], dp[l][m] + dp[m][r] + sum[r] - sum[l]);
			}
		}
	}
	
	cout << dp[0][N] << "\n";
	
}


Measured memory_bytes: 1536
#include"cstdio"
int main(){
	int n,i,temp=0,t=1,m=0,os=0,js=0,four=0;
	int a[100005];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]%4==0) 	four++;
		if(a[i]%4==2)	os++;
		if(a[i]%2==1)	js++;
	}
//	if(os>1&&os<=3)
//		js=js+os-1;
//	if(os>3)
//		js=js+os-2;
//	if(os<=1)
//		js=js+os;
	if(os>0)	js=js+1;		
	if((js-1)<=four)	printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 512
if __name__ == '__main__':
    n, k = map(int, input().split())
    count = 0
    list = []
    for i in range(k):
        b = int(input())
        c = [int(i) for i in input().split()]
        list.extend(c)
    setList = set(list)
    print(n - len(setList))




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

int main(){
	int n,x=0;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		int b=2;
		int c=1;
		if(a[i]<2) c=0;
		while(b*b<=a[i]&&c){
			if(a[i]%b==0) c=0;
			else b++;
		}
		if(c==1) x++;
	}
	cout<<x<<endl;
	return 0;
}

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

int main() {
  long long x, m, ls = 0, k = 0, j = 1, s, rest, n, S = 0;
  bool c = false;
  cin >> n >> x >> m;
  vector<int> A(m+5), f(m, 1);
  A[0] = x;
  x = x*x % m;
  while(f[x]) {
    A[j] = x;
    f[x] = 0;
    x = x*x % m;
    j++;
  }
  rep(i, j) {
    if(A[i] == x) {
      c = true;
      s = i;
    }
    if(c) {
      ls += A[i];
      k++;
    }
  }
  if(n <= s) {
    rep(i, n) S += A[i];
  } else {
    rep(i, s) S += A[i];
    S += ls * ((n-s) / k);
    rest = n - s - ((n-s) / k) * k;
    rep(i, rest) S += A[s+i];
  }
  cout << S << endl;
}

Measured memory_bytes: 4016
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int a[100010], b[100010];
int main() {
#define int long long
	priority_queue<int> que;
	int sum = 0, sum1 = 0;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i];
		sum1 += b[i];
		que.push(a[i] - b[i]);
		a[i] = a[i] - b[i];
	}
	if (sum < sum1) {
		cout << "-1" << endl;
		return 0;
	}
	sort(a, a + n);
	int co = 0;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (co <= 0) {
			co += que.top();
			que.pop();
			ans++;
		}
		if (a[i] < 0) {
			co += a[i];
			ans++;
		}
	}
	if (ans == 1) {
		ans = 0;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2040
n, m, x, y = gets.chomp.split(' ').map(&:to_i)
x_ary = gets.chomp.split(' ').map(&:to_i)
y_ary = gets.chomp.split(' ').map(&:to_i)
if  x>=y || x_ary.max >= y_ary.min
  puts 'War'
  exit
end
puts [*x_ary.max..y_ary.min].all? { |num| [*x+1..y].include?(num) } ? 'No War' : 'War'

Measured memory_bytes: 2556
import sys
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=1)
a=0
b=0
j=N-1
for i in range(N-1):
  if A[i]==A[i+1]:
    a=A[i]
    j=i
    break
for i in range(j+2,N-1):
  if A[i]==A[i+1]:
    b=A[i]
    break

print(a*b)

Measured memory_bytes: 14252
import java.util.InputMismatchException;
import java.util.Scanner;
//import java.io.*;
//import java.util.Arrays;
public class Main {
	public static void main(String[] args) throws java.io.IOException {
		Scanner scan = new Scanner(System.in);
		//InputStreamReader is = new InputStreamReader(System.in);
		//BufferedReader br = new BufferedReader(is);
		try{
			while(true){
				int A = scan.nextInt();
				int B = scan.nextInt();
				System.out.println(A+B);
			}
		}catch(Exception e){
			
		}
	}
}

Measured memory_bytes: 26512
//Prime Numbers
//2019-01-16
//Ebitani Akira

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define N 10000
#define MAX 100000000

int Judge (int);

int array[N];
int n;
int count = 0;

int main(){
  int i;

  scanf("%d", &n);
  if(n < 1 || n > N){
    printf("数字の数が適当ではありません。\n");
    exit(1);
  }

  for(i = 0 ; i < n ; i++){
      scanf("%d", &array[i]);
    if(array[i] > MAX || array[i] == 1){
      printf("要素が適当ではありません。\n");
      exit(2);
    }
  }

  for(i = 0 ; i < n ; i++){
    if(Judge(array[i]) == 1)
      count++;
  }

  printf("%d\n", count);

  return 0;
}

int Judge (int x){
  int i;
  if(x == 2)
    return 1;
  if(x % 2 == 0 || x == 1)
    return 0;
  i = 3;
  while(i <= sqrt(x)){
    if(x % i == 0)
      return 0;
    i += 2;
  }
  return 1;
}



Measured memory_bytes: 2104
A = int(input())
B = int(input())
C = int(input())
X = int(input())
count = 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if 500*i + 100*j + 50*k == X:
                count += 1

print(count)


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main()
{
	int a , b, c;
	cin >> a >> b >> c;
	if (a < b&&b < c) {
		cout << a << " " << b << " " << c << endl;
	}
	else if (a <= c&&c <= b) {
		cout << a << " " << c << " " << b << endl;
	}
	else if (b <= a&&a <= c) {
		cout << b << " " << a << " " << c << endl;
	}
	else if (b <= c&&c <= a) {
		cout << b << " " << c << " " << a << endl;
	}
	else if (c <= a&&a <= b) {
		cout << c << " " << a << " " << b << endl;
	}
	else{
		cout << c << " " << b << " " << a << endl;
	}
	return 0;
}



Measured memory_bytes: 3076
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    vector<int> C(n);
    vector<int> S(n);
    vector<int> F(n);
    for (int i = 0; i + 1 < n; ++i) {
        cin >> C[i] >> S[i] >> F[i];
    }


    vector<long long> res(n, 0);
    for (int i = n - 2; i >= 0; --i) {
        long long t = S[i] + C[i];
        for (int j = i + 1; j + 1 < n; ++j) {
            t = (max(t, (long long)S[j]) + F[j] - 1) / F[j] * 1LL * F[j] + C[j];
        }
        res[i] = t;
    }

    for (int i = 0; i < n; ++i) {
        cout << res[i] << '\n';
    }

    return 0;
}

Measured memory_bytes: 3644
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
    if (v.empty())return out;
    constexpr bool is_vector_v = is_vector<T>::value;
    if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
    else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
    return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

int main() {
    IOS;
    string s,t;
    cin >> s >> t;
    vector<int> ss(s.size()+1,0),ts(t.size()+1,0);
    REP(i,s.size()){
        int temp = 0;
        if(s[i]=='A'){
            temp = 1;
        }else{
            temp = 2;
        }
        ss[i+1]=ss[i]+temp;
    }
    REP(i,t.size()){
        int temp = 0;
        if(t[i]=='A'){
            temp = 1;
        }else{
            temp = 2;
        }
        ts[i+1]=ts[i]+temp;
    }
    int q;
    cin >> q;
    REP(i,q){
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        int as = (ss[b]-ss[a-1])%3, at=(ts[d]-ts[c-1])%3;
        if(as==at){
            put("YES");
        }else{
            put("NO");
        }
    }
    return 0;
}


Measured memory_bytes: 1744