akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>

//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<int>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#include <time.h>
typedef std::pair<int,int> pii;
using namespace std;
using ll = long long;
#define PI 3.14159265358979323846264338327950L
const int mod =  998244353;



map<int,int> prime(int n ){
    map<int,int> ret;
    while(n%2 == 0){
        n/=2;
        ret[2]++;
    }
    for(int i = 3; i*i <= n; i = i + 2){
        while(n%i == 0){
            n/=i;
            ret[i]++;
        }
    }
    if (n>2) ret[n]++;
    return ret;
}

bool ok;

void dfs(vector<int>& ps, vector<int>& pw, int i, int v,map<int,int>& seen){
    if (i == pw.size()){
        if (v==1) return;
        ok |= seen[v];
        //cout << v << endl;
        return;
    }
    for(int j = 0; j <= pw[i]; j++){
        dfs(ps,pw,i+1,v*pow(ps[i],j),seen);
    }
}

bool check(map<int,int>& p, map<int,int>& seen){
    ok = false;
    vector<int> ps,pw;
    for(auto e:p){
        ps.push_back(e.first);
        pw.push_back(e.second);
    }
    dfs(ps,pw,0,1,seen);
    return ok;
}

void solveD(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    SORT(a);
    if (a[0] == a[n-1]){
        cout << 0;
        return;
    }
    int ans = 0;
    map<int,int> seen;
    
    for(int i = 0; i < n; i++){
        auto p = prime(a[i]);
        
        if (check(p,seen)) ans++;
        seen[a[i]] = 1;
    }
    
    cout << n - ans;
}

void solveC(){
    int x,n;
    cin >> x >> n;
    map<int,int> seen;
    rep(i,n){
        int p;
        cin >> p;
        seen[p] = 1;
    }
    int diff = 1001001001;
    int ans = 0;
    for(int i = -1000; i <= 1000; i++){
        if (seen[i]) continue;
        if (abs(i-x) < diff){
            diff = abs(i-x);
            ans = i;
        }
    }
    cout << ans;
}


void solveB(){
    int x,y;
    cin >> x >> y;
    if (y%2==1){
        cout << "No";
        return;
    }
    int b = y-2*x;
    b/=2;
    int a = x - b;
    
    if (a>=0 && b>=0){
        cout <<"Yes";
        return;
    }
    cout << "No";
}

void solveA(){
    rep(i,5){
        int x;
        cin >> x;
        if (x==0){
            cout << i+1;
            return;
        }
    }
}

int main(){
    int T;
    T = 1;
    while(T--){
        solveB();
        cout << endl;
    }
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;





void solve(){
    using P = array<int, 30>;
    P X;
    for (auto &&i : X) scanf("%d", &i);
    vector<P> ok{};
    vector<array<int, 10>> shifts{{0, 3, 6, 9, 15, 23, 26, 29, 20, 17}, {2, 5, 8, 11, 12, 21, 24, 27, 18, 14},
                                 {0, 1, 2, 14, 18, 27, 28, 29, 15, 20}, {6, 7, 8, 12, 9, 21, 22, 23, 17, 11}};
    int ans = 8;
    auto dfs = [&](int dep, P A, auto &&f) -> void {
        if(dep >= ans) return;
        int ok = 1;
        for (int i = 0; i < 8 && ok; ++i) {
            if(A[i] != A[i+1]) ok = 0;
            if(A[i+21] != A[i+22]) ok = 0;
        }
        for (int i = 0; i < 2 && ok; ++i) {
            if(A[i+9] != A[i+10]) ok = 0;
            if(A[i+12] != A[i+13]) ok = 0;
            if(A[i+15] != A[i+16]) ok = 0;
            if(A[i+18] != A[i+19]) ok = 0;
        }
        if(ok){
            ans = min(ans, dep);
            return;
        }
        for (auto &&S : shifts) {
            auto B = A;
            for (int i = 0; i < 5; ++i) {
                swap(B[S[i]], B[S[i+5]]);
            }
            f(dep+1, B, f);
        }
    };
    dfs(0, X, dfs);
    cout << ans << "\n";
}

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3244
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, groupby
from math import floor, ceil, sqrt, factorial, log
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop
from itertools import product
import sys
stdin = sys.stdin
mod = 10**9 + 7


def ns(): return stdin.readline().rstrip()


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


x = ni()
ans = 1
for b in range(2, 100):
    for p in range(2, 10):
        if b**p <= x:
            ans = max(ans, b**p)
print(ans)


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int l, r;
  l = a + b, r = c + d;
  if(l > r) {
    cout << "Left" << endl;
  }
  else if(l == r) {
    cout << "Balanced" << endl;
  }
  else if(l < r) {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
n=int(input())
k=int(input())
x=list(map(int,input().split()))
ct=0
for i in range(n):
    if (x[i]*2)<(abs(k-x[i])*2):
        ct+=(x[i]*2)
    else:
        ct+=(abs(k-x[i])*2)
print(ct)

Measured memory_bytes: 3060
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let a: usize = read!();
    let b: usize = read!();
    let c: usize = read!();

    let ans = if a == b && b == c { "Yes" } else { "No" };
    println!("{}", ans);
}


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

#define ll long long
#define sd(x) scanf("%d", &(x))
#define pii pair<int, int>
#define F first
#define S second
#define all(c) ((c).begin()), ((c).end())
#define sz(x) ((int)(x).size())
#define ld long double

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<", "<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"{";
	for(int i = 0;i < (int)v.size(); i++){
		if(i)os<<", ";
		os<<v[i];
	}
	os<<"}";
	return os;
}

#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::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...);
}
#else
#define trace(...)
#endif

