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

using namespace std;

int n, m;

vector<pair<int,int>> A;

bool cmp(pair<int,int> a, pair<int,int> b) { 
  
  return a.second < b.second; 
}

int main() {
    cin >> n >> m;
  
    A.resize(m);
  
    for (int i = 0; i < m; ++i) cin >> A[i].first >> A[i].second;
  
    sort(A.begin(), A.end(), cmp);
  
    int res = 0;
  
    int temp = 0;
  
    for (int i = 0; i < m; ++i) {
        if (A[i].first >= temp) {
          
            temp = A[i].second;
            ++res;
          
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 1024
while True:
    nyuryoku = []
    tomeru = []
    nyuryoku  = (input().split( ))
    tukau = [int(s) for s in nyuryoku]
    if tukau[0] == 0 and tukau[1] == 0:
        break
    else:
        ans = int(0)
        for a in range(1,tukau[0]+1):
            for b in range(1,tukau[0]+1):
                if b <= a:
                    continue
                c = tukau[1]-(a+b)
                if c > b and c <= tukau[0]:
                    ans += 1
    print(ans)


Measured memory_bytes: 5604
#include<bits/stdc++.h>
#define ll long long
using namespace std;
map<int,bool>mm;
vector<string>v;
int ans[200005];
int main()
{
    mm.clear();
    int n;
    cin>>n;
    int x;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(mm[x])
        {
            printf("NO\n");
            return 0;
        }
        else mm[x]=1;
    }
    printf("YES\n");

}


Measured memory_bytes: 9600
#include<algorithm>
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<string>
#include<math.h>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<cstdio>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	cout<<max(a+b,max(a-b,a*b));
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << endl;
using LL=long long;
using VI=vector<int>;
using VL=vector<long long>;
using VS=vector<string>;
using VVI=vector<vector<int>>;
using PII=pair<int, int>;
const int inf = (int)1e9;
const LL mod = (long long)1e9 + 7;
const double pi = acos(-1.0);

template <class T>void Sort(T & a) { sort(a.begin(), a.end()); }
template <class T>void ReSort(T& a) { sort(a.rbegin(), a.rend()); }
template <class T>void Reverse(T& a) { reverse(a.begin(), a.end()); }
template <class T>void Unique(T& a) { a.erase(unique(a.begin(), a.end()), a.end()); }
template <class T>auto Max(T a) { return *max_element(a.begin(), a.end()); }
template <class T>auto Min(T a) { return *min_element(a.begin(), a.end()); }
template <class T, class U>int Count(T a, U c) { return count(a.begin(), a.end(), c); }
template <class T, class U>U Sum(T a, U init = 0) { return accumulate(a.begin(), a.end(), init); }

//INPUT//
void CINPUT() {}
template <class H, class ...T> void CINPUT(H&& h, T&& ...t) { cin >> h; CINPUT(forward<T>(t)...); }
#define Cin(T,...) T __VA_ARGS__; CINPUT(__VA_ARGS__);
#define VecIn(T,name,n) vector<T> name(n); for(auto &i:name)cin>>i;

//OUTPUT//
void print() { cout << endl; }
template <class H> void print(H&& h) { cout << h << endl; }
template <class H, class... T> void print(H&& h, T&& ... t) { cout << h << " "; print(forward<T>(t)...); }
template <class T>void out(T n) { cout << n << endl; }
template <class T>void out(vector<T> a, string sep = " ", string end = "\n") { for (int i = 0; i < (int)a.size(); ++i)cout << a[i] << (i == (int)a.size() - 1 ? end : sep); }
template <> void out(double a) { printf("%.20f\n", a); }
void yes(bool f) { puts(f ? "yes" : "no"); }
void Yes(bool f) { puts(f ? "Yes" : "No"); }
void YES(bool f) { puts(f ? "YES" : "NO"); }
void Yay(bool f) { puts(f ? "Yay!" : ":("); }

int main() {
	Cin(int, n);
	string s = to_string(n);
	int sum = 0;
	for (auto c : s) {
		sum += c - '0';
	}
	Yes(n % sum == 0);
}

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

using namespace std;

const int maxn=1400;

struct rectangle{
    int height,pos;
};

int getmaxv(int size,int buffer[])
{
    stack<rectangle>S;
    int maxv=0;
    buffer[size]=0;
    for(int i=0;i<=size;i++){
        rectangle rect;
        rect.height=buffer[i];
        rect.pos=i;
        if(S.empty()){
            S.push(rect);
        }else{
            if(S.top().height<rect.height){
                S.push(rect);
            }else if(S.top().height>rect.height){
                int target=i;
                while(!S.empty()&&S.top().height>=rect.height){
                    rectangle pre=S.top();
                    S.pop();
                    int area=pre.height*(i-pre.pos);
                    maxv=max(maxv,area);
                    target=pre.pos;
                }
                rect.pos=target;
                S.push(rect);
            }
        }
    }
    return maxv;
}

int h,w;
int buffer[maxn][maxn];
int t[maxn][maxn];

int solve()
{
    for(int j=0;j<w;j++){
        for(int i=0;i<h;i++){
            if(buffer[i][j]){
                t[i][j]=0;
            }else{
                t[i][j]=(i>0)?t[i-1][j]+1:1;
            }
        }
    }
//    for(int i=0;i<h;i++){
//        for(int j=0;j<w;j++){
//            cout<<t[i][j]<<" ";
//        }
//        cout<<endl;
//    }
    int maxv=0;
    for(int i=0;i<h;i++){
        maxv=max(maxv,getmaxv(w,t[i]));
    }
    return maxv;
}

int main()
{
    scanf("%d%d",&h,&w);
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            scanf("%d",&buffer[i][j]);
        }
    }
    cout<<solve()<<endl;
    return 0;
}



