akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using Edges = vector<vector<pair<int, int>>>;


vector<int> single_source_shortest_path(int r, const Edges & Es){
    vector<int> dist(Es.size(), -1);
    priority_queue<pair<int, int>> pq;
    pq.push(make_pair(0, r));
    while (not pq.empty()){
        auto dv = pq.top();
        pq.pop();
        int d = -dv.first;
        int v = dv.second;
        if ((dist[v] != - 1) and (d >= dist[v])) continue;
        dist[v] = d;
        for (auto & uc : Es[v]){
            int u = uc.first;
            int c = uc.second;
            if ((dist[u] != -1) and (d + c >= dist[u])) continue;
            pq.push(make_pair(-(d + c), u));
        }
    }
    return dist;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int V, E, r;
    cin >> V >> E >> r;
    Edges Es(V);
    while (E--){
        int s, t, d;
        cin >> s >> t >> d;
        Es[s].emplace_back(t, d);
    }
    auto dist = single_source_shortest_path(r, Es);
    for (auto d : dist){
        if (d == -1){
            cout << "INF" << '\n';
        }else{
            cout << d << '\n';
        }
    }
    return 0;
}

Measured memory_bytes: 14028
#include <iostream>
#include <math.h>

using namespace std;

int is_prime(int num) {
  double l = sqrt((double)num);
  for (int i = 2; i <= l; i++) {
    if (num % i == 0) {
      return 0;
    }
  }
  return 1;
}

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

  int cnt = 0;
  for (int i = 0; i < n; i++) {
    int num;
    cin >> num;
    cnt += is_prime(num);
  }

  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

int n, x;
int ans[200000];
bool saw[200000];

int main() {
    cin >> n >> x;
    if (n == 2) {
        if (x != 2) {
            cout << "No" << endl;
            return 0;
        }
        cout << "Yes" << endl;
        cout << 1 << endl << 2 << endl << 3 << endl;
        return 0;
    }
    if (x == 1 || x == 2*n-1) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    ans[n-1] = x-1;
    ans[n] = x;
    ans[n+1] = x+1;
    int num = 1;
    for (int i = 1; i <= 2*n-1; i++) {
        if (abs(i-n) <= 1) continue;
        if (num == x-1) num += 3;
        ans[i] = num;
        num++;
    }
    for (int i = 1; i <= 2*n-1; i++) cout << ans[i] << endl;
}

Measured memory_bytes: 2304
#include<iostream>
using namespace std;
int main()
{
  int n,i,h,a,s=0;
  cin >> h >> n;
  for(i=0;i<n;i++){
    cin >> a;
    s+=a;
    if(s>=h){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#define trdef for (int z=1;z<n;z++)	scanf ("%d %d", &a, &b), tr[a].push_back(b), tr[b].push_back(a), ij[a]++, ij[b]++
using namespace std;
typedef long long ll;
const int C=100001, M=1000000007;

vector <vector <int> > tr(C);
int ij[C], a, b, n;
ll dp[2][C];

int s[C], is=0, par[C], ji[C];
void proc_tree(int a, int n, vector <vector <int> > &tab, int ij[]){
	s[0]=a, is=1, dp[0][a]=dp[1][a]=1;
	int b;
	
	for(int z=1;z<=n;z++)	ji[z]=ij[z], par[z]=0;
	
	while (is>0){
		a=s[is-1];
		if (ji[a]>0&&tab[a][ji[a]-1]==par[a])	ji[a]--;
		if (ji[a]>0)	b=s[is]=tab[a][ji[a]-1], dp[0][b]=dp[1][b]=1, par[b]=a, is++, ji[a]--;
		else {
			dp[0][par[a]]=(dp[0][par[a]]*(dp[1][a]+dp[0][a]))%M;
			dp[1][par[a]]=(dp[1][par[a]]*dp[0][a])%M;
			is--;
		}
	}
}


int main(){
	scanf ("%d", &n);
	trdef;
	proc_tree(1, n, tr, ij);
	printf ("%lld\n", (dp[0][1]+dp[1][1])%M);
return 0;}

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

h,w,KK = map(int,input().split())

if h == 1:
    s = input()
    res = 0
    cnt = 0
    for i in range(w):
        if s[i] == "1":
            cnt += 1
            if cnt == KK and i != w-1:
                res += 1
                cnt = 0
    print(res)
    exit()

s = []
for i in range(h):
    s.append(input())

res = 10**9

d = dict()
for i in range(1<<(h-1)):
    tmp = 0
    for j in range(h-1):
        d[j] = tmp
        if (i>>j)&1 == 1:
            tmp += 1
    d[h-1] = tmp
    cnt = [0]*h


    for j in range(w):
        r = [0]*h
        judge = False
        for k in range(h):
            if s[k][j] == "1":
                r[d[k]] += 1
                if r[d[k]] > KK:
                    tmp = 10**9
                    break
                if r[d[k]] + cnt[d[k]] > KK:
                    judge = True
        if tmp == 10**9:
            break
        if judge:
            tmp += 1
            for k in range(h):
                cnt[k] = r[k]
        else:
            for k in range(h):
                cnt[k] += r[k]



    if res > tmp:
        res = tmp
print(res)




Measured memory_bytes: 45148
// https://atcoder.jp/contests/dp/tasks/dp_a

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
// int gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// int lcm(long a, long b) { return a * b / gcd(a, b); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> h(n + 1, INF);
    REP(i, n) cin >> h[i];
    // 入力値の足場の高さHの差分の合計を最小化する
    vector<int> dp(n + 1, INF);
    dp[0] = 0;
    REP(i, n - 1) {
        dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
        dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
    }
    cout << dp[n - 1] << endl;

    return 0;
}


Measured memory_bytes: 1024
# coding: utf-8
import math
def isPrime(n):
    if n == 1:
        return False
    if n == 2:
        return True
    if n % 2 == 0:
        return False
    for i in range(3, int(math.sqrt(n))+1,2):
        if n % i == 0:
            return False
    return True
            

n = int(input().rstrip())
count = 0
for i in range(n):
    if isPrime(int(input().rstrip())):
        count += 1
print(count)


Measured memory_bytes: 5676
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long n,m;
  cin>>n>>m;
  vector<int>a(n+2,0);
  for(int i=0;i<m;i++){
    int l,r;
    cin>>l>>r;
    a[l]++;
    a[r+1]--;
  }
  for(int i=1;i<n+2;i++){
    a[i]+=a[i-1];
  }
  long long kotae=0;
  for(int i=1;i<=n;i++){
    if(a[i]==m)kotae++;
  }
  cout<<kotae<<endl;
  return 0;
}



Measured memory_bytes: 3776
#include<stdio.h>
#include<string.h>
int main(void)
{
	char s[101];
	int k,len,i;
	scanf("%d %s",&k,s);
	len=strlen(s);
	if(len<=k){
		printf("%s\n",s);
	}
	else{
		for(i=0;i<k;i++){
			printf("%c",s[i]);
		}
		printf("...\n");
	}
	return 0;
}

Measured memory_bytes: 1648
using System;
using System.Collections.Generic;
using System.Linq;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            long ret = 0;
            for (int i = 0; i < N; i++)
            {
                var input = long.Parse(Console.ReadLine());
                if (i == 0)
                {
                    ret = input;
                    continue;
                }

                ret = Lcm(ret, input);
            }
            Console.WriteLine(ret);
        }        
        public static long Lcm(long a, long b)
        {
            return a * (b / Gcd(a, b));
        }
        public static long Gcd(long a, long b)
        {
            if (a < b)
                return Gcd(b, a);
            while (b != 0)
            {
                var remainder = a % b;
                a = b;
                b = remainder;
            }
            return a;
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define MAXX 500005
#define PI 3.14159265358979323846264338327950
#define F first
#define S second
#define ll   long long int
#define mod  1000000007



int main()
{
	FAST;
	ll n;
	cin >> n;
	n = (n-2) * 180;
	cout << n;
}

Measured memory_bytes: 3640
#pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <set>
#include <map>
#include <queue>
#include <cstring>
#include <cmath>
#include <bitset>
#include <iomanip>
//#include <unordered_map>

using namespace std;

template<typename T> void uin(T &a, T b) {if (b < a) a = b;}
template<typename T> void uax(T &a, T b) {if (b > a) a = b;}

#define double long double
#define right right228
#define mp make_pair
#define all(v) v.begin(), v.end()


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	int A = h1 * 60 + m1;
	int B = h2 * 60 + m2;
	cout << max(0, B - A - k) << '\n';
	return 0;
}

