akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>

std::vector<unsigned> gaps;

unsigned insertion_sort(unsigned a[], unsigned n, unsigned gap = 1){
  unsigned count = 0;
  for(unsigned i = gap; i < n; i++){
    unsigned v = a[i];
    int j = i - gap;
    while(j >= 0 && a[j] > v){
      a[j+gap] = a[j];
      j -= gap;
      count++;
    }
    a[j+gap] = v;
  }
  return count;
}

void make_gap_table(unsigned n){
  unsigned h = 1;
  unsigned i = 1;
  while(h <= n){
    gaps.push_back(h);
    h = pow(4,i) + 3*pow(2,i-1) + 1;
    i++;
  }
}

void shell_sort(unsigned a[], unsigned n){
  make_gap_table(n);
  unsigned count = 0;
  for(int i=gaps.size()-1;i>=0;i--){
    count += insertion_sort(a,n,gaps[i]);
  }

  std::cout << gaps.size() << '\n';

  for(int i=gaps.size()-1;i;i--){
    std::cout << gaps[i] << ' ';
  }
  std::cout << gaps[0] << '\n';

  std::cout << count << '\n';
}

int main(){
  unsigned n;
  unsigned buf;
  std::vector<unsigned> a;
  std::cin >> n;
  for(unsigned i = 0; i < n; i++){
    std::cin >> buf;
    a.push_back(buf);
  }

  shell_sort(a.data(),a.size());
  for(auto &v : a){
    std::cout << v << '\n';
  }
}

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

#define rep(i,n) for(int i = 0;i<n;i++)
#define vv(Type,Name, n,m,d)vector<vector<Type>> Name(n, vector<Type>(m, d))
#define P pair
using namespace std;
using ll = long long;

int ctoi(char c) {
	switch (c) {
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default: return 0;
	}
}

int main(void) {

	ios::sync_with_stdio(false);
	cin.tie(0);

    int a = 0;
    string str;
    cin >> str;
    int len = str.length();
    rep(i, len) {
		a += ctoi(str[i]);

		a %= 9;

    }


	if (!a) cout << "Yes" << endl;
	else cout << "No" << endl;


	return 0;
}


Measured memory_bytes: 3776
#include<bits/stdc++.h>
using namespace std;
int min(int a,int b)
{
    return (a<b)?a:b;
}
int abso(int a)
{
    if(a<0)
    return a*(-1);
    return a;
}
int main()
{
    int n;
    cin>>n;
    int a[n],b[n];
    b[0]=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(i==1)
        b[i]=abso(a[i]-a[i-1]);
        else if(i>1)
        {
            b[i]=min(abso(a[i]-a[i-2])+b[i-2],b[i-1]+abso(a[i]-a[i-1]));
        }
        
    }
    cout<<b[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;


int main(){
    int n;
    cin >> n;
    int box[n][3];
    for(int i=0;i<n;i++){
        cin >> box[i][0] >> box[i][1] >> box[i][2];
    }
    vector<vector<ll>> dp(n, {0, 0, 0});

    for(int i=0;i<3;i++){
        dp[0][i] = box[0][i];
    }
    for(int i=1;i<n;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(j != k){
                    dp[i][k] = max(dp[i][k], dp[i-1][j]+box[i][k]);
                }
            }
        }
    }

    ll ans = 0;
    for(int i=0;i<3;i++){
        ans = max(ans, dp[n-1][i]);
    }
    cout << ans << endl;
    return 0;
}

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

namespace
{
const int MAX_N	= 100000;
int a[ MAX_N + 5 ];
int b[ MAX_N + 5 ];
}

int main( int argc, char *argv[] )
{
int i;
int N;
int H;
int iMaxA;
int iB;
int iCnt;
int X;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> N;
	cin >> H;
	for( i = 0; i < N; i++ )
	{
		cin >> a[ i ];
		cin >> b[ i ];
	}

	sort( a, a + N );
	sort( b, b + N );
	iMaxA = a[ N - 1 ];

	iB = 0;
	iCnt = 0;
	for( i = N - 1; i >= 0; i-- )
	{
		if( b[ i ] > iMaxA )
		{
			iCnt++;
			iB += b[ i ];
			if( iB >= H )
			{
				cout << iCnt << endl;

				return 0;
			}
		}
	}

	X = H - iB;
	if( X % iMaxA == 0 )
		cout << iCnt + X / iMaxA << endl;
	else
		cout << iCnt + X / iMaxA + 1 << endl;

	return 0;
}



Measured memory_bytes: 1024
N, M = map(int, input().split())
switch = [list(map(int, input().split())) for _ in range(M)]
P = list(map(int, input().split()))

ans = 0
for i in range(1<<N):
    cond = [0]*N
    for j in range(N):
        if 1&(i>>j):  # 右シフトして論理積（bit全探索）
            cond[j] = 1
    
    flag = True
    # print('cond: ', cond)
    for i in range(M):
        cnt = 0
        for j in switch[i][1:]:
            cnt +=  cond[j-1]
        if cnt%2 != P[i]:
            flag = False
            break
    # print('flag: ', flag)
    # print()
    ans += flag

print(ans)

Measured memory_bytes: 3064
from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))

yag = defaultdict(int)

for i in a:
    yag[i]+=1

result = 0
for i in yag.keys():
    t = yag[i]
    result += (t*(t-1))//2