Measured memory_bytes: 18464
def main():
    n = int(input())
    primes = get_primes_less_than(55556)
    out = []
    num = 0
    for prime in primes:
        if prime%5 == 1:
           out.append(prime)
           num += 1
        if n == num:
            print(*out)
            return

def get_primes_less_than(x):
    ans = []
    ap = ans.append
    if x < 3:
        return ans
    if x == 3:
        ap(2)
        return ans
    else:
        for i in range(3, x, 2):
            for j in ans:
                if not i%j:
                    break
            else:
                ap(i)
    return ans
        
if __name__ == "__main__":
    main()

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

int main(){
  int S[11];
  int ans=0;
  char A[11];
  for(int i=0; i<11; ++i){
    A[i]='a';
    S[i]=0;
  }
  for(int i=1; i<11; ++i) cin>>A[i];
  for(int i=1; i<11; ++i){
    if(A[i]=='A') S[i]+=1;
    else if(A[i]=='T') S[i]+=1;
    else if(A[i]=='C') S[i]+=1;
    else if(A[i]=='G') S[i]+=1;
  }
  for(int i=10; i>1; --i){
    if(S[i-1]!=0) S[i-1]+=S[i];
  }
  for(int i=1; i<11; ++i){
    ans=max(ans,S[i]);
  }
  cout<<ans<<endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
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; }
const ll MOD = 1e9+7;

ll N, M, V, P;
vector<ll> A;

bool search(int idx){
    int free = (P-1) + (N-idx);
    int rem = V - free;
    ll sup = A[idx] + M;
    if(sup < A[P-1])
        return false;
    ll num = rem * M;

    for(int i = P-1; i < idx; i++){
        ll a = A[i];
        ll sub = 0;
        chmax(sub, min(M, sup - a));
        num -= sub;
    }

    if(num <= 0) return true;
    else return false;
}

int main(){
    cin >> N >> M >> V >> P;
    A.resize(N);
    REP(i,N){
        cin >> A[i];
    }

    sort(A.rbegin(), A.rend());

    ll ans = 0;

    int left = 0;
    int right = N;
    //int left = 6;
    //int right = 8;
    while(right - left > 1){
        int mid = (left+right)/2;
        bool valid = search(mid);
        if(valid) left = mid;
        else right = mid;
    }

    ans = left+1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
typedef vector<iii> viii;
typedef pair<ll,ll> pll;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef map<int,int> mpii;
typedef map<string,int> mpsi;
typedef set<int> si;
typedef set<ll> sll;
#define pb push_back
#define I insert
#define INF 1000000000
#define LINF (ll)INF*INF
#define all(x) x.begin(),x.end()
#define F first
#define S second
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int k;cin>>k;
	vi rem(k,0);
	queue<int> q;
	for(int i=1;i<=min(9,k);i++)
		q.push(i%k),q.push(i);
	while(!q.empty())
	{
		int r = q.front();q.pop();
		int s = q.front();q.pop();
		rem[r] = s;
		for(int i=0;i<10;i++)
		{
			int rn = (r*10+i)%k;
			int sn = s+i;
		//	cout<<rn<<endl;
			if(rem[rn]<=sn&&rem[rn])
			{
				continue;
			}
			rem[rn] = sn;
			q.push(rn);
			q.push(sn);
		}
	}
	cout<<rem[0]<<endl;
	return 0;
}
/*
	Two roads diverged in a wood, and I—
	I took the one less traveled by,
	And that has made all the difference.
*/

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

int main(int argc, char *argv[]) {
  int N, K;
  scanf("%d %d", &N, &K);
  if (K > 1) {
    printf("%d\n", N - K);
  } else {
    printf("0\n");
  }

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int maxn=1e4+5;
const int maxm=5e2+5;
const int maxq=55;
const int INF=0x3f3f3f3f;
int a[9]={111,222,333,444,555,666,777,888,999};
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        for(int i=0;i<9;i++)
        {
            if(a[i]>=n)
            {
                printf("%d\n",a[i]);
                break;
            }
        }
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
// greater<int>()
typedef long long ll;
ll GCD(ll x, ll y) { return y ? GCD(y, x%y) : x; }
ll LCM(ll x, ll y) { return x * y / GCD(x, y); }

using namespace std;

int main() {
	string s;
	cin >> s;

	map<char, int> mp;
	for (int i = 0; i < s.size(); i++)
	{

		mp[s[i]]++;
	}

	string ans = "yes";
	for (auto v : mp)
	{
		if (v.second > 1) {

			ans = "no";
		}
	}
	cout << ans << endl;




}


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

int main() {
  int n,m;
  cin >> n >> m;
  int L,R,l=0,r=1e9;
  rep(i,m){
    cin >> L >> R;
    if(L>l)
    l=L;
    if(R<r)
    r=R;
  }
  if(l<=r)
  cout << r-l+1 << endl;
  else 
  cout << 0 << endl;
}

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

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    string s, t;
    cin >> s >> t;

    int ans = 0;

    rep (i, s.size())
    {
        if (s[i] != t[i]) ++ans;
    }

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



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


//defines...
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define in insert
#define pi 2*acos(0.0)1
#define srt(s) sort(s.begin(),s.end())
#define all(x) x.begin(),x.end()

const ll mod=1e9+7;
const ll MX=2e5+5;

//code goes from here...



int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);

    freopen("output.txt", "w", stdout);
