akhauriyash/Code-Regression huggingface dataset:
package main

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

func main() {
	N := nextInt()
	A := nextInts(N)
	gcdList := make([]int, N)
	gcdList[0] = A[0]
	for i := 1; i < N; i++ {
		gcdList[i] = gcd(gcdList[i-1], A[i])
	}
	r := make([]int, N)
	r[N-1] = A[N-1]
	for i := N - 2; i >= 0; i-- {
		// log.Println(i, r[i+1], A[i], gcd(r[i+1], A[i]))
		r[i] = gcd(r[i+1], A[i])
	}
	// log.Println(gcdList)
	// log.Println(r)
	// ans := gcdList[0]
	ans := max(gcdList[N-2], r[1])
	for k := 0; k < N-2; k++ {
		ans = max(ans, gcd(gcdList[k], r[k+2]))
	}
	fmt.Println(ans)
}

var dy = []int{1, 0, -1, 0, 0}
var dx = []int{0, 1, 0, -1, 0}
var inf = int(1e9)

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type pair struct {
	a, b int
}

type pairs []pair

func (p pairs) Len() int {
	return len(p)
}
func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}

var nextReader func() []byte

func init() {
	nextReader = newScanner()
	log.SetFlags(log.Lshortfile)
}

func newScanner() func() []byte {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() []byte {
		r.Scan()
		return r.Bytes()
	}
}
func nextBytes() []byte {
	return nextReader()
}

func nextString() string {
	return string(nextReader())
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(string(nextReader()), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(string(nextReader()))
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(string(nextReader()), 64)
	return f
}


Measured memory_bytes: 4736
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<limits>
#include<iomanip>
#include<cmath>
#include<climits>
using namespace std;

typedef long long ll;
typedef string S;
typedef pair<int,int> P;
typedef vector<int> vi;
const int mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<double> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    int ians=0,Min=0;
    for(int i=0;i<n;i++){
        if(fabs(a[n-1]/2-a[ians])>fabs(a[n-1]/2-a[i])){
            ians=i;
        }
    }
    cout << static_cast<int>(a[n-1])<< " " << static_cast<int>(a[ians]) << endl;
    return 0;
}

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

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}

template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}

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

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}

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

  int s, w; cin >> s >> w;
  if(s <= w) cout << "un";
  cout << "safe" << endl;

}
























Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

// 階乗や組合わせの場合の数を求める
ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1)*a%MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1)*a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b,a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size()>n) return kaijo_memo[n];
  if(kaijo_memo.size()==0) kaijo_memo.push_back(1);
  while(kaijo_memo.size()<=n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1]*kaijo_memo.size()%MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size()>n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size()==0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size()<=n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1]*mpow(gyaku_kaijo_memo.size(),MOD-2)%MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n==r) return 1;
  if(n<r ||r<0) return 0;
  ll ret = 1;
  ret *= kaijo(n); ret %= MOD;
  ret *= gyaku_kaijo(r); ret %= MOD;
  ret *= gyaku_kaijo(n-r); ret %= MOD;
  return ret;
}


