akhauriyash/Code-Regression huggingface dataset:
import collections

h, w = list(map(int, input().split()))
smat = [input() for _ in range(h)]

def bfs(x0, y0):
    visited = [[0 for _ in range(w)] for _ in range(h)]
    deq = collections.deque()
    deq.append((x0, y0, -1))

    mx = 0
    while len(deq) > 0:
        x, y, d = deq.popleft()
        nd = d + 1
        visited[x][y] = 1
        mx = max(mx, nd)

        for dx, dy in [(-1, 0), (0, -1), (+1, 0), (0, +1)]:
            nx = x + dx
            ny = y + dy
            if not (0 <= nx < h) or not (0 <= ny < w):
                # bound check
                continue
            if smat[nx][ny] == '#':
                # cell attr check
                continue
            if visited[nx][ny] == 1:
                # already visited
                continue
            v = (nx, ny, nd)
            deq.append(v)
    
    return mx

if all(all(col == '.' for col in row) for row in smat):
    print((w - 1) + (h - 1))
else:
    mxall = 0
    for x0 in range(h):
        for y0 in range(w):
            if smat[x0][y0] == '.':
                mx = bfs(x0, y0)
                mxall = max(mxall, mx)
    print(mxall)


Measured memory_bytes: 9492
H,W=map(int,input().split())

S=["" for i in range(H+2)]

S[0]="."*(W+2)

for i in range(1,H+1):
    S[i]="."+input()+"."

S[H+1]="."*(W+2)

#全ての黒マスの縦か横に黒マスがあることをチェック

CHECK=1

for i in range(1,H+1):

    for j in range(1,W+1):

        if S[i][j]=="#":
            if S[i][j+1]=="." and S[i][j-1]=="." and S[i-1][j]=="." and S[i+1][j]==".":
                CHECK=0


if CHECK==1:
    print("Yes")
else:
    print("No")

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



int main(){
  int N;
  cin >> N;
  int ans = 0; 
  for(int j = 1;j<=N;j++){
    int a;
    cin >> a;
    if(j%2==1){
      if(a%2==1){
        ans ++;
      }
    }
  }
        
  cout <<ans<< endl;
}



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

using namespace std;
#define BUF (205)

int h,w;
int a[BUF][BUF];
int c[11][11];


void wf(void){
	for(int k=0;k<10;k++) for(int i=0;i<10;i++) for(int j=0;j<10;j++){
		if(c[i][j] > c[i][k]+c[k][j]) c[i][j] = c[i][k]+c[k][j];
		
	}
}

int main(void){
	cin >> h >>w;
	for(int i=0;i<10;i++) for(int j=0;j<10;j++) cin >> c[i][j];
	wf();
	int ans =0;
	for(int i=1;i<=h;i++) for(int j=1;j<=w;j++){
		 int tmp;
		 cin >> tmp;
		 //cout << tmp;
		 if(tmp!=-1)ans+=c[tmp][1]; 
	}

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


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

# define ll long long 
# define VI vector<int>
# define VL vector<ll>
# define PII pair<int,int> 
# define VII vector<PII>
# define mp make_pair
# define pb push_back
# define PI acos(-1)
# define ld long double
# define FOR(i,a,b) for(int i = a ; i < b ; ++i) 
const ll inf = 1e18 ; 
ll n , p ; 




void solve() {

	cin >> n >> p ; 
	if(n == 1) {
		cout << p ; 
		return ; 
	}
	ll ans = 1 ; 
	for(ll i = 2 ; i <= sqrt(p) ; ++i) { 
		if(p%i == 0 ) {
			ll copy = p ; 
			ll cnt = 0 ; 
			bool ok = true ; 
			while(copy) {
				if(copy % i != 0 ) {
					ok = false ;
					break  ; 
				}
				copy /= i ; 
				cnt++;
				if(cnt == n)
					break ; 
			}
			if(ok && cnt == n)  
				ans = max(ans, i) ; 
		}
	}
	cout << ans ; 
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL) ; 
	
	int  t =1; 
	//cin >> t ; 
	while(t--)
		solve() ; 
	return 0 ; 
}



Measured memory_bytes: 3676
import java.util.Scanner;

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

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

        System.out.println(solve(A, B));

        sc.close();
    }

    static String solve(int A, int B) {
        if (A == 1) {
            A += 13;
        }
        if (B == 1) {
            B += 13;
        }

        if (A < B) {
            return "Bob";
        } else if (A > B) {
            return "Alice";
        } else {
            return "Draw";
        }
    }
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
int main(){
  char a[3][3];
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin >> a[i][j];
      if(i==j) cout << a[i][j];
    }
  }
  cout << endl;

}


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

int main(){
  int A,B,C;
  cin >> A >> B >> C;
  long long int x=0;
  bool res=false;
  for(int i=0; i<B+1; ++i){
    x= A*i%B;
    if(x==C){
      res=true;
      break;
    }
    else{
      res=false;
    }
  }
  if(res==true){
    cout << "YES"<<endl;
  }
  else{cout << "NO"<<endl;}
  }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pii>
