akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

int main(){
int r,c,T[101][101];
cin >>r >>c;
for(int i=0;i<r;i++){
for(int j=0;j<c;j++){
cin >> T[i][j];
}
}
for(int i=0;i<=r;i++) T[i][c]=0;
for(int j=0;j<=c;j++) T[r][j]=0;
for(int i=0;i<r;i++){
for(int j=0;j<c;j++){
T[i][c]=T[i][c]+T[i][j];
T[r][j]=T[r][j]+T[i][j];
T[r][c]=T[r][c]+T[i][j];
}
}
for(int i=0;i<=r;i++){
for(int j=0;j<=c;j++){
if(j) cout <<" ";
cout <<T[i][j];
}
cout <<endl;
}
return 0;
}

Measured memory_bytes: 3104
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]

n,ma,mb=map(int,input().split())
abc=[list(map(int,input().split())) for i in range(n)]
# dp=[[[float('inf')]*(400+1) for i in range(400+1)] for j in range(n+1)]
dp=[]
for i in range(n+1):
    tmp=[]
    for j in range(401):
        tmp2=[]
        for k in range(401):
            tmp2.append(float('inf'))
        tmp.append(tmp2)
    dp.append(tmp)
dp[0][0][0]=0
for i in range(n):
    a,b,c=abc[i]
    for j in range(400):
        for k in range(400):
            if dp[i][j][k]!=float('inf'):
                dp[i+1][j+a][k+b]=min(dp[i+1][j+a][k+b],dp[i][j][k]+c)
                dp[i+1][j][k]=min(dp[i+1][j][k],dp[i][j][k])
ans=float('inf')
now=[ma,mb]
while 1:
    a,b=now
    ans=min(ans,dp[n][a][b])
    if a+ma>400 or b+mb>400:
        break
    now=[a+ma,b+mb]
if ans==float('inf'):
    print(-1)
else:
    print(ans)

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<string> vs;
#define fo(i, a, b) for (int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
#define pb push_back
#define all(s) s.begin(), s.end()
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }

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

  if(b <= c || d <= a) cout << 0 << endl;
  else if(b <= d) {
    if(a <= c) {
      cout << b - c << endl;
    } else {
      cout << b - a << endl;
    }
  } else {
    if(a <= c) {
      cout << d - c << endl;
    } else {
      cout << d - a << endl;
    }
  }
  return 0;
}


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

int main(){
	int N;
	cin>>N;
	vector<int> X(N), Y(N);
	for(int i=0;i<N;i++){
		cin>>X[i];
		Y[i] = X[i];
	}
	sort(X.begin(), X.end());

	for(int i=0;i<N;i++){
		if(Y[i] <= X[N/2 - 1]){
			cout<<X[N/2]<<endl;
		}
		else{
			cout<<X[N/2 - 1]<<endl;
		}
	}
}

Measured memory_bytes: 3712
import java.util.Scanner;

public class Main {
	
	static int mod = 1000000007;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		
		char []s = sc.next().toCharArray();
		
		int[]c = new int [27];
		
		for(int i = 0 ; i < n ; i++) {
			int m = (int)(s[i] - 'a');
			c[m]++;
		}
		
		long ans = 1;
		
		for(int i = 0 ; i < 27 ;i++) {
			int temp = c[i] + 1;
			ans = ans * temp % mod;
		}
		
		System.out.println(ans-1);
		
		

	}
	
}


Measured memory_bytes: 26924
#include <cstdio>

int t, sum, c[] = {1, 5, 10, 50, 100, 500};

int main(){
    for(int i = 0; i < 6; i++){
        scanf("%d", &t);

        sum += c[i] * t;
    }

    if(sum >= 1000) printf("1\n");
    else printf("0\n");

    return 0;
}

Measured memory_bytes: 2696
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        _a: String,
        b: chars,
        _c: String,
    }
    println!("A{}C", b[0]);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
 
ll f,n,ar[51],dp[50001][51]; 
 
ll solve(ll i,ll sum)
 {
   if(i==n)
    {
       if(sum%2==f)
        {
           return 1;
        }
        else
         {
            return 0;
         }
    }
    if(dp[sum][i]!=-1)
     {
       return dp[sum][i];
     }
 return dp[sum][i]=solve(i+1,sum+ar[i])+solve(i+1,sum);    
 }
 
int main() {
	// your code goes here
ll i;
cin>>n>>f;
memset(dp,-1,sizeof(dp));
for(i=0;i<n;i++)
 {
   cin>>ar[i]; 
 }
cout<<solve(0,0); 
	return 0;
}

Measured memory_bytes: 20224
import Control.Monad
import Data.List

main = do
  n <- read <$> getLine
  xs <- forM [1..n] $ \t -> do
    read <$> getLine
  putStrLn . show . solve $ xs

solve xs = snd $ foldr (\x (cur,sm) -> if cur == x then (cur,sm) else (x,1+sm)) (-1,0) $ sort xs


Measured memory_bytes: 1020
S = input()[::-1]
rem = [0]*2019

n = 0
d = 1

for s in S:
    n = n%2019 + (int(s)*d)%2019
    tmp = n%2019
    rem[tmp] += 1
    d *= 10
    d %= 2019
    
