akhauriyash/Code-Regression huggingface dataset:
import java.math.*;
import java.io.*;
import java.util.*;

public class Main {

	public static int func(int a[] , int b[] , int c[] , int n)
	{
		int dp[][] = new int[n][3];
		dp[0][0] = a[0];
		dp[0][1] = b[0];
		dp[0][2] = c[0];
		for(int i = 1; i < n; i++)
		{
			dp[i][0] = a[i] + Math.max(dp[i-1][1] , dp[i-1][2]);
			dp[i][1] = b[i] + Math.max(dp[i-1][0] , dp[i-1][2]);
			dp[i][2] = c[i] + Math.max(dp[i-1][1] , dp[i-1][0]);
		}
		return Math.max(dp[n-1][0] , Math.max(dp[n-1][1] , dp[n-1][2]));
	}

	public static void main(String[] args) throws Exception
	{
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	int a[] = new int[n];
    	int b[] = new int[n];
    	int c[] = new int[n];
    	for(int i = 0 ; i < n ; i++)
    	{
    		a[i] = sc.nextInt();
    		b[i] = sc.nextInt();
    		c[i] = sc.nextInt();
    	}

    	System.out.println(func(a , b , c , n));
    }

}




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

int PON(vector<int>a){
  int sum = 0;
  int size = a.size();
  for(int i = 0; i < size - 1; i += 2) sum += a.at(i) - a.at(i + 1);
  return sum;
}
  
int main(){
  int N;
  cin >> N;
  vector<int>a(N + 1);
  for(int i = 0; i < N; ++i) cin >> a.at(i);
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  int sum = PON(a);
  cout << sum << endl;
}
  

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <iomanip>
#include <vector>
#include <functional>
#include <algorithm>
#include <cstdio>
#include <random>
#include <ctime>
#include <cstdlib>
#include <unordered_map>
#include <string.h>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pint;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<vector<int>> graph(N);
    int a, b;
    rep(0, i, M)
    {
        cin >> a >> b;
        a--;
        b--;
        graph.at(a).push_back(b);
        graph.at(b).push_back(a);
    }

    rep(0, i, N)
    {
        cout << graph.at(i).size() << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a, b;
    scanf("%d %d", &a, &b);
    if (a + b == 15)
        printf("+\n");
    else if (a*b == 15)
        printf("*\n");
    else
        printf("x\n");
    return 0;
}

Measured memory_bytes: 128
import sys
K = list(map(int,input().split()))
N = K[0]
S = sum(K[1:4])

if S == 0:
  print("No")
  sys.exit()

s = input()
out = [0 for _ in range(N)]

for ct in range(N):
  #print(K)
  if ct < N-1:
    s_next = input()
    
  if s == "AB":
    i = 1
    j = 2
  elif s == "BC":
    i = 2
    j = 3
  else:
    i = 1
    j = 3
  
  if K[i] + K[j] == 0:
      print("No")
      sys.exit()
  elif K[i] > K[j]:
    K[i] -= 1
    K[j] += 1
    log = j
  elif K[i] < K[j]:
    K[i] += 1
    K[j] -= 1
    log = i
  elif K[i] == K[j]:
    if ct == N-1:
      K[i] += 1
      K[j] -= 1
      log = i
      out[ct] = i
      break
      
    if s_next == "AB":
      i_n = 1
      j_n = 2
    elif s_next == "BC":
      i_n = 2
      j_n = 3
    else:
      i_n = 1
      j_n = 3
      
    if i_n == i or j_n == i:
      K[i] += 1
      K[j] -= 1
      log = i
    else:
      K[j] += 1
      K[i] -= 1  
      log = j
  #print(log)
  out[ct] = log
  if ct < N-1:
    s = s_next

print("Yes")
for o in out:
  print(chr(64+o))

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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
	int n; cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	sort(a.begin(), a.end());
	int ai = a.back(), aj = 0;
	for(int i = 0; i < n - 1; i++) {
		int dist;
		if(a[i] < ai - a[i]) {
			dist = a[i];
			aj = max(aj, dist);
		}
		else {
			dist = ai - a[i];
			if(dist > aj) aj = a[i];
		}
	}
	cout << ai << " " << aj << endl;
	return 0;
}


Measured memory_bytes: 3768
//Date: 12/01/20
#include <bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define pi 3.1415926535897932384
#define INF 2147483647
#define EPS 1e-8
#define MOD 1000000007
#define MAX 25
using namespace std;
 
typedef long long ll;
typedef pair<int, int> ii;
 
int Set(int mask, int pos){return mask = mask | (1<<pos);}
bool check(int mask, int pos){return (bool)(mask & (1<<pos));}

int dist[MAX][MAX], grid[MAX][MAX], vis[MAX][MAX];
int fx[] = {1, -1, 0, 0};
int fy[] = {0, 0, 1, -1};
int n, m;

