akhauriyash/Code-Regression huggingface dataset:
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N;
int A[int(2e5 + 5)], B[int(2e5 + 5)];

int main(){
  scanf("%d", &N);
  for (int i = 0; i < N; i++) scanf("%d%d", A + i, B + i);
  sort(A, A + N); sort(B, B + N);

  if (N % 2 == 0){
    cout << (B[N / 2] + B[N / 2 - 1]) - (A[N / 2] + A[N / 2 - 1]) + 1 << endl;
  }else{
    cout << B[N / 2] - A[N / 2] + 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 5332
#include <iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

using namespace std;

struct Node {
    int key;
    Node *left, *right;
};
Node *root, *NIL;

void insert(int k) {
    if(root == NIL) {
        root = (Node *)malloc(sizeof(Node));
        root->key = k;
        root->left = root->right = NIL;
    }else {
        Node *z = (Node *)malloc(sizeof(Node));
        z->key = k;
        z->left = z->right = NIL;

        Node *x = root;
        while(true) {
            if(k < x->key) {
                if(x->left == NIL) {
                    x->left = z;
                    break;
                }
                else x = x->left;
            }else {
                if(x->right == NIL) {
                    x->right = z;
                    break;
                }
                else x = x->right;
            }
        }
    }
}

void inorder(Node *node) {
    if(node == NIL) return;
    inorder(node->left);
    printf(" %d", node->key);
    inorder(node->right);
}

void preorder(Node *node) {
    if(node == NIL) return;
    printf(" %d", node->key);
    preorder(node->left);
    preorder(node->right);
}

int main()
{
    /*
    int n, x;
    string str;
    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
        cin >> str;
        if(str == "insert") {
            scanf("%d", &x);
            insert(x);
        }else if(str == "print") {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }
    return 0;
    */


    int n, x;
    char str[19];
    scanf("%d", &n);

    for(int i = 0; i < n; i++) {
        scanf("%s", str);
        if(str[0] == 'i') {
            scanf("%d", &x);
            insert(x);
        }else if(str[0] == 'p') {

            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }

    return 0;

}

Measured memory_bytes: 18704
#include <stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
void dfs_visit(int);
void dfs(void);
int n,M[N][N]={},color[N],o[N],e[N],count;

void dfs_visit(int u){
  int v;
  
  color[u]=GRAY;
  o[u]=++count;

  for(v=0;v<n;v++){
    if(M[u][v]==0) continue;
    if(color[v]==WHITE) dfs_visit(v);
  }

  color[u]=BLACK;
  e[u]=++count;
}

void dfs(void){
  int u;
  
  for(u=0;u<n;u++) color[u]=WHITE;
  count=0;

  for(u=0;u<n;u++){
    if(color[u]==WHITE) dfs_visit(u);
  }

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

int main()
{
  int u,v,k,i,j;

  scanf("%d",&n);

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

  dfs();

  return 0;
}

Measured memory_bytes: 636
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define ln '\n'
//const long long MOD = 1000000007LL;
const long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

using mint = modint<MOD>;

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    string S; cin >> S;

    mint ans = 1;
    rep(i,N) ans *= (i+1);
	vector<ll> A(3*N),P(3*N);
	int R = 0, G = 0, B = 0; 
    rep(i,3*N) {
		if (S[i]=='R') {
			R++;
			if (R > G && R > B) {
				A[i] = 1;
			} else if (R <= G && R <= B) {
				A[i] = -1;
			} 
		}
		if (S[i]=='G') {
			G++;
			if (G > B && G > R) {
				A[i] = 1;
			} else if (G <= B && G <= R) {
				A[i] = -1;
			} 
		}
		if (S[i]=='B') {
			B++;
			if (B > R && B > G) {
				A[i] = 1;
			} else if (B <= R && B <= G) {
				A[i] = -1;
			} 
		}
    }
	ll cnt = 0;
	rep(i,3*N) {
		if (A[i]==1) cnt++;
		if (A[i]==0) {
			P[i] = cnt;
			--cnt;
		}
	}
	cnt = 0;
	for (int i = 3*N-1; i >= 0; --i) {
		if (A[i]==-1) cnt++;
		if (A[i]==0) {
			P[i] *= cnt;
			ans *= P[i];
			--cnt;
		}
	}
    cout << ans.a << ln;
}


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

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}






int gcd(int a,int b)
{
 
  int r, tmp;
 
  
 
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
 
 
  return b;
}







int fac(int n){
  int m=1;
  while(n>=1) m*=n,n--;
  return m;
}

int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}
///////////////////////////
int main() {
  bool flag=false;
  int n,m;
  cin>>n>>m;
  vector<int> a(m),b(m),v;
  rep(i,m) cin>>a[i]>>b[i];
  rep(i,m){
    if(a[i]==1 && b[i]==n){
      cout<<"POSSIBLE"<<endl;
      return 0;
    }
    if(a[i]==1){
      v.push_back(b[i]);
    }
    if(b[i]==n){
      v.push_back(a[i]);
    }
  }
  sort(v.begin(),v.end());
  if(v.size()<=1){
    cout<<"IMPOSSIBLE"<<endl;
    return 0;
  }
  
  for(int i=0;i<v.size();i++){
    if(v[i]==v[i+1]){
      cout<<"POSSIBLE"<<endl;
      return 0;
    }
  }
  cout<<"IMPOSSIBLE"<<endl;
  
  
}
///////////////////////////

Measured memory_bytes: 2936
#include<iostream>
#include<math.h>
#include<stdio.h>
using namespace std;

int main() {
	double N;
	cin >> N;
	double x[10];
	double y[10];
	for (int i = 0; i < N; i++) {
		cin >> x[i] >> y[i];
	}
	auto f = [&](int i, int j) {
		double res;
		res = sqrt((x[i] - x[j])*(x[i] - x[j]) + (y[i] - y[j])*(y[i] - y[j]));
		return res;
	};
	double r = 1;
	for (double i = 1; i < N; i++) {
		r = r * i;
	}
  //   r = 2 * r;  //周数 2(N-1)!　

//それぞれの町間の距離の合計
		double S = 0;
		for (int i = 0; i < N-1; i++) {
			for (int j = i + 1; j < N; j++) {
				S = S + f(i, j);
			}
		}
		double ave=S*2/N;
		printf("%.7f", ave);

	return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
#pragma warning(disable : 4996)
using namespace std;
int N, L; string S[111];
int main() {
	cin >> N >> L;
	for (int i = 0; i < N; i++) cin >> S[i];
	sort(S, S + N);
	for (int i = 0; i < N; i++) cout << S[i];
	cout << endl;
	return 0;
}

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

using namespace std;

int h, w, c[10][10], a[200][200], dp[10];
bool b[10];

void fd(int i, int add, int now){
	for(int j = 0; j < 10; j++){
		if(j == i)
			continue;
		if(j == 1){
			dp[i] = min(dp[i], add + c[now][1]);
		}
		if(!b[j]){
			b[j] = 1;
			fd(i, add + c[now][j], j);
			b[j] = 0;
		}
	}
}

int main(){
	long long int count = 0;
	cin >> h >> w;
	for(int i = 0; i < 10; i++){
		for(int j = 0; j < 10; j++){
			cin >> c[i][j];
		}
	}
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			cin >> a[i][j];
		}
	}
	for(int i = 0; i < 10; i++){
		dp[i] = c[i][1];
		for(int j = 0; j < 10; j++){
			b[j] = 0;
		}
		fd(i, 0, i);
	}
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(a[i][j] >= 0){
				count += dp[a[i][j]];
			}
		}
	}
	
	cout << count << endl;
	
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;cin >> n;
    int a[n];
    int count = 0;
    for(auto &i:a) cin >> i;
    for(int i=0;i<n;i++){
        int minj = i;
        for(int j=i;j<n;j++){
            if(a[j]<a[minj]){
                minj = j;
            }
        }
        if(i!=minj){
            swap(a[i],a[minj]);
            count++;
        }
    }
    for(int i=0;i<n-1;i++) cout << a[i] << " ";
    cout << a[n-1] << endl << count << endl;
    return 0;
}


