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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		sc.nextLine();
		Iterator<Integer> list = Arrays.asList(sc.nextLine().split(" "))
				.stream()
				.map(Integer::valueOf)
				.sorted(Comparator.reverseOrder())
				.iterator();
		int result = 0;
		for (int flagNegate = 1; list.hasNext(); flagNegate *= -1) {
			result += list.next() * flagNegate;
		}
		System.out.println(result);
	}
}

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

using namespace std;

const int MAXN = 1e6+5;
int tab[3][MAXN];
long long sum[MAXN];
int main()
{
  int n;
  cin >> n;
  for (int i = 0; i < 3; i++)
  {
    for (int j = 1; j <= n; j++)
    {
      cin >> tab[i][j];
    }
    sort(tab[i]+1, tab[i]+n+1);
    for (int j = 1; j <= n; j++)
    {
    //  cout << tab[i][j] << " ";
    }
    //cout << "\n";
  }

  long long res = 0;
  for (int i = 1; i <= n; i++)
  {
    int l = 1, r = n;
    while(r-l > 1)
    {
      int mid = (l+r)/2;
      if (tab[2][mid] <= tab[1][i]) l = mid;
      else r = mid;
    }
    if (tab[2][l] > tab[1][i]) sum[i] = n-l+1;
    else if (tab[2][r] > tab[1][i]) sum[i] = n-r+1;
    //cout << l << " " << r << " " << tab[1][i] << " " << sum[i] << "\n";
    sum[i] += sum[i-1];
  }

  for (int i = 1; i <= n; i++)
  {
    int l = 1, r = n;
    while (r-l > 1)
    {
      int mid = (l+r)/2;
      if (tab[1][mid] <= tab[0][i]) l = mid;
      else r = mid;
    }
    if (tab[1][l] > tab[0][i]) res += sum[n]-sum[l-1];
    else if (tab[1][r] > tab[0][i]) res += sum[n]-sum[r-1];
  }
  cout << res << "\n";
}


Measured memory_bytes: 9216
#include <stdio.h>

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

  int i;
  int is_left_swap = 0;
  int ans = 0;
  for(i=0;i<n;i++) {
    int pi;
    scanf("%d", &pi);
    if(pi == i + 1) {
      if(!is_left_swap) {
        ans++;
        is_left_swap = 1;
      } else {
        is_left_swap = 0;
      }
    } else {
      is_left_swap = 0;
    }
  }

  printf("%d", ans);

  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;
