akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
int main() {
    long long n;
    scanf("%lld",&n);
    long long ans=1e18;
    for(long long i=1;i*i<=n;i++) {
        if(n%i) continue;
        ans=std::min(ans,i+n/i);
    }
    printf("%lld",ans-2);
    return 0;
}


Measured memory_bytes: 256
//Code is like humor. When you have to explain it, it’s bad.
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#include <bits/stdc++.h>
#define MOD 1000000007
#define int long long
using namespace std;
#define ss second
#define ff first
int32_t main()
{
    fastio;
    int T,n,m,i,j,k,a,b,c;
    T=1;
    while(T --> 0)
    {
        cin>>k;
        cin>>n;
        int A[n];
        for(i=0;i<n;i++)
            cin>>A[i];
        
        int m=-1;
        for(i=1;i<n;i++)
        {
            m=max(m,A[i]-A[i-1]);
        }
        m=max(m,A[0]+k-A[n-1]);
        cout<<k-m;
    }
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <math.h>

using namespace std;

int main() {
	string s;
	int j, k;
	cin >> s;
	j = s.size();
	for (int i = 0; i < s.size(); i++) {
		if (i < j &&s[i]=='A') {
			j = i;
		}
		if (i > j&& s[i] == 'Z') {
			k = i;
		}
	}

	cout << k - j + 1 << endl;


	return 0;
}

Measured memory_bytes: 640
package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	g := newGraph(n)
	for i := 1; i < n; i++ {
		p := getNextInt(scanner) - 1
		g.appendEdge(p, i, i)
	}
	for i := 0; i < n; i++ {
		g.v[i].x = getNextInt(scanner)
		g.v[i].dp = math.MaxInt32
	}
	g.dfs(0)
	for i := 0; i < n; i++ {
		if g.v[i].dp == math.MaxInt32 {
			fmt.Fprintln(writer, "IMPOSSIBLE")
			return
		}
	}
	fmt.Fprintln(writer, "POSSIBLE")
}

type vertex struct {
	x, dp int
}
type edge struct {
	to, id int
}
type graph struct {
	v []vertex
	e [][]edge
}

func newGraph(n int) graph {
	return graph{
		v: make([]vertex, n),
		e: make([][]edge, n),
	}
}
func (g *graph) appendEdge(from, to, id int) {
	g.e[from] = append(g.e[from], edge{
		to: to,
		id: id,
	})
}

func (g *graph) dfs(c int) {
	var sum int
	if len(g.e[c]) == 0 {
		g.v[c].dp = 0
		return
	}
	dp := make([]int, 5005)
	dp[0] = 1
	for _, e := range g.e[c] {
		g.dfs(e.to)
		dp2 := make([]int, 5005)
		sum += g.v[e.to].x + g.v[e.to].dp
		for i := 5000; i >= 0; i-- {
			if i-g.v[e.to].x >= 0 {
				dp2[i] = dp2[i] | dp[i-g.v[e.to].x]
			}
			if i-g.v[e.to].dp >= 0 {
				dp2[i] = dp2[i] | dp[i-g.v[e.to].dp]
			}
		}
		dp = dp2
	}
	for i := g.v[c].x; i >= 0; i-- {
		if dp[i] == 1 {
			g.v[c].dp = sum - i
			break
		}
	}
}


