akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
using namespace std;
using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x, a, b;
  cin >> x;
  cin >> a;
  cin >> b;
  x -= a;
  x = x % b;
  cout << x << endl;
  return 0;
}

Measured memory_bytes: 256
import itertools

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))


n = list(range(1, N+1))

c = list(itertools.permutations(n))

count = 1
for i in c:
    if i == P:
        p = count
    if i == Q:
        q = count
    count += 1

print(abs(p-q))


Measured memory_bytes: 8052
n,m=map(int,input().split())
d={int(x):True for x in input().split()}

temp=n
ans=0
while(True):
    if(temp not in d):
        ans=temp
        break
    temp+=1
temp=n
while(True):
    if(temp not in d):
        if(abs(n-temp)<=abs(n-ans)):
            ans=temp
        break
    temp-=1
print(ans)

Measured memory_bytes: 61412
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    class Cake{
	int num, p, q, r, Kcal;
	Cake(int i, int p, int q, int r){
	    num=i; this.p=p; this.q=q; this.r=r;
	    Kcal = (p+r)*4+q*9;
	}

	boolean check(int P, int Q, int R, int C){
	    return p<=P && q<=Q && r<=R && Kcal<=C;
	}

	int getNum(){ return num; }
    }

    int n;
    boolean hasAns;
    int P, Q, R, C;

    void run(){
	while(sc.hasNext()){
	    n = sc.nextInt();
	    if(n==0) break;
	    hasAns = false;
	    Cake[] cakes = new Cake[n];

	    for(int i=0; i<n; i++)
		cakes[i] = new Cake(sc.nextInt(), sc.nextInt(), 
				    sc.nextInt(), sc.nextInt());

	    P = sc.nextInt();
	    Q = sc.nextInt();
	    R = sc.nextInt();
	    C = sc.nextInt();

	    for(int i=0; i<n; i++)
		if(cakes[i].check(P, Q, R,C)){
		    System.out.println(cakes[i].getNum());
		    hasAns = true;
		}
	    if(!hasAns)
		System.out.println("NA");
	}
    }
}

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

using namespace std;

#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    FOREACH(x, v) { cout << x << " "; }                                        \
    cout << "\n";

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll, V, greater<ll>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;
const ll dx[] = {1, -1, 0, 0};
const ll dy[] = {0, 0, 1, -1};

ll N;
VL sum;

int main() {
    cin >> N;
    sum.resize(N + 1);
    REP(i, N) sum[i + 1] = sum[i] + IN();
    ll ans = LINF;
    FOR(i, 1, N) { ans = min(abs(sum[i] - (sum[N] - sum[i])), ans); }
    cout << ans << "\n";
}

Measured memory_bytes: 1792
#include <stdio.h>

int main()
{
int n,i, r, m;
int a[3];
int ans;
scanf("%d",&n);
r = n;

for(i = 0; i<3; i++){
  a[i] = r%10;
  r = (r-a[0])/10;
}

m = a[2]+10*a[1]+100*a[0];

if(n ==m){
  printf("Yes\n");
}
else{
  printf("No\n");
}




return 0;
}


Measured memory_bytes: 128
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	s, t := scanString(), scanString()
	ans := 0
	for i := 0; i < len(s); i++ {
		if s[i] != t[i] {
			ans++
		}
	}
	fmt.Fprintln(wr, ans)
}


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

int main(){
	int n,i,j,k,a = 1,b = 1,count,fact;
	cin >> n;
	int p[n],q[n],chk[n];
	for(i = 0; i < n; i++){
		cin >> p[i];
	}
	for(i = 0; i < n; i++){
		cin >> q[i];
	}
	for(i = 0; i < n; i++){
		chk[i] = 0;
	}
	for(i = 0; i < n; i++){
		count = 0;
		fact = 1;
		for(j = 0; j < n; j++){
			if(chk[j] == 0){
				if(p[i] == j+1){
					chk[j] = 1;
					break;
				}
				else{
					count++;
				}
			}
		}
		for(k = 0; k < n - i - 1; k++){
			fact = fact*(k+1);
		}
		a = a + count*fact;
	}

	for(i = 0; i < n; i++){
		chk[i] = 0;
	}
	for(i = 0; i < n; i++){
		count = 0;
		fact = 1;
		for(j = 0; j < n; j++){
			if(chk[j] == 0){
				if(q[i] == j+1){
					chk[j] = 1;
					break;
				}
				else{
					count++;
				}
			}
		}
		for(k = 0; k < n - i - 1; k++){
			fact = fact*(k+1);
		}
		b = b + count*fact;
	}

	if(a >= b){
		cout << a-b;
	}
	else if(a < b){
		cout << b-a;
	}
	return 0;
}


