akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int a,b;
    cin >> a >> b;
    if(a>b)swap(a,b);
    if(a==1&&b==2)cout << 3 << endl;
    else if(a==2&&b==3)cout << 1 << endl;
    else cout << 2 << endl;
}

Measured memory_bytes: 256
// 有點不耐煩會破壞偉大的計劃

#include <bits/stdc++.h>

#define append push_back

using namespace std;
using ll = long long;

const int N = 1e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 9;
const int SM = 1e3 + 5;
const int logN = 22, BL = 400;
const double EPS = 1e-9, PI = acos(-1);
const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1};
const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1};

void debug() {
	cerr << "\n";
}
template<typename Type1, typename... Type2>
void debug(Type1 a, Type2... b) {
    cerr << a << " ";
    debug(b...);
}

int main() {
//    freopen(".in", "r", stdin);
//    freopen(".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    long long n; cin >> n;

    for(long long i = 1; i <= n; i++) {
        if(floor(double(i) * double(1.08)) == n) {
            return cout << i, 0;
        }
    }

    cout << ":(";

    return 0;
}


Measured memory_bytes: 3576
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main(){
  map<string,int> mp;
  int q;
  cin >> q;
  REP(i,q){
    int b;
    cin >> b;
    string key;
    cin >> key;
    if(b==0){
      int x;
      cin >> x;
      mp[key] = x;
    }else if(b==1){
      cout << mp[key] << endl;
    }else if(b==2){
      mp.erase(key);
    }
  }
}



Measured memory_bytes: 27684
//c++ テンプレ
#include<bits/stdc++.h>
using namespace std;

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve(){
    int x;
    int n;
    cin >> x >> n;
    vector<int>p(n);
    vector<bool>f(102,true);
    for(int i=0;i<n;i++){
        cin >> p[i];
        f[p[i]]=false;
    }
    int ans=0;
    int dif=1e9;
    for(int i=0;i<102;i++){
        if(dif>abs(x-i) && f[i]==true){
            dif=abs(x-i);
            ans=i;
        }
        if(dif==abs(x-i))ans=min(ans,i);
    }
    cout << ans << endl;

}

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


Measured memory_bytes: 3576
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--)
#define Rep(i,a) for(int i = 0; i < a; i++)
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
#define x first
#define y second
#define pb(a) push_back(a)
const int N = 110;
int n, m, f[2][N][N][N];
char a[N][N];
int s[N][N];
void upd(int &a, int b) { if (b > a) a = b; }

int sum(int a, int b, int c, int d) {
	return s[b][d] - s[a - 1][d] - s[b][c - 1] + s[a - 1][c - 1];
}