signed main(){
	ll n,k; cin>>n>>k;
	if(n+1<k) return cout<<0<<endl,0;
	ll ans = 0;
	ll l = 0, r = 0;
	rep(i,k){
		l+=i; r+=n-i;
		l+=MOD; r+=MOD;
		l%=MOD; r%=MOD;
	}
	for(int i=k;i<=n+1;i++){
		ans+=r-l+1; ans+=MOD; ans%=MOD;
		l+=i, r+=n-i;
		l+=MOD; r+=MOD;
		l%=MOD; r%=MOD;
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 3652
n=int(input())
l=list(map(int,input().split()))


c=0
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      if l[i]+l[j]>l[k] and l[i]+l[k]>l[j] and l[k]+l[j]>l[i]:
        if l[i]!=l[j] and l[j]!=l[k] and l[k]!=l[i]:
          c+=1
print(c)
        

Measured memory_bytes: 9116
#include <stdio.h>

int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	if(a<b){
		printf("a < b\n");
	}else if(a>b){
		printf("a > b\n");
	}else if(a==b){
		printf("a == b\n");
	}

	return 0;
}

Measured memory_bytes: 580
import java.util.Scanner
import scala.io.StdIn._

object Main extends App {

  val Array(n, m) = readLine().split(" ").map(_.toInt)
  val H = readLine().split(" ").map(_.toInt)
  val A = Array.fill(m)(readLine().split(" ").map(_.toInt - 1))


  def solve() = {
    val hMaxArr = Array.fill(n)(0)

    A.foreach { root =>
      val s = root(0)
      val e = root(1)
      hMaxArr(s) = Math.max(hMaxArr(s), H(e))
      hMaxArr(e) = Math.max(hMaxArr(e), H(s))
    }
    (0 until n).foldLeft(0L) { case (acc, index) =>
      if(H(index) > hMaxArr(index)) acc+1 else acc
    }
  }

  println(solve())

}



Measured memory_bytes: 66828
/*
#include <boost/functional/hash.hpp>
#include <boost/multiprecision/cpp_int.hpp>
typedef boost::multiprecision::cpp_int mlint;
*/
#include <bits/stdc++.h>
using namespace std;

#define debug 0
#define print(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define fcout(d) cout << fixed << setprecision(d)
#define each(i,v) for(auto i = begin(v); i != end(v); ++i)
#define reach(i,v) for(auto i = rbegin(v); i != rend(v); ++i)
#define urep(i,s,t) for(int i = (int)(s); i <= (int)(t); ++i)
#define drep(i,s,t) for(int i = (int)(s); i >= (int)(t); --i)
#define rep(i,n) urep(i,0,(n) - 1)
#define rep1(i,n) urep(i,1,(n))
#define rrep(i,n) drep(i,(n) - 1,0)
#define all(v) begin(v),end(v)
#define rall(v) rbegin(v),rend(v)
#define vct vector
#define prique priority_queue
#define l_bnd lower_bound
#define u_bnd upper_bound
#define rsz resize
#define ers erase
#define emp emplace
#define emf emplace_front
#define emb emplace_back
#define pof pop_front
#define pob pop_back
#define mkp make_pair
#define mkt make_tuple
#define fir first
#define sec second

typedef long long ll;
typedef double db;
//typedef vct<vct<ll>> mat;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tiii;
typedef map<int,int> mpii;
typedef unordered_map<int,int> umpii;

template <class T, class U> ostream& operator << (ostream& s, pair<T,U> p) { return s << p.fir << " " << p.sec; }
template <class T> ostream& operator << (ostream& s, vct<T> v) { each(i,v) { if(i != begin(v)) s << " "; s << *i; } return s; }

auto esc = [](auto ret) { cout << ret << endl; exit(0); };
auto odd = [](auto x) { return x & 1; };
auto even = [](auto x) { return !odd(x); };
auto qceil = [](auto x, auto y) { return x > 0 ? (x - 1) / y + 1 :  x / y; };
auto parity = [](auto x, auto y) { return odd(x) ^ even(y); };
auto chmax = [](auto& m, auto x) { if(m < x) { m = x; return 1; } return 0; };
auto chmin = [](auto& m, auto x) { if(m > x) { m = x; return 1; } return 0; };
auto cmprs  = [](auto& v) {
    auto tmp = v;
    sort(all(tmp));
    tmp.erase(unique(all(tmp)),end(tmp));
    for(auto it = begin(v); it != end(v); ++it) *it = l_bnd(all(tmp),*it) - begin(tmp) + 1;
    return tmp.size() != v.size();
};

const int dir[8][2] = { {1,0},{0,1},{-1,0},{0,-1},{1,1},{-1,1},{-1,-1},{1,-1} };
const ll inf32 = (1 << 30) - 1;
const ll inf64 = (1LL << 62) - 1;
const ll mod = 1e9 + 7;
const db eps = 1e-15;



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

    int n,k;
    cin >> n >> k;
    int a[100001];
    rep(i,n) cin >> a[i];
    queue<int> q[100001];
    rep(i,n) q[a[i]].push(i);
    int ans = 0;
    rep1(i,k){
        if(q[i].empty()) esc(0);
        ans = max(ans,q[i].front() + 1);
    }
    int tmp = ans;
    rep(i,n) {
        q[a[i]].pop();
        if(q[a[i]].empty() && a[i] <= k) esc(ans);
        tmp--;
        if(a[i] <= k) tmp = max(tmp,q[a[i]].front() - i);
        ans = min(ans,tmp);
    }
    esc(ans);
}



Measured memory_bytes: 71184
import java.util.Scanner;

public class Main {
	static int prime[] = new int [999999];
	static boolean is_prime[] = new boolean[1000000];
	static int sieve(int n){
		int p = 0;
		for(int i = 0;i <= n; i++) is_prime[i] = true;
		is_prime[0] =  false;
		is_prime[1] = false;
		for(int i = 2;i <= n;i++){
			if(is_prime[i]){
				prime[p++] = i;
				for(int j = 2*i;j <= n;j += i) is_prime[j] = false;
			}
		}
		return p;
	}
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		while(true){
			try{
				int N = in.nextInt();
	            System.out.println(sieve(N));
			}catch(Exception e){
				System.exit(0);
			}
		}
	}
}

Measured memory_bytes: 26436
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {

    // test
    
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(in.readLine());
        int n = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());
        @SuppressWarnings("unchecked")
        List<LR> list[] = new List[m + 1];
        for (int i = 1; i <= m; i++) {
            list[i] = new ArrayList<>();
        }
        for (int i = 1; i < n + 1; i++) {
            st = new StringTokenizer(in.readLine());
            int start = Integer.parseInt(st.nextToken());
            int end = Integer.parseInt(st.nextToken());
            list[end - start + 1].add(new LR(start, end));
        }
        int[] fen = new int[m + 1];
        int accum = n;
        StringBuilder sb = new StringBuilder();
        for (int i = 1; i < m + 1; i++) {
            int ans = 0;
            for (int j = i; j < m + 1; j += i) {
                ans += accum(fen, j);
            }
            for (LR temp : list[i]) {
                add(temp.l, 1, fen);
                add(temp.r + 1, -1, fen);
            }
            sb.append(ans + accum);
            sb.append('\n');
            accum -= list[i].size();
        }
        System.out.println(sb);
    }

    static class LR {
        final int l, r;

        LR(int start, int end) {
            this.l = start;
            this.r = end;
        }
    }

    static int accum(int[] fen, int i) {
        int ans = 0;
        while (i > 0) {
            ans += fen[i];
            i -= (i & -i);
        }
        return ans;
    }

    static void add(int i, int a, int[] fen) {
        while (i < fen.length) {
            fen[i] += a;
            i += (i & -i);
        }
    }
}

