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

int main() {
	long long n,x,k,i,j,m,ans,cur,res1,res2;
	cin >> n >> x >> m;
	
	vector<long long> p(m,-1),sum(m,0);
	sum[1]=x;
	cur=x; p[x]=1;
	for(i=2; i<=n; i++){
		cur=(cur*cur)%m;
		sum[i]=sum[i-1]+cur;
		if(p[cur]==-1){
			p[cur]=i;
		}else{
			res1=(n-p[cur])/(i-p[cur]);
			res2=(n-p[cur])-(i-p[cur])*res1;
			ans=sum[p[cur]]+res1*(sum[i]-sum[p[cur]])+sum[p[cur]+res2]-sum[p[cur]];
			cout << ans << endl; return 0;
		}
	}
	cout << sum[n] << endl;
	
	
	return 0;
}

Measured memory_bytes: 4812
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int s[100100];
    int n;
    cin >> n;
    int i = 1;
    while(n --)
    {
        cin >> s[i];
        i ++;
    }
    int m;
    cin >> m;
    while(m --)
    {
        int p, x;
        cin >> p >> x;
        int c;
        c = s[p];
        s[p] = x;
        int sum = 0;
        for(int j = 1; j < i; j ++)
        {
            sum += s[j];
        }
        cout << sum <<endl;
        s[p] = c;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();

		StringBuilder sb = new StringBuilder();


		for (int i = 0; i < b; i++) {
			for (int j = 0; j < a; j++) {
				sb.append(1);
			}

			for (int j = 0; j < w - a; j++) {
				sb.append(0);
			}

			sb.append("\n");
		}

		for (int i = 0; i < h - b; i++) {
			for (int j = 0; j < a; j++) {
				sb.append(0);
			}

			for (int j = 0; j < w - a; j++) {
				sb.append(1);
			}
			sb.append("\n");
		}

		System.out.println(sb.toString());
	}
}

Measured memory_bytes: 30568
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
 
/*---------------------------------------------------*/

bool is_prime(int n){
  if(n==0||n==1)return false;
  for(int i=2;i*i<=n;i++){
    if(n%i==0)return false;
  }
  return true;
}

