akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <limits.h>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(void){
    string s, t, ans1, ans2;
    cin >> s;
    cin >> t;
    
    int rst = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] != t[i]) {
            string a, b;
            a[0] = s[i], b[0] = t[i];
            for (int j = 0; j < t.size(); j++) {
                if (s[j] == a[0]) s[j] = b[0];
                else if (s[j] == b[0]) s[j] = a[0];
            }
            rst++;
        }
        if (rst > 26) {
            cout << "No" << endl;
            return 0;
        }
    }
    
    if (s == t) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    //cout << s << endl << t << endl;
    
}


Measured memory_bytes: 1020
#include <algorithm>
#include <iostream>
#include <math.h>
#include <cstdio>
#include <string.h>
#include <vector>
using namespace std;
int main(void){
	int a,b;
	cin>>a>>b;
	cout<<max(a+b,max(a-b,a*b));
	return 0;
}

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

int main(){
    string s,t,u;
    int a,b;
    cin >> s >> t >> a >> b >> u;
    if(s == u) a--;
    else b--;
    cout << a << ' ' << b << endl;
}

Measured memory_bytes: 3604
package main

import (
  "fmt"
  "sort"
  "math"
)

func divisors(n int) []int {
  res := make([]int, 0)
  for i := 1; i < int(math.Sqrt(float64(n)))+1; i++ {
    if n % i == 0 {
      res = append(res, i)
      if n / i != i {
        res = append(res, n/i)
      }
    }
  }
  sort.Ints(res)
  return res
}

func absInt(x int) int {if x >= 0 {return x}; return -x}
func gcd(a, b int) int {if (b == 0) {return absInt(a)}; return gcd(b, a % b)}
func lcm(a, b int) int {return absInt(a / gcd(a, b) * b)}

func main() {
  var a, b, k int 
  fmt.Scan(&a, &b, &k)
  cand := divisors(gcd(a, b))
  fmt.Println(cand[len(cand)-k])

}

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

int main(){
	int n;
	cin >> n;
	priority_queue<int> q;
	rep(i,n){
		int a;
		cin >> a;
		q.push(a);
	}
	int ali = 0;
	int bob = 0;
	while(q.size()){
		ali += q.top();
		q.pop();
        if(q.size() == 0) break;
		bob += q.top();
		q.pop();
	}
	int ans = ali - bob;
	cout << ans << endl;
}

Measured memory_bytes: 256
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100005;

 main()

{
    fast
    string s;
    cin>>s;
    int ses=0;
    for(auto x:s)
    {
        int val=x-'0';
        ses=(ses+val)%9;
    }
    if(ses==0)
    {
        cout<<"Yes\n";
    }
    else
    {
        cout<<"No\n";
    }
    return 0;

}





































Measured memory_bytes: 3752
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cstdint>
#include<unordered_map>
#include<sstream>
#include<boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pb push_back

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

typedef pair<int, int> P;

bool ps1(const P& element1, const P& element2)
{//first昇順
	return element1.first < element2.first;
}
bool ps2(const P& element1, const P& element2)
{//first降順
	return element1.first > element2.first;
}
bool ps3(const P& element1, const P& element2)
{//second昇順
	return element1.second < element2.second;
}
bool ps4(const P& element1, const P& element2)
{//second降順
	return element1.second > element2.second;
}

