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

public class Main {
    static String[] marks = {"i", "x", "c", "m"};

    static int calc(String mcxi) {
        int ans = 0;
        String[] tokens = mcxi.split("");
        for (int i = 0; i < tokens.length; i++) {
            int ind = Arrays.asList(marks).indexOf(tokens[i]);
            if (i != 0 && !Arrays.asList(marks).contains(tokens[i-1])) {
                // previous token is number
                ans += Integer.parseInt(tokens[i-1]) * Math.pow(10, ind);
            } else {
                ans += Math.pow(10, ind);
            }
        }
        return ans;
    }

    static String createMCXI(int num) {
        String str = "";
        int n = num;
        int c;
        for (int i = 3; i >= 0; i--) {
            c = n / (int)Math.pow(10, i);
            n = n % (int)Math.pow(10, i);
            if (c != 0) {
                if (c != 1)
                    str += c;
                str += marks[i];
            }
        }

        return str;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine().trim());
        String[] str;

        for (int i = 0; i < n; i++) {
            str = sc.nextLine().split(" ");
            System.out.println(createMCXI(calc(str[0]) + calc(str[1])));
        }
    }
}

Measured memory_bytes: 45776
package main

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

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

var sc = bufio.NewScanner(os.Stdin)

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

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	A, B := getInt(), getInt()

	if A%3 == 0 || B%3 == 0 || (A+B)%3 == 0 {
		out("Possible")
	} else {
		out("Impossible")
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, start, n) for (int i = (int)(start); i < (int)(n); ++i)
static const int INFTY = (1 << 30);
int N, M;
void func()
{
    cin >> N;
    int a[N + 1];
    rep(i, 1, N + 1) { cin >> a[i]; }
    int p = 1, number = 1;
    while (p < N + 1)
    {
        if (a[p] == number)
        {
            ++number;
        }
        ++p;
    }
    if (number == 1)
        cout << -1 << endl;
    else
    {
        cout << N - number + 1 << endl;
    }
}
int main()
{
    func();
}

Measured memory_bytes: 1024
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int data1 = sc.nextInt();
		//System.out.println(data1);
		int data2 = sc.nextInt();
		//System.out.println(data2);
		int data3 = sc.nextInt();
		//System.out.println(data3);

		int data = (data1 * 100) + (data2 * 10) + data3;
		//System.out.println(data);

		if (data % 4 == 0) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	}

}


Measured memory_bytes: 21844
fun main(args: Array<String>){
    var n = readLine()!!
    val topDigit = n[0].toString().toInt()
    n = n.slice(1 until n.length)
    var maxDigit = 0
    var minDigit = 9
    n.forEach {
        maxDigit = Math.max(maxDigit, it.toString().toInt())
        minDigit = Math.min(minDigit, it.toString().toInt())
    }
    println(
        if (minDigit == 9) topDigit + (9 * n.length)
        else (topDigit - 1) + (9 * n.length)
    )
}


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

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define ms(a, x) memset(a, x, sizeof(a))
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
#define pb push_back

using namespace std;
using ll=long long;
using pii= pair<int, int>;
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
template<typename... T> void rd(T&... args) {((cin>>args), ...);}
template<typename... T> void wr(T... args) {((cout<<args<<" "), ...);cout<<endl;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    map<int,int> cnt;
    ll sum=0;
    forn(i,n){
        int x;
        cin>>x;
        cnt[x]++;
        sum+=x;
    }
    int q;
    cin>>q;
    while(q--){
        int b,c;
        cin>>b>>c;
        sum+=cnt[b]*(c-b);
        cnt[c]+=cnt[b];
        cnt[b]=0;
        cout<<sum<<endl;
    }
    return 0;
}



Measured memory_bytes: 8016
#include<stdio.h>
int main(){
  int n,a[1000],diff,i,j,mindiff;
  while(1){
    scanf("%d",&n);
    if(n==0)break;

    for(i=0;i<n;i++){
      scanf("%d",&a[i]);
    }
    if(a[0]>a[1]){
      mindiff=a[0]-a[1];
    }else{
      mindiff=a[1]-a[0];
    }

    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
	if(i==j)continue;
	
	diff=a[i]-a[j];

	if(diff>=0 && mindiff > diff){
	  mindiff = diff;
	}
      }
    }
    printf("%d\n",mindiff);
  }
  return 0;
}

Measured memory_bytes: 604
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  /* your code */
  NodePointer x = nil->next;

  while(x!=nil && x->key!=key) x = x->next;

  return x;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  /* your code */
  if(t==nil) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  NodePointer t = nil->prev;
  /* your code */
  deleteNode(t);
}

void delete(int key){
  NodePointer x;
  /* your code */
  x = listSearch(key);
  deleteNode(x);
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;

  /* your code */
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;

}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}



Measured memory_bytes: 32968
N = int(input())
C = input()

W = 0                  #仕切りより左側の白い石の個数
R = C.count('R')       #仕切りより右側の赤い石の個数

ans = max(W, R)

for i in range(N):
    if C[i] == 'W':    #仕切りの左側に'W'が移動する
        W += 1
    else:              #仕切りの左側に'R'が移動する
        R -= 1
    ans = min(ans, max(W, R))