/*

1
3 2 2
1 2 3 1 
2 3 1 0
1
1 3

01.a
3 3 4
...
.#.
...
1 1 1 3 8 
1 3 1 3 64
2 1 1 3 24
2 1 3 3 40

3 4 3
1 2
2 2
2 4
3
1 1 1 4
2 2 3 3
3 2 2 4

*/


Measured memory_bytes: 3612
N = int(input())
C=list(input())
W=(C.count('W'))
R=N-W
WW=0
RR=0
X=[0]*(N-1)
if W>0 and R>0:
  for i in range(N-1):
    if C[i]=='W':
      WW+=1
    RR=(N-i-1)-(W-WW)
    X[i]=max(WW,RR)
print(min(X))

Measured memory_bytes: 18212
import std.algorithm;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.meta;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


void main() {
  int ans = 0;
  foreach (c; readln.chomp)
    if (c == '+')
      ans++;
    else
      ans--;
  ans.writeln;
}


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

const int MAX = 100;
long long dp[MAX];

long long fb(int n) {
  if (n < 2) {
    return 1;
  }
  if (dp[n] != 0) {
    return dp[n];
  } else {
    return dp[n] = fb(n-1) + fb(n-2);
  }
}

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



Measured memory_bytes: 3084
while True:
    try:
        x1,y1,x2,y2,x3,y3,xp,yp = map(float,raw_input().split())
        r = 0
        vec = (x2-x1) * (yp-y1) - (y2-y1) * (xp-x1)
        if vec > 0:
            r += 1
        elif vec < 0:
            r -= 1
        vec = (x3-x2) * (yp-y2) - (y3-y2) * (xp-x2)
        if vec > 0:
            r += 1
        elif vec < 0:
            r -= 1
        vec = (x1-x3) * (yp-y3) - (y1-y3) * (xp-x3)
        if vec > 0:
            r += 1
        elif vec < 0:
            r -= 1
        if r == 3 or r == -3:
            print("YES")
        else:
            print("NO")
    except EOFError:
        break

Measured memory_bytes: 4272
package main

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

func chmin(a *int, b int) bool {
	if *a > b {
		*a = b
		return true
	}
	return false
}
func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func newLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func main() {
	var n, k int
	inputLine := strings.Split(newLine(), " ")
	n, _ = strconv.Atoi(inputLine[0])
	k, _ = strconv.Atoi(inputLine[1])

	h := make([]int, n+200)
	inputLine = strings.Split(newLine(), " ")
	for i, v := range inputLine {
		h[i], _ = strconv.Atoi(v)
	}

	dp := make([]int, n+200)
	for i := 0; i < n+200; i++ {
		dp[i] = math.MaxInt64
	}
	dp[0] = 0

	for i := 0; i < n; i++ {
		for step := 1; step <= k; step++ {
			chmin(&dp[i+step], dp[i]+abs(h[i]-h[i+step]))

		}
	}
	fmt.Println(dp[n-1])
}


Measured memory_bytes: 5888
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
using namespace std;
using ll=long long;
#define mod  1000000007

