akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main(){
  int a ,b ,c ,d ,total[2];
  for( int i=0 ; i<2 ; i++ ){
    cin >> a >> b >> c >> d;
    total[i] = a + b + c + d;
  }

  if( total[0] > total[1] ){
    cout << total[0] << endl;
  }

  else{
    cout << total[1] << endl;
  }

}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#define ll long long
#define eps 1e-7
#define all(x) ((x).begin()),((x).end())
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
using pii = pair<int, int>;

int main()
{
	usecppio
	int a, b;
	cin >> a >> b;
	cout << max(max(a+b,a-b),a*b);
}


Measured memory_bytes: 892
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var inputArray = input.split(' ');
var a = inputArray[0];
var b = inputArray[1];
var c = inputArray[2];
var d = inputArray[3];

var result = (a * b > c * d) ? a * b : c * d;
console.log(result);

Measured memory_bytes: 11468
#include <stdio.h>
#include <string.h>

int	main(void)
{
  	char	s[6];
	int		num;
  
  	num = scanf("%s", s);
  
  	if (strncmp(s, "Sunny", 6) == 0)
    {
      	printf("Cloudy");
    }
  	else if (strncmp(s, "Cloudy", 6) == 0)
    {
      	printf("Rainy");
    }
  	else
    {
      	printf("Sunny");
    }
  	return (0);
}

Measured memory_bytes: 128
def inp() a=gets.to_s.chomp.split(" ").map{|u|u.to_i}end
def r_up(a, b) (a+b-1)/b end
def r_sort(a) a.sort{|a,b|b<=>a} end

bn = inp[0]
(1..3500).each do |h|
  (1..3500).each do |n|
    si = bn*h*n
    bo = (4*h*n - bn*h - bn*n)
    next if(si <= 0)
    next if(bo <= 0)
    if(si % bo == 0)
      r = si / bo
      puts "#{h} #{n} #{r}"
      exit
    end
  end
end


Measured memory_bytes: 3836
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int ac=0,wa=0,tle=0,re=0;
		for(int i=0;i<n;i++){
			String result = sc.next();
			switch (result){
			case "AC":
				ac ++;
				break;
			case "WA":
				wa ++;
				break;
			case "TLE":
				tle ++;
				break;
			case "RE":
				re ++;
				break;
			default:
			}
		}
		System.out.println("AC x "+ ac);
		System.out.println("WA x "+ wa);
		System.out.println("TLE x "+ tle);
		System.out.println("RE x "+ re);
	}
}

Measured memory_bytes: 58224
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);
    int h = sc.nextInt();
    int w = sc.nextInt();
    List<List<Pair>> lists = new ArrayList<>();
    int c1 = sc.nextInt() - 1;
    int c2 = sc.nextInt() - 1;
    int d1 = sc.nextInt() - 1;
    int d2 = sc.nextInt() - 1;
    char[][] arr = new char[h][w];
    int[] dy = {1, 0, -1, 0};
    int[] dx = {0, 1, 0, -1};
    int[][] warpCnt = new int[h][w];
    boolean[][] flag = new boolean[h][w];


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

    void run() {

        for (int i=0; i<h; i++) {
            arr[i] = sc.next().toCharArray();
        }

//        List<Pair> list = new ArrayList<>();
//        list.add(new Pair(c1, c2));
        bfs(new Pair(c1, c2));

//        for (int i=0; i<h; i++) {
//            for (int j=0; j<w-1; j++) {
//                System.out.print(warpCnt[i][j] + " ");
//            }
//            System.out.println(warpCnt[i][w-1]);
//        }

        if (!flag[d1][d2]) System.out.println(-1);
        else System.out.println(warpCnt[d1][d2]);

    }

    void bfs(Pair pair){
        Queue<Pair> queue = new ArrayDeque<>();
        queue.add(pair);
        List<Pair> list = new ArrayList<>();
        list.add(pair);
        while (!queue.isEmpty()){
            Pair p = queue.peek();
            int y = p.y;
            int x = p.x;
            flag[y][x] = true;
            for (int i=0; i<4; i++) {
                int ny = y + dy[i];
                int nx = x + dx[i];
                if (ny<0 || h<=ny || nx<0 || w<=nx) continue;
                if (flag[ny][nx]) continue;
                if (arr[ny][nx] == '#') continue;
                flag[ny][nx] = true;
                list.add(new Pair(ny, nx));
                queue.add(new Pair(ny, nx));
                warpCnt[ny][nx] = warpCnt[y][x];
            }
            queue.poll();
            if (queue.isEmpty()) {
                if (list.size()==0) break;
                List<Pair> list1 = new ArrayList<>();
                for (Pair pair1: list) {
                    int y1 = pair1.y;
                    int x1 = pair1.x;
                    for (int yy=-2; yy<=2; yy++) {
                        for (int xx=-2; xx<=2; xx++) {
                            int nyy = y1 + yy;
                            int nxx = x1 + xx;
                            if (yy==0 && xx==0) continue;
                            if (nyy<0 || h<=nyy || nxx<0 || w<=nxx) continue;
                            if (arr[nyy][nxx] == '#') continue;
                            if (flag[nyy][nxx]) continue;
                            queue.add(new Pair(nyy, nxx));
                            list1.add(new Pair(nyy, nxx));
                            warpCnt[nyy][nxx] = warpCnt[y1][x1] + 1;
                        }
                    }
                }
                list.clear();
                list = list1;
            }
        }
    }



    class Pair {
        int y;
        int x;
        public Pair(int y, int x) {
            this.y = y;
            this.x = x;
        }
    }



}



