akhauriyash/Code-Regression huggingface dataset:
import sys
n, k = map(int, input().split())
a = list(map(int, input().split())) 

visited = [None]*n
cur = 0
for i in range(k):
    if visited[cur] is None:
        visited[cur] = i
        cur = a[cur]-1
    else:
        break
else:
    print(cur+1)
    sys.exit()

k -= i
k %= i-visited[cur]

for i in range(k):
    cur = a[cur]-1

print(cur+1)


Measured memory_bytes: 32360
def MI():return map(int,input().split())
def LI():return list(MI())

x,y,a,b,c=MI()
p=sorted(LI())[::-1][:x]
q=sorted(LI())[::-1][:y]
r=sorted(LI())[::-1]

u=sorted(p+q+r)[::-1][:x+y]
print(sum(u))


Measured memory_bytes: 113004
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.math;

void main(){

    int casenum = 1;
    while(true){
	int w = to!int(chomp(readln()));
	if(w == 0) break;
	int ca = to!int(chomp(readln()));
	int[] trev,trew;
	for(int i=0;i<ca;i++){
	    auto s = split(chomp(readln()),',');
	    trev ~= to!int(s[0]);
	    trew ~= to!int(s[1]);
	}
	int a[1001];
	a[0] = 1;
	int ans=0;
	for(int j=0;j<ca;j++){
	    for(int i = w;i>=0;i--){
		if(i-trew[j]>=0 && a[i-trew[j]] > 0){
		    a[i] = max(a[i],trev[j] + a[i-trew[j]]);
		    ans = max(ans,a[i]);
		}
	    }
	}
	for(int i=0;i<=w;i++){
	    if(a[i] == ans){
		writef("Case %d:\n",casenum);
		writeln(a[i]-1);
		writeln(i);
		break;
	    }
	}
	casenum++;

    }
}

Measured memory_bytes: 2532
n = int(input())
k, *b_arr = map(int, input().split())
masks = [1 << x for x in range(n)]
b_mask = 0
for b in b_arr:
    b_mask += 1 << b

for i in range(1 << n):
    if i & b_mask != b_mask:
        continue
    sub = [idx for idx, mask in enumerate(masks) if i & mask != 0b00]
    print('{}: {}'.format(i, ' '.join(map(str, sub)))) if len(sub) != 0 else print(f'{i}:')


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

int main() {
  int a, b,y=0;
  cin >> a >> b;
  for(int i=0;i<=a;i++){
      if(2*i+4*(a-i)==b){
      	y=1;
    }
  }
  if(y==1){
  	cout << "Yes" << endl;
  }else{
  	cout << "No" << endl;
  }
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
#define bn(x) ((1<<x)-1)
#define newline puts("")
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 200005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;



int main() {
  int m = 37;
  int k = m+1;
  int n = k*(k-1)+1;
  cout<<n<<" "<<k<<endl;
  vvi a(m,vi(m));
  vi b(k);
  rep(i,m)rep(j,m) a[i][j] = i*m+j+1;
  rep(i,k) b[i] = m*m+i+1;
  rep(d,m) {
    rep(s,m) {
      vi now;
      rep(i,m) {
        int j = (s+i*d)%m;
        now.pb(a[i][j]);
      }
      now.pb(b[d]);
      cout<<now<<endl;
    }
  }
  rep(i,m) {
    vi now = a[i];
    now.pb(b[m]);
    cout<<now<<endl;
  }
  cout<<b<<endl;
  return 0;
}






















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

using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef pair<ul, ul> P;

const int INF = 1e9;
const int MOD =1e9+7;
const ll LINF = 1e18;

int main(){
    int N, K;
    int l[60];
    
    cin >> N >> K;
    rep(i,N) cin >> l[i];

    sort(l, l + N, greater<int>());

    int sum = 0;
    rep(i,K){
        sum += l[i];
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
/*{{{*/
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int N;
    LL K;
    R(N,K);
    VI A(N+1),pos(N+1,-1);
    FOR(i,1,N)R(A[i]);
    int now=1;
    VI d;
    int id=0;
    while(pos[now]==-1){
        d.PB(now);
        pos[now]=id++;
        now=A[now];
    }
    if(K<SZ(d))W(d[K]);
    else W(d[(K-pos[now])%(SZ(d)-pos[now])+pos[now]]);
    return 0;
}


Measured memory_bytes: 5912
#include<set>
#include<iostream>
using namespace std;
int main(){
  int i,j;
  int n;
  while(cin>>n&&n){
    int a[101];
    for(i=0;i<n+1;++i)
      cin>>a[i];
    for(i=0;i<n+1;++i){
      set<int> b;
      for(j=1;j<n+1;++j){
        if(false){
        }else if(j-1==i){
          if(j-2<0)continue;
          b.insert(a[j]-a[j-2]);
        }else if(j==i){
          if(j+1>=n+1)continue;
          b.insert(a[j+1]-a[j-1]);
        }else{
          b.insert(a[j]-a[j-1]);
        }
      }
      if(b.size()==1)break;
    }
    cout<<a[i]<<endl;
  }
  return 0;
}

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

using namespace std;
  
int main()
{
  int dist = 0, n, x, tmp, i;
  int result = 1;
  cin >> n >> x;

  for(i=0;i<n;i++){
    cin >> tmp;
    dist += tmp;
    if(dist > x){
      break;
    }
    result++;
  }

  cout << result;

  return 0;
}

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

using namespace std;

int N;
int A[100005];

int main() {

cin.tie(0);
ios::sync_with_stdio(false);

cin>>N;

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

int S;

for(int i=0; i<=N; i++){
  S+=abs(A[i]-A[i+1]);
}

for(int i=1; i<=N; i++){
  int ans=S-abs(A[i-1]-A[i])-abs(A[i]-A[i+1])+abs(A[i-1]-A[i+1]);
  cout<<ans<<endl;
}

}


Measured memory_bytes: 1664
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e6+3)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define ALL(x) (x).begin(),(x).end()
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)

