akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
vector<int> ans[2];
vector<int> g[100001];
bool v[100001];
int cnt;
void dfs(int x){
    for(int i=0;i<g[x].size();i++){
        if(v[g[x][i]])
            continue;
        v[g[x][i]]=1;
        ans[cnt].push_back(g[x][i]);
        dfs(g[x][i]);
        return;
    }
}
int main(){
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    srand((unsigned int)(time(NULL)));//随机数保佑（超时我就找你算账）
    unsigned int o=rand()%n+1;
    ans[0].push_back(o),ans[1].push_back(g[o][0]);
    v[o]=1,v[g[o][0]]=1;
    dfs(o);
    cnt++;
    dfs(g[o][0]);
    cout<<ans[0].size()+ans[1].size()<<endl;
    for(int i=ans[0].size()-1;i>=0;i--)
        cout<<ans[0][i]<<" ";
    for(int j=0;j<ans[1].size();j++)
        cout<<ans[1][j]<<" ";
    cout<<endl;
    return 0;
}

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

using namespace std;

int main() {
    int n;
    cin>>n;
    if ( n==1) {
        cout<<1<<endl;
    }
    else {
        if ( n%2==0) cout<<n/2<<endl;
        else cout<< (n/2)+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

vector<int> G[100005];
int parent[100005];

int main(){
  int N, M;
  cin >> N >> M;
  rep(i,M){
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  rep(i,100005) parent[i] = -1;
  parent[1] = 1;
  
  queue<int> que;
  que.push(1);
  while(!que.empty()){
    int v = que.front(); que.pop();

    rep(i,G[v].size()){
      if(parent[G[v][i]] != -1) continue;
      parent[G[v][i]] = v;
      que.push(G[v][i]);
    }
  }

  cout << "Yes" << endl;
  REP(i,2,N+1){
    cout << parent[i] << endl;
  }
  
  
  return 0;
}



Measured memory_bytes: 10492
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;

int main(){
  int n,ans[1000000]={0};
  bool num[1000000]={true};
  num[1]=true;
  for(int i=2;i<1000000;i++){
    if(num[i]==false){
      for(int j=i+i;j<1000000;j=j+i){
	num[j]=true;
      }
    }
  }

  for(int i=1;i<1000000;i++){
    ans[i]=ans[i-1]+!num[i];
    //cout<<num[i]<<endl;
  }
  while(cin>>n){
    cout<<ans[n]<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 7892
# -*- coding: utf-8 -*-
"""
Created on Sat Apr  6 21:09:02 2019

@author: rubug
"""

A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

T = [A,B,C,D,E]
t = [A % 10,B % 10,C % 10,D % 10,E % 10]
for i in range(5):
    if t[i]==0:
        t[i]=10
t.sort()
t.reverse()

sm = 0
for i in range(4):
    sm += T[i]-t[i]+10
sm += T[4]

print(sm)  

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int a, b, x;
  cin >> a >> b >> x;
  if (a <= x && a + b >= x)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

//const long long MOD = 1000000007;
const long long MOD = 998244353;
const long long INF = 1LL << 60;



const long double PI = 3.14159265359;
const int MAX_N = 100010;


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m; cin >> n >> m;
	VE a(n); rep(i, n)cin >> a[i];
	vector<P>tmp(m);
	rep(i, m) {
		int b, c; cin >> b >> c;
		tmp[i] = make_pair(c, b);
	}
	sort(ALLR(tmp));
	sort(ALL(a));
	vector<int>ans;
	int now = 0;
	rep(i, n) {
		if (tmp[now].second == 0)now++;
		if (now >= m)break;
		ans.push_back(tmp[now].first);
		tmp[now].second--;
	}
	sort(ALLR(ans));
	rep(i, n) {
		if (i >= ans.size())break;
		if (ans[i] > a[i]) {
			a[i] = ans[i];
		}
		else break;
	}
	int sum = 0;
	rep(i, n)sum += a[i];
	cout << sum << endl;
	return 0;
}

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

int n;

int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	long double v, w, a , b, tt;
	cin>>a>>v;
	cin>>b>>w;
	cin>>tt;

	if(v <= w ) {
		cout<<"NO\n";
	} else {
		long double dist = (abs(a - b));
		long double speed = (v - w);
		long double t = (dist)/(speed);
		// cout<<dist<<": "<<speed<<endl;
		// cout<<t<<endl;
		if(t > tt)
			cout<<"NO\n";
		else 
			cout<<"YES\n";
	}
}




Measured memory_bytes: 3640
import Control.Applicative
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.List
import Data.Char (isSpace)

main :: IO ()
main = solve <$> f <*> f >>= print
  where
    f = readil B.readInt <$> B.getLine

solve :: [Int] -> [Int] -> Int
solve [n, k] xs = f 1000000000 xs (drop (k-1) xs)
  where
    f t _ [] = t
    f t (y:ys) (z:zs)
      | y * z >= 0 = f (min t (max (abs y) (abs z))) ys zs
      | otherwise = f (min t (max (abs y) (abs z) + 2 * (min (abs y) (abs z)))) ys zs

readil :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> [a]
readil f = unfoldr g
  where
    g s = do
      (n, s') <- f s
      return (n, B.dropWhile isSpace s')


Measured memory_bytes: 8572
import java.util.Scanner;

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

		for (int i = 0; i < w.length; i++) {
			w[i] = sc.nextInt();
		}

		int min = Integer.MAX_VALUE;

		for (int i = 0; i < N; i++) {
			int S1 = 0;
			int S2 = 0;
			for (int j = 0; j <=i; j++) {
				S1 += w[j];
			}
			for (int j = i+1; j < N; j++) {
				S2 += w[j];
			}
			min = Math.min(Math.abs(S1-S2), min);
		}
		System.out.println(min);
	}
}


Measured memory_bytes: 21844
using System;

class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        string[] str = Console.ReadLine().Split(' ');
        for(;;)
        {
            if (n == 1) { Console.WriteLine(str[n - 1]); }
            else Console.Write(str[n-1] +" ");
            n--;
            if (n == 0) { break; }
        }
    }
}


Measured memory_bytes: 15936
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000009;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-10;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}

