akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt(); scan.nextLine();

        if (N < 3) {
            System.out.println("0");
            System.exit(0);
        }

        Integer[] march = {0, 0, 0, 0, 0};
        for (int i=0; i<N; i++) {
            switch (scan.next().substring(0,1)) {
                case "M":
                    march[0] += 1;
                    break;
                case "A":
                    march[1] += 1;
                    break;
                case "R":
                    march[2] += 1;
                    break;
                case "C":
                    march[3] += 1;
                    break;
                case "H":
                    march[4] += 1;
                    break;
            }
        }

        int zero = 0;
        for (int i=0; i<5; i++) {
            if (march[i] == 0) zero++;
        }

        if (zero > 3) {
            System.out.println("0");
            System.exit(0);
        } else {
            // march から 0 を削除して、newmarch を生成
            List<Integer> remove = new ArrayList<>(Arrays.asList(0));
            List<Integer> marchlist = new ArrayList<>(Arrays.asList(march));
            marchlist.removeAll(remove);

            int l = marchlist.size();
            int[] newmarch = new int[l];
            Iterator<Integer> iter = marchlist.iterator();
            for (int i=0;i<l;i++) newmarch[i] = iter.next();
            // ここまで

            long ans = 0, anstemp;
            if (zero == 2) {
                System.out.println(newmarch[0] * newmarch[1] * newmarch[2]);
            } else if (zero == 1) {
                for (int unselect = 0; unselect < 4; unselect++) {
                    anstemp = 1;
                    for (int i=0; i<4; i++) {
                        if (i != unselect) anstemp *= newmarch[i];
                    }
                    ans += anstemp;
                }

                System.out.println(ans);
            } else {
                for (int unselect = 0; unselect < 4; unselect++) {
                    for (int unselect2 = unselect+1; unselect2 < 5; unselect2++) {
                        anstemp = 1;
                        for (int i=0; i<5; i++) {
                            if (i != unselect && i != unselect2) anstemp *= newmarch[i];
                        }

                        ans += anstemp;
                    }
                }

                System.out.println(ans);
            }
        }
    }
}


Measured memory_bytes: 45420
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

vector<int> vt;
int t[101],v[101];
double c_area(double h1,double h2,double w){
    return 0.5*(h1+h2)*w;
}
int main(){
    int n,tt;
    cin>>n;
    cin>>t[0];
    FOR(i,1,n){
        cin>>tt;
        t[i]=tt+t[i-1];
    }
    rep(i,n) cin>>v[i];
    double cv=0.0,ans=0.0,pre=0.0;
    int ct=0;
    v[n]=0;
    for(double i=0.5;i<=t[n-1];i+=0.5){
        cv+=0.5;
        if(i>t[ct]) ++ct;
        rep(j,n){
            if(i<=t[j]) cv=min(cv,v[j+1]+(t[j]-i));
        }
        cv=min(cv,(double)v[ct]);
        ans+=c_area(pre,cv,0.5);
        pre=cv;
    }
    cout<<fixed<<setprecision(10)<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc129/tasks/abc129_c

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF (1e9)
#define MOD (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
// int gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// int lcm(long a, long b) { return a * b / gcd(a, b); }

ll dp[100001];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, m, t;
    ll ans = 0;
    cin >> n >> m;
    set<ll> st;

    for (int i = 0; i < m; i++) {
        cin >> t;
        st.insert(t);
    }
    dp[0] = 1;
    // 貰うDPで計算する。dp[i] : i段目でのパターン数
    for (int i = 1; i <= n; i++) {
        if (st.count(i) == 0) {
            t = 0;
            if (i - 1 >= 0) {
                t += dp[i - 1];
            }
            if (i - 2 >= 0) {
                t += dp[i - 2];
            }
            if (t == 0) {
                cout << "0\n";
                return 0;
            }
            dp[i] = t % MOD;
        }
    }
    cout << dp[n] << endl;

    return 0;
}


Measured memory_bytes: 4992
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define mp make_pair
#define pi pair<int,int>
#define pl pair<long long int,long long int>
#define pb push_back
#define fi first
#define se second
#define len(a) (int)(a).length()
#define sz(a) (int)(a).size()

typedef long long int ll;
typedef long double ld;

using namespace std;

int n, p;
ll a[16][16], b[(1<<16)] = {}, dp[(1<<16)];
vector <int> tmp[(1<<16)];

ll solve (ll x) {
	if (dp[x] != -1) return dp[x];
	int s = sz(tmp[x]);
	for (int i=1; i<(1<<s); ++i) {
		int j = 0;
		ll v = 0;
		while (j < s) {
			if (i & (1 << j)) v += (1LL<<tmp[x][j]);
			++j;
		}
		dp[x] = max(dp[x], b[v] + solve(x - v));
	}
	assert(dp[x] != -1);
	return dp[x];
}

