akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
const int maxn=5e5+5;
int n,c[maxn],last[maxn];
vector<pair<int,int> > queries[maxn];
int sum[maxn];
void add(int pos,int val)
{
    while(pos<=n)
    {
        sum[pos]+=val;
        pos+=pos&(-pos);
    }
    return;
}
int query(int pos)
{
    int res=0;
    while(pos)
    {
        res+=sum[pos];
        pos-=pos&(-pos);
    }
    return res;
}
int ans[maxn];
int main()
{
    int m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        scanf("%d",&c[i]);
    for(int i=1;i<=m;i++)
    {
        int l,r;
        scanf("%d%d",&l,&r);
        queries[r].push_back(make_pair(l,i));
    }
    memset(last,-1,sizeof(last));
    for(int i=1;i<=n;i++)
    {
        if(~last[c[i]])
            add(last[c[i]],-1);
        last[c[i]]=i;
        add(i,1);
        for(int j=0;j<(int)queries[i].size();j++)
        {
            int s=queries[i][j].first;
            ans[queries[i][j].second]=query(i)-query(s-1);
        }
    }
    for(int i=1;i<=m;i++)
        printf("%d\n",ans[i]);
    return 0;
}
/*
4 3
1 2 1 3
1 3
2 4
3 3
 
10 10
2 5 6 5 2 1 7 9 7 2
5 5
2 4
6 7
2 2
7 8
7 9
1 8
6 9
8 10
6 8
 */


Measured memory_bytes: 33232
#include <cstdio>
#include"atcoder/all"

using namespace std;
using namespace atcoder;
typedef long long ll;

int main() {
    int t;
    scanf("%d", &t);
    for (int i = 0; i < t; ++i) {
        ll n, m, a, b;
        scanf("%lld%lld%lld%lld", &n, &m, &a, &b);
        printf("%lld\n", floor_sum(n, m, a, b));
    }

    return 0;
}

Measured memory_bytes: 3824
# -*- coding: utf-8 -*-


def main():

    s, t = input().split()
    a, b = map(int, input().split())
    u = input()

    temp = {s: a, t: b}
    temp[u] = temp.get(u) - 1

    return " ".join([str(temp.get(s)), str(temp.get(t))])


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 3060
package main

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

func main() {
	resolve(parseProblem(os.Stdin))
}

func parseProblem(r io.Reader) int {
	const (
		initialBufSize = 100000
		maxBufSize     = 1000000
	)
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines

	return scanInt(sc)
}

func resolve(n int) {
	for i := 1; i <= n; i++ {
		if int(float64(i)*1.08) == n {
			fmt.Println(i)
			return
		}
	}
	fmt.Println(":(")
	return
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 640
n,p = map(int,input().split())
if n == 1:
  print(p)
  exit()
a = 1
for k in range(2,1000001):
  c = 0
  while p%k == 0:
    p = p//k
    c += 1
  a *= k**(c//n)
  if p == 1:
    break
print(a)

Measured memory_bytes: 2940
fn main() {
    let r = read::<f64>();
    println!("{}", 2.0 * r * std::f64::consts::PI);
}
 
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}

Measured memory_bytes: 2192
#include <iostream>
using namespace std;
int main(void){
    string str,s,p;
    cin >> str;
    int n,a,b;
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> s >> a >> b;
        if (s == "print"){
            for (int i = 0; i < b - a + 1; i++)
                cout << str[i + a];
            cout << endl;
        }
        else if(s == "reverse"){
            for (int i = 0; i < (b - a + 1) / 2; i++){
                int j;
                j = str[i + a];
                str[i + a] = str[b - i];
                str[b - i] = j; 
            }
        }
        else if(s == "replace"){
            cin >> p;
            for (int i = 0; i < b - a + 1; i++)
                str[i + a] = p[i];
        }
    }
}



