akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python

N = int(input())

FIELD_SIZE = 101

x = []
y = []
h = []
for n in range(N):
    inputs = input().split()
    x.append(int(inputs[0]))
    y.append(int(inputs[1]))
    h.append(int(inputs[2]))

H = [[0] * FIELD_SIZE for n in range(FIELD_SIZE)]
determined_flag = False

for n in range(N):
    for cx in range(FIELD_SIZE):
        for cy in range(FIELD_SIZE):

            ch = h[n] + abs(x[n] - cx) + abs(y[n] - cy)
            if n == 0:
                H[cx][cy] = ch

            elif determined_flag:
                if h[n] != 0:
                    if ch == H[cx][cy]:
                        pass
                    else:
                        H[cx][cy] = 0
                else:
                    if ch >= H[cx][cy]:
                        pass
                    else:
                        H[cx][cy] = 0

            else:
                if h[n] != 0:
                    if ch <= H[cx][cy]:
                        H[cx][cy] = ch
                    else:
                        H[cx][cy] = 0
                else:
                    H[cx][cy] = min(H[cx][cy], ch)
    if h[n] != 0:
        determined_flag = True


for cx in range(FIELD_SIZE):
    for cy in range(FIELD_SIZE):
        if H[cx][cy] >= 1:
            print(cx, cy, H[cx][cy])


Measured memory_bytes: 3444
#include <cmath>
#include <iomanip>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int A, B, H, M;
  cin >> A >> B >> H >> M;
  // 360 = 2 * M_PI
  double hour = (double)(H * 60 + M) / 720.0 * 2 * M_PI;
  double minu = (double)M / 60.0 * 2 * M_PI;

  // anti-clockwise
  // x2 = x1 cos - y1 sin
  // y2 = x1 sin + y1 cos
  // clockwise
  // x2 = x1 cos + y1 sin
  // y2 = -x1 sin + y1 cos
  double hx = A * sin(hour);
  double hy = A * cos(hour);
  double mx = B * sin(minu);
  double my = B * cos(minu);

  double answer = sqrt((hx - mx) * (hx - mx) + (hy - my) * (hy - my));
  cout << setprecision(20) << answer << endl;
  return 0;
}


Measured memory_bytes: 4112
N = int(input())
s = [0]*N
for i in range(N):
    s[i] = int(input())

if sum(s) % 10 != 0:
    print(sum(s))
else:
    ans = 0
    tmp = sum(s)
    for i in range(N):
        if (tmp - s[i]) % 10 != 0:
            ans = max(ans,tmp - s[i])
    print(ans)

Measured memory_bytes: 38384
while True:
    N, K = map(int, input().split())
    if N == 0:
        break
    S = [0] + list(map(int, input().split()))
    flag = True
    for _ in range(N):
        B = list(map(int, input().split()))
        for i, b in enumerate(B):
            S[i+1] -= b
            if S[i+1] < 0:
                flag = False
                break
    print("Yes" if flag else "No")

Measured memory_bytes: 7552
def examA():
    A, B = LI()
    if B%A==0:
        ans = A+B
    else:
        ans = B-A
    print(ans)
    return

def examB():
    N, M = LI()
    Flag = [0]*M
    for i in range(N):
        K = LI()
        for j in range(1,K[0]+1):
            Flag[K[j]-1] +=1
    ans = 0
    for i in Flag:
        if i==N:
            ans +=1
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examB()


Measured memory_bytes: 3444
#include <cstdio>
#include <cctype>
#include <cstring>

//User's Lib

#include <array>
#include <queue>
#include <algorithm>

using namespace std;

char buf[11111111], *pc = buf;

struct Main_Guard{
	Main_Guard(){
		fread(buf, 1, 11111111, stdin);
	}
	Main_Guard(const char *ins){
		freopen(ins, "r", stdin);
		fread(buf, 1, 11111111, stdin);
	}
	Main_Guard(const char *ins, const char *ous){
		freopen(ins, "r", stdin);
		freopen(ous, "w", stdout);
		fread(buf, 1, 11111111, stdin);
	}
	~ Main_Guard(){
		fclose(stdin), fclose(stdout);
	}
};

static inline int read(){
    int num = 0;
    char c, sf = 1;
    while(isspace(c = *pc++));
    if(c == 45) sf = -1, c = *pc ++;
    while(num = num * 10 + c - 48, isdigit(c = *pc++));
    return num * sf;
}

namespace LKF{
    template <typename T>
    extern inline T abs(T tar){
        return tar < 0 ? -tar : tar;
    }
    template <typename T>
    extern inline void swap(T &a, T &b){
        T t = a;
        a = b;
        b = t;
    }
    template <typename T>
    extern inline void upmax(T &x, const T &y){
        if(x < y) x = y;
    }
    template <typename T>
    extern inline void upmin(T &x, const T &y){
        if(x > y) x = y;
    }
    template <typename T>
    extern inline T max(T a, T b){
        return a > b ? a : b;
    }
    template <typename T>
    extern inline T min(T a, T b){
        return a < b ? a : b;
    }
}

//Source Code

const int MAXN = 101010;

int x, y, z, n;

struct Data{
    int a, b, c;
    Data(){}
    Data(const int &_a, const int &_b, const int &_c) : a(_a), b(_b), c(_c) {}
    inline bool operator < (const Data &tar) const {
        return a - b > tar.a - tar.b;
    }
}num[MAXN];

template<typename _Tp, typename _Sequence = vector<_Tp>,
        typename _Compare  = less<typename _Sequence::value_type> >
inline void clear(priority_queue<_Tp, _Sequence, _Compare> &tar){
    priority_queue<_Tp, _Sequence, _Compare> tmp;
    swap(tmp, tar);
}

