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

using namespace std;

struct node{
	vector<int> cld;
	int dis;
	bool vis;
	node(){
		dis = 1e7+7;
		vis = 0;
	}
}a[100005];

int n , m;

int main(){
	cin>>n>>m;
	for(int i = 0 ; i < m ; i++){
		int aa , b;
		cin>>aa>>b;
		a[aa].cld.push_back(b);
		a[b].cld.push_back(aa);
	}
	deque<pair<int , int>> in;
	in.push_back({1 , 0});
	while(!in.empty()){
		int aa = in.front().first , bb = in.front().second;
		if(a[aa].vis == 0){
			a[aa].dis = bb;
			a[aa].vis = 1;
			in.pop_front();
			for(int i : a[aa].cld) if(a[i].vis == 0) in.push_back({i , aa});
		}
		else in.pop_front();
	}
	bool s = 1;
	for(int i = 2 ; i <= n ; i++) if(a[i].dis == 1e7+7) s = 0;
	if(s){
		cout<<"Yes"<<endl;
		for(int i = 2 ; i <= n ; i++) cout<<a[i].dis<<endl;
	}
	else cout<<"No"<<endl;
}

Measured memory_bytes: 11260
#include<cstdio>
    int main()
    {
    	int n,flag=0;scanf("%d",&n);
    	while(n)
    	{
    		char c=getchar();
    		if(c<'A'||c>'Z') continue;
    		n--;if(c=='Y') flag=1;
    	}
    	if(!flag) printf("Three\n");else printf("Four\n");
    	return 0;
    } 

Measured memory_bytes: 128
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   

using namespace std;


int main() {

	int a, b;
	
	cin >> a >> b;
	
	if (a <= 8 && b <= 8) {
		cout << "Yay!" << endl;
	}
	else {
		cout << ":(" << endl;

	}
	

	

}

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

int main() {
    string S; int K;
    cin >> S >> K;
    set<string> substr;
    for(int i = 0; i < S.size(); i++) {
    	string N;
    	for(int len = 1; len <= S.size()-i && len <= K; len++) {
    	   N += S[i + len - 1];
    	   substr.insert(N);
        }
    }
    //cout << substr.size() << endl;
    int cnt = 0;
    for(auto x : substr) {
    	cnt++;
    	if(cnt == K) {
    		cout << x << endl;
    		break;
    	}
    	else
    		continue;
    }
	return 0;
}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str1 = br.readLine();
		String str2 = br.readLine();
		
		if(str1.charAt(0) == str2.charAt(2) && str1.charAt(1) == str2.charAt(1)
				&& str1.charAt(2) == str2.charAt(0)){
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
		
	}

}


Measured memory_bytes: 23124
#include <iostream>

struct Node {
    int parent = -1;
    int left = -1;
    int right = -1;
};

void preorder(Node * nodes, int idx) {
    if (idx == -1) {
        return;
    }
    std::cout << " " << idx;
    preorder(nodes, nodes[idx].left);
    preorder(nodes, nodes[idx].right);
}

void inorder(Node * nodes, int idx) {
    if (idx == -1) {
        return;
    }
    inorder(nodes, nodes[idx].left);
    std::cout << " " << idx;
    inorder(nodes, nodes[idx].right);
}

void postorder(Node * nodes, int idx) {
    if (idx == -1) {
        return;
    }
    postorder(nodes, nodes[idx].left);
    postorder(nodes, nodes[idx].right);
    std::cout << " " << idx;
}

int main() {
    int n;
    std::cin >> n;

    Node nodes[n];

    for (int i = 0; i < n; i++) {
        int id, left, right;
        std::cin >> id >> left >> right;
        nodes[id].left = left;
        nodes[id].right = right;
        nodes[left].parent = id;
        nodes[right].parent = id;
    }

    int root_idx = -1;
    for (int i = 0; i < n; i++) {
        if (nodes[i].parent == -1) {
            root_idx = i;
            break;
        }
    }

    std::cout << "Preorder" << std::endl;
    preorder(nodes, root_idx);
    std::cout << std::endl;
    std::cout << "Inorder" << std::endl;
    inorder(nodes, root_idx);
    std::cout << std::endl;
    std::cout << "Postorder" << std::endl;
    postorder(nodes, root_idx);
    std::cout << std::endl;
}



