akhauriyash/Code-Regression huggingface dataset:
from heapq import nsmallest
from itertools import product


def calc(start, color):
    _n, _tbl, _grids = n, tbl[color], grids
    ret = 0
    for i in range(start, _n - 1, 3):
        j = 0
        while i >= 0:
            # print('calc', start, c, i, j, ret)
            ret += _tbl[_grids[i][j]]
            i -= 1
            j += 1
    for j in range((start + 1 - _n % 3) % 3, _n, 3):
        i = _n - 1
        while j < _n:
            # print('calc', start, c, i, j, ret)
            ret += _tbl[_grids[i][j]]
            i -= 1
            j += 1
    return ret


n, c = map(int, input().split())
tbl = [list(map(int, input().split())) for _ in range(c)]
grids = [list(map(int, input().split())) for _ in range(n)]

tbl = list(zip(*tbl))
for row in grids:
    for i, k in enumerate(row):
        row[i] = k - 1

preliminary = []
for s in range(3):
    preliminary.append(nsmallest(3, ((calc(s, color), color) for color in range(c))))

ans = float('inf')
for (v0, c0), (v1, c1), (v2, c2) in product(*preliminary):
    if c0 == c1 or c1 == c2 or c2 == c0:
        continue
    ans = min(ans, v0 + v1 + v2)
print(ans)


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

int main() {
	int n,count=0;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++)
	cin>>arr[i];
	for(int i=1;i<n-1;i++){
		if((arr[i]>arr[i-1]&&arr[i]<arr[i+1])||(arr[i]<arr[i-1]&&arr[i]>arr[i+1]))
		count++;
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define ll long long
const ll mod=1000000007;
inline int roundup(int a, int b) { return (((a + (b -1)) / b)); }
inline ll powmod(ll x, ll y) {ll res=1; for(ll i=0;i<y;i++){ res=res*x%mod; } return res;}
using namespace std;

signed main(void) {
    bool flag = false;
    int n;
    ll count = 0;
    cin >> n;
    for(int i=1; i<n;++i) {
        for(int j=1;j<i+1;++j) {
            if(i*j < n){
                count++;
            }else{ 
                break;
            }
            if(i != j) count++;
        }
        if(flag == true) break;
    }
    cout << count << '\n';
    return 0;
}

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

using namespace std;

int main()
{
    size_t h, w;
    cin >> h >> w;
    vector<string> field(h);

    for (size_t i = 0; i < h; ++i)
        cin >> field[i];

    for (size_t row = 0; row < h; ++row)
    {
        for (size_t col = 0; col < w; ++col)
        {
            if (field[row][col] == '.')
            {
                size_t bombsCnt = 0;
                const int dRowMin = row > 0 ? -1 : 0;
                const int dRowMax = row < h - 1 ? 1 : 0;
                for (int dRow = dRowMin; dRow <= dRowMax; ++dRow)
                {
                    const int dColMin = col > 0 ? -1 : 0;
                    const int dColMax = col < w - 1 ? 1 : 0;
                    for (int dCol = dColMin; dCol <= dColMax; ++dCol)
                    {
                        if (field[row + dRow][col + dCol] == '#')
                            ++bombsCnt;
                    }
                }
                field[row][col] = '0' + bombsCnt;
            }
        }
    }


    for (size_t row = 0; row < h; ++row)
        cout << field[row] << '\n';

    return 0;
}


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

const int rh_mod = 1e9 + 7;
const int rh_b1 = 1009, rh_b2 = 10007;

class rolling_hash {
	const int n;
	vector<int> r1, r2, h1, h2;
public:
	rolling_hash(const string& s)
		: n(s.size()), r1(n + 1), r2(n + 1), h1(n + 1), h2(n + 1) {
		r1[0] = r2[0] = 1;
		for (int i = 0; i < n; i++) {
			r1[i + 1] = (ull)r1[i] * rh_b1 % rh_mod;
			r2[i + 1] = (ull)r2[i] * rh_b2 % rh_mod;
			h1[i + 1] = ((ull)h1[i] * rh_b1 + s[i]) % rh_mod;
			h2[i + 1] = ((ull)h2[i] * rh_b2 + s[i]) % rh_mod;
		}
	}
	ull get(int l, int r) {
		assert(0 <= l && l <= r && r <= n);
		ull x1 = (h1[r] - (ull)h1[l] * r1[r - l] % rh_mod + rh_mod) % rh_mod;
		ull x2 = (h2[r] - (ull)h2[l] * r2[r - l] % rh_mod + rh_mod) % rh_mod;
		return (x1 << 32LL) | x2;
	}
};

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	string T, P;
	cin >> T >> P;
	int n = T.size(), m = P.size();
	rolling_hash rh(T);
	ull h = rolling_hash(P).get(0, m);
	for (int i = 0; i + m <= n; i++) if (rh.get(i, i + m) == h) {
		printf("%d\n", i);
	}
	return 0;
}



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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()

const int MAX = 3010;
const int MOD = 998244353;

int N, T;
vii ab;

ll dp[MAX][2*MAX]; // dp[n][t] : n個目までの注文を終えていて、t秒までに食べ終わっている最大の満足度

int solve() {
    sort(ALL(ab));
    REP (i, N) {
        REP (t, T+1) dp[i+1][t] = dp[i][t];
        REP (t, T+1) {
            dp[i+1][t+ab[i].first] = max(dp[i+1][t+ab[i].first], dp[i][t]+ab[i].second);
        }
    }

    ll ans = 0;
    REP (i, N) {
        ans = max(ans, dp[i][T-1] + ab[i].second);
    }
    return ans;
}

