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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

template<class T>inline bool chmax(T &a, const T &b) { if (b > a) { a = b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int N;
    cin >> N;
    vector<string> S(N);
    for (int i=0; i<N; ++i) cin >> S[i];

    for (int i=0; i<N; ++i) reverse(S[i].begin(), S[i].end());
    sort(S.begin(), S.end(), [](auto a, auto b){return (int)a.size() > (int)b.size();});

    map<string, vector<int>> mp;
    ll res = 0;
    int cur = (int)S.front().size();
    for (int i=0; i<N; ++i) {
        int len = (int)S[i].size();
        if (cur >= len) {
            int dif = cur - len + 1;
            map<string, vector<int>> tmp;
            for (auto iter=mp.begin(); iter!=mp.end(); ++iter) {
                string s = iter->first;
                vector<int> v = iter->second;
                string sub = s.substr(0, (int)s.size()-dif);
                for (int j=0; j<dif; ++j) v[*(s.end()-dif+j) - 'a'] = v.back();
                if ((int)tmp[sub].size() == 0) {
                    tmp[sub] = v;
                } else {
                    vector<int> &vv = tmp[sub];
                    for (int j=0; j<27; ++j) vv[j] += v[j];
                }
            }
            mp.swap(tmp);
            cur -= dif;
        }
        string sub = S[i].substr(0, len-1);
        int pla = S[i].back() - 'a';
        if (mp[sub].size() == 0) mp[sub].assign(27, 0);
        else res += mp[sub][pla];
        vector<int> &v = mp[sub];
        ++v[pla];
        ++v.back();
    }

    cout << res << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 37264
#include<stdio.h>
#include<string.h>
int main()
{
    int i,j;
    char s[2][3];
    for(i=0; i<2; i++)
        for(j=0; j<4; j++)
            scanf("%c",&s[i][j]);
    if(s[0][0]==s[1][2]&&s[0][1]==s[1][1]&&s[0][2]==s[1][0])
        printf("YES\n");
    else
        printf("NO\n");

}

Measured memory_bytes: 128
#include "bits/stdc++.h"

using namespace std;

vector<int> parents;
vector<int> ranks;

void init(int n) {
    parents = vector<int>(n, 0);
    ranks = vector<int>(n, 0);
    for (int i = 0; i < n; ++i) {
        parents[i] = i;
    }
}

int find(int x) {
    if (parents[x] == x) {
        return x;
    }
    else {
        parents[x] = find(parents[x]);
        return parents[x];
    }
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) {
        return;
    }

    if (ranks[x] < ranks[y]) {
        parents[x] = y;
    }
    else if (ranks[x] > ranks[y]) {
        parents[y] = x;
    }
    else {
        parents[y] = x;
        ++ranks[x];
    }
}

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

void Main() {
    int N;
    cin >> N;
    vector<pair<int, int>> x(N, make_pair(0, 0)), y(N, make_pair(0, 0));
    for (int i = 0; i < N; ++i) {
        cin >> x[i].first >> y[i].first;
        x[i].second = i;
        y[i].second = i;
    }

    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    vector<pair<int, pair<int, int>>> diffs;
    for (int i = 1; i < N; ++i) {
        int xdiff = abs(x[i].first - x[i - 1].first);
        int ydiff = abs(y[i].first - y[i - 1].first);
        diffs.push_back(make_pair(xdiff, make_pair(x[i - 1].second, x[i].second)));
        diffs.push_back(make_pair(ydiff, make_pair(y[i - 1].second, y[i].second)));
    }
    sort(diffs.begin(), diffs.end());

    init(N);
    long long ans = 0LL;
    for (int i = 0; i < diffs.size(); ++i) {
        int a = diffs[i].second.first;
        int b = diffs[i].second.second;
        int cost = diffs[i].first;
        if (!same(a, b)) {
            unite(a, b);
            ans += (long long)cost;
        }
    }
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 7996
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
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); }
//SOLVE

void solve(void)
{
  int H,W,N;cin>>H>>W>>N;
  int ix,iy;cin>>ix>>iy;
  ix--;iy--;
  string S,T;cin>>S>>T;
  int L = 0;int R = W;
  bool check = true;
  if(S[N-1] =='L')++L;
  if(S[N-1] =='R')--R;
  for (int i = N-2; i >= 0; i--) 
  {
    if(T[i] == 'L') R = min(R+1,W);
    else if(T[i] =='R') L = max(0LL,L-1);
    if(S[i] == 'L') L = L = L+1;
    else if(S[i] =='R') R = R - 1;;
    if(L >= R)check = false;
  }
  if(iy < L || iy >= R)check = false;
  L = 0,R = H;
  if(S[N-1] =='U')++L;
  if(S[N-1] =='D')--R;
  for (int i = N-2; i >= 0; i--) 
  {
    if(T[i] == 'U') R = min(R+1,H);
    else if(T[i] =='D') L = max(0LL,L-1);
    if(S[i] == 'U') L = L = L+1;
    else if(S[i] =='D') R = R - 1;;
    if(L >= R)check = false;
  }
  if(ix < L || ix >= R)check = false;

  if(check)
  {
    cout<<"YES"<<endl;
  }
  else
  {
    cout<<"NO"<<endl;
  }
  
  
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


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

using ll = long long;
using ull = unsigned long long;

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll yens;
    cin>>yens;

    ll yen500 = yens/500;
    ll yen5 = (yens%500)/5;

    cout<<yen500*1000 + yen5 * 5<<'\n';

    return 0;
}