for i in a:
    t = yag[i]
    print(result - (t*(t-1))//2 + ((t-1)*(t-2))//2)




Measured memory_bytes: 88140
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static int d;
	static final int MOD=(int)1e9+7;
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		String s=scan.next();
		d=scan.nextInt();
		dp=new long[s.length()][2][d];
		for(long[][] dd:dp) {
			for(long[] ddd:dd) Arrays.fill(ddd,-1);
		}
		System.out.println((go(0,0,0,s)-1+MOD)%MOD);
	}
	static long[][][] dp;
	public static long go(int at, int less, int rem, String s) {
		if(at==s.length()) {
			return rem==0?1:0;
		}
		if(dp[at][less][rem]!=-1) return dp[at][less][rem];
		long res=0L;
		int end=(less==1)?9:s.charAt(at)-'0';
		for(int i=0;i<=end;i++) {
			int nxtless=less;
			if(i<end) nxtless=1;
			res=(MOD+res+go(at+1,nxtless,(rem+i)%d,s)%MOD)%MOD;
		}
		return dp[at][less][rem]=res%MOD;
	}
}

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

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll now = a[0],ans=0;
    REP(i,n-1){
        if(a[i]>=now){
            now = a[i];
        }else{
            ans+=(now-a[i]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4736
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int N;
int A[2][100];

int calc(int i)
{
	int res = 0;
	int k = 0;
	for (int j = 0; j < N; j++) {
		res += A[k][j];
		if (i == j) {
			k++;
			res += A[k][j];
		}
	}
	return res;
}

void solve()
{
	int max = 0;
	for (int i = 0; i < N; i++) {
		int tmp = calc(i);
		max = tmp > max ? tmp : max;
	}
	cout << max << endl;
}

int main()
{
	cin >> N;
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < N; j++) {
			cin >> A[i][j];
		}
	}
	solve();
	return 0;
}

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

int main() {
  ll n, i, a, even = 0, odd = 0, check = 0, cnt = 0;
  cin >> n;
  for (i = 0; i < n; ++i) {
    cin >> a;
    if (a % 2 == 0) {
      ++even;
    } else {
      ++odd;
    }
  }
  if (even == n) {
    cout << "second"
         << "\n";
  } else {
    cout << "first"
         << "\n";
  }
  return 0;
}

Measured memory_bytes: 256
let N=stdin.ReadLine() |> int
let B=stdin.ReadLine().Split() |> Array.map int
let rec f i sum=
    if i=N then sum
    elif i=0 then f (i+1) (sum+B.[i]) 
    elif i=N-1 then f (i+1) (sum+B.[N-2])
    else B.[(i-1)..i] |>Array.min |> fun x->f (i+1) (sum+x)
f 0 0 |> stdout.WriteLine

Measured memory_bytes: 11220
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        String n = sc.next();
        sc.close();

        // 主処理
        int sum = 0;
        for (String s : n.split("")) {
            int num = Integer.parseInt(s);
            sum += num;
        }
        boolean judge = sum % 9 == 0;
        String result = judge ? "Yes" : "No";

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 54380
use List::Util qw(max);
my $n = <>;
my @masu = glob<>;
my $ans = 0;
my $val = 0;
@masu = reverse(@masu);
my @max = (0);

for(my $i = 1; $i <= $#masu; $i++){
	if($masu[$i-1] <= $masu[$i]){
    	$val++;
    } else {
    	$val = 0;
    }
    push @max, $val;
}
print List::Util::max(@max);


Measured memory_bytes: 27136
#include<bits/stdc++.h>
using namespace std;
int a,b;
int main()
{
	scanf("%d%d",&a,&b);
	if(a!=1&&b!=1)
		printf("%d\n",1);
	if(a!=2&&b!=2)
		printf("%d\n",2);
	if(a!=3&&b!=3)
		printf("%d\n",3);
	return 0;
}

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

class Program
{
    public enum Color
    {
        WHITE,
        BLACK
    }
    public struct P
    {
        public char key;
        public int x;
        public int y;
        public Color color;
        public P(int y,int x,char key)
        {
            this.key = key;
            this.x = x;
            this.y = y;
            color = Color.WHITE;
        }
    }
    static void Main(string[] args)
    {
        var hw = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var gred = new string[hw[0]];
        for (var i = 0; i < hw[0]; i++)
            gred[i] = ReadLine();
        var ps = new P[hw[0], hw[1]];
        for (var i = 0; i < hw[0]; i++)
            for (var j = 0; j < hw[1]; j++)
                ps[i, j] = new P(i, j,gred[i][j]);
        var dp = new long[hw[0], hw[1]];
        var queue = new Queue<P>();
        queue.Enqueue(ps[0, 0]);
        dp[0, 0] = 1;
        ps[0, 0].color = Color.BLACK;
        while (queue.Count != 0)
        {
            var p = queue.Dequeue();
            if (p.x != hw[1] - 1 && ps[p.y,p.x+1].key == '.'&&ps[p.y,p.x+1].color==Color.WHITE)
            {
                queue.Enqueue(ps[p.y,p.x+1]);
                ps[p.y,p.x+1].color = Color.BLACK;
            }
            if (p.y != hw[0] - 1 && ps[p.y + 1, p.x].key == '.' && ps[p.y + 1, p.x].color == Color.WHITE)
            {
                queue.Enqueue(ps[p.y + 1, p.x]);
                ps[p.y+1,p.x].color = Color.BLACK;
            }
            var sum = 0L;
            if (p.y != 0) sum += dp[p.y - 1, p.x];
            if (p.x != 0) sum += dp[p.y, p.x - 1];
            dp[p.y, p.x] = sum==0?1:sum%MOD;
        }
        WriteLine(dp[hw[0] - 1, hw[1] - 1]);
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}


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

using namespace std;

using ll = long long;

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

    int n;

    cin >> n;
    vector<int> a(n + 2, 0);
    for (int i = 0; i < n; ++i)
        cin >> a[i + 1];

    ll sum = 0;
    for (int i = 1; i <= n + 1; ++i)
        sum += abs(a[i] - a[i - 1]);

    for (int i = 1; i <= n; ++i) {
        cout << sum - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i])
            + abs(a[i + 1] - a[i - 1]) << '\n';
    }

    return 0;
}


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

string s;
vector< vector<ll> > dp;

