akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
n,k = list(map(int,input().split()))
s = input()
rl_cnt = s.count("RL")
ret = 0
s0 = s[0]
sn = s[-1]
if s0==sn:
    ret=n-1-2*max(0,rl_cnt-k)
elif s0=="L" and sn=="R":
    if k<=rl_cnt:
        ret=n-2-2*(rl_cnt-k)
    else:
        ret=n-1
else:
    if k<rl_cnt:
        ret = n - 2*(rl_cnt-k)
    else:
        ret = n-1
print(ret)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int N;
	map<int,bool>layer;
	int D[101],i;
	cin>>N;
	for(i=0;i<N;i++)
	{
		cin>>D[i];
		layer[D[i]]=false;
	}
	int count=0;
	for(i=0;i<N;i++)
	{
		if(layer[D[i]]==false)
		{
			count+=1;
			layer[D[i]]=true;
		}
		
	}cout<<count<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    
    int N = sc.nextInt();
    int[] a = new int[N];

    long sum = 0;

    for (int i = 0; i < N; i++) {
      a[i] = sc.nextInt();
      sum += a[i];
    }

    sc.close();
    
    long min = Math.abs(sum - (2 * a[0]));
    long x = a[0];

    for (int i = 1; i < N-1; i++) {
      x += a[i];
      min = Math.min(min, Math.abs(sum - (2 * x)));
    }

    System.out.println(min);

  }

}


Measured memory_bytes: 84896
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    s = S()
    s.sort()
    if s == ["a", "b", "c"]:
        print("Yes")
    else:
        print("No")
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()


Measured memory_bytes: 39024
#include<iostream>
#include <vector>
#include <algorithm>
#include "math.h"
using namespace std;