int main ()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	cin >> n;
	for (int i=0; i<n; ++i)
		for (int j=0; j<n; ++j)
			cin >> a[i][j];
	p = (1 << n);
	for (int i=1; i<p; ++i) {
		int j = 0;
		while (j < n) {
			if (i & (1 << j)) tmp[i].pb(j);
			++j;
		}
		for (int j=0; j<sz(tmp[i]); ++j)
			for (int k=j+1; k<sz(tmp[i]); ++k)
				b[i] += a[tmp[i][j]][tmp[i][k]];
	}
	memset(dp, -1, sizeof(dp));
	dp[0] = 0;
	for (int i=1; (1<<i) < n; ++i)
		dp[(1<<i)] = 0;
	cout << solve(p - 1) << '\n';
	return 0;
}


Measured memory_bytes: 8816
package main

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

var sc *bufio.Scanner = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}()

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func calcLcm(l, r int) int {
	return l * r / calcGcd(l, r)
}

func calcGcd(l, r int) int {
	if r > l {
		t := r
		r = l
		l = t
	}
	d := l % r
	for d != 0 {
		l = r
		r = d
		d = l % r
	}
	return r
}
func countMultiple(v, max, min int) int {
	mn := ceil(min, v)
	mx := max / v
	return mx - mn + 1
}

func ceil(num, denom int) int {
	quotient := num / denom
	remainder := num % denom
	if remainder != 0 {
		quotient++
	}
	return quotient
}

func count(min, max, c, d int) int {
	cc := countMultiple(c, max, min)
	dd := countMultiple(d, max, min)
	cd := countMultiple(calcLcm(c, d), max, min)
	return max - min + 1 - cc - dd + cd
}

func main() {
	a, b, c, d := nextInt(), nextInt(), nextInt(), nextInt()
	r := count(a, b, c, d)
	fmt.Println(r)
}


Measured memory_bytes: 640
import java.io.*;
import java.util.Scanner;

class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws IOException {
        int a = ReadInt();
        int b = ReadInt();
        if( a < b ) {
            System.out.println("a < b");
        }
        else if( a == b ) {
            System.out.println("a == b");
        }
        else {
            System.out.println("a > b");
        }
    }
    static int ReadInt() throws IOException {
        return Integer.parseInt(sc.next());
    }
}

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

using ll = long long;
#define ld long double
#define ull unsigned long long int

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  // (i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define ret return

