akhauriyash/Code-Regression huggingface dataset:
/**
 *    author:  morato
 *    created: 29.08.2020 17:24:30
**/
#include <bits/stdc++.h>

using namespace std;

map<int, bool> ok;
map<int, int> freq;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    freq[v[i]]++;
    ok[v[i]] = true;
  }
  sort(v.begin(), v.end());
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = v[i] + v[i]; j <= v[n - 1]; j += v[i]) {
      ok[j] = false;
    }
    ok[v[i]] &= (freq[v[i]] == 1);
    ans += (int) ok[v[i]];
  }
  cout << ans << '\n';
  return 0;
}

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

int main() {

    string s;
    cin >> s;

    int a;
    int z;

    rep(i, s.length()) {
        if (s[i] == 'A') {
            a = i;
            break;
        }
    }

    for (int i = s.length(); i > 0; --i) {
        if (s[i] == 'Z') {
            z = i;
            break;
        }
    }
    cout << z - a + 1<< endl;

    return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <sstream>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
int MOD = 1000000007;

signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int k;
	cin >>k;
	vector<int> a;
	for(int i=1;i<=9;i++){
		a.push_back(i);
	}
	while(1){
		if(k <= a.size()){
			cout << a[k-1] << endl;
			return 0;
		}
		k -= a.size();
		vector<int> old;
		swap(old, a);
		for(int x : old){
			for(int i=-1; i<=1; i++){
				int d = x%10 + i;
				if(d<0 || d>9){
					continue;
				}
				int nx = x*10 + d;
				a.push_back(nx);
			}
		}
	}
	return 0;
}


Measured memory_bytes: 1712
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

const double EPS = 1e-6;

double dist(double px, double py, double qx, double qy) {
  return sqrt((px - qx) * (px - qx) + (py - qy) * (py - qy));
}

int main(void) {
  ll N, M;
  cin >> N >> M;
  vector<ll> P(N);
  REP(i, 0, N) {
    ll X, Y;
    cin >> X >> Y;
    P[i] = X * 100000000 + Y;
  }

  sort(P.begin(), P.end());
  P.erase(unique(P.begin(), P.end()), P.end());

  N = P.size();
  vector<double> X(N), Y(N);
  REP(i, 0, N) {
    X[i] = P[i] / 100000000;
    Y[i] = P[i] % 100000000;
  }

  vector<double> radius(1LL << N);
  REP(s, 0, 1LL << N) {
    ll cnt = 0;
    REP(i, 0, N) if(s & (1LL << i)) cnt++;
    if(cnt < 2) {
      radius[s] = 0.0;
      continue;
    }

    double minr = 1e10;
    REP(i, 0, N) REP(j, i + 1, N) {
      if(!((s & (1LL << i)) && (s & (1LL << j)))) continue;

      double d = dist(X[i], Y[i], X[j], Y[j]) / 2.0;
      double dx = +(Y[i] - Y[j]) / (d * 2.0);
      double dy = -(X[i] - X[j]) / (d * 2.0);
      double mx = (X[i] + X[j]) / 2.0;
      double my = (Y[i] + Y[j]) / 2.0;

      bool ok = true;
      REP(k, 0, N) if(s & (1LL << k)) if(dist(X[k], Y[k], mx, my) > d + EPS) ok = false;
      if(ok) {
        minr = min(minr, d);
        continue;
      }

      double l1 = d, h1 = 1e10;
      REP(_, 0, 100) {
        double m = (l1 + h1) / 2.0;
        double t = sqrt(m * m - d * d);

        double c1x = mx + dx * t;
        double c1y = my + dy * t;
        bool ok1 = true;
        REP(k, 0, N) if(s & (1LL << k)) if(dist(X[k], Y[k], c1x, c1y) > m + EPS) ok1 = false;

        (ok1 ? h1 : l1) = m;
      }

      double l2 = d, h2 = 1e10;
      REP(_, 0, 100) {
        double m = (l2 + h2) / 2.0;
        double t = sqrt(m * m - d * d);

        double c2x = mx - dx * t;
        double c2y = my - dy * t;
        bool ok2 = true;
        REP(k, 0, N) if(s & (1LL << k)) if(dist(X[k], Y[k], c2x, c2y) > m + EPS) ok2 = false;

        (ok2 ? h2 : l2) = m;
      }

      minr = min(minr, min(h1, h2));
    }
    radius[s] = minr;
  }

  vector< vector<double> > dp(1LL << N, vector<double>(M + 1, 1e10));
  dp[0][0] = 0.0;
  REP(s, 0, 1LL << N) REP(i, 0, M) {
    ll sup = 0;
    REP(j, 0, N) if(!(s & (1LL << j))) sup = sup | (1LL << j);

    ll sub = sup;
    do {
      dp[s | sub][i + 1] = min(dp[s | sub][i + 1], max(dp[s][i], radius[sub]));
      sub = (sub - 1) & sup;
    } while(sub != sup);
  }

  double ans = 1e10;
  REP(i, 0, M + 1) ans = min(ans, dp[(1LL << N) - 1][i]);
  printf("%.15lf\n", ans);
}



Measured memory_bytes: 5272
import sys
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N = ri()

mem = [[0]*10 for _ in range(10)]
for n in range(1, N+1):
    s = str(n)
    mem[int(s[0])][int(s[-1])] += 1
ans = 0
for i in range(1, 10):
    for j in range(1, 10):
        ans += mem[i][j] * mem[j][i]
print(ans)


Measured memory_bytes: 40428
#include <bits/stdc++.h>
#define db(x) cout << (x) << '\n';
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pii;
typedef pair<double,ll> pdi;
typedef pair<string,ll> psi;
typedef pair<ll,string> pls;
typedef pair<ll,pii> pip;
typedef pair<pii,pii> ppp;

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

    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int l=0;
    while(a>0 && c>0)
    {
        if(l&1)
            a-=d;
        else
            c-=b;
        l++;
    }

    if(l&1)
        db("Yes")
    else
        db("No")

    return 0;
}