Measured memory_bytes: 52452
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll a[999];
int main(){
	ll n;
	scanf("%lld",&n);
	rep(i,0,n)scanf("%lld",a+i);
	sortup(a,n);
	ll ans=1;
	rep(i,1,n)if(a[i-1]!=a[i])ans++;
	printf("%lld",ans);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair

int main()
{
  double a,b;
  cin>>a>>b;
  double h,m;
  cin>>h>>m;
  double f=h*30+(m/60)*30,g=m*6;
  double gg=abs(f-g);
  double kk=min(360-gg,gg);
  //cout<<kk<<endl;
  double pi = 2 * acos(0.0);
  double n = kk * (pi / 180.00000000);
  double p=cos(n);
  //cout<<p<<endl;
  double ans=sqrtl(a*a+b*b-2*a*b*p);
  printf("%0.10f",ans);
}


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

#define INF ((1<<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)

bool have[1010];

int main() {
    int N, K;
    cin >> N >> K;
    rep(i, K) {
        int d;
        cin >> d;
        rep(j, d) {
            int a;
            cin >> a;
            a--;
            have[a] = true;
        }
    }

    int ans = 0;
    rep(i, N) {
        if (!have[i]) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3636
#include<iostream>
#include<string>
using namespace std;
// Problem https://atcoder.jp/contests/abc085/tasks/abc085_a
// ref https://qiita.com/drken/items/fd4e5e3630d0f5859067#%E7%AC%AC-2-%E5%95%8F--abc-081-a---placing-marbles-100-%E7%82%B9

string solve(string errorDate){
    errorDate[3]='8';
    return errorDate; 
}

int main(void){
    string errorDate,answerDate;
    cin >> errorDate;
    answerDate = solve(errorDate);
    cout << answerDate << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
    
    ll n;
    cin >> n;
    cout << n*(n-1) / 2 << endl;

}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

template<typename T> class RPQ : public PQ<T, vector<T>, greater<T>> { };
template<typename Cost> void dijkstra(int start, vector<pair<int, Cost>> g[], Cost dist[]) {
	RPQ<pair<Cost, int>> q;
	dist[start] = 0;
	q.emplace(dist[start], start);
	while(! q.empty()) {
		auto cp = q.top(); q.pop();
		int  p = cp.SE;
		Cost c = cp.FI;
		if(dist[p] != c) { continue; }
		for(auto && e : g[p]) {
			int  ep = e.FI;
			Cost ec = e.SE;
			if(setmin(dist[ep], dist[p] + ec)) { q.emplace(dist[ep], ep); }
		}
	}
	return;
}

int k, d[100000];
vector<pair<int, int>> v[100000];

int main() {
	cin >> k;
	
	inc(i, k) {
		v[i].EB((i +  1) % k, 1);
		v[i].EB((i * 10) % k, 0);
		d[i] = 46;
	}
	
	dijkstra(1, v, d);
	
	cout << d[0] + 1 << endl;
	
	return 0;
}


Measured memory_bytes: 6780
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        n: usize,
        q: usize,
        a: [i64; n],
        x: [i64; q],
    }

    let mut wsum = vec![0; n + 1];
    let mut osum = vec![0; n + 1];
    let mut esum = vec![0; n + 1];

    for i in 0..n {
        wsum[i + 1] = wsum[i] + a[i];
        osum[i + 1] = osum[i] + if i % 2 == 1 { a[i] } else { 0 };
        esum[i + 1] = esum[i] + if i % 2 == 0 { a[i] } else { 0 };
    }

    let a: Vec<i64> = a.into_iter().map(|x| x * 4).collect();

    for x in x.into_iter() {
        let x = x * 4 - 1;
        let mut lo = 0;
        let mut hi = 4_000_000_000;
        while hi - lo > 1 {
            let mi = (lo + hi) / 2;

            let ll = bsearch(x - mi, &a);
            let rr = bsearch(x + mi + 1, &a);
            let cnt = rr - ll;

            if cnt > n - rr {
                hi = mi;
            } else {
                lo = mi;
            }
        }

        let ll = bsearch(x - lo, &a);
        let rr = bsearch(x + lo + 1, &a);

        // eprintln!("{:?}: {:?}", (ll, rr), (lo, hi));

        let ans = (wsum[n] - wsum[rr]) + if n % 2 == 1 { esum[ll] } else { osum[ll] };
        println!("{}", ans);
    }
}

// return i where v[i] >= x
fn bsearch(x: i64, v: &[i64]) -> usize {
    let mut lo = -1i64;
    let mut hi = v.len() as i64;

    while hi - lo > 1 {
        let mi = ((lo + hi) / 2) as usize;
        if v[mi] >= x {
            hi = mi as _;
        } else {
            lo = mi as _;
        }
    }

    hi as usize
}


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

int main(){
  string s,t;
  ll n,m,count=0,result=-1;
  bool absent = false;
  cin >> s >> t;
  n = s.size();
  m = t.size();
  vector<ll> l[10000];
  for(ll i=0;i<n;i++){
    ll x = s.at(i);
    l[x].push_back(i);
  }
  for(ll i=0;i<m;i++){
    result++;
    ll x = t.at(i);
    if(l[x].size() == 0){
      absent = true;
      break;
    }
    auto Iter = lower_bound(l[x].begin(),l[x].end(),result);
    if(Iter == l[x].end()){
      count++;
      result=0;
      Iter = lower_bound(l[x].begin(),l[x].end(),result);
    }
    result = *Iter;
  }
  if(absent){
    cout << -1 << endl;
  }
  else{
    cout << count*n+result+1 << endl;
  }
}


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

int main() {
  int N, sum = 0;
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r;
    
    sum += r - l + 1;
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

require 'bigdecimal'

N = get_int
X = []
Y = []
N.times do |i|
  X[i], Y[i] = get_ints
end

sum = 0
[*0...N].permutation.each do |arr|
  s_sum = 0
  arr.each_cons(2) do |i, j|
    s_sum += Math.sqrt(BigDecimal((X[i] - X[j]) ** 2) + BigDecimal((Y[i] - Y[j]) ** 2))
  end
  sum += s_sum
end

puts sum / [*0...N].permutation.to_a.length


Measured memory_bytes: 20940
n = int(input())
ct, f = 0, 0
for i in range(n):
    d1, d2 = map(int, input().split())
    if d1 == d2:
        ct += 1
    else: ct = 0

    if ct == 3 and f == 0:
        f = 1

if f == 1:
    print('Yes')
else: print('No')


Measured memory_bytes: 9168
#include <stdio.h>

int check(int n)
{
     if(n == 3 || n % 10 == 3){
        return 1;
    }
    else if(n == 0){
        return 0;
    }
    else {
        n /= 10;
        if(check(n) == 1){return 1;}
    }
    return 8;
}

int main(void)
{
    int n;
    int i;

    scanf("%d", &n);

    for(i=1;i<=n;i++){
        if(i % 3 == 0 || check(i) == 1){
            printf(" %d", i);
        }
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <bitset>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using lint = long long;
using namespace std;

const int MOD = 1000000007;

int main() {
    int A, B;
    cin >> A >> B;
    int res = A+B;
    res = max(res, A-B);
    res = max(res, A*B);
    cout << res << endl;
    return 0;
}


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

int main() {
    int N=0;
    while(cin >> N && N!=0) {
        vector<int> A(N), B(N);
        for(int i=0; i<N; ++i) cin >> A[i] >> B[i];

        int ret_a=0, ret_b=0;
        for(int i=0; i<N; ++i) {
            if(A[i] < B[i]) {
                ret_b += A[i]+B[i];
            } else if(A[i] > B[i]) {
                ret_a += A[i]+B[i];
            } else {
                ret_a += A[i]; ret_b += B[i];
            }
        }
        cout << ret_a << " " << ret_b << endl;
    }
}

Measured memory_bytes: 1272
package main

import (
	"fmt"
	"math"
)

func main() {
	var s string
	fmt.Scan(&s)
	ans := 1000
	for i := 0; i+2 < len(s); i++ {
		X := int(100*int(s[i]-'0') + 10*int(s[i+1]-'0') + 1*int(s[i+2]-'0'))
		var diff = int(math.Abs(float64(X - 753)))
		if diff < ans {
			ans = diff
		}
	}
	fmt.Println(ans)
}


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

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

  ll amount = 100;
  int i = 0;

  while (amount < x) {
    amount += amount / 100;
    i++;
  }

  cout << i << endl;

  return 0;
}


Measured memory_bytes: 3632
import java.util.*;
class Main 
{
  public static void main(String[] args) 
  {
    Scanner sc = new Scanner(System.in);
    String input =sc.next();    
    String[] ar = input.split("");
      boolean isGood = true;
    int i = 1;
      
        for (String value : ar) {
            if (i%2 == 0) {
                if (value.equals("L") || value.equals("U") || value.equals("D") ){
                    i++;
                    continue;
                } else {
                    isGood =false;
                    break ;
                }
            
            
            } else {
                if (value.equals("R") || value.equals("U") || value.equals("D") ){
                    i++;
                    continue;
                } else {
                    isGood =false;
                    break ;
                }
            }
        }
      if (isGood) {
         System.out.println("Yes");
      } else {
          System.out.println("No");
      }
    
  }
}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >>  s >> t;
  bool f = true;
  for(int i=0;i<s.size();i++) {
    if(s.at(i) != t.at(i)) {
      f = false;
    }
  }
  if(f) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
long long n,m;
vector<vector<long long> >v(100001);
long long mem[100001];
long long dp(long long i)
{
    if(mem[i]!=-1)
        return mem[i];
    mem[i]=0;
   for(long long j=0;j<v[i].size();j++)
        mem[i]=max(mem[i],1+dp(v[i][j]));
   return mem[i];
}
int main()
{
  memset(mem,-1,sizeof(mem));
  cin>>n>>m;
  long long i;
  long long a,b;
  for(i=0;i<m;i++)
  {
  cin>>a>>b;
  v[a].push_back(b);
  }
  long long res=0;
  for(i=1;i<=n;i++)
  res=max(res,dp(i));
  cout<<res;
  return 0;
}


Measured memory_bytes: 7808
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;}
typedef long long ll;

ll n,m,h,w;
string s,t;

int main() {
  cin >> h >> w >> n;
  cout << (n+max(h,w)-1)/max(h,w) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>

const unsigned int MAX_N = 35;

int N;
int dp[MAX_N];

int main(){
    while(true){
        std::cin >> N;
        if(N == 0)
            break;
        
        memset(dp, 0, sizeof(dp));
        ++N;
        dp[0] = 1;

        for(int i = 0; i < N - 1; ++i){
           for(int j = 1; j <= 3; ++j){
                dp[i + j] += dp[i];
            }
        }

        int ans = dp[N - 1] / 3650 + (dp[N - 1] % 3650 != 0);

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

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

using namespace std;

#define MAXN 100010
const int INF = 1 << 30;
typedef pair<int, int> pii;
vector<pii> g[MAXN];

int d[MAXN];

void dijkstra(int s, int n){
    priority_queue <pii, vector<pii>, greater<pii> > q;
    d[s]=0;
    q.push(pii(0,s));
    while(!q.empty()){
        int dist = q.top().first;
        int cur = q.top().second;
        q.pop();
        if(dist>d[cur]) continue;
        for(int i=0;i<g[cur].size();++i){
            int next = g[cur][i].first;
            int w = g[cur][i].second;
            if(d[cur]+w <   d[next]){
                d[next] = d[cur] + w;
                q.push(pii(d[next],next));
            }
        }
    }
}

main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;++i){
        if(i==n-1) g[i].push_back(pii(0,1));
        else g[i].push_back(pii(i+1,1));
        int next = ((n + i)*10)%n;
        if(next!=i) g[i].push_back(pii(next,0));
    }
    // for(int i=0;i<n;++i){
    //     cout << i << " -> ";
    //     for(int j=0;j<g[i].size();++j){
    //         cout << g[i][j].first << " ";
    //     }
    //     cout << endl;
    // }
    for(int i =0;i<n;++i) d[i]=INF;
    dijkstra(1,6);
    cout << d[0]+1 << endl;
}

Measured memory_bytes: 6780
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
int main()	{
  int n;
  cin>>n;
  vector<int>a(n);
  rep(i,n) cin>>a[i];
  sort(all(a));
  rep(i,n-1){
    if(a[i]==a[i+1]){
      cout<<"NO"<<endl;
      return 0;
    }
  }
  cout<<"YES"<<endl;
}

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

int main()
{
    ll n, sum = 0;
    cin >> n;
    ll arr[n];
    map<ll , ll > mp;
    for(int i = 0; i < n; i++)  {
        cin >> arr[i];
        sum += arr[i];
        mp[arr[i]]++;
    }
    ll q;
    cin >> q;
    while(q--)  {
        ll a, b;
        cin >> a >> b;
        sum += mp[a]*(b-a);
        mp[b] += mp[a];
        mp[a] = 0;
        cout << sum << "\n";
    }
    return 0;
}


Measured memory_bytes: 10196
#include<stdio.h>

int main(){
    int i, N, K, X, Y;
    int sum = 0;
    
    scanf("%d", &N);
    scanf("%d", &K);
    scanf("%d", &X);
    scanf("%d", &Y);
    
    for(i = 1;i <= N;i++){
        if(i <= K){
            sum += X;
        }else{
            sum += Y;
        }
    }
    
    printf("%d\n", sum);
    
    return 0;
}



Measured memory_bytes: 128
def main():
     x,n = map(int,input().split())
     L = list(map(int,input().split()))
     i = 0
     if n == 0 or x not in L:
          print(x)
          return 0
     while(True):
          i += 1
          if x - i not in L:
               print(x - i)
               return 0
          if x + i not in L:
               print(x + i)
               return 0
main()

Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define fast ios::sync_with_stdio(false); cin.tie(NULL);
#define loop(n) for(int i=0; i<n; i++)
#define rep(i,start,n) for(int i=start; i<n; i++)

signed main(){
    fast;  

    int n;cin>>n;
    int T;cin>>T;

    int curr = T;
    int ans=T;
    int t[n];

    for(int i=0;i<n;i++){
    	cin>>t[i];
    	if(i!=0){
    		
    		if(t[i]<=curr)
    			ans+=(t[i]-t[i-1]);
    		else
    			ans+=( T );

    		curr = t[i]+T;
    		
    	}
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 5220
// Knapsack w/ Limitation
// AOJ DPL 1G
#include    <bits/stdc++.h>
using   namespace   std;
typedef long long ll;

#define INF (1<<30)

#define Rep0(i, n)  for (int i=0; i<n; i++)
#define Rep1(i, n)  for (int i=1; i<=n; i++)

struct  Item {
    int v=0;
    int w=0;
    int m=0;
};

int main() {
    int N, W;
    cin >>N >>W;
    vector<Item> I(N);
    Rep0(i, N)
        cin >>I.at(i).v >>I.at(i).w >>I.at(i).m;
    // DP table: index: sum weight (0, W), holds total value
    vector<int> DP(W+1, 0);
    Rep0(i, N) { // From Item# 0 to N-1
        int v=I.at(i).v;
        int w=I.at(i).w;
        int m=I.at(i).m;
        for (int j=1; m>0; j*=2) {
               int mm=min(m, j); //mm=1, 2, 4, ..., (m-1-2-4-...)
               m -=mm;
               for (int k=W; k>=w*mm; k--) // Full scan
                   DP.at(k)=max(DP.at(k), DP.at(k-w*mm)+v*mm); // Pick up or not, better one
        }
    }
    // Search for the best
    int S=0;
    for (int w=0; w<=W; w++)
        S=max(S, DP.at(w));
    cout <<S <<endl;
    return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;

const int mod = 1e9 + 7;

int gcd(int a, int b) {
    return b? gcd(b, a % b) : a;
}
pii exgcd(int a, int b) {
    if(b == 0) return pii(1, 0);

    pii t = exgcd(b, a % b);
    return pii(t.second, t.first - a / b * t.second);
}

int exp(int x, int n) {
    int ret = 1;
    while(n) {
        if(n & 1) ret = 1LL * ret * x % mod;
        x = 1LL * x * x % mod;
        n >>= 1;
    }
    return ret;
}

int solve(int a, int b, int c, ll limx, ll limy) {
    int d = gcd(a, b);
    if(c % d) return 0;

    a /= d;
    b /= d;
    c /= d;

    pii t = exgcd(a, b);
    ll Ra = t.first;
    ll Rb = t.second;

    Ra *= c;
    Rb *= c;

    Rb += Ra / b * a;
    Ra -= Ra / b * b;
    while(Ra <= 0) {
        Ra += b;
        Rb -= a;
    }
    if(Ra > limx) return 0;
    if(Rb <= 0) return 0;
    ll as = 0, ae = (1LL * limx - Ra) / b;
    ll bs = Rb <= limy? 0 : (Rb - limy + a - 1) / a, be = (Rb - 1) / a;
    return max(0LL, min(ae, be) - max(as, bs) + 1) % mod;
}

int po[10];
int S;
int ans = 0;

int main() {
    po[0] = 1;
    for(int i = 1; i <= 9; i++) {
        po[i] = po[i - 1] * 10;
    }

    cin >> S;

    for(int a = 1; a <= 9; a++) {
        for(int b = a + 2; b <= 9; b++) {

            int cnt = 0;
            for(int i = a + 1; i < b; i++) {
                cnt += (po[i] - po[i - 1]) * i;
            }
            if(cnt >= S) continue;

            ans += solve(a, b, S - cnt, po[a] - po[a - 1], po[b] - po[b - 1]);
            ans %= mod;
        }
    }

    for(int i = 1; i <= sqrt(S); i++) {
        if(S % i == 0) {
            int tmp = exp(10, i) + mod - exp(10, i - 1);
            tmp %= mod;

            if(i > 9 || tmp >= S / i) {
                tmp += mod - S / i + 1;
                tmp %= mod;

                ans += tmp;
                ans %= mod;
            }

            if(i * i != S) {
                tmp = exp(10, S / i) + mod - exp(10, S / i - 1);
                tmp %= mod;

                if(S / i > 9 || tmp >= i) {
                    tmp += mod - i + 1;
                    tmp %= mod;

                    ans += tmp;
                    ans %= mod;
                }
            }
        }
    }

    for(int a = 1; a < 9; a++) {
        ans += solve(a, a + 1, S, po[a] - po[a - 1], po[a + 1] - po[a]);
        ans %= mod;
    }

    //*
    if(S >= 1e6) {
        for(int i = 2; i <= 10; i++) {
            if(S % i) {
                ans += solve(S / i, S / i + 1, S, 1e18, 1e18);
                ans %= mod;
            }
        }
        for(int a = 9; a < S / 10; a++) {
            ans += solve(a, a + 1, S, 1e18, 1e18);
            ans %= mod;
        }
        cout << ans;
        return 0;
    }
    //*/

    for(int a = 9; a <= S / 2; a++) {
        ans += solve(a, a + 1, S, 1e18, 1e18);
        ans %= mod;
    }

    cout << ans;
}


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

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

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

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

vector<int> c[5];

int erase(int h) {
	int ct = 1,n = 0,old_n = 0,max_ct = 1,i2,n2;
	for(int i = 0;i < 5;i++) {
		old_n = n;
		if((int)c[i].size() > h) n = c[i][h];
		else n = 0;

		if(old_n == n) ct++;
		else ct = 1;

		if(ct > max_ct) {
			max_ct = ct;
			i2 = i;
			n2 = n;
		}
	}
	if(max_ct >= 3 && n2 != 0) {
		for(int i = i2 - max_ct + 1;i <= i2;i++) c[i][h] = 0;
		return max_ct * n2;
	}
	return 0;
}

int main() {

	int h;
	while(cin >> h && h != 0) {
		for(int i = 0;i < 5;i++) {
			c[i].resize(h,0);
		}
		for(int i = 0;i < h;i++) {
			cin >> c[0][h - i - 1] >> c[1][h - i - 1] >> c[2][h - i - 1] >> c[3][h - i - 1] >> c[4][h - i - 1];
		}

		int score = 0,old_score = -1;
		while(score != old_score) {
			old_score = score;
			for(int i = 0;i < h;i++) score += erase(i);
			for(int i = 0;i < 5;i++) c[i].erase(remove(c[i].begin(),c[i].end(),0),c[i].end());
		}

		cout << score << endl;
	}
	 
}

Measured memory_bytes: 1212
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
#define N 500000
ll MOD=1e9+7;
vec mem(20,-1);
main(){
    string s;
    cin>>s;
    int n=s.size();
    ll now=0,ans=0;
    rep3(i,n-1,0){
        if(s[i]=='C'){
            if(i&&s[i-1]=='B'){
                now++;i--;
            }
            else{
                now=0;
            }
        }
        else if(s[i]=='A'){
            ans+=now;
        }
        else{
            now=0;
        }
    }
    cout<<ans;
}



Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,N) for(int i = 0;i < (int)(N);i++)
int main(){
string s;
cin>>s;
  int n=s.size();
  string t="Yes";
  rep(i,n){
   if(s[i]!=s[n-i-1]){
     t="No";
     break;
   }
  }
   rep(i,(n-1)/2){
   if(s[i]!=s[(n-1)/2-1-i]){
     t="No";
     break;
   }
  }
   rep(i,(n-1)/2){
   if(s[(n-1)/2-1-i]!=s[n-i-1]){
     t="No";
     break;
   }
  }
  cout<<t<<endl;
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define endl "\n"
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 2e+9 + 10;
typedef pair<ll, ll> P;


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

  int N,A; cin >> N >> A;
  if(N%500 <= A) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


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

#define ll long long

int main () {

    ll a, b, c, k;

    cin >> a >> b >> c >> k;

    ll sum = 0;

    if (a > k) {
        sum += k;

    } else {
        sum += a;
        k -= a;

        if (b < k) {
            k -= b;

            sum -= k;
        }
    }

    cout << sum << "\n";
}

Measured memory_bytes: 3640
N = input()
T, A = map(int, input().split())
targets = list(map(int, input().split()))
 
result = 0
min = 0
 
for i, target in enumerate(targets):
  temp = T - target * 0.006 
  if i == 0:
    result = i + 1
    min = abs( A - temp )
  elif abs( A - temp ) < min :
    result = i +1 
    min = abs( A - temp )
 
print(result)

Measured memory_bytes: 3064
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)

def main():
    k = int(input())
    s = input()[:-1]
    if len(s) <= k:
        print(s)
    else:
        print(s[:k] + '...')

if __name__ == '__main__':
    main()


Measured memory_bytes: 9172
h,w=[int(i) for i in input().split()]
s=[input() for i in range(h)]
ans=""
for i in range(h):
    for j in range(w):
        cnt=0
        if s[i][j]=="#":
            ans+="#"
        else:
            for y,x in [(i+1,j-1),(i+1,j),(i+1,j+1),(i-1,j-1),(i-1,j),(i-1,j+1),(i,j+1),(i,j-1)]:
                if x>=0 and y>=0 and y<h and x<w:
                    if s[y][x]=="#":
                        cnt+=1
            ans+=str(cnt)
    ans+="\n"
print(ans)

Measured memory_bytes: 40176
using System;
using System.Linq;

namespace _2000
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int n = int.Parse(Console.ReadLine());
                if (n == 0) break;
                int[,] gems = new int[n,2];
                for (int i = 0; i < n; i++)
                {
                    int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
                    gems[i,0] = x[0]; gems[i,1] = x[1];
                }
                bool[,] planet = new bool[21,21]; planet[10,10] = true;
                int robotx = 10; int roboty = 10;
                int m = int.Parse(Console.ReadLine());
                for (int i = 0; i < m; i++)
                {
                    string[] s = Console.ReadLine().Split();
                    for (int j = 0; j < int.Parse(s[1]); j++)
                    {
                        switch (s[0])
                        {
                            case ("E"): { robotx++; break; }
                            case ("W"): { robotx--; break; }
                            case ("N"): { roboty++; break; }
                            case ("S"): { roboty--; break; }
                        }
                        planet[robotx,roboty] = true;
                    }
                }
                bool flag = true;
                for (int i = 0; i < n; i++)
                {
                    if (!planet[gems[i,0],gems[i,1]]) flag = false;
                }
                Console.WriteLine(flag ? "Yes" : "No");
            }
        }
    }
}


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

int main(void) {
    char c1[11];
    char c2[11];
    int nc1, nc2;
    char target[11];
    scanf("%s %s", c1, c2);
    scanf("%d %d", &nc1, &nc2);
    scanf("%s", target);

    if(strcmp(c1, target) == 0) {
        --nc1;
    }
    else {
        --nc2;
    }

    printf("%d %d\n", nc1, nc2);
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void) {
	int N;
	int Hmax = 0;
	int i;
	int satousatomi = 0;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		int H;
		if (scanf("%d", &H) != 1) return 1;
		if (Hmax <= H) {
			satousatomi++;
			Hmax = H;
		}
	}
	printf("%d\n", satousatomi);
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<queue>
#include<functional>
#include<cstring>
#include<vector>
using namespace std;

long long int ans=0;
long long int res[10001];

int main(void){
	priority_queue<int, vector<int> , greater<int> > que;
	int n;
	while(1){
		ans=0;
		memset(res,0,sizeof(res));
		scanf("%d",&n);
		if(n==0)break;
		for(int i=0;i<n;i++){
			int a;
			scanf("%d",&a);
			que.push(a);
		}
		for(int i=0;i<n;i++){
			int r=que.top();que.pop();
			res[i+1]=r+res[i];
			ans+=res[i];
		//	printf("%d\n",res[i]);
		}
		printf("%lld\n",ans);
	}
    return 0;
}

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

a=0
b=0

for i in range(H):
    str = input().split()
    for j in range(W):
        if(str[j]=='snuke'):
            a=i
            b=j

print(chr(b+ord('A')), end="")
print(a+1)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;	
#pragma GCC optimize("Ofast") 
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;	i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define endl '\n'
#define PI  3.14159265358979323846
#define MOD 1000000007
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
const int N = 2e6+5;
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int ar[N];
int dp[N];
signed main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	IOS;
	int T=1;
	// cin >> T;
	while(T--){
		int n;
		cin >> n ;
		int m = n;
		n = ((n+1000-1)/1000 )* 1000;
		cout << n - m;
	
	}
	return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define All(V) v.begin(), v.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
  int n; cin >> n;
  ll t; cin >> t;
  ll ans = t;
  vector<ll> v(n);
  rep(i, n) cin >> v[i];
  for(int i = 0; i < n-1; i++){
    if(v[i+1]-v[i] <= t) ans += v[i+1]-v[i];
    else{
      ans += t;
    }
  }
  cout << ans << endl;
  system("pause");
}

