#include <bits/stdc++.h>
using namespace std;
#define int long long
#define Rep(i, N) for(int i = 0; i < N; i++)
#define Reps(i, x, N) for(int i = x; i < N; i++)

const int LLINF = 1LL << 60;

signed main()
{
  int N, P;

  while(cin >> N >> P, N || P) {

    int w = P;
    int have[55] = {0};
    int i = 0;
    while(true) {
      if(w) have[i]++, w--;
      else w += have[i], have[i] = 0;
      if(have[i] == P) { cout << i << endl; break; }
      i++; if(i == N) i = 0;
    }

  }

  return 0;
}

#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define dbg(x) cout<<#x"="<<x<<endl

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;

#define INF 1000000000

int stone[50];

int main(){

  while(true){
    int n,p;
    cin >> n >> p;
    if(n==0 && p==0) break;

    rep(i,n) stone[i]=0;
    int bowl=p;
    int idx=0;
    while(true){
      if(stone[idx]+1==p) break;
     //??????????????????
      while(bowl>0){
	stone[idx]++;
	bowl--;
	idx = (idx+1)%n;
      }

      //?¬???????????????£????????????
      while(stone[idx]==0) idx=(idx+1)%n;

      //????????\??????
      bowl=stone[idx];
      stone[idx]=0;
      idx= (idx+1)%n;
    }

    cout << idx << endl;

  }
}


#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>
#include <locale>
#include <omp.h>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;
typedef pair<long long int, pll> lpll;

const long long int mod = 1000000007;
const long long int INF = 1e18;
const long double PI=3.14159265358979323;
//const long long int pl=1000000;
long long int N,X,m[200200],res=INF,L,R;

int main(){
    cout << fixed << setprecision(18);
    cin>>L>>R;
    if(R-L>=2019){cout<<0<<endl;}
    else{
        for(long long int i = L; i <= R; i++){
            for(long long int j = i+1; j <= R; j++){
                res=min(res,(i*j)%2019);
            }
        }
        cout<<res<<endl;
    }
}

#include<iostream>
#include <string>
using namespace std;

int main(){
    while(1){
        int n,p;
        int flag=0;
        int have[50];
        //読み込み
        cin>>n>>p;
        int cup = p;
        if(n == 0 && cup==0){
            return 0;
        }

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

        for(int i=0;;i=(i+1)%n){
            if(cup==0){
                cup = have[i];
                have[i]=0;
            }else if(cup>0){
                have[i]++;
                cup--;
                if(have[i]==p){
                    cout<<i<<endl;
                    break;
                }
            }
        }
    }
}


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

int main()
{
    long long x;
    cin >> x;
    long long m = x % 11LL;
    long long q = x / 11LL;
    long long ans = 0LL;

    if (1 < m)
        ans++;
    if (7 <= m)
        ans++;
    ans += 2 * q;
    if (m == 1)
        ans++;
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define ANS cout << ans << endl
#define RETURN(x)    \
  cout << x << endl; \
  return 0
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

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

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

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

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

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;
}

signed main() {
  init();
  ll N;
  cin >> N;

  ll ans = N / 11;
  ans *= 2;
  ll amari = N % 11;
  if (amari == 0) {
    RETURN(ans);
  }
  if (amari <= 6) {
    ans++;
  } else if (amari <= 11) {
    ans += 2;
  }
  ANS;
  return 0;
}


#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
#define INF 1 << 30;

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

    int n;
    cin >> n;
    vector<ll> a(n);
    vector<vector<ll>> dp(n+1, vector<ll>(2, 0));
    dp[0][1] = -INF;
    ll sum = 0;
    for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
    for (int i = 0; i < n; i++) {
        dp[i+1][0] = max(dp[i][0]+a[i], dp[i][1]-a[i]);
        dp[i+1][1] = max(dp[i][0]-a[i], dp[i][1]+a[i]);
    }

    cout << dp[n][0] << endl;

}

#include <iostream>

using namespace std;
using ll = long long;

int main() {
  ll N, A, ans{}, s{}, m{1 << 30};
  cin >> N;
  for (int i = 0; i != N; ++i) {
    cin >> A;
    if (A < 0) A *= -1, ++s;
    m = min(m, A);
    ans += A;
  }
  cout << ans - (s % 2 ? 2 * m : 0) << endl;
}


#include <bits/stdc++.h>

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll N;
    cin >> N;
    vector<ll> a(N), b(N), c(N), d(N);
    vector<pair<ll, ll>> red, blue;
    vector<bool> isUsed(N, false);
    REP(i, N)
    {
        cin >> a[i] >> b[i];
        red.push_back(make_pair(a[i], b[i]));
    }
    REP(i, N)
    {
        cin >> c[i] >> d[i];
        blue.push_back(make_pair(c[i], d[i]));
    }
    sort(ALL(blue));

    ll ans = 0;
    REPV(it, blue)
    {
        ll bx = it->first, by = it->second;
        priority_queue<pair<ll, ll>> q;
        REP(i, N)
        {
            if (!isUsed[i])
            {
                ll rx = red[i].first, ry = red[i].second;
                if (rx < bx && ry < by)
                {
                    q.push(make_pair(ry, i));
                }
            }
        }
        if (!q.empty())
        {
            ans++;
            ll maxIndex = q.top().second;
            isUsed[maxIndex] = true;
        }
    }

    cout << ans << endl;
}

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

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

struct Point{
    ll x;
    ll y;
    Point(ll x, ll y): x(x), y(y) {}
    Point(){}
};