print(ans)

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

int main() {
  int A,B;
  cin>>A>>B;
  int P,Q,R,S;
  P=(A*25+1)/2,Q=(A*25+26)/2;
  R=B*10,S=B*10+10;
  if(Q<=R||S<=P){
    cout<<"-1"<<endl;
  }
  else{
    cout<<max(P,R)<<endl;
  }
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public final class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int h, w, n;
		String[] arg = br.readLine().split(" ");
		h = Integer.parseInt(arg[0]);
		w = Integer.parseInt(arg[1]);
		n = Integer.parseInt(arg[2]);
		int[] xi = new int[n];
		int[] yi = new int[n];
		for (int i = 0; i < n; i++) {
			arg = br.readLine().split(" ");
			yi[i] = Integer.parseInt(arg[0]) - 1;
			xi[i] = Integer.parseInt(arg[1]) - 1;
		}
		long[] res = new Solver().solve(xi, yi, w - 1, h - 1);
		for (long s : res)
			System.out.println(s);
	}

}

class Solver {
	long mod = 1_000_000_000l;

	long[] solve(int[] xi, int[] yi, int w, int h) {
		Map<Long, Integer> m = new HashMap<Long, Integer>();
		for (int i = 0; i < xi.length; i++) {
			for (int k = 0; k <= 2; k++) {
				for (int kk = 0; kk <= 2; kk++) {

					if (xi[i] - k < 0 || yi[i] - kk < 0 || xi[i] - k > w - 2 || yi[i] - kk > h - 2)
						continue;
					long p = (xi[i] - k) * mod + (yi[i] - kk);
					if (m.containsKey(p)) {
						m.replace(p, m.get(p) + 1);
					} else {
						m.put(p, 1);
					}
				}
			}

		}
		long[] ans = new long[10];
		ArrayList<Integer> vals = new ArrayList<Integer>(m.values());
		long sum = 0L;
		for (int i = 0; i < vals.size(); i++) {
			ans[vals.get(i)]++;
		}
		for (int i = 1; i < ans.length; i++) {
			sum += ans[i];
		}
		ans[0] = ((long) (h - 1) * (w - 1) - sum);
		return ans;
	}
}

Measured memory_bytes: 132948
/*
    Author A.G.Maruf
    5 th seme :P
    code written 09:36PM; 23/06/2018
*/
#include <bits/stdc++.h>
#define gc              getchar
#define pc              putchar
#define pb              push_back
#define Sort_arr(n,x)   sort(n,n+x);
#define SortS(s)        sort(s.begin(), s.end());
#define SortRS(s)       sort(s.rbegin(), s.rend());
#define all(s)          s.begin(), s.end()
#define GCin(a)         getline(cin,a);
#define Sz(a)           a.size()
#define arr_rev(n)      sort(n.begin(), n.end(), greater<int>());
#define Gin(a)          getline(cin,a);
#define input(a)        cin>>a;
#define Sz(a)           a.size()
#define input2(a,b)     cin>>a>>b;
#define input3(a,b,c)   cin>>a>>b>>c;
#define input4(a,b,c,d) cin>>a>>b>>c>>d;
#define rep(n)          for(int i=1;i<n;i++)
#define Fast_read       ios_base::sync_with_stdio(false);
#define Unique(n)       sort(Search(n)),n.erase(unique(Search(n)),n.end());
#define PI              3.1415926535897932384626433832795l
#define Ignore          cin.ignore();
#define out(n)          cout<<n<<endl;
#define mem(n,i)        memset(n,i,sizeof n);
#define square(n)       (n*n)
#define cube(n)         (n*n*n)
#define F               first
#define S               second
#define mxin              -INFINITY
#define mnin              INFINITY
#define el              <<endl
using namespace std;
int main ()
{
    //freopen("output.txt","w",stdout);
    int a,b,sum=0,sub=0,multi=1;
    cin>>a>>b;
    sum=a+b;
    sub=a-b;
    multi=a*b;
    int ans=max(sum,sub);
    ans=max(multi,ans);
    cout<<ans<<endl;
}




Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<vector<ll> > mat;

int main()
{ios_base::sync_with_stdio(false);
string s;
cin>>s;
int n=s.length(),ans=0;
rep(i,0,n-1)if(s[i]=='g')ans++;
else ans--;
ans/=2;
ol(ans);
return 0;
}


Measured memory_bytes: 640
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Joy
 */

#include <bits/stdc++.h>
#define REP(i, N) for (ll i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF ll(1e9)
#define INFL ll(1e18)
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int ctoi(char c) {return c - '0';}

class CGuessTheNumber {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int N, M;
	    in >> N >> M;
	    int s[M];
	    char c[M];
	    REP(i, M) in >> s[i] >> c[i];
	    int ans = -1;
	    int temp = 1;
	    REP(i, N) temp *= 10;
        for (int i = 0; i < temp; ++i) {
            if (N > 1) {
                if (i < temp/10) continue;
            }
            string t = to_string(i);
            bool ok = true;
            REP(j, M) {
                if (t[s[j]-1] != c[j]) ok = false;
            }
            if (ok) {
                ans = i;
                break;
            }
        }
        out << ans << '\n';
	}
};


