akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll inf=1e18;
const ll mod=1e9+7;
const ll maxn=1e5;
bool srts(const pair<ll,ll> &a, 
              const pair<ll,ll> &b) 
{ 
    //if(a.second==b.second)return a.first>b.first;
    if(a.first==b.first)return a.second>b.second;
    return (a.first > b.first); 
}
ll add(ll a,ll b){
    return ((a%mod)+(b%mod))%mod;
}
ll mul(ll a,ll b){
    return ((a%mod)*(b%mod))%mod;
}
ll powm(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}
int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); 
    ll n,k;
    cin>>n>>k;
    set<ll>s;
    for(int i=k-n+1;i<=k+n-1;i++)cout<<i<<" ";

    return 0;
}

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

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


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

#define max(a,b) ((a) > (b) ? (a) : (b))
int get_int(char *line, int size) {
  if(!fgets(line, size, stdin)) return 0;
  int num;
  sscanf(line, "%d", &num);
  return num;
}

static char table[256] = {
  ['A'] = 1,
  ['T'] = 1,
  ['G'] = 1,
  ['C'] = 1,
};

#define buf_size 53
int main(void) {

  char buf[buf_size];
  int i, j;
  char *s;
  int cnt = 0;
  int ans = 0;
  if(fgets(buf, buf_size, stdin) == NULL) return 0;

  for(s = buf; *s != '\n'; s++) {
    cnt = table[*s] ? cnt + 1 : 0;
    ans = max(ans, cnt);
  }

  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define test() ll t;cin>>t;while(t--)
#define MOD 1000000007
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

int main() {
    SPEED;
    //CODE
	ll k,n;
	cin>>k>>n;
	ll a[n];
	for(ll i=0;i<n;i++) cin>>a[i];
	ll ans=a[n-1]-a[0];
	for(ll i=1;i<n;i++){
		ans=min(ans,a[i-1]-a[i]+k);
	}
	cout<<ans;
	return 0;
}

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

using namespace std;

typedef long long ll;
ll calc(ll x) {
	switch (x & 3) {
		case 0: return x;
		case 1: return 1;
		case 2: return x + 1;
		case 3: return 0;
	}
	return -1;
}

int main() {
	ll a, b;
	cin >> a >> b;
	cout << (calc(b) ^ calc(a - 1));
	return 0;
}


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


class UnionFind {
public:
    vector < ll > par; // 各元の親を表す配列
    vector < ll > siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1);
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main(){
  int n,m;
  cin >> n >> m;
  UnionFind tree(n);
  for(int i=0;i<m;++i){
    int x,y;
    cin >> x >> y;
    x--;
    y--;
    tree.merge(x,y);
  }

  ll ans=0;
  for(ll i=0;i<n;++i){
    ans=max(ans,tree.size(i));
  }
  cout << ans << endl;
  return 0;
}


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

#define int long long 
#define dou  double 
#define endl "\n"

const int MOD=1e9+7;

void solve()
{
	int n,d,x,y,z,cnt=0,i;
	cin >> n >> d;
	for(i=1;i<=n;i++)
	{
		cin >> x >> y;
		double z = sqrt(x*x+y*y);
		if(z<=d)
			cnt++;
	}
	cout << cnt << endl;
}

main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	solve();
}

Measured memory_bytes: 3684
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var n int
	var ns string
	fmt.Scan(&n)
	for i := n; i <= 999; i++ {
		ns = strconv.Itoa(i)
		if strings.Count(ns, ns[0:1]) == 3 {
			fmt.Println(i)
			return
		}
	}
}


Measured memory_bytes: 640
import java.util.*;

public class Main
{
    private final static Main main = new Main();

    public static void main(String[] args)
    {
        main.contest();
    }