int main(int argc, char const *argv[]) {
  int n;
  std::cin >> n;
  std::cout << n/3 << '\n';
  return 0;
}

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

int main() {
    int X; cin >> X;
    int now = X;
    long ureshisa = 0;
    while(true){
        if(now < 500){
            break;
        }
        else{
            now -= 500;
            ureshisa += 1000;
        }
    }
    while(true){
        if(now < 5){
            break;
        }
        else{
            now -= 5;
            ureshisa += 5;
        }
    }
    cout << ureshisa << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
using namespace std;

int n,a,x[55];
ll dp[55][55][2555];

int main() {
	#ifdef kvutxdy
	freopen("C:/Users/khanh/OneDrive/RoadtoPurple/Code/Codeforces/input.in", "r", stdin);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cin>>n>>a;
	for(int i=1;i<=n;++i) cin>>x[i];
	dp[0][0][0]=1LL;
	for(int i=1;i<=n;++i){
		for(int j=0;j<=i;++j){
			for(int k=0;k<=2500;++k){
				dp[i][j][k]=dp[i-1][j][k];
				if(j>0&&k-x[i]>=0) dp[i][j][k]+=dp[i-1][j-1][k-x[i]];
			}
		}
	}
	ll res=0LL;
	for(int i=1;i<=n;++i) res+=dp[n][i][a*i];
	cout<<res; 
}

Measured memory_bytes: 55552
N=int(input())
T,A=map(int,input().split())
H=[int(x) for x in input().split()]
s=float("inf")
j=0
for i in range(N):
  tempgap=abs(T-H[i]*0.006-A)
  if tempgap<s:
    s,j=tempgap,i
print(j+1)
  

Measured memory_bytes: 3060
package main

import (
	"fmt"

	"os"
	"io"
	"bufio"
	"bytes"

	"strings"
	"strconv"
	"math"
)

//  長い入力を読む
func ReadLongLines(times int) ([]string, error) {
	result := make([]string, times)
	reader := bufio.NewReader(os.Stdin)
	buffer := bytes.NewBuffer(make([]byte, 0))
	readBytes := int64(2)
	for i := 0; i < times; i++ {
		for {
			readBuf, isPrefix, err := reader.ReadLine()
			// fmt.Printf("Reader.Read: %d\n", len(readBuf))
			readBytes += int64(len(readBuf) + 1)
			if err != nil {
				if err == io.EOF {
					fmt.Println("EOF")
					break
				} else {
					return result, err
				}
			}
			_, err = buffer.Write(readBuf)
			if err != nil {
				return result, err
			}
			// end of line
			if !isPrefix {
				result[i] = buffer.String()
				buffer.Reset()
				// reader = bufio.NewReader(os.Stdin)
				break
			}
		}
	}
	// 先読みしてしまうようなので、戻しておく
	os.Stdin.Seek(-int64(reader.Buffered()), os.SEEK_CUR)
	return result, nil
}


// go だと固定長配列とか辛いので無理だった
type Queue struct {
	arr [] int
}
func NewQueue() Queue {
	q := Queue{make([]int, 1, 10000)}
	q.arr[0] = math.MinInt32
	return q
}

func (this *Queue)Insert(i int) {
	this.arr = append(this.arr, i)
	index := len(this.arr) - 1
	this.Build(index)
	this.Dump()
}

func (this *Queue)GetMax() int {
	return this.arr[1]
}

func (this *Queue) DeleteMax() {
	if 1 == len(this.arr) {
		return
	}
	this.arr[1] = this.arr[len(this.arr) - 1]
	this.arr = this.arr[:len(this.arr) -1]
	if 1 < len(this.arr) {
		this.Heapfy(1)
	}
	this.Dump()
}

func (this *Queue) Empty() bool {
	return  len(this.arr) <= 1
}

func (this *Queue) Dump() {
	// fmt.Println(this.arr)
}

func (this *Queue) Build(index int) {
	for {
		parent := index / 2
		if parent == 0 {
			return
		}
		if this.arr[parent] < this.arr[index] {
			this.arr[parent], this.arr[index] = this.arr[index], this.arr[parent]
		}
		index = parent
	}
}

func (this *Queue)Heapfy(index int) {
	if index == 0 {
		return
	}
	left := 0
	if (index) * 2 <= len(this.arr) - 1 {
		left = (index) * 2
	}
	right := 0
	if (index) * 2 + 1 <= len(this.arr) - 1 {
		right = (index) * 2 + 1
	}
	largest := index

	if this.arr[largest] < this.arr[left] {
		largest = left
	}
	if this.arr[largest] < this.arr[right] {
		largest = right
	}
	if largest != index {
		this.arr[index], this.arr[largest] = this.arr[largest], this.arr[index]
		this.Heapfy(largest)
	}
}



func main() {
	var n int
	var q int

	fmt.Scanf("%d %d", &n, &q)
	Queues := make([]Queue, n)
	for i := 0; i < n; i++ {
		Queues[i] = NewQueue()
	}
	lines, _ := ReadLongLines(q)
	for _, line := range lines {
		args := strings.Split(line, " ")
		cmd := args[0]
		switch cmd {
		case "0":
			t, _ := strconv.Atoi(args[1])
			x, _ := strconv.Atoi(args[2])
			// fmt.Printf("insert %d < %d\n", t, x)
			Queues[t].Insert(x)
		case "1":
			t, _ := strconv.Atoi(args[1])
			// fmt.Printf("getMax %d\n", t)
			if !Queues[t].Empty() {
				fmt.Println(Queues[t].GetMax())
			}
		case "2":
			t, _ := strconv.Atoi(args[1])
			// fmt.Printf("deleteMax %d\n", t)
			Queues[t].DeleteMax()
		}
	}
}


Measured memory_bytes: 29324
#include <iostream>
using namespace std;
int abs(int x)
{
  return (x>0)?(x):(-x);
}
int main(void)
{
  int N;
  cin >> N;
  for(int num = 0 ; num < N ; num++)
    {
      int m,n;
      cin >> m >> n;
      if(m*m + n*n <= 1)
	{
	  cout << "C" << endl;
	}
      else
	{
	  bool prime = true;
	  int  maxmn = (abs(m)>abs(n))?abs(m):abs(n);
	  for(int p = -maxmn ; p <= maxmn ; p++)
	    for(int q = -maxmn ; q <= maxmn ; q++)
	      {
		if((p*p + q*q > 0)
		   &&(   !(p ==  1 && q ==  0) && !(p ==  0 && q ==  1)
		      && !(p == -1 && q ==  0) && !(p ==  0 && q == -1)
		      && !(p ==  m && q ==  n) && !(p == -n && q ==  m)
		      && !(p == -m && q == -n) && !(p ==  n && q == -m))
		   &&((p*m + q*n) % (p*p + q*q) == 0)
		   &&((p*n - q*m) % (p*p + q*q) == 0))
		  {
		    prime = false;
		  }
	      }
	  cout << ((prime)?("P"):("C")) << endl;
	}
    }
  return 0;
}



Measured memory_bytes: 3068
def solve()
  input1 = readline()
  array = []
  cnt = 0

  for num in 0..3 do
    array.push(input1[num])
  end

  for i in 0..3 do
    if array.count(input1[i]) == 2 then
      cnt += 1
    end
  end

  if cnt == 4 then
    puts("Yes")
  else
    puts("No")
  end

end

solve()

Measured memory_bytes: 1788
import sys
input = lambda: sys.stdin.readline().rstrip()
N = int(input())
X, Y = [], []
for _ in range(N):
    x, y = map(int, input().split())
    X.append(x-1)
    Y.append(y-1)

IX = [0] * N
for i, x in enumerate(X):
    IX[x] = i

YY = [Y[IX[i]] for i in range(N)]
mi = N
L = []
I = [0] * N
T = []
for i, y in enumerate(YY):
    mi = min(mi, y)
    T.append(i)
    I[i] = len(L)
    if mi == N - 1 - i:
        L.append(T)
        T = []
if len(T):
    L.append(T)
print(*[len(L[I[X[i]]]) for i in range(N)], sep = "\n")

Measured memory_bytes: 135080
import math

if __name__ == "__main__":
    num = list(map(int, input().split()))

    a = num[0]
    b = num[1]
    h = num[2]
    m = num[3]

    deg = abs(30 * h + 0.5 * m - 6 * m)
    
    rad = math.radians(deg)
    
    c_2 = a * a + b * b - 2 * a * b * math.cos(rad)
    c = math.sqrt(c_2)

    print(c)


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

int main()
{
    ll k,x,y;
    cin>>k>>x>>y;
    if(k%2==0 &&(abs(x)+abs(y))%2==1)
    {
        cout<<-1<<endl;
        return 0;
    }
    else
    {
        ll fugoux=1,fugouy=1;
        bool swapflag = false;
        if(x<0)
        {
            fugoux=-1;
            x=-x;
        }
        if(y<0)
        {
            fugouy=-1;
            y=-y;
        }
        if(x<y)
        {
            swapflag=true;
            swap(x,y);
        }
        ll c = (k-(x+y)%k)%k;
        vector<pll> v;
        if(x+y<k && (x+y) % 2 ==1)
        {
            v.push_back(make_pair(x, -k+x));
            v.push_back(make_pair(x+(k+x-y)/2, (-k+x+y)/2));
            v.push_back(make_pair(x,y));
        }
        else
        {
            ll n;
            if(x+y<k && (x+y)%2==0)
            {
                n=2;
            }
            else
            {
                n = (x+y+k-1)/k;
                if(c%2==1) n++;                
            }
            
            ll p1 = -(n*k-x-y)/2;
            ll stage = 0;
            ll nowx=0, nowy=0;
            for (int i = 0; i < n; i++)
            {
                ll nextx=nowx, nexty=nowy;
                if(stage==0)
                {
                    if(x+y==k)
                    {
                        nextx=x;
                        nexty=y;
                    }
                    else if(nowy-k > p1)
                    {
                        nexty-=k;
                    }
                    else
                    {
                        nextx+=k-(nowy-p1);
                        nexty=p1;
                        stage++;
                    }
                }
                else if (stage==1)
                {
                    if(nowx+k<x)
                    {
                        nextx+=k;
                    }
                    else
                    {
                        nexty+=k-(x-nowx);
                        nextx=x;
                        stage++;
                    }
                    
                }
                else
                {
                    nexty+=k;
                }
                v.push_back(make_pair(nextx, nexty));
                nowx=nextx;
                nowy=nexty;
            }
            
        }

        cout<<v.size()<<endl;
        for (int i = 0; i < v.size(); i++)
        {
            ll xx = v[i].first;
            ll yy = v[i].second;
            if(swapflag) swap(xx,yy);
            xx*=fugoux;
            yy*=fugouy;
            cout<<xx<<" "<<yy<<endl;
        }
        
    }
    
    return 0;
}

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

//#include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// using cint = cpp_int;

// Define
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll MOD = 1e9 + 7;
const ll INF = LONG_MAX;
const ull MAX = ULONG_MAX;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define x first
#define y second
#define endl '\n'
#define space ' '
#define def inline auto
#define func inline constexpr ll
#define run __attribute__((constructor)) def _
#define all(v) begin(v), end(v)
#define input(a) scanf("%lld", &(a))
#define print(a) printf("%lld\n", (a))

// Debug
#define debug(...)                                                             \
    {                                                                          \
        cerr << __LINE__ << ": " << #__VA_ARGS__ << " = ";                     \
        for (auto &&X : {__VA_ARGS__}) cerr << "[" << X << "] ";               \
        cerr << endl;                                                          \
    }

#define dump(a, h, w)                                                          \
    rep(i, h) {                                                                \
        rep(j, w) cerr << a[i][j] << space;                                    \
        cerr << endl;                                                          \
    }
#define lldump(a, n) dump(vector<vector<ll>>{a}, 1, n)

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i <= _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i >= _##i; --i)
#define each(i, a) for (auto &&i : a)
#define rep(i, n) inc(i, 0, n - 1)
#define loop() for (;;)

// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)

// Speed
run() { fasten, fout(10); }
#pragma GCC optimize("O3")
#pragma GCC optimization_level 3
#pragma GCC target("avx")

// Math
func gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
func lcm(ll a, ll b) { return a * b / gcd(a, b); }
func sign(ll a) { return a ? abs(a) / a : 0; }

def in() {
    ll A;
    cin >> A;
    return A;
}

signed main() {
    ll res = 0;
    string s, t = "CODEFESTIVAL2016";
    cin >> s;
    rep(i, 16) if(s[i] != t[i]) res++;
    cout << res << endl;
}

// for compilation: g++ -Ofast -march=native -o _ _.cpp -std=c++17

Measured memory_bytes: 256
def main():
    n, k = map(int, input().split())
    print(solve(n, k))

def solve(n, k):
    r = (n // k) ** 3

    if k % 2 == 0:
        x = n // k
        if n % k >= k // 2:
            x += 1
        r += x ** 3

    return r

main()


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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define INFTY 999999

int main(void){
    int N;
    scanf("%d", &N);

    long* A;
    NEW(A,N);
    long* B;
    NEW(B,N);

    for(int i=0;i<N;i++){
        scanf("%ld", &A[i]);
    }
    for(int i=0;i<N;i++){
        scanf("%ld", &B[i]);
    }

    //A-Bが負になるもの(勉強足りない)ものの差の総和を格納する
    long long D=0;
    int d=0; //Dの要素数

    //A-Bが正になるもの(足りてる)を格納する
    long* P;
    NEW(P,N);
    int p=0; //Pの要素数

    for(int i=0;i<N;i++){
        if(A[i]<B[i]){
            D+=(-A[i]+B[i]);
            d++;
        }
        else if(A[i]>B[i]){
            P[p]=A[i]-B[i];
            p++;
        }
    }

    long max;
    int index;

    int ans=d;

    while(1){
        max=0;
        //Pの中で一番大きいP[i]を探す
        for(int i=0;i<p;i++){
            if(max<P[i]){
                max=P[i];
                index=i;
            }
        }
        if(max>0){
            if(D<=0){
                break;
            }
            D-=max;
            P[index]=0;
            ans++;
        }
        else{
            break;
        }
    }

    if(D<=0){
        printf("%d\n",ans);
    }
    else{
        printf("-1\n");
    }
    
    return 0;
    
}


Measured memory_bytes: 2176
#include<stdio.h>
int main()
{
    int c,a[10],i,j;
   for(i=0;i<=9;i++)
   {
       scanf("%d",&a[i]);
   }    for(i=0;i<10;i++)
    {
        for(j=i+1;j<10;j++)
        {
        if(a[i]<a[j])
        {
            c=a[i];
            a[i]=a[j];
            a[j]=c;
        }
        }
    }for(i=0;i<3;i++)
    {
    printf("%d\n",a[i]);

    }
    return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    //方針
    //毎日満足度は低下し続ける
    //満足度上昇の方法はコンテスト開催のみ
    //開催されてないコンテストを放置すると低下が著しくなる
    //実際にコンテストを開いた時の満足度上昇が最大のものを採用してみる
    //低下をなくせる分を上昇と捉えると、c_i(d-last(d,i)) + s_{d,i} だけペイすると考えられる？→あんまり適当じゃない
    int D;cin>>D;
    int c[26],last[26]={},s[365][26];
    REP(i,26) cin>>c[i];
    REP(i,D) REP(j,26) cin>>s[i][j];
    REP(i,D){
        int tmp = -1e9,res = 0;
        REP(j,26){
            int up = 0;
            REP(k,26){
                if(j==k) up += s[i][k];
                else up -= c[k]*(i-last[k]);
            }
            if(tmp < up){
                tmp = up;
                res = j;
            }
        }
        last[res] = i;
        cout<<res+1<<"\n";
    }
}


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

int main() {
    string s;
    cin >> s;
    if (s.length() < 26) {
        cout << s;
        for (char c = 'a'; c <= 'z'; c++) {
            if (s.find(c) == string::npos) { cout << c; break; }
        }
        return 0;
    }
    string tmp = s;
    bool t = next_permutation(s.begin(), s.end());
    if (!t) { cout << -1; return 0; }
    int cur = 0;
    while (cur < s.size() && s[cur] == tmp[cur]) cout << s[cur++];
    cout << s[cur];
    return 0;
}

Measured memory_bytes: 256
using System;
// using System.Collections.Generic;
// using System.Linq;

class Program
{
    static void Main()
    {
        int K = int.Parse(Console.ReadLine());
        string S = Console.ReadLine();
        if (S.Length <= K)
            Console.WriteLine(S);
        else
            Console.WriteLine(S.Substring(0, K) + "...");
        return;
    }
}

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

int main() {
    string s, ans;
    int k;
    cin >> k >> s;
    ans = s.substr(0, min(k, (int)s.length()));
    if(ans.length() < s.length()) ans += "...";
    cout << ans << endl;
}

Measured memory_bytes: 3600
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <random>
#include <bitset>
#include <time.h>
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
//#define endl '\n'
#define mp make_pair
#define pbc push_back
#define pob pop_back()
#define empb emplace_back
#define sp system("pause")
#define queuel queue<long long>
#define all(x) (x).begin(),(x).end()
#define matrix vector<vector<ll>>
#define pin(p) cin >> p.first >> p.second;
#define rev(v) reverse(v.begin(),v.end());
#define mx(v) max_element(v.begin(), v.end());
#define mn(v) min_element(v.begin(), v.end());
#define sout(s, c) for(auto i : s) cout << i << c;
#define pout(p) cout << p.first << " " << p.second;
#define er(v, l, r) erase(v.begin() + l, v.begin() + r);
#define vin(v) for(ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vout(v, c) for(int i = 0; i < v.size(); ++i) cout << v[i] << c;
#define pushi(v, a) for(int i = 0; i < a.size(); ++i) v.push_back(a[i]);
#define sin(s, n) for(int i = 0; i < n; ++i){int a; cin >> a; s.insert(a);}
#define fastio() ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);srand(time(NULL));
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
using namespace std;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
const ll INF = 1000LL * 1000 * 1000 * 1000 * 1000 * 1000;
const int inf = 1000 * 1000 * 1000;
const ld PI = acos(-1.0);
const ll mod1 = inf + 7;
const ll mod2 = inf + 9;
const int MAXN = 500001;
const ld EPS = 1e-9;
int hp = 179;

signed main()
{
	fastio();
	string s;
	cin >> s;
	if (s[0] != 'A')
	{
		cout << "WA";
		return 0;
	}
	if (s.back() == 'C')
	{
		cout << "WA";
		return 0;
	}
	int cnt = 0;
	for (int i = 1; i < s.size(); ++i)
	{
		
		if (i >= 2 && s[i] == 'C')
		{
			cnt++;
		}
		else if( tolower(s[i]) !=s[i])
		{
			cout << "WA";
			return 0;
		}
	}
	if (cnt != 1)
	{
		cout << "WA";
		return 0;
	}
	cout << "AC";
	system("pause");
}

Measured memory_bytes: 504
from bisect import bisect_left
import sys
input = sys.stdin.readline

N = int(input())
XD = [[int(i) for i in input().split()] for _ in range(N)]

mod = 998244353

XD.sort()

class SegTree:
  def __init__(self, n, v, f) :
    i = 1
    while i < n : 
      i <<= 1
    self.n = i
    self.v = v
    self.f = f
    self.tree = [v] * (i << 1)

  def update(self, i, x) :
    i += self.n - 1
    self.tree[i] = x
    while i > 0 :
      i = (i - 1) // 2
      self.tree[i] = self.f(self.tree[i * 2 + 1], self.tree[i * 2 + 2])

  # [l, r)
  def query(self, l, r) :
    l = l + self.n
    r = r + self.n
    s = self.v
    while l < r :
      if r & 1 :
        r -= 1
        s = self.f(s, self.tree[r - 1])
      if l & 1 :
        s = self.f(s, self.tree[l - 1])
        l += 1
      l >>= 1
      r >>= 1
    return s

INF = 1 << 60
ST = SegTree(N, -INF, max)

xs = [x for x, _ in XD]
for i in range(N - 1, -1, -1) :
  x, d = XD[i]
  j = bisect_left(xs, x + d)
  ST.update(i, max(i, ST.query(i, j)))

dp = [0] * (N + 1)
dp[N] = 1

for i in range(N) :
  dp[i] += dp[i - 1]
  dp[i] %= mod
  j = ST.query(i, i + 1)
  dp[j] += dp[i - 1]
  dp[j] %= mod

print(dp[N-1])

Measured memory_bytes: 99520
#include<bits/stdc++.h>
using namespace std;
const int N=105;
int n,m,f[N][N];
char s[N][N];
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)scanf("%s",s[i]+1);
	memset(f,0x3f,sizeof f);
	for (int i=n;i;i--)
		for (int j=m;j;j--)
			if (i==n&&j==m)f[i][j]=s[i][j]=='#';
			else f[i][j]=min(f[i+1][j]+((s[i][j]=='#')&&(s[i+1][j]!='#')),f[i][j+1]+((s[i][j]=='#')&&(s[i][j+1]!='#')));
	printf("%d\n",f[1][1]);
}


