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

public class Main {

	public static void main(String[] args) {
		//		new Main().solveA();
		//		new Main().solveB();
		//		new Main().solveB2();
		new Main().solveC();
		// new Main().solveD();
	}

	private void solveA() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();
			numK = scanner.nextInt();

			if (numN % numK == 0) {
				System.out.println(0);
			} else {
				System.out.println(1);
			}

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private int isPurchase(int numN, int num) {

		if (numN <= 0) {
			return numN;
		}
		if (bWkMap.get(numN) != null) {
			return bWkMap.get(numN);
		}

		int val1 = isPurchase(numN - 7, 4);
		int val2 = isPurchase(numN - 7, 7);
		int val3 = isPurchase(numN - 4, 4);
		int val4 = isPurchase(numN - 4, 7);

		val1 = val1 < 0 ? 999999999 : val1;
		val2 = val2 < 0 ? 999999999 : val2;
		val3 = val3 < 0 ? 999999999 : val3;
		val4 = val4 < 0 ? 999999999 : val4;

		int wk = Math.min(Math.min(val1, val2), Math.min(val3, val4));

		bWkMap.put(numN, wk);
		return wk;
	}

	private Map<Integer, Integer> bWkMap = new HashMap<Integer, Integer>();

	private void solveB() {
		Scanner scanner = null;
		int numN = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			int val = isPurchase(numN, 0);

			System.out.println(val == 0 ? "Yes" : "No");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveB2() {
		Scanner scanner = null;
		int numN = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			for (int i = 0; i < 25; i++) {
				for (int j = 0; j < 15; j++) {
					if (4 * i + 7 * j == numN) {
						System.out.println("Yes");
						return;
					}
				}
			}
			System.out.println("No");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveC() {
		Scanner scanner = null;
		int numN = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			long wk = 0;
			StringBuilder builder = new StringBuilder();
			while (numN != 0) {
				if (numN % 2 != 0) {
					numN--;
					builder.append("1");
				} else {
					builder.append("0");
				}
				numN /= -2;
			}
			if (builder.length() == 0) {
				builder.append("0");
			}

			System.out.println(builder.reverse().toString());

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveD() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

Measured memory_bytes: 21844
from sys import stdin
def main():
    readline=stdin.readline
    X,Y,A,B,C=map(int,readline().split())
    p=list(map(int,readline().split()))
    q=list(map(int,readline().split()))
    r=list(map(int,readline().split()))

    p.sort(reverse=True)
    q.sort(reverse=True)
    r.sort(reverse=True)

    res=sum(p[:X])+sum(q[:Y])
    i=X-1
    j=Y-1
    k=0
    while True:
        if k==C:
            break
        if i!=-1 and j!=-1:
            if q[j]<=p[i]:
                if q[j]<r[k]:
                    res-=q[j]
                    res+=r[k]
                    j-=1
                    k+=1
                else:
                    break
            else:
                if p[i]<r[k]:
                    res-=p[i]
                    res+=r[k]
                    i-=1
                    k+=1
                else:
                    break
        elif i==-1:
            if q[j]<r[k]:
                res-=q[j]
                res+=r[k]
                j-=1
                k+=1
            else:
                break
        elif j==-1:
            if p[i]<r[k]:
                res-=p[i]
                res+=r[k]
                i-=1
                k+=1
            else:
                break
        else:
            break

    print(res)

if __name__=="__main__":
    main()

Measured memory_bytes: 92516
from collections import Counter
n = int(input())
d = list(map(int, input().split()))
cnt = Counter(d)
cnt = sorted(cnt.items(), key=lambda x:x[0])
val = 0
for idx, (i, v) in enumerate(cnt):
    val += v
    if val == n // 2:
        print(cnt[idx+1][0] - cnt[idx][0])
        exit()
    elif val > n // 2:
        print(0)
        exit()
    else:
        continue


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

using namespace std;

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

  int len;
  string train;
    vector<string> ans, tmp;
    for(int lp = 0; lp < m; lp ++) {
    cin >> train;
    len = train.size();
    ans.clear();

    for(int i = 1; i < len; i ++) {
      tmp.clear();
      
      string sub1 = train.substr(0, i);
      string sub2 = train.substr(i, len);
      
      string _sub1, _sub2;
      if(sub1.size() > 1) {
	for(int j = sub1.size()-1; j >= 0; j --) {
	  _sub1 += sub1[j];
	}
      }
      else {
	_sub1 = sub1;
      }
      if(sub2.size() > 1) {
	for(int j = sub2.size()-1; j >= 0; j --) {
	  _sub2 += sub2[j];
	}
      }
      else {
	_sub2 = sub2;
      }
      
      string a =  sub1 +  sub2;
      string b = _sub1 +  sub2;
      string c =  sub1 + _sub2;
      string d = _sub1 + _sub2;
      string e =  sub2 +  sub1;
      string f = _sub2 +  sub1;
      string g =  sub2 + _sub1;
      string h = _sub2 + _sub1;
      
      tmp.push_back(a);
      tmp.push_back(b);
      tmp.push_back(c);
      tmp.push_back(d);
      tmp.push_back(e);
      tmp.push_back(f);
      tmp.push_back(g);
      tmp.push_back(h);
      
      for(int j = 0; j < 8; j ++) {
	vector<string>::iterator it = ans.begin();
	int flg = 0;
	while(it != ans.end()) {
	  if(*it == tmp[j]) {
	    flg = 1;
	    break;
	  }
	  it ++;
	}
	if(!flg) {
	  ans.push_back(tmp[j]);
	}
      }
    }

    cout << ans.size() << endl;
  }
  return 0;
}

Measured memory_bytes: 1284
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
const int MOD = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < int(n); ++i)

//-------------------ここから回答する-----------------------

void solve(void)
{
    string s;
    cin >> s;
    int len = s.length();
    int l;
    rep(i, len)
    {
        if (s[i] == 'A')
        {
            l = i;
            break;
        }
    }
    int r;
    for (int i = len - 1; i >= 0; --i)
    {
        if (s[i] == 'Z')
        {
            r = i;
            break;
        }
    }
    cout << r - l + 1 << endl;
}
int main(void)
{
    solve();
}


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

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

int main() {
	int x;
	cin >> x;
	if (x == 0) {
		cout << 1 << endl;
	}
	else {
		cout << 0 << endl;
	}
}

Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		long N = scan.nextInt();
		long power = 1;
		long c = 1000000000 + 7;
		
		for(long i=1;i<=N;i++){
			power = i*power % c;
		}
		
		System.out.println(power);
	}

}