int main(){
	long long N,A,B;
	scanf("%lld%lld%lld",&N,&A,&B);
	if(A>B||(A!=B&&N==1)){
		printf("0\n");return 0;
	}
	printf("%lld\n",B*(N-2)-A*(N-2)+1);
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
    int H,M,h,m,K;
    cin >> H>>M>>h>>m>>K;
    int hajime = H*60+M;
    int ohari = h*60+m;
    int aida = ohari-hajime;
    cout<<aida - K;
    return 0;
}

Measured memory_bytes: 3188
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	Main m = new Main();
	m.answer();
    }

    private Scanner scan = new Scanner(System.in);
    private int N;
    private int[] count = new int[101];

    public Main() {
	N = Integer.parseInt(scan.next());
	for (int i = 0; i < N; i++) {
	    int d = Integer.parseInt(scan.next());
	    count[d]++;
	}

	scan.close();
    }

    public final void answer() {
	long ans = Arrays.stream(count)
	    .filter(c -> c > 0)
	    .count();
	System.out.println(ans);
    }
}


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

//ライブラリ始まり

//定数

//円周率
const double PI = 3.1415926535897932384;

//天井
const int INF = 1000000000; // = 10^9
const ll LINF = 1000000000000000; // = 10^15

//ABC文字列
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC";
const string abc = "abcdefghijklmnopqrstuvwxyzabc";

//よくあるmodくん
const ll MOD = 1000000007; // = 10^9 + 7

//関数

//ctoi
int ctoi(char c){
  if (c == '0') {
    return 0;
  }
  if (c == '1') {
    return 1;
  } 
  if (c == '2') {
    return 2;
  } 
  if (c == '3') {
    return 3;
  }
  if (c == '4') {
    return 4;
  } 
  if (c == '5') {
    return 5;
  } 
  if (c == '6') {
    return 6;
  }
  if (c == '7') {
    return 7;
  } 
  if (c == '8') {
    return 8;
  } 
  if (c == '9') {
    return 9;
  }
  return -1;  
}

//素数判定
bool PN(int x) {
  if (x <= 1) {
    return false;
  }
  if (x == 2) {
    return true;
  }
  for (int i = 2; i < sqrt(x) + 1; i++) {
    if (x % i == 0) {
      return false;
    }
  }
  return true;
}

//ライブラリ終わり

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  cout << A.at(N - 1) - A.at(0) << endl;
}

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

int main(){
  int n, t;
  cin >> n;
  set<int> s;
  for(int i=0; i<n; i++){
    cin >> t;
    s.insert(t);
  }
  cout << s.size() << endl;
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int a, b;
	scanf("%2d%2d", &a, &b);
	a = a>0 && a < 13;
	b = b>0 && b < 13;

	if (a && b) puts("AMBIGUOUS");
	else if (a) puts("MMYY");
	else if (b) puts("YYMM");
	else puts("NA");
}


Measured memory_bytes: 128
import java.util.Arrays;
import java.util.Scanner;

public class Main {
  Scanner sc;

  void run() {
    while (true) {
      int n = ni();
      int p = ni();
      if ((n | p) == 0)
        break;

      int[] list = new int[n];
      int idx = 0;
      // 10^6
      while (true) {
        if (p == 1) {
          boolean f = false;
          // 50
          for (int i = 0; i < n; ++i) {
            if (i == idx)
              continue;
            f |= list[i] > 0;
          }
          if (!f) {
            break;
          }
        }

        if (p == 0) {
          p += list[idx];
          list[idx] = 0;
        } else {
          --p;
          ++list[idx];
        }

        ++idx;
        idx %= n;
      }

      System.out.println(idx);
    }
  }

  int ni() {
    return sc.nextInt();
  }

  Main() {
    sc = new Scanner(System.in);
  }

  public static void main(String[] args) {
    new Main().run();
  }

  void debug(Object... os) {
    System.err.println(Arrays.deepToString(os));
  }
}

Measured memory_bytes: 20308
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
typedef long long ll;
using namespace std;
int main()
{
	int N, K;
  	cin >> N >> K;
  	if(K == 1) {
    	cout << 0 << endl;
    } else {
    	cout << N - K<< endl;
    }
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

long long mod = 1e9 + 7;

long long pow_mod(long long n, long long p) {
    long long ret = 1;
    while (p > 0) {
        if (p & 1) ret = (ret * n) % mod;
        n = (n * n) % mod;
        p >>= 1;
    }
    return ret;
}

int main() {

    long long N;
    cin >> N;

    vector<long long> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];

    map<long long, long long> M;
    for (auto x: a) M[x]++;

    bool good = true;
    if (N % 2 == 1) {
        if (M[0] != 1) good = false;
        for (int i = 2; i <= N - 1; i += 2) if (M[i] != 2) good = false;
    }
    if (N % 2 == 0) {
        for (int i = 1; i <= N; i += 2) if (M[i] != 2) good = false;
    }

    if (!good) {
        cout << 0 << endl;
    } else {
        cout << pow_mod(2, N / 2) << endl;
    }


}




























