akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include<stdlib.h>
int cmp(const void *a,const void *b)
{
  return *(int*)a-*(int*)b;
} 
int main()
{
 int n,k;
  scanf("%d%d",&n,&k);
  
  int p[n];
  int i;
  for(i=0;i<n;i++){
    scanf("%d",&p[i]);
  }
  qsort(p,n,sizeof(int),cmp);
  
  int ans=0;
  for(i=0;i<k;i++){
    ans+=p[i];
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 1740
N, K = map(int, input().split())
A = list(map(int, input().split()))
mA, nA = [], []
for a in A:
    if a < 0:
        mA.append(a)
    else:
        nA.append(a)
mA = sorted(mA)[::-1]
nA = sorted(nA)
lnA = len(nA)
lmA = len(mA)


def F(k):
    # k以下の数
    # positive positive
    r = 0
    i, j = 0, lnA-1
    while i < lnA:
        while j >= 0 and nA[j]*nA[i] > k:
            j -= 1
        r += j+1
        i += 1

    # negative negative
    i, j = 0, lmA-1
    while i < lmA:
        while j >= 0 and mA[j]*mA[i] > k:
            j -= 1
        r += j+1
        i += 1

    # positive negative
#    i, j = 0, lmA-1
#    while i < lnA:
#        while j >= 0 and mA[j]*nA[i] <= k:
#            j -= 1
#        r += 2*(lmA-j-1)
#        i += 1
    i, j = lmA-1, 0
    while i >= 0:
        while j < lnA and nA[j]*mA[i] > idx:
            j += 1
        r += 2*(lnA-j)
        i -= 1
    for a in A:
        if a*a <= k:
            r -= 1
    return r//2


mx, mn = 2*10**18, -2*10**18
idx = (mx+mn)//2
target = K
while mx - mn > 1:
    if F(idx) < target:
        mn = idx
    else:
        mx = idx
    idx = (mx+mn)//2
print(idx+1)


Measured memory_bytes: 99924
import java.util.Scanner

fun main(args:Array<String>){
    val cin = Scanner(System.`in`)
    val n = cin.nextInt()
    val list = mutableListOf<Int>()

    for(i in 1..n){
	list.add(cin.nextInt())
    }

    list.reverse()

    for(i in list.indices){
	if(i > 0) print(" ")
	print(list[i])
    }
    println()
}



Measured memory_bytes: 27804
#include<stdio.h>
int main(int argc, char* argv[])
{
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
 
  if(c <= a){
    printf("No\n");
  }else if(c <= b){
    printf("No\n");
  }else if(b <= a){
    printf("No\n");
  }else{
    printf("Yes\n");
  }
  return(0);
}

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

int main() {
  string s;
  cin >> s;

  if (s[0]==s[1]&&s[1]==s[2])
  {cout << "Yes" << endl;}
  else if (s[1]==s[2]&&s[2]==s[3])
  {cout << "Yes" << endl;}
  else {cout << "No" << endl;}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double dbl;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<long long> vl;
typedef vector< pair<int, int> > vii;
#define mp make_pair
#define pb push_back
#define invec(a, n) for(ll i = 0; i < n; i++) {cin >> a[i];}
#define rep(n) for(ll i = 0; i < n; i++)
#define fr(i,j,k) for(ll i = j; i < k; i++)
#define FR(i,j,k) for(ll i = j; i >= 0; i--)
#define MOD 1000000007
#define all(v) v.begin(), v.end()
#define INF 1000000
#define xx first
#define yy second
#define pl cout<<endl;
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
        return os<<"("<< p.first << "," << p.second<<")";
}
template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
os << "{";
typename vector< T > :: const_iterator it;
for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
}
return os << "}";
}
template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
os << "[";
typename set< T > :: const_iterator it;
for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
os << *it;
}
return os << "]";
}
template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
        os << "[";
        typename map< F , S >::const_iterator it;
for( it = v.begin(); it != v.end(); it++ ) {
if( it != v.begin() ) os << ", ";
os << it -> first << " = " << it -> second ;
}
return os << "]";
}
#define deb(x) cout << #x << " = " << x << endl;

#define er(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}
 