ans = 0
for i in rem:
    ans += ((i*(i-1))//2)

print(ans+rem[0])

Measured memory_bytes: 9212
/* 	* In the name of GOD 
	* Thanks God */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define F first
#define S second
#define int long long
const int N = 101234;
int a[N], f[N], b[N];

void solve() {
	int n, x, m;
	cin >> n >> x >> m;
	f[x] = 1;
	a[0] = 0;
	b[0] = x;
	int num = 0, s = 0;
	while (true) {
		num++;
	//	cout << a[num] << endl;
		x = ((x * x) % m);
		b[num] = x;
		if (f[x]) {
			s = f[x];
			break;
		}
		f[x] = num + 1;
	}
	s--;
	num--;
	int ans = 0;
	for (int i = 0; i < s; i++)
		ans += b[i];
	a[s] = 0;
	for (int i = s; i <= num; i++) {
		a[i + 1] = a[i] + b[i];
	}
	if (n <= num) {
		ans = 0;
		for (int i = 0; i < n; i++)
			ans += b[i];
		cout << ans;
		return;
	}
	n -= s;
	int t = (num - s + 1);
	ans += (n / t) * a[num + 1];
	ans += a[(n % t) + s];
	cout << ans;
}

int32_t main() {
	int t = 1;
//	cin >> t;
	while (t--) {
		solve();
	}
}


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

int main() {
    string s;
    cin>>s;
    int i = 0;
    while(i < 3 && s[i] == 'R') {
        i++;
    }
    int j = 1;
    while(j < 3 && s[j] == 'R') {
        j++;
    }
    int k = 2;
    while(k < 3 && s[k] == 'R') {
        k++;
    }
    cout<<max(i,max(k-2,j-1));
    return 0;
}


Measured memory_bytes: 3616
/* ex5_3
   moka223711 */

#include <stdio.h>
#define ROW 101
#define COL 101

int main(void){
    int row, col, i, j, br[ROW]={0}, bc[COL]={0};
    char sq[ROW][COL];
    scanf("%d %d", &row, &col);
    for(i = 0; i < row; i++){
        for(j = 0; j < col; j++){
            scanf(" %c", &sq[i][j]);
            if(sq[i][j]=='#'){
                br[i] = 1;
                bc[j] = 1;
            }
        }
    }
    for(i = 0; i < row; i++){
        if(br[i] == 0)
            continue;
        for(j = 0; j < col; j++){
            if(bc[j] == 0)
                continue;
            printf("%c", sq[i][j]);
        }
        printf("\n");
    }
    return 0;
}


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

const int nax = 1e5;
int bad[nax];
struct Edge {
  int s, e;
};
vector<Edge> edges;
vector<int> node[nax];

int done[nax];
vector<pair<int,int>> topo;
void dfs(int p, int par_ei = -1) {
  if (done[p]++) return;
  for (int ei : node[p]) {
    int i = edges[ei].e;
    dfs(i, ei);
  }
  topo.push_back({p, par_ei});
}

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n, m;
  cin >> n >> m;
  while (m--) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    node[a].push_back(edges.size());
    edges.push_back({a,b});
    node[b].push_back(edges.size());
    edges.push_back({b,a});
    bad[a] ^= 1;
  }
  int bads = 0;
  for (int i = 0; i < n; i++)
    bads += bad[i];
  if (bads%2) {
    cout << -1 << endl;
    return 0;
  }
  dfs(0);
  for (auto p : topo) {
    int i = p.first, ei = p.second;
    if (bad[i]) {
      bad[i] ^= 1;
      bad[edges[ei].s] ^= 1;
      swap(edges[ei], edges[ei^1]);
    }
  }
  for (int i = 0; i < edges.size(); i += 2)
    cout << edges[i].s+1 << ' ' << edges[i].e+1 << '\n';
}


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

#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define rev(v) reverse(v.begin(), v.end());
#define io() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); srand(time(NULL));
#define check cout<<"?\n";
 
using namespace std;

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