Measured memory_bytes: 6144
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;
 
 
 
const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
 
 
 
int main(){
	int n,k;
	while(cin >> n){
		vector<vector<int>> e_list;
		vector<int> v_val(n+1,INF);
		
		vector<pair<int,int>> v_queue;
		
		for(int i=0;i<n+1;i++){
			e_list.push_back(vector<int>());
		}
		for(int i=0;i<n-1;i++){
			int a,b;
			cin >> a >> b;
			e_list[a].push_back(b);
			e_list[b].push_back(a);
		}
		cin >> k;
		if(k == 0){
			v_val[1] = 1;
			v_queue.emplace_back(1,1);
		}else{
			for(int i=0;i<k;i++){				
				int v,p;
				cin >> v >>	p;
				v_val[v] = p;
				v_queue.emplace_back(p,v);
			}
			sort(v_queue.begin(),v_queue.end());
		}
		
		while(!v_queue.empty()){
			int v = v_queue.back().second;
			v_queue.pop_back();
			int s = e_list[v].size();
			
			for(int i=0;i<s;i++){
				int ne = e_list[v][i];
				if(v_val[ne] == INF){
					v_val[ne] = v_val[v] - 1;
					pair<int,int> q(v_val[ne],ne);
					std::vector<pair<int,int>>::iterator it = lower_bound (v_queue.begin(), v_queue.end(), q);
					v_queue.emplace(it,q);
				}
				else if(v_val[ne] - v_val[v] != -1 && v_val[ne] - v_val[v] != 1){
					cout << "No" << endl;
					return false;
				}
			}
		}
		
		cout << "Yes" << endl;
		for(int i=1;i<v_val.size();i++)
			cout << v_val[i] << endl;
		
	}
	
	return 0;
}

Measured memory_bytes: 8816
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
using namespace std;


int main(){
  int n,t;
  int c,tt;
  int ans=10000;
  scanf ("%d %d",&n,&t);
  for(int k=0;k<n;++k){
    scanf ("%d %d",&c,&tt);
    if(tt<=t){
      if(c<ans){
        ans=c;
      }
    }
  }
  if(ans==10000){
    printf("TLE\n");
  }
  else{
    printf("%d\n",ans);
  }

}


Measured memory_bytes: 256
//#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <math.h>
 
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
// using namespace __gnu_pbds;
// template<class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
 
#define ll long long int
#define ull unsigned long long int
 
#define lp(i,n) 	    for(int i=0;i<(int)(n);i++)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);i++)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);i--)
 
#define all(v)  	 ((v).begin()), ((v).end())
#define sz(v)    	 ((int)((v).size()))
#define clr(v, d)    memset(v, d, sizeof(v))
#define PB           push_back
#define MP           make_pair
#define N 100006
 
#define PI 3.14159265359
 
ll gcd(ll a, ll b);
vector<string> split(string target,unsigned char c );
 
 
ll n,k,t,m,x,y,l,r;
 
bool isPrime(ll h); 
 
ll ans;

 
ll mod=1e9 +7;


 
int main() {
// freopen("d.in","r",stdin); 
// 	freopen("d_out.txt","w",stdout); 
cout.precision(7);
ios_base::sync_with_stdio(false);
cin.tie(NULL);  cout.tie(NULL);

cin>>x>>y>>l;
if(x==y && y!=l || (x==l && y!=l) || (y==l && y!=x))cout<<"Yes\n";
else cout<<"No\n";

	
 
 
}

ll gcd(ll a, ll b){
	return b==0?a:gcd(b,a%b);
}
 
 
vector<string> split(string target,unsigned char c ){
	string d="";
	vector<string>arr;
	for(auto n:target)
	{
		if(n!=c)
		d+=n;
		else if(d!="")
		arr.push_back(d),d="";
	}
	if (d!="")
	arr.push_back(d),d="";
	return arr;
}
// bool isPrime(ll h){
//      for(ll i=0;primes[i]*primes[i]<= h;i++)
//      if (h%primes[i]==0)
//      	return 0;
//      return h!=1;
//  }
 bool isPrime(ll g){
   if((g%2==0 && g>2) || g==1)return 0;
   for(ll i=3;i*i<=g;i+=2)if(g%i==0)return 0;
   return 1;   
 
 }

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

using namespace std;

const int N=1e3;

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

