akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
    public static void main (String[] args) {
	Scanner s = new Scanner(System.in);
	int result = 0;
	while (true) {
	    int a = s.nextInt();
	    String op = s.next();
	    int b = s.nextInt();
	    if (op.equals("?")) break;
	    switch (op) {
	        case "+":
		    result = a + b;
		    break;
		case "-":
                    result = a - b;
		    break;
	        case "*":
		    result = a * b;
		    break;
	        case "/":
		    result = a / b;
		    break;
	    }
	    System.out.println(result);
	}
    }
}


Measured memory_bytes: 26244
//Bismillahir Rahman-ir Rahim
#include <bits/stdc++.h>
using namespace std;
#define MAX 1000000
#define PI acos(-1)
#define debug(x) cout << '>' << #x << " : " << x << endl;
#define all(c) c.begin(), c.end()
#define F first
#define S second
#define pb push_back
#define mp make_pair
typedef unsigned long long ull;
typedef long long ll;
typedef vector< int > vi;


bool cmp(pair <string, int> p1, pair <string, int> p2)
{
    return p1.S < p2.S;
}

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n;
    cin >> n;
    vector < pair <string, int> > vp, vp2, vp_main;
    for(int i = 0; i < n; i++){
        string temp;
        cin >> temp;
        int num = temp[1] - '0';
        //debug(num);
        vp.push_back({temp, num});
    }
    vp2 = vp_main = vp;
    stable_sort(all(vp2), cmp);
    //vp2 is stable

    // bubble sort
    for(int i = 0; i < n; i++){
        for(int j = n-1; j >= i+1; j--){
            if(vp[j].S < vp[j-1].S){
                swap(vp[j], vp[j-1]);
            }
        }
    }
    for(int i = 0; i < n; i++){
        if(i == n - 1)cout << vp[i].F;
        else cout << vp[i].F << ' ';
    }
    cout << endl;
    if(vp == vp2){
        cout << "Stable" << endl;
    }
    else cout << "Not stable" << endl;

    //selection sort
    for(int i = 0; i< n; i++){
        int mini = i;
        for(int j = i; j < n; j++){
            if(vp_main[j].S < vp_main[mini].S){
                mini = j;
            }
        }
        swap(vp_main[i], vp_main[mini]);
    }
    for(int i =0; i < n; i++){
        if(i == n - 1)cout << vp_main[i].F;
        else cout << vp_main[i].F << ' ';
    }
    cout << endl;
    if(vp_main == vp2){
        cout << "Stable" << endl;
    }
    else cout << "Not stable" << endl;




    return 0;
}



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

struct position{
    int time, x, y;
};

