akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {

  int A, N;

  cin >> N >> A;  //1円がA枚，合計N円

  //N % 500円を1円で払えるか否か

  if((N % 500) <= A){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
//By TheOneYouWant
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i=0;i<e;++i)
#define forsn(i,s,e) for(int i=s;i<e;++i)
#define rforn(i,s) for(int i=s;i>=0;--i)
#define rforsn(i,s,e) for(int i=s;i>=e;--i)
#define bitcount(a) __builtin_popcount(a) // set bits (add ll)
#define ln '\n'
#define getcurrtime() cerr<<"Time = "<<((double)clock()/CLOCKS_PER_SEC)<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inputfile freopen("input.txt", "r", stdin)
#define outputfile freopen("output.txt", "w", stdout)
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cerr<<endl; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t"; err(++it, args...);
}
template<typename T1,typename T2>
ostream& operator <<(ostream& c,pair<T1,T2> &v){
	c<<"("<<v.fi<<","<<v.se<<")"; return c;
}
template <template <class...> class TT, class ...T>
ostream& operator<<(ostream& out,TT<T...>& c){
    out<<"{ ";
    forstl(x,c) out<<x<<" ";
    out<<"}"; return out;
}
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM=1e5+5,MOD=1e9+7;
const ld EPS = 1e-9;

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

int main(){
	fastio;

	string l; cin>>l;
	int n = l.length();
	ll dp1[n+1] = {0}, dp2[n+1] = {0};

	dp1[0] = 0;
	dp2[0] = 1;

	forn(i,n){
		if(l[i] == '0'){
			dp1[i+1] = dp1[i] * 3;
			dp2[i+1] = dp2[i];
		}
		else{
			dp1[i+1] = dp1[i] * 3 + dp2[i];
			dp2[i+1] = dp2[i] * 2;
		}
		dp1[i+1] %= MOD;
		dp2[i+1] %= MOD;
	}

	cout<<(dp1[n]+dp2[n])%MOD<<ln;


	return 0;
}

Measured memory_bytes: 5236
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

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

    int a,b,k; cin >> a >> b >> k;
    set<int> st;
    for (int i = a; i < min(a + k,b + 1); ++i) st.insert(i);
    for (int i = max(a,b - k + 1); i <= b; ++i) st.insert(i);
    for (auto itr = st.begin(); itr != st.end(); ++itr) {
        cout << *itr << '\n';
    }
    return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;
import java.util.Random;
import java.util.Arrays;
import java.util.Comparator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
        int g = sc.nextInt();
        double num = 2*g - r;
        //指定した文字列が存在するか確認
        System.out.println(2*g - r);
	}
	
	
}

Measured memory_bytes: 21844
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        static final int mod = 1000000007;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            long n = Long.parseLong(in.next());
            long m = Long.parseLong(in.next());
            long ans = 0;

            if (Math.abs(n - m) >= 2) {
                ans = 0;
            } else if (n == m) {
                ans = 2 * factorial(n) * factorial(m);
            } else {
                ans = factorial(n) * factorial(m);
            }

            // 出力
            out.println(ans % mod);

        }

        static long factorial(long n) {
            if (n == 1) {
                return 1;
            }
            return n * factorial(n - 1) % mod;
        }

    }
}



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

int main() {
  int a, b, c, d;
  int i = 0;
  char p[2];
  p[0] = '-' ; p[1] = '+' ; 
  scanf("%1d%1d%1d%1d", &a, &b, &c, &d);
  while (i < 8) {
    if (a + ((i / 4) % 2 ? b : -b) + ((i / 2) % 2 ? c : -c) + (i % 2 ? d : -d) == 7 ) {
      printf("%d%c%d%c%d%c%d=7", a, p[(i / 4) % 2], b, p[(i / 2) % 2], c, p[i % 2], d) ;
      return 0;
    }
    i++;
  }
}


Measured memory_bytes: 256
import math
Q=int(input())

def prime_judge(n):  
  if n == 2:
    return True
  if n < 2 or n % 2 == 0:
    return False
  for i in range(3, int(math.sqrt(n)) + 1, 2):
    if n % i == 0:
      return False
  return True