int dist[N+2][N+2];
char grid[N+2][N+2];
priority_queue<pair<int,pair<int,int>>,vector<pair<int,pair<int,int>>>,greater<pair<int,pair<int,int>>>>pq;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int i,j,m,n,x,x1,x2,y,y1,y2,z;
    cin >> n >> m >> x1 >> y1 >> x2 >> y2;
    for(i=1;i<=n;i++)
    {
        cin >> grid[i]+1;
        for(j=1;j<=m;j++)dist[i][j]=INT_MAX;
    }
    dist[x1][y1]=0;
    pq.push({0,{x1,y1}});
    while(!pq.empty())
    {
        z=pq.top().first;
        x=pq.top().second.first;
        y=pq.top().second.second;
        pq.pop();
        for(i=0;i<4;i++)
        {
            x1=x+dx[i];
            y1=y+dy[i];
            if(x1 > 0  &&  x1 <= n  &&  y1 > 0  &&  y1 <=m  &&  grid[x1][y1] == '.'  &&  dist[x1][y1] > z)
            {
                dist[x1][y1]=z;
                pq.push({z,{x1,y1}});
            }
        }
        ++z;
        for(i=x-2;i<=x+2;i++)
        {
            for(j=y-2;j<=y+2;j++)
            {
                if(i > 0  &&  i <= n  &&  j > 0  &&  j <=m  &&  grid[i][j] == '.'  &&  dist[i][j] > z)
                {
                    dist[i][j]=z;
                    pq.push({z,{i,j}});
                }
            }
        }
    }
    if(dist[x2][y2] == INT_MAX)cout << "-1";
    else cout << dist[x2][y2];
    return 0;
}

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

int main() {
  string S;
  cin>>S;
  vector<int64_t> A(26,0);
  int64_t a=-97,b=S.size();
  rep(i,b){
    int64_t c=S.at(i);
    A.at(a+c)++;
  }
  int64_t ans=b*(b-1)/2;
  rep(i,26){
    int64_t d=A.at(i);
    if(d>1) ans-=d*(d-1)/2;
  }
  cout<<ans+1;
}


Measured memory_bytes: 3704
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
using namespace std;

long long digit_sum(long long n, long long base = 10) {
    long long res = 0;
    while (n > 0) res += n % base, n /= base;
    return res;
}

int main() {
    long long n, s; cin >> n >> s;
    if (n < s) return cout << -1 << endl, 0;
    if (n == s) return cout << n + 1 << endl, 0;
    set<long long> res;
    for (long long b = 2; b * b <= n; b++) {
        if (digit_sum(n, b) == s) res.emplace(b);
    }
    for (long long p = 1; p * p < n; p++) {
        if ((n - s) % p == 0) {
            long long b = (n - s) / p + 1;
            if (0 <= s - p && s - p < b) res.emplace(b);
        }
    }
    if (res.empty()) {
        cout << -1 << endl;
    } else {
        cout << *res.begin() << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

struct edge{
    ll to, cost;
};

using Graph = vector<vector<edge>>;
vector<ll> dis(100010);

void dfs(const Graph &G, ll v, ll p, ll d) { 
    dis[v] = d;
	for (auto nv : G[v]) {
		if (nv.to == p)continue;
		dfs(G, nv.to, v, d + nv.cost);
	}
}


int main() {
    int n;
    cin >> n;
    Graph G(n);
    rep(i, n-1){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        G[a].push_back({b, c});
        G[b].push_back({a, c});
    }
    ll q, k;
    cin >> q >> k; k--;
    dfs(G, k, -1, 0);
    rep(i, q){
        int x, y;
        cin >> x >> y;
        x--; y--;
        cout << dis[x] + dis[y] << endl;
    }
}


Measured memory_bytes: 17280
#include <bits/stdc++.h>
int h, w, k, x1, yy1, x2, y2, d[4] = {1,-1}, mp[3000005], qu[1000005], b, e, inf=1e9;
int main(){
	scanf("%d%d%d", &h, &w, &k); w++;
	scanf("%d%d%d%d", &x1, &yy1, &x2, &y2);
	memset(mp,-1,sizeof(mp));
	for(int i=0; i<h*w; i++) if(getchar() == '.') mp[i+w] = inf;
	mp[qu[e++] = x1*w+yy1] = 0;
	d[2] = w; d[3] = -w;
	while(b<e) for(int i=0, x=qu[b++]; i<4; i++) for(int nx=x+d[i], u=0; u<k && mp[nx]>mp[x]; u++, nx+=d[i]) if(mp[nx] == inf) mp[qu[e++] = nx] = mp[x] + 1;
	printf("%d\n", mp[x2*w+y2] == inf ? -1 : mp[x2*w+y2]);
}

Measured memory_bytes: 18444
#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
int sub(int a, int b) { return (a -= b) < 0 ? a + mod : a; }

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  #ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif

  string s;
cin >> s;
cout << (s[0] == '7' || s[1] == '7' || s[2] == '7' ? "Yes" : "No");
}

Measured memory_bytes: 3648
def main():
    N = int(input())
    num = [True for i in range(N+1)]
    
    for i in range(N+1):
        if i%3 == 0 or i%5 == 0:
            num[i] = False
    
    ans = 0
    for i in range(N+1):
        if num[i]:
            ans += i
    
    print(ans)
    
    
    
    
    
    
    
if __name__ == "__main__":
    main()


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

bool check(int n) {
  string s = to_string(n);
  bool ok = true;
  for (int i = 0;i<s.size();i++) {
    if (s.at(i) != s.at(s.size()-1-i)) ok = false;
  }
  return (ok);
}

    


int main() {
  int A,B;
  cin >> A >> B;
  int cnt = 0;
  for (int i = A;i<=B;i++) {
    if (check(i)) cnt++;
  }
  cout << cnt << endl;
  
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
	int N, K;
	cin >> N >> K;
	vector <int> A(N);
	for (int ii = 0; ii < N; ++ii){
		cin >> A[ii];
	}

	for (int kk = 0; kk < K; ++kk){
		vector <int> imos(N + 1, 0);
		for (int ii = 0; ii < N; ++ii){
			int left = max(0, ii - A[ii]);
			int right = min(N, ii + 1 + A[ii]);
			imos[left]++;
			imos[right]--;
		}
		// printf("imos = ");
		// for (int ii = 0; ii < N; ++ii){
		// 	printf("%i  ", imos[ii]);
		// }
		// printf("\n");
		for (int ii = 1; ii < N; ++ii){
			imos[ii] += imos[ii-1];
		}
		for (int ii = 0; ii < N; ++ii){
			A[ii] = min(N, imos[ii]);
		}

		bool ok = true;
		for (int ii = 0; ii < N; ++ii){
			if (A[ii] < N){
				ok = false;
				break;
			}
		}
		if (ok){
			break;
		}
	}

	for (int ii = 0; ii < N; ++ii){
		cout << A[ii] << " ";
	}
	cout << "\n";

	return 0;
}


Measured memory_bytes: 4844
import java.io.*;
import java.util.function.*;
import java.util.stream.*;
 
class Main
{
    /**
     * ABC 062 B: Picture Frame
     *     (周囲1ピクセルを'#'で囲む)
     */ 
    public static void main(String[] args) throws IOException
    {
        // 入力
        BufferedReader br = new BufferedReader(
                new InputStreamReader(System.in));
        int[] HW = Stream.of(br.readLine().split(" ")).mapToInt(
                item -> new Integer(item)).toArray();
        Stream<String> as = br.lines().filter(item -> item.indexOf(" ") < 0);
 
        // 枠線を入れる
        // Streamは同じインスタンスで2度処理を実行できないため、Supplierを通す
        Supplier<Stream<String>> frame = () ->
                Stream.of(new String(new char[HW[1]]).replace("\0", "#"));
        Stream<String> out = Stream.concat(frame.get(), Stream.concat(as, frame.get())).map(
                item -> "#" + item + "#") ;        
 
        // 出力
        System.out.println(out.collect(Collectors.joining("\n")));
    }
}

Measured memory_bytes: 26196
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	std::string s;
	std::cin >> s;
	std::set<char> set;
	for(auto c:s) set.emplace(c);
	if(set.size()==2) {
		print("Yes");
	} else print("No");
	return 0;
}


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

