akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>

int check(char m1, char m2);

int main(void) {
	std::string str;

	std::cin >> str;

	int checkYM = 0;
	int checkMY = 0;

	checkYM = check(str[2], str[3]);

	checkMY = check(str[0], str[1]);

	if (checkYM == 0 && checkMY == 0) {
		std::cout << "AMBIGUOUS";
	}
	else if (checkYM == 0 && checkMY != 0) {
		std::cout << "YYMM";
	}
	else if (checkYM != 0 && checkMY == 0) {
		std::cout << "MMYY";
	}
	else {
		std::cout << "NA ";
	}

	return 0;
}

int check(char m1, char m2) {
	int rc = 0;

	int num1 = 0;
	int num2 = 0;

	num1 = atoi(&m1);
	num2 = atoi(&m2);

	if (num1 == 0) {
		if (num2 == 0) {
			rc = -1;
		}
		else {
			rc = 0;
		}
	}
	else if (num1 == 1) {
		if (num2 > 2) {
			rc = -1;
		}
		else {
			rc = 0;
		}
	}
	else {
		rc = -1;
	}

	return rc;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll INF = 987654321987654321;

int main()
{
	int N, K;
	ll ans = -INF;
	cin >> N >> K;
	vector<int>P(N), C(N);
	for (auto&i : P)
	{
		cin >> i;
		i--;
	}
	for (auto&i : C)cin >> i;

	for (int i = 0; i < N; i++)
	{
		int cycleN = 1, now = P[i];
		ll cycleSum = C[i];
		while (now != i)
		{
			cycleN += 1;
			cycleSum += C[now];
			now = P[now];
		}
		ll path = 0;
		int cnt = 0;
		while (true)
		{
			cnt++;
			path += C[now];
			if (cnt > K)break;
			ll score = path + max((ll)0, cycleSum)*((K - cnt) / cycleN);
			ans = max(ans, score);
			now = P[now];
			if (now == i)break;
		}
	}
	cout << ans;
}


Measured memory_bytes: 3592
def main():
    s = list(str(input()))
    s.reverse()
    s = [int(c) for c in s]
    s += [0]
    m = len(s)

    dp = [[10**7, 10**7] for _ in range(len(s)+5)]
    # dp[i][0]: 繰り下がりなし
    # dp[i][1]: 繰り下がりあり

    dp[0][0] = 0

    for i in range(m):
        for j in range(2):
            nd = s[i]
            if j == 1:
                nd += 1
            if dp[i+1][0] >= dp[i][j]+nd:
                dp[i+1][0] = dp[i][j]+nd
            if dp[i+1][1] >= dp[i][j]+10-nd:
                dp[i+1][1] = dp[i][j]+10-nd
    #print(dp)
    print(dp[m][0])

if __name__ == '__main__':
    main()

Measured memory_bytes: 153852
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int MAX = 100010;

struct edge {int to; ll dis;};

vector <edge> adj[MAX];
ll dist[MAX];
bool vst[MAX];

bool dfs(int v, ll td) {
    vst[v] = true;
    dist[v] = td;
    bool f = true;
    for (edge e : adj[v]) {
        if (vst[e.to]) {
            f = f && td+e.dis == dist[e.to];
        }
        else f = f && dfs(e.to, td+e.dis);
    }
    return f;
}

void solve(void){
    int N, M;
    cin >> N >> M;
    rep(M, i) {
        int l, r; ll d;
        cin >> l >> r >> d;
        l--, r--;
        adj[l].pb((edge{r, d}));
        adj[r].pb((edge{l, -d}));
    }
    rep(N, i) {
        if (!vst[i] && !dfs(i, 0LL)) {
            cout << "No" << endl;
            return;
        }
    }
    cout << "Yes" << endl;
}

int main(void){
  solve();
  //cout << "yui(*-v・)yui" << endl;
  return 0;
}


Measured memory_bytes: 15616
#include <stdio.h>

int main() {
	int i, sum, max;

	sum = max = 0;
	for (i = 0; i < 5; i++) {
		int a, b;

		scanf("%d", &a);
		b = (a + 9) / 10 * 10;
		sum += b;
		if (max < b - a)
			max = b - a;
	}
	printf("%d\n", sum - max);
	return 0;
}


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

typedef long long ll;

int N;
bool edge[50][50] = {};
int force[50] = {};
ll memo[50];
int dp1[1<<21], dp2[1<<21];

int dfs1(int state) {
    int &ret = dp1[state];
    if (ret >= 0) return ret;
    ret = 0;

    int n = N/2;
    for (int i = 0; i < n; i++) {
        if (!((state >> i) & 1)) continue;
        int next_state = (int)(((ll)state) & memo[i]);
        ret = max(ret, force[i] + dfs1(next_state));
    }
    return ret;
}

int dfs2(int state) {
    int &ret = dp2[state];
    if (ret >= 0) return ret;
    ret = 0;

    int n = N/2, ns = N - n;
    for (int i = 0; i < ns; i++) {
        if (!((state >> i) & 1)) continue;
        int next_state = (int)(((ll)state) & (memo[i + n] >> n));
        ret = max(ret, force[i + n] + dfs2(next_state));
    }
    return ret;
}

int main() {
    while (cin >> N, N) {
        map<string, int> name2id;
        memset(edge, false, sizeof(edge));
        for (int i = 0; i < N; i++) {
            string from; int f, n_v;
            cin >> from >> f >> n_v;
            if (!name2id.count(from)) {
                int id = name2id.size();
                name2id[from] = id;
            }

            int fid = name2id[from];
            force[fid] = f;
            edge[fid][fid] = true;

            for (int j = 0; j < n_v; j++) {
                string to; cin >> to;
                if (!name2id.count(to)) {
                    int id = name2id.size();
                    name2id[to] = id;
                }
                edge[fid][name2id[to]] = true;
            }
        }

        if (N == 1) {
            cout << force[0] << endl;
            continue;
        }

        for (int i = 0; i < N; i++) {
            ll tmp = 0;
            for (int j = 0; j < N; j++)
                if (edge[i][j]) tmp |= (1ll << j);
            memo[i] = ((1ll << 55) - 1) ^ tmp;
        }

        memset(dp1, -1, sizeof(dp1));
        memset(dp2, -1, sizeof(dp2));
        int n = N / 2, ans = 0;
        for (int state = 0; state < (1 << n); state++) {
            if (state & 1) continue;

            bool is_ok = true;
            for (int i = 0; is_ok && i < n; i++) {
                if (edge[0][i] && ((state >> i) & 1)) is_ok = false;
            }
            if (!is_ok) continue;

            ll flag = (1ll << N) - 1;
            flag &= memo[0];
            for (int i = 0; i < n; i++) {
                if ((state >> i) & 1) flag &= memo[i];
            }
            int ns = (int)(flag >> n);

            ans = max(ans, force[0] + dfs1(state) + dfs2(ns));
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 19608
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

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

const bool ready = [](){
    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(12);
    return true;
}();

const double PI = acos(-1);
using ll= long long;
#define int ll
#define all(v) (v).begin(), (v).end()
#define fori(n) for(int i=0; i<int(n); i++)

#define cini(i) int i; cin>>i;
#define cins(s) string s; cin>>s;
#define cind(d) double d; cin>>d;
#define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; }

using pii= pair<int, int>;
using pdd= pair<double, double>;
using vd= vector<double>;
using vb= vector<bool>;
using vi= vector<int>;
using vvi= vector<vi>;
using vs= vector<string>;

#define endl "\n"

/* see https://cp-algorithms.com/data_structures/disjoint_set_union.html
 * Also known as union find structure. 
 * Note that the above link has some optimizations for faster combining of sets if needed. 
 */

struct Dsu {
    vector<int> p;
/* initializes each (0..size-1) to single set */
    Dsu(int size) {
        p.resize(size);
        iota(p.begin(), p.end(), 0);
    }

/* makes v a single set, removes it from other set if contained there. */
    void make_set(int v) {
        p[v] = v;
    }

/* finds set representative for member v */
    int find_set(int v) {
        if (v == p[v])
            return v;
        return p[v] = find_set(p[v]);
    }

/* combines the sets of two members. 
 * Use the bigger set as param a for optimized performance.  */
    void union_sets(int a, int b) {
        a = find_set(a);
        b = find_set(b);
        if (a != b)
            p[b] = a;
    }
};

void solve() {
    cini(n);
    cini(m);

    Dsu dsu(n);
    for(int i=0; i<m; i++) {
        cini(a); a--;
        cini(b); b--;
        dsu.union_sets(a,b);
    }

    set<int> s;
    for(int i=0; i<n; i++) 
        s.insert(dsu.find_set(i));

    cout<<s.size()-1<<endl;
}

signed main() {
    solve();
}

// FIRST THINK, THEN CODE
// DO NOT JUMP BETWEEN PROBLEMS


Measured memory_bytes: 7856
<?php
list($N, $K) = array_map("intval", explode(" ", trim(fgets(STDIN))));
$hArray = array_map("intval", explode(" ", trim(fgets(STDIN))));
 
$dp = array_fill(0, $N+1, 10**18);
$dp[0] = 0;
for($i = 1; $i < $N; $i++){
    $dpi = &$dp[$i];
    $limit = min($i, $K);
    $hi = $hArray[$i];
    for($j = $i, $J = $i-$limit; $j >= $J; --$j){
        $diff = $hi - $hArray[$j];
        if($diff>0){
            $new = $dp[$j] + $diff;
        }else{
            $new = $dp[$j] - $diff;
        }
        if($new < $dpi){
            $dpi = $new;
        }
    }
}
echo $dp[$N-1];

Measured memory_bytes: 16884
#include <iostream>
#include <algorithm>
using namespace std;
main() {
 pair< int, pair<int,int> > p1, p2;
 cin >> p1.first >> p1.second.first >> p1.second.second;
 cin >> p2.first >> p2.second.first >> p2.second.second;
 if ( p1 > p2 ) swap( p1, p2 );

 if ( p1.second < p2.second )
 cout << p2.first - p1.first + 1 << endl;
 else cout << p2.first - p1.first << endl;
}



Measured memory_bytes: 3100
n = input()

if int(n[-1]) == 2 or int(n[-1]) == 4 or int(n[-1]) == 5 or int(n[-1]) == 7 or int(n[-1]) == 9:
    print("hon")
elif int(n[-1]) == 0 or int(n[-1]) == 1 or int(n[-1]) == 6 or int(n[-1]) == 8:
    print("pon")
else:
    print("bon")


Measured memory_bytes: 9188
n,k=map(int,input().split())
a=list(map(int,input().split()))
c=0
d=0
for i in range(n-1):
  for j in range(i+1,n):
    if a[i]>a[j]:
      d+=1
for i in range(n):
  for j in range(n):
    if a[i]>a[j]:
      c+=1
ans=k*d+c*k*(k-1)//2
print(int(ans%(10**9+7)))


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

using namespace std;

int main(int argc, char const *argv[])
{
    string s;
    int count = 0;

    cin >> s;

    for (int i = 1; i < s.size(); i++) {
        if (s[i] == s[i-1]) {
            s[i] = (s[i] == '1') ? '0' : '1';
            count++;
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 512
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
#define u64 uint64_t
#define ll long long
#define endl "\n"
#define PI acos(-1)
#define fi first
#define si second
#define mp make_pair
#define pb push_back
#define set0(arr) memset(arr,0,sizeof(arr))
#define setinf(arr) memset(arr,126,sizeof(arr))
#define vsort(v) sort(v.begin(),v.end())
#define all(x) (x).begin(),(x).end()
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
using pll = pair<ll,ll>;
using vl = vector<ll>;
using vpll = vector<pll>;
using mll = map<ll,ll>;
using mcl = map<char,ll>;
using sl = set<ll>;
using sc = set<char>;
using dl = deque<ll>;
ll mod=1e9+7;
const int N=1e6+5;
vl adj[200005];
vpll adjc[200005];
ll vis[200005],dis[200005];
ll arr[N];
void dfs(ll x)
{
    vis[x]=1;
    for(ll i=0;i<adjc[x].size();i++)
    {
        auto p=adjc[x][i];
        if(!vis[p.first])
        {
            dis[p.first]=dis[x]+p.second;
            dfs(p.first);
        }
    }
}
int main()
{
    IOS;
    ll a,b,c,d,sz,n,m,p,x,y,z,i,j,k,f=0,tc,cnt=0,sum=0,mul=1,mi=1e18,ma=-1e18;
    string str;
    char ch;
    double db;
    //code
    cin>>n;
     set0(vis);
    for(i=1;i<n;i++)
    {
        cin>>a>>b>>c;
        adjc[a].pb({b,c});
        adjc[b].pb({a,c});
    }
    dis[1]=0;
    dfs(1);
   for(i=1;i<=n;i++)
   {
       cout<<dis[i]%2<<endl;
   }



    //code
    return 0;
}


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

int main(){
  int N;
  string s;
  cin>>N>>s;

  for(int i=0;i<s.size();i++){
    if((int)s.at(i)<90-N+1)
      s.at(i)=char((int)s.at(i)+N);
    else
      s.at(i)=char((int)s.at(i)+N-26);
  }
  cout << s <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln =  '\n';

const int mx=200010;
const ll mod=1e9+7;


int main(){
  int n,k;
  cin >> n >> k;
  vector<ll> a(n+3,0);
  rep(i,n){
    cin >> a[i];
  }
  vector<ll> dp(mx,longinf);
  dp[0]=0;
  rep(i,n){
    REP(j,1,k+1){
      dp[i+j] = min(dp[i+j], dp[i]+abs(a[i]-a[i+j]));
    }
  }
  ll ans = dp[n-1];
  cout << ans << ln;
  return 0;
}

Measured memory_bytes: 2560
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;
using ll = long long;

ll gcd(ll x, ll y){
  if(x < y) swap(x,y);
  while(y) x %= y, swap(x,y);
  return x;
}

int main(){
  ll n, m;
  cin >> n >> m;
  vector<ll> A(n);
  vector<double> P(n);
  for(int i = 0; i < n; ++i) cin >> A[i];
  for(int i = 0; i < n; ++i) cin >> P[i], P[i] /= 100.0;
  double ans = 0;
  vector<ll> LCM;
  vector<double> P_;
  LCM.push_back(1);
  P_.push_back(-1.0);
  for(int i = 0; i < n; ++i){
    ll s = LCM.size();
    for(ll j = 0; j < s; ++j){
      if(LCM[j]/gcd(LCM[j],A[i]) > m/A[i]) continue;
      ll t = LCM[j]/gcd(LCM[j],A[i])*A[i];
      if(t > m) continue;
      double p = -P_[j]*P[i];
      ans += m/t*p;
      LCM.push_back(t);
      P_.push_back(p);
    }
  }
  printf("%.12f\n",ans);
  return 0;
}



Measured memory_bytes: 19548
import java.util.*;
public class Main {
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        int N = Integer.parseInt(a + "" + b);
        
        double d = Math.sqrt(N);
        
        
        
        System.out.println(d % 1 == 0 ? "Yes" : "No");
    }
    
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define ALLOF(v) (v).begin(), (v).end()
#define SZ(v) ((int)(v).size())
#define DUMP(x) cerr << #x << " = " << (x) << endl;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double PI = acos(-1);

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

int main(void)
{
    int n, m;
    cin >> n >> m;
    vector<ll> h(n + 1);
    vector<ll> ma(n + 1);
    reps(i, n) cin >> h.at(i);
    rep(_, m)
    {
        int a, b;
        cin >> a >> b;
        chmax(ma.at(a), h.at(b));
        chmax(ma.at(b), h.at(a));
    }
    int ans = 0;
    reps(i, n) ans += h.at(i) > ma.at(i);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4820
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "}"; return os; }


int main(){
    LL h, w, n;
    cin >> h >> w >> n;
    LL x = max(h, w);
    LL ans = (n + x-1) / x;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 888
#include <cstdio>
#include <cstring>

using namespace std;

const int MAX_WIDTH = 1005, MAX_HEIGHT = 1005, MOD = 1e9 + 7;
const char WALL = '#';
char grid[MAX_WIDTH][MAX_HEIGHT];
long long no_of_paths[MAX_WIDTH][MAX_HEIGHT];

int main()
{
    int height, width;
    scanf("%d %d", &height, &width);

    for(int i = 1; i <= height; i++)
        scanf("%s", grid[i] + 1);

    memset(no_of_paths, 0, sizeof(no_of_paths));

    for(int i = 1; i <= height; i++)
    {
        for(int j = 1; j <= width; j++)
        {
            if(grid[i][j] == WALL) continue;

            if(i == 1 && j == 1)
            {
                no_of_paths[i][j] = 1;
            }
            else
            {
                no_of_paths[i][j] = (no_of_paths[i - 1][j] + no_of_paths[i][j - 1])%MOD;
            }
        }
    }

    printf("%lld", no_of_paths[height][width]);
    return 0;
}

Measured memory_bytes: 10568
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#define rep(i,n) for(int i =0;i<(int)(n);i++)
typedef long long ll;
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	rep(i, n) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	int ans = 0;
	rep(i, n-1) {
		ans += a[i+1] - a[i];
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;


int main(){
    
    string A, B, U;
    int a, b;

    cin >> A >> B;
    cin >> a >> b;
    cin >> U;

    if( U == A ){
        cout << (a-1) << " " << b << endl;
    }else{
        cout << a << " " << (b-1) << endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    abc143c()
}

fun abc143c() {
    val n = readLine()!!.toInt()
    val s = readLine()!!

    val slimes = mutableListOf<Char>()
    s.forEachIndexed { index, c ->
        if (index > 0) {
            if (slimes.last() != c) slimes.add(c)
        } else {
            slimes.add(c)
        }
    }

    println(slimes.size)
}


Measured memory_bytes: 36292
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   B_How_Many_ways.c                                  :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: mkosaka <42tokyo_jan2020_pisciner>         +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/02/05 11:57:49 by mkosaka           #+#    #+#             */
/*   Updated: 2020/02/05 11:57:49 by mkosaka          ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include <stdio.h>
#include <stdlib.h>

int		combination_sum_equals(int n, int sum)
{
	int count;
	int i;
	int j;
	int k;

	count = 0;
	i = 1;
	while (i <= n - 2)
	{
		j = i + 1;
		while (j <= n -1)
		{
			k = j + 1;
			while (k <= n)
			{
				if (i + j + k == sum)
					count += 1;
				k++;
			}
			j++;
		}
		i++;
	}
	return (count);
}

void	print_integers(int *integers, int ammounts)
{
	int i;

	i = 0;
	while (i < ammounts)
	{
		printf("%d\n", integers[i]);
		i++;
	}
}

int		main(void)
{
	int *counts;
	int n;
	int x;
	int i;

	counts = (int *)malloc(sizeof(int) * 300);
	i = 0;
	while (1)
	{
		scanf("%d %d", &n, &x);
		if (n == 0 && x == 0)
			break;
		counts[i] = combination_sum_equals(n, x);
		i++;
	}
	print_integers(counts, i);
	return (0);
}



Measured memory_bytes: 2072
#![allow(unused_imports)]
use std::io;
use std::cmp::*;
use std::collections::*;
#[allow(dead_code)]
const M: i64 = 1e9 as i64 + 7;

fn read_line() -> String {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();
    buf
}
#[allow(dead_code)]
fn read<T>() -> T where T: std::str::FromStr, T::Err : std::fmt::Debug {
    read_line().trim().parse().unwrap()
}
#[allow(dead_code)]
fn readv<T>() -> Vec<T> where T: std::str::FromStr, T::Err : std::fmt::Debug {
    read_line().split(' ').map(|a| a.trim().parse().unwrap()).collect()
}

use std::time::Instant;
fn main() {
    let now = Instant::now();
    let _ = read::<usize>();
    let aa = readv::<usize>();
    let bb = readv::<usize>();
    let x = aa.iter().fold(0, |acc, &a| acc ^ a);
    let (mut aa, bb): (Vec<_>, Vec<_>) = aa.iter().zip(bb.iter()).filter(|&(&a, &b)| a != b).unzip();
    let n = aa.len();
    aa.push(x);
    let mut nums = HashMap::with_capacity(n + 1);
    for &a in &aa {
        *nums.entry(a).or_insert(0) += 1;
    }
    // let mut nums: HashMap<_, i32> = aa.iter()
    //     .fold(HashMap::with_capacity(n + 1), |mut acc, &a| { *acc.entry(a).or_insert(0) += 1; acc });
    for &b in &bb {
        *nums.entry(b).or_insert(0) -= 1;
        if nums[&b] < 0 {
            println!("{}", -1);
            return;
        }
    }
    if now.elapsed().as_secs() >= 1 {
        std::process::exit(1);
    }

    let mut dests = bb.iter().enumerate()
        .fold(HashMap::new(), |mut acc, (a, b)| { (acc.entry(b).or_insert(Vec::new())).push(a); acc });
    let mut q: VecDeque<_> = std::iter::once(n).collect();
    let mut rems: HashSet<_> = (0..n + 1).collect();
    let mut ans = n;
    #[cfg(local)] println!("{}: {:?}", "(aa, bb)", (&aa, &bb));
    while !rems.is_empty() {
        while let Some(s_idx) = q.pop_front() {
            if !rems.remove(&s_idx) { continue; }
            let s_num = aa[s_idx];
            if let Some(destv) = dests.remove(&s_num) {
                for dest in destv {
                    q.push_back(dest);
                }
            }
        }
        if let Some(&rem) = rems.iter().next() {
            q.push_back(rem);
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 27576
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		string str = Console.ReadLine();
		int R = 0;
		int B = 0;
		for(var i=0;i<N;i++){
			if(str.Substring(i,1)=="R"){
				R++;
			} else {
				B++;
			}
		}
		string ans = "No";
		if(R>B){
			ans = "Yes";
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 11092
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
using namespace std;

int main(void){
        int i,j;
        int n;
        int d[150],e[150];
        scanf("%d",&n);
        for(i=0;i<n;i++){
            scanf("%d%d",&d[i],&e[i]);
        }
        
        for(i=0;i<n-2;i++){
            if( (d[i]==e[i]) && (d[i+1]==e[i+1]) && (d[i+2]==e[i+2]) ){
                printf("Yes\n");
                return 0;
            }
        }
        printf("No\n");

        return 0;
}


Measured memory_bytes: 3684
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

    int R, G;
    cin >> R >> G;

    cout << 2 * G - R << "\n";
    
    int a;
    cin >> a;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
#define int long long
#define double long double
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define sz size()
#define bgn begin()
#define en end()
#define pb push_back
#define pp() pop_back()
#define V vector
#define P pair
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())
#define Q queue
#define pri priority_queue
#define Pri priority_queue<int,vector<int>,greater<int>>
#define PriP priority_queue<P<int,int>,vector<P<int,int>>,greater<P<int,int>>>
#define all(a)  (a).begin(),(a).end()


signed main(){
  int a,b;
  cin>>a>>b;
  V<V<int>> c(10,V<int>(10));
  fo(i,10){
    fo(j,10){
      cin>>c[i][j];
    }
  }
  V<V<int>> d(a,V<int>(b));
  fo(i,a){
    fo(j,b){
      cin>>d[i][j];
    }
  }
  fo(k,10){
    fo(i,10){
      fo(j,10){
        c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
      }
    }
  }
  int e=0;
  fo(i,a){
    fo(j,b){

      if(d[i][j]!=-1){
        e+=c[d[i][j]][1];
      }
    }

  }
  cout<<e<<endl;
}

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

int main() {
    string W, T;
    
    cin >> W;
    
    for (int i = 0; i < W.size(); i++) {
        if ('A' <=W[i] && W[i] <= 'Z') W[i] += 'a' - 'A';
    }
    
    int count = 0;
    while(cin >> T) {
        if (T == "END_OF_TEXT") break;
        for (int i = 0; i < T.size(); i++){
            if ('A' <= T[i] && T[i] <= 'Z') T[i] += 'a' - 'A';
        }
        if (W == T) count++;
    }
    
    printf("%d\n", count);
}



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

#define pb push_back 
#define x first 
#define y second 
#define MOD 1000000007

using namespace std;
typedef long long ll;
typedef pair< int , int > PII;
const int dirx[] = {-2,-1,1,2, 1, -1};
const int diry[] = {0,1,1,0, -1, -1};
inline void debugMode() {
    #ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
    freopen("output.out", "w", stdout);
    #endif
}

int n, m, a[100100][3], dp[100100][3];
string s, c;

int main(){
	//debugMode();
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i][1];
	for (int i = 1; i <= n; i++) cin >> a[i][2];
	for (int i = 1; i <= 2; i++){
		for (int j = 1; j <= n; j++){
			dp[j][i] = max(dp[j - 1][i], dp[j][i - 1]) + a[j][i];
		}
	}
	cout << dp[n][2];
	return 0;
}


Measured memory_bytes: 256
#N = int(input())
#A = list(map(int,input().split()))
X,Y = map(int,input().split())	


#合計を求める
sum = 0

if(X == 1):
  #300,000
  sum += 300000
  if(Y == 1):
    sum += 300000
    sum += 400000
  elif(Y == 2):
    sum += 200000
  elif(Y == 3):
    sum += 100000
  else:
    pass
elif( X == 2):
  #200,000
  sum += 200000
  if(Y == 1):
    sum += 300000
    #sum += 400000
  elif(Y == 2):
    sum += 200000
  elif(Y == 3):
    sum += 100000
  else:
    pass
elif( X == 3):
  #100,000
  sum += 100000
  if(Y == 1):
    sum += 300000
    #sum += 400000
  elif(Y == 2):
    sum += 200000
  elif(Y == 3):
    sum += 100000
  else:
    pass
else:
  if(Y == 1):
    sum += 300000
    #sum += 400000
  elif(Y == 2):
    sum += 200000
  elif(Y == 3):
    sum += 100000
  else:
    pass

print(sum)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef vector<ll>VI;
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 ALL(a)  (a).begin(),(a).end()
#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 $(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'
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<int> >;//ll or Edge
using Edge=pair<int,ll>;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// sort_reverse...greater<ll>()
// vector型から重複を削除 list.erase(unique(ALL(list)),list.end());
// g++ -o a a.cpp -Wall -lm -std=c++17

int main(){
    ll a,b,c;cin>>a>>b>>c;
    if(c-a-b>0 && a*a+b*b+c*c>2*(a*b+b*c+c*a))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3568
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int[][] A = new int[N][];
		for(int i=0;i<N;i++){
			A[i] = new int[N];
		}
		
		int b = 2;
		int cnt = 1;
		while(true){
			bool update = false;
			for(int i=0;i<N;i++){
				for(int j=i+1;j<N;j++){
					if(A[i][j] != 0) continue;
					if(A[i][j] == 0){
						update = true;
						for(int k=j;k<N;k+=b){
							A[i][k] = cnt;
						}
						break;
					}
				}
			}
			if(!update) break;
			cnt++;
			b *= 2;
		}
		
		
		
		
		for(int i=0;i<N-1;i++){
			Console.WriteLine(String.Join(" ", A[i].Skip(i + 1)));
		}
		
		
		
		
	}
	int N;
	public Sol(){
		N = ri();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 18768
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	ae := make([]string, 0, n)
	ba := make([]string, 0, n)
	bh := make([]string, 0, n)
	cr := make([]string, 0, n)
	for i := 0; i < n; i++ {
		var s string
		fmt.Scan(&s)
		if s[0] == 'B' && s[len(s)-1] == 'A' {
			ba = append(ba, s)
		} else if s[0] == 'B' {
			bh = append(bh, s)
		} else if s[len(s)-1] == 'A' {
			ae = append(ae, s)
		} else {
			cr = append(cr, s)
		}
	}
	sum := 0
	for _, v := range ae {
		for i := 1; i < len(v); i++ {
			if v[i-1] == 'A' && v[i] == 'B' {
				sum++
			}
		}
	}
	for _, v := range ba {
		for i := 1; i < len(v); i++ {
			if v[i-1] == 'A' && v[i] == 'B' {
				sum++
			}
		}
	}
	for _, v := range bh {
		for i := 1; i < len(v); i++ {
			if v[i-1] == 'A' && v[i] == 'B' {
				sum++
			}
		}
	}
	for _, v := range cr {
		for i := 1; i < len(v); i++ {
			if v[i-1] == 'A' && v[i] == 'B' {
				sum++
			}
		}
	}
	ac := len(ae)
	bac := len(ba)
	bc := len(bh)
	if ac == bac {
		sum += ac
		bac = 0
	} else if ac < bac {
		sum += ac
		bac = bac - ac
	} else {
		sum += bac
		bac = 0
	}
	if bc == bac {
		sum += bc
		bac = 0
	} else if bc < bac {
		sum += bc
		bac = bac - bc
	} else {
		sum += bac
		bac = 0
	}
	if bac == 0 {
		if ac <= bc {
			sum += ac
		} else {
			sum += bc
		}
	} else {
		if ac != 0 || bc != 0 {
			sum += bac
		} else {
			sum += bac - 1
		}
		if ac <= bc {
			sum += ac
		} else {
			sum += bc
		}
	}
	fmt.Println(sum)
}


Measured memory_bytes: 1408
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let m1: usize = read!();
    let _: usize = read!();
    let m2: usize = read!();
    let _: usize = read!();

    let ans = if m1 != m2 { 1 } else { 0 };
    println!("{}", ans);
}



Measured memory_bytes: 2072
#pragma region template
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(ll i=0,i##_len=(n);i<i##_len;i++)
#define rep2(i,a,b) for(ll i=(a),i##_len=(b);i<=i##_len;i++)
#define rrep(i,n) ll i=(n);ll now=-1;while(i--&&(now++||1))
#define Yes(n) cout<<((n)?Yes:No)
#define pb push_back
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vbl = vector<bool>;
using vint = vector<int>;
using vstr = vector<string>;
static inline void ignore_ret(int x) {x++;}
template<class T> inline bool chmax(T&a,const T&b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T&a,const T&b){if(a>b){a=b;return true;}return false;}
template<class T> inline T gcd_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=gcd(r,v.at(i));return r;}
template<class T> inline T lcm_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=lcm(r,v.at(i));return r;}
template<class T> inline T factorial(T n){if(n==0)return 1;T r=1;for(T i=2;i<=n;i++)r*=i;return r;}
template<class T> inline T nCr(T n,T k){if(n<k||n<0||k<0)return 0;T r=1;k=min(k,n-k);for(T i=n-k+1;i<=n;i++)r*=i;return r/factorial(k);}
template<class T> inline T dot_product(vector<T>u,vector<T>v){T r=0;for(T i=0;i<u.size();i++)r+=u.at(i)*v.at(i);return r;}
template<class T> inline T sum(vector<T>v){return reduce(all(v),0LL);}
#pragma endregion template

map<string, int> mp;

void solve(ll N, vector<string> S) {
  for (auto x: S) {
    mp[x]++;
  }
  cout << mp.size() << endl;
}

int main() {
  ll N;
  ignore_ret(scanf("%lld",&N));
  vector<string> S(N);
  for(int i = 0 ; i < N ; i++){
    cin >> S[i];
  }
  solve(N, move(S));
  return 0;
}


Measured memory_bytes: 25120
N = int(input())
A = list(map(int,input().split()))
color = [0,0,0]
ans = 1
for i in range(N):
    p = 0
    flag = 0
    for j in range(3):
        if A[i] == color[j]:
            p += 1
            if flag == 0:
                color[j] += 1
                flag = 1  
    ans *= p
    ans %= 10**9+7
print(ans)

Measured memory_bytes: 83324
#include <cstdio>
#include <vector>
#include <algorithm>
#include <array>
#include <set>
#include <map>
#include <queue>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <cassert>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
#define repeat_from(i,m,n) for (int i = (m); (i) < int(n); ++(i))
using ll = long long;
using namespace std;
template <class T> inline void setmin(T & a, T const & b) { a = min(a, b); }

constexpr ll inf = ll(1e18)+9;
int main() {
    // input
    ll h, w; scanf("%lld%lld", &h, &w);
    auto maxdiff = [&](ll ah, ll aw, ll bh, ll bw, ll ch, ll cw) {
        assert (0 <= ah and ah <= h);
        assert (0 <= bh and bh <= h);
        assert (0 <= ch and ch <= h);
        assert (0 <= aw and aw <= w);
        assert (0 <= bw and bw <= w);
        assert (0 <= cw and cw <= w);
        ll as = ah * aw;
        ll bs = bh * bw;
        ll cs = ch * cw;
        assert (as + bs + cs == h * w);
        return max(abs(as - bs), max(abs(bs - cs), abs(cs - as)));
    };
    // solve
    ll result = inf;
    { // // hr, hr
        ll ah = h / 3;
        ll bh = (h - ah) / 2;
        ll ch = h - ah - bh;
        setmin(result, maxdiff(ah, w, bh, w, ch, w));
    }
    { // // vr, vr
        ll aw = w / 3;
        ll bw = (w - aw) / 2;
        ll cw = w - aw - bw;
        setmin(result, maxdiff(h, aw, h, bw, h, cw));
    }
    { // // vr, hr
        ll ah = h;
        repeat_from (aw,0,w+1) {
            ll bw = w - aw;
            ll cw = w - aw;
            ll bh = h / 2;
            ll ch = h - bh;
            setmin(result, maxdiff(ah, aw, bh, bw, ch, cw));
        }
    }
    { // // hr, vr
        ll aw = w;
        repeat_from (ah,0,h+1) {
            ll bh = h - ah;
            ll ch = h - ah;
            ll bw = w / 2;
            ll cw = w - bw;
            setmin(result, maxdiff(ah, aw, bh, bw, ch, cw));
        }
    }
    // output
    printf("%lld\n", result);
    return 0;
}


Measured memory_bytes: 128
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<long long> A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	vector<long long> newA;
	vector<int> C;
	int cont = 1;
	for (int i = 1; i <= N; ++i) {
		if (i == N || A[i - 1] != A[i]) {
			newA.push_back(A[i - 1]);
			C.push_back(cont);
			cont = 0;
		}
		++cont;
	}
	A = newA;
	N = A.size();
	vector<vector<int> > dp(N);
	for (int i = 0; i < N; ++i) {
		dp[i].resize(C[i] + 1, 0);
	}
	int ans = 0;
	for (int i = N - 1; i >= 0; --i) {
		int par = -1;
		int b = 1;
		while (b < A[i]) b <<= 1;
		b -= A[i];
		for (int j = C[i] - 1; j >= 0; --j) {
			dp[i][j] = max(dp[i][j], dp[i][j + 1]);
		}
		if (b == 0) {
			int sub = 0;
			for (int j = 0; j <= C[i]; ++j) {
				sub = max(sub, dp[i][j] + j / 2);
			}
			ans += sub;
		}
		else {
			int pos = lower_bound(A.begin(), A.end(), b) - A.begin();
			if (A[pos] != b) {
				ans += *max_element(dp[i].begin(), dp[i].end());
			}
			else {
				for (int j = 0; j <= C[pos]; ++j) {
					for (int k = 0; k <= C[i] && j + k <= C[pos]; ++k) {
						dp[pos][j] = max(dp[pos][j], dp[pos][j + k] + dp[i][k] + k);
					}
				}
			}
		}
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 15088
#include <cstdio>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define _ << " _ " <<
#define TRACE(x) cerr << #x << " = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define debug
#define TRACE(x)

using namespace std;

typedef long long llint;

const int MAXN = 200010;

vector<int> e[2][MAXN];
int n, X, Y, dad[MAXN], sp[MAXN], dist[MAXN], sol;
bool infi;

void dfs(int t, int x, int par) {
  dad[x] = par;
  for (int y : e[t][x])
    if (y != par) {
      dist[y] = dist[x] + 1;
      dfs(t, y, x);
    }
}

void solve(int x, int par, int d) {
  if (sp[x]) infi = true;
  sol = max(sol, 2 * dist[x]);
  for (int y : e[0][x]) {
    TRACE(x _ y _ d _ dist[y]);
    if (y != par && dist[y] > d + 1)
      solve(y, x, d + 1);
  }
}

int main(void) {
  scanf("%d %d %d",&n,&X,&Y);
  --X; --Y;
  REP(t, 2) REP(i, n - 1) {
    int a, b;
    scanf("%d %d",&a,&b);
    --a; --b;
    e[t][a].push_back(b);
    e[t][b].push_back(a);
  }

  dfs(1, Y, -1);

  REP(a, n)
    for (int b : e[0][a]) {
      bool lng = true;
      if (dad[a] == b) lng = false;
      if (dad[b] == a) lng = false;
      if (dad[a] == dad[b]) lng = false;
      if (dad[a] != -1 && dad[dad[a]] == b) lng = false;
      if (dad[b] != -1 && dad[dad[b]] == a) lng = false;
      if (lng) sp[a] = sp[b] = 1;
    }

  REP(x, n) TRACE(x _ sp[x]);

  solve(X, -1, 0);
  if (infi)
    sol = -1;
  
  printf("%d\n",sol);
  
  return 0;
}


Measured memory_bytes: 35836
//ITNOA
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
const long long INF=1e9+10,MAX=2e5+1e4,MOD=1e9+7,MAXL=25;
typedef long long ll;
typedef pair<ll,ll> pii;
typedef pair<pii,ll> piii;
void OUT(long double o,int x){
	 cout<<fixed<<setprecision(x)<<o;
	 return;
}
ll a[MAX];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin>>n;
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		if(x!=0)
			a[x-1]++;
		a[x]++;
		a[x+1]++;
	}
	ll x=0;
	for(int i=0;i<=100000;i++)
		x=max(x,a[i]);
	cout<<x;
	return 0;
}


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

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

    int n;
    cin >> n;
    vector<vector<int>> adj(n * n);
    for (int i = 0; i < 2 * (n * n - n); i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    int start = -1;
    for (int i = 0; i < n * n; i++) {
        if (adj[i].size() == 2) {
            start = i;
            break;
        }
    }
    assert(start != -1);

    vector<vector<int>> ans(n, vector<int>(n));
    vector<bool> used(n * n);
    used[start] = true;
    ans[0][0] = start;
    int dx[] = {-1, 0};
    int dy[] = {0, -1};
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i == 0 && j == 0) continue;
            vector<int> need;
            for (int k = 0; k < 2; k++) {
                int x = i + dx[k], y = j + dy[k];
                if (0 <= x && x < n && 0 <= y && y < n) {
                    need.push_back(ans[x][y]);
                }
            }
            int deg = 4;
            if (i == 0 || i == n - 1 || j == 0 || j == n - 1) deg = 3;
            if ((i == 0 || i == n - 1) && (j == 0 || j == n - 1)) deg = 2;
            bool found = false;
            for (int k = 0; k < n * n; k++) {
                if (used[k]) continue;
                if (adj[k].size() != deg) continue;
                bool dame = false;
                for (int a : need) {
                    if (find(adj[k].begin(), adj[k].end(), a) == adj[k].end()) {
                        dame = true;
                        break;
                    }
                }
                if (dame) continue;
                ans[i][j] = k;
                used[k] = true;
                found = true;
                break;
            }
            assert(found);
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cout << ans[i][j] + 1;
            if (j != n - 1) cout << ' ';
        }
        cout << '\n';
    }
}



Measured memory_bytes: 3560
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int max(int a, int b)
{
    return a > b ? a : b;
}

int min(int a, int b)
{
    return a < b ? a : b;
}

/* O(n) */
int maximum_profit(int *A, int n)
{
    int maxv = -1000000000;
    int minv = A[0];

    for (int j = 1; j < n ; j++)
    {
        maxv = max(maxv, A[j] - minv);
        minv = min(minv, A[j]);
    }
    return maxv;
}

/* 効率悪い (O(n^2)) */
// int maximum_profit(int *A, int n)
// {
//     int maxv = -1000000;

//     for (int j = 1; j < n; j++)
//     {
//         for (int i = 0; i < j; i++)
//         {
//             if (A[j] - A[i] > maxv)
//             {
//                 maxv = A[j] - A[i];
//             }
//         }
//     }
//     return maxv;
// }

int main(void)
{
    int n;
    int A[200000];

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

    printf("%d\n", maximum_profit(A, n));

    return 0;
}


Measured memory_bytes: 2528
#include<iostream>
#include<string>
#include<math.h>

using namespace std;
int main() {

	int X,A,B,C;
	char str[3][3];
	
	
	/*
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			cin >> str[i][j];
			
		}
	}

	cout << str[0][0] << str[1][1] << str[2][2] << endl;
	*/
	

	cin >> X >> A >> B;
	C = (X - A) / B;
	cout << (X - A) - (C*B) << endl;
	
	
	
	return 0;

}


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

a = readline().rstrip().decode('utf-8')
a = a[::-1]
b = readline().rstrip().decode('utf-8')
b = b[::-1]
c = readline().rstrip().decode('utf-8')
c = c[::-1]
lst = [a,b,c]
p = 0
while True:
    if lst[p] == "":
        if p == 0:
            print("A")
        elif p == 1:
            print("B")
        else:
            print("C")
        exit()
    idx = lst[p][-1]
    lst[p] = lst[p][:-1]
    if idx == "a":
        p = 0
    elif idx == "b":
        p = 1
    else:
        p = 2

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define ll long long int
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define pb(v, a) v.push_back(a)
#define Sort(v) sort(v.begin(), v.end())
#define For(m) for (auto it = m.begin(); it != m.end(); it++)
#define mod 1000000007
#define PI 3.14159265358979323846
using namespace std;

int main()
{
  ll k,a,b;
  cin >> k >> a >> b;
  if(a+1>=b)
  {
      cout << k+1;
  }
  else
  {
      if(k<=a)
      {
          cout << k+1;
      }
      else
      {
          ll sum = a;
          ll m = k-a+1;
          if(m%2==1)
          {
              sum+=((m-1)/2)*(b-a);
              sum+=1;
          }
          else
          {
              sum+=((m)/2)*(b-a);
          }
          cout << sum << endl;
      }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define MOD 1000000007
#define len(x) x.size()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(v) v.begin(), v.end()
#define alla(a, n) a, a + n
#define F(i, n) for (i = 0; i < n; i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<string> vs;

int32_t main()
{

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string s;
  cin >> s;
  if (s[1] == 'B')
    cout << "ARC" << endl;
  else
    cout << "ABC" << endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 1000000009
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

// 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;
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 {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=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 {
    mint res(*this);
    return res/=a;
  }
};

mint pow2(ll n){
  mint ans = 1;
  if(n == 0){
    return ans;
  }
  else if(n % 2 == 0){
    ans = pow2(n/2);
    ans *= ans;
    return ans;
  }
  else{
    ans = pow2(n/2);
    ans *= ans;
    ans *= 2;
    return ans;
  }
}

mint f(ll n, ll k){
  mint ans = 1;
  mint N = n;
  rep(i, k){
    ans *= (N-i)/(i+1);
  }
  return ans;
}

int main(){
  ll n, a, b;
  cin >> n >> a >> b;
  mint ans = pow2(n)-1-f(n,a)-f(n,b);
  cout << ans.x << endl;
}

Measured memory_bytes: 256
# AOJ 0078 Magic Square
# Python3 2018.6.17 bal4u

MAX = 15

tbl = [0]*MAX
while True:
	n = int(input())
	if n == 0: break
	tbl = [[0 for r in range(n)] for c in range(n)]
	r, c = n//2+1, n//2
	tbl[r][c] = i = 1
	while i < n*n:
		r += 1
		c += 1
		while True:
			if c >= n: c = 0;
			elif c < 0: c = n - 1;
			if r >= n: r = 0;
			if tbl[r][c] == 0:
				i += 1
				tbl[r][c] = i
				break
			r += 1
			c -= 1

	for r in range(n):
		for c in range(n):
			print(format(tbl[r][c], '4d'), end='')
		print()


Measured memory_bytes: 5644
#include <iostream>
#include <string>
#include <map>

using namespace std;

typedef map<string, int> msi;

int main(){
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    string s;
    cin >> s;

    int l = 0, r = n;
    while (r - l > 1) {
        int mid = (l + r) / 2;

        bool f = false;
        msi m0, m1;
        for (int i = 0; i <= n - mid; i++) {
            string t = s.substr(i, mid);
            if (!m0.count(t)) {
                m0[t] = i;
            }
            if (i - m0[t] >= mid) {
                f = true;
            }
        }

        if (f) {
            l = mid;
        } else {
            r = mid;
        }
    }

    cout << l << endl;

    return 0;
}


Measured memory_bytes: 6680