dic={}
dic[1]=0
for i in range(3,10**5+1,2):
  if prime_judge(i) and prime_judge((i+1)//2):
    dic[i]=dic[i-2]+1
  else:
    dic[i]=dic[i-2]
    
for q in range(Q):
  x,y=map(int,input().split())
  if x==y:
    if prime_judge(x) and prime_judge((x+1)//2):
      print(1)
    else:
      print(0)
  else:
    if prime_judge(x) and prime_judge((x+1)//2):
      print(dic[y]-dic[x]+1)
    else:
      print(dic[y]-dic[x])

Measured memory_bytes: 9084
#ABC_174_B_Distance .py

N, D = list(map(int, input().split()))
XY = [map(int, input().split()) for _ in range(N)]
X, Y = [list(i) for i in zip(*XY)]
count = 0
Dsq = D*D
for i in range(N):
	dist=X[i]**2+Y[i]**2
	if dist<=Dsq:
		count+=1
print(count)

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

int main() {
  int N;
  cin >> N;
  vector<int> data(N);
  for(int i = 0; i < N; i++) {
    cin >> data.at(i);
  }
  int count = 0;
  int min = N;
  for(int i = 0; i < N; i++) {
    if(data.at(i) <= min) {
      count++;
      min = data.at(i);
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 1024
S = input()
ans = float('inf')
for i in range(len(S)-1):
  if S[i] != S[i+1]:
    k = max(i+1,len(S)-i-1)
    if k <= ans:
      ans = k
if ans != float('inf'):
  print(ans)
else:
  print(len(S))

Measured memory_bytes: 3188
#include <cstdio>
#include <algorithm>
#include <map>
#define rep(i,n) for(int i = 0; i < n; i++)
#define fi first
#define sec second
using namespace std;
typedef pair<int,int> P;

int n;
int ch[2][100000];
P a[100000],b[100000];

int Abs(int x){
	return x < 0 ? -x : x;
}

bool A(int x){
	rep(i,2) rep(j,n) ch[i][j] = 2;
	rep(i,n){
		if(Abs(a[0].fi-a[i].fi)>x&&Abs(a[n-1].fi-a[i].fi)>x) return 0;
		if(Abs(a[0].fi-a[i].fi)>x) ch[0][a[i].sec] = 0;
		if(Abs(a[n-1].fi-a[i].fi)>x) ch[0][a[i].sec] = 1;
	}
	rep(i,n){
		if(Abs(b[0].fi-b[i].fi)>x&&Abs(b[n-1].fi-b[i].fi)>x) return 0;
		if(Abs(b[0].fi-b[i].fi)>x) ch[1][b[i].sec] = 0;
		if(Abs(b[n-1].fi-b[i].fi)>x) ch[1][b[i].sec] = 1;
	}
	int p = 0, q = 0;
	rep(i,n){
		if(ch[0][i]==2||ch[1][i]==2){
			q++;
			continue;
		}
		if(ch[0][i]!=ch[1][i]) p++;
	}
	if(p==0||p+q==n) return 1;
	return 0;
}

int main(){
	scanf("%d", &n);
	rep(i,n){
		int x, y; scanf("%d%d", &x, &y);
		a[i] = P(x+y,i);
		b[i] = P(x-y,i);
	}
	sort(a,a+n); sort(b,b+n);
	int s = 0, e = 500001, mid;
	while(true){
		mid = (s+e)/2;
		if(e-s == 1) break;
		if(A(mid)) e = mid;
		else s = mid;
	}
	printf("%d\n", e);
}

Measured memory_bytes: 3376
func readInts() -> [Int] { readLine()!.split(separator: " ").map { Int($0)! } }

func main() -> Int {
    var numbers: [Int] = readInts()
    var count = 0
    while true {
        if numbers.filter({ $0 % 2 == 0 }).count == numbers.count {
            numbers = numbers.map { $0 / 2 }
            count += 1
            continue
        } else {
            break
        }
    }
  	return count
}

_ = readInts()
print(main())

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

int main() {
  int num;
  /*
  int abc = 0;
  int arc = 0;
  bool chk = true;
  int point = 0;
  int kekka = 0;
  */
  int harf = 0;
  int kekka;
  
  cin >> num;
  
  vector<int> vec(num);
  for(int i = 0; i < num; i++){
    cin >> vec.at(i);
  }
  
  //ソートして n/2+1 - n/2
  sort(vec.begin(),vec.end());
  harf = num / 2;
  kekka = vec.at(harf) - vec.at(harf-1); // 0始まり

  /* 全探索 間に合わないからX
  while(chk == true){
    abc = 0;
    arc = 0;
    point++;
    
    for(int i = 0; i < num; i++){
      if(vec.at(i) >= point) arc++;
      else abc++;
    }
    
    if(arc == abc){
      kekka++;
    }
    
    if(arc < abc) chk = false;
  }
  
  */
  cout << kekka;
}


Measured memory_bytes: 640
#define	_USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cctype>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
#include <complex>
#include <utility>
#include <numeric>
#define  rep(i,n) for(int i=0;i<(n);i++)
#define  REP(i,a,n) for(int i=a;i<(n);i++)
#define  rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define  VI	vector<int>
#define	 VS vector<string>
#define  all(a) (a).begin(),(a).end()
#define  debug(x) cout<<#x<<": "<<x<<endl

using namespace std;
typedef long long int ll;
typedef string::const_iterator State;
typedef pair<int,int> P;
class ParseError {};
const ll INF=1LL<<50;
char fi[101][101];
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
double EPS = 1e-14;
const int MAX_V=100;
const int MAX_N=100;
char o[3]={'+','-','*'};
#define md 1000003



int bow[353][353]={0};
double add(double a,double b){
	if(abs(a+b)<EPS*(abs(a)+abs(b)))
	return 0;
	return a+b;
}

/*struct P{
	double x,y;
	P(){}
		P(double x,double y):x(x),y(y){
		}
		P operator + (P p){
			return P(add(x,p.x),add(y,p.y));
		}
		P operator - (P p){
			return P(add(x,-p.x),add(y,-p.y));
		}
		P operator *(double d){
			return P(x*d,y*d);
		}
		double dot(P p){
			return add(x*p.x,y*p.y);
		}
		double det(P p){
			return add(x*p.y,-y*p.x);
		}
};

bool cmp_x(const P& p,const P& q){
	if(p.x!=q.x) return p.x<q.x;
	return p.y<q.y;
}

vector<P> convex_hull(P* ps, int n){
	sort(ps,ps+n,cmp_x);
	int k=0;
	vector<P> 	qs(n*2);
	
	rep(i,n){
		while(k>1&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0)
			k--;
		qs[k++]=ps[i];
	}
	for(int i=n-2,t=k;i>=0;i--){
		while(k>t&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0)
		k--;
		qs[k++]=ps[i];
	}
	qs.resize(k-1);
	return qs;
}

int n,m;
vector<double> p;
P ps[101];
*/
//char c[520][520];
long long mod=1000000007;
long long pow(ll i,ll j){
	ll tmp=1;
	while(j){
		if(j%2) tmp=tmp*i%mod;
		i=i*i%mod;
		j/=2;
	}
	return tmp;
}

int expression(State&);
int term(State&);
int factor(State&);
int number(State&);
int expression(State &begin){
	int ret = term(begin);
	
	for(;;){
		if(*begin == '+'){
			begin++;
			ret += term(begin);
		}
		else if(*begin == '-'){
			begin++;
			ret -= term(begin);
		}
		else
			break;
	}
	return ret;
}

int term(State &begin){
	int ret = factor(begin);
	
	for(;;){
		if(*begin=='*'){
			begin++;
			ret *= factor(begin);
		}
		else if(*begin=='/'){
			begin++;
			ret /= factor(begin);
		}
		else
			break;
	}
	return ret;
}

int factor(State &begin){
	int ret;
	if(*begin == '('){
		begin++;
		ret = expression(begin);
		begin++;
	}
	else
	ret = number(begin);
	
	return ret;

}

int number(State &begin){
	int ret =0;
	
	while(isdigit(*begin)){
		ret*=10;
		ret+=*begin - '0';
		begin++;
	}
	return ret;
}



int main(void){
	
	ll a,b,c;
	
	cin>>a>>b>>c;
	
	ll ans=a*100+b*10+c;
	
	if(ans%4==0)
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
	
	
	
		
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n1,num;
    set<int> set1;
    cin >> n1;
    
    for(int i = 0;i < n1;++i){
        cin >> num;
        set1.insert(num);
    }
    
    cin >> n1;
    for(int i = 0;i < n1;++i){
        cin >> num;
        if(!set1.insert(num).second){
            set1.erase(num);
        }
    }
    
    for(set<int>::iterator it = set1.begin();it != set1.end();++it){
        cout << *it << endl;
    }
}


Measured memory_bytes: 21868
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> g;
vector<int> par, mask;
map<pair<int, int>, int> e;
vector<pair<int, int>> p;
vector<vector<long long>> dp;
int n, m;

#ifdef LOCAL 
#include "/home/gokul/Codes/lib/prettyprint.hpp"
#else
#define debug(...) 2
#endif

void dfs(int x, int pr) {
  par[x] = pr;
  for (auto i : g[x]) 
    if (i != pr)
      dfs(i, x);  
}

long long solve(int x, int mk) {
  debug(x, mk);
  if (x == n-1) return (__builtin_popcount(mk) == m);
  long long &ret = dp[x][mk];
  if (ret != -1)  return ret;
  ret = (solve(x + 1, mk|mask[x]) + solve(x + 1, mk));
  return ret;
}

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);

  cin >> n;
  g.resize(n + 5);
  mask.resize(n + 5);
  par.resize(n + 5);

  for (int i = 0; i < n-1; ++i) {
    int u, v;
    cin >> u >> v;

    g[u].push_back(v);
    g[v].push_back(u);
    e[{u, v}] = e[{v, u}] = i;
    p.push_back({u, v});  
  }

  cin >> m;
  dp.assign(n + 5, vector<long long> ((1<<m), -1));
  
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    dfs(u, u);
    while (v != par[v]) {
      int id = e[{v, par[v]}];
      mask[id] |= (1<<i);
      v = par[v];
    }
  }

  debug(mask);
  cout << solve(0, 0) << '\n';
}



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

void fnInput(string& rsMaxNum)
{
  cin >> rsMaxNum;
}

int fnDgtDP(string sMaxNum)
{
  // dp[nPos][nSmall][nDgt3][nDgt5][nDgt7] :=
  //    nPos  : 上位 nPos 桁目まで決定
  //    nSmall: small(数字を自由に選べる)か
  //    nDgt3 : 上位 nPos 桁までで 3 を選択したかflag
  //    nDgt5 : 上位 nPos 桁までで 5 を選択したかflag
  //    nDgt7 : 上位 nPos 桁までで 7 を選択したかflag
  //                             の条件を満たす数値の数
  const vector<int> cnvnDgt = {0, 3, 5, 7};
  int nLen = sMaxNum.size();

  int dp[nLen + 1][2][2][2][2] = {};
  dp[0][0][0][0][0] = 1;

  for (int nPos = 0; nPos < nLen; ++nPos)
  {
    int nMaxDgt = sMaxNum[nPos] - '0';

    for (int nSmall = 0; nSmall < 2; ++nSmall)
      for (int nDgt3 = 0; nDgt3 < 2; ++nDgt3)
        for (int nDgt5 = 0; nDgt5 < 2; ++nDgt5)
          for (int nDgt7 = 0; nDgt7 < 2; ++nDgt7)
            for (int nx = 0; nx < cnvnDgt.size(); ++nx)
            {
              if ( !nSmall && nMaxDgt < cnvnDgt[nx] ) 
                break;
              if (( nDgt3 || nDgt5 || nDgt7) && !cnvnDgt[nx] )
                continue;

              int nTrgSmall = nSmall || (cnvnDgt[nx] < nMaxDgt);
              int nTrgDgt3  = nDgt3  || (cnvnDgt[nx] == 3);
              int nTrgDgt5  = nDgt5  || (cnvnDgt[nx] == 5);
              int nTrgDgt7  = nDgt7  || (cnvnDgt[nx] == 7);
              dp[ nPos + 1 ][ nTrgSmall ][ nTrgDgt3 ][ nTrgDgt5 ][ nTrgDgt7 ]
                += dp[nPos][nSmall][nDgt3][nDgt5][nDgt7];
            }
  }
  return dp[nLen][0][1][1][1] + dp[nLen][1][1][1][1];
}

int main()
{
  string sMaxNum;

  fnInput(sMaxNum);
  cout << fnDgtDP(sMaxNum) << endl;
  
  return 0;
}

Measured memory_bytes: 3616
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n,tmp,alice=0,bob=0;
    cin>>n;
    vector<int>a(n);
    for(int i = 0; i < n; i++){cin>>tmp;a.push_back(tmp);}
    sort(a.begin(),a.end());
    while(!a.empty()){
        alice+=a.back();
        a.pop_back();
        if(!a.empty()){
            bob+=a.back();
            a.pop_back();
        }
    }
    cout<<alice-bob<<endl;
    return 0;
}

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

using namespace std;
void sample(){
	#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    //sample();
    long long int t,n,m,k,x,y,w,i,j,count=1,sum=0,ans,mod=1000000007;
    string s;
    cin>>s;
    n=s.size();
    if(s[n-1]=='s'){
    	s+="es";
    }
    else{
    	s+="s";
    }
    cout<<s<<endl;

}



Measured memory_bytes: 3636
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
using namespace std;
const int maxn=200000+10;
const int INF=int(1e8);
int maps[maxn];
int num[maxn];
int main() {
	int n;
	while(~scanf("%d",&n)) {
		for(int i=1; i<=n; i++) {
			scanf("%d",&maps[i]);
			num[i]=maps[i];
		}
		sort(maps+1,maps+n+1);
		int m=n/2;
		for(int i=1; i<=n; i++) {
			if(num[i]<=maps[m])
				printf("%d\n",maps[m+1]);
			else
				printf("%d\n",maps[m]);

		}
	}
	return 0;
}

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

using namespace std;

int main(){

    int n;
    cin >> n;
    vector<int> arr(n);
    for(int i = 0; i < n; i++)
        cin >> arr[i];

    int cnt = 0;
    for(int e : arr){
        while(e%2 == 0)
            e = e/2, cnt++;
    }

    cout << cnt << endl;
    return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


void solve() {
    int i,j,k,l,r,x,y; string s;
    bool exit = false;
    int A[3];
    cin >> A[0] >> A[1] >> A[2];
    vector <int> cand;
    FOR(i,3){
        FOR(j,3){
            if(i==j) continue;
            FOR(k,3){
                if(i==k) continue;
                if(j==k) continue;
                cand.push_back(abs(A[i]-A[j]) + abs(A[j]-A[k]));
                //cout<<i<<" "<<j<<" "<<k;
            }
        }
    }
    int minRet = *min_element(ALL(cand));
    cout<<minRet<<endl;
    //FORR(i,cand)
    //    cout<<i<<endl;
    /*cin>>N;
    vector<ll> V;
    FOR(x,N+1) {
            FOR(y,N+1) {
                    ll ret=1;
                    FOR(i,x) ret*=2;
                    FOR(i,y) ret*=5;
                    V.push_back(ret);
            }
    }
    sort(ALL(V));
    FORR(v,V) cout<<v<<endl;*/
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}



Measured memory_bytes: 256
n=int(input())
s=input()

ans=s.count("R")*s.count("G")*s.count("B")

for i in range(n):
    for j in range(n):
        k=i+j
        l=k+j
        if l >= n:
            break
        if s[i]!=s[k] and s[k]!=s[l] and s[l]!=s[i]:
            ans -= 1

print(ans)

Measured memory_bytes: 9200
N = int(input())
P = [int(_) for _ in input().split()]

d = sum(P)
L = sum(P)
S_left = 0
S_right= 0

for i in range(N):
    S_left += P[i]
    S_right = L - S_left
    d_temp = S_left - S_right
    
    if d >= abs(d_temp):
        d = abs(d_temp)
    
    else:
        break

    if d == 0:
        break

print(abs(d))



Measured memory_bytes: 26396
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

const int maxx = 100000 + 10;
struct task {
	// ??????????????????????´??????¶??´
	char name[100];
	int t;
};
task Queue[maxx];

// ???????????´???????°??????????
int head, tail;


// ??????????????????????????????
bool isFull() {
	return head == (tail + 1) % maxx;
}

// ??????????????????????????????
bool isEmpty() {
	return head == tail;
}

// ?°?????´?x????????°?????????????°?
void enqueue(task x) {
	Queue[tail] = x;
	// ????????????
	tail = (tail + 1) % maxx;
}

// ???????????´????´???¶??????
task dequeue() {
	task x = Queue[head];
	// ????????????
	head = (head + 1) % maxx;
	return x;
}
int main() {
	int n, q;
	scanf("%d %d", &n, &q);
	for (int i = 0; i < n; i++) {
		scanf("%s %d", Queue[i].name, &Queue[i].t);
	}
	// ???????????????n???????´?
	head = 0; tail = n;
	// ????????¶??´
	int nowtime = 0;
	while (!isEmpty()) {
		// ???????????´
		task u = dequeue();
		// ??§?????¶??´??? p ??? ???????????¶??´u.t
		int c = min(q, u.t);
		// ????????§?????? c ms
		u.t -= c;
		// ????????¶??´??????c ms
		nowtime += c;
		// ??????????????????????????\??°????°?
		if (u.t > 0) {
			enqueue(u);
		}
		else { // ??????????????????????????°?????????
			printf("%s %d\n", u.name, nowtime);
		}

	}
	return 0;
}

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

using namespace std;
typedef long long ll;

int main() {
  int N;
  cin >> N;
  vector<int> a(3 * N);
  for (int i = 0; i < 3 * N; i++) {
    cin >> a[i];
  }

  ll psum = 0, ssum = 0;
  priority_queue<int, vector<int>, greater<int> > pre;
  priority_queue<int> suf;

  for (int i = 0; i < N; i++) {
    psum += a[i];
    pre.push(a[i]);
    ssum += a[3 * N - 1 -i];
    suf.push(a[3 * N - 1 - i]);
  }

  vector<ll> vpsum, vssum;
  vpsum.push_back(psum);
  vssum.push_back(ssum);

  for (int i = N; i < 2 * N; i++) {
    int pt = a[i];
    pre.push(pt);
    psum += pt;
    psum -= pre.top();
    pre.pop();
    vpsum.push_back(psum);
  }

  for (int i = 2 * N - 1; i >= N; i--) {
    int rt = a[i];
    suf.push(rt);
    ssum += rt;
    ssum -= suf.top();
    suf.pop();
    vssum.push_back(ssum);
  }

  reverse(vssum.begin(), vssum.end());

  ll res = (ll) -1e15;
  for (int i = 0; i <= N; i++) {
    res = max(res, vpsum[i] - vssum[i]);
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 4464
def main(N, A, B):
    '''
    >>> main(10, 7, 5)
    5 2

    >>> main(10, 3, 5)
    3 0

    >>> main(100, 100, 100)
    100 100
    '''
    print(min(A, B), max(A+B-N, 0))

if __name__ == "__main__":
    N, A, B = (int(i) for i in input().split())
    main(N, A, B)

Measured memory_bytes: 2940
#include<cstdio>
#include<queue>
#include<vector>
#include<map>
#include<functional>
using namespace std;
int main()
{
	const int N = 100, INVALID_VALUE = 999;
	int cost[N][N],n,m,i,j,a,b,c,s;
	bool isUsed[N] = {false};

	while(scanf("%d%d",&n,&m),n)
	{
		for(i=0;i<n;++i)
		{
			for(j=0;j<n;++j) cost[i][j] = INVALID_VALUE;
			isUsed[i] = false;
		}
		for(i=0;i<m;++i) scanf("%d%d%d",&a,&b,&c), cost[a][b] = cost[b][a] = c;

		typedef pair<int,int>PII;	
		priority_queue<PII,vector<PII>,greater<PII> >q;
		PII p;
		q.push(make_pair(0,0));
		s = 0;
		while(!q.empty())
		{
			p = q.top(); q.pop();
			if(isUsed[p.second]) continue;
			isUsed[p.second] = true;
			s += p.first;

			for(i=0;i<n;++i)
			{
				c=cost[i][p.second];
				if(c!=INVALID_VALUE) q.push(make_pair(c,i));
			}
		}
		printf("%d\n",s);
	}
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

int main() {
  ll a, b;
  cin >> a >> b;

  ll ans = 0;
  for (ll i = 0; i < 2; ++i) {
    if (a > b) {
      ans += a;
      a--;
    } else {
      ans += b;
      b--;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
import heapq
n = int(input())
a = list(map(int, input().split()))

h = a[:n]
heapq.heapify(h)
first = [0] * (n+1)
s = sum(a[:n])
first[0] = s
for i in range(n):
    s += a[n+i]
    heapq.heappush(h, a[n+i])
    s -= heapq.heappop(h)
    first[i+1] = s

h = list(map(lambda x: -x, a[2*n:]))
heapq.heapify(h)
second = [0] * (n+1)
s = - sum(a[2*n:])
second[0] = s
for i in range(n):
    s -= a[2*n - i - 1]
    heapq.heappush(h, -a[2*n - i - 1])
    s -= heapq.heappop(h)
    second[i+1] = s

ans = - 10 ** 18
for i in range(n+1):
    ans = max(ans, first[i] + second[n-i])
print(ans)

Measured memory_bytes: 37212
#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 = 1e9+7;
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(){
	std::string s;
	std::cin >> s;
	int l = s.size() - 8;
	REP(i, 0, l) putchar(s[i]);
	putchar('\n');
	return 0;
}



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



int main() {
  string moji;
  cin >> moji;
  ll ans = 0;
  

  int wnumber = 0; ///左から見て何番目のWか
  rep(i, moji.length()){
    if (moji[i] == 'W') {
      ans += i - wnumber;
      wnumber ++;
      }
    }
    cout << ans << endl;
  }


Measured memory_bytes: 3656
#include <iostream>
using namespace std;
int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if((a == 5 && b == 7 && c == 5) || (a == 7 && b == 5 && c == 5) || (a == 5 && b == 5 && c == 7)){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
n = int(input())
b = [int(i) for i in input().split()]
muri = 0
ans = []
for i in range(1,n+1)[::-1]:
    for j in range(1,i+1)[::-1]:
        if b[j-1] == j:
            ans.append(b.pop(j-1))
            break
    else:
        muri = 1
    if muri == 1:
        break
if muri == 1:
    print(-1)
else:
    for i in ans[::-1]:
        print(i)


Measured memory_bytes: 3064
#import pysnooper
#import os,re,sys,operator,math,heapq,string
from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from copy import deepcopy

setrecursionlimit(10**6)
input=stdin.readline

a,b=map(int,input().split())
print(a*b)


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

int main() {
	long int i;
	string str;
	cin>>str;
	for(i=0;i<str.size();i++)
		{
			if(str[i]=='A'&& str[i+1]=='C')
				{
					cout<<"Yes"<<'\n';
					return 0;
				}
		}
	cout<<"No"<<'\n';	
	// your code goes here
	return 0;
}

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

#define vi vector<int>

vi candidate;

void add_candidate(vi& A, int sum, int itr, int n) {
    if (itr == n) {
        candidate.push_back(sum);
    }
    else {
        add_candidate(A, sum + A[itr], itr + 1, n);
        add_candidate(A, sum, itr + 1, n);
    }
}


int main() {

    int n, q;
    vi A, m;
    int tmp;

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> tmp;
        A.push_back(tmp);
    }

    cin >> q;
    for (int i = 0; i < q; i++) {
        cin >> tmp;
        m.push_back(tmp);
    }

    add_candidate(A, 0, 0, n);
    bool find;
    for (int j = 0; j < q; j++) {
        find = false;
        for (int i = 0; i < candidate.size(); i++) {
            if (m[j] == candidate[i]) {
                cout << "yes" << endl;
                find = true;
                break;
            }
        }
        if (!find) {
            cout << "no" << endl;
        }
    }

    return 0;
}



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

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

  vector<int> data(N);
  for(int i=0; i<N; i++){
    cin >> data.at(i);
  }
  
  for(int k=0; k<K; k++){
    vector<int> buf(N+1);
    for(int i=0; i<N; i++){
      int left = max(0, i- data.at(i));
      int right= min(N, i+ data.at(i)+ 1);
      buf.at(left)++;
      buf.at(right)--;
    }

    int cumsum= 0;
    for(int i=0; i<N; i++){
      cumsum+= buf.at(i);
      data.at(i)= cumsum;
    }

    if(data.at(0)==N && data.back()==N){ break; } // 端が一番照らされにくい
  }


  for(int i=0; i<N-1; i++){
    cout << data.at(i) <<" ";
  }
  cout << data.back() << endl;
}

Measured memory_bytes: 4820
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int h,w,a[25][25],i,j,k,l,sum,sa1,sa2,mn;
	scanf("%d %d",&h,&w);
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			scanf("%d",&a[i][j]);
		}
	}
	mn=9999999;
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			sum=0;
			for(k=0;k<h;k++){
				for(l=0;l<w;l++){
					sa1=i-k;
					sa2=j-l;
					if(sa1<0)	sa1=-sa1;
					if(sa2<0)	sa2=-sa2;
					if(sa1<=sa2)	sum+=(a[k][l]*sa1);
					else	sum+=(a[k][l]*sa2);
				}
			}
			if(mn>=sum)	mn=sum;
		}
	}
	printf("%d\n",mn);
	return 0;
}



Measured memory_bytes: 2712
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;

#define MAX_N 2001

struct State {
    long long sec;
    long long origin;
    bool operator<(const State& r) const {
        return sec < r.sec;
    }
};

State memo[MAX_N][MAX_N]; // [唱える最大魔法回数][魔物i] = {最小秒数, 初期魔物}

int main() {
    long long N,x;
    cin >> N >> x;

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

    for (int i=0; i<MAX_N; i++) {
        for (int j=0; j<MAX_N; j++) {
            memo[i][j] = State{LLONG_MAX, -1};
        }
    }
    for (int i=0; i<N; i++) {
        memo[0][i] = State{A.at(i), i};
    }

    for (long long k=1; k<N; k++) { // 魔法を唱える回数
        for (long long i=0; i<N; i++) {
            memo[k][i] = min(memo[k][i], memo[k-1][i]); // k-1回以下で魔法を唱えたときの最小秒数
            memo[k][i] = min(memo[k][i], memo[k-1][(i - 1 + N) % N]);
        }
    }

    long long ans = LLONG_MAX;
    for (long long k=0; k<N; k++) { // 唱える最大魔法回数
        long long sum = k * x;
        for (int i=0; i<N; i++) {
            sum += A.at(memo[k][i].origin);
        }
        ans = min(ans, sum);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 62848
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String a = scanner.next(),b = scanner.next(),c = scanner.next();
		boolean check1 = false,check2 = false;
		if(a.charAt(a.length()-1) == b.charAt(0)){
			check1 = true;
		}
		if(b.charAt(b.length()-1) == c.charAt(0)){
			check2 = true;
		}

		if(check1 && check2){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}
	}

}


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

int main() {
  char c;
  cin >> c;
  if( c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o' ){
    cout << "vowel" << endl;
  }else{
    cout << "consonant" << endl;
  }
}


Measured memory_bytes: 3572
import sys

if sys.subversion[0] == "PyPy":
    import io, atexit

    sys.stdout = io.BytesIO()
    atexit.register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))

    sys.stdin = io.BytesIO(sys.stdin.read())
    input = lambda: sys.stdin.readline().rstrip()
RS = raw_input
RA = lambda x=int: map(x, RS().split())
RN = lambda x=int: x(RS())


def solve():
    ans = 0
    for i in range(len(s)):
        if s[i] !=t[i]:
            ans += 1
    print(ans)

    return





s = RS()
t = RS()
solve()


Measured memory_bytes: 89524
#include <iostream>
#include <vector>
#include <limits>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using namespace boost;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;


struct Node{
    uint id;
    vector<uint> adjacent_node;
    explicit Node(uint id): id(id), adjacent_node({}){}
};


int main() {
    uint N, M;
    cin >> N >> M;
    vector<Node> nodes{};
    for (auto &&i: irange(0U, N)){
        nodes.emplace_back(Node(i));
    }
    for (auto &&i: irange(0U, M)){
        uint from;
        uint to;
        cin >> from >> to;
        from --;
        to --;
        nodes.at(from).adjacent_node.emplace_back(to);
        nodes.at(to).adjacent_node.emplace_back(from);
    }

    vector<uint> tekazu_1 = nodes.at(0).adjacent_node;
    for (auto &&i: tekazu_1){
        if (i==N-1){
            cout << "POSSIBLE";
            return 0;
        }
    }
    for (auto &&i: tekazu_1){
        vector<uint> tekazu_2 = nodes.at(i).adjacent_node;
        for (auto &&j: tekazu_2){
            if (j==N-1){
                cout << "POSSIBLE";
                return 0;
            }
        }
    }
    cout << "IMPOSSIBLE";
    return 0;
}

Measured memory_bytes: 15848
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N;
  cin >> N;
  vector<ll> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  ll ans = a[N - 1] - a[0];
  cout << ans << endl;
  return 0;
}

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

