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

import static java.util.Comparator.*;


public class Main {
    public static void main(String[] args) throws IOException {
        FastReader s = new FastReader();
        String str=s.next();
        String t=s.next();
        int count=0;
        for(int i=0;i<str.length();i++)
        {
            if(str.charAt(i)==t.charAt(i))
            {
                count++;
            }
        }
        System.out.println(count);


    }

}

class FastReader
{
    BufferedReader br;
    StringTokenizer st;

    public FastReader()
    {
        br = new BufferedReader(new
                InputStreamReader(System.in));
    }

    String next()
    {
        while (st == null || !st.hasMoreElements())
        {
            try
            {
                st = new StringTokenizer(br.readLine());
            }
            catch (IOException  e)
            {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt()
    {
        return Integer.parseInt(next());
    }

    long nextLong()
    {
        return Long.parseLong(next());
    }

    double nextDouble()
    {
        return Double.parseDouble(next());
    }

    String nextLine()
    {
        String str = "";
        try
        {
            str = br.readLine();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return str;
    }
}

Measured memory_bytes: 21076
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
ll num[71][71];
ll fact[10001];
ll inv_fact[10001];
ll mod_pow(ll a, ll b) {
	if (b == 0) return 1;
	if (b % 2 == 0) {
		ll x = mod_pow(a, b / 2);
		return (x*x) % MOD;
	}
	return (a*mod_pow(a, b - 1)) % MOD;
}
ll comb(ll n, ll k) {
	if (n < k) return 0;
	ll ret = fact[n];
	(ret *= inv_fact[k]) %= MOD;
	(ret *= inv_fact[n - k]) %= MOD;
	return ret;
}
int N, K;
ll ans;
string s;
bool check(vector<int> &v) {
	bool used[70] = {};
	int pos[70];
	int now= 0;
	for (int i = 0; i < v.size(); i++) {
		while (now < s.size()) {
			if (s[now] == 'r') break;
			now++;
		}
		if (now == s.size()) return 0;
		used[now] = 1;
		pos[i] = now;
		now++;
	}
	for (int i = 0; i < v.size(); i++) {
		if (v[i] == 1) break;
		now = pos[i] + 1;
		while (now < s.size()) {
			if (!used[now] && s[now] == 'b') break;
			now++;
		}
		if (now == s.size()) return 0;
		used[now] = 1;
		pos[i] = now;
	}
	for (int i = 0; i < v.size(); i++) {
		if (v[i] <= 2) break;
		int cnt = 0;
		now = pos[i] + 1;
		while (now < s.size()) {
			if (!used[now]) {
				used[now] = 1;
				cnt++;
			}
			if (cnt >= v[i] - 2) break;
			now++;
 		}
		if (now == s.size()) return 0;
	}
	return 1;
}
ll calc(vector<int> &v) {
	map<int, int> freq;
	for (int i = 0; i < v.size(); i++) {
		freq[v[i]]++;
	}
	ll ret = fact[v.size()];
	for (auto p : freq) {
		(ret *= inv_fact[p.second]) %= MOD;
	}
	int x = N + 1;
	int y = 0;
	for (int i = 0; i < v.size(); i++) {
		if (v[i] >= 2) x += 2;
		y += 2 * v[i];
	}
	(ret *= comb(x, y)) %= MOD;
	return ret;
}
void brute(int k, int prev, int sum, vector<int> &v) {
	if (sum > N) return;
	if (check(v)) {
		(ans += calc(v)) %= MOD;
	}
	for (int i = min(k, prev); i >= 1; i--) {
		int m = 1;
		if (i > 1) m = i * 2 - 3;
		if (v.size() > 0) m++;
		v.push_back(i);
		brute(k - i, i, sum + m, v);
		v.pop_back();
	}
}
int main() {
	fact[0] = inv_fact[0] = 1;
	for (int i = 1; i <= 10000; i++) {
		fact[i] = (fact[i - 1] * i) % MOD;
		inv_fact[i] = (inv_fact[i - 1] * mod_pow(i, MOD - 2)) % MOD;
	}
	cin >> N >> K;
	cin >> s;
	vector<int> v;
	brute(K, K, 0, v);
	cout << ans << endl;
}

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

int main(){
  string s;
  cin >> s;
  int alpha[26],sum=0;
  for(int i=0;i<26;i++){
    alpha[i] = 0;
  }
  for(int i=0;i<s.size();i++){
    alpha[s[i]-'a']++;
  }
  for(int i=0;i<26;i++){
    if(alpha[i]%2==1){
      sum++;
    }
  }
  if(sum>0){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
  return 0;
}

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
	int n,wid,h;cin>>n>>wid>>h;
  vector<int> x(n);
  vector<int> y(n);
  vector<int> w(n);
  int i;
  rep(i,n)cin>>x[i]>>y[i]>>w[i];
  vector<int> wsum(wid+1,0);
  rep(i,n)
  {
    wsum[max(0,x[i]-w[i])]++;
    wsum[min(wid,x[i]+w[i])]--;
  }
  rep(i,wid)wsum[i+1]+=wsum[i];
  bool wok=true;
  for(i=0;i<wid;i++)if(wsum[i]<=0)wok=false;
  vector<int> hsum(h+1,0);
  rep(i,n)
  {
    hsum[max(0,y[i]-w[i])]++;
    hsum[min(h,y[i]+w[i])]--;
  }
  rep(i,h)hsum[i+1]+=hsum[i];
  bool hok=true;
  for(i=0;i<h;i++)if(hsum[i]<=0)hok=false;
  if(wok||hok)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}



Measured memory_bytes: 4672
s = [ord(x) - ord("a") for x in input()]
k = int(input())

for i, r in enumerate(s):
    if r == 0:
        pass
    elif 26 - r <= k:
        k -= 26-r
        s[i] = 0

if k > 0:
    k %= 26
    s[-1] += k

ans = ""
for r in s:
    ans += chr(ord("a") + r)

print(ans)



Measured memory_bytes: 4212
/*input
37564
whydidyoudesertme
*/

// Nihesh Anderson - knandy

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key
ll MOD=1000000007;

#define endl '\n'
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
ll INF = 2000000000000000001;
long double EPS = 1e-9;
ll power(ll a, ll n, ll md){if(n==0){return 1;}else{ll res=power(a,n/2,md);res=(res*res)%md;if(n%2!=0){res=(res*a)%md;}return res;}}
random_device rndm;
mt19937 grndm(rndm());
void mix(ll* a, ll* b){shuffle(a,b,grndm);}

const ll MX = 2000006;

ll fact[MX], ifact[MX], pow25[MX], pow26[MX];

ll choose(ll n, ll k) {
	return fact[n] * ifact[k] % MOD * ifact[n - k] % MOD;
}

int main(){
	fast_cin();
	// freopen("input.in","r",stdin);
	// freopen("output.out","w",stdout);
	fact[0] = 1;
	for(ll i = 1; i < MX; i++) {
		fact[i] = (i * fact[i - 1]) % MOD;
	}
	for(ll i = 0; i < MX; i++) {
		ifact[i] = power(fact[i], MOD - 2, MOD);
	}
	pow25[0] = pow26[0] = 1;
	for(ll i = 1; i < MX; i++) {
		pow25[i] = (25 * pow25[i - 1]) % MOD;
		pow26[i] = (26 * pow26[i - 1]) % MOD;
	}
	ll k; cin >> k;
	string s; cin >> s;
	ll n = s.size();
	ll ans = 0;
	for(ll i = n - 1; i <= n + k - 1; i++) {
		ans = (ans + choose(i, n - 1) * pow26[n + k - 1 - i] % MOD * pow25[i - n + 1] % MOD) % MOD;
	}
	cout << ans << endl;
	return 0;
}

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

ll nck(ll n, ll k) {
    ll r = 1;
    for (ll d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}

int main(){
    int N,M;cin>>N>>M;
    if(N<=1&&M<=1) cout<<0<<endl;
    else cout<<nck(N,2)+nck(M,2)<<endl;
}

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

const int N=100010;
int arr[N], dp[N];
int calc(int n) {
    dp[1] = arr[1];
    dp[2] = abs(arr[1]-arr[2]);
    dp[3] = min(abs(arr[1]-arr[3]), dp[2]+abs(arr[2]-arr[3]));
    for (int i=4;i<=n;i++) {
        dp[i] = min(abs(arr[i]-arr[i-1])+dp[i-1], dp[i-2]+abs(arr[i]-arr[i-2]));
    }
    int su=0;
    return dp[n];
}
int main() {
    int n;
    cin>>n;
    for (int i=1;i<=n;i++)cin>>arr[i];
    cout<<calc(n);
    
    return 0;
}   

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;

int main() {
	string mem;
	int n;

	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> mem;
		if (mem == "Y") {
			cout << "Four" << endl;
			return 0;
		}
	}
	cout << "Three" << endl;
}

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

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i <= int(r); ++i)
#define ford(i, n) for (int i = int(n)-1; i >= 0; --i)
#define pb push_back
#define eb emplace_back
#define ms(a, x) memset(a, x, sizeof(a))
#define F first
#define S second
#define endl '\n'
#define de(x) cout<<#x<<" = "<<(x)<<endl
#define de2(x,y) cout<<#x<<" = "<<(x) <<' '<< #y<<" = "<<y<<endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());

const int N=1e5+5;
int a[N][3];
int dp[N][4];
int n;
int dfs(int x,int la){
	if(x==n+1) return 0;
	if(dp[x][la]) return dp[x][la];
	int res=0;
	forn(i,3){
		if(i==la) continue;
		res=max(res,a[x][i]+dfs(x+1,i));
	}
	return dp[x][la]=res;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
	cin>>n;
	for1(i,n){
		forn(j,3) cin>>a[i][j];
	}
	cout<<dfs(1,4);
    return 0;
}



Measured memory_bytes: 10752
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;
const int mod = MOD7;

void ERROR(int num) { cout << "ERROR" << num << endl; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};


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

    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];

    ll sum = 0;
    map<ll,ll> Map;
    rep(i,N){
    	ll num = A[i];
    	Map[num]++;
    	sum += num;
    }


    int Q;
    cin >> Q;
    rep(i,Q){
    	ll B, C;
    	cin >> B >> C;
    	ll cnt = Map[B];
    	//cout << "cnt: " << cnt << endl;
    	sum = sum + cnt*(C-B);
    	cout << sum << endl;

    	Map[C] += cnt;
    	Map[B] = 0;
    }

}


Measured memory_bytes: 9940
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin>>S;
  if(S=="SUN"){
    cout<<7<<endl;
  }
  else if(S=="MON"){
    cout<<6<<endl;
  }
  else if(S=="TUE"){
    cout<<5<<endl;
  }
  else if(S=="WED"){
    cout<<4<<endl;
  }
  else if(S=="THU"){
    cout<<3<<endl;
  }
  else if(S=="FRI"){
    cout<<2<<endl;
  }
  else{
    cout<<1<<endl;
  }
}

