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

typedef pair<int, int> P;

int N;
vector<vector<int>> G;
vector<int> C;
int numOfColors;
map<P, int> colorOfEdges;

void dfs(int u, int c) {
    C[u] = c;
    numOfColors = max(numOfColors, (int)G[u].size());

    int edgeColor = 1;
    for (int v : G[u]) {
        if (C[v] != -1) continue;
        if (edgeColor == c) edgeColor++;
        colorOfEdges[P(u, v)] = edgeColor;
        dfs(v, edgeColor);
        edgeColor++;
    }
}

int main() {
    cin >> N;
    G.resize(N);
    C.resize(N, -1);
    vector<P> E(N - 1);
    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        E[i] = P(a, b);
        G[a].push_back(b);
        G[b].push_back(a);
    }

    dfs(0, 0);

    cout << numOfColors << endl;
    for (int i = 0; i < E.size(); i++) {
        cout << colorOfEdges[E[i]] << endl;
    }

    return 0;
}

Measured memory_bytes: 13440
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define sz(a)       (ll)(a.size())
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,x,n)   for(ll i=x;i<n;i++)
#define frr(i,x,n)  for(ll i=n-1;i>=x;i--)
using namespace std;


const ll N   =  500005;
const ll mod = 1e9 + 7;



void solve(){

  ll x=0,y=0,c=0,ans=0;
  ll n,m,k;
  cin>>n>>m;
  x = n*(n-1)/2 + m*(m-1)/2;
  c(x);
}

