akhauriyash/Code-Regression huggingface dataset:
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 2
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	hh := make([]hint, n)
	for i := 0; i < n; i++ {
		hh[i].x = getNextInt(scanner)
		hh[i].y = getNextInt(scanner)
		hh[i].h = getNextInt(scanner)
	}

	for i := 0; i < 101; i++ {
		for j := 0; j < 101; j++ {
			if valid(i, j, hh) {
				for k := 0; k < n; k++ {
					if hh[k].h == 0 {
						continue
					}
					fmt.Fprintln(writer, fmt.Sprintf("%d %d %d", j, i, height(i, j, hh[k])))
					return
				}
			}
		}
	}
}
func absint(i int) int {
	if i < 0 {
		return -i
	}
	return i
}
func valid(y, x int, hh []hint) bool {
	n := len(hh)
	h := 0
	for i := 0; i < n; i++ {
		if hh[i].h == 0 {
			continue
		}
		h2 := height(y, x, hh[i])
		if h < h2 {
			h = h2
		}
	}
	for i := 0; i < n; i++ {
		h2 := height(y, x, hh[i])
		if hh[i].h == 0 {
			if h > h2 {
				return false
			}
			continue
		}
		if h != h2 {
			return false
		}
	}

	return true
}
func height(y, x int, h hint) int {
	return h.h + absint(h.y-y) + absint(h.x-x)
}

type hint struct {
	x, y, h int
}


Measured memory_bytes: 640
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());

using ll = long long int;
const ll MOD = 1000000007;

ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a % b);
}

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

int main(){
    string s;
    cin >> s;
    int n = s.size();
    vector<vector<ll>> dp(n + 1);
    generate(dp.begin(), dp.end(), [](){ return vector<ll>(13, 0); });
    dp[0][0] = 1;
    rep(i, n) {
        bool nq = s[i] != '?';
        rep(j, 10) {
            if(nq && j != s[i] - '0') continue;
            rep(k, 13) {
                dp[i + 1][(k * 10 + j) % 13] += dp[i][k];
            }
        }
        rep(j, 13) {
            dp[i + 1][j] %= MOD;
        }
    }
    cout << dp[n][5] << endl;
    return 0;
}


Measured memory_bytes: 13696
#include <stdio.h>

int main(void) {
    int H, W, M, x, y, i, j, k;
    int T, t, h, w, a, b, A[25][25];
    int AB, C;
    char S[25][25];
    scanf("%d%d", &H, &W);
    T=H*W;
    for (i=0; i<H; i++) {
        scanf("%s", S[i]);
        for (j=0; j<W; j++) {
            if (S[i][j]=='#') T--;
        }
        // for (i=0; i<H; i++) printf("%s\n", S[i]);
    }
    // printf("%d %d", H, W);
    M=0;
    for (i=0; i<H; i++) {
        for (j=0; j<W; j++) {
            for (k=0; k<H*W; k++) {
                if (S[k/W][k%W]=='.') A[k/W][k%W]=1000;
                else A[k/W][k%W]=1001;
                // printf("%d: %d %d\n", k, k/W, k%W);
            }
            if (S[i][j]=='#') continue;
            A[i][j]=0;
            t=T-1;
            AB=0;
            while (t>0) {
                for (k=0; k<H*W; k++) {
                    h=k/W; w=k%W;
                    if (h==0) a=-1;
                    else if (h==H-1) a=1;
                    else a=0;
                    if (w==0) b=-1;
                    else if (w==W-1) b=1;
                    else b=0;
                    y=A[h][w];
                    C=0;
                    if (a!=-1) {
                        if (y<A[h-1][w]) {
                            if (A[h-1][w]==1001) C=1;
                            if (A[h-1][w]==1000 && C==0) t--;
                            if (A[h-1][w]>y+1 && C==0) A[h-1][w]=y+1;
                        }
                    }
                    C=0;
                    if (a!=1) {
                        if (y<A[h+1][w]) {
                            if (A[h+1][w]==1001) C=1;
                            if (A[h+1][w]==1000 && C==0) t--;
                            if (A[h+1][w]>y+1 && C==0) A[h+1][w]=y+1;
                        }
                    }
                    C=0;
                    if (b!=-1) {
                        if (y<A[h][w-1]) {
                            if (A[h][w-1]==1001) C=1;
                            if (A[h][w-1]==1000 && C==0) t--;
                            if (A[h][w-1]>y+1 && C==0) A[h][w-1]=y+1;
                        }
                    }
                    C=0;
                    if (b!=1) {
                        if (y<A[h][w+1]) {
                            if (A[h][w+1]==1001) C=1;
                            if (A[h][w+1]==1000 && C==0) t--;
                            if (A[h][w+1]>y+1 && C==0) A[h][w+1]=y+1;
                        }
                    }
                    // printf("(%d %d %d): %d\n", AB, h, w, t);
                }
                // AB++;
                // if (AB>=10) break;
            }
            /*
            for (k=0; k<H*W; k++) {
                h=k/W; w=k%W;
                printf("%4d", A[h][w]);
                if (w!=W-1) printf(" ");
                else printf("\n");
            }
            */
            for (k=0; k<H*W; k++) {
                h=k/W; w=k%W;
                if (A[h][w]==1001) continue;
                if (A[h][w]>M) M=A[h][w];
            }
        }
    }
    printf("%d", M);
    return 0;
}