#endif

    boost
    //---------------------------------
    ll h,w;
    cin >> h >> w;
    if(h==1 || w==1) cout <<  1 <<endl;
    else if((h*w)%2)
    {
        cout << h*w/2+1 << endl;
    }
    else cout << h*w/2 << endl;
    
    //---------------------------------
    
    return 0;
}


Measured memory_bytes: 3608
N=int(input())
S=list(input())
S.insert(0,0)
R=S.count("R")
G=S.count("G")
B=S.count("B")
ans=R*G*B
for i in range(1,N-1):
    for j in range(i+1,N):
        k=2*j-i
        if k<N+1 and S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
            ans-=1
print(ans)
        

        



    









        

    









    

        




    















    



    





    






        






    
















        


























            
    


    


    
    














    


    














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

const int MOD = 1e9 + 7;
int dp[103][103] , h[103] , lsh[103] , N , cl;

int poww(long long a , int b){
	int times = 1;
	while(b){
		if(b & 1) times = times * a % MOD;
		a = a * a % MOD; b >>= 1;
	}
	return times;
}

int main(){
	lsh[++cl] = 1; cin >> N;
	for(int i = 1 ; i <= N ; ++i){cin >> h[i]; lsh[++cl] = h[i];}
	sort(lsh + 1 , lsh + cl + 1); cl = unique(lsh + 1 , lsh + cl + 1) - lsh - 1;
	for(int i = 1 ; i <= N ; ++i) h[i] = lower_bound(lsh + 1 , lsh + cl + 1 , h[i]) - lsh;
	for(int i = 1 ; i <= h[1] ; ++i) dp[1][i] = poww(2 , 1 + lsh[h[1]] - lsh[i]);
	for(int i = 1 ; i <= h[1] ; ++i) dp[1][i] = (dp[1][i] - dp[1][i + 1] + MOD) % MOD;
	for(int i = 1 ; i < N ; ++i)
		if(h[i] >= h[i + 1])
			for(int j = 1 ; j <= h[i] ; ++j)
				dp[i + 1][min(h[i + 1] , j)] = (dp[i + 1][min(h[i + 1] , j)] + 1ll * dp[i][j] * (1 + (j >= h[i + 1]))) % MOD;
		else{
			int pw = poww(2 , lsh[h[i + 1]] - lsh[h[i]]);
			for(int j = 1 ; j < h[i] ; ++j)
				dp[i + 1][j] = 1ll * pw * dp[i][j] % MOD;
			for(int j = h[i] ; j <= h[i + 1] ; ++j)
				dp[i + 1][j] = 2ll * dp[i][h[i]] * poww(2 , lsh[h[i + 1]] - lsh[j]) % MOD;
			for(int j = h[i] ; j <= h[i + 1] ; ++j)
				dp[i + 1][j] = (dp[i + 1][j] - dp[i + 1][j + 1] + MOD) % MOD;
		}
	int sum = 0;
	for(int i = 1 ; i <= cl ; ++i) sum = (sum + dp[N][i]) % MOD;
	cout << sum; return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <set>
using namespace std;
using ll = long long;
    int n,a;
    vector<long long> x(55);
    long long dp[55][55][4000];
int main(void){
    cin >> n >> a;
    for(int i=0;i<n;i++){
        cin >> x[i];
    }
    
    dp[0][0][0]=1;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            for(int k=0;k<3000;k++){
                dp[i+1][j][k] += dp[i][j][k];
                if(k>=x[i]){
                    dp[i+1][j+1][k]+=dp[i][j][k-x[i]];
                }
            }
        }
    }
    
    long long ans=0;
    for(int j=1;j<=n;j++){
        ans+=dp[n][j][j*a];
    }
    cout << ans << endl;
}

Measured memory_bytes: 86528
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdint.h>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);
static const ll MOD = 2019;

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) cout << #x << ": " << x << endl

ll count_[MOD];

void solve(string S) {
  ll cur = 0;
  ll keta = 1;
  count_[0] = 1;
  REP(i, S.size()) {
    cur += (S[S.size() - 1 - i] - '0') * keta;
    cur %= MOD;
    count_[cur]++;
    keta *= 10;
    keta %= MOD;
  }
  ll sum = 0;
  REP(i, MOD) { sum += (count_[i] * (count_[i] - 1)) / 2; }
  cout << sum << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  char S[200001];
  scanf("%s", S);
  solve(string(S));
  return 0;
}


