akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int INF=1e9;
const long double eps=1e-9;
const int maxn=3e2+10;
int dp[maxn][maxn][maxn];
char str[maxn];
inline int read(){
	int x=0,flag=1;
	char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')flag=-1,ch=getchar();
	while(isdigit(ch))x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return x*flag;
}
inline void chkmax(int &x,int y){
	x=x>y?x:y;
}
int main(){
	int i,j,k,m,n;
	scanf("%s",str+1);
	n=strlen(str+1);m=read();
	dp[0][n+1][0]=0;
	for(i=1;i<=n;i++)
		for(j=n;j>=i;j--)
			for(k=0;k<=m;k++){
				if(str[i]==str[j])chkmax(dp[i][j][k],dp[i-1][j+1][k]+1);
				else if(k)chkmax(dp[i][j][k],dp[i-1][j+1][k-1]+1);
				chkmax(dp[i][j][k],dp[i][j+1][k]);chkmax(dp[i][j][k],dp[i-1][j][k]);
			}
	int ans=0;
	for(i=1;i<=n;i++)
		for(j=0;j<=m;j++)
			ans=max(ans,dp[i][i][j]*2-1);
	for(i=1;i<=n;i++)
		for(j=i+1;j<=n;j++)
			ans=max(ans,dp[i][j][m]*2);
	printf("%d\n",ans);
	return 0;
}


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

int n;
int a[111];

int calc(int x) {
	int res = 0;
	for(int i=0;i<n;i++)
		res += (a[i]-x)*(a[i]-x);
	return res;
}

int main() {
	scanf("%d", &n);
	for(int i=0;i<n;i++) scanf("%d", &a[i]);
	
	int ans = 1e9;
	for(int i=1;i<=100;i++)
		ans = min(ans, calc(i));
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
N=int(input())
P=[tuple(map(int,input().split())) for i in range(N-1)]
Path=[[] for i in range(N)]
for p in P:
  Path[p[0]-1].append(p[1]-1)
  Path[p[1]-1].append(p[0]-1)
colornum=1
dic={}
def bfs(nodes,p,pcolor,selfnum):
  global colornum
  if len(nodes)-1==0 and p!=-1:
    return
  c=1
  for n in nodes:
    if n == p:
      continue
    if c==pcolor:
      c+=1
    dic[(selfnum+1,n+1)]=c
    dic[(n+1,selfnum+1)]=c
    bfs(Path[n],selfnum,c,n)
    c+=1
  if c>colornum:
    colornum=c
bfs(Path[0],-1,0,0)
print(colornum-1)
for p in P:
  print(dic[p])

Measured memory_bytes: 94636
#include <iostream>
using namespace std;
int main(){

  int n,a[100],result=0;

  cin>>n;
  for(int i=0;i<n;i++)
    cin>>a[i];
  for(int i=0;i<n-1;i++)
    for(int j=n-2;j!=i-1;j--)
        if(a[j]>a[j+1]){
            swap(a[j],a[j+1]);
            result++;
        }
  for(int i=0;i<n-1;i++)
    cout<<a[i]<<" ";
  cout<<a[n-1]<<endl<<result<<endl;

  return 0;
  
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};




int main(){
    string s;cin >> s;
    cout << s.substr(0, 3) << endl;
    return 0;
}


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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;

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

constexpr long long mod = 1000000007;

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

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

    ll n;
    cin >> n;
    vll a(n);
    rep(i, n) cin >> a[i];

    ll sum = 0;
    rep(i, n) sum ^= a[i];

    rep(i, n){
        ll s = sum ^ a[i];
        cout << s << endl;
    }

}

Measured memory_bytes: 4752
#include <iostream>

using namespace std;