Measured memory_bytes: 61688
def main():
    from sys import stdin
    from collections import Counter
    readline = stdin.readline

    n = int(readline())
    S = [readline()[:-1] for _ in [0]*n]

    s = Counter(S)
    most = s.most_common(1)[0][1]

    answers = [i[0] for i in s.items() if i[1] == most]
    answers = sorted(answers)

    for ans in answers:
        print(ans)


if __name__ == '__main__':
    main()

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

int main()
{
    int n,t,i,z,k;
    int a[100010];
    while(scanf("%d",&n)!=EOF){
        t=1;
        for(i=1;i<=n;i++){
            scanf("%d",&a[i]);
        }
        z=a[1];
        for(i=1;i<=n;i++){
            if(z!=2){
                z=a[z];
                t++;
            }
            else {printf("%d\n",t);break;}
        }
        if(i>n)printf("-1\n");

    }
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
using namespace std;

const long long mod=1e9+7;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> vn(N);
  REP(n,N) cin >> vn.at(n);

  int ans = 0;
  REP(i,min({N,K})+1){
    vector<int> vec(i);
    REP(j,i+1){
      int A = j;
      int B = i-j;
      int cnt = 0;
      REP(aa,A){
        vec.at(cnt) = vn.at(aa);
        cnt+=1;
      }
      REP(bb,B){
        vec.at(cnt) = vn.at(N-1-bb);
        cnt +=1;
      }

      sort(vec.begin(),vec.end());

      REP(k,min({K-i, i})){
        if(vec.at(k) < 0) vec.at(k) = 0;
      }

      int tmp = accumulate(vec.begin(),vec.end(), 0);
      ans = max({ans,tmp});
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<string>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main(){
    int n;
    cin >> n;
    int ret = 0;
    rep(i, n) {
        int a;
        cin >> a;
        ret ^= a;
    }
    if ( ret == 0 ) cout << "Yes" << endl;
    else            cout << "No" << endl;
    return 0;
}

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

int main(){
  string s[3];
  cin >> s[0] >> s[1] >> s[2];
  locale l = locale::classic();
  for (int i=0; i < 3; i++) {
    cout << toupper(s[i][0], l);
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int ans = 0;
    for(int i=0; i<4; i++) {
        int v; cin >> v;
        ans += v;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3100
#include <stdio.h>
int main(void){
	char a[4];
	int i,c=0;
	scanf("%s",a);
	for(i=0;i<3;i++){
		if(a[i]=='o'){
			c++;
		}
	}
	printf("%d",700+100*c);
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector <int> a(n);
    rep(i,n) cin >> a[i];

    int p=max(a[0], a[1]);
    int s=min(a[0], a[1]);
    if(n == 2){
        cout << a[1] << endl;
        cout << a[0] << endl;
        return 0;
    }

    for(int i=2; i<n; i++){
        if(a[i] >= p){
            s = p;
            p = a[i];
        }

        else if (a[i] > s){
            s = a[i];
        }
    }

    vector <int> ans(n);
    rep(i,n){
        if(a[i] == p) ans[i] = s;
        else ans[i] = p;
    }

    rep(i,n){
        cout << ans[i] << endl;
    }

}


Measured memory_bytes: 3200
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
K = int(input())
a = abs(A-B)
b = abs(A-C)
c = abs(A-D)
d = abs(A-E)
e = abs(B-C)
f = abs(B-D)
g = abs(B-E)
h = abs(C-D)
i = abs(C-E)
j = abs(D-E)
if a<=K and b<=K and c<=K and d<=K and e<=K and f<=K and g<=K and h<=K and i<=K and j<=K:
  print("Yay!")
else:
  print(":(")

Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int n = sc.nextInt();
        int m = sc.nextInt();

        PriorityQueue pq = new PriorityQueue<>(Collections.reverseOrder());
      
        for (int i = 0; i < n; i++) {
          pq.add(sc.nextInt());
        }        
      
        for (int i = 0; i < m; i++) {
          int max = (int) pq.poll();
          max = max / 2;
          pq.add(max);
        }
      
        long sum = 0;
        for (int i = 0; i < n; i++) {
          sum += (int) pq.poll();
        }
      System.out.println(sum);
    }
}   

Measured memory_bytes: 58648
#include <iostream>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  for (int i = 0; i < s.size(); ++i) {
    if (s.at(i) != t.at(i)) {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a,b,c;
    while(cin>>a>>b>>c)
    {
        ll ans=0;
        bool chk=0;
        while(a%2==0 && b%2==0 && c%2==0)
        {
            ll x=(b/2)+(c/2);
            ll y=(a/2)+(c/2);
            ll z=(a/2)+(b/2);
            ans++;

            int cnt=0;
            if(x==a && y==b && z==c)
            {
                chk=1;
                break;
            }
            a=x;
            b=y;
            c=y;
        }
        if(chk) cout<<-1<<endl;
        else cout<<ans<<endl;
    }
    return 0;
}


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

class Program
{
    static void Main(string[] args)
    {
        var N = int.Parse(ReadLine());

        var ans = 0;

        for (int i = 111; i <= 999; i += 111)
        {
            if(N<=i)
            {
                ans = i;
                break;
            }
        }

        WriteLine(ans);
    }
}


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

namespace ABC111B
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = int.Parse(Console.ReadLine());

            int answer = 0;
            if (input <= 111)
                answer = 111;
            else if (input <= 222)
                answer = 222;
            else if (input <= 333)
                answer = 333;
            else if (input <= 444)
                answer = 444;
            else if (input <= 555)
                answer = 555;
            else if (input <= 666)
                answer = 666;
            else if (input <= 777)
                answer = 777;
            else if (input <= 888)
                answer = 888;
            else if (input <= 999)
                answer = 999;

            Console.WriteLine(answer);
        }
    }
}


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

int main(){
    ll N, K;
    cin >> N >> K;

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

    int k=0;
    int st;
    int root[N]={0};
    int wi=0;
    int now=0;
    while(k<K){
        root[now]=1;
        k++;
        if(root[A[now]-1]==1){
            st=A[now]-1;
            now=st;
            while(true){
                wi++;
                now=A[now]-1;
                if(now==st) break;
            }
            break;
        }
        now=A[now]-1;
        root[now]=1;
    }

    int ans;
    if(k==K) ans=now+1;
    else{
        int num=(K-k)%wi;
        rep(i, num) now=A[now]-1;
        ans=now+1;
    }

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

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

ll func(ll a, ll b, ll x) { return a * x / b - a * (x / b); }
int main() {
  ll a, b, n;
  cin >> a >> b >> n;

  cout << func(a, b, min(b - 1, n)) << endl;
}

Measured memory_bytes: 3636
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<set>
#include<tuple>
using namespace std;
#define INF 11000000000
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> p;
typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)

ll dp[2100][2];

int main(){
    int N;
    ll Z,W,a[2100];
    cin>>N>>Z>>W;
    for(int i=0;i<N;i++){
        cin>>a[i];
    }
    ll ans=0;
    for(int i=N-1;i>=1;i--){
        for(int j=0;j<=1;j++){
            if(j==0){
                ll temp=0;
                int k=i+1;
                while(k<=N-1){
                    temp=max(temp,dp[k][1]);
                    k++;
                }
                temp=max(temp,abs(a[N-1]-a[i-1]));
                dp[i][0]=temp;
            }else{
                ll temp=1100000000;
                int k=i+1;
                while(k<=N-1){
                    temp=min(temp,dp[k][0]);
                    k++;
                }
                temp=min(temp, abs(a[N-1]-a[i-1]) );
                dp[i][1]=temp;
            }
            if(j==1) ans=max(ans,dp[i][j]);
        }
    }
    
    ans=max(abs(a[N-1] - W) ,ans );
    cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
#define PI acos(-1.0)
#define eps 1e-9
#define ll long long
#define ull unsigned long long
#define nl printf("\n")
#define spc printf(" ")
#define sf scanf
#define pf printf
#define INF (ll)1e15
#define mod 1000000007
#define FI freopen("input.txt","r",stdin)
#define FO freopen("output.txt","w",stdout)
#define si(x) scanf("%d",&x)
#define sii(x,y) scanf("%d %d",&x,&y)
#define siii(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sll(x,y) scanf("%lld %lld",&x,&y)
#define slll(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)

///#define isValid(n,m,nx,ny)nx>=0&&nx<n&&ny>=0&&ny<m
///#define triangle_area(a,b,m,n,x,y) (a*(n-y)+m*(y-b)+x*(b-n))/2.0
///int ax[]={1, 1, -1, -1, 2, 2, -2, -2}; //knight moves
///int ay[]={2,-2,  2, -2, 1,-1,  1, -1}; //knight moves
///int dx[]={1,-1,0,0,1,-1,1,-1};//eight direction
///int dy[]={0,0,1,-1,1,-1,-1,1};//eight direction

///using namespace __gnu_pbds;
using namespace std;

inline double toRad(double deg){return deg*PI/180;}
inline double toDeg(double rad){return rad*180/PI;}
///typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;

const int S=123456;
int main()
{
    #ifndef ONLINE_JUDGE
    //FI;
    //FO;
    #endif
    //ios_base::sync_with_stdio(0); cin.tie(0);
    double a,b,x;
    while(cin>>a>>b>>x)
    {
        double y=x/a;
        double theta;
        if(y<=(b/2.0)*a)
        {
            double t=(2.0*y)/(b*b);
            theta=atan(t);
        }
        else
        {
            double z=(a*b)-y;
            double t=(a*a)/(2.0*z);
            theta=atan(t);
        }

        cout<<fixed<<setprecision(13)<<90-toDeg(theta)<<endl;
    }
    return 0;
}







Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

const int MAX_N = 20005;

class segTree{
    public:
        int n, dat[4 * MAX_N];
        virtual int query(int, int, int, int, int) = 0;
        void init(int n_){}
        void init(int a[MAX_N], int n_){
            n = 1;
            while(n <= n_) n *= 2;
            for(int i = n; i < n * n; i++){
                dat[i] = a[i - n];
            }
            for(int i = n - 1; i >= 1; i--){
                dat[i] = min(dat[i * 2], dat[i * 2 + 1]);
            }
        }
};

class rangeAddQuery : public segTree{
    private:
        int dat_add[4 * MAX_N];
        int query(int a, int b, int k, int l, int r){
            if(b <= l || r <= a) return 0;
            else if(a <= l && r <= b) return dat[k] * (r - l) + dat_add[k];
            else{
                int res = (min(b, r) - max(a, l)) * dat[k];
                res += query(a, b, k * 2, l, (l + r) / 2);
                res += query(a, b, k * 2 + 1, (l + r) / 2, r);
                return res;
            }
        }
        void add(int a, int b, int k, int l, int r, int x){
            if(a <= l && r <= b){
                dat[k] += x;
            }else if(l < b && a < r){
                dat_add[k] += (min(b, r) - max(a, l)) * x;
                add(a, b, k * 2, l, (l + r) / 2, x);
                add(a, b, k * 2 + 1, (l + r) / 2, r, x);
            }
        }
    public:
        void init(int n_){
            n = 1;
            while(n <= n_) n *= 2;
            rep(i,2 * n) dat[i] = dat_add[i] = 0;
        }

        void update(int i, int x){
            add(i, i + 1, 1, 0, n, x);
        }
        int query(int a, int b){
            return query(a,b,1,0,n);
        }
        void add(int s, int t, int x){
            add(s, t, 1, 0, n, x);
        }
        int get(int a){ return query(a, a + 1); }
        void outputAns(int n_){
            rep(i,n_){
                cout << get(i + 1) << (i == n_ - 1 ? '\n' : ' ');
            }
        }
};

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

    int p[20005];
    rep(i,n){
        cin >> p[i];
    }

    rangeAddQuery a, b;
    a.init(n);
    b.init(n);
    rep(i,n){
        a.update(i + 1, i + 1);
        b.update(i + 1, n - i);
    }

    int pre = a.get(p[0]) + b.get(p[0]);
    range(i,1,n){
        int cur = a.get(p[i]) + b.get(p[i]);
        if(pre >= cur){
            int dif = pre - cur + 1;
            //show(dif)
                //cout << p[i] << ' ' << n + 1 << endl;
            a.add(p[i], n + 1, dif);
            b.add(1, p[i] + 1, dif);
        }
        pre = a.get(p[i]) + b.get(p[i]);
    }

    vector<int> v;
    rep(i,n){
        v.emplace_back(a.get(p[i]) + b.get(p[i]));
    }
    //assert(v.end() == adjacent_find(all(v), [](const int &a, const int &b){ return a > b; }));
    a.outputAns(n);
    b.outputAns(n);
}


Measured memory_bytes: 1920
#include <iostream>

using namespace std;

long long kaijo(int n)
{
	if (n == 1) return 1;
	else return (n*kaijo(n - 1))%1000000007;
}

int main()
{
	int n, m;
	long long ans;

	cin >> n >> m;

	if (n - m > 1 || m - n > 1)
	{
		cout << "0" << endl;
	}
	else
	{
		if (n == m)
		{
			ans = (kaijo(n)%1000000007) * (kaijo(m)%1000000007) * 2;
		}
		else
		{
			ans = kaijo(n) * kaijo(m);
		}

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


Measured memory_bytes: 1792
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    //nextLineとnextを同時に使ったら死ぬ
    val sc = new Scanner(System.in)
    val h, w = sc.nextInt()
    val map = List.fill(h)(sc.next())
    (0 until w + 2).foreach(_ => print('#'))
    println()
    map.foreach(elm => {
      print('#')
      elm.foreach(print)
      println('#')
    })
    (0 until w + 2).foreach(_ => print('#'))
    println()
  }
}


Measured memory_bytes: 32804
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

ll V;
vector<vector<ll>> G;
vector<ll> match;
vector<int> used;

void add_edge(ll u, ll v) {
	G[u].push_back(v);
	G[v].push_back(u);
}

bool dfs(ll v) {
	used[v] = 1;
	for (int i = 0; i < G[v].size(); i++) {
		ll u = G[v][i], w = match[u];
		if (w < 0 || ((used[w] == 0) && dfs(w))) {
			match[v] = u;
			match[u] = v;
			return true;
		}
	}
	return false;
}

ll bipartite_matching() {
	ll res = 0;
	for (int i = 0; i < (int)match.size();i++)match[i] = -1;
	for (int v = 0;v < V;v++) {
		if (match[v] < 0) {
			for (int i = 0; i < (int)used.size();i++)used[i] = 0;
			if (dfs(v))res++;
		}
	}
	return res;
}

/* use example */
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	ll X, Y, E; cin >> X >> Y >> E;
	V = X + Y + 2; // initialize V
	G.resize(V); used.resize(V); match.resize(V); // initialize G used match
	for (int i = 0; i < E;i++) {
		ll x, y; cin >> x >> y;
		add_edge(x, y + X);
	}
	cout << bipartite_matching() << endl;
	return 0;
}

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