signed main(){
    io();
    int n; cin >> n;
    vector<int> v, ans;
    for(int i = 0, x; i < n - 1; ++i){
        cin >> x;
        v.push_back(x);
    }   
    v.push_back(INT_MAX);
    ans.push_back(v[0]);
    for(int i = 0; i < v.size() - 1; ++i){
        ans.push_back(min(v[i], v[i + 1]));
    }
    int a = 0;
    for(auto &x : ans){
        a += x;
    }
    return cout << a << '\n', 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <vector>
int main()
{
    int N;
    std::cin >> N;
    std::vector<int> h(N);
    for (int i = 0; i < N; i++) { std::cin >> h[i]; }
    constexpr int INF = 1 << 30;
    std::vector<int> dp(N, INF);
    dp[0] = 0;
    for (int i = 1; i < N; i++) {
        dp[i] = dp[i - 1] + std::abs(h[i] - h[i - 1]);
        if (i >= 2) { dp[i] = std::min(dp[i], dp[i - 2] + std::abs(h[i] - h[i - 2])); }
    }
    std::cout << dp[N - 1] << std::endl;
    return 0;
}


Measured memory_bytes: 1024
A, B, C, D = map(int, input().split())

import math

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return int(a/gcd(a, b)*b)

def myfunc(x, div1, div2):
    div3 = lcm(div1, div2)
    return x-x//div1-x//div2+x//div3

print(myfunc(B, C, D)-myfunc(A-1, C, D))

Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		List<Integer> list = new ArrayList<>();

		for(int i = 0; i < 3; i++) {
			int tmp = sc.nextInt();
			list.add(tmp);
		}

		if(isPoor(list)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

	static boolean isPoor(List<Integer> list) {
		list.sort(null);

		int A = list.get(0);
		int B = list.get(1);
		int C = list.get(2);

		if(A == B) {
			if(B != C) {
				return true;
			}
		} else {
			if(B == C) {
				return true;
			}
		}
		return false;
	}

}


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

main() {
    string S; cin >> S;
    int a=(S[5]-'0')*10+(S[6]-'0');
    if(a>=5) cout << "TBD" << endl;
    else cout << "Heisei" << endl; 

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define INF int(1e9)
#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for(ll i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = int(1e5);
ll N;
unordered_map<ll, ll> mp;


void solve() {
    ll ans = 1;
    REP(i, N / 2) {
        ans *= 2;
        ans %= ll(1e9 + 7);
    }
    cout << ans << endl;
}

int main() {
    cin >> N;
    ll temp;
    REP(i, N) {
        cin >> temp;
        mp[temp]++;
        if (mp[temp] > 2 || mp[0] == 2) {
            cout << 0 << endl;
            return 0;
        }
    }
    solve();
    return 0;
}

Measured memory_bytes: 2316
N = int(input())
L = list(map(int, input().strip().split()))
L.sort()
ans = 0
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if L[i] != L[j] and L[j] != L[k] and L[i] + L[j] > L[k]:
                ans += 1
print(ans)

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

int main(){
  int x;
  cin>>x;
  cout<<x/500*1000+x%500/5*5<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100005
#define NIL -1

typedef struct
{
  int p,l,r;
}Node;

Node T[MAX];
int n,D[MAX];

void print(int u)
{
  int i,c;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].p);
  printf("depth = %d, ",D[u]);
  if(T[u].p==NIL)printf("root, ");
  else if(T[u].l==NIL)printf("leaf, ");
  else printf("internal node, ");
  printf("[");
  for(i=0,c=T[u].l;c!=NIL;i++,c=T[c].r)
    {
      if(i)printf(", ");
      printf("%d",c);
    }
  printf("]\n");
}
void rec(int u,int p)
{
  D[u]=p;
  if(T[u].r!=NIL)rec(T[u].r,p);
  if(T[u].l!=NIL)rec(T[u].l,p+1);
}

int main()
{
  int i,j,d,v,c,l,r;
  scanf("%d",&n);
  for(i=0;i<n;i++)T[i].p=T[i].l=T[i].r=NIL;
  for(i=0;i<n;i++)
    {
      scanf("%d%d",&v,&d);
      for(j=0;j<d;j++)
	{
	  scanf("%d",&c);
	  if(j==0)T[v].l=c;
	  else T[l].r=c;
	  l=c;
	  T[c].p=v;
	}
    }
  for(i=0;i<n;i++)
    {
      if(T[i].p==NIL)r=i;
    }
  rec(r,0);
  for(i=0;i<n;i++)print(i);
  return 0;
}



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

/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
int main() {
	int n;
	cin >> n;
	vector<int> s;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		s.push_back(a);
	}
	sort(s.begin(), s.end());
	cout << (s[s.size() - 1] - s[0]);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define rep_3(i, initial, n) for (int(i) = (int)(initial); (i) < (int)(n); ++(i))
#define rep(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int(i) = (int)(n); (i) > 0; (i)--)
#define rep_r_3(i, initial, n) for (int(i) = (int)(initial); (i) > (int)(n); (i)--)
#define rep_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define type definition
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int; // 多倍長整数（任意精度）
typedef pair<int, int> P;

// define construct variable
const double EPS = numeric_limits<double>::epsilon();
// 10^9 + 7
const ll MOD = ll(1e9) + 7;
const ll INF = ll(1e10);
const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";
const double PI = acos(-1);

// define methods
// 最大公約数
ll gcd(const ll a, const ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }
// 素因数分解
vector< pair<ll, ll> > prime_factorize(ll n)
{
	vector<pair<ll, ll>> p;
	for (ll i = 2; i * i <= n; i++)
	{
		if ((n % i) != 0)
			continue;
		pair<ll, ll> a = make_pair(i, 0);
		while ((n % i) == 0)
		{
			n /= i;
			a.second += 1;
		}
		p.push_back(a);
	}

	if (n != 1)
		p.push_back(make_pair(n, 1));
	return p;
}
// 組み合わせの整合性を保つ（後ほど解析する）
ll modinv(ll a)
{
	ll b = MOD, u = 1, v = 0;
	while (b)
	{
		ll t = a / b;
		a -= t * b;
		swap(a, b);
		u -= t * v;
		swap(u, v);
	}
	u %= MOD;
	if (u < 0)
	{
		u += MOD;
	}
	return u;
}
// 順列
ll permutation(const ll n, const ll m)
{
	ll result = 1;
	for (ll i = n; i > n - m; i--)
	{
		result = (result * i) % MOD;
	}
	return result;
}

// 繰り返し n 乗法
ll repeat_square(const ll n, const ll x)
{
	if (x == 0)
		return 1;
	ll res = repeat_square(n, x / 2);
	res = res * res % MOD;
	if ((x % 2) == 1)
		res = res * n % MOD;
	return res;
}
// 組み合わせ nCm
ll combination(ll n, ll m)
{
	ll p = permutation(n, m);
	ll div = 1;
	for (ll i = 2; i <= m; i++)
	{
		div = (div * i) % MOD;
	}
	return (p * modinv(div)) % MOD;
}

int main() {
	int H, W;
	cin >> H >> W;
	vector<string> n(H);
	rep(i, H) cin >>n[i];

	P prev = make_pair(0, 0);
	rep(i, H) rep(j, W) {
		string m = n[i].substr(j, 1);
		if (m == ".") continue;
		// cout << "n: " << n[i][j] << endl;

		// r & b
		if ((i+1) < H && (j+1) < W) {
			if (m == n[i+1].substr(j, 1) && m == n[i].substr(j+1, 1)) {
				cout << "Impossible" << endl;
				return 0;
			}
		}
		// l
		if (i > 0) {
			if (m == n[i-1].substr(j, 1) && make_pair(i-1, j) != prev) {
				cout << "Impossible" << endl;
				return 0;
			}
		}
		// t
		if (j > 0) {
			if (m == n[i].substr(j-1, 1) && make_pair(i, j-1) != prev) {
				cout << "Impossible" << endl;
				return 0;
			}
		}

		if (m == "#") prev = make_pair(i, j);
	}

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


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

using namespace std;

set<int> s;

bool check(int n){
    while(n){
        if(s.count(n%10)){
            return false;
        }
        n/=10;
    }    
    return true;
}

int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, k;
    cin >> n >> k;


    int x;

    for(int i=0;i<k;++i){
        cin >> x;
        s.insert(x);
    }

    while(1){
        if(check(n)){
            cout << n << '\n';
            break;
        }
        n++;
    }

    return 0;
}

Measured memory_bytes: 256
while num = gets.split(" ").map(&:to_i) do
  if(num[0] == 0 && num[1] == 0) then
    exit
  end
  for i in 1..num[0] do
    for j in 1..num[1] do
      if (i + j) % 2 == 0 then
        printf "#"
      else
        printf "."
      end
    end
    printf "\n"
  end
  printf "\n"
end

Measured memory_bytes: 8760
import sys
def input():
	return sys.stdin.readline().strip()




class Union_Find():
	def __init__(self, n):
		self.union = [i for i in range(n)]
		self.level = [0 for i in range(n)]

	def root(self, i, mode=0):
		keiro = [i]
		ans = i
		while ans != self.union[ans]:
			ans = self.union[ans]
			keiro.append(ans)
		if mode == 0:
			return ans
		else:
			return ans, keiro

	def unite(self, i, j):
		root_i, list_i = self.root(i, 1)
		root_j, list_j = self.root(j, 1)
		if root_i != root_j:
			if self.level[root_i] < self.level[root_j]:
				self.level[root_j] = max(self.level[root_i] + 1, self.level[root_j])
				for node in list_i:
					self.union[node] = root_j
			else:
				self.level[root_i] = max(self.level[root_j] + 1, self.level[root_i])
				for node in list_j:
					self.union[node] = root_i

N, K, L = list(map(int, input().split()))

UF_road = Union_Find(N)
UF_train = Union_Find(N)
for i in range(K):
	p, q = list(map(int, input().split()))
	p -= 1
	q -= 1
	UF_road.unite(p,q)
for i in range(L):
	p, q = list(map(int, input().split()))
	p -= 1
	q -= 1
	UF_train.unite(p,q)

group = []
for i in range(N):
	group.append([UF_road.root(i), UF_train.root(i), i])
group.append([100000000,0,0])
group.sort()
X = group[0][0:2]
town = [group[0][2]]
number = [-1 for i in range(N)]
for i in range(1, N + 1):
	if X != group[i][0:2]:
		num = len(town)
		for j in town:
			number[j] = num
		town = [group[i][2]]
	else:
		town.append(group[i][2])
	X = group[i][0:2]


def list_print(A):
	length = len(A)
	for i in range(length - 1):
		print(A[i], end="")
		print(" ", end="")
	print(A[N - 1])

list_print(number)

Measured memory_bytes: 124876
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int x,y;
    int n;
    cin >> n;
    cin >> x >> y;
    map<int,int> mp;
    vector<vector<int>> v(n);
    for(int i=0;i<n-1;i++){
        v[i].push_back(i+1);
        v[i+1].push_back(i);
    }
    v[x-1].push_back(y-1);
    v[y-1].push_back(x-1);
    for(int i = 0;i<n;i++){
        vector<int> dp(n,1e9);
        dp[i] = 0;
        queue<int> que;
        que.push(i);
        while(!que.empty()){
            int it = que.front();
            int d = dp[it];
            que.pop();
            for(auto i:v[it]){
                if(dp[i]>d+1){
                    dp[i] = d+1;
                    que.push(i);
                }
            }
        }
        for(int j = 0;j<n;j++){
            mp[dp[j]]++;
        }
    }
    for(int i = 1;i<n;i++){
        cout << mp[i]/2 << endl;
    }
    return 0;
}