Measured memory_bytes: 3372
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  cin >> N;
  cin >> K;
  
  int number = 1;
  
  for(int i = 0; i < N ; i++){
  	if(2 * number > number + K){
    	number = number + K;
    }else{
    	number = 2 * number;
    }
  }
  
  cout << number << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007


int main()
{
	int n;
	long long int k;
	cin >> n >> k;
	long long int a[200001], f[200001];
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	for(int i = 0; i < n; i++){
		cin >> f[i];
	}
	sort(a, a + n);
	sort(f, f + n);
	reverse(f, f + n);
	long long int l = -1, r = a[n - 1] * f[0] + 1;
	while(r - l > 1){
		long long int mid = (l + r) / 2;
		long long int need = 0;
		// cout << mid << endl;
		for(int i = 0; i < n; i++){
			long long int ll = -1, rr = a[i];
			while(rr - ll > 1){
				long long int mm = (ll + rr) / 2;
				if((a[i] - mm) * f[i] <= mid) rr = mm;
				else ll = mm;
			}
			// cout << a[i] << " " << f[i] << " " << rr << endl;
			need += rr;
		}
		if(need <= k) r = mid;
		else l = mid;
	}
	cout << r << endl;
}



Measured memory_bytes: 3456
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
#define MAXN 100100
int n, m, k, ans;
int main()
{
	scanf("%d%d%d",&k,&n,&m);
	ans = (n+k-1)/k * k;
	if(ans <= m) printf("OK\n");
	else printf("NG\n");
	
	return 0;
}

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

#define PI 3.14159265359

int main() {
  int X, N;
  cin >> X >> N;
  int p;
  vector<bool> forbidden(102);
  int ans = 0;
  int diff = X * -1;
  for (int i = 0; i < N; i++){
    cin >> p;
    forbidden[p] = true;
  }
  for (int i = 1; i < 102; i++){
    if (!forbidden[i]){
      if (abs(diff) > i - X){
        ans = i;
        diff = i - X;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3628
import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 998_244_353

@njit((i8, i8[:]), cache=True)
def main(N, LR):
    L, R = LR[::2], LR[1::2]
    K = len(L)
    F = np.zeros(N + 10, np.int64)
    F[0] = 1
    for n in range(1, N + 10):
        F[n] += F[n - 1]
        for k in range(K):
            l, r = L[k], R[k] + 1
            if n - l >= 0:
                F[n] += F[n - l]
            if n - r >= 0:
                F[n] -= F[n - r]
        F[n] %= MOD
    ans = F[N - 1] - F[N - 2]
    return ans % MOD

N, K = map(int, readline().split())
LR = np.array(read().split(), np.int64)

print(main(N, LR))

Measured memory_bytes: 107908
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		new Main().run();
	}
	char[][] map;
	public void run(){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			String str = scan.nextLine();
			if(str.equals("")){
				continue;
			}
			map = new char[12][];
			map[0] = str.toCharArray();
			for(int i = 1;i < 12;i++){
				map[i] = scan.nextLine().toCharArray();
			}
			int count = 0;
			for(int i = 0;i < 12;i++){
				for(int j = 0;j < 12;j++){
					if(map[i][j] == '1'){
						count++;
						checkMap(i,j);
					}
				}
			}
			System.out.println(count);
		}
	}
	public void checkMap(int i,int j){
		if(map[i][j] == '0'){
			return;
		}
		map[i][j] = '0';
		int[] dx = {-1,1,0,0};
		int[] dy = {0,0,-1,1};
		for(int k = 0;k < 4;k++){
			if(i+dy[k] >= 0 && i+dy[k] < 12 && j+dx[k] >= 0 && j+dx[k] < 12){
				checkMap(i+dy[k],j+dx[k]);
			}
		}
		return;
	}
}

Measured memory_bytes: 17392
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define mod 1000000007
#define ff first
#define ss second
#define vi vector<int>
#define pii pair<int, int>
#define pb push_back
#define vll vector<ll>
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define f(i, n) for(int i=0; i<n; ++i)
#define rep(i, a, b) for(int i=a; i<=b; i++)
#define repd(i, a, b) for(int i=a; i>=b; i--)
#define MAXN 200001
#define umapi unordered_map<int, int>
#define umapll unordered_map<ll, ll> 
 
 
int add(int a, int b)
{
    int temp=a+b;
    if(temp<0)
        temp=mod+temp;
    else if(temp>mod)
        temp=temp%mod;
    return temp;
}
 
int mul(int a, int b)
{
    ll temp=(1ll*a*b);
    if(temp<0)
        temp=mod+temp;
    else if(temp>=mod)
        temp=temp%mod;
    return temp;
}

bool perfect(int x)
{
    if(x<0)
        return false;
    if(x==0)
        return true;
    int temp=sqrt(x);
    return (temp*temp)==x;
}

ll dp[MAXN];


ll cost(int* A, int n, int k, int curr)
{
    if(dp[curr]!=10000000001)
        return dp[curr];
    if(curr>n)
        return 10000000001;
    if(curr==n)
        return 0;

    dp[curr]=10000000001;
    rep(i, 1, k)
        dp[curr]=min(dp[curr], abs(A[curr]-A[curr+i])+cost(A, n, k, curr+i));
    return dp[curr];
}

 
void solve()
{   
    int n, A[MAXN], k; cin>>n>>k;
    f(i, n)
        cin>>A[i+1];
    f(i, n)
        dp[i+1]=1000000001;

    dp[1]=0;

    rep(i, 2, n)
    {
        rep(j, 1, k)
        {
            if(i==2)
                dp[i]=abs(A[i]-A[i-1])+dp[i-1];
            else if(i-j>=1)
                dp[i]=min(dp[i], abs(A[i]-A[i-j])+dp[i-j]);
        }
    }
    //ll ans=cost(A, n, k, 1);
    ll ans=dp[n];
    printf("%lld\n", ans);
}
 

void io()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}
 
 
int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    //io();
    
    //int t; cin>>t; 
    int tc=0;
    //while(t--)
    {
        tc++;
        //printf("Case #%d: ", tc); 
        solve();
    }  
    return 0;
}