struct dsu{
    int n;
    vector<int> par;
    vector<vector<int>> comp;
    int num;
    dsu(int n) : n(n), par(n), comp(n), num(n){
        iota(par.begin(), par.end(), 0);
    }
    int root(int x){
        return x == par[x] ? x : (par[x] = root(par[x]));
    }
    bool merge(int x, int y){
        x = root(x); y = root(y);
        if(x == y) return 0;
        par[x] = y;
        num--;
        return 1;
    }
    void get(){
        for(int i = 0; i < n; i++) comp[root(i)].push_back(i);
    }
};


int a[100005];
int main(){
    int n, m; sd(n); sd(m);
    for(int i = 0; i < n; i++) sd(a[i]);
    dsu D(n);
    for(int i = 0; i < m; i++){
        int u, v;
        sd(u); sd(v);
        D.merge(u, v);
    }
    if(D.num == 1){
        printf("0\n");
        return 0;
    }
    D.get();
    vector<int> rem;
    ll ans = 0;
    int num = 0;
    for(int i = 0; i < n; i++) if(!D.comp[i].empty()){
        vector<int> V = D.comp[i];
        sort(all(V), [&](int i, int j){
            return a[i] < a[j];
        });
        ans += a[V[0]];
        for(int j = 1; j < sz(V); j++) rem.push_back(a[V[j]]);
    }
    if(sz(rem) < D.num - 2){
        printf("Impossible\n");
        return 0;
    }
    sort(all(rem));
    for(int i = 0; i < D.num - 2; i++) ans += rem[i];
    printf("%lld\n", ans);
}

Measured memory_bytes: 6528
#include <stdio.h>
#define W 0
#define G 1
#define B 2

int M[100][100],n,d[100],que[100],qf=0,qb=0,c[100];
void enque(int x)
{
  que[qb]=x;
  qb=(qb+1)%100;
}

int deque(void)
{
  int x;
  x=que[qf];
  qf=(qf+1)%100;
  return x;
}

void bfs(void)
{
  int u,v;
  for(u=0;u<n;u++)
    {
      d[u]=-1;
      c[u]=W;
    }
  c[0]=G;
  d[0]=0;
  enque(0);
  while(qf!=qb)
    {
      u=deque();
      for(v=0;v<n;v++)
	{
	  if(M[u][v]==1&&c[v]==W)
	    {
	      c[v]=G;
	      d[v]=d[u]+1;
	      enque(v);
	    }
	}
      c[u]=B;
    }

  for(u=0;u<n;u++)
    {
      printf("%d %d\n",u+1,d[u]);
    }
}
  

int main()
{
  int i,j;
  scanf("%d",&n);

  for(i=0;i<n;i++)
    {
      for(j=0;j<n;j++)
	{
	  M[i][j]=0;
	}
    }

  int k,u,v;
  
  for(i=0;i<n;i++)
    {
      scanf("%d",&u);
      scanf("%d",&k);
      for(j=0;j<k;j++)
	{
	  scanf("%d",&v);
	  M[u-1][v-1]=1;
	}
    }

  bfs();

  return 0;
}



Measured memory_bytes: 2112
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N, A, B;
  cin >> N >> A >> B;

  if (abs(A - B) % 2 == 0) {
    cout << abs(A - B) / 2 << endl;
    return 0;
  }

  cout << min(A - 1, N - B) + abs(B - A - 1) / 2 + 1 << endl;

  return 0;
}


Measured memory_bytes: 256
class Dice
  attr_accessor :face

  def rotate(dir)
    case dir
    when "N"
      @face[0],@face[1],@face[5],@face[4] = @face[1],@face[5],@face[4],@face[0]
    when "E"
      @face[0],@face[2],@face[5],@face[3] = @face[3],@face[0],@face[2],@face[5]
    when "S"
      @face[0],@face[1],@face[5],@face[4] = @face[4],@face[0],@face[1],@face[5]
    when "W"
      @face[0],@face[2],@face[5],@face[3] = @face[2],@face[5],@face[3],@face[0]
    when "cw" #ClockWise rotation
      self.rotate("E").rotate("N").rotate("W")
    end
    return self
  end

  def aline_dir(top, front)
    alined_dice = []
    self.face.each_with_index do |item, index|
      dice_clone = Marshal.load(Marshal.dump(self))
      if item == top
        case index
        when 1
          dice_clone.rotate("N")
        when 2
          dice_clone.rotate("W")
        when 3
          dice_clone.rotate("E")
        when 4
          dice_clone.rotate("S")
        when 5
          dice_clone.rotate("N").rotate("N")
        end
        (1..4).each do |i|
          dice_clone2 = Marshal.load(Marshal.dump(dice_clone))
          if dice_clone.face[i] == front
            case i
            when 2
              dice_clone2.rotate("cw")
            when 3
              dice_clone2.rotate("cw").rotate("cw").rotate("cw")
            when 4
              dice_clone2.rotate("cw").rotate("cw")
            end
            alined_dice.push(dice_clone2.face)
          end
        end
      end
    end
    return alined_dice
  end
  
  def same?(dice_alined)
    bool = false
    dice_alined.each do |item|
      bool = true if self.face.eql?(item)
    end
    return bool
  end
end

dices = []
n = gets.chomp.to_i
n.times do |i|
  dices.push(Dice.new)
  dices[i].face = gets.chomp.split.map(&:to_i)
end

i = 0
bool = false
n.times do |i|
  for j in i+1..n-1
    alined_dice = dices[j].aline_dir(dices[i].face[0], dices[i].face[1])
    bool = true if dices[i].same?(alined_dice)
  end
end
puts bool == true ? "No" : "Yes"

Measured memory_bytes: 6224
class Array
  def sum; inject(:+) end # v2.5
end
def min(a,b); a < b ? a : b end