int main() {
    cin >> N >> T;
    ab = vii(N);
    REP (i, N) {
        int a, b; cin >> a >> b;
        ab[i] = MP(a,b);
    }
    cout << solve() << endl;
}

Measured memory_bytes: 141568
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>

using namespace std;

char get(void) {
    const int sz = 1000000000 + 1;
    static char buf[sz];
    static char *S = buf;
    static char *T = buf;

    if (S == T) {
        T = (S = buf) + fread(buf, 1, sz, stdin);
        if (S == T) return EOF;
    }

    return *S++;
}

template<class T> void fr(T &x)
{
    char c;
    int s = 0;
    x = 0;

    c = get();

    if (c == '-') s = 1;
    else if ('0' <= c && c <= '9')  x = c - '0';

    while (true)
    {
        c = get();

        if (c < '0' || c > '9') break;
        x = x * 10 + (c - '0');
    }

    if (s) x = -x;
}

int main()
{
    int N, T;
    fr(N);
    fr(T);

    int bk, t;
    fr(t);
    bk = t;

    long long int overlap = 0LL;

    for (int i = 1; i < N; i++)
    {
        fr(t);

        int dif = T - (t - bk);

        overlap = dif < 0 ? overlap : overlap + dif;

        bk = t;
    }

    printf("%lld\n", (long long int)N * T - overlap);
    return 0;
}


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

struct UnionFind {
  vector<int> d;
  UnionFind(int n = 0) : d(n, -1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -d[find(x)]; }
};

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

  UnionFind uf(n);

  rep(i, m) {
    int a, b;
    cin >> a >> b;
    uf.unite(--a, --b);
  }

  int res = 0;

  rep(i, n) res = max(res, uf.size(i));

  cout << res << endl;
  return 0;
}


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

using namespace std;

int main() {
    vector <int> vec(3);
    cin >> vec[0] >> vec[1] >> vec[2];
    sort(vec.begin(),vec.end());
    cout << vec[1]-vec[0] + vec[2]-vec[1] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <queue>
#include <list>
#include <map>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;

class Matching{
  typedef vector<vector<int> > G;

  vector<bool> visited;

  const G &g; //g[i][j] = k <==> i is connected to k
  int n;      //number of node
  int m;      //number of left node

  bool augment(int left) {
    if (left < 0)
      return true;
    if (visited[left])
      return false;
    visited[left] = true;
    REP(i, g[left].size()) {
      int right = g[left][i];
      if (augment(matching[right])) {
        matching[right] = left;
        return true;
      }
    }
    return false;
  }

public:
  vector<int> matching;

  explicit Matching(const G &graph, int mm)
    : g(graph), m(mm){
    n = graph.size();
  }

  int solve() {
    int matches = 0;
    matching = vector<int>(n,-1);
    visited  = vector<bool>(n);
    REP(left, m) {
      visited.assign(n, false);
      if (augment(left))
        matches++;
    }
    return matches;
  }
};

int solve(const vector<int> &x){
  const int n = x.size();
  vector<vector<int> > g(n + n);
  REP(i,n) REP(j,n) if(i != j)
    if(x[i] % x[j] == 0)
      g[i].push_back(n + j);
  return n - Matching(g, n).solve();
}

int main(){
  int n = getInt();
  vector<int> x(n);
  map<int, int> memo;
  REP(i,n) memo[x[i] = getInt()] = i + 1;

  int num = solve(x);
  vector<int> ans;


  while(x.size()){
    list<int> tmp(x.begin(), x.end());

    int xx = x[0];
    // printf("xx : %d ... ", xx);
    for(list<int>::iterator it = tmp.begin();
	it != tmp.end();){
      if(*it % xx == 0 || xx % *it == 0) it = tmp.erase(it);
      else it++;
    }

    if(solve(vector<int>(tmp.begin(), tmp.end())) == num - 1){
      x = vector<int>(tmp.begin(), tmp.end());
      ans.push_back(memo[xx]);
      num--;
      // puts("ok");
    }else{
      x = vector<int>(x.begin() + 1, x.end());
      // puts("bad");
    }
  }

  REP(i,ans.size()) printf("%d%c", ans[i], i == ans.size() - 1 ? '\n' : ' ');

  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b % mod; if (a >= mod) a -= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12); // debuged
    int T;
    T = 1;
    while (T--) solve();
}

void solve() {
    int n;
    cin >> n;
    if (n < 1200) cout << "ABC" << endl;
    else if (n < 2800) cout << "ARC" << endl;
    else cout << "AGC" << endl;
}



Measured memory_bytes: 3608
def abc077c_snuke_festival():
    import bisect
    n = int(input())
    a = sorted(list(map(int, input().split())))
    b = sorted(list(map(int, input().split())))
    c = sorted(list(map(int, input().split())))
    total = 0
    for i in range(n):
        b_size = b[i]
        j = bisect.bisect_left(a, b_size)
        j = n - j
        k = bisect.bisect_right(c, b_size)

        total += (n - j) * (n - k)
    print(total)


abc077c_snuke_festival()

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

