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

int main()
{
  int A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;

  int ans = 0;
  for(;;) {
    if(X <= 0 && Y <= 0) {
      cout << ans << endl;
      return 0;
    }

    if(X > 0 && Y > 0) {
      ans += min(A+B, C*2);
      --X;
      --Y;
    }
    else if (X > 0 && Y <= 0) {
      ans += min(A, C*2);
      --X;
    }
    else {
      ans += min(B, C*2);
      --Y;
    }
  }
}


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

int main(void){

  int a , b,i;
  cin >> a >> b;
  i = 1;
  while(1){
    
      if(b == 1){
          cout << "0" << endl;
          break;
      }
      if((a-1)*(i-1) + a  >= b){
          
        cout << i << endl;
        break;
      }
      
      i ++;
      
    }
    
  
  
  
  return 0;

}


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

using namespace std;

int main() {
	int a[9] = {};
	for (int i = 0; i < 6; i++) {
		int b;
		cin >> b;
		a[b]++;
		if (a[b] > 2) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}


Measured memory_bytes: 256
N,W = map(int,input().split())
w,v = [0]*N,[0]*N
for i in range(N):
    w[i],v[i] = map(int,input().split())
    
# dp[i][j]:i番目の品物を詰めて重さjのときの価値の最大値
dp = [[0]*(W+1) for i in range(N+1)]

#w[i-1]を使うかどうか
for i in range(1,N+1):
    #ナップサックの残りの容量(0-Wまで) 
    for j in range(W+1):
        if j >= w[i-1]:
            dp[i][j] = max(dp[i-1][j-w[i-1]]+v[i-1],dp[i-1][j])
        else:
            dp[i][j] = dp[i-1][j]
            
print(dp[-1][-1]) 

Measured memory_bytes: 119916
n = int(input())

def divisior(n):
    a = []
    i = 1
    while (i*i <= n):
        if n%i == 0:
            a.append(i)
            if (i*i != n): a.append(n//i)
        i += 1
    return a

ans = 0
a = divisior(n)

for x in a:
    if x == 1: continue
    tmp = n
    while (tmp%x == 0): tmp = tmp//x
    if (tmp%x == 1) : ans += 1

b = divisior(n-1)

ans = ans + len(b) -1

print(ans)




Measured memory_bytes: 3188
//FIRST THINK THEN CODE.

#include <bits/stdc++.h>


using namespace std;

typedef long long ll;

#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 FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vld vector<ld>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define vvld vector<vector<ld>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define rev(p) reverse(p.begin(),p.end());
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)
#define sz(x) ((ll)x.size())
const ll M = 1000000007;
const ll MM = 998244353;
ll begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define trace(...)
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

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

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



ll powM(ll a, ll b, ll m)
{
  if (a <= 0)return 0;
  a %= m;
  ll ans = 1LL;
  while (b)
  {
    if (b & 1)ans = ans * a % m;
    a = a * a % m;
    b >>= 1;
  }

  return ans;
}



ll poww(ll a, ll b)
{

  ll ans = 1;
  while (b)
  {
    if (b & 1)ans = ans * a;
    a = a * a;
    b >>= 1;
  }

  return ans;

}


string tostring(ll x) {
  stringstream sss;
  sss << x;
  string ans = sss.str();
  return ans;
}



const ll N = 1e6 + 5;



int main() {

  IOS;

#ifndef ONLINE_JUDGE

  freopen("input1.txt", "r", stdin);
  freopen("output1.txt", "w", stdout);

#endif

  ll a, b, c, d;
  cin >> a >> b >> c >> d;

  ll x1 = a * c;
  chmax(x1, a * d);
  ll x2 = b * d;
  chmax(x2, b * c);
  ll x3 = max(x2, x1);

  cout << x3 << endl;


  //end_routine();



  return 0;
}

Measured memory_bytes: 3676
H,W = map(int,input().split())
alp = [0]*26
for i in range(H):
    for c in input():
        alp[ord(c)-97] += 1
m4 = [0]*4
for i in alp:
    m4[i%4] += 1
if m4[1]+m4[3] <= H%2*W%2 and m4[2] <= (H//2)*(W%2)+(W//2)*(H%2):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
IDENTIFICATION DIVISION.
PROGRAM-ID. 168A.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 N          PIC 9(03).
*>
PROCEDURE DIVISION.
  ACCEPT N.
*>
  EVALUATE N(3:1)
    WHEN '2'
    WHEN '4' 
    WHEN '5'
    WHEN '7'
    WHEN '9'
      DISPLAY 'hon'
    WHEN '0'
    WHEN '1'
    WHEN '6'
    WHEN '8'
      DISPLAY 'pon'
    WHEN '3'
      DISPLAY 'bon'
  END-EVALUATE. 
*>
  STOP RUN.


Measured memory_bytes: 3792
N, M = map(int, input().split())
SC = []
for i in range(M):
    s, c = map(int, input().split())
    SC.append((s-1,str(c)))

if N == 1:
    lo = 0
else:
    lo = 10**(N-1)
hi = 10**N
def solve():
    for n in range(lo, hi):
        n = str(n)
        if all(n[s] == c for s, c in SC):
            return n
    return -1

print(solve())



Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main() {
  int X;
  cin >> X;
  int ans = X;
  primecheck:
  for (int i = 2;i * i <= ans;++ i) {
    if (ans % i == 0) {
      ++ ans;
      goto primecheck;
    }
  }
  cout << ans;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>
#include <random>
using namespace std;
char par[101];
int length, score, min_score;

int main(void) {
	scanf("%d", &length);
	scanf("%s", par);
	score = 0; min_score = 0;
	for (int i = 0; i < length; i++) {
		if (par[i] == '(') {
			score += 1;
		}
		else {
			score -= 1;
		}
		if (min_score > score) {
			min_score = score;
		}
	}
	for (int i = 0; i < -min_score; i++) {
		printf("(");
	}
	printf("%s", par);
	for (int i = 0; i < score - min_score; i++) {
		printf(")");
	}
}

Measured memory_bytes: 888
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }

int get_bit(int x, int b) {
    if (((x >> b) & 0x01) != 0) return 1;
    return 0;
}

int get_bit_num(int x, int N) {
    int ret = 0;
    rep(i, N) {
        if (((x >> i) & 0x01) != 0) ret++;
    }
    return ret;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    vector<vector<pair<int, int>>> graph(N + 1);
    rep(i, N) {
        int A;
        cin >> A;
        rep(j, A) {
            int x, y;
            cin >> x >> y;
            graph[i + 1].push_back(make_pair(x, y));
        }
    }

    int ans = 0;
    rep(x, 1 << N) {
        bool is_ok = true;
        rep(b, N) {
            int mask = get_bit(x, b);
            if (mask == 0) continue;
            for (auto &adj : graph[b + 1]){
                if (get_bit(x, adj.first - 1) != adj.second) {
                    is_ok = false;
                    break;
                }
            }
            if (is_ok == false) {
                break;
            }
        }
        if (is_ok == true) {
            int bit_num = get_bit_num(x, N);
            ans = max(ans, bit_num);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define INF10 1001001001 
#define INF5 100000
#define EPS 1e-10


int main() {
	int N; cin >> N;
	cout << N * N << endl;






	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define PB push_back
#define MP make_pair
#define REP(i,n) for(int i=0;i<(n);i++)
int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<max(a*b,c*d)<<endl;
}

Measured memory_bytes: 256
/*
    Author - Param Kothari
    Ah shit, here we go again
*/

#include <bits/stdc++.h>
 
using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair

typedef long long ll;
typedef long double ld;

void solve(){
    int n;
    cin >> n;
    vector<ll> a(n);
    map<ll, ll> m1, m2;
    for(ll i = 0; i < n; i++){
        cin >> a[i];
        m1[i - a[i]]++;
        m2[i + a[i]]++;
    }
    ll res = 0;
    for(auto x : m1){
        res += (x.second * (m2[x.first]));
    }
    cout << res << "\n";
    return;
}

int main(){
    IOS;
    int t = 1;
    // cin >> t;
    for(int i = 1; i <= t; i++){
        solve();
    }
    return 0;
}


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

struct UnionFind {
    vector<int> d; // d[a]=bのとき、「aの親がbである」ということを表す。

    UnionFind(int n=0): d(n, -1) {} // 全て根であるとみなす。d[x]==-1のとき、そのノードは根である。

    int find(int x) {
        if (d[x] < 0) return x; // 今の頂点が根ならその値を返す
        return d[x] = find(d[x]); // 経路縮約（メモ化）
    }

    bool unite(int x, int y) { // Minimum Spanning Treeのためにboolを返す実装にしている。
        int rx = find(x);
        int ry = find(y);

        if (rx == ry) return false;
        if (d[rx] > d[ry]) swap(rx, ry); // マイナスサイズなので不等号が逆。xのサイズの方が大きいようにする。
        d[rx] += d[ry]; // 連結成分のサイズを管理するためのコード
        d[ry] = rx; // xにyをくっつける。yの値をxの根とする。
        return true;
    }

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


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

    UnionFind uf(N);
    vector<int> deg(N, 0);
    vector<vector<int>> to(N, vector<int>());

    rep(i, M) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        deg[a]++;
        deg[b]++;
        uf.unite(a, b);
    }

    rep(i, K) {
        int c, d;
        cin >> c >> d;
        --c;
        --d;
        to[c].push_back(d);
        to[d].push_back(c);
    }

    rep(i, N) {
        int ans = uf.size(i) - 1 - deg[i];
        for (int u: to[i]) if (uf.same(i, u)) --ans;
        cout << ans << " ";
    }
    cout << endl;
}


Measured memory_bytes: 6784
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,K;
  string S;
  cin>>N>>S>>K;
  for(int i=0;i<N;i++){
    if(S.at(K-1)!=S.at(i))S.at(i)='*';
    cout<<S.at(i);
  }
  cout<<endl;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define SQ(x) (x)*(x)
#define MN(a,b) a = min(a,(__typeof__(a))(b))
#define MX(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#ifdef BALBIT
#define IOS()
#define bug(...) fprintf(stderr,"#%d (%s) = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define bug(...)
#endif

const int iinf = 1e9+10;
const ll inf = 1ll<<60;
const ll mod = 1e9+7 ;

#define int ll
void GG(){cout<<"0\n"; exit(0);}

ll mpow(ll a, ll n, ll mo = mod){ // a^n % mod
    ll re=1;
    while (n>0){
        if (n&1) re = re*a %mo;
        a = a*a %mo;
        n>>=1;
    }
    return re;
}

ll inv (ll b, ll mo = mod){
    if (b==1) return b;
    return (mo-mo/b) * inv(mo%b,mo) % mo;
}

const int maxn = 2e3+10;

bitset<maxn*maxn/2> bs;

signed main(){
    IOS();
    int n; cin>>n;
    bs[0] = 1;
    ll s=0;
    for (int i = 0; i<n; ++i) {
        int a; cin>>a;
        s += a;
        bs |= (bs << a);
    }
    for (int i = s/2; i>=0; --i) {
        if (bs[i]) {
            cout<<s-i<<endl; return 0;
        }
    }

}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b;
  cin >> a >> b;
  if(a < 10 && b < 10){
    cout << a * b;
  }
  else{
    cout << -1 << endl;
  }

  return 0;
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    lint a;cin >> a;
    lint ans=a+a*a+a*a*a;
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    vector<int> A(N);
    for(int i=0;i<N;i++)cin>>A[i];
    reverse(A.begin(),A.end());
    for(int i=0;i<N;i++){
        cout<<A[i];
        if(i==N-1)cout<<'\n';
        else cout<<' ';
    }
}


Measured memory_bytes: 3088
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 100000000000000;
const double PI = acos(-1);

int t[100100], a[100100];
int h[100100];

int main() {
	LL n, ans = 1; 
	cin >> n;
	vector<int> t(n + 2);
	vector<int> a(n + 2);
	for (int i = 1; i <= n; i++) {
		cin >> t[i];
	}
	t.back() = t[n];
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	a[0] = a[1];
	if (t[n] != a[1]) {
		cout << 0 << endl;
		return 0;
	}
	int maxt = 0, maxa = n + 2;
	for (int i = 1; i <= n; i++) {
		if (t[i - 1] < t[i]) {
			maxt = i;
		}
		if (a[i] > a[i + 1] && maxa == n + 2) {
			maxa = i;
		}
		if (t[i - 1]<t[i] || a[i]>a[i + 1]) continue;
		ans *= min(t[i], a[i]);
		ans %= MOD;
	}
	if (maxa < maxt) {
		cout << 0 << endl;
		return 0;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1152
using System;
class main{
  static void Main(){
    string a;
    int num;
    int[] list = new int[10];
    for(int i = 0; ; i++){
      a = Console.ReadLine();
      if(a == null) break;
      num = Convert.ToInt32(a);
      list[i] = num;
    }

    Array.Sort(list);
    for(int i = 0; i < 3; i++){
      Console.WriteLine(list[list.Length - i - 1]);
    }

  }
}



Measured memory_bytes: 20004
#include <string.h>
int main()
{
    int i, j, l;
    char s[120], t[120], c;
    gets(s);
    gets(t);
    l=strlen(s);
    for(i=0; i<l; i++)
    {
        if(strcmp(s, t)==0){
            printf("Yes\n");
            return 0;
        }
        c=t[l-1];
        for(j=l-1; j>=0; j--)
        {
            t[j]=t[j-1];
        }
        t[0]=c;
    }
    //printf("%s\n", t);
    printf("No\n");

    return 0;
}

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

int main(void){
  string a,b,c,d,e,f;
  cin>>a>>b>>c;
  d=toupper(a[0]);
  e=toupper(b[0]);
  f=toupper(c[0]);
  cout<<d+e+f;
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

#include <bits/stdc++.h>
using namespace std;

template<typename T>
void cmpmax(T* reference, T value) {
	*reference = max(*reference, value);
}

template<typename T>
void cmpmin(T* reference, T value) {
	*reference = min(*reference, value);
}

const ll mod = 998244353;

static const ll INF = 1e15;


int main() {
	ll n, s;
	cin >> n >> s;
	vector<ll> vs(n);
	rep(i, n) {
		cin >> vs[i];
	}
	vector<vector<ll>> dp(n+1, vector<ll>(s + 1, 0));
	dp[0][0] = 1;
	rep(i, n) {
		rep(j, s + 1) {
			dp[i + 1][j] = 2 * dp[i][j];
			dp[i + 1][j] %= mod;
		}
		for (int j = 0; j + vs[i] < s + 1; j++) {
			dp[i + 1][j + vs[i]] += dp[i][j];
			dp[i + 1][j + vs[i]] %= mod;
		}
	}
	cout << dp[n][s] << endl;
	return 0;
}
	


Measured memory_bytes: 73684
from collections import deque
def solve():
    S = input()
    S = deque(S)
    Q = int(input())

    isReversed = False
    for i in range(Q):
        query = list(input().split())
        T = int(query[0])
        if T == 1:
            if isReversed:
                isReversed = False
            else:
                isReversed = True
        if T == 2:
            F = int(query[1])
            C = query[2]
            # 先頭
            if (isReversed and F == 2) or (not isReversed and F == 1):
                S.appendleft(C)
            # 末尾
            else:
                S.append(C)
        
    ans = ""
    if isReversed:
        ans = list(S)[::-1]
    else:
        ans = list(S)
        
    print("".join(ans))

if __name__ == '__main__':
    solve()

Measured memory_bytes: 81112
#!/usr/bin/env python3
import sys

input = sys.stdin.readline


def S():
    return input().rstrip()


def I():
    return int(input())


def MI():
    return map(int, input().split())


k = I()

m = k % 10
if m % 2 == 0 or m == 5:
    print(-1)
    exit()
if k == 1 or k == 7:
    print(1)
    exit()
else:
    rk = 7
    for i in range(2, 10 ** 6 + 1):
        rk1 = ((10 % k) * rk % k + 7 % k) % k
        if rk1 == 0:
            print(i)
            exit()
        rk = rk1


Measured memory_bytes: 9192
N = int(input())
S = []
for i in range(N):
    S.append(input())
cnt = 0
cntA = 0
cntB = 0
cntAB = 0
for s in S:
    cnt += s.count('AB')
for s in S:
    if s[0] == 'B':
        cntB += 1
    if s[-1] == 'A':
        cntA += 1
    if s[0]=='B' and s[-1] =='A':
        cntAB += 1
if cntA == cntB == cntAB != 0:
    print(cnt + cntAB - 1)
else:
    print(cnt + min(cntA, cntB))


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

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

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

    int sum[n];

    for(int i=0;i<n;i++){
        sum[i] = 0;
    }

    for(int c=0;c<n;c++){
        for(int x=0;x<c+1;x++){
            sum[c] += a[0][x];
        }
        for(int x=c;x<n;x++){
            sum[c] += a[1][x];
        }
    }

    int max=sum[0];
    for(int i=0;i<n;i++){
        if(max<=sum[i]){
            max = sum[i];
        }
    }

    cout << max << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, z = 0;
    ll a[200005] = {}, b[200005] = {}, k;
    cin >> n >> m >> k;
    for ( int i = 1 ; i <= n ; i++ ) cin >> a[i];
    for ( int i = 1 ; i <= m ; i++ ) cin >> b[i];
    for ( int i = 1 ; i <= n ; i++ ) a[i] += a[i - 1];
    for ( int i = 1 ; i <= m ; i++ ) b[i] += b[i - 1];
    for ( int i = 0 ; i <= n ; i++ ) {
        if ( a[i] <= k ) {
            int l = 0 , r = m + 1;
            while ( l + 1 < r ) {
                int x = ( l + r ) / 2;
                if ( a[i] + b[x] <= k ) l = x;
                else r = x;
            }
            z = max( z , i + l );
        }
    }
    cout << z;
}



Measured memory_bytes: 6748
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<map>

using namespace std;
#define mod 1000000007
#define ll long long 


int dp[3009][3009];
int n, m;
string s, t;

// int solve(int idx, int jdx) {
//   if(idx == n || jdx == n)
//     	return 0;
// 	if(dp[idx][jdx] != -1)
//       return dp[idx][jdx];
//   if(s[idx] == t[jdx])
//     	dp[idx][jdx] = 1 + solve(idx + 1, jdx + 1);
//   else
//     dp[idx][jdx] = max(solve(idx + 1, jdx), solve(idx, jdx + 1));
// 	return dp[idx][jdx];
// }


void lcs( string X, string Y) { 
	int m = X.length();
	int n = Y.length();
   	int L[m+1][n+1]; 
  
   	for (int i = 0; i <= m; i++) { 
    	for (int j = 0; j <= n; j++) { 
       		if (i == 0 || j == 0) 
         		L[i][j] = 0; 
       		else if (X[i - 1] == Y[j - 1]) 
         		L[i][j] = L[i - 1][j - 1] + 1; 
       		else
         	L[i][j] = max(L[i - 1][j], L[i][j - 1]); 
     	} 
   	} 

   	int index = L[m][n]; 
  
  	char lcs[index+1]; 
   	lcs[index] = '\0';	

   	int i = m, j = n; 
   	while (i > 0 && j > 0) { 
      
      	if (X[i-1] == Y[j-1]) { 
          	lcs[index-1] = X[i-1];
          	i--; j--; index--;
      	} 
  
  	    else if (L[i-1][j] > L[i][j-1]) 
    		i--; 
      	else
        	j--; 
  	}
  	cout<<lcs<<endl;
  
} 
  

int main() {
  	cin>>s>>t;
	n = s.length();
  	m = t.length();
  	lcs(s, t);
  	// memset(dp, -1, sizeof(dp));
  	// cout<<solve(0, 0)<<endl;

}

Measured memory_bytes: 35456
fun main(args: Array<String>) {
    val (n, t) = readLine()!!.split(' ').map(String::toInt)
    val aList = readLine()!!.split(' ').map(String::toInt)
    val lMax = IntArray(n)
    lMax[n - 1] = aList[n - 1]
    ((n - 2) downTo 0).forEach { lMax[it] = Math.max(lMax[it + 1], aList[it]) }
    val diffMap = mutableMapOf<Int, Int>()
    ((n - 1) downTo 0).forEach {
        val diff = lMax[it] - aList[it]
        diffMap[diff] = (diffMap[diff] ?:0) + 1
    }
    val maxKey = diffMap.keys.max()
    println(diffMap[maxKey])
}

Measured memory_bytes: 58044
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

A, B, C, X, Y = MAP()

ans = []
ans.append(A*X + B*Y)
ans.append(C*(max(X, Y))*2)
if X > Y:
	ans.append(Y*C*2 + A*(X-Y))
else:
	ans.append(X*C*2 + B*(Y-X))

#print(ans)
print(min(ans))



Measured memory_bytes: 5200
n, k = map(int, input().split())
Ps = list(map(int, input().split()))
Ps.insert(0,0)
Cs = list(map(int, input().split()))
Cs.insert(0,0)
Ls = [0] * (n + 1)  # 周期
As = [0] * (n) # 回答候補

# 周期を見つける
for i in range(1,n + 1):
  count = 1
  temp = Ps[i]
  while temp != i:
    temp = Ps[temp]
    count += 1
  Ls[i] = count

# それぞれの最大値を見つける
for i in range(1, n + 1):
  ans = 0
  p = [0] * Ls[i]  #途中経過集
  tempIndex = i
  tempSum = 0
  for j in range(Ls[i]):
    tempIndex = Ps[tempIndex]
    tempSum += Cs[tempIndex]
    p[j] = tempSum
  # print(f'p:{p}')
  # ansを求める
  if p[-1] <= 0:
    ans = max(p[:min(k,Ls[i])])
  else:
    q, r = divmod(k, Ls[i])
    # print(f'q,r,k,Ls[i]:{q}{r}{k}{Ls[i]}')
    start = (q - 1) * p[-1]
    anss = [0] * (r + Ls[i])
    anss.insert(0, start)
    tempIndex = i
    tempSum = start
    for z in range(r + Ls[i]): #rは高々Ls[i]、つまりn、つまり5 * (10**3)
      tempIndex = Ps[tempIndex]
      tempSum += Cs[tempIndex]
      anss[z + 1] = tempSum
    ans = max(anss)
  As[i-1] = ans
print(max(As))

Measured memory_bytes: 90628
#include <iostream>
#include <cmath>
using namespace std;
struct cordinate
{
	long long x;
	long long y;
	long long h;
};

int main()
{
	long long N;
	int flag = 0;
	cin >> N;
	cordinate* ip;
	ip = new cordinate[N];
	for (int i = 0;i < N;i++)
	{
		cin >> ip[i].x >> ip[i].y >> ip[i].h;
	}
	long long i, j, k;
	for (i = 0;i < N && ip[i].h == 0;i++);

	long long a = ip[i].x, b = ip[i].y;
	long long c = ip[i].h;
	

	for (i = 0;i <= 100;i++)
	{
		for (j = 0; j <= 100;j++)
		{
			flag = 1;
			for (k = 0;k < N;)
			{
				if (ip[k].h == 0)
				{
					if (abs(i - ip[k].x) + abs(j - ip[k].y) - abs(i - a) - abs(j - b) >= c)
					{
						k++;
						continue;
					}
					else
					{
						flag = 0;
						break;
					}
				}
				if ((abs(i - ip[k].x) + abs(j - ip[k].y) - (abs(i - a) + abs(j - b))) != c - ip[k].h)
				{
				flag = 0;
				break;
				}
				k++;
			}
			if (flag == 1) break;
		}
		if (flag == 1) break;
	}
	cout << i << ' ' << j << ' ' << abs(i - a) + abs(j - b) + c;
	delete[]ip;
}

Measured memory_bytes: 3608
def examA():
    O = SI()
    E = SI()
    ans = ""
    for i in range(len(O)+len(E)):
        if i%2==0:
            ans += O[i//2]
        else:
            ans += E[i//2]
    print(ans)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examA()

"""

"""

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

char s[100][101];
int main() {
	int m, n; scanf("%d%d", &m, &n);
	rep(i, m)scanf("%s", s[i]);
	int cnt = 0;
	for (int i = 1; i < m; i++)rep(j, n) {
		if (s[i][j] != '-')continue;
		if ((j&&s[i][j - 1] != '-') || (j < n - 1 && s[i][j + 1] != '-'))continue;
		for (int x = -1; x <= 1; x++)for (int y = -1; y <= 1; y++) {
			int nx = i + x, ny = j + y;
			if (0 <= nx&&nx < m && 0 <= ny&&ny < n) {
				if (s[nx][ny] == 'x')goto g;
			}
		}
		cnt++;
	g:;
	}
	printf("%d\n", cnt);
}

Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
//const int MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const double pi = acos(-1.0);
const double EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N, K;
    cin >> N >> K;
    int X[N];
    rep(i, N) cin >> X[i];
    int nl[N][20], nr[N][20];
    ll sl[N][20], sr[N][20];
    int ptr = 0;
    rep(i, N){
        while(ptr < N && X[ptr] < X[i]+K) ptr++;
        nl[i][0] = ptr, sl[i][0] = i;
    }
    ptr = N-1;
    rep3(i, N-1, 0){
        while(ptr >= 0 && X[ptr] > X[i]-K) ptr--;
        nr[i][0] = ptr, sr[i][0] = i+1;
    }
    rep2(j, 1, 19){
        rep(i, N){
            if(nl[i][j-1] == N){
                nl[i][j] = N;
                sl[i][j] = sl[i][j-1];
            }
            else{
                nl[i][j] = nl[nl[i][j-1]][j-1];
                sl[i][j] = sl[i][j-1]+sl[nl[i][j-1]][j-1];
            }
        }
        rep(i, N){
            if(nr[i][j-1] == -1){
                nr[i][j] = -1;
                sr[i][j] = sr[i][j-1];
            }
            else{
                nr[i][j] = nr[nr[i][j-1]][j-1];
                sr[i][j] = sr[i][j-1]+sr[nr[i][j-1]][j-1];
            }
        }
    }
    int Q;
    cin >> Q;
    while(Q--){
        int l, r; cin >> l >> r; l--, r--;
        ll suml = 0, sumr = 0;
        int pl = l, pr = r;
        rep3(i, 19, 0){
            if(nl[pl][i] <= r){
                suml += sl[pl][i], pl = nl[pl][i];
            }
        }
        suml += pl;
        rep3(i, 19, 0){
            if(nr[pr][i] >= l){
                sumr += sr[pr][i], pr = nr[pr][i];
            }
        }
        sumr += pr+1;
        cout << sumr-suml << endl;
    }
}

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

typedef vector<int> veci;
typedef pair<int,int> pii;
typedef vector<pii> vecii;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vecl;
typedef vector<pll> vecll;
#define EPS (1e-9)
#define MOD (1e9+7)
#define fi first
#define se second
#define endl '\n'

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef LOCAL_TEST    
    int tcs;
    cin >> tcs;
    while (tcs-->0)
#endif        
{
    int n;
    cin >> n;

    veci va(n,0);
    int max_p=0, max_abs=-1;
    for (int i=0; i<n; ++i) {
        cin >> va[i];
        if (va[i]>0) {
            if (va[i]>max_abs) {
                max_abs = va[i];
                max_p = i;
            }
        } else {
            if (-va[i]>max_abs) {
                max_abs = -va[i];
                max_p = i;
            }
        }
    }

    vecii res;
    for (int i=0; i<n; ++i) {
        if (i==max_p)
            continue;
        res.push_back({max_p+1,i+1});
    }

    if (va[max_p]>0) {
        for (int i=0; i<n-1; ++i)
            res.push_back({i+1,i+2});
    } else {
        for (int i=n-1; i>0; --i)
            res.push_back({i+1,i});
    }

    cout << res.size() << endl;
    for (auto e:res)
        cout << e.fi << " " << e.se << endl;
}}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i < n; i++)
#define elif else if
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = 1e18;

int main(){
    int N;
    cin >> N;
    int A[N];
    queue<int> que[3];
    ll ans = 1;
    rep(i, N){
        cin >> A[i];
        ll count = 0;
        rep(j, 3){
            if(que[j].size() == A[i]) count++;
        }
        rep(j, 3){
            if(que[j].size() == A[i]){
                que[j].push(i);
                break;
            }
        }
        ans *= count;
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3

from collections import deque


H, W = map(int,input().split()) 
graph = [input() for i in range(H)]#graphの作成
dist = [[-1]*W for i in range(H)]
que = deque()#queueの作成（今回は、初期値が#のところからスタート）

#スタート位置の読み込み（＃の位置）
for h in range(H):
    for w in range(W):
        if graph[h][w] == "#":
            que.append([h, w])
            dist[h][w] = 0 #黒は0、白は-1（なんでもOK）
            
def bfs(que, dist):
    cnt = 0 #黒に塗った回数
    while que:
        y, x = que.popleft()#先に入れたものを出すので最短経路になる
        cnt = dist[y][x] #
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):#上下左右に動かす
            new_y, new_x = y+j, x+k
            if new_y < 0 or H <= new_y or new_x < 0 or W <= new_x:#端っこはスルー
                continue
            elif dist[new_y][new_x] == -1:#セルが白やったら
                dist[new_y][new_x] = cnt+1 #黒からの距離をcnt+1にして
                que.append([new_y, new_x]) #黒にしたので、queに加える
    return cnt #黒のセルをすべて調べたら（結局すべて黒になるが）終わり

print(bfs(que,dist))

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

int main() {
    int K, A, B;
    cin >> K >> A >> B;
    for (int i = A; i <= B; i++) {
        if (i % K == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "YES"; }
  string_type do_falsename() const { return "NO"; }
};

void solve(string S) {
  int res = 0;
  for (int len = 0; len * 2 < int(S.size()); ++len) {
    if (S.substr(0, len) == S.substr(len, len))
      chmax(res, len * 2);
  }
  cout << res << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	string S;
	cin >> S;
	solve(S);
	return 0;
}


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

struct edge{
    int to, cost;
};

int n;
int dist[810];
bool visited[810];
vector<edge> g[810];

void dfs(int v){
    visited[v]=true;
    for(int i=0; i<g[v].size(); i++){
        if(!visited[g[v][i].to] && g[g[v][i].to].size()>1){
            dist[g[v][i].to]=dist[v]+g[v][i].cost;
            //cout << "dist["<<g[v][i].to<<"]="<<dist[g[v][i].to]<<"\n";
            dfs(g[v][i].to);
        }
    }
}

int main(){
    while(cin>>n, n){
        //cout << "##############"<<"\n";
        int p[810];
        int sum=0, d, bridge[810][810];
        for(int i=0; i<801; i++){
            g[i].clear();
            dist[i]=0;
            visited[i]=false;
            for(int j=0; j<801; j++){
                bridge[i][j]=0;
            }
        }
        for(int i=2; i<=n; i++){
            cin >> p[i];
        }
        for(int i=2; i<=n; i++){
            cin >> d;
            g[i].push_back((edge){p[i], d});
            g[p[i]].push_back((edge){i, d});
            bridge[i][p[i]]=bridge[p[i]][i]=d;
            sum+=d*3;
        }
        //cout<<"sum="<<sum<<"\n";
        dist[1]=0;
        dfs(1);
        int max0=0, start=0;
        for(int i=1; i<=n; i++){
            //cout << dist[i] << "\n";
            if(max0 < dist[i]){
                max0=dist[i];
                start=i;
            }
        }
        //cout << "------"<<"\n";
        fill(dist, dist+(n+1), 0);
        fill(visited, visited+(n+1), false);
        dfs(start);
        int diameter=0;
        for(int i=1; i<=n; i++){
            //cout << dist[i] << "\n";
            if(diameter<dist[i]){
                diameter=max(diameter, dist[i]);
            }
        }
        //cout << start << " " << end<<"\n";
        for(int i=1; i<=n; i++){
            int now=0, cnt=0;
            for(int j=1; j<=n; j++){
                if(bridge[i][j]>0 || bridge[i][j]==-1){
                    cnt++;
                    now=j;
                }
            }
            //cout << "size=" << g[i].size() << "\n";
			if(cnt!=1) continue;
			//if(i==start || i==end) sum-=bridge[i][now];
			sum-=2*bridge[i][now];//葉の島へかかる分は引く(i:葉の島 now:その親のときcount=1)
			bridge[i][now]=bridge[now][i]=-1;
			//cout << i << ", "<<sum<<"\n";
        }
        cout << (sum-diameter) << "\n";
    }
}


Measured memory_bytes: 5756
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cstdlib>
#include<sstream>
#include<fstream>
#include<vector>
#include<list>
#include<deque>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cmath>
#include<utility>
#include<numeric>
#include<iterator>
#include<algorithm>
#include<functional>
#include<ctime>
#include<cassert>
using std::cin;
using std::cout;
using std::endl;
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> P;
#define FOR(i,init,len) for(int i=(init);i<(len);++i)
#define For(i,init,len) for(int i=(init);i<=(len);++i)
#define fi first
#define se second
#define pb push_back
#define is insert
namespace IO {
	inline char getchar() {
		static const int BUFSIZE=5201314;
		static char buf[BUFSIZE],*begin,*end;
		if(begin==end) {
			begin=buf;
			end=buf+fread(buf,1,BUFSIZE,stdin);
			if(begin==end) return -1;
		}
		return *begin++;
	}
}
inline void read(int &in) {
	int c,symbol=1;
	while(isspace(c=IO::getchar()));
	if(c=='-') { in=0;symbol=-1; }
	else in=c-'0';
	while(isdigit(c=IO::getchar())) { in*=10;in+=c-'0'; }
	in*=symbol;
}
inline int read() { static int x;read(x);return x; }
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
#define PA(name,init,len) cout<<#name"["<<(len-init)<<"]=";FOR(_,init,len) cout<<name[_]<<" \n"[_==(len-1)];
#define Pa(name,init,len) cout<<#name"["<<(len-init+1)<<"]=";For(_,init,len) cout<<name[_]<<" \n"[_==(len)];
#define PV(name) cout<<#name"="<<name<<'\n';

int n;
const int maxn=15;
const int INF=1e9;
int d[maxn][maxn];

int main() {

    while(scanf("%d",&n)==1&&n){
        For(i,0,9) For(j,0,9) d[i][j]=INF;
        For(i,0,9) d[i][i]=0;
        int ma=0;
        FOR(i,0,n){int a,b,c;scanf("%d%d%d",&a,&b,&c);d[a][b]=d[b][a]=c;ma=std::max(ma,std::max(a,b));}
        For(k,0,ma) For(i,0,ma) For(j,0,ma) d[i][j]=std::min(d[i][j],d[i][k]+d[k][j]);
        int idx=0,ans=INF;
        For(i,0,ma){
            int t=0;
            For(j,0,ma) t+=d[i][j];
            if(t<ans) {idx=i;ans=t;}
        } 
        printf("%d %d\n",idx,ans);
    }

	return 0;
}



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

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

 int main() {
   int n;
   cin >> n;
   vector<int> ans(26, 50);

   rep(i, n) {
     string s;
     vector<int> tmp(26, 0);
     cin >> s;
     rep(j, s.length()) tmp.at((int)(s.at(j) - 'a'))++;
     rep(k, 26) {
       ans.at(k) = min(ans.at(k), tmp.at(k));
     }
   }

   rep(i, 26) {
     if (ans.at(i) > 0) {
       rep(j, ans.at(i)) {
         cout << (char)(i + 'a');
       }
     }
   }
   cout << endl;
 }


Measured memory_bytes: 256
N = int(input())
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
AB = sorted(list(set(A + B)))
D = {ab: i+1 for i, ab in enumerate(AB)}
A = [D[a] for a in A]
B = [D[a] for a in B]
def chk(L):
    NN = 5
    BIT=[0] * (2**NN+1)
    def addbit(i):
        while i <= 2**NN:
            BIT[i] += 1
            i += i & (-i)
 
    def getsum(i):
        ret = 0
        while i != 0:
            ret += BIT[i]
            i -= i&(-i)
        return ret
    s = 0
    for l in L[::-1]:
        s += getsum(l+1)
        addbit(l+1)
    return s
ans = 1 << 100
for m in range(1<<N):
    if bin(m).count("1") & 1: continue
    C = [[], []]
    for i in range(N):
        p = m >> i & 1
        q = p + i & 1
        C[q].append(((A[i] if p == 0 else B[i]) << 5) + i)
    if len(C[1]) != N // 2: continue
    C[0].sort()
    C[1].sort()
    CC = [C[i&1][i//2] for i in range(N)]
    for i in range(1, N):
        if CC[i-1] >> 5 > CC[i] >> 5: break
    else:
        CCC = [c % 32 for c in CC]
        ans = min(ans, chk(CCC))
print(ans if ans < 1 << 100 else -1)

Measured memory_bytes: 52956
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int u32;
typedef pair<int, int> p;
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; }
int Inf = (1<<30);
ll inf = (1LL<<60);
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main() {
	ll n, k;
	cin >> n >> k;
	int i;
	vector<ll> num(110000,0);
	for (i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		num[a] += b;
	}
	ll sum = 0;
	for (i = 1; i <= 100000; i++) {
		sum += num[i];
		if (sum >= k) {
			cout << i;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 1152
#include "bits/stdc++.h"

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define P3(a, b, c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main(){
    char N,ans;
    cin >> N;
    ans=N+1;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_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(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template
int N;
bool prime(int a) {
    for(int i = 2; i * i <= a; i++) {
        if(a % i == 0) return false;
    }
    return true;
}

vector<int> calc() {
    vector<int> ret;
    for(int i = 3; i <= 55555; i += 5) {
        if(prime(i)) {
            ret.pb(i);
            if(ret.size() >= N) break;
        }
        
    }
    return ret;
}

template <typename T> inline void voutput(T &v){
    rep(i, v.size()){
        if (i) cout << " " << v[i];
        else cout << v[i];
    }
    cout << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    
    cin >> N;
    auto A = calc();
    voutput(A);
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <chrono>
#include <random>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	int n, x;
	std::cin >> n >> x;
	std::swap(n, x);
	x--;
	for(int d = -x; d <= x; d++) {
		std::cout << d + n << (d==x?'\n':' ');
	}
}

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

#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 
int main()
{
    int X[3];
    cin >> X[0] >> X[1] >> X[2];
    cout << X[2] << " " << X[0] << " " << X[1] << endl;
    return 0;
}



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

int main()
{
	int N, K = 0;
	std::cin >> N >> K;

	std::vector<bool> kids(N);
	for (int i = 0; i < N; ++i)
	{
		kids.at(i) = false;
	}

	for (int i = 0; i < K; ++i)
	{
		int tempA = 0;
		std::cin >> tempA;
		for (int j = 0; j < tempA; ++j)
		{
			int tempB = 0;
			std::cin >> tempB;
			if (!kids.at(tempB - 1))
			{
				kids.at(tempB - 1) = true;
			}
		}
	}

	int answer = 0;
	for (int i = 0; i < N; ++i)
	{
		if (!kids.at(i))
		{
			answer++;
		}
	}

	std::cout << answer << "\n";

	return 0;
}

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

using namespace std;



int main(){
	int N, Sn,m;
	
	Sn=0;

	cin>>N;
	m=N;
	while(10<=N){
		Sn=Sn+N%10;
		N=N/10;
	}
	
	Sn = Sn+N;
	
	
	if(m%Sn==0) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	
}


Measured memory_bytes: 256
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
typedef long long ll;

using namespace std;


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	vector<vector<int>> v(3, vector<int>(3));
	vector<vector<bool>> v2(3, vector<bool>(3,false));
	rep(i, 3)
		rep(j, 3)
		cin >> v[i][j];
	int n; cin >> n;
	rep(_, n) {
		int b; cin >> b;
		rep(i, 3)
			rep(j, 3)
			if (v[i][j] == b)
				v2[i][j] = true;
	}
	bool ans = false;
	rep(i, 3)
		if (v2[i][0] && v2[i][1] && v2[i][2])
			ans = true;
	rep(j, 3)
		if (v2[0][j] && v2[1][j] && v2[2][j])
			ans = true;
	if (v2[0][0] && v2[1][1] && v2[2][2])
		ans = true;
	if (v2[0][2] && v2[1][1] && v2[2][0])
		ans = true;
	if (ans) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256