Measured memory_bytes: 256
def check(dic,index):
  ret = []
  for c in dic[index]:
    if c in dic.keys():
      for d in check(dic,c):
        if not(d in ret):
          ret.append(d)
    else:
      if not(c in ret):
        ret.append(c)
  dic[index] = ret
  return ret


while True:
  n = int(input())
  if n == 0:
    break
  dic = {}
  index = ''
  for i in range(n):
   a,b = [char for char in input()[0:-1].split(':')]
   if i == 0:
     index = a
   b = b.split(',')

   dic[a] = b
  #print(dic.keys())
  print(len(check(dic,index)))


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

int main(){

  int A,B,C;
  cin >>A >>B;
  C=A-2*B;
  if(C>0){
  cout <<C<<endl;
  }
  else{
  cout <<"0"<<endl;
  }
  return(0);
  
  
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        a: i64,
        b: i64,
        c: i64,
        d: i64,
    };
    let mut hpt = a;
    let mut hpa = c;
    for i in 0.. {
        if hpt <= 0 || hpa <= 0 {
            break;
        }
        if i % 2 == 0 {
            hpa -= b;
        } else {
            hpt -= d;
        }
    }
    println!("{}", if hpt > 0 { "Yes" } else { "No" });
}


Measured memory_bytes: 2104
#include <iostream>