Measured memory_bytes: 256
//package atcoder.beginner_170;

import java.io.*;
import java.util.StringTokenizer;

public class Main {

    public static void main (String[] args) throws Exception {

        String s = "takahashi";

//        br = new BufferedReader(new StringReader(s));
        br = new BufferedReader(new InputStreamReader(System.in));
        bw = new BufferedWriter(new OutputStreamWriter(System.out));

        rl(); int I=-1; for(int i=0; i<5; ++i) if (nin()==0) I=i+1;

        bw.write(Integer.toString(I));
        bw.newLine();
        bw.flush();

    }

    static BufferedReader br;
    static BufferedWriter bw;
    static StringTokenizer st;
    static void rl() throws Exception{
        st = new StringTokenizer(br.readLine());
    }
    static long nlo(){
        return Long.parseLong(st.nextToken());
    }
    static int nin(){
        return Integer.parseInt(st.nextToken());
    }
    /*private static void te(){
      }*/
    static double ndo(){
        return Double.parseDouble(st.nextToken());
    }
    static char[] nca(){
        return st.nextToken().toCharArray();
    }
    static String nstr(){
        return st.nextToken();
    }
}

Measured memory_bytes: 32636
#include <stdio.h>

#define N_MAX   100000
#define W_MAX   100000
#define H_MAX   100000

int MIN(int a,int b){return a<b?a:b;}
int MAX(int a,int b){return a<b?b:a;}

int width[W_MAX+1]    = {};
int height[H_MAX+1]   = {};

