akhauriyash/Code-Regression huggingface dataset:
import math
n = int(input())
ans = []
tmp = n
cnt = 1
r = 0
for i in range(1, 11):
  tmp -= pow(26, i)
  if tmp <= 0:
    break
  cnt += 1
  r += pow(26, i)
idx = n - r
now = 0
while(cnt!=1):
  cnt -= 1
  j = 1
  while(1):
    now += pow(26, cnt)
    if idx <= now:
      now -= pow(26, cnt)
      ans.append(j)
      break
    else:
      j += 1
k = 0
while(1):
  if now+k==idx-1:
    ans.append(k+1)
    break
  else:
    k += 1
anstr = ''
for e in ans:
  anstr += chr(e+96)
print(anstr)

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


string s;
int main()
{
    cin>>s;
    int sum=0;
    for(int i=0;i<s.size();i++)
    {
        sum+=int(s[i])-48;
        if(sum>=9) sum%=9;
    }
    if(!sum) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 3736
// ぱっと見むずいがにぶたんの臭いがする
// 一瞬誤読して実際に作ったやつ省くんかと思ったが種類だけを聞いているんだった
// TLEになりやがったのでbufioを使う
package main

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

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

func main() {
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush()
	N := nextInt()
	A, B, C := nextInts(N), nextInts(N), nextInts(N)
	sort.Sort(sort.Reverse(sort.IntSlice(A)))
	sort.Ints(B)
	sort.Ints(C)
	ans := 0
	for i := 0; i < N; i++ {
		// ascendingのときreverseしなきゃいけないのか....
		left := sort.Search(N, func(j int) bool {
			return A[j] < B[i]
		})
		right := sort.Search(N, func(j int) bool {
			return C[j] > B[i]
		})
		if left == N || right == N {
			// golangのバイナリサーチで見つからないとき下でも上でもこれになるらしい
			continue
		}
		ans += (N - left) * (N - right)
	}
	fmt.Fprintln(out, ans)
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}


Measured memory_bytes: 6656
N=gets.chomp.to_i
A=gets.chomp.split.map(&:to_i)
B=gets.chomp.split.map(&:to_i)
C=gets.chomp.split.map(&:to_i)
ans=0
A.each_with_index do |e,i|
	if i==0
		next
	end
	if A[i]-A[i-1] == 1
		ans+=C[A[i-1]-1]
	end
end
puts ans+B.inject(:+)

Measured memory_bytes: 1788
///                                                     ببِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم
#include <bits/stdc++.h>
#define off  exit( 0 )
#define cn   continue
#define rt   return
#define sc   scanf
#define pr   printf
#define pb   push_back
#define pf   push_front
#define p_f  pop_front
#define p_b  pop_back
#define ff   first
#define ss   second
#define vec  vector
#define gcd  __gcd
#define pi   acos( -1 )
#define ll   long long
#define ld   long double
#define N    300256
#define M    1000000007
#define I    1000000000000000000
#define pdd  pair < ld, ld >
#define pll  pair < ll, ll >
#define pii  pair < int, int >
#define rep( a, b, c, d )  for( int a = b; a <= c; a += d )
#define rvv( a, b, c, d )  for( int a = b; a >= c; a -= d )
#define en                 printf( "\n" )
#define sqr( a )           a * a
#define all( c )           c.begin(), c.end()
#define srt( c )           sort( all( c ) )
#define rev( c )           reverse( all( c ) )
#define srtr( c )          sort( c.rbegin(), c.rend() )
#define numcounts          __builtin_popcount
#define mxn( x, y, z )     max( x, min( y, z ) )
#define mnx( x, y, z )     min( x, max( y, z ) )
const int dx[ ] = { 1, -1, 0, 0 };
const int dy[ ] = { 0, 0, -1, 1 };
using namespace std;
ll ttt = 1;
int n, k, a[N], dp[N];
void solve()
{
    cin >> n >> k;
    for( int i = 0; i < n; i ++ )
        cin >> a[i];
    for( int i = 1; i < n; i ++ )
    {
        dp[i] = M;
        for( int j = 1; j <= k && i - j >= 0; j ++ )
            dp[i] = min( dp[i - j] + abs( a[i] - a[i - j] ), dp[i] );
    }
    cout << dp[n - 1];
}
int main()
{
    //sc( "%I64d", &ttt );
    for( int i = 0; i < ttt; i ++ )
        solve();
}














Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int     long long
#define F       first
#define S       second
#define _READ   freopen("input.txt","r", stdin);
#define _FAST   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
void solve()
{
    int n;
    cin>>n;
    if(n%10==3)
        cout<<"bon";
    else if(n%10==0 ||n%10==1||n%10==6||n%10==8)
        cout<<"pon";
    else
        cout<<"hon";
}
int32_t main()
{
    clock_t tStart = clock();
    #ifndef ONLINE_JUDGE
    _READ
    #endif
    
    int t;
    t=1;
    while(t--)
        solve();
    
    #ifndef ONLINE_JUDGE
    cout<<fixed<<setprecision(5)<<"\nTime taken: "<<(double)(clock() - tStart)/CLOCKS_PER_SEC;
    #endif
    
    return 0;
}
/*
===FOR N-Dimensional Vector===
https://codeforces.com/blog/entry/76149
g++ -std=c++17 -Wshadow -Wall -g -fsanitize=address -fsanitize=undefined a.cpp -o a -D_GLIBCXX_DEBUG
*/

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define max(x, y) ((x) > (y) ? (x) : (y))
#define min(x, y) ((x) < (y) ? (x) : (y))
#define rep(i,a,m) for((i) = (a) ; (i) < (m) ; ++(i))
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rall(x) x.end(),x.begin()
#define sz(x) ((int)x.size())
using namespace std;
/*
#ifdef JUDGE
#include <fstream>
std::ifstream cin("input.txt");
std::ofstream cout("output.txt");
#else
#include <iostream>
using std::cin;
using std::cout;
#endif
*/
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pi;
int a, b, c, i, j, k;
long long ans = 0LL;
long double eps = 1.0E-14;
long long MOD = 1000000007;
int main ()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll t,T;
	cin >> T;	
    long long sum = (T*(T+1))/2;
    ll t3 = T/3, t5 = T/5, t15 = T/15;
    sum -= 3LL*((t3*(t3+1))/2);
    sum -= 5LL*((t5*(t5+1))/2);
    sum += 15LL*((t15*(t15+1))/2);
    cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3636
n = int(input())
c = input()
r_cnt = c.count('R')
w_cnt = c.count('W')
new_c = 'R' * r_cnt + 'W' * w_cnt
cnt = 0
for i in range(n):
    if c[i] != new_c[i]:
        cnt += 1
    else:
        pass
if cnt >= 2:
    ans = cnt //2
elif cnt == 1:
    ans = 1
elif cnt == 0:
    ans = 0
print(ans)

Measured memory_bytes: 9500
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

int main(){
	int N;
	string in;
	scanf("%d",&N);
//	char in[1000];
//	scanf("%s",in);

	cin >> in;

	for(int i=0;i<in.size();i++){
		if(in[i]+N>'Z'){
			in[i] = (N-('Z'-in[i]+1)) + 'A';
		}else{
			in[i] = in[i] + N;
		}
	}

	cout << in;

//	printf("%s",in);
	return 0;
}

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

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end());
#define REPIT(x) for(auto it=(x).begin(), end=(x).end(); it!=end; ++it)
#define perm(c) sort(all(c)); for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
  cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
	cout << a;
	if (&a != &vec.back()) cout << " ";
  }
  cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
	print(vec);
  }
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

