akhauriyash/Code-Regression huggingface dataset:
prime_list = [2]
N = int(input())
A = [0] * N

for i in range(3,10**3+1):
  flag = True
  for j in range(2,int(i**0.5)+1):
    if i % j == 0:
      flag = False
      break
  if flag:
    prime_list.append(i)

for i in range(1,N+1):
  # 素因数分解してAにぶち込む
  tmpN = i
  for j in prime_list:
    while tmpN % j == 0:
      A[j-1] += 1
      tmpN //= j
ans = 1
p = 10**9 + 7
for i in range(1,N):
  ans *= (A[i] + 1)
  ans %= p
print(ans)

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

size_t f(vector<pair<size_t, size_t>> &x, size_t n)
{
    priority_queue<size_t, vector<size_t>, greater<size_t>> candidates;
    priority_queue<pair<size_t, size_t>, vector<pair<size_t, size_t>>, greater<pair<size_t, size_t>>> q;
    for (pair<size_t, size_t> p : x)
    {
        q.push(p);
    }
    size_t current = 1;
    while (!q.empty() && size_t(current) <= x.size())
    {
        size_t index = q.top().first;
        if (index < current)
        {
            q.pop();
            continue;
        }
        if (index > current)
        {
            while (current < candidates.size())
            {
                candidates.pop();
            }
            current = index;
        }
        else
        {
            candidates.push(q.top().second);
            q.pop();
        }
    }
    while (current < candidates.size())
    {
        candidates.pop();
    }
    while (!q.empty())
    {
        if (q.top().first <= n)
        {
            candidates.push(q.top().second);
        }
        q.pop();
    }

    size_t ret = 0;
    while (!candidates.empty())
    {
        ret += candidates.top();
        candidates.pop();
    }
    return ret;
}

void solve()
{
    size_t N;
    cin >> N;
    vector<size_t> K(N);
    vector<size_t> R(N);
    vector<size_t> L(N);
    vector<pair<size_t, size_t>> right;
    vector<pair<size_t, size_t>> left;
    size_t ans = 0;
    for (size_t n = 0; n < N; n++)
    {
        cin >> K[n] >> R[n] >> L[n];
        if (R[n] > L[n])
        {
            right.push_back(make_pair(K[n], R[n] - L[n]));
        }
        else if (R[n] < L[n])
        {
            left.push_back(make_pair(N - K[n], L[n] - R[n]));
        }
        ans += min(R[n], L[n]);
    }

    ans += f(right, N);
    ans += f(left, N);
    cout << ans << endl;
}

int main()
{
    size_t T;
    cin >> T;
    for (size_t t = 0; t < T; t++)
    {
        solve();
    }
}


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

int main(){
    int H,W;
    cin >> H >> W;
    vector<string> vec(H + 2);
    vec[0] = ".........................................................................";
    vec[H + 1] = ".......................................................................";
    for(int i = 1; i <= H; i++){
        cin >> vec[i];
        vec[i] = "." + vec[i] + ".";
    }
    bool possible = true;
    rep(i,H){
        rep(j,W){
            if (vec[i + 1][j + 1] == '#'){
                if (vec[i][j + 1] != '#' && vec[i + 2][j + 1] != '#' && vec[i + 1][j] != '#' && vec[i + 1][j + 2] != '#'){
                    possible = false;
                }
            }
        }
    }
    if (possible) cout << "Yes" << endl;
    else cout << "No" << endl;
}



Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<map>
#define FOR(i,a,b) for(int i=(a); i<int(b); ++i)
#define RFOR(i,a,b) for(int i=(b)-1; i>=int(a); --i)
#define rep(i,n) FOR(i,0,n)
#define rep1(i,n) FOR(i,1,int(n)+1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)
#define al(d) d.begin(),d.end()
using namespace std;

template <typename T>
void putv(vector<T>& V){
	// cout << "The elements in the vector are: " << endl;
	for(auto x: V)
		cout << x << " ";
	cout << endl;
}
template <class T>
vector<T> getv(int n){
	vector<T> vec;
	rep(i,n){
		T input;
		cin >> input;
		vec.emplace_back(input);
	}
	return vec;
}

