akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::Read;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn to_time(v: Vec<u8>) -> usize {
    let h: usize = (10 * (v[0] - 48) + v[1] - 48).into();
    let m: usize = (10 * (v[3] - 48) + v[4] - 48).into();
    let s: usize = (10 * (v[6] - 48) + v[7] - 48).into();
    3600 * h + 60 * m + s
}

fn solve() {
    loop {
        let n = get();
        if n == 0 { break; }
        const T: usize = 86400;
        let mut imos = [0; T];
        for _ in 0 .. n {
            let a = to_time(get_word().bytes().collect::<Vec<_>>());
            let b = to_time(get_word().bytes().collect::<Vec<_>>());
            imos[a] += 1;
            imos[b] -= 1;
        }
        for i in 0 .. T - 1 {
            imos[i + 1] += imos[i];
        }
        let ma = imos.iter().max().unwrap();
        println!("{}", ma);
    }
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}



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

namespace CSharpSample01
{


    class Program
    {

        //change(おつり)
        static int Solve(int change)
        {
            int cnt = 0;

            
            int[] coin = { 500, 100, 50, 10, 5, 1 };

            for(int i = 0; i < coin.Length; i++)
            {
                //coin[i]で限界まで引き続ける
                while(true)
                {
                    if(change - coin[i] >= 0)
                    {
                        change -= coin[i];
                        cnt++;
                    }
                    else
                    {
                        break;
                    }
                }
                //おつりが0になったら終了
                if (change == 0) break;
            }
            
            return cnt;
        }

        static void Main(string[] args)
        {
            while (true)
            {
                int cost = int.Parse(Console.ReadLine());

                if (cost == 0) break;

                Console.WriteLine(Solve(1000 - cost));
            }
            
        }
    }
}


Measured memory_bytes: 13844
h, w = gets.split.map(&:to_i)
cm = Array.new(h + 2){Array.new(w + 2, 0)}
que = []
1.upto(h) do |i|
  s = gets.chomp
  1.upto(w) do |j|
    if s[j - 1] == '#'
      cm[i][j] = -1
    end
  end
end
que << [1, 1]
cm[1][1] = 0
while que.size > 0
  y, x = que.shift
  if (cm[y + 1][x] == -1 && cm[y][x + 1] == -1) || cm[y - 1][x + 1] == -1 || cm[y + 1][x - 1] == -1
    puts 'Impossible'
    exit
  end
  if cm[y + 1][x] == -1
    que << [y + 1, x]
  end
  if cm[y][x + 1] == -1
    que << [y, x + 1]
  end
end
puts 'Possible'

Measured memory_bytes: 1788
// This amazing code is by Eric Sunli Chen.
#include<bits/stdc++.h>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

const int maxn=200111;
struct sparse_table
{
	int lg[maxn],v[20][maxn],n;
	void construct(int n,int *a)
	{
		this->n=n;
		for(int i=2;i<=n;i++)lg[i]=lg[i>>1]+1;
		for(int i=1;i<=n;i++)v[0][i]=a[i];
		for(int i=1;i<20;i++)for(int j=1;j<=n;j++)
		{
			int nxt=j+(1<<i-1);
			if(nxt>n)v[i][j]=v[i-1][j];
			else v[i][j]=min(v[i-1][j],v[i-1][nxt]);
		}
	}
	int query(int l,int r)
	{
		int len=lg[r-l+1];
		return min(v[len][l],v[len][r-(1<<len)+1]);
	}
}mn,mx;

int n,m,a[maxn],s[maxn];

int main()
{
	get2(n,m);
	for(int i=1;i<=n;i++)get1(a[i]);
	
	mn.construct(n,a);
	for(int i=1;i<=n;i++)a[i]=-a[i];
	mx.construct(n,a);
	
	int ans=n-m+1;
	for(int i=1;i<=n-m;i++)
	{
		if(mn.query(i,i+m)==-a[i]&&mx.query(i,i+m)==a[i+m])ans--;
	}
	for(int i=1;i<n;i++)s[i]=s[i-1]+(a[i]<a[i+1]);
	
	int last=0;
	for(int i=1;i<=n-m+1;i++)
	{
		if(s[i-1]==s[i+m-2])
		{
			if(last&&last!=i-1)ans--;
			last=i;
		}
	}
	printendl(ans);
	return 0;
}

Measured memory_bytes: 34688
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}



#[allow(non_snake_case, unused_variables)]
fn main() {
    input!{
        N: usize,
        A: [i64; N],
    }
    let mut fact: i64 = 1;
    let mut odd: i64 = 1;
    for a in A {
        if a%2==0 {
            odd *= 2;
        }
        fact *= 3;
    }
    println!("{}", fact-odd);
}


Measured memory_bytes: 4476
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdio>
#include <queue>
#include <map>

#define rep(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define all(v) (v).begin(), (v).end()
#define MP make_pair
#define f first
#define s second

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> P;

void pp(vi v){
	rep(i, v.size()){
		cout << v[i] << ' ';
	}
	cout << endl;
}

void pp(vector<string> v){
	rep(i, v.size()){
		cout << v[i] << endl;
	}
}

void pp(int (*f)[21]){
	rep(i, 21){
		rep(j, 21){
			cout << f[i][j];
		}
		cout << endl;
	}
}