Measured memory_bytes: 21716
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <functional>


using namespace std;

int main() {
  long long n,k;
  cin>>n>>k;
  long long ans = 0;

    
  long long  max=0;
  for(long long i=n;i>n-k+1;i--){
    max+=i;
  }
  long long  min=0;
  for(long long i=0;i<k-1;i++){
    min+=i;
  }
  long long ko = max-min+1;
  
  for(long long  s = k;k<n+1;k++){
    ko += n + 2 - 2*k ;
      ans+=ko;
  }
  
  long long ss = (10*10*10*10*10*10*10*10*10 + 7);
  cout<<ans%ss + 1<<endl;

  return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
vl v;
ll nx(ll n) {
	if(n < 9) return n+1;
	n++;
	ll sm = 0;
	ll va = n;
	while(va) {
		sm += va%10;
		va /= 10;
	}
	ll ct = 0;
	while(sm < n+1) {
		ct++;
		sm += 9-(n%10);
		n /= 10;
	}
	for(int i=0;i<ct;i++) {
		n = n*10+9;
	}
	return n;
}
int main() {
	ll k;
	scanf("%lld",&k);
	ll ac = 1;
	for(int i=0;i<k;i++) {
		printf("%lld\n",ac);
		ac = nx(ac);
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;

int main()
{
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;

    int mx = tx-sx,my = ty-sy;
    for(int j = 0; j < 2; j++){
        for(int i = 0; i < my; i++) cout << 'U';
        for(int i = 0; i < mx; i++) cout << 'R';
        if(j%2) cout << "RDRD";
        for(int i = 0; i < my; i++) cout << 'D';
        for(int i = 0; i < mx; i++) cout << 'L';
        cout << "LU";
    }
    cout << endl;


    return 0;
}

Measured memory_bytes: 256
//  main.cpp
//  CppTest

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

int main(int argc, const char * argv[]) {
    
    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    /////////////////////
    // Write code below /
    /////////////////////
    vector<int>antennas(5);
    int limitDistance;
    for (int i = 0; i < antennas.size(); i++) cin >> antennas.at(i);
    cin >> limitDistance;
    
    if ( (antennas.at(4) - antennas.at(0)) > limitDistance ) {
        cout << ":(" << endl;
    } else {
        cout << "Yay!" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		//入力ここから
		int N = sc.nextInt();
		int iniN = N;

		List<Integer> DList = new ArrayList<Integer>();

		while (N > 0) {
			int D = N % 10;
			DList.add(D);
			N = N / 10;
		}

		int tmp = 0;
		for (int i = 0; i < DList.size(); i++) {
			tmp = tmp + DList.get(i);
		}

		if (iniN % tmp == 0) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}

	}
}



Measured memory_bytes: 23636
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

int main(){
    string s,t;
    cin>>s;
    cin>>t;
    int n=s.length();
    bool f=1;
    for(int i=0;i<n;i++){
        if(s[i]!=t[i]){
            f=0;
        }
    }
    if(f){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int n,m;
    cin >> n >> m;
    vector<bool> f(n+1);
    rep(i,0,m){
        int c,d;
        cin >> c >> d;
        rep(j,c,d) f[j]=true;
    }
    int ans=n+1;
    rep(i,0,n+1) if(f[i]) ans+=2;
    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}

Measured memory_bytes: 3216
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int main()
{
    int m, n;
    long ans;
    while(cin>>m>>n)
    {
        ans = 0;
        long temp1 = m <= 1 ? 0 : ((m * (m - 1)) / 2);
        long temp2 = n <= 1 ? 0 : ((n * (n - 1)) / 2);
        ans += temp1;
        ans += temp2;
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(x) x.begin(),x.end()

using namespace std;
typedef long long ll;

template<typename T>
T gcd(T a, T b) {
	if (a % b == 0) {
		return(b);
	}
	else {
		return(gcd(b, a % b));
	}
}


template<typename T>
T lcm(T a, T b) {
	return a / gcd(a, b) * b;
}

int main(void) {
	int x, n;
	cin >> x >> n;
	vector<int>p(n);
	rep(i, n) {
		cin >> p[i];
	}
	sort(ALL(p));
	for (auto i = p.begin(); i != p.end(); ++i) {
		if (x <= *i) {

		}
		for (int j = 0;; ++j) {
			auto index = find(ALL(p), x - j);
			if (index == p.end()) {
				cout << x - j;
				return 0;
			}
			index = find(ALL(p), x + j);
			if (index == p.end()) {
				cout << x + j;
				return 0;
			}

		}
	}
	cout << x;
}

/*  
4 5 6 7 10
    *
*/


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

string foundOneTimeChars(string S) {
	if (S.length() == 1) { return S; }
	int cnt = 0;
	char target;
	while (cnt < S.length()) {
		target = S[cnt];
		for (int i = cnt + 1; i < S.length();) {
			if (S[i] == target) {
				S.erase(i, 1);
			}else{
              i++;
            }
		}
		cnt++;
	}
	return S;
}

int main()
{
	int N;
	cin >> N;
	string S;
	cin >> S;
	int cnt, ans;
	ans = cnt = 0;
	char target;
	for (int i = 1; i < N; i++) {
		string front(S);
		front.erase(i);
		front = foundOneTimeChars(front);
		string latter(S);
		latter.erase(0, i);
		latter = foundOneTimeChars(latter);      
		for (int j = 0; j < front.length(); j++) {
          	if (front[j] == latter[0]){cnt++;}
          else if (latter.find(front[j])<latter.length()) { cnt++; }
		}
		if (ans < cnt) { ans = cnt; }
		cnt = 0;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    char s;
    cin >> s;

    if (isupper(s)){
        cout << "A" << endl;
    } else {
        cout << "a" << endl;
    }

    return 0;
}

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

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


int main()
{
    int N, Z, W;
    cin >> N >> Z >> W;
    vector<int> a(N);
    REP(i, N) cin >> a[i];

    // dp_min[i]: 後ろから i 番目を Y が引いたときの |X_Y| の最小値
    // dp_max[i]: 後ろから i 番目を X が引いたときの |X-Y| の最大値
    vector<int> dp_min(N+1), dp_max(N+1);
    dp_min[1] = 1e+9;
    dp_max[1] = abs(a[N-1]-W);
    FOR(i, 2, N+1){
        dp_min[i] = abs(a[N-i]-a[N-1]);
        dp_max[i] = abs(a[N-i]-a[N-1]);
        FOR(j, 1, i){
            dp_min[i] = max(dp_min[i], dp_max[j]);
            dp_max[i] = min(dp_max[i], dp_min[j]);
        }
    }
    cout << *max_element(dp_max.begin(), dp_max.end()) << endl;

    return 0;
}

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

#define MP make_pair
#define F first
#define S second
#define mid (be+en)/2
#define cl c*2
#define cr cl|1

using namespace std;

const int N = 1e6;
pair<long long int, long long int> p[N];
set<pair<pair<long long int, long long int>,long long int>>s;
long long int t[N], sum[N], laz[N];
long long int n, d, a;

void build(int be=0, int en=n, int c=1) {
    if(be+1==en) {
        sum[c]=p[be].S;
        return;
    }
    build(be,mid,cl);
    build(mid,en,cr);
    sum[c]=sum[cl]+sum[cr];
}

void relax(int c, int l, int r) {
    sum[c]+=(r-l)*laz[c];
    laz[cr]+=laz[c];
    laz[cl]+=laz[c];
    laz[c]=0;
}

long long int query(int l, int r, int be=0, int en=n, int c=1) {
    if(en<=l||r<=be)return 0;
    relax(c,be,en);
    if(l<=be&&en<=r) {
        return sum[c];
    }
    return query(l,r,be,mid,cl)+query(l,r,mid,en,cr);
}

void update(int l, int r, int val, int be=0, int en=n, int c=1) {
    if(en<=l||r<=be)return;
    relax(c,be,en);
    if(l<=be&&en<=r) {
        laz[c]+=val;
        return;
    }
    update(l,r,val,be,mid,cl);
    update(l,r,val,mid,en,cr);
    relax(cl,be,mid);
    relax(cr,mid,en);
    sum[c]=sum[cl]+sum[cr];
}

int main () {
    cin >> n >> d >> a;
    for(int i = 0 ; i < n ; i++ ) {
        cin >> p[i].F >> p[i].S;
    }
    sort(p,p+n);
    long long int p1=0, p2=1;
    while(p1<n) {
        //cout << p1 << ' '<< p2 << '\n';
        if(p2==n) {
            t[p1]=p2-p1-1;
            p1++;
        }
        else {
            if(p[p2].F-p[p1].F<=2*d) {
                p2++;
                continue;
            }
            else {
                t[p1]=p2-p1-1;
                p1++;
            }
        }
        while(p2<=p1)p2++;
    }
    build();
    long long int ans = 0;
    for(int i = 0 ; i < n ; i++ ) {
        long long int hea = query(i,i+1);
        if(hea<=0)continue;
        update(i,i+t[i]+1,-1*((hea+a-1)/a)*a);
        ans+=((hea+a-1)/a);
    }
    cout << ans;
}


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

int main(void){
    int N,A[200],count = 0,check = 0;
    cin >> N;
    for(int i = 0;i < N;i++)cin >> A[i];
    
    while( 1 ){
        for(int i = 0;i < N;i++){
            if(A[i] % 2 == 1){
                check += 1;
                break;
            }
            A[i] = A[i] / 2;
        }
        if(check > 0)break;
        count += 1;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
n = gets.to_i
a = gets.split(/\s+/).map(&:to_i)

a = a.sort.reverse

alice = 0
bob = 0

(0...n).each do |i|
  if i % 2 == 0
    alice += a[i]
  else
    bob += a[i]
  end
end

puts(alice - bob)

Measured memory_bytes: 1916
#include<stdio.h>
#include<math.h>

int A[500000], compare;

void merge(int left, int mid, int right){
  int n1 = mid - left, n2 = right - mid, L[n1 + 1], R[n2 + 1], i, j, k;
  for(i=0;i<n1;i++)
    L[i] = A[left + i];
  for(i=0;i<n2;i++)
    R[i] = A[mid + i];
  L[n1] = INFINITY;
  R[n2] = INFINITY;
  i = 0;
  j = 0;
  for(k=left;k<right;k++){
    if(L[i] <= R[j]){
      A[k] = L[i];
      i++;
    } else {
      A[k] = R[j];
      j++;
    }
  compare++;
  }
}

void mergeSort(int left, int right){
  int mid;
  if(left + 1 < right){
    mid = (left + right)/2;
    mergeSort(left, mid);
    mergeSort(mid, right);
    merge(left, mid, right);
  }
}

int main(void){
  int n, i;
  scanf("%d", &n);
  for(i=0;i<n;i++)
    scanf("%d", &A[i]);
  mergeSort(0, n);
  for(i=0;i<n-1;i++)
    printf("%d ", A[i]);
  printf("%d\n%d\n", A[n-1], compare);
  return 0;
}

Measured memory_bytes: 5624
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;


public class Main {
	
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
	

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
    public static long mod = (long) (1e9+7);
    public final static int MAX = (int)1e5;
  // static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
	   
	 FastReader sc = new FastReader();
	 int n = sc.nextInt();
	 int m = sc.nextInt();
	 List<Integer>[] edge = new ArrayList[MAX+1];
	 for(int i=0;i<edge.length;++i) edge[i] = new ArrayList<>();
	
	 TreeMap<Integer,Integer> map = new TreeMap<>();
	 for(int i=0;i<n;++i) {
		 int u = sc.nextInt();
		 int v = sc.nextInt();
		 edge[u].add(v);
		
	 }
	
	
	 long ans = 0;
	 for(int i=1;i<=m;++i) {
		for(int x : edge[i]) add(map,x);
		if(map.size() != 0) {
			ans+=map.lastKey();
			delete(map,map.lastKey());
		}
	 }
	
	 out.print(ans);
	 out.close();
		
	}
	

	private static void add(TreeMap<Integer, Integer> map, int i) {
		// TODO Auto-generated method stub
		if(map.containsKey(i)) map.put(i, map.get(i)+1);
		else map.put(i, 1);
		
	}
	private static void delete(TreeMap<Integer, Integer> map, int i) {
		if(map.containsKey(i)) {
			if(map.get(i) == 1) map.remove(i);
			else map.put(i, map.get(i)-1);
		}
		
	}
	
}

Measured memory_bytes: 52136
#include <iostream>
#include <cstdio>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i,k,n) for(int i=k;i<n;i++)
using namespace std;
int n;
string s[620] = {};

bool check(int X,int Y){
    rep(y,n){
        REP(x,y+1,n){
            if(s[y+Y][x+X]!=s[x+Y][y+X]) return false;
        }
    }
    return true;
}

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

    cin >> n;
    rep(i,n){
        cin >> s[i];
        s[i] += s[i];
    }
    rep(i,n){
        s[i+n] = s[i];
    }
    int ans = 0;
    rep(x,n){
        ans += check(x,0);
    }
    ans = ans * n;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define init(n) int n;cin>>n;int a[n];rep(i,n)cin>>a[i];
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll mod = 1e9+7;
int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    int T=1;
  
    // cin>>T;
    while(T--){
        int n;cin>>n;
        int ans=0;
        vector<int> v;
        vector<int> p(n);
        vector<int> q(n); 
        rep(i,n)v.pb(i+1);
        rep(i,n)cin>>p[i];
        rep(i,n)cin>>q[i];
        int a=1,b=1;
        int x=1;
        do{
            if(p==v){
            	// cout<<"s";
                a=x;
            }
            if(q==v){
                b=x;
            }
            x++;
        }
        while(next_permutation(all(v)));
        cout<<abs(a-b)<<endl;
    }
    return 0;   
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[200010];
struct edge{int to,cost;};
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
void init_fact(){
	kaijo[0]=1;
	for(int i=1;i<=200000;i++){
		kaijo[i]=kaijo[i-1]*i;
		kaijo[i]%=MOD;
	}
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	int memo=modpow(a,b/2);
	return memo*memo%MOD;
}
int comb(int a,int b){
	if(!kaijo[0])init_fact();
	return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int inv(int x){
	x=modpow(x,MOD-2);
	return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
double dist(double ax,double ay,double bx,double by){
	return sqrt((bx-ax)*(bx-ax)+(ay-by)*(ay-by));
}
int n;
vector<int>v;
int x[10],y[10],cnt;
double sum=0.;
signed main(){
	cin>>n;
	rep(i,n)cin>>x[i]>>y[i];
	rep(i,n)v.pb(i);
	do{
		for(int i=1;i<n;i++){
			int fr=v[i-1],to=v[i];
			sum+=dist(x[fr],y[fr],x[to],y[to]);
		}
		cnt++;
	}while(next_permutation(all(v)));
	printf("%.12lf\n",sum/cnt);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;



int main(){
    ll n,m; cin >> n >> m;
    vl v(n,0);
    ll a,b;
    rep(i,m){
        cin >> a >> b; a--; b--;
        v[a]++; v[b]++;
    }
    rep(i,n){
        if(v[i] % 2 == 1){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long int ll;

ll mod=1e9+7;

template<typename T>
map<T,ll> factorize(T x){
	map<T,ll> res;
	for(ll i=2;i*i<=x;i++){
		while(x%i==0){
			x/=i;
			res[i]++;
		}
	}
	if(x!=1) res[x]++;
	return res;
}

struct perm {
private:
	int sz;
	vector<long long> p, invp;
public:
	perm(int n) {
		sz = n + 1;
		p.resize(sz), invp.resize(sz);
		p[0] = 1;
		for(int i=1;i<=sz - 1;i++) {
			p[i] = p[i - 1] * i%mod;
		}
		invp[sz - 1] = 1;
		ll cop = mod - 2, x = p[sz - 1];
		while (cop) {
			if (cop % 2)invp[sz - 1] = invp[sz - 1] * x%mod;
			cop >>= 1; x = x * x % mod;
		}
		for(int i=sz-2;i>=0;i--) {
			invp[i] = invp[i + 1] * (i + 1) % mod;
		}
	}
	ll comb(ll x, ll y) {
		if (x < y || y < 0)return 0;
		ll ret = p[x];
		(ret *= invp[y]) %= mod;
		(ret *= invp[x - y]) %= mod;
		return ret;
	}
	ll combP(ll x, ll y) {
		if (x < y || y < 0)return 0;
		return p[x] * invp[x - y] % mod;
	}
};
perm p(1 << 18);

int main(){
	ll n,m; cin >> n >> m;
	auto x=factorize(m);
	ll ans=1;
	for(auto q:x){
		int k=q.second;
		ans*=p.comb(k+n-1,k);
		ans%=mod;
	}
	cout << ans << endl;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> A(n + 1), B(n + 1), C(n + 1), D(n + 1), E(n + 1);
    for (int i = 0; i < n; i++)
    {
        int m;
        cin >> m;
        A[m]++;
    }
    for (int i = 1; i <= n; i++)
    {
        B[A[i]]++;
    }
    for (int i = 1; i <= n; i++)
    {
        C[i] = C[i - 1] + i * B[i];
        D[i] = D[i - 1] + B[i];
    }
    for (int i = 1; i <= n; i++)
    {
        E[i] = (C[i] + (D[n] - D[i]) * i) / i;
    }
    for (int i = 1, j = n; i <= n; i++)
    {
        for (; j > 0; j--)
        {
            if (E[j] >= i)
            {
                cout << j << endl;
                break;
            }
        }
        if (j == 0)
        {
            cout << j << endl;
        }
    }
}


Measured memory_bytes: 6784
// D.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>

using namespace std;

typedef long long LL;

int main(int argc, char *argv[]) {
	LL n, ga, sa, ba, gb, sb, bb;
	cin >> n >> ga >> sa >> ba >> gb >> sb >> bb;
	for (int t = 0; t < 2; ++t) {
		vector<LL> dp(n + 1);
		iota(dp.begin(), dp.end(), 0);
		for (LL i = ga; i <= n; ++i) {
			dp[i] = max(dp[i], dp[i - ga] + gb);
		}
		for (LL i = sa; i <= n; ++i) {
			dp[i] = max(dp[i], dp[i - sa] + sb);
		}
		for (LL i = ba; i <= n; ++i) {
			dp[i] = max(dp[i], dp[i - ba] + bb);
		}
		n = *max_element(dp.begin(), dp.end());
		swap(ga, gb);
		swap(sa, sb);
		swap(ba, bb);
	}
	cout << n << endl;
	return 0;
}


Measured memory_bytes: 195584
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <climits>
#include <cmath>
#include <vector>
#include <string>
#include <queue>

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

using namespace std;

int H, W;
char s[51][51];
const int INF = 100000000;

//typedef pair<int, int> PII;

const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
int depth[51][51];

typedef pair<int, int> PII;

int bfs()
{
    queue<PII> Q;
    Q.push(make_pair(0, 0));
    depth[0][0] = 1;
    while (!Q.empty()) {
        PII q = Q.front(); Q.pop();
        REP(i, 4) {
            int nx = dx[i] + q.first;
            int ny = dy[i] + q.second;
            if (!(0<=nx && nx<H && 0<=ny && ny<W))
                continue;
            if (depth[nx][ny]!=INF)
                continue;
            if (nx==H-1 && ny==W-1)
                return depth[q.first][q.second] + 1;
            if (s[nx][ny]=='.') {
                depth[nx][ny] = depth[q.first][q.second] + 1;
                Q.push(make_pair(nx, ny));
            }
        }
    }
    return -1;
}

int main()
{
    scanf("%d %d", &H, &W);
    int num_b = 0;
    REP(i, H) {
        REP(j, W) {
            scanf(" %c ", &s[i][j]);
            if(s[i][j]=='#')
                num_b++;
        }
    }
    REP(i, H) {
        REP(j, W) {
            depth[i][j] = INF;
        }
    }

    int ans = bfs();
    if (ans==-1)
        cout << ans << endl;
    else
        cout << W*H-num_b-ans << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma optimize("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
// #include<iomanip>
using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pii;
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fo(i,a,b) for(ll i = a; i<=b;i+=1)
#define rf(i,a,b)  for(ll i=a;i>=b;i--)
#define vll vector<ll>
#define sz(a) ll(a.size())
#define all(v) v.begin(),v.end()
#define pb push_back
#define pf push_front 
#define MAXN 100010
#define N 100010
#define MOD 1000000007
#define mod 998244353
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define nl '\n'
#define MS(x,y) fill_n(*x, sizeof x / sizeof **x, y);
#define mem(x,y) memset(x,y,sizeof(x));
#define INF 1000000000000000000
#define IO                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);

template<int D, typename T>
struct Vec : public vector<Vec<D - 1, T>> {
static_assert(D >= 1, "Vector dimension must be greater than zero!");
template<typename... Args>
    Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {
    }
};
template<typename T>
struct Vec<1, T> : public vector<T> {
    Vec(int n = 0, const T& val = T()) : vector<T>(n, val) {
    }
};

ll modpower(ll x, ll y,ll p)
{
    ll res = 1;     // Initialize result
    x = x % p;
    if (y==0)return 1;
    if(x==0)return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1; // y = y/2
        x = (x*x) % p;  // Change x to x^2
    }
    return res;
}
ll power(ll x, ll y)
{
    ll res = 1;     // Initialize result
    x = x ;
    if (y==0)return 1;
    if(x==0)return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x);
        y = y>>1; // y = y/2
        x = (x*x);  // Change x to x^2
    }
    return res;
}
// int gcd(int a, int b) { if (a == 0)return b;return gcd(b % a, a);}

ll modinv(ll a,ll p){return modpower(a,p-2,p);}

const int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}, dy[8] = {0, 1, 0, -1, -1, 1, -1, 1};

long long safe_sqrt(long long n) {
    long long res = sqrt((long double) n);
    if (res*res == n) return res;
    const long double eps = 1e-8;
    if ((long double)(res+1)*(res+1) < n + eps) return res+1;
    if ((long double)res*res + eps > n) return res-1;
    return res;
}   
// (a+b-1)/b for ceil
void solve(){
    ll n;
    cin >> n;
    ll sum = 0;
    fo(i, 1, n){
        sum+=(i)*(n-i+1);
    }
    // deb(sum)
    fo(i, 1, n-1){
        ll u, v;
        cin >> u >> v;
        sum -= min(u, v)*(n-max(u, v)+1);
        // deb(sum)
    }
    cout<<sum<<nl;
    return ;
}
int main()
{
    IO;
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    // #endif
    int T = 1;
    // cin >> T;
    f(c, 0, T){
        solve();
    }
    return 0;
}//multiset m make_pair make_tuple  tuple<int,int,int> continue resize insert count size else true isValid second first false erase double priority_queue 
//cout<<setprecision(12); push_back pop_back pop_front push_front  lower_bound upper_bound  reverse

Measured memory_bytes: 3624
while True:
    n,m=map(int,raw_input().split())
    if n==m==0:break
    L=[0]*m
    Q=[map(int,raw_input().split()) for i in range(n)]
    for i in range(n):
        for j in range(m):
            L[j]-=Q[i][j]
    L=sorted([(L[i],i+1) for i in range(m)])
    print " ".join(map(str,[i[1] for i in L]))

Measured memory_bytes: 5540
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;cin>>n;
	int a[n],b[n],c[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i]>>b[i]>>c[i];
	}
	long int res[n][3];
	res[0][0]=a[0];
	res[0][1]=b[0];
	res[0][2]=c[0];
	for (int i = 1; i < n; ++i)
	{
		res[i][0]=a[i]+max(res[i-1][1],res[i-1][2]);
		res[i][1]=b[i]+max(res[i-1][0],res[i-1][2]);
		res[i][2]=c[i]+max(res[i-1][0],res[i-1][1]);
	}
	cout<<max(res[n-1][0],max(res[n-1][1],res[n-1][2]));
	return 0;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
#define L long long
using namespace std;
int n,x[200010],a[200010];
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j,k;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	  scanf("%d",&a[i]),x[a[i]]=i;
	for(i=1,j=0,k=0;i<=n;i++)
	  {
	   if(i==1 || x[i]>x[i-1])
	     j++;
	   else
	     j=1;
	   k=max(k,j);
      }
    printf("%d\n",n-k);
	return 0;
}


Measured memory_bytes: 1792
/**
*    created: 13.05.2020 18:04:07
**/
#include <bits/stdc++.h>
#define int long long
const int INF = 1e18L + 5;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int a, p; cin >> a >> p;
    cout << (3 * a + p) / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=100000+10;
long long x[N],a,b,n,f[N]={0},ans=0;
int main(){
	scanf("%ld%ld%ld",&n,&a,&b);
	for(int i=1;i<=n;i++)
		scanf("%ld",&x[i]);
	for(int i=1;i<=n-1;i++)
		f[i]+=min((x[i+1]-x[i])*a,b);
	for(int i=1;i<=n-1;i++)
	 ans+=f[i]; 
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1792
#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(){
  string s;
  cin >> s;
  if(s.at(0) == '7' || s.at(1) == '7' || s.at(2) == '7') cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3588
import java.util.Scanner;

public class Main {
    public static void main (String args[]) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        sc.close();

        if (n * a > b) {
            System.out.println(b);
        } else {
            System.out.println(n * a);
        }
    }
}


Measured memory_bytes: 23764
#include<stdio.h>
#include<vector>
#include<queue>
#include<algorithm>
#include<string.h>
#include<stack> 
#include<set>
#include<map>
#include<iostream>
#include <iomanip>
#include<assert.h>
#include<bits/stdc++.h>
//#define Min(a,b,c) min((a),min((b),(c)))
#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
#define pll pair<LL,LL>
#define pb(x) push_back(x)
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define EPS 1e-11
#define N 500005
#define pi 3.14159265359
typedef long long LL;
using namespace std;
const int mod = 1e9+7;
int main(){
	int n;
	scanf("%d",&n);
	int a[N];
	for(int i=0;i<n;i++)
	scanf("%d",&a[i]);
	LL temp=1,ans=1;
	for(int i=1;i<n;i++){
		temp++;
		if(temp>(a[i]+1)/2)
		{
			//printf("%lld %d\n",temp,a[i]);
			ans*=temp;
			ans%=mod;
			temp--;
		}
	}
	while(temp){
		ans=ans*temp%mod;
		temp--;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 640
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static long H;
	static long W;
	static long[] S= new long[3];

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

		H=scan.nextLong();
		W=scan.nextLong();

		long s=1000000;

		s=Math.min(s, minimum(true,H/3,true,H,W));
		s=Math.min(s, minimum(true,(H+1)/3,true,H,W));
		s=Math.min(s, minimum(true,(H+2)/3,true,H,W));
		s=Math.min(s, minimum(true,H/3,false,H,W));
		s=Math.min(s, minimum(true,(H+1)/3,false,H,W));
		s=Math.min(s, minimum(true,(H+2)/3,false,H,W));

		s=Math.min(s, minimum(false,W/3,true,H,W));
		s=Math.min(s, minimum(false,(W+1)/3,true,H,W));
		s=Math.min(s, minimum(false,(W+2)/3,true,H,W));
		s=Math.min(s, minimum(false,W/3,false,H,W));
		s=Math.min(s, minimum(false,(W+1)/3,false,H,W));
		s=Math.min(s, minimum(false,(W+2)/3,false,H,W));

		System.out.println(s);



	}

	static long minimum(boolean h,long X,boolean h2,long H,long W){


		if(h){
			S[0]=X*W;
			H-=X;
			if(h2){
				long H_=H/2;
				S[1]=W*(H_);
				H-=H_;
				S[2]=W*H;
			}else{
				long W_=W/2;
				S[1]=H*W_;
				W-=W_;
				S[2]=W*H;
			}


		}else{
			S[0]=X*H;
			W-=X;
			if(h2){
				long H_=H/2;
				S[1]=W*(H_);
				H-=H_;
				S[2]=W*H;
			}else{
				long W_=W/2;
				S[1]=H*W_;
				W-=W_;
				S[2]=W*H;
			}
		}

		Arrays.sort(S);
		return S[2]-S[0];


	}

}


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


int main(){
  int to;
  cin>>to;
  for(int oo=0;oo<to;oo++){
    int n;
    cin>>n;
    int h[n],ud,upmax=0,downmax=0;
    for(int i=0;i<n;i++){
      cin>>h[i];
    }
    for(int j=0;j<n-1;j++){
      if(h[j]>h[j+1]){
	ud=h[j]-h[j+1];
	if(downmax<ud){
	  downmax=ud;
	}
      }else if(h[j]<h[j+1]){
	ud=h[j+1]-h[j];
	if(upmax<ud){
	  upmax=ud;
	}
      }
    }
    cout<<upmax<<" "<<downmax<<endl;
  }

  return 0;
}

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

int main()
{
    ll n, ans=0;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;++i)
    cin>>a[i];
    for(int i=1;i<n;++i)
    {
        if(a[i]<a[i-1])
        {
            ans += (a[i-1]-a[i]);
            a[i] = a[i-1];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5176
#include "bits/stdc++.h"

#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define ffor(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
#define rep(i, n) ffor(i,0,n)
#define All(obj) (obj).begin(),(obj).end()
#define INF ((ll)1e9+7)
#define c(a) cout<<a<<"\n";
using namespace std;
const int N = 100005;



int main() {
	speed;
	cout << fixed << setprecision(6);
	/*start*/
	int a, b;
	cin >>a >> b;
	int ans = 0;
	if (a > 9 || b > 9) {
		ans = -1;
	}
	else {
		ans = a * b;
	}
	c(ans);
	ed;
	return 0;
}



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

int main() {
    char b;
    cin >> b;
    if(b=='A' || b=='T'){
        if(b=='A') b='T';
        else b='A';
    }else {
        if(b=='G') b='C';
        else b='G';
    }
    cout << b << endl;
    return 0;
}


Measured memory_bytes: 256
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll A[2][110];
    rep(i,0,2){
        rep(j,0,N){
            cin >> A[i][j];
        }
    }
    ll ans = 0;
    rep(i,0,N){
        ll res = 0;
        rep(j,0,i+1){
            res += A[0][j];
        }
        rep(j,i,N){
            res += A[1][j];
        }
        ans = max(ans, res);
    }
    print(ans);
    

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <limits>
#include <map>
#include <bitset>

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

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

vector< vector<int> > memo;

int gcd(int a, int b, int c) {
	int min_num = (a > b) ? b : a;
	if (min_num > c) min_num = c;
	while (min_num != 1) {
		if (a % min_num == 0 && b % min_num == 0 && c % min_num == 0) break;
		min_num--;
	}
	return min_num;
}

int gcd(int a, int b) {
	int m = (a < b) ? a : b;
	while (m != 1) {
		if (a % m == 0 && b % m == 0)break;
		m--;
	}
	return m;
}

int main() {
	int r;
	cin >> r;
	cout << 2 * r * acos(-1) << endl;

	return 0;
}


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

int main()
{
    int N,M;
    cin >> N >> M;
    int a,b;
    int c=0;
    int count[200001]={0};
    for(int i=0;i<M;i++){
        cin >> a >> b;
        if(a==1){
            count[b]++;
        }
        if(b==N){
            count[a]++;
        }
    }
    for(int t=0;t<N;t++){
        if(count[t]==2) {
            cout << "POSSIBLE" << endl;
            c=1;
        }
    }
    if(c==0){
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <cstring>
#include <sstream>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;

ll power(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) {
            res = res * a;
        }
        a = a * a;
        b >>= 1;
    }
    return res;
}

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

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
    int cnt = 0;
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cnt += (n - 1) / i;
    }
    cout << cnt << endl;
    return 0;
}







Measured memory_bytes: 3688
#include <stdio.h>

int main(void) {
	int N,K;
	scanf("%d%d",&N,&K);
	char S[N];
	scanf("%s",S);
	if(S[K-1]=='A'){
		S[K-1]='a';
	}
	if(S[K-1]=='B'){
		S[K-1]='b';
	}
	if(S[K-1]=='C'){
		S[K-1]='c';
	}
	printf("%s",S);
	return 0;
}


Measured memory_bytes: 128
n = gets.to_i

class Player
  attr_accessor :id, :battle_orders, :possible_game

  def initialize(id, battle_orders)
    @id = id
    @battle_orders = battle_orders
    @possible_game = true
  end

  def next_opponent_id
    battle_orders.first - 1
  end

  def battle
    battle_orders.shift
    self.possible_game = false
  end

  def finish?
    battle_orders.empty?
  end

  def reset
    self.possible_game = true
  end
end

players = []
n.times {|i| players << Player.new(i, gets.split.map(&:to_i))}

day = 0
gamed_players = []
while true
  day += 1
  candidate_players = []
  gamed_players.each {|gamed_player| candidate_players << gamed_player}
  gamed_players = []
  candidate_players = players if day == 1
  candidate_players.each do |player|
    next if player.finish?
    opponent_player = players[player.next_opponent_id]
    next if opponent_player.next_opponent_id != player.id || opponent_player.finish?
    game_pair = [player, opponent_player]
    if game_pair.all?(&:possible_game)
      game_pair.each do |player|
        player.battle
        gamed_players << player
      end
    end
  end
  break if gamed_players.empty?
  gamed_players.each(&:reset)
end

if players.all?(&:finish?)
  p day - 1
else
  p -1
end

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

#define SZ(x) ((int(x.size())))

typedef long long ll;
typedef long double ld;

using namespace std;

const int maxn = 210;
int ans, a[maxn], n;

int main()
{
    cin >> n;
    for (int i = 0; i < 2 * n; i++)
        cin >> a[i];
    sort (a, a + (2 * n));
    for (int i = 0; i < n; i++)
        ans += min (a[2 * i], a[2 * i + 1]);
    cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
using namespace std;
int main() {
    int n;
    cin >> n;
    string w;
    char c;
    set<string> s;
    bool flag=1;
    for(int i=0; i<n; i++) {
        cin >> w;
        if(i!=0 && c!=w.front()) flag=0;
        if(s.count(w)) flag=0;
        s.insert(w);
        c=w.back();
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), min = 1000, max = 0,result = 0;
		int[] a = new int[n];
		for(int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
			if(min > a[i]) min = a[i];
			if(max < a[i]) max = a[i];
		}
		result = max - min;
		System.out.print(result);

	}

}

Measured memory_bytes: 21332
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  // 2^18 = 262,144
  int N;
  cin >> N;
  map<int, int, greater<int>> ss;
  F0R(i, 1 << N) {
    int s;
    cin >> s;
    ss[s]++;
  }

  /*
  for (auto e : ss) {
    cout << e.first << ':' << e.second << newl;
  }
  return 0;
  //*/

  priority_queue<int> qu;
  qu.push(ss.begin()->first);
  
  if (!--ss.begin()->second) {
    ss.erase(ss.begin());
  }
  F0R(i, N) {
    priority_queue<int> qu2;
    while (qu.size()) {
      int q = qu.top();
      qu.pop();
      //debug(q);
      //debug(ss[si]);

      auto c = ss.begin();
      while (c->first >= q) {
        if (++c == ss.end()) {
          cout << "No";
          return 0;
        }
      }
      qu2.push(q);
      qu2.push(c->first);
      if (!--c->second) {
        ss.erase(c);
      }
    }
    qu = move(qu2);
  }
  cout << "Yes";
}
#endif


Measured memory_bytes: 14192