akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937 mt32(rnd());
	std::uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt32);
}
/*--------Library Zone!--------*/



signed main() {
	int n;
	string s,t,ans;
	cin>>n>>s>>t;
	rep(i,n){
		ans.push_back(s[i]);
		ans.push_back(t[i]);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
H,W = map(int,input().split())
grid = []
X = [['.']*W for _ in range(H)]
for i in range(H):
    grid.append(list(input()))
cur = 0
for i in range(H):
    if grid[i][cur] == '.':
        print('Impossible')
        exit()
    grid[i][cur] = '.'
    if cur != W-1:
        while grid[i][cur+1] == '#':
            grid[i][cur+1] = '.'
            cur += 1
            if cur == W-1:
                break

if grid != X:
    print('Impossible')
else:
    print('Possible')

Measured memory_bytes: 62088
num = int(input())

m = 0
a = 0
r = 0
c = 0
h = 0

P1 = [0 ,0 ,0 ,0 ,0 ,0 ,1 ,1 ,1 ,2]
P2 = [1 ,1 ,1 ,2 ,2 ,3 ,2 ,2 ,3 ,3]
P3 = [2 ,3 ,4 ,3 ,4 ,4 ,3 ,4 ,4 ,4]


for _ in range(num):
    word = input()
    if word[0] == 'M':
        m += 1
    if word[0] == 'A':
        a += 1
    if word[0] == 'R':
        r += 1
    if word[0] == 'C':
        c += 1
    if word[0] == 'H':
        h += 1

D = [m, a, r, c, h]

sum = 0
for d in range(10):
    sum += D[P1[d]] * D[P2[d]] * D[P3[d]]

print(sum)

Measured memory_bytes: 3064
#include <stdio.h>
int main(void)
{
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if(c>b)
	printf("0\n");
	if(c<=b)
	{
		if(a>c)
		{
			if(d>a)
			{
			    if(b>d)
			    printf("%d\n",d-a);
			    else
			    printf("%d\n",b-a);
		    }
		    if(d<=a)
		    printf("0\n");
		}
		if(a<=c)
		{
			if(d>b)
			printf("%d\n",b-c);
			else
			printf("%d\n",d-c);
		}
	}
	return 0;
}

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

int maxHappy() {

    int n; cin >> n;
    int happy[n][3];
    for (int i = 0; i < n; i++)
        cin >> happy[i][0] >> happy[i][1] >> happy[i][2];

    if (n > 1) {
        for (int i = 1; i < n; i++) {
            happy[i][0] = happy[i][0] + max(happy[i - 1][1] , happy[i - 1][2]);
            happy[i][1] = happy[i][1] + max(happy[i - 1][0] , happy[i - 1][2]);
            happy[i][2] = happy[i][2] + max(happy[i - 1][0] , happy[i - 1][1]);
        }
    }

    int ans = happy[n - 1][0];
    ans = max(ans, (max(happy[n - 1][1], happy[n - 1][2])));
    return ans;
}

int main()
{
    cout << maxHappy();
    return 0;
}


Measured memory_bytes: 1408
from collections import deque

H, W = map(int, input().split())
C = tuple(map(lambda a: int(a) - 1, input().split()))
D = tuple(map(lambda a: int(a) - 1, input().split()))
S = [input() for _ in range(H)]
INF = 10**18

def cord(h, w):
    return h * W + w

minDist = [INF] * (H * W + 10)
que = deque([(C, 0)])
minDist[cord(*C)] = 0

while que:
    (h, w), dist = que.popleft()

    for dh in range(-2, 3):
        for dw in range(-2, 3):
            toH, toW = h + dh, w + dw
            if not (0 <= toH < H and 0 <= toW < W) or (h, w) == (toH, toW):
                continue
            if S[toH][toW] == '#':
                continue

            d = 0 if (abs(dh) + abs(dw) <= 1) else 1
            if minDist[cord(toH, toW)] > dist + d:
                minDist[cord(toH, toW)] = dist + d
                if d == 0: que.appendleft(((toH, toW), dist + d))
                else: que.append(((toH, toW), dist + d))

print(minDist[cord(*D)] if minDist[cord(*D)] < INF else -1)


Measured memory_bytes: 97236
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

void  base_num(ll data,ll base){
    if(data==0) return;
    ll next=abs(data)%abs(base);
    if(data<0) next=(abs(base)-next)%abs(base);
    base_num((data-next)/base,base);
    cout << next;
}


int main(){
    string s;
    ll a=0,b=0;
    cin >> s;
    for (ll i=0;i<s.size();i++){
        if (s[i]-'0'==1){
            a++;
        }else{
            b++;
        }
    }
    cout << min(a,b)*2 << endl;
    return 0;
}


Measured memory_bytes: 512
sx,sy,tx,ty = map(int,input().split())

width = tx-sx 
height = ty-sy
ans = ''
ans += 'U'*height
ans +='R'*width

ans += 'D'*height
ans += 'L'*width

ans +='L'
ans +='U'*(height+1)
ans +='R'*(width+1)
ans += 'D'

ans +='R'
ans +='D'*(height+1)
ans +='L'*(width+1)
ans += 'U'


print(ans)

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

int main()
{
	for (int i = 1; i < 10; i++)
	{
		for (int j = 1; j < 10; j++)
		{
			cout << i << "x" << j << "=" << i*j << endl;

		}
	}
	return 0;
}

Measured memory_bytes: 3004
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

int N, M, K;

int n, m, k;

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

    cin >> N >> M >> K;

    /* k = n * M + N * m - n * m * 2 */

    for (n = 0; n <= N; ++n)
    {
        for (m = 0; m <= M; ++m)
        {
            if (n * M + N * m - n * m * 2 == K)
            {
                cout << "Yes\n";
                return 0;
            }
        }
    }

    cout << "No\n";

    return 0;
}



Measured memory_bytes: 256
M=9;main(n,i,j,k,a,b,c){
	double p=atan(1)*4,X[100],Y[100],x,y;
	for(;scanf("%d",&n),n;printf("%d\n",a)){
		for(i=0;i<n;i++)scanf("%lf,%lf",X+i,Y+i);
		for(a=i=0;i<n;i++){
			for(b=k=0;k<M;k++){
				x=X[i]+cos(p*k/M),y=Y[i]+sin(p*k/M);
				for(c=j=0;j<n;j++){
					if((X[j]-x)*(X[j]-x)+(Y[j]-y)*(Y[j]-y)<1+1e-3)c++;
				}
				if(b<c)b=c;
			}
			if(a<b)a=b;
		}
	}
exit(0);}

Measured memory_bytes: 644
package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	fmt.Fprintf(writer, "%d:", n)
	dd := make([]int, 0)
	for n > 1 {
		d := div(n)
		dd = append(dd, d)
		n /= d
	}
	for i := 0; i < len(dd); i++ {
		fmt.Fprint(writer, " ")
		fmt.Fprint(writer, dd[i])
	}
	fmt.Fprintln(writer, "")
}
func div(x int) int {
	for i := 2; i*i < x+1; i++ {
		if x%i == 0 {
			return i
		}
	}
	return x
}



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