Measured memory_bytes: 3100
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int[] a = new int[n];

		for(int i=0; i<n; i++){
			a[i] = sc.nextInt();
		}

		int[] a_sum = new int[n];

		a_sum[0] = a[0];
		for(int i=1; i<n; i++){
			a_sum[i] = a_sum[i-1] + a[i];
		}
		
		int[] a_sum_copy = new int[n];
		for(int i=0; i<n; i++){
			a_sum_copy[i] = a_sum[i];
		}

		//奇数番目までの和を正に、偶数番目までの和を負にする
		long cnt1 = 0;
		long cnt2 = 0;
		for(int i=0; i<n; i++){
			a_sum[i] += cnt1 + cnt2;
			if(i%2==0){
				if(a_sum[i]<0){
					cnt1 += (-a_sum[i]) + 1;
					a_sum[i] = 1;
				}else if(a_sum[i]==0){
					cnt1 += 1;
					a_sum[i] = 1;
				}
			}else if(i%2==1){
				if(a_sum[i]>0){
					cnt2 -= a_sum[i] + 1;
					a_sum[i] = -1;
				}else if(a_sum[i]==0){
					cnt2 -= 1;
					a_sum[i] = -1;
				}
			}
		}

		//奇数番目までの和を負に、偶数番目までの和を正にする
		long cnt3 = 0;
		long cnt4 = 0;
		for(int i=0; i<n; i++){
			a_sum_copy[i] += cnt3 + cnt4;
			if(i%2==1){
				if(a_sum_copy[i]<0){
					cnt3 += (-a_sum_copy[i]) + 1;
					a_sum_copy[i] = 1;
				}else if(a_sum_copy[i]==0){
					cnt3 += 1;
					a_sum_copy[i] = 1;
				}
			}else if(i%2==0){
				if(a_sum_copy[i]>0){
					cnt4 -= a_sum_copy[i] + 1;
					a_sum_copy[i] = -1;
				}else if(a_sum_copy[i]==0){					
					cnt4 -= 1;
					a_sum_copy[i] = -1;
				}
			}
		}

		if(cnt1-cnt2>cnt3-cnt4){
			System.out.print(cnt3-cnt4);
		}else{
			System.out.print(cnt1-cnt2);
		}

	}

}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define MOD 1000000007
#define el endl
typedef long long ll;
typedef long double ld;

int main() {
    struct s{
        bool is_ac;
        int penalty;
    };
    int n,m, pena = 0, ac = 0;
    cin >> n >> m;
    vector
 sv(n);
    rep(i, m){
        int p_n;
        string res;
        cin >> p_n;
        cin >> res;
        
        p_n--;
        
        if(res == "AC"){
            if(!sv[p_n].is_ac){
                sv[p_n].is_ac = true;
                ac++;
                pena += sv[p_n].penalty;
            }
        }else{
            sv[p_n].penalty++;
        }
    }
    cout << ac << " " << pena << el;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <limits>
#include <vector>

using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> h(n), f(n);
    for (int& hi : h) cin >> hi;
    for (int i = 1; i < n; ++i) {
        f[i] = numeric_limits<int>::max();
        for (int j = 1; j <= min(i, k); ++j)
            f[i] = min(f[i], f[i - j] + abs(h[i] - h[i - j]));
    }
    cout << f.back();
    return 0;
}


Measured memory_bytes: 1024
N = int(input())
A = list(map(int,input().split()))
d = {}
ans = 0
for i in range(N):
    sa = i-A[i]
    if sa in d:
        ans += d[sa]
    wa = i+A[i]
    if wa in d:
        d[wa] += 1
    else:
        d[wa] = 1
print(ans)


Measured memory_bytes: 118820
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <random>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,a,b,c,d; cin >> n >> a >> b >> c >> d;
	cout << min((n+a-1)/a*b,(n+c-1)/c*d) << endl;
}


Measured memory_bytes: 3208
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main() {
  string s;
  int c = 0;
  cin >> s;
  rep(i, s.size()) {
    if (s[i] == '1') c++;
  }
  cout << c << endl;
  return 0;
}


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

#define ll long long

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define repA(i,A)   for(auto i:A)

#define err() cout<<"=================================="<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl

#define mp make_pair
#define pb push_back
#define all(A)  A.begin(),A.end()
#define ft first
#define sd second

#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>

#define endl "\n"

const ll logN = 20;
const ll N = 100005;
const ll M = 1000000007;
#define PI 3.14159265

