akhauriyash/Code-Regression huggingface dataset:
let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let parent i = int_of_float ((float_of_int (i - 1)) /. 2.)

let left i = 2*i + 1

let right i = 2*i + 2

let to_pow_of_2 n =
  let rec doit i =
    if i > n then i
    else doit (i * 2) in
  doit 1

let add s n i x =
  let j = n + i - 1 in
  s.(j) <- x + s.(j);
  let rec doit j =
    if j > 0 then begin
      let j = parent j in
      s.(j) <- s.(left j) + s.(right j);
      doit j
    end in
  doit j

let sum s n a b =
  let rec doit a b k l r =
    if r < a || b < l then 0
    else if a <= l && r <= b then s.(k)
    else doit a b (left k) l ((l + r) / 2) + doit a b (right k) ((l + r) / 2 + 1) r in
  doit a b 0 0 (n - 1)

let solve n q =
  let n = to_pow_of_2 n in
  let s = Array.make (2*n) 0 in
  let rec doit i =
    if i < q then begin
      begin match List.map int_of_string (split_on_char ' ' (read_line ())) with
      | 0 :: x :: y :: _ -> add s n x y
      | 1 :: x :: y :: _ -> Printf.printf "%d\n" (sum s n x y)
      | _ -> ()
      end;
      doit (i + 1)
    end in
  doit 0

let () =
  match List.map int_of_string (split_on_char ' ' (read_line ())) with
  | [n; q] -> solve n q
  | _ -> ()

Measured memory_bytes: 6524
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long lli;
lli n,a,b;
vector<lli> x;
int main(int argc, char const *argv[]) {
    cin >> n >> a >> b;
    x = vector<lli> (n);
    for(lli i = 0;i < n;i++) cin >> x[i];
    lli ans = 0;
    for(lli i = 1;i < n;i++){
        ans += min((x[i]-x[i-1])*a,b);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
import sys
input = sys.stdin.readline

from collections import deque

N = int(input())

graph = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    a, b, c = map(int, input().split())
    graph[a].append([b, a, c])
    graph[b].append([a, b, c])
distance = [-1] * (N + 1)

Q, K = map(int, input().split())
distance = [-1] * (N + 1)
distance[K] = 0
que = deque()
q_append = que.append
for i in graph[K]:
    q_append(i)

q_left = que.popleft
while len(que) != 0:
    for _ in range(len(que)):
        abc = q_left()
        if distance[abc[0]] == -1: #動き先の値がまだ決まっていないとき
            distance[abc[0]] = distance[abc[1]] + abc[2]
            for j in graph[abc[0]]:
                q_append(j)
# print (distance)

for _ in range(Q):
    x, y = map(int, input().split())
    print (distance[x] + distance[y])

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

#define int long long
#define ll long long
#define f1(i,a,b) for(int i=a;i<b;i++)
#define f2(i,a,b) for(int i=a;i>=b;i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair
#define ld long double

const int mod = 1000000007;
const ld PI = acosl(-1.0);
ll temp;

// Don't forget to initialise parent and siz.
int parent[200001]; // 1e6 by default
int siz[200001]; // 1e6 by default
int ans[200001];
void make_set(int v) 
{
    parent[v] = v;
    siz[v] = 1;
}

int find_set(int v) 
{
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b) 
{
    a = find_set(a);
    b = find_set(b);
    if (a != b) 
    {
        if (siz[a] < siz[b])
            swap(a, b);
        parent[b] = a;
        siz[a] += siz[b];
    }
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m;
    cin>>n>>m;
    f1(i, 1, n + 1)
    make_set(i);
    f1(i, 0, m)
    {
        int a, b;
        cin>>a>>b;
        union_sets(a, b);
    }
    memset(ans, 0, sizeof ans);
    f1(i, 1, n + 1)
    {
        ans[find_set(i)]++;
    }
    int final = 0;
    f1(i, 1, n + 1)
    {
        final = max(final, ans[i]);
    }
    cout<<final<<endl;
    return 0;
}

Measured memory_bytes: 8340
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

int main(){
    ll n;
    cin >> n;
    ll a[n];
    
    ll iMin = INF;
    ll cnt = 0;
    //負の数は2個ずつしか減らせない
    //min(abs(a[i]))を引けばいい気がする
    //0があれば min -> 0
    REP(i,n)
    {
        cin >> a[i];
        iMin = min(iMin,abs(a[i]));
        if(a[i] < 0)++cnt;
    }

    ll res = 0;
    REP(i, n)
    {
        res += abs(a[i]);
    }

    if(cnt % 2 == 1)
    {
        res -= iMin * 2;
    }

    cout << res << endl;

    return 0;    
}



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

int main() {
  string s;
  cin >>s;
  bool b;
  b=0;
  for(int i=0; i<3; i++){
    if(s[i] == s[i+1]){
      b=1;
      break;
    }
  }
  if(b == 0)
    cout << "Good";
  else
    cout << "Bad";
}

Measured memory_bytes: 256
//Created by Aminul on 7/5/2020.

import java.io.*;
import java.util.*;

import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = in.nextInt(), m = in.nextInt(), k = in.nextInt();
        char[][] str = new char[n][m];
        for (int i = 0; i < n; i++) {
            str[i] = in.next().toCharArray();
        }

        int res = 0;
        for (int x = 0; x < (1 << n); x++) {
            for (int y = 0; y < (1 << m); y++) {
                int cnt = 0;
                for (int i = 0; i < n; i++) {
                    if (check(x, i)) continue;
                    for (int j = 0; j < m; j++) {
                        if (check(y, j)) continue;
                        cnt += str[i][j] == '#' ? 1 : 0;
                    }
                }
                if (cnt == k) res++;
            }
        }

        pw.println(res);

        pw.close();
    }

    static boolean check(int N, int pos) {
        return (N & (1 << pos)) != 0;
    }

    static void debug(Object... obj) {
        System.err.println(Arrays.deepToString(obj));
    }
}