int main() {
	CGuessTheNumber solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i = 0; i < N; i++) cin >> a[i];
    int S = 1;
    int b = 0;
    for(int i = 0; i < 1000000; i++){
        if(a[b] == 2){
            cout << S << endl;
            return 0;
        }
        b = a[b] - 1;
        S++;
        if(i == 100100){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}


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

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

#define loop(i, n) for(int i = 0;i < n;i++)
#define IINF 2e9
#define MOD 1e9+7

int main(void){

    int x, n;
    cin >> x >> n;
    if(n == 0) {
        cout << x << endl;
        return 0;
    }


    vector<int> p(n);
    loop(i, n) cin >> p[i];


    vector<bool> a(102, false);

    loop(i, n){
        a[p[i]] = true;
    }

    int ans = IINF;
    int index = 0;

    for(int i = 101;i >= 0;i--){
        if(a[i] == false){
            if(ans >= abs(x-i)){
                ans = min(ans, abs(x-i));
                index = i;
            }
        }
    }

    cout << index << endl;

    return 0;
}

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

using namespace std;

void solve()
{
	vector<int> vec(3);
	for (int i = 0; i < 3; ++i)
	{
		cin >> vec[i];
	}
	sort(vec.begin(), vec.end());
	cout << vec[0] + vec[1] << endl;
}

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

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
const int SIZE=205;
//int arr[SIZE]={};
//ここまでテンプレ
vector<pair<int,int>> node[SIZE];
int N,M,R;
vector<int> RR;
int v[201]={};
bool done[10]={};
int dfs(int s,int ans);
int main(){
	cin>>N>>M>>R;
	int d[SIZE][SIZE]={};
	for(int i=0;i<R;i++){
		int r;
		cin>>r;
		r--;
		v[r]=i;
		RR.push_back(r);
	}
	for(int i=0;i<SIZE;i++)for(int j=0;j<SIZE;j++){
		if(i==j)
			d[i][j]=0;
		else
			d[i][j]=INF;
	}
	for(int i=0;i<M;i++){
		int A,B,C;
		cin>>A>>B>>C;
		A--,B--;
		d[A][B]=C;
		d[B][A]=C;
	}
	for(int k=0;k<N;k++)for(int i=0;i<N;i++)for(int j=0;j<N;j++){
		d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
	}
	for(int i=0;i<N;i++){
		for(int j=0;j<R;j++){
			if(i!=RR[j])
				node[i].push_back(make_pair(RR[j], d[i][RR[j]]));
		}
	}
	int mini=INF;
	for(int i=0;i<R;i++){
		done[v[RR[i]]]=1;
		mini=min(mini,dfs(RR[i],0));
		done[v[RR[i]]]=0;
	}
	cout<<mini<<endl;
    return 0;
}
int dfs(int s,int ans){
	int mini=INF;
	for(int i=0;i<node[s].size();i++){
		int next=node[s][i].first;
		int d=node[s][i].second;
		if(done[v[next]]==0){
			//cout<<v[next]<<" "<<done[v[next]]<<endl;
			done[v[next]]=1;
			ans+=d;
			mini=min(mini,dfs(next,ans));
			done[v[next]]=0;
			ans-=d;
		}
	}
	if(mini<INF){
		return mini;
	}
	else
		return ans;
}

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

int main()
{
	int n, m;
	while (cin >> n, n) {
		cin >> m;
		string s;
		cin >> s;
		vector<int> dp(m + 1);
		int res = 0;
		for (int i = 0; i < m; i++) {
			if (s[i] == 'I' && i - 2 >= 0 && s.substr(i - 2, 3) == "IOI") {
				dp[i + 1] = dp[i - 1] + 1;
				if (dp[i + 1] >= n) {
					res++;
				}
			}
		}
		cout << res << endl;
	}
	return 0;
}



Measured memory_bytes: 7824
from collections import deque


def main():
    S = [s for s in input().split()]
    ops = ['+', '-', '*']
    
    d = deque()
    for s in S:
        if s in ops:
            b, a = d.pop(), d.pop()
            eq = a + s + b
            v = eval(eq)
            d.append(str(v))
        else:
            d.append(s)
            
    print(v)
 
    
if __name__=="__main__":
    main()


Measured memory_bytes: 5976
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner in = new Scanner(System.in);

		int n = in.nextInt();
		int[] a = new int[n];
		int count = 0;

		for(int i=0;i<n;i++) {
			a[i] = in.nextInt();
			if((i+1)%2==1&&a[i]%2==1) {
				count++;
			}
		}
		System.out.println(count);

	}

}


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

signed main() {
  ios::sync_with_stdio(false);

  int N;
  cin >> N;
  
  static int A[16][16];
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < N; ++j)
      cin >> A[i][j];

  static int64_t score[1 << 16];
  for (int s = 0; s < 1 << N; ++s)
    for (int i = 0; i < N; ++i)
      for (int j = i + 1; j < N; ++j)
        if ((s >> i & 1) && (s >> j & 1))
          score[s] += A[i][j];

  static int64_t dp[1 << 16];
  static bool   vis[1 << 16];
  memset(dp, 0xc0, sizeof(dp));
  function<int64_t(int)> dfs = [&](int s) {
    if (vis[s]) return dp[s];
    if (!s) return (int64_t) 0;
    vis[s] = 1;
    for (int t = s; t > 0; t = t - 1 & s) {
      dp[s] = max(dp[s], score[t] + dfs(s ^ t));
    }
    return dp[s];
  };

  cout << dfs((1 << N) - 1) << endl;

  return 0;
}


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