Measured memory_bytes: 2040
def solve(A, B, C, X):
    ans = 0
    for i in range(A+1):
        for j in range(B+1):
            Y = 500*i + 100*j
            if ((X-Y) % 50 == 0) and (0 <= (X-Y) / 50 <= C):
                ans += 1
    return ans
print solve(input(), input(), input(), input())

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

int main() {
    int N;
    cin>>N;
    vector<int> A(N);
    int mod = 1000000007;
    long long sum = 0;
    long long temp = 0;

    for(int i=0;i<N;i++){
        cin>>A[i];
        temp += A[i];
        temp %= mod;
    }
    

    for(int i=0;i<N;i++){
        temp -= A[i];
        if(temp<0)  temp += mod;
        sum += A[i] * temp;
        sum %= mod;
    }

    cout<<sum<<endl;

    return 0;
}

Measured memory_bytes: 4036
//????????°???????????????????????°???????????????????????????????????????????????????????????????????????¨??????????????????
//????????°???????????¢????????????
//????´???????, ??°???????????¨????????°??????????????????????????§???????????????????±?????????°??????(NP-Hard?)

#include <iostream>
#include <algorithm>
using namespace std;

const int inf = 50000841;
const int m = 100;	//The range of number
	
int n;
int a, b;
int to[100][100], toSize[100];
bool vis[100] = {false};