Measured memory_bytes: 27660
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
//using ll=long long;
const double EPS = 1e-10;
inline bool equals(double a, double b) { return fabs(a - b) < EPS; }
const double PI = 3.141592653589793238;
class Point {
public:
	double x, y;
	Point(double x, double y) :x(x), y(y) {}
	Point() {}
	Point operator +(const Point &p) const{ return Point(x + p.x, y + p.y); };
	Point operator -(const Point &p) const{ return Point(x - p.x, y - p.y); }
	Point operator *(double k) { return Point(x*k, y*k); }
	Point operator /(double k) { return Point(x / k, y / k); }
};

using Vector = Point;
inline double norm(Vector a) {
	return a.x*a.x + a.y*a.y;
}
double absv(Vector a) {
	return sqrt(norm(a));
}
inline double dot(Vector a, Vector b) {
	return a.x*b.x + a.y*b.y;
}
inline double cross(Vector a, Vector b) {
	return a.x*b.y - a.y*b.x;
}
struct Segment {
	Point p1, p2;
};

using Line = Segment;
class Circle {
public:
	Point c;
	double r;
	Circle(Point c = Point(), double r = 0.0) :c(c), r(r) {}
};
using Polygon = vector<Point>; 
Point project(Segment s, Point p) {
	Vector base = s.p2 - s.p1;
	double r = dot(p - s.p1, base) / norm(base);
	return s.p1 + base*r;
}
Point reflect(Segment s, Point p) {
	return p + (project(s, p) - p)*2.0;
}

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

int ccw(Point p0, Point p1, Point p2) {
	Vector a = p1 - p0;
	Vector b = p2 - p0;
	if (cross(a, b) > EPS) return COUNTER_CLOCKWISE;
	if (cross(a, b) < -EPS) return CLOCKWISE;
	if (dot(a, b) < -EPS) return ONLINE_BACK;
	if (norm(a) < norm(b)) return ONLINE_FRONT;
	return ON_SEGMENT;
}
bool intersect(Point p1, Point p2, Point p3, Point p4) {
	return (ccw(p1, p2, p3)*ccw(p1, p2, p4) <= 0 and ccw(p3, p4, p1)*ccw(p3, p4, p2) <= 0);
}

bool intersect(Segment s1, Segment s2) {
	return intersect(s1.p1, s1.p2, s2.p1, s2.p2);
}
double getDistance(Point a, Point b) {
	return absv(a - b);
}

double getDistanceLP(Line l, Point p) {
	return abs(cross(l.p2 - l.p1, p - l.p1) / absv(l.p2 - l.p1));
}

double getDistanceSP(Segment s, Point p) {
	if (dot(s.p2 - s.p1, p - s.p1) < 0.0) return absv(p - s.p1);
	if (dot(s.p1 - s.p2, p - s.p2) < 0.0) return absv(p - s.p2);
	return getDistanceLP(s, p);
}

double getDistance(Segment s1,Segment s2){
	if (intersect(s1, s2)) return 0.0;
	return min(min(getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2)), min(getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2)));
}

Point getCrossPoint(Segment s1, Segment s2) {
	Vector base = s2.p2 - s2.p1;
	double d1 = abs(cross(base, s1.p1 - s2.p1));
	double d2 = abs(cross(base, s1.p2 - s2.p1));
	return s1.p1 + (s1.p2 - s1.p1)*(d1 / (d1 + d2));
}

int main() {
	int q, x[4], y[4];
	Point p[4];
	cin >> q;
	for (int i = 0; i < q; i++) {
		for (int j = 0; j < 4; j++) {
			cin >> x[j] >> y[j];
			p[j] = Point(x[j], y[j]);
		}
		Segment s[2];
		s[0] = { p[0],p[1] }, s[1] = { p[2],p[3] };
		Point ans = getCrossPoint(s[0], s[1]);
		printf("%.10lf %.10lf\n", ans.x,ans.y);
	}
}

Measured memory_bytes: 3204
import scala.io.StdIn.readInt

object Main {
  def round(n:Double) = {
    val m = n % 1000
    if(m>0) n-m+1000 else n
  }

  def getDebt(n:Int,m:Double):Int = if(n==0) m.toInt else getDebt(n-1,round(m*1.05))

  def main(args:Array[String]) = println(getDebt(readInt,100000))
}