int main()
{
  int A, B, K;
  cin >> A >> B >> K;

  if (B-A <= 2 * K - 1) {
    for (int i = A; i <=B ; i++) {
      std::cout << i << std::endl;
    }
  } else {
    for (int i = A; i <A+K ; i++) {
      std::cout << i << std::endl;
    }
    for (int i = B-K+1; i <=B ; i++) {
      std::cout << i << std::endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main{

	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int M = scan.nextInt();
		int[] A = new int[N];
		int sum = 0;
		for(int i=0;i<N;i++) {
			A[i] = scan.nextInt();
			sum += A[i];
		}
		int judge = sum/(4*M);
		boolean judgeF = true;
		if(sum%(4*M)>0) {
			judgeF = false;
		}
		Arrays.sort(A);
		String result = "Yes";
		int count = 0;

		for(int j=N-1;count<M;j--) {
			if(judgeF){
				if(A[j]<judge) {
					result = "No";
				}
			}else {
				if(A[j]<=judge) {
					result = "No";
				}
			}
			count++;
		}

		System.out.println(result);

	}
}

Measured memory_bytes: 23892
def max(a, b, c)
  a < b ? (b < c ? c : b) : (a < c ? c : a)
end
def min(a, b, c)
  a > b ? (b > c ? c : b) : (a > c ? c : a)
end

H, W = gets.split.map(&:to_i)



results = []
if H == 2

elsif H % 3 == 0
  results.push(0)
else
  results.push(((H / 3 + 1) * W) - ((H / 3) * W))
end

if W == 2

elsif W % 3 == 0
  results.push(0)
else
  results.push(((W / 3 + 1) * H) - ((W / 3) * H))
end

(((H + 1) / 4)..((H + 1) / 2)).each do |h|
  pieces = [h * W]
  pieces.push (H - h) * (W / 2)
  pieces.push (H - h) * ((W + 1) / 2)
  results.push max(pieces[0], pieces[1], pieces[2]) - min(pieces[0], pieces[1], pieces[2])
end

(((W + 1) / 4)..((W + 1) / 2)).each do |h|
  pieces = [h * H]
  pieces.push (W - h) * (H / 2)
  pieces.push (W - h) * ((H + 1) / 2)
  results.push max(pieces[0], pieces[1], pieces[2]) - min(pieces[0], pieces[1], pieces[2])
end

puts results.min

Measured memory_bytes: 2300
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<cassert>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<deque>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<iomanip>
#include<utility>
#include<functional>
using namespace std;
const int MOD=1000000007;
int dp[105][4][4][4];
int n;
int ans;
//0 A ; 1 G ; 2 C ; 3 T
//AGC 012
//ACG 021
//GAC 102
//AXGC 0X12
//ACXG 01X2
int main()
{
	cin>>n;
	for(int a2=0;a2<4;a2++)
		for(int a3=0;a3<4;a3++)
			for(int a4=0;a4<4;a4++)
				if(!(a2==0&&a3==1&&a4==2)&&!(a2==0&&a3==2&&a4==1)&&!(a2==1&&a3==0&&a4==2))
					dp[3][a2][a3][a4]=1;
	for(int i=4;i<=n;i++)
		for(int a1=0;a1<4;a1++)
			for(int a2=0;a2<4;a2++)
				for(int a3=0;a3<4;a3++)
					for(int a4=0;a4<4;a4++)
						if(!(a2==0&&a3==1&&a4==2)&&!(a2==0&&a3==2&&a4==1)&&!(a2==1&&a3==0&&a4==2)&&!(a1==0&&a3==1&&a4==2)&&!(a1==0&&a2==1&&a4==2))
							dp[i][a2][a3][a4]=(dp[i][a2][a3][a4]+dp[i-1][a1][a2][a3])%MOD;
	for(int a2=0;a2<4;a2++)
		for(int a3=0;a3<4;a3++)
			for(int a4=0;a4<4;a4++)
				ans=(ans+dp[n][a2][a3][a4])%MOD;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=998244353;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

const int M=1000001;
int n;
vi a;
bool b[M];

int main(){
	cin>>n;
	a=vi(n);
	map<int,int> mp;
	for(auto &i:a){
		cin>>i;
		mp[i]++;
	}
	sort(a.begin(),a.end());
	int t=0;
	for(auto i:a){
		if(mp[i]==1&&!b[i]) t++;
		if(!b[i]){
			int x=i;
			while(x<M){
				b[x]=1;
				x+=i;
			}
		}
	}
	cout<<t<<endl;
}

Measured memory_bytes: 14192
//
// Created by yamunaku on 2019/09/07.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

const ld pi=3.14159265358979323846;

int main(){
    int n;
    cin >> n;
    vector<ld> x(n),y(n);
    rep(i,n) cin >> x[i] >> y[i];
    vector<ld> rad(n);
    rep(i,n){
        rad[i]=atan2(y[i],x[i]);
    }
    vector<int> idx(n);
    iota(all(idx), 0);
    sort(all(idx),[&](int l, int r){
        return rad[l]<rad[r];
    });
    vector<ld> nx(2*n),ny(2*n);
    vector<ld> nrad(2*n);
    rep(i,2*n){
        nx[i]=x[idx[i%n]];
        ny[i]=y[idx[i%n]];
        nrad[i]=rad[idx[i%n]]+(i/n)*2*pi;
//        cout << nx[i] SP ny[i] SP nrad[i] << endl;
    }
    int r=0;
    ld ans=0;
    ld xx=0,yy=0;
    rep(i,n){
        while(r<i+n){
            if(nrad[r]-nrad[i]>pi) break;
            xx+=nx[r];
            yy+=ny[r];
            ans=max(ans,sqrt(xx*xx+yy*yy));
            r++;
        }
        ans=max(ans,sqrt(xx*xx+yy*yy));
        xx-=nx[i];
        yy-=ny[i];
        r--;
        xx-=nx[r];
        yy-=ny[r];
    }
    CST(15);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    string N; cin >> N;
    int K; cin >> K;
    
    int n = (int)N.length();
    
    // dp[i][j][k] := i番目　(j = 1 必ず下回る) k 0でない数
    auto dp = make_v<ll>(n+1,2,K+1);
    
    
    for(int x = 1; x < N[0]-'0'; x++){
        dp[1][1][1] += 1;
    }
    dp[1][0][1] += 1;
    
    // dp[0][1][0] += 1;
    for(int i = 1; i < n; i++){
        for(int j = 0; j < 2;j++){
            for(int k = 0; k <= K;k++){
                if(dp[i][j][k] == 0) continue;
                int lim = j?9:N[i]-'0';
                for(int x = 0; x <= lim; x++){
                    if(x != 0 && k == K) continue;
                    dp[i+1][j|(x!=lim)][k+(x!=0)] += dp[i][j][k];
                }
            }
        }
        
        for(int x = 1; x <= 9; x++){
            dp[i+1][1][1] += 1;
        }
    }
    
    res = dp[n][0][K] + dp[n][1][K];
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 384
while True:
    lst = list(map(int, input().split()))
    n, x = lst[0], lst[1]
    count = 0

    if n == 0 and x == 0:
        break

    for i in range(1,n+1):
        for j in range(i+1,n+1):
            for k in range(j+1,n+1):
                if i+j+k == x:
                    count = count +1
                    break
            if i+j >= x:
                break
        
        if i >=x:
            break

    print(count)


Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    int x;
    cin >> x;
    if (x < 1200)cout << "ABC" << endl;
    else cout << "ARC" << endl;
}

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

int main() {
	int n;
	cin >> n;
	vector<int> x(n), y(n);
	rep(i, n) cin >> x[i] >> y[i];
	vector<int> p(n);
	rep(i, n) p[i] = i;
	double tot = 0;
	int cnt = 0;
	do {
		rep(i, n - 1) {
			int dx = x[p[i + 1]] - x[p[i]];
			int dy = y[p[i + 1]] - y[p[i]];
			double s = sqrt(dx * dx + dy * dy);
			tot += s;
		}
		cnt++;
	} while (next_permutation(p.begin(), p.end()));
	printf("%.10f\n", tot / cnt);
	return 0;
}

Measured memory_bytes: 3848
n, k, *a = map(int, open(0).read().split())
b = [0]*49
for i in a:
    c = bin(i)[::-1][:-2]
    for j in range(len(c)):
        b[j] += int(c[j])
d = [int(i < n-i) for i in b]
*e, = bin(k)[2:]
*e, = map(int, e)
d = d[:len(e)][::-1]
for i in range(len(e)):
    d[i] = d[i]&e[i]
    if d[i] < e[i]: break
*d, = map(str, d)
f = int(''.join(d), 2)
print(sum(f^i for i in a))

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

#define N 2999

int main(void){
  double dp[N+1][N+3]; // dp[i][j] = i枚降ってj枚オモテの確率
  int n;
  double p[N+1], ans;
  
  cin >> n;
  for (int i=1; i<=n; i++){
    cin >> p[i];
  }
  
  dp[0][0] = 1.; // 0枚降ったら必ずオモテは0枚
  for (int i=1; i<=n; i++){
    for (int j=0; j<=i; j++){
      dp[i][j] = dp[i-1][j]*(1-p[i]); // 今出たのはウラ
      if (j) dp[i][j] += dp[i-1][j-1]*p[i]; // 今出たのはオモテ
    }
  }
  
/*
  for (int i=1; i<=n; i++){
    for (int j=0; j<=i; j++){
      cout << dp[i][j] << " ";
    } cout << endl;
  }
*/
  ans = 0;
  for (int i=n/2+1; i<=n; i++) ans += dp[n][i];
  cout << setprecision(12) << ans << endl;
  return 0;
}


Measured memory_bytes: 70400
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int stones[n],memo[n]; 
    for(int i = 0 ; i< n ; i++) {
        cin >> stones[i];
        memo[i] = 0;    
    }
    memo[0] = 0;
    memo[1] = abs(stones[1]-stones[0]);
    memo[2] = abs(stones[2]-stones[0]);
    for(int i =3; i<n; i++){
        memo[i] = min(memo[i-1]+abs(stones[i] - stones[i-1]), memo[i-2]+abs(stones[i]-stones[i-2]));
    }
    cout << memo[n-1] << endl;
    
    return 0;

}


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

int d[50][3001];
int main() {
	int n, m, s;
	while (scanf("%d%d%d", &n, &m, &s), n *= n) {
		memset(d, 0, sizeof(d));
		d[0][0] = 1;
		for (int i = 1; i <= m; i++)
			for (int j = n; j > 0; j--)
				for (int k = i; k <= s; k++)
					(d[j][k] += d[j - 1][k - i]) %= 100000;
		printf("%d\n", d[n][s]);
	}
}

Measured memory_bytes: 3736
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};




int main(){
    int n;cin >> n;
    vector<int> a(n);
    bool t=true,f=true;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if(a[i]>0) t=false;
        if(a[i]<0) f=false;
    }
    sort(ALL(a));
    int mx=a[n-1],mi=a[0];
    if(n==2){
        cout << mx - mi << endl;
        cout << mx << " " << mi << endl;
        return 0;
    }
    vector<P> ans;
    if(f){
        ans.pb(mp(mi,mx));
        mi = mi-mx;
        for (int i = 1; i < n-2; i++) {
            ans.pb(mp(mi,a[i]));
            mi-=a[i];
        }
        ans.pb(mp(a[n-2],mi));
        cout << a[n-2]-mi << endl;
    }
    else if(t){
        ans.pb(mp(mx,mi));
        mx = mx-mi;
        for (int i = 1; i < n-2; i++) {
            ans.pb(mp(mx,a[i]));
            mx-=a[i];
        }
        ans.pb(mp(mx,a[n-2]));
        cout << mx-a[n-2] << endl;
    }
    else{
        int k = 1;
        for (; k < n-1; k++) {
            if(a[k]>0) break;
            ans.pb(mp(mx,a[k]));
            mx-=a[k];
        }
        for (; k < n-1; k++) {
            ans.pb(mp(mi,a[k]));
            mi-=a[k];
        }
        cout << mx - mi << endl;
        ans.pb(mp(mx,mi));
    }
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i].fs << " " << ans[i].sc << endl;
    }
    return 0;
}


