akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
using namespace std;
int n,k;
int dat[100002];
int main(void){
  scanf("%d%d",&n,&k);
  int i,j;
  int no=0,ls=0,ans=0;
  bool lf=false,cf=false;
  while(n!=0){
    for(i=0;i<k;i++)scanf("%d",&(dat[i]));
    sort(dat,dat+k);
    dat[k]=100005;
    i=0;
    if(dat[i]==0){
      cf=true;
      i++;
      if(dat[i]!=1)lf=true;
    }
    while(i<k){
      j=i;
      while(j<k && dat[j+1]==dat[j]+1)j++;
      ls=no;no=j-i+1;i=j;
      if(cf&&lf){
    ans=ans<no+ls+1?no+ls+1:ans;
      }
      else{
    ans=ans<no?no:ans;
      }
      if(dat[j+1]==dat[j]+2)lf=true;
      i++;
    }
    printf("%d\n",ans);
    scanf("%d%d",&n,&k);
  }
  return 0;
}

Measured memory_bytes: 2936
import java.util.Scanner;


public class Main{
	public static void main(String[] args) {
		Scanner scan =new Scanner(System.in);
		while(scan.hasNext()){
		int d=scan.nextInt();
		int s=0;
		for(int i=0;i*d<600;i++){
			s+=i*i*d*d*d;
		}
		System.out.println(s);
		}
	}

}