int main(){
    int n; cin >> n;
    vector<int> x(n);
    vector<int> b(n);
    for(int i = 0; i < n; i++){
        cin >> x[i];
        b[i] = x[i];
    }
    sort(x.begin(), x.end());
    int ans1 = x[n/2], ans2 = x[n/2-1];
    for(int i = 0; i < n; i++){
        if(b[i] <= ans2){
            cout << ans1 << endl;
        }else{
            cout << ans2 << endl;
        }
    }
}

Measured memory_bytes: 3712
//#include <bits/stdc++.h>
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
#include <queue>
#include <cctype>
using namespace std;
using ll = long long;
const int mod = 1000000007;

ll gcd(ll a, ll b){return b ? gcd(b,a%b) : a;};//最大公約数
ll lcm(ll a, ll b){return a*b/gcd(a,b);};//最小公倍数
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[100001];
//char str[1010][1010];
//typedef pair<ll,ll> A;
//vector<A> pc;
//int ABS(int a){return max(a,-a);}
//ll a[100000];
//ll dom[100001];

int main(){
  ll n;
  cin>>n;
  ll a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a,a+n);
  for(int i=0;i<n-1;i++){
    if(a[i]==a[i+1]){
      cout<<"NO";
      return 0;
    }
  }
  cout<<"YES";
  return 0;
}

Measured memory_bytes: 1792
N, A = map(int, input().split())
X = list(map(lambda x:int(x)-A, input().split()))
dp = [0]*10000
dp[0] = 1
for i in range(N):
  new_dp = dp[:]
  for j in range(-3000,3000):
    if dp[j]>0:
      new_dp[j+X[i]] += dp[j]
  dp = new_dp
print(dp[0]-1)


Measured memory_bytes: 73448
n = int(input())
h = tuple(map(int, input().split()))
cost = [0] * (n + 1)

inf = 10**18
dp = [inf]*(n+5)
dp[0] = 0
dp[1] = abs(h[1]-h[0])

for i in range(2, n):
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))

ans = dp[n-1]
print(ans)


Measured memory_bytes: 14052
import sys



# ---------------------------------------------------
# ---------------------------------------------------
# ---------------------------------------------------