ll combination(ll n, ll r) {
	if (r * 2 > n) r = n - r;
	ll dividend = 1;
	ll divisor = 1;
	for (ll i = 1; i <= r; ++i) {
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}

int main()
{
	ll l, r;
	cin >> l >> r;
	bool zero = false;
	if (r-l>= 2019) {
		zero = true;
	}
	for (ll i = l; i < r + 1; i++) {
		if (i % 2019 == 0) {
			zero = true;
			break;
		}
	}
	if (!zero) {
		ll ans = 2019;
		for (ll i = l; i < r; i++) {
			for (ll j = i + 1; j < r + 1; j++) {
				ll ii = i % 2019;
				ll jj = j % 2019;
				ll tmp = (ll)ii * jj;
				tmp %= 2019;
				ans = min(ans, tmp);
			}
		}
		cout << ans << endl;
	}
	else {
		cout << 0 << endl;
	}


}


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

using namespace std;

int etot(char a) {
    if(a >= 'a') {
        return a - 'a' + 10;
    } else {
        return a - '0';
    }
}

int main() {
    
    int q;
    string s;

    cin >> q;

    for(int k = 0; k < q; ++k) {

        cin >> s;

        unsigned int b = 0;
        for(int i = 0; i < 8; ++i) {
            b |= etot(s[7 - i]) << 4 * i;
        }

        if(b >> 31 & 1) cout << "-";

        cout << ((b >> 7) & ((1 << 24) - 1));

        int under_point = 0;
        int w = 78125;
        for(int i = 0; i < 7; ++i) {
            if((b >> i) & 1) {
                under_point += w;
            }
            w *= 2;
        }

        cout << ".";

        if(under_point) {
            int d = 7;
            while(!(under_point % 10)) {
                under_point /= 10;
                --d;
            }
            printf("%0*d\n", d, under_point);
        } else {
            cout << "0" << endl;
        }

    }

}

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

class Progaram
{
    static void Main(string[] args)
    {
        var l = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        var k = l[0]; var n = l[1];
        var hs = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        var hsd = new int[n];
        int bh, nh;
        bh = hs[0];
        for (var i = 1; n > i; i++)
        {
            nh = hs[i];
            hsd[i - 1] = nh - bh;
            bh = nh;
        }
        hsd[n - 1] = (k - bh) + hs[0];
        Console.WriteLine(hsd.Sum() - hsd.Max());
    }
}

Measured memory_bytes: 34788
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

int N;
long long int x[55], y[55];

int check[55];

set<pair<long long int, long long int> > S;

void CALL(long long int X, long long int Y, long long int p, long long int q) {
	
	long long int n = 1;
	while (1) {
		int sign = 0;
		for (int m = 1; m <= N; m++) {
			if ((x[m] == X + n*p) && (y[m] == Y + n*q) && (check[m] == 0)) { check[m] = 1; sign = 1; n++; break; }
		}
		if (sign == 0) { break; }
	}
}

int main(void) {

	cin >> N;

	if (N == 1) { cout << 1 << endl; return 0; }

	vector<pair<long long int, long long int> > V;

	for (int i = 1; i <= N; i++) {
		long long int tmp1, tmp2;
		cin >> tmp1 >> tmp2;
		V.push_back(make_pair(tmp1, tmp2));
		S.insert(make_pair(tmp1, tmp2));
	}

	sort(V.begin(), V.end());

	for (int i = 0; i < N; i++) {
		x[i + 1] = V[i].first;
		y[i + 1] = V[i].second;
	}

	long long int ans = 99999999;

	long long int cnt;

	for (int i = 1; i <= N; i++) {
		for (int j = i+1; j <= N; j++) {
			if (i == j) { continue; }

			//============
			cnt = 0;
			for (int i = 1; i <= N; i++) { check[i] = 0; }
			//========

			for (int k = 1; k <= N; k++) {
				if (check[k] == 0) {
					cnt++;
					long long int p = x[j] - x[i];
					long long int q = y[j] - y[i];
					CALL(x[k], y[k], p,q);
				}
			}
			ans = min(ans, cnt);
		}
	}

	cout << ans << endl;

	return 0;
}

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

int g(int a){
  int t=1;
  while(t<a)t<<=1;
  while(true){
    while(t>a)t>>=1;
    if(t==a)return t;
    a-=t;
  }
  return -1;
}
int ans;
map<int,int> m;
void f(int l,int r){
  int wi=r-l;
  if(wi<=10){
    for(int i=l;i<r;i++)ans^=g(i);
    return;
  }
  int t=1;
  while(t<wi)t<<=1;
  t>>=1;t>>=1;
  for(int i=l;i<r;i++){
    if(i%t==1&&i+t+t-2<r){
      ans^=t;
      return f(i+t+t-1,r);
    }
    else ans^=g(i);
  }
}

signed main(){
  int n,l;cin>>n>>l;
  vector<string> s(n);
  for(int i=0;i<n;i++)cin>>s[i];
  sort(s.begin(),s.end());
  for(int i=0;i<n;i++){
    int a=0;
    if(i)while(s[i-1][a]==s[i][a])a++;
    int sl=s[i].size()-a;
    int ll=l-a;
    m[ll+1]^=1;
    m[ll-sl+1]^=1;
  }
  vector<int> v;
  for(auto p:m)if(p.second)v.push_back(p.first);
  for(int i=0;i<v.size();i+=2)f(v[i],v[i+1]);
  cout<<(ans?"Alice":"Bob")<<endl;
}


Measured memory_bytes: 640
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;




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




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

	REP(i, n) {
		if (ans  < k) {
			ans *= 2;
		}
		else {
			ans += k;
		}
	}

	cout << ans << endl;

	return 0;
}



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;

class Program
{
    static void Main(string[] args)
    {
        var stack = new Stack<int>();
        var ar = ReadLine().Split(' ');
        for(var i = 0; i < ar.Length; i++)
        {
            var num = 0;
            if (int.TryParse(ar[i], out num))
                stack.Push(num);
            else
            {
                var n = stack.Pop();
                var res = stack.Pop();
                switch (ar[i])
                {
                    case "+":
                        res += n;
                        break;
                    case "-":
                        res -= n;
                        break;
                    case "*":
                        res *= n;
                        break;
                }
                stack.Push(res);
            }
        }
        WriteLine(stack.Pop());
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}



Measured memory_bytes: 18408
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int K = sc.nextInt();

        int ans = 0;
        if(A <= K){
            ans = A;
            K -= A;
        }else{
            ans = K;
            K = 0;
        }
        if(B <= K){
            K -= B;
        }else{
            K = 0;
        }
        ans -= K;

        System.out.println(ans);
    }
}



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

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

#define MAXN 1003
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define se second 
#define FAIL {printf("-1\n"); return 0;}

int H, W;
char A[MAXN][MAXN];
int dp[MAXN][MAXN];

int main(int argc, char **argv)
{
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif

    scanf("%d %d", &H, &W);
    for (int i = 0; i < H; i++) scanf("%s", A[i]);

    dp[0][0] = 1;
    for (int i = 1; i < W; i++) {
        dp[0][i] = (A[0][i] == '.') ? dp[0][i-1] : 0;
        dp[i][0] = (A[i][0] == '.') ? dp[i-1][0] : 0;
    }

    for (int i = 1; i < H; i++) {
        for (int j = 1; j < W; j++) {
            if (A[i][j] == '.') {
                dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % MOD;
            }
        }
    }

    printf("%d\n", dp[H-1][W-1]);

    return 0;
}