Measured memory_bytes: 3088
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
#include<chrono>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define vint(a,n) vint a(n); rep(i, n) cin >> a[i];
#define vll(a,n) vll a(n); rep(i, n) cin >> a[i];
#define ALL(n) begin(n),end(n)
#define RALL(n) rbegin(n),rend(n)
#define MOD (1000000007)
// #define MOD (998244353)
#define INF (2e9)
#define INFL (2e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using vint=vector<int>;
using vll=vector<ll>;
using vbool=vector<bool>;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
    int n, m; cin >> n >> m;
    ll x[n][3];
    rep(i, n) rep(j, 3) cin >> x[i][j];

    ll ans = 0;
    rep(bit, 1<<3){
        vll s(n);
        int ax[3];
        rep(i, 3){
            if((bit>>i)&1) ax[i] = 1;
            else ax[i] = -1; 
            // cout << ax[i] << " ";
        }
        // pr("");
        rep(i, n){
            rep(j, 3) s[i] += ax[j]*x[i][j];
        }
        sort(RALL(s));
        ll t = 0;
        rep(i, m) t += s[i];
        // pr(t);
        // pr("");
        chmax(ans, t);
    }
    pr(ans);
    return 0;}

Measured memory_bytes: 3664
/*
 * ex 9-1
 * kamecha
 */
#include <stdio.h>
#include <stdlib.h>

#define SIZE 100

typedef struct{
    int size;
    int count;
    char data[SIZE];
    char *top;
} stack;

void initialize(stack *stk){
    stk->count = 0;
    stk->size = SIZE;
    stk->top = &(stk->data[SIZE]);
}

void push(stack *stk, char elem){
    if(stk->count < stk->size){
        stk->top--;
        *(stk->top) = elem;
        stk->count++;
    }
}

char pop(stack *stk){
    char latest;
    if(stk->count > 0){
        latest = *(stk->top);
        stk->top++;
        stk->count--;
        return latest;
    }
}

//下から順に表示
void print(stack *stk){
    char *ptr = &(stk->data[SIZE]);
    for(int i = 0; i < stk->count; i++){
        printf("%c", *(--ptr));
    }
    printf("\n");
}

