akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;
#pragma GCC optimize("O3")

template <class T>
class SegTree {
    using F = function<T(T, T)>;
    int n;
    vector<T> data;
    const F f;
    const T e;

public:
    SegTree(const vector<T>& as, const F f, const T& e) : f(f), e(e) {
        n = 1;
        while (n < as.size()) n <<= 1;
        data.assign(2 * n, e);
        for (int i = 0; i < as.size(); i++) {
            data[n + i] = as[i];
        }
        for (int i = n - 1; i > 0; i--) {
            data[i] = f(data[2 * i], data[2 * i + 1]);
        }
    }

    void update(int k, const T& x) {
        k += n;
        data[k] = x;
        while (k >>= 1) {
            data[k] = f(data[2 * k], data[2 * k + 1]);
        }
    }

    T query(int a, int b) {
        T L = e, R = e;
        for (a += n, b += n; a < b; a >>= 1, b >>= 1) {
            if (a & 1) {
                L = f(L, data[a++]);
            }
            if (b & 1) {
                R = f(data[--b], R);
            }
        }
        return f(L, R);
    }
};

void printvec(vi& x, int size = 0) {
    cout << x.front();
    for (int i = 1; i < (size == 0 ? x.size() : size); i++) {
        cout << " " << x[i];
    }
    cout << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout.setf(ios::fixed);
    cout.precision(10);
    int n, l;
    cin >> n >> l;
    vi as(n);
    for (int i = 0; i < n; i++) {
        cin >> as[i];
    }

    SegTree<i64> tree(as, [](i64 a, i64 b) {return min(a, b);}, 1e18);

    vi ans;
    for (int i = 0; i < n - l + 1; i++) {
        ans.push_back(tree.query(i, i + l));
    }
    printvec(ans);
}



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

int main() {
  int n,m;
  cin >> n >> m;
  vector<int> v(200);
  rep(i,m*2){
    cin >> v[i];
  }
  
  rep(i,n){
    int count=0;
    rep(j,m*2){
      if(v[j]==i+1){
        count++;
      }
    }
    cout << count << endl;
  }
}

Measured memory_bytes: 256
runRail :: [Int] -> [Int]
runRail = runWithStack [] where
    runWithStack _ [] = []
    runWithStack s (x:xs) = case x of
                                0 -> head s : runWithStack (tail s) xs
                                _ -> runWithStack (x:s) xs

main = getContents >>= mapM_ print . runRail . map read . lines

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

int main(){
	int sum = 0;
	int n;
	
	for(int i = 0; i < 5; i++){
		cin >> n;
		if(n < 40){
			sum += 40;
		}else {
			sum += n;
		}
	}
	
	cout << sum / 5 << endl;
	
	return 0;
}

Measured memory_bytes: 1160
n = gets.chop.split("").map(&:to_i)

flag = false
m = [[1,1,1],[1,1,-1],[1,-1,1],[1,-1,-1],[-1,1,1],[-1,1,-1],[-1,-1,1],[-1,-1,-1]]

i = 0
while i < 8 && !flag
	r = n[0] + m[i][0] * n[1] + m[i][1] * n[2] + m[i][2] * n[3]
	flag = true if r == 7
	i += 1
end
op = m[i-1].map{|k| k == 1 ? "+" : "-"}
print "#{n[0]}#{op[0]}#{n[1]}#{op[1]}#{n[2]}#{op[2]}#{n[3]}=7"


Measured memory_bytes: 1788
#include <vector>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <functional>

const int INF = 1001001000;
const int MOD = (int)1e9 + 7;

using ll = long long;

using namespace std;

typedef pair<int,int> P;

int dx[] = { 0, 0, 1, -1};
int dy[] = { 1, -1, 0, 0};

int main(){

  int a,b;
  cin >> a >> b;
  int x = a*b;
  if( x%2 == 1){
    cout << "Odd" << endl;
  }else{
    std::cout << "Even" << '\n';
  }

}


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

int main(){
	ll n, b;
	int ans = 10;
	
	cin >> n;
	for(ll i = 1; i * i <= n; i++){
		if(n % i == 0){
			b = n / i;
			string sb = to_string(b);
			int temp = sb.size();
			ans = min(ans, temp);
		}
	}
	cout << ans << endl;
	
	return 0;
}



Measured memory_bytes: 256
using System;
 
class Sample{
	public static void Main(){
      String[] temp=System.Console.ReadLine().Split(' ');
      int treeNum=int.Parse(temp[0]);
      int choiceTreeNum=int.Parse(temp[1]);
      int[] treeHigh=new int[treeNum];
      for(int i=0;i<treeNum;i++){
      treeHigh[i]=int.Parse(System.Console.ReadLine());
      }
      Array.Sort(treeHigh);
      int dif=int.MaxValue;
      for(int i=0;i<=treeNum-choiceTreeNum;i++){
      dif=Math.Min(dif,treeHigh[i+choiceTreeNum-1]-treeHigh[i]);
      }
      System.Console.WriteLine(dif);
    }
}

Measured memory_bytes: 15452
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int linearSearch(int *, int, int);

main(){
  int n,q,i,findN=0;
  int *sAry, *tAry;

  scanf("%d", &n);
  sAry = (int *)malloc((n+1)*sizeof(int)); //番兵用に+1
  for(i=0; i<n; i++) scanf("%d", sAry+i);
  scanf("%d", &q);
  tAry = (int *)malloc(q*sizeof(int));
  for(i=0; i<q; i++) scanf("%d", tAry+i);

  for(i=0; i<q; i++) findN+=linearSearch(sAry, n, tAry[i]);

  printf("%d\n", findN);

  return 0;
}