using namespace std;

int s;

int function(int n) {
    if (n % 2 == 0) {
        return n / 2; 
    }
    else {
        return 3 * n + 1;
    }
}

int main()
{

    cin >> s;
    int count = 1;
    while (s != 4 && s != 2 && s != 1) {
        s = function(s);
        count++;
    }

    cout << count + 3 << endl;

    return 0;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using db = double;
using pll = pair < ll, ll >;
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
    cerr << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define trace(...)
#endif
 
#define pb push_back
#define mp make_pair
#define fastIo() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
 
const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e6 + 10;

ll cnt[N];

bool valid(ll a1) {
	if(cnt[a1] > 1) return false;

	for(ll i = 2; i*i <= a1; i++) {
		// trace(i, a1);
		if((a1%i == 0) && (cnt[a1/i] || cnt[i])) return false;
	}
	return true;
}

int main(){ 
	ll n; cin >> n;
	ll a[n];
	set<ll>st;
	for(ll i = 0; i < n; i++) {
		cin >> a[i];
		cnt[a[i]]++;
	}
	sort(a, a + n);
	if(cnt[1]) {
		if(cnt[1] < 2) {
			cout << 1 << endl;
		} else {
			cout << 0 << endl;
		}
	}
	else {
		ll ans = 0;
		for(ll i = 0; i < n; i++) {
			if(valid(a[i])) {
				ans++;
			}
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 12980
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000000002


int main(){
	int N;
	cin>>N;
	
	vector<long long> X(N),Y(N),P(N);
	for(int i=0;i<N;i++)cin>>X[i]>>Y[i]>>P[i];
	
	vector<long long> ans(N+1,Inf);
	
	for(int i=0;i<(1<<N);i++){
		vector<int> ind0,ind1;
		for(int j=0;j<N;j++){
			if((i>>j)&1)ind0.push_back(j);
			else ind1.push_back(j);
		}
		
		for(int j=0;j<(1<<ind0.size());j++){
			long long t = 0LL;
			for(int k=0;k<ind1.size();k++){
				long long xx = min(abs(Y[ind1[k]]),abs(X[ind1[k]]))*P[ind1[k]];;;
				for(int l=0;l<ind0.size();l++){
					if((j>>l)&1){
						xx = min(xx,abs(Y[ind1[k]]-Y[ind0[l]])*P[ind1[k]]);
					}
					else{
						xx = min(xx,abs(X[ind1[k]]-X[ind0[l]])*P[ind1[k]]);
					}
				}
				t+=xx;
				if(t>=ans[ind0.size()])break;
			}
			
			ans[ind0.size()] = min(ans[ind0.size()],t);
		}
	}
	
	for(int i=0;i<=N;i++)cout<<ans[i]<<endl;
			
	
	return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
#include <numeric>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<P> vp;
typedef vector<bool> vb;
#define rep(i, a, n) for (ll i = (a); i < (n); ++i)
#define rrep(i, a, n) for (ll i = (a); i > (n); --i)
#define erep(i, a, n) for (ll i = (a); i <= (n); ++i)
#define rerep(i, a, n) for (ll i = (a); i >= (n); --i)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define vec_max(V) *max_element(all(V))
#define vec_min(V) *min_element(all(V))
#define vec_sum(V) accumulate(all(V), 0LL)
#define print(X) cout << (X) << "\n"
#define _ << " " <<
#define Yes print("Yes")
#define No print("No")
static const int INF = 1e+9+7;

int main(){
  int N;
  cin >> N;
  int T,A;
  cin >> T >> A;
  double min = INF;
  int min_num = 0;
  rep(i,1,N+1){
    int H;
    cin >> H;
    if(abs(A - (T-H*0.006)) < min){
      min = abs(A - (T-H*0.006));
      min_num = i;
    }
  }
  print(min_num); 

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include<algorithm>
#include <cstdlib>
#include <cmath>

using namespace std;
int main()
{
	int a, b, h;
	cin >> a >> b >> h;
	int count = 3;
	if (a == b) count--;
	else if (a == h) count--;
	if (b == h) count--;
	cout<< count << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
sum = 0
ans = 0
for i in range(1, N):
   sum +=A[i-1]
   sum = sum % (10**9 + 7)
   ans = ans + (sum * A[i]) % (10**9 + 7)
   ans = ans % (10**9 + 7)
print(ans)

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

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

    int takahashiAttackCount = (c + b - 1) / b;
    int aokiAttackCount = (a + d - 1) / d;

    cout << (takahashiAttackCount <= aokiAttackCount ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3648
S = input()

tap_flag = True
for i in range(len(S)):
    if (i+1) % 2 == 0:
        if S[i] == "R":
            tap_flag = False
            break
    elif (i+1) % 2 == 1:
        if S[i] == "L":
            tap_flag = False
            break

if tap_flag == True:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<cmath>

using namespace std;

int main(){
 int n;
  cin >> n;
 string s;
  cin >>s; 
  
  int res=0;
  int cnt=0;
  for(int i=0;i<s.length();i++){
    if(s[i]=='I') cnt++;
    else cnt--;
    res=max(res,cnt);
  }
  
  cout << res << endl;

}

Measured memory_bytes: 256
# coding: utf-8

def main():
    n = int(input())
    a_array = list(map(int, input().split()))
    ans = 0
    for i in range(1, n):
        tmp = a_array[i-1] - a_array[i]
        if tmp > 0:
            ans += tmp
            a_array[i] += tmp
    print(ans)
main()


Measured memory_bytes: 32252
s = gets.chomp
st = []
s.chars{|c|st<<c}
a = 0
s.chars{|c|
  if st[-1] == c then
    st.pop
  else
    while st[-1]=='x'
      a+=1
      st.pop
    end
    if st[-1] == c then
      st.pop
    end
  end
  #p c,st
}

while st[-1]=='x'
  a+=1
  st.pop
end
#p st,a

if st.size>0 then
  p -1
else
  p a
end 

Measured memory_bytes: 9468
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
#define eps 1e-8
#define eq(x,y) (fabs((x)-(y)) < eps)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
const int mod = 1e9+7;
long double PI = acosl(-1);
const ll infl = 1e18+100;
const int inf = 2e9+100;
const int nmax = 2e5+5;
const int MAXLG = log2(nmax)+1;
//mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ost;


int sub[nmax];

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

    int n;
    cin>>n;
    for(int i=2; i<=n; i++){
        int x;
        cin>>x;
        sub[x]++;
    }

    for(int i=1; i<=n; i++) cout<<sub[i]<<"\n";
}


Measured memory_bytes: 4396
#include <bits/stdc++.h>
    using i64 = long long;
    using P = std::pair<int, int>;
     
    int main() {
        constexpr int inf = 100000000;
        int n, m;
        std::cin >> n >> m;
        std::vector<std::vector<int>> g(n);
        for (int i = 0; i < m; i++) {
            int a, b;
            std::cin >> a >> b;
            g[a - 1].push_back(b - 1);
        }
     
        int min = inf;
        std::vector<int> path;
        for (int s = 0; s < n; s++) {
            std::vector<int> dist(n, inf), prev(n, -1);
            std::priority_queue<P, std::vector<P>, std::greater<>> q;
            q.emplace(0, s);
            while (!q.empty()) {
                auto p = q.top();
                q.pop();
                // if (dist[p.second] < p.first) continue;
                for (auto to : g[p.second]) {
                    auto nc = p.first + 1;
                    if (dist[to] <= nc) continue;
                    dist[to] = nc;
                    prev[to] = p.second;
                    q.emplace(nc, to);
                }
            }
     
            if (dist[s] < min) {
                min = dist[s];
                path.clear();
                path.push_back(s);
                while (true) {
                    int v = prev[path.back()];
                    if (v == s) break;
                    path.push_back(v);
                }
            }
        }
     
        if (min == inf) {
            std::cout << -1 << std::endl;
        } else {
            std::cout << min << std::endl;
            for (auto v : path) std::cout << v + 1 << std::endl;
        }
     
        return 0;
    }

Measured memory_bytes: 256
mod = 10**9+7
n, K = map(int, input().split())
a = [[int(x) for x in input().split()] for _ in range(n)]

A = [a]

i = 1
while 2**i <= K:
    mtrix = []
    for j in range(n):
        raw = []
        for l in range(n):
            tmp = 0
            for k in range(n):
                tmp += A[-1][j][k] * A[-1][k][l]
            raw.append(tmp % mod)
        mtrix.append(raw)
    A.append(mtrix)
    i += 1

bit_max = i

ans = [[0]*n for _ in range(n)]
for i in range(n):
    for j in range(n):
        if i == j:
            ans[i][j] = 1

for i in range(bit_max):
    if (K >> i) & 1:
        mtrix = []
        for j in range(n):
            raw = []
            for l in range(n):
                tmp = 0
                for k in range(n):
                    tmp += ans[j][k] * A[i][k][l]
                raw.append(tmp % mod)
            mtrix.append(raw)
        ans = mtrix

ans = sum(map(lambda x: sum(x) % mod, ans))

print(ans % mod)


Measured memory_bytes: 70748
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline std::ostream& operator << (std::ostream& out, const std::vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }


int main() {
	IOS;
	int n, m;
	cin >> n >> m;
	int a = (n - 1) * n / 2;
	int b = (m - 1) * m / 2;
	put(a + b);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printInt(a) printf("%d\n", a)
#define printll(a) printf("%lld\n", a)
#define scanInt(a) scanf("%d", &a)
typedef long long ll;
using namespace std;

int main() {
    int n, s;
    ll total = 0;
    scanInt(n);
    vector<int> as(n);
    rep(i, n) {
        cin >> as.at(i);
    }
    sort(as.begin(), as.end(), greater<int>());
    for (int i = 1; i < n; ++i) {
        total += as[i/2];
    }
    printll(total);
    return 0;
}


Measured memory_bytes: 4080
package main

import "fmt"

var (
	a, b int
)

func main() {
	fmt.Scan(&a, &b)

	if a%3 == 0 || b%3 == 0 || (a+b)%3 == 0 {
		fmt.Println("Possible")
	} else {
		fmt.Println("Impossible")
	}
}

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

int main(){
 	int s1s2s3,s1,s2,s3;
  	cin>>s1s2s3;
  	s1=s1s2s3/100;
  	s2=s1s2s3/10%10;
  	s3=s1s2s3%10;
  	cout<<s1+s2+s3<<endl;
}

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

int A, B, Q;
vector<ll> s, t, x;

void shrine_temple(ll x) {
    auto east_shrine = lower_bound(s.begin(), s.end(), x);
    auto west_shrine = east_shrine - 1;
    auto east_temple = lower_bound(t.begin(), t.end(), x);
    auto west_temple = east_temple - 1;

    ll ans = INF;
    ll shrine[] = {*west_shrine, *east_shrine};
	ll temple[] = {*west_temple, *east_temple};
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            ans = min(abs(x - shrine[i]) + abs(shrine[i] - temple[j]), ans);
            ans = min(abs(x - temple[j]) + abs(temple[j] - shrine[i]), ans);
        }
    }
 
    cout << ans << endl;
}

int main() {
	cin >> A >> B >> Q;
    s.push_back(-INF);
	for (int i = 0; i < A; i++) {
        ll s_in;
        cin >> s_in;
        s.push_back(s_in);
    }
    s.push_back(INF);
    t.push_back(-INF);
	for (int i = 0; i < B; i++) {
        ll t_in;
        cin >> t_in;
        t.push_back(t_in);
    }
    t.push_back(INF);
    for (int i = 0; i < Q; i++) {
        ll x_in;
        cin >> x_in;
        x.push_back(x_in);
    }

    for (int i = 0; i < Q; i++) {
        shrine_temple(x[i]);
    }

    return 0;
}

Measured memory_bytes: 3828