signed main(){
     
  ios_base::sync_with_stdio(false);   
  cin.tie(NULL);
  //int T;cin >> T;while (T--)
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    string s1,s2;
    getline(cin, s1);
    getline(cin, s2);
    int n = s1.size(), m = s2.size(),j;
    for (int i = 0; i < n; i++){
        if (s2[0] == s1[i])
        {
            int k = i;
            for (j = 0; j < m; j++){
                 
                if (s2[j] != s1[k])
                    break;
                k++;
                if (k == n)
                    k = 0;
                 
            }
            if (j == m)
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3168
X, K, D = map(int, input().split())
X = abs(X)
point = X % D
q = X // D
ans = 0
if q >= K:
    ans = abs(X-D*K)
elif (K - q) % 2 == 0:
    ans = point
else:
    ans = D-point
print(ans)

Measured memory_bytes: 9092
#include<bits/stdc++.h>
#define re register
#define LL long long
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
inline int read() {
	char c=getchar();int x=0;while(c<'0'||c>'9') c=getchar();
	while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+c-48,c=getchar();return x;
}
int T,n,m;
int bf(int n) {
	if(n<m) return 0;if(n%m==0) return n/m;
	return bf(n-n/m-1);
}
int sg(int n) {
	if(n<m) return 0;if(n%m==0) return n/m;
	int x=n/m;int u=x*m;
	int h=(n-u)/(x+1);
	if(n-h*(x+1)==u) return x;
	return sg(n-(h+1)*(x+1));
}
int main() {
	int ans=0;
	for(re int T=read();T;--T) {
		n=read(),m=read();
		if(m<=n/m) ans^=bf(n);
		else ans^=sg(n);
	}
	if(ans) puts("Takahashi");
	else puts("Aoki");
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))

Clist = []
for count in range(len(A)+1):
    Clist.append(0)

for count in range(len(A)):
    Clist[A[count]-1] = Clist[A[count]-1] + 1

for count in range(0,len(A)+1):
    print(Clist[count])

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

void solve()
{
    string s,t;
    cin>>s>>t;
    s=' '+s;
    t=' '+t;
    int n=s.length(),m=t.length();
    int dp[n][m];
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            if(i==0 || j==0){
                dp[i][j]=0;
                continue;
            }
            if(s[i]==t[j]){
                dp[i][j]=1+dp[i-1][j-1];
            }
            else{
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    int i=n-1,j=m-1;
    string ans="";
    while(i>0 && j>0){
        if(s[i]==t[j]){
            ans=s[i]+ans;
            i--;
            j--;
        }
        else{
            if(dp[i-1][j]>dp[i][j-1]){
                i--;
            }
            else{
                j--;
            }
        }
    }
    cout<<ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t=1;
    while(t--){
        solve();
        cout<<endl;
    }
}


Measured memory_bytes: 38892
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rfor(i, a, b) for(int i = a; i < (int)b; i++)
#define all(ary) (ary).begin(), (ary).end()
#define debug(x) cerr << #x << ": " << x << '\n'
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
using namespace std;
using v = vector<int>;
using ll = long long;
template <class T = int> T in(){ T x; cin >> x; return (x);}

int main(int argc, char *argv[]){
    int w, a, b; cin >> w >> a >> b;
    if(a+w < b) cout << b - a - w << endl;
    else if(b+w < a) cout << a - b - w << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
//164B(Atcoder)
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
      	int K = sc.nextInt();
      	int[] A=new int[N];
      	
      	for(int i=0;i<K;i++){
          int d=sc.nextInt();
        for(int j=0;j<d;j++){
          A[sc.nextInt() - 1] += 1;
        }}
		
      	int count = 0;
        for (int i = 0; i < N; i++) {
          
            if (A[i] == 0) {
                count++;
            
        }
      }
 
        // 出力
        System.out.println(count);
    }
}

Measured memory_bytes: 37568
from collections import Counter
N=int(input())
A=list(map(int,input().split()))

parent=dict()
An=set(A)
parecou=0
aaa=Counter(A)
for i in aaa.values():
    parecou+=int((i*(i-1)/2))
"""
for i in An:
    f=A.count(i)
    parent[i]=f
    parecou+=int((f*(f-1)/2))
"""


#print(parecou)
for i in range(N):
    anko=aaa[A[i]]
    print(parecou-int((anko*(anko-1)/2))+int(((anko-2)*(anko-1)/2)))
    #print(parecou-anko+1)


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

#define ll long long
#define fr first
#define se second
#define pb push_back

using namespace std;

const long long N = 1e5 + 7;

ll res, n, m, cnt, ans , a , b , sum , mx = -1e9 , mn, c , d;
string s;
map<int , int>mp;
int main()
{
    cin >> n >> m;
    while( m -- ){
        cin >> a;
        for( int i = 0; i < a;i ++ ){
            cin >> b , cnt+=!mp[b];
            mp[b] ++;
        }
    }
    cout << n - cnt;
}


Measured memory_bytes: 3632
#define _USE_MATH_DEFINES

#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

int LIS[200010];
int const INF = 1 << 29;

typedef pair<int, int> P;

int main(){
	
	int x1, x2, y1, y2, N;
	bool minus = false;
	cin >> x1 >> y1 >> x2 >> y2;
	if(x1 > x2){
		swap(x1, x2);
		swap(y1, y2);
	}
	if(y1 > y2){
		minus = true;
		y1 = -y1;
		y2 = -y2;
	}
	
	vector<P> v;
	P p;
	p.first = x1;
	p.second = y1;
	v.push_back(p);
	p.first = x2;
	p.second = y2;
	v.push_back(p);
	
	cin >> N;
	
	for(int i = 0; i < N; i++){
		P p;
		cin >> p.first >> p.second;
		if(minus){
			p.second = -p.second;
		}
		v.push_back(p);
	}
	
	N += 2;
	
	sort(v.begin(), v.end());
	
	for(int i = 0; i < N; i++){
		LIS[i] = INF;
	}
	
	bool flag = false;
	
	for(int i = 0; i < N; i++){
		if(v[i].first == x2 && v[i].second == y2){
			break;
		}
		if(flag){
			if(v[i].second < y1){
				continue;
			}
			int* pos = lower_bound(LIS, LIS + N, v[i].second);
			*pos = v[i].second;
		}
		if(v[i].first == x1 && v[i].second == y1){
			flag = true;
		}
	}
	
	long long int num = (int)(upper_bound(LIS, LIS + N, y2) - LIS);
	
	long long int dist = (x2 - x1) + (y2 - y1);
	
	long long int d1 = dist * 100 - num * 20;
	
	if(num == min(x2 - x1, y2 - y1) + 1){
		num++;
	}
	
	num *= 5;
	
	double ans = double(d1) + num * M_PI;
	
	printf("%.15f\n", ans);
	
	return 0;
}



Measured memory_bytes: 2672
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

ll f(ll n, ll k) {
  ll res = 0;
  while(n % k == 0) {
    res++;
    n /= k;
  }
  return res;
}

int main() {
  ll n;
  cin >> n;
  vl a(n);
  rep(i, n) {
    double d;
    cin >> d;
    a[i] = round(d * 1e9);
  }
  vector<vl> v(19, vl(19, 0));
  vl two(n), five(n);
  rep(i, n) {
    two[i] = f(a[i], 2);
    five[i] = f(a[i], 5);
    ll ti = min(18LL, two[i]);
    ll fi = min(18LL, five[i]);
    v[ti][fi]++;
  }

  ll cnt = 0;
  rep(i, n) {
    rep(j, 19) rep(k, 19) if(j >= 18 - two[i] && k >= 18 - five[i]) cnt +=
        v[j][k];
    if(min(two[i], five[i]) >= 9) cnt--;
  }
  cout << cnt / 2 << endl;
}

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

typedef long long int ll;

int main(void) {
    int N;
    cin >> N;

    vector<int> A(N);

    for(int i=1; i<N; i++) {
        int tmp;
        cin >> tmp;
        A[tmp-1]++;
    }

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

Measured memory_bytes: 4048
#include<iostream>
#include<queue>
#include<functional>
#include<algorithm>
#include<vector>
using namespace std;

typedef pair<long long, long long> P;
#define MAX_N 1000
#define INF 1000000000000000LL

vector<P>X[MAX_N];
priority_queue<P, vector<P>, greater<P>>Q;
long long dist[MAX_N];
long long N, M, A, B, C;

int solve(int P) {
	while (!Q.empty()) { Q.pop(); }
	for (int i = 0; i < MAX_N; i++) { dist[i] = INF; }
	dist[P] = 0; Q.push(make_pair(0, P)); int cnt = 0;
	while (!Q.empty()) {
		cnt++;
		if (cnt >= 500000) { return 1; }
		pair<long long,long long> pa = Q.top(); Q.pop();
		long long a1 = pa.first, a2 = pa.second;
		for (int i = 0; i < X[a2].size(); i++) {
			long long to = X[a2][i].first;
			if (dist[to] > a1 + X[a2][i].second) {
				dist[to] = a1 + X[a2][i].second;
				Q.push(make_pair(dist[to], to));
			}
		}
	}
	for (int i = 0; i < N; i++) {
		if (i >= 1) { cout << ' '; }
		if (dist[i] == INF) { cout << "INF"; }
		else { cout << dist[i]; }
	}
	cout << endl;
	return 0;
}

int main() {
	cin >> N >> M;
	for (int i = 0; i < M; i++) { cin >> A >> B >> C; X[A].push_back(make_pair(B, C)); }
	for (int i = 0; i < N; i++) {
		int B = solve(i); if (B == 1) { cout << "NEGATIVE CYCLE" << endl; return 0; }
	}
	return 0;
}

Measured memory_bytes: 35768
#include <iostream>
#include <string>

using namespace std;

#define MIN(a, b)   ((a)>(b) ? (b) : (a))

inline int convert(char c) 
{
    return (c=='0') ? 0 : 1;
}

int main(void)
{
    string S;
    int counter = 0;

    cin >> S;
    
    for(size_t i=0; i<S.size(); i++){
        if((i%2) != convert(S[i]))
            counter++;
    }

    cout << MIN(counter, S.size()-counter);

    return 0;
}

Measured memory_bytes: 512
#include <iostream>

void fastin(int &num) {
    bool neg = false;
    int c;
    num = 0;
    c = getchar_unlocked();
    if (c == '-') {
        neg = true;
        c = getchar_unlocked();
    }
    for (; (c > 47 && c < 58); c = getchar_unlocked()) num = num * 10 + c - 48;
    if (neg) num *= -1;
}

void fastout(int n) {
    int N = n, rev, count = 0;
    rev = N;
    if (N == 0) { putchar_unlocked('0'); putchar_unlocked('\n'); return ;}
    while ((rev % 10) == 0) { ++count; rev /= 10;}
    rev = 0;
    while (N != 0) { rev = (rev<<3) + (rev<<1) + N % 10; N /= 10;}
    while (rev != 0) { putchar_unlocked(rev % 10 + '0'); rev /= 10;}
    while (count--) putchar_unlocked('0');
}

int main(){    
    int n, m, Q; fastin(n); fastin(m); fastin(Q);
    int square[n + 5][n + 5] = {};
    for (int i = 0; i < m; ++i){
      int l, r;
      fastin(l); fastin(r); ++square[l][r];
    }

    for (int i = 1; i <= n; ++i){
        for (int j = 1; j <= n; ++j){
            square[i][j] += square[i][j - 1];
        }
    }

    for (int i = 1; i <= n; ++i){
        for (int j = 1; j <= n; ++j){
            square[i][j] += square[i - 1][j];
        }
    }

    for (int i = 0; i < Q; ++i){
        int p, q; fastin(p); fastin(q);
        fastout(square[q][q] + square[p - 1][p - 1] - square[p - 1][q] - square[q][p - 1]); putchar_unlocked('\n');
    }
    
    return 0;
}

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

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'

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

  int n; cin >> n;
  string s[n]; rep(i, n) cin >> s[i];

  int ans = 0;

  int a = 0, b = 0, ab = 0;

  rep(i, n){

    //int ta = 0, tb = 0;
    for (int j = 0; j < (int) s[i].size() - 1; ++j){
      if (s[i][j] == 'A' && s[i][j + 1] == 'B') ++ans;
    }
    if (s[i][0] == 'B' && s[i].back() == 'A') ++ab;
    else if (s[i][0] == 'B') ++b;
    else if (s[i].back() == 'A') ++a;
  }

  if (ab > 0){
   ans += (ab - 1);
  }

  if (a > 0 && ab > 0){
    ++ans; --a;
  }

  if (b > 0 && ab > 0){
    ++ans; --b;
  }

  if (min(a, b) >= 0) ans += min(a, b);

  print(ans);

  return 0;
}

Measured memory_bytes: 768
#include <iostream>

using namespace std;

int main(void) {

	int n; cin >> n;
	int sw = 0;
	
	int* a = new int[n + 1];

	a[0] = 0;

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

		int num; cin >> num;

		if (num == i) {

			a[i] = 1;

		}
		else {

			a[i] = 0;

		}

	}

	for (int i = 1; i <= n;) {

		if (a[i]) {

			if (a[i + 1]) {

				a[i] = 0;
				a[i + 1] = 0;

				i += 2;

			}
			else {

				a[i] = 0;

				++i;

			}

			++sw;

		}
		else {

			++i;

		}

	}

	cout << sw << endl;

	return 0;

}

Measured memory_bytes: 640
N=int(input())
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))