Measured memory_bytes: 3648
s=input()
n=len(s)
flag=True
for i in range((n-1)//2):
  if s[i]!=s[(-1)*(i+1)]:
    #print("g1",i)
    flag=False
    break
if flag:
  for i in range((n-1)//4):
    if s[i]!=s[(n-1)//2-(i+1)] or s[(n+3)//2-1+i]!=s[(-1)*(i+1)]:
      #print("g2",i)
      flag=False
      break
if flag:
  print("Yes")
else:
  print("No")


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<sstream>
#include<math.h>
#define rep(i,n) for(int i =0;i<(int)(n);i++)
typedef long long ll;
using namespace std;
int main() {
	int n, d;
	cin >> n >> d;
	d = 2 * d + 1;
	if (n%d == 0) {
		cout << n / d << endl;
	}
	else {
		cout << n / d + 1 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
x = int(input())
if 400 <= x < 600:
    print(8)
elif 600<= x < 800:
    print(7)
elif 800<=x <1000:
    print(6)
elif 1000<=x<1200:
    print(5)
elif 1200<=x<1400:
    print(4)
elif 1400<=x<1600:
    print(3)
elif 1600<=x<1800:
    print(2)
else:
    print(1)

Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
bool graph[8][8];

int dfs(int v, int N, bool visited[8]){

    bool all_visited=true;

    for(int i=0;i<N;i++){
        if(visited[i]==false){
            all_visited=false;
        }
    }

    if(all_visited){
        return 1;
    }

    int ret = 0;

    for(int i = 0; i<N; i++){
        if(graph[v][i]==false)continue;
        if(visited[i]) continue;

        visited[i]=true;
        ret+=dfs(i,N,visited);
        visited[i]=false;
    }

    return ret;

}



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


    for(int i = 0; i < M; i++){
        int A,B;
        cin >> A >> B;
        graph[A-1][B-1]=graph[B-1][A-1]=true;
    }

    bool visited[8];
    for(int i = 0; i < N; i++){
        visited[i]=false; 
    }
   
    visited[0]=true;

    cout << dfs(0,N,visited) << endl;

    return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    ll ans=1;
    rep(i,n){
        ll t; cin>>t;
        ans = ans/__gcd(ans,t)*t;
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(){
    int N;
    string S, T;
    cin >> N >> S >> T;
    string ans = "";
    for(int i=0;i<N;i++){
        ans += S[i];
        ans += T[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import Control.Monad

type Point = (Double, Double)
type Line = (Point, Point)

koch :: Line -> [Line]
koch ((sx, sy), (ex, ey)) = [(p0, p1), (p1, p2), (p2, p3), (p3, p4)]
  where
    dx = ex - sx
    dy = ey - sy
    pre2 = rotate60 (fst p3 - fst p1, snd p3 - snd p1)
    p0 = (sx, sy)
    p1 = (sx + dx / 3, sy + dy / 3)
    p2 = (fst p1 + fst pre2, snd p1 + snd pre2)
    p3 = (sx + dx * 2 / 3, sy + dy * 2 / 3)
    p4 = (ex, ey)

rotate60 :: Point -> Point
rotate60 (x, y) = (x / 2 - y * sqrt 3 / 2 , x * sqrt 3 / 2 + y / 2)

main = do
  n <- fmap read getLine
  let result = case n of
               0 -> [((0, 0), (100, 0))]
               _ -> foldr1 (<=<) (replicate n koch) $ ((0, 0), (100, 0))
  mapM_ putStrLn $ map (\((sx, sy), _) -> show sx ++ " " ++ show sy) $ result
  putStrLn $ (\(x, y) -> show x ++ " " ++ show y) . snd . last $ result

Measured memory_bytes: 4912
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int main()
{
    char a[10],b[5],s[10];
    cin>>a>>b;
    strcat(a,b);
    int c=atoi(a);
    int flag=0;
    for(int i=0;i<=10000;i++)
        if(i*i==c)
        flag=1;
    if(flag)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


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

using namespace std;


template<typename T>
class UF{
public:
	UF(){
		size = 0;
	}

	//値を挿入する
	void push(T a){
		M[a] = size;
		V.push_back(size);
		rank.push_back(0);
		C.push_back(1);
		size++;
	}

	//同じグループにする
	void unite(T a, T b){
		long long int x = find(M[a]);
		long long int y = find(M[b]);
		if( x == y )return;
		if( rank[x] < rank[y] ){
			V[x] = y;
			C[y] += C[x];
		} else{
			V[y] = x;
			C[x] += C[y];
			if( rank[x] == rank[y] )rank[x]++;
		}
	}

	void merge(T a, T b){
		unite(a, b);
	}

	//同じグループにいるかどうか判定する
	bool same(T a, T b){
		return find(M[a]) == find(M[b]);
	}

	//今何グループあるか数を返す
	long long int group(){
		set<long long int>S;
		for( long long int i = 0; i < V.size(); i++ ){
			S.insert(find(V[i]));
		}
		return S.size();
	}

	//グループに属している数を返す
	long long int count(T a){
		return C[find(M[a])];
	}

	//今属しているグループのIDを返す
	long long int groupID(T a){
		return find(M[a]);
	}

	//同じグループのメンバーを返す
	vector<T>friendList(T a){
		long long int inputID = find(M[a]);
		vector<T>ret;
		for( auto now : M ){
			if( find(now.second) == inputID ){
				ret.emplace_back(now.first);
			}
		}
		return ret;
	}

private:
	vector<long long int>C, V, rank;
	map < T, long long int>M;
	long long int size;

	//祖先までたどる
	long long int find(long long int x){
		if( V[x] == x )return x;
		else return V[x] = find(V[x]);
	}
};



int main(){
	long long int N, M;
	cin >> N >> M;
	UF<long long int>uf;
	for( size_t i = 0; i < N; i++ ){
		uf.push(i);
	}
	vector<vector<pair<long long int, long long int>>>X(N);
	for( size_t i = 0; i < M; i++ ){
		long long int L, R, D;
		cin >> L >> R >> D;
		L--;
		R--;
		X[L].push_back(make_pair(R, D));
		X[R].push_back(make_pair(L, -D));
	}
	map<long long int, long long int>m;
	for( size_t i = 0; i < N; i++ ){
		if( m.count(i) ){
			continue;
		}
		m[i] = 0;
		queue<long long int>que;
		que.push(i);
		while( que.size() ){
			auto now = que.front(); que.pop();
			for( auto x : X[now] ){
				if( m.count(x.first) ){
					if( m[x.first]!=m[now]+x.second ){
						cout << "No" << endl;
						return 0;
					}
					continue;
				}
				m[x.first] = m[now] + x.second;
				que.push(x.first);
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 27488
if __name__ == '__main__':
  
  h, w = map(int, input().split())
  s = []
  
  s.append('.' + '.' * w + '.')
  for i in range(h):
      s.append('.' + input() + '.')
  s.append('.' + '.' * w + '.')
  
  for i in range(h):
      result_list = []
      for j in range(w):
          target_cell = ''
          if s[i + 1][j + 1] == '.':
            target_cell += s[i][j:j+3]
            target_cell += s[i+1][j:j+3]
            target_cell += s[i+2][j:j+3]
              
            print(target_cell.count('#'), end="")
          else:
            print('#', end="")
            
      print()

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define FORI(i,v) for (auto i = v.begin(); i != v.end(); i++)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)
#define YES(b) cout << ((b) ? "YES" : "NO") << endl
#define Yes(b) cout << ((b) ? "Yes" : "No") << endl

const int MAX = 111;

int X, N, P[MAX];

ll solve() {
    set<int> st;
    REP (i, N) st.insert(P[i]);

    REP (i, 1000) {
        int x = X + ((i&1) ? (i>>1) : (-(i>>1)));
        if (st.find(x) != st.end()) continue;
        return x;
    }
}

int main() {
    cout << fixed << setprecision(15);
    cin >> X >> N;
    REP (i, N) cin >> P[i];
    cout << solve() << endl;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
constexpr int MX = 200005;
int n, a[MX*3], b[MX], z[MX*3], l, r = 1, o;
int main(){
	scanf("%d", &n);
	rep(i,n*2+1) if(i-n) scanf("%d", a+i+(i<n?n+1:-n-1));
	a[n*2+1] = a[n+1];
	a[n] = a[0];
	rep(i,n) b[i] = a[0] ^ a[n+1+i];
	rep(i,n*2+1) a[i] ^= a[i+1];
	rep(i,n) a[i+n*2+1] = a[i+n+1];
	a[n] = 1<<30;
	rep(i,n*2+1){
		if((o = z[i-l]+i >= r)) for(l=i, r=max(r,i); a[r-l]==a[r]; r++);
		if((z[i] = o ? r-l : z[i-l]) == n) printf("%d %d\n", i-n-1, b[i-n-1]);
	}
}

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

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
    ll t,i,j,temp1,temp2,x,y,sum=0,o,n,m,k,d;
    cin >> n >> k;
    unordered_set <ll> u;
    for(i=0;i<k;i++){
        cin >> d;
        for(j=0;j<d;j++){
            cin >> temp1;
            u.insert(temp1);
        }
    }
    cout << n-u.size();
}

Measured memory_bytes: 3664
<?php
  
  fscanf(STDIN,"%s",$C);
  fscanf(STDIN,"%s",$CC);

if($C[1] == $CC[1] && $C[0] == $CC[2] && $CC[0] == $C[2]){
  echo "YES\n";
}else{
  echo "NO\n";
}





Measured memory_bytes: 4604
import java.util.Scanner;
import java.util.Arrays;

public class Main { //HDL-style Disjoint Set
	static int N; // int_maxsize > 10000 (constrain)
	static int Q; // int_maxsize > 110000 (worstcase = 10000initial set  + 100000 new set)
	static boolean Com; //com only have two kind;
	static int V1;
	static int V2;
	static int[] S;
	static Scanner scanner;
	public static void main(String[] args){
		scanner = new Scanner(System.in);
		N = scanner.nextInt();
		N = 100000;
		S = new int[N];
		reset();
		Q = scanner.nextInt();
		FSM();
	}
	//end of main
	private static void reset(){
		Com = false;
		V1 = 0;
		V2 = 0;
		for(int i = 0; i<N; i++){
			S[i]=i;
		}
	}
	//end of reset
	private static void FSM(){
		while(Q>0){
			fetch();
			dispatch();
			Q--;
		}
	}
	//end of FSM
	private static void fetch(){
		Com = (scanner.nextInt() > 0)?true:false;
		V1 = scanner.nextInt();
		V2 = scanner.nextInt();
	}
	//end of feteh
	private static void dispatch(){
		if(Com){
			same();
		}else {
			unite();
		}
	}
	//end of dispatch
	private static void unite(){
		if(S[V1] == S[V2]){
			return;
		}else{
			merge();
		}
	}
	//end of unite
	private static void same(){
		if(S[V1] == S[V2]){
			System.out.println(1);
		}else{
			System.out.println(0);
		}
	}
	//end of same
	private static void merge(){
		V1 = S[V1];// use variable 1 to store the set code of V1
		V2 = S[V2];// use variable 2 to store the set code of V2
		for(int i = 0; i< N;i++)
		{
			if(S[i] == V1){
				S[i] = V2;
			}else{
				continue;
			}
		}
	}
}	



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

int main() {
  int a,b,c;
  int d = 0;

  cin >> a >> b >> c;

  if(a==b){
    d++;
  }
  if(b==c){
    d++;
  }
  if(c==a){
    d++;
  }
  if(d == 1 || d == 2){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
n = int(input())    # 観光スポットの数
a = list(map(int, input().split())) # 観光スポットの座標
a.insert(0, 0)
a.append(0)
sum = 0
for i in range(0, n+1):
    sum += abs(a[i] - a[i+1])
for i in range(1, n+1):
    head = abs(a[i-1] - a[i])
    tail = abs(a[i] - a[i+1])
    mid = abs(a[i-1] - a[i+1])
    print(sum + mid - head - tail) 


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

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

    ll n;
    cin >> n;
    
    cout << n*(n-1)/2 << endl;

    return 0;
}

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

typedef long long ll;
typedef pair <int , int> pii;
typedef long double ld;

const int N = 2e5+10 , mod = 1e9+7;

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   string s;
   cin >> s;
   int n = s.length();
   int sum = 0;
   for(int i = 0 ; i < n ; i++){
      sum += (s[i] - '0');
      sum %= 9;
   }
   if(sum == 0)
      cout << "Yes";
   else
      cout << "No";
   return 0;
}


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

ll cnt[1000000];
ll a[1000000],b[1000000],c[1000000];

int main(){
	int n,m;scanf("%d%d",&n,&m);
	int back;scanf("%d",&back);back--;
	rep(i,m-1){
		int p;scanf("%d",&p);p--;
		cnt[min(p,back)]++;
		cnt[max(p,back)]--;
		back=p;
	}
	rep(i,n-1){
		scanf("%lld%lld%lld",&a[i],&b[i],&c[i]);
	}
	ll sum=0;
	rep(i,n-1){
		if(i)cnt[i]+=cnt[i-1];
		sum+=min(cnt[i]*a[i],cnt[i]*b[i]+c[i]);
	}
	printf("%lld\n",sum);
}

Measured memory_bytes: 6352
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_set>
#include <bitset>
#include <time.h>
#include <limits.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) (int)x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
typedef tuple<int, int, int> t3;

namespace MaxFlow{
	const int MV = 300020;
	const int ME = 700040;
	const int INF = 1e9;
	int dis[MV];
	int st[MV], en[ME<<1], nxt[ME<<1], flow[ME<<1], ce;
	int start[MV];
	void init() {
		memset(st, 0, sizeof st);
		ce = 1;
	}
	void addE(int s, int e, int f = 1) {
		++ce; nxt[ce] = st[s]; st[s] = ce; en[ce] = e; flow[ce] = f;
		++ce; nxt[ce] = st[e]; st[e] = ce; en[ce] = s; flow[ce] = 0;
	}
	int que[MV];
	int bfs(int N, int S, int E) {
		for(int i=1;i<=N;i++) dis[i] = -1;
		dis[S] = 0;
		int *fr = que, *re = que;
		*fr++ = S;
		while(fr != re) {
			int t = *re++;
			for(int i=st[t];i;i=nxt[i]) if(flow[i] > 0 && dis[en[i]] == -1) {
				dis[en[i]] = dis[t] + 1;
				*fr++ = en[i];
			}
		}
		return dis[E] != -1;
	}
	
	int dfs(int x, int E, int f) {
		if(x == E) return f;
		for(int &i=start[x],t;i;i=nxt[i]) if(flow[i] > 0 && dis[en[i]] == dis[x] + 1 && (t = dfs(en[i], E, min(f, flow[i]))) > 0){
			flow[i] -= t;
			flow[i^1] += t;
			return t;
		}
		return 0;
	}
	
	int Get(int N, int S, int E) {
		int res = 0;
		while(bfs(N, S, E)) {
			for(int i=1;i<=N;i++) start[i] = st[i];
			while(1) {
				int t = dfs(S, E, INF);
				if(t == 0) break;
				res += t;
			}
		}
		return res;
	}
	
	void trace(int N, int S, int E, int chk[]) {
		bfs(N, S, E);
		for(int i=1;i<=N;i++) chk[i] = (dis[i] != -1);
	}
}

int N;
vector <int> R[100010], L[100010];
int V[100010], W[100010];
int mark[100010];

int main() {
	scanf("%d", &N);
	for(int i=1;i<N;i++) {
		int c; scanf("%d", &c);
		while(c--) {
			int x; scanf("%d", &x);
			R[i].pb(x);
		}
	}
	int ST = 1;
	MaxFlow::init();
	for(int i=1;i<N;i++) {
		MaxFlow::addE(1, i + 1);
		for(int j=0;j<szz(R[i]);j++) {
			if(R[i][j] != 1) MaxFlow::addE(i+1, N + R[i][j] - 1);
		}
	}
	for(int i=1;i<N;i++) MaxFlow::addE(N + i, 2 * N);
	int r = MaxFlow::Get(2*N, 1, 2*N);
	if(r != N - 1) {
		puts("-1");
		return 0;
	}
	for(int i=2;i<=N;i++) {
		for(int j=MaxFlow::st[i];j;j=MaxFlow::nxt[j]) {
			int e = MaxFlow::en[j];
			if(N+1 <= e && e < 2*N && MaxFlow::flow[j] == 0) V[i-1] = e - N + 1;
		}
	}
	for(int i=1;i<N;i++) for(int e : R[i]) if(e != V[i]) L[e].pb(i);
	vector <int> q;
	for(int e : L[1]) {
		W[e] = 1; mark[e] = 1;
		q.pb(e);
	}
	rep(i, szz(q)) {
		int t = q[i];
		int v = V[t];
		for(int e : L[v]) {
			if(mark[e] == 0) {
				W[e] = v;
				mark[e] = 1;
				q.pb(e);
			}
		}
	}
	if(szz(q) < N - 1) puts("-1");
	else {
		for(int i=1;i<N;i++) printf("%d %d\n", V[i], W[i]);
	}
	
	return 0;
}


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

int main() {
	int X;
	cin >> X;
	int G = 0;
	int g = 0;

	
	G = X / 500;
	g = X % 500 /5;

	cout << G * 1000 + g * 5 << endl;

	return 0;

	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
//#define local
#ifdef local
#include "dbg-macro/dbg.h"
#endif
#define ll long long
#define pi (acos(-1))
#define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i)
using namespace std;
std::vector<unsigned ll> genprimevec(const unsigned ll N);


int main()
{int n;cin>>n;
	vector<int>vec(n);
	unsigned ll m=69696969696969669;
	rep(i,n){
		cin>>vec[i];
	}
	ll ans=0;
	rep(i,n){
	m=min(m,static_cast<unsigned ll>(vec[i]));
		if(vec[i]==m){++ans;}
	}
	cout<<ans<<endl;
    return 0;
}

ll extgcd(ll a, ll b, ll &x, ll &y)
{
    if (b == 0)
    {
        x = 1, y = 0;
        return a;
    }
    ll d = extgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}


std::vector<unsigned ll> genprimevec(const unsigned ll N)
{
    std::vector<bool> is_prime(N + 1);
    for (unsigned ll i = 0; i <= N; i++) { is_prime[i] = true; }
    std::vector<unsigned ll> P;
    for (unsigned ll i = 2; i <= N; i++)
    {
        if (is_prime[i])
        {
            for (unsigned ll j = 2 * i; j <= N; j += i) { is_prime[j] = false; }
            P.emplace_back(i);
        }
    }
    return P;
}


Measured memory_bytes: 4036
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

#if DEBUG && !ONLINE_JUDGE
    ifstream input_from_file("input.txt");
    #define cin input_from_file
#else

#endif



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); // Togliere nei problemi con query online

    int X, N;
    cin >> X >> N;
    vector<bool> presi(102, false);
    for (int i = 0; i < N; i++) {
        int p;
        cin >> p;
        presi[p] = true;
    }
    int atbest = 0;
    for (int i = 0; i <= 101; i++) {
        if (presi[i]) continue;
        if (abs(X-i) < abs(X-atbest)) atbest = i;
    }
    cout << atbest << "\n";
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
 
int main(){
    fast;
    ll a, b, c, n;
    cin >> n;
    ll cnt = 0;
    while(n > 0){
        ll ans = n%10;
        if(ans == 7)
            cnt++;
        n =n/10;
    }
    if(cnt > 0)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}
//                                     #!!{*[$um1t_Kum@r]*}!!#

Measured memory_bytes: 3640
#include<stdio.h>

int main() {
	char a[4];
	gets(a);
	int f = 0;
	for (int i = 0; i < 3; i++)
		if (a[i] == '7')
			f = 1;
	if (f)
		printf("Yes");
	else
		printf("No");
	
}


Measured memory_bytes: 1644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	bool ch=true;
	for(ll i=0;i<n;i++){
		ll now;
		cin>>now;
		if(now%2==0){
			if(now%3!=0&&now%5!=0){
				ch=false;
			}
		}
	}
	if(ch){
		cout <<"APPROVED";
	}
	else{
		cout << "DENIED";
	}
	// your code goes here
	return 0;
}

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

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	long long int tc,k,a[100005];
	while(cin>>tc>>k){
		for(int i=0;i<tc;i++){
			cin>>a[i];
		}
		sort(a,a+tc);
		long long ma=9e18;
		for(int i=0;i<=tc-k;i++){
			//cout<<a[i+k-1]<<' '<<a[i]<<endl;
			ma=min(ma,a[i+k-1]-a[i]);
		}
		cout<<ma<<endl;
	}
} 

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<math.h>
#include<numeric>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
//scanf("%d", &a); '\n';

int main() {
	//ios::sync_with_stdio(false);
	//cin.tie(0);
	int h, n;
	cin >> h >> n;
	vector<int> dp(h + 1, MOD);
	dp[0] = 0;
	rep(i, n) {
		int a, b;
		scanf("%d", &a); '\n';
		scanf("%d", &b); '\n';
		rep(j, h) {
			int nj = min(j + a, h);
			dp[nj] = min(dp[nj], dp[j] + b);
		}
	}
	cout << dp[h];
}



Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;

const int N = 309;

int d[N][N];
int f[N][N];
int q[N];

int main() {
  int n, m, l;
  scanf("%d%d%d", &n, &m, &l);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      d[i][j] = 1'000'000'009;
    }
  }
  for (int i = 0; i < m; ++i) {
    int x, y, c;
    scanf("%d%d%d", &x, &y, &c);
    --x;
    --y;
    d[x][y] = c;
    d[y][x] = c;
  }
  for (int k = 0; k < n; ++k) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  for (int from = 0; from < n; ++from) {
    for (int i = 0; i < n; ++i) {
      f[from][i] = -1;
    }
    f[from][from] = 0;
    q[0] = from;
    for (int qh = 0, qt = 1; qh < qt; ++qh) {
      int x = q[qh];
      for (int y = 0; y < n; ++y) {
        if (d[x][y] > l || f[from][y] != -1) {
          continue;
        }
        f[from][y] = f[from][x] + 1;
        q[qt++] = y;
      }
    }
    for (int i = 0; i < n; ++i) {
      if (f[from][i] > 0) {
        --f[from][i];
      }
    }
  }
  int qq;
  scanf("%d", &qq);
  while (qq--) {
    int from, to;
    scanf("%d%d", &from, &to);
    --from;
    --to;
    printf("%d\n", f[from][to]);
  }
}


Measured memory_bytes: 1152
n=int(raw_input())
a=[int(raw_input()) for _ in xrange(n)]*3

dp=[[0]*(3*n) for _ in xrange(3*n)]
for i in xrange(3*n):
    if (n-1)%2==0:
        dp[i][i]=a[i]

for d in xrange(1,n):
    for l in xrange(2*n):
        r=l+d
        if (r-l)%2==(n-1)%2:
            dp[l][r]=max(dp[l+1][r]+a[l],dp[l][r-1]+a[r])
        else:
            if a[l]>a[r]:
                dp[l][r]=dp[l+1][r]
            else:
                dp[l][r]=dp[l][r-1]

ans=0
for i in xrange(n):
    ans=max(ans,dp[i][i+n-1])
print(ans)

Measured memory_bytes: 384192
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll=long long;

int main(){
    ll i,j,n,m;
    double r;
    cin>>r;
    cout<<setprecision(15)<<2*r*M_PI;


    return 0;
}



Measured memory_bytes: 3780
n,a,b=map(int, input().split())

if a==0:
    print(0)
    
elif b==0:
    print(n)
    
else:
    
    quo=n//(a+b)
    
    #商
    if n%(a+b)==0:
        rem=0
    elif  1<=n%(a+b)<=a:
        rem=n%(a+b)
    else:
        rem=a
        
    print(quo*a+rem)

Measured memory_bytes: 9188
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = scan.nextInt();
        Arrays.sort(a);
        int ans = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                if (a[j] == a[i]) continue;
                for (int k = j + 1; k < n; k++) {
                    if (a[k] == a[j]) continue;
                    if (a[i] + a[j] > a[k]) ans++;
                }
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 36052
package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)

//=====I/O=====

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

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

func scanInt64() int64 {
	sc.Scan()
	a,_ := strconv.ParseInt(sc.Text(),10,64)
	return a
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//=====main=====

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 100000000)

	n,m := scanInt(), scanInt()
	s := scanText()

	l := make([]int, n+1)

	c := 1
	p := n
	for p > 0 {
		next := p
		for j := 1; j < m+1; j++ {
			if p-j < 0 {
				break
			}

			if s[p-j] == '0' {
				l[p-j] = c
				next = p-j
			} else {
				l[p-j] = c
			}
		}

		if next == p {
			fmt.Println(-1)
			return
		}

		p = next
		c++
	}
	
	cnt := 1

	for i := 0; i < n; i++ {
		if l[i] == l[i+1] {
			cnt++
		} else {
			fmt.Fprint(wr, cnt)
			cnt = 1
			if i != n {
				fmt.Fprint(wr, " ")
			} else {
				fmt.Fprintln(wr)
			}
		}
	}

	wr.Flush()
}


Measured memory_bytes: 4480
def main():
    from collections import Counter
    from itertools import combinations

    n, *s = map(lambda x: str(x)[0], open(0).read().split())
    c = Counter(s)

    m = [c.get(x) if c.get(x) != None else 0 for x in ["M", "A", "R", "C", "H"]]
    ans = sum(i * j * k for (i, j, k) in combinations(m, 3))
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 11412
using System;
using System.Collections.Generic;
using System.Linq;

class Procon
{
    public Procon() { }
    static void Main(string[] agrs)
    {
        new Procon().Do();
    }

    Scanner cin;

    public void Do()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        long X = cin.nextLong();
        long[] x = new long[N];

        for (int i = 0; i < N; i++)
        {
            long tmp = cin.nextLong();
            x[i] = Math.Abs(tmp - X);
        }

        long ret = x[0];
        for (int i = 1; i < N; i++)
        {
            ret = gcd(x[i], ret);
        }

        Console.WriteLine(ret);
    }

    long gcd(long a, long b)
    {
        long tmp;
        if (b > a)
        {
            tmp = a;
            a = b;
            b = tmp;
        }

        if (b == 0)
        {
            return a;
        }

        return gcd(b, a % b);
    }
}

class Scanner
{
    string[] s;
    int i;
    int max_i;

    public Scanner()
    {
        s = new string[0];
        max_i = 0;
        i = 0;
    }

    public string nextString()
    {
        if (i >= s.Length)
        {
            s = Console.ReadLine().Split(' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0)
            {
                return "";
            }
            return s[i++];
        }
        else
        {
            return s[i++];
        }
    }

    public int nextInt()
    {
        return int.Parse(nextString());
    }


    public long nextLong()
    {
        return long.Parse(nextString());
    }

    public double nextDouble()
    {
        return double.Parse(nextString());
    }

    public string[] arrayString()
    {
        return Console.ReadLine().Split(' ');
    }

    public int[] arrayInt()
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] array = new int[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = int.Parse(str[i]);
        }
        return array;
    }

    public long[] arrayLong()
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] array = new long[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = long.Parse(str[i]);
        }
        return array;
    }

    public double[] arrayDouble()
    {
        string[] str = Console.ReadLine().Split(' ');
        double[] array = new double[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = double.Parse(str[i]);
        }
        return array;
    }
}



Measured memory_bytes: 18784
#!/usr/bin/env python
N, M = map(int, input().split())
d = {}
for i in input().split():
    d[int(i)] = d.get(int(i), 0) + 1
for i in range(M):
    b, c = map(int, input().split())
    d[c] = d.get(c, 0) + b
cnt = 0
ans = 0
for key, item in sorted(d.items(), key=lambda x:-x[0]):
    if cnt + item <= N:
        ans += key * item
        cnt += item
    else:
        ans += key * (N - cnt)
        break
print(ans)

Measured memory_bytes: 49596
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

typedef pair<int,int> pint;
int N, M;

int main() {
    while (cin >> N >> M) {
        set<pint> se;
        for (int i = 0; i < M; ++i) {
            int a, b;
            cin >> a >> b;
            se.insert(pint(a,b));
            se.insert(pint(b,a));
        }
        
        bool ok = false;
        for (int i = 1; i <= N; ++i) {
            if (se.count(pint(1, i)) && se.count(pint(i, N))) ok = true;
        }
        if (ok) puts("POSSIBLE");
        else puts("IMPOSSIBLE");
    }
}










Measured memory_bytes: 18944
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,d,e,k;
  	cin >> a >> b >> c >> d >> e >> k;
 	if(abs(a-b)<=k && abs(a-c)<=k && abs(a-d)<=k && abs(a-e)<=k && abs(b-c)<=k && abs(b-d)<=k && abs(b-e)<=k && abs(c-d)<=k && abs(c-e)<=k && abs(d-e)<=k)
    {cout << "Yay!" << endl;
    }
  	else{
    cout << ":(" << endl;
    }
}

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

int main(){
  int a,b;
  cin >> a >> b;
  int plus = a+b;
  int minus = a-b;
  int multi = a*b;
  int ans = max(plus,max(minus,multi));
  cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;

class Solve
{
    static void Main(string[] args) {
        var N = int.Parse(Console.ReadLine());
        var h = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var dp = new int[N];
        dp[0] = 0;
        dp[1] = Math.Abs(h[1] - h[0]);
        for (int i = 2; i < N; i++) {
            dp[i] = Math.Min(dp[i - 1] + Math.Abs(h[i] - h[i - 1]), dp[i - 2] + Math.Abs(h[i] - h[i - 2]));
        }
        var answer = dp[^1];
        var writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();
    }
}

Measured memory_bytes: 35096
def main():
    n = int(input())
    x = list(map(int, input().split()))
    mod = 10**9 + 7
    X = []
    for i in range(n - 1):
        X.append(x[i + 1] - x[i])
    l, left = 1, [1]
    for i in range(1, n - 1):
        l *= i
        l %= mod
        left.append(l)
    r, right = 1, [1]
    for i in range(n - 1, 1, -1):
        r *= i
        r %= mod
        right.append(r)
    right.reverse()
    f, flst = 0, []

    for i, j in zip(left, right):
        f += i * j % mod
        f %= mod
        flst.append(f)
    s = 0
    for i, j in zip(X, flst):
        s += i * j % mod
    print(s % mod)
main()


Measured memory_bytes: 23112
import java.io.PrintStream;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;

public class Main {
	static boolean debug = true;
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		// write here
		int A=sc.nextInt();
		int B=sc.nextInt();
		int C=sc.nextInt();
		String res="No";
		if(C>=A&&C<=B)
			res="Yes";
		System.out.println(res);
		
	}

	private static void print(String string) {
		// TODO Auto-generated method stub
		if (debug)
			System.out.println(string);
	}

	private static void print(int[] data) {
		if (debug) {
			for (int i = 0; i < data.length; i++)
				System.out.println(i + ":" + data[i]);
		}
	}

	private static void print(String[] data) {
		if (debug) {
			for (int i = 0; i < data.length; i++)
				System.out.println(i + ":" + data[i]);
		}
	}

	private static void print(char[] data) {
		if (debug) {
			for (int i = 0; i < data.length; i++)
				System.out.println(i + ":" + data[i]);
		}
	}

	private static void print(double[] data) {
		if (debug) {
			for (int i = 0; i < data.length; i++)
				System.out.println(i + ":" + data[i]);
		}
	}

	private static void print(int[][] data) {

		if (debug) {
			for (int i = 0; i < data.length; i++) {
				for (int j = 0; j < data.length; j++) {
					System.out.print(i + " " + j + ":" + data[i]);
				}
				System.out.println();
			}
		}
	}

	private static void print(char[][] data) {

		if (debug) {
			for (int i = 0; i < data.length; i++) {
				for (int j = 0; j < data.length; j++) {
					System.out.print(i + " " + j + ":" + data[i][j] + " ");
				}
				System.out.println();
			}
		}
	}

	private static void print(String[][] data) {

		if (debug) {
			for (int i = 0; i < data.length; i++) {
				for (int j = 0; j < data.length; j++) {
					System.out.print(i + " " + j + ":" + data[i][j] + " ");
				}
				System.out.println();
			}
		}
	}

	private static void print(double[][] data) {

		if (debug) {
			for (int i = 0; i < data.length; i++) {
				for (int j = 0; j < data.length; j++) {
					System.out.print(i + " " + j + ":" + data[i][j] + " ");
				}
				System.out.println();
			}
		}
	}

	public static void inPutData(char[][] c) {
		for (int i = 0; i < c.length; i++) {
			c[i] = sc.nextLine().toCharArray();
		}
	}

}


Measured memory_bytes: 21844
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    if(a > b) {
      System.out.println(a - 1);
    }
    else {
      System.out.println(a);
    }
  }
}

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