Measured memory_bytes: 91616
# -*- coding: utf-8 -*-
A, B, C, X = map(int, [input() for i in range(4)])
ans = 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if i*500 + j*100 + k*50 == X:
                ans += 1
print(ans)

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

typedef struct qu{
  int p;
  int y;
  int x;
  int index;
} node;

int cmpY(const void *a,const void *b){
  return ((node *)a)->y-((node *)b)->y;
}

int cmpIndex(const void *a,const void *b){
  return ((node *)a)->index-((node *)b)->index;
}

void print(int n){
  char s[6];
  int k=0;
  while(n>0){
    s[k++]='0'+n%10;
    n/=10;
  }
  while(k<6) s[k++]='0';
  while(k>0) putchar(s[--k]);
}

void run(void){
  int n,m;
  scanf("%d%d",&n,&m);
  node *a=(node *)calloc(m,sizeof(node));
  int i;
  for(i=0;i<m;i++){
    int p,y;
    scanf("%d%d",&p,&y);
    a[i]=(node){p,y,-1,i};
  }
  qsort(a,m,sizeof(node),cmpY);
  int *x=(int *)calloc(n+1,sizeof(int));
  for(i=0;i<m;i++){
    int p=a[i].p;
    a[i].x=++x[p];
  }
  qsort(a,m,sizeof(node),cmpIndex);
  for(i=0;i<m;i++){
    print(a[i].p);
    print(a[i].x);
    putchar('\n');
  }
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 4964
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;

void dfs(int v, int p, ll dp[][2], list<int> adj[]) {
    dp[v][0] = dp[v][1] = 1;
    for(int u : adj[v]) {
        if(u != p) {
            dfs(u, v, dp, adj);
            dp[v][0] = dp[v][0] * dp[u][1] % mod;
            dp[v][1] = (dp[u][1] + dp[u][0]) % mod * dp[v][1] % mod;
        }
    }
}

int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    list<int> adj[n+1];
    for(int i = 0; i < n-1; ++i){
        int x,y;
        cin >> x >> y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    ll dp[n+1][2];
    dfs(1, 1, dp, adj);
    cout << (((dp[1][0] + dp[1][1]) % mod) + mod) % mod;
    return 0;
}


Measured memory_bytes: 16640
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
using ll=long long;
using ld=long double; 
using namespace std;
//const int INF = 7+(1e+9);
ll GCD(ll x, ll y)
{
    if (y == 0)
    {
        return x;
    }
    else
    {
        return GCD(y, x % y);
    }
}
ll LCM(ll x, ll y)
{
    return x / GCD(x, y) * y;
}
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll MOD=1e9+7;

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


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef long long int LL;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//---------------------------------------------------------------------------

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

    int a,b;cin>>a>>b;
    for(int i=1;i<100000;i++){
        //cout<<(int)((double)i*0.08)<<" "<<(int)((double)i*0.1)<<endl;
        if((int)((double)i*0.08)==a&&(int)((double)i*0.1)==b){
            
            cout<<i<<endl;
            return 0;
        }
    }
    //cout<<25*0.08<<" "<<25*0.1<<endl;
    cout<<-1<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------

/*
ll n;cin>>n;
vector<ll>a(n);
for(ll i=0;i<n;i++)
    cin>>a[i];
 
ll n;cin>>s;
string s;cin>>s;

ll n,m;cin>>n>>m;
vector<ll>a(n),b(m);
for(ll i=0;i<n;i++){
    cin>>a[i];
}
for(ll i=0;i<m;i++){
    cin>>b[i];
}

ll n;cin>>n;
vector<Pll>xy;
for(ll i=0;i<n;i++){
    ll x,y;cin>>x>>y;
    xy.pb({x,y});
}
*/


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

#define thegamebegins   ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define fileio          freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define int             long long
#define float           long double
#define test            int T; cin>>T; while(T--)
#define in(a,n)         for(int i=0; i<n; ++i)  cin>>a[i]
#define r0              return 0
#define E               "\n"
#define S               " "
#define elif            else if 
#define M               1000000007
#define fi(i,x,y)       for(int i=x; i<y; ++i)
#define fa(i,s)         for(auto i:s)
#define fp(i,s)         for(auto i=(s).begin(); i!=(s).end(); ++i)
#define sz(s)           (int)(s).size()
#define vi              vector <int>
#define vpii            vector <pair <int,int> >
#define mii             map <int,int>
#define pii             pair <int,int>
#define seti            set <int>
#define setd            set <int,greater <int> >
#define all(s)          (s).begin(),(s).end()
#define sortd(a,n)      sort(a, a+n, greater<int>())
#define pb              push_back
#define fr              first
#define sc              second
#define lb              lower_bound
#define ub              upper_bound
#define er              equal_range
 
const int INF = 0x3f3f3f3f;

signed main()
{
    thegamebegins

    int n;  cin>>n;
    vi a(3*n+1);
    fi(i,1,3*n+1)   cin>>a[i];
    priority_queue <int> mx;
    priority_queue <int, vector<int>, greater<int>> mn;
    int minsum=0LL, maxsum=0LL;
    fi(i,1,n+1)
    {
        mn.push(a[i]);
        maxsum+=a[i];
    }
    fi(i,2*n+1,3*n+1)
    {
        mx.push(a[i]);
        minsum+=a[i];
    }
    int dpmax[n+1],dpmin[n+1];
    dpmax[0]=maxsum;
    dpmin[n]=minsum;
    fi(i,n+1,2*n+1)
    {
        mn.push(a[i]);
        maxsum+=a[i]-mn.top();
        mn.pop();
        dpmax[i-n]=maxsum;
    }
    for(int i=2*n; i>=n+1; --i)
    {
        mx.push(a[i]);
        minsum+=a[i]-mx.top();
        mx.pop();
        dpmin[i-n-1]=minsum;
    }
    int sum=LLONG_MIN;
    fi(i,0,n+1)     sum=max(sum,dpmax[i]-dpmin[i]);
    cout<<sum;
    r0;
}


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

int main() {
  int N, X; 
  cin >> N >> X;
  vector<int> D(N + 1);
  D.at(0) = 0;
  for (int i = 0; i < N; i++) {
    int x; 
    cin >> x;
    D.at(i + 1) = D.at(i) + x;
  }
  int ans = 0;
  for (int i = 0; i <= N; ++i) {
    if (D.at(i) <= X) {
    ans++;
    }
  }
  cout << ans << endl;
 
}

Measured memory_bytes: 3604
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ECHO(x) cout<<x<<endl;
#define MEMSET(a, n, x) REP(i, n) a[i]=x;
#define ARRIN(a, n) REP(i, n) cin>>a[i];
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;

class unionfind{
  public:
  int Num;
  vector<int> par; //親の番号
  vector<int> height; //木の高さ(ランク)

  unionfind(int N):
    par(vector<int>(N, 0)), height(vector<int>(N, 0)), Num(N) {}


  //初期化
  void init(){
    REP(i, Num){
      par[i] = i;
      height[i] = 0;
    }
  }

  //xの親番号を返す、再帰処理あり
  int root(int x){
    return par[x] == x ? x : par[x] = root(par[x]);
  }

  //xとyの親番号が同一か判定する
  bool same(int x, int y){
    return root(x) == root(y);
  }

  //xとyのある木を結合する
  void unite(int x, int y){
    x = root(x);
    y = root(y);
    if(x == y) return; //親が同一なら結合済み。

    if(height[x] < height[y]) par[x] = y;
    else {
      par[y] = x;
      if(height[x] == height[y]) height[x]++;
    }
  }
};

int main(){
  int n, m;
  cin>>n>>m;
  unionfind uf(n);
  set<int> s;
  int p;
  uf.init();

  int x[m], y[m], z[m];
  REP(i, m) {
    cin>>x[i]>>y[i]>>z[i];
    --x[i];
    --y[i];
    uf.unite(x[i], y[i]);
  }

  REP(i, n){
    p=uf.root(i);
    //ECHO(p);
    s.insert(p);
  }
  cout<<s.size()<<endl;
  return 0;
}


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

void solve(long long a, long long b)
{
    long double x = ceill(((double)a + (double)b) / 2.0);
    cout << x << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long a;
    scanf("%lld", &a);
    long long b;
    scanf("%lld", &b);
    solve(a, b);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
	int a, b;

	cin >> a >> b;

	bool p = false;
	for (int c = 1; c < 10; c++) {
		int d = a * b * c;

		if (d % 2 == 1) {
			cout << "Yes" << endl;
			p = true;
			break;
		}
	}
	if (!p) {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

a, b, k = map(int, input().split())

M = min(a, b)
cnt = 0
for i in range(M, 0, -1):
    if a%i == 0 and b%i == 0:
        cnt += 1
        if cnt == k:
            print(i)
            exit()

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

int bunkatu(int x) {
        int a,b,result;
        a = x/500;
	    b = (x - (a*500))/5;
        result = b*5 + a*1000;
        return result;

}


int main() {

        int x;
        cin >> x;
        cout << bunkatu(x) << endl;
        return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static Scanner scanner;

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

	    long A=gl();
	    long B=gl();
	    long C=gl();
	    

	    //System.out.println(min);
        if (A%2==0 || B%2==0 || C%2==0) {
    	    System.out.print(0);
        }else {
        	if(A>=B && A>=C) {
        		System.out.print(B*C);
        	} else if(B>=A && B>=C) {
        		System.out.print(A*C);
        	} else {
        		System.out.print(B*A);
        	}
        }
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35616
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, m, n) for (int i = m; i < n; i++)
#define repr(i, m, n) for (int i = m; i >= n; i--)
#define db(x) cout << #x << "=" << x << endl;
template <class T>
bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
#define EPS 1e(-9);
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
//--GLOBAL---------------------------------
const int MAX = 1000100;
ll fac[MAX], finv[MAX], inv[MAX];
void cinit() { // O(nlogn)
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  reps(i, 2, MAX){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
ll c(int n, int k){ // 二項係数計算
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//--MAIN-----------------------------------
void Main() {
    ll X,Y;
    cin >> X>>Y;

    ll Z=X+Y;

    if(Z%3!=0){
        cout<< 0<<"\n"; return;
    }

    if(X*2<Y or Y*2<X){
        cout<< 0<<"\n";
        return;
    }

    Z/=3;

    X-=Z;

    cinit();

    cout<< c(Z,X) <<"\n";

}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 23680
s = gets.split("").map(&:chomp)
s.delete("")
t = true
while t
  if s[0] == "h" && s[1] == "i"
    s.delete_at(0)
    s.delete_at(0)
  else
    t = false
  end
end
if s.size != 0
  puts "No"
else
  puts "Yes"
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##_max = (b); i < i##_max; ++i)
#define RFOR(i, a, b) for (int i = (b)-1, i##_min = (a); i >= i##_min; --i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()

#define pb push_back
#define mp make_pair
#define fst first
#define snd second

using namespace std;
using i64 = int64_t;
using u64 = uint64_t;
using vb = vector<bool>;
using vi = vector<int>;
using vl = vector<i64>;
using vd = vector<double>;
using pi = pair<int, int>;
using pl = pair<i64, i64>;
using pd = pair<double, double>;

constexpr int INF = 1 << 30;
constexpr int MOD = 1000000007;

template <typename T>
inline void chmin(T &a, T b) {
  a = min(a, b);
}
template <typename T>
inline void chmax(T &a, T b) {
  a = max(a, b);
}
template <typename T>
void print(T &v) {
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin()) cout << " ";
    cout << *it;
  }
  cout << endl;
}

constexpr int N = 3;
constexpr int N2 = N * N;
constexpr array<int, 4> dx{-1, 0, 1, 0}, dy{0, -1, 0, 1};
constexpr array<char, 4> dir{'u', 'l', 'd', 'r'};

struct Puzzle {
  std::array<int, N2> f;
  int space;
  string path;

  bool operator<(const Puzzle &p) const {
    REP(i, N2) {
      if (f[i] == p.f[i]) continue;
      return f[i] > p.f[i];
    }
    return false;
  }
};

bool is_target(Puzzle &p) {
  REP(i, N2) {
    if (p.f[i] != i + 1) return false;
  }
  return true;
}

string bfs(Puzzle &s) {
  queue<Puzzle> Q;
  map<Puzzle, bool> V;
  s.path = "";
  Q.push(s);
  V[s] = true;

  while (!Q.empty()) {
    auto u = Q.front();
    Q.pop();
    if (is_target(u)) return u.path;
    int sx = u.space / N;
    int sy = u.space % N;
    REP(r, 4) {
      int tx = sx + dx[r];
      int ty = sy + dy[r];
      if (tx < 0 || ty < 0 || tx >= N || ty >= N) continue;
      auto v = u;
      swap(v.f[u.space], v.f[tx * N + ty]);
      v.space = tx * N + ty;
      if (!V[v]) {
        V[v] = true;
        v.path += dir[r];
        Q.push(v);
      }
    }
  }
}

int main() {
  Puzzle in;
  REP(i, N2) {
    cin >> in.f[i];
    if (in.f[i] == 0) {
      in.f[i] = N2;
      in.space = i;
    }
  }
  auto ans = bfs(in);
  cout << ans.size() << endl;
}


Measured memory_bytes: 30608
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <bitset>
#include <vector>
#include <string>
#include <assert.h>
#include <algorithm>

using namespace std;
#define ll long long

int main()
{
	int N, K;
	cin >> N >> K;
	string s;
	cin >> s;
	s[K - 1] += 'a' - 'A';
	cout << s << endl;

	return 0;
}

Measured memory_bytes: 256
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
int a,b,c,x;
cin>>a>>b>>c>>x;
int s=0;
for (int i=0;i<=a;i++)
  for (int j=0;j<=b;j++)
    for (int k=0;k<=c;k++)
      if (i*500+j*100+k*50==x) s++;
cout<<s<<endl;
return 0;
}

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

#define M 1000000007
#define MM 998244353 
#define ll long long 
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
#define all(v) v.begin(),v.end()
#define sz(a) (ll)a.size()
#define F first
#define S second
#define PI 3.1415926536
#define INF 2e18
#define endl "\n"
#define llevel 20
ll power(ll b,ll e,ll m)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b%m,e/2,m)%m;
	return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b,e/2);
	return power(b*b,e/2);
}