ablist=[]
for i in range(N):
  ablist.append(alist[i]-blist[i])
  
ablist.sort()
#print(ablist)

if ablist[0] >= 0:
  print("0")
elif sum(ablist) < 0:
  print("-1")
else:
  cnt = 0
  sum_ab = 0
  for ab in ablist:
    if ab<0:
      cnt += 1
      sum_ab += ab
    else:
      break
      
  for ab in reversed(ablist):
    cnt += 1
    sum_ab += ab
    if sum_ab >= 0:
      break
      
  print(cnt)

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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for(ll i = 0 ; i < n; i++)

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    ll A, B, C, K;

    cin >> A >> B >> C >> K;

    ll ans = 0;
    if( K <= A ){
        ans = K;
    }else if( K <= (A+B) ){
        ans = A;
    }else if( K <= (A+B+C) ){
        ans = A - (K - (A+B));
    }

    cout << ans << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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;
}



int main(){
    ll n;
    cin >> n;
    char s[n];
    REP(i,n){
        cin >> s[i];
    }
    ll ans = 0;
    char ctp = ' ';
    REP(i,n){
        if(ctp != s[i]){
            ans += 1;
        }
        ctp = s[i];
    }
    cout << ans << endl;
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(int, a, b);
  rep(i, 3) if (a * (i + 1) * b % 2 == 1) {
    out("Yes");
    return 0;
  }
  out("No");
}