int main(){
	int n1,n2;
	char buf,*cf,*ct,*re;

	while(1){
		cin >> n1;
		if(n1 != 0){
			cf = new char[n1];
			ct = new char[n1];

			for(int i = 0; i < n1; i++){
				cin >> cf[i];
				cin >> ct[i];
			}

			cin >> n2;
			re = new char[n2];

			for(int i = 0; i < n2; i++){
				cin >> buf;

				for(int j = 0; j < n1; j++){
					if(buf == cf[j]){
						buf = ct[j];
						break;
					}
				}

				re[i] = buf;
			}

			for(int i = 0; i < n2; i++){
				cout << re[i];
			}
			cout << endl;
		}else{
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 1004
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        int[] g = {0, 0, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0};

        if (g[a] == g[b]) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21844
use std::collections::BinaryHeap;

macro_rules! scan {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };

    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
}

fn wfs(graph: &[Vec<usize>], root: usize, dists: &mut [i64]) {
    let mut q = BinaryHeap::new();

    dists[root] = 0;
    q.push((0i64, root));
    while let Some((_, r)) = q.pop() {
        for &b in graph[r].iter() {
            let d = dists[r] + 1;
            if d < dists[b] {
                dists[b] = d;
                q.push((-d, b))
            }
        }
    }
}

fn main() {
    let n = scan!(usize);

    let mut graph = vec![vec![]; n + 1];
    for _ in 0..n - 1 {
        let (a, b) = scan!(usize, usize);
        graph[a].push(b);
        graph[b].push(a);
    }

    let mut dists_f = vec![1i64 << 60; n + 1];
    wfs(&graph, 1, &mut dists_f);
    let mut dists_s = vec![1i64 << 60; n + 1];
    wfs(&graph, n, &mut dists_s);

    let (mut s, mut f) = (0, 0);
    for (f0, s0) in dists_f.iter().zip(dists_s.iter()).skip(1) {
        if f0 <= s0 {
            f += 1
        } else {
            s += 1
        }
    }
    println!("{}", if f > s { "Fennec" } else { "Snuke" })
}


Measured memory_bytes: 14588
#include <cassert>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <limits>
#include <numeric>

using namespace std;



int main(){
  ios::sync_with_stdio(false);
  
  int n;         // 1 .. 20
  vector<int> p; // size = n, p[i] = 1 .. 2000
  int q;         // 1 .. 200
  vector<int> M; // size = q, M[j] = 1 .. 2000

  //input
  cin >> n;
  for(int i = 0; i<n; ++i){int p_i; cin >> p_i; p.push_back(p_i);}
  cin >> q;
  for(int j = 0; j<q; ++j){int M_j; cin >> M_j; M.push_back(M_j);}
  
  //calc
  for(auto bagsize : M){
    vector<bool> makable(bagsize, false);
    makable[0] = true;
  
    for(auto w : p){
      for(int j = bagsize; j > 0; --j){
	if(j>=w && makable[j-w]){
	  makable[j] = true;
	}
      }
    }
    
    cout << (makable[bagsize] ? "yes" : "no")
	 << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <string>

using namespace std;

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

	string S;
	cin >> S;
	while (S.length() != 0) {
		S.erase(S.end()-1);
		string a, b;
		if (S.length() % 2 == 0) {
			for (int i = 0; i < S.length() / 2; i++) {
				a += S[i];
			}
			for (int i = S.length()/2; i < S.length(); i++) {
				b += S[i];
			}
			if (a == b) {
				cout << S.length() << '\n';
				break;
			}
		}
		
	}
	
	

	

	return 0;
}

Measured memory_bytes: 256
import sys
import itertools

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
s_readline = sys.stdin.readline

N, K = map(int, readline().split())
S = list(map(int, s_readline().strip()))


def solve():
    s_grp = itertools.groupby(S)
    zl = []
    ol = []

    llen = 0
    f = False

    for k, l in s_grp:

        l = list(l)
        if k == 0:
            llen += len(l)
            f = True
        elif k == 1:
            ol.append(len(l))
            if f:
                llen += len(l)
                zl.append(llen)
                llen = 0

    else:
        if k == 0:
            zl.append(llen)

    if S[0] == 0:
        ol = [0] + ol

    # print(zl)
    # print(ol)

    zl_N = len(zl)

    zl_tsum = [0 for _ in range(zl_N + 1)]
    for i in range(zl_N):
        zl_tsum[i + 1] = zl_tsum[i] + zl[i]

    Km = min(K, zl_N)
    ans = 0
    for i in range(zl_N - Km + 1):
        t = zl_tsum[Km + i] - zl_tsum[i] + ol[i]
        ans = max(ans, t)

    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 6848
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,a[9],b[9],x[9],g=1;
	long double ans=0;
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i]>>b[i],x[i]=i,g*=(i+1);
	do{
		for(int i=1;i<n;i++)
			ans=ans+sqrt(fabs(a[x[i]]-a[x[i-1]])*fabs(a[x[i]]-a[x[i-1]])+fabs(b[x[i]]-b[x[i-1]])*fabs(b[x[i]]-b[x[i-1]]))*1.0/g;
	}while(next_permutation(x,x+n));
	cout<<fixed<<setprecision(10)<<ans;
} 

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    string str;
    cin >> str;
    
    bool flag=true;
    if(str[2]!=str[3]) {
        flag = false;
    }
    if(str[4]!=str[5]) {
        flag = false;
    }
    
    if(flag) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }


    return 0;
    
}

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

long long x;
bool dp[1000106];

