akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>


int main(void)
{
	int i, n, min=1000000, max=-1000000,a[10000];
	long long sum = 0;

	scanf("%d", &n);
	
	for (i=0; i < n; i++){
		scanf("%d", &a[i]);
	}

	for (i = 0; i < n; i++){
		if (min>a[i]){
			min = a[i];
		}
	}

	for (i = 0; i < n; i++){
		if (max<a[i]){
			max = a[i];
		}
	}

	for (i = 0; i < n; i++){
		sum += a[i];
	}

	printf("%d %d %lld\n", min, max, sum);

	return 0;
}

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

int n, ret[200], a[200], b[200];

int main() {
    cin >> n;
    for (int i = 1; i <= n; ++i)
        scanf("%d", b + i), a[i] = b[i];
    int tot = 0;
    while (true) {
        int pos = -1;
        for (int i = 1; i <= n - tot; ++i)
            if (b[i] == i) pos = i;
        if (pos == -1) break;
        ret[++tot] = b[pos];
        for (int i = pos; i <= n - tot; ++i)
            b[i] = b[i + 1];
        b[n - tot + 1] = 0;
    }
    if (tot != n) {
        puts("-1");
        return 0;
    }
    for (int i = n; i >= 1; --i) {
        printf("%d\n", ret[i]);
    }
    return 0;
}


Measured memory_bytes: 256
// ABC067/ARC078 A
// 2017/07/15

