akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <chrono>
#include <queue>
#include <functional>

using namespace std;

typedef long long ll;

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

    string S; cin >> S;

    int len = S.size();
    int c[2] = {0, 0};
    for (int i = 0; i < len; ++i) {
        c[S[i] == '0' ? 0 : 1]++;
    }

    cout << min(c[0], c[1]) * 2 << "\n"; 

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define pii pair < int, int >
typedef vector<int> vi;
typedef  long long ll;
const int mod =1e9+7;
const int N = (int)2e5 + 5;

int get(char c){
	return (int)(c-'0');
}

void solve(){
 	string s;
 	cin>>s;
 	int y=get(s[0])*1000+get(s[1])*100+get(s[2])*10+get(s[3]);
 	int m=get(s[5])*10+get(s[6]);
 	int d=get(s[8])*10+get(s[9]);
 	if(y>2019){
 		cout<<"TBD";
 		return;
 	}	
 	if(y<2019){
 		cout<<"Heisei";
 		return;
 	}		
 	if(m<4){
 		cout<<"Heisei";
 		return;
 	}
 	if(m>4){
 		cout<<"TBD";
 		return;
 	}
 	if(d<=30){
 		cout<<"Heisei";
 		return;
 	}
 	cout<<"TBD";
	
    
}

int main(){
	Red;
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, 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 ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

ll choose(ll n){
  return n * (n - 1) / 2;
}
int main(){
  ll N, M; cin >> N >> M;
  vector<ll> a(N); rep(i, N) cin >> a[i];

  vector<ll> s(N + 1, 0);
  rep(i, N) s[i + 1] = s[i] + a[i];
  map<ll, ll> mp;
  for (int i = 1; i < N + 1; ++i) mp[s[i] % M]++;
  ll ans = 0;
  for (auto v: mp){
    ans += choose(v.second);
  }
  ans += mp[0];
  cout << ans << endl;
}


Measured memory_bytes: 5760
import java.util.*;
public class Main {
	//定義関数から参照できる変数定義はこの辺
	static int A;
	static int B;
	static int K;
	static int ans=0;


	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
		A = sc.nextInt();
		B = sc.nextInt();
		K = sc.nextInt();

		if ((A+K-1)<(B-K+1)) {
			for(int i=A;i<=A+K-1;i++){
				ans=i;
				System.out.println(ans);
			}
			for(int i=B-K+1;i<=B;i++){
				ans=i;
				System.out.println(ans);
			}
		}
		else{
			for(int i=A;i<=B;i++){
				ans=i;
				System.out.println(ans);
			}

		}


		
		//System.out.print(ans);
    }
}

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

int main() {
    int a[3];
    for (int i = 0; i < 3; i++) cin >> a[i];
    sort(a, a + 3);
    int ans = 0;
    // 最大値 or 最大値-1まで+2
    for (int i = 0; i < 2; i++) {
        if (a[i] + 1 < a[2]) {
            int addition = (a[2] - a[i]) / 2 * 2;
            a[i] += addition;
            ans += addition / 2;
        }
    }
    // 貪欲法でシミュレーション
    while (true) {
        sort(a, a + 3);
        if (a[0] < a[2]) {
            a[0]++;
            a[1]++;
            ans++;
            continue;
        }
        break;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		int m=in.nextInt();
		int[] deg=new int[n];
		int[] dp=new int[n];
		ArrayList<Integer>[] G=new ArrayList[n];
		for (int i=0;i<n;++i)
			G[i]=new ArrayList<Integer>();
		while (m-->0) {
			int u=in.nextInt();
			int v=in.nextInt();
			--u;
			--v;
			G[u].add(v);
			++deg[v];
		}
		Queue<Integer> que=new LinkedList<Integer>();
		int res=0;
		for (int i=0;i<n;++i) if (deg[i]==0)
			que.add(i);
		while (!que.isEmpty()) {
			int u=que.peek();
			que.poll();
			for (int i=0;i<G[u].size();++i) {
				int v=G[u].get(i);
				dp[v]=Math.max(dp[v],dp[u]+1);
				res=Math.max(res,dp[v]);
				--deg[v];
				if (deg[v]==0) que.add(v);
			}
		}
		System.out.println(res);
	}
}

Measured memory_bytes: 100316
package main

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

//=====I/O=====

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//=====main=====

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

	n, a, b := int64(scanInt()), int64(scanInt()), int64(scanInt())

	if (b-a)%2 == 0 {
		fmt.Println((b-a)/2)
	} else {
		if a-1 < n-b {
			fmt.Println(a+(b-a)/2)
		} else {
			fmt.Println(n-b+1+(b-a)/2)
		}
	}

}


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

using namespace std;

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

int main()
{
    int n;
    long fin = 0;
    cin>>n;
    int v[n], c[n];
    fo(i, n)
        cin>> v[i];
    fo(i, n)
    {
        cin>> c[i];
        if(v[i] > c[i])
            fin += v[i] - c[i];
    }
    cout<<fin;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#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++)
typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<int> X(N), Y(N);
    for (int i = 0; i < N; i++){
        cin >> X[i];
      	Y[i] = X[i];
    }
    sort(Y.begin(), Y.end());
    for (int i = 0; i < N; i++){
        if (X[i] < Y[N / 2]) {
            cout << Y[N/2] << endl;
        }
        else{
            cout << Y[N/2 - 1] << endl;
        }
    }
}



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