bool dfs(long long sum){
    if(dp[sum]) return false;

    if(sum > x){
        dp[sum] = true;
        return false;
    }
    if(sum == x) return true;

    if(dfs(sum+100)) return true;
    if(dfs(sum+101)) return true;
    if(dfs(sum+102)) return true;
    if(dfs(sum+103)) return true;
    if(dfs(sum+104)) return true;
    if(dfs(sum+105)) return true;

    dp[sum] = true;
    return false;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> x;
    if(dfs(0)) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

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

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

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

func debug(a ...interface{}) {
	if os.Getenv("ONLINE_JUDGE") == "false" {
		fmt.Fprintln(os.Stderr, a...)
	}
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	s := scanString()
	ans := len(s) * (len(s) + 1) / 2
	sa := newSuffixArray(s)
	lcp := newLCPArray(s, sa)
	for i := 0; i < len(lcp); i++ {
		ans -= lcp[i]
	}
	fmt.Fprintln(wr, ans)
}

func newSuffixArray(s string) []int {
	n := len(s)
	sa := make([]int, n+1)
	ra, tmp := make([]int, n+1), make([]int, n+1)

	for i := 0; i <= n; i++ {
		sa[i] = i
		if i < n {
			ra[i] = int(s[i])
		} else {
			ra[i] = -1
		}
	}

	var k int
	comp := func(i, j int) bool {
		if ra[sa[i]] != ra[sa[j]] {
			return ra[sa[i]] < ra[sa[j]]
		}
		ri, rj := -1, -1
		if sa[i]+k <= n {
			ri = ra[sa[i]+k]
		}
		if sa[j]+k <= n {
			rj = ra[sa[j]+k]
		}
		return ri < rj
	}

	for k = 1; k <= n; k <<= 1 {
		sort.Slice(sa, comp)
		tmp[sa[0]] = 0
		for i := 1; i <= n; i++ {
			tmp[sa[i]] = tmp[sa[i-1]]
			if comp(i-1, i) {
				tmp[sa[i]]++
			}
		}

		ra, tmp = tmp, ra
	}

	return sa
}

func newLCPArray(s string, sa []int) []int {
	n := len(s)
	lcp := make([]int, n)
	ra := make([]int, n+1)
	for i := 0; i <= n; i++ {
		ra[sa[i]] = i
	}

	h := 0
	for i := 0; i < n; i++ {
		j := sa[ra[i]-1]
		if h > 0 {
			h--
		}
		for ; j+h < n && i+h < n; h++ {
			if s[j+h] != s[i+h] {
				break
			}
		}
		lcp[ra[i]-1] = h
	}

	return lcp
}


Measured memory_bytes: 19692
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
Vs = list(mapint())
Vs.sort()
val = Vs[0]
for v in Vs[1:]:
    val = (val+v)/2

print(val)

Measured memory_bytes: 61852
use std::io::{BufRead, Write};
use std::io;
use std::ops::{Add, Sub, Mul, Div};

const MOD: u64 = 1000000007;

#[derive(Clone, Copy, Debug)]
struct ModInt(u64);

impl ModInt {
    fn pow(self, exp: u64) -> ModInt {
        match exp {
            0 => ModInt(1),
            1 => self,
            x if x % 2 == 0 => ModInt(self.pow(x / 2).0.pow(2)),
            x => ModInt(self.pow(x / 2).0.pow(2)) * self,
        }
    }

    fn permutation(mut lhs: u64, rhs: u64) -> ModInt {
        let mut result = ModInt(1);
        for _ in 0..rhs {
            result = result * ModInt(lhs);
            lhs -= 1;
        }
        result
    }
}

impl From<u64> for ModInt {
    fn from(x: u64) -> Self {
        ModInt(x % MOD)
    }
}

impl Into<u64> for ModInt {
    fn into(self) -> u64 {
        self.0
    }
}

impl Add for ModInt {
    type Output = ModInt;

    fn add(self, rhs: Self) -> ModInt {
        let sum = self.0 + rhs.0;
        ModInt(if sum > MOD { sum - MOD } else { sum })
    }
}

impl Sub for ModInt {
    type Output = ModInt;

    fn sub(self, rhs: Self) -> ModInt {
        ModInt(if self.0 < rhs.0 {
            self.0 + MOD - rhs.0
        } else {
            self.0 - rhs.0
        })
    }
}

impl Mul for ModInt {
    type Output = ModInt;

    fn mul(self, rhs: Self) -> ModInt {
        ModInt(self.0 * rhs.0 % MOD)
    }
}

impl Div for ModInt {
    type Output = ModInt;

    fn div(self, rhs: Self) -> ModInt {
        self * rhs.pow(MOD - 2)
    }
}

fn solve<R: BufRead, W: Write>(mut input: R, mut output: W) {
    let mut s = String::new();
    input.read_line(&mut s).unwrap();
    let mut split = s.split_whitespace();
    let n: u64 = split.next().unwrap().parse().unwrap();
    let m: u64 = split.next().unwrap().parse().unwrap();
    let result: u64 = if n == m {
        ModInt::permutation(n, n) * ModInt::permutation(m, m) * 2.into()
    } else if n == m + 1 || n + 1 == m {
        ModInt::permutation(n, n) * ModInt::permutation(m, m)
    } else {
        0.into()
    }.into();
    writeln!(output, "{}", result).unwrap();
}

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();
    solve(stdin.lock(), stdout.lock());
}

#[cfg(test)]
mod tests {
    fn test(input: &str, output: &str) {
        let mut v: Vec<u8> = Vec::new();
        ::solve(input.as_bytes(), &mut v);
        assert_eq!(String::from_utf8(v).unwrap(), output);
    }
    #[test]
    fn case1() {
        test("2 2\n", "8\n");
    }
    #[test]
    fn case2() {
        test("3 2\n", "12\n");
    }
    #[test]
    fn case3() {
        test("1 8\n", "0\n");
    }
    #[test]
    fn case4() {
        test("100000 100000\n", "530123477\n");
    }
}


Measured memory_bytes: 4352
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define int long long
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
#endif
#define ff first
#define ss second
#define endl "\n"
#define all(c) c.begin(),c.end()
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" "; cout<<endl;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve(){
   cout<<fixed<<setprecision(8);
   int n;
   double ans=0;
   cin>>n;
   for(int i=0;i<n;i++){
	    double x;
	    string s;
	    cin>>x>>s;
	    if(s=="JPY")ans+=x;
	    else {
		  x*=380000.0;
		  ans+=x;	
		}
	}
    cout<<ans<<endl;
}
int32_t main(){
  IOS;
  solve();
  //debug();
 #ifdef LOCAL_DEFINE
 cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
 #endif	
}


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