typedef long double ld;
int main(){
    ll n,m;cin>>n>>m;
    ll a,b;
    vector<vector<ll>> v(n+1);
    REP(i,m){
        cin>>a>>b;
        v[a].push_back(b);
    }
    ll from=1;
    string ans="IMPOSSIBLE";
    REP(i,SIZE(v[1])){
        ll to=v[1][i];
        if(find(ALL(v[to]),n)!=v[to].end()){
            ans="POSSIBLE";
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 11884
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T iabs(const T& x) { return max(x, -x); }
// #define abs gabs

int main() {
    int a, b;
    cin >> a >> b;
    int c = a + b;
    if (c >= 10) cout << "error" << endl;
    else cout << c << endl;
    return 0;
}

Measured memory_bytes: 888
//バブルソート 2015／4／15 h25i18 高木 博康
#include <iostream>
using namespace std;

int cnt = 0;

void BubbleSort(int S[], int N){ 
	bool flag;
	do{
		flag = false;
		for(int i = 0; i < N - 1; i++){
			if(S[i] > S[i + 1]){
				int tmp = S[i];
				S[i] = S[i + 1];
				S[i + 1] = tmp;
				cnt++;
				flag = true;
			}
		}
	}while(flag);
}

int main(){
	int n;
	cin >> n;
	int s[n];
	for(int i = 0; i < n; i++){
		cin >> s[i];
	}
	BubbleSort(s,n);
	for(int i = 0; i < n-1; i++){
		cout << s[i] << ' ';
	}
	cout <<s[n-1]<< endl << cnt << endl;
	return 0;
}


Measured memory_bytes: 1164
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <map>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;


int main() {

    ll N,A,B;
    cin >> N >> A >> B;
    ll ans = 0;
    
    ans = (N/(A+B))*A;
    if(N%(A+B)>A){
        ans += A;
    }else{
        ans += N%(A+B);
    }
    cout << ans << endl;
    return 0;
}

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

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

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

const int mod=1000000007;
void add(int&a,int b){
	a+=b;
	if(a>=mod)a-=mod;
}

const int S=19;
const int M=20;
int dp[1<<S];
int rest_pos[M],rest_val[M];

int main(){
	int n=read()-1,m=read(),k=read();
	REP(i,k){
		int a=read()-1,b=n-read(),c=read();
		rest_pos[a]+=(1<<b);
		rest_val[a]+=(c<<b);
	}
	REP(bit,1<<n)
		if((bit&rest_pos[0])==rest_val[0])
			dp[bit]=1;
	REP(i,m){
		if(i>0){
			REP(bit,(1<<n)-1)
				add(dp[bit|(bit+1)],dp[bit]);
			for(int j=0;j<n-1;j++){
				int w=1<<j;
				REP(bit,(1<<n)-w)if(bit&w)
					add(dp[(bit^w)|(bit+w)],dp[bit]);
			}
		}
		REP(bit,1<<n)
			if((bit&rest_pos[i])!=rest_val[i])
				dp[bit]=0;
	}
	int ans=0;
	REP(bit,1<<n)
		add(ans,dp[bit]);
	cout<<ans<<endl;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long a,b;
  cin>>a;
  b=0;
  vector<long long>vecA(2*a);
  for(long long i=0;i<a*2;i++){
    cin>>vecA.at(i);
  }
  for(int k=2*a-1;k>0;k-=2){
    long long c=vecA.at(k);
    long long d=vecA.at(k-1)+b;
    if(d%c==0){
    }
    else{
      b+=c-d%c;
    }
  }
  cout<<b<<endl;
}

Measured memory_bytes: 1792
n, m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
c = [list(map(int, input().split())) for i in range(m)]
for i in range(n):
  dist = []
  for k in range(m):
    dist.append(abs(a[i][0]-c[k][0])+abs(a[i][1]-c[k][1]))
  print(dist.index(min(dist))+1)

Measured memory_bytes: 3064
#include <math.h>
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <iostream>

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

using namespace std;

int main()
{
    int N,K;
    cin>>N>>K;
    vector<int> A(N);
    FOR(i, 0, N){
        cin >> A[i];
    }
    int ans = N;
    sort(A.begin(),A.end());
    vector<vector<bool>> D(N+1,vector<bool>(K,false));
    D[N][0] = true;
    FOR(j,0,N){
        int i = N - j - 1;
        D[i][0] = true;
        if (A[i]>=K){
            ans = i;
            continue;
        }
        else {
            FOR(k,0,K){
                if (D[i+1][k]){
                    if (K-A[i]<=k){
                        ans = i;
                    }
                    D[i][k] = true;
                    if (k+A[i]<K){
                        D[i][k + A[i]] = true;
                    }
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3584
// #include <bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <climits>
#include <complex>
#include <cstring>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
//#define dump(x) cerr << #x << "=" << (x) << endl;
using namespace std;
const int INF = (int)2e9 + 1;
const long long LINF = (long long)9e18 + 1;

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

  int N, K, Q, temp;
  cin >> N >> K >> Q;

  vector<int> point(N, K);
  for (int i = 0; i < Q; i++) {
    cin >> temp;
    point[--temp]++;
  }

  for (int i = 0; i < N; i++) {
    if (point[i] <= Q) {
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
    }
  }

  return 0;
}


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

#define ll long long
#define endl '\n'
#define REP(i, a, n) for(int i=a; i<n; ++i)
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const double PI = 3.141592653589793238460;
const ll mod = 1e9 + 7;

void FAST(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

int fact(int n){
    if(n == 0)
        return 1;
    return n * fact(n - 1);
}

double abc(ii a, ii b){
    double x = a.first - b.first;
    double y = a.second - b.second;
    return pow(x*x + y*y, 0.5);
}

int main(){
  FAST();
  int n;
  cin >> n;

  vii town(n);
  REP(i, 0, n){
      int x, y;
      cin >> x >> y;
      town[i] = {x, y};
  }
  sort(all(town));

  double dist = 0.0;
  do{
    REP(i, 1, n){
        dist += abc(town[i], town[i - 1]);
        //cout << town[i].first << " " << town[i].second <<endl;
    }
  }while(next_permutation(all(town)));

  cout << fixed << setprecision(10) << dist/fact(n) << endl;

  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
#define MOD 1000000007
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> p;
typedef vector<int> vi;
int a,b;
int ans=0;
string s,tmp;

int main(int argc,char const* argv[])
{
  cin >> a >> b;
  for(int i=a;i<=b;i++)
    {
      s=to_string(i);
      tmp="?????";
      for(int i=0;i<5;i++)
	{
	  tmp[i]=s[4-i];
	}
      if(s==tmp)
	{
	  ans++;
	}
    }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//CLOCKS_PER_SEC
#define se second
#define fi first
#define ll long long
#define Pii pair<int,int>
#define Pli pair<ll,int>
#define ull unsigned long long
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define fio ios::sync_with_stdio(false);cin.tie(0);
#define db double
#define mk make_pair
const double Pi=3.14159265;
const int N = 2e5+10;
const int M = 2e5+10;
const ull base=163;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
const db eps=1e-8;
const db pi=acos(-1);
using namespace std;
int n, m;
int head[N], to[N], nx[N];
int tot = 0;
priority_queue<pair<int,Pii> , vector< pair<int,Pii> >, greater<pair<int,Pii> > > q;
void add(int u, int v){
    to[tot] = v;
    nx[tot] = head[u];
    head[u] = tot++;
}
int dis[N][4];
bool vis[N][4];
int s, t;

void work(){
    memset(dis, 0x3f, sizeof(dis));
    dis[s][0] = 0;
    q.push({0,{s, 0}});
    while(!q.empty()){
        pair<int,Pii> p = q.top(); q.pop();
        if(vis[p.se.fi][p.se.se])continue;
        vis[p.se.fi][p.se.se] = 1;
        int u = p.se.fi;
        for(int i = head[u]; ~i; i = nx[i]){
            int v = to[i];
            int x = p.se.se+1;
            if(x == 4) x = 1;
            if(dis[v][x] > dis[u][p.se.se] +1){
                dis[v][x] = dis[u][p.se.se] + 1;
                q.push({dis[v][x], {v, x}});
            }
        }
    }
  //  cout<<dis[1][1]<<endl;
}
int main(){
    memset(head, -1, sizeof(head));
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= m; ++i){
        int u, v;
        scanf("%d%d", &u, &v);
        add(u, v);
    }
    scanf("%d%d", &s, &t);
    work();
    if(dis[t][3] == INF){
        dis[t][3] = -1;
    }
    else dis[t][3] /= 3;
    printf("%d\n", dis[t][3]);
    return 0;
}


Measured memory_bytes: 6652
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############
N = inputI()
P = inputIL()

memo = []
for i in range(1,N+1):
  if P[i-1] != i:
    memo.append((P[i-1],i))
    
if len(memo) == 0:
  print("YES")
  exit()
if len(memo) == 2:
  if memo[0][0] == memo[1][1]:
    print("YES")
    exit()
print("NO")
  


Measured memory_bytes: 63988
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int cnt=0,l;
    string s,t;
    cin>>s>>t;
    l=s.length();
    for(int i=0;i<l;i++){
        if(s[i]!=t[i]){
            cnt++;
        }
    }
    cout<<cnt<<'\n';
}


Measured memory_bytes: 3920
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<ll> p(51), b(51);

ll f(ll n, ll x) {
	if (n >= x)
		return 0;
	if (n == 0) {
		return 1;
	}
	if (x <= 1 + b[n-1])
		return f(n-1, x-1);
	if (x == (2 + b[n-1]))
		return p[n-1] + 1;
	if (x <= 2 + 2 * b[n-1])
		return p[n-1] + 1 + f(n-1, x-2-b[n-1]);
	return 2 * p[n-1] + 1;
}

int main() {
	ll n; cin >> n;
	ll x; cin >> x;
	p[0] = b[0] = 1;
	for (int i = 0; i < 50; i++) {
		b[i+1] = b[i] * 2 + 3;
		p[i+1] = p[i] * 2 + 1;
	}
	cout << f(n, x) << '\n';
	return 0;
}


Measured memory_bytes: 3608
// atcoder/abc054/B/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, m;
  while (cin >> n >> m) {
    char a[n][n];
    char b[m][m];
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        cin >> a[i][j];
      }
    }
    for (int i = 0; i < m; ++i) {
      for (int j = 0; j < m; ++j) {
        cin >> b[i][j];
      }
    }
    bool f = false;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        int cnt = 0;
        for (int p = 0; i + p < n && p < m; ++p) {
          for (int q = 0; j + q < n && q < m; ++q) {
            cnt += (a[i + p][j + q] == b[p][q]);
          }
        }
        f = f || (cnt == m * m);
      }
    }
    cout << (f ? "Yes" : "No") << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        String s = scanner.next();
        String t = scanner.next();
        
        for (int i=0;i<n;i++){
            System.out.print(s.substring(i,i+1));
            System.out.print(t.substring(i,i+1));
        }
    }
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e5;
const int MAXM = 1e5;

int N, M;
vector<int> adj[MAXN+10];
int indeg[MAXN+10], dp[MAXN+10], ans;

int main()
{
    int i, j;

    scanf("%d%d", &N, &M);
    for(i=1; i<=M; i++)
    {
        int u, v;
        scanf("%d%d", &u, &v);
        adj[u].push_back(v);
        indeg[v]++;
    }

    queue<int> Q;
    for(i=1; i<=N; i++) if(indeg[i]==0) Q.push(i), dp[i]=-1;

    while(!Q.empty())
    {
        int now=Q.front(); Q.pop();
        dp[now]++; ans=max(ans, dp[now]);

        for(int nxt : adj[now])
        {
            dp[nxt]=max(dp[nxt], dp[now]);
            indeg[nxt]--;
            if(indeg[nxt]==0) Q.push(nxt);
        }
    }
    printf("%d", ans);
}


Measured memory_bytes: 6528
from operator import itemgetter
n=int(input())
li=[]
x=[0,0]
for i in range(n):
  a, b = list(map(int, input().split()))
  li.append([a,b,a+b])

li.sort(reverse=True, key=itemgetter(2))
for i in range(n):
  x[i % 2] += li[i][i % 2]

print(x[0]-x[1])


Measured memory_bytes: 24872
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int X = getint(), Y = getint(), A = getint(), B = getint(), C = getint();

	int abc[300000];
	auto a = abc;
	auto b = abc + A;
	auto c = abc + A + B;

	rep(i, A + B + C) a[i] = getint();

	nth_element(a, b - X, b);
	nth_element(b, c - Y, c);
	if (B - Y) for (auto i = b - 1; i >= b - X; i--) *(i + B - Y) = *i;
	nth_element(c - X - Y, c + C - X - Y, c + C);

	ll kotae = 0;
	for (auto kari = c + C - X - Y; kari < c + C; kari++) kotae += *kari;

	printf("%lld", kotae);

	Would you please return 0;
}

Measured memory_bytes: 1408
using System;
					
public class Beaulo
{
  　public static int[] a = new int[32] {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    
	public static void Main()
	{
        int k = int.Parse(Console.ReadLine());
		Console.WriteLine(a[k-1]);
	}
}

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

int keta(int x) {
  int num = 0;
  while (x > 0) {
    x /= 10;
    num++;
  }
  return num;
}

int main() {
  int n;
  cin >> n;
  int cnt = 0;
  for (int i = 1; i<n+1; i++) {
    int num = keta(i);
    if (num % 2 != 0) cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    int x,a,b;
    cin >> x >> a >> b;
    if(abs(a-x)>abs(b-x)){
        cout << "B" << endl;
    }else{
        cout << "A" << endl;
    }
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int main(){
    long long k,a,b,ans=1LL,l,r,mid;
    scanf("%lld %lld %lld",&k,&a,&b);
    if(b<=a+2||k<=a-3){
        printf("%lld\n",k+1);
        return 0;
    }
    ans=a;
    if((k-a+1)%2){
        ans++;
    }
    printf("%lld\n",ans+(b-a)*(k-ans+1)/2);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef vector< pii > vii;

#define ll          long long
#define ff          first
#define ss          second
#define pb          push_back
#define mkp         make_pair
#define sz          size()

#define forf(a,b,c)    for(int i=a;i<=b;i+=c)
#define forr(a,b,c)    for(int i=a;i>=b;i-=c)
#define all(a)      a.begin(),a.end()
#define mem(a,b)    memset(a,b,sizeof(a))
#define pi          2*acos(0.0)
#define End         return 0;
#define nl endl

#define scan1(a)    scanf("%d",&a)
#define scan2(a,b)  scanf("%d %d",&a,&b)
#define scan3(a,b,c)  scanf("%d %d %d",&a,&b,&c)
#define scanl(a)    scanf("%lld",&a)
#define scanll(a,b) scanf("%lld %lld",&a,&b)
#define scanlll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)

#define print1(a)    printf("%d",a)
#define print2(a,b)  printf("%d %d",a,b)
#define print3(a,b,c)  printf("%d %d %d",a,b,c)
#define printl(a)    printf("%lld",a)
#define printll(a,b) printf("%lld %lld",a,b)
#define printlll(a,b,c) printf("%lld %lld %lld",a,b,c)

#define MAXN        100000007
#define INF 0x3f3f3f3f
bool mark[100005];vi prime;
void seive(ll N){for(int i=2;i<=N;i++){if(mark[i]==false){prime.pb(i);for(int j=i+i;j<N;j+=i)mark[j]=true;}}}
//freopen("input.txt", "r", stdin);

int main()
{
   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
   int a,b,c;
   cin>>a>>b>>c;
   a-=b;
   cout<<abs(c-min(a,c))<<endl;
   End;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i =0;i<(int)(n);i++)
#define endl '\n'
typedef pair<int,int> P;
typedef long long ll;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int x;
    cin >> x;
    cout << 10- x/200 << endl;
}

Measured memory_bytes: 3608
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int A, B, n, m;
long long D[3010][3010], Mod = 998244353, po1[3010], po2[3010];
long long Pow(long long a, long long b){
    long long r=1;
    while(b){
        if(b&1)r=r*a%Mod;
        b>>=1;a=a*a%Mod;
    }
    return r;
}
int main(){
    int i, j;
    scanf("%d%d%d%d",&A,&B,&n,&m);
    D[A][B]=1;
    for(i=A;i<=n;i++){
        long long t = Pow(i-1,Mod-2);
        po1[0]=po2[0]=1;
        for(j=1;j<=m;j++){
            po1[j]=po1[j-1]*(i-1)%Mod;
            po2[j]=po2[j-1]*t%Mod;
        }
        long long s=0;
        for(j=B;j<=m;j++){
            if(i==A&&j==B)continue;
            D[i][j]=(D[i-1][j]*j+s*po1[j])%Mod;
            s=(s+D[i-1][j]*po2[j])%Mod;
        }
    }
    long long res=0;
    for(i=B;i<=m;i++){
        res+=D[n][i]*Pow(n,m-i)%Mod;
    }
    printf("%lld\n",res%Mod);
}


Measured memory_bytes: 72280
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
  cin >> s;
  if(s=="SSS")
    cout<<0;
  else if(s=="RRR")
    cout<<3;
  else if(s=="SRR" || s=="RRS")
    cout<<2;
  else
    cout<<1;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int main(){
    int H,W;
    cin >> H >> W ;

   vector<vector<char>> data(H, vector<char>(W));
   for (int i = 0; i < H; i++) {
       for (int j = 0; j < W; j++) {
           cin >> data.at(i).at(j);
        }
   }

   vector<bool> row(H,false);
   vector<bool> col(W,false);

   for (int i = 0; i < H; i++) {
       for (int j = 0; j < W; j++) {
           if (data.at(i).at(j)=='#'){
               row.at(i) = true;
               break;
           }
        }
   }

   for (int j = 0; j < W; j++){
       for (int i = 0; i < H; i++){
           if (data.at(i).at(j)=='#'){
               col.at(j) = true;
               break;
           }
        }
   }

   for (int i = 0; i < H; i++) {
       if(row.at(i)){
           for (int j = 0; j < W; j++) {
           if(col.at(j)){
               cout << data.at(i).at(j);
           }
        }
        cout << endl;
       }
   }
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var nx = Input.ar;
        var ar = Input.ar;
        var res = 0L;
        for(var i=0;i<nx[0];i++)
            if (ar[i] > nx[1])
            {
                res += ar[i] - nx[1];
                ar[i] = nx[1];
            }
        for(var i = 0; i < nx[0]-1; i++)
        {
            var dif= ar[i] + ar[i + 1] - nx[1];
            if (dif>0)
            {
                res += dif;
                ar[i + 1] -= dif;
            }
        }
        WriteLine(res);
    }
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public  static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


Measured memory_bytes: 25052
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#define VIZ2 {printf("graph G{\n"); for(int i=1;i<=n;i++) for es(i,e) if(vb[e]>=i)printf("%d--%d;\n",i,vb[e]); puts("}");}
#define SZ 666666
map<string,int> tmp;
//int cc=0;
//#define edg(a,b) ((abs((a)-(b))==1))
int ask(string s)
{
	int r=0;
	for(int i=0;i<s.size();i++) r+=(s[i]=='1');
	if(r<=1) return 0;
	if(tmp.count(s)) return tmp[s];
	/*
	++cc; vi rp;
	for(int i=0;i<s.size();i++)
		if(s[i]=='1') rp.pb(i);
	if(rp.size()==2)
	return tmp[s]=edg(rp[0],rp[1]);
	if(rp.size()!=3) throw "RE";
	bool a=edg(rp[0],rp[1]),b=edg(rp[0],rp[2]),
	c=edg(rp[1],rp[2]);
	return tmp[s]=a+b+c;*/
	cout<<"? "<<s<<endl;
	int x; cin>>x; return tmp[s]=x;
}
int n,ff[SZ]; vector<int> vs[SZ],rs;
int gf(int x) {return ff[x]?ff[x]=gf(ff[x]):x;}
void uni(int a,int b)
{int ga=gf(a),gb=gf(b);if(ga^gb)ff[ga]=gb;}
int cnt()
{
	int ans=0; rs.clear();
	for(int i=1;i<=n;i++) vs[i].clear();
	for(int i=1;i<=n;i++)
	{
		vs[gf(i)].pb(i);
		if(gf(i)==i);else continue;
		++ans; rs.pb(i);
	}
	random_shuffle(rs.begin(),rs.end());
	for(int i=1;i<=n;i++)
		random_shuffle(vs[i].begin(),vs[i].end());
	return ans;
}
const int B=11;
vector<pii> es;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++) vs[i].pb(i);
	for(int i=2;i<=n;i++)
	{
		for(int j=1;j<i;j+=B)
		{
			string s; s.resize(n);
			for(int i=0;i<n;i++) s[i]='0';
			for(int k=0;k<B&&j+k<i;++k) s[j+k-1]='1';
			int a=ask(s); s[i-1]='1';
			int b=ask(s);
			if(a==b) continue;
			for(int k=0;k<B&&j+k<i;++k)
			{
				for(int i=0;i<n;i++) s[i]='0';
				s[j+k-1]=s[i-1]='1';
				if(ask(s)==1)
					es.pb(pii(j+k,i));
			}
		}
	}
	cout<<"!";
	for(auto r:es) printf(" (%d,%d)",r.fi-1,r.se-1);
	puts("");
	//cerr<<cc<<"\n";
}


Measured memory_bytes: 18512
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
vector<int>v;
signed main(){
	int n;
	int a[114514];
	int b[114514];
	int ans=0;
	cin>>n;
	int cnt=0;
	rep(i,n)cin>>a[i];
	rep(i,n){
		cin>>b[i];
		if(a[i]<b[i]){
			cnt+=b[i]-a[i];
			ans++;
		}
		else v.push_back(a[i]-b[i]);
	}
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());
	if(cnt<=0){
			cout<<ans<<endl;
			return 0;
	}
	rep(i,v.size()){
		cnt-=v[i];
		ans++;
		if(cnt<=0){
			cout<<ans<<endl;
			return 0;
		}
	}
	puts("-1");
	return 0;
}


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

int main(){
    unsigned long N, M;
    cin >> N >> M;
    class union_find{
        vector<long> parent, tree_size;
    public:
        union_find(unsigned long _n) : parent(_n), tree_size(_n, 1){
            for(unsigned long i = 0; i < _n; ++i){
                parent[i] = i;
            }
        }
        long find(long x){
            while(parent[x] != x){
                parent[x] = parent[parent[x]];
                x = parent[x];
            }
            return x;
        }
        bool marge(long a, long b){
            a = find(a);
            b = find(b);
            if(a == b)return false;
            if(tree_size[a] < tree_size[b])swap(a, b);
            tree_size[a] += tree_size[b];
            parent[b] = a;
            return true;
        }
    } uf{N};
    unsigned long ans{N};
    for(unsigned long i = 0, a, b, c; i < M; ++i){
        cin >> a >> b >> c;
        ans -= uf.marge(a - 1, b - 1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
import java.io.*;

public class Main {

    public static void main(String[] args) throws Exception {
        BufferedReader stdReader = new BufferedReader(new InputStreamReader(System.in));
        String c = stdReader.readLine();
        String vals = stdReader.readLine();
        
        long[] ls = new long[Integer.valueOf(c)];
        String[] ss = vals.split(" ");

        long total = 0;

        long[] sunu = new long[Integer.valueOf(c)];
        for (int i = 0; i < ls.length ;i++) {
            long v = Long.valueOf(ss[i]);
            ls[i] = v;

            total += v;
            sunu[i] = total;
        }

        long min = 0;
        for (int i = 0; i < ls.length - 1; i++) {
            long arai = total - sunu[i];

            long current = Math.abs(arai - sunu[i]);
            if (i == 0) {
                min = current;
            }
            
            //System.out.println(i + ":" + arai + "," + sunu[i] + "::" + current + "," + min);

            min = Math.min(min, current);
        }

        System.out.println(min);

    }

}


Measured memory_bytes: 63924
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long 
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 2000000009
#define mod 1000000007
#define ld long double
using namespace std;

int main()
{ 

    fast;

    ll h,w,n;
    cin>>h>>w>>n;

    ll x=max(h,w);

    ll ans=n/x;

    if(n%x)
      ans++;
    cout<<ans<<endl;



}

Measured memory_bytes: 256
def LD(str1,str2):
    A = [j for j in range(+len(str2)+1)]
    for i in range(len(str1)):
        A_copy = A[:]
        A[0] = i+1
        for j in range(len(str2)):
            if(str1[i]==str2[j]):
                cost = 0
            else:
                cost = 1
            A[j+1] = min(A[j]+1,A[j+1]+1,A_copy[j]+cost)
    print(A[-1])

str1 = input()
str2 = input()
LD(str1,str2)


Measured memory_bytes: 5588
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
using namespace std;
//cout << fixed << setprecision(0)
int main() { 
  int n;string s;cin >> n >> s;
  /*int er[300000],wr[300000];
  int esum,wsum;
  rep(i,n){
    if(s[i]=='E')esum++;
    else wsum++;
    er[i] = esum;wr[i] = wsum;
  }*/
  int ans=0,num=0;
  repd(i,1,n)if(s[i]=='E'){ans++;num++;}
  repd(i,1,n){
    if(s[i-1]=='W')num++;
    if(s[i]=='E')num--;
    ans = min(ans,num);
  }
  cout << ans << endl;
}


Measured memory_bytes: 900
n = input()
op_cnt = len(n) - 1  # すき間の個数
for i in range(2 ** op_cnt):
    op = ["-"] * op_cnt  # あらかじめ ["-", "-", "-"] というリストを作っておく
    for j in range(op_cnt):
        if ((i >> j) & 1):
            op[op_cnt - 1 - j] = "+"  # フラグが立っていた箇所を "+" で上書き

    formula = ""
    for p_n, p_o in zip(n, op + [""]):  # 少々モヤッとする
        formula += (p_n + p_o)
    if eval(formula) == 7:
        print(formula + "=7")
        break

Measured memory_bytes: 9092
# -*- coding: utf-8 -*-

n, k = map(int, input().split())
nums = input().split()

pay = n
disLike = True

while disLike:
    disLike = False
    for j in range(len(str(pay))):
        if str(pay)[j] in nums:
            disLike = True
            pay += 1

print(pay)


Measured memory_bytes: 3316
import java.util.Scanner;

public class Main {

	private static final long MOD = (long) Math.pow(10, 9) + 7;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] A = new int[N];
		for(int i = 0;i < N;i++) {
			A[i] = sc.nextInt();
		}
		sc.close();
		long cnt1 = 0;
		for(int i = 0;i < N;i++) {
			for(int j = i+1;j < N;j++) {
				if(A[i] > A[j]) {
					cnt1++;
				}
			}
		}
		long cnt2 = 0;
		for(int i = 0;i < N;i++) {
			for(int j = 0;j < N;j++) {
				if(A[i] > A[j]) {
					cnt2++;
				}
			}
		}
		long sum2 = ((cnt2%MOD) * ((((long)K * (long)(K-1))/2)%MOD));
		long sum = ((cnt1*K) %MOD+sum2)%MOD;
		System.out.println(sum);
	}
}

Measured memory_bytes: 26168
#include <stdio.h>

int main(void)
{
	int a, b;
	int sum;
	int i;
	
	while (scanf("%d %d", &a, &b) != EOF){
		sum = a + b;
		i = 0;
		while (sum != 0){
			sum /= 10;
			i++;
		}
		printf("%d\n", i);
	}
	
	return (0);
}

Measured memory_bytes: 600
#include <stdio.h>
#include <math.h>
#include <stdbool.h>
#define N 10000

bool isprime(int n){
  int i;

  if(n == 2) return true;

  if(n < 2 || n%2 == 0) return false;

  i = 3;
  while(i <= sqrt(n)){
    if(n%i == 0) return false;
    i = i+2;
  }

  return true;
}

int main(){
  int num[N];
  int i,n,p=0;

  scanf("%d",&n);

  for(i = 0; i < n; i++) scanf("%d",&num[i]);

  for(i = 0; i < n; i++){
    if(isprime(num[i]) == true) p++;
    else continue;
  }

  printf("%d\n",p);

  return 0;
}




Measured memory_bytes: 2680
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

// MLE
public class Main{
	Scanner sc=new Scanner(System.in);

	int n, k;
	long x0;

	void run(){
		n=sc.nextInt();
		k=sc.nextInt()-1;
		x0=sc.nextLong();
		solve();
	}

	void solve(){
		if(x0==0){
			println("0");
			return;
		}

		long x=x0;
		int s=(int)1e4;
		int[] count=new int[s];
		double offset=pow(2, 63), M=s/pow(2, 64);
		for(int i=0; i<n; i++){
			int at=(int)((x+offset)*M);
			if(at<0){
				at=0;
			}
			if(at>=s){
				at=s-1;
			}
			count[at]++;
			x^=x<<13;
			x^=x>>>7;
			x^=x<<17;
		}

		int sum=0, length=-1, target=-1;
		for(int i=0; i<s; i++){
			if(sum<=k&&k<sum+count[i]){
				target=i;
				length=count[i];
				break;
			}
			sum+=count[i];
		}

		int now=0;
		long[] is=new long[length];
		x=x0;
		for(int i=0; i<n; i++){
			int at=(int)((x+offset)*M);
			if(at<0){
				at=0;
			}
			if(at>=s){
				at=s-1;
			}
			if(at==target){
				is[now++]=x;
			}
			x^=x<<13;
			x^=x>>>7;
			x^=x<<17;
		}
		sort(is);
		println(is[k-sum]+"");
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

Measured memory_bytes: 21808
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

bool ok(vvi &cards) {
	bool flag = true;

	REP(i, 3) {
		if(cards[i*3][1] == cards[i*3+1][1] && cards[i*3+1][1] == cards[i*3+2][1]) {
			if(cards[i*3][0] == cards[i*3+1][0] && cards[i*3+1][0] == cards[i*3+2][0]) {
							
			} else if(cards[i*3][0] == cards[i*3+1][0]-1 && cards[i*3+1][0] == cards[i*3+2][0]-1) {

			} else {
				flag = false;
				break;
			}
		} else {
			flag = false;
			break;
		}
	}

	return flag;
}

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

	REP(szg, T) {
		vvi cards(9, vi(2));

		REP(i, 9) {
			cin >> cards[i][0];
		}
		char c;
		REP(i, 9) {
			cin >> c;
			cards[i][1] = c;
		}
		
		sort(ALL(cards));

		do {
			if(ok(cards)) {
				cout << 1 << endl;
				goto next;
			}
		} while(next_permutation(ALL(cards)));

		cout << 0 << endl;
next:
		;
	}

	return 0;
}

Measured memory_bytes: 1220
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.container;
import std.bigint;
import std.math;
import std.datetime;

void main()
{
	int[] a;
	auto week = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
	while (a = readln.split.map!(to!int).array, a[0]) {
		week[Date(2004, a[0], a[1]).dayOfWeek].writeln;
	}
}

Measured memory_bytes: 1224
#include <stdio.h>
#include <stdlib.h>

int compare_int(const void *a, const void *b) {
    return *(int*)a - *(int*)b;
}

int attack2HP(int N, int min, int *HP) {
	int counter=0;
	int more_min[N];
	for (int i = 1; i < N; i++) {
	int remainder,devided=HP[i];
	remainder = devided % min;
	if (remainder < min && remainder != 0) {
		more_min[counter] = remainder;
		counter++;
		}
	}
	if (counter == 0) return min;
	else {
		more_min[counter] = min;
		qsort(more_min, counter, sizeof(int), compare_int);
		int next=more_min[0];
		if (next == 1) return 1;
		attack2HP(counter+1, next, more_min);
	}
}

int main() {
	int N;
	scanf("%d",&N);
	int HP[N];
	for (int i = 0; i < N; i++) {
		scanf("%d",&HP[i]);
	}
	qsort(HP, N, sizeof(int), compare_int);
	int min=HP[0],answer;
	answer = attack2HP(N, min, HP);
	printf("%d\n",answer);
	return 0;
}

Measured memory_bytes: 1268
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  while(1){
    cin>>n;
    if(n==-1)break;
    if(n==0){
      cout<<0<<endl;
      continue;
    }
    vi a;
    while(n){
      a.push_back(n%4);
      n/=4;
    }
    for(i=a.size()-1;i>=0;i--)
      cout<<a[i];
    cout<<endl;
  }
}

Measured memory_bytes: 3080
#include <stdio.h>

int main()
{
  int i;
  int in;
  int N;
  
  scanf("%d",&N);
  int bango[N+1];
  
  for(i=0;i<N;i++){
    scanf("%d",&in);
    bango[in] = i+1;
  }

  for(i=0;i<N;i++){
    printf("%d ",bango[i+1]);
  }
  printf("\n");

  return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <set>
#include <stack>
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;
string convertInt(int number)
{
    if (number == 0)
        return "0";
    string temp = "";
    string returnvalue = "";
    while (number > 0)
    {
        temp += number % 10 + 48;
        number /= 10;
    }
    for (int i = 0; i < temp.length(); i++)
        returnvalue += temp[temp.length() - i - 1];
    return returnvalue;
}
const int eps = 1e-7;


vector<int>v(1e7);
int main() {

    fast

        int a, b, c;
    cin >> a >> b >> c;
    if (a == b && b != c)cout << "Yes" << endl;
    else if (a == c && b != c)cout << "Yes" << endl;
    else if (c == b && b != a)cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

#define int                                       long long
#define lop(i,s,e)                                for(int i=s;i<(int)e;i++)
#define rlop(i,e,s)                               for(int i=e;i>=s;i--)
#define prvec(v)                                  lop(R15,0,v.size())cout << v[R15] <<" "; cout << endl;
#define prarr(arr,s1,e1)                          lop(R15,s1,e1)cout << arr[R15] << " "; cout << endl;

#define endl                                      '\n'
#define ff                                        first
#define ss                                        second
#define pii                                       pair<int,int>

#define pb                                        push_back
#define all(v)                                    v.begin(),v.end()

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

const int N = 3e6 + 7, M = 1000000007, inf = INT_MAX;
const long long INF = LLONG_MAX;

int n, Q;
int arr[N + 2], freq[N];


void solve()
{
	cin >> n;
	int sum = 0;
	lop(i, 0, n)
	{
		int x; cin >> x;
		sum += x;
		freq[x]++;
	}

	cin >> Q;
	while (Q--)
	{
		int b, c; cin >> b >> c;
		sum -= freq[b] * b;
		sum -= freq[c] * c;
		freq[c] += freq[b];
		freq[b] = 0;
		sum += freq[c] * c;
		cout << sum << endl;
	}

}

int32_t main()
{
	ios_base::sync_with_stdio(0);   cin.tie(0);   cout.tie(0);

	int test = 1;
	// cin >> test;
	while (test--)solve();


}





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

class Main {
    static Scanner scanner = new Scanner();
    static long mod = 1000000007;

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int[][] s = new int[n][n];
        for (int i = 0; i < n; i++) {
            char[] t = scanner.next().toCharArray();
            for (int j = 0; j < n; j++) {
                s[i][j] = t[j] == '1' ? 1 : 0x7ffffff;
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                for (int k = 0; k < n; k++) {
                    s[j][k] = Math.min(s[j][k], s[j][i] + s[i][k]);
                }
            }
        }
        int max = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i == j) {
                    continue;
                }
                max = Math.max(max, s[i][j]);
                for (int k = 0; k < n; k++) {
                    if ((s[i][j] + s[j][k] + s[k][i]) % 2 == 1) {
                        System.out.println(-1);
                        return;
                    }
                }
            }
        }
        System.out.println(max + 1);
    }

    static class Scanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

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

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


Measured memory_bytes: 25484
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int f(int x, vector<int> &num)
{
    int ans = 0;
    for (int i : num)
    {
        ans += (i - x) * (i - x);
    }
    return ans;
}
int main()
{
    int n;
    cin >> n;
    vector<int> num(n);
    int sum=0;
    for (int i = 0; i < n; i++)
    {
        cin >> num[i];
        sum+=num[i];
    }
    int minans=min(f(sum/n,num),f(sum/n+1,num));
    cout<<minans<<endl;
}

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int n;
int a[maxn];

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

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

  if (tot%10) out(tot);
  int best = 0;
  for (int i=0; i<n; i++) {
    int cur = tot - a[i];
    if (cur%10) best = max(best, cur);
  }

  cout<<best<<endl;
  
  

  return 0;
}
// don't forget to read in the input :^)


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;
// << fixed << setprecision
// --------------------------------------
int n, m;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> m;
  vector<int> a(n);
  ll sum = 0;
  REP(i, n) {
    cin >> a[i];
    sum += a[i];
  }
  sort(a.begin(), a.end());

  priority_queue<P> que;
  REP(i, m) {
    int b, c;
    cin >> b >> c;
    que.push(P(c, b));
  }

  int i = 0;
  while(!que.empty()) {
    P p = que.top(); que.pop();
    int b = p.second;
    int c = p.first;

    for(int j = 0; j < b; j++, i++) {
      if(!(i < n) || !(a[i] <= c)) {
        cout << sum << endl;
        return 0;
      }
      sum += c - a[i];
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 4660