def resolve():
    class Node:
        def __init__(self, data):
            self.data = data
            self.left = None
            self.right = None

    class BST:
        def __init__(self):
            self.node = None

        def insert(self, data):
            if self.node is None:
                self.node = Node(data)
            else:
                self._insert(data, self.node)

        def _insert(self,data, cur_node):
            if data < cur_node.data:
                if cur_node.left is None:
                    cur_node.left = Node(data)
                else:
                    self._insert(data, cur_node.left)
            elif data > cur_node.data:
                if cur_node.right is None:
                    cur_node.right = Node(data)
                else:
                    self._insert(data, cur_node.right)
            else:
                print("同じ値があります。")

        def pre_order_print(self):
            if self.node:
                self._pre_order_print(self.node)

        def _pre_order_print(self, cur_node):
            if cur_node:
                print(" ", end="")
                print(cur_node.data, end="")
                self._pre_order_print(cur_node.left)
                self._pre_order_print(cur_node.right)

        def in_order_print(self):
            if self.node:
                self._in_order_print(self.node)

        def _in_order_print(self, cur_node):
            if cur_node:
                self._in_order_print(cur_node.left)
                print(" ", end="")
                print(cur_node.data, end="")
                self._in_order_print(cur_node.right)

    N = int(input())
    bst = BST()
    lines = sys.stdin.readlines()
    for line in lines:
        s = line.split()
        if s[0] == "insert":
            x = int(s[1])
            bst.insert(x)
        else:
            # 出力規定： 先頭に1つの空白もいれる
            bst.in_order_print()
            print()
            bst.pre_order_print()
            print()


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 141172
N,K = list(map(int,input().split()))
h = []
for i in range(N):
    h.append(int(input()))
sorted_h = sorted(h)
minDelta = 10 ** 10
for i in range(N-K+1):
    delta = sorted_h[i+K-1] - sorted_h[i]
    if minDelta > delta:
        minDelta = delta
print(minDelta)

Measured memory_bytes: 13904
//Dijkstra
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
typedef pair<int, int> P;
int n, dis[10001], n_left;
vector< vector<P> > G(10001);
priority_queue< P, vector<P>, greater<P> > heap;
bool visited[10001];

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

    scanf("%d", &n);
    n_left = n;
    for(int i=0; i<n; i++){
        scanf("%d %d", &u, &k);
        for(int j=0; j<k; j++){
            scanf("%d %d", &v, &w);
            G[u].push_back(P(w, v));
        }
    }
    memset(visited, 0, sizeof(visited));
    memset(dis, 127, sizeof(dis));

    dis[0] = 0;
    heap.push(P(0, 0));
    while(!heap.empty() && n_left>0){
        P top = heap.top();
        heap.pop();
        if(!visited[top.second]){
            u = top.second;
            visited[u] = true;
            --n_left;
            for(int i=0; i<G[u].size(); i++){
                v = G[u][i].second;
                w = dis[u] + G[u][i].first;
                if(!visited[v] && w < dis[v]){
                    heap.push(P(w, v));
                    dis[v] = w;
                }
            }
        }
    } 
    for(int i=0; i<n; i++){
        printf("%d %d\n", i, dis[i]);
    }
    return 0;
}


Measured memory_bytes: 7688
#include <iostream>
    #include <bits/stdc++.h>
    #include <math.h>
    using namespace std;
    #define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
 
    #define ull unsigned long long 
    #define int long long
    #define pb push_back 
    #define SZ(x) ((int)x.size())
    #define mp make_pair
    #define ff first
    #define ss second
    #define lb lower_bound
    #define ub upper_bound
    #define endl "\n"
    #define Max(x,y,z) max(x,max(y,z))
    #define Min(x,y,z) min(x,min(y,z))
    #define MAX 1e18
    #define PI 3.14159265
    const int mod = 1e9 + 7;

    #define ordered_set tree<pair<int, int>, null_type,less<pair<int, int>>, rb_tree_tag,tree_order_statistics_node_update>
    
     
     
     
     
     
     
    int power(int x, int y) 
    { 
       int res = 1;      
                                                                  
       
        while (y > 0) 
        { 
           
            if (y & 1) 
                res = (long long)(res*x); 
      
     
            y = y>>1; 
     
            if (x<=100000000)
            x = (long long)(x*x);
     
            //cout<<x<<'\n'; 
        } 
        return res; 
    } 
     
    int gcd (int a, int b) {
        if (b == 0)
            return a;
        else
            return gcd (b, a % b);
    }
     
    int ceiling(int a,int b){
      if(a%b!=0){
        return (a/b)+1;
     
      }
      else
        return (a/b);
    }
     
    int lcm (int a, int b) {
        return a / gcd(a, b) * b;
    }
     
    bool isPrime(int n) 
    { 
        // Corner cases 
        if (n <= 1) 
            return false; 
        if (n <= 3) 
            return true; 
      
        // This is checked so that we can skip 
        // middle five numbers in below loop 
        if (n % 2 == 0 || n % 3 == 0) 
            return false; 
      
        for (int i = 5; i * i <= n; i = i + 6) 
            if (n % i == 0 || n % (i + 2) == 0) 
                return false; 
      
        return true; 
    } 









void solve()
{
 int k;
 cin>>k;

 int m=7;
 int n=7;

 if(k%2==0 or k%2==5){
  cout<<-1<<endl;
  return;
 }

 int r=0;

 for(int i=1;i<=1e6;i++){

  r=(r*10 + 7)%k;

  if(r==0){
    cout<<i<<endl;
    return;
  }
   


 }

 cout<<-1<<endl;





  return;
  }




  



 int32_t main()
    
{
   IOS;
   
   int t;
   t=1;
   while(t--){
    solve();
   }

   return 0;
   
}
  
 





 
 

 