ll modpow(ll x, ll n) {
    if(n==0){
        return 1;
    }else if(n%2==0){
        ll h = modpow(x,n/2);
        return h * h % MOD;
    } else {
        return x * modpow(x,n-1) % MOD;
    }
}

int main() {
  std::cout<<std::fixed<<std::setprecision(12);
  ll n, m, d;
  cin >> n >> m >> d;

  //全数はn^m通り
  //美しさに該当する組は(n,n-d),...,(d+1,1)
  //隣り合う2つの数について美しさを満たす確率は(n-d)/(n^2)
  double ans;

  //d==0のとき
  //美しさに該当する組はn組
  //隣り合う2つの数について美しさを満たす確率は(n)/(n^2)

  if(d==0){
    ans = 1.0*(m-1)/(1.0*n);
  }else{
    ans = 2.0*(n-d)*(m-1)/(1.0*n*n);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
n, k = map(int, input().split())

def Base_10_to_n(n, k):
  if int(n/k):
    return Base_10_to_n(int(n/k), k)+str(n%k)
  return str(n%k)
 
x = Base_10_to_n(n, k)
print(len(x))

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    CIN(int, N);
    CINS(int, A, N);
    CINS(int, B, N);
    CINS(int, C, N);

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());

    ll ans = 0;
    ll rA = -1, lC = -1;

    for (int b = 0; b < N; b++) {
        for (int a = max(rA, 0ll); a < N; a++) {
            if (A[a] >= B[b]) break;
            rA = a;
        }
        for (int c = max(lC, 0ll); c < N; c++) {
            if (C[c] > B[b]) break;
            lC = c;
        }
        ans += (rA + 1) * (N - 1 - lC);
    }

    cout << ans << "\n";
    return 0;
}

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

int n, m, t, tot;

int main()
{
	cin >> n >> m;
	for (int i = 1; i <= m; i++)
	{
		cin >> t;
		tot += t;
	}
	if (n - tot >= 0) cout << n - tot << endl;
	else cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 3592
#prag\
ma GCC optimize("O3")

#include <bits/stdc++.h>

using namespace std;

int n,sum1[105],sum2[105];

int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);

	ios::sync_with_stdio(false);

	cin>>n;
	
	int x;
	
	cin>>x;
	
	sum1[1]=x;
	
	for (register int i=2;i<=n;++i)
	{
		cin>>x;
		sum1[i]=sum1[i-1]+x;
	}
	
	cin>>x;
	
	sum2[1]=x;
	
	for (register int i=2;i<=n;++i)
	{
		cin>>x;
		sum2[i]=sum2[i-1]+x;
	}	
	
	int ans=0;
	
	for (register int i=1;i<=n;++i)
	{
		ans=max(ans,sum1[i]+sum2[n]-sum2[i-1]);
	}
	
	cout<<ans<<'\n';
	 
	return 0;
}


Measured memory_bytes: 256
using System.Text;
using static System.Math;
using System.Collections.Generic;
using System.Linq;
using System;

public class hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var imax = Pow(2, n);
        var sb = new StringBuilder();
        for (int i = 0; i < imax; i++)
        {
            var b = new List<int>();
            for (int j = 0; j < n; j++)
                if (((i >> j) & 1) == 1) b.Add(j);
            if (b.Count() == 0) sb.Append(string.Format("{0}:\n", i));
            else
            {
                sb.Append(string.Format("{0}: ", i));
                sb.Append(string.Join(" ", b));
                sb.Append("\n");
            }
        }
        Console.Write(sb);
    }
}