Measured memory_bytes: 3208
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class B
{
	public static void Main()
	{
		int N = GetInt();
		int D = GetInt();
		int range = 2 * D + 1;
		Console.WriteLine((N + range - 1) / range);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


Measured memory_bytes: 11092
// AOJ NTL_1- D Elementary Number Theory - Euler's Phi Function
// 2017.10.31 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define SIZE  50
int factor[SIZE], size;

int ptbl[] = {
         3,   5,   7,  11,  13,  17,  19,  23,  29,
   31,  37,  41,  43,  47,  53,  59,  61,  67,  71,
   73,  79,  83,  89,  97, 101, 103, 107, 109, 113,
  127, 131, 137, 139, 149, 151, 157, 163, 167, 173,
  179, 181, 191, 193, 197, 199, 211, 223, 227, 229,
  233, 239, 241, 251, 257, 263, 269, 271, 277, 281,
  283, 293, 307, 311, 313, 317, 331, 337, 347, 349,
  353, 359, 367, 373, 379, 383, 389, 397, 401, 409,
  419, 421, 431, 433, 439, 443, 449, 457, 461, 463,
  467, 479, 487, 491, 499, 503, 509, 521, 523, 541,
  547, 557, 563, 569, 571, 577, 587, 593, 599, 601,
  607, 613, 617, 619, 631, 641, 643, 647, 653, 659,
  661, 673, 677, 683, 691, 701, 709, 719, 727, 733,
  739, 743, 751, 757, 761, 769, 773, 787, 797, 809,
  811, 821, 823, 827, 829, 839, 853, 857, 859, 863,
  877, 881, 883, 887, 907, 911, 919, 929, 937, 941,
  947, 953, 967, 971, 977, 983, 991, 997, 0 };

void prime_factor(int n)
{
  int i, d, sw;
  int *pp;

  size = 0;
  if ((n & 1) == 0) {
    factor[size++] = 2;
    do n >>= 1;
    while ((n & 1) == 0);
  }
  for (pp = ptbl; n > 1 && *pp > 0; pp++) {
    if (n % *pp) continue;
    d = *pp;
    factor[size++] = d;
    do n /= d;
    while (n % d == 0);
  }
  if (n > 1) {
    int b = (int)sqrt(n);
    for (i = 1009, sw = 0; n > 1; ) {
      if (i > b) {
        factor[size++] = n;
        break;
      }
      if (n % i == 0) {
        factor[size++] = i;
        do n /= i;
        while (n % i == 0);
      }
      if (sw) { i += 2, sw = 0; }
      else    { i += 4, sw = 1; }
    }
  }
}

int eulerPhiFunction(int n)
{
	int i;
	prime_factor(n);
	for (i = 0; i < size; i++) n /= factor[i], n *= (factor[i]-1);
	return n;
}

int main()
{
	int n;

	scanf("%d", &n);
	printf("%d\n", eulerPhiFunction(n));
	return 0;
}

Measured memory_bytes: 1840
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;

int main()
{
    int w, h, x, y;
    scanf("%d%d%d%d", &w, &h, &x, &y);
    printf("%lf %d\n", double(w)*double(h) / 2, x + x == w&&y + y == h);

    
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
dict_ = {i: a for i, a in enumerate(A)}
list_ = []
for k, v in sorted(dict_.items(), key=lambda x: x[1]):
    list_.append(str(k+1))
str_ = ' '.join(list_)
print(str_)


Measured memory_bytes: 31708
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N; int L = 0; int H = 0; cin >> N;vector<int>A(8);
	for (int X = 0; X < N; X++) {
		int S; cin >> S;
		if (S < 3200 && A[S / 400] == 0) A[S / 400] = 1;
		if (S > 3199)L++;
	}
	cout << max(1,A[0]+A[1]+A[2]+A[3]+A[4]+A[5]+A[6]+A[7]) << " " << L+A[0]+A[1]+A[2]+A[3]+A[4]+A[5]+A[6]+A[7] << endl;
}


Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <cstring>
#include <set>
using namespace std;


int main() {
  int n, h;
  while (cin >> n >> h, n+h) {
    set<int> cube;
    
    for (int i=0; i<h; i++) {
      string s;
      int a, b;
      cin >> s;
      cin >> a >> b;
      a--;b--;
      if (s == "xy") {
        for (int j=0; j<n; j++) {
          cube.insert(a*500*500+b*500+j);
        }
      } else if (s == "xz") {
        for (int j=0; j<n; j++) {
          cube.insert(a*500*500+j*500+b);
        }
      } else {
        for (int j=0; j<n; j++) {
          cube.insert(j*500*500+a*500+b);
        }
      }
    }
    cout << n*n*n-cube.size() << endl;
  }
}

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

#define MN 50001

int main()
{
	bool pr[MN] = {0};
	for(int i=2; i<MN; i++) pr[i]=1;

	for(int i=2; i*i<MN; i++)
	{
		if(pr[i])
		for(int j=i*2; j<MN; j+=i)
		{
			pr[j] = 0;
		}
	}

	int n,c;
	while(cin >> n, n)
	{
		c=0;
		for(int i=2; i<=n/2; i++)
		{
			if(pr[i] && pr[n-i]) c++;
		}
		cout << c << endl;
	}
}

Measured memory_bytes: 912
#include <iostream>
#include <cstdio>
#include <map>
using namespace std;
//@date: 2020-02-16 20:38:29
//@state:
//@purpose:

map<string,int> mp;

int main()
{
    int mx=-9999,n;
    string t;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>t;
        mp[t]++;
        if(mp[t]>mx)mx=mp[t];
    }
    for(auto &i:mp){
        if(i.second==mx)
            cout<<i.first<<endl;
    }
    return 0;
}

Measured memory_bytes: 26496
#include <stdio.h>

int main(){
    int A;
    int B;
    scanf("%d %d",&A,&B);
    
    int a=A*B;
    int b=A+B;
    int c=A-B;
    
    if(A*B-(A+B)>0){
        if(A*B-(A-B)>0){
            printf("%d",a);
        }else{
            printf("%d",c);
        }
    }else{
        if((A+B)-(A-B)>0){
            printf("%d",b);
        }else{
            printf("%d",c);
        }
    }
    return 0;
}


Measured memory_bytes: 128
class Koch
  DEG = (60 * Math::PI / 180.0)

  def initialize
  end

  class Point
    attr_accessor :x, :y
    def initialize(x = 0.0, y = 0.0)
      @x = x
      @y = y
    end

    def dump
      puts "%.5f %.5f" % [@x, @y]
    end
  end


  def solve(d, p1, p2)
    return if d==0

    s = Point.new
    s.x = (2*p1.x + p2.x) / 3.0;
    s.y = (2*p1.y + p2.y) / 3.0;

    t = Point.new
    t.x = (p1.x + 2*p2.x) / 3.0;
    t.y = (p1.y + 2*p2.y) / 3.0;

    u = Point.new
    u.x = (t.x - s.x)*Math.cos(DEG) - (t.y - s.y)*Math.sin(DEG) + s.x
    u.y = (t.x - s.x)*Math.sin(DEG) + (t.y - s.y)*Math.cos(DEG) + s.y

    solve(d-1, p1, s)
    s.dump
    solve(d-1, s, u)
    u.dump
    solve(d-1, u, t)
    t.dump
    solve(d-1, t, p2)
  end
end

d = gets.to_i
kh = Koch.new
p1 = Koch::Point.new(0.0, 0.0)
p2 = Koch::Point.new(100.0, 0.0)
p1.dump
kh.solve(d, p1, p2)
p2.dump

Measured memory_bytes: 8988
//organize and stay in moment
//Abhinav - IIITA
//I love you Disha
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define ld long double
int prime[100005] ,arr[100005],pre[100005];
void seive(){
	prime[0]=prime[1]=1;
	for(int i=2;i<100005;++i){
		if(prime[i]==0)
		for(int j=2*i;j<100005;j+=i)
			prime[j]=1;
	}
}
int32_t main(){
	int n; cin>>n;
	int arr[n];
	for(int i=0;i<n;++i)
		cin>>arr[i];
	int cost[n];
	cost[0]=0;
	cost[1]=abs(arr[1]-arr[0]);
	for(int i=2;i<n;++i)
		cost[i]=min(cost[i-1]+abs(arr[i]-arr[i-1]),cost[i-2]+abs(arr[i]-arr[i-2]));
	cout<<cost[n-1];
	return 0;
}

Measured memory_bytes: 1792
N = int(input())
W = [input() for i in range(N)]
result = "No"

if len(W) == len(set(W)):
    for i in range(N):
        if 0 < i and W[i-1][-1] != W[i][0]:
            result = "No"
            break
        else:
            result = "Yes"
print(result)


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

using namespace std;
typedef long long LL;
int main(void) {
  LL p = 1000000007;
  int n;
  cin >> n;
  vector<int> cs(n);
  for(int &c: cs) cin >> c;
  cs.erase(std::unique(cs.begin(), cs.end()), cs.end());
  vector<LL> pre(212345);
  LL tmp = 1;
  for(int c: cs) {
    tmp = tmp + pre[c];
    tmp %= p;
    pre[c] = tmp;
  }
  cout << tmp % p << endl;
  return 0;
}


Measured memory_bytes: 2688
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>
#include <functional>
#include <sstream>
#include <cstdio>

using namespace std;

#define ERROR_ID		0

#define PROCESS_ERROR(Condition)    \
{                                   \
		if (!(Condition))           \
		{                           \
			goto Exit0;             \
		}                           \
}

typedef unsigned char			BYTE;
typedef int						BOOL;
typedef unsigned long			DWORD;
typedef long long				LLONG;

inline int read() {
	int ret = 0, f = 1;
	char ch = getchar();
	while (ch<'0' || ch>'9') {
		if (ch == '-') f = -f;
		ch = getchar();
	}
	while (ch >= '0'&&ch <= '9') ret = ret * 10 + ch - '0', ch = getchar();
	return ret * f;
}//快读优化

int main(int argc, char* argv[])
{
	LLONG			lNumberM;
	LLONG			lNumberN;

	cin >> lNumberM >> lNumberN;

	if (lNumberM * 2 >= lNumberN)
	{
		cout << lNumberN / 2 << endl;
	}
	else
	{
		cout << lNumberM + (lNumberN - 2 * lNumberM) / 4 << endl;
	}

	return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DPartition solver = new DPartition();
        solver.solve(1, in, out);
        out.close();
    }

    static class DPartition {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long n = in.nextInt(), m = in.nextInt();
            long answer = 0;
            for (int i = 1; i * i <= m; i++) {
                if (m % i != 0)
                    continue;
                if (i * n <= m) {
                    answer = Math.max(answer, i);
                }
                if ((m / i) * n <= m) {
                    answer = Math.max(answer, m / i);
                }
            }

            out.println(answer);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 21460
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>

using namespace std;

int main() {
	int i, j, n, k, num = 1;

	cin >> n >> k;

	for (i = 0; i < n; i++) {
		if (num * 2 < (num + k)) {
			num = num * 2;
		}
		else {
			num = num + k;
		}
	}

	cout << num << endl;


	
	return 0;
}

Measured memory_bytes: 256
n=int(input())
l=[]
for i in range(n):
    x,y=map(int,input().split())
    l.append([x,y])
l=sorted(l)
s=set()
for j in range(n-1):
    for k in range(j,n):
        s.add((l[k][0]-l[j][0],l[k][1]-l[j][1]))
s_l=sorted(list(s))
cnt=[0]*len(s_l)
dic={}
for i in range(len(s_l)):
    dic[s_l[i]]=i
for j in range(n-1):
    for k in range(j+1,n):
        cnt[dic[(l[k][0]-l[j][0],l[k][1]-l[j][1])]]+=1
if n==1:
    print(1)
    exit()
print(n-max(cnt))


Measured memory_bytes: 9296
while True:
    try:
        p, q = map(int, input().split())
        m = p % q
        i = -1
        decs = ['']
        mods = [m]
        while m != 0:
            d, m = divmod(m * 10, q)
            decs.append(str(d))
            if m not in mods:mods.append(m)
            else:
                i = mods.index(m)
                break
        if len(decs) == 0:print(0)
        else:
            print(''.join(decs))
            if m != 0 and i > -1:
                for j, dec in enumerate(decs):
                    if j > i:decs[j] = '^' * len(decs[j])
                    else:decs[j] = ' ' * len(decs[j])
                print(''.join(decs))
    except:break



Measured memory_bytes: 5608
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
using std::sort;

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

    vector<string> vs;
    for (int i = 0; i < n; i++) {
        string word;
        cin >> word;
        vs.push_back(word);
    }

    sort(vs.begin(), vs.end());
    for (auto word: vs) cout << word;
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int j,i;
    long long  s1,s2,s3,s4,s5;
    s1=s2=s3=s4=s5=0;
    cin>>j;
    string a;
    for(i=0;i<j;i++){
        cin>>a;
        if(a[0]=='M')
            s1++;
        if(a[0]=='A')
            s2++;
        if(a[0]=='R')
            s3++;
        if(a[0]=='C')
            s4++;
        if(a[0]=='H')
            s5++;
    }
    cout<<s1*s2*s3+s1*s2*s4+s1*s2*s5+s1*s3*s4+s1*s3*s5+s1*s4*s5+
    s2*s3*s4+s2*s3*s5+s2*s4*s5+s3*s4*s5<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

int sum(int i){
  int ans = 0;
  while(i > 0){
    ans += i % 10;
    i /= 10;
  }
  return ans;
}

int main(){
  int n;
  cin >> n;
  int ans = 1e9;
  rep(a,1,n - 1){
    int b = n - a;
    ans = min(ans , sum(a) + sum(b));
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T>using vv = vector<vector<T>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 28, MOD = 1e9 + 7; constexpr ll LINF = 1ll << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

template<typename T = int, class F = std::plus<T>, class F_INV = std::minus<T>, const T E = T()>
struct BinaryIndexedTree {
    const F op = F(); const F_INV op_inv = F_INV();
    int n; vector<T> dat;
    template<class U = vector<T>> void build(U && v) {
        static_assert(std::is_same<std::remove_reference_t<U>, vector<T>>::value, "");
        n = v.size(); dat.assign(n, E); for (int i = 0; i < n; ++i) add(i, v[i]);
    }
    void add(int k, T x) { for (int i = k; i < n; i |= i + 1) dat[i] = op(dat[i], x); }
    void update(int k, T x) { add(k, op_inv(x, query(k, k + 1))); }
    T query(int a, int b) {
        if (a == b) return E;
        T ret = E; for (int i = b - 1; i >= 0; i = (i & (i + 1)) - 1) ret = op(ret, dat[i]);
        return op_inv(ret, query(0, a));
    }
};

vector<int> vcomp;
BinaryIndexedTree<ll> bit;
vector<ll> vbit;

ll inversion_number(vector<int>& v) {
    vcomp.resize(v.size());
    copy(all(v), vcomp.begin());
    sort(vcomp.begin(), vcomp.end());
    vcomp.erase(unique(vcomp.begin(), vcomp.end()), vcomp.end());

    vbit.resize(vcomp.size());
    bit.build(vbit);
    ll inv = 0;
    for (int i = 0; i < v.size(); ++i) {
        int j = lower_bound(vcomp.begin(), vcomp.end(), v[i]) - vcomp.begin();
        inv += i - bit.query(0, j + 1);
        bit.add(j, 1);
    }

    return inv;
}

int main() {
    int N;
    cin >> N;
    ll msize = (ll)N * (N + 1) / 2;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    vector<int> Asorted = A;
    sort(all(Asorted));
    vector<int> Abinary(N);
    vector<int> accum(N + 1);

    int ok = 0;
    int ng = N;
    while (ng - ok > 1) {
        int mid = (ng + ok) / 2;

        // A[mid]以上or未満
        rep(i, N) Abinary[i] = A[i] >= Asorted[mid] ? 1 : -1;
        rep(i, N) accum[i + 1] = accum[i] + Abinary[i];

        ll inv = inversion_number(accum);
        if (msize - inv < (msize + 1) / 2) ng = mid;
        else ok = mid;
    }

    write(Asorted[ok]);
}

Measured memory_bytes: 3840
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
#include <climits>
#include <chrono>
#include <fstream>
using namespace std;

#pragma region

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

const double PI = acos(-1.0);

using ll = long long;
using P = pair<int, 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; }

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter = " ") { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

#pragma endregion


int main() {
    string s;
    cin >> s;
    int cnt = 0;
    rep(i, 4) if (s[i] == '2') cnt++;
    cout << cnt << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;
 
template <class T> using V = vector<T>;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
const long long INF = 1LL << 60;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;

 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>=(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
  
 

ll sum(ll n) {
ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int 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;
    }
}
 
 
#define comuse Comuse()
 
ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
 
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}




 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll n,m;
    ci(n>>m);
  vpll A(n);
  FOR(i,0,n){
    ci(A[i].fi>>A[i].se)
  }
  SORT(A);
  ll now=0;
  priority_queue<ll> summer;
  summer.push(0);
  ll ans=0;
  FOR(i,0,m){
    while(A[now].fi<=i+1&&now!=n){
      summer.push(A[now].se);
      now++;
    }

    if(summer.top()!=0){
    ans+=summer.top();
    summer.pop();
    }
  }
  co(ans)
}

Measured memory_bytes: 2936
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
int N = 110005;
signed main() {
	vector<bool>p(N, true);
	p[0] = p[1] = false;
	rep(i, 2, sqrt(N)) {
		if (p[i]) {
			for (int j = i + i; j < N; j += i) {
				p[j] = false;
			}
		}
	}
	vector<int>s; s.push_back(0);
	rep(i, 0, N) {
		if (p[i]) {
			s.push_back(s.back() + i);
		}
	}
	int n;
	while (cin >> n, n) {
		cout << s[n] << endl;
	}
	return 0;
}

Measured memory_bytes: 3256
require 'set'
S = gets.chomp.chars
ODD = Set.new(%w[R U D])
EVEN = Set.new(%w[L U D])

result = 'Yes'
S.each_slice(2) do |odd, even|
  break(result = 'No') unless ODD.include?(odd) && (even.nil? || EVEN.include?(even))
end

puts result


Measured memory_bytes: 1916
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
long long n,k;
int main(){
	scanf("%lld%lld",&n,&k);
	if(k&1){
		cout<<(n/k)*(n/k)*(n/k)<<endl;
		return 0;
	}
	cout<<(n/k)*(n/k)*(n/k)+((n+k/2)/k)*((n+k/2)/k)*((n+k/2)/k)<<endl;
}

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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    int n;
    cin >> n;
    vint x(n);
    rep(i, n)
    {
        cin >> x[i];
    }

    vint x2 = x;

    sort(ALL(x2));

    int l = x2[n / 2 - 1];
    int r = x2[n / 2];

    rep(i, n)
    {
        if (x[i] <= l)
        {
            cout << r << endl;
        }
        else
        {
            cout << l << endl;
        }
    }
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3840
#include <iostream>
#include <vector>
#include <algorithm>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define INF 999999999
using namespace std;

int  main(){
          int N;
          cin >> N;
          vector<int> v;
          REP(i,N){
                    int z;
                    cin >> z;
                    z--;
                    v.push_back(z);
          }

          int now=0,c=0;
          while(1){
                    if (now == 1){
                              cout << c << endl;
                              break;
                    }
                    if (c >= N){
                              cout << -1 << endl;
                              break;
                    }
                    c++;
                    now = v[now];
          }
          return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0; i<n-1; i++){
    int x;
    cin >> x;
    a[x-1]++;
  }
  for(int i=0; i<n; i++){
    cout << a[i] << endl;
  }

}


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

int main()
{
    int x, y, z;
    string a, b, c;
    
    cin >> a >> b >> c;
    
    x = a.size();
    y = b.size();
    z = c.size();
    
    if((a[x-1] == b[0]) && (b[y-1] == c[0])) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
//min max sum

#include<iostream>
using namespace std;

int main()
{
	long a,n,min,max,sum;
	cin >> n >>a;

	min = a; max = a; sum = a;
	
	for (int i = 0; i < n-1; i++)
	{
		cin >> a;

		if (max < a)max = a;
		if (min > a)min = a;

		sum += a;
	}
	cout << min << " " << max << " " << sum << endl;

	return 0;

}

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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;


int main(){

    int N,M;
    cin>>N>>M;
    char ans[N];
    rep(i,N)ans[i]='0';

    rep(i,M){
        int t;
        char c;
        cin>>t>>c;
        
        if((t==1 && c=='0'&& N>1) || (ans[t-1]!='0' && ans[t-1]!=c)){
            cout<<"-1"<<endl;
            return 0;
        }
        ans[t-1]=c;
    }
    if(ans[0]=='0' && N>1){
        ans[0]='1';
    }
    
    //if(ans[0])ans[0]='1';
    rep(i,N)cout<<ans[i];
    cout<<endl;

    

    return 0;

}
/*


*/


Measured memory_bytes: 256
def solve():
    n, k = map(int, input().split())
    s = input()

    t = []
    cont = 0
    p = '1'
    for c in s:
        if c == p:
            cont += 1
        else:
            t.append(cont)  # * (1 if p == '0' else -1))
            p = c
            cont = 1
    t.append(cont)  # * (1 if p == '0' else -1))
    t.extend([0] * 2)
    if len(t) % 2 == 1:
        t.append(0)
    # [直立,逆立,...直立,逆立]

    st = t[::2]  # 直立
    acc = [0]  # 直立,逆立の累積和

    p = 0
    j = 0
    while j < len(t) - 1:
        p += sum(t[j:j + 2])
        j += 2
        acc.append(p)

    ret = 0
    for j, (x, acc_) in enumerate(zip(st, acc)):
        ret = max(ret, (x + acc_) - acc[max(0, j - k)])
    return ret


if __name__ == '__main__':
    print(solve())


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

int main() {
  
  int N; cin >> N; vector<int> vec(N); int ans = 0;
  
  for (int i = 0; i < N; i++) cin >> vec.at(i);
  
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      int dif = abs(vec.at(i) - vec.at(j));
      ans = max(ans, dif);
    }
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
class Stack:
    MAX = 101

    def __init__(self):
        self.S = [None] * self.__class__.MAX
        self.top = 0

    def is_empty(self):
        return self.top == 0

    def is_full(self):
        return self.top >= self.__class__.MAX - 1

    def push(self, x):
        self.top += 1
        self.S[self.top] = x

    def pop(self):
        self.top -= 1
        return self.S[self.top + 1]


stack = Stack()
[stack.push(eval("".join(map(str,[stack.pop(),s,stack.pop()][::-1]))))
 if s in["+","-","*"]else stack.push(int(s))for s in input().split()]
print(stack.pop())



Measured memory_bytes: 5612
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;
const int MaxN = 1e5;
bool flag, ok;
LL sum, ans, anv, anw;
int n;
int a[MaxN + 5], b[MaxN + 5], c[MaxN + 5];
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		scanf("%d", &a[i]);
		b[i] = a[i];
		c[i] = a[i];
	}
	sum = a[1];
	if(a[1] < 0)flag = 1, ok = 1;
	if(a[1] != 0){
	for(int i = 2; i <= n; i++){
		if(flag == 1){
			if(sum + a[i] <= 0){
				LL ant = sum + a[i];
				int t = a[i];
				a[i] = 1 - sum;
				ans += (a[i] - t);
				sum += a[i];
			}
			else sum += a[i];
			flag = 0;
		}
		else{
			if(sum + a[i] >= 0){
				LL ant = sum + a[i];
				int t = a[i];
				a[i] = -1 - sum;
				ans += (t - a[i]);
				sum += a[i];
			}
			else sum += a[i];
			flag = 1;
		}
	}
	}
	if(c[1] == 0)ans = 1LL << 62;
	int tr = b[1];
	if(ok)b[1] = 1, flag = 0;
	else b[1] = -1, flag = 1;
	anv += (abs(b[1] - tr));
	sum = b[1];
	for(int i = 2; i <= n; i++){
		if(flag == 1){
			if(sum + b[i] <= 0){
				LL ant = sum + b[i];
				int t = b[i];
				b[i] = 1 - sum;
				anv += (b[i] - t);
				sum += b[i];
			}
			else sum += b[i];
			flag = 0;
		}
		else{
			if(sum + b[i] >= 0){
				LL ant = sum + b[i];
				int t = b[i];
				b[i] = -1 - sum;
				anv += (t - b[i]);
				sum += b[i];
			}
			else sum += b[i];
			flag = 1;
		}
	}
	int te = c[1];
	if(!ok)c[1] = 1, flag = 0;
	else c[1] = -1, flag = 1;
	anw += (abs(c[1] - te));
	sum = c[1];
	for(int i = 2; i <= n; i++){
		if(flag == 1){
			if(sum + c[i] <= 0){
				LL ant = sum + c[i];
				int t = c[i];
				c[i] = 1 - sum;
				anw += (c[i] - t);
				sum += c[i];
			}
			else sum += c[i];
			flag = 0;
		}
		else{
			if(sum + c[i] >= 0){
				LL ant = sum + c[i];
				int t = c[i];
				c[i] = -1 - sum;
				anw += (t - c[i]);
				sum += c[i];
			}
			else sum += c[i];
			flag = 1;
		}
	}
	printf("%lld\n", min(ans, min(anv, anw)));
}