h,w,k = gets.to_s.split.map(&:to_i)
a = Array.new(h){ gets.to_s.chomp.bytes }.transpose

ans = (h-1) * (w-1)
[0, 1].repeated_permutation(h-1) do |bit|
  div  = [0] * h
  t    = 0
  able = true
  (0...h-1).each do |i|
    t += 1 if bit[i] == 1
    div[i+1] = t
  end
  wc = [0] * (t+1)
  cut = bit.sum
  w.times do |j|
    over = false
    h.times do |i|
      wc[div[i]] += 1 if a[j][i] == 49
      if wc[div[i]] > k
        over = true
        break
      end
    end
    if over
      (t+1).times{|k| wc[k] = 0 }
      cut += 1
      h.times do |i|
        wc[div[i]] += 1 if a[j][i] == 49
        if wc[div[i]] > k
          able = false
          break
        end
      end
    end
    
    break if not able
  end
  ans = min(ans, cut) if able
end

p ans


Measured memory_bytes: 2172
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Buffer(make([]byte, 500000), 500000)
	sc.Split(bufio.ScanWords)

	n := nextInt()
	v := make([]int, n)

	for i := range v {
		v[i] = nextInt()
	}

	sort.Ints(v)

	res := float64(v[0])
	for i := 1; i < n; i++ {
		res = (res + float64(v[i])) / 2.0
	}
	fmt.Println(res)
}

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

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextInt64() int64 {
	sc.Scan()
	i, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return i
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);};};
const ll MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<62;

struct Corr{
    int y;
    int x;
    int depth;
};

queue<Corr> q;
set<pair<int,int> > s;

void bfs(vector<string> &v, vvi &dist) {
    while(!q.empty()) {
        Corr now = q.front();q.pop();
        // cout<<now.y<<" "<<now.x<<endl;
        dist[now.y][now.x]=now.depth;
        int dx[] = {1,-1,0,0};
        int dy[] = {0,0,1,-1};
        for(int i=0;i<4;i++){
            int nextx = now.x+dx[i];
            int nexty = now.y+dy[i];
            if(nextx<0||nextx>=dist[0].size()||nexty<0||nexty>=dist.size())continue;
            if(dist[nexty][nextx]<=now.depth+1)continue;
            if(s.count(mp(nextx,nexty))>0)continue;
            Corr c={nexty,nextx,now.depth+1};
            q.push(c);
            s.insert(mp(nextx,nexty));
        }
    }
}


int main(void) {

    int n,m;
    cin>>n>>m;
    vs v(n);
    // cout<<"AAAAA\n"<<endl;
    rep(i,n){
        string s;
        cin>>s;
        v[i]=s;
    }

    vvi dist(n, vi(m,INF));

    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(v[i][j]=='#'){
                Corr c={i,j,0};
                dist[i][j]=0;
                q.push(c);
            }
        }
    }
    bfs(v,dist);
    int ans=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            ans=max(ans,dist[i][j]);
        }
    }
    fin(ans);

    // for(int i=0;i<n;i++){
    //     for(int j=0;j<m;j++){
    //         cout<<dist[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }

}


Measured memory_bytes: 52864
#include<stdio.h>
#include<algorithm>
using namespace std;
int p[1100];

int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++){
		int c,d;
		scanf("%d%d",&c,&d);
		for(int i=c;i<d;i++)p[i]++;
	}
	int ret=a+1;
	for(int i=1;i<=a;i++)if(p[i])ret+=2;
	printf("%d\n",ret);
}

Measured memory_bytes: 1032
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;     //  必须为质数才管用
const ll MAXN = 2e5 + 3;

ll fac[MAXN];       //  阶乘
ll inv[MAXN];       //  阶乘的逆元

ll QPow(ll x, ll n)
{
    ll ret = 1;
    ll tmp = x % MOD;
    while (n)
    {
        if (n & 1)
        {
            ret = (ret * tmp) % MOD;
        }
        tmp = tmp * tmp % MOD;
        n >>= 1;
    }

    return ret;
}