long long dp[MAXN];

int main(){
    Main_Guard main_guard;
    n = (x = read()) + (y = read()) + (z = read());
    long long sumc = 0, sum = 0, ans = 0;
    for(int i = 1; i <= n; i++){
        num[i].a = read(), num[i].b = read(), num[i].c = read();
        sumc += num[i].c;
    }
    sort(num + 1, num + 1 + n);
    priority_queue<int, vector<int>, greater<int> > pq;
    for(int i = 1; i <= x; i++){
        sum += num[i].a - num[i].c;
        pq.push(num[i].a - num[i].c);
    }
    for(int i = x + 1; i <= n - y + 1; i++){
        dp[i] = sum;
        sum += num[i].a - num[i].c;
        pq.push(num[i].a - num[i].c);
        sum -= pq.top();
        pq.pop();
    }
    clear(pq);
    sum = 0;
    for(int i = n; i >= n - y + 1; i--){
        sum += num[i].b - num[i].c;
        pq.push(num[i].b - num[i].c);
    }
    for(int i = n - y; i >= x; i--){
        LKF::upmax(ans, sumc + dp[i + 1] + sum);
        sum += num[i].b - num[i].c;
        pq.push(num[i].b - num[i].c);
        sum -= pq.top();
        pq.pop();
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 6396
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    string s;
    cin>>s;
    int sum=700;
    for(int i=0; i<3; i++)
        if(s[i]=='o')
            sum+=100;
    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 3544
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int[] m=new int[4];
		m[0]=sc.nextInt();
		m[1]=sc.nextInt();
		m[2]=sc.nextInt();
		int work,a;
		for(int j=1;j<=2;j++){
			for(int i=j;i>0;i--){
				if(m[i-1]<m[i]){
					m[3]=m[i-1];
					m[i-1]=m[i];
					m[i]=m[3];
				}
			}
		}
		a=3;
		while(a<10){
			int i=2;
			work=sc.nextInt();
			a++;
			while(((i>=0) && work>m[i])){
					m[i+1]=m[i];
					i--;
			}
			if(i!=2){
				m[i+1]=work;
			}
		}
		
			System.out.println(m[0]+"\n"+m[1] + "\n"+m[2]);
		

	}

}

Measured memory_bytes: 17172
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
using ll = long long;
using ull = unsigned long long;
constexpr int MOD = 1000000007;

int mod(ll x){
    return x > 0 ? x % MOD : (x+MOD) % MOD;
}

int modm(ll x,ll m){
    return x * m % MOD;
}

int modpow(ll x, ll p) {
    int ret = 1;
    while(p > 0) {
        if (p & 1) ret = modm(ret,x);
        x = modm(x,x);
        p >>= 1;
    }
    return ret;
}

// x * modinv(d)
int modd(ll x,ll d) {
    return modm(x,modpow(d,MOD-2));
}