void textIO()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

void fastIO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

}


int main()
{

    textIO();
    fastIO();

    long long n, cnt = 0;
    cin >> n;
    while(cnt < n){
        cnt+=1000;
    }

    cout << cnt-n << '\n';

    return 0;
}


Measured memory_bytes: 3652
n = int(input())

S = n * (n - 1) // 2
if n % 2 == 0:
    S -= 1
E = [[] for i in range(n+1)]

j = 1
for i in range(n // 2, 0, -1):
    E[i] = [k for k in range(1, n+1) if k != i and k != i + j]
    E[i + j] = E[i]
    j += 2

ans = []
for i, e in enumerate(E):
    for v in e:
        if i < v:
            ans.append((i, v))

print(len(ans))
for a in ans:
    print(*a)

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

int main(){
    int n,a=0,b=0;
    cin >> n;
    vector<int> data(n);
    for (int i = 0; i < n; i++){
        cin >> data.at(i);
    }
    sort(data.begin(), data.end());//小さい順に並べる
    reverse(data.begin(), data.end());//リバース   
    for (int i = 0; i < n; i++){
        if(n % 2 == 0){
            a += data.at(i);
            i++;
            b += data.at(i);
        }else{
            a += data.at(i);
            i++;
            if(i < n){
                b+= data.at(i);
            }
        }
    }
    cout << a-b << endl;
}

Measured memory_bytes: 3616
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    S=ST()
    for i in range(1<<3):
        now = int(S[0])
        ans = S[0]
        for j in range(3):
            if(i>>j&1):
                now -= int(S[j+1])
                ans+="-"
            else:
                now += int(S[j+1])
                ans+="+"
            ans += S[j+1] 
        if(now==7):
            print(ans+"=7")
            return
if __name__ == '__main__':
    main()

Measured memory_bytes: 66540
def solve():
    [N, X] = [int(x) for x in input().split()]
    a = [int(x) for x in input().split()]

    ans = 0
    for i in range(1, N):
        d = a[i] + a[i-1] - X
        if d > 0:  # need to eat
            a[i] -= d
            ans += d
            if a[i] < 0:
                a[i-1] += a[i]
                a[i] = 0
    return ans


def main():
    print(solve())


if __name__ == '__main__':
    main()





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

int main() {
    ll n,k;
    cin>>n>>k;
    ll ans=0;
    rep(i,n+2) {
        if(i<k)continue;
        if(i==n+1) {
            ans++;
        }else if(i==n) {
            ans = (ans+n+1)%mod;
        }else{
            ans=(ans+(n-i+1)*i+1)%mod;
        }
    }
    cout << ans%mod <<endl;
}

Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.regex.Pattern;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Deque<Process> ad = new ArrayDeque<Process>();
        int[] n = createListInt(br.readLine());
        int totalTime = 0;
        for (int i = 0; i < n[0]; i++) {
            String[] lines = br.readLine().split(" ");
            ad.add(new Process(lines[0], ip(lines[1])));
        }
        int m = n[1];
        while (!ad.isEmpty()) {
            Process t = ad.poll();
            if (m < t.time) {
                ad.add(new Process(t.name, t.time - m));
                totalTime+=m;
            } else {
                totalTime+=t.time;
                System.out.println(t.name+" "+totalTime);
            }
        }

    }

    static boolean isNumber(String num) {
        return Pattern.compile("^\\-?[0-9]*\\.?[0-9]+$").matcher(num).find();
    }

    static int[] createListInt(String line) {
        String[] lines = line.split(" ");
        int n = lines.length;
        int[] list = new int[n];
        while (n-- > 0) {
            list[n] = Integer.parseInt(lines[n]);
        }
        return list;
    }

    static long[] createListLong(String line) {
        String[] lines = line.split(" ");
        int n = lines.length;
        long[] list = new long[n];
        while (n-- > 0) {
            list[n] = Long.parseLong(lines[n]);
        }
        return list;
    }

    static int ip(String s) {
        return Integer.parseInt(s);
    }

    static long lp(String s) {
        return Long.parseLong(s);
    }
}

class Process {
    String name;
    int time;

    Process(String name, int time) {
        this.name = name;
        this.time = time;
    }
}

Measured memory_bytes: 64540
from sys import stdin
from itertools import repeat
from collections import deque
def main():
    n, m = map(int, stdin.readline().split())
    dat = map(int, stdin.read().split(), repeat(10, 2 * m))
    deg = [0] * n
    la = [None] * n
    xt = [0] * (2 * m)
    for i in xrange(m):
        ui = i * 2
        vi = i * 2 + 1
        dat[ui] -= 1
        dat[vi] -= 1
        u = dat[ui]
        v = dat[vi]
        deg[u] += 1
        deg[v] += 1
        xt[vi] = la[u]
        la[u] = vi
        xt[ui] = la[v]
        la[v] = ui
    so = tr = lo = 0
    q = deque()
    done = [0] * n
    pu = q.append
    po = q.popleft
    for i in xrange(n):
        if done[i]:
            continue
        pu(i)
        done[i] = 1
        nu = [i]
        while q:
            x = po()
            y = la[x]
            while y is not None:
                z = dat[y]
                if not done[z]:
                    done[z] = 3 - done[x]
                    pu(z)
                    nu.append(z)
                y = xt[y]
        sd = 0
        pa = 0
        for x in nu:
            sd += deg[x]
            y = la[x]
            while y is not None:
                z = dat[y]
                if done[x] == done[z]:
                    pa = 1
                y = xt[y]
        if sd == 0:
            so += 1
        elif pa:
            lo += 1
        else:
            tr += 1
    print lo * lo + lo * tr * 2 + tr * tr * 2 + so * n * 2 - so * so
