akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(void){
	int month;
	int date;
	while(scanf("%d ",&month)){
		if(month == 0){
			break;
		}
		scanf("%d",&date);
		if((month == 1) || (month == 4) || (month == 7)){
			if(date % 7 == 1){
				printf("Thursday\n");
			}
			else if(date % 7 == 2){
				printf("Friday\n");
			}
			else if(date % 7 == 3){
				printf("Saturday\n");
			}
			else if(date % 7 == 4){
				printf("Sunday\n");
			}
			else if(date % 7 == 5){
				printf("Monday\n");
			}
			else if(date % 7 == 6){
				printf("Tuesday\n");
			}
			else{
				printf("Wednesday\n");
			}
		}
		else if((month == 2) || (month == 8)){
			if(date % 7 == 1){
				printf("Sunday\n");
			}
			else if(date % 7 == 2){
				printf("Monday\n");
			}
			else if(date % 7 == 3){
				printf("Tuesday\n");
			}
			else if(date % 7 == 4){
				printf("Wednesday\n");
			}
			else if(date % 7 == 5){
				printf("Thursday\n");
			}
			else if(date % 7 == 6){
				printf("Friday\n");
			}
			else{
				printf("Saturday\n");
			}
		}
		else if((month == 3) || (month == 11)){
			if(date % 7 == 1){
				printf("Monday\n");
			}
			else if(date % 7 == 2){
				printf("Tuesday\n");
			}
			else if(date % 7 == 3){
				printf("Wednesday\n");
			}
			else if(date % 7 == 4){
				printf("Thursday\n");
			}
			else if(date % 7 == 5){
				printf("Friday\n");
			}
			else if(date % 7 == 6){
				printf("Saturday\n");
			}
			else{
				printf("Sunday\n");
			}
		}
		else if(month == 5){
			if(date % 7 == 1){
				printf("Saturday\n");
			}
			else if(date % 7 == 2){
				printf("Sunday\n");
			}
			else if(date % 7 == 3){
				printf("Monday\n");
			}
			else if(date % 7 == 4){
				printf("Tuesday\n");
			}
			else if(date % 7 == 5){
				printf("Wednesday\n");
			}
			else if(date % 7 == 6){
				printf("Thursday\n");
			}
			else{
				printf("Friday\n");
			}
		}
		else if(month == 6){
			if(date % 7 == 1){
				printf("Tuesday\n");
			}
			else if(date % 7 == 2){
				printf("Wednesday\n");
			}
			else if(date % 7 == 3){
				printf("Thursday\n");
			}
			else if(date % 7 == 4){
				printf("Friday\n");
			}
			else if(date % 7 == 5){
				printf("Saturday\n");
			}
			else if(date % 7 == 6){
				printf("Sunday\n");
			}
			else{
				printf("Monday\n");
			}
		}
		else if(month == 10){
			if(date % 7 == 1){
				printf("Friday\n");
			}
			else if(date % 7 == 2){
				printf("Saturday\n");
			}
			else if(date % 7 == 3){
				printf("Sunday\n");
			}
			else if(date % 7 == 4){
				printf("Monday\n");
			}
			else if(date % 7 == 5){
				printf("Tuesday\n");
			}
			else if(date % 7 == 6){
				printf("Wednesday\n");
			}
			else{
				printf("Thursday\n");
			}
		}
		else{
			if(date % 7 == 1){
				printf("Wednesday\n");
			}
			else if(date % 7 == 2){
				printf("Thursday\n");
			}
			else if(date % 7 == 3){
				printf("Friday\n");
			}
			else if(date % 7 == 4){
				printf("Saturday\n");
			}
			else if(date % 7 == 5){
				printf("Sunday\n");
			}
			else if(date % 7 == 6){
				printf("Monday\n");
			}
			else{
				printf("Tuesday\n");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100;

bool p[MAX+1000];

int main() {
	int x;cin>>x;
	rep(i,MAX+1000) p[i]=true;
	p[0]=p[1]=false;
	rep(i,MAX+1000) {
		if(!p[i]) continue;
		for(int j=2*i; j<MAX+1000;j+=i) p[j]=false;
	}
	for(int i=x; i<MAX+1000;i++) {
		if(!p[i]) continue;
		cout<<i<<endl;
		break;
	}
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int a,b,h;
  cin >> a >> b >> h;
  cout << (a+b)*h/2 << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		for(int i = s.length() - t.length() ; i >= 0  ; i--) {
			boolean ok = true;
			for(int j = 0 ; j < t.length() ; j++) {
				if(s.charAt(i + j) != '?' && s.charAt(i + j) != t.charAt(j)) ok = false;
			}
			if(ok) {
				String temp = s.substring(0, i) + t + s.substring(i + t.length());
				System.out.println(temp.replaceAll("\\?", "a"));
				return;
			}
		}
		System.out.println("UNRESTORABLE");
	}
}

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

int main() {

    int N;
    cin >> N;

    vector<int> d(N);
    rep(i, N) cin >> d[i];
    sort(d.begin(), d.end());

    if (N % 2 == 0) cout << d[N/2] - d[N/2-1] << endl;
    else cout << 0 << endl;

    return 0;
}

Measured memory_bytes: 640
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n = i_input()

    print(1-n)

if __name__ == '__main__':
    main()


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

int main() {
  int N; cin >> N;
  int BA = 0, Bx = 0, xA = 0, AB = 0;
  for (int i = 0; i < N; i++) {
    string s; cin >> s;
    if (s.at(0) == 'B' && s.back() == 'A') BA++;
    else if (s.at(0) == 'B') Bx++;
    else if (s.back() == 'A') xA++;
    for (int j = 1; j < s.size(); j++) {
      if (s.at(j-1) == 'A' && s.at(j) == 'B') AB++;
    }
  }
  if (BA == 0) cout << AB + min(Bx, xA) << endl;
  else if (Bx == 0 && xA == 0) cout << AB + BA - 1 << endl;
  else cout << AB + BA + min(Bx, xA) << endl;
}

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

using namespace std;
using ll = long long;
using ld = long double;

void solve(ll A, ll B) {
  auto ans = ceil((double)(B-1) / (A-1));
  cout << ans << endl;
}

int main() {
  ll A;
  cin >> A;
  ll B;
  cin >> B;
  solve(A, B);
  return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>tr;

int a[200000];
int main(){
	int n;scanf("%d",&n);
	rep(i,n){
		scanf("%d",&a[i]);
		tr.insert(P(a[i],i));
	}
	rep(i,n){
		tr.erase(P(a[i],i));
		printf("%d\n",tr.find_by_order((n-1)/2)->first);
		tr.insert(P(a[i],i));
	}
}

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

using namespace std;
 
#define rep(i, n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define pb push_back

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

	if(s[0]==s[2]){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
#include<unordered_set>
using namespace std;
//int p = 998244353;
int p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define qin pair<int,pin>
#define V vector
#define Endl endl
#define veb vector<bool>
#define rev(s) reverse(s.begin(),s.end())
int max_kai = 150000;
vel kai(max_kai, 1);
vel inv_kai;
int rui(int a, int n) {
	if (n == 0) { return 1; }
	int x = rui(a, n / 2);
	x *= x; x %= p;
	if (n % 2 == 1) { x *= a; x %= p; }
	return x;
}
int inv(int a) { return rui(a, p - 2); }
void make_kai() {
	for (int i = 1; i < max_kai; i++) { kai[i] = kai[i - 1] * i; kai[i] %= p; }
	inv_kai = kai;
	rep(i, max_kai) { inv_kai[i] = inv(kai[i]); }
}
int nCr(int n, int r) {
	int a = kai[n] * inv_kai[r]; a %= p;
	a *= inv_kai[n - r]; a %= p;
	return a;
}
vel pa;
int root(int x) {
	if (pa[x] == -1) { return x; }
	int ans = root(pa[x]); pa[x] = ans;
	return ans;
}
void marge(int x, int y) {
	x = root(x);
	y = root(y);
	if (x != y) {pa[x] = y;}
}
#define lower(h,val) lower_bound(h.begin(),h.end(),val)-h.begin()
#define upper(h,val) upper_bound(h.begin(),h.end(),val)-h.begin()
const int sz = (1 << 21);
vel bit_in(sz+1, 0);
vel bit_out = bit_in;
void change(vel &bit, int pot, int val) {
	pot++;
	for (int x = pot; x <= sz; x += x & -x) bit[x] += val;
}
int sum(vel &bit, int pot) {
	int ret = 0;
	pot++;
	for (int x = pot; x > 0; x -= x & -x) ret += bit[x];
	return ret;
}
void add(int st, int to,set<int> &all_st) {
	if (to < 0) { to =  0; }
	change(bit_out, st, 1);
	change(bit_in, to, 1);
	auto itr_to = all_st.upper_bound(to);
	auto itr_st = all_st.upper_bound(st);
	if (itr_to != itr_st) {
		itr_st--;
		all_st.erase(itr_st);
	}
}
void del(int st, int to, set<int> &all_st) {
	if (to < 0) { to = 0; }
	change(bit_out, st, -1);
	change(bit_in, to, -1);
	if (sum(bit_in, to) == sum(bit_out, to)) {
		all_st.insert(to + 1);
	}
}
int rui_2(int n) {
	if (n == 0) { return 1; }
	return 2 * rui_2(n - 1);
}
signed main(){
	int n, p; cin >> n >> p;
	vel co(2, 0);
	rep(i, n) {
		int a; cin >> a;
		co[a % 2]++;
	}
	if (p % 2 == 0) {
		if (co[1] == 0) {cout << rui_2(co[0]) << endl;}
		else { cout << rui_2(co[0] + co[1] - 1) << endl; }
	}
	if (p % 2 == 1) {
		if (co[1] == 0) { cout << 0 << endl; }
		else { cout << rui_2(co[0] + co[1] - 1) << endl; }
	}
	return 0;
}

Measured memory_bytes: 34176
// https://atcoder.jp/contests/abc063/tasks/arc075_b
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
template <class T> void scan(T &number) {
    bool negative = false;
    register T c;
    number = 0;
    c = getchar();
    if (c == '-') {
        negative = true;
        c = getchar();
    }
    for (; (c > 47 && c < 58); c = getchar())
        number = number * 10 + c - 48;
    if (negative)
        number *= -1;
}
int n, a, b;
vector<int> v;
bool check(ll x) {
    ll c = 0;
    auto it = lower_bound(ALL(v), b * x);
    while (it != v.end()) {
        // 全体にbダメージ * x回
        ll h = *it - x * b;
        if (h > 0) {
            // a - b の追加ダメージ
            c += ceil((double)h / (a - b));
        }
        it++;
    }
    return c <= x;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    scan(n), scan(a), scan(b);
    v.resize(n);
    REP(i, n) scan(v[i]);
    sort(ALL(v));
    int ng = 0, ok = v[n - 1] * 2;
    while (ng + 1 != ok) {
        int x = (ng + ok) / 2;
        if (check(x))
            ok = x;
        else
            ng = x;
    }
    cout << ok << endl;

    return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

vector<pair<string, ll>> calc(ll n) {
  if (n == 1) {
    return { mp("a",1ll) };
  }

  vector<pair<string, ll>> strs = calc(n-1);
  vector<pair<string, ll>> ans;
  for (auto& p : strs) {
    // Here, we have number of chars in s.
    // this is c
    string& s = p.first;
    ll c = p.second;
    rep(i, c) {
      string newS = s;
      newS += (char)('a'+i);
      ans.push_back(mp(newS, c));
    }
    string newS = s;
    newS += (char)('a'+c);
    ans.push_back(pair<string, ll>(newS, c+1));
  }
  return ans;
}

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n;
  cin >> n;
  vector<pair<string, ll>> strs = calc(n);
  for (auto& p : strs) {
    cout << p.first << endl;
  }
}


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

using namespace std;

int main() {
    int A, B, C, D, E;
    cin >> A >> B >> C;
    if ((10*B+C)%4)
    {
        cout << "NO" << endl;
        /* code */
    }else
    {
        cout << "YES" << endl;
    }
    
    

    return 0;
}

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

int main() {
    char a, b, c, d;
    scanf("%c%c%c%c", &a, &b, &c, &d);
    printf(((a == b && b == c) || (b == c && c == d)) ? "Yes\n" : "No\n");
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using static kyoupuro.Input;
using static kyoupuro.MyMath;

namespace kyoupuro {

    class MainClass {

        public static void Main() {
            var S = Line();
            var a = int.Parse(S[0] + "");
            var b = int.Parse(S[1] + "");
            var c = int.Parse(S[2] + "");
            var d = int.Parse(S[3] + "");

            if (a + b + c + d == 7) Console.WriteLine(a + "+" + b + "+" + c + "+" + d + "=7");
            else if (a + b + c - d == 7) Console.WriteLine(a + "+" + b + "+" + c + "-" + d + "=7");
            else if (a + b - c + d == 7) Console.WriteLine(a + "+" + b + "-" + c + "+" + d + "=7");
            else if (a + b - c - d == 7) Console.WriteLine(a + "+" + b + "-" + c + "-" + d + "=7");
            else if (a - b + c + d == 7) Console.WriteLine(a + "-" + b + "+" + c + "+" + d + "=7");
            else if (a - b + c - d == 7) Console.WriteLine(a + "-" + b + "+" + c + "-" + d + "=7");
            else if (a - b - c + d == 7) Console.WriteLine(a + "-" + b + "-" + c + "+" + d + "=7");
            else if (a - b - c - d == 7) Console.WriteLine(a + "-" + b + "-" + c + "-" + d + "=7");
        }
    }

    class MyMath {
        static long Gcd(long a, long b) {
            return b == 0 ? a : Gcd(b, a % b);
        }
    }

    class Input {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line() {
            return Console.ReadLine();
        }

        public static int NextInt() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return int.Parse(enumerator.Current);
        }

        public static long NextLong() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return long.Parse(enumerator.Current);
        }

        public static string[] StrArr() {
            return Line().Split(' ');
        }

        public static List<int> IntList() {
            return StrArr().Select(int.Parse).ToList();
        }

        public static List<long> LongList() {
            return StrArr().Select(long.Parse).ToList();
        }

        public static void Skip(int line = 1) {
            enumerator.Reset();
            for (int i = 0; i < line; i++) Console.ReadLine();
        }

        public static void Reset() {
            enumerator.Reset();
        }
    }
}

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

using namespace std ;

int n ; 

const int MAXN = 100010 ; 

int fa[MAXN], fb[MAXN] ;

vector<int> ga[MAXN], gb[MAXN] ; 


int x[MAXN], y[MAXN] ; 

struct Edge {
		int l, r, bel, typ, t2, nxt ; 
} e[MAXN << 2] ;

bool vis[MAXN << 2] ; 

int ecnt = 1, hed[MAXN] ; 

int due[MAXN] ; 

void addedge(int l, int r, int bel, int typ, int t2) { 
		++ ecnt, e[ecnt].l = l, e[ecnt].r = r, e[ecnt].nxt = hed[l], e[ecnt].bel = bel, e[ecnt].typ = typ, e[ecnt].t2 = t2, hed[l] = ecnt; 
		due[l] ++ ; 
}

void adde(int l, int r, int bel, int typ, int t2) { 
		addedge(l, r, bel, typ, t2) ;
		addedge(r, l, bel, typ ^ 1, t2) ; 
}

void Build() {
		for (int i = 1; i <= n; i ++) { 
				adde(i, fa[i] == -1 ? n + 1 : fa[i], i, 0, 0) ; 
				adde(i, fb[i] == -1 ? n + 1 : fb[i], i, 1, 1) ; 
		}
}

void Dfs(int X) { 
		for (int i = hed[X]; i; i = hed[X]) {
				hed[X] = e[i].nxt ; 
				if (vis[i ^ 1]) continue ; 
				vis[i] = 1;  
				Dfs(e[i].r) ; 
				if (e[i].t2 == 0) { 
						x[e[i].bel] = e[i].typ ? 1 : -1 ; 
				}
				else y[e[i].bel] = e[i].typ ? 1 : -1 ; 
				if (!hed[X]) break ;
		}
}

int main() {

		scanf("%d", &n) ; 
		for (int i = 1; i <= n; i ++) { 
				scanf("%d", &fa[i]) ; 
				if (fa[i] != -1) ga[fa[i]].push_back(i) ; 
		}
		for (int i = 1; i <= n; i ++) { 
				scanf("%d", &fb[i]) ; 
				if (fb[i] != -1) gb[fb[i]].push_back(i) ; 
		}
		Build() ; 
		for (int i = 1; i <= n; i ++) { 
				if (due[i] & 1) {
						puts("IMPOSSIBLE") ; 
						return 0 ; 
				}
		}
		puts("POSSIBLE");  	
		Dfs(n + 1) ; 
		for (int i = 1; i <= n; i ++) { 
				int tmp = x[i] ; 
				for (int j = 0; j < ga[i].size(); j ++) { 
						tmp -= x[ga[i][j]] ; 
				}
				printf("%d%c", tmp, i == n ? 10 : ' '); 
		}
}







	


Measured memory_bytes: 26496
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;



int main(int argc, char *argv[]) {

	int N; cin >> N;

	long ans = 0;
	int M = 0;
	for (int i = 0; i < N; i++) {
		int a; cin >> a;
		M = max(M,a);
		ans += M - a;
	}
	cout << ans << endl;
	
	return 0;
}


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

struct P{
    int first;
    int second;
    P(int a,int b) : first(a), second(b) {}
    bool operator<( const P& o ) const {
        return second == o.second ? first > o.first : second < o.second;
    }
};

P genP(int a, int b){
    P res(a, b);
    return res;
}

int main(){
    int n, q, m_a = 0;
    cin >> n >> q;
    priority_queue< P > pq;
    vector<int> nl(n+1, 0);
    for(int i = 1; i <= n; i++){
        pq.push( genP(i, 0) );
    }
    for(int i = 0; i < q; i++){
        int a, v;
        cin >> a >> v;
        nl[a] += v;
        pq.push( genP(a, nl[a]) );
        while( nl[ pq.top().first ] != pq.top().second ){
            pq.pop();
        }
        P tp = pq.top();
        cout << tp.first << ' ' << tp.second << endl;
    }
    return 0;
}

Measured memory_bytes: 23632
#include <iostream>
#include <vector>

using namespace std;

template<typename T>
class SegTree {
public:
    explicit SegTree(int n, T def) : actualN(n), N(calcN_(n)), def(def), mVal(2*calcN_(n), def) {}
    void update(int idx, T value){
        int i = N + idx;
        update_(mVal[i], value);
        for(int t=i/2;t>=1;t/=2){
            mVal[t] = operate(mVal[2*t], mVal[2*t+1]);
        }
    }
    T get(int l, int r){
        l = max(0, l) + N;
        r = min(N, r) + N;
        T resL = def;
        T resR = def;
        while(l < r){
            if(l&1){ resL = operate(resL, mVal[l]); l++; }
            if(r&1){ resR = operate(mVal[r-1], resR); }
            l /= 2;
            r /= 2;
        }
        return operate(resL, resR);
    }
    template<class F>
    int maxRight(int l, F f){
        l = max(0, l) + N;
        T resL = def;
        while(l){
            if(l&1){
                T next = operate(resL, mVal[l]);
                if(f(next)){
                    while(l < N){
                        l *= 2;
                        next = operate(resL, mVal[l]);
                        if(!f(next)){
                            resL = next;
                            ++l;
                        }
                    }
                    return l - N;
                }
                resL = next;
                if(!(l&(l+1))) break;
                l++;
            }
            l /= 2;
        }
        return actualN;
    }
private:
    int calcN_(int n){
        int res = 1;
        while(res < n) res *= 2;
        return res;
    }
    void update_(T& data, T val) { data = val; }
    T operate(T a, T b) { return max(a, b); }
    const int N;
    const int actualN;
    const T def;
    vector<T> mVal;
};

int main(){
    int N, Q; cin >> N >> Q;
    SegTree<int> seg(N, 0);
    for(int i=0;i<N;i++){
        int a; cin >> a;
        seg.update(i, a);
    }
    for(int i=0;i<Q;i++){
        int t, x, v; cin >> t >> x >> v;
        if(t==1){
            seg.update(x-1, v);
        } else if(t==2){
            cout << seg.get(x-1, v) << endl;
        } else {
            cout << seg.maxRight(x-1, [&](int t){ return t >= v; }) + 1 << endl;
        }
    }
}

Measured memory_bytes: 5340
import sys,math,collections,itertools
input = sys.stdin.readline

N,A,B = list(map(int,input().split()))
X = sorted(list(map(int,input().split())))
cnt=0
for i in range(N-1):
    if (X[i+1]-X[i])*A >B:
        cnt+=B
    else:
        cnt +=A*(X[i+1]-X[i])
print(cnt)


Measured memory_bytes: 21308
using System;
using System.Linq;
using System.Collections.Generic;

namespace cs
{
    class Program
    {
        static void Main(string[] args)
        {
            var pg = new Program();
            pg.Execute();

        }

        private void Execute()
        {
            var input = ReadLineLong;
            int sum = 0;
            for (int i = 1; i <= input; i++)
            {
                for (int j = 1; j <= input; j++)
                {
                    for (int k = 1; k <= input; k++)
                    {
                        sum += Gcd(Gcd(i,j),k);
                    }
                }
            }
            
            OutputResult(sum);
        }

        private void OutputResult<Type>(Type result)
        {
            Console.WriteLine(result);
        }

        static long ReadLineLong => long.Parse(Console.ReadLine());
        static string ReadLineString => Console.ReadLine();
        static IEnumerable<long> ReadLinesLongList => Console.ReadLine().Split(' ').Select(i => long.Parse(i));
        static IEnumerable<string> ReadLinesStringList => Console.ReadLine().Split(' ');

        public static int Gcd(int a, int b) {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }

    }
}


Measured memory_bytes: 46036
#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 ll INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    string s;
    cin >> s;
    int n = s.size();
    if(n == 2) {
        if(s[0] == s[1]) cout << "1 2" << endl;
        else cout << "-1 -1" << endl;
        return 0;
    }
    rep(i, n-2) {
        if(s[i] == s[i+1] || s[i+1] == s[i+2] || s[i+2] == s[i]) {
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }
    cout << -1 << " " << -1 << endl;
    return 0;
}

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

signed main() {
  int a, b, c;
  std::cin >> a >> b >> c;
  int ans = a + b;
  chmax(ans, a * b);
  chmax(ans, a - b);
  print(ans);
}


Measured memory_bytes: 256
import itertools
N,M,Q=list(map(int,input().split()))
query=list()
for _ in range(Q):
    query.append(list(map(int,input().split())))

ans = 0
for an in itertools.combinations_with_replacement(range(1,M+1),N):
    score = 0
    for a,b,c,d in query:
        if an[b-1] - an[a-1] == c:
            score += d
    ans = max(ans,score)
print(ans)

Measured memory_bytes: 67632
#ifndef _WIN32
#include<iostream>
#endif
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<string.h>
#include<map>
#include<utility>
using namespace std;

#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
typedef vector<string> VS;
VS wrap(VS v,char c) {
	int R = v.size(), C = v[0].size();
	VS ret(R + 2, string(C + 2, c));
	REP(i, R)REP(j, C)ret[i + 1][j + 1] = v[i][j];
	return ret;
}
const int dr[] = { 0,0,1,-1 };
const int dc[] = { 1,-1,0,0 };
typedef long long LL;
typedef vector<LL> V;
typedef vector<V> VV;
const LL INF = 1e14;
int main() {
	int N, M, S, A, B;
	while (cin>>N >> M >> S >> A >> B, N + M + S + A + B) {
		VV d(N , V(N,INF));
		REP(i, N)d[i][i] = 0;
		REP(i, M) {
			int a, b,c;
			cin >> a >> b>>c;
			d[a - 1][b - 1] =c;
		}
		REP(k, N)REP(i, N)REP(j, N)d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
		LL res = INF;
		REP(i, N)res = min(res, d[S-1][i] + d[i][A-1] + d[i][B-1]);
		cout << res << endl;
	}
}

Measured memory_bytes: 3140
#include<cstdio>
#include<iostream>
#include<map>
#include<set>
#include<vector>
#include<cstring>
#include<cassert>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<limits>
#include<ctime>
#include<stack>
#include<bits/stdc++.h>
#include<string>
#include<stdlib.h>
#include<stdio.h>

typedef long long ll;
using namespace std;
const ll x=1000000007;
int mod(ll a){
	return a%x;
}
int main(){
	ll n;
	cin>>n;
	ll a[n],ans=0,mins=n+1;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]<mins){
			ans+=mins-a[i]-1;
			mins=a[i];
		}
		if(a[i]==1){
			break;
		}
	}
	cout<<n-ans;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> x(N), y(N), h(N);
  for (int i = 0; i < N; i++) {
    cin >> x.at(i) >> y.at(i) >> h.at(i);
  }

  int tmp, i, j, k;
  bool flag = false, flag2;
  for (i = 0; i <= 100; i++) {
    for (j = 0; j <= 100; j++) {
      tmp = 0;
      flag2 = true;
      for (k = 0; k < N; k++) {
	if (h.at(k)) {
	  if (flag2) {
	    tmp = abs(x.at(k) - i) + abs(y.at(k) - j) + h.at(k);
	    flag2 = false;
	  }
	  else {
	    if (tmp != abs(x.at(k) - i) + abs(y.at(k) - j) + h.at(k)) {
	      break;
	    }
	  }
	}
	if (k == N-1) flag = true;
      }
      if (flag) {
	flag = false;
	for (k = 0; k < N; k++) {
	  if (h.at(k) == 0) {
	    if (tmp - abs(x.at(k) - i) - abs(y.at(k) - j) > 0) break;
	  }
	  if (k == N-1) flag = true;
	}
      }
      if (flag) break;
    } 
    if (flag) break;
  }

  printf("%d %d %d\n", i, j, tmp);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main() {
int N; 
cin >> N; 
int a[314159]; 
for (int i = 0; i < N; ++i){
cin >> a[i]; 
}
int b[314159]; 
for (int i = 0; i < N; ++i){
b[i] = a[i]; 
}
sort(b, b + N);
int P = b[N/2 - 1]; 
int Q = b[N/2]; 
for (int i = 0; i < N; ++i){
if(a[i] <= P) cout << Q << endl;
else cout << P << endl;
}
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;
map<string, int> mpp;
signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    rep(i, n) {
        string s; cin >> s;
        mpp[s]++;
    }
    int bes = 0;
    for(auto& v:mpp) bes = max(bes, v.se);
    for(auto& v:mpp) {
        if(v.se == bes) 
  cout << v.fi << endl;
    }
}

Measured memory_bytes: 23808
#include <bits/stdc++.h>                                           
 
//#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
using namespace std;
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;
typedef unsigned long long ull;         
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;  
typedef long long ll;  
typedef double db;                             
 
 
const int inf = 1e9, maxn = 4e5 + 148, mod = 1e9 + 7, N = 1e6 + 11;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;


string s;


main () {
	cin >> s;
	cout << (s == "ABC" ? "ARC" : "ABC") << endl;
}





Measured memory_bytes: 3636
#include<set>   
#include<map>   
#include<stack>   
#include<cmath>   
#include<cstdio>   
#include<queue>   
#include<vector>   
#include<climits>   
#include<cstring> 
#include<iostream> 
#include<algorithm> 
#define LL long long 
using namespace std;      
int read(){      
    int f=1,x=0;char c=getchar();         
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}        
    while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();      
    return x*f;     
}
#define MAXN 1000
#define INF 0x3f3f3f3f
int main(){
	int a=read(),b=read();
	if(b%a==0) printf("%d\n",a+b);
	else printf("%d\n",b-a);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

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


int main(){
	int a,b,c;
	while(cin>>a>>b>>c,a||b||c){
		// cin>>a>>b>>c;?
		int n;
		cin>>n;
		vint v(a+b+c,2);
		vector<vint> vv;
		initvv(vv,n,4);
		rep(i,n){
			rep(j,4){
				cin>>vv[i][j];
			}
			rep(j,3){
				vv[i][j]--;
			}
		}
		rep(i,n){
			if(vv[i][3]==1){
				rep(j,3){
					v[vv[i][j]]=1;
				}
			}
		}
		rep(i,n){
			if(vv[i][3]==0){
				int cnt=0;
				rep(j,3){
					if(v[vv[i][j]]==1){
						cnt++;
					}
				}
				if(cnt==2){
					rep(j,3){
						if(v[vv[i][j]]==2){
							v[vv[i][j]]=0;
						}
					}
				}
			}
		}
		rep(i,v.size()){
			cout<<v[i]<<endl;
		}
	}
}

Measured memory_bytes: 1268
const [l1, l2] = require("fs").readFileSync("/dev/stdin", "utf8").split("\n");
const n = Number(l1);
let max,
  min,
  sum = 0;
const ns = l2.split(" ");
for (let i = 0; i < n; i++) {
  const v = Number(ns[i]);
  if (max == null) {
    max = v;
    min = v;
  } else {
    max = Math.max(max, v);
    min = Math.min(min, v);
  }
  sum += v;
}

console.log(`${min} ${max} ${sum}`);



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

int main()
{   char s1[20];
   scanf("%s",s1);
   printf("2018");
   for(int i=4;i<strlen(s1);i++)
    printf("%c",s1[i]);
   printf("\n");


    return 0;
}


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

string oom, mes;


void rJ() {
  const string tmp = mes;
  mes = tmp[tmp.length()-1] + tmp.substr(0, tmp.length()-1);
}
void rC() {
  const string tmp = mes;
  mes = tmp.substr(1) + tmp[0];
}
void rE() {
  string l = mes.substr(0, mes.length()/2);
  string r = mes.substr((mes.length()+1)/2);
  if(mes.length() % 2 != 0) {
    mes = r + mes[mes.length()/2] + l;
  } else {
    mes = r + l;
  }
}
void rA() {
  reverse(mes.begin(), mes.end());
}

void rP() {
  for(int i = 0; i < mes.length(); ++i) {
    if(isdigit(mes[i])) {
      mes[i] = (mes[i]-'0'+9)%10+'0';
    }
  }
}
void rM() {
  for(int i = 0; i < mes.length(); ++i) {
    if(isdigit(mes[i])) {
      mes[i] = (mes[i]-'0'+1)%10+'0';
    }
  }
}

void solve() {
  reverse(oom.begin(), oom.end());
  for(int i = 0; i < oom.length(); ++i) {
    switch(oom[i]) {
    case 'J': rJ(); break;
    case 'C': rC(); break;
    case 'E': rE(); break;
    case 'A': rA(); break;
    case 'P': rP(); break;
    case 'M': rM(); break;
    }
  }
  cout << mes << endl;
}

main() {
  int n;
  cin >> n;
  for(int i = 0; i < n; ++i) {
    cin >> oom;
    cin >> mes;
    solve();
  }
}

Measured memory_bytes: 0
import java.io.File;
import java.io.FileInputStream;
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;

public class Main {
	static int N;
	static char[][] A;
	static int M;
	static char[][] B;
	
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		Scanner sc = new Scanner(System.in);
		
		N = sc.nextInt();
		M = sc.nextInt();
		A = new char[N][N];
		for(int i = 0; i < N; i++) A[i] = sc.next().toCharArray();
		B = new char[M][M];
		for(int i = 0; i < M; i++) B[i] = sc.next().toCharArray();
		
		for(int ii = 0; ii <= N - M; ii++){
			for(int jj = 0; jj <= N - M; jj++){
				if(match(ii, jj)){
					System.out.println("Yes");
					//System.out.println(ii + " " + jj);
					return;
				}
			}
		}
		System.out.println("No");
	}
	
	public static boolean match(int ii, int jj){
		for(int i = 0; i < M; i++){
			for(int j = 0; j < M; j++){
				if(A[i + ii][j + jj] != B[i][j])
					return false;
			}
		}
		return true;
	}
}

Measured memory_bytes: 23636
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
signed main(){
    int a,b,c;
    cin>>a>>b>>c;
    cout<<(a==b&&b!=c||b==c&&c!=a||c==a&&a!=b?"Yes":"No")<<endl;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N, D; cin >> N >> D;
    ll X[N][D];
    rep(i, N){rep(j, D){
        cin >> X[i][j];
    }}
    ll ans = 0;
    rep(i, N){rep(j, N){
        if (i >= j){
            continue;
        } else {
            ll tmp = 0;
            rep(k, D){tmp += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);}
            if (abs(round(sqrt(tmp)) - sqrt(tmp)) < 1e-6){ans++;}
        }
    }}
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


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

class LCA{
public:
    int n,root,log2_n;
    vector<vector<int>> parent; // parent[i][v]:=vから2^i回親を辿ったノード
    vector<int> depth;

    LCA(){}
    /* g:graph, r:root */
    LCA(const vector<vector<int>>& g,int r){
        init(g,r);
    }
    void init(const vector<vector<int>>& g,int r){
        n = g.size();
        log2_n = log2(n)+1;
        root = r;
        parent = vector<vector<int>>(log2_n,vector<int>(n));
        depth = vector<int>(n);
        dfs(g,root,-1,0);   // parent[0],depthの初期化
        // parentの計算
        for(int k=0;k+1<log2_n;k++){
            for(int v=0;v<n;v++){
                if(parent[k][v]<0) parent[k+1][v] = -1;
                else parent[k+1][v] = parent[k][parent[k][v]];
            }
        }
    }
    void dfs(const vector<vector<int>>& G,int v,int p,int d){
        parent[0][v] = p;
        depth[v] = d;
        for(const auto& u : G[v]){
            if(u != p) dfs(G,u,v,d+1);
        }
    }

    int get(int u,int v){
        if(depth[u]>depth[v])swap(u,v);
        for(int k=0;k<log2_n;k++){
            if((depth[v]-depth[u]) >> k & 1){
                v = parent[k][v];
            }
        }
        if(u==v) return u;
        for(int k=log2_n-1;k>=0;k--){
            if(parent[k][u] != parent[k][v]){
                u = parent[k][u];
                v = parent[k][v];
            }
        }
        return parent[0][u];
    }
};

int main(){
    int n; cin >> n;
    vector<vector<int>> G(n);
    for(int i=0;i<n;i++){
        int k; cin >> k;
        for(int j=0;j<k;j++){
            int u; cin >> u;
            G[i].push_back(u);
        }
    }
    LCA lca(G,0);
    int q; cin >> q;
    for(int i=0;i<q;i++){
        int u,v; cin >> u >> v;
        int ans = lca.get(u,v);
        cout << ans << endl;
    }
}



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

using namespace std;

typedef long long ll;

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

	string s;
	cin >> s;

	int n = s.size();
	if(n <= 2){
		cout << 0 << endl;
		return 0;
	}

	ll ans = 0;
	ll acnt = 0;
	for(int i = 0; i < n - 1; ){
		if(s[i] == 'B' && s[i+1] == 'C'){
			ans += acnt;
			i += 2;
		}else if(s[i] == 'A') {
			acnt++;
			i++;
		}else{
			acnt = 0;
			i++;
		}
	}

	cout << ans << endl;

}