#define ll long long
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//const int MOD = 1e9 + 7;
const int MAX = 1e5 + 1;
int arr[MAX];

int main()
{
	IOS
	int t = 1;
	//cin >> t;
	while(t--)
	{
		int n;
		cin >> n;
		for(int i = 1; i <= 100; ++i)
		{
			for(int j = 1; j <= 100; ++j)
			{
				for(int k = 1; k <= 100; ++k)
				{
					int ind = i * i + j * j + k * k + i * j + i * k + k * j;
					if(ind > n) break;
					arr[ind] += 1;
				}
			}
		}
		for(int i = 1; i <= n; ++i)
			cout << arr[i] << endl;
	}
	return 0;
}



Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	int r, l;
	cin >> s;
	int n = s.size();
	for (int i = 0; i < n; i++)
	{
		if (s[i] == 'C')
		{
			l = i;
			break;
		}
	}
	for (int i = n; i >= 0; i--)
	{
		if (s[i] == 'F')
		{
			r = i;
			break;
		}
	}
	if (r > l) cout << "Yes";
	else cout << "No";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define popcnt(a) __builtin_popcount(a)
#define FastIO() ios::sync_with_stdio(false), cin.tie(0);
#define IO() freopen("palindrome.in","rw",stdin)
#define error(args...)                       \
{                                            \
    cerr<<"LINE "<<__LINE__;                 \
    string _s = #args;                       \
    replace(_s.begin(), _s.end(), ',', ' '); \
    stringstream _ss(_s);                    \
    istream_iterator<string> _it(_ss);       \
    err(_it, args);                          \
    cerr<<endl;                              \
}
void err(istream_iterator<string> it)
{
} 
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
  cerr<<' '<< *it << " = " << a ;
  err(++it, args...);
} 
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e6+9, M = (1<<31), OO = 0x3f3f3f3f;
LL arr[N];
int main()
{
  bool f = 1;
  int n;
  int cur;
  scanf("%d",&n);
  scanf("%d",&cur);
  cur--;
  for(int i=1;i<n;++i)
  {
    int nxt;
    scanf("%d",&nxt);
    if(cur>nxt)
    {
      f=0;
      break;
    }
    else if(nxt>cur) nxt--;
    cur=nxt;
  }
  if(f) puts("Yes");
  else puts("No");
  #ifdef _LOCAL_DEFINE
  cerr << (double)clock() * 1.0 / CLOCKS_PER_SEC << endl;
  #endif
  return 0; 
}

Measured memory_bytes: 256
import * as fs from "fs";

let input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
const n = +input[0];
const a: Array<number> = input[1].split(" ").map((x: string): number => +x);

let min = Infinity;
let min_i = -1;
let max = -Infinity;
let max_i = -1;
for (let i = 0; i < n; i++) {
	if (a[i] < min) {
		min = a[i];
		min_i = i;
	}
	if (a[i] > max) {
		max = a[i];
		max_i = i;
	}
}

let positive = true;
if (max < 0) positive = false;
else if (min < 0) {
	if (-min > max) positive = false;
}

const result = [];

if (positive && min < 0) {
	for (let i = 0; i < n; i++) {
		if (a[i] < 0) {
			a[i] += max;
			result.push([max_i, i]);
		}
	}
}

else if (!positive && max > 0) {
	for (let i = 0; i < n; i++) {
		if (a[i] > 0) {
			a[i] += min;
			result.push([min_i, i]);
		}
	}
}

console.error(a);

if (positive) {
	for (let i = 1; i < n; i++) {
		if (a[i - 1] <= a[i]) continue;
		a[i] += a[i - 1];
		result.push([i - 1, i]);
	}
}

else {
	for (let i = n - 2; i >= 0; i--) {
		if (a[i] <= a[i + 1]) continue;
		a[i] += a[i + 1];
		result.push([i + 1, i]);
	}
}

console.log(result.length);
for (let p of result) {
	console.log(p[0] + 1, p[1] + 1);
}

console.error(a);


Measured memory_bytes: 9420
def c():
    K, N = map(int, input().split())
    A = list(map(int, input().split()))
    diff = [A[i+1] - A[i] for i in range(N-1)]
    diff.append(A[0]+K - A[N-1])
    # print(diff)
    print(K - max(diff))


##########
if __name__ == "__main__":
    c()


Measured memory_bytes: 26444
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;

fn main() {
    input! {
    a:String,
    }
    let v = a.chars().collect_vec();
    if (v[5]as usize - '0' as usize)*1000+(v[6]as usize - '0' as usize)*100+(v[8]as usize - '0' as usize)*10+(v[9]as usize - '0' as usize)>430 {println!("TBD") }
    else { println!("Heisei") }
}


Measured memory_bytes: 2160
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;