int _runtimeTerror_()
{
	ll x,y,a,b,c,n,i;
	cin>>x>>y>>a>>b>>c;
	ll p[a],q[b],r[c];
	for(i=0;i<a;++i)
		cin>>p[i];
	for(i=0;i<b;++i)cin>>q[i];
	for(i=0;i<c;++i)cin>>r[i];
	sort(p,p+a);sort(q,q+b);sort(r,r+c);
	vector<ll> tt;
	ll ans=0;
	for(i=0;i<x;++i)
	{
		ans+=p[a-1-i];
		tt.pb(p[a-1-i]);
	}
	for(i=0;i<y;++i)
	{
		ans+=q[b-1-i];
		tt.pb(q[b-1-i]);
	}
	sort(all(tt));
	ll st=0,en=c-1;
	ll xx=x+y;
	while(st<x+y && en>=0)
	{
		if(tt[st]<=r[en])
		{
			ans+=r[en]-tt[st];
			++st;--en;
		}
		else
			break;
	}
	cout<<ans<<endl;
	return 0;
}

int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#ifdef runSieve
		sieve();
	#endif
	#ifdef NCR
		initialize();
	#endif
	int TESTS=1;
	//cin>>TESTS;
	while(TESTS--)
		_runtimeTerror_();
	return 0;
}