unsigned long long gcd(const unsigned long long a, const unsigned long long b);
unsigned long long lcm(const unsigned long long a, const unsigned long long b);
unsigned long long lcmv(vector<long long> vec);
int main(){
	int N;
	cin >> N;
	vector<long long> A = getv<long long>(N);
	int ans = 0;

	map<long long, int> odd_or_even;
	for(auto a:A){
		if(odd_or_even[a] == 0){
			ans += 1;
			odd_or_even[a] = -1;
		}else{
			ans += odd_or_even[a];
			odd_or_even[a] *= -1;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 7284
# -*- coding: utf-8 -*-
import math

if __name__ == '__main__':
    N = int(input())
    val = len(str(N))
    li = []
    for i in range(1, math.ceil(math.sqrt(N))+1):
        if N % i == 0:
            a = len(str(int(i)))
            b = len(str(int(N/i)))
            c = max(a, b)

            if c < val:
                val = c

    print(val)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

ll n, m;
ll a[30];

using ll = long long;
ll mod_pow(ll x, ll n, ll mod)
{
    ll res = 1;
    while (n > 0)
    {
        if (n & 1)
            (res *= x) %= mod;
        (x *= x) %= mod;
        n >>= 1;
    }
    return res;
}

int main()
{
    string s;
    cin >> n >> s;
    ll ans = 1;
    for (int i = 0; i < n; i++)
    {
        a[s[i] - 'a']++;
        ans += ans * mod_pow(a[s[i] - 'a'], mod - 2, mod);
        ans %= mod;
    }
    ans--;
    cout << ans % mod << endl;
}



Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;


int main()
{
	int N;
	string S;

	cin >> N >> S;

	map< char, int> r,l;

	int ans = 0;
	for (int ni = 1; ni < N - 1; ni++) {
		r.clear();
		l.clear();
		for (int ti = 0; ti < N; ti++) {
			if (ti < ni) {
				l[S[ti]] = 1;
			}
			else {
				r[S[ti]] = 1;
			}
		}

		int flag = 1;
		int cnt = 0;
		for (auto c : l) {
			if (r.count(c.first) > 0) {
				cnt++;
			}
		}
		ans = max(ans, cnt);
	}

	printf("%d", ans);

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <array>
#include <vector>

using namespace std;

int main() {
  while( true ) {
	int n;
	cin >> n;
	if ( n == 0 ) break;
	int mp = -1, md = -1;
	for ( int i = 0; i < n; i++ ) {
	  int p, d1, d2;
	  cin >> p >> d1 >> d2;
	  if ( d1 + d2 > md ) {
		mp = p;
		md = d1 + d2;		
	  }
	}
	cout << mp << " " << md << endl;
  }
}

Measured memory_bytes: 1160
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main(A, B, C):
    counts = np.zeros(1 << 18, np.int32)
    popcount = np.zeros(1 << B, np.int32)
    for i in range(B):
        popcount[1 << i:1 << i + 1] = popcount[:1 << i] + 1

    answer = 0
    for i in range(1 << B):
        k = popcount[i]
        t = 0
        for x in A & i:
            n = counts[x]
            counts[x] += 1
            t -= C[n]
            t += C[n + 1]
        for x in A & i:
            counts[x] = 0
        if k & 1:
            t = -t
        answer += t
    return answer
  
if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('main', '(i4[::1],i4,i8[::1])')(main)
    cc.compile()
    exit()
from my_module import main

N, K, S, T = map(int, readline().split())
A = np.array(readline().split(), np.int32)

def convert_problem(S, T, A):
    ng = np.zeros(len(A), np.bool)
    B = np.zeros_like(A)
    n = 0
    for i in range(18):
        s, t = (S >> i) & 1, (T >> i) & 1
        if (s, t) == (0, 0):
            ng |= ((A >> i) & 1) == 1
        elif (s, t) == (1, 1):
            ng |= ((A >> i) & 1) == 0
        elif (s, t) == (1, 0):
            print(0)
            exit()
        else:
            B += ((A >> i) & 1) << n
            n += 1
    return B[~ng], n

A, B = convert_problem(S, T, A)

C = np.zeros((100, 100), np.int64)
C[0, 0] = 1
for n in range(1, 100):
    C[n, :-1] += C[n - 1, :-1]
    C[n, 1:] += C[n - 1, :-1]
C = C[:, 1:K + 1].sum(axis=1)

print(main(A, B, C))


Measured memory_bytes: 30448
N = int(input())
R = [int(input()) for _ in range(N)]

max_res = -1e9
min_R = R[0]

for j in range(1, N):
    R_j = R[j]
    max_res = max(max_res, (R_j - min_R))
    min_R = min(min_R, R_j)

print(max_res)


Measured memory_bytes: 13628
// O O O O O O O O O O O O O O O OO O OO O OO O O O TTCH O TTTCH O TTTCH O O O O
#pragma GCC optimize("Ofast")
// #pragma GCC optimize("no-stack-protector")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <random>
#include <iomanip>
#include <bitset>
#include <cassert>

using namespace std;

// #define int long long
#define double long double
#define less less228
#define left left228
#define right right228

template<typename T> void uin(T &a, T b) {
    if (b < a) a = b;
}
template<typename T> void uax(T &a, T b) {
    if (b > a) a = b;
}


random_device rnd;

template<typename T> void shuffle(vector< T > &v) {
    for (int i = 1; i < (int)v.size(); ++i) {
        swap(v[rnd() % i], v[i]);
    }
    for (int i = (int)v.size() - 1; i; --i) {
        swap(v[rnd() % i], v[i]);
    } 
}

const int N = 100 * 1000 + 228;

int a[N];

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, l;
    cin >> n >> l;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    for (int i = 1; i < n; ++i) {
        if (a[i] + a[i + 1] >= l) {
            cout << "Possible\n";
            for (int j = n - 1; j > i; --j) {
                cout << j << "\n";
            }
            for (int j = 1; j <= i; ++j) {
                cout << j << "\n";
            }
            return 0;
        }
    }
    cout << "Impossible\n";
    return 0;
}
// RU_023

/*
6 5 2
5 1 3 6 2 4
1 3
1 6
3 5
4 5
2 2

3 3 5
1 12 6
1 3
2 3
1 2

shironury

boootgslkfjdaojfdopsjfopjso
pgjq]pogjopsjg\qrwjopg
j
pogjqwrjgp]oqwjjqw]pjljfojpjowjow4jgopja    ohbip]aeo'rogpoaj0
[bkrw
pР С‘Р С—РЎС“РЎРѓРЎвЂљРЎРЉР В±РЎС“Р Т‘Р ВµРЎвЂљРЎР‚РЎС“Р С”Р В°РЎвЂљР Р†Р С•РЎРЏРЎвЂљР Р†Р ВµРЎР‚Р Т‘Р В°ojgqwjp\\j\;sync_with_stdiojp
ojeofmpworuc[owejgoprwig
[sdkz
pgj
p[gjes
p0ghjqsp[

jg
prsjgopjg]prwjgoprejgopjrepogjrepog]jgoprejgrgjporeqjgoperjgoprejgopeqrjgopeqrjgoprqwjgpoqjrwsopt4ng\ojsbjsoprnbfqsn\bvhqerpogjorwo
pwewh\rwh \wjiowe orw jop jgr\p jpj o jopj gr\pj p gjop j\pj\pe jp'oj [
 k
 p[eq   fj\pjfdwj\ejopjojopjopjf;'djpfsj, ipojs\p gpsdigsj gorkgjgjrogjdojgiao'fsdvopdshpdfidopcnweojccodj [cjd;ofjd[jdspmcojc"ajno[:Afvoq[w0shbprs`nm/jP{Vadmn;'fnc[Ajojsfpfjcffor 9int i= ; 1 < nfor (int i =1; for (int i =1 ; i <= n: ++i) frfor (int j = 1; j <= ml; ++'}]]]]]]]]]
5
1 5
1 2
2 3
2 
4
*/

Measured memory_bytes: 1280
fun main(args :Array<String>) {
    val n = readInteger()
    val aArray = readIntegerList().toIntArray()

    var m = 0
    val boxes = IntArray(n)
    for (i in (n - 1) downTo 0) {
        var count = 0
        for (j in i until n step (i + 1)) {
            count += boxes[j]
        }

        if (count % 2 != aArray[i]) {
            m++
            boxes[i] = 1
        }
    }

    println(m)
    boxes.mapIndexed { index, it ->
        if (it == 1) index + 1 else 0
    }.filter { it > 0 }
    .joinToString(" ")
    .let { println(it) }
}

fun readInteger() = readLine()!!.toInt()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)


Measured memory_bytes: 79016
import os, sys, re, math

(N, M, X, Y) = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]

x.append(X)
y.append(Y)
x.sort()
y.sort()

print ('No War' if x[-1] < y[0] else 'War') 


Measured memory_bytes: 3316
#include <iostream>

using namespace std;

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

    cin >> a >> b >> c >> d;

    while(true){
        c = c - b;
        if(c <= 0){
            cout << "Yes";
            return 0;
        }
        a = a - d;
        if(a <= 0){
            cout << "No";
            return 0;
        }
    }
}

