akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

bool WH[55][55];

typedef struct{
    int x;
    int y;
    int step;
}LOC;

bool isvisit[55][55];

int main(){
    int H,W;
    cin >> H >> W;
    int sum = 0;
    REP(i,H){
        REP(j,W){
            char c;
            cin >> c;
            if(c == '.'){
                WH[i][j] = true;
                sum++;
            }
        }
    }

    queue<LOC> qu;
    qu.push((LOC){0,0,1});
    int step;
    while(1){
        if(qu.empty()){
            cout << -1 << endl;
            return 0;
        }

        LOC loc = qu.front();
        qu.pop();
        int x = loc.x;
        int y = loc.y;
        int s = loc.step;
        if(isvisit[y][x]) continue;
        isvisit[y][x] = true;

        if(x == W-1 && y == H-1){
            step = s;
            break;
        }

        if(x+1 < W && WH[y][x+1]){
            qu.push((LOC){x+1, y, s+1});
        }
        if(x-1 >= 0 && WH[y][x-1]){
            qu.push((LOC){x-1, y, s+1});
        }
        if(y+1 < H && WH[y+1][x]){
            qu.push((LOC){x, y+1, s+1});
        }
        if(y-1 >= 0 && WH[y-1][x]){
            qu.push((LOC){x, y-1, s+1});
        }
    }

    cout << sum - step << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
template<class A,size_t N,class T>void Fill(A(&a)[N],const T&v){fill((T*)a,(T*)(a+N),v);}

const int MOD = 1e9+7; //998244353;

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m=MOD){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m=MOD){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>Fac,Rac;void setF(int n,int m=MOD){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%m;Rac[n-1]=modInv(Fac[n-1],m);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%m;}
//ll comb(int a,int b,int m=MOD){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int N = 1e4+1;
int n, m, d[3]={-1,-1,-1};
void bad(){
  cout << -1 << endl;
  exit(0);
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  FOR(_, 0, m){
    int s, c;
    cin >> s >> c;
    s--;
    if(d[s]>=0 && c!=d[s]) bad();
    d[s] = c;
  }
  if(d[0]==0 && n>1) bad();
  FOR(i, 0, n){
    if(d[i]<0) d[i] = !i && n>1;
    cout << d[i];
  }
  cout << endl;
}

Measured memory_bytes: 3600
package main

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

func toInt(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		panic(err)
	}
	return n
}

type Node struct {
	value int
	prev  *Node
	next  *Node
}

func (n Node) String() string {
	prev := 0
	if n.prev != nil {
		prev = n.prev.value
	}
	next := 0
	if n.next != nil {
		next = n.next.value
	}
	return fmt.Sprintf("prev:%d, value:%d, next:%d", prev, n.value, next)
}

type DoublyLinkedList struct {
	start *Node
	last  *Node
	size  int
}

func (l *DoublyLinkedList) insert(x int) {
	node := &Node{x, nil, l.start}
	if l.size == 0 {
		l.start = node
		l.last = node
	} else if l.size != 0 {
		node.next.prev = node
		l.start = node
	}
	l.size++
}

func (l *DoublyLinkedList) delete(x int) {
	if l.size == 0 {
		return
	} else if l.size == 1 {
		if l.start.value == x {
			l.start = nil
			l.last = nil
			l.size = 0
		}
		return
	} else {
		for node := l.start; node != nil; node = node.next {
			if node.value == x {
				if node.prev != nil {
					node.prev.next = node.next
				} else {
					l.start = node.next
				}
				if node.next != nil {
					node.next.prev = node.prev
				} else {
					l.last = node.prev
				}
				l.size--
				return
			}
		}
	}
}

func (l *DoublyLinkedList) deleteFirst() {
	if l.size == 1 {
		l.start = nil
		l.last = nil
		l.size = 0
	} else if l.size > 1 {
		l.start.next.prev = nil
		l.start = l.start.next
		l.size--
	}
}

func (l *DoublyLinkedList) deleteLast() {
	if l.size == 1 {
		l.start = nil
		l.last = nil
		l.size = 0
	} else if l.size > 1 {
		l.last.prev.next = nil
		l.last = l.last.prev
		l.size--
	}
}

func (l DoublyLinkedList) String() string {
	node := l.start
	xs := make([]string, l.size)
	for i := 0; i < l.size; i++ {
		xs[i] = fmt.Sprintf("%d", node.value)
		node = node.next
	}
	return strings.Join(xs, " ")
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n := toInt(sc.Text())

	l := DoublyLinkedList{}

	for i := 0; i < n; i++ {
		sc.Scan()
		command := sc.Text()
		switch command {
		case "insert":
			sc.Scan()
			v := toInt(sc.Text())
			l.insert(v)
		case "delete":
			sc.Scan()
			v := toInt(sc.Text())
			l.delete(v)
		case "deleteFirst":
			l.deleteFirst()
		case "deleteLast":
			l.deleteLast()
		}
	}

	fmt.Println(l)
}



Measured memory_bytes: 45200
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int gcd(int a, int b) {  
  return b != 0 ? gcd(b, a % b) : a;
}//MAX
int lcm(int a, int b) { 
   return a * b / gcd(a, b);
   }