int main(void){
    int N,W,H,x,y,w;
    int i,j;
    int M;
    
    scanf("%d %d %d",&N,&W,&H);
    for( i=0; i<N; i++){
        scanf("%d %d %d",&x,&y,&w);
        width[MAX(0,   x-w)]++;
        width[MIN(H+1, x+w)]--;
        height[MAX(0,  y-w)]++;
        height[MIN(W+1,y+w)]--;
    }
    
    M=N;
    for( i=0; i<W; i++){
        if( M > width[i] ){
            M = width[i];
        }
        width[i+1] += width[i];
    }
    
    if( M <= 0 ){
        M = N;
        for( i=0; i<H; i++){
            if( M > height[i] ){
                M = height[i];
            }
            height[i+1] += height[i];
        }
    }
    
    if( M <= 0 ){
        printf("No\n");
    }else{
        printf("Yes\n");
    }
}




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

typedef long long int ll;

int main(){
   int n,l;
   cin>>n>>l;
   ll r = (n*(l-1))+((n*(n+1))/2);

   int min=abs(l-1+1);
   int ri=1; 
   for(int i=2;i<=n;i++){
       if(abs(l-1+i)<min){
           min=abs(l-1+i);
           ri=i;
       }
   }
   r-=(l-1+ri);
   cout<<r<<endl;

}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace TestApp
{
    partial class Program
    {
        static void Main(string[] args)
        {
            daydream();
            Console.ReadLine();
        }

        private static void daydream(){
            String input = Console.ReadLine();
            var patterns = new String[]{"dream", "dreamer", "erase", "eraser"};
            //patterns = patterns.OrderByDescending(x => x.Length).ToArray();

            //while
            int CurrentIdx = 0;
            int InputLen = input.Length;

            string output ="YES";

            while(InputLen > CurrentIdx){

                bool IsMatched = false;
                foreach(var pattern in patterns){                    
                    //パターン文字列と比較して一致するか調べる

                    int CurrentLen = pattern.Length;
                    //後方の文字列を切り取り
                    int RightLen =InputLen-CurrentLen-CurrentIdx;
                    //負の値ならエラーになるので次へ
                    if(RightLen < 0) continue;
                    string TStr = input.Substring(RightLen,CurrentLen);
                    
                    //対象の後方を切り取り比較
                    if(TStr ==　pattern){
                        //次の参照位置をセットしてforを抜ける
                        CurrentIdx+=CurrentLen;
                        IsMatched=true;
                        break;
                    }
                }
                //一つもマッチがないとエラー
                if(!IsMatched){
                    output ="NO";
                    break;
                }
            }

            Console.WriteLine(output);

        }



    }
}

Measured memory_bytes: 11232
fun main(args: Array<String>) {
    val (n, a, b, c) = readLine()!!.split(" ").map(String::toInt)
    val ls = mutableListOf<Int>()
    for (i in 1..n) {
        ls.add(readLine()!!.toInt())
    }
    println(dfa(n, ls, a, b, c, 0, 0, 0, 0))
}

fun dfa(n: Int, l: List<Int>, A: Int, B: Int, C: Int, cur: Int, a: Int, b: Int, c: Int): Int {
    if (cur == n) {
        return if (listOf(a, b, c).min()!! > 0) {
            Math.abs(a - A) + Math.abs(b - B) + Math.abs(c - C) - 30
        } else {
            10000000
        }
    }
    val ret0 = dfa(n, l, A, B, C, cur + 1, a, b, c)
    val ret1 = dfa(n, l, A, B, C, cur + 1, a + l[cur], b, c) + 10
    val ret2 = dfa(n, l, A, B, C, cur + 1, a, b + l[cur], c) + 10
    val ret3 = dfa(n, l, A, B, C, cur + 1, a, b, c + l[cur]) + 10
    return listOf(ret0, ret1, ret2, ret3).min()!!
}


Measured memory_bytes: 50500
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<queue>
using namespace std;

int main(){
  long long n;
  cin >> n;
  cout << n*(n-1)/2 << endl;
  return 0;
}

Measured memory_bytes: 256
#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; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;

int main(){
    ll a=0,b=0,c=0,d=0,n,max=-100000;
    //VI a(N);
    string s,s2;
    cin >> s;
    for(int i=0;i<s.size();i++){
        if(s[i]== 'A'||s[i]== 'C'||s[i]== 'G'||s[i]== 'T'){
            c++;
            for(int j=i+1;j<s.size();j++){
                if(s[j]== 'A'||s[j]== 'C'||s[j]== 'G'||s[j]== 'T'){
                    c++;
                }
                else break;
            }
        }
        if(max<c){
            max = c;
        }
        c=0;
    }
    cout << max <<endl;
    return 0;
}


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