namespace ConsoleApp14
{
	class Program
	{
		static void Main(string[] args)
		{
			string input = Console.ReadLine();
			int n = int.Parse(input);
			int lastdigit = n % 10;
			if (lastdigit == 2 || lastdigit == 4 || lastdigit == 5 || lastdigit == 7 || lastdigit == 9)
			{
				Console.WriteLine("hon");
			}
			else if	(lastdigit == 0 || lastdigit == 1 || lastdigit == 6 || lastdigit == 8)
			{
				Console.WriteLine("pon");
			}
			else
			{

				Console.WriteLine("bon");

			}
		
		}
	}
}


Measured memory_bytes: 27376
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <vector>
#include <sstream>
#include <string>
#include <cstdio>
#include <array>

using namespace std;

int main(void) {
    int N;
    cin >> N;
    int a[N];
    int i,j,k;
    
    for(i=0; i<N; i++) {
        cin >> a[i];
    }
    
    //display a[]
    for(k=0; k<N; k++) {
        if(k==0) cout << a[k];
        else cout << " " << a[k];
    }
    cout << endl;


    for(i=1; i<N; i++) {
        
        int key = a[i];
        for(j=i-1; j>=0 && a[j]>key; j--) {
            a[j+1] = a[j];
        }
        a[j+1] = key; //j??????1?????????????¨???????????????????????????§
        
        //display a[]
        for(k=0; k<N; k++) {
            if(k==0) cout << a[k];
            else cout << " " << a[k];
        }
        cout << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3076
#include <iostream>
#include <set>
#include <map>
#include <array>
#include <cassert>
#include <cstring>
#include <vector>
#include <list>
#include <algorithm>

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
#define eb emplace_back
#define pb push_back
#define mp make_pair

template <typename T>
bool uax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template <typename T>
bool uin(T& a, T b) { if (b < a) { a = b; return true; } return false; }

using namespace std;

typedef pair<int, int> pii;
typedef vector<pii> vpi;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef list<int> li;
typedef vector<li> vli;
typedef vector<vpi> vvpi;
typedef long long i64;

const int inf = 1e9;

void solve_a() {
  int a,b,c;
  cin >> a >> b >> c;
  i64 k;
  cin >> k;
  // a, b, c = a-b
  // b+c, a+c, a+b = b-a
  // 2a+b+c, 2b+a+c, 2c+a+b = a-b
  // 2a+3b+3c, 3a+2b+3c, 3a+3b+2c = b-a
  a = (k & 1) ? b - a : a - b;
  cout << a << endl;
}

int main() {
#ifdef HOME
  freopen("input.txt", "rt", stdin);
#endif
  solve_a();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pie 3.142857143
#define ll long long int
#define fr(i,a,n) for(ll i=a;i<n;i++)
#define vi vector<int>
#define vlli vector<ll>
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fv(i,a) for(auto i:a)
#define sz(a) int((a).size())
#define all(c) (c).begin(),(c).end()
#define frv(i,c) for(auto i = c.begin(); i != c.end(); i++)

void solve()
{
	ll x, n, f = 0;
	cin >> x >> n;

	if (n == 0)
		cout << x << endl;
	else {
		map<int, int>m;
		int a[n];
		fr(i, 0, n) {
			cin >> a[i];
			m[a[i]]++;
		}
		ll j = 0;
		while (f == 0)
		{
			if (m[x - j] == 0)
			{
				cout << x - j << endl;
				f = 1;
			}
			else if (m[x + j] == 0)
			{
				cout << x + j << endl;
				f = 1;
			}
			else
				j++;
		}
	}
}


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);
	int t;
	//cin>>t;
	t = 1;
	while (t--)
	{
		solve();
	}


	return 0;
}

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

int main(){
  int a,b,c,d,e,k,n;
  n=1;
  cin >> a >> b >> c >> d >> e >> k;
  vector<int> vec ={a,b,c,d,e};
  for(int i=0; i < 5; i++){
    for(int j=i+1; j < 5; j++){
      int x = vec.at(j) - vec.at(i);
      if(x > k){
      n=0;
      break;}
    }
    if(n == 0){
      cout << ":(" << endl;
      break;
    }
  }
      if(n == 1)
      cout << "Yay!" << endl;
      }

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int[] arr = new int[n + 1];
			for (int i = 0; i < n; i++) {
				arr[i + 1] = sc.nextInt();
			}

			int count = 0;
			int light = 1;
			int tmp;
			do {
				count++;
				tmp = arr[light];
				if (tmp == 0) {
					System.out.println("-1");
					return;
				}
				arr[light] = 0;
				light = tmp;
			} while (light != 2);
			System.out.println(count);
		}
	}
}


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