typedef pair<int, int>    pii;
typedef vector<int>       vi;
typedef vector<vi>        vii;
typedef vector<long long> vl;

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    int x, y, z;
    cin >> x >> y >> z;

    // 処理
    int v = x - z;

    // 出力
    cout << v / (y + z) << endl;

    return 0;
}


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl "\n"
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}


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

  int n;
  cin >> n;
  vii m(n, vi(3));
  rep(i,n)rep(j,3) cin >> m[i][j];
  vii dp(n, vi(3));
  rep(i,3) dp[0][i] = m[0][i];
  REP(i,n) {
    rep(j,3) {
      int mx = -1;
      rep(k,3) {
        if(j == k) continue;
        mx = max(dp[i-1][k], mx);
      }
      dp[i][j] = m[i][j] + mx;
    }
  }
  int ans = -1;
  rep(i,3) {
    ans = max(ans, dp[n-1][i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 11136
import java.io.*;
import java.math.*;
import java.util.*;





public class Main {

    static MyScanner in = new MyScanner();
    static   PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    int N;
    static int max = 200001;
    static int [] dr = {1,-1,0,0};
    static int [] dc={0,0,-1,1};
    public static void main(String args[]) throws IOException {
        int N = in.nextInt();
        int M = in.nextInt();
        int C = in.nextInt();
        int [] b = new int[M];
        int count =0; 
        for(int i=0;i<M;i++)
        b[i] = in.nextInt();
        for(int i=0;i<N;i++){
            long sum = 0;
            for(int j=0;j<M;j++){
                sum+=(in.nextInt()*b[j]);
            }
            if(sum+C>0){
                count++;
            }
        }
        out.println(count);

        out.flush();
        }
       static boolean isEven(long a){
            return (a&1)==0;
        }
       static  void swap (int a, int b){

        int temmp = b;
        b=a;
        a = temmp;
        }
    

    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
   
        public MyScanner() {
           br = new BufferedReader(new InputStreamReader(System.in));
        }
   
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
   
        int nextInt() {
            return Integer.parseInt(next());
        }
   
        long nextLong() {
            return Long.parseLong(next());
        }
   
        double nextDouble() {
            return Double.parseDouble(next());
        }
   
        String nextLine(){
            String str = "";
        try {
           str = br.readLine();
        } catch (IOException e) {
           e.printStackTrace();
        }
        return str;
        }
  
     }
}

Measured memory_bytes: 22228
#include <iostream>
using namespace std;
#define RIKU 1
#define UMI 0

int w,h;
int d[50][50];

void rec(int i,int j){
  if( i<0 || j<0 )
    return ;
  if( i>=h | j>=w )
    return;

  if( d[i][j]==UMI )
    return;

  d[i][j]=UMI;
  for( int x=-1;x<2;x++ )
    for( int y=-1;y<2;y++ ){
      if( x==0 && y==0 )continue;
      rec(i+x, j+y);
    }

}

int main(){

  while(cin>>w>>h,w){
    for( int i=0;i<h;i++ )
      for( int j=0;j<w;j++ )
	cin >> d[i][j];

    int ans=0;
    for( int i=0;i<h;i++ )
      for( int j=0;j<w;j++ )
	if( d[i][j]==RIKU ){
	  rec(i,j);
	  ans++;
	}
    cout << ans << endl;
  }
}

Measured memory_bytes: 1276
#include <iostream>
#include <algorithm>
#include <limits>
#include <vector>
#include <map>
#include <cmath>
#include <limits>
#include <iomanip>
#define ll long long int
#define rep(i,n) for(int i = 0;i < n;i++)
#define pb push_back
#define mp make_pair

using namespace std;

int main(){

    int h,w,n;
    cin >> w >> h >> n;

    vector<int> a(n);
    vector<int> x(n);
    vector<int> y(n);

    rep(i,n){
        cin >> x[i] >> y[i] >> a[i];
    }
    int left = 0,right = w;
    int high = h,low = 0;

    rep(i,n){
        if(a[i] == 1){
            if(left < x[i]) left = x[i];
        }
        else if(a[i] == 2){
            if(right > x[i]) right = x[i];
        }
        else if(a[i] == 3){
            if(low < y[i]) low = y[i];
        }
        else{
            if(high > y[i]) high = y[i];
        }
    }

    if(left >= right || low >= high){
        cout << 0 << endl;
    }
    else{
        cout << (right - left) * (high - low) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
#define ll long long
const ll MOD=1e9+7;
const int MAX=2e5+1;

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}

int main(){
    ll n,a,b;
    cin>>n>>a>>b;
    ll xa=1,xb=1;
    ll ya=1,yb=1;
    for(ll i=0;i<a;i++){
        xa=xa*(n-i)%MOD;
        ya=ya*(i+1)%MOD;
    }
    for(ll i=0;i<b;i++){
        xb=xb*(n-i)%MOD;
        yb=yb*(i+1)%MOD;
    }
    ll ans=modpow(2,n)-1-xa*modpow(ya,MOD-2)%MOD-xb*modpow(yb,MOD-2)%MOD;
  while(ans<0) ans+=MOD;
  cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;

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

//pow(llpow,modpow)
template<class T> ll llpow(T x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int main(){
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    int score=0;
    rep(i,n-1)if(s[i]==s[i+1])score++;
    int ans=min(n-1,score+2*k);
    cout<<ans<<endl;
    return 0;
}




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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;

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

  LL N, K;
  cin >> N >> K;
  vector<LL> A(N);
  vector<LL> cnt(200001, 0);
  vector<vector<LL>> idxs(200001);
  REP(i,N){
    cin >> A[i];
    cnt[A[i]]++;
    idxs[A[i]].push_back(i);
  }

  vector<LL> next(N, -1);
  
  REP(i,idxs.size()){
    REP(j,idxs[i].size()){
      next[idxs[i][j]] = idxs[i][(j + 1) % idxs[i].size()];
    }
  }

  LL idx = 0;
  LL loops = 0;
  while (true)
  {
    LL nextidx = next[idx];
    if(nextidx<=idx){
      loops++;
    }
    if(nextidx==N-1){
      loops++;
    }
    nextidx = (nextidx + 1) % N;
    idx = nextidx;
    if(idx==0){
      break;
    }
  }
  LL period = loops;

  K %= period;

  idx = 0;
  loops = 0;
  while (loops<K-3)
  {
    LL nextidx = next[idx];
    if(nextidx<=idx){
      loops++;
    }
    if(nextidx==N-1){
      loops++;
    }
    nextidx = (nextidx + 1) % N;
    idx = nextidx;
  }

  vector<LL> ans;

  while (loops<K)
  {
    LL nextidx = next[idx];
    LL nextloops = loops;
    if (nextidx <= idx)
    {
      nextloops++;
    }
    if(nextloops>=K){
      ans.push_back(A[idx]);
      idx++;
      if(idx==N){
        idx = 0;
        loops++;
      }
    }else{
      if(nextidx==N-1){
        nextloops++;
      }
      nextidx = (nextidx + 1) % N;
      idx = nextidx;
      loops = nextloops;
    }
  }

  REP(i,ans.size()){
    if(i!=0){
      cout << " ";
    }
    cout << ans[i];
  }
  cout << endl;
}


Measured memory_bytes: 18892
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin>>s;
  int flag=1;
  for(int i;i<(s.size()-1)/2;i++){
    if(s.at(i)!=s.at(s.size()-1-i)){
      flag=0;
    }
  }
  for(int i;i<(s.size()-1)/4;i++){
    if(s.at(i)!=s.at((s.size()/2)-1-i)){
      flag=0;
    }
  }
  if(flag==1){
    cout<<"Yes";
  }else{
    cout<<"No";
  }
}

Measured memory_bytes: 3616
#とても回りくどいやり方をしていたので他の人のを見て直す
n = gets.to_i
data = Array.new(10){Array.new(10, 0)}

(n+1).times do |i|
  a = i.to_s
  af = a[0].to_i
  al = a[-1].to_i
  data[af][al] += 1
end

sum = 0
1.upto(9) do |i|
  1.upto(9) do |j|
    sum += data[i][j] * data[j][i]
  end
end

p sum

Measured memory_bytes: 3836
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
    int h;
    int n;
    cin>>h>>n;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        h=h-a;
        if(h<=0){
            cout<<"Yes";
            break;
        }
    }
    if(h>0){
    cout<<"No";
    }
}



Measured memory_bytes: 256
<?php
/**
 * @see: https://atcoder.jp/contests/abc051/tasks/abc051_b
 */

function getInput(): array
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}