Measured memory_bytes: 1280
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
	switch (a){
      case 25:
        System.out.println("Christmas");
        break;
      case 24:
        System.out.println("Christmas Eve");
        break;
      case 23:
        System.out.println("Christmas Eve Eve");
        break;
      case 22:
        System.out.println("Christmas Eve Eve Eve");
        break;
      default:
        break;
    }
  }
}


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


int main(){
  int N;
  cin >> N;
  
  if(N%10==0){
    cout << 10 << endl;
  }
 
  
  else if(N%10!=0){
    int a=N/1000000;
    int b=(N%1000000)/100000;
    int c=(N%100000)/10000;
    int d=(N%10000)/1000;
    int e=(N%1000)/100;
    int f=(N%100)/10;
    int g=N%10;
    
    cout << a+b+c+d+e+f+g << endl;
  }
}
    

Measured memory_bytes: 256
A, B, C, K = list(map(int, input().split()))

if K%2 == 0:
  if A-B > 10**18:
    print("Unfair")
  else:
    print(A-B)
else:
  if -(A-B) > 10**18:
    print("Unfair")
  else:
    print (-(A-B))

Measured memory_bytes: 8892
n, m = map(int, input().split())
N = [0]*n
t = [0]*n
if n>1:
    N[0]=1
f = 0
for i in range(m):
    s, c = map(int, input().split())
    if t[s-1]!=0 and N[s-1]!=c:
        f = 1
    t[s-1] = 1
    N[s-1] = c