namespace AGC014B
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt;
            var M = ReadInt;

            int[] count = new int[N];
            for (int i = 0; i < M; i++)
            {
                var a = ReadInt - 1;
                var b = ReadInt - 1;
                count[a]++;
                count[b]++;
            }

            bool ans = true;
            if (count.Where(x => x % 2 != 0).Count() != 0) ans = false;

            if (ans) Console.WriteLine("YES");
            else Console.WriteLine("NO");
        }


    }


}

namespace Assistant
{
    static class Input
    {
        static List<string> line = new List<string>();
        static int index = 0;
        static String ReadNext()
        {
            if (line.Count <= index) line.AddRange(Console.ReadLine().Split());
            return line[index++];
        }
        public static int ReadInt => int.Parse(ReadNext());
        public static long ReadLong => long.Parse(ReadNext());
        public static int[] ReadInts => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static long[] NextLongs => Console.ReadLine().Split().Select(long.Parse).ToArray();
    }

    static class Debug
    {
        static public void Draw2D(int[,] map, int mode = 1)
        {
#if DEBUG
            int W = map.GetLength(0);
            int H = map.GetLength(1);

            int[,] map2 = new int[W + 1, H + 1];
            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (i == 0 && j == 0) map2[i, j] = 0;
                    else if (i == 0) map2[i, j] = j - 1;
                    else if (j == 0) map2[i, j] = i - 1;
                    else map2[i, j] = map[i - 1, j - 1];
                }
            }

            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (mode == 0) Console.Write(map2[i, j] % 10);
                    if (mode == 1) Console.Write(map2[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
#endif
        }

        static void Draw1D(int[] array, int mode = 0)
        {
#if DEBUG
            Console.WriteLine(string.Join(" ", array));
#endif
        }
    }
}


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

#define ll long long
#define ar array

const int mxN=2e5, M=1e9+7;
int n, s[mxN];
vector<int> adj[mxN];
ll iv[mxN], f1[mxN], f2[mxN], dp[mxN], ans[mxN];

void dfs1(int u=0, int p=-1) {
    dp[u]=1;
    for(int v : adj[u]) {
        if(v==p)
            continue;
        dfs1(v, u);
        dp[u]=dp[u]*dp[v]%M*f1[s[u]+s[v]]%M*f2[s[u]]%M*f2[s[v]]%M;
        s[u]+=s[v];
    }
    ++s[u];
}

ll mI(ll a, ll m) {
    return (a%=m)<2?a:(1-mI(m%a, a)*m)/a+m;
}

void dfs2(int u=0, int p=-1, ll pd=1) {
    ans[u]=dp[u]*pd%M*f1[n-1]%M*f2[s[u]-1]%M*f2[n-s[u]]%M;
    for(int v : adj[u]) {
        if(v==p)
            continue;
        dfs2(v, u, ans[u]*mI(dp[v], M)%M*f2[n-1]%M*f1[n-1-s[v]]%M*f1[s[v]]%M);
    }
}

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

    cin >> n;
    iv[1]=1;
    for(int i=2; i<n; ++i)
        iv[i]=M-M/i*iv[M%i]%M;
    f1[0]=f2[0]=1;
    for(int i=1; i<n; ++i) {
        f1[i]=f1[i-1]*i%M;
        f2[i]=f2[i-1]*iv[i]%M;
    }
    for(int i=1, u, v; i<n; ++i) {
        cin >> u >> v, --u, --v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs1();
    dfs2();
    for(int i=0; i<n; ++i)
        cout << ans[i] << "\n";
}

Measured memory_bytes: 22516
#include<iostream>
#include<algorithm>
using namespace std;

int main(){

  int w, h, n, x, y, a;
  cin >> w >> h >> n;
  int w0=0, h0=0, w1=w, h1=h;

  for(int i=0; i<n; i++){
    cin >> x >> y >> a;
    if(a==1){
      w0 = max(w0, x);
    } else if(a==2){
      w1 = min(w1, x);
    } else if(a==3){
      h0 = max(h0, y);
    } else if(a==4){
      h1 = min(h1, y);
    }
  }

  cout << max(0, w1-w0)*max(0, h1-h0) << endl;
  return 0;
}

Measured memory_bytes: 256
MAX_N = 110
N, W = map(int, input().split())
weight = [0] * MAX_N
value = [0] * MAX_N
for i in range(N):
    weight[i], value[i] = map(int, input().split())
dp = [[0] * (W + 1) for _ in range(MAX_N)]
for i in range(N):
    for sum_w in range(W + 1):
        if sum_w - weight[i] >= 0:
            dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w - weight[i]] + value[i])
        dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w])
# for l in dp:
#     print(l)
print(dp[N][W])

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

using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using ll = long long int;
using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>;
using vd = vector<double>; using vvd = vector<vd>; using vvvd = vector<vvd>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using cdouble = complex<double>;