Measured memory_bytes: 43540
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    for(int i = 0; i <= 100; i++) {
        for(int j = 0; j <= 100; j++) {
            if(4 * i + 7 * j == N) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

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

int main()
{
	int a[105];
	int n, i, tot;
	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &a[i]);
	tot = SelectSort(a, n);
	for (i = 0; i < n; i++)
		printf("%d%c", a[i], n - 1 == i ? '\n' : ' ');
	printf("%d\n", tot);
	return 0;
}

Measured memory_bytes: 600
def C_Dubious_Document_2(S, T):
    """
    S:鍵の文字列のいくつかを'?'で置き換えたもの
    T:Sの中に含まれている可能性のある文字列
    """
    ans = 'UNRESTORABLE'
    for i in range(len(S) - len(T) + 1):
        # ↑この位置まで調べてSの中にTを置く場所がなければ、復元不可能が確定
        for j in range(len(T)):
            if S[i + j] != '?' and S[i + j] != T[j]:
                # 逆に、S[i+j]=='?'かS[i+j]==T[j]が成り立つなら、
                # Tをうまく「ずらす」ことでSに埋め込める可能性があることを意味する
                break
            if j == len(T) - 1:
                # TをSに埋め込める可能性があった。
                # そのうち、Sのできるだけ後ろにTを埋め込むようになっている。
                tmp = S[:i] + T + S[i + len(T):]
                #辞書順最小になるように、残った'?'はすべて'a'で置き換える
                tmp = tmp.replace('?', 'a')
                ans = tmp
    return ans

S = input()
T = input()
print(C_Dubious_Document_2(S, T))

Measured memory_bytes: 3064
//???????????¢????????§?????°????????¢?????????????§????
//??????????????¨?????¢????????????????????????????°??????¢?????????????§???????????????????????????¨???????????????
//???2 3??§?????£??????????????????????????????4 6??§?????£?????????????????????????????????????????´?????????
//???????????????????????¨??????????????????????§??????????????????\?????¨????????????
//?§£?±??????????????????¢?????????????????? = ????°??????¢????????? * ??´??°(>=1)???
//??????????????§?????£????????????????????§?????????????????????????¢?????????????????????????

#include<iostream>
#define int long long
using namespace std;

struct Bou{
	int childl;
	int childr;
	int lengthl;
	int lengthr;
	
	void setBou( int p, int q, int r, int s ){
		lengthl = p;
		lengthr = q;
		childl = r;
		childr = s;
	}
}bou[101];

int gcd( int a, int b ){
	return ((b > 0) ? gcd( b, a % b ) : a);
}
int lcm( int a, int b ){
	return a * b / gcd(a, b);
}

int dfs( int ind ){
	//?????????
	if( ind == 0 ){
		return 1;
	}
	//???
	int lw = dfs(bou[ind].childl);
	//???
	int rw = dfs(bou[ind].childr);
	
	int moment = lcm(lw * bou[ind].lengthl, rw * bou[ind].lengthr);
	int ret = moment / bou[ind].lengthr + moment / bou[ind].lengthl;
	return ret;
}

signed main()
{
	int n;
	bool isRoot[101];
	
	while( cin >> n ){
		if( !n ) break;
		for( int i = 1; i <= n; i++ ){ isRoot[i] = true; }
		
		for( int i = 0; i < n; i++ ){
			int p, q, r, s;
			cin >> p >> q >> r >> s;
			bou[i+1].setBou(p, q, r, s);
			isRoot[r] = (isRoot[s] = false);
		}
		
		for( int i = 1; i <= n; i++ ){
			if( isRoot[i] ){
				cout << dfs(i) << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1164
#include <iostream>

using namespace std;

int main(void){
  int N,K;
  cin >> N >> K;
  long s = K;
  long t = 0;
  while(s<=N){
    t++;
    s+=K;
  }

  if( K%2==0 ){
    long i = 0;
    long j = K/2;
    while(j<=N){
      i++;
      j+=K;
    }
    cout << t*t*t+i*i*i << endl;
  }else{
    cout << t*t*t << endl;
  }
  return 0;
  }

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

char S[5], T[5];

ll i, j, k;
int main(){
    scanf("%s%s",S,T);
    fornum(i,0,3){
        if(S[i]==T[i]){
            j++;
        }
    }
    printf("%lld", j);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(register int i=a;i<=b;++i)
#define rpd(i,a,b) for(register int i=a;i>=b;--i)
#define rep1(i,x) for(register int i=head[x];i;i=nxt[i])
typedef long long ll;
//const int N=+5;
using namespace std;
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int a,b;
int main(){
	a=read();b=read();
	if(1LL*a*b<=0LL)return puts("Zero"),0;
	if(a>0)return puts("Positive"),0;
	if((b-a+1)&1)return puts("Negative"),0;
	return puts("Positive"),0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> list(n+1),list2(n + 1);
    int ans1 = 0, ans2 = 0;
    rep(i,m){
        int p;
        string s;
        cin >> p >> s;
        if(s=="AC"){
            if(!list[p]){
                ans1++;
                list[p]++;
            }
        }else{
            if(!list[p])
            list2[p]++;
        }
    }
    rep(i,n){
        if(list[i+1]){
            ans2 += list2[i + 1];
        }
    }
    cout << ans1 << ' ' << ans2 << endl;
}


Measured memory_bytes: 1152
//In the name of Allah :)
#include <bits/stdc++.h>
using namespace std;
string to_string(char c) { return string(1,c); }
string to_string(bool b) { return b ? "true" : "false"; }
string to_string(const char* s) { return (string)s; }
string to_string(string s) { return s; }
template<class A> string to_string(complex<A> c) { 
	stringstream ss; ss << c; return ss.str(); }
string to_string(vector<bool> v) { 
	string res = "{"; for(int i = 0; i < (int)v.size(); i++) res += char('0'+v[i]);
	res += "}"; return res; }
template<size_t SZ> string to_string(bitset<SZ> b) {
	string res = ""; for(size_t i = 0; i < SZ; i++) res += char('0'+b[i]);
	return res; }
template<class A, class B> string to_string(pair<A,B> p);
template<class T> string to_string(T v) { // containers with begin(), end()
	bool fst = 1; string res = "{";
	for (const auto& x: v) {
		if (!fst) res += ", ";
		fst = 0; res += to_string(x);
	}
	res += "}"; return res;
}
template<class A, class B> string to_string(pair<A,B> p) {
	return "("+to_string(p.f)+", "+to_string(p.s)+")"; }
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
	cerr << to_string(h); if (sizeof...(t)) cerr << ", ";
	DBG(t...); }
#ifdef LOCAL // compile with -DLOCAL
#define wis(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__)
#else
#define wis(...) 0
#endif
typedef long long ll;
const int MOD = 1e9 + 7, INF = 1e9 + 5;
inline ll powmod(ll a, ll b){ll res=1;for(;b;b>>=1,a=a*a%MOD)if(b&1)res=res*a%MOD;return res;}
inline ll power(ll a, ll b){ll res=1;for(;b;b>>=1,a=a*a)if(b&1)res=res*a;return res;}

const int MAXN = 2e4 + 10;

int ans[MAXN];


int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	for(int x = 1; x <= 100; x++){
		for(int z = 1; z <= 100; z++){
			for(int y = 1; y <= 100; y++){
				int cur = x * x + y * y + z * z + x * y + x * z + y * z;
				if(cur >= MAXN)
					continue;
				ans[cur]++;
			}
		}
	}
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++){
		cout << ans[i] << '\n';
	}
}


Measured memory_bytes: 3728
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#include <random>
#include <chrono>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

ll d;
vector<ll> c(26 + 1, 0);
vector<vector<ll>> s(365 + 1, vector<ll>(26 + 1, 0));

ll scoring(vector<int> t)
{
    ll ans = 0;
    vector<ll> last(26 + 1, 0);

    for (int i = 1; i <= d; i++)
    {
        ans += s[i][t[i]];
        ans -= c[t[i]] * (i - last[t[i]]) * (i - last[t[i]] - 1) / 2;
        last[t[i]] = i;
    }

    for (int i = 1; i <= 26; i++)
    {

        ans -= c[i] * (d - last[i] + 1) * (d - last[i]) / 2;
    }

    return ans;
}

int main(void)
{
    random_device seed_gen;
    mt19937 rand(seed_gen());
    cin >> d;

    for (int i = 1; i <= 26; i++)
    {
        cin >> c[i];
    }

    for (int i = 1; i <= d; i++)
    {
        for (int j = 1; j <= 26; j++)
        {
            cin >> s[i][j];
        }
    }

    vector<int> BestT(d + 1, 1);

    for (int i = 1; i <= d; i++)
    {
        BestT[i] = rand() % 26 + 1;
    }

    double BestScore = scoring(BestT);
    double score;

    auto start = chrono::system_clock::now();
    vector<int> t(d + 1, 1);

    double T0 = 1e6;
    double T1 = 5e2;
    double TL = 1980;
    double msec;

    ll count = 0;

    while (1)
    {
        if (count % 100 == 0)
        {
            msec = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now() - start).count();
        }

        if (msec >= TL)
        {
            break;
        }

        double T = powf(T0, 1 - msec / TL) * powf(T1, msec / TL);

        t = BestT;

        for (int i = 0; i < 2; i++)
        {
            t[rand() % d + 1] = rand() % 26 + 1;
        }

        score = scoring(t);

        double p = exp((score - BestScore) / T);

        if (p > 0.5)
        {
            BestT = t;
            BestScore = score;
        }

        count++;
    }

    for (int i = 1; i <= d; i++)
    {
        printf("%d\n", BestT[i]);
    }
}


Measured memory_bytes: 4432
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
"""
全員が自分以外の全員のxorを把握しているので、全員の値を求めよ
nは偶数

"""
n = int(readline())
lst1 = list(map(int,readline().split()))
limit = 33
ans = []
parity = [0]*limit
for i in lst1:
    for j in range(limit):
        parity[j] += i>>j

for i in range(limit):
    parity[i] %= 2

for i in lst1:
    res = 0
    for j in range(limit):
        p = i>>j&1
        if parity[j]== 0 and p== 1:
            res += 1<<j
        elif parity[j] == 1 and p == 0:
            res += 1<<j
    ans.append(res)
print(*ans)

Measured memory_bytes: 98688
#include<iostream>
#include<numeric>
#include<set>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
typedef long long li;
#define chmin(a,b) (a>(b)?a=(b),1:0)
#define abs(n) max((n),-(n))
#define dist(a,b) max((a)-(b),(b)-(a))
#define chmax(a,b) (a<(b)?a=(b),1:0)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define MOD 1000000000
#define rep(i,n) for(int i=0;i<(n);i++)

#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  // ここでストリームに obj を書き込みます。
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}


int main(){
  int n; li k; cin >>n >>k;
  vector<pair<int,int>> v;
  rep(i,n){
    int a,b; cin >>a >>b;
    v.push_back({a,b});
  }
  sort(v.begin(),v.end());
  li t=0,i=0;
  while(t<k){
    t+=v[i++].second;
  }
  print(v[i-1].first);
}





Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    long long num;
    vector<char> list;
    cin >> num;
    string b = to_string(num), c;
    for (int i=0; i<3; i++) {
        char a = b[i];
        c=a;
        list.push_back(stoll(c));}
    if (list[1]<list[0]) {cout << list[0]*100 + list[0]*10 + list[0];}
    else if (list[1]>=list[0]) {
        if (list[2]>list[0]) {cout << (list[0]+1)*100 + (list[0]+1)*10 + (list[0]+1);}
        else if (list[1]>list[0]) {cout << (list[0]+1)*100 + (list[0]+1)*10 + (list[0]+1);}
        else if (list[2]<list[0]) {cout << list[0]*100 + list[0]*10 + list[0];}
        else if (list[1]==list[0] && list[2]==list[0]) {cout << list[0]*100 + list[0]*10 + list[0];}}}

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