int dfs( int pos ){
	int ret = 0;
	int i, npos;
	
	vis[pos] = true;
	for( i = 0; i < toSize[pos]; i++ ){
		npos = to[pos][i];
		if( !vis[npos] )
			ret = max(ret, dfs(npos) + 1);
	}
	vis[pos] = false;
	return ret;
}

int main(){
	int i;
	
	while( cin >> n ){
		if(!n) return 0;
		for( i = 0; i < m; i++ ) toSize[i] = 0;
		for( i = 0; i < n; i++ ){
			cin >> a >> b; a--; b--;
			to[a][toSize[a]++] = b;
			to[b][toSize[b]++] = a;
		}
		
		int ans = 0;
		for( i = 0; i < m; i++ )
			ans = max(dfs(i) + 1, ans);
		cout << ans << endl;
	}
	return 0;
}

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


class Program
{
    static void Main(string[] args)
    {
        var ab = Console.ReadLine().Split(' ');
        var a = int.Parse(ab[0]);
        var b = int.Parse(ab[1]);

        var count = 0;
        while (b > (a * count - (count -1)))
        {
            count++;
        }

        Console.Write(count);
    }
}


Measured memory_bytes: 11092
#include <map>
#include <string>
#include <iostream>
#include<vector>
#include <set>
#include<math.h>
#include<algorithm>