int linearSearch(int *ary, int n, int a){
  int i=0;
  ary[n]=a;
  while(ary[i]!=a) i++;
  if(i==n) return 0;
  return 1;
}

Measured memory_bytes: 636
H, W = map(int, input().split())
h = []
w = []
a = [""]*H
for i in range(H):
    a[i] = input()


for y in range(H):
    flag = True
    for x in range(W):
        if a[y][x] == "#":
            flag = False
            break
    if flag:
        h.append(y)

for x in range(W):
    flag = True
    for y in range(H):
        if a[y][x] == "#":
            flag = False
            break
    if flag:
        w.append(x)

for y in range(H):
    for x in range(W):
        if y not in h and x not in w:
            print(a[y][x], end="")
    if y not in h:
        print()


Measured memory_bytes: 4468
//どうかACをお恵みくださいお願いしますお願いしますお願います何もしませんから
using System;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            string[] n = Console.ReadLine().Split();
            int D = int.Parse(n[0]);
            int T = int.Parse(n[1]);
            int S = int.Parse(n[2]);
            if(D<=T*S)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 27532
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
vector<int>vec(n);
for(int i=0;i<n;i++){
  cin >> vec.at(i);
}
int sub=1;
  for(int i=0;i<n;i++){
  if(vec.at(i)%2==0)sub*=2;
  else sub*=1;
  }
  cout << pow(3,n) - sub << endl; 
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << (x) << endl;
typedef long long ll;
const int MAX = 999999999;