ll q(int l, int r) {
    if (dp[l][r] != -1) return dp[l][r];
    if (l == 0) dp[l][r] = 0;
    if (s[l-1] == s[r-1]) {
        ll res = q(l-1, r-1) + 1;
        if (res <= r-l) dp[l][r] = res;
        else dp[l][r] = 0;
    }
    else dp[l][r] = 0;
    return dp[l][r];
}

int main() {
    int n;
    cin >> n >> s;
    dp.resize(n+5, vector<ll>(n+5, -1));
    ll maxi = 0;
    for (int i = n; i >= 0; i--) {
        for (int j = i-1; j > 0; j--) {
            ll res = q(j, i);
            maxi = max(maxi, res);
        }
    }
    cout << maxi << endl;
    return 0;
}

Measured memory_bytes: 196480
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int x,y,z,i,a;
    while(~scanf("%d %d %d",&x,&y,&z))
    {
        a=0;
        if(x<=z)
        {
            for(i=0;i<=y;i++)
            {
                if(x+i==z)
                {
                    a=1;
                }
            }
        }
        if(a==1)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define S second
#define F first
#define pb push_back

using namespace std;

typedef long long llong;

const int MXN = (int)2e5 + 7;
const int MOD = (int)1e9 + 7;
const llong INF = 2e18 + 7;

llong h, ans;
int t;

llong binpow(llong a, llong n)
{
  if(!n) return 1;
  if(n & 1){
    return binpow(a, n - 1) * a;
  }else{
    llong b = binpow(a, n / 2);
    return b * b;
  }
}

int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  #endif
  cin >> h;
  for(int i = 0; i <= (int)log2(h); i++){
    ans += binpow(2, i);
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let 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")
    };
}

//

fn run() {
    input! {
        n: usize,
        k: usize,
        e: [(usize1, usize1); n - 1],
    }
    let mut g = vec![vec![]; n];
    for &(a, b) in &e {
        g[a].push(b);
        g[b].push(a);
    }
    let mut ans = 0;
    let r = k / 2;
    if k % 2 == 0 {
        for i in 0..n {
            let mut cnt = 0;
            let mut stack = vec![(i, i, 0)];
            while let Some((v, p, d)) = stack.pop() {
                if d > r {
                    continue;
                }
                cnt += 1;
                for &u in &g[v] {
                    if u != p {
                        stack.push((u, v, d + 1));
                    }
                }
            }
            ans =std::cmp::max(ans, cnt);
        }
    } else {
        for &(a, b) in &e {
            let mut cnt = 0;
            let mut stack = vec![(a, b, 0), (b, a, 0)];
            while let Some((v, p, d)) = stack.pop() {
                if d > r {
                    continue;
                }
                cnt += 1;
                for &u in &g[v] {
                    if u != p {
                        stack.push((u, v, d + 1));
                    }
                }
            }
            ans = std::cmp::max(ans, cnt);
        }
    }
    println!("{}", n - ans);
}

fn main() {
    run();
}


Measured memory_bytes: 4352
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var NK = Sarray();
            var N = NK[0];
            var K = NK[1];
            var ans = 0L;
            ans = (N / K) * (N / K) * (N / K);
            if (K % 2 == 0 && K / 2 <= N)
            {
                var sel = (N - K / 2) / K + 1;
                ans += sel * sel * sel;
            }
            WriteLine(ans);
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include <sstream>
#include <stdio.h>
//#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))

using namespace std;