//MIN

 main() {
string s ="CODEFESTIVAL2016";
string t;
cin >> t;
int che =0;
for(int i=0;i<s.size();i++){
    if(s.at(i)!=t.at(i))che++;
}
cout << che << endl;
 }


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

#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << "\t|";
  __f(comma + 1, args...);
}
 

#define print(x) for(auto it : x) cout<< it << " "; cout << endl;
typedef long long ll;
typedef unsigned long long ull;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    map<string, int> m;
    // AC, WA, TLE, and RE
    for (int i = 0; i < n; i++) {
        string a; cin >> a;
        m[a]++;
    }
    cout << "AC x " << m["AC"] << '\n';
    cout << "WA x " << m["WA"] << '\n';
    cout << "TLE x " << m["TLE"] << '\n';
    cout << "RE x " << m["RE"] << '\n';
    return 0;
}


Measured memory_bytes: 3660
//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl '\n'
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
bool sortbysec(const pair<ll,ll>&a,const pair<ll,ll>&b)
{
    return (a.second<b.second);
}

int main()
{
    ios;
    int n;
    cin>>n;
    int k=ceil(n/2.0);
    cout<<fixed<<setprecision(7)<<(k*1.0)/n*1.0<<endl;



}





Measured memory_bytes: 3784
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

n = arr_data[0][0]

if (n[0]==n[1] and n[0]==n[2]) or (n[1]==n[2] and n[1]==n[3]) :
    
    print("Yes")
else:
    
    print("No")

Measured memory_bytes: 3064
n, m, x = map(int, input().split())
C = [list(map(int, input().split())) for _ in range(n)]

import itertools as it
import math

cost = math.inf
for comb in it.chain(*(it.combinations(C, r) for r in range(1, n+1))):
    c, *a = map(sum, zip(*comb))
    if c < cost and min(a) >= x:
        cost = c

print(-1 if cost is math.inf else cost)


Measured memory_bytes: 9196
n,m=map(int,input().split())
g=[[]for _ in range(n)]
for _ in range(m):
  a,b=map(int,input().split())
  g[a-1].append(b-1)
  g[b-1].append(a-1)
import sys
sys.setrecursionlimit(10**7)

def dfs(t,seen):
  if all(seen):
    return 1
  ret=0
  l=g[t]
  for li in l:
    if seen[li]==0:
      seenli=seen.copy()
      seenli[li]=1
      ret+=dfs(li,seenli)
  return ret
seen=[0]*n
seen[0]=1
print(dfs(0,seen))

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iomanip>
using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int mx = max({ a, b, c });
	cout << 9 * mx + a + b + c << endl;
}

Measured memory_bytes: 256
N = int(input())
Al = ['M', 'A', 'R', 'C', 'H']
S = {}
for _ in range(N):
    s = input()[0]
    if s in Al:
        if not s in S.keys():
            S[s] = 1
        else:
            S[s] += 1
L = S.values()
if len(L) == 3:
    a, b, c = L
    ans = a*b*c
elif len(L) == 4:
    a, b, c ,d = L
    ans = a*b*c + a*b*d + a*c*d + b*c*d
elif len(L) == 5:
    a, b, c, d, e = L
    ans = a*b*c + a*b*d + a*c*d + b*c*d + a*b*e + a*c*e + a*d*e + b*c*e + b*d*e + c*d*e
else:
    ans = 0

print(ans)

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

H, W, K = map(int, input().split())
S = [[int(i) for i in input()[:-1]] for _ in range(H)]

m = float('inf')
for i in range(1 << (H - 1)) :
  pos = [0] * H
  x = 0
  for j in range(H - 1) :
    if i & (1 << j) :
      x += 1
    pos[j+1] = x
  
  ret = x
  x = 0
  cnt = [0] * H
  flag = 0
  while x < W :
    for y in range(H) :
      cnt[pos[y]] += S[y][x]
      if cnt[pos[y]] > K :
        cnt = [0] * H
        ret += 1
        flag += 1
        break
    else :
      x += 1
      flag = 0
      
    if flag == 2 :
      ret = float('inf')
      break
  
  m = min(m, ret)
  
print(m)

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