int main() {
  int N, K, i = 0, ans = 1;
  cin >> N >> K;

  for (; i < N && ans < K; i++) {
    ans *= 2;
  }
  for (; i < N; i++) {
    ans += K;
  }
  cout << ans << endl;
}

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

int main(){
    long long s;cin>>s;int ans=1000;
    while(s>99){
        int a=s%1000;
        ans=min(max(a-753,753-a),ans);
        s/=10;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main() {
map<string,int> msi;
string s;
int ma=0;
int ma2=0;
string ans;
string ans2;
while (cin >> s){
	if (!EXIST(msi,s))
		msi[s]=1;
	else{
		msi[s] = msi[s]+1;
		if (ma2<msi[s]){
		ans2=s;
		ma2 = msi[s];
		}
		}
	if (ma < s.length()){
	ans=s;
	ma = s.length();
	}
}
cout << ans2 << " "<<ans<<endl;
	return 0;
}

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

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e19;
const int MOD = 1e9 + 7;

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a, b;
    cin >> a >> b;
    cout << (a >= 13 ? b : (a > 5 ? b/2 : 0)) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;
template<class T> inline void chkmax(T &x, const T &y) { if(x < y) x = y; }
template<class T> inline void chkmin(T &x, const T &y) { if(x > y) x = y; }
const int MAXN = (1 << 20);

string s;

void read()
{
	cin >> s;
}

void solve()
{
	int l = 0, r = s.size() - 1, ans = 0;
	while(l <= r)
	{
		if(s[l] == s[r]) 
		{
			l++;
			r--;
			continue;
		}

		if(s[l] == 'x')
		{
			l++;
			ans++;
			continue;
		}

		if(s[r] == 'x')
		{
			r--;
			ans++;
			continue;
		}

		cout << -1 << endl;
		return;
	}

	cout << ans << endl;
}

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

	read();
	solve();
	return 0;
}



Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int K = Integer.parseInt(sc.next());
		sc.close();

		if(N % K == 0) {
			System.out.println(0);
		}else {
			System.out.println(1);
		}

	}
}

Measured memory_bytes: 21844
s = input()
s0 = s[0]
if ((s[0] == s[1] and s[2] == s[3]) or (s[0] == s[2] and s[1] == s[3]) or (s[0] == s[3] and s[1] == s[2])) and (not (s[0] == s[1] and s[0] == s[2])):
  print("Yes")
else:
  print("No")

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

