akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

   typedef long long ll;
   typedef pair<ll, ll> Pii;
   typedef vector<ll> Vi;
   typedef vector<Vi> VVi;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define RSORT(x) sort((x).rbegin(), (x).rend())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
   template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}
   ll pow(ll a, ll b, ll m){if (b == 0) return 1; else if (a == 0) return 0; else if (b % 2 == 0) return (pow((a * a) % m, b / 2, m) % m); else return (pow((a * a) % m, b / 2, m) * a) % m;}
   ll residue(ll a, ll m){return ((a % m) + m) % m;};

   ll dx[4]={1,0,-1,0};
   ll dy[4]={0,1,0,-1};

typedef vector<vector<long long>> Graph ;

Pii farthest(ll p, ll v, const Graph &g){
  //p:parent v:node g:Graph
  Pii u = mp(0, v); // weight, node
  for(auto &e : g[v]){
    if(e == p) continue;
    Pii t = farthest(v, e, g);
    if(t.first  + 1 > u.first) u = mp(t.first + 1, t.second);
  }
  return u;
}

ll diameter(const Graph &g){
  Pii u = farthest(-1, 0, g);
  Pii v = farthest(-1, u.second, g);
  return v.first;
}
int main(){
  ll n; cin >> n;
  Graph G(n, Vi());
  REP(i, n - 1){
    ll a, b; cin >> a >> b; a--; b--;
    G[a].pb(b); G[b].pb(a);
  }
  ll D = diameter(G);
  cout << ((D % 3 == 1) ? "Second" : "First") << endl;
}


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

using namespace std;

const int MX = 301, md = 998244353;

char str[MX];
int a[MX], s[MX], f[MX][MX], g[MX][2 * MX], h[MX + 1][2 * MX];

int main() {
	int k;
	ignore = scanf("%s %d", str, &k);
	
	k = min(k, MX - 1);
	
	int n = 0;
	for (int i = 0, c = 0; true; i++) {
		if (str[i] == '1') c++;
		else {
			a[n++] = c;
			c = 0;
			
			if (str[i] == 0) break;
		}
	}
	
	s[0] = 0;
	for (int i = 0; i < n; i++) s[i + 1] = s[i] + a[i];
	
	f[0][0] = 1;
	for (int p = 0; p < n; p++) {
		memset(g, 0, sizeof g);
		memset(h, 0, sizeof h);
		
		for (int x = 0; x <= k; x++)
			for (int y = s[p]; y < MX; y++) {
				g[x][y] += f[x][y];
				g[x][y] %= md;
				
				g[x][y + a[p]] += md - f[x][y];
				g[x][y + a[p]] %= md;
				
				h[x][y + a[p]] += f[x][y];
				h[x][y + a[p]] %= md;
			}
		
		for (int x = 0; x < MX; x++)
			for (int y = 0; y < MX; y++) {
				f[x][y] = (g[x][y] + h[x][y]) % md;
				
				g[x][y + 1] += g[x][y];
				g[x][y + 1] %= md;
				
				h[x + 1][y + 1] += h[x][y];
				h[x + 1][y + 1] %= md;
			}
	}
	
	int ans = 0;
	for (int x = 0; x <= k; x++) {
		ans += f[x][s[n]];
		ans %= md;
	}
	
	printf("%d\n", ans);
	
	return 0;
}


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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long  ll; typedef vector<int> VI; typedef pair<ll,ll> pii; typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VL x(n), y(n), p(n);
	rep(i, n) cin >>x[i] >>y[i] >>p[i];
	const int pj = 3;
	VL  xx, yy, hl;
	VL ans(n+1, 1LL<<55);
	rep(i,(int)pow(pj, n)){
		xx.clear(); yy.clear(), hl.clear();
		for(int j=0, wki=i; j<n; j++, wki/=pj){
			int nw = wki%pj;
			if(nw==0) hl.push_back(j);
			else if(nw==1) xx.push_back(x[j]);
			else if(nw==2) yy.push_back(y[j]);
		}
		//for(auto x :vi) cerr<<x<<" "; dbg();
		ll sm = 0;
		for(auto z: hl){
			ll cnd = min<ll>(abs(x[z]), abs(y[z]));
			for(auto k: xx) cnd = min(cnd, abs(k - x[z]));
			for(auto k: yy) cnd = min(cnd, abs(k - y[z]));
			sm += cnd * p[z];
		}
		int sc = sz(xx)+sz(yy);
		//dbg(sc, i, sm);
		ans[sc] = min(ans[sc], sm);
	}
	
	rep(i, n+1) cout <<ans[i] <<"\n";
}