int  main()
{
	int k; cin >> k;
	int ans;
	if (k % 2 == 0)
	{
		ans = (k/2)*(k/2);
	}
	else
	{
		ans = (k/2)* ((k+1) / 2);
	}
	cout << ans << endl;
	return (0);
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b && b == c && a == c) {
        puts("Yes");
    } else {
        puts("No");
    }
    return 0;
}

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

using namespace std;
using ll = long long;
using ii = pair<int, int>;

const int MAX { 200010 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

vector<int> adj[MAX];

vector<int> solve(int N)
{
    vector<int> ans(N + 1, -1);
    queue<int> q;
    q.push(1);

    while (not q.empty())
    {
        auto u = q.front();
        q.pop();

        for (auto v : adj[u])
        {
            if (ans[v] == -1)
            {
                ans[v] = u;
                q.push(v);
            }
        }
    }

    for (auto i = 2; i <= N; ++i)
        if (ans[i] == -1)
            return { };

    return ans;
}

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

    int N, M;
    cin >> N >> M;

    vector<ll> xs(N);

    for (int i = 0; i < M; ++i)
    {
        int u, v;
        cin >> u >> v;

        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    auto ans = solve(N);

    if (ans.empty())
        cout << "No\n";
    else
    {
        cout << "Yes\n";

        for (int i = 2; i <= N; ++i) 
            cout << ans[i] << endl;
    }

    return 0;
}


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

int main(){
  int n; cin >> n;
  string s; cin >> s;
  set<char> a; set<pair<char,char>> b; set<tuple<char,char,char>> c;
  for (int i = n-1; i >= 0; i--){
    for (auto u : b){
      char x = u.first, y = u.second;
      c.insert(make_tuple(s.at(i), x, y));
    }
    for (char c : a) b.insert(make_pair(s.at(i), c)); 
    a.insert(s.at(i));
  }
  cout << c.size() << endl;
  return 0;
}

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

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

const int INF = 1000000007;

int cal[2] ={1, -1};
int cal2[2]={1, -1};
int cal3[2]={1, -1};

int main(){
	int n; cin>>n;
	int a,b,c,d;

	d = n % 10; n /= 10;
	c = n % 10; n /= 10;
	b = n % 10; n /= 10;
	a = n % 10; n /= 10;

	//cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
	
	if(a+b+c+d==7) cout<<a<<'+'<<b<<'+'<<c<<'+'<<d<<"=7"<<endl;
	else if(a+b+c-d==7) cout<<a<<'+'<<b<<'+'<<c<<'-'<<d<<"=7"<<endl;
	else if(a+b-c+d==7) cout<<a<<'+'<<b<<'-'<<c<<'+'<<d<<"=7"<<endl;
	else if(a+b-c-d==7) cout<<a<<'+'<<b<<'-'<<c<<'-'<<d<<"=7"<<endl;
	else if(a-b+c+d==7) cout<<a<<'-'<<b<<'+'<<c<<'+'<<d<<"=7"<<endl;
	else if(a-b+c-d==7) cout<<a<<'-'<<b<<'+'<<c<<'-'<<d<<"=7"<<endl;
	else if(a-b-c+d==7) cout<<a<<'-'<<b<<'-'<<c<<'+'<<d<<"=7"<<endl;
	else if(a-b-c-d==7) cout<<a<<'-'<<b<<'-'<<c<<'-'<<d<<"=7"<<endl;


	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int a=stdIn.nextInt();
		int b=stdIn.nextInt();
		int c=stdIn.nextInt();
		int z=0,y=0,x=0;
		if(a==5)
			z++;
		else
			y++;
		if(b==5){
			z++;
		}
		else{
			y++;
		}
		if(c==5)
			z++;
		else
			y++;
		if(z==2&&y==1)
			System.out.println("YES");
		else
			System.out.println("NO");
	}
}

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