int main(void)
{
    IOS
    int n;
    cin >> n;
    n++;
    vector<int> p;
    int el[1010];
    memset(el,0,sizeof el);
    FOR(i,2,n) {
        if (el[i] == 1) continue;
        p.emplace_back(i);
        int j = 2;
        while(i * j < n) {
            el[i*j] = 1;
            j++;
        }
    }
    vector<int> v(p.size(),0);

    FOR(i,2,n) {
        int x = i;
        //cerr << x << endl;
        int pi = 0;
        while(x != 1) {
            if (x % p[pi] == 0) {
                x /= p[pi];
                v[pi]++;
            } else {
                pi++;
            }
        }
    } 

    int ans = 1;
    REP(i,v.size()) {
        ans = modm(ans,v[i]+1);
        //cerr << ans << endl;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define int unsigned long long int
signed main(){
    //int t;cin>>t;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;cin>>n;
    int a[n];for(int i=0;i<n;i++)cin>>a[i];
    int mx=a[0],ans=0;
    for(int i=1;i<n;i++){
        if(a[i]<mx)ans+=mx-a[i];
        mx=max(mx,a[i]);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 5208
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
static const int SIZE = 100;
static const int NIL = -1;

struct Node
{
	int parent;
	int left;
	int right;
};

vector<Node> T(SIZE);
int n;
vector<int> D(SIZE);
vector<int> H(SIZE);

void setDepth(int u, int d)
{
	if (u == NIL)
	{
		return;
	}
	D[u] = d;
	setDepth(T[u].left, d + 1);
	setDepth(T[u].right, d + 1);
}

int setHeight(int u)
{
	int h1 = 0;
	int h2 = 0;
	if (T[u].left != NIL)
	{
		h1 = setHeight(T[u].left) + 1;
	}
	if (T[u].right != NIL)
	{
		h2 = setHeight(T[u].right) + 1;
	}
	return(H[u] = max(h1, h2));
}

int getSibling(int u)
{
	if (T[u].parent == NIL)
	{
		return(NIL);
	}
	if (T[T[u].parent].left != u && T[T[u].parent].left != NIL)
	{
		return(T[T[u].parent].left);
	}
	if (T[T[u].parent].right != u && T[T[u].parent].right != NIL)
	{
		return(T[T[u].parent].right);
	}
	return(NIL);
}

void print(int u)
{
	cout << "node " << u << ": ";
	cout << "parent = " << T[u].parent << ", ";
	cout << "sibling = " << getSibling(u) << ", ";
	int deg = 0;
	if (T[u].left != NIL)
	{
		++deg;
	}
	if (T[u].right != NIL)
	{
		++deg;
	}
	cout << "degree = " << deg << ", ";
	cout << "depth = " << D[u] << ", ";
	cout << "height = " << H[u] << ", ";

	if (T[u].parent == NIL)
	{
		cout << "root\n";
	}
	else if (T[u].left == NIL && T[u].right == NIL)
	{
		cout << "leaf\n";
	}
	else
	{
		cout << "internal node\n";
	}
}

void solve()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		T[i].parent = NIL;
	}
	for (int i = 0; i < n; ++i)
	{
		int id, l, r;
		cin >> id >> l >> r;
		T[id].left = l;
		T[id].right = r;
		if (l != NIL)
		{
			T[l].parent = id;
		}
		if (r != NIL)
		{
			T[r].parent = id;
		}
	}
	int root;
	for (int i = 0; i < n; ++i)
	{
		if (T[i].parent == NIL)
		{
			root = i;
		}
	}

	setDepth(root, 0);
	setHeight(root);
	for (int i = 0; i < n; ++i)
	{
		print(i);
	}
}

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

Measured memory_bytes: 1204
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	int N;
	Node[] nodes;
	Edge[] edges;
	int result = 0;

	static class Edge {
		int id, src, dst, color;

		Edge(int id, int src, int dst) {
			this.id = id;
			this.src = src;
			this.dst = dst;
			this.color = -1;
		}
	}

	static class Node {
		int id;
		List<Edge> edges;

		Node(int id) {
			this.id = id;
			this.edges = new ArrayList<>();
		}

	}

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		N = Integer.parseInt(in.readLine());
		this.nodes = new Node[N];
		for (int i = 0; i < N; ++i) {
			nodes[i] = new Node(i);
		}
		this.edges = new Edge[N - 1];
		for (int i = 0; i < N - 1; ++i) {
			String[] tokens = in.readLine().split(" ");
			int a = Integer.parseInt(tokens[0]) - 1;
			int b = Integer.parseInt(tokens[1]) - 1;
			this.edges[i] = new Edge(i, a, b);
			this.nodes[a].edges.add(this.edges[i]);
			this.nodes[b].edges.add(this.edges[i]);
		}
	}

	void calc() {
		colorize(nodes[0], null);
		// 最大の色を探す
		for (Edge edge : this.edges) {
			result = Math.max(result, edge.color);
		}
	}

	void colorize(Node node, Edge parent) {
		if (parent == null) {
			// 自由に塗る
			int color = 1;
			for (int i = 0; i < node.edges.size(); ++i) {
				Edge edge = node.edges.get(i);
				edge.color = color;
				++color;
			}
		} else {
			// parentと異なるcolor以外で塗る
			int color = 1;
			for (int i = 0; i < node.edges.size(); ++i) {
				Edge edge = node.edges.get(i);
				if (edge.equals(parent)) {
					continue;
				}
				if (color == parent.color) {
					++color;
				}
				edge.color = color;
				++color;
			}
		}
		// parent以外のedgeの先のnodeに対して，同様に彩色する
		for (Edge edge : node.edges) {
			if (edge.equals(parent)) {
				continue;
			}
			Node next = edge.src == node.id ? this.nodes[edge.dst] : this.nodes[edge.src];
			colorize(next, edge);
		}
	}

	void showResult() {
		System.out.println(result);
		for (int i = 0; i < edges.length; ++i) {
			System.out.println(this.edges[i].color);
		}
	}
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

std::string S;

bool ok(){
    int n = S.size();

    for(int i=0;i<n;++i){
        if(i % 2 == 0 && S[i] == 'L'){
            return false;
        }

        if(i % 2 == 1 && S[i] == 'R'){
            return false;
        }
    }

    return true;
}

int main(){
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  
  std::cin >> S;

  if(ok()){
      std::cout << "Yes" << std::endl;
  }else{
      std::cout << "No" << std::endl;
  }
}


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

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

typedef long long ll;
using namespace std;

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

  int A, B, X;
  cin >> A >> B >> X;
  if (X < A || A + B < X) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(a: usize, b: usize, k: usize);
    let a_d = divisors(a);
    let b_d = divisors(b);
    let mut vvv = Vec::new();
    for v in &a_d {
        for vv in &b_d {
            if v == vv && !vvv.contains(v) {
                vvv.push(*v);
            }
        }
    }
    vvv.sort_by_key(|w| std::cmp::Reverse(*w));
    println!("{}", vvv[k - 1]);
}

fn divisors(n: usize) -> Vec<usize> {
    let mut divisors = Vec::new();
    // n := i * x とおくと、 i が i > root(n) の時、　i はすでに ある x に探索されているから
    // i <= root(n) まで探索すればよい
    for i in 1..=(f64::sqrt(n as f64) + 1e-9) as usize {
        // i で n が割り切れた場合
        if n % i == 0 {
            // 約数リストに格納
            divisors.push(i);

            // n := i * x の x を格納。ただし x := i の時は除く
            if i != n / i {
                divisors.push(n / i);
            }
        }
    }
    divisors.sort();
    divisors
}


Measured memory_bytes: 2184
#include "iostream"
#include "vector"
#include "string"
#include <iomanip>

//const double PI = 3.14159265358979323846;

using namespace std;

int main() {
	int X,Y;

	cin >> X >> Y;

	double t = -0.5 * Y + 2.0 * X;
	double k = 0.5 * Y -  X;

	bool t1 = ceil(t) == floor(t);
	bool t2 = t >= 0;

	bool k1 = ceil(k) == floor(k);
	bool k2 = k >= 0;

	if (t1 & t2 & k1 & k2) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;

}

