akhauriyash/Code-Regression huggingface dataset:
class Dice 
    attr_reader :nums
    def initialize(nums)
        @nums = [nil] + nums
    end
    def top
        @nums[1]
    end
    def front
        @nums[2]
    end
    def right
        @nums[3]
    end
    def rollx
        @nums[1], @nums[2], @nums[6], @nums[5] = @nums[5], @nums[1], @nums[2], @nums[6]
        self
    end
    def rolly
        @nums[1], @nums[3], @nums[6], @nums[4] = @nums[4], @nums[1], @nums[3], @nums[6]
        self
    end
    def rollz
        @nums[2], @nums[3], @nums[5], @nums[4] = @nums[4], @nums[2], @nums[3], @nums[5]
        self
    end
    def moveN
        rollx.rollx.rollx
    end
    def moveS
        rollx
    end
    def moveE
        rolly
    end
    def moveW
        rolly.rolly.rolly
    end
    def move(m)
        case m
        when 'N' then moveN
        when 'S' then moveS
        when 'E' then moveE
        when 'W' then moveW
        end
    end
    def move_all
        moves = [
            # top:1 front:2
            :y, :rollz, :y, :rollz, :y, :rollz, :y, :rollz, :moveN,
            # top:2 front:6
            :y, :rollz, :y, :rollz, :y, :rollz, :y, :rollz, :moveW,
            # top:3 front:6
            :y, :rollz, :y, :rollz, :y, :rollz, :y, :rollz, :moveW,
            # top:5 front:6
            :y, :rollz, :y, :rollz, :y, :rollz, :y, :rollz, :moveW,
            # top:4 front:6
            :y, :rollz, :y, :rollz, :y, :rollz, :y, :rollz, :moveN,
            # top:6 front:3
            :y, :rollz, :y, :rollz, :y, :rollz, :y, :rollz,
        ]
        moves.each do |m|
            if m == :y
                yield self
            else
                self.send(m)
            end
        end
    end
end

nums1 = STDIN.gets.split.map(&:to_i)
nums2 = STDIN.gets.split.map(&:to_i)

dice1 = Dice.new(nums1)
dice2 = Dice.new(nums2)

results = []
dice1.move_all do |d|
    if d.nums == dice2.nums
        puts "Yes"
        exit
    end
end

puts "No"