main()


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

namespace ConsoleApplication8
{
    class Program
    {
        static void Main(string[] args)
        {
            
            while (true)
            {
                string[] str = Console.ReadLine().Split(' ');
                int n = int.Parse(str[0]);
                int x = int.Parse(str[1]);

                if ((n == 0) && (x == 0))
                {
                    break;
                }

                int[] Array = new int[n];               //n?????§?????°???????????????????´?
                for (int i = 0; i < n; ++i)
                {
                    Array[i] = i + 1;
                }

                int count = 0;
                for (int i = 0; i < n; ++i)
                {
                    for (int j = (i + 1); j < n; ++j)
                    {
                        for (int k = (j + 1); k < n; ++k)
                        {
                            
                            if ((Array[i] + Array[j] + Array[k]) == x)
                            {
                                ++count;
                            }
                        }
                    }
                }
                Console.WriteLine(count);
            }
        }
    }
}

Measured memory_bytes: 19932
function main()
N,x=map(x->parse(Int,x),split(readline()))
ans=10^18
A=map(x->parse(Int,x),split(readline()))
for j=0:N
  now=j*x
  p=A[1]
  for i=1:N
    now+=A[i]
    if i<N&&A[i]>A[i+1]
      A[i]=A[i+1]
    end
  end
  ans=min(ans,now)
  A[N]=min(A[N],p)
end
println(ans)
end
main()

Measured memory_bytes: 155292
#include <iostream>

using namespace std;

int main()
{
  uint u;
  cin >> u;
  for (auto i = 1; i <= u; i++) {
    uint x = i;
    if (x % 3 == 0) {
      cout << " " << i;
    } else {
      while (x != 0) {
	if (x % 10 == 3) {
	  cout << " " << i;
	  break;
	}
	x /= 10;
      }
    }
  }
  cout << endl;
}



Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main()
{
    int n;
    cin >> n;
    int cnt = 0;
    bool ok = false;
    if(n==1){
        cout << "Yes" << endl;
        cout << 2 << endl;
        cout << 1 << " " << 1 << endl;
        cout << 1 << " " << 1 << endl;
        return 0;
    }
    for (int i = 0; i < n; i++)
    {
        if(n==i*(i+1)/2){
            ok = true;
            cnt = i;
            break;
        }
    }
    if(ok){
        vector<vector<int>> v(cnt + 2,vector<int>());
        int c = 1;
        for (int i = 1; i <= cnt; i++)
        {
            for (int j = 1; j <= i; j++)
            {
                v[j].push_back(c);
                c++;
            }
        }
        c = 1;
        for (int i = 2; i <= cnt + 1; i++)
        {
            for (int j = 1; j < i; j++)
            {
                v[i].push_back(c);
                c++;
            }
        }
        cout << "Yes" << endl;
        cout << cnt + 1 << endl;
        for (int i = 1; i <= cnt+1; i++)
        {
            cout << cnt << " ";
           // sort(ALL(v[i]));
            for (int j = 0; j < cnt; j++)
            {
                cout << v[i][j] << " ";
            }
            cout << endl;
        }
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}



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

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n; cin >> n;
  vector<int> dist(n, 9 * 5);
  dist[1] = 1;
  auto comp = [&](int a, int b) { return dist[a] > dist[b]; };
  priority_queue<int, vector<int>, decltype(comp)> pq(comp);
  pq.push(1);
  while(pq.size()) {
    int i = pq.top();
    pq.pop();
    if(dist[(i + 1) % n] > dist[i] + 1) {
      dist[(i + 1) % n] = dist[i] + 1;
      pq.push((i + 1) % n);
    }
    if(dist[i * 10 % n] > dist[i]) {
      dist[i * 10 % n] = dist[i];
      pq.push(i * 10 % n);
    }
  }
  cout << dist[0];
}


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

int main(){
    int n;
    cin >> n;
    vector <ll> a(n+1);
    rep(i,n){
        cin >> a[n-i-1];
    }
    a[n]=0;

    ll ans=0;
    int k=0;
    rep(i,n){
        if(a[i]-a[i+1]==1){
            if(k==0){
                ans+=a[i];
                k=1;
            }
        }
        else if(a[i]==a[i+1]){
            if(k!=1){
            ans+=a[i];
            }
            k=0;
        }
        else if(a[i]<a[i+1]){
            if(k!=1){
            ans+=a[i];
            }
            k=0;
        }
        else{
            cout << -1 << endl;
            return 0;
        }

        //cout << i << " " << a[i] << " "<< ans << endl;
    }

    if(a[n-1]!=0){
        ans=-1;
    }

    cout << ans << endl;


    

    return 0;
}

