akhauriyash/Code-Regression huggingface dataset:
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	int n, k; cin >> n >> k;
    vector<int> p(n);
    rep(i, n) {
        cin >> p[i];
    }
    sort(all(p));
    int sum = 0;
    rep(i, k) {
        sum += p[i];
    }
    cout << sum << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 3668
#include<stdio.h>

int main(){
  int a,b,d,r;
  scanf("%d %d",&a,&b);
  if(1<=a && a<=1000000000 && 1<=b && b<=1000000000){
  d = a	/ b;
  r = a	% b;
  double x = a;
  double y = b;
  double f = x / y;
  printf("%d %d %.5lf\n",d,r,f);
  }
  return 0;
}

Measured memory_bytes: 1068
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<stack>
#include<iostream>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define MOD 1000000007
#define vec(a) vector<int>a
using namespace std;



int main()
{
#ifndef ONLINE_JUDGE
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
#endif
	ll n,i,j,k;
	cin>>n;
	k=n;
	string str;
	cin>>str;
	j=str.length();
	n=min(n,j);
	for(i=0;i<n;i++)
		cout<<str[i];
	if(j>k)
	cout<<"..."<<"\n";
}
	

Measured memory_bytes: 3588
#include <bits//stdc++.h>
using namespace std;
#define rep(i,n,k) for(int i=n;i<k;i++)
#define int long long
#define P make_pair
#define F first
#define S second
signed main(void){
    int n,m,ans,p,q;
    ans=0;
    string s,t,u;
    cin>>n>>m;
    int expect[n];
    int k=0;
    int h=0;
    rep(i,0,n){cin>>expect[i];expect[i]=(expect[i]+1);}
    rep(i,0,n){
        if(i<m){
            h+=(expect[i]);
            k=h;
        }
        else{
            h=h-expect[i-m]+expect[i];
            
            if(k<h)
            k=h;
        }
    }
    if(k%2==0)
    cout<<k/2<<endl;
    else
    cout<<k/2<<".5"<<endl;
    return 0;


}

Measured memory_bytes: 1792
package main

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

// S
var (
	S []string
	t [][]int
	H int
	W int
)

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func printIntln(v ...int) {
	if len(v) == 0 {
		return
	}
	b := make([]byte, 0, 4096)
	for i := 0; i < len(v)-1; i++ {
		b = append(b, strconv.Itoa(v[i])...)
		b = append(b, " "...)
	}
	b = append(b, strconv.Itoa(v[len(v)-1])...)
	fmt.Println(string(b))
}

func bfs(q [][2]int) [][2]int {
	warpq := make([][2]int, 0)
	for len(q) != 0 {
		h, w := q[0][0], q[0][1]
		warpq = append(warpq, [2]int{h, w})
		q = q[1:]
		if h-1 >= 0 && t[h-1][w] > t[h][w] {
			q = append(q, [2]int{h - 1, w})
			t[h-1][w] = t[h][w]
		}
		if h+1 < H && t[h+1][w] > t[h][w] {
			q = append(q, [2]int{h + 1, w})
			t[h+1][w] = t[h][w]
		}
		if w-1 >= 0 && t[h][w-1] > t[h][w] {
			q = append(q, [2]int{h, w - 1})
			t[h][w-1] = t[h][w]
		}
		if w+1 < W && t[h][w+1] > t[h][w] {
			q = append(q, [2]int{h, w + 1})
			t[h][w+1] = t[h][w]
		}
	}
	return warpq
}

func main() {
	defer flush()

	H = readInt()
	W = readInt()
	Ch := readInt() - 1
	Cw := readInt() - 1
	Dh := readInt() - 1
	Dw := readInt() - 1
	S = make([]string, H)
	for i := 0; i < H; i++ {
		S[i] = readString()
	}

	t = make([][]int, H)
	for i := 0; i < H; i++ {
		t[i] = make([]int, W)
		for j := 0; j < W; j++ {
			if S[i][j] == '#' {
				t[i][j] = -1
			} else {
				t[i][j] = math.MaxInt64
			}
		}
	}

	t[Ch][Cw] = 0
	q := make([][2]int, 0)
	q = append(q, [2]int{Ch, Cw})
	warpq := bfs(q)
	if t[Dh][Dw] != math.MaxInt64 {
		println(t[Dh][Dw])
		return
	}

	for {
		q := make([][2]int, 0)
		for len(warpq) != 0 {
			h, w := warpq[0][0], warpq[0][1]
			warpq = warpq[1:]
			for i := max(0, h-2); i <= min(H-1, h+2); i++ {
				for j := max(0, w-2); j <= min(W-1, w+2); j++ {
					if t[i][j] <= t[h][w]+1 {
						continue
					}
					t[i][j] = t[h][w] + 1
					q = append(q, [2]int{i, j})
				}
			}
		}
		if len(q) == 0 {
			break
		}
		warpq = bfs(q)
		if t[Dh][Dw] != math.MaxInt64 {
			break
		}
	}

	if t[Dh][Dw] == math.MaxInt64 {
		println(-1)
	} else {
		println(t[Dh][Dw])
	}
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}

var stdoutWriter = bufio.NewWriter(os.Stdout)

func flush() {
	stdoutWriter.Flush()
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdoutWriter, args...)
}


Measured memory_bytes: 40368
#include <iostream>
#include <vector>