int main(void)
{
	lli x, y; cin >> x >> y;
	lli ans = abs(x) + abs(y) + 10;
	if (x <= y)ans = min(ans, y - x);
	if (-x <= y)ans = min(ans, y + x + 1);
	if(x<=-y)ans = min(ans, abs(y + x) + 1);
	if (-x <= -y)ans = min(ans, 2 - y + x);

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {

	int n, m, i=1, j, k, l = 0, sumt = 0, sumh = 0;
	int taro[101], hanako[101], co1[101], co2[101], ans[202];

	for (i = 0; i < 202; i++) {
		ans[i] = 101;
	}

	while (i) {

		scanf("%d %d", &n, &m);

		if (n == 0 && m == 0)
			break;

		for (i = 0; i < n; i++) {
			scanf("%d", &taro[i]);
			co1[i] = taro[i];
		}

		for (i = 0; i < m; i++) {
			scanf("%d", &hanako[i]);
			co2[i] = hanako[i];
		}

		for (i = 0; i < n; i++) {

			for (j = 0; j < m; j++) {

				co1[i] = hanako[j];
				co2[j] = taro[i];

				for (k = 0; k < n; k++)
					sumt += co1[k];
				for (k = 0; k < m; k++)
					sumh += co2[k];

				if (sumt == sumh && ((co1[i] + co2[j]) < (ans[l] + ans[l + 1]))) {
					ans[l] = taro[i];
					ans[l + 1] = hanako[j];
				}
				sumt = 0;
				sumh = 0;

				for (k = 0; k < n; k++)
					co1[k] = taro[k];
				for (k = 0; k < m; k++)
					co2[k] = hanako[k];
			}
		}
		l = l + 2;
         }

	for (i = 0; i < l; i = i + 2) {
		if (ans[i] == 101 && ans[i+1] == 101)
			printf("-1\n");
		else
			printf("%d %d\n", ans[i], ans[i + 1]);
	}
	
	return 0;
}

Measured memory_bytes: 616
package main

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

func main() {
	N := ReadInt()
	S := ReadString()

	dp := make([][]int, N+1)
	for i := 0; i < N+1; i++ {
		dp[i] = make([]int, N+1)
	}
	for i := N - 1; i >= 0; i-- {
		for j := N - 1; j >= 0; j-- {
			if S[i] == S[j] {
				dp[i][j] = 1 + dp[i+1][j+1]
			}
		}
	}

	max := 0
	for i := 0; i < N-1; i++ {
		for j := i + max + 1; j+max < N; j++ {
			if dp[i][j] > max {
				max = Min(dp[i][j], j-i)
			}
		}
	}
	fmt.Println(max)
}

func Min(xs ...int) int {
	min := xs[0]
	for _, x := range xs[1:] {
		if min > x {
			min = x
		}
	}
	return min
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 209480
a = int(input())
b = int(input())
c = int(input())
x = int(input())

count = 0
for k in range(a+1):
  if x-500*k < 0:
    break
  for j in range(b+1):
    if x-500*k-100*j < 0:
      break
    if (x-500*k-100*j)//50 > c:
      continue
    count += 1
print(count)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+9;
string s[N];
int n;
long long ans=0;
long long C(int x,int y){
    if(x==1)return 0;
    return 1ll*x*(x-1)/2;
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++)cin>>s[i],sort(s[i].begin(),s[i].end());
    sort(s+1,s+n+1);
  //  for(int i=1;i<=n;i++)cout<<s[i]<<endl;
    for(int i=1;i<=n;i++){
        int j=i;
        while(s[i]==s[j]&&j<=n)j++;
        ans+=C(j-i,2);
        i=j-1;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 8064
import collections


class Dice():
    def __init__(self, labels):
        self.__pip = labels
    
    def roll_e(self): # 0352 → 3520
        self.__pip[0], self.__pip[3], self.__pip[5], self.__pip[2] = \
            self.__pip[3], self.__pip[5], self.__pip[2], self.__pip[0]

    def roll_n(self): # 0154 → 1540
        self.__pip[0], self.__pip[1], self.__pip[5], self.__pip[4] = \
            self.__pip[1], self.__pip[5], self.__pip[4], self.__pip[0]

    def roll_s(self): # 0451 →  4510
        self.__pip[0], self.__pip[4], self.__pip[5], self.__pip[1] = \
            self.__pip[4], self.__pip[5], self.__pip[1], self.__pip[0]

    def roll_w(self): # 0253 → 2530
        self.__pip[0], self.__pip[2], self.__pip[5], self.__pip[3] = \
            self.__pip[2], self.__pip[5], self.__pip[3], self.__pip[0]

    def roll_nn(self): # 0154 → 5401
        self.roll_n()
        self.roll_n()

    def turn_dice(self): # 1243 → 2431
        self.__pip[1], self.__pip[2], self.__pip[4], self.__pip[3] = \
            self.__pip[2], self.__pip[4], self.__pip[3], self.__pip[1]

    def roll_dice(self, c):
        if c != self.__pip[0]:
            if c == self.__pip[1]:
                self.roll_n()
            elif c == self.__pip[2]:
                self.roll_w()
            elif c == self.__pip[3]:
                self.roll_e()
            elif c == self.__pip[4]:
                self.roll_s()
            else:
                self.roll_nn()
    
    def get_top(self):
        return self.__pip[0]

    def get_front(self):
        return self.__pip[1]

    def get_right(self):
        return self.__pip[2]
        
    def get_left(self):
        return self.__pip[3]
        
    def get_behind(self):
        return self.__pip[4]
        
    def get_bottom(self):
        return self.__pip[5]
    
    def judge(self, dice_2):
        top = dice_2.get_top()
        self.roll_dice(top)
        for i in range(4):
            if dice_2.get_front() == self.__pip[1]:
                break
            if i == 3:
                return False
            self.turn_dice()
        if dice_2.get_right() != self.__pip[2] or \
            dice_2.get_left() != self.__pip[3] or \
            dice_2.get_behind() != self.__pip[4] or \
            dice_2.get_bottom() != self.__pip[5]:
            return False
        return True
       
        
def main():
    lst1 = list(input().split())
    lst2 = list(input().split())
    if len(set(lst1) ^ set(lst2)) != 0:
        print('No')
        return
    c = collections.Counter(lst2)
    dice1 = Dice(lst1)
    dice2 = Dice(lst2)
    dice2.roll_dice(c.most_common()[-1][0]) # 出現頻度の少ない数字の面を上にする
    if dice1.judge(dice2):
        print('Yes')
    else:
        print('No')
        

if __name__ == "__main__":
    main()



Measured memory_bytes: 5988
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pli pair<ll,int>
#define pii pair<int,int>
using namespace std;

const ll INF = 1e18;
vector<pii> dir = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int R, C, K;
	cin >> R >> C >> K;
	int xa, ya, xb, yb;
	cin >> xa >> ya >> xb >> yb;
	--xa; --ya; --xb; --yb;
	bool mp[R][C], done[R][C][4];
	ll dp[R][C][4];
	for (int i=0; i<R; i++) {
		string s;
		cin >> s;
		for (int j=0; j<C; j++) {
			mp[i][j] = (s[j] == '.');
			for (int d=0; d<4; d++) {
				dp[i][j][d] = INF;
				done[i][j][d] = false;
			}
		}
	}
	priority_queue<pair<pli,pii>, vector<pair<pli,pii>>, greater<pair<pli,pii>>> pq;
	for (int d=0; d<4; d++) {
		pq.push({{0, d}, {xa, ya}});
		dp[xa][ya][d] = 0;
	}
	while (!pq.empty()) {
		int x = pq.top().second.first, y = pq.top().second.second;
		int cur = pq.top().first.second;
		pq.pop();
		if (done[x][y][cur]) continue;
		done[x][y][cur] = true;
		for (int d=0; d<4; d++) {
			int xx = x+dir[d].first;
			int yy = y+dir[d].second;
			int add;
			if (cur == d) add = 1;
			else {
				int tmp = dp[x][y][cur]%K;
				if (!tmp) add = 0;
				else add = K - tmp;
				add++;
			}
			if (0<=xx && xx<R && 0<=yy && yy<C && mp[xx][yy] && dp[xx][yy][d] > dp[x][y][cur] + add) {
				dp[xx][yy][d] = dp[x][y][cur] + add;
				pq.push({{dp[xx][yy][d], d}, {xx, yy}});
			}
		}
	}
	/*
	for (int d=0; d<4; d++) {
		for (int i=0; i<R; i++) {
			for (int j=0; j<C; j++) {
				cout << dp[i][j][d] << ' ';
			}
			cout << '\n';
		}
		cout << '\n';
	}
	*/
				
	ll ans = INF;
	for (int d=0; d<4; d++) {
		if (dp[xb][yb][d] != INF) {
			ans = min(ans, (ll)ceil((ld)dp[xb][yb][d]/K));
		}
	}
	if (ans == INF) cout << -1;
	else cout << ans;
}

Measured memory_bytes: 45668
H, W = map(int, input().split())
S = [input() for _ in range(H)]

dy = [0, 1, 0, -1]
dx = [1, 0, -1, 0]
INF = 10**9 + 7

def bfs(y, x):
    res = 0
    q = [[y,x]]
    D = [[INF for _ in range(W)] for _ in range(H)]
    D[y][x] = 0
    while len(q):
        y, x = q.pop(0);
        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]
            if not (0 <= ny <= H-1 and 0 <= nx <= W-1): continue
            if S[ny][nx] == '#': continue
            if D[ny][nx] > D[y][x] + 1:
                D[ny][nx] = D[y][x] + 1
                q.append([ny,nx])
                res = max(res, D[ny][nx])
    return res

ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == '#': continue
        ans = max(ans, bfs(i,j))
print(ans)


Measured memory_bytes: 46832
local mmi, mma = math.min, math.max
local mfl, mce = math.floor, math.ceil
local n, m, r = io.read("*n", "*n", "*n")
local t = {}
for i = 1, r do
  t[i] = io.read("*n")
end
local inf = 1000000007 * 1000
local len = {}
for i = 1, n do
  len[i] = {}
  for j = 1, n do
    len[i][j] = i == j and 0 or inf
  end
end
for i = 1, m do
  local a, b, c = io.read("*n", "*n", "*n")
  len[a][b], len[b][a] = c, c
end
for k = 1, n do
  for i = 1, n do
    for j = 1, n do
      len[i][j] = mmi(len[i][j], len[i][k] + len[k][j])
    end
  end
end

local function getpattern(n, patall, idx)
  local used = {}
  local retary = {}
  local div = patall
  for i = 1, n do used[i] = false end
  for i = n, 1, -1 do
    div = mfl(div / i)
    local v_idx = mfl(idx / div)
    idx = idx % div
    local tmp_idx = 0
    for j = 1, n do
      if not used[j] then
        if tmp_idx == v_idx then
          table.insert(retary, j)
          used[j] = true
          break
        else
          tmp_idx = tmp_idx + 1
        end
      end
    end
  end
  return retary
end
local tot = 1
for i = 1, r do
  tot = tot * i
end
local ret = inf
for i = 0, tot - 1 do
  local pat = getpattern(r, tot, i)
  local z = 0
  for i = 1, r - 1 do
    z = z + len[t[pat[i]]][t[pat[i + 1]]]
  end
  if z < ret then ret = z end
end
print(ret)


Measured memory_bytes: 3756
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();

        System.out.println(num(B,C,D) - num(A-1,C,D));
    }

    static long gcd(long a, long b) {
        if(b == 0) {
            return a;
        } else {
            return gcd(b, a % b);
        }
    }

    // cでもdでも割れない個数
    static long num(long n, long c, long d) {
        // 最大公約数
        long G = gcd(c,d);
        // 最小公倍数
        long L = c / G * d;

        return n - (n/c) - (n/d) + (n/L);
    }
}