N, M = map(int, input().split())
L = [[int(v) for v in input().split()] for _ in range(M)]
m = [set() for _ in range(N)]

for l, r in L:
    l -= 1
    r -= 1
    
    m[l].add(r)
    
N -= 1
for v in m[0]:
    if N in m[v]:
        print("POSSIBLE")
        exit()
        
print("IMPOSSIBLE")

Measured memory_bytes: 93976
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long   ll;
typedef unsigned long long   ull;
typedef long double ld;
typedef pair<ll, ll>    pll;
typedef pair<ull, ull>    pull;
typedef pair<ll, ll>  pii;
typedef pair<ld, ld>  pld;
ll n, m;
vector<ll> g[100009];
ll wh[100009];
ll bl[100009];
ll ans[100009];
void precalc(ll v, ll p){
    wh[v] = 1;
    bl[v] = 1;
    for(auto u : g[v]){
        if(u == p)
            continue;
        precalc(u, v);
        bl[v] *= (bl[u]+wh[u])%m;
        bl[v] %= m;

        wh[v] *= wh[u];
        wh[u] %= m;
    }
}
void calc(ll v, ll p){
    ans[v] = bl[v];
    vector<ll> vecwh;
    vector<ll> vecbl;
    ll cur = 0;
    for(auto u : g[v]){
        vecwh.pb(wh[u]);
        vecbl.pb((bl[u]+wh[u])%m);
        ++cur;
    }
    for(int i = vecwh.size()-2; i >= 0; --i){
        vecwh[i] = vecwh[i]*vecwh[i+1]%m;
        vecbl[i] = vecbl[i]*vecbl[i+1]%m;
    }
    ll befwh = 1;
    ll befbl = 1;
    cur = 0;
    for(auto u : g[v]){
        ++cur;
        if(u == p){
            befbl = befbl*((bl[u]+wh[u])%m)%m;
            befwh = befwh*wh[u]%m;
            continue;
        }
        ll oldblv = bl[v];
        ll oldwhv = wh[v];
        ll oldblu = bl[u];
        ll oldwhu = wh[u];
        
        bl[v] = befbl;
        wh[v] = befwh;
        if(cur < vecwh.size()){
            bl[v] = bl[v]*vecbl[cur]%m;
            wh[v] = wh[v]*vecwh[cur]%m;
        }
        //cout << u << " " << v <<" " << bl[v] << " " << wh[v] << "\n";
        wh[u] = wh[u]*wh[v]%m;
        bl[u] = bl[u]*((bl[v]+wh[v])%m)%m;
        calc(u, v);
        bl[v] = oldblv;
        wh[v] = oldwhv;
        bl[u] = oldblu;
        wh[u] = oldwhu;
        befbl = befbl*((bl[u]+wh[u])%m)%m;
        befwh = befwh*wh[u]%m;
    }
}
int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);

    cin >> n >> m;
    for(ll i = 0; i < n-1; ++i){
        ll t1, t2;
        cin >> t1 >> t2;
        g[t1].pb(t2);
        g[t2].pb(t1);
    }
    precalc(1, -1);
    calc(1, -1);
    for(int i = 1; i <= n; ++i)
        cout << ans[i] << "\n";
}