int main(void)
{
    
    char str[1201] = {0};
    
    fgets(str, sizeof(str), stdin);
  
    for ( int i = 0; i < strlen(str); i++ ) {
        if ( (0x41 <= str[i]) && (str[i] <= 0x5A) ) {
            printf("%c", str[i] + 0x20);
        } else if ( (0x61 <= str[i]) && (str[i] <= 0x7A) ) {
            printf("%c", str[i] - 0x20);
        } else {
            printf("%c", str[i]);
        }
    }

    return 0;
}


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

const int mxn = 2e5;
bool prime[mxn + 5];
void takbir(){
    for(int i = 2; i*i<=mxn; i++){
        if(!prime[i]){
            for(int j = i*i; j<=mxn; j+=i) prime[j] = 1;
        }
    }
}

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

    //good luck kittu!
    takbir();
    int x; cin>>x;
    for(int i = x; ; i++){
        if(!prime[i]) return cout<<i, 0;
    }
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n;
    cin >> n;
    vector<int> vec(n);
    for(int i=0;i<n;++i){
        cin >> vec[i];
    }
    reverse(vec.begin(),vec.end());
    for(int i=0;i<n-1;++i){
        cout << vec[i] << " ";
    }
    cout << vec[n-1] << endl;
}


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

#define    int                      long long int
#define    ld                       long double
#define    f(i,j,n)                 for(int i = j; i <= n; i++)
#define    r(i,n,j)                 for(int i = n; i >= j; i--)
#define    mod                      1000000007
#define    speed                    ios_base::sync_with_stdio(false);
#define    upp                      cin.tie(NULL);
#define    pb                       push_back
#define    mp                       make_pair
#define    T                        int ttt; cin >> ttt; while(ttt--)
#define    ff                       first
#define    ss                       second
#define    all(container)            container.begin() , container.end()
#define    sz(container)            (int)container.size()
#define    pii                      pair <int , int>
#define    sp(x)                    setprecision(x)
#define    bp                       __builtin_popcountll

