akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

typedef struct {
    int ue, shita , migi, hidari, oku, temae;
    int men[7];
}Dice;

Dice initialization(Dice);
Dice North(Dice);
Dice East(Dice);
Dice South(Dice);
Dice West(Dice);
Dice TurnDice(Dice, int);

int main() {
    int i, n, key_ue, key_temae;
    Dice d1;

    for (i = 1; i <= 6; i++) {
        scanf("%d", &d1.men[i]);
    }

    scanf("%d", &n);

    for (i = 0; i < n; i++) {
         d1 = initialization(d1);
        scanf("%d%d", &key_ue, &key_temae);

        if (key_ue == d1.men[2]) {
            d1 = North(d1);
        }
        else if (key_ue == d1.men[3]) {
            d1 = West(d1);
        }
        else if (key_ue == d1.men[4]) {
            d1 = East(d1);
        }
        else if (key_ue == d1.men[5]) {
            d1 = South(d1);
        }
        else if (key_ue == d1.men[6]) {
            d1 = South(d1);
            d1 = South(d1);
        }

        d1 = TurnDice(d1, key_temae);

        printf("%d\n", d1.men[d1.migi]);
    }

    return 0;
}


Dice initialization(Dice d) {
    d.ue = 1;
    d.temae = 2;
    d.migi = 3;
    d.hidari = 4;
    d.oku = 5;
    d.shita = 6;

    return d;
}

Dice North(Dice d) {
    int temp;

    temp = d.ue;
    d.ue = d.temae;
    d.temae = d.shita;
    d.shita = d.oku;
    d.oku = temp;

    return d;
}

Dice East(Dice d) {
    int temp;

    temp = d.ue;
    d.ue = d.hidari;
    d.hidari = d.shita;
    d.shita = d.migi;
    d.migi = temp;

    return d;
}

Dice South(Dice d) {
    int temp;

    temp = d.ue;
    d.ue = d.oku;
    d.oku = d.shita;
    d.shita = d.temae;
    d.temae = temp;

    return d;
}

Dice West(Dice d) {
    int temp;

    temp = d.ue;
    d.ue = d.migi;
    d.migi = d.shita;
    d.shita = d.hidari;
    d.hidari = temp;

    return d;
}

Dice TurnDice(Dice d, int key) {
    int temp;

    while (d.men[d.temae] != key) {
        temp = d.temae;
        d.temae = d.migi;
        d.migi = d.oku;
        d.oku = d.hidari;
        d.hidari = temp;
    }
    return d;
}


Measured memory_bytes: 2120
package main

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

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

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

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

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

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

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

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

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

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

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	rr := make(RR, n)
	for i := 0; i < n; i++ {
		rr[i].x = getNextInt(scanner)
		rr[i].ll = getNextInt(scanner)
		rr[i].l = rr[i].x - rr[i].ll
		rr[i].r = rr[i].x + rr[i].ll
	}
	sort.Sort(rr)
	max := -math.MaxInt32
	ans := 0
	for i := 0; i < n; i++ {
		ans++
		if max <= rr[i].l {
			max = rr[i].r
		} else {
			ans--
			if max == -math.MaxInt32 || max > rr[i].r {
				max = rr[i].r
			}
		}
	}
	fmt.Fprintln(writer, ans)

}

type Robot struct {
	x, l, r, ll int
}

type RR []Robot

func (a RR) Len() int           { return len(a) }
func (a RR) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a RR) Less(i, j int) bool { return a[i].l < a[j].l }


Measured memory_bytes: 7168
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{try{BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	long x;
	x=Long.parseLong(br.readLine());
	long sum =( (x/500)*1000)+((x%500)/5)*5;
	System.out.print(sum);}catch (Exception e){}
	
		
	}
}

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

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



Measured memory_bytes: 256
import numpy as np

N, W = map(int, input().split())
dp = np.zeros(W + 1, dtype=np.int64)
for _ in range(N):
    w, v = map(int, input().split())
    np.maximum(dp[:-w] + v, dp[w:], out=dp[w:])

print(dp[-1])


Measured memory_bytes: 14572
a,b,c = map(int, input().split())

if a%2==0 or b%2==0 or c%2==0:
	print(0)