int main(void){
    stack stk;
    initialize(&stk);
    char str[20];
    scanf("%s", str);
    for(int i = 0; str[i] != '\0'; i++){
        if(str[i] == 'B'){
            pop(&stk);
        }else{
            push(&stk, str[i]);
        }
    }
    print(&stk);
    return 0;
}


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

int main(){
    vector<int> a(5);
    int k;
    for(int i=0;i<5;++i){
        cin >> a[i];
    }
    cin >> k;
    sort(a.begin(),a.end());
    if(a[4]-a[0]<=k){
        cout << "Yay!" << endl;
    }else{
        cout << ":(" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

"""
参考にしました(写経)
https://atcoder.jp/contests/abc163/submissions/12137623

Axが大きい順に置ける部分の中で一番左か一番右に置きたい
dp[i][j]:左からi個目, 右からj個目まで埋まっているときの最大値
i個目を見ているとき左と右に埋まっている数はi-1個なので
dp[i][j]は(左の個数,右の個数) = (0,i-1),(1,i-2),...とO(N)で探索できる
"""
n = I()
a = LI()
b = [[a[i],i] for i in range(n)]
b.sort(reverse=1)
dp = [[0]*(n+1) for _ in range(n+1)]
for i in range(n):
    a,j = b[i]
    for k in range(i+1):
        dp[k][i+1-k] = max(dp[k][i+1-k], dp[k][i-k] + a*abs(j-((n-1)-(i-k)))) #右側に追加
        dp[k+1][i-k] = max(dp[k+1][i-k], dp[k][i-k] + a*abs(j-k)) #左側に追加
ans = 0
for i in range(n):
    ans = max(ans, dp[i][n-i])
print(ans)

Measured memory_bytes: 101124
#include<cstdio>
#define N 200002
#define p 1000000007
inline int mod(int x){return x<p?x:x-p;}
int f[N],g[N],i,j,m,n,t,x;char s[N];
int main()
{
    scanf("%d%d%s",&n,&m,s+1),f[0]=g[0]=1;
    if(s[1]=='B')for(i=1;i<=m;i++)s[i]=s[i]=='B'?'R':'B';
    while(s[m]=='R')s[m--]=0;
    for(i=0;s[i+1]=='R';i++);
    for(t=i++|1;s[i];t=(i-j&1)&&i-j<t?i-j:t)
    {
        while(s[i]=='B')i++;
        for(j=i;s[i]=='R';i++);
    }
    if(m)for(i=1;i<=n;f[i]=mod(f[i-1]+g[i]),i++)if(~i&1)g[i]=i<t+2?f[i-1]:mod(p+f[i-1]-f[i-t-2]);else;
    else for(g[1]=1,i=2;i<=n;i++)g[i]=mod(g[i-2]+g[i-1]);
    if(m)for(i=n-2;0<=i&&n-i<=t+1;i-=2)x=(x+(long long)g[i]*(n-i))%p;
    else x=mod(g[n]+g[n-2]);
    return 0*printf("%d\n",x);
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define mod 1000000007
 
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
 
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

int main(){
	int n;
	cin >> n;
	int x[n], y[n], h[n];
	int v;
	for (int i = 0; i < n; i++){
		cin >> x[i] >> y[i] >> h[i];
		if (h[i] > 0) v = i;
	}

	for (int i = 0; i <= 100; i++){
		for (int j = 0; j <= 100; j++){
			int hh = h[v] + abs(x[v] - i) + abs(y[v] - j);
			bool ok = true;
			for (int k = 0; k < n; k++){
				if (max(hh - abs(x[k] - i) - abs(y[k] - j), 0) != h[k]){
					ok = false;
					break;
				}
			}
			if (ok){
				cout << i << " " << j << " " << hh << endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
// SeeAlso: 

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

int main() {
    int N, M;
    cin >> N >> M;
    
    print(M>=N ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(void) {
    string s;
    cin>>s;
    int len=s.size();
    s.push_back('R');
    
    vector<int> ans(len,0);
    
    int flag=0;
    int count=0;
    
    for(int i=0;i<len;i++){
        if(flag==0 && s[i+1]=='R'){
            count++;
        }
        else if(flag==0 && s[i+1]=='L'){
            count++;
            flag=1;
            ans[i]+=(count+1)/2;
            ans[i+1]+=count/2;
            count=0;
        }
        else if(flag==1 && s[i+1]=='L'){
            count++;
        }
        else{
            count++;
            flag=0;
            ans[i-count]+=count/2;
            ans[i-count+1]+=(count+1)/2;
            count=0;
        }
    }
    for(int i=0;i<len;i++){
        cout<<ans[i]<<" ";
    }
    cout<<endl;
}

Measured memory_bytes: 1024
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
graph = [{} for _ in range(N)]

for _ in range(N-1):
    u, v, w = mapint()
    graph[u-1][v-1] = w%2
    graph[v-1][u-1] = w%2

from collections import deque
stack = deque([0])

colors = [-1]*N
colors[0] = 0
while stack:
    v = stack.pop()
    for nx in graph[v].keys():
        if colors[nx]==-1:
            w = graph[v][nx]
            colors[nx] = (colors[v]+w)%2
            stack.append(nx)

for a in colors:
    print(a)

Measured memory_bytes: 108052
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[][] input = new int[M][2];
		for(int i = 0;i < M;++i) {
			input[i][0] = sc.nextInt();
			input[i][1] = sc.nextInt();
		}
		sc.close();
		
		Map<Integer, ArrayList<Integer>> map = new HashMap<>();
		for(int i = 0;i < M;++i) {
			if(!map.containsKey(input[i][0])) {
				ArrayList<Integer> cap = new ArrayList<>();
				cap.add(i);
				map.put(input[i][0], cap);
			}else {
				ArrayList<Integer> list = map.get(input[i][0]);
				int left = 0, right = list.size();
				while(left <= right) {
					int j = (left + right)/2;
					if(input[list.get(j)][1] < input[i][1]) {
						if(j+1 > list.size()-1) {
							list.add(i);
							break;
						}else if(input[list.get(j+1)][1] > input[i][1]) {
							list.add(j+1, i);
							break;
						}else {
							left = j+1;
						}
					}else {
						if(j-1 < 0) {
							list.add(0, i);
							break;
						}else if(input[list.get(j-1)][1] < input[i][1]) {
							list.add(j, i);
							break;
						}else {
							right = j-1;
						}
					}
				}
			}
		}
		
		for(Integer i : map.keySet()) {
			ArrayList<Integer> list = map.get(i);
			for(int j = 0;j < list.size();++j) {
				input[list.get(j)][1] = j;
			}
		}
		
		StringBuilder sb = new StringBuilder();
		for(int i = 0;i < M;++i)
			sb.append(String.format("%06d%06d\n", input[i][0], input[i][1]+1));
		System.out.println(sb.toString());
	}
}


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


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

    long long int sum = 0;

    for(int i=1; i<=N; i++){
        if(i%5 != 0 && i%3 != 0){
            sum += i;
        }
        
    }

    cout << sum;


    return 0;
}

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

pair<int, int> solve(string s)
{
  int len = s.length();
  if(len == 1) return make_pair(-1, -1);
  if(len == 2)
   if(s[0] == s[1])
    return make_pair(1, 2);
   else
    return make_pair(-1, -1);

  for(int i=0; i<=len-3; i++)
   if(s[i] == s[i+1] || s[i] == s[i+2] || s[i+1] == s[i+2]) //se esiste una sottostringa nonbilanciata, deve esistere anche una sottostringa da 3 non bilanciata
    return make_pair(i+1, i+3);
  return make_pair(-1, -1);
}

int main()
{
  string s;
  cin>>s;
  pair<int, int> r = solve(s);
  cout<<r.first<<" "<<r.second<<endl;
  return 0;
}


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

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

    int n, l;
    cin >> n >> l;
    vector<int> A(n);
    int t = 0;
    for(int i = 0; i < n; i++){
        A[i] = l + (i + 1) - 1;
        t += A[i];
    }

    int ans = 1e9, a = 0;
    for(int i = 0; i < n; i++){
        if(ans > abs(A[i])){
            a = t - A[i];
            ans = abs(A[i]);
        }
    }

    cout << a << endl;

    return 0;
}

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

using namespace std;

int main(void){
vector<int> v;
int t;
for (int i=0; i<4; i++){
cin>>t;
v.push_back(t);
}
sort(v.begin(), v.end());
cout << (v[0]==v[1]&&v[2]==v[3]?"yes":"no") << endl;
return 0;
}


Measured memory_bytes: 3160
#include<bits/stdc++.h>
#define endl '\n'
#define INF (1 << 21)
typedef long long ll;
const int MOD = 1000000007;
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  string w[105];
  map<string, int>lw;

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

  for(int i = 1;i < n;i++){
    if(lw[w[i]] != 1 || w[i - 1][w[i - 1].size() - 1] != w[i][0]){
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  return 0;
}



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

#define YESNO(x) x ? printf("YES") : printf("NO")
#define YesNo(x) x ? printf("Yes") : printf("No")
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define scani(x) scanf("%d", &x)
#define scanll(x) scanf("%lld", &x)
#define printi(x) printf("%d", x)
#define printll(x) printf("%lld", x)
typedef long long ll;
using namespace std;

long long GCD(long long x, long long y) {
	return y ? GCD(y, x % y) : x;
}

long long LCM(long long x, long long y) {
	return x * y / GCD(x, y);
}

int Main() {
	int n;
	scani(n);

	switch (n % 10) {
	case 2:
	case 4:
	case 5:
	case 7:
	case 9:
		printf("hon");
		break;
	case 0:
	case 1:
	case 6:
	case 8:
		printf("pon");
		break;
	case 3:
		printf("bon");
		break;
	}

	return 0;
}

int main()
{
	Main();

	return 0;
}

Measured memory_bytes: 3832
# AOJ 0114: Electro-Fly
# Python3 2018.6.18 bal4u

from math import gcd

while True:
	a1, m1, a2, m2, a3, m3 = list(map(int, input().split()))
	if a1 == 0: break
	n = 0
	b1, b2, b3 = 1, 1, 1
	a, b, c = 0, 0, 0
	while True:
		if a == 0: b1 = (b1 * a1) % m1
		if b == 0: b2 = (b2 * a2) % m2
		if c == 0: b3 = (b3 * a3) % m3
		n += 1
		if a == 0 and b1 == 1: a = n
		if b == 0 and b2 == 1: b = n
		if c == 0 and b3 == 1: c = n
		if a != 0 and b != 0 and c != 0: break
	
	ans = a // gcd(a,b) * b
	ans = ans // gcd(ans, c) * c
	print(ans)



Measured memory_bytes: 5660
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 08/02/20 20:55:48
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  ll n,d; cin>>n>>d;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ll x,y; cin>>x>>y;
    if (x*x + y*y <= d*d) {
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}


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

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

  if((a==7 && b==5 && c==5) || (a==5 && b==7 && c==5) || (a==5 && b==5 && c==7)) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define max(a,b) a > b ? a : b

int main(void){
	int n, w, v[100], i, j, count[11], num, max;
	double sum;
	while(1){
		scanf("%d%d",&n,&w);
		if(n == 0 && w == 0)
			break;
		max = 0;
		for(i = 0;i < n;i++){
			scanf("%d",&v[i]);
			max = max(max,v[i]);
		}
		num = max / w + 1;
		memset(count,0,sizeof(count));
		max = 0;
		for(i = 0;i < n;i++){
			for(j = 0;j < num;j++){
				if(j * w <= v[i] && v[i] < (j + 1) * w)
					count[j]++;
			}
		}


		for(i = 0;i < num;i++)
			max = max(max,count[i]);
		sum = 0;
		if(num != 1){
			for(i = 0;i < num;i++){
				sum += ((double)(num - 1 - i) / (num - 1)) * ((double)count[i] / max);
			}
			printf("%.16f\n",sum + 0.01);
		}
		else
			printf("1.01\n");
	}
	return 0;
}

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

using namespace std;

 

int main() {

  int N,M;

  cin >> N >> M;

  vector<int> x(M*2);

  vector<int> y(N);

  

  for(int i=0;i<x.size();i++){

    cin >> x.at(i);

  }

  

  for(int i=0;i<x.size();i++){

    

    for(int j=0;j<N;j++){

      

      if(x.at(i)==j+1){

        y.at(j)+=1;

        

      }

      

    }

    

  }

  

  for(int i=0;i<N;i++)

    cout << y.at(i) << endl;

  

}



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

using namespace std;

typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli>> mat;
typedef vector<unordered_map<lli,lli>> graph;

lli n,k;
lli ans;

int main(){
  cin >> n >> k;
  if(k == 0){ cout << n*n << endl;return 0;}
  for(lli i = k+1;i <= n;i++){
    ans += (i-k)*(n/i);
    if(n%i != 0) ans += max(n%i+1,k)-k;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
using System.Linq;
class ABC060A
{
    static void Main()
    {
        var inputs=System.Console.ReadLine().Split(' ');
        System.Console.WriteLine(
            inputs[0].Last()==inputs[1].First()&&inputs[1].Last()==inputs[2].First()?
            "YES"
            :"NO"
        );
    }
}

Measured memory_bytes: 11220
from math import ceil,floor

A,B=map(int,input().split())
x_min=int(min(ceil(A/0.08)-5, ceil(B/0.1)-5))
x_max=int(max(ceil((A+1)/0.08)+5, ceil((B+1)/0.1)+5))
exists=0
for i in range(x_min, x_max):
  if floor(i*0.08)==A and floor(i*0.1)==B:
    print(i)
    exists=1
    break
if not exists:print(-1)

Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	x=0;char c=getchar();bool f=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return  x;
}
template<class t> inline void write(t x){
	if(x<0){putchar('-'),write(-x);}
	else{if(x>9)write(x/10);putchar('0'+x%10);}
}

#include <tr1/unordered_map>

const int N=2e5+5;
int n,k,s[N];
long long ans;
tr1::unordered_map<int,queue<int> > mp;

signed main(){
	read(n);read(k);
	for(int i=1,x;i<=n;i++){
		read(x);
		x%=k;
		s[i]=(s[i-1]+x)%k;
	}
	for(int i=1;i<=n;i++){
		int now=s[i]-i;
		now=(now%k+k)%k;
		while(!mp[now].empty()&&i-mp[now].front()>=k) mp[now].pop();
		ans+=mp[now].size();
		if(s[i]==i) ans++;
		mp[now].push(i);
	}
	write(ans);
}


Measured memory_bytes: 143688
#include<iostream>

using namespace std;

int main(void)

{
    int a,b,c;
    cin>>a>>b>>c;
    if((a==b && b !=c)||(b==c&&c!=a)||(c==a&&a!=b)){
        cout<<"Yes\n";
    }
    else{
        cout<<"No\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cerr<<#x<<"="<<(x)<<endl;
template<typename T>
void read(T &x)
{
	char ch=getchar();
	for (x=0;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';x=x*10+ch-'0',ch=getchar());
}
typedef long long ll;
ll n,A,B,bg,sm;
int main()
{
	read(n),read(A),read(B);
	if (A>B)
		puts("0");
	else if (n==1)
		printf("%d\n",(A==B));
	else
	{
		bg=(n-1)*B+A;
		sm=(n-1)*A+B;
		printf("%lld",bg-sm+1);
	}
	return 0;
}

Measured memory_bytes: 256
## coding: UTF-8
s = input().split()
t = [int(p) for p in s]
K = t[0]
S = t[1]
counter = 0

for X in range(K+1):
    for Y in range(K+1):
        if(S-X-Y >= 0 and S-X-Y <=K):
            counter += 1
print(counter)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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


int main() {
    int N;
    cin >> N;
    vector<double> x(N), y(N);
    REP(i, N){
        cin >> x[i] >> y[i];
    }

    vector<vector<double>> m(N, vector<double>(N, 0));
    double s = 0;
    REP(i, N)REP(j, N){
        m[i][j] = sqrt((x[i] - x[j]) *(x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
        s += m[i][j];
    }
    s /= N;
    //cout << s << endl;
    printf("%.8f\n", s);
    return 0;
}

Measured memory_bytes: 256
using System;
using static System.Console;
using static System.Math;

namespace algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            string tmp = ReadLine();
            decimal H = int.Parse(tmp.Split()[0]);
            decimal W = int.Parse(tmp.Split()[1]);
            if (H == 1 || W == 1)
            {
                WriteLine(1);
            }
            else
            {
                WriteLine(Ceiling(H * W / 2));
            }
        }
    }
}

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

int main() {
    int R;
    int N;
    int TmpR = 0;
     cin >> N;
     cin >> R;
    if (N < 10) {
        TmpR = 100 * (10 - N);
    }
     
    cout << R+TmpR << endl;
}


Measured memory_bytes: 256
"use strict";
function main(input) {
  const inputs = input.split("\n").filter(x => x !== "");
  let N = Number(inputs[0]);

  function resolve(n) {
    let result = Array(n + 1).fill(0);
    for (let i = 2; i <= n; i++) {
      let cur = i;
      for (let j = 2; j <= i; j++) {
        while (cur % j === 0) {
          result[j] += 1;
          cur = cur / j;
        }
      }
    }
    return result;
  }

  function findLargerThan(num, array) {
    return array.filter(element => element >= num).length;
  }

  function combination(numA, numB) {
    let result = 1;
    for (let i = numA; i > numA - numB; i = i - 1) {
      result = result * i;
    }

    for (let i = numB; i > 0; i = i - 1) {
      result = result / i;
    }
    return result;
  }

  let result = resolve(N);

  let l74 = findLargerThan(74, result);
  let l24 = findLargerThan(24, result);
  let l14 = findLargerThan(14, result);
  let l4 = findLargerThan(4, result);
  let l2 = findLargerThan(2, result);

  let r5x5x3 = (l4 * (l4 - 1) * (l2 - 2)) / 2;
  let r15x5 = l14 * (l4 - 1);
  let r25x3 = l24 * (l2 - 1);
  let r75 = l74;

  console.log(
    l74 + l24 * (l2 - 1) + l14 * (l4 - 1) + (l4 * (l4 - 1) * (l2 - 2)) / 2
  );
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21064
#include <stdio.h>
#include <stdlib.h>

int main()
{
    long long int i,j,k;
    long long int n,a[100],b[100],c[100],point=0;
    scanf("%lld",&n);

    for(i=0; i<n; i++)
    {
        scanf("%lld",&a[i]);
    }
     for(i=0; i<n; i++)
    {
        scanf("%lld",&b[i]);
    }
     for(i=0; i<n-1; i++)
    {
        scanf("%lld",&c[i]);
    }

    for(i=0; i<n; i++)
    {
        if(i==0)
        {
            
            point+=b[a[i]-1];
            // printf("%lld  ",point);
        }else
        {
            if(a[i]==a[i-1]+1)
            {
                point+=c[a[i-1]-1];
            }
            point+=b[a[i]-1];
        }
    }
    
    printf("%lld",point);
    
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> pair_t;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = 1 << 29;
/****** define constant end ********/

/****** define variable start ******/
ll A, B, M;
vl a, b, x, y, c;
/******* define variable end *******/
ll solve()
{
    cin >> A >> B >> M;
    a.resize(A);
    b.resize(B);
    x.resize(M);
    y.resize(M);
    c.resize(M);
    ll a_min = 10000000;
    ll b_min = 10000000;
    REP(i, A)
    {
        cin >> a[i];
        if (a[i] < a_min)
        {
            a_min = a[i];
        }
    }
    REP(i, B)
    {
        cin >> b[i];
        if (b[i] < b_min)
        {
            b_min = b[i];
        }
    }
    ll ans = a_min + b_min;
    REP(i, M)
    {
        cin >> x[i] >> y[i] >> c[i];
    }
    REP(i, M)
    {
        ll cost = a[x[i] - 1] + b[y[i] - 1] - c[i];
        if (cost < ans)
        {
            ans = cost;
        }
    }
    cout << ans << endl;
    return 0;
}
int main()
{
    //clock_t start = clock();
    cout << std::fixed << std::setprecision(10);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll end_solve = solve();
    /*
    clock_t end = clock();
    const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    printf("time %lf[ms]\n", time);
    */

    return (int)end_solve;
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<string.h>
#include<math.h>

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

    int a[n];

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

    long sum=0;
    for(int i=1; i<n; i++){
        if(a[i]<a[i-1]){
            sum+=a[i-1]-a[i];
            a[i]=a[i-1];
        }
    }
    if(n==1)printf("0");
    else printf("%ld",sum);
    
}

Measured memory_bytes: 2504
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#if defined(DAIJOBU)
#include "/home/ichigo/includes.hpp"
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long lint;
typedef vector<lint> vlint;
typedef vector<vlint> vvlint;
typedef pair<lint, lint> plint;
typedef double ld;

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



int main() {
    ios::sync_with_stdio(false);
	cin.tie(0);
	
	int a, b;
	cin >> a >> b;
	cout << (b - 1) / (a - 1) + bool((b - 1) % (a - 1)) << '\n';
	return 0;
}


Measured memory_bytes: 256
// Problem : D - Friends
// Contest : AtCoder - AtCoder Beginner Contest 177
// URL : https://atcoder.jp/contests/abc177/tasks/abc177_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)


#include<bits/stdc++.h>
#define 	ll		    long long
#define 	rep(i,a,n)  for(int i=a;i<n;i++)
#define 	MOD 		1000000007
#define 	vp 			vector<pair<int,int> >
#define 	ff 			first
#define 	ss 			second
#define 	pb 			push_back
#define 	all(x) 		(x).begin(),(x).end()
#define 	dg(x)		cerr<<"--- x = "<<x<<"\n"
#define 	endl		"\n"


using namespace std;
const int N = 2e5 + 5; 

int parent[N];
int sz[N];

void uni(int i, int j){
	
	/*while(parent[i] != i){
		parent[i] = parent[parent[i]];
		i = parent[i];
	}
	while(parent[j] != j){
		parent[j] = parent[parent[j]];
		j = parent[j];
	}*/
	
	if(sz[i] >= sz[j]){
		
		parent[j] = parent[i];
		sz[i] += sz[j];
		
	}
	else{
		parent[i] = parent[j];
		sz[j] += sz[i];
	}
}

bool find(int &i, int &j){
	
	while(parent[i] != i){
		parent[i] = parent[parent[i]];
		i = parent[i];
	}
	while(parent[j] != j){
		parent[j] = parent[parent[j]];
		j = parent[j];
	}
	if(i == j)
		return true;
	return false;
}

void init(){
	
	rep(i, 1, N){
		parent[i] = i;
		sz[i] = 1;
	}
	
}

void solve(){
	int n, m; cin >> n >> m;
	init();
	
	rep(i, 1, m + 1){
		
		int x, y; cin >> x >> y;
		if(!find(x, y)){
			uni(x,y);
			cerr << false << endl;
		}
		
	}
	int ans = 0;
	rep(i, 1, n + 1)
		ans = max(ans, sz[i]);
	cout << ans;
		
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
        cout<<endl;
    }
}


Measured memory_bytes: 5208
n = int(input())
ls = list(map(int,input().strip().split()))
maxi = 10**18
ans = 1
zc = ls.count(0)
if zc>0: print(0)
else:
    for val in ls:
        ans *=val
        if ans>maxi:
            ans = -1
            break
    print(ans)

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

int main(){
    ll n;
    cin >> n;
    ll a[n];
    for(ll i = 0; i < n; i++) cin >> a[i];
    ll ans = 0;
    for(ll i = 0; i < n-1; i++){
        for(ll j = i+1; j < n; j++){
            ans += (a[i]* a[j]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int n;
        n=sc.nextInt();
        int i=1;
        do{
            int x=i;
                if(i%3==0){
                    System.out.print(" "+i);
                }else{
                    while(true){
                        if(x%10==3){
                            System.out.print(" "+i);
                            break;
                        }
                        x/=10;
                        if(x!=0) continue;
                        else break;
                        }
                    }
                }while(++i<=n);
        System.out.println();
    }
}


Measured memory_bytes: 28936
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> h;
  n = 1;
  while (1) {
    h /= 2;
    ans += n;
    n *= 2;
    if (h == 0) break;
  }
  Cout(ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn=105,INF=0x7FFFFFFF;
int n,q,ans,ansdec=INF;
bool boo[maxn];
int main()
{
	scanf("%d%d",&q,&n);
	for (int i=1,x;i<=n;i++)
	{
		scanf("%d",&x);
		boo[x]=true;
	}
	for (int i=0;i<=101;i++)
		if (!boo[i] && abs(i-q)<ansdec)
		{
			ans=i;
			ansdec=abs(i-q);
		}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 3816
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

ll a[200001];
const int LG = 19;

ll st[200001][LG];

ll rmq(ll l, ll r)
{
	if(r < 0) return 1000000;
	if(l > r) return 1000000;
	int k = 31 - __builtin_clz(r-l);
	return min(st[l][k], st[r - (1<<k) + 1][k]);
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	//freopen("minsum.in","r",stdin);
	int n; cin >> n;
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	for(ll j = 0; j < LG; j++)
	{
		for(ll i = 0; i < n; i++)
		{
			st[i][j] = 1000000;
			if(i + (1<<j) - 1 < n)
			{
				if(j == 0) st[i][j] = a[i];
				else st[i][j] = min(st[i][j-1], st[i + (1<<(j-1))][j-1]);
			}
		}
	}
	//cerr << "OK" << endl;
	ll ans = 0;
	for(int i = 0; i < n; i++)
	{
		int lo = 0; int hi = i - 1;
		int l = i; int r = i;
		while(lo <= hi)
		{
			int mid = (lo+hi)>>1;
			if(rmq(mid, i - 1) < a[i])
			{
				lo = mid + 1;
			}
			else
			{
				l = mid;
				hi = mid - 1;
			}
		}
		lo = i + 1; hi = n - 1;
		r = i;
		while(lo <= hi)
		{
			int mid = (lo+hi)>>1;
			if(rmq(i + 1, mid) <= a[i])
			{
				hi = mid - 1;
			}
			else
			{
				r = mid;
				lo = mid + 1;
			}
		}
		//cerr << l << ' ' << r << '\n';
		ans += ll(a[i])*ll(i-l+1)*ll(r-i+1);
	}
	cout << ans;
}	


Measured memory_bytes: 31488
#include <cstring>
#include <cstdio>

char a[505][505],b[505][505];

int main(){
	int h,w;
	scanf("%d%d\n",&h,&w);
	for (int i=1;i<=h;i++) scanf("%s",a[i]+1);
	memcpy(b,a,sizeof a);
	for (int i=1;i<=h;i++) a[i][1]=b[i][w]='#';
	for (int i=2;i<h;i++)
		for (int j=2;j<w;j++)
			if (i&1) a[i][j]='#';else b[i][j]='#';
	for (int i=1;i<=h;i++) printf("%s\n",a[i]+1);
	printf("\n");
	for (int i=1;i<=h;i++) printf("%s\n",b[i]+1);
}

Measured memory_bytes: 1152
#include <iostream>
#include <cstdio>

using namespace std;

int selsort(int a[],int n){
  int count = 0;
  int j;
  for(int i=0;i<n;i++){
    int minj = i;
    for(j=i;j<n;j++){
      if(a[j]<a[minj])
	minj=j;
    }
    if(minj!=i){
      swap(a[minj],a[i]);
      count++;
    }
  }
  return count;
}
  
  int main() {

  int n;
  int a[100];
  cin >> n;

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

  for(int i=0;i<n;++i){
    if(i>0) cout << " ";
    cout << a[i];
  }
  putchar('\n');

  cout << count << endl;

}

Measured memory_bytes: 1164
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))

lst = [a[0]]
for i in range(1,n):
    lst.append(a[lst[i-1]-1])

    if lst[i]==2:
        break

if 2 in lst:
    print(lst.index(2)+1)
else:
    print(-1)

Measured memory_bytes: 7856
from heapq import heappush, heappop
def dijkstra(graph: list, node: int, start: int) -> list:
    # graph[node] = [(cost, to)]
    inf = float('inf')
    dist = [inf] * node

    dist[start] = 0
    heap = [(0, start)]
    while heap:
        cost, thisNode = heappop(heap)
        for NextCost, NextNode in graph[thisNode]:
            dist_cand = dist[thisNode] + NextCost
            if dist_cand < dist[NextNode]:
                dist[NextNode] = dist_cand
                heappush(heap,(dist[NextNode], NextNode))
    return dist
    # dist = [costs to nodes]

n, m = map(int, input().split())
edge = [[] for _ in range(n)]

for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edge[a].append((1, b))
    edge[b].append((1, a))

dist = dijkstra(edge, n, 0)
if dist[n-1] == 2:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


Measured memory_bytes: 72024
import java.util.*;
import java.lang.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int[] P = new int[N];
		for( int i=0; i<N; i++ ){
			P[i] = sc.nextInt();
		}
		int count = 0;
		int minium = P[0];
		for( int i=0; i<N; i++ ){
			if( P[i]<=minium ){
				minium = P[i];
				count++;
			}
		}
		System.out.println(count);
	}
}


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

int main(){
  int n,m;
  cin >> n >> m;
  char a[n][m];
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      cin >> a[i][j];
    }
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      if(a[i][j]=='.'){
        int count=0;
        if(i!=0){
          if(j!=0){
            if(a[i-1][j-1]=='#'){
              count++;
            }
          }
          if(j!=m-1){
            if(a[i-1][j+1]=='#'){
              count++;
            }
          }
          if(a[i-1][j]=='#'){
            count++;
          }
        }
        if(i!=n-1){
          if(j!=0){
            if(a[i+1][j-1]=='#'){
              count++;
            }
          }
          if(j!=m-1){
            if(a[i+1][j+1]=='#'){
              count++;
            }
          }
          if(a[i+1][j]=='#'){
            count++;
          }
        }
        if(j!=0){
            if(a[i][j-1]=='#'){
              count++;
            }
          }
          if(j!=m-1){
            if(a[i][j+1]=='#'){
              count++;
            }
          }
          if(a[i][j]=='#'){
            count++;
          }
        char c=count+'0';
        a[i][j]=c;
      }
    }
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      cout << a[i][j];
    }
    cout << endl;
  }
}

Measured memory_bytes: 256