bool checkIsRect(vector<string> &data, int leftx, int topy, int rightx, int bottomy, const char mat){
	// 外周
	for(int j = topy-1; j <= bottomy+1; j++){
		if(data[j][leftx-1] == 'mat') return false;
		if(data[j][rightx+1] == 'mat') return false;
	}
	for(int i = leftx-1; i <= rightx+1; i++){
		if(data[topy-1][i] == 'mat') return false;
		if(data[bottomy+1][i] == 'mat') return false;
	}

	// 内部
	for(int j = topy; j <= bottomy; j++){
		for(int i = leftx; i <= rightx; i++){
			if(data[j][i] != mat && data[j][i] != '#')return false;
		}
	}

	// 長方形が確定したら、物体のあった場所を影とする
	for(int j = topy; j <= bottomy; j++){
		for(int i = leftx; i <= rightx; i++){
			data[j][i] = '#';
		}
	}

	return true;
}

class Edge{
public:
	int leftx;
	int topy;
	int rightx;
	int bottomy;

	bool ischecked;

	Edge(int x, int y){
		leftx = rightx = x;
		topy = bottomy = y;
		ischecked = false;
	}

	void updateEdge(int x, int y){
		leftx = min(leftx, x);
		rightx = max(rightx, x);
		topy = min(topy, y);
		bottomy = max(bottomy, y);
	}
};

bool checkBag(vector<pair<char, Edge> > &item, vector<string> &data){
	// 全ての荷物を調べる
	bool retry = false;
	bool safe = true;
	rep(i, item.size()){
		Edge *e = &item[i].second;
		if(e->ischecked != true){
			e->ischecked = checkIsRect(data, e->leftx, e->topy, e->rightx, e->bottomy, item[i].first);
			retry |= e->ischecked;
		}
		safe &= e->ischecked;
	}
	if(safe) return true;
	if(retry) return checkBag(item, data);
	return false;
}


void updateItem(vector<pair<char, Edge> > &item, char c, int y, int x){
	rep(i, item.size()){
		if(item[i].first == c){ // 端点の更新
			item[i].second.updateEdge(x, y);
			return;
		}
	}
	item.push_back(MP(c, Edge(x, y)));
}