Measured memory_bytes: 256
import java.io.File;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Scanner;
import java.util.Set;
import java.util.Stack;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static Properties pps = System.getProperties();
	static boolean dbg = true;

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int a = ni();
	
		List<String> l=new ArrayList<String>();
		solve(a,l);
		System.out.println(l.size());
		for(String str:l)
			out(str);
		
	}



	private static void solve(int a,List<String> l) {
		// TODO Auto-generated method stub
		
		if(a%2==0) {
			for(int i=1;i<=a/2;i++) {
				for(int j=i+1;j<=a/2;j++) {
					l.add(i+" "+j);
					l.add(i+" "+(a+1-j));
					l.add((a+1-i)+" "+j);
					l.add((a+1-i)+" "+(a+1-j));
				}
			}
		}
		else {
			solve(a-1, l);
			for(int i=1;i<a;i++) {
				l.add(a+" "+i);
			}
		}
		
	}



	private static void out(List<Integer> l) {
		// TODO Auto-generated method stub
		for (int i : l)
			System.out.println(i);

	}

	private static void out(int[] b) {
		// TODO Auto-generated method stub
		for (int i : b)
			System.out.println(i);

	}

	public static void out(String str) {

		if (dbg)
			System.out.println(str);
	}

	public static void out(int str) {

		if (dbg)
			System.out.println(str);
	}

	public static int ni() {

		return sc.nextInt();

	}

	public static String ns() {

		return sc.nextLine();
	}

	public static int[] ni(int k) {
		int[] res = new int[k];
		for (int i = 0; i < k; i++)
			res[i] = sc.nextInt();
		sc.nextLine();
		return res;
	}

	public static String[] ns(int k) {
		String[] res = new String[k];
		for (int i = 0; i < k; i++)
			res[i] = sc.nextLine();
		return res;
	}

	public static int[][] ni(int a, int b) {
		int[][] res = new int[a][b];
		for (int i = 0; i < a; i++)
			for (int j = 0; j < b; j++)
				res[i][j] = sc.nextInt();
		sc.nextLine();
		return res;
	}
}


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

using namespace std;

int main()
{
    string s;
    cin >> s;
    int ans = 0;
    for (int i = 0; i < s.length(); i++)
    {
        if (s[i] - '0' != i % 2)
        {
            ans++;
        }
    }
    cout << min(ans, (int) s.length() - ans) << endl;
    return 0;
}


Measured memory_bytes: 512
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,a,b = map(int, input().split())
if (b-a)%2==0:
    ans = (b-a)//2
else:
    m = b-1
    M = n-a
    m1 = (n-b) + 1 + (b-a-1)//2
    m2 = (a-1) + 1 + (b-a-1)//2
    ans = min(m,M, m1, m2)
print(ans)

Measured memory_bytes: 38384
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <queue>

typedef long long ll;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    ll n;
    cin >> n;

    vector<pair<string, ll>> l;

    string ts;
    ll tmp;
    rep(i,0,n) cin >> ts >> tmp, l.push_back({ts, tmp});

    string x;
    cin >> x;

    ll t(0); 
    bool f(false);
    for (auto i: l)
    {
        if (f) t+=i.second;

        if (!f && i.first==x)
            f = true;
    }

    cout << t << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
 
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;
}
///////////////////////////////////////////////
int dx[2] = {0,1};
int dy[2] = {1,0};

int main(){
    int H,W;
    cin >> H >> W;
    static char grid[402][402] = {};
    static bool visited[402][402] = {};
    //getchar();
    REP(h,H){
        REP(w,W){
            cin >> grid[h][w];
        }
        getchar();
    }

    REP(i,H-1){
        REP(j,W-1){
            if (grid[i][j] == '#' and grid[i+1][j] == '#' and grid[i][j+1] == '#'){
                printf("Impossible\n");
                return 0;
            }
        }
    }

    REP(i,H-1){
        REP(j,W-1){
            if (grid[i+1][j+1] == '#' and grid[i+1][j] == '#' and grid[i][j+1] == '#'){
                printf("Impossible\n");
                return 0;
            }
        }
    }


    printf("Possible\n");
}


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

using namespace std;
const int MAX=1e5;
vector<pair<int,int> >v;
int n,w;
long long dp[101][MAX+3];

long long solve(int ind,int sum){
if(sum>w) return -1e17;
if(ind==n) return 0;
if(dp[ind][sum]!=-1) return dp[ind][sum];
long long ans=-1e17;
ans=max(ans,solve(ind+1,sum+v[ind].first)+v[ind].second);
ans=max(ans,solve(ind+1,sum));
return dp[ind][sum]=ans;
}

int main()
{
    cin>>n>>w;
    v.resize(n);
    for(int i=0;i<n;i++) cin>>v[i].first>>v[i].second;
    memset(dp,-1,sizeof(dp));
    cout<<solve(0,0);
    return 0;
}


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