int main(){
  int ans=0;
  int q,l,r;
  vi list;
  REP(i,1,100001){
    if(i%2==0)continue;
    if(is_prime(i)&&is_prime((i+1)/2))list.pb(i);
  }
  cin>>q;
  //cout<<list.size()<<endl;
  rep(i,q){
    ans=0;
    cin>>l>>r;
    rep(i,list.size()){
      if(l<=list[i]&&list[i]<=r){
	ans++;
        
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 640
from collections import deque

H, W = map(int, input().split())
X = [input() for _ in range(H)]

dist = [[0] * W for _ in range(H)]
dist[0][0] = 1
q = deque([(0, 0)])

while q:
    u, v = q.popleft()
    for i, j in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
        if (not (0 <= u + i < H and 0 <= v + j < W)
                or X[u + i][v + j] == "#"
                or dist[u + i][v + j] > 0):
            continue
            
        dist[u + i][v + j] = dist[u][v] + 1
        q.append((u + i, v + j))

if dist[-1][-1] > 0:
    print(W * H - dist[-1][-1] - sum(s.count("#") for s in X))
else:
    print(-1)


Measured memory_bytes: 39792
#!/usr/bin/env python3

import sys
# import math
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4


def main():
    mod = 1000000007                  # 10^9+7
    inf = float('inf')
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    k, x = mi()
    for i in range(x - (k-1), x + (k-1) + 1):
        print(i, end=' ')
    print('')

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include<algorithm>
#include<functional>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second
#define FOR(itr,data) for(__typeof((data).begin()) itr=(data).begin();itr!=(data).end();++itr)

typedef unsigned long long UInt64;
typedef long long Int64;

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

using namespace std;

typedef pair<int ,int > P;

map<string,int> strs;
int n;

/*
vector<string> split(string _str)
{
	vector<string> res;
	string tmp="";
	rep(i,_str.size())
	{
		if(_str[i]==' ')
		{
		//	cout<<tmp<<endl;
			res.pb(tmp);	
			tmp="";
			continue;
		}
		else if('a'<=_str[i] && _str[i]<='z')
		{
			tmp +=_str[i];
			
		}
	}
	res.pb(tmp);
	//cout<<res<<endl;
	return res;
}

void inputs()
{
	getchar();
	rep(i,n)
	{
		string str;
		getline(cin,str);

	//	cout<<"[debug]"<<str<<endl;
		//cout<<"[debug]"<<tmp<<endl;
		vector<string> tmp;
		tmp=split(str);


		rep(i,tmp.size())
		{
			cout<<"[debug]"<<tmp[i]<<endl;
			strs[tmp[i]]++;
		}

		
	}

}
//*/

void inputs()
{
	getchar();
	rep(i,n)
	{
		string str;
		getline(cin,str);
		stringstream ss(str);
		while(ss>>str)
			strs[str]--;
	
	}

}
int main()
{
	while(cin>>n)
	{
		if(!n) return 0;
		inputs();

		//cout<<"Hoge"<<endl;
		string c;cin>>c;

		vector<pair<int,string> > vec;
		vector<string> ans;
		
		FOR(it,strs)
		{
			if(c[0] == it->fr[0])
				vec.pb(mp(it->sc,it->fr));
		}

		sort(all(vec));

		int cnt=0;
		FOR(it,vec)
		{
			if(cnt==5) break;
			if(cnt) cout<<" "<<it->sc;
			else cout<<it->sc;
			cnt++;
		}

		if(!cnt) cout<<"NA";
		cout<<endl;

		
		strs.clear();

	}


		return 0;
}

Measured memory_bytes: 1244
#include<cstdio>
#include<vector>
using namespace std;
int main(){
	char s[200];
	int n,a,b,c,i;
	vector<int> v;
	scanf("%s",s);
	scanf("%d",&c);
	a=s[0]-'0';
	for(i=2;s[i-1];i+=2){
		if(s[i-1]=='+') a+=(s[i]-'0');
		else a*=(s[i]-'0');
	}
	v.push_back(s[0]-'0');
	for(i=2;s[i-1];i+=2){
		if(s[i-1]=='+') v.push_back(s[i]-'0');
		else v.back()*=(s[i]-'0');
	}
	b=0;
	for(i=0;i<v.size();i++) b+=v[i];
	if(a==c&&b==c) printf("U\n");
	else if(a==c&&b!=c) printf("L\n");
	else if(a!=c&&b==c) printf("M\n");
	else printf("I\n");
	return 0;
}

Measured memory_bytes: 1036
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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

	
	int A, B, C;
	cin >> A >> B >> C;

	if (A - B == B - C) co("YES");
	else co("NO");

	Would you please return 0;
}

Measured memory_bytes: 256
package main

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

const Mod = int(1e9) + 7

func main() {
	N := ReadInt()
	C := ReadInts(N)
	dp := make([]int, N+1)
	dp[0] = 1
	C = append(C, 2*1e5+1)
	s := make([]int, 2*1e5+2)
	for i := 0; i < N; i++ {
		dp[i+1] = dp[i]
		if C[i] != C[i+1] {
			dp[i+1] += s[C[i]]
			dp[i+1] %= Mod
			s[C[i]] += dp[i]
			s[C[i]] %= Mod
		}
	}
	fmt.Println(dp[N])
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 10224
import java.util.*;
import java.io.*;

//A - Frog 1

public class Main {
    static StringTokenizer st;
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

 
    public static void main(String[] args) throws IOException {
  
        int N = nextInt();
        int dp[] = new int[N+1];

        int input[] = new int[N+1];


        for (int i=1; i<=N;  i++) {
            input[i] = nextInt();
        }

        // now dp time
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[1] = 0;
        for (int i=1; i<=N;  i++) {
            if(i+1<=N){
                dp[i+1] = Math.min(dp[i+1], dp[i] + Math.abs(input[i+1]- input[i]));
            }
            if(i+2<=N){
                dp[i+2] = Math.min(dp[i+2], dp[i] + Math.abs(input[i+2]- input[i]));
            }
        }

        System.out.println(dp[N]);
    }
    

    public static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
    public static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

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

    static String next() throws IOException {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine().trim());
        return st.nextToken();
    }
}

Measured memory_bytes: 34208
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define ld long double
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef vector <ll> vi;
#define out(x) return cout<<x,0;
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define lc(n) 2*n+1
#define rc(n) 2*n+2
#define fill(a,b) memset((a),(b),sizeof((a)))
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL)); 
const ll N = 55, M = 35;

int main(){
    FAST;
    ll n, x = 0, m, k, i, t, ans = 1, j, y = 0, z = 0, c = 0;
    string s, s1;
    cin >> s;
    n = s.size();
    s1 = s;
    reverse(all(s1));
    if ( s1 != s ) out("No");
    
        string s2 = s.substr(0, (n - 1)/2);
        s1 = s2;
        reverse(all(s1));
        if ( s1 != s2 ) out("No");
        s2 = s.substr((n + 3)/2 - 1 , (n - 1)/2);
        if ( s1 != s2 ) out("No");

    cout << "Yes";
}

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

template <class T>
inline void read(T &x) {
    x = 0;
    int f = 0;
    char ch = getchar();
    while (!isdigit(ch))    { f |= ch == '-'; ch = getchar(); }
    while (isdigit(ch))     { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); }
    x = f ? -x : x;
    return ;
}

typedef unsigned long long uLL;

const uLL k = 1e18;

uLL a[100010];
uLL s;
int T, n;
bool flag;