#define gr vector<vpii>
#define fi first
#define se second
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define GAME_OVER return 0
#define MOD (int)(1E9 + 7)
using namespace std;
int mul(int a, int b)
{
    return a * b % MOD;
}
int add(int a, int b)
{
    return (a + b) % MOD;
}
int sub(int a, int b)
{
    return (a - b + MOD) % MOD;
}
int fac(int n)
{
    int res = 1;
    for (int i = 2; i <= n; i++)
        res = mul(res, i);
    return res;
}
int binpow(int a, int b)
{
    int res = 1;
    while (b)
    {
        if (b % 2)
            res = mul(res, a);
        a = mul(a, a);
        b /= 2;
    }
    return res;
}
int inv(int a)
{
    return binpow(a, MOD - 2);
}
int divide(int a, int b)
{
    return mul(a, inv(b));
}
int cnk(int n, int k)
{
    int x = 1, y = 1;
    for (int i = 0; i < k; i++)
        x = mul(x, n - i);
    for (int i = 1; i <= k; i++)
        y = mul(y, i);
    return divide(x, y);
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, a, b;
    cin >> n >> a >> b;
    cout << sub(sub(binpow(2, n), 1), add(cnk(n, a), cnk(n, b))) << endl;
    GAME_OVER;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      if(N % 1000 == 0){
        System.out.println(0);
      }else{
        System.out.println((N / 1000 + 1)*1000 - N);
      }
    }
}
      