Measured memory_bytes: 256
import java.io.*
import java.util.*

fun solve(N: Int, s: Array<String>){
    s.map{ it.toList().sorted().joinToString() }
        .groupBy{ it }
        .map{ it.value.size.toLong() }
        .map{ it*(it-1)/2 }
        .sum()
        .let{ println(it) }
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    val s = StringArray(N)
    for (i in 0 until N) {
        s[i] = sc.next()
    }
    solve(N, s)
}



Measured memory_bytes: 92280
#include<bits/stdc++.h>
using namespace std;
int n,m;

struct node
{
    int a,b;
}manx[100005];
bool cmp(node kp,node pk)
{
    return kp.a < pk.a;
}
int main()
{
    cin >> n >> m;
    for(int i = 0 ; i < n ; i ++ )
    {
        cin >> manx[i].a >> manx[i].b;
    }
    sort(manx,manx + n,cmp);
    priority_queue<int>q;
    int sum = 0,num = 0;
    for(int i = 1 ; i <= m ; i ++ )
    {
        while(1){
            if(manx[num].a <= i && num < n)
            {
                q.push(manx[num].b);
                num ++ ;
            }
            else
                break;
        }
        if(!q.empty())
        {
            sum += q.top();
            q.pop();
        }
        else
            continue;

    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1660
/******************************************
* NICK : nikhilsinghh59 *
******************************************/


#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"

#define PB push_back
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
const int M = 1e9+7;

int main()
{   
    
    ll n;
    cin >> n;
    
    ll ar[n];
    bool present[n] = {false};
    //map<ll , ll>mp;
    ll mp[1000006];
    
    for(int i=0 ; i<1000006 ; i++) mp[i] = -1;
    
    //map<ll , ll>ct;
    
    for(int i=0;i<n;i++){
        cin >> ar[i];
        //ct[ar[i]]++;
    }
    sort(ar , ar+n);
    
    for(ll i=0;i<n;i++){
        //cin >> ar[i];
        if(mp[ar[i]]!=-1) {
            //cout << mp[ar[i]] << endl;
            present[i] = true;
            present[mp[ar[i]]-1] = true;
        }
        mp[ar[i]] = i+1;
    }
    
    for(ll i=0;i<n;i++){
        //cout << present[i] << endl;
        if(i!=0 && ar[i]==ar[i-1]) continue;
        ll ele = ar[i];
        //if(present[i]) continue;
        ll t = ele+ele;
        while(t < 1000006) {
            if(mp[t]!=-1){
                present[mp[t]-1] = true;
            }
            t+=ele;
        }
    }
    
    ll ans=0;
    
    for(ll i=0;i<n;i++){
        ans+=(present[i]==false);
        //cout << present[i] << " ";
    }
    cout << ans;
    
    return 0;
}

Measured memory_bytes: 13156
N = int(input())
ct ,cx, cy = (0, 0, 0) #Current t,x, y
for i in range(N):
    get = input().split()
    nt = int(get[0])
    nx = int(get[1]) #Next x, y
    ny = int(get[2])
    dt, dx, dy = nt - ct, nx - cx, ny - cy
    if dt < dx + dy:
        print("No")
        break
    elif dt > dx + dy and (dt - (dx + dy)) % 2 == 1:
        print("No")
        break
    ct = nt
    cx = nx
    cy = ny
else:
    print("Yes")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
const ll MOD=1e9+7;

int main() {
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> dp(n+1,1);
    rep(i,n-1) dp[i+2]=dp[i+1]+dp[i]; 
    cout << dp[n] << endl;
    
    return 0;
}


Measured memory_bytes: 3120
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

void push(int);
int pop(void);

int s[100];
int t;

int main()
{
  int a,b,n;
  char C[100];
  t = 0;
  while(scanf("%s",C)!=EOF)
    {
      if(C[0]=='+')
	{
	  a = pop();
	  b = pop();
	  push(a+b);
	}
      else if(C[0] == '-')
	{
	  b = pop();
	  a = pop();
	  push(a-b);
	}
      else if(C[0] == '*')
	{
	  a = pop();
	  b = pop();
	  push(a*b);
	}
      else
	{
	  n = atoi(C);
	  push(n);
	}
    }
  printf("%d\n",pop());
  return 0;
}

void push(int x)
{
  s[++t]=x;
}

int pop(void)
{
  t--;
  return s[t+1];
}



Measured memory_bytes: 2144
#include <stdio.h>
                                                                                                
  
int main(void){
                                                                                                
   
    long long n, a, b;
         
   
    scanf("%lld %lld %lld", &n, &a, &b );


    if( n == 1 ){

        if( a != b ){

            printf("0\n");

            return 0;

            }

        else printf("1\n");

             return 0;

        }

    else if( a > b ){

         printf("0\n");

         return 0;

         }  

    else printf("%lld\n", ( a - b ) * ( 2 - n ) + 1 );


    return 0;
                                                          
}

Measured memory_bytes: 128
//Electro-Fly
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

ll a1, a2, a3, m1, m2, m3;

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

int main(){
  while(cin>>a1>>m1>>a2>>m2>>a3>>m3){
    if(a1==0 && m1==0 && a2==0 && m2==0 && a3==0 && m3==0)break;
    ll b1=1, b2=1, b3=1;
    ll t1=a1, t2=a2, t3=a3;
    while(t1!=1){t1=(t1*a1)%m1; b1++;}
    while(t2!=1){t2=(t2*a2)%m2; b2++;}
    while(t3!=1){t3=(t3*a3)%m3; b3++;}
    ll g1=gcd(min(b1, b2), max(b1, b2));
    b1=b1*(b2/g1);
    ll g2=gcd(min(b1, b3), max(b1, b3));
    cout<<b1*(b3/g2)<<endl;
  }
  return 0;
}

Measured memory_bytes: 1156
# ABC138D - Ki (main, dfs, global variables)
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def dfs(v: int, p: int) -> None:
    for u in T[v]:
        if u != p:  # p: parent -> skip
            cnt[u] += cnt[v]  # cumulative sum
            dfs(u, v)


def main():
    # Ai (A[i][0]) may be not a parent of Bi (A[i][1])
    global T, cnt
    N, Q = tuple(map(int, input().split()))  # vertices and queues
    E = tuple(tuple(map(int, input().split())) for _ in range(N - 1))
    P = tuple(tuple(map(int, input().split())) for _ in range(Q))
    T = [[] for _ in range(N + 1)]  # tree, (N+1: 1-idx -> 0-idx)
    for a, b in E:
        T[a] += [b]
        T[b] += [a]
    cnt = [0] * (N + 1)
    for p, x in P:
        cnt[p] += x  # increase vertex p by x
    dfs(1, -1)
    print(*cnt[1:])


if __name__ == "__main__":
    main()

Measured memory_bytes: 265808
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
        var input = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
        var cnt5 = input.Where(d => d == 5).Count();
        var cnt7 = input.Where(d => d == 7).Count();
        
        if (cnt5 == 2 && cnt7 == 1) {
            Console.WriteLine("YES");
        } else {
            Console.WriteLine("NO");   
        }
	}
}