function calculate(int $K, int $S): int
{
    $numberOfTriples = 0;

    for ($X = 0; $X <= min($K, $S); $X++) {
        for ($Y = 0; $Y <= min($K, $S - $X); $Y++) {
            $Z = $S - $X - $Y;

            if (0 <= $Z && $Z <= $K) {
                $numberOfTriples++;
            }
        }
    }

    return $numberOfTriples;
}

list($K, $S) = getInput();

$result = calculate($K, $S);

echo $result . PHP_EOL;


Measured memory_bytes: 4728
import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n = i_input()
    ans = 0
    for i in range(1,n):
        ans += (n-1)//i
    print(ans)


if __name__=="__main__":
    main()


Measured memory_bytes: 83880
var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input,
  "index" : 0,
  "max" : input.length,
  "next" : function(){
    if(!this.hasNext()){throw "NoSuchElementException:次に要素は無いよ";}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  },
  "hasNext" : function(){return (this.index < this.max);}
}
Main();
function next(){return obj.next();}
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var N = nextInt();
  while(!isPrime(N)){
    N++;
  }
  myout(N);
}
function isPrime(val){
  if(val == null || val <= 1 || (val != 2 && val % 2 == 0)){
    return false;
  }else if(val == 2){
    return true;
  }
  var root = Math.floor(Math.sqrt(val));
  for(var i = 3; i <= root; i += 2){
    if(val % i == 0){
      return false;
    }
  }
  return true;
}


Measured memory_bytes: 7372
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let w: i32 = input();
    let h: i32 = input();
    let n: usize = input();
    let xya: Vec<(i32, i32, i32)> = (0..n)
        .map(|_| {
            let x = input();
            let y = input();
            let a = input();
            (x, y, a)
        })
        .collect();

    let mut leftbottom = (0, 0);
    let mut righttop = (w, h);
    for (x, y, a) in xya {
        if a == 1 {
            leftbottom.0 = std::cmp::max(leftbottom.0, x);
        } else if a == 2 {
            righttop.0 = std::cmp::min(righttop.0, x);
        } else if a == 3 {
            leftbottom.1 = std::cmp::max(leftbottom.1, y);
        } else {
            righttop.1 = std::cmp::min(righttop.1, y);
        }
    }

    println!(
        "{}",
        std::cmp::max(0, righttop.0 - leftbottom.0) * std::cmp::max(0, righttop.1 - leftbottom.1)
    );
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;
const int INF = 1000000000;
const int MAXN = 400;

int visited[MAXN];
int color[MAXN];
string graph[MAXN];
int n;

bool dfs(int c, int now)
{
    if (visited[now]) return true;
    visited[now] = 1;
    color[now] = c;

    // check color
    rep(i, 0, n)
    {
        if (i == now) continue;
        if (graph[now][i] == '0') continue;

        if (color[now] == color[i])
            return false;
    }

    int next_c = c * -1;
    rep(i, 0, n)
    {
        if (i == now) continue;
        if (graph[now][i] == '0') continue;

        bool check = dfs(next_c, i);
        if (! check)
            return false;
    }
    return true;
}


int main()
{
    cin >> n;
    rep(i, 0, n) cin >> graph[i];

    vector<vector<int>> dis(n, vector<int>(n, INF));
    rep(i, 0, n) 
    {
        dis[i][i] = 0;
        rep(j, 0, n)
        {
            if (graph[i][j] == '1')
                dis[i][j] = 1;
        }
    }
    

    rep(k, 0, n)
        rep(i, 0, n)
            rep(j, 0, n)
                dis[i][j] = min(dis[i][j], dis[i][k]+dis[k][j]);
    
    bool is_ok = dfs(1, 0);
    int ans = 0;
    rep(i, 0, n)
        rep(j, 0, n)
        {
            // cout << i << ' ' << j << ' ' << dis[i][j] << endl;
            ans = max(ans, dis[i][j]);
        }
    
    if (is_ok) 
        cout << ans+1 << endl;
    else
        cout << -1 << endl;
    return 0;
}

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

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


Measured memory_bytes: 1024
N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
nums = {}
for a in A:
    if a in nums:
        nums[a] += 1
    else:
        nums[a] = 1
sorted_nums = list(sorted(nums.items(), key=lambda x: x[1]))
nums_len = len(sorted_nums)
ans = 0
if nums_len > K:
    for i in range(nums_len - K):
        ans += sorted_nums[i][1]
print(ans)


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