Measured memory_bytes: 35628
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define st first
#define nd second
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;++i)
#define endl '\n'
int mx=2e4+5;
int main(){
	
	int a,b,c;
  	cin >> a >> b >> c;
  if(a+b+c>=22)cout<<"bust"<<endl;
  else cout<<"win"<<endl;

} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int N;
  cin >> N;
  int n;
  string s;
  string S;
  while(N != 0){
    n = N % 26;
    N = (N - n) / 26;
    if(n == 0){
      s += 'z';
      N -= 1;
    }
    else if(n == 1){
      s += 'a';
    }
    else if(n == 2){
      s += 'b';
    }
    else if(n == 3){
      s += 'c';
    }
    else if(n == 4){
      s += 'd';
    }
    else if(n == 5){
      s += 'e';
    }
    else if(n == 6){
      s += 'f';
    }
    else if(n == 7){
      s += 'g';
    }
    else if(n == 8){
      s += 'h';
    }
    else if(n == 9){
      s += 'i';
    }
    else if(n == 10){
      s += 'j';
    }
    else if(n == 11){
      s += 'k';
    }
    else if(n == 12){
      s += 'l';
    }
    else if(n == 13){
      s += 'm';
    }
    else if(n == 14){
      s += 'n';
    }
    else if(n == 15){
      s += 'o';
    }
    else if(n == 16){
      s += 'p';
    }
    else if(n == 17){
      s += 'q';
    }
    else if(n == 18){
      s += 'r';
    }
    else if(n == 19){
      s += 's';
    }
    else if(n == 20){
      s += 't';
    }
    else if(n == 21){
      s += 'u';
    }
    else if(n == 22){
      s += 'v';
    }
    else if(n == 23){
      s += 'w';
    }
    else if(n == 24){
      s += 'x';
    }
    else if(n == 25){
      s += 'y';
    }
  }
  int s_size = s.size();
  for(int i = s_size - 1;i >= 0;i--){
    S += s.at(i);
  }
  cout << S << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

int wei; // 持てる最大の重さ
int n; // お宝の数
int v[1001]; // お宝の価値
int w[1001]; // お宝の重さ
 // グローバル配列は0で初期化されている
int dp[1001][1001]; //メモテーブル