Measured memory_bytes: 3952
#include<bits/stdc++.h>
#define ll long long

using namespace std;

int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

int main(){
    string S; cin >> S;
    vector<ll> cnt(2019, 0);
    ll sum = 0;
    ll d = 1;
    ll ans = 0;

    cnt[0]++;

    for (ll i = S.length(); i > 0; i--){
        sum += (S[i-1] - '0')*d;
        sum %= 2019;
        d *= 10;
        d %= 2019;
        cnt[sum]++;
    }

    for (ll i = 0; i < cnt.size(); i++){
        ans += cnt[i]*(cnt[i]-1) / 2;
    }

    cout << ans << endl;

    return 0;

}


Measured memory_bytes: 3748
#include <bits/stdc++.h>
#define ll long long
using namespace std ;
#define MAX 800
const int N = 1e6 + 5 ;
int arr[ N ] ;
int tempSize = 0 ;
int multiply(int x, int res[], int res_size);
void factorial(int n)
{
    int res[MAX];
    int res_size = 1;
    res[0] = 1;
int x = 0 ;
    for (int x=2; x<=n; x++)
        res_size = multiply(x, res, res_size);
        tempSize = res_size ;
    for (int i=res_size-1; i>=0; i--)
    {
      arr[ x++ ] = res[ i ] ;
    }

}
int multiply(int x, int res[], int res_size)
{
    int carry = 0;

    for (int i=0; i<res_size; i++)
    {
        int prod = res[i] * x + carry;
        res[i] = prod % 10;

        carry  = prod/10;
    }
    while (carry)
    {
        res[res_size] = carry%10;
        carry = carry/10;
        res_size++;
    }
    return res_size;
}
string toString(int res[], int res_size)
{
    string number = " ";
    for(int i = 0; i < res_size - 1; i++)
    {
        number[i] = res[i];
    }
    return number;
}
ll mod(string num, ll a)
{
    ll res = 0;
    for (ll i = 0; i < num.length(); i++)
         res = (res*10LL + (ll)num[i] - '0') % a;
    return res;
}