Measured memory_bytes: 128
'''
.append(要素) リストに要素を追加
.extend(リスト) リストを連結する
.insert(場所,要素) 指定した場所に要素追加
del 配列名[場所]
-1で末尾で末尾から一つ前

sort()
sorted(reverse=true)

配列の初期化
配列名=[a]*n+[b]*m

Decimal()
'''

from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
from functools import reduce
from operator import mul
from collections import Counter

n = stdin.readline().rstrip().split()
N = int(n[0])
M = int(n[1])

print(int(N*(N-1)/2+M*(M-1)/2))


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

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

using namespace std;

int main(){
	string s,t; cin>>s>>t;
	int n=s.length();
	rep(i,n) if(s.substr(i)+s.substr(0,i)==t) { cout<<"Yes"<<endl; return 0; }
	cout<<"No"<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll N,M; cin>>N>>M;
  ll sum=0;
  vector<ll> B(N,0);
  for(int i=0; i<N; i++){
    ll a; cin>>a; sum+=a; B[i]=a;
  }
  sort(B.begin(), B.end(), greater<ll>());
  ll border=sum/(4*M);
  if(sum%(4*M)!=0) border++;
  if(B[M-1]>=border) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	vector<int> vec;
	int n;
	for(int i=0;i<10;i++){
	cin>>n;
	 vec.push_back(n);
	}
	sort(vec.begin(),vec.end());
	cout<<vec[9]<<endl;
	cout<<vec[8]<<endl;
	cout<<vec[7]<<endl;
	return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,la,ans,l;
char s[500001];
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	la=1;
	ans=1;l=1;
	while(la<n){
		ans++;
		//printf("%d\n",la);
		la++;
		if(l==1){
			if(s[la-1]==s[la]){
				if(la==n)ans--;
				 else la++,l=2;
			}
		}
		 else l=1;
	}
	printf("%d",ans);
}

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

int main(){
  double n;
  cin >> n;
  int64_t ans=10,s=0;
  for(int i=1;i<=sqrt(n);i++){
    if(n/i==ceil(n/i)){
      s=max(log10(i),log10(n/i))+1;
      ans=min(ans,s);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4032
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */


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

    int X; cin >> X;
    vector<int> a(6), m(6);
    rep(i, 6) a[i] = 100 + i;
    rep(i, 6) m[i] = 1e7;

    vector<vector<int>> dp(10, vector<int>(X+5, -1));
    dp[0][0] = 0;
    rep(i, 6) rep(j, X+1){
        if(dp[i][j]>=0) dp[i+1][j] = m[i];
        else if(j < a[i] || dp[i+1][j-a[i]]<=0) dp[i+1][j] = -1;
        else dp[i+1][j] = dp[i+1][j-a[i]]-1;
    }
    
    cout << (dp[6][X]>=0) << endl;
    
    return 0;
}

Measured memory_bytes: 4608
#include <bits/stdc++.h>
using namespace std;
int main() {
  char c;
  cin >> c;
  if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
    cout << "vowel" << endl;
}
  else {
    cout << "consonant" << endl;
}
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  string S,T;
  cin >> S >> T;
  int count = 0;
  for(int i=0; i<S.size(); i++){
    char s = S[i];
    char t = T[i];
    if(s != t){
      count = count + 1;
    }  
  }  
  cout << count << endl;  
  return 0;
}

Measured memory_bytes: 3448
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

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

		// 入力値の取得
		int N = sc.nextInt();
		int K = sc.nextInt();
		Set<Integer> kids = new HashSet<>();
		for (int i = 0; i < K; i++) {
			int d = sc.nextInt();
			for (int j = 0; j < d; j++) {
				kids.add(sc.nextInt());
			}
		}
		// 結果の出力
		System.out.println(N - kids.size());

		sc.close();
	}
}


Measured memory_bytes: 37488
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = 0;

    if(a<=9 && b<=9){
      c = a*b;
      System.out.println(c);
    }else{
      System.out.println(-1);
    }
  }
}


Measured memory_bytes: 22740
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int H, W, c[15][15], dp[15][15];
int main() {
	while(scanf("%d%d", &W, &H), H) {
		memset(c, 0, sizeof(c));
		memset(dp, 0, sizeof(dp));
		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) scanf("%d", &c[i][j]);
		}
		for(int i = 0; i < W; i++) {
			if(c[0][i] == 0) dp[0][i] = 1;
		}
		for(int i = 1; i < H; i++) {
			for(int j = 0; j < W; j++) {
				if(c[i][j] == 1) continue;
				if(i != H && c[i - 1][j] == 0) dp[i][j] = dp[i - 1][j];
				if(i != H && c[i][j] == 0 && j != 0 && c[i - 1][j - 1] == 0) dp[i][j] += dp[i - 1][j - 1];
				if(i != H && c[i][j] == 0 && j + 1 != W && c[i - 1][j + 1] == 0) dp[i][j] += dp[i - 1][j + 1];
				if(i > 1 && c[i - 2][j] == 2) dp[i][j] += dp[i - 2][j];
			}
		}
		int ret = 0;
		for(int i = 0; i < W; i++) {
			ret += dp[H - 1][i];
			if(c[H - 2][i] == 2) ret += dp[H - 2][i];
		}
		printf("%d\n", ret);
	}
}

Measured memory_bytes: 3184
import java.io.*
import java.util.*