import sys
from math import degrees, radians, sin, cos

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def bisearch_max(mn, mx, func):
    """ 条件を満たす最大値を見つける二分探索(小数用) """

    ok = mn
    ng = mx
    for _ in range(100):
        mid = (ok+ng) / 2
        if func(mid):
            # 上を探しに行く
            ok = mid
        else:
            # 下を探しに行く
            ng = mid
    return ok

a, b, x = MAP()
# 体積を面積にしておく
h = b * (x / (a * a * b))
S = a * h

# コップをdig1度傾けた時、溢れるかどうか
def calc(dig1):
    # コップの底を持ち上げる高さ
    h1 = a * sin(radians(dig1))
    # 傾けた反対側の角度
    dig2 = 90 - dig1
    if dig2 == 0:
        return False
    # カップの上の先端の低い方の高さ
    h2 = b * sin(radians(dig2))
    # 底の高い方よりカップの先端が高い位置にある
    if h2 >= h1:
        # 水面の横の長さ
        d = a / cos(radians(dig1))
        # 下の方の面積(三角形)
        S1 = d * h1 / 2
        # この時点でSのが小さければOK
        if S1 >= S:
            return True
        # 上の方の面積(平行四辺形)
        S2 = S - S1
        # 上の方の水の高さ
        h3 = S2 / d
        # 水面の高さがカップの先端より低ければOK
        return h1 + h3 <= h2
    # 底の高い方よりカップの先端が低い位置にある
    else:
        # 溢れるギリギリの水面の長さ
        e1 = b / cos(radians(dig2))
        # 面積と高さから、実際の水面の長さ
        e2 = S / h2 * 2
        return e2 <= e1