const double eps = 1e-7;
#define Loop(i, n) for(int i = 0; i < int(n); i++)
#define Loopll(i, n) for(ll i = 0; i < ll(n); i++)
#define Loop1(i, n) for(int i = 1; i <= int(n); i++)
#define Loopll1(i, n) for(ll i = 1; i <= ll(n); i++)
#define Loopr(i, n) for(int i = int(n) - 1; i >= 0; i--)
#define Looprll(i, n) for(ll i = ll(n) - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = int(n); i >= 1; i--)
#define Looprll1(i, n) for(ll i = ll(n); i >= 1; i--)
#define Foreach(buf, container) for(auto buf : container)
#define Loopdiag(i, j, h, w, sum) for(int i = ((sum) >= (h) ? (h) - 1 : (sum)), j = (sum) - i; i >= 0 && j < (w); i--, j++)
#define Loopdiagr(i, j, h, w, sum) for(int j = ((sum) >= (w) ? (w) - 1 : (sum)), i = (sum) - j; j >= 0 && i < (h); j--, i++)
#define Loopdiagsym(i, j, h, w, gap) for (int i = ((gap) >= 0 ? (gap) : 0), j = i - (gap); i < (h) && j < (w); i++, j++)
#define Loopdiagsymr(i, j, h, w, gap) for (int i = ((gap) > (h) - (w) - 1 ? (h) - 1 : (w) - 1 + (gap)), j = i - (gap); i >= 0 && j >= 0; i--, j--)
#define Loopitr(itr, container) for(auto itr = container.begin(); itr != container.end(); itr++)
#define printv(vector) Loop(ex_i, vector.size()) { cout << vector[ex_i] << " "; } cout << endl;
#define printmx(matrix) Loop(ex_i, matrix.size()) { Loop(ex_j, matrix[ex_i].size()) { cout << matrix[ex_i][ex_j] << " "; } cout << endl; }
#define quickio() ios::sync_with_stdio(false); cin.tie(0);
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
#define Comp(type_t) bool operator<(const type_t &another) const
#define fst first
#define snd second
#define INF INFINITY
bool feq(double x, double y) { return abs(x - y) <= eps; }
bool inrange(ll x, ll t) { return x >= 0 && x < t; }
bool inrange(vll xs, ll t) { Foreach(x, xs) if (!(x >= 0 && x < t)) return false; return true; }
int ceillog2(ll x) { int ret = 0;	x--; while (x > 0) { ret++; x >>= 1; } return ret; }
ll rndf(double x) { return (ll)(x + (x >= 0 ? 0.5 : -0.5)); }
ll floorsqrt(ll x) { ll m = (ll)sqrt((double)x); return m + (m * m <= x ? 0 : -1); }
ll ceilsqrt(ll x) { ll m = (ll)sqrt((double)x); return m + (x <= m * m ? 0 : 1); }
ll rnddiv(ll a, ll b) { return (a / b + (a % b * 2 >= b ? 1 : 0)); }
ll ceildiv(ll a, ll b) { return (a / b + (a % b == 0 ? 0 : 1)); }
ll gcd(ll m, ll n) { if (n == 0) return m; else return gcd(n, m % n); }
ll lcm(ll m, ll n) { return m * n / gcd(m, n); }

/*******************************************************/

int main() {
	int n; cin >> n;
	vi a(n); Loop(i, n) cin >> a[i];
	vi ans(n, -1);
	Loopr(i, n) {
		int x = i + 1;
		int y = x + x;
		int z = 0;
		while (y - 1 < n) {
			z ^= ans[y - 1];
			y += x;
		}
		ans[i] = a[i] ^ z;
	}
	vi out;
	Loop(i, n) {
		if (ans[i] == 1) out.push_back(i + 1);
	}
	cout << out.size() << endl;
	printv(out);
}

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

const int M = 1000005;

int main(){
  int n; cin >>n;
  vector<int> a(n);
  rep(i,n) cin >>a[i];
  vector<int> cnt(M);
  for(int x : a){
    if(cnt[x]!=0){
      cnt[x] = 2;
      continue;
    }
    for(int i = x; i<M; i+=x) cnt[i]++;
  }
  int ans = 0;
  for(int x : a){
    if(cnt[x]==1) ans++;
  }
  cout << ans << endl;
  return 0; 
}


Measured memory_bytes: 8004
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
#define ff first
#define ss second
#define pb push_back
#define N 100005

ll inv[N], fac[N], finv[N];

void make()
{
	fac[0] = fac[1] = 1;
	inv[1] = 1;
	finv[1] = finv[0] = 1;
	for(int i = 2; i < N; ++i)
	{
		fac[i] = i * fac[i - 1] % MOD;
		inv[i] = MOD - MOD/i * inv[MOD % i] % MOD;
		finv[i] = inv[i] * finv[i - 1] % MOD;
	}
}

ll C(ll n, ll k)
{
	if(n < k || n < 0) return 0;
	return fac[n] * finv[n - k] % MOD* finv[k] % MOD;
}

int n;
vector<pair<int, int>> g[N];
int co[N] = {};
int visited[N] = {};
void dfs(int node, int we, int col)
{
	visited[node] = 1;
	for(auto e : g[node])
	{
		if(!visited[e.ff])
		{
			// cout << e.ss + we << " " << e.ff << "\n";
			if(e.ss % 2)
				co[e.ff] = (col == 1 ? 0 : 1);
			else
				co[e.ff] = col;
			dfs(e.ff, we, co[e.ff]);
		}
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	int v, u, w;
	for (int i = 0; i < n - 1; ++i)
	{
		cin >> v >> u >> w;
		g[v].pb({u, w});
		g[u].pb({v, w});
	}
	dfs(1, 0, 0);
	co[1] = 0;
	for(int i = 1; i <= n; ++i)
		cout << co[i] << "\n";
	return 0;
}

Measured memory_bytes: 9728
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
  cin>>n; string s="...",ans;
  cin>>ans;
  if(ans.length()>n)  { ans=ans.substr(0,n); ans+=s;}
  
 /* set<int>a={2,4,5,7,9},b={0,1,6,8};
  n=n%10;
  if(a.count(n)) s="h"+s;
  else if(b.count(n)) s="p"+s;
  else s="b"+s;*/
  cout<<ans<<endl;
}