const val YES = "Yes"
const val NO = "No"
// |S| ~ 10 ^ 5
// 文字の置換('a' <-> 'b')でS -> Tにできるか
fun solve(S: String, T: String) {
    val cache1 = mutableMapOf<Int, Int>()
    val cache2 = mutableMapOf<Int, Int>()
    for (i in 0 until S.length) {
        val s = S[i].toInt() - 97
        val t = T[i].toInt() - 97
        if(s in cache1.keys && cache1[s]!! != t){
            println(NO)
            return
        }
        if(t in cache2.keys && cache2[t]!! != s){
            println(NO)
            return
        }
        cache1[s] = t
        cache2[t] = s
    }
    println(YES)
    return
}
fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val S = sc.next()
    val T = sc.next()
    solve(S, T)
}


Measured memory_bytes: 34984
#include<bits/stdc++.h>
using namespace std;
const int N=300005,m=300001;
int n,k,a[N],tr[N<<2],ans;
void update(int k,int l,int r,int x,int v)
{
	if(l==r)
	{
		tr[k]=v;
		return;
	}
	int mid=l+r>>1;
	if(x<=mid) update(k<<1,l,mid,x,v);
	else update(k<<1|1,mid+1,r,x,v);
	tr[k]=max(tr[k<<1],tr[k<<1|1]);
}
int query(int k,int l,int r,int a,int b)
{
	if(l==a&&r==b)
		return tr[k];
	int mid=l+r>>1;
	if(b<=mid) return query(k<<1,l,mid,a,b);
	else if(a>mid) return query(k<<1|1,mid+1,r,a,b);
	else return max(query(k<<1,l,mid,a,mid),query(k<<1|1,mid+1,r,mid+1,b));
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		int l=max(0,a[i]-k),r=min(m-1,a[i]+k);
		int v=query(1,1,m,l+1,r+1)+1;
		ans=max(ans,v);
		update(1,1,m,a[i]+1,v);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 8968
import java.util.Scanner;
class Main {

    public static void main(String[] args) {
        java.util.Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        char charArray[]=new char[S.length()];
        for(int i=0;i<S.length();i++)
        {
            if((S.charAt(i)+N)>='A' && (S.charAt(i)+N)<='Z')
            {
                charArray[i]= (char)((int)S.charAt(i)+N) ;
            }
            else if((S.charAt(i)+N)>'Z')
            {
                charArray[i]=(char)(((int)S.charAt(i)+N)-26);
            }
        }
        System.out.println(new String(charArray));
    }
}

Measured memory_bytes: 23764
#include <iostream>
using namespace std;
#include <bits/stdc++.h>
#define MOD 1000000007
typedef long long ll;

vector<vector<ll>> dp_arr;

int main()
{
	int n, k;
	cin >> n >> k;
	vector<ll> arr(n);
	for(int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}
	vector<int> dp_arr(k+1,0);
	dp_arr[0] = 1;
	for(int i = 1; i <= n; i++)
	{
		vector<ll> cum_sum(k+1,0);
		cum_sum[0] = dp_arr[0];
		for(int i = 1; i <=k; i++)
		{
			cum_sum[i] = (cum_sum[i-1]%MOD + dp_arr[i]%MOD)%MOD;
		}
		for(int candies = 0; candies <= k; candies++)
		{
			if(candies > arr[i-1])
				dp_arr[candies] = (cum_sum[candies]%MOD - cum_sum[candies-arr[i-1]-1]%MOD + MOD)%MOD;
			else
				dp_arr[candies] = cum_sum[candies];
		}
	}
	cout << dp_arr[k] << endl;
	return 0;
}


Measured memory_bytes: 1408
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<iostream>
#include<cstring>
typedef long long ll;
const ll MAXN=110+10;
const int INF=0x7fffffff; 

using namespace std;


int main(){
	int n;
	cin>>n;
	cout<<"ABC"<<n<<endl;
	return 0;
} 

Measured memory_bytes: 256
from collections import defaultdict

n,k = map(int,input().split())
a_li = list(map(int,input().split()))

d = defaultdict(int)

for key in a_li:
    d[key] += 1
d = sorted(d.items(), key=lambda x:x[1])
    
s = len(d) - k
ans = 0

for i in range(s):
    ans += d[i][1]
    
print(ans)

Measured memory_bytes: 39352
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
//constexpr int MOD=1000000007;
constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;
//struct edge{lint to,num;};

int main(void){
    string S,T;
    cin >> S >> T;
    int ans=INF;
    int sl=S.length(),st=T.length();
    for(int i=0;i<sl-st+1;i++){
        int cmp=0;
        for(int j=i;j<i+st;j++) if(S[j]!=T[j-i]) cmp++;
        ans=min(ans,cmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
    cin>>s;
    string a=s;
    reverse(s.begin(),s.end());
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='b') s[i]='d';
        else 
            if(s[i]=='d')s[i]='b';
            else 
                if(s[i]=='p') s[i]='q';
                    else 
                        if(s[i]=='q') s[i]='p';
    }
    if(s==a) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 512
using System;

namespace atcoder1
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            var arr = input.Split(' ');
            var n = Convert.ToInt32(arr[0]);
            var m = Convert.ToInt32(arr[1]);
            var ret = 0;
            ret += m * (m - 1) / 2;
            ret += n * (n - 1) / 2;
            Console.Write(ret);
        }
    }
}