int main() {
	vector<vector<int>> a(3,vector<int>(3,0));
	for(int i = 0;i < 3;i++)
	{
		for(int j = 0;j < 3;j++)
		{
			cin >> a.at(i).at(j);
		}
	}
	int n;
	cin >> n;
	for(int i = 0;i < n;i++)
	{
		int b;
		cin >> b;
		for(int j = 0;j < 3;j++)
		{
			for(int l = 0;l < 3;l++)
			{
				if(b == a.at(j).at(l))
				{
					a.at(j).at(l) = 0;
				}
			}
		}	
	}
	string k = "No";
	for(int i = 0;i < 3;i++)
	{
		if(a.at(i).at(0)==0&&a.at(i).at(1)==0&&a.at(i).at(2)==0)
		{
			k = "Yes";
		}
		else if(a.at(0).at(i)==0&&a.at(1).at(i)==0&&a.at(2).at(i)==0)
		{
		 	k = "Yes";
		}
	}
	if(a.at(0).at(0)==0&&a.at(1).at(1)==0&&a.at(2).at(2)==0)
	{
		k = "Yes";
	}
	if(a.at(2).at(0)==0&&a.at(1).at(1)==0&&a.at(0).at(2)==0)
	{
		k = "Yes";
	}
	cout << k <<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  long a[100];
  a[0] = 2;
  a[1] = 1;
 
  for(int i = 2; i < n+1; i++){
    a[i] = a[i-1] + a[i-2];
  }
  
  cout << a[n] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
int n , x , ans[202020];

int main(){
    cin >> n >> x;
    if(x == 1 || x == n + n - 1) return puts("No") , 0;
    puts("Yes");
    int l = n , r = n;
    ans[n] = x;
    int lft = 1 , rgt = n + n - 1;
    for(;;){
        if(lft == x) lft++;
        if(rgt == x) rgt--;
        ans[--l] = lft , ans[++r] = rgt;
        lft++;rgt--;
        if(l == 1) break;
        if(lft == x) lft++;
        if(rgt == x) rgt--;
        ans[--l] = rgt , ans[++r] = lft;
        lft++;rgt--;
        if(l == 1) break;
    }
    rep(i,1,n+n) printf("%d\n",ans[i]);
    return 0;
}


Measured memory_bytes: 2304
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int x, i=1;
    
    while (1) {
        
        scanf("%d", &x);
        if (x == 0) break;
        printf("Case %d: %d\n", i, x);
        
        i++;
    }
    
    return 0;
}


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

int main()
{
    int N, sum = 0;
    cin >> N;
    vector<int> A(N), B(101);
    rep(i, N)
    {
        cin >> A[i];
        B[A[i]] = 1;
    }
    rep(i, 101)
    {
        sum += B[i];
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
	Scanner sc;
	
	private void calc() {
		sc = new Scanner(System.in);
		long N = sc.nextLong();
		if ( N%2 == 1) {
			System.out.println(0);
			return;
		}
		
		long n2 = N/2;
		long cnt5 = 0;
		while (n2 > 0) {
			cnt5 += (n2 = n2 / 5);
		}
		System.out.println(cnt5);
	}

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

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


int main() {
    int n, Q;
    cin >> n >> Q;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    for (int j =0; j < Q; j++) {
        ll x; cin >> x;
        ll res = 0;
        int r = 0;
        ll s = 0;
        for (int l = 0; l < n; l++) {
            while (r < n && s + a[r] <= x) {
                s += a[r];
                r++;
            }

            res += r-l;
            if (l == r) r++;
            else s -= a[l];
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 3552
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int t = sc.nextInt();

		if(x-t <= 0) {
			System.out.println(0);
		}else {
			System.out.println(x-t);
		}

	}

}


Measured memory_bytes: 21844
h,w=map(int,input().split())
s=[input().split() for _ in range(h)]

a="ABCDEFGHIJKLMNOPQRSTUVWXYZ"

for i in range(h):
  for j in range(w):
    if s[i][j]=="snuke":
      print(a[j]+str(i+1))
      exit()

Measured memory_bytes: 3060
n = int(input())
xy = []
for _ in range(n):
    x,y = map(int,input().split())
    xy.append((x,y))
    
al,be = 1000000000,1000000000
f = [(1,1),(1,-1),(-1,1),(-1,-1)]
ans = -1145141919810364

for k,l in f:
    alfa = al * k
    beta = be * l
    man = []
    for i,j in xy:
        man.append(abs(alfa-i) + abs(beta-j))
    ans = max(ans,max(man) - min(man))
    
print(ans)

Measured memory_bytes: 142208
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	ll n, a, b;
	cin >> n >> a >> b;
	if(!a){
		cout << 0 << endl;
		return 0;
	}
	ll num = (n / (a + b)) * a;
	n %= (a + b);
	num += min(n, a);
	cout << num << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<vector>
#define rng(i,a) for(int i=0;i<a;i++)
using namespace std;
int main(){
  //これは毎日株を売っていけばいいのでは……
  int a,b,c;
  cin>>a>>b>>c;
  //rngさんすごい
  vector<int>dp(1e6);
  dp[c]=c;
  vector<vector<int> >in(b,vector<int>(a));
  rng(i,b)rng(j,a)cin>>in[i][j];
  rng(i,b-1){
    for(int j=1e6-1;j>=0;j--)
      if(dp[j]!=0){
	rng(k,a)if(j-in[i][k]>=0)dp[j-in[i][k]]=max(dp[j-in[i][k]],dp[j]-in[i][k]+in[i+1][k]);
      }
    vector<int>tmp(1e6);
    rng(i,1e6)if(dp[i])tmp[dp[i]]=dp[i];
    dp=tmp;
    //rng(i,15)cout<<" "<<dp[i];
    //cout<<dp[15]<<endl;
  }
  int ma=-1;
  rng(i,1e6)ma=max(dp[i],ma);
  cout<<ma<<endl;
}

Measured memory_bytes: 9020
K,N=map(int,input().split())
A=list(map(int,input().split()))

B=[]
for i in range(N-1):
    B.append(A[i+1]-A[i])
B.append(K-A[N-1]+A[0])

del B[B.index(max(B))]

print(sum(B))

Measured memory_bytes: 26420
import math


def solve():
    N, X, M = map(int, input().split())

    A = [X]
    vis = [-1] * M
    vis[X] = 0
    for i in range(1, M + 1):
        X = X ** 2 % M
        if vis[X] != -1:
            prefix = A[:vis[X]]
            cycle = A[vis[X]:]
            break
        A.append(X)
        vis[X] = i

    if N < len(prefix):
        return sum(prefix[:N])
    else:
        n_full_period = (N - len(prefix)) // len(cycle)
        suffix_length = N - len(prefix) - n_full_period * len(cycle)
        ans = 0
        ans += sum(prefix)
        ans += sum(cycle) * n_full_period
        ans += sum(cycle[:suffix_length])
        return ans

print(solve())

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def is_prime(num):
    """ 素数判定 """
    from math import sqrt

    if num < 2: 
        return False
    if num in [2, 3, 5]: 
        return True
    if num % 2 == 0 or num % 3 == 0 or num % 5 == 0:
        return False
    # 疑似素数(2でも3でも割り切れない数字)で次々に割っていく
    prime = 7
    step = 4
    num_sqrt = sqrt(num)
    while prime <= num_sqrt:
        if num % prime == 0:
            return False
        prime += step
        step = 6 - step
    return True

N = INT()
a = 2
A = []
while len(A) < N:
    # 素数判定
    if is_prime(a):
        # 数列の中身は全てMOD 5で同じになるものにする
        A.append(a)
    a += 5
print(*A)


Measured memory_bytes: 3064
//K-OS WITH THE OCDE

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <iostream>
#include <numeric>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <deque>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <climits>

using namespace std;

typedef long long int ll;
typedef long double db;


#define TEST ll t; cin>>t; while(t--)
#define vell vector<ll>
#define pl pair<ll,ll>
#define all(v) v.begin(),v.end()
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define dbg(x)  cerr << #x << ": "<< x <<endl
#define dbg2(x,y) cerr<< #x <<": "<< x <<" || "<< #y << ": " << y << endl

#define endl "\n"
#define MAX 1e18
#define MIN INT_MIN
#define mod 1000000007



void solve()
{
	ll x, k, d;
	cin >> x >> k >> d;

	x = abs(x);
	ll r = x / d;
	ll t = min(k , r);

	x -= t * d;
	k -= t;



	if(k) {

		 ll p = abs(x-d);

		 if(k&1)
		 	x = p;
	}

	cout << x;






}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0); cin.tie(0);
	//TEST
	solve();
}



Measured memory_bytes: 3648
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF INT32_MAX / 2
#define PIE 3.14159265358979323

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;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
#define int long long

template <class T>
vector<pair<T,T>> divisor(T n) {
    vector<pair<T,T>> r;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            r.push_back(make_pair(i, n / i));
        }
    }
    sort(r.begin(), r.end());
    return r;
}