int main()
{
	std::vector<std::pair<int, int>> list;

	for (int i = 0; i < 3; ++i)
	{
		int n, k;
		std::cin >> n;
		std::cin >> k;
		list.emplace_back(n, k);
	}

	int a[4] = {0};
	bool flg = false;
	for (auto c : list)
	{
		a[c.first - 1]++;
		a[c.second - 1]++;
	}
	int cnt = 0;
	for (int i = 0; i < 4; ++i)
	{
		if (a[i] == 2)
			cnt++;
	}
	if (cnt == 2)flg = true;
	if (flg)
		std::cout << "YES" << std::endl;
	else
		std::cout << "NO" << std::endl;

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    cout << ( A + B == C + D ? "Balanced" : A + B > C + D ? "Left" : "Right") << endl;
    return 0;
}

Measured memory_bytes: 256
# ABC139E - League
from collections import deque


def main():
    N, *A = map(int, open(0).read().split())
    B = {}
    for i in range(N):
        x = i * (N - 1)
        B[i + 1] = deque(A[x : x + N - 1])
    cnt, cur, days = 0, [0] * (N + 1), [0] * (N + 1)
    q = deque(list(range(1, N + 1)))
    while q:
        x = q.popleft()
        if not B[x]:  # player x has finished all games
            continue
        y = B[x].popleft()
        if cur[y] == x:  # player y's next game is against x and vice versa
            cnt += 1
            days[x] = days[y] = max(days[x], days[y]) + 1
            cur[x], cur[y] = 0, 0
            q.append(x), q.append(y)
        else:  # the opponent will do another game before playing against x
            cur[x] = y
    flg = cnt == N * (N - 1) // 2  # finished all scheduled games or not
    print(max(days) if flg else -1)


if __name__ == "__main__":
    main()

Measured memory_bytes: 104788
from functools import reduce
from fractions import gcd
from collections import defaultdict
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    d = defaultdict(int)
    for a in A:
        d[a] += 1
    
    res = 0
    for k in d.keys():
        if d[k] >= k:
            res += d[k] - k
        else:
            res += d[k]
    
    print(res)
    
    


if __name__ == '__main__':
    main()