using namespace std;

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

    int x[n];
    int y[n];
    int h[n];

    for (int i = 0; i < n; i++)
    {
        cin >> x[i] >> y[i] >> h[i];
    }

    for (int i = 0; i <= 100; i++)
    {
        for (int j = 0; j <= 100; j++)
        {
            int hmax = -1;
            bool flag = true;
            for (int k = 0; k < n; k++)
            {
                if (h[k] == 0)
                    continue;
                if (hmax == -1)
                {
                    hmax = h[k] + abs(i - x[k]) + abs(j - y[k]);
                }
                else
                {
                    if (hmax != h[k] + abs(i - x[k]) + abs(j - y[k]))
                    {
                        flag = false;
                        break;
                    }
                }
            }
            for (int k = 0; k < n; k++)
            {
                if (h[k] == 0)
                {
                    if (i == x[k] && j == y[k])
                    {
                        flag = false;
                        break;
                    }
                    if (hmax - abs(i - x[k]) - abs(j - y[k]) > 0)
                    {
                        flag = false;
                        break;
                    }
                }
            }
            if (flag)
            {
                cout << i << " " << j << " " << hmax << endl;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
//s.k
  
long long Zeros(long long  n) 
{ 
    if (n & 1LL) 
        return 0; 
  
    else { 
        long long ans = 0; 
  
        n /= 2; 
        while (n) { 
            ans += n / 5; 
            n /= 5; 
        } 
  
        return ans; 
    } 
} 
  
int main() 
{ 
long long n;
    cin>>n;
    
  
    cout << Zeros(n); 
  
}

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

#define QUE_SIZE 1000000
typedef struct {
    char name[10];
    int time;
} QUE;
QUE que[QUE_SIZE];

int main() {
    int i,j,n,q,time=0,head=0,tail;
    char name[10];
    scanf("%d %d", &n, &q);
    tail=n;
    for(i=0;i<n;i++){
        scanf("%s %d", name, &time);
        for (j=0;j<strlen(name);j++) que[i].name[j] = name[j];
        que[i].time = time;
    }
    time=0;
    while(head!=tail){
        if(que[head].time <= q || (QUE_SIZE+tail-head)%QUE_SIZE == 1) {
            time += que[head].time;
            printf("%s %d\n", que[head].name, time);
            head = (head+1)%QUE_SIZE;
        } else {
            time += q;
            for (j=0;j<strlen(name);j++) que[tail].name[j] = que[head].name[j];
            que[tail].time = que[head].time - q;
            head = (head+1)%QUE_SIZE;
            tail = (tail+1)%QUE_SIZE;
        }
    }
    return 0;
}


Measured memory_bytes: 5256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
struct node{
  struct node *prev;
  int number;
  struct node *next;
};
 
typedef struct node* NodePointer;
 
NodePointer N;
 
void init(void);
void insert(int);
void delete(int);
void deleteFirst(void);
void deleteLast(void);
void printList(void);
 
int main(){
  int i, n, a;
  char c[12];
 
  scanf("%d",&n);
 
  init();
 
  for(i = 1; i <= n; i++){
    scanf("%s",c);
 
    if(strcmp(c, "deleteFirst") == 0) deleteFirst();
 
    else if(strcmp(c, "deleteLast") == 0) deleteLast();
 
    else if(strcmp(c, "insert") == 0 || strcmp(c, "delete") == 0){
      scanf("%d",&a);
 
      if(strcmp(c, "insert") == 0) insert(a);
 
      else delete(a);
    }
  }
 
  printList();
 
  return 0;
}
 
void init(void){
  N = malloc(sizeof(struct node));
  N->next = N;
  N->prev = N;
}
 
void insert(int a){
  NodePointer new;
  static int count = 0;
 
  new = malloc(sizeof(struct node));
 
  new->number = a;
   
  if(count == 0){
    new->next = N;
    N->next = new;
    new->prev = N;
    N->prev = new;
    count++;
  }
 
  else{
    new->next = N->next;
    N->next->prev = new;
    N->next = new;
    new->prev = N;
    count++;
  }
}
 
void delete(int a){
  int judge = 0;
  NodePointer x;
  NodePointer y; 
   
  for(y = N->next; y != N; y = y->next){
    if(y->number == a){
      judge = 1;
    }
  }
   
  if(judge == 1){
    y = N->next;
 
    while(y != N){
      if(y->number == a) break;
      y = y->next;
    }
 
    x = y->prev;
    x->next = y->next;
    x->next->prev = x;
    free(y);
  }
}
 
void deleteFirst(void){
  NodePointer x = N->next;
  N->next = x->next;
  x->next->prev = N;
}
 
void deleteLast(void){
  NodePointer x = N->prev;
  N->prev = x->prev;
  x->prev->next = N;
  free(x);
}
 
void printList(void){
  NodePointer x = N->next;
  int y = 1;
 
  while(x != N){
    if (y == 0) printf(" ");
    printf("%d", x->number);
    x = x->next;
    y = 0;
  }
 
  printf("\n");
}

Measured memory_bytes: 31852
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int[] A = new int[N];
		for (int i=0; i<N; i++) {
			A[i] = sc.nextInt();
		}

		boolean flg = true;

		int count = 0;
		while (flg) {
			flg = false;
			for (int j=N-1; j>0; j--) {
				if (A[j]<A[j-1]) {
					int tmp = A[j];
					A[j] = A[j-1];
					A[j-1] = tmp;
					count++;
					flg = true;
				}
			}
		}
		for (int i=0; i<N; i++) {
			if (i!=0) {
				System.out.print(" ");
			}
			System.out.print(A[i]);
		}
		System.out.println();
		System.out.println(count);

		sc.close();
	}

}

Measured memory_bytes: 26408
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <stack>
#include <cmath>
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
using namespace std;
//
const int inf=1e9+7;
const int mod=1e9+7;
//
struct poi{
	int X;int Y;int Z;
	bool operator<(const poi&R)const{
		return X==R.X ? Y==R.Y ? Z<R.Z : Y<R.Y : X<R.X;
	}
};
//
ll GCD(ll a,ll b){
	return (b==0)?(a):(GCD(b,a%b));
}
ll LCM(ll a,ll b){
	return a/GCD(a,b)*b;
}
//
int H,N;
int ok[20000][4];
int DP[20000][5];
int main(){
	cin>>H>>N;
	FOR(i,0,H){
		FOR(j,0,4){
			ok[i][j]=1;
		}
	}
	FOR(i,0,N){
		int X,Y;
		cin>>X>>Y;
		ok[Y][X]=0;
	}
	/*
	cout<<endl;
	FOR(i,0,H){
		FOR(j,0,4){
			cout<<ok[i][j]<<" ";
		}
		cout<<endl;
	}
	cout<<endl;
	*/
	//
	if(ok[0][0]&&ok[0][1]&&ok[1][0]&&ok[1][1]){
		DP[0][1]=1;
	}
	if(ok[0][1]&&ok[0][2]&&ok[1][1]&&ok[1][2]){
		DP[0][2]=1;
	}
	if(ok[0][2]&&ok[0][3]&&ok[1][2]&&ok[1][3]){
		DP[0][3]=1;
	}
	if(ok[0][0]&&ok[0][1]&&ok[1][0]&&ok[1][1]&&ok[0][2]&&ok[0][3]&&ok[1][2]&&ok[1][3]){
		DP[0][4]=2;
	}
	//
	if(ok[1][0]&&ok[1][1]&&ok[2][0]&&ok[2][1]){
		DP[1][1]=DP[0][3]+1;
	}
	if(ok[1][1]&&ok[1][2]&&ok[2][1]&&ok[2][2]){
		DP[1][2]=1;
	}
	if(ok[1][2]&&ok[1][3]&&ok[2][2]&&ok[2][3]){
		DP[1][3]=DP[0][1]+1;
	}
	if(ok[1][0]&&ok[1][1]&&ok[2][0]&&ok[2][1]&&ok[1][2]&&ok[1][3]&&ok[2][2]&&ok[2][3]){
		DP[1][4]=2;
	}
	//
	FOR(i,2,H-1){
		DP[i][0]=max({DP[i-2][0],DP[i-2][1],DP[i-2][2],DP[i-2][3],DP[i-2][4],DP[i-1][0],DP[i-1][1],DP[i-1][2],DP[i-1][3],DP[i-1][4]});
		DP[i][1]=max({DP[i-2][0],DP[i-2][1],DP[i-2][2],DP[i-2][3],DP[i-2][4],DP[i-1][3],DP[i-1][0]});
		DP[i][2]=max({DP[i-2][0],DP[i-2][1],DP[i-2][2],DP[i-2][3],DP[i-2][4],DP[i-1][0]});
		DP[i][3]=max({DP[i-2][0],DP[i-2][1],DP[i-2][2],DP[i-2][3],DP[i-2][4],DP[i-1][1],DP[i-1][0]});
		DP[i][4]=max({DP[i-2][0],DP[i-2][1],DP[i-2][2],DP[i-2][3],DP[i-2][4],DP[i-1][0]});
		if(ok[i][0]&&ok[i][1]&&ok[i+1][0]&&ok[i+1][1]){
			DP[i][1]++;
		}else{
			DP[i][1]=max({DP[i][1],DP[i][0]});
		}
		if(ok[i][1]&&ok[i][2]&&ok[i+1][1]&&ok[i+1][2]){
			DP[i][2]++;
		}else{
			DP[i][2]=max({DP[i][2],DP[i][0]});
		}
		if(ok[i][2]&&ok[i][3]&&ok[i+1][2]&&ok[i+1][3]){
			DP[i][3]++;
		}else{
			DP[i][3]=max({DP[i][3],DP[i][0]});
		}
		if(ok[i][0]&&ok[i][1]&&ok[i+1][0]&&ok[i+1][1]&&ok[i][2]&&ok[i][3]&&ok[i+1][2]&&ok[i+1][3]){
			DP[i][4]+=2;
		}else{
			DP[i][4]=max({DP[i][4],DP[i][0]});
		}
	}
	int ans=0;
	/*
	FOR(i,0,H){
		FOR(j,0,5){
			cout<<DP[i][j]<<" ";
		}
		cout<<endl;
	}
	cout<<endl;
	*/
	FOR(i,0,5){
		ans=max(ans,DP[H-2][i]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3448
#include <stdio.h>

#define MONTHS 12

int main(void){
	int l;
	int m, n, ok;
	
	while (scanf("%d", &l), l){
		ok = -1;
		for (int i=1; i<=MONTHS; i++){
			scanf("%d%d",&m,&n);
			l -= (m-n);
			if (ok<0 && l<=0) ok = i;
		}
		if (ok==-1) puts("NA");
		else printf("%d\n", ok);
	}
	return 0;
}

Measured memory_bytes: 1040
n=int(input())

def GCD(a,b):
    if min(a,b)==0:
        return max(a,b)
    else:
        return GCD(min(a,b),max(a,b)%min(a,b))

def LCM(a,b):
    return (a*b)//GCD(a,b)

a=[int(i) for i in input().split(" ")]

lcm=1
for ai in a:
    lcm=LCM(ai,lcm)
print(lcm)



Measured memory_bytes: 5604
n,m,c = map(int, input().split())
bdata = [int(iz) for iz in input().split()]
adata = [list(map(int, input().split())) for _ in range(n)]

c_max = 0

for i in range(n):
    ans = 0
    for j in range(m):
        ans = ans  +  int(adata[i][j]) * bdata[j]
    if ans + c > 0:
        c_max += 1

print(c_max)



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

def dfs(c):
  if len(c) == 0:
    return []

  for i in range(len(c), 0, -1):
    if c[i-1] > i:
      return False

    if c[i-1] == i:
      cc = c.copy()
      del cc[i-1]
      res = dfs(cc)
      if res is not False:
        res.append(i)
        return res

  return False

res = dfs(b)
if res is False:
  print(-1)
else:
  for i in res:
    print(i)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main() {
    string s; cin >> s;
    int k; cin >> k;
    for (int i = 0; i < k; i++) {
        if (s[i] > '1') { cout << s[i] << endl; return 0; }
    }
    cout << s[k-1] << endl;
}


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

signed main(){
	ll n,k;
	cin>>n>>k;
	ll max=0,min=0,ans=0;
	for(ll i=k;i<=n+1;i++){
		min=(i*(i-1))/2;
		max=((n+1)*n)/2-((n-i+1)*(n-i))/2;
		ans+=(max-min+1);
	}
  	ans%=MOD;
	cout<<ans<<endl;
	return 0;
}


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

int main(){

    long long A;
    long double B;
    cin >> A >> B;

    long long C = floor(A*B);
    cout << fixed << setprecision(0) << C << endl;

    return 0;
}

Measured memory_bytes: 3728
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        String s = sc.next();

        if (a >= 3200) {
            System.out.println(s);
        } else {
            System.out.println("red");
        }
    }
}

Measured memory_bytes: 23636
// Aizu Vol-1 0190: Eleven Puzzle
// 2017.8.23 bal4u@uu
// 2017.11.21

#include <stdio.h>
#define TM 0
#if TM
#include <time.h>
#endif

typedef unsigned long long UL;

#define HASHSIZ 900001
typedef struct { UL s; char m; } HASH;
HASH hash[HASHSIZ+3], *hashend = hash+HASHSIZ;

int lookup(UL s)
{
	HASH *p = hash + s % HASHSIZ;
	while (p->s) {
		if (p->s == s) return p->m;
		if (++p == hashend) p = hash;
	}
	return -1;
}

int insert(UL s, char m)
{
	HASH *p = hash + s % HASHSIZ;
	while (p->s) {
		if (p->s == s) return 0;
		if (++p == hashend) p = hash;
	}
	p->s = s, p->m = m;
	return 1;
}

#define MAX 500000
typedef struct { UL s; char b1, b2; } QUE;
QUE Q[MAX+3], *top, *end, *qmax = Q+MAX;

int move[13][5] = {
	/*  0 */{ 2, -1 },
	/*  1 */{ 2, 5, -1 },
	/*  2 */{ 0, 1, 3, 6, -1 },
	/*  3 */{ 2, 7, -1 },
	/*  4 */{ 5, -1 },
	/*  5 */{ 1, 4, 6, 9, -1 },
	/*  6 */{ 2, 5, 7, 10, -1 },
	/*  7 */{ 3, 6, 8, 11, -1 },
	/*  8 */{ 7, -1 },
	/*  9 */{ 5, 10, -1 },
	/* 10 */{ 6, 9, 11, 12, -1 },
	/* 11 */{ 7, 10, -1 },
	/* 12 */{ 10, -1 } };

UL swap(UL s, int p, int sp)
{
	UL n;
	p = (12 - p) << 2, sp = (12 - sp) << 2;
	n = (s >> p) & 0xf;
	s &= ~(0xfULL << p);
	return s | (n << sp);
}

int sach(UL s, int b1, int b2, int mode, int lim)
{
	int i, j, x, b[2], step = 1;
	UL s2;

	top = end = Q, end->s = s, end->b1 = b1, end->b2 = b2, end++, end->s = 0, end++;
	while (top+1 < end) {
		s = top->s, b[0] = top->b1, b[1] = top->b2, top++;
		if (!s) { step++, end->s = 0, end++; continue; }
		if (step > lim) break;
//	printf("%#15llx, b1 %2d, b2 %2d, step %2d\n", s, b[0], b[1], step);
		for (i = 0; i < 2; i++) {
			for (j = 0; (x = move[b[i]][j]) >= 0; j++) {
				if (x == b[0] || x == b[1]) continue;
				s2 = swap(s, x, b[i]);
				if (mode) { if (lookup(s2) >= 0) return step; }
				else if (!insert(s2, step)) continue;
				end->s = s2;
				if (i) end->b1 = b[0], end->b2 = x;
				else   end->b1 = x, end->b2 = b[1];
				end++;
			}
		}
	}
	return step;
}

int main()
{
	UL s;
	int i, ans, p, b1, b2;
#if TM
	clock_t start, finish;
	start = clock();
#endif
	s = 0x123456789ab0ULL, insert(s, 0);
	sach(s, 0, 12, 0, 13);
	while (1) {
		for (b1 = -1, s = i = 0; i < 13; i++) {
			scanf("%d", &p);
			if (p < 0) goto done;
			if (!p) { if (b1 < 0) b1 = i; else b2 = i; }
			s = (s << 4) | p;
		}
		if ((ans = lookup(s)) < 0) {
			if ((ans = sach(s, b1, b2, 1, 7)) > 7) ans = -1;
			else ans += 13;
		}
		printf(ans < 0 ? "NA\n" : "%d\n", ans);	
	}
done:
#if TM
	finish = clock();
	printf("time %lf\n", (double)(finish-start)/CLOCKS_PER_SEC);
#endif
	return 0;
}

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

#define loop(v, f, l) for(int v = (f), v##_ = (l); v < v##_; ++v)

using namespace std;

typedef long long int lint;
static inline int in(){ int x; scanf("%d", &x); return (x); }
static inline lint inl(){ lint x; scanf("%lld", &x); return (x); }

int main()
{
	int x;
	int h;
	while( 1 )
	{
		scanf("%d%d", &x, &h);
		if( x == 0 && h == 0 )break;

		printf("%f\n", (x * x) + sqrt( (x * x / 4.0) + h * h ) * x * 2);
	}
	return (0);
}

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

int main() {
	int i, l, c=0;
	char str[80];
	
	while(fgets(str,80,stdin)!=NULL) {
	
		// Get String length
		for(l=1;;l++) {
			if (str[l]=='\0') break;
		}
		// ignore NULL
		l--;
		for(c=0;c<26;c++) {
			for(i=0;i<l;i++) {
				// if str[i] is NULL, I will do break;
				if (str[i]=='\0') break;
				// if str[i] is "." or " ", I will do nothing.
				if ((str[i]==' ')||(str[i]=='.')) continue;
				if (str[i]<='a') str[i]='z';
				else str[i]--;
			}
			
			if ((strstr(str ,"the")!=0)||
				(strstr(str ,"this")!=0)||
				(strstr(str ,"that")!=0)) break;
		}
		printf("%s",str);
	}
	return 0;
}

Measured memory_bytes: 0
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

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

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, a);
    IN(ll, b);
    IN(ll, c);
    IN(ll, d);
    YES(abs(c - a) <= d or abs(a - b) <= d and abs(b - c) <= d);
}

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