Measured memory_bytes: 3632
import sys
input = sys.stdin.readline
from heapq import heappush,heappop
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

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

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

        if x == y:
            return

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

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

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
def solve():
  n,m = (int(i) for i in input().split())
  p = list(int(i) for i in input().split())

  uf = UnionFind(n)
  for i in range(m):
    x,y = (int(i) for i in input().split())
    uf.union(x-1,y-1)
  ans = 0
  for i in range(n):
    if uf.same(i,p[i]-1):
      ans += 1
  print(ans)
    
solve()

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

bool solve()
{
    int H, W; cin >> H >> W;

    vector<int> counts(H+W-1);

    for (int r = 0; r < H; r++)
    {
        string row; cin >> row;
        for (int c = 0; c < W; c++)
            if (row[c] == '#')
                counts[r+c]++;
    }

    for (const int x : counts)
        if (x != 1)
            return false;
    return true;
}

int main()
{
    cout << (solve() ? "Possible" : "Impossible") << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class41
    {
        static void Main()
        {
            var abc = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Array.Sort(abc);
            string max = abc[2].ToString() + abc[1].ToString();
            string min = abc[0].ToString();

            int ans = int.Parse(max) + int.Parse(min);
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13396
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;





int main(){
    ll n,k;
    cin>>n>>k;
    ll w=1;
    while(0<(--n)){
        w+=(w+k-2)/(k-1);
    }
    cout<<w-1<<endl;
    
    
    return 0;
}



Measured memory_bytes: 3116
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int n=0,m=0;
        if(scan.hasNext())
            n=scan.nextInt();
        if(scan.hasNext())
            m=scan.nextInt();
        if(n<m){
            for(int i=0;i<m;i++){
                System.out.print(n);
            }
        }else{
            for(int i=0;i<n;i++){
                System.out.print(m);
            }
        }
    }
}


Measured memory_bytes: 21844
import std.stdio, std.array, std.conv, std.string;

struct Card {
  string suit;
  int number;

  size_t toHash() {
    int a = 100;
    string[] suits = ["S", "H", "C", "D"];
    foreach (int i, s; suits) {
      if (s == suit) a = i;
    }

    return 13 * a + number;
  }
}

void main() {
  int n = to!int(chomp(readln()));
  bool[Card] set;

  for (int i = 0; i < n; ++i) {
    string[] s = split(readln());
    set[Card(s[0], to!int(s[1]))] = true;
  }

  string[] suits = ["S", "H", "C", "D"];
  foreach (i; suits) {
    for (int j = 1; j <= 13; ++j) {
      if (Card(i, j) in set) continue;
      writef("%s %d\n", i, j);
    }
  }
}

Measured memory_bytes: 2532
/*
    なるべく諦めない！
    なせば大抵なんとかなる！
*/

#define VERNIY st();int ver=0,niy=0,hbk=0

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <limits.h>
#include <float.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iterator>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <functional>
#include <set>
#define LLU unsigned long long int
#define LL long long int
using namespace std;
#define Lfmax DBL_MAX
#define LLUmax ULLONG_MAX
#define LLmax LLONG_MAX
#define dmax INT_MAX
#define vd vector<int>
#define vpd vector<pair<int,int>>
#define vLL vector<long long int>
#define vpLL vector<pair<long long int,long long int>>
#define vLLU vector<unsigned long long int>
#define vpLLU vector<pair<unsigned long long int,unsigned long long int>>
#define pd pair<int,int>
#define pLL pair<long long int,long long int>
#define pLLU pair<unsigned long long int,unsigned long long int>
#define qd queue<int>
#define qpd queue<pair<int,int>>
#define maxpqd priority_queue<int>
#define minpqd priority_queue<int, vector<int>, greater<int>>
#define fr front
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define debugarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i]);printf("\n")
#define newline printf("\n")
#define forin(a,b,c) for(int a=b ; a<c ; ++a)
#define forineq(a,b,c) for(int a=b ; a<=c ; ++a)
#define forde(a,b,c) for(int a=b ; a>=c ; --a)
#define UPC(oo) (oo>='A' && oo<='Z')
#define LWC(oo) (oo>='a' && oo<='z')
#define DGT(oo) (oo>='0' && oo<='9')
#define UPCVOC(oo) (oo=='A' || oo=='E' || oo=='I' || oo=='U' || oo=='O')
#define LWCVOC(oo) (oo=='a' || oo=='e' || oo=='i' || oo=='u' || oo=='o')
#define filein freopen("in.txt","r",stdin);
#define fileout freopen("out.txt","w",stdout);