int main() {

	int X;
	cin >> X; //砂時計のパーツの残量
	int x;
	cin >> x; //経過秒数

	int Z = X - x;
	if (Z > 0){
		cout << Z;
	}
	else{
		cout << 0;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
 
#define barsik ios::sync_with_stdio(false)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair <int, int> pii;
typedef std::unordered_set <int> u_si;
const double PI = acos(-1);
const long double EPS = 1e-9;
using namespace std;

int sum(int n){
    int ans = 0;
    while(n > 0){
        ans += n % 10;
        n /= 10;
    }
    return ans;
}

void solve(){
    int n;
    cin >> n;
    if(n % sum(n) == 0) cout << "Yes";
    else cout << "No";
}
int main(){
    int q = 1;
    //cin >> q;}
    while(q--) solve();
}


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

def isnot_fizzbuzz(number: int) -> bool:
    if (number) % 3 != 0 and (number) % 5 != 0:
        return True
    return False

def main():
    sum = 0
    for number in range(1, N + 1):
        if isnot_fizzbuzz(number) == True:
            sum += number
    print(sum)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9160
#include <bits/stdc++.h>
using namespace std;
int main () {
  int a,b,c;
  cin >> a >> b >> c;
  if(2*max({a,b,c})==a+b+c){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
N=int(input())
mojiretsu=[]
c1=""
c2=""

c3=""
c4=""
for i in range(N):
    mojiretsu.append(input())

for i in range(N):
    c1=mojiretsu[i]
    for j in range(N):
        c2=mojiretsu[j]
        if i!=j:
            if c1==c2:
                print("No")
                exit()

for i in range(N-1):
    c3=mojiretsu[i]
    c3=c3[-1]
    c4=mojiretsu[i+1]
    c4=c4[0:1]
    
    if c3!=c4:
        print("No")
        exit()
        
                
print("Yes")
                


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

const int N = 505;
int n, m;
char s[N][N], a[N][N], b[N][N];

int main() {
    cin >> n >> m;
    rep(i, 1, n) {
        scanf("%s", s[i] + 1);
        rep(j, 1, m) a[i][j] = b[i][j] = s[i][j];
    }
    rep(i, 1, m) {
        a[1][i] = b[n][i] = '#';
        rep(j, 2, n - 1)
            (i % 2) ? a[j][i] = '#' : b[j][i] = '#';
    }
    rep(i, 1, n) printf("%s\n", a[i] + 1);
    puts("");
    rep(i, 1, n) printf("%s\n", b[i] + 1);
    return 0;
}


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

using namespace std;
using uint = unsigned int;
using int64 = long long;
using i64 = int64;
using uint64 = unsigned long long;
using vint = vector<int>;
using vint64 = vector<int64>;
template<typename T>
using p_que = priority_queue<T>;
#define rep(i,N) for(int i=0;i<(int)(N);++i)
#define rep1(i,N) for(int i=1;i<=(int)(N);++i)
#define fs first
#define sc second
#define eb emplace_back
#define all(x) x.begin(),x.end()

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

template<class T> ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "[";
	for (auto& e : v) os << e << ", ";
	return os << "]";
}

template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U> p) {
	return os << "P(" << p.first << ", " << p.second << ")";
}

template<class T, class U> ostream& operator<<(ostream& os, const map<T, U>& mp) {
	os << "{";
	for (auto& e : mp) os << e << " ";
	return os << "}";
}

void Main();
signed main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	Main();
}

/* Cut from here! */

#define int long long

void Main() {
	int m, f, b; cin >> m >> f >> b;
	if (m < b) {
		if (m + f < b) {
			cout << "NA" << endl;
		}
		else {
			cout << b - m << endl;
		}
	}
	else {
		cout << 0 << endl;
	}
}


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

 double pi=3.14159265358979323846;

 
int main(){
    int t=1;
    //cin>>t;
    while(t--){
        int n,m;
        cin>>n>>m;
        map<int,vector<int> > m1;
        int a,b;
        for(int i=0;i<m;i++){
            cin>>a>>b;
            m1[a].push_back(b);
            m1[b].push_back(a);
        }
        vector<int> ans(n);
        vector<int> visited(n+1,0);
        visited[1]=1;
        queue<int> q;
        q.push(1);
        while(!q.empty()){
            int n=q.front();
            q.pop();
            vector<int> temp=m1[n];
            for(auto x:temp){
                if(visited[x]==0){
                    ans[x-1]=n;
                    q.push(x);
                    visited[x]=1;
                }
            }
        }
        int flag=0;
        for(int i=1;i<n;i++){
            if(ans[i]==0){
                cout<<"No"<<endl;
                flag=1;
                break;
            }
        }
        if(flag==0){
            cout<<"Yes"<<endl;
            for(int i=1;i<n;i++) cout<<ans[i]<<endl;
        }
    }


    
}

Measured memory_bytes: 16452
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
	ll ch[102][5][2];
int main() {
	ll k;
	string s;
	cin>>s>>k;
	ch[0][0][0]=1;
	for(ll i=0;i<s.size();i++){
		for(ll j=0;j<=9;j++){
			ll now=s[i]-'0';
			if(now<j){
				if(j==0){
					for(ll l=0;l<4;l++){
						ch[i+1][l][1]+=ch[i][l][1];
					}
				}
				else{
					for(ll l=0;l<4;l++){
						ch[i+1][l+1][1]+=ch[i][l][1];
					}					
				}
			}
			else if(now==j){
				if(j==0){
					for(ll l=0;l<4;l++){
						ch[i+1][l][0]+=ch[i][l][0];
						ch[i+1][l][1]+=ch[i][l][1];
					}
				}
				else{
					for(ll l=0;l<4;l++){
						ch[i+1][l+1][0]+=ch[i][l][0];
						ch[i+1][l+1][1]+=ch[i][l][1];
					}					
				}				
			}
			else if(now>j){
				if(j==0){
					for(ll l=0;l<4;l++){
						ch[i+1][l][1]+=ch[i][l][0];
						ch[i+1][l][1]+=ch[i][l][1];
					}
				}
				else{
					for(ll l=0;l<4;l++){
						ch[i+1][l+1][1]+=ch[i][l][0];
						ch[i+1][l+1][1]+=ch[i][l][1];
					}					
				}					
			}
		}
	}
	cout << ch[s.size()][k][0]+ch[s.size()][k][1];
	// your code goes here
	return 0;
}

Measured memory_bytes: 3612
//abc140-b
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin >> n;
    //int a[n], b[n], c[n];
    vector<int> a(n), b(n), c(n-1);
    int num=0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        a[i]--;
    }
    for(int i=0;i<n;i++) cin >> b[i];
    for(int i=0;i<n-1;i++) cin >> c[i];
    
    for(int i=0;i<n;i++){
        num += b[a[i]];
        if(i>0 && a[i]-1==a[i-1]) num += c[a[i-1]];
    }
    cout << num << 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 rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

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