#include <iostream>
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    if (a % 3 == 0 or b % 3 == 0 or (a + b)%3 == 0){
        cout << "Possible" << endl;
    }else{
        cout << "Impossible" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>

using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
#define rep(i, n) for (i32 i = 0; i < (i32)(n); i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using P = pair<i64, i64>;

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    i64 h, w;
    cin >> h >> w;
    vector<string> a(h);
    rep(i, h)cin >> a[i];
    map<char, int> mp;
    rep(i, h) {
        rep(j, w) {
            mp[a[i][j]]++;
        }
    }
    if (h % 2 == 0 && w % 2 == 0) {
        for (auto v:mp) {
            if (v.second % 4 != 0) {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
        return 0;
    } else if (h % 2 && w % 2) {
        map<i64, i64> cnt;
        for (auto v:mp) {
            cnt[v.second % 4]++;
        }
        if (cnt[3]) {
            cout << "No" << endl;
            return 0;
        } else if (cnt[1] != 1) {
            cout << "No" << endl;
            return 0;
        } else if (cnt[2] > (h - 1) / 2 + (w - 1) / 2) {
            cout << "No" << endl;
            return 0;
        }
        cout << "Yes" << endl;
        return 0;
    }
    if (w % 2)swap(h, w);
    map<i64, i64> cnt;
    for (auto v: mp) {
        cnt[v.second % 4]++;
    }
    if (cnt[1] || cnt[3]) {
        cout << "No" << endl;
        return 0;
    } else if (cnt[2] > w / 2) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

set<int> s;

bool isOk(int n)
{
    while (n > 0)
    {
        if(s.count(n % 10))
            return false;
        n /= 10;
    }
    return true;
}

int main()
{
    int n, k;
    cin >> n >> k;
    for(int i = 0, x; i < k; i++)
    {
        cin >> x;
        s.insert(x);
    }
    while(1)
    {
        if(isOk(n))
            break;
        n++;
    }
    cout << n;
    return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	var a float64
	var b float64
	var h float64
	var m float64

	var ans float64

	sc.Split(bufio.ScanWords)

	a = float64(nextInt())
	b = float64(nextInt())
	h = float64(nextInt())
	m = float64(nextInt())

	ans = math.Sqrt(a*a + b*b - 2*a*b*math.Cos((h*30+m*0.5-m*6)*math.Pi/180))
	fmt.Printf("%g\n",ans)
}

Measured memory_bytes: 1772
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  ll N, K;
  cin >> N >> K;

  ll ret = 0;
  REP(i,1,N+1){
    if(i==1){
      if(K==0) ret += N;
    }else{

      ll a = N/i;
      ll b = N%i;
      
      ret += max(0LL,i-K)*a;
      if(K==0){
        ret += b;
      }else{
        ret += max(0LL, b+1-K);
      }
    }
  }

  cout << ret << endl;
  
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include<memory>
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back
 
typedef long long ll;

using namespace std;

const int mod=1e9+7;
const int INF=1<<25;

int main(){
  int N;
  cin >> N ;
  int temp,pre=-1,cnt=0;
  int a[N];
  rep(i,N)  cin >> a[i] ;
  sort(a,a+N);
  rep(i,N){
    if(pre!=a[i]){
      ++cnt;
      pre=a[i];
    }
  }
  if(cnt % 2){
    cout << cnt << endl;
  }else{
    cout << cnt-1 << endl;
  }

  return 0;
}

Measured memory_bytes: 640
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
total_b = sum(b)
t_c=0
for i in range(1,n):
    if a[i-1]+1==a[i]:
        t_c+=c[a[i-1]-1]

print(total_b+t_c)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
#define pb push_back
#define mp make_pair
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
typedef long long ll;
 
const int inf = int(1e9);
const int mod = 1e9 + 7;
const int N = 1e6 + 555;
const long double PI = acos(-1.0);

void solve()
{	
	int a, b;
	cin >> a >> b;
	if(a > 8 || b > 8) cout << ":(";
	else cout << "Yay!";
}

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


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

const int N = 1e5 + 7;
map<int, int> m;

int main() {
    int n;
    cin >> n;
    int cnt = n;
    while (n--) {
        int a;
        cin >> a;
        if (m.empty()) {
            m[-a]++;
        } else {
            auto p = m.upper_bound(-a);
            if (p != m.end()) {
                m[p->first]--;
                if (m[p->first] == 0) {
                    m.erase(p->first);
                }
                cnt--;
            }
            m[-a]++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 8228
#include<stdio.h>

int main(void)
{
        int i,j,l;
        char a[11],b[11],c[11];

        scanf("%s%s%s",&a,&b,&c);

        i=j=l=0;
        while(a[i] != '\0')
          i++;
        i=i-1;

        while(b[j] != '\0')
          j++;
        j=j-1;

        if(a[i] == b[0]){
          if(b[j] == c[0])
            printf("YES\n");
          else
            printf("NO\n");
   }
        else
          printf("NO\n");

        return 0;
}


Measured memory_bytes: 128
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D: Axis-Parallel Rectangle
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 50;
const long long LINF = 1LL << 62;

/* typedef */

typedef long long ll;
typedef map<int,int> mii;

/* global variables */

int xs[MAX_N], ys[MAX_N], gxs[MAX_N], gys[MAX_N];
mii xmap, ymap;
int as[MAX_N][MAX_N], asums[MAX_N + 1][MAX_N + 1];

/* subroutines */

/* main */

int main() {
  int n, k;
  scanf("%d%d", &n, &k);

  for (int i = 0; i < n; i++)
    scanf("%d%d", &xs[i], &ys[i]), gxs[i] = xs[i], gys[i] = ys[i];

  sort(xs, xs + n);
  int xn = unique(xs, xs + n) - xs;
  for (int i = 0; i < xn; i++) xmap[xs[i]] = i;
  sort(ys, ys + n);
  int yn = unique(ys, ys + n) - ys;
  for (int i = 0; i < yn; i++) ymap[ys[i]] = i;
  //printf("xn=%d, yn=%d\n", xn, yn);

  for (int i = 0; i < n; i++) as[ymap[gys[i]]][xmap[gxs[i]]] = 1;
  for (int y = 0; y < yn; y++)
    for (int x = 0; x < xn; x++)
      asums[y + 1][x + 1] =
	as[y][x] + asums[y + 1][x] + asums[y][x + 1] - asums[y][x];

  ll minar = LINF;
  for (int x0 = 0; x0 < xn; x0++)
    for (int x1 = x0 + 1; x1 <= xn; x1++)
      for (int y0 = 0, y1 = 1; y1 <= yn; y0++) {
	while (y1 <= yn &&
	       asums[y1][x1] - asums[y1][x0] - asums[y0][x1] + asums[y0][x0]
	       < k) y1++;
	if (y1 > yn) break;

	ll ar = (ll)(xs[x1 - 1] - xs[x0]) * (ys[y1 - 1] - ys[y0]);
	if (minar > ar) minar = ar;
      }

  printf("%lld\n", minar);
  return 0;
}


Measured memory_bytes: 256
program prob1
    implicit none
    integer::A, B, K, i
    read(*,*) A, B, K

    i = 0
    do while(i < K)
        if(mod(A,2) == 1) then
            A = A - 1
        end if
        B = B + A/2
        A = A/2
        i = i+1
        if(i == K) then
            exit
        end if
        if(mod(B,2) == 1) then
            B = B - 1
        end if
        A = A + B/2
        B = B/2
        i = i+1
    end do
    write(*,*) A, B
    stop
end program

Measured memory_bytes: 2880
package main

import (
	"fmt"
	"sort"
)

type R struct {
	No    int
	Name  string
	Point int
}

type Rs []R

func (r Rs) Len() int      { return len(r) }
func (r Rs) Swap(i, j int) { r[i], r[j] = r[j], r[i] }
func (r Rs) Less(i, j int) bool {
	if r[i].Name < r[j].Name {
		return true
	} else if r[i].Name == r[j].Name {
		if r[i].Point > r[j].Point {
			return true
		}
	}
	return false
}

func main() {
	var N, P int
	var S string
	fmt.Scan(&N)
	var rs Rs
	for i := 0; i < N; i++ {
		fmt.Scan(&S, &P)
		rs = append(rs, R{No: i + 1, Name: S, Point: P})
	}
	sort.Sort(Rs(rs))
	for i := 0; i < len(rs); i++ {
		fmt.Println(rs[i].No)
	}
}

Measured memory_bytes: 512
package main

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

const (
	Rock         = "Rock"
	Scissors     = "Scissors"
	Paper        = "Paper"
	FailRock     = "FailRock"
	FailScissors = "FailScissors"
	FailPaper    = "FailPaper"
)

func main() {
	in := readLineInt()
	Count, Dup := in[0], in[1]

	in = readLineInt()
	RockP, ScissorsP, PaperP := in[0], in[1], in[2]

	Machine := readLine()
	ResultArray, Result := make([]string, Count), 0

	//fmt.Println(utf8.RuneCountInString(Machine))

	for i, M := range strings.Split(Machine, "") {
		var r string
		switch M {
		case "r":
			r = Paper
		case "s":
			r = Rock
		case "p":
			r = Scissors
		default:
			//fmt.Println("fixme: Fail at switch M")
		}

		if i-Dup >= 0 {
			if isFail(ResultArray[i-Dup]) {
				ResultArray[i] = r
			} else if ResultArray[i-Dup] == r {
				ResultArray[i] = getFail(r)
			} else {
				ResultArray[i] = r
			}
		} else {
			//fmt.Println("initial")
			ResultArray[i] = r
		}
	}

	//fmt.Println(ResultArray)

	for _, v := range ResultArray {
		switch {
		case v == Rock:
			Result += RockP
		case v == Scissors:
			Result += ScissorsP
		case v == Paper:
			Result += PaperP
		case isFail(v):
			Result += 0
		}
	}

	fmt.Println(Result)
}

func isFail(i string) bool {
	return i == FailPaper || i == FailRock || i == FailScissors
}

func getFail(i string) string {
	switch i {
	case Rock:
		return FailRock
	case Scissors:
		return FailScissors
	case Paper:
		return FailPaper
	}
	//fmt.Println("fixme: getFail")
	return ""
}

/////////////////////////////////////////

func readLineInt() []int {
	result := make([]int, 0)
	for _, v := range strings.Split(readLine(), " ") {
		i, _ := strconv.Atoi(v)
		result = append(result, i)
	}
	return result
}

var reader = bufio.NewReaderSize(os.Stdin, 1e6)

func readLine() string {
	result := make([]byte, 0, 1e6)
	for {
		line, remains, e := reader.ReadLine()
		if e != nil {
			panic(e)
		}
		result = append(result, line...)
		if !remains {
			break
		}
	}
	return string(result)
}


Measured memory_bytes: 5248
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] a = new long[n];
    long[] b = new long[n];
    for(int i=0;i<n;i++){
      a[i] = sc.nextInt();
      b[i] = sc.nextInt();
    }
    long[] sum = new long[n];
    long res = 0;
    long diff;
    for(int i=n-1;i>=0;i--){
      a[i] = a[i] + sum[i];
      diff = (a[i]+b[i]-1)/b[i]*b[i]-a[i];
      res+=diff;
      if(i>0){
        sum[i-1] = sum[i]+diff;
      }
    }
    System.out.println(res);
  }
}


Measured memory_bytes: 61572
#include <bits/stdc++.h>
#define fi first
#define se second
using ll = long long;
using namespace std;

int32_t main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    bool ok = false;
    for(int i = 1; i <= 9; ++i) {
        for(int j = 1; j <= 9; ++j) {
            ok |= i * j == n;
        }
    }
    cout << (ok ? "Yes" : "No") << '\n';
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
#define rep(i,ra,re) for((i)=ra;(i)<(re);(i)++)
#define rep_(i,ra,re) for((i)=ra;(i)<=(re);(i)++)
#define put(n) cout << n << " "; 
#define puts(n) cout << n << endl;
#define INF 10e15

static const int MAX_N=10e5,MAX_M=10e5;
long long int N,M,K,X,Y,Z;
long long int maxs=-1,mini=INF,ans,res;
long long int A[MAX_N],B[MAX_N],C[MAX_N];

int main(void){
	cin >> N;
	int i;
	rep(i,0,5){
		cin >> A[i];
		mini=min(A[i],mini);
	}
	long long int res=(N+mini-1)/mini;
	
	puts(5+res-1);
	return 0;
}

Measured memory_bytes: 2304
#include <stdio.h>

#define MAX 100000

int Partition(int *, int, int);

int main() {
  int n, q, i;
  int A[MAX];

  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &A[i]);
  }

  q = Partition(A, 0, n - 1);

  for (i = 0; i < q; i++) {
    printf("%d ", A[i]);
  }
  printf("[%d] ", A[q]);
  for (i = q + 1; i < n - 1; i++) {
    printf("%d ", A[i]);
  }
  printf("%d\n", A[i]);

  return 0;
}

int Partition(int *A, int p, int r) {
  int x, tmp, i, j;
  x = A[r];
  i = p - 1;
  for (j = p; j < r; j++) {
    if (A[j] <= x) {
      i++;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
  }
  tmp = A[i + 1];
  A[i + 1] = A[r];
  A[r] = tmp;
  return i + 1;
}



Measured memory_bytes: 2108
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

//===
struct UnionFind {
    int n;
    vector<int> parent;

    UnionFind() {}
    UnionFind(int nmemb) {
        init(nmemb);
    };

    void init(int nmemb) {
        parent.clear();
        parent.assign(nmemb, -1);
    };

    int root(int x) {
        if (parent[x] < 0) {
            return x;
        }
        return parent[x] = root(parent[x]);
    };

    void unite(int x, int y) {
        x = root(x);
        y = root(y);

        if (x == y) return;

        if (parent[y] < parent[x]) swap(x, y);

        parent[x] += parent[y];
        parent[y] = x;
        
        return;
    };
    
    bool same(int x, int y) {
        return root(x) == root(y);
    };
    int size(int x) {
        return -(parent[root(x)]);
    };
};
//===

llong n, m;
llong p[100005];
UnionFind uf(100005);

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

    for (int i = 0; i < m; i++) {
        llong x, y;
        cin >> x >> y;
        --x, --y;

        uf.unite(p[x], p[y]);
    }

    llong ans = 0;
    for (int i = 0; i < n; i++) {
        if (uf.same(p[i], i + 1)) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
//Modular Exponentiation
    int powmod(int x,int y) 
    { 
        if (y == 0) return 1; 
        int p = powmod(x, y/2) % mod; 
        p = (p * p) % mod;   
        return (y%2 == 0)? p : (x * p) % mod; 
    }
    
    
//Modular Inverse
    int inverse(int a) 
    { 
       return powmod(a,mod-2); 
    }
    
//Binomial Coefficients
    int fact[2000001], factinv[2000001] , coefficientflag = 0;
    void Util_nCr()
    {
        fact[0] = 1 , factinv[0] = 1;
		for(int i = 1 ; i < 2000001 ; i++)       
        // repp(i,1,2000001)
        {
            fact[i] = (fact[i-1] * i)%mod;
            factinv[i] = (factinv[i-1] * inverse(i))%mod;
        }
    }
    int nCr(int n , int r)
    {
        if(!coefficientflag) coefficientflag = 1 , Util_nCr();             
        return ((fact[n] * inverse(fact[n-r]) % mod * inverse(fact[r]))%mod) ;
    }
    
//

signed main() 
{
	int k ;
	cin >> k;
	string s;
	cin >> s;
	int l = s.length()  , ans = 0;
	for(int i = l - 1 ; i < (k+l) ; i++)
		ans = (ans + (nCr(i,l-1)*powmod(25,i - l + 1)%mod*powmod(26,k + l - 1 - i)%mod))%mod;
	cout << ans << endl;
}

Measured memory_bytes: 35612
K, A, B = map(int, input().split())
if A >= B:
    print(K + 1)
    exit()

# A - 1 回叩いて A 枚にする
# 残り K - (A - 1) 回については，A 枚を1 円にして，B 枚のクッキーに増やすを繰り返す．
tmp = K - (A - 1)
if tmp < 0:
    print(K + 1)
    exit()
cnt = tmp // 2
amari = tmp % 2

ans = cnt * B - (cnt - 1) * A + amari
ans = max(ans, K + 1)
print(ans)

Measured memory_bytes: 3064
n,w = map(int,input().split())
dp = [0]*(w+1)

for i in range(n):
    a,b = map(int,input().split())
    for j in range(w+1):
        if b > j:
            continue
        else:
            dp[j] = max(dp[j] , dp[j-b] + a)
            
print(dp[w])


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

using namespace std;
long long n;
int main()
{
    cin>>n;
    long long t = 100;
    for(long long i=1;i<=3760;i++)
    {
        t+=t/100;
        if(t>=n)
        {
            cout<<i;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3572
N=int(input())
Height =list(map(int,input().split()))

from itertools import groupby

ans = [ 1 if Height[i]>=Height[i+1] else 0 for i in range(N-1)  ]

gr = groupby(ans)

total=0
for key,value in gr:
    if key ==1:
        total=max(total,len(list(value)))

print(total)

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

bool comp(int a, int b) {
    
    if(a <= b) return false;
    return true;
}

vector<int> arr[100005];
vector<int> visited(100005,0);

void dfs(int i) {
    
    visited[i]++;
    for(auto j : arr[i]) {
        
        if(!visited[j]) {dfs(j);}
        
    }
}


void solve()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        arr[a].push_back(b);
        arr[b].push_back(a);
    }
    
    int comp = 0;
    for(int i=1;i<=n;i++)
    {
        if(!visited[i])
        {
            comp++;
            dfs(i);
        }
    }
    cout<<comp-1<<endl;
}

int main()
{
    // int t;
    // cin >> t;
    
    // while(t--) {
   
    // }
    
    
    
    solve();
    
    
    

    
}





Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;
typedef pair<int, int> P;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, K;
  cin >> N >> K;
  ll x = N % K;
  cout << min(x, K - x) << endl;
}


Measured memory_bytes: 3648
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef int in;
typedef vector<in> VI;
typedef vector<VI> VVI;
in ggt(in a, in b){
  if(b==0)
    return a;
  return ggt(b,a%b);
}
in n;
in wns(VI& a){
  in sm=0;
  bool fd=0;
  forn(i,n){
    fd|=(a[i]==1);
    sm+=a[i]-1;
    sm%=2;
  }
  if(fd){
    if(sm)
      return 1;
    return 0;
  }
  if(n>=19 && sm)
    return 1;
  VI cds;
  for(in i=1;i*i<=a[0];++i){
    if(a[0]%i==0){
      cds.PB(i);
      cds.PB(a[0]/i);
    }
    if((a[0]-1)%i==0){
      cds.PB(i);
      cds.PB((a[0]-1)/i);
    }
  }
  sort(all(cds));
  in nxt=0;
  forv(i,cds){
    if(cds[i]==1)
      continue;
    if(i && cds[i]==cds[i-1])
      continue;
    cds[nxt++]=cds[i];
  }
  cds.resize(nxt);
  in tid;
  forv(i,cds){
    if((sm+n-1)%cds[i])
      continue;
    if(((sm+n-1)/cds[i]-n)%2==1 && n>=19)
      continue;
    tid=-1;
    bool ok=1;
    forn(j,n){
      if(a[j]%cds[i]==0)
	continue;
      if(a[j]%cds[i]==1){
	if(tid!=-1){
	  ok=0;
	  break;
	}
	tid=j;
	continue;
      }
      ok=0;
      break;
    }
    if(!ok)
      continue;
    if(tid==-1)
      continue;
    VI tp=a;
    --tp[tid];
    in g=tp[0];
    for(in j=1;j<n;++j)
      g=ggt(g,tp[j]);
    forn(j,n)
      tp[j]/=g;
    if(!wns(tp))
      return 1;
  }
  return 0;
}
VI a;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin>>n;
  a.resize(n);
  forn(i,n){
    cin>>a[i];
  }
  if(wns(a))
    cout<<"First"<<endl;
  else
    cout<<"Second"<<endl;
  return 0;
}


Measured memory_bytes: 9728
#include "bits/stdc++.h"

using namespace std;
int main() {
	int N, M;
	cin >> N >> M;
	vector<set<int>> A(N);
	for (int n = 0;n<M;++n) {
		int s,c;
		cin >> s >> c;
		A[s - 1].insert(c);
	}
	
	int ans = 1;
	if (0 == A[0].size()) {
		if (1 == N) {
			ans = 0;
		}
	}
	else if (1 == A[0].size()) {
		ans = *A[0].begin();
		if (0 == ans&&N != 1) {
			cout << "-1" << endl;
			return 0;
		}
	}
	else {
		cout << "-1" << endl;
		return 0;
	}



	for (int n = 1;n<N;++n) {
		int num = 0;
		if (A[n].size()>1) {
			cout <<"-1"<<endl;
			return 0;
		}
		if (A[n].size() == 1) {
			num = *A[n].begin();
		}
		if (num == 0 && 0 == n) {
			if (1 != N) {
				num = 1;
			}
		}
		ans = 10 * ans + num;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3636
import java.util.Arrays;
import java.util.Scanner;


public class Main {
	public static void main(String args[])throws Exception{
		Scanner sc = new Scanner(System.in);
		Integer[] mount = new Integer[10];
		int i = 0;
		while(i != 10){
			mount[i] = sc.nextInt();
			i++;
		}
		sc.close();
		Arrays.sort(mount);
		i = i-1;
		for(;i >= 7;i--){
		System.out.println(mount[i]);
		}
	}
}

Measured memory_bytes: 25944
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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


/*
int V; //頂点数
std::vector<std::vector<edge>> G;  std::vector<int> G;
std::vector<int> d; //sからの距離
*/

struct edge{
    int to, cost;
    edge(int To, int Cost): to(To), cost(Cost){}
};

void dijkstra(std::vector<std::vector<edge>>& G, std::vector<int>& d, int s){
    //pair<int, int> first: 距離　second: 頂点
    std::priority_queue<std::pair<int, int>,
                        std::vector<std::pair<int, int>>,
                        std::greater<std::pair<int, int>>> que;
    int V(G.size());
    d.resize(V, INF+3);
    d[s] = 0;
    que.push({0, s});

    while(!que.empty()){
        std::pair<int, int> p(que.top()); que.pop();
        int v(p.second);
        if(d[v] < p.first) continue;
        for(edge &e: G[v]){
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push({d[e.to], e.to});
            }
        }
    }
}
int main(){
    int V, E, r; std::cin >> V >> E >> r;
    std::vector<std::vector<edge>> G(V);
    {
        int s, t, d; 
        for(int i(0); i < E; ++i){
            std::cin >> s >> t >> d;
            G[s].emplace_back(t, d);
        }
    }
    std::vector<int> d;
    dijkstra(G, d, r);
    for(int i(0); i < V; ++i){
        if(d[i] > INF) std::cout << "INF";
        else std::cout << d[i];
        std::cout << "\n";
    }
    return 0;
}



Measured memory_bytes: 12920
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#include<queue>

using namespace std;

#define INF 999999999
#define REP(i,n) for(int i=0; i<(int)(n); i++)

int main(){
	int H;
	vector <int> p[5];
	int ans, ins;
	
	while(1){
		cin >> H;
		if(!H) break;
		ans = 0;
		REP(i,5) p[i].clear();
		REP(i,H){
			REP(j,5){
				cin >> ins;
				p[j].insert(p[j].begin(), 1, ins);
			}
		}
		int flag=1;
		while(flag){
			flag = 0;
			for(int i=p[2].size()-1;i>=0;i--){
				if(p[2][i]==p[0][i]&&p[2][i]==p[1][i]&&p[2][i]==p[3][i]&&p[2][i]==p[4][i]){
					flag++;
					ans += p[2][i] * 5;
					for(int j=0;j<5;j++)p[j].erase(p[j].begin()+i);
				}
				else if(p[2][i]==p[1][i]&&p[2][i]==p[3][i]&&p[2][i]==p[4][i]){
					flag++;
					ans += p[2][i] * 4;
					for(int j=1;j<5;j++)p[j].erase(p[j].begin()+i);
				}
				else if(p[2][i]==p[0][i]&&p[2][i]==p[1][i]&&p[2][i]==p[3][i]){
					flag++;
					ans += p[2][i] * 4;
					for(int j=0;j<4;j++)p[j].erase(p[j].begin()+i);
				}
				else if(p[2][i]==p[0][i]&&p[2][i]==p[1][i]){
					flag++;
					ans += p[2][i] * 3;
					for(int j=0;j<3;j++)p[j].erase(p[j].begin()+i);
				}
				else if(p[2][i]==p[1][i]&&p[2][i]==p[3][i]){
					flag++;
					ans += p[2][i] * 3;
					for(int j=1;j<4;j++)p[j].erase(p[j].begin()+i);
				}
				else if(p[2][i]==p[3][i]&&p[2][i]==p[4][i]){
					flag++;
					ans += p[2][i] * 3;
					for(int j=2;j<5;j++)p[j].erase(p[j].begin()+i);
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;

int main()
{
  int N;
  cin >> N;
  vector<int> W(N);
  auto * const w = &W[0];
  for (int i = 0; i < N; ++i)
    cin >> w[i];
  auto total = accumulate(w, w + N, 0);
  double half = .5*total;
  int sum = 0;
  int i = 0;
  for (; i < N; ++i)
  {
    sum += w[i];
    if (half <= sum)
      break;
  }
  if (0 != i && half - (sum - w[i]) < sum - half)
    sum -= w[i];
  cout << abs(2*sum - total);
  return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
    ll N;
    cin >> N;
    vector<double> P(N);
    rep(i, N) cin >> P[i];
    vector<vector<double>> dp(N + 1, vector<double>(N + 1, 0));
    dp[0][0] = 1.0;
    rep(i, N) {
        double p = P[i];
        rep(j, i + 1) {
            dp[i + 1][j + 1] += dp[i][j] * p;
            dp[i + 1][j] += dp[i][j] * (1.0 - p);
        }
    }
    double ans = 0;
    rep2(i, (N + 1) / 2, N + 1) {
        ans += dp[N][i];
    }
    cout << ans << '\n';
}

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


Measured memory_bytes: 73736
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  vector<int>a(n);
  int i;
  for(i=0;i<n;i++)cin >> a[i];
  int total = 0;
  for(i=0;i<n;i++)total+=a[i];
  int cnt = 0;
  for(i=0;i<n;i++){
    if(a[i] >= (double)(total)/(4*m))cnt++;
  }
  if(cnt>=m)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

ll mod1e7(ll a){
  return (a % 1000000007);
}

ll mod1e9(ll a){
  return (a % 1000000009);
}

ll mod998(ll a){
  return (a % 998244353);
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}

vector<ll> fac(200001);
void factorial(){
  fac[0] = 1; 
  for(ll i=1; i < 200001; i++){
    fac[i] = mod998(fac[i-1]*i);
  }
}
    
ll nCr(ll n,ll r){
  if(r == 1) return n;
  else if(r == 0) return 1;
  else return mod998(fac[n]/fac[r]/fac[n-r]);
}

int main(){
  ll h,w; cin >> h >> w; ll ans = 0; ll INF = 1e14;
  vector<vector<char>> table(h,vector<char>(w));
  
  rep(i,h){
    rep(j,w){
      cin >> table[i][j];
    }
  }
  
  ll dh[] = {1,-1,0,0}; ll dw[] = {0,0,1,-1};
  
  for(ll i=0; i < h; i++){
    for(ll j=0; j < w; j++){
      if(table[i][j] == '#') continue;
      
      queue<pair<ll,ll>> q;
      vvl num(h,vl(w,INF));
      num[i][j] = 0;
      
      q.push(make_pair(i,j));
      
      while(!q.empty()){
        auto p = q.front();
        q.pop();
        
        ll nowh = p.first; ll noww = p.second;
        
        rep(i,4){
          ll nexth = nowh+dh[i]; ll nextw = noww+dw[i];
          if(0 <= nexth and nexth < h and
             0 <= nextw and nextw < w and
             table[nexth][nextw] == '.' and
             num[nexth][nextw] == INF){
            
            num[nexth][nextw] = num[nowh][noww] + 1;
            q.push(make_pair(nexth,nextw));
          }
        }
      }
      
      ll maxans = 0;
      rep(i,h){
        rep(j,w){
          if(table[i][j] == '.') maxans = max(maxans,num[i][j]);
        }
      }
      
      ans = max(maxans,ans);
    }
  }
  
  cout << ans << endl;
  
  
}

Measured memory_bytes: 4608
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = n - 1; i >= 0; --i)


void sieve(ll n, vector<bool>& out){
    out.resize(n + 1);
    fill(out.begin(), out.end(), true);
    out.at(0) = false;
    out.at(1) = false;
    for(ll i = 2; i <= n; ++i){
        if(out.at(i) == false){ continue; }
        for(ll j = i * 2; j <= n; j += i){
            out.at(j) = false;
        }
    }
}

struct mint{
    static const long long MOD = 1000000007;

    long long v;

    mint() : v(0) {}
    mint(long long x){
        x = x % MOD;
        if(x < 0){ x += MOD; }
        v = x;
    }
    mint& operator+=(mint a){
        v += a.v;
        if(v >= MOD){ v -= MOD; }
        return *this;
    }
    mint& operator*=(mint a){
        v *= a.v;
        v %= MOD;
        return *this;
    }
    mint& operator-=(mint a){
        v -= a.v;
        if(v < 0){ v += MOD; }
        return *this;
    }
    mint& operator/=(mint a){
        return (*this) *= a.inv();
    }

    mint operator*(mint a) const{
        return mint(v) *= a;
    }

    mint operator+(mint a) const {
        return mint(v) += a;
    }

    mint operator-(mint a) const {
        return mint(v) -= a;
    }

    mint operator/(mint a) const {
        return mint(v) /= a;
    }

    mint pow(long long k) const {
        mint res(1),tmp(v);
        while(k){
            if(k&1) res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    mint inv(){return pow(MOD - 2); }

    static mint comb(long long n, int k){
        mint res(1);
        for(int i = 0; i < k; ++i){
            res *= mint(n - i);
            res /= mint(i + 1);
        }
        return res;
    }

    static mint factorial(long long n){
        mint res(1);
        for(int i = n; i > 1; --i){
            res *= mint(i);
        }
        return res;
    }

    bool operator<(const mint &a) const {
        return v < a.v;
    };
};

mint operator*(long long l, mint r){ return r * l; }

std::ostream& operator<<(std::ostream& stream, const mint& m){
    stream << m.v;
    return stream;
}


int main(){
    ll n, k;
    cin >> n >> k;
    vector<mint> dp(k + 1);
    mint ans = 0;
    for(ll g = k; g >= 1; --g){
        dp.at(g) = mint(k / g).pow(n);
        for(ll j = 2; j * g <= k; ++j){
            dp.at(g) -= dp.at(j * g);
        }
        ans += g * dp.at(g);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;


#include <random>

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int D;
    cin>>D;
    int c[26];
    int q[D];
    rep(i,26){
        cin>>c[i];
    }
    int s[D][26];
    rep(i,D){
        rep(j,26){
            cin>>s[i][j];
        }
    }
    int ans=0;
    map<int,int> m;
    int y=0;
    rep(i,D){

        int an=-INF;
        int x=0;
        rep(k,26){
            int a=ans;
            map<int,int> ma=m;
            a+=s[i][k];
            rep(j,26){
                if(j==k){
                    ma[k]=0;
                }else{
                    ma[j]++;
                    a-=ma[j]*c[j];
                }
            }
            if(an<a){
                x=k;
                an=a;
            }
        }
        y=x;
        ans+=s[i][y];
        rep(j,26){
            if(j==y){
                m[y]=0;
            }else{
                m[j]++;
                ans-=m[j]*c[j];
            }
        }
        y++;
        q[i]=y;
    }

    int tr=0;
    std::random_device rnd; 
    while(tr<=16500){
        int g=rnd()%26;
        int h=rnd()%26;
        tr++;
        int ansm=0;
        int r[D];
        rep(i,D){
            if(i==g){
                if(h!=q[i]){
                    r[i]=h;
                }else{
                    r[i]=rnd()%26;
                }

            }else{
                r[i]=q[i];
            }
        }
        map<int,int> mx;
        rep(i,D){
            ansm+=s[i][r[i]];
            rep(j,26){
                if(j==r[i]){
                    mx[r[i]]=0;
                }else{
                    mx[j]++;
                    ansm-=mx[j]*c[j];
                }
            }
        }
        if(ansm>ans){
            rep(i,D){
                q[i]=r[i];
            }
        }
    }
    rep(i,D){
        cout << q[i] << endl;
    }

    



}


Measured memory_bytes: 3752
#include <cstdio>
#include <iostream>
using namespace std;
int n,m;
const int  p = 1000000007;
typedef long long ll;
int main(){
	cin >> n >> m;
	if (n > m)	swap(n,m);
	if (n < m-1){
		cout << 0 << endl;
		return 0;
	}
	ll ans = 1;
	for (int i = 1;i <= n;i++){
		ans = ans*i%p;
	}
	for (int i = 1;i <= m;i++){
		ans = ans*i%p;
	}
	if (n == m)	ans = ans*2%p;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INF 1000000

int n,S[N][N],d[N],color[N],pi[N];

void dijkstra(int s){
  int min,i,u,v;
  for(i=0;i<n;i++){
  d[i]=INF;
  pi[i]=-1;
  color[i]=WHITE;
  }
  d[s]=0;
color[s]=GRAY;
    while(1){
      min =INF;
      u=-1;
      for(i=0;i<n;i++){
        if (color[i] != BLACK && d[i] < min){
        min = d[i];
        u = i;
      }
    }
      if (u==-1){
        break;
      }

    color[u] = BLACK;

    for (v=0;v<n;v++){
      if (color[v] != BLACK && S[u][v]+d[u] < d[v] && S[u][v] != -1){
        d[v] = S[u][v]+d[u];
      }
    }
    }

  }
int main(){
  int i,j,k,c,u,v;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      S[i][j]=-1;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d %d",&v,&c);
      S[u][v]=c;
        }
  }

  dijkstra(0);

for(i=0;i<n;i++){
  printf("%d %d\n",i,d[i]);
}
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#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++)

int main() {
  string s;
  cin >> s;
  if(s=="SUN")cout << 7;
  else if(s=="MON")cout << 6;
  else if(s=="TUE")cout << 5;
  else if(s=="WED")cout << 4;
  else if(s=="THU")cout << 3;
  else if(s=="FRI")cout << 2;
  else if(s=="SAT")cout << 1;
  cout << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int A,B;
  string a,b,c;
  cin>>a>>b>>A>>B>>c;
  if(c==a)
    cout<<A-1<<" "<<B<<endl;
  else	cout<<A<<" "<<B-1<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int a, b, c, d, p, x, y;
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);
	scanf("%d", &d);
	scanf("%d", &p);
	
	x = p * a;
	
	y = b;
	if( p > c){
		y = (( p - c) * d) + y;
	}
	
	if( x < y){
		printf("%d\n", x);
	}else{
		printf("%d\n", y);
	}
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
#define all(a) (a).begin(),(a).end()
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for(ll i = 0;i < (n);i++)
#define rep2(i,n) for(ll i = 0;i < (n);i++)
#define rep3(i,a,b) for(ll i = (a);i < (b);i++)
#define rep4(i,a,b,c) for(ll i = (a);i < (b);i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i = (n)-1;i >= 0;i--)
#define rrep2(i,n) for(ll i = (n)-1;i >= 0;i--)
#define rrep3(i,a,b) for(ll i = (a)-1;i >= (b);i--)
#define rrep4(i,a,b,c) for(ll i = (a)-1;i >= (b);i -= (c))
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define SHOW(x) cout << #x << ": " << x << endl;
template<class T> ll sumArr(const T& a){ return accumulate(all(a), 0LL);}
template<class T> auto minArr(const T& a){ return *min_element(all(a));}
template<class T> auto maxArr(const T& a){ return *max_element(all(a));}
template<class T> void DEBUG_PRINT(T tmp){cout<<tmp<<endl;}
template<class T1,class... T2> void DEBUG_PRINT(T1 tmp,T2... tmp2){cout<<tmp<<" ";DEBUG_PRINT(tmp2...);}
ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;


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

    int x;
    cin>>x;
    rep(i,-1000,1000){
        rep(j,-1000,1000){
            if(pow(i,5) - pow(j,5) == x){
                cout<<i<<" "<<j<<endl;
                return 0;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 4080
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <math.h>
#include <deque>
#include <queue>
#include <assert.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    char c; cin >> c;
    if('a'<=c&&c<='z'){
    	printf("a\n");
    }
    else{
    	printf("A\n");
    }
}




Measured memory_bytes: 3640
from collections import defaultdict
from itertools import groupby, accumulate, product, permutations, combinations
from math import gcd
def reduction(x,y):
    g = gcd(x,y)
    return abs(x)//g,abs(y)//g

def solve():
    mod = 10**9+7
    dplus = defaultdict(lambda: 0)
    dminus = defaultdict(lambda: 0)
    N = int(input())
    xzero = 0
    yzero = 0
    xyzero = 0
    for i in range(N):
        x,y = map(int, input().split())
        if x==0:
            if y==0:
                xyzero += 1
            else:
                xzero += 1
        elif y==0:
            yzero += 1
        elif x*y>0:
            dplus[reduction(x,y)] += 1
        else:
            dminus[reduction(-y,x)] += 1
    pattern = 1
    other = N
    pattern = pow(2,xzero,mod)+pow(2,yzero,mod)-1
    other = N-xzero-yzero-xyzero
    for k,v in dplus.items():
        pattern *= pow(2,dminus[k],mod)+pow(2,v,mod)-1
        other -= dminus[k]+v
    ans = pattern * pow(2,other,mod) - 1
    ans += xyzero
    ans %= mod
    return ans
print(solve())

Measured memory_bytes: 55084
// #pragma GCC optimize("O3", "unroll-loops")
// #pragma GCC target("avx2")
 
#include <bits/stdc++.h>
using namespace std;
 
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
// #define ost tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
#define    int                      long long int
#define    ld                       long double
#define    f(i,j,n)                 for(int i = j; i <= n; i++)
#define    r(i,n,j)                 for(int i = n; i >= j; i--)
#define    mod                      1000000007
#define    speed                    ios_base::sync_with_stdio(false);
#define    upp                      cin.tie(NULL);
#define    pb                       push_back
#define    mp                       make_pair
#define    T                        int ttt; cin >> ttt; while(ttt--)
#define    ff                       first
#define    ss                       second
#define    all(container)            container.begin() , container.end()
#define    sz(container)            (int)container.size()
#define    pii                      pair <int , int>
#define    sp(x)                    setprecision(x)
#define    bp(x)                    __builtin_popcount(x)
 
int power(int x, int y, int p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0; 
    while (y > 0)  
    {     
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res; 
}

int32_t main()
{
    speed upp
    set<string>s;
    int n;
    cin>>n;
    string a;
    f(i,1,n)
    {
        cin>>a;
        s.insert(a);
    }
    cout<<sz(s);
}

Measured memory_bytes: 19248
import java.util.*;


public class Main {
	public static void main (String[] args){
		Scanner sc =  new Scanner(System.in);
		String S = sc.next();
		StringBuffer sb1 = new StringBuffer();
		StringBuffer sb2 = new StringBuffer();
		int Q = sc.nextInt();
		//int sum = 0;
		boolean R = false;
		for(int i = 0; i < Q; i++) {
			int q = sc.nextInt();
			if(q == 1) {
				R = !R;
			}
			else if(q == 2) {
				int F = sc.nextInt();
				String C = sc.next();
				if(F == 1 && R == false) {
					sb1.append(C);
				}					
				else if(F == 2 && R==true){
					sb1.append(C);
				}
				else {
					sb2.append(C);
				}
			}
		}
		StringBuffer sb = new StringBuffer();
		sb1.reverse();
		sb.append(sb1);
		sb.append(S);
		sb.append(sb2);
		if(R == true) {
			sb.reverse();
		}
		System.out.println(sb.toString());
	}	
}

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

int main(){
	string s;
	cin>>s;
	int a=0,z=0;
	rep(i,s.size()){
		if(s.at(i)=='A'){
		a=i;
		break;
		}
	}
	rep(i,s.size()){
		if(s.at(s.size()-1-i)=='Z'){
		z=i;
		break;
		}
	}
	cout<<s.size()-1-z-a+1<<endl;
	//cout<<a<<z;
return 0;}

/*compile
g++ code.cpp
./a.out
run*/

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };




signed main() {
	int r;

	cin >> r;

	if (r < 1200) {
		cout << "ABC" << endl;
	}
	else if (r < 2800) {
		cout << "ARC" << endl;
	}
	else {
		cout << "AGC" << endl;
	}


	return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
using namespace std;
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
int dx[4]={0,0,-1,1},dy[4]={1,-1,0,0};

ll calc(ll a){
  ll cnt=(a+1)/2;
  ll ans=cnt%2;
  if(a%2==0) ans^=a;
  return ans;
}

int main(int argc, char const *argv[]) {
  ll a,b;
  cin >> a >> b;
  ll ans=calc(b)^calc(a-1);
  std::cout << ans << '\n';
  return 0;
}


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

#define fi first
#define se second
#define FO(x, n) for (int x = 0; x < n; ++x)
#define FOR(x, a, b) for (int x = a; x < b; ++x)
#define RFO(x, n) for (int x = n - 1; x >= 0; --x)
#define RFOR(x, a, b) for (int x = b - 1; x >= a; --x)
#define FOR_ITER(x, a) for(auto x = a.begin(); x != a.end(); ++x)

using namespace std;

typedef unsigned char byte;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;
typedef pair<ll, ll> pll;
inline bool feq(const double& a, const double& b) { return fabs(a - b) < 1e-10; }



int n, m;

int main(){
//    int n, l;
//    cin >> n >> k;
//    vector<bool> dislike(10, false);
//
//    FOR(i, 0, k) {
//        int t;
//        cin >> t;
//        dislike[t] = true;
//    }


    int w, a, b;

    cin >> w >> a >> b;

    int rs = 0;
    if(a < b) {
        if (a + w >= b) {
            rs = 0;
        } else {
            rs = b - (a + w);
        }
    } else {
        if (b + w >= a)
        {
            rs = 0;
        } else {
            rs = a - (b + w);
        }
    }
    cout << rs << endl;
    return 0;
}


Measured memory_bytes: 256