Measured memory_bytes: 27520
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2767>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

ll solve(){
    ll res = 0;
    ll N; cin >> N;
    string S; cin >> S;
    vector<int> alpha;
    for(int i = 0; i < 26;i++){
        int x = (int)count(S.begin(),S.end(),'a'+i);
        if(x == 0) continue;
        alpha.push_back(x);
    }
    for(int x = 1; x <= 9; x++){
        int y = (int)count(alpha.begin(),alpha.end(),x);
        if(y == 0) continue;
        if(x == 1){
            res += (2*y-1);
        }else{
            if(y == 1){
                res += 3*y;
            }else{
                res += (4+2*y-1);
            }
        }
    }
    sort(alpha.begin(),alpha.end());
    alpha.erase(unique(alpha.begin(),alpha.end()),alpha.end());
    
    res += alpha.size()-1;
    
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}



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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

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

inline bool ok(vector<int> &v){
    rep(i,1,9) if(v[i]!=v[i-1]) return false;
    rep(i,10,12) if(v[i]!=v[i-1]) return false;
    rep(i,13,15) if(v[i]!=v[i-1]) return false;
    rep(i,16,18) if(v[i]!=v[i-1]) return false;
    rep(i,19,21) if(v[i]!=v[i-1]) return false;
    rep(i,22,30) if(v[i]!=v[i-1]) return false;
    return true;
}

