akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int INF=1<<29;
ll mod=1000000007;

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

	string s;
	cin>>s;
	int size=s.size();
	char arr[size];
	for(int i=0;i<size;i++) arr[i]=s[i];

	vector<char> tmp;
	bool left=false,right=false;
	for(int i=0;i<size+1;i++){
		if( (left && right && arr[i]=='R') || i==size){
			if(tmp.size()%2==0){
				for(int j=0;j<tmp.size();j++){
					if( j+1<tmp.size() && tmp[j]=='R' && tmp[j+1]=='L') cout<<tmp.size()/2<<" ";
					else if( j-1>=0 && tmp[j]=='L' && tmp[j-1]=='R') cout<<tmp.size()/2<<" ";
					else cout<<0<<" ";
				}
			}else{
				int big=max(count(tmp.begin(),tmp.end(),'R'),count(tmp.begin(),tmp.end(),'L'));
				int r=count(tmp.begin(),tmp.end(),'R'),l=count(tmp.begin(),tmp.end(),'L');
				int sm=tmp.size()/2,bi=(tmp.size()+1)/2;
				if((big-1)%2==0){
					for(int j=0;j<=r-1;j++){
						if(j==r-1){
							if(r>l) cout<<bi<<" ";
							else cout<<sm<<" ";
						}else cout<<0<<" ";
					}
					for(int j=r;j<tmp.size();j++){
						if(j==r){
							if(r>l) cout<<sm<<" ";
							else cout<<bi<<" ";
						}
						else cout<<0<<" ";
					}
				}else{
					for(int j=0;j<=r-1;j++){
						if(j==r-1){
							if(r>l) cout<<sm<<" ";
							else cout<<bi<<" ";
						}else cout<<0<<" ";
					}
					for(int j=r;j<tmp.size();j++){
						if(j==r){
							if(r>l) cout<<bi<<" ";
							else cout<<sm<<" ";
						}else cout<<0<<" ";
					}
				}
			}
			tmp.clear();
			left=false;
			right=false;
		}
		tmp.push_back(arr[i]);
		if(arr[i]=='L') left=true;
		if(arr[i]=='R') right=true;
	}
	return 0;
}

Measured memory_bytes: 848
import bisect

n=int(input())
l=list(map(int,input().split()))

l.sort()
ans=0

for i in range(n-2):
    for j in range(i+1,n-1):
        right=bisect.bisect_left(l,l[i]+l[j])
        left=j+1
        ans += right -left

print(ans)

Measured memory_bytes: 3188
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AOJ
{
	class Program
	{
		static void Main(string[] args)
		{
			var r = 0L;
			var n = int.Parse(Console.ReadLine());
			for (int i = 0; i < n; i++)
			{
				r += long.Parse(Console.ReadLine());
			}
			Console.WriteLine("{0}", r / n);
		}
	}
}

Measured memory_bytes: 5656
use v5.18; # strict say state
use warnings;
use List::Util qw(reduce first max min sum0);

my ($h, $w, $wa, $hb) = split / /, <STDIN>;

for my $i (0..$h-1) {
  for my $j (0..$w-1) {
    if (($i<$hb && $j<$wa) || ($i>=$hb && $j>=$wa)) {
      print 0;
    } else {
      print 1;
    }
  }
  say "";
}

Measured memory_bytes: 1792
inputs =  list(map(int, input().split()))

N = inputs[0]
T = inputs[1]

best = 9999

for i in range(N):
    inputs = list(map(int, input().split()))
    if(best >= inputs[0]):
        if(T >= inputs[1]):
            best = inputs[0]

if best != 9999:
    print(best)
else:
    print("TLE")

Measured memory_bytes: 3060
#include <stdio.h>

int main(){
    
    int a,b;
    
    scanf("%d %d", &a, &b);
    
    if(a != b){
        printf("a %c b\n", (a<b)?'<':'>');
    }else{
        printf("a == b\n");
    }
    
    return 0;
}

Measured memory_bytes: 2680
# 2, 0
n, k = gets.split.map &:to_i # N本の木。K本選ぶ。
# p [n,k]
x = [] # 木の高さ
while xx = gets
  x << xx.to_i
end
x.sort! # logM
mini = 10**9
(x.size-k+1).times do |i| # N
  mini = [mini,x[i+k-1] - x[i+0]].min
end

p mini


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

using namespace std;

#define PB push_back
#define MP make_pair
#define FOR( i , n ) for( int i = 0; i < (n); i++ )
#define FORR( i , n ) for( int i = ( n - 1 ); i >= 0 ; i-- )
#define DB( x ) cout << #x << " = " << x << endl;
#define OUT( a , n ) for( int J = 0; J < (n); J++ )cout<< (a)[J] << " \n"[J == (n) - 1 ]
#define WAIT cout << flush , system("PAUSE");
#define CONTAINS(a, x) ((a).find(x) != (a).end())
#define endl '\n'

typedef pair<int, int> pii;

#define y1 _jsdbgdg4095345

const int N = 2e6 + 100;

const double pi = 2 * acos(0);
double fee = 20.0 - 2 * pi * 10 / 4.0;

int x1 , y1 , x2 , y2;
int n;


int s[N];

int t[N];

void add(int i, int x){
	for(; i < N;  i+= (i & -i)){
		t[i]  = max(t[i] , x);
	}
}