Measured memory_bytes: 3648
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	int a, b, c;
	cin >> a>>b>>c;
	b = b / a;
	if (b >= c)
		cout << c << endl;
	else
		cout << b << endl;
}

Measured memory_bytes: 3616
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int n;
int a[202020];
map<int, int> num;
bool calc(int mid){
    num.erase(ALL(num));
    for(int i = 1;i < n; i++){
        if(a[i - 1] >= a[i]){
            if(num.empty()){
                num[a[i]] = 1;
            }else{
                auto it =num.upper_bound(a[i]);
                num.erase(it, num.end());
                num[a[i]]++;
                int d = a[i];
                while(num[d] == mid){
                    if(d == 1)return false;
                    num.erase(d);
                    d--;
                    num[d]++;
                }
            }
        }
    }
    return true;
}

int lis(vector<LL> &v) {
	vector<LL> ans(v.size(), HINF<LL>());
	for (int i = 0; i < v.size();i++) {
		(*lower_bound(ans.begin(), ans.end(), v[i])) = v[i];
	}
	return lower_bound(ans.begin(), ans.end(), HINF<LL>()) - ans.begin();
}

vector<LL> v;

int main(){
    INIT;
    cin >> n;
    REP(i ,n){
        cin >> a[i];
        v.emplace_back(a[i]);
    }
    if(lis(v) == n){
        cout << 1 << endl;
        return 0;
    }
    int ng = 1, ok = n + 1;
    while(ok - ng > 1){
        int mid = (ok + ng)/2;
        if(calc(mid)){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    cout << ok  << endl;
}

Measured memory_bytes: 4336
n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(k):
    acc = [0 for j in range(n+1)]
    for j in range(n):
        acc[max(0, j - a[j])] += 1
        acc[min(n-1, j + a[j]) + 1] -= 1
    for j in range(n):
        acc[j+1] += acc[j]
    a = acc[:-1]
    if sum(a) == n * n:

        break
print(" ".join(map(str, a)))


Measured memory_bytes: 226576
#include<bits/stdc++.h>
using namespace std;
int main() 
{
    int n;
    cin>>n;
    int temp=n%10;
    if(temp==2||temp==4||temp==5||temp==7||temp==9)
    {
        cout<<"hon";
    }
    else if(temp==3)
    {
        cout<<"bon";
    }
    else
    {
        cout<<"pon";
    }

return 0;
}


Measured memory_bytes: 3636
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <ios>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;

int main()
{
    int N;
    cin >> N;
    int sum = 0;
    int M = 0;
    for (size_t i = 0; i < N; i++) {
        int L;
        cin >> L;
        sum += L;
        M = max(M, L);
    }
    cout << (2 * M < sum ? "Yes\n" : "No\n");
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <map>

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  string s; cin >> s;
  string result = ((s.length()%2==1) ^ (s[0]==s[s.length()-1])) ? "First" : "Second";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 512
#@k0gane_p 
a, b, c, d = [int(i) for i in input().split()]
def gcd(x,y):#最大公約数
    while y:
        x,y = y, x%y
    return x
def lcm(x,y):#最小公倍数
    return x*y // gcd (x,y)
def count(A,B,C):#A以下で、BでもCでも割り切れない個数
    D=A//B
    E=A//C
    F=A // lcm(B,C)
    return A-D-E+F
ans = count(b, c, d) - count(a-1, c, d)
#A以上B以下の整数のうち、CでもDでも割り切れないものの個数
#if(a % c != 0 and a % d != 0):
    #ans += 1#AがCでもDでも割り切れないなら、足す１
print(ans)

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

int main(){
    long long x,k,d;
    cin >> x >> k >> d;
    x = abs(x);
    long long tmp = min(k, x/d);
    x -= tmp * d;
    k -= tmp;
    if(k % 2 != 0){
        x = abs(x - d);
    }
    cout << x << endl;
    return 0;
}


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

bool is_kaibun(int n) {
  ostringstream oss;
  oss << n;
  string str = oss.str();
  bool is_ok = true;
  for (int i = 0; i < str.size() / 2; i++) {
    if (str[i] != str[str.size() - i - 1]) {
      is_ok = false;
      break;
    }
  }
  return is_ok;
}

void answer1(int a, int b) {
  int count = 0;
  for (int i = a; i <= b; i++) {
    if (is_kaibun(i)) {
      count++;
    }
  }
  cout << count << endl;
}

int main() {
  int a, b;
  cin >> a >> b;
  answer1(a, b);

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pll pair<ll,ll>
#define pint pll
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

struct edge{int to,cost;};
int V;
vector<edge> G[500010];
ll d[500010];
 
void dijkstra(int s){
  priority_queue<pint,vector<pint>,greater<pint>> que;
  fill(d,d+V,longinf);
  d[s]=0;
  que.push(pint(0,s));
  
  while(!que.empty()){
    pint p=que.top(); que.pop();
    int v=p.second;
    if(d[v]<p.first)continue;
    rep(i,G[v].size()){
      edge e=G[v][i];
      if(d[e.to]>d[v]+e.cost){
        d[e.to]=d[v]+e.cost;
        que.push(pint(d[e.to],e.to));
      }
    }
  }
}

int main(){
  int E;
  cin >> V >> E;
  rep(i,E){
    int x,y;
    cin >> x >> y;
    x--,y--;
    rep(i,3)G[x+i*V].push_back({y+((i+1)%3)*V,1});
  }
  int s,t;
  cin >> s >> t;
  s--,t--;
  V*=3;
  dijkstra(s);
  if(d[t]==longinf){
    cout << -1 << endl;
    return 0;
  }
  cout << d[t]/3 << endl;
return 0;}

Measured memory_bytes: 25216
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long INF=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)

bool isprime(int x){
	for(int i = 2;i*i<=x;i++){
		if(x%i == 0)return false;
	}
	return x!=1;
}
int gcd(int a, int b) 
{ 
    // Everything divides 0  
    if (a == 0) 
       return b; 
    if (b == 0) 
       return a; 
   
    // base case 
    if (a == b) 
        return a; 
   
    // a is greater 
    if (a > b) 
        return gcd(a-b, b); 
    return gcd(a, b-a); 
} 

int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	ini(n);
	ini(n1);
	int x = gcd(n,n1);
	if(x == 1){
		out(1);
		return 0;
	}
	set<int> set1;
	set1.insert(1);
	if(isprime(x))set1.insert(x);
	for(int i  = 2;i*i<=x;i++){
		if(x%i == 0){
			if(isprime(i))set1.insert(i);
			if(isprime(x/i))set1.insert(x/i);
		}
	}
	out(set1.size());













	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int N=1e2+5,M=2e5+5;
int n;
int a[N];
int main()
{
    // ios::sync_with_stdio(false);std::cin.tie(0);cout.tie(0);
    // freopen("a.in","r",stdin);
    // while(~scanf("%d",&n)){
    if(true){
    // int T;scanf("%d",&T);while(T--){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",a+i);
    }
    ll ans=1000;
    for(int i=1;i<n;i++){
        if(a[i]<a[i+1]) ans=ans%a[i]+ans/a[i]*a[i+1];
    }
    printf("%lld\n",ans);
    }return 0;
}


Measured memory_bytes: 3840
#include<iostream>
#include<string>

using namespace std;

int main() {
  int n, a;
  while (cin >> n, n) {
  int b[10] = {};
  for (int i = 0; i < n; i++) {
    cin >> a;
    b[a] += 1;
  }
  for (int i = 0; i < 10; i++) {
    if (b[i] > 0){
    string s(b[i], '*');
    cout << s << endl;
  } else if (b[i] <= 0) {
    cout << '-' << endl;
  }
  }
}
  return 0;
}



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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int K;
    cin >> K;

    if (K % 2 == 0) {
        cout << K * K / 4 << endl;
    } else {
        cout << (K + 1) / 2 * (K - 1) / 2 << endl;
    }

    return 0;
}



Measured memory_bytes: 256
import java.util.*;

// ARC 82-D
// https://beta.atcoder.jp/contests/arc082/tasks/arc082_b

public class Main {
	
	static int N;
	static int answer = Integer.MAX_VALUE;

	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		N = in.nextInt();
		int[] nums = new int[N];
		
		for (int i = 0; i < N; i++) {
			nums[i] = in.nextInt();
		}
		
		int answer = 0;
		
		for (int i = 0; i < N; i++) {
			if (i + 1 == nums[i]) {
				// Not the end of the array
				if (i != N - 1) {
					swap(nums, i, i + 1);
				} else {
					swap(nums, i, i - 1);
				}
				answer++;
			}
		}
		
		System.out.println(answer);
	}
	
	
	public static void swap(int[] arr, int i, int j) {
		int temp = arr[i];
		arr[i] = arr[j];
		arr[j] = temp;
	}
}