int main(){
    int n, a, b;
    cin >> n >> a >> b;

    vector<int> nums(n);
    rep(i, n) cin >> nums[i];

    sort(all(nums));

    int under_a = 0, under_b = 0, other = 0;
    rep(i, n){
        if(nums[i] <= a) under_a ++;
        else if(nums[i] <= b) under_b ++;
        else other ++;
    }

    cout << min(other, min(under_a, under_b)) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
#include <fstream>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

ll mod(ll a, ll b){
  ll ret=a%b;
  if(ret<0) ret+=b;
  return ret;
}

ll modpow(ll a,ll b,ll c){
  ll res=1;
  while(b>0){
    if(b&1) res=mod(res*a,c);
    a=mod(a*a,c);
    b>>=1;
  }
  return res;
}

int GCD(int x,int y){
  if(x<y){
    swap(x,y);
  }
  while(x%y!=0){
    int temp=x;
    x=y;
    y=temp%y;
  }
  return y;
}

int digitsum(int x){
  int sum=0;
  while(x>0){
    sum+=(x%10);
    x/=10;
  }
  return sum;
}

int dp[1001][20010];

int main() {
  int h,n;
  cin>>h>>n;
  int a[n+1],b[n+1];
  for(int i=1;i<=n;i++){
    cin>>a[i]>>b[i];
  }
  for(int i=0;i<20010;i++){
    dp[0][i]=1e9;
  }
  dp[0][0]=0;
  for(int i=1;i<=n;i++){
    for(int j=0;j<20010;j++){
      dp[i][j]=dp[i-1][j];
      if(j-a[i]>=0){
        dp[i][j]=min(dp[i][j],dp[i][j-a[i]]+b[i]);
      }
    }
  }
  int ans=dp[n][h];
  for(int i=h+1;i<20010;i++){
    ans=min(ans,dp[n][i]);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 81848
<?php
$n = trim(fgets(STDIN));
$numbers = str_split($n);

$ope = ["-", "+"];
for ($mask = 0; $mask < (1 << 3); $mask++) {
    
    $ans = $numbers[0];
    $ope = [];
    for ($i = 0; $i < 3; $i++) {
         
         if(($mask >> $i) & 1) {
             $ans += $numbers[$i+1];
              $ope[$i] = "+";
         } else {
             $ans -= $numbers[$i+1];
             $ope[$i] = "-";
         }
    }
    
    if($ans == 7) {
        echo $numbers[0].$ope[0].$numbers[1].$ope[1].$numbers[2].$ope[2].$numbers[3]."=7";
        break;
    }
     
}

?>

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

using namespace std;

#define FOR(i, m, n) for(int i = m; i < n; i++)

int isPrime(int n) {
    if (n == 2 || n == 3) return 1;
    if (n == 1 || n % 2 == 0) return 0;
    for (int i = 3; i * i <= n; i += 2) {
        if (n % i == 0) return 0;
    }
    return 1;
}

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

    int n;
    cin >> n;
    int ans = 0;
    FOR(i, 1, n + 1) {
        int k;
        cin >> k;
        ans += isPrime(k);
    }
    cout << ans << endl;
    return 0;
}



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

int main()
{
    string s;
    cin >> s;
    int plus = 0;
    int minus = 0;
    for(auto c:s){
        if(c == '+') plus++;
        if(c == '-') minus++;
    }
    
    cout << plus - minus << endl;
    return 0;
}

Measured memory_bytes: 256
// B.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
	int n, m, a, b;
	cin >> n >> m;
	vector<int> r(n);
	for (int i = 0; i < m; ++i) {
		cin >> a >> b;
		r[a - 1] += 1;
		r[b - 1] += 1;
	}
	for (int i = 0; i < n; ++i) {
		cout << r[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import sys
from collections import Counter

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()

count = Counter()
for x in range(1, 100):
    for y in range(1, 100):
        for z in range(1, 100):
            n = (x**2) + (y**2) + (z**2) + (x*y) + (y*z) + (z*x)
            count[n] += 1


for i in range(1, N+1):
    print(count[i])

Measured memory_bytes: 72396
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

string str[105];
int n, m;


int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; ++i)
		cin >> str[i];

	sort(str, str + n);

	for (int i = 0; i < n; ++i)
		cout << str[i];
	cout << endl;

	return 0;
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

//-----------------------------------------------------------------------------

int bubble_sort(vector< int > &a) {
    int cnt = 0;
    for (int i = 0; i < (int)a.size() - 1; i++) {
        for (int j = (int)a.size() - 1; j > i; j--) {
            if (a[j - 1] > a[j]) {
                swap(a[j - 1], a[j]);
                cnt++;
            }
        }
    }
    return cnt;
} 

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

    int n;
    cin>>n;
    vector< int > a(n);
    REP(i, n) cin >> a[i];
    int cnt = bubble_sort(a);
    REP(i, n) cout << a[i] << (i == n - 1 ? '\n' : ' ');
    cout << cnt << endl;


	return 0;
}



Measured memory_bytes: 3228
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)















int main(){
    ll n;
    string s;
    cin >> n >> s;
    ll ans = 0;
    REP(i, n - 2){
        if(s.substr(i, 3) == "ABC") ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
s = input()
# s = "dreamerase"
L = ["eraser", "dreamer", "erase", "dream"]
i = 0
f = 0
while i < len(s):
    if s[i:i+6] == "eraser" and (len(s) == i+6 or s[i+6:i+8] != "as"):
        i += 6
    elif s[i:i+7] == "dreamer" and (len(s) == i+7 or s[i+7:i+9] != "as"):
        i += 7
    elif s[i:i+5] == "erase" or s[i:i+5] == "dream":
        i += 5
    else:
        f = 1
        break

if f == 0:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3188
const main = (input) => {
  const mod = (10**9 + 7)
  const s = Number(input.trim())

  const dp = [1, ...new Array(s).fill(0)]

  for (let x=3; x<dp.length; x++) {
    let sum = 0

    for (let i=x-3; i>=0; i--) {
      sum = (sum + dp[i]) % mod
    }

    dp[x] = sum
  }

  return console.log((dp[s] % mod + mod) % mod)
}

process.env.MYTEST
  ? (process.env.MYTEST === 'test' ? test() : main(require('fs').readFileSync('dev/stdin', 'utf8')))
  : main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 32216
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <queue>
using namespace std;

int main(){
  int n;
  int a,b,c;
  string s,t,u;
  cin >> s;
  cin >> t;
  cin >> u;
  cout << s[0] << t[1] << u[2] << endl;
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>    
#define inf 100000000
#define INF 9223372036854775807
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
int mod=(int)1e09+7;

int in(void){
    int i;scanf("%d",&i);
    return i;
}
long long llin(void){
    long long i;scanf("%lld",&i);
    return i;
}
double din(void){
    double i;scanf("%lf",&i);
    return i;
}
void chin(char s[]){
    scanf("%s",s);
}
void print(int a){
    printf("%d\n",a);
}
void llprint(long long a){
    printf("%lld\n",a);
}
void dprint(double a){
    printf("%.10f\n",a);
}
void print2(int a,int b){
    printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
    return a>b?a:b;
}
long long min(long long a,long long b){
    return a<b?a:b;
}
int cmp(const void *a,const void *b){
    return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
    return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
    return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
    return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
    int t=*a;
    *a=*b;
    *b=t;
}
long long gcd(long long x,long long y){
    return x%y?gcd(y,x%y):y;
}
long long lcm(long long x,long long y){
    return x/gcd(x,y)*y;
}

// write codes below this
// when you use 'sort',
// make sure TYPE macro is correct
int keta(int n){
    int t=n,s=0;
    while(t){
        s+=t%10;
        t/=10;
    }
    return s;
}

int main(void){
    int n=in(),a,b,m=inf;
    rep(a,n){
        if(!a)continue;
        b=n-a;
        m=min(m,keta(a)+keta(b));
    }
    print(m);
    return 0;
}

Measured memory_bytes: 128
n=int(input())
A=list(map(int,input().split()))

B=[0]*(n+1)
C,cnt=[],0
for i in range(1,n+1)[::-1]:
    sum_list=sum([B[j] for j in range(i,n+1,i)])
    if sum_list%2!=A[i-1]:
        B[i]=1
        cnt +=1
        C.append(i)

print(cnt)
print(*C[::-1])

Measured memory_bytes: 14840
package main

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

type sword struct {
	id, a, b int
}

type swords []sword

func (s swords) Len() int {
	return len(s)
}
func (s swords) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

type byAthenB struct {
	swords
}
type byBthenA struct {
	swords
}

func (a byAthenB) Less(i, j int) bool {
	if a.swords[i].a < a.swords[j].a {
		return true
	} else if a.swords[i].a == a.swords[j].a {
		if a.swords[i].b > a.swords[j].b {
			return true
		}
	}
	return false
}
func (b byBthenA) Less(i, j int) bool {
	if b.swords[i].b < b.swords[j].b {
		return true
	} else if b.swords[i].b == b.swords[j].b {
		if b.swords[i].a < b.swords[j].a {
			return true
		}
	}
	return false
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}
func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	N := nextInt(sc)
	H := nextInt(sc)
	swords := make([]sword, N)
	for i := 0; i < N; i++ {
		swords[i].a = nextInt(sc)
		swords[i].b = nextInt(sc)
		swords[i].id = i
	}
	// 斬りつけるための刀はaでソートして最大の剣のうち、投げつけ威力の小さいもの
	sort.Sort(byAthenB{swords})
	A := swords[len(swords)-1].a
	Aid := swords[len(swords)-1].id
	B := swords[len(swords)-1].b

	// 投げる価値のある剣を選ぶ
	Bs := make([]int, 0)
	sort.Sort(sort.Reverse(byBthenA{swords}))
	for i := 0; i < N; i++ {
		if swords[i].b >= A && swords[i].id != Aid {
			Bs = append(Bs, swords[i].b)
		}
	}
	// 投げられる剣は全て投げてしまって良い
	ans := 0
	for i := 0; i < len(Bs); i++ {
		H -= Bs[i]
		ans++
		if H <= 0 {
			fmt.Println(ans)
			return
		}
	}
	// まだHPが残っているなら、残った剣で斬る（最後に投げつける分を最初に引いておく）
	if B > A {
		H -= B
		ans++
	}
	ans += ((H + A - 1) / A)
	fmt.Println(ans)
}


Measured memory_bytes: 8576
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    s = S()
    if '7' in s:
        print("Yes")
    else:
        print("No")

main()



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

using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

#ifdef _LOCAL
struct Tester {
    Tester() { freopen("sample.in", "r", stdin); }
    ~Tester() { fprintf(stderr, "\nTime: %d ms\n", int(1000.0 * clock() / CLOCKS_PER_SEC)); }
} _tester;
#endif

const int INF = 0x3F3F3F3F;
const LL INFLL = 0x3F3F3F3F3F3F3F3FLL;
const int N = 1e5 + 10;
const int Q = 1e5 + 10;

vector<int> v[N];

int main() {
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        int time, reward;
        cin >> time >> reward;
        v[time].push_back(reward);
    }
    priority_queue<int> heap;
    LL res = 0;
    for (int i = 1; i <= m; ++i) {
        for (int val : v[i]) heap.push(val);
        if (!heap.empty()) {
            res += heap.top();
            heap.pop();
        }
    }
    cout << res;
    return 0;
}

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

int main()
{

	int v,e,r;
	cin >> v >> e >> r;

	vector<map<int,int>> g(v);
	for (int i=0;i<e;++i)
	{
		int s,t,d;
		cin >> s >> t >> d;
		g[s][t]=d;
		//g[t][s]=d;
	}

	vector<int> d(v);
	const int infinity=65536*32766;
	for (int i=0;i<v;++i)
	{
		d[i]=infinity;
	}

	priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq;
	pq.push(make_pair(0,r));

	while (pq.size()>0)
	{
		pair<int,int> p=pq.top();
		pq.pop();
		if (d[p.second]==infinity)
		{
			d[p.second]=p.first;
			for (pair<int,int> pp: g[p.second])
			{
				pq.push(make_pair(p.first+pp.second,pp.first));
			}
		}
	}

	for (int i=0;i<v;++i)
	{
		if (d[i]!=infinity)
		{
			cout << d[i] << endl;
		}
		else
		{
			cout << "INF" << endl;
		}
	}
}

	






Measured memory_bytes: 32744
def main():
    x = list(map(int, input().split()))
    n = x[0]
    m = x[1]

    common_section = [1, n]

    for i in range(m):
        a = list(map(int, input().split()))
        if a[0] > common_section[0]:
            common_section[0] = a[0]
        if a[1] < common_section[1]:
            common_section[1] = a[1]

    answer = common_section[1] - common_section[0] + 1
    if answer < 0:
        answer = 0
    print(answer)


if __name__ == "__main__":
    main()


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

int main(){
    string s;
    cin >> s;
    bool check = true;

    for(int i=0; i<s.size(); i++){
        if((i+1)%2 == 0){
            if(s[i] == 'R'){
                check = false;
            }
        }else{
            if(s[i] == 'L'){
                check = false;
            }
        }
    }
    if(check){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int k,n,a[55],l;
    while(cin>>n>>k)
    {
        l=0;
        for(int i=0;i<n;i++)
        {cin>>a[i];}
    sort(a,a+n);
   /*for(int i=0;i<n;i++)
        cout<<a[i]<<' ';*/
    for(int i=n-1;i>=n-k;i--)
    {
        l=l+a[i];
    }
    cout<<l<<'\n';
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pi acos(-1)
#define mod 1000000007
using namespace std;

int dp[3001][3001];
string a, b;

void funk(int i, int j, string &s, string curr){
    if(i == 0 || j == 0){
        if(curr.length() > s.length()){
            s = curr;
        }
        return ;
    }
    if(a[i-1] == b[j-1]){
        curr += a[i-1];
        funk(i-1,j-1,s,curr);
        return;
    }
    if(dp[i-1][j] < dp[i][j-1]){
        funk(i,j-1,s,curr);
    }else{
        funk(i-1,j,s,curr);
    }
    return;
}

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

    cin >> a >> b;
    int n = a.length(), m = b.length();
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            if(a[i] == b[j]){
                dp[i + 1][j + 1] = dp[i][j] + 1;
            }
            dp[i+1][j+1] = max(dp[i + 1][j + 1], max(dp[i + 1][j], dp[i][j + 1]));
        }
    }
    string ans = "";
    string s;
    funk(n, m, ans, s);
    reverse(ans.begin(), ans.end());
    cout << ans;
    return 0;
}


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

#define endl '\n'
#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f

typedef long long ll;
typedef pair <int, int> pii;
typedef vector<int> vi;
const int N = 3e3+5;
const ll MOD = 1e9+7;

int n;
ll dp[N][N];
string s;

// '>': dp[i][j]=dp[i-1][j] + ... + dp[i-1][i]
// '<': dp[i][j]=dp[i-1][j+1] + ... + dp[i-1][i] 

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0); 
  cin >> n >> s;

  dp[1][1]=(s[0]=='>'); 
  dp[1][2]=1;

  for(int i=2; i<n; i++){
    for(int j=1; j<=i+1; j++){
      if(s[i-1]=='>') dp[i][j]=(dp[i-1][i]-dp[i-1][j-1] + MOD)%MOD;
      else dp[i][j]=dp[i-1][j-1];
      dp[i][j]=(dp[i][j]+dp[i][j-1])%MOD; 
    }
  }

  cout << dp[n-1][n] << endl;
}