int main()
{
    string s, S = "abcdefghijklmnopqrstuvwxyz";
    int a[27] = {};
    while (getline(cin, s))
    {
        for (char c : s)
        {
            if ('a' <= c && c <= 'z')
            {
                a[c - 'a']++;
            }
            else if ('A' <= c && c <= 'Z')
            {
                a[c - 'A']++;
            }
        }
    }
    int i = 0;
    for (int i = 0; i < 26; i++)
    {
        cout << char('a' + i) << " : " << a[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3148
#include<bits/stdc++.h>
using namespace std;
#define MAX 102
int a[MAX];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int n,ans=0;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int j=1;j<=1003;j++){
        bool check=false;
        for(int i=1;i<=n;i++){
            if(check){
                if(a[i]>0){
                    a[i]--;
                }
                else {
                    check=false;
                }
            }
            else {
                if(a[i]>0){
                    a[i]--;
                    ans++;
                    check=true;
                }
                
            }
        }
    }
    cout<<ans;
}

Measured memory_bytes: 256
N=int(input())
F=[[int(i) for i in input().split()] for j in range(N)]
P=[[int(i) for i in input().split()] for j in range(N)]
R=[]
for i in range(1,1024):
    opentime = [i>>k & 1 for k in range(10)]
    R.append(sum([P[shop][sum([i*j for i,j in zip(opentime,F[shop])])] for shop in range(N)]))
print(max(R))

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main()
{
	int A, B,ans=0;
	cin >> A >> B;
	for (int i = A; i <= B; i++)
	{
		if (i / 10000 == i % 10 && ((i / 1000) % 10 == (i / 10) % 10))
			ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for i in range(N):
    S = input()
    if S == "AC":
        ac += 1
    elif S == "WA":
        wa += 1
    elif S == "RE":
        re += 1
    else:
        tle += 1
print("AC x", ac)
print("WA x", wa)
print("TLE x", tle)
print("RE x", re)

Measured memory_bytes: 74800
#!/usr/bin/env python3
import math
def solve(n):
    ans = float('inf')
    for x in range(1, int(math.sqrt(n)) + 3):
        if n % x == 0:
            y = n // x
            ans = min(ans, x + y - 2)
    return ans
print(solve(int(input())))


Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF (long long)1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

vector<string> res(20000);
int cnt;
string s;

void dfs(int n) {
	if(n == 0) {
		res[cnt] = s;
		++cnt;
		return;
	}
	bool ex = false;
	REP(i, s.size()) {
		if(s[i] == 'a' + n) {
			ex = true;
			break;
		}
		if(s[i] == 'a' + (n - 1)) {
			s[i] = 'a' + n;
			dfs(n - 1);
			s[i] = 'a' + (n - 1);
		}
	}
	if(!ex) {
		dfs(n - 1);
	}
}

int main(void) {
	while(true) {
		cin>>s;
		if(s == "#") break;
		cnt = 0;
		dfs(25);
		sort(res.begin(), res.begin() + cnt);
		cout<<cnt<<endl;
		if(cnt <= 10) {
			REP(i, cnt) {
				cout<<res[i]<<endl;
			}
		} else {
			REP(i, 5) {
				cout<<res[i]<<endl;
			}
			REP(i, 5) {
				cout<<res[cnt - 5 + i]<<endl;
			}
		}
	}
}

Measured memory_bytes: 4264
use std::io::Read;

pub fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let k: usize = iter.next().unwrap().parse().unwrap();
    let s = iter.next().unwrap().as_bytes();
    let mut series_nums: Vec<usize> = Vec::new();
    if s[0] == ('0' as u8) {series_nums.push(0)}
    let mut current = s[0];
    let mut acc: usize = 1;
    for i in 1..n {
        if current != s[i] {
            series_nums.push(acc);
            acc = 0;
        }
        current = s[i];
        acc += 1;
    }
    series_nums.push(acc);
    if s[s.len() - 1] == ('0' as u8) {series_nums.push(0)};

    let mut cumsum: Vec<usize> = vec![0;series_nums.len() + 1];
    for i in 0..series_nums.len() {
        cumsum[i+1] = cumsum[i] + series_nums[i];
    }

    let mut ret: usize = 0;
    for left in 0..cumsum.len() {
        if left % 2 == 0 {
            let mut right = left + 2 * k + 1;
            if right >= cumsum.len() {
                right = cumsum.len() - 1;
            }
            ret = std::cmp::max(ret, cumsum[right] - cumsum[left]);
        }
    }
    println!("{}", ret);
}


Measured memory_bytes: 6396
# -*- coding: utf-8 -*-
from itertools import accumulate, product
from operator import itemgetter

def inpl(): return tuple(map(int, input().split()))
N, W = inpl()
I = [inpl() for _ in range(N)]
w1 = I[0][0]
A = {w1 + x: [] for x in range(4)}

for w, v in I:
    A[w].append(v)

for k, v in A.items():
    A[k] = [0] + list(accumulate(sorted(v, reverse=True)))

res = 0
g0 = itemgetter(0)
g1 = itemgetter(1)

for L in product(enumerate(A[w1]),
                 enumerate(A[w1+1]),
                 enumerate(A[w1+2]),
                 enumerate(A[w1+3])):
    if sum([(w1+i)*l for i, l in enumerate(map(g0, L))]) <= W:
        res = max(res, sum(map(g1, L)))

print(res)

Measured memory_bytes: 3188
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

int N, K;
vector<bool> S;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> K;
  S.resize(N, false);
  for (int i = 0; i < K; i++) {
    int d;
    cin >> d;
    for (int j = 0; j < d; j++) {
      int a;
      cin >> a;
      a--;
      S[a] = true;
    }
  }

  int ans = 0;
  for (int i = 0; i < S.size(); i++) {
    if (!S[i]) {
      ans++;
    }
  }

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


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

const int MAX_R = 100100;

int main()
{  
    bool isprime[MAX_R];
    rep(i,MAX_R) isprime[i] = true;

    isprime[0] = isprime[1] = false;
    for(int i=2; i<MAX_R; i++){
        int j = i+i;
        while(j<MAX_R){
            isprime[j] = false;
            j += i;
        }
    }

    int sim2017[MAX_R];
    sim2017[0] = sim2017[1] = sim2017[2] = 0;
    for(int i=3; i<MAX_R; i++){
        if(i%2 == 0) sim2017[i] = sim2017[i-1];
        else{
            if(isprime[i] && isprime[(i+1)/2]){
                sim2017[i] = sim2017[i-1]+1;
            }else{
                sim2017[i] = sim2017[i-1];
            }
        }
    }

    int q; cin >> q;
    rep(_,q){
        int l,r; cin >> l >> r;
        cout << (sim2017[r]-sim2017[l-1]) << endl;
    }
}

Measured memory_bytes: 4004
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e15;
const int mod=1e9+7;
const int M=100005;
int dp[203][203];
 main()

{
    fast
    int n,m,r;
    cin>>n>>m>>r;
    vector<int>vec;
    f(i,1,r)
    {
       int x;
       cin>>x;
       vec.pb(x);
    }
    f(i,1,n)
    {
        f(j,1,n)
        {
            dp[i][j]=inf;
            dp[j][i]=inf;
        }
    }
    f(i,1,m)
    {
        int a,b,c;
        cin>>a>>b>>c;
        dp[a][b]=min(dp[a][b],c);
        dp[b][a]=min(dp[b][a],c);
    }
    f(k,1,n)
    {
        f(i,1,n)
        {
            f(j,1,n)
            {

                if(dp[i][j]>dp[i][k]+dp[k][j])
                {
                    dp[i][j]=dp[i][k]+dp[k][j];
                }
            }
        }
    }
    int ses=inf;
    sort(vec.begin(),vec.end());
    do
    {

      int cost=0;
      for(int i=1;i<r;i++)
      {
          cost+=dp[vec[i]][vec[i-1]];
      }
      ses=min(ses,cost);

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

    cout<<ses<<endl;
    return 0;

}





































Measured memory_bytes: 640
#include<stdio.h>
int main(void)
{
	int	e1,e2,e3,e4;
	scanf("%d %d %d %d",&e1,&e2,&e3,&e4);
	if (e1==e2&&e3==e4) {
		printf("yes\n");
	}
	else if(e1==e3&&e2==e4) {
		printf("yes\n");
	}
	else if(e1==e4&&e2==e3) {
		printf("yes\n");
	}
	else if(e1==e2==e3==e4) {
		printf("yes\n");
	}
	else {
		printf("no\n");
	}
	return 0;
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e;
int main(){
  cin>>a;
  b=a/1000;
  c=a%1000/100;
  d=a%100/10;
  e=a%10;
  if((b==c&&b==d)||(c==d&&c==e))cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n, a;
    cin >> n >> a;

    n %= 500;

    if(a < n) {
        out("No");
    }
    else {
        out("Yes");
    }
    
    re0;
}

Measured memory_bytes: 256
h,w,k=map(int,input().split())
x=[]
for i in range(h):
    l=input()
    l2=[]
    for o in range(len(l)):
        l2.append(l[o])
    x.append(l2)
n=2**(h+w)
ans=0
for i in range(n):
    q=i
    num=[0]*(h+w)
    p=0
    while q>0:
        if q%2!=0:
            num[p]=1
        q=q//2
        p+=1
    cnt=0
    for tat in range(h):
        if num[tat]==0:
            for yok in range(w):
                if num[yok+h]==0  and  x[tat][yok]=="#":
                        cnt+=1
    if cnt==k:
        ans+=1
print(ans)


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

int main()
{
	int N;
	scanf("%d", &N);
	std::vector<int> d(N);
	for (auto& e: d) scanf("%d", &e);
	int sum{};
	for (int i{}; i < N; i++)
		for (int j{i + 1}; j < N; j++)
			sum += d[i] * d[j];
	printf("%d\n", sum);

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int compr(const void *n,const void *m);
int main(){

	int A[5];
	int i;
	scanf("%d %d %d %d %d",A,A+1,A+2,A+3,A+4);
	qsort(A,5,sizeof(int),compr);
	printf("%d %d %d %d %d\n",A[0],A[1],A[2],A[3],A[4]);
	
	return 0;
}

int compr(const void *n,const void *m){

	int a =*(int *)n;
	int b =*(int *)m;

	if(a>b) return -1;
	if(a==b) return 0;
	if(a<b) return 1;



}

Measured memory_bytes: 600
// Last Change: 05/19/2019 22:39:04.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> val(N + 1);
  ll time = 1, cnt = 0;
  for (ll i = N; i >= 1; --i) {
    while (i * time < K) {
      time *= 2;
      ++cnt;
    }
    val[i] = time;
  }

  ll ans = 0;
  for (ll i = N; i >= 1; --i) {
    ans += val[1] / val[i];
  }
  ans *= 1e10;
  ans /= val[1];
  ans /= N;

  double dans = double(ans) / 1e10; // / val[1] / N;
  cout << fixed << setprecision(12) << dans << endl;

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 1024
s = input()
while True:
    # print(s[-6:], s[-7:], s[-5:])
    # print(s[:-6], s[:-7], s[:-5])
    # print(s)
    if len(s) >= 6 and s[-6:] == 'eraser':
        s = s[:-6]
    elif len(s) >= 5 and s[-5:] == 'erase':
        s = s[:-5]
    elif len(s) >= 7 and s[-7:] == 'dreamer':
        s = s[:-7]
    elif len(s) >= 5 and s[-5:] == 'dream':
        s = s[:-5]
    elif len(s) > 0:
        # print('s=', s, ';',s=='erase',s[-5:]=='erase',s[:-5])
        print('NO')
        import sys
        sys.exit()
    else:break
    # except:
    #     print('NO')
    #     import sys
    #     sys.exit()
print('YES')


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

using namespace std;

int main(){
        long long int N,X;
        long long int x[100010],keep[100010];

        cin>>N>>X;
        for(int i=0; i<N; ++i) {
                cin>>x[i];
        }
        x[N]=X;
        sort(x,x+(N+1));

        int num1=abs(x[N]-x[N-1]);
        for(int i=N-2; i>=0; i--){
                int num2=abs(x[i+1]-x[i]);
                if(num1>num2) {
                        int tmp=num1;
                        num1=num2;
                        num2=tmp;;
                }
                int num=num2%num1;
                while(num!=0){
                        num2=num1;
                        num1=num;
                        num=num2%num1;
                }

        }

        cout<<num1<<endl;
        return 0;
}

Measured memory_bytes: 1024
// AOJ ITP2_10_B Bit Operation II
// 2019.3.8 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif

unsigned in()   // 非負整数の入力
{
	unsigned n = 0;
	int c = gc();
	do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void outb(unsigned n)   // 非負整数の2進数表示、最後に改行あり
{
	int i;
	char ob[40];

	i = 0; while (i < 32) ob[i++] = (n & 1) + '0', n >>= 1;
	while (i--) pc(ob[i]);
	pc('\n');
}

int main()
{
	unsigned a, b;

	a = in(), b = in();
	outb(a & b);
	outb(a | b);
	outb(a ^ b);
	return 0;
}


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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100005;

bool ysort(pair<int,int> a,pair<int,int> b){
    if(a.second==b.second) return a.first<b.first;
    return a.second<b.second;
}

int main(){
    
    int N,M;cin>>N>>M;
    vector<pair<int,int>> S(M);
    
    for(int i=0;i<M;i++){
        cin>>S[i].first>>S[i].second;
    }
    
    sort(all(S),ysort);
    
    int cnt=0;
    int now=1;
    for(int i=0;i<M;i++){
        if(S[i].first<now) continue;
        now=S[i].second;
        cnt++;
    }
    
    cout<<cnt<<endl;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(void){
int a,b,i,j,d,c;
c=0;
scanf("%d %d",&a,&b);
for(i=1;i<=12;i++){
   switch(i){
      case 2:
         d=28;break;
      case 4:
      case 6:
      case 9:
      case 11:
         d=30;break;
      default:
         d=31;
   }
   for(j=1;j<=d;j++){
     if(i==j){c++;}
     if(i==a && j==b){break;}
   }
   if(i==a && j==b){break;}
}
printf("%d\n",c);
return 0;
}


Measured memory_bytes: 128
def main():
    n = int(input())
    fs = [list(map(int, input().split())) for _ in range(n)]
    ps = [list(map(int, input().split())) for _ in range(n)]

    res = -(1 << 30)
    for b in range(1, 1 << 10):
        p = 0
        for i in range(n):
            c = 0
            for j in range(10):
                if (b >> j) & 1 and fs[i][j]:
                    c += 1
            p += ps[i][c]
        if res < p:
            res = p

    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()

print(max(map(len, S.split("S"))))


Measured memory_bytes: 9916
#include <iostream>
#include <fstream>
#include <bits/stdc++.h> 
#include <string>

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef priority_queue<int> pqi;
typedef priority_queue<int, vi, greater<int>> mpqi;

#define IOS std::ios::sync_with_stdio(false); cin.tie(0);
#define F0R(i,a) for(int i = 0; i < a; i++)
#define R0F(i,a) for(int i = a - 1; i >= 0; i--)
#define S0RT(a,n) sort(a, a + n)
#define pb push_back
#define mp make_pair

const int MOD = 1000000007;
const ll INF = 1000000000000000000;
const ld PI = 4*atan((ld)1);

/* NOTES TO SELF:
    Int overflow? Use all ll if in doubt.
    Edge cases? (n = 1, n = 0)
*/

int h, n;
int a[100002];

int main(){
    IOS;
    cin >> h >> n;
    F0R(i,n){
        cin >> a[i];
        h -= a[i];
        if(h <= 0){
            cout << "Yes";
            return 0;
        }
    }
    if(h <= 0){
        cout << "Yes";
        return 0;
    }
    else{
        cout << "No";
        return 0;
    }
    return 0;
}

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

int main(){
  ll n,k,num=1;
  cin >> n >> k;
  ll a[n+10];
  rep(i,n)
    cin >> a[i+1];
  unordered_map<ll,ll> mp;
  
  while(true){
    if(mp[num]==2){
      break;
    }
    mp[num]++;
    if(mp[num]==2){
      break;
    }
    num = a[num];
    k--;
    if(k==0){
      cout << num;
      return 0;
    }
  }
  ll tmp=a[num];
  ll l_num=1;
  while(num!=tmp){
    tmp=a[tmp];
    l_num++;
  }
  if(l_num==1){
    cout << num;
    return 0;  
  }
  ll mod = k%l_num;
  ll res=num;
  rep(i,mod)
    res = a[res];
    
  cout << res;
  return 0;
}

Measured memory_bytes: 11880
N=int(input())
count=0
for i in range(9):
  if N%(i+1)==0:
    ans=N//(i+1)
    if ans<10 and ans>0:
      print("Yes")
      break
    else :
      count+=1
  else :
    count+=1
if count==9:
  print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll mod=1000000007;
ll MOD=998244353;
int inf=1000001000;
ll INF=100000000000000000;


int main() {
    string s;
    cin >> s;
    vector<int> a(0);
    int o=1,b=s[0]-'0';
    rep(i,s.size()/2){
        int u=s[2*i]-'0';
        char t=s[2*i+1];
        o*=u;
        if (t=='+') {a.push_back(o);o=1;}
    }
    int r=s[s.size()-1]-'0';
    a.push_back(o*r);
    int ans=0;
    for(int i:a) ans+=i;
    rep(i,s.size()/2){
        int u=s[2*i+2]-'0';
        char t=s[2*i+1];
        if (t=='+') b+=u;
        else b*=u;
    }
    int e;
    cin >> e;
    if (e==ans && e==b) cout << "U" << endl;
    else if (e==ans) cout << "M" << endl;
    else if (e==b) cout << "L" << endl;
    else cout << "I" << endl;
}



Measured memory_bytes: 3204
import java.util.Scanner;
 
public class Main{
  public static void main(String[] args){
    Scanner scanner =  new Scanner(System.in);
    int card[][] = new int[3][3];
    for(int i = 0;i < 3;i++){
      for(int j = 0;j < 3;j++){
        card[i][j] = scanner.nextInt();
      }
    }
    
    int figures[][] = new int[3][3];
    for(int i = 0;i < 3;i++){
      for(int j = 0;j < 3;j++){
        figures[i][j] = 0;
      }
    }
    int N = scanner.nextInt();
    for(int k = 0;k < N;k++){
      int figure = scanner.nextInt();
      for(int i = 0;i < 3;i++){
        for(int j = 0;j < 3;j++){
          if(card[i][j] == figure){
            figures[i][j] = 1;
          }
        }
      }
    }
    
    String bingo = "No";
    if(figures[0][0] == 1){
      if(figures[0][1]== 1){
        if(figures[0][2] == 1){
          bingo = "Yes";
        }
      }
      
      if(figures[1][0] == 1){
        if(figures[2][0] == 1){
          bingo = "Yes";
      	}
      }
      
      if(figures[1][1] == 1){
        if(figures[2][2] == 1){
          bingo = "Yes"; 
      	}
      }
    }
    
    if(figures[0][1] == 1){
      if(figures[1][1] == 1){
        if(figures[1][2] == 1){
          bingo = "Yes"; 
        }
      }
    }
    
    if(figures[0][2] == 1){
        if(figures[1][2] == 1){
          if(figures[2][2] == 1){
            bingo = "Yes";
        }
      }
      if(figures[1][1] == 1){
        if(figures[2][0] == 1){
          bingo = "Yes";
        }
      }
    }
    
    if(figures[2][0] == 1){
      if(figures[2][1] == 1){
        if(figures[2][2] == 1){
          bingo = "Yes";
        }
      }
    }
    
    if(figures[1][0] == 1){
      if(figures[1][1] == 1){
        if(figures[1][2] == 1){
          bingo = "Yes";
        }
      }
    }

    if(figures[2][0] == 1){
      if(figures[2][1] == 1){
        if(figures[2][2] == 1){
          bingo = "Yes";
        }
      }
    }
    System.out.println(bingo);
  }
}

Measured memory_bytes: 23892
N,M=map(int,input().split())
a=[0]
for _ in range(M):
    a.append(int(input()))

b=[]
num=0
if len(a)>1:
    b.append(a[1]-a[0]-1)
    for i in range(1,M):
            b.append(a[i+1]-a[i]-2)
    b.append(N-a[M]-1)
else:
    b.append(N)

num=max(b)


mod=1000000007

def fib(n,num):
    fib=[0 for i in range(num+10)]
    fib[0]=1
    fib[1]=1
    for i in range(2,num+1):
        fib[i]=fib[i-1]+fib[i-2]
    return fib[n]

if -1 in b:
    print(0)
else:
    p=1
    for j in range(M+1):
        p*=fib(b[j],num)
    print(p%mod)

Measured memory_bytes: 460056
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;

public class Main{
	public static void main(String args[]) {
		Scanner sc=new Scanner(System.in);
	int N=sc.nextInt();
	List<String> strList1=new ArrayList<String>();
	for(int i=0;i<N;i++) {
		String S=sc.next();
		strList1.add(S);
	}
	List<String> listB = new ArrayList<String>(new HashSet<>(strList1));
	int len=listB.size();
	System.out.println(len);
	}
}


Measured memory_bytes: 73268
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<cmath>
#include<cstdio>

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

using namespace std;
using ll =long long;
using P = pair<int,int>;

int main(int argc, const char * argv[]) {
    int N;
    string S;
    cin >> N >> S;
    
    int ans=0;
    rep(i, 10){
        rep(j, 10){
            rep(k, 10){
                bool ok1 = false;
                bool ok2 = false;
                bool ok3 = false;
                rep(s, N){
                    int l = stoi(S.substr(s, 1));
                    if(k == l && ok2) ok3 = true;
                    else if(j == l && ok1) ok2 = true;
                    else if(i == l) ok1 = true;
                        
                    if(ok1 && ok2 && ok3){
                        ans+=1;
                        break;
                    }
                }
            }
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>

typedef struct {
    double x;
    double y;
} xy;

int main()
{
    using namespace std;
    double a, b, c, d, e, f, x, y;
    vector<xy> results;
    cout.precision(3);
    cout << fixed << showpoint;
    while (cin >> a >> b >> c >> d >> e >> f) {
        double denom = (b*d - a*e);
        x = (b*f - c*e)/denom;
        y = (c*d - a*f)/denom;
        x = round(x*1000.0)/1000.0;
        y = round(y*1000.0)/1000.0;
        if (x == 0) x = fabs(x);
        if (y == 0) y = fabs(y);
        results.push_back( {x,y} );
    }
    for (vector<xy>::iterator itr = results.begin();
         itr != results.end(); ++itr) {
        cout << itr->x << " " << itr->y << endl;
    }
}

Measured memory_bytes: 1316
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const ll inf = 1e9;
const int MAX_N = 500;

int main() {
    int N; cin >> N;
    int n = N;
    int tmp = 0;
    while (n > 0) {
        tmp += n%10;
        n /= 10;
    }
    if (N % tmp == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <cstdio>

#define abs(a) ((a) < 0 ? -(a) : (a))

int main()
{
  int n;
  scanf("%d", &n);
  long long a[200001] = {0};
  for (int i = 1; i <= n; ++i)
  {
    scanf("%lld", a + i);
    a[i] += a[i - 1];
  }
  long long min = 1e18;
  for (int i = 1; i <= n - 1; ++i)
  {
    if (min > abs(a[n] - 2 * a[i]))
    {
      min = abs(a[n] - 2 * a[i]);
    }
  }
  printf("%lld\n", min);
  return 0;
}


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

int main(){
    int H, W, K;
    vector<vector<char>> S(11,vector<char>(1010));

    cin >> H >> W >> K;
    rep(i,H)rep(j,W) cin >> S[i][j];

    int ans = 1e8;
    rep(bit, 1 << (H-1)){
        bitset<10> bit_now(bit);
        int ans_now = bit_now.count(); 

        vector<int> cut;
        rep(i,10){
            if(bit_now[i]) cut.push_back(i);
        }
        cut.push_back(H-1);


        vector<int> cnt(cut.size(),0);
        int itr_cnt = 0;
        rep(w,W){
            int h=0;
            rep(i,cut.size()){
                while(h <= cut[i]){
                    if(S[h][w] == '1') cnt[i]++;
                    h++;
                }
            }

            rep(i,cut.size()){
                if(cnt[i] > K) {
                    ans_now++;
                    fill(cnt.begin(),cnt.end(),0);
                    w--;
                }
            }
            if(itr_cnt > 3*W) break;
            itr_cnt++;
        }

        ans = min(ans, ans_now);
    }

    cout << ans << endl;


}


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

int main() {
  bool c = false, f = false;
  string s;

  cin >> s;

  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'C') c = true;
    if (c && s[i] == 'F') f = true;
    if (c && f) {
      cout << "Yes";
      return 0;
    }
  }

  cout << "No";

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(){
  
  int d,t,s;
  
  // スペース区切りの整数の入力
  scanf("%d %d %d", &d, &t, &s);
  
  if(d<=t*s) {
    printf("Yes"); 
  }else{
    printf("No");
  }
  
}

Measured memory_bytes: 1736
#include<cstdio>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<fstream>
using namespace std;
int main()
{
	int x,y,z;
	int s,k;
	cin>>k>>s;
	int sum=0;
	for(x=0;x<=k;x++)
	{
		for(y=0;y<=k;y++)
		{
			z=s-x-y;
			if(z>=0&&z<=k)
			{
				sum++;
			}
		}
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
int a[123456], t[123456], n, l, ans=0;
signed main() {
	cin>>n>>l;
	for1(i, n)cin>>a[i];
	for1(i, n){
		if(a[i-1]<a[i]&&a[i]>a[i+1]){
			t[i]=l-a[i];
			int k=i-1;
			while(k>0){
				if(a[k-1]<a[k]&&a[k]<a[k+1]){
					t[k]=t[k+1]+l-a[k];
				}
				else if(a[k-1]>a[k]&&a[k]<a[k+1]){
					t[k]=max(t[k-1],t[k+1])+l-a[k];
					break;
				}
				k--;
			}
			k=i+1;
			while(k<=n){
				if(a[k-1]>a[k]&&a[k]>a[k+1]){
					t[k]=t[k-1]+l-a[k];
				}
				else break;
				k++;
			}
		}
	}
	for1(i, n)ans=max(ans, t[i]);
	cout<<ans<<endl;
}


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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  priority_queue <double> pq;
  double vals[n];
  double total = 0;
  for (int i = 0; i < n; i++) {
    cin >> vals[i];
    total += vals[i];
    pq.push(vals[i]);
  }
  double limit = total / (4.0 * m);

  while (m-- && pq.size() > 0) {
    if (pq.top() < limit) {
      cout << "No\n";
      return 0;
    }
    pq.pop();
  }
  cout << "Yes\n";
  return 0;
}


Measured memory_bytes: 3776
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

n,a,b = nm()
print((n//(a+b))*a + min(a,n%(a+b)))


Measured memory_bytes: 3060
fn main() {
    let v = read_vec::<usize>();
    let _n = v[0];
    let k = v[1];
    let mut ls = read_vec::<i32>();
    ls.sort_by_key(|l| -l);
    let mut sum = 0;
    for i in 0..k {
        sum += ls[i];
    }
    println!("{}", sum);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

int main() {
  int x, y, w = 0, z;
  cin >> x >> y;
  int a[x][y];
  for (int i = 0; i < x; i++) {
    for (int o = 0; o < y; o++) {
      cin >> a[i][o];
    }
  }
  for (int i = 0; i < x; i++) {
    for (int o = 0; o < y; o++) {
      w = w + a[i][o];
      cout << a[i][o] << " ";
    }
    cout << w << endl;
    w = 0;
  } 
  for (int o = 0; o < y; o++) {
    int q = 0;
    for (int i = 0; i < x; i++) {
      q = q + a[i][o];
    }
    cout << q << " ";
    z = z + q;
  }
  cout << z << endl;
}



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

int main(){
  int a[6];
  int d[6] = {0,1,2,3,4,5};
  char r;

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

  int n[6] = {4,0,2,3,5,1};
  int e[6] = {2,1,5,0,4,3};
  int s[6] = {1,5,2,3,0,4};
  int w[6] = {3,1,0,5,4,2};

  while(cin >> r){
    //cout << r << endl;
    if(r=='N'){
      for(int i=0; i<6; i++){
        d[i] = n[d[i]];
      }
    } else if(r=='E'){
      for(int i=0; i<6; i++){
        d[i] = e[d[i]];
      }
    } else if(r=='S'){
      for(int i=0; i<6; i++){
        d[i] = s[d[i]];
      }
    } else if(r=='W'){
      for(int i=0; i<6; i++){
        d[i] = w[d[i]];
      }
    }
  }
  for(int i=0; i<6; i++){
    if(d[i] == 0)cout << a[i] << endl;
  }
}


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

using namespace std;


int W, H, S[1000][1000];

bool check()
{
  vector< int > latte, malta;
  for(int i = 0; i < H; i++) {
    if(S[i][0] == 1) latte.push_back(i);
    else malta.push_back(i);
  }
  if(abs((int) latte.size() - (int) malta.size()) > 1) {
    return (false);
  }
  int t1 = 1, t2 = 0;
  for(int i = 1; i < W; i++) {
    vector< int > beet;
    for(int j = 0; j < H; j++) {
      if(S[j][i] == 1) beet.push_back(j);
    }
    if(beet == latte) ++t1;
    else if(beet == malta) ++t2;
    else return (false);
  }
  return (abs(t1 - t2) <= 1);
}

int main()
{
  scanf("%d %d", &W, &H);
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      scanf("%d", &S[i][j]);
    }
  }

  puts(check() ? "yes" : "no");
}

Measured memory_bytes: 7108
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <math.h>
using namespace std;


int main() {
  
int y,m,d;
char c1, c2;
    cin >> y >> c1 >> m >> c2 >> d;
    cout << (m <= 4 ? "Heisei" : "TBD") << endl;
  
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<math.h>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
ll Mod = 998244353;
//scanf("%d", &a)

int main() {
	int n;
	cin >> n;
	vector<int> d(n);
	rep(i, n) scanf("%d", &d[i]);
	if (d[0] != 0) { 
		cout << 0 << endl; return 0;
	}
	sort(d.begin(), d.end());
	rep2(i, 1, n) {
		if (d[i] == 0|| d[i] - d[i - 1] > 1) { cout << 0 << endl; return 0; }
	}

	ll ans = 1;
	vector<int> s(n, 0);
	int j = 0;
	int count = 1;
	
	rep2(i, 2, n) {
		if (d[i] != d[i - 1]) {
			s[j] = count;
			++j;
			count = 1;
		}
		else count++;
		if (i == n - 1) s[j] = count;
	}
	rep2(i, 1, n) {
		if (s[i] == 0) break;
		//ans = ans *ll(powl(s[i - 1], s[i]))% Mod;
		rep(j, s[i]) {
			ans *= s[i - 1];
			ans %= Mod;
		}
	}
	cout << ans << endl;
}
	

Measured memory_bytes: 1024
/************************
*                       *
* Nothing Is Impossible *
*                       *
************************/
#include <algorithm>
#include <iostream>
#include <fstream>
#include <ctype.h>
#include <string>
#include <vector>
#include <math.h>
#include <cmath>
#include <map>
#define GetRand(Min, Max) ((rand()%(int)(((Max) + 1)-(Min))) + (Min))
#define Rep(i, min, max) for (int i = min; i < max; ++i)
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef long double ld; 
using namespace std;

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

	double a, b;
	cin >> a >> b;
	double ans = a/b;
	printf("%.10f", ans);
	return 0;
}

Measured memory_bytes: 256