inline void scd(int &a){scanf("%d",&a);}
inline void scdd(int &a,int &b){scanf("%d %d",&a,&b);}
inline void sctd(int &a,int &b,int &c){scanf("%d %d %d",&a,&b,&c);}
inline void sctlld(LL &a,LL &b,LL &c){scanf("%I64d %I64d %I64d",&a,&b,&c);}
inline void scdlld(LL &a,LL &b){scanf("%I64d %I64d",&a,&b);}
inline void sclld(LL &a){scanf("%I64d",&a);}
inline void scllu(LLU &a){scanf("%I64u",&a);}
inline void scdllu(LLU &a,LLU &b){scanf("%I64u %I64u",&a,&b);}
inline void sctllu(LLU &a,LLU &b,LLU &c){scanf("%I64u %I64u %I64u",&a,&b,&c);}

template<class Ver>
inline void prd(Ver a){cout<<a<<"\n";};
template<class Ver>
inline void prdd(Ver a,Ver b){cout<<a<<" "<<b<<"\n";};
template<class Ver>
inline void prtd(Ver a, Ver b, Ver c){cout<<a<<" "<<b<<" "<<c<<"\n";};

inline void debug(){printf("asd\n");}
template<class Ver>
inline void debugd(Ver a){cout<<"--- "<<a<<endl;};
template<class Ver>
inline void debugdd(Ver a,Ver b){cout<<"--- "<<a<<" "<<b<<endl;};
template<class Ver>
inline void debugtd(Ver a,Ver b,Ver c){cout<<"--- "<<a<<" "<<b<<" "<<c<<endl;};

#define grav 9.8
#define pi 3.14159265

void st()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
}

int main()
{
	VERNIY;
	int a,b;
	scdd(a,b);
	int z=ceil(((float)a+(float)b)/(float)2);
	prd(z);

	return 0;
}