Measured memory_bytes: 3636
k = int(input())

n = 50

a = k//n
b = k%n

if b == 0:
    res = [a]*n
    for i in range(n):
        res[i] += i
else:
    res = [0]*(n+1)
    for i in range(n+1):
        res[i] = i
    del res[n-b]
    for i in range(n):
        res[i]+=a
print(n)
ass = ''
for i in range(n):
    if i != 0:
        ass += ' '
    ass += str(res[i])
print(ass)

Measured memory_bytes: 3064
// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//


#define _USE_MATH_DEFINES
#include<math.h>

//#include<cmath>

#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>



//#include "Ants.h"
using namespace std;
typedef long long ll;
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<n;i++)
#define show(s) cout<<s<<endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define LINF (1000000000000000000ll)
typedef pair < int, int> P;
ll gcd(ll a, ll b) {//最大公約数を求める///最大公倍数a*b/gcd(a,b)
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcd(ll a, ll b) {//最小公倍数を求める　b=0のときaを返す
	if (b == 0) return a;
	return (a / gcd(a, b)) * b;
}
vector<int> divnum(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p;
}
int digiter(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p.size();
}
vector<int> convert(string s) {
	vector<int> d;
	ll n = s.size();
	rep(i, n) {
		d.push_back(s[i] - '0');
	}
	return d;
}

int K,N,A[200005];
int main()
{
	cin >> K >> N;
	int excep = 0;
	rep(i, N) {
		cin >> A[i];
	}
	A[N] = A[0]+K;
	rep(i, N) {
		chmax(excep, A[i + 1] - A[i]);
	}

	cout << K-excep << endl;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

const int N = 5000;

int A, B, a[N], b[N];

int calc(int ai, int bi){
  if(bi >= B) return 0;
  for(int i=ai;i<A;i++){
    if(b[bi] == a[i]){
      return calc(i+1, bi+1) + 1;
    }
  }
  return 0;
}

main(){
  while(cin >> A >> B){
    for(int i=0;i<A;i++){
      cin >> a[i];
    }
    for(int i=0;i<B;i++){
      cin >> b[i];
    }
    int ans = 0;
    for(int i=0;i<B;i++){
      ans = max(ans, calc(0, i));
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 864
# -*- coding: utf-8 -*-
import sys

N, M, *AB = map(int, sys.stdin.buffer.read().split())

dict_path = {i+1: [] for i in range(N)}

for i in range(M):
  A,B = AB[2*i:2*i+2]
  dict_path[A].append(B)
  dict_path[B].append(A)

list_bfs = [1]
list_flg = [0 for _ in range(N+1)]
list_flg[1] = 1

while len(list_bfs)>0:
  list_tmp = []
  for i in list_bfs:
    for j in dict_path[i]:
      if list_flg[j]==0:
        list_tmp.append(j)
        list_flg[j] = i
  list_bfs = list_tmp

print('Yes')
for i in list_flg[2:]:
  print(i)

Measured memory_bytes: 48124
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var N = array[0];
            var K = array[1];

            var s = IntToN(N, K);
            Console.WriteLine(s.Length);
        }

        private static string IntToN(int a, int sp)
        {
            return ByteToN(BitConverter.GetBytes(a), sp);
        }
            
        private static string ByteToN(byte[] b, int sp)
        {
            long n = BitConverter.ToUInt32(b, 0);
            long num = n;

            char[] ch = getChar(sp);

            string result = string.Empty;

            long amari = 0;
            while (true)
            {
                if (num < sp)
                {
                    result = ch[num] + result;
                    break;
                }
                amari = num % sp;
                num = num / sp;
                result = ch[amari] + result;
            }
            return result;
        }
        private static char[] getChar(int count)
        {
            char[] result = new char[count];
            for (int i = 0; i < 10 && i < count; i++)
            {
                result[i] = (char)('0' + ((char)i));
            }
            if (count > 10)
            {
                for (int i = 0; i < count - 10; i++)
                {
                    result[i + 10] = (char)('a' + ((char)i));
                }
            }
            return result;
        }
    }
}


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

namespace AtCoder
{

    static class Program
    {
        static void Main()
        {
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });

            var chars = "aiueo".ToCharArray();
            var c = GetChar();
            var ans = chars.Any(a => a == c) ? "vowel" : "consonant";

            Console.WriteLine(ans);


            Console.Out.Flush();
            Console.ReadKey();
        }


        static public string GetStr() { return Console.ReadLine().Trim(); }
        static public char GetChar() { return Console.ReadLine().Trim()[0]; }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
        static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public char[] GetCharArray() { return Console.ReadLine().Split(' ').Select(char.Parse).ToArray(); }
        static public Double[] GetDoubleArray() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
        static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
        static string yesno(this bool b) { return b ? "yes" : "no"; }
        static string YesNo(this bool b) { return b ? "Yes" : "No"; }
        static string YESNO(this bool b) { return b ? "YES" : "NO"; }

        static bool eq<T, U>() => typeof(T).Equals(typeof(U));
        static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
        static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                           : eq<T, long>() ? ct<T, long>(long.Parse(s))
                           : eq<T, double>() ? ct<T, double>(double.Parse(s))
                           : eq<T, char>() ? ct<T, char>(s[0])
                                             : ct<T, string>(s);
        static void Multi<T>(out T a) => a = cv<T>(GetStr());
        static void Multi<T, U>(out T a, out U b)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
        }
        static void Multi<T, U, V,W>(out T a, out U b, out V c, out W d)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]);
        }
        static void Multi<T, U, V, W,X>(out T a, out U b, out V c, out W d,out X e)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]);e = cv<X>(ar[4]);
        }
    }
}