Measured memory_bytes: 17176
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		String S = input.next();
		String ans = "No";
		if (N%2==0) {
			int mid = N/2;
			String left = S.substring(0,mid);
			String right = S.substring(mid,N);
			if (left.equals(right)) ans="Yes";
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
#include<iostream> 
#include<vector>
#include<algorithm>
#include<queue>
#include<stdio.h>
#include<vector>
using namespace std;
int main(){
  int n, k, q;
  cin >> n >> k >> q;
  vector<int> cnt(n,0);
  int a;
  for(int i=0;i<q;i++){
    cin >> a;
    cnt[a-1]++;
  }
  for(int i=0;i<n;i++){
    if(q-cnt[i]>=k)cout << "No" << endl;
    else cout << "Yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
typedef long long ll;

using namespace std;
int n, mn = 9999999;

int main(){
cin >> n;

for(int i=1;i<n;i++){
	int a, b, res = 0;
	a = i;
	b = n - i;

	while(a){
		res += (a % 10);
		a /= 10;
	}
	while(b){
		res += (b % 10);
		b /= 10;
	}
	mn = min(mn, res);
}
cout << mn;
return 0;
}


Measured memory_bytes: 256
N[]={ 6, 14, 18, 10,  2,  9, 22, 15,  1, 17, 23,  7,  3,  5, 21, 19,  0, 13, 20, 11,  4,  8, 16, 12};
E[]={13, 17,  9,  5,  8, 21, 14,  1, 16, 22,  6,  0,  4, 20, 18,  2, 12, 23, 10,  3, 11, 19, 15,  7};
R_[]={ 3,  0,  1,  2,  7,  4,  5,  6, 11,  8,  9, 10, 15, 12, 13, 14, 19, 16, 17, 18, 23, 20, 21, 22};
a;
d;
T,F,R;
char s[9];
main(c)
{
	for(;c-48&&scanf("%s",s);a+=d/4+1)
	{
		c=*s;
		if(c<60)a&&printf("%d\n",a),a=d=0,T=1,F=2,R=3;
		if(c==78)d=N[d];
		if(c==83)d=N[N[N[d]]];
		if(c==69)d=E[d];
		if(c==87)d=E[E[E[d]]];
		if(c==82)d=R_[d];
		if(c==76)d=R_[R_[R_[d]]];
	}
}

Measured memory_bytes: 0
using System;
using System.Linq;
using System.Collections.Generic;
class P{
  class L{
    public List<L> r=new List<L>();
    public int d1=-1,dN=-1;
    public void Setd1(int n){
      if(d1==-1){
        d1=n;
        foreach(L l in r){
          l.Setd1(n+1);
        }
      }
    }
    public void SetdN(int n){
      if(dN==-1){
        dN=n;
        foreach(L l in r){
          l.SetdN(n+1);
        }
      }
    }
  }
  static void Main(){
    int n=int.Parse(Console.ReadLine());
    L[] s=new L[n];
    for(int i=0;i<n;i++)s[i]=new L();
    for(int i=0;i<n-1;i++){
      var p=Console.ReadLine().Split().Select(int.Parse).ToArray();
      s[p[0]-1].r.Add(s[p[1]-1]);
      s[p[1]-1].r.Add(s[p[0]-1]);
    }
    s[0].Setd1(0);
    s[n-1].SetdN(0);
    long a=s.Count(x=>x.d1<=x.dN);
    Console.WriteLine(a>n-a?"Fennec":"Snuke");
  }
}

Measured memory_bytes: 42648
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1 << 21;
int main() {
	int g, r;
	cin >> r >> g;
	cout << 2 * g - r << endl;
	return 0;
}

Measured memory_bytes: 768
match = [0,2,5,5,4,5,6,3,7,6]
n,m = map(int,input().split())
a = [int(_) for _ in input().split()]
dp = [-1]*(n+10)
dp[0] = 0
for i in range(n+1):
    if dp[i]== -1:
        continue
    else:
        for j in a:
            dp[i+match[j]]= max(dp[i+match[j]],dp[i]*10+j)
print(dp[n])

Measured memory_bytes: 14820
#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and typedef Constants *******/
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.rbegin(), cont.rend()
#define Dcout(a) cout << setprecision(20) << a << endl
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define fi first
#define se second
using Graph = vector<vector<int>>;
const ll INF = (1LL << 60);
const double pi=acos(-1.0);
#define debug cout << "line : " << __LINE__ << " debug" << endl
/****** Template of some basic operations *****/
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; }
/**************************************/
/******** User-defined Function *******/
Graph G;
vector<int> ans;
void dfs(int v, int p=-1){
    //頂点vを根とする部分木にans[v]を加算する
    for(int nv: G[v]){
        if(nv==p) continue;
        ans[nv] += ans[v];
        //加算後にその頂点に対して再びdfs
        dfs(nv,v);
    }
}
/**************************************/
/********** Main()  function **********/
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    //n頂点とクエリの数qを入力
    int n, q; cin >> n >> q;
    G.resize(n);

    //辺を入力
    rep(i, n-1){
        int a, b; cin >> a >> b;
        --a, --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    ans.resize(n);

    //クエリを入力
    rep(i,q){
        int p, x; cin >> p >> x;
        --p;
        ans[p] += x;
    }

    //根から順にdfsする
    dfs(0);

    rep(i,n) cout << ans[i] << endl;

}
/********  Main() Ends Here *************/


Measured memory_bytes: 24204
a = []
b = []
n,m,l = gets.chomp.split(" ").map{|x| x.to_i}
for i in 1..n do
  a[i-1] = gets.chomp.split(" ").map{|x| x.to_i}
end
for j in 1..m do
  b[j-1] = gets.chomp.split(" ").map{|x| x.to_i}
end

for i in 1..n do
  c = [0]*l
  for k in 1..l do
    for j in 1..m do
      c[k-1] += a[i-1][j-1] * b[j-1][k-1]
    end
  end
  printf("%s\n",c.join(" "))
end


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

int main() {
  int h, w;
  std::cin >> h >> w;
  std::vector<std::string> strs;
  for (int i = 0; i < h; ++i) {
    std::string str;
    std::cin >> str;
    strs.push_back(str);
  }
  std::cout << std::string(w + 2, '#') << std::endl;
  for (auto str : strs) {
    std::cout << "#" << str << "#" << std::endl;
  }
  std::cout << std::string(w + 2, '#') << std::endl;
}


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

int main(){
    int h, w;
    std::cin >> h >> w;

    std::vector<std::string> s(1, std::string(w + 2, '_'));
    std::string strBuf;
    for(int i = 0; i < h; ++i){
        std::cin >> strBuf;
        s.push_back("_" + strBuf + "_");
    }
    s.push_back(std::string(w + 2, '_'));

    char counter;
    for(int i = 1; i < h + 1; ++i){
        for(int j = 1; j < w + 1; ++j){
            counter = '0';
            if('.' == s.at(i).at(j)){
                for(int k = -1; k < 2; ++k){
                    for(int l = -1; l < 2; ++l){
                        if('#' == s.at(i + k).at(j + l)){
                            ++counter;
                        }
                    }
                }
                s.at(i).at(j) = counter;
            }
        }
    }
    
    for(int i = 1; i < h + 1; ++i){
        for(int j = 1; j < w + 1; ++j){
            std::cout << s.at(i).at(j);
        }
        std::cout << std::endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

void DFS(int R, vector< vector<int> > & G, auto & par, auto & cnt, auto & sum_dep, auto & sum_min, string & S) {
	if(S[R] == '1') cnt[R] = 1;
	ALL_THE(G[R], it) if(par[*it] == -1) {
		par[*it] = R;
		DFS(*it, G, par, cnt, sum_dep, sum_min, S);
		cnt[R] += cnt[*it];
		sum_dep[R] += sum_dep[*it] + cnt[*it];
	}
	sum_min[R] = 0;
	ALL_THE(G[R], it) if(par[*it] == R) {
		int d = sum_dep[R]-sum_dep[*it]-cnt[*it];
		if(sum_min[*it]+cnt[*it] <= d) sum_min[R] = max(sum_min[R], sum_dep[R]&1);
		sum_min[R] = max(sum_min[R], sum_min[*it]+cnt[*it]-d);
	}
}

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N;
	string S;
	cin >> N >> S;
	vector< vector<int> > G(N);
	for(int i = 0; i < N-1; i++) {
		int u, v;
		cin >> u >> v;
		G[--u].push_back(--v);
		G[v].push_back(u);
	}
	int ans = OVER9000;
	for(int i = 0; i < N; i++) {
		vector<int> par(N, -1), sum_dep(N, 0), sum_min(N), cnt(N, 0);
		par[i] = i;
		DFS(i, G, par, cnt, sum_dep, sum_min, S);
		if(sum_min[i] == 0) ans = min(ans, sum_dep[i]/2);
	}
	if(ans == OVER9000) cout << "-1\n";
	else cout << ans << "\n";
	return 0;
}

// look at my code
// my code is amazing


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


int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	long long asum = 0;
	rep(i, n) {
		cin >> a[i];
		asum += a[i];
	}
	int idx = 0;
	long long isum = 0;
	while (isum < asum / 2) {
		isum += a[idx];
		idx++;
	}
	long long l1 = 2 * isum - asum;
	long long l2 = asum - 2 * (isum - a[idx - 1]);
	if (l1 < l2) cout << l1 << endl;
	else cout << l2 << endl;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main() 
{
	int a, b, c, d, e, f, g, h, A, B;
	cin >> a >> b >> c >> d;
	cin >> e >> f >> g >> h;
	A = a + b + c + d;
	B = e + f + g + h;
	if (A >= B) {
		cout << A << endl;
	}
	else
		cout << B << endl;
	return 0;
}


Measured memory_bytes: 3056
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;

	ll n;
	cin >> n;
	if(n & 1) cout << 0 << endl;
	else {
		n /= 2;
		ll cnt = 0;
		ll p = 5;
		while(p <= n) {
			cnt += n / p;
			p *= 5;
		}
		cout << cnt << endl;
	}	
	
}





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

int main(){
	int N, M, i, j;
	scanf("%d", &N);
	vector<string> s(N);
	for(i = 0; i < N; i++){
		cin >> s[i];
	}
	scanf("%d", &M);
	vector<string> t(M);
	for(i = 0; i < M; i++){
		cin >> t[i];
	}
	int ans = 0;
	for(i = 0; i < N; i++){
		int now = 0;
		for(j = 0; j < N; j++){
			if(s[i] == s[j]){
				now++;
			}
		}
		for(j = 0; j < M; j++){
			if(s[i] == t[j]){
				now--;
			}
		}
		ans = max(ans, now);
	}
	printf("%d\n", ans);
	return 0;
}

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

#define rep(i,n) for(long long i=0; i<n ; ++i)
#define REP(i,a,b) for(long long i=a; i<b; ++i)
#define all(v) (v).begin() , (v).end()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvc = vector<vector<char>>;
using pii = pair<int , int>;
using pll = pair<long long , long long>;

//プロトタイプ宣言
void faster(void);
template <class T>
T gcd(T , T);
template <class T>
T get_digent(T);
template <class T>
T POW(T , T);


int main(){
  faster();
  int n;
  cin >> n;
  vi a(n);
  rep(i,n) cin >> a[i];
  rep(i,n){
    if(a[i]%2==0){
      if(a[i]%3!=0 && a[i]%5!=0){
        cout << "DENIED";
        return 0;
      }
    }
  }
  cout << "APPROVED";
}



























//同期解除
void faster(void){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

//ユークリッドの互除法
template <class T>
T gcd(T a, T b) {
  return (b ? gcd(b, a%b) : a);
} 

//桁数取得
template <class T>
T get_digent(auto x){
  string s;
  s = to_string(x);
  ll digent = s.size();
  return digent;
} 

//べき乗計算
template <class T>
T POW(T x, T y){
  if(y==0) return 1;
  if(y%2 == 1){
    ll temp = POW(x,y-1);
    return (temp*x);
  }
  else{
    ll temp = POW(x,y/2);
    return temp*temp;
  }
} 



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

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef unsigned long long ull;

#define faster ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define debug(x) cout<<#x<<" = "<<(x)<< endl
#define nl "\n"
#define sp " "

const int MOD = 1e9 + 7, SZ = 3e6 + 5;
int fact[SZ], N;
string s;

ll powmodk(ll a, ll k, ll m) {
    if (k == 0) return 1;
    ll r = powmodk(a, k / 2, m);
    r = (r * r) % m;
    if (k % 2) r = (r * a) % m;
    return r;
}

inline ll fix(ll x){
	return (x % MOD + MOD) % MOD;
}

inline ll modinverse(ll a) {
    return powmodk(fix(a), MOD - 2, MOD);
}

ll nck(int n, int k){
	ll num = fact[n];
	ll den = modinverse(1LL * fact[n - k] * fact[k]);
	return fix(num * den);
}

int main() {
	faster
	fact[0] = 1;
	for(int i = 1; i < SZ; i++){
		fact[i] = fix(1LL * i * fact[i - 1]);
	}

	cin >> N >> s;
	N += int(s.length());
	ll ans = powmodk(26,N,MOD);

	for(int i = 0; i < int(s.size()); i++){
		ll pow = powmodk(25, N - i, MOD);
		ans -= fix(nck(N,i) * pow);
	}

	cout << fix(ans) << nl;
}


Measured memory_bytes: 15932
#ABC169b

n = int(input())
a = list(map(int, input().split()))

sum = 1

if 0 in a:
    sum = 0
else:
    for i in range(n):
        sum = sum * a[i]
        if sum > 10**18:
            break

if sum > 10**18:
    print(-1)
else:
    print(sum)


Measured memory_bytes: 21660
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"
struct button {
	int l, u, r, d;
	string to;
};
struct page {
	string name;
	vector<button>bs;
};

int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		int W, H; cin >> W >> H;
		map<string, page>pagemp;
		string start;
		for (int i = 0; i < N; ++i) {
			string name; cin >> name;
			if (!i)start = name;
			page apage;
			apage.name = name;
			int b; cin >> b;
			for (int j = 0; j < b; ++j) {
				int l, u, r, d; string to; cin >> l >> u >> r >> d>>to;
				apage.bs.push_back(button{ l,u,r,d,to });
			}
			pagemp[apage.name] = apage;
		}
		int Q; cin >> Q;
		vector<string>memorys(1,start);
		int now = 0;
		while (Q--) {
			string st; cin >> st;
			if (st == "show") {
				cout << memorys[now] << endl;
			}
			else if (st == "back") {
				if (now)now--;
			}
			else if (st == "forward") {
				if (now != memorys.size() - 1)now++;
			}
			else {
				assert(st == "click");
				{
					int x, y; cin >> x >> y;
					for (auto b : pagemp[memorys[now]].bs) {
						if (b.l <= x&&x <= b.r&&b.u <= y&&y <= b.d) {
							memorys.erase(memorys.begin() + now+1, memorys.end());
							memorys.push_back(b.to);
							now++;
							break;
						}
					}
				}
			}
		}
	}
	return 0;
}

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

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


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n); i++) 
#define dunk(n) cout << n << endl
#define all(a) (a).begin(),(a).end()
typedef pair<int,int> P;
typedef long long ll;