Measured memory_bytes: 720
#include <stdio.h>
#include <string.h>
int main()
{
	int n,l,i,j;
	scanf("%d%d",&n,&l);
	char s[n][l+1],t[l+1];
	for(i=0;i<n;i++){
		scanf("%s",s[i]);
	}
	for(i=0;i<n-1;i++){
		for(j=i+1;j<n;j++){
			if(strcmp(s[i],s[j])>0){
				strcpy(t,s[j]);
				strcpy(s[j],s[i]);
				strcpy(s[i],t);	
			}
		}
	}
	for(i=0;i<n;i++){
		printf("%s",s[i]);
	}
	printf("\n");
}

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

int main(){
  int N, Alice, Bob;
  cin >> N; //数字の個数を変数Nに格納
  vector<int> vec(N); //要素数Nの配列変数vecを宣言
  for (int i=0 ; i < N; i++){
    cin >> vec.at(i);//配列の要素に入力値を格納
  }  
    sort(vec.begin(), vec.end());//配列の要素を昇順にソート
    reverse(vec.begin(), vec.end()); //上のソート結果を逆順に（降順）ソート
    
    
  for (int i=0; i < vec.size(); i++){ //配列要素数の回数だけ処理を繰り返す
    if (i%2 == 0){                    //配列番号0,2,4...と偶数番目の数の合計がアリス
       Alice += vec.at(i);
    }
    else{
       Bob += vec.at(i);//配列番号1.3.5と奇数番目の数の合計がBob
    }
  }
  //cout << Alice << endl;
  //cout << Bob << endl;
  cout << Alice - Bob << endl;//AlicとBobの合計の差
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	int r, c, ans;
	int[][] map;
	
	void loop(int z){
		if(z==r) check();
		else{
			loop(z+1);
			for(int i=0;i<c;i++) map[z][i] = 1-map[z][i];
			loop(z+1);
			for(int i=0;i<c;i++) map[z][i] = 1-map[z][i];
		}
	}
	
	void check(){
		int temp;
		int sum = 0;
		for(int i=0;i<c;i++){
			temp = 0;
			for(int j=0;j<r;j++){
				temp += map[j][i];
			}
			if(temp<=r/2) temp = r-temp;
			sum += temp;
		}
		ans = Math.max(ans, sum);
	}
	
	void solve(){
		Scanner sc = new Scanner(System.in);
		
		while(true){
			r = sc.nextInt();
			c = sc.nextInt();
			if(r==0 && c==0) break;
			
			map = new int[r][c];
			for(int i=0;i<r;i++){
				for(int j=0;j<c;j++){
					map[i][j] = sc.nextInt();
				}
			}
			ans = 0;
			loop(0);
			System.out.println(ans);
		}	
	}
	
	public static void main(String[] args) {
		new Main().solve();	
	}	
}