Measured memory_bytes: 90660
#include<bits/stdc++.h>
using namespace std;
#define ll long long
vector<ll>v;
void SieveOfEratosthenes(ll n) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (ll p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p 
            for (ll i=p*2; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (ll p=2; p<=n; p++) 
       if (prime[p]) 
          v.push_back(p);
} 

int main()
{
	SieveOfEratosthenes(100005);
	ll x;
	cin>>x;
	// auto itr;
	for(auto itr:v)
	{
		if(itr>=x)
		{
			x=itr;
			break;
		}
	}
	cout<<x<<endl;
}

Measured memory_bytes: 512
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1005
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline ll read()
{
	ll x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}
const ll mod=1e9+7;
const int N=2e5+10;
ll a[N],n,k;
vector<ll>G1,G2;
bool cmp2(ll x,ll y)
{
    return abs(x)<abs(y);
}
bool cmp1(ll x,ll y)
{
    return x>y;
}
bool cmp3(ll x,ll y)
{
    return x<y;
}
void run1()
{
    //puts("***");
    sort(G1.begin(),G1.end(),cmp1);
    sort(G2.begin(),G2.end(),cmp3);
//    for(ll v:G1) printf("%lld ",v);puts("");
//    for(ll v:G2) printf("%lld ",v);puts("");

    int id1=0,id2=0;
    ll ans=1;
    if(k%2){
        ans=G1[id1++];
    }
    while(id1+1<G1.size()&&id2+1<G2.size()&&id1+id2+2<=k){
        //printf("id1:%d id2:%d\n",id1,id2);

        if(G1[id1]*G1[id1+1]>G2[id2]*G2[id2+1]){
            ans=ans*G1[id1]%mod*G1[id1+1]%mod;
            id1+=2;
        }
        else{
            ans=ans*G2[id2]%mod*G2[id2+1]%mod;
            id2+=2;
        }
    }
    //printf("id1:%d id2:%d sz:%d\n",id1,id2,G1.size());

    while(id2+1<G2.size()&&id1+id2+2<=k){
        ans=ans*G2[id2]%mod*G2[id2+1]%mod;
        id2+=2;
    }
    while(id1+1<G1.size()&&id1+id2+2<=k){
        ans=ans*G1[id1]%mod*G1[id1+1]%mod;
        id1+=2;
    }
    //if(id1+id2<k) ans=ans*G1[id1++]%mod;
    printf("%lld\n",(ans+mod)%mod);

}
int main()
{
    n=read(),k=read();
    int zero=0;
    rep(i,1,n)
    {
        a[i]=read();
        if(a[i]>0) G1.emplace_back(a[i]);
        else if(a[i]<0) G2.emplace_back(a[i]);
        else zero++;
    }
    if(G2.size()-(G2.size()&1)+G1.size()>=k&&(k&1)<=G1.size()){
        run1();
    }
    else if(zero){
        puts("0");
    }
    else{
        sort(a+1,a+1+n,cmp2);
        ll ans=1;
        rep(i,1,k) ans=ans*a[i]%mod;
        printf("%lld\n",(ans+mod)%mod);
    }

}

/*
7 5
35 25 5 -25 -25 -25 -25
*/


Measured memory_bytes: 6604
S = list(input())

res = 0
for i in range(len(S)-1):
    if S[i] == '0' and S[i+1] == '0':
        S[i+1] = '1'
        res += 1
        
    if S[i] == '1' and S[i+1] == '1':
        S[i+1] = '0'
        res += 1
        
print(res)

Measured memory_bytes: 3956
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect_left
from heapq import heappush, heappop
from scipy.sparse.csgraph import dijkstra

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
	def dijkstra(E, start):
	    N_d = len(E)
	    dist = [INF] * N_d
	    dist[start] = 0
	    q = [(0, start)]
	    while q:
	        dist_v, v = heappop(q)
	        if dist[v] != dist_v:
	            continue
	        for u, dist_vu in E[v]:
	            dist_u = dist_v + dist_vu
	            if dist_u < dist[u]:
	                dist[u] = dist_u
	                heappush(q, (dist_u, u))
	    return dist

	n, m, s, t = MAP()

	uvab = [LIST() for _ in range(m)]

	A = [[] for _ in range(n+1)]
	B = [[] for _ in range(n+1)]

	for u, v, a, b in uvab:
		A[u].append((v, a))
		A[v].append((u, a))
		B[u].append((v, b))
		B[v].append((u, b))

	distA = dijkstra(A, s)  # 円での移動(s->i)
	distB = dijkstra(B, t)  # スヌークでの移動(t->i)

	Ans = []
	init = 10**15
	ans = INF
	for a, b in zip(distA[:0:-1], distB[:0:-1]):
		ans = min(ans, a+b)
		Ans.append(init-ans)
	Ans = Ans[::-1]
	print("\n".join(map(str, Ans)))

main()


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

int main(){
  int N;
  cin >>N;
  
  vector<int> H(N);
  rep(i,0,N) cin >>H[i];
  
  int ans = 0; 
  int a = 0;
  rep(i,0,N-1){
    if(H[i]<H[i+1]){
      ans = max(a,ans);
      a = 0;
    }else if(H[i]>=H[i+1]) a++;
  }
  ans = max(a,ans);
  cout <<ans<< endl;
}

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

int main() {
	int n; cin >> n;
	int l = 0, r = n - 1;
	string s[n];
	{
		cout << l << '\n';
		cout.flush();
		cin >> s[l];
		if(s[l] == "Vacant") return 0;
	}
	{
		cout << r << '\n';
		cout.flush();
		cin >> s[r];
		if(s[r] == "Vacant") return 0;
	}
	while(true) {
		int mid = (l + r) / 2;
		cout << mid << '\n';
		cout.flush();
		cin >> s[mid];
		if(s[mid] == "Vacant") return 0;
		if((mid - l) % 2 == 1) {
			if(s[l] == s[mid]) {
				r = mid;
			}
		}
		if((mid - l) % 2 == 0) {
			if(s[l] != s[mid]) {
				r = mid;
			}
		}
		if((r - mid) % 2 == 1) {
			if(s[r] == s[mid]) {
				l = mid;
			}
		}
		if((r - mid) % 2 == 0) {
			if(s[r] != s[mid]) {
				l = mid;
			}
		}
	}
	return 0;
}


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

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

  int i;
  char color;
  bool four_color = false;

  for(i = 0; i < N; i++){
    cin >> color;
    if(color == 'Y'){
      four_color = true;
    }
  }

    if(four_color){
      cout << "Four";
    }else{
      cout << "Three";
    }
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d %d", $N, $K);
$p = fgets(STDIN);


$array = array_map('intval', explode(' ', $p));

sort($array);

$min = [];

for ($i = 0; $i < $K; $i++) {
  $min[] = min($array);
  array_shift($array);
}

$ans = array_sum($min);

print_r ($ans);
?>

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

//#define int long long
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define dbg(x) cout<<#x" = "<<(x)<<ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

ll n, h, a[100000], b[100000], am, r;

signed main() {
	cin >> n >> h;
	rep(i,n) {
		cin >> a[i] >> b[i];
		chmax(am, a[i]);
	}
	// まず貪欲に投げる
	sort(b, b+n);
	repr(i,n-1) {
		// 投げるより効率的な振りがあるならもちろんそっちのほうがいい
		if (b[i]<am) continue;
		h -= b[i];
		r++;
		if (h<=0) break;
	}
	// 投げだけで倒せるなら終わり 倒せないなら投げる前に一番でかいaで削る必要がある
	if (h>0) r += (h + am - 1)/am;
	cout << r << ln;
}

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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<ll> a(n), b(n);
  for (int i = 0; i < n; i++) cin >> a.at(i) >> b.at(i);
  
  ll ans = 0;
  if (n % 2 == 1) {
    vector<ll> x = a, y = b;
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    ans = y.at(n / 2) - x.at(n / 2) + 1;
  }
  else {
    vector<ll> x = a, y = b;
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    ans = (y.at(n / 2 - 1) + y.at(n / 2)) - (x.at(n / 2 - 1) + x.at(n / 2)) + 1;
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 9536
#include <iostream>
#include <iomanip>
#include <cassert>

#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <limits>
#include <queue>
#include <unordered_map>
#include <list>
using namespace std;

using ll = long long;

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

int main()
{
	int N;
	cin >> N;
	vector<int> A(N);
	rep(i, N)
	{
		cin >> A[i];
	}

	sort(A.begin(), A.end());
	vector<bool> dp(A[N-1] + 1, true);

	int ans = 0;
	rep(i, N)
	{
		if (!dp[A[i]])
		{
			continue;
		}

		if (i+1 >= N || A[i] != A[i+1])
		{
			++ans;
		}

		int j = 1;
		while (j * A[i] <= A[N-1])
		{
			dp[j*A[i]] = false;
			++j;
		}
	}

	cout << ans;

	return 0;
}

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

namespace program
{
    class Program
    {
        static void Main()
        {
          var r = Input.ScanInt();
          Out(3*r*r);
        }
        static public void Out(object s) { Console.WriteLine(s); }
    }
    
    static class Input {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split().Select(x => uint.Parse(x)).ToArray(); }
        static public double[] ScanDoubleArray() { return Console.ReadLine().Split().Select(x => double.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split().Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(); }
    }

  static class ArrayExtensions {
    public static void Reverse(this Array self){
        Array.Reverse( self );
    }
    public static void Sort(this Array self){
      Array.Sort(self);
    }
    
    
  }
  
    static class MyMath {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


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

int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    rep(i,n)cin>>a[i];
    int cnt=0;
    for(int i=0;i<n;i++){
        int temp=i+1;
        if(a[i]%2==1 && temp%2==1)cnt+=1;
    }
    cout<<cnt<<endl;
}

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

using ll = long long;
#define FOR(i,m,n) for(int i = (m); i < (n); i++)
#define print(n) cout << n << endl

int main(){
    int K;
    cin >> K;
    ll ans = 0;

    FOR(a,1,K+1) FOR(b,1,K+1) FOR(c,1,K+1)
      ans += __gcd(a,__gcd(b,c));

    print(ans);
    return 0;
    
}

Measured memory_bytes: 3632
// ------------------------------------
// Date:2018/ 3/ 5
// Problem:ABC 083 MultipleGift c.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

static const int MOD = 1000000007;

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

  ll X, Y;
  cin >> X >> Y;

  ll ans = 0ll;
  while(X <= Y) {
    X *= 2;
    ans++;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <ios>
#include <iostream>
#include <vector>

#define ll long long

using namespace std;

int X, A, B;

int main()
{
    cin >> X >> A >> B;
    if (A >= B) {
        cout << "delicious" << endl;
    } else if (B - A <= X) {
        cout << "safe" << endl;
    } else {
        cout << "dangerous" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            // in
            int N = Integer.parseInt(sc.next());
            int[] q = new int[N+1];
            long ans = 0L;

            for (int i = 1; i <= N; i++) {
                for (int j = i; j <= N; j += i) {
                    ans += j;
                }
            }
            System.out.println(ans);
        }
    }
}

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

int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

    int cou = 0;
    int b, c, d;

    for(int i = 0; i < n - 2; i++){
        b = a[i];
        c = a[i + 1];
        d = a[i + 2];

        if(( b < c && c < d) || (d < c && c < b)){
            cou++;
        }
    }

    cout << cou << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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; }


int main() {
    ll k, a, b; cin >> k >> a >> b;
    ll res = 1;
    if(b <= a+2) res += k;//変換効率が悪いため、ひたすらビスケットを叩く
    else{
        //ビスケットをa枚まで増やす
        if(k < a-1) res += k;
        else{
            res += a-1;
            k -= a-1;
        }
        //ひたすらビスケットを変換する
        ll plus = b-a;
        res += k/2 * plus;
        //残り回数が奇数の場合、最後はビスケットを叩く
        if(k%2==1) res++;
    }
    cout << res << ln; 
}


Measured memory_bytes: 256
#pragma region
#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
#define tr t[root]
#define lson t[root << 1]
#define rson t[root << 1 | 1]
#define rep(i, a, n) for (long long i = a; i <= n; ++i)
#define per(i, a, n) for (long long i = n; i >= a; --i)
#define IO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
template <typename T>
void read(T &x) {
    x = 0;
    char ch = getchar();
    ll f = 1;
    while (!isdigit(ch)) {
        if (ch == '-') f *= -1;
        ch = getchar();
    }
    while (isdigit(ch)) {
        x = x * 10 + ch - 48;
        ch = getchar();
    }
    x *= f;
}
using namespace std;
/*
 *                                                     __----~~~~~~~~~~~------___
 *                                    .  .   ~~//====......          __--~ ~~
 *                    -.            \_|//     |||\\  ~~~~~~::::... /~
 *                 ___-==_       _-~o~  \/    |||  \\            _/~~-
 *         __---~~~.==~||\=_    -_--~/_-~|-   |\\   \\        _/~
 *     _-~~     .=~    |  \\-_    '-~7  /-   /  ||    \      /
 *   .~       .~       |   \\ -_    /  /-   /   ||      \   /
 *  /  ____  /         |     \\ ~-_/  /|- _/   .||       \ /
 *  |~~    ~~|--~~~~--_ \     ~==-/   | \~--===~~        .\
 *           '         ~-|      /|    |-~\~~       __--~~
 *                       |-~~-_/ |    |   ~\_   _-~            /\
 *                            /  \     \__   \/~                \__
 *                        _--~ _/ | .-~~____--~-/                  ~~==.
 *                       ((->/~   '.|||' -_|    ~~-/ ,              . _||
 *                                  -_     ~\      ~~---l__i__i__i--~~_/
 *                                  _-~-__   ~)  \--______________--~~
 *                                //.-~~~-~_--~- |-------~~~~~~~~
 *                                       //.-~~~--\
 *                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 */

#pragma endregion
const int maxn = 1e5 + 5;
ll n, W, w[maxn], val[maxn], dp[maxn];
int main() {
    IO;
    cin >> n >> W;
    rep(i, 1, n) cin >> w[i] >> val[i];
    rep(i, 1, 1e5) dp[i] = 0x3f3f3f3f;
    dp[0] = 0;
    rep(i, 1, n) for (int t = 1e5; t >= val[i]; --t) dp[t] = min(dp[t], dp[t - val[i]] + w[i]);
    for (int i = 1e5; i; --i)
        if (dp[i] <= W) {
            cout << i << endl;
            return 0;
        }
}

Measured memory_bytes: 4448
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main() {
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];
	vector<ll> b(n,0);
	rep(i,n) {
		if (i % 2 == 0) b[0] += a[i];
		else b[0] -= a[i];
	}
	rep(i,n-1) {
		b[i+1] = 2 * a[i] - b[i];
	}
	rep(i,n) {
		if (i != 0) cout << " ";
		cout << b[i];
	}
	cout << endl;
}

Measured memory_bytes: 4840
#include <stdio.h>

int main(void)
{
    int W, H, x, y, r;
    
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
    
    if (((y - r) >= 0 && H >= (y + r)) && ((x - r) >= 0 && W >= (x + r)))
    {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    
    return 0;
}

Measured memory_bytes: 584
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=998244353;
const int N=1e5+5;
const int MAXN=1e5+5;
const ll inf=0x3f3f3f3f;
int a[N],b[N];
int main(){
    std::ios::sync_with_stdio(false);
    ll n,l,r;
    cin>>n;
    ll ans=0;
    ans=(n*(n-1))/2;
    cout<<ans<<endl;
    return 0;
}





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

using namespace std;

using ll = long long;

//引数unzipには圧縮前のvectorを入れる
int compress(vector<ll>& unzip, map<ll, int>& zip) {
    sort(unzip.begin(), unzip.end());
    unzip.erase(unique(unzip.begin(), unzip.end()), unzip.end());
    for (int i = 0; i < unzip.size(); i++) {
        zip[unzip[i]] = i;
    }
    return unzip.size();
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    map<ll, int> zip;
    cout << (compress(a, zip) == n ? "YES" : "NO") << endl;
    return 0;
}

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

int n,m,cl,cr,c,ans;
struct hito{int l,r;}p[200005];
bool operator<(hito a,hito b){return a.l<b.l;}

std::priority_queue<int,std::vector<int>,std::greater<int>>heap;
int q[200005];

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;++i)
	scanf("%d%d",&p[i].l,&p[i].r);

    std::sort(p+1,p+n+1);

    for(int i=1;i<=n;++i)
    {
	heap.push(p[i].r),++cl;
	if(cl>p[i].l)q[++c]=heap.top(),heap.pop(),--cl;
    }

    std::sort(q+1,q+c+1,std::greater<int>());

    cr=m+1;
    for(int i=1;i<=c;++i)
	if(--cr<q[i])++ans,++cr;

    printf("%d\n",cl<cr?ans:n-m);
    
    return 0;
}