Measured memory_bytes: 5120
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;

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

string s[3];

string solve() {
  const char p[2] = { 'b', 'w' };
  string res = " ";
  rep (z,2) {
    const char c = p[z];
    bool ok = false;
    for (int i = 0; i < 3; ++i) {
      if (s[0][i] == c && s[1][i] == c && s[2][i] == c) ok = true;
      if (s[i][0] == c && s[i][1] == c && s[i][2] == c) ok = true;
    }
    if (s[0][0] == c && s[1][1] == c && s[2][2] == c) ok = true;
    if (s[0][2] == c && s[1][1] == c && s[2][0] == c) ok = true;
    if (ok) {
      res[0] = c; return res;
    }
  }
  return string("NA");
}

int main() {
  while (cin >> s[0]) {
    if (s[0][0] == '0') break;
    for (int i = 1; i < 3; ++i) cin >> s[i];
    cout << solve() << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)

int main()
{
	int A, B;
	cin >> A >> B;
	if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) {
		cout << "Possible" << endl;
	}
	else {
		cout << "Impossible" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<int,int>
#define poly vector<ll>
#define mem(a) memset((a),0,sizeof(a))
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const ull base=233;
const int N=250005;
char ch[N];
ull f[N],g[N];
map<ull,int> M;
int main(){
	ull zs=base,inv=1; For(i,1,63){inv=inv*zs; zs=zs*zs;}
	assert(base*inv==1);
	//cout<<inv<<endl;
	int n=read();
	scanf("%s",ch+1);
	g[0]=1;
	For(i,1,n){
		f[i]=f[i-1]; g[i]=g[i-1];
		if(ch[i]=='+')f[i]+=g[i];
		if(ch[i]=='-')f[i]-=g[i];
		if(ch[i]=='>')g[i]*=base;
		if(ch[i]=='<')g[i]*=inv;
		M[f[i]]++;
	}
	ll ans=0;
	For(i,1,n){
		ans+=M[f[n]*g[i-1]+f[i-1]];
		M[f[i]]--;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 35584
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

int main(){

   int a,b,c;
   cin >> a >> b >> c;

   int tmp = a-b;
   int ans = c - tmp;

   if(ans > 0) cout << ans << endl;
   else cout << 0 << endl;


   return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

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


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

  int l = 0, r = N;

  cout << 0 << endl;
  fflush(stdout);
  string s;
  cin >> s;
  if (s == "Vacant")
    return 0;


  string L = s, R = s;

  while (r - l > 1) {
    int m = (r + l) / 2;
    cout << m << endl;
    fflush(stdout);
    string s;
    cin >> s;
    if (s == "Vacant")
      return 0;

    int lm = (m - l - 1) % 2, mr = (r - m - 1) % 2;
    if (lm ^ (L == s)) {
      r = m;
      R = s;
    } else {
      l = m;
      L = s;
    }
  }

  cout << l << endl;
  fflush(stdout);
  cin >> s;
  if (s == "Vacant")
    return 0;

  cout << r << endl;
  fflush(stdout);
  cin >> s;
  if (s == "Vacant")
    return 0;
}

Measured memory_bytes: 3856
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
// #define int ll
using namespace std;
const int INF (1 << 30);
const ll LLINF (1LL << 55LL);
const int MOD = 1000000007;
const int MAX = 510000;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin>>n;
    if(n%2==0){
        cout<<0.5000000000<<endl;
    }
    else{
        cout<<((double)(n/2+1)/(double)n)<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
X = sorted(map(int, input().split()))

d = [0] * (M - 1)

if (N >= M):
    print(0)
    exit()
else:
    for i in range(M):
        if (i == M - 1):
            break
        else:
            d[i] = X[i + 1] - X[i]

d.sort(reverse=True)
count = 0
for i in d:
    if (N > 1):
        N -= 1
        continue
    elif(N == 1):
        count += i

print(count)


Measured memory_bytes: 85400
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

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

        int sNum = Integer.parseInt(scanner.nextLine());
        String[] sLine = scanner.nextLine().split(" ", sNum);

        Map<String, Boolean> sSeen = new HashMap<>();
        for (int i = 0; i < sNum; i++) {
            sSeen.put(sLine[i], true);
        }

        int tNum = Integer.parseInt(scanner.nextLine());
        String[] tLine = scanner.nextLine().split(" ", tNum);

        int result = 0;
        for (int i = 0; i < tNum; i++) {
            if (sSeen.containsKey(tLine[i])) {
                result++;
            }
        }
        System.out.println(result);
    }
}



Measured memory_bytes: 30324
using System;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        new Program().Solve();
        Console.ReadKey();
    }

    Scanner sc = new Scanner();
    void Solve()
    {
        const int MOD = (int)1e9+7;
        int n = sc.NextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[sc.NextInt()]++;
        int start = n % 2 == 0 ? 1 : 2;

        if (start == 2 && a[0] != 1)
        {
            Console.WriteLine(0);
            return;
        }

        long ans = 1;
        for (int i = start; i < n; i+=2)
        {
            if (a[i] != 2)
            {
                Console.WriteLine(0);
                return;
            }
            ans *= 2;
            ans %= MOD;
        }
        Console.WriteLine(ans);
    }
    // ------------------------------------- //
    int Max(int v1, int v2) { return Math.Max(v1, v2); }
    int Min(int v1, int v2) { return Math.Min(v1, v2); }
    int[][] CreateArray2D(int n1, int n2)
    {
        int[][] ary = new int[n1][];
        for (int i = 0; i < n1; i++) ary[i] = new int[n2];
        return ary;
    }
}
class Scanner
{
    public Scanner() { }
    private string[] buff = null;
    private int bIndex = 0;
    public string Next()
    {
        if (buff == null || bIndex >= buff.Length)
        {
            buff = Console.ReadLine().Split(' ');
            bIndex = 0;
        }
        return buff[bIndex++];
    }
    public int NextInt()
    {
        return int.Parse(Next());
    }
    public long NextLong()
    {
        return long.Parse(Next());
    }
}
class Pair<T, K>
{
    public Pair() { }
    public Pair(T f, K s)
    {
        first = f;
        second = s;
    }
    public T first {get; set;}
    public K second {get; set;}
}

Measured memory_bytes: 9688
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;


void solve(long long N, std::vector<long long> P){
    if(N==1){
        cout<<0<<endl; return;
    }
    if(N==2){
        cout<< (P[0]<P[1]? 0:1)<<endl; return;
    }
    vll A(N);
    REP(i, N){
        A[P[i]]=i;
    }
    A.push_back(INF);
    ll s=0, t=0;
    ll cnt = 0;
    while(s<N){
        while(t<N-1 && A[t+1]>A[t])
            t++;
        cnt = max(cnt, t-s+1);
        s = t+1;
        t = s;
    }
    cout<< N - cnt<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> P(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&P[i]);
        P[i]--;
    }
    solve(N, std::move(P));
    return 0;
}


Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
struct edge{
    long long to;
    long double cost;
};
typedef pair<ll,long double> P;
struct graph{
  ll V;
  vector<vector<edge> > G;
  vector<long double> d;