unsigned long long Factorial(int n)
{
    const unsigned int M = 1000000007;

    unsigned long long f = 1;
    for (int i = 1; i <= n; i++)
        f = (f*i) % M;

    return f;
}

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

    cout << Factorial(n) ;



}


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

signed main() {
  int N;
  cin >> N;
  vector<int> v;
  int sum = 0;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    sum += a;
    if (a > b) v.push_back(b);
  }

  if (v.size() == 0) {
    cout << 0 << endl;
    return 0;
  }

  sort(v.begin(), v.end());

  cout << sum - v[0] << endl;
  return 0;
}


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

typedef long long lint;

int main(){
    lint N;
    cin >> N;
    lint *A,*B;
    A=new lint[N];
    B=new lint[N];
    for(int i=0;i<N;i++) cin >> A[i];
    for(int i=0;i<N;i++) cin >> B[i];

    lint X=0;
    for(int i=0;i<=28;i++){
        lint *mA;
        lint *mB;
        mA=new lint[N];
        mB=new lint[N];
        for(int j=0;j<N;j++){
            mA[j]=A[j]%(2<<i);
            mB[j]=B[j]%(2<<i);
        }
        sort(mB,mB+N);
        lint cnt=0;
        for(int j=0;j<N;j++){
            auto al=lower_bound(mB,mB+N,(1<<i)-mA[j]);
            auto ar=upper_bound(mB,mB+N,(2<<i)-mA[j]-1);
            cnt+=distance(al,ar);

            auto bl=lower_bound(mB,mB+N,(3<<i)-mA[j]);
            auto br=upper_bound(mB,mB+N,(4<<i)-mA[j]-1);
            cnt+=distance(bl,br);
        }
        X+=(cnt%2)<<i;
        delete[] mA,mB;
    }

    cout << X << endl;
    delete[] A,B;
    return 0;
}

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

using ll = long long;

const ll MOD = 1e9 + 7;