using namespace std;

int main()
{
	int n, amount=100;
	cin >> n;
	
	for (int i=0; i<n; i++)
	{
		amount = amount * 1.05 + 0.999;
	}
	
	cout << amount*1000 << endl;
}

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

#define pb push_back

int asd[505][505];
vector <int> ans1;
vector <int> ans2;
vector <int> ans3;
vector <int> ans4;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int z,x;
	cin>>z>>x;
	
	for(int q=1;q<=z;q++)
	{
		for(int w=1;w<=x;w++)
		{
			cin>>asd[q][w];
		}
	}
	
	for(int q=1;q<=z;q++)
	{
		for(int w=1;w<=x;w++)
		{
			if(asd[q][w]%2==1)
			{
				if(w==x && q!=z)
				{
					ans1.pb(q);
					ans2.pb(w);
					ans3.pb(q+1);
					ans4.pb(w);
					asd[q+1][w]++;
				}
				else if(w!=x)
				{
					ans1.pb(q);
					ans2.pb(w);
					ans3.pb(q);
					ans4.pb(w+1);
					asd[q][w+1]++;
				}
			}
		}
	}
	cout<<ans1.size()<<endl;
	for(int q=0;q<ans1.size();q++)
	{
		cout<<ans1[q]<<" "<<ans2[q]<<" "<<ans3[q]<<" "<<ans4[q]<<endl;
	}
}