Measured memory_bytes: 1408
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 998244353;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	int a, b, c, d;
	scanf("%d %d %d %d", &a, &b, &c, &d);
	
	ll dp[c+1][d+1];
	dp[a][b] = 1;
	REP(j, b+1, d+1) dp[a][j] = dp[a][j-1] * a % MOD;
	REP(i, a+1, c+1) dp[i][b] = dp[i-1][b] * b % MOD;

	REP(i, a+1, c+1){
		REP(j, b+1, d+1){
			dp[i][j] = (dp[i-1][j]*j%MOD + dp[i][j-1]*i%MOD) % MOD;
			dp[i][j] -= dp[i-1][j-1]*(i-1)%MOD * (j-1)%MOD;
			if(dp[i][j]<0) dp[i][j] += MOD;
		}
	}

	printf("%ld\n", dp[c][d]);
	return 0;
}







Measured memory_bytes: 73924
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main() {
	int n;
	cin >> n;
	if (n >= 400 && n < 600) {
		cout << 8;
	}
	else if (n >= 600 && n < 800) {
		cout << 7;

	}
	else if (n >= 800 && n < 1000) {
		cout << 6;
	}
	else if (n >= 1000 && n < 1200) {
		cout << 5;
	}
	else if (n >= 1200 && n < 1400) {
		cout << 4;
	}
	else if (n >= 1400 && n < 1600) {
		cout << 3;
	}
	else if (n >= 1600 && n < 1800) {
		cout << 2;
	}
	else if (n >= 1800 && n < 2000) {
		cout << 1;
	}

}

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

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var N = int.Parse(Console.ReadLine());
			long power = 1;
			for (int i = 1; i <= N; i++)
			{
				power *= i;
				power %= (long)(Math.Pow(10, 9) + 7);
			}
			Console.WriteLine(power);
		}
	}
}


Measured memory_bytes: 11220
# -*- coding: utf-8 -*-
"""
Binary Search - Equal Range
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_6_D&lang=jp

"""
from bisect import bisect_left, bisect_right

n = int(input())
A = [int(a) for a in input().split()]
for _ in range(int(input())):
    k = int(input())
    print(bisect_left(A, k), bisect_right(A, k))



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

typedef long long ll;

constexpr ll MAX = 5000000;
constexpr ll MOD = 1000000007;
// fac[i] = i!;
// facinv[i] = (i!)^-1 (mod MOD)

constexpr ll extgcd(ll a, ll b, ll &x, ll &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  // ll d = extgcd(b, a % b, x, y);
  // ll temp = x;
  // x = y;
  // y = temp - (a / b) * x;
  ll d = extgcd(b, a % b, y, x);
  y -= (a / b) * x;
  return d;
}

constexpr ll modinv(ll a, ll m) {
  // Need: gcd(a, m) = 1;
  // a^-1(mod. m)は
  // ax+my=gcd(a, m)=1;
  // を満たすxである。(それはそう,両辺をmodを法としてmodを考えてみよう)
  ll x = 0, y = 0;
  extgcd(a, m, x, y);
  return (x % m + m) % m;
}

template <int N> struct ComCalc {
  long long fac[N + 1];
  long long facinv[N + 1];

  constexpr ComCalc() {
    fac[0] = 1;
    for (int i = 1; i <= N; i++) {
      fac[i] = fac[i - 1] * i % MOD;
    }
    facinv[N] = modinv(fac[N], MOD);
    for (int i = N; i >= 1; i--) {
      facinv[i - 1] = facinv[i] * i % MOD;
    }
  }

  ll comb(ll n, ll r) {
    return (fac[n] * facinv[r]) % MOD * facinv[n - r] % MOD;
  }
};

int main() {
  auto calc = ComCalc<MAX>();
  ll x, y;
  cin >> x >> y;
  if ((2 * x - y) % 3 != 0) {
    cout << 0 << endl;
    return 0;
  }
  if ((2 * y - x) % 3 != 0) {
    cout << 0 << endl;
    return 0;
  }
  ll a = (2 * x - y) / 3;
  ll b = (2 * y - x) / 3;
  if (a < 0 || b < 0) {
    cout << 0 << endl;
    return 0;
  }
  a %= MOD;
  b %= MOD;
  cout << calc.comb((a + b) % MOD, a) << endl;
}