Measured memory_bytes: 3192
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

int main(void){
    int N,M,Q;
    cin >> N >> M >> Q;
    int a[Q],b[Q],c[Q],d[Q];
    rep(i,Q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--,b[i]--;
    }
    int ans=0;
    for(int i0=1;i0<=M;i0++) for(int i1=i0;i1<=M;i1++) for(int i2=i1;i2<=M;i2++) for(int i3=i2;i3<=M;i3++) for(int i4=i3;i4<=M;i4++) for(int i5=i4;i5<=M;i5++) for(int i6=i5;i6<=M;i6++) for(int i7=i6;i7<=M;i7++) for(int i8=i7;i8<=M;i8++) for(int i9=i8;i9<=M;i9++) {
        int A[10];
        int cnt=0;
        A[0]=i0,A[1]=i1,A[2]=i2,A[3]=i3,A[4]=i4,A[5]=i5,A[6]=i6,A[7]=i7,A[8]=i8,A[9]=i9;
        rep(k,Q){
            if(A[b[k]]-A[a[k]]==c[k]) cnt+=d[k];
        }
        ans=max(cnt,ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3660
#include<stdio.h>
#include<string.h>
int MAX(int a,int b){return a<b?b:a;}
int P[1010],L[1010],R[1010],H[1010],C=1;
//int hyouka(int i,int x){return N[i]<=x?N[i]<x?-1:0:1;}
char N[1010][110];
int hyouka(int i,char *s){return strcmp(N[i],s);}
int h(int a){return H[R[a]]-H[L[a]];}
void rotl(int a){
  int b=L[a],r=P[a];
  L[r]==a?(L[r]=b):(R[r]=b);
  if(R[b])P[R[b]]=a;
  L[a]=R[b];
  R[b]=P[b];
  P[b]=P[a];
  P[a]=b;
  H[a]=MAX(H[L[a]],H[R[a]])+1;
  H[b]=MAX(H[L[b]],H[L[b]])+1;
}
void rotr(int a){
  int b=R[a],r=P[a];
  R[r]==a?(L[r]=b):(R[r]=b);
  if(L[b])P[L[b]]=a;
  R[a]=L[b];
  L[b]=P[b];
  P[b]=P[a];
  P[a]=b;
  H[a]=MAX(H[L[a]],H[R[a]])+1;
  H[b]=MAX(H[L[b]],H[R[b]])+1;
}
int mfind(char *x){
  int i,j,r,n;
  if(C==1){
    L[0]=C;
    //N[C]=x;
    strcpy(N[C],x);
    P[C++]=0;
    return 1;
  }
  for(i=1;r=hyouka(i,x);i=n){
    if(r<0){
      if(L[i]==0){
	L[i]=C;
	P[C]=i;
	H[i]=MAX(1,H[i]);
	//N[C]=x;
	strcpy(N[C],x);
	C++;
      }
      n=L[i];
    }
    else{
      if(R[i]==0){
	R[i]=C;
	P[C]=i;
	H[i]=MAX(1,H[i]);
	strcpy(N[C],x);
	//N[C]=x;
	C++;
      }
      n=R[i];
    }
  }//printf("%d\n",i);
  j=P[i];
  while(1){
    if(h(j)<-1){
      if(h(L[j])>0)rotl(L[j]);
      rotr(j);
      break;
    }
    if(h(j)>1){
      if(h(R[j])<0)rotr(R[j]);
      rotl(j);
      break;
    }
    if(h(j)==0)break;
    j=P[j];
    if(j==0)break;
  }//printf("%d\n",i);
  return i;
}      
int main(){
  int i,l,max=0,mj=1,r,a[1010]={};
  char *c,*mi,s[1020];
  fgets(s,1010,stdin);
  mi=strtok(s," \n");
  a[mj=mfind(mi)]++;
  max=strlen(mi);
  // printf("%s\n",mi);
  while(c=strtok(NULL," \n")){
    //printf("%s\n",c);
    a[r=mfind(c)]++;
    //printf("%d\n",r);
    l=strlen(c);//printf("%s %d\n",mi,l);
    if(max<l){
      max=l;
      strcpy(mi,c);
    }//printf("a\n");
    if(a[r]>a[mj])mj=r;//printf("a\n");
  }
  //printf("%s %d\n",mi,mj);
  printf("%s %s\n",N[mj],mi);
  return 0;
}

Measured memory_bytes: 564
#include <stdio.h>
#include <math.h>
 main(void)
 {
 int h,w;
 while(1)
{
 scanf("%d %d",&h,&w);
 if((h|w)==0)break;
 for(int i=0;
i<h;
i++)
{
 for(int j=0;
j<w;
j++)
{
 printf("%c",j==0||j==w-1||i==0||i==h-1?'#':'.');
 }
 printf("\n");
 }
 printf("\n");
 }
 } 


Measured memory_bytes: 2044
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N-1; i++) {
		int a;
		cin >> a;
		A[a-1]++;

	}
	for (int i = 0; i < N; i++) {

		cout << A[i] << endl;
	}
}

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

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

    ll n, m;
    cin >> n >> m;
    vector<ll> a(n), s(n + 1);
    rep(i, 0, n) cin >> a[i];
    sort(a.begin(), a.end());

    ll r = 1e18, l = 0; // cnt[r] <= m
    while (r - l > 1) {
        ll mid = l + (r - l) / 2;
        ll cnt = 0;
        rep(i, 0, n) cnt +=
            a.end() - lower_bound(a.begin(), a.end(), mid - a[i]);
        // cout << mid << ' ' << cnt << endl;
        if (cnt <= m)
            r = mid;
        else
            l = mid;
    }
    ll cnt = 0, ans = 0;
    sort(a.begin(), a.end(), greater<ll>());
    rep(i, 0, n) s[i + 1] = s[i] + a[i];
    sort(a.begin(), a.end());
    rep(i, 0, n) {
        ll z = a.end() - lower_bound(a.begin(), a.end(), r - a[i]);
        cnt += z;
        ans += s[z] + z * a[i];
    }
    ans += (m - cnt) * (r - 1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
// Problem : C - Walking Takahashi
// Contest : AtCoder - AtCoder Beginner Contest 175
// URL : https://atcoder.jp/contests/abc175/tasks/abc175_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define vi vector<ll>
#define vb vector<bool>
#define vp vector<pair<ll,ll>>
#define mod 1000000007
#define M_PI 3.14159265358979323846
#define pll pair<ll,ll>
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define per(i,b,a) for(ll i=b; i>=a ;--i)
#define vin(a) for(auto &i:a) cin>>i
#define mms(a,n) memset(a,n,sizeof(a))
#define fill(a,value) fill(a.begin(),a.end(),value)
#define all(a) a.begin(),a.end()
#define n_ones(x) __builtin_popcountll(x)
#define n_trailzero(x) __builtin_ctzll(x)
#define pb push_back
#define popb pop_back
#define fi first
#define se second
#define see(args...)                       \
{                                            \
    cerr<<"LINE "<<__LINE__;                 \
    string _s = #args;                       \
    replace(_s.begin(), _s.end(), ',', ' '); \
    stringstream _ss(_s);                    \
    istream_iterator<string> _it(_ss);       \
    err(_it, args);                          \
    cerr<<endl;                              \
}
void err(istream_iterator<string> it){}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
  cerr<<' '<< *it << " = " << a ;
  err(++it, args...);
} 
template <typename T, typename U>inline void min_self(T &x, U y){if (y < x)x = y;}
template <typename T, typename U>inline void max_self(T &x, U y){if (x < y)x = y;}
template<class T1, class T2>ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class T> ostream& operator<<(ostream& out, set<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class L, class R> ostream& operator<<(ostream& out, map<L, R> vec) { out<<"("; for (auto& v: vec) out<<"["<<v.first<<", "<<v.second<<"]"; return out<<")"; }
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}

// cout << fixed << setprecision(10) << pi <<" "<<npi<<endl; 
// INT64_MAX
// transform(all(s), s.begin(), ::tolower);

ll XX[4] = {-1,0,1,0};
ll YY[4] = {0,-1,0,1};


void solve(){
    ll x,k,d;
    cin>>x>>k>>d;
    x = abs(x);
    ll times = x/d;
    x -= min(times,k)*d;
    k -= min(times,k);
    k%=2;
    if(k&1){
    	cout<<abs(x-d)<<endl;
    }
    else cout<<x<<endl;
    
    
	return;
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
	// cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3480
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  int n;
  cin>>n;

  vector<ll> p(3*n);
  rep(i,3*n){
    cin>>p[i];
  }

  priority_queue<ll,vector<ll>,greater<ll>> sa;
  priority_queue<ll> yu;
  vector<ll> san(3*n+1);
  vector<ll> yan(3*n+1);

  ll sum=0;
  rep(i,n){
    sum+=p[i];
    sa.push(p[i]);
  }
  san[n]=sum;
  for(int i=n;i<2*n;i++){
    sum+=p[i];
    sa.push(p[i]);
    sum-=sa.top();
    sa.pop();
    san[i+1]=sum;
  }

  sum=0;
  for(int i=2*n;i<3*n;i++){
    sum+=p[i];
    yu.push(p[i]);
  }
  yan[2*n]=sum;
  for(int i=2*n-1;i>=n;i--){
    sum+=p[i];
    yu.push(p[i]);
    sum-=yu.top();
    yu.pop();
    yan[i]=sum;
  }

  ll ans=-INF;
  for(int i=n;i<=2*n;i++){
    chmax(ans,san[i]-yan[i]);
    //cout << san[i] << " " << yan[i] << endl;
  }


  cout << ans << endl;

}

Measured memory_bytes: 12604
#include <iostream>

using namespace std;

int main(){
	long long a,b;
	cin >> a >> b;
	long long ans = -1;
	for(long long i = a; i <= a*b; i += a){
		if(i % b == 0) {ans = i; break;}
	}
	cout << ans << endl;
	
}

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
#define REP(i,a,b) for (int i = (int)(a); (i) < (int)(b); i++)
#define rep(i,n) REP(i,0,n)

int main(){
	int n;
	cin >> n;
	int a[n];
	rep(i,n){ cin >> a[i]; }
	
	int res[n];
	rep(i,n){ res[i] = 0; }
	
	rep(i,n){ res[a[i]-1] = i+1; }
	rep(i,n){ cout << res[i] << " "; }
	return 0;
}

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

int main(){
    long long N, Q;
    scanf("%lld%lld", &N, &Q);

    vector<long long> A(N), AS(N + 2), S(N + 1), X, a;
    for(int i = 0; i < N; ++i){
        scanf("%lld", &A[i]);
        AS[i + 2] = A[i] + AS[i];
        S[i + 1] = A[i] + S[i];
    }

    reverse(A.begin(), A.end());
    reverse(S.begin(), S.end());
    reverse(AS.begin(), AS.end());
    
    for(int i = 1; i <= (N + 1) / 2; ++i){
        a.push_back(S[0] - S[i] + AS[i * 2]);
    }

    for(int i = 1; i <= (N - 1) / 2; ++i){
        X.push_back(A[i] + A[i * 2]);
    }

    reverse(a.begin(), a.end());
    reverse(X.begin(), X.end());

    for(long long i = 0, x = 0; i < Q; ++i){
        scanf("%lld", &x);
        printf("%lld\n", a[lower_bound(X.begin(), X.end(), x * 2) - X.begin()]);
    }
    return 0;
}

Measured memory_bytes: 4984
#include<stdio.h>

isprime(x){
  int i;

  if(x==2)return 1;

  if(x<2 || x%2==0) return 0;

  i=3;

  while(i*i<=x){

    if(x%i==0)return 0;

    i=i+2;

  }

  return 1;

}


int main(){

  int n,i,m[10000],sum=0,a;


  scanf("%d",&n);

  for(i=0;i<n;i++){

    scanf("%d",&m[i]);

  }

  for(i=0;i<n;i++){

    a=isprime(m[i]);
    
    sum=sum+a;

  }

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

  return 0;
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1e9 + 7;

int main()
{
    ll n;
    cin >> n;
    ll ans = 0;
    for(ll a=1; a<=n-1; ++a){
        ll max_b = (n-1)/a;
        ans += max_b;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h> 
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
typedef long long ll;
using namespace std;
int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  bool ans=true;
  if(n%2==1){ans=false;}
  if(n%2==0){rep(i,n/2){if(s[i]!=s[i+n/2]){ans=false;}}}
  if(ans){cout<<"Yes"<<endl;}
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        List<Integer> hp = new ArrayList<>();
        long ans = 0;

        for(int i = 0;i < n;i++){
            hp.add(sc.nextInt());
        }
        Collections.sort(hp);
        for(int i = 0; i < n-k;i++){
            ans += hp.get(i);
        }
        System.out.println(ans);
    }
}

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

int N,M;
int res=0;
vector<vector<int>>S(10);
vector<int>P(10);

void calc(vector<int>v){
  bool OK=true;
  for(int i=0;i<M;i++){
    int count_on=0;
    //cout<<"Light"<<i+1<<":";
    for(int j=0;j<S.at(i).size();j++){
      if(v.at(S.at(i).at(j)-1)==1){
        count_on++;
        //cout<<"o"<<" ";
      }
      //else
        //cout<<"x"<<" ";
    }
    
    if(count_on%2!=P.at(i))
      OK=false;
    //cout<<endl;
    //cout<<count_on%2<<" "<<P.at(i)<<endl;
  }
  if(OK)
    res++;
}
  


void dfs(int depth, vector<int>v){
  if(depth==N){
    calc(v);
    return;
  }
  
  for(int i=0;i<2;i++){
    v.at(depth)=i;
    dfs(depth+1,v);
  }
}

int main(){
  cin>>N>>M;
  
  for(int i=0;i<M;i++){
    int k; cin>>k;
    vector<int>s(k);
    
    for(int j=0;j<k;j++){
      cin>>s.at(j);
    }
    S.at(i)=s;
  }
  
  vector<int>v(N);
  
  for(int i=0;i<M;i++){
    int p; cin>>p;
    P.at(i)=p;
  }
  
  dfs(0,v);
  
  cout<<res<<endl;
  
  //vector<int>a={0,1,0,0,0,0,0,0,0,0};
  
  //calc(a);
  
  //cout<<res<<endl;
}

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

int main() {
  int N,M;
  cin>>N>>M;
  vector<int> p(M);
  vector<int> q(M);
  vector<int> r(N);
  vector<int> s(N);
  for(int i=0;i<N;i++){
    cin>>r[i]>>s[i];
  }
  for(int i=0;i<M;i++){
    cin>>p[i]>>q[i];
  }
  for(int j=0;j<N;j++){
    int a=r[j],b=s[j];
    int Z=0,A=2001924167;
    for(int i=0;i<M;i++){
      if(A>abs(a-p[i])+abs(b-q[i])){
        Z=i+1;
        A=abs(a-p[i])+abs(b-q[i]);
      }
    }
    cout<<Z<<endl;
  }
}



Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		int num = 2;
		
		if (n == 1) {
			System.out.println(1);
		} else {
			while (num <= n) num *= 2;
				
			System.out.println(num / 2);
		}
		sc.close();
	}
}

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