int main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  int n;
  cin>>n;
  ll h[n];
  rep(i, 0, n) cin>>h[i];
  ll cost[n] = {0};
  for(int i=1; i<n; i++){
      if(i == 1){
            cost[i] = abs(h[i]-h[i-1]);
      }
      else{
            cost[i] = min(cost[i-1] + abs(h[i]-h[i-1]), cost[i-2] + abs(h[i] - h[i-2]));
      }
  }
  cout<<cost[n-1]<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  for(int i=1;i<100000;i++){
    if(i*8/100==a&&i*10/100==b){
      cout<<i<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
  return 0;
}

Measured memory_bytes: 256
N, A, B = map(int, input().split())

if A > B:
    ans = 0
else:
    if N == 1:
        if A == B:
            ans = 1
        else:
            ans = 0
    elif N == 2:
        if A == B:
            ans = 1
        else:
            ans = B - A + 1
    else:
        ans = (N - 2) * B - (N - 2) * A + 1

print(ans)

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int N;
  cin >> N;
  vector<P> X(N);

  ll x, l;
  rep(i, N){
    cin >> x >> l;
    // 始点 = x - l, 終点 x + l
    X[i] = P(x-l, x+l);
  }

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

  vector<ll> dp(N+1);
  rep(i, N+1){
    dp[i] = INF;
  }

  dp[0] = - INF;

  rep(i, N){

    int ind = lower_bound(dp.begin(), dp.end(), X[i].first+1) - dp.begin();

    dp[ind] = min(dp[ind], X[i].second);

  }

  ll ans = 0;
  rep(i, N+1){
    if(dp[i] < INF){
      ans = i;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2560
#include <iostream>

using namespace std;
typedef long long ll;

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


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a) = min((a), (b)))
#define chmax(a, b) ((a) = max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1);
const double eps = 1e-10;

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

int main(){
    int n; cin>>n;
    vector<int> p(n);
    for(int i=0; i<n; i++) cin>>p[i];

    int ans = 1e9;
    for(int i=0; i<=p[0]; i++){
        auto cp = p;
        int sum = i;
        cp[0] -= i;
        for(int j=0; j+1<n; j++){
            while(0 < cp[j]){
                cp[j]--;
                cp[j+1]--;
                sum += 2;
            }
        }

        sum += max(0, cp[n-1]);

        ans = min(ans, sum);
    }

    cout << ans << endl;
}


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

#define all(x) 		 (x).begin(),(x).end()
#define mp     		 make_pair
#define pb 				 push_back
#define fi 				 first
#define se 				 second
#define sz(x) 		 ((int)(x).size())
#define rep(x,y,z) for(int x=y;x<z;x++)
#define per(x,z,y) for(int x=z-1;x>=y;x--)
#define trav(y,x)  for(auto& y:x)
#define pii 			 pair<int,int>
#define vi 				 vector<int>

int dbg = 0;
#define cri   		 if(0)
#define shame 		 cri cerr<<(++dbg)<<"\n\n";

// aaaaaaaaaaaaaaaa
const int N = 2e5 + 1;
const int lg = 20;
const ll mod = 0xfffff;


void solve() {
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> grid(h);
  rep(i, 0, h)
    cin >> grid[i];
  
  int mn = h * w, hor, ver;
  rep(x, 0, 1 << (h - 1)) {
    hor = __builtin_popcount(x);
    ver = 0;

    bool can = 1;
    int last = 0;
    vi row(h, 0);
    rep(y, 0, w) {
      rep(z, 0, h)
        if (grid[z][y] == '1')
          row[z]++;
      int mx = 0, grp = 0;
      rep(z, 0, h) {
        grp += row[z];
        if (z < h - 1) {
          if (x & (1 << z)) {
            mx = max(mx, grp);
            grp = 0;
          }
        }
        else mx = max(mx, grp);
      }

      if (mx > k && last == y) {
        can = 0; break;
      }
      else if (mx > k) {
        ver++;
        rep(z, 0, h) {
          row[z] = 0;
          if (grid[z][y] == '1')
            row[z] = 1;
        }
      }
    }

    if (can)
      mn = min(mn, hor + ver);
  }
  cout << mn << "\n";
}

int main() {
  // freopen("input.in", "r", stdin);
  // freopen("input.out", "w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	// cout<<setprecision(15);
	// int t; cin>>t; while(t--)
	solve();
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define ALL(v) (v).begin(),(v).end()
#define FOR(i, n) for(ll (i)=0; (i)<(n); (i)++)
#define RFOR(i, n) for(ll (i)=(n)-1; (i)>=0; (i)--)
#define REP(i, x, n) for(ll (i)=(x); (i)<(n); (i)++)
#define RREP(i, x, n) for(ll (i)=(n)-1; (i)>=x; (i)--)

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

        ll N, Q;
        cin >> N;
        vector<ll> A(N);
        FOR(i, N) cin >> A[i];
        cin >> Q;
        vector<ll> B(Q), C(Q);
        FOR(i, Q) cin >> B[i] >> C[i];
        ll sum = 0;
        vector<ll> num(100000, 0);
        FOR(i, N) {
                sum += A[i];
                num[A[i]]++;
        }
        FOR(i, Q) {
                sum += (C[i] - B[i]) * num[B[i]];
                num[C[i]] += num[B[i]];
                num[B[i]] = 0;
                cout << sum << endl;
        }

        return 0;
}

Measured memory_bytes: 6336
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
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; }
template<typename T> inline T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }






int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    
    
    // 解説みた
    
    int a, b;
    cin >> a >> b;
    
    const int maxn = 100; // 10でdebug
    char x = '.', y = '#';
    
    char table[maxn][maxn];
    rep(i, maxn) {
        rep(j, maxn / 2) table[i][j] = y;
        rep3(j, maxn / 2, maxn) table[i][j] = x;
    }
    int c = 0, c2 = 0;
    for (int i = 0; i < maxn; i += 2) {
        for (int j = 0; j < maxn / 2 - 1; j += 2) {
            c++;
            if (c > a - 1) break;
            table[i][j] = x;
        }
        
        for (int j = maxn / 2 + 1; j < maxn; j += 2) {
            c2++;
            if (c2 > b - 1) break;
            table[i][j] = y;
            
        }
    }
    
    
    
    cout << maxn << " " << maxn << endl;
    rep(i, maxn) { rep(j, maxn) cout << table[i][j]; cout << endl; } // 空白入れててwa
}






Measured memory_bytes: 256
import numpy as np

N = int(input())

p = np.zeros((N, 2))

X, Y = [], []
for i in range(N):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)


X = np.array(X)
Y = np.array(Y)

p[:, 0] = X + Y
p[:, 1] = X - Y

xmin = np.argmin(p[:, 0])
xmax = np.argmax(p[:, 0])
ymin = np.argmin(p[:, 1])
ymax = np.argmax(p[:, 1])

ans = 0

for c in [xmin, xmax, ymin, ymax]:
    x, y = p[c]
    p_ = p.copy()
    p_[:, 0] -= x
    p_[:, 1] -= y
    p_m = np.max(p_, axis=1)
    ans = max(ans, np.max(p_m))
print(int(ans))
    