Measured memory_bytes: 4848
import sys
def solve(l,v1,v2):
    dist=sum(l)/(v1+v2)*v1
    for i in range(11):
        if sum(l[:i])>=dist:
            return i
    return 0
for line in sys.stdin.readlines():
    line=map(float,line.strip().split(","))
    l,v1,v2=line[:10],line[10],line[11]
    print solve(l,v1,v2)

Measured memory_bytes: 4236
# TLE
"""
N = int(input())
A = list(map(int, input().split()))

buka = [str(A.count(i)) for i in range(1, N+1, 1)] # countメソッドのためTLE

print("\n".join(buka))
"""
"""
# sys（入力メイン）-----------------------------------------
import sys
read = sys.stdin.buffer.read # 全読み込み
readline = sys.stdin.buffer.readline # 一行読み込み
readlines = sys.stdin.bufer.readlines # 一行ずつ全読み込み
sys.setrecursionlimit(10**7) # 再帰限界変更（デフォルトは1000）

# 文字列（数値変換も含む）
n = readline().rstrip() # １行に１文字列のみ
lis = readline().rstrip().split() # # １行に複数の文字列

# 数値（文字変換も含む）
n = int(readline().rstrip()) # １行に数値１個のみ
a, b, c = int(readline().rstrip().split()) # １行に複数の数値
lis = [readline().rstrip().split() for _ in range(n)] # １行に複数の数値(m個)かつ、n行続く場合（出力は二次元リスト：[['1', '2'], ['4', '5']]）

-----------------------------------------
"""

import sys
read = sys.stdin.buffer.read # 全読み込み
readline = sys.stdin.buffer.readline # 一行読み込み
readlines = sys.stdin.buffer.readlines # 一行ずつ全読み込み
sys.setrecursionlimit(10**7) # 再帰限界変更（デフォルトは1000）

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

buka=[0]*N

for i in range(N-1):
    buka[A[i]-1]+=1

L=[str(a) for a in buka]
L="\n".join(L)
print(L)

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

char str[20];
int ans = 1234567890;

int main(){
    scanf("%s", str);
    for (int i=2; str[i]; i++) ans = min(ans, abs((str[i-2]-'0')*100 + (str[i-1]-'0')*10 + (str[i]-'0') - 753));
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
def main():
    h, w, k = map(int, input().split())
    s = [[int(i) for i in list(input())] for _ in range(h)]
    cnt = [bin(i).count("1") for i in range(2**(h - 1))]
    c = 0
    for ci in [sum(i) for i in zip(*s)]:
        if ci > k:
            cnt[0] = 100000
            break
        c += ci
        if c > k:
            cnt[0] += 1
            c = ci
    minc = cnt[0]
    for i in range(1, 2**(h - 1)):
        div = [j + 1 for j in range(h) if i & 2**j]
        ss = []
        l = 0
        for d in div:
            ss.append(s[l:d])
            l = d
        ss.append(s[l:])
        c = [0] * len(ss)
        t = [[sum(i) for i in zip(*si)] for si in ss]
        for j in range(w):
            if cnt[i] >= minc:
                break
            if max(ti[j] for ti in t) > k:
                cnt[i] = 100000
                break
            for tt, ti in enumerate(t):
                c[tt] += ti[j]
            if max(c) > k:
                cnt[i] += 1
                c = [ti[j] for ti in t]
    print(min(cnt))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};


signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    int N,K; cin >> N >> K;
    VI A(N);
    REP(i,N) cin >> A[i];
    REP(i,K){
        VI imos(N+1);
        REP(j,N){
            int left = max(0,j-A[j]);
            int right = min(N,j+A[j]+1);
            imos[left]++;
            imos[right]--;
        }
        A[0] = imos[0];
        REP(j,N-1){
            A[j+1] = A[j] + imos[j+1];
        }
        bool ok = true;
        REP(j,N){
            if(A[j] != N) ok = false;
        }
        if(ok) break;
    }
    REP(i,N){
        cout << A[i] << " ";
    }
    cout << endl;

}

Measured memory_bytes: 4920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 2001;
ll dfs(ll now,ll par,ll k,vector<vector<ll>> &g){
  if(k==0)return 1;
  else {
    ll a=1;
    rep(i,g[now].size()){
      if(g[now][i]==par)continue;
      a+=dfs(g[now][i],now,k-1,g);
    }
    return a;
  }
}

int main()
{
ll n,k;
cin >> n >> k;
if(k==1){
cout << n-2 << endl;
return 0;
}
vector<vector<ll>> g(n);
rep(i, n-1)
{
    ll a,b;
    cin >> a>>b;
    g[a-1].push_back(b-1);
    g[b-1].push_back(a-1); //無向辺
}

if(k%2){
  rep(i,n)rep(j,g[i].size()){
    ans=min(ans,n-dfs(i,g[i][j],k/2,g)-dfs(g[i][j],i,k/2,g));
  }
}
else{
  rep(i,n){
    ans=min(ans,n-dfs(i,-1,k/2,g));
  }
}

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

Measured memory_bytes: 384
<?php

fscanf(STDIN,"%d",$n);

$a = strlen($n);
$array = str_split($n);
$count = 0;

for ($i = 1; $i <= $a +1; $i++){
    $count += $array[$i-1];
}

if ($n % $count == 0){
    echo "Yes";
}else{
    echo "No";
}


Measured memory_bytes: 4728
import java.util.Scanner;  

public class Main { 

private static Scanner sc;
public static void main(String[] args) {
    Scanner(0);
} 
public static void Scanner(int sum){ 
    sc = new Scanner(System.in); 
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c;
    c = (a-1) * (b-1);
    System.out.println(c); 
    } 
}

Measured memory_bytes: 23124
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <deque>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)