Measured memory_bytes: 68992
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

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

    ll h, w, n; cin >> h >> w >> n;
    ll sr, sc; cin >> sr >> sc;
    string s, t; cin >> s >> t;

    ll lb = 1;
    ll rb = w;
    ll ub = 1;
    ll db = h;

    repr(i, s.size()){
        if(t[i] == 'R'){
            lb = max(1LL, lb - 1);
        }
        else if(t[i] == 'L'){
            rb = min(rb + 1, w);
        }
        else if(t[i] == 'D'){
            ub = max(ub - 1, 1LL);
        }
        else if(t[i] == 'U'){
            db = min(db + 1, h);
        }

        if(s[i] == 'R'){
            // lb = max(1LL, lb - 1);
            rb--;
        }
        else if(s[i] == 'L'){
            // rb = min(rb + 1, w);
            lb++;
        }
        else if(s[i] == 'D'){
            // ub = max(1LL, ub - 1);
            db--;
        }
        else if(s[i] == 'U'){
            // db = min(h, db + 1);
            ub++;
        }

        if(rb < lb || db < ub){
            cout << "NO" << endl;
            return 0;
        }

        // cout << i << " " << lb << " " << rb << " " << ub << " " << db << endl;
    }

    if(ub <= sr && sr <= db && lb <= sc && sc <= rb){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }


    return 0;
}