void Init()
{
    fac[0] = 1;
    for (int i = 1; i < MAXN; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
    }
    inv[MAXN - 1] = QPow(fac[MAXN - 1], MOD - 2);
    for (int i = MAXN - 2; i >= 0; i--)
    {
        inv[i] = inv[i + 1] * (i + 1) % MOD;
    }
}
ll C(int a,int b) {
    if(a<0||b<0)return 1;
    return fac[a]*inv[b]%MOD*inv[a-b]%MOD;
}
int main() {
	int H,W,A,B;
	int N;
    scanf("%d%d%d%d",&H,&W,&A,&B);
    N=H+W-2;
    Init();
    ll ans=C(H+W-2,H-1);
    for(ll i=1;i<=B;i++) {
        ans-=C(H-A+i-2,H-A-1)*C(A-1+W-i,A-1)%MOD;
        ans=(ans%MOD+MOD)%MOD;
    }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int a,b,c,d;
char ca,cb,cc,cd;
int main()
{
	cin>>ca>>cb>>cc>>cd;
	a=ca-48;
	b=cb-48;
	c=cc-48;
	d=cd-48;
	if (a+b+c+d==7)
	{
		printf("%d+%d+%d+%d=7",a,b,c,d);
		return 0;
	}
	if (a-b+c+d==7)
	{
		printf("%d-%d+%d+%d=7",a,b,c,d);
		return 0;
	}
	if (a+b+c-d==7)
	{
		printf("%d+%d+%d-%d=7",a,b,c,d);
		return 0;
	}
	if (a+b-c+d==7)
	{
		printf("%d+%d-%d+%d=7",a,b,c,d);
		return 0;
	}
	if (a+b-c-d==7)
	{
		printf("%d+%d-%d-%d=7",a,b,c,d);
		return 0;
	}
	if (a-b+c-d==7)
	{
		printf("%d-%d+%d-%d=7",a,b,c,d);
		return 0;
	}
	if (a-b-c+d==7)
	{
		printf("%d-%d-%d+%d=7",a,b,c,d);
		return 0;
	}
	if (a-b-c-d==7)
	{
		printf("%d-%d-%d-%d=7",a,b,c,d);
		return 0;
	}
}

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

int main(){
    int N;
    cin >> N;
    map<string,int> M;
    int m = 0;
    rep(i,N){
        string S;
        cin >> S;
        M[S]++;
        m = max(m,M[S]);
    }
    set<string> st;
    for(auto it = M.begin();it != M.end();it++){
        if(it->second == m)st.insert(it->first);
    }
    for(auto it = st.begin();it != st.end();it++){
        cout << *it << endl;
    }

    return 0;
}

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

int all(char c, string S) {
  for (char s : S) {
    if (s != c) return 0;
  }
  return 1;
}

int f(char c, string S) {
  int ret = 0;
  while (!all(c, S)) {
    string S2 = S.substr(0, S.size()-1);
    for (int i = 0; i < S2.size(); i++) {
      if (S[i] == c || S[i+1] == c) S2[i] = c;
    }
    S = S2;
    ret++;
  }
  return ret;
}

int main() {
  string S;
  cin >> S;
  int ans = S.size();
  for (char c = 'a'; c <= 'z'; c++) {
    if (S.find(c) == string::npos) {
      continue;
    }
    ans = min(ans, f(c, S));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n=parseInt(readline())
    ans=0
    for i in 1:trunc(Int,sqrt(n))+1
        if n%i==0
            if i>1 && n%(i-1)==n÷(i-1)
                ans+=i-1
            end
            tmp=n÷i
            if tmp>1 && n%(tmp-1)==n÷(tmp-1)
                ans+=n÷i-1
            end
        end
    end
    println(ans)
end
main()

Measured memory_bytes: 135100
N = int(input())
H = list(map(int,input().split()))
ans = 0
cnt = 0
for i in range(N-1):
      if H[i] >= H[i+1]:
          cnt += 1
      else:
          ans = max(ans,cnt)
          cnt = 0
      if i+2 == N:
        print(max(ans,cnt))
        exit()
print(ans)

Measured memory_bytes: 15020
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#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()
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}

void solve(int a, int b) {
  if (a == b) {
    cout << "a == b" << endl;
  } else if (a > b) {
    cout << "a > b" << endl;
  } else {
    cout << "a < b" << endl;
  }
}

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

  int a, b; cin >> a >> b;
  solve(a, b);

  return 0;
}


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

#define Mset(s, n)      memset(s, n, sizeof(s))
#define Rp0(i, m)       for(int i = 0; i < m; ++i)
#define Rpd(i, m, l)    for(int i = m; i >= l; --i)
#define Rp1(i ,m)       for(int i = 1; i <= m; i++)
#define All(a)          (a).begin(), (a).end()
#define Lwb             lower_bound
#define Upb             upper_bound
#define Sz(a)           int((a).size())
#define Count_bit(x)    __builtin_pop(x)
#define u_map           unordered_map
#define fi              first
#define se              second
#define pb              push_back
#define pf              push_front
#define is              insert
#define ooi             2000000000
#define ool             LLONG_MAX
#define ll              long long
#define ull             unsigned ll
#define ld              long double
#define pii             pair<int, int>
#define vi              vector<int>
#define vpii            vector<pii>

const ll MOD = (ll) 1e9 + 7;
const ld PI = acos((ld) -1);
inline int Get_bit(int x, int k){return (x >> (k - 1)) & 1;}
inline ll Gcd(ll a, ll b) {ll r; while(b){ r = a % b; a = b; b = r;} return a;}
inline ll Lcm(ll a, ll b) {return a / Gcd(a, b) * b;}
inline ll Pow(ll n, ll k) {ll r = 1; for(; k; k >>= 1, n = n * n % MOD){if(k & 1) r = r * n % MOD;} return r;}
const int base = 311;


const int N = 3e5;

int n, m, k, q, ans, a[N];
inline void Solve(){
    cin >> n >> k >> q;
    int mx = 0;
    for(int i = 1; i <= q; i++){
        int x;
        cin >> x;
        a[x]++;
        mx = max(mx, a[x]);
    }
    for(int i = 1; i <= n; i++){
        if(a[i]-q +k > 0) cout <<"Yes\n"; else cout << "No\n";
    }
}


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(10);
    Solve();
    return 0;
}


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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int x; cin >> x;
  int ans;
  
  if(400<=x && x<=599) ans = 8;
  else if(600<=x && x<=799) ans = 7;
  else if(800<=x && x<=999) ans = 6;
  else if(1000<=x && x<=1199) ans = 5;
  else if(1200<=x && x<=1399) ans = 4;
  else if(1400<=x && x<=1599) ans = 3;
  else if(1600<=x && x<=1799) ans = 2;
  else ans = 1;

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


Measured memory_bytes: 3632
# aを1番目の値、2~n-1番目の値、n番目の値と3つに分けて考えてリストに追加
n = int(input())
b = list(map(int, input().split()))

a = []

# aの1番目の値
a.append(b[0])

# aの2~n-1番目の値
b_len = len(b)
for i in range(b_len-1):
    ai = min(b[i], b[i+1])
    a.append(ai)

# aのn番目の値
a.append(b[-1])

print(sum(a))

Measured memory_bytes: 3064
using System;

namespace Aizu
{
    class Program
    {
        static void Main()
        {
            string[] str = Console.ReadLine().Split();
            var a = int.Parse(str[0]);
            var b = int.Parse(str[1]);
            if(a < b){
                Console.WriteLine("a < b");
            } else if(a > b){
                Console.WriteLine("a > b");
            } else if(a == b){
                Console.WriteLine("a == b");
            }
        }
    }
}



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