else:
	print(min(abs(((a//2)*b*c) - ((a-a//2)*b*c)), abs(((b//2)*a*c) - ((b-b//2)*a*c)), abs(((c//2)*a*b) - ((c-c//2)*a*b))))
	

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

void search(int **a, int n, int *d, int *f, int u, int *t) {
  int i;
  d[u] = *t;
  (*t)++;
  for (i = 0; i < n; i++) {
    if(a[u][i] == 1 && d[i] == 0) {
      search(a,n,d,f,i,t);
    }
  }
  f[u] = *t;
  (*t)++;	
}

int main()
{
  int i,j,n,**a,u,k,v;
  scanf("%d",&n);
  a = (int**)malloc(sizeof(int*) * n);
  for (i = 0; i < n; i++) {
    a[i] = (int*)malloc(sizeof(int) * n);
    for(j = 0; j < n; j++) a[i][j] = 0;
  }
  for (i = 0; i < n; i++) {
    scanf("%d",&u);
    scanf("%d", &k);
    for(j = 0; j < k; j++){
      scanf("%d",&v);
      a[u-1][v-1] = 1;
    }
  }

  int *d,*f,t;
  d = (int*)calloc(n,sizeof(int));
  f = (int*)calloc(n,sizeof(int));
  t = 1;

  for (i = 0; i < n; i++) {
    if(d[i] == 0) {
      search(a,n,d,f,i,&t);
    }
  }


  for (i = 0; i < n; i++) {
    printf("%d ", i+1);
    printf("%d ", d[i]);
    printf("%d\n", f[i]);
  }

  free(a);
  free(d);
  free(f);
  return 0;
}

Measured memory_bytes: 652
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
lli mod=1000000007;

int main()
{
	ios_base::sync_with_stdio(false); 
	lli a,b;
	cin>>a>>b;
	lli end=(b+1)*10;
	for(lli i=0;i<end;++i){
		lli t1=8*i;
		lli t2=10*i;
		t1/=100;
		t2/=100;
		if(t1==a&&t2==b){
			cout<<i<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0}, dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	int a, b, c, d, e;
	cin >> a >> b >> c >> d >> e;
	int n = (c * 60 + d) - (a * 60 + b) - e;
	cout << max(0, n) << endl;

	return 0;
}

Measured memory_bytes: 3652
package main

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

const (
	maxBufSize = 1024 * 1024
)

var (
	sc = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, 1)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
	out = bufio.NewWriter(os.Stdout)
)

type cake struct {
	idx int
	count int64
}

func solve(k int64, t int64, as []int64) int64 {
	if t == 1 {
		return k - 1
	}

	cs := make([]cake, t)
	for i, a := range as {
		cs[i].idx = i
		cs[i].count = a
	}
	sort.Slice(cs, func(i, j int) bool {
		return cs[i].count > cs[j].count
	})
	ret := int64(0)
	prevIdx := -1
	for ;;{
		if cs[0].idx != prevIdx {
			cs[0].count --
			prevIdx = cs[0].idx
			if cs[0].count < cs[1].count {
				sort.Slice(cs, func(i, j int) bool {
					return cs[i].count > cs[j].count
				})
			}
			continue
		}

		if cs[1].count == 0 {
			ret += cs[0].count
			break
		}

		cs[1].count --
		prevIdx = cs[1].idx
		if t > 2 && cs[1].count < cs[2].count {
			sort.Slice(cs, func(i, j int) bool {
				return cs[i].count > cs[j].count
			})
		}
	}
	return ret
}

func main() {
	defer out.Flush()

	k := nextInt()
	t := nextInt()
	as := nextInts(t)
	res := solve(k, t, as)
	fmt.Fprintln(out, res)
}

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

func nextStringAsBytes() []byte {
	sc.Scan()
	return []byte(sc.Text())
}

func nextInt() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int64) []int64 {
	ret := make([]int64, n)
	for i := int64(0); i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

func nextFloats(n int64) []float64 {
	ret := make([]float64, n)
	for i := int64(0); i < n; i++ {
		ret[i] = nextFloat()
	}
	return ret
}
func nextStrings(n int64) []string {
	ret := make([]string, n)
	for i := int64(0); i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func containStr(arr []string, target string) bool {
	for _, v := range arr {
		if v == target {
			return true
		}
	}
	return false
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "orz")
	}
}

// mapからkeysとvaluesを返す
func splitKeyValue(m map[interface{}]interface{}) (keys, values []interface{}) {
	switch reflect.TypeOf(m).Kind() {
	case reflect.Map:
		s := reflect.ValueOf(m)
		for _, v := range s.MapKeys() {
			keys = append(keys, v)
			values = append(values, s.MapIndex(v))
		}
	default:
		fmt.Fprintln(out, "orz")
	}
	return
}


Measured memory_bytes: 2736
import java.util.Scanner

fun main (args: Array<String>) {
  val scan = Scanner(System.`in`)
  val input1 = scan.nextInt()
  val input2 = scan.nextInt()
  val 面積 = input1 * input2
  val 週の長さ = (input1 * 2) + (input2 * 2)
  println("$面積 $週の長さ")
}


Measured memory_bytes: 27512
H, W = map(int, input().split())

if H%3 == 0 or W%3 == 0:
    print (0)
elif H == W:
    if H%2 == 0:
        print (H//2)
    else:
        print (H-((2 * H)//6 - H//6))
elif H%3 == 2 and W%3 == 2:
    if H%2 == 0 and W%2 == 0:
        print (min(H//2, W//2))
    else:
        if H%2 == 0:
            print (H//2)
        elif W%2 == 0:
            print (W//2)
        else:
            print (min(H, W))
elif H%3 == 1 and W%3 == 1:
    if H%2 == 0 and W%2 == 0:
        print (min(H//2, W//2))
    else:
        if H%2 == 0:
            print (H//2)
        elif W%2 == 0:
            print (W//2)
        else:
            print (min(H,W))
else: #この部分に間違い有り
    if H%2 == 0 and W%2 == 0:
        print (min(H//2, W//2))
    else:
        if H%2 == 0:
            print (min(H//2, H, W))
        elif W%2 == 0:
            print (min(W//2, H, W))
        else:
            print (min(H, W))


Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<numeric>
 
using namespace std;
int main(){
int h,n;
cin >> h >> n;
  vector<int> a;
  while(n > 0){
    int temp;
    cin >> temp;
   a.push_back(temp);    
    n--;
  }
  (accumulate(a.begin(),a.end(),0) < h)? cout << "No\n" : cout <<"Yes\n";
 
return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}


char m[10][10];


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

  ll H, W; cin >> H >> W ;
  rep(i,H){
    string str; cin >> str;
    rep(j,W){
      m[i][j] = str[j];
    }
  }
  
  pair<ll,ll>  now = mp(0,0);
  
  while(1){
    ll x = now.first, y = now.second;
    m[x][y] = '.';
    if(now == mp(H-1, W-1)){
      break;
    }
    else if(m[x+1][y] == '#'){
      now.first ++;
      continue;
    }
    else if(m[x][y+1] == '#'){
      now.second ++;
      continue;
    }
    else{
      cout << "Impossible" << endl;
      return 0;
    }
  }

  rep(i,H) rep(j,W) if(m[i][j] == '#' ){cout << "Impossible" << endl; return 0;}

  cout << "Possible" << endl;
    
  //cout << fixed << setprecision(16) << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<map>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<fstream>
#include<iostream>
#include<algorithm>
using namespace std;
char nm[150][150];
int n,m;
int dx[8]={0,0,1,-1,-1,1,1,-1};
int dy[8]={1,-1,0,0,1,1,-1,-1};
int dfs(int x,int y){
	int sum=0;
	for(int i=0;i<8;i++){
		if(nm[x+dx[i]][y+dy[i]]=='#')
		    sum++;
	}
	return sum;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%s",nm[i]);
    }
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(nm[i][j]=='.')
				printf("%d",dfs(i,j));
			else if(nm[i][j]=='#')
			    printf("%c",nm[i][j]);
		}
		printf("\n");
	}
}

Measured memory_bytes: 256
#include <stdio.h>

int main() 
{
  int n;
  int i;
  int cnt;
  int t1, t2;
  scanf("%d", &n);
  cnt = 0, t1 = -1;
  for (i = 0; i < n; i++) {
    scanf("%d", &t2);
    if (t1 == t2) cnt++, t1 = -1;
    else t1 = t2;
  }
  printf("%d\n", cnt);
  return 0;
}
  

Measured memory_bytes: 128
#include <iostream>
#include <vector>

using namespace std;

int main()
{
  int n, m, k;

  while(cin>>n>>k>>m && (n+m+k)){
    vector<int> vec;
    for(int i = 1; i <= n; i++){
      vec.push_back(i);
    }
    m--;
    k--;
    vec.erase(vec.begin()+(m%vec.size()));
    while(vec.size() > 1){
	m += k;
	m %= vec.size();
	vec.erase(vec.begin()+m);
    }
    
    cout << vec[0] << endl;
  }

  return 0;
}

Measured memory_bytes: 1012
//不等,不问,不犹豫,不回头.
//挺秒的数学题,首先我们可以思考到将连续且颜色相同的块捆绑起来.这样方便统计答案
//设我们分成了t份,容易发现对答案的贡献就是n-t,这其实很好想,对于每一块的第一块不统计答案,每一份中多来一块就
//和前面的块贡献答案.转换成这样容我们容易统计答案.其实这源于一段连续颜色相同的块对答案的贡献是块数-1.
//这启示我们将颜色相同且连续的块捆绑即可.之后题目要求至多有k对,则n-t<=k.得t>=n-k.
//考虑对于每一个t我们如何求得答案,首先解决每一份的块数问题,设xi为第i份的块数.则有x1+x2+...+xt=n.
//求x>=1的方案数,傻逼的我还不知道这是啥....不就是典型的隔板法吗？qwq.....被自己的蠢哭晕...
//之后考虑颜色的问题,我们只要求相邻两份之间颜色不同即可.第一份有m中选择,之后的每一份只要与前一份不同即可.
//故颜色的贡献为m*(m-1)^t.所有总的贡献为(n-1,t-1)*m*(m-1)^(t-1). 
#include<bits/stdc++.h>
#define _ 0
#define db double
#define RE register
#define ll long long
#define P 998244353
#define INF 1000000000
#define get(x) x=read()
#define PLI pair<ll,int>
#define PII pair<int,int>
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define pb(x) push_back(x)
#define ull unsigned long long
#define getc(c) scanf("%s",c+1)
#define put(x) printf("%d\n",x)
#define putl(x) printf("%lld\n",x)
#define rep(i,x,y) for(RE int i=x;i<=y;++i)
#define fep(i,x,y) for(RE int i=x;i>=y;--i)
#define go(x) for(int i=link[x],y=a[i].y;i;y=a[i=a[i].next].y)
using namespace std;
const int N=2e5+10;
ll jc[N],jcn[N],n,m,k; 

inline ll read()
{
	ll x=0,ff=1;
	char ch=getchar();
	while(!isdigit(ch)) {if(ch=='-') ff=-1;ch=getchar();}
	while(isdigit(ch)) {x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	return x*ff;
}

inline ll power(ll x,ll y)
{
	ll ans=1;
	while(y)
	{
		if(y&1) ans=ans*x%P;
		y>>=1;
		x=x*x%P;
	}
	return ans;
}

inline ll C(int n,int m){return jc[n]*jcn[m]%P*jcn[n-m]%P;}

int main()
{
	///freopen("1.in","r",stdin);
	get(n);get(m);get(k);
	jc[0]=1;jcn[0]=1;
	rep(i,1,n) jc[i]=i*jc[i-1]%P,jcn[i]=power(jc[i],P-2);
	ll ans=0;
	rep(t,n-k,n) ans=(ans+C(n-1,t-1)*m%P*power(m-1,t-1)%P)%P;
	putl(ans); 
	return (0^_^0);
}
//以吾之血,祭吾最后的亡魂







Measured memory_bytes: 6852
#![allow(unused_imports)]
#![allow(non_snake_case)]

use procon::*;
use std::cmp::{max, min};
use std::collections::*;
use std::ops::*;
use std::*;

pub fn main() {
    let words = read_words::<i64>();
    let (A, B, _, K) = (words[0], words[1], words[2], words[3]);
    let parity = K % 2;
    println!("{}", if parity == 0 { A - B } else { B - A });
    return;
}

pub mod procon {
    use std;
    use std::collections::*;
    use std::io;
    use std::mem;
    use std::str::FromStr;

    pub fn read_line() -> String {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        buf.trim_right().to_owned()
    }

    pub fn read_words<T>() -> Vec<T>
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        buf.split_whitespace()
            .map(|word| T::from_str(word).unwrap())
            .collect()
    }

    pub fn read_vec(len: usize) -> Vec<String> {
        let mut vec = Vec::new();
        while vec.len() < len {
            let line = read_line();
            for word in line.split_whitespace() {
                vec.push(word.to_owned());
            }
        }
        assert!(vec.len() == len);
        vec
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#include<numeric>
#include<cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#define ll long long int
#define CON 100010
const long long mod=1e9+7;
const int INF=1001001001;
//const int inf=100000;
//const ll ful=1e18;
using namespace std;
//namespace mp = boost::multiprecision;
int main() 
{
	int n;
	cin>>n;
	int size=n*2;
	pair<int,int> p[n];
	for(int i=0;i<n;++i)
	{
		cin>>p[i].first>>p[i].second;
	}
	bool flag=false;
	for(int i=0;i<n-2;++i)
	{
		if(p[i].first==p[i].second&&p[i+1].first==p[i+1].second&&p[i+2].first==p[i+2].second)
		{
			flag=true;
		}
	}
	if(flag)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3616
#include<stdio.h>

int main(){
  
  int K, S, Sum = 0;
  scanf("%d%d",&K,&S);
  
  for(int i=0; i<=K; i++){
    for(int j=0; j<=K; j++){
      if(S-i-j<=K && S-i-j >= 0) Sum++;
    }
  }
  printf("%d\n", Sum);
  return 0;
}

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

#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;cin >> s;
    ll n = s.size();
    int ans=0;
    rep(i,0,n){
        if(s[i] - '0'> 5 || ((s[i]-'0')== 5 && i<n-1 && (s[i+1]-'0') > 4)){
            ans +=2; //1つ上の桁を払う
            bool ok = true;
            while(i<n && ((s[i]-'0')>4  || (((s[i]-'0')==4 && i<n-1 && (s[i+1]-'0')>4)))){
                ans += (9-(s[i]-'0'));
                i++;
                ok = false;
            }
            if(ok) ans -= 2;
            if(i<n) ans+= s[i]-'0';
        }
        else if(i<n) ans += (s[i]-'0');
    }
    cout << ans << endl;
}

Measured memory_bytes: 1948
ls = list(map(int,input().split()))
ls.sort(reverse=True)
ans = 0
div1 = ls[0]-ls[1]
div2 = ls[1]-ls[2]
ans += div1
if div2 % 2== 0:
    ans += div2//2
else:
    ans += div2//2+2
print(ans)

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

int table[100][100];
int d[100];//????°??????¢
bool used[100];
int v;
const int INF = 10000000;

int prim(){
  fill(d,d+v,INF);
  fill(used,used+v,false);
  d[0] = 0;
  int res = 0;

  while(1){
    int k=-1;
    //???????±???????????????????????????????????????????????????????????°?????????????????????¢???
    for(int i=0;i<v;i++){
      if(!used[i] && (k==-1 || d[i] < d[k])) k=i;
    }

    if(k==-1) break;
    used[k] = true;
    res += d[k];

    for(int i=0;i<v;i++){
      if(table[k][i] != -1){
        d[i] = min(d[i],table[k][i]);
      }
    }
  }
  return res;
}

int main(){

    cin >> v;

    for(int i=0;i<v;i++){
      for(int j=0;j<v;j++){
        cin >> table[i][j];
      }
    }

    cout << prim() << endl;

    return 0;
}

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

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i ,a, b) for (int i = a ; i <= b ; i++)
#define sz(a) int(a.size())
#define cuti(a) cout << a << endl;
#define cutii(a,b) cout << a << " " << b << endl;
#define cutiii(a,b,c) cout << a << " " << b << " " << c << endl;
#define vec(a) vector<int > a;

template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }

typedef long long LL;
typedef pair<int ,int > pii;
typedef pair<string ,int > psi;
typedef pair<string ,string > pss;
typedef pair<LL, LL> pLL;

const long long oo = 1e9 + 7;
const double PI = acos(-1.0);

double DEG_to_RAD(double d) { return d * PI / 180.0; }

int n;

int main(){
   // freopen("test.txt","r",stdin);
    cin >> n;
    n = 2*24 - n;
    cout <<n << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

typedef struct
{
    char line[1002];
} line_st;

void print(char *str, char *args)
{
    int a, b;
    sscanf(args, "%d %d", &a, &b);
    for (char *elm = str + a, *const end = str + b + 1; elm != end; ++elm)
    {
        printf("%c", *elm);
    }
    printf("\n");
}

void reverse(char *str, char *args)
{
    int a, b;
    sscanf(args, "%d %d", &a, &b);
    for (char *from = str + a, *to = str + b; from < to; ++from, --to)
    {
        char c = *to;
        *to = *from;
        *from = c;
    }
}

void replace(char *str, char *args)
{
    int a, b;
    char p[1001] = {};
    sscanf(args, "%d %d %s", &a, &b, p);
    for (char *elm = str + a, *const end = str + b + 1, *src = p; elm != end; ++src, ++elm)
    {
        *elm = *src;
    }
}

int main(int argc, char *argv[])
{
    char str[1002] = {};
    if (fgets(str, 1002, stdin))
    {
        int q;
        scanf("%d", &q);
        getchar();
        line_st lines[100] = {};
        for (line_st *elm = lines, *const end = elm + q; elm != end; ++elm)
        {
            fgets(elm->line, 1002, stdin);
        }
        for (line_st *elm = lines, *const end = elm + q; elm != end; ++elm)
        {
            char *command = strtok(elm->line, " \n");
            void (*func)(char *, char *) = !strcmp(command, "print"  ) ? print :
                                           !strcmp(command, "reverse") ? reverse :
                                           !strcmp(command, "replace") ? replace : NULL;
            if (func)
            {
                func(str, elm->line + strlen(command) + 1);
            }
        }
    }
    return 0;
}



Measured memory_bytes: 2136
def main():
    N, M = (int(i) for i in input().split())
    ab = [tuple(int(i) for i in input().split()) for j in range(M)]

    dist = 1
    ans = 0
    ab.sort(key=lambda p: p[1])
    for a,b in ab:
        if dist <= a:
            ans += 1
            dist = b
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 62040
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
using namespace std;
const ll N=500010;

ll power(ll x,ll n)
{
    if(n==0){return 1;}
    if(n==1){return x;}
    if(n%2==0){
        return power((x*x)%M,n/2);
    }
    if(n%2==1){
        return (power((x*x)%M,n/2)*x)%M;
    }
}

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

    vector<ll> fac(N);
    fac[0]=1;
    for(ll i=1;i<N;++i){
        fac[i]=(i*fac[i-1])%M;
    }

    ll n,k;
    cin>>n>>k;

    ll pre[n+1]={0};
    pre[k-2]=1;
    for(ll i=k-1;i<=n;++i)
    {
        ll num=fac[i];
        ll denum=(fac[k-2]*fac[i-k+2])%M;
        pre[i]=(num*power(denum,M-2))%M;
    }
    ll sum[n+1]={0};
    sum[0]=pre[0];
    for(ll i=1;i<=n;++i)
    {
        sum[i]=(sum[i-1]+pre[i])%M;
    }
    ll ans=0;
    ll ar[n];
    for(ll i=0;i<n;++i){cin>>ar[i];}
    sort(ar,ar+n);
    for(ll i=0;i<n;++i)
    {
        ll left=i-k+1;
        ++left;
        left=max(left,0LL);
        if(left>0)
        {
            ll ch=sum[k-3+left];
            //cout<<"!!+ "<<i<<" "<<ch<<" "<<left<<endl;
            ch=(ch*ar[i])%M;
            ans=(ans+ch)%M;
        }
        left=i+k-1;
        if(left<=n-1)
        {
            left=n-left;
            ll ch=sum[k-3+left];
            //cout<<"!!- "<<i<<" "<<ch<<endl;
            ch=(ch*ar[i])%M;
            ans=(ans-ch+M)%M;
        }
    }
    cout<<ans;

    return (0);
}


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

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

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

#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);

  int N, A, B;
  cin >> N >> A >> B;
  cout << min(A * N, B) << endl;
  return 0;
}

Measured memory_bytes: 256
/*! path: /home/ts3min/work/tspro/src/contest/atcoder/msol2020/b.ts */!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";(function(e){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.main=void 0;const o=r(n(2)),u=n(3);function i(e){const t=u.getNextInt(e),n=t(),r=t(),o=t(),i=t();console.log(function({A:e,B:t,C:n,K:r}){let o=0;for(;t<=e;)o++,t*=2;for(;n<=t;)o++,n*=2;return o<=r?"Yes":"No"}({A:n,B:r,C:o,K:i}))}if(t.main=i,n.c[n.s]===e){i(o.default.readFileSync("/dev/stdin","utf8"))}}).call(this,n(1)(e))},function(e,t){e.exports=function(e){return e.webpackPolyfill||(e.deprecate=function(){},e.paths=[],e.children||(e.children=[]),Object.defineProperty(e,"loaded",{enumerable:!0,get:function(){return e.l}}),Object.defineProperty(e,"id",{enumerable:!0,get:function(){return e.i}}),e.webpackPolyfill=1),e}},function(e,t){e.exports=require("fs")},function(e,t,n){"use strict";function*r(e){const t=e.split(/\s+/);for(const e of t)yield e}Object.defineProperty(t,"__esModule",{value:!0}),t.getNextBigInt=t.getNextInt=t.getNext=t.getIteratorWithParser=t.getIterator=void 0,t.getIterator=r,t.getIteratorWithParser=function*(e,t){const n=e.split(/\s+/);for(const e of n)yield t(e)},t.getNext=function(e){const t=r(e);return()=>t.next().value},t.getNextInt=function(e){const t=r(e);return()=>parseInt(t.next().value)},t.getNextBigInt=function(e){const t=r(e);return()=>BigInt(t.next().value)}}]);
//# sourceMappingURL=submit.js.map

Measured memory_bytes: 29828
import * as readline from "readline";

/* ここに処理を書く */
const sumStrInt = (a: string, b: string): string => {
  let lArray: string[], sArray: string[];
  if (parseInt(a) >= parseInt(b)) {
    lArray = a.split("").reverse();
    sArray = b.split("").reverse();
  } else {
    lArray = b.split("").reverse();
    sArray = a.split("").reverse();
  }

  let resArray: string[] = ["0"];
  for (let i = 0; i < lArray.length; i++) {
    const li: number = parseInt(lArray[i]);
    const si: number = i < sArray.length ? parseInt(sArray[i]) : 0;
    const ri: number = parseInt(resArray[i]);

    const y: number = li + si + ri;
    resArray[i] = (y % 10).toString();
    resArray.push(10 <= y ? "1" : "0");
  }

  resArray = resArray.reverse();
  if (resArray[0] === "0") resArray = resArray.slice(1);
  const str: string = resArray.reduce((acc: string, cur: string) => acc + cur);

  return str;
};

const main = (args: any[]) => {
  const N = args[0];

  const list: string[] = ["2", "1"];
  for (let i = 2; i <= N; i++) {
    list.push(sumStrInt(list[i - 1], list[i - 2]));
    // console.log(list[i], list[i - 1], list[i - 2]);
  }
  console.log(list[N]);
  return;
};

/* 標準入力処理 */
const stdin = (main: Function) => {
  const args: any[] = [];
  const reader = readline.createInterface({
    input: process.stdin,
    output: process.stdout
  });
  reader.on("close", function() {
    main(args);
  });
  reader.on("line", function(line: any) {
    if (line === "") {
      reader.close();
    }
    line.split(" ").forEach((arg: any) => {
      args.push(isNaN(arg) ? arg : Number(arg));
    });
  });
};
/* 実行 */
stdin(main);


Measured memory_bytes: 7756
#include<iostream>
using namespace std;
int main(){
 	int a,b,s;
  	cin>>a>>b;
  	if(a>b){
    	 cout<<2*a-1;
    }else if(a==b){
    	cout<<2*a;
    }else{
     	cout<<2*b-1; 
    }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
using namespace std;
#define ll long long
int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int x1 = c/b;
    if (c%b!=0) x1++;
    int x2 = a/d;
    if (a%d!=0) x2++;
    if (x1<=x2) cout << "Yes";
    else cout << "No";
    return 0;
}







Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define LL long long int

class F {
private:
    multiset<int> lowA, highA;
    LL sumA, sumLowA, sumHighA, sumB;

public:
    F() {
        sumA = sumLowA = sumHighA = sumB = 0;
    }

    void insert(int a, int b) {
        if (lowA.size() > 0 && a <= *lowA.rbegin()) {
            lowA.insert(a);
            sumLowA += a;

            //balancing
            while (lowA.size() - highA.size() > 1) {
                auto ptr = --(lowA.end());
                int val = *ptr;

                lowA.erase(ptr);
                sumLowA -= val;

                highA.insert(val);
                sumHighA += val;
            }
        } else {
            highA.insert(a);
            sumHighA += a;

            //balancing
            while (highA.size() > lowA.size()) {
                auto ptr = highA.begin();
                int val = *ptr;

                highA.erase(ptr);
                sumHighA -= val;

                lowA.insert(val);
                sumLowA += val;
            }
        }

        sumB += b;
    }

    pair<int, LL> query() {
        int szLow = (int) lowA.size();
        int szHigh = (int) highA.size();

        int x = *lowA.rbegin();

        LL result = ((LL) x * szLow - sumLowA) + (sumHighA - (LL) x * szHigh) + sumB;
        return {x, result};
    }
};

int Q;
F f = F();

int main() {
    scanf("%d", &Q);
    for (int q = 1; q <= Q; q++) {
        int t, a, b;
        scanf("%d", &t);

        if (t == 1) {
            scanf("%d%d", &a, &b);
            f.insert(a, b);
        } else {
            auto answer = f.query();
            printf("%d %lld\n", answer.first, answer.second);
        }
    }
}


Measured memory_bytes: 9600
#include<stdio.h>
int main()
{
	long long int a;
	scanf("%lld", &a);
	char bb[102];
	scanf("%s", bb);
	long long int b = 0;
	int i;
	for (i = 0; bb[i] != '\0'; i++)
	{
		if (bb[i] != '.')
		{
			b = 10 * b + bb[i] - '0';
		}
	}
	printf("%lld\n", a * b / 100);
	return 0;
}

Measured memory_bytes: 1704
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;
const int mod = MOD7;

void ERROR(int num) { cout << "ERROR" << num << endl; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};

vector<vector<int>> G;

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

    int N, M;
    cin >> N >> M;
    G.resize(N);
    rep(i,M){
    	int a, b;
    	cin >> a >> b;
    	a--, b--;
    	G[a].pb(b);
    	G[b].pb(a);
    }

	queue<int> que;
	que.push(0);
	vector<int> vis(N,-1);
	vector<int> pre(M,-1);
	vis[0] = 0;
	while(!que.empty()){
		int cur = que.front(); que.pop();
		for(auto nx : G[cur]){
			if(vis[nx]!=-1) continue;
			que.push(nx);
			vis[nx] = vis[cur]+1;
			pre[nx] = cur;
		}
	}

	cout << "Yes" << endl;
	rep(i,N){
		if(i==0) continue;
		int ans = pre[i];
		ans++;
		cout << ans << endl;
	}

    
}

Measured memory_bytes: 10928
#include<stdio.h>
#define MAX 100000
 
typedef struct{
  int p,l,r;
}Node;

Node T[MAX];
int n,D[MAX],H[MAX];
 
void print(int u){
  int i,c,deg=0;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].p);
  printf("sibling = %d, ",getSibling(u));
  if(T[u].l!=-1)deg++;
  if(T[u].r!=-1)deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);
 
  if(T[u].p == -1)printf("root\n");

  else if(T[u].l == -1 && T[u].r == -1)printf("leaf\n");

  else printf("internal node\n");
 
}
 
int setHeight(int u){
  int h1=0,h2=0;
  if(T[u].l!=-1)
    h1=setHeight(T[u].l) + 1;
  if(T[u].r!=-1)
    h2=setHeight(T[u].r) + 1;
  return H[u] = (h1 > h2 ? h1 : h2);
}
 
int getSibling(int u){
  if(T[u].p == -1)return -1;
  
  if(T[T[u].p].l != u && T[T[u].p].l != -1)
    return T[T[u].p].l;
  
  if(T[T[u].p].r != u && T[T[u].p].r != -1)
    return T[T[u].p].r;
  return -1;
}
 
void rec(int u,int d){
  if(u==-1)return;
  D[u] = d;
  rec(T[u].r, d+1);
  rec(T[u].l, d+1);
}

int main(){
  int i,v,a,b,root=0;
  scanf("%d",&n);
  
  for(i=0;i<n;i++)T[i].p=-1;
  for(i=0;i<n;i++){
    scanf("%d %d %d",&v,&a,&b);
    T[v].l=a;
  T[v].r=b;
  if(a!=-1)T[a].p=v;
  if(b!=-1)T[b].p=v;
  }
  for(i=0;i<n;i++)if(T[i].p==-1)root=i;
 
  rec(root,0);
  setHeight(root);
 
  for(i=0;i<n;i++)print(i);
 
  return 0;
}

Measured memory_bytes: 624
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define P pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define MOD 1000000007
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
int kaijo(int n){
	int ans=1;
	for(int i=1;i<=n;i++){
		ans*=i;
		ans%=MOD;
	}
	return ans;
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b==1)return a%MOD;
	if(b%2)return modpow(a,b-1)*a%MOD;
	return modpow(a,b/2)*modpow(a,b/2)%MOD;
}
int comb(int a,int b){
	return kaijo(a)*modpow(kaijo(a-b),MOD-2)%MOD*modpow(kaijo(b),MOD-2)%MOD;
}
signed main(){
	int n;
	string a,b,c;
	int ans=0;
	cin>>n>>a>>b>>c;
	rep(i,n){
		char x=a[i],y=b[i],z=c[i];
		if(x==y){
			if(y==z)ans+=0;
			else ans+=1;
		}
		else{
			if(y==z)ans+=1;
			else{
				if(x==z)ans++;
				else ans+=2;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
from collections import deque

def main():
    H, W, K = map(int, input().split())
    A = [input() for _ in range(H)]
    s = None
    for i in range(H):
        for j in range(W):
            if A[i][j] == "S":
                s = (i, j)
    q = deque()
    q.append((s[0], s[1], K))
    directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
    visited = [[False] * W for _ in range(H)]
    visited[s[0]][s[1]] = True
    dst = float("inf")
    while(len(q)):
        i, j, m = q.popleft()
        dst = min(dst, min([i, j, H-1-i, W-1-j]))
        if m == 0:
            continue
        for d in directions:
            ni = i + d[0]
            nj = j + d[1]
            if 0 <= ni < H and 0 <= nj < W:
                if A[ni][nj] == "." and not visited[ni][nj]:
                    q.append((ni, nj, m-1))
                    visited[ni][nj] = True
    ans = 1 - (-dst//K)
    print(ans)


if __name__ == "__main__":
    main()


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
#define MAX_N 200000

vector<queue<ll>> side(MAX_N);
vll pt(MAX_N, 0);
vll ans(MAX_N, 0);

bool dfs(ll pos, ll now){
  ans[pos] = now;
  if(side[pos].empty())
    return false;

  while(!side[pos].empty()){
    ll next = side[pos].front();
    side[pos].pop();
    now += pt[next];
    dfs(next, now);
    now -= pt[next];
  }


}



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

  ll n, q;
  cin >> n >> q;

  ll a, b;
  REP(i, n-1){
    cin >> a >> b;
    a--;
    b--;
    side[a].push(b);
  }

  ll p, x;
  REP(i, q){
    cin >> p >> x;
    p--;
    pt[p] += x;
  }

  ll now = pt[0];
  dfs(0, now);

  REP(i, n)
    cout << ans[i] << " ";
  cout << endl;

}


Measured memory_bytes: 149248
n=int(input())
import math
m=None
for i in range(1,int(math.sqrt(n))+1):
  if n%i==0:
    #print(i, n//i)
    #print(i-1, n//i-1)
    if m is None or m > (i+n//i-2):
      m=i+n//i-2
    #print()
print(m)

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

int n;

int64_t rgb(string s) {
    int64_t r, g, b;
    r = 0;
    g = 0;
    b = 0;
    for (int i = 0; i < n; i++) {
        if (s.at(i) == 'R') {
            r++;
        } else if (s.at(i) == 'G') {
            g++;
        } else {
            b++;
        }
    }

    int64_t ans = r * g * b;

    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (2 * j - i >= n) {
                break;
            }
            if (s.at(i) != s.at(j) && s.at(j) != s.at(2 * j - i) && s.at(2 * j - i) != s.at(i)) {
                ans--;
            }
        }
    }

    return ans;
}

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

    int64_t ans = rgb(s);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3580
#include <stdio.h>

int main()
{
	long long n, a, b, i, x,k,min,max;
	long long c = 0;
	long long m = 0;
	long long h[100000];
	scanf("%lld %lld %lld", &n, &a, &b);
	for (i = 0; i < n; i++) {
		scanf("%lld", &h[i]);
		if (m < h[i]) {
			m = h[i];
		}
	}
	max = m / b + 1;
	min = 0;	
	m = 0;
	while (m == 0) {
		x = (max - min) / 2 +min;
		c = 0;
		for (i = 0; i < n; i++) {
			if (x*b < h[i]) {
				c += (h[i] - x*b) / (a - b);
				if ((h[i] - x*b) % (a - b) != 0) {
					c++;
				}
			}
			if (c >x) {
				break;
			}
		}
		if (c >x) {
			min = x + 1;
			continue;
		}
		max = x;
		c = 0;
		for (long long k = 0; k < n; k++) {
			if ((x-1)*b < h[k]) {
				c += (h[k] - (x-1)*b) / (a - b);
				if ((h[k] - (x-1)*b) % (a - b) != 0) {
					c++;
				}
			}
			if (c >(x-1)) {
				m++;
				break;
			}
		}
	}
	printf("%lld", x);
    return 0;
}



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

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

int main() {
    int s;
    cin >> s;
    int n = 1000000;
    vector<int> a(n);
    for (int i = 1; i <= n; i++) {
        if (i == 1) a[i] = s;
        else {
            a[i] = f(a[i-1]);
            for (int j = 1; j < i; j++) {
                if (a[j] == a[i]) {
                    cout << i << endl;
                    goto out;
                }
            }
        }
    }
    out:
    return 0;
}

Measured memory_bytes: 7220
p = [[0 for j in range(10)] for i in range(10)]

s1i = [-1, 0, 0, 1]
s1j = [0, -1, 1, 0]
s2i = [-1, -1, -1, 0, 0, 1, 1, 1]
s2j = [-1, 0, 1, -1, 1, -1, 0, 1]
s3i = [-2, -1, -1, -1, 0, 0, 0, 0, 1, 1, 1, 2]
s3j = [0, -1, 0, 1, -2, -1, 1, 2, -1, 0, 1, 0]

while True:
  try:
    x, y, s = map(int, input().split(","))
  except:
    break

  p[y][x] += 1
  if s == 1:
    for k in range(len(s1i)):
      xx = x + s1j[k]
      yy = y + s1i[k]
      if 0 <= xx and xx < 10 and 0 <= yy and yy < 10:
        p[yy][xx] += 1
  elif s == 2:
    for k in range(len(s2i)):
      xx = x + s2j[k]
      yy = y + s2i[k]
      if 0 <= xx and xx < 10 and 0 <= yy and yy < 10:
        p[yy][xx] += 1
  else:
    for k in range(len(s3i)):
      xx = x + s3j[k]
      yy = y + s3i[k]
      if 0 <= xx and xx < 10 and 0 <= yy and yy < 10:
        p[yy][xx] += 1
    
cnt = 0
m = 0
for i in range(10):
  #print(p[i])
  for j in range(10):
    if p[i][j] == 0:
      cnt += 1
    else:
      pass
    m = max(p[i][j], m)

#print()
print(cnt)
print(m)


Measured memory_bytes: 5624
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

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

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N,M;
vector<int> cnt;
vector<vector<int>> G;
vector<pii> edge;
void input(){
    fast_io();
    cin >> N >> M;
    cnt.assign(N,0);
    G.resize(N);
    for (int i = 0; i < M; i++)
    {
        int a,b; cin >> a >> b;
        a--,b--;
        cnt[a]++;
        cnt[b]++;
        G[a].push_back(b);
        G[b].push_back(a);
        edge.emplace_back(a,b);
    }
}

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  bool same(int x, int y) {
    return (find(x)==find(y));
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};


bool dfs(int a){
    // aを除いたグラフが連結-> false
    // aを除いたグラフが非連結-> true
    UnionFind uf(N);
    for (int i = 0; i < M; i++)
    {
        if(edge[i].first==a || edge[i].second==a) continue;
        uf.unite(edge[i].first, edge[i].second);
    }
    for(auto u:G[a])
        for(auto v:G[a]){
            if(!uf.same(u,v)) return true;
    }
    return false;
}

int solve(){
    bool ok = false;
    int cnt4 = 0;
    int a = 0;
    for (int i = 0; i < N; i++)
    {
        if(cnt[i]%2){
            cout << "No" << endl;
            return 0;
        }
        if(cnt[i]==4) {cnt4++; a=i;}
        if(cnt[i]>=6) ok = true;
    }
    if(ok || cnt4>=3) cout << "Yes" << endl;
    else if(cnt4==2 && dfs(a)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 10084
#include "bits/stdc++.h"
#pragma warning(disable:4996)
using namespace std;
const int K = 1e5 + 5;
const int N = 105;
const int mod = 1e9 + 7;
int a[N];
int dp[N][K];
void add(int& a, int b) {
	a += b;
	if (a >= mod)
		a -= mod;
}

int sub(int a, int b) {
	a -= b;
	if (a < 0)
		a += mod;
	return a;
}

int main() {
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i <= a[1]; i++) {
		dp[1][i] = 1;
	}
	for (int i = 1; i <= k; i++) {
		add(dp[1][i], dp[1][i - 1]);
	}
	for (int i = 2; i <= n; i++) {
		for (int j = 0; j <= k; j++) {
			int sum = dp[i - 1][j];
			if (j - a[i] - 1 >= 0) {
				sum = sub(dp[i - 1][j], dp[i - 1][j - a[i] - 1]);
			}
			if(j > 0)
				add(sum, dp[i][j - 1]);
			add(dp[i][j], sum);
		}
	}
	printf("%d\n", sub(dp[n][k] , dp[n][k - 1]));
}


Measured memory_bytes: 40832
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
int gcd(int a,int b)
{
	if(a%b==0)
		return b;
	else
		return gcd(b,a%b);
}
int x[107],y[107],alt[107];
void solve()
{
    int cx,cy,h,n,index=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>x[i]>>y[i]>>alt[i];
        if(alt[i]>0)
            index=i;
    }
    for(int i=0;i<=100;i++)
        for(int j=0;j<=100;j++)
        {
            int coun=0;
            h=alt[index]+abs(i-x[index])+abs(j-y[index]);
            for(int k=0;k<n;k++)
            {
                if(alt[k]==max(0,h-abs(i-x[k])-abs(j-y[k])))
                    coun++;
            }
            if(coun==n)
            {
                cout<<i<<" "<<j<<" "<<h;
                return;
            }
        }
}
int main()
{
	int t=1;
	while(t--)
		solve();
	return(0);
}


Measured memory_bytes: 256