Measured memory_bytes: 78336
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,i,s=0;
    cin>>n;
    int a[n],b[n],c[n];
    for(i=0;i<n;i++)
    cin>>a[i]>>b[i]>>c[i];
    for(i=1;i<n;i++)
    {
        a[i]=a[i]+max(b[i-1],c[i-1]);
        b[i]=b[i]+max(a[i-1],c[i-1]);
        c[i]=c[i]+max(a[i-1],b[i-1]);
    }
    s=max(a[n-1],max(b[n-1],c[n-1]));
    
    cout<<s<<"\n";
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;
typedef pair<ll  ,ll > pll;

const ll maxn =2e6+5;
const ll mod = 1e9+7;
const ld PI = 4 * atan((ld) 1);

#define pb(x) push_back(x);
#define endl '\n'
#define dokme(x) cout << x ;  return(0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
#define ms(x , y) memset(x , y , sizeof x);
ll pw(ll a, ll b) {
    return (!b ? 1 : (b & 1 ? a * pw(a * a % mod, b / 2) % mod : pw(a * a % mod, b / 2) % mod));
}

ll n;
ll a[maxn];
ll num[maxn];

int main(){
    migmig
    ms(num , 0);
    cin >> n;
    for (int i = 1 ; i <= n ; i ++){
        cin >> a[i];
        ll boz = a[i];
        for (int j = 2; j*j<=boz ; j ++){
            if(boz%j == 0){
                ll mx = 0;
                while(boz%j == 0){
                    boz/=j;
                    mx++;
                }
                num[j] = max(num[j] , mx);
            }
        }
        if(boz>1){
            num[boz] = max(num[boz] , (ll)1);
        }
    }
    ll ans = 0;
    ll lcm = 1;
    for (int i = 0 ; i <= 1e6 ; i ++){
        if(num[i]){
            lcm*=pw(i , num[i]);
            lcm%=mod;
        }
    }
    for (int i = 1 ; i <= n ; i ++){
        ans+=lcm*pw(a[i] , mod - 2);
        ans%=mod;
    }
    cout << ans;
    return(0);
}


//When we hit our lowest point, we are open to the greatest change.
//If I try, I fail. If I don't try, I'm NEVER GOING TO GET IT.
//Sometimes, life is like this dark tunnel. You can't always see the light at the end of the tunnel. But if you just keep moving... you will come to a better place.
//It is important to draw wisdom from diffrent places. If you take it from only one place it becomes rigid and stale.


Measured memory_bytes: 16768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
int main(void){
    int x; cin>>x;
    if(x==1){
        cout<<0<<endl;
    }else{
        cout<<1<<endl;
    }
    
}


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

int main(){

	int n;
	int a[1000];
	
	cin>>n;
	int i;
	for(i=0; i<=n; i=i+1)
	{cin>>a[i];}
	
	int j;
	for(j=n-1; j>-1; j=j-1)
	{cout<<a[j];
	
		if(j>0){cout<<" ";}
		if(j==0){cout<<endl;}
	
}
}



Measured memory_bytes: 3092
import heapq
N,M = map(int , input().split(" "))
A = list(map(int, input().split(" ")))

A_q = list(map(lambda x:x*(-1),A))
heapq.heapify(A_q)

for i in range(M):

    max = heapq.heappop(A_q) * (-1) // 2
    heapq.heappush(A_q, -max)



result = 0
A_q = list(map(lambda x:x*(-1),A_q))

for i in range(N):
    result += A_q[i]

print(result)

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

int main()
{
    string s;
    cin >> s;

    map<char, int> M;
    rep(i, s.length()) M[s[i]]++;

    int cnt1 = MOD;
    for (auto m : M)
    {
        char c = m.first;
        int cnt2 = 0, cnt3 = 0;
        rep(i, s.length())
        {
            if (s[i] == c)
            {
                cnt2 = max(cnt2, cnt3);
                cnt3 = 0;
            }
            else
            {
                cnt3++;
            }
        }
        cnt2 = max(cnt2, cnt3);
        cnt1 = min(cnt1, cnt2);
    }

    cout << cnt1 << endl;
}

Measured memory_bytes: 3576
import java.util.Scanner;

public class Main {
	
	public long solve(long N, long X) {
		long longEdge = Math.max(X, N-X);
		long shortEdge = Math.min(X, N-X);
		
		long length = X + N - X;

		// 短編shortEdge, 長編longEdgeの平行四辺形の中を反射する距離を求める
		while (shortEdge > 0) {
			long num = longEdge / shortEdge;
			length += (shortEdge * num * 2);

			// num * 2回反射して、longEdge - shortEdge * numが残る
			long left = longEdge - (shortEdge * num);
			longEdge = shortEdge;
			shortEdge = left;
		}
		
		// 1回分行き過ぎるので、戻す
		length -= longEdge;
		
		return length;
	}
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long N = in.nextLong();
		long X = in.nextLong();
		in.close();
		
		Main main = new Main();
		long result = main.solve(N, X);
		
		System.out.println(result);
	}
}

Measured memory_bytes: 23636
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
 if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  string s;
  cin>>s;
  if(s[1]=='B') COUT("ARC");
  else COUT("ABC");
}

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

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 rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<vector<int>>;