int main() {
	scanf("%d%d",&n,&m);
	rep(i,1,n) scanf("%s",a[i] + 1);
	int u, d, l, r;
	rep(i,1,n) rep(j,1,m) if (a[i][j] == 'E') {
		u = i, d = n - i + 1;
		l = j, r = m - j + 1;
	}

	rep(i,1,n) rep(j,1,m) s[i][j] = (a[i][j] == 'o');
	rep(i,1,n) rep(j,1,m) s[i][j] += s[i][j - 1];
	rep(i,1,n) rep(j,1,m) s[i][j] += s[i - 1][j];

	int ans = 0;
	dep(i,n,1) {
		memset(f[i & 1], 0, sizeof(f[i & 1]));
		rep(j,i,n) dep(k,m,1) rep(t,k,m) {
			int F;
			//up
			F = f[(i & 1)^1][j][k][t];
			if (j - i + 1 <= d) {
				int L = max(k, t - r + 1), R = min(t, k + l - 1);
				F += sum(i, i, L, R);
			}
			upd(f[i&1][j][k][t], F);
			//down
			F = f[i & 1][j - 1][k][t];
			if (j - i + 1 <= u) {
				int L = max(k, t - r + 1), R = min(t, k + l - 1);
				F += sum(j, j, L, R);
			}
			upd(f[i&1][j][k][t], F);
			//left
			F = f[i & 1][j][k + 1][t];
			if (t - k + 1 <= r) {
				int U = max(i, j - d + 1), D = min(j, i + u - 1);
				F += sum(U, D, k, k);
			}
			upd(f[i&1][j][k][t], F);
			//right
			F = f[i & 1][j][k][t - 1];
			if (t - k + 1 <= l) {
				int U = max(i, j - d + 1), D = min(j, i + u - 1);
				F += sum(U, D, t, t);
			}
			upd(f[i&1][j][k][t], F);
			upd(ans, f[i & 1][j][k][t]);
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

#define rep(i,n) for(int i=0;i<n;++i)
#define Rep(i,n) for(int i=1;i<=n;++i)
#define rrep(i,n) for(int i=n-1;0<=i;--i)
#define rRep(i,n) for(int i=n;0<i;--i)
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define EPS 1e-8
#define INF 1e8

typedef double Real;
typedef int Int;
typedef vector<Int> vi;
typedef vector<vector<Int> > vvi;
typedef pair<Int,Int> pii;

inline Real sr(Real a) {return sqrt(max(a, (Real)0));}
const vi dy = {-1, 0, 1, 0}, dx = {0, -1, 0, 1};

template <typename K, typename V> ostream& operator<< (ostream& out, const pair<K, V>& p) {
  out << '(' << p.first << ", " << p.second << ')';
  return out;
}

template <typename T> ostream& operator<< (ostream& out, const vector<T>& v) {
  out << '[';
  rep(i, v.size()) out << v[i] << ",";
  out << "\b], " << v.size();
  return out;
}

vi tetrahedralNums;

inline int calcTetrahedralNum(int N){
  return N * (N + 1) * (N + 2) / 6;
}

int M = 183;

void solve(){
  int N, ansA, ansB;
  tetrahedralNums.resize(M);
  rep(i, M) tetrahedralNums[i] = calcTetrahedralNum(i+1);

  vi dp1(1e6+1, INF), dp2(1e6+1, INF);
  dp1[0] = 0;
  rep(i, M){
    int m = tetrahedralNums[i];
    for(int j = m; j <= 1e6; j++)
      if(dp1[j] > dp1[j - m] + 1)
          dp1[j] = dp1[j - m] + 1;
  }

  dp2[0] = 0;
  rep(i, M){
    if(tetrahedralNums[i] % 2 == 0) continue;
    int m = tetrahedralNums[i];
    for(int j = m; j <= 1e6; j++)
      if(dp2[j] > dp2[j - m] + 1)
          dp2[j] = dp2[j - m] + 1;
  }

  while(cin >> N && N){
    cout << dp1[N] << ' ' << dp2[N] << endl;
  }
}

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(9);

  solve();

  return 0;
}

Measured memory_bytes: 10668
N = int(input())
S = []
hoge = 1
i = 0
while hoge <= N:
    S.append([])
    i += 1
    for j in range(i):
        S[-1].append(hoge)
        hoge += 1

if S[-1][-1] == N:
    print("Yes")
else:
    print("No")
    exit()

N = len(S)
print(N+1)

for i in range(N):
    print(N,end = " ")
    x,y = 0,i
    for j in range(i+1):
        x = j
        print(S[y][x],end=" ")
    for j in range(i+1,N):
        y = j
        print(S[y][x],end=" ")
    print()
print(N,end = " ")
for i in S:
    print(i[-1],end = " ")
print()

Measured memory_bytes: 8456
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE TypeApplications #-}
import Data.Char (isSpace)
import qualified Data.Vector.Unboxed as U
import qualified Data.ByteString.Char8 as BS

solve :: U.Vector Int -> Int
solve xs = let ys = U.scanl max 0 xs
           in U.sum $ U.map (max 0) $ U.zipWith (-) (U.tail ys) xs

main = do
  n <- readLn @Int
  xs <- U.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  print $ solve xs


Measured memory_bytes: 11700
#include <iostream>
#include <algorithm>

const int gcd(const int a, const int b)
{
    if(a % b == 0)
    {
        return b;
    }

    return gcd(b, a % b);
}

const int lcm(const int a, const int b,  const int g)
{
    return (a / g) * b;
}

int main(void)
{
    int a, b;

    while(std::cin >> a >> b)
    {
        if(a < b)
        {
            std::swap(a, b);
        }
    
        const int g = gcd(a, b);
        const int l = lcm(a, b, g);
    
        std::cout << g << " " << l << std::endl;
    }

    return 0;
}

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

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

  vector<pair<int, int>> p;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    p.emplace_back(b, a);
  }

  sort(p.begin(), p.end());

  int pos = 0, ans = 0;
  for (auto e : p) {
    int a = e.second, b = e.first;
    if (a < pos && pos <= b)
      continue;
    pos = e.first;
    ++ans;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1400
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        s: chars,
    }
    let mut sub_flag = 0;
    let mut res = 0;

    let a_idx = &s
        .iter()
        .enumerate()
        .filter(|&(i, &c)| &c == &'A')
        .map(|(i, _)| i)
        .collect::<Vec<_>>();
    let z_idx = &s
        .iter()
        .enumerate()
        .filter(|&(i, &c)| &c == &'Z')
        .map(|(i, _)| i)
        .collect::<Vec<_>>();

    println!("{}", *z_idx.last().unwrap() - *a_idx.first().unwrap() + 1);
}


Measured memory_bytes: 8444
/**********************************************************************
File    .cpp
Author  Takahiro Yamazaki
**********************************************************************/
/**********************************************************************
Include Libraries
**********************************************************************/
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
/**********************************************************************
Declare variables
**********************************************************************/
/**********************************************************************
Declare instance
**********************************************************************/
/**********************************************************************
Proto_type_Declare functions
**********************************************************************/

/**********************************************************************
Main
**********************************************************************/
int main() {
  int n;
  cin >> n;
  string s[220000];
  rep(i,n) cin >> s[i];
  int ans = 1;

  sort(s, s+n);
  rep(i,n-1){
    if(s[i+1] != s[i]){
      ans++;
    }
  }
  printf("%d\n", ans);
  // printf("%s\n", s[0]);
  // printf("%s\n", s[1]);
  // rep(i,n){
  //   rep(j,n){
  //     if (s[i] == ) {
  //       /* code */
  //     }
  //   }
  // }
}
/**********************************************************************
Functions
**********************************************************************/


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