int main()
{
    int n, pp, qq, cnt = 1;
    cin >> n;
    vector<int> p(n), q(n), b(n);
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
        b[i] = i + 1;
    }
    for (int i = 0; i < n; i++)
    {
        cin >> q[i];
    }
    do
    {
        if (b == p)
            pp = cnt;
        if (b == q)
            qq = cnt;
        cnt++;
    } while (next_permutation(b.begin(), b.end()));
    int ans = pp > qq ? pp - qq : qq - pp;
    cout << ans << "\n";
    return 0;
}


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

int main(){
    int a1, a2, a3;
    cin >> a1 >> a2 >> a3;
    if(a1 + a2 + a3 >= 22){
        cout << "bust" <<endl;
    }
    else{
        cout << "win" << endl;
    }
    return 0;
}

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

using namespace std;

static int table[1001][128] = { { 0 } };

int main(){
	ios_base::sync_with_stdio(false);
	for(int i = 1; i <= 1000; ++i){
		if(i % 2 == 1){
			table[i][0] = table[i - 1][0];
			for(int j = 1; j < 128; ++j){
				table[i][j] = table[i][j - 1] + 1;
			}
		}else{
			table[i][127] = table[i - 1][127];
			for(int j = 126; j >= 0; --j){
				table[i][j] = table[i][j + 1] + 1;
			}
		}
	}
	int T;
	cin >> T;
	while(T--){
		int n, d;
		cin >> n >> d;
		cout << table[n][d] << endl;
	}
	return 0;
}



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

struct Dice
{
	Dice(int d[6]){
		for(int i = 0; i < 6; ++i)
			n[i] = d[i];
	}
	void toN(){ shift( n[0], n[1], n[5], n[4] ); }
	void toS(){ shift( n[0], n[4], n[5], n[1] ); }
	void toW(){ shift( n[0], n[2], n[5], n[3] ); }
	void toE(){ shift( n[0], n[3], n[5], n[2] ); }
	void shift( int& a, int& b, int& c, int& d ){
		int t = a;
		a = b;
		b = c;
		c = d;
		d = t;
	}
	int getIndex( int a ){
		for(int i = 0; i < 6; ++i){
			if( n[i] == a )
				return i;
		}
		return -1;
	}
	int getRightNumberOfTopFront( int t, int f ){
		return n[getRightIndexOfTopFront( getIndex(t), getIndex(f) )]; 
	}
	int getRightIndexOfTopFront( int t, int f ){
		switch( t )
		{
		case 0:
			switch( f )
			{
			case 1: return 2;
			case 2: return 4;
			case 3: return 1;
			case 4: return 3;
			}
		case 1:
			switch( f )
			{
			case 0: return 3;
			case 2: return 0;
			case 3: return 5;
			case 5: return 2;
			}
		case 2:
			switch( f )
			{
			case 0: return 1;
			case 1: return 5;
			case 4: return 0;
			case 5: return 4;
			}
		case 3:
			switch( f )
			{
			case 0: return 4;
			case 1: return 0;
			case 4: return 5;
			case 5: return 1;
			}
		case 4:
			switch( f )
			{
			case 0: return 2;
			case 2: return 5;
			case 3: return 0;
			case 5: return 3;
			}
		case 5:
			switch( f )
			{
			case 1: return 3;
			case 2: return 1;
			case 3: return 4;
			case 4: return 2;
			}
		}
		return -1;
	}
	int n[6];
};

int main()
{
	int n, i, t, f, d[6] = {};
	for(i = 0; i < 6; ++i)
		cin >> d[i];

	Dice dice(d);
	cin >> n;
	for(i = 0; i < n; ++i){
		cin >> t >> f;
		cout << dice.getRightNumberOfTopFront( t, f ) << "\n";
	}

	return 0;
}

Measured memory_bytes: 1164
n,m = map(int,input().split())
x = [0 for _ in range(m)]
y = [0 for _ in range(m)]
for i in range(m):
    x[i],y[i] = map(int,input().split())
    x[i] -= 1
    y[i] -= 1

box = [1 for _ in range(n)]
red = [0 for _ in range(n)]
red[0] = 1
for i in range(m):
    red[y[i]] = 1 if red[x[i]] else red[y[i]]
    red[x[i]] = red[x[i]] if box[x[i]]-1 else 0
    box[x[i]] -= 1
    box[y[i]] += 1
print(sum(red))

Measured memory_bytes: 12592
#include<bits/stdc++.h>
#define endl "\n" 
#define pi acos(-1)
#define ll long long 
using namespace std;
void att(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
}
void sirra(){
	#ifndef ONLINE_JUDGE
    	freopen("input.txt", "r", stdin);
    	freopen("output.txt", "w", stdout);
	#endif
}
void solve();
int main(){
	att();sirra();
	int q=1;//cin>>q;
	while(q--){
		solve();
	}
}
void solve(){
	int n,x,k(0);cin>>n;
	for(int i=1;i<=n;i++){
		cin>>x;
		if((i & x) & 1)
			k++;
	}
	cout<<k;
}

