akhauriyash/Code-Regression huggingface dataset:
n=int(input())
l=[1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 5, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 6, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 5, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 7, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 5, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 6, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 5, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 8, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 5, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 6, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 5, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 7, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 5, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 6, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 5, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 9, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 5, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 6, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 5, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 7, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 5, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 6, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 5, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 8, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 5, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 6, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 5, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 7, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 5, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 6, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1, 5, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2]
for i in range(n):
    print(*l[:n-i-1])

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

int main(){
    while(1){
        int x, y;
        cin >> x >> y;
        
        if(x == 0 && y == 0) break;
        else if (x < y) cout << x << " " << y << endl;
        else cout << y << " " << x << endl;
    }
    return 0;
}


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


int main()
{
   string s;
   cin >> s;
   if(s=="MON") cout << 6 ;
   if(s=="TUE") cout << 5 ;
   if(s=="WED") cout << 4 ;
   if(s=="THU") cout << 3 ;
   if(s=="FRI") cout << 2 ;
   if(s=="SAT") cout << 1 ;
   if(s=="SUN") cout << 7 ;

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;

public static class P
{
    public static void Main()
    {
        Console.WriteLine(Console.ReadLine().Split().Select(int.Parse).Any(x => x % 2 == 0) ? "Even" : "Odd");
    }
}


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

long long N, K;
long long nr[2009][2009];
long long mod = 1000000007;

void init() {
	for (int i = 0; i <= 2000; i++) {
		for (int j = 0; j <= 2000; j++) {
			if (i == 0 || j == 0) nr[i][j] = 1;
			else nr[i][j] = (nr[i - 1][j] + nr[i][j - 1]) % mod;
		}
	}
}

long long ncr(long long n, long long r) {
	if (r < 0 || n < r) return 0;
	return nr[n - r][r];
}

int main() {
	cin >> N >> K;
	init();

	if (N == K) {
		cout << "1" << endl;
		for (int i = 2; i <= K; i++) cout << "0" << endl;
	}
	else {
		for (int i = 1; i <= K; i++) {
			long long v1 = ncr(K - 1, i - 1);
			long long v2 = ncr(N - K - 1, i - 2);
			long long v3 = ncr(N - K - 1, i - 1);
			long long v4 = ncr(N - K - 1, i);
			cout << v1 * (v2 + v3 + v3 + v4) % mod << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 31616
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "Yes" << endl;
#define POK cout << "OK" << endl;
#define PNO cout << "No" << endl;
#define PNG cout << "NG" << endl;

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

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

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;

// const
// 円周率
const double pi = M_PI;
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)

int main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int a,b;
  cin >> a >> b;
  cout << a*b << endl;

  return 0;
}


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

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> A(M);
  int i,cost;
  cost=0;
  for(i=0;i<M;i++){
    cin >> A.at(i);
    cost=cost+A.at(i);
  }
  if(N-cost<0){
    cout << -1 << endl;
  }
  else {
    cout << N-cost << endl;
  }
  return 0;
}

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

typedef long long ll;

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

int main() {
  int n, k;
  cin >> n >> k;
  if (n % k == 0) cout << "0" << endl;
  else cout << "1" << endl;
  return 0;
}


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

int main(){

    long long K, A, B;
    cin >> K >> A >> B;

    long long viscuit = 1;
    if(A + 1 < B){
        for(long long i = 0; i < K; i++){
            if(viscuit >= A && i + 1 < K){
                viscuit += B - A;
                i++;
            }else{
                viscuit++;
            }
        }
    }else{
        viscuit += K;
    }

    cout << viscuit << endl;

    return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "functional"
#include "ctime"

using namespace std;

//constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> N;
	vector<long long int>v(N);
	for (auto &i : v)cin >> i;
	K = accumulate(v.begin(), v.end(), 0LL)*accumulate(v.begin(), v.end(), 0LL);
	for (auto i : v)K -= i * i;
	cout << K / 2 << endl;
}

Measured memory_bytes: 256
N,s,t = map(int,input().split())

LIST=[]

print("?",s,t,flush=True)
d0=int(input())

for i in range(1,N+1):
    if i==s or i==t:
        continue
    print("?",s,i,flush=True)
    d1=int(input())
    print("?",t,i,flush=True)
    d2=int(input())

    if d1+d2==d0:
        LIST.append([d1,i])

LIST.sort()
ANS=[]

NOW=s
NOWd=0

for d,ans in LIST:
    print("?",NOW,ans,flush=True)
    d1=int(input())
    print("?",ans,t,flush=True)
    d2=int(input())

    if d1+d2==d0-NOWd:
        ANS.append(ans)
        NOWd+=d1
        NOW=ans

print("!",s,*ANS,t)



    



Measured memory_bytes: 5636
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define str string
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define all(x) x.begin(),x.end()
int main(){
  int A,B,C,D;
  str N,N2;
  cin>>N;
  if(N[0]==N[1]&&N[1]==N[2])cout<<"Yes"<<endl;
  else if(N[3]==N[2]&&N[1]==N[2])cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int a[200005], b[200005];
	for (int i=0; i<n; i++)
	{
		cin >> a[i];
		b[i]=a[i];
	}
	sort(a, a+n);
	for (int i=0; i<n; i++)
	{
		if (a[n-1]==b[i])
			cout << a[n-2] << endl;
		else
			cout << a[n-1] << endl;
	}
	return 0;
}

Measured memory_bytes: 3200
N = int(input())
XS = list(map(int, input().split()))
mid_low = sorted(XS)[len(XS) // 2 - 1]
mid_high = sorted(XS)[len(XS) // 2]
for x in XS:
    if x <= mid_low:
        print(mid_high)
    else:
        print(mid_low)


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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef pair<ii, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef map<ll, ll> mpii;
typedef unordered_map<ll, ll> umpii;

#define pb(v) push_back(v)
#define all(v) v.begin(), v.end()
#define upb(v, key) (upper_bound(all(v), key) - v.begin())
#define lob(v, key) (lower_bound(all(v), key) - v.begin())

ll inf = 1e9;
ll INF = inf * 1ll * inf;
ll mod = 1e9 + 7;
double eps = 1e-9;
const ld pi = ld(3.1415926535897932384626433832795);
ll dr[] = {-1, 0, 0, 1};
ll dc[] = {0, 1, -1, 0};

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}
template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)

/*...................................................*/
ll a[420], n, dp[420][420], pfix[420];

ll fn(ll l, ll r) {
  if(l >= r) return 0;
  ll &res = dp[l][r];
  if(res != -1) return res;
  res = INF;
  for(ll i = l; i < r; i++)
  res = min(res, fn(l, i) + fn(i + 1, r) + pfix[r] - pfix[l - 1]);
  
  return res;
}
int main()
{
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  
  ll t, m, i, j, k, q, u, v;
  // cin >> t;
  // ll tc = t;
  t = 1;
  while (t--)
  {
    cin >> n;
    for(i = 1; i <= n; i++)
    cin >> a[i];
    memset(dp, -1, sizeof(dp));
    pfix[0] = 0;
    for(i = 1; i <= n; i++)
    pfix[i] = pfix[i - 1] + a[i];
    cout << fn(1, n);
    
    // cout << "Case #" << tc - t << ": ";

    cout << '\n';
  }
  return 0;
}

Measured memory_bytes: 1664
fun main(args:Array<String>?): Unit {
    val (n, m) = readLine()!!.trim().split(' ').map(String::toInt)
    val professors = Array(m){
        val (a, b) = readLine()!!.trim().split(' ').map{it.toInt() - 1}
        Pair(a, b)
    }
    println(solve(n, professors) ?: "Impossible")
}
fun solve(room: Int, professors: Array<Pair<Int, Int>>): Int? {
    val sorted = professors.sortedBy{it.first}
    tailrec fun sub(current: Int, covered: Int, count: Int = 0): Int? {
        return if (covered == room - 1) count
        else if (current == professors.size) null
        else {
            val prof = (current until sorted.size).takeWhile{sorted[it].first <= covered + 1}
            if (prof.isNotEmpty()) sub(current + prof.size, prof.map { sorted[it].second }.max() ?: covered, count + 1)
            else null
        }
    }
    return sorted.takeWhile{it.first == 0}.map{it.second}.max()?.let{covered -> sub(0,  covered, 1)}
}


Measured memory_bytes: 34588
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String st = sc.next();
		System.out.println((int)Math.min(st.length() - st.replace("1", "").length(),
			st.length() - st.replace("0", "").length()) * 2);
	}
}