Measured memory_bytes: 44208
import math
a,b = map(int,input().split())
length = len(str(b))
n = a * 10 ** length + b
count = 0
for i in range(int(math.sqrt(n)) + 1):
  if i ** 2 == n:
    print("Yes")
    count += 1
    exit()
if count == 0:
  print("No")

Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define dump(v) (cerr << #v << ": " << v << endl)
#define cerr                                                                   \
  if (true)                                                                    \
  cerr

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

void solve(long long n, vector<long long> a) {
  // 1 2 3 4
  // 3 2 4 1

  // 1 2 3
  // 2 3 1
  deque<ll> f, b;
  for (int i = n - 1; i >= 1; i -= 2) {
    f.push_back(a[i]);
    b.push_front(a[i - 1]);
  }

  if (n % 2 != 0)
    b.push_front(a[0]);

  REP(i, f.size()) cout << f[i] << " ";
  REP(i, b.size() - 1) cout << b[i] << " ";

  cout << b.back() << endl;
}

int main() {
  ios::sync_with_stdio(false);
  long long n;
  cin >> n;
  vector<long long> a(n - 1 + 1);
  for (int i = 0; i <= n - 1; i++) {
    cin >> a[i];
  }
  solve(n, a);
  return 0;
}


Measured memory_bytes: 7040
#include<iostream>
#include<map>
using namespace std;int main(){for(int n,v,i,V;cin>>n,i=n;){map<int,int>m;for(;i--;++m[v]>m[V]?V=v:0)cin>>v;m[V]*2>n?cout<<V<<endl:cout<<"NO COLOR\n";}}

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

int main(){

    int menu[5];
    cin >>menu[0] >> menu[1] >> menu[2] >> menu[3] >> menu[4];
    int min_menu = 10;
    int min_pointer = 0;
    for(int i=0; i<5; i++){
        if(menu[i] - (menu[i]/10)*10 < min_menu && menu[i] % 10 != 0){
            min_menu = menu[i] - (menu[i]/10)*10;
            min_pointer = i;
        }
    }

    int min_time = menu[min_pointer];
    //cout << min_time << endl;
    for(int i=0; i<5; i++){
        if(i != min_pointer){
            if((menu[i]/10)*10 == menu[i]){
                min_time += menu[i];
            }else{
                min_time += (menu[i]/10)*10 + 10;
            }

            //cout << min_time << endl;
        }
    }

    cout << min_time << endl;
    return 0;
}

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

int main(){
    int ans=0;
    string s;
    bool sw=true;
    cin>>s;
    for(auto i=s.rbegin();i!=s.rend();i++){
        if(i!=s.rend()-1){
            ans+=9;
            if(*i!='9')sw=false;
        }
        else ans+=(*i-(!sw?'1':'0'));
    }
    cout<<ans<<endl;
}

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

#define ll          long long
#define pb          push_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
void solve(){
    ll n;
    string s;
    cin>>n>>s;
    rep(i,0,sz(s)-1){
        s[i]=(s[i]-'A'+n)%26+'A';
    }
    cout<<s;
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

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

using namespace std;

int main(void)
{
	int i,n;

	cin >> n;

	int A[n];
	int B[n]={};

	for(i=1;i<n;i++)
	{
		cin >> A[i];
	}

	for(i=1;i<n;i++)
	{
		B[A[i]-1]=B[A[i]-1]+1;
	}

	for(i=0;i<n;i++)
	{
		cout << B[i] << endl;
	}

	return 0;
}


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

n,k=map(int,input().split())
a=list(map(int,input().split()))
rlst=ruiseki(a)
# print(rlst)
lst=[]
for i in range(n+1):
    for j in range(i+1,n+1):
        # print(i,j)
        lst.append(rlst[j]-rlst[i])
# print(lst)
tmp=math.log(rlst[-1],2)
now=int(tmp)

while now>=0:
    anslst=[]
    for i in range(len(lst)):
        if 1&(lst[i]>>now)==1:
            anslst.append(lst[i])
    if len(anslst)>=k:
        lst=anslst
    now-=1
# print(lst)
ans=lst[0]
for i in range(k):
    ans=ans&lst[i]
print(ans)

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

class Program
{
    static void Main(string[] args)
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        long[] a = new long[n];
        for (int i = 0; i < n; i++) a[i] = sc.NextLong();
        long[] l = new long[n + 1];
        long[] r = new long[n + 1];

        l[1] = a[0];
        r[n - 1] = a[n - 1];
        for (int i = 2; i <= n; i++)
        {
            l[i] = Gcd(l[i - 1], a[i - 1]);
            r[n - i] = Gcd(r[n - i + 1], a[n - i]);
        }

        long ans = 0;
        for (int i = 0; i < n; i++)
        {
            long g = Gcd(l[i], r[i + 1]);
            if (g > ans) ans = g;
        }
        Console.WriteLine(ans);
    }

    static long Gcd(long a, long b)
    {
        if (a < b) return Gcd(b, a);
        if (b == 0) return a;
        return Gcd(b, a % b);
    }
}

class Scanner
{
    int index = -1;
    string[] buf;

    public Scanner()
    {
    }

    public int NextInt()
    {
        CheckNext();
        return int.Parse(buf[index++]);
    }

    public long NextLong()
    {
        CheckNext();
        return long.Parse(buf[index++]);
    }

    public double NextDouble()
    {
        CheckNext();
        return double.Parse(buf[index++]);
    }

    public string NextString()
    {
        CheckNext();
        return buf[index++];
    }

    private void CheckNext()
    {
        if (index >= 0 && index < buf.Length) return;

        buf = Console.ReadLine().Split(' ');
        index = 0;
    }
}


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

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

    int A[N+2] = {0};

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

    int64_t B, sum = 0;
    for (int i = 1; i <= N; ++i) {
        std::cin >> B;

        if (B <= A[i]) {
            A[i] -= B;
            sum += B;  
        }
        else {
            sum += A[i];
            B   -= A[i];
            A[i] = 0;

            if (B <= A[i+1]) {
                A[i+1] -= B;
                sum += B;  
            }
            else {
                sum += A[i+1];
                A[i+1] = 0;
            }
        }
    }

    std::cout << sum << std::endl;

    return 0;
}