int power(int x, int y, int p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0; 
    while (y > 0)  
    {     
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res; 
}


int32_t main()
{
    speed upp
	int n;
    cin>>n;
    int x,y=0;
    f(i,1,n)
    {
        if(i%3==0 || i%5==0)
            continue;

            y+=i;
    }
    cout<<y;
}

Measured memory_bytes: 3640
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
std::random_device rd;
std::mt19937 mt(rd());
constexpr int MOD = 1e9+7; constexpr int MAX = 200020;
const double pi = acos(-1); constexpr double EPS = 1e-8;
constexpr ll INF = 1e18;



void solve() {
	int A, B, M;
	cin >> A >> B >> M;
	vector<int>a(A), b(B);
	REP(i, A) {
		cin >> a[i];
	}
	REP(i, B) {
		cin >> b[i];
	}
	vector<int>X(M), Y(M), C(M);
	REP(i, M) {
		cin >> X[i] >> Y[i] >> C[i];
		X[i]--; Y[i]--;
	}
	ll ans = 1e18;
	REP(i, M) {
		ans = min(ans, a[X[i]] + b[Y[i]] - C[i]);
	}
	VSORT(a);
	VSORT(b);
	ans = min(ans, a[0] + b[0]);
	print(ans);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}



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

int main(){
    string s;
    cin>>s;
    int c=0;
    if(s[0]=='1'){c+=1;}
    if(s[1]=='1'){c+=1;}
    if(s[2]=='1'){c+=1;}
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 768
while 1:
	t,p,r=map(int,raw_input().split())
	if t==0:break
	wrong=[[0]*p for i in range(t)]
	point={i+1:[0,0] for i in range(t)}
	for i in range(r):
		tid,pid,time,msg=map(str,raw_input().split())
		tid,pid,time=int(tid),int(pid),int(time)
		if msg[0]=="W":
			wrong[tid-1][pid-1]+=1
		else:
			point[tid][0]+=1
			point[tid][1]+=1200*wrong[tid-1][pid-1]+time

	for k,v in sorted(sorted(point.items(),key=lambda x:x[1][1]),key=lambda x:x[1][0],reverse=True):
		print k,v[0],v[1]
	

Measured memory_bytes: 4276
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.C_Challenge
{
    class ABC_047
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            string input = Console.ReadLine();
            bool isBlack = input[0] == 'B';
            int cnt = 0;
            for (int i = 1; i < input.Length; i++)
            {
                if ((isBlack && input[i] == 'W')
                    ||(!isBlack&&input[i]=='B'))
                {
                    cnt++;
                    isBlack= input[i] == 'B';
                }
            }
            Console.WriteLine(cnt);
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    int h;
    h = (n+1)/2;

    float nf = n;
    float nh = h;

    double ans = (nh/nf);
    printf("%.9f\n",ans);


    return 0;
}

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

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    int H=gi();
	    int W=gi();
	    int D=gi();
	    Pair<Integer, Integer>[] A=new Pair[H*W+1];
	    for(int i=0;i<H;i++) {
	    	for(int j=0;j<W;j++) {
	    	    int a=gi();
	    	    A[a]=new Pair<Integer, Integer>(i,j);
	    	}
	    }

	    int[][] d=new int[D][Math.floorDiv(H*W, D)+2];
	    for(int i=1;i<H*W-D+1;i++) {
	    	int i1=i%D;
	    	int i2=Math.floorDiv(i, D);
	    	d[i1][i2]=Math.abs(A[i+D].getKey()-A[i].getKey()) + Math.abs(A[i+D].getValue()-A[i].getValue());
	    	if(i2>0) d[i1][i2]+=d[i1][i2-1];
	    }
	    int Q=gi();
	    for(int i=0; i<Q;i++) {
	    	int l=gi();
	    	int r=gi();
	    	int l1=l%D;
	    	int l2=(l-l1)/D-1;
	    	int r1=r%D;
	    	int r2=(r-r1)/D-1;
	    	if (l2>=0 && r2>=0) {
	    	    System.out.println(d[r1][r2]-d[l1][l2]);
	    	} else if(r2>=0) {
	    		System.out.println(d[r1][r2]);
	    	} else {
	    		System.out.println(0);
	    	}
	    }

	    //System.out.println(-1);
	}

	public static class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> implements Comparable<Pair<K, V>> {
		/** serialVersionUID. */
	    private static final long serialVersionUID = 6411527075103472113L;

	    public Pair(final K key, final V value) {
	        super(key, value);
	    }

		@Override
		public int compareTo(Pair<K, V> o) {

			Comparable key = (Comparable)this.getKey();
			Comparable key2 = (Comparable)o.getKey();

			return key.compareTo(key2);
		}

	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 68732
import java.util.Scanner;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int sz = Integer.parseInt(sc.nextLine());
        String l2 = sc.nextLine().trim();
		String s1 = l2.split("\\s+")[0];
		String s2 = l2.split("\\s+")[1];
		StringBuilder sb = new StringBuilder();
		for (int i=0; i<sz; i++) {
			sb.append(s1.charAt(i));
			sb.append(s2.charAt(i));
		}

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


Measured memory_bytes: 21716
// AtCode.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
#include <queue>
#include <bitset>

using namespace std;

#define MAX_NUM (393)

int s[MAX_NUM];
int l[MAX_NUM];
int p[MAX_NUM];

//dp[i][j]: i番目のフレーズまでを使た場合の、長さjフレーズの最高得点
int dp[MAX_NUM + 1][MAX_NUM + 1];

int main() {

	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s[i] >> l[i] >> p[i];
	}

	for (int id = 1; id < n + 1; id++) {
		for (int length = 0; length < MAX_NUM + 1; length++) {
			dp[id][length] = dp[id - 1][length];
			for (int use = s[id - 1]; use < min(length,l[id - 1])+1; use++) {
				dp[id][length] = max(dp[id][length], dp[id][length - use] + p[id - 1]);
			}
		}
	}

	int m;
	cin >> m;
	vector<int> ans;
	for (int i = 0; i < m; i++) {
		int tmp;
		cin >> tmp;
		ans.push_back(dp[n][tmp]);
		if (dp[n][tmp] == 0) {
			cout << "-1" << endl;
			return 0;
		}
	}

	for (int i = 0; i < ans.size(); i++) {
		cout << ans[i] << endl;
	}


	return 0;
}




Measured memory_bytes: 3716
#define _DEBUG 1

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define check(s)
#endif

#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

void solve(ll A, ll B, ll M, std::vector<ll> a, std::vector<ll> b,
           std::vector<ll> x, std::vector<ll> y, std::vector<ll> c) {
  ll result = -1;

  rep(i, M) {
    ll price = a.at(x.at(i) - 1) + b.at(y.at(i) - 1) - c.at(i);
    result = result != -1 ? min(price, result) : price;
  }

  ll minA = -1;
  ll minB = -1;
  // a の min + b の min でよさそう
  rep(i, A) { minA = minA != -1 ? min(minA, a.at(i)) : a.at(i); }
  rep(i, B) { minB = minB != -1 ? min(minB, b.at(i)) : b.at(i); }
  result = min(minA + minB, result);

  cout << result << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  ll A;
  scanf("%lld", &A);
  ll B;
  scanf("%lld", &B);
  ll M;
  scanf("%lld", &M);
  std::vector<ll> a(A);
  for (int i = 0; i < A; i++) {
    scanf("%lld", &a[i]);
  }
  std::vector<ll> b(B);
  for (int i = 0; i < B; i++) {
    scanf("%lld", &b[i]);
  }
  std::vector<ll> x(M);
  std::vector<ll> y(M);
  std::vector<ll> c(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &x[i]);
    scanf("%lld", &y[i]);
    scanf("%lld", &c[i]);
  }
  solve(A, B, M, std::move(a), std::move(b), std::move(x), std::move(y),
        std::move(c));
  return 0;
}