Measured memory_bytes: 13396
import math
import sys

n1=set()
n2=set()
n3=set()

N = int(input())
S = input()
# print(N,S)

for i in range(len(S)):
    s = S[i]
    # print(s)
    for s2 in n2:
        s3 = s2 + s
        if s3 not in n3:
            n3.add(s3)
    for s1 in n1:
        s2 = s1 + s
        if s2 not in n2:
            n2.add(s2)
    if s not in n1:
        n1.add(s)
    # print(n1,n2,n3)
print(len(n3))

Measured memory_bytes: 3188
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var line = consoleReader.SplitInt32();
            var a = line[0];
            var b = line[1];

            if (a == b)
                return a + a;
            else
                return Math.Max(a, b) * 2 - 1;
        }


        const int mod = 1000000007;
        private readonly ConsoleReader consoleReader;
        public Program() : this(new ConsoleReader()) { }
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program().Calc());
        public static string MultiLine<T>(IEnumerable<T> source) => string.Join("\n", source);
    }

    public class ConsoleReader
    {
        public virtual string String() => Console.ReadLine();
        public int Int32() => int.Parse(String());
        public long Int64() => long.Parse(String());
        public ulong UInt64() => ulong.Parse(String());
        public double Double() => double.Parse(String());
        public string[] Split() => String().Split().ToArray();
        public int[] SplitInt32() => String().Split().Select(int.Parse).ToArray();
        public long[] SplitInt64() => String().Split().Select(long.Parse).ToArray();
        public ulong[] SplitUInt64() => String().Split().Select(ulong.Parse).ToArray();
        public double[] SplitDouble() => String().Split().Select(double.Parse).ToArray();

        public IEnumerable<string> Repeat(int count)
        {
            for (int i = 0; i < count; i++)
                yield return String();
        }
        public IEnumerable<int> RepeatInt32(int count)
        {
            for (int i = 0; i < count; i++)
                yield return Int32();
        }
        public IEnumerable<long> RepeatInt64(int count)
        {
            for (int i = 0; i < count; i++)
                yield return Int64();
        }
        public IEnumerable<string[]> RepeatSplit(int count)
        {
            for (int i = 0; i < count; i++)
                yield return Split();
        }
        public IEnumerable<int[]> RepeatSplitInt32(int count)
        {
            for (int i = 0; i < count; i++)
                yield return SplitInt32();
        }
    }
    static class DicExt
    {
        public static V GetOrDefault<K, V>(this Dictionary<K, V> dic, K key, V defaultValue = default(V))
        {
            V val;
            return dic.TryGetValue(key, out val) ? val : defaultValue;
        }
    }
}