Measured memory_bytes: 640
ini = [1,2,3] -- t,n,w

cmd "north" [t,n,w] = [7-n,t,w]
cmd "east"  [t,n,w] = [w,n,7-t]
cmd "south" [t,n,w] = [n,7-t,w]
cmd "west"  [t,n,w] = [7-w,n,t]

f i [] = i
f i (c:cs) = f (cmd c i) cs

ans' d = head $ f ini d

ans (n:x) = 
    let n' = read n :: Int
        d  = ans' $ take n' x
        r  = ans  $ drop n' x
    in
        if n' == 0 then [] else d:r

main = do 
    c <- getContents
    let i = lines c
        o = ans i
    mapM_ print o


Measured memory_bytes: 4236
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
#define rep(i,n) for(ll i=0;i<(n);i++)
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

using mint = Fp<1000000007>;
vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll i=2;i<=sqrt(n);i++){
    if(n%i!=0) continue;
    ll num=0;
    while(n%i==0){
      n/=i;
      num++;
    }
    ans.push_back(make_pair(i,num));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

int main(){
  ll n;
  cin>>n;
  vector<ll> v(n);
  vector<ll> num(1100000,0);
  rep(i,n){
    cin>>v[i];
    auto pf=prime_factorize(v[i]);
    for(auto p:pf) num[p.first]=max(num[p.first],p.second);
  }
  mint LCM=1;
  rep(i,1100000){
    LCM*=modpow((mint)i,num[i]);
  }
  mint ans=0;
  rep(i,n){
    ans+=LCM/v[i];
  }
  cout<<ans<<endl;
}

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

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

using namespace std;

struct UnionFind {
  vector<int> par;
  vector<int> rank;

  UnionFind(int n) : par(n), rank(n, 1) {
    for (int i = 0; i < n; ++i)
      par[i] = i;
  }

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

  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) swap(x, y);
    par[y] = x;
    rank[x] += rank[y];
  }

  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -rank[find(x)]; }
};

int main() {
  ll N, M;
  cin >> N >> M;
  vector<int> A(M), B(M);
  vector<ll> ans(M);
  REP(i, M) {
    cin >> A[i] >> B[i];
    A[i]--;
    B[i]--;
  }
  UnionFind uf(N);
  ans[M - 1] = N * (N - 1) / 2;
  for (int i = M - 1; i > 0; --i) {
    if (uf.same(A[i], B[i])) {
      ans[i - 1] = ans[i];
      continue;
    }
    ans[i - 1] = ans[i] - uf.size(A[i]) * uf.size(B[i]);
    uf.unite(A[i], B[i]);
  }
  REP(i, M) cout << ans[i] << endl;
}

Measured memory_bytes: 3712
using System;
using System.Threading.Tasks;

static class Program
{
static void Main()
{
  string[] inputs = Console.ReadLine().Split(' ');
  int A = int.Parse(inputs[0]);
  int B = int.Parse(inputs[1]);
  int T = int.Parse(inputs[2]);
  if(A > T)
    Console.WriteLine("0");
  else
  {
    int sum = 0;
    for (int i = 1; i <= T; i++)
    {
      if (i % A == 0)
        sum += B;
    }
    Console.WriteLine(sum);
  }
}

}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll llINF=1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
 
int main() {
  ll l,r;
  cin>>l>>r;
  if(r-l>=4037){
    cout<<0<<endl;
    return 0;
  }
  ll ans=llINF;
  for(ll i=l;i<r;i++){
    for(ll j=i+1;j<=r;j++){
      ll cnt=(i*j)%2019;
      mins(ans,cnt);
    }
  }
  cout<<ans<<endl;
}

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

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

vector<ll> a;
vector<vector<int>> edges;

ll dfs(int i,int p) {
    ll sum = 0,mx = 0;
    for (int j : edges[i]) if (j != p) {
        ll c = dfs(j,i);
        if (c == -1) return -1;
        sum += c;
        if (mx < c) mx = c;
    }
    if (edges[i].size() == 1) return a[i];
    if (sum < a[i] || mx > a[i] || sum > 2*a[i]) return -1;
    return 2*a[i]-sum;
}