Measured memory_bytes: 13652
# A - Restaurant

# N 今までに食べた食数
# x 今までに払った金額（円）
# y レストランからもらった金額（円）

N = int(input())
# print(N)

# x の計算 1食800円
x = N * 800
# print(x)

# y の計算 15食毎200円
y = int(N / 15) * 200
# print(y)

# x - y
answer = x - y

# 結果の表示
print(answer)


Measured memory_bytes: 9132
#include <iostream>
#include <string>
using namespace std;
int main(){
        int N;
        bool counting[200]={false};
        int max=0;
        cin >> N;
        for(int i=0 ; i<N ; i++ ){
                int tmp;
                cin>> tmp;
                counting[tmp]=true;
                if(max<tmp)
                        max=tmp;
        }
        int counter=0;
        for(int i=max ; i>0 ; i-- ){
                if(counting[i])
                        counter++;
        }
        cout << counter << endl;
        return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int>vec(M); // 範囲外エラーがでないって怖かったです…＞＜ しばらくはint A[N]とかつかうのやめとく…
  
  int K, A;
  for (int i = 0; i < N; i++)
  {
    cin >> K;
    
    for (int j = 0; j < K; j++)
    {
      cin >> A;
      vec.at(A - 1)++;
    }
  }
  
  int answer = 0;
  for (int i = 0; i < M; i++)
  {
    if (vec.at(i) == N)
      answer++;
  }
  
  cout << answer << endl;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <set>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;

int main(){
  ll N; cin >> N;
  vector <ll> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  
  vector <ll> loc(N + 1);
  for (int i = 0; i < N; i++) loc[A[i]] = i + 1;
  
  set <ll> st{0, N + 1};

  ll ans = 0;
  for (ll i = 1; i <= N; i++){
    st.insert(loc[i]);

    auto itr = st.find(loc[i]);
    itr--; ll L = loc[i] - *itr;
    itr++;itr++; ll R = *itr - loc[i];

    ans += i * L * R;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
// __builtin_ctz : no of trailing zeros
#define int long long
#define ll long long
#define pp pair<int,int>
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
int max(int x, int y)
{
    return x>y ? x : y;
}
int min(int x, int y)
{
    return x<y ? x : y;
}
void _(int&a , int b)
{
    a=(a%mod+b%mod)%mod;
    a=(a+mod)%mod;
}
ll cl(ll a,ll b)
{
    return (a/b)+(!(!(a%b)));
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;cin >> n;
    ll a[n];ll d=0;
    for (int i = 0; i < n; ++i)
    {
    	cin >> a[i];d^=a[i];
    }
    for (int i = 0; i < n; ++i)
    {
    	cout << (d^a[i]) << " ";
    }
    }

Measured memory_bytes: 5108
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){
  ll N,M;
  cin >> N >> M;
  ll p[M];
  string S[M];
  for(int i=0;i<M;i++){
    cin >> p[i] >> S[i];
  }
  ll err = 0;
  ll ans = 0;
  bool ok[N+1];
  ll W[N+1];
  for(int i=1;i<N+1;i++){
    ok[i]=false;
    W[i]=0;
  }
  for(int j=0;j<M;j++){
    if(ok[p[j]]) continue;
    if(S[j]=="AC"){
      ans++;
      err += W[p[j]];
      ok[p[j]]=true;
    }
    else if(S[j]=="WA") W[p[j]]++;
  }
  cout << ans << " " << err << endl;
}


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

int main() {
    int H, N, A;
    cin >> H >> N;
    for (int i = 0; i < N; i++) {
        cin >> A;
        H -= A;
    }
    if (H > 0) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<utility>


#define rep(i,x) for(int i=0;i<(int)(x);i++)
#define reps(i,x) for(int i=1;i<=(int)(x);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)

#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e9

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; }
typedef long long ll;
typedef std::pair<ll, ll> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

using namespace std;


int main()
{
    int a[3][3];
    rep(i, 3){
        rep(j, 3){
            ll tmp;
            cin >> tmp;
            a[i][j] = tmp;
        }
    }
    int flag0 = 1;
    rep(i, 2){
        ll k;
        k = a[2][0]-a[i][0];
        rep(j, 3){
            if(a[2][j]-a[i][j] != k) flag0 = 0;
        }
    }

    int flag1 = 1;
    rep(j, 2){
        ll k;
        k = a[0][2] - a[0][j];
        rep(i, 3){
            if(a[i][2] - a[i][j] != k) flag1 = 0;
        }
    }
    if(flag0 == 1 && flag1 == 1) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 256
n,m=map(int,input().split())
if abs(n-m)>1:
    print(0)
elif n==m:
    prod=1
    for i in range(1,n+1):
        prod*=i
        prod%=1000000007
    print(prod*prod*2%1000000007)
else:
    prod=1
    for i in range(1,min(m,n)+1):
        prod*=i
        prod%=1000000007
    print(prod*prod*max(m,n)%1000000007)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, A;
    cin >> H >> A;
    cout << (H + A - 1) / A << endl;
}

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

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 

const ll inf = (ll)(1e17 + 17);
const ll mod = (ll)(1e9 + 7);
const int MAX = (int)(1e6) ;
vector<bool> prime(MAX + 1, true);
vll gv;
void SieveOfEratosthenes() 
{  
  
    for (int p=2; p*p<=MAX; p++) 
    {  
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=MAX; i += p) 
                prime[i] = false; 
        } 
    }
    for(ll i = 2; i < MAX; i++) if(prime[i]) gv.pb(i);
}