inline vector<int> rotate1(vector<int> v){
    swap(v[0],v[27]);
    swap(v[1],v[28]);
    swap(v[2],v[29]);
    
    swap(v[14],v[15]);
    
    swap(v[20],v[18]);
    return move(v);
}

inline vector<int> rotate2(vector<int> v){
    swap(v[0],v[23]);
    swap(v[3],v[26]);
    swap(v[6],v[29]);
    
    swap(v[20],v[9]);
    
    swap(v[15],v[17]);
    return move(v);
}

inline vector<int> rotate3(vector<int> v){
    swap(v[6],v[21]);
    swap(v[7],v[22]);
    swap(v[8],v[23]);
    
    swap(v[12],v[17]);
    
    swap(v[9],v[11]);
    return move(v);
}

inline vector<int> rotate4(vector<int> v){
    swap(v[2],v[21]);
    swap(v[5],v[24]);
    swap(v[8],v[27]);
    
    swap(v[11],v[18]);
    
    swap(v[12],v[14]);
    return move(v);
}

void solve_(){
    vector<int> p(30);
    for(auto &x:p) cin >> x;
    
    queue<pair<vector<int>,int>> que;
    que.push(make_pair(p,0));
    while(true){
        vector<int> v=que.front().first;
        int d=que.front().second;
        que.pop();
        if(ok(v)){
            cout << d << endl;
            return;
        }
        
        //assert(d<8);
        
        //assert(v==rotate1(rotate1(v)));
        //assert(v==rotate2(rotate2(v)));
        //assert(v==rotate3(rotate3(v)));
        //assert(v==rotate4(rotate4(v)));
        
        que.push(make_pair(rotate1(v),d+1));
        que.push(make_pair(rotate2(v),d+1));
        que.push(make_pair(rotate3(v),d+1));
        que.push(make_pair(rotate4(v),d+1));
    }
}

void solve(){
    int n;
    cin >> n;
    rep(i,0,n) solve_();
}

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

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

using namespace std;

void move_surface(char surface[4]) {
    char tmp = surface[0];
    surface[0] = surface[2];
    surface[2] = surface[3];
    surface[3] = surface[1];
    surface[1] = tmp;
}

void move8(char *c1, char *c2, char *c3, char *c4, char *c5, char *c6, char *c7, char *c8) {
    char tmp1 = *c7;
    char tmp2 = *c8;
    *c8 = *c6;
    *c7 = *c5;
    *c6 = *c4;
    *c5 = *c3;
    *c4 = *c2;
    *c3 = *c1;
    *c2 = tmp2;
    *c1 = tmp1;
}