int main() {
    int n;
    cin >> n;
    a.resize(n);
    edges.resize(n);
    for (int i = 0;i < n;++i) cin >> a[i];
    for (int i = 0;i < n-1;++i) {
        int u,v;
        cin >> u >> v;
        u--;v--;
        edges[u].push_back(v);
        edges[v].push_back(u);
    }
    ll m = -1;
    for (int i = 0;i < n;++i) if (edges[i].size() > 1) {
        m = dfs(i,-1);
        break;
    }
    if (n == 2 && a[0] == a[1]) m = 0;
    cout << (m == 0 ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 13184
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
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<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};


int main(){
    int n;cin >> n;
    vector<string> s(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }
    vector<int> a(n,0),b(n,0);
    vector<P> p;
    vector<P> z;
    vector<P> m;
    for (int i = 0; i < n; i++) {
        int c = 0;
        for (int j = 0; j < s[i].length(); j++) {
            if(s[i][j] == '(') c++;
            else c--;
            chmin(b[i], c);
        }
        a[i] = c;
        if(c == 0) z.pb(mp(a[i], b[i]));
        else if(c > 0) p.pb(mp(b[i], a[i]));
        else m.pb(mp(b[i] - a[i], -a[i]));
    }

    LL now = 0;
    sort(RALL(p));
    for (int i = 0; i < p.size(); i++) {
        if(now + p[i].fs < 0){
            puts("No");
            return 0;
        }
        else{
            now += p[i].sc;
        }
    }
    for (int i = 0; i < z.size(); i++) {
        if(now + z[i].sc < 0){
            puts("No");
            return 0;
        }
    }
    sort(ALL(m));
    for (int i = 0; i < m.size(); i++) {
        if(now + (m[i].fs - m[i].sc) < 0){
            puts("No");
            return 0;
        }
        else{
            now -= m[i].sc;
        }
    }
    if(now == 0){
        puts("Yes");
    }
    else{
        puts("No");
    }
    return 0;
}


Measured memory_bytes: 58136
#include<bits/stdc++.h>
using namespace std;
char s1[1000001],s2[1000001],s3[1000001];
int main(){
	scanf("%s%s%s",s1,s2,s3);
	printf("%c%c%c",s1[0],s2[0],s3[0]);
	return 0;
}

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

using namespace std;

int main()
{
  int a,b;
  cin >> a;
  vector <string> red(a);
  for(int i=0;i<a;i++) cin >> red[i];
  cin >> b;
  vector <string> blue(b);
  for(int i=0;i<b;i++) cin >> blue[i];
  int sum = 0;
  string wa;
  for(int i=0;i<a;i++){
    int aka = 0;
    int ao = 0;
    wa = red[i];
    for(int j =0;j<a;j++){
      if(red[j]==wa)aka++;
    }
    for(int j =0;j<b;j++){
      if(blue[j]==wa)ao++;
    }
    sum = max(sum,aka-ao);
  }
  cout << sum << endl;
}

Measured memory_bytes: 3608
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <vector>
#include <map>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

typedef pair<llint, llint> h;

h f(string& s) {
  llint h1 = 0, h2 = 0;
  REP(i, (int)s.size()) {
    if (i < 10) {
      h1 = h1 * 27 + s[i] - 'a' + 1;
    } else {
      h2 = h2 * 27 + s[i] - 'a' + 1;
    }
  }
  return {h1, h2};
}

void go(char* s, int N, vector<pair<h, h>>& A, bool rev) {
  REP(ms, 1 << N) {
    string r, b;
    REP(i, N) {
      if (ms & (1 << i)) {
        r.push_back(s[i]);
      } else {
        b.push_back(s[i]);
      }
    }

    if (rev) {
      swap(r, b);
      reverse(r.begin(), r.end());
      reverse(b.begin(), b.end());
    }
    A.push_back({f(r), f(b)});
  }
}

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

  char s[44];
  scanf("%s", s);

  vector<pair<h, h>> A, B;
  go(s, N, A, false);
  go(s+N, N, B, true);

  map<pair<h, h>, int> M;

  for (auto& p: A) {
    M[p]++;
  }

  llint ret = 0;
  for (auto& p: B) {
    ret += M[p];
  }

  printf("%lld\n", ret);
  return 0;
}