Measured memory_bytes: 3164
#include <iostream>
#include <cstring> 
using namespace std;
char s[100000+100];
int a[100];
int main() {
	memset (a, 0, sizeof(a));
	
	cin>>s;
	int len = strlen(s);
	//标记 
	for (int i = 0; i <= len-1; i++){
		int x = int (s[i]) - 96; //'a'<->'z' ==> 1<->26 
		a[x] = 1;
	}
	//找最小 
	bool flag = false;
	for (int i = 1; i <= 26; i++){
		if (a[i] == 0){
			char ch = char(i + 96);
			cout<<ch<<endl;
			flag = true;
			break;
		}
	}
	if (flag == false) {
		cout<<"None"<<endl;
	}
	return 0;
}


Measured memory_bytes: 384
h,m = map(int,input().split())

a = []

for i in range(h):
	b = input()
	if b.count('.') != m:
		a.append(b)

b = len(a)
c =['' for i in range(m)]

for i in a:
	for j in range(m):
		c[j] += i[j]
d = []
for i in c:
	if i.count('.') != len(i):
		d.append(i)

b = len(d)
c =['' for i in range(len(d[0]))]

for i in d:
	for j in range(len(d[0])):
		c[j] += i[j]

for i in c:
	print(i)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef vector<double> dvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
#define fs first
#define sc second
int main()	{
  int n,m;
  cin>>n>>m;
  vector<int>d(m);
  rep(i,n){
    int k;
    cin>>k;
    rep(j,k){
      int a;
      cin>>a;
      d[a-1]++;
    }
  }
  int ans=0;
  rep(i,m){
    if(d[i]==n)
      ans++;
  }
  cout<<ans<<endl;
}

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

const int MAX = 510000;
const int MOD = 1000000007;

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

// 二項係数計算
long long 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 main() {
    int n,k;
    cin >> n >> k;
    if ( k >= n ) k = n-1;
    
    int64_t ans = 0;
    COMinit();
    
    for ( int64_t i = 0; i <= k; ++i){
        ans = ( ans + COM(n,i) * COM(n-1,i) ) % MOD;
    }
    
    cout << ans << endl;
    
    
    return 0;
}


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

int main() {
  long long int N, A, B, count=0;
  cin >> N >> A >> B;
  
  if (N<A){
    cout << N << endl;
  }
  else if (N <= (A + B)){
    cout << A << endl;
  }
  else {
    count = N / (A + B);
    
    if (N % (A + B)<=A){
      count *= A;
      count += N % (A + B);
    }
    else{
      count *= A;
      count += A;
    }
    cout << count << endl;
  }
  
}

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

typedef long long LL;

const int N=500,mod=1000000007;

int add(int a,int b,int p=mod){return a+b>=p?a+b-p:a+b;}
int sub(int a,int b,int p=mod){return a-b<0?a-b+p:a-b;}
int mul(int a,int b,int p=mod){return (LL)a*b%p;}
void sadd(int &a,int b,int p=mod){a=add(a,b,p);}
void ssub(int &a,int b,int p=mod){a=sub(a,b,p);}
void smul(int &a,int b,int p=mod){a=mul(a,b,p);}

int n,m,cnt[N+9];

void into(){
  scanf("%d%d",&n,&m);++m;
  for (int i=1;i<=n;++i){
	int x;
	scanf("%d",&x);
	++cnt[x];
  }
}

int pw[N+9][N+9];

void Get_pw(){
  int t=max(n,m);
  pw[0][0]=1;
  for (int i=1;i<=t;++i){
	pw[i][0]=1;
	for (int j=1;j<=t;++j) pw[i][j]=mul(pw[i][j-1],i);
  }
}

int inv[N+9],fac[N+9],ifac[N+9];

void Get_inv(){
  int t=max(n,m);
  inv[1]=1;
  fac[0]=fac[1]=1;
  ifac[0]=ifac[1]=1;
  for (int i=2;i<=t;++i){
	inv[i]=mul(mod-mod/i,inv[mod%i]);
	fac[i]=mul(fac[i-1],i);
	ifac[i]=mul(ifac[i-1],inv[i]);
  }
}

int dp[2][N+9][N+9],now,old,ans;

void Get_dp(){
  now=1;old=0;
  dp[now][0][0]=1;
  for (int i=m;i>=1;--i){
	now^=1;old^=1;
	for (int j=0;j<=m;++j)
	  for (int k=0;k<=m;++k) dp[now][j][k]=0;
    for (int j=0;j<=m;++j)
	  for (int k=0;k<=m;++k){
		if (!dp[old][j][k]) continue;
		for (int t=0;t<=m&&j+t<=m&&k+t*i<=m;++t){
		  int nj=j+t,nk=k+t*i;
		  sadd(dp[now][nj][nk],mul(mul(ifac[t],pw[nk-nj*i][cnt[i]]),dp[old][j][k]));
		}
	  }
  }
  for (int i=1;i<=m;++i){
	int t=mul(fac[i],dp[now][i][m]);
	i&1?sadd(ans,t):ssub(ans,t);
  }
}

void work(){
  Get_pw();
  Get_inv();
  Get_dp();
}

void outo(){
  printf("%d\n",ans);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 6820
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S,T;
  cin >> S >> T;
  bool ok = true;
  int size = S.length();
  int size_T = T.length();
  for (int i=0; i<size; i++){
    if (S[i] != T[i]){
      ok = false;
    }
  }
  
  if (size+1 != size_T) ok = false;
  
  if (ok == true) cout << "Yes";
  else cout << "No";

}

Measured memory_bytes: 3628
#include<algorithm>
#include<vector>
#include<cstring>
#include<iostream>
#include<cmath>

using namespace std;

int mod;

void dfs(int in, int pi, vector<int> adj[], long long dp[]) {
	dp[in] = 1;
	for(auto node: adj[in]) {
		if(node == pi)
			continue;
		dfs(node, in, adj, dp);
		dp[in] = dp[in] * (1+dp[node]) % mod;
	}
}