Measured memory_bytes: 34760
N = input()
*A, = map(int,input().split(" "))
cnt = 0
end = 0
while end==0:
  f = 0
  for i in A:        #A = [8, 12, 40] 
    if(i % 2 == 1):
      end=1
    A[f] = i/2
    f += 1
  cnt+= 1
cnt-=1
print(cnt)

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

int main() {
  int n,d,x;
  cin >> n >> d >> x;
  rep(i,0,n){
    int a,v = 1;
    cin >> a;
    while(v <= d){
      x++;
      v += a;
    }
  }
  cout << x << endl;
}

Measured memory_bytes: 3576
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

const int N=101000;
int s[N];
int n,c,k,ans;
int main()
{
	scanf("%d%d%d",&n,&c,&k);
	for(int i=1;i<=n;i++)scanf("%d",s+i);
	std::sort(s+1,s+n+1);
	ans=0;
	for(int i=1,j;i<=n;i=j+1,ans++)
		for(j=i;j<n && j-i+1<c && s[j+1]-s[i]<=k;j++);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

main(){
  int n;
  cin >> n;
  while(n--){
    unsigned int N[9];
    for(int i=0;i<9;i++){
      string in;
      cin >> in;
      N[i] = 0U;
      for(int j=0;j<in.size();j++) N[i] = (N[i] << 4) + ('0' <= in[j] && in[j] <= '9' ? in[j]-'0' : in[j]-'a'+10);
    }
    unsigned int K = 0U;
    for(int i=0;i<32;i++){
      unsigned int t = 0;
      for(int j=0;j<8;j++) t += N[j] ^ K;
      if((t & (1U << i)) != (N[8] & (1U << i))) K |= (1U << i);
    }
    string ans;
    for(int i=0;i<32;i+=4){
      int tmp = 0;
      for(int j=0;j<4;j++){
        tmp <<= 1;
        if((K >> (i+3-j)) & 1) tmp |= 1;
      }
      ans += (tmp < 10 ? tmp + '0' : tmp - 10 + 'a');
    }
    reverse(ans.begin(), ans.end());
    for(int i=0;;i++){
      if(ans[i] != '0' || i+1 == ans.size()){
        ans = ans.substr(i);
        break;
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1200
// AOJ 2220: The Number of the Real Roots of a Cubic ...
// 2017.12.9 bal4u@uu

#include <stdio.h>

int p, m;

void equ1(int a, int b)
{
	if      (b == 0) p = m = 0;
	else if (b >  0) p = 0, m = 1;
	else             p = 1, m = 0;
}

void equ2(int a, int b, int c)
{
	if (c == 0) { equ1(a, b); return; }
	if (b*b - 4*a*c < 0) p = m = 0;
	else {
		if      (c < 0) p = m = 1;
		else if (b > 0) p = 0, m = 2;
		else            p = 2, m = 0;
	}
}

void equ(int a, int b, int c, int d)
{
	int e, f1, f2;
	long long delta;

	if (a < 0) { equ(-a, -b, -c, -d); return; }
	if (d == 0) { equ2(a, b, c); return; }

	delta = (long long)b*b*c*c - 4*(long long)a*c*c*c -
		    4*(long long)b*b*b*d - 27*(long long)a*a*d*d + 18*(long long)a*b*c*d;
	e = b*b - 3*a*c;

	f1 = f2 = 0;
	if (b*b < e) f1 = f2 = 1;
	else f1 = b < 0, f2 = b > 0;

	if (delta >= 0){
		if (e == 0){
			if (b > 0) p = 0, m = 3;
			else       p = 3, m = 0;
			return;
		}
		if (d > 0) {
			if (!f1) p = 0, m = 3;
			else     p = 2, m = 1;
		} else {
			if (!f2) p = 3, m = 0;
			else     p = 1, m = 2;
		}
	} else {
		if (d > 0) p = 0, m = 1;
		else       p = 1, m = 0;
	}
}

int main()
{
	int cno, a, b, c, d;;
	
    scanf("%d", &cno);
	while (cno-- > 0) {
		scanf("%d%d%d%d", &a, &b, &c, &d);
		equ(a, b, c, d);
		printf("%d %d\n", p, m);
	}
	return 0;
}

Measured memory_bytes: 1760
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 
 using namespace std;
 
 double abs(double x)
 {
   if(x<0) return -x;
   else return x;       
 }
  
 int main()
 {
   double v;
   while(cin>>v)
   {
     double t=v/9.8;
     double h=4.9*t*t;
     int N=(int)((h+5)/5)+1;
     cout<<N<<endl;
   }
   //while(1);      
   return 0;    
 }

 

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    while(true){
        priority_queue<pair<int, int>> pq;
        int N, M; cin >> N >> M;
        if(N == 0) break;
        int ans = 0;
        rep(i, N){
            int d, p; cin >> d >> p;
            pq.push(make_pair(p, d));
        }
        while(!pq.empty()){
            pair<int, int> op = pq.top();
            pq.pop();
            if(M == 0){
                ans += op.first*op.second;
            }
            else if(M < op.second){
                ans += (op.second - M)*op.first;
                M = 0;
            }
            else M -= op.second;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3188
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
def check(i):
  x = []
  for j in range(N):
    if i & (1 << j):
      x.append(b[j])
    else:
      x.append(a[j])
  sx = sorted(x)
  odd = [0] * 51
  even = [0] * 51
  for j in range(N):
    odd[sx[j]] += j % 2
    even[sx[j]] += (j % 2 == 0)
  for j in range(N):
    if i & (1 << j):
      if j % 2: even[x[j]] -= 1
      else: odd[x[j]] -= 1
    else:
      if j % 2: odd[x[j]] -= 1
      else: even[x[j]] -= 1
  return min(min(odd), min(even)) >= 0
class BIT:
  def __init__(self, n):
    self.n = n
    self.data = [0] * (n + 1)
    self.el = [0] * (n + 1)
  def sum(self, i):
    s = 0
    while i > 0:
      s += self.data[i]
      i -= i & -i
    return s
  def add(self, i, x):
    self.el[i] += x
    while i <= self.n:
      self.data[i] += x
      i += i & -i
  def get(self, i, j = None):
    if j is None:
      return self.el[i]
    return self.sum(j) - self.sum(i)
res = float("inf")
for i in range(pow(2, N)):
  if check(i) == False: continue
  fwk = BIT(N)
  t = 0
  odd = []
  even = []
  for j in range(N):
    if i & (1 << j):
      if j % 2: even.append((b[j], j))
      else: odd.append((b[j], j))
    else:
      if j % 2: odd.append((a[j], j))
      else: even.append((a[j], j))
  #print(t, i)
  odd.sort(key = lambda x: x[0])
  even.sort(key = lambda x: x[0])
  ind = []
  #print(t, i)
  for j in range(N):
    if j % 2: ind.append(odd[j // 2][1])
    else: ind.append(even[j // 2][1])
  #print(t, i, ind)
  for x in ind:
    t += fwk.get(x, N)
    fwk.add(x + 1, 1)
  res = min(res, t)
  #print(t, i)
if res == float("inf"): print(-1)
else: print(res)

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

#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

ll dp[100010][3];
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int d[n][3];
    rep(i,0,n) cin >> d[i][0] >> d[i][1] >> d[i][2];
    
    rep(j,0,n)rep(i,0,3)rep(k,0,3){
        if(i == k) continue;
        dp[j+1][i] = max(dp[j+1][i],dp[j][k]+d[j][i]);
    }

    cout << max(dp[n][0],max(dp[n][1],dp[n][2])) << endl;
    
}

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vdb = vector<db>;
using vvll = vector<vll>;
using vst = vector<st>;
using vchar = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
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;}
const ll mod = 1000000007;
const ll inf = 1LL << 60;

int main() {
  ll h, n;
  cin >> h >> n;
  vll a(n + 1), b(n + 1);
  rep(i, 1, n + 1) cin >> a.at(i) >> b.at(i);

  vvll dp(n + 1, vll(h + 10001, inf));
  dp.at(0).at(0) = 0;
  rep(i, 1, n + 1)rep(j, 0, h + 10001){
    chmin(dp.at(i).at(j), dp.at(i - 1).at(j));
    if(j - a.at(i) >= 0) chmin(dp.at(i).at(j), dp.at(i).at(j - a.at(i)) + b.at(i));
  }
  ll ans = inf;
  rep(i, h, h + 10001) chmin(ans, dp.at(n).at(i));
  cout << ans << endl;
}

Measured memory_bytes: 160640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << (x) << endl

struct segtree {
    vector<int> lazy, dat;
    int n;

    segtree(int n_, int init){
        n = 1;
        while(n < n_) n *= 2;
        dat.assign(n*2, init);
        lazy.assign(n*2, -1);
    }

    void set(int l, int r, int x){
        queue<tuple<int,int,int>> q;
        q.emplace(0, n, 1);
        while(q.size()){
            int segl, segr, n;
            tie(segl, segr, n) = q.front();
            q.pop();
            push(segl, segr, n);
            if(segr <= l || r <= segl);
            else if(l <= segl && segr <= r) lazy[n] = x;
            else {
                int segm = (segl + segr) / 2;
                q.emplace(segl, segm, n*2);
                q.emplace(segm, segr, n*2+1);
            }
        }
        set(l, r, x, 0, n, 1);
    }

    void set(int l, int r, int x, int segl, int segr, int n){
        push(segl, segr, n);
        if(segr <= l || r <= segl);
        else if(l <= segl && segr <= r) lazy[n] = x;
        else {
            int segm = (segl + segr) / 2;
            set(l, r, x, segl, segm, n*2);
            set(l, r, x, segm, segr, n*2+1);
        }
    }

    int get(int k){
        return get(k, 0, n, 1);
    }

    int get(int k, int segl, int segr, int n){
        push(segl, segr, n);
        if(segl + 1 == segr) return dat[n];
        int segm = (segl + segr) / 2;
        if(k < segm) return get(k, segl, segm, n*2);
        else return get(k, segm, segr, n*2+1);
    }

    void push(int segl, int segr, int node){
        if(lazy[node] != -1){
            dat[node] = lazy[node];
            if(segl + 1 != segr){
                lazy[node*2] = lazy[node];
                lazy[node*2+1] = lazy[node];
            }
            lazy[node] = -1;
        }
    }
};

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

    int n, q;
    cin >> n >> q;
    segtree st(n, 2147483647);
    for(int iq = 0; iq < q; ++iq){
        int t;
        cin >> t;
        // dump(t);
        if(t == 0){
            int s, t, x;
            cin >> s >> t >> x;
            ++t;
            st.set(s, t, x);
        } else {
            int i;
            cin >> i;
            cout << st.get(i) << '\n';
        }
    }
}

Measured memory_bytes: 4904
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.Double;

public class Main {

	public static void main(String[] args) throws Exception {
		String line = readLine();
		String[] strArray = line.split(" ");
		double[] arrayA = new double[strArray.length];
		for(int i = 0; i < strArray.length; i++){
			arrayA[i] = Double.parseDouble(strArray[i]);
		}

		double tmp = (arrayA[0]*arrayA[1])/2.0;
		System.out.print(String.format("%.4f", tmp) + " ");

		if(arrayA[0]/2 == arrayA[2] && arrayA[1]/2 == arrayA[3]){
			System.out.print("1");
		} else {
			System.out.print("0");
		}
	}


	private static String readLine() throws Exception {
		BufferedReader br = new BufferedReader( new InputStreamReader(System.in));
		return br.readLine();
	}
}

Measured memory_bytes: 21332
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,d,a = LI()
    p = LIR(n)
    s = [0]*(n+1)
    p.sort()
    ans = 0
    X = [p[i][0] for i in range(n)]
    for i in range(n):
        x,h = p[i]
        j = bisect.bisect_left(X,x-2*d)
        if i != j:
            su = s[i-1]
            if j > 0:
                su -= s[j-1]
            h -=  su
        if h > 0:
            l = x
            k = math.ceil(h/a)
            ans += k
            s[i] = k*a
        s[i] += s[i-1]
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 100008
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
  string S;
  cin >> S;
  const int N = S.size();
  const ll MOD_INF = 1e9+7;
  const ll MOD = 13;
  const ll dec = 10;
  ll dp[N+1][13];
  for(int i=0; i<N+1; i++) for(int j=0; j<MOD; j++) dp[i][j] = 0;
  // dp[i][r]: i+1番目の数まで見て、余りがrの場合の数
  // 答えはdp[N][5]
  dp[0][0] = 1;
  
  ll keta = 1;
  for(int i=0; i<N; i++){
    if(S[N-i-1] == '?'){
      for(int j=0; j<dec; j++){
        for(int k=0; k<MOD; k++){
          dp[i+1][(keta*j + k)%MOD] += dp[i][k];  
          dp[i+1][(keta*j + k)%MOD] %= MOD_INF;            
        }
      }
    }else{
      int num = (char)(S[N-i-1] - '0');
      for(int k=0; k<MOD; k++){
        dp[i+1][(keta*num + k)%MOD] += dp[i][k];  
        dp[i+1][(keta*num + k)%MOD] %= MOD_INF;  
      } 
    }
    keta *= 10;
    keta %= MOD;
  }
//  for(int i=0; i<MOD; i++) cout << dp[N][i] << endl;
  cout << dp[N][5] << endl;
  return 0;
}

Measured memory_bytes: 10624
#include <stdio.h>

int main(void)
{
        int n,i,s=0;
        scanf("%d",&n);
        int v[n],c[n];
        for(i=0;i<n;i++)
                scanf("%d",&v[i]);
        for(i=0;i<n;i++)
                scanf("%d",&c[i]);
        for(i=0;i<n;i++){
                if(v[i]>c[i])
                        s+=v[i]-c[i];
        }
        printf("%d\n",s);
        return 0;
}


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

#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for(ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for(ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for(ll i = a; i >= (ll)(b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

#define INF 1000000000000
#define MOD 10000007 
#define MAXR 100000 

signed main() {
    string S, T; cin >> S >> T;
    bool flag = true;
    for (int i = 0; i < S.length(); i++) {
        if (S[i] != T[i]) flag = false;
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
#define REP(i,n) for(int i=0;i< (n);i++)
#define REPR(i, n) for(int i = (n);i >= 0;i--)
#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define FORR(i, m, n) for(int i = (m);i >= (n);i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define ALL(obj) (obj).begin(),(obj).end()

using namespace std;

const int INF = 99999999;
const ll LINF = 9999999999999;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
int vx[4] = { 0,1,0,-1 };
int vy[4] = { 1,0,-1,0 };

int alpha[26] = {};
int h, w;
char tmp;
int utigawa = 0, kisuhen = 0,center = 0;
signed main() {

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

	cin >> h >> w;

	REP(i, h)REP(j, w) {
		cin >> tmp;
		alpha[tmp - 'a']++;
	}

	utigawa = (h / 2)*(w / 2);
	if (h % 2 != 0 && w % 2 != 0) {
		center = 1;
	}

	if (h % 2 == 1) {
		kisuhen += (w / 2);
	}
	if (w % 2 == 1) {
		kisuhen += (h / 2);
	}

	//1ペアがcenterだけ
	//2ペアがkisuhenだけ
	//4ペアがutigawaだけいる

	REP(i, utigawa) {
		REP(j, 26) {
			if (alpha[j] >= 4) {
				alpha[j] -= 4;
				break;
			}
			if (j == 25) {
				cout << "No" << endl;
				return 0;
			}
		}
	}

	REP(i, kisuhen) {
		REP(j, 26) {
			if (alpha[j] >= 2) {
				alpha[j] -= 2;
				break;
			}
			if (j == 25) {
				cout << "No" << endl;
				return 0;
			}
		}
	}

	REP(i, center) {
		REP(j, 26) {
			if (alpha[j] >= 1) {
				alpha[j] -= 1;
				break;
			}
			if (j == 25) {
				cout << "No" << endl;
				return 0;
			}
		}
	}

	cout << "Yes" << endl;
	return 0;

}

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

int main(void){
  int n;
  scanf("%d\n", &n);
  int a[n];
  int num_ki = 0;
  for (int i = 0; i < n; i++){
    scanf("%d", &a[i]);
    if (a[i] % 2 == 1) num_ki++;
  }
  if (num_ki % 2 == 1) printf("NO");
  else printf("YES");
}

Measured memory_bytes: 512
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int ans=0;
  		int countr=0;
  		int count=0;
		
  		String s=sc.next();
  		String[] a=s.split("");
  		
		for(int c=0;c<n;c++){
          if(a[c].equals("R")){
          countr++;
          }
    	}
    
 	for(int d=0;d<countr;d++){
    	if(a[d].equals("R")){
        	count++;
        }
    }
		ans=countr-count;
    	System.out.println(ans);
    }
}


Measured memory_bytes: 55156
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  replace(s.begin(), s.end(), ',', ' ');
  cout << s << endl;
}


Measured memory_bytes: 256
def solve(h, w, a):
    rs = []
    for r in range(h):
        ok = True
        for c in range(w):
            if a[r][c] == "#":
                ok = False
                break
        if not ok:
            rs.append(r)
    cs = []
    for c in range(w):
        ok = True
        for r in range(h):
            if a[r][c] == "#":
                ok = False
                break
        if not ok:
            cs.append(c)
    res = "\n".join(map(lambda r: "".join(map(lambda c: a[r][c], cs)), rs))
    return res

assert solve(4,4,["##.#","....","##.#",".#.#"]) == "###\n###\n.##"
assert solve(3,3,["#..",".#.","..#"]) == "#..\n.#.\n..#"
assert solve(4,5,[".....",".....","..#..","....."]) == "#"
h, w = map(int, raw_input().split())
a = []
for r in range(h):
    a.append(raw_input())
print solve(h, w, a)

Measured memory_bytes: 2696
N = int(input())
base = ""
d = 0
if N == 0:
    print(0)
else:
    while N != 0:
        if N%2 == 0:
            base += "0"
            N = N//2
        else:
            base += "1"
            if d%2 == 0:
                N = (N-1)//2
            else:
                N = (N+1)//2
        d += 1
    print(int(base[::-1]))

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

int main(){
	int N;
	cin >> N;
	ll A[2][N];
	REP(i, 2){
		REP(j, N){
			cin >> A[i][j];
		}
	}
	ll res = 0;
	ll tmp;
	REP(i, N){
		tmp = 0;
		for(int j=0;j<=i;j++) tmp += A[0][j];
		for(int j=i;j<N;j++) tmp += A[1][j];
		res = max(res, tmp);
	}
	cout << res << endl;
    return 0;
}

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

int dp[101][1<<15],n,m,a[111],b[111],sum[1<<15];

signed main(){
    while(cin>>n>>m,n){
        memset(sum,0,sizeof(sum));
        r(i,101)r(j,1<<n)dp[i][j]=1e9;
        r(i,n)cin>>a[i];
        r(i,m)cin>>b[i];
        r(i,1<<n)r(j,n)if(i&(1<<j))sum[i]+=a[j];
        sort(b,b+m);
        r(i,1<<n)dp[0][i]=0;
        for(int i=0;i<m+1;i++){
            for(int j=0;j<(1<<n);j++){
                for(int k=0;k<n;k++){
                    if(j&(1<<k))continue;
                    dp[i][j|(1<<k)]=min(dp[i][j|(1<<k)],dp[i][j]);
                }
            }
            if(i!=m)for(int j=0;j<(1<<n);j++){
                dp[i+1][j]=dp[i][j]+abs(b[i]-sum[j]);
            }
        }
        int ans=1e9;
        r(i,1<<n)ans=min(ans,dp[m][i]);
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 16232
#include<algorithm>
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main()
{
	int n,s,m=-1145141919,f[114][514],p[114][514];
	cin>>n;
	for(int i=0;i<n;i++)for(int t=0;t<10;t++)cin>>f[i][t];
	for(int i=0;i<n;i++)for(int c=0;c<11;c++)cin>>p[i][c];
	for(int j=1;j<1024;j++)
	{
		int c[114]={0};
		s=0;
		for(int i=0;i<n;i++)
		{
			for(int t=0;t<10;t++)
			{
				if((j&1<<t)&&f[i][t])c[i]++;
			}
			s+=p[i][c[i]];
		}
		m=max(m,s);
	}
	cout<<m<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define vr(v,n) vector<int> (v)(n)
#define in(name) for(auto &i:name) cin>>i
#define pr(name) for(auto i:name) cout<<i<<" "
#define db(n) cout<<n<<"\n"
#define start_c auto start_clock_time=chrono::high_resolution_clock::now()
#define stop_c auto stop_clock_time=chrono::high_resolution_clock::now()
#define pr_c cout<<"\n"<<chrono::duration_cast<chrono::milliseconds>(stop_clock_time-start_clock_time).count()<<" ms\n"
#define MOD 1000000007
#define pb push_back()
#define srt(v) sort(v.begin(),v.end())
#define test_cases long long test_cases;cin>>test_cases;while(test_cases-->0)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define fr(i,n) for(ll i=0;i<n;i++)
#define all(v) (v).begin(),(v).end()
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    if(a==b)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
static const int MAX = 100001;
int q;
int l, r;

vector<int> makeBitPrimes(int n){
    vector<int> v(n+1, 1);
    v[0] = v[1] = 0;
    for(int  i = 2; i*i <= n; i++){
        if(v[i]==1){
            int j = i + i;
            while (j <= n){
                v[j] = 0;
                j = j + i;
            }
        }
    }
    
    return v;
}

int main(void){
    // Your code here!
    cin >> q;
    vector<int> primes = makeBitPrimes(MAX);
    int A[MAX];
    int B[MAX];
    
    for(int i = 1; i <= MAX; i++){
        if(primes[i] == 1 && primes[(i+1)/2] == 1){
            A[i] = 1;
        }
    }
    
    for(int i = 1; i <= MAX; i++){
        B[i] = B[i-1] + A[i];
    }
    
    for(int i = 0; i < q; i++){
        cin >> l >> r;
        cout << B[r] - B[l-1] << endl;
    }
    
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<math.h>
#include<string.h>
using namespace std;
long long int a[1000010],b[1000010];
int main()
{
	long long int x,n,i,j;
	while(scanf("%lld",&x)!=EOF)
	{
		for(i=1;i<=1000000;i++)
		b[i]=0;
		for(i=1;;i++)
		{
			if(b[x]!=0)
			{
				j=i;break;
			}
			if(x%2==0)
			{
				b[x]=1;
				x/=2;
			}
			else if(x%2!=0)
			{
				b[x]=1;
				x=x*3+1;
			}
		}
		printf("%lld\n",j);
	}
	return 0;
}

Measured memory_bytes: 8320
#include <stdio.h>

#pragma warning(disable:4996)

int main(void) {
	int N;
	int H[20];
	scanf("%d", &N);

	for (int i = 0; i < N; ++i) {
		scanf("%d", &H[i]);
	}
	int sum = 0;
	int max = -1;
	for (int i = 0; i < N; ++i) {
		if (H[i] >= max) {
			++sum;
			max = H[i];
		}
	}

	printf("%d", sum);

	return 0;
}

Measured memory_bytes: 128
// #Sazaの1日1AC
#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000000+7;
const long long INF=9e15;
const double PI=3.14159265358979323846;

//マクロ
//型エイリアス
using ll = long long;
using P=pair<long long,long long>;
using vl=vector<long long>;
using vvl=vector<vector<long long>>;
using vP=vector<pair<long long, long long>>;
//ショートカット
#define rep(i,n) for(long long i = 0; i < n; i++)
#define rep2(i,k,n) for(long long i = k; i < n; i++) //半開区間
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define mkp make_pair
//入力
#define vin(v,N) for(long long i=0;i<N;i++) cin>>v.at(i)
#define lin(n) long long n;cin>>n
#define chin(x) char x;cin>>x;
#define sin(s) string s;cin>>s;
#define vlin(v,N) vector<long long>v(N);for(long long i=0;i<N;i++)cin>>v.at(i)

#define max(a,b) max((ll)a,(ll)b)
#define min(a,b) min((ll)a,(ll)b)

//関数
//最大公約数
long long gcd(long long m, long long n){
  long long a=max(m,n);
  long long b=min(m,n);
  long long r=a%b;
  while(r!=0){
    a=b; b=r; r=a%b;
  }
  return b;
}
// 最小公倍数
long long lcd(long long m, long long n){
  return m*n/gcd(m,n);
}
//xのn乗
long long power(long long x, long long N){
  long long ret=1;
  for(long long i=0;i<N;i++)   
    ret*=x;
  return ret;
}
//繰り返し二乗法
long long repeat_squaring(long long x, long long n){
  if(n==0) return 1;
  else if(n%2==0){
    long long t=repeat_squaring(x,n/2);
    return t*t%mod;
  }
  else
    return x*repeat_squaring(x,n-1);
}
//素因数分解(mapで返す)
map<long long,long long> factor(long long p){
  ll p1=p;
  map<long long,long long>ret;
  for(long long i=2;i*i<=p1;i++){
     while(p%i==0){
      ret[i]++;
      p/=i;
    }
  }
  if(p!=1)
  ret[p]++;
  return ret;
}
//素数判定
bool is_prime(long long N){
  for(long long i=2;i*i<=N;i++){
    if(N%i==0)
      return false;
  }
  return true;
}
//最大値更新
void chmax(long long &a,long long b){
  a=max(a,b);
}
//最小値更新
void chmin(long long &a,long long b){
  a=min(a,b);
}

//構造体

//Union-Find木
struct UnionFind{
  //メンバ変数 
  vector<long long>par; //par[i]:=頂点iの親
  vector<long long>s; //s[i]:=頂点iが属する集合の個数(iが根のとき)
  
  //コンストラクタ
  UnionFind(long long N):par(N),s(N){
    for(long long i=0;i<N;i++){
      par[i]=i; //最初はすべてが根として初期化
      s[i]=1;
    }
  }
  //メンバ関数
  //root(i):=頂点iの根
  long long root(long long i){
    if(par[i]==i) return i;
    par[i]=root(par[i]); //経路圧縮
    return root(par[i]); //再帰
  }
  //size[i]:=iが属する集合の個数
  long long size(long long i){
    return s[root(i)];
  }
  //same(x,y) xとyが同じ根を持つか(同じ集合に含まれるか)
  bool same(long long x, long long y){
    return root(x)==root(y);
  }
  //unite(x,y) xの根をyの根に繋げる(集合を合併)
  void unite(long long x, long long y){
    if(!same(x,y)){
      long long rx=root(x);
      long long ry=root(y);
      par[rx]=par[ry];
      s[ry]=s[rx]+s[ry];
    }
  }
};

/////////////////⊂('ω'⊂ )))Σ≡GO!/////////////////

//メイン関数
int main(){
  //doubleの桁数
  cout<<fixed<<setprecision(15);

  sin(S);
  int res = 0;
  rep(i, 3) if(S[i] == 'R') res++;
  if(S[1] == 'S' && res == 2) res = 1;
  cout << res << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N,x,y,z,l,n,m,a,r,f;
  long long min,max,sum;
  //vector<vector<int>> A(n, vector<int>(m, 0));
  vector<int> B(26, 0);
  string s,g;
  string s1,s2;
  int n1,n2;
  
  n1 = 0;
  n2 = 0;
  /*while(1){
  	cin >> s;
    if(s == "-")break;*/
    cin >> n;
    for(int i=0;i<n;++i){
      cin >> s1 >> s2;
      if(s1 == s2){
        n1++;
        n2++;
      } else if(s1 > s2){
      	n1 += 3;
      } else {
        n2 += 3;
      }
      
    }
    
    cout << n1 << " " << n2 << endl;
  //}
}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repi(i,x,n) for(ll i=x;i<(ll)(n);i++)
#define lb lower_bound
#define ub upper_bound
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
//cin.tie(0);ios::sync_with_stdio(false);



signed main(){
    ll w,h,ans=0;cin>>w>>h;
    vector<ll> x(w),y(h),ysum(h+1,0);

    rep(i,w){
        cin>>x[i];
        ans+=x[i];
    }

    rep(i,h){
        cin>>y[i];
        ans+=y[i];
    }

    sort(all(x));
    sort(all(y));

    rep(i,h)ysum[i+1]=ysum[i]+y[i];

    rep(i,w){
        ll itr=ub(all(y),x[i])-y.begin();
        ans+=(h-1-itr+1)*x[i];
        ans+=ysum.at(itr);
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <fstream>
#include <sstream>
using namespace std;

#define x first
#define y second
#define pb push_back
#define mp make_pair
#define FOR(i, l, r) for (int (i) = (l); (i) < (r); ++(i))
#define REP(i, n) FOR((i), 0, (n))

long long cnt[100];
int n;
string s;

int main() {
	cin >> n;
	REP(i, n) {
		cin >> s;
		if (s[0] == 'M') cnt[0]++;
		else if (s[0] == 'A') cnt[1]++;
		else if (s[0] == 'R') cnt[2]++;
		else if (s[0] == 'C') cnt[3]++;
		else if (s[0] == 'H') cnt[4]++;
	}
	long long res = 0;

	REP(i, 5) FOR(j, i+1, 5) FOR(k, j+1, 5) res += cnt[i] * cnt[j] * cnt[k];
	cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
        #define REP(i, n) for(int i = 0;i < n;i++)
        #define REPR(i, n) for(int i = n;i >= 0;i--)
        #define FOR(i, m, n) for(int i = m;i < n;i++)
        #define FORR(i, m, n) for(int i = m;i >= n;i--)
        #define SORT(v, n) sort(v, v+n);
        #define VSORT(v) sort(v.begin(), v.end());
        #define llong long long
        #define pb(a) push_back(a)
        #define INF 999999999
        using namespace std;
        typedef pair<int, int> P;
        typedef pair<llong, llong> LP;
        typedef pair<int, P> PP;
        typedef pair<llong, LP> LPP;
     
        int dy[]={0, 0, 1, -1, 0};
        int dx[]={1, -1, 0, 0, 0};
     
        int main()
        {
           llong n;
           cin>>n;
           vector<llong> a(5,0);
           REP(i,5)cin>>a[i];
           sort(a.begin(),a.end());
           if(n%a[0]!=0) {cout<<4+1+n/a[0]<<endl;}
           else cout<<4+n/a[0]<<endl;
        }

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

using namespace std;

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

int main(int argc, char* argv[]) {
  int N;
  cin >> N;

  vector<int> p(N);
  vector<int> q(N);

  for (int i = 0; i < N; ++i)
    cin >> p[i];
  for (int i = 0; i < N; ++i)
    cin >> q[i];

  // check p
  int a = 1;
  int b = 1;
  vector<int> a_past;
  vector<int> b_past;
  for (int i = 0; i < N; ++i) {
    if (i == N - 1)
      continue;

    int greater_a = 0;
    int greater_b = 0;
    for (int j = 0; j < i; ++j) {
      if (p[i] > a_past[j])
        ++greater_a;
      if (q[i] > b_past[j])
        ++greater_b;
    }

    a_past.push_back(p[i]);
    b_past.push_back(q[i]);

    a += (p[i] - 1 - greater_a) * factor(N - i - 1);
    b += (q[i] - 1 - greater_b) * factor(N - i - 1);
  }

  cout << abs(a - b) << endl;

  return 0;
}

Measured memory_bytes: 256
import math
import decimal


def main():

    N = int(input())
    ans = 0
    A = int(math.ceil(N**0.5)+1)
    explist = []
    flag = False
    if N >= 3:
        for L in range(2, A):
            if N < L:
                break
            d = L
            cnt = 0
            while(True):
                if N % d == 0:
                    N /= d
                    cnt += 1
                    flag = True
                else:
                    break
            explist.append([d, cnt])
        for i in explist:
            c = i[1]
            for j in range(1, A):
                if c >= j:
                    ans += 1
                    c -= j
                else:
                    break
        if N >= A:
            ans += 1
        if flag:
            print(ans)
            return
        else:
            print(1)
            return
    elif N == 2:
        print(1)
        return
    else:
        print(0)
        return


if __name__ == '__main__':
    main()


Measured memory_bytes: 128888
#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> A){
    ll cnt = 0;
    vll rec;
    ll sum = 0;
    REP(i, N){
        if(A[i]>0)
            sum += A[i];
        else{
            if(i > 0 && A[i-1]==0){
                continue;
            }
            else {
                rec.push_back(sum);
                sum = 0;
            }
        }
    }
    rec.push_back(sum);
    REP(i, rec.size()){
        cnt += rec[i]/2;
    }
    cout << cnt << endl;
}

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


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

#define int long long
#define all(s) s.begin(), s.end()
#define pb push_back
#define ii pair<int, int>
#define x first
#define y second
#define bit(x, y) ((x >> y) & 1)

main() {
    ios::sync_with_stdio(false); cin.tie(0); 
    cout.tie(0);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int mx = max({a * c, a * d, b * c, b * d});
    cout << mx;
    return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>

using namespace std;

int main()
{
    double a, b, c, k;
    cin >> a >> b >> c >> k;

    double sum;
    if (k > a) {
        sum = a;
        k = k - a;

        if (k > b) {
            k = k - b;

            sum = sum - k;
        }

    }
    else {
        sum = k;
    }


    

    //cout << sum;
    printf("%.0f", sum);
    

    return 0;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
long long a;
bool prime(int x)
{
    for(int i=2;i*i<=x;i++)
    {
        if(x%i==0)
        return 0;
    }
    return 1;
}
int main()
{
	cin>>a;
    for(int i=a;;i++)
    {
        if(prime(i))
        {
            cout<<i<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256