Measured memory_bytes: 512
x = int(input())

if 400 <= x <= 599:
	print(8)
elif 600 <= x <= 799:
  	print(7)
elif 800 <= x <= 999:
  	print(6)
elif 1000 <= x <= 1199:
  	print(5)
elif 1200 <= x <= 1399:
  	print(4)
elif 1400 <= x <= 1599:
  	print(3)
elif 1600 <= x <= 1799:
  	print(2)
elif 1800 <= x <= 1999:
  	print(1)

Measured memory_bytes: 9188
#include<iostream>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<math.h>
using namespace std;
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; }
long long inf=100000000000000;
int main(){
  int n,W;
  cin >> n >> W;
  long long w[110],v[110];
  int i;
  for(i=0;i<n;i++){
    cin >> w[i] >> v[i];
  }
  long long dp[105][100005]={0};
  int lw=0;
  for(i=0;i<n;i++){
    for(lw=0;lw<=W;lw++){
      if(lw>=w[i]){ // ピックする場合 //
        chmax(dp[i+1][lw],dp[i][lw-w[i]]+v[i]);
      }
      chmax(dp[i+1][lw],dp[i][lw]); //　しない場合 //
    }
  }
  cout << dp[n][W];
}

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

tlist=[]
for i in range(N):
    tlist.append([A[i],i])
