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

using namespace std;

int main()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	vector<int> a,b;
	map<int,int> m;
	for(int i=0;i<n;i++){
		if(s[i]=='R') a.push_back(i);
		else if(s[i]=='G') b.push_back(i);
		else if(s[i]=='B') m[i]++;
	}
	int c = n-(a.size()+b.size());
	long long ans = a.size()*b.size()*c;
	for(int i=0;i<a.size();i++){
		for(int j=0;j<b.size();j++){
			int mn = min(a[i],b[j]);
			int mx = max(a[i],b[j]);
			int d = mx-mn;
			if(d%2==0){
				int x = d/2;
				if(m[mn+x]>0) ans--;
			}
			if(m[mn-d]>0) ans--;
			if(m[mx+d]>0) ans--;
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 4204
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

int main(){
  ll x;
  cin >> x;

  if(x % 11 == 0){
    cout << x / 11 * 2;
    return 0;
  }

  if(x % 11 <= 6){
    cout << x / 11 * 2 + 1;
    return 0;
  }
  cout << x / 11 * 2 + 2;
  return 0;
}


Measured memory_bytes: 256
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    sumA = sum(A)
    
    for i in range(N):
        res = B[i]
        if A[i] > 0 and res != 0:
            A[i], res = max(A[i] - res, 0), max(res - A[i], 0)

        if A[i+1] > 0 and res != 0:
            A[i+1], res = max(A[i+1] - res, 0), max(res - A[i+1], 0)
    
    print(sumA - sum(A))
    return

resolve()

Measured memory_bytes: 24128
def resolve():
    m,d = map(int, input().split())
    count = 0

    for i in range(1,m+1):
        for j in range(1,d+1):
            d1 = j % 10
            d10 = j // 10
            if d1 >= 2 and d10 >= 2 and d1 * d10 == i:
                count += 1

    print(count)



resolve()

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

#define LL long long

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	LL a,b;
	cin >> a >> b;
	LL curr = 1;
	LL res = 0;
	while (curr < b){
		res++;
		curr += (a-1);
	}
	cout << res << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>

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

int main(){
    int n;
    cin >> n;
    vector<vector<int>> g(n, vector<int>(n));
    rep(i, n)rep(j, n) g[i][j] = -1;
    rep(i, n) {
        int m;
        cin >> m;
        rep(j, m) {
            int a, x;
            cin >> a >> x;
            --a;
            g[i][a] = x;
        }
    }
    int ans = 0;
    rep(i, 1<<n) {
        vector<int> d(n);
        rep(j, n) if ( i>>j & 1 ) {
            d[j] = 1;
        }
        bool ok = true;
        rep(j, n) {
            if ( d[j] ) {
                rep(k, n) {
                    if (g[j][k] == -1 ) continue;
                    if (g[j][k] != d[k] ) ok = false; 
                }
            }
        }
        int cnt = 0;
        if ( ok ) {
            for ( auto tmp_d : d ) {
                if ( tmp_d ) ++cnt;
            }
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<list> 
using namespace std;
static const int MAX = 100000;

vector<int> G[MAX];
list<int> out;
bool V[MAX];
int N;

void dfs(int u) {
    V[u] = true;
    for(int i = 0; i < G[u].size(); i++) {
    	int v = G[u][i];
    	if(!V[v]) dfs(v);
    }
    out.push_front(u);
}


int main() {
	int s, t, M;
	
	cin >> N >> M;
	
	for(int i = 0; i < N; i++) V[i] = false;

    for(int i = 0; i < M; i++) {
    	cin >> s >> t;
    	G[s].push_back(t);
    }
    
    for(int i = 0; i < N; i++) {
    	if(!V[i]) dfs(i);
    }
    
    for(list<int> ::iterator it = out.begin(); it != out.end(); it++) {
    	cout << *it << endl;
    }
    
    return 0;
} 

Measured memory_bytes: 6016
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <set>
#include <queue>
#include <limits>
#include <deque>
#include <locale>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <wchar.h>
#include <wctype.h>
#include <algorithm>
#include <bitset>
#include <map>
#include <iomanip>
#include <ios>
#include <iostream>
#include <vector>
#include <cwchar>
#include <cwctype>
#define mp make_pair
#define fs first
#define se second
#define memset(a,t) memset(a,t,sizeof(a))
#define all(v) v.begin(),v.end()
#define MN 0LL
#define Mx 200000005
#define Mn -Mx
#define MX 20000000000000005
using namespace std;
int readint(){
	char c;
	while(c=getchar(),(c<'0'||c>'9')&&c!='-');
	bool flag=(c=='-');
	if(flag)c=getchar();
	int x=0;
	while(c>='0'&&c<='9'){
		x=x*10+c-48;
		c=getchar();
	}
	return flag?-x:x;
}
inline string tos(int x){
	string s;
	while(x) s=(char)(x%10+'0')+s,x/=10;
	return s;
}
inline int toi(string s){
	int rt=0;
	for(int i=0;i<s.size();i++) rt=rt*10+(int)(s[i]-'0');
	return rt;
}
int main(){
	int i,j;
	string a,b,c;
	cin>>a>>b>>c;
	cout<<a[0]<<b[1]<<c[2]<<endl;
	return 0;
}


Measured memory_bytes: 256
import sys
import socket

hostname = socket.gethostname()

if hostname == 'F451C':
    sys.stdin = open('a1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    r = read_int()
    if r < 1200:
        print('ABC')
    elif r >= 2800:
        print('AGC')
    else:
        print('ARC')


main()


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

using namespace std;

int main() {
    int n, k, d[1000]={}, a[1000][1000]={}, i, j, snuk[1000]={};
    cin>>n>>k;
    for(i=1;i<=n;i++)
    {
        cin>>d[i];
        for(j=1;j<=d[i];j++)
        {
        cin>>a[i][j];
        snuk[a[i][j]]++;
        }
    }
    int dap=0;
    for(i=1;i<=n;i++)
    dap+=(snuk[i]==0);
    cout<<dap;
    
    return 0;
}

Measured memory_bytes: 7544
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int N;
	cin >> N;
	
	vector<int> X(N), Y(N);
	vector<char> U(N);
	
	map<char, int> conv;
	char conv_table[5] = "URDL";
	REP(i, 4) conv[conv_table[i]] = i;
	
	REP(i, N) {
		char c;
		scanf("%d %d %c", &X[i], &Y[i], &c);
		U[i] = c;
	}
	
	map<int, vector<pii>> lr, ud, ru, rd;
	REP(i, N) {
		lr[Y[i]].emplace_back(X[i], U[i]);
		ud[X[i]].emplace_back(Y[i], U[i]);
		ru[X[i] - Y[i]].emplace_back(X[i], U[i]);
		rd[X[i] + Y[i]].emplace_back(X[i], U[i]);
	}
	
	int ans = INF;
	for (auto &it : lr) {
		vector<pii> v = it.se;
		vector<int> ord(v.size());
		iota(ALL(ord), 0);
		sort(ALL(ord), [&](int i, int j) {
			return v[i].fi < v[j].fi;
		});
		int last = -INF;
		for (int i : ord) {
			if (v[i].se == 'R') last = v[i].fi;
			else if (v[i].se == 'L' && last != -INF) chmin(ans, (v[i].fi - last) * 5);
		}
	}
	for (auto &it : ud) {
		vector<pii> v = it.se;
		vector<int> ord(v.size());
		iota(ALL(ord), 0);
		sort(ALL(ord), [&](int i, int j) {
			return v[i].fi < v[j].fi;
		});
		int last = -INF;
		for (int i : ord) {
			if (v[i].se == 'U') last = v[i].fi;
			else if (v[i].se == 'D' && last != -INF) chmin(ans, (v[i].fi - last) * 5);
		}
	}
	for (auto &it : ru) {
		vector<pii> v = it.se;
		vector<int> ord(v.size());
		iota(ALL(ord), 0);
		sort(ALL(ord), [&](int i, int j) {
			return v[i].fi < v[j].fi;
		});
		int lastu = -INF, lastr = -INF;
		for (int i : ord) {
			if (v[i].se == 'U') lastu = v[i].fi;
			else if (v[i].se == 'R') lastr = v[i].fi;
			else if (v[i].se == 'D' && lastr != -INF) chmin(ans, (v[i].fi - lastr) * 10);
			else if (v[i].se == 'L' && lastu != -INF) chmin(ans, (v[i].fi - lastu) * 10);
		}
	}
	for (auto &it : rd) {
		vector<pii> v = it.se;
		vector<int> ord(v.size());
		iota(ALL(ord), 0);
		sort(ALL(ord), [&](int i, int j) {
			return v[i].fi < v[j].fi;
		});
		int lastr = -INF, lastd = -INF;
		for (int i : ord) {
			if (v[i].se == 'R') lastr = v[i].fi;
			else if (v[i].se == 'D') lastd = v[i].fi;
			else if (v[i].se == 'U' && lastr != -INF) chmin(ans, (v[i].fi - lastr) * 10);
			else if (v[i].se == 'L' && lastd != -INF) chmin(ans, (v[i].fi - lastd) * 10);
		}
	}
	
	if (ans == INF) puts("SAFE");
	else cout << ans << endl;
	return 0;
}


Measured memory_bytes: 73712
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;

void main() {
	int n;
	scanf("%d\n", &n);
	auto ls = readln.chomp.split.to!(long[]);
	ls.sort!"a<b";
	long[2*1000+1] cache;
	foreach(ref x; cache) {
		x = -1;
	}
	foreach(i, l; ls) {
		cache[l] = i;
	}
	long t = 0;
	foreach(ref x; cache) {
		if (x == -1) {
			x = t;
		}
		else {
			t = x;
		}
	}
	size_t cnt = 0;
	foreach(i, a; ls) {
		foreach(j, b; ls[i+1..$]) {
			cnt += max(cache[a+b-1]-j-i-1, 0);
		}
	}
	cnt.write;
}


Measured memory_bytes: 2428
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define _ << " " <<
#define all(v) v.begin(), v.end()

using namespace std;
using ll = long long;

const int mod = 1000000007;

bool bin_search(vector<ll>& a, ll v) {
	int l = 0, r = a.size() - 1;
	while (l <= r) {
		int m = (l + r) / 2;
		if (a[m] == v)  return true;
		if (a[m] < v) l = m + 1;
		else r = m - 1;
	}
	return false;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin >> s;
	int a = stoi(s.substr(0, 2)), b = stoi(s.substr(2, 2));
	if ((a == 0 || a > 12) && b > 0 && b < 13) cout << "YYMM\n";
	else if (a > 0 && a < 13 && (b == 0 || b > 12)) cout << "MMYY\n";
	else if (a > 0 && b > 0 && a < 13 && b < 13) cout << "AMBIGUOUS\n";
	else cout << "NA\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;

int main(){
    ll n , m ; cin >> n >> m;
    vector<bool> chk(n,false);
    rep(i,m){
        ll a,b ; cin >> a >> b;
        a--; b--;
        chk.at(a) = !chk.at(a);
        chk.at(b) = !chk.at(b);        
    }
    bool flag = true;
    rep(i,n){
        if(chk.at(i)) flag = false;        
    }
    if(flag){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}


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

#define vi vector<int>
#define vii vector<vi>
#define pi pair<int,int>
#define vpi vector<pi>
#define S second
#define F first
#define pb push_back
#define inf 100000000000
#define Test int t,i=0;cin>>t;while(i<t)
#define MAXN 100005
#define M 100005
#define int long long int

signed main()
{
    int n,k,i,j;
    cin>>n>>k;
    int a[n],dp[n+2];
    for(i=0;i<n;i++)
        {
            cin>>a[i];
            dp[i] = inf;
        }
    dp[0] = 0;dp[0] = 0;
    for(i=0;i<n;i++)
        for(j=1;j<=k;j++)
            if(i+j<n)
                dp[i+j] = min(dp[i+j],dp[i]+abs(a[i+j]-a[i]));
    cout<<dp[n-1]<<"\n";
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

int main(){
    int N, T;
    cin >> N >> T;
    int c[101];
    int t[101];
    for(size_t i = 0; i < N; i++)
    {
        cin >> c[i] >> t[i];
    }
    int min = 1001;
    for(size_t i = 0; i < N; i++)
    {
        if (t[i] <= T)
            if (c[i] <= min)
                min = c[i];
    }
    if (min == 1001)
        cout << "TLE" << endl;
    else
        cout << min << endl;
    
    return 0;
}

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

typedef struct{
    int to, c, rev;
}Edge;

class FordFulkerson{
private:
    int V;
    vector<vector<Edge>> G;
    
public:
    FordFulkerson(int V): V(V){
        G.resize(V);
    }
    void add_edge(int u, int v, int c){
        G[u].push_back({v, c, (int)G[v].size()});
        G[v].push_back({u, 0, (int)G[u].size()-1});
    }
    int dfs(int u, int t, int f, vector<bool> &visited){
        if(t == u)
            return f;
        
        visited[u] = true;
        
        for(auto &edge: G[u]) if(!visited[edge.to] && edge.c > 0){
            int d = dfs(edge.to, t, min(f, edge.c), visited);
            if(d > 0){
                edge.c -= d;
                G[edge.to][edge.rev].c += d;
                return d;
            }
        }
        return 0;
    }
    int max_flow(int s, int t){
        int res = 0;
        while(true){
            vector<bool> visited(V);
            int f = dfs(s, t, 1<<30, visited);
            if(f == 0)
                break;
            res += f;
        }
        return res;
    }
};

int V, E;

int main(){
    cin >> V >> E;
    FordFulkerson ff(V);
    for(int i=0; i<E; i++){
        int u, v, c;
        cin >> u >> v >> c;
        ff.add_edge(u, v, c);
    }
    
    cout << ff.max_flow(0, V-1) << endl;
    
    return 0;
}

Measured memory_bytes: 3152
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#define INF 1000000000
#define MOD 1000000007

using namespace std;

int main()
{
    string map[105];
    string cmp;
    int h, w;

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

    for(int i = 0; i < w; i++) {
        cmp += '.';
    }

    for(int i = 0; i < h; i++) {

        if(map[i] != cmp) {
            for (int j = 0; j < w; j++) {
                int k;
                k = 0;
                while (map[k][j] == '.' && k < h) {
                    k++;
                }

                if (k < h) {
                    cout << map[i][j];
                }
            }

            cout << endl;
        }
    }




    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    cout << max(0, c - (a - b)) << endl;
}


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

namespace ConsoleApplication13
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                // 山札を入力
                string strInputCards = Console.ReadLine();

                // 入力は"-"の場合終了
                if (strInputCards == "-")
                {
                    break;
                }

                else
                {
                    // 出力用文字列に入力文字列を代入
                    string strResultCards = strInputCards;

                    // 試行回数を入力
                    int intInputTryNum = int.Parse(Console.ReadLine());

                    for (int num = 0; num < intInputTryNum; num++)
                    {
                        // シャッフル回数を入力
                        int intInputShuffleNum = int.Parse(Console.ReadLine());
                        // シャッフル後の文字列生成
                        strResultCards = strResultCards.Substring(intInputShuffleNum) + strResultCards.Substring(0, intInputShuffleNum);
                    }

                    // 出力
                    Console.WriteLine(strResultCards);
                }
            }
        }
    }
}



Measured memory_bytes: 17880
using System;
using static System.Console;
using static System.Math;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{   
    class Template
    {
        static void Main(string[] args)
        {
            int N = IO.ReadInt();
            int[] T = IO.ReadIntArr();

            int M = IO.ReadInt();
            while(M-- > 0)
            {
                var @in = IO.ReadIntArr();
                int P = @in[0];
                int X = @in[1];
                
                WriteLine(T.Sum() - T[P-1] + X);
            }
        }
    }

    public class IO
    {
        public static string ReadStr() => Console.ReadLine();
        public static string[] ReadStrArr() => ReadStr().Split(' ');
        public static int ReadInt() => int.Parse(ReadStr());
        public static int[] ReadIntArr() => Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        public static double ReadDouble() => double.Parse(ReadStr());
        public static double[] ReadDoubleArr() => Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);
        public static long ReadLong() => long.Parse(ReadStr());
        public static long[] ReadLongArr() => Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
    }
}


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

int main() {
    //freopen( "in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, sum = 0;
    cin >> n >> m;
    for( int i = 0; i<m; i++) {
        int x;
        cin >> x;
        sum+=x;
    }
    if ( n >=sum) cout << n-sum << '\n';
    else cout << -1 << '\n';
    return 0;
}


Measured memory_bytes: 3652
//
// Created by 清水ヒロシ on 2018/11/19.
//
// from ALDS1_1_A: Insertion Sort
//

#include <iostream>

using namespace std;

void insertSort();
void traceBuffer(const int *buffer, int len);

int main()
{
    insertSort();
    return 0;
}

void insertSort()
{
    int N;
    cin >> N;
    int *buffer = new int[N];
    for (int i=0; i<N; ++i) {
        cin >> *(buffer + i);
    }
    // input first line
    traceBuffer(buffer, N);
    // perform sort and input other lines
    int j;
    int key;
    for (int i=1; i<N; ++i) {
        key = buffer[i];
        j = i - 1;
        while ((j >= 0) && (buffer[j] > key)) {
            buffer[j+1] = buffer[j];
            j --;
        }
        buffer[j+1] = key;
        traceBuffer(buffer, N);
    }
    delete[] buffer;
}

void traceBuffer(const int *buffer, int len)
{
    for (int i=0; i<len; ++i) {
        if (i > 0) {
            cout << " ";
        }
        cout << *(buffer + i);
    }
    cout << endl;
}


Measured memory_bytes: 3080
import numpy as np
n, k, q = map(int, input().split())
correct = []
orig = np.ones(n) * k - q
for i in range(q):
    tmp = int(input())
    orig[tmp-1] += 1
for i in orig:
    if i <=0:
        print("No")
    else:
        print("Yes")

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

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

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

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

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

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

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

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

//
// solution 
//
#[allow(unused_mut)]
#[allow(non_snake_case)]
fn main() {
    input!{
        N: usize,
        M: usize, 
        city: [(usize, usize); M],
    }

    let mut pref_num = vec![0; N+1];

    let mut city_with_ind: Vec<(usize, usize, usize, usize)>
        = city.into_iter().enumerate().enumerate().map(|(ind, (rank, (p, y)))| (ind, rank, p, y)).collect();
    
    city_with_ind.sort_by_key(|a| a.3);
    
    for a in city_with_ind.iter_mut() {
        pref_num[a.2] += 1;
        a.1 = pref_num[a.2];
    }

    city_with_ind.sort_by_key(|a| a.0);

    for &(_ind, rank, p, _y) in city_with_ind.iter() {
        println!("{0: >06}{1: >06}", p, rank);
    }

}


Measured memory_bytes: 13300
#include <bits/stdc++.h>
#define ll  long long int
#define N 200002
#define M 1000000007
#define f(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define po pop_back
#define pb emplace_back
#define lb lower_bound
#define ub upper_bound
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define cot cout.tie(0)
using namespace std;
/**
  * @author :: Sawlani
  *
  */

  int main()
  {
      ll a,b,k;
      cin >> a >> b >> k;

      if(a>k)
      {
          a-=k;
          k=0;
          cout << a << " " << b ;
          return 0;
      }
      else
      {
          k=k-a;
          a=0;
          b=b-min(b,k);

          cout << 0 << " " << b ;

      }

  }


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

typedef pair<int, int> P;
#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 1234567890

const int maxn = 1e5 + 10;


//initialization here
//
vi v;
//
//initialization finish


// your function is here
//

//
// your function finished



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

	// your code is here
	//

	ll n,m; cin >> n>>m;
	ll dis[105][105];
	rep(i, n)rep(j, n)dis[i][j] = INF;
	rep(i, n) dis[i][i] = 0;
	ll aa[1005], bb[1005], cc[1005];

	rep(i, m)
	{
		ll a, b, c;
		cin >> a>>b>>c;
		a--, b--;
		aa[i] = a, bb[i] = b, cc[i] = c;
		dis[a][b] = c;
		dis[b][a] = c;
	}

	rep(k, n)rep(i, n)rep(j, n)
	{
		dis[i][j] = min(dis[i][j],dis[i][k]+dis[k][j]);
	}

	ll count = 0;
	rep(i, m)if (dis[aa[i]][bb[i]] != cc[i])count++;


	Print(count);
	//
	// your code finished
	return 0;
}

Measured memory_bytes: 384
n = int(input())
x = [0] * n
y = [0] * n
ans = 0
for i in range(n):
  x[i],y[i] = input().split()
  x[i] = float(x[i])
for i in range(n):
  if y[i] == "BTC":
    ans += x[i] * 380000
  else:
    ans += x[i]
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    vector<vector<int>> data(10, vector<int>(N));
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < N; j++) {
      cin >> data.at(i).at(j);
    }
  }
  
  
  for (int j = 0; j < N-1; j++) {
      cin >> data.at(2).at(j);
  }

  int count=0;

   for (int j = 0; j < N-1; j++) {
      int before_num=0;
      before_num = data.at(0).at(j);
      int after_num=0;
      after_num=data.at(0).at(j+1);
      if(before_num-after_num==-1){
        count+= data.at(2).at(before_num-1);
      }
    }
  
    for (int j = 0; j < N; j++) {
      count+= data.at(1).at(j);
    }
    
    cout << count<< endl;
  
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <queue>
#include <set>
#include <bitset>
#include <map>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef queue<int, int> qii;
typedef pair<int, int> pii;
typedef pair<string, int> psi;