int bfs(int sx, int sy)
{
    memset(vis, 0, sizeof(vis));
    vis[sx][sy] = 1;
    dist[sx][sy] = 0;
    int maxDist = 0;

    queue<ii> q;
    q.push(mk(sx, sy));

    while(!q.empty()){
        ii u = q.front();
        q.pop();

        for(int i = 0; i < 4; i++){
            int tx = u.ff + fx[i];
            int ty = u.ss + fy[i];
            if(tx >= 0 && tx < n && ty >= 0 && ty < m && !vis[tx][ty] && grid[tx][ty] != -1){
                vis[tx][ty] = 1;
                dist[tx][ty] = dist[u.ff][u.ss] + 1;
                maxDist = max(maxDist, dist[tx][ty]);
                q.push(mk(tx, ty));
            }
        }
    }

    return maxDist;

}
int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    #ifdef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    
    cin>>n>>m;

    for(int i = 0; i < n; i++){
        string str;
        cin>>str;
        for(int j = 0; j < m; j++){
            if(str[j] == '#')
                grid[i][j] = -1;
        }
    }

    int ans = 0;

    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            if(grid[i][j] == 0)
                ans = max(ans, bfs(i, j));
        }
    }

    cout<<ans<<endl;


    return 0;
}

Measured memory_bytes: 256
# 2019/11/24
import sys
sys.setrecursionlimit(10**9)