int main() {
  int n, z;
  bool zoro3 = false;
  int d1, d2;

  cin >> n;
  z = 0;
  for (int i = 0; i < n; i++) {
    cin >> d1 >> d2;
    if (d1 == d2) {
      z++;
      if (z == 3) zoro3 = true;
    }
    else z = 0;
  }
  if (zoro3) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    String o, e;
    StringBuilder sb;

    public static void main(String args[]) {
        new Main().run();
    }

    void run() {
        FastReader sc = new FastReader();
        o = sc.next();
        e = sc.next();
        solve();
    }

    void solve() {
        sb = new StringBuilder();
        for (int i = 0; i < e.length(); i++) {
            sb.append(o.charAt(i));
            sb.append(e.charAt(i));
        }
        if (o.length() > e.length()) {
            sb.append(o.charAt(o.length() - 1));
        }
        System.out.println(sb);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 22996
#include <stdio.h>

int main(void) {
	int a, b, k, temp, count=0;
	scanf("%d%d%d", &a, &b, &k);

	for (temp = 100; temp > 1;temp --) {
		if (a % temp == 0 && b % temp == 0) count++;
		if (count == k)
			break;
	}
  printf("%d", temp);
  return 0;
}

Measured memory_bytes: 128
Q=int(input())

PN=[1]*(10**5+1)
PN[0]=0
PN[1]=0

for i in range(2,int(int(10**5)**0.5+1)):
    if PN[i]==1:
        cnt=2
        while i*cnt<10**5+1:
            PN[i*cnt]=0
            cnt+=1

chk=[0]*(10**5+1)

for i in range(1,100001,2):
    if PN[i]==1 and PN[(i+1)//2]==1:
        chk[i]=1

S=[0]*(10**5+2)
for i in range(1,10**5+2):
    S[i]=S[i-1]+chk[i-1]

for i in range(Q):
    l,r=map(int,input().split())
    print(S[r+1]-S[l])





Measured memory_bytes: 7924
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int P;
        int min = 0;
        int counter = 0;
        for(int i = 0; i < N; i++){
            P = sc.nextInt();
            if(min < 1 || P < min){
                min = P;
                counter++;
            }
        }
        
        System.out.println(counter);
    }
}


Measured memory_bytes: 62860
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
void swap(int *x,int *y){int tmp=*x;*x=*y;*y=tmp;}
int asc_cmp(const void* X,const void* Y){int x=*(int*)X,y=*(int*)Y;if(x<y)return -1;else if(x==y)return 0;else return 1;}
//next_permutation
//from https://qiita.com/Nikkely/items/0ddca51b3c0e60afbaab
int next_permutation(int *a,int n){
    int x=-1,y=-1;
    for(int i=n-2;i>=0;i--)if(a[i]<a[i+1]){x=i;break;}
    for(int i=n-1;x!=-1&&i>=0;i--)if(a[x]<a[i]){y=i;break;}
    if(x==-1||y==-1)return 1;
    swap(&a[x],&a[y]);
    qsort(&a[x+1],n-(x+1),sizeof(int),asc_cmp);
    return 0;
}

int main(){
    int n;scanf("%d",&n);
    int p[20];for(int i=0;i<n;i++)scanf("%d",&p[i]);
    int q[20];for(int i=0;i<n;i++)scanf("%d",&q[i]);

    char p_str[20],q_str[20];
    for(int i=0;i<n;i++){
      p_str[i]=p[i]+'0';
      q_str[i]=q[i]+'0';
    }
    p_str[n]=q_str[n]='\0';

    int a[n];for(int i=1;i<=n;i++)a[i-1]=i;

    int index[2];
  	index[0]=index[1]=-1;
    char list[20];
    for(int i=0;1;i++){
        for(int j=0;j<n;j++)list[j]='0'+a[j];
        list[n]='\0';
        if(!strcmp(list,p_str))index[0]=i;
        if(!strcmp(list,q_str))index[1]=i;
        if(index[0]!=-1&&index[1]!=-1)break;
      	if(next_permutation(a,n))break;
    }
    
    printf("%d\n",abs(index[0]-index[1]));
    return 0;
}


Measured memory_bytes: 128
## main

loop do
  h, w, n = gets.strip.split(' ').map{|s| s.to_i}
  break if (h | w | n) == 0

  drcs = h.times.map{gets.strip.split(' ').map{|s| s.to_i}}
  #p crs

  counts = (h + 1).times.map{(w + 1).times.map{0}}
  counts[0][0] = n - 1

  for y in (0...h)
    for x in (0...w)
      c = counts[y][x]
      d = drcs[y][x]
      c2 = c / 2

      counts[y + 1][x] += (c + 1 - d) / 2
      counts[y][x + 1] += (c + d) / 2
    end
  end

  for y in (0...h)
    for x in (0...w)
      drcs[y][x] ^= (counts[y][x] & 1)
    end
  end

  x = y = 0

  while x < w && y < h
    if drcs[y][x] == 0
      y += 1
    else
      x += 1
    end
  end

  puts [y + 1, x + 1].join(' ')
end

Measured memory_bytes: 25976
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	price := 0
	if a >= 13 {
		price = b
	} else if a >= 6 {
		price = b / 2
	} else {
		price = 0
	}
	fmt.Println(price)
}


Measured memory_bytes: 512
//Single Source Shortest Path (Negative Edges)
#include<iostream>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using namespace std;