using namespace std;

using ll = long long;
using Point = pair<int, int>;

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

    int n, k;

    cin >> n >> k;
    vector<Point> p(n);
    vector<int> y(n);
    vector<int> idx(n);
    int size;

    for (int i = 0; i < n; ++i) {
        cin >> p[i].first >> p[i].second;
        y[i] = p[i].second;
    }

    sort(p.begin(), p.end());
    sort(y.begin(), y.end());

    ll min_area = (ll)(y[n - 1] - y[0]) * (ll)(p[n - 1].first - p[0].first);
    for (int by = 0; by < n; ++by) {
        for (int ty = by + 1; ty < n; ++ty) {
            size = 0;
            for (int i = 0; i < n; ++i)
                if (y[by] <= p[i].second && p[i].second <= y[ty])
                    idx[size++] = i;

            int lb = 0;
            while (lb + k - 1 < size) {
                min_area = min(min_area, (ll)(y[ty] - y[by]) * (ll)(p[idx[lb + k - 1]].first - p[idx[lb]].first));
                ++lb;
            }
        }
    }

    cout << min_area << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define INF 0x3f3f3f3f
#define eps 1e-8
using namespace std;
const ll maxn = 1e6 + 5;
ll a,b,c,ans;
string str;
int main()
{
    cin >> a >> b;
    if(a == 1 || b == 1)
        return puts("1") * 0;
    cout << (a / 2 + a % 2) * (b / 2 + b % 2) + (a / 2) * (b / 2)<< endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string a,b;
	cin>>a>>b;
	long long n=0;
	for(int i=0;i<a.size();i++){
		if(a[i]!=b[i]){
			n++;
		}
	}
	cout<<n<<endl;
	return 0;
}

Measured memory_bytes: 3928
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,p;
ll ans=1;
int main(){
	cin>>n>>p;
	if(n==1){
		cout<<p<<endl;
		return 0;
	}
	for(int i=2;i<=sqrt(p);i++){
		if(p%i==0){
			int cnt=0;
			while(p%i==0){
				cnt++;
				p/=i;
				if(cnt%n==0) ans*=i;
			}
		}
		if(p==1) break;
	}
	cout<<ans<<endl;
	return 0;	
}

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

static const int MAX =100;
static const int INFTY = (1<<21);
static const int black= 2;
static const int gray= 1;
static const int white= 0;

int n,M[MAX][MAX];

void d()
{
  int i,u,j,minv;
  int d[MAX],iro[MAX];

  for(i=0;i<n;i++)
    {
      d[i] = INFTY;
      iro[i] = white;
    }

  d[0] = 0;
  iro[0] = gray;
  while(1)
    {
      minv = INFTY;
      u = -1;
      for(i=0;i<n;i++)
	{
	  if(minv > d[i] && iro[i] != black)
	    {
	      u = i;
	      minv = d[i];
	    }
	}
      if(u==-1) break;
      iro[u] = black;
      for(j=0;j<n;j++)
	{
	  if(iro[j] != black && M[u][j] != INFTY)
	    {
	      if( d[j] > d[u] + M[u][j])
		{
		  d[j] = d[u] + M[u][j];
		  iro[j] = gray;
		}
	    }
	}
    }

  for(int i =0;i < n;i++)
    {
      cout << i << " " << ( d[i] == INFTY ? -1 : d[i] ) << endl;
    }
}

int main()
{
  cin >> n;
  for( int i = 0; i < n; i++)
    {
      for(int p = 0; p < n; p++)
	{
	  M[i][p] = INFTY;
	}
    }

  int k,c,u,v;
  for(int i =0 ; i < n ; i++)
    {
      cin >> u >> k;
      for(int p = 0; p < k; p++)
	{
	  cin >> v >> c;
	  M[u][v] = c;
	}
    }
  d();

  return 0;
}



Measured memory_bytes: 3132
S = input()
U = int(S[:2])
L = int(S[2:])

def month(n):
  if 1 <= n <= 12:
    return True
  else:
    return False

if month(U) == True and month(L) == True:
  print("AMBIGUOUS")
elif month(U) == True and month(L) == False:
  print("MMYY")
elif month(U) == False and month(L) == True:
  print("YYMM")
else:
  print("NA")

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

int A[200][2], B[2000][2], M, N;
int main()
{
  while(true)
  { 
    cin >> M;
    if(!M)
      break;
    for(int i = 0; i < M; i++)
      cin >> A[i][0] >> A[i][1];
    cin >> N;
    for(int i = 0; i < N; i++)
      cin >> B[i][0] >> B[i][1];
    for(int i = 0; i < N; i++)
    {
      int dx = B[i][0] - A[0][0];
      int dy = B[i][1] - A[0][1];
      int mn = 0;
      for(int j = 0; j < M; j++)
      {
        for(int k = 0; k < N; k++)
        {
          if(A[j][0] + dx == B[k][0] && A[j][1] + dy == B[k][1])
            mn++;
        }
      }
      if(mn == M)
      {
        cout << dx << " " << dy << endl;
        break;
      }
    }
  }
}

Measured memory_bytes: 1176
import sys

S = list(input())
T = list(input())

if len(S) < len(T):
    print("UNRESTORABLE")
    sys.exit()

ans = []

for i in range(len(S)-len(T)+1):
    for j, k in enumerate(S[i:i+len(T)]):
        if k == T[j] or k == "?":
            continue
        else: break
    else:
        box = S.copy()
        count = 0
        for x in range(len(S)):
            if i <= x < i + len(T):
                box[x] = T[count]
                count += 1
            elif box[x] != "?":
                continue
            else:
                box[x] = "a"
        ans.append(box)