void dfs2(int in, int pi, vector<int> adj[], long long dp[], long long dp2[]) {
	{
		vector<long long> pref(adj[in].size());
		vector<long long> suff(adj[in].size());
		long long running_prod = 1;
		for(int j=0; j<adj[in].size(); j++) {
			int node = adj[in][j];
			if(node == pi) {
				pref[j] = running_prod;
				continue;
			}
			running_prod = running_prod * (1+dp[node]) % mod;
			pref[j] = running_prod;
		}
		running_prod = 1;
		for(int j=(int)adj[in].size()-1; j>=0; j--) {
			int node = adj[in][j];
			if(node == pi) {
				suff[j] = running_prod;
				continue;
			}
			running_prod = running_prod * (1+dp[node]) % mod;
			suff[j] = running_prod;
		}
		for(int j=0; j<adj[in].size(); j++) {
			int node = adj[in][j];
			if(node == pi)
				continue;
			dp2[node] = dp2[in];
			dp2[node] = dp2[node] * (j-1>=0 ? pref[j-1] : 1) % mod;
			dp2[node] = dp2[node] * (j+1<adj[in].size() ? suff[j+1] : 1) % mod;
			dp2[node] = 1+dp2[node];
		}
	}
	for(auto node: adj[in]) {
		if(node != pi)
			dfs2(node, in, adj, dp, dp2);
	}
}

int main() {
	int n;
	scanf("%d%d", &n, &mod);

	vector<int> adj[n];
	for(int i=0; i<n-1; i++) {
		int x, y;
		scanf("%d%d", &x, &y);

		x--;
		y--;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}

	long long dp[n], dp2[n];
	dfs(0, -1, adj, dp);
	dp2[0] = 1;
	dfs2(0, -1, adj, dp, dp2);
	for(int i=0; i<n; i++) {
		printf("%lld\n", dp[i]*dp2[i]%mod);
	}
    return 0;
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  string s;
  int m, h;
  while (cin >> s, s != "-") { 
    cin >> m;
    while (m--) {
      cin >> h;
      s = s.substr(h) + s.substr(0, h);
    }
    cout << s << '\n';
  }
  return 0;
}



Measured memory_bytes: 3132
FAST_IO = 1
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()

    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())
rrmm = lambda n: [rrm() for _ in xrange(n)]

n = rri()
arr = rrm()
ans = 0
for i in range(0, n,2):
    if arr[i]&1:
        ans+=1
print(ans)

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