int main() {
	int A, B, P;
	 scanf("%d %d", &A, &B);
	 char S[A + B + 1];
	 scanf("%s", &S);
	if (strlen(S) != A + B + 1) {
		printf("No\n");
		return 0;
	}
	if (S[A] != '-') {
		printf("No\n");
		return 0;
	}
	for (int i = 0; i < A; i++) {
		P = S[i] - '0';
		if (P < 0 || P > 9) {
			printf("No\n");
			return 0;
		}
	}
	for (int i = A + 1; i < A + B + 1; i++) {
		P = S[i] - '0';
		if (P < 0 || P > 9) {
			printf("No\n");
			return 0;
	    }
    }
    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 1584
let positive_sum array =
  let rec positive_sum' array i res =
    if i >= Array.length array || array.(i) <= 0 then res
    else positive_sum' array (i + 1) (res + array.(i)) in
  positive_sum' array 0 0
;;

let id = fun x -> x;;

let () = Scanf.scanf " %d" (fun n' ->
  let n = n' in
  let v = Array.init n (fun _ -> Scanf.scanf " %d" id) in
  let c = Array.init n (fun _ -> Scanf.scanf " %d" id) in
  let p = Array.mapi (fun i vi -> vi - c.(i)) v in (
    Array.fast_sort (fun a b -> b - a) p;
    p |> positive_sum |> print_int
));;

Measured memory_bytes: 384
# -*- coding: utf-8 -*-
import sys
from heapq import heappush,heappop,heapify
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    a=list(map(int,input().split()))
    f=[0]*(N+1)
    s=[0]*(N+1)
    h=a[:N]
    heapify(h)
    f[0]=sum(a[:N])
    for i in range(N):
        heappush(h,a[N+i])
        f[i+1]=f[i]+a[N+i]-heappop(h)
    h=[-x for x in a[2*N:]]
    heapify(h)
    s[N]=sum(a[2*N:])
    for i in range(N):
        heappush(h,-a[2*N-i-1])
        s[N-i-1]=s[N-i]+a[2*N-i-1]+heappop(h)
    ans=-INF
    for x,y in zip(f,s):
        ans=max(ans,x-y)
    print(ans)
    
    

if __name__ == '__main__':
    main()


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

const int N = 1e6+6;
int nod[N];

void fnod(){
  for (int i = 1; i < N; ++i){
    for (int j = i; j < N; j+=i){
      nod[j]++;
    }
  }
}


int main(){
  ios::sync_with_stdio(0), cin.tie(0);
  
  fnod();
  int n;  cin >> n;
  long long ans = 0;
  for (int i = 1; i < n; ++i){
    ans += nod[i];
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 7552
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        s: String
    }
    let s = s.chars().collect::<Vec<char>>();
    let mut cnt = 0;
    for i in 0..3 {
        if s[i] == '1' { cnt += 1 };
    }
    println!("{}", cnt);
}


Measured memory_bytes: 4352
s = str(input())
t = str(input())

bestmatch = 0

for i in range(len(s) - len(t) + 1):
  match = 0
  for j in range(len(t)):
    if s[ i + j ] == t[ j ]:
      match += 1
  if match > bestmatch:
    bestmatch = match

print(len(t)-bestmatch)

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

int main() {
  int n;

  cin >> n;

  vector<vector<int> > happy(n,vector<int>(3));
  vector<vector<int> > dp(n,vector<int>(3,0));

  for(int i=0;i<n;i++) {
    cin >> happy[i][0];
    cin >> happy[i][1];
    cin >> happy[i][2];
  }

  dp[0][0]=happy[0][0];
  dp[0][1]=happy[0][1];
  dp[0][2]=happy[0][2];

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

  // for(int i=0;i<n;i++) {
  //   cout << dp[i][0] << " " << dp[i][1]<< " " << dp[i][2] << endl;
  // }

  cout << max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]) << endl;

  return 0;
}


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

int main(){
  int n;cin>>n;
  vector<int> a(n+1,0),x(n+1,0),ans(n+1,0);
  REP(i,n) cin>>a.at(i);

  for(int i=n;i>=1;i--){
    ans.at(i)=x.at(i)^a.at(i);
    for(int j=1;j*j<=i;j++){
      if(!(i%j)){
        x.at(j)^=ans.at(i);
        if((j!=1)&&(j!=i/j)) x.at(i/j)^=ans.at(i);
      }
    }
  }

  int count=0;
  REP(i,n) if(ans.at(i)) count++;
  cout<<count<<endl;
  REP(i,n) if(ans.at(i)) cout<<i<<" ";
}

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