n=int(input())
ab=[]
edge=[[] for _ in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    a,b=a-1,b-1
    ab.append((a,b))
    edge[a].append(b)

ans={}
def solve(p,c):
    global ans
    cnt=1
    for vtx in edge[p]:
        while c==cnt:
            cnt+=1
        ans[(p,vtx)]=cnt
        solve(vtx,cnt)
        cnt+=1

solve(0,0)
print(max(ans.values()))
for e in ab:
    print(ans[e])


Measured memory_bytes: 76780
/************************Code by Hardik Aggarwal!!!!***********************************/

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define endl '\n'
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;

typedef long long int ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
vl g[200005];
ll a[200005];
void dfs(ll u,ll p)
{   
    a[u]+=a[p];
    for(auto v:g[u])
    {
        if(v!=p)
        {
            dfs(v,u);
        }
    }
}
int main()
{
    
    
   
    IOS
    ll n,q;
    cin>>n>>q;
    for(ll i=1;i<n;i++)
    {
        ll u,v;
        cin>>u>>v;
        g[u].pb(v);
        g[v].pb(u);
    }

    a[0]=0;
    memset(a,0,sizeof(a));
    while(q--)
    {
        ll p,x;
        cin>>x>>p;
        a[x]+=p;
    }

    dfs(1,0);
    for(ll i=1;i<=n;i++)
    {
        cout<<a[i]<<" ";
    }
    

}
    
 
    
    



Measured memory_bytes: 24320
A, B, M = input().split()
a_num = input()
b_num = input()
number = [input() for i in range(int(M))]

a_cost = []
b_cost = []

for a in a_num.split():
	a_cost.append(a)

for b in b_num.split():
    b_cost.append(b)


cal_box = []
# 番号が入る　冷蔵庫と電子レンジの組み合わせ
for i in range(int(M)):
    x, y, c = number[i].split()
        
    cal = int(a_cost[int(x)-1]) + int(b_cost[int(y)-1]) - int(c)
    cal_box.append(cal)

cal_box.append(int(min(a_cost)) + int(min(b_cost)))

print(int(min(cal_box)))

Measured memory_bytes: 29040
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
const long long INF = 1LL << 60;

int main() {
	int N, D;
	cin >> N >> D;
	vector<vector<int>> x(N, vector<int>(D, 0));
	REP(i, N) {
		REP(j, D) {
			cin >> x[i][j];
		}
	}

	int ans = 0;
	REP(i, N - 1) {
		FOR(j, i + 1, N) {
			int temp = 0;
			bool frag = false;
			REP(k, D) {
				temp += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
			}
			REP(l, 1000) {
				if (l*l == temp) {
					frag = true;
				}
			}
			if (frag) {
				ans++;
			}
		}
	}

	cout << ans << endl;


	return 0;
}

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

void operation(int& A, int& B);
int main()
{
	int A, B, K;
	cin >> A >> B >> K;
    for(int i=1; i<=K; i++)
    {
    	if(i%2==1)  // turn of A
    	{  
            operation(A,B); 
    	}
    	else // turn of B 
    	{
    		operation(B,A);
    	}
    }

    cout << A <<" "<<  B << endl;


   return 0;
}
void operation(int& A, int& B)
{
	if(A%2==1) {
        A--;
	}

	B += A/2;
	A /= 2;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
 int n;
 scanf("%d",&n);
 int i,j,k,ii;
 map<int,int>mp;
 for(ii=1;ii<=n;ii++)
 {
     scanf("%d",&i);
     j=i;
     if(i%2==0)
     {
          while(i%2==0)
          {
              i/=2;
          }
          mp[2]++;
     }

     for(k=3;(k*k)<=j;k+=2)
     {
         if(i%k==0)
         {
             while(i%k==0)
             {
                 i/=k;

             }
             mp[k]++;
         }
     }
     if(i>1)
     {
         mp[i]++;
     }
 }
 int maxi=0;

 map<int,int>::iterator it=mp.begin();
 for(it=mp.begin();it!=mp.end();it++)
 {
    maxi=max(maxi,it->second);
 }
 if((maxi==1)||(maxi==0))
 {
     printf("pairwise coprime");
 }
 else if(maxi<n)
 {
     printf("setwise coprime");
 }
 else
 {
     printf("not coprime");
 }
 return 0;
}


Measured memory_bytes: 7472
#include <bits/stdc++.h>
using namespace std;
int main(){
	map<int,int> r;
	long long ans = 0;
	r[0] = 1;
	int n, m; cin >> n >> m;
	long long sum = 0;
	for(int i = 0; i < n; i++){
		int x; cin >> x;
		sum += x; sum %= m;
		ans += r[sum];
		r[sum]++;
	}
	cout << ans << endl;
	return 0;
}


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

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

vint G[500];

signed main(){
    int N,M;
    while(cin>>N>>M,N||M){
            rep(i,N)G[i].clear();
    rep(i,M){
        int a,b;
        cin>>a>>b;
        a--;b--;
        G[a].pb(b);G[b].pb(a);
    }

    vint lis={0};
    rep(i,2){
        bool vis[500]={};
        for(auto v:lis){
            vis[v]=true;
            for(auto u:G[v])vis[u]=true;
        }
        lis=vint();
        rep(j,N)if(vis[j])lis.pb(j);
    }

    cout<<lis.size()-1<<endl;
    }
    return 0;
}

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

using namespace std;

int pow2(int n){
    int ret=1;
    for (int i = 0; i < n; ++i) {
        ret=ret*2;
    }
    return ret;
}

int main(){
    while(true){
        string s;
        cin>>s;
        if(s=="#")break;
        long long ans=0;
        int ansb=0;
        int ind=-1;
        if(s.back()=='h'){
            ans=0;
            ind=s.size()-5;
        }
        else {
            ans=90;
            ind=s.size()-4;
        }
        for (int i = ind-1; i >= 0; --i) {
            if(s[i]=='h'){
                ans=ans*2-90;
                ++ansb;
                i-=4;
            }
            else if(s[i]=='t'){
                ans=2*ans+90;
                ++ansb;
                i-=3;
            }
        }
        while(ansb>0&&ans%2==0){
            ans=ans/2;
            --ansb;
        }
        if(ansb==0)cout<<ans<<endl;
        else cout<<ans<<"/"<<pow2(ansb)<<endl;
    }
    return 0;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
  
int main() {
  vector<int> x(3);
  for(int i=0; i<3; i++){
    cin>>x.at(i);
  }
  sort(x.begin(), x.end());
  
  if(x.at(0)==5 && x.at(1)==5 && x.at(2)==7){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
  
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define inf 1000000000
#define md 1000000007
#define pb push_back
#define li 100005
#define lo long long
using namespace std;
int a,b;
int main(){
	scanf("%d %d",&a,&b);
	int say=a;
	if(b==1){
		printf("0\n");
		return 0;
	}
	for(int i=1;i<=1000;i++){
		if(say>=b){
			printf("%d\n",i);
			return 0;
		}
		say+=a;
		say-=1;
	}
	return 0;
}




Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# define MAX_W 20
# define MAX_H 20
# define INF (1e6)

int w, h;
int stage[MAX_H][MAX_W];

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

int sx, sy, gx, gy;

int dfs(int x, int y, int c) {
	int res = INF;
	if (c >= 10)
		return res;
	for (int i = 0; i < 4; ++i) {
		int nx = x + dx[i], ny = y + dy[i];
		if (nx < 0 || ny < 0 || nx >= w || ny >= h)
			continue;
		if (stage[ny][nx] == 1)
			continue;
		if (stage[ny][nx] == 3)
			return c + 1;
		while (1) {
			nx += dx[i];
			ny += dy[i];
			if (nx < 0 || ny < 0 || nx >= w || ny >= h)
				break;
			if (stage[ny][nx] == 3)
				return c + 1;
			else if (stage[ny][nx] == 1) {
				stage[ny][nx] = 0;
				res = std::min(res, dfs(nx - dx[i], ny - dy[i], c + 1));
				stage[ny][nx] = 1;
				break;
			}
		}
	}
	return res;
}

int main() {
	while (1) {
		std::cin >> w >> h;
		if (w == 0 && h == 0)
			break;
		for (int i = 0; i < h; ++i) {
			for (int j = 0; j < w; ++j) {
				std::cin >> stage[i][j];
				if (stage[i][j] == 2) {
					sx = j;
					sy = i;
					stage[sy][sx] = 0;
				}
				else if (stage[i][j] == 3) {
					gx = j;
					gy = i;
				}
			}
		}
		int res = (dfs(sx, sy, 0) == INF) ? -1 : dfs(sx, sy, 0);
		std::cout << res << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    vll water(31, 0);
    REP(i, 30){
        REP(j, 30){
            if(a * i + b * j > 30) continue;
            water[a * i + b * j] = 1;
        }
    }
    ll resw, ress, init = 1;
    REP(i, 31){
        if(!i || !water[i]) continue;
        ll w = 100 * i, s, bound = e * i;
        REP(j, 61){
            REP(k, 61){
                s = c * j + d * k;
                if(w + s > f || s > bound || !s) continue;
                if(init){
                    init = 0;
                    resw = w;
                    ress = s;
                }
                else if(s * (resw + ress) > ress * (w + s)){
                    resw = w;
                    ress = s;
                }
            }
        }
    }
    if(init){
        cout << a * 100 << " " << 0 << endl;
        return 0;
    }
    cout << resw + ress << " " << ress << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
typedef long long ll;
typedef pair<ll,ll> P;
#define se second
#define fi first
struct PP{ll fi;ll se;ll th;};
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
bool chmin(auto &a,auto b){if(a>b){a=b;return true;}return false;}
bool chmax(auto &a,auto b){if(a<b){a=b;return true;}return false;}
void outvi(vi v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
void outvvi(vvi v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}
int main(){
    ll n;cin>>n;
    ll a=n/100,b=n%100;
    if(a*5>=b)cout<<1<<endl;
    else cout<<0<<endl;
}

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

int main(){
  int n;
  cin>>n;
  double a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  
  double b=0;
  for(int i=0;i<n;i++){
    b+=1/a[i];
  }
  cout<<setprecision(12)<<1/b<<endl;
}

Measured memory_bytes: 768
n=int(input())
A=list(map(int,input().split()))
A=sorted(A)
MOD=10**9+7
if n%2==1:
    for i in range(n):
        if A[i]!=((i+1)//2)*2:
            print(0)
            exit()
else:
    for i in range(n):
        if A[i]!=(i//2)*2+1:
            print(0)
            exit()

print(2**(n//2)%MOD)

Measured memory_bytes: 52844
#include<bits/stdc++.h> 
  
using namespace std; 
  
int count( int S[], int m, int n ) 
{ 
    int i, j, x, y; 
    int table[n + 1][m]; 
    for (i = 0; i < m; i++) 
        table[0][i] = 1; 
    for (i = 1; i < n + 1; i++) 
    { 
        for (j = 0; j < m; j++) 
        { 
            x = (i-S[j] >= 0) ? table[i - S[j]][j] : 0; 
            y = (j >= 1) ? table[i][j - 1] : 0; 
            table[i][j] = x + y; 
        } 
    } 
    return table[n][m - 1]; 
} 
int main() 
{ 
    int arr[] = {100,101,102,103,104,105}; 
    int m =6;
    int n;
    cin>>n;
    int k=count(arr, m, n); 
    if(k==0)
    cout<<"0";
    else
    cout<<"1";
    return 0; 
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>

using namespace std;

void solve()
{
	int n;
	while (cin >> n, n)
	{
		int point = 0;
		int before = 2;
		int flag[2] = { 0 };
		for (int i = 0; i < n; ++i)
		{
			string s;
			cin >> s;
			if (s == "lu")
			{
				flag[0] = 1;
			}
			else if (s == "ld")
			{
				flag[0] = 2;
			}
			else if (s == "ru")
			{
				flag[1] = 1;
			}
			else if (s == "rd")
			{
				flag[1] = 2;
			}
			if ((flag[0] == 1 && flag[1] == 1 && before == 2) || (flag[0] == 2 && flag[1] == 2 && before == 1))
			{
				++point;
				flag[0] = 0;
				flag[1] = 0;
				if (before == 1)
				{
					before = 2;
				}
				else if (before == 2)
				{
					before = 1;
				}
			}
		}
		cout << point << endl;
	}
}

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

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

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

	vector<int> v(n);

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

	int ans;
	int tmp = 1;
	int cnt = 0;
	while (true) {

		cnt++;
		tmp = v[tmp - 1];

		if (tmp == 2) break;

		if(n < cnt){
			cnt = -1;
			break;
		}

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

Measured memory_bytes: 640
# 15
# ABC145 C Average Length

import itertools
import math

n = int(input())
xy_l = [[int(x) for x in input().split()] for y in range(n)]

per = itertools.permutations(list(range(n)))
num = math.factorial(n)
ans = 0
for order in per:
    _sum = 0
    for i in range(n-1):
        _sum += ((xy_l[order[i]][0] - xy_l[order[i+1]][0])**2
                 + (xy_l[order[i]][1] - xy_l[order[i+1]][1])**2)**0.5
    ans += _sum
print(ans/num)

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

using namespace std;
typedef long long ll;

int main(){
  int n;
  cin >> n;
  int ans=0;
  int v[n],c[n];
  rep(i,n){
    cin >> v[i];
  }
  rep(i,n){
    cin >> c[i];
  }
  rep(i,n){
    if(v[i]>c[i]){
      ans+=v[i]-c[i];
    }
  }
  cout << ans << endl;

}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

vector<int> Div(int n) {
    vector<int> ret;
    for(int i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);

            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

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

    int npos = 0; // 文字列の何文字目か
    int cnt = 0; // 何個繋げたか

    vector<int> v[26];
    for(int i = 0; i < s.size(); ++i) {
        v[s[i] - 'a'].pb(i);

    }

    for(int i = 0; i < t.size(); ++i) {
        int al = t[i] - 'a';
        if(v[al].size() == 0) {
            cout << -1 << endl;
            return 0;

        }

        auto p = lower_bound(all(v[al]), npos);
        if(p == v[al].end()) {
            ++cnt;
            npos = 0;
            p = lower_bound(all(v[al]), npos);

        }
        npos = (*p) + 1;
        if(npos == s.size()) {
            ++cnt;
            npos = 0;

        }
    }
    cout << LL(s.length()) * LL(cnt) + npos << endl;
    return 0;
}



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

int main(void)
{
    long long N;
    cin >> N;
    vector<long long> f(N+1);

    for (long long x = 1; x <= 100; x++)
    {
        for (long long y = 1; y <= 100; y++)
        {
            for (long long z = 1; z <= 100; z++)
            {
                long long num = pow(x, 2) + pow(y,2) + pow(z, 2) + x * y + y * z + z * x;
                if (num <= N)
                {
                    f[num]++;
                }
            }
        }
    }

    for (long long i = 1; i < N+1; i++)
    {
        cout << f[i] << endl;
    }
}

Measured memory_bytes: 3576
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		List<Integer> list1 = new ArrayList<>();
		List<Integer> list2 = new ArrayList<>();
		for(int i = 0; i < a; i++){
			int e= sc.nextInt();
			list1.add(e);
		}
		for(int i = 0; i< b; i++){
			int f = sc.nextInt();
			list2.add(f);
		}
		Collections.sort(list1);
		Collections.sort(list2);
		for(int i = c+1; i<=d; i++){
			if(list1.get(a-1)<i && list2.get(0)>=i){
				System.out.println("No War");
				return;
			}
		}
		System.out.println("War");
	}
}

Measured memory_bytes: 23764
#include<iostream>
long long t[1001]={0},a[1001]={0};
using namespace std;
int main()
{
	long long n,yes,no,b;
	cin>>n;
	for(long long i=1;i<=n;i++)
	{ 
		cin>>t[i];
		cin>>a[i];
	} 
	for(long long i=1;i<=n;i++)
	{ 
		if(t[i]<=t[i-1]||a[i]<=a[i-1])
		{
			if(t[i-1]%t[i]!=0)
			{
				yes=1;
			}
			else
			{
				yes=0;
			}
			if(a[i-1]%a[i]!=0)
			{
				no=1;
			}
			else
			{
				no=0;
			}
			b=max(a[i-1]/a[i]+no,t[i-1]/t[i]+yes);
			t[i]=b*t[i];
			a[i]=b*a[i];
		}
	} 
	cout<<t[n]+a[n];
	return 0;
} 

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

#define INF ll(1e18)
typedef long long ll;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	int n,m; cin>>n>>m;
	ll d[m];
	ll dp[n+1];
	
	for(int i=0;i<m;i++){
		cin>>d[i];
	}
	
	dp[0]=0;
	for(int i=1;i<=n;i++){
		dp[i]=INF;
	}
	
	for(int i=1;i<=n;i++){
		for(int j=0;j<m;j++){
			if(i-d[j]>=0){
				dp[i]=min(dp[i],dp[i-d[j]]+1);
			}
		}
	}
	
	cout<<dp[n]<<'\n';
	
	return 0;
}



Measured memory_bytes: 3600
import sys
input = sys.stdin.readline


def main():
    x, k, d = map(int, input().split())
    x = abs(x)
    step = x // d
    if step >= k:
        ans = x - d * k
        print(ans)
        return

    k -= step
    x = x - step * d
    k %= 2
    ans = abs(x - d*k)
    print(ans)


if __name__ == "__main__":
    main()


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

int main() {
  string s;
  cin >> s;
  long long int L=s.size();
  long long sum=0;
  for (int i = 0; i < L; ++i) {
    int j = s[i] - '0';
    sum=sum+j;  
    }
  if (sum % 9 ==0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << min(a, b) + min(c, d) << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

class UnionFind():
    """unionFindツリー
    FindとUnionがきも
    https://note.nkmk.me/python-union-find/
    """
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

N,M = map(int, input().split())

uf = UnionFind(N+M)
for i in range(N):
  li = list(map(int, input().split()))
  for j in li[1:]:
    uf.union(i,N+j-1)
    
p = uf.find(0)
for i in range(1,N):
  q = uf.find(i)
  #print(p,q)
  if p != q:
    print("NO")
    exit(0)
    
print("YES")

Measured memory_bytes: 15724
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int[] input = new int[N];
            for (int i = 0; i < N; i++) {
                input[i] = sc.nextInt();
            }
            int cnt = 0;

            //Bubble Sort
            boolean flag = true;
            while (flag) {
                flag = false;
                for (int i = N - 1; i > 0; i--) {
                    if (input[i] < input[i - 1]) {
                        int tmp = input[i];
                        input[i] = input[i - 1];
                        input[i - 1] = tmp;
                        cnt++;
                        flag = true;
                    }
                }
            }
            System.out.print(input[0]);
            for (int i = 1; i < N; i++) System.out.print(" " + input[i]);
            System.out.println();
            System.out.println(cnt);
        }
    }
}


Measured memory_bytes: 26416
# include <stdio.h>
int main ()
{
  int N,T,A,X;
scanf ("%d%d%d",&N ,&T ,&A);
int res =0;
int cc = 1<<30;
for(int i =1;i <=N;i ++)
{
scanf ("%d",&X);
int d=(T *1000 -X*6) -A *1000;
if(d <0)d=-d;
if(cc > d)
  cc=d,res=i;
}
printf ("%d\n",res );
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <stack>
#include <vector>
using namespace  std;

struct StDtl
{
  int m_nLeft;

  StDtl(int nLeft) :
    m_nLeft(nLeft)
  { }
};

struct StSum
{
  int m_nLeft;
  int m_nRight;
  int m_nArea;

  StSum(int nLeft, int nRight, int nArea) :
    m_nLeft(nLeft), m_nRight(nRight), m_nArea(nArea)
  { }
};

void fnCroSecSet(stack<StDtl> &rskoDtl, vector<StSum> &rvoSum, int &rnTotalArea)
{
  string sCrossSect;
  cin >> sCrossSect;

  for (int i = 0; i < sCrossSect.size(); i++)
  {
    if (sCrossSect[i] == '\\')
    {
      StDtl oDtl(i);
      rskoDtl.push(oDtl);
    }
    else if (sCrossSect[i] == '/')
    {
      if (rskoDtl.size() > 0)
      {
        int nLeft = rskoDtl.top().m_nLeft; rskoDtl.pop();
        int nSum = i - nLeft; 
        rnTotalArea += nSum;

        while (rvoSum.size()  &&
               nLeft < rvoSum.back().m_nLeft  &&
               rvoSum.back().m_nRight < i       )
        {
          nSum += rvoSum.back().m_nArea;
          rvoSum.pop_back();
        }
        StSum oSum(nLeft, i, nSum);
        rvoSum.push_back(oSum);
      }
      else;
    }
  }
}

void  fnCroSecGet(const vector<StSum> &cnrvoSum, int nTotalArea)
{
  cout << nTotalArea << endl;
  cout << cnrvoSum.size();
  if (cnrvoSum.size() > 0)
  {
    cout << " ";
    for (auto itvoSum = begin(cnrvoSum); itvoSum != end(cnrvoSum); ++itvoSum)
    {
      if (itvoSum != begin(cnrvoSum)) cout << " ";
      cout << itvoSum->m_nArea;
    }
  }
  cout << endl;
}

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

  stack<StDtl> skoDtl;
  vector<StSum> voSum;
  int nTtlAra = 0;

  fnCroSecSet(skoDtl, voSum, nTtlAra);
  fnCroSecGet(voSum, nTtlAra);

  return 0;
}

Measured memory_bytes: 3244
package main

import "bufio"
import "fmt"
import "os"
import "sort"
import "strconv"

//============================================================
var sc = bufio.NewScanner(os.Stdin)

func setScSplit() { sc.Split(bufio.ScanWords) }
func readStr() string {
  sc.Scan()
  return sc.Text()
}
func readInt() int {
  i, _ := strconv.Atoi(readStr())
  return i
}
func readFloat() float64 {
  f, _ := strconv.ParseFloat(readStr(), 64)
  return f
}

func uniq(list []int) []int {
  m := make(map[int]struct{}) // 空のstructを使う

  for _, ele := range list {
    m[ele] = struct{}{} // m["a"] = struct{}{} が二度目は同じものとみなされて重複が消える。
  }

  uni := []int{}
  for i := range m {
    uni = append(uni, i)
  }
  return uni
}

//=============================================================

func main() {
  setScSplit()
  n := readInt()
  list := []int{}
  for i := 0; i < n; i++ {
    list = append(list, readInt())
  }
  sort.Sort(sort.IntSlice(list))
  list = uniq(list)
  fmt.Println(len(list))

}


Measured memory_bytes: 640
#include<cstring>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<queue>
#include<string>
#define fi first
#define se second
#define ll long long
#define INF 0x3f3f3f
using namespace std;
int main (void)
{
    int a,b,t;
    t=0;
    scanf("%d%d",&a,&b);
    for(;;)
    {
        if(a<=0)
            break;
        a-=b;
        t++;

    }
    printf("%d\n",t);
    return 0;
}


Measured memory_bytes: 256
//** aman**/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b) for(int i=a;i<b;i++)
#define lb lower_bound
#define ub upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
int main(){
	ll n;cin>>n;
	ll a[5];
	ll mi=1e16;
	for(ll i=0;i<5;i++){
		cin>>a[i];
		mi=min(mi,a[i]);
	}
	//cout<<n/mi<<endl;
	ll ans=0;
	if(n%mi==0)ans=4LL+n/mi;
	else ans=5LL+n/mi;
	cout<<ans<<endl;
}

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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
// 出力は.xで！！！！

int main(){
  int n,k; cin >> n >> k;
  mint ans=0;
  vector<mint> sums(n+2);
  sums[0]=sums[1]=0;
  rep(i,n) sums[i+2]=sums[i+1]+i+1;
  for(int i=n+1; i>=k; i--) ans+=sums[n+1]-sums[n+1-i]-sums[i]+1;
  cout << ans.x << endl;
return 0;
}

Measured memory_bytes: 4760
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define stpr setprecision
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ld EPS=10e-8;
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

ll N,A[107][107];
ll DKSTR[107],chek[107];

void dikstra(){
    DKSTR[0]=0;
    ll C=1,key=0;
    vector<pair<ll,ll>> V;
    while(C<N){
        chek[key]=1;
        V.clear();
        rep(i,N){
            DKSTR[i]=min(DKSTR[i],DKSTR[key]+A[key][i]);
            if(chek[i]==0){
                V.pb(mp(DKSTR[i],i));
            }
        }
        sort(ALL(V));
        while(1){
            key=V[0].second;
            C++;
            break;
        }
    }
}

int main(){
    ll X,Y,a,b;
    cin>>N;
    rep(i,N+1){
        rep(j,N+1){
            A[i][j]=MOD;
        }
        DKSTR[i]=MOD;
    }
    rep(i,N){
        cin >> X >> Y;
        rep(j,Y){
            cin >> a >> b;
            A[X][a]=b;
        }
    }
    dikstra();
    rep(i,N){
        cout << i << " " << DKSTR[i] << endl;
    }
}


Measured memory_bytes: 3180
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	vector<int> ar1(n), ar2(n);
	for(int i=0;i<n;i++){
		cin>>ar1[i];
	}
	for(int i=0;i<n;i++){
		cin>>ar2[i];
	}
	vector<int> v(n);
	for(int i=0;i<n;i++){
		v[i] = i+1;
	}
	
	long i = 0L,a,b;
	do {
		i++;
		if(v == ar1)
			a = i;
		if(v == ar2)
			b = i;
	}while(next_permutation(v.begin(), v.end()));
	cout<<abs(a-b);
 	return 0;
}


Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
xs = gets.split.map(&:to_i)
ys = gets.split.map(&:to_i)

MOD = 1000000007
def calc(xs)
    n = xs.length
    num = 0
    val = 0
    sum = 0
    (1...n).each{|i|
        d = xs[i] - xs[i-1]
        num +=1
        num %= MOD
        val += num * d
        val %= MOD
        sum += val
        sum %= MOD
    }
    return sum
end
    
xret = calc(xs)
yret = calc(ys)

puts (xret * yret) % MOD


Measured memory_bytes: 17424
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>

using namespace std;

int main() {
	string str1, str2, str3;

	cin >> str1 >> str2 >> str3;

	cout << str1[0] << str2[0] << str3[0] << endl;









	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp(a, b) make_pair(a, b)
#define ls (rt << 1)
#define rs (rt << 1 | 1) 
typedef pair<int, int> pii; 
const ll mod = 1e9 + 7;
template <class T> T lowbit(T x){return ((x)&(-(x)));}
const int maxn = 2e5 + 10;
int n, m, tot, sum;
int a[maxn];
int main()
{
	cin >> n >> m;
	for(int i = 1; i <= n; ++i) cin >> a[i], sum += a[i];
	for(int i = 1; i <= n; ++i)
		if(a[i] * 4 * m >= sum)
			++tot;
	if(tot >= m)
		puts("Yes");
	else
		puts("No");
	return 0;
}

Measured memory_bytes: 256
a, b, c = input().split()
A = int(a)
B = int(b)
C = int(c)
 
if A == B or A == C:
    if B != C:
        print("Yes")
    else:
        print("No")
elif B == C:
    if A != B:
        print("Yes")
else:
    print("No")

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

// template {{{
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1)
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

void solver() {
    string s;
    cin >> s;

    vector< int > ans(s.size(), 1);
    range(i, 0, s.size() - 2) {
        if (s[i] == 'L') continue;
        if (s[i + 1] == 'L') continue;

        ans[i + 2] += ans[i];
        ans[i] = 0;
    }

    rrange(i, 2, s.size()) {
        if (s[i] == 'R') continue;
        if (s[i - 1] == 'R') continue;

        ans[i - 2] += ans[i];
        ans[i] = 0;
    }

    cout << ans << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 3868
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL N; cin >> N;
		vector<LL> A(N + 1); A[0] = 0;
		rep(i, N) { cin >> A[i + 1]; A[i + 1] += A[i]; }
		sort(A.begin(), A.end());
		LL p = A[0] - 1;
		ULL n = 0;
		ULL ans = 0;
		rep(i, N + 1) {
			//cout << A[i] << " ";
			if (p == A[i]) { ans += n; n++; }
			else { n = 1; p = A[i]; }
		}
		//cout << endl;
		cout << ans << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

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

using namespace std;
/*******************************************
****************** BY **********************
******* FUTURE GOOGLE EMPLOYEE *************
****** KARTHICK KUPPURAJ M *****************
********************************************/
#define ms(s, n) memset(s, n, sizeof(s))
#define pb push_back
#define pf push_front
#define mp make_pair
#define f first
#define s second
#define prec(n) fixed<<setprecision(n)
#define sll(x) scanf("%lld",&x);
#define pll(x) printf("%lld",x);
#define pn printf("\n");
#define ps printf(" ");
#define pc(c) printf("%c",c);
typedef long long int ll;
#define EPS 1e-9
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
set<pair<int, int>> st;
const int MAX = 5e5 + 2;
int p[MAX],t[MAX];
struct Node
{
    int l, r;
} a[MAX];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, k;
    cin >> n >> k;
    st.insert(mp(n + 1, n + 1));
    for (int i = 1; i <= n; ++i)
    {
        cin >> p[i];
        st.insert(mp(p[i], i));
        if (i - k > 0)
        {
            st.erase(mp(p[i - k], i - k));
        }
        t[i] = (*st.upper_bound(mp(p[i],i))).second;
        //cout<<t[i]<<" ";
    }
    int end = n + 1;
    int open = n + 2;
    a[open].r = end;
    a[end].l = open;
    for (int i = 1; i <= n; ++i)
    {
        a[i].r = t[i];
        a[i].l = a[t[i]].l;
        a[a[t[i]].l].r = i;
        a[t[i]].l = i;

    }
    for (int i = a[open].r, c = 1; i != end; i = a[i].r, c++)
    {
        p[i] = c;
    }
    for (int i = 1; i <= n; ++i)
    {
        cout << p[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 34816
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int a[3],k;
	cin>>a[0]>>a[1]>>a[2]>>k;
	sort(a,a+3);
	for(int i=0;i<k;i++){
	    a[2] *= 2;
	}
	cout<<a[0]+a[1]+a[2]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#define int long long
const int INF = 1e9;

signed main() {
    int N;
    cin >> N;
    vector<pair<int, int>> A;
    for (int i = 0; i < N; i++) {
        int e; cin >> e;
        A.emplace_back(e, i);
    }
    A.emplace_back(INF, -1);
    
    int cnt = 1;
    int ans = 1;
    sort(A.begin(), A.end());
    for (int i = 1; i <= N; i++) {
        if (A[i-1].second < A[i].second) cnt++;
        else {
            ans = max(ans, cnt);
            cnt = 1;
        }
    }
    ans = N-ans;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2420
//Priority Queue
#include <iostream>

using namespace std;

const int MAX = 2000000;
int H = 0;
int A[MAX + 1];

int parent(int i) {
    return i / 2;
}

int left(int i) {
    return 2 * i;
}

int right(int i) {
    return 2 * i + 1;
}

void maxHeapify(int i) {
    int l = left(i);
    int r = right(i);

    int largest = i;
    if(l < (H + 1) && A[largest] < A[l]) largest = l;
    if(r < (H + 1) && A[largest] < A[r]) largest = r;

    if(largest != i) {
        swap(A[i], A[largest]);
        maxHeapify(largest);
    }
}

void insert(int k) {
    H++;
    A[H] = k;
    int i = H;
    while(parent(i) > 0 && A[parent(i)] < A[i]) {
        swap(A[i], A[parent(i)]);
        i = parent(i);
    }
}

int extract() {
    int k = A[1];
    A[1] = A[H];
    H--;
    maxHeapify(1);
    return k;
}

int main() {
    int k;
    string opr;
    while(1) {
        cin >> opr;
        if(opr == "insert") {
            cin >> k;
            insert(k);
        }
        else if(opr == "extract") {
            cout << extract() << endl;
        }
        else if(opr == "end") {
            break;
        }
    }
}


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

using namespace std;

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

vector<long long> a, b, c;
unordered_set<string> vis;
int x, y, z, k;

bool hashval(int a, int b, int c){
    string A = to_string(a) + " " + to_string(b) + " " + to_string(c);

    if(vis.find(A) != vis.end())
        return false;

    vis.insert(A);
    return true;
}

int main(){

    cin.sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

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

    cin >> x >> y >> z >> k;

    // merge k list

    for(int i = 0; i < x; ++i){
        long long j;
        cin >> j;
        a.push_back(j);
    }
    for(int i = 0; i < y; ++i){
        long long j;
        cin >> j;
        b.push_back(j);
    }
    for(int i = 0; i < z; ++i){
        long long j;
        cin >> j;
        c.push_back(j);
    }

    --x; --y; --z;

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());

    priority_queue<pair<long long, pair<int, pair<int, int>>>> q;
    q.push(make_pair(a[x] + b[y] + c[z], make_pair(x, make_pair(y, z))));

    pair<long long, pair<int, pair<int, int>>> state;

    while(k--){

        state = q.top();
        q.pop();

        cout << state.first << "\n";

        x = state.second.first; y = state.second.second.first; z = state.second.second.second;

        if(x > 0 && hashval(x - 1, y, z))
            q.push(make_pair(a[x - 1] + b[y] + c[z], make_pair(x - 1, make_pair(y, z))));
        if(y > 0 && hashval(x, y - 1, z))
            q.push(make_pair(a[x] + b[y - 1] + c[z], make_pair(x, make_pair(y - 1, z))));
        if(z > 0 && hashval(x, y, z - 1))
            q.push(make_pair(a[x] + b[y] + c[z - 1], make_pair(x, make_pair(y, z - 1))));

    }

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
 
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 
 ///解説AC
  int main(){      
      lint n;
      cin>>n;
      lint num=6;
      rep(i,n){
          num+=5;
          if(primary(num))cout<<num<<" ";
          else --i;
      }
      }
      
    

  
          
  

Measured memory_bytes: 256