Measured memory_bytes: 5220
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <utility>
#include <cstdlib>
#include <memory>
#include <queue>
#include <cassert>
#include <cmath>
#include <ctime>
#include <complex>
#include <bitset>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <numeric>

using namespace std;

#define ws ws_____________________
#define y1 y1_____________________
#define y0 y0_____________________
#define left left_________________
#define right right_______________
#define next next_________________
#define prev prev_________________
#define hash hash_________________

#define pb push_back
#define fst first
#define snd second
#define mp make_pair 
#define sz(C) ((int) (C).size())
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define ford(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define all(C) begin(C), end(C)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef long double ld;
typedef complex<double> cd;

#define FILE_NAME "a"


int n, a, b;
vi h;

bool read() {
	if  (scanf("%d%d%d", &n, &a, &b) < 3) {
		return 0;
	}
	h.resize(n);
	forn(i, n) {
		scanf("%d", &h[i]);
	}
	return 1;
}

bool can(int cnt) {
	ll need = 0;
	forn(i, n) {
		ll remain = h[i] - cnt * 1ll * b;
		if  (remain > 0) {
			need += (remain + (a - b) - 1) / (a - b);
		}
	}
	return need <= cnt;
}

int solve() {
	int L = 0;
	int R = int(1e9) + 10;
	while (L != R - 1) {
		int M = (L + R) >> 1;
		if  (can(M)) {
			R = M;
		} else {
			L = M;
		}
	}
	return R;
}

int main() {
#ifdef LOCAL
	freopen(FILE_NAME ".in", "r", stdin);
	// freopen(FILE_NAME ".out", "w", stdout);
#endif

	while (read()) {
		printf("%d\n", solve());
	}

#ifdef LOCAL
	cerr.precision(5);
	cerr << "Time: " << fixed << (double) clock() / CLOCKS_PER_SEC << endl;
#endif
	return 0;
}


Measured memory_bytes: 640
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] a = new int[n];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            sum += a[i];
        }
        sc.close();
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            if ((double)a[i] >= (double)sum / (4*m)) cnt++;
        }
        String res = "No";
        if (m <= cnt) res = "Yes";
        
        System.out.println(res);
    }
}

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