Measured memory_bytes: 3608
def gcd(x, y)
  if( x.to_i == 0 || y.to_i ==0)
    return 0
  end
  #ユークリッド互除法
  while ( ( r = x % y) != 0 )
    x = y
    y = r
  end

  return y
end

def lcd(x,y)
  if(x.to_i == 0 || y.to_i ==0)
    return 0
  end

  return x*y / gcd(x,y)
end

while line = gets
  num = line.split(" ")
  puts gcd(num[0].to_i,num[1].to_i).to_s+" "+lcd(num[0].to_i,num[1].to_i).to_s
end

Measured memory_bytes: 6100
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val Array(n, a, b) = in.readLine().split("\\s+").map(_.toLong)

    out.println(
      n / (a + b) * a + Math.min(a, n % (a + b))
    )
    out.flush()
  }
}


Measured memory_bytes: 27340
N = int(input())
RC = [tuple(map(int, input().split())) for _ in range(N)]
INF = 10**18
# dp[i][j]: iからjの区間における最小回数
dp = [[INF]*N for _ in range(N)]
for i in range(N):
    for j in range(N):
        if i == j:
            dp[i][j] = 0
for diff in range(2, N+1):
    for i in range(N-diff+1):
        j = i+diff-1
        for k in range(i, j):
            dp[i][j] = min(dp[i][j], dp[i][k]+dp[k+1][j]+RC[i][0]*RC[k][1]*RC[j][1])
print(dp[0][N-1])


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


bool isTraingle(int a,int b,int c){
    if(a+b<=c) return false;
    if(a+c<=b) return false;
    if(b+c<=a) return false;
    return true;
}

bool NotEqual(int a,int b,int c){
    if(a==b) return false;
    if(a==c) return false;
    if(b==c) return false;
    return true;
}

int main(){
 
   int n;cin>>n;
   int arr[105];
   for(int i=0;i<n;i++) cin>>arr[i];
   if(n<3) {cout<<0<<endl; return 0;}
    int cnt=0;
   
   for(int i=0;i<n;i++){
       for(int j=i+1;  j<n;j++){
           for(int k=j+1; k<n;k++){
               if(NotEqual(arr[i],arr[j],arr[k]) &&isTraingle(arr[i],arr[j],arr[k])) {
                   cnt++;
               }
           }
       }
   }
   cout<<cnt<<endl;
}

Measured memory_bytes: 3676
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

int main()
{
	long long int n,ans=0,min=100000000;
	int flag=0;
	
	cin >> n;
	
	vector<int> a(n);
	
	for(int i=0;i<n;i++){
		cin >> a[i];
	}

	
	for(int i=0;i<n;i++){
		if( 0 > a[i] ){
			if(flag==0)flag=1;
			else flag=0;
		}
		a[i] = abs(a[i]);
		if(min > a[i])min = a[i];
	}
	
	
	for(int i=0;i<n;i++){
		ans += a[i];
	}
	
	if(flag==1)ans = ans - 2*min;
	
	cout << ans << endl;
	
	return 0;
}
	

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

typedef vector<int> vi;

typedef long long ll;
struct RollingHash {
	static const ll mo0 = 1000000007, mo1 = 1000000009;
	static ll mul0, mul1;
	static const ll add0 = 1000010007, add1 = 1003333331;
	static vector<ll> pmo[2];
	vector<int> s; int l; vector<ll> hash_[2];
	void init(vector<int> s) {
		this->s = s; l = s.size(); int i, j;
		hash_[0] = hash_[1] = vector<ll>(1, 0);
		if (!mul0) mul0 = 10009 + (((ll)&mul0) >> 5) % 259, mul1 = 10007 + (((ll)&mul1) >> 5) % 257;
		if (pmo[0].empty()) pmo[0].push_back(1), pmo[1].push_back(1);
		for (int i = 0; i < l; i++) hash_[0].push_back((hash_[0].back()*mul0 + add0 + s[i]) % mo0);
		for (int i = 0; i < l; i++) hash_[1].push_back((hash_[1].back()*mul1 + add1 + s[i]) % mo1);
	}
	pair<ll, ll> hash(int l, int r) { // s[l..r]
		if (l>r) return make_pair(0, 0);
		while (pmo[0].size()<r + 2)
			pmo[0].push_back(pmo[0].back()*mul0%mo0), pmo[1].push_back(pmo[1].back()*mul1%mo1);
		return make_pair((hash_[0][r + 1] + (mo0 - hash_[0][l] * pmo[0][r + 1 - l] % mo0)) % mo0,
			(hash_[1][r + 1] + (mo1 - hash_[1][l] * pmo[1][r + 1 - l] % mo1)) % mo1);
	}
};
vector<ll> RollingHash::pmo[2]; ll RollingHash::mul0, RollingHash::mul1;