int main() {
    int n;
	while(cin>>n,n){
        int p=0;
        vector<int> a;
        a.resize(n);
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        sort(a.begin(),a.end());
        
        for(int i=1;i<n-1;i++){
            p+=a[i];
        }
        cout << p/(n-2) << endl;
    }

	return 0;
}

Measured memory_bytes: 3140
cnt = 0


def insertion_sort(a, n, g):
    global cnt
    for i in range(g, n):
        v = a[i]
        j = i-g
        while j >= 0 and a[j] > v:
            a[j+g] = a[j]
            j = j-g
            cnt += 1
        a[j+g] = v


def shell_sort(a, n):
    g = [1]
    for i in range(100):
        if g[-1]*3+1 < n:
            g.append(g[-1]*3+1)
    g.reverse()
    m = len(g)
    print(m)
    print(' '.join(map(str, g)))
    for i in range(m):
        insertion_sort(a, n, g[i])


def main():
    n = int(input())
    a = []
    for i in range(n):
        a.append(int(input()))
    shell_sort(a, n)
    print(cnt)
    for i in a:
        print(i)


if __name__ == "__main__":
    main()



Measured memory_bytes: 45512
#include<stdio.h>
#define N 100
#define white 0
#define gray 1
#define black 2

int n,M[N][N];
int color[N],d[N],f[N],t;

void dfsv(int u){
  int v;
  color[u]=gray;
  d[u]=++t;
  for(v=0;v<n;v++){
    if(M[u][v]==0)continue;
    if(color[v]==white){
      dfsv(v);
    }
  }
color[u]=black;
f[u]=++t;
}

void dfs(){
  int u;
  for(u=0;u<n;u++)color[u]=white;
  t=0;
  for(u=0;u<n;u++){
    if(color[u]==white)dfsv(u);
  }
for(u=0;u<n;u++){
  printf("%d %d %d\n",u+1,d[u],f[u]);
}
}

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



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

int n,t[101],c[101],T;

int i1,i2;char ch;
inline int read()
{
	i1=i2=0;ch=0;
	while(!isdigit(ch))	{i1|=ch=='-';ch=getchar();}
	while(isdigit(ch))	{i2=(i2<<1)+(i2<<3)+(ch^48);ch=getchar();}
	return i1? -i2:i2;
}