signed solve()
{
	int a, b;
	cin >> a >> b;
	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)
		print("Possible");
	else
		print("Impossible");
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
int arr[101];
using namespace std;
int main(void)
{
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> arr[i];
	bool item = true;
	for (int j = n - 1; j >= 0; --j)
	{
		if (item)
			cout << arr[j];
		else
			cout << " " << arr[j];
		item = false;
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3104
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
//	freopen("product.in","r",stdin);
//	freopen("product.out","w",stdout);
 	int a,b;
 	cin>>a>>b;
 	if (a%2&&b%2) cout<<"Odd"<<endl;
 	else cout<<"Even"<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  string T;
  cin>>S;
  cin>>T;
  if(T==S+'a'||T==S+'b'||T==S+'c'||T==S+'d'||T==S+'e'||T==S+'f'||T==S+'g'||T==S+'h'||T==S+'i'||T==S+'j'||T==S+'k'||T==S+'l'||T==S+'m'||T==S+'n'||T==S+'o'||T==S+'p'||T==S+'q'||T==S+'r'||T==S+'s'||T==S+'t'||T==S+'u'||T==S+'v'||T==S+'w'||T==S+'x'||T==S+'y'||T==S+'z'){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}



Measured memory_bytes: 3636
require 'prime'
#require 'openssl'
MOD=10**9+7;  cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def ar2(s1,s2,de=nil) Array.new(s1){Array.new(s2,de)} end
def ar3(s1,s2,s3,de=nil) Array.new(s1){Array.new(s2){Array.new(s3,de)}} end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+).to_i end
def ceil(a,b) (a.to_f/b).ceil end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def pu(h) begin; require './../nemi_lib/debug.rb'; puts_val(h); rescue LoadError; end; end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n=gi

pr=n.prime_division
total=0
pr.each do |base, nn|
  cnt=0
  c1=1
  while true
    nn-=c1
    if nn>=0
      cnt+=1
    else
      break
    end
    c1+=1
  end
  total+=cnt
end
puts total

Measured memory_bytes: 14460
import math

n, k = map(int, input().split(" "))
aL = list(map(int, input().split(" ")))

ans = 0

for i in range(1, n - k + 1):
    j = i + k - 1
    if aL[i - 1] < aL[j]:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 33036
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    ll A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    // X <= Yを仮定する
    if(X>Y){
        swap(X, Y);
        swap(A, B);
    }

    // 全部ABピザ
    ll price0 = max(X, Y) * C * 2;

    // 全部単品
    ll price1 = A * X + B * Y;

    // はみでた分を単品
    ll diff = Y - X;
    ll price2 = diff * B + X * 2 * C;

    ll price = min(price0, price1);
    price = min(price, price2);
    p(price);
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0; i<(n); i++)
const int MX = 100005;
const int MOD = 998244353;
int n, d, m;
long long ans = 1, a[MX];
ll exp(ll b, ll n){
	ll res = 1;
	for(; n; n/=2,(b*=b)%=MOD) if(n%2) (res *= b) %= MOD;
	return res;
}
int main(){
	scanf("%d", &n);
	rep(i,n){
		scanf("%d", &d);
		a[d]++;
		m = max(m,d);
		if(d == 0 && i) ans = 0;
	}
	rep(i,m) ans = ans * exp(a[i],a[i+1]) % MOD;
	printf("%lld\n", ans);
}