int max_value(int i, int j) {
  int value;

  if( dp[i][j] >= 0 ){
    return dp[i][j];
    //すでに１回は調べている
  }
 
  if (i == n) {
    // 品物がもう残っていないときは、価値の和の最大値は0で確定
    //もうお宝がないつまり、価値は0
    value = 0;
  } else if (j < w[i]) {
    //風呂敷が持てる重さを超えてしまう
    // 残りの容量が足りず品物iを入れられないので、入れないパターンだけ処理
    // i+1 以降の品物のみを使ったときの最大値をそのままこの場合の最大値にする
    value = max_value(i + 1, j);
  } else {
    //左がお宝を入れない、右がお宝を入れた場合
    // 品物iを入れるか入れないか選べるので、両方試して価値の和が大きい方を選ぶ
    value = max( max_value(i + 1, j), max_value(i + 1, j - w[i]) + v[i] );
  } 
  return dp[i][j] = value;
  //メモに記憶させる
}

void max_weight( int ans ){

  int w_min;
   
  for (int i = wei -1 ; i >= 0 ; i--){
    if( ans != max_value( 0 , i ) ){
         w_min = i + 1;
         break;
    }
  }
  cout << w_min << endl;  
}


int main(void){

  int cnt = 1;
  while( cin >> wei ){
    memset( dp , -1 , sizeof(dp) );
    //まだ調べてないところを-1で初期化
    if( wei == 0 )break;
    cin >> n;
    char ten;
    for( int i = 0 ; i < n ; i++ ){
      cin >> v[i] >> ten >> w[i];
    }
    cout << "Case " << cnt << ":" << endl;
    int ans = max_value( 0 , wei );
    cout << ans << endl;
    max_weight(ans);
    cnt++;
  }
  return 0;
}

Measured memory_bytes: 5132
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
struct Point { long double px, py; };
Point Minus(Point p1, Point p2) {
	Point p3;
	p3.px = p1.px - p2.px;
	p3.py = p1.py - p2.py;
	return p3;
}
long double norm(const Point& a) { return a.px * a.px + a.py * a.py; }
long double dot(const Point& a, const Point& b) { return a.px * b.px + a.py * b.py; }
long double crs(const Point& a, const Point& b) { return a.px * b.py - a.py * b.px; }
int ccw(Point p0, Point p1, Point p2) {
	Point a = Minus(p1, p0), b = Minus(p2, p0);
	if (crs(a, b) > 1e-10) return 1;
	if (crs(a, b) < -1e-10) return -1;
	if (dot(a, b) < -1e-10) return 2;
	if (norm(a) < norm(b)) return -2;
	return 0;
}
bool is_convex(vector<Point> v) {
	if (v.size() < 3) return false;
	int s = -3;
	for (int i = 0; i < v.size(); i++) {
		int r = ccw(v[i], v[(i + v.size() - 1) % v.size()], v[(i + 1) % v.size()]);
		if (abs(r) == 1 && s == -3) s = r;
		if (s * r == -1) return false;
	}
	return true;
}
int main() {
	vector<Point>V; Point C; char c;
	while (cin >> C.px >> c >> C.py) {
		V.clear();
		V.push_back(C);
		for (int i = 0; i < 3; i++) {
			cin >> c >> C.px >> c >> C.py;
			V.push_back(C);
		}
		bool G = is_convex(V);
		if (G == true)cout << "YES" << endl;
		if (G == false)cout << "NO" << endl;
	}
	return 0;
}

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

int main()
{
    int w,a,b;
    cin>>w>>a>>b;
    if(a<b){
        cout<<max(0,b-(a+w))<<endl;
    }
    else cout<<max(0,a-(b+w))<<endl;

    
}

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

#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)

using namespace std;

template <class T>
using vec = std::vector<T>;
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL<<60;


const int MAX_H=10000;
const int MAX_N=1000;

int A,B,M,tmp_a,tmp_b,tmp_coupon;
vec<int>  a(100010,1000000),b(100010,1000000),val(10010,1000000);
int x,y,c;

int main()
{

    cin>>A>>B>>M;
    int min_a=100000;
    int min_b=100000;
    rep(i,A)
    {
        cin>>tmp_a;
        a[i]=tmp_a;
        min_a=min(min_a,tmp_a);
    }
    rep(i,B)
    {
        cin>>tmp_b;
        b[i]=tmp_b;
        min_b=min(min_b,tmp_b);
    }
    int tmp_min=min_a+min_b;

    rep(i,M)
    {
        cin>>x>>y>>c;
        tmp_min=min(tmp_min,a[x-1]+b[y-1]-c);
    }
    cout<<tmp_min<<endl;
    return 0;

}




Measured memory_bytes: 1024
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)

now = A[0]
tateyoko = [0, 0]
count = 0
nowflag = False
for i in range(1, N):
  if (A[i] == now) and (not nowflag):
    tateyoko[count] = now
    count += 1
    nowflag = True
  else:
    nowflag = False
  if count == 2:
    break
  now = A[i]
  
print(tateyoko[0] * tateyoko[1])


Measured memory_bytes: 14224
require 'pp'

N = readline.chomp.to_i

$edges = Hash.new {|h,k| h[k] = [] }
(N-1).times do |i|
  i,j,w = readline.chomp.split.map(&:to_i)
  $edges[i-1] << [j-1,w]
  $edges[j-1] << [i-1,w]
end

$colors = Array.new(N,nil)
$colors[0] = 0
stack = [0]

while stack.size > 0
  i = stack.pop
  $edges[i].each do |j,w|
    next if $colors[j] != nil
    if w % 2 == 0
      $colors[j] = $colors[i]
      stack << j
      # dfs(j)
    else
      $colors[j] = ($colors[i]+1)%2
      stack << j
      #dfs(j)
    end
  end
end

#dfs(0)
puts $colors