int main(){
   int n;
   cin >> n;
   vector<int> v(n);
   rep(i,n){
       cin >> v[i];
   }
   int ans=0;
   rep(i,n){
       while(v[i]%2 == 0){
           ans++;
           v[i] /= 2;
        }
   }
   cout << ans << endl;
    
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x%mod;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	if (x == y)return 1;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}

struct edge { int from, to, cost; };

int n, m, p, a[5000], b[5000], c[5000];
edge ta[5000];
int d[2510];
int e;

int BF() {
	fill(d, d + n, INF);
	d[0] = 0;
	int cnt = 0;
	while (1) {
		bool bl = false;
		for (int i = 0; i < m; i++) {
			edge x = ta[i];
			if (d[x.to] > d[x.from] + x.cost) {
				d[x.to] = d[x.from] + x.cost;
				bl = true;
			}
		}
		if (!bl)break;
		cnt++;
		if (cnt == n - 1)e = d[n - 1];
		if (cnt == 2 * n - 1 && d[n - 1] != e)return INF;
		else if (cnt == 2 * n - 1)return d[n - 1];
	}
	return d[n - 1];
}

signed main() {
	cin >> n >> m >> p;
	for (int i = 0; i < m; i++) {
		cin >> a[i] >> b[i] >> c[i];
		a[i]--;
		b[i]--;
		ta[i] = { a[i],b[i],(c[i] - p) * -1 };
	}
	int c = BF();
	if (c == INF)cout << -1 << endl;
	else cout << max((int)0, c*-1) << endl;
}

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