/*
    なるべく諦めない！
    なせば大抵なんとかなる！
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define fast ios::sync_with_stdio(false); cin.tie(NULL);
#define loop(n) for(int i=0; i<n; i++)
#define rep(i,start,n) for(int i=start; i<n; i++)

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

	int a[n+1];

	rep(i,1,n+1)cin>>a[i];

	int curr = 1;
	int next = a[curr];
	a[curr]=-1;
	int cnt = 1;

	while( curr!=next && next!=2){
		curr = next;
		if(a[curr]==-1){
			cout<<-1<<endl;
			return;
		}
		next = a[curr];
		a[curr]=-1;
		cnt++;
		// cout<<curr<<" "<<next<<endl;
	}
	if( next==curr ){
		if(curr==2)cout<<cnt<<endl;
		else cout<<-1;
	}
	else cout<<cnt;
	
}
	
signed main(){
    fast;    
    // int t;cin>>t;while(t--)
    solve();    
    return 0;
}


Measured memory_bytes: 4400
h = int(input())
if(h == 1):
  print(1)
  exit()
cnt = 1
point = 0
list = [0 for i in range(100)]
while (h>point+1):
  list[cnt] = ((list[cnt-1] * 2) +1)
  point += 2**cnt
  cnt += 1

print(list[cnt-1]*2+1)

Measured memory_bytes: 3064
// Author            -  Ranadev Varma
// Codeforces Handle -  Ranadev_CaptainR
// Codechef Handle   -  ranadev
 
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("O3")
//#pragma GCC optimize ("O2")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize ("unroll-loops")
 
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <iterator>
#include <iomanip>
#include <set>

using namespace std ;

#define MOD 1000000007LL
#define LOD 1000000006
#define pi 3.14159

#define lol1 ios::sync_with_stdio(false)
#define lol2 cin.tie(NULL);cout.tie(NULL)

#define FOR(i,a,b)  for(int i = a ; i < b ; i++)
#define RFOR(i,a,b) for(int i = a ; i > b ; i--)

#define pb push_back
#define mp make_pair
#define fi first
#define se second

int main()
{
    lol1;
    lol2;
    int n,k;
    cin >> n >> k;
    if(n%k==0)
    {
        cout << "0" << "\n";
    }
    else
    {
        cout << "1" << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < n; i++) {
            set.add(sc.nextInt());
        }
        System.out.println(set.size() == n ? "YES" : "NO");
        sc.close();

    }

}


Measured memory_bytes: 100076
#include <bits/stdc++.h>
using namespace std;
const int kN = 2e5 + 10;

char c[kN];
int main() {
	scanf("%s", c);
	int n = strlen(c);
	int num = 0;
	for(int i = 0; i < n; i++) num += c[i] - '0';
	puts(num % 9 == 0 ? "Yes" : "No");
	return 0;
}



Measured memory_bytes: 3824
/*
    なせば大抵なんとかなる！
*/

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <limits.h>
#include <float.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iterator>
#include <vector>
#include <map>
#include <utility>
#define LLU unsigned long long int
#define LL long long int
#define LD long double
using namespace std;
#define Lfmax DBL_MAX
#define LLUmax ULLONG_MAX
#define LLmax LLONG_MAX
#define dmax INT_MAX
#define vd vector<int>
#define vLL vector<long long int>
#define vLLU vector<unsigned long long int> 
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define debug printf("asd\n")
#define debugd(a) printf("--%d\n",a)
#define debugdd(a,b) printf("--%d %d\n",a,b)
#define debugarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i]);printf("\n")
#define newline printf("\n")
#define forin(a,b,c) for(int a=b ; a<c ; a++)
#define forde(a,b,c) for(int a=b ; a>=c ; a--)


inline void scd(int &a){scanf("%d",&a);}
inline void scdd(int &a,int &b){scanf("%d %d",&a,&b);}
inline void sctd(int &a,int &b,int &c){scanf("%d %d %d",&a,&b,&c);}
inline void scdlld(LL &a,LL &b){scanf("%I64d %I64d",&a,&b);}
inline void sclld(LL &a){scanf("%I64d",&a);}

#define scarrd(a,b) for(int index=0 ; index<b ; index++)scanf("%d",&a[index])
#define prdlld(a,b) printf("%I64d %I64d",a,b)
#define prdd(a,b) printf("%d %d",a,b)
#define prd(a) printf("%d",a)
#define prarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i])
#define iniarr(a,b) for(int i=0 ; i<b ;i++)a[i]=0
#define arr(a,b) int *a=(int *)malloc(b*sizeof(int))
#define llarr(a,b) long long int *a=(long long int *)malloc(b*sizeof(long long int))
#define st(a,b) char *a=(char *)malloc(b*sizeof(char))
#define grav 9.8
#define pi 3.14159265

int main()
{
	int a,b,c;
	sctd(a,b,c);
	if((b-a)==(c-b))
	printf("YES\n");
	else
	printf("NO\n");
	return 0;
}

Measured memory_bytes: 256
import sys
a=sys.stdin.readline()
res = [int(x) for x in a.split() if x.isdigit()] 
N,A,B= [res[i] for i in (0,1,2)]
if 1<=N<=20 and 1<=A<=50 and 1<=B<=50:
    x=N*A
    if x>B:
        print(B)
    else:
        print(x)

Measured memory_bytes: 3064
//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
const int mod = 1000000007;
#define EPS (1e-10)

#define pb push_back
#define fir first
#define scn second
#define ednl endl

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")


P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}



int main(){
  int n;cin>>n;
  string s;cin>>s;
  for(int i = 0; s.size() > i; i++){
    cout << (char)(((s[i]-'A'+n)%26)+'A');
  }
  cout << endl;
}


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

vector<int64_t> L(100);

void sum(int x) {
  L.at(x) = L.at(x-1) + L.at(x-2);
  return;
}

int main() {
  L.at(0) = 2;
  L.at(1) = 1;
  int N;
  cin >> N;
  for (int i = 2; i <= N; i++) {
    sum(i);
  }
  cout << L.at(N) << endl;
}


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