int getdigit(int n) {
    int res = 0;
    while (n) {
        n /= 10;
        res++;
    }
    return res;
}

signed main() {
    int n;
    cin >> n;
    if (n == 1) {
        cout << 1 << endl;
        return 0;
    }
    int res = INF;
    auto v = divisor(n);
    for (int i = 0; i < v.size(); i++) {
        chmin(res,max(getdigit(v[i].first), getdigit(v[i].second)));
    }
    cout << res << endl;
    return 0;
}

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

public class Main {
  public static void main(String[] args) {
	FastReader sc = new FastReader();
	String s = sc.next();
	int res = 0;
	
	for (char c: s.toCharArray()) {
		if (c == '+') {
			res++;
		} else {
			res--;
		}
	}
	System.out.println(res);
  }
  
  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 <bits/stdc++.h>
#define lli long long int
using namespace std;
#define MOD 1000000007
#define mod 1000000037
#define mod1 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define INF 2*1e9

lli func1(lli n,lli d)
{
    if(d==1)
        return 1;
    while(n%d==0 and n>=d)
        n=n/d;
    return n%d;
}

lli func(lli n)
{
    lli ans=0;
    for(lli i=1;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
            lli b=n/i;
            //cout << i << " " << b << endl;
            if(i!=b)
            {
                lli t1=func1(n,i),t2=func1(n,b);
                if(t1==1)
                    ans+=1;
                if(t2==1)
                    ans+=1;
            }
            else
            {
                lli t1=func1(n,i);
                if(t1==1)
                    ans+=1;
            }
        }
    }
    return ans-1;
}

lli func2(lli n)
{
    lli ans=0;
    for(lli i=1;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
            lli b=n/i;
            if(i!=b)
                ans+=2;
            else
                ans+=1;
        }
    }
    return ans-1;
}