Measured memory_bytes: 11220
#include <iostream>
#include <utility>
#include <tuple>
#include <string>
#include <cstdint>
#include <vector>
#include <array>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <cassert>
using namespace std;
using i64 = int64_t;
int n, s, t;
vector<vector<int>> g;
vector<int> depth, deep;
void dfs_depth(int u, int p) {
    for (int v : g[u]) {
        if (v == p) continue;
        depth[v] = depth[u] + 1;
        dfs_depth(v, u);
    }
}
void dfs_deep(int u, int p) {
    deep[u] = depth[u];
    for (int v : g[u]) {
        if (v == p) continue;
        dfs_deep(v, u);
        deep[u] = max(deep[u], deep[v]);
    }
}
int main() {
    cin >> n >> s >> t;
    g.resize(n + 1);
    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }   
    depth.resize(n + 1);
    dfs_depth(t, 0);
    deep.resize(n + 1);
    dfs_deep(t, 0);
    int mid_depth = depth[s] / 2 + 1;
    int mid_u = s;
    while (depth[mid_u] != mid_depth) {
        assert(depth[mid_u] > mid_depth);
        for (int v : g[mid_u]) {
            if (depth[v] == depth[mid_u] - 1) {
                mid_u = v;
                break;
            }
        }
    }
    int ans = deep[mid_u] - 1;
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11648
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);

		String str=sc.next();

		int N=str.length();

		int count01=0;
		int count10=0;

		if(N>2) {

			String[] strs=str.split("");

			String s0="0";
			String s1="1";

			for(int i=0;i<strs.length;i++) {

				if(i%2==0) {
					if(!strs[i].equals(s0)) count01++;
					if(!strs[i].equals(s1)) count10++;
				}else {
					if(!strs[i].equals(s1)) count01++;
					if(!strs[i].equals(s0)) count10++;
				}

			}
		}

		System.out.println(Math.min(count01, count10));

		sc.close();

	}

}


Measured memory_bytes: 33364
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define RFOR(i,a,b) for(int i=(b-1); i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    int n,m; cin >> n >> m;
    vector<vector<int>> g(n);
    rep(i,m){
        int a,b; cin >> a >> b; a--; b--;
        g[a].pb(b);
        g[b].pb(a);
    }
    vector<bool> seen(n, false);
    vector<int> ans(n);
    queue<int> q;
    q.push(0);
    seen[0] = true;
    ans[0] = -1;
    while(!q.empty()){
        int v = q.front(); q.pop();
        for(int u : g[v]){
            if(seen[u]) continue;
            q.push(u);
            seen[u] = true;
            ans[u] = v;
        }
    }
    cout << "Yes" << endl;
    FOR(i, 1,n){
        cout << ans[i] + 1 << endl;
    }
}


Measured memory_bytes: 10128
N = int(input())
S = input()
#0なし
numlist = [""]
dp = [False] * 1000
for s in S:
    tmp = []
    for n in numlist:
        if len(n+s) == 3:
            dp[int(n+s)] = True
        if len(n+s) < 3:
            tmp.append(n+s)
    numlist.extend(tmp)
    numlist = list(set(numlist))
print(sum(dp))

Measured memory_bytes: 42220
#if 0
2019.08.25

如果 W 出现在奇数位（编号从 1 开始）上，那么它一定作为一个操作的右端点。
证明：假设 s[i] = W 出现在某操作的左端点，
那么 s[i] 被翻成 B ，必须有奇数个小于 i 的 l 和大于 i 的 r 构成的操作序列，
那么 i 左边剩下的与大于 i 的没有关联的一定是奇数个，
奇数个点无法保证每个点在操作序列中，得出矛盾，原命题成立。

同理，如果 W 出现在偶数位必须是左端点，
B 出现在奇数位必须是左端点，出现在偶数位则相反。

那么就可以确定每个点是作为 l 或者 r ，
剩下的问题就是求把 l 与 r 的问题一一匹配的方案数，
假设操作序列无序，那么就是括号匹配，乘上 n! 即可得出有序的方案数。
#endif
#include <cstdio>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long lolong;

inline int input() { int x; scanf("%d", &x); return x; }

const int maxn = 100005, mod = 1000000007;
char s[maxn << 1];

int main() {
	int n = input();
	scanf("%s", s + 1);

	lolong ans = 1;
	int l = 0;

	for(int i = 1; i <= (n << 1); i ++)
		if((s[i] == 'W') == (i & 1))
			(ans *= (l --)) %= mod;
		else
			l ++;

	for(int i = 1; i <= n; i ++)
		(ans *= i) %= mod;

	printf("%lld\n", (l == 0) * ans);
}


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