Measured memory_bytes: 57576
#include <iostream>
using namespace std;
int main(){
    int n; //お釣り
    cin >> n;
    int c[4] = {25, 10, 5, 1};  //コインの種類
    int cnt = 0;
    for(int i = 0; i < 4; i++){
        int p = n / c[i];
        int r = n % c[i];
        cnt += p;
        n = r;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3116
from heapq import heappush, heappop

N, M = map(int, input().split())
AB = [[] for _ in range(M)]

for i in range(N) :
    A, B = map(int, input().split())
    if A <= M :
        AB[A-1].append(B)

#print(AB)
queue = []
ans = 0
for i in range(M) :
    for j in range(len(AB[i])) :
        heappush(queue, -AB[i][j])

    if len(queue) != 0 :
        ans += -heappop(queue)

print(ans)


'''
ans = 0
#print(AB)
for i in range(1, M + 1) :
    maxIncome = 0
    anker = -1
    for k in ABkeys :
        #print(AB[j][0])
        if k <= i :
            if heappop(AB[k]) > maxIncome :
                maxIncome = AB[j][0]
                anker = k
                #print('A', j, maxIncome)
                continue
        else :
            break
    ans += maxIncome
    if len(AB) == 0 :
        break
    if anker != -1:
        AB[anker].pop(0)
        if len(AB[anker]) == 0 :
            AB.remove


print(ans)
'''
'''
N, M = map(int, input().split())
AB = []
for i in range(N) :
    AB.append(list(map(int, input().split())))

AB = sorted(AB, key=lambda x:(x[0],x[1]))

ans = 0
#print(AB)
for i in range(1, M + 1) :
    maxIncome = 0
    anker = -1
    for j in range(len(AB)) :
        #print(AB[j][0])
        if AB[j][0] <= i :
            if AB[j][1] > maxIncome :
                maxIncome = AB[j][1]
                anker = j
                #print('A', j, maxIncome)
                continue
        else :
            break
    ans += maxIncome
    if len(AB) == 0 :
        break
    if anker != -1:
        AB.pop(anker)

print(ans)
'''


Measured memory_bytes: 18436
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int const N = 2e5+9;
int main(){
    string s;
    cin>>s;
    map<char,vector<int>> mp;
    for(int i = 0;i<s.size();i++){
        mp[s[i]].push_back(i);
    }
    for(auto c : mp){
        int f[c.second.size()];
        int s[c.second.size()];
        for(int j = 0;j<c.second.size();j++){
            f[j] = 2*(j+1) - (c.second[j]+1)+2;
            s[j] = 2*(j+1) - (c.second[j]+1)+1;
        }
        int mn = s[0];
        int indx = c.second[0];
        for(int i = 1;i<c.second.size();i++){
            if(f[i] > mn){
                cout<<indx+1<<' '<<c.second[i]+1;
                return 0;
            }
            if(s[i] < mn){
                mn = s[i];
                indx = c.second[i];
            }
        }
    }
    cout<<"-1 -1";
    return 0;
}

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

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define int long long
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define all(x) x.begin(), x.end()

using Point = complex<double>;
constexpr double EPS = 1e-8;

struct Circle {
    double x, y, z, r;
    Circle(double x, double y, double z, double r) : x(x), y(y), z(z), r(r) {}
};

double dist(const Circle &a, const Circle &b) {
    double d = sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) + (a.z - b.z) * (a.z - b.z));
    d -= (a.r + b.r);
    if (d < EPS)
        return 0;
    else
        return d;
}

struct UnionFind {
    int N;
    vector<int> siz, par, Rank;

    UnionFind(int n) : siz(n, 1), par(n), Rank(n, 0), N(n) { REP(i, N) par[i] = i; }

    int find(int x) {
        if (par[x] == x)
            return x;
        else
            return par[x] = find(par[x]);
    }
    void init(int N) {
        REP(i, N) {
            siz[i] = 1;
            par[i] = i;
            Rank[i] = 0;
        }
    }
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (Rank[x] < Rank[y]) {
            par[x] = y;
            siz[x] += siz[y];
            siz[y] = siz[x];
        } else {
            siz[y] += siz[x];
            siz[x] = siz[y];
            par[y] = x;
            if (Rank[x] == Rank[y]) Rank[x]++;
        }
    }
    bool same(int x, int y) { return find(x) == find(y); }
};

struct Edge {
    int from, to, cost;
    bool operator<(const Edge &rhs) { return cost < rhs.cost; }
};

bool solve() {
    int N, M;
    cin >> N >> M;
    if (N == 0) return false;
    vector<Edge> es;
    UnionFind uf(N);
    REP(i, M) {
        int u, v, c;
        cin >> u >> v >> c;
        u--, v--;
        es.push_back({u, v, c});
    }
    sort(all(es));
    int ans = 1e18;

    // REP(i, N) { cout << es[i].from << " " << es[i].to << " " << es[i].cost << endl; }
    REP(i, M) {
        uf.init(N);
        FOR(j, i, M) {
            uf.unite(es[j].from, es[j].to);
            if (uf.siz[uf.find(0)] == N) {
                int res = es[j].cost - es[i].cost;
                ans = min(ans, res);
                break;
            }
        }
        if (uf.siz[uf.find(0)] != N) break;
    }
    if (ans == 1e18)
        cout << -1 << endl;
    else
        cout << ans << endl;
    return true;
}

signed main() {
    while (solve())
        ;
}


Measured memory_bytes: 3260
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;
 
int N;
int A[100001];
int num[100001]={0};
 
