akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;

int main() {
    int a,b;
    string c;
    cin >> a >> b >> c;

    c[b - 1] = tolower(c[b-1]);

    cout << c << endl;

    
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stack>
#include <vector>
#include <queue>

using namespace std;

void solve(){
    int num,k;
    cin >> num >> k;
    int ct;
    for(int i=0;i<num;i++){
        int v;
        cin >> v;
        ct+=k<=v;
    }
    cout << ct << endl;
}

int main(){
    solve();
    return 0;
}

Measured memory_bytes: 256
N,M = map(int, input().split())
A = list(map(int, input().split()))

l = len(A)

if N>=2:
  while M>=1:
    A.sort(reverse=True)
    div = A[0]//2
    
    for i in range(l):
      if A[i]>=div:
        if M>=1:
          A[i] = A[i]//2
          M -= 1
        else:
          break
      else:
        break
 
  print(sum(A))
else:
    i=1
    while 2**(i+1)<=A[0]:
      i+=1
    if M>=i:
      print(0)
    else:
      print(A[0]//2**M)

Measured memory_bytes: 14252
#include <iostream>
using namespace std;
int main () {
  int A[4][3][10];
  int n;
  int b, f, r, v;
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 10; k++) {
	A[i][j][k] = 0;
      }
    }
  }

  cin >> n;
  for (int i = 0; i<n; i++) {
    cin >> b >> f >> r >> v;
    if ((b > 0) && (b < 5) && (f > 0) && (f < 4) && (r > 0) && (r < 11)) {
      A[b-1][f-1][r-1] += v;
    }
  }
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 10; k++) {
	cout << " " << A[i][j][k];
      }
      cout << endl;
    }
    if (i != 3) {
      cout << "####################" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1160
H, W = [int(x) for x in input().split(" ")]
if H > W:
    H, W = W, H
if H == 1:
    print(1)

elif H % 2 == 0:
    print(W * (H // 2))
else:
    if W % 2 == 0:
        print(W * H // 2)
    else:
        print(((W - 1) * H // 2) + H // 2 + 1)


Measured memory_bytes: 3060
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys

INF = float('inf')
YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(A: int, B: int, C: int):
    return [NO, YES][not A == B == C and (A == B or B == C or C == A)]


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    print(f'{solve(A, B, C)}')


if __name__ == '__main__':
    main()


Measured memory_bytes: 70424
from collections import*
n,m=map(int,input().split())
e=[[]for _ in range(3*(n+1))]
d=[-3]*(3*(n+1))
for _ in range(m):
  a,b=map(int,input().split())
  e[a]+=[b+n]
  e[a+n]+=[b+2*n]
  e[a+2*n]+=[b]
s,t=map(int,input().split())
q=deque([s])
d[s]=0
while q:
  now=q.popleft()
  for to in e[now]:
    if d[to]!=-3:continue
    d[to]=d[now]+1
    q.append(to)
print(d[t]//3)

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

using namespace std;

typedef long long ll;
#define int ll
typedef long double ld;

typedef pair<int,int> pii;
#define x first
#define y second

const int N=2e6+100,MOD=1e9+7;

int f[N],r[N];

int ppow(int x,int y=MOD-2)
{
    int ans=1;
    while(y)
    {
        if(y&1)
            ans=ans*x%MOD;
        y>>=1;
        x=x*x%MOD;
    }
    return ans;
}

int solve(int x,int y)
{
//    cout<<x<<" "<<y<<" -> "<<flush;
    int ans=f[x+y+2]*r[x+1]%MOD*r[y+1]%MOD;
//    cout<<ans<<endl;
    return ans;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    f[0]=1;
    r[0]=1;
    for(int i=1;i<N;i++)
        f[i]=f[i-1]*i%MOD,
        r[i]=ppow(f[i]);

    int r1,c1,r2,c2;
    cin>>r1>>c1>>r2>>c2;
    cout<<((solve(r2,c2)-solve(r2,c1-1)-solve(r1-1,c2)+solve(r1-1,c1-1))%MOD+MOD)%MOD;
}


Measured memory_bytes: 31488
package main

import (
	"bufio"
	. "fmt"
	"io"
	"math/big"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var n int
	Fscan(in, &n)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
		if a[i] == 0 {
			Fprintln(out, 0)

			return
		}
	}
	s := big.NewInt(1)
	upper := big.NewInt(1e18)
	for _, v := range a {

		s.Mul(s,big.NewInt(int64(v)))
		if s.Cmp( upper)>0 {
			Fprintln(out, -1)
			return
		}
	}
	Fprintln(out, s.Int64())
}

func main() { run(os.Stdin, os.Stdout) }


Measured memory_bytes: 6152
package main

import "fmt"

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}
func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

func main() {
	var N, M int
	var S, T string
	fmt.Scan(&N, &M)
	fmt.Scan(&S, &T)
	m := make(map[int]byte, 0)
	L := lcm(N, M)
	for i := 0; i < N; i++ {
		m[i*(L/N)+1] = S[i]
	}
	good := true
	for i := 0; i < M; i++ {
		if val, ok := m[i*(L/M)+1]; ok {
			if T[i] != val {
				good = false
				break
			}
		}
	}
	if good {
		fmt.Println(L)
	} else {
		fmt.Println(-1)
	}

}


Measured memory_bytes: 4992
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N,K;
	int x[100001];
	vint xplus,xminus;
	scan(N);scan(K);
	rep(i,N){
		scan(x[i]);
		if(x[i]==0){
			K--;
			N--;
			i--;
			continue;
		}
		else if(x[i]>0){
			xplus.push_back(x[i]);
		}
		else{
			xminus.push_back(x[i]);
		}
	}
	if(K==0){
		prin(0);
		return 0;
	}
	sort(xplus.begin(),xplus.end());
	sort(xminus.rbegin(),xminus.rend());
	int ans=INF;
	if(xplus.size()>=K) ans=min(ans,xplus[K-1]);
	if(xminus.size()>=K) ans=min(ans,abs(xminus[K-1]));
	rep1(leftn,K-1){
		int rightn=K-leftn;
		if(xplus.size()>=rightn&&xminus.size()>=leftn){
			ans=min(ans,min(2*xplus[rightn-1]+abs(xminus[leftn-1]),xplus[rightn-1]+2*abs(xminus[leftn-1])));
		}
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 1404
#include <bits/stdc++.h>
using namespace std;
#define fast_io cin.tie(0);ios_base::sync_with_stdio(0);
string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cout << endl; }
void show() { cout << endl; }
void pret() { cout << endl; exit(0);}
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cout << " " << to_string(H); debug_out(T...);}
template <typename Head, typename... Tail> void show(Head H, Tail... T) {cout <<H<<" "; show(T...);}
template <typename Head, typename... Tail> void pret(Head H, Tail... T) {cout <<H<<" "; pret(T...);}
#define pr(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
typedef long long ll;
#define int ll
typedef long double ld;
typedef vector<int> vi;
#define disp(x) cout<<x<<" ";
#define rep(i,a,b) for(int i=a;i<(int)b;i++)
#define fo(i,a,b) for(int i=a;i<=(int)b;i++)
#define rf(i,a,b) for(int i=a;i>=(int)b;i--)
#define mp make_pair
#define pb emplace_back
#define F first
#define S second
#define endl '\n'
//cout.setf(ios::fixed);cout.precision(18)
const int MOD = 1e9+7;
const int maxn = 1e6 + 10;

int divs[maxn];

int32_t main(){
    fast_io;
    fo(i, 1, maxn - 1){
        for (int j = i; j < maxn; j += i)
        {
            divs[j]++;
        }
    }
    int n;
    cin >> n;
    int ans = 0;
    fo(i, 1, n - 1){
        ans += divs[i];
    }
    show(ans);
    return 0;
}

Measured memory_bytes: 11464
n, m = map(int, input().split())
G = [[] for _ in range(n)]
indeg = [0] * n

for _ in range(m):
    l, r, d = map(int, input().split())
    l -= 1
    r -= 1
    G[l].append((r, d))
    G[r].append((l, -d))

from collections import deque
ng = False
visited = [0] * n
visited_cost = [0] * n

for start in range(n):
    if visited[start]:
        continue
    visited[start] = 1
    st = deque([[start, 0]])
    while st:
        i, cost = st.pop()
        for ni, nd in G[i]:
            if visited[ni] == 0:
                visited[ni] = 1
                visited_cost[ni] = cost + nd
                st.append([ni, cost + nd])
            else:
                # 既に記録されていて、矛盾している場合
                if visited_cost[ni] != cost + nd:
                    # 終了
                    ng = True
                    break
        if ng:
            break
    if ng:
        break
print('No' if ng else 'Yes')

Measured memory_bytes: 76456
# ABC090B - Palindromic Numbers
def main():
    a, b = list(map(int, input().rstrip().split()))
    cnt = 0
    for i in range(a, b + 1):
        s = str(i)
        if s == s[::-1]:
            cnt += 1
    print(cnt)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return ~n & 1; }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

main {
  while (true) {
    int p, q, a, n;
    cin >> p >> q >> a >> n;
    if (p == 0 && q == 0 && a == 0 && n == 0) break;
    function<int(int, int, int, int)> dfs = [&](int N, int P, int Q, int lim) -> int {
      if (Q * p == P * q) return 1;
      if (Q * p < P * q || N == 0) return 0;
      int cnt = 0;
      for (int i = lim; i * Q <= a; i++) cnt += dfs(N - 1, i * P + Q, Q * i, i);
      return cnt;
    };
    cout << dfs(n, 0, 1, 1) << endl;
  }
}



Measured memory_bytes: 3044
#include<bits/stdc++.h>
#define ls p<<1
#define rs p<<1|1 
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define mm make_pair
#define pi 2*acos(0.0)
#define lcm(a,b) (a*b)/__gcd(a,b)
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout.precision(i);cout<<fixed<<ans<<endl;
#define lowbit(x) (x)&(-x)
#define out(x) {cout<<x<<endl;return 0;} 
#define all(v) v.begin(),v.end() 
#define mem(x,i) memset(x,i,sizeof(x)) 
#define mec(x,y) memcpy(x,y,sizeof(y))
#define eps 1e-8 
#define ull unsigned long long
#define cps CLOCKS_PER_SEC
using namespace std;
typedef long long ll;
const ll mod=4E18;
const int inf=0x3f3f3f3f;
ll gcd(ll x,ll y){if(y==0) return x;else return gcd(y,x%y);} 
ll ksm(ll a,ll b){ll r=1;while(b){if(b&1) r=(r*a)%mod;a=a*a%mod;b>>=1;}return r;} 
void exgcd(ll a, ll b, ll &x, ll &y, ll &d){if(!b) d=a,x=1,y=0;else exgcd(b,a%b,y,x,d),y-=a/b*x;}
ll inv(ll a, ll p){ll x,y,d;exgcd(a,p,x,y,d);x=(x%p+p)%p;return x;}
inline int read()
{
    char c=getchar();int x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
const int maxn=2e5+100;
ll n,m,k,t;
ll a[maxn];
unordered_map<ll,int> mp;
int main()
{
	cin>>n;
	FOR(i,1,n) {cin>>a[i];a[i]=-a[i];}
	FOR(i,1,n) mp[a[i]+i]++;
	ll ans=0;
	FOR(i,1,n)
	{
		mp[a[i]-i]--;
		ll tmp=-a[i]+i;
		ans+=mp[tmp];
	}
	cout<<ans<<endl;
}

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

int main() {
  int n,m;
  cin>>n>>m;
  vector<int> a(n);
  rep(i,n) cin>>a[i];
  double max=0;
  rep(i,n) max+=a[i];
  max=max/(4*m);
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  bool b=0;
  
  rep(i,m){
  if(a[i]<max){
  b+=1;
  }
  }

  if(b==1){
  cout<<"No"<<endl;
  }
  if(b==0){
  cout<<"Yes"<<endl;
  }
  
  
}

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

using namespace std;

typedef long long	ll;
typedef pair< int, int >	pii;

const int maxsilver = 50 * 50;
const int N = 51;

class No{
public:
	int first, second;
	ll third;
};

vector< No > adj[N];
ll dis[N][maxsilver + 1];
priority_queue< pair< ll, pii > > pq;
const ll inf = ll(1e18);
ll c[N], d[N];

void dijkstra(int s){
	for(int i = 0 ; i < N ; i++){
		for(int j = 0 ; j <= maxsilver ; j++){
			dis[i][j] = inf;
		}
	}

	dis[1][s] = 0;

	pq.push({0, {1, s}});

	while(!pq.empty()){
		auto u = pq.top();
		// printf("%d %d\n", u.second.first, u.second.second);

		pq.pop();

		auto e = u.second;

		if(-u.first > dis[e.first][e.second]){
			continue;
		}

		int aux = e.second;
		ll tim = 0LL;

		if(aux < maxsilver){
			aux += c[e.first];
			tim += d[e.first];

			aux = min(aux, maxsilver);

			if(dis[e.first][aux] > dis[e.first][e.second] + tim){
				dis[e.first][aux] = dis[e.first][e.second] + tim;

				pq.push({-dis[e.first][aux], {e.first, aux}});
			}
		}

		for(auto u: adj[e.first]){
			if(u.second <= e.second){
				if(dis[u.first][e.second - u.second] > dis[e.first][e.second] + u.third){
					dis[u.first][e.second - u.second] = dis[e.first][e.second] + u.third;
					pq.push({-dis[u.first][e.second - u.second], {u.first, e.second - u.second}});
				}
			}
		}
	}

	for(int i = 2 ; i < N ; i++){
		for(int j = 0 ; j <= maxsilver ; j++){
			dis[i][0] = min(dis[i][0], dis[i][j]);
		}
	}
}

int main(){
	int n, m, s;

	scanf("%d %d %d", &n, &m, &s);

	s = min(s, maxsilver);

	for(int i = 0 ; i < m ; i++){
		int u, v, a;
		ll b;

		scanf("%d %d %d %lld", &u, &v, &a, &b);

		adj[u].push_back({v, a, b});
		adj[v].push_back({u, a, b});
	}

	for(int i = 1 ; i <= n ; i++){
		scanf("%lld %lld", &c[i], &d[i]);
	}

	dijkstra(s);

	for(int i = 2 ; i <= n ; i++){
		printf("%lld%c", dis[i][0], '\n');
	}

	return 0;
}

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

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

const int MN = 123456;
int X, Y, Z;
int a[MN], b[MN], ord[MN];
ll l[MN], r[MN];

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

    ll sc = 0;
    cin >> X >> Y >> Z;
    int n = X + Y + Z;
    for (int i = 0; i < n; i++) {
        int c;
        cin >> a[i] >> b[i] >> c;
        sc += c;
        a[i] -= c; b[i] -= c;
    }

    iota(ord, ord + n, 0);
    sort(ord, ord + n, [&](int x, int y) {
        return a[x] - b[x] > a[y] - b[y];
    });

    using MS = multiset<int>;
    MS tr;

    ll sm = 0;
    for (int ii = 0; ii < n; ii++) {
        int i = ord[ii];
        sm += a[i];
        tr.insert(a[i]);
        if (int(tr.size()) > X) {
            sm -= *tr.begin();
            tr.erase(tr.begin());
        }
        if (int(tr.size()) == X) l[ii + 1] = sm;
    }

    sm = 0;
    tr.clear();
    for (int ii = n - 1; ii >= 0; ii--) {
        int i = ord[ii];
        sm += b[i];
        tr.insert(b[i]);
        if (int(tr.size()) > Y) {
            sm -= *tr.begin();
            tr.erase(tr.begin());
        }
        if (int(tr.size()) == Y) r[n - ii] = sm;
    }

    ll ans = -TEN(18);
    for (int i = X; i <= n - Y; i++) {
        ans = max(ans, l[i] + r[n - i]);
    }
    ans += sc;
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 6656
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int ara[n], b[n];
    for(int i=0; i<n; i++)
    {
        cin>>ara[i];
    }
    for(int i=0; i<n; i++)
    {
        b[ara[i] - 1] = i + 1;
    }
    for(int i=0; i<n; i++)
    {
        cout<<b[i]<<" ";
    }
    return 0;
}

Measured memory_bytes: 1536
import sys
# sys.setrecursionlimit(100000)
from collections import defaultdict
from functools import lru_cache


@lru_cache(None)
def gcd(x: int, y: int) -> int:
    if x < y:
        x, y = y, x
    while y > 0:
        r = x % y
        x, y = y, r
    return x


def merge_dict(d1, d2):
    for k, v in d2.items():
        d1[k] += v
    return d1


def input():
    return sys.stdin.readline().strip()


def prime_factorization(N: int) -> dict:
    primes = defaultdict(int)
    primes[1] = 1
    if N < 2:
        return primes
    i = 2
    while i * i <= N:
        while N % i == 0:
            primes[i] += 1
            N = N // i
        i += 1
    if N != 1:
        primes[N] = 1
    return primes


def main():
    n = int(input())
    A = [int(i) for i in input().split()]
    primes = defaultdict(int)
    is_pair_gcd = True
    # pre-process
    for i in range(n):
        p = prime_factorization(A[i])
        for k, v in p.items():
            if k == 1:
                continue
            if k in primes.keys():
                is_pair_gcd = False
                break
            else:
                primes[k] += v
        else:
            continue
        break

    if is_pair_gcd:
        print("pairwise coprime")
        return

    set_gcd = A[0]
    for i in range(1, n):
        set_gcd = gcd(set_gcd, A[i])

    if set_gcd == 1:
        print("setwise coprime")
    else:
        print("not coprime")

    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 353676
#include<bits/stdc++.h>
using namespace std;
int arr[11]={0};
int main()
{
	int a;
	for(int i=0;i<3;i++)
	{
		cin>>a;
		arr[a]++;
	}
	if(arr[5]==2&&arr[7]==1)cout<<"YES";
	else cout<<"NO";

 	return 0;
}


Measured memory_bytes: 256
n, m, x = map(int, input().split())
c = [0] * n
a = []
for i in range(n):
    A = list(map(int, input().split()))
    c[i] = A[0]
    a.append(A[1:])

cmin = 100000 * n + 1

for bit in range(1 << n):
    A = [0] * m
    csum = 0
    for i in range(n):
        if bit & (1 << i):
            for j in range(m):
                A[j] += a[i][j]
            csum += c[i]

    f = True
    for i in A:
        if i < x:
            f = False

    if f:
        cmin = min(cmin, csum)

print((cmin if cmin != 100000 * n + 1 else -1))


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

const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.14159265;

#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); ++i)
#define RFOR(i,n,r) for(ll i = (ll)(n-1); i >= r; --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,n,0)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()

#define cout cout << setprecision(12)

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;
using vp = vector<pair<ll, ll>>;
using vs = vector<string>;
using vc = vector<char>;
using lst = list<ll>;
using pq = priority_queue<ll>;

template < typename T >
inline void dbg(T a) { cout << a << ' '; }

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;
double d;

/*--------------------template--------------------*/

int main() {
    cin >> n;
    cout << (n+1)/2 << endl;
}


Measured memory_bytes: 764
n = int(input())
s = list(map(int,input().split(" ")))
sum_st = 10000000000
for p in range(1,max(s)+1):
  sum_sti = 0
  for x in s:
    sum_sti += (x-p)**2
  if sum_sti < sum_st:
    sum_st = sum_sti
print(sum_st)    

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

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

    string s;

    cin >> s;
    ll n = s.length();

    string s_sub_left = s.substr(0, (n-1)/2);
    string s_sub_right = s.substr((n+3)/2 - 1, (n-1)/2);

    string s_rev = s;
    string s_sub_left_rev = s_sub_left;
    string s_sub_right_rev = s_sub_right;

    reverse(s_rev.begin(), s_rev.end());
    reverse(s_sub_left_rev.begin(), s_sub_left_rev.end());
    reverse(s_sub_right_rev.begin(), s_sub_right_rev.end());

    bool is_valid = true;

    if(s != s_rev){
        is_valid = false;
    }
    if(s_sub_left != s_sub_left_rev){
        is_valid = false;
    }
    if(s_sub_right != s_sub_right_rev){
        is_valid = false;
    }

    if(is_valid){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll N,A,B;
ll S[100010];

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

  cin>>N>>A>>B;
  rep(i,N)cin>>S[i];
  if(A==B){
    ll g=0;
    rep(i,N)g^=(S[i]%(A+1));
    if(g==0)cout<<"Jiro"<<endl;
    else cout<<"Hanako"<<endl;
    return 0;
  }
  if(A>B){
    bool done=false;
    rep(i,N)if(S[i]>B)done=true;
    if(done){
      cout<<"Hanako"<<endl;
    }else{
      ll g=0;
      rep(i,N)g^=S[i];
      if(g==0)cout<<"Jiro"<<endl;
      else cout<<"Hanako"<<endl;
    }
  }else{
    ll idx=-1;
    rep(i,N)if(S[i]>A){
      if(idx!=-1){
        cout<<"Jiro"<<endl;
        return 0;
      }
      idx=i;
    }
    if(idx==-1){
      ll g=0;
      rep(i,N)g^=S[i];
      if(g==0)cout<<"Jiro"<<endl;
      else cout<<"Hanako"<<endl;
    }else{
      ll g=0;
      rep(i,N)if(i!=idx)g^=S[i];
      if(S[idx]>g&&S[idx]-g<=A&&g<=A)cout<<"Hanako"<<endl;
      else cout<<"Jiro"<<endl;
    }
  }

  return 0;
}



Measured memory_bytes: 3956
import java.util.*;
//import java.util.stream.Collectors;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());
		int[] foods = new int[m+1];
		for(int i=0; i<n; i++){
			int k = Integer.parseInt(sc.next());
			for(int j=0; j<k; j++){
				int a = Integer.parseInt(sc.next());
				foods[a]++;
			}
		}
		int count = 0;
		for(int f : foods){
			if(f == n){
				count++;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 38216
#include<stdio.h>
int main(void) {
	int a, b;
	scanf("%d %d", &a, &b);
	if (a < b) {
		printf("a < b\n");
	}
	else if (a > b) {
		printf("a > b\n");
	}
	else if (a = b) {
		printf("a == b\n");
	}
	return  0;
}


Measured memory_bytes: 2044
//templates
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <vector>
#include <unordered_map>
#include <map>
#include <cmath>
#include <iomanip>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(x) (x).begin(),(x).end()
#define sort_key(struct_name,key_name) [](const struct_name &x, const struct_name &y){return x.key_name < y.key_name;}
#define pb(x) push_back(x)
typedef long long ll;
const ll MOD = 1e9 + 7;
using namespace std;

//main
int main(){
  int N,M,C; cin>>N>>M>>C;
  vector<int> B(M);
  rep(i,M) cin>>B[i];
  vector<vector<int>> A(N, vector<int> (M));
  rep(i,N) rep(j,M) cin>>A[i][j];
  int ans=0;
  int sum;
  rep(i,N){
    sum = 0;
    rep(j,M){
      sum += B[j]*A[i][j];
    }
    if(sum+C>0) ans += 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define endl '\n'
#define ld long double
#define FOR(i,a,n) for (ll i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (ll i=(n);i>=(a);--i)
#define FI(i,n) for (ll i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }
 
/*
░░░░░░░░░░░░░░░░░░░░░░░░░
░░█▀▀▄░░░░░░░░░░░▄▀▀█░░░░
░░█░░░▀▄░▄▄▄▄▄░▄▀░░░█░░░░
░░░▀▄░░░▀░░░░░▀░░░▄▀░░░░░
░░░░░▌░▄▄░░░▄▄░▐▀▀░░░░░░░
░░░░▐░░█▄░░░▄█░░▌▄▄▀▀▀▀█░
░░░░▌▄▄▀▀░▄░▀▀▄▄▐░░░░░░█░
░▄▀▀▐▀▀░▄▄▄▄▄░▀▀▌▄▄▄░░░█░
░█░░░▀▄░█░░░█░▄▀░░░░█▀▀▀░
░░▀▄░░▀░░▀▀▀░░▀░░░▄█▀░░░░
░░░░█░░░░░░░░░░░▄▀▄░▀▄░░░
░░░░█░░░░░░░░░▄▀█░░█░░█░░
░░░░█░░░░░░░░░░░█▄█░░▄▀░░
░░░░█░░░░░░░░░░░████▀░░░░
░░░░▀▄▄▀▀▄▄▀▀▄▄▄█▀░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░
*/
 
// I want to be the very best, like no one ever was, I will battle everyday to claim my rightful place
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
// I am questioning life and universe and 
// everything else after looking at this

const ll MAXN = 2e6 + 10;
ll w[MAXN];
ll freq[MAXN];
const ll MOD = 998244353;

ll power(ll x,ll y){
    ll res = 1;

    while(y){
        if(y&1) res = (res*x)%MOD;
        x = (x*x)%MOD;
        y >>= 1;
    }

    return res;
}

void solve(){
    
    FOR(i,1,MAXN-1) w[i] = power(i,MOD-2);

    FOR(i,1,MAXN-1){
        for(ll j=2*i;j<MAXN;j+=i){
            w[j] = ((w[j] - w[i])%MOD + MOD)%MOD; 
        }
    }

    ll n; cin>>n;

    ll ans = 0;
    FOR(i,1,n){
        ll x; cin>>x;
        freq[x]++;
        ans = ((ans - x)%MOD + MOD)%MOD;
    }

    FOR(g,1,MAXN-1){
        ll sum = 0;
        for(ll i=g;i<MAXN;i+=g){
            sum = (sum + (freq[i]*i)%MOD)%MOD;
        }

        ans = (ans + (((sum*sum)%MOD) * w[g])%MOD)%MOD;
    }

    ans = (ans*power(2,MOD-2))%MOD;

    cout<<ans<<endl;
}   

signed main(){
 
   FastRead;    


    ll t;
    t = 1; 
    // cin>>t;
    FOR(i,1,t){
        // clog<<"DEBUGGING ----> "<<i<<endl; 
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}

Measured memory_bytes: 25344
#include<stdio.h>
int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	if(a>b){
		printf("a > b\n");
	}else if(a<b){
		printf("a < b\n");
	}else if(a==b){
		printf("a == b\n");
}
	return 0;
}

Measured memory_bytes: 580
using System.Collections.Generic;
using System;

public class hello
{
    public static void Main()
    {
        string L;
        for (; (L = Console.ReadLine()) != null;)
        {
            string[] line = L.Trim().Split(' ');
            var a = int.Parse(line[0]);
            var b = int.Parse(line[1]);
            getAns(a, b);
        }
    }
    static void getAns(int a, int b)
    {
        var d = new Dictionary<int, int>();
        var d2 = new Dictionary<int, int>();
        var p = 0;
        while (true)
        {
            a *= 10;
            var w0 = a / b;
            var w = a - w0 * b;
            if (w == 0)
            {
                if (w0 != 0) Console.WriteLine(w0);
                else Console.WriteLine();
                return;
            }
            else if (!d.ContainsKey(w)) { Console.Write(w0); d[w] = p++; d2[w] = w0; }
            else
            {
                var flg = true;
                if (d2[w] == w0) { Console.WriteLine(); flg = false; }
                else Console.WriteLine(w0);
                var s = "";
                var imax = flg ? d[w] : d[w] - 1;
                for (int i = 0; i <= imax; i++) s += " ";
                s += new string('^', p - d[w]);
                Console.WriteLine(s);
                return;
            }
            a = w;
        }
    }
}



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

int main()
{
	int x;
	cin >> x;
	for(int i = 1; i < 10; i++){
		for(int j = 1; j < 10; j++){
			if(x == i * j){
					cout << "Yes" << endl;
					return 0;
			}

		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.stream.Stream;

public class Main {

	public static void main(String[] args) throws IOException {

		try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){

			final String inputLine = br.readLine();
			final String[] inputNumbers = inputLine.split(" ");

			Stream<String> stream = Arrays.stream(inputNumbers);

			String[] array = stream.sorted().toArray(String[]::new);
			System.out.println(array[0] + " " + array[1] + " " + array[2]);

		}

	}

}


Measured memory_bytes: 30660
#include<iostream>
#include<cmath>
#include <vector>
using namespace std;

double facctorialMethod(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

double wayOf(int k){
    int sum = 0;
    for (int i = 1; i < k; ++i)
    {
        sum += i;
    }
    return sum;
}

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

  int X[N];
  int Y[N];

  for (int i = 0; i < N; i++) {
    cin >> X[i];
    cin >> Y[i];
  }

  double sum = 0;
  double avr = 0;

  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      sum += sqrt((pow((X[i] - X[j]), 2) + pow((Y[i] - Y[j]), 2)));
    }
  }

  sum *= facctorialMethod(N) * (N - 1) / wayOf(N);
  avr = sum / facctorialMethod(N);

  cout << fixed << avr << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
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; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB(x) push_back(x)
#define MP make_pair
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define couty cout<<'Y'<<'e'<<'s'<<endl
#define coutn cout<<'N'<<'o'<<endl
#define coutY cout<<'Y'<<'E'<<'S'<<endl
#define coutN cout<<'N'<<'O'<<endl
//cout << std::fixed << std::setprecision(15);
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e9;
const long long MOD = 1e9+7;
signed main(){
    int n; cin >> n;
    set<int> set;
    rep(i,n){
        int add; cin >> add;
        set.insert(add);
    }
    if(n==set.size()) coutY;
    else coutN;
}

Measured memory_bytes: 9728
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i, n) ;for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) ;for (int i = s; i < (int)(n);i++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF (922337203685477587+1)
#define sosuu 1000000007


int main() {
  lli A, B, C ,N;
  cin >> A >> B>>  C >> N;
  
  if(N<=A+B){
    if(N<A){
    cout << N << endl;
    return 0;
    }
    cout << A << endl;
    return 0;
  }
  N-=A+B;
  cout << A-N << endl;
    
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
typedef long long int ll;
#define rep(i,n) for (int i = 0; i< (n); i++)
#define Rep(i,n,m) for (int i = (n); i< (m); i++)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
using namespace std;

int main() {
    //vector<int> ans;
    int n, k, q, count = 0;
    cin>>n>>k>>q;
    
    vector<int> a(q);
    rep(i, q) cin>> a[i];
   
    vector<int> ans(n);
    
    rep(i, q){
        ans[a[i]-1] ++;
    }
        
    rep(i, n){
        if(ans[i] + k - q <= 0){
            cout<<"No"<<endl;
        }
        else{
            cout<<"Yes"<<endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int abc(string s, int n)
{
    int cnt=0;
    for (int i=0; i<n-2; i++)
    {
        if (s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
            cnt ++;
    }
    return cnt;
}
int main()
{
    int n;
    string s;
    cin >> n >> s;
    cout << abc(s, n) << endl;
    return 0;
}

Measured memory_bytes: 3564
#include<bits/stdc++.h>
#define ll long long int
#define pragi(a,b) for(ll i = a;i<b;i++)
#define pragj(a,b) for(ll j = a;j<b;j++)
#define pragk(a,b) for(ll k = a;k>=b;k--)
#define all(v) (v.begin(),v.end())
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define KAKA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int mod = 1e9 + 7;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef long double ld;
typedef pair<int, int> pii;
//typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ll, ll> pll;

void Compute(ll n)
{
    KAKA
    vector<bool> present(10000001,false);
    vector<ll> freq(10000001,0);
    vector<ll> v(n);
    pragi(0,n)
    {
        cin>>v[i];
        present[v[i]] = true;
        freq[v[i]]++;
    }
    bool fg = false;
    pragi(0,n)
    {
        if((freq[v[i]] == n) and (n > 1))
        {
          fg = true;
          break;
        }
    }
    ll cnt = 0;
    if(fg) cout<<0<<"\n";
    else{
    if(present[1] and (freq[1] == 1)) cout<<1<<"\n";
    else if(present[1] and (freq[1] > 1)) cout<<0<<"\n";
    else{
    pragi(0,n)
    {
        ll ele = v[i];
        bool flag = true;
        vl factors;
        for(ll j = 2;(j * j) <= ele;j++)
        {
            if((ele % j) == 0)
            {
               factors.eb(j);
               if(j != (ele / j))
               factors.eb(ele/j);
            }
        }
        for(auto f : factors)
        {
            if(present[f])
            {
                flag = false;
                break;
            }
        }
        if((flag) and (freq[ele] > 1))
        {
            flag = false;
        }
        if(flag) cnt++;
    }
    cout<<cnt<<"\n";
    }}
}
int main()
{
    KAKA
    ll n;
    cin>>n;
    Compute(n);
}


Measured memory_bytes: 84228
#include<stdio.h>
#include<algorithm>
#include<string.h>
#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)

using namespace std;

int main(){
	int n,v[100],cnt;
	for(;;){
		scanf("%d",&n);
		if(n==0)break;
		rep(i,n)scanf("%d",v+i);
		cnt=0;
		for(int i=n-1;i>0;i--)reps(j,1,i)if(v[j]<v[j-1]){
			swap(v[j],v[j-1]);
			cnt++;
		}
		printf("%d\n",cnt);
	}
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h> 
int main(){
	int a,b,c,d,e,k;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	scanf("%d",&d);
	scanf("%d",&e);
	scanf("%d",&k);
	if(b-a<=k&&c-a<=k&&d-a<=k&&e-a<=k&&c-b<=k&&d-b<=k&&e-b<=k&&d-c<=k&&e-c<=k&&e-d<=k)
		printf("Yay!");
	else
		printf(":(");
}

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

int main(){
    int N, M, X; cin >> N >> M >> X;
    vector<ll> cost(N);
    vector<vector<ll>> a(N,vector<ll>(M));
    for (int i = 0; i < N; i++)
    {
        cin >> cost[i];
        for (int j = 0; j < M; j++)
        {
            cin >> a[i][j];
        }
    }
    ll n = 1LL << N;
    ll min_cost = LONG_LONG_MAX/2;
    for (ll i = 0; i < n; i++)
    {
        ll icost = 0;
        vector<ll> iskill(M,0);
        for (ll j = 0; j < N; j++)
        {
            if(i & (1LL<<j)) continue;
            icost += cost[j];
            for (int k = 0; k < M; k++) iskill[k]+=a[j][k];            
        }
        bool flag = true;
        for (int k = 0; k < M; k++)
        {
            if(iskill[k]<X){
                flag = false;
                break;
            }
        }
        if(flag==true)
            min_cost = min(min_cost, icost);
    }

    if(min_cost==LONG_LONG_MAX/2) cout << -1 << endl;
    else cout << min_cost << endl;
    
}

Measured memory_bytes: 3632
N,K=map(int,input().split())
t=list(map(int,input().split()))
g=[1]
h={1}
for i in range(N-1):
  x=t[g[i]-1]
  g.append(x)
  if x in h:
    break
  h.add(x)
if K>len(g):
  a=g.index(g[-1])
  b=len(g)-a-1
  K=(K-a)%b+a
print(g[K])

Measured memory_bytes: 32396
import java.util.*;

class Main{

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

		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();

		int max = 0;
		int min = 10;

		if(A>=B && A>=C){
			System.out.println(A*10 + B + C);
		}else if(B>=C && B>=A){
			System.out.println(B*10 + A + C);
		}else{
			System.out.println(C*10 + A + B);
		}

	}
}

Measured memory_bytes: 21460
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printInt(a) printf("%d\n", a)
#define printll(a) printf("%lld\n", a)
#define printdbl(a) printf("%lf\n", a)
#define printYes() printf("Yes\n")
#define printNo() printf("No\n")
#define scanll(a) scanf("%lld", &a)
#define scanInt(a) scanf("%d", &a)
#define scan2Int(a, b) scanf("%d %d", &a, &b)
#define scan3Int(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define scan4Int(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d)
typedef long long ll;
const int INF = 1001001001;
using namespace std;
void swap(int *a, int *b) {
    int tmp = *a;
    *a = *b;
    *b = tmp;
    return;
}
int gdc(int a, int b) {
    int r;
    if (a < b)
        swap(&a, &b);
    r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

int main() {
    ll n, k, tmp;
    scanf("%lld %lld", &n, &k);
    tmp = n % k;
    if (tmp > abs(tmp - k)) {
        printll(abs(tmp - k));
    } else {
        printll(tmp);
    }
    return 0;
}

Measured memory_bytes: 3816
#include<bits/stdc++.h>
using namespace std;
#define INFTY 1<<20
typedef long long int ll;
const int MOD=1000000007;
using Graph = vector<vector<int>>;
#define rep(i,n) for (int i = 0; i < (n); ++i)

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int h,w;
char s[22][22];
int d[22][22];


int main(){
  cin>>h>>w;
  rep(i,h){
    rep(j,w){
      cin>>s[i][j];
    }
  }
  queue<pair<int,int>> que;
  int ans = 0;
rep(sh,h){
  rep(sw,w){
    if(s[sh][sw]=='#')continue;
    rep(i,h){
      rep(j,w){
        d[i][j]=-1;
      }
    }
    que.push(make_pair(sh,sw));
    d[sh][sw]=0;
    while(!que.empty()){
      pair<int,int> now =que.front();
      que.pop();
      int nh = now.first,nw=now.second;
      if(s[nh][nw+1]=='.'&&d[nh][nw+1]==-1){
        d[nh][nw+1]=d[nh][nw]+1;
        que.push(make_pair(nh,nw+1));
      }
      if(s[nh][nw-1]=='.'&&d[nh][nw-1]==-1){
        d[nh][nw-1]=d[nh][nw]+1;
        que.push(make_pair(nh,nw-1));
      }
      if(s[nh+1][nw]=='.'&&d[nh+1][nw]==-1){
        d[nh+1][nw]=d[nh][nw]+1;
        que.push(make_pair(nh+1,nw));
      }
      if(s[nh-1][nw]=='.'&&d[nh-1][nw]==-1){
        d[nh-1][nw]=d[nh][nw]+1;
        que.push(make_pair(nh-1,nw));
      }
    }
    int mx=0;
    rep(i,h){
      rep(j,w){
      mx = max(mx,d[i][j]); 
      }
    }
    ans = max(ans,mx);
  }
}
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
cnt = int(input())
width_list = []
for x in range(cnt):
    width = int(input())
    width_list.append(width)

width_sort = sorted(width_list)
dan = 0
now_width = 0
for x in width_sort:
    if now_width != x:
        dan += 1
    now_width = x
print(dan)

Measured memory_bytes: 3060
import sys
import numpy as np

MOD = 10 ** 9 + 7

I = np.array(sys.stdin.read().split(), dtype=np.int64)
n, m = I[:2]
x = I[2:2+n]
y = I[2+n:]

def main():
    
    sdx = np.sum(x * np.arange(n) - x * np.arange(n-1, -1, -1)) % MOD
    sdy = np.sum(y * np.arange(m) - y * np.arange(m-1, -1, -1)) % MOD
    ans = sdx * sdy % MOD
    return ans
    
if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 37360
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<cstdlib>
#include<iostream>
using namespace std;
int n,k;
bool tf[11],no;
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1,t;i<=k;i++){
		scanf("%d",&t);
		tf[t]=true;
	}
	while(1){
		int m=n;
		no=true;
		while(m>0){
			int t=m%10;
			if(tf[t]){
				no=false;
				break;
			}
			m/=10;
		}
		if(no){
			printf("%d",n);
			break;
		} 
		n++;
	}
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
ll n,m,q;
ll x[15],a[55],b[55],c[55],d[55];
ll ans=0;
void dfs(ll i,ll j){
    x[i]=j;
    if(i==n-1){
        ll tmp=0;
        rep(0,k,q)if((x[b[k]]-x[a[k]])==c[k])tmp+=d[k];
        //cout<<tmp<<endl;
        //rep(0,k,n)cout<<x[k]<<" ";
        //cout<<endl;
        ans=max(ans,tmp);
    }else{
        rep(j,k,m)dfs(i+1,k);
    }
}
int main(void){
    cin>>n>>m>>q;
    rep(0,i,q){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
        --a[i],--b[i];
    }
    rep(0,k,m)dfs(0,k);
    cout<<ans;
}

Measured memory_bytes: 3592
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int util(vector<int>&a,vector<int>&b,vector<int>&c)
{
  int n=a.size();
  int dp[n][3];
  for(int i=0;i<n;i++)
  {
    dp[i][0]=dp[i][1]=dp[i][2]=0;
  }
  dp[0][0]=a[0];
  dp[0][1]=b[0];
  dp[0][2]=c[0];
  for(int i=1;i<n;i++)
  {
    dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
    dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][2]);
    dp[i][2]=c[i]+max(dp[i-1][0],dp[i-1][1]);
  }
  return max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}
int main()
{
  int n;
  cin>>n;
  vector<int> a,b,c;
  for(int i=0;i<n;i++)
  {
    int ta,tb,tc;
    cin>>ta>>tb>>tc;
    a.push_back(ta);
    b.push_back(tb);
    c.push_back(tc);
  }
  int ans=util(a,b,c);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 2796
n = gets.chomp.to_i
ary = []
n.times do |i|
    ary << [gets.chomp.split, i+1].flatten
end
    
ary.sort! {|a,b|
    if a[0] == b[0]
        b[1].to_i <=> a[1].to_i
    else
        a[0] <=> b[0]
    end
}
# p ary
ary.each do |item|
    puts item[2]
end


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

int main(){
  int a,b,c,d,e,f;
  cin>>a>>b>>c>>d>>e>>f;
  int w, s, W, S, sgrcapa;
  double r = 0.0;
  for(int i = 0; i*a*100 < f; i++){
    for(int j = 0; (i*a+j*b)*100 < f; j++){
      w = (i*a+j*b)*100;
      sgrcapa = min(f-w, w/100*e);
      for(int k = 0; k*c <= sgrcapa; k++){
        s = (sgrcapa-k*c)/d*d + k*c;
        if(r < 1.0*s/(w+s)){
          r = 1.0*s/(w+s);
          W = w, S = s;
        }
      }
    }
  }
  if(S==0) W = a*100;
  cout << W+S << ' ' << S << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

int n, w;

long long arr[100005];

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

    std::cin >> n >> w;
    for(int i=0; i<n; i++)
    {
        long long a, b;
        std::cin >> a >> b;
        for(int j=w; j>a-1; j--) arr[j] = std::max(arr[j], arr[j-a]+b);
    }
    std::cout << *std::max_element(&arr[0], &arr[w+1]) << '\n';
}

Measured memory_bytes: 1024
///mAAria...
#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(),v.end()
#define allr(v) v.begin(),v.end()
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pii pair<int,int>
#define pi 3.1415926535897932384626433832
#define mod 1000000007
//#define mod 998244353
#define inf 1000000000
#define pr1(a) cout << a << endl
#define pr2(a,b)cout << a <<  " " <<b<< endl
#define pr3(a,b,c) cout << a <<" " << b << " " << c << endl

const long double PI = acos(-1);

int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

int gcd(int a, int b){
    if(b==0)return a;
    return gcd(b,a%b);
}

bool power_of_two(int n){
    return ((n&(n-1))==0);

}

void solve(){

    int n;
    cin >> n;
    
    int a[n+1];
    
    for(int i =0;i<n;i++){
        cin >> a[i];
    }
    int mx = a[0];
    int ans = 0;
    for(int i = 0; i<n;i++){
        if(a[i]<mx)ans += (mx - a[i]);
        mx = max(a[i], mx);
    }
    
    cout << ans << endl;
} 

signed main() 
{   
    IOS;
    int t = 1;
    // cin >> t;

    for(int i = 1;i<=t;i++){
        solve();
    }
    return 0;
} 

 
    

Measured memory_bytes: 5208
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mii map<int,int>
#define msi map<string,int>
#define pb push_back
#define mp make_pair
#define M 1101
#define MOD 1000000007
#define fi first
#define se second
#define vi vector<int>
#define vl vector<ll>
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define repl(i,l,r) for(long long i=l;i<=r;++i)
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define ins insert
#define inf INT_MAX
#define vpi vector< pair<int,int> >
#define vpl vector< pair<ll,ll> >
#define eps 1e-9

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;cin>>n;
    int l;cin>>l;
    vi f(n);
    vi g(n);
    rep(i,0,n-1)
    {
        f[i]=abs(l+i);
        g[i]=(l+i);
    }
    sort(all(f));
    int sum=0;
    int c=0;
    rep(i,0,n-1)
    {
        if(g[i]==f[0]|| g[i]==-f[0])
        {
            if(c==0)
            {
                c++;
                continue;
            }

        }
        sum+=g[i];
    }
    cout<<sum<<"\n";
    return 0;

    //check for long long or int
}


Measured memory_bytes: 256