akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    long m = sc.nextLong();
    long d = sc.nextLong();
    if (d == 0) {
      System.out.println(Math.pow(n, (-2)) * (m - 1) * (n - d));
    } else {
      System.out.println(Math.pow(n, (-2)) * (m - 1) * (n - d) * 2);
    }
    
   
    
  }
}

Measured memory_bytes: 21588
# 参考 -> https://atcoder.jp/contests/dp/submissions/8271798

import itertools
import sys
input = sys.stdin.readline

N, MOD = map(int, input().split())
XY = [list(map(int, input().split())) for i in range(N-1)]
prod = lambda x, y: x*y%MOD

tree = [[] for i in range(N)]
for x, y in XY:
  tree[x-1].append(y-1)
  tree[y-1].append(x-1)

root = 0
parent = [-1] * (N+1)
order = []
stack = [root]
while stack:
  node = stack.pop()
  order.append(node)
  for child in tree[node]:
    if child == parent[node]:
      continue
    parent[child] = node
    stack.append(child)

# dp_down[i] : 頂点iを黒く塗ったときの子側の塗り方
dp_down = [0] * N
for node in order[::-1]: # 葉から根に向かって伝搬させる
  res = 1
  for child in tree[node]:
    res *= dp_down[child] + 1
    res %= MOD
  dp_down[node] = res

# dp_up[i] : 頂点iを黒く塗ったときの親側の塗り方
dp_up = [1] * N
for node in order: # 根から葉に向かって伝搬させる
  par = parent[node]
  arr = [dp_down[c]+1 if c!=par else dp_up[node] for c in tree[node]]
  # それぞれの子(=c)について、自身を根とする下側の部分木を除いた積
  left = [1] + list(itertools.accumulate(arr, prod))[:-1]
  right = list(itertools.accumulate(reversed(arr), prod))[-2::-1] + [1]
  upper_cases = [l*r%MOD for l, r in zip(left, right)]
  for c, res in zip(tree[node], upper_cases):
    if c != par:
      dp_up[c] = res + 1 # (+1 : cより上側が全て白である場合を足し合わせる)

ans = [d*u%MOD for d, u in zip(dp_down, dp_up)]
print(*ans, sep='\n')

Measured memory_bytes: 62148
#include "bits/stdc++.h"
using namespace std;

//約数の個数
long long calc(long long N) {
	vector<long long> x;
	for (long long i = 2; i*i <= N; i++) {
		int m = 0;
		while (N%i == 0) { // 素数で割り切れなくなるまで割っていく
			m++;//割った個数を配列に足す
			N /= i;
		}
		if (0 != m) {
			x.push_back(m);
		}
		if (1 == N) {
			break;
		}
	}
	if (1 != N) {
		x.push_back(1);
	}

	long long nAns = 1;
	for (long long n = 0; n < x.size(); ++n) {
		nAns *= x[n] + 1;
	}
	return nAns;
}