int main() {
  int H, W;
  cin >> H >> W;
  
  vector<vector<int>> A(H, vector<int>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> A.at(i).at(j);
    }
  }
  
  vector<vector<int>> B(H, vector<int>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> B.at(i).at(j);
    }
  }
  
  vector<vector<vector<bool>>> DP(H, vector<vector<bool>>(W, vector<bool>(12801, false)));
  DP.at(0).at(0).at(abs(A.at(0).at(0) - B.at(0).at(0))) = true;
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      int p = abs(A.at(i).at(j) - B.at(i).at(j));
      for (int k = 0; k <= 12800; k++) {
        bool c1 = i > 0 ? DP.at(i - 1).at(j).at(k) : false;
        bool c2 = j > 0 ? DP.at(i).at(j - 1).at(k) : false;
        if (c1 || c2) {
          DP.at(i).at(j).at(k + p) = true;
          DP.at(i).at(j).at(abs(k - p)) = true;
        }
      }
    }
  }
  
  int ans;
  for (int i = 0; i <= 12800; i++) {
    if (DP.at(H - 1).at(W - 1).at(i)) {
      ans = i;
      break;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 12544
#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>;
const int Mod = 1000000007;

int main(){
  int S, W;
  cin >> S >> W;
  if(W >= S) cout << "un";
  cout << "safe" << endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int n,ans,sum,a[10001];
int main(){
    cin>>n;
    for(int i=0;i<2*n;i++) cin>>a[i];
    sort(a,a+2*n);
    for(int i=0;i<2*n;i+=2) sum+=a[i];
    cout<<sum<<endl;
    return 0;
}

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

using namespace std;

long F(long a, long b) {
    return max(to_string(a).length(), to_string(b).length());
}

int main() {
    long n;
    cin >> n;
    long a,b;
    long ret = n;
    for (long i = 1; i*i <= n; i++) {
        a = i;
        if (n % i == 0) {
            long l;
            b = n / i;
            ret = min(ret, F(a,b));
        }
    }

    cout << ret << endl;
}


Measured memory_bytes: 256
def main():
    n, x = map(int, input().split())
    l = list(map(int, input().split()))
    sum = 0
    for idx, i in enumerate(l):
        sum += i
        if sum > x:
            print(idx + 1)
            break
    else:
        print(n + 1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) true
#define dump(x) true
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	string s;
	cin >> s;
	int N = s.size();
	V<ll> h(N+1,1e9);
	rep(i,N-1) if(s[i] == '>' && s[i+1] == '<'){
		h[i+1] = 0;
	}
	if(s.front() == '<') h[0] = 0;
	if(s.back() == '>') h[N] = 0;
	V<int> z; rep(i,N+1) if(h[i] == 0) z.pb(i);
	int K = z.size();
	rep(i,K-1){
		for(int X=z[i];X<z[i+1];X++) if(s[X] == '<' && s[X+1] == '>'){
			X++;
			for(int x=z[i],he=0;x<X;x++,he++) h[x] = he;
			for(int x=z[i+1],he=0;x>X;x--,he++) h[x] = he;
			h[X] = max(h[X-1],h[X+1])+1;
			break;
		}
	}
	for(int x=z[0],he=0;x>=0;x--,he++) h[x] = he;
	for(int x=z.back(),he=0;x<=N;x++,he++) h[x] = he;
	dump(h);
	cout << accumulate(all(h),0LL) << endl;
}


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

int main() {
  long long N;
  cin >> N;
  
  vector<long long> L(N);
  for (long long i = 0; i < N; i++) {
    cin >> L[i];
  }
  sort(L.rbegin(), L.rend());
  
  long long count = 0;
  for (int i = 0; i+2 < N; i++) {
    if (L[i] >= L[i+1] + L[i+2]) continue;
    for (int j = i+1; j < N; j++) {
      if (L[i] >= L[j] + L[j+1]) break;
      for (int k = j+1; k < N; k++) {
        if (L[i] >= L[j] + L[k]) break;
        count++;
      }
    }
  }
  
  cout << count << endl;  
  return 0;
}

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

int main(){
  long long n, a, b, x, y, s = 0;
  cin >>n>>a>>b;
  x = n/(a+b);
  y = n-(a+b)*x;
  if(n%(a+b) != 0){
    if(a>y){
    	s += y;
    }
    else{
    	s += a;
    }
  }
  s += x*a;
  cout << s << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;

int N, M, S, T;
using P = pair<int, int>;
vector<P> link_e[100010];
vector<P> link_s[100010];
int len_list_e[100010];
int len_list_s[100010];

void func(vector<P> *link, int* len_list, int s, int t)
{
	queue<int> q;
	q.push(s);
	len_list[s] = 0;
	while (q.size() > 0)
	{
		int q_size = q.size();
		for (int i = 0; i < q_size; i++)
		{
			int a = q.front();
			q.pop();
			for (P l : link[a])
			{
				int new_len = len_list[a] + l.second;
				if (len_list[l.first] > new_len)
				{
					len_list[l.first] = new_len;
					q.push(l.first);
				}
			}
		}
	}
}

int ans[100010];

signed main()
{
	cin >> N >> M >> S >> T;
	REP(i, M)
	{
		int u, v, a, b;
		cin >> u >> v >> a >> b;
		link_e[u].push_back(P(v, a));
		link_e[v].push_back(P(u, a));
		link_s[u].push_back(P(v, b));
		link_s[v].push_back(P(u, b));
	}

	for (int i = 0; i <= N; i++)
	{
		len_list_e[i] = LLONG_MAX;
		len_list_s[i] = LLONG_MAX;
	}

	func(link_e, len_list_e, S, T);
	func(link_s, len_list_s, T, S);

	ans[N - 1] = len_list_e[N] + len_list_s[N];

	for (int i = N - 2; i >= 0; i--)
	{
		int a = len_list_e[i + 1] + len_list_s[i + 1];
		ans[i] = MIN(ans[i + 1], a);
	}

	for (int i = 0; i < N; i++)
	{
		cout << (1000000000000000 - ans[i]) << endl;
	}
}







Measured memory_bytes: 19164
n = int(input())
t, x, y = [0]*(n+1), [0]*(n+1), [0]*(n+1)
for i in range(1,n+1):
    t[i], x[i], y[i] = map(int, input().split())

for i in range(1, n+1):
    a = abs(t[i] - t[i-1])
    b = abs(x[i] - x[i-1]) + abs(y[i] - y[i-1])
    if a>=b and a%2 == b%2:
        continue
    else:
        print("No")
        break
else:
    print("Yes")



Measured memory_bytes: 11636
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
long long int n,a,b,c,d,i;
cin>>n;
c = 9999999999;
d=0;
for(i=0;i<n;i++){
cin>>a;
c = min(a,c);
if(c==a)d++;}
cout<<d<<endl;}

Measured memory_bytes: 3572
import sys
input=sys.stdin.readline
def main():
    N,Q = map(int,input().split())
    X = [list(map(int,input().split())) for _ in range(N-1)]
    Y = [list(map(int,input().split())) for _ in range(Q)]

    con = [[] for _ in range(N)]
    for i in range(N-1):
        con[X[i][0]-1]+=[X[i][1]-1]
        con[X[i][1]-1]+=[X[i][0]-1]

    dif = [0]*N
    for i in range(Q):
        dif[Y[i][0]-1] += Y[i][1]

    root = [0]
    while root:
        cur = root.pop()
        for i in con[cur]:
            dif[i] += dif[cur]
            con[i].remove(cur)
            root.append(i) 
    print(*dif)

if __name__ == "__main__":
    main()

Measured memory_bytes: 141168
#include<stdio.h>
#define N 100
void swap(int*,int*);
int main(){
  int data[N],i,n,j,count=0;

  scanf("%d",&n);

  for(i=0;i<n;i++){
  scanf("%d",&data[i]);
  }

  
  for(i=0;i<n;i++){
    for(j=n-1;j>i;j--){
    if(data[j]<data[j-1]){
      swap(&data[j],&data[j-1]);
      count++;
    }
  }
  }
    for(i=0;i<n;i++){
      printf("%d",data[i]);
      if(i!=n-1){
	printf(" ");
      }
    }
      printf("\n%d\n",count);

      return 0;
    }
      

void swap(int*x,int*y){
  int data;

  data=*x;
  *x=*y;
  *y=data;
}



Measured memory_bytes: 2048
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
//#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
#include <iomanip>
//#include <stdlib.h>
//#include <cctype>

using namespace std;

const int MAX_N = 1000000;
#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define prec std::cout << std::fixed << std::setprecision(15);
#define endl "\n"
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define ssort(z) sort(z.begin(), z.end())
#define rsort(z) sort(z.rbegin(), z.rend())
#define eerase(z) z.erase(unique(z.begin(), z.end()), z.end())
#define ccnt(z, w) count(z.begin(), z.end(), w)

void printVec(std::vector<int> & vec)
{
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it)
	{
		std::cout << *it << " ";
	}
	cout << '\n';
}
void printVec1(std::vector<string>& vec)
{
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it)
	{
		std::cout << *it << " ";
	}
	cout << '\n';
}
void printVec2(std::vector<Int>& vec)
{
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it)
	{
		std::cout << *it << " ";
	}
	cout << '\n';
}