void fast()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
 
 
int main()
{
    ll n,k;
    cin>>n>>k;
    vl v(n);
    invec(v,n);
    vl dp(n);
    fill(all(dp),LLONG_MAX);
    dp[0]=0;
    dp[1]=abs(v[1]-v[0]);
    
    for(ll i=2;i<n;i++)
    {
        for(ll j=1;j<=k;j++)
        {
             if(i-j<0)
             {
                 break;
             }
             dp[i]=min(dp[i],abs(v[i]-v[i-j])+dp[i-j]);
        }
       // dp[i]=min(abs(v[i]-v[i-2])+dp[i-2],abs(v[i]-v[i-1])+dp[i-1]);
    }       
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1792
def main():
    N, M, X = map(int, input().split())
    A = list(map(int, input().split()))
    costL, costR = 0, 0
    for i in range(0, X):
        if i in A:
            costL += 1
    for i in range(X, N):
        if i in A:
            costR += 1
    print(min(costL, costR))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: map(str, sys.stdin.buffer.readline().split())
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n = ri()
a = rl()
a.sort()
i = n//2
print(a[i] - a[i-1])



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

using namespace std;

long long q, h, s, d, n;

int main() {
  cin >> q >> h >> s >> d >> n;
  long long one = min(s, min(2LL * h, 4LL * q));
  long long two = min(d, 2LL * one);
  long long ans = two * (n / 2) + one * (n & 1);
  cout << ans << '\n';
  return 0;
}



Measured memory_bytes: 256
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn solve() {
    input! {
        n: usize, m: usize,
        av: [u64; n]
    };

    let mut heap = BinaryHeap::from(av);
    for _ in 0..m {
        let x = heap.pop().unwrap();
        heap.push(x / 2);
    }
    let res = heap.into_iter().sum::<u64>();
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 3352
// 🐋💭
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func readInt() -> Int {
    return Int(readLine()!)!
}

func readDoubles () -> [Double] {
    return readLine()!.split(separator: " ").map { Double($0)! }
}

func readDouble() -> Double{
    return Double(readLine()!)!
}
///最大公約数を返す
func gcd(_ m:Int, _ n:Int) -> Int {
    if n == 0 {return m}
    return gcd(n, m % n)
}
///最小公倍数を返す
func lcm(_ m:Int, _ n:Int) -> Int {
    return m * n / gcd(m, n)
}

///素数判定(試し割り)
func isPrime(_ x:Int) -> Bool {
    if x <= 1 || x % 2 == 0 { return false }
    if x == 2 { return true }
    for i in stride(from: 3, to: Int(ceil(sqrt(Double(x)))), by: 2){
        if x % i == 0 {
            return false
        }
    }
    return true
}

//https://program-life.com/669
///実行速度の計測
func exectionTime(action: () -> Void) {
    let startDate = Date()
    action()
    let endDate = Date()
    print(endDate.timeIntervalSince(startDate))
}

// https://melheaven.hatenadiary.jp/entry/atcoder144
///約数の配列を返す
func makeDivisors(_ n:Int) -> [Int] {
    var divisors = [Int]()
    for i in 1..<Int(pow(Double(n), 0.5)) + 1 {
        if n % i == 0{
            divisors.append(i + n / i)
        }
    }
    
    return divisors
}

//https://riptutorial.com/ja/swift/example/14738/インデックスを知らずに配列から要素を削除する
extension Array where Element: Equatable {
    
    mutating func remove(_ element: Element) {
        _ = firstIndex(of: element).flatMap {
            self.remove(at: $0)
        }
    }
}

func binarySearch(rifgt:Int, key:Int, ary:[String]) -> Int{
    var left = 0
    var right = rifgt
    
    while abs(right - left) > 1 {
        let mid = left + (right - left) / 2
        
        if Int(ary[mid])! < key {
            left = mid
            
        } else {
            right = mid
        }
    }
    return left
}

func arrangement (prev:String, ary:[String], returnVal:[String]) -> [String] {
    var returnVal = returnVal
    if ary.count == 0 {
        returnVal.append(prev)
        return returnVal
    }
    
    for s in ary {
        let wprev = prev + s
        var wary = ary
        wary.remove(s)
        returnVal = arrangement(prev: wprev, ary: wary, returnVal: returnVal)
    }
    return returnVal
}

func main() {
    let k = readInt()
    //＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿ここまで入力
    
    var mod = 7 % k
    var i = 1
    while mod > 0 && i <= k {
        mod = (mod * 10 + 7) % k
        i += 1
    }
    print(mod == 0 ? i: -1)
    
}
main()


Measured memory_bytes: 13132
# -*- coding: utf-8 -*-
# 入力のインプット
dic = {"A":10, "B":11, "C":12, "D":13, "E":14, "F":15}
put1, put2 = input().split()
for i in dic.keys():
    if put1 == i:
        out1 = dic[i]
    if put2 == i:
        out2 = dic[i]

if(out1 > out2):
    print(">")
elif(out1 < out2):
    print("<")
else:
    print("=")

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

int main() {
    ios_base::sync_with_stdio(false);;
    cin.tie(0);
    cout.tie(0); 
ll n,a,b,l,r,f,ans,i;
char c;
ll k1;
cin>>k1;
string s;
vector<set<ll>>v(26);
cin>>s;
for(i=0;i<s.size();i++)
{v[s[i]-'a'].insert(i);
}

cin>>n;
while(n--)
{cin>>a;
if(a==1)
{cin>>b>>c;
v[s[b-1]-'a'].erase(b-1);
v[c-'a'].insert(b-1);
s[b-1]=c;
}
else
{ans=0;
cin>>l>>r;
--l;
--r;
for(f=0;f<26;++f)
{auto it=v[f].lower_bound(l);
if(*it<=r && it!=v[f].end())
{ans+=1;
}
}
cout<<ans<<"\n";
}
}



return 0;
}

Measured memory_bytes: 24220
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;


public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        List<Long> list = Stream.iterate(1l , (Long i)-> {
            return i + 1l;
        })
                .limit(n).collect(Collectors.toList());
        long sum = 0;
        List<Long> filterd = list.stream().filter(x -> {
            if(x.longValue() % 3 == 0 || x.longValue() % 5 == 0){
                return false;
            }else{
                return true;
            }
        }).collect(Collectors.toList());

        for(Long in : filterd){
            sum += in.longValue();
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 77408
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
// dp[length][zero_exists][nine_exists]
int dp[1000001][2][2], n;

inline int add(int x, int y) { return x += y, x %= mod; }
inline int mul(long long x, int y) { return x *= y, x %= mod; }
inline int mac(int x, int y, int z) { return add(x,mul(y,z)); } 

int main() {
    cin >> n, dp[0][0][0] = 1;
    for (int i = 0, j = 1; i < n; i = j++) 
        dp[j][0][0] = mul(dp[i][0][0],8),
        dp[j][0][1] = mac(dp[i][0][0],9,dp[i][0][1]),
        dp[j][1][0] = mac(dp[i][0][0],9,dp[i][1][0]),
        dp[j][1][1] = mac(add(dp[i][0][1],dp[i][1][0]),10,dp[i][1][1]);
    cout << dp[n][1][1]; }


Measured memory_bytes: 19028
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)

	n := len(s)
	s1 := s[:(n-1)/2]
	s2 := s[(n+3)/2-1:]

	if s == reverse(s) && s1 == reverse(s1) && s2 == reverse(s2) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
using namespace std;
int n, h[100005];
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> h[i];
	int j = 1, ans = 0;
	for (int i = 1; i <= n; i++)
	{
		if (h[i] > h[i - 1])
		{
			ans = max(ans, i - 1 - j + 1);
			j = i; continue;
		}
		if (i == n)
			ans = max(ans, i - j + 1);
	}
	cout << (ans > 0 ? ans - 1 : ans) << endl;
	return 0;
}

Measured memory_bytes: 640
def work(item):
    if recipe.has_key(item):
        price = 0
        for i in recipe[item]: price += work(i)
        p_list[item] = min(price, p_list[item])
        del recipe[item]
    return p_list[item]

while True:
    p_list = {}
    recipe = {}

    n = input()
    if n == 0: break

    for i in range(n):
        item, price = raw_input().split()
        p_list[item] = int(price)

    m = input()
    for i in range(m):
        data = raw_input().split()
        recipe[data[0]] = []
        for j in range(int(data[1])):
            recipe[data[0]].append(data[j + 2])

    if m == 0:
        print p_list[raw_input()]
    else:
        price = work(raw_input())
        print price

Measured memory_bytes: 4260
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

template<class INT_T> vector<INT_T> divisors(INT_T n)
{
    vector<INT_T> divs;
    for (INT_T d=1; d*d <= n; d++) {
        if (n%d==0) {
            divs.push_back(d);
            INT_T q = n/d;
            if (q != d) divs.push_back(q);
        }
    }
    // sort(divs.begin(), divs.end());
    return divs;
}

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

    vector<ll> divs1 = divisors(N-1);
    vector<ll> divs = divisors(N);

    ll ans = 0;

    ans += count_if(divs1.begin(), divs1.end(), [](ll x) { return x != 1; });
    ans += count_if(divs.begin(), divs.end(), [&](ll x) {
        if (x != 1) {
            ll n = N;
            while (n % x == 0) n /= x;
            if (n % x == 1) return true;
        }
        return false;
    });

    cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,a,b;
	scanf("%d",&n);
	if(n==1) printf("Hello World\n");
	else{
		scanf("%d%d",&a,&b);
		printf("%d\n",a+b);
	} 
	return 0;
}