Measured memory_bytes: 8752
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	ll n,h; cin>>n>>h;
	ll amax=0;
	vl vec(n+1);
	rep(i,0,n){
		ll a,b; cin>>a>>b;
		amax=max(amax,a);
		vec[i]=b;
	}
	sort(all(vec));
	//reverse(all(vec));
	
	ll d=0,ans=0;
	bool p=false;
	while(d<h){
		ll s=vec.size();
		ll k=vec[s-1];
		if(vec.empty() || amax>=k){
			p=true;
			break;
		}
		d+=k;
		vec.pop_back();
		++ans;
	}
	if(p){
		ll add=(h-d + amax - 1) / amax;
		ans+=add;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main () {
    ios_base::sync_with_stdio(false);
    string str;
    cin>>str;
    if(str[2] == str[3] && str[4] == str[5]) {
        cout<<"Yes"<<"\n";
    }
    else {
        cout<<"No"<<"\n";
    }
    return 0; 
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	vector<int>a(n); for(auto&&i:a)cin>>i;
	for(int i=1;i<n;++i){
		cout<<a.at(0);
		for(int k=1;k<n;++k){
			cout<<" "s<<a.at(k);
		}
		cout<<"\n"s;
		int v=a.at(i),j=i-1;
		while(j>=0&&a.at(j)>v){
			a.at(j+1)=a.at(j);
			--j;
		}
		a.at(j+1)=v;
	}
	cout<<a.at(0);
	for(int i=1;i<n;++i){
		cout<<" "s<<a.at(i);
	}
	cout<<"\n"s;
}


Measured memory_bytes: 3220
package main

import (
	"fmt"
)

// a,bがどちらもcより安い場合 => a,bをそれぞれx,y個賈う
// aがcより安くて、bがcより高い場合
// => c*2よりbが高ければ
// a > 0 && b > 0 = c/2 < a
// a > 0 && b > 0 = c/2 < a

func main() {
	var a, b, c, x, y int
	fmt.Scan(&a, &b, &c, &x, &y)
	var cost int
	var cNum int
	if ((c < a && c < b) || ((c < a || c < b) && c*2 < a+b)) && x > 0 && y > 0 {
		n := Min(x, y)
		cost += c * 2 * n
		x -= n
		y -= n
		cNum += n * 2
	}
	if c*2 < a {
		cost += c * 2 * x
		x = 0
		cNum += 2 * x
	}
	if c*2 < b {
		cost += c * 2 * y
		y = 0
		cNum += 2 * y
	}
	cost += a * x
	cost += b * y

	fmt.Println(cost)
}

func Min(a, b int) int {
	if a < b {
		return a
	}
	return b
}


Measured memory_bytes: 512
n = int(input())
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
c = list(map(int, input().split(' ')))

plus = 0
for i in range(n - 1):
    if a[i+1] == a[i] + 1:
        plus += c[a[i]-1]
print(sum(b) + plus)    

Measured memory_bytes: 3064
#include <cstdio>
#include <cmath>
#include <limits>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define rep(i, s, g) for (i = s; i < g; i++)
using namespace std;
using ll = long long;
const int inf = 1000000000; //10^9

int main(){
    int n,m;

    cin >> n >> m;
    int ans,ans_n,ans_m;

    if(n==0){
        ans_n = 0;
    }else{
        ans_n = n*(n-1)/2;
    }

    if(m==0){
        ans_m = 0;
    }else{
        ans_m = m*(m-1)/2;
    }

    ans = ans_n + ans_m;

    cout << ans << endl;
}

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

int c[12];
int a[12][12];
ll sum[12] = {0};
int n, m, x;
ll ans = 1500000;
ll total = 0;


bool judge(bitset<12> f){
    total = 0;
    for(int i = 0; i < n; i++){
        total += f[i] * c[i];
        for(int j = 0; j < m; j++){
            sum[j] += f[i] * a[i][j];
        }
    }
    for(int i = 0; i < m; i++){
        if(sum[i] < x) return false;
    }
    return true;
}

int main(){
    cin >> n >> m >> x;
    for(int i = 0; i < n; i++){
        cin >> c[i];
        for(int j = 0; j < m; j++){
            cin >> a[i][j];
        }
    }
    for(int i = 0; i < 4096; i++){
        for(int b = 0; b < 12; b++) sum[b] = 0;
        bitset<12> bs(i);
        if(judge(bs)) ans = min(ans, total);
    }
    if(ans == 1500000) cout << "-1" << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 3584
import java.util.*;
 
public class Main {
	public static void main (String[] args) {
      Scanner sc = new Scanner(System.in);
      
      int t = sc.nextInt();
      int[] arr = new int[t];
      for(int i =0;i<t;i++){
        arr[i]= sc.nextInt();
      }
      int[] dp = new int[t];
      dp[0] = 0;
      dp[1]= Math.abs(arr[0]-arr[1]);
      for(int i =2;i<t;i++){
        int f = dp[i-1]+ Math.abs(arr[i]-arr[i-1]);
        int s = dp[i-2]+ Math.abs(arr[i]-arr[i-2]);
        dp[i]= Math.min(f,s);
      }
      System.out.println(dp[dp.length-1]);
    }
  
}


Measured memory_bytes: 59772
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstring>
#define N 3003
using namespace std;
const int Mod = 1e9 + 7;

int n, f[N][N], sum[N][N];
char s[N];

int main() {
#ifdef whyqx
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif
    cin >> n;
    scanf("%s", s + 1);
    f[1][1] = sum[1][1] = 1;
    for (int i = 2; i <= n; ++i)
        for (int j = 1; j <= i; ++j) {
            if (s[i - 1] == '<')
                (f[i][j] += sum[i - 1][j - 1]) %= Mod;
            else (f[i][j] += (sum[i - 1][i - 1] - sum[i - 1][j - 1]) % Mod) %= Mod;
            sum[i][j] = (sum[i][j - 1] + f[i][j]) % Mod;
        }
    cout << (sum[n][n] % Mod + Mod) % Mod << endl;
    return 0;
}


Measured memory_bytes: 69376
#include <bits/stdc++.h>
#define int long long
#define lint long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; 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 T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e,v); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int N;
    cin >> N;
    double S = 0;
    REP(i, N) {
        int A;
        cin >> A;
        S += 1.0 / A;
    }
    cout << 1.0 / S << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#define rip(i,n) for(int i=0;i<n;i++)
#define ll long long
#define ld long double
#define set setprecision　//小数点以下何位まで知りたいか
#define mod 1000000007
#define pi 3.14159265
#include<numeric>
using namespace std;
int gcd(int a, int b)//最大公約数
{
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
int lcm(int a, int b)//最小公倍数
{
	return a * b / gcd(a, b);
}
ll pow(ll a, ll b) {
	ll k = b % 30000, h = b / 30000, s = 1;
	rip(i, 30000)s = (s * a) % mod; ll j = 1;
	if (h != 0)rip(i, h)j = j * s % mod;
	if (k != 0)rip(i, k)j = j * a % mod;
	return(j);
}
int  main() {
	int n;
	cin >> n;
	vector<int>a(n);
	rip(i, n)cin >> a[i];
	int mini = 1000000000;
	int sum;
	rip(i, 100) {
		sum = 0;
		rip(j, n) {
			sum += (a[j] - i) * (a[j] - i);
		}
		mini = min(mini, sum);
	}
	cout << mini;
}

Measured memory_bytes: 256
package main

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

func SortString(w string) string {
	s := strings.Split(w, "")
	sort.Strings(s)
	return strings.Join(s, "")
}

func main() {
	sc := NewScanner()

	n := sc.NextInt()

	mp := map[string]int{}
	for i := 0; i < n; i++ {
		s := sc.NextLine()
		s = SortString(s)
		mp[s]++
	}
	ans := 0
	for _, val := range mp {
		if val-1 > 0 {
			ans += comb(val)
		}

	}
	fmt.Printf("%v\n", ans)
}

// comb ...
func comb(a int) int {
	return (a * (a - 1)) / 2
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 11776
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
using namespace std;

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

int A[100010];

int main() {
    int N;
    cin >> N;
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
    }
    A[0] = 0;
    A[N + 1] = 0;

    int dis = 0;
    for(int i=0;i<=N;i++) {
        dis += abs(A[i + 1] - A[i]);
    }
    for (int i = 1; i <= N; i++) {
        int disi = dis + abs(A[i - 1] - A[i + 1]) - (abs(A[i - 1] - A[i]) + abs(A[i] - A[i + 1]));

        cout << disi << endl;
    }
}

Measured memory_bytes: 1664
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def r_sort(a) a.sort{|a,b|b<=>a} end

n = inp[0]
a = [0]+inp
t = na(n+1,0)
ans = []
((n/2+1)..n).each do |i|
  if(1 == a[i])
    t[i] = 1
    ans.push(i)
  end
end
(n/2).downto(1) do |i|
  d = i*(n/i)
  c = 0
  while d > 0
    c ^= t[d]
    if(d != i)
      d -= i
      next
    end
    if(c != a[i])
      t[i] = 1
      ans.push(i)
    end
    d -= i
  end
end
puts ans.size
puts ans.join(" ") if(ans.size > 0)

Measured memory_bytes: 23884
import itertools
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]

ans = []
for v in itertools.permutations(list(range(n)), n):
    a = 0
    for i in range(len(v)-1):
        x1,y1 = xy[v[i]][0], xy[v[i]][1]
        x2,y2 = xy[v[i+1]][0], xy[v[i+1]][1]
        a += ((x1-x2)**2+(y1-y2)**2)**0.5
    ans.append(a)
print(sum(ans)/len(ans))

Measured memory_bytes: 10844
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        String[] s = new String[n];
        for(int i=0;i<n;i++){
            s[i] = sc.next();
        }
        Map<List<String>, Integer> codes = new HashMap<>();
        long count = 0;
        for(int i=0;i<n;i++){
            String[] st = s[i].split("");
            Arrays.sort(st);
            List<String> str = Arrays.asList(st);
            if(codes.containsKey(str)){
                int tmp = codes.get(str);
                count += (long)tmp;
                codes.put(str, tmp+1);
            }
            else{
                codes.put(str, 1);
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 154864
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int l,r,d;
    cin>> l >> r >> d;
    int x=r/d,y=(l-1)/d;
    cout<< x-y <<endl;
    return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>
int main() {
  char ch;
  int nums[26] = {0}; 
  while ((ch = getchar()) != EOF) {
    if (ch>=97 && ch<=122)    nums[ch-'a'] += 1;
    else if(ch>=65 && ch<=90) nums[ch-'A'] += 1;
  }
  for (int i = 0; i < 26; i++) {
    printf("%c : %d\n", 'a'+i, nums[i]);
  }
  return 0;
}



Measured memory_bytes: 2588
//ABC085C.go
package main

import "fmt"

func calcAns(n, y int) (int, int, int) {
	for num10k := n; num10k >= 0; num10k-- {
		for num5k := n - num10k; num5k >= 0; num5k-- {
			num1k := n - num10k - num5k
			if 10000*num10k+5000*num5k+1000*num1k == y {
				return num10k, num5k, num1k
			}
		}
	}
	return -1, -1, -1
}

func main() {
	var n, y int
	fmt.Scan(&n, &y)
	fmt.Println(calcAns(n, y))

}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define F first
#define S second
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define sz size()
#define all(A)    A.begin(), A.end()
#define mem(a, b) memset(a, b, sizeof(a))   // all elements of A are b=0 or b=-1 else don't work
#define f0(i,b)   for(ll i=0;i<(b);i++)
#define f1(i,b)   for(ll i=1;i<=(b);i++)
#define f2(i,a,b) for(ll i=(a);i<=(b);i++)
#define f3(i,b,a) for(ll i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(ll i=(a);i!=(b);i+=(c))
#define mod 1000000007

#define whilee(i,t)  while(i!=t)
#define  sl(a)  scanf("%lld",&a)
#define  pl(a)  printf("%lld\n",a)

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;

//for(auto it =A.begin(); it!=A.end(); it++)
//sort(A.begin(),A.end());
//binary_search(A.begin(),A.end(),x);
//reverse(A.begin(), A.end());
//cout << *max_element(A.begin(), A.end());
//cout << *min_element(A.begin(), A.end());
//count(A.begin(), A.end(), X); //counts the occurrences of X
//distance(A.begin(),A.end());  //distance between first to last element
//accumulate(A.begin(), A.end(), 0); //add
//next_permutation(A.begin(), A.end());
//prev_permutation(A.begin(), A.end());
//swap(S[0], T[0]);

//scanf("%lld",&x);
//printf("%lld\n",x);
//while (scanf("%lld %lld", &a, &b) == 2)
//printf("Case %lld: %lld\n", t++, a);

//vector <ll> A;
//deque <ll> A;
//queue <ll> A;
//stack <ll> A;
//list <int> A;
//set <ll> A;
//map <ll,ll> A;
//pair <ll,ll> A ;
//vector <pair <ll,ll>> A ;
//bitset<32> bset1;
//char ch;
//string S, T, U;
ll i, j, k, a, b, c, d, e, f, g, h, l, m, n, o, p, q, r, s, t=1, u, v, w, x, y, z, maxx=INT_MIN, minn=INT_MAX, ans=0, sum=0, cnt=0;

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

    //scan(n);
    cin>>n;
    ll A[n];
    f0(i,n)
    {
        cin>>A[i];
    }
    f1(i,n-2)
    {
        if(A[i-1]<A[i] && A[i]<A[i+1])
        {
            cnt++;
        }
        else if(A[i-1]>A[i] && A[i]>A[i+1])
        {
            cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fo(i, n) for (i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define ll long long
#define si(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
#define ss(s) scanf("%s", s)
#define pi(x) printf("%d\n", x)
#define pl(x) printf("%lld\n", x)
#define ps(s) printf("%s\n", s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << ", " << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;

int dist (pii x, pii y) {
    int result = abs(x.F - y.F) + abs(x.S - y.S);
    return result;
}

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    int n, m, i, j;
    cin>>n>>m;

    vpii a(n);
    vpii b(m);

    fo(i, n) {
        cin>>a[i].F>>a[i].S;
    }
    fo(i, m) {
        cin>>b[i].F>>b[i].S;
    }
    int min, index;
    fo(i, n) {
        min = 1e9;
        fo(j, m) {

            int cur = dist(a[i], b[j]);
            if(cur<min) {
                min = cur;
                index = j+1;
            }

        }
        cout<<index<<endl;
    }


return 0;
}

Measured memory_bytes: 3656
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {
        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        Integer a = Integer.valueOf(mylist.get(0));
        String t = mylist.get(1);

        System.out.println(a>=3200 ? t :"red");

    }

}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int h,w; cin>>h>>w;
	vector<string>s(h); for(auto&&i:s)cin>>i;
	vector<vector<int>>u(h+2,vector<int>(w+2,0)),d(h+2,vector<int>(w+2,0)),
	l(h+2,vector<int>(w+2,0)),r(h+2,vector<int>(w+2,0));
	for(int i=0;i<h;++i){
		for(int j=0;j<w;++j){
			if(s[i][j]=='.'){
				u[i+1][j+1]=u[i][j+1];
				l[i+1][j+1]=l[i+1][j];
				++u[i+1][j+1];
				++l[i+1][j+1];
			}
			int y=abs(h-i),x=abs(w-j);
			if(s[y-1][x-1]=='.'){
				d[y][x]=d[y+1][x];
				r[y][x]=r[y][x+1];
				++d[y][x];
				++r[y][x];
			}
		}
	}
	int ans=0;
	for(int i=1;i<=h;++i){
		for(int j=1;j<=w;++j){
			ans=max(ans,u[i][j]+l[i][j]+d[i][j]+r[i][j]-3);
		}
	}
	cout<<ans<<"\n"s;
}


Measured memory_bytes: 70468
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;

int s[100000 + 1];

int main(){
	while (1) {
		int n, k,ans=0;
		cin >> n >> k;
		if (n == 0) break;
		for (int i = 0; i < n; i++) cin >> s[i];

		for (int i = 0; i < n - k; i++) {
			int t = 0;
			for (int j = 0; j < k; j++) {
				t+=s[i+j];
			}
			ans = max(ans, t);
		}
		cout << ans << endl;
	}
	return 0;
}


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

int main() {
  int K;
  cin >> K;
  int hoge = 7;
  int sum = 0;
  for(int i=0; i<K*5; i++) {
    hoge = (hoge % K);
    sum++;
    if(hoge == 0) break;
    hoge = hoge * 10 + 7;
  }
  if(sum == K*5) sum = -1;
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3608
using System;

class quiz
{
    public int solve(int N, int M, int[][] KA)
    {
        int[] ans = new int[M];
        int[] a = new int[M];

        for (int i = 0; i < M; i++)
        {
            ans[i] = 1;
        }

        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < M; j++)
            {
                a[j] = 0;
            }

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

            for (int j = 0; j < M; j++)
            {
                if (a[j] == 0 && ans[j] == 1)
                    ans[j] = 0;
            }
        }

        int ret = 0;

        for (int i = 0; i < M; i++)
        {
            if (ans[i] == 1)
                ret++;
        }

        return ret;
    }

    public int[] ParseIntBySpace(string str)
    {
        int[] array = new int[str.Length];
        int lastloc = 0, spaceloc = -1;

        for (int i = 0; i < str.Length; i++)
        {
            if (str[i] == ' ')
            {
                array[lastloc++] = int.Parse(str.Substring(spaceloc + 1, i - spaceloc - 1));
                spaceloc = i;
            }
            else if (i == str.Length - 1)
            {
                array[lastloc++] = int.Parse(str.Substring(spaceloc + 1, i - spaceloc));
            }
        }

        Array.Resize(ref array, lastloc);

        return array;
    }
}

class Example
{
    static void Main()
    {
        quiz ex = new quiz();

        int[] NM = ex.ParseIntBySpace(Console.ReadLine());
        int[][] KA = new int[NM[0]][];

        for (int i = 0; i < NM[0]; i++)
        {
            KA[i] = ex.ParseIntBySpace(Console.ReadLine());
        }

        Console.WriteLine(ex.solve(NM[0],NM[1],KA));
    }
}

Measured memory_bytes: 13268
#include<iostream>
using namespace std;
int abs(int x){ return (x<0?-x:x); }
int sum(int a[], int n){
  int s=0;
  for(int i=0; i<n; i++) s+=a[i];
  return s;
}
int main(){
  int N,L;
  cin>>N>>L;
  int A[N];
  for(int i=0; i<N; i++) A[i]=L+i;
  int min_idx=0;
  for(int i=0; i<N; i++){
    if(abs(A[min_idx])>abs(A[i])) min_idx=i;
  }
  A[min_idx] = 0;
  int sum=0;
  for(int i=0; i<N; i++) sum+=A[i];
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 1000000007
#define seg_size 262144
#define REP(a,b) for(long long a = 0;a < b;++a)
long long go[64][200000];
int ans[200000];
int main() {
	string s;
	cin >> s;
	REP(i, s.length()) {
		if (s[i] == 'R') {
			go[0][i] = i + 1;
		}
		else {
			go[0][i] = i - 1;
		}
	}
	REP(i, 60) {
		REP(q, s.length()) {
			go[i + 1][q] = go[i][go[i][q]];
		}
	}
	REP(i, s.length()) {
		ans[go[50][i]]++;
	}
	REP(i, s.length()) {
		cout << ans[i] << " ";
	}
	cout << endl;
}

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

int main()
{
    string s;
    cin >> s;
    int y = stoi(s.substr(0, 4));
    int m = stoi(s.substr(5, 2));
    int d = stoi(s.substr(8, 2));
    if (y <= 2019 && m <= 4 && d <= 30)
    {
        cout << "Heisei"
             << "\n";
    }
    else
    {
        cout << "TBD"
             << "\n";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define pb push_back
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ll long long
using namespace std;
int main(){
  int n;
  cin >> n;
  REP(i, 26)REP(j, 15){
    if(i * 4 + j * 7 == n){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;
typedef vector<pii> vpii;
#define reps(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define all(g) (g).begin(),(g).end()
#define pb push_back
const int mod = 1e9 + 7;
#define INF 1<<25
/*
input case
output case
*/

int N, M;
const int MAX = 100100;
int x, y;
int red[MAX];
int white[MAX];

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

	reps(i,1,N){
		white[i] = 1;
		red[i] = 0;
	}

	red[0] = 1;
	white[0] = 0;

	rep(i,M){
		cin >> x >> y;
		x--;
		y--;
		if (red[x] == 0 and 0 < white[x]){
			white[x]--;
			white[y]++;
		}else if (0 < red[x] and white[x] == 0){
			red[x]--;
			red[y]++;
		}else if (0 < red[x] and 0 < white[x]){
			white[x]--;
			red[y]++;
		}
	}

	int ans = 0;
	rep(i,N){
		if (red[i]) ans++;
	}

	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#define REP(i, n) for(int i=0; i<(n); i++)
#define FOR(i, a, n) for(int i=(a); i<(n); i++)
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;

int main(){
    int N;cin>>N;
    int count = 0;
    FOR(i, 1, N){
        int p;cin>>p;
        if(p != i){
            count++;
        }
    }
    
    if(count <= 2){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int t=1,n,k,x,y;
    while(t--)
    {
        long long int s=0,d,e;
        cin>>n;
        int a[n];
        unordered_map<int,int>m;
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
            m[a[i]]++;
            s=s+a[i];
        }
        cin>>k;
        while(k--)
        {
            cin>>x>>y;
            d=m[x];
            e=m[y];
            s=s-d*x;
            s=s+d*y;
            m[y]=e+d;
            m[x]=0;
            cout<<s<<endl;
        }
    }

}


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

int main()
{
	int a,b,c,d,sum=0;
	string s;
	
	cin>>a>>b;
	if(a<b)
		cout<<0;
	else
		cout<<10;
	return 0;
}
	

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta (bas + (son-bas)/2)
#define coc g[node][i]
#define mod 1000000007
#define inf 1e18
#define N 1000005

using namespace std;
 
typedef long long ll;

double ans;
int a;

int main()
{
	cin >> a;
 
    if (a % 2 == 0) 
    {
      ans = (double)(a/2)/(double)a;
      cout << ans;
    }
    else
    {
      ans = (double)((a+1)/2)/(double)a;
      cout << ans;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <complex>
#include <bitset>
#include <functional>

using namespace std;
using ll=long long int;

int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n), f(n);
    for (auto &e: a) cin >> e;
    for (auto &e: f) cin >> e;

    sort(a.begin(), a.end());
    sort(f.rbegin(), f.rend());

    ll mv = 0;
    for (int i = 0; i < n; ++i) {
        mv = max(mv, a[i] * f[i]);
    }

    auto fn = [&](ll t) {
        ll ret = 0;
        for (int i = 0; i < n; ++i) {
            if (t < a[i] * f[i]) {
                ret += a[i] - t / f[i];
            }
        }
        return ret;
    };

    ll l = -1, r = mv;
    while (r - l > 1) {
        ll mid = (l+r)/2;
        if (fn(mid) <= k) {
            r = mid;
        } else {
            l = mid;
        }
    }

    cout << r << endl;

    return 0;
}


Measured memory_bytes: 3328
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

void main()
{
    long A, B;
    scan(A, B);
    long c = A - 1;
    c += (A <= B) ? 1 : 0;
    writeln(c);
}


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

int N;
int x[201],y[201];
int main(){
	while(cin>>N&&N){
		int xmin=0,xmax=0,ymin=0,ymax=0;
		x[0]=y[0]=0;
		for(int i=1;i<N;i++){
			int n,d,nx,ny;
			cin>>n>>d;
			nx = x[n];ny=y[n];
			if(d==0)nx++;
			else if(d==1)ny++;
			else if(d==2)nx--;
			else ny--;
			xmax=max(xmax,nx);
			xmin=min(xmin,nx);
			ymax=max(ymax,ny);
			ymin=min(ymin,ny);
			x[i]=nx;
			y[i]=ny;
		}
		cout<<xmax-xmin+1<<' '<<ymax-ymin+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include<stdio.h>                                                                                                                           
#include<string.h>

int main()
{
   char s[101];
   char t[101];
   char stmp;
   int slen;
   int i ,j;
   int yn = 0;

   scanf("%s", s);
   scanf("%s", t);

   slen = strlen(s);

   for(i=0;i<slen;i++){
      stmp = s[slen-1];
      for(j=slen-1;j>0;j--){
         s[j] = s[j-1];
      }
      s[0] = stmp;

      if(strcmp(s,t)==0){
         yn = 1;
         break;
      }
   }

   if(yn==1){
      printf("Yes\n");
   }
   else {
      printf("No\n");
   }

   return 0;
}

Measured memory_bytes: 128
using System;

public class p0030
{
	int cnt, n, m;
	
	p0030(){
		string str;
		string[] st;
		
		while((str=Console.ReadLine()) != null){
			if(str == "0 0") break;
			st = str.Split(' ');
			n = int.Parse(st[0]);
			m = int.Parse(st[1]);
			cnt = 0;
			
			solve(0, 0, 0);
			Console.WriteLine("{0}", cnt);
		}
	}
	
	public void solve(int p, int sm, int q){
		if(p == n){
			if(sm == m) ++cnt;
			return;
		}
		
		if(sm > m) return;
		
		for(int i = q; i < 10; ++i)
			solve(p+1, sm+i, i+1);
	}
	
	public static int Main(string[] args){
		new p0030();
		return 0;
	}
}

Measured memory_bytes: 5564
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int n;
    long long a, ans = 1;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> a;
        if (a == 0) {
            ans = 0;
        } else if(ans == -1 || ans > (long long)1e18 / a){
            ans = -1;
        } else {
            ans *= a;
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define FASTIO  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int
#define ld long double
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define W while
#define For(i,s,x) for(int i=s;i<x;i++)
#define FOR(i,x) for(int i=0;i<x;i++)
#define Rof(i,s,x) for(int i=s;i>=x;i--)
#define pb push_back
#define F first
#define S second
#define nextl cout<<"\n"
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define get(a) cin>>a
#define deb(x) cout<<#x<<"="<<x<<"\n";


int main() {
	FASTIO;
    ll n;
    get(n);
    ll c[n][2];
    FOR(i,n) cin>>c[i][0]>>c[i][1];
    ld ans=0;
    FOR(i,n) FOR(j,n) ans+=sqrt(pow(c[i][0]-c[j][0],2)+pow(c[i][1]-c[j][1],2));
    cout<<fixed<<setprecision(10)<<ans/n;
	return 0;
}

Measured memory_bytes: 256
##### ABC087B - Coins
a, b, c, x = list(map(int, [input().rstrip() for _ in range(4)]))
count = 0

for i in range(min(a, int(x / 500)) + 1):
    for j in range(min(b, int((x - i * 500) / 100)) + 1):
        if (x - i * 500 - j * 100) // 50 <= c and (x - i * 500 - j * 100) % 50 == 0:
            count += 1
print(count)

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

int main()
{
    int a,b;
    cin>>a>>b;
    if(a>=13){
        cout<<b<<endl;
    }else if(a<6){
        cout<<0<<endl;
    }else{
        cout<<b/2<<endl;
    }
}

Measured memory_bytes: 256
S = input()
T = input()

ok = True

RS = {}
RT = {}

for i in range(len(S)):
    s = S[i]
    t = T[i]
    if s in RS:
        if RS[s] != t:
            ok = False
    if t in RT:
        if RT[t] != s:
            ok = False
    RS[s] = t
    RT[t] = s
if ok:
    print('Yes')
else:
    print("No")

Measured memory_bytes: 3632
#B
import math
N = int(input())
def make_prime_list_2(num):
    if num < 2:
        return []

    prime_list = [i for i in range(num + 1)]
    prime_list[1] = 0 
    num_sqrt = math.sqrt(num)

    for prime in prime_list:
        if prime == 0:
            continue
        if prime > num_sqrt:
            break

        for non_prime in range(2 * prime, num, prime):
            prime_list[non_prime] = 0

    return [prime for prime in prime_list if prime != 0]
def search_divisor_num_1(num):
    if num < 0:
        return None
    elif num == 1:
        return 1
    else:
        num_sqrt = math.floor(math.sqrt(num))
        prime_list = make_prime_list_2(num_sqrt)

        divisor_num = 1
        for prime in prime_list:
            count = 1
            while num % prime == 0:
                num //= prime
                count += 1
            divisor_num *= count

        if num != 1:
            divisor_num *= 2

        return divisor_num
res = 0
for i in range(N+1):
    if search_divisor_num_1(i) == 8 and i % 2 == 1:
        res+=1
print(res)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 1e6 + 11;
int f[N][3];
int n, fac[N], inv[N];
inline int M(int x, int y){
    return 1LL * x * y % mod;
}
inline int A(int x, int y){
    return x + y - (x + y >= mod ? mod : 0);
}
inline int C(int x, int y){
    if(x < y)return 0;
    return M(fac[x], M(inv[y], inv[x-y]));
}
int ksm(int base, int x){
    int ans = 1;
    while(x){
        if(x & 1)ans = M(ans, base);
        base = M(base, base);
        x >>= 1;
    }
    return ans;
}
int main(){
    cin>>n;
    fac[0] = fac[1] = inv[1] = inv[0] = 1;
    for(int i = 2;i <= n; i++){
        inv[i] = (mod - 1LL * mod / i * inv[mod%i] % mod);
        fac[i] = M(fac[i-1], i);
    }
    for(int i = 2;i <= n; i++)inv[i] = M(inv[i-1], inv[i]);
    f[0][0] = 1;
    for(int i = 1;i <= n; i++){
        for(int j = 0;j <= 2; j++){
            for(int k = 0;k <= 2; k++){
                if(j == k)continue;
                f[i][j] = A(f[i][j], f[i-1][k]);
            }
        }
    }
    int ans = 0;
    int all = ksm(ksm(3, n - 1), mod - 2);
    for(int i = 1;i <= n; i++){
        int res = M(C(n, i), f[i][1]);
        res = M(res, all);
        ans = A(ans, M(res, ksm(M(3 * n, i), mod - 2)));
    }
    cout<<ans<<endl;
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9

using namespace std;
typedef long long int lli;
typedef long long ll;

int main() {
    int a, b;
    cin >> a >> b;

    if(a <= 8 && b <= 8){
        cout << "Yay!" << endl;
    }
    else{
        cout << ":(" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <string>
#define int long long
#define P pair<int,int>
#define V vector<int>
#define rep(i,n) for(int i=0;i<n;++i)
#define vsort(vec) sort(vec.begin(),vec.end())
#define end system("PAUSE");return 0
using namespace std;
signed main() {
	int n, a, b;
	cin >> n >> a >> b;
	if (n == 1 && a == b)cout << 1;
	else if (n == 1)cout << 0;
	else if (a > b)cout << 0;
	else cout << (b - a)*(n - 2) + 1;
	cout << endl;
	end;
}


Measured memory_bytes: 504
#include<iostream>
using namespace std;
int main(){
    string s;
    int a[4],num;
    cin >> s;
    for(int i=0;i<4;i++)    a[i] = int(s[i]-'0');

    for(int x=0;x<2;x++){
        for(int y=0;y<2;y++){
            for(int z=0;z<2;z++){
                num = a[0];
                if(x==1)    num+=a[1];
                else   num-=a[1];
                if(y==1)    num+=a[2];
                else    num-=a[2];
                if(z==1)    num+=a[3];
                else    num-=a[3];
                if(num==7){
                    cout << a[0];
                    if(x==1)    cout << '+';
                    else    cout << '-';
                    cout << a[1];
                    if(y==1)    cout << '+';
                    else    cout << '-';
                    cout << a[2];
                    if(z==1)    cout << '+';
                    else    cout << '-';
                    cout << a[3] << "=7\n";
                    return 0;
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#include<iomanip>//浮動小数点数を出力する制度の指定
//使い方　数値をnumとして　cout<<setprecision(n)<<num ;nは桁数
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
using ll =long long;
#define INF 2000000000
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
/*覚えてないことメaモ
  数値型から文字列に変換　to_string(number);これは簡単
  文字列から数値型に変換　stoi(number)  文字列からllに変換　stoll(number)*/
 
 
 int main(){
	int n; cin >> n;
	double odd = (n+1) / 2;
	cout <<setprecision(8)<< odd / n  << endl;
 }


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
# define pll pair<ll,ll>

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n,k;
    cin>>n>>k;
    ll a[n];
    for(int i=0;i<n;i++){
    	cin>>a[i];
	}
	for(int i=k;i<n;i++){
		if(a[i]>a[i-k]){
			cout<<"Yes\n";
		}else{
			cout<<"No\n";
		}
	}
    return 0;
}

Measured memory_bytes: 5216
import java.util.*;

class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long n = scan.nextLong();
		long k = scan.nextLong();
		int[] arr = new int[200001];
		for(int i = 0; i < n; i++) {
			arr[scan.nextInt()]++;
		}
		PriorityQueue<Integer> q = new PriorityQueue<>(200000);
		for(int val : arr) {
			if(val>0) q.add(val);
		}
		int result = 0;
		while(q.size()>k) {
			result += q.poll();
		}
		System.out.println(result);
	}
}


Measured memory_bytes: 83300
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define all(ppp) ppp.begin(),ppp.end()
#define out(ppp) cout<<(ppp)<<endl
#define out1(ppp) cout<<(ppp) 
#define MAX_CHAR 256

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define pb push_back

typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<double, double> pd;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pld;
 
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pd> vpd;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<vpi> vvpi;

typedef set<pi> spi;

const int INF=INT_MAX;
ll x,y;
ll inv[10000100];
ll FactorialInv[10000100];
ll Factorial[10000100];

ll mymod(ll a,ll b){
    a%=MOD;
    ll result=1;
    while(b>0){
        if(b&1){
            result=(result*a)%MOD;
        }
        a=(a*a)%MOD;
        b>>=1;
    }
    return result;
    
}
ll modInverse(ll n){
    return mymod(n,MOD-2);
}

void init_combination(){
    const int MAX = 10000002;   //1e6+2
    Factorial[0]=1;
    inv[0]=1;
    for(int i=1;i<=MAX;i++){
        Factorial[i]=(Factorial[i-1]*i)%MOD;
    }
    FactorialInv[MAX]=modInverse(Factorial[MAX]);
    for(int i=MAX-1;i>=0;i--){
        FactorialInv[i]=FactorialInv[i+1]*(i+1)%MOD;
    }
    for(int i=1;i<=MAX;i++){
        inv[i]=(FactorialInv[i]*FactorialInv[i-1])%MOD;
    }
}

ll combination(ll n,ll k){
    if(n==k||k==0){
        return 1;
    }
    if(n<k){
        return 0;
    }
    ll ans=(Factorial[n]*FactorialInv[k])%MOD;
    ans=(ans*FactorialInv[n-k])%MOD;
    return ans;
}


int main(){
    cin>>x>>y;
    ll rem=(x+y)%3;
    if(rem!=0){
        out(0);
        return 0;
    }
    rem=(x+y)/3;
    ll a=2*x-y;
    ll b=2*y-x;
    if(a<0||b<0){
        out(0);
        return 0;
    }
    if(a%3!=0){
        out(0);
        return 0;
    }
    a=a/3;
    //cout<<rem<<" "<<a<<endl;
    init_combination();
    ll ans=combination(rem,a);
    out(ans);
}


Measured memory_bytes: 234624
from math import ceil

N, K, *A = map(int, open(0).read().split())

def is_ok(n):
    t = 0
    for a in A:
        if a <= n:
            continue
        t += ceil(a / n) - 1
    return t <= K

ok = 1000000000
ng = 0.0000000001
while abs(ng - ok) > 1:
    m = (ok + ng) // 2
    if is_ok(m):
        ok = m
    else:
        ng = m

print(ceil(ok))


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

const int MOD = 998244353;
stack<pair<pair<int,int>,int> > h;
pair<pair<int,int>,int> car[200010];
vector<int> e[200010];
bool noroot[200010];

long long dfs(int x) {
	long long tmp = 1;
	for (int y : e[x]) tmp = (tmp * dfs(y)) % MOD;
	return tmp+1;
}

int main() {
	ios::sync_with_stdio(false);
	int n; cin >> n;
	for (int i = 1; i <= n; i++) {
		int x,d; cin >> x >> d;
		car[i] = {{x,x+d},i};		
	}
	sort(car+1, car+n+1);
	for (int i = n; i; i--) {
		while (!h.empty()) {
			auto it = h.top();
			if (car[i].first.second > it.first.first) {
				e[car[i].second].push_back(it.second);
				noroot[it.second] = true;
				h.pop();
			}
			else break;
		}
		h.push(car[i]);
	}
	long long ans = 1;
	for (int i = 1; i <= n; i++) if (!noroot[i]) ans = (ans * dfs(i))% MOD;
	cout << ans << "\n";
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	if(N%2==0) {
		cout<<(N/2-1)<<endl;
	}
	else {
		cout<<N/2<<endl;
	}
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256