Measured memory_bytes: 920
//"BISMILLAHIR RAHMANIR RAHIM"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
const long long M = 1e10 ;
int main()
{
    ll d,i,j,k,n,con=0,x,y;
    cin>>n>>d;
    for(i=0;i<n;i++){
        cin>>x>>y;
        if(x*x+y*y<=d*d)
            con++;
    }
    cout<<con<<endl;
    return 0;
}


Measured memory_bytes: 3548
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>
#include<random>
#include<set>
#include<queue>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define dump(a) cout << a << endl; 

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

/**
* @fn
* 最大値を取ります.Vector<int>を渡すこと.
*/
long long int imax(vector<int> a) {
	int MAX = -10000000;
	for (int i = 0; i < a.size(); i++) {
		if (MAX < a.at(i)) MAX = a.at(i);
	}
	return MAX;
}

/**
* @fn
* 最小値を取ります.Vector<int>を渡すこと.
*/
long long int imin(vector<int> a) {
	int MIN = 1000000000;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
	}
	return MIN;
}

/**
* @fn
* 自然数について、桁数を求める
*/
Int getDigit(Int num) {
	return (Int)(log10(num)) + 1;
}


int get2Digit(Int num) {
	int cnt = 0;
	while (num > 0) {
		if (num % 2 != 0) {
			return cnt;
		}
		cnt++;
		num /= 2;
	}
}