Measured memory_bytes: 256
loop do
  break if gets.to_i == 0
????m = gets.to_i
  r = []
????m.times { r << gets.split.map(&:to_i) }

  friends = r.select {|(a,b)| a == 1 || b == 1 }.map {|(a,b)| a == 1 ? b : a }.uniq
  foafs = r.select {|(a,b)| a != 1 && b != 1 && (friends.include?(a) || friends.include?(b)) }.flatten - friends

  puts friends.size + foafs.uniq.size
end

Measured memory_bytes: 8832
#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n)	for(int i=a; i<n; i++)
#define loop(i,a,n)	for(int i=a; i>=n; i--)

int main() 
{	
	ios_base :: sync_with_stdio(false),cin.tie(NULL),cout.tie(0);
	
	string s;
	cin>>s;
	if(s[2]==s[3] and s[4]==s[5])	cout<<"Yes";
	else cout<<"No";
	
	return 0;	
}

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

const int N = 1e5 + 1;
int dp[N], a[101];
int n, k, min_a;

bool f(int k) {
  if (dp[k] != -1)
    return dp[k];

  if (k < min_a) 
    return dp[k] = false;

  for (int i = 0; i < n; i++) 
    if (a[i] == k)
      return dp[k] = true;

  for (int i = 0; i < n; i++)
    if (k >= a[i] && !f(k - a[i]))
        return dp[k] = true;

  return dp[k] = false;
}

int main() {
  cin >> n >> k;
  min_a = N;
  for (int i = 0; i <= k; i++) 
    dp[i] = -1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if(min_a > a[i]) 
      min_a = a[i];
  }
  string ans = f(k) ? "First" : "Second";
  cout << ans << endl;
}


Measured memory_bytes: 5376
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0; 
void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }

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

const long mod = 1_000_000_007;
void solve(){
  int n = scan!int;
  long[] as = scan!long(n);
  
  long sum;
  foreach(a; as) sum += a, sum %= mod;
  
  long sqsum;
  foreach(a; as) sqsum += (a * a) % mod, sqsum %= mod;
  
  long ans = (sum * sum) % mod;
  ans += mod - sqsum, ans %= mod;
  if(ans % 2) ans += mod;
  ans /= 2;
  
  ans.writeln;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++) cin >> a[i], a[i]--;

  int cnt = 0;
  for(int i=0;i<n;i++){
    if(i == a[a[i]]) cnt++;
  }
  cout << cnt/2 << endl;
}