Measured memory_bytes: 69348
// by adiforluls
#pragma GCC optimize ("-O2")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define FAST            ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll              long long
#define ld              long double
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define all(a)          (a).begin(),(a).end()
#define clz(a)          __builtin_clz(a) // count leading zeroes
#define ctz(a)          __builtin_ctz(a) // count trailing zeroes
#define popc(a)         __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define rep(i,a,b)      for(ll i=a;i<b;i++)
#define rfor(i,a,b)     for(ll i=a; i>=b; i--)
#define debug(x)        cerr << #x << " = " << x << endl;
#define F               first
#define S               second
#define endl            '\n'
#define SIZE            1000005
#define deci(n)         cout<<fixed<<setprecision(n)
#define ordered_set     tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key(k)
// find_by_order(k)
const ld PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const ll lul2 = 998244353;
const ll lul = 1000000007;

void mod(ll &x)
{
    if(x>=lul) x-=lul;
    if(x<0) x+=lul;
}

ll _gcd(ll a, ll b)
{
    if(b == 0) return a;
    return _gcd(b,a%b);
}

ll expo(ll n, ll p)
{
    if(p == 0) return 1;
    ll x = expo((n*n)%lul, p/2)%lul;
    if(p&1) return (x*n)%lul;
    return x;
}
//---------------------------------------------------------------------