#define PI 3.14159265359
#define rep(i,a) for(int i=0;i<a;i++)

//int型を受け取ってその桁数を返す
int check_digits(int n, int m) {
	int digits = 0;
	while (n != 0) {
		n /= m;
		digits++;
	}
	return digits;
}

//int型を受け取ってその各桁の和を返す
int sum_digits(int n) {
	int sum = 0;
	int N = n;
	while (N) {
		sum += N % 10;
		N /= 10;
	}
	return sum;
}


//最大公約数を返す関数
int gcd(int n, int m) {
	while (n != 0) {
		if (n < m) swap(n, m);
		n = n % m;
	}
	return m;
}


//2点間の距離を返す
float dis(int x1, int y1, int x2, int y2) {
	return sqrt(pow(abs(x1 - x2), 2) + pow(abs(y1 - y2), 2));
}


//入力された文字列が回文か判断してboolを返す
bool is_kaibun(string s) {
	string s_r(s.rbegin(), s.rend());
	return (s == s_r);
}


void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }


//提出言語もしっかり確認して…
//問題文を落ち着いて読む！
//型に注意！！
//出力例もちゃんと全部見る！！！！！
int main() {
	int n,ans = 0;
	string s;
	cin >> n >> s;
	rep(i, n) {
		if(s[i] != s[i+1]) ans++;
	}
	cout << ans << endl;

	system("pause");
	return 0;
}