Measured memory_bytes: 640
package main

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

type Edge struct {
	source, target, cost int
}

const Inf = 1 << 60

func main() {
	N, M := ReadInt(), ReadInt()
	edges := make([]Edge, M)
	for i := 0; i < M; i++ {
		edges[i].source = ReadInt() - 1
		edges[i].target = ReadInt() - 1
		edges[i].cost = -ReadInt()
	}
	d := make([]int, N)
	for i := 0; i < N; i++ {
		d[i] = Inf
	}
	d[0] = 0
	foundNegativeCycle := false
	for i := 0; i < N; i++ {
		update := false
		for _, e := range edges {
			if d[e.source] == Inf {
				continue
			}
			newD := d[e.source] + e.cost
			if newD < d[e.target] {
				d[e.target] = newD
				update = true
				if i == N-1 && e.target == N-1 {
					foundNegativeCycle = true
				}
			}
		}
		if !update {
			break
		}
	}
	if foundNegativeCycle {
		fmt.Println("inf")
	} else {
		fmt.Println(-d[N-1])
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }


Measured memory_bytes: 2008
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
    int a,b;
    cin >>a>>b;
    int k = a-(b*2);
    if(k <0) k = 0;
    cout<<k;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int W = sc.nextInt();
        int[] w = new int[N + 1];
        long[] v = new long[N + 1];
        for (int i = 1; i <= N; i++) {
            w[i] = sc.nextInt();
            v[i] = sc.nextLong();
        }
        long[][] dp = new long[N + 1][W + 1];
        for (int i = 1; i <= N; i++) {
            for (int j = 0; j <= W; j++) {
                if (j < w[i]) {
                    dp[i][j] = dp[i - 1][j];
                } else {
                    dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
                }
            }
        }
        System.out.println(dp[N][W]);
    }

}


Measured memory_bytes: 140668
import itertools
N = int(input())
seq = ("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z")

a = (N * 25 + 26) / 26
ans = 1#文字数
#print(a)
while a > 26:
  a /= 26
  #print(a)
  ans += 1

p = (26 ** ans - 26) / 25
z = int(N - p)
#print(z, p, ans)
ans2 = [0] * ans
for i in range(ans):
  x = N % 26
  if x == 0:
    x = 26
  N = int((N - x) // 26)
  ans2[ans - i - 1] = x
  
#print(ans2)
for i in range(ans):
  print(seq[ans2[i] - 1], end = "")
  
#x = list(itertools.product(seq, repeat = ans))
#ans2 = x[N - 1]
#for i in range(len(ans2)):
#  print(ans2[i], end = "")
#print("")


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

string str,out;

int flg=0;

int main(){
  getline(cin,str);
  out="";
  for(int i=0;i<(int)str.size();i++){
    if((str[i]==' '||str[i]=='.'||str[i]==',')){
      if(out.size()>=3&&out.size()<=6){
	if(flg)cout<<" ";
	cout<<out;
	flg=1;
      }
      out="";
    }else{
      out.push_back(str[i]);
    }    
  }
  cout<<endl;

  return 0;
}

Measured memory_bytes: 1172
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		static readonly int mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			int n = int.Parse(Console.ReadLine());
			//string s = Console.ReadLine();
			string[] s = Console.ReadLine().Split();
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();
			for (int i = 0; i < n; i++) {
				Console.Write(s[0][i]);
				Console.Write(s[1][i]);
			}
			Console.WriteLine();


			Console.Out.Flush();
		}
	}
}


Measured memory_bytes: 11092
program main
  implicit none
  integer :: n, k, res, i
  integer, allocatable :: x(:)
  read(*, *) n
  read(*, *) k
  allocate(x(n))
  read(*, *) x(:)
  res = 0
  do i = 1, n
    res = res + min(x(i), k - x(i))
  end do
  write(*, "(i0)") res * 2
end program main


Measured memory_bytes: 256
#import sys

#input = sys.stdin.readline
import math
#import bisect

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True


def main():
#    h,w,a,b = map(int, input().split())
    s = input()
    a = [0]*(len(s)+1)

    a[0] = 0
    temp = 0
    for i in range(len(s)):
        if s[i] == "<":
            a[i + 1] = a[i]+ 1
            if temp>0:
                for j in range(temp+1):
                    a[i - j] = max(0 + j,a[i-j])
            temp = 0
        elif s[i] == ">" and i < len(s)-1:
            temp += 1
        else:
            temp+=1
            for j in range(temp):
                a[i - j] = 0 + j + 1

    b = 0
    for i in range(len(a)):
        b += a[i]

    print(b)




if __name__ == "__main__":
    main()