  graph(ll n){
    init(n);
  }

  void init(ll n){
    V = n;
    G.resize(V);
    d.resize(V);
    for (ll i = 0; i < V;i++){
            d[i] = INF;
        }
  }

  void add_edge(ll s, ll t, long double cost){
    edge e;
    e.to = t, e.cost = cost;
    G[s].push_back(e);
  }

  void dijkstra(ll s){
      for (ll i = 0; i < V;i++) {
          d[i] = INF;
      }
    d[s] = 0;
    priority_queue<P,vector<P>, greater<P> > que;
    que.push(P(0,s));
    while(!que.empty()){
      P p = que.top(); que.pop();
      ll v = p.second;
      if(d[v]<p.first) continue;
      for(auto e : G[v]){
        if(d[e.to]>d[v]+e.cost){
          d[e.to] = d[v]+e.cost;
          que.push(P(d[e.to],e.to));
        }
      }
    }
  }
};
long double calcdist(ll x1,ll y1,ll r1,ll x2,ll y2,ll r2){
    return max((long double)0,sqrtl((long double)(x1 - x2) * (long double)(x1 - x2) + (long double)(y1 - y2) * (long double)(y1 - y2)) - (long double)r1 - (long double)r2);
}
int main(){
    ll xs, ys, xt, yt;
    cin >> xs >> ys >> xt >> yt;
    ll n;
    cin >> n;
    ll x[n+2], y[n+2], r[n+2];
    for (ll i = 0; i < n;i++){
        cin >> x[i] >> y[i] >> r[i];
    }
    x[n] = xs;
    y[n] = ys;
    r[n] = 0;
    x[n + 1] = xt;
    y[n + 1] = yt;
    r[n + 1] = 0;

    graph g(n + 2);
    for (ll i = 0; i < n + 2;i++){
        for (ll j = 0; j < n + 2;j++){
            if (i == j) continue;
            g.add_edge(i,j,calcdist(x[i], y[i], r[i], x[j], y[j], r[j]));
			g.add_edge(j,i,calcdist(x[i], y[i], r[i], x[j], y[j], r[j]));
        }
    }
    g.dijkstra(n);
    long double ans = g.d[n + 1];
    cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 76516
import java.util.*;
import java.text.DecimalFormat;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt(), t = sc.nextInt(), i=0, no=n;
		double s = t;
		int[] T = new int[n];
		while (no-->0) T[i++] = sc.nextInt();
		for (i=0; i<n-1; i++) s+=Math.min(T[i+1]-T[i], t);
		System.out.println(new DecimalFormat("#").format(s));
		sc.close();		
	}

	public static void main(String args[]) {
		solve();
	}

}

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

void solve() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> v(m);
  rep(i, m) {
    int k;
    cin >> k;
    rep(j, k) {
      int s;
      cin >> s;
      v[i].push_back(s-1);
    }
  }
  vector<int> p(m);
  rep(i, m) cin >> p[i];

  int ans = 0;

  for(int bit = 0; bit < (1 << n); bit++) {
    int b = true;
    rep(i, m) {
      int num = 0;
      for(int j = 0; j < v[i].size(); j++) {
        if (bit & (1 << v[i][j])) num++;
      }
      if (num % 2 == p[i]) b = (b && true);
      else b = false;
    }
    if(b) ans++;
  }

  cout << ans << endl;
}

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

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main(void) {
  int64_t A, B, C;
  cin >> A >> B >> C;
  int64_t N = A * B * C;
  int64_t NA = N - 2 * (A / 2) * B * C;
  int64_t NB = N - 2 * A * (B / 2) * C;
  int64_t NC = N - 2 * A * B * (C / 2);
  int64_t answer = std::min({NA, NB, NC});
  cout << answer << endl;
  return 0;
}

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

