akhauriyash/Code-Regression huggingface dataset:
from heapq import heappush, heappop

if __name__ == '__main__':
    # ??????????????\???
    # ???????????????
    h = []
    while True:
        raw_input = input()
        if raw_input == 'extract':
            pri, item = heappop(h)
            print(item)
        elif raw_input == 'end':
            break
        else:
            cmd, pri = raw_input.split()
            heappush(h, (-1*int(pri), pri))

Measured memory_bytes: 166312
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, M, x;
  cin >> N >> M;
  while(M--){
    cin >> x;
    N = N - x;
    if(N < 0) break;
  }
  if(N < 0) N = -1;
  cout << N << "\n";
}


Measured memory_bytes: 3632
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {
    int N;
    int[] a;
    public void solve() {
        N = nextInt();
        a = new int[N];
        for(int i = 0;i < N;i++){
            a[i] = nextInt();
        }

        TreeMap<Integer,Integer> map = new TreeMap<>();
        for(int i = 0;i < N;i++){
            if(map.containsKey(a[i])) {
                map.put(a[i],map.get(a[i]) + 1);
            }else{
                map.put(a[i],1);
            }
        }

        TreeSet<Integer> set = new TreeSet<>();
        long ans = 0;
        for(int key : map.keySet()){
            if(map.get(key) > 1){
                if(map.get(key) > 3){
                    ans = Math.max(ans,(long)key * key);
                }
                set.add(key);
            }
        }

        if(set.size() < 2){
            out.println(ans);
        }else{
            int first = set.pollLast();
            int second = set.pollLast();
            out.println(Math.max(ans,(long)first * second));
        }
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[2048];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

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

int main() {
    int n;
    cin >> n;
    vector<vector<int>> testimony(n, vector<int>(n, -1));
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        for (int j = 0; j < a; j++) {
            int x, y;
            cin >> x >> y;
            x--;
            testimony[i][x] = y;
        }
    }
    int ans = 0;
    for (int i = 0; i < (1 << n); i++) {
        bitset<15> bit(i);
        bool flag = true;
        for (int j = 0; j < n && flag; j++) {
            if (!bit[j]) continue;
            for (int k = 0; k < n; k++) {
                if (testimony[j][k] == -1) continue;
                if (bit[k] != testimony[j][k]) {
                    flag = false;
                    break;
                }
            }
        }
        if (flag) {
            int temp = 0;
            for (int j = 0; j < 15; j++) {
                if (bit[j]) temp++;
            }
            ans = max(ans, temp);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
s_dict = {}
for i in range(n):
    s = input()
    if s in s_dict.keys():
        s_dict[s] += 1
    else:
        s_dict[s] = 1

max_count = max(s_dict.values())
answer_list = []
for k, v in s_dict.items():
    if v == max_count:
        answer_list.append(k)

for answer in sorted(answer_list):
    print(answer)

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

const int maxn = 2e5+10;

string s[maxn];
map<string, int> mp;

int main() {
    int n;
    scanf("%d", &n);
    int mx = 0;
    for(int i=1; i<=n; i++) {
        cin >> s[i];
        mp[s[i]]++;
        mx = max(mx, mp[s[i]]);
    }
    for(auto p: mp) {
        if(p.second==mx)
            cout << p.first << endl;
    }
    return 0;
}


Measured memory_bytes: 26752
N,M = map(int,(input().split()))
high = list(map(int, input().split()))
high.insert(0,0)
good_flg = [0]
for i in range(N):
  good_flg.append(1)
for i in range(M):
  A,B = map(int,(input().split()))
  if(high[A]>high[B]):
    good_flg[B]=0
  elif(high[A]<high[B]):
    good_flg[A]=0
  else:
    good_flg[A]=0
    good_flg[B]=0

print(good_flg.count(1))
  

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

int main()
{
    int N;
    int ans = 0;
    cin >> N;
    for (int i = 1; i < N; i++)
    {
        ans += (N - 1) / i;
    }
    cout << ans << '\n';
    return (0);
}


Measured memory_bytes: 3584
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		public static long P = (long)1e9 + 7;
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

			var dic = new Dictionary<int, int>();
			for (int i = 0; i < n; i++) {
				if (dic.ContainsKey(a[i])) {
					dic[a[i]]++;
				} else {
					dic[a[i]] = 1;
				}
			}

			var keys = dic.Keys.OrderBy(x => x).ToArray();

			long ans = 1;
			int target = (n + 1) % 2;
			foreach (var k in keys) {
				if (k != target) {
					Console.WriteLine(0);
					return;
				}

				if (target == 0) {
					if (dic[k] != 1) {
						Console.WriteLine(0);
						return;
					}
				} else {
					if (dic[k] != 2) {
						Console.WriteLine(0);
						return;
					}

					ans = (ans * 2) % P;
				}

				target += 2;
			}

			Console.WriteLine(ans);
		}
	}
}

Measured memory_bytes: 24160
#include <iostream>

using namespace std;

//int gcdcount(int a, int b, int count)
//{
//	if(a % b == 0)
//	{
//		return count;
//	}
//	else
//	{
//		return gcdcount(b, a % b, ++count);
//	}
//}
int gcd(int a, int b, int& count)
{
	if(a % b == 0)
	{
		cout << b << " " << ++count << endl;
		return b;
	}
	else
	{
		return gcd(b, a % b, ++count);
	}
}

void solve()
{
	int m, n;
	while(cin >> m >> n)
	{
		if(!m && !n)
		{
			break;
		}
		if(m < n)
		{
			swap(m, n);
		}
		int count = 0;
		gcd(m, n, count);
	}
}

int main()
{
	solve();
	return(0);
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define MOD 1000000007
#define el endl
#define INF 1e8
typedef long long ll;
typedef long double ld;

int main() {
    int n;
    cin >> n;
    int n_d = log(n) / log(10) + 1;
    int n_t = n / pow(10, n_d-1);
    int n_b = n % 10;
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        int degit = log(i) / log(10);
        int top = i / pow(10, degit);
        int bot = i % 10;
        if(bot == 0) continue;
        for(int j = 1; j <= n_d; j++){
            if(j == 1){
                if(top == bot) ans++;
            }else if(j != n_d){
                ans += pow(10, j-2);
            }else if(j == n_d){
                if(bot > n_t) continue;
                if(bot < n_t){
                    ans += pow(10, j-2);
                }else if(bot == n_t){
                    int tmp = bot * pow(10, j-1) + top;
                    while(tmp <= n){
                        tmp += 10;
                        ans++;
                    }
                }
            }
        }
    }
    cout << ans << endl;
}


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

int main() {
    set<int> g1 = {1, 3, 5, 7, 8, 10, 12}, g2 = {4, 6, 9, 11};
    int x, y;
    cin >> x >> y;

    if ((g1.find(x) != g1.end() and g1.find(y) != g1.end())
        or (g2.find(x) != g2.end() and g2.find(y) != g2.end())) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import std.functional,
       std.algorithm,
       std.bigint,
       std.string,
       std.traits,
       std.array,
       std.range,
       std.stdio,
       std.conv;

class UnionFind {
  long[] data;

  this (size_t size) {
    data.length = size;
    foreach (ref e; data) {
      e = -1;
    }
  }

  void unite(long x, long  y) {
    x = root(x);
    y = root(y);

    if (x != y) {
      if (size(x) < size(y)) { swap(x, y); }
      data[x] += data[y];
      data[y] = x;
    }
  }

  bool same(long x, long y) {
    return root(x) == root(y);
  }

  long root(long x) {
    return data[x] < 0 ? x : (data[x] = root(data[x]));
  }

  size_t size(long x) {
    return -data[root(x)];
  }
}

void main() {
  int[] NM = readln.chomp.split.to!(int[]);
  int N = NM[0],
      M = NM[1];
  int ans;
  int[][] es;

  foreach (_; 0..M) {
    int[] ab = readln.chomp.split.to!(int[]);
    int a = ab[0],
        b = ab[1];
    a--;
    b--;
    es ~= [a, b];
  }

  foreach (i, e; es) {
    UnionFind uf = new UnionFind(N);

    foreach (j, e2; es) {
      if (i == j) { continue; }
      uf.unite(e2[0], e2[1]);
    }

    if (uf.size(0) != N) {
      ans++;
    }
  }

  writeln(ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vec;
 
#define vecc vector<vector<ll>>
#define LM LLONG_MAX
 
#define int long long int
#define P pair<ll,ll>
 
#define ff first
#define ss second
 
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
 
#define N 100005
#define MOD (ll)1000000007

ll dp[N][3],a[N][3];

ll solve(ll n,ll t)
{
      if(n<1)           return 0;
      
      ll &ans=dp[n][t];
      
      if(ans!=0)        return ans;
      
      ans = max({solve(n-1,(t+1)%3),solve(n-1,(t+2)%3),solve(n-2,t)});
      ans+=a[n][t];
      
      return ans;
}

signed main()
{
      FAST;
      
      ll n;
      cin>>n;
      
      memset(dp,0,sizeof(dp));
      
      for(int i=1;i<=n;i++)
            for(int j=0;j<=2;j++)
                  cin>>a[i][j];
                  
      cout<<max({solve(n,0),solve(n,1),solve(n,2)})<<"\n";
      
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

// #define int ll

#define _GLIBCXX_DEBUG

#define REP(i,n) for (int i = 0; i < (n); ++i)
#define FORE(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define debug(x) cerr << #x << ": " << x << '\n'
#define hyphen() cerr << "--\n"

#define ALL(vec) (vec).begin(), (vec).end()
#define REVALL(vec) (vec).rbegin(), (vec).rend()

#define fst first
#define pb push_back

const int MOD = (int)1e9 + 7;
const int INF = numeric_limits<int>::max();

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


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

}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    double d,t,s;
    cin>>d>>t>>s;
    if(t>=d/s)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N; scanf("%d", &N);
  string s; cin >> s;

  int cnt = 0;
  string ans = s;
  for (int i = 0; i < N; ++i) {
    if (s[i] == '(') { ++cnt; }
    else if (s[i] == ')') {
      if (cnt == 0) { ans = "(" + ans; }
      else { --cnt; }
    }
  }
  ans += string(cnt, ')');
  printf("%s\n", ans.c_str());
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n,a,b;
    
    scanf("%d %d %d",&n ,&a,&b);
    
    int p=a;
    if(a>b)p=b;
    
    int q=a+b-n;
    if(q<0)q=0;
    
    printf("%d %d\n",p,q);
    
    return 0;
}

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

#define all(v) v.begin(),v.end()
#define rep(i,a,n) for(auto i=a;i<=n;i++)
#define f(i,n) for(auto i=0;i<n;i++)
#define fr first
#define sc second
#define pb emplace_back
#define pf push_front
#define mp make_pair
#define ll long long
#define endl "\n"
#define digit(n) floor(log10(n))+1
#define mod 1000000007
#define maxn 1000001
#define mem(a,val) memset(a,val,sizeof(a))
#define pow(a,b) (ll)(pow(a,b)+0.5)
#define inf 1000000000000000001
#define FASTIO std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//------------------- * Chaliye Shuru Karte Hain (code) * -------------------//

int main()
{
    FASTIO
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll x=0,f=0,j,q=1,i,n,m,k;
    //cin>>q;
    while(q--)
    {
        cin>>n;
        ll dp[n+1][3];
        mem(dp,0);
        rep(i,1,n){
            ll a,b,c;
            cin>>a>>b>>c;
            dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a;
            dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b;
            dp[i][2]=max(dp[i-1][1],dp[i-1][0])+c;
        }
        cout<<max(dp[n][0],max(dp[n][1],dp[n][2]));
        cout<<endl;    
    }        
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

int a[100], dp[100][2];
signed main(){
	int n, p;
	scanf("%lld%lld", &n, &p);
	rep(i,n)scanf("%lld", &a[i]);
	rep(i,n)a[i] = a[i]%2;
	dp[0][0] = 1;
	rep(i,n){
		dp[i+1][1] = dp[i][1];
		dp[i+1][0] = dp[i][0];
		dp[i+1][(0+a[i])%2] += dp[i][0];
		dp[i+1][(1+a[i])%2] += dp[i][1];
	}
	printf("%lld\n", dp[n][p]);
	return 0;
}







Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#define mod 1000000007
using namespace std;
typedef long long int ll;
ll w,h;
bool map1[2000][2000];
ll dp[2000][2000];
int main()
{
    scanf("%lld%lld",&h,&w);
    for(int i = 1; i <= h; i++)
    {
        getchar();
        for(int j = 1; j <= w; j++)
        {
            map1[i][j] = (getchar()=='.');
        }
    }
    //start dping
    dp[1][1] = 1;
    for(int i = 1; i<= h; i++)
    {
        for(int j = 1; j <= w; j++)
        {
            if(map1[i][j])
            {
                dp[i][j] += (dp[i-1][j]+dp[i][j-1])%(mod);
            }
        }
    }
    printf("%lld\n",dp[h][w]);
}


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

int main(){
    int N, K, Q;
    cin >> N >> K >> Q;
    vector<int> score(N, K-Q);
    int A;
    for(int i = 0; i < Q; i++){
        cin >> A;
        score[A - 1] = score[A - 1] + 1;
    }
    for(int i = 0; i < N; i++){
        if(score[i] > 0){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    string S; cin >> S;
    stack<char> st;
    string T;
    for(auto c:S){
        if(st.empty()){
            st.push(c);
        }else{
            if(st.top() != c){
                res += 2;
                st.pop();
            }else{
                st.push(c);
            }
        }
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include<string>
#include<stack>
#include<queue>
#include<stdio.h>
#include <algorithm>
#include<set>
#include<vector>

#define _CRT_SECURE_NO_WARNINGS

using namespace std;
struct Human
{
	int age;
	double weight;
	char name[256];
};

int findSumOfDigits(int n) {
	int sum = 0;
	while (n > 0) { // n が 0 になるまで
		sum += n % 10;
		n /= 10;
	}
	return sum;
}

int main()
{
	//cin>>N;
	// for (int i = 0; i < N; ++i) cin >> A[i];
	//while(true){break; ++res;}
	//cout << res << endl;
	//sort(a, a+N, greater<int>()) 大きい順ソート sort(v.begin(), v.end()); // vector
	//set<int>values; values.insert() values.size()
	//map<string,int>salary; salary["John"] = 1400;
	// string num = to_string(counter);

	int l[10000];
	int n = 6;
	int v[3];
	int a, b, c, d;
	int sum = 0;
	int count=1;
	int kari = 0;
	int w, h;
	int x, y, r;
	vector<string> lang;
	vector<int> data;
	string s; // s.size() to_string char string %s

	while (1)
	{
		cin >> l[count];
		count = count + 1;
		if (l[count-1] == 0) break;
	}

	for (int i = 1; i < count-1; i++)
	{
		cout << "Case " << i << ": " << l[i] << endl;
	}
	return 0;
}



Measured memory_bytes: 3132
#include<bits/stdc++.h>
#define N 100005
#define CM cerr<<(&MOP1-&MOP2)/1024.0/1024.0<<endl
using namespace std;
template <class T> inline T Min(T x, T y){
    return x<y?x:y;
}
template <class T> inline T Max(T x, T y){
    return x>y?x:y;
}
bool MOP1;
char str[100005];
int A[N];
bool MOP2;
int main(){
	int now=-1;
	scanf("%s",str+1);
	int s=strlen(str+1);
	for(int i=1;i<=s;i++){
		if(str[i]=='L'&&str[i-1]=='R')now=i;
		if(now!=-1&&str[i]=='L'){
			if((i-now)&1)A[now-1]++;
			else A[now]++;
		}
	}
	now=-1;
	for(int i=s;i;i--){
		if(str[i]=='R'&&str[i+1]=='L')now=i;
		if(now!=-1&&str[i]=='R'){
			if((now-i)&1)A[now+1]++;
			else A[now]++;
		}
	}
	for(int i=1;i<=s;i++)printf("%d ",A[i]);
	return 0;
}






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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ll long long

using namespace std;

int main(){
  ll n,a,b;cin>>n>>a>>b;

  if(n==1 && b!=a || a>b)cout<<0;
  else if(n==1)cout<<1;
  else cout<<(n-2)*(b-a)+1;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>


#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s

typedef long long ll;

using namespace std;

template<class T>
T fastpower(T a, long long n) {  // n must be >= 1
  if (n % 2 == 0) {  
      T halfpower = fastpower<T>(a, n/2);
      return halfpower*halfpower;
  } else {
      if (n == 1) {  return a; } else {  
          T halfpower = fastpower<T>(a, n/2);
          return (halfpower*halfpower)*a;
      }
  }
};


int main()   {
    cout.precision(17);
    ll modd = 1000 * 1000 * 1000 + 7;
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no
    ll infinit = 10000000000000000;

//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readint(n);
        vector<ll> d;
        ll total_children = 0;
        forr(i,0,n+1) {
            readint(kk); d.push_back(kk);
            total_children += kk;
        }
        vector<ll> part_sum;
        part_sum.push_back(0);
        for(auto x : d) {
            part_sum.push_back(part_sum.back() + x);
        }

        ll ret = 0; bool possible = true; ll free_from_previous = 1; ll level = 0;
        forr(i,0,d.size()) {
            ret += free_from_previous;
            ll ava_for_spread = free_from_previous - d[i];
            if (ava_for_spread < 0) {possible = false; break;}
            ll nodes_at_next_level = 2*ava_for_spread;
            if (nodes_at_next_level > total_children - part_sum[i+1]) {
                nodes_at_next_level = total_children - part_sum[i+1];
            }
            free_from_previous = nodes_at_next_level;
        }

        if (possible) {
            cout << ret << endl;
        } else {
            cout << -1 << endl;
        }


    }
    return 0;
}


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

#define MAX 100

double get_manhattan_dist(int n, int x[], int y[]);
double get_euclid_dist(int n, int x[], int y[]);
double get_p3_dist(int n, int x[], int y[]);
double get_chebyshev_dist(int n, int x[], int y[]);

int main(void)
{
    int i;

    int n;
    scanf("%d", &n);

    int x[MAX], y[MAX];
    for (i = 0; i < n; i++) {
        scanf("%d", &x[i]);
    }
    for (i = 0; i < n; i++) {
        scanf("%d", &y[i]);
    }

    double manhattan_dist = get_manhattan_dist(n, x, y);
    double euclid_dist = get_euclid_dist(n, x, y);
    double p3_dist = get_p3_dist(n, x, y);
    double chebyshev_dist = get_chebyshev_dist(n, x, y);

    printf("%f\n%f\n%f\n%f\n",
            manhattan_dist, euclid_dist, p3_dist, chebyshev_dist);

    return 0;
}

double get_manhattan_dist(int n, int x[], int y[])
{
    int i;

    double dist = 0;
    for (i = 0; i < n; i++) {
        dist += abs(x[i] - y[i]);
    }

    return dist;
}

double get_euclid_dist(int n, int x[], int y[])
{
    int i;

    double dist = 0;
    for (i = 0; i < n; i++) {
        dist += pow(x[i] - y[i], 2);
    }
    dist = sqrt(dist);

    return dist;
}

double get_p3_dist(int n, int x[], int y[])
{
    int i;

    double dist = 0;
    for (i = 0; i < n; i++) {
        dist += pow(abs(x[i] - y[i]), 3);
    }
    dist = cbrt(dist);

    return dist;
}

double get_chebyshev_dist(int n, int x[], int y[])
{
    int i;

    double max = abs(x[0] - y[0]);
    for (i = 1; i < n; i++) {
        int dist = abs(x[i] - y[i]);
        if (dist > max) {
            max = dist;
        }
    }

    return max;
}

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

using namespace std;

int main() {
    int n;
    cin>>n;
    int arr[n][3];
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++)
            cin>>arr[i][j];
    }
    vector<vector<int>> dp(n, vector<int> (3));
    dp[0][0] = arr[0][0], dp[0][1] = arr[0][1], dp[0][2] = arr[0][2];
    for(int i=1;i<n;i++){
        dp[i][0] = arr[i][0] + max(dp[i-1][1],dp[i-1][2]);
        dp[i][1] = arr[i][1] + max(dp[i-1][0],dp[i-1][2]);
        dp[i][2] = arr[i][2] + max(dp[i-1][0],dp[i-1][1]);
    }
    cout<<max(dp[n-1][0], max(dp[n-1][1],dp[n-1][2]))<<"\n";
}

Measured memory_bytes: 9804
#include <iostream>
#include <array>
using namespace std;
constexpr int FACE_NUM = 6;
enum Face { Top, Front, Right, Left, Back, Bottom };
constexpr int RIGHT_TBL[FACE_NUM][FACE_NUM] = {
    //    Top,  Front,  Right,   Left,   Back, Bottom
    {-1, Right, Back, Front, Left, -1}, // Top
    {Left, -1, Top, Bottom, -1, Right}, // Front
    {Front, Bottom, -1, -1, Top, Back}, // Right
    {Back, Top, -1, -1, Bottom, Front}, // Left
    {Right, -1, Bottom, Top, -1, Left}, // Back
    {-1, Left, Front, Back, Right, -1}, // Bottom
};
class Dice {
 private:
  array<int, FACE_NUM> faces;

 public:
  explicit Dice(array<int, FACE_NUM> faces) : faces{faces} {}

  const int &getRight(int top, int front) const {
    for (int i{0}; i < FACE_NUM; ++i) {
      if (faces[i] == top) {
        for (int j{0}; j < FACE_NUM; ++j) {
          if (faces[j] == front) {
            return faces[RIGHT_TBL[i][j]];
          }
        }
      }
    }
    exit(0);
  }
};

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

  array<int, FACE_NUM> faces;

  for (int i{0}; i < FACE_NUM; ++i) {
    cin >> faces[i];
  }
  Dice dice{faces};

  int q, top, front;
  cin >> q;
  for (int i{0}; i < q; ++i) {
    cin >> top >> front;
    cout << dice.getRight(top, front) << '\n';
  }
}



Measured memory_bytes: 3140
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define mk make_pair
#define pb push_back
#define eps 1e-12
#define MAXN 200009
using namespace std;
vector<int> g[MAXN];
int depth[MAXN];
int par[MAXN];
inline void dfs(int pos,int prev)
{
	par[pos]=prev;
	depth[pos]=depth[prev]+1;
	for(int i=0;i<g[pos].size();i++)
	{
		if(g[pos][i]!=prev)
		{
			dfs(g[pos][i],pos);
		}
	}
}
int ans=0;
inline void dfs1(int pos,int prev)
{
	ans++;
	for(int i=0;i<g[pos].size();i++)
	{
		if(g[pos][i]!=prev)
		{
			dfs1(g[pos][i],pos);
		}
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	for(int i=1;i<n;i++)
	{
		int x,y;
		cin>>x>>y;
		g[x].pb(y);
		g[y].pb(x);
	}
	dfs(1,0);
	int num=depth[n]-depth[1]-1;
	num=num/2;
	int x=n;
	while(num--)
	{
		x=par[x];
	}
	dfs1(x,par[x]);
	//cout<<x<<" "<<par[x]<<"\n";
	//cout<<ans<<"\n";
	if(n-ans>ans)
	{
		cout<<"Fennec\n";
	}
	else
	{
		cout<<"Snuke\n";
	}
}

Measured memory_bytes: 12672
S = list(input())
T = list(input())
 
test = [-1] * 26
test2 = [-1] * 26

for i in range(len(S)):
    a = ord(S[i]) - ord('a')
    b = ord(T[i]) - ord('a')

    if (test[a] != -1) or test2[b] != -1:
        if test[a] != b or test2[b] != a:
           print("No")
           exit()

    else:
        test[a] = b
        test2[b] = a


print("Yes")

 


Measured memory_bytes: 6704
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  ll n;
  cin >> n;

  ll ans = 0;
  auto f = [&](ll x) {
    if (n/x == n%x) {
      ans += x;
    }
  };
  for (ll i = 1; i*i <= n; i++) {
    if (n%i == 0) {
      if (i != 1) f(i-1);
      if (i != n/i) f(n/i-1);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mod=1e9+7;
int m,n; 
struct SY
{
	int a,b;
}sy[100005];
int cmp(SY a,SY b)
{
	return a.a<b.a;
}
int main()
{
    std::ios::sync_with_stdio(0); std::cin.tie(0);
    cin>>m;
    for(int i=1;i<=m;++i)
    {
    	cin>>sy[i].a;
    	sy[i].b=i;
	}
	sort(sy+1,sy+m+1,cmp);
	for(int i=1;i<=m;++i) cout<<sy[i].b<<" ";
	return 0;
}

Measured memory_bytes: 4400
def slove():
    import sys
    input = sys.stdin.readline
    n, m = list(map(int, input().rstrip('\n').split()))
    py = []
    ls = [1] * (n + 1)
    for i in range(m):
        p, y = list(map(int, input().rstrip('\n').split()))
        py.append([p, y, 0, i])
    py.sort()
    for i in range(m):
        py[i][2] = ls[py[i][0]]
        ls[py[i][0]] += 1
    py.sort(key=lambda x: x[3])
    for i in range(len(py)):
        a = ["0"] * 6
        a = a + list(str(py[i][0]))
        a = a[-6:]
        b = ["0"] * 6
        b = b + list(str(py[i][2]))
        b = b[-6:]
        print("".join(a + b))


if __name__ == '__main__':
    slove()


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

int main() {
  int A,B;
  cin >> A >> B;
  if (A > 12){
  	cout << B << endl;
  }
  else if(A > 5){
   	cout << B / 2 << endl;
  }
  else{
  	cout << 0 << endl;
  }
}


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

int main(){
    string s;
    cin >> s;
    string output = "";
    for (int i = 0; i < s.length(); i++)
    {
        if(output.size()>0){
            if(s[i] == '0'){
                output += "0";
            }else if(s[i] == '1'){
                output += "1";
            }else{
                output.erase(output.size()-1, 1);
            }
        }else{
            if(s[i] == '0'){
                output += "0";
            }else if(s[i] == '1'){
                output += "1";
            }            
        }
    }
    cout << output << endl;
}

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

using namespace std;
typedef long long ll;

#define rep(i , j , n) for(long long i = j ; i <= n ; i++)
const ll N = 123456;

int a[N];

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

    int n;
    cin >> n;

    int ans = 0;

    rep(i , 1 , n) {
        string s = to_string(i);

        int cnt = s.length();

        ans += (cnt % 2 != 0);
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
	int n;
	cin >> n;
	vector<ll> a(n), b(n);
	rep(i, n) cin >> a[i] >> b[i];
	ll ans = 0LL;
	repr(i, n) {
		a[i] += ans;
		if(a[i] == 0) continue;
		ll tmp;
		if(a[i] <= b[i]) tmp = b[i] - a[i];
		else {
			tmp = (a[i] + b[i]-1) / b[i];
			tmp = b[i] * tmp - a[i];
		}
		ans += tmp;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define int long long
#define inf 1e9
#define mod 1000000007

const int maxn = 200010;

vector<int> adj[maxn];
int LIS[maxn];
int val[maxn];
int ans[maxn];

void dfs(int node, int par, int len)
{
	auto lb = lower_bound(LIS, LIS + len, val[node]);
	int temp = *lb;
	if (lb == LIS + len)
		ans[node] = len + 1;
	else
		ans[node] = len;
	*lb = val[node];
	for (auto x : adj[node])
	{
		if (x != par)
		{
			dfs(x, node, ans[node]);
		}
	}
	*lb = temp;
}


void solve()
{
	int N, u, v;
	cin >> N;
	for (int i = 1; i <= N; i++)
		cin >> val[i];
	for (int i = 1; i < N; i++)
	{
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	for (int i = 0; i <= N; i++)
		LIS[i] = inf;
	dfs(1, -1, 1);
	for (int i = 1; i <= N; i++)
		cout << ans[i] << "\n";
}

int32_t main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	solve();
	return 0;
}


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

using namespace std;

using ll = int_fast64_t;
constexpr ll llmax = INT_FAST64_MAX; // std::numeric_limits<int_fast64_t>::max()
constexpr ll llmin = INT_FAST64_MIN; // std::numeric_limits<int_fast64_t>::min()
using ull = uint_fast64_t;
constexpr ull ullmax = UINT_FAST64_MAX; // std::numeric_limits<uint_fast64_t>::max()

#define FOR(i, b, e) for (int i = (b); i < (e); ++i)
#define RFOR(i, b, e) for (int i = ((e) - 1); (b) <= i; --i)
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define RREP(i, N) for (int i = ((N) - 1); 0 <= i; --i)
#define scanInt(x) int x; scanf("%d", &(x)); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &(x)); getchar();
#define scanVecInt(A, N) vector<int> A(N); REP(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); REP(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    string S;
    cin >> S;
    int mincount = INT_MAX;
    {
        int count = 0;
        char color = '0';
        for (auto&& c : S){
            if (c != color) count++;
            if (color == '0'){
                color = '1';
            }else{
                color = '0';
            }
        }
        mincount = min(mincount, count);
    }
    {
        int count = 0;
        char color = '1';
        for (auto&& c : S){
            if (c != color) count++;
            if (color == '0'){
                color = '1';
            }else{
                color = '0';
            }
        }
        mincount = min(mincount, count);
    }
    cout << mincount << endl;
}


Measured memory_bytes: 512
import java.util.*;
import java.math.*;
import java.text.*;
public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int[][] paper = new int[10][10];
		for(int i=0; i<10; i++){
			for(int j=0; j<10; j++){
				paper[i][j] = 0;
			}
		}
		while(in.hasNext()){
			String str = in.next();
			if(str.equals("0,0,0")) break;
			String st[] = str.split(",");
			int x = Integer.parseInt(st[0]);
			int y = Integer.parseInt(st[1]);
			int size = Integer.parseInt(st[2]);
			switch(size){
			case 1:
				paper = small(x,y,paper);
				break;
			case 2:
				paper = middle(x,y,paper);
				break;
			case 3:
				paper = big(x,y,paper);
				break;
				
			}
		}
		int blank = 0;
		int max = 0;
		for(int i=0; i<10; i++){
			for(int j=0; j<10; j++){
				if(paper[i][j] == 0) blank++;
				else if(max<paper[i][j]) max = paper[i][j];
			}
		}
		System.out.println(blank);
		System.out.println(max);
	}
	
	public static int[][] small(int x, int y, int[][] paper){
		paper[x][y]++;
		if(x!=0) paper[x-1][y]++;
		if(x!=9) paper[x+1][y]++;
		if(y!=0) paper[x][y-1]++;
		if(y!=9) paper[x][y+1]++;
		return paper;
	}
	
	public static int[][] middle(int x, int y, int[][] paper){
		for(int i=-1; i<=1; i++){
			if(0<=i+x && i+x<10){
				for(int j=-1; j<=1; j++){
					if(0<=j+y && j+y<10){
						paper[i+x][j+y]++;
					}
				}
			}
		}
		return paper;
	}
	
	public static int[][] big(int x, int y, int[][] paper){
		for(int i=-1; i<=1; i++){
			if(0<=i+x && i+x<10){
				for(int j=-1; j<=1; j++){
					if(0<=j+y && j+y<10){
						paper[i+x][j+y]++;
					}
				}
			}
		}
		if(x>1) paper[x-2][y]++;
		if(x<8) paper[x+2][y]++;
		if(y>1) paper[x][y-2]++;
		if(y<8) paper[x][y+2]++;
		return paper;
	}
}

Measured memory_bytes: 12000
import sys
input = sys.stdin.readline

n = int(input())

#n以下の素数列挙(O(n log(n))
def primes(n):
    ass = []
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    for i in range(len(is_prime)):
        if is_prime[i]:
            ass.append(i)
    return ass

p = primes(55555)
cnt = 0
ass = []
idx = 0
while cnt != n:
    if p[idx] % 5 == 1:
        ass.append(p[idx])
        cnt += 1
    idx += 1

res = ''
for e in ass:
    res += str(e) + ' '
print(res)

Measured memory_bytes: 3700
N = int(input())
H=[]
for i in range(N):
    H.append(input().split())
X = str(input())
for i in range(N):
    if X==str(H[i][0]):
        k=i
        break
ans=0
for i in range(k+1,N):
    ans+=int(H[i][1])
print(ans)


Measured memory_bytes: 3060
from collections import deque
import heapq
import copy

N = int(input())
an = list(map(int, input().split()))

ans = sum(an[:N]) - sum(an[2*N:])
left = [0] * (N+1)
right = [0] * (N+1)
left[0] = sum(an[:N])
right[-1] = -sum(an[2*N:])

l = an[:N]
heapq.heapify(l)
m = an[N:2*N]
r = [-i for i in an[2*N:]]
heapq.heapify(r)

for k in range(N):
    heapq.heappush(l, m[k])
    left[1+k] = left[k] + m[k] - heapq.heappop(l)

    heapq.heappush(r, -m[-1-k])
    right[-2-k] = right[-1-k] - heapq.heappop(r) - m[-1-k]

ans = float('-inf')
for i in range(N+1):
    ans = max(ans, left[i]+right[i])


print(ans)

Measured memory_bytes: 45252
// ref: antsbook page. 37~ 39
// ref: https://atcoder.jp/contests/abc007/submissions/8568869

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
using namespace std;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

int search(const vector<string>& vStr, int r_begin, int c_begin, int r_end, int c_end){
    int Rows = vStr.size();
    int Cols = vStr[0].size();
    vector<vector<int>> vvS(Rows, vector<int>(Cols, INT_MAX)); // steps
    
    queue<tuple<int,int,int>> queRCS; queRCS.push(make_tuple(r_begin, c_begin, 0)); // row, col, steps
    while(queRCS.size()!=0){
        int r, c, steps;
        tie(r, c, steps) = queRCS.front(); queRCS.pop();
        if(!( 0<=r&&r<Rows && 0<=c&&c<Cols) ){ continue; }
        
        if(vStr[r][c]=='#'){ continue; }
        if(vvS[r][c]!=INT_MAX){ continue; }
        vvS[r][c] = steps;
        if(r==r_end && c==c_end){ break; }
        
        ++steps;
        queRCS.push(make_tuple(r-1, c  , steps));
        queRCS.push(make_tuple(r  , c-1, steps));
        queRCS.push(make_tuple(r+1, c  , steps));
        queRCS.push(make_tuple(r  , c+1, steps));
    }
    return vvS[r_end][c_end];
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int H, W; cin >> H >> W;
    vector<string> vS(H);
    for(int r; r<H; ++r){
        cin >> vS[r];
    }
    
    int cnt_B=0; // black
    for(int r=0; r<H; ++r){
        for(int c=0; c<W; ++c){
            if(vS[r][c]=='#'){ ++cnt_B; }
        }
    }
    
    int steps = search(vS, 0, 0, H-1, W-1);
    if(steps==INT_MAX){ cout << -1 << endl; return 0; }
    
    cout << H*W - cnt_B - steps - 1 << endl;
    
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
l = [list(map(int,input().split())) for i in range(n)]

l.sort()

drink = 0
shop = 0
money = 0
while drink < m:
  if l[shop][1] == 0:
    shop += 1
  else:
    drink += 1
    money += l[shop][0]
    l[shop][1] -= 1
"""    
    print("shop:",shop)
    print("drink:",drink)
    print("money:",money)
"""
print(money)

Measured memory_bytes: 27760
/*

  _|_|                              _|  _|    _|
_|    _|  _|  _|_|  _|_|_|_|        _|  _|  _|
_|    _|  _|_|          _|          _|  _|_|
_|    _|  _|          _|      _|    _|  _|  _|
  _|_|    _|        _|_|_|_|    _|_|    _|    _|

*/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
//#define ls (rt<<1)
//#define rs (rt<<1|1)
#define vi vector<int>
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define rep(i,a,b) for(int i=(a),i##end=(b);i<=i##end;i++)
#define fi first
#define se second
typedef long long ll;
using namespace std;
const int maxn=2*305;
const int mod=1e9+7;
ll dp[maxn][maxn][maxn];//从后往前 这个之后弄到了多少个 一个确定了的多少个 一个都没确定多少个
int ty[maxn];
int a[maxn];
int main(){
    ios::sync_with_stdio(0);
    int n;cin>>n;int unknow=0;
    rep(i,1,n){
        int x,y;cin>>x>>y;if(x>y)swap(x,y);
        if(y==-1)unknow++;//都没定
        else if(x==-1)ty[y]=1;//缺一个
        else ty[x]=ty[y]=2;//定了
    }
    dp[2*n][0][0]=1;int ava=0;
    for(int i=2*n;i>=1;i--){
        for(int j=0;j<=ava;j++){
            for(int k=0;j+k<=ava;k++)if(dp[i][j][k]){
                if(ty[i]==2){
                    dp[i-1][j][k]+=dp[i][j][k];dp[i-1][j][k]%=mod;
                }
                else if(ty[i]==1){
                    dp[i-1][j+1][k]+=dp[i][j][k];dp[i-1][j+1][k]%=mod;
                    if(k){dp[i-1][j][k-1]+=dp[i][j][k];dp[i-1][j][k-1]%=mod;}
                }
                else{
                    dp[i-1][j][k+1]+=dp[i][j][k];dp[i-1][j][k+1]%=mod;
                    if(j){dp[i-1][j-1][k]+=1ll*j*dp[i][j][k]%mod;dp[i-1][j-1][k]%=mod;}
                    if(k){dp[i-1][j][k-1]+=dp[i][j][k];dp[i-1][j][k-1]%=mod;}
                }
            }
        }
        if(ty[i]!=2)ava++;//非2的有多少个
    }
    ll ans=dp[0][0][0];
    rep(i,1,unknow)ans=ans*i%mod;
    cout<<ans;
    return 0;
}


Measured memory_bytes: 408556
A, B, C, X, Y = map(int, input().split())
r1 = A*X+B*Y
if X < Y:
  r2 = 2*C*X+B*(Y-X)
else:
  r2 = 2*C*Y+A*(X-Y)
if X < Y:
  r3 = 2*C*Y
else:
  r3 = 2*C*X
r = min(r1, r2, r3)
print(r)


Measured memory_bytes: 3316
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;
int main(){
    int n;
    cin>>n;
    string s1,s2;
    cin>>s1>>s2;
    ll ans;
    int start=1;
    if(s1[0]==s2[0])ans=3;
    else {
        ans=6;
        start=2;
    }
    for(int i=start;i<n;++i){
        if(s1[i-1]==s2[i-1]){
            ans*=2;
            if(s1[i]!=s2[i])i++;
        }
        else{
            if(s1[i]!=s2[i]){
                ans*=3;
                i++;
            }
        }
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(){
 
  int A,B,C;
  
  cin>>A>>B>>C;
  
  int temp = A+B+C;
  
  if(temp==17){
    
    cout << "YES";
    
  }else{
    
    cout<<"NO";
  }
  
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
#include <iomanip>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fcout cout << fixed << setprecision(10)
#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define mp(a,b) make_pair(a,b)
#define pb push_back
const ll inf = 1e18;
const ll mod = 1e9 + 7;

vector<vint> tree;
vint ans;
vint query;

void dfs(int pos, int c, vint& visited){
    visited[pos] = 1;
    c += query[pos];
    ans[pos] += c;
    // printf("pos = %d, c = %d\n", pos, c);
    rep(i, tree[pos].size()){
        if(visited[ tree[pos][i] ] == 0) dfs(tree[pos][i], c, visited);
    }
}

int main(){
    int n, q;
    cin >> n >> q;
    tree.resize(n);
    ans.resize(n);
    query.resize(n);
    vint visited(n,0);
    rep(i,n-1){
        int from, to;
        cin >> from >> to;
        tree[from-1].pb(to-1);
        tree[to-1].pb(from-1);
    }
    rep(i,q){
        int p, x;
        cin >> p >> x;
        query[p-1] += x;
    }
    dfs(0, 0, visited);
    rep(i,n) cout << ans[i] << " "; cout << endl;
}


Measured memory_bytes: 25088
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<bitset>
#include<cmath>
#include<queue>
#include<map>
#include<set>

using namespace std;

int read()
{
	int ans=0,f=1;
	char c=getchar();
	while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
	return ans*f;
}

int a,b,c,d;

int main()
{
	a=read();b=read();c=read();d=read();
	while(1)
	{
		c-=b;
		if(c<=0)
		{
			printf("Yes\n");
			return 0;
		}
		a-=d;
		if(a<=0)
		{
			printf("No\n");
			return 0;
		}
		
	}
	return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int H = sc.nextInt();	//回数
		int W = sc.nextInt();	//K番目に小さいかず
		
		int sum = W+H;
		
		if (sum >=10){
			System.out.println("error");
		}
		else {
			System.out.println(sum);
		}
		
				
	}

}


Measured memory_bytes: 21844