Measured memory_bytes: 33788
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
int main(){

    int n;
    cin >> n;
    while(n > 0){
        char a[2000] = {0};
        char b[2000] = {0};
        scanf("%s%s",a,b);
        int len_a = 0,len_b = 0;
        //長さを測る
        for(int i = 0; a[i] != 0; i++) len_a++;
        for(int i = 0; b[i] != 0; i++) len_b++;
        //もし80桁を超えてたらoverflowと出力
        if(len_a > 80 || len_b > 80){
            printf("overflow\n");
        }
        //80桁を超えてなかったら
        else{
            char ans[120] = {0};
            //aを逆向きに入れ替える
            for(int i = 0; i < len_a/2; i++){
                swap(a[i],a[len_a-i-1]);
            }
            //bを逆向きに入れ替ええる
            for(int i = 0; i < len_b/2; i++){
                swap(b[i],b[len_b-i-1]);
            }
            //aとbで長い方の長さをとる
            int len = max(len_a,len_b);
            //ここで足し算をする
            for(int i = 0; i < len; i++){
                if(ans[i] != 0){
                    if(a[i] == 0 || b[i] == 0)
                        ans[i] += a[i] + b[i] - '0';
                    else ans[i] += a[i] + b[i] - '0' - '0';

                }
                else if(a[i] == 0 || b[i] == 0) ans[i] += a[i] + b[i];
                else ans[i] += a[i] + b[i] - '0';
                if(ans[i] >= 58){
                    ans[i+1]+='1';
                    ans[i] -= 10;
                }
            }
            //このままではansが逆向きなので入れ替える
            for(int i = 0; i < strlen(ans)/2; i++){
                swap(ans[i],ans[strlen(ans)-i-1]);
            }

            int len_ans = 0;
            //ansの長さを測る
            for(int i = 0; ans[i] != 0; i++) len_ans++;
            //もし80桁を超えていたらoverflowと出力する
            if(len_ans > 80) printf("overflow");
            //それ以外なら一文字ずつ出力
            else for(int i = 0; ans[i] != 0; i++) printf("%c",ans[i]);
            printf("\n");
        }
        n--;
    }

    return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
const int MOD = 1000000007;
int N,M,L;
char s[MAXN];
bool flag = 0;
int f[MAXN][2],dp[MAXN],sum[MAXN][2];
int inc(int a,int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
    return 1LL * a * b % MOD;
}
void update(int &x,int y) {
    x = inc(x,y);
}
void Solve1() {
    int ans = 0;
    f[1][1] = 1;f[1][0] = 1;
    for(int i = 2 ; i <= N ; ++i) {
	f[i][0] = f[i - 1][1];
	f[i][1] = inc(f[i - 1][1],f[i - 1][0]);
    }
    ans = inc(f[N][0],f[N][1]);
    memset(f,0,sizeof(f));
    f[1][0] = 1;
    for(int i = 2 ; i < N ; ++i) {
	f[i][0] = f[i - 1][1];
	f[i][1] = inc(f[i - 1][1],f[i - 1][0]);
    }
    ans = inc(ans,MOD - f[N - 1][1]);
    out(ans);enter;
}
void Solve2() {
    dp[0] = 1;sum[0][0] = 1;
    for(int i = 1 ; i <= N ; ++i) {
	if(i >= 2) {
	    int t = sum[i - 2][i & 1];
	    if(i > L + 1) update(t,MOD - sum[i - L - 2][i & 1]);
	    dp[i] = t;
	}
	sum[i][0] = sum[i - 1][0];sum[i][1] = sum[i - 1][1];
	sum[i][i & 1] = inc(sum[i][i & 1],dp[i]);
	
    }
    int ans = dp[N];
    for(int i = 1 ; i <= L ; i += 2) {
	update(ans,mul(i,dp[N - i - 1]));
    }
    out(ans);enter;
}
void Init() {
    read(N);read(M);
    scanf("%s",s + 1);
    while(M >= 1 && s[M] == s[1]) --M;
    L = N;
    if(M == 0) flag = 1;
    else {
	for(int i = 1 ; i <= M ; ++i) {
	    if(s[i] != s[1]) continue;
	    else {
		int j = i;
		while(s[j + 1] == s[1]) ++j;
		int t = j - i + 1;
		if(i == 1) {
		    if(t % 2 == 0) L = min(L,t + 1);
		    else L = min(L,t); 
		}
		else {
		    if(t % 2 == 1) L = min(L,t);
		}
		i = j;
	    }
	}
    }
    if(L == N) flag = 1;
    if(flag) Solve1();
    else Solve2();
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Init();
}


Measured memory_bytes: 4352
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stdlib.h>
#include <list>
#include <queue>
#include <map>
#include <stack>
#include <set>
#define inf 0x3f3f3f3f
#define PI acos(double(-1))
using namespace std;

typedef long long ll;

int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    int i=0;
    while(i<=10000)
    {
        if(a%2||b&1||c&1)
            break;
        int x,y,z;
        a/=2,b/=2,c/=2;
        x=b+c,y=a+c,z=a+b;
        a=x,b=y,c=z;
        i++;
    }
    if(i==10001)
        cout << "-1" << endl;
    else
        cout << i << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a,b;
    int i,coun=0;
    cin>>a>>b;
    for(i=0;i<3;i++)
        if(a[i]==b[i]) coun++;
    cout<<coun<<endl;
    return 0;
}


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




    int main(){
        int a, b;
        std::cin >> a >> b;
        int ans = 0;
        int outlet = 1;
        while (outlet < b)
        {
            --outlet;
            outlet += a;
            ++ans;
        }
        std::cout << ans << "\n";
        return 0;
    }


Measured memory_bytes: 256
from math import ceil
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

def f(S,v):
    if S:
        res = []
        for i in range(len(S)):
            res += f(S[:i] + S[i+1:], 10 * ceil(v / 10) + S[i])
        return res
    else:
        return [v]