Measured memory_bytes: 760
#include <iostream>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;
typedef long long ll;

struct S {
	int n;
	char d[10];
	S() {}
	S(int n) : n(n) {}
	ll hash() {
		ll r = 0;
		for (int i = 0; i < n; i++) {
			r *= 16;
			r += d[i];
		}
		return r;
	}
};

typedef pair<S, int> P;

int main() {
	int n;
	cin >> n;
	S s(n), r(n);
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x; x--;
		s.d[i] = x;
		r.d[i] = i;
	}
	ll rh = r.hash();
	int dist = 1, rdist = 1;
	queue<P> q;
	map<ll, int> u;
	q.push(P(s, 1));
	while (!q.empty()) {
		S s(0); int d;
		tie(s, d) = q.front(); q.pop();
		if (d == 6) break;

		ll sh = s.hash();
		if (u[sh]) continue;
		u[sh] = d;
		dist = d;
		if (sh == rh) {
			break;
		}
		for (int i = 0; i < n; i++) {
			for (int j = i+2; j <= n; j++) {
				S ss = s;
				reverse(ss.d + i, ss.d + j);
				q.push(P(ss, d+1));
			}
		}
	}
	map<ll, int> ru;
	q = queue<P>();
	q.push(P(r, 1));
	while (!q.empty()) {
		S s(0); int d;
		tie(s, d) = q.front(); q.pop();
		ll sh = s.hash();
		if (d == 6) {
			rdist = 6;
			break;
		}
		if (ru[sh]) continue;
		ru[sh] = d;
		rdist = d;
		if (u[sh]) {
			break;
		}
		for (int i = 0; i < n; i++) {
			for (int j = i+2; j <= n; j++) {
				S ss = s;
				reverse(ss.d + i, ss.d + j);
				q.push(P(ss, d+1));
			}
		}
	}
	cout << dist+rdist-2 << endl;
	return 0;
}