int main(){
	int N;
	int R;

	scanf("%d",&N);
	scanf("%d",&R);

	if(N>=10){
		printf("%d\n",R);
	}
	else{
		printf("%d\n",R+100*(10-N));
	}
	return 0;
}

Measured memory_bytes: 128
class itp1_2a:
    def out(self,a,b):
        if a<b:
            print "a < b"
        elif a>b:
            print "a > b"
        else :
            print "a == b"
if __name__=="__main__":
    ipt=map(int,raw_input().split(" "))
    run=itp1_2a()
    run.out(ipt[0],ipt[1])

Measured memory_bytes: 4204
#include<bits/stdc++.h>
#define N 100005
using namespace std;

int n,cnt,a[N]; long long ans,b[N],s1[N],s2[N];
int main(){
	scanf("%d%lld",&n,&b[cnt=1]);
	int i,x; char ch;
	for (i=1; i<n; i++){
		ch=getchar(); while (ch!='+' && ch!='-') ch=getchar();
		scanf("%d",&x);
		if (ch=='+') b[cnt]+=x; else{
			cnt++; a[cnt]=b[cnt]=x;
		}
	}
	for (i=1; i<=cnt; i++){
		s1[i]=s1[i-1]+b[i]; s2[i]=s2[i-1]+b[i]-a[i]-a[i];
	}
	for (i=2; i<=cnt; i++) ans=max(ans,s2[i-1]-b[i]+s1[cnt]-s1[i]);
	printf("%lld\n",(cnt==1)?b[1]:ans);
	return 0;
}


Measured memory_bytes: 2944
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
string s;
int main(){
	cin>>s;
	putchar(s[0]),putchar(s[1]),putchar(s[2]);
	return 0;
}


Measured memory_bytes: 3632
N = int(input())
S = input()
SL = list(S)
cnt = 0
nr = SL.count('R')
ng = SL.count('G')
nb = SL.count('B')
ans = nr * ng * nb
cnt = 0
for i in range(len(S)):
    for d in range(N):
        j = i + d
        k = j + d
        if k >= N:
            break
        if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
            ans -= 1
print(ans)

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

bool isPalindrome(string s){
    string t = s;
    reverse(t.begin(), t.end());
    return (s == t);
}

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

    while(n != 0){
        n /= k;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long LL;
LL n,k,anss,b;
int main()
{
	scanf("%lld%lld",&n,&k);
	for(b=k+1;b<=n;b++)
	{
		anss+=(n+1)/b*(b-k)+max((n+1)%b-k,0LL);
		if(k==0)	anss--;
		//printf("%lld\n",anss);
	}
	printf("%lld",anss);
	return 0;
}


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

using namespace std;

template <class T>
struct Edge {
    int to;
    T cost;
    Edge(int to, T cost) : to(to), cost(cost){};
};

template <class T>
class Graph {
public:
    explicit Graph(int N = 0) : size(N) { path.resize(size); }
    void span(int u, int v, T cost = 1) { path[u].push_back(Edge<T>(v, cost)); }
    vector<Edge<T>> operator[](int v) const { return path[v]; }

    int size;
    vector<vector<Edge<T>>> path;
};

template <class T>
class TopologicalSort {
public:
    int size;
    Graph<T> graph;
    vector<bool> visited;
    vector<int> order, id;
    // トポロジカルソート後において、頂点vはid[v]番目

    void dfs(int v) {
        if (visited[v]) return;
        visited[v] = true;
        for (const auto& e : graph[v]) dfs(e.to);
        order.push_back(v);
    }

    explicit TopologicalSort(const Graph<T>& g) : size(g.size), graph(g) {
        visited.assign(size, false);
        for (int v = 0; v < size; ++v) dfs(v);
        reverse(order.begin(), order.end());

        id.resize(size);
        for (int i = 0; i < size; ++i) id[order[i]] = i;
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    Graph<int> graph(N);
    vector<vector<int>> par(N);

    for (int i = 0; i < N + M - 1; ++i) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        graph.span(u, v);
        par[v].push_back(u);
    }

    TopologicalSort<int> ts(graph);
    for (int v = 0; v < N; ++v) {
        int p;
        if (par[v].empty()) {  // 根
            p = -1;
        } else {
            // トポロジカルソートで一番大きいのが直接の親
            p = *max_element(par[v].begin(), par[v].end(),
                             [&](int i, int j) { return ts.id[i] < ts.id[j]; });
        }
        cout << p + 1 << endl;
    }
    return 0;
}


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

int main() {
  
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  
  if ( a + b > c + d ){
    cout << "Left" << endl;
  }else if ( a + b < c + d ){
    cout << "Right" << endl;
  }else{
    cout << "Balanced" << endl;
  }
  
}



Measured memory_bytes: 256
import Data.Functor( (<$>))

main = do
    [x,y] <- (read <$>) . words <$> getLine	::IO [Int]
    let
	l = min x y
	g = max x y

	gcd x 0 = x
	gcd x y
	  = let
		r = x `rem` y
	    in
		gcd y r

    print $ gcd g l



Measured memory_bytes: 3648
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int D;
    cin >> D;
    vi c(26);
    rep(i, 26) cin >> c[i];
    vvi s(D, vi(26));
    rep(i, D) rep(j, 26) {
        cin >> s[i][j];
    }

    rep(i, D) {
        cout << (i*s[i][(i+1)%26])%26 +1<< endl;
    }
}

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