int main() {
  int N, M;
  string temp;
  vector<pair<int,string>> blue(1);
  
  cin >> N;
  for(int i=0; i<N; i++){
    cin >> temp;
    if(i==0){
      blue.at(0).second = temp;
      blue.at(0).first = 1;
    }else{
      bool check = true;
      for(int j=0; j<blue.size(); j++){
        if(temp == blue.at(j).second){
          blue.at(j).first++;
          check = false;
          break;
        }
      }
      if(check){
        blue.push_back( make_pair(1,temp) );
      }
    }
  }
  
//  for(int i=0; i<blue.size(); i++){
//    cout << "first:" << blue.at(i).first << " second:" << blue.at(i).second << endl; 
//  }
  
  cin >> M;
  for(int i=0; i<M; i++){
    cin >> temp;
    for(int j=0; j<blue.size(); j++){
      if(temp == blue.at(j).second){
        blue.at(j).first--;
        break;
      }
    }
  }
  
//  for(int i=0; i<blue.size(); i++){
//    cout << "first:" << blue.at(i).first << " second:" << blue.at(i).second << endl; 
//  }
  
  int max = 0;
  for(int i=0; i<blue.size(); i++){
    if (blue.at(i).first > max) {
      max = blue.at(i).first;
    }
  }
  
  cout << max << endl;
    
}


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

#define rep(i,z) for(int i = 0; i<(int)(z); i++)
#define rep1(i,z) for(int i = 1; i<=(int)(z); i++)
 
using namespace std;

typedef long long ll;
const ll MOD=1e9+7;
using pear = pair<int,int>;



int main(){
    long double l; cin>>l;
    cout<< fixed << setprecision(7) << (l / 3) * (l / 3) * (l / 3)<<endl;
}


Measured memory_bytes: 3672
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  string x;
  string y;
  cin >> x >> y;
  if(x.size()==y.size()){
    for(int i=0;i<x.size();i++){
      cout << x.at(i) <<y.at(i);
    }
    cout<< endl;
  }
  else{
      for(int i=0;i<x.size()-1;i++){
      cout << x.at(i) <<y.at(i);
    }
    cout << x.at(x.size()-1) << endl;
  }
}

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

int main(){
  string S;
  cin >> S;
  
  int N = S.size();
  vector<int> pos(N + 1, 0);
  
  for (int i = 0; i <= N - 1; i++){
    if (S.at(i) == '<'){
      pos.at(i + 1) = pos.at(i) + 1;
    }
  }
  
  for (int i = N - 1; i >= 0; i--){
    if (S.at(i) == '>'){
      pos.at(i) = max(pos.at(i + 1) + 1, pos.at(i));
    }
  }
  
  ll ans = 0;
  for (int i = 0; i <= N; i++){
    ans += pos.at(i);
  }
  
  cout << ans << endl;
}

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

int main()
{
    string n;

    int c=0;

    cin>>n;

    if(n[0]==n[1]&&n[0]==n[2]&&n[0]=='R') c=3;
    else if(n[0]==n[1]&&n[0]=='R') c=2;
    else if(n[1]==n[2]&&n[1]=='R') c=2;
    else if(n[0]=='R'||n[1]=='R'||n[2]=='R') c=1;
    else c=0;

    cout<<c<<endl;
}


Measured memory_bytes: 3620
#include<stdio.h>

#define N 200000

int main()
{
  int i,j,maxv,minv,n,a,R[N];

  scanf("%d",&n);

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

  minv = R[0];
  maxv = -2000000000;
  
  for(j = 1; j < n; j++)
  {
    if(maxv < R[j] - minv)maxv = R[j] - minv;
    if(minv > R[j])minv = R[j];
  }

  printf("%d\n",maxv);

  return 0;
}



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

struct Group{
    set<string> chi;
};

map<string,Group> groups;



vector<string> split(string &x,char del){
    vector<string> res;
    string buf;
    for(int i=0;i<x.size();i++){
        if(x[i]==del) res.push_back(buf),buf.clear();
        else buf+=x[i];
    }
    if(!buf.empty()) res.push_back(buf);
    return res;
}
void dfs(string name){
    set<string> inserter;
    set<string> eraser;
    for(auto &cname:groups[name].chi){
        if(groups.count(cname)){
            dfs(cname);
            for(auto &e:groups[cname].chi) inserter.insert(e);
            eraser.insert(cname);

        }
        else{
            inserter.insert(cname);
        }
    }
    for(auto &e:inserter) groups[name].chi.insert(e);
    for(auto &e:eraser) groups[name].chi.erase(e);
    
    
}
int solve(){
    groups.clear();
    int n;
    cin>>n;
    if(n==0) return false;
    string name0;
    for(int i=0;i<n;i++){
        string str;
        cin>>str;
        int p=0;
        vector<string> tmp=split(str,':');
        string gname=tmp[0];
        if(i==0) name0=gname;
        vector<string> chils=split(tmp[1],',');
        chils.back().pop_back();
        for(int i=0;i<chils.size();i++){
            groups[gname].chi.insert(chils[i]);
        }
    }
    dfs(name0);
    cout<<groups[name0].chi.size()<<endl;
    return true;
}

int main(){
    while(solve());
    return 0;
}


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


int main(){


    int a, b, c;

    char s1, s2;


    cin >> a >> s1 >> b >> s2 >> c;


    if( b <= 4 ){

        cout << "Heisei" << endl;

        return 0;

        }


    cout << "TBD" << endl;

    return 0;

    }


Measured memory_bytes: 256
#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))
//-------------------------------------------------------