Measured memory_bytes: 259504
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())

if a>b:
  muki=-1
else:
  muki=1

at=a+v*muki*t
bt=b+w*muki*t

if muki==1:
  if at>=bt:
    print("YES")
  else:
    print("NO")
else:
  if at<=bt:
    print("YES")
  else:
    print("NO")

Measured memory_bytes: 9200
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> v(n), c(n);
    for(int i=0; i<n; i++){
        cin >> v[i];
    }
    for(int i=0; i<n; i++){
        cin >> c[i];
    }
    vector<int> tmp(n);
    for(int i=0; i<n; i++){
        tmp[i]=v[i]-c[i];
    }
    int ans=0;
    for(int i=0; i<n; i++){
        if(tmp[i]>0) ans+=tmp[i];
    }
    cout << ans;
    
    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  string s,t;
  cin>>s>>t;
  int ans=0;
  for(int i=0;i<(int)s.size();i++)
    ans+=s[i]!=t[i];
  cout<<ans<<newl;
  return 0;
}


Measured memory_bytes: 3784
//In the Name of God
//Ya Ali

#include<bits/stdc++.h>

#define int long long

#define pb push_back

#define err(A) cout<<#A<<" = "<<(A)<<endl

using namespace std;

int q,h,s,d,n,ans;

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

  cin>>q>>h>>s>>d;

  h=min(h,q+q);
  s=min(s,h+h);
  d=min(d,s+s);

  cin>>n;

  n*=4;

  ans+=n/8*d;
  n%=8;

  ans+=n/4*s;
  n%=4;

  ans+=n/2*h;
  n%=2;

  ans+=n/1*q;

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


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