int main(){
    int N,X,T; cin>>N>>X>>T;
    cout<<((N-1)/X+1)*T<<endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define pb push_back
#define MOD 1000000007
#define sz5 100005
#define sz6 1000005
#define UP upper_bound
#define LB lower_bound
#define F first
#define S second
#define PI pair<int,int>
#define PL pair<ll,ll>
#define VI vector<int>
#define VL vector<ll>


int main() {
    FAST

    #ifndef ONLINE_JUDGE
        // freopen("in", "r", stdin);
        // freopen("out", "w", stdout);
    #endif

    ll n,w,la,lb;
    cin>>n>>w;
    ll v[n+2], wt[n+2];
    for(la=1;la<=n;la++)
        cin>>wt[la]>>v[la];

    ll dp[w+2][n+3];
    memset(dp, 0, sizeof(dp));
    for(la=1;la<=w;la++){
        for(lb=1;lb<=n;lb++){
            dp[la][lb]=max(dp[la-1][lb], dp[la][lb-1]);
            if(la>=wt[lb])
            dp[la][lb]=max(dp[la][lb], v[lb]+dp[la-wt[lb]][lb-1]);
        }
    }

    // for(la=0;la<=w;la++){
    //     for(lb=0;lb<=n;lb++)
    //         cout<<dp[la][lb]<<' ';
    //     cout<<endl;
    // }

    cout<<dp[w][n]<<endl;
    return 0;
}

Measured memory_bytes: 84060
#include<stdio.h>
#include<string.h>

int main(void)
{
  int A,B,ke5,ke1,ke4,ke2,i;
  int cnt=0;
  int tmp[100];
  
  scanf("%d %d",&A,&B);
  
  for(i=A;i<=B;i++){
   ke5 = i/10000;
   ke1 = i%10;
   if(ke5==ke1){
    ke4 = (i/1000)%10;
    ke2 = (i/10)%10;
    if(ke4==ke2){
      tmp[cnt]=i;
      cnt++;
    }
   }     
  }
  
  printf("%d\n",cnt);
  
  return 0; 
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <cstdlib>

using namespace std;

int main(){

	long long  a, b, c, x, y;
	long long  need=0, api=0, bpi=0;
	cin >> a >> b >> c >> x >> y;
	if( (a+b)  <= c * 2 ){
		while( (api<x) && (bpi<y) ){
			need += a + b;
			api++;
			bpi++;
		}
	}
	else{
		while( (api<x) && (bpi<y) ){
			need += c*2;
			api++;
			bpi++;
		}
	}


	if( bpi < y ){  //つまりbが足りていない
		if( c < b/2 ){
			need += c*2*(y-bpi);
		}
		else{
			need += b*(y-bpi);
		}
	}

	else if( api < x ){  //つまりaが足りていない
		if( c < a/2 ){
			need += c*2*(x-api);
		}
		else{
			need += a*(x-api);
		}
	}
	cout << need <<endl;


	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>

using ll = long long;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, x) for(int i=1;i<=(int)(x);i++)
#define rrep(i, x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i, x) for(int i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007

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

using namespace std;


struct UnionFind {
    vector<int> rank, parent;

    UnionFind() {}

    UnionFind(int size) {
        rank.resize(size, 0);
        parent.resize(size, 0);
        for (int i = 0; i < size; ++i) {
            makeSet(i);
        }
    }

    void makeSet(int x) {
        parent[x] = x;
        rank[x] = 0;
    }

    void link(int x, int y) {
        if (rank[x] < rank[y]) {
            parent[x] = y;
        } else {
            parent[y] = x;
            if (rank[x] == rank[y]) rank[x]++;
        }
    }

    bool same(int x, int y) {
        return findSet(x) == findSet(y);
    }

    void unite(int x, int y) {
        link(findSet(x), findSet(y));
    }

    int findSet(int x) {
        if (parent[x] != x) {
            parent[x] = findSet(parent[x]);
        }
        return parent[x];
    }
};

int p[100000];
int x[100000];
int y[100000];

int main() {
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    rep(i, n) {
        cin >> p[i];
    }
    rep(i, m) {
        cin >> x[i] >> y[i];
        uf.unite(x[i] - 1, y[i] - 1);
    }
    int ans = 0;
    rep(i, n) {
        if (uf.same(p[i] - 1, i)) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 2176
#define ll long long
#define pi acos(-1.0)
#define Go "\n"
#define Afor(i,a,b) for( i=a;i<b;i++)
#define GCD __gcd
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll,ll>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i;
    cin>>n;
    pll a[n];

    Afor(i,0,n)
    {
        cin>>a[i].ff;
        a[i].ss=i;
    }
    sort(a,a+n);
        Afor(i,0,n)
    {
        cout<<a[i].ss+1<<" ";
    }
    cout<<"\n";


}


Measured memory_bytes: 5148
//31
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  for(int n,t;cin>>n>>t,n|t;){
    static double p[2001][2000];
    fill(p[0],p[t+1],0);
    p[0][0]=1;
    for(int i=0;i<t;i++){
      for(int j=0;j<n;j++){
	for(int k=1;k<=6;k++){
	  p[i+1][(j+k)%n]+=p[i][j]/6;
	}
      }
    }
    char c[2001];
    cin>>c;
    double mp=0;
    for(int i=0;i<n;i++){
      double cp=0;
      for(int j=0;j<n;j++){
	if(c[(i+j)%n]=='R'){
	  cp+=p[t][j];
	}
      }
      if(cp>mp){
	mp=cp;
      }
    }
    cout.precision(8);
    cout<<fixed<<mp<<endl;
  }
  return 0;
}

Measured memory_bytes: 32508
n = int(input())
a = [int(input()) for _ in range(n)]
if 2 not in a:
    print(-1)
    quit()
else:
    s = 1
    count = 0
    while count <= n:
        s = a[s-1]
        count += 1
        if s == 2:
            print(count)
            quit()
print(-1)

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

namespace AizuOnlineJudge
{
    class Program
    {
        static void Main(string[] args)
        {
            while(true)
            {
                var arr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                if (arr[0] == 0 && arr[1] == 0) break;

                var s = string.Join("", Enumerable.Repeat("#", arr[1]));
                Console.WriteLine(string.Join("\n", Enumerable.Repeat(s, arr[0])));

                Console.WriteLine();
            }
        }
    }
}



Measured memory_bytes: 18460
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <string.h>
using namespace std;
typedef long long ll;

//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(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 SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく

//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

using namespace std;

int main(void){
 
  ll n;
  cin >> n;
  if( n >= 30 ){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3592
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

vector<vector<int>>vec;
int n;
vector<int>color;
void bsf(int s, int c) {
	queue<int>q;
	q.push(s);
	color[s] = c;
	while (!q.empty()) {
		int u = q.front(); q.pop();
		rep(v, 0, vec[u].size()) {
			if (color[vec[u][v]] != -1)continue;
			color[vec[u][v]] = c;
			q.push(vec[u][v]);
		}
	}
}
void assignColor() {
	rep(i, 0, n) {
		if (color[i] == -1)bsf(i, i);
	}
}

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

	cin >> n;
	vec = vector<vector<int>>(n);
	color = vector<int>(n, -1);
	int K, L; cin >> K >> L;
	rep(i, 0, K) {
		int p, q; cin >> p >> q; p--, q--;
		vec[p].push_back(q);
		vec[q].push_back(p);
	}
	assignColor();
	vector<int>road = color;
	color = vector<int>(n, -1);
	vec = vector<vector<int>>(n);
	rep(i, 0, L) {
		int r, s; cin >> r >> s; r--, s--;
		vec[r].push_back(s);
		vec[s].push_back(r);
	}
	assignColor();
	vector<int>rail = color;

	dump(road); dump(rail);

	map < pair<int, int>, int>ans;
	rep(i, 0, n)ans[make_pair(road[i], rail[i])]++;
	rep(i, 0, n)cout << ans[make_pair(road[i], rail[i])] << (i == n - 1 ? '\n' : ' ');


	return 0;
}

Measured memory_bytes: 21052
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<deque>
#include<sstream>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<bitset>
#include<time.h>
#include<cstdlib>
#include<cassert>
#define ll long long
#define fi first
#define se second
using namespace std;

int dx[]={1,0,-1};
int dy[]={1,0,-1};
int w,h;
char a[100][100];

inline int check(int y,int x){
  if(a[y][x]=='#')return 100;
  int ans=0;
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      if(i==1 && j==1)continue;
      if(y+dy[i]<0)continue;
      if(y+dy[i]>=h)continue;
      if(x+dx[j]<0)continue;
      if(x+dx[j]>=w)continue;
      if(a[y+dy[i]][x+dx[j]]=='#')ans++;
    }
  }
  return ans;
}
                   
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin); 
    freopen("out","w",stdout);