Measured memory_bytes: 13396
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)

	H, W := nextInt(), nextInt()
	S := make([]string, H)
	// for i := 0; i < H; i++ {
	// 	S[i] = make([]string, W)
	// }

	for i := 0; i < H; i++ {
		S[i] = nextLine()
	}

	var left, right, up, down [2100][2100]int

	for i := 0; i < H; i++ {
		cur := 0
		for j := 0; j < W; j++ {
			if S[i][j] == '#' {
				cur = 0
			} else {
				cur++
			}
			left[i][j] = cur

		}
	}

	for i := 0; i < H; i++ {
		cur := 0
		for j := W - 1; j >= 0; j-- {
			if S[i][j] == '#' {
				cur = 0
			} else {
				cur++
			}
			right[i][j] = cur
		}
	}

	for j := 0; j < W; j++ {
		cur := 0
		for i := 0; i < H; i++ {
			if S[i][j] == '#' {
				cur = 0
			} else {
				cur++
			}
			up[i][j] = cur
		}
	}

	for j := 0; j < W; j++ {
		cur := 0
		for i := H - 1; i >= 0; i-- {

			if S[i][j] == '#' {
				cur = 0
			} else {
				cur++
			}
			down[i][j] = cur
		}
	}

	res := 0
	for i := 0; i < H; i++ {
		for j := 0; j < W; j++ {
			res = max(res, left[i][j]+right[i][j]+up[i][j]+down[i][j]-3)
		}
	}

	fmt.Println(res)
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}


Measured memory_bytes: 146176
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n; cin >> n;
  vector<int> a(n);
  REP(i,n){
    cin >> a[i];
    a[i]--;
  }
  
  int cnt = 0;
  REP(i,n) if(a[a[i]]==i) cnt++; 
  cnt /= 2;
  cout << cnt << '\n';
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll X;
    cin >> X;
    ll ans = (X / 500) * 1000;
    X %= 500;
    ans += X / 5 * 5;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int A,B;
	1 <=A && A<=B && B<=20;
	scanf("%d%d",&A,&B);
	if(B%A==0){
		printf("\n%d",A+B);}else{
		printf("\n%d",B-A);
	}
	return 0;
}

Measured memory_bytes: 128
s=list(map(int,list(input())))
k=int(input())
for i in range(len(s)):
    if s[i]!=1:
        if i>=k:
            print(1)
        else:
            print(s[i])
        break
else:
    print(1)
'''
N=5000000000000

def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2

x=groupby(s)

for i in x:
    i[1]=i[1]*(i[0]**N)
計算量的に間に合わないのは明らか
print(x)
'''


Measured memory_bytes: 3060
N, K = map(int, input().split())
a = list(map(int, input().split()))

dp = [-1] * (K+1)
dp[0] = 1
for i in range(1, K+1):
    l = [dp[i-aj] if i-aj>=0 else 0 for aj in a]
    dp[i] = 0 if 1 in l else 1
        
ans = 'First' if dp[-1] == 0 else 'Second'
print(ans)

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define CEIL(n, m) ceil(n/pow(10.0, m))*pow(10.0, m)
#define FLOOR(n, m) floor(n/pow(10.0, m))*pow(10.0, m)
#define ROUND(n, m) round(n/pow(10.0, m))*pow(10.0, m)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).begin(),(x).end(),greater<int>())
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) " (L" << __LINE__ << ") " << __FILE__ << endl;

typedef long long ll;
const int mod = 1e9+7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;

void solve()
{
  int ans=0;

  int n; cin >> n;
  vector<int> a1(n),a2(n);
  for (int i=0; i<n; i++) {
    cin>>a1[i];
  }
  for (int i=0; i<n; i++) {
    cin>>a2[i];
  }
  for (int i=1; i<n; i++) {
    a1[i] += a1[i-1];
    a2[n-i-1] += a2[n-i];
  }
  for (int i=0; i<n; i++) {
    ans = max(ans, a1[i]+a2[i]);
  }

  cout << ans << endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int INF = 1001001001;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a,b,v,w,t;
  cin >> a >> v >> b >> w >> t;
  if( v * t >= w * t + abs(a - b)) puts("YES");
  else puts("NO");
  return 0;
}

Measured memory_bytes: 3652
# https://atcoder.jp/contests/abc123/tasks/abc123_a

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

antenna = [a, b, c, d, e]


ans = 'Yay!'
for i in range(0, len(antenna)-1):
    current = antenna[i]
    for n in range(i+1, len(antenna)):
        if abs(current - antenna[n]) > k:
            ans = ':('
            break

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for(long long i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;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());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

int main(){
  string s;
  cin >>s;
  int ans1 = 0,ans2 = 0;// 01010  10101
  for(int i = 0;i <s.length();i++) {
    if (i % 2 == 0) {
      if (s[i] == '0') {
        ans2++;
      } else {
        ans1++;
      }
    } else {
      if (s[i] == '0') {
        ans1++;
      } else {
        ans2++;
      }
    }
  }
  cout <<min(ans1,ans2);
}

Measured memory_bytes: 512
#include <cstdio>

int main(void)
{
    int a, b, d, r;
    double f;
    scanf("%d %d", &a, &b);
    d = a/b;
    r = a%b;
    f = double(a)/b;
    printf("%d %d %.5f\n", d, r, f);

    return 0;
}


Measured memory_bytes: 2736
#include<iostream>
using namespace std;
int togeter(int x,int y)
{
	return x*y;
}
int main()
{
	int d[52],n,sum=0;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>d[i];
	for(int i=0;i<n-1;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			sum+=togeter(d[i],d[j]);
		}
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}