w,h,n=map(int,input().split())
x,y=0,0

for i in range(n):
    a,b,c=map(int,input().split())
    if c==1:
        x=max(x,a)
    elif c==2:
        w=min(w,a)
    elif c==3:
        y=max(y,b)
    elif c==4:
        h=min(h,b)


print(max(0,w-x)*max(0,h-y))


Measured memory_bytes: 3060
n = int(input())
dp = [int(i) for i in input().split()]
for i in range(n-1):
    a, b, c = map(int, input().split())
    a0 = dp[0]
    b0 = dp[1]
    c0 = dp[2]
    
    dp[0] = max(b0, c0) + a
    dp[1] = max(c0, a0) + b
    dp[2] = max(a0, b0) + c
print(max(dp))

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

bool in(int x, int y, int n) {
	return 0 <= x && x < n && 0 <= y && y < n;
}

int main() {
	int d;
	cin >> d;
	for(int t = 0; t < d; t++) {
		char str[128][128];
		int n;
		cin >> n;

		for(int i = 0; i < 128; i++)
			for(int j = 0; j < 128; j++)
				str[i][j] = ' ';

		int x = 0, y = n - 1;
		int dir = 0;
		int dx[] = {0, 1, 0, -1}, dy[] = {-1, 0, 1, 0};
		bool flag = false;
		while(1) {
			str[y][x] = '#';
			/*
			for(int i = 0; i < n; i++) {
				for(int j = 0; j < n; j++)
					cout << ((i == y && j == x) ? '*' : str[i][j]);
				cout << endl;
			}
			cout << (dir == 0 ? "up" : dir == 1 ? "forward" : dir == 2 ? "down" : "back") << endl;
			cout << endl;
			*/

			int nx, ny;
			bool turn_flag = false;
			nx = x + dx[dir]; ny = y + dy[dir];

			if(in(nx+dx[dir], ny+dx[dir], n))
				turn_flag |= str[ny+dx[dir]][nx+dx[dir]] == '#';
			if(in(nx+dx[dir], ny        , n))
				turn_flag |= str[ny        ][nx+dx[dir]] == '#';
			if(in(nx+dx[dir], ny-dx[dir], n))
				turn_flag |= str[ny-dx[dir]][nx+dx[dir]] == '#';

			if(in(nx, ny+dx[dir], n))
				turn_flag |= str[ny+dx[dir]][nx] == '#';
			if(in(nx, ny        , n))
				turn_flag |= str[ny        ][nx] == '#';
			if(in(nx, ny-dx[dir], n))
				turn_flag |= str[ny-dx[dir]][nx] == '#';

			if(in(nx+dy[dir], ny+dy[dir], n))
				turn_flag |= str[ny+dy[dir]][nx+dy[dir]] == '#';
			if(in(nx        , ny+dy[dir], n))
				turn_flag |= str[ny+dy[dir]][nx        ] == '#';
			if(in(nx-dy[dir], ny+dy[dir], n))
				turn_flag |= str[ny+dy[dir]][nx-dy[dir]] == '#';

			if(in(nx+dy[dir], ny, n))
				turn_flag |= str[ny][nx+dy[dir]] == '#';
			if(in(nx        , ny, n))
				turn_flag |= str[ny][nx        ] == '#';
			if(in(nx-dy[dir], ny, n))
				turn_flag |= str[ny][nx-dy[dir]] == '#';

			if(!in(nx,ny,n))
				turn_flag = true;

			if(turn_flag) {
				if(flag)
					break;
				dir = (dir + 1) % 4;
				flag = true;
			}
			else {
				x += dx[dir];
				y += dy[dir];
				flag = false;
			}
		}

		if(t > 0)
			cout << endl;
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++)
				cout << str[i][j];
			cout << endl;
		}
	}
}

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

struct Card {
    char suit, value;
};

void trace(struct Card A[], int N) {
    for(int i = 0; i < N; i++) {
        if(i > 0) cout << " ";
        cout << A[i].suit << A[i].value;
    }
    cout << endl;
}

void bubbleSort(struct Card A[], int N) {
    bool flag = true;
    int i = 0;
    while(flag) {
        flag = false;
        for(int j = N - 1; j > i; j--) {
            if(A[j].value < A[j - 1].value) {
                swap(A[j], A[j - 1]);
                flag = true;
            }
        }
        i++;
    }
}

void selectionSort(struct Card A[], int N) {
    int minj;
    for(int i = 0; i < N; i++) {
        minj = i;
        for(int j = i; j < N; j++) {
            if(A[j].value < A[minj].value) {
                minj = j;
            }
        }
        swap(A[i], A[minj]);
    }
}

bool isStable(struct Card A[], struct Card B[], int N) {
    for(int i = 0; i < N; i++) {
        if(A[i].suit != B[i].suit) return false;
    }
    return true;
}

