akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

void lunlun(vector<int> &d){
	int no=0;
	for (int i = 0; i < 10; i++){
		if(d[i]>9){
			if(d[i+1]==-1)d[i+1]=1;
			else d[i+1]++;
			for (int j = 0; j <= i; j++){
				d[j]=0;
			}
		}
		if(d[i+1]==-1)break;
		if(abs(d[i+1]-d[i])>1){
			no=1;
			break;
		}
	}if(no==0)return;
	for (int i = 0; i < 10; i++){
		if(d[i+1]!=-1&&d[i+1]-d[i]>1)d[i]=d[i+1]-1;
		if(d[i+1]!=-1&&d[i]-d[i+1]>1){
			d[i+1]++;
			for (int j = 0; j <= i; j++){
				d[j]=0;
			}
		}
	}
	lunlun(d);
}
int main() {
	int k;
	cin>>k;
	vector<int> d(11,-1);
	d[0]=1;
	for (int i = 1; i < k; i++){
		d[0]++;
		lunlun(d);
	}
	for (int i = 9; i >=0; i--){
		if(d[i]!=-1)cout<<d[i];
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

int main()
{
	string word;
	bool first = true;

	while ( cin >> word )
	{
		int pos;
		
		if ( ( pos = word.find( "peach" ) ) != string::npos )
		{
			word.replace( pos, 5, "apple" );
		}
		else if ( ( pos = word.find( "apple" ) ) != string::npos )
		{
			word.replace( pos, 5, "peach" );
		}

		if ( first )
		{
			first = false;
		}
		else
		{
			cout << ' ';
		}

		cout << word;
	}

	cout << endl;

	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
int N;
int D[101];
int A[101];
map<vector<int>, int> perm;

int solve(){
	int dp[101][5040] = {};//今いる所、前７個の順番
	int ans = 0;
	for(int i = 1; i < N; i++){
		vector<int> p = {0, 1, 2, 3, 4, 5, 6, 7};
		do{
			int add = 0;
			bool eaten[8] = {};
			//i番目の小籠包に関する影響のみを考える
			for(int idx = 0; idx < 8; idx++){
				int x = i - p[idx];
				if(x == i){
					eaten[p[idx]] = true;
					for(int d = 1; d <= D[i]; d++){
						if(i - d < 0) continue;
						if(!eaten[d]) add += A[x];
					}
				}
				if(x >= 0){
					eaten[p[idx]] = true;
					if(!eaten[0] && p[idx] <= D[x]){
						add += A[x];
					}
				}
			}
		
			//今の順序の取り出し
			vector<int> tmp1;
			for(int j = 0; j <= 7; j++){
				if(p[j] != 7) tmp1.push_back(p[j]);
			}
			//参照する順序の取り出し
			vector<int> tmp2;
			for(int j = 0; j <= 7; j++){
				if(p[j] != 0) tmp2.push_back(p[j] - 1); 
			}
			dp[i][perm[tmp1]] = max(dp[i][perm[tmp1]], dp[i - 1][perm[tmp2]] + add);
			ans = max(ans, dp[i][perm[tmp1]]);
		}while(next_permutation(p.begin(), p.end()));
	}
	vector<int> p = {0, 1, 2, 3, 4, 5, 6};
	do{
		ans = max(ans, dp[N - 1][perm[p]]);
	}while(next_permutation(p.begin(), p.end()));
	return ans;
}

void init(){
	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> D[i];
	}
	for(int i = 0; i < N; i++){
		cin >> A[i];
	}
	int idx = 0;
	vector<int> p = {0, 1, 2, 3, 4, 5, 6};
	do{	
		for(int i = 0; i < N; i++){
			
		}
		perm[p] = idx++;
	}while(next_permutation(p.begin(), p.end()));
}

int main(){
	init();
	cout << solve() << endl;
	return 0;
}


Measured memory_bytes: 5776
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ld long double
#define fi first
#define se second
#define all(uiet) uiet.begin(),uiet.end()
#define read(UIET) for(int i = 0; i < n; ++i) cin >> UIET[i]
#define out(UIET) for(int i = 0; i < n; ++i) cout << UIET[i]
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vpp vector<pair< int, int > >
#define pll pair<int , int >
#define ppll pair < pll , pll >
#define debug(n1) cout << n1 << endl
#define len(a) ((int) (a).size())
#define endl "\n"
#define mod 1000000007
const int INF=(1LL<<60)-1;
const int maxN = 1000001;
string extractStringAtKey(string str, int key){
    char *s = strtok((char *)str.c_str(), " ");
    while(key > 1){
        s = strtok(NULL, " ");
        key--;
    }
    return (string)s;
}
bool prime[maxN + 1];
void seive(){
    memset(prime, true, sizeof(prime));
    for(int i = 2; i * i <= maxN; ++i){
        if(prime[i]){
            for(int j = i * i; j <= maxN; j += i){
                prime[j] = false;
            }
        }
    }
}
int32_t main(){
    SPEED;
    int n;
    cin >> n;
    seive();
    int a = 0, b = 0, ans = INF;
    for(int i = 2; i <= 1000000; ++i){
        if(n % i == 0){
            a = i;
            b = n/i;
            ans = min(ans, a + b - 2);
        }
    }
    if(ans == INF) cout << n - 1;
    else cout << ans ;
}

Measured memory_bytes: 4588
#include <bits/stdc++.h>
using namespace std;
#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 ALL(v) v.begin(), v.end()
#define downque(que) priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
typedef vector<vector<int>> Matrix;
const int MOD = 1e9 + 7;
const int MAX = 1e7;
const int INF = numeric_limits<int>::max();



int main(){

  int n,time; cin>>n;
  int x=0, y=0, t=0;
  bool flag = true;

  REP(i, n){
    int a, b, c;
    cin >> a >> b >> c;
    time = a-t;
    time -= abs(b - x) + abs(c - y);
    if (time<0 ||time%2!=0){
      flag = false;
      break;
    }
    x=b,y=c,t=a;
  }

  if (flag)
    cout <<"Yes"<< endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-1) ;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}


int main(){
 ll n ;cin>> n ;
 string s ;cin>>s ;
 ll gap=0 ; ll ans=0 ;
 rep(i,n){
  if(s[i]==')') gap++ ;
  else gap-- ;
  chmax(ans,gap) ;
 }
 string bns= "";
 {
     rep(i,ans){
         bns+= '(' ;
     }
     bns+=s ;
     rep(i,ans-gap){
         bns+=')' ;
     }
     cout<<bns<<endl ;
 }
 

 
 return 0 ; 
}

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

using namespace std;

int main() {
    long long a, b, c, k, ans=0;
    cin >> a >> b >> c >> k;

    if (k<=a) {
        for (int i = a; i > 0; i--) {
            ans++;
            k--;
            if (k == 0) {
                cout << ans << endl;
                return 0;
            }
        }
    } else if (a<k && k<=a+b) {
        ans = a;
        cout << ans << endl;
        return 0;
    } else {
        ans = a;
        k -= (a+b);
        for (int i = c; i > 0; i--) {
            ans--;
            k--;
            if (k == 0) {
                cout << ans << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3f
#define endl '\n'
#define ll long long
#define int long long
#define f first
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int>> ppi;
typedef vector<vector<int>> mat;
const ll mod = 1e9+7;
const ll LINF = 0x3f3f3f3f3f3f3f;
const int MAXN = 400005;

int32_t main() {
	int n;
	cin >> n;
	int ans = 0;
	for(int i = 1; i <= n; i++) {
		if(i == 10 or i == 1000 or i == 100000){
			i*=10;
			i--;
			continue;
		} 
		ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
use std::io;
use std::cmp;

fn main() {
    let (n, k) = {
        let i = read::<usize>();
        (i[0], i[1] as u32)
    };
    let an = read::<usize>();

    let mut ans = std::usize::MAX;
    for b in 0..1 << n {
        if (b as usize).count_ones() < k { continue; }
        let mut h = an[0];
        let mut cost: usize = 0;
        for i in 0..n {
            if b & (1 << i) != 0 {
                if i != 0 && h >= an[i] {
                    cost += h - an[i] + 1;
                    h += 1;
                }
            }
            h = cmp::max(h, an[i]);
        }
        ans = cmp::min(ans, cost);
    }

    println!("{}", ans);
}

#[allow(unused)]
fn read<T>() -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}


#[allow(unused)]
fn read_one<T>() -> T
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 2132
#include <bits/stdc++.h>
using namespace std;
const int days[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30};
const string s[] = {"Wednesday", "Thursday", "Friday", "Saturday",
                    "Sunday",    "Monday",   "Tuesday"};
int main() {
  int m, d;
  while (cin >> m >> d, m | d) {
    int sum = d;
    for (int i = 0; i < m - 1; i++) {
      sum += days[i];
    }
    cout << s[sum % 7] << endl;
  }
}



Measured memory_bytes: 3004
from collections import deque

H,W  =  map(int,input().split())
M = [list(input()) for i in range(H)]

count_w = 0
for i in range(H):
    for j in range(W):
        if M[i][j] == ".":
            count_w += 1
            
def bfs():
    que = deque()
    que.append((0,0))
    dx = [0,1,0,-1]
    dy = [-1,0,1,0]
    d = [[float("Inf")]*W for i in range(H)]
    d[0][0] = 0
    while que :
        p = que.popleft()
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if 0 <=nx <H and 0 <= ny <W and M[nx][ny] != "#" and d[nx][ny] == float("Inf"): 
                que.append((nx,ny))
                d[nx][ny] = d[p[0]][p[1]]+1
    if d[H-1][W-1] != float("Inf"):
        return d[H-1][W-1]
    else:
        return -1

ans = bfs()
if ans != -1:
    print(count_w-ans-1)
else:
    print(-1)
        

Measured memory_bytes: 3316
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from math import ceil, floor, sqrt, gcd
from copy import deepcopy
from decimal import *

def main():
    a,b = map(Decimal, input().split())
    result = a*b
    print(int(result))
    
if __name__ == "__main__":
    main()

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

int main(){
  string s;
  cin >> s;
  int n = s.size();
  bool ok = true;

  if(s[0]!='A') ok = false;
  int count = 0;
  for (int i = 2; i < n-1; i++)
  {
    if(s[i]=='C') count++;
  }
  if(count!=1) ok = false;

  for (int i = 0; i < n; i++)
  {
    if(s[i]<'a' && s[i]!='A' && s[i]!='C') ok = false;
  }

  if(ok) puts("AC");
  else puts("WA");
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

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

typedef long long ll;

ll c[30],s[370][30];
int a[370],last[30];

unsigned seed=chrono::steady_clock::now().time_since_epoch().count();
mt19937 rng(seed);

ll f(int d)
{
    ll x=0;
    memset(last,-1,sizeof(last));
    for(int i=0;i<d;i++){
        x+=s[i][a[i]];
        last[a[i]]=i;
        for(int j=0;j<26;j++){
            x+=c[a[i]]*(i-last[a[i]]);
        }
    }
    return x;
}

int main()
{
    auto start=chrono::high_resolution_clock::now();
    ll x=0,sc=0;
    int d,ans[370];
    scanf("%d",&d);
    for(int i=0;i<26;i++){
        scanf("%lld",&c[i]);
        sc+=c[i];
    }
    for(int i=0;i<d;i++){
        for(int j=0;j<26;j++){
            scanf("%lld",&s[i][j]);
        }
    }
    if(sc==0){
        for(int i=0;i<d;i++){
            int mx=-1,j=-1;
            for(int k=0;k<26;k++){
                if(s[i][k]>mx) mx=s[i][k],j=k;
            }
            printf("%d\n",j);
        }
        return 0;
    }
    while(true){
        for(int i=0;i<d;i++) a[i]=rng()%26;
        ll y=f(d);
        if(y>x) copy(a,a+d,ans),x=y;
        auto stop=chrono::high_resolution_clock::now();
        int duration=chrono::duration_cast<chrono::microseconds>(stop-start).count();
        if(2000000-duration<100000) break;
    }
    for(int i=0;i<d;i++){
        printf("%d\n",a[i]+1);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 3920
a=[list(map(int,input().split())) for _ in range(3)]
n=int(input())
for i in range(n):
    nn=int(input())
    for j in range(3):
        if nn in a[j]:
                a[j][a[j].index(nn)]=0

cnt=0
for j in range(3):
    if a[j][0]+a[j][1]+a[j][2]==0:
        cnt+=1
for j in range(3):
    if a[0][j]+a[1][j]+a[2][j]==0:
        cnt+=1
if a[0][0]+a[1][1]+a[2][2]==0:
    cnt+=1
if a[0][2]+a[1][1]+a[2][0]==0:
    cnt+=1

if cnt>0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 31) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

int n;

bool f(pair<double, string> ds1, pair<double, string> ds2) {
	if (fabs(ds1.first - ds2.first) < EPS) {
		return ds1.second < ds2.second;
	}
	return ds1.first > ds2.first;
}

int main() {
	while (cin >> n&&n) {
		vector<pair<double, string>> vds;
		rep(i, n) {
			string l;
			double p, a, b, c, d, e, f, s, m;
			cin >> l >> p >> a >> b >> c >> d >> e >> f >> s >> m;
			double t = a + b + c + d + e;
			double cnt = f*s - p;
			rep(i, m - 1) {
				t += (d + e);
				cnt += f*s;
			}
			//cout << cnt << " " << t << endl;
			vds.push_back({ cnt / t,l });
		}
		sort(ALL(vds), f);
		rep(i, n) {
			cout << vds[i].second << endl;
		}
		cout << "#" << endl;
	}
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

signed main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
	
  	Int(n);
  if (n < 1200) cout << "ABC" << endl;
  else cout << "ARC" << endl;
  
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <iostream>
#include <map>
#include <functional>
#include <cstdlib>
#include <numeric>
#include <queue>
#include <complex>

using namespace std;

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

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> Point;
typedef map<int, set<int> > Graph;

void checkConnectedGraph(Graph& g, int s, set<int>& visited)
{
	visited.insert(s);
	for(set<int>::iterator itr = g[s].begin(); itr != g[s].end(); ++itr){
		if(!visited.count(*itr))
			checkConnectedGraph(g, *itr, visited);
	}
}

bool isOdd(const pii& n)
{
	return n.second % 2 == 1;
}

int main()
{
	int a, b;
	while(scanf("%d%d", &a, &b) != EOF){
		map<int, int> hist;
		Graph graph;
		do{
			graph[a].insert(b);
			graph[b].insert(a);

			if(!hist.count(a))
				hist[a] = 1;
			else
				++hist[a];

			if(!hist.count(b))
				hist[b] = 1;
			else
				++hist[b];
		}while(scanf("%d%d", &a, &b), a);

		set<int> sets;
		checkConnectedGraph(graph, 1, sets);

		int cnt = count_if(hist.begin(), hist.end(), ptr_fun(isOdd));
		bool pre = hist[1]%2 == 1 && hist[2]%2 == 1 && cnt == 2;

		if(pre && sets.size() == hist.size())
			puts("OK");
		else
			puts("NG");
		
	}

	return 0;
}

Measured memory_bytes: 0
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type node struct {
	key                 int
	parent, left, right *node
}

var tree *node
var wtr = bufio.NewWriter(os.Stdout)

func inorder(u *node) {
	if u == nil {
		return
	}
	inorder(u.left)
	fmt.Fprintf(wtr, " %d", u.key)
	inorder(u.right)
}

func preorder(u *node) {
	if u == nil {
		return
	}
	fmt.Fprintf(wtr, " %d", u.key)
	preorder(u.left)
	preorder(u.right)
}

func printtree(u *node) {
	inorder(u)
	fmt.Fprintf(wtr, "\n")
	wtr.Flush()
	preorder(u)
	fmt.Fprintf(wtr, "\n")
	wtr.Flush()
}

func insert(tree **node, z *node) {
	// zの親になるノードをyとする
	var y *node
	// zの親になるノードを探す
	x := *tree
	for x != nil {
		y = x //仮親を設定
		if z.key < x.key {
			x = x.left
		} else {
			x = x.right
		}
	}
	z.parent = y  // zの親をyにする
	if y == nil { // tが空の場合(木に追加される最初の要素)
		*tree = z
	} else if z.key < y.key {
		y.left = z // zをyの左の子にする
	} else {
		y.right = z // zをyの右の子にする
	}
}

type cmd struct {
	command string
	key     int
}

func main() {
	var N int
	fmt.Scan(&N)
	var tree *node
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := 0; i < N; i++ {
		var command string
		sc.Scan()
		command = sc.Text()
		if command == "insert" {
			sc.Scan()
			key, _ := strconv.Atoi(sc.Text())
			// insert処理をする
			z := new(node)
			z.key = key
			insert(&tree, z)
		} else if command == "print" {
			printtree(tree)
		}
	}
}



Measured memory_bytes: 23740
#include <bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9

typedef long long ll;

using namespace std;

const ll inf = 1e18;
const ll mod = 1e9+7;
const int N = 1e5+5;
//int a[N];

int main()

{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    int n, m;

    cin >> n >> m;

    cout << (n-1)*(m-1);

    return 0;
}


Measured memory_bytes: 256
var a:array[1..100000] of longint ;
      n,i,ans,j:longint ;
procedure swap(n,m:longint) ;
var t:longint ;
begin 
   a[n]:=t ;a[n]:=a[m];a[m]:=t ;
end;
procedure solve(k:longint) ;
begin 
   if a[k+1]=k then swap(k,k+1) 
	 else if a[k]=k+1 then swap(k,k-1) 
	 else if a[k]=k-1 then swap(k,k+1) ;
end;
begin 
   readln(n) ;
	 for i:=1 to n do read(a[i]) ;
	 i:=1;
	 while i<=n do 
	 begin 
	   if a[i]<>i then inc(i)
		 else
		 begin 
		   solve(i) ;//挑选好的替换搭档。
			 inc(ans) ;
		   i:=i+2 ;
		 end;
	 end;
	 writeln(ans) ;
end.

Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
 
int main()
{ 
  int i,j,min,n;
  int C[50][2],ki[50][2],syo[50][2];
  int N;
  int tmp1;
  char tmp2,str[3];

 
  scanf("%d",&N);
 
  for(i=1; i<=N;i++)
    {
      scanf("%s",str);
      C[i][0] = ki[i][0] = syo[i][0] = atoi(&str[1]);
      C[i][1] = ki[i][1] = syo[i][1] = str[0];
    }
 
  for (i=1; i<=N; i++)
    {
      for (j=N; j>=i+1; j--)
	{
 
	  if(ki[j][0] < ki[j-1][0])
	    {
     
	      tmp1 = ki[j][0];
	      tmp2 = ki[j][1];
	      ki[j][0] = ki[j-1][0];
	      ki[j][1] = ki[j-1][1];
	      ki[j-1][0] = tmp1;
	      ki[j-1][1] = tmp2;
    
	    }
	}
    }

  for (i=1; i<=N; i++)
    {
      min = i;
      for (j=i; j<=N; j++)
	{
	  if(syo[j][0] < syo[min][0])
	    {
	      min = j;
	    }
	}

      if(i != min)
	{
  
	  tmp1 = syo[i][0];
	  tmp2 = syo[i][1];
	  syo[i][0] = syo[min][0];
	  syo[i][1] = syo[min][1];
	  syo[min][0] = tmp1;
	  syo[min][1] = tmp2;
	
	}
      
    }
  
  n = 1;
  
  for (i=1; i<=N; i++)
    {
      printf("%c%d",ki[i][1],ki[i][0]);
      
      if(n == 1 && i > 1 && ki[i][0] == ki[i-1][0])
	{
	  for(j=1; j<=N; j++)
	    {
	      if(C[j][0] == ki[i][0] && C[j][1] == ki[i][1])
		{
		  n = 0;
		  break;
		}
	      if(C[j][0] == ki[i-1][0] && C[j][1] == ki[i-1][1])
		{
		  break;
		}
	    }
	}
    
      if(i!=N)
	{
	  printf(" ");
	}
    }
  
  printf("\n");
  if(n == 1)
    {
      printf("Stable");
    }
  else{
    printf("Not stable");
  }
  printf("\n");
  
  n = 1;
  
  for (i=1; i<=N; i++)
    {
      printf("%c%d",syo[i][1],syo[i][0]);
  
  
      if(n == 1 && i > 1 && syo[i][0] == syo[i-1][0])
	{
	  for(j=1; j<=N; j++)
	    {
	      if(C[j][0]==syo[i][0] && C[j][1]== syo[i][1])
		{
		  n = 0;
		  break;
		}
	      if(C[j][0] == syo[i-1][0] && C[j][1] == syo[i-1][1])
		{
		  break;
		}
	    }
	}
  
      if(i != N)
	{
	  printf(" ");
	}
    }
  
  printf("\n");
  if(n == 1)
    {
      printf("Stable");
    }
  else{
    printf("Not stable");
  }
  printf("\n");
 
  return 0;
  
}

Measured memory_bytes: 604
#include <iostream>
#include <stdio.h>

using namespace std;

double s(double s0,int n){
	if(n==1){
		return s0;
	}
	else if(n%2==1){
		return s(s0,n-1)/3.0;
	}
	else{
		return s(s0,n-1)*2;
	}
}

int main(){
	double s0;
	while(cin>>s0){
		double sum = 0;
		for(int i=1;i<=10;i++){
			sum += s(s0,i);
		}
		printf("%.6f\n",sum);
	}	

	return 0;

}

/*
Sample Input
1.0
2.0
3.0
Output for the Sample Input
7.81481481
15.62962963
23.44444444
*/

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

int solve(string s, string t) {
  int ans = 10000, max = s.size() - t.size() + 1;
  vector<int> vec(max, 0);
  for (int i = 0; i < max; i++) {
    for (int j = 0; j < t.size(); j++) {
      if (s[i + j] != t[j]) vec[i]++;
    }
  }
  for (int i = 0; i < max; i++) {
    ans = min(ans, vec[i]);
  }
  return ans;
}

int main() {
  string s, t;
  cin >> s >> t;
  
  cout << solve(s, t) << endl;
}

Measured memory_bytes: 3612
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
using namespace std;

int main() {
	int y;
	cin >> y;
	
	if (y == 1) cout << "Hello World" << endl;
	else {
		int a, b;
		cin >> a >> b;
		cout << a + b << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
const ll mod998 = 998244353;
const ll intmax = 2147483647;
const ll llmax = 9223372036854775807;
const char sp = ' ';

double a, b, x;

int main() {
	cin >> a >> b >> x;
	x /= a;
	if (x >= a*b / 2) {
		printf("%.10f\n", 180 / M_PI * acos(a / sqrt(a*a + (2 * (a*b - x) / a)*(2 * (a*b - x) / a))));
	}
	else {
		printf("%.10f\n", 180 / M_PI * atan(b / (2 * x / b)));
	}
}

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

int main() {
  int X,Y;
  cin>>X>>Y;
  int ans=0;
  if(X==3) ans+=100000;
  if(X==2) ans+=200000;
  if(X==1) ans+=300000;

  if(Y==3) ans+=100000;
  if(Y==2) ans+=200000;
  if(Y==1) ans+=300000;

  if(X==1&&Y==1) ans+=400000;

cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

template <typename T>
struct SegmentTree {
 private:
  ll n;            //最下段のサイズ
  T e;             //単位元
  vector<T> node;  //セグメント木を表現する配列
  typedef function<T(T, T)> Func;
  Func f;  //区間クエリで使う処理

 public:
  SegmentTree(vector<T> v, Func f_input, T e_input) {
    f = f_input;
    e = e_input;
    ll sz = SZ(v);
    n = 1;
    while (n < sz) n *= 2;
    node.resize(2 * n - 1, e);
    REP(i, sz) node[i + n - 1] = v[i];
    IREP(i, n - 1) node[i] = f(node[2 * i + 1], node[2 * i + 2]);
  }

  // x番目(0-indexed)の要素をvalに更新する
  void update(ll x, T val) {
    x += (n - 1);
    node[x] = val;
    while (x > 0) {
      x = (x - 1) / 2;
      node[x] = f(node[2 * x + 1], node[2 * x + 2]);
    }
  }

  // [a, b) に対する区間クエリに答える
  // k := 自分がいるノードのインデックス
  // [l, r) : ノードkの対象区間
  T query(ll a, ll b, ll k = 0, ll l = 0, ll r = -1) {
    if (r < 0) r = n;
    if (r <= a || b <= l) return e;
    if (a <= l && r <= b) return node[k];
    T vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
    T vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
    return f(vl, vr);
  }

  // 添字でアクセス
  T operator[](ll i) { return node[i + n - 1]; }
};

int main() {
  ll n, m;
  cin >> n >> m;
  const ll INF = 1e18;
  vector<ll> dp(n, INF);
  dp[0] = 0;
  SegmentTree<ll> st(dp, [](ll a, ll b) { return min(a, b); }, INF);

  vector<vector<ll>> a(m);
  REP(i, m) {
    ll l, r, c;
    cin >> l >> r >> c;
    l--;
    r--;
    a[i] = {l, r, c};
  }
  sort(ALL(a));
  REP(i, m) {
    ll l = a[i][0], r = a[i][1], c = a[i][2];
    ll t = st.query(l, r) + c;
    st.update(r, min(st[r], t));
  }

  if (st[n - 1] == INF) {
    cout << -1 << endl;
    return 0;
  }
  cout << st[n - 1] << endl;
}

Measured memory_bytes: 8448
#include <bits/stdc++.h> 
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<int>>;

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

int main(){
    int n;
    cin>>n;
    vector<int> ans(10005,0);
    for(int x=1;x*x<10000;++x){
        for(int y=1;y*y<10000;++y){
            for(int z=1;z*z<10000;++z){
                ll w=x*x+x*y+y*y+y*z+z*z+x*z;
                if(w<=n){
                    ++ans[w];
                }
            }
        }
    }
    for(ll i=1;i<=n;++i){
        cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 3588
import copy
h, w = map(int, input().split())
ch, cw = map(int, input().split())
ch -= 1
cw -= 1

dh, dw = map(int, input().split())
dh -= 1
dw -= 1

S = []
for i in range(h):
    S.append(list(input()))
#print(S)

def by_walk(stack):
    walk_point = copy.copy(stack)
    while stack != []:
        temp = []
        for i, j in stack:
            warp_counter = S[i][j]
            next_points = [(i+1, j), (i-1, j), (i, j+1), (i, j-1)]
            for next_point in next_points:
                next_h, next_w = next_point
                if next_h >= 0 and next_h < h and next_w >= 0 and next_w < w:
                    if S[next_h][next_w] ==".":
                        S[next_h][next_w] = warp_counter
                        temp.append(next_point)
                        walk_point.append(next_point)
        stack = temp
    return walk_point

def warp(stack):
    warp_point = []
    for i, j in stack:
        warp_counter = S[i][j]
        for shift_i in range(-2, 3):
            for shift_j in range(-2, 3):
                new_i = i + shift_i
                new_j = j + shift_j
                if not(new_i == i and new_j == j):
                    if new_i >= 0 and new_i < h and new_j >= 0 and new_j < w:
                        if S[new_i][new_j] == ".":
                            S[new_i][new_j] = warp_counter + 1
                            warp_point.append((new_i, new_j))
    return warp_point

stack = [(ch, cw)]
S[ch][cw] = 0
"""
ans = by_walk(stack)
print(ans)
ans = warp(ans)
print(*S, sep="\n")
print(ans)
"""
while stack != []:
    stack = by_walk(stack)
    #print(*S, sep="\n")
    #print(stack)
    if S[dh][dw] != ".":
        print(S[dh][dw])
        break
    stack = warp(stack)
    #print(*S, sep="\n")
    #print(stack)
    if S[dh][dw] != ".":
        print(S[dh][dw])
        break
else:
    print(-1)



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

bool compare(const vector<long long> &a, const vector<long long> &b) {
    return atan2(a[1], a[0]) < atan2(b[1], b[0]);
}

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

    int N;
    cin >> N;
    vector<vector<long long>> coords;
    for (int i = 0; i < N; i++) {
        vector<long long> coord(2);
        cin >> coord[0] >> coord[1];
        coords.push_back(coord);
    }

    sort(coords.begin(), coords.end(), compare);

    long long maxDist = 0;
    for (int i = 0; i < N; i++) {
        long long x = 0, y = 0;
        for (int j = i; j < i + N; j++) {
            x += coords[j % N][0];
            y += coords[j % N][1];
            maxDist = max(maxDist, x * x + y * y);
        }
    }
    cout << fixed << setprecision(11) << sqrt(maxDist) << '\n';

    return 0;
}

Measured memory_bytes: 512
import java.util.*;

class Main{
  static Set<Character> list;
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    list = new HashSet<>();
    list.add('a');
    list.add('i');
    list.add('u');
    list.add('e');
    list.add('o');
    int n;
    loop:while(scan.hasNext()) {
      n = scan.nextInt();
      if(n==0) return;
      String[] arr = new String[n];
      for(int i = 0; i < n; i++) arr[i] = getShortName(scan.next().toCharArray());
      Arrays.sort(arr);
      int result = 0;
      for(int i = 0; i < n-1; i++) {
        if(arr[i].equals(arr[i+1])) {
          System.out.println(-1);
          continue loop;
        }else {
          int same = 0;
          for(int j = 0; j < Math.min(arr[i].length(),arr[i+1].length()); j++) {
            if(arr[i].charAt(j)==arr[i+1].charAt(j)) {
              same++;
            }
          }
          result = Math.max(same,result);
        }
      }
      System.out.println(result+1);
    }
  }

  public static String getShortName(char[] input) {
    String result = ""+input[0];
    for(int i = 1; i < input.length; i++) {
      if(list.contains(input[i-1])) {
        result += input[i];
      }
    }
    return result;
  }
}

Measured memory_bytes: 39260
/**
 *    author:  tourist
 *    created: 20.11.2019 14:13:00       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<vector<int>> g(n);
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    --x; --y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  vector<vector<int>> dd;
  for (int rot = 0; rot < n; rot += n - 1) {
    vector<int> dist(n, n);
    dist[rot] = 0;
    vector<int> que(1, rot);
    for (int b = 0; b < (int) que.size(); b++) {
      for (int j : g[que[b]]) {
        if (dist[j] == n) {
          dist[j] = dist[que[b]] + 1;
          que.push_back(j);
        }
      }
    }
    dd.push_back(dist);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) ans += (dd[0][i] <= dd[1][i]);
  cout << (ans > n - ans ? "Fennec" : "Snuke") << '\n';
  return 0;
}


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

int main()
{
  int N;
  string S;
  cin >> N >> S;
  for (int i = 0; i < S.size(); i++)
  {
    for (int j = 0; j < N; j++)
    {
      if (S[i] == 'Z')
      {
        S[i] = 'A';
      }
      else
      {
        S[i]++;
      }
    }
  }
  cout << S << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}


int main() {
    int n,k;
    cin >> n>> k;
    vector<int>a(n);
    rep(i,n) cin >> a[i];
    for (int i = k+1;i<=n;i++) {
        if(a[i-1-k] < a[i-1]) cout<< "Yes" << endl;
        else cout << "No" << endl;
    }
}
      


Measured memory_bytes: 4004
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define fi first
#define se second
#define pf push_front
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define debug(val) cerr << "Value " << #val << " : " << val << '\n';
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ld epsilon = 10e-9;
const ll nax = 1e5+5;
ll n, k, r, s, p, arr[nax], ans=0;
string a;
unordered_map<ll, bool>skip;
	
int main(void){
	IOS
	cin >> n >> k;
	cin >> r >> s >> p;
	cin >> a;
	ll l=a.length();
	for(int i=0;i<l;i++){
		skip[i]=0;
	}
	for(int i=0;i+k<l;i++){
		if(skip[i]) continue;
		if(a[i]==a[i+k]){
			skip[i+k]=1;
		}
	}
	for(int i=0;i<l;i++){
		if(skip[i]) continue;
		else{
			if(a[i]=='r') ans+=p;
			else if(a[i]=='s') ans+=r;
			else ans+=s;
		}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 7488
#include<cstdio>
#include<algorithm>

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

using namespace std;

typedef	pair<int,int>	pii;

bool cmp(int a,int b,int x,int y,int xx,int yy){
	if(x+y!=xx+yy)	return x+y<xx+yy;
	return a*x+b*y<a*xx+b*yy;
}

int xgcd(int a,int b,int &x,int &y){
	if(b==0){ x=1; y=0; return a; }
	int g=xgcd(b,a%b,y,x); y-=a/b*x;
	return g;
}

pii solve(int a,int b,int d){
	int x,y,g=xgcd(a,b,x,y);
	x*=d/g,y*=d/g;
	int xans=x,yans=y;
	for(int k=-100000;k<=100000;k++){
		int xx=x+k*b/g,yy=y-k*a/g;
		if(!cmp(a,b,abs(xans),abs(yans),abs(xx),abs(yy)))	xans=xx,yans=yy;
	}
	return mp(abs(xans),abs(yans));
}

int main(){
	for(int a,b,d;scanf("%d%d%d",&a,&b,&d),a;){
		pii res=solve(a,b,d);
		printf("%d %d\n",res.first,res.second);
	}
	return 0;
}

Measured memory_bytes: 756
n = int(input())
arr = sorted([int(x) for x in input().split(" ")], reverse=True)
S = arr[0]
iter = 1
c = False
for i in range(n - 2):
    S += arr[iter]
    if c == False:
        c = True
        continue
    if c == True:
        iter += 1
        c = False
        continue
        
print(S)



Measured memory_bytes: 31696
#include <iostream>
#include <cstdio>
//#include <stdlib.h>
using namespace std;

#define debug 0

int InArray[200000] = {0};
int N = 0;

long long sumArray(int, int);

int main()
{
	// initialize input
	int temp;
#if debug
	FILE *inputFile = fopen("0600_in1.txt", "r");
	fscanf(inputFile, "%d", &N);
	//cout << "N: " << N << endl;
	for(int i = 0; i < N; i++){
		fscanf(inputFile, "%d", &temp);
		//cout << temp << endl;
		InArray[i] = temp;
		InArray[i + N] = temp;
	}
	cout << endl;
	
	//for(int i = 0; i < 2 * N; i++){
	//	cout << InArray[i] << endl;
	//}
	
	fclose( inputFile);
#else
	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> temp;
		InArray[i] = temp;
		InArray[i + N] = temp;
	}
#endif
	
	// Calculate sum and average
	long long sum = sumArray(0, N);
	long long average;
	if(sum % 3 == 0){
		average = sum / 3;
	}else{
		average = sum / 3 + 1;
	}

#if debug	
cout << "sum:\t" << sum << endl;
cout << "average:" << average << endl;
#endif
	
	long long MaxMin = 0;
	long long tempMin;
	long long a1_sum, a2_sum;
	long long average2;
	
	for(int a1 = 0; a1 < N; a1++){
		a1_sum = 0;
		for(int a2 = a1 + 1; a2 < (a1 + N); a2++){
			a1_sum += InArray[a2 - 1];
			if(a1_sum < average) continue;
			
			if((sum - a1_sum) % 2 == 0){
				average2 = (sum - a1_sum) / 2;
			}else{
				average2 = (sum - a1_sum + 1) / 2;
			}
			
			a2_sum = 0;
			for(int a3 = a2 + 1; a3 < (a1 + N); a3++){	// left 1 for a3_sum
				a2_sum += InArray[a3 -1];
				if(a2_sum < average2) continue;
#if debug
//cout << a1 << " " << a2 << " " << a3 << endl;
//cout << a1_sum << " " << a2_sum << " " << sum - a1_sum - a2_sum << endl;
#endif				
				if(a2_sum - InArray[a3 -1] > MaxMin){
					MaxMin = a2_sum - InArray[a3 -1];
#if debug
//cout << MaxMin << endl;
#endif
				}
				if(sum - a1_sum - a2_sum   > MaxMin){
					MaxMin = sum - a1_sum - a2_sum;
#if debug
//cout << MaxMin << endl;
#endif
				}
				break;
			}
			break;
		}
	}
	
	cout << MaxMin << endl;
	
	return 0;
}

long long sumArray(int start, int end)
{
	long long sum = 0;
	for(int i = start; i < end; i++){
		sum += InArray[i];
//		cout << "i:" << i << "sum:" << sum << endl;
	}
//	cout << sum << endl;
//	system("pause");
	return sum;
}

Measured memory_bytes: 3860
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 998244353;
 
// 32 mil = ~1 sec 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
const int biggg = 2000000000;
const long long bigggest = 1000000000000000000LL;
const double eps = .0000000001; 

int main ()
{
  prep();
  int n, p;
  string s;
  cin >> n >> p >> s;
  long long cnt = 0;
  if (p == 2){
      // ends in even
      for (int i=0; i<n; i++){
          if ((s[i]-'0')%2 == 0) cnt += i+1;
      }
      cout << cnt;
      return 0;
  }else if (p == 5){
      // ends in 0 or 5
      for (int i=0; i<n; i++){
          if ((s[i]-'0')%5 == 0) cnt += i+1;
      }
      cout << cnt;
      return 0;
  }
  long long sums[n];
  long long curpow = 1;
  int freqs[p] = {0};
  for (int i=s.size()-1; i>=0; i--){
      sums[i] = curpow*(s[i]-'0');
      curpow *= 10;
      curpow %= p;
  }

  for (int i=0; i<n; i++) {
      if (i > 0) sums[i] += sums[i-1];
      sums[i] %= p;
      freqs[sums[i]]++;
  }
  
  long long cursum = 0;
  for (int i=0; i<s.size(); i++){
      cnt += freqs[cursum];
      freqs[sums[i]]--;
      cursum = sums[i];
  }
  cout << cnt;
  return 0;
}

Measured memory_bytes: 2196
#include<algorithm>
#include<cstring>
#include<cctype>
#include<cstdio>
#define rep(i,x,y) for(int i=x; i<=y; ++i)
#define mid (l+r>>1)
 
using namespace std;
const int N=100005;
int n,poola[N],poolb[N],a[N],b[N],jdga,jdgb,tot,ans,f[N+N];
struct data{int a,b;} dat[N];
 
int getint()
{
	char ch;
	while(!isdigit(ch=getchar()));
	int x=ch-48;
	while(isdigit(ch=getchar())) x=x*10+ch-48;
	return x;
}
 
int find(int x)
{
	int l=0,r=n;
	while(l<=r)
		poola[mid]<=x?l=mid+1:r=mid-1;
	return l;
}
 
int getfa(int x)
{
	return f[x]==x?x:f[x]=getfa(f[x]);
}
 
void merge(int x,int y)
{
	x=getfa(x),y=getfa(y);
	if(x!=y) f[x]=y;
}
 
int query()
{
	rep(i,1,n) if(a[i]!=b[i]) dat[++tot]=(data){a[i],b[i]};
	dat[++tot]=(data){jdga,jdgb};
	rep(i,1,tot) dat[i].a=find(dat[i].a),dat[i].b=find(dat[i].b);
	rep(i,1,tot+n+1) f[i]=i;
	rep(i,1,tot) merge(i,dat[i].a+tot),merge(i,dat[i].b+tot);
	rep(i,1,tot) poola[i]=dat[i].a;
	sort(poola+1,poola+1+tot);
	rep(i,1,tot) if(i==1 || poola[i]!=poola[i-1]) if(f[tot+poola[i]]==tot+poola[i]) ++ans;
	return tot+ans-2;
}
 
int main()
{
	n=getint();
	rep(i,1,n) poola[i]=a[i]=getint(),jdga^=a[i];
	rep(i,1,n) poolb[i]=b[i]=getint(),jdgb^=b[i];
	poola[0]=jdga,poolb[0]=jdgb;
	sort(poola,poola+1+n),sort(poolb,poolb+1+n);
	rep(i,0,n) if(poola[i]!=poolb[i]) {puts("-1"); return 0;}
	printf("%d\n",query());
	return 0;
}

Measured memory_bytes: 4864
#include <iostream>

using namespace std;

int main()
{
	int N, Y;
	int x, y, z;
	int a;
	cin >> N >> Y;
	Y /= 1000;
	for (x = Y / 10; x >= 0; x--)
	{
		a = Y - N - 9 * x;
		if (a % 4 || a < 0 ) continue;
		y = a / 4;
		z = N - x - y;
		if (z < 0) continue;
		break;
	}
	if (x == -1) y = z = -1;
	cout << x << " " << y << " " << z << " " << endl;
	return 0;
}


Measured memory_bytes: 256
l, r = map(int,input().split())
if r - l > 2018:
    print(0)
elif l % 2019 > r % 2019:
    print(0)
else:
    ans = 100000
    for i in range(l % 2019, r % 2019):
        for j in range(i+1, r % 2019 + 1):
            ans = min(ans, i * j % 2019)
    print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,t,ans1,ans2,ans3,ans4;
  for(int i=0; i<4; i++){
    cin >> t >> n;
    if(t==1) {
	ans1 = 6000*n;
	cout << ans1 << endl;
    }
    if(t==2){
	ans2 = 4000*n;
	cout << ans2 << endl;
    }
    if(t==3){
	ans3 = 3000*n;
	cout << ans3 << endl;
    }
    if(t==4){
	ans4 = 2000*n;
	cout << ans4 << endl;
    }
  }
  return 0;
}
  


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

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
typedef long long ll;
typedef double lf;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e18;

const int MAX = 305;
ll g[MAX][MAX];
ll g2[MAX][MAX];
int N, M, L;

void floydWarshall() {
    for (int k = 0; k < N; k++)
        for (int i = 0; i < N; i++)
            for (int j = 0; j < N; j++)
                g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
}
void floydWarshall2() {
    for (int k = 0; k < N; k++)
        for (int i = 0; i < N; i++)
            for (int j = 0; j < N; j++)
                g2[i][j] = min(g2[i][j], g2[i][k] + g2[k][j]);
}

void init(){
    forn(i,N+1){
        forn(j,N+1){
            g[i][j]=(i==j?0:INF);
            g2[i][j]=0;
        }
    }
}

int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
    fastIO;
#endif
    cin>>N>>M>>L;
    init();
    forn(i,M){
        int x,y,c;
        cin>>x>>y>>c;
        x--,y--;
        g[x][y]=c,g[y][x]=c;
    }
    floydWarshall();
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(g[i][j]<=L)g2[i][j]=1;
            else g2[i][j]=INF;
        }
    }
    floydWarshall2();
    int q;
    cin>>q;
    while(q--){
        int x,y;
        cin>>x>>y;
        x--,y--;
        if(g2[x][y]==INF)cout<<-1<<endl;
        else cout<<g2[x][y]-1<<endl;
    }
    return 0;
}


Measured memory_bytes: 5108
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

const int N = 200000;

// x^n
ll mod_pow(ll x, ll n) {
  if (n == 0) return 1;
  ll res = mod_pow(x * x % MOD, n / 2);
  if (n & 1) res = res * x % MOD;
  return res;
}

// x^{-1}
ll mod_inv(ll x) { return mod_pow(x, MOD - 2); }

ll fact[N + 1];
ll fact_inv[N + 1];

void init_fact() {
  fact[0] = fact_inv[0] = 1;
  REP(i, N) {
    fact[i + 1] = fact[i] * (i + 1) % MOD;
    fact_inv[i + 1] = fact_inv[i] * mod_inv(i + 1) % MOD;
  }
}

ll nCr(ll n, ll r) {
  if (n < r || n < 0 || r < 0) return 0;
  return fact[n] * fact_inv[r] % MOD * fact_inv[n - r] % MOD;
}

ll nPr(ll n, ll r) { return nCr(n, r) * fact[r] % MOD; }

map<int, int> prime_factor(int n) {
  map<int, int> res;
  for (int i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n] = 1;
  return res;
}

int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> mp = prime_factor(m);
  ll ans = 1;
  init_fact();
  for (auto a : mp) {
    ans *= nCr(a.second + n - 1, a.second);
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B =sc.nextInt();
		if (A+B>=10) {
			System.out.println("error");
		} else {
			System.out.println(A+B);
		}
	}
}

Measured memory_bytes: 20688
n, m = map(int, input().split())
mod = 10**9 + 7

if abs(n - m) > 1:
    res = 0
else:
    a = 1
    for x in range(1, n+1):
        a = (a * x) % mod
    b = 1
    for x in range(1, m+1):
        b = (b * x) % mod
    res = (a * b) % mod
    if n == m:
        res = (res * 2) % mod

print(res)

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

using namespace std;
typedef long long ll;

ll mcm(ll x,ll y){
	return (x/__gcd(x,y))*y;
}

int main(){
	int n;cin>>n;
  	ll ans = 1;
  	ll num;
  	for(int i=0;i<n;i++){
    	cin>>num;
      	ans = mcm(ans,num);
    }
  	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_map>
#define mod 1000000007
using namespace std;
typedef long long ll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define mad(a,b) a=(a+b)%mod
#define mul(a,b) a=a*b%mod

#define N 100010
ll n,a[N];
vector<ll> g[N];
bool dfs(ll x,ll from){
    ll sum=0,ma=-1;
    for(auto y:g[x])if(y!=from){
	if(dfs(y,x)==0)return 0;
	sum+=a[y];
	chmax(ma,a[y]);
    }
    if(ma==-1)return 1;
    ll rem=sum-a[x];
    if(rem<0)return 0;
    if(sum-ma<rem)return 0;
    a[x]-=rem; if(a[x]<0)return 0;
    return 1;
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=0;i<n-1;i++){
	ll a,b; cin>>a>>b;
	g[a].push_back(b);
	g[b].push_back(a);
    }
    if(n==2){
	cout<<(a[1]==a[2]?"YES":"NO")<<endl;
	return 0;
    }
    ll p=1;
    for(;g[p].size()==1;p++){}
    if(dfs(p,0)==1&&a[p]==0)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}



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

int A[22], B[22], C[22];

int main() {
    long long ans = 0;
    int N; scanf("%d",&N);
    for(int i=1; i<=N; i++) scanf("%d",&A[i]);
    for(int i=1; i<=N; i++) scanf("%d",&B[i]);
    for(int i=1; i<N; i++) scanf("%d",&C[i]);
    for(int i=1; i<=N; i++) {
        ans += B[i];
        if(i >= 2 && A[i-1] + 1 == A[i]) ans += C[A[i-1]];
    }
    printf("%lld", ans);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static int intN =0;
	static int sosuCnt =0;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String n = sc.nextLine();
		String[] v = sc.nextLine().split(" ");

		int intN = Integer.parseInt(n);

		double result = 0;
		for (int i = 0;i < v.length;i++) {

			result = result + 1.0 / Integer.parseInt(v[i]);

		}

		System.out.println(1 / result);
	}
}

Measured memory_bytes: 20820
from collections import deque
h,w=map(int,input().split())
s=[list(input()) for _ in range(h)]
ans=0
for i in range(h):
    for j in range(w):
        if s[i][j]==".":
            cnt=[[-1]*w for _ in range(h)]
            cnt[i][j]=0
            queue=deque()
            queue.append([i,j])
            for k in range(100*h*w):
                if len(queue)==0:
                    break
                num=queue.popleft()
                num1=num[0]
                num2=num[1]
                if num1!=0:
                    if s[num1-1][num2]=="." and cnt[num1-1][num2]==-1:
                        cnt[num1-1][num2]=cnt[num1][num2]+1
                        queue.append([num1-1,num2])
                if num2!=0:
                    if s[num1][num2-1]=="." and cnt[num1][num2-1]==-1:
                        cnt[num1][num2-1]=cnt[num1][num2]+1
                        queue.append([num1,num2-1])
                if num1!=h-1:
                    if s[num1+1][num2]=="." and cnt[num1+1][num2]==-1:
                        cnt[num1+1][num2]=cnt[num1][num2]+1
                        queue.append([num1+1,num2])
                if num2!=w-1:
                    if s[num1][num2+1]=="." and cnt[num1][num2+1]==-1:
                        cnt[num1][num2+1]=cnt[num1][num2]+1
                        queue.append([num1,num2+1])
            cnt2=0
            for k in range(h):
                cnt2=max(cnt2,max(cnt[k]))
            ans=max(ans,cnt2)
print(ans)


Measured memory_bytes: 9432