int i,j,flag=0,t;
int x[6],y[6],z[6];

void input(){
    for(i = 0;i < 6;i++) scanf("%d",&x[i]);
    for(i = 0;i < 6;i++) scanf("%d",&y[i]);
}

void N(int w[]){
    t = w[0];
    w[0] = w[1];
    w[1] = w[5];
    w[5] = w[4];
    w[4] = t;
}
 
void S(int w[]){
    t = w[0];
    w[0] = w[4];
    w[4] = w[5];
    w[5] = w[1];
    w[1] = t;
}
 
void W(int w[]){
    t = w[0];
    w[0] = w[2];
    w[2] = w[5];
    w[5] = w[3];
    w[3] = t;
}
 
void E(int w[]){
    t = w[0];
    w[0] = w[3];
    w[3] = w[5];
    w[5] = w[2];
    w[2] = t;
}

void turn(int w[]){
    t = w[1];
    w[1] = w[2];
    w[2] = w[4];
    w[4] = w[3];
    w[3] = t;
}

int main(void){
    input();
    for(i=0;i<6;i++){
        if(x[0]==y[i]){
            memcpy(z,y,sizeof(int)*6);
            switch(i){
                case 0:
                break;
                case 1:
                N(z);
                break;
                case 2:
                W(z);
                break;
                case 3:
                E(z);
                break;
                case 4:
                S(z);
                break;
                case 5:
                N(z);
                N(z);
                break;
            }
            for(j=0;j<4;j++){
                if(x[0]==z[0] && x[1]==z[1] && x[2]==z[2] && x[3]==z[3] && x[4]==z[4] && x[5]==z[5]){
                flag=1;
                break;
                }else turn(z);
            }
        }
        if(flag==1) break;
    }
    if(flag==1) printf("Yes\n");
    else printf("No\n");
    
}