long long int absmin(vector<int> a, long long int b) {
	int mini = 100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (mini > abs(a.at(i) - b)) {
			mini = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}


long long int absmax(vector<int> a, long long int b) {
	int max = -100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (max < abs(a.at(i) - b)) {
			max = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}

int gcd(int a, int b)
{
	if (a < b) swap(a, b);
	if (b < 1) return -1;
	if (a % b == 0) return b;
	return gcd(b, a % b);
}

void haerobatya(int start, int end, char level) {
	if (start > end) swap(start, end);
	for (int i = start; i <= end; i++) {
		if (i < 100) {
			cout << "https://atcoder.jp/contests/abc0" << i << "/tasks/abc0" << i << "_" << level << endl;
		}
		else {
			cout << "https://atcoder.jp/contests/abc" << i << "/tasks/abc" << i << "_" << level << endl;
		}
	}
}

long long int cntmod(long long int warareru, long long int mod) {
	long long int i = 0;
	for (i = 0; true; i++) {
		if (warareru % mod == 0 && warareru >= mod) {
			warareru /= mod;
		}
		else {
			return i;
		}
	}
}

void ansYes(bool a) {
	if (a == true) cout << "Yes" << endl;
	else cout << "No" << endl;
}

void ansYES(bool a) {
	if (a == true) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Int euclidean_gcd(Int a, Int b) {
	while (true) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

typedef pair<int, int> pai;


//ここまでライブラリ
//ここから本文

int main() {
	int n, k;
	cin >> n >> k;
	if (n % k == 0) {
		dump(0);
	}
	else {
		dump(1);
	}
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
    	FastIO sc = new FastIO(System.in);
    	PrintWriter out = new PrintWriter(System.out);
    	int n = sc.nextInt();
    	int m = sc.nextInt();
    	if(n%2==1) {
    		int cnt = 1;
    		for(int i=0; i<m; i++) {
    			System.out.println(cnt + " " + (n-cnt));
    			cnt++;
    		}
    	}else {
    		int cnt = 1;
    		int idx = 1;
    		for(int i=0; i<m; i++) {
    			if(idx==1&&(n-cnt+idx-cnt)<=n/2) idx = 0;
    			System.out.println(cnt + " " + (n-cnt+idx));
    			cnt++;
    		}
    	}
    	out.close();
    }
    static class FastIO {
		 
		// Is your Fast I/O being bad?
 
		InputStream dis;
		byte[] buffer = new byte[1 << 17];
		int pointer = 0;
 
		public FastIO(String fileName) throws IOException {
			dis = new FileInputStream(fileName);
		}
 
		public FastIO(InputStream is) throws IOException {
			dis = is;
		}
 
		int nextInt() throws IOException {
			int ret = 0;
 
			byte b;
			do {
				b = nextByte();
			} while (b <= ' ');
			boolean negative = false;
			if (b == '-') {
				negative = true;
				b = nextByte();
			}
			while (b >= '0' && b <= '9') {
				ret = 10 * ret + b - '0';
				b = nextByte();
			}
 
			return (negative) ? -ret : ret;
		}
 
		long nextLong() throws IOException {
			long ret = 0;
 
			byte b;
			do {
				b = nextByte();
			} while (b <= ' ');
			boolean negative = false;
			if (b == '-') {
				negative = true;
				b = nextByte();
			}
			while (b >= '0' && b <= '9') {
				ret = 10 * ret + b - '0';
				b = nextByte();
			}
 
			return (negative) ? -ret : ret;
		}
 
		byte nextByte() throws IOException {
			if (pointer == buffer.length) {
				dis.read(buffer, 0, buffer.length);
				pointer = 0;
			}
			return buffer[pointer++];
		}
 
		String next() throws IOException {
			StringBuffer ret = new StringBuffer();
 
			byte b;
			do {
				b = nextByte();
			} while (b <= ' ');
			while (b > ' ') {
				ret.appendCodePoint(b);
				b = nextByte();
			}
 
			return ret.toString();
		}
 
	}
}

Measured memory_bytes: 51316
N = int(input())
graph = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
C = list(map(int, input().split()))
C.sort(reverse=True)

q = [0]
checked = [False]*N
checked[0] = True
ans = 0
c = 0
score = [None for _ in range(N)]
score[0] = C[c]

while q:
    qq = []
    for p in q:
        for np in graph[p]:
            if not checked[np]:
                qq.append(np)
                checked[np] = True
                c += 1
                score[np] = C[c]
                ans += min(score[np], score[p])
    q = qq

print(ans)
for s in score:
    print(s, end=' ')
print()


Measured memory_bytes: 5916
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String data;
        char arr[];
        int sum = 0;
        try {
            while (true) {
                data = br.readLine();
                arr = data.toCharArray();

                if (data.equals("0"))
                    return;

                for (int i = 0; i < arr.length; i++) {
                    sum += (int) arr[i] - 48;
                }
                System.out.println(sum);
                sum = 0;
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


Measured memory_bytes: 24432
import java.util.Scanner;

public class Main {

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

		int numBoll = sn.nextInt();
		int numPerson = sn.nextInt();

		// 一人
		if (numPerson == 1) {
			System.out.println("0");

		}else {
			System.out.println(numBoll - numPerson);
		}

	}
}


Measured memory_bytes: 23892
#include<bits/stdc++.h>
#define inf 0x7fffffff
#define RG register
#define inf 0x7fffffff
#define mkp make_pair
#define maxn 100205
typedef unsigned int U;
using namespace std;
typedef long long ll;
const ll mod = 998244353;
const  double eps = 1e-8;
const double pi = acos(-1);
inline ll read(){
    ll x = 0, f = 1;
    char ch = getchar();
    while(ch > '9' || ch < '0') {if(ch == '-') f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = x *10 + ch -'0';ch = getchar();}
    return x * f;
}
int n,m,inde[100005],tot;
struct p{
	int c[4];
	bool operator < (const p & a)const{
		if(c[0]!=a.c[0]) return c[0]<a.c[0];
		if(c[1]!=a.c[1]) return c[1]<a.c[1];
		if(c[2]!=a.c[2]) return c[2]<a.c[2];
		return c[3]<a.c[3];
	}
}col[405];
map<p,int> mp;
void add(p x,int val){
	p now=x,nxt;
	mp[now]+=val;
	for(int j=1;j<=3;j++){
		for(int i=0;i<=3;i++) nxt.c[i]=now.c[(i+1)%4];
		now=nxt;
		mp[now]+=val;
	}
}
int main(){
	int i,j,u,v,e,w;
	//freopen("a.out","r",stdin);
	//freopen("a.ans","w",stdout);
	n=read();
	for(i=1;i<=n;i++)
		col[i].c[0]=read(),col[i].c[1]=read(),col[i].c[2]=read(),col[i].c[3]=read();
	for(i=1;i<=n;i++) 
		add(col[i],1);
	ll ans=0,S;
	for(i=1;i<=n-5;i++){
		add(col[i],-1);
		for(j=i+1;j<=n;j++){
			add(col[j],-1);
			p now,nxt=col[j],pj;
			for(e=1;e<=4;e++){
				now=nxt;
				S=1;
				for(w=0;w<=3;w++) nxt.c[w]=now.c[(w+1)%4];
				for(w=0;w<=3;w++){
					pj=(p){col[i].c[(w+1)%4],col[i].c[w],now.c[3-w],now.c[3-(w+1)%4]};
					S*=mp[pj];
					if(!mp[pj]) break;
					else add(pj,-1);
				}
				w--;
				for(;w>=0;w--){
					pj=(p){col[i].c[(w+1)%4],col[i].c[w],now.c[3-w],now.c[3-(w+1)%4]};
					add(pj,1);
				}
				ans+=S;
			}
			add(col[j],1);
		}
	}
	printf("%lld\n",ans);
	return 0;
}
/*
8
0 0 0 0
0 0 1 1
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 0
1 1 1 1
*/

Measured memory_bytes: 23696
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
#define N 2500000
ll MOD=1e9+7;



main(){
    int r=in();
    cout<<r*r*3;
}



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

// ÄAÉæé2iñ
void rec(int depth, int max_depth, int a[], int &cnt) {
  if ( depth == max_depth ) {
    cnt++;
    return;
  }
  
  for(int i = 0; i < 2; i++) {
    a[depth] = i;
    rec(depth + 1, max_depth, a, cnt);    
  }  
}

int main() {  
  int a[128];
  int cnt = 0;
  int max_depth = 25;
  rec(0, max_depth, a, cnt);
  
  for(int a = 1; a <= 9; a++)
    for(int b = 1; b <= 9; b++)
      printf("%dx%d=%d\n", a, b, a * b);
  return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

struct info { int num; int color; };
vector<vector<int>> adj;
map<int, map<int, info>> edge;

void dfs(int n, int p, int c) {
  int count = (c==1) ? 2 : 1;
  for (auto x: adj[n]) {
    if (x==p) continue;
    int ma = max(n,x), mi = min(n,x);
    edge[mi][ma].color = count;
    dfs(x, n, count);
    count += (count+1==c) ? 2 : 1;
  }
}

int main() {
  int N; cin >> N;
  adj.resize(N);
  rep(i,N-1) {
    int a, b; cin >> a >> b; a--; b--;
    int ma = max(a,b), mi = min(a,b);
    adj[a].push_back(b);
    adj[b].push_back(a);
    edge[mi][ma] = {i,-1};
  }
  int pos = -1, num = 0;
  rep(i,N) if (adj[i].size()>num) { pos=i; num=adj[i].size(); }
  dfs(pos,-1,-1);

  int result[N-1];
  for (auto x: edge) for (auto y: x.second) {
    result[y.second.num] = y.second.color;
  }
  cout << num << endl;
  rep(i,N-1) cout << result[i] << endl;
  // cout << result << endl;
  return 0;
}

Measured memory_bytes: 19072
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define ld long double
#define mx 200005
#define fr first
#define se second
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
ll dp[100005],coin[100005];
ll n;
ll func(ll i)
{
    if(i>=n) return 0;
    if(dp[i]!=-1) return dp[i];
    ll ans1=INT_MAX;
        for(int k=1; k<=2; k++){
            if(i+k<=n) ans1 = min(ans1,abs(coin[i]-coin[i+k])+func(i+k));
        }
    return dp[i] = ans1;
}

int main()
{
   fast;
   cin >> n;
   memset(dp,-1,sizeof dp);
   for(ll i=1; i<=n; i++) cin >> coin[i];
   cout << func(1) << "\n";
   return 0;
}


Measured memory_bytes: 6528
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    a,b,c = LI()
    if min(a,b) < c < max(a,b):
        print("Yes")
    else:
        print("No")
    return

#B
def B():
    n = I()
    s = S()
    k = I()
    f = s[k-1]
    for i in range(n):
        if s[i] != f:
            print("*",end = "")
        else:
            print(s[i],end = "")
    print()
    return

#C
def C():

    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#G
def G():

    return

#Solve
if __name__ == "__main__":
    B()


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

int main()
{
    int A, B, C, K;
    cin >> A >> B >> C >> K;

    if (K <= A)
    {
        cout << K << endl;
    }
    else if (K <= A + B)
    {
        cout << A << endl;
    }
    else
    {
        cout << A - (K - A - B) << endl;
    }
}

Measured memory_bytes: 3636
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math
from collections import deque
import itertools
import heapq
#import bisect
from fractions import Fraction
import copy
from functools import lru_cache
from collections import defaultdict
import pprint

#oo=list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
# ko=list("abcdefghijklmnopqrstuvwxyz")

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)

def soinsubunkai(n):
    a = []
    i = 1
    while i*i <= n:
        if n % i == 0 and i!=1:
            a.append(i)
            n=n//i

        if n% i !=0 or i==1:
            i += 1
    nokori=[n]
    return a + nokori

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

def main():
    #l,r,d=map(int,input().split())
    d,t,s = map(int, input().split())
    print("Yes") if t*s>=d else print("No")



if __name__ == "__main__":

    main()


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

const int MOD = 1000000007;
int main() {
    long long N, K;
    cin >> N >> K;
    long long M = N+1, L = K-1;
    long long res = M*(M*M+5)/6 + L*(L*L*2+L*3-5-M*(L+1)*3)/6;
    cout << res%MOD << endl;
}

Measured memory_bytes: 3604
import itertools


def check(H, W, K, S, p):
    num_groups = p.count(True) + 1
    group_total = [0] * num_groups
    ret = p.count(True)

    for j in range(W):
        group_value = [0] * num_groups
        group_value[0] += int(S[0][j])
        group_idx = 0
        for i in range(H-1):
            if p[i]:
                group_idx += 1
            group_value[group_idx] += int(S[i+1][j])
        if max(group_value) > K:
            return float("inf")
        group_total_tmp = list(map(sum, zip(group_value, group_total)))
        if max(group_total_tmp) <= K:
            group_total = group_total_tmp
        else:
            group_total = group_value
            ret += 1
    return ret


def main():
    H, W, K = map(int, input().split())
    S = [input() for _ in range(H)]
    ans = float("inf")
    for p in itertools.product([True, False], repeat=H-1):
        ans = min(ans, check(H, W, K, S, p))
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 45916
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <map>
 
using namespace std;
 
const double eps=1e-10;

int main()
{

	vector<long long> prime,ans(10000,0);
	prime.push_back(2);
	prime.push_back(3);
	prime.push_back(5);

	for(int i=7;prime.size()<12000;i+=2){
		bool ok=true;
		for(int j=0;prime[j]*prime[j]<=i && ok;j++){
			if(i%prime[j]==0) ok=false;
		}
		if(ok) prime.push_back(i);

//		cout<<prime.size()<<":"<<prime.back()<<endl;
	}

	ans[0]=prime[0];
	for(int i=1;i<10000;i++) ans[i]=prime[i]+ans[i-1];

	int n;
	while(cin>>n,n){
		cout<<ans[n-1]<<endl;
	}


	return 0;
}

Measured memory_bytes: 1428
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

tuple<int,int,bool,bool> dfs(
    const vector<vecint>& g,
    const vecint& num,
    vector<tuple<int,int,bool,bool>>& vr,
    int i, int p = -1) {
  if (num[i] >= 0) {
    vr[i] = make_tuple(num[i], num[i], num[i] % 2 == 0, num[i] % 2 == 1);
    return vr[i];
  }
  int mn = 0;
  int mx = 1000000;
  bool ise = false, iso = false;
  for (auto&& to:g[i]) {
    if (to == p) continue;
    int cn, cx;
    bool ce, co;
    tie(cn, cx, ce, co) = dfs(g, num, vr, to, i);
    mn = max(mn, cn-1);
    mx = min(mx, cx+1);
    if (ce) iso = true;
    else if (co) ise = true;
  }
  if (ise && iso) {
    cout<<"No\n";
    exit(0);
  }
  if (ise) {
    mn += mn % 2;
    mx -= mx % 2;
  } else if (iso) {
    mn += (mn+1) % 2;
    mx -= (mx+1) % 2;
  }
  if (mn > mx) {
    cout<<"No\n";
    exit(0);
  }
  vr[i] = make_tuple(mn, mx, ise, iso);
  return vr[i];
}

void dfs2(
    const vector<vecint>& g,
    vecint& num,
    const vector<tuple<int,int,bool,bool>>& vr,
    int pnum, int i, int p = -1) {
  if (num[i] >= 0) return;
  int mn, mx;
  bool ise, iso;
  tie(mn, mx, ise, iso) = vr[i];
  int candi = pnum-1;
  if (mn <= candi && candi <= mx) {
    num[i] = candi;
  } else {
    num[i] = pnum+1;
  }
  for (auto&& to : g[i]) {
    if (to == p) continue;
    dfs2(g, num, vr, num[i], to, i);
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin>>n;
  vector<vecint> g(n);
  REP(i,n-1) {
    int a,b;
    cin>>a>>b;
    --a;--b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  int k;
  cin>>k;
  vecint num(n, -1);
  REP(i,k) {
    int v,p;
    cin>>v>>p;
    --v;
    num[v] = p;
  }
  vector<tuple<int,int,bool,bool>> vr(n);
  REP(i,n) {
    if (num[i] < 0) {
      int mn, mx;
      bool ise, iso;
      tie(mn, mx, ise, iso) = dfs(g, num, vr, i);
      dfs2(g, num, vr, mn+1, i);
    }
  }
  REP(i,n) {
    for (auto&& to : g[i]) {
      if (abs(num[to] - num[i]) != 1) {
        cout<<"No\n";
        return 0;
      }
    }
  }
  cout<<"Yes\n";
  REP(i,n) {
    cout<<num[i]<<"\n";
  }
  return 0;
}


Measured memory_bytes: 15104
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int W = in.nextInt();
    int H = in.nextInt();
    int x = in.nextInt();
    int y = in.nextInt();
    int r = in.nextInt();

    if (x - r < 0 || x + r > W || y - r < 0 || y + r > H) {
      System.out.println("No");
    }
    else {
      System.out.println("Yes");
    }
  }
}

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

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
int main(){
  string s;cin>>s;
  reverse(s.begin(), s.end());
  bool ans=true;
  int pos=0;
  while(pos<(int)s.size()){
  	char c=s[pos];
    if(c=='m'){
      if(s.substr(pos, 5)=="maerd")pos+=5;
      else{ans=false;break;}
    }else if(c=='e'){
      if(s.substr(pos, 5)=="esare")pos+=5;
      else{ans=false;break;}
    }else if(c=='r'){
      if(pos>=(int)s.size()-2){ans=false;break;}
      else if(s[pos+2]=='m'){
      	if(s.substr(pos, 7)=="remaerd")pos+=7;
        else{ans=false;break;}
      }else if(s[pos+2]=='s'){
      	if(s.substr(pos, 6)=="resare")pos+=6;
        else{ans=false;break;}
      }else{
      	ans=false;break;
      }
    }else{
      ans=false;break;
    }
  }
  if(pos!=(int)s.size())ans=false;
  cout<<(ans?"YES":"NO")<<endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
    
    int n;
    cin >> n;
    int count=0;
    
    vector<int> vec(n);
    
    for(int i=0;i<n;i++){
        cin >> vec[i];
        count^=vec[i];
    }
    
    for(int i=0;i<n;i++){
        int x=count^vec[i];
      cout<<x<< " ";
    }
    cout <<endl;
}


Measured memory_bytes: 3880