int main() {
    int n;
    cin >> n;
    vector<int> x;
    int ans = 0;
    rep(i,n) {
        int s;
        cin >> s;
        if(s%10!=0) x.push_back(s); 
        ans+=s;
    }
    sort(all(x));
    if(x.size()==0 && ans%10==0){cout << 0 << endl; return 0;}
    if(ans%10==0) ans-= x[0];
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  while(cin>>n>>m){
    if(n==0&&m==0){break;}
    int x=n;
  	int a[30],b[30];
    a[0]=n;
    vector<int>v;
    while(x!=0){
      v.push_back(x%10);
      x/=10;
    }
    int g=m-v.size();
	while(g--){
      v.push_back(0);
    }
    sort(v.begin(),v.end());
    int k=1;
    while(k){
      	int x=0,y=0;
    	for(int i=0; i<v.size(); i++){
      		x+=v[i]*pow(10,v.size()-i-1);
      		y+=v[v.size()-1-i]*pow(10,v.size()-i-1);
    	}
      	a[k]=max(x,y)-min(x,y);
        b[k]=a[k];
      	for(int i=0; i<v.size(); i++){
          v[i]=b[k]%10;
          b[k]/=10;
        }
      	sort(v.begin(),v.end());
      	k++;
      	if(k>20){break;}
    }
	    vector<pair<int,int>>vec;
    for(int i=0; i<50; i++){
      for(int j=0; j<50; j++){
        	if(i<=j){continue;}
        	if(a[i]==a[j]){
              vec.push_back(make_pair(i,j));
            }  
      	}
    }
    sort(vec.begin(),vec.end());
    cout<<vec[0].second<<" "<<a[vec[0].first]<<" "<<vec[0].first-vec[0].second<<endl;
  }
}
    
    
    
      
  
  