int N;
int A[101010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) cin>>A[i];
	sort(A,A+N);
	
	x=0;
	FOR(i,N-1) {
		if(abs(A[N-1]-2*A[i])<abs(A[N-1]-2*A[x])) x=i;
	}
	
	cout<<A[N-1]<<" "<<A[x]<<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: 640
import numpy as np


def test(n, xxx, m, k, aaa):
    # print(xxx)
    print(np.diff(xxx))
    for _ in range(k):
        for a in aaa:
            x, y, z = xxx[a - 2:a + 1]
            b = x - (y - x)
            c = z + (z - y)
            xxx[a - 1] = (b + c) // 2
        # print(xxx)
        print(np.diff(xxx))


n = int(input())
xxx = list(map(int, input().split()))
m, k = map(int, input().split())
aaa = list(map(int, input().split()))

doubling = np.arange(n - 1, dtype=np.int64)
for a in aaa:
    doubling[a - 2], doubling[a - 1] = doubling[a - 1], doubling[a - 2]

perm = np.arange(n - 1, dtype=np.int64)
while k:
    if k & 1:
        perm = perm[doubling]
    doubling = doubling[doubling]
    k >>= 1

diff = np.diff(xxx)[perm]
diff = np.insert(diff, 0, xxx[0])
print('\n'.join(map(str, diff.cumsum())))


Measured memory_bytes: 48260
n = int(input())
c = [[0] * 10 for _ in range(10)]
for i in range(1, n+1):
    c[int(str(i)[0])][int(str(i)[-1])] += 1
ans = 0
for i in range(10):
    for j in range(10):
        ans += c[i][j] * c[j][i]
print(ans)


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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int n, p;
  cin >> n >> p;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  int odd = 0;
  rep(i, n) {
    if (a.at(i) % 2 == 1) {
      odd++;
    }
  }
  ll res;
  if (odd == 0) {
    if (p == 0) {
      res = 1LL << n;
    } else {
      res = 0;
    }
  } else {
    res = 1LL << (n - 1);
  }
  cout << res << endl;
  return 0;
}


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

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define smaller_queue  priority_queue <ll, vector<ll>, greater<ll> >
//------------------------------------------------------

int main() {
    string s, t;
    cin >> s >> t;

    rep(i, t.length()) {
        string u = s.substr(i) + s.substr(0, i);
        if (t == u) {
            Yes(true);
            return 0;
        }
    }
    Yes(false);
    return 0;
}



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