if n!=1 and N[0]==0:
    print(-1)

elif f==1:
    print(-1)

else:
    for i in range(n):
        print(N[i],end="")

Measured memory_bytes: 9220
//Author: master19
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define ff first 
#define ss second 
#define pb push_back
#define endl "\n"
#define mod 1000000007LL // fixed...
#define modd 1000000007LL // Can be changed for global use
#define all(arr) arr.begin(),arr.end()
#define x(arr) arr.begin(),arr.end()
#define ulli unsigned long long int
#define assign(x,val) memset(x,val,sizeof(x))
#define prec(val, dig) fixed << setprecision(dig) << val
#define Sort(arr) sort(arr.begin(), arr.end())
#define lower(str) transform(str.begin(), str.end(), str.begin(), ::tolower);
#define upper(str) transform(str.begin(), str.end(), str.begin(), ::toupper);
#define crap ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define get(arr, num) vector < ll > arr(num); for(int i=0; i<num; i++)cin >> arr[i];
#define get_set(arr, num, st, type) set < type > st; for(int i=0; i<num; i++) st.insert(arr[i]);
#define put(arr, num) for(int i=0; i<num; i++)cout << arr[i] << " "; cout << endl;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > new_ds; 
void debug_out() { cerr << endl; }
template <typename HeadStart, typename... TailEnd>
void debug_out(HeadStart H, TailEnd... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
ll lets_do_it();
pair < ll, ll > xy[] = {{-1, 0}, {1, 0} , {0, -1}, {0, 1}};
pair < ll, ll > dig[] = {{-1, -1}, {-1, 1}, {1, 1}, {1, -1}};
bool isValid(ll x, ll y, ll row, ll col){
    return ((x>=0) && (y >=0)  && (x < row) && (y < col));
}
int main(int argc, const char** argv) {
    crap;
    ll test = 1;
    // cin >> test;
    for(int loop=0; loop<test; loop++){
        // cout << "Case #" << (loop+1) << ": "; 
        lets_do_it();
    }
    return 0;
}
ll dfs(vector < set < ll > > &arr, vector < ll > &visit, ll num, ll start){
    visit[start] = true;
    ll value = 0;
    for(auto it: arr[start]){
        if(!visit[it]){
            value += dfs(arr, visit, num, it);
        }
    }
    return value + 1;
}
ll lets_do_it(){
    // Your code goes by here !!
    ll num, value;
    cin >> num >> value;
    vector < set < ll > > arr(num+1);
    for(int i=0; i<value; i++){
        ll a, b;
        cin >> a >> b;
        arr[a].insert(b);
        arr[b].insert(a);
    }
    ll maxi = 0;
    vector < ll > visit(num+1, false);
    for(int i=1; i<=num; i++){
        if(!visit[i]){
            ll val = dfs(arr, visit, num, i);
            maxi = max(maxi, val);
        }
    }
    cout << maxi << endl;




    return 0;
}


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

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl
#define debug2(s, t, u) cout << s << " " << t << " " << u << endl
#define printvec(v)       \
    for (auto &&i : v)    \
        cout << i << " "; \
    cout << endl

using namespace std;
using i64 = long long;

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

    vector<bool> seen1(10, false);
    vector<vector<bool>> seen2(10, vector<bool>(10, false));

    int ct = 0;
    for (int i = 0; i < 10; i++)
    {
        int index = -1;
        for (int ix = 0; ix < n; ix++)
        {
            if (s[ix] != i + '0')
                continue;
            index = ix;
            break;
        }
        if (index < 0)
            continue;
        for (int j = 0; j < 10; j++)
        {
            int subindex = -1;
            for (int ix = index + 1; ix < n; ix++)
            {
                if (s[ix] != j + '0')
                    continue;
                subindex = ix;
                break;
            }
            if (subindex < 0)
                continue;
            map<char, int> mp;
            for (int ix = subindex + 1; ix < n; ix++)
            {
                mp[s[ix]]++;
            }
            ct += mp.size();
        }
    }
    cout << ct << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a[100010];
int main()
{
	long long n,ba=1;
	cin>>n;
	for(int t=0;t<n;t++)
	{
		cin>>a[t];
		if(a[t]==0)
		{
			cout<<0;
			return 0;
		}
	}
	for(int t=0;t<n;t++)
	{
		if((long double)(ba)>1000000000000000000.0/(long double)(a[t]))
		{
			cout<<"-1";
			return 0;
		}

		ba*=a[t];
	}
	cout<<ba;
	return 0;
}

Measured memory_bytes: 4308
#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;



int32_t main()
{


    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS



    int x,k,d;
    cin >> x >> k >> d;


    int y = min(abs(x)/d,k);

    if(x > 0)x -= y*d;
    else x += y*d;

    k -= y;

    

    if(k%2 == 0)
    {
      cout << abs(x) << endl;
    }
    else
    {
      cout << min(abs(x-d),abs(x+d)) << endl;
    }

    return 0;
}


Measured memory_bytes: 3636
import java.util.*;

public class Main{

    public static void main(String args[]){

        Scanner scan = new Scanner(System.in);
        Long h = scan.nextLong();

        System.out.println(calc(h)/2);
    }

    static long counter = 0;
    static long cc = 0;
    static long calc(long h){
        cc++;
        if(h != 0){
            counter += Math.pow(2,cc);
            return calc(h/2);
        }else{
            return counter;
        }
    }

    static int factorial(int n){
        if(n == 0){
          return 1;
        }
        return n * factorial(n-1);
      }
}

Measured memory_bytes: 23636
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

mat graph;

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

    string s;
    cin >> s;
    ll n = s.size();
    if (s[n-1] == '1' or s[0] == '0') {
        cout << "-1\n";
        return 0;
    }

    Rep (i, n/2) {
        if (s[i] != s[n-2-i]) {
            cout << "-1\n";
            return 0;
        }
    }

    graph.assign(n, vec());

    ll tmp = 0;
    Rep (i, n-1) {
        graph[tmp].push_back(i+1);
        graph[i+1].push_back(tmp);
        if (s[i] == '1') {
            tmp = i+1;
        }
    }

    Rep (i, n) {
        for (ll e : graph[i]) {
            if (i < e) {
                cout << i+1 << " " << e+1 << "\n";
            }
        }
    }
}