int main() {
    int a,b;
    cin >> a >> b;
    if(b > a){
        swap(a,b);
    }
    rep(i,a){
        cout << b;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3592
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace paiza2
{
    class Program
    {
        static void Main(string[] args)
        {
            var read = Console.ReadLine();
            var split = read.Split(' ');
            int N = Int32.Parse(split[0]);
            int L = Int32.Parse(split[1]);
            string[] S = new string[N];
            for (int c = 0; c < N; c++)
            {
                read = Console.ReadLine();
                S[c] = read;
            }
            StringComparer cmp = StringComparer.Ordinal;
            Array.Sort(S, cmp);
            string output = "";
            for (int c = 0; c < N; c++)
            {
                output += S[c];
            }
            Console.WriteLine(output);
        }
    }
}


Measured memory_bytes: 11488
#include<cstdio>
#include<cstring>
#include<iostream>
#define in inline
#define re register
using namespace std;
in int read() {
	re int t=0;
	re char v=getchar();	
	while(v<'0'||v>'9'){
	v=getchar();
	}	
	while(v>='0'&&v<='9'){		
	t=(t<<3)+(t<<1)+(v^48);		
	v=getchar();	}
	return t;
}
double a,b,c,d;
int main(){
a=read();
for(double i=1;i<=a;++i){
	if(i*1.08>=a&&i*1.08<a+1){
		cout<<i<<endl;return 0;
	}
}
puts(":(");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long int
 

 ll arr[100000];

int main()
{
 	std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  	//ll tt;	cin>>tt;	while(tt--)
  	{
  		ll n,i,a,x,ans;
  		cin>>n;

  		for(i=1;i<=n;i++)
  		{
  			a=i%10;
  			x=i;
  			while(x>=10)	x/=10;
  			arr[x*10+a]++;
  			//cout<<x*10+a<<endl;
  		}

  		ans=0;
  		for(i=1;i<=n;i++)
  		{
  			a=i%10;
  			x=i;
  			while(x>=10)	x/=10;

  			ans+=arr[a*10+x];
  		}

  		//for(i=0;i<100;i++)	cout<<arr[i]<<' ';cout<<endl;
  		cout<<ans;

  	}
 	cerr<<" Execution : "<<(1.0*clock())/CLOCKS_PER_SEC<<"s \n";
    return 0;
  		
}

Measured memory_bytes: 256
//Never stop trying
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef string str;
typedef long long ll;
#define int ll
typedef double db;
typedef long double ld;

typedef pair<int,int> pi;
#define fi first
#define se second

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;

#define pb push_back
#define eb emplace_back
#define pf push_front

#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"

const int MOD = 1e9+7; //998244353
const ll INF = 1e18;
const int nx[4]={0,0,1,-1}, ny[4]={1,-1,0,0}; //right left down up

void IO(){
#ifndef ONLINE_JUDGE 
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout); 
#endif 
}

const int MX=1006;
int R,C,X,Y,X2,Y2;
char g[MX][MX]; 

bool grid(int x, int y){
	return x>=0 && y>=0 && x<R && y<C;
}

int32_t main(){
   boost;
   IO();
	
	cin>>R>>C>>X>>Y>>X2>>Y2; X--; Y--; X2--; Y2--;
	for(int i=0; i<R; i++) for(int j=0;j<C;j++) cin>>g[i][j];

	int dist[R][C]; for(int i=0; i<R; i++) for(int j=0;j<C;j++)dist[i][j]=INF;
	priority_queue<pair<int,pi>,vector<pair<int,pi>>,greater<pair<int,pi>>> q;
	dist[X][Y]=0;
	q.push({0,{X,Y}});

	while(!q.empty()){
		int x=q.top().se.fi,y=q.top().se.se,d=q.top().fi; 
		q.pop();
		if(d>dist[x][y]) continue;

		for(int m=0; m<4; m++){
			int nwx=x+nx[m],nwy=y+ny[m];
			if(grid(nwx,nwy) && g[nwx][nwy]!='#' && dist[nwx][nwy]>dist[x][y]){
				dist[nwx][nwy]=dist[x][y];
				q.push({dist[nwx][nwy],{nwx,nwy}});
			}
		}

		for(int i=x-2; i<=x+2; i++) for(int j=y-2; j<=y+2; j++)if(grid(i,j) && g[i][j]!='#' && dist[i][j]>dist[x][y]+1){
			dist[i][j]=dist[x][y]+1;
			q.push({dist[i][j],{i,j}});
		}
	}
	if(dist[X2][Y2]==INF) cout << -1 << endl;
	else cout << dist[X2][Y2] << endl;	

   return 0;
}



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

#define  int        long long int
 #define    sp(x)                 setprecision(x)
#define    bp(x)           __builtin_popcount(x)
 #define  ld         long double
 #define  f(i,j,n)            for(int i = j; i <= n; i++)
#define  r(i,n,j)       for(int i = n; i >= j; i--)
 #define  all(container)       container.begin() , container.end()
#define  sz(container)   (int)container.size()
 #define  ff             first
#define  ss             second
 #define  pii      pair <int , int>
#define  sp(x)       setprecision(x)
 #define  endl    "\n"
#define  mod  1000000007
 #define  pb    push_back
#define  mp    make_pair
 #define  T     int ttt; cin >> ttt; while(ttt--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);

int power(int x, int y, int p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0; 
    while (y > 0)  
    {     
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res; 
}

int32_t main()
{
    fast
    int n,x=1000,y=0;
    cin>>n;
    int a[n+2];
    f(i,1,n)    cin>>a[i];
    a[n+1]=-1;
    f(i,1,n)
    {
        if(a[i]<a[i+1])
        {
            int z=x/a[i];
            x-= z*a[i];
            y+=z;
        }
        else
        {
            x+= y*a[i];
            y=0;
        }
    }
    cout<<x;
}

Measured memory_bytes: 3644
using System;
public class Hello{
    public static void Main(){
        // Your code here!
        
        int result=0;
        
        
        var line=System.Console.ReadLine().Split();
        var data=Array.ConvertAll(line,int.Parse);
        
        for(var i=0;i<data[0];i++)
        {
             var targetData=System.Console.ReadLine().Split();
             var target=Array.ConvertAll(targetData,double.Parse);
             
             double a=target[0]*target[0];
             double b=target[1]*target[1];
             
             double answer=a+b;
             
             double answer2 = Math.Sqrt(answer);
             //System.Console.WriteLine(answer2);
             
             if(answer2<=data[1])
             {
                 result=result+1;
             }
             
        }
        
        
        System.Console.WriteLine(result);

        
    
    }
}


Measured memory_bytes: 40572
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>
#include <set>
#include <map>

using namespace std;

typedef long long ll;

int main()
{
  ll n, p;
  cin >> n >> p;
  string s;
  cin >> s;
  if (p == 2 || p == 5) {
    ll result = 0;
    ll cur = 0;
    for (char c : s) {
      cur++;
      ll x = c - '0';
      if (x % p == 0) result += cur;
    }
    cout << result << endl;
    return 0;
  }

  reverse(s.begin(), s.end());
  vector<ll> a = {0};
  ll d = 1;
  for (char c : s) {
    ll x = c - '0';
    a.push_back(x * d % p);
    d = d * 10 % p;
  }

  for (ll i = 0; i < a.size() - 1; ++i) {
    a[i + 1] += a[i];
    a[i + 1] %= p;
  }

  vector<ll> count(p);
  ll result = 0;
  for (ll x : a) {
    result += count[x];
    count[x]++;
  }

  cout << result << endl;

  return 0;
}


Measured memory_bytes: 2680
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}

int judge(int n) {
    if(n < 400) {
        return 0;
    } else if(n < 800) {
        return 1;
    } else if(n < 1200) {
        return 2;
    } else if(n < 1600) {
        return 3;
    } else if(n < 2000) {
        return 4;
    } else if(n < 2400) {
        return 5;
    } else if(n < 2800) {
        return 6;
    } else if(n < 3200) {
        return 7;
    } else return 8;
}

signed main() {
    int N;
    cin >> N;
    vi cnts(9, 0);

    rep(i, N) {
        int a;
        cin >> a;
        cnts[judge(a)]++;
    }

    int res = 0;
    rep(i, 8) {
        if(cnts[i]) res++;
    }

    cout << max(res, 1) << " " << res+cnts[8] << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
void xorSwap(int *x, int *y)
{
	*x ^= *y;
	*y ^= *x;
	*x ^= *y;
}

int main(void)
{
	int n, m, a[100001], i, j;
	int *itr;
	unsigned long long ans = 0;
	scanf("%d %d", &n, &m);
	for(j = i = 1; i <= n; j = ++i) {
		scanf("%d", a + i);
		// printf("%d%c", j, n - i ? ' ' : '\n');
		while(j ^ 1 && a[j] > a[j >> 1]) {
			xorSwap(a + j, a + (j >> 1));
			j >>= 1;
		}
	}
	// int k;for(k = 1; k <= n; k++) printf("%d%c", a[k], n - k ? ' ' : '\n');
	for(i = 0; i < m; i++) {
		a[1] >>= 1;
		j = 1;
		while(j << 1 <= n) {
			if(j << 1 == n) {
				if(a[j] < a[j << 1]) xorSwap(a + j, a + n);
				j <<= 1;
			} else {
				if(a[j] < a[j << 1] && a[(j << 1) + 1] <= a[j << 1]) {
					xorSwap(a + j, a + (j << 1));
					j <<= 1;
				} else if(a[j] < a[(j << 1) + 1]) {
					xorSwap(a + j, a + (j << 1) + 1);
					j = (j << 1) + 1;
				} else {
					break;
				}
			}
		}
		// int k;for(k = 1; k <= n; k++) printf("%d%c", a[k], n - k ? ' ' : '\n');
	}
	for(itr = a + 1; itr <= a + n; itr++) ans += (unsigned long long)*itr;
	printf("%llu\n", ans);
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define endl '\n'

using namespace std;

main()
{
  fast;
  ll n,k1,k2,k3;
  cin>>n;
  ll ans=(n*(n+1))/2;
  k1=n/3;
  k2=n/5;
  k3=n/15;
  ans-=(3*k1*(k1+1))/2;
  ans-=(5*k2*(k2+1))/2;
  ans+=(15*k3*(k3+1))/2;
  cout<<ans<<endl;
}

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

static const int INF=1e9;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    string s; cin >> s;
    int ans=0;
    for(int i=0;i<s.size()/2;i++){
        if(s[i]!=s[s.size()-1-i]) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
n,m = map(int,input().split())
ss = [1]*n
for i in range(0,m):
    ss[int(input())-1] = 0
if n == 0:
    print(0)
elif n == 1:
    print(1)
elif n == 2:
    if ss[0] == 0:
        print(1)
    else:
        print(2)
else:
    if ss[n-3] != 0:
        ss[n-3] = ss[n-2]+ ss[n-1]
    for i in range(n-4,-1,-1):
        if ss[i] == 0:
            continue
        ss[i] = ss[i+1] + ss[i+2]
    print((ss[0]+ss[1])%(10**9+7))

Measured memory_bytes: 460020
#include<stdio.h>
#include<stdlib.h>
 
#define SIZE 250
 
int main(){
  int i,m;
  int b[SIZE];
 
  scanf("%d",&m);
 
  for(i = 1; i <= m; i++){
    scanf("%d",&b[i]);
  }
 
  for(i = 1; i <= m; i++){
    printf("node %d: key = %d,",i ,b[i]);
    if(i != 1){
      printf(" parent key = %d,",b[i/2]);
    }
   
   
 if(2*i <= m){
      printf(" left key = %d,",b[2*i]);
    }
 if(2*i+1 <= m){
      printf(" right key = %d,",b[2*i+1]);
    }
    printf(" \n");
  }
  return 0;
}

Measured memory_bytes: 608
import java.util.Scanner;

public class Main {


	
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		int n	   = Integer.parseInt(sc.next());
		double answer = Math.pow(n, 3);
		System.out.println((int)answer);

		sc.close();
	}

}



Measured memory_bytes: 26044
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
    #define debug(...) printf(__VA_ARGS__)
#else
    #define debug(...) (void)0
#endif
#define mp make_pair
#define pb push_back
#define LL long long
#define pii pair<int,int>
#define PII pair<long long, long long>
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
const int inf = 0x7fffffff; //beware overflow
const LL INF = 0x7fffffffffffffff; //beware overflow
#define mem(x, y) memset(x, (y), sizeof(x) );
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
template<typename A, typename B>
ostream& operator <<(ostream &s, const pair<A,B> &p) {
     return s<<"("<<p.first<<","<<p.second<<")";
}
template<typename T>
ostream& operator <<(ostream &s, const vector<T> &c) {
    s << "[ ";
    for (auto it : c) s << it << " ";
    s << "]";
    return s;
}
template<typename T>
ostream& operator << (ostream &o, const set<T> &st) {
    o << "{";
    for (auto it=st.begin(); it!=st.end(); it++) o << (it==st.begin() ? "" : ", ") << *it;
    return o << "}";
}
template<typename T1, typename T2>
ostream& operator << (ostream &o, const map<T1, T2> &mp) {
    o << "{";
    for (auto it=mp.begin(); it!=mp.end(); it++) {
        o << (it==mp.begin()?"":", ") << it->fi << ":" << it->se;
    }
    o << "}";
    return o;
}
inline LL getint(){
   LL _x=0,_tmp=1; char _tc=getchar();
   while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
   if( _tc == '-' ) _tc=getchar() , _tmp = -1;
   while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
   return _x*_tmp;
}
#define maxn
    char tab[10][10];
    const int dx[] = {1, 0};
    const int dy[] = {0, 1};
    int go=0;
    int h, w;
void dfs(int r, int c) {
    go++;
    for(int i=0;i<2;i++) {
        int nx = r+dx[i], ny = c+dy[i];
        if( nx < h && ny < w ) {
            dfs(nx, ny);
            return ;
        }
    }
}
int main() {
    cin>>h>>w;
    int cnt = 0;
    for(int i=0;i<h;i++) {
        scanf("%s", tab[i]);
        cnt += count(tab[i], tab[i]+w, '#');
    }
    dfs(0, 0);
    puts(go==cnt?"Possible":"Impossible");
}



Measured memory_bytes: 764
N = int(input())
B = list(map(int, input().split()))
A = []
for i in range(N):
  if i == 0:
    A.append(B[0])
  elif i == N-1:
    A.append(B[N-2])
  else:
    A.append(min(B[i], B[i-1]))
print(sum(A))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;  

 for(int a = 1; a <= 9;a++)for(int b = 1;b <= 9;b++){
        if(a * b == N){
      cout << "Yes" << endl;
      return 0;
        }   
}
     cout << "No" << endl;  
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	string s;
	cin >> s;
	const int n = s.size();
	bool accept = (n % 2 == 0);
	for(int i = 0; i < n; ++i){
		if(s[i] != (i % 2 == 0 ? 'h' : 'i')){
			accept = false;
		}
	}
	cout << (accept ? "Yes" : "No") << endl;
	return 0;
}



Measured memory_bytes: 768
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cmath>
#include <climits>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
#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 all(v) v.begin(),v.end()

int main() {
    int n,k;
    cin >> n >> k;
    vector<bool> sunuke(n,false);
    rep(i,k) {
        int d;
        cin >> d;
        rep(j,d) {
            int a;
            cin >> a;
            sunuke[a-1] = true;
        }
    }
    int ans = 0;
    rep(i,n) {
        if (!sunuke[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int X, A, B;
    cin >> X >> A >> B;

    if(X-(B-A)<0) cout << "dangerous" << endl;
    else if(A-B<0) cout << "safe" << endl;
    else cout << "delicious" << endl; 
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
const ll mod = 1e9+7;
 
int main(){
    int n,m;
    cin>>n>>m;
    vector<int> a(n+1,true);
    vector<ll> dp(n+1);
    rep(i,m){
        int q;
        cin>>q;
        a[q]=false;
    }
    //////
    dp[0]=1;
    for(int i=0;i<n;++i){
        for(int j=i+1;j<=min(n,i+2);++j){
            if(a[j]){
                dp[j]+=dp[i];
                dp[j]%=mod;
            }
        }
    }
        cout<<dp[n]<<endl;
}

Measured memory_bytes: 1408
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e2 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b == c || a + c == b || b + c == a) puts("Yes");
	else puts("No");
	return 0;
}

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

using namespace std;

int main()
{
	int n,m,add=0,temp;
	int a[1000];
	bool judge = false;

	start:

	scanf("%d %d", &n,&m);

	if (n == 0 && m==0 ) {
		goto finish;
	}

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

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

	for (int i = 0; i < n - 1; i++) {
		//if (judge == true) break;
		for (int j = n-1; j != i; j--) {
			if (m < a[i] + a[j]) {
				break;
			}
			else {
				if(add<a[i]+a[j]) add = a[i] + a[j];
				//judge = true;
			}
		}
	}
	if (add == 0) {
		cout << "NONE" << endl;
	}
	else {
		cout << add << endl;
	}

	n = 0;
	m = 0;
	add = 0;
	judge = false;

	goto start;

	finish:

	return 0;
}


Measured memory_bytes: 3236
import numpy as np
def gcd(a, b):
    if a % b:
        return gcd(b, (a % b))
    else:
        return b
N = int(input())
A = list(map(int,input().split()))
A_gcd = A[0]
for a in A:
    A_gcd = gcd(a,A_gcd)
print(A_gcd)


Measured memory_bytes: 23112
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<utility>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<map>
#include<string>
#include<cctype>
#include<cmath>
#include<cassert>
#include<deque>
using namespace std;
int main()
{
	string a[3];
	for(int i=0;i<3;i++)
	{
		cin >> a[i];
	}
	cout << a[0][0] << a[1][1] << a[2][2];
	return 0;
}

Measured memory_bytes: 256
/*
ex3_3
tomatokan
*/
#include<stdio.h>

int main(void){
    int n,k,i,l;
    scanf("%d",&n);
    scanf("%d",&k);
    i=1;
    l=k;/*l=k^i*/
    while(n>=l){/*n>=l ならn>=k^i*/
        i++;
        l=l*k;
    }
    printf("%d\n",i);
    return 0;
}

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

int n,x,y,nd[2000],d;

int main(){
    cin>>n>>x>>y;
    for(int i=1;i<n;i++){
        for(int j=i+1;j<=n;j++){
            d=j-i;
            d=min(d,abs(x-i)+abs(y-j)+1);
            nd[d]++;
            //for(int k=1;k<n;k++)cout<<nd[k];
            //cout<<i<<j<<d<<abs(x-i)+abs(y-j)+1<<endl;
        }
    }
    for(int i=1;i<n;i++){
        cout<<nd[i]<<endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;


int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);
    ll sum=0;
    int i;
    map<ll,int> cnt;
    cnt[0]++;
    for(i=0; i<n; i++) {
        int tmp;
        scanf("%d", &tmp);
        sum+=tmp;
        cnt[sum]++;
    }

    ll ans=0;
    auto it=cnt.begin();
    for(; it!=cnt.end(); ++it) {
        ll tmp=it->second;
        ans += tmp*(tmp-1)/2;
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 12672
# from sys import stdin

# # 解説のコード
# def get_result(data):
#     N, X, Y = data
#     dist_cnt = [0 for i in range(N)]
#     for i in range(1, N+1):
#         for j in range(i+1, N+1):
#             min_dist = min([j-i, abs(X-i) + 1 + abs(Y-j), abs(Y-i) + 1 + abs(X-j)])
#             dist_cnt[min_dist] += 1
#     for i in range(1, N):
#         print(dist_cnt[i])


# if __name__ == '__main__':
#     data = list(map(int, stdin.readline().rstrip('\n').split(' ')))
#     get_result(data)

from sys import stdin
from heapq import heappush, heappop


class Dijkstra:
    def __init__(self, num_nodes):
        self.n = num_nodes
        self.adj_list = [[] for _ in range(self.n)]

    # Edge数分回すことを想定
    def add_edge(self, start, end, weight=1, undirected=True):
        self.adj_list[start].append((end, weight))
        if undirected:
            self.adj_list[end].append((start, weight))

    def distance(self, start):
        # 始点から各頂点までの最短距離を格納する
        self.dist = [float('inf') for _ in range(self.n)]
        # 最短経路における, その頂点の前の頂点のIDを格納する
        self.prev = [-1 for _ in range(self.n)]
        self.dist[start] = 0
        # 各要素は，(頂点vのID, startからある頂点vまでの仮の距離)からなるタプル
        q = []
        heappush(q, (start, 0))
        while len(q) != 0:
            src, prov_cost  = heappop(q)
            # プライオリティキューに格納されている最短距離が, 現在計算できている最短距離より大きければ，distの更新をする必要はない
            if self.dist[src] < prov_cost:
                continue
            # 他の頂点の探索
            for val in self.adj_list[src]:
                dest, cost = val
                if self.dist[dest] > self.dist[src] + cost:
                    self.dist[dest] = self.dist[src] + cost # distの更新
                    heappush(q, (dest, self.dist[dest])) # キューに新たな仮の距離の情報をpush
                    self.prev[dest] = src
        return self.dist


# BFS pypyでAC
def get_result(data):
    N, X, Y = data
    _data = [[i, i+1] for i in range(1, N)]
    _data += [[X, Y]]
    solver = Dijkstra(N)
    for val in _data:
        solver.add_edge(val[0]-1, val[1]-1, undirected=True)
    dist_cnt = [0 for i in range(N)]
    for i in range(N):
        dist = solver.distance(i)
        for j in range(i, N):
            dist_cnt[dist[j]] += 1
    for i in range(1, N):
        print(dist_cnt[i])


if __name__ == '__main__':
    data = list(map(int, stdin.readline().rstrip('\n').split(' ')))
    get_result(data)


Measured memory_bytes: 119772
#include<stdio.h>
#include<stdlib.h>
 
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL
 
Node root;
 
Node treeMinimum(Node x){
  while(x->left!=NIL)
    x =x->left;
    return x;
}
 
Node treeMaximum(Node x){
  while(x->right != NIL)
    x = x->right;
    return x;
}
 
Node treeSearch(Node u, int k){
  while(u!=NIL && k!=u->key){
 
  if(k < u->key) u=u->left;
 
  else u=u->right;
  }
  return u;
   
}
 
Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL) return treeMinimum(x->right);
  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
 
}
 
void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left==NIL || z->right==NIL) y = z;
  else y = treeSuccessor(z);
 
  if(y->left != NIL) x=y->left;
  else x = y->right;
 
  if(x!=NIL) x->parent = y->parent;
  if(y->parent==NIL) root = x;
  else if(y == y->parent->left) y->parent->left = x;
  else y->parent->right =x;
   
  if(y!= z) z->key = y->key;
  free(y);
}
 
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
 
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
 
  while(x!=NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;
  if(y==NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}
 
void inorder(Node u){
  if(u == NIL)return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
   
}
void preorder(Node u){
  if(u ==NIL)return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
   
}
 
 
int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
 
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }
 
  return 0;
}



Measured memory_bytes: 20504
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

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<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;

int modpow(ll x, ll y) {
	ll r = 1, a = x % MOD;
	while (y > 0) {
		if ((y & 1) == 1) r = (r*a) % MOD;
		a = (a*a) % MOD;
		y /= 2;
	}
	return r;
}
int T, n, m;

int main(int argc, char *argv[]){
	ios::sync_with_stdio(false);
	cin >> n >> m;
	vi a(n), b(n);
	REP(i, n) cin >> a[i];
	REP(i, n) cin >> b[i];
	vector<ll> dp(m + 1);
	dp[0] = 1;

	vector<vector<ll>> powt(401, vector<ll>(m + 1, 1));

	REP(x, 401)REPS(j, m) {
		powt[x][j] = powt[x][j - 1] * x % MOD;
	}

	vector<vector<ll>> sum(n, vector<ll>(m + 1));
	REP(i, n)REP(j, m + 1) {
		for (int x = a[i]; x <= b[i]; x++) {
			sum[i][j] += powt[x][j];
		}
		sum[i][j] %= MOD;
	}
	REP(i, n) {
		vector<ll> nxt(m + 1);
		REP(j, m+1)REP(k, j+1) { // k <= j
			nxt[j] = (nxt[j] + dp[k] * sum[i][j - k]) % MOD;
		}
		swap(dp, nxt);
	}
	cout << dp[m] << endl;
	return 0;
}


Measured memory_bytes: 2944
import java.util.Scanner;

public class Main {

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

		int[] ti = new int[N+1];
		int[] xi = new int[N+1];
		int[] yi = new int[N+1];
		ti[0] = xi[0] = yi[0] = 0;
		for (int i=1; i<N+1; i++) {
			ti[i] = sc.nextInt();
			xi[i] = sc.nextInt();
			yi[i] = sc.nextInt();
		}

		String can = "Yes";
		for (int i=0; i<N; i++) {
			int dt = ti[i+1] - ti[i];
			int dist = Math.abs(xi[i+1] - xi[i]) + Math.abs(yi[i+1] - yi[i]);
			//System.out.println("debug dt=" + dt + ", dist=" + dist);
			if (dt < dist) {
				can = "No";
				break;
			}
			if ((dt % 2) != (dist % 2)) {
				can = "No";
				break;
			}
		}
		System.out.println(can);

	}

}


Measured memory_bytes: 89108
n,t=map(int,input().split())
ct=[list(map(int,input().split())) for i in range(n)]
ans=float('inf')
ok=False
for i in range(n):
  if ct[i][1]<=t:
    ans=min(ans,ct[i][0])
    ok=True
if ok:
  print(ans)
else:
  print('TLE')


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

int main() {
	vector<P>v;
	for (int i = 2; i <= 500; i++) {
		for (int j = 1; j < i; j++) {
			v.push_back(P(i*i + j*j, j));
		}
	}
	sort(v.begin(), v.end());
	int h, w;
	while (scanf("%d%d", &h, &w), h) {
		auto p = upper_bound(v.begin(), v.end(), P(h*h + w*w, h));
		int i = p->second;
		printf("%d %d\n", i, (int)sqrt(p->first - i*i));
	}
}

Measured memory_bytes: 3636
MOD = 10**9 + 7

n,a,b = map(int,input().split())

def comb_mod(n,k):
    a,b=1,1
    for i in range(k):
        a = a*(n-i) % MOD
        b = b*(k-i) % MOD
    return a * pow(b,MOD-2,MOD) % MOD

ans = pow(2,n,MOD) -1 - comb_mod(n,a) - comb_mod(n,b) %MOD
ans = (ans + MOD ) % MOD
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mx *max_element
#define mn *min_element
#define fo(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define rfo(i,n) for(ll i=n-1;i>=0;i--)
#define rloop(i,a,b) for(ll i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x))
#define precision cout<<fixed<<setprecision(10)
#define mem(x,p) memset(x,p,sizeof(x))
#define w(t) ll t;cin>>t;while(t--)
#define kk "\n"
#define setbits(x) __builtin_popcountll(x)
const double pi=3.1415926535897932384626;
//const ll mod = 998244353;
const ll mod=1e9+7;
int main()
{
  IOS
  string s,t;
  cin>>s>>t;
  ll n=s.length();
  ll c=0;
  fo(i,n)
  {
    if(s[i]!=t[i])
      c++;
  }
  cout<<c;
  return 0;
}

Measured memory_bytes: 3804