void rotate(char c, char cube[6][4]) {
    switch (c) {
        case 'L':
            move_surface(cube[0]);
            move8(  &cube[4][0], &cube[4][2], &cube[1][0], &cube[1][2],
                    &cube[5][0], &cube[5][2], &cube[3][3], &cube[3][1]);
            break;
        case 'F':
            move_surface(cube[1]);
            move8(  &cube[4][2], &cube[4][3], &cube[2][0], &cube[2][2],
                    &cube[5][1], &cube[5][0], &cube[0][3], &cube[0][1]);
            break;
        case 'R':
            move_surface(cube[2]);
            move8(  &cube[4][3], &cube[4][1], &cube[3][0], &cube[3][2],
                    &cube[5][3], &cube[5][1], &cube[1][3], &cube[1][1]);
            break;
        case 'B':
            move_surface(cube[3]);
            move8(  &cube[4][1], &cube[4][0], &cube[0][0], &cube[0][2],
                    &cube[5][2], &cube[5][3], &cube[2][3], &cube[2][1]);
            break;
        case 'U':
            move_surface(cube[4]);
            move8(  &cube[3][1], &cube[3][0], &cube[2][1], &cube[2][0],
                    &cube[1][1], &cube[1][0], &cube[0][1], &cube[0][0]);
            break;
        case 'D':
            move_surface(cube[5]);
            move8(  &cube[0][2], &cube[0][3], &cube[1][2], &cube[1][3],
                    &cube[2][2], &cube[2][3], &cube[3][2], &cube[3][3]);
            break;
    }
}

void print(char cube[6][4]) {
    cout << ".." << cube[4][0] << cube[4][1] << "...." << endl;
    cout << ".." << cube[4][2] << cube[4][3] << "...." << endl;
    cout << cube[0][0] << cube[0][1] << cube[1][0] << cube[1][1];
    cout << cube[2][0] << cube[2][1] << cube[3][0] << cube[3][1] << endl;
    cout << cube[0][2] << cube[0][3] << cube[1][2] << cube[1][3];
    cout << cube[2][2] << cube[2][3] << cube[3][2] << cube[3][3] << endl;
    cout << ".." << cube[5][0] << cube[5][1] << "...." << endl;
    cout << ".." << cube[5][2] << cube[5][3] << "...." << endl;
}

int main() {
    string s;
    char cube[6][4] = {
        {'g', 'g', 'g', 'g'},
        {'y', 'y', 'y', 'y'},
        {'b', 'b', 'b', 'b'},
        {'w', 'w', 'w', 'w'},
        {'r', 'r', 'r', 'r'},
        {'o', 'o', 'o', 'o'}
    };
    cin >> s;
    for (int i=0; i<(int)s.length(); i++) {
        rotate(s[i], cube);
    }
    print(cube);
    return 0;
}

Measured memory_bytes: 1184
#include<bits/stdc++.h>
using namespace std;
int main(){
long long n,k;
  cin>>n>>k;
  vector<vector<int>>v(n+1,vector<int>());
  int x;
  for(int i=0;i<n;i++){
    cin>>x;
    v[i+1].push_back(x);
  }
  vector<int>vis(n+1,0);
  int cur;
  int i=1;
  int f= 0;
  int count=0;
  if(n>=k){
     while(k--){
       cur = v[i][0];
       i = cur;
 }
    cout<<cur;
    return 0;
  }
  while(k--){
    count++;
    if(!vis[i]){
       vis[i]= count;
       cur = v[i][0];
       i = cur;
    }
    else{
      f=1;
        break; 
    }
  }
  k++;
  if(k>n){
    k%= count-vis[i];
 }
 while(k--){
   cur = v[i][0];
   i = cur;
 }
  
  cout<<cur;
  return 0;
}


Measured memory_bytes: 14876
// D - Insertion
#include <bits/stdc++.h>
using namespace std;

int main(){
	int _N; cin>>_N;//not used
	string S; cin>>S;
	int l = 0, r = 0;//r = depth
	for(char s:S){
		if(s == '(') r++;
		else{
			r--;
			if(r < 0){
				r = 0;
				l++;
			}
		}
	}
	cout<< string(l,'(') + S + string(r,')') <<endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    private static double[][] dp;
    private static double calculate(int current, int heads, double[] p){
        if(heads == 0) return 1;
        if(current < 0) return 0;
        if(dp[current][heads] != -1) return dp[current][heads];
        double p1 = (1 - p[current]) * calculate(current - 1, heads, p);
        double p2 = p[current] * calculate(current - 1, heads - 1, p);
        dp[current][heads] = p1 + p2;
        return p1 + p2;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        // code goes here
        int n = nextInt(br);
        double[] p = new double[n];
        StringTokenizer st = new StringTokenizer(br.readLine());
        for(int i = 0; i < n; i++){
            p[i] = Double.parseDouble(st.nextToken());
        }
        dp = new double[n][n+1];
        for(int i = 0; i < n; i++){
            Arrays.fill(dp[i], -1);
        }
        double prob = 0;
        for(int i = n/2+1; i <= n/2+1; i++){
            prob += calculate(n - 1, i, p);
        }
        sb.append(prob);
        System.out.print(sb.toString());
    }

    private static int nextInt(BufferedReader br) throws IOException{
        return Integer.parseInt(br.readLine());
    }

    private static int[] nextIntArray(BufferedReader br, int n) throws IOException{
        StringTokenizer st = new StringTokenizer(br.readLine());
        int[] arr = new int[n];
        for(int i = 0; i < n; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        return arr;
    }

    static class Pair<A, B>{
        A first;
        B second;
        public Pair(A first, B second){
            this.first = first;
            this.second = second;
        }
    }
}


Measured memory_bytes: 107960