int main()
{
	string T, P;
	cin >> T >> P;

	if (T.length() < P.length()) return 0;

	RollingHash HashT, HashP;

	vi VT(T.length());
	rep(i, 0, T.length()) VT[i] = T[i] - 'a';
	HashT.init(VT);

	vi VP(P.length());
	rep(i, 0, P.length()) VP[i] = P[i] - 'a';
	HashP.init(VP);

	rep(i, 0, T.length() - P.length() + 1)
	{
		auto t = HashT.hash(i, i + P.length() - 1);
		auto p = HashP.hash(0, P.length() - 1);
		//if (t == p) cout << T.substr(i, P.length()) << endl;
		if (t == p) cout << i << endl;
	}
}

Measured memory_bytes: 3272
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int A = fs.nextInt();
        int B = fs.nextInt();

        if(A<10 && B<10) {
            System.out.println(A*B);
        }else {
            System.out.println(-1);
        }
    }
}
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
 
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
 
    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }
 
    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
 
    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }
 
    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
 
    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
 
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
 
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 21204
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int[][] a = getIntArr(in, n, n);
		long r = solve(n, a);
		System.out.println(r);
		in.close();
	}

	static long mod = 1000000007;

	private static long solve(int n, int[][] a) {
		long[] dp = new long[1 << n];
		dp[0] = 1;
		for (int mask = 0; mask < 1 << n; mask++) {
			int ones = Integer.bitCount(mask);
			for (int j = 0; j < n; j++) {
				if ((mask & (1 << j)) != 0 && a[ones - 1][j] == 1) {
					int subMask = mask ^ (1 << j);
					dp[mask] = (dp[mask] + dp[subMask]) % mod;
				}
			}
		}
		return dp[(1 << n) - 1];
	}

	static String str(int[] a) {
		String[] str = new String[a.length];
		for (int i = 0; i < a.length; i++) {
			str[i] = a[i] + "";
		}
		return String.join(" ", str);
	}

	static int[] getIntArr(Scanner in, int size) {
		int[] arr = new int[size];
		for (int i = 0; i < size; i++) {
			arr[i] = in.nextInt();
		}
		return arr;
	}

	static int[][] getIntArr(Scanner in, int row, int col) {
		int[][] arr = new int[row][];
		for (int i = 0; i < row; i++) {
			arr[i] = getIntArr(in, col);
		}
		return arr;
	}

	static char[] getCharArr(Scanner in, int size) {
		char[] arr = in.next().toCharArray();
		return arr;
	}

	static String[] getStringArr(Scanner in, int size) {
		String[] arr = new String[size];
		for (int i = 0; i < size; i++) {
			arr[i] = in.next();
		}
		return arr;
	}

	static Map<Integer, List<Integer>> getEdges(Scanner in, int size, boolean directed) {
		Map<Integer, List<Integer>> edges = new HashMap<>();
		for (int i = 0; i < size; i++) {
			int from = in.nextInt();
			int to = in.nextInt();
			if (!edges.containsKey(from)) {
				edges.put(from, new ArrayList<Integer>());
			}
			edges.get(from).add(to);
			if (!directed) {
				if (!edges.containsKey(to)) {
					edges.put(to, new ArrayList<Integer>());
				}
				edges.get(to).add(from);
			}

		}
		return edges;
	}
}


Measured memory_bytes: 40788
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;
int main(){
    string s;
    cin>>s;
    bool flag=false;
    int a=0,b=0,c=0;
    rep(i,0,2){
        if(s[i]=='a') a++;
        if(s[i]=='b') b++;
        if(s[i]=='c') c++;
        if(a==b&&b==c) flag = true; 
    }
    if(flag) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
N, K = [int(i) for i in input().split()]
S = list(input())

if S[K-1] == 'A':
    S[K-1] = 'a'
elif S[K-1] == 'B':
    S[K-1] = 'b'
else:
    S[K-1]  = 'c'
    
print(''.join(S))


Measured memory_bytes: 3060
# Square869120Contest #4 B - Buildings are Colorful!　
# 分割統治法 ver
import sys

N, K = map(int, sys.stdin.readline().strip().split())
a = list(map(int, sys.stdin.readline().strip().split()))

if K == 0:
    sys.exit()

def dfs(height=a[0], cost=0, target=K, can_see=1, i=1):
    if can_see >= target:
        # print('height', height)
        # print('can_see', can_see)
        # print('cost', cost)
        return cost

    # 端まで探索したとき
    if i == len(a):
        return float('inf')

    # 建物 i を選ばない場合
    if height >= a[i]:
        cost1 = dfs(height=height, cost=cost, target=K, can_see=can_see, i=i+1)
    else:
        cost1 = dfs(height=a[i], cost=cost, target=K, can_see=can_see+1, i=i+1)
    # print('cost1', cost1, 'can_see', can_see, 'i', i)

    # 建物　i を選んだ場合
    cost += max(0, height + 1 - a[i])
    height = max(a[i], height + 1)
    cost2 = dfs(height=height, cost=cost, target=K, can_see=can_see+1, i=i+1)
    # print('cost2', cost2)

    return min(cost1, cost2)


print(dfs(a[0], cost=0, target=K, can_see=1, i=1))



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
const ll MAX = 1001001;
const ll MOD = 1000000007;

int main()
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = max({a * c, a * d, b * c, b * d});

    cout << ans << endl;
}