int query(int i){
	int ans = 0;
	if(i <= 0)return 0;
	for(; i > 0; i-= (i & -i)){
		ans = max(ans , t[i]);
	}
	return ans;
}

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


	scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
	scanf("%d", &n);

	if(x1 > x2){
		swap(x1 , x2);
		swap(y1 , y2);
	}

	vector<pii> pnts;
	vector<int> aint;

	for( int i = 0; i < n; i++ ){
		int a , b;
		scanf("%d %d", &a, &b);
		if(a >= x1 && a <= x2 && b >= min(y1, y2) && b <= max(y1, y2)){
			aint.push_back(b);
			pnts.push_back({a , b});
		}
	}

	sort(aint.begin() , aint.end());
	sort(pnts.begin(), pnts.end());

	for( int i = 0; i < (int)pnts.size(); i++){
		pnts[i].second= lower_bound(aint.begin(), aint.end(), pnts[i].second) - aint.begin() + 1;
	}

	int sz = pnts.size();

	for( int i = 0; i < sz; i++){
		s[i] = pnts[i].second;
	}


	if(y1 > y2){
		reverse(s , s + sz);
	}


	int dist= abs(x1 - x2) + abs(y1 - y2);

	int ans = 0;
	for( int i = 0; i < sz; i++ ){
		int y = s[i];
		int q = query(y) + 1;
		add(y, q);
	}

	ans = query(N - 1);

	double sol = 1LL * dist * 100 - ans * fee;

	if(ans == min(abs(y2 - y1), abs(x1 - x2)) + 1){
			sol += 2 * pi * 10.0 / 4.0;
	}


	printf("%.18lf\n", sol);


	return 0;
}


Measured memory_bytes: 11880
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
const ll mod=1000000007;
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)

int main() {
  int n;cin>>n;
  vector<int> v(n),p(n),q(n);
  for(int i=0;i<n;++i) v[i] = i+1;
  for(int i=0;i<n;++i) cin>>p[i];
  for(int i=0;i<n;++i) cin>>q[i];
  int idp =-1,idq=-1,id=0;
  do {
    bool isp = true,isq = true;
    for(int i=0;i<n;++i){
      if(v[i]!=p[i]) isp = false;
      if(v[i]!=q[i]) isq = false;
    }
    if(isp) idp = id;
    if(isq) idq = id;
    if(idq>-1&&idp>-1)break;
    ++id;
  } while (next_permutation(v.begin(), v.end()));
  cout << abs(idp-idq) << endl;
  return 0;
}


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

using namespace std;

int main(){
  int x,a,b;
  long long num;
  cin >> x;

  for(int i=-118; i<=119;i++){
    for(int j=-119; j<=118;j++){
      num = pow(i,5)-pow(j,5);
      if(num==x) {
        a=i;
        b=j;
      }
    }
  }

  cout << a << " " << b << endl;
  return 0;
}


