akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

S = input()
if S == 'Sunny':
    ans = 'Cloudy'
elif S == 'Cloudy':
    ans = 'Rainy'
else:
    ans = 'Sunny'

print(ans)

Measured memory_bytes: 12312
#include <bits/stdc++.h>
using namespace std;
const int N = 3010;
int n, m;
int S[N][N], C[N][N], pw2[N * N], pww[N], ans;
int powi(int a, int b)
{
    int c = 1;
    for (; b; b >>= 1, a = 1ll * a * a % m)
        if (b & 1) c = 1ll * c * a % m;
    return c;
}
int main()
{
    cin >> n >> m;
    S[0][0] = 1;
    for (int i = 0; i < n; ++ i)
        for (int j = 0; j <= i; ++ j)
        {
            S[i + 1][j] = (S[i + 1][j] + 1ll * S[i][j] * (j + 1)) % m;
            S[i + 1][j + 1] = (S[i + 1][j + 1] + S[i][j]) % m;
        }
    for (int i = 0; i <= n; ++ i)
    {
        C[i][0] = C[i][i] = 1;
        for (int j = 1; j < i; ++ j)
            C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % m;
    }
    pw2[0] = 1;
    for (int i = 1; i <= n * n; ++ i) pw2[i] = (pw2[i - 1] + pw2[i - 1]) % m;
    for (int i = 0, j = 1; i <= n; ++ i)
    {
        pww[i] = powi(2, j);
        j = 2 * j % (m - 1);
    }
    for (int i = 0; i <= n; ++ i)
        for (int j = 0; j <= n - i; ++ j)
            ans = (ans + 1ll * C[n][i] * ((n - i) & 1 ? m - 1 : 1) % m * pww[i] % m * pw2[i * j] % m * S[n - i][j]) % m;
    cout << ans << endl;
}


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

int main(){
    ll n, k;
    cin >> n >> k;
    ll R, S, P;
    cin >> R >> S >> P;
    string t;
    cin >> t;
    string c;
    ll points = 0;
    rep(i,n){
        if((i-k>=0) && (t[i-k] == t[i])){
            t[i] = '!';
            continue;
        }
        if(t[i]=='r') points+=P;
        else if(t[i]=='s') points+=R;
        else if(t[i]=='p') points+=S;
    }
    cout << points << endl;
    return 0;
}

Measured memory_bytes: 512
const Main = input => {
  const sp = input.split('\n');
  const N = Number(sp[0]);
  const A_list = sp[1].split(' ').map(e => Number(e));

  const list = new Array(N).fill(0);

  for(let i=0; i<A_list.length; i++) list[A_list[i]-1]++;

  console.log(list.join('\n'));
};

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));
/*Main(`5
1 1 2 2`);
Main(`10
1 1 1 1 1 1 1 1 1`)
Main(`7
1 2 3 4 5 6`)*/


Measured memory_bytes: 53016
#include <iostream>
#include <map>
#include <string>
#include <cmath>

using namespace std;