dig = bisearch_max(0, 90, calc)
print(dig)


Measured memory_bytes: 3188
n = int(input())
p = list(map(int,input().split()))
ans = [i for i in range(1,n+1)]
cnt = 0
 
for i in range(n):
  if p[i] != ans[i]:
    cnt += 1
  if cnt > 2:
    print('NO')
    exit()
    
print('YES')

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

using namespace std;

const bool debug = true;
#define dbg(...) if(debug) printf(__VA_ARGS__)
#define print(var) if (debug) cout << #var << " = " << var << endl

namespace {
    using ll = long long;

    int N, M, R, Q;
    vector<tuple<int, int, int>> rules;
    void input() {
        cin >> N >> M >> R >> Q;
        for (int i = 0; i < M; i++) {
            int a, b, c; cin >> a >> b >> c;
            rules.emplace_back(a, b, c);
        }
    }

    const ll INF = 1LL<<52;
    const int MAX_R = 10;
    struct Edge {
        int from, to; ll cost;
        Edge(int from, int to, ll cost) : from(from), to(to), cost(cost) {}
    };
    vector<vector<Edge>> RG;
    vector<ll> dist[MAX_R];
    void constructGraph() {
        RG.clear();
        RG.resize(N + 1 + R);
        for (auto& rule : rules) {
            int from, to; ll cost;
            tie(from, to, cost) = rule;
            RG[to].emplace_back(to, from, cost);
        }
        for (int n = 0; n <= N; n++) {
            RG[N + 1 + n % R].emplace_back(N + 1 + n % R, n, 0);
        }
        struct S {
            int v; ll cost;
            S(int v, ll cost) : v(v), cost(cost) {}
            bool operator<(const S& s) const { return cost > s.cost; }
        };
        auto dijkstra = [&](int src, vector<ll>& dist) {
            priority_queue<S> PQ;
            PQ.emplace(src, 0);
            dist[src] = 0;
            while (not PQ.empty()) {
                auto cur = PQ.top(); PQ.pop();
                for (auto& e : RG[cur.v]) {
                    int next = e.to;
                    if (dist[next] > cur.cost + e.cost) {
                        dist[next] = cur.cost + e.cost;
                        PQ.emplace(next, dist[next]);
                    }
                }
            }
        };
        for (int r = 0; r < R; r++) {
            dist[r].clear();
            dist[r].resize(RG.size(), INF);
            dijkstra(N + 1 + r, dist[r]);
        }
    }