Measured memory_bytes: 3632
def p2(AA):
    A = AA&0xFFFFFFFFFFFFC
    #print (AA,A,sA)
    a = A
    K = 0
    for i in range(1000):
        if (a>0):
            K+=1
        a//=2
    a = A
    D = 0
    for k in range(K-1,0,-1):
        p2k = 1<<(k)
        if (a-p2k>=0):
            D = (D<<1)+(a-p2k-1)%2
            #print ( a,"D",(a-p2k-1)%2,p2k)
            a = a-p2k
        else:
            D = (D<<1)
            #print (a,"D",0,p2k)
    D<<=1
    for i in range(A+1,AA+1):
        D = D^i
    return D

a,b = [int(it) for it in input().split()]
if (a==0):
  print ( p2(b) )
else:
  print ( p2(b)^p2(a-1) )

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace cswork
{
    class Program
    {
        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);
                i = 0;
                return next();
            }

            public int nextInt()
            {
                return int.Parse(next());
            }

            public long nextLong()
            {
                return long.Parse(next());
            }

            public double nextDouble()
            {
                return double.Parse(next());
            }
        }

        public Program() { }

        static void Main(string[] args)
        {
            new Program().Omame();
        }

        Scanner cin;
        const int MAXIN = 1024;
        bool[] used = new bool[MAXIN];
        int[] perm = new int[MAXIN];

        List<int[]> permList = new List<int[]>();

        public void Permutation(int pos, int n, int length)
        {
            if (pos == n)
            {
                permList.Add((int[])perm.Clone());
            }

            for (int i = 0; i < n; i++)
            {
                if (!used[i])
                {
                    perm[pos] = i;
                    used[i] = true;
                    Permutation(pos + 1, n, length);
                    used[i] = false;
                }
            }
        }

        public static List<long> GeneratePrime(long max)
        {
            long prime;
            double sqrtMax = Math.Sqrt(max);
            var primeList = new List<long>();

            List<long> searchList = new List<long>();
            for (long i = 2; i <= max - 1; i++)
            {
                searchList.Add(i);
            }

            do
            {
                prime = searchList.First();
                primeList.Add(prime);
                searchList.RemoveAll(n => n % prime == 0);
            } while (prime < sqrtMax);

            primeList.AddRange(searchList);

            return primeList;
        }

        void Omame()
        {
            cin = new Scanner();
            long X = cin.nextLong();

            List<long> primeList = GeneratePrime(110000);

            for (int i = 0; i < primeList.Count; i++)
            {
                if(primeList[i] >= X)
                {
                    Console.WriteLine(primeList[i]);
                    return;
                }
            }
        }
    }
}


Measured memory_bytes: 13152
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#define ll long long int
#define mod 1000000007
#define pii pair<int, int>
#define fr(n) for (int i = 0; i < n; i++)
#define fr1(n) for (int i = 1; i <= n; i++)
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n, k, a[52] = {}, b = 0;
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n, greater<int>());
    for (int i = 0; i < k; i++) b += a[i];
    cout << b << '\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <functional>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
//#define int long long
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n, a, b;

signed main() {
	int i;
	
	cin >> n >> a >> b;
	cout << min(a, b) << " " << max(0, a + b - n) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iomanip>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;

#define ld long double
#define ll long long

map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  string S1,S2;
  cin >> N >> S1 >> S2;
  bool flag=true; // tureの時_縦
  ll ans=0;
  for(int i=0;i<N;i++){
    if(S1[i]==S2[i]){
      if(ans==0){
        ans=3;
        flag =true;
        continue;
      }
      if(flag){
        ans*=2;
      }else{
        ans*=1;
      }
      ans%=MOD;
      flag=true;
    }else if(S1[i]==S1[i+1]){
      if(ans==0){
        ans=6;
        flag =false;
        i+=1;
        continue;
      }
      if(flag){
        ans*=2;
      }else{
        ans*=3;
      }
      flag=false;
      i+=1;
      ans%=MOD;
    }
  }
  cout << ans%MOD << endl;
  return 0;
}

Measured memory_bytes: 256
//
// tested with : g++ (GCC) 8.3.0
//

#include <iostream>
#include <cmath>
using namespace std;

int main() {
    int a;
    int b;
    cin >> a >> b;
    double x = ((double)a + (double)b) / 2;
    int x2 = ceil(x);
    cout << x2 << endl;

    return 0;
}

//ceil   :切り上げ
//floor  :切り捨て
//round  :四捨五入

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

const int MAX_N = 100;
int bit[MAX_N+1], n;