ll field[21][21];

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

    // input
    for(;;){
        // jewel num
        ll N;
        cin >> N;

        if(N==0) return 0;

        Point p = Point(10, 10);

        FOR(i, 0, 21){
            FOR(j, 0, 21){
                field[i][j] = 0;
            }
        }

        // jewel position
        FOR(i, 0, N){
            ll x, y;
            cin >> x >> y;
            field[y][x] = 1;
        }

        // move
        ll count = 0;
        ll M; cin >> M;
        FOR(i, 0, M){
            char c; cin >> c;
            ll len; cin >> len;

            FOR(j, 0, len){
                if(c=='N') p.y++;
                if(c=='S') p.y--;
                if(c=='E') p.x++;
                if(c=='W') p.x--;
                if(field[p.y][p.x]==1){
                    field[p.y][p.x] = 0;
                    count++;
                }
            }
        }
        if(count==N){
            p_yes();
        }else{
            p_no();
        }
    }

    return 0;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int,int>> p(m);
  for(int i=0;i<m;i++) cin >> p[i].first >> p[i].second;
  for(int x=0;x<1000;x++) {
    int keta = 1;
    int nx = x/10;
    vector<int> d(1,x%10);
    while (nx) {
      keta++;
      d.push_back(nx%10);
      nx /= 10;
    }
    if (keta != n) continue;
    bool ok = true;
    reverse(d.begin(), d.end());
    for(int i=0;i<m;i++) {
      if (d[p[i].first-1] != p[i].second) ok = false;
    }
    if (ok) {
      cout << x << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

using pv = pair<P,vector<int>>;
vector<int> graph[1005];

int main(){
    int n,m;
    cin >> n >> m;
    vector<P> edge(m);
    rep(i,m){
        cin >> edge[i].first >> edge[i].second;
        --edge[i].first;--edge[i].second;
        graph[edge[i].first].push_back(edge[i].second);
    }
    int id = -1;
    int mn = INF;
    vector<int> ans;
    rep(i,m){
        vector<bool> seen(n,false);
        queue<pv> q;
        q.push(pv(P(edge[i].second,0),{}));
        while(!q.empty()){
            int now = q.front().first.first;
            int c = q.front().first.second;
            vector<int> way = q.front().second;
            q.pop();
            if(now==edge[i].first){
                if(c < mn){
                    id = i;
                    mn = c;
                    way.push_back(now);
                    ans = way;
                    break;
                }else{
                    break;
                }
            }
            if(seen[now]) continue;
            seen[now] = true;
            way.push_back(now);
            for(int j:graph[now]){
                if(seen[j]) continue;
                q.push(pv(P(j,c+1),way));
            }
        }
    }
    if(mn==INF){
        cout << -1 << endl;
    }else{
        cout << (int)ans.size() << endl;
        rep(i,ans.size()) cout << ans[i]+1 << endl;
    }
    return 0;
}


#include "bits/stdc++.h"
#include "math.h"

using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;
ll roundd(ll x,ll n){
  if(x>n){return x%n;}
  else if(x<0){return x%n+n;}
  else return x;
}
bool isprime(ll n){
    if(n==1)return false;
    for (ll i = 2; i * i <= n; i++) {
        if(n%i==0)return false;
    }
    return true;
}
int main(){
  ll n;cin>>n;
  rep(i,2,55556){
    if(i%5==1&&isprime(i)){
      cout<<i<<" ";n--;
    }
    if(n==0)break;
  }
  cout<<endl;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef long double ld;
typedef vector<ll>VI;
typedef pair<ll,ll>P;
#define VV(T) vector<vector<T>>
#define sz(x) int(x.size())
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
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; }
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX6 1001001//6
#define MAX7 10010010//7
#define SENTINEL 2000000000//9
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
#define CLR(mat) memset(mat, 0, sizeof(mat))
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
template<class T> bool contain(const std::string& s, const T& v) {
   return s.find(v) != std::string::npos;
}
using Edge=pair<int,ll>;
using Graph=vector<vector<ll> >;//ll or Edge
const int MOD = 1000000007;
//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// vector型から重複を削除 list.erase(unique(ALL(list)),list.end());
// g++ -o a a.cpp -Wall -lm -std=c++17
//push_back -> emplace_back

vector<bool>a(55555,1);
int main(){
   int n;cin>>n;
   auto er=[&](){
      VI res;
      for(int i=2;i*i<=55555;i++){
         int j=i+i;
         while(j<55555){
            a[j]=0;
            j+=i;
         }
      }
      rep(i,55555)if(i>=2 && a[i]==1 && i%10==1)res.emplace_back(i);
      return res;
      };
      VI res=er();
      rep(i,n)cout<<res[i]<<' ';
      cout<<endl;

   }


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値

double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}

int main() {
ll n,p;
cin>>n>>p;
ll ca=0;
ll a[n+2]={};
ll b[n+2]={};
ll m=0;
ll f=0;
for(ll i=1; i<n+1; i++){
cin>>a[i];}
for(ll i=0; i<p; i++){

for(ll k=1; k<=n; k++){
if(k-a[k]<=0){
b[0]++;}
else{
b[k-a[k]]++;}
if(k+a[k]>=n){
b[n+1]--;}
else{
b[k+a[k]+1]--;}}
ca=b[0];
b[0]=0;
for(ll k=1; k<=n; k++){
ca+=b[k];
b[k]=0;
a[k]=ca;
if(a[k]==n){
m++;}
}
if(m==n) {f++; break;}
m=0;
ca=0;}
for(ll i=1; i<=n; i++){
cout << a[i] << " ";}
cout << endl;}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;

struct BIT {
  int n;
  vector<long long> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, long long x=1) {
    for (i++; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  long long sum(int i) {
    long long x = 0;
    for (i++; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
  long long sum(int l, int r) {
    return sum(r-1) - sum(l-1);
  }
};

int main(){
    int n,q;
    cin >> n >> q;
    vector<int> c(n);
    for(int i = 0; i < n; i++) cin >> c[i], c[i]--;

    vector<pair<pair<int,int>,int>> pq;
    for(int i = 0; i < q; i++){
        int l,r;
        cin >> l >> r;
        l--;r--;
        pq.push_back(make_pair(make_pair(l,r),i));
    }

    vector<int> memo(n,-1);
    vector<pair<int,int>> cp;
    for(int i = 0; i < n; i++){
        if(memo[c[i]] != -1) cp.push_back(make_pair(memo[c[i]],i));
        memo[c[i]] = i;
    }

    sort(pq.rbegin(),pq.rend());
    sort(cp.rbegin(),cp.rend());

    BIT tree(n);
    vector<int> ans(q,0);

    int ncp = 0;
    for(int i = 0; i < q; i++){
        while(true){
            if(ncp < (int)cp.size() && pq[i].first.first <= cp[ncp].first){
                tree.add(cp[ncp].second,1);
                ncp++;
            } else break;
        }
        ans[pq[i].second] = pq[i].first.second-pq[i].first.first+1-tree.sum(pq[i].first.second);
    }

    for(int i = 0; i < q; i++) cout << ans[i] << endl;

    return 0;
}


#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define MOD 998244353
#define INIT -1

int main()
{
   string n;
   cin >> n;
   // result[i][0] : i - 1桁めまで払ってる　繰り下がりはない
   // result[i][1] : i - 1桁目まで払ってる　繰り下がりあり
   int result[1000010][2] = {};
   result[0][0] = 0;
   result[0][1] = 1;
   for (int i = 1; i <= n.length(); i++)
   {
      result[i][0] = min(result[i - 1][0] + (n[i - 1] - '0'), result[i - 1][1] + (10 - (n[i - 1] - '0')));
      result[i][1] = min(result[i - 1][1] + (10 - (n[i - 1] - '0') - 1), result[i - 1][0] + (n[i - 1] - '0' + 1));
   }
   cout << result[n.length()][0] << endl;
}

#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <cmath>

using namespace std;

bool is_balanced(int s, int e, vector<int>& v) {
    int len = e - s + 1;
    for (auto i: v) {
        if (i > len / 2 && len >= 2) {
            return true;
        }
    }
    return false;
}

void print(vector<int> v) {
    cout << "{ ";
    for (auto i : v) {
        cout << i << ", ";
    }
    cout << " }" << endl;
}

int main() {
    string s;
    cin >> s;
    vector<int> v(26, 0);

    int i = 0, j = 0;
    int len = (int) s.size();
    int start, end;

    while (j < len) {
        v[s[j] - 'a']++;
        if (is_balanced(i, j, v)) {
            start = i + 1;
            end = j + 1;
            cout << start << " " << end << endl;
            return 0;
        } else {
            if (j > i + 1) {
                v[s[i] - 'a']--;
                i++;
            }
        }
        j++;
    }

    cout << -1 << " " << -1 << endl;

    return 0;
}


#include <string>
#include <math.h>
#include <iostream>

using namespace std;

int main()
{
  int a, b;
  cin >> a >> b;
  int aa = 0;
  int bb = 0;
  int cc = 0;
  int dd = 0;
  int ee = 0;
  int ff = 0;

  if (a == 1)
    ee = 300000;
  else if (a == 2)
    aa = 200000;
  else if (a == 3)
    bb = 100000;
   if (b == 1)
    ff = 300000;
   else if (b == 2)
    cc = 200000;
   else if (b == 3)
    dd = 100000;

  if (a == 1 && b == 1)
    cout << "1000000";
  else
    cout << aa + bb + cc + dd + ee + ff;
}

#include<iostream>
#include<cstdio>
#include<string>
#include<cstdlib>
#include<set>
#include<string.h>
#include<ctype.h>

using namespace std;

int arr[10];
int sub[10];
int n,k;
int now = 0;
int cont;
int c = 0;

set<int> visit2;

void saiki(int[],int);

int main()
{
	for(;;)
	{
		visit2.clear();
		int i;
		c = 0;
		now = 0;

		scanf("%d",&n);
		scanf("%d",&k);
		if(n == 0 && k == 0){
			break;
		}

		for(i = 0; i < n; i++){
			scanf("%d",&arr[i]);
		}
		for(i = 0; i < n; i++){
			sub[0] = arr[i];
	//		printf("\næªJ[hF%d\n",arr[i]);
			saiki(sub,1);
			now++;
		}
		cout <<visit2.size()-c << endl;
	}
}

void saiki(int temp[], int kk)
{
	//k:TõK
	int used[50] = {0};
	int i;
	int t = 0;
	char str[256] = "";

	for(i = 0; i < kk; i++){
		sprintf(str+strlen(str),"%d",temp[i]);
	}

	t = atoi(str);

	if(kk == k){

		visit2.insert(t);
		return;
	}
	else{
		int j;

//		cout << "*t = " << t << endl;

		for(i = 0; i < kk; i++){
			for(j = 0; j < n; ++j ){
				if( used[j] == 0 && arr[j] == temp[i] ){
//					printf("J[h%dÍgpÏÝ\n",arr[j]);
					used[j] = 1;
					break;
				}
			}
		}

		for(i = 0; i < n; i++){
			if(used[i] == 0){
				temp[kk] = arr[i];
				used[i] = 1;
				saiki(temp, kk+1);
				used[i] = 0;
			}
		}
	}
}


#include<bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define M 1000000007
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define f first
#define s second
#define b begin
#define e end
#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for(i=a;i<b;i++)
#define RFOR(i,a,b) for(i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define itfr(it,x) for(it=x.begin();it!=x.end();it++)
#define flash ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;

int main()
{
    flash;
    //sieve();
    int T=1,t,n,m,k,i;
    // cin>>T;
    while(T--)
    {
        cin>>n>>k;
        int a[10]={0};
        FOR(i,0,k){
          cin>>t;
          a[t]=1;
        }
        vector<int> vs;
        FOR(i,0,10)
            if(a[i]==0)
                vs.pb(i);
        // for(auto it:vs)cout<<it<<" ";cout<<endl;
        int dg=0;
        for(i=n;i>0;i/=10)dg++;
        ll ans=0;
        k = pow(10,dg-1);
        int fl=0;
        int num=n;
        // cout<<dg<<" "<<k<<endl;
        while(ans<num)
        {
            if(k==0){
                ans = ans*10 + vs[0];
                continue;
            }
            m = n/k;
            n = n%k;
            k/=10;
            if(a[m]==0&fl==0){
                ans = ans*10 + m;
                continue;
            }
            dg=0;
            if(fl==0)
            {
                for(auto it:vs)
                    if(it>=m)
                    {
                        dg=it;
                        break;
                    }
                if(dg==0)
                {
                    if(vs[0]!=0)
                        dg=vs[0];
                    else
                    {
                        if(ans==0)
                            dg=vs[1];
                        else
                            dg=vs[0];
                    }
                }
                ans = ans*10+dg;
                fl=1;
            }
            else
            {
                ans = ans*10 + vs[0];
            }
        }
        cout<<ans<<endl;
    }
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tii;
#define rep(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

int main(){
  ll A,B; cin >> A >> B;
  if(A<B) swap(A,B);
  ll y = gcd(A,B);
  ll yy = y;
  ll x = 2;
  ll ans = 1;
  while(x*x<=y&&yy!=1){
    if(yy%x==0){
      ans++;
      while(yy%x==0) yy /= x;
    }
    x++;
  }
  if(yy!=1) ans++;
  cout << ans << endl;
}


// God put a smile upon your face <3

#include <bits/stdc++.h>

#define slld(longvalue) scanf("%lld", &longvalue)

#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >

#define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define pb push_back

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

using namespace std;

bool check(ll n, ll pos)
{
	return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
	return n = n | (1LL << pos);
}

int main()
{
    ll i, j, k, l, m, n, o, r, q;
    ll testcase;
    ll input, flag, tag, ans;

//    freopen("input.txt", "r", stdin);

//    freopen("output.txt", "w", stdout);

    double rad;

    while(cin >> rad)
    {
		cout << setprecision(10) << fixed << 2.0 * acos(-1.0) * rad << "\n";
    }

}

#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; ++i) // マクロ
using namespace std; // stdの省略
using pii = pair<int, int>; // pairの略記
using ll = long long; // long longの略記

int main(void) {

   int r;
   cin >> r;

   cout << 2*r*M_PI << endl;

   return 0;
}


#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <math.h>
#include <tuple>
#include <string.h>
#include <map>
#include <iomanip>
#include <time.h>
using namespace std;
typedef long long ll;

int n, m, id[100010];
bool vis[100010];
vector<int> G[100010], R[100010], po;

void dfs(int v) {
    if (vis[v]) return;
    vis[v] = 1;
    for (auto& i : G[v]) dfs(i);
    po.push_back(v);
}

void rev_dfs(int v, int num) {
    if (vis[v]) return;
    vis[v] = true;
    id[v] = num;
    for (auto& i : R[v]) rev_dfs(i, num);
}

int main() {
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        R[b].push_back(a);
    }

    for (int i = 0; i < n; i++) dfs(i);
    for (int i = 0; i < n; i++) vis[i] = 0;

    int num = 0;
    reverse(po.begin(), po.end());
    for (int i = 0; i < n; i++) {
        int v = po[i];
        if (!vis[v]) {
            rev_dfs(v, num);
            num++;
        }
    }

    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int x, y;
        cin >> x >> y;
        cout << (id[x] == id[y]) << endl;
    }

}

#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define LOOP(i) while(i--)
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

class ConnectNodeInfo{
	vector<vector<pair<ll,ll>>> graph;
public:
	ConnectNodeInfo(int node_num){
		graph.resize(node_num);
	}
	void AddNonDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
		graph[v].emplace_back(u,w);
	}
	void AddDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
	}
	vector<pair<ll,ll>>& operator[](ll index){
		return graph[index];
	}
	size_t size(){return graph.size();}
};

class UnionFind{
	vector<ll> rank;
	vector<ll> diff_weight;
	vector<ll> num;
public:
	vector<ll> par;

	UnionFind(ll N):par(N),num(N),rank(N),diff_weight(N){
		for(ll i=0;i<N;i++){
			par[i]=i;
			num[i]=1;
			rank[i]=0;
			diff_weight[i]=0;
		}
	}

	ll root(ll x){
		if(par[x]==x){
			return x;
		}
		ll r = root(par[x]);
		diff_weight[x]+=diff_weight[par[x]];
		return par[x]=r;
	}

	void unite(ll x,ll y){
		ll rx = root(x);
		ll ry = root(y);
		if (rx == ry) return;
		if(rank[rx]<rank[ry]) swap(rx,ry);
		if(rank[rx]==rank[ry]) ++rank[rx];
		par[ry] = rx;
		num[rx] += num[ry];
	}

	void relate(ll x,ll y,ll w){
		w+=weight(x),w-=weight(y);
		ll rx = root(x);
		ll ry = root(y);
		if (rx == ry) return;
		if(rank[rx]<rank[ry]){
			swap(rx,ry);
			w = -w;
		}
		if(rank[rx]==rank[ry]) ++rank[rx];
		par[ry] = rx;
		diff_weight[ry] = w;
		num[rx] += num[ry];
	}

	bool same(ll x,ll y){
		ll rx = root(x);
		ll ry = root(y);
		return rx == ry;
	}

	ll getsize(ll x){
		return num[root(x)];
	}

	ll weight(ll x){
		root(x);
		return diff_weight[x];
	}

	ll diff(ll x,ll y){
		return weight(y)-weight(x);
	}
};

void FirstDFS(int child,int& post_count,vector<int>& post,ConnectNodeInfo& connect,vector<int>& memo){
	memo[child] = 1;
	for(auto& x:connect[child]){
		if(!memo[x.first]){
			FirstDFS(x.first,post_count,post,connect,memo);
		}
	}
	post[child] = post_count++;
}

void SecondDFS(int start,int child,ConnectNodeInfo& connect,UnionFind& uf,vector<int>& memo){
	uf.unite(start,child);
	memo[child] = 1;
	for(auto& x:connect[child]){
		if(!memo[x.first]){
			SecondDFS(start,x.first,connect,uf,memo);
		}
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	int N=in(),M=in();
	ConnectNodeInfo connect(N),inverse_connect(N);
	REP(i,M){
		int u=in(),v=in();
		connect.AddDirectionalConnection(u,v,1);
		inverse_connect.AddDirectionalConnection(v,u,1);
	}

	int post_count=0;
	vector<int> post(N,-1);
	vector<int> memo(N,0);
	REP(i,N){
		if(!memo[i]) FirstDFS(i,post_count,post,connect,memo);
	}
	vector<pair<int,int>> new_order(N);
	REP(i,N){
		new_order[i].first=i;
		new_order[i].second=post[i];
	}
	sort(ALL(new_order),PAIRCOMP(second,>));
	UnionFind uf(N);

	fill(ALL(memo),0);
	REP(i,N){
		if(!memo[new_order[i].first]) SecondDFS(new_order[i].first,new_order[i].first,inverse_connect,uf,memo);
	}

	int Q=in();
	LOOP(Q){
		int u=in(),v=in();
		out(uf.same(u,v)?1:0);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define lor(a,b,c) for(register int a=b;a<=c;++a)
#define ror(a,b,c) for(register int a=c;a>=b;--a)
typedef long long ll;

const int MAXN=505,MAXD=7919;
const int movx[4]={-1,0,1,0},movy[4]={0,1,0,-1};

int n; ll a[MAXN][MAXN];
bool vis[MAXD]; ll prime[MAXN<<1];

inline ll gcd(ll a,ll b){
	return b?gcd(b,a%b):a;
}

inline ll lcm(ll a,ll b){
	if(!a||!b) return a|b;
	return a/gcd(a,b)*b;
}

inline void judge(){
	int x,a[505][505];
	scanf("%d",&x); lor(i,1,x) lor(j,1,x) scanf("%d",&a[i][j]);

}

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

	if(n==2) return printf("4 7\n23 10\n"),0;

	lor(i,2,MAXD){
		if(!vis[i]) prime[++prime[0]]=i;
		for(register int j=1;j<=prime[0]&&i*prime[j]<=MAXD;++j) vis[i*prime[j]]=true;
	}

	lor(i,1,n) lor(j,1,n) if(!((i+j)&1)){
		a[i][j]=prime[(i+j)>>1]*prime[n+(n+1)/2+(i-j)/2];
	}
	lor(i,1,n) lor(j,1,n) if((i+j)&1){
		a[i][j]=lcm(lcm(a[i-1][j],a[i][j-1]),lcm(a[i+1][j],a[i][j+1]))+1;
	}
	lor(i,1,n){
		lor(j,1,n) printf("%lld ",a[i][j]); printf("\n");
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct Node {
    int k;
    Node *p, *l, *r;
};

Node *NIL, *root;

void insert(int key) {
    Node *parent = NIL;
    Node *node = root;
    Node *target = (Node *)malloc(sizeof(Node));
    target->k = key;
    target->l = NIL;
    target->r = NIL;

    while(node != NIL) {
        parent = node;
        if(target->k < node->k) {
            node = node->l;
        } else {
            node = node->r;
        }
    }
    target->p = parent;
    if(parent == NIL) {
        root = target;
    } else {
        if(target->k < parent->k) {
            parent->l = target;
        } else {
            parent->r = target;
        }
    }
}

Node *findNode(int key) {
    Node *node = root;
    while(node != NIL) {
        if(key < node->k) {
            node = node->l;
        } else if(key > node->k) {
            node = node->r;
        } else {
            return node;
        }
    }
    return NIL;
}

Node *getSuccessor(Node *target) {
    if(target->r != NIL) {
        target = target->r;
        while(target->l != NIL) {
            target = target->l;
        }
        return target;
    }

    Node *parent = target->p;
    while(parent != NIL && target == parent->r) {
        target = parent;
        parent = parent->p;
    }
    return parent;
}

void deleteNode(int key) {
    Node *target = findNode(key);
    // error handling
    if(target == NIL)
        return;
    Node *deleteNode;
    Node *deleteNodeChild;
    Node *deleteNodeParent;
    // select node to delete.
    if(target->l == NIL || target->r == NIL) {
        deleteNode = target;
    } else {
        deleteNode = getSuccessor(target);
    }
    // select child node of node to delete.
    if(deleteNode->l != NIL) {
        deleteNodeChild = deleteNode->l;
    } else {
        deleteNodeChild = deleteNode->r;
    }

    // if node to delete has the children nodes.
    if(deleteNodeChild != NIL) {
        deleteNodeChild->p = deleteNode->p;
    }

    // if node to delete is root of tree.
    if(deleteNode->p == NIL) {
        root = deleteNodeChild;
        // confirm which is node to delete.
    } else if(deleteNode == deleteNode->p->l) {
        deleteNode->p->l = deleteNodeChild;
    } else {
        deleteNode->p->r = deleteNodeChild;
    }

    if(target != deleteNode) {
        target->k = deleteNode->k;
    }
}

void inorder(Node *node) {
    if(node == NIL)
        return;
    inorder(node->l);
    printf(" %d", node->k);
    inorder(node->r);
}

void preorder(Node *node) {
    printf(" %d", node->k);
    if(node->l != NIL) {
        preorder(node->l);
    }
    if(node->r != NIL) {
        preorder(node->r);
    }
}

bool find(int key) {
    Node *node = root;
    while(node != NIL) {
        if(key < node->k) {
            node = node->l;
        } else if(key > node->k) {
            node = node->r;
        } else {
            return true;
        }
    }
    return false;
}

int main() {
    int n, key;
    string com;
    NIL = (Node *)malloc(sizeof(Node));
    root = (Node *)malloc(sizeof(Node));
    root = NIL;
    root->p = NIL;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> com;
        if(com == "print") {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        } else {
            scanf("%d", &key);
            if(com == "find") {
                if(find(key)) {
                    printf("yes\n");
                } else {
                    printf("no\n");
                }
            } else if(com == "insert") {
                insert(key);
            } else if(com == "delete") {
                deleteNode(key);
            }
        }
    }
}

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int n;
int t[12][12];

int main(void){
	while(cin>>n,n){
		memset(t,0,sizeof(t));
		for(int i=0;i<=n;i++){
			for(int j=0;j<n;j++){
				if(i != n){
					cin>>t[i][j];
					t[n][j] += t[i][j];
				}
				t[i][n] += t[i][j];
			}
		}

		for(int i=0;i<=n;i++){
			for(int j=0;j<=n;j++){
				printf("%5d",t[i][j]);
			}
			cout<<endl;
		}
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long int

int main()
{
    ll t;
    t = 1;
    //cin t;
    while (t--)
    {
        ll n, m;
        cin >> n >> m;
        int i = 1;
        int j = n;
        if (n % 2 != 0)
        {
            while (m--)
                cout << i++ << " " << j-- << endl;
        }
        else
        {
            int count[n + 1] = {0};
            int current = 1;
            int x = n / 2;
            int s = 1;
            int s1 = x + 1;
            for (int i = x - 1; i >= 1; i--)
            {
                if (m == 0)
                    break;
                if (i % 2 == 0)
                {
                    cout << s << " " << s + i << endl;
                    s++;
                }
                else
                {
                    cout << s1 << " " << s1 + i << endl;
                    s1++;
                }

                m--;
            }
            // cout << i << " " << --j << endl;
        }
    }
}

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll= long long;
using ld= long double;
using vl= vector<ll>;
using vd= vector<ld>;
using vs= vector<string>;
using vb= vector<bool>;
using vvl= vector<vector<ll>>;
using vvd= vector<vector<ld>>;
using vvs= vector<vector<string>>;
using vvb= vector<vector<bool>>;
using pll= pair<ll, ll>;
constexpr ll mod= 1e9 + 7;
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for(ll(i)= 0; (i) < (n); (i)++)
#define REPS(i, n) for(ll(i)= 1; (i) <= (n); (i)++)
#define RREP(i, n) for(ll(i)= (n - 1); (i) >= 0; (i)--)
#define RREPS(i, n) for(ll(i)= (n); (i) > 0; (i)--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())
#define YES(n) ((n) ? "YES" : "NO")
#define Yes(n) ((n) ? "Yes" : "No")
#define yes(n) ((n) ? "yes" : "no")

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

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

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    ll N,Q;
    cin >> N >> Q;
    fenwick_tree<ll> fw(N);
    REP(i,N){
        ll x;
        cin >> x;
        fw.add(i,x);
    }
    REP(i,Q){
        ll b;
        cin >> b;
        if(b == 0){
            ll p,t;
            cin >> p >> t;
            fw.add(p,t);
        }else{
            ll l,r;
            cin >> l >> r;
            cout << fw.sum(l,r) << "\n";
        }
    }
}


        #include<bits/stdc++.h>
        using namespace std;
        int main(){
          int n;
          cin>>n;
          int k;
          cin>>k;
          bool arr[k];
         // memset(arr,false,sizeof(arr));
          int temp;
          for(int i=0;i<10;i++)
            arr[i] = false;
          for(int i=0;i<k;i++){
            cin>>temp;
            arr[temp] = true;
          }

          while(true){
            bool flag=true;
            int l = n;

            while(l!=0){
              int rem = l%10;
              if(arr[rem]==true){
                flag = false;
                break;
              }
              l = l/10;
            }
            if(flag == true){
              cout<<n;
              break;
            }
            n++;
          }
        }

#include <iostream>
#include <cstdio>
#include <string>
#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 <ctime>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int const MOD = 1000000007;

int main() {
    int l[11]; l[0] = 0;
    int v1, v2;
    while(cin >> l[1]) {
        int sum = l[1];
        rep(i,2,11) {scanf(",%d", &l[i]); sum += l[i]; l[i] += l[i-1];}
        scanf(",%d,%d", &v1, &v2);

        double r = (double)sum / (v1 + v2);
        double dist = r * v1;
        rep(i,0,11) {
            if(dist <= l[i]) {cout << i << endl; break;}
        }
    }
    return 0;
}


#include <iostream>
#include <cmath>
using namespace std;

struct Point
{
    double x, y;
    Point(double x=0, double y=0) : x(x), y(y) {}

	double distance (const Point &o) const
	{
        return sqrt((x - o.x) * (x - o.x) + (y - o.y) * (y - o.y));
    }

    Point operator+(const Point &o) const
	{
        return Point(x+o.x, y+o.y);
    }

    Point operator-(const Point &o) const
	{
        return Point(x-o.x, y-o.y);
    }

    Point operator*(const double m) const
	{
        return Point(x*m, y*m);
    }

    Point operator/(const double d) const
	{
        return Point(x/d, y/d);
    }

    double cross(const Point &o) const
	{
        return x * o.y - y * o.x;
    }

    double dot(const Point &o) const
	{
        return x * o.x + y * o.y;
    }

    double atan() const
	{
        return atan2(y, x);
    }

    double norm() const
	{
        return dot(*this);
    }

	double area(const Point &a,const Point &b) const
	{
		double t = (a.x - x) * (b.y - y);
		double t2 = (a.y - y) * (b.x - x);
		double areas = abs(t-t2);
		return  areas/2;
	}
};

int main()
{
	Point p1,p2;
	cin >> p1.x >> p1.y >> p2.x >> p2.y;
	cout << fixed;
	cout.precision(6);
	cout << p1.distance(p2) << endl;

	return 0;
}

#include<iostream>
#include<iomanip>
#include<cmath>

using namespace std;

int main(){

	double x1, x2, y1, y2;

	cin >> x1 >> y1 >> x2 >> y2;

	if (x1 == x2){
		cout << setprecision(12) << fabs(y1 - y2) << endl;
	}
	else if (y1 == y2){
		cout << setprecision(12) << fabs(x1 - x2) << endl;
	}
	else {
		cout << setprecision(12) << sqrt(pow(fabs(x1 - x2), 2) + pow(fabs(y1 - y2), 2)) << endl;
	}

	return 0;
}


#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;

int main()
{
  ll N; cin>>N;
  string S; cin>>S;
  ll hitomi=0;
  ll max_hitomi=0;
  rep(i,N)
  {
    if(i==0) {continue;}
    if(S.at(i)=='W') {hitomi++;}
  }
  rep(i,N)
  {
    if(i==0) {max_hitomi=hitomi; /*cout<<hitomi<<" "<<max_hitomi<<endl;*/ continue;}
    if(S.at(i-1)=='E') {hitomi++;}
    if(S.at(i)=='W') {hitomi--;}
    max_hitomi=max(max_hitomi,hitomi);
    //cout<<hitomi<<" "<<max_hitomi<<endl;
  }
  cout<<N-1-max_hitomi<<endl;
  return 0;
}

#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

int main() {
	string S;
	int w;
	cin >> S >> w;

	for (int i = 0; i < S.size(); i+=w) {
		cout << S.at(i);
	}
	cout << endl;
}


#include <iostream>
#include <string.h>
using namespace std;

int main() {

    int N;
    int cnt = 0;

    cin >> N;

    int a[N];
    int a_next[N];

    for (int i = 0; i < N; i++) {
        int tmp;
        cin >> tmp;
        a[i] = tmp;
    }

    do {
        int flg = 0;
        for (int i = 0; i < N; i++) {
            if (a[i] % 2 == 0){
                a_next[i] = a[i] / 2;
            }
            else{
                flg = 1;
                break;
            }
        }

        if (flg == 0){
            cnt = cnt + 1;
            for (int j = 0; j < N; j++) {
                a[j] = a_next[j] ;
            }
        }
        else{
            cout << cnt << endl;
            return 0;
        }

    } while (true);

    return 0;

}

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

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

  int dmin = 100;
  for (int i = 0; i < N; i++) {
    int A, d = 0;
    cin >> A;

    while (A % 2 == 0) {
      A /= 2;
      d++;
    }

    dmin = min(dmin, d);
  }

  cout << dmin << endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll a,b,c;
    cin>>a>>b>>c;
    if(c>min(a,b) && c<max(a,b))
    {
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
   return 0;

}

#include<iostream>
using namespace std;

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  cout << ((a-c)*(b-c)<0?"Yes":"No") << endl;
}


#include<iostream>
#include <climits>
#include<vector>
#include<numeric>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;

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

	int N;
	cin >> N;
	vector<int> A(N);
	REP(i, N) cin >> A[i];
	bool flag = true;
	int res = 0;
	while (flag) {
		flag = false;
		for (int i = N - 1;i > 0;i--) {
			if(A[i-1]>A[i]){
				int tmp = A[i];
				A[i] = A[i - 1];
				A[i - 1] = tmp;
				flag = true;
				res++;
			}
		}
	}
	REP(i, N) {
		if (i < N - 1)cout << A[i] << " ";
		else cout << A[i] << "\n";
	}
	cout << res << "\n";

	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    for (auto &x: a) cin >> x;
    for (auto &x: b) cin >> x;
    for (auto &x: c) cin >> x;
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    vector<long long> l(n);
    int j = 0;
    for (int i = 0; i < n; i++) {
        while (j < n && c[j] <= b[i]) j++;
        l[i] = n - j;
    }
    for (int i = n - 1; i > 0; i--) l[i-1] += l[i];
    long long ans = 0;
    j = 0;
    for (int i = 0; i < n; i++) {
        while (j < n && b[j] <= a[i]) j++;
        if (j == n) break;
        ans += l[j];
    }
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>

int main(){
    using namespace std;
    constexpr unsigned long MOD = 1000000007;
    vector<unsigned long> tapi(1048576, 1), tapu(1048576), tape(1048576);
    unsigned long ans{0}, t{500000004}, a{0}, z{0}, A;cin >> A;
    while(cin >> A)if(a ^= A){
        (tapu[a] += (tapi[a] += tapu[a] * (z - tape[a])) %= MOD) %= MOD;
        ans += tapi[a];
        tape[a] = z;
    }else ++z, (t *= 2) %= MOD;
    cout << (a ? tapi[a] : (ans + t) % MOD) << endl;
    return 0;
}

#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996)

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;

ll dp[41][1<<16][2];

int main(int argc, char* argv[])
{
    int n,x,y,z;
    scanf("%d%d%d%d", &n, &x, &y, &z);

    int s=(1<<(x+y+z))+(1<<(y+z))+(1<<z);
    int s2=s/2;

    dp[0][0][0]=1;
    int i,j,p,k;
    for(i=0; i<n; i++) {
        for(j=0; j<(1<<16); j++) {
            for(p=0; p<2; p++) {
                if(dp[i][j][p]) {
                    for(k=1; k<=10; k++) {
                        ll tmp=((ll)((j<<1)+1)<<(k-1));
                        int flag=p;
                        if(flag==0 && (tmp&s2)==s2) {
                            flag=1;
                        }
                        int j2=tmp%(1<<16);
                        dp[i+1][j2][flag]=(dp[i+1][j2][flag]+dp[i][j][p])%MOD;
                    }
                }
            }
        }
    }
    ll ans=0;
    for(j=0; j<(1<<16); j++) {
        ans=(ans+dp[n][j][1])%MOD;
    }
    printf("%lld\n", ans);

    return 0;
}


#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  string S;
  cin>>S;
  int ans=0,sc=0;
  for(auto c:S){
    if(c=='S'){
      sc++;
      ans++;
    }else{
      if(sc>0){
        ans--;
        sc--;
      }else{
        ans++;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

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

    string s;
    cin>>s;

    string ans;
    for (char c: s)
        if (c == 'S')   ans += c;
        else if (ans.size() && ans.back() =='S')    ans.pop_back();
        else ans += c;
    cout<<ans.size()<<endl;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  int N; cin >> N; cout << 180 * (N-2) << endl;
}

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <numeric>
#include <math.h>

using namespace std;

void func()
{
	int64_t N, ai = 0;;
	cin >> N;
	for (int64_t i = 1; i <= N; ++i)
	{
		if (i % 3 == 0 || i % 5 == 0)
			continue;
		ai += i;
	}
	cout << ai << endl;
}

int main() {

//	while (1)
		func();
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

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

int main()
{
    int n = 0, i = 0, output = 0;
    cin >> n;
    vector<int> skewer(2 * n, 0);

    for(i = 0;i < 2*n; i++)
    {
        int temp = 0;
        cin >> temp;
        skewer.push_back(temp);
    }
    sort(skewer.begin(), skewer.end());
    i = 0;
    while(i < skewer.size())
    {
        output = output + skewer[i];
        i = i + 2;
    }
    cout << output;
	return 0;
}

#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
using graph = vector<vector<int>>;
using P = pair<int,int>;
ll MAX(ll a,ll b,ll c){return max(a,max(b,c));}
ll MIN(ll a,ll b,ll c){return min(a,min(b,c));}
const ll mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    int n;
    cin >> n;
    n *= 2;
    int num[n];
    rep(i,n){
        cin >> num[i];
    }
    sort(num,num+n);
    reverse(num,num+n);
    ll ans = 0;
    rep(i,n){
        if(i % 2 == 1) ans += num[i];
    }
    cout << ans << endl;
}


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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()

// output
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
  cout << a;
  ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
  cout << a << ' ';
  pr(b);
}

int ans = 0;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

int main()
{

  vector<int> v(5);
  rep(i, 5) cin >> v[i];
  int k;
  cin >> k;
  sort(v.begin(), v.end());
  if (v[4] - v[0] <= k)
    pr("Yay!");
  else
    pr(":(");
  return 0;
}

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace  std;

int main() {
	vector<vector<string>> data(3);
	string stra,strb,strc;
	string next = "a";
	cin >> stra;

	cin >> strb;

	cin >> strc;
	int a = 0, b = 0, c = 0;
	while (true) {
		if (next == "a") {
			if (a < stra.size()) {
				next = stra[a];
				a++;
			}
			else {
				cout << "A" << endl;
				break;
			}
		}
		else if (next == "b") {
			if (b < strb.size()) {
				next = strb[b];
				b++;
			}
			else {
				cout << "B" << endl;
				break;
			}

		}
		else {
			if (c< strc.size()) {
				next = strc[c];
				c++;
			}
			else {
				cout << "C" << endl;
				break;
			}

		}
	}

	return 0;

}


#include <vector>
#include <functional>
#include <iostream>
using namespace std;

int main() {
    int n, m; cin >> n >> m;
    vector<vector<int> > adj(n);
    while (m--) {
        int u, v; cin >> u >> v;
        u--; v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    long long a = 0, b = 0, c = 0;
    int col[n];
    bool visited[n];
    fill(visited, visited+n, false);
    function <bool(int, int)> dfs = [&](int i, int c) {
        col[i] = c;
        visited[i] = true;
        bool ret = true;
        for (int j : adj[i]) {
            if (!visited[j]) { if (!dfs(j, -c)) ret = false; }
            else if (col[j] == c) ret = false;
        }
        return ret;
    };
    for (int i = 0; i < n; i++) {
        if (adj[i].empty()) a++;
        else if (visited[i]) continue;
        else if (dfs(i, 1)) b++;
        else c++;
    }
    cout << 2 * a * n - a * a + b * b + (b + c) * (b + c) << endl;
}

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<59;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

#define N 5010
ll dp[N];

int main(){
	ll n;
	cin>>n;
	vector<ll> h(n), p(n);
	rep(i, n) cin>>h[i]>>p[i];
	vector<P> a(n);
	rep(i, n) a[i] = P(h[i]+p[i], i);
	sort(all(a));
	fill(dp+1, dp+n+1, INF);
	rep(i, n) for(int j = i; j >= 0; j--){
		ll x = h[a[i].snd], y = p[a[i].snd];
		if(dp[j]<=x) dp[j+1] = min(dp[j+1], dp[j]+y);
	}
	ll res = 0;
	rep(i, n+1) if(dp[i]<INF) res = i;
	cout<<res<<endl;
	return 0;
}


#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <map>
#include <set>
#include <stack>
#include <queue>

using namespace std;

#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()

#define REP(i,s,e)	for(int i=(s); i<(e); i++)
#define rep(i,n)	REP(i,0,n)
#define REPE(i,s,e)	for(int i=s; i>e; i--)
#define repe(i,n)	REPE(i,n,-1)

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

typedef vector<vi> vvi;

const int IMAX=((1<<30)-1)*2+1;
const int INF=100000000;
const double EPS=1e-10;
//int mod=1000000007

int main(){
	int n;
	while(cin >> n && n>0){
		int a,b,sa=0,sb=0;
		rep(i,n){
			cin>>a>>b;
			if(a>b) sa+=(a+b);
			else if(a==b) sa+=a,sb+=b;
			else sb+=(a+b);
		}
		cout<<sa<<" "<<sb<<endl;
	}
}

#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

int sb[10][10000];

#define MAX (50000000)

int main(){
  int n,k;
  while(scanf("%d%d",&n,&k), n+k){
    int dist[n][n];
    REP(i,n) REP(j,n) dist[i][j] = MAX;
    REP(i,n) dist[i][i] = 0;
    while(k --> 0){
      int s; scanf("%d",&s);
      if(s == 0){
        int a,b;
        scanf("%d%d",&a,&b); a--; b--;
        if(dist[a][b] == MAX) puts("-1");
        else printf("%d\n",dist[a][b]);
      }else{
        int a,b,c;
        scanf("%d%d%d",&a,&b,&c); a--; b--;
        if(dist[a][b] < c) continue;
        dist[a][b] = dist[b][a] = c;
        REP(i,n){
          dist[a][i] = dist[i][a] = min(dist[a][i], dist[a][b] + dist[b][i]);
          dist[b][i] = dist[i][b] = min(dist[b][i], dist[b][a] + dist[a][i]);
        }
        REP(i,n) REP(j,n){
          dist[i][j] = min(dist[i][j], dist[i][a] + dist[a][j]);
          dist[i][j] = min(dist[i][j], dist[i][b] + dist[b][j]);
        }
      }
    }
  }
  return 0;
}


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

int main() {
  int d, t, s;
  string result;
  cin >> d >> t >> s;

  if(d <= t*s){
    result = "Yes";
  }else{
    result = "No";
  }

  cout << result << endl;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
void add_self(int& a, int b) {
    a += b;
    if(a >= mod) {
        a -= mod;
    }
}

int main(){
	float d,t,s;
    cin>>d>>t>>s;
    if ((d/s)>t){
        cout<<"No";
    }

    else{
        cout<<"Yes";
    }
    }


#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007

int bs(ll k,vector<ll> & v){
  int l = -1,r = v.size();
  while(r-l > 1){
    int mid = (l+r)/2;
    if(v[mid] < k)l = mid;
    else r = mid;
  }
  return r;
}

int main(){

  ll n;
  cin >> n;
  vector<vector<ll>> v(30);
  vector<P> w(n);
  rep(i,n){
    string s;cin >> s;
    ll a = 0,b = 0,digit = 0;
    rep(k,s.size()){
      if(s[k] == '.'){
        for(ll j = k+1;j < s.size();j++)b = b*10+s[j]-'0',digit++;
        break;
      }
      a = a*10+s[k]-'0';
    }
    a *= 1000000000ll;
    rep(g,9-digit)b *= 10ll;
    a += b;
    ll two = 0,five = 0;
    while(!(a & 1))two++,a >>= 1;
    while(!(a % 5))five++,a /= 5;
    w[i] = make_pair(five,two);
    v[five].push_back(two);
  }
  rep(i,30)sort(ALL(v[i]));
  ll res = 0;
  rep(i,n){
    ll k = max(0,18-w[i].first);
    for(ll j = k;j < 30;j++){
      ll pos = max(0,bs(18-w[i].second,v[j]));
      ll l = v[j].size();
      res += l - pos;
    }
    if(w[i].first >= 9 && w[i].second >= 9)res--;
  }
  res >>= 1;
  cout << res << "\n";

  return 0;
}

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

int main() {
    cin.tie(0)->sync_with_stdio(false);

	int n; cin >> n;

	vector<vector<int> > ten(20, vector<int>(20, 0));
	ll cnt = 0;
	REP(i, n) {
		double x; cin >> x;
		ll tmp = x * 1e9 + 0.1;
		int two = 0;
		int five = 0;
		while (!(tmp % 2)) {
			tmp /= 2;
			two++;
		}
		while (!(tmp % 5)) {
			tmp /= 5;
			five++;
		}
		if (two > 18) two = 18;
		if (five > 18) five = 18;
		for (int j = 18 - two; j <= 18; j++)
			for (int k = 18 - five; k <= 18; k++)
				cnt += ten[j][k];
		ten[two][five]++;
	}

	cout << cnt << '\n';
    return 0;
}


#include <iostream>
#include <string>
using namespace std;

class Dice{
public:
	int l1,l2,l3,l4,l5,l6;

	void East(){
		int t = l1;
		l1 = l4;
		l4 = l6;
		l6 = l3;
		l3 = t;
	}
	void West(){
		int t = l1;
		l1 = l3;
		l3 = l6;
		l6 = l4;
		l4 = t;
	}
	void South(){
		int t=l1;
		l1 = l5;
		l5 = l6;
		l6 = l2;
		l2 = t;
	}
	void North(){
		int t=l1;
		l1 = l2;
		l2 = l6;
		l6 = l5;
		l5 = t;
	}
};

int main() {

	Dice dice;
	int l1,l2,l3,l4,l5,l6;
	char d;

	cin>>l1>>l2>>l3>>l4>>l5>>l6;
	dice.l1 = l1;
	dice.l2 = l2;
	dice.l3 = l3;
	dice.l4 = l4;
	dice.l5 = l5;
	dice.l6 = l6;

	while(cin>>d){
		if(d=='E')dice.East();
		else if(d=='W')dice.West();
		else if(d=='S')dice.South();
		else dice.North();
	}

	cout<<dice.l1<<endl;
}

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

int main() {
string S;
int w;
cin>>S>>w;

int i=0;
while(i<S.size()){
  cout<<S[i];
  i+=w;
}
cout<<endl;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N;
	cin >> N;
	vector<int> a(N);
	bool ok=true;
	int ans=1e9;
	//O(N * LOG(MAX(a)))
	for(int& x : a) {
		cin >> x;
		if(x&1) ok=false;
		int cnt=0;
		while(x) {
			if(x&1) {
				ans=min(ans,cnt);
				break;
			}
			cnt++;
			x/=2;
		}
	}
	if(!ok) {
		puts("0");return 0;
	}else {
		cout << ans;
	}
	return 0;
}

#include<iostream>
#include<vector>
using namespace std;
int num_2(int a) {
	int ret=0;
	while (a % 2 == 0) {
		ret++;
		a /= 2;
	}
	return ret;
}
int even(vector<vector<int>> a) {
	int ret = a.at(1).at(0);
	for (int i = 0; i < a.at(0).size(); i++) {
			if (ret > a.at(1).at(i))ret = a.at(1).at(i);
	}
	return ret;
}
int main() {
	int n;
	cin >> n;
	vector<vector<int>> a(2,vector<int> (n));
	for (int i = 0; i < n; i++) {
		cin >> a.at(0).at(i);
	}
	for (int i = 0; i < n; i++) {
		a.at(1).at(i) = num_2(a.at(0).at(i));
	}
	cout << even(a) << endl;

}


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

//Made with <3 by MinumCoklatPanas
typedef long long ll;
const int INF = 1e9;
const ll INFF = 1e18;
const int MAXN = 510;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double INFD = 1E9;
const double EPS = 1e-9;

vector< pair<int,int> > adj[100010];
ll sum[100010];

void dfs(int u,ll curSum,int prv)
{
    sum[u] = curSum;
    for (auto it : adj[u]) if (it.first != prv)
    {
        dfs(it.first,curSum + it.second,u);
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    for (int i = 1 ; i < n ; i++)
    {
        int a,b,c;
        cin >> a >> b >> c;
        adj[a].push_back({b,c});
        adj[b].push_back({a,c});
    }
    int q,k;
    cin >> q >> k;
    dfs(k,0,-1);
    while (q--)
    {
        int u,v;
        cin >> u >> v;
        ll ans = sum[u] + sum[v];
        cout << ans << endl;
    }
    return 0;
}

#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}

int n;
void dijkstra(vector<vector<pair<ll,ll>>>& graph,vector<long long> &distance,int start){
    priority_queue<pair<ll,ll>> PQ;
    vector<bool> checked(n,false);
    distance[start]=0;
    PQ.push(make_pair(0,start));
    int u;
    while(1){
        u=-1;
        while(!PQ.empty()){
            if(!checked[PQ.top().second]){
                u=PQ.top().second;
                distance[u]=-PQ.top().first;
                PQ.pop();
                break;
            }
            PQ.pop();
        }
        if(u==-1)break;
        checked[u]=true;
        for(int i=0;i<graph[u].size();i++){
            PQ.push(make_pair(-(distance[u]+graph[u][i].second),graph[u][i].first));
        }
    }
}

int main(){
    in(n);
    vector<vector<pair<ll,ll>>> graph(n);
    vector<ll> distance(n,1000000000000000000);
    int u,k,v,c,q;
    rep(i,n-1){
        in(u,v,c);
        graph[u-1].push_back(make_pair(v-1,c));
        graph[v-1].push_back(make_pair(u-1,c));
    }
    in(q,k);
    dijkstra(graph,distance,k-1);
    rep(i,q){
        in(u,v);
        out(distance[u-1]+distance[v-1]);
    }
}


#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int f(int);
int integral(int);

int main(void) {
	int a, b;

	while(cin >> a >> b) {
		cout << integral(a) << endl;
		cout << integral(b) << endl;
	}
	return 0;
}
int integral(int d){
	int n = 600 / d;
	int sum = 0;

	for (int i = 1; i < n; i++) {
		sum = sum + f(d * i) * d;
	}

	return sum;
}

int f(int a) {
	return a * a;
}

#include<iostream>

using namespace std;
int solve(int d){
	int ret=0;
	for(int i=d;i<=600-d;i+=d)
		ret+=i*i*d;
	return ret;
}

int main(){
	int d;
	while(cin>>d){
		cout<<solve(d)<<endl;
	}
}


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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int M,L,R;
    while(cin>>M>>L>>R,M||L||R){
        vint P(M);rep(i,M)cin>>P[i];
        sort(all(P));reverse(all(P));

        int val=0,ma=0;
        for(int i=L-1;i<R;i++){
            int tmp=P[i]-P[i+1];
            if(tmp>=val){
                val=tmp;
                ma=i+1;
            }
        }
        cout<<ma<<endl;
    }
    return 0;
}

#include <bits/stdc++.h>
#define range(i,c,o) for(register int i=(c);i<(o);++i)
using namespace std;

// fast_io BEGIN HERE
namespace IO
{
	static const size_t isize=1000000;
	char *cur,pool[isize];
	inline void clear()
	{
		rewind(stdin),cur=pool+isize;
	}
	inline char getC()
	{
		if(cur==pool+isize)
		{
			int siz=fread(pool,1,isize,stdin);
			if(siz<isize) pool[siz]='\0'; cur=pool;
			if(!siz) return '\0';
		}
		return *(cur++);
	}
	inline unsigned getU()
	{
		char c; unsigned r=0;
		while(!isdigit(c=getC()));
		for(;isdigit(c);c=getC())
		{
			r=(r<<3)+(r<<1)+c-'0';
		}
		return r;
	}
	inline char *getS(char*str)
	{
		char *i=str,c; while(isspace(c=getC()));
		for(;!isspace(c)&&c;c=getC()) *(i++)=c;
		return *i='\0',str;
	}
	static const size_t osize=100;
	char stk[osize];
	template<typename T>
	inline size_t putU(const T&n,const char&c='\n')
	{
		int bot=osize;
		stk[--bot]=c,stk[--bot]=n%10+'0';
		for(T i=n;i/=10;stk[--bot]=i%10+'0');
		return fwrite(stk+bot,osize-bot,1,stdout);
	}
	inline size_t putS(const char*str)
	{
		return fwrite(str,strlen(str),1,stdout);
	}
}
// fast_io END HERE

static int N;

// BIT BEGIN HERE
int bit[1000005];

inline int lowbit(const int&x) {return x&-x;}

inline void modify(const int&x,const int&y)
{
	for(int i=x+1;i;i-=lowbit(i)) bit[i]=min(bit[i],y);
}

inline int query(const int&x)
{
	int ret=0x7FFFFFFF;
	for(int i=x+1;i<N+2;i+=lowbit(i)) ret=min(ret,bit[i]);
	return ret;
}
// BIT END HERE

char S[1000005],T[1000005];
int pre[1000005],las[1000005],rec[1000005];
deque<int> que;
int main()
{
	//freopen("game.in" ,"r",stdin );
	//freopen("game.out","w",stdout);
	IO::clear(),N=IO::getU();
	IO::getS(S),IO::getS(T);
	if(!strcmp(S,T)) return IO::putS("0\n"),0;
	for(int i=N,j=N;i--;pre[i]=j)
	{
		for(j-=j>i;~j&&S[j]!=T[i];--j);
		if(!~j) return IO::putS("-1\n"),0;
	}
	int ans=0,cnt=0;
	for(int i=0;i<N;)
	{
		rec[cnt]=i,las[cnt++]=pre[i];
		for(++i;i<N&&pre[i]==pre[i-1];++i);
	}
	memset(bit,0x7F,sizeof bit);
	modify(N-cnt,cnt+1);
	for(int i=cnt;i--;)
	{
		modify(las[i]-i,i+1);
		ans=max(ans,query(rec[i]-i)-i);
	}
	return IO::putU(ans),0;
}


#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000000;
#define all(v) v.begin(), v.end()

int main(){
  ll N,M;
  cin >> N >> M;
  if(N*N==M){
    cout << N << endl;
  }else if(N*N<M){
    for(ll i=N;i*i<M;i++){
      if(M%i==0){
        cout << M/i << endl;
        return 0;
      }
    }
    for(ll i=N-1;i>0;i--){
      if(M%i==0){
        cout << i << endl;
        return 0;
      }
    }
  }else{
    for(ll i=M/N;i>0;i--){
      if(M%i==0){
        cout << i << endl;
        return 0;
      }
    }
  }

}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=max(x,a)
#define chmin(x,a) x=min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
const int MOD = 1000000007;
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
#define greater greater<int>()
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
using Edge=pair<int,ll>;
using Graph=vector<vector<bool> >;//ll or Edge
using Edge=pair<int,ll>;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// g++ -o a a.cpp -Wall -lm -std=c++17

vector<ll>divisor(int n){
    vector<ll>res;
    for(ll i=1;i*i<=n;++i){
        if(n%i==0){
            res.push_back(i);
            if(i!=n/i)res.push_back(n/i);
        }
    }
    sort(ALL(res));
    return res;
}
int main(){
    ll n,m;cin>>n>>m;
    VI s=divisor(m);
    ll ans;
    for(auto b:s){
        if(m/b>=n)ans=b;
    }
    cout<<ans<<endl;
}


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

int main() {
	long long n,k;
	cin>>n>>k;
	long double ch[200010];
	for(ll i=0;i<n;i++){
		cin>>ch[i];
	}
	long double ans=0;
	for(ll i=0;i<k;i++){
		long double now=ch[i];
		now=(ch[i]+1)/2;
		ans+=now;
	}
	//printf("%.10Lf\n",ans);
	long double cnt=ans;
	for(ll i=0;i+k<n;i++){
		cnt+=-(ch[i]+1)/2+(ch[i+k]+1)/2;
		ans=max(ans,cnt);
	}
	printf("%.10Lf",ans);
	// your code goes here
	return 0;
}

#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<random>
#include<chrono>
#include<bitset>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const double PI=acos(-1);
const ll INF = 1LL<<62;
const ll MINF = -(1LL<<62);

template<typename T> T getint() {
	T val=0;
	char c;

	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)

int main() {
	IO;
	ll a,b;
	cin>>a>>b;
	cout<<a*b<<"\n";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;

lint fac[MAX], finv[MAX], inv[MAX];

void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }

    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    }
 ///解説AC
  int main(){
      double n,m,d;
      cin>>n>>m>>d;
      if(d==0){
          printf("%.9f",1/n*(m-1));
      }else{
          printf("%.9f",2*(n-d)/n/n*(m-1));
      }
      }

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};

using ld=long double;

int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    ld n,m,d;
    cin>>n>>m>>d;
    ld ans=(m-1.0)*(n-d);
    if(d!=0.0) ans *=2.0;
    ans /=n;
    ans /=n;
    cout<<ans<<'\n';
}/*
./problem.exe
*/


#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
const int maxn=4e5+7;
int a[maxn],b[maxn];
int s[maxn],t[maxn];
int len;
int fail[maxn];
void getfail()
{
    memset(fail, 0, sizeof(fail));
    int j = 0, k = fail[0] = -1;
    while (j < len)
    {
        while (k != -1 && t[j] != t[k])
            k = fail[k];
        fail[++j] = ++k;
    }
}
vi ans;
int kmp()
{
    int n = len*2, m = len;
    int i = 0, j = 0;
    int ret = 0;
    while (i < n)
    {
        while (j != -1 && s[i] != t[j])
            j = fail[j];
        i++, j++;
        if (j == m)
        {
            ans.push_back(i-len);
            ret++, j = fail[j];
        }
    }
    return ret;
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int j=0;j<n;j++) cin>>b[j];
    if(n==1)
    {
        cout<<0<<" "<<(a[0]^b[0])<<'\n';
        return 0;
    }
    for(int i=1;i<n+n;i++) s[i-1]=a[i%n]^a[(i-1)%n];
    for(int i=1;i<n;i++) t[i-1]=b[i]^b[i-1];
    len=n-1;
    getfail();
    kmp();
    for(auto u:ans) cout<<u<<" "<<(b[0]^a[u])<<'\n';
}

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
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;
  cin>>N;
  ll A[2*N],AA[N],B[2*N],BB[N];
  REP(i,N) cin>>AA[i];
  REP(i,N) cin>>BB[i];
  REP(i,N){
    A[i]=AA[i]^AA[(i+1)%N];
    A[N+i]=A[i];
  }
  REP(i,N){
    B[i]=BB[i]^BB[(i+1)%N];
    B[N+i]=B[i];
  }

  ll base=1007,P[N+1],HA=0,HB=0;
  P[0]=1;
  RREP(i,N) P[i]=P[i-1]*base%MOD;

  REP(i,N){
    HA+=A[i]*P[N-1-i]%MOD;
    HA%=MOD;
    HB+=B[i]*P[N-1-i]%MOD;
    HB%=MOD;
  }

  REP(i,N){
    if(HA==HB){
      ll X=AA[i]^BB[0];
      cout<<i<<" "<<X<<endl;
    }
    HA=HA*base%MOD;
    HA-=A[i]*P[N]%MOD;
    HA+=A[i+N];
    HA%=MOD;
    if(HA<0) HA+=MOD;
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,x[100005],y[100005],mod=1e9+7;
ll calc(ll a[],ll n){
    ll ans =0 ;
    for(ll i=0;i<n-1;i++)a[i]=a[i+1]-a[i];
    n-=1;
    for(ll i=0;i<n;i++){
        ans = ans  + (i+1)*(n-i)%mod*a[i]%mod;
        ans%=mod;
    }
    return ans;
}
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin>>n>>m;
    for(ll i=0;i<n;i++)cin>>x[i];
    for(ll i=0;i<m;i++)cin>>y[i];
    cout<< (calc(x,n) * calc(y,m) )%mod;
}

#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	int n; scanf("%d", &n);
	std::vector<i64> a(n);
	for(int i = 0; i < n; i++) scanf("%lld", &a[i]);
	i64 m, k; scanf("%lld%lld", &m, &k);
	std::vector<int> b(m);
	for(int i = 0; i < m; i++) {
		scanf("%d", &b[i]);

		b[i]--;
	}

	std::vector<i64> d(n - 1);
	for(int i = 0; i < d.size(); i++) d[i] = a[i + 1] - a[i];

	std::vector<int> op(d.size());
	for(int i = 0; i < op.size(); i++) op[i] = i;
	for(auto v: b) std::swap(op[v - 1], op[v]);

	std::vector<int> ret(d.size());
	for(int i = 0; i < d.size(); i++) ret[i] = i;
	std::function<void ()> solve = [&]() {
		while(k) {
			if(k & 1) {
				std::vector<int> tmp(ret.size());
				for(int i = 0; i < op.size(); i++) {
					tmp[i] = ret[op[i]];
				}
				ret.swap(tmp);
			}

			std::vector<int> nxt = op;
			for(int i = 0; i < op.size(); i++) {
				nxt[i] = op[op[i]];
			}
			op.swap(nxt);
			k >>= 1;
		}
	};
	solve();

	std::vector<i64> ans(n, 0); ans[0] = a[0];
	for(int i = 0; i < ret.size(); i++) ans[i + 1] = d[ret[i]];
	for(int i = 0; i < ret.size(); i++) ans[i + 1] += ans[i];

	for(auto v: ans) printf("%lld\n", v);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int ba[12][12];
int dx[] = {1,0,-1,0};
int dy[] = {0,-1,0,1};
void dfs(int x,int y) {
  REP(i,4) {
    int xx = x+dx[i];
    int yy = y+dy[i];
    if (xx<0||xx>=12||yy<0||yy>=12) continue;
    if (ba[xx][yy]) {
      ba[xx][yy] = 0;
      dfs(xx,yy);
    }
  }
}

int main() {
  char b;
  while(cin >> b) {
    ba[0][0] = b-'0';
    REP(i,12) {
      REP(j,12) {
        if (i==0&&j==0)continue;
        char a;
        cin >> a;
        ba[j][i] = a-'0';
      }
    }
    int ans = 0;
    REP(i,12) {
      REP(j,12) {
        if (ba[i][j]) {
          ans++;
          dfs(i,j);
        }
      }
    }
    cout << ans << endl;
  }
}

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{

	int n, num;
	vector< int > a;

	while( 1 ) {

		cin >> n;
		if( n == 0 ) break;

		int Max = -100001;

		a.push_back( 0 );

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

			cin >> num;
			a.push_back( num );

		}

		for( int i = 1; i <= n; i++ ) {

			a[i] = max( a[i], a[i] + a[i - 1] );
			Max  = max( Max, a[i] );

		}

		cout << Max << endl;

		a.clear();

	}

	return 0;

}


#include <cstdio>
#include <iostream>
#define ri register int
using namespace std;

typedef long long LL;
const int N = 102;

char ch[N][N];
short le[N][N], up[N][N], dp[N][N][N][N];

inline void upd(short &x, short y) {
  if (x < y) x = y;
}

int main() {
  int n, m, ex, ey;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i ++) {
    scanf("%s", ch[i] + 1);
    for (int j = 1; j <= m; j ++) {
      le[i][j] = le[i][j - 1];
      up[i][j] = up[i - 1][j];
      if (ch[i][j] == 'o') le[i][j] ++, up[i][j] ++;
      if (ch[i][j] == 'E') ex = i, ey = j;
    }
  }
  short t, ans = 0;
  for (ri U = ex; U; U --)
    for (ri D = ex; D <= n; D ++)
      for (ri L = ey; L; L --)
	for (ri R = ey; R <= m; R ++) {
	  t = dp[U][D][L][R];
	  ans = max(ans, t);
	  if (U - 1 > D - ex) upd(dp[U - 1][D][L][R], t + le[U - 1][min(R, m - (ey - L))] - le[U - 1][max(L - 1, R - ey)]);
	  if (n - D > ex - U) upd(dp[U][D + 1][L][R], t + le[D + 1][min(R, m - (ey - L))] - le[D + 1][max(L - 1, R - ey)]);
	  if (L - 1 > R - ey) upd(dp[U][D][L - 1][R], t + up[min(D, n - (ex - U))][L - 1] - up[max(U - 1, D - ex)][L - 1]);
	  if (m - R > ey - L) upd(dp[U][D][L][R + 1], t + up[min(D, n - (ex - U))][R + 1] - up[max(U - 1, D - ex)][R + 1]);
	}
  cout << ans << endl;
  return 0;
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#define LL long long
using namespace std;
const int N=200005;
const LL inf=1ll<<40;
int n,q,sta,stb;
int x[N];
struct tree
{
	LL mv1[N*4],mv2[N*4],tag[N*4];//mv1-> f[x]-x mv2 -> f[x]+x
	void pushup(int k)
	{
		mv1[k]=min(mv1[k<<1],mv1[k<<1|1]);
		mv2[k]=min(mv2[k<<1],mv2[k<<1|1]);
	}
	void setv(int k,LL v){tag[k]+=v;mv1[k]+=v;mv2[k]+=v;}
	void pushdown(int k)
	{
		if(!tag[k])return;
		setv(k<<1,tag[k]);setv(k<<1|1,tag[k]);
		tag[k]=0;
	}
	void build(int k,int l,int r)
	{
		tag[k]=0;
		if(l==r){mv1[k]=mv2[k]=inf;return;}
		int mid=(l+r)>>1;
		build(k<<1,l,mid);build(k<<1|1,mid+1,r);
		pushup(k);
	}
	void upd(int k,int l,int r,int pos,LL v)
	{
		if(l==r){if(v<mv1[k]+l){mv1[k]=v-l;mv2[k]=v+l;}return;}
		int mid=(l+r)>>1;
		pushdown(k);
		if(mid>=pos)upd(k<<1,l,mid,pos,v);
		else upd(k<<1|1,mid+1,r,pos,v);
		pushup(k);
	}
	LL query1(int k,int l,int r,int ql,int qr)// query mv1
	{
		if((l>=ql&&r<=qr)||mv1[k]>=inf)return mv1[k];
		int mid=(l+r)>>1;LL res=inf;
		pushdown(k);
		if(mid>=ql)res=min(res,query1(k<<1,l,mid,ql,qr));
		if(mid<qr)res=min(res,query1(k<<1|1,mid+1,r,ql,qr));
		return res;
	}
	LL query2(int k,int l,int r,int ql,int qr)// query2 mv2
	{
		if((l>=ql&&r<=qr)||mv2[k]>=inf)return mv2[k];
		int mid=(l+r)>>1;LL res=inf;
		pushdown(k);
		if(mid>=ql)res=min(res,query2(k<<1,l,mid,ql,qr));
		if(mid<qr)res=min(res,query2(k<<1|1,mid+1,r,ql,qr));
		return res;
	}
	LL querya(int k,int l,int r)
	{
		if(l==r)return mv1[k]+l;
		int mid=(l+r)>>1;
		pushdown(k);
		return min(querya(k<<1,l,mid),querya(k<<1|1,mid+1,r));
	}
}t;
int Abs(int x){return x<0?-x:x;}
int input()
{
	int x=0,F=1;
	char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')F=-1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();}
	return x*F;
}
int main()
{
	cin>>n>>q>>sta>>stb;
	for(int i=1;i<=q;i++)x[i]=input();
	x[0]=sta;
	t.build(1,1,n);
	t.upd(1,1,n,stb,0);
	for(int i=1;i<=q;i++)
	{
		LL minv=min(t.query1(1,1,n,1,x[i])+x[i],t.query2(1,1,n,x[i]+1,n)-x[i]);
		t.setv(1,Abs(x[i]-x[i-1]));
		t.upd(1,1,n,x[i-1],minv);
	}
	cout<<t.querya(1,1,n);
	return 0;
}


#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair <int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

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

const int mod = 1e9 + 7;
const char nl = '\n';

void solve() {
    int n;
    cin >> n;
    int ara[n];
    for(int i = 0; i < n; ++i){
        cin >> ara[i];
    }
    sort(ara, ara + n);
    ll a(0), b(0);
    ll len = n - 1;
    char c(1);
    while(len){
        if(ara[len] == ara[len - 1]){
            if(c){
                a = ara[len];
                c = 0;
            }
            else{
                b = ara[len];
                break;
            }
            len--;
        }
        len--;
    }
    cout << a * b << nl;
}

int main() {
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    int n;cin >> n;
    vector<ll> A(n), abs_A(n);
    ll min_abs_A = 1e10;
    int minus_cnt = 0;
    for (int i = 0; i < n; i++){
        cin >> A[i];
        abs_A[i] = abs(A[i]);
        min_abs_A = min(min_abs_A, abs_A[i]);
        if (A[i] < 0) minus_cnt++;
    }
    ll ans = accumulate(abs_A.begin(), abs_A.end(), 0LL);
    if (minus_cnt % 2) {
        ans -= min_abs_A * 2;
    }
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define f(i,j,n) for(int i=j;i<=n;i++)
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int r;
    cin>>r;
    if(r<1200)
      cout<<"ABC";
    else if(r<2800 && r>=1200)
     cout<<"ARC";
    else
    cout<<"AGC";
}

#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  cout<<(N-2)*180<<endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define INF 10**9

int main() {
    ll n,prev=-1;
    cin >> n;
    rep(i,100000){
        if (pow(i,2)<=n){
            prev=pow(i,2);
        }
        else{
            cout << prev << endl;
            break;
        }
    }
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;

int main(){
  Int N;
  cin >> N;
  Int ans = 0;
  for (Int i = 1; i * i <= N; i++) {
    ans = i * i;
  }

  cout << ans << endl;

}


#include <iostream>
#include <string>

using namespace std;

int main(int argc, char const* argv[])
{
	string str;

	while( getline( cin, str ) ){
		for( int i = 0;i < 26;i++ ){
			for( int j = 0;j < str.size();j++ ){
				if( str[j] >= 'a' && str[j] <= 'y' ) str[j]++;
				else if( str[j] == 'z' ) str[j] = 'a';
			}
			if( str.find( "the" ) != string::npos || str.find( "this" ) != string::npos || str.find( "that" )  != string::npos ) {cout << str << endl; break;}
		}
	}
	return 0;
}

#include <iostream>

using namespace std;

class Rect{
	public:
		int w;
		int h;
		int diagonal;
};

void swap(int *a,int *b){
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

int main(){

	Rect rect[11180];
	for(int i=0;i<11180;i++){
		rect[i].diagonal=1000000;
	}

	int cnt=0;
	for(int i=1;i<=150;i++){
		for(int j=1;j<i;j++){
			rect[cnt].w=i;
			rect[cnt].h=j;
			rect[cnt].diagonal =i*i+j*j;
			cnt++;
		}
	}

	for(int i=0;i<11180;i++){
		for(int j=11180-1;j>i;j--){
			if(rect[j].diagonal<=rect[j-1].diagonal){
				swap(&rect[j].h,&rect[j-1].h);
				swap(&rect[j].w,&rect[j-1].w);
				swap(&rect[j].diagonal,&rect[j-1].diagonal);
			}
		}
	}

	for(int i=0;i<11180;i++){
		for(int j=11180-1;j>i;j--){
			if(rect[j].diagonal==rect[j-1].diagonal && rect[j].h<=rect[j-1].h){
				swap(&rect[j].h,&rect[j-1].h);
				swap(&rect[j].w,&rect[j-1].w);
				swap(&rect[j].diagonal,&rect[j-1].diagonal);
			}
		}
	}
	/*
	for(int i=0;i<=10100;i++){
		cout<<"i="<<i<<endl;
		cout<<"h="<<rect[i].h<<"w="<<rect[i].w<<"diagonal="<<rect[i].diagonal<<endl;
	}
	*/

	int inH,inW;
	while(cin>>inH>>inW){
		if(inH==0 && inW ==0)break;

		for(int i=0;i<11180;i++){
			if(rect[i].h == inH && rect[i].w == inW){
				/*
				cout<<"rectH="<<rect[i].h<<"rectW="<<rect[i].w<<endl;
				cout<<"inH ="<<inH<<"inW="<<inW<<endl;
				cout<<i<<" "<<i+1<<endl;
				*/
				cout<<rect[i+1].h<<" "<<rect[i+1].w<<endl;
				break;
			}
		}
	}

	return 0;
}


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

int main() {
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	string res = "";
	for (int i = sy; i < ty; i++) {
		res += 'U';
	}
	for (int i = sx; i < tx; i++) {
		res += 'R';
	}
	for (int i = sy; i < ty; i++) {
		res += 'D';
	}
	for (int i = sx; i < tx; i++) {
		res += 'L';
	}
	res += 'L';
	for (int i = sy; i < ty + 1; i++) {
		res += 'U';
	}
	for (int i = sx; i < tx + 1; i++) {
		res += 'R';
	}
	res += 'D';
	res += 'R';
	for (int i = sy; i < ty + 1; i++) {
		res += 'D';
	}
	for (int i = sx; i < tx + 1; i++) {
		res += 'L';
	}
	res += 'U';
	cout << res;
	return 0;
}

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")
//#pragma warning(disable : 4996)

//#include"atcoder/all"

#ifdef _MSC_VER
#include <intrin.h>

#define __builtin_popcount __popcnt
#define __builtin_popcountll __popcnt64
#endif

#include <limits.h>
#include <math.h>
#include <time.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
//using namespace atcoder;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m - 1; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v, n) reverse(v, v + n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout << (x) << endl
#define pe(x) cout << (x) << " "
#define DEBUG(x) cout << #x << ": " << x << endl
#define lb(v, n) lower_bound(v.begin(), v.end(), (n))
#define ub(v, n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i, v.size()) cout << v[i] << " \n"[i==(int)v.size()-1]
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; }
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 1e9 + 7;
constexpr int MAX = 500050;
const double pi = acos(-1);
constexpr double EPS = 1e-8;
constexpr ll LINF = 1e18 + 1;
constexpr int INF = 1e9 + 1;

void solve() {
	int A, B, C, D; cin >> A >> B >> C >> D;
	int K; cin >> K;
	int t1 = A * 60 + B;
	int t2 = C * 60 + D;
	int d = t2 - t1;
	print(d - K);
}

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

	//int q;
	//cin >> q;
	//while (q--)
	solve();

}


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

const int INF = 1e+9 * 2;

int main() {
	int n;
	while(cin >> n && n){
		int a[5010] = {0};
		for(int i = 0; i < n; ++i)
			scanf("%d", &a[i]);
		int ans = -INF;
		for(int i = 0; i < n; ++i){
			int sum = 0;
			for(int j = i; j < n; ++j){
				sum += a[j];
				if(ans < sum)
					ans = sum;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

#include <iostream>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
int main(void){
    int lp;
    cin >> lp;
    int* ary =(int*)malloc(sizeof(int)*lp);
    for(int i=0;i<lp;i++) {
        cin >> ary[i];
    }
    int count =0;
    for(int i=0;i<lp;i++) {
        for(int j=0;j<lp-i-1;j++) {
            if(ary[j] > ary[j+1]) {
                int tmp=ary[j];
                ary[j] = ary[j+1];
                ary[j+1] = tmp;
                count++;
            }
        }
    }
    for(int i=0;i<lp;i++) {
        if(i==lp-1)
            printf("%d\n",ary[i]);
        else
            printf("%d ",ary[i]);
    }
    printf("%d\n",count);
    free(ary);
    return 0;
}