int main() {
	int n;
	cin >> n;
	int x = 0, y = 0, t = 0;
	for (int i = 0; i < n; i++) {
		int xt, yt, tt;
		cin >> tt >> xt >> yt;

		int d = abs(xt - x) + abs(yt - y);
		if (d > (tt - t)) {
			cout << "No" << endl;
			return 0;
		}
		if (d + 1 == (tt - t)) {
			cout << "No" << endl;
			return 0;
		}
		if (((tt - t) - d) % 2 != 0) {
			cout << "No" << endl;
			return 0;
		}

		x = xt;
		y = yt;
		t = tt;
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <unordered_map>
#include <utility>
#include <map>
#include <set>
#include <numeric>
using namespace std;

int main(){
    string s, t;
    cin >> s >> t;
    
    int data[26][26];
    int i, j;
    int flag = 1;
    
    for(i = 0; i < 26; i++){
        for(j = 0; j < 26; j++){
            data[i][j] = 0;
        }
    }
    
    for(i = 0; i < s.size(); i++){
        data[s[i]-'a'][t[i]-'a'] = 1;
    }
    
    // 2以上で終了
    int count = 0;
    for(i = 0; i < 26; i++){
        count = 0;
        for(j = 0; j < 26; j++){
            count += data[i][j];
        }
        if(count >= 2){
            cout << "No" << endl;
            return 0;
        }
    }
    
    for(i = 0; i < 26; i++){
        count = 0;
        for(j = 0; j < 26; j++){
            count += data[j][i];
        }
        if(count >= 2){
            cout << "No" << endl;
            return 0;
        }
    }
    
    int taiou[26];
    for(i = 0; i < 26; i++){
        taiou[i] = 26;
    }
    // 何と対応しているか
    for(i = 0; i < 26; i++){
        for(j = 0; j < 26; j++){
            if(data[i][j] == 1){
                taiou[i] = j;
            }
        }
    }
    
    for(i = 0; i < 26; i++){
        if(taiou[i] != 26){
            if(taiou[taiou[i]] != i && data[taiou[i]][i] != 0){
                flag = 0;
            }
        }
    }
    
    if(flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 776
#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define N 500
using namespace std;
int n,k;
int main()
{
	if(scanf("%d",&k),k==1) return puts("1\n1\n"),0;
	RI i,j,t;for(printf("%d\n",n=((k+3)/4)*2),i=1;i<=n;++i)
		for(j=1;j<=n;++j) t=i+j-1,t>n&&(t-=n),printf("%d%c",(i&1)&&t+n<=k?t+n:t," \n"[j==n]);
	return 0;
}

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

vector<long long> layer = {1}, patty = {1};

long long getPatty(int n, long long x) {
    if (n == 0) {
        return (x == 1 ? 1 : 0);
    } else {
        if (x <= layer[n - 1] + 1) {
            return getPatty(n - 1, x - 1);
        } else if (x <= 2 * layer[n - 1] + 2) {
            return patty[n - 1] + 1 + getPatty(n - 1, x - (layer[n - 1] + 2));
        } else {
            return 2 * patty[n - 1] + 1;
        }
    }
}

int main() {
    int N;
    long long X;
    cin >> N >> X;

    for (int i = 1; i <= N; i++) {
        layer.push_back(2 * layer[i - 1] + 3);
        patty.push_back(2 * patty[i - 1] + 1);
    }
  
    cout << getPatty(N, X) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int dp[100005];
int n,arr[100005];
int func(int i)
{
    int ans1=0,ans2=0;
    if(i>=n) return 0;
    if(dp[i]!=-1) return dp[i];
    ans1 = abs(arr[i]-arr[i+1])+func(i+1);
    if(i<=n-2) ans2=abs(arr[i]-arr[i+2])+func(i+2);
    else ans2=123456;
    return dp[i]=min(ans1,ans2);
}
int main()
{
    int i;
    cin>>n;

    for(i=1;i<=n;i++) cin>>arr[i];
    memset(dp,-1,sizeof dp);
    int ans = func(1);
    cout<<ans;
}


Measured memory_bytes: 4096
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

N =  int(sys.stdin.readline())

ans = 0
for i in range(1, 40):
    for j in range(2, 10):
        tmp = i ** j
        if tmp <= N:
            ans = max(tmp, ans)
print(ans)


Measured memory_bytes: 64364
#require 'Math'

n=gets.strip.to_i
xy=readlines.map{|l| l.split.map(&:to_i) }

alls = (1..n).to_a.permutation

def dis(l,r)
  Math.sqrt((l[0]-r[0])**2 + (l[1]-r[1])**2)
end

result = 0
alls.each do |pa|
  pa.each_cons(2) do |ll,rr|
    l=ll-1
    r=rr-1
    result += dis(xy[l], xy[r])
  end
end

p result/alls.size.to_f


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

int main() {
  int N = 0, A = 0;
  
  cin >> N;
  cin >> A;
  
  if ((N % 500) <= A) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdint>
#include <utility>
#include <iterator>

template <typename T>
struct SegmentTree{
private:
    int n;
    T init;
    std::vector<T> node;

public:
    explicit SegmentTree(int sz,T initv = 0) {
        n=1;
        init=initv;
        while(n<sz)n=n*2;
        node.resize(static_cast<unsigned int>(2 * n - 1), init);
        for (int i = 0; i <sz ; ++i) node[i+n-1]=init;
        for (int i = n-2; i >= 0 ; --i) node[i]=std::max(node[2*i+1],node[2*i+2]);
    }

    void update(int x, T val){//x:0-indexed
        x+=n-1;
        node[x]=val;
        while(x>0){
            x=(x-1)/2;
            node[x]=std::max(node[2*x+1],node[2*x+2]);
        }
    }

    T getmax(int p,int q,int k=0,int l=0,int r=-1){//[p,q):0-indexed
        if(r<0)r=n;
        if(r<=p||l>=q)return init;//out of range
        if(p<=l&&r<=q)return node[k];

        return std::max(getmax(p,q,2*k+1,l,(l+r)/2),getmax(p,q,2*k+2,(l+r)/2,r));
    }
};

using ll = long long;
using pi = std::pair<ll,ll>;
const ll mod = 998244353;
int main() {
    int n;
    std::cin>>n;
    if(n==1){
        std::cout<<2<<std::endl;
        return 0;
    }
    SegmentTree<ll> st(n);
    std::vector<pi> robo(n);
    for(int i = 0;i < n;++i) {
        int x,d;
        std::cin>>x>>d;
        robo[i]=pi(x,d);
    }
    std::sort(robo.begin(),robo.end());
    std::vector<ll> lim(n);
    for(int i = n-1;i >= 0;--i) {
        auto it=std::lower_bound(robo.begin(),robo.end(),pi(robo[i].first+robo[i].second,0));
        st.update(i,i);
        if(it==robo.begin()+i){
            continue;
        }
        else --it;
        int d=it-robo.begin();
        st.update(i,st.getmax(i,d+1));
    }
    std::vector<ll> dp(n,0);
    dp[n-1]=2;
    for(int i = n-2;i >= 0;--i) {
        dp[i]+=dp[i+1];
        dp[i]%=mod;
        auto t=st.getmax(i,i+1);
        if(t<n-1)dp[i]+=dp[t+1];
        else ++dp[i];
        dp[i]%=mod;
    }
    std::cout<<dp[0]<<std::endl;
    return 0;
}


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

using namespace std;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
using ll = long long;
int n, m, s, t;
struct Edge {
    int to;
    ll J, S;
    explicit Edge(int to = 0, ll J = 0, ll S = 0) : to(to), J(J), S(S) {}
};

vector<vector<Edge>> G;

const ll INF = 1e18;
vector<ll> dijk(int s, int t, bool jpy) {
    using State = pair<ll, int>;
    vector<ll> dp(n, INF);
    priority_queue<State, vector<State>, greater<State>> que;

    dp[s] = 0;
    que.push(State{0, s});

    while (que.size()) {
        auto now = que.top();
        que.pop();
        ll cost = now.first;
        int v = now.second;
        if (dp[v] < cost) continue;

        for (const auto &e : G[v]) {
            auto e_cost = jpy ? e.J : e.S;
            if (dp[e.to] > dp[v] + e_cost) {
                dp[e.to] = dp[v] + e_cost;
                que.push(State{dp[e.to], e.to});
            }
        }
    }
    return dp;
}

int main() {
    cin >> n >> m >> s >> t;
    s--, t--;
    G.resize(n);
    rep(i, m) {
        int u, v;
        ll a, b;
        cin >> u >> v >> a >> b;
        u--, v--;
        G[u].push_back(Edge(v, a, b));
        G[v].push_back(Edge(u, a, b));
    }

    auto dp1 = dijk(s, t, true);
    auto dp2 = dijk(t, s, false);

    vector<ll> ans;
    rep(i, n) {
        ll tmp = dp1[i] + dp2[i];
        ans.push_back((ll)(1e15 - tmp));
    }
    for (int i = n - 1; i >= 1; i--) {
        ans[i - 1] = max(ans[i - 1], ans[i]);
    }

    rep(i, n) cout << ans[i] << endl;

    return 0;
}


Measured memory_bytes: 13952
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod=1e9+7;

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i=0; i<N; i++){
        cin >> a[i];
    }
    int cnt=0;
    for(int i=0; i<N-1; i++){
        if(a[i]==a[i+1]){
            a[i+1] = 10001;
            cnt++;
        }
    }
    cout << cnt;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Xml.Schema;

namespace Contest
{
    class Scanner
    {
        private string[] line = new string[0];
        private int index = 0;
        public string Next()
        {
            if (line.Length <= index)
            {
                line = Console.ReadLine().Split(' ');
                index = 0;
            }
            var res = line[index];
            index++;
            return res;
        }
        public int NextInt()
        {
            return int.Parse(Next());
        }
        public long NextLong()
        {
            return long.Parse(Next());
        }
        public string[] Array()
        {
            line = Console.ReadLine().Split(' ');
            index = line.Length;
            return line;
        }
        public int[] IntArray()
        {
            var array = Array();
            var result = new int[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = int.Parse(array[i]);
            }

            return result;
        }
        public long[] LongArray()
        {
            var array = Array();
            var result = new long[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = long.Parse(array[i]);
            }

            return result;
        }
    }

    class Program
    {
        private int N, X;
        private int[] A;
        private void Scan()
        {
            var sc = new Scanner();
            N = sc.NextInt();
            X = sc.NextInt();
            A = sc.IntArray();
        }

        public void Solve()
        {
            Scan();
            Array.Sort(A);
            int i;
            for (i = 0; i < N; i++)
            {
                if (X >= A[i])
                {
                    X -= A[i];
                }
                else
                {
                    X = 0;
                    break;
                }
            }

            if (X > 0)
            {
                i--;
            }
            Console.WriteLine(i);
        }

        static void Main() => new Program().Solve();
    }
}

Measured memory_bytes: 13140
import java.util.*

fun main(args: Array<String>){
  val sc =Scanner(System.`in`)
  val a=sc.nextInt()
  val b=sc.nextInt()
  var sum=0
  for(i in 1..b-a){
   	sum=sum+i 
    //print(i)
    //print(" ")
    //println(sum)
  }
  println(sum-b)
  
  
  
  
  
}
  

Measured memory_bytes: 31144
#include <bits/stdc++.h>
#define LL long long
#define MEM(x,y) memset(x,y,sizeof(x))
#define MOD(x) ((x)%1000000007)

using namespace std;
const int maxn = 1e5+7;
const int mod=1e9+7;
LL sum[maxn],a[maxn];

LL ksm(LL a,LL b)
{
    LL res=1,base=a;
    while (b)
    {
        if (b&1) res=MOD(res*base);
        base=MOD(base*base);
        b/=2;
    }
    return (res);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n;cin>>n;for (int i=1;i<=n;i++) cin>>a[i];
    sum[1]=1;for (int i=2;i<=n;i++) sum[i]=MOD(ksm(i,mod-2)+sum[i-1]);
    LL ans=0;
    for (int i=1;i<=n;i++)
    {
        ans=MOD(ans+(sum[n-i+1]+sum[i]-1)*a[i]);
    }
    LL tmp=1;for (int i=1;i<=n;i++) tmp=MOD(tmp*i);
    ans=MOD(ans*tmp);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1792
#pragma GCC target ("avx2")
#pragma GCC optimize "trapv"
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define input(a,n) for(ll i1=0;i1<n;i1++)cin>>a[i1]
#define ll long long
#define pi 2 * acos(0.0)
#define usll unordered_set<ll>
#define sll set<ll>
#define vll vector<ll>
#define mll map<ll,ll>
#define pll pair<ll,ll>
#define umll unordered_map<ll,ll>
#define S second
#define sz size()
#define all(v) v.begin(),v.end()
#define Y cout<< "Yes"<< "\n"
#define N cout<< "No"<< "\n"
#define F first
#define mp make_pair
#define pb push_back
#define pf push_front
#define ld long double
#define mod 1000000007
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll x,y,f=0;
    cin>>x>>y;
    for(ll i=0;i<=x;i++)
    {
        for(ll j=0;j<=x;j++)
        {
            if(i+j==x)
            {
                if(4*i+2*j==y)
                {
                    f=1;
                    break;
                }
            }
        }
    }
    if(f)
        Y;
    else
        N;
    return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <unordered_map>

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

using namespace std;

struct ab {
    long long a;
    long long b;
    ab(){}
    ab(long long a, long long b) {
        this->a = a;
        this->b = b;
    }
};

bool operator>(const ab& l, const ab& r) {
    return l.b > r.b;
}
bool operator<(const ab& l, const ab& r) {
    return l.b < r.b;
}

int main(){
    int n; cin >> n;
    vector<long long> a(n);
    vector<long long> b(n);
    vector<ab> v(n);
    for(int i = 0; i < n; i++){
        long long tmpa, tmpb;
        cin >> tmpa >> tmpb;
        v[i] = ab(tmpa, tmpb);
    }
    sort(v.begin(), v.end());
    long long used = 0;
    for(int i = 0; i < n; i++){
        // cout << v[i].a << " " << v[i].b << endl;
        if(used + v[i].a > v[i].b) {
            cout << "No" << endl;
            return 0;
        } else {
            used += v[i].a;
        }
    }
    cout << "Yes" << endl;
}



Measured memory_bytes: 6528
import           Control.Monad
import qualified Data.ByteString.Char8 as BS
import           Data.Maybe

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
  [n, k] <- getIntList
  let r = n `mod` k
      ans = min r (k-r)
  print ans

Measured memory_bytes: 380
from collections import Counter
N=int(input())
A=sorted(map(int,input().split()),reverse=True)
c=Counter(A)
ans=0
for i in range(N):
    if c[A[i]]==0:
        continue
    c[A[i]]-=1
    k=1<<A[i].bit_length()
    v=k-A[i]
    if v in c and c[v]>0:
        ans+=1
        c[v]-=1
print(ans)

Measured memory_bytes: 36116
#include "bits/stdc++.h"
using namespace std;
#define ll long long
int n,x,y;

int main(){

	cin >> n >> x >> y;
	vector<vector<int> > graph(n);
	graph[0].push_back(1);
	graph[n-1].push_back(n-2);
	for(int i = 1; i < n - 1; i++)
	{
		graph[i].push_back(i+1);
		graph[i].push_back(i-1);
	}
	graph[x-1].push_back(y-1);
	graph[y-1].push_back(x-1);
	int INF = 1e9 + 7;
	vector<int> ans(n, 0);
	vector<vector<int> > dist(n, vector<int> (n, INF));

	for(int i = 0; i < n; i++){  
		dist[i][i] = 0;
		queue<int> q;
		q.push(i);
		while(!q.empty()){
			int u = q.front();
			q.pop();
			for(auto it:graph[u]){
				if(dist[i][it] > 1 + dist[i][u]){
					dist[i][it] = 1 + dist[i][u];
					ans[dist[i][it]]++;
					q.push(it);
				}	
			}
		}

	}
	for(int i = 1; i < n; i++)
		cout << ans[i]/2 <<  endl;

	

	return 0;

}


Measured memory_bytes: 16128
import sys
import numpy as np
# from numba import njit

# 公式解説を見てからやった
# 複数サイクルでき、1-K回移動可能
# N < 5000?多分、O(N * 2N)くらいで行けそうに見えるが。。。

# @njit(cache=False)
def main(N,K,P,C,ans):


	# 一度計算したサイクル情報を一応キャッシュしておく。。。
	# あんまり意味なさそう
	cycleIDs = np.full( N, -1, dtype=np.int64 )
	cycleInfs = []


	# print(P)

	cycleID = 0

	for n in range(N):

		v = n
		currentCycleItemCnt = 0
		currentCycleTotal = 0

		if cycleIDs[v] != -1:
			currentCycleItemCnt, currentCycleTotal = cycleInfs[ cycleIDs[v] ]
			# print(currentCycleItemCnt, currentCycleTotal)
		else:
			while True:
				# 全頂点について、属するサイクルを計算する
				currentCycleItemCnt += 1
				currentCycleTotal += C[v]

				v = P[v]
				if v == n:
					# サイクル発見
					cycleInfs.append( (currentCycleItemCnt, currentCycleTotal) )
					cycleID += 1
					break

				# 一応、一度サイクルを計算した頂点については、
				# その頂点の属するサイクルの情報をメモっておく。。。
				cycleIDs[v] = cycleID

		procCnt = 0
		currentCycleSumTmp = 0

		while True:

			# 頂点vにコマが置かれた時の最高スコアを計算し、
			# これまでの最高スコアを上回ったら、これまでの最高スコアを更新する
			procCnt += 1
			currentCycleSumTmp += C[v]
			if K < procCnt:
				break

			cycleLoopCnt = 0
			if procCnt < K and 0 < currentCycleTotal:
				cycleLoopCnt = int(( K - procCnt ) // currentCycleItemCnt)

			# print("v=", v, "currentCycleSumTmp=", currentCycleSumTmp, procCnt)
			tmp = currentCycleSumTmp + cycleLoopCnt * currentCycleTotal
			ans = max( int(ans), int(tmp) )

			v = P[v]
			if v == n:
				# サイクル終了
				break

	print(int(ans))

if sys.argv[-1]=='ONLINE_JUDGE':
	# from numba import njit
	from numba.pycc import CC
	cc=CC('my_module')
	cc.export('main','void(i8,i8,i8[:],i8[:],i8)')(main)
	# main=njit(main, cache=True)
	cc.compile()
	exit(0)
from my_module import main



if __name__ == "__main__":
	N,K = map(int,input().split())
	P = np.array( input().split(), np.int64 )
	P -= 1
	C = np.array( input().split(), np.int64 )

	ans = -1e9	# NOTES: 2020/08/17 numba関数内でこれをやっていたら、データによってはWAになってしまっていた。詳細は、いまだに不明。
	main(N,K,P,C,ans)
	#print(ans)




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

int n, y;

int main()
{
    int i, j;

    cin >> n >> y;

    for(i=0; i<=n; i++)
        for(j=0; j<=n-i; j++)
            if(i*10000+j*5000+(n-i-j)*1000==y)
            {
                cout << i << " " << j << " " << n-i-j;
                return 0;
            }

    cout << "-1 -1 -1";
    return 0;
}

Measured memory_bytes: 256
//Bokan ga bokka--nn!!
//Daily Lunch Special Tanoshii !!
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define s(x) scanf("%d",&x)
#define rep(i,x) for(int i=0;i<x;i++)
int rui[1005][1005][3]={};
char f[1005][1005];
int n,m,q;
int main()
{
	scanf("%d %d %d",&n,&m,&q);
	for(int i=0;i<n;i++)
	{
		scanf("%s",f[i]);
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			rui[i][j][0]=rui[i-1][j][0]+rui[i][j-1][0]-rui[i-1][j-1][0]+(f[i-1][j-1]=='J');
			rui[i][j][1]=rui[i-1][j][1]+rui[i][j-1][1]-rui[i-1][j-1][1]+(f[i-1][j-1]=='O');
			rui[i][j][2]=rui[i-1][j][2]+rui[i][j-1][2]-rui[i-1][j-1][2]+(f[i-1][j-1]=='I');
			
		}
	}
	for(int aa=0;aa<q;aa++)
	{
		int x,y,z,w;
		scanf("%d %d %d %d",&x,&y,&z,&w);
		int r[3];
		for(int i=0;i<3;i++) r[i]=rui[z][w][i]-rui[z][y-1][i]-rui[x-1][w][i]+rui[x-1][y-1][i];
		printf("%d %d %d\n",r[0],r[1],r[2]);
	}
}

Measured memory_bytes: 13828
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class401
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split().Select(long.Parse).ToArray();

            int count = 0;
            for (int i = 0; i < N; i++)
            {
                while (a[i] % 2 == 0)
                {
                    a[i] /= 2;
                    count++;
                }
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 29360
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);    
    int circle = scan.nextInt();
    int num = scan.nextInt();
    
    List<Integer> length = new ArrayList<>();
    for(int i = 0; i < num; i++) {
      length.add(scan.nextInt());
    }
    scan.close();

    List<Integer> diff = new ArrayList<>();
    
    for(int i = 0; i < length.size() - 1; i++) {
      diff.add(length.get(i + 1) - length.get(i));
    }
      diff.add(circle - length.get(length.size() - 1) + length.get(0));
    
    Collections.sort(diff, Collections.reverseOrder());
    
    System.out.println(circle - diff.get(0));
    
  }
}

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

using i64 = long long;
using P = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()


void solve(long long N, std::vector<long long> A){
    i64 ans = 0;
    rep(i, N){
        ans += A[i] / 2;
        A[i] %= 2;
        if(A[i] == 1){
            if(i != 0 && A[i - 1] == 1){
                A[i] = A[i - 1] = 0;
                ans++;
            }else if(i != N - 1 && A[i + 1] != 0){
                A[i] = 0;
                A[i + 1]--;
                ans++;
            }
        }
    }
    cout << ans << endl;
}

struct IoSetup {
    IoSetup() {
        // cin.tie(nullptr);
        // ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 1024
S = input()

# 最初の状態
if len(S)%2 == 1:
    start = 1
else:
    start = 0
    
# 最後の状態
if S[0] == S[-1]:
    last = 1
else:
    last = 0
    
if (start+last)%2 == 1:
    print("First")
else:
    print("Second")

Measured memory_bytes: 3316
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

struct State {
  int t;
  int x;
  int y;
};

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

  vector<State> v(N + 1, {0, 0, 0});
  for (int i = 1; i <= N; ++i) {
    cin >> v[i].t >> v[i].x >> v[i].y;
  }

  bool found = true;
  for (int i = 1; i <= N; ++i) {
    const auto start = v[i - 1];
    const auto goal = v[i];

    const auto t = goal.t - start.t;
    const auto d = abs(start.x - goal.x) + abs(start.y - goal.y);
    if (d > t || t % 2 != d % 2) {
      found = false;
      break;
    }
  }
  if (found)
    printf("Yes\n");
  else
    printf("No\n");

  return 0;
}


Measured memory_bytes: 1408
import itertools
n,m,q = map(int,input().split())
ab = [0]*q
for i in range(q):
    ab[i] = list(map(int,input().split()))
data = list(range(1,m+1))
ans = 0
a = list(itertools.combinations_with_replacement(data, n))
for s in a:
    score = 0
    for i in range(q):
        if s[ab[i][1]-1] != s[ab[i][0]-1] + ab[i][2]:
            pass
        else:
            score += ab[i][3]
    ans = max(ans,score)
print(ans)

Measured memory_bytes: 85020
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
void qmax(int &x,int y) {if (x<y) x=y;}
void qmin(int &x,int y) {if (x>y) x=y;}
ll read()
{
	char s;
	ll k=0,base=1;
	while((s=getchar())!='-'&&s!=EOF&&!(isdigit(s)));
	if(s==EOF)exit(0);if(s=='-')base=-1,s=getchar();
	while(isdigit(s)){k=k*10+(s^'0');s=getchar();}
	return k*base;
}
void write(int x)
{
	if(x<0){putchar('-');write(-x);}
	else{if(x/10)write(x/10);putchar(x%10+'0');}
}
const int maxn=101000;
const int maxm=201000;
int n,m,s,t,X,Y;
ll Z;
int to[maxm<<1],ne[maxm<<1];
ll w[maxm<<1];
int po[maxn],id;
ll dis[maxn],d[maxn];
const ll mod=1e9+7;
ll dp[maxn],f[maxn];
void add(int x,int y,ll z)
{
	id++;
	to[id]=y;
	w[id]=z;
	ne[id]=po[x];
	po[x]=id;
}
struct node
{
	ll x; 
	int d;
	bool operator < (const node &a) const 
	{
		return x>a.x;
	}
} e;
ll ans;
priority_queue<node> q;
int main()
{
	id=1;
	n=read();m=read();s=read();t=read();
	for (int i=1;i<=m;i++)
	{
		X=read();Y=read();Z=read();
		add(X,Y,Z);add(Y,X,Z);
	}
	memset(dis,0x3f3f3f3f,sizeof(dis));
	dis[s]=0;
	e.d=s;
    e.x=0;
    q.push(e);
    dp[s]=1;
	while (!q.empty())
	{
		e=q.top();q.pop();
		int u=e.d,v;
		if (e.x>dis[u]) continue;
		for (int i=po[u];i;i=ne[i])
		{
			v=to[i];
			if ((dis[u]+w[i]==dis[v]))
			{
				dp[v]+=dp[u];
				if (dp[v]>=mod) dp[v]-=mod;
			}
			if (dis[u]+w[i]<dis[v])
			{
				dis[v]=dis[u]+w[i];
				dp[v]=dp[u];
				e.d=v;
				e.x=dis[v];
				q.push(e);
			}
		
		}
	}
	
	memset(d,0x3f3f3f3f,sizeof(d));
//	cout<<d[0];
	d[t]=0;
	e.d=t;
    e.x=0;
    q.push(e);
    f[t]=1;
	while (!q.empty())
	{
		e=q.top();q.pop();
		int u=e.d,v;
		if (e.x>d[u]) continue;
		for (int i=po[u];i;i=ne[i])
		{
			v=to[i];
			if ((d[u]+w[i]==d[v]))
			{
				f[v]+=f[u];
				if (f[v]>=mod) f[v]-=mod;
			}
			if (d[u]+w[i]<d[v])
			{
				d[v]=d[u]+w[i];
				f[v]=f[u];
				e.d=v;
				e.x=d[v];
				q.push(e);
			}
		
		}
	}	
	
	ans=dp[t]*dp[t]%mod;
//	cout<<ans;
	for (int i=1;i<=n;i++)
	{
		if (dis[i]+d[i]!=dis[t]) continue;
		if (dis[i]==d[i])
		{
			ans-=dp[i]*dp[i]%mod*f[i]%mod*f[i]%mod;
//			cout<<ans<<endl;
			ans%=mod;
		} else
		if (dis[i]*2<dis[t])
		{
			for (int j=po[i];j;j=ne[j])
			{
				if (dis[to[j]]+d[to[j]]!=dis[t]) continue;
				if (dis[i]+w[j]==dis[to[j]]&&dis[i]+w[j]+d[to[j]]==dis[t]&&dis[to[j]]*2>dis[t])
				{
					ans-=dp[i]*f[to[j]]%mod*dp[i]%mod*f[to[j]]%mod;
					ans%=mod;
				}
			}
		}
	}
	ans=(ans%mod+mod)%mod;
	cout<<ans;
	return 0;
} 

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

using namespace std;

inline int popcount(int x) { return __builtin_popcount(x); }

int f(int x) { return x == 0 ? 0 : f(x % popcount(x)) + 1; }

int r[200001][2];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  string s;
  cin >> n >> s;
  int pc = 0;
  for (char c : s) pc += c - '0';
  const int pc0 = pc + 1;
  const int pc1 = pc - 1;

  int xr[2] = {0};
  int k0 = 1;
  int k1 = 1;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == '1') {
      xr[0] += k0;
      xr[0] %= pc0;
      if (pc1 > 0) {
        xr[1] += k1;
        xr[1] %= pc1;
      }
    }
    r[i][0] = k0;
    r[i][1] = k1;
    k0 = (2 * k0) % pc0;
    if (pc1 > 0) {
      k1 = (2 * k1) % pc1;
    }
  }

  for (int i = 0; i < n; i++) {
    int xi = 0;
    if (s[i] == '1') {
      if (pc == 1) {
        cout << 0 << endl;
        continue;
      }
      xi = (xr[1] - r[i][1] + pc1) % pc1;
    } else {
      xi = (xr[0] + r[i][0] + pc0) % pc0;
    }
    cout << f(xi) + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 5320
#include<bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ull unsigned long long
#define ll long long

int main() {
	fastio();
	ull h, w;
	cin >> h >> w;
	if(w == 1 || h == 1) {
		cout << 1 << "\n";
		return 0;
	}
	ull p = h * w;
	if(p & 1)
		cout << p/2 + 1 << "\n";
	else
		cout << p/2 << "\n";
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
 
int main(){
   int a,b,n;
   scanf("%d %d %d", &n,&a,&b);
   if(n*a<=b)
     printf("%d", n*a);
   else 
	printf("%d", b);
   
 
 
  	
	return 0;
 
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
int main()
{
    char s[11];
    cin>>s;
    int len = strlen(s);
    double k;
    int num,diff=0,d=0;
    for(int i = 0; i<=len-3; i++){
        //num = 0,diff = 0;
        //k = 2;
        /*for(int j = i,k=2; j<(j+3),k>=0; j++,k--){
                double p = pow(10,k);
                num+=( (s[j]-48) * p);
                //k--;
        }*/
        //cout<<num<<endl;
        num = ((s[i]-48)*100)+((s[i+1]-48)*10)+((s[i+2]-48)*1);
        //cout<<num<<endl;
        diff = abs(num-753);
        if(i==0)d = diff;
        else d=min(d,diff);
    }
    cout<<d<<endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
S = input()

l = 0
r = 0
for i in range(N):
    if S[i] == ")":
        r -= 1
        if r<0:
            l += 1
            r=0 #rを0に戻す作業
    else:
        r += 1

print("("*l + S + ")"*r)

Measured memory_bytes: 61780
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
import math
a,b,h,m = readInts()
h = h-12 if h>=12 else h
h_ = 30 * h + 30 * m/60
m_ = 360 * m / 60
kakudo = min(abs(m_ - h_), 360 - abs(m_ - h_))
c = pow(a**2 + b**2 - 2*a*b*math.cos(math.radians(kakudo)),.5)
print(c)


Measured memory_bytes: 10688
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

vector<int> ans(100001, -1);
vector<vector<pair<int, int> > > graph(100001);

void solve(int root, int color)
{
	for(int i = 0; i < graph[root].size(); i++){
		int child = graph[root][i].first;
		int w = graph[root][i].second;
		if(ans[child] != -1) continue;
		if(w % 2 == 0){
			ans[child] = color;
			solve(child, color);
		} else {
			ans[child] = (color + 1) % 2;
			solve(child, (color + 1) % 2);
		}
	}
}

int main()
{
	int n;
	cin >> n;
	for(int i = 0; i < n - 1; i++){
		int u, v, w;
		cin >> u >> v >> w;
		u--;
		v--;
		graph[u].push_back(make_pair(v, w));
		graph[v].push_back(make_pair(u, w));
	}
	ans[0] = 0;
	solve(0, 0);
	for(int i = 0; i < n; i++){
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 8448
// Problem : C - Marks
// Contest : AtCoder - M-SOLUTIONS Programming Contest 2020
// URL : https://atcoder.jp/contests/m-solutions2020/tasks/m_solutions2020_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 100005

//Solution

void solve(){
    int n,k;
    cin>>n>>k;
    vi a(n);
    for(int &i : a) cin>>i;
    for(int i=k;i<n;i++){
        int t1 = a[i-k];
        int t2 = a[i];
        if(t2 > t1) cout<<"Yes\n";
        else cout<<"No\n";
    }
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

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

int64_t H,W;
int64_t x,y,depth;
const int64_t H_max = 30;
const int64_t W_max = 30;
char maze[H_max][W_max];
char maze_sub[H_max][W_max];
const int64_t dx[4] = {1,0,-1,0};
const int64_t dy[4] = {0,1,0,-1};

struct Corr{
    int64_t x;
    int64_t y;
    int64_t depth;
};

queue<Corr> que;

int64_t bfs ( int64_t gx, int64_t gy ) {
    while ( !que.empty() ){
        Corr now = que.front(); que.pop();
        x = now.x; y = now.y; depth = now.depth;
        for ( int64_t i = 0; i < 4; ++i){
            Corr next = { x + dx[i], y + dy[i], depth + 1};
            if ( next.x == gx and next.y == gy ){
                return next.depth;
            }
            if ( 0 <= next.x and next.x < H and 0 <= next.y and next.y < W
                and maze[next.x][next.y] == '.') {
                maze[next.x][next.y] = 'x';
                que.push(next);
            }
        }
    }
    return 0;
}

int64_t bfs_main ( int64_t sx, int64_t sy, int64_t gx, int64_t gy){
    while ( !que.empty() ){
        que.pop();
    }
    Corr start = {sx,sy,0};
    que.emplace(start);
    return bfs(gx,gy);
}

int main(){
    cin >> H >> W;
    for ( int i = 0; i < H; ++i ){
        for ( int j = 0; j < W; ++j ){
            cin >> maze_sub[i][j];
        }
    }
    
    int64_t length = 0;
    int64_t ans = 0;
    for ( int64_t sx = 0; sx < H; ++sx){
        for ( int64_t sy = 0; sy < W; ++sy ){
            for ( int64_t gx = 0; gx < H; ++gx ){
                for ( int64_t gy = 0; gy < W; ++gy ){
                    for ( int i = 0; i < H; ++i){
                        for ( int j = 0; j < W; ++j){
                            maze[i][j] = maze_sub[i][j];
                        }
                    }
                    if ( sx == gx and sy == gy ){
                        length = 0;
                    } else if ( maze[gx][gy] == '#' or maze[sx][sy] == '#' ) {
                        length = 0;
                    }
                    else {
                        length = bfs_main(sx,sy,gx,gy);
                    }
                    // cout << sx << sy << gx << gy << length << endl;
                    ans = max(ans,length);
                }
            }
        }
    }
    
    cout << ans << endl;
    return 0;
}


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

#define MAXN 100010
#define ll long long
#define mod 1000000007

using namespace std;

int n, tot, ans;

int a[MAXN];

string s, s1, s2;

bool check(string str) {
	int l = 0, r = str.size() - 1, f = 1;
	while (l < r) {
		if (s[l] != s[r]) f = 0;
		l++; r--;
	}
	return f;
}


int main() {
	int t;
	cin >> s;
	n = s.size();
	s1 = s.substr(0, ((n - 1) / 2));
	s2 = s.substr((n + 3) / 2 - 1, n - 1);
//	cout << s1 << " " << s2 << endl;
	if (check(s) && check(s1) && check(s2)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main()
{
    int a,b,c,sum;
    scanf("%d %d %d",&a,&b,&c);
    
    if(a<=b || a<=c)
    {
        sum = sum + a;
    }
    if(b<=a || b<=c)
    {
        sum = sum + b;
    }
    if(c<=a || c<=b)
    {
        sum = sum + c;
    }
    if(a == b && a == c && b == c)
    {
        sum = sum - c;
    }
    printf("%d",sum);
}

Measured memory_bytes: 1720
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

int main(){

    set<string> dict={"dream","dreamer","erase","eraser"};
    string S;cin>>S;

    int point=0;
    int contain=0;
    string used[S.size()];

    string tmp="";
    bool isPossible=true;
    while(point<S.size()){
        tmp+=S[point];
        if(dict.find(tmp)!=dict.end()){
            used[contain++]=tmp;
            tmp="";
        }

        if(tmp.size()>7||(point==S.size()-1&&tmp!="")){
            if(contain==0){
                cout<<"NO"<<endl;
                return 0;
            }
            point -=tmp.size();
            tmp=used[--contain];
        }
        point++;
    }

    if(tmp!=""){
        cout<<"NO"<<endl;
    }else{
        cout<<"YES"<<endl;
    }


    return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
        return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
        ll n, k;
        cin >> n >> k;

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

        ll x = 0;
        for (int i = 60; i >= 0; i--) {
                if (x + (1LL << i) > k) continue;
                int t = 0;
                rep (j, n) {
                        if ((1LL << i) & a[j]) {
                                t++;
                        }
                }

                if (t < n - t) {
                        x += 1LL << i;
                }
        }

        ll ans = 0;
        rep (i, n) ans += x ^ a[i];

        cout << ans << endl;

        return 0;
}


Measured memory_bytes: 1024
// Aizu Vol-1 0144: Packet Transportation
// 2017.8.9

#include <stdio.h>

#define MAX 100
char visited[MAX + 2];
char cost[MAX + 2][MAX + 2], len[MAX + 2];
char Q[2][MAX + 2], end[2];
int n;

int search(int s, int g, int v);

int main(void)
{
	int r, k, t;
	int P, s, d, v;
	int i, j;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d%d", &r, &k), len[r] = k;
		for (j = 0; j < k; j++) scanf("%d", &t), cost[r][j] = t;
	}
	scanf("%d", &P);
	for (i = 0; i < P; i++) {
		scanf("%d%d%d", &s, &d, &v);
		if (s == d) puts(v >= 1 ? "1" : "NA");
		else if (v <= 1) puts("NA");
		else {
			if ((j = search(s, d, v)) >= 0) printf("%d\n", j);
			else puts("NA");
		}
	}
	return 0;
}

int search(int s, int g, int lim)
{
	int i, k, k1, k2, step;
	int e, a, b;

	for (i = 1; i <= n; i++) visited[i] = 0;
	Q[0][0] = s, end[0] = 1, visited[s] = 1, step = 2;
	for (k1 = 0, k2 = 1; ; k2 = k1, k1 = !k2) {
		for (e = 0, i = end[k1] - 1; i >= 0; i--) {
			a = Q[k1][i], k = len[a];
			while (k-- > 0) {
				if ((b = cost[a][k]) == g) return step;
				if (!visited[b]) Q[k2][e++] = b, visited[b] = 1;
			}
		}
		if (e == 0) return -1;
		end[k2] = e;
		if (++step > lim) return -1;
	}
}

Measured memory_bytes: 620
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

// solve
void dump(vector<string> vec){
  rep(i, vec.size()){
    cout << vec[i];
    if(i + 1 == vec.size())cout << endl;
    else cout << " ";
  }
}

bool comp(string &a, string &b){
  return a[1] < b[1];
}

bool eq(string &a, string &b){
  return a[1] == b[1];
}

int main(int argc, char const* argv[])
{
  int n;
  cin >> n;
  vector<string> a(n);
  rep(i, n)cin >> a[i];
  unordered_map<string, int> mp;
  rep(i, n)mp[a[i]] = i;

  vector<string> b = a, c = a;
  rep(i, n){
    for(int j = n - 1; j >= i + 1; j--){
      if(comp(b[j], b[j-1]))swap(b[j], b[j-1]);
    }
  }
  dump(b);
  bool res = true;
  rep(i, n){
    FOR(j, i+1, n){
      if(eq(b[i], b[j]) && mp[b[i]] > mp[b[j]])res = false;
    }
  }
  if(res)cout << "Stable" << endl;
  else cout << "Not stable" << endl;

  rep(i, n){
    int minj = i;
    FOR(j, i, n){
      if(comp(c[j], c[minj]))minj = j;
    }
    swap(c[i] ,c[minj]);
  }
  dump(c);

  res = true;
  rep(i, n){
    FOR(j, i+1, n){
      if(eq(c[i], c[j]) && mp[c[i]] > mp[c[j]])res = false;
    }
  }
  if(res)cout << "Stable" << endl;
  else cout << "Not stable" << endl;

	return 0;
}



Measured memory_bytes: 3224
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>
 
#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second
 
const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;
int n;
int a[102];
void plot() {
    rep(i,n) cout<<(i==0?"":" ")<<a[i];
    cout<<endl;
}
void insert_sort() {
    for(int i=1;i<n;i++) {
        plot();
        int v=a[i];
        int j=i-1;
        while(j>=0 && a[j] > v) {
            a[j+1]=a[j];
            j--;
        }
        a[j+1]=v;
    }
    plot();
 
}
 
int main() {
    cin>>n;
    rep(i,n) cin>>a[i];
    insert_sort();
    return 0;
}

Measured memory_bytes: 1160
import sys
readline = sys.stdin.readline
DIV = 10 ** 9 + 7
N,M = map(int,readline().split())
A = sorted(list(map(int,readline().split())))
B = sorted(list(map(int,readline().split())))
setA = set(A)
setB = set(B)
if len(setA) != len(A) or len(setB) != len(B):
  print(0)
  exit(0)

import bisect
ans = 1
for i in range(N * M, 0, -1):
  if i in setA and i in setB:
    ans *= 1
  elif i in setA and i not in setB: # 片方だけに現れる
    # Aに現れ、Bには現れないため、「Bに存在する、iより大きな数」の個数だけ存在する
    ans *= (M - bisect.bisect_left(B,i))
    ans %= DIV
  elif i not in setA and i in setB: # 片方だけに現れる
    ans *= (N - bisect.bisect_left(A,i))
    ans %= DIV
  else: # どちらにも表れない
    # 「Bに存在するiより大きな数の個数」と「Aに存在するiより大きな数の個数」の積
    # ただし、今までに既に埋めた数は除外するため、(N * M - i)を引く
    b = (M - bisect.bisect_left(B,i))
    a = (N - bisect.bisect_left(A,i))
    ans *= ((a * b - (N * M - i)) % DIV)
    ans %= DIV
    
print(ans)

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

int main(){
    int A,B;
	cin >> A >> B;
	
	if(A>=13){
		cout << B;
		}
	if(6<=A && A <= 12){
		cout << B/2;
		}
		
	if(A<=5){
		cout <<0;
		}	
	cout << endl;
		
	}
	


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

int main() {
 	int n;
  char s1,s2;
  int ans = 0;
  cin >> n;
  for(int i=0; i!=n; i++){
    cin >> s2;
    if(s2 != s1){
      s1 = s2;
      ans += 1;
    }else{
      continue;
    }
  }
  cout << ans << '\n';
	return 0;
}


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

int main() {
    long long N,K,S;
    long long ans=0;
    cin >> N >> K >> S;

    vector<long long> a(N);
    for (int i = 0; i < N; ++i){
        if(i<K) a[i]=S;
        else{
            if(S=1e9) a[i]=S-1;
            else a[i]=S+1;
        }
    }

    for (int i = 0; i < N-1; ++i) cout << a[i] << ' ';
    cout << a[N-1] << endl;
    //cout << res << endl;

}

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

string ans ="";
void func (int x,int y){
	for(int i=0;i<x;i++)ans = ans + "R";
			for(int i=0;i<y;i++)ans = ans + "U";
			for(int i=0;i<x;i++)ans = ans + "L";
			for(int i=0;i<y;i++)ans = ans + "D";
			ans = ans + "D";
			for(int i=0;i<x+1;i++)ans = ans + "R";
			for(int i=0;i<y+1;i++)ans = ans + "U";
			ans = ans + "L";
			ans = ans + "U";
			for(int i=0;i<x+1;i++)ans = ans + "L";
			for(int i=0;i<y+1;i++)ans = ans + "D";
			ans = ans + "R";
}
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int sx,sy,tx,ty;
	cin >> sx >> sy >> tx >> ty;
	tx-=sx;
	ty-=sy;
	sx = sy = 0;
	int x = tx;
	int y = ty;
	int flag = -1;
	if(x>=0 && y>=0)flag = 1;
	else if(x<=0&&y>=0)flag = 2;
	else if(x<=0&&y<=0)flag = 3;
	else if(x>=0&&y<=0)flag = 4;
	func(abs(x),abs(y));
	if(flag==1)cout << ans << endl;
	else if(flag==2){
		for(int i=0;i<ans.size();i++){
			if(ans[i]=='R')cout << "L";
			else if(ans[i]=='L')cout << "R";
			else cout << ans[i];
		}
		cout << endl;
	}else if(flag==3){
		for(int i=0;i<ans.size();i++){
			if(ans[i]=='R')cout << "L";
			else if(ans[i]=='L')cout << "R";
			else if(ans[i]=='U')cout << "D";
			else if(ans[i]=='D')cout << "U";
			else cout << ans[i];
		}
		cout << endl;
	}else if(flag==4){
		for(int i=0;i<ans.size();i++){
			if(ans[i]=='U')cout << "D";
			else if(ans[i]=='D')cout << "U";
			else cout << ans[i];
		}
		cout << endl;
	}
}

Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#define REP(i, a, b) for (auto i = (a); i < (b); ++i)
using namespace std;

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	int n; cin >> n;
	int l[n]; REP(i, 0, n) cin >> l[i];
	sort(l, l + n);
	int ans = 0;
	REP(i, 0, n)
		REP(j, i + 1, n)
			ans += lower_bound(l, l + n, l[i] + l[j]) - l - j - 1;
	cout << ans;
}

Measured memory_bytes: 256