Measured memory_bytes: 49932
use std::io;
use std::iter::Iterator;

fn read<T: std::str::FromStr>() -> Vec<T> {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().split(' ').flat_map(str::parse).collect()
}

fn main() {
    let l1 = read::<i32>();

    let a = l1[0];
    let b = l1[1];
    let c = l1[2];

    let ans = (a..b + 1).filter(|n| c % n == 0).count();

    println!("{}", ans);
}



Measured memory_bytes: 5028
import fractions

n,x = map(int,input().split())
s = [abs(int(i)-x) for i in input().split()]

dp = [0]*n
for i in range(n):
    if i == 0:
        dp[0] = s[0]
    else:
        dp[i] = fractions.gcd(dp[i-1],s[i])
print(dp[-1])

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

const int N_MAX = 500;


int main() {
    int N, M, Q;
    cin >> N >> M >> Q;
    int L, R;
    int answerquery[N_MAX+1][N_MAX+1] = {0};
    int map[N_MAX+1][N_MAX+1] = {0};

    for (int i=0;i<M;i++)
    {
        cin >> L >> R;
        map[L][R]++;
    }

    for (int i=1;i<=N_MAX;i++)
    {
        for (int j=1;j<=N_MAX;j++)
            answerquery[i][j] = map[i][j] + answerquery[i][j-1] ;
    }

    for (int i=N_MAX; i>0;i--)
    {
        for (int j=1;j<=N_MAX;j++)
        {
            answerquery[i][j] += answerquery[i+1][j];
        }
    }
    int p, q;
    for (int i=0;i<Q;i++)
    {
        cin >> p >> q;
        cout << answerquery[p][q] << endl;
    }

    return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional> // greater など
#include <cmath>      // abs など
#include <numeric>    // accumulate, gcd など
#include <cassert>    // assert
#include <stdexcept>
#include <bitset>
using namespace std;

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
// typedef int128_t ll;
// typedef cpp_int ll;

// GCC, 配列のアクセスなど
#define _GLIBCXX_DEBUG
// Clang, 配列のアクセスなど
#define _LIBCPP_DEBUG 0

//////////////// //////////////// //////////////// //////////////// ////////////////
//////////////// //////////////// //////////////// //////////////// ////////////////

// constexpr inline ll mod = 1'000'000'007;
// constexpr int max_n = 200'000 + 5;

int main()
{
    // 高速な入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(15); // 浮動小数の表示の精度

    int h,w,k; cin>>h>>w>>k;
    vector<vector<bool>> ss(h, vector<bool>(w));
    rep(y, h) {
        rep(x, w) {
            char c; cin >> c;
            ss[y][x] = (c == '1');
        }
    }

    int res = 1050;
    for (int S = 0; S < (1 << (h - 1)); S++) {
        int tmpres = bitset<32>(S).count();
        vector<int> cnt(tmpres + 1);
        bool ok = true;
        rep(x, w) {
            bool cut = false;
            vector<int> cur_cnt(cnt.size());
            int cur_j = 0;
            rep(y, h) {
                cur_cnt[cur_j] += ss[y][x];
                if (cur_cnt[cur_j] > k)
                {
                    ok = false;
                }
                if (((S >> y) & 1) || y == h-1)
                {
                    if (cur_cnt[cur_j] + cnt[cur_j] > k) {
                        cut = true;
                    }
                    cur_j++;
                }
            }
            if (cut) {
                tmpres++;
                rep(j, cnt.size()) {
                    cnt[j] = 0;
                }
            }
            rep(j, cnt.size())
            {
                cnt[j] += cur_cnt[j];
            }
        }
        if (ok) {
            res = min(res, tmpres);
        }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 3640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_N 200

int stack[MAX_N+1];
int top;

void init(void) {
  top = 0;
}

int isEmpty(void) {
  return top == 0;
}

int isFull(void) {
  return top >= MAX_N;
}

void push(int x) {
  if (isFull()) {               /* オーバーフロー */
    return;                     /* スタックが満杯の時は何もしない */
  }
  top++;
  stack[top] = x;
}

int pop(void) {
  if (isEmpty()) {              /* アンダーフロー */
    return -1;                  /* スタックが空の場合は-1を返す */
  }
  top--;
  return stack[top+1];
}

int main(void) {
  int x;
  char s[100];

  while(scanf("%s", s) != EOF) {
    int a, b;
    if (s[0] == '+') {
      a = pop();
      b = pop();
      if (b >= 0) {
        push(b+a);
      }
    } else if (s[0] == '-') {
      a = pop();
      b = pop();
      if (b >= 0) {
        push(b-a);
      }
    } else if (s[0] == '*') {
      a = pop();
      b = pop();
      if (b >= 0) {
        push(b*a);
      }
    } else {
      x = atoi(s);
      push(x);
    }
  }

  printf("%d\n", stack[1]);
  return 0;
}

Measured memory_bytes: 548
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>

using namespace std;

vector<int> nums;

vector<string> split(string str, string delim)
{
	int pos = 0;
	vector<string> vec;
	while((pos=str.find_first_of(delim)) != str.npos)
	{
		if(pos > 0)
		{
			vec.push_back(str.substr(0, pos));
		}
		str = str.substr(pos + 1);
	}

	if(str.length() > 0)
	{
		vec.push_back(str);
	}

	return vec;
}

void solve()
{
	int sum = 0;
	int c = 0;
	for(int i=0; i<nums.size(); i++)
	{
		if(nums[i]>=10) sum += 10;
		else if(nums[i] != 1) sum += nums[i];
		else sum += 11, c++; 
	}

	for(int i=0; i<c; i++)
	{
		if(sum > 21) sum -= 10;
		else break;
	}
	sum = sum > 21 ? 0 : sum;
	cout << sum << endl;
}

int main(int argc, char** argv)
{
	string s;
	vector<string> vec;
	while(getline(cin, s) && s!="0")
	{
		vec = split(s, " ");
		nums.clear();
		for(int i=0; i<vec.size(); i++)
		{
			nums.push_back(atoi(vec[i].c_str()));
		}
		solve();
	}
}

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

int main(){
	string a, b;
	cin >> a >> b;

	int x = stoi(a + b);//Point.

	for(int i = 1; i*i <= x; ++i){
		if(i*i == x){
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;
	return 0;
}//解説参考.

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

int main()
{
    long long n, m;
    cin >> n >> m;
    if(n == 1 && m == 1){
        cout << 1 << endl;
    }
    else if(n == 1 || m == 1){
        cout << max(n, m) - 2 << endl;
    }
    else{
        cout << n * m - 2 * (m + n - 2) << endl;
    }
}

Measured memory_bytes: 256
N, M = map(int, input().split())
S, C = [], []
for _ in range(M):
    s, c = map(int, input().split())
    s -= 1
    if s in S:
        if C[S.index(s)] != c:
            print(-1)
            exit()
        else:
            continue
    S.append(s)
    C.append(c)

if len(S) == 0:
    if N == 1:
        print(0)
    elif N == 2:
        print(10)
    else:
        print(100)
    exit()

ans = [-1] * N
for i in range(len(S)):
    ans[S[i]] = C[i]

if N == 1:
    if ans[0] == 0:
        print(0)
        exit()

if ans[0] == -1:
    ans[0] = 1
elif ans[0] == 0:
    print(-1)
    exit()

ans = [a if a != -1 else 0 for a in ans]
print(''.join(list(map(str, ans))))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define INF_LL 1000000000000000LL
#define INF 200000000
#define MOD 1000000007
#define ll long long
#define all(x) x.begin(), x.end()
#define REP(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
// typedef float double;
// typedef priority_queue prique;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<ll> vl;
typedef vector<vi> matrix;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int sign[2] = {1, -1};
template <class T> bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}

ll modpow(ll a, ll b, ll m) {
    if(b == 0)
        return 1;
    ll t = modpow(a, b / 2, m);
    if(b & 1) {
        return (t * t % m) * a % m;
    } else {
        return t * t % m;
    }
}
struct edge {
    int to;
    ll cost;
    edge(int t, ll c) { to = t, cost = c; }
};

#define MAX_S 2500LL

vector<ll> dijkstra(vector<vector<edge>> &g, int start, int n) {
    priority_queue<P, vector<P>, greater<P>> que;
    vector<ll> dist(n, INF_LL);
    dist[start] = 0;
    que.push(P(0, start));
    while(!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if(dist[v] < p.first)
            continue;
        rep(i, (int)g[v].size()) {
            edge e = g[v][i];
            if(dist[e.to] > dist[v] + e.cost) {
                dist[e.to] = dist[v] + e.cost;
                que.push(P(dist[e.to], e.to));
            }
        }
    }
    return dist;
}

int main() {
    int n, m, s;
    cin >> n >> m >> s;
    vector<vector<edge>> g(n * (MAX_S + 1));
    rep(i, m) {
        int u, v, a;
        ll b;
        cin >> u >> v >> a >> b;
        REP(j, a, MAX_S + 1) {
            g[(u - 1) * (MAX_S + 1) + j].push_back(
                edge((v - 1) * (MAX_S + 1) + j - a, b));
            g[(v - 1) * (MAX_S + 1) + j].push_back(
                edge((u - 1) * (MAX_S + 1) + j - a, b));
        }
    }
    rep(i, n) {
        ll c, d;
        cin >> c >> d;
        rep(j, MAX_S) {
            g[i * (MAX_S + 1) + j].push_back(
                edge(i * (MAX_S + 1) + min(j + c, MAX_S), d));
        }
    }
    vl d(n * (MAX_S + 1));
    d = dijkstra(g, min((ll)s, MAX_S), n * (MAX_S + 1));
    REP(j, 1, n) {
        ll ans = INF_LL;
        rep(i, MAX_S + 1) { chmin(ans, d[j * (MAX_S + 1) + i]); }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 27128
#include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define FAST ios_base::sync_with_stdio(false);cin.tie(0);
    const double EPS = 1e-9;
    const double PI = acos(-1);
    const int knightDir[8][2] = {{-2,-1},{-2,1},{-1,2},{1,2},{2,-1},{2,1},{-1,-2},{1,-2}};
    //const int dx[]={0,0,0,1,1,1,-1,-1,-1};
    //const int dy[]={-1,0,1,-1,0,1,-1,0,1};
    const int dx[] = {0 , 1 , 0 , -1};
    const int dy[] = {1 , 0 , -1 , 0};
    //#define MOD         1000000007LL
    #define MAX         1005
    const ll MOD = 1000000000 + 7;

    bool vis[MAX][MAX];
    int cost[MAX][MAX];
    string maze[MAX];
    int w , h ,cx , cy , fx , fy;
    bool isSafe(int x , int y)
    {
        if(x < 0 || x >= w || y < 0 || y >= h)return false;
        else return true;
    }
    int main()
    {
        FAST
        int t;
        t = 1;

        while(t--)
        {

           cin >> w >> h;
           cin >> cx >> cy;
           cx-- , cy--;
           cin >> fx >> fy;
           fx--,fy--;

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

           memset(cost , -1 , sizeof cost);

           deque<pair <int , int > > q;
           q.push_front({cx , cy});
           cost[cx][cy] = 0;

           while(!q.empty())
           {

               pair <int, int> t = q.front();
               q.pop_front();

               if(vis[t.first][t.second])
               {
                   continue;
               }
               vis[t.first][t.second] = 1;

               for(int i = 0 ; i < 4 ; i++)
               {
                   int nx = t.first + dx[i];
                   int ny = t.second + dy[i];

                   if(!isSafe(nx , ny))continue;
                   if(maze[nx][ny] == '#')continue;

                   if(cost[nx][ny] == -1 || cost[t.first][t.second] < cost[nx][ny])
                   {
                       cost[nx][ny] = cost[t.first][t.second];
                       q.push_front({nx , ny});
                   }

               }

               for(int i = -2 ; i < 3 ; i++)
               {
                   for(int j = -2 ; j < 3 ; j++)
                   {
                       int nx = t.first + i;
                       int ny = t.second + j;

                       if(!isSafe(nx , ny))continue;
                       if(maze[nx][ny] == '#')continue;

                       if(cost[nx][ny] == -1 || cost[t.first][t.second] + 1 < cost[nx][ny])
                   {
                       cost[nx][ny] = cost[t.first][t.second] + 1;
                       q.push_back({nx , ny});
                   }

                   }
               }

           }

           cout << cost[fx][fy] << endl;
        }
    }



Measured memory_bytes: 9760
#include <stdio.h>
#include <stdlib.h>
#define p 360
#define inf (int)(1e9)

int max(int a, int b){
	if(a > b){
		return a;
	}
	else{
		return b;
	}
}

int min(int a, int b){
	if(a < b){
		return a;
	}
	else{
		return b;
	}
}

int MOD(int a){
	if(a >= 0){
		return a % p;
	}
	else{
		return p + a % p;
	}
}

int main(){
	int N, x, i, M, D, ans = inf, ans_sub;
	scanf("%d", &N);
	int *MD = (int *)malloc(sizeof(int) * N);
	int *S = (int *)malloc(sizeof(int) * N);
	int *V = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		scanf("%d%d%d%d", &M, &D, &V[i], &S[i]);
		MD[i] = 30 * (M - 1) + (D - 1);
	}
	for(x = 0; x < 360; x++){
		ans_sub = 0;
		for(i = 0; i < N; i++){
			if((MD[i] <= x && x < MD[i] + V[i]) || (MD[i] <= x + p && x + p < MD[i] + V[i])){
				ans_sub = max(ans_sub, S[i]);
			}
			else{
				ans_sub = max(ans_sub, S[i] - min(MOD(MD[i] - x), MOD(x - MD[i] - V[i] + 1)));
			}
		}
		ans = min(ans, ans_sub);
//		printf("(x, ans) = (%d, %d)\n", x, ans);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1840
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

#define MAXN 2000005
#define MAXM 10000

int a[MAXN],b[MAXN];
int c[MAXM+1];
int n;

int main()
{
    scanf("%d",&n);
    memset(c,0,sizeof(c));
    for(int i=1; i<=n; i++)
    {
        scanf("%d",&a[i]);
        c[a[i]]++;
    }
    for(int i=1; i<=MAXM; i++)
        c[i]+=c[i-1];
    for(int i=1; i<=n; i++)
    {
        b[c[a[i]]]=a[i];
        c[a[i]]--;
    }
    for(int i=1; i<n; i++)
        printf("%d ",b[i]);
    printf("%d\n",b[n]);
    return 0;
}

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

int main(){
  int N,K,c;
  cin>>N>>K>>c;
  string S;
  cin>>S;
  vector<int> a(K),b(K);

  int i=0;
  int cnt=0;
  while(cnt<K && i<N){
    if(S[i]=='x') ++i;
    else{
      a[cnt]=i;
      ++cnt;
      i += c+1;
    }
  }
  i=N-1;
  cnt=K-1;
  while(cnt>=0 && i>=0){
    if(S[i]=='x') --i;
    else{
      b[cnt]=i;
      --cnt;
      i=i-(c+1);
    }
  }

  for(int i=0;i<K;++i){
    if(a[i]==b[i]) cout<<a[i]+1<<endl;
  }

}

Measured memory_bytes: 3332
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
		int x = Integer.parseInt(sc.next());
      	int a = Integer.parseInt(sc.next());
      
      	int result = (x < a) ? 0: 10;
      	System.out.print(result);
    }
}


Measured memory_bytes: 21588
from collections import deque
n = int(input())
G = [deque([]) for _ in range(n)]
for i in range(n - 1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append([b, c])
    G[b].append([a, c])
dist = [-1] * n

def dfs(v):
    cnt = 0
    stack = [[v, 0]]
    while stack:
        x = stack[-1]
        if len(G[x[0]]) > 0:
            w = G[x[0]].popleft()
            if dist[w[0]] == -1:
                dist[w[0]] = w[1] + dist[x[0]]
                stack.append(w)
        else: stack.pop()

q, k = map(int, input().split())
k -= 1
dist[k] = 0
dfs(k)
for i in range(q):
    x, y = map(int, input().split())
    print(dist[x - 1] + dist[y - 1])
#print(dist)

Measured memory_bytes: 100316
N, A, B = map(int, input().split())

if abs(A - B) % 2 == 0:
    print((B - A) // 2)
else:
    left = B - 1
    right = N - A
    if abs(A - B) < 3:
        print(min(left, right))
    else:
        if left < right:
            print((B - A - 1) // 2 + A)
        else:
            print((B - A - 1) // 2 + N - B + 1)

Measured memory_bytes: 3060
import datetime

a = input().split("/")

year = int(a[0])
month = int(a[1])
day = int(a[2])

kyou = datetime.datetime(year,month,day)

reiwa = datetime.datetime(2019,5,1)

if kyou < reiwa :
    print('Heisei')
else:
    print('TBD')

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<58;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    while(true){
        ll n,k;
        cin >> n >> k;
        if(n==0 and k==0) break;

        ll x,y;
        rep(i,1,inf){
            ll tmp=i*(pow(10,i)-pow(10,i-1));
            if(n-tmp>0) n-=tmp;
            else{
                x=pow(10,i-1);
                y=i;
                break;
            }
        }
        dump(x);
        dump(y);
        dump(n);

        ll z=0;
        rep(i,1,11){
            if(n-y*x>0) n-=y*x;
            else{
                z=i;
                break;
            }
        }
        dump(z);
        dump(n);
        ll w=0;
        rep(i,1,11){
            if(n-y*x/10>0) n-=y*x/10;
            else{
                w=i-1;
                break;
            }
        }
        dump(w);
        dump(n);
        ll hoge=0;
        rep(i,1,11){
            if(n-y*x/100>0) n-=y*x/100;
            else{
                hoge=i-1;
                break;
            }
        }
        dump(hoge);
        ll piyo=0;
        rep(i,1,11){
            if(n-y*x/1000>0) n-=y*x/1000;
            else{
                piyo=i-1;
                break;
            }
        }
        dump(piyo);
        dump(n);
        stringstream ss;
        rep(i,0,100000){
            ss << x*z+x*w/10+x*hoge/100+x*piyo/1000+i;
            //dump(ss.str().size());
            if(ss.str().size()>n+k) break;
        }
        cout << ss.str().substr(n-1,k) << endl;
    }
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    cout << fixed << setprecision(8);
    solve();
    return 0;
}

Measured memory_bytes: 5264