Measured memory_bytes: 4224
A,B,H,M=map(int,input().split())
import math
t=60*H+M
if H>=12:
    H-=12
tA=2*math.pi*t/60/12
tB=2*math.pi*M/60
ans=(A*math.cos(tA)-B*math.cos(tB))**2+(A*math.sin(tA)-B*math.sin(tB))**2
print(ans**0.5)

Measured memory_bytes: 9568
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  int ABS_MAX = -1;
  int pos = -1;
  bool plus = true;
  for(int i=0; i<N; i++){
    cin >> vec[i];
    if(abs(vec[i]) > ABS_MAX){
      ABS_MAX = abs(vec[i]);
      pos = i;
      if(vec[i] < 0){
        plus = false;
      }
      else{
        plus = true;
      }
    }
  }
  
  cout << 2*N << endl;
  
  for(int i=0; i<N; i++){
    if(i == pos){
      continue;
    }
    cout << pos+1 << " " << i+1 << endl;
  } 
  cout << pos+1 << " " << pos+1 << endl;
  
  
  if(plus){
    for(int i=0; i<N; i++){
      if(i == 0){
        cout << pos+1 << " " << i+1 << endl;
      }
      else{
        cout << i << " " << i+1 << endl;
      }
    }
  }
  else{
    for(int i=N-1; i>=0; i--){
      if(i == N-1){
        cout << pos+1 << " " << i+1 << endl;
      }
      else{
        cout << i+2 << " " << i+1 << endl;
      }
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    
    int main(){
        string str;
        cin >> str;
        if(str[0] == '9' || str[1] == '9' ){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }

        return 0;
    }

Measured memory_bytes: 256
import math

n,k =  map(int,input().split())
lis = []
for i in range(n):
    if i+1 >= k:
        lis.append(0)
    else:
        lis.append(math.ceil(math.log2((k/(i+1)))))

#print(lis)


ans = []
for i in range(n):
    ans.append(1/n * (1/2)**lis[i])

print(sum(ans))

Measured memory_bytes: 7064
s = gets.chomp
a = [?A, ?K, ?I,?H, ?B, ?R]
s.chars do |c|
    if !a.include?(c)
        puts "NO"
        exit
    end
end
s2 = s.delete(?A)
if s2 != "KIHBR"
    puts "NO"
    exit
end
if s.index(?K) <=1 && s.index(?I) - s.index(?K) == 1 && s.index(?H) - s.index(?I) == 1 && s.index(?B) - s.index(?H) <= 2 && s.index(?R) - s.index(?B) <= 2 && s.size - s.index(?R) <= 2
    puts "YES"
else
    puts "NO"
end

Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] x = new int[N];
		for (int i = 0; i < x.length; i++) {
			x[i] = sc.nextInt();
		}

		int ans = Integer.MAX_VALUE;
		for (int i = 0; i < N - K + 1; i++) {
			int dist = Math.min(x[i + K - 1] - x[i] + Math.abs(x[i + K - 1]),
								x[i + K - 1] - x[i] + Math.abs(x[i]));
			ans = Math.min(ans, dist);
		}

		System.out.println(ans);
	}
}

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


