akhauriyash/Code-Regression huggingface dataset:
// https://atcoder.jp/contests/abc162/tasks/abc162_f
// DP 解説動画の手法
// oxoxoxo...xoにxを1コまたは2コ挿入
// i番目まで見たときにjコのxが挿入された場合のMAX　のDP

#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

typedef long long ll;

#define MAX_N 200005
const ll INF = 1e18;

int N;
ll a[MAX_N];
ll dp[MAX_N][4];

int main() {
    cin >> N;
	rep(i,N) cin >> a[i];
	int k = 1 + N%2; // 挿入されるxの数
	rep(i,N)rep(j,4)dp[i][j]=-INF;
	rep(j,k+1)dp[0][j+1]=0;

	rep(j,k+1){
		rep(i,N-k){
			if(i%2){
				dp[i+1][j+1]=dp[i][j+1];
			}else{
				dp[i+1][j+1] = max(dp[i][j+1]+a[i+j],dp[i+1][j]);
			}
		}
	}
	cout << dp[N-k][k+1] << endl;
	// rep(j,k+2){
	// 	rep(i,N+1){
	// 		cout << dp[i][j] << " ";
	// 	}
	// 	cout << endl;
	// }
    return 0;
}


Measured memory_bytes: 11416
#include "bits/stdc++.h"
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 6;
const ll LLINF = 4e18;

//平行四辺形:タテaヨコb
ll leng(ll a, ll b) {
    ll ans = 0;
    if (a < b) swap(a, b);
    ans += a / b * 2 * b;
    if (a % b != 0) {
        ans += leng(a%b, b);
    }
    else {
        ans -= b;
    }
    return ans;
}

int main() {
    ll n, x; cin >> n >> x;
    ll r = n;
    cout << leng(n-x,x)+n << endl;
    getchar(); getchar();
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))


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

def main():
    n = INT()
    table = [0] * (n + 1)
    table[0] = 0
    table[1] = 1

    for i in range(2, n + 1):
        if table[i] == 0:
            table[i] = 2
            for j in range(i + i, n + 1, i):
                cnt = 0
                c = j
                while c % i == 0:
                    c //= i
                    cnt += 1
                table[j] = table[c] * (cnt + 1)

    # print(table)
    ans = 0
    for i in range(n + 1):
        ans += i * table[i]
    print(ans)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 151792
# vim: fileencoding=utf-8


def main():
    a, b = map(int, input().split())
    c = 0
    for i in range(a, b + 1):
        s = str(i)
        r = "".join(reversed(list(s)))
        if s == r:
            c += 1
    print(c)


if __name__ == "__main__":
    main()


Measured memory_bytes: 73744
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e16;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    ll N; cin >> N;
    vl a(N), b(N), c(N); ll ans = 0;
    REP(i, N){
        cin >> a[i] >> b[i]; c[i] = a[i] + b[i]; ans += -b[i];
    }
    sort(c.begin(), c.end(), greater<ll>());
    
    REP(i, N){
        if(i%2==0) ans += c[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2560
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String N = sc.nextLine();
		if (N.matches(".*[24579]$")){
			System.out.println("hon");
		}else if(N.matches(".*[0168]$")){
			System.out.println("pon");
		} else {
			System.out.println("bon");
		}
	}
}