Measured memory_bytes: 1024
import math
import sys
from collections import deque
import copy
import itertools
from itertools import permutations
def mi() : return map(int,sys.stdin.readline().split())
def ii() : return int(sys.stdin.readline().rstrip())
a,b=mi()
l=[list(mi()) for _ in range(b)]
l=sorted(l,key=lambda x:x[1])
q=deque([1,1])
ans=0
for i,j in l:
  y=q.pop()
  x=q.pop()
  if i<x:
    q.append(x)
    q.append(y)
  else:
    ans+=1
    q.append(j)
    q.append(j)
print(ans)


Measured memory_bytes: 30384
#include<cstdio>
#include<algorithm>
using namespace std;
int a[100001];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]); 
	}
	sort(a+1,a+1+n);
	int sum=1,ans=0;
	for(int i=2;i<=n;i++){
		if(a[i]==a[i-1]){
			sum^=1;
		}else{
			ans+=sum;
			sum=1;
		}
	}
	if(sum%2){
		ans++;
	}
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;

int main()
{
	int k;
	cin >> k;
	int n = (k+3)/4*2;
	if(k == 1) n = 1;
	printf("%d\n", n);
	for(int i=0; i<n; i++)
	{
		for(int j=0; j<n; j++)
		{
			int c = (!(i&1)) ? (j-i+n)%n : n+(j-i+n)%n;
			if(c >= k) c -= n;
			printf("%d ", c+1);
		}
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 1152
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
if a[-1]==0:
    print(0)
    exit()
ans=a[0]
for i in range(len(a)-1):
    ans*=a[i+1]
    if ans>1000000000000000000:
        ans=-1
        break
print(ans)

Measured memory_bytes: 21660
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	aStr, _ := reader.ReadString('\n')
	reader.ReadString('\n')
	reader.ReadString('\n')
	reader.ReadString('\n')
	eStr, _ := reader.ReadString('\n')
	kStr, _ := reader.ReadString('\n')
	aStr = strings.Trim(aStr, "\n")
	eStr = strings.Trim(eStr, "\n")
	kStr = strings.Trim(kStr, "\n")

	a, err := strconv.Atoi(aStr)
	if err != nil {
		log.Fatalln(err)
	}
	e, err := strconv.Atoi(eStr)
	if err != nil {
		log.Fatalln(err)
	}
	k, err := strconv.Atoi(kStr)
	if err != nil {
		log.Fatalln(err)
	}

	if e-a > k {
		fmt.Println(":(")
	} else {
		fmt.Println("Yay!")
	}
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
string s;
int a, b;
int main() {
	cin >> s;
	for (int i=0; i<s.size(); i++) {
		if (s[i]=='A') a++;
		if (s[i]=='B') b++;
	}
	if (a>0 && b>0) cout << "Yes" << "\n";
	else cout << "No" << "\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using ll = long long ;
ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    int max_num = 0;
    rep(i,n) {
        cin >> h[i];
        max_num = max(max_num,h[i]);
    }
    int ans = 0;
    for(int i=max_num;i>=1;i--){
        vector<int> vec(n);
        rep(j,n) {
            if (h[j]>=i) vec[j]= 1;
            else vec[j] = 0;
        }
        bool ok = false;
        rep(j,n) {
            if (vec[j]==0) {
                ok = false;
            }else{
                if (ok) continue;
                else {
                    ans += 1;
                    ok = true;
                }
            }
        }
    }
     cout << ans << endl;

    
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    public static void main (String[] args) {
        MyScanner sc = new MyScanner();

        char[] s = sc.next().toCharArray();

        boolean isAns = true;
        for (int i = 0; i < s.length; i++) {
            if (s[i] == 'R' && i % 2 == 1) {
                isAns = false;
                break;
            } else if (s[i] == 'L' && i % 2 == 0) {
                isAns = false;
                break;
            }
        }

        System.out.println(isAns ? "Yes" : "No");
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

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

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

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

string suji(int a){
    string c(5,'1');
    c = to_string(a);
    return c;
}


int main() {
    int a = 0;
    int b = 0;
    int ans = 0;
    string s;

    cin >> a >> b;
    for (int i = a; i <= b; ++i) {
        s = suji(i);

        if (s[0] == s[4] && s[1] == s[3]){
            ans++;
        }
    }

    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll arr[1<<18],h[1<<18],b[1<<18],segTree[3*1<<18];
/*
0 0 0 0
0 20 0 0
0 20 0 60
10 20 0 60
10 20 50 60
*/

ll query(int segIdx,int segLeft,int segRight,int left,int right){
    if(segLeft>=left && segRight<=right){
        return segTree[segIdx];
    }
    
    if(segLeft>right || segRight<left){
        return -1e18;
    }
    int segMid=(segLeft+segRight)/2;
    return max(query(segIdx*2,segLeft,segMid,left,right) , query(segIdx*2+1,segMid+1,segRight,left,right));
}

void update(int segIdx,int segLeft,int segRight,int idx,ll value){
    if(segLeft==idx && segRight==idx){
        segTree[segIdx]=value;
        return;
    }
    
    if(segLeft>idx || segRight<idx) return;
    
    int segMid=(segLeft+segRight)/2;
    update(segIdx*2,segLeft,segMid,idx,value);
    update(segIdx*2+1,segMid+1,segRight,idx,value);
    segTree[segIdx]=max(segTree[segIdx*2],segTree[segIdx*2+1]);
}
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>h[i];
        arr[h[i]]=i;
    }
    
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    ll ans=0;
    for(int i=1;i<=n;i++){
        ll q=query(1,0,n-1,0,arr[i])+b[arr[i]];
        ans=max(ans,q);
        //cout<<arr[i]<<" "<<q<<endl;
        update(1,0,n-1,arr[i],q);
    }
    
    cout<<ans<<endl;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n; cin >> n;
  for(int i = 1; i <= 10; ++i) {
    if(1000*i >= n) {
      cout << 1000*i - n << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3616
# https://qiita.com/snow67675476/items/e87ddb9285e27ea555f8

def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0:
        cnt+=1
        temp //= i
      arr.append([i, cnt])

  if temp!=1:
    arr.append([temp, 1])

  if arr==[]:
    arr.append([n, 1])

  return arr

def resolve():
  N = int(input())
  prime_factors = factorization(N)
  result = 0

  for prime_factor in prime_factors:
    if prime_factor[0] == 1:
      continue

    for count in range(2, 42):
      if prime_factor[1] < (count + 1)*count//2:
        result += count - 1
        break
  print(result)

if __name__ == "__main__":
  resolve()


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


int main() {
    long long int n;
    cin>>n;
    long long int a[n], b[n];
    for (long long int i = 0; i < n; i++) {
      cin >> a[i] >> b[i];
    }
    long long int prec = 0;
    long long int ans = 0;
    for (long long int i = n - 1; i >= 0; i--) {
      a[i] += prec;
      if (a[i] % b[i] != 0) {
        prec += b[i] - (a[i] % b[i]);
        ans += b[i] - (a[i] % b[i]);
      }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
ll n;


 
int main(void){
    cin>>n;
    ll ans = 0;
    for(ll i=1;i<=9;i++){
        for(ll j=i;j<=9;j++){
            if(i==j){
                if(i>n)break;
                ll num = 0;
                num++;
                for(ll k=0;k<=4;k++){
                    if(k==0){
                        ll now =10*i+j;
                        if(now<=n)num++;
                        else break;
                    }
                    else{
                        ll now =pow(10,1+k)*i+j;
                        ll end =pow(10,k);
                        for(ll d=0;d<end;d++){
                            ll x = now+d*10;
                            if(x<=n)num++;
                            else break;
                        }
                    }
                }
                ans+=num*num;
            }
            else{
                ll num1=0;
                ll num2=0;
                for(ll k=0;k<=4;k++){
                    if(k==0){
                        ll now =10*i+j;
                        if(now<=n)num1++;
                        else break;
                    }
                    else{
                        ll now =pow(10,1+k)*i+j;
                        ll end =pow(10,k);
                        for(ll d=0;d<end;d++){
                            ll x = now+d*10;
                            if(x<=n)num1++;
                            else break;
                        }
                    }
                }
                for(ll k=0;k<=4;k++){
                    if(k==0){
                        ll now =10*j+i;
                        if(now<=n)num2++;
                        else break;
                    }
                    else{
                        ll now =pow(10,1+k)*j+i;
                        ll end =pow(10,k);
                        for(ll d=0;d<end;d++){
                            ll x = now+d*10;
                            if(x<=n)num2++;
                            else break;
                        }
                    }
                }
                ans +=num1*num2*2;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
N,X=map(int,input().strip().split())
x=list(map(int,input().strip().split()))
x.append(X)
x.sort()
    
d=[]
for n in range(1,N+1):
    d.append(x[n]-x[n-1])
    
def gcd(a,b):
    x=max(a,b)
    y=min(a,b)
    tmp=x%y
    if tmp==0:
        return y
    else:
        return gcd(y,tmp)
    
if len(d)<=1:
    print(d[0])
else:
    D=d[0]
    for i in range(1,len(d)):
        D=gcd(D,d[i])
    print(D)

Measured memory_bytes: 19964
#!/usr/bin/env python
# coding: utf-8

# In[1]:


import sys
input = sys.stdin.readline
N, M = map(int, input().split())
A = list(map(int, input().split()))
bcs = [list(map(int, input().split())) for i in range(M)]


# In[14]:


"""
def binary_search(nbs, tar):
    #print(nbs, tar)
    ln = 0
    rn = len(nbs)-1
    t = int(len(nbs)/2)
    
    while ln < rn:
        comp = nbs[t]
        if tar >= comp and tar<nbs[t+1]:
            break
        elif tar >= comp: # 今の値がtar以下であれば、
            ln = t + 1 # 左端をt+1に更新
        elif tar < comp: # 今の値がtarより大きければ、
            rn = t - 1 # 右端をt-1に更新
        t = int((ln+rn)/2)
    return t
"""


# In[16]:


sbcs = sorted(bcs, key=lambda x:x[1], reverse=True)
sA = sorted(A)

nb = 0
ans = 0
is_finish = False

for i in range(M):
    B, C = sbcs[i]
    
    for j in range(B):
        if nb < N and sA[nb] < C:
            ans += C
            nb += 1
        else:
            is_finish = True
            break
    
    if is_finish:
        break

if nb < N:
    ans += sum(sA[nb:])

print(ans)
        
"""
    if nb >= N: # nbがN以上になれば、終了
        break
    
    B, C = sbcs[i]
    las = nb+B-1
    las = las if las <N else N-1
    if sA[nb] >= C: # もしnb個目がC以上であれば、終了
        break
    elif sA[nb+B-1] <= C: #もしB個目が、C以下なら、B個目までをCにする
        sA[nb:nb+B] = [C]*B
        nb += B
    else: #nb個目がC未満で、nb+B-1個目がCより大きければ
        t = binary_search(sA[nb:nb+B], C) 
        t = t if nb+t < N else N-nb-1
        sA[nb:nb+t+1] = [C]*(t+1)
        nb += t+1
    
print(sum(sA))
"""


# In[ ]:






Measured memory_bytes: 34712
#include<bits/stdc++.h>
using namespace std;
int keta(int x){
  for(int i=1;i<11;i++){
    if(x==0||x==1){
      return 1;
    }

    if(x!=0&&x!=1){
    if(x%int(pow(10,i))==x){
return i;
      break;
    }
  }
}

}

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

  for(long long int i=1;i<=N;i++){
    if(keta(i)%2==1){
      ans++;
    }
  }
  
  cout<<ans<<endl;
}
   

Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <queue>
#include <iomanip>
#include <cfloat>
using namespace std;
typedef pair<double, int> P;

int xs, ys, xt, yt;
int N;
int x[1000], y[1000], r[1000];
struct edge {int to; double cost;};
vector<edge> G[1002];
double d[1002];

void dijkstra(int s){
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d, d+N+2, DBL_MAX);
    d[s] = 0.0;
    que.push(P(0.0, s));
    while(!que.empty()){
        P p = que.top(); que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        for(int i=0; i<G[v].size(); i++){
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

double getCost(int x1, int y1, int r1, int x2, int y2, int r2){
    double temp = sqrt(pow(x1-x2, 2.0) + pow(y1-y2, 2.0));
    return max(0.0, temp - r1 - r2);
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    cin >> xs >> ys >> xt >> yt;
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> x[i] >> y[i] >> r[i];
    }
    for(int i=0; i<N; i++){
        double c = getCost(xs, ys, 0.0, x[i], y[i], r[i]);
        G[0].push_back(edge{i+1, c});
        G[i+1].push_back(edge{0, c});
        c = getCost(xt, yt, 0.0, x[i], y[i], r[i]);
        G[N+1].push_back(edge{i+1, c});
        G[i+1].push_back(edge{N+1, c});
    }
    double c = getCost(xs, ys, 0.0, xt, yt, 0.0);
    G[0].push_back(edge({N+1, c}));
    G[N+1].push_back(edge({0, c}));
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            double c = getCost(x[i], y[i], r[i], x[j], y[j], r[j]);
            G[i+1].push_back(edge{j+1, c});
            G[j+1].push_back(edge{i+1, c});
        }
    }
    dijkstra(0);
    cout << setprecision(32) << d[N+1] << endl;


	return 0;
}


Measured memory_bytes: 36848
#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() {
  int N,A,B;
  cin>>N>>A>>B;
  if(A*N<B){
    cout<<A*N<<endl;
  }
  else{
    cout<<B<<endl;
  }
}

Measured memory_bytes: 256
r,c = list(map(int,input().split()))
matrix = []
for i in range(r):
	matrix.append(list(map(int,input().split())))
	matrix[i].append(sum(matrix[i]))
add_list = []
for j in range(c+1):
	num = 0
	for k in range(r):
		num += matrix[k][j]
	add_list.append(num)
matrix.append(add_list)

for i in range(r+1):
	out = ''
	for m in matrix[i]:
		out += str(m) + ' '
	print(out[:-1])

Measured memory_bytes: 7716
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n, m = map(int, input().split())

MOD = 10 ** 9 + 7
factorial = [0] * (10 ** 6 + 1)
inverse = [0] * (10 ** 6 + 1)
factorial[0] = inverse[0] = 1
for i in range(1, 10 ** 6 + 1):
    factorial[i] = (factorial[i-1] * i) % MOD
    inverse[i] = pow(factorial[i], MOD-2, MOD)

prime_factors = []
total = 0
i = 2
while i ** 2 <= m:
    ext = 0
    while m % i == 0:
        ext += 1
        m //= i
    if ext:
        prime_factors.append((i, ext))
        total += ext
    i += 1
if m != 1:
    prime_factors.append((m, 1))
    total += 1

ans = 1
for pf, num in prime_factors:
    ans = (ans * (factorial[num + (n-1)] * inverse[num] * inverse[n-1])) % MOD
print(ans)


Measured memory_bytes: 82036
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,num;
ll ans;
map<int,int> ma,mb;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&num);
		ma[i-num]++,mb[i+num]++;
	}
	for(map<int,int>::iterator it=ma.begin();it!=ma.end();it++)
	{
		pair<int,int> pi=*it;
		int a=pi.first,b=pi.second;
		ans+=ll(b)*ll(mb[a]);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 29336
#include <iostream>//約数だけ考えればよいですね。O(sqrt(n))で解けます。
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <complex>
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;
vector<ll> enumDivisor(ll n) {
	vector<ll> a;
	for (ll i = 1; i * i <= n; i++) {
		if (n % i != 0)continue;
		a.push_back(i);
		if (i * i != n)a.push_back(n / i);
	}
	
	return a;
}
int main() {
	ll n,ans=0;
	cin >> n;
	for (ll x : enumDivisor(n)) {
		if (x == 1)continue;
		ll tmp = n;
		while (tmp % x == 0)tmp /= x;
		tmp %= x;
		if (tmp == 1)ans++;
	}
	ans += enumDivisor(n - 1).size()-1;
	cout << ans;
	return 0;
}

Measured memory_bytes: 384
n = int(input())
s = input()

ans = ''
for char in s:
    over_cnt = (ord(char) + n) - ord('Z')
    if(over_cnt > 0):
        ans += chr(((ord('A') - 1 )+ over_cnt))
    else:
        ans += chr(ord(char)+n)
    over_cnt = -1

print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>

using namespace std;

#define DEBUG (1)
#define LOOP_MAX (1000000009)

int main()
{
  long long N,K,ans = 0;
  
  cin >> N >> K;
  
  for(int i =1; i < LOOP_MAX;i++){
    if(N < pow((double)K,(double)i)){
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}

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

def main():
    A, B = [int(x) for x in input().split()]
    a = [0] * 45
    if A == B:
        print(A)
        exit()
    for i in range(0, 44):
        x = (B // (2 ** i)) // 2 * (2 ** i)
        if (B // (2 ** i)) & 1:
            x += B % (2 ** i) + 1
        y = ((A - 1) // (2 ** i)) // 2 * (2 ** i)
        if ((A - 1) // (2 ** i)) & 1:
            y += (A - 1) % (2 ** i) + 1
        a[i] = x - y

    ans = 0
    for i, v in enumerate(a):
        if v & 1:
            ans += 2 ** i

    print(ans)

    
    

if __name__ == '__main__':
    main()



Measured memory_bytes: 3064
def make(i):
    if int(i) > 3234566667:  return
    lun.append(int(i))
    if int(i[-1]) - 1 >= 0:  make(i + str(int(i[-1]) - 1))
    make(i + i[-1])
    if int(i[-1]) + 1 <= 9:  make(i + str(int(i[-1]) + 1))

lun = []
for i in range(1, 10):  make(str(i))
lun = sorted(lun)
print(lun[int(input()) - 1])

Measured memory_bytes: 82604
n = gets.to_i
a = readline.split.map(&:to_i)
b = readline.split.map(&:to_i)
c = a.zip(b).map { |a, b| a - b }.map(&:abs)

def distance(c, q)
  d = c.inject(0.0) do |sum, v|
    sum += (v ** q).abs
  end

  case q
  when 1
    d
  when 2
    Math.sqrt(d)
  when 3
    Math.cbrt(d)
  end
end
puts distance(c, 1)
puts distance(c, 2)
puts distance(c, 3)
puts c.max

Measured memory_bytes: 6160
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef unsigned long long ll;

ll N, n, M, K;

int main(){
    cin >> N >> M;
    int left = 1, right = N;
    REP(i, M){
        int L, R;
        cin >> L >>R;
        left= max(left, L);
        right = min(right, R);
    }
    cout << max(0,(right-left) + 1) << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll inf = 1e14;

class min_cost_flow{
private:
    int N;
    struct edge{int to; ll cap,cost; int rev;};
    vector<vector<edge>> G;
    vector<ll> h,dist,prevv,preve;
public:
    min_cost_flow(int n){
        N = n;
        G = vector<vector<edge>>(N);
        h = dist = prevv = preve = vector<ll>(N,0);
    }
    void add_edge(int from,int to,ll cap,ll cost){
        G[from].push_back((edge){to,cap,cost,(int) G[to].size()});
        G[to].push_back((edge){from,0,-cost,(int) G[from].size()-1});
    }
    ll answer(int s,int t,ll f){
        ll res = 0;
        fill(h.begin(),h.end(),0);
        while(f>0){
            priority_queue<P,vector<P>,greater<P>> Q;
            fill(dist.begin(),dist.end(),inf);
            dist[s] = 0;
            Q.push(P(s,0));
            while(!Q.empty()){
                P p = Q.top(); Q.pop();
                int v = p.second;
                if(dist[v]<p.first) continue;
                for(int i=0;i<G[v].size();i++){
                    edge &e = G[v][i];
                    if(e.cap>0 && dist[e.to]>dist[v]+e.cost+h[v]-h[e.to]){
                        dist[e.to] = dist[v]+e.cost+h[v]-h[e.to];
                        prevv[e.to] = v;
                        preve[e.to] = i;
                        Q.push(P(dist[e.to],e.to));
                    }
                }
            }
            if(dist[t]==inf) return -1;
            for(int v=0;v<N;v++) h[v] += dist[v];
            ll d = f;
            for(int v=t;v!=s; v=prevv[v]){
                d = min(d,G[prevv[v]][preve[v]].cap);
            }
            f -= d;
            res += d*h[t];
            for(int v=t;v!=s;v=prevv[v]){
                edge &e = G[prevv[v]][preve[v]];
                e.cap -= d;
                G[v][e.rev].cap += d;
            }
        }
        return res;
    }
};

int main(){
    int N;
    while(cin >> N && N){
        min_cost_flow flow(367);
        for(int i=0;i<N;i++){
            int l,r,w;
            cin >> l >> r >> w;
            flow.add_edge(l,r+1,1,-w);
        }
        for(int i=0;i<366;i++) flow.add_edge(i,i+1,2,0);
        cout << -flow.answer(0,366,2) << endl;
    }
}


Measured memory_bytes: 3180
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}


#[cfg(debug_assertions)]
macro_rules! mydbg {
    //($arg:expr) => (dbg!($arg))
    ($arg:expr) => (println!("{:?}",$arg));
}


#[cfg(not(debug_assertions))]
macro_rules! mydbg {
    ($($arg:expr),*) => {};
}


fn main() {
    input!{
        a:i32,
        p:i32
    }

   let kakera = a *3+p;
   let ret = kakera/2;
   
   println!("{}",ret);


}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int mod=1000000007;
const int INF=1001001001;

vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int main() {
  int64_t A,B,C;
  cin>>A>>B>>C;
  if(A%2==0||B%2==0|C%2==0){cout<<0<<endl;}
  else{cout<<min({A*B,A*C,B*C})<<endl;}
  return 0;  
}

Measured memory_bytes: 3528
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		for(int i = 1;;i++){
			int num = sc.nextInt();
			if(num == 0){
				break;
			}else {
				System.out.println("Case " + i + ": " + num);
			}
		}
	}
}


Measured memory_bytes: 41504
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, S, E) for (int(X) = (S); (X) < (E); ++(X))
#define rrep(X, S, E) for (int(X) = (E)-1; (X) >= (S); --(X))
#define itrep(X, Y) for (auto(X) = (Y).begin(); (X) != (Y).end(); (X)++)
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef priority_queue<ll, vl> decendingQueue;              //降順
typedef priority_queue<ll, vl, greater<ll>> ascendingQueue; //昇順
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll INF = 9 * 1e18;

const long long MOD = 1000000007;

void solve(long long N, long long M, std::vector<long long> a) {
  vl broken(N + 1);
  rep(i, 0, M) { broken[a[i]] = true; }

  vl dp(N + 1);
  dp[0] = 1;
  rep(i, 1, N + 1) {
    if (!broken[i]) {
      dp[i] += dp[i - 1];
      dp[i] %= MOD;
      if (i > 1) {
        dp[i] += dp[i - 2];
        dp[i] %= MOD;
      }
    }
  }

  print(dp[N]);
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> a(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &a[i]);
  }
  solve(N, M, std::move(a));
  return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

#ifdef BTK
#include<dvector.h>
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define DEBUG if(0)
#endif

#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
    
int main(){
    int N,A,B;
    cin>>N>>A>>B;
    cout<<min(B,N*A)<<endl;
    
    return 0;
}


Measured memory_bytes: 892
#include<stdio.h>
#include<string.h>
#define NUM 100000

struct node{
  struct node *parent;
  struct node *left;
  struct node *right;
  int p_number;
  int s_number;
  int l_number;
  int r_number;
  int number;
};

int Height(int);
struct node n[NUM],null_node;

int main(){
  int i,j,depth[NUM],degree[NUM],height[NUM],n1,num,left,right,h1,h2;
  
  for(i=0;i<NUM;i++){
    n[i].parent=&null_node;
    n[i].left=&null_node;
    n[i].right=&null_node;
    n[i].p_number=-1;
    n[i].s_number=-1;
    n[i].l_number=-1;
    n[i].r_number=-1; 
    depth[i]=0;
    degree[i]=0;
    height[i]=0;
  }
  scanf("%d",&n1);
  
  for(i=0;i<n1;i++){ 
    scanf("%d%d%d",&num,&left,&right);
    n[num].number=num;
    n[num].l_number=left;
    n[num].r_number=right;
    if(left!=-1){
      n[num].left=&n[left];
      n[left].parent=&n[num];
      n[left].p_number=num;
    }
    if(right!=-1){
      n[num].right=&n[right];
      n[right].parent=&n[num];
      n[right].p_number=num;
    }

    if(left!=-1&&right!=-1){
      n[left].s_number=right;
      n[right].s_number=left;
    }
    
    if(left!=-1){
      degree[num]++;
    }
    if(right!=-1){
      degree[num]++;
    }
  }

  for(i=0;i<n1;i++){
    j=i;
    while(n[j].parent!=&null_node){
      j=n[j].p_number;
      depth[i]++;
    }
  }

  for(i=0;i<n1;i++){
    height[i]=Height(i);
  }     

  for(i=0;i<n1;i++){
    printf("node %d: ",i);
    printf("parent = %d, ",n[i].p_number);
    printf("sibling = %d, ",n[i].s_number);
    printf("degree = %d, ",degree[i]);
    printf("depth = %d, ",depth[i]);
    printf("height = %d, ",height[i]);
    if(n[i].p_number==-1){
      printf("root\n");
    }else if(n[i].p_number!=-1 && n[i].left==&null_node && n[i].right==&null_node){
      printf("leaf\n");
    }else{
      printf("internal node\n");
    }
  }
  
  return 0;
}
  
int Height(int i){
  int h1=0,h2=0;
  if(n[i].right!=&null_node){
    h1=Height(n[i].r_number)+1;
  }
  if(n[i].left!=&null_node){
    h2=Height(n[i].l_number)+1;
  }
  
  if(h1>=h2)return h1;
  else return h2;
}



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

int main() {
    int N, M; cin >> N >> M;
    string S; cin >> S;

    stack<int> res;
    int cur = N;
    while(cur > 0) {
        int step = 1;
        while(cur - step > 0 && step < M && S[cur - step] == '1') ++step;
        if(S[cur - step] == '1') {
            cout << -1 << endl;
            return 0;
        }
        int ma = step;
        for(int i=step+1; i<=M; ++i) {
            if(cur - i < 0) break;
            if(S[cur - i] == '0') ma = i;
        }
        res.push(ma);
        cur -= ma;
    }
    
    while(!res.empty()) {
        cout << res.top();
        res.pop();
        cout << (res.empty() ? '\n' : ' ');
    }
}

Measured memory_bytes: 868
import java.util.Scanner;



public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int N = s.nextInt()+1;
		int[] t = new int[N];
		int[] x = new int[N];
		int[] y = new int[N];
		t[0] = x[0] = y[0] = 0;
		for(int i = 1;i < N;i++){
			t[i] = s.nextInt();
			x[i] = s.nextInt();
			y[i] = s.nextInt();
		}

		boolean d = true;
		for(int i = 0;i < N-1;i++){
			int xm = Math.abs(x[i+1] - x[i]);
			int ym = Math.abs(y[i+1] - y[i]);
			int tm = t[i+1] - t[i];
			d = (tm - (ym + xm)) >= 0 && (tm - (ym + xm)) % 2 == 0;
		}

		System.out.println(d ? "Yes":"No");


	}

}


Measured memory_bytes: 90180
#include<iostream>
using namespace std;
int main(){
    int x,y;

    while(1){
        cin >> x>>y;
        if( x==0 && y==0)break;

        if(x<y){
            cout << x <<" " <<y << endl;

        }else{
            cout << y <<" " << x << endl;
        }

    }
    
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n,m;
    cin >> n >> m;
    for(int32 i = m / n; i >= 1; --i){
        if(m % i == 0){
            ANS(i);
            return 0;
        }
    }
    ANS(1);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1e09+7;



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

int main(){


  ll n,k;
  cin>>n>>k;
  
  ll x=n%k;
  
  ll answer=min(x,k-x);
  
  cout<<answer<<endl;
  
  
}





Measured memory_bytes: 3552