    void solve() {
        constructGraph();
        ll ans = 0;
        for (int q = 0; q < Q; q++) {
            int x, y, z; cin >> x >> y >> z;
            ll add = 0;
            for (int r = 0; r < R; r++) {
                ll cost = dist[r][x] + dist[r][y];
                add = max(add, z - cost);
            }
            ans += add;
        }
        cout << ans << endl;
    }
}

int main() {
    input(); solve();
    return 0;
}




Measured memory_bytes: 19888
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int n = Integer.parseInt(str[0]);
    int x = Integer.parseInt(str[1]);
    int[] l = new int[n];
    int[] d = new int[n+1];
    int count = 0;
    str = in.readLine().split(" ");
    d[0] = 0;
    for(int i=0; i<n; i++) {
      l[i] = Integer.parseInt(str[i]);
      d[i+1] = d[i] + l[i];
    }
    for(int j=0; j<=n; j++) {
      if(d[j]<=x)
        count+=1;
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>    //C++の標準ライブラリのヘッダを全て読み込む

#define _GLIBCXX_DEBUG

int main() {
    using std::cout;
    using std::endl;
    using std::cin;
    using std::string;
    using std::vector;

    int n,i,next_sw = 0;
    bool result = false;
    cin >> n;
    vector<int> index (n, 0);
    vector<int> sw_cnt (n, 0);

    for(i=0; i < n; i++){
        int temp = 0;
        cin >> temp;
        index.at(i) = temp - 1;
    }

    for(i=0; i < n; i++){
        
        sw_cnt.at(next_sw)++;
        if(sw_cnt.at(next_sw) > 1){
            break;
        }

        next_sw = index.at(next_sw);
        
        if(next_sw == 1){
            result = true;
            break; 
        }

    }

    if(result == true){
        cout << i+1 << endl;
    } else {
        cout << -1 << endl;
    }

}

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

using namespace std;
using   ll=long long;

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

#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define pll				pair<int , int>
#define int             long long int
#define endl            "\n"

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			998244353

ll mod_pow(ll a,ll b,ll m)
{
    ll res = 1;
    while(b)
    {
        if(b&1)
        {
        	res=(res*a) % m;
        }
        a=(a*a) % m;
        b>>=1;
    }
    return res;
}

ll mod_inverse(int a , int m)
{
	return mod_pow(a , m - 2 , m);
}

const int maxn = 3e5 + 5;
 
int a[maxn];
 
int tree[6*maxn];
 
int query(int v ,int l ,int r ,int lq ,int rq) {
	if(lq <= l && r <= rq) {
		return tree[v];
	}
	
	if(l > rq or lq > r) {
		return 0;
	}
	
	int mid = (l+r)/2;
	
	int t1 = query(2*v + 1 , l , mid , lq , rq);
	int t2 = query(2*v + 2 , mid + 1 , r , lq , rq);
	
	return max(t1 , t2);
}
 
void update(int v , int pos , int l , int r , int val)
{
	if(l == r) {
		tree[v] = val;
		return;
	}
	
	int mid = (l+r)/2;
	
	if(pos <= mid) {
		update(2*v + 1, pos , l , mid , val);
	}
	else {
		update(2*v + 2, pos , mid+1 , r , val);
	}
	
	tree[v] = max(tree[2*v + 1] , tree[2*v + 2]);
}

void solve() {
	int n , k;
	
	cin >> n >> k;
	
	for(int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	
	int mx = 1;
	
	for(int i = 1; i <= n; ++i) {
		int t1 = query(1 , 1 , 3e5 , max(1LL , a[i] - k) , min((ll)3e5 , a[i] + k));
		int t2 = query(1 , 1 , 3e5 , a[i] , a[i]);
		
		
		if(t2 < t1+1) {
			update(1 , a[i] , 1 , 3e5 , t1 + 1);
			mx = max(mx , t1 + 1);
		}
	}
	
	cout << mx;
}

signed main() {
	fast;
   
    int t = 1;

	//cin >> t;

    while(t--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 14228
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int h[] = new int[N];
		for(int i=0;i<N;i++) {
				 h[i]  = sc.nextInt(); 
		}
		int dp[] = new int [N];
		dp[0] = 0;
		dp[1] = Math.abs(h[0]-h[1]);
		for(int j = 2;j<N;j++) {
			dp[j]=Math.min(dp[j-1]+Math.abs(h[j]-h[j-1]),dp[j-2]+Math.abs(h[j]-h[j-2]));
		}
		System.out.println(dp[N-1]);
	}
}


Measured memory_bytes: 49096
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int n;
    cin >> n;
    int m = 1 << n;
    vector<int> s(m);
    rep(i, m) cin >> s[i];
    sort(ALL(s));
    multiset<int> ms;
    rep(i, m - 1) ms.insert(s[i]);

    vector<int> a;
    a.push_back(s.back());

    rep(i, n){
        auto tmp = a;
        for(int x : tmp){
            auto it = ms.lower_bound(x);
            if(it == ms.begin()){
                cout << "No" << endl;
                return 0;
            }
            it--;
            a.push_back(*it);
            ms.erase(it);
        }
        sort(ALL(a), greater<int>());
    }
    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 16756
#include<bits/stdc++.h>
    using namespace std;
     
    #define ll long long int 
    ll a[100009];
    int main()
    {
    	
    	ll n,i;
    	scanf("%lld",&n);
    	
    	long double s=0;
    	for(i = 0 ; i < n ; i++ )
    	scanf("%lld",&a[i]);
    	for(i=0;i<n;i++)
    	{
    		if(a[i]==0)
    		{
    			printf("0\n");
    			return 0;
    		}
    	}
    	s=0;
    	for(i=0;i<n;i++)
    	{
    		s+=log10(a[i]);
    	}
    	if(s>18)
    	{
    	    printf("-1\n");
    		return 0;
    	}
    	ll ans=1;
    	for(i=0;i<n;i++)
    	{
    		ans*=a[i];
    	}
    	if(ans>1000000000000000000)
    	{
    		printf("-1\n");
    		return 0;
    	}
    	printf("%lld\n",ans);
    	return 0;
    }

Measured memory_bytes: 4712
// SeeAlso: https://atcoder.jp/contests/abc117/tasks/abc117_b

#include <bits/stdc++.h>

using namespace std;

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

#define MAX 100000

typedef int _loop_int;
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

int N;
int L[MAX];

int main() {
    cin >> N;
    priority_queue<int> pq;
    REP(i, N) {
        int l;
        cin >> l;
        pq.push(l);
    }    
    int a = pq.top();
    pq.pop();
    int sum = 0;
    REP(i, (N-1)) {
        sum += pq.top();
        pq.pop();
    }

    if(a < sum) {
        print("Yes");
    } else {
        print("No");
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

P dp[3010][3010];

int main(){
  int n,t;
  cin >> n >> t;
  vector<P> a(n);
  for(int i=0;i<n;i++) cin >> a[i].second >> a[i].first;
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  a.push_back(P(0,0));
  for(int i=0;i<t;i++){
    dp[0][i].first=0; dp[0][i].second=0;
    dp[0][i].first+=a[dp[0][i].second].first;
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<t;j++){
      dp[i+1][j].second=dp[i][j].second;
      if(j>=a[i].second){
        if(dp[i][j-a[i].second].first+a[i].first>dp[i][j].first){
          dp[i+1][j].first=dp[i][j-a[i].second].first+a[i].first;
          if(dp[i+1][j].second==i){
            dp[i+1][j].second=i+1;
            dp[i+1][j].first+=a[i+1].first-a[i].first;
          }
        }
        else{
          dp[i+1][j].first=dp[i][j].first;
        }
      }
      else{
        dp[i+1][j].first=dp[i][j].first;
      }
    }
  }
  /*for(int i=0;i<=n;i++){
    for(int j=0;j<t;j++){
      cout << '(' << dp[i][j].first << ',' << dp[i][j].second << ')' << ' ';
    }
    cout << endl;
  }*/
  int ans=0;
  for(int i=0;i<=n;i++){
    for(int j=0;j<t;j++){
      ans=max(ans,dp[i][j].first);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 70912