Measured memory_bytes: 3996
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Main {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    void solve() throws IOException {
        int N = ni();
        int[] A = nia(N);

        int now = 2;
        long ans = A[0] - 1;

        for (int i = 1; i < N; i++) {
            if (A[i] == now) {
                now++;
                continue;
            } else if (A[i] > now) {
                ans += (A[i] - 1) / now;
            }
        }

        out.println(ans);
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 23468
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <istream>
#include <ostream>

#include <cstdlib>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define rep(i,n) for(ll i=0; i < (n); ++i)
#define rrep(i,n) for(ll i=((n)-1); i >= 0; --i)

#define OPLT(T) bool operator<(const T & lop_, const T & rop_)
#define OPEQ(T) bool operator==(const T & lop_, const T & rop_)

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

istream& operator>>(istream& istr, __float128& obj) { double d; istr >> d; obj = d; return istr; };
ostream& operator<<(ostream& ostr, __float128& obj) { ostr << static_cast<double>(obj); return ostr; };

int main() {
	int N;
	cin >> N;
	if(N == 2) {
		cout << -1 << endl;
		return 0;
	}
	if(N % 2) {
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < N-1; j++) {
				cout << 1 + (i+j+1) % N << " \n"[j==N-1];
			}
			cout << endl;
		}
	}
	else {
		for(int i = 0; i < N-1; i++) {
			if(i) cout << N << " " << 1 + (i+1) % (N-1) << " ";
			else  cout << 1 + (i+1) % (N-1) << " " << N << " ";
			for(int j = 0; j < N-1 -2; j++) {
				cout << 1 + (i+j+2) % (N-1) << " \n"[j==N-1];
			}
			cout << endl;
		}
		for(int i = 0; i < N-1; i++)
			cout << i+1 << " \n"[i==N-1];
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 384
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(int d, int[][] a) {
    int ans = 0;
    for (int i = 0; i < a.length; i++) {
        for (int j = i + 1; j < a.length; j++) {
            int len = 0;
            for (int k = 0; k < d; k++) {
                len += abs(a[i][k] - a[j][k]) ^^ 2;
            }

            int p = 1;
            while (p * p <= len) {
                if (p * p == len) {
                    ans++;
                    break;
                }
                p++;
            }
        }
    }
    return ans;
}

void main() {
    int n, d; scan(n, d);
    int[][] a;
    foreach (_; 0..n) a ~= readints;

    writeln(calc(d, a));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
    int main(){
        int N;
            cin >> N;
        int c = 0;
        for(int i = 1; i <= N; i++){
            if(1 <= i && i <= 9){
                c += 1;
            }else if(100 <= i && i <= 999){
                c += 1;
            }else if(10000 <= i && i <= 99999){
                c += 1;
            }else{}
        }
            cout << c;
    }


Measured memory_bytes: 256
def d_checker():
    # 参考1: https://pitsbuffersolution.com/compro/atcoder/arc089d.php
    # 参考2: https://atcoder.jp/contests/abc086/submissions/3271380
    import numpy as np
    N, K = [int(i) for i in input().split()]

    def get_bound(p):
        """ある希望を満たすような角のマスの集合はKxK正方形区間のようになっている
        p<K-1 のときはその正方形を分割しないとならない"""
        return [(0, p + 1), (p + K + 1, 2 * K)] if p < K - 1 else [(p - K + 1, p + 1)]

    # マス(x, y)が白⇔マス(x, y+K)が黒なので、希望の色を黒に統一する
    # 市松模様の周期は2Kなので、x, y座標をそれぞれ2Kで剰余を取った座標と同一視できる
    requests_black = [[0] * (2 * K + 1) for _ in range(2 * K + 1)]
    for _ in range(N):
        x, y, c = input().split()
        x = int(x) % (2 * K)
        y = int(y) % (2 * K) if c == 'B' else (int(y) + K) % (2 * K)

        for shift in (0, K):  # 2Kx2Kの市松模様の中に同色の領域が2つずつあることを反映
            # bottom, top, left, right
            for b, t in get_bound((y + shift) % (2 * K)):
                for l, r in get_bound((x + shift) % (2 * K)):
                    # 2次元imos法(左上、左下、右上、右下に±1することと対応)
                    requests_black[b][l] += 1
                    requests_black[t][l] -= 1
                    requests_black[b][r] -= 1
                    requests_black[t][r] += 1
    # 最後に累積和を取ると、あるマスを正方形の角としたとき叶えられる希望の数がわかる
    return int(np.max(np.cumsum(np.cumsum(requests_black, axis=1), axis=0)))

print(d_checker())

Measured memory_bytes: 106216
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        int n=s.nextInt(),x=s.nextInt(),t=s.nextInt();
        long sum = n/x;
        sum *= t;
        if(n%x!=0)sum+=t;
        System.out.println(sum);
 
    }
 
}
 
 
 
 
class Scanner
{
    StringTokenizer st;
    BufferedReader br;
 
    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}
 
    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }
 
    public int nextInt() throws IOException {return Integer.parseInt(next());}
 
    public long nextLong() throws IOException {return Long.parseLong(next());}
 
    public String nextLine() throws IOException {return br.readLine();}
 
    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }
 
    public boolean ready() throws IOException {return br.ready();}
 
 
}

Measured memory_bytes: 25408
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define double long double
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vec;
typedef vector<vec> mat;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    ll n;cin>>n;
    bool f=1;
    rep(i,n){
        ll a;cin>>a;
        if(a%2)continue;
        if(a%5!=0&&a%3!=0)f=0;
    }
    if(f)cout<<"APPROVED"<<endl;
    else cout<<"DENIED"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  vector<int>height(n+1);
  for(int i=1;i<=n;i++){
      cin>>height[i];
  }
  int a,b;
  vector<vector<int>>v(n+1,vector<int>());
  for(int i=0;i<m;i++){
      cin>>a>>b;
      v[a].push_back(b);
      v[b].push_back(a);
  }int count = 0;
  
  for(int i=1;i<=n;i++){
      if(v[i].size()==0){
          count++;
      }
      else{
          int flag = 1;
          for(auto x: v[i]){
              if(height[x]>=height[i]){
                  flag = 0;
                  break;
              }
          }
          if(flag==1){
              count++;
          }
      }
  }
  cout<<count;
  return 0;
}

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