void Main()
{
	string s, t;
	cin >> s >> t;
	sort(all(s));
	sort(rall(t));
	// cout << s << endl;
	// cout << t << endl;
	if(s<t) puts("Yes");
	else puts("No");
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

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

int main() {
    int n;
    std::cin >> n;
    std::vector<int> pow(21);
    pow[0] = 1;
    for (int i = 1; i < 21; i++) pow[i] = pow[i - 1] * 2;
    int d = 1, cnt = std::bitset<20>(n).count();
    while (n >> (d + 1) > 0) d++;
    std::cout << d + 1 << " " << 2 * d + cnt - 1 << "\n";
    int s = d + 1;
    for (int i = 1; i <= d; i++) {
        int cost = pow[d - i];
        std::cout << i << " " << i + 1 << " " << 0 << "\n";
        std::cout << i << " " << i + 1 << " " << cost << "\n";
    }
    int cc = 1 << d;
    n -= cc;

    while (n) {
        while (n >> (d - 1) == 0) d--;
        std::cout << 1 << " " << s - d + 1 << " " << cc << "\n";
        cc += pow[d - 1];
        n -= pow[d - 1];
    }

    std::cout << std::flush;

    return 0;
}


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

typedef long long ll;
typedef pair<int,int> pii;

#define F first
#define S second
#define make_pair MP

const int MAX = 2000+9;
const ll MOD = 1e9+7;

vector <int> g[MAX];
queue <int> q;
int dis[MAX];

int main () {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n-1; i++) {
		int v, u;
		cin >> v >> u;
		v--, u--;
		g[v].push_back(u);
		g[u].push_back(v);
	}
	int res = n;
	if (k%2) {
		k /= 2;
		for (int i = 0; i < n; i++) {
			for (auto t : g[i]) {
				if (i < t) continue;
				memset(dis, -1, sizeof dis);
				q.push(i);
				dis[i] = 0;
				while (q.size()) {
					int v = q.front();
					q.pop();
					for (auto u : g[v]) {
						if (dis[u] != -1 || u == t) continue;
						dis[u] = dis[v] + 1;
						q.push(u);
					}
				}
				q.push(t);
				dis[t] = 0;
				while (q.size()) {
					int v = q.front();
					q.pop();
					for (auto u : g[v]) {
						if (dis[u] != -1 || u == i) continue;
						dis[u] = dis[v] + 1;
						q.push(u);
					}
				}
				int cost = 0;
				for (int t = 0; t < n; t++)
					if (dis[t] > k) cost++;
				res = min(res, cost);
			}
		}
	} else {
		k /= 2;
		for (int i = 0; i < n; i++) {
			memset(dis, -1, sizeof dis);
			q.push(i);
			dis[i] = 0;
			while (q.size()) {
				int v = q.front();
				q.pop();
				for (auto u : g[v]) {
					if (dis[u] != -1) continue;
					dis[u] = dis[v] + 1;
					q.push(u);
				}
			}
			int cost = 0;
			for (int t = 0; t < n; t++)
				if (dis[t] > k) cost++;
			res = min(res, cost);
		}
	}
	cout << res << "\n";
}

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

int main(){
  int X;
  cin >> X;
  int sum=X;
  for(int i=1;;i++){
    if(sum%360==0){
      cout << i << endl;
      break;
    }
    sum+=X;
  }
  return 0;
}


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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define ld long double
#define mem(x,y) memset(x,y,sizeof x)

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> ordered_set;

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
/*
 * Be careful of overflow
 * Array bounds
 * Assert a!=0 when performing x/a
 * Check base condition for recursion
 * Iterator -> O(1), Element -> O(log n) while using erase
 * 1LL<<x when x>32
 * Be sure of what you are going to code (exception dp)
 * Don't try fancy tricks during contest
 * You can always make a bad round to a good enough round
 */ 
ll dp[3009][3009][4];
int v[3009][3009];
void solve()
{
	int r,c,i,j,k;
	cin>>r>>c>>k;
	for(i=0;i<k;i++)
	{
		int a,b,cc;
		cin>>a>>b>>cc;
		v[a][b]=cc;
	}
	for(i=1;i<=r;i++)
	for(j=1;j<=c;j++)
	{
		dp[i][j][0]=max({dp[i-1][j][0],dp[i-1][j][1],dp[i-1][j][2],dp[i-1][j][3]});
		dp[i][j][1]=max({dp[i][j][0]+v[i][j],dp[i][j-1][0]+v[i][j],dp[i][j-1][1]});
		dp[i][j][2]=max({dp[i][j][1],dp[i][j-1][1]+v[i][j],dp[i][j-1][2]});
		dp[i][j][3]=max({dp[i][j][2],dp[i][j-1][2]+v[i][j],dp[i][j-1][3]});
	}
	cout<<max({dp[r][c][0],dp[r][c][1],dp[r][c][2],dp[r][c][3]});
}

int main()
{
	IOS
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}


Measured memory_bytes: 320876
#include<bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long int ll;
typedef long double ld;
const ll INF=(1LL<<62);
const ld pi=acosl((ld)-1);
const ll mod = 1000000007;
// const ll mod = 1234567;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
#define endn "\n"
#define TO_STRING(VariableName) # VariableName

