akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define y1 zzz
#define fi first
#define se second
#define PII pair<int,int>
#define PII2 pair<int,PII >
#define PII3 pair<PII,int >
#define PII4 pair<PII,PII >
#define all(x) (x).begin(),(x).end()
#define pb push_back
int f[2010],ans[2010],n,x,y;
vector<int> adj[2010];
void solve()
{
    cin>>n>>x>>y;
    adj[x].pb(y);
    adj[y].pb(x);
    for(int i=1;i<n;i++)
    {
        adj[i].pb(i+1);
        adj[i+1].pb(i);
    }
    for(int i=1;i<=n;i++)
    {
        queue<int> q;
        f[i]=1;
        q.push(i);
        while(q.size())
        {
            int u=q.front();
            q.pop();
            for(int v:adj[u])
            {
                if(!f[v])
                {
                    f[v]=f[u]+1;
                    q.push(v);
                }
            }
        }
        for(int j=1;j<=n;j++)
        {
            ans[f[j]-1]++;
            f[j]=0;
        }
    }
    for(int i=1;i<n;i++)cout<<ans[i]/2<<'\n';
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("STRWC.inp","r",stdin);
    //freopen("FORMMAU.out","w",stdout);
    //int t;cin>>t;while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for (int64_t i = 0; i < (n); i++)
ll n,m,l=1,a[100010],i;
ll r(){ll x;cin>>x;return x;}
ll f(){
    REP(i,n){
        l=l/__gcd(a[i],l)*a[i];
        if(l>m)return 0;
    }
    REP(i,n)if(!(l/a[i]%2))return 0;
    return m/l+1>>1;
}
int main(){
    cin.tie(0);
	ios::sync_with_stdio(false);
    cin>>n>>m;
    REP(i,n)a[i]=r()/2;
    cout<<f()<<endl;
 	return 0;
}

Measured memory_bytes: 1024
# https://atcoder.jp/contests/abc087/tasks/abc087_b
# Ruby 1st try
a = gets.chomp.to_i
b = gets.chomp.to_i
c = gets.chomp.to_i
x = gets.chomp.to_i
fivehundredmax = a
onehundredmax = b
fiftymax = c
total = x
answer = 0
for j in 0..fivehundredmax do
    for k in 0..onehundredmax do
        for m in 0..fiftymax do
            sum = j*500+k*100+50*m
            if sum == total
                answer = answer + 1
            end
        end
    end
end
puts(answer)

Measured memory_bytes: 1788
;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (ql:quickload '(:cl-debug-print :fiveam))
  #-swank (set-dispatch-macro-character #\# #\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)
#-swank (disable-debugger) ; for CS Academy

;; BEGIN_INSERTED_CONTENTS
(declaim (ftype (function * (values fixnum &optional)) read-fixnum))
(defun read-fixnum (&optional (in *standard-input*))
  (macrolet ((%read-byte ()
               `(the (unsigned-byte 8)
                     #+swank (char-code (read-char in nil #\Nul))
                     #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\Nul) nil))))
    (let* ((minus nil)
           (result (loop (let ((byte (%read-byte)))
                           (cond ((<= 48 byte 57)
                                  (return (- byte 48)))
                                 ((zerop byte) ; #\Nul
                                  (error "Read EOF or #\Nul."))
                                 ((= byte #.(char-code #\-))
                                  (setf minus t)))))))
      (declare ((integer 0 #.most-positive-fixnum) result))
      (loop
        (let* ((byte (%read-byte)))
          (if (<= 48 byte 57)
              (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))
              (return (if minus (- result) result))))))))

(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 1000000007)

;; Body

(defun main ()
  (let* ((n (read))
         (as (make-array 100001 :element-type 'uint32)))
    (declare (uint32 n))
    (dotimes (_ n)
      (incf (aref as (read-fixnum))))
    (println
     (if (oddp (loop for a across as
                     sum (if (zerop a) 0 (- a 1)) of-type uint32))
         (- (count-if #'plusp as) 1)
         (count-if #'plusp as)))))

#-swank (main)


Measured memory_bytes: 22372
import java.util.Scanner;


public class Main{
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNextInt()) {
			int n = sc.nextInt();
			if(n == 0) break;
			System.out.println(ten(n));
		}
		sc.close();
	}
	
	
	static int dev(int n, int dev) {
		int result = 0;
		int m = n;
		while(m % dev == 0) {
			result++;
			m = m / dev;
		}
		return result;
	}
	
	static int ten(int n) {
		int two = 0;
		int five = 0;
		for(int i = 1; i <= n; i++) {
			two += dev(i, 2);
			five += dev(i, 5);
		}
		return two < five? two: five;
	}
	
}

Measured memory_bytes: 18908
s = input()
n = len(s)

def dfs(i, f):
    if i == n -1:
        return sum(list(map(int, f.split("+"))))
    
    return dfs(i+1, f + s[i+1]) + dfs(i+1, f + "+" + s[i+1])

print(dfs(0, s[0]))


Measured memory_bytes: 3060
import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int W = sc.nextInt();
		int[] w = new int[N];
		long[] v = new long[N];
		long[][] dp = new long[N + 1][W + 1];
		for(int i = 0;i < N;i++){
			w[i] = sc.nextInt();
			v[i] = sc.nextLong();
		}
		Arrays.fill(dp[0],0);
		for(int i = 0;i < N;i++){
			for(int j = 0;j < W + 1;j++){
				if(j >= w[i]){
					dp[i + 1][j] = Math.max(dp[i][j - w[i]] + v[i],dp[i][j]);
				}else{
					dp[i + 1][j] = dp[i][j];
				}
			}
		}
		System.out.println(dp[N][W]);
	}
}

Measured memory_bytes: 127572
#include <iostream>
#include <vector>
#include <map>
using namespace std;




int main(){

  while(1){

    int x,y,z;
    cin >> x >> y >> z;
    if(x == 0 && y == 0 && z == 0) break;

    //init
    vector<int> mapp(y+1,0);
    vector<int> val(y+1,0);
    vector<int> v(x);
    for(int i=0;i<x;i++) cin >> v[i];
    
    vector<int> n(z),e(z),a(z);
    for(int i=0;i<z;i++){
      cin >> n[i] >> e[i] >> a[i];
      mapp[n[i]] = e[i];
      if(e[i] == 3) a[i] *= -1;
      val[n[i]] = a[i];
    }
    double p = 1.0 / (double)x;

    long double dp[52][5200]={};
    dp[0][0] = 1.0;

    for(int i=0; i<y; i++){
      for(int j=0; j<y*100; j++){
	for(int k=0; k<x; k++){
	  
	  int ni = i+v[k], nj = j;
	  if(ni >= y) ni = y;

	  if(mapp[ni] == 1) ni += val[ni];
	  else if(mapp[ni] == 2 || mapp[ni] == 3) nj += val[ni];

	  if(nj <= 0) nj = 0;
	  if(ni >= y) ni = y;
	  dp[ni][nj] += dp[i][j]*p;

	}
      }
    }
    long double ans = 0.0;
    for(int i=0; i<y*100+1; i++){
      ans += dp[y][i]*i;
    }
    cout << (int)ans << endl;
  }
}

Measured memory_bytes: 5428
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} cout << a[a.size()-1] << endl;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

arr<int> G;
vector<bool> seen;
bool flag;
int v, e;

void dfs(int s, int k, int n){
    // pr(s);
    if(n > 0 && s==k){
        flag = true;
        return;
    }
    if(seen[s]) return;
    seen[s] = true;
    for(int j: G[s]){
        dfs(j, k, n+1);
    }
}

int main()
{
    cin >> v >> e;
    G.resize(v);
    int s, t;
    rep(i, e){
        cin >> s >> t;
        G[s].push_back(t);
    }

    rep(i, v){
        flag = false;
        seen.assign(v, false);
        dfs(i, i, 0);
        if(flag) break;
    }

    pr(flag);
    return 0;}


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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const ll MOD=1e9+7;


int main(){
    int N; cin >> N;
    vector<ll> A(N);
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    ll M, cur;
    vector<pii> res;
    sort(all(A));
    if(A[0] >= 0){
        cur=A[0];
        for(int i=1; i<N-1; i++){
            res.push_back({cur, A[i]});
            cur=cur-A[i];
        }
        res.push_back({A[N-1], cur});
        M=A[N-1]-cur;
    }
    else if(A[N-1] < 0){
        cur=A[N-1];
        for(int i=0; i<N-1; i++){
            res.push_back({cur, A[i]});
            cur=cur-A[i];
        }
        M=cur;
    }
    else{
        cur=A[0];
        int id=N-1;
        while(A[id-1] > 0){
            res.push_back({cur, A[id]});
            cur=cur-A[id];
            id--;
        }
        int id2=1;
        res.push_back({A[id], cur});
        cur=A[id]-cur;
        while(id2 != id){
            res.push_back({cur, A[id2]});
            cur=cur-A[id2];
            id2++;
        }
        M=cur;
    }
    
    cout << M << endl;
    for(int i=0; i<N-1; i++){
        cout << res[i].first << " " << res[i].second << endl;
    }
    return 0;
}

Measured memory_bytes: 5088
import java.util.*;
//import java.io.*;
import java.util.stream.IntStream;

public class Main{
    static int minR = Integer.MAX_VALUE;
    static int maxL = 0;
    public static void main (String args[]){
        //初期処理
        Scanner sc=new Scanner(System.in);
        // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        // try{
            // int n = Integer.parseInt(br.readLine());
        int h = sc.nextInt();
        int w = sc.nextInt();
        sc.nextLine();

        char[][] arr = new char[h][w];
        int[][] L = new int[h][w];
        int[][] R = new int[h][w];
        int[][] U = new int[h][w];
        int[][] D = new int[h][w];

        IntStream.range(0,h).forEach(i->{
            String line = sc.nextLine();
            for(int j=0;j<w;j++){
                arr[i][j]=line.charAt(j);
            }
        });

        //L
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(arr[i][j]=='#'){
                    L[i][j]=0;
                }else{
                    if(j==0){
                        L[i][j]=1;
                    }else{
                        L[i][j]=L[i][j-1]+1;
                    }
                }

            }
        }

        //R
        for(int i=0;i<h;i++){
            for(int j=w-1;j>=0;j--){
                if(arr[i][j]=='#'){
                    R[i][j]=0;
                }else{
                    if(j==w-1){
                        R[i][j]=1;
                    }else{
                        R[i][j]=R[i][j+1]+1;
                    }
                }

            }
        }

                //U
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(arr[i][j]=='#'){
                    R[i][j]=0;
                }else{
                    if(i==0){
                        U[i][j]=1;
                    }else{
                        U[i][j]=U[i-1][j]+1;
                    }
                }

            }
        }

                //D
                for(int i=h-1;i>=0;i--){
                    for(int j=0;j<w;j++){
                        if(arr[i][j]=='#'){
                            D[i][j]=0;
                        }else{
                            if(i==h-1){
                                D[i][j]=1;
                            }else{
                                D[i][j]=D[i+1][j]+1;
                            }
                        }
        
                    }
                }

        
        
        int ans=0;

        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                    int candidate = L[i][j]+R[i][j]+U[i][j]+D[i][j]-3;
                ans = Math.max(ans,candidate);
            }
        }

        System.out.println(ans);

    }
}

Measured memory_bytes: 145232
#include<stdio.h>
//abc120-A
/*
int main(void)
{
	int a, b, c,d;
	scanf("%d %d %d", &a, &b, &c);

	if (b >= a * c)
	{
		printf("%d", c);
	}

	else
	{
		d = b / a;
		printf("%d", d);
	}
	return 0;
}
//abc120-B
int main(void)
{
	int a, b, k, tmp;
	int ans = 0, i, j;

	scanf("%d %d %d", &a, &b, &k);

	if (a < b)
	{
		tmp = a;
		a = b;
		b = tmp;
	}

	for (i = b; i > 0; i--)
	{
		if ((a % i + b % i) == 0)
		{
			ans += 1;
		}
		if (ans == k)
		{
			break;
		}

	}
	printf("%d", i);
	return 0;
}*/
//abc119-A
int main(void)
{
	int a, b, c;
	scanf("%d/%d/%d", &a, &b, &c);
	if (b < 5)
	{
		printf("Heisei");
	}
	else
	{
		printf("TBD");
	}

	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vlll = vector<vll>; using vpll = vector<pll>;
using vs = vector<string>; using tll = tuple<ll, ll, ll>; using vtll = vector<tll>;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define co(i) cout << i << endl;
#define co2(i,j) cout << i << " " << j << endl;
#define co3(i) cout << i << " ";
#define po(i) cout << i.first << " " << i.second << endl;
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.second < secondElof.second;
}
//AtCoder以外ではコメントアウトを忘れずに！
#include <atcoder/all>
using namespace atcoder;
//**Snippetリスト**//
//rep, vin, all, iteLoop, bitSearch, bitList, nod, LIS, digitDP, treeDP, Rerooting//
//gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv, doubling//
//dfs, bfs, dijkstra, WarshallFloyd, BellmanFord, UnionFind, Kruskal, RMQ, LCA, FordFulkerson//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q, T;
ll MOD = 1000000007, INF = 1LL << 60, ans = 0, z = 0, o = 1;
vll flag, D; vector<vpll> path; vs S;
int main() {
	string S;
	cin >> S;
	vector<int> SA = suffix_array(S);
	ans = S.size() * (S.size() + 1) / 2;
	for (auto x : lcp_array(S, SA)) ans -= x;
	co(ans);
}

Measured memory_bytes: 15680
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(void){
  int N;
  cin >> N;
  vector<int> L(2*N);
  REP(i, 2*N) cin >> L[i];

  sort(ALL(L));
  int ans = 0;
  REP(i, N){
    ans += L[2*i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n'
#define fo(i,n)        for(int i=0; i<n; i++)
#define foa(i,k,n)     for(int i=k; i<=n; i++)
#define fod(i,k,n)     for(int i=n; i>=k; i--)
#define clr(arr)       memset(arr, 0, sizeof arr)
#define hi(x)          cout<<" -> "<<#x<<" : "<<x<<endl;
using namespace std;
const int mod = 1e9 + 7;


void solve()
{
// #define T
	int n; cin>>n;
	cout<<n+n*n+n*n*n<<endl;
}

int32_t main()
{
///////////////////////////////////////////////////////
#ifdef FIN
	freopen("in.txt", "r", stdin);
#endif
	ios_base::sync_with_stdio(false); cin.tie(nullptr);
///////////////////////////////////////////////////////

	int t = 1;
#ifdef T
	cin >> t;
#endif
	while (t--)
		solve();
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
#define INF (1e18)

ll dp[1000010][4] = {};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, Q;
    string S;
    ll k[110];
    cin >> N >> S >> Q;
    rep(i,0,Q) cin >> k[i];
    ll cnt_M[1000010] = {};
    rep(i,0,N){
        if(S[i] == 'D'){
            dp[i+1][0] += dp[i][0] + 1;
            dp[i+1][1] += dp[i][1];
            dp[i+1][2] += dp[i][2];
        }else if(S[i] == 'M'){
            cnt_M[i+1] = 1;
            dp[i+1][1] += dp[i][0] + dp[i][1];
            dp[i+1][0] = dp[i][0];
            dp[i+1][2] = dp[i][2];
        }else if(S[i] == 'C'){ 
            dp[i+1][2] += dp[i][1];
            dp[i+1][0] = dp[i][0];
            dp[i+1][1] = dp[i][1];
        }else{
            dp[i+1][2] = dp[i][2];
            dp[i+1][0] = dp[i][0];
            dp[i+1][1] = dp[i][1];

        }
    }
    rep(i,0,N+1) cnt_M[i+1] += cnt_M[i];
    rep(q,0,Q){
        ll ans = 0;
        rep(i,0,N){
            if(S[i] == 'C'){
                if(i < k[q]){
                    ans += dp[i+1][1];
                }else{
                    ans += dp[i+1][1] - dp[i+1-k[q]][1] - dp[i+1-k[q]][0] * (cnt_M[i+1] - cnt_M[i+1-k[q]]);
                }
            }
        }
        print(ans);
    }
}

Measured memory_bytes: 40476
/*
Author: Racer5x
 ***************************************   UNAUTHORISED COPYING OF CODE PROHIBITED   **********************************
*/
 
// #pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include<bits/stdc++.h>
#define int         long long
#define double      long double
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define hell        998244353 
#define PI          3.141592653589
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MAX         2000000000000000000
#define M           1000000007
using namespace std;
 
signed main()
{
    tezz
    
    int a, b;
    cin>>a>>b;

    if((a+b) % 2 == 0){
        cout<<(a+b)/2;
    }
    else cout<<"IMPOSSIBLE";
} 

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

void chmax(int& a, int b){
  if(a < b){
    a = b;
  }
}

int main(){
  int N;
  cin >> N;
  vector<vector<int>> a(N + 10, vector<int>(3));
  for(int i = 0; i < N; i++){
    cin >> a.at(i).at(0) >> a.at(i).at(1) >> a.at(i).at(2);
  }
  vector<vector<int>> dp(N + 10, vector<int>(3, 0));
  for(int i = 0; i < 3; i++){
    dp.at(0).at(i) = a.at(0).at(i);
  }
  for(int i = 0; i < N; i++){
    for(int j = 0; j < 3; j++){
      for(int k = 0; k < 3; k++){
        if(j == k){
          continue;
        }
        chmax(dp.at(i + 1).at(j), dp.at(i).at(k) + a.at(i + 1).at(j));
      }
    }
  }
  int maximum = 0;
  for(int i = 0; i < 3; i++){
    chmax(maximum, dp.at(N - 1).at(i));
  }
  cout << maximum << endl;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    rep(i, N) cin >> A[i] >> B[i];
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    if (N&1) {
        int left, right;
        left = A[N/2]; right = B[N/2];
        int ans = right - left + 1;
        cout << ans << '\n';        
    } else {
        double left, right;
        left = (double)(A[N/2] + A[N/2 - 1]) / 2;
        right = (double)(B[N/2] + B[N/2 - 1]) / 2;
        int ans = (right - left) / 0.5 + 1;
        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 4744
#pragma region noncode
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#pragma endregion

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    ll ans = 0;
    rep(i, n) {
        while(a[i] % 2 == 0) {
            ans++;
            a[i] /= 2;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<55)+1e9; // ~ 3.6 * 1e16
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
using T = tuple<Int,Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> &a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
template<class T>void prArr(T a,string s=" "){Int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}

struct dat{
  int idx,to, pre;
  
  dat(int idx=-1, int to=-1,int pre = -1):idx(idx),to(to), pre(pre){}
};

void print(int head, int tail, vector<dat> A,vector<int> num){
  vector<int>ans;
  for(int i = head; ; i = A[i].to){
    //pr(i, A[i].pre, A[i].to, A[i].idx, head,tail);
    ans.push_back(num[A[i].idx]);
    if(i == tail) break;;
  }
  cout<<ans<<endl;
  
}

signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n, Q;
  cin >>n>> Q;
  vector<dat> A(n);
  for(int i=0;i<n;i++){
    A[i].idx = i;
    A[i].to = (i+1)%n;
    A[i].pre = (i-1 + n) % n;
  }
  int head = 0, tail = n-1;
  
  vector<int> num(n);
  vector<int> Idx(n);
  cin>>num;
  for(int i=0;i<n;i++) Idx[num[i]-1] = i;

  auto query=[&](int x){

    if(x == tail){
      int nhead = x;
      int ntail = A[x].pre;
      A[x].to = head;
      A[head].pre = x;
      head = nhead;
      tail = ntail;
      return;
    };

    if(x == head){
      int nhead = A[x].to;
      int ntail = x;
      A[tail].to = x;
      A[x].pre = tail;
      head = nhead;
      tail = ntail;
      return;
    }

    int nhead = A[x].to;
    int ntail = A[x].pre;
    A[x].to = head;
    A[head].pre = x;

    A[tail].to = x;
    A[x].pre = tail;
    head = nhead;
    tail = ntail;
  };

  
  while(Q--){
    int q;
    cin>>q;
    query(Idx[q-1]);
    // print(head, tail, A,num);
  }

  print(head, tail, A, num);
  
  
  return 0;
}



Measured memory_bytes: 6892
object Main {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn.readLine
    val Array(datA, datB, datC) = readLine.split(" ").map(_.toInt)
    val ans = (datA to (datA * datB) by datA).exists(a => (a % datB) == datC)
    println(if(ans) "YES" else "NO")
  }
}


Measured memory_bytes: 27288
def main():
    w = int(input())
    n = int(input())
    ans =[i for i in range(1, w+1)]

    def change(li, a, b):
        tmp = li[a-1]
        li[a-1] = li[b-1]
        li[b-1] = tmp
        return li

    for _ in range(n):
        a, b = map(int, input().split(","))
        ans = change(ans, a, b)
    print(*ans, sep="\n")


if __name__ == "__main__":
    main()

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

#define ALL(a) (a).begin(), (a).end()
#define ll long long

using namespace std;

signed main(){
    int n,m; cin >> n >> m;
    vector<pair<int, int> > a(m);
    for(int i = 0; i < m; i++){
        cin >> a[i].first >> a[i].second;
        a[i].first--;
        a[i].second--;
    }
    sort(ALL(a));
    int ans = 0;
    int right = n-1;
    for(int i = n-2; i >= 0; i--){
        auto lb = lower_bound(ALL(a), make_pair(i,i));
        if(lb != a.end() && lb->first == i && lb->second <= right){
            ans++;
            right = i;
        }
    }
    cout << ans << endl;

        



    return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    string s;
    cin >> s;
    vector<int> num(3, 0);
    int n = s.length();
    rep(i, n) {
        ++num[s[i]-'a'];
    }
    bool ok = true;
    int check_num = n / 3;
    rep(i, 3) {
        if ( num[i] != check_num && num[i] != check_num + 1) {
            ok = false;
        }
    }
    if ( ok ) cout << "YES" << endl;
    else      cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <numeric>




typedef long long ll;
#define PI 3.14159265359
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define mp make_pair
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBAC
#include <functional>
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

ll gcd(ll a, ll b) {
	ll c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

ll lcm(ll a, ll b) {
	ll c;
	c = a * b / gcd(a, b);
	return c;
}

int sort_greater(int m, int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(), greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
	return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t, sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

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

const ll mod = 1000000007;


map<string, int> memo;

using P=pair<int, int>;




/*void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}*/
ll findIndex(int value, vector<ll> a)
{

	for (ll i = 0; i < a.size(); i++) {
		if (a[i] == value) {
			return i;
		}
	}
	return -1;
}
ll nCr(ll n, ll r) {
	ll a = 1;
	for (ll i = n; i > n - r; --i) {
		a = a * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		a = a / i;
	}
	return a;
}

void comb(vector<vector <long long int> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (ll j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}


int main() {
	int n, m,X,Y;
	cin >> n >> m>>X>>Y;
	vector<int> x(n), y(m);
	rep(i, n)cin >> x[i];
	rep(i, m)cin >> y[i];
	sort(rall(x)); sort(all(y));
	x[0]++;
	if (x[0] <= y[0]&&X<x[0]&&x[0]<=Y)cout << "No War";
	else cout << "War";
	return 0;
}













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

const int N = 2e5 + 5;

struct Line {
  long long m;
  long long c;

  Line(long long _m, long long _c) {
    m = _m;
    c = _c;
  }

  long long eval(long long x) {
    return m * x + c;
  }

  void print() {
    cout << m << " " << c << endl;
  }
};

long long c;
int n;

int arr[N];
long long dp[N];
vector<Line> hull;
int hullIt;

void read() {
  scanf("%d %lld", &n, &c);
  for (int i = 1 ; i <= n ; i++) {
    scanf("%d", &arr[i]);
  }
}

bool bad(Line p, Line q, Line r) {
  return (long double)(r.c - p.c) / (p.m - r.m) < (long double)(q.c - p.c) / (p.m - q.m);
}

void add(Line l) {
  while (hull.size() >= 2 && bad(hull[hull.size()-2], hull.back(), l)) {
    // puts("POP");
    // hull.back().print();
    hull.pop_back();
  }

  hull.push_back(l);
}

long long extract(long long x) {
  if (hullIt >= hull.size()) hullIt = hull.size()-1;
  while (hullIt+1 < hull.size() && hull[hullIt].eval(x) >= hull[hullIt+1].eval(x)) {
    hullIt++;
  }

  // hull[hullIt].print();
  return hull[hullIt].eval(x);
}

void work2() {
  for (int i = 2 ; i <= n ; i++) {
    int best = -1;
    long long val = 4e18;

    for (int j = 1 ; j < i ; j++) {
      long long cur = 1ll * (arr[i] - arr[j]) * (arr[i] - arr[j]) + dp[j] + c;
      if (cur < val) {
        val = cur;
        best = j;
      }
    }

    dp[i] = val;
    printf("%d: best %d dp %lld\n", i, best, dp[i]);
  }
}

long long work() {
  dp[1] = 0;

  add(Line(-2 * arr[1], dp[1] + 1ll * arr[1] * arr[1] + c));

  for (int i = 2 ; i <= n ; i++) {
    dp[i] = extract(arr[i]) + 1ll * arr[i] * arr[i];
    // printf("i %d dp %lld\n", i, dp[i]);
    add(Line(-2 * arr[i], dp[i] + 1ll * arr[i] * arr[i] + c));
  }

  return dp[n];
}

int main() {
  read();
  // work2();
  cout << work() << endl;
  return 0;
}

Measured memory_bytes: 8432
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    int n;
    cin >> n;
    vector<int> H(n);
    rep(i, n) cin >> H[i];
    bool ans = true;
    for(int i = n - 1; i > 0; i--) {
        if(H[i] - H[i - 1] >= 0) continue;
        else if(H[i]- H[i - 1] == -1) {
            H[i - 1]--;
            if(H[i - 1] < 1) {
                ans = false;
                break;
            }
        } else {
            ans = false;
            break;
        }
    }

    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

const int mod = 1000000007;
int dp[100005][2];

int main() {
  string s;
  cin >> s;
  int n = s.size();
  dp[0][0] = 1;
  // dp[0][1] = 0;
  rep(i,n) {
    dp[i+1][0] = dp[i+1][0] = 0;
    { // a+b = 0
      if (s[i] == '0') {
        dp[i+1][0] += dp[i][0];
        dp[i+1][1] += dp[i][1];
      } else {
        dp[i+1][1] += (dp[i][0] + dp[i][1]) % mod;
      }
    }
    { // a+b = 1
      if (s[i] == '0') {
        (dp[i+1][1] += dp[i][1]*2 % mod) %= mod;
      } else {
        (dp[i+1][0] += dp[i][0]*2 % mod) %= mod;
        (dp[i+1][1] += dp[i][1]*2 % mod) %= mod;
      }
    }
  }
  int ans = (dp[n][0]+dp[n][1]) % mod;
  cout << ans << endl;
  // rep(i,n)cout<<dp[i+1][0];
  // cout << endl;
  // rep(i,n)cout << dp[i+1][1];
  // cout << endl;
  // cout << dp[0][1] << endl;
  return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#include <string>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    if(a + b == 15){
        cout<<"+"<<endl;
    }
    else if(a * b == 15){
        cout<<"*"<<endl;
    }
    else{
        cout<<"x"<<endl;
    }
}

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

int p[200010],Q[200010],v[200010],Cx,Cy,Hx,Hy,n,ma;
bool bo;

struct node
{
	int ls[4000010],rs[4000010],val[4000010],rt[200010],tot;
	void add(int i,int I,int l,int r,int x,int v)
	{
		val[i]=max(val[I],v);
		if (l==r) return;
		int mid=(l+r)>>1;
		if (x<=mid) rs[i]=rs[I],add(ls[i]=(++tot),ls[I],l,mid,x,v);
		else ls[i]=ls[I],add(rs[i]=(++tot),rs[I],mid+1,r,x,v);
	}
	int query(int i,int l,int r,int ql,int qr)
	{
		if (ql>qr) return val[0];
		if (l==ql&&r==qr) return val[i]==0?val[0]:val[i];
		int mid=(l+r)>>1;
		if (qr<=mid) return ls[i]?query(ls[i],l,mid,ql,qr):val[0];
		if (ql>mid) return rs[i]?query(rs[i],mid+1,r,ql,qr):val[0];
		return max(ls[i]?query(ls[i],l,mid,ql,mid):val[0],rs[i]?query(rs[i],mid+1,r,mid+1,qr):val[0]);
	}
}t[2];

int main()
{
	scanf("%d",&n),ma=0;
	for (int i=1; i<=n; i++) 
	{
		scanf("%d",&p[i]);
		if (p[i]>ma) v[i]=2,ma=p[i]; else v[i]=1;
	}
	Q[n+1]=0;
	for (int i=n; i; i--) Q[i]=Q[i+1]+v[i]-1;
	t[0].rt[n+1]=t[1].rt[n+1]=t[0].tot=t[1].tot=1,t[1].val[0]=-2*n-1;
	for (int i=n; i; i--)
		if (v[i]==2)
		{
			t[0].add(t[0].rt[i]=(++t[0].tot),t[0].rt[i+1],1,n,p[i],2+t[0].query(t[0].rt[i+1],1,n,p[i]+1,n));
			t[1].add(t[1].rt[i]=(++t[1].tot),t[1].rt[i+1],1,n,p[i],2+t[1].query(t[1].rt[i+1],1,n,p[i]+1,n));
		} else
		{
			t[0].add(t[0].rt[i]=(++t[0].tot),t[0].rt[i+1],1,n,p[i],1+t[1].query(t[1].rt[i+1],1,n,p[i]+1,n));
			t[1].add(t[1].rt[i]=(++t[1].tot),t[1].rt[i+1],1,n,p[i],1+t[0].query(t[0].rt[i+1],1,n,p[i]+1,n));
		}
	Cx=Cy=Hx=Hy=0,bo=0;
	int nw=Cy-Cx+Q[1];
	if (nw>=0&&t[nw&1].query(t[nw&1].rt[1],1,n,Hx+1,n)>=nw) bo=1;
	nw=Cx-Cy+Q[1];
	if (nw>=0&&t[nw&1].query(t[nw&1].rt[1],1,n,Hy+1,n)>=nw) bo=1;
	if (!bo) return puts("-1"),0;
	for (int i=1; i<=n; i++)
	{
		int cx=Cx+(p[i]>Hx),hx=max(Hx,p[i]),cy=Cy,hy=Hy,nw;
		nw=cy-cx+Q[i+1];
		if (nw>=0&&t[nw&1].query(t[nw&1].rt[i+1],1,n,hx+1,n)>=nw) 
		{
			putchar('0'),Hx=hx,Hy=hy,Cx=cx,Cy=cy;
			continue;
		}
		nw=cx-cy+Q[i+1];
		if (nw>=0&&t[nw&1].query(t[nw&1].rt[i+1],1,n,hy+1,n)>=nw) 
		{
			putchar('0'),Hx=hx,Hy=hy,Cx=cx,Cy=cy;
			continue;
		}
		Cy+=(p[i]>Hy),Hy=max(Hy,p[i]),putchar('1');
	}
	return puts(""),0;
}

Measured memory_bytes: 98176
function main(input) {
  input = input.trim();
  const a = input.split(" ").map(Number);
  let sum = 0;
  for(let i=0;i<a;++i){
     sum += (i+1);
  }
  console.log(sum);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 30580
n = int(input())
l = [int(i) for i in input().split()]

m = []
flag = 0
while flag ==0:
    l.sort()
    p = len(l)
    for i in range(1,p):
        a = l[i]%l[0]
        if a != 0:
            l[i] = a
        else:
            l[i] = l[0]

    kkk = set(l)
    if len(kkk) <= 1 or min(l) == 1:
        flag = 1

if len(l) == 0:
    print(l[0])
else:
    l.sort()
    print(l[0])


Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using in6 = int64_t;
using ind = double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <map>
using namespace std;
inline int read()
{
	int f = 1, x = 0;
	char ch;

	do{
		ch = getchar();
		if (ch == '-')
			f = -1;
	}while(ch < '0' || ch > '9');
	do{
		x = x * 10 + ch - '0';
		ch = getchar();
	}while(ch >= '0' && ch <= '9');
	return f * x;
}
const int N = 1e5;

int n, x, cnt;
map<int, int> p;
int a[N + 1], b[N + 1];
struct Edge {
	int to, next;
} edge[(N << 1) + 1];
int start[N + 1], tot;
int vis[N + 1];
int ans;

inline void addedge(int u, int v)
{
	edge[++tot] = Edge{ v, start[u] };
	start[u] = tot;
	edge[++tot] = Edge{ u, start[v] };
	start[v] = tot;
	ans++;
	return;
}
inline void dfs(int u)
{
	vis[u] = 1;
	for (int i = start[u]; i; i = edge[i].next) {
		int v = edge[i].to;
		if (!vis[v])
			dfs(v);
	}
	return;
}
int main()
{
	n = read();
	for (int i = 1; i <= n; i++) {
		a[i] = read();
		p[a[i]]++;
		x ^= a[i];
	}
	p[x]++;
	for (int i = 1; i <= n; i++) {
		b[i] = read();
		p[b[i]]--;
	}
	for (map<int, int>::iterator it = p.begin(); it != p.end(); it++) {
		if ((*it).second < 0) {
			printf("-1\n");
			return 0;
		}
		(*it).second = ++cnt;
	}
	for (int i = 1; i <= n; i++)
		if (a[i] != b[i])
			addedge(p[a[i]], p[b[i]]);

	for (int i = 1; i <= cnt; i++) {
		if (start[i] && !vis[i]) {
			ans++;
			dfs(i);
		}
	}

	if (start[p[x]])
		ans--;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 14480
//Author: AnandRaj doubleux
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll; 

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test() int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define prin(V) for(auto v:V) cout<<v<<" ";cout<<endl
#define take(V,f,n) for(int in=f;in<f+n;in++) cin>>V[in]
#define what(x) cerr<<#x<<" = "<<x<<endl
#define KStest() int t,t1;cin>>t;t1=t;while(t--)
#define KScout cout<<"Case #"<<t1-t<<": "

const int MOD = 1e9+7,MAX = 1e6+5;
/////////////////FastExp///////////////////
ll powN(ll a,ll p,ll mod)
{
	if(p==0) return 1;
	ll z=powN(a,p/2,mod);
	z=(z*z)%mod;
	if(p%2) z=(z*a)%mod;
	return z;
}
/////////////////FastExp///////////////////
//////////////////Sieve////////////////////
vector<bool> is_prime(MAX, true);
vector<int> MinDiv(MAX);
void Sieve()
{
	is_prime[0] = is_prime[1] = false;
	int i,j;
	for (i = 2; i*i <= MAX; i++) 
	{
    	if (is_prime[i]) 
    	{
    		MinDiv[i]=i;
        	for (j = i * i; j <= MAX; j += i)
            {
				is_prime[j] = false;
				MinDiv[j]=i;
    		}
    	}
	}
	for(int i=2;i<=MAX;i++) if(is_prime[i]) MinDiv[i]=i;
}
//////////////////Sieve////////////////////

const double pi = 4*atan(1);

int main()
{
	int a,b,h,m;
	cin>>a>>b>>h>>m;
	double degh = h*30+m*0.5;
	double degm = m*6;

	double dis = a*a+b*b-2*a*b*cos(abs(degm-degh)*pi/180);

	cout<<setprecision(10)<<sqrt(dis)<<endl;
}		

Measured memory_bytes: 7036
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
  int a, b;
  cin >> a >> b;
  vector<int>x(b);//aがb個
  vector<int>y(a);//bがa個
  rep(i, b) x.at(i)=a;
  rep(i, a) y.at(i)=b;
  
  if(a>b) {
    rep(i, a) cout << y.at(i);
  }
  else {
    rep(i, b) cout << x.at(i);
  }
  
}

Measured memory_bytes: 256
n = int(input())
hlis = list(map(int, input().split()))
hlis.append(float('inf'))
dp = [0] + [abs(hlis[0] - hlis[1])] + [float('inf')]*(n-1)
for i in range(n-1):
    one = abs(hlis[i]-hlis[i+1])
    two = abs(hlis[i]-hlis[i+2])
    dp[i+1] = min(dp[i]+one, dp[i+1])
    dp[i+2] = min(dp[i]+two, dp[i+2])
print(dp[n-1])

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

int main() {
	int V, E, s, t, d, i;
	cin >> V >> E;
	vector<vector<int>> D(V, vector<int>(V, INT_MAX));
	for (i = 0; i < E; ++i) {
		cin >> s >> t >> d;
		D[s][t] = d;
	}
	for (i = 0; i < V; ++i) D[i][i] = 0;
	for (i = 0; i < V; ++i) {
		for (int j = 0; j < V; ++j) {
			if (D[j][i] != INT_MAX) {
				for (int k = 0; k < V; ++k) {
					if (D[i][k] != INT_MAX) D[j][k] = min(D[i][k] + D[j][i], D[j][k]);
				}
			}
		}
	}
	for (i = 0; i < V; ++i) {
		if (0 > D[i][i]) break;
	}
	if (V == i) {
		for (i = 0; i < V; ++i) {
			if (D[i].front() == INT_MAX) cout << "INF";
			else cout << D[i].front();
			for (int j = 1; j < V; ++j) {
				cout << ' ';
				if (D[i][j] == INT_MAX) cout << "INF";
				else cout << D[i][j];
			}
			cout << endl;
		}
	}
	else cout << "NEGATIVE CYCLE" << endl;
}


Measured memory_bytes: 3208
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn=1e5+5;
struct discount{
	int a,b,cost;
}dis[maxn];
int A,B,M;
int a[maxn],b[maxn];
int res=0,mina=maxn,minb=maxn;
int main(){
	cin>>A>>B>>M;
	for(int i=1;i<=A;i++){
		cin>>a[i];
		if(a[i]<mina)
			mina=a[i];
	}
	for(int i=1;i<=B;i++){
		cin>>b[i];
		if(b[i]<minb)
			minb=b[i];
	}
	for(int i=1;i<=M;i++){
		cin>>dis[i].a>>dis[i].b>>dis[i].cost;
	}
	int tmpres=mina+minb;
	res=tmpres;
	for(int i=1;i<=M;i++){
		tmpres=a[dis[i].a]+b[dis[i].b]-dis[i].cost;
		if(tmpres<res)
			res=tmpres;
	}
	cout<<res<<endl;
	return 0;
	
}


Measured memory_bytes: 2176
x[37];main(a,b,c,d){for(a=0;a<=9;a++)for(b=0;b<=9;b++)for(c=0;c<=9;c++)for(d=0;d<=9;d++)x[a+b+c+d]++;for(;~scanf("%d",&a);printf("%d\n",x[a]));return 0;}

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

using namespace std;

using ll = long long;

const int N = (int)5e3 + 5,
          mod = (int)1e9 + 7;
int n, dp[N][N];
string s;

int add(int _a, int _b) {
    _a += _b;
    if (_a >= mod) _a -= mod;
    return _a;
}

int mul(int _a, int _b) { return (int)( (ll)_a * _b % mod); }

int binPow (int _a, int _m) {
    int ret = 1;
    for (; _m; _m >>= 1, _a = mul(_a, _a) ) if (_m & 1) ret = mul(ret, _a);
    return ret;
}

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

    cin >> n >> s;

    dp[0][0] = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= i; ++j) if (dp[i][j]) {
            dp[i + 1][j + 1] = add(dp[i + 1][j + 1], mul(2, dp[i][j]) );
            dp[i + 1][ max(0, j - 1) ] = add(dp[i + 1][ max(0, j - 1) ], dp[i][j]);
        }
    }

    cout << mul(dp[n][(int)s.size()], binPow(binPow(2, (int)s.size() ), mod - 2) );

    return 0;
}


Measured memory_bytes: 96384
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001



int main() {
    int N; cin >> N;
    vector<int> A(N), B(N), C(N-1);
    for(int &a:A) cin >> a;
    for(int &b:B) cin >> b;
    for(int &c:C) cin >> c;
    
    int ans = 0;
    for(int i=0; i<N; i++){
        A[i]--;
        ans += B[A[i]];
    }
    
    for(int i=0; i<N-1; i++){
        if(A[i]+1==A[i+1]) ans += C[A[i]];
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
diagram = input()

water_all = 0
water = 0
ip = 0
stack1 = []
stack2 = []

for i, symbol in enumerate(diagram):
    if symbol == '\\': # 一つのバックスラッシュはこう書くらしい
        stack1.append(i)
    elif symbol == '/':
        if stack1 != []:
            ip = stack1.pop()
            water = i - ip
            water_all += water
            
            if stack2 != []:
                while stack2[-1][0] > ip:
                    i2, water2 = stack2.pop()
                    water += water2
                    if stack2 == []:
                        break
                stack2.append([ip, water])
            else:
                stack2.append([ip, water])

s = str(len(stack2))
waters = [str(i[1]) for i in stack2]
if len(waters)!=0:
    s += ' ' + ' '.join(waters)

print(water_all)
print(s)


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

#define I inline void 

using namespace std ; 

using ld = long double ; 
using ll = long long ; 

const int N = 1e6  + 7 , mod = 1e9 + 7 ; 

int n , k ; 

ll ans = 1e18 ; 

int main(){
	ios_base::sync_with_stdio(0) ; 
	cin.tie(0) ; 
	//freopen("in.in"  ,"r" , stdin) ; 

	cin >> n >> k ; 
	std::vector<int> v1, v2;
	for(int i = 0 ;i < n;i++){
		int x ; 
		cin >> x; 
		if( x < 0){
			v1.push_back(x) ; 
		}
		else{
			v2.push_back(x) ;
		}
	}
	reverse(v1.begin() , v1.end()) ; 
	if(k <= (int)v2.size()){
		ans = v2[k -1 ] ; 
	}
	for(int i = 0 ;i < (int) v1.size() ;i ++){
		ll dst = abs(v1[i]) ; 
		int req = k - i - 1; 
		if(req > (int) v2.size())continue ; 
		ll dst2 = (req > 0 ? abs(v2[req-1])  : 0 )  ; 
		ans = min(ans , dst + dst2 + min(dst , dst2)) ; 
	}	
	cout<< ans ; 
	return 0 ; 
}

Measured memory_bytes: 3956