Int gcd(Int a, Int b)
{
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b)
{
	return a / gcd(a, b) * b;
	//a*bは64bit integer overflow
}

bool integer(double num)
{
	return floor(num) == num;
}

Int fact(int num)
{
	if (num == 0)
		return 1;
	else
		return num * fact(num - 1);
}

int main() {
	IOS;
	// cout << fixed << setprecision(20);
	// int a;cin >> a;
	// string s;cin>>s;
	int m,d;cin >> m >> d;
	int d1 = 2, d2 = 2;
	int cnt = 0;
	for (int i = 1; i <= m;i++){
		while(d2*10+d1<=d){
			
			if(d1*d2==i){
				//cout << i << " " << d1+d2*10<<endl;
				cnt++;
			}
			if(d1==9){
				d1 = 2;
				d2++;
			}else{
				d1++;
			}
		}
		d1 = 2, d2 = 2;
	}
	cout << cnt;

	cout << endl;
	return 0;
}

/*
テレビも無ェ ラジオも無ェ
自動車もそれほど走って無ェ
ピアノも無ェ バーも無ェ
巡査 毎日ぐーるぐる
朝起ぎで 牛連れで
二時間ちょっとの散歩道
電話も無ェ 瓦斯も無ェ
バスは一日一度来る
俺らこんな村いやだ 俺らこんな村いやだ
東京へ出るだ 東京へ出だなら
銭コァ貯めで 東京でベコ(牛)飼うだ
*/


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