bool solve(){
	set<ld>st;
	rep(i,200)st.insert(i-10);
	ld x;cin>>x;
	int n;cin>>n;
	rep(i,n){
		ld a;cin>>a;st.erase(a);
	}
	ld num=0;
	for(auto&& q:st){
		if(abs(q-x)<abs(num-x))num=q;
	}
	cout<<(ll)num<<endl;
  	return false;
}

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout<<fixed<<setprecision(15);
  solve();
}


Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  sort(s.begin(), s.end());
  if (s[0] == s[1] && s[2] == s[3] && s[1] != s[2]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <queue>
#include <deque>
#include <iomanip>
#include <cmath>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>

#define FOR(i,n) for(int i=0;i<n;i++)
#define FORE(i,a,b) for(int i=a;i<=b;i++)
#define ll long long 
//#define int long long
#define ld long double
#define vi vector<ll>
#define pb push_back
#define ff first
#define ss second
#define ii pair<int,int>
#define iii pair<int,ii>
#define il pair<ll,ll>
#define vv vector
#define endl '\n'

using namespace std;

const ll MOD = 998244353;
ll fxp(ll a,ll b){
    if(b == 0)return 1;
    if(b%2 == 0){
        ll c = fxp(a,b/2);
        return (c*c)%MOD;
    }else{
        return (a*fxp(a,b-1))%MOD;
    }
}
//ll f[3001*3001];
void solve(){
    //f[0] =1;
    //FORE(i,1,3000*3000)f[i] = (i*f[i-1])%MOD;
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    //ll x = c*d - a*b;
    //ll y = c+d - a-b;
    //ll ans = (((f[x]*fxp(f[x-y],MOD-2))%MOD)*fxp(f[y],MOD-2))%MOD;
    //cout << ans << endl;
    //return;


    ll dp[c+1][d+1];
    FOR(i,c+1)FOR(j,d+1)dp[i][j] = 0;
    dp[a][b] = 1;
    FORE(i,a,c){
        FORE(j,b,d){
            if(i == a and b == j)continue;
            else{

                if(i > a)dp[i][j] += (dp[i-1][j]*j)%MOD;
                if(j > b)dp[i][j] += (dp[i][j-1]*i)%MOD;
                if(i > a and j > b)dp[i][j] -= ((i-1)*(j-1)*dp[i-1][j-1])%MOD;
                dp[i][j] += MOD;
                dp[i][j] %= MOD;
            }
        }
    }
    
    cout << dp[c][d] << endl;
}

int main(){
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    while(t--)solve();
    return 0;
}

Measured memory_bytes: 73968
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
using namespace std;

int ndig_cnt(int dig, int k) {
  if (dig < k) return 0;
  else if (k == 0 && dig == 1) return 1;
  else if (k == 0) return 0;
  else if (k == 1) return 9;
  else if (k == 2) {
    int base = 9 * 9;
    int divident = (dig - 1); 
    return base * divident;
  } else {
    int base = 9 * 9 * 9;
    int divident = (dig - 1) * (dig - 2); 
    int divider = 2;
    return base * divident / divider;
  }
}

int ndig_cnt_accum(int nd, int k) {
  int sum = 0;
  for (int i = 1; i <= nd; i++) {
    sum += ndig_cnt(i, k);
  }
  return sum;
}


int rec(string& N, int idx, int nd, int k) {
  //cout << "rec called:" << idx << "," << nd << "," << k << endl; 
  if (nd < k) {
    return 0;
  } else if (nd == 1 && k != 0) {
    //cout << N[idx] << endl;
    return N[idx] -'0';
  } else if (k == 0) {
    return 1;
  }
  if (N[idx] == '0') {
    return rec(N, idx + 1, nd - 1, k);
  } else {
    int res = ndig_cnt_accum(nd - 1, k);
    //cout << "check2 :" << res << endl;
    res += (N[idx] - '1') * ndig_cnt_accum(nd - 1, k - 1);
    res += rec(N, idx + 1, nd - 1, k -1);
    return res;
  }
}

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

  string N;
  cin >> N;
  int K;
  cin >> K;
  int nd = N.size(); 
  if (nd < K) {
    cout << 0 << endl;
    return 0;
  } else if (nd == 1) {
    cout << N[0] - '0' << endl;
    return 0;

  }

  //cnt_init(nd);
  int sum = ndig_cnt_accum(nd - 1, K);
  sum += (N[0] - '1') * ndig_cnt_accum(nd - 1, K - 1);
  //cout << "check1: " << sum << endl;
  sum += rec(N, 1, nd - 1, K - 1);
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<string> W(N);
  for (int i=0; i<N; i++) cin >> W[i];
  bool ans = true;
  for (int i=0; i<N-1; i++) {
    if (W[i][W[i].length()-1] != W[i+1][0]){
      ans = false;
    }
  }
  for (int  i=0; i<N; i++) {
    for (int j=0; j<i; j++) {
      if (W[i] == W[j]) {
        ans = false;
      }
    }
  }
  if (ans) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
n,k=map(int,input().split())

ans = 0
count=[0]*k
mod = 10**9+7
for i in range(0,k):
  kk=k-i#考える最大公約数
  maxi=k//kk#k以下のkkの倍数の個数
  count1=pow(maxi,n,mod)
  count2=0
  for j in range(2,maxi+1):
    count2 = count2 + count[j*kk-1]
  count[kk-1]=(count1 - count2)%mod

for l in range(0,k):
  ans = (ans + ((l+1)*count[l])%mod)%mod

print(ans)


Measured memory_bytes: 11096
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		long x = sc.nextLong();
		long y = sc.nextLong();
		
		int cnt = 0;
		while(x<=y){
			cnt++;
			x*=2;
		}
		
		System.out.println(cnt);
	}

}


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

int NextInt() {
    int tmp;
    if (scanf("%d", &tmp) != 1) {
        throw std::runtime_error("NextInt");
    }
    return tmp;
}

#define ForRange(i, a, b) for (auto i = a; i < b; i += 1)
#define ForAll(i, a, b) for (auto i = a; i <= b; i += 1)

constexpr int kMaxN = 1000 + 3;
constexpr int kMaxMost = 5000 + 5;
constexpr int kInf = 1e9;

int most[kMaxMost];
int minDiff[kMaxN];

typedef std::vector<std::vector<int>> VVI;