const int N = 100;
int a[N],b[N],r[N];

int main()
{
	int n,m;
	cin>>n>>m;
	memset(r,0,sizeof(r));
	for(int i=0;i<m;i++)
		cin>>a[i]>>b[i];
	for(int i=0;i<m;i++)
		r[a[i]]++,r[b[i]]++;
	for(int i=1;i<=n;i++)
		cout<<r[i]<<endl;
	return 0;
}

Measured memory_bytes: 256
I=->{gets.split.map &:to_i};N,Q=I[];A=1,c=1,1,*[0]*(N-2),1;Q.times{a,b=I[];A[a],A[b]=A[b],A[a];c=c==a ?b:c==b ?a:c;A[c-1]=A[c+1]=1};p A.reduce(:+)-2

Measured memory_bytes: 4220
X, K, D = gets.chomp.split.map(&:to_i)

if X == 0
  if D.even?
    puts 0
  else
    puts D
  end
elsif X > 0
  i = X / D
  if i > K
    j = X - D * K
    puts j.abs
  else
    j = X % D
    k = D - j
    if (K - i).even?
      puts j.abs
    else
      puts k.abs
    end
  end
else
  i = (- X) / D
  if i > K
    j = X + D * K
    puts j.abs
  else
    j = - ((- X) % D)
    k = D + j
    if (K - i).even?
      puts j.abs
    else
      puts k.abs
    end
  end