Measured memory_bytes: 2684
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define PQ priority_queue
#define UM unordered_map
#define ALL(a) (a).begin(),(a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
const ll INF = (1ll << 60);
typedef pair<ll,ll> pii;
struct Edge{ll s,t,d; Edge(ll s,ll t,ll d):s(s),t(t),d(d){}};
typedef vector<vector<Edge>> Graph;
typedef vector<pii> vpii;

int main() {
  ll N; cin>>N;
  vi a(3*N); REP(i,3*N) cin>>a[i];
  sort(ALL(a));
  ll sum=0; REP(i,N) sum+=a[3*N-2-2*i];
  cout<<sum<<endl;
}


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

int main() {
  cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false);
  int N;
  int64_t M;
  cin >> N >> M;
  vector<int64_t> A(N);
  for (auto& e : A)cin >> e;
  sort(begin(A), end(A));
  vector<int64_t> csumA(N + 1, 0);
  for(int i = 0; i < N; ++i)csumA[i + 1] = csumA[i] + A[i];
  int64_t low = 0, high = A.back()*2+1;
  while (high - low > 1) {
    int64_t mid = low + (high - low) / 2;
    int64_t n = 0;
    for(int i = 0; i < N; ++i){
      auto iter = lower_bound(begin(A), end(A), mid-A[i]);
      int d = distance(begin(A), iter);
      n += N-d;
    }
    if(n>=M)low = mid;
    else high = mid;
  }
  int64_t sum = 0;
  int64_t n = 0;
  for(int i = 0; i < N; ++i){
      auto iter = lower_bound(begin(A), end(A), low-A[i]);
      int d = distance(begin(A), iter);
      sum += csumA[N] - csumA[d] + A[i] * (N-d);
      n += N - d;
  }
  if(n>M)sum -= (n - M) * low;
  cout << sum << endl;
}


Measured memory_bytes: 1792