int main() {
 
  string s;
  cin >> s;
  
  for (int i = 0; i < s.size(); i++) {
    if (i == 5 || i == 13) {
      cout << " ";
    } else {
      cout << s[i];
    }
  }
  
  cout << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sys/time.h>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>

using namespace std;

void solve(long long N, vector<long long> a, vector<long long> b){
    int ans = 0;
    for (int i = 0; i < 29; i++) {
        vector<long long> v;
        for (auto&& bm : b) {
            v.push_back(bm % (1 << (i+1)));
            v.push_back((1 << (i+1)) + bm % (1 << (i+1)));
        }
        sort(v.begin(), v.end());
        int cnt = 0;
        for (auto&& am : a) {
            int low1 = lower_bound(v.begin(), v.end(), (3 << i) - (am% (1<<(i+1)))) - v.begin();
            int low2 = lower_bound(v.begin(), v.end(), (4 << i) - (am% (1<<(i+1)))) - v.begin();
            cnt += low2 - low1;
        }
        if (cnt%2 != 0) {
            ans += 1<<i;
        }
    }
    std::cout << ans << std::endl;
}

int main(){	
    struct timeval start,end;
    long long span;
    gettimeofday(&start,NULL);

    long long N;
    scanf("%lld",&N);
    vector<long long> b(N-1+1);
    vector<long long> a(N-1+1);
    for(int i = 0 ; i <= N-1 ; i++){
    	scanf("%lld",&a[i]);
    }
    for(int i = 0 ; i <= N-1 ; i++){
    	scanf("%lld",&b[i]);
    }
    solve(N, a, b);

    gettimeofday(&end,NULL);
    span = (end.tv_sec -start.tv_sec)*1000000LL + (end.tv_usec - start.tv_usec);
    std::cerr << "--Total Time: " << span/1000 << "ms" << endl;
    return 0;
}


Measured memory_bytes: 15748
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
#include <queue>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define print(x) cout<<(x)<<'\n'
#define print_vec(v) rep(i,v.size()){if(i!=0)cout<<" ";cout<<v[i];}cout<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<'\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pll=pair<ll,ll>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vstr=vector<string>;

void solve() {
    ll A,B;
    char op;
    cin >> A >> op >> B;
    ll ans;
    if(op=='+') ans = A+B;
    else ans = A-B;
    print(ans);
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    //int q; cin >> q;
	//while (q--)
		solve();
    return 0;
}

Measured memory_bytes: 3560
#include<iostream>
#include<cmath>

using namespace std;

struct pt{double x, y;};

void koch(int n, pt a, pt b) {
	if(n<1) return;
	n--;
	pt s, t, u;
	s.x=(2*a.x+b.x)/3;
	s.y=(2*a.y+b.y)/3;
	u.x=(a.x+2*b.x)/3;
	u.y=(a.y+2*b.y)/3;
	t.x=(a.x+b.x)/2-(b.y-a.y)*(sqrt(3.0)/6.0);
	t.y=(a.y+b.y)/2+(b.x-a.x)*(sqrt(3.0)/6.0);
	koch(n, a, s);
	cout<<s.x<<' '<<s.y<<'\n';
	koch(n, s, t);
	cout<<t.x<<' '<<t.y<<'\n';
	koch(n, t, u);
	cout<<u.x<<' '<<u.y<<'\n';
	koch(n, u, b);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.setf(ios::fixed);
	cout.precision(8);
	int n;
	cin>>n;
	pt p1={0,0};
	pt p2={100,0};
	cout<<"0 0\n";
	koch(n, p1, p2);
	cout<<"100 0\n";
	return 0;
}



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

#define ll long long
#define ld long double

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define repA(i,A)   for(auto i:A)

#define err() cout<<"=================================="<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl

#define mp make_pair
#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)	A.rbegin(),A.rend()
#define ft first
#define sd second

#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V> 
#define Vpll vector<pll>

#define endl "\n"

const ll logN = 20;
const ll N = 100005;
const ll M = 1000000007;
const ll INF = 1e12;
#define PI 3.14159265

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

ll C[5005][3];
ll cost[5005];

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n,m,p;
    cin>>n>>m>>p;
    bool f=0;
    rep(i,0,m){
    	ll u,x,w;
    	cin>>u>>x>>w;
 		C[i][0]=u;C[i][1]=x;C[i][2]=-w+p;
    }
    rep(i,0,n+1)	cost[i]=INF;
    cost[1]=0;
    ll cnt=0,res;
   	while(cnt<n-1){
   		cnt++;
   		rep(i,0,m){
    		if(cost[C[i][0]] != INF){
    			if(cost[C[i][1]] > cost[C[i][0]] +	C[i][2]){
    				cost[C[i][1]] = cost[C[i][0]] +	C[i][2];
    			}
    		}
    	}
    }
    res = cost[n];
    cnt=0;
    while(cnt<n-1){
   		cnt++;
   		rep(i,0,m){
    		if(cost[C[i][0]] != INF){
    			if(cost[C[i][1]] > cost[C[i][0]] +	C[i][2]){
    				cost[C[i][1]] = cost[C[i][0]] +	C[i][2];
    			}
    		}
    	}
    }
	if(res!=cost[n]){
		cout<<-1<<endl;
	}
    else cout<<max(-cost[n],0LL)<<endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int a[120],b,c,sum1=0;
bool cmp(int x,int y)
{
  return x>y;
}
int main()
{
  scanf("%d %d",&b,&c);
  for(int i=1;i<=b;i++)
    scanf("%d",&a[i]),sum1+=a[i];
  sort(a+1,a+b+1,cmp);
  if(a[c]*c*4>=sum1)printf("Yes\n");
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 256
//Name: Split Up!
//Level: 3
//Category: 全探索,DP
//Note:

/*
 * 全ての選び方を試す．
 * このとき，ある選び方が2進数 pat で与えられているとき，これに対する攻撃力の合計値は
 * patのビットをどれか1つ落としたときの合計値に，落としたビットに対応する攻撃力を加えたものとなる．
 * このとき，パターンを2進数で昇順に試していけばビットを1つ落としたパターンは必ず pat より前に試しているので，
 * これらの値を記憶しておくことで簡単に計算できるようになる．
 *
 * 落とすビットはどれでもよいが，最下位ビットが pat&(-pat) で得られるのでここではこれを使っている．
 *
 * オーダーは O(2^N)．
 * 愚直に各パターンについて合計値を求めると O(N*2^N) であるから高速化されている．
 */
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int arr[20];
int pos_of[1<<20];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    for(int i = 0; i < 20; ++i) pos_of[1<<i] = i;
    while(true) {
        int N;
        cin >> N;
        if(!N) break;

        int sum = 0;
        for(int i = 0; i < N; ++i) {
            cin >> arr[i];
            sum += arr[i];
        }
        int ans = 100000000;
        vector<int> memo(1<<N, 0);
        for(int pat = 1; pat < (1<<N); ++pat) {
            const int prev = pat&~(pat&-pat);
            const int suma = memo[prev] + arr[pos_of[pat&-pat]];
            const int sumb = sum - suma;
            ans = min(ans, abs(suma-sumb));
            memo[pat] = suma;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 7388
import os

import sys
import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N, K = list(map(int, sys.stdin.buffer.readline().split()))
A = list(map(int, sys.stdin.buffer.readline().split()))

A = np.array(A, dtype=int) - 1

dp = np.zeros((K.bit_length(), N), dtype=int)
dp[0] = A
for h in range(len(dp) - 1):
    dp[h + 1] = dp[h, dp[h]]

ans = 0
for i in reversed(range(K.bit_length())):
    if K >> i & 1:
        ans = dp[i, ans]
print(ans + 1)


Measured memory_bytes: 125904