int main(void){
    string s, t;
    cin >> s >> t;

    int cnt = 0;
    rep(i,s.length()) {
        if (s[i] != t[i]) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3852
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def main():
    N, K = map(int, input().split())
    p = list(map(int, input().split()))
    p.sort()
    print(sum(p[:K]))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 62256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;

string s3[3]={
	"aab",
	"c.b",
	"cdd"
};
string s4[4]={
	"aacd",
	"bbcd",
	"efgg",
	"efhh"
};
string s5[5]={
	"aabee",
	"c.bff",
	"cdd.j",
	"gh..j",
	"ghii."
};
string s7[7]={
	"aabee..",
	"c.b..ff",
	"cdd.j..",
	"g..ij..",
	"g..il..",
	".h..lmm",
	".hkk.nn"
};

void f(vi a){
	vs b(n,string(n,'.'));
	int t=0;
	for(auto i:a){
		for(int j=0;j<i;j++) for(int k=0;k<i;k++){
			char c;
			if(i==3) c=s3[j][k];
			if(i==4) c=s4[j][k];
			if(i==5) c=s5[j][k];
			if(i==7) c=s7[j][k];
			b[t+j][t+k]=c;
		}
		t+=i;
	}
	for(int i=0;i<n;i++) cout<<b[i]<<endl;
}

int main(){
	cin>>n;
	if(n==2){
		cout<<-1<<endl;
		return 0;
	}
	if(n%3==0){
		vi a(n/3,3);
		f(a);
		return 0;
	}
	for(int i=0;4*i<=n;i++) for(int j=0;5*j<=n-4*i;j++) if((n-4*i-5*j)%7==0){
		int k=(n-4*i-5*j)/7;
		vi a(i+j+k);
		for(int l=0;l<i;l++) a[l]=4;
		for(int l=0;l<j;l++) a[l+i]=5;
		for(int l=0;l<k;l++) a[l+i+j]=7;
		f(a);
		return 0;
	}
	while(1);
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n;
  cin>>n;
  vi a(n),S(n);
  int mx = 0;
  rep(i,n-1){
    cin>>a[i];
    a[i]--;
  }
  rep(i,n-1){
    S[a[i]]++;
  }
  S[n-1] = 0;
  rep(i,n){
    cout<<S[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 4780
from collections import Counter
s = input()
sc = Counter(s)
ans = float('inf')
for i in sc.keys():
    s2 = s
    while len(Counter(s2).keys()) != 1:
        for j in range(len(s2)-1):
            if s2[j+1] == i:
                s2 = s2[:j] + s2[j+1]+ s2[j+1:]
        s2 = s2[:-1]
    ans = min(ans,len(s)-len(s2))
print(ans)

Measured memory_bytes: 3316
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <typeinfo>
#include <cmath>
#include <numeric>
#include <queue>
#include <set>
using namespace std;

bool isYM(string str){
    if(str == "00") return true;
    int num = stoi(str);
    if((num > 12)&&(num < 100)){
        return true;
    }else{
        return false;
    }
}

int main(){
    // std::cout << stoi(string("01")) << "\n";
    std::string S;
    std::cin >> S;
    string answer;
    string first = S.substr(0, 2);
    string second = S.substr(2, 2);
    
    if(isYM(first)){
        if(isYM(second)){
            answer = "NA";
        }else{
            answer = "YYMM";    
        }
    }else{
        if(isYM(second)){
            answer = "MMYY";
        }else{
            answer = "AMBIGUOUS";            
        }
    }
    std::cout << answer << "\n";
    // std::cout << isYM(second) << "\n";
}

Measured memory_bytes: 256
N, M, Q = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(M)]
P = [list(map(int, input().split())) for _ in range(Q)]

table = [[0 for i in range(N+1)] for j in range(N+1)]

for l, r in LR:
    table[l][r]+=1
    
for y in range(N+1):
    for x in range(N):
        table[y][x+1]+=table[y][x]

for x in range(N+1):
    for y in range(N):
        table[N-y-1][x]+=table[N-y][x]
        
for p, q in P:
    print(table[p][q])

Measured memory_bytes: 73752
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
const int MAX_V=610;
int V;
vector<int> G[MAX_V];
vector<int> rG[MAX_V]; //辺の向きを逆にした
double d[MAX_V], d2[MAX_V];
void add_edge(int from, int to){
    G[from].pb(to);
    rG[to].pb(from);
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll m;
    cin>>V>>m;
    rep(i,0,m){
        int s,t;
        cin>>s>>t;
        add_edge(s-1, t-1);
    }
    rer(i,V-1,0){
        double res=0;
        for(int to:G[i]){
            res+=d[to]+1;
        }
        d[i]=res/sz(G[i]);
    }
    double ans=d[0];
    rep(i,0,V){
        if(sz(G[i])>1){
            rep(j,0,V) d2[j]=d[j];
            double res=0;
            double M=0;
            for(int to:G[i]){
                res+=d2[to]+1;
                M=max(M,d2[to]+1);
            }
            d2[i]=(res-M)/(sz(G[i])-1);
            rer(j,i,0){
                double res=0;
                for(int to:G[j]){
                    res+=d2[to]+1;
                }
                d2[j]=res/sz(G[j]);
            }
            ans=min(ans,d2[0]);
        }
    }
    cout << setprecision(15)<<ans<<"\n";
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define CLR(a) memset(a,0,sizeof(a))
#define DBG(x) cout<<(#x)<<"="<<x<<endl
#define FOR(i,a,b)  for(int i=(a);i<(b);i++)
#define REP(i,a,b)  for(int i=(a);i<=(b);i++)
#define DOWN(i,a,b) for(int i=(a);i>=(b);i--)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const double eps=1e-8;
const int INF=0x3f3f3f3f;
const ll LL_INf=0x3f3f3f3f3f3f3f3f;
const ll mod=1000000009;
const int N=30+10;

int n;

int main(){
	cin>>n;
	cout<<n/3<<endl;
	//cout<<1.*clock()/CLOCKS_PER_SEC<<"ms"<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N;
LL A[1011];

void MAIN() {
    scanf("%d", &N);
    REP (i, N) scanf("%lld", A+i);

    int s = 0;
    LL ans = 0;

    REP (t, 2) {
	LL cur = 0;
	for (int i=t; i<N; i+=2) {
	    if (A[i] > 0) cur += A[i];
	}

	if (ans < cur) {
	    ans = cur;
	    s = t;
	}
    }

    if (ans == 0) {
	int k = max_element(A, A+N) - A;
	printf("%lld\n", A[k]);
	printf("%d\n", N-1);
	for (int i=N-1; i>k; i--) printf("%d\n", i+1);
	REP (i, k) puts("1");

    } else {

	printf("%lld\n", ans);
	VI v;

	int L = 0, R = N;
	while (L%2 != s || A[L] <= 0) {
	    v.push_back(1);
	    L++;
	}
	while ((R-L)%2 == 0 || A[R-1] <= 0) {
	    v.push_back(R-L);
	    R--;
	}
	while (L+2 < R) {
	    if (A[L+2] <= 0) {
		v.push_back(3);
		A[L+2] = A[L];
		L += 2;
	    } else {
		v.push_back(2);
		A[L+2] += A[L];
		L += 2;
	    }
	}

	printf("%d\n", (int)v.size());
	EACH (e, v) printf("%d\n", *e);
    }
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#define debug(a) cout << "*" << a << "*" << endl
using namespace std;
typedef long long ll;
int n, num[200005];
struct node{
	int x;
	int id;
	friend bool operator<(node a, node b){
		return a.x < b.x;
	}
}a[200005];
int main()
{	
	while (~scanf("%d", &n))
	{
		for (int i = 1; i <= n; i++)
		{
			scanf("%d", &a[i].x);
			a[i].id = i;
		}
		sort(a + 1, a + 1 + n);
		for (int i = 1; i <= n; i++)
		{
			num[a[i].id] = i;
		}
		for (int i = 1; i <= n; i++)
		{
			if (num[i] <= n / 2)
				printf("%d\n", a[n / 2 + 1]);
			else
				printf("%d\n", a[n / 2]);
		}
	}
}

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



int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}

int main(){

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

long double n;
cin>>n;
n/=3;
long double l=n*n*n;;


cout << setprecision(12) << fixed<<l<< endl;

}


Measured memory_bytes: 256
import sys

def solve(a,b):
    e = b[0]
    d = b[-1]
    for c in b:
        if d < c:
            d = c
        elif e >= c:
            e = c
    return d-e
    
def readQuestion():
    line1 = sys.stdin.readline().rstrip()
    n = int(line1)
    line2 = sys.stdin.readline().rstrip()
    lst_a = [int(s) for s in line2.split(' ')]
    return (n, lst_a)

def main():
    n, lst_ab = readQuestion()
    answer = solve(n, lst_ab)
    print(answer)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#define ll unsigned long long int

using namespace std;

ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    return(a / gcd(a, b) * b);
}

int main(){
    int n;
    ll answer, temp;
    cin >> n;
    for(int i = 0; i < n; i++){
        if(i == 0){
            cin >> answer;
        }else{
            cin >> temp;
            answer = lcm(answer, temp);
        }
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	//ios::sync_with_stdio(false);
	//cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll x;
	cin >> x;
	ll a = 100;
	ll ans = 0;
	while (a < x) {
		a += a / 100;
		ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3636