int main() {
    int N;
    cin >> N;
    Card A[N], B[N];
    for(int i = 0; i < N; i++) {
        cin >> A[i].suit >> A[i].value;
    }
    for(int i = 0; i < N; i++) {
        B[i] = A[i];
    }

    bubbleSort(A, N);
    selectionSort(B, N);

    trace(A, N);
    cout << "Stable" << endl;
    trace(B, N);
    if(isStable(A, B, N)) {
        cout << "Stable" << endl;
    } else {
        cout << "Not stable" << endl;
    }
}


Measured memory_bytes: 3116
import collections

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for i in range(Q):
    Bi, Ci = map(int, input().split())
    B.append(Bi)
    C.append(Ci)

counter = collections.Counter(A)
s = sum(A)

for i in range(Q):
    if B[i] not in counter:
        print(s)
        continue
    s += counter[B[i]] * (C[i] - B[i])
    counter[C[i]] += counter[B[i]]
    del counter[B[i]]
    print(s)

Measured memory_bytes: 27176
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int N,K,X,Y;
  cin >> N >> K >> X >> Y;
  int sum=0;
  for(int i=1;i<=N;i++)
  {
    if(i<=K)
      sum+=X;
    else
      sum+=Y;
  }
  cout<<sum<<endl;
  return 0;
}
  

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <time.h>
#include <sys/timeb.h>
#include <cstdio>
#include <sys/time.h>

using namespace std;
#define ll long long
#define uint unsigned int
#define ulong unsigned long long int

int main(){
	
	
	int N;
	int A;
	cin >> N >> A;
	cout << N * N - A << endl;
	
	
	
}

Measured memory_bytes: 256
N = int(input())
binary = [0]*60
for inp in input().split():
    inp = bin(int(inp))[2:][::-1]
    for j, _inp in enumerate(inp):
        if _inp == '1':
            binary[j] += 1
    
ret = 0
pow2 = 1
for elem in binary:
    if elem == 0 or elem == N:
        pass
    else: 
        mn = elem * (N - elem) % (10**9 + 7)
        ret += pow2 * mn 
        ret = ret % (10**9 + 7)
    pow2 = pow2 * 2 % (10**9 + 7)
print(ret)

Measured memory_bytes: 122808
#include<bits/stdc++.h>//本当は必要なヘッダファイルだけインクルードするべきです
using namespace std;//本当は個別にusingするか変数や関数ごとにstd::をつけるべきです
//本当は関数内に宣言し明示的に初期化するべきです
int gcd(int x,int y){
  if(y==0)return x;
  else return gcd(y,x%y);
}

int main(void){
  int x,y;
  cin>>x>>y;
  cout<<gcd(x,y)<<endl;
  return 0;
}



Measured memory_bytes: 3132
#include<stdio.h>

#define MAX 200000
#define SNT 2000000000

typedef long long int llong;

int L[MAX / 2 + 2], R[MAX / 2 + 2];

llong merge(int*, int, int, int, int);
llong mergeSort(int*, int, int, int);

llong merge(int A[], int n, int left, int mid, int right){
  int i, j, k;
  int n1, n2;
  llong c = 0;
  
  n1 = mid - left;
  n2 = right - mid;
  
  for( i = 0 ; i < n1 ; i++){
    L[i] = A[left + i];
  }
  
  for( i = 0 ; i < n2 ; i++){
    R[i] = A[mid + i];
  }
  
  L[n1] = R[n2] = SNT;
  i = j = 0;
  
  for( k = left ; k < right ; k++){
    
    if( L[i] <= R[j] ){
      A[k] = L[i++];
    }
    
    else{
      A[k] = R[j++];
      c += n1 - i;
    }
  }
  return c;
}

llong mergeSort(int A[], int n, int left, int right){
  int mid;
  llong v1, v2, v3;
  if( left + 1 < right){
    mid = (left + right) / 2;
    v1 = mergeSort(A, n, left, mid);
    v2 = mergeSort(A, n, mid, right);
    v3 = merge(A, n, left, mid, right);
    return v1 + v2 + v3;
  }
  else return 0;
}

int main(){
  int A[MAX], n, i;
  llong ans;

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

  ans = mergeSort(A, n, 0, n);
  printf("%lld\n", ans);

  return 0;
}



Measured memory_bytes: 3264
//パソコン甲子園2010 問題番号02 病院でウォーキング
#include<stdio.h>

int main(void){

	int i1, n, p, d1, d2, sum, num, max;

	scanf("%d",&n);
	while(n != 0){

		max = -1;
		for(i1 = 1; i1 <= n; i1++){
			scanf("%d %d %d",&p,&d1,&d2);
			sum = d1 + d2;
			if(max < sum){
				max = sum;
				num = p;
			}
		}

		printf("%d %d\n",num,max);
		scanf("%d",&n);

	}
	return 0;
}

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

typedef long long ll;

const int MAXV = 1e5 + 10;
const int MAXN = 1e3 + 10;
const ll INF = 1e13;

ll dp[MAXV];
int N,W,V,wi[MAXN],vi[MAXN];