int sum(int i){
	int s = 0;
	while(i > 0){
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

void add(int i, int x){
	while(i <= n){
		bit[i] += x;
		i += i & -i;
	}
}

int main(){
	int a[MAX_N], b[MAX_N];
	while(std::cin >> n, n){
		for(int i=0;i<MAX_N+1;i++){
			bit[i] = 0;
		}

		for(int i=0;i<n;i++){
			std::cin >> a[i];
		}

		for(int i=0;i<n;i++){
			b[i] = a[i];
		}
		std::sort(b, b+n);
		std::map<int, int> m;
		for(int i=0;i<n;i++){
			m[b[i]] = i+1;
		}

		int t = 0;
		for(int i=0;i<n;i++){
			t += i - sum(m[a[i]]);
			add(m[a[i]], 1);
		}

		std::cout << t << std::endl;
	}
}

Measured memory_bytes: 1216
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <tuple>
#include <list>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <cstring>
#include <cstdlib>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

#define xx first
#define yy second
#define $1 first
#define $2 second

void solve() {
	ll n, m; cin >> n >> m;
	ll sum = 0;
	for (int i = 0; i < m; i++) {
		ll k;  cin >> k; sum += k;
	}
	ll ans = n-sum;
	if (ans < 0) {
		cout << -1;
	}
	else {
		cout << ans;
	}

}
int main() {

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif
	solve();
}

Measured memory_bytes: 3672
#include <iostream>

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

using namespace std;

int main(){
	int n, dg=10;
	char d[1005], ans[20]={};

	cin >> n;
	REP(i,n) cin >> d[i];

	REP(i, dg+1) ans[i] = '0';
	while(1){
		int now = dg;
		bool f = true;
		for(int i=0; i<n; i++){
			if( d[i] == ans[now] ){
				now++;
				if( ans[now] == '\0' ){
//	cout << (ans+dg) << " i=" << i << endl;
					now--;
					while( ++ans[now] > '9' ){
						ans[now] = '0';
						now--;
						dg = min(dg, now);
					}
					f = false;
					break;
				}
			}else{
				i -= now - dg;
				now = dg;
			}
		}
		if( f ) break;
	}

	cout << (ans+dg) << endl;

	return 0;
}

Measured memory_bytes: 1160
#include<cstdio>
#include<cstdlib>
using namespace std;

int main()
{
	int ans = 0;
	int num;
	scanf("%d", &num);
	while(num != 0){
		if(num % 10) ans++;
		num /= 10;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;

public class Main {
    static Input in = new Input(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int N = in.nextInt();
        Integer[] A = new Integer[N];
        for (int n = 0; n < N; n++)
            A[n] = in.nextInt();

        Arrays.sort(A, Comparator.reverseOrder());
        long ans = 0;
        for (int i = 1; i < N; i++) {
            ans += A[i / 2];
        }
        out.println(ans);

        out.flush();
    }

    static class Input {
        private BufferedReader br;
        private String[] buff;
        private int index = 0;

        Input(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }
        String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
        String next() {
            while (buff == null || index >= buff.length) {
                buff = nextLine().split(" ");
                index = 0;
            }
            return buff[index++];
        }
        byte nextByte() {
            return Byte.parseByte(next());
        }
        short nextShort() {
            return Short.parseShort(next());
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        float nextFloat() {
            return Float.parseFloat(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
        BigDecimal nextBigDecimal() {
            return new BigDecimal(next());
        }
    }
}



Measured memory_bytes: 63252
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#include<vector>
using namespace std;

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

    int S[10] = {};
    int C[10] = {};
    for(int i=0;i<M;i++)
    {
        cin >>S[i] >> C[i]; 
    }

    // 先頭桁が0の場合NG。ただし0の場合は除く。
    if(N != 1)
    {
        for(int i=0; i<M;i++)
        {
            if(S[i] == 1)
            {
                if(C[i] == 0)
                {
                    cout << -1 << endl;
                    return 0;
                }
            }
        }
    }

    // S[i]の中に同じ桁が存在したら同じ値以外NG
    for(int i=0; i<M;i++)
    {
        for(int j=1;j<M;j++)
        {
            if(S[i] == S[j])
            {
                if(C[i] != C[j])
                {
                    cout << -1 << endl;
                    return 0;
                }
            }
        }
    }



    int Ans = 0;
    bool keta3 = false;
    bool keta2 = false;
    bool keta1 = false;

    for(int i=0;i<M;i++)
    {
        switch(S[i])
        {
            case 1:
                if(!keta3)
                {
                    if(N == 3)
                    {
                        Ans += (C[i]*100);
                        keta3 = true;
                    }
                    else if(N == 2)
                    {
                        Ans += (C[i]*10);
                        keta3 = true;
                    }
                    else if(N == 1)
                    {
                        Ans += (C[i]);
                        keta3 = true;
                    }
                }
                break;
            case 2:
                if(!keta2)
                {
                    if(N == 3)
                    {
                         Ans += (C[i]*10);
                         keta2 = true;
                    }
                    else if(N==2)
                    {
                        Ans += C[i];
                        keta2 = true;
                    }
                }
                break;
            case 3:
                if(!keta1)
                {
                    Ans += (C[i]);
                    keta1 = true;
                }
                break;    
        }
    }

    // 3桁なのに、3桁存在しない場合
    if(N == 3 && Ans < 100)
        Ans += 100;
    if(N == 2 && Ans < 10)
        Ans += 10;

    cout << Ans << endl;
    return 0;

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	int e;
	while (cin >> e, e) {
		int min = e;
		for (int i = 0; i * i <= e; i++) {
			for (int j = 0; i * i + j * j * j <= e; j++) {
				if (i + j + (e - i * i - j * j * j) < min) min = i + j + (e - i * i - j * j * j);	
			}	
		}
		cout << min << endl;	
	}
	return 0;
}

Measured memory_bytes: 1156