tlist.sort()

tmp=[]
for i in range(N):
    tmp.append(str(tlist[i][1]+1) )
print(' '.join(tmp))

Measured memory_bytes: 28516
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            TaskD.Vertex[] vs = new TaskD.Vertex[n];
            for (int i = 0; i < n; ++i) vs[i] = new TaskD.Vertex();
            for (int i = 0; i < n - 1; ++i) {
                TaskD.Vertex x = vs[in.nextInt() - 1];
                TaskD.Vertex y = vs[in.nextInt() - 1];
                x.adj.add(y);
                y.adj.add(x);
            }
            int z = vs[0].solve(null);
            if (z == 0) {
                out.println("Bob");
            } else {
                out.println("Alice");
            }
        }

        static class Vertex {
            List<TaskD.Vertex> adj = new ArrayList<>();

            public int solve(TaskD.Vertex parent) {
                int res = 0;
                for (TaskD.Vertex v : adj)
                    if (v != parent) {
                        res ^= 1 + v.solve(this);
                    }
                return res;
            }

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 62748
#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

typedef pair<int,int> P;

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

int D(int x1, int y1, int x2, int y2 ){
	return (x1-x2) * (x1-x2) + (y1-y2) * (y1-y2) ;
}

int main(){
	int AN, BN, R;
	while( scanf("%d %d %d", &AN, &BN , &R ), AN || BN ){
		int AX[100001], AY[100001];
		vector<P> m[250][250];
		int ans=0;

		for(int i=0 ; i < AN ; i++ ){
			scanf("%d %d", &AX[i], &AY[i]);
		}
		for(int i=0 ; i < BN ; i++ ){
			int x, y;
			scanf("%d %d", &x, &y );
			P p(x,y);
			m[y/40][x/40].push_back( p );
		}
		for(int i=0 ; i < AN ; i++ ){
			int ax = AX[i];
			int ay = AY[i];

			for(int j=0 ; j < 9 ; j++ ){
				int mx = ax/40 + dx[j];
				int my = ay/40 + dy[j];
				if( mx < 0 || my < 0 || mx >= 250 || my >= 250 ) continue;
				vector<P> B = m[my][mx];
				for(int k=0 ; k < B.size() ; k++ ){
					int bx = B[k].first;
					int by = B[k].second;
					if( D(ax,ay,bx,by) <= 16*R*R ){
						ans++;
					}
				}
			}
		}
		printf("%d\n", ans );
	}
}

Measured memory_bytes: 3348
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
//#include <intrin.h>

#define fore(i,a,b) for(int i = a; i < (b); i++)
#define fr(i,a,b) for(int i = a; i >= b; i--)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define __builtin_popcount __popcnt
#define N 200005
#define FH 400005
#define inf INT32_MAX
#define MOD 1000000007LL

using namespace std;
typedef long long ll;
typedef pair<int, int> pr;


inline void solve()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	if (n % 2)
	{
		cout << "No";
		return;
	}
	fore(i, 0, n/2)
	{
		if (s[i] != s[i + n / 2])
		{
			cout << "No";
			return;
		}
	}
	cout << "Yes";
}



int main()
{
	fast;
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	solve();
}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