int main(){
	int sets;
	cin >> sets;
	while(sets--){
		int h, w;
		cin >> h >> w;
		vector<string> data(h+2);

		rep(i,w+2) data[0] += '.';
		data[h+1] = data[0];
		FOR(i, 1, h+1){
			cin >> data[i];
			data[i] = '.' + data[i] + '.';
		}

		// それぞれの文字について、左上、右下(と推測される座標)を得る
		vector<pair<char, Edge> > item;
		rep(i, h+2){
			rep(j, w+2){
				if(data[i][j] != '.' && data[i][j] != '#'){
					updateItem(item, data[i][j], i, j);
				}
			}
		}

		if(item.size() == 0) cout << "SAFE" << endl;
		else{
			cout << (checkBag(item, data)?"SAFE":"SUSPICIOUS") << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1232
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

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

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

/* SimpleSegTree(0-index) */

template <typename Type = int>
struct SimpleSegTree{
  int segn2;
  Type initVal;
  vector<Type> data;
  function<Type(Type, Type)> merge;

  SimpleSegTree(int n, Type initVal, function<Type(Type, Type)> merge):
    initVal(initVal), merge(merge)
  {
    for(segn2=1; segn2<n; segn2*=2);
    data.assign(segn2*2, initVal);
  }

  SimpleSegTree(int n): //RangeMinimunQuery
    SimpleSegTree(n, LLINF, [](Type a, Type b){ return min(a, b); }) {}

  SimpleSegTree(int n, Type initVal): //RangeMinimunQuery
    SimpleSegTree(n, initVal, [](Type a, Type b){ return min(a, b); }) {}

  //get value [a,b)
  Type query(int a, int b, int l = 0, int r = -1, int k = 0){
    if(r == -1) r = segn2;
    if(a <= l && r <= b) return data[k];
    if(r <= a || b <= l) return initVal;
    return merge(query(a,b,l,(l+r)/2,k*2+1),query(a,b,(l+r)/2,r,k*2+2));
  }

  //set kth number x
  void set(int k, Type x){
    k += segn2-1;
    data[k] = x;
    while(k > 0){
      k = (k-1)/2;
      data[k] = merge(data[k*2+1], data[k*2+2]);
    }
  }
};


int main(){
  int N, x;
  pair<int,int> p[SIZE];

  scanf("%d", &N);

  SimpleSegTree<ll> seg(N+1);

  seg.set(0, (ll)N * (N + 1) / 2);

  for (int i=0; i<N; i++) {
    scanf("%d", &x);

    ll v = seg.query(0, x);
    seg.set(x, v-x);
  }

  cout << seg.query(0, N+1) << endl;

  return 0;
}



Measured memory_bytes: 4936
#=============================================================================
# ダイクストラ法
#=============================================================================
import heapq
N,M,s=map(int,input().split())
Graph=[[] for _ in range(N+1)]
dig=["INF" for _ in range(N+1)]
see=[False for _ in range(N+1)]

for _ in range(M):
    a,b,w=map(int,input().split())
    Graph[a].append([w,b])
#    Graph[b].append([w,a])

pq=[]
#s=0
dig[s]=0
see[s]=True
for nv in Graph[s]:
    heapq.heappush(pq,nv)

while len(pq):
    v=heapq.heappop(pq)
    if see[v[1]]:
        continue
    see[v[1]]=True
    dig[v[1]]=v[0]
    for nv in Graph[v[1]]:
        if not see[nv[1]]:
            heapq.heappush(pq,[dig[v[1]]+nv[0],nv[1]])

for i in range(N):
    print(dig[i])



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

typedef unsigned uint;
typedef long long INT;
typedef unsigned long long UINT;
const int INF = 1001001001;
const INT INFLL = 1001001001001001001LL;

 int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
INT lin() { INT x; scanf("%lld", &x); return x; }


int main(){
    int a, b, c;
    double fa, fb, fc;
    char sa[128], sb[128], sc[128];

    scanf("%s", sa);

    if (sa[0] == '7') {
        printf("Yes");
    }
    else if (sa[1] == '7') {
        printf("Yes");
    }
    else if (sa[2] == '7') {
        printf("Yes");
    }
    else {
                printf("No");
    }





    return 0;
}







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

int main(){
    int H1,M1,H2,M2,K; cin>>H1>>M1>>H2>>M2>>K;
    int t1 = H1*60+M1;
    int t2 = H2*60+M2;
    int ans = max( t2-K-t1  ,0);
    cout << ans << "\n";
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define STARTUP {(cin.tie(0));\
 (ios::sync_with_stdio(false));}

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define CINVEC(vec) REP(i,(vec).size()) cin>>(vec)[i];

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
std::istream& operator>>(std::istream& is, std::pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

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

using ll = long long;
using namespace std;
ll mod = 1'000'000'007;

const int INF = 1'050'000'000;

int main() {
    STARTUP;

    string s;
    cin >> s;
    string ans = "";
    REP(i, s.length()) {
        if (s[i] == 'B') {
            if (ans.size() > 0)
                ans = ans.erase(ans.size() - 1);
        }
        else {
            ans += s[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii, std.numeric, std.random;
import std.typecons, std.functional, std.traits,std.concurrency;
import std.algorithm, std.container;
import core.bitop, core.time, core.memory;
import std.bitmanip;
import std.regex;

enum INF = long.max/3;
enum MOD = 10L^^9+7;

//辞書順順列はiota(1,N),nextPermituionを使う


void end(T)(T v)
if(isIntegral!T||isSomeString!T||isSomeChar!T)
{
    import core.stdc.stdlib;
    writeln(v);
    exit(0);
}

T[] scanArray(T = long)()
{
    static char[] scanBuf;
    readln(scanBuf);
    return scanBuf.split.to!(T[]);
}

dchar scanChar()
{
    int c = ' ';
    while (isWhite(c) && c != -1)
    {
        c = getchar;
    }
    return cast(dchar)c;
}

T scanElem(T = long)()
{
    import core.stdc.stdlib;
    static auto scanBuf = appender!(char[])([]);

    scanBuf.clear;

    int c = ' ';
    while (isWhite(c) && c != -1)
    {
        c = getchar;
    }
    while (!isWhite(c) && c != -1)
    {
        scanBuf ~= cast(char) c;
        c = getchar;
    }
    return scanBuf.data.to!T;
}

dchar[] scanString(){
    return scanElem!(dchar[]);
}


void main()
{
  auto a = scanElem;
  (a*a-scanElem).writeln;
}


Measured memory_bytes: 256
n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
res=[0,abs(a-(t-(h[0]*0.006)))]
for i in range(1,len(h)):
    if res[1] > abs(a-(t-(h[i]*0.006))):
        res[0] = i
        res[1] = abs(a-(t-(h[i]*0.006)))
print(res[0]+1)

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

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
using lll = long long;
using ull = unsigned long long;
using namespace std;



int main(){
  lll ii,jj,kk;
  lll n;
  cin >>  n;
  cout << pow(n,3) << endl;
  return 0;
}


Measured memory_bytes: 256
def resolve():
    K = int(input())
    N = 50
    ans = [49+K//N]*N
    for i in range(K%N):
        ans[i] += 1
    for j in range(K%N, N):
        ans[j] -= K%N
    print(N)
    print(*ans)
    

if '__main__' == __name__:
    resolve()

Measured memory_bytes: 9172
use proconio::input;

// 最大公約数 (あえて match を使ってみる)
fn gcd(a: usize, b: usize) -> usize {
    match b {
        0 => a,
        _ => gcd(b, a % b)
    }
}

// 最小公倍数
fn lcm(a: usize, b: usize) -> usize {
    a * b / gcd(a, b)
}

fn main() {
	input!(x: usize);

	let lcm = lcm(360, x);
	println!("{}", lcm / x);
}



Measured memory_bytes: 2152
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();
        int times = 0;
        while (H > 1) {
            times++;
            H >>= 1;
        }
        long result = 0;
        for (int i = 0; i<=times; ++i){
            result += Math.pow(2, i);
        }
        System.out.println(result);
    }
}


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

int main() {
    int N,K;
    string S;
    cin >> N >> S >> K;

    for (int i = 0; i < N; i++) {
        if (S.at(i) != S.at(K - 1)) {
            S.at(i) = '*';
        }
    }

    cout << S << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define V vector
#define L long
#define W V<L>
L E=70;W S(V<W>p){if(!E){return{1,0};}V<V<W>>T(2);for(W x:p){T[x[1]&1].push_back({x[0]/2,x[1]/2});if(x[0]&1){T[(x[1]+1)&1].push_back({x[0]/2,(x[1]+1)/2});}}for(int i;i<2;i++){L c=0;for(W x:T[!i]){L Q=(2*x[0]+x[1])%3;c^=Q+1;}if(!c){E--;W A=S(T[i]);A[0]*=2;A[1]*=2;A[1]+=i;return A;}}for(W&v:p){v[0]++;}W A=S(p);A[0]--;return A;}int main(){L M=2e17,n,a,b;cin>>n;V<W>p(n);for(int i;i<n;i++){cin>>a>>b;p[i]={a+M,b+M};}W x=S(p);cout<<x[0]-M<<" "<<x[1]-M;}

Measured memory_bytes: 62908
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
#define PI 3.14159265359

int main()
{
	double a,b,c,x,d,e;
	double sita;
	cin>>a>>b>>x;
	if( x >= a*a*b/2){
		c = 2*b - 2*x/(a*a);
		d = sqrt(a*a + c*c);
		sita = asin(a/d);
		
	}else{
		e = 2*x/(a*b);
		sita = atan(e/b);
	}
	sita = 90- (180 * sita/PI);
	printf("%.10lf\n",sita);
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>

using namespace std;

class Dice {
    public:
        int D[6];

        void constractor(int d1, int d2, int d3, int d4, int d5, int d6);
        void Rotate_E();
        void Rotate_N();
        void Rotate_S();
        void Rotate_W();

};

void Dice::constractor (int d1, int d2, int d3, int d4, int d5, int d6) {
    D[0] = d1;
    D[1] = d2;
    D[2] = d3;
    D[3] = d4;
    D[4] = d5;
    D[5] = d6;
}

void Dice::Rotate_E () {
    int tmp;

    tmp = D[2];
    D[2] = D[0];
    D[0] = D[3];
    D[3] = D[5];
    D[5] = tmp;
}

void Dice::Rotate_N () {
    int tmp;

    tmp = D[4];
    D[4] = D[0];
    D[0] = D[1];
    D[1] = D[5];
    D[5] = tmp;
}

void Dice::Rotate_S () {
    int tmp;

    tmp = D[4];
    D[4] = D[5];
    D[5] = D[1];
    D[1] = D[0];
    D[0] = tmp;
}

void Dice::Rotate_W () {
    int tmp;

    tmp = D[2];
    D[2] = D[5];
    D[5] = D[3];
    D[3] = D[0];
    D[0] = tmp;
}

bool Dice_Compare (Dice dice0, Dice dice1) {

    for (int X = 0; X < 6; X++) {

        Dice dice[2];
        dice[0] = dice0;
        dice[1] = dice1;

        if (X == 0) {

            dice[1].Rotate_S();
        
        } else if (X == 1) {

        } else if (X == 2) {

            dice[1].Rotate_W();
            dice[1].Rotate_S();

        } else if (X == 3) {

            dice[1].Rotate_E();
            dice[1].Rotate_S();

        } else if (X == 4) {

            dice[1].Rotate_S();
            dice[1].Rotate_S();

        } else {

            dice[1].Rotate_N();

        }

        for (int i = 0; i < 4; i++) {

            dice[1].Rotate_E();

            for (int i = 0; i < 6; i++) {
                if (dice[0].D[i] != dice[1].D[i]) {
                    // cout << "X: " << X << " i: " << i << endl;
                    break;
                }

                if (i == 5) {
                    // cout << "X: " << X << endl;
                    return true;
                }
            }
        }

    }

    return false;

}

int main () {

    Dice dice[100];

    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        
        int d1, d2, d3, d4, d5, d6;

        cin >> d1 >> d2 >> d3 >> d4 >> d5 >> d6;
        dice[i].constractor(d1, d2, d3, d4, d5, d6);

    }

    bool X = false;

    for (int i = 0; i < n - 1; i++) {

        bool answer = false;

        for (int j = i + 1; j < n; j++) {
            answer = Dice_Compare(dice[i], dice[j]);

            if (answer) {
                X = true;
                break;
            }
        }
        if (answer) {
            break;
        }
    }

    if (X) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }

    return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> A(N-1), B(N-1);
    vector<vector<int>> g(N);
    for ( int i = 0; i < N-1; i++ ) {
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
        g[A[i]].push_back(B[i]);
        g[B[i]].push_back(A[i]);
    }
    vector<int> C(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> C[i];
    }
    sort(C.begin(), C.end(), greater<int>());
    vector<int> s(N, -1);

    int k = 0;
    queue<int> q;
    q.push(0);
    while ( !q.empty() ) {
        int p = q.front();
        q.pop();
        s[p] = C[k];
        k++;
        for ( int i = 0; i < g[p].size(); i++ ) {
            int v = g[p][i];
            if ( s[v] == -1 ) {
                q.push(v);
            }
        }
    }

    ll sum = 0;
    for ( int i = 1; i < N; i++ ) {
        sum += (ll)C[i];
    }

    cout << sum << '\n';
    for ( int i = 0; i < N; i++ ) {
        cout << (i!=0 ? " " : "") << s[i];
    }    
    cout << '\n';
    return 0;
}

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

using namespace std;
int h, w;
int dx[] = {0, 0, -1, 1};
int dy[] = {-1, 1, 0, 0};

int used[2000][2000];

bool check(int x, int y) {
    return (x >= 0 && x < h && y >= 0 && y < w && used[x][y] == -1);
}

int main() {
    cin >> h >> w;
    string a[h];
    queue<pair<int, int>> que;
    for(int i = 0; i < h; i++) {
        cin >> a[i];
    }
    int i, j;
    for(i = 0; i < 2000; i++) {
        for(j = 0; j < 2000; j++) {
            used[i][j] = -1;
        }
    }
    for(i = 0; i < h; i++) {
        for(j = 0; j < w; j++) {
            if(a[i][j] == '#') {
                que.push(make_pair(i, j));
                used[i][j] = 0;
            }
        }
    }
    int ret = 0;

    while(!que.empty()) {
        pair<int, int> p = que.front();
        que.pop();
        for(i = 0; i < 4; i++) {
            int x = p.first + dx[i];
            int y = p.second + dy[i];
            if(check(x, y)) {
                used[x][y] = used[p.first][p.second] + 1;
                ret = max(used[x][y], ret);
                que.push(make_pair(x, y));
            }
        }
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 25104
import java.util.Scanner;
import java.util.StringJoiner;

class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    String[] ary = new String[n];

    for (int i = 0; i < n; i++ ) {
      ary[i] = String.valueOf(sc.nextInt());
    }

    sc.close();

    StringJoiner sj = new StringJoiner(" ");

    for(int i = 0; i<n; i++) {
      sj.add(ary[n-1-i]);
    }

    System.out.println(sj.toString());

  }
}

Measured memory_bytes: 26248
//Author: Fuadul Hasan(fuadul202@gmail.com)
#include<bits/stdc++.h>
using namespace std;

#define ll long long
const int N   = 2e5 + 5;

int main(){
	
	int n,m;
	cin>>n>>m;
	int a[n+1];

	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	vector<int>v(n+1,0);
	for(int i=1;i<=n;i++){
		v[i] = v[i-1]+a[i];
	}

	for(int i=0;i<v.size();i++){
		if(v[i]>m){
			cout<<i<<endl;
			return 0;
		}/*if(v[i] == m){
			cout<<i<<endl;
			return 0;
		}*/
	}

	cout<<n+1<<endl;


	

	return 0;
}

Measured memory_bytes: 3648
#include <math.h>
#include <stdio.h>

int main() {
  int a, b, c, d, e, f;
  while (scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f) != EOF) {
    double det = a * e - b * d;
    double x = (c * e - b * f) / det;
    double y = (a * f - c * d) / det;
    if (x == 0) {
      x = fabs(x);
    }
    if (y == 0) {
      y = fabs(y);
    }
    printf("%.3lf %.3lf\n", x, y);
  }
  return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE

int valid(vector<int>A){
  int N = A.size();
  for(int i=0;i<N-1;i++)
    if(A[i] > A[i+1]) return 0;
  return 1;
}

signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  cin>>N;
  vector<int> A(N);
  cin>>A;

  for(int i=0;i<N-1;i++){
    if(A[ N - 1 - i] < A[N - 1 - i - 1]) A[N - 1 - i - 1]--;
  }

  int ans = valid(A);
  cout<<(ans? "Yes":"No")<<endl;

  return 0;
}


Measured memory_bytes: 1024
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

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

	n := nextInt()
	m := nextInt()

	city := make([]int, n)
	for i := 0; i < n; i++ {
		city[i] = 0
	}

	a := make([]int, m)
	b := make([]int, m)
	for i := 0; i < m; i++ {
		a[i] = nextInt() - 1
		b[i] = nextInt() - 1
	}

	for i := 0; i < m; i++ {
		city[a[i]]++
		city[b[i]]++
	}

	for _, c := range city {
		fmt.Println(c)
	}
}


Measured memory_bytes: 640
#include <stdio.h>
int main(void)
{
    int Ascore[5],Bscore[5],i;
    for(i=0;i<4;i++)
        scanf("%d",&Ascore[i]);
    for(i=0;i<4;i++)
        scanf("%d",&Bscore[i]);
    Ascore[4]=Ascore[0]+Ascore[1]+Ascore[2]+Ascore[3];
    Bscore[4]=Bscore[0]+Bscore[1]+Bscore[2]+Bscore[3];
    if(Ascore[4]>Bscore[4])
        printf("%d\n",Ascore[4]);
    else
        printf("%d\n",Bscore[4]);
    return 0;
}

Measured memory_bytes: 592
public class Main {


  private static void solve() {
    int n = ni();
    int m = ni();
    int c = ni();
    int[] b = na(m);
    int[][] a = ntable(n, m);
    
    int cnt = 0;
    for (int[] p : a) {
      int x = c;
      for (int i = 0; i < m; i ++) {
        x += p[i] * b[i];
      }
      if (x > 0) {
        cnt ++;
      }
    }
    System.out.println(cnt);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 23568
// tsukasa_diary's programing contest code template
#include <bits/stdc++.h>
using namespace std;
// define
#define for_(i,a,b) for(int i=a;i<b;++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()
// typedef
typedef long long lint;
typedef double Double;
typedef pair<int, int> pii;
//
typedef vector< int > Array;
typedef vector< Array > Matrix;
typedef vector< Double > DArray;
typedef vector< DArray > DMatrix;
typedef vector< string > SArray;
typedef vector< pii > PArray;
// popcount
inline int POPCNT(int _x) { return __builtin_popcount(_x); }
inline int POPCNT(lint _x) { return __builtin_popcountll(_x); }
// inf
const int iINF = 1L << 30;
const lint lINF = 1LL << 60;
// eps
Double EPS = 1e-9;
// in range
inline bool in_range(int _v, int _mx, int _mi) { return _mi <= _v && _v < _mx; }
inline bool in_range(Double _v, Double _mi, Double _mx) { return -EPS < _v - _mi && _v - _mx < EPS; }
inline bool in_range(int _x, int _y, int _W, int _H) { return 0 <= _x && _x < _W && 0 <= _y && _y < _H; }
// neighbor clockwise
const int DX[4] = {0,1,0,-1}, DY[4] = {-1,0,1,0};
const int DX_[8] = {0,1,1,1,0,-1,-1,-1}, DY_[8] = {-1,-1,0,1,1,1,0,-1};
// variable update
inline void modAdd(int& _a, int _b, int _m) { _a = (_a + _b) % _m; }
inline void modAdd(lint& _a, lint _b, lint _m) { _a = (_a + _b) % _m; }
inline void minUpdate(int& _a, int _b) { _a = min(_a, _b); }
inline void minUpdate(lint& _a, lint _b) { _a = min(_a, _b); }
inline void maxUpdate(int& _a, int _b) { _a = max(_a, _b); }
inline void maxUpdate(lint& _a, lint _b) { _a = max(_a, _b); }

bool f[31];

void solve() {
	for_(i,1,31) if (!f[i]) cout << i << endl;
}

int main() {
	for_(i,0,30) {
		int a; cin >> a;
		f[a] = true;
	}
	solve();
	return 0;
}

Measured memory_bytes: 1160
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n=parseInt(readline())
    a,b=parseMap(split(readline()))
    p=parseMap(split(readline()))
    cnt=zeros(Int,3)
    for i in p
        if i<=a
            cnt[1]+=1
        elseif i<=b
            cnt[2]+=1
        else
            cnt[3]+=1
        end
    end
    println(minimum(cnt))
end
main()

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

#if defined(DEBUG)

#include <unistd.h>
#include <sys/fcntl.h>
#define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
#define DCALL(func, ...) func(__VA_ARGS__)

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#else  // defined(DEBUG)

#define DLOG(...)
#define DCALL(func, ...)

#endif // defined(DEBUG)
// ----------------------------------------------------------------------

// ----------------------------------------------------------------------
int main(int argc, char *argv[]) {
#if defined(DEBUG)
  // GDB on Cygwin ignores redirection at run command.
  if (argc == 2) dup2(open(argv[1], 0), 0);
#else
  // For performance.  We should not use C-style stdio functions
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  cout << setprecision(20);

  int N; cin >> N;
  vector<vector<int>> nbr(N);
  for (int i = 0; i < N; i++) {
    string s; cin >> s;
    for (int j = 0; j < N; j++) {
      if (s.at(j) == '1') nbr.at(i).push_back(j);
    }
  }

  auto func = [&](int i) -> int {
    vector<int> bp(N, -1);
    bp.at(i) = 0;
    int idx = 1;
    vector<int> prev;
    prev.push_back(i);
    while (true) {
      vector<int> recent;
      for (int p : prev) {
	for (int x : nbr.at(p)) {
	  if (bp.at(x) == -1) {
	    bp.at(x) = idx;
	    recent.push_back(x);
	  }else if (bp.at(x) % 2 != idx % 2) {
	    return -1;
	  }
	}
      }
      if (recent.size() == 0) return idx;
      prev = move(recent);
      idx ++;
    }
  };


  int ans = 0;
  for (int i = 0; i < N; i++) {
    int x = func(i);
    if (x < 0) {
      cout << "-1\n";
      return 0;
    }
    ans = max(ans, x);
  }
  cout << ans << endl;
  return 0;
}



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

const int mod = 1000000007;
struct mint {
    long long x;
    mint(long long x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

void Main()
{
    long n, a, b;
    cin >> n >> a >> b;

    mint x = 2;

    mint a1 = 1, a2 = 1;
    for (int i = 0; i < a; i++)
    {
        a1 *= (n-i);
        a2 *= i+1;
    }

    mint b1 = a1, b2 = a2;
    for (size_t i = a; i < b; i++)
    {
        b1 *= (n-i);
        b2 *= i+1;
    }

    long x1 = x.pow(n).x - 1;
    long x2 = (a1*a2.inv()).x;
    long x3 = (b1*b2.inv()).x;

    x = x1 - x2 - x3;

    cout << x << endl;

    // ans = 2^n -1 - nCa - nCb
}

int main(int argc, char **argv)
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    Main();
    return 0;
}


Measured memory_bytes: 3620
n=int(input())
d=len(str(n))

if d==1:
    print(n)
elif d==2 or d==3:
    c=9
    if d%2==0:
        print(c)
    else:
        print(c+n-10**(d-1)+1)
elif d==4 or d==5:
    c=909
    if d%2==0:
        print(c)
    else:
        print(c+n-10**(d-1)+1)
elif d==6:
    print("90909")

Measured memory_bytes: 3064
// Author -- Frame

#include<bits/stdc++.h>

#define lowbit(x) ((x)&(-(x)))
#define Finline __inline__ __attribute__ ((always_inline))
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
#define SZ(x) ((int)x.size())
#define mkpr std::make_pair
#define pb push_back

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef std::pair<int,int> pi;
typedef std::pair<ll,ll> pl;
using std::min;
using std::max;

const int inf=0x3f3f3f3f,Inf=0x7fffffff;
const ll INF=0x3f3f3f3f3f3f3f3f;

Finline uint rnd(){static uint seed=416;return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;}
template <typename _Tp>_Tp gcd(const _Tp &a,const _Tp &b){return (!b)?a:gcd(b,a%b);}
template <typename _Tp>Finline _Tp abs(const _Tp &a){return a>=0?a:-a;}
template <typename _Tp>Finline void chmax(_Tp &a,const _Tp &b){(a<b)&&(a=b);}
template <typename _Tp>Finline void chmin(_Tp &a,const _Tp &b){(b<a)&&(a=b);}
template <typename _Tp>Finline void read(_Tp &x)
{
	char ch(getchar());bool f(false);while(!isdigit(ch)) f|=ch==45,ch=getchar();
	x=ch&15,ch=getchar();while(isdigit(ch)) x=(((x<<2)+x)<<1)+(ch&15),ch=getchar();
	f&&(x=-x);
}
template <typename _Tp,typename... Args>Finline void read(_Tp &t,Args &...args){read(t);read(args...);}
template <typename _Tp,typename... Args>Finline _Tp min(const _Tp &a,const _Tp &b,const Args &...args){return a<b?min(a,args...):min(b,args...);}
template <typename _Tp,typename... Args>Finline _Tp max(const _Tp &a,const _Tp &b,const Args &...args){return a<b?max(b,args...):max(a,args...);}
Finline int read_str(char *s)
{
	char ch(getchar());while(ch==' '||ch=='\r'||ch=='\n') ch=getchar();
	char *tar=s;*tar=ch,ch=getchar();while(ch!=' '&&ch!='\r'&&ch!='\n'&&ch!=EOF) *(++tar)=ch,ch=getchar();
	return tar-s+1;
}

int main()
{
	int n,k;read(n,k);
	std::string s,t;
	std::cin>>s;
	char minn=127;
	for(int i=0;i<n;++i) chmin(minn,s[i]);
	if(k>=14)
	{
		for(int i=1;i<=n;++i) putchar(minn);
		putchar('\n');
		return 0;
	}
	--k;
	int qwq=1;for(int i=0;i<k;++i) qwq<<=1;
	t.resize(n+n);
	for(int i=0;i<n;++i) t[i]=s[i],t[i+n]=s[n-i-1];
	std::string ans=s;
	for(int i=n-1;i<n+n;++i)
	{
		int pos=i;
		while(pos>=0&&t[pos]==t[i]) --pos;
		int cnt=i-pos;
		std::string cur;cur.resize(n);
		if(qwq*cnt>=n) for(int j=0;j<n;++j) cur[j]=t[i];
		else
		{
			for(int j=0;j<qwq*cnt;++j) cur[j]=t[i];
			for(int j=qwq*cnt;j<n;++j) cur[j]=t[pos--];
		}
		if(cur<ans) ans=cur;
	}
	printf("%s\n",ans.c_str());
	return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define REP(i, n) for (int i=0; i<n; ++i)
#define print(x) cout << x << endl;

using namespace std;

void solve() {
    int N;
    cin >> N;
    vector<int> B(N-1);
    REP(i, N-1) cin >> B[i];

    int ans = 0;
    REP(i, N) {
        if (i == 0) {
            ans += B[0];
        } else if (i == N-1) {
            ans += B[N-2];
        } else {
            ans += min(B[i-1], B[i]);
        }
    }
    print(ans);
}

int main() {

    solve();
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define PI 3.141592653589793

int main(){
    string S, T; cin >> S >> T;
    int N = S.size(); bool ok = true;
    rep(i, N){
        if(S[i]!=T[i]) ok = false;
    }
    if(T.size()!=N+1) ok=false;
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3624
package main

import (
	"fmt"
)

func solution(n, a, b int64) int64 {
	d := n % (a + b)

	c := n / (a + b)

	if d > a {
		return a * (c + 1)
	}
	return a*c + d
}

func main() {
	var n, a, b int64
	fmt.Scan(&n, &a, &b)
	fmt.Println(solution(n, a, b))
}


Measured memory_bytes: 512
#include <iostream>

int solve(int a){
  int ans=0;
  for(int j=105;j<=a;j+=2){
    int cnt=0;
    for(int i=1;i*i<=j;++i){
      if(j%i==0){
        cnt++;
        if(j/i != i)cnt++;
      }
    }
    if(cnt==8){
      ans++;
      //std::cout<<j<<std::endl;
    }
    //std::cout<<cnt<<std::endl;
  }
  //std::cout<<ans;
  return ans;
}

int main(){
  int n;
  std::cin>>n;
  if(n<105)std::cout<<0<<std::endl;
  else{
    std::cout<<solve(n)<<std::endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MaxN = 2e5+3;
char s[MaxN];
LL l,r;
int cnt[MaxN][26];
struct Statu{
	LL s[26];
	Statu() {memset(s,0,sizeof s);}
	template<typename T>
	Statu(const T* x) {
		for (LL* p=s;p<s+26;++p,++x) *p=*x;
	}
	inline LL& operator [](const char& ch) {
		return *(s+(int)ch-'a');
	}
	inline LL& operator [] (const int& x) {
		return *(s+x);
	}
	inline Statu& operator +=(const Statu& o) {
		for (int i=0;i<26;++i) s[i]+=o.s[i];
		return *this;
	}
	inline Statu operator +(const Statu& b) const {
		Statu ret;
		for (int i=0;i<26;++i) ret.s[i]=s[i]+b.s[i];
		return ret;
	}
	inline void print() const {
		for (int i=0;i<26;++i) printf("%I64d ",s[i]);
		putchar('\n');
	}
};

inline int* Z_box(const char* str,int* z) {
	int r=-1,p=-1,l=strlen(str);
	z[0]=l-1;
	for (int i=1;i<l;++i) {
		z[i]=-1;
		if (r>=i) z[i]=min(z[i-p],r-i);
		while (i+z[i]+1<l && str[i+z[i]+1]==str[z[i]+1]) z[i]++;
		if (i+z[i]>r) r=i+z[i],p=i;
	}
	return z;
}

LL solve(LL llen,Statu L,LL rlen,Statu R,LL last,Statu& ans) {
	if (llen+rlen<=last) {
		LL t=solve(llen+rlen,L+R,llen,L,last,ans);
		last=t;
	}
	if (llen<=last) {
		ans+=L;
		last-=llen;
	}
	return last;
} 
char s2[MaxN];int z[MaxN];
int main() {
	scanf("%s",s);
	cin >> l >> r;
	l--,r--;
	int len=strlen(s);
	for (int i=0;i<len/2;++i) s2[i]=s[i];
	int l2=strlen(s2);
	Z_box(s2,z);
	memset(cnt,0,sizeof cnt);
	cnt[0][s[0]-'a']=1;
	for (int i=1;i<l2;++i) {
		for (int j=0;j<26;++j) cnt[i][j]=cnt[i-1][j];
		cnt[i][s[i]-'a']++;
	}
	int pre=0x7fffffff; 
	for (int i=1;i<l2;++i) {
		if (z[i]!=-1 && i+z[i]==l2-1) pre=min(pre,i); 
	}
	if (pre==0x7fffffff) {
		Statu ans;
		for (int i=0;i<26;++i) {
			ans[i]+=(LL)cnt[l2-1][i]*(r/l2)+cnt[r%l2][i];
			if (l>=1) ans[i]-=(LL)cnt[l2-1][i]*((l-1)/l2)+cnt[(l-1)%l2][i];
		}
		for (int i=0;i<26;++i) cout << ans[i] << " ";
	} else {
		Statu L,R,ans1,ans2,ans;
		for (int i=0;i<26;++i) 
			L[i]=cnt[pre-1][i],
			R[i]=cnt[l2-1][i]-cnt[pre-1][i];
		LL x1=solve(pre,L,l2-pre,R,r+1,ans1),x2=solve(pre,L,l2-pre,R,l,ans2);
		for (int i=0;i<26;++i) {
			ans[i]=ans1[i]-ans2[i]; 
			if (x1>=1) ans[i]+=cnt[x1-1][i];
			if (x2>=1) ans[i]-=cnt[x2-1][i];
		}
		for (int i=0;i<26;++i) cout << ans[i] << " ";
	}
	return 0;
}

Measured memory_bytes: 21248
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)

n = int(input())
G = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int, input().split())
    a,b = a-1,b-1
    G[a].append([b,i])

ans = [None]*(n-1)
def rec(cur,color):
    cnt = 1
    for (to, j) in G[cur]:
        if cnt == color:
            cnt += 1
        ans[j] = cnt
        rec(to, cnt)
        cnt += 1
rec(0, 0)
print(max(ans))
print(*ans, sep="\n")

Measured memory_bytes: 71032
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int n;
	cin >> n;
	int a[100005];
	int count = 0;
	int counter = 0;
	for(int i=0;i<n;i++){
		cin >> a[i];
		if(a[i]%4 == 0){
			count++;
		}
		if(a[i]%2 == 0 && a[i]%4 == 2){
			counter++;
		}
	}
	string ans = "No";
	if(n%2 == 1 && count>=(n-1)/2){
		ans = "Yes";
	}
	if(n%2 == 1 && (count)+(counter)/2 >= (n-1)/2){
		ans = "Yes";
	}
	if (n%2 == 0 && count>=n/2){
		ans = "Yes";
	}
	if (n%2 == 0 && (count)+(counter)/2 >= n/2){
		ans = "Yes";
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

typedef long long LL;
const int N = 101;
const int V = 100001;

LL dp[N][V], w[N], v[N];

int main() {
    // freopen("a.txt", "r", stdin);
    int n, wl;
    cin >> n >> wl;
    for(int i = 1; i <= n; ++i) cin >> w[i] >> v[i];

    memset(dp, 0x3f, sizeof(dp));
    dp[0][0] = 0;
    for(int i = 1; i <= n; ++i) {
        for(int j = 0; j < V; ++j) {
            dp[i][j] = min(dp[i][j], dp[i - 1][j]);
            if(j >= v[i]) dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
        }
    }
    int res = 0;
    for(int i = V - 1; i >= 0; --i) {
        if(dp[n][i] <= wl) {
            res = i; break;
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 79104
#include<bits/stdc++.h>
#define N 1000007
#define P 1000000007
using namespace std;
int f[N];
int inc(int a,int b){a+=b;return a>=P? a-P:a;}
int main()
{
    int n,i,sum=0;scanf("%d",&n);
    if(n==1) return !printf("1");
    f[n]=n,f[n-1]=1ll*n*n%P;
    for(i=n-2;i;--i) sum=inc(sum,f[i+3]),f[i]=inc(inc(inc(f[i+1],1ll*(n-1)*(n-1)%P),sum),i+1);
    return !printf("%d",f[1]);
}


Measured memory_bytes: 4096