int main()
{
    fastio;
    lli n;
    cin >> n;
    lli a=func(n);
    lli b=func2(n-1);
    //cout << a << b << endl;
    cout << a+b << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
typedef long long ll;
using namespace std;
int main()
{
  vector<int > a(3);
  cin >> a[0]>> a[1] >> a[2];
  sort(all(a));
  // REP(i,3){cout << a[i] << endl;}
  cout << a[2] - a[0] << endl;
  
}


Measured memory_bytes: 256
using System;
using System.Linq;

class Program
{
  public static void Main(string[] args)
  {
    int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray();
    if(s[0] + s[1] > s[2] + s[3]) Console.WriteLine("Left");
    else if(s[0] + s[1] < s[2] + s[3]) Console.WriteLine("Right");
    else Console.WriteLine("Balanced");
  }
}


Measured memory_bytes: 11348
#include<stdio.h>
int main()
{
	int N,Q,i,r,Y[50]={0};
	char n[50][31]={{"kogakubu10gokan"}};
	scanf("%d%d",&N,&Q);
	for(i=1;i<=N;i++)
		scanf("%d%s",&Y[i],n[i]);
	for(i=1,r=0;i<=N;i++)
		if(Q>=Y[i])
			r=i;
	puts(n[r]);
	return 0;
}

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


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

    for h in range(1, 3500 + 1):
        for n in range(1, 3500 + 1):
            a = large_n * h * n
            b = 4 * h * n - large_n * (n + h)

            if b != 0:
                w, q = divmod(a, b)

                if q == 0 and w > 0:
                    print(h, n, w)
                    exit()


if __name__ == '__main__':
    main()


Measured memory_bytes: 39408
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N;
  cin >> N;
  vector<ll> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }
  ll ans = 0;
  for (int i = 1; i < N - 1; i++) {
    if ((p[i - 1] < p[i] && p[i] < p[i + 1]) ||
        (p[i + 1] < p[i] && p[i] < p[i - 1]))
      ans++;
  }
  cout << ans << endl;
  return 0;
}

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

typedef pair<int,int> ii;

struct Package {
    int a, b, c;

    Package(int x, int y, int z){
        a = x; b = y; c = z;
    }
};

int n, ma, mb, dp[509][509];
vector<Package> packs;

int main(){
    scanf("%d%d%d", &n ,&ma, &mb);
    for(int i=0; i<n; i++){
        int x, y, z; scanf("%d%d%d", &x, &y, &z);
        packs.push_back(Package(x,y,z));
    }

    memset(dp, 63, sizeof dp);
    int INF = dp[0][0]; dp[0][0] = 0;
    for(Package pack : packs) {
        for(int i=400; ~i; i--)
            for(int j=400; ~j; j--)
                if(dp[i][j] == INF) continue;
                else dp[i + pack.a][j + pack.b] = min(dp[i + pack.a][j + pack.b], dp[i][j] + pack.c);
    }

    int ans = INF;
    for(int i=ma, j=mb; i<=500 && j<=500; i+=ma,j+=mb){
        // fprintf(stderr, "%d %d - %d\n", i, j, dp[i][j]);
        ans = min(ans, dp[i][j]);
    }

    printf("%d\n", ans == INF? -1:ans);
    return 0;
}


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

int main() {
  int m,d;
  cin>>m>>d;

  int out=0;
  rep(i, d+1) {
    if(i%10>=2 && i/10>=2 && (i/10)*(i%10)<=m) out++;
  }

  cout <<out<<endl;
}


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


int main(){
  while(true){
    int n;
    cin >> n; 
    if(n == 0)break;
    int s[2][n];
    for(int i=0;i<n;i++)cin >> s[0][i];
    int cnt = 0;
    while(true){
      for(int i=0;i<n;i++)s[1][i] = count(s[0],s[0]+n,s[0][i]);
      bool fin = true;
      for(int i=0;i<n;i++){
	if(s[1][i] != s[0][i])fin = false;
	s[0][i] = s[1][i];
      }
      if(fin)break;
      cnt++;
    }
    cout << cnt << endl;
    for(int i=0;i<n;i++){
      cout << s[0][i];
      i==n-1?cout << endl:cout << ' ';
    }
  }
  return 0;
}

Measured memory_bytes: 1160
#ABC071-B
s = input()

s_set = set(s)
alphabet = "abcdefghijklmnopqrstuvwxyz"
flg = False
for i in range(len(alphabet)):
    if not alphabet[i] in s_set:
        print(alphabet[i])
        flg = True
        break
if not flg:
    print(None)

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

int main() {
  char c;
  cin >> c;
  if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
    cout << "vowel" << endl;
  } else {
    cout << "consonant" << endl;
  }
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,LL> PL;