int main () {
        flag = true;
        read(n);
        s = 1;
        for (int i = 1; i <= n; ++i) {
            read(a[i]);
            if (!a[i]) {
                flag = false;
            }
        }
        if (!flag) {
            puts("0");
            return 0;
        }
        for (int i = 1; i <= n; ++i) {
            if (a[i] == 0) {
                s = 0;
                break;
            }
            if (a[i] <= k / s) {
                s *= a[i];
            } else {
                flag = false;
                break;
            }
        }
        printf("%lld\n", flag ? s : -1);
    return 0;
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long int
#define INF 1000000007
#define llINF 1000000000000000007
#define v(i) vector<i>
#define vv(i) vector<vector<i>>
// cin.eof() 入力個数の問題
// int num = atoi(string.c_str()); 文字列の整数変換
int keta(ll n){int ans=0;while(n>0){n /= 10; ans++;}return ans;}
ll _pow(ll a,ll b){ll ans = 1;rep(i,b){ ans *= a;}return ans;}

int main() {
int n; cin>>n;
ll a[n],b[n];
pair<ll,ll> p[n];
rep(i,n){
    cin>>a[i]>>b[i];
    p[i] = make_pair(b[i],a[i]);
}
sort(p,p+n);
ll sum = 0;
rep(i,n){
sum += p[i].second;
if(sum > p[i].first){
    cout<<"No"<<endl;
    return 0;
}
}

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


Measured memory_bytes: 9852
#include<stdio.h>
#include<vector>
#include<map>
#define INF 1000000000
using namespace std;
typedef pair<int,int> P;
vector<P> stn[150];
vector<int> dp[150][80];
int abs(int a){return a>=0?a:-a;}
int min(int a,int b){return a<b?a:b;}
int main(){
	int n,m;
	int i,j,k,l;
	while(1){
	scanf("%d %d",&n,&m);
	if(n==0)return 0;
	for(i=0;i<150;i++){
		stn[i].clear();
		for(j=0;j<80;j++)dp[i][j].clear();
	}
	for(i=0;i<n;i++){
		int t;
		scanf("%d",&t);
		for(j=0;j<t;j++){
			int a,b;
			scanf("%d %d",&a,&b);
			stn[i].push_back(P(a,b));
			for(k=0;k<=m;k++)dp[i][k].push_back(INF);
		}
	}
	for(i=0;i<stn[0].size();i++)dp[0][0][i]=0;
	if(m>=1)for(i=0;i<stn[1].size();i++)dp[1][1][i]=0;
	for(i=0;i<n-1;i++){
		for(j=0;j<=m;j++){
			for(k=0;k<stn[i].size();k++){
				for(l=0;l<stn[i+1].size();l++){
					int cost=(stn[i][k].second+stn[i+1][l].second)*abs(stn[i][k].first-stn[i+1][l].first);
					dp[i+1][j][l]=min(dp[i+1][j][l],dp[i][j][k]+cost);
				}
			}
			if(j==m||i==n-2)continue;
			for(k=0;k<stn[i].size();k++){
				for(l=0;l<stn[i+2].size();l++){
					int cost=(stn[i][k].second+stn[i+2][l].second)*abs(stn[i][k].first-stn[i+2][l].first);
					dp[i+2][j+1][l]=min(dp[i+2][j+1][l],dp[i][j][k]+cost);
				}
			}
		}
	}
	int ans=INF;
	for(i=0;i<stn[n-1].size();i++){
		for(j=0;j<=m;j++)ans=min(ans,dp[n-1][j][i]);
	}
	for(i=0;i<stn[n-2].size();i++){
		for(j=0;j<m;j++)ans=min(ans,dp[n-2][j][i]);
	}
	printf("%d\n",ans);
	}
}

Measured memory_bytes: 2252
n,m = map(int,input().split())

brid = []

for _ in range(m):
    a,b = map(int,input().split())
    brid.append([a-1,b-1])

brid = brid[::-1]

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*n
        self.rank = [0]*n

    def find(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.find(self.root[x])
            return self.root[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if(x == y):
            return 

        elif(self.rank[x] > self.rank[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y

            if(self.rank[x] == self.rank[y]):
                self.rank[y] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def card(self, x):
        return -self.root[self.find(x)]

u = UnionFind(n)


tmp = n * (n-1) // 2
ans = []

for i in range(m):
    ans.append(tmp)
    if not u.same(brid[i][0],brid[i][1]):
        tmp -= u.card(brid[i][0])*u.card(brid[i][1])
        u.unite(brid[i][0],brid[i][1])

ans = ans[::-1]

for i in range(m):
    print(ans[i])


Measured memory_bytes: 116568
let rec divNumBy2 num acc =
    if num = 0 then 0
    else if num = 1 && acc = 0 then 1
    else if num % 2 = 0 then divNumBy2 (num / 2) (acc + 1)
    else acc

let judge n =
    let helper (i, divNum) (accI, addDivNum) =
        if divNum <= addDivNum then (accI, addDivNum) else (i, divNum)

    [| for i in [ 0 .. n ] do
        yield (i, divNumBy2 i 0) |]
    |> Array.fold helper (0, 0)
    |> fst

//let input = [| 7; 32; 1; 100 |]
//for i in input do judge i |> printfn "%d"
// expected 4; 32; 1; 64

[<EntryPoint>]
let main argv =
    let n = stdin.ReadLine() |> int
    judge n |> printfn "%d"
    0


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

const ll mod = 1000000007;

ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

int main() {
  int N;
  cin >> N;
  ll x, y, a;
  x = 0;
  y = 0;
  rep(i, N) {
    cin >> a;
    x += a;
    x %= mod;
    y += a * a;
    y %= mod;
  }
  x *= x;
  x %= mod;
  ll ans = x - y;
  if (ans < 0) ans += mod;
  ans = ans * modinv(2, mod) % mod;
  cout << ans << endl;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int N;
    cin >> N;
    vector<int> P(N);
    vector<int> Q(N);
    rep(i,N){
        cin >> P[i];
    }
    rep(i,N){
        cin >> Q[i];
    }
    vector<int> R(N);
    rep(i,N){
        R[i]=i+1;
    }
    int a,b;
    a=1;
    do{
        bool flg = true;
        for(int i=0;i<N;i++){
            if(R[i]!=P[i]){
                flg = false;
                break;
            }
        }
        if(flg==false){
            a++;
        }else{
            break;
        }
    }while(next_permutation(R.begin(),R.begin()+N));
    rep(i,N){
        R[i]=i+1;
    }
    b=1;
    do{
        bool flg = true;
        for(int i=0;i<N;i++){
            if(R[i]!=Q[i]){
                flg = false;
                break;
            }
        }
        if(flg==false){
            b++;
        }else{
            break;
        }
    }while(next_permutation(R.begin(),R.begin()+N));
    cout << abs(a-b) << endl;
    return 0;
}

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

int main(){
    int n,arr[1000000],p=0;
    memset(arr,0,sizeof(arr));
    cin>>n;
    for(int i=2;i<=n;i++){
        int x;
        cin>>x;
        arr[x]++;
    }
    for(int i=1;i<=n;i++){
        cout<<arr[i]<<"\n";
    }
    return 0;
}


Measured memory_bytes: 7540
import std.stdio;

void main() {
	int animals, legs;
	readf("%s %s", &animals, &legs);

	int turtles = animals;
	int cranes = 0;

	while (turtles >= 0) {
		if (turtles * 4 + cranes * 2 == legs) {
			writeln("Yes");
			return;
		}
		--turtles;
		++cranes;
	}

	writeln("No");
}


Measured memory_bytes: 2764
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;

if(a + b == c + d)  {
    cout << "Balanced" << endl;
}

else if(a+b > c+d)  {
    cout << "Left" << endl;

}

else {
    cout << "Right" << endl;
}


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
#define MOD 100000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<double,string> P;
const int INF=1e9;
bool comp(P a,P b){
      if(a.first!=b.first)return a.first>b.first;
      int l=min(a.second.size(),b.second.size());
      REP(i,l){
            if(a.second[i]!=b.second[i])return a.second[i]<b.second[i];
      }
      return a.second.size()<b.second.size();
}
int main(){
      int n,p,a,b,c,d,e,f,s,m;
      while(cin>>n&&n){
            vector<P> V;
            string l;
            REP(i,n){
                  cin>>l>>p>>a>>b>>c>>d>>e>>f>>s>>m;
                  if(m==1){
                        V.PB(P((double)(s*f-p)/(a+b+c+d+e),l));
                  }else{
                        V.PB(P((double)(s*f*m-p)/(a+b+c+(d+e)*m),l));
                  }
            }
            sort(ALL(V),comp);
            REP(i,V.size()){
                  cout<<V[i].second<<endl;
            }
            cout<<'#'<<endl;
      }
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#include <numeric>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())

#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
#define Dev 1000000007

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    int a;
    cin >> a >> a;
    cout << (H - h) * (W - w) << endl;
    return 0;
}

Measured memory_bytes: 256
list = [int(input()) for n in range(5)]
min = 100
min_arg = 0
for i in range(5):
  if min > list[i] % 10 and list[i] % 10 != 0:
    min = list[i] % 10
    min_arg = i
ans = 0
for i in range(5):
  if i == min_arg:
    continue
  ans += list[i]
  if ans % 10 != 0:
    ans = ans - (ans % 10) + 10
ans += list[min_arg]
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
	char x, y;
	cin >> x >> y;
	if (x == 'A') {x = '1';}
	if (x == 'B') {x = '2';}
	if (x == 'C') {x = '3';}
	if (x == 'D') {x = '4';}
	if (x == 'E') {x = '5';}
	if (x == 'F') {x = '6';}	
	if (y == 'A') {y = '1';}
	if (y == 'B') {y = '2';}
	if (y == 'C') {y = '3';}
	if (y == 'D') {y = '4';}
	if (y == 'E') {y = '5';}
	if (y == 'F') {y = '6';}
	if ((int)x > (int)y) {
		cout << ">" << endl;
	}
	if ((int)x < (int)y) {
		cout << "<" << endl;
	}
	if ((int)x == (int)y) {
		cout << "=" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;

using namespace std;

int main(void){
    ll N, Lin;
    vector<int> L;
    cin>>N;
    rep(i, N){
        cin>>Lin;
        L.push_back(Lin);
    }
    sort(all(L));
    ll count = 0;
    for(int i = N-1; i>1; i--){
        for(int j = i-1; j>0; j--){
            int d = L[i] - L[j];
            ll pattern =distance(upper_bound(L.begin(), L.begin()+j, d), L.begin()+j);
            //cout << pattern << endl;
            pattern = max(pattern, (ll)0);
            count+=pattern;
        }
    }
    cout <<count<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int INF=105;
int n,l[INF],ans;
signed main()
{
        scanf("%d",&n);
        for (int i=1; i<=n; i++) scanf("%d",&l[i]); sort(l+1,l+1+n);
        for (int i=1; i<=n; i++)
                for (int j=i+1; j<=n; j++)
                        for (int k=j+1; k<=n; k++)
                                if (l[i]+l[j]>l[k] && l[i]!=l[j] && l[j]!=l[k] && l[i]!=l[k]) ans++;
        cout<<ans<<"\n";
        return 0;
}


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

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

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <queue>

void solve(long M, long N, std::vector<long> A) {
  std::priority_queue<long> pq;
  for(auto a: A)
  {
    pq.push(a);
  }
  
  for(long i = 0; i < M; i++)
  {
    long tmp = pq.top(); pq.pop();
    tmp /= 2;
    pq.push(tmp);
  }
  
  long sum = 0;
  while(!pq.empty())
  {
    sum += pq.top(); pq.pop();
  }
  std::cout << sum << std::endl;
}
int main(void) {
  long M;
  long N;
  std::cin >> N;
  std::cin >> M;
  std::vector<long> A(N);
  for(auto i0 = 0; i0 < N; ++i0)
  {
    std::cin >> A[i0];
  }
  solve(M,N,A);
  return 0;
}


Measured memory_bytes: 2936
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;


using namespace std;

#define debug(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(int i=0;i<(int)(n);i++)
#define foi(i,k,n) for(int i=(k); i<(int)(n); i+=1)
#define fod(i,n,k) for(int i=k; i>=(int)n; i-=1)
#define fast_io ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define all(x) x.begin(), x.end()
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define endl "\n"

#define EPS 1e-12
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007

#define fir first
#define sec second
#define pb push_back
#define mp make_pair

typedef long long int llint;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<llint> VL;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MII;
typedef set<int> SI;
string tostr(int n) {stringstream rr;rr<<n;return rr.str();}
llint toint(string s) {stringstream ss(s); llint x; ss >> x; return x;}
//gp_hash_table<string, llint> table;


//int mpow(llint base, llint exp) {
  //base %= MOD;
  //llint result = 1;
  //while (exp > 0) {
    //if (exp & 1) result = ((llint)result * base) % MOD;
    //base = ((llint)base * base) % MOD;
    //exp >>= 1;
  //}
  //result %= MOD;
  //return result;
//}


//void makegraph(int n, int m){
	//int i, u, v;
	//while(m--){
		//cin>>u>>v;
		//u--, v--;
		//g[u].pb(v);
		//g[v].pb(u);
	//}
//}

//void dfs(int u, int par){
	//for(int v:g[u]){
		//if (v == par) continue;
		//dfs(v, u);
	//}
//}


// ------------------------------------------------------------------PRIYANSHU RAJPUT----------------------------------------------------------------  //


void solve(){
	int n, m, k;
	cin>>n>>m>>k;
	VI a(n), b(m);
	VL dpa(n, 0), dpb(m, 0);
	loop(i, n){
		cin>>a[i];
		dpa[i] = i == 0? a[i] : dpa[i-1] + a[i];
	}
	loop(i, m){
		cin>>b[i];
		dpb[i] = i == 0 ? b[i] : dpb[i-1] + b[i];
	}
	int ans = 0; 
	loop(i, n){
		int t = dpa[i];
		if(t > k) break;
		int book = upper_bound(all(dpb), k - t) - dpb.begin();
		//debug(t);
		ans = max(ans, i + book + 1);
	}
	int book = upper_bound(all(dpb), k) - dpb.begin();
	ans = max(ans, book);
	cout<<ans;
}



int main() {
	fast_io;
    int t = 1;
    //cin >> t;
    while(t--) {
      solve();
    }
    return 0;
}



Measured memory_bytes: 7952
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define INF 1000000000000000000
#define N 100100
#define pb push_back
#define MOD 1000000007
#define fn(i,n) for(int i=0;i<n;i+=1)
int dp[1001][1001];
char a[1001][1001];
signed main() {
    int n,m;cin>>n>>m;
    fn(i,n){
        fn(j,m)cin>>a[i][j];
    }

    fn(i,n+1)
    {
        fn(j,m+1)
        {
            if(i==0||j==0)dp[i][j]=0;
            else if(i==1 && j==1)dp[i][j]=1;
            else if(a[i-1][j-1]=='#')dp[i][j]=0;
            else
            {
                dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD;
            }
        }
    }
cout<<dp[n][m]%MOD<<endl;

    return 0;
}



Measured memory_bytes: 9088
import math
T1,T2=map(int,input().split())
A1,A2=map(int,input().split())
B1,B2=map(int,input().split())
C1,C2=A1-B1,A2-B2
D1,D2=T1*C1,T2*C2

if D1==-D2:
    print("infinity")
    exit(0)

diff=0
x=-1
ans=0

if  D1*(D1+D2)<0:
    ans+=1
    diff+=D1+D2
else:
    print(ans)
    exit(0)

if diff*(diff+D1)<=0:
    ans+=2*abs((diff+D1)//(D1+D2))

if diff+(D1+D2)*abs((diff+D1)//(D1+D2))+D1==0:
    ans+=1
if diff+(D1+D2)*abs((diff+D1)//(D1+D2))+D1+D2==0:
    ans+=1

print(ans)

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

int main()
{
    int n;
    cin >> n;
    int items = n / 100;
    int left = n % 100;
    int maxPossible = items*5;
    if(left > maxPossible)
    	cout << "0" << endl;
   	else
   		cout << "1" << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <queue>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

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

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }

// #define FL fflush(stdout)

#define MOD 1000000007
#define INF 2000000000

int GLL(LL& x) {
  return scanf("%lld", &x);
}

int GI(int& x) {
  return scanf("%d", &x);
}

int N, M;
map<int, int> cnt;
int main() {
  GI(N); GI(M);
  FORN(i, M) {
    int a, b; GI(a); GI(b);
    cnt[a]++;
    cnt[b]++;
  }

  for (auto kv : cnt) {
    if (kv.SS & 1) {
      printf("NO\n");
      return 0;
    }
  }
    
  printf("YES\n");
  return 0;
}

Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;



int main(){
	string S; cin >> S;
	int N = S.size();
	bool ok = true;
	for(int i = 0; i < N; i+=2){
		if(S[i] == 'L') ok = false;
	}
	for(int i = 1; i < N; i+=2){
		if(S[i] == 'R') ok = false;
	}
	cout << (ok ? "Yes" : "No") << endl;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		//????????£?????????????????????
		Scanner sc = new Scanner(System.in);
		//
		while(true){
		//??£?¨??????????????????????
		long sum = 0;
		//1??????????????????
		String line = sc.nextLine();
		//?????£?????\???????????????1???
		if(line.length()==1){
			//?????£?????\????????????1??????0?????£?????´????????????
			if(Integer.parseInt(line)==0){
				break;
				}
			}
			//
			for(int i=0;i<line.length();i++){
				sum += Integer.parseInt(String.valueOf(line.charAt(i)));
			}
			//
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 26920
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define ft first
#define sd second
#define mp make_pair
#define fr(i,n) for(int i=0;i<(n);i++)
#define Fr(i,n) for(int i=0;i++<(n);)
#define ifr(i,n) for(int i=(n)-1;i>=0;i--)
#define iFr(i,n) for(int i=(n);i>0;i--)

int main(){
  int n,h,k,c=1;
  cin>>n;
  cin>>k;
  fr(i,n-1){
    cin>>h;
    k=max(k,h);
    if(k==h) c++;
  }
  cout<<c<<endl;
}

Measured memory_bytes: 256
n = int(input())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))
sum = 0
before_target = 0
for i in range(n):
    target = a_list[i]
    if i != 0 and before_target+1 == target :
        sum += b_list[target - 1] + c_list[target - 2]
    else:
        sum += b_list[target - 1]
    before_target = target

print(sum)

Measured memory_bytes: 3064
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define vec vector
#define fi first
#define se second
#define eb emplace_back
#define ef emplace_front
#define pof pop_front()
#define pob pop_back()
#define Rep(i,n) for(li i=0,nn=(li)(n);i!=nn;++i)
#define Rep1(i,n) for(li i=1,nn=(li)(n)+1;i!=nn;++i)
#define Size(v) (li)(v.size())
#define SortA(v) sort(v.begin(),v.end())
#define SortD(v) sort(v.rbegin(),v.rend())
#define All(a) (a).begin(),(a).end()
#define Input(a) for(li ii=0,nn=(li)(a.size());ii!=nn;++ii){cin>>(a).at(ii);}
#define Input2(a,b) for(li ii=0,nn=(li)(a.size());ii!=nn;++ii){cin>>(a).at(ii)>>(b).at(ii);}
#define mp make_pair
using li = int64_t;
using intl = int64_t;
using vi = vec<li>;
using vb = vec<bool>;
using vvi = vec<vi>;
using qi = deque<li>;
using pi = pair<li, li>;
using vpi = vec<pi>;
using si = set<li>;
using vsi = vec<si>;
using mii = map<li, li>;
using vmii = vec<mii>;
vec<li> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<li> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr li INF = LLONG_MAX;

void Yes(li b) {
	if (b)cout << "Yes";
	else cout << "No";
}
void yes(li b) {
	if (b)cout << "yes";
	else cout << "no";
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	cout.precision(16);

	li N;

	cin >> N;

	char s;

	vsi al(26);

	Rep1(i, N) {
		cin >> s;
		al[s - 'a'].insert(i);
	}

	li Q, q,l,r,cnt;

	cin >> Q;

	Rep(i, Q) {
		cin >> q;
		if (q == 1) {
			cin>>q;
			Rep(j,26){
				if(al[j].find(q)!=al[j].end()){
					al[j].erase(q);					
					cin >>s;
					al[s - 'a'].insert(q);
                    break;
				}
			}
		}
		else{
			cnt=0;
			cin >>l>>r;
			Rep(j,26){
				if(al[j].lower_bound(l)!=al[j].upper_bound(r)){
                  cnt++;
                }
			}
			cout<<cnt<<'\n';
		}

	}
    

}

Measured memory_bytes: 27080
# -*- coding: utf-8 -*-
import fractions


def gcd(x, y):
    return int(fractions.gcd(x, y))


def lcm(x, y):
    return x * y // gcd(x, y)


tmp = input()
N, M = [int(a) for a in tmp.split()]
S = str(input())
T = str(input())
S_len = len(S)
T_len = len(T)

check_num = gcd(S_len, T_len)
S_skip = S_len // check_num
T_skip = T_len // check_num

ok = True
S_i = T_i = 0
for i in range(check_num):
    if S[S_i] != T[T_i]:
        ok = False
        break
    S_i += S_skip
    T_i += T_skip

if ok:
    print(lcm(S_len, T_len))
else:
    print(-1)




Measured memory_bytes: 5716
#include <iostream>
#include <cstdlib>
#include <vector>

using namespace std;


template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    // n -> number of nodes
    // enherit -> enherit of Abel group
    UnionFind(int n, Abel enherit = 0) {
        init(n, enherit);
    }

    void init(int n, Abel enherit = 0) {
        par.resize(n);
        rank.resize(n);
        diff_weight.resize(n);
        for (int i = 0; i < n; ++i){
            par[i] = i;
            rank[i] = 0;
            diff_weight[i] = enherit;
        }
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool is_same(int x, int y) {
        return root(x) == root(y);
    }

    bool unite_set(int x, int y, Abel w) {
        w += weight(x);
        w -= weight(y);
        x = root(x);
        y = root(y);
        if (x == y){
            return false;
        }
        if (rank[x] < rank[y]){
            swap(x, y);
            w = -w;
        }
        if (rank[x] == rank[y]){
            ++rank[x];
        }
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

int main()
{
    int n, m;
    int l, r, d;
    cin >> n >> m;
    UnionFind<int> uf(n);
    vector<int> data;
    data.resize(n);
    bool isContra = false;
    for (int i=0; i<m; ++i){
        cin >> l >> r >> d;
        --l;
        --r;
        if(uf.is_same(l, r)){
            if(uf.diff(l, r) != d){
                isContra = true;
                break;
            }
        }
        else {
            uf.unite_set(l, r, d);
        }
    }
    if(isContra){
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
    }
    return 0;
}


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

int N,K,A[200000],C[200001];

int main(){
	cin>>N>>K;
	for(int i=0;i<N;i++)cin>>A[i];
	for(int _=0;_<K;_++){
		for(int i=0;i<N;i++){
			C[i]=0;
		}
		for(int i=0;i<N;i++){
			C[max(0,i-A[i])]++;
			C[min(N,i+A[i]+1)]--;
		}
		for(int i=0;i<N;i++){
			C[i+1]+=C[i];
		}
		bool f=true;
		for(int i=0;i<N;i++){
			A[i]=C[i];
			if(A[i]!=N)f=false;
		}
		if(f)break;
	}
	for(int i=0;i<N;i++){
		cout<<A[i];
		if(i!=N-1)cout<<' ';
	}
	cout<<endl;
}


Measured memory_bytes: 5188
#include <stdio.h>

int main(void)
{
    int r,d,x[10],i;

    scanf("%d %d %d",&r,&d,&x[0]);

    for(i=0;i<10;i++){
        x[i+1]=r*x[i]-d;
    printf("%d\n",x[i+1]);
    }
    return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

// O(V^2 E)なのでフローが小さいときはFord-Fulkersonにすべき
template<class V> class MaxFlow_dinic {
public:
	struct edge { int to,reve;V cap;};
	static const int MV = 221100;
	vector<edge> E[MV];
	int itr[MV],lev[MV];
	void add_edge(int x,int y,V cap,bool undir=false) {
		E[x].push_back((edge){y,(int)E[y].size(),cap});
		E[y].push_back((edge){x,(int)E[x].size()-1,undir?cap:0});
	}
	void bfs(int cur) {
		MINUS(lev);
		queue<int> q;
		lev[cur]=0;
		q.push(cur);
		while(q.size()) {
			int v=q.front(); q.pop();
			ITR(e,E[v]) if(e->cap>0 && lev[e->to]<0) lev[e->to]=lev[v]+1, q.push(e->to);
		}
	}
	V dfs(int from,int to,V cf) {
		if(from==to) return cf;
		for(;itr[from]<E[from].size();itr[from]++) {
			edge* e=&E[from][itr[from]];
			if(e->cap>0 && lev[from]<lev[e->to]) {
				V f=dfs(e->to,to,min(cf,e->cap));
				if(f>0) {
					e->cap-=f;
					E[e->to][e->reve].cap += f;
					return f;
				}
			}
		}
		return 0;
	}
	V maxflow(int from, int to) {
		V fl=0,tf;
		while(1) {
			bfs(from);
			if(lev[to]<0) return fl;
			ZERO(itr);
			while((tf=dfs(from,to,numeric_limits<V>::max()))>0) fl+=tf;
		}
	}
};

template<int um> class UF {
	public:
	vector<int> par,rank,cnt;
	UF() {par=rank=vector<int>(um,0); cnt=vector<int>(um,1); for(int i=0;i<um;i++) par[i]=i;}
	void reinit() {int i; FOR(i,um) rank[i]=0,cnt[i]=1,par[i]=i;}
	int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));}
	int count(int x) { return cnt[operator[](x)];}
	int operator()(int x,int y) {
		if((x=operator[](x))==(y=operator[](y))) return x;
		cnt[y]=cnt[x]=cnt[x]+cnt[y];
		if(rank[x]>rank[y]) return par[x]=y;
		rank[x]+=rank[x]==rank[y]; return par[y]=x;
	}
};
UF<101010> PF,QF;
MaxFlow_dinic<int> mf;

int N;
int P[101010],Q[101010];


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>P[i];
		PF(i,P[i]);
	}
	FOR(i,N) {
		cin>>Q[i];
		QF(i,Q[i]);
	}
	FOR(i,N) {
		if(P[i]==i&&Q[i]==i) {
			mf.add_edge(0,200020,1);
		}
		else if(P[i]==i) {
			mf.add_edge(100010+QF[i],200020,1);
		}
		else if(Q[i]==i) {
			mf.add_edge(0,5+PF[i],1);
		}
		else if(P[i]!=Q[i]) {
			mf.add_edge(100010+QF[i],5+PF[i],1);
		}
		else {
			mf.add_edge(100010+QF[i],5+PF[i],1);
			mf.add_edge(5+PF[i],100010+QF[i],1);
		}
	}
	cout<<N-mf.maxflow(0,200020)<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 17408
k = gets.to_i

if k % 2 == 0 || k % 5 == 0 then
	puts -1
else
	x = 7
	(1..k).each{|i|
		mod = x % k
		if mod == 0 then
			puts i
			exit
		else
			x = mod * 10 + 7
		end
	}
end

Measured memory_bytes: 14300
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug" << x << endl;
using namespace std;

void role(int dice[7], char order){
    int temp;
    if(order == 'E'){
        temp = dice[1];
        dice[1] = dice[4];
        dice[4] = dice[6];
        dice[6] = dice[3];
        dice[3] = temp;
    }else if(order == 'N'){
        temp = dice[1];
        dice[1] = dice[2];
        dice[2] = dice[6];
        dice[6] = dice[5];
        dice[5] = temp;
    }
}

int compale(int *dice, int *otherDice){
    bool c = false;
    rep(k,4){
        role(dice, 'E');
        rep(i,4){
            role(dice, 'N');
            rep(j,4){
                role(dice, 'E');
                if(dice[1] == otherDice[1] &&
                   dice[2] == otherDice[2] &&
                   dice[3] == otherDice[3] &&
                   dice[4] == otherDice[4] &&
                   dice[5] == otherDice[5] &&
                   dice[6] == otherDice[6]
                  ){
                    c = true;
                    break;
                }
            }
            if(c) break;
        }
        if(c) break;
    }
    if(c) return 1;
    else return 0;
}

int main(){
    int dice[101][7], n;
    cin >> n;
    rep(i,n){
        rep(j,6){
            cin >> dice[i][j + 1];
        }
    }
    bool c = false;
    rep(i,n - 1){
        for(int j = i + 1; j < n; j++){
            if(compale(dice[i], dice[j])){
                c = true;
                break;
            }
        }
        if(c) break;
    }
    if(c) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 1160
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  int n,k[5000],max;
  while(1){
  cin >> n;
  if(n==0)break;
  for(int i=0;i<n;i++){
    cin >> k[i];
  }
  max=k[0];
  int sum=0;
  for(int i=0;i<n;i++,sum=0){
    for(int j=i;j<n;j++){
      sum += k[j];
      if(sum>max){
	max=sum;
      }
    }
  }   
  cout << max << endl;
  }
}

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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

#define ALL(obj)	(obj).begin(),(obj).end()

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;
typedef vector<int>				V;
typedef vector<V>				VV;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define LINF		((ll)1 << 63 -1)
#define INF 		(1<<29)
#define MINF		-2000000007
#define MAX 		200050

const int MOD = 1e9+7;
// テンプレ終了
//====================================================================//

int DP[MAX];

//
int main(){
	int N;
	cin >> N;
	V a(N);
	REP(i,N)cin>>a[i];

	V ans;
	for(int i=N;i>0;--i){
		for(int j = i+i;j<=N;j+=i)
			DP[i] ^= DP[j];
		DP[i] ^= a[i-1];
		if(DP[i])ans.push_back(i);
	}

	cout << ans.size() << endl;
	if(ans.size()==0)return 0;
	REP(i,ans.size())cout << ans[ans.size()-i-1] << " ";
	cout << endl;

	return 0;
}




Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
  ll n,m,x;
  cin >> n >> m >> x;
  ll ans=INF;
  vl c(n);
  vvl a(n,vl(m));
  rep(i,n){
    cin >> c[i];
    rep(j,m){
      cin >> a[i][j];
    }
  }
  vl ex(m);
  rep(i,1<<(n)){
    ll cost=0;
    bool b=true;
    rep(i,m){
      ex[i]=0;
    }
    rep(j,n){
      if((i>>j)%2==1){
        cost+=c[j];
        rep(l,m){
          ex[l]+=a[j][l];
        }
      }
    }
    rep(j,m){
      if(ex[j]<x){
        b=false;
      }
    }
    if(b){
      ans=min(ans,cost);
    }
  }
  if(ans==INF){
    cout << -1 << endl;
  }
  else{
    cout << ans << endl;
  }
}

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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;


signed main() {
    int N, A, B;
    cin >> N >> A >> B;
    int blue = 0;
    int sum = A + B;
    blue = N / sum * A;
    blue += min(A, N % sum);
    cout << blue << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
#include <math.h>
#include <set>
#include <string>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
//typedef pair<ll, P> T;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define revrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define f first
#define s second
#define pb push_back

ll mod = 1000000007;
const ll INF = 100000000000010000;
//const ull B = 998244353;

ll bit[200010];
//ll kai[3010];

//void pres(double A, ll x = 20) { printf("%.20f\n", x); }

ll sum(ll i)
{
	i += 1;
	ll t = 0;
	while (i > 0)
	{
		t += bit[i];
		i -= i & -i;
	}
	return t;
}

void add(ll i, ll x)
{
	i += 1;
	while (i <= 200005)
	{
		bit[i] += x;
		i += i & -i;
	}
}

/*`ll SAIKI(ll S) {
	for (ll T = S; ; T = (T - 1) & S) {

	}
}*/

void test() {
	cout << "888888888888888888888888" << endl;
}

ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}

ll pow_mod(ll x, ll y) {
	if (y == 0) return 1;
	if (y % 2 == 1) {
		return x * pow_mod(x, y - 1) % mod;
	}
	else {
		ll half = pow_mod(x, y / 2);
		return half * half % mod;
	}
}

ll div_mod(ll x) {
	return pow_mod(x, mod - 2);
}

/*ll com(ll x, ll y) {
	return kai[x] * div_mod(kai[y] * kai[x - y] % mod) % mod;
	//毎回オーダーlog(n)かかる
}

void kaijo() {
	kai[0] = 1;
	for (ll i = 1; i <= 3004; i++) {
		kai[i] = kai[i - 1] * i % mod;
	}
}*/

ll N;
map<P, ll> mp;
ll ans;

void solve() {
	cin >> N;
	rep(i, N) {
		ll num = i + 1;
		ll a = num % 10;
		while (num >= 10) num /= 10;
		ll b = num;
		mp[P(a, b)]++;
	}
	rep(i, 9) {
		rep(j, 9) {
			ll a = i + 1, b = j + 1;
			ans += mp[P(a, b)] * mp[P(b, a)];
		}
	}
	cout << ans << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	ll N;
	cin >> N;
}

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

bool isprime(int n) {
	if (n==2 || n==3) return true;
	if (!(n%2)) return false;
	if (!(n%3)) return false;
	int lim = (int)sqrt((double)n) + 1;
	for (int i = 6; i <= lim; i += 6) {
		if (!(n%(i-1))) return false;
		if (!(n%(i+1))) return false;
	}
	return true;
}

int main() {
	int n;
	while (cin >> n) {
		int k;
		for (k = n-1; !isprime(k); k--);
		cout << k;
		for (k = n+1; !isprime(k); k++);
		cout << " " << k << endl;
	}
	return 0;
}

Measured memory_bytes: 0