int main(){
  int n,m;
  cin >> n >> m;
  int a[100010];
    bool an[100010]={0};
  FOR(i,m){
    cin >> a[i];
    an[a[i]]=1;
    
  }

  FOR(i,m-1){
    if(a[i]+1==a[i+1]){
      cout << 0 << endl;
      return 0;
    }
  }

  ll ans[100010];
  ans[0]=1;
  ans[1]=1;
  for(int i=2;i<=n;i++){
    if(an[i])continue;
    if(an[i-2]){
      ans[i]=ans[i-1];
    }else if(an[i-1]){
      ans[i]=ans[i-2];
    }else{
      ans[i]=(ans[i-1]+ans[i-2])%MOD;
    }
  }

  cout << ans[n] << endl;

  

  
}


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

void solve(std::istream &ist, std::ostream &ost)
{
    /* ------- 宣言と入力 ------- */

    int N;

    ist >> N;

    vector<int> a;

    for (int i = 0; i < N; i++)
    {
        int tmp;
        ist >> tmp;
        a.emplace_back(tmp);
    }

    /* ------- 計算 ------- */

    int two = 0;
    int four = 0;
    int others = 0;

    for (auto n : a)
    {
        if (n % 4 == 0)
        {
            four++;
        }
        else if (n % 2 == 0)
        {
            two++;
        }
        else
        {
            others++;
        }
    }

    if ((two != 0 && others <= four) || (two == 0 && others <= four + 1))
    {
        ost << "Yes" << endl;
    }
    else
    {
        ost << "No" << endl;
    }
}

#ifndef WOMAIN
int main()
{
    solve(std::cin, std::cout);
    return 0;
}
#endif


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long int lld;
#define sq(x) x*x
#define fr(i,m,n) for(i=m;i<n;i++)
#define vec vector<int>
#define sint set<int>
#define qint queue<int>
#define mip map<int,int>
#define pint priority_queue<int>
#define pb push_back
#define pp pop_back()
#define ft first
#define sd second
#define full(v) v.begin(),v.end()

int main()
{
    int i,j,k,a,b,c,x,y,z,n,m,t;
    string s,u,v;
    cin>>a>>b;
    if(b%2==0 && b>=a*2 && b<=a*4) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}



Measured memory_bytes: 3600
#include <stdio.h>