const int MOD=1000000007;
int INF=100100100;
int main(){
  int a,b,c,d,k;
  cin>>a>>b>>c>>d>>k;
  cout<<max(0,60*c+d-60*a-b-k)<<endl;
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
using namespace chrono;
using ll = long long;
using ii = pair<int, int>;
constexpr int MN = 200002;

int N, A[MN];

time_point<high_resolution_clock> start;

void fast_incorrect() {
    int ans = 0;
    map<int, int> M;
    for (int i = 1; i < N; ++i) {
        if (A[i] <= A[i-1]) {
            if (!ans) ans = 1;
            int x = A[i];
            if (M[x] == ans) {
                int j = x-1;
                while (j > 0 && M[j] == ans) --j;
                if (j > 0) x = j;
            }
            ans = max(++M[x], ans);
            while (rbegin(M)->f > x) M.erase(prev(end(M)));
        }
    }
    cout << ans+1;
    exit(0);
}

bool solve(int K) {
    map<int, int> M;
    for (int i = 1; i < N; ++i) {
        if (duration_cast<duration<double>>(high_resolution_clock::now()-start) > duration<double>(0.8)) fast_incorrect();
        if (A[i] <= A[i-1]) {
            int x = A[i];
            if (M[x] == K) {
                int j = x-1;
                while (j > 0 && M[j] == K) --j;
                if (j > 0) x = j;
                else return 0;
            }
            ++M[x];
            while (M.size() && rbegin(M)->f > x) M.erase(prev(end(M)));
        }
    }
    return 1;
}

int main() {
    if (fopen("in", "r")) freopen("in", "r", stdin), freopen("out", "w", stdout);
    ios_base::sync_with_stdio(0), cin.tie(0);

    start = high_resolution_clock::now();

    cin >> N;
    for (int i = 0; i < N; ++i) cin >> A[i];
    
    bool good = 1;
    for (int i = 1; i < N; ++i) {
        if (A[i] <= A[i-1]) good = 0;
    }
    if (good) {
        cout << 1;
        return 0;
    }

    int l = 1, h = MN;
    for (int i = 0; i < 50; ++i) {
        int m = (l+h)/2;
        solve(m) ? h = m : l = m+1;
    }
    cout << l+1;
}

Measured memory_bytes: 4384
#include<cstdio>
#include<cctype>

using namespace std;

int main(int argc, char const *argv[])
{
    char ch;
    while(1) {
        scanf("%c",&ch);
        if(isalpha(ch)){
            if(islower(ch)){
                printf("%c",toupper(ch));
            }
            else printf("%c", tolower(ch));
        }
        else printf("%c", ch);
        if(ch=='\n') break;
    }
    return 0;
}

Measured memory_bytes: 944
#include <bits/stdc++.h>
using namespace std;
string arr;
int d;
int mod=1e9+7;
long long getsum(int ind,int sum,int flag,vector<vector<vector<long long> > >&dp){
	if(ind==arr.size()) {
		if(sum%d==0) return 1;
		return 0;
	}
	if(dp[ind][sum][flag]!=-1) return dp[ind][sum][flag];
	int limit=9;
	if(!flag) limit=arr[ind]-'0';
	long long res=0;
	for(int i=0;i<=limit;i++){
		if(flag||i<limit){
			res+=getsum(ind+1,(sum+i)%d,1,dp);
		}
		else res+=getsum(ind+1,(sum+i)%d,0,dp);
	}
	dp[ind][sum][flag]=res%mod;
	return res%mod;
	
	
}
int main() {
	
		
		cin>>arr;
	    cin>>d;
	
		
		
		
			vector<vector<vector<long long> > >dp(arr.size()+1,vector<vector<long long> >(200,vector<long long>(2,-1)));
		long long u=getsum(0,0,0,dp);
		
		
		cout<<(u-1+mod)%mod<<endl;
		
		
	
	
	return 0;
}
//hari

Measured memory_bytes: 114104
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>
 
using namespace std;
 
int a[26]; string w;
int main(){
    string S;
    cin >> S;
    if(S=="SUN"){
        cout << 7 << endl;
    }else if(S=="MON"){
        cout << 6 << endl;
    }else if(S=="TUE"){
        cout << 5 << endl;
    }else if(S=="WED"){
        cout << 4 << endl;
    }else if(S=="THU"){
        cout << 3 << endl;
    }else if(S=="FRI"){
        cout << 2 << endl;
    }else if(S=="SAT"){
        cout << 1 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using llong = long long;
#define REP(I, N) for (std::decay_t<decltype(N)> I = 0, I##_LEN = (N); I < I##_LEN; ++I)
#define PER(I, N) for (auto I = (N) - 1; 0 <= I; --I)
#define ALLOF(c) begin(c), end(c)
#define MEM0(x) memset((x), 0, sizeof(x))
#define MEMFF(x) memset((x), 0xFF, sizeof(x))
template<class T> const T big_number;
template<> const int big_number<int> = 1 << 30;
template<> const llong big_number<llong> = ((llong) 1) << 60;

void solve() {
    int a[3];
    cin >> a[0] >> a[1] >> a[2];

    // 1つめがa[0]のとき, a[1]のとき, a[2]のとき
    // 2つめがa[1]のとき, 2つめがa[2]のとき
    // 3つめがa[2]のとき

    // REP (i, 3) {
    // }
    // a[0]a[1]a[2]
    // a[0]a[2]a[1]

    // a[1]a[0]a[2]
    // a[1]a[2]a[0]

    // a[2]a[0]a[1]
    // a[2]a[1]a[0]

    int c = accumulate(ALLOF(a), 1, [](int x, int y) { return x * y; });
    constexpr int e = 5 * 5 * 7;

    if (c == e) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}






int main() {
    ios::sync_with_stdio(false);
    solve();
}



Measured memory_bytes: 256
#include<stdio.h>

int n,i=1,x;
int end_flag = 0;


void checkNum();

void endCheckNum(){
  if(++i <= n){
    checkNum();
  }

  end_flag = 1;
}

void include3(){
  if(end_flag) return;
  
  if(x % 10 == 3){
    printf(" %d",i);
    endCheckNum();
  }
  x /= 10;
  if( x ) include3();

  endCheckNum();
}

void checkNum(){
  if(end_flag) return;
  x = i;
  if(x % 3 == 0){
    printf(" %d",i);
    endCheckNum();
  }

  include3();
}


int main(){
  scanf("%d",&n);
  
  checkNum();
  
  printf("\n");
  return 0;
}



Measured memory_bytes: 2216
<?php /*atcoder.php*/

$t = new temp();

$t->stdin(fgets(STDIN));

unset($t);

class temp{
	private $stdin = array();
	
	public function __construct(){
	}

	public function stdin($data = null){
		$this->stdin = explode(" ", $data);
		
		$s1 = $this->stdin[0] . $this->stdin[1];
		$f = false;
for($i = 1; $i < $s1; $i++){
if ($s1 == ($i * $i)){
echo "Yes";
$f = false;
break;
}else{
$f = true;
}
}
		if($f)echo "No";
	}
	
}

?>


Measured memory_bytes: 3828
import numpy

N = int(input())
AN = list(map(int,input().split()))

ans = 1				#配列数。切らない場合1なので初期値1
beforeDiff = 0				#一つ前の差分値。初期値は任意
chgFlag = True				#区切りフラグ。初期値は0番目に区切った扱いにするのでTrue

for i in range(1,N):			#i-1を参照するため1スタート
	diff = AN[i] - AN[i-1]
	
	if chgFlag or beforeDiff==0:	#符号を維持(区切り直後、前回の差が0)
		beforeDiff = diff	#区切り直後の差分値を入れる(重要なのは符号)
		chgFlag = False	#区切らない
		continue
		
	if (numpy.sign(beforeDiff) == 1 and numpy.sign(diff) == -1) or (numpy.sign(beforeDiff) == -1 and numpy.sign(diff) == 1):		#以前と符号が逆なら区切る
		chgFlag = True		#区切る
		ans += 1
		
print(ans)

Measured memory_bytes: 23140
#include <iostream>
int main()
{
	int n,m;
	int seiza[200][2];
	int point[1000][2];
	while(std::cin>>n,n){
		for(int i=0; i<n; i++)
			std::cin>>seiza[i][0]>>seiza[i][1];
		std::cin>>m;
		for(int i=0; i<m; i++)
			std::cin>>point[i][0]>>point[i][1];
			
		for(int i=0; i<m; i++){
			int j;
			int dx = point[i][0] - seiza[0][0];
			int dy = point[i][1] - seiza[0][1];
			for(j=1; j<n; j++){
				int x = seiza[j][0] + dx;
				int y = seiza[j][1] + dy;
				int k;
				for(k=0; k<m; k++)
					if( point[k][0]==x && point[k][1]==y )break;
				if( k==m )break;
			}
			if( j==n ){
				printf("%d %d\n",dx,dy);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 880
import collections
d=collections.defaultdict(int)
n = int(input())
for i in range(1, n + 1):
    s = str(i)
    d[s[0], s[-1]] += 1
ans = 0
for i in range(1, n + 1):
    s = str(i)
    ans += d[s[-1], s[0]]
print(ans)

Measured memory_bytes: 3316
mod=10**9+7
n=int(input())
a=list(map(int,input().split()))

def gcd(m, n):
    while n:
        m, n = n, m % n
    return m

def lcm(a,b):
  return a*b//gcd(a,b)

L = 1
for i in range(n):
  L = lcm(L, a[i])
ans = 0
L %= mod
for i in range(n):
  ans += L * pow(a[i], mod - 2, mod)
  ans %= mod
print(ans)


Measured memory_bytes: 4084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl

const ll INF=1e11+7;
const ll N = 100003;
ll n,a,b,h[N],ma=0,ans=INF;
ll mid,r,l;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>a>>b;
	FOR(i,0,n){
		cin>>h[i];
		ma=max(ma,h[i]);
	}
	r=0;l=ma/b+1;

	while(l-r>1){
		mid=(l+r)/2;
		ll k=0,p;
		FOR(i,0,n){
			p=h[i];
			p-=b*mid;
			if(p>0){
				k+=p/(a-b);
				if(p%(a-b)!=0)k++;
			}
		}
		if(k>mid){ //can not
			r=mid;
		}else{
			ans=min(ans,mid);
			l=mid;
		}
	}
	ans=r+1;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

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

	int n, i, j, k, ans = 0;
	cin >> n;
	vector<int> a(n);
	for (i = 0; i < n; i++) cin >> a[i];
	for (i = 0; i < n; i++) {
		if (a[i] == ans + 1) ans++;
	}
	ans = n - ans;
	if (ans == n) ans = -1;
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 1152
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

class Prime {
private:
	vector<int> min_pf; // min_pf[i] = minimum prime factor of i
	vector<int> prime;

	// linear sieve https://cp-algorithms.com/algebra/prime-sieve-linear.html
	void sieve(int N) {
		min_pf[0] = min_pf[1] = -1;
		for (int i = 2; i < N; i++) {
			if (min_pf[i] == 0) {
				prime.emplace_back(i);
				min_pf[i] = i;
			}
			for (int j = 0; j < (int)(prime.size()); ++j) {
				if (prime[j] > min_pf[i] || i * prime[j] >= N) break;
				min_pf[i * prime[j]] = prime[j];
			}
		}
	}

public:
	Prime(int N = 1100000) : min_pf(N + 1) { sieve(N + 1); }

	vector<pair<lint, int>> factorize(lint n) {
		vector<pair<lint, int>> res;
		lint sz = (lint)min_pf.size();

		for (lint i = 2; i * i <= n; i++) {
			if (n < sz) break;
			int cnt = 0;
			while (n % i == 0) {
				cnt++;
				n /= i;
			}
			if (cnt) res.emplace_back(i, cnt);
		}

		if (n >= sz) res.emplace_back(n, 1);
		else {
			int prev = min_pf[n], cnt = -1;
			while (n > 0) {
				int now = min_pf[n];
				n /= now;
				cnt++;
				if (prev != now) {
					res.emplace_back(prev, cnt);
					prev = now;
					cnt = 0;
				}
			}
		}

		return res;
	}

	// verified using boost miller_rabin_test https://wandbox.org/permlink/6YepW3J9SQNFwWxu
	bool isPrime(lint n) {
		if (n < (int)(min_pf.size())) return min_pf[n] == n;
		else if (n == 2 || n == 3) return true;
		else if (n % 2 == 0 || n % 3 == 0) return false;
		else if (n % 6 != 1 && n % 6 != 5) return false;
		for (lint i = 5; i * i <= n; i += 6) {
			if (n % i == 0) return false;
			if (n % (i + 2) == 0) return false;
		}
		return true;
	}
};

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int x;
	cin >> x;

	Prime p(110000);
	for (int i = x; ; i++) {
		if (p.isPrime(i)) {
			cout << i << "\n";
			break;
		}
	}

	return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

void Main(){
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans = 0;
    ans = min(a, k);
    k -= a;
    k -= b;
    if (k > 0) ans -= min(k, c);
    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}


Measured memory_bytes: 3656
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007
var inf int = 1000000000000

type lazysegtree struct {
	n    int
	node []int
	lazy []int
}

func newlazySegtree(v []int) *lazysegtree {
	sz := len(v)
	_n := 1
	for _n < sz {
		_n *= 2
	}
	_node := make([]int, 2*_n-1)
	_lazy := make([]int, 2*_n-1)
	for i := 0; i < sz; i++ {
		_node[i+_n-1] = v[i]
	}
	for i := _n - 2; i >= 0; i-- {
		_node[i] = _node[2*i+1] + _node[2*i+2]
	}
	return &lazysegtree{
		n:    _n,
		node: _node,
		lazy: _lazy,
	}
}

// k番目のノードについて遅延評価を行う
func (u lazysegtree) eval(k int, l int, r int) {
	if u.lazy[k] != 0 {
		u.node[k] += u.lazy[k]
		if r-l > 1 {
			u.lazy[2*k+1] += u.lazy[k] / 2
			u.lazy[2*k+2] += u.lazy[k] / 2
		}
		u.lazy[k] = 0
	}
	return
}

func (u lazysegtree) add(a int, b int, x int, k int, l int, r int) {
	if r < 0 {
		r = u.n
	}
	u.eval(k, l, r)
	if b <= l || r <= a {
		return
	}
	if a <= l && r <= b {
		u.lazy[k] += (r - l) * x
		u.eval(k, l, r)
	} else {
		u.add(a, b, x, 2*k+1, l, (l+r)/2)
		u.add(a, b, x, 2*k+2, (l+r)/2, r)
		u.node[k] = u.node[2*k+1] + u.node[2*k+2]
	}
}

//[a,b)内の合計の取得
func (u lazysegtree) getsum(a int, b int, k int, l int, r int) int {
	if r < 0 {
		r = u.n
	}
	if r <= a || b <= l {
		return 0
	}
	u.eval(k, l, r)
	if a <= l && r <= b {
		return u.node[k]
	}
	vl := u.getsum(a, b, 2*k+1, l, (l+r)/2)
	vr := u.getsum(a, b, 2*k+2, (l+r)/2, r)
	return vl + vr
}

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	//予備
	x := iScan()
	if x == 0 {
		fmt.Println(1)
	} else {
		fmt.Println(0)
	}
}

Measured memory_bytes: 1772
import sys
# import math
# import decimal
# import queue
# import bisect
# import heapq
import time
# import itertools

mod = int(1e9+7)
INF = 1<<29

def main():
    n = int(input())
    s = []
    for i in range(n):
        s.append(input())
    s.sort()
    ans = []
    num = 0
    count = 1
    for i in range(1,n):
        if s[i] == s[i-1]:
            count += 1
        else:
            if count > num:
                ans = [s[i-1]]
            elif count == num:
                ans.append(s[i-1])
            num = max(num,count)
            count = 1
        if i == n - 1:
            if count > num:
                ans = [s[i]]
            elif count == num:
                ans.append(s[i])
    for a in ans:
        print(a)
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 83668