Measured memory_bytes: 3272
H, W = map( int, input().split() )



ans = 1e+9
for h in range(1, H):
    # 横と縦で3分割する場合
    S1 = h * W
    S2 = (H - h) * (W // 2)
    S3 = (H - h) * W - S2
    ans = min( ans, max(S1, S2, S3) - min(S1, S2, S3) )
    # 横に3分割する場合
    S2 = (H - h)//2 * W
    S3 = (H - h) * W - S2
    ans = min( ans, max(S1, S2, S3) - min(S1, S2, S3) )

# ひっくり返してもう一回
H, W = W, H 
for h in range(1, H):
    # 横と縦で3分割する場合
    S1 = h * W
    S2 = (H - h) * (W // 2)
    S3 = (H - h) * W - S2
    ans = min( ans, max(S1, S2, S3) - min(S1, S2, S3) )
    # 横に3分割する場合
    S2 = (H - h)//2 * W
    S3 = (H - h) * W - S2
    ans = min( ans, max(S1, S2, S3) - min(S1, S2, S3) )

print( ans )

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime> 

using namespace std;

int main(void){
	map<string, vector<int> > index;
	string s;
	int n;
	while(cin >>s >> n){
		index[s].push_back(n);
	}
	map<string, vector<int> >::iterator it;
	for( it = index.begin() ; it != index.end() ; ++it ){
        sort( it->second.begin() , it->second.end() );
         
        cout << it->first << endl;
        for(int i=0 ; i < it->second.size() ;i++){
            cout << it->second[i];
            ( i == it->second.size()-1 )? cout << endl : cout << " " ;
        }
    }
	return 0;
}

Measured memory_bytes: 0
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    int k = sc.nextInt();
    int[] a = new int[n];
    
    for(int i=0; i<k; i++){
      int d = sc.nextInt();
      for(int j=0; j<d; j++){
        int x = sc.nextInt()-1;
        a[x]++;
      }
    }
    
    int ans = 0;
    for(int i=0; i<n; i++){
      if(a[i]<=0){
        ans++;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 46260
#include <iostream>
#include <queue>

using namespace std;




struct link { //link connecting x and y vertices
  int x;
  int y;
  int weight;
  bool operator<(const link& other) const
  {
    return weight > other.weight; // for min priority queue, trick the operator
  }
};

priority_queue<link> links;
int roots[100];

int root(int x) {
  if (x == roots[x]) {
    return x;
  } else {
    roots[x] = root(roots[x]); //attach all to root
    return root(roots[x]);
  }
}

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

void unite(int x, int y) {
  roots[root(x)] = root(y);
}


  
int main() {
  int min_cost = 0;
  int n;
  cin >> n;


  for (int i = 0; i < n; i++) {
    roots[i] = i; // initialize roots
    for (int j = 0; j < n; j++) {
      
      int weight;
      cin >> weight;
      if (j <= i ) continue;
      if (weight != -1) {
	link new_link = {i, j, weight};
	links.push(new_link);
	//cout << "link added has i j weight: " << i << " " << j << " " << weight << endl;
      }
    }
  }

  while (!links.empty()) {
    link cur_link = links.top();
    //cout << "cur link weight: " << cur_link.weight << " x: " << cur_link.x << " y: " << cur_link.y << endl;
    if (!same(cur_link.x, cur_link.y)) {
      min_cost += cur_link.weight;
      unite(cur_link.x, cur_link.y);
    }
    links.pop();
  }

  cout << min_cost << endl;
      
    
}

Measured memory_bytes: 3156
N=int(input())
a=[0]*(N+1)
for i in range(1,N+1):
  a[i]=int(input())

now=1
cnt=0
for j in range(1,N+1):
  #print(j,cnt,now,a[now])
  if a[now]==2:
    cnt +=1
    print(cnt)
    break
  elif a[now]==now:
    print(-1)
    break
  else:
    now=a[now]
    cnt += 1
else:
  print(-1)

Measured memory_bytes: 8948
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  int a, b;
  cin >> a >> b;
  
  int x;
  int sum = 0;
  for(int i=1; i<=999; i++) {
    sum += i;
    if(sum > a) {
      x = sum + i+1;
      if(x > b) {
        if(sum-a == x-b) {
        cout << sum-a << endl;
        return 0;
        }
      }
    }
  }
}

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

long long int GCD(long long int a,long long int b){
    if(a == 0){
        return b;
    }

    return GCD(b % a, a);
}

long long int LCM(long long int a,long long int b){
    long long int gcd = GCD(a, b);
    return a / gcd * b;
}
 
int main()
{
    long long int n, gcd, ban = 1LL;
    cin >> n;
    vector<long long int> t(n);
    for(int i = 0;i < n;i++){
        cin >> t[i];
        ban = LCM(ban, t[i]);
    }
    
    cout << ban;
        
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;

vector<ll> cand;

void DFS(ll a) {
  if (a > Mod-7) {
    return ;
  }
  cand.push_back(a*10 + 3);
  cand.push_back(a*10 + 5);
  cand.push_back(a*10 + 7);
  DFS(a*10 + 3);
  DFS(a*10 + 5);
  DFS(a*10 + 7);
  return ;
}

int main() {
  ll N;
  cin >> N;
  DFS(0);
  int ans = 0;
  for (int i = 0; i < (int)cand.size(); i++) {
    if (N >= cand[i]) {
      ll t = cand[i];
      string str = to_string(t);
      bool _3 = false;
      bool _5 = false;
      bool _7 = false;
      for (int j = 0; j < (int)str.size(); j++) {
        if (str[j] == '3') {
          _3 = true;
        } else if (str[j] == '5') {
          _5 = true;
        } else {
          _7 = true;
        }
      }
      if (_3 && _5 && _7) {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4304
#include<stdio.h>

int main(){
	int n;
	int A=0;
	int B=0;
	int i=0;
	while(1){
	A=0;
	B=0;
	scanf("%d", &n);
	if(n==0){
	return 0;
	}
	int x[10000];
	int y[10000];
	i=0;
	while(i<n){
	scanf("%d", &x[i]);
	if(0>x[i] || 9<x[i]){
	return 0;
	}
	scanf("%d", &y[i]);
	if(0>y[i] || 9<y[i]){
	return 0;
	}
	++i;
}
	i=0;
	while(i<n){
	if(x[i]>y[i]){
	A=A+x[i]+y[i];
}else {
	if(x[i]<y[i]){
	B=B+x[i]+y[i];
}else{
	A=A+x[i];
	B=B+y[i];
			}
		}
	++i;
	}
	printf("%d %d\n", A, B);
	}
}

Measured memory_bytes: 0
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse = True)
q.sort(reverse = True)
r.sort(reverse = True)
p2 = p[:x]
q2 = q[:y]
r2 = r[:min((x + y), c)]
s = p2 + q2 + r2
s.sort(reverse = True)
s2 = s[:(x + y)]
print(sum(s2))

Measured memory_bytes: 113004
#include<iostream>
using namespace std;
int main()
{
  int s;
  int t;
  cin >> s >> t;
int a =s+t;
int b=s*t;
int c=s-t;

if (a>b and a>c) cout<< a;
else if (b>a and b>c) cout<< b;
else  cout << c;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll N,M,Q;
ll a[51],b[51],c[51],d[51];
ll A[11];
ll Solve(ll now){
    if(now==N){
        ll cnt=0;
        for(ll i=0;i<Q;i++){
            if(A[b[i]-1]-A[a[i]-1]==c[i]) cnt+=d[i];
        }
        return cnt;
    }
    ll ret=0;
    for(ll i=(now==0)?1:A[now-1];i<=M;i++){
        A[now]=i;
        ret=max(ret,Solve(now+1));
    }
    return ret;
}
int main(){
    cin>>N>>M>>Q;
    for(ll i=0;i<Q;i++){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
    }
    cout<<Solve(0);
    return 0;
}

Measured memory_bytes: 3636
def p_result(lenn, numm):
    result = ""
    for i in range(lenn):
        result += str(numm)
    print(result)


num = list(map(int, input().split()))
if 1 <= num[0] <= 9 and 1 <= num[1] <= 9:
    if num[0] >= num[1]:
        p_result(num[0], num[1])
    elif num[0] <= num[1]:
        p_result(num[1], num[0])
    else:
        p_result(num[0], num[1])

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


struct permutation {
    int sz;
    vector<int> a;
    permutation(int N = 0): sz(N), a(N + 10) { }
    inline void identity() {
        for(int i = 1; i <= sz; ++i)  a[i] = i;
    }
    inline void show(const char * msg) {
        printf("%s", msg);
        for(int i = 1; i <= sz; ++i) {
            printf("%d", a[i]);
            if(i < sz) putchar(' ');
        }
    }
    int& operator [] (int idx) { return a[idx]; }
    permutation operator * (permutation rhs) {
        permutation res(sz);
        for(int i = 1; i <= sz; ++i)
            res[i] = a[rhs[i]];
        return res;
    }
    bool check() {
        vector<int> _vis(sz + 3, 0);
        rep(i, sz) _vis[a[i]] = true;
        rep(i, sz) if(!_vis[i]) { puts("NO!NOT A PERMUTATION!"); return false; }
        return true;
    }
    ll decomp() {
        vector<int> _vis(sz + 3, 0);
        ll ans = -1;
        for(int i = 1; i <= sz; ++i) if(!_vis[i]) {
            ll len = 0, c = i;
            while(!_vis[c]) {
                _vis[c] = true;
                len++;
                c = a[c];
            }
            if(ans == -1) ans = len;
            else ans = ans * (len / __gcd(ans, len));
        }
        return ans;
    }
    permutation inverse() {
        permutation rev(sz);
        rep(i, sz) rev[a[i]] = i;
        return rev;
    }
};

permutation qpow(permutation p, int y) {
    permutation t(p.sz);
    t.identity();
    for(; y; y >>= 1, p = p * p)
        if(y & 1) t = t * p;
    return t;
}

int n, k;
int main() {
    scanf("%d%d", &n, &k);
    int period = (k - 1) / 6, left = k - 6 * period;
    permutation p(n), q(n), pi(n), qi(n), res(n), A(n), B(n), qpqp(n);
    rep(i, n) scanf("%d", &p[i]);
    rep(i, n) scanf("%d", &q[i]);
    pi = p.inverse();
    qi = q.inverse();
    qpqp = q * pi * qi * p;
    res.identity();

    A = qpow(qpqp, period);
    switch(left) {
        case 1: B = p; break;
        case 2: B = q; break;
        case 3: B = q * pi; break;
        case 4: B = q * pi * qi; break;
        case 5: B = q * pi * qi * p * qi; break;
        case 6: B = q * pi * qi * p * p * qi; break;
    }
    
    res = A * B * A.inverse();
    res.show("");
    putchar('\n');

    return 0;
}

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

int main()
{
    char s[100];
    int l,i,k=0;
    gets(s);
    l=strlen(s);
    for(i=0; i<l-1; i++)
    {
        if(s[i]=='A' && s[i+1]=='C')
        {
            k=1;
            break;
        }
    }
    if(k==1)printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main(){
    int a;
    int b;
    int c;

    cin >> a >> b >> c;

    if(a+b+c==17)
        if(a==7)
        {
            if(b==c)
            {
                cout << "YES" << endl;
            }
        }
        else if (b==7)
        {
            if(a==c)
            {
                cout << "YES" << endl;
            }
        }
        else if (c==7)
        {
            if(a==b)
            {
                cout << "YES" << endl;
            }
        }
        else
        {
            cout << "NO" << endl;
        }
    else
    {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define min(p,q)((p)<(q)?(p):(q))
#define INF ((1LL<<62)-(1LL<<31))

//辺の情報を個別に持つタイプ
typedef struct edge{ll s,g,c;}E;
typedef struct graph{
	int vcnt,ecnt;
	E  e[200010];//適宜変える
	int id[100010];//適宜変える
}G;

int esort(const void*a,const void*b){
	E*p=(E*)a,*q=(E*)b;
	if((*p).s<(*q).s)return -1;
	if((*p).s>(*q).s)return  1;
	if((*p).g<(*q).g)return -1;
	return 1;
}

G g;
void readgraph(){
	//適宜変える
	ll n;
	ll m=0;
	scanf("%lld",&n);
	rep(i,0,n){
		ll t,k;
		scanf("%lld%lld",&t,&k);
		while(k--){
			int s;
			scanf("%d",&s);
			g.e[m].s=t;
			g.e[m].g=s;
			g.e[m].c=1;
			m++;
		}
	}
	g.vcnt=n+1;
	g.ecnt=m;
	qsort(g.e,g.ecnt,sizeof(E),esort);
//	qsort(g.e,g.ecnt,sizeof(E),csort);

	int p=0;
	rep(i,0,g.vcnt){
		while(p<g.ecnt&&g.e[p].s<i)p++;
		g.id[i]=p;
	}
	g.id[g.vcnt]=g.ecnt;//番兵
}

//ベルマンフォード
//グラフと始点を引いて単一始点最短経路を返す
//辺のソートは不要
//O(EV)、負辺ありでもOK
//*
ll d[1010];
void berumanfoodo(G g,ll s){
	rep(i,0,g.vcnt)d[i]=i==s?0:INF;
	rep(nnnn,0,g.vcnt-1)rep(i,0,g.ecnt)if(d[g.e[i].s]!=INF)d[g.e[i].g]=min(d[g.e[i].g],d[g.e[i].s]+g.e[i].c);
	rep(nnnn,0,g.vcnt)rep(i,0,g.ecnt)if(d[g.e[i].s]!=INF){
		if(d[g.e[i].g]>d[g.e[i].s]+g.e[i].c)d[g.e[i].g]=-INF;
	}
}
//*/

int main(){
	readgraph();
	berumanfoodo(g,1);
	for(int i=1;i<g.vcnt;i++)printf("%d %d\n",i,d[i]==INF?-1:d[i]);
}


Measured memory_bytes: 6880