#endif
  cin>>h>>w;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>a[i][j];
    }
  }
  int ans[100][100];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      ans[i][j]=check(i,j);
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(ans[i][j]==100)cout<<'#';
      else cout<<ans[i][j];
    }
    cout<<endl;
  }
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    i64 N, K; cin >> N >> K;
    using P = pair<i64, i64>;
    vector<P> sushi(N);
    unordered_map<i64, i64> dist;
    REP(i, N) {
        i64 t, d; cin >> t >> d;
        sushi[i] = {d, t};
    }

    sort(sushi.begin(), sushi.end(), greater<P>());
    unordered_set<i64> types;
    i64 sv = 0;
    i64 st = 0;
    REP(i, K) {
        sv += sushi[i].first;
        types.insert(sushi[i].second);
        dist[sushi[i].second]++;
    }
    st = types.size();

    auto score = [](i64 sv, i64 st) {
        return sv + st * st;
    };

    i64 maxs = score(sv, st);
    i64 discard = K - 1;
    for (i64 i = K; i < N; i++) {
        if (dist[sushi[i].second] >= 1) continue;
        while (dist[sushi[discard].second] == 1) discard--;
        if (discard < 0) break;
        // discard
        dist[sushi[discard].second]--;
        sv -= sushi[discard].first;
        discard--;

        // add
        dist[sushi[i].second]++;
        sv += sushi[i].first;
        st++;

        // update
        chmax(maxs, score(sv, st));
    }

    cout << maxs << endl;

    return 0;
}

Measured memory_bytes: 7704