int n;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    if(n%10==n/100) cout<<"Yes"<<'\n';
    else cout << "No" << '\n';

    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    Int ij[10][10] = {};

    for (Int i = 1; i <= n; i++) {
        string s = to_string(i);
        ij[s[0] - '0'][s[s.size() - 1] - '0']++;
    }

    Int ans = 0;
    for (int i = 0; i < 10; i++) {
        for (int k = 0; k < 10; k++) {
            ans += ij[i][k] * ij[k][i];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int i, N, K;
	long long a[100001];
	scanf("%d %d", &N, &K);
	for (i = 1; i <= N; i++) scanf("%lld", &(a[i]));
	
	long long sum[2][100001], max = 0, tmp;
	for (i = 1, sum[0][0] = 0, sum[1][0] = 0; i <= N; i++) {
		sum[0][i] = sum[0][i-1] + a[i];
		sum[1][i] = sum[1][i-1] + ((a[i] > 0)? a[i]: 0);
	}
	for (i = 1; i <= N - K + 1; i++) {
		tmp = (sum[0][i+K-1] > sum[0][i-1])? sum[0][i+K-1] - sum[0][i-1]: 0;
		if (sum[1][i-1] + sum[1][N] - sum[1][i+K-1] + tmp > max) max = sum[1][i-1] + sum[1][N] - sum[1][i+K-1] + tmp;
	}
	
	printf("%lld\n", max);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 4056
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;
int main()
{
	int a,b;
	cin >> a >> b;
	cout << (a+b)%24 << endl;
}


Measured memory_bytes: 256
import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
void main() {
  int N=to!int(chomp(readln()));
  string[] input=split(readln());
  int[] a;
  foreach(item;input) {
    a~=to!int(item);
  }
  sort(a);
  reverse(a);
  int A=0,B=0;
  foreach(i,e;a) {
    if(i%2==0) A+=e;
    else B+=e;
  }
  writeln(A-B);
}


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int ans = 0;
  for (int i = a; i <=b; i++) {
    if (c % i == 0) {
      ans++;
    }
  }
  cout << ans << endl;
}



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

typedef long long ll;
typedef pair<int, int> P;

const int INF = 1000000007;

int main(void){
	int n,m; cin>>n>>m;
	P p[100010], q[100100];
	for(int i=0;i<m;i++){
		cin>>p[i].first>>p[i].second;
		q[i] = p[i];
	}

	sort(q , q + m);
	map<P , int> mp;
	int city = q[0].first;
	int i=0, cnt=1;
	for(int i=0;i<m;i++) {
		if(city == q[i].first) {
			mp[q[i]] = cnt;
			cnt++;
		}
		else {
			cnt = 1;
			city = q[i].first;
			i--;
		}
	}

	for(int i=0;i<m;i++) {
		printf("%06d%06d\n", p[i].first, mp[p[i]]);
	}
	

	return 0;
}

Measured memory_bytes: 9344
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vaibhav ios_base::sync_with_stdio(false);cin.tie(NULL);
 int bs(vector<int>v,int l,int r,int x)
 {
   
    while(r>=l)
    {
      if(l==r)
      {
        if(v[l]>x)
          return v[l];
        else
          return -1;
      }
      int m=(l+r)/2;

      if(v[m]<=x)
        l=m+1;
      else
        r=m;
    }

 }

int main()
{ vaibhav
int x;
 string s,t;
 cin>>s>>t;
 int qq=s.length();
 vector<int>v[26];
 for(int i=0;s[i]!='\0';i++)
 {
    x=((int)s[i])-97;
    v[x].push_back(i+1);
 }
  int val=0;
  vector<int>::iterator p;
  ll sum=0;
  int f=0;
  // x=((int)'t')-97;
  // p=bs(v[x],0,v[x].size()-1,3);
  //   cout<<p<<endl;

 for(int i=0;t[i]!='\0';i++)
 {
   x=((int)t[i])-97;
    
    if(v[x].size()==0)
    {
      f=1;break;
    }
   p=upper_bound(v[x].begin(),v[x].end(),val);
   if(p!=v[x].end())
   {
    sum=sum+(*p-val);
    val=*p;
   }
   else
   {  sum=sum+(qq-val);
      p=upper_bound(v[x].begin(),v[x].end(),0);
      sum=sum+*p;
      val=*p;
   }

 }

 if(f==1)
  cout<<-1;
else
  cout<<sum;


  return 0;
  
}

 

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

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  long long h;
  cin >> h;
  long long ans = 0;
  function<long long(long long)> go = [&](long long x) {
    if(x == 0) return x;
    return 1 + 2 * go(x >> 1);
  };
  cout << go(h) << '\n';
}

Measured memory_bytes: 256