Measured memory_bytes: 7492
N = int(input())
W = []
G = [[] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split())
    W.append((a,b))
    G[a].append(b)
    G[b].append(a)
K = 0
for i in range(1,N+1):
    n = len(G[i])
    K = max(K,n)
print(K)
d = {}
D = {}
D[1] = 1
k = 1
H = []
list = [1]
sumi = []
while list:
    x = list.pop(0)
    sumi.append(x)
    Y = G[x]
    k = D[x] + 1
    while Y:
        y = Y.pop(0)
        if x in G[y]:
            G[y].remove(x)
        if k > K:
            k -= K
        list.append(y)
        d[(x,y)] = k
        D[y] = k 
        k += 1
        if k > K:
            k -= K
                
for i in range(N-1):
    a,b = W[i]
    print(d[(a,b)])

Measured memory_bytes: 50320
fn main() {
    let stdin = std::io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).ok();
    let n: usize = buf.trim().parse().unwrap_or(0);

    let mut buf = String::new();
    stdin.read_line(&mut buf).ok();
    let vec: Vec<&str> = buf.split_whitespace().collect();
    let mut a: Vec<u32> = vec.iter().map(|&x| x.parse().unwrap_or(0)).collect();

    for i in 1..n {
        for (k, e) in a.iter().enumerate() {
            print!("{}", e);
            if k != n - 1 {
                print!(" ");
            }
        }
        println!("");
        let key = a[i];
        let mut j = i - 1;
        while a[j] > key {
            a[j+1] = a[j];
            if j == 0 {
                break
            } else {
                j -= 1;
            }
        }
        a[j+1] = key;
        if a[0] > a[1] {
            let key = a[1];
            a[1] = a[0];
            a[0] = key;
        }
    }
    for (k, e) in a.iter().enumerate() {
        print!("{}", e);
        if k != n - 1 {
            print!(" ");
        }
    }
    println!("");
}



Measured memory_bytes: 5032
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  vector<int> v(N);
  rep(i,N)cin >> v[i];
  vector<int> w(N+1,0);
  rep(i,N) w[v[i]] = w[v[i]-1]+1;
  int m = 0;
  rep(i,N) m = max(m,w[i+1]);
  cout << N-m << endl;
  return 0;
}


Measured memory_bytes: 1792