int main(){
    int n, ans = INT_MAX;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    for(int i = a[0]; i <= a[n - 1]; i++){
        int tmp = 0;
        for(int j = 0; j < n; j++){
            tmp += (a[j] - i) * (a[j] - i);
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}


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

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

int main() {

  while(1){
    int N;
    cin>>N;
    if(N==0) break;
    int M, t;
    set<int> s[105];
    REP(i,1,N+1){
      cin>>M;
      REP(j,0,M){
        cin>>t;
        s[i].insert(t);
      }
    }
    int K;
    set<int> chs;
    cin>>K;
    REP(i,0,K){
      cin>>t;
      chs.insert(t);
    }

    int cnt=0, ans;
    REP(i,1,N+1){
      bool flag = true;
      set<int>::iterator it = chs.begin();
      while(it != chs.end()){
        if(s[i].find(*it) == s[i].end()){
          flag = false;
          break;
        }
        it++;
      }
      if(flag) cnt++, ans=i;
    }

    if(cnt == 1) cout<<ans<<endl;
    else cout<<-1<<endl;
  }

  return 0;
}

Measured memory_bytes: 3480
def main():
    num = int(input())
    data = list(map(int, input().split()))
    max_num = max(data)

    ans_data = []

    while data != []:
        for i in range(max_num)[::-1]:
            if i >= len(data):
                continue
            if data[i] == i + 1:
                ans_data.append(i + 1)
                data.pop(i)
                break
        else:
            break

    if len(data) == 0:
        for ele in ans_data[::-1]:
            print(ele)
    else:
        print(-1)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064