akhauriyash/Code-Regression huggingface dataset:
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define ll long long
#define INFTY 1 << 21
ll min(ll a, ll b) { return b < a ? b : a; }
ll max(ll a, ll b) { return b < a ? a : b; }
typedef pair<int, int> P;

int main() {
  string s;
  cin >> s;
  if (s == "Sunny") cout << "Cloudy" << endl;
  if (s == "Cloudy") cout << "Rainy" << endl;
  if (s == "Rainy") cout << "Sunny" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define EB emplace_back
#define G(x,i) get<i>(x)
#define F(i,s,n) for(int i = s; i < n; i++)
#define all(x) x.begin(), x.end()
typedef pair<int,int> ii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
#define MOD 998244353

ll A[200005];
ll B[200005];

int main() {
	iostream::sync_with_stdio(false);
	cin.tie(0);
	int N;
	cin>>N;
	F(i,0,N){
		int a;
		cin>>a;
		A[a]++;
		B[i] = a;
	}
	ll total = 0;
	F(i,1,N+1){
		total += A[i] * (A[i] - 1);
	}
	F(i,0,N){
		cout<<(total - A[B[i]]*(A[B[i]] - 1) + (A[B[i]] - 1) * (A[B[i]] - 2)) / 2<<endl;
	}
}

Measured memory_bytes: 4736
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ull, ull> UP;
typedef tuple<int, int, int> T;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
ll digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
ll countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}


int main() {
	IOS;
	int n;
	cin >> n;
	if (n / 10 == 9 || n % 10 == 9)cout << "Yes" << endl;
	else cout << "No" << endl;
}



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;
using P = pair<int,int>;

int main() {
  string s; cin >> s;
  if ((int)s.size() % 2 == 1) {
    cout << "No";
    return 0;
  }
  rep(i, (int)s.size()) {
    if ((i % 2 == 0 && s[i] != 'h') || (i % 2 == 1 && s[i] != 'i')) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

MOD = 10 ** 9 + 7

N = int(input())
S = list(map(lambda x: int(x == "W"),input()))
if S[0] or S[-1]:
    print(0)
    exit(0)

Dc = 1
LRsub = 1
Pattern = 1
Sp = S[0]

for i in range(1,N*2):
    Sc = S[i]
    Dc = Dc if Sc != Sp else -Dc
    Sp = Sc
    if Dc < 0:
        Pattern = (Pattern * LRsub) % MOD
    LRsub += Dc

if LRsub == 0:
    for i in range(2,N+1):
        Pattern = (Pattern * i) % MOD
    print(Pattern)
else:
    print(0)


Measured memory_bytes: 5092
check[30], c, n, a;
int main() {
  while (1) {
    c = getchar_unlocked();
    if ('0' <= c && c <= '9')
      n = n * 10 + c - '0';
    else
      break;
  }

  int xor_sum = 0;
  for (int i = 0; i < n; i++) {
    a = 0;
    while (1) {
      c = getchar_unlocked();
      if ('0' <= c && c <= '9')
        a = a * 10 + c - '0';
      else
        break;
    }
    xor_sum ^= a;
    a = a ^ (a - 1);

    check[__builtin_popcount(a) - 1] = 1;
  }

  int ans = 0;
  for (int bit = 29; bit >= 0; bit--) {
    if (check[bit] && ((1 << bit) & xor_sum)) {
      int x = (1 << (bit + 1)) - 1;
      xor_sum ^= x;
      ans += 1;
    }
  }

  if (xor_sum != 0) {
    printf("-1\n");
  } else {
    printf("%d\n", ans);
  }
}

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

////////////
// ModInt //
////////////

// 四則演算の最も左に存在する値がModIntでなければキャストでバグる
// 例えばx = mint * 1000;やx = ModInt(1000) * mint;はいいがx = 1000 * mint;は駄目。
template<int64_t mod_ = 1'000'000'007>
class ModInt {
private:
	int64_t integer_;

public:
	constexpr ModInt(const int64_t initial_number = 0)
		: integer_(initial_number){}
	
	// 四則演算
	constexpr ModInt operator+(const ModInt& operand) const
	{
		ModInt ret{this->integer_ + operand.integer_};
		if (ret.integer_ >= mod_)
			ret.integer_ -= mod_;
		return ret;
	}
	constexpr ModInt operator-(const ModInt& operand) const
	{
		ModInt ret{this->integer_ - operand.integer_};
		if (ret.integer_ < 0)
			ret.integer_ += mod_;
		return ret;
	}
	constexpr ModInt operator*(const ModInt& operand) const
	{
		return {this->integer_ * operand.integer_ % mod_};
	}
	constexpr ModInt operator/(const ModInt& operand) const
	{
		return *this * (operand ^ (mod_ - 2));
	}

	// 累乗
	constexpr ModInt operator^(const int64_t operand) const
	{
		ModInt ret{1}, pow_ope{this->integer_};
		for (int64_t pow{operand}; pow > 0; pow >>= 1)
		{
			if (pow & 1) ret *= pow_ope;
			pow_ope *= pow_ope;
		}
		return ret;
	}

	// 代入
	constexpr ModInt& operator=(const ModInt& operand)
	{
		this->integer_ = operand.integer_;
		return *this;
	}
	constexpr ModInt& operator+=(const ModInt& operand)
	{
		*this = *this + operand;
		return *this;
	}
	constexpr ModInt& operator-=(const ModInt& operand)
	{
		*this = *this - operand;
		return *this;
	}
	constexpr ModInt& operator*=(const ModInt& operand)
	{
		*this = *this * operand;
		return *this;
	}
	constexpr ModInt& operator/=(const ModInt& operand)
	{
		*this = *this / operand;
		return *this;
	}

	// その他
	constexpr operator int64_t() { return integer_; }

	constexpr ModInt getOne() const
	{
		return ModInt(1ll);
	}
	constexpr ModInt getZero() const
	{
		return ModInt(0ll);
	}
};

using vi = std::vector<int64_t>;
using vvi = std::vector<vi>;

std::string L;
vvi dp;

int64_t rc(int, int);

int main()
{
	std::cin >> L;
	L = '0' + L;
	dp.resize(L.size() + 1, vi(2, -1));
	dp[L.size()][0] = dp[L.size()][1] = 1;
	printf("%lld\n", rc(0, 0));

	return 0;
}

int64_t rc(int digit, int is_free)
{
	if (dp[digit][is_free] >= 0) return dp[digit][is_free];
	ModInt<> ret;
	ret += ModInt<>(rc(digit + 1, is_free || L[digit] == '1'));
	if (is_free || L[digit] == '1')
		ret += ModInt<>(2) * ModInt<>(rc(digit + 1, is_free));
	dp[digit][is_free] = (int64_t)ret;
	return dp[digit][is_free];
}

Measured memory_bytes: 12156
N=int(input())
T=[0]*N
for i in range(N):
  T[i]=int(input())
  
def gcd(a,b):
  if b>a:
    a,b=b,a
  while a%b!=0:
    a,b=b,a%b
  return b

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

ans=1
for i in range(N):
  ans=lcd(ans,T[i])
  
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=1e6+5;
int tab[MAXN];

int main(){
    ios::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);
    int n,sum1=0,sum2=0;
    cin >> n;
    for(int i=0;i<n;i++)
		cin >> tab[i];
	sort(tab,tab+n,greater<int>());
	for(int i=0;i<n;i+=2)
		sum1+=tab[i];
	for(int i=1;i<n;i+=2)
		sum2+=tab[i];
	cout << sum1-sum2;
}


Measured memory_bytes: 256
#n=int(input())
#n,m=map(int,input().split())
#sl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

n=int(input())
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())