int main(){

	cin >> N >> W;
	for(int i = 1;i<=N;i++){
		cin >> wi[i] >> vi[i];
		V += vi[i];
	}

	for(int i = 1;i<=V;i++) dp[i] = INF;
	dp[0] = 0;
	
	for(int item = 1;item<=N;item++){
		int w = wi[item], v = vi[item];
		for(int i = V;i>=v;i--){
			dp[i] = min(dp[i],dp[i - v] + w);
		}
	}

	for(int i = V;i>=0;i--){
		if(dp[i] <= W){
			cout << i << endl;
			break;
		}
	}

	return 0;

}

Measured memory_bytes: 4344
/*
    Created by Rahul Goel.
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
/*******************************************************************************/
using namespace std;
using namespace __gnu_pbds;
template < typename T >
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/*******************************************************************************/
using ll = long long;
using ld = long double;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const int INF = 1e9;
const ll LINF = 1e18;
/*******************************************************************************/
ll mod_sum() { return 0LL; }
template < typename T, typename... Args >
T mod_sum(T a, Args... args) { return ((a + mod_sum(args...))%MOD + MOD)%MOD; }
/*******************************************************************************/
ll mod_prod() { return 1LL; }
template< typename T, typename... Args >
T mod_prod(T a, Args... args) { return (a * mod_prod(args...))%MOD; }
/*******************************************************************************/
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
#define fastio          ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(c)          (c).begin(), (c).end()
#define present(c,x)    ((c).find(x) != (c).end())
#define cpresent(c,x)   (find(all(c),x) != (c).end())
#define uniq(c)         (c).resize(distance((c).begin(), unique(all(c))))
#define min_pq(t)       priority_queue < t, vector < t >, greater < t > >
#define max_pq(t)       priority_queue < t >
#define pb              push_back
#define ff              first
#define ss              second
/*******************************************************************************/
using pii = pair < ll, ll >;
using vi = vector < ll >;
using vb = vector < bool >;
using vvi = vector < vector < ll > >;
using vvb = vector < vector < bool > >;
using vpii = vector < pii >;
using vvpii = vector < vector < pii > >;
/*******************************************************************************/
//.-.. . -. -.- .- .. ... .-.. --- ...- .
/*
    Code begins after this.
*/

vvi adj;
vb vis;

void add_edge(ll u, ll v) {
    adj[u].pb(v);
    adj[v].pb(u);
}

void dfs(ll v) {
    vis[v] = true;
    for (ll u : adj[v]) {
        if (!vis[u]) {
            dfs(u);
        }
    }
}

ll solve() {
    ll n, m;
    cin >> n >> m;
    adj.resize(n);
    vis.resize(n);
    
    for (ll i = 0; i < m; i++) {
        ll u, v;
        cin >> u >> v;
        --u, --v;
        add_edge(u, v);
    }

    ll comp = 0;
    for (ll i = 0; i < n; i++) {
        if (!vis[i]) {
            dfs(i);
            comp++;
        }
    }

    cout << comp - 1 << endl;

    return 0;
}

signed main() {
    fastio;

    ll t = 1;
    while (t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 9812
k=0
while True:
    n=int(input())
    if n==0:break
    
    L=[0,0,0,0,0,0,0,0,0,0]
    for i in range(n):
        x=int(input())
        L[x]+=1
    
    for j in range(10):
        if L[j]==0:print('-')
        else:
            for k in range(L[j]):
                print('*',end='')
            print('')


Measured memory_bytes: 7580
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

ll N,T[101],g,ans;

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

int main(void){
	cin>>N;
	rep(i,N)cin>>T[i];
	ans=T[0];
	reg(i,1,N-1){
		g = euclid(ans,T[i]);
		ans *= T[i]/g;
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

const int N = 200010;
const double eps = 1e-6;

int n, two, four, el;

int main()
{
    cin >> n;
    while(n--)
    {
        int x;
        cin >> x;
        if(x % 4 == 0) four++;
        else if(x % 2 == 0) two++;
        else el++;
    }

    if(two)
    {
        if(four >= el) puts("Yes");
        else puts("No");
    }
    else
    {
        if(four + 1 >= el) puts("Yes");
        else puts("No");
    }
    return 0;
}


Measured memory_bytes: 256
from sys import stdin

def main():
    S = list(stdin.readline().rstrip())
    Q = int(input())
    rev = 0
    head = []
    tail = []

    for _ in range(Q):
        q = stdin.readline()
        if q[0] == "1":
            rev = (rev+1)%2
        else:
            if q[2] == "1":
                if rev == 0:
                    head.append(q[4])
                else:
                    tail.append(q[4])
            else:
                if rev ==0:
                    tail.append(q[4])
                else:
                    head.append(q[4])

    if rev == 0:
        ans = "".join(head[::-1] + S + tail)
    else:
        ans = "".join(tail[::-1] + S[::-1] + head)
    
    print(ans)
    """
    S = stdin.readline().rstrip() 
    Q = int(input())
    rev = 0
    for _ in range(Q):
        q = stdin.readline()

        if q[0] == "1":
            rev = (rev+1)%2
        else:
            if q[2] == "1":
                if rev == 0:
                    S = "{}{}".format(q[4], S)
                else:
                    S = "{}{}".format(S, q[4])
            else:
                if rev ==0:
                    S = "{}{}".format(S, q[4])
                else:
                    S = "{}{}".format(q[4], S)
    if rev == 1:
        print(S[::-1])
    else:
        print(S)
    """
main()

Measured memory_bytes: 9988