ans = sorted(ans)
if len(ans) == 0:
    print("UNRESTORABLE")
else:
    print("".join(ans[0]))

Measured memory_bytes: 3064
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        double psum =0;
        for(int i = 0; i< N; i++){
            double p_i = 1;
            int point = i+1;
            while(point < K){
                point *= 2;
                p_i *= 0.5;
            }
            psum += p_i;
        }
        psum /= N;
        System.out.println(psum);
    }
}



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

using ll = long long;
const int MOD = 1e9 + 7;

int main() {
    int N;  cin >> N;
    vector<ll> A(N);
    ll sum = 0;
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        sum = (sum + A[i]) % MOD;
    }
    ll ans = 0;
    for (int i = 0; i < N; ++i) {
        sum -= A[i];
        while (sum < 0) sum += MOD;
        sum %= MOD;
        ans = (ans + A[i] * sum) % MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4832
from collections import Counter as c
n = int(input())
d = list(map(int, input().split()))
m = int(input())
t = list(map(int, input().split()))
flag = True
d_c = c(d)
t_c = c(t)
if n<m: flag = False
else: 
    for i,j in t_c.items():
        if d_c[i] < j:
            flag = False
            break
print('YES' if flag else 'NO')


Measured memory_bytes: 57048
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=2e5+5;
struct eg{int v,nx;}e[N<<1];int head[N],tot;
inline void add(R int u,R int v){e[++tot]={v,head[u]},head[u]=tot;}
int st[N],vis[N],top,n,m;
void dfs(int u){vis[u]=1;go(u)if(!vis[v]){st[++top]=v,dfs(v);break;}}
int main(){
	scanf("%d%d",&n,&m);
	for(R int i=1,u,v;i<=m;++i)scanf("%d%d",&u,&v),add(u,v),add(v,u);
	st[++top]=1,dfs(1),reverse(st+1,st+1+top),dfs(1);
	printf("%d\n",top);
	fp(i,1,top)printf("%d ",st[i]);
	return 0;
}

Measured memory_bytes: 3968
n = int(input())
val_j = list(map(int, input().split()))
cost = list(map(int, input().split()))
profit = [0]*n
total_p = 0
for i in range(0, n):
    profit[i] = val_j[i] - cost[i]
for i in profit:
    if i > 0:
        total_p += i
print(total_p)

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iomanip>
#include <vector>
#include <cstdio>
#include <float.h>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <stack>
#include <functional>
 
using namespace std;
 
#define endl '\n'
#define MOD 1000000007
#define INF 1ll<<30
#define MAX 100010
#define eps 1e-11
#define bit_max 1ll<<32
#define _USE_MATH_DEFINES
 

 
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("./input.txt","r",stdin);
   // freopen("./output.txt","w",stdout);
    int a,b;
    cin>>a>>b;
    if(2*b>=a)
    {
        cout<<0<<endl;
    }
    else
    {
        cout<<a-(2*b);
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<vector>
#include<functional>

using namespace std;

#ifdef DEBUG
#define dprintf      printf
#define dout(x)      cout<<#x" = "<<(x)<<endl
#define darray(x,n)    {int i;rep(i,n)cout<<#x"["<<i<<"] = "<<*((x)+i)<<endl;}
#define dloop(i,s,g) for((i)=(s);(i)<(g);(i)++)
#define drep(i,n)    for((i)=0;(i)<(n);(i)++)
#define dstop()      scanf("%*c")
#else
#define dprintf      (1)?0:printf
#define dout(x)
#define darray(x,n)
#define dloop(i,s,g) if(1){}else
#define drep(i,n)    if(1){}else
#define dstop()      if(1){}else
#endif

#define F    first
#define S    second
#define pb   push_back
#define mp   make_pair

#define loop(i,s,g) for((i)=(s);(i)<(g);(i)++)
#define rep(i,n)    for((i)=0;(i)<(n);(i)++)
#define all(x)      (x.begin(),x.end())
#define in(T,...) T __VA_ARGS__; impl(__VA_ARGS__);
#define array(T,id,n) T id[n]; rep(i,n)cin>>id[i];

//#define int long long;
#ifndef int
#define INF  (0x7fffffff)
#else
#define LINF (0x7fffffffffffffff)
#endif

typedef  long long           ll;
typedef  unsigned            ui;
typedef  unsigned long long  ull;
typedef  pair<int,int>       i_i;
typedef  pair<ll,int>        ll_i;
typedef  pair<ll,ll>         ll_ll;
typedef  pair<double,int>    d_i;
typedef  pair<double,double> d_d;

void impl(){};
template <typename T,typename... TS >
void impl(T &head,TS &... tail)
{
  cin>>head;
  impl(tail ...);
}

signed main()
{  
  int a;
  int n;
  ll dp[101][21]={};
  int i,j;
 
  cin>>n;
  cin>>a;
  dp[0][a]=1;
 
  for(i=1;i<n-1;i++)
    {
      cin>>a;
      for(j=0;j<=20;j++)
	{
	  if(j-a>=0)
	    dp[i][j-a]+=dp[i-1][j];
	  if(j+a<=20)
	    dp[i][j+a]+=dp[i-1][j];
	}
    }
  cin>>a;
  cout<<dp[n-2][a]<<endl;
}

Measured memory_bytes: 3096
s = raw_input()
k = int(raw_input())

opreq = [(ord('z') - ord(c) + 1) % 26 for c in s]

s_ = []

if len(s) > 1:
    i = 0
    while i < len(s) - 1:
        if opreq[i] <= k:
            k = k - opreq[i]
            s_.append('a')
        else:
            s_.append(s[i])
        i += 1

# Last character
last_c = chr((k + ord(s[-1]) - ord('a')) % 26 + ord('a'))
s_.append(last_c)

print("".join(s_))

Measured memory_bytes: 4460
n,p = map(int,input().split())
a = [int(i) for i in input().split()]

fac = [1]*(n+1)
for i in range(2,n+1): fac[i] = fac[i-1]*i
def comb(n,k):
    if n < k: return 0
    if n < 0 or k < 0: return 0
    return fac[n]//(fac[k]*fac[n-k])

even = odd = 0
for i in range(n):
    if a[i]%2 == 0: even += 1
    else: odd += 1

cnte = cnto = 0
for i in range(even+1): cnte += comb(even,i)
for i in range(odd+1)[p::2]: cnto += comb(odd,i)
print(cnte*cnto)

Measured memory_bytes: 9180
n,k = map(int, input().split())
a = list(map(int, input().split()))
def d(n,k,a):
    b=[0]*41
    for i in a:
        for j in range(41):
            if (i>>j)&1==1:
                b[j] += 1
    return c(0,0,40,n,k,b)
def c(h,x,m,n,k,b):
    if m<0:
        return h
    g=(1<<m)
    y=x+g
    z=n-b[m]
    u=b[m]
    v=0
    w=0
    if u>z:
        v = c(h+g*u,x,m-1,n,k,b)   
    else:
        if y <= k:
            w = c(h+g*z,y,m-1,n,k,b)
        else:
            v = c(h+g*u,x,m-1,n,k,b)
    return max(v,w)
print(d(n,k,a))

Measured memory_bytes: 14980
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;

const int N_MAX = 2005;

int X[N_MAX], Y[N_MAX];

int main(){
    int n, z, w;
    int a[N_MAX];

    scanf("%d %d %d", &n, &z, &w);
    for(int i = 1; i <= n; i++){
        scanf("%d", &a[i]);
    }

    for(int i = n-1; i >= 1; i--){
        int nextx = abs(a[i] - a[n]);
        int nexty = abs(a[i] - a[n]);
        for(int j = i+1; j <= n-1; j++){
            nextx = min(nextx, Y[j]);
            nexty = max(nexty, X[j]);
        }
        X[i] = nextx;
        Y[i] = nexty;
    }

    int nowx = z;
    int nowy = w;
    int turn = 1;
    int card = 0;
    while(card < n){
        if (turn % 2 == 1){
            int xd = n;
            int xp = abs(nowy - a[n]);
            for(int j = card + 1; j <= n-1; j++){
                if (X[j] > xp){
                    xd = j;
                    xp = X[j];
                }
            }
            nowx = a[xd];
            card = xd;
        }
        if (turn % 2 == 0){
            int yd = n;
            int yp = abs(nowx - a[n]);
            for(int j = card + 1; j <= n-1; j++){
                if (Y[j] < yp){
                    yd = j;
                    yp = Y[j];
                }
            }
            nowy = a[yd];
            card = yd;
        }
        turn++;
    }
    printf("%d\n", abs(nowx - nowy));
    return 0;
}

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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()

int main(){
    ll n, m, l;
    cin >> n >> m >> l;
    vvll d(n, vll(n, INT_MAX));
    rep(i, n) d[i][i] = 0;
    rep(i, m){
        ll a, b, c;
        cin >> a >> b >> c;
        d[a-1][b-1] = d[b-1][a-1] = c;
    }
    ll q;
    cin >> q;
    vll s(q), t(q);
    rep(i, q) cin >> s[i] >> t[i];

    rep(i, n) rep(j, n) rep(k, n){
        d[j][k] = min(d[j][k], d[j][i]+d[i][k]);
    }
    rep(i, n) rep(j, n){
        d[i][j] = i==j? 0 : d[i][j]<=l? 1 : INT_MAX;
    }
    rep(i, n) rep(j, n) rep(k, n){
        d[j][k] = min(d[j][k], d[j][i]+d[i][k]);
    }

    rep(i, q){
        ll res = d[s[i]-1][t[i]-1];
        cout << (res<INT_MAX? (res-1) : -1) << endl;
    }
}


Measured memory_bytes: 2688
#!/usr/bin/env python3
#
# FILE: 2138-AtCoDeer_and_Paint Cans.py
#
# @author: Arafat Hasan Jenin <opendoor.arafat[at]gmail[dot]com>
#
# LINK: https://abc046.contest.atcoder.jp/tasks/abc046_a?lang=en
#
# DATE CREATED: 17-06-18 00:09:52 (+06)
# LAST MODIFIED: 17-06-18 00:19:32 (+06)
#
# VERDICT: Accepted
#
# DEVELOPMENT HISTORY:
# Date         Version     Description
# --------------------------------------------------------------------
# 17-06-18     1.0         Deleted code is debugged code.
#
#               _/  _/_/_/_/  _/      _/  _/_/_/  _/      _/
#              _/  _/        _/_/    _/    _/    _/_/    _/
#             _/  _/_/_/    _/  _/  _/    _/    _/  _/  _/
#      _/    _/  _/        _/    _/_/    _/    _/    _/_/
#       _/_/    _/_/_/_/  _/      _/  _/_/_/  _/      _/
#
##############################################################################

print(len(set(map(int, input().split()))))


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

namespace Geometry {
  using Float = long double;
  using Real = long long;
  constexpr Float eps = 1e-9;

  namespace Plane {
    struct Vec {
      Real x, y;
      constexpr Vec() : x(0), y(0) {}
      constexpr Vec(Real k) : x(k), y(k) {}
      constexpr Vec(Real x, Real y) : x(x), y(y) {}
      static constexpr Real dot(Vec v, Vec w) { return v.x*w.x + v.y*w.y; }
      static constexpr Real cross(Vec v, Vec w) { return v.x*w.y - v.y*w.x; }
      constexpr Real norm2() const { return x*x+y*y; }
      Float norm() const { return std::sqrt(x*x+y*y); }
      Float arg() const { return std::atan2(x, y); }
      constexpr Vec& operator+=(Vec const& v) { x += v.x; y += v.y; return *this; }
      constexpr Vec& operator-=(Vec const& v) { x -= v.x; y -= v.y; return *this; }
      constexpr Vec& operator*=(Real const& k) { x *= k; y *= k; return *this; }
      constexpr Vec& operator*=(Vec const& v) { x *= v.x; y *= v.y; return *this; }
      constexpr Vec operator-() const { return Vec(-x, -y); }
      friend constexpr Vec operator+(Vec const& v, Vec const& w) { return Vec(v) += w; }
      friend constexpr Vec operator-(Vec const& v, Vec const& w) { return Vec(v) -= w; }
      friend constexpr Vec operator*(Real const& k, Vec const& v) { return Vec(v) *= k; }
      friend constexpr Vec operator*(Vec const& v, Vec const& w) { return Vec(v) *= w; }
      constexpr int ort() const { // orthant
        // if(abs(x) < eps && abs(y) < eps) return 0;
        if(  x>0  && !(y<0)) return 1; //  x>0 && y>=0
        if(!(x>0) &&   y>0 ) return 2; // x<=0 &&  y>0
        if(  x<0  && !(y>0)) return 3; //  x<0 && y<=0
        if(!(x<0) &&   y<0 ) return 4; // x>=0 &&  y<0
        return 0;
      }
      friend constexpr bool operator<(Vec const& a, Vec const& b) {
        int ao = a.ort() , bo = b.ort();
        if(ao != bo) return ao < bo;
        return 0 < cross(a, b);
      }
      friend std::istream& operator>>(std::istream& is, Vec& v) noexcept { is >> v.x >> v.y; return is; }
      friend std::ostream& operator<<(std::ostream& os, Vec const& v) noexcept { os << '(' << v.x << ',' << v.y << ')'; return os; }
    };

  }
}
using Geometry::Plane::Vec;

#include <iomanip>
#include <algorithm>
#include <vector>

signed main() {
  using namespace std;

  // abc139_f
  int n;
  cin >> n;

  vector<Vec> v(n);
  for(int i=0; i<n; ++i) cin >> v[i];

  sort(v.begin(), v.end());

  Vec ans{};
  for(int l=0; l<n; ++l) {
    Vec now{};
    for(int r=l, i=0; i<n; ++r, ++i) {
      now += v[r %= n];
      if(ans.norm2() < now.norm2()) ans = now;
    }
  }

  cout << fixed << setprecision(15) << ans.norm() << endl;

  return 0;
}

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

int main(){
  int a[10001];
  for(int i=0;i<10001;++i){
    cin >> a[i];
    if(a[i] == 0)break;
  }
  for(int j=0;j<10001;++j){
    if(a[j] != 0){
      cout << "Case " << j+1 << ": " << a[j] << endl;
    } else break;
  }
  return 0;
}


Measured memory_bytes: 3100
n,q=map(int,input().split())
s=input()
lr=[]
for _ in range(q):
  lr.append(list(map(int,input().split())))
sa=[0,0]
c=0
for i in range(1,n):
  if s[i-1]+s[i]=='AC':
    c+=1
  sa.append(c)
for i in range(q):
  t=sa[lr[i][1]]-sa[lr[i][0]]
  print(t)


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

struct Node {
	int d = -1;
	bool flag = false;
	vector<int> v;
};

queue<int> s;

void bfs_s(vector<Node>& u, int id, int d)
{
	if (u[id].flag) return;

	u[id].d = d;
	u[id].flag = true;
	for (int i = 0; i < u[id].v.size(); i++)
	{
		s.push(u[id].v[i]);
	}
	return;
}

void bfs(vector<Node>& u)
{
	int d = 0;
	while(!s.empty())
	{
		int n = s.size();
		for (int i = 0; i < n; i++)
		{
			bfs_s(u, s.front(), d);
			s.pop();
		}
		d++;
	}
	return;
}

int main(void)
{
	int N, id, k, x;
	Node z;
	cin >> N;
	vector<Node> u(N + 1);
	for (int i = 0; i < N; i++)
	{
		cin >> id >> k;
		for (int j = 0; j < k; j++)
		{
			cin >> x;
			u[id].v.push_back(x);
		}
	}
	s.push(1);
	bfs(u);

	for (int i = 1; i <= N; i++) cout << i << " " << u[i].d << endl;

	return 0;
}


Measured memory_bytes: 3136
import java.util.*;



import java.io.*;
public class Main {

	public static void main(String[] args) {
	FastScanner sc=new FastScanner();
	int n=sc.nextInt(),w=sc.nextInt();
	int a[][]=new int[n][2];
	for(int i=0;i<n;i++) {
		a[i][0]=sc.nextInt();
		a[i][1]=sc.nextInt();
	
	}
	long dp[][]=new long[n+1][w+1];
	for(int i=0;i<=n;i++) {
		for(int j=0;j<=w;j++) {
			if(i==0||j==0) {
				dp[i][j]=0;
			}
			else {
				if(j<a[i-1][0])
					dp[i][j]=dp[i-1][j];
				else {
					dp[i][j]=Math.max(dp[i-1][j], dp[i-1][j-a[i-1][0]]+a[i-1][1]);
				}
				
				
			}
		}
	}
	
	System.out.println(dp[n][w]);


	}
	static class FastScanner{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
		int [] readArray(int n) {
			int a[]=new int[n];
			for(int i=0;i<n;i++) a[i]=nextInt();
			return a;
		}
		
		
	}
	

}



Measured memory_bytes: 138192