int main() {
  int N;
  cin >> N;
  string S;
  
  for(int i = 0; i < N; i++){
      cin >> S;
      if(S == "Y"){
          cout << "Four" << endl;
          break;
      }
      else if(i == N - 1){
          cout << "Three" << endl;
      }
  }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
namespace ConsoleApp15
{
    class Class258
    {
        static void Main()
        {
            var HN = Array.ConvertAll(ReadLine().Split(), int.Parse);
            int H = HN[0];
            int N = HN[1];

            var dp = Enumerable.Repeat(int.MaxValue, H + 1).ToArray();
            dp[0] = 0;

            for(int i = 0; i < N; i++)
            {
                var ab = Array.ConvertAll(ReadLine().Split(), int.Parse);
                int a = ab[0];
                int b = ab[1];

                for(int j = 0; j < H; j++)
                {
                    if (dp[j] != int.MaxValue)
                    {
                        var v = Math.Min(j + a, H);
                        dp[v] = Math.Min(dp[v], dp[j] + b);
                    }
                }
            }
            WriteLine(dp[H]);
        }
    }
}


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

int main()
{
    int n,k;
    cin >> n >> k;
    vector<int> d(k);
    for(int i=0;i<k;++i) cin >> d[i];
    while(true){
        int x=n;
        bool f=1;
        while(x>0){
            for(int i=0;i<k;++i){
                if(x%10==d[i]) f=0;
            }
            x/=10;
            if(f==0) x=0; 
        }
        if(f==1){
            cout << n << endl;
            return 0;
        }
        ++n;
    }
}

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

int main() {
  //2c a+b
  ll a,b,c,x,y;
  cin>>a>>b>>c>>x>>y;
  ll ans=1000000000000;
  
    int mx=max(x,y);
    
      ll count=0;
      int mn=min(x,y);
      
    for(int i=0;i<=2*mx;i+=2){ //iはcの枚数/
      count=0;
      count+=i*c;
      if(x-i/2>0)
      count+=(x-i/2)*a;
      if(y-i/2>0)
      count+=(y-i/2)*b;
    
    
    
    
    ans=min(ans,count);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3596
#include<stdio.h>
int main(){
  int n,x,i,j,k,count;

  while(1){
  
    scanf("%d%d",&n,&x);

    if(n==0 && x==0)break;
    else{
      count=0;
      for(i=1; i<=n; i++){
	for(j=i+1; j<=n; j++){
	  for(k=j+1; k<=n; k++){
	    if(i+j+k == x)count++;
	  }
	}
      }
      printf("%d\n",count);
	}
  }
 
  return 0;
}
	

Measured memory_bytes: 600
#include <stdio.h>
int main()
{
	int a, b, ans;
	scanf("%d %d", &a, &b);
	if(a<=5)
		ans = 0;
	else if(a<=12)
		ans = b/2;
	else if(a<=100)
		ans = b;
	printf("%d\n", ans);
	return 0;
}


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

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)

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

Measured memory_bytes: 1228
import java.util.*;
import java.io.*;

public class Main {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 32768);
    static PrintWriter out = new PrintWriter(System.out);
    static StringTokenizer t;

    static String sn() {
        while (t == null || !t.hasMoreTokens()) {
            try {
                t = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                throw new RuntimeException();
            }
        }
        return t.nextToken();
    }

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

    static long nlo() {
        return Long.parseLong(sn());
    }

    public static void main(String args[]) {
        int t = 1;//ni();
        while (t-- > 0) {
            solve();
        }
        out.close();
    }

    static long mod = 998244353;

    static long pro(long a, long b) {
        return (a % mod * b % mod) % mod;
    }

    static long add(long a, long b) {
        return (a + b) % mod;
    }

    static int maxn = 200005;

    static void solve() {
        char c[] = sn().toCharArray();
        int n = c.length;
        int f[] = new int[26];
        for (int i = 0; i < n; i++)
            f[c[i] - 'a']++;
//        out.println(Arrays.toString(f));
        int ff = 0;
        for (int i = 0; i < 26; i++) {
            if (f[i] > 0 && f[i] % 2 != 0) {
                ff = 1;
                out.println("No");
                break;
            }
        }
        if (ff == 0)
            out.println("Yes");
    }
}

Measured memory_bytes: 21076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=100010;
int a[MAXN],n,cnt;
int read(){
    int f=1,x=0;
    char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();}
    return f*x;
}
int main(){
    cin>>n;
    for(int i=1;i<=4;i++){
        if(n%10==2) cnt++;
        n/=10;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for(int i = (s); i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
typedef long long ll;
const int INF = 1001001001;
const int mod = 1000000007;

void dfs(int x, int y) {}

int main() {
    vector<int> v(3);
    cin >> v[0] >> v[1] >> v[2];
    map<int, int> mp;
    rep(i, 3){
        if(mp.count(v[i])){
            mp[v[i]]++;
        }
        else{
            mp[v[i]] = 1;
        }
    }
    cout << mp.size() << endl;
}

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

namespace ABC096
{
    class Program
    {
        public static void Main(string[] args)
        {
            /*
            var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int a = input[0];
            int b = input[1];
            int x = input[2];
            string result = "NO";
            */

            int[] array = new int[4];
            for (int i = 0; i < 4; i++) {
                array[i] = int.Parse(Console.ReadLine());
            }
            var a = 0;
            var b = 0;

            a = (array[0] <= array[1]) ? array[0] : array[1];
            b = (array[2] <= array[3]) ? array[2] : array[3];

            Console.WriteLine(a+b);
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 11092
import Data.Bits

main = do
    [a, b] <- map read . words <$> getLine
    let ns = map (numBits a (b + 1)) [0..40]
        xs = map (\k -> if numBits a (b + 1) k `mod` 2 == 1 then 1 `shift` k else 0) $ [0..40]
    -- print (ns :: [Int])
    print $ sum (xs :: [Int])

roundDown :: Int -> Int -> Int
roundDown n k = n `div` k * k

roundUp :: Int -> Int -> Int
roundUp n k = (n + k - 1) `div` k * k

nextMultiple :: Int -> Int -> Int
nextMultiple n k = (n + k - 1)

numBits :: Int -> Int -> Int -> Int
numBits b e k = let twoPowK = 1 `shift` k
                    twoPowKPlus1 = 1 `shift` (k + 1)
                    m = b + roundDown (e - b) twoPowKPlus1
                    m' = roundUp m twoPowKPlus1
                    m'' = m' - twoPowK
                    m''' = m' + twoPowK
                    x = (m - b) `div` 2
                    y = min e m' - min e (max m m'') + e - min e m'''
                    in x + y

-- numBits :: Int -> Int -> Int -> Int
-- numBits b e k = let twoPowK = 1 `shift` k
--                     twoPowKPlus1 = 1 `shift` (k + 1)
--                     b' = roundDown b twoPowKPlus1
--                     b'' = b' + twoPowK
--                     e' = roundUp e twoPowKPlus1
--                     e'' = e' - twoPowK
--                     x = (e' - b') `div` 2
--                     y = max (e' - max e e'') 0
--                     z = max (b - b'') 0
--                     in x - y - z

Measured memory_bytes: 508
#include <iostream>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
using namespace std;



int main()
{
	int a, b, c, d, e, X[5],sum = 0;
	cin >> a >> b >> c >> d >> e;
	
	X[0] = a%10 ==0 ?0 :10 - a % 10;
	X[1] = b % 10 == 0 ? 0: 10 - b % 10;
	X[2] = c % 10 == 0 ? 0: 10 - c % 10;
	X[3] = d % 10 == 0 ?0: 10 - d % 10;
	X[4] = e % 10 == 0 ? 0: 10 - e % 10;

	int i, j, temp;

	for (i = 0; i < 4; i++) {
		for (j = 0; j < 4; j++) {
			if (X[j + 1] < X[j]) {
				temp = X[j]; 
				X[j] = X[j + 1]; 
				X[j + 1] = temp;
			}
		}
	}
	
	for (i = 0; i < 4; i++)
	{
		sum += X[i];
	}
	cout << a + b + c + d + e + sum << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline int GCD(int a,int b){return !b?a:GCD(b,a%b);}
const int Primes[168]=
{2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,
 97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,
 227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,
 367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,
 509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,
 661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,
 829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997};
const char common[]="not coprime",disjoint[]="pairwise coprime",several[]="setwise coprime";
char esc[1000000];
static inline int Divide(int x)
{
  if(!x){return 0;}
  rep(i,168)
  {
    if(Primes[i]*Primes[i]>x)break;
    if(x%Primes[i])continue;
    if(esc[Primes[i]-1])return 0;
    esc[Primes[i]-1]=1;
    while(x%Primes[i]==0&&x)x/=Primes[i];
  }
  if(x>1){if(esc[x-1])return 0;esc[x-1]=1;}
  return 1;
}
int main(void)
{
  int N=IN(),A=0,f=0,g=0;
  rep(i,N){A=IN();g=GCD(g,A);if(i&&g!=1){f=1;}if(f)continue;else{if(!Divide(A))f=1;}}
  if(g>1)return puts(common),0;else{if(f)return puts(several),0;else return puts(disjoint),0;}
}

Measured memory_bytes: 2488
/////////////////////////////////////////////////////////
//
//  c/temp.cpp file
//  Last Updated: 2018-10-23 ...Maybe
//
//    I hope you adding this code to the setting file
//    alias g++='g++ -std=c++1y -DDEBUG_LOCAL'
//
/////////////////////////////////////////////////////////

#include <bits/stdc++.h>

using namespace std;

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

//#define int long long

#define _overload3(_1,_2,_3,name,...) name
#define _REP(i,n) REAP(i,0,n)
#define REAP(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(...) _overload3(__VA_ARGS__,REAP,_REP,)(__VA_ARGS__)

#define _REPR(i,n) REAPR(i,n,0)
#define REAPR(i,a,b) for(int i=int(a-1);i>=int(b);--i)
#define REPR(...) _overload3(__VA_ARGS__,REAPR,_REPR,)(__VA_ARGS__)

#define ALL(a) a.begin(),a.end()
#define rALL(a) a.rbegin(),a.rend()

#define coutALL(a) {int loop_coutALL=0;for(auto e:a) cout<<(loop_coutALL++?" ":"")<<e; cout<<endl;}

#define coutYN(a) cout<<((a)?"YES":"NO")<<endl;
#define coutYn(a) cout<<((a)?"Yes":"No")<<endl;
#define coutyn(a) cout<<((a)?"yes":"no")<<endl;

#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)

const int INF=1145141919;
//const long long INF=114514191911451419;
const int MOD=(int)1e9+7;
const double EPS=1e-12;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
//const int dx[]={-1,-1,-1,0,1,1,1,0},dy[]={-1,0,1,1,1,0,-1,-1};

using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;

typedef pair<int,int> pii;
typedef pair<int,string> pis;
typedef pair<string,int> psi;
typedef pair<string,string> pss;

typedef long long ll;

template<typename T> istream &operator >> (istream &is, vector<T> &v){for(T &x:v) is>>x;return is;}
template<typename T> ostream &operator << (ostream &os, vector<T> &v){int i=0;for(T &x:v) os<<(i++?" ":"")<<x;return os;}

ll rev(ll n){ll x=0;for(;n>0;){x=x*10+n%10;n/=10;}return x;}

ll upper(ll n,ll m){return (n+m-1)/m;};
ll rounding(ll n){return (long double)n+0.5;};

bool inG(ll x,ll n){return 0<=x && x<n;}
bool outG(ll x,ll n){return x<0 || n<=x;}

inline int qp(int a,ll b){if(!b)return 1;int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
inline int qp(int a,ll b,int mo){if(!b)return 1;int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

inline ll fac(ll k,ll n){ll a=1;for(int i=0;i<n;i++)a*=k--;return a;}
inline ll fac(ll k,ll n,int mo){ll a=1;for(int i=0;i<n;i++)a*=k--,a%=mo;return a;}

inline int dsum(ll n){int a=0;for(;n;n/=10)a+=n%10;return a;}

struct Arithmetic{Arithmetic(){cin.tie(0);ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);}};

//#define DEBUG_LOCAL

#ifdef DEBUG_LOCAL
template<typename T> void deb(T a){cerr<<"deb: "<<a<<"です"<<endl;}
#define debl {cerr<<"debug: "<<__LINE__<<"行目だ"<<endl;}
void what_cr(){cout<<__GCC_ATOMIC_CHAR16_T_LOCK_FREE<<" ←？"<<endl;}
//ori_func S

//ori_func E
#else
template<typename T>void deb(T a){}
#define debl
void what_cr(){}void t_t(){}
#endif

signed main(){

  Arithmetic Exception;

  int w,h,x,y;

  cin>>w>>h>>x>>y;

  cout<<(double)w*h/2<<" "<<(x+x==w && y+y==h)<<endl;

  return 0;

}


Measured memory_bytes: 256
N, M = map(int, input().split())

if M % N == 0:
    ans = M // N
else:
    ans = 0
    for i in range(1, int(M ** 0.5) + 1):
        if M % i == 0:
            if i <= M // N:
                ans = max(ans, i)
            if M // i <= M // N:
                ans = max(ans, M // i)
        
print(ans)

Measured memory_bytes: 3064
//#define _USE_MATH_DEFINES
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#define FINAL_OUT(x) {cout << (x) << '\n'; exit(0); }
inline int safe_mul(const int x, const int y) __attribute__ ((warn_unused_result));


int main()
{
//    freopen("in.txt","r", stdin);
    cout << fixed << setprecision(20);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n,m;
    cin >> n >> m;
    vector<pair<int,int>> a(n);
    for (auto& pa : a)
        cin >> pa.first >> pa.second;
    sort(begin(a), end(a));

    multiset<int, greater<int>> qu;
    auto it = a.begin();
    int ans = 0;
    for (int d = 1; d <= m; ++d) {
        while (it != a.end() && it->first == d) {
            qu.insert(it->second);
            ++it;
        }
        if (!qu.empty()) {
            ans += *qu.begin();
            qu.erase(qu.begin());
        }
    }
    cout << ans << endl;
}


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


int main(){
  int N;
  cin >> N;
  for(int ii=0; ii<N; ii++){
    int a;
    cin >> a;
    if(a%2==1) continue;
    if(a%3==0) continue;
    if(a%5==0) continue;
    cout << "DENIED" << endl;
    return 0;
  }
  cout << "APPROVED" << endl;
  return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<ll, int> P;
#define MOD (1000000007ll)
#define l_ength size

ll sq(ll x){
	return x*x;
}

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

bool isvowel(char c){
	int i;
	string v="aeiou";
	for(i = (v.size()-1); i>=0; --i){
		if(c == v[i]){
			return true;
		}
	}
	return false;
}

ll manhattan(ll x1, ll y1, ll x2, ll y2){
	return ((ll)(abs(x1-x2)+abs(y1-y2)));
}

ll digit(ll x){
	ll ans = 0ll;
	if(!x){
		return 0ll;
	}
	while(x>0){
		ans++;
		x /= 10;
	}
	return ans;
}

ll f(ll a, ll b){
	return max(digit(a),digit(b));
}

int main(void){
	ll n,m,i,ans=INF;
	cin >> n;
	m = sqrt(n);
	for(i=1ll; i<=m; ++i){
		if(n%i){
			continue;
		}
		ans = min(ans,f(i,n/i));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

/**
 * Created by khrom on 2017/06/14.
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        double a = scanner.nextDouble();
        double b = scanner.nextDouble();
        System.out.printf("%d %d %.5f", (int) Math.floor(a / b), (int) (a % b), a / b);
    }
}

Measured memory_bytes: 28076
#include <iostream>
using namespace std;
int main(){
	char c1[3],c2[3];
	cin >> c1[0] >> c1[1] >> c1[2];
	cin >> c2[0] >> c2[1] >> c2[2];
	if((c1[0]==c2[2])&&(c1[1]==c2[1])&&(c1[2]==c2[0])){
		cout << "YES\n" ;
	}else{
		cout << "NO\n" ;
	}
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 100005
#define endl "\n"
#define mod 1000000007
#define PI 3.141592653589793
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
ll n,k,ar[N],dp[N];
ll maxval(ll i){
	if(i==n) return 0;
	if(i+1==n) return abs(ar[i]-ar[i+1]);

	if(dp[i]!=-1) return dp[i];
	ll a=1e18,j;
	for(j=i+1;j<=min(n,i+k);j++){
		a=min(a,maxval(j)+abs(ar[i]-ar[j]));
	}
	return dp[i]=a;
}
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,l;
	cin>>n>>k;
	for(i=1;i<=n;i++){
		cin>>ar[i];
	}	
	memset(dp,-1,sizeof(dp));
	ll an=maxval(1);
	cout<<an;
	return 0;	
}

Measured memory_bytes: 9908
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>
#include <cmath>
#include <functional>
#include <map>
#include <cstdlib>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

int main()
{
    int N;
    cin >> N;
    int M = 1<<N;
    vector<int> A(M), u(M), v(M);
    for(int i=0; i<M; i++){
        cin >> A[i];
        u[i] = i;
    }

    auto comp = [&](const int a, const int b){
        if(A[a]==A[b]) return a < b;
        return A[a] < A[b];
    };
    set<int, decltype(comp)> st(comp);
    for(int i=0; i<N; i++){
        for(int j=0; j<M; j++){
            if((j>>i)&1){
                st.clear();
                int k = j ^ (1<<i);
                if(v[j] != -1) st.insert(v[j]);
                if(v[k] != -1) st.insert(v[k]);
                st.insert(u[j]);
                st.insert(u[k]);

                auto itr = st.end();
                u[j] = *(itr = prev(itr));
                v[j] = *(itr = prev(itr));
            }
        }
    }

    int ans = 0;
    for(int i=1; i<M; i++){
        ans = max(ans, A[u[i]] + A[v[i]]);
        cout << ans << "\n";
    }
}

Measured memory_bytes: 6144
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long
//#define lint long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

typedef pair<int, int> P;
priority_queue< P, vector<P>, greater<P> > pq;//ダイクストラの時、greaterで小さい順
vector<P> edge[200000];
int d[200000];




int n;
int q,k;
signed main(){
  cin >> n;
  REP(i,n-1){
    int a1,b1,c1;
    cin >> a1 >> b1 >> c1;
    edge[a1].pb(P(c1,b1));
    edge[b1].pb(P(c1,a1));
  }
  cin >> q >> k;
  REP(i,n+1) d[i] = INF;
  d[k] = 0;
  pq.push(P(0,k));
  while(pq.size()>0){
    P p1 = pq.top();
    pq.pop();
    int nN = p1.second;
    int nD = p1.first;
    if(d[nN] < nD) continue;
    REP(i,edge[nN].size()){
      if (d[edge[nN][i].second] > edge[nN][i].first + nD){
        d[edge[nN][i].second] = edge[nN][i].first + nD;
        pq.push(P(d[edge[nN][i].second],edge[nN][i].second));
      }
    }
  }
  REP(i,q){
    int x1,y1;
    cin >> x1 >> y1;
    cout << d[x1] + d[y1] << endl;
  }
  return 0;
}


Measured memory_bytes: 13552
// #Sazaの1日1AC
#include <bits/stdc++.h>
using namespace std;

//メイン関数
int main()
{
  //doubleの桁数
  cout << fixed << setprecision(10);

  while (true)
  {
    int N; int x;
    cin >> N >>x;
    if(N == 0 && x == 0) break;
    int res = 0;
    for (int i = 1; i <= N; i++)
    {
      for (int j = i + 1; j <= N; j++)
      {
        int k = x - i - j;
        if (1 <= k && k <= N && i < k && j < k)
          res++;
      }
    }

    cout << res << endl;
  }
}


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

using ll = long long;

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

	int n;
	cin >> n;
	vector<ll> arr(n);
	ll sum = 0;
	for(ll& x : arr) {
		cin >> x;
		sum ^= x;
	}

	// consider each bit in the sum:
	// 	if bit k is set, we get it for free
	// 	if bit k is not set, 
	// 		divide into 2 sets greedily, such that both
	// 		have bit k set
	//
	// 	remove set bits in sum from each num,
	// 	maximize A + B, ans = sum + (A + B)
	// 	but A == B, maximize A
	
	vector<ll> a(n);
	for(int i = 0; i < n; i++) {
		a[i] = arr[i] - (sum & arr[i]);
	}

	//sort(a.rbegin(), a.rend());
	int i = 0;
	for(int b = 59; b >= 0; b--) {
		int x = i;
		while(x < n && (a[x] >> b & 1) == 0) {
			x++;
		}
		if(x == n) continue;
		swap(a[i], a[x]);
		for(int j = 0; j < n; j++) {
			if(j == i) continue;
			if(a[j] >> b & 1) {
				a[j] ^= a[i];
			}
		}
		i++;
	}
	ll mx = 0;
	for(int i = 0; i < n; i++) {
		mx = max(mx, mx ^ a[i]);
	}
	sum += 2*mx;
	cout << sum << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define inf INT_MAX
#define sc(a) scanf("%d",&a)
#define scc(a,b) scanf("%d %d",&a,&b)
#define sccc(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pf(a) printf("%d",a)
#define pff(a,b) printf("%d %d",a,b)
#define pfff(a,b,c) printf("%d %d %d",a,b,c)
#define pb(a) push_back(a)
#define em empty()
#define fr front()
#define cl clear()
#define sz size()
#define mp(a,b) make_pair(a,b)
#define fri(b) freopen(b,"r",stdin)
#define fro(b) freopen(b,"w",stdout)
/*
ID: uslusam1
TASK: test
LANG: C++
*/
using namespace std;

int main(){
	//fri("a.gir");
	//fro("a.cik");
	int n;
	cin>>n;
	string s;
	cin>>s;
	int k=n/2;
	if(n%2==1){
		cout<<"No";
		return 0;
	}
	else{
		for(int i=0;i<=k-1;i++){
			if(s[i]!=s[i+k]){
				cout<<"No";
				return 0;
			}
		}
	}
	cout<<"Yes";
 
	return 0;
}

Measured memory_bytes: 256
use proconio::input;
use std::collections::HashSet;

fn main() {
    input! {
        x: i64,
        n: usize,
        p: [i64; n],
    }

    let mut set = HashSet::new();
    for pi in p.iter().copied() {
        set.insert(pi);
    }

    let mut ans = 1000;
    for i in (-200..200).rev() {
        if set.contains(&i) {
            continue;
        }
        if (x - i).abs() <= (x - ans).abs() && i < ans {
            ans = i;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2180