end


Measured memory_bytes: 14316
#include<bits/stdc++.h>
using namespace std;
string a,b;
int main(void)
{
	cin>>a>>b;
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	reverse(b.begin(),b.end());
	if(b>a) printf("Yes");
	else printf("No");
}

Measured memory_bytes: 256
const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

using namespace std;

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

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define pb push_back
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};
string Ans[2] = {"No", "Yes"};
string ANS[2] = {"NO", "YES"};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

int Root(int x, vector<int> &root)
{
    if (x == root[x]) return x;
    return root[x] = Root(root[x], root);
}

void Merge(int v, int u, vector<int> &root, vector<int> &sz)
{
    v = Root(v, root), u = Root(u, root);
    if (v == u) return;
    if (sz[v] < sz[u])
    {
        sz[u] += sz[v];
        root[v] = u;
    }
    else
    {
        sz[v] += sz[u];
        root[u] = v;
    }
}

int ok(int x, int n)
{
    return 0 <= x && x < n;
}

void bfs(int v, vi &dist, vector<vi> &graph)
{
    fill(all(dist), -1);
    dist[v] = 0;
    vi q = {v};
    for (int i = 0; i < q.size(); i++)
    {
        for (auto u : graph[q[i]])
        {
            if (dist[u] == -1)
            {
                dist[u] = dist[q[i]] + 1;
                q.push_back(u);
            }
        }
    }
}


signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int c; cin >> c;
    cout << (c + 1) / 2;
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

int mask[4][4][4][4] = {};

void init_mask(){
  rep(i,4){
    mask[2][1][0][i] = 1;
    mask[2][1][i][0] = 1;
    mask[2][i][1][0] = 1;
    mask[2][0][1][i] = 1;
    mask[1][2][0][i] = 1;
  }
}