int main()
{
    const ll INF = 1e8;
    struct edge{
        ll from;
        ll to;
        ll cost;
    };
    ll V, E, r;
    cin >> V >> E >> r;
    vector<edge>edges(E);
    rep(i,E){
        int s, t, d;
        cin >> s >> t >> d;
        edges[i] = {s, t, d};
    }
    vector<ll>shortest(V, INF);
    shortest[r] = 0;
    rep(i,V-1){
        rep(j,E){
            if(shortest[edges[j].from] != INF) {
                shortest[edges[j].to] = min(shortest[edges[j].to], shortest[edges[j].from] + edges[j].cost);
            }
        }
    }
    bool ok = true;
    rep(j,E){
        ll a = shortest[edges[j].to];
        if(shortest[edges[j].from] != INF){
            shortest[edges[j].to] = min(shortest[edges[j].to], shortest[edges[j].from] + edges[j].cost);
        }
        if(a != shortest[edges[j].to]){ 
            ok = false;
            break;
        }
    }
    if(!ok){
        cout << "NEGATIVE CYCLE" << endl;
        return 0;
    }else{
        rep(i,V){
            if(shortest[i] == INF) cout << "INF" << endl;
            else cout << shortest[i] << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3140
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#include<tuple>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

const ll mod = 1e9+7;
const ll INF = ll(1e18)+1;
const ll MAXN = 1e6;

const int MAX=510000;

int main()
{
    int n;
    cin>>n;
    int d[n];
    rep(i,n)
    {
        cin>>d[i];
    }
    sort(d,d+n);
    int min=d[n/2-1];
    int max=d[n/2];
    cout<<max-min;
}

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

int main() {
    int a,b;
    cin >> a >> b;
    if(a > b) {
        for(int i = 0;i < a;i++) {
            cout << b;
        }
        cout << endl;
    }
    else {
        for(int i = 0;i < b;i++) {
            cout << a;
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>
#include <limits>
#include <cmath>
#include <iomanip>
#include <sstream>
 
#define ALL(a)  (a).begin(),(a).end()
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int main() {
    double ans = 0;
    ll n, k;

    cin >> n >> k;

    for (int i = 1; i <= n; i++) {
        ll m = max((int)ceil(log2((double)k/(double)i)), 0);
        ans += (1.0/n) * pow(0.5, m);
    }

    cout << setprecision(12) << ans << endl;

}

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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using ll = long long;
using namespace std;

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

    double a, b, h; cin >> a >> b >> h;
    cout << h * ((a + b) / 2);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define INF 1e18
#define MOD 1000000007
#define N 1000005
#define BB(V) V[V.size()-2]
#define ex(V) return printf(V),0
using namespace std;
int chk[100005];
deque<pii>dq;
int main(){
	int n;
	scanf("%d",&n);
	dq.pb({1,1});
	while(!dq.empty()){
		pii t=dq.front();dq.pop_front();
		if(t.F==0)return printf("%d",t.S),0;
		if(chk[t.F])continue;
		chk[t.F]=1;
		if(!chk[t.F*10%n])dq.push_front({t.F*10%n,t.S});
		if(!chk[(t.F+1)%n])dq.pb({(t.F+1)%n,t.S+1});
	}
}

Measured memory_bytes: 1152
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef vector<int> VI;
typedef vector<VI> VVI;
template<class T> T gcd( T a, T b ) {
	return !b ? a : gcd( b, a % b );
}
template<class T> T lcm( T a, T b ) {
	return a / gcd( a, b ) * b;
}
template<class T> string print_v( vector<T> v ) {
	OSS oss;
	for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end();
          ++it_i ) {
		oss << *it_i << ", ";
	}
	return oss.str();
}

VI A;
int n;

int solve( int k, int d ) {
    if ( k >= n ) return d;
    if ( A[k] == 1 ) {
        return max( ( d + 1 > 21 ? 0 : solve( k + 1, d + 1 ) ), ( d + 11 > 21 ? 0 : solve( k + 1, d + 11 ) ) );
    } else if ( A[k] >= 10 ) {
        if ( d + 10 > 21 ) return 0;
        return solve( k + 1, d + 10 );
    } else {
        if ( d + A[k] > 21 ) return 0;
        return solve( k + 1, d + A[k] );
    }
    return 0;
}

int main() {
    string line;
    while ( getline( cin, line ) && line != "0" ) {
        A.clear();
        int w;
        ISS iss( line );
        while ( iss >> w ) A.push_back( w );
        n = A.size();
        cout << solve( 0, 0 ) << endl;
    }
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int N, K, X, Y; cin >> N >> K >> X >> Y;
	if (N < K) { cout << N*X << endl; }
	else {
		cout << K*X + (N - K)*Y << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAXN 1000
#define MAXH 10000

int H, N, A[MAXN + 3], B[MAXN + 3], dp[MAXH + 3];

int solve(int h) {
    if (h <= 0)
        return 0;

    if (dp[h] != -1)
        return dp[h];

    int best = 1e9;
    for (int i = 1; i <= N; i++) {
        best = min(best, B[i] + solve(h - A[i]));
    }

    return dp[h] = best;
}

int main() {
    cin >> H >> N;
    for (int i = 1; i <= N; i++)
        cin >> A[i] >> B[i];

    memset(dp, -1, sizeof(dp));

    cout << solve(H) << endl;
}


Measured memory_bytes: 896
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
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 num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  ll n,a,b,c;
  cin >> n>>a>>b>>c;
  
  vector<string> p(n);
  vector<char> q(n);
  
  if(a+b+c==1) {
    rep(i,n) {
      cin >> p[i];
      if(p[i]=="AB") {
        if(a+b==1) {
          if(a==0) q[i]='A';
          else q[i]='B';
          a=1-a;
          b=1-b;
        }
        else {
        cout << "No" << endl;
        return 0;
        }
      }
      if(p[i]=="BC") {
        if(b+c==1) {
          if(b==0) q[i]='B';
          else q[i]='C';
          c=1-c;
          b=1-b;
        }
        else {
        cout << "No" << endl;
        return 0;
        }
      }
      if(p[i]=="AC") {
        if(a+c==1) {
          if(a==0) q[i]='A';
          else q[i]='C';
          a=1-a;
          c=1-c;
        }
        else {
        cout << "No" << endl;
        return 0;
        }
      }
      if(i==n-1){
      a=3;
      b=3;
      c=-5;
      }
    }
  }
  else {
    rep(i,n) {
    cin >> p[i];
    }
  }
  
  if((a==0 && b==0 && p[0]=="AB")||(b==0 && c==0 && p[0]=="BC")||
    (c==0 && a==0 && p[0]=="AC")) { 
  cout << "No" << endl;    
  return 0;
  }
  
  cout << "Yes" << endl;
  
  if(a+b+c==1) {
    rep(i,n) {
    cout << q[i] << endl;
    }
  }
  
  else{
    rep(i,n) {
      if(p[i]=="AB") {
        if(i!=n-1 && a==b && p[i+1]=="BC") {
          cout << 'B' << endl;
          a-=1;
          b+=1;
        }
        else if(a<=b) {
          cout << 'A' << endl;
          a+=1;
          b-=1;
        }
        else {
          cout << 'B' << endl;
          a-=1;
          b+=1;
        }
      }
      if(p[i]=="BC") {
        if(i!=n-1 && b==c && p[i+1]=="AC") {
          cout << 'C' << endl;
          b-=1;
          c+=1;
        }
        else if(b<=c) {
          cout << 'B' << endl;
          b+=1;
          c-=1;
        }
        else {
          cout << 'C' << endl;
          b-=1;
          c+=1;
        }
      }
      if(p[i]=="AC") {
        if(i!=n-1 && a==c && p[i+1]=="AB") {
          cout << 'A' << endl;
          c-=1;
          a+=1;
        }
        else if(c<=a) {
          cout << 'C' << endl;
          c+=1;
          a-=1;
        }
        else {
          cout << 'A' << endl;
          c-=1;
          a+=1;
        }
      }
    }
  }
}

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

int main(){
    int n, ans = 0;
    string s, s2 = "ABC";
    cin >> n >> s;
    int cnt = 0;
    for(int i = 0; i < n - 2; i++){
        if(s.substr(i, 3) == s2){
            ans++;
        }
    }    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i < (int)(n); i++)
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;


int main()
{
    string S;

    cin >> S;

    if (S[2] == S[3] && S[4] == S[5])
        cout << "Yes";
    else
        cout << "No";

	return 0;
}

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

map<string, long> m;
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		sort(s.begin(), s.end());
		m[s]++;
	}
	long r = 0;
	for (auto p : m)
		r += p.second*(p.second - 1) / 2;
	cout << r << endl;
	return 0;
}


Measured memory_bytes: 11136
N, M = map(int, input().split(" "))
S = input()
T = input()

L = N * M
n, m = N, M
if n < m:
    n, m = m, n
while m != 0:
    n, m = m, n%m
GCD = n
LCM = L//n

if GCD == 1 and S[0] == T[0]:
    print(L)
elif S[::N//GCD] == T[::M//GCD]:
    print(LCM)
else:
    print(-1)

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

using namespace std;
typedef long long ll;

const int MOD = 1e9+7;

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    if(((a==b)&&(b!=c))||((b==c)&&(c!=a))||((c==a)&&a!=b)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
s = input()
k = int(input())

one_counter = 0
for i in range(len(s)):
    if s[i] != "1":
        break
    else:
        one_counter += 1

if s[0] == "1":
    if k <= one_counter:
        res = s[0]
    else:
        res = s[one_counter]
else:
    res = s[0]

print(res)

Measured memory_bytes: 9184
using System;

public class AOJ11
{
    public static void Main()
    {
        int[] a = new int[50];
        int[] b = new int[50];
        while (true)
        {
            int n, r;
            string[] v = Console.ReadLine().Split(' ');
            n=Int32.Parse(v[0]); r=Int32.Parse(v[1]);
            if (n == 0 && r == 0) break;
            for (int i = 0; i < n; i++) a[i] = n - i;
            for (int i = 0; i < r; i++)
            {
                int p, c;
                string[] tmp = Console.ReadLine().Split(' ');
                p = Int32.Parse(tmp[0]); c = Int32.Parse(tmp[1]);
                for (int j = p-1; j <= p+c-2 ; j++) b[j-(p-1)] = a[j];
                for (int j = 0; j <= p-2; j++) b[j + c] = a[j];
                for (int j = p + c-1; j <= n-1; j++) b[j] = a[j];
                b.CopyTo(a, 0);
            }
            Console.WriteLine(a[0]);
        }
    }
}

Measured memory_bytes: 5844
#include<cstdio>
#define N 5005
#define p 1000000007
#define ll long long
int a[N],b[N<<1],c[N<<1],d[N>>1],f[N][N],n,s[N],t;
void dfs(int u,int v)
{
	f[u][s[u]=1]=1;
	for(int i=a[u];i;i=b[i])if(c[i]!=v)
	{
		dfs(c[i],u);
		for(int j=s[u];j;f[u][j]=(ll)f[u][j]**f[c[i]]%p,j--)for(int k=s[c[i]];k;k--)f[u][j+k]=(f[u][j+k]+(ll)f[u][j]*f[c[i]][k])%p;
		s[u]+=s[c[i]];
	}
	for(int i=2;i<=s[u];i+=2)*f[u]=(*f[u]+(ll)f[u][i]*(p-d[i>>1]))%p;
}
int main()
{
	scanf("%d",&n),*d=d[1]=1;
	for(int i=2;i<<1<=n;i++)d[i]=(i-1<<1|1ll)*d[i-1]%p;
	for(int i=2,u,v;i<=n;i++)scanf("%d%d",&u,&v),b[++t]=a[u],c[a[u]=t]=v,b[++t]=a[v],c[a[v]=t]=u;
	dfs(1,0),printf("%d\n",(p-*f[1])%p);
	return 0;
}

Measured memory_bytes: 97024
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}

int main(void){
	int n, i;
	scanf("%d", &n);
	int ans = n;
	for (i=0; i<=n; i++){
		int now=0;
		int t=i;
		while(t>0){now+=t%6 , t/=6;}
		t=n-i;
		while(t>0){now+=t%9 , t/=9;}
		if(ans>now) ans=now ;
	}
	printf("%d\n", ans);
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

map<li, li> d;
map<li, li> p;

int main() {
    li n, m;
    cin >> n;
    rin{
        li x;
        cin >> x;
        d[x]++;
    }
    cin >> m;
    rep(i, m) {
        li x;
        cin >> x;
        p[x]++;
    }
    foreach (it, p) {
        if (it->S > d[it->F]) {
            puts("NO");
            return 0;
        }
    }
    puts("YES");


    return 0;
}

Measured memory_bytes: 25216
#include<iostream>

using namespace std;

int main(void)
{
  string s;
  cin>>s;
  string hi;
  
  for(int i=0;i<5;i++){
    hi+="hi";
    if(hi==s){
      puts("Yes");
      return 0;
    }
  }
  
  puts("No");
  return 0;
}
    
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using intl = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for(intl i = (intl)(n); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define repid(i, a, b) for(intl i = (intl)(a); i >= (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin,(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define int intl
#define itn intl
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool flag){
    if(flag)cout << "Yes" << endl;
    else cout << "No" << endl;
}
void fp(bool flag, string s, string t){
    if(flag)cout << s << endl;
    else cout << t << endl;
}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
signed main(){
    cout << fixed << setprecision(10);
    string s;
    cin >> s;
    intl len = s.length();
    char c = s[0];
    intl cnt = 0;
    rep(i, len){
        if(c != s[i]){
            cnt++;
            c = s[i];
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 512
N = int(input())

A =list(map(int, input().split()))

x = 0

for i in range(N):
    if i % 2 == 1:
        x -= A[i]
    else:
        x += A[i]

x = x // 2

ans = [0] * N
ans[0] = x
for i in range(N-1):
    ans[i+1] = A[i]-ans[i]
for i in range(N):
    ans[i] *= 2    
print(*ans)

Measured memory_bytes: 14616
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int x;
	cin >> x;
	int ans = 1;
	for(int i = 2; i <= x; i++){
		for(int j  = 2; pow(i,j) <= x; j++){
			int cmp = pow(i,j);
			chmax(ans, cmp);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int n, k;

int main() {
  scanf("%d", &k);
  if (k == 1) {
    printf("1\n1\n");
    return 0;
  }
  n = ((k - 1) / 4 + 1) * 2;
  printf("%d\n", n);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      int c = (i + j) % n;
      if ((i & 1) && c + n < k) {
        c += n;
      }
      printf("%d%c", c + 1, " \n"[j == n - 1]);
    }
  }
  return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  for(int i=s.size()-1;i>=1;i--){
    if(i%2){
      continue;
    }
    string t=s.substr(0,i/2);
    if(t==s.substr(i/2,i/2)){
      cout<<i<<endl;
      break;
    }
    //cout<<t+" "+s.substr(i/2,i/2)<<endl;
  }
  return 0;
}

Measured memory_bytes: 3608
/*
***************************************************************************
 name  : ITP1_03_C.cpp
 title : Swapping Two Numbers
 make  : 2018/08/08 tanabe
***************************************************************************
*/

// Library
#include <iostream> // standard input output object

// Prototype
void Swap(int *x,int *y); // Swap the values of x and y

main(void){
  int x,y;  // integers

  std::cin >> x >> y; // input "x y"

  // continue x != 0 and y != 0
  // input "x y" at loop update
  for(;x || y;std::cin >> x >> y){
    if(x > y){
      Swap(&x,&y); // swap x and y
    }
    std::cout << x << " " << y << std::endl; // output "x y"
  }

}

// +-----------------------------------------+
// | name       : Swap                       |
// | obtain     : int *x,int *y              |
// | return     : none                       |
// | processing : swap the values of x and y |
// +-----------------------------------------+
void Swap(int *x,int *y){
  int temp; // temporary container

  // swap
  temp = *x;
  *x = *y;
  *y = temp;

}



Measured memory_bytes: 3112
#pragma region Macros

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

using ll = long long;
#define int ll
using vi = vector<int>;
using vvi = vector<vi>;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

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;
}
template <class T>
ostream &operator<<(ostream &out, vector<T> const &v) {
    for (auto &&a : v) out << a << " ";
    out << endl;
    return out;
}

// debug methods
// usage: debug(x,y);
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << endl
#define debug_4(x1, x2, x3, x4) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...)                                                        \
    CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
    (__VA_ARGS__)
#else
#define debug(...)
#endif

#pragma endregion

void Main() {
    int N, K;
    cin >> N >> K;

    int min = INT64_MAX;
    int buff;
    N = N % K;
    while (1) {
        buff = abs(N - K);
        if (N <= buff) {
            break;
        }
        chmin(N, buff);
    }

    cout << N;
}

#pragma region main
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    Main();
    cout << flush;
}
#pragma endregion


Measured memory_bytes: 3516
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=1e6+23;
int vis[maxn];
int main(){
	int n;
	cin>>n;
	int now=7;
	for(int i=1;;i++){
		if(vis[now]%n) break;
		vis[now%n]=1;
		if(now%n==0){
			printf("%d",i);
			return 0;
		}
		now=(now*10+7)%n;
	}
	cout<<-1;
}

Measured memory_bytes: 7488
#include <bits/stdc++.h>
using namespace std;
#define mem(a,n) memset(a,n,sizeof(a))
#define rep(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
const double eps=1e-6;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
const int N=1e5+5;
int prime[N],sum[N];
bool is_pr[N];
int cnt;
inline int Scan()
{
    int r = 0,f = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9')
    {
        if(ch == '-')f = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9')
    {
        r = r * 10 + ch - '0';
        ch = getchar();
    }
    return r * f;
}
void sieve()
{
    cnt=0;
    mem(is_pr,0);
    for(int i=2; i*i<=N; i++)
    {
        if(!is_pr[i])
        {
            for(int j=i*i; j<=N; j+=i)
                is_pr[j]=1;
        }
    }
    for(int i=2; i<N; i++)
        if(!is_pr[i]) prime[cnt++]=i;
    mem(sum,0);
    for(int i=1; i<cnt; i++)
    {
        int tmp=(prime[i]+1)/2;
        int pos=lower_bound(prime,prime+i,tmp)-prime;
        if(prime[pos]==tmp) sum[prime[i]]++;
    }
    for(int i=1; i<cnt; i++) sum[prime[i]]+=sum[prime[i-1]];
}
int main()
{
    sieve();
    int q;
    q=Scan();
    rep(i,0,q)
    {
        int l,r;
        scanf("%d%d",&l,&r);
        int pos1=lower_bound(prime,prime+cnt,l)-prime;
        // printf("prime  %d\n",prime[pos1]);
        int pos2=lower_bound(prime,prime+cnt,r)-prime;
        if(prime[pos2]==r) r=prime[pos2];
        else r=prime[pos2-1];
        //printf("%d %d\n",sum[r],sum[pos1]);
        printf("%d\n",sum[r]-sum[prime[pos1-1]]);
    }
    return 0;
}


Measured memory_bytes: 1152
s=gets.chomp.split("")

zero_start_zero=s.select.with_index{|_,i| i%2==0}.count {|si| si == "0"}
zero_start_one=s.select.with_index{|_,i| i%2==1}.count {|si| si == "1"}

zero_start_c=s.select.with_index {|si,i|
  if i%2==0
    si == "1"
  else
    si=="0"
  end
}.count

one_start_c=s.select.with_index {|si,i|
  if i%2==1
    si == "1"
  else
    si=="0"
  end
}.count

r=zero_start_c > one_start_c ? one_start_c : zero_start_c
print(r)


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

int main() {
	int n;
	cin >> n;
	bool ans = false;
	for (int i = 0;4 * i <= n;i++) {
		for (int j = 0;7 * j <= n;j++) {
			if (4 * i + 7 * j == n)ans = true;
		}
	}
	if (ans)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <memory>
#include <memory.h>
#include <fstream>
#include <cmath>
#include <math.h>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <map>
#include <set>
#include <iomanip>
#include <list>
#include <cctype>
#include <algorithm>
#include <complex>
using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<double, double> Pd;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 28;
const double EPS = 1E-10;

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

int N[] = {1, 5, 10, 50, 100, 500};
int nums[6];

inline int pay(int v){
	int cnt = 0;
	rep(i, 6){
		int pay = min(nums[5-i], v / N[5-i]);
		cnt += pay;
		v -= pay * N[5-i];
	}
	if(v == 0) return cnt;
	else return INF;
}

inline int receive(int v){
	int cnt = 0;
	rep(i, 6){
		int pay = v / N[5-i];
		cnt += pay;
		v -= pay * N[5-i];
	}
	return cnt;
}

int main(){
	int p;
	while(cin >> p && p){
		rep(i, 6) cin >> nums[i];
		int res = INF;
		int Pmax = 0;
		rep(i, 6) Pmax += nums[i] * N[i];
		rep2(i, p, Pmax + 1){
			int ret = i - p;
			res = min(res, pay(i) + receive(ret));
		}
		cout << res << endl;
	}
	return 0;
}

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

using namespace std;

const int N = 0 + 77 , Mod = 1000000007;

struct Matrix {
	int n , m , M[N][N];
	Matrix (int n1 , int m1){
		n = n1 ;m = m1;
		Clear();
	}
	void Clear(){
		for(int i = 0;i < n;++ i)
			for(int j = 0;j < m;++ j)
				M[i][j] = 0;
	}
	void Identity(){
		Clear();
		if(n != m){
			cerr << "Cannot Make Identity Matrix Not Compatible\n";return ;
		}
		for(int i = 0;i < n;++ i)
			M[i][i] = 1;
	}
	void Print(){
		cerr << "***\n";
		for(int i = 0;i < n;++ i){
			for(int j = 0;j < m;++ j)
				cerr << M[i][j] << ' ';
			cerr << '\n';
		}
		cerr << "***\n";
	}
	void Fill(int t){
		for(int i = 0;i < n;++ i)
			for(int j = 0;j < m;++ j)
				M[i][j] = t;
	}
	Matrix operator * (const Matrix &T){
		Matrix R = Matrix(n , T.m);R.Clear();
		if(m != T.n){
			cerr << "Matrices not Compatible for multiplying\n";return R;
		}
		for(int i = 0;i < n;++ i)
         for(int k = 0;k < m;++ k)
            for(int j = 0;j < T.m;++ j)
					R.M[i][j] = (R.M[i][j] + M[i][k] * 1ll * T.M[k][j]) % Mod;
		return R;
	}
	Matrix operator + (const Matrix &T){
		Matrix R = Matrix(n , m);
		R.Clear();
		for(int i = 0;i < n;++ i)
			for(int j = 0;j < m;++ j)
				R.M[i][j] = (M[i][j] + T.M[i][j]) % Mod;
		return R;
	}
	Matrix operator ^ (const long long t){
		Matrix res = Matrix(n , m);res.Identity();
		if(t == 0)return res;
		Matrix T = Matrix(n , m);T.Clear();
		for(int i = 0;i < n;++ i)
			for(int j = 0;j < m;++ j)
				T.M[i][j] = M[i][j];
		long long p = t;
		while(p){
			if(p & 1)
				res = res * T;
			p >>= 1;
			T = T * T;
		}
		return res;
	}
};

int n , A;
long long k;
int main(){
   ios::sync_with_stdio(0);cin.tie(0);
   cin >> n >> k;
   Matrix M = Matrix(n , n);
   for(int i = 0;i < n;++ i)
      for(int j = 0;j < n;++ j)
         cin >> M.M[i][j];
   M = M ^ k;
   for(int i = 0;i < n;++ i)
      for(int j = 0;j < n;++ j)
         A = (A + M.M[i][j]) % Mod;
   cout << A;
   return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <queue>
#include <utility>
#include <vector>

using namespace std;



int main() {
    int N, M;
    cin >> N >> M;
    
    // auto cmp=[](pair<long long int, int> a, pair<long long int, int> b) {
    //     if(a.first!=b.first) {
    //         return a.first<b.first;
    //     } else {
    //         return a.second>b.second;
    //     }
    // };
    
    priority_queue<pair<long long int, int>, vector<pair<long long int , int> >, greater<pair<long long int, int> > > que;
    for(int i=0; i<N; i++) {
        long long int A;
        int B;
        cin >> A >> B;
        
        que.push(make_pair(A, B));
    }
    
    long long int sum=0;
    while(M) {
        if(M>que.top().second) {
            sum += que.top().first * que.top().second;
            M -= que.top().second;
            que.pop();
        } else {
            sum += que.top().first * M;
            M = 0;
        }
    }

    cout << sum << endl;

    return 0;
    
}

Measured memory_bytes: 2420