Measured memory_bytes: 23336
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, _s, n) for(int i = _s, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;

#define repi(itr, ds) for(auto itr = ds.begin(); itr != ds.end(); itr++)
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for(T &x : vec) is >> x;
  return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "{";
  for(int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  os << "}\n   ";
  return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  repi(itr, map_var) {
    os << *itr;
    itr++;
    if(itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  repi(itr, set_var) {
    os << *itr;
    itr++;
    if(itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}

#define DUMPOUT cerr

void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
  DUMPOUT << head;
  if(sizeof...(Tail) > 0) {
    DUMPOUT << ", ";
  }
  dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define dump(...)                                                             \
  DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                             \
          << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
          << "    ",                                                          \
      dump_func(__VA_ARGS__)
#else
#define DEB if(false)
#define dump(...)
#endif

typedef long long int ll;

int main() {
  ll N;
  cin >> N;
  if(N % 2 == 1) {
    cout << 0 << endl;
    return 0;
  }

  ll d = 10;
  ll ans = 0;
  while(d <= N) {
    ans += N / d;
    d *= 5;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	while(1){
	int h,w;
	cin >> h >> w;
	if(h == 0 && w == 0){
		break;
	}
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if((i + j) % 2 == 0){
				cout << "#";
			}
			else{
				cout << "."; 
			}
		}
		cout << endl;
		}
	cout << endl;
	}
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string N;
  cin >> N;
  int count=0;
  for(int i=0;i<3;i++){
  	if(N.at(i)=='7'){
    	count++;
    }
  }
  if(count==0){
  	cout << "No" << endl;
  }else{
  	cout << "Yes" << endl;
  }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define REP(i, n) for(int i=0; i<n; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
using P = pair<int, int>;
const int inf = 1e9;
const ll INF = 1e18;
const ll MOD = 1e9+7;
const ll MAX = 1e9+7;
template<typename T> T factorial(T n){
    if(n==1) return 1;
    else return n*factorial(n-1);
}
template<typename T> T combination(T n, T k){
    vector<vector<T>> v(n+1, vector<T>(n+1, 0)); //dpテーブル
    REP(i, v.size()){
        v[i][0] = 1; v[i][i] = 1;
    }
    for(int j=1; j<v.size(); j++){
        for(int k=1; k<j; k++){
            v[j][k] = v[j-1][k-1] + v[j-1][k];
        }
    }
    return v[n][k];
}
struct edge{
    int to;
    int cost;
};
using graph = vector<vector<edge>>;

int main(){
    int vec[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k; cin >> k;
    cout << vec[k-1] << endl;
    return 0;
}

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

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

const long long INF = 1LL << 60;

/* bがa以上のとき、置き換え */
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b;}else{return false;}return true;}

/* bがa以下のとき、置き換え */
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b;}else{return false;}return true;}

int main()
{
	int N;
	std::cin >> N;
	std::map<std::string, int> name;
	
	rep(i, N)
	{
		std::string tmp;
		std::cin >> tmp;

		if( name.find(tmp) != name.end() )
		{
			name[tmp]++;
		}
		else
		{
			name.insert(std::make_pair(tmp, 1));
		}
	}
	
	// maxの回数を調べる
	int max = 0;
	for( std::pair<std::string, int> now: name )
	{
		int value = now.second;
		max = std::max( max, value );
	}

	// 出力する 
	for( std::pair<std::string, int> now: name )
	{
		if( now.second == max )
		{
			std::cout << now.first << std::endl;
		}
	}

	return 0;
}


Measured memory_bytes: 19188
# import sys
# input = sys.stdin.readline
import itertools
import collections
from decimal import Decimal
from functools import reduce


# 持っているビスケットを叩き、1枚増やす
# ビスケット A枚を 1円に交換する
# 1円をビスケット B枚に交換する
def main():
    H, W, k = input_list()
    maze = [list(input()) for _ in range(H)]
    ans = 0
    for row_bit in itertools.product(range(2), repeat=H):
        for col_bit in itertools.product(range(2), repeat=W):
            cnt = 0
            for row in range(H):
                for col in range(W):
                    if maze[row][col] == "#" and (row_bit[row] and col_bit[col]):
                        cnt += 1
            if cnt == k:
                ans += 1
    print(ans)


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


def bfs(H, W, black_cells, dist):
    d = 0
    while black_cells:
        h, w = black_cells.popleft()
        d = dist[h][w]
        for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
            new_h = h + dy
            new_w = w + dx
            if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w:
                continue
            if dist[new_h][new_w] == -1:
                dist[new_h][new_w] = d + 1
                black_cells.append((new_h, new_w))
    return d


def input_list():
    return list(map(int, input().split()))


def input_list_str():
    return list(map(str, input().split()))


if __name__ == "__main__":
    main()


Measured memory_bytes: 78292
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

void solve(){
	int x; cin>>x;
	if(x==0)
		cout<<1;
	else cout<<0;
	cout<<"\n";
	
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    // ll t; cin>>t;
    // while(t--)
        solve();
    return 0;
}



Measured memory_bytes: 3600
#include <iostream>

using namespace std;

int main() {
  int i = 1;
  while (1) {
    int x;
    cin >> x;
    if (x == 0) {
      break;
    }
    cout << "Case " << i << ": " << x << endl;
    i++;
  }
  return 0;
}


Measured memory_bytes: 2976
// B - Good Distance

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const int MOD = 1e9 + 7;

vector<int> X[10];

int calc_dist_sq(int D, vector<int> A, vector<int> B) {
	int res = 0;
	for (int i=0; i<D; i++) {
		res += (A[i] - B[i]) * (A[i] - B[i]);
	}

	return res;
}

int main(){
	int N, D;
	cin >> N >> D;

	for (int i=0; i<N; i++) {
		for (int j=0; j<D; j++) {
			int x;
			cin >> x;
			X[i].push_back(x);
		}
	}

	int ans = 0;
	for (int i=0; i<N; i++) {
		for (int j=i+1; j<N; j++) {
			int dist_sq = calc_dist_sq(D, X[i], X[j]);
			if ((int)sqrt(dist_sq) * (int)sqrt(dist_sq) == dist_sq) ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

typedef pair<ll, ll> P;
#define fs first
#define sc second

bool cmp(const P &a, const P &b){
    return a.sc < b.sc;
}

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

    P p[N];
    for(int i = 0; i < N; i++){
        ll x, l;
        cin >> x >> l;
        p[i].fs = x - l;
        p[i].sc = x + l;
    }

    sort(p, p + N, cmp);

    ll r = -1000000000;
    int ans = 0;
    for(int i = 0; i < N; i++){
        if(p[i].fs >= r){
            ans++;
            r = p[i].sc;
        }
    }

    cout << ans << endl;
    return 0;
}

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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

const int32_t inf = 1001001001;
const int64_t infll = 1001001001001001001ll;
const int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}, dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};

template <typename T> using vector2d = vector<vector<T>>;

// clang-format off
template <typename T> void sort(vector<T> &v) { sort(all(v)); }
// ostream &operator<<(ostream &os, __int128_t value) { if (ostream::sentry(os)) { __uint128_t tmp = value < 0 ? -value : value; char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
// istream &operator>>(istream &is, __int128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } if (in[0] == '-') value *= -1; return is; }
// ostream &operator<<(ostream &os, __uint128_t value) { if (ostream::sentry(os)) { char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[value % 10]; value /= 10; } while (value != 0); int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
// istream &operator>>(istream &is, __uint128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } return is; }
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { os << v[0]; for (int i = 1; i < v.size(); ++i) os << " " << v[i]; return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.fs << " " << p.sc; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.fs >> p.sc; return is; }

struct IoSetup { IoSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup;

inline int64_t in() { int64_t x = 0; cin >> x; return x; }
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

signed main(int argc, char *argv[]) {
  int n = in();
  int a[2][200] = {};

  for (int i = 0; i < 2; ++i)
    for (int j = 1; j <= n; ++j) {
      cin >> a[i][j];
    }

  for (int i = 1; i <= n; ++i) {
    a[0][i] += a[0][i - 1];
    a[1][i] += a[1][i - 1];
  }

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


Measured memory_bytes: 256
/**********************************************
 * author : deepak nayan
 * file   : e:/Solutions/atcoder/abc111_a.cpp
 * time   : Fri May  1 02:04:42 2020
 * quest  : A - AtCoder Beginner Contest 999
 *********************************************/
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  cout << (s[0] == '1' ? '9' : '1') << (s[1] == '1' ? '9' : '1') << (s[2] == '1' ? '9' : '1') << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
typedef long long ll;

ll n;
char str[100005];

ll win, lose;
ll g, p;

int main()
{
	scanf("%s", str);

	n = strlen(str);
	for (ll i = 0; i < n; i++) {
		if (g == p) {
			g++;

			if (str[i] == 'p') {
				lose++;
			}

		} else {
			p++;

			if (str[i] == 'g') {
				win++;
			}
		}
	}

	printf("%lld\n", win - lose);

	return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a = read::<usize>();
    let b = read::<usize>();
    let t = read::<usize>();
    println!("{}", t / a * b);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rep3(i, a, b) for(ll i = a; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(c) begin(c), end(c)
#define ok() puts(ok?"Yes":"No");
template<class T> bool chmax(T &a, const T &b) { if(a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if(a > b) { a = b; return true; } return false; }
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

vi to[200006];
ll add[200005];
ll ans[200005];

void dfs(int v=0, int p=-1) {
  for (int u: to[v]) {
    if (u==p) continue;
    ans[u]+=ans[v];
    dfs(u, v);
  }
}

int main() {
  int N,Q;
  cin >> N >> Q;
  rep(i,N-1) {
  int a,b; cin >> a >> b; a--; b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  rep(i,Q) {
    int p,x;cin>>p>>x;
    p--;
    ans[p]+=x;
  }
  dfs();  
  rep(i,N) printf("%lld%c",ans[i],i==N-1?'\n':' ');
  return 0;
}

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

int main(){
  string s;
  cin >> s;
  int n=s.size(),i,cur=0,ans=0;
  for(i=0; i<n; i++){
    if(s[i]=='A' || s[i]=='T' || s[i]=='G' || s[i]=='C'){
      cur++; ans=max(cur,ans);
    }else{
      cur=0;
    }
  }
  cout << ans;
}

Measured memory_bytes: 256
H, W= map(int, input().split())
fi=[[False] * W for i in range(H)]
for i in range(H):
    s=input().strip()
    for j in range(W):
        fi[i][j]=s[j]
fl=True
for i in range(H):
    for j in range(W):
        if fi[i][j]=='#':
            if i-1>=0 and j-1>=0 and i+1<H and j+1<W:
                if fi[i+1][j]=='.' and fi[i][j+1]=='.' and fi[i-1][j]=='.' and fi[i][j-1]=='.':
                    fl=False
            elif i-1<0 and j-1>=0 and i+1<H and j+1<W:
                if fi[i+1][j]=='.' and fi[i][j+1]=='.' and fi[i][j-1]=='.':
                    fl=False
            elif i-1>=0 and j-1<0 and i+1<H and j+1<W:
                if fi[i+1][j]=='.' and fi[i][j+1]=='.' and fi[i-1][j]=='.':
                    fl=False
            elif i-1>=0 and j-1>=0 and i+1>=H and j+1<W:
                if fi[i][j+1]=='.' and fi[i-1][j]=='.' and fi[i][j-1]=='.':
                    fl=False
            elif i-1>=0 and j-1>=0 and i+1<H and j+1>=W:
                if fi[i+1][j]=='.' and fi[i-1][j]=='.' and fi[i][j-1]=='.':
                    fl=False
            elif i-1<0 and j-1<0 and i+1<H and j+1<W:
                if fi[i+1][j]=='.' and fi[i][j+1]=='.':
                    fl=False
            elif i-1<0 and j-1>=0 and i+1>=H and j+1<W:
                if fi[i][j+1]=='.' and fi[i][j-1]=='.':
                    fl=False
            elif i-1<0 and j-1>=0 and i+1<H and j+1>=W:
                if fi[i+1][j]=='.' and fi[i][j-1]=='.':
                    fl=False
            elif i-1>=0 and j-1<0 and i+1>=H and j+1<W:
                if fi[i][j+1]=='.' and fi[i-1][j]=='.':
                    fl=False
            elif i-1>=0 and j-1<0 and i+1<H and j+1>=W:
                if fi[i+1][j]=='.' and fi[i-1][j]=='.':
                    fl=False
            elif i-1>=0 and j-1>=0 and i+1>=H and j+1>=W:
                if  fi[i-1][j]=='.' and fi[i][j-1]=='.':
                    fl=False
            elif i-1>=0 and j-1<0 and i+1>=H and j+1>=W:
                if fi[i-1][j]=='.':
                    fl=False
            elif i-1<0 and j-1>=0 and i+1>=H and j+1>=W:
                if fi[i][j-1]=='.':
                    fl=False
            elif i-1<0 and j-1<0 and i+1<H and j+1>=W:
                if fi[i+1][j]=='.':
                    fl=False
            elif i-1<0 and j-1<0 and i+1>=H and j+1<W:
                if fi[i][j+1]=='.':
                    fl=False
            elif i-1<0 and j-1<0 and i+1>=H and j+1>=W:
                fl=False
                    


if fl:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3320
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int a[n], b[n], c[n];
    for(int i = 0; i < n; i++)
        cin >> a[i] >> b[i] >> c[i];

    int dp[n][3];
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    for(int i = 0; i < n - 1; i++)
    {
        dp[i + 1][0] = max(dp[i][1], dp[i][2]) + a[i + 1];
        dp[i + 1][1] = max(dp[i][0], dp[i][2]) + b[i + 1];
        dp[i + 1][2] = max(dp[i][0], dp[i][1]) + c[i + 1];
    }

    cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));

    return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>
#include <string.h>
#include <math.h>

int main() {

    long x;

    scanf("%ld", &x);

    double mysum = 100;
    int cnt = 0;
    while (mysum < x) {

        mysum = floor(mysum * 1.01);

        cnt++;
        
    }

    printf("%d", cnt);

    return 0;
}


Measured memory_bytes: 1736
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <random>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod = 1000000007;
int rnd(int x) { return mrand() % x; }
ll powmod(ll a, ll b)
{
	ll res = 1;
	a %= mod;
	assert(b >= 0);
	for (; b; b >>= 1)
	{
		if (b & 1)
			res = res * a % mod;
		a = a * a % mod;
	}
	return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

static uint MD = mod;
struct ModInt
{
	using M = ModInt;
	uint v;
	ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
	M &set_v(uint _v)
	{
		v = (_v < MD) ? _v : _v - MD;
		return *this;
	}
	explicit operator bool() const { return v != 0; }
	M operator-() const { return M() - *this; }
	M operator+(const M &r) const { return M().set_v(v + r.v); }
	M operator-(const M &r) const { return M().set_v(v + MD - r.v); }
	M operator*(const M &r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
	M operator/(const M &r) const { return *this * r.inv(); }
	M &operator+=(const M &r) { return *this = *this + r; }
	M &operator-=(const M &r) { return *this = *this - r; }
	M &operator*=(const M &r) { return *this = *this * r; }
	M &operator/=(const M &r) { return *this = *this / r; }
	bool operator==(const M &r) const { return v == r.v; }
	M pow(ll n) const
	{
		M x = *this, r = 1;
		while (n)
		{
			if (n & 1)
				r *= x;
			x *= x;
			n >>= 1;
		}
		return r;
	}
	M inv() const { return pow(MD - 2); }
	friend ostream &operator<<(ostream &os, const M &r) { return os << r.v; }
};
using Mint = ModInt;
//head
// cin >> t;
// for (int cas = 1; cas <= t; ++cas)
// {
// 	cout << "Case #" << cas << ": ";
// }

int main()
{
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	ull a,b,n;
	cin>>a>>b>>n;
	
	ull t = (n>=b-1) ? b-1: n;
	cout<<(a*(t)/b)<<endl;
	return 0;
}


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

int main(){
    int A, B;
    cin >> A >> B;
    int R = 0;
    for(int i = A; i<=B; i++){
        int S = i % 10, T = i / 10000 % 10;
        int U = i / 10 % 10, V = i / 1000 % 10;

        if(S == T&&U == V){
            R++;
        }

    }
    cout << R << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String str = scanner.next();
		char[] strs = new char[str.length()];
		int q = scanner.nextInt();
		for (int i = 0; i < str.length(); i++) {
			strs[i] = str.charAt(i);
		}
		for (int i = 0; i < q; i++) {
			String please = scanner.next();
			if (please.equals("print")) {
				int a = scanner.nextInt();
				int b = scanner.nextInt();
				for (int j = 0; a + j <= b; j++) {
					System.out.print(strs[a + j]);
				}
				System.out.println();

			} else if (please.equals("reverse")) {
				int a = scanner.nextInt();
				int b = scanner.nextInt();
				char oki;
				while ( a <= b) {
					oki = strs[a];
					strs[a] = strs[b];
					strs[b] = oki;
					a++;
					b--;
				}

			} else if (please.equals("replace")) {
				int a = scanner.nextInt();
				int b = scanner.nextInt();
				String nstr = scanner.next();
				char nstrs[] = new char[nstr.length()];
				for (int i2 = 0; i2 < nstr.length(); i2++) {
					nstrs[i2] = nstr.charAt(i2);
				}
				for (int j = 0; a <= b; j++) {
					strs[a] = nstrs[j];
					a++;
				}

			}

		}
		scanner.close();
	}
}


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

int main() {
	string S,ans="Yes";
	cin>>S;
	
  map<char,int> M;
  
  for(int i=0; i<S.length();i++){
    if(!M.count(S.at(i))){M[S.at(i)]=1;}
    else{M[S.at(i)]++;}
  }
    for(int i=0; i<S.length();i++){
      if(M.at(S.at(i))%2==1){ans="No";break;}
    }
      
	cout<<ans<<endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define N 500009
#define inf 999999999999
#define pb push_back
#define M (L+R)/2
using namespace std;
 
struct node {
	ll sum;
	node *left,*right;
	node(): sum(0), left(NULL), right(NULL){}
};
node *root(NULL);
 
void upd(node *&parent,ll L,ll R,ll ind,ll x){
	if(!parent){
		parent=new node();
	}
	if(L+1==R){
		parent->sum+=x;
		return;
	}
	if(ind<M){
		upd(parent->left,L,M,ind,x);
	} else {
		upd(parent->right,M,R,ind,x);
	}
	parent->sum=(parent->left?parent->left->sum:0)+(parent->right?parent->right->sum:0);
	return;
}
 
ll get(node *&parent,ll L,ll R,ll l,ll r){
	if(parent){
		if(L>=r || R<=l)return 0;
		if(l<=L && R<=r)return parent->sum;
		return get(parent->left,L,M,l,r)+get(parent->right,M,R,l,r);
	}
	return 0;
}
 
 
ll n,A[N],a[N],b[N],c[N];
 
bool check(ll x){
	ll zero=0,one=0;
	for(int i=1;i<=n;i++){
		if(a[i]<x)b[i]=-1;
		else b[i]=1;
	}
	for(int i=1;i<=n;i++){
		b[i]+=b[i-1];
		if(b[i]<0)zero++;
		else one++;
		upd(root,-2*N,2*N,b[i],1);
	}
	for(int i=1;i<=n;i++){
		upd(root,-2*N,2*N,b[i],-1);
		ll G=get(root,-2*N,2*N,b[i],N-1);
		one+=G;
		zero+=n-i-G;
	}
	
	if(zero>one)return false;
	else return true;
}
 
int main(){
	
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		A[i]=a[i];
	}
	sort(A+1,A+1+n);
	ll L=1,R=n,pas=0;
	while(L<=R){
		root=NULL;
		if(check(A[M])){
			pas=A[M];
			L=M+1;
		} else {
			R=M-1;
		}
	}
	cout<<pas<<endl;
	return 0;
}


Measured memory_bytes: 118784
use proconio::input;

fn main() {
  input! {
      n: usize,
      mut arr: [u64; n]
  }

  arr.sort();
  if arr.len() == 2 {
    println!("{}", arr[1]);
    return
  }

  if arr.len() == 3 {
    println!("{}", arr[1] + arr[2]);
    return
  }

  let mut result = arr.pop().unwrap();
  let mut base_stack: Vec<u64> = vec![arr.pop().unwrap()];
  while (0 <= arr.len()) {
    let mut stack: Vec<u64> = vec![];
    while 0 < base_stack.len() {
      let val = base_stack.remove(0);
      if arr.len() == 0 {
        println!("{}", result);
        return
      }
      stack.push(arr.pop().unwrap());
      result += val;

      if arr.len() == 0 {
        println!("{}", result);
        return
      }
      stack.push(arr.pop().unwrap());
      result += val;
    }
    base_stack = stack;
  }

  println!("{}", result);
}

Measured memory_bytes: 7616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

vector<ll> a;
ll N;

// index が条件を満たすかどうか
bool isOK(ll start, ll goal) {
    for(ll i = 0; i < N; i++) {
        start -= (start % a[i]);
    }
    if(start >= goal)
        return true;
    else
        return false;
}

// 汎用的な二分探索のテンプレ
ll binary_search(ll key) {
    ll left = 1;         //「index = 0」が条件を満たすこともあるので、初期値は -1
    ll right = longinf;  // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* どんな二分探索でもここの書き方を変えずにできる！ */
    while(right - left > 1) {
        ll mid = left + (right - left) / 2;
        if(isOK(mid, key))
            right = mid;
        else
            left = mid;
    }

    /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
    return right;
}
int main() {
    cin >> N;
    a.resize(N);
    for(int i = 0; i < N; i++) cin >> a[i];
    ll under = binary_search(2);
    ll upper = binary_search(3);
    if(under >= upper)
        cout << -1 << "\n";
    else
        cout << under << " " << upper - 1 << "\n";
    return 0;
}

Measured memory_bytes: 1024