int main(){
  init_mask();
  int n;
  cin >> n;
  long dp[200][4][4][4] = {};
  rep(i,n+1){
    rep(x,4){
      rep(y,4){
        rep(z,4){
          rep(w,4){
            
              if(i <= 1){
                dp[i][x][y][z] = 0;
              }else if(i == 2){
                dp[i][x][y][z] = 1;
                if(x==2 && y==1 && z==0) dp[i][x][y][z] = 0;
                if(x==1 && y==2 && z==0) dp[i][x][y][z] = 0;
                if(x==2 && y==0 && z==1) dp[i][x][y][z] = 0;
              }else{
                dp[i][x][y][z] += dp[i-1][y][z][w] * (1 - mask[x][y][z][w]);
                dp[i][x][y][z] %= MOD;
              }
            
        }
      }
    }
  }
  }
  long ans = 0;
  rep(i,4){
    rep(j,4){
      rep(k,4){
        ans += dp[n-1][i][j][k];
        ans %= MOD;
      }
    }
    
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
def slove():
    import sys
    import fractions
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    gcd = 0
    for i in range(n):
        gcd = fractions.gcd(gcd, a[i])
    print(gcd)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 88428
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1ll<<59

int main(){
  ll n,m;
  while(1){
    cin>>n>>m;
    if(n==0) return 0;

    vector<ll> ma(n,0),mi(n,0);
    
    ll s,k,x;
    ll i,j;

    for(i=0;i<m;i++){
        cin>>s>>k;
        if(k==1){
          cin>>x;
          ma[x-1]+=s;
          mi[x-1]+=s;
        }
        else {
          for(j=0;j<k;j++){
            cin>>x;
            ma[x-1]+=s;
          }
        }
    }

    vector<ll> v1,v2;
    ll MM=0,mm=mi[0];
    for(i=0;i<n;i++){
      MM=max(MM,ma[i]);
      
      mm=min(mm,mi[i]);
    }
    for(i=0;i<n;i++){
      if(MM==ma[i]) v1.pb(i);
      if(mm==mi[i]) v2.pb(i);
    }
    if(v1.size()>1||v2.size()>1) cout<<MM-mm+1<<endl;
    else if(v1[0]!=v2[0]) cout<<MM-mm+1<<endl;
    else {
      ll MM2=-1;
      ll mm2=1000000000;
      for(i=0;i<n;i++){
        if(ma[i]<MM) MM2=max(ma[i],MM2);
        if(mi[i]>mm) mm2=min(mi[i],mm2);
      }
      cout<<max(MM2-mm+1,MM-mm2+1)<<endl;
    }


  }
}


Measured memory_bytes: 3256
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
const int N = 666666;
vector<int> e[N];int n,m,d[N],id[N],pos[N],col[N],A[N],B[N];bool ok[N];
bool cmp(int x, int y){return d[x]<d[y];}
int main() {
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
        scanf("%d",&d[i]);
        id[i]=i;
	}
	for(int i=1;i<=m;i++){
		scanf("%d%d",&A[i],&B[i]);
		e[A[i]].push_back(B[i]);
		e[B[i]].push_back(A[i]);
	}
	sort(id+1,id+n+1,cmp);
	for(int i=1;i<=n;i++)pos[id[i]]=i;
	for(int i=1;i<=n;i++){
		int x=0;
		for(int j=0;j<e[id[i]].size();j++)if(pos[e[id[i]][j]]<i)
			x=col[e[id[i]][j]]^1;
		for(int j=0;j<e[id[i]].size();j++)if(pos[e[id[i]][j]]<i&&!ok[e[id[i]][j]])
			x=col[e[id[i]][j]]^1;
		col[id[i]]=x;
		for(int j=0;j<e[id[i]].size();j++)if(pos[e[id[i]][j]]<i&&col[e[id[i]][j]]!=x)
			ok[id[i]]=1,ok[e[id[i]][j]]|=d[e[id[i]][j]]==d[id[i]];
	}
	for(int i=1;i<=n;i++)if(!ok[i]){puts("-1");return 0;}
	for(int i=1;i<=n;i++)printf("%c",col[i]?'B':'W');puts("");
	for(int i=1;i<=m;i++)printf("%d\n",max(d[A[i]],d[B[i]]));
	return 0;
}


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

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

  int n, m;
  cin >> n >> m;

  cout << (n * (n-1) / 2) + (m * (m-1) / 2) << '\n';

  return (0);
}


Measured memory_bytes: 3564
N = gets.to_i
str = gets.split
a = []
all = 0
for x in 0...N
  a[x] = str[x].to_i
  all += a[x]
end

ave = all / N.to_f

answer = 0
dif = (a[0] - ave).abs

for x in 1...N
  if dif > (a[x] - ave).abs
    answer = x
    dif = (a[x] - ave).abs
  end
end

puts(answer)

Measured memory_bytes: 1788
#include <iostream>

using namespace std;

#define INFY 2000000000;

static int cnt = 0;

void merging (int *A, int left, int mid, int right) {

  int n1 = mid - left;
  int n2 = right - mid;

  int L[n1], R[n2];

  for (int i = 0; i < n1; i++) L[i] = A[left+i];

  for (int i = 0; i < n2; i++) R[i] = A[mid+i];

  L[n1] = R[n2] = INFY;

  int j = 0, i = 0;

  for (int k = left; k < right; k++) {
    cnt++;
    if (L[i] < R[j]) {
      A[k] = L[i];
      i++;
    } else {
      A[k] = R[j];
      j++;
    }
  }

}

void mergeSort (int *A, int left, int right) {

  if (left+1 < right) {
    int mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merging(A, left, mid, right);
  }

}

int main () {

  int n;

  scanf("%d", &n);

  int A[n];

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

  mergeSort(A, 0, n);

  for(int i = 0; i < n; i++) {
    if (i != 0) {
      printf(" ");
    }
    printf("%d", A[i]);
  }

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

}

Measured memory_bytes: 7084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<ll> Size;
    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1);
        for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        Size[x] += Size[y];
        return true;
    }

    ll size(int x){
        return Size[root(x)];
    }
};

int field[55][35];
set<int> st[55];

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true) {
        int N;
        cin >> N;
        if(N == 0) break;
        for(int i = 1; i <= N; i++) {
            st[i].clear();
            st[i].insert(i);
        }
        for(int i = 1; i <= N; i++) {
            for(int b = 0; b <= 30; b++) field[i][b] = 0;
        }
        for(int i = 1; i <= N; i++) {
            int f;
            cin >> f;
            while(f--) {
                int a;
                cin >> a;
                field[i][a] = 1;
            }
        }
        bool clear = false;
        for(int day = 1; day <= 30; day++) {
            set<int> now;
            for(int i = 1; i <= N; i++) {
                if(field[i][day] == 0) continue;
                for(auto itr = st[i].begin(); itr != st[i].end(); itr++) {
                    now.insert(*itr);
                }
            }
            for(int i = 1; i <= N; i++) {
                if(field[i][day] == 1) st[i] = now;
            }
            if(now.size() == N) {
                clear = true;
                cout << day << endl;
                break;
            }
        }
        if(!clear) cout << -1 << endl;
    }
    return 0;
}