void TravelTree(const VVI& son, int u) {
    for (int v: son[u]) {
        TravelTree(son, v);
    }

    static int dp[2][kMaxMost];
    int flag = 1;

    ForAll(i, 0, most[u]) {
        dp[!flag][i] = 0;
    }
    for (int v: son[u]) {
        auto dpNow = dp[flag];
        auto dpPre = dp[!flag];

        if (minDiff[v] == kInf) {
            minDiff[u] = kInf;
            return;
        }

        ForAll(sumSame, 0, most[u]) {
            dpNow[sumSame] = kInf;
            if (sumSame >= most[v]) {
                // v u same color
                dpNow[sumSame] = dpPre[sumSame - most[v]] + minDiff[v];
            }
            if (sumSame >= minDiff[v]) {
                // v u diff color
                // assert(v >= 0 and v < kMaxN);
                // assert(sumSame >= 0 and sumSame < kMaxMost);
                // assert(sumSame - minDiff[v] >= 0);
                // assert(sumSame - minDiff[v] < kMaxMost);
                dpNow[sumSame] = std::min(dpNow[sumSame], 
                                 dpPre[sumSame - minDiff[v]] + most[v]);
            }
        }
        flag ^= 1;
    }
    
    auto dpFinal = dp[!flag];
    minDiff[u] = kInf;
    ForAll(sumSame, 0, most[u]) {
        minDiff[u] = std::min(dpFinal[sumSame], minDiff[u]);
    }
}

int main() {
    int n = NextInt();
    
    VVI son(n);
    ForRange(i, 1, n) {
        int parent = NextInt();
        son[parent - 1].push_back(i);
    }

    ForRange(i, 0, n) {
        most[i] = NextInt();
    }

    int root = 0;
    TravelTree(son, root);
    puts(minDiff[root] == kInf ? "IMPOSSIBLE" : "POSSIBLE");
    return 0;
}



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

using namespace std;
using ll =long long;
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
//Write From this Line
ll dp[52][52][2510]; // おそらく初期値は全部0
int main()
{
	int n, a;
	cin >> n >> a; // average を a 円にする！
	vector<int> x(n);
	rep(i,n) cin >> x[i]; 
	// dp[i][j][k] := i 枚目までで j 枚選択して和を k にするときの組み合わせが何通りあるか。 

	rep(i,52){
		rep(j,52){
			rep(k,2510){
				// 任意の i に対して j == 0 , k == 0 は1
				if(j == 0 && k == 0) dp[i][j][k] = 1;
				else dp[i][j][k] = 0;
			}
		}
	}

	/* 遷移は、今見ているカードの数字が X のとき,Xを使うなら X が j 枚目になるから
	   dp[i][j][k] = dp[i-1][j-1][k-X] + dp[i-1][j][k];
	 */

	ll ans = 0;
	for(int i = 1; i <= n; i++){
		int X = x[i-1]; 
		for(int j = 1; j <= n; j++){
			for(int k = 1; k <= 2500; k++){
				if(k <= X - 1){
					// (X - 1　までは、そいつを使うことはできない)
					dp[i][j][k] = dp[i-1][j][k];
					continue;
				}
				dp[i][j][k] = dp[i-1][j-1][k-X] + dp[i-1][j][k];
			}
		}
	}

	// n 枚目までで j 枚選んだとき j * a になるやつをansに足す
	rep(j,n+1){
		ans += dp[n][j][j*a] ;
	}
	// なぜか1大きい値が出力されるので-1する
	cout << ans - 1<< endl;
}


Measured memory_bytes: 53248
#include <stdio.h>
#include <string.h>

char *reverse(char *s)
{
    int i;
    char tmp;
    for(i=0; i<strlen(s)/2; i++){
        tmp = s[i];
        s[i] = s[strlen(s)-1-i];
        s[strlen(s)-1-i] = tmp;
    }
    return s;
}

int main()
{

    char str[21];

    fgets(str, sizeof(str), stdin);
    printf("%s\n", reverse(str));

    return 0;
}

Measured memory_bytes: 524
M[100],i,j,h,s;char*N[100],B[];main(n,m){for(;scanf("%d%d",&n,&m)*n;printf("%d\n",s)){for(i=n;i--;)scanf("%as%d",N+i,M+i);for(s=0;m--;)for(scanf("%s",B),i=n;i--;s+=M[i]*!h)for(h=j=0;j<8;j++)h|=N[i][j]-42&&N[i][j]-B[j];}}

Measured memory_bytes: 0
//============================================================================
// Name        : Watch.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
	int s;
	cin >> s;
	cout << s/(60*60) << ":" << (s%(60*60))/60 << ":" << (s%60) << endl;
	return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 998244353;

ll calc(ll b, ll n) {
	if (n < b) 	return n;
	else return n%b + calc(b, n / b);
}