Measured memory_bytes: 35780
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
using namespace std;
int main()
{
    string tenki;
    cin >> tenki;
    if (tenki == "Sunny")
    {
        cout << "Cloudy" << endl;
    }
    if (tenki == "Cloudy")
    {
        cout << "Rainy" << endl;
    }
    if (tenki == "Rainy")
    {
        cout << "Sunny" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    n=int(readline())

    ans=(n * (n-1)) // 2
    
    print(ans)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Measured memory_bytes: 5620
N = $stdin.gets.chomp.to_i
A = $stdin.gets.chomp.split(" ").map{ |a| a.to_i }

#p A

def heads(arr)
  sh = arr.sort_by{ |e| -e[:v] }.each_with_index{ |e,k| e[:k] = k }
  #p sh
  
  psum = sh[0...N].map{ |e| e[:v] }.inject(:+)
  k0 = N-1
  
  heads = [psum] + (N...2*N).to_a.reverse.map { |i|
    k, v = arr[i][:k], arr[i][:v]
    arr[i][:v] = nil
    #p [i,k,v]
    if k <= k0
      while true
        k0 += 1
        break if sh[k0][:v]
      end
      psum = psum - v + sh[k0][:v]
    end
    psum
    #p [k0,psum]
  }
  
  heads
end

h = A[0...2*N].map{ |a| {v: a} }
t = A[N...3*N].map{ |a| {v: -a} }.reverse

#p h
#p t

H = heads(h)
T = heads(t).reverse

#p H
#p T
p H.zip(T).map{ |h,t| h+t }.max


Measured memory_bytes: 134600
import java.util.*;
class Main
{
	public static void main(String[] args)	
	{
        Scanner sc=new Scanner(System.in);
        while(true){
            String str = sc.nextLine();
        if(str.equals("0")) break;
        int sum = 0;
        for (int i = 0; i < str.length(); i++) {
             char a = str.charAt(i);
        if (Character.isDigit(a)) {
            int n = Integer.parseInt(String.valueOf(a));
            sum = sum + n;
            }
        }
            System.out.println(sum);
        }
    }
}


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

int main() {
    int n;
    cin >> n;
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
    for (int i = 0, a; i < n; i++) {
        cin >> a;
        q.emplace(a, i % 2);
    }
    int result = 0;
    for (int i = 0; i < n; i++) {
        if (q.top().second != i % 2) {
            result++;
        }
        q.pop();
    }
    cout << result / 2;
    return 0;
}

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

int main() {
	// your code goes here
	char a,b,c;
	c = '-';
	cin >> a >> b >> c;
	if(c == '-'){
		cout << a << b << '\n';
	}else{
		cout << c << b << a << '\n';
	}
	return 0;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	ll N=in(),W=in();
	vector<pair<ll,ll>> P[4];
	ll w0=-1;
	REP(i,N){
		ll u=in(),v=in();
		if(w0<0) w0=u;
		P[u-w0].emplace_back(u,v);
	}
	REP(i,4){
		sort(ALL(P[i]),PAIRCOMP(second,>));
	}
	int M[4];
	vector<pair<ll,ll>> S[4];
	REP(i,4){
		M[i]=P[i].size();
		S[i].resize(M[i]+1);
		S[i][0]=make_pair(0,0);
	}
	REP(i,4){
		for(int j=0;j<M[i];j++){
			S[i][j+1]= make_pair(S[i][j].first+P[i][j].first,S[i][j].second+P[i][j].second);
		}
	}

	ll ans=0;
	REP(a,M[0]+1){
		REP(b,M[1]+1){
			REP(c,M[2]+1){
				REP(d,M[3]+1){
					ll weight = S[0][a].first+S[1][b].first+S[2][c].first+S[3][d].first;
					ll value = S[0][a].second+S[1][b].second+S[2][c].second+S[3][d].second;
					if(weight<=W){
						ans = max(ans,value);
					}
				}
			}
		}
	}
	
	out(ans);
	return 0;
}


Measured memory_bytes: 256
/*input
async layered coding
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
int main()
{
	IOS;
	int n,m;
	cin>>n>>m;
	cout<<(n-1)*(m-1);
	return 0;
}


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

int main()
{
 int a, b,c;
 cin >> a >> b >> c;
 int tot = a + b;
 int tota = b + c;
 int total = c + a;
int ans = min(min(tot,tota),total);
cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
		int[] x = new int[3];
		x[0] = sc.nextInt();
		x[1] = sc.nextInt();
		x[2] = sc.nextInt();
		int answer = 0;
		Arrays.sort(x);

		while (x[0] != x[1] || x[1] != x[2]) {
			if (x[1] == x[2]) {
				x[0] += 2;
			} else {
				x[0] += 1;
				x[1] += 1;
			}
			answer++;
			Arrays.sort(x);
		}

		System.out.println(answer);
  }
}


Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#define int long long
using namespace std;

signed main() {
  int N, K;
  cin >> N >> K;
  
  int ans = 0;
  for (int i = K; i < N; ++i) {
    int B = i + 1;
    ans += (N / B) * (B - K);
    if (K == 0) ans += N % B;
    if (0 < K && K <= N % B) ans += N % B - K + 1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define N 200005
#define mod 998244353
#define rep(i, l, r) for(int i=l; i<=r; ++i)
using namespace std;
int t;
int n, k;
int l[11], r[11];
int f[N], s[N];
int main(){
	scanf("%d%d", &n, &k);
	rep(i, 1, k){
		scanf("%d%d", &l[i], &r[i]);
	}
	s[1]=f[1]=1;
	rep(i, 2, n){
		rep(j, 1, k){
			if(i>l[j]){
				if(i>r[j]) f[i]=((f[i]+s[i-l[j]]-s[i-r[j]-1])%mod+mod)%mod;
				else f[i]=(f[i]+s[i-l[j]])%mod;
			} 
		}
		//printf("%d %d\n", i, f[i]);
		s[i]=(s[i-1]+f[i])%mod;
	}
	printf("%d", f[n]);
	return 0;
}
	

Measured memory_bytes: 3284
while True:
    n, x = map(int, input().split())
    ans = 0
    if n == 0 and x == 0:
        break
    else:
        for i in range(1, n+1):
            for j in range(i+1, n+i):
                for k in range(j+1, n+1):
                    if i+j+k == x:
                        ans += 1
    print(ans)



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

int main(){
	int a,b,c,t=0;
	cin>>a>>b>>c;
	if(a!=b) t++;
	if(a!=c) t++;
	if(b!=c) t++;
	if(t==0) t++;
	cout<<t<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> LLP;

// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;
// const double PI = M_PI;

int N;
vector<string> S;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  S.resize(N);
  rep(i, N) { cin >> S[i]; }

  int c0 = 0;
  int c1 = 0;
  int c2 = 0;
  int c3 = 0;

  rep(i, N) {
    if (S[i] == "AC") {
      c0++;
    } else if (S[i] == "WA") {
      c1++;
    } else if (S[i] == "TLE") {
      c2++;
    } else {
      c3++;
    }
  }

  cout << "AC x " << c0 << endl;
  cout << "WA x " << c1 << endl;
  cout << "TLE x " << c2 << endl;
  cout << "RE x " << c3 << endl;
  return 0;
}


Measured memory_bytes: 5160
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
int a[100];
int main(){
	REP(i,3) {
		cin >> a[i];
	}
	sort(a,a + 3);
	cout << a[0] + a[1] << endl;
	return 0;
}


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

int main()
{
    std::string S;
    std::cin >> S;
    long len=S.length();
    std::string temp1,temp2;
    temp1=S[0];
    long counter=1;
    for(long i=1; i<len;i++){
        temp2+=S[i];
        if(temp1!=temp2){
            counter++;
            temp1=temp2;
            temp2="";
        }
    }
    std::cout << counter << std::endl;
    return 0;
}

Measured memory_bytes: 640
def main():
  n, m, k = map(int, raw_input().split())
  alst = [0] + [int(raw_input()) for _ in range(n)]
  INF = 10 ** 15
  dp = [INF] * (n + 1)
  dp[0] = 0
  for i in range(1, n + 1):
    a = b = alst[i]
    diff = 0
    x = k
    dpi = INF
    limit = i - m - 1 if i > m else -1
    for j in range(i - 1, limit, -1):
      x += diff
      if dpi > dp[j] + x:
        dpi = dp[j] + x
      temp = alst[j]
      if temp > b:
        diff = temp - a
        x = diff * (i - j) + k
        b = temp
        continue
      if a > temp:
        diff = b - temp
        x = diff * (i - j) + k
        a = temp

    dp[i] = dpi
  print dp[n]

main()


Measured memory_bytes: 6576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vp;
typedef map<ll, ll> mll;
typedef map<string, ll> mstrll;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fir first
#define sec second
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
#define out(x) cout << (x)
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
ll gcd(ll a, ll b){return b != 0 ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}
const ll INF = 1e16;
const ll MOD = 1e9 + 7;
ll a, b, c, n, m, x, y, z, w, h, ans, cnt, mx, mn;
string s, t;
vll dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
//vll dx = {-1, 0, 1, -1, 1, -1, 0, 1}, dy = {-1, -1, -1, 0, 0, 1, 1, 1};

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> n){
        ans = 1;
        rep(i, n){
            cin >> a;
            ans = lcm(ans, a);
        }
        print(ans);
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
   int x[10];
   for(int i=1;i<=5;i++) cin>>x[i];
   for(int i=1;i<=5;i++){
      if(!x[i]){
         cout<<i;
         break;
      }
   }
   return 0;
}

Measured memory_bytes: 3520
#include<stdio.h>
int main(void){
    int S,s,m,h;
    scanf("%d",&S);
    s=S%60;
    S/=60;
    m=S%60;
    h=S/60;
    printf("%d:%d:%d\n",h,m,s);
    return 0;
    
}


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

vector<ll> parent(100010,-1);
ll N, M, x, y;


ll find(ll x){
    return parent[x]<0?x:parent[x]=find(parent[x]);
}
void unite(ll x, ll y){
    x = find(x), y = find(y);
    if(x != y){
        if (parent[x] > parent[y]) swap(x,y);
        parent[x] += parent[y];
        parent[y] = x;
    }
}
ll size(ll x){
    return -parent[find(x)];
}

int main() {
    cin >> N >> M;
    ll A[100010];
    ll B[100010];
    vector<ll> ans;

    REP(i,M){
        cin >> A[i] >> B[i];
        A[i]--; B[i]--;
    }

    ll t = (N*(N-1))/2;
    REP(i,M){
        ans.push_back(t);
        ll x = A[M-i-1], y = B[M-i-1];
        if(find(x)!=find(y)){
            t -= size(x)*size(y);
            unite(x,y);
        }
    }
    reverse(ans.begin(),ans.end());
    for (auto& it: ans){cout << it << endl;}
    return 0;
}


Measured memory_bytes: 4596
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rrep(i, n) for (ll i = n - 1; i >= 0; i--)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define RRep(i, r, n) for (ll i = n - 1; i <= r; i--)
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define int long long
#define pb push_back
#define mp make_pair
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
const int MOD = (1000000007);
//const int MOD = (998244353);
//const int INF = (1 << 30)-1;
const int INF = (1LL << 60)-1;
const double EPS = (1 >> 30);

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

using Graph = vector<vector<pair<int, int>>>;

using Ki = vector<vector<int>>;
using Vi = vector<int>;
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    //---------------------------------------------
    
    int a,b;
    cin>>a>>b;
    cout<<6-a-b<<endl;
    
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <memory.h>
#include <functional>

using namespace std;

//FILE * in = freopen("B", "r", stdin);

typedef pair<int,int> P;

int n, m;
int cnt = 0;
int data[100][100];
int check[100][100];

int mvx[] = {-1, 0, 1, -1, 1, -1, 0, 1};
int mvy[] = {-1, -1, -1, 0, 0, 1, 1, 1};

void input() {
	for(int i = 0; i < m; i++){
		for(int j = 0; j < n; j++) {
			scanf("%d", &data[i][j]);
		}
	}
	cnt = 0;
	memset(check, 0, sizeof(check));
}

void bfs(int x, int y) {
	queue<P> que;
	que.push(P(x,y));
	check[x][y] = 1;
	while(!que.empty()){
		P cur = que.front(); que.pop();
		for(int i = 0; i < 8; i++) {
			if(cur.first + mvx[i] >= 0 && cur.first + mvx[i] < m && cur.second + mvy[i] >= 0 && cur.second + mvy[i] < n
				&& data[cur.first + mvx[i]][cur.second + mvy[i]] && !check[cur.first+mvx[i]][cur.second+mvy[i]]){
					check[cur.first +mvx[i]][cur.second+mvy[i]] = 1;
					que.push(P(cur.first+mvx[i], cur.second+mvy[i]));
			}
		}
	}
}

void process() {
	for(int i = 0; i < m; i++) {
		for(int j = 0; j < n; j++) {
			if(data[i][j] && !check[i][j]) {
				bfs(i,j);
				++cnt;
			}
		}
	}
	printf("%d\n", cnt);
}

int main() {
	while(true) {
		scanf("%d%d", &n, &m);
		if(n == 0) break;
		input();
		process();
	}
	return 0;
}

Measured memory_bytes: 1096
#! /usr/bin/env python3
import sys
sys.setrecursionlimit(10**9)


INF=10**20
def solve(S: str):
    if S == "RRR":  
        print(3)
    elif S[1:3] == "RR" or S[0:2] == "RR":
        print(2)
    else:
        ans = 0
        for s in S:
            if s == "R":
                ans = 1
        print(ans)
 
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)



if __name__ == "__main__":
    main()


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

string s,t,u;
int a,b;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

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

    return 0;
}

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

int main() {
  int  n;
  double n1;
  cin >> n;
  n1 = n;
  if(n%2) cout <<(n1+1)/2/n1 << endl;
  else cout << n1/2/n1 << endl;
}

Measured memory_bytes: 764
#include <iostream>
#include <cstdio>
const int A=1000000007;
using namespace std;

int main()
{
     long long s,c;
    scanf("%lld %lld",&s,&c);
    if (2*s>=c) {
        printf("%lld",c/2);
        return 0;
    }
    if (2*s<c) {
        c=c-2*s;
        c=c/4;
        printf("%lld",c+s);
        return 0;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const ll INF=(ll)(1e18);

int main()
{
    ll a,b,c,k,d,e,f,n,m,t;
    cin>>n>>k;
    ll arr[n+5];
    ll cost[n+5]={INF};
    for(int i=1;i<=n;i++) 
    {
        cin>>arr[i];
        cost[i]=INF;
    }
    c=0;
    
    
    cost[1]=0;
    cost[2]=abs(arr[2]-arr[2-1]);
    
    for(int i=3;i<=n;i++)
    {
        t=k;
        while(t>0)
        {
            if(i-t>0)
            cost[i]=min(cost[i-t]+abs(arr[i]-arr[i-t]),cost[i]);
            //else cost[i]=min(cost[i],arr[i]);
            
            t--;
        }
        
    }
    
    
    
    
    
    
    cout<<cost[n];
    
    
    
    return 0;
}

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

int main(){
	int H, W;
	cin >> H >> W;
	char a[H][W];
	rep(i,H)rep(j,W) cin >> a[i][j];

	rep(i,W+2) cout << '#';
	cout << "\n";
	rep(i,H){
		cout << '#';
		rep(j,W) cout << a[i][j];
		cout << "#\n";
	}
	rep(i,W+2) cout << '#';
	cout << "\n";

	return 0;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
int main() {
  char c;
  cin >> c;
  if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
  return 0;
}

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

int main()
{
    bool f=0;
    int n;cin>>n;
    char c;
    while(n--)
    {
        cin>>c;
        if(c=='Y')f=1;
    }
    if(f)cout<<"Four";
    else cout<<"Three";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SZ(a) ((int)(a).size())
int main(){
#ifdef LOCAL
  freopen(".a.in", "r", stdin);
#endif
  ios_base::sync_with_stdio(false),cout.tie(0),cin.tie(0);
  int64_t n,d;
  cin>>n>>d;
  int res=0;
  for(int i=0;i<n;++i){
    int64_t x,y;cin>>x>>y;
    if(x*x+y*y<=d*d)res++;
  }
  cout<<res<<'\n';
  
  return 0;
}
//2020.08.02 20:02:20


Measured memory_bytes: 3652
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 505
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;
}
const int n=read(),mod=read();
int dp[N][N>>1],ans;
pair<int,int> p[N];
int getF(int x){
	int tmp=2*n-1;
	while(x*x+tmp*tmp>4*n*n)--tmp;
	return tmp+1;
}
int getG(int x){
	int tmp=2*n-1;
	while(x*x+tmp*tmp>=n*n)--tmp;
	return tmp+1;
}
int main(){
	for(int i=0;i<(n<<1);++i){
		if(i<n)p[i]=make_pair(getG(i),getF(i));
		else p[i]=make_pair(getF(i),0);
	}
	sort(p,p+(n<<1));
	for(int k=0;k<=n;++k){
		memset(dp,0,sizeof(dp));
		dp[0][0]=1;
		int c1=0,c2=0;
		for(int i=0;i<(n<<1);++i){
			if(!p[i].second){
				for(int j=0;j<=k;++j){
					dp[i+1][j]=(dp[i+1][j]+1LL*dp[i][j]*(p[i].first-j-c1))%mod;
				}
				++c1;
			}
			else{
				for(int j=0;j<=k;++j){
					dp[i+1][j]=(dp[i+1][j]+1LL*dp[i][j]*(p[i].second-k-n-(c2-j)))%mod;
					dp[i+1][j+1]=(dp[i+1][j+1]+1LL*dp[i][j]*(p[i].first-c1-j))%mod;	
				}
				++c2;
			}
		}	
		ans=(ans+(k&1?-1:1)*dp[n<<1][k])%mod;
	}
	printf("%d\n",(ans+mod)%mod);
	return 0;
}


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

using namespace std;
vector<vector<int>> G;
vector<int> ret1, ret2;
vector<int> used;

void dfs(int x) {
    for(int y : G[x]) {
        if(used[y] == 0) {
            ret1.push_back(y);
            used[y] = 1;
            dfs(y);
            break;
        }
    }
    return;
}

void dfs2(int x) {
    for(int y : G[x]) {
        if(used[y] == 0) {
            ret2.push_back(y);
            used[y] = 1;
            dfs2(y);
            break;
        }
    }
    return;
}

int main() {
    int n, m;
    cin >> n >> m;
    G.resize(n+1);
    used.resize(n+1,0);
    for(int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    used[0] = 1;
    ret1.push_back(0);
    dfs(0);
    dfs2(0);
    reverse(ret2.begin(), ret2.end());
    cout << ret1.size() + ret2.size() << endl;
    for(int x : ret2) {
        cout << x + 1 << " ";
    }
    for(int x : ret1) {
        cout << x + 1 << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 9976
N = int(input())
A = [int(i) for i in input().split()]

while True:
    A = list(set(A))
    A.sort()
    if 0 in A:
        A.remove(0)
    if len(A) == 1:
        print(A[0])
        exit()

    A0 = A[0]
    i = 1
    for a in A[1:]:
        A[i] = a % A0
        i += 1


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

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String w = sc.nextLine();
		String p;
		List<String> temp = new ArrayList<String>();
		while( !(p = sc.nextLine()).equals("END_OF_TEXT")){
			for(String in : p.split(" ")){
				temp.add(in);
			}
		}
		int ans = 0;
		for(String str : temp){
			if(str.equalsIgnoreCase(w)){
				ans++;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 26100
class ACGTHashList {
  static get MAP() {
    return {
      'A': 1,
      'C': 2,
      'G': 3,
      'T': 4,
    }
  }

  constructor(M) {
    this.M = M;
    this.H = [];
    for (let i = 0; i < M; i++) this.H[i] = '';
  }

 static _getKey(str) {
   let sum = 0;
   let p = 1;
   for (let i = 0, p = 1; i < str.length; i++, p *= 5) sum += p * ACGTHashList.MAP[str[i]];
   return sum;
 }

 _h1(key) { return key % this.M;}

 _h2(key) { return 1 + key % (this.M - 1);}

 find(str) {
   let key = ACGTHashList._getKey(str);
   let h;
   const h1 = this._h1(key), h2 = this._h2(key);
   for (let i = 0;; i++) {
     h = (h1 + i * h2) % this.M;
     if (this.H[h] === str) return 1;
     else if (this.H[h] === '') return 0;
   }
   return 0;
 }

 insert(str) {
   let key = ACGTHashList._getKey(str);
   let h;
   const h1 = this._h1(key), h2 = this._h2(key);
   for (let i = 0;; i++) {
     h = (h1 + i * h2) % this.M;
     if (this.H[h] === str) return 1;
     else if (this.H[h] === '') {
       this.H[h] = str;
       return 0;
     }
   }
   return 0;
 }

}

(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8');
  var Arr=(lines.trim()).split("\n").slice(1);
  const commands = Arr.map(l => l.split(' '));

  let hl = new ACGTHashList(1046527);
  commands.forEach(cmd => {
    if (cmd[0][0] === 'i') {
      hl.insert(cmd[1]);
    } else {
      console.log(hl.find(cmd[1]) ? 'yes' : 'no');
    }
  });
})();



Measured memory_bytes: 389576
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
 
public class Main {
 
    void solve() throws IOException {
        int x1 = ni();
        int x2 = ni();
        int x3 = ni();
        int x4 = ni();
        int x5 = ni();
        if(x1 == 0){
            out.println(1);
        }else if(x2 ==0){
            out.println(2);
        }else if(x3 ==0){
            out.println(3);
        }else if(x4 ==0){
            out.println(4);
        }else if(x5 ==0){
            out.println(5);
        }

    }

 
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 32628
import numpy as np

N, K = map(int, input().split())
K2 = 2 * K
Mij = [[0 for _ in range(K2 + 1)] for _ in range(K2 + 1)]


def imos(x1, y1, x2, y2):
    Mij[y1][x1] += 1
    Mij[y2][x2] += 1
    Mij[y2][x1] -= 1
    Mij[y1][x2] -= 1

for _ in range(N):
    ls = input().split()
    x = int(ls[0]) % K2
    y = int(ls[1]) % K2
    if ls[2] == "B":
        y = (y + K) % K2
    x_ = x % K
    y_ = y % K

    if (x < K and y < K) or (K <= x and K <= y):
        imos(0, 0, x_ + 1, y_ + 1)
        imos(x_ + K + 1, 0, K2, y_ + 1)
        imos(0, y_ + K + 1, x_ + 1, K2)
        imos(x_ + K + 1, y_ + K + 1, K2, K2)
        imos(x_ + 1, y_ + 1, x_ + K + 1, y_ + K + 1)
    else:
        imos(x_ + 1, 0, x_ + K + 1, y_ + 1)
        imos(x_ + 1, y_ + K + 1, x_ + K + 1, K2)
        imos(0, y_ + 1, x_ + 1, y_ + K + 1)
        imos(x_ + K + 1, y_ + 1, K2, y_ + K + 1)

Mij = np.array(Mij)
for x in range(K2):
    Mij[:, x + 1] += Mij[:, x]
for y in range(K2):
    Mij[y + 1, :] += Mij[y, :]

print(Mij.max())

Measured memory_bytes: 75992
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int n = sc.nextInt();
		int[] list = new int[n];
		for(int i = 0; i < n-1; i++) {
			int ch = sc.nextInt();
			if(list[i] > ch && i!=0) {
				list[i] = ch;
			}else if(i == 0) {
				list[0] = ch;
			}
			list[i+1] = ch;
		}
		
		int sum = Arrays.stream(list).sum();
		pw.print(sum);
		pw.close();
	}
	
	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;

	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

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

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

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

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}

Measured memory_bytes: 27092
h,w = [int(x) for x in input().split()]
a = []
for _ in range(h):
    tmp = list(input())
    a.append(tmp)

ans = "Possible"
for i in range(h-1):
    for y in range(w-1):
        if a[i][y+1] == a[i+1][y] == "#":
            ans = "Impossible"
            break
print(ans)

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

int main() {
	int n;
	cin >> n;
	int h[100];
	int max = 0, min = 1000;
	for (int i = 0; i < n; i++) {
		cin >> h[i];

		if (max < h[i]) max = h[i];
		if (min > h[i]) min = h[i];
	}

	cout << max - min << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define IOS cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
int N,M; bool G[10][10];

int dfs(int v,int n,bool visited[10]){
    bool alvisited = true;
    rep(i,n) if(!visited[i]) {alvisited=false; break;}
    if(alvisited) return 1;
    int res=0;
    rep(i,n) {
        if(!G[v][i] || visited[i]) continue;
        visited[i]=true;
        res+=dfs(i,n,visited);
        visited[i]=false;
    }
    return res;
}

main() {
    cin >> N >> M;
    rep(i,M){
        int a,b; cin >> a >> b;
        a--; b--;
        G[a][b]=true;
        G[b][a]=true;
    }
    bool visited[N]; rep(i,N) visited[i]=false;
    visited[0]=true;
    cout << dfs(0,N,visited) << endl;
}

Measured memory_bytes: 256
#include <iostream>

int main(){
   int a, b, c, d;
   std::cin >> a >> b >> c >> d;

   if(abs(a-c)<=d) std::cout << "Yes" << std::endl;
   else if(abs(a-b)<=d && abs(b-c)<=d) std::cout << "Yes" << std::endl;
   else std::cout << "No" << std::endl;

   return 0;
}


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

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll d,g;
    cin >> d>>g;
    g /=100;
    ll p[d],c[d];
    ll mn=INF;
    ll curSum = 0;
    ll curP = 0;
    F0R(i,d) {cin >>p[i]>>c[i]; c[i] /=100;}
    F0R(i,1<<d){
      curSum = 0;
      curP =0;
      ll highestUnpack = -1;
      F0R(j,d){
        if((i >>j & 1) == 1){
          curP +=p[j];
          curSum +=p[j]*(j+1) + c[j];
        } else {
          highestUnpack = j;
        }
      }
      if(curSum < g){
        if(highestUnpack == -1) continue;
        if((g-curSum)/(highestUnpack+1) > p[highestUnpack]) continue;
        ll numberUnpack = (g-curSum+highestUnpack)/(highestUnpack+1);
        curP +=numberUnpack;
      }
      if(mn > curP) mn = curP;
    }

    cout << mn<<endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


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

using namespace std;

int merge(int a[], int l, int m, int r){
    int n1 = m - l, n2 = r - m;
    int L[n1+1], R[n2+1];
    rep(i, 0, n1) L[i] = a[l + i];
    rep(i, 0, n2) R[i] = a[m + i];
    L[n1] = LLONG_MAX;
    R[n2] = LLONG_MAX;
    int i = 0, j = 0;
    int cnt = 0;
    rep(k, l, r){
        if(L[i] <= R[j]) a[k] = L[i++];
        else {
            a[k] = R[j++];
            cnt += n1 - i;
        }
    }
    return cnt;
}

int merge_sort(int a[], int l, int r){
    int cnt = 0;
    if(l + 1 < r){
        int m = (l + r)/2;
        cnt += merge_sort(a, l, m);
        cnt += merge_sort(a, m, r);
        cnt += merge(a, l, m, r);
    }
    return cnt;
}

signed main(){
    int n; cin >> n;
    int a[n]; rep(i, 0, n) scanf("%ld", &a[i]);

    cout << merge_sort(a, 0, n) << endl;
    return 0;
}


Measured memory_bytes: 6288
#include <bits/stdc++.h>
#define range(i, a, n) for(int (i) = (a); (i) < (n); (i)++)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

using Cost = tuple<int, int, int>;

int h, w;
vector<string> field;
vector<vector<Cost>> cost;
vector<vvi> time_visited;
vector<pii> task;

vi dx = { 1, 0,-1, 0};
vi dy = { 0,-1, 0, 1};

bool dfs(pii pos, pii z, vector<pii> & route, vvi & used){
    if(used[pos.first][pos.second]) return false;
    used[pos.first][pos.second] = true;
    if(pos == z){
        route.push_back(pos);
        return true;
    }

    rep(i, 4){
        pii npos(pos.first + dy[i], pos.second + dx[i]);

        if(npos.first < 0 || h <= npos.first ||
           npos.second< 0 || w <= npos.second||
           field[npos.first][npos.second] == '#'){
            continue;
        }

        if(dfs(npos, z, route, used)){
            route.push_back(pos);
            return true;
        }
    }

    return false;
}

int main(void){
    int m; cin >> h >> w >> m;

    field = vector<string>(h);
    for(auto & e : field) cin >> e;

    cost = vector<vector<Cost>>(h, vector<Cost>(w));
    rep(y, h) rep(x, w) cin >> get<0>(cost[y][x]);
    rep(y, h) rep(x, w) cin >> get<1>(cost[y][x]);
    rep(y, h) rep(x, w) cin >> get<2>(cost[y][x]);

    task = vector<pii>(m);
    for(auto & e : task) cin >> e.first >> e.second;

    time_visited = vector<vvi>(h, vvi(w));
    pii pos = task[0];
    int t = 0;
    time_visited[pos.first][pos.second].push_back(t++);

    rep(i, m){
        vector<pii> route;
        vvi used(h, vi(w));

        dfs(pos, task[i], route, used);
        reverse(begin(route), end(route));

        for(auto & e : route){
            if(pos == e) continue;
            
            pos = e;
            time_visited[pos.first][pos.second].push_back(t++);
        }
    }

    int res = 0;
    rep(y, h){
        rep(x, w){
            int c_on, c_off, c_keep;
            tie(c_keep, c_on, c_off) = cost[y][x];

            if((int)time_visited[y][x].size() == 0) continue;

            res += c_on;
            rep(i, (int)time_visited[y][x].size() - 1){
                int diff = time_visited[y][x][i + 1] - time_visited[y][x][i];

                res += min(c_off + c_on, c_keep * diff);
            }
            res += c_off;
        }
    }

    cout << res << endl;

	return 0;
}

Measured memory_bytes: 8328
/// Coded by Dhiman Sarker Bappy (Dhimanda) - RMSTU

#include<bits/stdc++.h>
using namespace std;
#define in_file freopen("input.txt", "r", stdin)
#define out_file freopen("output.txt", "w", stdout)
#define    F    first
#define    S    second
#define    pb    push_back
#define    popb    pop_back
#define    pf    push_front
#define    popf    pop_front
#define    lcm(a,b)    (a*b)/gcd(a,b)
#define    gcd(a,b)    __gcd(a,b)
#define    pi    2*acos(0)
#define    elif    else if
#define    ll    long long
int Int(){int x;scanf("%d", &x);return x;}
#define Int Int()
#define mx 100010
int arr[mx];
int tree[mx*4];
void init(int node,int b,int e){
    if(b==e){
        tree[node]=arr[e];
        return;
    }
    int lft = node *2;
    int rgt = lft + 1;
    int mid = (b+e)/2;
    init(lft,b,mid);
    init(rgt,mid+1,e);
    tree[node] = min(tree[lft],tree[rgt]);
}

int q(int node,int b,int e,int l,int r){
    if(l > e | r < b){
        return mx;
    }
    if(b >= l && e<=r){
        return tree[node];
    }
    int lft = node *2;
    int rgt = lft + 1;
    int mid = (b+e)/2;
    int x = q(lft,b,mid,l,r);
    int y = q(rgt,mid+1,e,l,r);
    return min(x,y);
}
 int main()
{
    //in_file;
    //out_file;
    int t=Int;
    int kase = 0;
    while(t--){
        //printf("Case %d:\n" , ++kase);
        int n[3];
        cin >>n[0] >>n[1] >> n[2];
        sort(n , n+3);
        if (n[2]*n[2] == (n[0] * n[0] + n[1] * n[1] )) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;

    }
    return 0;
}



Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int a[N], b[N], n, m, v[N];
long long cnt[N][2];
vector<int> G[N];
int p1, p2, len;
long long dfs(int x, int p = 0, int d = 0) {
		++ cnt[x][d & 1];
		long long res = 0;
		for (int u=0;u< G[x].size();++u) {
			if (G[x][u] == p) continue;
			if (x == p1 && G[x][u] == p2) continue;
			if (x == p2 && G[x][u] == p1) continue;
			res += dfs(G[x][u], x, d + 1);
			cnt[x][0] += cnt[G[x][u]][0];
			cnt[x][1] += cnt[G[x][u]][1];
			res += abs(cnt[G[x][u]][0] - cnt[G[x][u]][1]);
		}
		return res;
}
void dfs2(int x, int p = 0) {
	v[x] = v[p] + 1;
	for (int u=0;u< G[x].size();++u) {
		if (G[x][u] == p) continue;
		if (v[G[x][u]]) {
			p1 = x;
			p2 = G[x][u];
			len = v[x] - v[G[x][u]] + 1;
		}
		else dfs2(G[x][u], x);
	}
}
long long calc(long long x) {
	memset(cnt, 0, sizeof(cnt));
	cnt[p1][0] += x;
	cnt[p2][1] += x;
	return dfs(1) + abs(x);
}
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; ++ i) {
		int u, v;
		
		scanf("%d%d", &u, &v);
		a[i] = u, b[i] = v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	if (m == n - 1) {

		long long ans = dfs(1);
		if (cnt[1][0] != cnt[1][1]) return 0 * puts("-1");
		printf("%lld\n", ans);
	}
	else {
		dfs2(1);
		dfs(1);
		if (len & 1) {
			if (abs(cnt[1][0] - cnt[1][1]) & 1) return 0 * puts("-1");
			long long del = (cnt[1][0] - cnt[1][1]) / 2;																						memset(cnt, 0, sizeof(cnt));
			cnt[p1][0] -= del;
			cnt[p2][0] -= del;
			long long ans = dfs(1) + abs(del);
			printf("%lld\n", ans);
		}
		else {
			if (cnt[1][0] != cnt[1][1]) return 0 * puts("-1");
			long long l = - 1e9, r = 1e9, ans = 1e18;
			while (l + 10 <= r) {
				long long midl = (l + r) / 2;
				long long midr = (midl + r) / 2;
				long long res1 = calc(midl);
				long long res2 = calc(midr);
				ans = min(ans, res1);
				ans = min(ans, res2);
				if (res1 < res2) {
					r = midr - 1;
				}
				else {
					l = midl + 1;
				}
			}
			for (int i = l; i <= r; ++ i) ans = min(ans, calc(i));
			printf("%lld\n", ans);
		}
	}
}


Measured memory_bytes: 16256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

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


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<math.h>
using namespace std;
int main() {
	int N;
	while (cin >> N, N) {
		int card[201];
		int ba=0;
		for (int i = 0; i < 201; i++)
			card[i] = 0;
		for (int i = 0; i < N; i++) {
			int num;
			cin >> num;
			card[num]= 1;
		}
		int HPoint = N;
		int TPoint = N;
		int turn=1;
		while (TPoint&&HPoint) {
			int OK=0;
			for (int i = ba+1; i <= 2 * N; i++) {
				if (card[i] == 1 && turn == 1) {
					ba = i; HPoint--; card[i] = -1;  OK = 1; break;
				}
				else if (card[i] == 0 && turn == 0) {
					ba = i; TPoint--; card[i] = -1; OK = 1;break;
				}
			}
			if (OK == 0) ba = 0;
			if (turn == 0) turn = 1;
			else turn = 0;
		}
		cout << TPoint << endl << HPoint << endl;
	}
	return 0;
}


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

int main()
{
    int a, b;
    cin >> a >> b;
    if ((a + b) % 2 == 0)
    {
        cout << (a + b) / 2 << endl;
    }
    else
    {
        cout << (a + b) / 2 + 1 << endl;
    }
}

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

using namespace std;

int main(){

	int X;
	cin>>X;
	vector<bool>co(X+1,0);
	co[1]=1;
	
	for(int i=2;i<=(int)sqrt((double)X)+1;i++){
		int v=i*i;
		while(v<=X){
			co[v]=1;
			v*=i;
			
		}
	}

	for(int i=X;i>0;i--){
		if(co[i]){
			cout<<i<<endl;
			return 0;
		}
	}

	return 0;

}


Measured memory_bytes: 256