int main() {
  string S, temp;
  cin >> S;
  bool flag = false;

  int i,j;
  for (i=0;i<S.size();i++){
    for (j=0;j<S.size();j++){
      temp = S;
      temp.erase(i,j);
      if (temp == "keyence"){
        flag = true;
        break;
      }
    }
  }

  if (flag){
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=2e5+10,inf=0x3f3f3f3f;
int idx[maxn],idx_cnt,a[maxn];
struct Segment_tree{
	int Min[maxn<<2],tag[maxn<<2];
	inline void push_down(int x){
		if(tag[x]){
			Min[x<<1]+=tag[x];
			Min[x<<1|1]+=tag[x];
			tag[x<<1]+=tag[x];
			tag[x<<1|1]+=tag[x];
			tag[x]=0;
		}
	}
	inline void push_up(int x){
		Min[x]=min(Min[x<<1],Min[x<<1|1]);
	}
	void build_tree(int x,int L,int R){
		if(L==R){
			Min[x]=idx[L];
			return;
		}
		int Mid=(L+R)>>1;
		build_tree(x<<1,L,Mid),build_tree(x<<1|1,Mid+1,R);
		push_up(x);
	}
	void update(int x,int L,int R,int ql,int qr,int v){
		if(ql>qr) return;
		if(ql<=L && R<=qr){
			tag[x]+=v,Min[x]+=v;
			return;
		}
		int Mid=(L+R)>>1;
		push_down(x);
		if(ql<=Mid) update(x<<1,L,Mid,ql,qr,v);
		if(qr>Mid) update(x<<1|1,Mid+1,R,ql,qr,v);
		push_up(x);
	}
	int query(int x,int L,int R,int ql,int qr){
		if(ql<=L && R<=qr) return Min[x];
		int Mid=(L+R)>>1,res=inf;
		push_down(x);
		if(ql<=Mid) chkmin(res,query(x<<1,L,Mid,ql,qr));
		if(qr>Mid) chkmin(res,query(x<<1|1,Mid+1,R,ql,qr));
		push_up(x);
		return res;
	}
}Seg;

ll ans;
int main(){
	int n=read();
	REP(i,1,n) a[i]=read();
	REP(i,1,n) idx[++idx_cnt]=a[i];
	sort(idx+1,idx+idx_cnt+1);
	idx_cnt=unique(idx+1,idx+idx_cnt+1)-idx-1;
	Seg.build_tree(1,1,idx_cnt);
	REP(i,1,n){
		int u=lower_bound(idx+1,idx+idx_cnt+1,a[i])-idx;
		ans+=Seg.query(1,1,idx_cnt,u,idx_cnt)-a[i];
		Seg.update(1,1,idx_cnt,1,u-1,1);
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 7936
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String a = scan.next();
		String b = scan.next();
		String c = scan.next();
		String message = "NO";
		if(a.endsWith(b.charAt(0) + "")) {
			if(b.endsWith(c.charAt(0) + "")) {
				message = "YES";
			}
		}
		System.out.println(message);
	}
}

Measured memory_bytes: 25172
#include <iostream>
#include <vector>
#include <numeric>//accumulate(v.begin(), v.end(), 0);
#include <algorithm>//sort(v.begin(),v.end());
#include <string>//
using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main(){
        int N;
        cin >> N;
        vector <int> v(N,0);

        rep(i,N) cin >> v[i];
        int ans = accumulate(v.begin(), v.end(), 0);

        cout << ans-N << endl;

        return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FILEIN freopen("input.txt", "r", stdin)

#define endl "\n"
int main(){
    // FILEIN;
    int n, mem[10][10] = {{}}; cin>>n;
    for(int i = 1; i<=n; i++){
        mem[to_string(i)[0]-'0'][i%10]++;
    }
    int ans = 0;
    for(int i = 0; i<=9; i++){
        for(int j = 0; j<=9; j++){
            ans += mem[i][j] * mem[j][i];
        }
    }
    cout<<ans<<endl;
}


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

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll ans = 0;
    rep(i,60){
        ll x = 0;
        rep(j,n) if(a[j]>>i&1) x++;
        ll now = x*(n-x)%MOD;
        rep(j,i) now = now*2%MOD;
        ans += now;
        ans %= MOD;
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {

    private static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
	String SA = scan.next();
	String SB = scan.next();
	String SC = scan.next();

	int sa = 0;
	int sb = 0;
	int sc = 0;
	char next = 'a';
	boolean flag = true;
	char winner = 0;
	while(flag) {
	    switch(next) {
		case 'a':
		    if(sa == SA.length()) {
			flag = false;
			winner = 'A';
		    } else {
			next = SA.charAt(sa);
			sa++;
		    }
		    break;
		case 'b':
		    if(sb == SB.length()) {
			flag = false;
			winner = 'B';
		    } else {
			next = SB.charAt(sb);
			sb++;
		    }
		    break;
		case 'c':
		    if(sc == SC.length()) {
			flag = false;
			winner = 'C';
		    } else {
			next = SC.charAt(sc);
			sc++;
		    }
		    break;
	    }
	}

	System.out.println(winner);
	scan.close();
    }
}


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

#define MAX_N (1 << 15)+10

using namespace std;

int main(void){
	int n;
	bool prime_judge[MAX_N + 1];
	vector<int> prime;
	
	fill(prime_judge,&prime_judge[MAX_N + 1],true);

	prime_judge[0] = prime_judge[1] = false;


	// エラトステネスの篩
	for(int i = 0;i * i <= MAX_N;i++){
		if(prime_judge[i]){
			for(int j = 2 * i;j <= MAX_N;j+=i){
				prime_judge[j] = false;
			}
		}
	}

	// 素数だけを可変長配列に入れていく。
	for(int i = 0;i <= MAX_N;i++){
		if(prime_judge[i]){
			prime.push_back(i);
		}
	}

	while(cin >> n){
		if(n == 0) break;
		int ans = 0;
		for(int i = 0;i < prime.size();i++){
			for(int j = i;j < prime.size();j++){
				if(prime[i] + prime[j] == n){
					ans++;
				}
			}
		}
		cout << ans << endl;
	}


	return 0;
}

Measured memory_bytes: 1276
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] ans = new int[n];
    int p = 0;
    for(int i = 11; i < 55555; i++) {
      if(p >= n) break;
      if(i % 5 == 1) {
      int f = 0;
      for(int j = 2; j * j <= i; j++) {
        if(i % j == 0) {
          f++;
          break;
        }
      }
      if(f == 0) {
        ans[p] = i;
        p++;
      }
      }
    }
    for(int i = 0; i < n; i++) {
      if(i < n - 1) System.out.print(ans[i] + " ");
      if(i == n - 1) System.out.print(ans[i]);
    }
  }
}