Measured memory_bytes: 3676
from itertools import product
def main():
    N,M,X=map(int, input().split())
    CA=[list(map(int, input().split())) for _ in range(N)]
    ans=float("inf")
    for p in product((False, True), repeat=N):
        res=[0]*(M+1)
        for pp,ca in zip(p,CA):
            if pp:
                for i in range(M+1):
                    res[i] += ca[i]
        if all(res[i]>=X for i in range(1,M+1)):
            ans=min(ans, res[0])
    if ans>=10**9:
        print(-1)
    else:
        print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 9220
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
    #include<numeric>
    #include<array>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
    #define chmin(a, b) a = min(a, b)
    #define chmax(a, b) a = max(a, b)
    #define Vl vector<ll>
     
    using namespace std;
    using ll = long long;
    using Graph = vector<vector<ll>>;
    using P = pair<ll, ll>;
     
const ll MOD = 1e9 + 7;
const ll ZER = 0;

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    int ma = min(a, b), mi = max(0, a + b - n);
    cout << ma << " "  << mi << endl;
}


Measured memory_bytes: 3580
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main()
{
    int N;
    int a[4];
    while(scanf("%d",&N)!=EOF)
    {

        a[0]=N%10;
        a[1]=N/10;
        if(a[0]!=9&&a[1]!=9)
            printf("No\n");
        else
            printf("Yes\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(int d=1; ; ++d){
        int n, m;
        cin >> n >> m;
        if(n == 0)
            return 0;

        vector<int> curr(m+1, 0);
        curr[0] = n;

        for(int t=1; ; ++t){
            vector<int> next(m+1, 0);
            for(int i=0; i<m; ++i){
                next[0] += curr[i] / 2;
                next[i] += curr[i] % 2;
                next[i+1] += curr[i] / 2;
            }

            curr.swap(next);
            if(curr[m] > 0){
                cout << "Case " << d << ": " << t << endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 1192
function dfs(n, m)
  result = []
  arr = [0]
  while length(arr) > 0
    while length(arr) > 0 && arr[end] == n
      pop!(arr)
    end
    if length(arr) > 0
      arr[end] += 1
      end_num = arr[end]
      while length(arr) < m
        push!(arr, end_num)
      end
      push!(result, copy(arr))
    end
  end
  return result
end

(()->begin
  n,m,q = readline() |> split |> x->parse.(Int,x)
  arr = fill([], q)
  for i in 1:q
    arr[i] = readline() |> split |> x->parse.(Int,x)
  end
  ans = 0
  dfs_result = dfs(m, n)
  for comb in dfs_result
    tmp = 0
    for (a,b,c,d) in arr
      if comb[b] - comb[a] == c
        tmp += d
      end
    end
    ans = max(ans, tmp)
  end
  println(ans)
end)()


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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

//実行部
void Main()
{
  ll n;
  cin >> n;
  vll a(n);
  rep(i, n) cin >> a[i];
  ll front = 0, back = 0;
  rep(i, n) back += a[i];
  ll ans = abs(back - front);
  for (ll i = 0; i < n; i++)
  {
    front += a[i];
    back -= a[i];
    ans = min(ans, llabs(front - back));
  }
  fin(ans)
}

//前処理
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;queue<int> q;char s[1000005],t[1000005];
int main() {int n,ans=0,flg=1;
	scanf("%d%s%s",&n,s+1,t+1);
	for (int i=1;i<=n;++i) flg&=(s[i]==t[i]);
	if (flg) return 0*puts("0");
	for (int i=n,j=n;i;--i) if (t[i-1]^t[i]) {
		for (j=min(i,j);j&&s[j]^t[i];--j);
		if (!j) return 0*puts("-1");
		while (!q.empty()&&q.front()-q.size()>=i) q.pop();
		q.push(j);if (i^j) ans=max(ans,int(q.size()));
	}printf("%d",ans+1);return 0;
}

Measured memory_bytes: 8888
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace A
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var LRd = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var (L, R, d) = (LRd[0], LRd[1], LRd[2]);
            var answer = 0;
            for (var i = L; i <= R; i++)
            {
                if (i % d == 0) answer++;
            }
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 27984
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
ll inf = 100000000;
ll v[205];
ll x[20000005];
ll a[10005], b[10005];
ll dp[10005][10005];
int dx[4] = { 1,-1,0,0 };
int dy[4] = { 0,0,1,-1 };
typedef pair<ll, ll> P;

P ans(ll i) {
	ll x = i % 10;
	ll b = 0;
	while (i) {
		b = i;
		i = i / 10;
	}
	return P(x, b);
}


int main() {
	int n;
	cin >> n;
	map<P, ll>v;
	for (int i = 1; i <= n; i++) {
		P now = ans(i);
		v[now]++;
	}
	ll kai = 0;
	for (int i = 1; i <= n; i++) {
		P a = ans(i);
		P q(a.second, a.first);
		kai += v[q];
	}
	cout << kai << endl;
	return 0;

}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>

int main()
{
	unsigned long long H;
	std::cin >> H;

	if (H == 1) {
		std::cout << 1 << std::endl;
		return 0;
	}

	unsigned long long e = 0;
	while (1 < H) {
		H /= 2;
		++e;
	}

	unsigned long long count = 3;
	if (1 < e) {
		for (unsigned long long i = 2; i <= e; ++i) {
			count = count * 2 + 1;
		}
	}




	std::cout << count << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#define int long long
signed main(){
  int M,N,ans,temp;
  std::cin>>N>>M;
  std::priority_queue<int>price;
  for (int i=0;i<N;i++){
    std::cin >> temp;
    price.push(temp);
  }
  for (int i=0;i<M;i++){
    temp=price.top();
    price.pop();
    price.push(temp/2);
  }
  for (int i=0;i<N;i++){
    ans+=price.top();
    price.pop();
  }
  std::cout<<ans<<std::endl;
}

Measured memory_bytes: 1400
#include<iostream>
using namespace std;
int main(){
	int a, b, c;
	cin >> a >> b >> c;
	if (a >= c){
		cout << 0 << endl;
	}
	else{
		if (a + b >= c){
			cout << c - a << endl;
		}
		else{
			cout << "NA" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3112
# 木上の累積和

import sys
from collections import defaultdict
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))


def ints():
    return list(map(int, read().split()))


N, Q = ints()
tree = defaultdict(lambda: [])
for _ in range(N - 1):
    a, b = mina(*ints())
    tree[a].append(b)
    tree[b].append(a)
cnt = [0] * N
for _ in ra(Q):
    q, x = ints()
    cnt[q - 1] += x
cnt.append(0)  # -1アクセス用

# dfsでcntに木に沿った累積和をsetしていく


# def dfs(u, p):  # uは現在のノード、pは親のノード
#     cnt[u] += cnt[p]
#     for nv in tree[u]:
#         if nv == p:
#             continue
#         dfs(nv, u)


def dfs(u, p):  # 戻り値なしver
    S_args = [(u, p)]  # 引数管理のstack
    S_cmd = [0]  # 0:into, 1:outofの処理をすべきと記録するstack

    def into(args):
        '''入るときの処理'''
        u, p = args
        cnt[u] += cnt[p]

    def nxt(args):
        S_args.append(args)  # 抜けるときに戻ってくることを予約
        S_cmd.append(1)
        '''今の引数からみて次の引数を列挙'''
        u, p = args
        for nx in tree[u]:
            if nx == p:
                continue
            _stack(nx, u)

    def outof(args):
        '''抜けるときの処理'''
        pass

    def _stack(*args):  # お好きな引数で
        S_args.append(args)
        S_cmd.append(0)

    while S_cmd:
        now_args = S_args.pop()
        cmd = S_cmd.pop()
        if cmd == 0:
            into(now_args)
            nxt(now_args)  # 次の再帰する(次のintoを予約)
        else:
            outof(now_args)


dfs(0, -1)

print(*cnt[:-1])


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

#define rep(i,n) for(int i=0;i<(n);++i)
#define loop(i,b,n) for(int i=b;i<(n);++i)
#define each(e,v) for(auto &&e : v)

#define all(v) (v).begin(),(v).end()
#define sz(v) (int)v.size()

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const double EPS = 1e-9;

template<typename A,typename B> inline void chmin(A &a,B b){ if(a>b) a=b; }
template<typename A,typename B> inline void chmax(A &a,B b){ if(a<b) a=b; }
template <typename T> inline void print(const T& x) { cout << x << endl; }

int main() {
    int n,m,k;
    cin >> n >> m >> k;
    vector<int> a(n+1);
    vector<int> b(m+1);

    a[0] = 0;
    cin >> a[1];
    loop(i,2,n+1){
        int t;
        cin >> t;
        a[i] = (k-a[i-1]) >= t ? a[i-1]+t : INF;
    }

    b[0] = 0;
    cin >> b[1];
    loop(i,2,m+1){
        int t;
        cin >> t;
        b[i] = (k-b[i-1]) >= t ? b[i-1]+t : INF;
    }

    int count = 0;
    for(int i=0; i<=n; ++i){
        if(a[i]>k) break;
        for(int j=count-i+1; j<=m; ++j){
            if(a[i]+b[j]>k) break;
            count = i+j;
        }
    }
    print(count);
    return 0;
}


Measured memory_bytes: 4844
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}




template <typename T>
struct  BIT{
	int n;
	vector<T> d;
	BIT(int n): n(n), d(n+1){}

	void add(int i, T x=1){
		for(i++; i<=n; i +=i&(-i)){
			d[i] += x;			
		}
	}

	T sum(int i){
		T x = 0;
		for(i++; i; i -= i&(-i)){
			x += d[i];
		}
		return x;
	}
	T sum(int l, int r){
		return sum(r-1) - sum(l-1);
	}

};




using P = pair<int, int>;
int main(){

	int N, Q;
	cin >> N >> Q;

	vector<int> c(N);
	vector<int> id(N, -1);
	vector<vector<int>> arrow(N);
	for(int i=0; i<N; i++){
		cin >> c[i];
		c[i]--;
		int left = id[c[i]];
		if(left != -1) arrow[left].push_back(i);
		id[c[i]] = i;
	}

	vector<vector<P>> qs(N);
	for(int i=0; i<Q; i++){
		int left, right;
		cin >> left >> right;
		left--; right--;
		qs[left].emplace_back(right, i);
	}

	vector<int> ans(Q);
	BIT<int> bi(N+1);
	for(int i=N-1; i>=0; i--){
		for(int a: arrow[i]) bi.add(a);
		// for(int j=0; j<(int)arrow[i].size(); j++){
		// 	int a = arrow[i][j];
		// 	bi.add(a);
		// }
		for(P q: qs[i]){
			int left = i;
			int right = q.first;
			int id = q.second;
			ans[id] = (right-left+1) - bi.sum(right);
		}
	}

	for(int i=0; i<Q; i++) cout << ans[i] << endl;
	
	return 0;
}



Measured memory_bytes: 59840