vector<int> v;

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

    int N;
    std::cin >> N;

    v.resize(N);

    for(int i=0;i<N;++i){
        std::cin >> v[i];
    }

    sort(v.begin(), v.end());

    int pr = -1, n = 0;
    for(int i=0;i<N;++i){
        if(pr < v[i]){
            pr = v[i];
            ++n;
        }
    }

    std::cout << n << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int MOD = 1000000007;

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

    bool yes = (N % 10) == 7;
    N /= 10;
    yes |= (N % 10) == 7;
    N /= 10;
    yes |= (N % 10) == 7;

    cout << (yes ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
typedef map<string,int> msi; typedef long long ll;
int N; ll ans; string s; msi m;
int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin>>N; while (N--) {
        cin>>s; sort(s.begin(),s.end());
        ans+=m[s]; m[s]++;
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 11264
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define forn(a,b,c) for(int a=b;a<=c;a++)
#define ford(a,b,c) for(int a=b;a>=c;a--)
#define f first
#define s second
typedef pair<int,int> pii;
const int N=1e5+5;
const int mod=998244353;
const ll inf=1e18+7;
int n,m,deg[N],dep[N];bool vis[N];
vector<int>g[N];stack<int>st;
void dfs(int x){
    vis[x]=true;
    for(auto&y:g[x]){
        if(!vis[y])
            dfs(y);
    }
    st.push(x);
}
int main()
{
    scanf("%d%d",&n,&m);
    forn(i,1,m){
        int x,y;
        scanf("%d%d",&x,&y);
        g[x].pb(y);
    }
    forn(i,1,n){
        if(!vis[i]){
            dfs(i);
        }
    }
    while(!st.empty()){
        int x=st.top();
        st.pop();
        for(auto&y:g[x]){
            dep[y]=max(dep[y],dep[x]+1);
        }
    }
    int mx=0;
    forn(i,1,n){
        //printf("dep[%d]:%d\n",i,dep[i]);
        mx=max(mx,dep[i]);
    }
    printf("%d\n",mx);
    return 0;
}


Measured memory_bytes: 8704
# pragma GCC optimize("O3")
# include <bits/stdc++.h>
# define maxn 100005
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define sz(x) (int)((x).size())
//# define int ll
using namespace std;

ll n,x,a,b,c;

int32_t main(){_
    //freopen("input","r",stdin);
	cin >> n;
	for(int i = 1;i <= n;i++)
	{
		cin >> x;
		if(x % 4 == 0) a++;
		else if(x % 2 == 0) b++;
		else c++;
	}
	if(c - 1 > a) rc("No");
	if(c - 1 == a) rc((b ? "No" : "Yes"));
	rc("Yes");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 11116
#define mod 998244353

int n,x,y,f[N][N],ans;
char a[N],b[N];
long long fac[N],inv[N];

long long C(int x,int y){
	return fac[x]*inv[y]%mod*inv[x-y]%mod;
}

int read(){
	int x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

int main(){
	scanf(" %s %s",a,b);n=strlen(a);
	for (int i=0;i<n;i++)
		if (a[i]=='1')
		(b[i]=='0')?x++:y++;
	fac[0]=fac[1]=inv[0]=inv[1]=1;
	for (int i=2;i<N;i++) fac[i]=fac[i-1]*i%mod;
	for (int i=2;i<N;i++) inv[i]=-(mod/i)*inv[mod%i]%mod;
	for (int i=2;i<N;i++) inv[i]=inv[i-1]*inv[i]%mod;
	for (int i=0;i<=x;i++) f[i][0]=fac[i]*fac[i]%mod;
	for (int i=1;i<=x;i++)
		for (int j=1;j<=y;j++)
			f[i][j]=(1ll*f[i-1][j]*i*i+1ll*f[i][j-1]*i*j)%mod;
	for (int i=0;i<=y;i++)
		ans=(ans+1ll*f[x][y-i]*fac[i]%mod*fac[i]%mod*C(y,i)%mod*C(x+y,i))%mod;
	printf("%d\n",(ans+mod)%mod);
	return 0;
}

Measured memory_bytes: 217728
#include<iostream>
#include<vector>
#include<set>
#include<bits/stdc++.h>

using namespace std;
void st(set< vector<int> >&s,vector<int> &ns,vector<int> temp)
    {
        if(temp.size()>=ns.size())
            return;
        for(int i=0;i<ns.size();i++)
        {
            if(temp.size()==0)
            {
                temp.push_back(ns[i]);
                s.insert(temp);
                st(s,ns,temp);
                temp.pop_back();
            }
            else
            {
                if(ns[i]>temp[temp.size()-1])
                {
                    temp.push_back(ns[i]);
                    s.insert(temp);
                    st(s,ns,temp);
                    temp.pop_back();
                }
            }
        }
    }

int main(){
    int n, m, x;
    cin >> n >> m >> x;
    vector<vector<int>> a(n, vector<int>(m));
    vector<int> c(n);
    for(int i = 0; i < n; i++){
        cin >> c[i];
        for(int j = 0; j < m; j++)cin >> a[i][j];
    }
    set<vector<int> >s;
    vector<int> temp;
    vector<int> ns;
    for(int i=0;i<n;i++)
    ns.push_back(i);
    st(s,ns,temp);
     int ans = 12345678;
    vector< vector<int> >v1;
    for(auto &i:s)
      v1.push_back(i);
     for(int i=0;i<v1.size();i++)
     {
         vector<int> level(m);
         int cost=0;
         for(int j=0;j<v1[i].size();j++)
         {
             int pos=v1[i][j];
             cost+=c[pos];
             for(int k=0;k<m;k++)
             {
                 level[k]+=a[pos][k];
             }
         }
         bool ok=true;
         for(int k=0;k<m;k++)
            {
                if(level[k]<x)
                {
                    ok=false;
                break;
                }
            }
            if(ok)
             ans=min(cost,ans);
     }
      if(ans == 12345678) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}
    
    
    
    
    
    
    
    
    
    
    
    
    
   

Measured memory_bytes: 4276
H, W, M = map(int,input().split())
R = [0] * H
C = [0] * W

L = []

for _ in range(M):
    h, w = map(int,input().split())
    R[h-1] += 1
    C[w-1] += 1
    L.append([h-1, w-1])

r = max(R)
c = max(C)

print(r + c - (R.count(r) * C.count(c) == sum(R[h] + C[w] == r + c for h, w in L)))

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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int a,b,c;
	cin >> a >> b >> c;
	set<int> s;
	s.insert(a);
	s.insert(b);
	s.insert(c);
	cout << s.size() << "\n";
	return 0;
}


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

int main()
{
   
   ll coins;
   cin>>coins;
   ll fiv=coins/500;
   ll ans=0;
    ans+=fiv*1000;
    coins-=fiv*500;
    fiv=coins/5;
    ans+=fiv*5;
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int x = input.nextInt();
        int count = 1;
        
        while (x != 0) {
            System.out.println("Case " + count + ": " + x);
            x = input.nextInt();
            count++;
        }
    }
}


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

int n;
vector<int> x, y;
vector<int> viewed;

double dist(int a, int b){
    return sqrt((x[a]-x[b])*(x[a]-x[b]) + (y[a]-y[b])*(y[a]-y[b]));
}

bool dfs(int v, double t, int c){
    if(c == n) return true;

    for(int i=0;i<n;i++){
        if(viewed[i]) continue;
        if(t + dist(v, i) >= dist(i, n+1)) return false;
    }

    for(int i=0;i<n;i++){
        if(viewed[i]) continue;
        double nt = t + dist(v, i);
        if(nt < dist(i, n+1)){
            viewed[i] = true;
            if(dfs(i, nt, c+1)) return true;
            viewed[i] = false;
        }
    }

    return false;
}

int main(){
    while(1){
        cin >> n;
        if(n == 0) break;
        x.assign(n+2, 0);
        y.assign(n+2, 0);
        cin >> x[n] >> y[n] >> x[n+1] >> y[n+1];
        for(int i=0;i<n;i++){
            cin >> x[i] >> y[i];
        }
        viewed.assign(n, 0);
        if(dfs(n, 0, 0)){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1188
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"

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

	int a;
	cin>>a;
	int n=(a+3)/4*2;
	vvi out(n,vi(n));
	rep(i,n)rep(j,n)
		out[i][j]=(i+j)%n+1+(j%2&&(i+j)%n+1<=a-n?n:0);
	
	if(a==1)out=vvi(2,vi(2,1));
	cout<<n<<endl;
	show2d(out);
}






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

string s, t;
long long ssize, tsize;
vector<long long> v[26];

long long solve();

int main() {
  cin >> s >> t;
  ssize = s.size();
  tsize = t.size();
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long cnt = 0, now = -1;
  for(int i = 0; i < ssize; ++i) v[s[i] - 'a'].push_back(i);
  for(int i = 0; i < tsize; ++i) {
    long long nc = t[i] - 'a';
    if(v[nc].size() == 0) return -1;
    auto it = upper_bound(v[nc].begin(), v[nc].end(), now);
    if(it == v[nc].end()) ++cnt, it = v[nc].begin();
    now = *it;
  }
  return cnt * ssize + 1 + now;
}

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

int main() {
	int a,b;
  scanf("%d%d",&a,&b);
        int x=b,y=a,a1=a,b1=b;
  while(x!=1)
        {
          a=a*10+a1;
          --x;
        }
         while(y!=1)
        {
          b=b*10+b1;
          --y;
        }
        int m=max(a,b);
        printf("%d",m);
	return 0;
}


Measured memory_bytes: 3752
#include <cstdio>

using namespace std;

const int N=510;

int n,x[N],a[N*N];
bool use[N];

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

void Solve()
{
	bool fl=1;
	for (int i=1;i<=n*n && fl;++i)
		if (a[i] && !use[a[i]])
		{
			use[a[i]]=1;
			int cnt=a[i]-1;
			for (int j=1;j<i && cnt;++j)
				if (!a[j])
				{
					a[j]=a[i];
					cnt--;
				}
			if (cnt) fl=0;
		}
	for (int i=1;i<=n;++i) use[i]=0;
	for (int i=n*n;i>=1 && fl;--i)
		if (a[i] && !use[a[i]])
		{
			use[a[i]]=1;
			int cnt=n-a[i];
			for (int j=n*n;j>i && cnt;--j)
				if (!a[j])
				{
					a[j]=a[i];
					cnt--;
				}
			if (cnt) fl=0;
		}
	if (!fl) printf("No\n");
	else 
	{
		printf("Yes\n");
		for (int i=1;i<=n*n;++i)
			printf("%d%c",a[i],i==n*n?'\n':' ');
	}
}

int main()
{
	Init();
	Solve();
	return 0;
}

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

void bubbleSort(int a[],int n){
    int c=0;
    for(int i=0;i<n;i++){
        for(int j=n-1;j>i;j--){
            if(a[j-1]>a[j]){
                swap(a[j-1],a[j]);
                c++;
            }
        }
    }
    for(int i=0;i<n;i++) cout<<a[i]<<((i==n-1)?'\n':' ');
    cout<<c<<endl;
}

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


Measured memory_bytes: 3116
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

vector<int> a;
vector<ll> s, r;
constexpr ll NA = 1LL << 60;

ll solve(int n) {
    if (n == 1) return 0;
    if (n == 2) return max(a[0], a[1]);
    if (r[n] != NA) return r[n];

    ll t = solve(n - 2) + a[n - 1];
    if (n % 2 == 0) {
        t = max(t, s[n]);
    } else {
        t = max(t, solve(n - 1));
    }
    return r[n] = t;
}

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

    int n;
    cin >> n;

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

    s.assign(n + 2, 0);
    for (int i = 0; i < n; i += 2) {
        s[i + 2] = s[i] + a[i];
    }

    r.assign(n + 1, NA);

    cout << solve(n) << endl;

    return 0;
}

Measured memory_bytes: 10268
/*Author - Shubham Gupta (@shubham107)*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;      typedef vector<int> vi;
typedef vector<vl> vvl;     typedef vector<vi> vvi;
typedef pair<ll, ll> pll;   typedef pair<int, int> pii;
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define INF ll(1e18)
#ifdef SHUBHAM107
#include "../trace.h"
#else
#define trace(args...)
#endif
void solve() {
    int n, x, cnt = 0;
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> x;
        if(i & 1) {
            if(x & 1)
                cnt++;
        }
    }
    cout << cnt;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifdef SHUBHAM107
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("err.txt", "w", stderr);
#endif
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}


Measured memory_bytes: 3608
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#define INF INT_MAX
using namespace std;

int D;

int main(){
	cin >> D;
	if (D == 25)cout << "Christmas" << endl;
	else if (D == 24)cout << "Christmas Eve" << endl;
	else if (D == 23)cout << "Christmas Eve Eve" << endl;
	else if (D == 22)cout << "Christmas Eve Eve Eve" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define read freopen("input.txt","r",stdin);
#define write freopen("out.txt","w",stdout);
#define endl "\n"
using namespace std;
const double pi = 2 * acos(0.0);
using ll = long long;
using ull = unsigned long long;
template <typename T> inline T gcd (T a, T b) {return a % b == 0 ? b : gcd(b, a%b);}
template <typename Y> inline Y lcm (Y a, Y b) {return (a / gcd(a, b)) * b;}

vector <int> v{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};


int main() {
	fast;
	int n;
	cin >> n;
	cout << v[--n] << endl;
	
}

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

template<typename T> void chmin(T &a,T b){if(a>b) a=b;}
template<typename T> void chmax(T &a,T b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  using P = pair<Int, Int>;
  vector<P> v;
  for(Int i=0;i<n;i++){
    Int a,b;
    cin>>a>>b;
    v.emplace_back(a,b);
  }
  sort(v.begin(),v.end());

  vector<Int> a,b;
  for(Int i=0;i<n;i++){
    if(a.empty()||a.back()!=v[i].first){
      a.emplace_back(v[i].first);
      b.emplace_back(v[i].second);
    }else{
      b.back()+=v[i].second;
    }  
  }

  //for(Int i=0;i<n;i++) cout<<i<<":"<<a[i]<<" "<<b[i]<<endl;

  vector<Int> c(b.size());
  partial_sum(b.begin(),b.end(),c.begin());

  // [l,r]
  auto get=[&](Int l,Int r){
    if(l) return c[r]-c[l-1];
    return c[r];
  };

  if(0){
    Int ans=0;
    for(Int i=0;i<(Int)a.size();i++)
      for(Int j=i;j<(Int)a.size();j++)
	chmax(ans,get(i,j)-(a[j]-a[i]));
    
    cout<<ans<<endl;
  }
  
  Int ans=0,l=0,r=0;
  for(Int i=0;i<(Int)a.size();i++){
    while(l<i&&a[l+1]-a[l]>=b[l]) l++;
    chmax(ans,get(l,i)-(a[i]-a[l]));
    
    chmax(r,l);
    while(r+1<i){
      while(r+1<i&&a[r+1]-a[l]<=get(l,r)) r++;
      if(a[r+1]-a[l]>=get(l,r)) l=r+1;
      else break;
    }
    chmax(ans,get(l,i)-(a[i]-a[l]));
  }
  
  cout<<ans<<endl;
  
  return 0;
}



Measured memory_bytes: 23852
N,Y=map(int,input().split())
flag=False
for i in range(min(Y//10000,N)+1):
    if flag:
        break
    for j in range(min((Y-i*10000)//5000,N-i)+1):
        if (Y-i*10000-j*5000)%1000==0 and i+j+(Y-i*10000-j*5000)//1000==N:
            print(" ".join(map(str,[i,j,N-i-j])))
            flag=True
            break
if not flag:
    print("-1 -1 -1")

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

int N;
vector<int> A(210);

int main() {
  cin>>N;
  for(int i=0;i<N;i++) cin>>A.at(i);
  int count=0;
  
  while(true){
    bool exist_odd=false;
    for(int i=0;i<N;i++){
      if(A.at(i)%2!=0) exist_odd=true;
    }
    
    if(exist_odd) break;
    
    for(int i=0;i<N;i++){
     A.at(i)/=2;
    }
    count++;
  }
  
  cout<<count<<endl;
  return 0;
}

Measured memory_bytes: 3588
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
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 a;

void solve(){
    cin >> a;
    cout << 1-a << endl;
}

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

Measured memory_bytes: 3608