Measured memory_bytes: 19796
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long LL;
const int N=100005;
LL A1[26],A2[26],an1[26],an[26],L,R,S,t;
int b[N<<1],next[N],s[N][26],i,j,k,n,m,l,B;
char c;

inline char getc()
{
	#define VV 10000000
	static char s[VV],*l=s,*r=s;
	if (l==r)
		l=s,r=s+fread(s,1,VV,stdin);
	return l==r?0:*l++;
}

LL read(){ LL z=0; do c=getc(); while (c<'0'||c>'9'); while (c>='0'&&c<='9') z*=10,z+=c-'0',c=getc(); return z; }

void fib(LL X)
{
	if (X<=n)
	{
		for (register int i=0;i<26;++i)
			an[i]+=s[X][i];
		return;
	}
	if (X<=n<<1)
	{
		for (register int i=0;i<26;++i)
			an[i]+=s[n][i]+s[X-n][i];
		return;
	}
	for (register int i=0;i<26;++i)
		A1[i]=s[n][i],A2[i]=A1[i]+s[B][i];
	LL l1=n,l2=n+B;
	while (X>l1+l2)
	{
		for (register int i=0;i<26;++i)
			t=A1[i],A1[i]=A2[i],A2[i]+=t;
		t=l1,l1=l2,l2+=t;
	}
	for (register int i=0;i<26;++i)
		an[i]+=A2[i];
	fib(X-l2);
}

void solve(LL X)
{
	if (X<=n)
		for (i=0;i<26;++i)
			an[i]=s[X][i];
	else
		if (n%B)
			fib(X);
		else
			for (S=X/n,l=X%n,i=0;i<26;++i)
				an[i]=S*s[n][i]+s[l][i];
}

int main()
{
	do c=getc(); while (c<'a'||c>'z');
	while (c>='a'&&c<='z') b[++n]=c-'a',c=getc();
	n>>=1,L=read(),R=read();
	for (i=2;i<=n;next[i]=j+(b[j+1]==b[i]),++i)
		for (j=next[i-1];j&&b[j+1]!=b[i];j=next[j]);
	B=n-next[n];
	for (i=1;i<=n;++s[i][b[i]],++i)
		for (j=0;j<26;++j)
			s[i][j]=s[i-1][j];
	solve(R);
	for (i=0;i<26;++i) an1[i]=an[i],an[i]=0;
	solve(L-1);
	for (i=0;i<26;++i) printf("%lld ",an1[i]-an[i]);
	return 0;
}

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

int main(){
    vector<ll> a(3);
    rep(i, 0, 3) cin >> a[i];
    ll ans = 1e18;
    do {
        ans = min(ans, abs(a[0]-a[1])+abs(a[1]-a[2]));
    } while(next_permutation(a.begin(), a.end()));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
t,_,s=open(0).read().partition('\n')
h,w=map(int,t.split())
a,b=h//2*(w//2),h%2and w%2
d=[b,(h*w-a*4-b)//2,0,a]
for i in map(s.count,set(s)-{'\n'}):
  for j in(3,1,0):
    while d[j]and i>j:
      i-=j+1
      d[j]-=1
print('YNeos'[sum(d)>0::2])

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

int main(){
    int temp;
    int key=-1;
    int data[3]={0};
    for(int i=0;i<10;i++){
        cin>>temp;
        for(int j=0;j<3;j++){
            if(temp>data[j])
            key=j;
        }
        if(key>=0){
        if(key>=1)
        for(int i=0;i<key;i++){
            data[i]=data[i+1];
        }
            data[key]=temp;
            key=-1;
        }
    }
    for(int i=2;i>-1;i--){
        cout<<data[i]<<endl;
    }
        return 0;
}

Measured memory_bytes: 3060
N,Q = map(int,input().split())
if N == 1:
    for i in range(Q):
        print(min(map(int,input().split())))
    exit()

def solve(s):
    a,b = map(int,s.split())
    while a != b:
        if a < b: a,b = b,a
        a = (a+N-2) // N
    return str(a)

print('\n'.join(map(solve, [input() for i in range(Q)])))


Measured memory_bytes: 17520
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N, M;
  
  cin >> N;
  vector<string> blue(N);
  for (int i = 0; i < N; i++) {
    cin >> blue.at(i);
  }
  
  cin >> M;
  vector<string> red(M);
  for (int i = 0; i < M; i++) {
    cin >> red.at(i);
  }
  
  int score = 0;
  
  for (int i = 0; i < N; i++) {
    
    int sub_score = 0;
    
    for (int j = 0; j < N; j++) {
      if (blue.at(i) == blue.at(j)) sub_score++;
    }
    
    for (int j = 0; j < M; j++) {
      if (blue.at(i) == red.at(j)) sub_score--;
    }
    
    score = max(score, sub_score);
    
  }
  
  cout << score << endl;
  
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
const int N=2e5+1;
int n,p[N],c[N],l=1,A=1;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>p[i];
	for(int i=1;i<=n;i++)
		c[p[i]]=i;
	for(int i=2;i<=n;i++)
		if(c[i]>c[i-1])
			A=max(A,i-l+1);
		else
			l=i;
	cout<<n-A;
	return 0;
}

Measured memory_bytes: 1792