Measured memory_bytes: 35784
k=int(input())
a=list(map(int,input().split()))
l=2
h=2
for i in a[::-1]:
    tl=i*-(-l//i)
    th=i*(h//i)
    if tl>h or th<l:
        print(-1)
        quit()
    else:
        l=tl
        h=th+i-1
print(l,h)

Measured memory_bytes: 14224
#include <stdio.h>

int a, b, c, x, y, ab=0, m;
long long s1=0, s2=0, mini;


int main(){
    scanf("%d %d %d %d %d", &a, &b, &c, &x, &y);
    mini = (a*x) + (b*y);
    if(x<y) m=y;
    else    m=x;

    for(int i=0; i<=m; i++){
        if(x < 0) x=0;
        if(y < 0) y=0;
        s1 =(x*a)+(y*b)+(ab*c);

        if(s1 < mini)
            mini = s1;
        x-=1; y-=1; ab+=2;
    }
    printf("%lld\n", mini);
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound

int main(){
  string S;
  cin>>S;
  if((S.size()%2&&S[0]==S[S.size()-1])||(S.size()%2==0&&S[0]!=S[S.size()-1])) cout<<"Second"<<endl;
  else cout<<"First"<<endl;
}

Measured memory_bytes: 512
c_11, c_12, c_13 = [int(c) for c in input().split()]
c_21, c_22, c_23 = [int(cc) for cc in input().split()]
c_31, c_32, c_33 = [int(ccc) for ccc in input().split()]
if c_11 + c_22 == c_12 + c_21 and c_11 + c_33 == c_13 + c_31 and c_22 + c_33 == c_23 + c_32:
  print("Yes")
else:
  print("No")

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

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int&v : a) cin >> v;
  for (int&v : b) cin >> v;
  int ans = 1e9;
  for (int m = 0; m < 1<<n; m++) {
    vector<pair<int,int>> x, y;
    for (int i = 0; i < n; i++) {
      if (m>>i&1) {
	(i%2?x:y).emplace_back(b[i], i);
      } else {
	(i%2?y:x).emplace_back(a[i], i);
      }
      if (x.size() == (n+1)/2) {
	sort(x.begin(), x.end());
	sort(y.begin(), y.end());
	vector<int> v(n), p(n);
	for (int i = 0; i < x.size(); i++)
	  tie(v[i*2], p[i*2]) = x[i];
	for (int i = 0; i < y.size(); i++)
	  tie(v[i*2+1], p[i*2+1]) = y[i];
	int ok = 1;
	for (int i = 1; i < n; i++)
	  if (v[i] < v[i-1]) ok = 0;
	if (!ok) continue;
	int inversions = 0;
	for (int i = 0; i < n; i++)
	  for (int j = 0; j < i; j++)
	    inversions += p[j] > p[i];
	ans = min(ans, inversions);
      }
    }
  }
  if (ans == 1e9) ans = -1;
  cout << ans << endl;
}


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

int N,M;
int NN;
int *dd;
int *d;

int search(int var)
{
	int i = 0, j = NN-1;
	int cut;

	while(i != j){
		cut = (i+j)/2;
		if(dd[cut] + var > M){
			j = cut;
		}
		else if(dd[cut] + var < M){
			i = cut+1;
		}
		else
			return dd[cut] + var;

	}

	if(var + dd[cut] <= M)
		return dd[cut] + var;

	return -1;
}
int main(void)
{


	while(	cin >> N >> M, N && M){

	NN = (N+1) * (N+1);
	d = new int [N+1];
	dd = new int [NN];

	d[0] = 0;

	for(int i = 1; i <= N; i++)
		cin >> d[i];

	int c = 0;
	for(int i = 0; i <= N; i++)
		for(int j = 0; j <= N; j++,c++)
			dd[c] = d[i] + d[j];

	sort(dd,dd+NN);

	c = 0;
	int num = 0;
	int MAX = 0;

	for(int i = 0; i < NN; i++){
		if(dd[i] > M)
			break;

		num = search(dd[i]);

		if(num > MAX)
			MAX = num;
	}
	cout << MAX << endl;
		

	delete [] d;
	delete [] dd;
	}
	return 0;
}

Measured memory_bytes: 5400
import bisect
n=int(input())
if n==1:
    print(0)
    exit()
def 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 ra(a):
    ll,l=[],1
    for i in range(len(a)-1):
        if a[i]==a[i+1]:
            l+=1
        else:
            ll.append(l)
            l=1
    ll.append(l)
    return ll
l=ra(factorize(n))
c=[1]
for i in range(2,10**4):
    c.append(i+c[-1])
ans=0
for i in l:
    ans+=bisect.bisect_left(c,i)
    if i in set(c):
        ans+=1
print(ans)

Measured memory_bytes: 10088
import std.algorithm;
import std.bigint;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(string S) {
    return S.map!(s => "ACGT".canFind(s))
        .group
        .filter!"a[0]"
        .map!"a[1]"
        .chain([0])
        .reduce!max;
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    string S;
    S = input.front.to!string;
    input.popFront;

    static if (is(ReturnType!solve == void))
        solve(S);
    else
        solve(S).writeln;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    char c;
    cin >> c;
    if(c =='a' || c=='i' || c=='u' || c=='e' || c=='o'){
        cout << "vowel" << endl;
    }
    else{
        cout << "consonant" << endl;
    }
}

Measured memory_bytes: 256
gets
current = [0, 0, 0]
ARGF.each do |line|
  t, x, y = line.split.map(&:to_i)
  d = (current[1] - x).abs + (current[2] -y).abs 
  if t - current[0] < d
	  puts 'No'
  	  exit
  else
    unless t.even? == (x + y).even?
      puts 'No'
      exit
    end
  end
end
puts 'Yes'

Measured memory_bytes: 1788
package main 
import (
  "fmt"
  "os"
  "bufio"
  )

func main(){
    var c[3][3]string 
    scanner := bufio.NewScanner(os.Stdin)
    count := 0
    for scanner.Scan() { 
        line := scanner.Text()
        c[count][0] = string(line[0])
        c[count][1] = string(line[1]) 
        c[count][2] = string(line[2])
        count++
        if count == 3 {
            break
        }
    } 
    ans := c[0][0] + c[1][1] + c[2][2]
    fmt.Println(ans) 
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int INF = 1000100000;
#define rep(i,n) for(int i=0;i<n;++i)

int main(){
  ll n;
  cin >>n;
  int s[n];
  int ans=0;
  rep(i,n){
    cin >> s[i];
    ans+=s[i];
  }
  sort(s,s+n);
  if(ans%10!=0)cout << ans << endl;
  else{
    int hiku=0;
    rep(i,n){
      if(s[i]%10!=0){
        hiku=s[i];
        break;
      }
    }
    if(hiku==0)ans=0;
    else ans-=hiku;
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int X;
  int N;
  set<int> S;
  cin >> X >> N;
  
  int ans = X;
  
  int a;
  
  for(int i=0;i<N;i++){
    cin >> a;
    S.insert(a);
  }
  
  for(int i=0;i<100;i++){
    if(N==0){
      break;
    }
    if(!(S.count(X - i))){
      ans = X - i;
      break;
    }
    if(!(S.count(X + i))){
      ans = X  + i;
      break;
    }
  }
  cout << ans << endl;
}

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

#define st first
#define nd second
#define all(x) (x).begin(), (x).end()

using namespace std;
using namespace placeholders;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <class T> void mini(T &l, T r){l = min(l, r);}
template <class T> void maxi(T &l, T r){l = max(l, r);}

template <class TH> void _dbg(const char *sdbg, TH h){cerr << sdbg << "=" << h << "\n";}
template <class TH, class ...TA> void _dbg(const char *sdbg, TH h, TA... a){
	while (*sdbg != ','){cerr << *sdbg++;}cerr << "=" << h << ","; _dbg(sdbg + 1, a...);
}
template <class T> ostream &operator <<(ostream &os, vector<T> V){
	os << "["; for (auto vv: V) os << vv << ","; return os << "]";
}
template <class L, class R> ostream &operator <<(ostream &os, pair<L, R> P){
	return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef SFIC
	#define eput(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
	#define eput(...) 218
#endif

int main(){
	int cas;
	scanf("%d", &cas);
	for (int casi = 1; casi <= cas; ++casi){
		ll A, B, C, D;
		scanf("%lld%lld%lld%lld", &A, &B, &C, &D);
		if (A < B || B > D)
			puts("No");
		else{
			ll E = __gcd(B, D);
			ll t = ((A - C - 1) % E + E) % E + 1;
			puts(B > C + t ? "No" : "Yes");
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

int main(){
    int n, a;
    std::cin >> n >> a;
    n %= 500;
    if(n <= a) std::cout << "Yes";
    else std::cout << "No";
}


Measured memory_bytes: 256
import java.util.*;


public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = Integer.parseInt(sc.nextLine());
        int a = sc.nextInt();
        int b = sc.nextInt();

        for(int i = a ; i<=b ; i++){
            if(i % k == 0){
                System.out.println("OK");
                System.exit(0);
            }
        }
        System.out.println("NG");
        System.exit(0);

    }
}

Measured memory_bytes: 35944
package main

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

func main() {
	nm := nextIntArray()
	n, m := nm[0], nm[1]
	if n >= m {
		fmt.Println(0)
		return
	}
	x := nextIntArray()
	sort.Ints(x)
	for i := 1; i < m; i++ {
		x[i-1] -= x[i]
	}
	for i := 0; i < m; i++ {
		if x[i] < 0 {
			x[i] = -x[i]
		}
	}
	x = x[:len(x)-1]
	sort.Ints(x)
	cnt := 0
	for _, v := range x[:m-n] {
		cnt += v
	}
	fmt.Println(cnt)

}

func lcm(a, b int64) int64 {
	return (a / gcd(a, b)) * b
}

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

const size = 1000000

var reader = bufio.NewReaderSize(os.Stdin, size)

func nextLine() string {
	var line, buffer []byte
	isPrefix := true
	var err error
	for isPrefix {
		line, isPrefix, err = reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
	}
	return string(buffer)
}
func nextStringArray() []string {
	return strings.Split(nextLine(), " ")
}
func nextInt() int {
	n, _ := strconv.Atoi(nextLine())
	return n
}

func nextIntArray() []int {
	s := strings.Split(nextLine(), " ")
	n := len(s)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i], _ = strconv.Atoi(s[i])
	}
	return a
}

func min(i, j int) int {
	if i > j {
		return j
	}
	return i
}

func max(i, j int) int {
	if i < j {
		return j
	}
	return i
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(_v) for(auto _x:_v){cout<<_x<<" ";}cout<<endl
#define printVS(_vs) for(auto _x : _vs){cout << _x << endl;}
#define printVV(_vv) for(auto _v:_vv){for(auto _x:_v){cout<<_x<<" ";}cout<<endl;} cout << endl;
#define printP(_p) cout << _p.first << " " << _p.second << endl
#define printVP(_vp) for(auto _p : _vp) printP(_p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;
typedef vector<vector<int>> Graph;

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

    int x;
    cin >> x;
    cout << (1ll << (x + 2)) - 2 << endl;
}


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

int is_n = 0;
int is_s = 0;
int is_w = 0;
int is_e = 0;

int main() {
	string s;
	
	cin >> s;
	for (int i = 0; i < s.length(); i++) {
		is_n |= (s[i] == 'N');
		is_s |= (s[i] == 'S');
		is_w |= (s[i] == 'W');
		is_e |= (s[i] == 'E');
	}
	if ((is_n + is_s) % 2 == 0 && (is_w + is_e) % 2 == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
map<string ,int>m;
cin>>n;
for(int i=0;i<n;i++)
{
  string x;
  cin>>x;
  m[x]++;

}
int mm;
cin>>mm;
for(int i=0;i<mm;i++)
{
string x;
cin>>x;
if(m[x])
{
  m[x]--;
}
}
int ans=0;
for(auto it=m.begin();it!=m.end();it++)
{
    if(ans<it->second)
    {
      ans=it->second;
    }
}
cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>
 
 
#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s
 
typedef long long ll;
 
using namespace std;

ll modd = 1000*1000*1000+7;

ll binary_search(function<bool(ll)> func, ll start, ll end) {
    /*      func:int ->bool
            returns smallest int x where func(x) evaluates to true, searches in [start,end), it is assumed the values are false, .. , false, true ...
             */
    if (end <= start) {   return end;  }   // has to be here, otherwise func(end-1) in next line could be a problem
    if (!func(end-1)) {  return end;  }
    while (end-start>1) {
        ll mid = (start+end)/2;
        if (func(mid)) {  end = mid;  } else { start = mid;   }
    }
    if (func(start)) {  return start;  } else {  return end;   }
}; 


int main()   {

    ios_base::sync_with_stdio(false);

    cout.precision(17);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no
 
//    auto start = chrono::steady_clock::now();
  
//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readint(h); readint(a);
        cout << 1 + h/a - (h%a==0) << endl;
    }
 
//    auto end = chrono::steady_clock::now();
//    cout << chrono::duration_cast<chrono::milliseconds>(end - start).count() << endl;
 
    return 0;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <numeric>
#include <complex>

using namespace std;

typedef long long ll;

#define mp make_pair
#define pb push_back
#define PI 3.1415926535897932384626433832795

#define fill(x, v)  fillchar(x, v, sizeof(x))
typedef pair<int, int>  pii;
typedef vector<int>     vi;
typedef vector< pii >   vpii;

int tc;

#define MAXN 100500
ll f[MAXN];
int n, v, w, W;

int main() {
    scanf("%i%i", &n, &W);
    for(int i = 0; i < n; ++i) {
        scanf("%i%i", &w, &v);
        for(int j = W; j >= w; --j)
            if (f[j] < f[j - w] + v) f[j] = f[j - w] + v;
    }


    printf("%lld\n", f[W]);
    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(void)
{
	char s[200001];
	int i,len,sum=0,ama=0;
	scanf("%s",s);
	len=strlen(s);
	for(i=0;i<len;i++){
		sum+=s[i]-'0';
	}
	if(sum%9==0){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}
	

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

int main(){
    int n;
    string ans="YES";
    cin>>n;
    int f=0;
    for(int i=0;i<n;++i){
        char p;
	int x;
	cin>>p>>x;
	if(p=='(')f+=x;
	else f-=x;
	if(f<0)ans="NO";
    }
    if(f>0)ans="NO";
    cout<<ans<<endl;
return 0;
}



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

int main(void)
{
	int n, m, s, g1, g2;
	int data[128][128];
	int a, b, c;
	
	while (scanf("%d %d %d %d %d", &n, &m, &s, &g1, &g2), n){
		for (int i = 0; i < 128; i++){
			for (int j = 0; j < 128; j++){
				if (i == j) data[i][j] = 0;
				else data[i][j] = 10000000;
			}
		}
		
		for (int i = 0; i < m; i++){
			cin >> a >> b >> c;
			data[a-1][b-1] = c;
		}
		
		// わーしゃるふろいど
		for (int k = 0; k < n; k++){
			for (int i = 0; i < n; i++){
				for (int j = 0; j < n; j++){
					data[i][j] = min(data[i][j], data[i][k] + data[k][j]);
				}
			}
		}
		
		int ret = 10000000;
		for (int i = 0; i < n; i++){
			ret = min(ret, data[s - 1][i] + data[i][g1 - 1] + data[i][g2 - 1]);
		}
		cout << ret << endl;
	}
	
	
	return 0;
}

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

typedef long long ll;

int main() {
    ll x;
    cin >> x;
    ll q = x / 11, r = x % 11;
    if (r == 0) cout << q * 2 << "\n";
    else if (r < 7) cout << q * 2 + 1 << "\n";
    else cout << q * 2 + 2 << "\n";
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 123456;
char s[MAXN];

int main() {
    scanf("%s", s);
    int N = strlen(s);
    int ans = N;
    for (int i = 1; i < N; i++) {
        if (s[i] == s[i - 1]) continue;
        int x = i, y = (N - i);
        x = max(x, y);
        ans = min(ans, x);
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    if (fopen("Test.INP", "r"))
        freopen("Test.INP", "r", stdin);

    int n;
    cin >> n;

    int a[n];
    for (int i = 0; i < n; ++i)
        cin >> a[i];

    int dp[n];
    dp[0] = 0;

    for (int i = 1; i < n; ++i)
    {
        dp[i] = dp[i - 1] + abs(a[i] - a[i - 1]);
        if (i > 1)
            dp[i] = min(dp[i], dp[i - 2] + abs(a[i] - a[i - 2]));
    }

    cout << dp[n - 1];
    return 0;
}


Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define RREP(i,a,b) for (int i = a; i > (b); --i)
#define all(x) (x).begin(),(x).end()
#define YY cout << "Yes" << endl
#define NN cout << "No" << endl
const int INF = 1000000007;
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
int solve(){
  int n,x;
  ll ans = 0;
  cin>>n>>x;
  vector<int>v(n);
  rep(i,n)cin >> v[i];
  REP(i,1,n){
    ll tmp = v[i] + v[i - 1];
    if(tmp <= x)continue;
    ll down = tmp - x;
    ans += down;
    if(down > v[i])v[i] = 0;
    else v[i] -= down;
  }
  cout << ans << endl;
  return 0;
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16);
  solve();
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;

signed main(){
	int n, m; cin >> n >> m;
	vector<int> cost(m);
	vector<vector<int> > data(m);
	for(int i = 0; i < m; i++){
		int x; scanf("%d%d", &cost[i], &x);
		for(int j = 0; j < x; j++){
			int y; scanf("%d", &y); data[i].push_back(y - 1);
		} 
	}
	vector<int> dp(1 << n, INF);
	dp[0] = 0;
	for(int bit = 0; bit < (1 << n); bit++){
		for(int j = 0; j < m; j++){
			int num = bit;
			for(int k = 0; k < data[j].size(); k++) num = num | (1 << data[j][k]);
		  dp[num] = min(dp[num], dp[bit] + cost[j]);
		}
	}
	int ans = dp[(1 << n) - 1];
	if(ans == INF) cout << -1 << endl;
	else cout << ans << endl;
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

int main() {
    li a, b, c, k;
    cin >> a >> b >> c >> k;
    li res = 0;
    if (k <= a) {
        cout << k << endl;
        return 0;
    }
    k -= a;
    res = a;
    if (k <= b) {
        cout << res << endl;
        return 0;
    }
    k -= b;
    cout << res - k << endl;


    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <climits>
using namespace std;

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

    vector<int> parent(n, -1);
    queue<int> q;
    q.push(0);

    while (not q.empty()) {
        int x = q.front();
        q.pop();

        for (int next : v[x]) {
            if (parent[next] < 0) {
                parent[next] = x;
                q.emplace(next);
            }
        }
    }

    bool flag = false;
    for (int i = 1; i < n; i++) {
        if (parent[i] < 0) flag = true;
    }
    if (flag)
        cout << "No" << endl;
    else {
        cout << "Yes" << endl;
        for (int i = 1; i < n; i++) {
            cout << parent[i] + 1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 10084
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
  lint n;
  cin >> n;
  lint a, b;
  cin >> a >> b;
  if ((b - a) % 2 == 0) {
    cout << (b - a) / 2 << endl;
  } else {
    cout << (b - a - 1) / 2 + 1 + (n - b <= a - 1 ? n - b : a - 1) << endl;
    }
  return 0;
}


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

int main(){
	int n, m, nonw[60] = {}, nonb[60] = {}, nonr[60] = {};
	int ans = 2000000000;
	string flag[60];
	cin >> n >> m;
	for(int i = 0;i<n;i++){
		cin >> flag[i];
		for(int j = 0;j<m;j++){
			if (flag[i][j] != 'W') nonw[i]++;
			if (flag[i][j] != 'B') nonb[i]++;
			if (flag[i][j] != 'R') nonr[i]++;
		}
		nonw[i + 1] += nonw[i];
		nonb[i + 1] += nonb[i];
		nonr[i + 1] += nonr[i];
	}
	for(int i = 0;i<n-2;i++){
		for(int j = i+1;j<n-1;j++){
			int tmp = nonw[i] + nonb[j] - nonb[i] + nonr[n] - nonr[j];
			ans = min(ans, tmp);
		}
	}
	cout << ans << endl;
return 0;
}

Measured memory_bytes: 3200
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var input = int.Parse(Console.ReadLine());
        var array = Console.ReadLine().Split(' ');

        var list = new List<long>();

        for(var i = 1; i < array.Length + 1; i++)
        {
            var n = long.Parse(array[i - 1]);
            list.Add(n - i);
        }

        list.Sort();
        long mid = 0;
        if (input % 2 == 0)
        {
            mid = list[input / 2 - 1];
        }
        else
        {
            mid = list[(input + 1) / 2 - 1];

        }

        var ansList = new List<long>();
        foreach (var n in list)
        {
            ansList.Add(Math.Abs(n - mid));
        }

        Console.WriteLine(ansList.Sum());


        Console.ReadLine();

    }

  
}


Measured memory_bytes: 34368
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int d[50][50];
const int dx[] = {0,1,0,-1};
const int dy[] = {1,0,-1,0};
int main() {
  int h,w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  rep(i,h)rep(j,w) d[i][j] = 1e9;

  queue<P> q;
  auto push = [&](int i,int j,int nd){
    if(i<0||h<=i||j<0||w<=j) return;
    if(s[i][j]=='#') return;
    if(d[i][j]<=nd) return;
    d[i][j] = nd;
    q.emplace(i,j);
  };
  push(0,0,1);
  while(!q.empty()){
    P p = q.front(); q.pop();
    int i = p.first, j = p.second;
    rep(x,4) push(i+dx[x],j+dy[x],d[i][j]+1);
  }
  if(h*w < d[h-1][w-1]){
    cout << -1 << endl;
  }else{
    int ans = 0;
    rep(i,h)rep(j,w)if(s[i][j]=='.') ++ans;
    ans -= d[h-1][w-1];
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
date0=input().rstrip().split(" ")
N=int(date0[0])
M=int(date0[1])
date1=input().rstrip().split(" ")
list0=[]
for i in range(N):
    list0.append(0)
for j in range(M):
    date=input().rstrip().split(" ")
    A=int(date[0])
    B=int(date[1])
    if int(date1[A-1])==int(date1[B-1]):
        list0[A-1]=1
        list0[B-1]=1
    elif int(date1[A-1])>int(date1[B-1]):
        list0[B-1]=1
    else:
        list0[A-1]=1
print(list0.count(0))

Measured memory_bytes: 18456
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a.at(i);
    sort(a.begin(), a.end(), greater<int>());
    int diff = 0;
    if (n % 2) {
        diff = a.back();
        a.pop_back();
    }
    for (int i = 0; i < a.size() / 2; i++) {
        diff += (a.at(i * 2) - a.at(i * 2 + 1));
    }
    cout << diff << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stdio.h>
#define REP(i, n) for(int i = 0;i < n;i++)

using namespace std;

static const int N = 100;
static const int INFTY = (1 << 21);

int n, M[N][N];
int d[N];

void bfs(int s)
{
	queue<int>	q;
	q.push(s);
	REP(i, n)
		d[i] = INFTY;
	d[s] = 0;
	int u;

	while (!q.empty())
	{
		u = q.front();
		q.pop();
		REP(v, n)
		{
			if (M[u][v] == 0)
				continue;
			if (d[v] != INFTY)
				continue;
			d[v] = d[u] + 1;
			q.push(v);
		}
	}
	REP(i, n)
		cout << i + 1 << " " << ((d[i] == INFTY) ? (-1) : d[i]) << endl;
}

int main()
{
	int u, k, v;

	cin >> n;

	REP(i, n)
	{
		REP(j, n)
			M[n][n] = 0;
	}

	REP(i, n)
	{
		cin >> u >> k;
		u--;
		REP(j, k)
		{
			cin >> v;
			v--;
			M[u][v] = 1;
		}
	}



	bfs(0);
	return 0;
}

Measured memory_bytes: 3148
#include<cstdio>
#include<algorithm>
int a[1001]; 
int main()
{
	int n,i,k,ans=0;
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;i++)scanf("%d",&a[i]);
	std::sort(a+1,a+1+n);
	for(i=n;i>=n-k+1;i-- )ans+=a[i];
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.Stack;

public class Main
{
    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        Stack<String> stack = new Stack<String>();
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String line = "";
        try
        {
            line = br.readLine();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }

        String[] s = line.split(" ");

        for (int i = 0; i < s.length; i++)
        {
            if ("+".equals(s[i]))
            {
                int op1 = Integer.parseInt(stack.pop());
                int op2 = Integer.parseInt(stack.pop());
                stack.push(Integer.toString((op1 + op2)));
            }
            else if ("-".equals(s[i]))
            {
                int op1 = Integer.parseInt(stack.pop());
                int op2 = Integer.parseInt(stack.pop());
                stack.push(Integer.toString((op2 - op1)));
            }
            else if ("*".equals(s[i]))
            {
                int op1 = Integer.parseInt(stack.pop());
                int op2 = Integer.parseInt(stack.pop());
                stack.push(Integer.toString((op1 * op2)));
            }
            else
            {
                stack.push(s[i]);
            }
        }

        System.out.println(stack.pop());
        scan.close();
    }

}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>=0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define ll long long
const int mod=1e9+7;
const ll MX=1<<30;

ll powmod(ll n,ll k){
    if (k==0) return 1;
    else if (k%2==0){
        ll tmp=powmod(n,k/2);
        return tmp*tmp%mod;
    }
    else return powmod(n,k-1)*n%mod;
}

int n,a,b,c,d;
ll dp[1005][1005];
ll fact[1005],fact1[1005][1005],fact2[1005];
ll comb[1005][1005];

signed main()
{
    scanf("%d%d%d%d%d", &n, &a, &b, &c, &d);
    rep(i,n+1){
        dp[i][0]=1;
    }
    fact[0]=1;
    rep2(i,1,n+1){
        fact[i]=fact[i-1]*i%mod;
        fact2[i]=powmod(fact[i],mod-2);
    }
    rep2(i,1,n+1){
        rep(k,n+2){
            fact1[i][k]=powmod(fact[i],(mod-2)*k);
        }
    }
    comb[0][0]=1;
    rep2(i,1,n+1){
        comb[i][0]=1;
        rep2(j,1,n+1){
            comb[i][j]=(comb[i-1][j-1]+comb[i-1][j])%mod;
        }
    }
    rep2(i,1,n+1){
        if(i<a) continue;
        rep2(j,1,n+1){
            if(j<a) continue;
            rep(k,j/i+1){
                if(d<k) break;
                if((c<=k&k<=d)&(a<=i&i<=b)){
                    ll tmp=fact1[i][k]*fact2[k]%mod;
                    dp[i][j]+=comb[n-j+i*k][i*k]*fact[i*k]%mod*tmp%mod*dp[i-1][j-i*k]%mod;
                    dp[i][j]%=mod;
                }
                else if(k==0){
                    dp[i][j]+=dp[i-1][j];
                    dp[i][j]%=mod;
                }
            }
        }
    }
    printf("%lld\n", dp[n][n]);
}


Measured memory_bytes: 23808
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
 
int main()
{
  int n,x,t;
  cin >> n >> x >> t;
  int quo;
  quo = (n+x-1) / x;
  cout << quo * t;
  
  return 0;
}

Measured memory_bytes: 3592
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let 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")
    };
}

#[allow(unused_imports)]
use std::{i32, i64, u32, u64, usize, f64};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{VecDeque, HashMap, BTreeMap, HashSet, BTreeSet};
#[allow(unused_imports)]
use std::io::{stdout, Write, BufWriter};
#[allow(unused_imports)]
use std::mem::{swap};

fn main() {
    input! {
        n: u32,
        m: usize,
        sc: [(u32, i32); m],
    }
    if m == 0 {
        if n == 1 {
            println!("{}", 0);
            return;
        } else {
            println!("{}", 10i32.pow(n - 1));
            return;
        }
    }
    let mut sc = sc;
    sc.sort();
    sc.dedup();
    let m = sc.len();
    if (0..(m - 1)).any(|i| sc[i].0 == sc[i + 1].0 )
        || (n != 1 && sc[0] == (1, 0)) {
        println!("-1");
        return;
    }
    if n == 1 {
        println!("{}", sc[0].1);
        return;
    }
    let mut ans = 0;
    for (s , c) in sc { ans += c * 10i32.pow(n - s); }
    if ans < 10i32.pow(n - 1) { println!("{}", ans + 10i32.pow(n - 1)) }
    else { println!("{}", ans) }
}


Measured memory_bytes: 4352
import java.util.Scanner

trait Reader {
  val scanner = new Scanner(System.in)
}

object Main extends App with Reader {

  val a = scanner.nextInt()
  val b = scanner.nextInt()
  val c = scanner.nextInt()

  val answer = Seq(a, b, c).foldLeft(Map[Int, Int]()) { (acc, element) =>
    acc.updated(element, acc.getOrElse(element, 0) + 1)
  }.minBy(_._2)._1

  println(answer)
}

Measured memory_bytes: 25656
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<map>

using namespace std;

int mini = 1<<21;
int ans = 0;
int n;
int x;

int main(){
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> x;
        if(mini >= x){
            mini = x;
            ans ++;
        }
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
M=10**9+7
f=[1]
for j in range(1,10**6):f+=f[-1]*j%M,
i=[pow(f[-1],M-2,M)]
for j in range(1,10**6)[::-1]:i+=i[-1]*j%M,
x,y=map(int,input().split())
n,m=divmod(x+y,3)
print((m<1)*(x*2>=y)*(y*2>=x)*f[n]*i[~n-n+y]*i[~y+n]%M)

Measured memory_bytes: 122296
#include <iostream>
#include <stdio.h>
#include <string>

#define MAX_N 100'000

using namespace std;

int C[MAX_N]{};

int main() {
  string S;
  cin >> S;
  int i = 0;
  int N = S.size();
  while (i < N) {
    int cnt = 0;
    while (i < N && S[i] == 'R') {
      ++i;
      ++cnt;
    }
    C[i - 1] += cnt / 2 + (cnt % 2 != 0);
    C[i] += cnt / 2;
    while (i < N && S[i] == 'L') {
      ++i;
    }
  }
  i = N - 1;
  while (i >= 0) {
    int cnt = 0;
    while (i >= 0 && S[i] == 'L') {
      --i;
      ++cnt;
    }
    C[i + 1] += cnt / 2 + (cnt % 2 != 0);
    C[i] += cnt / 2;
    while (i >= 0 && S[i] == 'R') {
      --i;
    }
  }
  for (int i = 0; i < N; ++i) {
    printf("%d\n", C[i]);
  }
}

Measured memory_bytes: 3668
// Aizu 2199: Differential Pulse Code Modulation
// 2017.9.21 bal4u@uu
// 2017.12.10

#include <stdio.h>
#include <string.h>

#define INF   0x1fffffff
int code[18];				// code book
int dp[20001][257];			// Sum of Squares
int x2[256][256];

char buf[15], *p;
int getsint()
{
	int n = 0;
	if (*p == '-') {
		p++; while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
		return -n;
	}
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int main()
{
	int n, m, i, j, k, x, s, t, ans;

	for (i = 0; i < 256; i++) for (j = 0; j < 256; j++) x2[i][j] = (i-j)*(i-j);

	while (fgets(p=buf, 15, stdin) && *p != '0') {
		n = getint(), p++, m = getint();

		for (j = 0; j < m; j++) fgets(p=buf, 10, stdin), code[j] = getsint();

		memset(dp, 0x33, sizeof(dp));
		dp[0][128] = 0;

		for (k = 0; k < n; k++) {
			fgets(p=buf, 10, stdin), x = getint();
			for (i = 0; i < 256; i++) {
				if (dp[k][i] > INF) continue;
				for (j = 0; j < m; j++) {
					t = i + code[j];
					if (t < 0) t = 0;
					if (t >= 256) t = 255;
					s = x2[t][x] + dp[k][i];
					if (s < dp[k+1][t]) dp[k+1][t] = s;
				}
			}
		}

		for (ans = INF, i = 0; i < 256; i++) if (dp[n][i] < ans) ans = dp[n][i];
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 22016
import java.io.PrintWriter
import java.util.*
import java.math.*
import java.lang.*
import kotlin.comparisons.*

val pw = PrintWriter(System.out)
val MOD: Long = (1e+9 + 7).toLong()

data class Job(val a: Int, val b: Int)

fun main(args: Array<String>) {
    val (n, m) = readListOfInt()    

    val jobs = (0 until n).map { 
        val (a, b) = readListOfInt()
        Job(a, b)
    }.sortedBy { it.a }

    var ans = 0L
    var jobIdx = 0
    val que = PriorityQueue<Int>(1, compareByDescending { it })
    for(day in 1..m) {
        while(jobIdx < n && jobs[jobIdx].a <= day) {
            que.add(jobs[jobIdx].b)
            jobIdx++
        }
        ans += que.poll()?: 0
    }

    println(ans)

    pw.flush()
}

/****** Declared Functions and Data Structures ******/
// IO
fun read() = readLine()!!
fun readInt() = read().toInt()
fun readLong() = read().toLong()
fun readDouble() = read().toDouble()
fun readListOfString() = read().split(" ")
fun readListOfInt() = readListOfString().map { it.toInt() }
fun readListOfLong() = readListOfString().map { it.toLong() }
fun readListOfDouble() = readListOfString().map { it.toDouble() }

fun Double.format(digits: Int) = String.format("%.${digits}f", this)
fun Float.format(digits: Int) = String.format("%.${digits}f", this)

fun print(value: Any) { pw.print(value) }
fun println(value : Any) { pw.println(value) }

fun<T> permutations(src: List<T>): List<List<T>> {
    if(src.size == 1) return listOf(src)
    val perms = mutableListOf<List<T>>()
    val insertElement = src[0]
    permutations(src.drop(1)).forEach { perm ->
        for(i in 0..perm.size) {
            val newPerm = perm.toMutableList()
            newPerm.add(i, insertElement)
            perms.add(newPerm.toList())
        }
    }
    return perms
}

// return nCr, if you want nCr, please access v[n][r]
fun combinations(n: Long): List<List<Long>> {
    val v = (0..n).map { (0..n).map{0L}.toMutableList() }.toMutableList()
    for(i in 0 until v.size) {
        v[i][0] = 1L
        v[i][i] = 1L
    }
    for(i in 0 until v.size) {
        for(j in 1 until i) {
            v[i][j] = (v[i-1][j-1] + v[i-1][j]) % MOD
        }
    }
    return v.map { it.toList() }.toList()
}

// should be a >= b
fun gcd(a: Long, b: Long): Long = 
    if(b == 0L) a else gcd(b, a % b)

// shoud be a >= b
fun lcm(a: Long, b: Long): Long = 
    a / gcd(a, b) * b

fun sumDigits(num_: Long): Long {
    var num = num_
    var rtn: Long = 0
    while(num != 0.toLong()) {
        val tmp = num % 10
        rtn += tmp
        num /= 10
    }
    return rtn
}

fun isDecimal(v: Double): Boolean = ((v - Math.floor(v)) != 0.0)

// Data Structures
class Stack<T>(private var st: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = st.isEmpty()
    fun top(): T = st.last()
    fun push(e: T) { st.add(e) }
    fun pop() { st = st.dropLast(1).toMutableList() }
}

class Queue<T>(private var que: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = que.isEmpty()
    fun top(): T = que.first()
    fun push(e: T) { que.add(e) }
    fun pop() { que = que.drop(1).toMutableList() }
}


Measured memory_bytes: 75584
import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner in = new Scanner(System.in);
        long a = in.nextLong(), b = in.nextLong(), n = in.nextLong();
        if (b > n)
            System.out.println(a * n / b - a * (n / b));
        else {
            long i = n / b, x = i * b - 1;
            System.out.println(Math.max(a * n / b - a * (n / b), a * x / b - a * (x / b)));
        }
    }

}


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

int main() {
  vector<vector<char>> C(2, vector<char>(3));
  for (int i=0; i<2; i++) {
    for (int j=0; j<3; j++) {
      cin >> C[i][j];
    }
  }
  
  string ans = "YES";
  for (int i=0; i<3; i++) {
    if (C[0][i]!=C[1][2-i]) {ans="NO";}
  }
  cout << ans << endl;
}


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

int main() {
  int N;
  cin >> N ;
  vector<int> button(N);
  int fstBtn;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    a--;
    button.at(i) = a;
    
  }
  int cnt = 0;
  int push = 0;
  for (int i = 0; i < N; i++) {
    if (push == 1 ) {
      break;
    }
    if (i == N-1) {
      cnt = -1;
      break;
    }
    push = button.at(push);
    cnt ++;

  }
  cout << cnt << endl;
}


Measured memory_bytes: 640