int main()
{
	n=read(),T=read();
	for(int i=1;i<=n;i++) c[i]=read(),t[i]=read();
	int ans=999999999;
	for(int i=1;i<=n;i++)
	{
		if(t[i]>T) continue;
		if(c[i]<ans)
			ans=c[i];
	}
	if(ans==999999999) printf("TLE\n");
	else cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
package main

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

var dp [100010]bool

func solve() {
	s := next()
	phrases := []string{"dream", "dreamer", "erase", "eraser"}

	dp[0] = true
	for i := 0; i < len(s); i++ {
		// printf("i: %d, %t\n", i, dp[i])
		if !dp[i] {
			continue
		}

		for _, p := range phrases {
			// printf("p: %s, %s\n", p, s[i:])
			if strings.HasPrefix(s[i:], p) {
				dp[i+len(p)] = true
			}
		}
	}

	ok := dp[len(s)]
	if ok {
		println("YES")
	} else {
		println("NO")
	}
	return
}

func main() {
	defer out.Flush()
	in.Buffer(make([]byte, scBufSize), scBufSize)

	in.Split(bufio.ScanWords)

	solve()
}

// --- template ---

const scBufSize = 1e6

var (
	in  = bufio.NewScanner(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
)

func println(a ...interface{}) {
	fmt.Fprintln(out, a...)
}

func printf(format string, a ...interface{}) {
	fmt.Fprintf(out, format, a...)
}

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

func nextInt() int {
	s := next()
	i, e := strconv.Atoi(s)
	if e != nil {
		fmt.Println(e)
	}
	return i
}

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

func unique(list []int) []int {
	m := make(map[int]bool)
	uniq := make([]int, 0)
	for _, e := range list {
		if !m[e] {
			m[e] = true
			uniq = append(uniq, e)
		}
	}
	return uniq
}


Measured memory_bytes: 1024
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn rep<T, F: FnMut() -> T>(n: usize, mut f: F) -> Vec<T> {
    (0..n).map(|_| f()).collect()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let n: usize = scan(tokens);
    let mut c: Vec<usize> = rep(n, || scan(tokens));
    if n == 1 {
        println!("{}", 2 * c[0] % MODULO);
        return;
    }
    c.sort();
    c.reverse();
    let power_of_two = power(2, 2 * n - 2);
    let mut ans = 0;
    for i in 0..n {
        ans = (ans + c[i] * power_of_two % MODULO * (2 + i)) % MODULO;
    }
    println!("{}", ans);
}

const MODULO: usize = 1_000_000_007;

fn power(mut base: usize, mut exponent: usize) -> usize {
    let mut prod = 1;
    while exponent > 0 {
        if exponent & 1 == 1 {
            prod = prod * base % MODULO;
        }
        base = base * base % MODULO;
        exponent >>= 1;
    }
    prod
}

Measured memory_bytes: 9464
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
typedef long long lint;
const int N=2e5+5;
int n,val[N];

namespace utils{
	template <class T> inline void apn(T &x,const T y){x>y?x=y:0;}
	template <class T> inline void apx(T &x,const T y){x<y?x=y:0;}
	inline int nxi(){
		int x=0;
		char c;
		while(((c=getchar())>'9'||c<'0')&&c!='-');
		const bool f=(c=='-')&&(c=getchar());
		while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
		return f?-x:x;
	}
}
using namespace utils;

int main(){
	n=nxi();
	for(int i=1; i<=n; ++i){
		val[i]=nxi();
	}
	for(int i=n; i>=1; i-=2){
		printf("%d ",val[i]);
	}
	for(int i=n&1?2:1; i<=n; i+=2){
		printf("%d ",val[i]);
	}
	puts("");
	return 0;
}


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

N = int(input())
if N%2==1:
    print(0)
    exit()
res = 0
M = N//2
a=0
b=0
for keta in range(1,54):
    tmp = M//(2**keta)
    a += tmp
    tmp = M//(5**keta)
    b += tmp

print(min([a,b]))


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

int main(){
  int N, M;
  cin >> N >> M;

  vector<int> a(N);
  vector<int> b(N);
  for (int i=0; i<N; i++){
    cin >> a.at(i) >> b.at(i);
  }

  vector<int> c(M);
  vector<int> d(M);
  for (int i=0; i<M; i++){
    cin >> c.at(i) >> d.at(i);
  }

  for (int i=0; i<N; i++){
    int x, y, min, index=1;
    x = c.at(0) - a.at(i);
    y = d.at(0) - b.at(i);
    if (x<0){
      x = -x;
    }
    if (y<0){
      y = -y;
    }
    min = x + y;

    for (int j=1; j<M; j++){
      x = c.at(j) - a.at(i);
      y = d.at(j) - b.at(i);
      if (x<0){
        x = -x;
      }
      if (y<0){
        y = -y;
      }

      if (min > x+y){
        min = x + y;
        index = j+1;
      }
    }
    cout << index << endl;
  }
}


Measured memory_bytes: 256
n, m = map(int, input().split())
l = 1
r = n
for i in range(m):
    L, R = map(int, input().split())
    l = max(L, l)
    r = min(R, r)

ans = r - l + 1 if r - l + 1 > 0 else 0
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ff first
#define ss second
typedef long long ll;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
bool isPalin(string s){
    if (s==string(s.rbegin(),s.rend()))
        return true;
    return false;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
ll a[3000][3000];
ll dp[3000][3000][4];
int main(){
    ll t=1;
    //cin>>t;
    while(t--){
        int r,c,k;
        cin>>r>>c>>k;
        for(int i=0;i<r;i++){
            for(int j=0;j<c;j++){
                for(int l=0;l<4;l++)
                    dp[i][j][l]=0;
                a[i][j]=0;
            }
        }        
        for(int i=0;i<k;i++){
            int p,q,r;
            cin>>p>>q>>r;
            a[p-1][q-1]=r;
        }
        ll ans=0ll;
        for(int i=0;i<r;i++){
            for(int j=0;j<c;j++){
                if(i-1>=0){
                    for(int ctr=0;ctr<4;ctr++)
                        dp[i][j][0]=max(dp[i][j][0],dp[i-1][j][ctr]);
                }
                if(j-1>=0){
                    for(int ctr=0;ctr<4;ctr++)
                        dp[i][j][ctr]=max(dp[i][j][ctr],dp[i][j-1][ctr]);
                }
                if(a[i][j]>0){
                    for(int ctr=3;ctr>0;ctr--)
                        dp[i][j][ctr]=max(dp[i][j][ctr],dp[i][j][ctr-1]+a[i][j]);
                }
                for(int ctr=0;ctr<4;ctr++)
                    ans=max(ans,dp[i][j][ctr]);
            }
        }
        cout<<ans<<"\n";
    }
    return 0;
}


Measured memory_bytes: 355000
#include <stdio.h>
int main(void)
{
    int i, ans=1, h[20], n, j, cnt=0;
    scanf("%d", &n);
    for(i=0;i<n;i++){
        scanf("%d", &h[i]);
    }

    for(i=1;i<n;i++){
        cnt=0;
        for(j=i-1;j>=0;j--){
            if(h[i]>=h[j]) cnt++;
            else break;
        }
        if(cnt==i) ans++;
    }

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

    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;
import java.util.BitSet;

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

		while(stdin.hasNext()){
			int n = stdin.nextInt();
			if (n == 0) break;
			System.out.println(primeNumberNums(n));
		}

		System.exit(0);
	}

	public static int primeNumberNums(int n){
		BitSet bs = new BitSet(n);
		for (int i = 2; i <= n; i++){
			int j = i;
			while(j <= n * 2){
				if (j > n) bs.set(j - n, true);
				j += i;
			}
		}
		return n - bs.cardinality();
	}
}

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

int main() {
    int n, a, b, c, d;
    cin >> n;
    d = n % 10;
    c = (n % 100 - d) / 10;
    b = (n % 1000 - c*10 - d) / 100;
    a = (n - b*100 - c*10 - d) / 1000;
    if(a == b && b == c || b == c && c == d) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3576
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

def lcm(a,b):
  return a*b//gcd(a,b)

def numberof2(n):
  ans = 0
  while n%2 == 0:
    n = n//2
    ans += 1
  return ans

N, M = map(int,input().split())
A = list(map(int,input().split()))
cnt = M

for i in range(N):
  if A[i]%2 == 0:
    A[i] = A[i]//2
  else:
    cnt = 0
for i in range(N-1):
  if numberof2(A[i]) != numberof2(A[i+1]):
    cnt = 0
    
lcm = A[0]
for i in range(1, N):
  lcm = lcm*A[i]//gcd(lcm, A[i])

print(min(cnt, 1+(M-lcm)//(2*lcm)))

Measured memory_bytes: 15060
#スペース区切りで代入する
a,b,c=gets.chomp.split(" ")
#それぞれの末尾1文字と頭文字1文字を切り出す。
if a[-1,1] == b[0,1] && b[-1,1] == c[0,1]
  puts "YES"
else
  puts "NO"
  
end

Measured memory_bytes: 1788
import sys
import math
readline = sys.stdin.readline
N, K = list(map(int, readline().split()))

ans = 0
for i in range(1, N+1):
        now = i
        tmp = 1/N
        while now < K:
            now = now * 2
            tmp = tmp / 2
        ans += tmp

print(ans)

Measured memory_bytes: 3060
import sys
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, K = map(int, readline().split())
A = list(map(int1, readline().split()))

visited = [0] * N
order = [0]
visited[0] = 1

pos = 0
while True:
    next_town = A[pos]
    
    if visited[next_town] == 1:
        order.append(next_town)
        break
    visited[next_town] += 1
    pos = next_town
    order.append(pos)

idx = order.index(order[-1])
l_l = len(order) - idx - 1
l = len(order) -1 - l_l

if K < len(order):
    print(order[K] + 1)
    sys.exit()
    
K -= l
K %= l_l

print(order[l+K]+1)



Measured memory_bytes: 27976
#coding: utf-8
N = int(raw_input())
rates = map(int, raw_input().split(' '))

colors = [0 for _ in range(8)]
top = 0
for r in rates:
	mod = r / 400
	if mod < 8:
		colors[mod] = 1
	else:
		top += 1	

minnum = sum(colors)
maxnum = minnum + top
if minnum == 0:
	minnum = 1
print '{} {}'.format(minnum, maxnum)

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

int main()
{
    int n;
    cin>>n;
    vector<int> l(n);
    for(int i=0;i<n;i++)cin>>l[i];
    sort(l.begin(),l.end());
    int t;
    int ans=0;
    for(int i=0;i<n-2;i++){
	    for(int k=i+1;k<n-1;k++){
		    t=k+1;
		    while(l[t]<l[i]+l[k]&&t<n){
			    ans++;
			    t++;
		    }
	    }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b))<EPS)

int n,m,w,h,S;
// A[hªüªæèºÉ é©Ç¤©
bool check(pair<int,int> p,double x,double y){
    // X«
    double d=(double)(p.first-p.second)/(0-w);
    double yv=d*(x-0)+p.first;
    return (yv>y);
}

int main(){
    while(cin>>n>>m>>w>>h>>S&&!(n==0&&m==0&&w==0&&h==0&&S==0)){
        int l,r;
        vector<pair<int,int> > ps;
        int armond[30001];
        memset(armond,0,sizeof(armond));
        ps.push_back(make_pair(0,0));
        for(int i = 0; i < m; i++){
            cin>>l>>r;
            ps.push_back(make_pair(l,r));
        }
        // A[hªÇÌfÐãÉ é©ÍL¯µÄ¨­
        for(int i = 0; i < n; i++){
            double x,y;
            cin>>x>>y;
            // A[hª»ÌüæèºÉ éºÀðTõ
            int ub=m;int lb=-1;
            while(ub-lb>1){
                bool b;
                int med=(ub+lb)/2;
                if(check(ps[med],x,y))
                    ub=med;
                else
                    lb=med;
            }
            // ubÌlªºÀÌüª
            armond[ub]++;
        }
        // µá­Æè@Å`R[gãðTõ
        int head=0;int tail=0;
        double peco=w*h;
        int arNum=n;
        const int INF=100000000;
        int minArNum=INF;
        // tailªÍÍ©çoéÜÅTõ
        while(tail<=m&&head<=tail){
            // ¶å¤¯ñð½µÄ¢éÈçXV
            if(EQ(peco,S)||peco>S)
                minArNum=min(minArNum,arNum);
            // àµ»ÝÌ×[±Ì`R[gÌÊÏªSÈºÈçAheadðâ·
            // »¤ÅÈ¢ÈçAtailðâ·
            if(EQ(peco,S)||peco>S){
                // tailðâ·
                tail++;
                if(!(tail<=m&&head<=tail))
                    break;
                // ÊÏðXV
                double ss=((double)abs(ps[tail-1].first-ps[tail].first)+abs(ps[tail-1].second-ps[tail].second))*w/2.0;
                peco-=ss;
                arNum-=armond[tail];
            }
            else{
                head++;
                if(!(tail<=m&&head<=tail))
                    break;
                // ÊÏðXV
                double ss=((double)abs(ps[head-1].first-ps[head].first)+abs(ps[head-1].second-ps[head].second))*w/2.0;
                peco+=ss;
                arNum+=armond[head];
            }
        }
        cout<<minArNum<<endl;
    }
    return 0;
}

Measured memory_bytes: 1572
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF 100000000
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100000
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
bool saw[3000];
int a[3000];
vector<int> e[3000];
vector<int> out;

bool dfs(int v, int now){
    int ret = now^1;
    saw[v] = true;
    rep(i,e[v].size()){
        if(saw[e[v][i]]) continue;
        if(a[e[v][i]] >= a[v]) continue;
        if(dfs(e[v][i],now^1) == now) return now;
    }
    return ret;
}

int main(){
    cin >> n;
    rep(i,n) cin >> a[i];
    rep(i,n-1){
        int u, v;
        cin >> u >> v;
        u--; v--;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    rep(i,n){
        memset(saw,0,sizeof(saw));
        if(!dfs(i,0)) out.push_back(i);
    }
    rep(i,out.size()){
        cout << out[i]+1;
        if(i != out.size()-1) cout << " ";
    }
    cout << endl;
}


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

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

	vector<int> v(n + 1); for (int i = 1; i <= n; i++) cin >> v[i];

	const int N = 100010;

	vector<int> o(N);
	vector<int> e(N);
	int o_maxNum_first = 0;
	int o_maxNum_second = 0;
	int o_maxValue;
	int e_maxNum_first = 0;
	int e_maxNum_second = 0;
	int e_maxValue;

	for (int i = 1; i <= n; i++) {
		if (i % 2 == 0) {
			e[v[i]]++;
		}
		else {
			o[v[i]]++;
		}
	}

	for (int j = 0; j < N; j++) {

		if (o_maxNum_first <= o[j]) {
		
			o_maxNum_second = o_maxNum_first;
			o_maxNum_first = o[j];
			o_maxValue = j;
		
		}
		else if (o_maxNum_second <= o[j] ) {

			o_maxNum_second = o[j];
		}
		
		if (e_maxNum_first <= e[j]) {

			e_maxNum_second = e_maxNum_first;
			e_maxNum_first = e[j];
			e_maxValue = j;

		}	
		else if (e_maxNum_second <= e[j]) {

			e_maxNum_second = e[j];
		}


	}

	int ans;

	if (o_maxValue != e_maxValue) {

		ans = n - o_maxNum_first - e_maxNum_first;

	}
	else { //  o_maxValue == e_maxValue

		ans = min(n - o_maxNum_first - e_maxNum_second, n - e_maxNum_first - o_maxNum_second);

	}

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

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

int main() {
    using namespace std;
    unsigned long K;
    cin >> K;
    long X, Y;
    cin >> X >> Y;
    if(~K & (X ^ Y) & 1)return 0 & puts("-1");
    {
        auto t = X + Y;
        Y = X - Y;
        X = t;
    }
    bool x = X < 0, y = Y < 0;
    if(x)X *= -1;
    if(y)Y *= -1;
    vector<pair<long, long>> ans;
    if(X <= K && Y <= K){
        if (X == K || Y == K){
            ans.emplace_back(X, Y);
        }else if(X & 1){
            ans.emplace_back(X - K + 1, K);
            ans.emplace_back(X - K, 0);
            ans.emplace_back(X, Y);
        }else{
            ans.emplace_back(X - K, K);
            ans.emplace_back(X, Y);
        }
    }else{
        unsigned long time = (max(X, Y) + K - 1) / K;
        if(K & (time ^ X) & 1)++time;
        unsigned long remX = time * K - X, remY = time * K - Y;
        long a{0}, b{0};
        for(unsigned long i = 0; i < time; ++i){
            if(remX){
                if(remX >= 2 * K){
                    a -= K;
                    remX -= 2 * K;
                }else{
                    a += K - remX;
                    remX = 0;
                }
                b += K;
            }else if(remY){
                if(remY >= 2 * K){
                    b -= K;
                    remY -= 2 * K;
                }else{
                    b += K - remY;
                    remY = 0;
                }
                a += K;
            }else{
                a += K;
                b += K;
            }
            ans.emplace_back(a, b);
        }
    }
    cout << ans.size() << endl;
    for(const auto& i : ans){
        auto aa = i.first * (x ? -1 : 1);
        auto bb = i.second * (y ? -1 : 1);
        cout << (aa + bb) / 2 << " " << (aa - bb) / 2 << endl;
    }
    return 0;
}

Measured memory_bytes: 6000
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>F,R;void setF(int n,int mod){F=R=V<ll>(++n);F[0]=1;FOR(i,1,n)F[i]=F[i-1]*i%mod;R[n-1]=modInv(F[n-1],mod);FORR(i,n-1,1)R[i-1]=R[i]*i%mod;}
//ll comb(int a,int b,int m){return a<b||b<0?0:F[a]*R[b]%m*R[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7; //998244353;
const int N = 2e5;
int h, n;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> h >> n;
  FOR(_, 0, n){
    int a;
    cin >> a;
    h -= a;
    if(h<=0){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int n, m, ans[100], x, y; 
signed main(){
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; ++i) scanf("%d%d", &x, &y), ans[x]++, ans[y]++;
	for(int i = 1; i <= n; ++i) printf("%d\n", ans[i]);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
  int N, M;
  while(cin >> N >> M && N){
    vector<int> coin(N);
    REP(i, N) cin >> coin[i];
    vector<int> v(1 << N);
    REP(S, 1 << N) REP(i, N) if(S >> i & 1) v[S] += coin[i];
    vector<int> dp(M + 1, INF);
    dp[0] = 0;
    for(int i = 1; i <= M; i++){
      for(int j = 0; j < v.size(); j++){
        if(i - v[j] >= 0){
          dp[i] = min(dp[i], dp[i - v[j]] + 1);
        }
      }
    }
    cout << dp[M] << endl;
  }
  return 0;
}

Measured memory_bytes: 1592
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;
constexpr long long int INF = std::numeric_limits<long long int>::max();
constexpr long long int NINF = std::numeric_limits<long long int>::min();
#define int long long int

const int MAX = 3 * 100000;
const int MOD = 1000000007;

int fac[MAX], finv[MAX], inv[MAX];

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

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

int kaijo[1001] = {1};

void solve() {
  COMinit();
  for (int i = 1; i <= 1000; i++) {
    kaijo[i] = i * kaijo[i - 1];
  }

  int N, K;
  cin >> N >> K;

  int R = N - K;

  for (int i = 1; i <= K; i++) {
    int r = R;
    int b = K;

    int ans_b = COM(b - 1, i - 1);
    int ans_a = COM(r + 1, i);
    // cout << "ans_b: " << ans_b << endl;
    // cout << "ans_a: " << ans_a << endl;
    // cout << "a_r: " << r + 1 << endl;
    // cout << "a_i: " << i + 1 << endl;
    int ans = (ans_b * ans_a) % MOD;
    cout << ans << endl;
  }
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


Measured memory_bytes: 7296
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define sz 10000009
#define mod 998244353
ll n,m,i,j,k,t,arr[sz],brr[sz],l;
vector<ll>v[sz];
map<ll,ll>mp;
vector<pair<ll,ll> >v1;
int main()
{
 for(i=1;i<=10000000;i++)
 {
    for(j=1;j*i<=10000000;j++)
        arr[i*j]++;
 }
 for(i=1;i<=10000000;i++)
    arr[i]*=i,brr[i]=brr[i-1]+arr[i];
    scanf("%lld",&n);
    printf("%lld\n",brr[n]);
 return 0;
}


Measured memory_bytes: 394432
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
    long long int N, mod = 1000000007;
    cin >> N;
    long long int a = 1, b = 1, c = 1;
    for(int i = 0; i < N; i++){
        a *= 10;
        a = a % mod;
        b *= 9;
        b = b % mod;
        c *= 8;
        c = c % mod; 
    }
    long long int A, B;
    B = 2 * b;
    B = B % mod;
    A = a - B + c;
    if(A < 0){
        A = A + mod;
    }
    cout << A;
}

Measured memory_bytes: 3640
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.IOException;

public class Main {

    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        String T = br.readLine().toLowerCase();

        int count = 0;
        String input;
        while (!(input = br.readLine()).equals("END_OF_TEXT")) {
            String[] word = input.toLowerCase().split(" ");
            for (String w : word) {
                if (T.equals(w)) {
                    count++;
                }
            }
        }

        bw.append(count + "\n");
        bw.flush();
    }

}


Measured memory_bytes: 24360
# https://atcoder.jp/contests/abc138/tasks/abc138_d

import sys
input = sys.stdin.readline
from copy import deepcopy


class Graph:
    def __init__(self, n, dictated=False, decrement=True, edge=[]):
        self.n = n
        self.dictated = dictated
        self.decrement = decrement
        self.edge = [set() for _ in range(self.n)]
        self.parent = [-1]*self.n
        self.info = [-1]*self.n
        for x, y in edge:
            self.add_edge(x,y)

    def add_edge(self, x, y):
        if self.decrement:
            x -= 1
            y -= 1
        self.edge[x].add(y)
        if self.dictated == False:
            self.edge[y].add(x)

    def add_adjacent_list(self, i, adjacent_list):
        if self.decrement:
            self.edge[i] = set(map(lambda x:x-1, adjacent_list))
        else:
            self.edge[i] = set(adjacent_list)

    def dfs2(self, info, start, goal=-1, time=0, save=False):
        """
        :param info: 各頂点の付加情報
        :param start: スタート地点
        :param goal: ゴール地点
        :param save: True = 前回の探索結果を保持する
        :return: ゴール地点までの距離。存在しなければ -1
        """

        if self.decrement:
            start -= 1
            goal -= 1
        # if not save:
        #     self.parent = [-1] * self.n
        # 
        # edge2 = deepcopy(self.edge)
        
        edge2 = self.edge

        p, t = start, time
        self.parent[p] = -2
        while True:
            if edge2[p]:
                q = edge2[p].pop()
                if q == self.parent[p] and not self.dictated:
                    """ 逆流した時の処理 """
                    """"""""""""""""""""
                    continue
                if self.parent[q] != -1:
                    """ サイクルで同一点を訪れた時の処理 """
                    """"""""""""""""""""
                    continue
                if q == goal:
                    """ ゴール時の処理"""
                    # return t + 1
                    """"""""""""""""""""
                    continue
                """ p から q への引継ぎ"""
                info[q] += info[p]
                """"""""""""""""""""
                self.parent[q] = p
                p, t = q, t + 1
            else:
                """ 探索完了時の処理 """
                """"""""""""""""""""
                if p == start and t == time:
                    break
                p, t = self.parent[p], t-1
                """ 二度目に訪問時の処理 """

                """"""""""""""""""""
        return info


######################################################################################################

N, Q = map(int, input().split())  # N:頂点数, Q: クエリの数
M = N-1

graph = Graph(N, dictated=False)

for _ in range(M):
    x, y = map(int, input().split())
    graph.add_edge(x,y)

info = [0] * N
for _ in range(Q):
    p, x = map(int, input().split())
    info[p - 1] += x

print(*graph.dfs2(info, start=1))


Measured memory_bytes: 164272
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a) memset(a,0,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
int main()
{
	ll a,b,c;
	cin>>a>>b>>c;
	if((a==b&&a!=c)||(a==c&&a!=b)||(b==c&&a!=b)) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
ll num[23333];

int main()
{
	ll n;
	cin >> n;
	for(int i = 1;i <= n;i ++) cin >> num[i];
	ll x = 1,ans = 0;
	for(int i = 1;i <= n;i ++) ans += (num[i] - 1);
	cout << ans;
	return 0; 
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18


int calc(vector<int> v,int L) {
	int n = v.size();
	int ret = INF;
	for (int bit=1; bit < (1 << n); bit++){
		
		int tmp = 0;
		int l = 0;

		int bitcnt = 0;
		for (int i = 0; i < n; i++) {
			if ((bit >> i) % 2 == 1) {
				bitcnt++;
				l += v[i];
			}
		}

		if (bitcnt == 0)continue;

		tmp = abs(L - l) + (bitcnt - 1) * 10;

		ret = min(ret, tmp);

	}

	return ret;
}


int main() {

	int n, a, b, c;cin >> n >> a >> b >> c;

	vector<int> l(n);

	for (int i = 0; i < n; i++) {
		cin >> l[i];
	}

	sort(l.begin(), l.end());

	int ans = INF;

	do {

		
		for (int t1 = 0; t1 < n; t1++) {
			for (int t2 = t1+1; t2 < n-1; t2++) {
				int tmp = 0;
				
				vector<int> va;
				vector<int> vb;
				vector<int> vc;

				for (int i = 0; i < n; i++) {
					if (i <= t1) {
						va.push_back(l[i]);
					}
					else if (i <= t2) {
						vb.push_back(l[i]);
					}
					else {
						vc.push_back(l[i]);
					}
				}

				tmp += calc(va, a);
				tmp += calc(vb, b);
				tmp += calc(vc, c);

				ans = min(ans, tmp);
			}
		}

	} while (next_permutation(l.begin(), l.end()));

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = (a); i < (b); ++i)

using namespace std;
using ll = long long;

static const ll INFTY = ll(1e18) + 1;

int N;
ll K;
vector<ll> a;

// count the number of those elements whose values are <= x
ll get_count (ll x) {
  ll cnt = 0;

#ifdef DEBUG
  printf("\nx=%lld\n", x);
#endif

  REP(i, 0, N) {
    if (a[i] < 0) {
      // start from (i, N)
      int l = i;
      int r = N;

      while (abs(r - l) > 1) {
        int m = (l + r) / 2;

        if (a[i] * a[m] <= x) r = m;
        else l = m;
      }

      // [r, N) fulfills the condition
      cnt += N - r;

#ifdef DEBUG
      printf("a[i]=%lld, Δ=%d\n", a[i], N - r);
#endif
    } else {
      // start from (i, N)
      int l = i;
      int r = N;

      while (abs(r - l) > 1) {
        int m = (l + r) / 2;

        if (a[i] * a[m] <= x) l = m;
        else r = m;
      }

      // (i, l] fulfills the condition
      cnt += l - i;

#ifdef DEBUG
      printf("a[i]=%lld, Δ=%d\n", a[i], l - i);
#endif
    }
  }

#ifdef DEBUG
  printf("cnt=%lld\n", cnt);
#endif

  return cnt;
}

ll bs (ll left0, ll right0) {
  // start from (left0, right0)
  ll left = left0;
  ll right = right0;

  while (abs(right - left) > 1) {
    ll mid = (left + right) / 2;

    if (get_count(mid) < K) left = mid;
    else right = mid;
  }

  // (left0, left] fulfills the condition
  return left + 1;
}

/**
 * main
 */
int main () {
  cin >> N;
  cin >> K;

  REP(i, 0, N) {
    ll input;
    scanf("%lld", &input);
    a.push_back(input);
  }

  sort(a.begin(), a.end());

  cout << bs(-INFTY, INFTY) << endl;
}


Measured memory_bytes: 2420
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;
  cin >> N;
  N-=1;
  ll A, B, C, D;
  cin >> A >> B >> C >> D;
  ll target = llabs(A-B);
  ll K = N/2 + 1;
  bool ok = false;
  for(ll i = 0;i < K;i++){
    ll moveback = i * llabs(D-C);
    if((N - i * 2)*C - moveback <= target && target <= (N - i * 2)*D + moveback){
      ok = true;
      break;
    }
  }
  if(ok)cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#include <string>

std::map<char, int> counter;
int main(){
    std::string str;
    std::cin >> str;
    
    for(auto&& c : str){
        ++counter[c];
    }
    
    std::cout << std::min({counter['K'], counter['U'], counter['P'], counter['C']}) << std::endl;
}

Measured memory_bytes: 3228