Measured memory_bytes: 52748
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

string S;

bool good() {
  for (int i = 0; i < S.size(); ++i) {
    if ((i % 2 == 0 && S[i] == 'L') || (i % 2 == 1 && S[i] == 'R')) {
      return false;
    }
  }
  return true;
}

int main() {
  cin >> S;
  cout << (good() ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;


int main(void)
{
    IOS
    int n; cin >> n;
    constexpr ll INF = 1LL << 50;
    vector<map<int,ll>> v(n,map<int,ll>());
    REP(i,n-1) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;b--;
        v[a][b] = c;
        v[b][a] = c;
    }
    int q, k;
    cin >> q >> k;
    k--;
    vector<pii> xy;
    REP(i,q){
        int x,y; cin >> x >> y;
        x--;y--;
        xy.push_back(make_pair(x,y));
    }

    // あえてダイクストラ
    vector<ll> d(n,INF);
    vector<bool> visit(n);
    d[k] = 0;
    visit[k] =true;
    priority_queue<pll,vector<pll>,greater<pll>> pq;
    for(auto item:v[k]) {
        d[item.first] = item.second;
        pq.push(make_pair(item.second,item.first));
    }
    int vcount = 1;
    while(!pq.empty()) {
        auto item = pq.top(); pq.pop();
        // cerr << item.second << " " <<pq.size() << endl;
        if (!visit[item.second]) {
            visit[item.second] = true;
            vcount++;
            for(auto to:v[item.second]) {
                // cerr << "to" << " " <<< to.first <<" " << to.second << endl;
                if (d[to.first] > d[item.second] + to.second) {
                    d[to.first] = d[item.second] + to.second;
                    pq.push(make_pair(d[to.first],to.first));
                }
            }
        }
    }

    REP(i,q) {
        cout << d[xy[i].first] + d[xy[i].second] << endl;
    }

    return 0;
}

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

int main(){
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    while(A>0 && C>0){
        C=C-B;
        if(C<=0){cout << "Yes" << endl;
        break;}
        A=A-D;
        if(A<=0){
            cout << "No" << endl;
            break;
        }



    }

    return 0;
    

    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
long long dp[3001][3001] = {0};
int main()
{
	long long n, i, j, a[3001] = {0};
	cin >> n;
	for(i = 0; i < n; i++)
	{
		cin >> a[i];
		if(n % 2)
			dp[i][i] = a[i];
		else
			dp[i][i] = -a[i];
	}
	for(i = 2; i <= n; i++)
	{
		for(j = 0; j + i - 1 < n; j++)
		{
			if(i % 2 && n % 2 || (!(i % 2)) && (!(n % 2)))
			{
				dp[j][i + j - 1] = max(dp[j][i + j - 2] + a[j + i - 1], dp[j + 1][i + j - 1] + a[j]);
			}
			else
			{
				dp[j][i + j - 1] = min(dp[j][i + j - 2] - a[j + i - 1], dp[j + 1][i + j - 1] - a[j]);
			}
		}
	}
	cout << dp[0][n - 1];
	return 0;
}

Measured memory_bytes: 49704
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

int main(){
  ll x;
  cin>>x;
  if(x%11==0) cout<<(x/11)*2;
  else if(x%11<7) cout<<(x/11)*2+1;
  else cout<<(x/11+1)*2;
  cout<<endl;
}

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

#define FOR(i, a, b) for(int i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(int i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define DEBUG_PRINT(...) fprintf(stderr, __VA_ARGS__)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;

int N;
deque<string> S;

int main(){
  scanf("%d", &N);
  REP(N){
    string tmp;
    cin>>tmp;
    assert(tmp.size() == N);
    S.push_back(tmp);
  }
  ll ans = 0;
  For(i, N){
    For(j, N){
      FOR(k, j+1, N){
        if(S[j][k]!=S[k][j])goto fend;
      }
    }
    ans+=N;
fend:;
     string tmp = S.front();
     S.pop_front();
     S.push_back(tmp);
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <math.h>
#include <cmath>
#include <ctime>
#include <stdlib.h>

using namespace std;

#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define m_p make_pair
#define m_t make_tuple
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
typedef pair<int, int> P;

const double pai = 3.1415926535897;
const int mod = 1000000007;
const int INF = 1000000021;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];


//x未満の要素数を返す二分探索関数
int b_s(vector<int>& vec, int xx) {
	return lower_bound(all(vec), xx) - vec.begin();
}
template<typename T>void vecout(vector<T>& vec) { for (T t : vec) cout << t << " "; cout << endl; }
template<typename TT>void vecin(vector<TT>& vec) {
	for (int i = 0; i < vec.size(); i++) {
		cin >> vec[i];
	}
}

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int 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;
	}
}

//n個を1個以上のx組のグループに分ける重複組み合わせはcom(n-1,x-1)
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
long long modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

bool chmax(int& xx, int yy) {
	if (xx < yy) {
		xx = yy;
		return true;
	}
	return false;
}
bool chmin(int& xx, int yy) {
	if (xx > yy) {
		xx = yy;
		return true;
	}
	return false;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	if (xx <= 1) {
		return 0;
	}
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}



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

Measured memory_bytes: 3732
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
int main(){
    int n;
    cin>>n;
    vector<pair<ll,ll>> v;
    rep(i,n){
        ll a,b;
        cin>>a>>b;
        v.push_back({a,b});
    }
    sort(v.begin(),v.end());
    ll ans=0;
    ans+=v[v.size()-1].first;
    ans+=v[v.size()-1].second;
    cout<<ans<<endl;

return 0;
}


Measured memory_bytes: 2420
from collections import deque

H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]