int main() {
    int N, M;
    cin >> N >> M;
    vector<ll> A(N + 1, 0), B(M + 1, 0);
    rep(i, N) cin >> A[i];
    rep(i, M) cin >> B[i];
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    ll ans = 1;
    int i = 0, j = 0;
    for (int k = N * M; k > 0; k--) {
        //cout << i << j << k << ans << endl;
        if (A[N - i] > k || B[M - j] > k) {
            cout << 0 << endl;
            return 0;
        }
        if (A[N - i] == k) {
            i++;
            if (B[M - j] == k) {
                j++;
                continue;
            } else {
                ans = (ans * j) % MOD;
            }
        } else {
            if (B[M - j] == k) {
                j++;
                ans = (ans * i) % MOD;
            } else {
                ll rest = i * j - (N * M - k);
                if (rest <= 0) {
                    cout << 0 << endl;
                    return 0;
                }
                ans = (ans * rest) % MOD;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using piii = pair<int, pair<int, int>>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;

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

    int K, N;
    cin >> K >> N;

    vector<int> A(2 * N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        A[N + i] = A[i] + K;
    }

    int ans = 1e9;
    for (int i = 0; i < N; ++i)
        ans = min(ans, A[i + N - 1] - A[i]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>

std::vector<int> vec, vec2, vec3;
int n;
int tmp;
int main() {
  std::cin >> n;
  vec.assign(n+1, 0);
  vec2.assign(n+1, 0);
  for (int i = 1; i <= n; i++) {
    std::cin >> tmp;
    vec[i] = vec[i-1] + tmp;
  }
   for (int i = 1; i <= n; i++) {
    std::cin >> tmp;
    vec2[i] = vec2[i-1] + tmp;
   }
  int t = 0;
  for (int i = 1; i <= n; i++) {
    t = vec[i] + (vec2[n] - vec2[i-1]);
    vec3.push_back(t);
  }
  std::cout << *std::max_element(vec3.begin(), vec3.end()) << std::endl;
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (long long i = 0; i < (long long)(n); ++i)
using ll = long long;
using P = pair<long long, long long>;
using MATRIX = vector< vector<ll> >;

long long gcd(long long a, long long b) {
  if(b == 0) return a;
  long long d;
  a = a % b;
  swap(a, b);
  d = gcd(a, b);
  return d;
}

int main() {
  long long A, B, N;
  cin >> A >> B >> N;
  long long d = gcd(A, B);
  if(N >= B) {
    cout << (A * (B-1)) / B << endl;
    return 0;
  }
  long long ans = A * N / B;
  ans %= A;
  cout << ans << endl;

  return 0;
}

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

int main(void){
    
    int M,N,X;
    cin >> N >> M >> X;
    int C[N],A[N][M];
    
    for(int i = 0; i < N;i++){
        cin >> C[i];
        for(int j = 0; j < M;j++)cin >> A[i][j];
    }
    
    // for(int i = 0; i < N;i++){
    //     cout << C[i]<<" ";
    //     for(int j = 0; j < M;j++)cout << A[i][j]<<" ";
    //     cout <<"a"<<endl;
    // }
    
    
    
    int F[M];
    int sum;
    int ans = INT_MAX;
    bool flag;
    for(int bit = 1; bit < (1<<N);bit++){
        for(int j = 0; j < M;j++){F[j] = 0;}
        sum = 0;
        for(int i = 0; i < N;i++){
            
            if(bit & (1<<i)){
//                cout << i<<" ";
                sum += C[i];
                for(int j = 0; j < M;j++){
                    F[j]+= A[i][j];       
                }
            }
        }
        // cout <<endl;
        // cout <<"#############"<<endl;
        flag = true;
        for(int j = 0; j < M;j++){
            //cout << F[j]<<" ";
            if(F[j] < X)flag = false;       
        }
        // cout <<endl;
        // cout <<"#############"<<endl;
        
        if(flag)ans = min(ans,sum);
        
    }
    
    if(ans != INT_MAX)cout << ans <<endl;
    else cout << -1 <<endl;

}


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

int main() {
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int max_f = 0;
	int max_s = 0;
	int max_n = 0;
	for (int i = 0; i < n; i++) {
		if (max_f < a[i]) {
			max_s = max_f;
			max_f = a[i];
			max_n = i;
		} else if (max_s < a[i]) {
			max_s = a[i];
		}
	}
	for (int i = 0; i < n; i++) {
		if (max_n == i) {
			cout << max_s << endl;
		} else {
			cout << max_f << endl;
		}
	}
	return 0;
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  set<ll> a;
  for (int i = 0; i < n; i++) {
    ll s;
    cin >> s;
    a.insert(s);
  }
  if (a.size() == n) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    double d=0,s=0,x1=0,y1=0;
    cin>>n;
    int x[n],y[n];
    for(int i=0;i<n;i++)
        cin>>x[i]>>y[i];
    vector<double>v;
    for(int i=0;i<n-1;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            x1=(double)pow((x[i]-x[j]),2);
            y1=(double)pow((y[i]-y[j]),2);
            d=sqrt(x1+y1);
            v.push_back(d);
        }
    }
    for(int i=0;i<v.size();i++)
    {
        v[i]=v[i]*2/(double)n;
        s+=v[i];
    }
    cout<<fixed<<setprecision(10)<<s<<endl;
    return 0;
}

Measured memory_bytes: 3748
#include<bits/stdc++.h>
const int maxn = 22;
int n, k;
int f[1 << maxn];
int*g[1 << maxn];
inline void * newint(int size) {
	static char buf[4 * maxn << maxn], * end = buf + sizeof buf;
	if(end <= buf) exit(1);
	return end -= size;
}
inline int w(int x) {
	int ret = 0;
	for(int i = 0;i < 20;++i) if(x >> i & 1) ret |= 1 << 20 - i;
	return ret;
}
int main() {
	std::ios::sync_with_stdio(false), std::cin.tie(0);
	for(int i = 1;i < 1 << 21;++i) g[i] = (int*) newint(4 << 21 - std::__lg(i));
	std::cin >> n >> k;
	for(int i = 0;i <= n;++i) {
		for(int j = 0;j < 1 << i;++j) {
			char ch; std::cin >> ch;
			g[1][j | 1 << i] = ch & 1;
		}
	}
	int ans = 1;
	for(int i = 1;i < 1 << n + 1;++i) {
		int sum = 0;
		for(int j = 1;j < 1 << n - std::__lg(i) + 1;++j) {
			sum += g[i][j];
			if(j & j - 1) g[i << 1 | 1][j >> __builtin_ctz(j) + 1] += g[i][j];
			if(j & j + 1) g[i << 1][j >> __builtin_ctz(~j) + 1] += g[i][j];
		}
		if(sum >= k && (std::__lg(i) > std::__lg(ans) || w(i) < w(ans)))
			ans = i;
	}
	while(ans != 1)
		std::cout.put(ans % 2 | 48), ans >>= 1;
}


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

vector<long long> Gauss(vector<long long> a) {
	sort(a.begin(), a.end());
	for (int i = 59; i >= 0; i--) {
		int pos = 0;
		for (int j = 0; j < a.size(); j++) {
			if (a[j] < (1LL << (i + 1))) { pos = j; }
		}
		for (int j = pos - 1; j >= 0; j--) {
			if (a[j] >= (1LL << i)) a[j] ^= a[pos];
		}
		sort(a.begin(), a.end());
	}
	vector<long long> b = a;
	b.erase(unique(b.begin(), b.end()), b.end());
	return b;
}

int main() {
	// 入力
	long long N, e = 0; cin >> N;
	vector<long long> a(N, 0);
	for (int i = 0; i < N; i++) { cin >> a[i]; e ^= a[i]; }

	// ビットを並び替える
	vector<long long> F;
	for (int i = 0; i < 60; i++) { if ((e & (1LL << i)) != 0) F.push_back(i); }
	for (int i = 0; i < 60; i++) { if ((e & (1LL << i)) == 0) F.push_back(i); }

	for (int i = 0; i < N; i++) {
		long long r = 0;
		for (int j = 0; j < 60; j++) { if ((a[i] & (1LL << F[j])) != 0) r += (1LL << j); }
		a[i] = r;
	}

	// 貪欲法
	vector<long long> b = Gauss(a);
	long long c = 0;
	for (int i = b.size() - 1; i >= 0; i--) {
		c = max(c, c^b[i]);
	}

	// 最後
	long long ans = 0;
	for (int i = 0; i < 60; i++) {
		if ((e & (1LL << F[i])) != 0) {
			ans += (1LL << F[i]);
		}
		else {
			if ((c & (1LL << i)) != 0) ans += (2LL << F[i]);
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  string S,T="",U="";
  int Q,t,F,cnt=0;
  char C;
  cin >> S >> Q;
  for(int i=0;i<Q;i++){
    cin >> t;
    if(t==1){
      cnt++;
    }else{
      cin >> F >> C;
      if((cnt%2==0&&F==1)||(cnt%2==1&&F==2)){
        T=C+T;
      }else{
        U=C+U;
      }
    }
  }
  if(cnt%2==1){
    for(int j=0;j<S.size()/2;j++){
      swap(S.at(j),S.at(S.size()-j-1));
    }
    for(int j=0;j<T.size()/2;j++){
      swap(T.at(j),T.at(T.size()-j-1));
    }
    cout << U+S+T << endl;
  }else{
    for(int j=0;j<U.size()/2;j++){
      swap(U.at(j),U.at(U.size()-j-1));
    }
    cout << T+S+U << endl;
  }
}

Measured memory_bytes: 1396
k = int(input())
L = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(L[k-1])

Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;
int main(void){
  int n, d;
  cin >> n >> d;
  vector<vector<int>> dot(n, vector<int>(d));
  for(int i = 0; i < n; i++){
    for(int j = 0; j < d; j++){
      cin >> dot.at(i).at(j);
    }
  }
  int num = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      if(i!=j){
      int kyori = 0;
      for(int k = 0; k < d; k++){
        kyori += pow(dot.at(i).at(k) - dot.at(j).at(k), 2);
        }
        //cout << kyori << " ";
        double dist = sqrt(kyori);
        kyori = (int)sqrt(kyori);
        //cout << dist << " is dist(double)\n " << kyori << " is kyori(int)\n";
        if( !(dist - kyori)*1000){
          num++;
        }
      }
      else{
      }
    }
    //cout << endl;
  }
  cout << num/2 << endl;
    


  return 0;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
// using namespace atcoder;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000000000000ll
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
//#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
/* clang-format on */

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n;
  cin >> n;
  vector<ll> a(n);
  REP(i, n) cin >> a[i];
  ll cn = 0, c0 = 0;
  REP(i, n) {
    if (a[i] < 0) cn++;
    if (a[i] == 0) c0++;
  }
  ll ans = 0;
  if (c0 > 0 || cn % 2 == 0) {
    REP(i, n) ans += abs(a[i]);
  } else {
    REP(i, n) a[i] = abs(a[i]);
    ans -= 2 * *min_element(ALL(a));
    REP(i, n) ans += a[i];
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3940
#include<stdio.h>
#include<stdlib.h>

int main(void){
  int n,i;
  int *a,*b,*c;
  scanf("%d",&n);
  a=malloc(sizeof(int)*n);
  b=malloc(sizeof(int)*n);
  c=malloc(sizeof(int)*n);
  for(i=0;i<n;i++){
    scanf("%d %d %d",&a[i],&b[i],&c[i]);
  }
  for(i=0;i<n;i++){
    if(a[i]*a[i]==b[i]*b[i]+c[i]*c[i]
     ||b[i]*b[i]==a[i]*a[i]+c[i]*c[i]
     ||c[i]*c[i]==b[i]*b[i]+a[i]*a[i])
      printf("YES\n");
    else printf("NO\n");
  }
  return 0;
}

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

using namespace std;

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

const int N = 100010;
const double eps = 1e-6;

int n;
int s[N], a[N];

int main()
{
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) scanf("%d", s + i);
    for(int i = 1; i <= n; i++) a[i] = s[i] - s[i - 1];

    int res = 0;
    for(int i = 1; i <= n; i++)
        if(a[i] > 0) res += a[i];

    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

ll mpow(ll x, ll n) {
  ll ans=1;
  while(n>0) {
    if(n&1) {
      ans=ans*x%mod;
    }
    x=x*x%mod;
    n>>=1;
  }
  return ans;
}

int main() {
  ll l;
  cin >> l;
  ll n=0;
  while(mpow(2,n)<=l) n++;
  vec a,b,c;
  ll sum=0;
  for(ll i=1;i<n;i++) {
    a.push_back(i);
    b.push_back(i+1);
    c.push_back(0);
    a.push_back(i);
    b.push_back(i+1);
    c.push_back(mpow(2,i-1));
  }

  for(ll i=n-1;i;i--) {
    if(l-mpow(2,i-1)>=mpow(2,n-1)) {
      a.push_back(i);
      b.push_back(n);
      c.push_back(l-mpow(2,i-1));
      l-=mpow(2,i-1);
    }
  }
  cout << n << " " << a.size() << endl;
  for(ll i=0;i<a.size();i++) {
    cout << a[i] << " " << b[i] << " " << c[i] << endl;
  }
}

Measured memory_bytes: 3576
# import sys
# readline = sys.stdin.readline
# generator = (readline().strip() for _ in range(N))

# N, M = map(int, input().split())
# As = list(map(int, input().split()))
# queries = (input() for _ in range(N))


def solve():
    l, r, d = map(int, input().split())

    count = 0
    for i in range(l, r+1):
        if i % d == 0:
            count += 1

    return count


def main():
    print(solve())


if __name__ == "__main__":
    main()


Measured memory_bytes: 9160
<?php
$s = trim(fgets(STDIN));
$ans = "";
for($i=0; $i<strlen($s); $i++){
    if($s[$i] == "B"){
        $ans = substr($ans,0,strlen($ans)-1);
    }else{
        $ans .= $s[$i];
    }
}

echo $ans;

Measured memory_bytes: 4732
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
using namespace std;

int main(){
  char x,y;
  cin >> x >> y;
  if(x<y){
    cout << "<" << endl;
  }else if(x==y){
    cout << "=" << endl;
  }else{
    cout << ">" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a_ = []
b_ = []
for i in range(n):
    a, b = list(map(int, input().split()))
    a_.append(a)
    b_.append(b)

to_added = 0
for i in reversed(range(n)):
    temp = a_[i] + to_added
    temp2 = temp % b_[i]
    if temp2 == 0:
        temp3 = 0
    else:
        temp3 = b_[i] - temp2

    to_added += temp3

print(to_added)
    

Measured memory_bytes: 11024
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   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;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 
    
 
 
  int main(){
      lint n;
      cin>>n;
      M mp;
      rep(i,n){
          lint a;
          cin>>a;
          mp[a]++;
      }
      lint x[1000005];
      fill(x,x+1000005,1);
      for(auto c:mp){
          lint b=c.first;
          if(c.second>1)x[b]=0;
          for(int i=b*2;i<1000005;i+=b){
              x[i]=0;
          }
      }
      lint ans=0;
      for(auto c:mp){
          if(x[c.first])ans+=c.second;
      }
      cout<<ans<<endl;
     }
     
 

Measured memory_bytes: 23724
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String args[]) throws Exception{
        BufferedReader stdR = new BufferedReader(new InputStreamReader(System.in));
        String[] s = stdR.readLine().split(" ");
        int A = Integer.parseInt(s[0]);
        int B = Integer.parseInt(s[1]);
        if((A + B) % 2 == 0) {
            System.out.println((A + B) / 2);
        }else {
            System.out.println("IMPOSSIBLE");
        }
    }
}

Measured memory_bytes: 20564
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	d := make(map[int]int)
	// どの番号があるかは関係がない いくつあるかだけ
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		if _, ok := d[a]; ok {
			d[a]++
		} else {
			d[a] = 1
		}
	}
	numbers, variety := make([]int, 0), len(d)
	for _, value := range d {
		numbers = append(numbers, value)
	}
	sort.Ints(numbers)
	ans := 0
	for k < variety {
		ans += numbers[0]
		numbers = numbers[1:]
		variety--
	}
	fmt.Println(ans)
}


Measured memory_bytes: 17280
#include <cstdio>

int main(){
    int x,a,b;
    scanf("%d %d %d",&x,&a,&b);
    if(a >= b){
        printf("delicious\n");
    }else if(b - a <= x){
        printf("safe\n");
    }else{
        printf("dangerous\n");
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int ans;
    if(B >= A * C){
      ans = C;
    } else {
      ans = (int) B / A;
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
const ll MOD=1000000007;

int main(){
    int N,C;
    cin >> N >> C;
    vector<vector<int>> D(C,vector<int>(C));
    rep(i,C){
        rep(j,C){
            cin >> D[i][j];
        }
    }
    vector<vector<int>> count(3,vector<int>(C,0));
    rep(i,N){
        rep(j,N){
            int x;
            cin >> x;
            x--;
            count[(i+j)%3][x]++;
        }
    }
    vector<vector<Pii>> cost(3,vector<Pii>(C));
    rep(i,3){
        rep(j,C){
            int sum=0;
            rep(k,C){
                sum+=D[k][j]*count[i][k];
            }
            cost[i][j]=Pii(sum,j);
        }
        sort(cost[i].begin(),cost[i].end());
    }
    int ans=1000000000;
    rep(i,3){
        rep(j,3){
            rep(k,3){
                int x=cost[0][i].second,y=cost[1][j].second,z=cost[2][k].second;
                if (x!=y&&y!=z&&z!=x){
                    ans=min(ans,cost[0][i].first+cost[1][j].first+cost[2][k].first);
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;
int N;
long long h[100010];

long long dp[100010];
int main() {
    int N,K; cin >> N >> K;
    for (int i = 0; i < N; ++i) cin >> h[i];
    for (int i = 0; i < 100010; ++i) dp[i] = INF;
    dp[0] = 0;
    for (int i = 0; i < N; ++i) {
        for(int j = 0; j <= K;++j){
        chmin(dp[i+j], dp[i] + abs(h[i] - h[i+j]));
    }
    }

    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1792
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N], color[N];
int d[N], f[N], t;

void idfs(int u){
  int v;
  color[u] = GRAY;
  d[u] = ++t;
  for( v = 0 ; v < n ; v++){
    if(M[u][v] == 0) continue;
    if(color[v] == WHITE){
      idfs(v);
    }
  }
  color[u] = BLACK;
  f[u] = ++t;
}

void dfs_init(){
  int i;
  for( i = 0 ; i < n ; i++){
    color[i] = WHITE;
  }
  t = 0;
  for( i = 0 ; i < n ; i++){
    if(color[i] == WHITE ) idfs(i);
  }
  for( i = 0 ; i < n ; i++ ){
    printf("%d %d %d\n", i+1, d[i], f[i]);
  }
}


int main(){
  int i, j, u, k, v;

  scanf("%d", &n);

  for( i = 0 ; i < n ; i++){
    for( j = 0 ; j < n ; j++){
      M[i][j] = 0;
    }
  }
  for( i = 0 ; i < n ; i++ ){
    scanf("%d%d", &u, &k);
    for( j = 0 ; j < k ; j++ ){
      scanf("%d", &v);
      M[u-1][v-1] = 1;
    }
  }
  dfs_init();
  return 0;
}



Measured memory_bytes: 2112
def bubbleSort(N, A):
    flag = 1
    count = 0
    while flag != 0:
        flag = 0
        for i in range(N - 1, 0, -1):
            if A[i] < A[i - 1]:
                k = A[i]
                A[i] = A[i - 1]
                A[i - 1] = k
                flag = 1
                count += 1
    print(" ".join(map(str, A)))
    print(count)


n = int(input())
a = list(map(int, input().split()))
bubbleSort(n, a)


Measured memory_bytes: 5600
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// cout << fixed << setprecision(14);
 
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;
	int A[N];
	int num = 0;
	rep(i,N){
		cin >> A[i];
		if(A[i] % 2 == 1){
			num++;
		}
	}
	if(num % 2 == 0){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}

}

Measured memory_bytes: 1024
#include <stdio.h>
int main(int argc, const char * argv[]) {

//    int x=1,y;
//
//    while(1){
//        scanf("%d",&y);
//        if(y!=0){break;}
//        printf("Case %d:%d\n",x,y);
//        x+=1;
//    }
//
//
//    return 0;
    int i, x;
    
    for (i = 1;; ++i)
    {
        scanf("%d", &x);
        if (x == 0)
            break;
        
        printf("Case %d: %d\n", i, x);
    }
    
    return 0;

}



Measured memory_bytes: 2044
#! usr/bin/env python
# -*- coding: utf-8 -*-


def main():
    n = int(input())

    digits = [0, 3, 5, 7]
    ans = 0
    for i in range(4**9):
        cur = 0
        for j in range(10):
            cur += digits[i % 4] * 10 ** j
            i //= 4

        num = cur
        cnt = [0] * 10
        while num:
            cnt[num % 10] += 1
            num //= 10

        if cur <= n and not cnt[0] and cnt[3] and cnt[5] and cnt[7]:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 42476
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApplication1 {
    class Program {
        public static int Main(string[] args) {
            var n = Console.ReadLine();

            switch (n) {
                case "1":
                    Console.WriteLine("Hello World");
                    break;
                case "2":
                    var a = int.Parse(Console.ReadLine());
                    var b = int.Parse(Console.ReadLine());
                    Console.WriteLine(a + b);
                    break;
            }

            return 0;
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
using matrix = vector<vector<uint>>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;

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

    int N;
    cin >> N;

    vector<vector<vector<ll>>> dp(N + 3, vector<vector<ll>>(3, vector<ll>(2, -1e18)));
    dp[0][1][0] = 0;
    for (int i = 0; i < N; ++i) {
        int A;
        cin >> A;
        if (i & 1) {
            dp[i + 1][1][0] = max(dp[i][1][1], dp[i + 1][1][0]);
            dp[i + 1][1][1] = max(dp[i][0][0] + A, dp[i + 1][1][1]);
            dp[i + 1][0][0] = max(dp[i][0][0], dp[i + 1][0][0]);
            dp[i + 1][0][0] = max(dp[i][0][1], dp[i + 1][0][0]);

        } else {
            dp[i + 1][0][1] = max(dp[i][0][0] + A, dp[i + 1][0][1]);
            dp[i + 1][0][0] = max(dp[i][1][0], dp[i + 1][0][0]);
            dp[i + 1][0][0] = max(dp[i][1][1], dp[i + 1][0][0]);
            dp[i + 1][1][1] = max(dp[i][1][0] + A, dp[i + 1][1][1]);
        }
    }

    cout << max(dp[N][!(N & 1)][0], dp[N][!(N & 1)][1]) << endl;

    return 0;
}


Measured memory_bytes: 42240
N=int(input())
a=[int(input()) for _ in range(N)]
dp=[0]*(10**5)
dp[0]=1
c=0
ans=0
for i in range(N):
  ans+=1
  if a[c]-1==1:
    print(ans)
    exit()
  if dp[a[c]-1]==1:
    print(-1)
    exit()
  dp[a[c]-1]=1
  c=a[c]-1

Measured memory_bytes: 13828
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextLong()
    println(problem077b(n))
}

fun problem077b(n: Long): Long {
    var max = 1L
    for (i in 1..n / 2) {
        if (i * i <= n) {
            max = i * i
        }
    }
    return max.toLong()
}

Measured memory_bytes: 31392