    private void contest()
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] list = new int[n];
        for(int i=0; i<n; ++i)
        {
            list[i] = sc.nextInt()-1;
        }
        int count = 0;
        for(int i=0; i<n; ++i)
        {
            int target = list[i];
            if(i == list[target])
            {
                count++;
                list[i] = -1;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 32492
import sys

for s in sys.stdin:
    xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2 = map(float,s.split())
    if xb2 < xa1 or xa2 < xb1: print "NO"
    elif yb2 < ya1 or ya2 < yb1: print "NO"
    else: print "YES"

Measured memory_bytes: 4200
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    def ng():
        print(-1)
        exit()

    n,m=MI()
    ans=[-1]*n
    for _ in range(m):
        s,c=MI()
        s-=1
        if ans[s]==-1 or ans[s]==c:ans[s]=c
        else:ng()
    if n>1 and ans[0]==0:ng()
    for i in range(n):
        if ans[i]==-1:
            if i==0 and n>1:ans[i]=1
            else:ans[i]=0
    print(*ans,sep="")

main()

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "YES" << '\n'; exit(0); }
inline void no() { cout << "NO" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template<typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template<typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template<typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template<typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template<typename T> inline T power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template<typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

vector<int> edges[200010];

void solve() {
  int n, m;
  cin >> n >> m;
  rep(i, n) {
    int k;
    cin >> k;
    rep(j, k) {
      int l;
      cin >> l;
      l += 100000;
      edges[i + 1].push_back(l);
      edges[l].push_back(i + 1);
    }
  }
  vector<bool> visited(200010, false);
  function<void(int)> dfs = [&](int x) {
    if (visited[x]) return;
    visited[x] = true;
    each(v, edges[x]) {
      if (visited[v]) continue;
      dfs(v);
    }
  };
  dfs(1);
  reps(i, n) if (!visited[i]) no();
  yes();
}


Measured memory_bytes: 8832
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
ll gcd(ll a, ll b){
    if(a%b == 0) return(b);
    else return(gcd(b, a%b));
}
ll lcm(ll a, ll b){
    return a*b / gcd(a,b);
}
int main(){
    ll a, b;
    cin >> a >> b;
    cout << lcm(a, b) << endl;
}

Measured memory_bytes: 256
// C++ includes used for precompiling -*- C++ -*-

// Copyright (C) 2003-2013 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// <http://www.gnu.org/licenses/>.

/** @file stdc++.h
 *  This is an implementation file for a precompiled header.
 */

// 17.4.1.2 Headers

// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)

int main()
{

  double w, h, x, y;
  cin >> w >> h >> x >> y;
  double a = h / w, b = y / x;
  int count = 0;
  if (w / 2.0 == x && h / 2.0 == y)
  {
    count = 1;
  }
  printf("%.6f %d\n", (w * h / 2.0), count);

  return 0;
}



Measured memory_bytes: 256
import math

def getDistance( x, y, n, p ):
	dxy = 0
	for i in range( n ):
		dxy += abs( x[i] - y[i] )**p
	return dxy**(1/float( p ) )


n = int( raw_input() )
x = [ float( i ) for i in raw_input( ).split( " " ) ]
y = [ float( i ) for i in raw_input( ).split( " " ) ]
print( getDistance( x, y, n, 1 ) )
print( getDistance( x, y, n, 2 ) )
print( getDistance( x, y, n, 3 ) )
dxy = [ 0 ]*(n+1)
for i in range( n ):
	dxy[i] = abs( x[i] - y[i] )

print( max( dxy ) )

Measured memory_bytes: 4460
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

signed main() {
  ll A, B;
  cin >> A >> B;
  if (A > 9 || B > 9) {
    COUT(-1);
  } else {
    COUT(A * B);
  }
  return 0;
}

Measured memory_bytes: 256
/*************************************************************************
	> File Name: 1.cpp
	> Author: Knowledge_llz
	> Mail: 925538513@qq.com 
	> Blog: https://blog.csdn.net/Pig_cfbsl 
	> Created Time: 2020/7/13 12:02:38
 ************************************************************************/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define LL long long
using namespace std;
int read(){
	char x=getchar(); int u=0,fg=0;
	while(!isdigit(x)){ if(x=='-') fg=1; x=getchar(); }
	while(isdigit(x)){ u=(u<<3)+(u<<1)+(x^48); x=getchar(); }
	return fg?-u:u;
}
const int maxx=1e5+10;
struct node{
	int x,id;
}a[maxx];
bool cmp(node x,node y){
	return x.x<y.x;
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.in", "r", stdin);
	freopen("output.out", "w", stdout);
#endif
	int n=read();
	For(i,1,n){
		a[i].x=read();
		a[i].id=i;
	}
	sort(a+1,a+n+1,cmp);
	For(i,1,n) printf("%d ",a[i].id);
	return 0;
}


Measured memory_bytes: 4484
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;


int main(void){
  int n,i,ans=0;
  string s;
  
  cin >> n >> s;
  
  for (i=0;i<n-2;i++){
    if (s[i]=='A' && s[i+1]=='B' && s[i+2]=='C'){
      ans++;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    sort(all(h));
    int ans = INF;
    for (int i = 0; i + k - 1 < n; i++) {
        chmin(ans, h[i + k - 1] - h[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
import sys
h, w, n = [int(i) for i in sys.stdin.readline().split()]
m = 1000000007
fact = [1, 1]
for i in range(2, 200002):
    fact.append(fact[-1] * i % m)
inv = [pow(i, m - 2, m) for i in fact]
f = lambda i: fact[i[0] + i[1]] * inv[i[0]] * inv[i[1]] % m
dp = [0] * (n + 1)
p = [[int(i) - 1 for i in sys.stdin.readline().split()] for j in range(n)]
p = sorted(p + [[h - 1, w - 1]])
for i in range(n + 1):
    h1, w1 = p[i]
    tot = f([h1, w1])
    for j in range(i):
        if p[j][1] > w1:
            continue
        tot = (tot - dp[j] * f([h1 - p[j][0], w1 - p[j][1]]) % m) % m
    dp[i] = tot
print(dp[-1])


Measured memory_bytes: 56356
#include <iostream>
#include <algorithm>
#include <cstring>
#include <set>
#include <map>
#include <utility>
#define io ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
const int N=3e5+10;
void solve(){
    int n,m,M;
    cin>>n>>m>>M;
    set<pair<int,int> > s;
    //memset(a,0,sizeof(a));
    for(int i=1;i<=M;i++){
        int a,b;cin>>a>>b;
        s.insert(make_pair(a,b));
    }
    int maxx=0,maxy=0;
    map<int,int> mp1,mp2;
    for(auto i:s){
        mp1[i.first]++;
        mp2[i.second]++;
    }
    int x=0,y=0;
    for(auto i:mp1){
        if(i.second>maxx){
            x=i.first;
            maxx=i.second;
        }
    }
    for(auto i:mp2){
        if(i.second>maxy){
            y=i.first;
            maxy=i.second;
        }
    }
    //cout<<maxx<<" "<<maxy<<"!\n";
    int ans=0,t=0;
    for(int i=1;i<=m;i++){
        t=max(mp2[i],t);
        if(s.count({x,i}))t--;
        ans=max(ans,t);
        //cout<<ans<<"!\n";
    }
    int res=ans+maxx;
    ans=0,t=0;
    for(int i=1;i<=n;i++){
        t=max(mp1[i],t);
        if(s.count({i,y}))t--;
        ans=max(ans,t);
        //cout<<ans<<"!\n";
    }
    cout<<max(res,ans+maxy);
}
int main(){
    io;
    //int T;cin>>T;
    //while(T--)
        solve();
}

Measured memory_bytes: 45820
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N = int(readline())

    odd = 0
    for i in range(1, N + 1):
        if i % 2 == 1:
            odd += 1

    print(odd / N)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61900
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <tuple>

const std::vector<int> dx{-1, 0, 1, 0}, dy{0, -1, 0, 1};
constexpr int INF = 1 << 30;

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

    std::vector<std::string> ss(h);
    for (auto& s : ss) std::cin >> s;

    int ans = 0;

    for (int sx = 0; sx < h; ++sx) {
        for (int sy = 0; sy < w; ++sy) {
            if (ss[sx][sy] == '#') continue;

            std::vector<std::vector<int>> dist(h, std::vector<int>(w, INF));
            dist[sx][sy] = 0;

            std::queue<std::pair<int, int>> que;
            que.emplace(sx, sy);

            while (!que.empty()) {
                int x, y;
                std::tie(x, y) = que.front();
                que.pop();

                for (int i = 0; i < 4; ++i) {
                    int nx = x + dx[i], ny = y + dy[i];
                    if (nx < 0 || h <= nx || ny < 0 || w <= ny ||
                        ss[nx][ny] == '#' || dist[nx][ny] < INF) continue;
                    dist[nx][ny] = dist[x][y] + 1;
                    que.emplace(nx, ny);
                }
            }

            int max = 0;
            for (int x = 0; x < h; ++x) {
                for (int y = 0; y < w; ++y) {
                    if (dist[x][y] < INF) {
                        max = std::max(max, dist[x][y]);
                    }
                }
            }

            ans = std::max(ans, max);
        }
    }

    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    static int MOD = 1_000_000_007;
    private static long[] compute(Node node) {
        long w = 1;
        long b = 1;
        for(Node n:node.children){
            long[] count = compute(n);
            w = (w*(count[0]+count[1]))%MOD;
            b = (b*count[0])%MOD;
        }
        long[] count = new long[2];
        count[0] = w; // white
        count[1] = b; // black
        //System.out.println(node.id+":"+Arrays.toString(count));
        return count;
    }

    private static Node createTree(Node[] nodeList) {
        Queue<Node> que = new ArrayDeque<Node>();
        que.add(nodeList[0]);
        nodeList[0].visited = true;
        while(!que.isEmpty()){
            Node node = que.remove();
            for(Node n: node.neighbors){
                if(!n.visited){
                    node.children.add(n);
                    n.parent = node;
                    n.visited = true;
                    que.add(n);
                }
            }
        }
        return nodeList[0];
    }

    static class Node{
        int id;
        Node parent;
        Set<Node> children = new HashSet<Node>();
        Set<Node> neighbors = new HashSet<Node>();
        boolean visited = false;
        Node(int id){
            this.id = id;
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Node[] nodeList = new Node[N];
        for(int i=0; i<N; i++){
            nodeList[i] = new Node(i);
        }
        for(int i=0; i<N-1; i++){
            Node x = nodeList[sc.nextInt()-1];
            Node y = nodeList[sc.nextInt()-1];
            x.neighbors.add(y);
            y.neighbors.add(x);
        }

        Node root = createTree(nodeList);
        System.out.println((compute(nodeList[0])[0]+compute(nodeList[0])[1])%MOD);
    }
}

Measured memory_bytes: 131744
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;

int n, m;
int G[10][10];

int main(void){
	cin >> n >> m;
	rep(i, m){
		int a, b; cin >> a >> b;
		a--; b--;
		G[a][b] = G[b][a] = 1;
	}

	// 0してん
	vector<int> v(n - 1);
    reps(i, 1, n) v[i - 1] = i;
    sort(v.begin(), v.end());
    int ans = 0;
    //すべての順列を調べる
    do{
        int now = 0;
        rep(i, v.size()){
        	if(G[now][v[i]] == 0) break;
      		now = v[i];
        	if(i == v.size() - 1)ans++;	        	
        }
    }while(next_permutation(v.begin(), v.end()));
    printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define SIZE 100001
#define NONE 0
#define CERT 1	//certainty
#define POSS 2	//possibility

struct process{
	int x;
	int y;
};

struct box{
	int red;	
	int num;
};

int main(void){
	int n;
	int m;
	struct process process[SIZE];
	struct box box[SIZE];
	int tmpx, tmpy;
	int i, j, k;
	int counter = 0;
	scanf("%d %d", &n, &m);
	box[0].red = CERT;
	box[0].num = 1;
	for(i = 1; i < n; i++){
		box[i].red = NONE;
		box[i].num = 1;
	}
	for(i = 0; i < m; i++){
		scanf("%d %d", &tmpx, &tmpy);
		tmpx--;
		tmpy--;
		if(box[tmpx].num == 1){
			if(box[tmpx].red == CERT){
				box[tmpx].red = NONE;
				box[tmpx].num--;
				box[tmpy].num++;
				box[tmpy].red = CERT;
			} else if(box[tmpx].red == POSS){
				box[tmpx].num--;
				box[tmpx].red = NONE;
				box[tmpy].red = POSS;
				box[tmpy].num++;
			} else {
				box[tmpx].num--;
				box[tmpy].num++;
			}
		} else if(box[tmpx].num == 0){
			printf("Error\n");
			return 0;
		} else {
			if(box[tmpx].red == CERT){
				box[tmpx].num--;
				box[tmpx].red = POSS;
				box[tmpy].num++;
				box[tmpy].red = POSS;
			} else if(box[tmpx].red == POSS){
				box[tmpx].num--;
				box[tmpx].red = POSS;
				box[tmpy].num++;
				box[tmpy].red = POSS;
			} else {
				box[tmpx].num--;
				box[tmpy].num++;
			}
		}
	}
	for(i = 0; i < n; i++){
		if(box[i].red == POSS){
			counter++;
		} else if(box[i].red == CERT){
			printf("1\n");
			return 0;
		}

	}

	printf("%d\n", counter);

	return 0;

}

Measured memory_bytes: 896
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)
	A := make(map[int]int)
	sum := 0
	for i := 0; i < N; i++ {
		var V int
		fmt.Scan(&V)
		A[V]++
		sum += V
	}
	var Q int
	fmt.Scan(&Q)
	for i := 0; i < Q; i++ {
		var V, C int
		fmt.Scan(&V, &C)
		x := V * A[V]
		y := C * A[V]
		sum += y - x
		A[C] += A[V]
		A[V] = 0
		fmt.Println(sum)
	}
}


Measured memory_bytes: 10852
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
static const int INF = 10000000;

struct cube
{
  int x, y, t, n, e, i;
  cube(int a, int b, int c, int d, int e_, int f)
    : x(a), y(b), t(c), n(d), e(e_), i(f)
  {}
  int top() const { return t; }
  int bottom() const { return t^1; }
  int north() const { return n; }
  int south() const { return n^1; }
  int east() const { return e; }
  int west() const { return e^1; }
  char color() const
  {
    static const char tbl[] = "rcgmby";
    return tbl[top()];
  }
};

int bfs(const vector<string>& grid, const string& route, int x, int y)
{
  const int H = grid.size();
  const int W = grid[0].size();
  static int dist[30][30][6][6][6][6];
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      for (int t = 0; t < 6; t++) {
        for (int n = 0; n < 6; n++) {
          for (int e = 0; e < 6; e++) {
            fill_n(dist[i][j][t][n][e], 6, INF);
          }
        }
      }
    }
  }
  queue<cube> q;
  q.push(cube(x, y, 0, 2, 4, 0));
  dist[x][y][0][2][4][0] = 0;
  int ans = INF;
  while (!q.empty()) {
    const cube c = q.front();
    q.pop();
    const int dd = dist[c.x][c.y][c.t][c.n][c.e][c.i];
    for (int d = 0; d < 4; d++) {
      cube cc(c);
      static const int dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, -1, 1};
      cc.x += dx[d];
      cc.y += dy[d];
      if (0 <= cc.x && cc.x < H && 0 <= cc.y && cc.y < W && grid[cc.x][cc.y] != 'k') {
        switch (d) {
          case 0: // north
            cc.n = c.top();
            cc.t = c.south();
            break;
          case 1: // south
            cc.n = c.bottom();
            cc.t = c.north();
            break;
          case 2: // west
            cc.e = c.bottom();
            cc.t = c.east();
            break;
          case 3: // east
            cc.e = c.top();
            cc.t = c.west();
            break;
        }
        if (grid[cc.x][cc.y] != 'w') {
          if (grid[cc.x][cc.y] == route[cc.i] && grid[cc.x][cc.y] == cc.color()) {
            ++cc.i;
            if (cc.i == 6) {
              ans = min(ans, dd+1);
            } else {
              int& ddd = dist[cc.x][cc.y][cc.t][cc.n][cc.e][cc.i];
              if (dd+1 < ddd) {
                ddd = dd+1;
                q.push(cc);
              }
            }
          }
        } else {
          int& ddd = dist[cc.x][cc.y][cc.t][cc.n][cc.e][cc.i];
          if (dd+1 < ddd) {
            ddd = dd+1;
            q.push(cc);
          }
        }
      }
    }
  }
  return ans;
}

int main()
{
  int W, H;
  while (cin >> W >> H && W != 0) {
    vector<string> grid(H);
    int x, y;
    for (int i = 0; i < H; i++) {
      cin >> grid[i];
      for (int j = 0; j < W; j++) {
        if (grid[i][j] == '#') {
          x = i;
          y = j;
          grid[i][j] = 'w';
        }
      }
    }
    string route;
    cin >> route;

    const int ans = bfs(grid, route, x, y);
    if (ans == INF) {
      cout << "unreachable" << endl;
    } else {
      cout << ans << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 5512
n = int(input())
a = list(map(int,input().split()))

for i in range(n):
    a[i] = [a[i],i]
l1 = 0
r1 = n-1
l2 = l1
r2 = r1
a.sort(reverse=1)
dp = [[0]*(n+1) for i in range(n+1)]
ans = 0
for i in range(1,n+1):
    dp[i][0] = dp[i-1][0] + a[i-1][0] * abs(a[i-1][1]-i+1)
    dp[0][i] = dp[0][i-1] + a[i-1][0] * abs(n-(a[i-1][1])-i)
    for j in range(1,i):
        dp[j][i-j] = max(dp[j-1][i-j]+a[i-1][0]*abs(a[i-1][1]-j+1),dp[j][i-j-1]+a[i-1][0]*abs(n-(a[i-1][1])-(i-j)))
for i in dp:
    ans = max(ans,max(i))
print(ans)

Measured memory_bytes: 100624
import math
N, D = map(int, input().split())

ans = 0
points = []
for n in range(N):
    points.append(list(map(int, input().split())))

i = 0
j = N - 1
while i < N - 1:
    a = points[i]
    b = points[j]
    total = 0
    for d in range(D):
        total += (a[d] - b[d]) ** 2
    res = math.sqrt(total)
    if res.is_integer(): ans += 1
    j -= 1
    if i == j:
        i += 1
        j = N - 1

print(ans)

Measured memory_bytes: 3188
while True:
    n = int(input())
    if n == 0:
        break
    dataset = [list(map(int, input().split())) for _ in range(n)]
    for p in dataset:
        x = (p[0] + p[1] + p[2]) // 3
        if 100 in p:
            print("A")
        elif (p[0] + p[1]) // 2 >= 90:
            print("A")
        elif x >= 80:
            print("A")
        elif x >= 70:
            print("B")
        elif x >= 50 and (p[0] >= 80 or p[1] >= 80):
            print("B")
        else:
            print("C")

Measured memory_bytes: 7812
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n,a,b=map(int,input().split())
    if((a+b)%2==0):
        print(abs(b-a)//2)
        return

    ans=INF
    # 1 側に向かう
    score=a
    score+=(b-a-1)//2
    ans=min(ans,score)

    a,b=n-b+1,n-a+1
    score=a
    score+=(b-a-1)//2
    ans=min(ans,score)

    print(ans)
resolve()

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

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

int main(){
  int n,m;
  cin >> n >> m;

  vector<vector<int>> ship(n, vector<int>(0));
  rep(i,m){
    int a,b;
    cin >> a >> b;
    a--; b--;
    ship.at(a).push_back(b);
    ship.at(b).push_back(a);
  }

  vector<int> check(n);
  rep(i,ship.at(0).size()){
    int is = ship.at(0).at(i);
    check.at(is) = 1;
  }
  
  rep(i,ship.at(n-1).size()){
    int is = ship.at(n-1).at(i);
    if(check.at(is)){cout<<"POSSIBLE"; return 0;}
  }

  cout << "IMPOSSIBLE";
}

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

int main(){
    int n; cin >> n;
    vector<int> h(100);
    for(int i=0; i<n; i++){
        cin >> h[i];
    }
    int ans = 0;
    for(int l=0; l<n; l++){
        while(h[l]>0){
            int r=0;
            for(r=l+1; r<n; r++){
                if(h[r]==0)
                    break;
            }
            for(int i=l; i<r; i++){
                h[i]--;
            }
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
import java.util.*;
public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int n = sc.nextInt();
                int m = sc.nextInt();
                int[] k = new int[n];
                int[] like = new int[m];
                Arrays.fill(like , 1);
                int[] yono = new int[m];
                for(int i = 0 ; i < n ; i++){
                        k[i] = sc.nextInt();
                        Arrays.fill(yono , 0);
                        for(int j = 0 ; j < k[i] ; j++){
                                yono[sc.nextInt() - 1]++;
                        }
                        for(int ii = 0 ; ii < m ; ii++){
                                like[ii] *= yono[ii];
                        }
                }
                for(int i = 0 ; i < m ; i++){
                        if(i != 0){
                                like[0] += like[i];
                        }
                }
                System.out.println(like[0]);
        }
}//0=48
//鶏になれ

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

int main(){
  int N; cin >> N;
  long long A[100000],B[100000];
  for(int i=0; i<N; i++){
    cin >> A[i] >> B[i];
  }
  long long button=0;
  for(int i=N-1; i>=0; i--){
    if((A[i]+button)%B[i]!=0){
      button+=(B[i]-(A[i]+button)%B[i]);
    }
  }
  cout << button << endl;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

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

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;


/*
 * Union-Find tree
 * header requirement: vector
 */
class UnionFind {
private:
  std::vector<int> disj;
  std::vector<int> rank;
public:
  UnionFind(int n) : disj(n), rank(n) {
    for (int i = 0; i < n; ++i) {
      disj[i] = i;
      rank[i] = 0;
    }
  }
  int root(int x) {
    if (disj[x] == x) {
      return x;
    }
    return disj[x] = root(disj[x]);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) {
      return;
    }
    if (rank[x] < rank[y]) {
      disj[x] = y;
    } else {
      disj[y] = x;
      if (rank[x] == rank[y]) {
	++rank[x];
      }
    }
  }
  bool is_same_set(int x, int y) {
    return root(x) == root(y);
  }
};

const int N = 112222;
int a[N], b[N], w[N];

typedef pair<ll, PI> PLPI;

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  VI c(n);
  int czero = 0;
  REP(i, 0, n) {
    cin >> c[i];
    czero += c[i] == 0;
  }
  vector<PLPI> pool;
  REP(i, 0, m) {
    cin >> a[i] >> b[i] >> w[i];
    a[i]--, b[i]--;
    pool.push_back(PLPI(w[i], PI(a[i], b[i])));
  }
  sort(pool.begin(), pool.end());
  UnionFind uf(k + n);
  int conn = k;
  ll tot = 0;
  REP(i, 0, pool.size()) {
    if (conn <= 1) break;
    ll ww = pool[i].first;
    int x = pool[i].second.first;
    int y = pool[i].second.second;
    x = c[x] == 0 ? k + x : c[x] - 1;
    y = c[y] == 0 ? k + y : c[y] - 1;
    assert (x >= 0);
    assert (y >= 0);
    if (not uf.is_same_set(x, y)) {
      tot += ww;
      uf.unite(x, y);
      conn--;
    }
  }
  cout << (conn > 1 ? -1 : tot) << "\n";
}


Measured memory_bytes: 4976
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;
 
int main(){
  int N, Q;
  cin >> N >> Q;
  string S;
  cin >> S;
  vector<int> l(Q), r(Q);
  for(int i=0; i<Q; i++){
    cin >> l[i] >> r[i];
  }

  vector<int> q(N, 0);
  vector<int> s(N+1, 0);
  for(int i=0; i<N-1; i++){
    if(S[i]=='A' && S[i+1]=='C'){
      q[i]++;
    }
    s[i+1]=s[i]+q[i];
  }

  for(int i=0; i<Q; i++){
    cout << s[r[i]-1]-s[l[i]-1] << endl;
  }
  return 0;
}

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

int main() {
	ll a,b,k;
	cin >> a >> b >> k;
	if (k<=a) a-=k;
	else if (k<=(a+b)) {b-=k-a;a=0;}
	else {a=0;b=0;}
	cout << a << " " << b;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int a;
	scanf("%d",&a);
	if(a%1000==0){
		printf("0\n");
	}
	else{
		printf("%d\n",1000-(a%1000));
	}
	return 0;
}

Measured memory_bytes: 1724
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"math"
	"os"
	"strconv"
)

const INF = math.MaxInt32

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

// An Item is something we manage in a priority queue.
type Item struct {
	val      int
	priority int
}

// A PriorityQueue implements heap.Interface and holds Items.
type PriorityQueue []*Item

func (q PriorityQueue) Len() int { return len(q) }

func (q PriorityQueue) Less(i, j int) bool {
	return q[i].priority < q[j].priority
}

func (q PriorityQueue) Swap(i, j int) {
	q[i], q[j] = q[j], q[i]
}

func (q *PriorityQueue) Push(x interface{}) {
	item := x.(*Item)
	*q = append(*q, item)
}

func (q *PriorityQueue) Pop() interface{} {
	old := *q
	n := len(old)
	item := old[n-1]
	*q = old[0 : n-1]
	return item
}

type Edge struct {
	to, cost int
}

type Graph [][]*Edge

func (g Graph) AddEdge(s, t, c int) {
	g[s] = append(g[s], &Edge{t, c})
}

func (g Graph) dijkstra(s int) []int {
	dist := make([]int, len(g))
	for i := range dist {
		dist[i] = INF
	}

	q := make(PriorityQueue, 0, len(g))
	heap.Init(&q)
	// slowest shit why?
	//q.Push(&Item{s, 0})
	heap.Push(&q, &Item{s, 0})
	dist[s] = 0

	for q.Len() != 0 {
		// slowest shit why?
		//e := q.Pop().(*Item)
		e := heap.Pop(&q).(*Item)
		if e.priority > dist[e.val] {
			continue
		}

		for _, f := range g[e.val] {
			cost := e.priority + f.cost
			next := f.to
			if cost < dist[next] {
				dist[next] = cost
				// slowest shit why?
				//q.Push(&Item{next, cost})
				heap.Push(&q, &Item{next, cost})
			}
		}
	}
	return dist
}

func main() {
	sc.Split(bufio.ScanWords)
	V, E, r := nextInt(), nextInt(), nextInt()
	g := make(Graph, V)

	for i := 0; i < E; i++ {
		s, t, d := nextInt(), nextInt(), nextInt()
		g.AddEdge(s, t, d)
	}

	dist := g.dijkstra(r)

	for _, d := range dist {
		if d == INF {
			fmt.Println("INF")
		} else {
			fmt.Println(d)
		}
	}
}




Measured memory_bytes: 23424
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = a - b*2;
        if(c>0) System.out.println(c);
        else System.out.println(0);
    }
}

Measured memory_bytes: 35700
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

#define SIZE 10000
#define MAX(a, b) ((a) > (b) ? (a) : (b))

int parent[SIZE];
int depth[SIZE];

int find(int x) {
    if (parent[x] == x)
        return x;
    return parent[x] = find(parent[x]);
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y)
        return;
    if (depth[x] < depth[y]) {
        int tmp = x;
        x = y;
        y = tmp;
    }
    // depth[x] > depth[y]
    parent[y] = x;
    depth[x] = MAX(depth[x], depth[y] + 1);
}

bool same(int x, int y) {
    return find(x) == find(y);
}

int main (void)
{
    int i;
    int n, q;
    scanf("%d %d", &n, &q);
    for (i = 0; i < n; i++) {
        parent[i] = i;
    }
    int com, x, y;
    for (i = 0; i < q; i++) {
        scanf("%d %d %d", &com, &x, &y);
        if (com == 0) unite(x, y);
        else
            printf("%d\n", same(x, y)? 1 : 0);
    }
    return 0;
}


Measured memory_bytes: 1872
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int A, B;
    cin >> A >> B;

    int ret = 0;

    for (int bit = 0; bit <= 40; bit++) {
        int tmp = 0;
        int pw = 1;
        for (int i = 0; i < bit; i++) pw *= 2;
        int pw2 = pw * 2;

        int a = A + (pw2 - A % pw2);
        int b = B - (B % pw2);

        tmp += min(a - A, pw);
        tmp += max(0LL, B - b - pw + 1);

        tmp += ((b - a) / pw2) * pw;

        if (tmp % 2 == 1) ret += pw;
    }

    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mpr make_pair
#define fi first
#define se second
using ll=long long int;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int main(){
	int n;
	cin>>n;
	vector<int>b(n),ans(n);
	rep(i,n)cin>>b[i];
	rep(i,n){
		int maxv=-1;
		rep(j,b.size()){
			if(b[j]==(j+1)){
				maxv=j+1;
			}
		}
		if(maxv==-1){
			cout<<-1<<endl;
			return 0;
		}		
		b.erase(b.begin()+(maxv-1));
		ans[n-i-1]=maxv;
		}
	rep(i,n)cout<<ans[i]<<endl;
	return 0;
}




Measured memory_bytes: 256
#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);}
}

const int N=1e5+5;
int en=1,n,h[N],now[N],ans[N],du[N],ma;

struct edge{
	int n,v;
}e[N<<1];

void add(int x,int y){
	e[++en]=(edge){h[x],y};
	h[x]=en;
}

void dfs(int x,int fa,int p){
	for(int i=h[x];i;i=e[i].n){
		int y=e[i].v;
		if(y==fa) continue;
		ans[i>>1]=++now[x];
		if(now[x]==p) ans[i>>1]=++now[x];
		dfs(y,x,now[x]);
	}
}

signed main(){
	read(n);
	for(int i=1,x,y;i<n;i++){
		read(x);read(y);
		add(x,y);
		add(y,x);
		du[x]++;
		du[y]++;
		ma=max(ma,max(du[x],du[y]));
	}
	dfs(1,0,0);
	write(ma);puts("");
	for(int i=1;i<n;i++) write(ans[i]),puts("");
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define square(x) pow(x 2.0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define max_queue(x) priority_queue<x>
#define min_queue(x) priority_queue<x, vector<x>, greater<x>>
#define big_sort(v) sort(all(v), [](int a, int b) { return a > b; })//大きい順にソート
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
/*
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
*/
int main() {
  int n,sum=0,hp1=0,hp2=0;
  cin >> n;
  vector<int> v(n);
  rep(i,n){
    cin >> v[i];
    sum += v[i];
  }
  sum /= n;
  rep(i,n){
    hp1+=(sum-v[i])*(sum-v[i]);
    hp2+=(sum+1-v[i])*(sum+1-v[i]);
  }
  cout << min(hp1,hp2) << endl;
  return 0;
}


Measured memory_bytes: 256
# frozen_string_literal: true

a, b, m = gets.split.map(&:to_i)
as = gets.split.map(&:to_i)
bs = gets.split.map(&:to_i)
xyc = m.times.map { gets.split.map(&:to_i) }

min = as.min + bs.min
xyc.each do |e|
  x = e[0] - 1
  y = e[1] - 1
  c = e[2]
  s = as[x] + bs[y] - c
  min = s if min > s
end
puts min


Measured memory_bytes: 18972
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
string alp="abcdefghijklmnopqrstuvwxyz";
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main(){
    ll a,b,c;cin>>a>>b>>c;
    ll ans=0;
    ll x,y,z;
    while((a!=b || b!=c) && a%2==0 && b%2==0 && c%2==0){
        ans++;
        x=(c+b)/2;
        y=(a+c)/2;
        z=(b+a)/2;
        a=x;
        b=y;
        c=z;
    }
    if(a%2==0 && b%2==0 && c%2==0){
        cout<<-1<<endl;
    }else{
        cout<<ans<<endl;
    }
    return 0;
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 1<<30
#define endl '\n'
#define maxn 100005
#define tc printf("Case %d: ", cs)
#define tcn printf("Case %d:\n", cs);
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
const double PI = acos(-1.0);
#define dbg(x) cerr << #x << " = " << x << endl;
#define dbg2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << endl;
#define dbg3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;


int main()
{
    FASTIO
    /*
    //double start_time = clock();
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
//*/
    int T;
    //cin >> T;
    T = 1;
    for (int cs = 1; cs <= T; cs++) {
        int n;
        cin >> n;
        vector<int> v(n);
        vector<pair<int, int> > vp;
        for (int i = 0; i < n; i++) {
            cin >> v[i];
            vp.push_back({v[i], i});
        }
        sort(vp.rbegin(), vp.rend());
        for (int i = 0; i < n; i++) {
            for (auto x : vp) {
                if (x.second != i) {
                    cout << x.first << endl;
                    break;
                }
            }
        }
    }

    //double end_time = clock();
    //printf( "Time = %lf ms\n", ( (end_time - start_time) / CLOCKS_PER_SEC)*1000);
    return 0;
}

Measured memory_bytes: 4080
n=int(input())
l=list(map(int,input().split()))
import collections
c=dict(collections.Counter(l))
d=list(c.values())
e=list(c.keys())
if len(d)==3:
    d.sort()
    e.sort()
    if d[0]==d[1]==d[2] and e[0]^e[2]==e[1]:
        print("Yes")
    else:
        print("No")
elif len(d)==2:
    d.sort()
    e.sort()
    if d[0]==d[1] and e[0]==0:
        print("Yes")
    elif d[0]*2==d[1] and e[0]==0 and c.get(0,-1)==d[0]:
        print("Yes")
    else:
        print("No")
elif len(d)==1 and e[0]==0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 16544