int main() {
	int N;
	cin >> N;
	int ans = 0;
	for (int i = 1; i <= N; i += 2) {
		if (8 == calc(i)) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3596
#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()
{
    int n, k;
    cin >> n >> k;
    int ans = 0;
    while (n)
    {
        n /= k;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
int main() {
	//input
	int A, B, C, K;
	cin >> A >> B >> C >> K;


	//calculation
	int output = 0;
	if (K <= A) {
		output = K;
	} else if (K <= A + B) {
		output = A;
	} else {
		output = 2 * A + B - K ;
	}

	//output
	cout << output << endl;


	return 0;
}


Measured memory_bytes: 3632
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list sep conv);
  arr

let rec powerset e =
  match Enum.get e with
  | None -> Enum.singleton @@ Enum.empty ()
  | Some v ->
    let f = powerset e in
    let g = Enum.clone f in
    EnumL.map f ~f:(fun x -> let y = Enum.clone x in push y v; y)
    |>  Enum.append g

let permutations l =
  let rec aux l =
    let rec interleave x = function
      | [] -> [[x]]
      | (hd::tl) as lst ->
        (x::lst) ::
        (ListL.map ~f:(List.cons hd)  @@ interleave x tl)
    in
    match l with
    | [] -> [[]]
    | hd::tl -> List.concat @@ List.map (interleave hd) @@ aux tl in
  let l = List.sort (List.compare Int.compare) @@ aux @@ List.of_enum l in
  List.enum % ListL.map ~f:List.enum @@ l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

module UnionFind = struct
  type elem = {root: int; size: int}

  let empty n = Array.init n (fun i -> {root=i; size=1})

  let root t n =
    let rec aux c =
      if c = t.(c).root then c
      else let p = aux t.(c).root in
        t.(c) <- {t.(c) with root=p}; p in
    aux n

  let size t v = t.(root t v).size

  let unite t v0 v1 =
    let w0 = root t v0 in
    let w1 = root t v1 in
    let s = (size t w0)+(size t w1) in
    t.(w0) <- {t.(w0) with size=s};
    t.(w1) <- {t.(w1) with root=w0}

  let same t v0 v1 = root t v0 = root t v1
end

let (n, m) = scan "%d %d" Tuple2.make
let ls = List.rev @@ scan_lines m "%d %d" Tuple2.make

let () =
  let uf = UnionFind.empty (succ n) in
  let rec solve n ans = function
    | [] -> ans
    | (a,b)::rest ->
      if UnionFind.same uf a b then
        solve n (n::ans) rest
      else
        let x = UnionFind.size uf a in
        let y = UnionFind.size uf b in
        let m = x * y in
        UnionFind.unite uf a b;
        solve (n-m) (n::ans) rest
  in
  let sum = n*(pred n)/2 in
  solve sum [] ls
  |> List.map String.of_int
  |> String.join "\n"
  |> Printf.printf "%s\n"


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

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);


int main(void)
{
    ll h,w; cin>>h>>w;
    vector<string> a(h);
    rep(i,h) cin>>a[i];
    ll cnt=0;
    rep(i,h)rep(j,w) if(a[i][j]=='#') cnt++;
    if(cnt==h+w-1) cout<<"Possible"<<endl;
    else cout<<"Impossible"<<endl;
    return 0;
}

Measured memory_bytes: 3564
#include<bits/stdc++.h>
#define llong long long
#define mkpr make_pair
#define x first
#define y second
#define iter iterator
#define riter reversed_iterator
#define y1 Lorem_ipsum_
#define tm dolor_sit_amet_
using namespace std;

inline int read()
{
	int x = 0,f = 1; char ch = getchar();
	for(;!isdigit(ch);ch=getchar()) {if(ch=='-') f = -1;}
	for(; isdigit(ch);ch=getchar()) {x = x*10+ch-48;}
	return x*f;
}

int gcd(int x,int y) {return y==0?x:gcd(y,x%y);}

int main()
{
	int x = read();
	printf("%d\n",360/gcd(x,360));
	return 0;
}

Measured memory_bytes: 3728
#include<bits/stdc++.h>                                                   //---------------------------------------------------------------
                                                                    
# define ll long long   
# define ld long double                                               
# define mod 1000000007LL                                              
# define MAX 100005                                                                                //shortcut keys
                                                                                
# define pb push_back                                                                     
# define mp make_pair                                                     
                                                                  
# define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);        //---------------------------------------------------------------                                       
using namespace std;
int main()
{
	int n,x;
	cin>>n>>x;
	int a[n];int arr[n+1];
	arr[0]=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<n;i++)
	{
		arr[i+1]=arr[i]+a[i];
	}
//	for(int i=0;i<=n;i++)
//	cout<<arr[i];
	int ans=0;
	for(int i=0;i<=n;i++)
	{
		if(arr[i]<=x)
		ans++;
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

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

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;  cin >> a >> b;
    int count = 0;
    FOR(i, a, b + 1) {
      string s = to_string(i);
      if (s[0] == s[4] && s[1] == s[3]) {
        count++;
      }
    }
    cout << count << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> pll;
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define pb push_back
const double PI = acos(-1);
const long long INF = (1LL << 60);
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;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}

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

  ll a, b;
  cin >> a >> b;
  for(ll i = 1; i <= 3; i++){
    if(a*b*i % 2 == 1){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
/*
 *  Author : Jun_SH
 *  Solution for ABC 096 B
 */
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a[5];
    cin>>a[0]>>a[1]>>a[2];
    int k;
    cin>>k;
    sort(a,a+3);
    int sum=0;
    sum+=a[2]<<k;
    sum+=a[0];
    sum+=a[1];
    cout<<sum<<endl;
}


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

#define _LL long long

int* mallocint(int si)
{
    return (int*) malloc(si * sizeof(int));
}

int* inputint(int n)
{
    int *ans = mallocint(n);
    for( int i = 0; i < n; i++ ) cin >> ans[i];
    return ans;
}
vector<int> b[200000];
int ans[200000];
int L[200000];

void calc(int *a, int c, int p, int max)
{
    int premax = max;
    int cindex = -1;
    int cpre = 0;
    if( p >= 0) 
    {
        if( a[c] > L[max - 1] )
        {
            max++;
            L[max - 1] = a[c];
        }
        else
        {
            int s = -1;
            int b = max;
            while( s + 1 < b )
            {
                int m = s + (b - s) / 2;
                if(a[c] > L[m])
                {
                    s = m;
                }
                else
                {
                    b = m;
                    if(a[c] == L[m]) break;
                }
            }
            cindex = b;
            cpre = L[b];
            L[b] = a[c];
        }
        ans[c] = max;
    }
    else
    {
        L[0] = a[c];
        ans[c] = 1;
        max = 1;
    }
    for( auto itr = b[c].begin(); itr != b[c].end(); itr++ )
    {
        if( *itr != p ) calc(a, *itr, c, max);
    }
    max = premax;
    if( cindex >= 0 ) L[cindex] = cpre;
}

int main()
{
    int n;
    cin >> n;
    int *a = inputint(n);
    for(int i = 0; i < n - 1; i++ )
    {
        int u, v;
        cin >> u >> v;
        u--; v--;
        b[u].push_back(v);
        b[v].push_back(u);
    }

    calc(a, 0, -1, 0);
    for( int i = 0; i < n; i++ ) cout << ans[i] << endl;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<char,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

map<int, int> factor(int n){
    map<int, int> res;

    for (int i = 2; i*i <= n; ++i) {
        while(n % i == 0){
            res[i]++;
            n /= i;
        }
    }
    if(n != 1) res[n] = 1;

    return res;
}

int modpow(ll x, ll n){
    int res = 1;
    while(n){
        if(n % 2) res = (ll)res * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }

    return res;
}

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

    int n;
    cin >> n;    

    vector<int> a(n);
    map<int, int> d;
    rep(i, n){
        cin >> a[i];

        map<int, int> mp = factor(a[i]);
        for (auto& p : mp) {
            if(d[p.first] < p.second){
                d[p.first] = p.second;
            }
        }
    }

    ll lcm = 1, ans = 0;
    for (auto& p : d) {
        lcm = (lcm * modpow(p.first, p.second)) % MOD;
    }

    rep(i, n){
        ans = (ans + modpow(a[i], MOD-2)) % MOD;
    }

    cout << ans*lcm%MOD << endl;


    return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef string::const_iterator State;
class ParseError{};
map<int,int> mp[128];
int size[128]={0};
string s;

void init(){
  rep(i,128){
    mp[i].clear();
    size[i]=0;
  }
}

int number(State &begin){
  int num=0;
  while(isdigit(*begin)){
    num*=10;
    num+=*begin-'0';
    begin++;
  }
  return num;
}

int expression(State &begin){
  if(isdigit(*begin)){
    return number(begin);
  }
  char c=*begin;
  begin++;
  if(size[c]==0) return -1;
  begin++;
  int num=expression(begin);
  begin++;
  if(num== -1 || num>=size[c] || mp[c].find(num)==mp[c].end()) return -1;
  return mp[c][num];
}


int declaration(State &begin){
  char c=*begin;
  begin++;
  if(size[c]!=0) return -1;
  begin++;
  int num=number(begin);
  size[c]=num;
  return 1;

}

int assignment(State &begin){
  char c=*begin;
  begin++;
  if(size[c]==0) return -1;
   begin++;
   int num=expression(begin);
   begin++;
   if(num== -1 || num>=size[c]) return -1;
   begin++;
   int num2=expression(begin);
   if(num2==-1) return -1;
   mp[c][num]=num2;
   return 1;
}




int program(State &begin){
  int num=s.size();
  bool flag=false;
  rep(i,num){
    if(s[i]=='='){
      flag=true;
      break;
    }
  }
  if(flag) return assignment(begin);
  else return declaration(begin);
}


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  while(1){
    int cnt=0;
    bool bre=false;
    init();
    while(1){
      
      cin>>s;
      if(s=="."){
	if(cnt==0) return 0;
	if(!bre) cout<<0<<endl;
	break;
      }
      if(bre) continue;
      State begin=s.begin();
      if(program(begin)==-1){
	bre=true;
	cout<<cnt+1<<endl;
      }
      cnt++;
    }
  }

  return 0;
}



Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
int main(void){
    int a, b;
    cin>>a>>b;
    if(a>b){
        cout<<a-1<<endl;
    }else{
        cout<<a<<endl;
    }
}


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

using ll = long long;
const ll MOD = 1e9 + 7;

int main() {
    ll N, A, B;
    cin >> N >> A >> B;
    cout << N / (A + B) * A + min(N % (A + B), A) << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys

H,W = list(map(int, input().rstrip().split()))
#-----

def check(h,w):
    area_diff = h*w

    for i in range(1,h//2+1):
        # 横3分割
        area = [ i*w , ((h-i)//2)*w , ((h-i)//2 + (h-i)%2)*w ]
        area.sort()
        diff = area[2] - area[0]
        area_diff = min( area_diff , diff )
        
        # 横1分割、縦2分割
        area = [ i*w , (h-i)*(w//2) , (h-i)*(w//2 + w%2) ]
        area.sort()
        diff = area[2] - area[0]
        area_diff = min( area_diff , diff )

    return area_diff
#-----


if (H % 3) == 0 or (W % 3) == 0:
    print(0)
    sys.exit()

res1 = check(H,W)
res2 = check(W,H)
print( min(res1,res2) )


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

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

  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;
  vector<int> w;
  vector<int> s;
  for (int i = 0; i <= f + 1; i += 100 * a) {
    for (int j = 0; j < f - i + 1; j += 100 * b) {
      if (i == 0 && j == 0) continue;
      w.push_back(i + j);
    }
  }
  for (int i = 0; i < f + 1; i += c) {
    for (int j = 0; j < f - i + 1; j += d) {
      s.push_back(i + j);
    }
  }
  sort(w.begin(), w.end());
  sort(s.begin(), s.end());
  int u = 0, v = 0;
  for (int &y : w) {
    for (int &x : s) {
      if (y + x > f) break;
      if ((100 + e) * x > (y + x) * e) break;
      if (x * u >= v * (y + x)) {
        u = y + x;
        v = x;
      }
    }
  }
  cout << u << " " << v << '\n';
  return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define ford(i, a, n) for (int i = (int)(n - 1); i >= (int)(a); --i)
#define fore(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

template<typename T>
inline void setmax(T& a, T b) {
    if (a < b) a = b;
}

template<typename T>
inline void setmin(T& a, T b) {
    if (a > b) a = b;
}

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

const int N = 1e5 + 10;

int d[2][N];
vector<int> e[N];

void dfs(int v, int pr, int ix) {
    if (pr == -1) d[ix][v] = 0;
    else d[ix][v] = d[ix][pr] + 1;

    for (int u : e[v])
        if (u != pr)
            dfs(u, v, ix);
}


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

    int n;
    cin >> n;
    forn(i, 1, n) {
        int u, v;
        cin >> u >> v;
        e[u].eb(v);
        e[v].eb(u);
    }
    dfs(1, -1, 0);
    dfs(n, -1, 1);
    int f = 0, s = 0;
    fore(i, 1, n) {
        if (d[0][i] <= d[1][i]) ++f;
        else ++s;
    }
    if (f > s) cout << "Fennec\n";
    else cout << "Snuke\n";
}


Measured memory_bytes: 11264
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {

	int a;
	set<int> s;
	for (int i = 0; i < 3; i++) {
		cin >> a;
		s.insert(a);
	}

	cout << s.size() << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define ll long long

int main(void) {
    ll n, k, x, tmp;
    scanf("%lld %lld", &n, &k);
    x = n % k;
    
    tmp = llabs(x - k);

    if (x > tmp) printf("%lld\n", tmp);
    else printf("%lld\n", x);

    return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>

#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds
#define ends asdgahhfdsfshdshfd
#define right asdashgasrhsdf

#define eps 1e-14
#define M_PI 3.141592653589793
#define bs 663224321
#define bsize 64

#define ldouble long double

using namespace std;

long long INF = 1e9;
const int N = 220031;

int n,ar[N];

vector<int> g[N];
int used[N];
vector<int> ans;

int gcd(int a,int b)
{
	while (a&&b)a>b?a%=b:b%=a;
	return a+b;
}

vector<int> run_merge(vector<int> a,vector<int> b){

	vector<int> ret;

	int ptr1=0;
	int ptr2=0;

	while (ptr1<a.size()||ptr2<b.size())
	{
		if (ptr1==a.size())
		{
			ret.push_back(b[ptr2]);
			++ptr2;
		}
		else if (ptr2==b.size())
		{
			ret.push_back(a[ptr1]);
			++ptr1;
		}
		else if (a[ptr1]>b[ptr2])
		{
			ret.push_back(a[ptr1]);
			++ptr1;
		}
		else
		{
			ret.push_back(b[ptr2]);
			++ptr2;
		}
	}
	return ret;
}

vector<int> dfs(int v){
	vector<int> here;
	used[v]=1;
	for (int i=0;i<g[v].size();i++)
	{
		int to=g[v][i];
		if (used[to])
			continue;
		vector<int> v2=dfs(to);
		here=run_merge(here,v2);
	}
	here.insert(here.begin(),ar[v]);
	return here;
}

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

	cin>>n;
	for (int i=1;i<=n;i++)
	{
		cin>>ar[i];
	}

	sort(ar+1,ar+n+1);

	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=n;j++)
		{
			if (gcd(ar[i],ar[j])!=1)
			{
				g[i].push_back(j);
				g[j].push_back(i);
			}
		}
	}

	for (int i=1;i<=n;i++)
	{
		if (used[i])
			continue;
		vector<int> here=dfs(i);
		ans=run_merge(ans,here);
	}

	for (int i=0;i<ans.size();i++)
	{
		if (i)
			cout<<" ";
		cout<<ans[i];
	}
	cout<<endl;

	cin.get(); cin.get();
	return 0;
}


Measured memory_bytes: 36992
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;

int main()
{
    int N, L;
    cin >> N >> L;
    int absMin = 10000;
    int eraseTaste = 0;
    int sum = 0;
    for (int i = 1; i <= N; ++i)
    {
        int taste = L + i - 1;
        sum += taste;
        int absTaste = abs(taste);
        if (absTaste < absMin)
        {
            absMin = absTaste;
            eraseTaste = taste;
        }
    }
    cout << sum - eraseTaste << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
template<typename T>
struct Edge {
    int from, to;
    T cost;
    Edge(int from, int to, T cost) {
        this->from = from;
        this->to = to;
        this->cost = cost;
    }
};
bool operator == (Edge<int> e1, Edge<int> e2) {
    return e1.from == e2.from &&
            e1.to == e2.to &&
            e1.cost == e2.cost;
}
template<typename T>
using Edges = std::vector<Edge<T>>;
template<typename T>
using Graph = std::vector<Edges<T>>;
template <typename T>
std::vector<T> dijkstra(const Graph<T> &g, int s) {
    int sz = (int)(g.size());
    std::vector<T> dist(sz, std::numeric_limits<T>::max());
    std::priority_queue<std::pair<T, int>, std::vector<std::pair<T, int>>, std::greater<std::pair<T, int>>> pq;
    dist[s] = 0;
    pq.push({0, s});
    while(!pq.empty()) {
        T d = pq.top().first;
        int now = pq.top().second;
        pq.pop();
        if(d > dist[now]) continue;
        for(int i=0;i<(int)(g[now].size());++i) {
            int next = g[now][i].to;
            T cost = g[now][i].cost;
            if(dist[next] > dist[now] + cost) {
                dist[next] = dist[now] + cost;
                pq.push({cost, next});
            }
        }
    }
    return dist;
}
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  while(1) {
    int n, m, p, a, b; cin >> n >> m >> p >> a >> b;
    a--; b--;
    if(n == 0) break;
    vector<int> t(n);
    for(int i=0;i<n;++i) {
      cin >> t[i];
    }
    Graph<int> g1(m);
    for(int i=0;i<p;++i) {
      int x, y, z; cin >> x >> y >> z;
      x--; y--;
      g1[x].push_back(Edge<int>(x, y, z));
      g1[y].push_back(Edge<int>(y, x, z));
    }
    int tmp = 1;
    int now = n;
    while(now > 0) {
      now--;
      tmp *= 2;
    }
    Graph<double> g2(tmp * m);
    for(int i=0;i<m;++i) {
      for(int j=0;j<(int)(g1[i].size());++j) {
        int now = g1[i][j].from, next = g1[i][j].to;
        double cost = g1[i][j].cost;
        for(int k=0;k<tmp;++k) {
          for(int l=0;l<n;++l) {
            if((k>>l)&1) {
              g2[tmp*now + k].push_back(Edge<double>(tmp*now+k, tmp*next + (k ^ (1<<l)), (double)cost / (double)t[l]));
            }
          }
        }
      }
    }
    vector<double> d = dijkstra(g2, tmp * (a+1) - 1);
    double mi = INF;
    for(int i=0;i<tmp;++i) {
      mi = min(mi, d[tmp * b + i]);
    }
    if(mi == INF) cout << "Impossible" << endl;
    else cout << mi << endl;
  }
}



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

# N, Sの入力
n = int(input())
s = input()

x = 0
maxi = x
for i in list(s):
    if i is 'I':
        x += 1
    elif i is 'D':
        x -= 1
    if x >= maxi:
        maxi = x

# 最大値の出力
print(maxi)


Measured memory_bytes: 2940
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <math.h>
#include <iomanip>
#include <algorithm>
using namespace std;

long double dist(long double a, long double b) {
    long double x = sqrt(a*a + b*b);
    return x;
}
 
int main(){
	long double a, b, h, m;
	cin >> a >> b >> h >> m;
	long double x1, x2, y1, y2, x, y, ans;
    long double PI = M_PI;
	x1 = a*sin((h+m/60)*(PI/6));
	x2 = b*sin(m*PI/30);
    y1 = a*cos((h+m/60)*(PI/6));
	y2 = b*cos(m*PI/30);
	x = x1 - x2;
	y = y1 - y2;
	ans = dist(x, y);
	cout << setprecision(15) << ans << endl;
	return 0;
}

Measured memory_bytes: 4144
import java.io.IOException;
import java.util.Scanner;

public class Main {

	/**
	 * 50 ??\????????£?????´??° n ?????\?????????0 ??? 9 ??????????????´??° a, b, c, d ????????§ a + b + c + d = n
	 * ??????????????????????????????????????°???????????????????????°?????????????????????????????????
	 * 
	 * @param args
	 * @throws IOException
	 * @throws NumberFormatException
	 */
	public static void main(String[] args) throws NumberFormatException,
			IOException {
		// TODO ?????????????????????????????????????????????

		Scanner sc = new Scanner(System.in);
		int inputNum, count;
		while (sc.hasNext()) {
			inputNum = sc.nextInt();
			count = 0;
			for (int i = 0; i <= 9; i++) {
				for (int j = 0; j <= 9; j++) {
					for (int k = 0; k <= 9; k++) {
						for (int l = 0; l <= 9; l++) {
							if (inputNum == i + j + k + l)
								count+= 1;
						}
					}
				}
			}
			System.out.println(count);
		}
	}

}

Measured memory_bytes: 18912
#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first setprecision

#if MYDEBUG
#include "lib/cp_debug.h"
#else
#define DBG(...) ;
#endif

using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL  MOD=1E9+7;

struct Problem{
    LL n,sum;
    vector<LL> a;
    Problem(LL n):n(n),a(n){};

    void solve(){
        sum=0;
        for(int i=0; i<n; ++i){
            cin >> a[i];
            sum+=a[i];
        }
        LL t=a[0],ans=abs(sum-2*t);
        for(int i=1; i<n-1; ++i){
            t+=a[i];
            ans=min(ans,abs(sum-2*t));
        }
        cout << ans <<"\n";

    }
};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    long long n=0;
    cin >> n;
    Problem p(n);
    p.solve();
    return 0;
}



Measured memory_bytes: 1792
from collections import deque

INF = 10101010

def main():
    h,w = map(int,input().split())
    s = []
    for i in range(h):
        s.append(input())

    ans = 0
    for i in range(h):
        ans += s[i].count('.')

    d = [[INF for j in range(w)] for i in range(h)]
    d[0][0] = 0
    que = deque()
    que.append((0,0))
    while que:
        y,x = que.pop()
        if (y,x) == (h-1,w-1):
            return ans - (d[h-1][w-1]+1)

        for dx,dy in [(1,0),(-1,0),(0,1),(0,-1)]:
            nx,ny = x+dx, y+dy
            if 0 <= nx < w and 0 <= ny < h:
                if s[ny][nx] != '#' and d[ny][nx]>d[y][x]+1:
                    d[ny][nx] = d[y][x]+1
                    que.appendleft((ny,nx))

    return -1

if __name__ == '__main__':
    print(main())


Measured memory_bytes: 3440
from bisect import bisect_left, bisect_right

N,K  = map(int, input().split())

X = list(map(int, input().split()))
Ne = bisect_left(X, 0)
Po = bisect_right(X, 0)

if Ne != Po:
  K -= 1

ans = 10**9

for i in range(K+1):
  tmp = 10**9
  if i > N - Po:
    continue
  if K - i > Ne:
    continue
  
  if i == 0:
    tmp = abs(X[Ne-K])
  
  elif i == K:
    tmp = abs(X[Po+K-1])
  
  else:
    tmp = X[Po+i-1] - X[Ne-(K-i)] + min(abs(X[Po+i-1]),abs(X[Ne-(K-i)])) 

  ans = min(ans,tmp)

print(ans) 

Measured memory_bytes: 62576
// Problem : F - Knapsack for All Subsets
// Contest : AtCoder - AtCoder Beginner Contest 169
// URL : https://atcoder.jp/contests/abc169/tasks/abc169_f
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

using namespace std;

int N, X;
long long dp[3005];
const long long MOD = 998244353;

long long add(long long a, long long b){
	return (a+b)%MOD;
}

int main(){
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> N >> X;
	dp[0] = 1;
	for(int i = 1; i<=N; i++){
		int n;
		cin >> n;
		for(int k = X; k>=0; k--){
			dp[k] = add(dp[k], dp[k]);
			if(k >= n){
				dp[k] = add(dp[k], dp[k-n]);
			}
		}
	}
	cout << dp[X] << "\n";
}

Measured memory_bytes: 3652
#include <iostream>
using namespace std;
typedef long long ll;
ll n, k, ans;
int main() {
	cin >> n >> k;
	if (k == 0)ans = n * n;
	else for (int i = k + 1; i <= n; i++)ans += n / i * (i - k) + (n - n / i * i >= k ? n - n / i * i - k + 1 : 0);
	cout << ans << endl;
	return 0;
}

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

int main(){
  int N; cin >> N;
  int A[100000];
  for(int i=0; i<N; i++) cin >> A[i];
  sort(A,A+N);
  int count=0;
  int prev=0;
  for(int i=0; i<N; i++){
    if(A[i]==prev){
      count--;
      prev=0;
    }else{
      count++;
      prev=A[i];
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
	int p,q,r;
	cin>>p>>q>>r;
	if(p<q){
		if(q<r){
			cout<<p+q;
		}else{
			cout<<p+r;
		}
	}else{
		if(p<r){
			cout<<p+q;
		}else{
			cout<<q+r;
		}
	}
	cout<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;
#define INF 0x7FFFFFFF
const double EPS = 1e-10;


inline bool eq(double a, double b) { return fabs(b - a) < EPS;}

struct p_t{
  double x;
  double y;
  double norm() { return x * x + y * y; }
  double abs() { return sqrt(norm()); }
};
struct l_t{
	p_t a, b;
};

double cross(p_t p,p_t q);
p_t line(p_t p,p_t q);

bool asc(p_t left,p_t right) {
    return left.x == right.x ? left.y < right.y : left.x < right.x;
}
int Crosspoint(l_t l,l_t m);

int main(){
  int n;
  cin>>n;
  for(int t=0;t<n;t++){
    p_t p,q,r,k,s;
    cin>>p.x>>p.y>>q.x>>q.y>>r.x>>r.y>>k.x>>k.y>>s.x>>s.y;
    l_t pq,qr,rp,ks;
    pq.a=p;
    pq.b=q;
    qr.a=q;
    qr.b=r;
    rp.a=r;
    rp.b=p;
    ks.a=k;
    ks.b=s;
    int ans=0;
    ans+=(Crosspoint(pq,ks)&&Crosspoint(ks,pq));
    ans+=(Crosspoint(qr,ks)&&Crosspoint(ks,qr));
    ans+=(Crosspoint(rp,ks)&&Crosspoint(ks,rp));
    if(ans==1){
      cout<<"OK"<<endl;
    }
    else{
      cout<<"NG"<<endl;
    }
  }
}


p_t line(p_t p,p_t q){
  p_t z;
  z.x=q.x-p.x;
  z.y=q.y-p.y;
  return z;
}


double cross(p_t p,p_t q){
  return p.x*q.y-p.y*q.x;
}

int Crosspoint(l_t l,l_t m){
  p_t aa,bb,cc,dd;
  aa.x=l.b.x-l.a.x;
  aa.y=l.b.y-l.a.y;
  bb.x=m.b.x-m.a.x;
  bb.y=m.b.y-m.a.y;
  cc=aa;
  dd.x=l.b.x-m.a.x;
  dd.y=l.b.y-m.a.y;
	double A = cross(aa,bb);
	double B = cross(cc,dd);
	//if (abs(A) < EPS && abs(B) < EPS) return 0;
  if(B/A>0&&B/A<1) return 1;
  return 0;
}



Measured memory_bytes: 3236
#include<bits/stdc++.h>
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using ii = pair<int, int>;

template<typename T>
T ext_gcd(T a, T b, T& x, T& y){
    if(b==0){
        x=1; y=0; return a;
    }
    else{
        T g = ext_gcd(b, a%b, y, x);
        y-=a/b*x; return g;
    }
}
template<typename T>
T mod_inv(T a, T m){
    T x, y;
    ext_gcd(a, m, x, y);
    return (x%m+m)%m;
}
template<typename T>
T mod_exp(T a, T b, T m){
    if(b == 0) return (T) 1;
    T c = mod_exp(a, b/2, m);
    c = (c*c)%m;
    if(b%2 != 0) c=(c*a)%m;
    return c;
}
#define MAXN 200010
ll fat[MAXN];
void preprocess_fat(ll m){
    fat[0] = 1;
    for(ll i=1; i<MAXN; ++i)
        fat[i]=(i*fat[i-1])%m;
}
ll mod = 998244353;

ll comb(ll a, ll b){
	ll res = ((fat[a]*mod_inv(fat[b], mod))%mod*mod_inv(fat[a-b], mod))%mod;
	return res;
}
int main(){
	preprocess_fat(mod);
	ll n, m, k;
	cin >> n >> m >> k;
	ll ans = 0;
	for(ll i=n-1-k; i<n; ++i){
		ll g = i+1;
		ll r1 = comb(n-1, i);
		ll r2 = (mod_exp(m-1, g-1, mod)*m)%mod;
		//cout << r1 << " " << r2 << endl;
		ans = (ans + (r1*r2)%mod)%mod;
	}
	cout << ans << endl;
}


Measured memory_bytes: 5196
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
  	double sum = 0.0;
    cin >> N;
    vector<double> S(N);
    for (int i = 0; i < N; i++) {
        cin >> S.at(i);
    }
    for (int i = 0; i < N; i++) {
        sum += 1 / S.at(i);
    }

    cout << 1 / sum  << endl;
}

Measured memory_bytes: 256
from collections import Counter
import sys
MOD = 998244353

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

c = Counter(D)
if c[0] != 1 or D[0] != 0:
    print(0)
    exit(0)
d = max(c)
ans = 1
for i in range(d):
    ans *= pow(c[i], c[i+1], MOD)
    ans = ans % MOD

print(ans)


Measured memory_bytes: 19936
import copy
n = int(input())
s = input()
slist = list(s)
# list
def search(slist, plist):
    s2 = copy.copy(slist)
    for k in plist:
        if k in s2:
            start = s2.index(k)+1
            s2 = s2[start:]
        else:
            return False
    return True

# print(search(slist, ["2","2","4"]))
count = 0
for i in range(1000):
    # 1000
    p = format(i, "03")
    plist = list(str(p))
    if search(slist, plist):
        count += 1
print(count)

Measured memory_bytes: 4344
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>
#include <cmath>
 
using namespace std;
int main(){
    int n;
    string s;
    int counter = 0;

    cin >> n >> s;
    for (size_t i = 0; i < n-2; i++)
    {
        string tmp = "";
        for (size_t j = i; j <= i+2; j++)
        {
            tmp += s[j];
        }
        
        if(tmp == "ABC") counter ++;
    }
    
    cout << counter << endl;
    
    
    
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.Math;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
	int n = sc.nextInt();
    int istack;
    int cnt = 0;
    int cnt2 = 0;
    int cnt3 = 0;
    int ef;
    boolean yon =true;
    
    for(int i = 0; i < n;i++) {
      istack = sc.nextInt();
      if(istack % 4 == 0) cnt++;
      else if(istack % 2 == 0) cnt2++;
      else cnt3++;
    }
   	if(cnt2 != 0)cnt3++;
    
    if(cnt+1 < cnt3) yon = false; 

    if(yon) System.out.println("Yes");
    else System.out.println("No");

  }
}


Measured memory_bytes: 58440
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e8;

signed main() {
	int A, B, C;
	cin >> A >> B >> C;
	if (A == B)cout << C;
	else if (A == C)cout << B;
	else cout << A;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <ctype.h>
#include <numeric>
#include <math.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

int dx4[4] = { 0, -1, 1, 0 };
int dy4[4] = { -1, 0, 0, 1 };
int dx8[8] = { 0, -1, 1, 0, -1, 1, -1, 1 };
int dy8[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };

int main() {
  int n; cin >> n;
  vector<int> h(n);
  for (int i = 0; i < n; ++i) cin >> h[i];
  int res = 1;
  for (int i = 1; i < n; ++i) {
    bool check = true;
    for (int k = 0; k < i; ++k) {
      if (h[k] > h[i]) {
        check = false;
        break;
      }
    }
    if (check) ++res;
  }

  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  int n, a2, a1, a0, cnt = 0;
  cin >> n >> a2 >> a1;

  for (int i = 2; i < n; i++) {
    cin >> a0;
    if ((a2 < a1 && a1 < a0) || (a0 < a1 && a1 < a2)) {
      cnt++;
    }
    a2 = a1; a1 = a0;
  }

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void)
{
  int a,b,c,d; cin>>a>>b>>c>>d;
  int sum1=a+b,sum2=c+d;
  
  if(sum1==sum2){puts("Balanced");}
  else if(sum1>sum2){puts("Left");}
  else{puts("Right");}
  
  return 0;
}

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

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

	int mask = 0;
	for (int i = 0; i < s.size(); ++i) {
		mask |= (1 << (s[i] - 'a'));
	}

	if (mask != (1 << 26) - 1) {
		for (int c = 0; c < 26; ++c) if (!(mask >> c & 1)) {
			cout << s << (char)(c + 'a') << endl;
			return 0;
		}
	} 

	for (int i = s.size() - 2; i >= -1; --i) {
		vector <int> vec;
		for (int j = i + 1; j < s.size(); ++j) vec.push_back(s[j] - 'a');

		bool decreasing = true;
		for (int j = 1; j < vec.size(); ++j) {
			decreasing &= (vec[j] < vec[j - 1]);
		}

		if (decreasing) continue;
		
		vector <int> nw = vec;
		next_permutation(nw.begin(), nw.end());

		cout << s.substr(0, i + 1);
		for (int j = 0; j < nw.size(); ++j) {
			if (nw[j] == vec[j]) cout << (char)(nw[j] + 'a');
			else {
				cout << (char)(nw[j] + 'a');
				break;
			}
		}
		cout << endl;
		return 0;
	}

	cout << -1 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a;
	float b,c,d;
	while(scanf("%d,%f,%f",&a,&c,&d)!=EOF){
		b=c/d/d;
		if(b>=25){
			printf("%d\n",a);
		}
	}
	return 0;
}

Measured memory_bytes: 624
#include <stdio.h>

#define MAX 50022

int main(){
  int i, j, n, prime[MAX] = {};
  prime[0] = prime[1] = 1;
  for(i = 2;i < MAX;i++){
    if(prime[i] != 1){
      for(j = i * 2;j < MAX;j += i){
	prime[j] = 1;
      }
    }
  }
  while(scanf("%d", &n) != EOF){
    for(i = n - 1;i > 0;i--)
      if(prime[i] != 1) printf("%d ", i), i = 0;
    for(i = n + 1;i < MAX;i++)
      if(prime[i] != 1)	printf("%d\n", i), i = MAX;
  }
  return 0;
}

Measured memory_bytes: 800
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

//--------------------------------------------

int n,m,x,y;
vpi mov;
int ball[100010], contami[100010];

signed main(){
    I(n); I(m);
    REP(i,m){
        I(x); I(y);
        mov.eb(x-1,y-1);
    }
    contami[0] = 1;
    for(auto pm: mov) {
        ball[pm.first]--;
        ball[pm.second]++;
        contami[pm.second] |= contami[pm.first];
        if (ball[pm.first] == -1) contami[pm.first] = 0;
    }
    int ret = 0;
    REP(i,n) ret += contami[i];
    cout << ret << endl;
}

Measured memory_bytes: 3440
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
inline void add(int &v, int k) {
  v += k;
  if (v >= MOD) v -= MOD;
}


int N, M;
int dp[2][301][301];
vector<P> G[301];

bool ok(int r, int a, int b) {
  for (P p : G[r]) {
    int l = p._1, x = p._2;
    if (1+(a>=l)+(b>=l) != x) return false;
  }
  return true;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> M;
  rep(i, M) {
    int l, r, x;
    cin >> l >> r >> x;
    G[r].pb(P(l, x));
  }
  dp[0][0][0] = 1;
  for (int i=1; i<=N; i++) {
    rep(j, N) rep(k, N) dp[1][j][k] = 0;
    rep(a, N) {
      rep(b, N) {
        int c = i-1;
        // (a, b, c) - i
        if (ok(i, a, b)) add(dp[1][a][b], dp[0][a][b]);
        if (ok(i, a, c)) add(dp[1][a][c], dp[0][a][b]);
        if (ok(i, b, c)) add(dp[1][b][c], dp[0][a][b]);
      }
    }
    swap(dp[0], dp[1]);
  }
  int s = 0;
  rep(a, N) rep(b, N) add(s, dp[0][a][b]);
  cout << s << "\n";
  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
#include<deque>
#include <iomanip>
#include<utility>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
#define S 21 
llfor;ll mod=1000000007;
/*pi*/double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll ans=1;rep(i,0,n){ans*=x;ans%=mod;}return ans;}
/*階乗*/ll fact(ll x){ll ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)*fact(n-r)/fact(r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=1,tmp=n;while(tmp/10>0){tmp/=10;d++;}return d;}
/*行列のコピー*/void matcpy(ll a[S][S],ll b[S][S]){ll t=i;rep(i,0,S)rep(j,0,S)b[i][j]=a[i][j];/*(aをbに)*/i=t;}
/*行列のリセット*/void matrst(ll a[S][S]){ll t=i;rep(i,0,S)rep(j,0,S)a[i][j]=0;i=t;}
/*行列の2乗*/void matpow(ll a[S][S]){ll ans[S][S];matrst(ans);ll t=i,k;rep(i,0,S)rep(j,0,S)rep(k,0,S)ans[i][j]+=a[i][k]*a[k][j];matcpy(ans,a);i=t;}
/*行列の乗算*/void matmul(ll a[S][S],ll b[S][S], ll as[S][S]){ll t=i,k;matrst(as);rep(i,0,S)rep(j,0,S)rep(k,0,S)as[i][j]+=a[i][k]*b[k][j];i=t;}
//ll ans=0;
////////////////////////////////////////////////////////////
int main(){
 ll n,m;
 cin>>n>>m;
 ll c[20][20],mn[20]={2000};
 rep(i,0,10){
  rep(j,0,10){
   cin>>c[i][j];
   if(j==1)mn[i]=c[i][j];
  }
 }
 bool flag=true;
 while(flag){
  flag=false;
  rep(i,0,10){
   rep(j,0,10){ 
    ll bef=mn[i];
    if(i!=j)mn[i]=min(mn[i],c[i][j]+mn[j]);
    //cout<<i<<" "<<mn[i]<<" "<<c[i][j]<<" "<<c[i][1]<<endl;
    if(bef!=mn[i])flag=true;
   }
  }
 }
 ll ans=0,a;
 rep(i,0,n){
  rep(j,0,m){
   cin>>a;
   if(a==-1)continue;
   ans+=mn[a];
  }
 }
 pr(ans);
return 0;}

Measured memory_bytes: 3612
numbers = list(map(int,input().split()))
numbers.sort()

#print(numbers)
ans = 0
M = max(numbers)
if 3*M%2 == sum(numbers)%2:
    #print(numbers,M)
    ans += (M-numbers[0])
    ans += (M-numbers[1])
    ans += (M-numbers[2])


else:
    #print(numbers,M+1)
    ans += (M+1-numbers[0])
    ans += (M+1-numbers[1])
    ans += (M+1-numbers[2])

print(ans//2)


Measured memory_bytes: 3060
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	var str string
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%s", &str)

	strs := strings.Split(str, "/")

	d := strings.Join(strs, "")
	date, _ := strconv.Atoi(d)

	if date <= 20190430 {
		fmt.Println("Heisei")
	} else {
		fmt.Println("TBD")
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int a,b;
int cnt,cur=1;
int main()
{
    ios_base::sync_with_stdio(false);
    cin>>a>>b;
    while(cur<b)
    {
        cur=cur-1+a;
        ++cnt;
    }
    cout<<cnt;
    return 0;
}


Measured memory_bytes: 256