dir = [(-1, 0), (1, 0), (0, -1), (0, 1)]

dist = [[-1] * W for _ in range(H)]

def BFS(y, x):
  """(y, x)からはじめて、道のマスをBFSで最短距離を探す"""
  que = deque()
  que.append((y, x))
  dist[y][x] = 0
  max_dist = 0
  while que:
    sy, sx = que.popleft()  # popleft?
    for dy, dx in dir:
      ny = sy + dy
      nx = sx + dx
      if 0 <= ny < H and 0 <= nx < W and S[ny][nx] != "#" and dist[ny][nx] == -1:
        que.append((ny, nx))
        dist[ny][nx] = dist[sy][sx] + 1
        max_dist = max(max_dist, dist[ny][nx])
  
  return max_dist

max_dist = 0
for sy in range(H):
  for sx in range(W):
    if S[sy][sx] != "#":
      dist = [[-1] * W for _ in range(H)]
      max_dist = max(max_dist, BFS(sy, sx))

print(max_dist)

Measured memory_bytes: 9476
// https://atcoder.jp/contests/abc110/tasks/abc110_d
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

// 素因数分解
map<ll, int> enumpr(ll n) {
    map<ll, int> V;

    for (int i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            V[i]++;
            n /= i;
        }
    }
    if (n > 1)
        V[n]++;
    return V;
}

const int MOD = 1000000007;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};
mint operator-(mint a) { return -a.n + MOD * (a.n != 0); }
mint operator+(mint a, mint b) {
    int x = a.n + b.n;
    return x - (x >= MOD) * MOD;
}
mint operator-(mint a, mint b) {
    int x = a.n - b.n;
    return x + (x < 0) * MOD;
}
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }
istream &operator>>(istream &i, mint &a) { return i >> a.n; }
ostream &operator<<(ostream &o, mint a) { return o << a.n; }

vector<mint> F_{1, 1}, R_{1, 1}, I_{0, 1};

void check_fact(int n) {
    for (int i = I_.size(); i <= n; i++) {
        I_.push_back(I_[MOD % i] * (MOD - MOD / i));
        F_.push_back(F_[i - 1] * i);
        R_.push_back(R_[i - 1] * I_[i]);
    }
}