int main()
{
    int n, m, q;
    cin >> n >> m >> q;

    vector<vector<int>> table(n + 1, vector<int>(n + 1, 0));
    while(m--)
    {
        int l,r;
        cin >> l >> r;
        table[l][r]++;
    }
    rep(i, n) rep(j, n) table[i + 1][j + 1] += table[i + 1][j] + table[i][j + 1] - table[i][j];

    while (q--)
    {
        int s, t;
        cin >> s >> t;

        cout << table[t][t] - table[s - 1][t] - table[t][s - 1] + table[s - 1][s - 1] << endl;
    }
}

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

using namespace std;

int a[105];

int main() {
	int n;
	scanf("%d", &n);
	if (n & 1) {
		for (int i = 1; i <= n - 1; ++i) {
			a[i] = min(i, n - i);
		}
		a[n] = n;
	} else {
		for (int i = 1; i <= n; ++i) {
			a[i] = min(i, n + 1 - i);
		}
	}
	vector< pair<int, int> > res;
	for (int u = 1; u <= n; ++u) {
		for (int v = u + 1; v <= n; ++v) {
			if (a[u] != a[v]) {
				res.push_back({u, v});
			}
		}
	}
	printf("%u\n", res.size());
	for (auto p : res) {
		printf("%d %d\n", p.first, p.second);
	}
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;

int main(){
  double a,b,x;
  cin>>a>>b>>x;
  if (x>(a*a*b)/2){
    double s = a*a*a/(2*a*a*b-2*x);
    cout <<setprecision(13)<< 90-atan(s)/M_PI*180 << endl;
  }else{
    double s=(2*x)/(a*b*b);
    cout <<setprecision(13)<< 90-atan(s)/M_PI*180 << endl;
  }
  return 0;
}



Measured memory_bytes: 256
/**
 * OfficialHouse.cpp
 * Create:20180422
 * Description:１フロア１０部屋、３階建て公舎４棟を管理している。
 * 各部屋の入居者数を出力するプログラム。
 */
#include <iostream>

const int ROOM = 10;
const int FLOOR = 3;
const int HOME = 4;

/**
 * Houseクラス
 */
class House{
private:
  int people[FLOOR][ROOM];
  // 初期化
  void reset(){
    for (int i = 0; i < FLOOR; i++){
      for (int j = 0; j < ROOM; j++){
        people[i][j] = 0;
      }
    }
  }
public:
  /**
   * デフォルトコンストラクタ
   */
  House(){
    reset();
  }

  /**
   * 表示関数
   */
  void draw(){
    for (int i = 0; i < FLOOR; i++){
      for (int j = 0; j < ROOM; j++){
        std::cout << " " << people[i][j];
      }
      std::cout << std::endl;
    }
  }

  /**
   * 居住人数変更関数
   * @param floor_no 階層番号
   * @param room_no  部屋番号
   * @param residens 入居・退去人数
   */
  void residens(int floor_no, int room_no, int residens){
    people[floor_no][room_no] += residens;
    // 人数が０より下だった場合０を設定
    if (people[floor_no][room_no] < 0)
      people[floor_no][room_no] = 0;
    // 人数が９より上だった場合９を設定
    if (people[floor_no][room_no] > 9)
      people[floor_no][room_no] = 9;
  }

};

int main(int argc, char* argv[]){
  House home[HOME] = House();

  int input_count;  // 入力数

  int house_no;   // 棟番号
  int floor_no;   // 階層数
  int room_no;    // 部屋番号
  int residens;   // 入居人数

  std::cin >> input_count;

  // 入力処理
  for (int i = 0; i < input_count; i++){
    std::cin >> house_no >> floor_no >> room_no >> residens;
    home[house_no - 1].residens(floor_no - 1, room_no - 1, residens);
  }

  // 出力処理
  for (int i = 0; i < HOME; i++){
    home[i].draw();
    if (i != HOME - 1){
      std::cout << "####################" << std::endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef pair<string , int> s_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<typename T> void remove(T & vector, unsigned int index){vector.erase(vector.begin() + index);}

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

    ll N, A, B; cin >> N >> A >> B;
    vel X(N); rep(i,N) cin >> X[i];

    ll ans = 0;
    rep(i,N-1) ans += min(A * ( X[i + 1] - X[i] ), B);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <cstring>
#include <climits>
#include <queue>
using namespace std;

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

const int dx[] = {0, 0, 1,-1};
const int dy[] = {1,-1, 0, 0};
int h,w,n,sx,sy;
char f[1010][1010];
int vt[1010][1010];

int main(){
	int ret = 0;
	scanf("%d%d%d",&h,&w,&n);
	rep(i,h)scanf("%s",f[i]);
	rep(i,h)rep(j,w)if( f[i][j]=='S' ){
		sx = j;  sy = i;
	}
	
	//printf("sx,sy %d,%d\n",sx,sy);
	
	for(int i=1; i<=n; i++){
		bool flag = false;
		queue<pair<int,int> > q;
		memset(vt,-1,sizeof(vt));
		q.push( make_pair(sx,sy) );
		vt[sy][sx] = 0;
		//printf("i:%d , %d\n",i,ret);

		while( !q.empty() && !flag ){
			int x = q.front().first;
			int y = q.front().second;
			int c = vt[y][x];
			q.pop();
			rep(k,4){
				int tx = x + dx[k];
				int ty = y + dy[k];
				//printf("tx,ty %d,%d\n",tx,ty);
				if( tx<0 || ty<0 || tx>=w || ty>=h ||
						vt[ty][tx]!=-1 || f[ty][tx]=='X' ) continue;
				
				if( f[ty][tx]==i+'0' ){
					ret += c+1;
					sy = ty; sx = tx;
					flag = true;
					break;
				}
				vt[ty][tx] = c+1;
				//printf("(%d,%d):%d\n",tx,ty,c+1);
				q.push( make_pair(tx,ty) );
			}
		}
		//if( !flag )puts("eeeeeeeeeeee");
	}
	printf("%d\n",ret);
	
	return 0;
}

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

char str[1003][1003];
const char mat1[4][5] = 
{
	"aabd",
	"ccbd",
	"efgg",
	"efhh"
};
const char mat2[5][6] = 
{
	"iijjk",
	"paa.k",
	"p..bl",
	"o..bl",
	"onnmm"
};
const char mat3[6][7] =
{
	"aab.cc",
	"d.be..",
	"dffe..",
	"gg.iij",
	"..hl.j",
	"..hlkk"
};	

void put4(int x){
	for(int i = 0 ; i < 4 ; ++i)
		for(int j = 0 ; j < 4 ; ++j)
			str[x + i][x + j] = mat1[i][j];
}

void put5(int x){
	for(int i = 0 ; i < 5 ; ++i)
		for(int j = 0 ; j < 5 ; ++j)
			str[x + i][x + j] = mat2[i][j];
}

void put6(int x){
	for(int i = 0 ; i < 6 ; ++i)
		for(int j = 0 ; j < 6 ; ++j)
			str[x + i][x + j] = mat3[i][j];
}

int main(){
	int N; cin >> N;
	if(N == 2) puts("-1");
	else{
		for(int i = 1 ; i <= N ; ++i)
			for(int j = 1 ; j <= N ; ++j)
				str[i][j] = '.';
		if(N == 7){
			puts("aabbcc.");
			puts("ddeef..");
			puts("gg..fgg");
			puts("..ab..c");
			puts("..ab..c");
			puts("....def");
			puts("....def");
			return 0;
		}
		else if(N % 3 == 0)
			for(int i = 1 ; i <= N ; i += 3)
				str[i][i] = str[i][i + 1] = str[i + 1][i + 2] = str[i + 2][i + 2] = 'a';
		else
			if(N == 8) put4(1) , put4(5);
			else if(N == 10) put5(1) , put5(6);
			else if(N % 6 == 4){
				put4(1);
				for(int i = 5 ; i <= N ; i += 6)
					put6(i);
			}
			else if(N % 6 == 5){
				put5(1);
				for(int i = 6 ; i <= N ; i += 6)
					put6(i);
			}
			else if(N % 6 == 1){
				put4(1); put4(5); put5(9);
				for(int i = 14 ; i <= N ; i += 6)
					put6(i);
			}
			else{
				put4(1); put5(5); put5(10);
				for(int i = 15 ; i <= N ; i += 6)
					put6(i);
			}
		for(int i = 1 ; i <= N ; ++i , putchar('\n'))
			for(int j = 1 ; j <= N ; ++j)
				putchar(str[i][j]);
	}
	return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  string s;
  cin >> s;
  vector<ll> a(4);
  REP(i, 4) { a[i] = s[i] - '0'; }
  REP(i, 2) REP(j, 2) REP(k, 2) {
    ll res = a[0];
    res += i % 2 == 0 ? a[1] : -a[1];
    res += j % 2 == 0 ? a[2] : -a[2];
    res += k % 2 == 0 ? a[3] : -a[3];

    if (res == 7) {
      cout << s[0] << (i % 2 == 0 ? '+' : '-') << s[1]
           << (j % 2 == 0 ? '+' : '-') << s[2] << (k % 2 == 0 ? '+' : '-')
           << s[3];
      cout << "=7" << endl;
      return 0;
    }
  }
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e18
#define mod 1000000007

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

  const ll M=16;
  ll N;
  cin>>N;
  vector<ll> A(N);
  rep(i,N)cin>>A[i];

  vector<ll> Aneg=A;
  rep(i,N)Aneg[i]=-2*A[i];
  vector<vector<ll>> pfx(N+1,vector<ll>(M,INF)),sfx(N+1,vector<ll>(M,INF));
  ll pre=-INF;
  rep(j,M)pfx[0][j]=0;
  rep(i,N){
    rep(j,M){
      ll crt=Aneg[i];
      rep(k,M){
        if(pre<=crt)minch(pfx[i+1][k],pfx[i][j]+2*k);
        crt*=4;
      }
      if(pre!=-INF)pre*=4;
    }
    rep(j,M-1)minch(pfx[i+1][j+1],pfx[i+1][j]+2*(i+1));
    pre=Aneg[i];
  }
  reverse(all(A));
  pre=INF;
  rep(j,M)sfx[0][j]=0;
  rep(i,N){
    rep(j,M){
      ll crt=A[i];
      rep(k,M){
        if(pre>=crt)minch(sfx[i+1][k],sfx[i][j]+2*k);
        crt*=4;
      }
      if(pre!=INF)pre*=4;
    }
    rep(j,M-1)minch(sfx[i+1][j+1],sfx[i+1][j]+2*(i+1));
    pre=A[i];
  }
  reverse(all(sfx));
  ll res=INF;
  rep(i,N+1){
    ll mn0=INF,mn1=INF;
    rep(j,M){
      minch(mn0,pfx[i][j]);
      minch(mn1,sfx[i][j]);
    }
    minch(res,mn0+mn1+i);
  }
  cout<<res<<endl;

  return 0;
}


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

namespace AOJ {
    public class Probrem {
        public static void Main() {
            var data = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var c = 0;
            for (var i = data[0]; i <= data[1]; i++)
                c += data[2] % i == 0 ? 1 : 0;
            Console.WriteLine(c);
        }
    }
}


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

int main(){
    int n, k;
    cin >> n >> k;

    vector<int> v(n);
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }
    sort(v.rbegin(), v.rend());

    int ans = 0;
    for(int i = 0; i < k; i++){
        ans += v[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
d=dict()
n,d["A"],d["B"],d["C"]=map(int,input().split())
s=[input() for i in range(n)]
ans=[]
i=0
while i<n:
    x,y=s[i][0],s[i][1]
    if d[x]==0 and d[y]==0:
        print("No")
        quit()
    elif d[x]==0:
        ans.append(x)
        d[x]+=1
        d[y]-=1
    elif d[y]==0:
        ans.append(y)
        d[x]-=1
        d[y]+=1
    else:
        if i==n-1:
            ans.append(x)
            break
        if y in s[i+1]:
            ans.append(y)
            d[x]-=1
            d[y]+=1
        else:
            ans.append(x)
            d[x]+=1
            d[y]-=1
    i+=1
print("Yes")
for i in ans:
    print(i)

Measured memory_bytes: 91840
# -*- coding: utf-8 -*-
"""
A - Eating Symbols Easy
https://beta.atcoder.jp/contests/abc101/tasks/abc101_a

"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    S = input()
    ans = S.count('+') - S.count('-')
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
struct UF
{
  vector<int> par;
  vector<int> sz;
  vector<int> rank;
  UF(int n):par(n),sz(n),rank(n){
    for(int i = 0; i < n; i++){
      par[i] = i;sz[i] = 1;rank[i] = 0;
    }
  }
  int find(int x) {
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
  }
  void merge(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return;
    if(rank[x] < rank[y]){
      par[x] = y;
      sz[y] += sz[x];
    }
    else{
      par[y] = x;
      sz[x] += sz[y];
      if(rank[x] == rank[y])rank[x]++;
    }
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int n){return sz[find(n)];}
};

bool isdig(char c){
  return '0' <= c && c <= '9';
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;cin>>s;
  string t = "CODEFESTIVAL2016";
  ll ans = 0;
  for(int i=0;i<s.size();i++){
    ans += (s[i]!=t[i]);
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

bool ok(int i) {
  if(i/100 == (i%100)/10 && (i%100)/10 == i%10) return true;
  else return false;
}

int main() {
  int N;
  cin>>N;
  int ans;
  for(int i=N;i<=1000;++i) {
    if(ok(i)) {
      ans = i;
      break;
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3616
import sys
X, N = map(int, input().split())
if N != 0:
    P = list(map(int, input().split()))
else:
    print(X)
    sys.exit(0)
l = []
for i in range(102):
    if i not in P:
        l.append(i)
tmp = 1000
ans = 0
for i in range(len(l)):
    if tmp > abs(X-l[i]):
        tmp = abs(X-l[i])
        ans = l[i]

print(ans)


Measured memory_bytes: 9180
#include<string>
#include<vector>
#include<iostream>

using namespace std;
#define d getchar()
int main() {

	int n;
	cin >> n;

	vector<int> a(n);
	bool state = false;

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

		if (a[i] % 2 == 0) {
			if (a[i] % 3 != 0 && a[i] % 5 != 0) {
				cout << "DENIED";
				return 0;
			}
		}
	}
	cout << "APPROVED";

	return 0;
}


Measured memory_bytes: 256
using System;

namespace atcoder_ABC075B
{
    class MainClass
    {
        public static void Main(string[] args)
        {
			string[] array = Console.ReadLine().Split(' ');
			int height = int.Parse(array[0]);
			int width = int.Parse(array[1]);

			char[,] grid = new char[height, width];
            for (int i = 0; i < height; i++)
			{
				string line = Console.ReadLine();
                for (int j = 0; j < width; j++)
				{
					grid[i, j] = line[j];
				}
			}

			for (int i = 0; i < height; i++)
			{
				for (int j = 0; j < width; j++)
				{
					int mineCount = 0;
					if (grid[i, j] == '.')
					{
						if (i - 1 >= 0 && grid[i - 1, j] == '#') mineCount++;
						if (i + 1 <= height - 1 && grid[i + 1, j] == '#') mineCount++;

						if (j - 1 >= 0 && grid[i, j - 1] == '#') mineCount++;
						if (j + 1 <= width - 1 && grid[i, j + 1] == '#') mineCount++;

						if (i - 1 >= 0 && j - 1 >= 0 && grid[i - 1, j - 1] == '#') mineCount++;
                        if (i + 1 <= height - 1 && j + 1 <= width - 1 && grid[i + 1, j + 1] == '#') mineCount++;

						if (i - 1 >= 0 && j + 1 <= width - 1 && grid[i - 1, j + 1] == '#') mineCount++;
                        if (i + 1 <= height - 1 && j - 1 >= 0 && grid[i + 1, j - 1] == '#') mineCount++;
                        
						grid[i, j] = char.Parse(mineCount.ToString());

						Console.Write(grid[i, j]);
					}
					else
					{
						Console.Write(grid[i, j]);
					}
				}

				Console.Write("\n");
			}
        }
    }
}


Measured memory_bytes: 11220
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <typeinfo>

using namespace std;

int main(){
  long long N,M;
  cin >> N >> M;

  if(N==1)  N+=2;
  if(M==1)  M+=2;
  long long ans=(N-2)*(M-2);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <iterator>
using namespace std;
int main()
{
    string str;
    cin >> str;
    int K;
    cin >> K;
    set<string> S;
    vector<int> N(str.size());
    for (int i = 0; i < str.size(); i++) N[i] = i;
    sort(N.begin(), N.end(), [&](int i, int j) { return str[i] < str[j]; });
    int count = 0;
    char ch = str[N[0]];
    for (int t = 0; t < str.size(); t++) {
        int i = N[t];
        if (str[i] != ch && count >= K) break;
        ch = str[i];
        for (int n = 1; i + n <= str.size() && n <= K; n++) {
            auto p = S.insert(str.substr(i, n));
            if (p.second) count++;
        }
    }
    auto it = S.begin();
    advance(it, K-1);
    cout << *it << endl;
    return 0;
}


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

using namespace std;

const int N = 1e6 + 6, mod = 998244353;

long long powmod(long long b, long long p) {
  long long r = 1;
  for (; p; p >>= 1, b = b * b % mod)
    if (p & 1)
      r = r * b % mod;
  return r;
}

int sum[N], sq[N];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    sum[x] += x;
    if (sum[x] >= mod)
      sum[x] -= mod;
    sq[x] = (sq[x] + 1LL * x * x) % mod;
  }
  for (int i = 1; i < N; ++i) {
    for (int j = i+i; j < N; j += i) {
      sum[i] += sum[j];
      if (sum[i] >= mod)
        sum[i] -= mod;
    }
    for (int j = i+i; j < N; j += i) {
      sq[i] += sq[j];
      if (sq[i] >= mod)
        sq[i] -= mod;
    }
    sum[i] = (1LL * sum[i] * sum[i] - sq[i]) % mod;
    sum[i] = 1LL * sum[i] * ((mod + 1) / 2) % mod;
  }
  long long ans = 0;
  for (int i = N-1; i >= 1; --i) {
    for (int j = i+i; j < N; j += i) {
      sum[i] += mod - sum[j];
      if (sum[i] >= mod)
        sum[i] -= mod;
    }
    ans = (ans + 1LL * sum[i] * powmod(i, mod-2)) % mod;
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 8064
while True:
    count = 0
    n,x = map(int,input().split())
    if n == x == 0:
        break
    for i in range(1,n+1):
        for k in range(i+1,n+1):
            for j in range(k+1,n+1):
                if i + k + j == x:
                    count += 1
    print(count)



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

int main(void) {
  ll i, j, k, n, q, a = -1, b;
  scanf("%lld%lld", &n, &q);
  b = n;
  char s[n + 10], t[q][3], d[q][3];
  scanf("%s", s);
  for(i = 0; i < q; ++i) scanf("%s%s", t[i], d[i]);
  for(i = q - 1; i >= 0; --i) {
    if(d[i][0] == 'L') {
      if(t[i][0] == s[a + 1]) a++;
      if(t[i][0] == s[b]) b++;
    } else {
      if(a != -1 && t[i][0] == s[a]) a--;
      if(t[i][0] == s[b - 1]) b--;
    }
    if(b - a == 1) break;
  }
  printf("%lld", b - a - 1);
  return 0;
}

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

using namespace std;

inline int read()
{
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
struct edge
{
	int u,v,next;
}vs[5000];
int n,k,ee,st[3000],dep[5000],tmp,ans;
inline void addedge(int u,int v)
{
	vs[++ee].v=v;vs[ee].u=u;
	vs[ee].next=st[u];st[u]=ee;
}
void dfs(int rt,int pr)
{
	if(dep[rt]*2>k) tmp++;
	for(int i=st[rt];i;i=vs[i].next)
	{
		if(vs[i].v==pr) continue;
		dep[vs[i].v]=dep[rt]+1;
		dfs(vs[i].v,rt);
	}
}
int main()
{
	n=read();k=read();
	for(int i=1;i<n;i++)
	{
		int u=read(),v=read();
		addedge(u,v); addedge(v,u);
	}
	ans=0x7fffffff;
	if(k&1)
	{
		for(int i=1;i<n;i++)
		{
			tmp=0;
			dep[vs[i<<1].u]=0;
			dep[vs[i<<1].v]=0;
			dfs(vs[i<<1].u,vs[i<<1].v);
			dfs(vs[i<<1].v,vs[i<<1].u);
			ans=min(ans,tmp);
		}
	}
	else
	{
		for(int i=1;i<=n;i++)
		{
			tmp=0; dep[i]=0;
			dfs(i,0);
			ans=min(ans,tmp);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(void){
    int x;
    cin >> x;
    
    if( x%7 == 2 ){
        cout << "sat";
    }
    else if( x%7 == 1 ){
        cout << "fri";
    }
    else if( x%7 == 3){
        cout << "sun";
    }
    else if( x%7 == 4){
        cout << "mon";
    }
    else if( x%7 == 5){
        cout << "tue";
    }
    else if( x%7 == 6){
        cout << "wed";
    }
    else if( x%7 == 0){
        cout << "thu";
    }
    cout << endl;
    
}



Measured memory_bytes: 3104
#include<bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;
typedef long long ll;
namespace IO{
	cs int Rlen=1<<22|1;
	inline char gc(){
		static char buf[Rlen],*p1,*p2;
		(p1==p2)&&(p2=(p1=buf)+fread(buf,1,Rlen,stdin));
		return p1==p2?EOF:*p1++;
	} int read(){
		int x=0; char c=gc(); bool f=false;
		while(!isdigit(c)) f=(c=='-'),c=gc();
		while(isdigit(c)) x=(((x<<2)+x)<<1)+(c^48), c=gc();
		return f?-x:x;
	}
} using namespace IO;
cs int N = 2e5 + 50;
cs ll INF = 1e18;
int n; struct dat{ int v, c, o; }a[N];
bool cmp(dat a, dat b){ return a.v < b.v; }
int main(){
	#ifdef FSYolanda
	freopen("1.in","r",stdin);
//	freopen("my.out","w",stdout);
	#endif
	scanf("%d",&n); int ct=0;
	for(int i=1; i<=n; i++)
	a[++ct]=(dat){read(),i,0}, a[++ct]=(dat){read(),i,1};
	sort(a+1,a+ct+1,cmp);
	static int vs[N];
	int sm[2]; sm[0]=sm[1]=0;
	ll Ans=0; bool ok=false;
	for(int i=1; i<=n; i++){
		++vs[a[i].c]; ++sm[a[i].o]; Ans+=a[i].v; 
		ok|=vs[a[i].c]>1;
	} if(ok||max(sm[0],sm[1])==n) return cout<<Ans,0;
	Ans+=a[n+1].v-a[n].v; --sm[a[n].o]; ++sm[a[n].o];
	if(a[n].c!=a[n+1].c) return cout<<Ans,0;
	if(max(sm[0],sm[1])==n) return cout<<Ans,0;
	cout<<Ans+min(a[n+2].v-a[n+1].v, a[n].v-a[n-1].v);
	return 0;
}

Measured memory_bytes: 6400
R,r=range,raw_input;N,K=map(int,r().split());L=K+1;P,Q=R(K),R(L);D=[L*[0]for i in Q];a=b=0
for i in R(N):x,y,c=r().split();x,y=int(x),int(y);p=(x/K+y/K+ord(c))%2;D[y%K+1][x%K+1]+=1-2*p;b+=p
for i in P:
 for j in Q:D[i+1][j]+=D[i][j]
for i in P:
 for j in Q:D[j][i+1]+=D[j][i]
for i in Q:
 for j in Q:S=D[i][K]+D[K][j]-D[i][j]*2;a=max(a,S,D[K][K]-S)
print a+b

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

long long A,B;
long long f(long long x){
    return ((A*x)/B)-(A*(x/B));
}

signed main(void){
    long long N;
    cin >> A >> B >> N;
    cout << f(min(N,B-1)) << endl;
    
    
    return 0;
}


Measured memory_bytes: 3628
import kotlin.math.ceil

fun main() = Thread(null, ::abc174e, "(^o^)", 128 * 1024 * 1024).apply { start() }.join()

@OptIn(ExperimentalStdlibApi::class)
fun abc174e() {
    val (n, k) = readLine()!!.split(" ").map { it.toInt() }
    val aList = readLine()!!.split(" ").map { it.toLong() }

    val aListD = aList.map { it.toDouble() }

    // 長さのリミット->必要なカット回数を返す
    fun check(lengthLimit: Long) = aListD.map { ceil(it / lengthLimit).toLong() - 1 }.sum()

    // 答え決め打ちにぶたん
    fun lowerBound(): Long {
        var ng = 0L
        var ok = aList.max()!!

        while (ok - ng > 1) {
            val mid = (ok + ng) / 2
            val check = check(mid)
            if (check <= k) ok = mid else ng = mid
        }
        return ok
    }

    val answer = lowerBound()

    println(answer)
}


Measured memory_bytes: 94764
from collections import defaultdict


def main():
    N, M = list(map(int, input().split(' ')))
    H = list(map(int, input().split(' ')))
    obs = defaultdict(list)
    for _ in range(M):
        A, B = list(map(int, input().split(' ')))
        A -= 1
        B -= 1
        obs[A].append(B)
        obs[B].append(A)
    cnt = 0
    for i in range(N):
        obs_list = obs[i]
        if len(obs_list) == 0:
            cnt += 1
            continue
        h_i = H[i]
        to_be_counted = True
        for j in obs_list:
            if h_i <= H[j]:
                to_be_counted = False
                break
        if to_be_counted:
            cnt += 1
    print(cnt)


if __name__ == '__main__':
    main()

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

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i ,a, b) for (int i = a ; i <= b ; i++)
#define sz(a) int(a.size())
#define cuti(a) cout << a << endl;
#define cutii(a,b) cout << a << " " << b << endl;
#define vec(a) vector<int > a;

template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }

typedef pair<int ,int > pii;
typedef long long LL;
const long long oo = 1e9 + 7;

int n;
long long cnt[123456],k;

int main() {
  //  freopen("test.txt","r",stdin);
    cin >> n >> k;

    for (int  i =1 ; i <= n ; i++) {
        int x,y;
        cin >> x >> y;
        cnt[x] += y;
    }
    long long now = 0;
    for (int i = 1; i  <= 100000 ;i++) {
        now += cnt[i];
        if ( now >= k) {
            cuti(i);
            return 0;
        }
    }
}


Measured memory_bytes: 1024
using System;

public class timeLimit
{
	public static void Main()
	{
		string[] hoge = Console.ReadLine().Split(' ');

		var n = int.Parse(hoge[0]);
		var t = int.Parse(hoge[1]);

		var min = int.MaxValue; //minimum cost

		for(int i = 0; i < n; i++)
		{
			string[] fuga = Console.ReadLine().Split(' ');


			if(int.Parse(fuga[1]) <= t && int.Parse(fuga[0]) < min)
			{

				min = int.Parse(fuga[0]);
				
			}
		}

		if(min < int.MaxValue)
		{
			Console.WriteLine(min);
		}
		else
		{
			Console.WriteLine("TLE");
		}
		
	}	
}

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



int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,x;
    cin>>n>>x;
    ll dp[2010][2010];
    rep(i,n)cin>>dp[i][0];
    
    forx(i,1,n){
        rep(j,n){
            dp[j][i]=min(dp[j][i-1],dp[(j+n-1)%n][i-1]);
        }
    }

    ll ans=1e18;
    rep(i,n){
        ll sum=i*x;
        rep(j,n)sum+=dp[j][i];
        ans=min(ans,sum);
    }

    cout<<ans<<endl;

    return 0;
}


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

using namespace std;

typedef long long ll;
const int maxn = 610,mod = 1e9 + 7;
int n,a[maxn],b[maxn],cnt,f[maxn][310][310];

int main()
{
    scanf("%d",&n);
    for (int i = 1; i <= 2 * n; i++)
        scanf("%d",&a[i]);
    for (int i = 1; i <= n; i++)
    {
        if (a[i * 2 - 1] != -1 && a[i * 2] != -1)
            b[a[i * 2 - 1]] = b[a[i * 2]] = 2;
        else if (a[i * 2 - 1] == -1 && a[i * 2] == -1)
            cnt++;
        else if (a[i * 2 - 1] == -1)
            b[a[i * 2]] = 1;
        else
            b[a[i * 2 - 1]] = 1;
    }
    f[2 * n][0][0] = 1;
    for (int i = 2 * n; i >= 1; i--)
    {
        if (b[i] == 2)
        {
            for (int j = 0; j <= n; j++)
                for (int k = 0; k <= n; k++)
                    f[i - 1][j][k] = f[i][j][k];
        }
        else if (b[i] == 1)
        {
            for (int j = 0; j <= n; j++)
                for (int k = 0; k <= n; k++)
                {
                    if (j >= 1)
                        (f[i - 1][j - 1][k] += f[i][j][k]) %= mod;
                    if (k <= n)
                        (f[i - 1][j][k + 1] += f[i][j][k]) %= mod;
                }
        }
        else
        {
            for (int j = 0; j <= n; j++)
                for (int k = 0; k <= n; k++)
                {
                    if (k >= 1)
                        (f[i - 1][j][k - 1] += 1LL * f[i][j][k] * k % mod) %= mod;
                    if (j <= n)
                        (f[i - 1][j + 1][k] += f[i][j][k]) %= mod;
                    if (j >= 1)
                        (f[i - 1][j - 1][k] += f[i][j][k]) %= mod;
                }
        }
    }
    int temp = 1;
    for (int i = 2; i <= cnt; i++)
        temp = 1LL * temp * i % mod;
    printf("%d\n",1LL * f[0][0][0] * temp % mod);

    return 0;
}


Measured memory_bytes: 225536
INF = float('inf')
cnt = 0
def merge(lst, left, middle, right):
    global cnt
    left_list  = lst[left:middle]+[INF]
    right_list = lst[middle:right]+[INF]
    i,j = 0,0
    for k in range(left, right):
        cnt += 1
        if left_list[i] < right_list[j]:
            lst[k] = left_list[i]
            i += 1
        else:
            lst[k] = right_list[j]
            j += 1
    
def merge_sort(lst, left, right):
    if left+1 < right:
        middle = (left+right)//2
        merge_sort(lst,   left, middle)
        merge_sort(lst, middle, right)
        merge(lst,left, middle, right)

n = int(input())
num_list = list(map(int,input().split()))
merge_sort(num_list,0,n)
print(' '.join([str(i) for i in num_list]))
print(cnt)



Measured memory_bytes: 66804
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [input() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    a, b, c, d = MI()
    left = a + b
    right = c + d
    if left > right:
        print("Left")
    elif left < right:
        print("Right")
    else:
        print("Balanced")
if __name__ == '__main__':
    main()

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

inline int read(){
    int X=0,w=0; char ch=0;
    while(!isdigit(ch)) {
        w|=ch=='-';ch=getchar();
    }
    while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    return w?-X:X;
}

inline void write(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}

inline void writeln(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
    puts("");
}

int a[110];

signed main(){
    int n=read();
    int ans=0;

    for(int i=1;i<=n;i++){
        a[i]=read();
        if(i%2==1 && a[i]%2==1)
            ans++;
    }
    
    writeln(ans);
    return 0;
}

Measured memory_bytes: 3572
#include <stdio.h>
int main(void) {
  int i,n;
  long double sum=0,a[100];
  scanf("%d",&n);
  for(i=0;i<n;i++) {
    scanf("%Lf",&a[i]);
    sum+=1/a[i];
  }
  printf("%Lf\n",1/sum);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    int n; cin >> n;
    int a[100010] = {};
    rep(i,0,n) cin >> a[i];
    sort(a, a+n);

    int x = (n % 2) ? 0 : 1;
    int k = 0;
    rep(i,0,n/2) {
        rep(j,0,(!i && n%2) ? 1 : 2) {
            if(a[k] != x) {
                cout << 0 << endl;
                return 0;
            }
            k++;
        }
        x += 2;
    }

    int ans = 1;
    rep(i,0,n/2) ans = (ans * 2) % MOD;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1152
using System;
using System.Linq;
using static System.Math;

class D
{
	static void Main() => Console.WriteLine(string.Join("\n", new int[int.Parse(Console.ReadLine())].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).Select(x => Find(x[0], x[1]))));

	static decimal Find(decimal a, decimal b)
	{
		decimal ab = a * b, r = (decimal)Sqrt((double)ab), r_ = Ceiling(r) - 1;
		return a == b ? 2 * (a - 1) :
			r == r_ + 1 ? 2 * r - 3 :
			r_ + Ceiling(ab / r_) - 3;
	}
}


Measured memory_bytes: 13652