int count(int i,vector<vector<int>> &a,int *s)
{
    int t=0;
    int j;
    for(j=0;j<a[i].size();j++)
    {
        if(s[a[i][j]]==-1)
        s[a[i][j]]= 1+count(a[i][j],a,s);

        if(t<s[a[i][j]])
        t=s[a[i][j]];
    }
    return t;
}
int main()
{
  int n,m,x,y,i;
  cin>>n>>m;
  vector<vector<int>> a(n+1);
  for(i=0;i<m;i++)
    {
        cin>>x>>y;
        a[x].push_back(y);
    }
  int t=0;
  int s[n+1];
  memset(s,-1,sizeof(s));

  for(i=1;i<=n;i++)
  {
      if(s[i]==-1)
      {
          s[i]=1+count(i,a,s);
      }
      if(t<s[i])
      t=s[i];
  }
  cout<<t-1;
    
  return 0;
}


Measured memory_bytes: 9472
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
using namespace std;

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

    int h,w;
    string s;
    cin>>h>>w;
    reps(i,h){
	cin>>s;
	cout<<s<<'\n'<<s<<'\n';
    }
    return 0;
}


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

int main()
{
    int N;
    cin >> N;
    map<string, int> m;

    for (int i = 0; i < N; i++)
    {
        string s;
        cin >> s;
        m[s] = 1;
    }

    if (m.size() == 3)
    {
        cout << "Three" << endl;
    }
    else if (m.size() == 4)
    {
        cout << "Four" << endl;
    }
}

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

int main()
{
  int n;
  cin >> n;
  bool is_enable = false;
  vector<int> vint(n);
  for (int i = 0; i < n; i++)
  {
    cin >> vint.at(i);
    if(vint.at(i) == 2) is_enable = true;
  }
  if(!is_enable){
    cout << -1 << endl;
    return 0;
  }
  int cnt = 0;
  int index = 0;
  while (true)
  {
    cnt++;
    int num = vint.at(index);
    if(num == 2){
      cout << cnt << endl;
      break;
    }
    if(num == -1){
      cout << -1 << endl;
      break;
    }
    vint.at(index) = -1;
    index = num - 1;
  }
  return 0;
}


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