mint I(int n) {
    check_fact(abs(n));
    return n >= 0 ? I_[n] : -I_[n];
}
mint F(int n) {
    check_fact(n);
    return n < 0 ? 0 : F_[n];
}
mint R(int n) {
    check_fact(n);
    return n < 0 ? 0 : R_[n];
}
mint C(int n, int r) { return F(n) * R(n - r) * R(r); }
mint P(int n, int r) { return F(n) * R(n - r); }
mint H(int n, int r) { return n == 0 ? (r == 0) : C(n + r - 1, r); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    auto mp = enumpr(m);

    mint ans = 1;
    for (auto x : mp) {
        ans *= H(n, x.second);
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];

    vector<bool> B(N, false);
    rrep(i, N - 1, 0) {
        ll a = A[i];
        ll cnt = 0;
        ll start = i + 1;
        while (start <= N) {
            cnt += B[start - 1];
            start += i + 1;
        }
        if (cnt % 2 == a) {
            continue;
        } else {
            B[i] = true;
        }
    }
    vector<ll> ans;
    rep(i, N) {
        if (B[i]) {
            ans.push_back(i);
        }
    }
    cout << ans.size() << '\n';
    rep(i, ans.size()) {
        cout << ans[i] + 1 << ' ';
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3700
/*
 NOTE:
*/
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <queue>
#include <vector>
#include <map>
#include <stack>
#include <set>
#define MP make_pair
#define F first
#define S second
#define TIME (double)clock()/CLOCKS_PER_SEC
using namespace std;
typedef long long ll;

int n, m;
int a[100010];
int point[100010], te = 0;
struct e {int to, next;} edge[200020];
void add (int u, int v)
{
	te ++;
	edge[te].to = v;
	edge[te].next = point[u];
	point[u] = te;
}

int b1[100010], b2[100010];

void dfs(int x, int rt)
{
	b1[x] = rt;
	b2[a[x]] = rt;
	for (int e = point[x]; e; e = edge[e].next) {
		int to = edge[e].to;
		if (!b1[to])
			dfs(to, rt);
	}
}

int main()
{
//	freopen("test.in", "r", stdin);
//	freopen("test.out", "w", stdout);
 	ios::sync_with_stdio(false);
	cin >> n >> m;
	for (int i = 1; i <= n; i ++)
		cin >> a[i];
	for (int a, b, i = 1; i <= m; i ++)
		cin >> a >> b, add (a, b), add (b, a);
	for (int i = 1; i <= n; i ++)
		if (!b1[i])
			dfs(i, i);
	int ans = 0;
	for (int i = 1; i <= n; i ++)
		ans += (b1[i] == b2[i]);
	cout << ans << endl;
	return 0;
}
/*
*/



Measured memory_bytes: 5376
/*
Arthor : Ender_zzm
E-mail zzm_ender_wiggin@outlook.com
Blog ender-zzm.enbar.cn
*/
#include <bits/stdc++.h>
using namespace std;

inline int Isdigit(char c) {
	if (c < '0' || c > '9') return 0;
	return 1;
}
inline int readint(){
    register int x = 0, flag = 1;
    register char ch;
    while (!Isdigit(ch = getchar())) if (ch == '-') flag = -1;
    while (x = x * 10 + (ch & 15), Isdigit(ch = getchar()));
	return x * flag;
}

inline long long readlong() {
	register long long x = 0, flag = 1;
	register char ch;
	while (!Isdigit(ch = getchar())) if (ch == '-') flag = -1;
    while (x = x * 10 + (ch & 15), Isdigit(ch = getchar()));
	return x * flag;
}
template <class T>
inline void write(T x){
    if (x < 0)
        putchar('-'), x = -x;
    if(x >= 10) write(x / 10); 
    putchar(x % 10 + '0');
}

template<class T> inline bool Chkmax(T& x, const T& y) { return x < y ? x = y, true : false; }
template<class T> inline bool Chkmin(T& x, const T& y) { return x > y ? x = y, true : false; }

#define For(i, x, y) for (int i = (x); i <= (y); i++) 
#define Rep(i, x, y) for (int i = (x); i >= (y); i--) 
#define ri readint
#define rl readlong

int main() {
	string s;
	cin >> s;
	int A = 0, B = 0;
	for (int i = 1; i <= 3; i++) {
		if (s[i - 1] == 'A') A++;
		else B++;
	}
	if (A > 0 && B > 0) {
		cout << "Yes"; return 0;
	}
	else {
		puts("No"); return 0;
	}
	return 0;
}


Measured memory_bytes: 3600
import java.io.*;  

public class Main {
    public static void main(String[] args) throws IOException {
	int hour;                                         
	int min;                                          
	int sec;                                          
    	
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	int y  = Integer.parseInt(br.readLine());
    
    	  hour = y /3600;
    	  min = (y%3600)/60;
    	  sec = (y%3600)%60;
    	System.out.println(hour + ":" + min + ":" + sec); 
    	
	    
    }
    
}

Measured memory_bytes: 24360
a,b,c,d=map(int,input().split())
sum=0
if d>a:
    sum=sum+a
    d=d-a
else:
    sum = sum+(d)
    d=0
    print(sum)
    exit()
if d>0:
    if b>=d:
        d=0
        print(sum)
        exit()
    else:
        d=d-b
if d>0:
    if c>=d:
        sum=sum-d
        print(sum)
        d=0
        exit()
    else:
        sum=sum-c
        print(sum)
        exit()
        
        

    


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


int main() {
    int a,b,ab;
    cin >>a>>b;
    ab = a + b;
    if (ab % 3 == 0||a%3==0||b%3==0)cout << "Possible" << endl;
    else cout << "Impossible" << endl;

    

   
    return 0;
   
}

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

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

int l[100002]={};
int r[100002]={};
int a[100000]={};

int main(){
  int N;
  cin >> N;
  for(int i=0; i<N; i++){
    cin >> a[i];
  }
  l[0]=l[N+1]=0;
  for(int i=0; i<=N; i++){
    l[i+1]=gcd(l[i], a[i]);
  }
  r[0]=r[N+1]=0;
  for(int i=N; i>=0; i--){
    r[i] = gcd(r[i+1],a[i]);
  }
  int max=1;
  for(int i=0; i<=N;i++){
    int g = gcd(l[i],r[i+1]);
    if(max < g) max = g;
  }
  cout << max << endl;
  return 0;
}

Measured memory_bytes: 1408
N = int(input())
A = [int(i) for i in input().split()]

import itertools
count = 0
check = [int(abs((N-i+1)- i)) for i in range(1,N+1)]
flag = sorted(A) == sorted(check)
if flag:
    print(2 ** (N//2) % (10 ** 9 + 7))
else:
    print(0)
    

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

signed main(){
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout.precision(20);

  int n;
  cin >> n;
  vector<int> w(n);
  REP(i,n) cin >> w[i];
  int t1 = w[0];
  int t2 = 0;
  REP(i, n - 1) t2 += w[i + 1];
  int min = INF;
  REP(i,n-1){
    int t = abs(t1 - t2);
    if(min > t){
      min = t;
    }
    t1 += w[i + 1];
    t2 -= w[i + 1];
  }

  cout << min << endl;

  return 0;
}

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


#include <assert.h>    // LON
#include <math.h>    // sqrt()


using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;

struct Edge {
    ll to, cost;
};

vector<ll> distances;
ll vector_count;
vector<vector<Edge>> edges;

void dijkstra(int k) {
    distances[k] = 0;  // 始点sへの最短距離は0

    priority_queue<P, vector<P>, greater<P>> que;  // 距離が小さい順に取り出せるようgreater<P>を指定
    que.push(P(0, k));
    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;  // 更新した頂点の中で距離が最小の頂点v
        if (distances[v] < p.first) {
            continue;
        }
        for (auto e : edges[v]) {  // 頂点vから出る辺eを走査
            if (distances[e.to] > distances[v] + e.cost) {
                distances[e.to] = distances[v] + e.cost;
                que.push(P(distances[e.to], e.to));
            }
        }
    }
}

int main() {
    cin >> vector_count;
    edges.resize(vector_count);
    distances.resize(vector_count, INF);

    rep(i, vector_count - 1) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        edges[b].push_back({a, c});
        edges[a].push_back({b, c});
    }

    ll q, k;
    cin >> q >> k;
    k--;

    dijkstra(k);

    rep(i, q) {
        ll x, y;
        cin >> x >> y;
        x--;
        y--;
        cout << distances[x] + distances[y] << endl;
    }

}

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

int main() {
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b){
        if(b==c){
            cout<<1<<endl;
        }else{
            cout<<2<<endl;
        }
    }else{
        if(a==c || b==c){
            cout<<2<<endl;
        }else{
            cout<<3<<endl;
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	int arr[n];
	for(int i = 0 ; i < n ; i++){
		cin >> arr[i];
	}
	int ite = 0 , cont = 0;
	int a , b , c;
	while(true){
		if(ite + 2 > n - 1) break;
		a = arr[ite]; b = arr[ite + 1] ; c = arr[ite +2];
		if((b >= a && b <= c) || (b <= a && b >= c)) cont ++;
		ite++;
		a = 0  ; b = 0 ; c = 0;
	}
	cout << cont;
	return 0;
}

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

#define mid(l,r) ((l+r)/2)

using namespace std;

const int N = 1e5 + 7;
const int inf = 1e9 + 7;

int n, m, k;

int main() {
	//freopen("t.gir", "r", stdin);
	//freopen("t.cik", "w", stdout);

	int a, b, c;

	cin >> a >> b >> c;

	if(a + b+ c >=22)
		cout << "bust";

	else cout << "win";

	
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
long long GCD(long long A, long long B) {
	if (B == 0) return A;
	else return GCD(B, A % B);
}
int main() {
	long long A, B;
	cin >> A >> B;
	if (A < B) {
		long long t = A;
		A = B;
		B = t;
	}
	long long gcd = GCD(A, B);
	cout << A * B / gcd << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=long long;

int main(){
    int n;
    ll d;
    cin>>n>>d;
    int res = 0;
    for(int i=0;i<n;i++){
        ll x,y;
        cin>>x>>y;
        if(x*x+y*y<=d*d){
            res++;
        }
    }
    cout<<res<<endl;
    
    return 0;
}

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

typedef long long ll;
typedef unsigned long long llu;

int main(int argc, char *argv[]) {
  ll N;
  cin >> N;

  vector<ll> p(N);
  vector<ll> orig(N);
  for (ll i = 0; i < N; ++i) {
    cin >> p[i];
  }
  orig = p;

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

  ll diff = 0;
  for (ll i = 0; i < N; ++i) {
    if (p[i] != orig[i]) {
      diff++;
    }
  }
  
  if (diff > 2) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
  int A,B,C;
  cin >> A >> B;
  if(13<=A){
    cout << B << endl;
  }
  else if(6<=A && A<=12){
    C = B/2;
    cout << C << endl;
  }
  else{
    cout << 0 << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second

using namespace std;
typedef long long int64;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int64 n;
    cin >> n;
    vector<int64> a(n + 1);
    map<int64, int> mp;
    for (int i = 1; i <= n; ++ i) {
        cin >> a[i];
        mp[i - a[i]] ++;
    }
    int64 cnt = 0;
    for (int i = 1; i <= n; ++ i) {
        mp[i - a[i]] --;
        cnt += mp[a[i] + i];
    }
    cout << cnt;
}

Measured memory_bytes: 27432
#include <stdio.h>
int main(void){
        int x,y,change;

        do{
                scanf("%d %d",&x,&y);
                if(x==0 && y==0)
                        break;

                if(x > y){
                        change=x;
                        x=y;
                        y=change;
                }
                printf("%d %d\n",x,y);
        }while(1);

                return 0;
        }


Measured memory_bytes: 2040
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

import math

def is_prime(n):
        if n == 1: return False

        for k in range(2, int(math.sqrt(n)) + 1):
            if n % k == 0:
                return False
        return True

def main():
    number=int(input())
    numbers=[]
    numbers=[int(input()) for _ in range(number)]
    counter=0
    for n in numbers:
        ans=is_prime(n)
        if ans ==True:
            counter+=1
        else:
            continue
    print(counter)
if __name__=="__main__":
    main()


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


int compare(const void *a, const void *b) {
    int* arr1 = (int*)a;
    int* arr2 = (int*)b;

    return arr1[1] - arr2[1];
}


int main(void) {
    int N;
    int AB[200000][2];

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

    qsort(AB, N, 2*sizeof(int), compare);

   int sum = 0;
   for (int i=0;i<N;i++) {
       sum += AB[i][0];
       if (sum > AB[i][1]) {
           printf("No\n");
           return 0;
       }
   }

   printf("Yes\n");
   return 0;
}

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

ll solve() {
    ll N, Z, W;
    cin >> N >> Z >> W;
    vector<ll> A(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> A[i];
    }
    if ( N == 1 ) return abs(W-A[N-1]);
    else return max(abs(W-A[N-1]), abs(A[N-2]-A[N-1]));
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define ZERO (1e-10)
#define INF int(1e9+1)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define DEB printf("DEB!\n");
#define D(X) cout<<"  "<<#X": "<<X<<endl;
#define EQ(A,B) (A+ZERO>B&&A-ZERO<B)
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
#define IN(n) int n;scanf("%d",&n);
#define FOR(i, m, n) for (int i(m); i < n; i++)
#define F(n) FOR(i,0,n)
#define FF(n) FOR(j,0,n)
#define FT(m, n) FOR(k, m, n)
#define aa first
#define bb second
void ga(int N,int *A){F(N)scanf("%d",A+i);}
int A[5],B,S;
int main(void){
    ga(5,A),sort(A,A+5),B=INF;
    do{
        S=0;
        F(5){
            while(S%10)++S;
            S+=A[i];
        }
        B=min(B,S);
    }while(next_permutation(A,A+5));
    printf("%d\n",B);
    return 0;
}


Measured memory_bytes: 256
#coding=UTF-8

N=int(input())
a=[]

for idx in range(0,N,1):
    a.append(int(input())-1)


lit=0
length=0
ans=None
for idx in range(0,N,1):
    lit=a[lit] #press
    length+=1
    if lit == 2-1:
        ans=True
        break
        



if ans:
    print(length)
else:
    print(-1)


Measured memory_bytes: 7084
n,k = map(int,input().split())
al = list(map(int,input().split()))

# a,bの最大公約数
def gcd(a, b):
   while b:
       a, b = b, a % b
   return a

tmp = al[0]
for a in al:
    tmp = gcd(a, tmp)

if k % tmp == 0 and max(al) >= k:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
int main(){
int a,b;char op='+';
while(op!='?'){
 cin>>a>>op>>b;
 switch(op){
  case('+'):
   cout<<a+b<<endl;
   break;
  case('-'):
   cout<<a-b<<endl;
   break;
  case('*'):
   cout<<a*b<<endl;
   break;
  case('/'):
   cout<<a/b<<endl;
   break;
  }
 }
}


Measured memory_bytes: 3088
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) (a).begin(), (a).end()
#define AALL(a, n) (a), ((a) + (n))
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define MODNUM (static_cast<int>(1e9 + 7))
#define MOD(x) ((x) % MODNUM)

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

const int INF = 2e9;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

template <typename T>
int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T>
void chmax(T& m, T x) {
	m = std::max(m, x);
}

template <typename T>
void chmin(T& m, T x) {
	m = std::min(m, x);
}

template <typename T>
T square(T x) {
	return x * x;
}

inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

int main() {
	int n;
	scanf("%d", &n);
	VI x(n);
	VI l(n);
	REP(i, n) { scanf("%d %d", &x[i], &l[i]); }
	vector<pair<int, int>> robot(n);
	REP(i, n) { robot[i] = pair<int, int>(x[i] + l[i], x[i] - l[i]); }
	sort(ALL(robot));
	int result = 0;
	int position = -INF;
	REP(i, n) {
		if(robot[i].second >= position) {
			result++;
			position = robot[i].first;
		}
	}
	printf("%d\n", result);
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fr first
#define sc second
const int mod = 1e9+7;
const int N = 1e6+6;
ll a[N];
int lg2(int x){
    int ret = 0;
    while(x%2==0){
        x/=2;
        ret++;
    }
    return ret;
}
int main(){
    int n;
    cin>>n;
    int ans = 0;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        ans+=lg2(x);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3604
package main

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

const (
	maxBufsize = 1000000
)

func inputs(lines int) []string {
	var strSlice []string

	rdr := bufio.NewReaderSize(os.Stdin, maxBufsize)

	for i := 0; i < lines; i++ {

		line := ReadLine(rdr)
		strSlice = append(strSlice, line)

	}

	return strSlice
}

// ReadLine is to read long line
func ReadLine(rdr *bufio.Reader) string {
	buf := make([]byte, 0, maxBufsize)
	for {
		l, p, e := rdr.ReadLine()

		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}

	return string(buf)
}

func main() {

	line1 := inputs(1)

	for _, v := range line1[0] {
		if string(v) == "7" {
			fmt.Println("Yes")
			return
		}
	}

	fmt.Println("No")

}

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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

bool f(ll c, int K, string &S) {
    bool prev0 = false;
    int cnt = 0;
    int N = S.size();
    for(int i = 0; i < c; i++) {
        if (S[i] == '0' && !prev0) {
            prev0 = true;
            cnt++;
        } else if (S[i] == '1' && prev0) {
            prev0 = false;
        }
    }
    int ans = cnt;
    for (int i = c; i < N; i++) {
        if (S[i] == '0' && !prev0) {
            prev0 = true;
            cnt++;
        } else if (S[i] == '1' && prev0) {
            prev0 = false;
        }
        if (S[i - c] == '0' && S[i - c + 1] == '1') {
            cnt--;
        }
        ans = min(ans, cnt);
    }
    return ans <= K;
}

void solve() {
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;

    ll ok = 0, ng = N + 1;
    while(ng - ok > 1) {
        ll c = (ng + ok) / 2;
        if (f(c, K, S)) {
            ok = c;
        } else {
            ng = c;
        }
    }

    cout << ok << endl;

}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

Measured memory_bytes: 512
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    ll n,a,b;
    cin >> n >> a >> b;

    if(a>b){
        cout << 0 << endl;
    }else if(a==b){
        cout << 1 << endl;
    }else{
        if(n==1){
            cout << 0 << endl;
        }else{
            cout << (b-a)*(n-2)+1 << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3628
N, M = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(M)]
visited = [0]*N
ans = 0
def move(vert):
    global ans
    visited[vert-1] = 1
    if sum(visited) == N:
        ans += 1
        visited[vert-1] = 0
        return 0 
    for i in range(M):
        if ab[i][0] == vert and visited[ab[i][1]-1] == 0:
            move(ab[i][1])
        elif ab[i][1] == vert and visited[ab[i][0]-1] == 0:
            move(ab[i][0])
    visited[vert - 1] = 0
    return ans
print(move(1))

Measured memory_bytes: 3064
import sys

INPUT = lambda: sys.stdin.readline().rstrip()
MAP = lambda: map(int, INPUT().split())

sys.setrecursionlimit(10 ** 9)


def main():
    H, W = MAP()
    h, w = MAP()
    print((H - h)*(W - w))


if __name__ == '__main__':
    main()

Measured memory_bytes: 38512
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
//ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
int main() {
	int K, N;
	cin >> K >> N;
	vector<int> a(N + 1), d(N);
	rep(i, 0, N)cin >> a[i];
	a[N] = K + a[0];
	rep(i, 0, N)d[i] = a[i + 1] - a[i];
	r_sort(d);
	printf("%d\n", K - d[0]);
	return 0;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
int main(){
    int n,i,j,minj;
    int count = 0;
    cin >> n;
    vector<int> A(n);
    for(i=0;i<n;i++) cin >> A.at(i);
    for(i=0;i<n;i++){
        minj = i;
        for(j=i;j<n;j++){
            if(A.at(j)<A.at(minj)) minj = j;
        }
        if(i != minj){
            swap(A.at(i),A.at(minj));
            count++;
        }
    }
    for(i=0;i<n;i++){
        if(i) cout << " ";
        cout << A.at(i);
    }
    cout << endl << count << endl;
    return 0;
}


Measured memory_bytes: 3108