int main(){
    int n;
    scanf("%d", &n);
    long long int ans=0;
    for(int i=1;i<=n;i++){
       if(i%3==0 ||i%5==0){
           continue;
       }
       ans +=i;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 1672
import sys
N, K = list(map(int, input().split()))
MOD = 10 ** 9 + 7

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

ans = 0
for k in range(K, N+2):
    ans += ((2 * N-k+1) * k) // 2 - ((k-1)*k // 2 - 1)
    ans %= MOD

print(ans)


Measured memory_bytes: 63548
//BELIEVE IN YOURSELF
//next_permutation

#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define pob pop_back
#define vi vector<ll>
#define mp make_pair
#define sz size()
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rep(i,n) for(ll i=0;i<n;i++)
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define maxx 100005
#define se second
#define fi first
#define be begin()
#define en end()
#define sortv(v) sort(v.begin(),v.end());
#define sortr(v) sort(v.rbegin(),v.rend());
#define w() ll _;cin>>_;while(_--)
#define edge pair<ll,ll>
#define pq priority_queue<ll>
#define mod 1000000007
#define Endl "\n"
#define cy cout<<"YES"<<endl;
#define cn cout<<"NO"<<endl;
#define lb(v,x) std::lower_bound(v.begin(),v.end(),x)
#define ub(v,x) std::upper_bound(v.begin(),v.end(),x)

using namespace std;


int main()
{
	fast;
	
	ll n;
	cin>>n;
	ll a[n];
	ll b[n];
	ll i;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(i=0;i<n;i++)
	{
		cin>>b[i];
	}
	
	ll r=n-1;
	
	for(i=0;i<n;i++)
	{
		if(a[i]==b[i])
		{
			if(b[i]==b[r])
			{
				r=n-1;
			}
			swap(b[i],b[r]);
			r--;
		}
	}
	
	ll l=0;
	
	for(i=0;i<n;i++)
	{
		if(a[i]==b[i])
		{
			if(b[i]==b[l])l=0;
			swap(b[i],b[l]);
			l++;
		}
	}
	ll fuck=0;
	for(i=0;i<n;i++)
	{
		if(a[i]==b[i])
		{
			fuck++;
		}
	}
	if(fuck)
	{
		cout<<"No"<<endl;
	}
	else
	{
		cout<<"Yes"<<endl;
		for(i=0;i<n;i++)
		{
			cout<<b[i]<<" ";
		}
	}
	
	
	
	return 0;
}

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

using namespace std;

int main(){
    long A, B, K;
    cin>>A>>B>>K;

    if(A < K){
        K -= A;
        A = 0;
    }else{
        A -= K;
        cout<<A<<" "<<B<<endl;
        return 0;
    }

    if(B < K){
        K -= B;
        B = 0;
    }else{
        B-=K;
    }
    cout<<A<<" "<<B<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 1987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int,int,int,int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };

int n,m;
int x[100000],y[100000],z[100000];
Pll p[100001];
VPi v[100001];
int main(){
	scanf("%d%d",&n,&m);
	fup(i,0,m-1,1)
	{
		scanf("%d%d%d",x+i,y+i,z+i);
		v[x[i]].pb(mp(y[i],i));
		v[y[i]].pb(mp(x[i],i));
	}
	queue<int> q;
	q.push(1);
	p[1].Y=1;
	while(!q.empty())
	{
		int x=q.front();
		q.pop();
		for(Pi next:v[x])
		{
			if(p[next.X].Y==0)
			{
				q.push(next.X);
				p[next.X]=mp((ll)z[next.Y]-p[x].X,-p[x].Y);
			}
		}
	}
	ll mn=1,mx=INF;
	fup(i,1,n,1)
	{
		if(p[i].Y==1)mn=max(mn,-p[i].X+1);
		else mx=min(mx,p[i].X-1);
	}
	fup(i,0,m-1,1)
	{
		int xx=x[i],yy=y[i];
		ll zz=z[i];
		if(p[xx].Y!=p[yy].Y)
		{
			if(p[xx].X+p[yy].X!=zz)return !printf("0");
		}
		else if(p[xx].Y==1)
		{
			ll t=zz-p[xx].X-p[yy].X;
			if(t&1)return !printf("0");
			t>>=1;
			mn=max(mn,t),mx=min(mx,t);
		}
		else
		{
			ll t=p[xx].X+p[yy].X-zz;
			if(t&1)return !printf("0");
			t>>=1;
			mn=max(mn,t),mx=min(mx,t);
		}
	}
	if(mn>mx)return !printf("0");
	printf("%lld",mx-mn+1);
}

Measured memory_bytes: 9600
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var (
	sc = bufio.NewReader(os.Stdin)
)

type pos struct {
	t, x, y int
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func arrive(p, p2 *pos) bool {
	t := p.t - p2.t
	x := abs(p.x - p2.x)
	y := abs(p.y - p2.y)
	d := x + y
	if d == t {
		return true
	}
	if d < t {
		if (t-d)%2 == 0 {
			return true
		} else {
			return false
		}
	}
	if t < d {
		return false
	}
	return true
}

func main() {
	N := scanInt()
	c := &pos{t: 0, x: 0, y: 0}
	for i := 0; i < N; i++ {
		n := &pos{t: scanInt(), x: scanInt(), y: scanInt()}
		if !arrive(n, c) {
			fmt.Println("No")
			return
		}
		c = n
	}
	fmt.Println("Yes")
}

func scan(a ...interface{}) { _, err := fmt.Fscan(sc, a...); pnc(err) }
func scanStr() (s string)   { scan(&s); return }
func scanInt() int          { i, err := strconv.Atoi(scanStr()); pnc(err); return i }
func scanFloat() float64    { f, err := strconv.ParseFloat(scanStr(), 64); pnc(err); return f }
func pnc(err error) {
	if err != nil {
		panic(err)
	}
}


Measured memory_bytes: 6340
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

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

    vector<pair<int, int>> g[N][3];
    int f[N][3];
    for(int i=0; i<M; i++){
        int a, b;
        cin >> a >> b;
        for(int j=0; j<3; j++){
            g[a-1][j].push_back(make_pair(b-1, (j+1)%3));
        }
    }

    for(int i=0; i<N; i++){
        fill(f[i], f[i]+3, -1);
    }

    int s, t;
    cin >> s >> t;
    int S = s-1; 
    int T = t-1;

    f[S][0] = 0;

    queue<pair<int, int>> q;
    q.push(make_pair(S, 0));
    while(!q.empty()){
        pair<int, int> now = q.front();
        q.pop();

        if(now.first==T && now.second==0)  break;
    
        for(auto p:g[now.first][now.second]){
            if(f[p.first][p.second] != -1) continue;
            f[p.first][p.second] = f[now.first][now.second] + 1;
            q.push(p);
        }
    }

    if(f[T][0] == -1) cout << f[T][0];
    else cout << f[T][0]/3;

    return 0;

}

Measured memory_bytes: 17792
N=int(input())
S=list(input())
L=[str(i)+str(j) for i in range(10) for j in range(10)]
n=0
for l in L:
  I=N
  for i in range(N):
    if S[i]==l[0]:
      I=i
      break
  J=N
  for j in range(I+1,N):
    if S[j]==l[1]:
      J=j
      break
  n+=len(list(set(S[J+1:N])))
print(n)

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

using namespace std;

typedef long long ll;

int MOD;

ll C[305][305];
int f[305][305],sum[305][305];

void pre(int n) {
  for(int i=0;i<=n;i++) C[i][0]=1;
  for(int i=1;i<=n;i++)
    for(int j=1;j<=i;j++) C[i][j]=(C[i-1][j-1]+C[i-1][j])%MOD;
}

int main() {
  int n,k;
  scanf("%d%d%d",&n,&k,&MOD);
  pre(n);
  for(int i=1;i<=k+1;i++) {
  	f[0][i]=1;
  	sum[0][i]=i;
  }
  for(int i=1;i<=n;i++) {
  	for(int j=1;j<=k+1;j++)
  	  for(int l=1;l<=i;l++) 
		f[i][j]=(f[i][j]+(ll)sum[l-1][j-1]*f[i-l][j]%MOD*C[i-1][l-1])%MOD;
  	for(int j=1;j<=k+1;j++) sum[i][j]=(sum[i][j-1]+f[i][j])%MOD;
  }
  printf("%d\n",f[n][k+1]);
  return 0;
}

Measured memory_bytes: 1664
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    s = input()
    K = read_int()
    min5 = []
    for i in range(len(s)):
        for j in range(i+1, min(len(s), i+K)+1):
            min5.append(s[i:j])
        min5 = sorted(set(min5))
        while len(min5) > K:
            min5.pop()
    return min5[-1]


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 73648
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

n = int(arr_data[0][0])
arr01=arr_data[1]

hash01={}

for v in arr01:
    
    cnt=hash01.setdefault(int(v),0)+1
    
    hash01[int(v)]=cnt
    
#print(hash01)  

menseki01=None
menseki02=None

a=None
b=None

for k, v in sorted(hash01.items(), reverse=True):
    
#    print(k,v)
    
    if(v>=2 and a is None):
    
    
#        print("--chk01")
        a=k
        
    elif(v>=2 and a is not None and b is None):
    
#        print("--chk02")
        b=k
        menseki02=a*b
    
    if(v>=4 and menseki01 is None):
        
        menseki01=k*k
        
#print(menseki01,menseki02,a,b)        
if menseki01 is None and menseki02 is None:
     
     print(0)


elif menseki01 is None and menseki02 is not None:

     print(menseki02)

elif menseki01 is not None and menseki02 is None:
     
    
     print(menseki01)

elif menseki01 is not None and menseki02 is not None:
     
    
    if menseki01 <= menseki02:

        print(menseki02)
        
    else:
        print(menseki01)



Measured memory_bytes: 27508
#include <cstdio>
#include <algorithm>

using namespace std;

bool ap[100010];
int v[100010];

int main ()
{
   // freopen ("file.in", "r", stdin);

    int n, m;
    scanf ("%d %d", &n, &m);

    ap[1] = true;

    for (int i = 1; i <= n; ++i)
        v[i] = 1;

    int nr = 0;
    for (int i = 1; i <= m; ++i)
    {
        int x, y;
        scanf ("%d %d", &x, &y);

        if (ap[x])
        {
            if (v[x] == 1) ap[x] = false;
            ap[y] = true;
        }

        --v[x];
        ++v[y];
    }

    for (int i = 1; i <= n; ++i)
        if (ap[i]) ++nr;

    printf ("%d\n", nr);

    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define LL long long
#define st first
#define nd second
using namespace std;
int n,val[100005],t;
vector<int> v[100005];
void dfs(int x) {
	vector<int> a;
	val[x]=0;
	if(v[x].size()==0) {
		return;
	}
	for(int i=0;i<v[x].size();++i) {
		dfs(v[x][i]);
		a.pb(val[v[x][i]]);
	}
	sort(a.begin(),a.end());
	for(int i=0;i<a.size();++i) {
		val[x]=max(val[x],a[i]);
		++val[x];
	}
}
int main(){
	cin>>n;
	for(int i=2;i<=n;++i) {
		cin>>t;
		v[t].pb(i);
	}
	dfs(1);
	cout<<val[1]<<endl;
}

Measured memory_bytes: 13952
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
long long a,b,n;
int main()
{
	cin>>n>>a>>b;
	if((b-a)%2==0)
	{
		cout<<"Alice"<<endl;
	}
	else
	{
		cout<<"Borys"<<endl;
	}
	return(0);
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>


int main(void) {
	char s[100000] = { 0 };
	int temp;
	int posi[100000] = { 0 };

	scanf("%s", s);
	int len = strlen(s);
	for (int i = 0; i < len; ) {
		if (s[i] == 'R') {
			for (int j = 1; j < len; j++) {
				if (s[i + j] == 'L') {
					temp = j;
					break;
				}
			}
			if (temp % 2) {
				posi[i + temp] += floor((double)temp / 2);
				posi[i + temp - 1] += ceil((double)temp / 2);
			}
			else {
				posi[i + temp] += floor((double)temp / 2);
				posi[i + temp - 1] += ceil((double)temp / 2);
			}
			i += temp;
		}
		else {
			for (int j = 1; j < len; j++) {
				if (s[i + j] == 'R') {
					temp = j;
					break;
				}
				else if (i + j == len ) {
					temp = j;
					break;
				}
			}
			if (temp % 2) {
				posi[i] += ceil((double)temp / 2);
				posi[i - 1] += floor((double)temp / 2);
			}
			else {
				posi[i] += ceil((double)temp / 2);
				posi[i - 1] += floor((double)temp / 2);
			}
			i += temp;
		}
		/*
		for (int i = 0; i < len; i++) {
			printf("%d ", posi[i]);
		}
		printf("\n");
		*/
	}
	for (int i = 0; i < len; i++) {
		printf("%d ", posi[i]);
	}
	return 0;
}

Measured memory_bytes: 896
# import sys
# import math
# import decimal
# import queue
# import bisect
# import heapq # priolity-queue
# import time
# import itertools
# import collections # queue
# from operator import itemgetter
# from fractions import Fraction

mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

def main():
    n = int(input())
    a = []
    for i in range(n):
        a.append(int(input()))
    b = [0] * n
    b[0] = 1
    i = 0
    ans = 0
    while True:
        b[a[i]-1] = 1
        ans += 1
        i = a[i]-1
        if b[1]:
            break
        elif b[a[i]-1]:
            ans = -1
            break
    print(ans)
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 7852
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    string s;
    cin >> s;
    int ans = inf;
    int n = s.size();
    rep(i,n-1) {
        if(s[i] != s[i+1]) {
            chmin(ans,max(i+1,n-1-i));
        }
    }
    if(ans != inf) cout << ans << endl;
    else cout << n << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法
#define JUUHATI 1000000000000000000 

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    char cx;
    cin >> cx;

    vector<char> alpha(26);

    alpha ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

    for(int i = 0;i < 26;i++){
        if(alpha[i] == cx){
            cout << alpha[i+1] << endl;
            break;
        }
    }
    
}

Measured memory_bytes: 256
n, c = map(int, input().split())
imos = [0 for _ in range(10 ** 5 + 1)]
ans = 0
channel = [[] for _ in range(30)]
for _ in range(n):
    s, t, c = map(int, input().split())
    channel[c - 1].append([s, t])
    
for lst in channel:
    lst.sort()
    before = 0
    for s, t in lst:
        start = max(before, s - 1)
        imos[start] += 1
        end = min(t, 10 ** 5 + 1)
        imos[end] -= 1
        before = end
tmp = 0
for num in imos:
    tmp += num
    ans = max(ans, tmp)
print(ans)    

Measured memory_bytes: 20848
#input
N = int(input())
A = list(map(int, input().split()))
#A.sort() # 配列を小さい順に並び替え
A.sort(reverse = True) # 配列を大きい順に並び替え
#print(A)
alice = bob = 0 # 初期化

for i in range(N):
    if i%2 == 0:
        alice += A[i]
    else:
        bob += A[i]


print(alice-bob)

Measured memory_bytes: 3060
/*-- ILSH --*/
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back 
#define pop pop_back
#define mp make_pair
#define vii vector < int >
#define vll vector < ll > 
#define pii pair < int , int >
#define pll pair < ll , ll >
#define vpi vector < pii >
#define vpl vector < pll >
#define viii vector < vii >
#define vlll vector < vll >
#define fi first
#define sz size 
#define len length 
#define se second 
//const ll mod=998244353;
const ll mod = 1000000000+7;
const ll N=200000+6;
const ll inf=1e18+1e17;
void solve(){
	int a,b;
	cin>>a>>b;
	if ( a>b)
		swap(a,b);
	for ( int i=0;i<b;i++)
		cout<<a;
	cout<<'\n';
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    // #ifndef ONLINE_JUDGE
    //    freopen ("INPUT.txt" , "r" , stdin);
    //    freopen ("OUTPUT.txt", "w" , stdout);
    // #endif	
    int t=1;
    //cin>>t;
    while ( t-- ){
    	solve();
    }

}

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

a = list(map(int, input().split()))

ans = []


for i in range(N-2,N%2-1,-2):
    ans.append(str(a[i]))
    
for i in range((N-1)%2,N,2):
    ans.append(str(a[i]))

ans.reverse()

print(' '.join(ans))

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

int main(){
	int N, h, ans=0, num=0;
	std::vector<int> H;
	std::cin >> N;
	for(int i=0; i<N; i++){
		std::cin >> h;
		H.push_back(h);
	}
	for(int i=0; i<N-1; i++){
		if(H[i]>=H[i+1]){
			num +=1;
			if(i == N-2){
				ans = std::max(ans, num);
			}
		}
		else{	
			ans = std::max(ans, num);
			num = 0;
		}
	}
	std::cout << ans << std::endl;
	return 0;
}



Measured memory_bytes: 892
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] written = br.readLine().split("");
        String[] target  = new String[]{"C","O","D","E","F","E","S","T","I","V","A","L","2","0","1","6"};
        int change = 0;
        for(int i=0;i<16;i++){
        	if(!written[i].equals(target[i])) change++;
        }
        
        System.out.println(change);
    }
}