ans = min(f([a,b,c,d,e],0))
print(ans)

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  int a;
  for(int i = 0;i < N - 1;i++){
    cin >> a;
    a = a-1;
    vec[a]++;
  }
  for(int i = 0;i < N;i++){
    cout << vec[i] << endl;
  }
}
    

Measured memory_bytes: 4048
from fractions import gcd
N,K = list(map(int, input().split()))

S = [0]*(K+1)
ans = [0]*(K+1)

for i in range(K):
    n = K - i
    yakusu = K//n
    s = pow(yakusu,N,1000000007)
    for j in range(2*n,K+1,n):
        s -= S[j]
    S[n] = s%1000000007
    ans[n] = s*n%1000000007



print(sum(ans)%1000000007)



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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef long long lli;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, str>> vpls;
typedef vector<tuple<str, ll, ll>> vtsl;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

//実行部
void Main()
{
  ll n, h, w; cin >> n >> h >> w;
  fin((n - h + 1) * (n - w + 1))
  return;
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, a;
	ll x[114], y[114], h[114];
	cin>>n;
	REP(i, n){
		cin>>x[i]>>y[i]>>h[i];
		if(h[i]){
			a=i;
		}
	}
	for(ll c1=0; c1<=100; ++c1){
		for(ll c2=0; c2<=100; ++c2){
			for(ll H=h[a]; H<=h[a]+200; ++H){
				bool ok=true;
				REP(i, n){
					if(h[i]){
						if(H!=h[i]+abs(x[i]-c1)+abs(y[i]-c2)){
							ok=false;
							i=n;
						}
					}
					else if(H>abs(x[i]-c1)+abs(y[i]-c2)){
						ok=false;
						i=n;
					}
				}
				if(ok){
					cout<<c1<<' '<<c2<<' '<<H<<'\n';
					return 0;
				}
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int K = sc.nextInt();
        String S = sc.next();

        if (S.length() <= K) {
            System.out.println(S);
        } else {
            System.out.println(S.substring(0, K) + "...");
        }
    }
}


Measured memory_bytes: 38588
#include <iostream>
#include <vector>
#include <bitset>

using namespace std;
const int t = 10000;

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<int>> board(h, vector<int>(w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int x;
            cin >> x;
            board[i][j] += x;
        }
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int x;
            cin >> x;
            board[i][j] -= x;
        }
    }

    vector<vector<bitset<20000>>> dp(h, vector<bitset<20000>>(w));
    dp[0][0][board[0][0] + t] = true, dp[0][0][-board[0][0] + t] = true;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int now = abs(board[i][j]);
            if (i > 0) {
                dp[i][j] |= (dp[i - 1][j] << now);
                dp[i][j] |= (dp[i - 1][j] >> now);
            }
            if (j > 0) {
                dp[i][j] |= (dp[i][j - 1] << now);
                dp[i][j] |= (dp[i][j - 1] >> now);
            }
        }
    }

    int ret = 1145141919;
    for (int i = 0; i < 20000; i++) {
        if (dp[h - 1][w - 1][i])ret = min(ret, abs(t - i));
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 16128
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    S = input()
    T = input()
    if S == T[:-1]:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()


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

using namespace std;

#define REP(i,m) for(ll i=0; i<m; i++)
#define FOR(i,n,m) for(ll i=n; i<m; i++)
#define INF 1000000007
#define INFL (1LL << 60)
#define MOD 998244353
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

int main(){
	ll a, b;
	cin >> a >> b;
	a--;
	ll am = a/4*4;
	ll bm = b/4*4;
	ll ans = 0;
	if(a != -1) FOR(i, am, a+1) ans ^= i;
	FOR(i, bm, b+1) ans ^= i;
	cout << ans << endl;
	return 0;
} 


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

int main() {
  int n, x;
  std::cin >> n >> x;

  auto costs = std::vector<int>(n);
  int basecost = 0;
  for (int i = 0; i < n; i++) {
    std::cin >> costs[i];
    basecost += costs[i];
  }

  int mincost = *std::min_element(costs.begin(), costs.end());

  std::cout << n + (x - basecost) / mincost << std::endl;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define MP make_pair
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define fst first
#define snd second

#define MAX_V 100010
#define MAX_LOG_V 20

vector<int> edge[MAX_V];
int parent[MAX_LOG_V][MAX_V];
int depth[MAX_V];

struct LCA{
  int root;

  LCA(int r): root(r){}

  void add_edge(int a, int b) {
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  
  void dfs(int v, int par, int dep) {
    parent[0][v] = par;
    depth[v] = dep;
    for (auto child : edge[v]) {
      if (child != par) dfs(child, v, dep + 1);
    }
  }

  void init(int V) {
    dfs(root, -1, 0);
    for (int k = 0; k + 1 < MAX_LOG_V; k++) {
      for (int v = 0; v < V; v++) {
	if (parent[k][v] < 0) {
	  parent[k+1][v] = -1;
	} else {
	  parent[k+1][v] = parent[k][parent[k][v]];
	}
      }
    }
  }

  int lca(int u, int v) {
    if (depth[u] > depth[v]) swap(u, v);
    for (int k = 0; k < MAX_LOG_V; k++) {
      if ((depth[v] - depth[u]) >> k & 1) {
	v = parent[k][v];
      }
    }
    if (u == v) return u;
    for (int k = MAX_LOG_V - 1; k >= 0; k--) {
      if (parent[k][u] != parent[k][v]) {
	u = parent[k][u];
	v = parent[k][v];
      }
    }
    return parent[0][u];
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int N;
  LCA lca(0);
  
  cin >> N;
  REP(i, N) {
    int k;
    cin >> k;
    REP(j, k) {
      int c;
      cin >> c;
      lca.add_edge(i, c);
    }
  }
  lca.init(N);
  int Q;
  cin >> Q;
  REP(i, Q) {
    int u, v;
    cin >> u >> v;
    cout << lca.lca(u, v) << endl;
  }
  return 0;
}

Measured memory_bytes: 17492