Measured memory_bytes: 4092
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    a = list(map(int, input().split()))
    ans = [0 for _ in range(n)]

    for index, ai in enumerate(a):
        if index % 2 == 0:
            ans[0] += ai
        else:
            ans[0] -= ai

    for i in range(n - 1):
        ans[i + 1] = 2 * a[i] - ans[i]

    print(' '.join(map(str, ans)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 19144
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#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 fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
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;}
const int P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;



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

    int n;
    cin>>n;
    vi v(n);
    rep(i,n)cin>>v[i];
    Sort(v);
    ll ans=0;
    int l=v[n-1],r=0;
    for(int i=0;i<n-1;i++){
        if(abs((double)l/2-v[i]) < abs((double)l/2-r)){
            r=v[i];
        }
    }
    cout<<l<<" "<<r<<endl;

//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
int main(){
string S;
  cin>>S;
  if(S=="Sunny")
    cout<<"Cloudy"<<endl;
  if(S=="Cloudy")
    cout<<"Rainy"<<endl;
  if(S=="Rainy")
    cout<<"Sunny"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF 1e9
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
template <class T> void chmax(T & a, T const & b) { if (b > a) a = b; }
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = LLONG_MAX;

int a,b;
int ans;
int main(){
  cin >>a>>b;
  for(int i=a;i<=b;i++){
    string s = to_string(i);
    bool flag=false;
    for(int i=0;i<(s.size()-1)/2;i++){
      if(s[i]!=s[s.size()-i-1])flag=true;
    }
    if(!flag)ans++;

  }
  cout<<ans<<endl;

}


Measured memory_bytes: 256
/* Code by Saborit */
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast") 
#define MX 200005
#define INF (1<<30)
#define EPS 1e-9
#define MOD 1000000007
#define mid (x+xend)/2
#define izq nod*2
#define der nod*2+1
#define fr first
#define sc second
#define pb push_back
#define mp make_pair
#define all(X) (X).begin(), (X).end()
#define unique(X) (X).resize(unique(all(X)) - (X).begin())
#ifdef LOCAL 
	#include "debug.h"
#endif
using namespace std;
using namespace __gnu_pbds;
typedef long long int64;
typedef unsigned long long unt64;

int N, L;
int A[MX];

int main(void){
    //~ freopen("a.in", "r", stdin);
    //~ freopen("a.out", "w", stdout);
    
    scanf("%d%d", &N, &L);
    for(int i=1; i<=N; i++)
		scanf("%d", &A[i]);
    
    for(int i=1; i < N; i++){
		if( A[i] + A[i+1] >= L ){
			printf("Possible\n");
			for(int j=1; j < i; j++)
				printf("%d\n", j);
			for(int j=N-1; j > i; j--)
				printf("%d\n", j);
			printf("%d\n", i);
			
			return 0;
		}	
	}
	printf("Impossible\n");
    
   return 0;
}


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

int main() {
	int n;
	while(cin >> n, n) {
		long long ans = 0;
		for(int i = 0; i < n; i++) {
			int x, y, h, w;
			cin >> x >> y >> h >> w;

			int a = x + y + h;
			if(a <= 60 && w <= 2)
				ans += 600;
			else if(a <= 80 && w <= 5)
				ans += 800;
			else if(a <= 100 && w <= 10)
				ans += 1000;
			else if(a <= 120 && w <= 15)
				ans += 1200;
			else if(a <= 140 && w <= 20)
				ans += 1400;
			else if(a <= 160 && w <= 25)
				ans += 1600;
		}

		cout << ans << endl;
	}
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)
#define ALL(x) x.begin(),x.end()
#define fs first
#define sd second
#define couts(x) cout << (x) << (" ")
#define coutn(x) cout << (x) << ("\n")
#define endl "\n"
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T1, typename T2> std::istream &operator>>(std::istream &is, std::pair<T1,T2> &p){is >> p.first >> p.second; return is; }
template<typename T> std::ostream &operator<<(std::ostream &os, const std::vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> std::ostream &operator<<(std::ostream &os, const std::deque<T> &vec){ os << "deque["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> std::ostream &operator<<(std::ostream &os, const std::set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> std::ostream &operator<<(std::ostream &os, const std::unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> std::ostream &operator<<(std::ostream &os, const std::multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> std::ostream &operator<<(std::ostream &os, const std::unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> std::ostream &operator<<(std::ostream &os, const std::pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> std::ostream &operator<<(std::ostream &os, const std::map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> std::ostream &operator<<(std::ostream &os, const std::unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }

template<class T> using V = vector<T>;
template<class T> using V2 = V<V<T>>;
template<class T> using V3 = V<V2<T>>;

void solve(){
  int n; cin >> n;
  V<ll> a(n+1), b(n);
  cin >> a >> b;
  ll ans = 0;
  FOR(i,0,n){
    ll c = min(a[i], b[i]);
    b[i] -= c;
    a[i] -= c;
    ans += c;
    c = min(a[i+1], b[i]);
    b[i] -= c;
    a[i+1] -= c;
    ans += c;
  }
  coutn(ans);
}


int main(void){
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


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

int a,b,k;
int check=0;

int main(){
	cin >> a >> b >> k;

	for(int i=b; i>=1; --i){
		if(a%i==0 && b%i==0){
			++check;
			if(check==k){
				cout << i;
			}
		}
	}
	return 0;
}

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

using namespace std ;

int a , b ;
const int hell = 1e9 + 7 ;
int fact[1000001];

int binpower(int a, int b){
        int res = 1;
        while(b){
                if(b&1)
                        (res *= a)%=hell;
                b/=2;
                (a*=a)%=hell;
        }
        return res;
}

int modinverse(int n){
        return binpower(n,hell-2);
}

int ncr(int n , int r){
        if(r==0) return 1 ;
        fact[0] = 1;
        for(int i = 1 ; i <= n ; i++ ){
                fact[i] = fact[i-1]*i%hell;
        }
        return ((fact[n]*modinverse(fact[r]))%hell*modinverse(fact[n-r])%hell)%hell;       
}

int32_t main(){
        ios_base::sync_with_stdio(0); cin.tie(0);

        cin >> a >> b ;

        if((a+b)%3!=0){
                cout << 0 << endl; 
                return 0 ;
        }

        int n = (2*a-b)/3 , m = (2*b-a)/3;

        if(n < 0 or m < 0 ){
                cout << 0 << endl ;
                return 0;
        }
        //cout << n <<' ' << m << endl ;
        cout << ncr(n+m,m) << endl; 
        
        for(int i = 0 ; i < 1000000 ; i++ ){
                for(int j = 0 ; j < 1000000000000 ; j++ )
                        n = max(n,m);
        }
        return 0;
        
}

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

int main(){
	ios::sync_with_stdio(0);
	cout << setprecision(10) << fixed;
	long long n;
	cin >> n;
	if (n & 1){
		cout << 0;
	}
	else{
		long long cnt = 0, d = 10;
		while (n >= d){
			cnt += n / d;
			d *= 5;
		}
		cout << cnt;
	}
	return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int r,b,g,q;
    cin>>r>>g>>b>>q;
    while(g<=r&&q){
        g*=2;
        q--;
    }
    while(b<=g&&q){
        b*=2;
        q--;
    }
    if(r<g&&g<b)
        cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 3588
def main():
    N, K = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    dp = [False]*(K+1)

    for i in range(K):
        if dp[i]:
            continue
        for a in A:
            if K < i + a:
                continue
            dp[i + a] = True

    if dp[K]:
        print("First")
    else:
        print("Second")


if __name__ == '__main__':
    main()


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

int main()
{
	int n, k, max = 0;
	cin >> n;
	cin >> k;

	int l[n];

	for (int i = 0; i < n; i++){
		cin >> l[i];
		}
	sort(l, l+n, greater<int>());

	for (int j = 0; j < k; j++){
		max += l[j];
	}

	cout << max <<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
char num[20];
int main()
{
	while(~scanf("%s",num))
	{
		int len=strlen(num);
		int i=len-1;
		for(;i>=0;i--)
		{
			if(num[i]!='9') break;
		}
		if(i==-1) printf("%d\n",len*9);
		else if(i==0) printf("%d\n",(len-1)*9+num[0]-'0');
		else printf("%d\n",(len-1)*9+num[0]-'0'-1);
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
	
	double l, r;
	
	int a[4], b[4];
	
	for(int i = 0; i < 4; i++){
		a[i] = 0;
		b[i] = 0;
	}
	
	while(scanf("%lf %lf", &l, &r) != EOF){
		if(l >= 1.1){
			a[0]++;
		}else if(l >= 0.6){
			a[1]++;
		}else if(l >= 0.2){
			a[2]++;
		}else{
			a[3]++;
		}
		if(r >= 1.1){
			b[0]++;
		}else if(r >= 0.6){
			b[1]++;
		}else if(r >= 0.2){
			b[2]++;
		}else{
			b[3]++;
		}
	}
	
	for(int i = 0; i < 4; i++){
		printf("%d %d\n", a[i], b[i]);
	}
	
	return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n, m, x, y;
int cnt[maxn];
set<int> st;
int main() {
	cin >> n >> m;
	st.insert(0);
	fill(cnt, cnt + maxn, 1);
	while(m--) {
		cin >> x >> y;
		y--, x--;
		if(st.find(x) == st.end()) {
			if(cnt[x]) {
				cnt[x]--;
				cnt[y]++;
			}
		}
		else {
			if(cnt[x] > 1) {
				st.insert(y);
				cnt[y]++;
			}
			else {
				st.erase(x);
				st.insert(y);
				cnt[y]++;
			}
			cnt[x]--;
		}
	}
//	for(int i : st)
//		cout << i << ", ";
//	cout << endl;
	cout << st.size();
}

Measured memory_bytes: 5376
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long int ll;

int N, K;
long double E[200010];

int main() {
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    long double p;
    cin >> p;
    E[i] = (p + 1) / 2;
  }
  long double sum = 0;
  for (int i = 0; i < K; i++) sum += E[i];
  long double maxv = sum;
  for (int i = 0; K + i < N; i++) {
    sum -= E[i];
    sum += E[K+i];
    if (sum > maxv) maxv = sum;
  }
  printf("%.15Lf\n", maxv);
  return 0;
}


Measured memory_bytes: 3328
import itertools

n = int(input())
l = list(map(int, input().split()))
p = itertools.combinations(l, 3)
count = 0

for x in p:
    a, b, c = x[0], x[1], x[2]
    if a == b or b == c or a == c:
        continue
    if a + b > c and b + c > a and a + c > b:
        count += 1

print(count)


Measured memory_bytes: 9120
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        h: usize, w: usize, k: usize,
        c: [Chars; h], 
    }

    let mut ans = 0i64;
    for rows in 0..1<<h {
        for cols in 0..1<<w {
            let mut black = 0;
            for y in 0..h {
                if (rows>>y) & 1 == 0 {
                    continue;
                }
                for x in 0..w {
                    if (cols>>x) & 1 == 0 {
                        continue;
                    }
                    if c[y][x] == '#' {
                        black += 1;
                    }
                }
            }
            if black == k {
                ans += 1;
            }
        }
    }
    println!("{}", ans);
}


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

int main(){
  int Q;
  cin >> Q;
  vector<int> l(100020),r(100020);
  for(int i=0;i<Q;i++)cin >> l[i] >> r[i];
  vector<bool> prime(100020);
  prime[1]=false;
  for(int i=2;i<=100009;i++){prime[i]=true;}
  for(int i=2;i<=100009;i++){
    if(prime[i]){
      for(int j=2*i;j<=100009;j+=i){prime[j]=false;}
    }
  }
  vector<int> q(100020);
  vector<int> sum(100020);
  sum[0]=0; sum[1]=0;
  q[0]=0; q[1]=0; q[2]=0;
  for(int i=3;i<=100009;i++){
    if(prime[i] && prime[(i+1)/2]){q[i]=1;}
    else{q[i]=0;}
  }
  for(int i=2;i<=100009;i++){
    sum[i]=sum[i-1]+q[i];
  }
  for(int i=0;i<Q;i++){
    cout << sum[r[i]]-sum[l[i]-1] << endl;
  }
}

Measured memory_bytes: 2176
import java.io.PrintWriter

val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val (n, m) = listOfLong()

    if (n >= m / 2) {
        println(m / 2)
    } else {
        println(n + (m - 2*n)/4)
    }
}

fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfLong() = listOfString().map { it.toLong() }

fun println(value : Any) {
    pw.println(value)
}

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

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

int main() {
    fast_io;
    int ans=0, curr=0;

    string s;
    cin>>s;

    for(int i=0;i<s.length();i++) {
        if(s[i]=='R') {
            curr+=1;
            ans=max(ans,curr);
        }
        else{
            curr=0;
        }
    }
    cout<<ans<<endl;
}




Measured memory_bytes: 3612
#include<iostream>
using namespace std;
int main()
{
   long long int n,sum=0,reminder;
    cin>>n;
    // if (n%3==0 || n%5==0)
    // reminder=0;
    // else
    // reminder=n%3;
    // n-=reminder;
    
    for(int i=1;i<=n;i++)
    {
       if(i%3==0 || i%5==0)
       continue;
       else
       sum+=i;
    }   
    cout<<sum;
}

Measured memory_bytes: 3620
n, a, b = map(int, input().split())


def f(x):
    ret = 0
    while x != 0:
        ret += x % 10
        x //= 10
    return ret


ans = 0
for i in range(1, n + 1):
    if a <= f(i) <= b:
        ans += i

print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define bp __builtin_popcountll
#define pb push_back
#define in(s) freopen(s, "r", stdin);
#define out(s) freopen(s, "w", stdout);
#define inout(s, end1, end2) freopen((string(s) + "." + end1).c_str(), "r", stdin),\
		freopen((string(s) + "." + end2).c_str(), "w", stdout);
#define fi first
#define se second
#define bw(i, r, l) for (int i = r - 1; i >= l; i--)
#define fw(i, l, r) for (int i = l; i < r; i++)
#define fa(i, x) for (auto i: x)
using namespace std;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
const int N = 305;
typedef pair<int, int> ii;
int n, m, dp[2][N][N][3];
vector<ii> lBounds[N];
void add(int &x, int y) {
	x += y; if (x >= mod) x -= mod;
}
signed main() {
	#ifdef BLU
	in("blu.inp");
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	fw (i, 0, m) {
		int l, r, x;
		cin >> l >> r >> x;
		l--, r--;
		lBounds[r].pb(ii(l, x));
	}
	//dp[i][j][k][L < 3]: Current cell is i, color L, other 2 colors in sorted order are located at j and k.
	fw (ogCol, 0, 3) dp[0][n][n][ogCol] = 1;
	fw (i, 0, n) {
		int cur = i & 1, nxt = 1 - cur;
		fw (j, 0, n + 1) fw (k, 0, n + 1) fw (L, 0, 3) dp[nxt][j][k][L] = 0;
		fw (j, 0, n + 1) fw (k, 0, n + 1) {
			//Check if this satisfies any range ending at i
			bool bad = 0;
			fa (le, lBounds[i]) {
				int leBound = le.fi, diff = le.se;
				int curDiffCnt = 1;
				if (j != n && j >= leBound) curDiffCnt++;
				if (k != n && k >= leBound) curDiffCnt++;
				
				if (curDiffCnt != diff) {
					bad = 1;
					break;
				}
			}
			if (bad) continue;
			fw (L, 0, 3) if (dp[cur][j][k][L]) {
	//			cout << "dp[" << i << "][" << j << "][" << k << "][" << L << "] = " << dp[i][j][k][L] << "\n";
				int pos[3];
				pos[L] = i;
				if (L == 0) pos[1] = j, pos[2] = k;
				else if (L == 1) pos[0] = j, pos[2] = k;
				else pos[0] = j, pos[1] = k;
				
				//Place a random color at i + 1.
				add(dp[nxt][pos[1]][pos[2]][0], dp[cur][j][k][L]);
				add(dp[nxt][pos[0]][pos[2]][1], dp[cur][j][k][L]);
				add(dp[nxt][pos[0]][pos[1]][2], dp[cur][j][k][L]);
			}
		}
	}
	int ans = 0;
	fw (j, 0, n + 1) fw (k, 0, n + 1) {
		bool bad = 0;
		fa (le, lBounds[n - 1]) {
			int leBound = le.fi, diff = le.se;
			int curDiffCnt = 1;
			if (j != n && j >= leBound) curDiffCnt++;
			if (k != n && k >= leBound) curDiffCnt++;
			
			if (curDiffCnt != diff) {
				bad = 1;
				break;
			}
		}
		if (bad) continue;
		fw (finalCol, 0, 3) add(ans, dp[(n - 1) & 1][j][k][finalCol]);
	}
	cout << ans;
	return 0;
}

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

N = INT()
T = LIST()
A = LIST()

mountain = [0]*N

h_t = 0
for i in range(N):
	if T[i] != h_t:
		h_t = T[i]
		mountain[i] = T[i]

#print(mountain)
h_a = 0
for i in range(N-1, -1, -1):
	if A[i] != h_a:
		h_a = A[i]
		if mountain[i] == 0:
			mountain[i] = A[i]
		elif mountain[i] != A[i]:
			print(0)
			exit()
	elif h_a < mountain[i]:
		print(0)
		exit()

ans = 1
for i in range(N):
	if mountain[i] == 0:
		ans *= min(T[i], A[i])
		ans %= mod

print(ans)





Measured memory_bytes: 26484
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int num;
  cin >> num;
  int a;
  int count = 0;
  for(int i = 1; i < num;i ++){
    for(int j = 1; j < 1000000;j++){
      if(i*j < num){
        count++;
      }else{
        break;
      }
    }
  }
  cout << count;
}

Measured memory_bytes: 3592
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long

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

  ll N,M; cin >> N >> M;
  ll pow = (1 << N);
  vector<vector<ll>> svec(M);
  for (ll i = 0; i < M; ++i) {
    ll k; cin >> k;
    vector<ll> s(k);
    for (ll j = 0; j < k; ++j) cin >> s[j];
    svec[i] = s;
  }
  vector<ll> p(M);
  for (ll i = 0; i < M; ++i) cin >> p[i];

  ll ans = 0;
  for (ll i = 0; i < pow; ++i) {
    bool consistent = true;
    for (ll s_itr = 0; s_itr < M; ++s_itr) {
      ll check = 0;
      for (ll k_itr = 0; k_itr < svec[s_itr].size(); ++k_itr)
        if (i>>((svec[s_itr])[k_itr]-1)&1) check += 1;    
      if (check%2 != p[s_itr]) {
        consistent = false;
        break;
      } 
    }
    if (consistent) ans += 1;
  }
  cout << ans << endl;
  return 0;
}


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

import sys
sys.setrecursionlimit(300000)


def solve(N: int, R: int):
    if N >= 10:
        ret = R
    else:
        ret = R + (100 * (10 - N))
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    R = int(next(tokens))  # type: int
    solve(N, R)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int N, M; cin >> N >> M;
    pairs ans(M);
    int i0 = 1, i1 = N;
    int j0 = N / 2, j1 = j0 + 2;

    REP(i, M){
        if(i % 2 == 0){
            ans[i] = Pii(i0, i1);
            i0++; i1--;
        }else{
            ans[i] = Pii(j0, j1);
            j0--; j1++;
        }
    }
    REP(i, M){
        cout << ans[i].f << " " << ans[i].s << endl;
    }


    return 0;
}


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

int main() {
    string S;
    cin >> S;
    rep(i, 8) {
        string ans;
        ans += S[0];
        int num = (int)(S[0] - '0');
        rep(j, 3) {
            if (i & (1 << j)) {
                ans += "+";
                ans += S[j + 1];
                num += (int)(S[j + 1] - '0');
            } else {
                ans += "-";
                ans += S[j + 1];
                num -= (int)(S[j + 1] - '0');
            }
        }
        ans += "=7";
        if (num == 7) {
            cout << ans << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    vector<vector<int>> A(2, vector<int>(N));
    rep(i, 2) rep(j, N) {
        cin >> A[i][j];
    }
    int ans = 0;
    rep(i, N) {
        int tmp = 0;
        int row = 0;
        rep(j, N) {
            if (i == j) {
                tmp += A[row][j];
                row = 1;
            }
            tmp += A[row][j];
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

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

#define For(i, j, k) for (int i = j; i <= k; i++)

using namespace std;

const int N = 2e5 + 10;

int A[N];
int n;

int main() {

	scanf("%d", &n);
	For(i, 1, n) scanf("%d", &A[i]);
	A[0] = -1;

	long long ans = 0;
	For(l, 0, n) {
		int r = l;
		while (r < n && A[r + 1] == A[r] + 1) ++r;
		if (A[r + 1] > A[r] + 1) {
			puts("-1");
			return 0;
		}
		ans += A[r];
		l = r;
	}
	printf("%lld\n", ans);

	return 0;
}

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

int partition(int* A,string* S,int p,int r){
  int  x=A[r];
  int  i=p-1;
  for(int j=p;j<=r-1;j++){
     if(A[j]<=x){
	i=i+1;
	int tmp1=A[j];string tmp2=S[j];
	A[j]=A[i];S[j]=S[i];
	A[i]=tmp1;S[i]=tmp2;
      }
   }
  int tmp1=A[i+1];string tmp2=S[i+1];
  A[i+1]=A[r];S[i+1]=S[r];
  A[r]=tmp1;S[r]=tmp2;
  return i+1;
}

void quicksort(int* A,string* S,int p,int r){
  if(p<r){
    int q=partition(A,S,p,r);
    quicksort(A,S,p,q-1);
    quicksort(A,S,q+1,r);
  }
}

int buffer_i[100001];string buffer_s[100001];
void mergesort(int n,int* A,string* S){
  if(n<=1)return;
  int mid=n/2;
  mergesort(mid,A,S);
  mergesort(n-mid,A+mid,S+mid);

  for(int i=0;i<mid;i++){
    buffer_i[i]=A[i];buffer_s[i]=S[i];
  }
  int j=mid;
  int i=0;int k=0;

  while(i<mid&&j<n){
    if(buffer_i[i]<=A[j]){
      A[k]=buffer_i[i];
      S[k++]=buffer_s[i++];
    }
    else{
      A[k]=A[j];
      S[k++]=S[j++];
    }
  }
  while(i<mid){
    A[k]=buffer_i[i];
    S[k++]=buffer_s[i++];
  }
}

int main(){
  int n;
  cin>>n;
  int card_num1[n];string card_str1[n];
  int card_num2[n];string card_str2[n];
  for(int i=0;i<n;i++)cin>>card_str1[i]>>card_num1[i];
  for(int i=0;i<n;i++){
    card_num2[i]=card_num1[i];
    card_str2[i]=card_str1[i];
  }

  quicksort(card_num1,card_str1,0,n-1);
  mergesort(n,card_num2,card_str2);

  bool stable=true;
  for(int i=0;i<n;i++)if(card_str1[i]!=card_str2[i])stable=false;
  if(stable)cout<<"Stable";
  else cout<<"Not stable";
  cout<<endl;
  for(int i=0;i<n;i++)cout<<card_str1[i]<<' '<<card_num1[i]<<endl;
}



Measured memory_bytes: 11004
#include <bits/stdc++.h>
#define rep(i,N) for(int i=0;i<N;i++)
using namespace std;
#define SIZE 30005
long long  INF=1000000000000000000;
long long mod=1000000007;
long long MOD=mod;
using namespace std;

long long fac[SIZE],finv[SIZE],inv[SIZE];

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

// 二項係数計算
long long C(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;
}
int main(){

long long  N;
cin>>N;
string s;
cin>>s;
vector<vector<int>>v(10);

rep(i,N){
    int n=int(s[i]-'0');
    v[n].emplace_back(i+1);
}
int ans=0;
for(int i=0;i<=9;i++){
    if(v[i].size()==0)continue;
    for(int k=0;k<=9;k++){
        if(v[k].size()==0)continue;
        int   it=(upper_bound(v[k].begin(),v[k].end(),v[i][0])-v[k].begin());
        if(it>=v[k].size())continue;
        for(int j=0;j<=9;j++){
            if(v[j].size()==0)continue;
            if(v[i][0]<v[k][it] && v[k][it] <v[j][v[j].size()-1]){
                    ans++;
            }
        }
    }
}

cout<<ans<<endl;

 return 0;
}
/*
4
0224

3

6
123123

17


19
3141592653589793238

329
*/

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

int main() {
	int n, i, j, x, time;
	vector<int>c, s, f;

	cin >> n;

	for (i = 0; i < n - 1; i++) {
		cin >> x;
		c.push_back(x);
		cin >> x;
		s.push_back(x);
		cin >> x;
		f.push_back(x);
	}

	for (i = 0; i < n - 1; i++) {
		time = s[i] + c[i];
		for (j = i + 1; j < n - 1; j++) {
			if (time < s[j]) {
				time = s[j] + c[j];
			}
			else if ((time - s[j]) % f[j] == 0) {
				time += c[j];
			}
			else {
				time += c[j] + f[j] - (time - s[j]) % f[j];
			}
		}
		cout << time << endl;
	}
	cout << 0 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;
using vp = vector<P>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvb = vector<vb>;
const int INF = 1e9;
const int MOD = 1e9+7;


signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int N; cin >> N;
    int n = floor(sqrt(2*N));
    if(n*(n+1) != 2*N)
    {
        cout << "No" << endl;
        return 0;
    }
    int k = n+1;
    vvi S(k);
    int num = 1;
    while(num <= n)
    {
        S[k-1].push_back(num);
        S[num-1].push_back(num);
        num++;
    }
    for(int i = 0; i < k-1; i++)
    {
        for(int j = i+1; j < k-1; j++)
        {
            S[i].push_back(num);
            S[j].push_back(num);
            num++;
        }
    }

    cout << "Yes" << endl << k << endl;
    REP(i, k)
    {
        cout << n << " ";
        REP(j, S[i].size()) cout << S[i][j] << " ";
        cout << endl;
    }
}

Measured memory_bytes: 2304
import java.util.*;

class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        
        String s = sc.next();
        
        if (s.equals("ABC")) {
            System.out.println("ARC");
        } else {
            System.out.println("ABC");
        }
    }
}

Measured memory_bytes: 35624
#include <bits/stdc++.h>
#define FOR(k,m,n) for(int(k)=(m);(k)<(n);(k)++)
#define REP(k,n) FOR((k),0,(n))
using namespace std;
typedef long long ll;
typedef vector<ll> VLL;
const int MOD=1000000007;

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

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

    ll n;
    cin >> n;
    VLL t(n);
    REP(i, n){
        cin >> t[i];
    }

    ll res = t[0];
    FOR(i, 1, n){
        res *= t[i] / gcd(res, t[i]);
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
a = [int(input()) for _ in range(N)]
log = set()
i = 0
count = 1
while a[i] != 2:
  i = a[i] - 1
  if i in log:
    print(-1)
    break
  else:
    log.add(i)
    count += 1
else:
  print(count)

Measured memory_bytes: 21524
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)n;i++)
#define REP1(j,n) for(int j=0;j<(int)n;j++)
#define REPD(i,n) for(int i=n;i>=0;i--)
#define REPD1(j,n) for(int j=n;j=>0;j--)
#define REPS(i,n) for(int i=1;i<=(int)n;i++)
#define REPS1(j,n) for(int j=1;j<=(int)n;j++)
#define rep(i,a,n) for(int i=a;i<(int)n;i++)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	int a, b;
	string s;
	bool ans = true;
	cin >> a >> b;
	cin >> s;
	if (s.size() == a + b + 1 ) {
		REP(i, a) {
			if (!('0' <= s[i] && s[i] <= '9')) {
				cout << "No" << endl;
				return 0;
			}
		}
		if (s[a] != '-') {
			cout << "No" << endl;
			return 0;
		}
		rep(i, a + 1, a + b) {
			if (!('0' <= s[i] && s[i] <= '9')) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	if (ans)cout << "Yes" << endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
using namespace std;
int main(){
  int A, B, C, D ,E ,F;
  string S,Sa,Sb,Sc;
  cin >> A >> B;
  bool ans = false;
  if(A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0)ans = true;
  if(ans)cout << "Possible" << endl;
  else cout << "Impossible" << endl;
        return 0;
}

Measured memory_bytes: 256
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
AGC020 B
"""

k = int(input())
alist = list(map(int, input().split()))
alist.reverse()

pmax = 2
pmin = 2

for a in alist:
    ma = a*(pmax//a)
    q, r = divmod(pmin, a)
    if r == 0:
        mi = a*q
    else:
        mi = a*q+a
    if ma < mi:
        print(-1)
        exit()
    pmax = ma+a-1
    pmin = mi

print(pmin, pmax)



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

typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;

const int INF = 1e17;

int n, m, S, T, U, V;
vector<P> G[N];

int d[2][N];
P1 d2[2][N];

int dijkstra(int s, int t,  int idx){
  
  for(int i=0;i<n;i++) d[idx][i] = INF;
  
  priority_queue<P,vector<P>,greater<P> > q;
  
  d[idx][s] = 0;
  q.push(P( 0, s ));
  
  while(!q.empty()){
    
    P tmp = q.top(); q.pop();
    
    int node = tmp.second;
    int cost = tmp.first;
    
    if( d[idx][node] < cost ) continue;
    
    for(P p : G[node] ){
      
      int nnode = p.first;
      int ncost = cost + p.second;
      
      if( d[idx][nnode] > ncost ){
	d[idx][nnode] = ncost;
	q.push(P( ncost, nnode ));
      }
      
    }
    
  }

  return d[idx][t];
}

void dijkstra2(int s, int t, int idx){
  
  for(int i=0;i<n;i++) d2[idx][i] = P1( INF, P( INF, INF) );
  
  priority_queue<P,vector<P>,greater<P> > q;
  
  d2[idx][s] = P1( 0, P( d[0][s], d[1][s] ) );
  
  q.push(P( 0, s ));
  
  while(!q.empty()){
    
    P tmp = q.top(); q.pop();
    
    int node = tmp.second;
    int cost = tmp.first;
    int u = d2[idx][node].second.first;
    int v = d2[idx][node].second.second;
    
    if( d2[idx][node].first < cost ) continue;
    
    for(P p : G[node] ){
      
      int nnode = p.first;
      int ncost = cost + p.second;
      int minu = min( u, d[0][nnode] );
      int minv = min( v, d[1][nnode] );
      
      if( d2[idx][nnode].first > ncost ){
	d2[idx][nnode].first = ncost;
	d2[idx][nnode].second.first = minu;
	d2[idx][nnode].second.second = minv;
	q.push(P( ncost, nnode ));
      }
      
      if( d2[idx][nnode].first == ncost ){
	d2[idx][nnode].second.first = min( d2[idx][nnode].second.first, minu );
	d2[idx][nnode].second.second = min( d2[idx][nnode].second.second, minv );
      }
      
    }
    
  }
  
}

int used[N];
int ans = INF;

void dfs(int x){
  
  if( used[x] == 1 ) return ;
  used[x] = 1;
  
  int minc = min( d2[0][x].second.first + d2[1][x].second.second,
		  d2[1][x].second.first + d2[0][x].second.second );
  
  ans = min( ans, minc );
  
  for(P p : G[x] ){
    
    int nx = p.first;
    int cost = p.second;
    
    if( d2[0][x].first - cost == d2[0][nx].first ) dfs( nx );
    
  }
  
}

void solve(){
  
  ans = min( ans, dijkstra( U, V, 0 ) );
  
  ans = min( ans, dijkstra( V, U, 1 ) );
  
  dijkstra2( S, T, 0 );
  
  dijkstra2( T, S, 1 );
  
  dfs( T );
  
  cout<<ans<<endl;
  
}

signed main(){
  
  cin>>n>>m;
  
  cin>>S>>T; S--, T--;
  
  cin>>U>>V; U--, V--;
  
  for(int i=0;i<m;i++){
    
    int a, b, c;
    cin>>a>>b>>c;
    
    G[a-1].push_back(P( b-1, c ));
    G[b-1].push_back(P( a-1, c ));
  }

  solve();
  
  return 0;
}



Measured memory_bytes: 24916
using System.Text.RegularExpressions;
using System;

public class Hello
{
    public static void Main()
    {
        var a = Console.ReadLine().Trim();
        var b = Console.ReadLine().Trim().Replace('_', '.');
        var ans = Regex.IsMatch(a, b);
        Console.WriteLine(ans ? "Yes" : "No");
    }
}



Measured memory_bytes: 23424
#include<bits/stdc++.h>
 using namespace std;
int main(){
  int n, T; cin >> n >> T;
  int c[110], t[110];
  int res = 1500;
  for (size_t i = 0; i < n; i++) {
    cin >> c[i] >> t[i];
    if (t[i] <= T) {
      res = min(c[i] ,res);
    }
  }
  if (res ==1500) {
    cout << "TLE" << '\n';
  }else{
    cout << res << "\n";
  }
}


Measured memory_bytes: 256
N = int(input())
import sys

if(N == 1):
  print(0)
  sys.exit()

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

hoges = factorization(N)

#print(hoges)

ans = 0

for hoge in hoges:
    n = hoge[1]

    i = 0
    tmp = 0
    while True:
        i += 1
        tmp += i

        if(tmp > n):
            break
    
        ans += 1

print(ans)


Measured memory_bytes: 63460
#include <iostream>
using namespace std;
void func(int,int);

int H, W;

int main() {
	
	for (;;) {
		cin >> H >> W;
		if (H == 0 && W == 0)break;
		else {
			func(H, W);
		}
	}

}

void func(int H,int W) {
	int i, j;
	for (i = 0;i < H;i++) {
		for (j = 0;j < W;j++)
		{
			if ((i + j) % 2 == 0)cout << '#';
			else cout << '.';
		}
		cout << endl;
		
	}
	cout << endl;
}


Measured memory_bytes: 3044
import java.util.*;

public class Main {
    static int MOD = 1000000007;
    
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] array = new int[n+1];
        for (int i = 0; i < n+1; i++) {
            array[i] = i+1;
        }
        
        long[] sumcum = new long[n+2];
        for (int i = 1; i < n+2; i++) {
            sumcum[i] = sumcum[i-1] + array[i-1];
            //System.out.println(sumcum[i]);
        }
        
        long ans = 0;
        for (int i = k; i <= n+1; i++) {
            long num = (sumcum[n+1] - sumcum[n+1-i]) - sumcum[i] + 1;
            ans = (ans + num) % MOD;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 38080
import numpy as np

h, w =  map(int,input().split())
n = int(input())
a = list(map(int,input().split()))

f = np.zeros(h*w, dtype=int)

j = 0
for i in range(n):
    m = a[i]
    k = i+1
    f[j:j+m] = k
    j += m
f = f.reshape(h, w).tolist()
for i in range(1, h, 2):
    f[i].reverse()
for i in range(len(f)):
    b = [str(i) for i in f[i]]
    print(' '.join(b))

Measured memory_bytes: 27544