int main()
{
	scanf("%d", &N);
	for (int i = 1; i <= N; ++i) scanf("%d", A + i);
 
	for (int i = 1; i <= N; ++i){
		num[A[i]]++;
	}
 
	std::vector<int> v;
	for (int i = 1; i <= 100000; ++i){
		if( num[i] ){
			while( num[i] >= 3 ){
				num[i] -= 2;
			}
			v.push_back(num[i]);
		}
	}
 
	int num_even = 0;
 
	for(auto itr = v.begin(); itr != v.end(); ++itr) {
		if (*itr == 2 ){
			num_even++;
		}
	}
 
	printf("%d\n", v.size() - (num_even%2) );
 
	return 0;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
#define ll long long
#define fort(i,n) for (int i = 1; i <= n; ++i)
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define sz size()
#define er erase
#define fr first
#define sc second
#define rc(x) return cout << x, 0
using namespace std;



int32_t main()
{
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    int a,b;
    cin >> a >> b;
    if (b%a==0) rc(a+b);
    cout << b-a;
}


Measured memory_bytes: 256
import sys
def main():
    num_a, num_b = map(int, input().split())
    data_a = [list(input()) for i in range(num_a)]
    data_b = [list(input()) for i in range(num_b)]

    for i in range(num_a - num_b + 1):
        for j in range(num_a - num_b + 1):
            ok_flg = 1
            for k in range(num_b):
                for l in range(num_b):
                    # print(data_b[k][l],  data_a[k + i][l + j])
                    if data_b[k][l] != data_a[k + i][l + j]:
                        ok_flg = 0
                        break
            if ok_flg:
                print('Yes')
                sys.exit()

    print('No')



if __name__ == '__main__':
    main()


Measured memory_bytes: 40176
/*
  AOJ 2031
  Title:Hyper Rock-Scissors-Paper
  @kankichi573
*/
#include <stdio.h>

char hands_table[15][11]={
"Rock", "Fire", "Scissors", "Snake", "Human", "Tree", "Wolf", "Sponge",
"Paper", "Air", "Water", "Dragon", "Devil", "Lightning", "Gun"};

int N;
int table[15];
int table2[15]; 
char input[11];

int solve()
{
  int i,j,ret,win;

  for(i=0;i<15;i++)
    {
      if(table2[i]==-1)
	continue;
      win=0;
      for(j=0;j<15;j++)
	{
	  if(table2[j]==-1 || i==j)
	    continue;

	  ret=hantei(table2[i],table2[j]);
          if(ret==1)
	    win++;
	  if(ret<=0)
	    goto NEXT;
	}
      if(win)
	return(i);
    NEXT:
      ;
    }
  return(-1);
}
int hantei(int h1,int h2)
{
  int dif;

  if(h1==-1 || h2==-1)
    return(0);
  dif=h2-h1;
  if(dif<0)
    dif+=15;
  if(dif==0)
    return(0);
  else if(dif<8)
    return(1);
  else
    return(-1);
}
int hand2num(char * input)
{
  int i;
  for(i=0;i<15;i++)
    if(0==strcmp(input,&hands_table[i][0]))
      return(i);
  return(-1); //no reach
}
dump()
{
  int i;
  for(i=0;i<15;i++)
    if(table[i])
      printf("%s:%d\n",hands_table[i],table[i]);
}
dump2()
{
  int i;
  for(i=0;i<15;i++)
    if(table2[i]!=-1)
      printf("%s:%d\n",hands_table[i],table2[i]);
}
main()
{
  int i,ret;

  while(scanf("%d",&N) && N)
    {
      for(i=0;i<15;i++)
	{
	  table[i]=0;
	  table2[i]=-1;
	}
      for(i=0;i<N;i++)
	{
	  scanf("%s",input);
	  table[hand2num(input)]++;
	}
      for(i=0;i<15;i++)
	if(table[i])
	  table2[i]=i;
      //dump2();
	  
	  
      ret=solve();
      if(ret>=0)
	printf("%s\n",hands_table[ret]);
      else
	printf("Draw\n");
      

    }
  return(0);
}

Measured memory_bytes: 600
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var N = Double.Parse(Console.ReadLine());
        double min = Math.Pow(10, 11);
        for (var a = 1; a <= Math.Sqrt((double) N); a++)
        {
            if (N % a != 0) continue;

            var b = N / a;
            var res = new [] {NumberOfDigits(a), NumberOfDigits(b)}.Max();
            if (res < min) min = res;
        }

        Console.WriteLine(min);
    }

    static int NumberOfDigits(double n)
    {
        var num = 1;
        while (true)
        {
            if (n / 10 < 1) break;
            n /= 10;
            num++;
        }

        return num;
    }
}


Measured memory_bytes: 28392
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
 
int main(){
    long n = 0;
    while (cin >> n){
        if (n == 0) break;
        vector<long> s(n, 0);
        for (long i = 0; i < n; i++){
            cin >> s[i];
        }
        long t = 0;
        for (long i = 0; i < n; i++){
            t += s[i];
        }
        double ave = 0;
        ave = (double)t / n;
        double sum = 0;
        for (long i = 0; i < n; i++){
            sum += (s[i] - ave) * (s[i] - ave);
        }
        cout << fixed << sqrt(sum / n) << endl;
    }
    return 0;
}

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

int main() {
  int n, m, i, sum = 0;
  cin >> n >> m;
  vector<pair<int, int>> ab(n);
  for (i = 0; i < n; i++)
    cin >> ab[i].first >> ab[i].second;
  sort(ab.begin(), ab.end());
  priority_queue<int> q; i = 0;
  for (int now = m-1; now >= 0; now--) {
    while (i < n && ab[i].first <= m-now)
      q.push(ab[i++].second);
    if (q.size()) {
      sum += q.top(); q.pop();
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 1660
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>

using namespace std;

struct Node {
  int key;
  Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k) {
  Node *y = NIL;
  Node *x = root;
  Node *z;

  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL) {
    y = x;
    if(z->key < x->key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }
  z->parent = y;

  if(y == NIL) {
    root = z;
  } else {
    if(z->key < y->key) {
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

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

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

int main() {
  int n, i, x;
  string com;
  scanf("%d", &n);

  for(i = 0; i < n; i++) {
    cin>>com;
    if(com == "insert") {
      scanf("%d", &x);
      insert(x);
    } else if(com == "print") {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}



Measured memory_bytes: 26716