Measured memory_bytes: 4724
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=max(x,a)
#define chmin(x,a) x=min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
const int MOD = 1000000007;
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
#define greater greater<int>()
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
using Edge=pair<int,ll>;
using Graph=vector<vector<bool> >;//ll or Edge
using Edge=pair<int,ll>;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// g++ -o a a.cpp -Wall -lm -std=c++17
int main(){
    int n;cin>>n;
    VI a(n);
    rep(i,n)cin>>a[i];
    map<ll,ll>L,R;
    rep(i,n){
        L[i+1+a[i]]++;
        R[i+1-a[i]]++;
    }
    ll ans=0;
    for(auto v:L){
        ll key=v.fi;
        ll Lvalue=v.se;
        ll Rvalue=R[key];
        ans+=Lvalue*Rvalue;
    }
    cout<<ans<<endl;
}


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


using namespace std;

typedef long long ll;








ll n, p, g = 1;


int main() {
    cin >> n >> p;
    if (n == 1)
        return cout << p, 0;
    for (ll i = 2; i * i <= p; i++)
        if (p % i == 0) {
            int c = 0;
            while (p % i == 0)
                p /= i, c++;
            for (int j = 0; j < (c / n); j++)
                g *= i;
        }
    cout << g;
    return 0;
}

Measured memory_bytes: 256
/* ****devACE**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  100005
bool comp(pair<int,int>l, pair<int,int>r){
	if(l.second==r.second)return l.first<r.first;
	else return l.second>r.second;
}
void print(set<int>a){
	for(auto i:a)cout<<i<<" "; cout<<"\n\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		int n,m,i,j,k;
		cin>>n>>m;
		set<int>a;
		for(i=1;i<=m;i++)a.insert(i);

		vector<pair<int,int> > b(n);
		for(i=0;i<n;i++){
			cin>>b[i].first>>b[i].second;
		}
		sort(b.begin(),b.end(),comp);


		int ans=0;
		for(i=0;i<n;i++){
			int days=m+1-b[i].first;
			if(a.size()==0)continue;
			auto it=a.lower_bound(days);
			if(it==a.begin()){
				if(*it==days){
					ans+=b[i].second;
					a.erase(*it);
				}
			}else{
				if(it!=a.end()){
					if(*it>days)it--;
					ans+=b[i].second;
					a.erase(*it);
				}else{
					if(days>=*a.rbegin()){
						ans+=b[i].second;
						a.erase(*a.rbegin());
					}
				}
			}
			//print(a);
		}

		cout<<ans;
	}
	return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int ans[5][37]={ 1 };
    for(int i=1; i<=4; i++) {
        ans[i][0]=ans[i-1][0];
        for(int j=1; j<=36; j++) {
            ans[i][j]=ans[i][j-1]+ans[i-1][j];
            if(j>9) ans[i][j]-=ans[i-1][j-10];
        }
    }

    int n;
    while(cin>>n) {
        if(n>36) cout<<"0\n";
        else cout<<ans[4][n]<<'\n';
    }
    return 0;
}



Measured memory_bytes: 3112
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <string>
#include <cstring>
#include <list>
#include <queue>
#include <numeric>
#include <map>
using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int a;
    cin>>a;
    if (a==105) cout<<1;
    else if (a<105) cout<<0;
    else {
    	int ans=1;
    	for (int t=106; t<=a; ++t) {
    		if ((t%2)==0) continue;
    		int cnt=1;
    		for (int i=2; i<=t; ++i) {
    			if ((t%i)==0) ++cnt;
    		}
    		if (cnt==8) ++ans; 
    	}
    	cout<<ans;
    }
    cout<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin>>N;
  vector<int> v(N);
  for(int i;i<N;i++){
    cin>>v.at(i);
  }
  int memo=0;
  int MeMo=0;
  for(int i;i<N;i++){
    memo=memo+v.at(i);
    MeMo=MeMo+v.at(i)*v.at(i);
  }
  cout<<(memo*memo-MeMo)/2;
}
  

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


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

  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    int a;
    cin >> a;
    if (i % 2 != 0 &&
        a % 2 != 0 ) {
      ans++;
    }
  }

  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3584
N = list(input())
N.insert(0, '0')
count = 0
for i in range(len(N)-1, -1, -1):
    if int(N[i]) <= 4:
        count += int(N[i])
    elif int(N[i]) == 5 and int(N[i-1]) <= 4:
        count += int(N[i])
    else:
        count += 10 - int(N[i])
        N[i-1] = str(int(N[i-1]) + 1)

print(count)

Measured memory_bytes: 67052
n,m,x=map(int,input().split())
data=[]
for i in range (n):
  a=list(map(int,input().split()))
  data.append(a)
mIN=10**7
for i in range(2**n):
  money=0
  bag=[]
  rikai=[0]*m
  cnt=[0]*m
  for j in range(n):
    if (i>>j)&1 :
      bag.append(data[j])
  for k in bag:
      money+=k[0]
      for s in range(m):
        rikai[s]+=k[s+1]
        if rikai[s]>=x:
          cnt[s]+=1
  if cnt.count(0)==0:
    mIN=min(mIN,money)
    
if mIN==10**7:
  print("-1")
else:
  print(mIN)
      

Measured memory_bytes: 9112
#include <iostream>
#include <sstream>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <algorithm>
#include <ctime>
#include <limits>
#include <iomanip>
#include <functional>
#include <array>
#include <climits>
#include <cmath>

using namespace std;
using ll = long long;
const ll MOD = (ll)1e9 + 7;

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

    map<ll, ll> a;
    for (ll i = 0; i < n; i++)
    {
        ll aa;
        cin >> aa;
        a[aa]++;
    }

    ll sum = 0;
    for (ll i = 30; i >= 1; i--)
    {
        ll p = (ll)1 << i;
        for (map<ll, ll>::iterator x = a.begin(); x != a.end(); ++x)
        {
            ll p0 = p - x->first;
            map<ll, ll>::iterator y = a.find(p0);
            if (y != a.end())
            {
                if (x == y)
                {
                    if (x->second > 1)
                    {
                        sum += x->second / 2;
                        x->second %= 2;
                    }
                }
                else
                {
                    if (x->second > 0 && y->second > 0)
                    {
                        ll m = min(x->second, y->second);
                        sum += m;
                        x->second -= m;
                        y->second -= m;
                    }
                }
            }
        }
    }
    cout << sum << endl;
    return 0;
}



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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30


int main() {
    int n; cin >> n;
    V<int> p(n);
    for(int i = 0; i < n; i++){
        cin >> p[i];
    }

    int ans = 0;
    for(int i = 1; i < n - 1; i++){
        if(p[i - 1] < p[i] && p[i] < p[i + 1] ||
            p[i + 1] < p[i] && p[i] < p[i - 1])
            ans++;
    }
    cout << ans << endl;

    return 0;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

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

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

typedef long long ll;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
    ll x;  // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

ll sum(ll l, ll r) { return (l + r) * (r - l + 1) / 2; }

void solve(long long N, long long K) {
    mint ans;
    for (int i = K; i <= N + 1; i++) {
        ll l = sum(0, i - 1), r = sum(N - i + 1, N);
        ans += r - l + 1;
    }
    cout << ans << endl;
}

int main() {
    long long N;
    scanf("%lld", &N);
    long long K;
    scanf("%lld", &K);
    solve(N, K);
    return 0;
}


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

int main(){
    int n; cin >> n ;
    vector<pair<double,string>> otoshidama(n);
    for ( int i = 0 ; i < n ; i++){
        cin >> otoshidama.at(i).first >> otoshidama.at(i).second;
    }

    double sum = 0 ;
    for ( int i = 0 ; i < n ; i++){
        if( otoshidama.at(i).second == "JPY" ){
            sum += otoshidama.at(i).first;
        }
        else{
            sum += otoshidama.at(i).first * 380000.0;
        }        
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
#define pint pair<double, int>
int main(){
    int n, h, w;
    pint a;
    while(cin >> n, n) {
        vector<pint> v;
        rep(i,n) {
            cin >> a.second;
            cin >> h >> w;
            a.first = abs(w/((h/100.0)*(h/100.0)) -22);
            v.push_back(a);
        }
        sort(v.begin(), v.end());
        cout << v[0].second << endl;
    }
    return 0;
}

Measured memory_bytes: 1232
//#define _GLIBCXX_DEBUG

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll k,n;cin>>k>>n;
  if(~k&1){
    vector<ll>ret(n,k);
    ret[0]=k/2;
    debug(ret,n);
    return 0;
  }
  vector<ll>ret(n);
  vector<ll>t(n+1,0);
  t[0]=1;
  const ll inf=1e9;
  ll tmp=k;
  rep(i,0,n){
    t[i+1]=min(t[i]+tmp,inf);
    tmp=min(tmp*k,inf);
  }
  //debug(t,n+1);
  rep(i,0,n){
    if(t[n-i]<=(ll)1e6){
      vector<ll>ret(i,(k+1)/2);
      ll sz=i+t[n-i]-1;
      ll mid=(sz+1)/2;
      mid-=i;
      //cout<<i spa mid spa sz<<endl;
      rep(j,i,n){
        if(mid==0)break;
        //cout<<j spa mid spa t[n-j-1]<<endl;
        ll d=(mid-1)/t[n-j-1];
        ret.PB(d+1);
        mid-=d*t[n-j-1]+1;
      }
      debug(ret,ret.size());
      break;
    }
  }
  return 0;
}

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

using namespace std;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getchar());
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getchar()) sum = sum * 10 - '0' + ch;
	return sum * fg;
}

typedef long long LL;
typedef pair<int, int> pii;

// Template-Libs

// END

const int MAXN = (int) 1e5;

int n;

int A[MAXN + 5], B[MAXN + 5];

inline void input()
{
	n = read<int>();
	for(int i = 1; i <= n; ++i) A[i] = read<int>(), B[i] = read<int>();
}

inline void solve()
{
	LL ans = LLONG_MAX, sum = 0;
	for(int i = 1; i <= n; ++i) sum += A[i];
	chkmin(ans, sum);
	sum = 0;
	for(int i = 1; i <= n; ++i) sum += B[i];
	chkmin(ans, sum);

	static int seq[MAXN * 2 + 5];

	for(int i = 1; i <= n; ++i) seq[i] = A[i], seq[n + i] = B[i];
	sort(seq + 1, seq + 2 * n + 1);

	static multiset<int> t;
	sum = 0;
	for(int i = 1; i <= n; ++i) sum += seq[i], t.insert(seq[i]);
	for(int i = 1; i <= n; ++i)
	{
		static vector<int> stk;

		int p0 = t.find(A[i]) == t.end() ? *t.rbegin() : A[i];
		sum -= p0, t.erase(t.find(p0)), stk.push_back(p0);
		int p1 = t.find(B[i]) == t.end() ? *t.rbegin() : B[i];
		sum -= p1, t.erase(t.find(p1)), stk.push_back(p1);

		chkmin(ans, sum + A[i] + B[i]);

		while(!stk.empty()) sum += stk.back(), t.insert(stk.back()), stk.pop_back();
	}
	printf("%lld\n", ans);
}

int main()
{
	input();
	solve();

	return 0;
}



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

using ll=long long;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n-1){
    int A;
    cin >> A;
    A--;
    a[A]++;
  }
  rep(i,n) cout << a[i] << endl;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define VEC(TYPE, A, NAME, INIT) vector<TYPE> NAME(A, INIT)
#define VEC2(TYPE, A, B, NAME, INIT) vector<vector<TYPE>> NAME(A, vector<TYPE>(B, (INIT)))

int main()
{
    int n = 0;
    cin >> n;
    VEC(int, n, vec, 0);
    REP(i, n) cin >> vec[i];

    VEC(int, 100001, cnt0, 0);
    VEC(int, 100001, cnt1, 0);
    
    REP( i, n )
    {
        if( i % 2 == 0 ) ++cnt0[vec[i]];
        else ++cnt1[vec[i]];
    }
    int max0 = distance( cnt0.begin(), max_element(cnt0.begin(), cnt0.end()));
    int max1 = distance( cnt1.begin(), max_element(cnt1.begin(), cnt1.end()));
    sort( cnt0.begin(), cnt0.end(), greater<int>() );
    sort( cnt1.begin(), cnt1.end(), greater<int>() );

    if( max0 != max1 )
    {
        cout << n - cnt0[0] - cnt1[0] << endl;
    }
    else
    {
        cout << min( n - cnt0[0] - cnt1[1], n - cnt0[1] - cnt1[0] ) << endl;
    }

    return 0;
}

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

string ans;
int number[4];

int recurse(int i, int sum) {
  if (i == 4) return (sum == 0);
  if (recurse(i + 1, sum + number[i])) {
    ans[2 * i - 1] = '-';
    return 1;
  } else if (recurse(i + 1, sum - number[i])) {
    ans[2 * i - 1] = '+';
    return 1;
  } else {
    return 0;
  }
}

int main()
{
  cin >> ans;
  const int n = ans.size();
  ans.resize(n * 2 - 1);
  for (int i = n - 1; i >= 0; --i) {
    number[i] = ans[i] - '0';
    ans[2*i] = ans[i];
  }
  recurse(1, 7 - number[0]);
  cout << ans << "=7";

  return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int a[100001],b[100001];
long long box[100001]={0};
int main(void)
{
	int n,m,c,i;
	long long sum;
	scanf("%d %d",&n,&m);
	box[0]=0;
	for(i=1;i<n;i++){
		scanf("%d",&a[i]);
		box[i]=box[i-1]+a[i];
	}
	for(i=0;i<m;i++){
		scanf("%d",&b[i]);
	}
	c=0;
	sum=0;
	for(i=0;i<m;i++){
		if(b[i]>0){
			sum+=box[c+b[i]]-box[c];
			c+=b[i];
		}
		else{
			sum+=box[c]-box[c+b[i]];
			c+=b[i];
		}
		sum%=100000;
	}
	printf("%lld\n",sum%100000);
	return 0;
}


Measured memory_bytes: 4232
str = raw_input()
str1 = raw_input()
array = str.split()
array = map(int, array)
N = array[0]
k = array[1]
array = str1.split()
array = map(int, array)
left_index = 0
right_index = 0
if array[0]*array[-1]>=0:
    if array[0] >= 0:
        answer = array[k-1]
    else:
        answer = abs(array[-k])
else:
    result = []
    x = min([abs(i) for i in array])
    if x == 0:
        index = array.index(x)
        if index < k - 1:
            left_index = 0
        else:
            left_index = index - k + 2
            result.append(abs(array[index-k+1]))
        if len(array) - 1 - index < k - 1:
            right_index = len(array)
        else:
            right_index = index + k - 1
            result.append(array[index+k-1])

    else:
        if x in array:
            index = array.index(x)
            middle_left_index = index - 1
            middle_right_index = index
        else:
            index = array.index(-x)
            middle_left_index = index
            middle_right_index = index + 1
        if middle_left_index < k - 1:
            left_index = 0
        else:
            left_index = middle_left_index - k + 2
            result.append(abs(array[middle_left_index - k + 1]))
        if len(array) - 1 - middle_right_index < k - 1:
            right_index = len(array)
        else:
            right_index = middle_right_index + k - 1
            result.append(array[middle_right_index+k-1])
    new_array = array[left_index:right_index]
    if len(new_array) >= k:
        min_route = max(abs(new_array[0]), abs(new_array[-1]))**2
        for i in range(len(new_array)):
            if i+k-1 <= len(new_array) - 1:
                left_abs = abs(new_array[i])
                right_abs = abs(new_array[i+k-1])
                current_min_route = min(left_abs, right_abs) + left_abs + right_abs
                if min_route > current_min_route:
                    min_route = current_min_route
        result.append(min_route)
    answer = min(result)
print answer


Measured memory_bytes: 12208
#include <iostream>
#include <string>

using namespace std;

int main() {
    string s;
    int n, a, b;
    int now = 0;
    int c = 1;

    cin >> n >> a >> b >> s;

    for (int i = 0; i < n; i++) {
        if (s[i] == 'a' && a + b > now) {
            cout << "Yes" << endl;
            now++;
        } else if (s[i] == 'b' && a + b > now && c <= b) {
            c++;
            cout << "Yes" << endl;
            now++;
        } else {
            cout << "No" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 896
/*
for (int i = 0; i < N; ++i){}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<int,int> point;
#define rep(i,n) for(i,0,n)
 
int main() {
	// 入力
	int N;
	cin >> N;
	long a[N];
	for (int i = 0; i < N; ++i) cin >> a[i];
 
	// 解法
	int ans = 0;
	int length = 1;
	for (int i = 0; i < N-1; ++i){
		if (a[i]==a[i+1]) length++;
		else{
			ans += length/2;
			// cout << '+' << length/2 << endl;
			length = 1;
		}
	}
	if (length!=0){
		// cout << '+' << length/2 << endl;
		ans += length/2;
	}
	
	//出力
	cout << ans << endl;
}
 


Measured memory_bytes: 256