int main(){
    int N;
    cin >> N;
    position back_position = {0, 0, 0};
    for(int i = 0; i < N; i++){
        position this_position;
        cin >> this_position.time >> this_position.x >> this_position.y;
        if((this_position.time - back_position.time) % 2 != ((this_position.x + this_position.y) - (back_position.x + back_position.y) + int(1e7)) % 2 || (this_position.x + this_position.y) - (back_position.x + back_position.y) > this_position.time - back_position.time){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
// g++ -std=c++17 -D LOCAL C.cpp
// Date: 47:22:01 31 05 2020
// Author: bonelord
#include <bits/stdc++.h>
using namespace std;

void solve(){
	long double A,B;
	cin>>A>>B;
	cout<<(long long)(A*B)<<endl;
}

main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.setf(ios::fixed);
#ifdef LOCAL
	freopen("in", "r", stdin);
	freopen("err", "w", stderr);
#endif
//	int t; cin>>t; while (t--)
	solve();
}


Measured memory_bytes: 3744
N = int(input())
w_list = []
for i in range(N):
    w_list.append(str(input()))

ans = 0

if len(set(w_list)) != N:
    print('No')
    exit()
for i in range(1,N):
    if w_list[i-1][-1] == w_list[i][0]:
        ans += 1
if ans == N - 1:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cmath>     // pow
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>   // setprecision
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;

// long long gcd(long long a, long long b) { return b != 0 ? gcd(b, a % b) : a;
// }

// int binary_search(int key) {
//     int ng = -1;
//     int ok = (int)a.size();
//     while(abs(ok - ng) > 1) {
//         int mid = (ok + ng) / 2;
//         if(isOK(mid, key))
//             ok = mid;
//         else
//             ng = mid;
//     }
//     return ok;
// }

// cout << fixed << setprecision(10);
// vector<vector<int>> vec(H, vector<int>(W))    // int H*W
// int MOD = 1000000007;

int main() {
    long long A, B;
    cin >> A >> B;
    int ans = -1;
    for(int i = 1; i <= 1262; i++) {
        if(floor(i * 0.08) == A && floor(i * 0.1) == B) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <stdio.h>
#include <cmath>
#include <sstream>
#include <algorithm>
#include <iomanip>

#define ll long long
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define vi vector<int>
#define vl vector<long long>
#define sz size()
#define x first
#define y second
#define pii pair<int, int>
#define pll pair<ll, ll>


using namespace std;

ll a[300300], n, l[300300], r[300300];
multiset<ll> s1, s2;
ll ans = -(ll)1e18;
ll sum1, sum2;

int main() {	
	cin >> n;
	for(int i = 1; i <= n * 3; i++) cin >> a[i];
	
	

	for(int i = 1; i <= n * 3; i++) {
		if(s1.sz < n) {
			s1.insert(a[i]);
			sum1 += a[i];
		} else {
			ll x = *s1.begin();
			if(x < a[i]) {
//				cout << "a";
				s1.erase(s1.find(x));
//				cout << "b" << endl;
				s1.insert(a[i]);
				sum1 += a[i] - x;
			}
		}
		l[i] = sum1;
	}

//	cout << "hello world";

	for(int i = 3 * n; i >= 1; i--) {
		if(s2.sz < n) {
			s2.insert(a[i]);
			sum2 += a[i]; 
		} else {
			ll x = *s2.rbegin();
			if(x > a[i]) {
				s2.erase(s2.find(x));
				s2.insert(a[i]);
				sum2 += a[i] - x;
			}
		}
		r[i] = sum2;
	}


	for(int i = n; i <= 2*n; i++) {
		
		ans = max(ans, l[i] - r[i + 1]);
	}

	cout << ans;

	return 0;
}

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

namespace AtCoder.Contest.D
{
	static class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			var cin = new Scanner();

			double a = cin.NextInt();
			double b = cin.NextInt();
			double x = cin.NextInt();
            if (a * a * b / 2 == x) Console.WriteLine(45);
			else if(a*a*b/2 < x)
            {
				double theta = Math.Atan((a * a * b - x) * 2 / (a * a * a));
				theta = theta * 90 * 2 / Math.PI;
                Console.WriteLine(theta);
            }
            else
            {
				double theta = Math.Atan((a * b * b) / (2 * x));
				theta = theta / Math.PI * 90 * 2;
                Console.WriteLine(theta);
            }

			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextInt() + add;
			}
			return Array;
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextLong() + add;
			}
			return Array;
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextDouble() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define INF 100000000

int n;
int a[10005] = { 0 };
int dp[2][5005][2] = { 0 };

int main(){
	cin >> n;
	for (int i = 1; i <= n-1; i++){
		cin >> a[i];
	}
	for (int i = 0; i < 2; i++){
		for (int j = 0; j < 5005; j++){
			dp[i][j][0] = dp[i][j][1] = INF;
		}
	}
	dp[0][0][0] = dp[0][1][0] = 0;
	for (int i = 0; i < n; i++){
		for (int j = 0; j <= min(i,n/2); j++){
			dp[(i + 1)%2][j + 1][0] = min(dp[i%2][j][0], dp[i%2][j][1] + a[i]);
			dp[(i + 1)%2][j][1] = min(dp[i%2][j][1], dp[i%2][j][0] + a[i]);
		}
		for (int j = 0; j <= n / 2; j++){
			dp[i % 2][j][0] = dp[i % 2][j][1] = INF;
		}
	}
	cout << min(dp[0][n / 2][0], dp[0][n / 2][1]) << endl;
	return 0;
}


Measured memory_bytes: 3244
//Daniel Grzegorzewski
#include <bits/stdc++.h>

#define MP make_pair
#define PB push_back
#define ST first
#define ND second

using namespace std;

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef long long LL;

void init_ios()
{
     ios_base::sync_with_stdio(0);
     cin.tie(0);
}

const int N = (int)1e5 + 10;

int n, a[N], res;
bool vis[N];

int main()
{
    init_ios();
    cin >> n;
    for (int i = 1; i <= n; ++i)
    	cin >> a[i];
    for (int i = 1; i <= n; ++i)
    	if (!vis[i] && a[a[i]] == i) {
    		++res;
    		vis[a[i]] = true;
    	}
    cout<<res<<"\n";
}

Measured memory_bytes: 768
# coding: utf-8
import math

h, w = map(int, input().split())

m = (h * w)

if h == 1:
    print(1)
    exit()
if w == 1:
    print(1)
    exit()

if m % 2 == 0:
    print(int(m / 2))
else:
    print(math.floor(m / 2) + 1)


Measured memory_bytes: 3060
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<iostream>
#include<vector>
#include<map>
using namespace std;
typedef pair<int,int> P;
#define F first
#define S second
int N,M;
P p[10003];
int main(){
  while(1){
    scanf("%d %d",&N,&M);
    if(!N && !M) break;
    for(int i=0;i<N;i++){
      int d,pa;
      scanf("%d %d",&d,&pa);
      p[i]=P(pa,d);
    }
    sort(p,p+N);
    int res=0;
    for(int i=N-1;i>-1;i--){
      if(M==0) res+=p[i].S*p[i].F;
      else if(M>p[i].S) M-=p[i].S;
      else if(M<=p[i].S){
	p[i].S-=M;
	M=0;
	res+=p[i].S*p[i].F;
      }
    }
    printf("%d\n",res);
  }
}

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

int main() {
  string S, T;
  cin >> S >> T;
  int count = 0;
  int size = S.size();
  for (int i = 0; i < size; i++) {
    if (S[i] != T[i]) {
    	count++;
    }
  }
  cout << count << endl;
}

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

bool prime[1000000];

int main(){
	int a, d, n;
	fill(prime, prime + 1000000, true);
	prime[0] = prime[1] = false;
	for(int i = 2; i * i < 1000000; i++){
		if(prime[i])
		for(int j = 2; i * j < 1000000; j++){
			prime[i*j] = false;
		}
	}
	while(cin >> a >> d >> n && (a || d || n)){
		int count = 0;
		if(prime[a]) count++;
		while(count < n){
			a += d;
			if(prime[a]) count++;
		}
		cout << a << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,ans=0;
    long long d;
    cin>>n>>d;
    d=d*d;
    while(n--)
    {
        long long x,y;
        cin>>x>>y;
        long long d1=x*x+y*y;
        if(d1<=d)
            ans++;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3556
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x) cout << #x << " = " << (x) << endl;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define P pair<int, int>

void solve()
{
}
int t[100010], a[100010];

signed main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    int M = 0;
    cin >> s;
    for (int i = 0; i < (int)s.size(); i++) {
        if (s[i] == '1')
            a[i]++;
    }
    M = (int)s.size();
    t[0] = 1;
    FOR(i, 1, 100005)
    {
        t[i] = t[i - 1] * 3;
        t[i] %= MOD;
    }
    int ans = 0;
    int p = 1;
    for (int i = 0; i < M; i++) {
        int k = 0;
        k = M - i;
        if (a[i]) {
            ans += t[k - 1] * p;
            ans %= MOD;
            p *= 2;
            p %= MOD;
        } else {
        }
    }
    if (!a[M - 1]) {
        ans += p;
    } else {
        ans += p;
    }
    ans %= MOD;
    cout << ans << endl;
    solve();
    return 0;
}


Measured memory_bytes: 2000
/*  CF_CC
        4U7H0R:_C4551DY */

#include <bits/stdc++.h>

using namespace std;

#define IC ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define f(im) for(int i=0;i<a;i++)
#define lb lower_bound
#define ll long long
#define pii pair<ll,ll>
#define vec vector<int>
#define fir first
#define sec second
const int mxi=1e7+10;
const int mod=1e9+7;

ll a,b,c;string s1,s2,s3;

int main()
{
    IC
    cin >> s1;
    for(int i=0;i<s1.length();i++){
        cout << 'x';
    }
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

vector<vector<int> > edges;

int solve(int curr, int prev, int& ans)
{
    vector<int> v(2, 0);
    for(int next : edges[curr]){
        if(next != prev)
            v.push_back(solve(next, curr, ans));
    }
    sort(v.rbegin(), v.rend());
    
    int cnt = v[0] + v[1];
    if(edges[curr].size() == 2){
        ++ cnt;
        ans = max(ans, cnt);
        return v[0] + 1;
    }
    else{
        ans = max(ans, cnt);
        return v[0];
    }
}

int main()
{
    int n;
    cin >> n;
    edges.assign(n, vector<int>());
    for(int i=0; i<n-1; ++i){
        int p, q;
        cin >> p >> q;
        -- p;
        -- q;
        edges[p].push_back(q);
        edges[q].push_back(p);
    }

    int leaf = 0;
    for(int i=0; i<n; ++i){
        if(edges[i].size() == 1)
            ++ leaf;
    }

    int ans = 0;
    solve(0, -1, ans);
    ans += leaf;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5888
#include<bits/stdc++.h>
using namespace std;
#define lint long long
#define inf 100000000000000000
#define mod 1000000007
#define MAX 200005
#define pb push_back
#define mp make_pair
#define vit vector<int>::iterator
typedef pair<lint,lint> pii;
struct DSU{ /// O(1) approximately. Worst case O(log(n)) for 1 find.
    vector<lint>parent,rank;
    DSU(lint n){
        parent.resize(n+1);
        rank.resize(n+1);
        for(int i=1;i<=n;i++){
            make_set(i);
        }
    }
    void make_set(lint v){
        parent[v]=v;
        rank[v]=0;
    }
    lint find_set(lint v){
        if(parent[v]==v) return v;
        return parent[v]=find_set(parent[v]); // path compression
    }
    bool union_set(lint u,lint v){
        u=find_set(u);
        v=find_set(v);
        if(u!=v){
            if(rank[u]<rank[v]) swap(u,v);
            parent[v]=u;
            if(rank[u]==rank[v]) rank[u]++; // union by rank
            return true;
        }
        else return false;
    }
};

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    lint n,m,u,v,w;
    cin>>n>>m;
    DSU ds(n);
    while(m--){
        cin>>w>>u>>v;
        if(!w) ds.union_set(u+1,v+1);
        else{
            if(ds.find_set(u+1)==ds.find_set(v+1)) cout<<"1\n";
            else cout<<"0\n";
        }
    }

    return 0;
}



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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

ll pows(ll b, ll n){
    return n==0? 1: b*pows(b,n-1);
}

ll S(ll n){//各桁の和
    ll N = n;
    ll SN = 0;
    while(N>0){
        SN += N%10;
        N /= 10;
    }
    return SN;
}

ll snuke(ll n){
    priority_queue< pair<double,ll>, vector<pair<double,ll>>, greater<pair<double,ll>> > val;

    ll digit = 0;

    while(pows(10,digit) <= n){
        FOR(i,1,10){//1-9
            ll v = n - n%pows(10,digit+1) + i*pows(10,digit) - 1;

            if(v >= n){
                val.push({(double)v/S(v), v});
            }

        }
        digit++;
    }
    digit--;

    FOR(i,1,101){
        ll v = i*pows(10,digit) - 1;
        if(v>=n){
            val.push({(double)v/S(v), v});
        }
    }

    auto ret = val.top();
    return ret.second;

}

int main() {
    ll K; cin >> K;

    ll n = 1;

    REP(i,K){
        cout << n << endl;
        n = snuke(n+1);

    }
    return 0;
}

Measured memory_bytes: 3568
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)


string str;

bool input(){
	cin>>str;
	return str!="0";
}

const int N = 88888;
const int T = 11;

int dp[N][T];
int solve(){
	rep(i,N)rep(j,T)dp[i][j]=0;
	
	int ans = 0;
	rep(i,str.size()){
		int a = str[i]-'0';
		if(a!=0)dp[i][a]++;
		
		if(i!=0){
			rep(j,T){
				int num = j*10 + a;
				dp[i][num%11] += dp[i-1][j];
			}
		}
		
		ans += dp[i][0];
	}
	/*
	reps(i,-1,str.size()){
		rep(j,T){
			printf("%2d ", i==-1 ? j : dp[i][j]);
		}puts("");
	}*/
	
	return ans;
}

void c_solve(){
	cout<<solve()<<endl;
}

int main(){
	while(input())c_solve();
}

Measured memory_bytes: 5136
#include <iostream>
#include <algorithm>
using namespace std;
int a[200001],ans=0,sum=0;
int main(){
	int i,j,k,n,l;
	cin>>n>>k;
	for(i=1;i<=n;i++){
		cin>>l;
		a[l]++;
	}
	sort(a,a+n+1);
	for(i=n;i>n-k;i--)sum+=a[i];
	cout<<n-sum<<endl;
	return 0;
}

Measured memory_bytes: 1152
function Main(input) {
	var inputArr = input.split("\n");
	var n = parseInt(inputArr[0]);
	var a = inputArr[1].split(" ");
    var sum = 0;
    var count = 0;
    var min = 9999999999;

	for (var i = 0; i < n ; i++) {
      var ai = Math.abs(a[i]);
      if (a[i] < 0) {
        count++;
      }
      if (ai < min) {
        min = ai;
      }
      sum = sum + ai;
    }
    if (count % 2 === 0) {
        console.log(sum) ;
    } else {
        console.log(sum - min - min) ;
    }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));



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

int main(int argc, char **argv) {
  int N;
  int *din;

  // data in
  cin >> N;
  din = new int[N];
  for (int i=0; i<N; i++) {
    cin >> din[i];
  }

  for (int i=0;i<N;i++) {
    cout << din[i];
    if (i+1<N) cout << " "; else cout << endl;
  }

  // sort
  for (int i=1;i<N;i++) {
    int v = din[i];
    int j = i-1;
    while (j>=0 && din[j]>v) {
      din[j+1]=din[j];
      j--;
    }
    din[j+1]=v;
    
    for (int i=0;i<N;i++) {
      cout << din[i];
      if (i+1<N) cout << " "; else cout << endl;
    }
  }
  delete din;
}

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

int main(void){
  int m, nmin, nmax;
  while(cin >> m >> nmin >> nmax, m | nmin | nmax){
    vector<int> P(m);
    for(int i = 0; i < m; i++) cin >> P[i];
    sort(P.begin(), P.end(), greater<int>());
    int ans = 0;
    int gap = 0;
    for(int n = nmin; n <= nmax; n++){
      if(gap <= P[n-1] - P[n]){
          gap = P[n-1] - P[n];
          ans = n;
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 3156
#include<cstdio>
#include<math.h>
#include<string.h>
#include<stdlib.h>
using namespace std;
int main()
{
    long long int N,M,i,prb[10000],p,time;
    while(scanf("%lld",&N)!=EOF)
    {
        long long int sum=0;
        for(i=0;i<N;i++)
        {
            scanf("%lld",&prb[i]);
            sum+=prb[i];
        }
        scanf("%lld",&M);
        long long int sum2= 0;
        for(i=0;i<M;i++)
        {
            scanf("%lld %lld",&p,&time);
            sum2=time+(sum-prb[p-1]);
            printf("%lld\n",sum2);
        }
    }
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

int main()
{
	int f[2][10]={{0,1,2,3,4,5,6,7,8,9},{0,2,4,6,8,1,3,5,7,9}};
	for(int n;cin>>n;){
		string s; cin>>s;
		int m; cin>>m;
		vi a(m);
		rep(i,m) cin>>a[i];
		
		reverse(all(s));
		
		int c[2]={},sum=0;
		rep(i,n){
			if(s[i]=='*')
				c[i&1]+=s[i]=='*';
			else
				sum+=f[i&1][s[i]-'0'];
		}
		
		int mask[2]={1,1};
		rep(i,2) rep(j,c[i]) mask[i]*=m;
		
		int res=0;
		rep(m0,mask[0]) rep(m1,mask[1]){
			int v0=0,v1=0,x;
			x=m0; rep(i,c[0]) v0+=f[0][a[x%m]],x/=m;
			x=m1; rep(i,c[1]) v1+=f[1][a[x%m]],x/=m;
			if((sum+v0+v1)%10==0)
				res++;
		}
		
		cout<<res<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1336
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define all(x) begin(x),end(x)
#define pii pair<int,int>
#include <bits/stdc++.h>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vi vector<int>
#define ld long double
#define ll long long
#define pb push_back
#define mid (l+r)/2
#define S second
#define F first
using namespace std;
const ll inf = 1e18;
const int mod = 1e9+7;
ll n;
set < ll > se;
set < ll > All;
void solve(ll div){
    ll num = n;
    while(div != 1 && num%div == 0){
        num /= div;
    }
    if(num%div == 1) All.insert(div);
}
int main(){
    fast,cin>>n;
    for(ll i=1;i*i<=n;i++){
        if(n%i) continue;
        se.insert(n/i);
        se.insert(i);
    }
    ll num = n-1;
    for(ll i=1;i*i<=num;i++){
        if(num%i) continue;
        All.insert(num/i);
        All.insert(i);
    }
    for(auto it=se.begin();it!=se.end();it++){
        solve(*it);
    }
    int ans = All.size();
    cout<<ans-(*All.begin()==1)<<endl;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
int main(void){
  int N,Y;
  scanf("%d",&N);
  scanf("%d",&Y);
  int x = Y/10000;
  for(int i = 0;i<=x;i++){//iは1万円札
    int y = (Y-10000*i)/5000;
    for(int j=0;j<=y;j++){
      if(N==i+j+(Y-10000*i-5000*j)/1000){
        printf("%d %d %d",i,j,(Y-10000*i-5000*j)/1000);
        exit(0);
      }
    }
  }
  printf("-1 -1 -1");
  return 0;
}



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

#define rep(i,n) for(int i=0; i<n ; ++i)
#define REP(i,a,b) for(int i=a; i<b; ++i)
#define all(v) (v).begin() , (v).end()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvc = vector<vector<char>>;
using pii = pair<int , int>;
using pll = pair<long long , long long>;

//プロトタイプ宣言
void faster(void);
template <class T>
T gcd(T , T);
template <class T>
T get_digent(T);
template <class T>
T POW(T , T);


int main(){
  faster();
  string s,t;
  cin >> s >> t;
  cout << t+s << endl;
}



























//同期解除
void faster(void){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

//ユークリッドの互除法
template <class T>
T gcd(T a, T b) {
  return (b ? gcd(b, a%b) : a);
} 

//桁数取得
template <class T>
T get_digent(auto x){
  string s;
  s = to_string(x);
  ll digent = s.size();
  return digent;
} 

//べき乗計算
template <class T>
T POW(T x, T y){
  if(y==0) return 1;
  if(y%2 == 1){
    ll temp = POW(x,y-1);
    return (temp*x);
  }
  else{
    ll temp = POW(x,y/2);
    return temp*temp;
  }
} 



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
long long inf=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};
 
int main(){
  int n;
  string s;
  cin>>n;
  cin>>s;
  int temp=0;
  int ans=0;
  REP(i,n){
    if(s[i]=='I'){
      temp++;
    }else{
      temp--;
    }
    ans = max(ans,temp);
  }
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;

typedef long long ll;

int n, i, j;
int m;
char a[3005];
char b[3005];
char ans[3005];
int dp[3001][3001];

int main(){
    scanf("%s", a+1);
    scanf("%s", b+1);
    n = strlen(a+1);
    m = strlen(b+1);
    memset(dp, 0, sizeof dp);
    for(i=1;i<=n;++i){
        for(j=1;j<=m;++j){
            dp[i][j] = max(max(dp[i-1][j], dp[i][j-1]), dp[i-1][j-1]+(a[i]==b[j]));
        }
    }
    ans[dp[n][m]] = 0;
    for(i=n, j=m;dp[i][j];){
        if(a[i] == b[j]){
            ans[dp[i][j]-1] = a[i];
            --i;
            --j;
        }
        else{
           if(dp[i][j] == dp[i-1][j])
               --i;
           else if(dp[i][j] == dp[i][j-1])
               --j;
           else
               --i,--j;
        }
    }
    printf("%s\n", ans);
    // printf("%d\n", dp[n][m]);
    return 0;
}







Measured memory_bytes: 35456
#include <iostream>
#include <vector>
#include <bitset>

using namespace std;

typedef struct book
{
	int C;
	vector<int> A;
} Book;

int main()
{
	int N, M, X, tmpA, minC = 1200001;
	cin >> N >> M >> X;
	vector<Book> a(N);
	for (int count = 0; count < N; count++)
	{
		Book tmpBook;
		cin >> tmpBook.C;
		for (int index = 0; index < M; index++)
		{
			cin >> tmpA;
			tmpBook.A.push_back(tmpA);
		}
		a.at(count) = tmpBook;
	}
	for (int count = 0; count < (1 << N); count++)
	{
		vector<int> sumA(M, 0);
		int sumC = 0;
		for (int i = 0; i < N; i++)
		{
			if (count & (1 << i))
			{
				for (int j = 0; j < M; j++)
				{
					sumA.at(j) += a.at(i).A.at(j);
				}
				sumC += a.at(i).C;
			}
		}
		bool flag = true;
		for (int i = 0; i < M; i++)
		{
			if (sumA.at(i) < X)
			{
				flag = false;
				break;
			}
		}
		if (flag && minC > sumC)
		{
			minC = sumC;
		}
	}
	if (minC == 1200001)
	{
		cout << "-1" << endl;
	}
	else
	{
		cout << minC << endl;
	}
}

Measured memory_bytes: 3660
MOD = 10**9+7

L=input()
N = len(L)
ans = 0
num = 0 # Lの先頭iケタにおける1の個数
cum_one_cnt = [0]*(N+1)
for i in range(N):
    length = N-i-1
    if L[i] == "1":
        ans += pow(3, length, MOD) * pow(2, num, MOD) % MOD
        ans %= MOD
        num += 1 # 1を発見したので1つ加算

# 最後のパターンのみ特殊(フリーなケタがない)
ans += pow(2, num, MOD)
print(ans%MOD)

Measured memory_bytes: 66512
# -*- coding:utf-8 -*-
def bubbleSort(A,N):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for j in range(N-1):
            if A[j] > A[j+1]:
                tmp = A[j]
                A[j] = A[j+1]
                A[j+1] = tmp
                flag = 1
                count += 1
    return A,count
N = int(input())
A = input()
A = A.split()
for i in range(len(A)):
    A[i] = int(A[i])
    
A,count = bubbleSort(A,N)
for i in range(len(A)-1):
    print(A[i],end = ' ')
print(A[len(A)-1])
print(count)

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)

using namespace std;

#define MAX 200010
bool used[MAX];

int main() {
  int n,m;
  cin >> n >> m;
  vector<int> e(m);
  rep(i,m) cin >> e[i];
  reverse(e.begin(),e.end());
  vector<int> answer;
  rep(i,m) {
    if( used[e[i]] ) continue;
    used[e[i]] = true;
    answer.push_back(e[i]);
  }
  rep(i,n) if( !used[i+1] ) answer.push_back(i+1);
  rep(i,n) cout << answer[i] << endl;
  return 0;
}

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

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

    int m = 0, a = 0, r = 0, c = 0, h = 0;
    for (int i = 0; i < N; i++) {
        string s;
        cin >> s;
        if (s[0] == 'M') m++;
        else if (s[0] == 'A') a++;
        else if (s[0] == 'R') r++;
        else if (s[0] == 'C') c++;
        else if (s[0] == 'H') h++;
    }

    vector<int> nums{m, a, r, c, h};
    vector<bool> v(5, false);
    fill(v.begin(), v.begin() + 3, true);

    long long res = 0;
    do {
        long long patterns = 1;
        for (int i = 0; i < 5; i++) {
            if (v[i])
                patterns *= nums[i];
        }
        res += patterns;
    } while (prev_permutation(v.begin(), v.end()));

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
public class Main {
    public static void main(String[] args) {

        // ??????????????????????????????.
        java.util.Scanner sc = new java.util.Scanner(System.in);

        // ?????????????????????????????????.
        // ??¨???????????? - 1 ?????´?????????????????¢??????.
        // ?????°???????????????????????????.
        int f = -2;
        int m = -2;
        int r = -2;
        while (true) {
            f = sc.nextInt();
            m = sc.nextInt();
            r = sc.nextInt();
            if (m == - 1 && f == - 1 && r == - 1) { break; }

            // ??????????¨??????????????¨????????????????????¬????????????´???????????? F
            if (m == - 1 || f == - 1) { System.out.print("F\n"); }
            else {
                // ??????????¨???¨??????????¨????????¨??????°??? 80 ??\???????????°????????? A
                if (m + f >= 80) { System.out.print("A\n"); }
                // ??????????¨???¨??????????¨????????¨??????°??? 65 ??\??? 80 ??????????????°????????? B
                if (m + f >= 65 && m + f < 80) { System.out.print("B\n"); }
                // ??????????¨???¨??????????¨????????¨??????°??? 50 ??\??? 65 ??????????????°????????? C
                if (m + f >= 50 && m + f < 65) { System.out.print("C\n"); }
                // ??????????¨???¨??????????¨????????¨??????°??? 30 ??\??? 50 ??????????????°????????? D
                // ?????????, ???????¨?????????°??? 50 ??\???????????°????????? C
                if (m + f >= 30 && m + f < 50) {
                    if (r >= 50) { System.out.print("C\n"); }
                    else { System.out.print("D\n"); }
                }
                // ??????????¨???¨??????????¨????????¨??????°??? 30 ??????????????°????????? F
                if (m + f < 30) { System.out.print("F\n"); }
            }
        }
    }
}

Measured memory_bytes: 26160
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  long long int a[n],b[n],s[n],a0;
  for(int i=0; i<n; i++){
    cin >> a[i];
    b[i] = a[i];
  }
  s[0] = a[0];
  a0=a[0];
  long long int ans1=0,ans2=0,tmp;
  for(int i=0; i<n; i++){
    if(i!=0){
      s[i] = s[i-1]+a[i];
    }
    tmp = s[i];
    if(i%2 == 0){
      if(tmp <= 0){
        a[i] += abs(tmp)+1;
        s[i] += abs(tmp)+1;
        ans1 += abs(tmp)+1; 
      }
    }else{
      if(tmp >= 0){
        a[i] -= abs(tmp)+1;
        s[i] -= abs(tmp)+1;
        ans1 += abs(tmp)+1;
      }
    }
  }
  s[0] = a0;
  
  for(int i=0; i<n; i++){
    if(i!=0){
      s[i] = s[i-1]+b[i];
    }
    tmp = s[i];
    if(i%2 != 0){
      if(tmp <= 0){
        b[i] += abs(tmp)+1;
        s[i] += abs(tmp)+1;
        ans2 += abs(tmp)+1; 
      }
    }else{
      if(tmp >= 0){
        b[i] -= abs(tmp)+1;
        s[i] -= abs(tmp)+1;
        ans2 += abs(tmp)+1;
      }
    }
  }
  cout << min(ans1,ans2) << endl;
}

Measured memory_bytes: 2560
import java.util.Scanner;

public class Main{
	public void solve(){
		Scanner sc=new Scanner(System.in);
		int m=0;
		int i=1;
		int n=sc.nextInt();
		
		while(n!=0){
			for(int j=1;j<=n;j++){
				int k=sc.nextInt();
				
				if(k>=2){
					i++;
				}else if(k==1){
					m++;
				}
			}
			if(i>=2){
				System.out.println(i+m);
			}else{
				System.out.println("NA");
			}
			
			m=0;
			i=1;
			n=sc.nextInt();
		}
	}
		public static void main(String[] args){
			Main obj= new Main();
			obj.solve();
		}
}

Measured memory_bytes: 158628
N = int(input())
a = list(map(int, input().split()))
ave = sum(a)/N
for i in range(len(a)):
    a[i] = abs(a[i]-ave)

mina, minid = 1e9,-1
for i in range(len(a)):
    if mina>=a[N-1-i]:
        mina, minid = a[N-1-i], N-1-i
print(minid)

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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

    ll n;
    cin >> n;

    ll ret = 0;
    FOR(i, 1, 1000010) {
        if(i > n) break;
        if(n%i == 0 && n/i-1 > i) {
            ret += n/i - 1;
            // cout << i << endl;
        }
    }
    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
#define INF 1000001LL
#define INF2 100000001000000LL
using namespace std;

typedef long long ll;

struct cord{
  int d,k;
  vector<ll> c;
  cord(void){d = k = 0;c.clear();}
  cord(vector<ll> v){d = v.size(); k = 0; c = v;}
  bool operator<(const cord a)const{return c[k]<a.c[k];}

  ll dis(cord &a){
    if(a.d != d)return INF;
    ll res = 0;
    for(int i=0;i<d;i++)res += (a.c[i]-c[i]) * (a.c[i]-c[i]);
    return res;
  }
};

struct KDTree{
  int n,d;
  vector<cord> v;

  KDTree(void){n = d = 0;v.clear();}
  KDTree(vector<cord> x){
    n = x.size();
    if(!n)return;
    d = x[0].c.size();
    if(!d)return;
    v = x;
    compose(0,n,0);
  }

  void compose(int l, int r, int depth){
    if(r-l<1)return;
    for(int i=l;i<r;i++)v[i].k = depth;
    sort(v.begin()+l,v.begin()+r);

    compose(l,(l+r)/2,(depth+1)%d);
    compose((l+r)/2+1,r,(depth+1)%d);
  }

  void search(int l,int r,vector<ll>& b, cord& p, int depth, ll& dist){
    if(r-l<1)return;

    int mid = (l+r)/2;
    dist = min(dist,p.dis(v[mid]));
    for(int i=0;i<d;i++){
      if(b[2*i]>p.c[i] && (b[2*i]-p.c[i])*(b[2*i]-p.c[i]) >= dist)return;
      else if(b[2*i+1]<p.c[i] && (b[2*i+1]-p.c[i])*(b[2*i+1]-p.c[i]) >= dist)return;
    }

    ll tmp;
    if(p.c[depth]>v[mid].c[depth]){
      tmp = b[2*depth];
      b[2*depth] = v[mid].c[depth]; 
      search(mid+1,r,b,p,(depth+1)%d,dist);
      b[2*depth] = tmp;
    }

    tmp = b[2*depth+1];
    b[2*depth+1] = v[mid].c[depth]; 
    search(l,mid,b,p,(depth+1)%d,dist);
    b[2*depth+1] = tmp;

    if(p.c[depth]<=v[mid].c[depth]){
      tmp = b[2*depth];
      b[2*depth] = v[mid].c[depth]; 
      search(mid+1,r,b,p,(depth+1)%d,dist);
      b[2*depth] = tmp;
    }
  }
};

int n,q,m;
vector<cord> v;
cord p,r;
vector<ll> tmp;   

int main(){
  vector<ll> box;
  for(int i=0;i<3;i++){
    box.push_back(-INF); 
    box.push_back(INF);
  }

  while(scanf("%d%d",&n,&q)!=EOF,n||q){
    v.resize(n); tmp.resize(3);

    for(int i=0;i<n;i++){
      for(int j=0;j<3;j++)scanf("%lld",&tmp[j]);
      v[i] = cord(tmp);
    }

    KDTree kd(v);

    for(int i=0;i<q;i++){
      scanf("%d",&m);
      double ans = 0;
      ll now, prv;

      for(int j=0;j<3;j++)scanf("%lld",&tmp[j]);
      p = cord(tmp); prv = INF2;
      kd.search(0,n,box,p,0,prv);

      for(int j=1;j<m;j++){
	for(int k=0;k<3;k++)scanf("%lld",&tmp[k]);
	r = cord(tmp); now = INF2;
	kd.search(0,n,box,r,0,now);

	ans += min(sqrt(prv) + sqrt(now), sqrt(p.dis(r)) );
	prv = now; p = r;
      }
      printf("%.9lf\n",ans);
    }
  }
}

Measured memory_bytes: 19556
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    ll n=s.length();
    for(int i=1;i<n;i++){
        if(i>1){
            if(s[i]==s[i-2]){
                cout << i-1<<" "<<i+1<<endl;
                return 0;
            }
        }
        if(s[i]==s[i-1]){
            cout << i<<" "<<i+1<<endl;
            return 0;
        }
    }
    cout << "-1 -1"<<endl; 
    return 0;
}


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

int main() {
int N,M;
cin >> N >> M;
vector<int> a(M);

for(int i=0; i<M; i++){
cin >> a.at(i);
N -= a.at(i);
}

if(N>=0)
cout << N << endl;
else
cout << -1 << endl;
}



Measured memory_bytes: 3636
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define _GLIBCXX_DEBUG
#define INF 100000010
 #define PI 3.14159265359

using namespace std;
const int64_t mod = 1000000007;
const int64_t tmpMod = 998244353;

int ctoi(char c) {
    if (c >= '0' && c <= '9') {
        return c - '0';
    }
    return 0;
}

int main() {
 
  string N;
  int a=0;
  cin>>N;
  //vector<int64_t> A(N);
  for(int i=0; i<N.size(); i++){
    a+=ctoi(N[i]);
  }
  //vector<vector<int> > A(N,vector<int>(M));
  //for(int i=0; i<N; i++){
  //   for(int j=0; j<M; j++){
  //       cin>>A[i][j];
  //   }
  // }
  //sort(A.begin(),A.end());
  //for (int i = 0; i < N; i++) { maximum = max(maximum , A[i]);}
  //for (int i = 0; i < N; i++) { minimum = min(minimum , A[i]);}
  if(a%9==0)cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main () {
  string ABCD;
  cin >> ABCD;
  for (int i = 0; i < 1 << 3; i++) {
    bitset<3> plus(i);
    vector<char> opt(3);
    int sum = (int)(ABCD.at(0) - '0');
    for (int j = 2; -1 < j; j--) {
      if (plus.test(j) & 1) {
        sum += (int)(ABCD.at(3 - j) - '0');
        opt.at(2 - j) = '+';
      }
      else {
        sum -= (int)(ABCD.at(3 - j) - '0');
        opt.at(2 - j) = '-';
      }
    }
    if (sum == 7) {
      cout << ABCD.at(0);
      for (int j = 0; j < 3; j++) {
        cout << opt.at(j);
        cout << ABCD.at(j + 1);
      }
      cout << "=7" << endl;
      break;
    }
  }
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
#define MOD 1000000007LL
#define endl "\n"
const ll UNDEF = -1;
const ll INF=1e18;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
ll cdiv(ll x,ll y) {
	return (x+y-1)/y;
}
int main() {
	ios_base::sync_with_stdio(false);
	ll n; scanf("%lld",&n);
	ll x=1,y=1;
	for (ll i=0;i<n;i++) {
		ll t,a; scanf("%lld%lld",&t,&a);
		ll g=max(cdiv(x,t),cdiv(y,a));
		x=g*t,y=g*a;
	}
	printf("%lld\n",x+y);
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int r = in.nextInt();
		int d = in.nextInt();
		int a = in.nextInt();
		in.close();
		int ans = a;
		for(int i = 0; i < 10; i++) {
			ans = ans * r - d;
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 21716
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()

int main() {
    int d;
    cin>>d;
    vector<int>c(26),t(d,1),t2(d,1),ans(d),nod(26);
    rep(j,26)cin>>c[j];
    vector<vector<int>>s(d,vector<int>(26));
    rep(i,d)rep(j,26)cin>>s[i][j];
    //rep(i,d)cin>>t[i];
    int pt,mx,tx,mxp=0;
    rep(k,360){
        pt=0;
        rep(j,26)nod[j]=0;
        rep(i,d){
            mx=-1000000;
            rep(j,26){
                tx=s[i][j]+nod[j]*c[j];
                if(tx>mx){
                    mx=tx;
                    t2[i]=t[i];
                    t[i]=j+1;
                }
            }
            if(i==k&&k!=359)t[i]=t2[i];
            rep(j,26){
                if(t[i]-1==j){
                    pt+=s[i][j];
                    nod[j]=0;
                }
                else{
                    nod[j]++;
                    pt-=c[j]*nod[j];
                }
            }
        }
        //cout<<pt;
        if(pt>mxp||k==359){
            mxp=pt;
            rep(i,d)ans[i]=t[i];
        }
    }
    //cout<<mxp<<endl;
    
    rep(i,d)cout<<ans[i]<<endl;
	return 0;
}


Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N; string S; 
  cin >> N >> S;
  
  int r = 1;char s1,s2;
  s1 = S.at(0);
  for(int i=0; i<N; i++) {
      s2 = S.at(i);
    if(s1 != s2) {
      s1 = s2;
      r++;
    }
  }
  
  cout << r << endl;

}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;

int main() {
  int n;
  while(cin >> n, n) {
    int f=0;
    vector<ll> sum(4001);
    vector<int> ff(4001);
    REP(i,n) {
      ll a,b,c;
      cin >> a>>b>>c;
      sum[a] += b*c;
      if (ff[a]==0&&sum[a]>=1000000) {
        ff[a]++;
        if (f==0)
          f=1;
        cout << a << endl;
      }
    }
    if (f==0)
      cout << "NA" << endl;
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(long long i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(long long i=int(n);i>0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+5  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
using PPI=pair<P,int>;
//ll const mod=998244353;
ll const mod=1e9+7;
const ll MAX=1000005;
using vi=vector<int>;
using vl=vector<ll>;
using vc=vector<char>;
using vd=vector<double>;
using vs=vector<string>;
using vp=vector<P>;
using vb=vector<bool>;
using vvi =vector<vector<int>>;
using vvl =vector<vector<ll>>;
using vvd=vector<vector<double>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
using vvb=vector<vector<bool>>;
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}

int main(){
    int n,h;
    cin>>n>>h;
    vl a(n),b(n);
    rep(i,n)cin>>a[i]>>b[i];
    sort(rall(a));
    sort(rall(b));
    rep(i,n-1){
        b[i+1]+=b[i];
    }
    int ans=(h)/a[0];
    if(h%a[0]!=0)ans++;
    rep(i,n){
        int t=h;
        int res=i+1;
        t-=b[i];
        if(t<0)t=0;
        res+=(t)/a[0];
        if(t>0&&t%a[0]!=0)res++;
        chmin(ans,res);
        if(t<=0)break;
    }
    cout<<ans<<endl;
    return 0;
}

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

typedef long long ll;
ll dp[200050];
ll INF=(int)1e10;
int main()
{
    int n,W;
    cin>>n>>W;
    for(int i=1;i<=(int)1e5;i++){
        dp[i]=INF;
    }

    ll maxv=0;
    for(int i=0;i<n;i++){
        ll w,v;
        scanf("%lld%lld",&w,&v);
        for(int j=maxv;j>=0;j--){
            dp[j+v]=min(dp[j+v],dp[j]+w);
            maxv= max(j+v,maxv);
        }
    }

    for(int i=maxv;i>=0;i--){
        if(dp[i]<=W){
            cout<<i;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 1024