int main() {
	ll n, s; cin >> n >> s;
	if (n == s) {
		cout << n + 1 << endl;
		return 0;
	}

	// b <= √n) の場合、全探索可能
	ll root = sqrt(n);
	for (ll b = 2; b <= root; ++b) {
		ll tmp = calc(b, n);
		if (tmp == s) {
			cout << b << endl;
			return 0;
		}
	}

	// b >= √n の場合
	//   n = p*b + q (q < b)
	//   s = p + q
	// b >= √nなので、
	// n >= p * √n + q -> p <= √n
	// p == 0の場合 -> n==sなので検査済み
	ll ans = -1;
	for (ll p = 1; p <= root; ++p) {
		ll q = s - p;
		ll b = (n-s)/p + 1;
		if (b <= root || q > b) continue;
		ll tmp = calc(b, n);
		if (tmp == s) {
			ans = b;
		}
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define REP(i,a,b,c) for(int i=a;i<=b;i+=c)
const int N = 1e5+5;
const int maxVal=1e4+5;
int a[N];
int dp[N];
using namespace std;
signed main(){
	int n;cin>>n;
	REP(i,0,n-1,1)cin>>a[i];
	REP(i,0,N-1,1) dp[i]=maxVal;
	dp[n-2]=abs(a[n-1]-a[n-2]);
	dp[n-3]=abs(a[n-1]-a[n-3]);
	int i=n-4;
	while(i>=0){
		dp[i]=min(dp[i+1]+abs(a[i+1]-a[i]),dp[i+2]+abs(a[i+2]-a[i]));
		i--;
	}
	cout<<dp[0]<<endl;
}

Measured memory_bytes: 4412
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1000000007;
ll INF = 1ll << 60;

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

  int count = 0;
  int tmp = 1;
  for (int i = 0; i < n; i++) {
    tmp = v[tmp - 1];
    count++;
    if (tmp == 2) {
      cout << count << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>

int main()
{
	long W, H, x, y;
	
	std::cin >> W >> H >> x >> y;
	
	std::cout << (double(W*H)/2.0) << " " << ((W==x*2 && H==y*2) ? 1 : 0) << "\n";
}


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

int main() {
        string s;
        cin >> s;
        int f, b;
        int ff=0;

        f  =  (s[0] - '0') * 10;
        f +=   s[1] - '0';
        b  =  (s[2] - '0') * 10;
        b +=   s[3] - '0';

        if (f < 13 && f > 0) {
                ff = 1;
        }
        if (b < 13 && b > 0) {
                ff += 10;
        }

        switch (ff) {
                case 11:
                        cout << "AMBIGUOUS" << endl;
                        break;
                case 0:
                        cout << "NA" << endl;
                        break;
                case 1:
                        cout << "MMYY" << endl;
                        break;
                case 10:
                        cout << "YYMM" << endl;
                        break;
        }
        return 0;
}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
/*
*/
int dp[100005];
int a[100005];
int main () {
	int n, k, t;
	cin >> n >> k;
	for (int i=0; i<n; ++i)
		cin >> a[i];
	if (n==2) {
		cout << abs(a[1]-a[0]);
		return 0;
	}
	dp[n-2] = abs(a[n-1]-a[n-2]);
	//dp[n-3] = a[n-1]-a[n-3];
	for (int i=n-3; i>=0; --i) {
		t = INT_MAX;
		dp[i] = t;
		for (int j=1; j<=k; j++) {
			if (i+j==n)
				break;
			t = min(t, dp[i+j]+abs(a[i]-a[i+j]));
		}
		dp[i] = t;
	}
	cout << dp[0];
	return 0;
}


Measured memory_bytes: 1024
import java.util.*;

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

        while (true) {
            int n = scan.nextInt();
            if (n == 0) break;

            double sum = 0, sumX = 0, m;
            double[] s = new double[n];

            for (int i = 0; i < n; i++) {
                s[i] = scan.nextDouble();
                sum += s[i];
            }

            m = sum / n;

            for (int i = 0; i < n; i++) {
                sumX += Math.pow((s[i] - m), 2) / n;
            }
            System.out.println(Math.sqrt(sumX));
        }
    }
}

Measured memory_bytes: 40464
#include<bits/stdc++.h>
#define clr(x) memset(x, 0, sizeof(x))
#define sz(x) (int)x.size()

using namespace std;

typedef long long ll;
typedef pair<long , long> pll;

const ll mx = 105;
const ll maxn = 1000001;
const ll mod = 1000000007;

vector<vector<int>> adj;
vector<int> res;
vector<int> ord;

int main(){

   ios_base::sync_with_stdio(false);
   cin.tie(0);
   
   ll n,  i, j, k;

   string s;

   cin>>n;

   cin>>s;

   ll res = 0;

   ll pr[sz(s)], pg[sz(s)], pb[sz(s)];
   clr(pr);
   clr(pg);
   clr(pb);

   if(s[0] == 'R'){
       pr[0] = 1;
   }
      if(s[0] == 'G'){
       pg[0] = 1;
   }
      if(s[0] == 'B'){
       pb[0] = 1;
   }
   
  // cout<<pg[0]<<"\n";
    for(i = 1;i < sz(s);i++){
        if(s[i] == 'R'){
            pr[i] = pr[i-1]+1;
            pg[i] = pg[i-1];
            pb[i] = pb[i-1];
        }

        if(s[i] == 'G'){
            pr[i] = pr[i-1];
            pg[i] = pg[i-1]+1;
            pb[i] = pb[i-1];
        }
           if(s[i] == 'B'){
            pr[i] = pr[i-1];
            pg[i] = pg[i-1];
            pb[i] = pb[i-1]+1;
        }
    }


    map<char, ll> m;
    m.insert({'R', 0});
   m.insert({'G', 1});  
  m.insert({'B', 2});
    bool car[3];
    for(i = 0 ;i < sz(s);i++){
        for(j = i+1;j < n;j++){
            if(s[i] != s[j]){
                
                clr(car);
                int ind;
               
                car[m[s[i]]] = true;
                car[m[s[j]]] = true;
                for(k = 0;k < 3;k++){
                     if(!car[k]){
                       ind = k;
                       break;
                     }
                }
                ll count = 0;
               // cout<<ind<<"\n";
                if(ind == 0){
                  count = pr[n-1] - pr[j];
                }
                if(ind == 1){
                  count = pg[n-1] - pg[j];
                }
                if(ind == 2){
                  count = pb[n-1] - pb[j];
                }
                  
                if(j + j - i < n ){
                       if(ind == 0){
                        if(s[2*j-i] == 'R'){
                            count--;
                        }
                        }
                        if(ind == 1){
                            if(s[2*j-i] == 'G'){
                                count--;
                            }                        
                        }
                        if(ind == 2){
                         if(s[2*j-i] == 'B'){
                             count--;
                         }
                        }
                }
                res += count;  
            }
        }
    }

    cout<<res<<"\n";


}




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

using namespace std;

using i64 = int64_t;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int n, MOD;
  cin >> n >> MOD;
  
  vector<vector<int>> graph(n);
  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  vector<i64> up(n, 1), down(n, 1);
  function<void(int, int)> dfs_down = [&](int v, int p) {
    for (auto it = graph[v].begin(); it != graph[v].end(); ) {
      auto ch = *it;
      if (ch == p) {
        it = graph[v].erase(it);
        continue;
      }
      dfs_down(ch, v);
      down[v] *= (down[ch] + 1);
      down[v] %= MOD;
      ++it;
    }
  };
  dfs_down(0, -1);
  function<void(int, int, i64)> dfs_up = [&](int v, int p, i64 prod) {
    if (~p) {
      up[v] = (up[p] * prod + 1) % MOD;
    }
    int k = (int) graph[v].size();
    vector<i64> pref(k + 1), suff(k + 1);
    pref[0] = suff[0] = 1;
    for (int i = 0; i < k; ++i) {
      pref[i + 1] = pref[i] * (down[graph[v][i]] + 1) % MOD;
      suff[i + 1] = suff[i] * (down[graph[v][k - i - 1]] + 1) % MOD;
    }
    for (int i = 0; i < k; ++i) {
      dfs_up(graph[v][i], v, pref[i] * suff[k - i - 1] % MOD);
    }
  };
  dfs_up(0, -1, 1);
  for (int i = 0; i < n; ++i) {
    cout << (down[i] * up[i] % MOD) << '\n';
  }
  return 0;
}


Measured memory_bytes: 20608
n,m = map(int,input().split())
ab = [ list(map(int,input().split(" "))) for i in range(n)]
ab.sort()
ans = 0
for i in range(n):
    if m >= ab[i][1]:
        m -= ab[i][1]
        ans += ab[i][0] * ab[i][1]
    else:
        ans += ab[i][0] * m
        break
print(ans)

Measured memory_bytes: 27416
program prob4
    implicit none
    integer(8) :: N, M
    integer(8), allocatable, dimension(:) :: X, Y
    integer(8) :: i
    integer(8) :: ans
    read(*,*) N, M
    allocate(X(M))
    read(*,*) X
    if(M == 1) then
        write(*,*) maxval(X) - minval(X)
        stop
    end if
    allocate(Y(M-1))

    call msort(X)
    do i = 1, M-1
        Y(i) = X(i+1) - X(i)
    end do

    call msort(Y)
    ans = 0
    do i = 1, M-N
        ans = ans + Y(i)
    end do
    write(*,*) ans

    deallocate(X)
    deallocate(Y)
    stop
contains

  !
  ! swap two arguments
  !
subroutine swap(a, b)
    implicit none
    integer(8), intent(inout) :: a, b

    integer(8) :: c

    c = a
    a = b
    b = c

  end subroutine swap

  !
  ! merge sort
  !
  recursive subroutine msort(x)
    implicit none
    integer(8), intent(inout) :: x(:)

    integer(8) :: n, mid, i, j, k
    integer(8), allocatable :: tmp(:)
    
    n = size(x)
    
    if(n == 1) then
      return
    end if

    !
    ! 前半と後半に分けてソート
    ! 1~midとmid+1~nをそれぞれソート済みにする
    !
    mid = n / 2
    call msort(x(:mid))
    call msort(x(mid+1:))

    !
    ! tmpという配列にxを一時的に保管
    ! マージソートは外部ソート
    !
    allocate(tmp(n))
    tmp = x

    ! tmpの後半部分を左右反転
    do k = n, mid+1, -1
      tmp(k) = x(mid + n - k + 1)
    end do

    ! iは前半のリストのうちまだ見ていないものの最小値
    ! jは後半のリストのうちまだ見ていないものの最小値
    ! kは見た回数の合計
    i = 1
    j = n

    do k = 1, n
      !
      ! 一番左と一番右のうち小さい方をxに入れていく
      ! ここが等号つき不等号なので、安定ソートとなる
      !
      if(tmp(i) <= tmp(j)) then
        x(k) = tmp(i)
        i = i + 1
      else
        x(k) = tmp(j)
        j = j - 1
      end if
    end do
    
    deallocate(tmp)
    return
  end subroutine msort
end program prob4       

Measured memory_bytes: 5080
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <bitset>
#include<vector>
#include<utility>
#include<fstream>
#include<queue>
#include <iomanip>
#include<numeric>
#include<set>
using namespace std;
typedef long long ll;
#define rep(i,k) for(i=0;i<k;i++)
#define P pair<ll,ll>
ll mod = 1000000007;
P p[200005];

ll i, b, c, k,j, n, m, z = 0,mi=10;
ll a[100008] = {};
vector<ll> v;
priority_queue<ll> q;
int main() {
	cin >> n >> m;
	rep(i, n) {
		cin >> b;
		q.push(b);
	}
	rep(i, m) {
		c = q.top();
		c = c / 2;
		q.pop();
		q.push(c);

	}

	rep(i, n) {
		z += q.top();
		q.pop();
	}

	cout << z;
	
	return 0;
}

Measured memory_bytes: 1400