int main(){
    string S;
    cin>>S;
    //cout<<int('1')<<endl;
    
    int y=(S[0]-48)*1000+(S[1]-48)*100+(S[2]-48)*10+(S[3]-48);
    int m=(S[5]-48)*10+(S[6]-48);
    int d=(S[8]-48)*10+(S[9]-48);
    
    
    if(y<=2018) cout<<"Heisei1"<<endl;
    else if(y==2019){
        if(m<=4) cout<<"Heisei"<<endl;
        else cout<<"TBD"<<endl;
    }else cout<<"TBD"<<endl;
    
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

using ll = long long int;

int main(void) {
  int a, b;
  cin>>a>>b;
  int aa = max(a, b);
  int bb = min(a, b);
  std::cout << max(aa+aa-1, max(bb+bb-1, aa+bb)) << std::endl;
  return 0;
}



Measured memory_bytes: 256
/*
オーダー
10**6	余裕を持って間に合う	
10**7	おそらく間に合う	余裕を持って間に合う
10**8	非常にシンプルな処理でない限り厳しい	おそらく間に合う
10**9		非常にシンプルな処理でない限り厳しい
logn	:OK
n		:10^7
nlogn	:10^6
n**2	:10^4
n**3	:300
2**n	:20
n!		:10



// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/

#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
ll gcd(ll a, ll b) {
	if(b == 0) return a;
	return gcd(b, a % b);
}

const ll MAX_N = 1e5;
string S;
// ll N;
// ll h[MAX_N];
ll dp[MAX_N+1][13]; // メモ化テーブル
ll num_d = (ll)(pow(10,9)+7);


ll get_tmp(ll keta){
	ll tmp = 1;
	REP(i, keta){
		tmp = (tmp*10)%num_d;
	}
	return tmp;
}


// i番目以降の品物から重さの総和がj以下になるように選ぶ
void rec(ll i){
	if (S[i]=='?'){
		// printf("tmp: %lld * x\n", tmp);
		if (i==0){
			REP(k,10){
				dp[i][k%13] += 1;
			}
		}
		else{
			REP(k,10){
				REP(j,13)dp[i][(j*10+k)%13] += dp[i-1][j];
			}
		}
	}
	else{
		ll tmp = stoi(S.substr(i,1));
		// printf("tmp: %lld\n", tmp);
		if (i==0){
			dp[i][tmp%13] = 1;
		}
		else{
			REP(j,13)dp[i][(j*10+tmp)%13] += dp[i-1][j];
		}
		
	}
	REP(j,13) dp[i][j] = dp[i][j]%num_d;
}

int main() {
	// 入力
	cin >> S;
 
	// 解法
	// REP(i,S.size()) printf("%c\n", S[i]);
	memset(dp, 0, sizeof(dp));
	REP(i,S.size()){
		rec(i);
		// printf("%lld\n", dp[i][5]);
	}
	cout<<dp[S.size()-1][5]<<endl;
}


Measured memory_bytes: 10624
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int P=1e9+7;
inline void upd(R int &x,R int y){(x+=y)>=P?x-=P:0;}
inline int inc(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
	R int res=1;
	for(;y;y>>=1,x=mul(x,x))(y&1)?res=mul(res,x):0;
	return res;
}
const int N=3e5+5;
char s[N];int f[N][8],n;
int mp[2][8]={{3,6,2,4,3,3,7,6},{1,2,2,5,3,1,1,6}};
int main(){
//	freopen("testdata.in","r",stdin);
	scanf("%s",s+1),n=strlen(s+1);
	f[0][0]=1;
	fp(i,1,n)fp(j,0,1)if(s[i]!='0'+(j^1))
		fp(k,0,7)upd(f[i][mp[j][k]],f[i-1][k]);
	printf("%d\n",inc(f[n][1],f[n][2]));
	return 0;
}

Measured memory_bytes: 9856
import java.util.Scanner;

public class Main{
	static Scanner sc = new Scanner(System.in);
	static long mod = 998244353;
	public static void main(String[] args) {
		int n = sc.nextInt(), m = sc.nextInt(), k = sc.nextInt();
		initComb();
		long ans = 0;
		for(int i=0;i<=k;i++) {
			ans += comb(n-1, i) * pow(m-1, n-i-1) % mod;
			ans %= mod;
		}
		ans = ans * m % mod;//先頭の塗り方
		System.out.println(ans);
	}
	static long fact[] = new long[200200];
	static long revFact[] = new long[200200];
	
	static void initComb() {
		fact[0] = 1;
		for(int i=1;i<200200;i++) {
			fact[i] = fact[i-1] * i % mod;
		}
		revFact[200199] = div(1, fact[200199]); 
		for(int i=200199;i>=1;i--) {
			revFact[i-1] = revFact[i] * i % mod;
		}
	}
	
	static long div(long x, long y) {
		return x * pow(y, mod - 2) % mod;
	}
	
	static long pow(long a, long x) {
		if(x == 0)return 1;
		if(x % 2 == 1) return a * pow(a, x-1) % mod;
		long root = pow(a, x / 2);
		return root * root % mod;
	}
	
	static long comb(int x, int y) {
		if( x < y )return 0;
		long up = fact[x];
		long down = fact[x - y] * fact[y] % mod;
		return div(up, down);
	}
}

Measured memory_bytes: 31020
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
long long geko[100000] = {};
long long dodo[100000] = {};
long long solve(long long now,long long hoge) {
	if (dodo[now]) return geko[now];
	dodo[now] = 1;
	if (hoge % now == 0) {
		return geko[now] = 0;
	}
	return geko[now] = solve(now + 1, hoge) + 1;
}
int main(){
#define int long long
	int n;
	cin >> n;
	vector<int> input;
	REP(i, n) {
		int a;
		cin >> a;
		input.push_back(a);
	}
	sort(input.begin(), input.end());
	int ans = 0;
	REP(i, n) {
		ans += solve(input[i], input[n - 1]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4096
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val k = readLine()!!.toInt()
    val x = readLine()!!.split(" ").map{ it.toInt() }
    var sum = 0
    for(a in x) {
        sum += 2*Math.min(a, k-a)
    }
    println(sum)
}


Measured memory_bytes: 37924
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <cstdint>
#include <tuple>
#include <numeric>
#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FILL(a, x) memset(a, x, sizeof(a))

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)

int main() {
	int n, h, w;
	cin >> n >> h >> w;
	cout << (n - h + 1)*(n - w + 1) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
//#include <bits/stdc++.h>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()

typedef long long ll;

//const int MOD = 1000000007;
//const int INF = 1<<30;
using namespace std;

string yn(bool x){
    return x ? "Yes" : "No";
}

int h,w;
char s[50][50];
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};


bool check(int x,int y){
    bool ans = 0;
    rep(i,4){
        if(x+dy[i]>=0 and x+dy[i] < h and y+dx[i] >= 0 and y+dx[i] < w){
            if(s[x+dy[i]][y+dx[i]] == '#') ans = 1;
        }
    }
    
    return ans;
}

int main(){
    cin >> h >> w;
    
    rep(i,h) rep(j,w) cin >> s[i][j];
    
    int ans = 1;
    rep(i,h) {
        rep(j,w){
            if(s[i][j] == '#') ans = check(i,j);
            
            if(!ans){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    
    cout << "Yes" << endl;
    
}
    
    
    


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<functional>
//#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ll MOD = 998244353;
const ld pi = 3.141592653589793238;

ll a[123456];
signed main() {
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	ll n; cin >> n;
	vector<ll> xs;
	rep(i, n) {
		cin >> a[i]; xs.push_back(a[i]);
	}
	sort(all(xs));
	xs.erase(unique(all(xs)), xs.end());
	ll x = xs.size();
	if (x >= 3) { cout << "No\n"; return 0; }
	if (x == 1) {
		if (xs[0] == n - 1) { cout << "Yes\n"; return 0; }
		if (xs[0] <= n / 2) { cout << "Yes\n"; return 0; }
		cout << "No\n";
	}
	if (x == 2) {
		if (xs[1] - xs[0] >= 2) { cout << "No\n"; return 0; }
		ll v = 0, w = 0;
		rep(i, n) {
			if (a[i] == xs[0]) { v++; }
			else { w++; }
		}
		if (xs[1] > v && (xs[1] - v) * 2 <= w) { cout << "Yes\n"; }
		else { cout << "No\n"; }
	}
	cin >> n;
	return 0;
}

Measured memory_bytes: 5028
import java.util.*;

class Main{

    int n, w, d;

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(true){
            n = sc.nextInt();
            w = sc.nextInt();
            d = sc.nextInt();
            if(n==0 && w==0 && d==0) break;

            //x, y, w, h
            LinkedList<int[]> q = new LinkedList<int[]>();
            q.add(new int[]{0,0,w,d});

            for(int i=0; i<n; i++){
                int p = sc.nextInt()-1;
                int s = sc.nextInt();

                int[] qq = q.get(p);
                q.remove(p);
                int x = qq[0], y = qq[1], W = qq[2], H = qq[3];
                s = s%((W+1)*2+(H-1)*2);

                int nx = x, ny = y;
                
                while(nx+1<=x+W && s-1>=0){nx++; s--;}
                while(ny+1<=y+H && s-1>=0){ny++; s--;}
                while(nx-1>=x && s-1>=0){nx--; s--;}
                while(ny-1>=y && s-1>=0){ny--; s--;}

                if(nx==x || nx==x+W){
                    int ny1 = ny-y, ny2 = H+y-ny;
                    int[] n1 = {x, y, W, ny1};
                    int[] n2 = {x, ny, W, ny2};
                    if(ny1<ny2){
                        q.add(n1); q.add(n2);
                    }else{
                        q.add(n2); q.add(n1);
                    }
                }else{
                    int nx1 = nx-x, nx2 = W+x-nx;
                    int[] n1 = {x, y, nx1, H};
                    int[] n2 = {nx, y, nx2, H};
                    if(nx1<nx2){
                        q.add(n1); q.add(n2);
                    }else{
                        q.add(n2); q.add(n1);
                    }
                }
            }

            PriorityQueue<Integer> ans = new PriorityQueue<Integer>(10, new Comparator<Integer>(){
                    public int compare(Integer a, Integer b){
                        return (int)(a-b);
                    }
                });

            while(q.size()>0){
                int[] qq = q.poll();
                ans.add(new Integer(qq[2] * qq[3]));
            }

            while(ans.size()>1) System.out.print(ans.poll()+" ");
            if(ans.size()==1) System.out.println(ans.poll());
            else System.out.println();
        }
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

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

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef unordered_map<int,int> umii;
typedef unordered_map<ll,ll> umll;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define bs(v,val) binary_search(v.begin(),v.end(),val)
#define mod 1000000007
#define ff first
#define ss second
#define fi(n) for(int i=0;i<n;i++)
#define fj(n) for(int j=0;j<n;j++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define m_p make_pair
#define endl '\n'

struct custom_hash {    // anti-hack for unordered_map. To declare: unordered_map<long long, int, custom_hash> safe_map;
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll power(ll x, ll y, ll p)
{  
    ll res = 1;
    x = x % p;  
    if (x == 0) return 0;
    while (y > 0){  
        if (y & 1)  res = (res*x) % p;  
        y = y>>1;
        x = (x*x) % p;  
    }  
    return res;  
}
ll modInverse(ll n, ll p)
{
    return power(n, p-2, p); 
}
// ********** CODE STARTS HERE ****************//

void solve()
{
	int n;
	cin >> n;
	vi a(n);
	fi(n)cin>>a[i];
	ll sum = 0;
	fi(n)sum+=a[i];
	ll sum_square = 0;
	// const int mod = 1000000007;
	fi(n){sum_square += 1ll*a[i]*a[i];sum_square%=mod;}
	sum%=mod;
	sum = sum*sum;
	ll res = ((sum-sum_square+mod)%mod+mod)%mod;
	cout<<(modInverse(2,mod)*res)%mod;
   
}


int main()
{
    int t;
    // cin>>t;
    // while(t--)
     solve();

	return 0;
}

Measured memory_bytes: 4044
s=input()
l1,l2=['R','U','D'],['L','U','D']
flg=0
for i in range(len(s)):
  if i%2==0 and s[i] not in l1:
    flg=1
    break
  elif i%2!=0 and s[i] not in l2:
    flg=1
    break
if flg==1:
  print("No")
else:
  print("Yes")

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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

    ll k, x;
    cin >> k >> x;

    for(ll i=max(x-k+1, -1000000LL); i<=min(1000000LL, x+k-1); ++i) {
        cout << i << (i==min(1000000LL, x+k-1)?'\n':' ');
    }

    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main{
    public static double find(int n)
    {int m=n;
    double val=(n*(n+1))/2;
    val=val/m;
    return val;}

     public static void main(String []args){
    Scanner s=new Scanner(System.in);
      int n=s.nextInt();
      int k=s.nextInt();
      int a[]=new int[n];
      for(int i=0;i<n;i++)
      a[i]=s.nextInt();
      double max=0.0;
      double sum=0;
      for(int i=0;i<k;i++)
      {sum+=find(a[i]);}
      max=sum;
      for(int i=k,j=0;i<n;i++,j++)
      {sum-=find(a[j]);
      sum+=find(a[i]);
      max=Math.max(max,sum);}
      System.out.println(max);
     }
}

Measured memory_bytes: 80944