Measured memory_bytes: 3240
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
vector<string>split(string s, char c = ' ') {
	vector<string>vec;
	string h = "";
	for (int i = 0; i < s.size();) {
		int j = i;
		while (j < s.size() && s[j] != ' ') {
			h += s[j++];
		}
		if (h.size() > 0) vec.push_back(h);
		h = "";
		i = j + 1;
	}
	return vec;
}
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
string s, t;
bool a[26];
vector<int>b[26], c[26];
signed main() {
	cin >> s >> t;
	for (int i = 0; i < s.size(); i++) {
		b[(int)(s[i] - 'a')].push_back(i);
		c[(int)t[i] - 'a'].push_back(i);
	}
	for (int i = 0; i < s.size(); i++) {
		int k = (int)(s[i] - 'a'), r = (int)(t[i] - 'a');
		if (!a[k]) {
			if (b[k].size() != c[r].size()) {
				cout << "No\n";
				return 0;
			}
			for (int j = 0; j < b[k].size(); j++) {
				if (b[k][j] != c[r][j]) {
					cout << "No\n";
					return 0;
				}
			}
			a[k] = 1;
		}
	}
	cout << "Yes\n";
}

Measured memory_bytes: 4744
#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#include<math.h>
#include<unordered_set>
using namespace std;

const int MAX = 100005;

int N;
int t[MAX];
int x[MAX];
int y[MAX];

bool solve() {
	for (int i = 1; i <= N; i++) {
		int dist = abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]);
		int time = t[i] - t[i - 1];
		if (time < dist)return false;
		if ((time % 2) != (dist % 2))return false;
	}
	return true;
}

int main() {
	t[0] = 0;
	x[0] = 0;
	y[0] = 0;

	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> t[i] >> x[i] >> y[i];
	}

	if (solve())cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n , a[N];
main(){
	scanf("%d" , &n);
    for(int i = 1 ; i <= n; i++)
      	scanf("%d" , a + i);
  	long long ans = 0;
  	for(int i = 1 ; i <= n; i++){
      	if(a[i] == 0)continue;
        if(a[i]&1)
          	ans += a[i] / 2 , a[i] = 1;
      	else ans += a[i] / 2 - 1, a[i] = 2;
    }
  	int cur = 0;
  	for(int i = 1;  i <= n + 1 ; i++)
      	if(a[i] == 0)ans += cur / 2, cur = 0;
  		else cur += a[i];
 	printf("%lld" , ans); 
}

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

int search(int *,int *,int,int);

int main(){
  int i,n,q,*S,*T,count;

  scanf("%d",&n);

  S=(int *)malloc((n+1)*sizeof(int));
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }

  scanf("%d",&q);

  T=(int *)malloc(q*sizeof(int));
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }
 
  count=search(S,T,n,q);
  printf("%d\n",count);
  free(S);
  free(T);
  return 0;

    }

int search(int *S,int *T,int n,int q){
  int i, j=n,count=0;
  
  for(i=0;i<q;i++){
    if(j!=n){
      count++;
    }
    j=0;
    S[n]=T[i];
    while(S[j]!=S[n]){
      j++;
    if(j==n) break;
    }
  }
  if(j!=n){
      count++;
    }
  
  return count;
}



Measured memory_bytes: 2108
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
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)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=1e9+7 ;

const int N=365, M=26;
int c[26], s[365][26];
int res[365];

int calc(){
    int ret=0;
    vector<int> last(26,-1);
    rep(i,N){
        ret+=s[i][res[i]];
        last[res[i]]=i;
        rep(j,26)ret-=c[j]*(i-last[j]);
    }
    return ret;
}
struct Xor128{
    unsigned x,y,z,w;
 
    Xor128(unsigned w_=88675123):x(123456789),y(362436069),z(521288629),w(w_){};
 
    inline unsigned xor128(){
        unsigned t;
        t = x^(x<<11);
        x = y;
        y = z;
        z = w;
        return w = (w^(w>>19))^(t^(t>>8));
    }
 
    int nextInt(int x,int y){
		if(x>y)swap(x,y);
        return xor128()%(y-x)+x;
    }
 
    double nextDouble(double a,double b){
        return (double)(xor128()&0xffff)/0xffff*(b-a)+a;
    }
 
};
int main(){
    int _;cin>>_;
    rep(i,M)cin>>c[i];
    rep(i,N)rep(j,M)cin>>s[i][j];
    auto rnd=Xor128();
    rep(i,N)res[i]=rnd.nextInt(0, M);
    int cur = calc();
    rep(_,100000){
        int i=rnd.nextInt(0, N), j=rnd.nextInt(0,M);
        int tmp=res[i];
        res[i]=j;
        int nc = calc();
        if(nc>cur){
            cur=nc;
        }
        else {
            res[i]=tmp;
        }
    }
    rep(i,N)cout<<res[i]+1<<endl;
    cerr << cur << endl;
    return 0;
}

Measured memory_bytes: 3680