Measured memory_bytes: 8404
# 今回の方針
# LRの境界の数だけで計算を済ませる

n, k = map(int, input().split())
s = list(input())

happy = 0
for i in range(0, n-1):
    if s[i] == s[i+1]:
        happy += 1

happy += 2*k
if happy >= n:
    happy = n-1

print(happy)


Measured memory_bytes: 3956
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <cmath>

int main(void){
	
	std::string s[3];

	std::cin >> s[0] >> s[1] >> s[2];

	std::cout << s[0][0] << s[1][1] << s[2][2] << std::endl;


	return 0;
}

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

int main () {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  if(A+B<C+D){
    cout << "Right" << endl;
  }
  else if(A+B>C+D){
    cout << "Left" << endl;
  }
  else if(A+B==C+D){
    cout << "Balanced" << endl;
  }
}
  
  


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int n[10], i, j, temp;
	char str[11];
	while (scanf("%s", str) != EOF){
		for (i = 0; i < 10; i++){
			n[i] = str[i] - '0';
		}
		for (i = 9; i > 0; i--){
			for (j = 0; j < i; j++){
				temp = n[j] + n[j+1];
			if (temp >= 10)
				n[j] = temp -10;
			else
				n[j] = temp;
			}
		}
		printf("%d\n", n[0]);
	}
	return 0;
}

Measured memory_bytes: 540