void solve()
{
    ll a,b,n; cin>>a>>b>>n;
    ll ans;
    ll fact = min(n,b-1);
    ans = (a*fact)/b - a*(fact/b);
    cout<<ans;
}
int main()
{   
    FAST;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; t=1;
    rep(i,1,t+1){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
//#define int long long
using namespace std;
typedef long long ll;
const int INF = 1e9;

int calc(int p)
{
    int ret = p / 500;
    p %= 500;
    ret += p / 100;
    p %= 100;
    ret += p / 50;
    p %= 50;
    ret += p / 10;
    return ret;
}

signed main()
{
    int p;
    int _10, _50, _100, _500;

    bool first = true;
    while (true) {
        cin >> p;
        if (p == 0) break;

        cin >> _10 >> _50 >> _100 >> _500;
        int minMaisu = 1e10;
        int min10, min50, min100, min500;
        for (int i=0; i<=_10; i++) {
            for (int j=0; j<=_50; j++) {
                for (int k=0; k<=_100; k++) {
                    for (int l=0; l<=_500; l++) {
                        int price = 10*i + 50*j + 100*k + 500*l;
                        if (price < p) continue;
                        int moraeru = calc(price - p);
                        int maisu = _10+_50+_100+_500-i-j-k-l+moraeru;
                        if (maisu >= 0 && minMaisu > maisu) {
                            min10 = i; min50 = j; min100 = k; min500 = l;
                            minMaisu = maisu;
                            //cout << "minMaisu = " << minMaisu << endl;
                        }
                    }
                }
            }
        }

        if (first) {
            first = false;
        } else {
            cout << endl;
        }
        if (min10 != 0) cout << "10 " << min10 << endl;
        if (min50 != 0) cout << "50 " << min50 << endl;
        if (min100 != 0) cout << "100 " << min100 << endl;
        if (min500 != 0) cout << "500 " << min500 << endl;
    }
}

Measured memory_bytes: 3000
#include <iostream>

using namespace std;

int main()
{
	int A, B;
	cin >> A >> B;

	if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) {
		cout << "Possible" << endl;
	}
	else {
		cout << "Impossible" << endl;
	}
	

}





Measured memory_bytes: 3620