mn=min(a,b,c,d,e)
import math
print(math.ceil(n/mn)+4)


Measured memory_bytes: 3060
import java.util.*;

public class Main{
	public static void main(String[] args){
		String input = new Scanner(System.in).nextLine();
		String[] num = input.split("\\s");

		int[] numb = new int[num.length];

		for(int i = 0; i < numb.length; i++){
			numb[i] = Integer.parseInt(num[i]);
		}

		for(int i = 0; i <numb.length; i++){
			for(int j = numb.length - 1; j > i; j--){
				if(numb[j] < numb[j-1]){
					int s = numb[j];
					numb[j] = numb[j-1];
					numb[j-1] = s;
				}
			}
		}
		System.out.println(numb[0] + " " + numb[1] + " " + numb[2]);
	}
}

Measured memory_bytes: 26112
import sys
import math

N = 1000000
primes = [1] * (N//2+1)
primes[0] = 1

for i in range(3,int(math.sqrt(N))+1,2):
    if primes[i//2]:
        primes[(i*i)//2::i] = [0] * len(primes[(i*i)//2::i])
    primes[i//2] += primes[i//2-1]

for i in range(int(math.sqrt(N))+1,N+1,2):
    primes[i//2] += primes[i//2-1]


for i in sys.stdin:
    n = int(i)
    if n == 1:
        print(0)
    elif n == 2:
        print(1)
    else:
        print(primes[(n-1)//2])

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

using namespace std;
using ll = long long;

int main() {
  string s;
  cin >> s;
  int n = (int)s.size();
  
  ll res = 0;
  for (int bits=0; bits<(1<<(n-1)); bits++) {
    ll tmp = (ll)(s.at(0) - '0');
    for (int i=0; i<n-1; i++) {
      if (bits & (1<<i)) {
        res += tmp;
        tmp = 0;
      } else {
        tmp *= 10;
      }
      tmp += (ll)(s.at(i+1) - '0');
    }
    res += tmp;
  }
  
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
import math
import random
import heapq
from collections import Counter, defaultdict
from decimal import Decimal, ROUND_HALF_UP, ROUND_CEILING
from functools import lru_cache, reduce
from itertools import combinations_with_replacement, product, combinations


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def mt(f):
    import time
    import sys

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        print(e - s, 'sec', file=sys.stderr)
        return ret

    return wrap


def root(G, x):
    if G[x] != x:
        G[x] = root(G, G[x])
    return G[x]


def same(G, x, y):
    return root(G, x) == root(G, y)


def union(G, x, y):
    x = root(G, x)
    y = root(G, y)

    if x != y:
        G[x] = y


@mt
def slv(N, M, P, XY):
    P = [-1] + P
    G = [i for i in range(N + 1)]

    for x, y in XY:
        union(G, x, y)

    ans = 0
    for i, p in enumerate(P):
        if same(G, p, i):
            ans += 1

    return ans


def main():
    N, M = read_int_n()
    P = read_int_n()
    XY = []
    for _ in range(M):
        XY.append(read_int_n())

    print(slv(N, M, P, XY))


if __name__ == '__main__':
    main()

Measured memory_bytes: 38380
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int N;
std::string S;

int64_t const B1 = 1e8+7;
int64_t const B2 = 1e9+7;

// Rolling Hash
bool isOK(int l) {
  int64_t r1 = 0, r2 = 0;
  std::map<int64_t, int> m1, m2;
  int64_t B1l = 1, B2l = 1;
  for(int i = 0; i < l; ++i) { B1l *= B1; B2l *= B2; }
  int i, j;
  for(i = 0; i < l; ++i) {
    r1 = r1*B1 + S[i];
    r2 = r2*B2 + S[i];
  }
  m1[r1] = m2[r2] = j = 0;
  for(; i < N; ++i) {
    r1 = r1*B1 + S[i] - S[j]*B1l;
    r2 = r2*B2 + S[i] - S[j]*B2l;
    ++j;
    if(m1.count(r1) && m1[r1] <= j-l && 
       m2.count(r2) && m2[r2] <= j-l) return true;
    if(m1.count(r1) < 1) m1[r1] = j;
    if(m2.count(r2) < 1) m2[r2] = j;
  }
  return false;
}

int main() {
  std::cin >> N >> S;
  int ok = 0, ng = N/2+1;
  while(ng - ok > 1) {
    int mid = (ok+ng)/2;
    if(isOK(mid)) ok = mid; else ng = mid;
  }
  fin(ok);
  return 0;
}


Measured memory_bytes: 896
#include <stdio.h>

int main(void)
{
	int n, i, j;
	int seed;

	scanf("%d", &n);
	for (i = 0; i < n; i++){
		scanf("%d", &seed);

		printf("Case %d:\n", i + 1);
		for (j = 0; j < 10; j++){
			seed *= seed;
			seed = (seed / 100) % 10000;
			printf("%d\n", seed);
		}
	}

	return (0);
}

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

typedef long long ll;

ll d[2007] = {0};
const ll m = 1e9+7;

void solve(ll x) {
	ll res = 0;
	for (int i = 0; i <= x - 3; ++i) {
		res = (res + d[i]) % m;
	}
	d[x] = res;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll n;
	cin >> n;
	d[0] = 1;
	for (ll i = 1; i <= n; ++i) {
		solve(i);
	}
	cout << d[n] << endl;
	return 0;
}

Measured memory_bytes: 3512
import math
from decimal import *
getcontext().prec = 50
a,b,c,d = map(int,input().split())

from functools import reduce
def gcd(a,b):
  if a < b:
    a, b = b, a
  while a % b != 0:
    a, b = b, a % b
  return b

def lcm_base(x, y):
  return (x * y) // gcd(x, y)

def lcm_list(numbers):
  return reduce(lcm_base, numbers, 1)

gcd = lcm_list([c,d])

def solve(n):
	start = n * math.ceil(Decimal(a) / Decimal(n))
	end = n * (Decimal(b) // Decimal(n))
	#print(start,end)
	return (end - start) // n + 1

#print(solve(c),solve(d),solve(gcd))
ans = solve(c) + solve(d) - solve(gcd)
#print(ans)
print(b - a - ans + 1)


Measured memory_bytes: 5076
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
int main(){
    int n; cin >> n;
    vector<int> p(n), pos(n);
    rep(i,n) {
        cin >> p[i];
        p[i]--;
        pos[p[i]] = i;
    }

    ll ans = 0;
    set<int> s;

    for(int i = n-1; i >= 0; i--){
        int index = pos[i];
        s.insert(index);
        vector<int> l(2, -1);
        vector<int> r(2, n);

        auto it = s.find(index);
        rep(j,2){
            if(it == s.begin()) break;
            it--;
            l[j] = *it;
        }

        it = s.find(index);
        rep(j,2){
            it++;
            if(it == s.end()) break;
            r[j] = *it;
        }

        ll cnt = (ll)(index-l[0])*(r[1]-r[0]) + (ll)(r[0]-index)*(l[0]-l[1]);
        ans += cnt*(i+1);
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 5760
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>
#include <random>
#include <complex>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

using ld = long double;
using pnt = complex<ld>;
constexpr ld EPS = 1e-12;

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

ld cross(const pnt &a, const pnt &b) { return a.real() * b.imag() - a.imag() * b.real(); }

template <class iter>
std::pair<pnt, ld> min_ball(iter left, iter right, int seed = 1333) {
	const int n = right - left;

	assert(n >= 1);
	if (n == 1) {
		return { *left, ld(0) };
	}

	std::mt19937 mt(seed);
	std::shuffle(left, right, mt);
	// std::random_shuffle(left, right); // simple but deprecated

	iter ps = left;
	using circle = std::pair<pnt, ld>;

	auto make_circle_3 = [](const pnt &a, const pnt &b, const pnt &c) -> circle {
		ld A = std::norm(b - c), B = std::norm(c - a), C = std::norm(a - b),
			S = cross(b - a, c - a);
		pnt p = (A * (B + C - A) * a + B * (C + A - B) * b + C * (A + B - C) * c) / (4 * S * S);
		ld r2 = std::norm(p - a);
		return { p, r2 };
	};

	auto make_circle_2 = [](const pnt &a, const pnt &b) -> circle {
		pnt c = (a + b) / (ld)2;
		ld r2 = std::norm(a - c);
		return { c, r2 };
	};

	auto in_circle = [](const pnt &a, const circle &c) -> bool {
		return std::norm(a - c.first) <= c.second + EPS;
	};

	circle c = make_circle_2(ps[0], ps[1]);

	// MiniDisc
	for (int i = 2; i < n; ++i) {
		if (!in_circle(ps[i], c)) {
			// MiniDiscWithPoint
			c = make_circle_2(ps[0], ps[i]);
			for (int j = 1; j < i; ++j) {
				if (!in_circle(ps[j], c)) {
					// MiniDiscWith2Points
					c = make_circle_2(ps[i], ps[j]);
					for (int k = 0; k < j; ++k) {
						if (!in_circle(ps[k], c)) {
							c = make_circle_3(ps[i], ps[j], ps[k]);
						}
					}
				}
			}
		}
	}
	return c;
}

int main() {

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

	int N;
	cin >> N;

	vector<pnt> xy(N);
	for (int i = 0; i < N; i++) {
		ld x, y;
		cin >> x >> y;
		xy[i] = { x,y };
	}

	//DMP(center(pnt(0, 0), pnt(1, 1), 0.5).first);

	ld ans = INF;

	cout << setprecision(20) << sqrt(min_ball<decltype(xy.begin())>(xy.begin(), xy.end()).second) << "\n";

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define NIL -1
#define YOSHI 100000

typedef struct node_{
    int p,l,r;
}node;

struct node_ T[YOSHI];

int n,D[YOSHI],H[YOSHI];
void setDepth(int,int);
int setHeight(int);
int getSibling(int);
void print(int);

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

void setDepth(int x,int d){
    if(x == NIL) return;
    
    D[x] = d;
    
    setDepth(T[x].l,d + 1);
    setDepth(T[x].r,d + 1);
}

int setHeight(int x){
    int H1 = 0,H2 = 0;
    
    if(T[x].l != NIL) H1 = setHeight(T[x].l) + 1;
    if(T[x].r != NIL) H2 = setHeight(T[x].r) + 1;
    
    return H[x] = (H1 > H2 ? H1 : H2);
}

int getSibling(int x){
    if(T[x].p == NIL) return NIL;
    if(T[T[x].p].l != x && T[T[x].p].l != NIL) return T[T[x].p].l;
    if(T[T[x].p].r != x && T[T[x].p].r != NIL) return T[T[x].p].r;
    
    return NIL;
}

void print(int x){
    int deg = 0;
    
    printf("node %d: ",x);
    printf("parent = %d, ",T[x].p);
    printf("sibling = %d, ",getSibling(x));
    
    if(T[x].l != NIL) deg++;
    if(T[x].r != NIL) deg++;
    printf("degree = %d, ",deg);
    printf("depth = %d, ",D[x]);
    printf("height = %d, ",H[x]);
    
    if(T[x].p == NIL) printf("root\n");
    else if(T[x].l == NIL && T[x].r == NIL) printf("leaf\n");
    else printf("internal node\n");
    
}


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

using namespace std;

int main(){
    long N,M;
    cin >> N >> M;
    vector<long> x(N);
    vector<long> y(N);
    vector<long> z(N);
    for(long i = 0; i < N; i++){
        cin >> x.at(i) >> y.at(i) >> z.at(i);
    }
    long result;
    long max = 0;
    for(int i = 0; i < 1 << 3; i++){
        vector<long> sum(N);
        result = 0;
        for(long j = 0; j < N; j++){
            sum.at(j) = pow(-1,(1 & i)) * x.at(j) + pow(-1,(1 & i >> 1)) * y.at(j) + pow(-1,(1 & i >> 2)) * z.at(j);
        }
        sort(sum.begin(),sum.end(),greater<long>());
        for(long k = 0; k < M ; k++){
            result += sum.at(k);
        }
        max = std::max(max,result);
    }
    cout << max << endl;
}

Measured memory_bytes: 512
# AtCoder Educational DP Contest - A

n = int(input())
h = [0] + list(map(int, input().split()))

cost = [0, 0, abs(h[1]-h[2])]

for i in range(3, n+1):
    cost.append(
        min(
            cost[i-2]+abs(h[i-2]-h[i]),
            cost[i-1]+abs(h[i-1]-h[i])
        )
    )

print(cost[n])


Measured memory_bytes: 13980
#include<bits/stdc++.h>
using namespace std;
main()
{
    long long n,m,i,j,k,p,x,y;
    cin>>n>>m>>k>>j;
    x=m*j;
    y=n*k;
    i=n*j;
    p=m*k;
    x=max(x,y);
    x=max(x,i);
    x=max(x,p);
    cout<<x;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;

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

    string s;
    cin >> s;
    int  k;
    cin >> k;
    set<string> st;
    int n = s.size();
    map<char,bool> mp;
    vector<vector<int>> num(26);
    for(int i = 0; i < n; i++) num[s[i]-'a'].push_back(i);
    for(int i = 0; i < n; i++) mp[s[i]] = true;
    for(int i = 0; i < 26; i++){
        if(mp['a'+i]){
            for(auto p:num[i]){
                for(int k = 1; k <= 5; k++){
                    string t = s.substr(p,k);
                    st.insert(t);
                }
            }
            if(st.size() >= k) break;
        }
    }
    //cout << st.size() << endl;
    int i = 0;
    for(auto p:st){
        //cout << p << endl;
        if(i == k-1){
            cout << p << endl;
            return 0;
        }
        i++;
    }
    return 0;
}


Measured memory_bytes: 3748
#include<bits/stdc++.h>
#define r(i,a,n) for(int i=a;i<n;i++)
using namespace std;
int n;
string s[101];
set<string>se;
void ch(int p){
  string t=s[p],y;
  int x=0;
  while(1)
    if(t[x]==':')break;
    else y+=t[x],x++;
  x++;
  if(se.count(y)||p==0){se.erase(y),y="";
    for(;x<t.size();x++)
      if(t[x]==','||t[x]=='.')se.insert(y),y="";
      else y+=t[x];
  }
}
int main(){
  while(cin>>n,n){
    se.clear();
    r(i,0,n)cin>>s[i];
    ch(0);
    r(i,1,n)r(j,1,n)ch(j);
    cout<<se.size()<<endl;
  }
}

Measured memory_bytes: 3112
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
    ll a, b, c;
    cin >> a >> b >> c;
    if(a+b<c) cout << a+2*b+1 << endl;
    else cout << b+c << endl;
    return 0;
}

Measured memory_bytes: 256
n,p = map(int, input().split())
lis = list(map(int, input().split()))

odd = [i for i in lis if i % 2==1]
even = [i for i in lis if i % 2 == 0]

if len(odd) == 0:
    if p == 0:
        print(2**n)
    else:
        print(0)
else:
    odd_m = len(odd)
    even_m = len(even)
    t1 = 2**even_m
    t2 = 2**(odd_m-1)
    print(t1*t2)

Measured memory_bytes: 9104
#include<iostream>
#include<string>
#include<stack>
using namespace std;
int main(){
	while(1){
		bool flag;
		flag = true;
		string str;
		stack<int> num;
		getline(cin,str);
		if(str==".")	break;
		for(int i=0;i<str.size();i++){
			if(str[i]=='[')	num.push(1);
			else if(str[i]==']'){
				if(num.size()==0){
					flag=false;
					break;
				}
				if(num.top()==1)	num.pop();
				else{
						flag=false;
						break;
				}
			}
			else if(str[i]==')'){
				if(num.size()==0){
					flag = false;
					break;
				}
				if(num.top()==2)	num.pop();
				else{
						flag=false;
						break;
				}
			}
			else if(str[i]=='(')	num.push(2);
			
		}
		if(num.size()==0&&flag)	cout << "yes\n";
		else	cout << "no\n";
	}
}


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

typedef unsigned long ul;
typedef long long int ll;
typedef pair<ll, ll> P;
#define pb push_back
#define mp make_pair
#define REP(i,n) REPN(i,0,n)
#define REPN(i,m,n) for(int i=m; i<(n); i++)
#define ALL(a) (a).begin(),(a).end()
#define dump(x) cout << #x << " = " << (x) << endl

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

    double t, x;
    cin >> t >> x;
    cout << t / x << '\n';
}


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

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

const int LIM = 1299709;

bool is_prime(int n) {
    if(n < 2) return false;
    if(n == 2) return true;
    if(n % 2 == 0) return false;
    for(int i=3; i*i<=n; i+=2) if(n % i == 0) return false;
    return true;
}

void solve(int k) {
    int a=0, b=0;
    for(int i=k+1; ; ++i) if(is_prime(i)) {
        b = i; break;
    }
    for(int i=k-1; i>=0; --i) if(is_prime(i)) {
        a = i; break;
    }
    if(a == 0 or b == 0) {
        puts("0"); return ;
    }
    for(int i=a+1; i<=b-1; i++) if(is_prime(i)) {
        puts("0"); return ;
    }
    cout << b - a << "\n";
}

int main() {
    int k;
    while(cin>>k, k) solve(k);
    return 0;
}

Measured memory_bytes: 3008
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const int MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

typedef struct {
    int to;
    ll cost;
} edge;

int main() {
    int N;
    cin >> N;
    vector<edge> tree[N];
    rep(i, N-1){
        int a,b,c;
        cin >> a >> b >> c;
        a--; b--;
        tree[a].push_back({b, c});
        tree[b].push_back({a, c});
    }
    int Q, K;
    cin >> Q >> K;
    K--;
    stack<edge> s;
    s.push({K, 0});
    ll depth[N];
    rep(i, N) depth[i] = -1;
    while(!s.empty()){
        edge from = s.top();
        s.pop();
        depth[from.to] = (ll)from.cost;
        for(auto &to : tree[from.to]){
            if(depth[to.to] == -1) s.push({to.to, to.cost + from.cost});
        }
    }
    rep(i, Q){
        int x, y;
        cin >> x >> y;
        x--, y--;
        cout << depth[x] + depth[y] << endl;
    }

    return 0;
}

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

using namespace std;
#define PI              3.1415926536

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod 1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define REP(i,n) for(i=0;i<n;i++)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

bool f(int x, int y)
{
	return x > y;
}
void c_p_c()
{
#ifndef  ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int n, m;
int a[100][100];
int vis[100][100];
int x;
int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
bool safe(int x, int y)
{
	return (x >= 0 && y >= 0 && x < n && y < m && vis[x][y] == 0 && a[x][y] == 1);
}
void dfs(int i, int j)
{
	x++;

	vis[i][j] = 1;
	int k;
	for (k = 0; k < 8; k++)
	{
		int p = i + dx[k];
		int q = j + dy[k];
		if (safe(p, q) )
			dfs(p, q);
	}


}

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

	int sum = 0;
	for (i = 1; i < n; i++)
	{
		if (a[i] < a[i - 1])
		{
			sum += (a[i - 1] - a[i]);
			a[i] = a[i - 1];

		}
	}
	cout << sum;

}





Measured memory_bytes: 5192
A = gets.chomp.to_i
B = gets.chomp.to_i
C = gets.chomp.to_i
x = gets.chomp.to_i

ans = 0
(0..A).each do |a|
  (0..B).each do |b|
    (0..C).each do |c|
      total = 500*a + 100*b + 50*c
      ans += 1 if total == x
    end
  end
end

puts ans

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

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

constexpr ll LNF = 1e15;

constexpr int INF = 1e9+7;

vector<int> dx = {-1,0,1,0,-1,1,-1,1};
vector<int> dy = {0,-1,0,1,1,-1,-1,1};

/* template */


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,m,v,p;
    cin >> n >> m >> v >> p;
    vector<ll> a(n);
    rep(i,0,n) cin >> a[i];
    sort(rall(a));
    auto is_ok = [&](const int index){
        ll base = a[index]+m;
        int c = 0;
        rep(i,0,n){
            if(a[i]>base) c++;
            else break;
        }
        if(c>=p){
            return false;
        }
        ll x = 0;
        int count = 0;
        rep(i,0,n){
            if(i==index) continue;
            if(count<p-1){
                count++;
                x += m;
                continue;
            }
            if(a[i]<=base){
                x += min(base-a[i],m);
            }
        }
        debug(x,m*(v-1));
        if(x>=m*(v-1)) return true;
        return false;
    };
    int ng = -1;
    int ok = a.size();
    while(abs(ok-ng)>1){
        int mid = (ok+ng)/2;
        debug(mid);
        if(is_ok(mid)) ng = mid;
        else ok = mid;
    }
    cout << ok << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
 
#define FOR(i, x, n) for(ll i = x; i < n; i++) 
#define pb push_back
#define pf push_front
#define ll long long
#define hii cout << "hii" << endl
#define pii pair<int, int>
#define pll pair<ll, ll>
#define int ll
#define mpp make_pair
#define endl '\n'
#define ff first 
#define ss second
#define vi vector<int>
#define all(s) s.begin(), s.end()
#define si size()
 
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; } 
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE
 
 
const int N = 5e5 + 5;
const int MAXN = 1e5 + 5;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int INF = 1e15;
const int LG = 21;

int pow(int a, int b, int m)
{
	int ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}

void solve() 
{
	int n;
	cin >> n;
	int cnt = 0;
	while(n)
	{
		cnt += (n % 10 == 7);
		n /= 10;
	}
	if(cnt)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
}

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

	    int t = 1;
	    // cin >> t;
	while(t--)solve();
	return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define arrprint(v,n) rep(i,0,n-1)cout << v[i] << " ";cout << endl;
#define matprint(v,n,m) rep(i,0,n-1){rep(j,0,m-1){cout << v[i][j] << " ";}cout << endl;}
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    string s;
    cin >> s;
    int n = sz(s);
    string ans = "Yes";
    rep(i,0,(n-1)/2){
        if(s[i] != s[n-1-i])ans = "No";
    }
    rep(i,0,(n-1)/2-1){
        if(s[i] != s[(n-1)/2-1-i])ans = "No";
    }
    rep(i,0,n-(n+3)/2){
        if(s[(n+3)/2-1 + i] != s[n-1-i])ans = "No";
    }

    cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 256
/*

I will just keep trying.I know can do it.And I will!!. 

 
   PPPPPPPP    UU      UU     CCCCCCCC    CCCCCCCC     HH     HH     UU      UU
   PP    PP    UU      UU     CC          CC           HH     HH     UU      UU
   PP    PP    UU      UU     CC          CC           HHHHHHHHH     UU      UU
   PPPPPPPP    UU      UU     CC          CC           HHHHHHHHH     UU      UU
   PP          UU      UU     CC          CC           HH     HH     UU      UU
   PP          UUUUUUUUUU     CCCCCCCC    CCCCCCCC     HH     HH     UUUUUUUUUU
  

*/
   
   
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
typedef long long ll;
#define loop(i,n)  for(int i=0;i<n;i++)
#define ford(i,a,b) for(int i=b;i>=a;i--)
#define read(a) int a; cin >>a;
#define readarr(a,n) int a[n] ; for(int i=0;i<n;i++) cin >> a[i];
#define readmat(a,n,m) int a[n][m]; for(int i=0;i<n;i++) for(j=0;j<m;j++) cin >> a[i][j];
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define pi pair<int,int>
#define vii vector<vector<int>>
#define sti set<int>
#define vpi vector<pair<int,int>>
#define print(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
#define printmat(a,n,m) for(int i=0;i<n;i++) {for(j=0;j<m;j++) cout<<a[i][j]<<" "; cout<<endl;}
#define fast ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define endl "\n"
#define mp make_pair
const ll inf = 1e18;
const ll mod = 1e9 + 7;
 
signed main()
{
 
    fast;
    int w,s;
    cin >>s>>w;
    if(w>=s) cout<<"unsafe"<<endl;
    else
    cout<<"safe"<<endl;
    return 0;
}

Measured memory_bytes: 3636
/// However long the night,
///     The dawn will break
/// ICPC next year

#include<bits/stdc++.h>
using namespace std ;
const int N = 1e5+5 ;

long long a ,b ,c ,d ,lcm ;
long long solve(long long x){
    long long ret = x ;
    ret -= x/c ;
    ret -= x/d ;
    ret += x/lcm ;
    return ret;
}
int main(){
    cin >> a >> b >> c >> d ;
    lcm = c/__gcd(c,d)*d ;
    cout << solve(b) - solve(a-1) ;
    return 0;
}


Measured memory_bytes: 256
a,b = map(int,input().split())
if a/0.08 == a//0.08:
    emin = a//0.08
else:
    emin = a//0.08+1
if (a+1)/0.08 == (a+1)//0.08:
    emax = (a+1)//0.08-1
else:
    emax = (a+1)//0.08
tmin = b/0.1
tmax = (b+1)/0.1-1
if tmax >= emax:
    if tmin <= emax:
        print(int(tmin))
    else:
        print(-1)
else:
    if emin <= tmax:
        print(int(emin))
    else:
        print(-1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main() {
  int A, B;
  cin >> A >> B;
  int ans = 0;
  int count = 1;
  while (count < B) {
    ans++;
    count = count - 1 + A;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#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 _GLIBCXX_DEBUG

int main() {
    using vi = vector<int>;
    
    long long a = 100;
    long long count = 0;
    long long x;
    cin >> x;
    while(a<x){
        count++;
        a*=1.01;
    }
    cout << count << endl;
}

Measured memory_bytes: 3636
A = input()

A = A.split()

N = int(A[0])
X = int(A[1])

L = input()
L = list(map(int,L.split()))

D = 0
count = 1
for i in range(N):
    D = L[i] + D
    if D <= X:
        count = count + 1

print(count)


Measured memory_bytes: 3060
import java.util.Scanner;
 
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  int N = sc.nextInt();
  int M = sc.nextInt();
  int X = sc.nextInt();
   int[] Narray = new int[N+1];
  int to0 =0;
  int toN =0;
  for(int i=0;i<M;i++){
 int tmp = sc.nextInt(); 
    Narray[tmp]=1;
  }  
  for(int i=0;i<X;i++){
  to0 += Narray[i];
  }
   for(int i=N;i>X;i--){
  toN += Narray[i];
  }
  if(to0>toN)
    System.out.print(toN);
  else
    System.out.print(to0);
}
}

Measured memory_bytes: 21844
d, n = map(int, input().split())

if d == 0:
    if n <= 99:
        print(n)
    else:
        print(101)
elif d == 1:
    if n <= 99:
        print(n*100)
    else:
        print(10100)
elif d == 2:
    if n <= 99:
        print(n*10000)
    else:
        print(1010000)

Measured memory_bytes: 9140
#include <stdio.h>
int binarySearch(int,int,int);

int num[100000];
int main()
{
  int n,q,x,i,j;
  int cnt=0;

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

  scanf("%d",&q);
  for(i=0;i<q;i++) {
    scanf("%d",&x);
    if(binarySearch(0,n,x)) cnt++;
  }
  printf("%d\n",cnt);

  return 0;
}

int binarySearch(int l,int r,int q){
  int m=(l+r)/2;
  if(num[m]==q) return 1;
  else if(l==m || r==m) return 0;
  else if(num[m] < q) return binarySearch(m,r,q);
  else return binarySearch(l,m,q);
}



Measured memory_bytes: 2120
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <unordered_map>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k>0){
        if(k%2==1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k/=2;
    }
    return ans;
}
ll inv(ll a){
	return powmod(a, MOD-2);
}
int main()
{
	int n;
	cin>>n;
  int d[301];
  bool same=1;
  for(int i=1; i<=n; i++){
    cin>>d[i]; d[i]--;
    if(d[i]!=1) same=0;
  }
  	ll f[301]; f[0]=1;
	for(ll i=1; i<=n; i++) f[i]=f[i-1]*i%MOD;
	ll invf[301];
	invf[n]=inv(f[n]);
	for(ll i=n-1; i>=0; i--) invf[i]=invf[i+1]*(i+1)%MOD;
  if(same){
    cout<<f[n-1]*500000004%MOD<<endl;
    return 0;
  }
  ll dp[301][301][301]={};
  dp[0][0][0]=1;
  for(int i=1; i<=n; i++){
    for(int j=0; j<=n; j++){
      for(int k=0; k<=i; k++){
        dp[i][j][k]=dp[i-1][j][k];
        if(j>=d[i] && k>0){
          dp[i][j][k]+=(dp[i-1][j-d[i]][k-1]*(ll)d[i]);
          dp[i][j][k]%=MOD;
        }
      }
    }
  }
  ll p=1;
  for(int i=1; i<=n; i++){
    p=p*invf[d[i]]%MOD;
  }
  ll ans=0;
  for(ll i=3; i<=n; i++){
    for(ll j=3; j<i; j++){
      ans+=(dp[n][i][j]*p%MOD*(i-j)%MOD*f[j-1]%MOD*f[n-j-1]%MOD*500000004%MOD);
      ans%=MOD;
    }
  }
  cout<<ans<<endl;
	return 0;
}

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

int main()
{
    int n;
    cin >> n;
    int ans = 0;
    map<pair<int, int>, int> fl;
    for (int i = 1; i <= n; i++)
    {
        int f = -1, l = i % 10;
        for (int j = 10;; j *= 10)
        {
            if (i >= 10)
                f = i / j;
            else
                f = i;
            if (f < 10)
                break;
        }
        ans += fl[make_pair(l, f)] * 2;
        if (f == l)
            ans += 1;
        fl[make_pair(f, l)]++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3624
#include <iostream>

using namespace std;
#define FOR(i,n) for(i=0;i<n;++i)
#define DEBG(s) cout<<s<<endl;
int i,j,a,b,c;

int main(void){
    int n,m;
    cin>>n;
    int t[n];
    FOR(i,n)cin>>t[i];
    cin>>m;
    int p[m],x[m];
    FOR(i,m)cin>>p[i]>>x[i];
    int total=0;
    FOR(i,n){
        total+=t[i];
    }
    FOR(i,m){
        cout<<total-t[p[i]-1]+x[i]<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define taskname "A"
#define pb push_back
#define mp make_pair
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
const int maxn = 1e6 + 5;
const int logn = log2(maxn) + 1;
const int mod = 1e9 + 7;
int f[maxn];
int g[maxn];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if(fopen(taskname".INP", "r")) {
        freopen(taskname".INP", "r", stdin);
        freopen(taskname".OUT", "w", stdout);
    }
    int n;cin >> n;
    int sum = n;
    f[n] = n;
    for(int i = n - 1 ; i >= 1 ; --i){
        f[i] = (sum - f[i + 2] + i + (i != n - 1) + (ll)(n - 1) * (n - 1)) % mod;
        if(f[i] < 0)f[i] += mod;
        sum += f[i];
        if(sum >= mod)sum -= mod;
    }
    cout << f[1];
}


Measured memory_bytes: 6144
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll n,m,p;
  cin >> n >> m >> p;
  vector<vector<vector<ll>>> G(n);
  for(int i=0;i<m;i++){
    ll a,b,c;
    cin >> a >> b >>c;
    G[a-1].push_back({b-1,c-p});
  }

  bool ikerukadouka[n]={};//各ノードに対して、そこからゴールまで行けるかどうかを確認
  vector<ll> d(n,-1);
  queue<int> que;
  bool korerukadouka[n]={};//各ノードに対して、スタートからそこまで行けるかどうかを確認
  for(int i=0;i<n;i++){
    que.push(i);
    d=vector<ll>(n,-1);
    d[i]=0;

    while(!que.empty()){
      int v=que.front();
      que.pop();

      for(int i=0;i<G[v].size();i++){
        if(d[G[v][i][0]]==-1){
          d[G[v][i][0]]=d[v]+1;
          que.push(G[v][i][0]);
        }
      }
    }
    if(d[n-1]>=0)ikerukadouka[i]=true;
    if(i==0){
      for(int j=0;j<n;j++)if(d[j]>=0)korerukadouka[j]=true;
    }
  }

  bool mugenkadouka=false;

  vector<ll> dist(n,-inf);
  dist[0] = 0; // 開始点の距離は0
  for (int i = 0; i < n; i++) {
    for (int v = 0; v < n; v++) {
      for (int k = 0; k < G[v].size(); k++) {
        vector<ll> e = G[v][k];
        if (dist[v] != -inf && dist[e[0]] < dist[v] + e[1]) {
          dist[e[0]] = dist[v] + e[1];
          if (i == n - 1 && ikerukadouka[v]==true && korerukadouka[v]==true) mugenkadouka=true; // n回目にも更新があるなら負の閉路が存在
        }
      }
    }
  }

  if(mugenkadouka)cout << -1 << endl;
  else cout << max(dist[n-1],(ll) 0) << endl;


}

Measured memory_bytes: 4088
import sys
n = int(input())
a = list(map(int,input().split()))
M = 10**18
a.sort(reverse=True)
ans = 1
if a[-1]==0:
    print(0)
else:
    for i in range(n):
        ans *= a[i]
        if ans >M:
            print(-1)
            sys.exit()
    print(ans)

Measured memory_bytes: 21728
N = int(input())
A = list(map(int, input().split()))

idx = 1
ans = 0
length = len(A)
lis = []
for a in A:
  if a == idx:
    lis.append(idx)
    idx += 1
    continue
  else:
    ans += 1
    length -= 1

if lis != [] and lis == list(range(1, length+1)):
  print(ans)
else:
  print(-1)
    

Measured memory_bytes: 32540
#include <iostream>
#include <vector>
#include <climits>

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> v(n), dp(n, INT_MAX);
    for (int i = 0; i < n; ++i)cin >> v[i];
    if (n == 1) {
        printf("0\n");
    } else {
        dp[0] = 0;
        for (int t = 1; 1 - t >= 0 && t <= k; ++t) {
            dp[1] = abs(v[1] - v[1 - t]);
        }
        for (int t = 1; 2 - t >= 0 && t <= k; ++t)
            dp[2] = min(dp[2], dp[2 - t] + abs(v[2] - v[2 - t]));
        for (int i = 3; i < n; ++i) {
            for (int t = 1; i - t >= 0 && t <= k; ++t)
                dp[i] = min(dp[i], dp[i - t] + abs(v[i] - v[i - t]));
        }
        printf("%d\n", dp[n - 1]);
    }
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
const double PI = acos(-1);
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;

//map<string>a
class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% mod + mod) % mod) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint & a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator-=(const mint & a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator*=(const  mint & a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint & a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint & a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint & a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint & a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint & a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream & os, const mint & m) {
		os << m.x;
		return os;
	}
};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
//組み合わせ
void recursive_comb(vector<int> indexes, int s, int rest, std::function<void(vector<int>)> f) {
	if (rest == 0) {
		f(indexes);
	}
	else {
		if (s < 0) return;
		recursive_comb(indexes, s - 1, rest, f);
		indexes[rest - 1] = s;
		recursive_comb(indexes, s - 1, rest - 1, f);
	}
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(vector<int>)> f) {
	vector<int>indexes(k);
	recursive_comb(indexes, n - 1, k, f);
}

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

int main() {
	ll N, K;
	cin >> N >> K;

	ll ans = 0;
	vector<int>h(N);
	rep(i, N){
		cin >> h[i];
	if (h[i] >= K) {
		ans++;
	}
}
	cout << ans;
}


Measured memory_bytes: 3152
#include <stdio.h>

int main(int argc, const char * argv[])
{
    int max,min,temp,i;
    double sum;
    
    scanf("%d",&i);
    scanf("%d",&temp);
    max=temp;
    min=temp;
    sum=temp;
    i=i-1;
    for( ;i > 0;i -= 1){
        scanf("%d",&temp);
        if(temp>max){
            max=temp;
        }
        if(temp<min){
            min=temp;
        }
        sum+=temp;
    }
    
    printf("%d %d %.f\n",min,max,sum);
    
    return 0;
}

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

#define ll long long

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    ll a;
    string s;
    cin>>a>>s;
    if(a>=3200)
        cout<<s;
    else
        cout<<"red";
    
    
    
	return 0;
}

Measured memory_bytes: 256