int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  SieveOfEratosthenes();
  ll x;
  cin >> x;
  cout << *lower_bound(all(gv), x) << endl;
  return 0;
} //good night.

Measured memory_bytes: 1528
$N+=<>;
@a=(_,glob<>);
$s[$_%2]+=$-=$a[$_]for 1..$N;
$s=$s[$p=$s[1]>$s[0]];
($q,$m)=sort{$b-$a}@a;
if($m<0){
	($i)=grep$a[$_]==$m,1..$N;
	@o=((reverse$i+1..$N),(1)x($i-1));
	$s=$m
}else{
	for($i=$N;$i;--$i){
		if($i%2!=$p&&$a[$i-1]>=0||$i%2==$p&&$a[$i]<0){
			push@o,$i;
			$N-=$N==$i||$i==1?1:2
		}
	}
	if($N!=1){
		push@o,1
	}
}
$,=$/;
print$s,@o+0,@o


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<(int)N;i++)
int main()
{
  int N,mean1=0,mean2=0,sum=0,y=0;
  cin>>N;
  vector<int> X(N,0);
  rep(i,N){cin>>X.at(i);sum+=X.at(i);}
  y=sum/N;
  rep(i,N){mean1+=pow(X.at(i)-y,2);mean2+=pow(X.at(i)-y-1,2);}
  cout<<min(mean1,mean2)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <iomanip>
#include <sstream>

using namespace std;

int N;

int main(){
    
    cin >> N;
    
    int k = sqrt(N);
    
    int ans = k*k;

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

    


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#define N 30
using namespace std;

int n,m,l,now,num[N];
vector<int>son[N],val[N];

int main()
{
    int i,j;
    cin>>n;
    now=n;
    for(; n; n/=2)
    {
        num[++l]=n%2;
    }
//    reverse(num+1,num+l+1);
//    for(i=1;i<=l;i++) cout<<num[i]<<" ";return 0;
    for(i=2; i<l; i++)
    {
        son[i-1].push_back(i);
        val[i-1].push_back(0);
        son[i-1].push_back(i);
        val[i-1].push_back((1 << (i-2)));
    }
    for(i=l-1; i>=1; i--)
    {
        if(!num[i]) continue;
        now-=(1 << (i-1));
        son[i].push_back(l);
        val[i].push_back(now);
    }
    now-=(1 << (l-1));
    son[l-1].push_back(l);
    val[l-1].push_back(now);
    son[l-1].push_back(l);
    val[l-1].push_back((1 << (l-2))+now);

    for(i=1; i<=l; i++) m+=son[i].size();
    cout<<l<<" "<<m<<endl;
    for(i=1; i<=l; i++)
    {
        for(j=0; j<son[i].size(); j++)
        {
            printf("%d %d %d\n",i,son[i][j],val[i][j]);
        }

    }
}

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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

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; }

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
constexpr int INF = 1001001001;
//constexpr ll INF = 1001001001001001001ll;
constexpr double EPS = 1e-10;
using number = long long;

double dp[3005][3005]; //dp[i][j]は個目まで使って表の個数がj個の確率

int main() {
    int N; cin >> N;
    vector<double> p(N);
    rep(i, N) cin >> p[i];
    dp[0][0] = 1;

    rep(i, N) {
        rep(j, N + 1) {
            dp[i + 1][j] += dp[i][j] * (1 - p[i]);
            dp[i + 1][j + 1] +=  dp[i][j] * p[i];
        }
    }

    double ans = 0;
    for (int i = N / 2 + 1; i <= N ; i++) {
        ans += dp[N][i];
    }

    cout << ans << endl;

}

Measured memory_bytes: 70656
fun main() {
    val (n, k) = readLine()!!.split(" ").map { it.toInt() }

    if (n == 1) {
        print(k)
        return
    }

    var answer = k

    for (i in (2 .. n)) {
        answer *= (k - 1)
    }
    print(answer)
}

Measured memory_bytes: 36360
#include <iostream>
#include <array>
#include <algorithm>
#include <map>
#include <vector>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <climits>
#include <string.h>
#include <cctype>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

// a と b の最大公約数を返す関数
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};

struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
} comb(2000005);

mint g(int r, int c) {
	return comb(r + c + 2, r + 1) - 1;
}

bool comp(int i, int j) {
	return i > j;
}

int main()
{
	long long  n, m;
	cin >> n >> m;
	long long sum = 0;
	for (int i = 0; i < m; i++)
	{
		long long tmp;
		cin >> tmp;
		sum += tmp;
	}
	if (n < sum)
	{
		cout << "-1";
	}
	else
	{
		cout << (n - sum);
	}
}


Measured memory_bytes: 34216
c = []
for i in range(3):
    x, y, z = map(int, input().split())
    c.append(x)
    c.append(y)
    c.append(z)

for a1 in range(101):
    for a2 in range(101):
        for a3 in range(101):
            b1 = c[0] - a1
            b2 = c[1] - a1
            b3 = c[2] - a1
            if c[3] == a2 + b1 and c[4] == a2 + b2 and c[5] == a2 + b3 and c[6] == a3 + b1 and c[7] == a3 + b2 and c[8] == a3 + b3:
                print('Yes')
                exit()
print('No')


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

#define INF 2*1000000000

//var 
int N,h[100001],dp[100001],K;

void dfs(int j){
	if(dp[j]!=INF)return;
	for(int i = 1; i<=K; i++){
		if(j-i<1)break;
		dfs(j-i);
		dp[j] = min(dp[j],dp[j-i]+abs(h[j]-h[j-i]));
	}
}

int main(){
	cin >> N >> K;
	for(int i = 1; i<=N; i++){
		cin >> h[i];
		dp[i] = INF;
	}dp[1] = 0;	
	dfs(N); cout << dp[N] << endl;
}

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

int main() {
  int N, a, b, s = 0;
  cin >> N;

  // N ÷ 10 = a…b
  a = N;
  do {
    b = a % 10;
    s += b;
  } while (a /= 10);

  if (N % s == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  char c;
  map<char, char> m = {{'A','T'}, {'T','A'}, {'C','G'}, {'G','C'}};
  cin >> c;
  cout << m[c] << endl;
}

Measured memory_bytes: 256
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  int a, b;
  scanf("%d%d", &a, &b);
  printf("%d\n", 6 - (a + b));
}

Measured memory_bytes: 128
n = int(input())
p = list(map(int,input().split()))
m = 2*10**5
cnt=0
if n == 1:
  print(1)
else:
  for i in range(n-1):
    if m > p[i]:
      m = p[i]
    if m > p[i+1]:
      #print(p[i+1])
      cnt+=1
  print(cnt+1)

Measured memory_bytes: 75472
#include <bits/stdc++.h>
using namespace std;
#define maxn 1000000
#define INF 99999999
#define int long long
int n, K, ans, tot, a[maxn];
int sum[maxn], num[maxn];
map <int, int> Map;

int read()
{
	int x = 0, k = 1;
	char c; c = getchar();
	while(c < '0' || c > '9') { if(c == '-') k = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * k;
}

void Update(int p, int l, int r, int x)
{
	if(l == r) { num[p] ++; return; }
	int mid = (l + r) >> 1;
	if(x <= mid) Update(p << 1, l, mid, x);
	else Update(p << 1 | 1, mid + 1, r, x);
	num[p] ++;
}

int Query(int p, int l, int r, int L, int R)
{
	if(L > r || R < l) return 0;
	if(L <= l && R >= r) return num[p];
	int mid = (l + r) >> 1;
	return Query(p << 1, l, mid, L, R) + Query(p << 1 | 1, mid + 1, r, L, R);
}

signed main()
{
	n = read(), K = read();
	for(int i = 1; i <= n; i ++) sum[i] = read() + sum[i - 1] - K;
	for(int i = 1; i <= n; i ++) a[i] = sum[i];
	sort(a + 1, a + 2 + n); a[0] = -INF;
	for(int i = 1; i <= n + 1; i ++)
		if(a[i] != a[i - 1]) Map[a[i]] = ++ tot;
	for(int i = 1; i <= n; i ++) sum[i] = Map[sum[i]];
	Update(1, 1, tot, Map[0]);
	for(int i = 1; i <= n; i ++)
	{
		ans += Query(1, 1, tot, 1, sum[i]);
		Update(1, 1, tot, sum[i]);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 27136
N = int(input())
A = list(map(int, input().split()))
answer = 0
temp = A[0]
right = 0

for i in range(N):
    if right < N - 1:
        while temp + A[right + 1] == temp ^ A[right + 1]:
            right += 1
            temp += A[right]
            if right == N - 1:
                break
        temp -= A[i]
        answer += right - i + 1
    else:
        answer += right - i + 1

print(answer)

Measured memory_bytes: 24840