int main(void){
    int n,num[50][26] = {};
    cin >> n;
    
    for(int i = 0;i < n;i++){
        string s;
        cin >> s;
        for(int j = 0;j < s.size();j++){
            int a = s[j]-'a';
            num[i][a]++;
        }
    }
    
    for(int i = 0;i < 26;i++){
        int sum = num[0][i];
        for(int j = 1;j < n;j++)sum = min(sum,num[j][i]);
        for(int j = 0;j < sum;j++)cout << (char)('a'+i);
    }
    cout << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<stdio.h>
#include<algorithm>
using namespace std;
int par[200005],cnt[200005]={0};
int find(int x){
	if(x==par[x])
		return x;
	return par[x]=find(par[x]);
}
void unite(int x,int y){
	x=find(x);
	y=find(y);
	par[x]=y;
}
int main(){
	int i,n,m,a,b;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)
		par[i]=i;
	for(i=0;i<m;i++){
		scanf("%d%d",&a,&b);
		unite(a,b);
	}
	int ans=0;
	for(i=1;i<=n;i++){
		cnt[find(i)]++;
		ans=max(ans,cnt[find(i)]);
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 8752
#include<stdio.h>

int main()
{
	char s[4];

	scanf("%s",s);
	
	int cnt=0;
	for(int a=0;a<4;a++)
	{
		if(s[a]=='+')cnt++;
		else cnt=cnt-1;
	}
	
	printf("%d\n",cnt);


	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;

int N, K, ans;
int a[100000];
int d[100000];
vector<int> child[100000];

int f(int n) {
	if(d[n] != -1) return d[n];
	return d[n] = f(a[n]) + 1;
}

int f2(int n, int depth) {
	int md = d[n];
	for(int c : child[n]) {
		int dd = f2(c, depth + 1);
		if(dd - depth + 1 > K) {
			ans++;
		}
		else {
			md = max(md, dd);
		}
	}
	return md;
}

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

	cin >> N >> K;
	for(int i = 0; i < N; i++) {
		cin >> a[i];
		a[i]--;
		if(i != 0) {
			child[a[i]].push_back(i);
		}
	}

	memset(d, -1, sizeof d);
	d[0] = 0;
	for(int i = 0; i < N; i++) {
		f(i);
	}
	d[0] = f(a[0]) + 1;

	bool ok = true;
	for(int i = 0; i < N; i++) {
		if(a[0] == 0 && d[i] <= K || d[i] == K) continue;
		ok = false;
		break;
	}
	if(ok) {
		cout << 0 << endl;
		return 0;
	}

	ans += a[0] != 0;
	a[0] = 0;
	for(int c : child[0]) {
		f2(c, 1);
	}
	cout << ans << endl;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BS binary_search
#define all(c) (c).begin(),(c).end()
#define sz(x) (int)(x).size()
#define get(a,t) get<a>(t)
#define EPS 0.000000001 //1e-9
using pii=pair<int,int>;
const int INF=1e18;
const int N=100005;
void solve()
{
    string s,t;
    cin>>s>>t;
    int temp=0;
    for(char a='a';a<='z';a++)
    {
        string c=s+a;
        if(c.compare(t)==0)
        {
            temp=1;
            break;
        }
    }
    if(temp==1)
    cout<<"Yes"<<endl;
    else
    {
        cout<<"No\n";
    }
    
}
int32_t main()
{
    IOS;
    //int t; cin>>t;
    int t=1;
    for(int tc=1;tc<=t;tc++)
    {
        //cout<<"Case #"<<tc<<": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
 
using namespace std;
 
void fail() {
  cout << -1 << endl;
  exit(0);
}
 
int main() {
  int N;
  cin >> N;
  string A[500], C[500];
  uint64_t B[500], D[500];
  int H = N, W = N;
  for(int i = 0; i < N; i++) {
    int x;
    cin >> x;
    if(x == 0) A[i] = "and";
    else A[i] = "or";
  }
 
  for(int i = 0; i < N; i++) {
    int x;
    cin >> x;
    if(x == 0) C[i] = "and";
    else C[i] = "or";
  }
  for(int i = 0; i < N; i++) {
    cin >> B[i];
  }
  for(int i = 0; i < N; i++) {
    cin >> D[i];
  }
 
  uint64_t ans[500][500] = {{}};
  for(int i = 0; i < 64; i++) {
    vector< vector< int > > decide(H, vector< int >(W, -1));
    vector< pair< int, int > > latte, malta;
 
    for(int j = 0; j < H; j++) {
      if(A[j] == "and") {
        if((B[j] >> i) & 1) for(int k = 0; k < W; k++) decide[j][k] = 1;
        else latte.emplace_back(j, 0);
      } else {
        if((~B[j] >> i) & 1) for(int k = 0; k < W; k++) decide[j][k] = 0;
        else latte.emplace_back(j, 1);
      }
    }
    for(int j = 0; j < W; j++) {
      if(C[j] == "and") {
        if((D[j] >> i) & 1) {
          for(int k = 0; k < H; k++) if(decide[k][j] == 0) fail();
          for(int k = 0; k < H; k++) decide[k][j] = 1;
        } else malta.emplace_back(j, 0);
      } else {
        if((~D[j] >> i) & 1) {
          for(int k = 0; k < H; k++) if(decide[k][j] == 1) fail();
          for(int k = 0; k < H; k++) decide[k][j] = 0;
        } else malta.emplace_back(j, 1);
      }
    }
 
    if(min(latte.size(), malta.size()) >= 2) {
      for(int j = 0; j < latte.size(); j++) {
        for(int k = 0; k < malta.size(); k++) {
          decide[latte[j].first][malta[k].first] = (j + k) & 1;
        }
      }
    } else if(latte.size() == 1) {
      for(auto &p : malta) {
        bool ex = false;
        for(int j = 0; j < H; j++) ex |= decide[j][p.first] == p.second;
        decide[latte[0].first][p.first] = ex ? latte[0].second : p.second;
      }
      bool f = false;
      for(int k = 0; k < W; k++) f |= decide[latte[0].first][k] == latte[0].second;
      if(!f) fail();
    } else if(malta.size() == 1) {
      for(auto &p : latte) {
        bool ex = false;
        for(int k = 0; k < W; k++) ex |= decide[p.first][k] == p.second;
        decide[p.first][malta[0].first] = ex ? malta[0].second : p.second;
      }
      bool f = false;
      for(int j = 0; j < H; j++) f |= decide[j][malta[0].first] == malta[0].second;
      if(!f) fail();
    } else {
      for(auto &p : latte) {
        bool f = false;
        for(int k = 0; k < W; k++) f |= decide[p.first][k] == p.second;
        if(!f) fail();
      }
      for(auto &p : malta) {
        bool f = false;
        for(int j = 0; j < H; j++) f |= decide[j][p.first] == p.second;
        if(!f) fail();
      }
    }
    for(int j = 0; j < H; j++) {
      for(int k = 0; k < W; k++) {
        ans[j][k] |= ((uint64_t) (decide[j][k] & 1)) << i;
      }
    }
  }
 
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) cout << ans[i][j] << " ";
    cout << endl;
  }
}


Measured memory_bytes: 8492
import itertools

A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

P = list(itertools.permutations([A, B, C,D,E]))
time = 0
mini = 10**3
for i in P:
    count = 0
    for j in i:
        time += j
        if (count ==4):
            break
        if j % 10 != 0:
            time += 10 - (time % 10)
        count += 1
    mini = min(mini, time)
    time = 0

print(mini)

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N;
  cin>>N;
  lint A[N];
  REP(i,N)cin>>A[i];
  lint S=0,T=0,U=0;
  REP(i,N/2){
    lint S1,T1,U1;
    S1=S+A[2*i+1];
    S1=max(S1,T+A[2*i+1]);
    T1=T+A[2*i];
    U1=U+A[2*i];
    U1=max(U1,S);
    U1=max(U1,T);
    S=S1;T=T1;U=U1;
  }
  if(N%2==1){
    U+=A[N-1];
    cout<<max(S,max(T,U))<<endl;
  }else{
    cout<<max(S,T)<<endl;
  }
  return 0;
}


Measured memory_bytes: 5208