akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FOR(i) for(cin>>i;i>0;i--)
#define elif else if
#define pb push_back
#define ll long long
#define mp make_pair
#define all(x) x.begin(),x.end()
#define re(x) {cout<<x<<endl;return 0;}
//#define x first
//#define y second

using namespace std;
int m,n,a[105],num=0,cnt=0;
int main()
{
	cin>>n>>m;
	rep(i,n)
	{
		cin>>a[i];
		num+=a[i];
	}
	rep(i,n) if(a[i]*4*m>=num) cnt++;
	if(cnt>=m) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CompetitiveProgCsLib
{
	class MainProg
	{
		static string R => Console.ReadLine();
		static int RI => int.Parse(R);
		static double RD => double.Parse(R);
		static int[] RIs => R.Split(' ').Select(int.Parse).ToArray();
		static double[] RDs => R.Split(' ').Select(double.Parse).ToArray();
		static void Out(object obj) => Console.WriteLine(obj);
		static void OutLine<T>(IEnumerable<T> obj, string separateChar) => Out(String.Join(separateChar, obj));
		static void Outb(bool b) => Out(b ? "Yes" : "No");
		static void OutB(bool b) => Out(b ? "YES" : "NO");
		static bool IsIn(int y, int x, int h, int w) => 0 <= x && x < w && 0 <= y && y < h;
		static T MIN<T>(params T[] args) => args.Min();
		static T MAX<T>(params T[] args) => args.Max();

		static void Main(string[] args)
		{
			var na = RIs;
			var n = na[0];
			var a = na[1];
			var b = na[2];
			var max = Math.Min(a, b);
			if(a + b <= n)
			{
				Out(max + " 0");
			}
			else
			{
				Out(max + " " + (a + b - n));
			}
			
		}
	}
}


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

int main(){

    int m, n;
    int a[10000];
    int sum = 0;

    cin >> n >> m;
    for(int i = 0; i < m; i++){
        cin >> a[i];
        sum += a[i];
    }
    n -= sum;

    if(n < 0){
        cout << -1;
    }else{
        cout << n;
    }

    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cctype>
#include <functional>
using namespace std;
using ll = long long;

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end(),greater<int>());

    int ans = 0;
    rep(i,n){
        if(i % 2==0) ans += a[i];
        else ans -= a[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n , m = map(int,input().split())
p = [(1,1,1),(1,1,-1),(1,-1,1),(1,-1,-1),(-1,1,1),(-1,1,-1),(-1,-1,1),(-1,-1,-1)]
cake = [list(map(int,input().split())) for i in range(n)]
ans = 0
for a , b , c in p:
    cou = []
    for x , y , z in cake:
        cou.append(x*a+y*b+z*c)
    cou.sort(reverse=True)
    ans = max(ans,sum(cou[:m]))
print(ans)

Measured memory_bytes: 9284
import sys

def solve():
   m,n = map(int,raw_input().split())
   d = [ [int(c) for c in raw_input().split()] for i in range(m)]
   print max([sum(d[i]) for i in range(m)]) 
   
    
                            
if __name__ == "__main__":
    solve()
   
   

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

int gcd(int a,int b)
{
    while (b != 0) {
        int rest = a % b;
        a = b;
        b = rest;
    }
    return a;
}

int main()
{
    int a, b;
    cin >> a >> b;

    cout << gcd(a, b) << endl;

    return 0;
}

Measured memory_bytes: 1164
N = int(raw_input())
A = map(int, raw_input().split())

counter = 0
while True:
  ischanged = False
  for i in xrange(1, N):
    if A[N-i] < A[N-i-1]:
      tmp = A[N-i]
      A[N-i] = A[N-i-1]
      A[N-i-1] = tmp
      counter += 1
      ischanged = True
  if ischanged == False:
    break
print " ".join(map(str, A))
print counter

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

// Template Headers {{{
using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long; using vll = vector<long long>;
template <class T> using min_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> istream &operator>>(istream &, vector<T> &);
template <class T> ostream &operator<<(ostream &, const vector<T> &);
template <class T, class U> istream &operator>>(istream &, pair<T, U> &);
template <class T, class U> ostream &operator<<(ostream &, const pair<T, U> &);
template <class T> struct Inf { static constexpr T inf() { return std::numeric_limits<T>::has_infinity() ? std::numeric_limits<T>::infinty() : std::numeric_limits<T>::max(); } };
template <> struct Inf<int> { static constexpr int inf() { return 0x3f3f3f3f; } };
template <> struct Inf<long long> { static constexpr long long inf() { return 0x3f3f3f3f3f3f3f3fLL; } };
constexpr int INF = Inf<int>::inf(); constexpr ll BINF = Inf<ll>::inf();
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// }}}

int solve() {
	int n, m; cin >> n >> m;
	vvi g(n);
	for (int i = 0; i < m; i++) {
		int u, v; cin >> u >> v;
		g[u].push_back(v); g[v].push_back(u);
	}
	int timer = 0;
	vi stTime(n, INF), enTime(n, INF);
	vi low(n);
	vpii ans;
	function<void(int, int)> dfs = [&] (int u, int p) {
		stTime[u] = timer++;
		low[u] = stTime[u];
		for (int v : g[u]) {
			if (v == p) continue;
			if (stTime[v] >= INF) {
				// tree edge
				dfs(v, u);
				low[u] = min(low[u], low[v]);
				if (low[v] > stTime[u]) ans.emplace_back(u, v);
			} else if (enTime[v] >= INF) {
				// back edge
				low[u] = min(low[u], stTime[v]);
			}
		}
		enTime[u] = timer;
	};
	dfs(0, -1);
	for (auto &p : ans) if (p.first > p.second) swap(p.first, p.second);
	sort(ans.begin(), ans.end());
	for (auto p : ans) cout << p << endl;
	return 0;
}

// Template Main {{{
int main() {
	ios::sync_with_stdio(0);
	// precompute();
	// int t; cin >> t; for (int i=1;i<=t;i++)
	solve();
	// cout << "Case #" << i << ": ", solve();
	return 0;
}

template <class T> istream &operator>>(istream &is, vector<T> &v) {
	for (auto it=v.begin();it!=v.end();++it) is >> *it;
	return is;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
	for (auto it=v.begin();it!=v.end();) os << *it, os << " \n"[++it==v.end()];
	return os;
}

template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) {
	return is >> p.first >> p.second;
}

template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) {
	return os << p.first << ' ' << p.second;
}
// }}}

// vim: fdm=marker


Measured memory_bytes: 4612
#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define ld long double
#define hell 998244353
#define hell1 1000000006
#define pb push_back
#define x first
#define y second
#define MAXL 100005
#define pll pair<ll,ll>
#define pii pair<int,int>
#define L LLONG_MAX
#define all(v) (v).begin(),(v).end()
#define tcFile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
using namespace std;
//vector<int>prime(15000005,0);
ll mM(ll a,ll b,ll p=hell){ll res = 0;if(a>=p)a %= p;while(b){if (b & 1ll)res = (res + a);if(res>=p) res%= p;a = (2 * a); if(a>=p)a%=p;b >>= 1ll;}return res;}
ll fpow(ll x,ll y,ll p=hell){if(x>=p)x=x%p;ll res=1;while(y){if(y&1ll)res*=x;if(res<0)res+=p;if(res>=p)res%=p;y=y>>1ll;x*=x;if(x<0)x+=p;if(x>=p)x%=p;}return res;}
ll inv(ll n,ll p=hell){return fpow(n,p-2,p);}
ll modmul(ll x,ll y,ll p = hell){if(x<0)x+=p;if(x>=p)x%=p;if(y<0)y+=p;if(y>=p)y%=p;return (x*y)%p;}
ll modadd(ll x,ll y,ll p = hell){if(x<0)x+=p;if(x>=p)x%=p;if(y<0)y+=p;if(y>=p)y%=p;ll temp=x+y;if(temp>=p)temp%=p;return temp;}
/*void sieve(){
    prime[0] = -1;
    prime[1] = 0;
    for(int i=2;i<=15000000;i++)
        if(!prime[i])
            for(int j=i;j<=15000000;j+=i)
            	if(!prime[j])
            		prime[j] = i;
}*/
int main(){
	ios
	int t = 1,tc = 0;
	//cin >> t;
	while(t--){
		string s, p;
		cin >> s >> p;
		ll dp[s.size()+1][p.size()+1];
		for (int i = 0; i <= s.size(); i++)
			for (int j = 0; j <= p.size(); j++)
				if (i == 0 || j == 0)
					dp[i][j] = 0;
				else if (s[i-1] == p[j-1])
					dp[i][j] = dp[i-1][j-1] + 1;
				else
					dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
		string ans = "";
		int i = s.size(), j = p.size();
		while ( i>=1 && j>=1) {
			if (s[i-1] == p[j-1]) {
				ans += s[i-1];
				i--;
				j--;
			} else if (dp[i-1][j] > dp[i][j-1])
				i--;
			else if (dp[i-1][j] < dp[i][j-1])
				j--;
			else
				j--;
		}
		reverse(all(ans));
		cout << ans << "\n";
	}
}


Measured memory_bytes: 73984
#include <iostream>
using namespace std;
int main (){
    int N,A,B,souwa,SUM;
    cin >> N >> A >> B;
    souwa=0;
    SUM=0;
    for (int i=1;i<=N;i++){
        souwa=0;
        int x=i;
        while (x>0){
            souwa += x % 10;
            x = x / 10;
        }
        if(souwa<=B && souwa>=A){
            SUM+=i;
        }
    }
    cout << SUM;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define p(s) cout<<(s)<<endl
#define REP(i,n,N) for(int i=n;i<N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=n;i--)
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const int inf = 1e9;

string s,t;
int main(){
    cin>>s;
    t=s;
    string ans = "YES";
    RREP(i,4,t.size()+1){
        if(i>=5&&(t.substr(i-5,5)=="dream"||t.substr(i-5,5)=="erase")){
            i-=4;
        }
        else if(i>=7&&t.substr(i-7,7)=="dreamer"){
            i-=6;
        }else if(i>=6&&t.substr(i-6,6)=="eraser"){
            i-=5;
        }else{
            ans="NO";
            break;
        }
    }
    p(ans);
    return 0;
}

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

int main(){
	int n,k;
	cin >> n >> k;
	int a=1;
	for(int i=0;i<n;i++){
		if(a*2 < a+k){
			a=a*2;
		} else {
			a=a+k;
		}
	}
	cout << a << 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 FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    ll a, b, k;
    cin >> a >> b >> k;
    if (k <= a) cout << a - k << " " << b << endl;
    else if (a + b < k) cout << 0 << " " << 0 << endl;
    else cout << 0 << " " << b - (k - a) << endl;
    
    return 0;
}



Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
public:
  ll *fac,*finv,*inv;
//public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

ll gcd(ll x,ll y){
  if(x%y == 0) return y;
  else return gcd(y,x%y);
}

void dfs(int k,string sub,int n){
  if(sub.length() == n){
    cout << sub << endl;
    return;
  }
  for(int i=0;i<k;i++){
    char temp = 'a'+i;
    if(i != k-1){
      dfs(k,sub+temp,n);
    }
    else{
      dfs(k+1,sub+temp,n);
    }
  }
  return;
}
int main(){
  int n;
  cin >> n;
  dfs(1,"",n);
  return 0;

}


Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <ctype.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;

int main() {
	vector<int>vec1(5);
	rep(i, 5) {
		cin >> vec1[i];
	}
	vector<int>vec2(5);
	for (int i = 0; i < 5; i++) {
		int A = 0;
		if (vec1[i] % 10 != 0) {
			A = 10 - (vec1[i] % 10);
		}
		vec2[i] = vec1[i] + A;
	}

	int sumA = 0;
	rep(i, 5) {
		sumA = sumA + vec2[i];
	}

	vector<int>vec3(5);
	for (int i = 0; i < 5; i++) {
		if (vec1[i] % 10 != 0) {
			vec3[i] = 10 - (vec1[i] % 10);
		}
	}

	vector<int>vec4(5);
	for (int i = 0; i < 5; i++) {
		vec4[i] = sumA - vec3[i];

	}
	sort(vec4.begin(), vec4.end());

	cout << vec4[0] << endl;
}

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

using lint = long long;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<vector<T>>;
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define repu(i, a, b, s) for(int i = int(a); i < int(b); i += int(s))
#define repd(i, a, b, s) for(int i = int(a); i > int(b); i += int(s))
#define endl "\n"
constexpr lint INF = 2e18;
constexpr lint MOD = 1e9 + 7;

lint test[120 * 1024 * 1024];
lint grid[10000][10000];
lint dp[3001][3001][4];

void solve() {
    lint R, C, K;
    cin >> R >> C >> K;

    rep(i, R) {
        rep(j, C) { grid[i][j] = -1; }
    }

    rep(i, K) {
        lint r, c, v;
        cin >> r >> c >> v;
        r--;
        c--;
        grid[r][c] = v;
    }

    rep(y, R) {
        rep(x, C) {
            rep(i, 4) { dp[y][x][i] = 0; }
        }
    }

    if(grid[0][0] != -1)
        dp[0][0][1] = grid[0][0];

    rep(y, R) {
        rep(x, C) {

            // 選ばない
            if(0 <= y - 1) {
                rep(i, 4) { dp[y][x][0] = max(dp[y][x][0], dp[y - 1][x][i]); }
            }
            if(0 <= x - 1) {
                rep(i, 4) { dp[y][x][i] = max(dp[y][x][i], dp[y][x - 1][i]); }
            }

            // 選ぶ
            if(grid[y][x] != -1) {
                if(0 <= y - 1) {
                    rep(i, 4) {
                        dp[y][x][1] =
                            max(dp[y][x][1], dp[y - 1][x][i] + grid[y][x]);
                    }
                }
            }
            if(0 <= x - 1) {
                repu(i, 1, 4, 1) {
                    dp[y][x][i] =
                        max(dp[y][x][i], dp[y][x - 1][i - 1] + grid[y][x]);
                }
            }
        }
    }

    lint ans = -INF;
    rep(i, 4) { ans = max(ans, dp[R - 1][C - 1][i]); }
    cout << ans << endl;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 366976
#include <stdio.h>

int main(void)
{
 int i,j,n,u,k,v;
 int Adj[101][101]={};

 scanf("%d",&n);

 for(i=0;i<n;i++){

   scanf("%d%d",&u,&k);

   for(j=0;j<k;j++){

     scanf("%d",&v);

     Adj[u][v]=1;

   }
 }

 for(i=1;i<=n;i++){
   for(j=1;j<n;j++){
     printf("%d ",Adj[i][j]);
   }
   printf("%d\n",Adj[i][n]);
 }

 return 0;
}

Measured memory_bytes: 1888
#include<stdio.h>
main(){
  int n,i,j,max,sosu[60000];
  while(scanf("%d",&n)!=EOF){
    for(i=0;i<=n;i++)sosu[i]=0;
    max=0;
  for(i=2;i<=n;i++){
    if(sosu[i]==0){
      if(i!=n)max=i;
    for(j=2;i*j<=60000;j++){
      sosu[i*j]=1;
    }
    }
  }
  printf("%d ",max);
  for(i=n+1;;i++){
    if(sosu[i]!=1){
      printf("%d\n",i);
      break;
    }
  }
  }
  return 0;
}

Measured memory_bytes: 828
i = gets.chomp.split(' ')
h = i[0].to_i
w = i[1].to_i
k = i[2].to_i
temp = ans = 0
s = readlines.map{|line| line.chomp.split('')}
#bit全探索
# 1:赤色に塗る = 削除とする
(1<<h).times{ |is|					#2行の場合Yes/Noで4パターン
	(1<<w).times{ |js|				#3列の場合Yes/Noで8パターン
		temp = 0;
		h.times{ |i|
			w.times{ |j|
				if(is>>i&1 == 1)	#削除した行はカウントしない
					next
				end
				if(js>>j&1 == 1)	#削除した列はカウントしない
					next
				end
				if(s[i][j] == '#')
					temp += 1
				end
			}
		}
		if(temp == k)
			ans += 1
		end
	}
}
puts ans


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

int main(){
  char b;
  cin >> b;
  switch(b){
      case'A':cout << 'T' << endl;break;
      case'T':cout << 'A' << endl;break;
      case'G':cout << 'C' << endl;break;
      case'C':cout << 'G' << endl;break;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<algorithm>

int N,H;
int a_max=0;
int b_sum=0,b_amo=0;
std::priority_queue<int> pq;
void input(void){
	int m1,m2;
	std::scanf("%d%d",&N,&H);
	for(int l1=0;l1<N;l1++){
		std::scanf("%d %d",&m1,&m2);
		if(a_max<m1) a_max=m1;
		pq.push(m2);
	}

	
}
void fight(void){
	int answer=0;
	while(H>0 && !pq.empty() && a_max<pq.top()){
		H-=pq.top();
		pq.pop();
		answer++;
	}
	if(H>0){
		if(H%a_max==0) answer+=H/a_max;
		else answer+=H/a_max+1;
	}
	std::cout <<answer<<std::endl;
}
int main(void){
	input();
	fight();
	return 0;
}


Measured memory_bytes: 892
#include <iostream>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
//const int MAX=;

int main(){
	int N,K;
	cin>>N>>K;
	cout<<(N-1)*(K-1);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  string T ="keyence";
  for(int i = 0; i <T.size(); i++){//keyofscienceの時i=3で！
    if(S.at(i)!=T.at(i)){
      for(int j = 0; j<T.size()-i;j++){//0<=j<4
      if(S.at(S.size()-j-1)!=T.at(6-j)){
        cout << "NO" << endl;
        return 0;
      }
    }
    }
  }
  cout << "YES" << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
 string S;
  cin >>S;
  ll x=S.size();
  vector<char> vec(x);
  rep(i,x) {
    if(i%2==0) {
vec.at(i)='0';
    }
    else if(i%2!=0) {
vec.at(i)='1';
    }
  }
  
  vector<char> vecto(x);
  rep(i,x) {
    if(i%2==0) {
vecto.at(i)='1';
    }
    else if(i%2!=0) {
vecto.at(i)='0';
    }
  }
  
  ll count1=0;
  ll count2=0;
  rep(i,x) {
    if(S.at(i)!=vec.at(i)) {
      count1++;
    }
    if(S.at(i)!=vecto.at(i)) {
      count2++;
    }
  }
  
  ll z=min(count1, count2) ;
  cout<<z<<endl;
}
  


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

typedef long long ll;
const int maxn=1e5+10,mod=1e9+7;
int n,a[maxn],cnt[maxn];
int dfsclock,dfn[maxn],low[maxn],stk[maxn],top,scccnt,scc[maxn],size[maxn];
ll ans,fac[maxn],inv[maxn],f[maxn],pow2[maxn];
int type[maxn],weight[maxn];
vector<int> g[maxn];

inline ll qpow(ll a,ll n){
	ll res=1;
	while(n){
		if(n&1ll)
			res=res*a%mod;
		a=a*a%mod;
		n>>=1;
	}
	return res;
}
inline void init(){
	fac[0]=1;for(int i=1;i<maxn;++i)fac[i]=fac[i-1]*i%mod;
	inv[maxn-1]=qpow(fac[maxn-1],mod-2);for(int i=maxn-1;i;--i)inv[i-1]=inv[i]*i%mod;
	f[0]=1;for(int i=1;i<maxn;++i)f[i]=f[i-1]*(2*i-1)%mod;
	pow2[0]=1;for(int i=1;i<maxn;++i)pow2[i]=pow2[i-1]*2%mod;
}
void dfs(int pos){
	dfn[pos]=low[pos]=++dfsclock;
	stk[++top]=pos;
	if(!dfn[a[pos]]){
		dfs(a[pos]);
		low[pos]=min(low[pos],low[a[pos]]);
	}
	else if(!scc[a[pos]])
		low[pos]=min(low[pos],dfn[a[pos]]);
	if(dfn[pos]<=low[pos]){
		++scccnt;
		do{
			scc[stk[top]]=scccnt;
			++size[scccnt];
		}
		while(stk[top--]!=pos);
	}
}

int main(){
	init();
	cin>>n;
	for(int i=1;i<=n;++i)
		cin>>a[i];
	for(int i=1;i<=n;++i)
		if(!dfn[i])
			dfs(i);
	for(int i=1;i<=n;++i)
		if(scc[a[i]]==scc[i])
			type[scc[i]]=1;
		else
			g[a[i]].push_back(i),weight[scc[a[i]]]=true;
	for(int i=1;i<=n;++i)
		if(g[i].size()>1){
			puts("0");
			return 0;
		}
	for(int i=1;i<=scccnt;++i)
		if(type[i]==1){
			if(weight[i])
				type[i]=2;
			else
				++cnt[size[i]];
		}
	ans=1;
	for(int i=1;i<=n;++i)
		if(type[scc[i]]==2){
			type[scc[i]]=0;
			static int ring[maxn];
			int len;ll tmp=1;
			ring[len=1]=i;
			for(int p=a[i];p!=i;p=a[p])
				ring[++len]=p;
			for(int j=1;j<=len;++j)
				if(g[ring[j]].size()){
					int p=ring[j],val=0;
					while(g[p].size())
						++val,p=g[p][0];
					int nxt=1;
					for(int k=j==1?len:j-1;g[ring[k]].empty();k=k==1?len:k-1)
						++nxt;
					if(nxt>val)
						tmp=tmp*2%mod;
					if(nxt<val){
						puts("0");
						return 0;
					}
				}
			ans=ans*tmp%mod;
		}
	for(int i=1;i<=n;++i)
		if((i&1)&&i>1){
			ll tmp=0;
			for(int j=0;2*j<=cnt[i];++j)
				tmp=(tmp+fac[cnt[i]]*inv[2*j]%mod*inv[cnt[i]-2*j]%mod*f[j]%mod*qpow(i,j)%mod*pow2[cnt[i]-2*j])%mod;
			ans=ans*tmp%mod;
		}
		else{
			ll tmp=0;
			for(int j=0;2*j<=cnt[i];++j)
				tmp=(tmp+fac[cnt[i]]*inv[2*j]%mod*inv[cnt[i]-2*j]%mod*f[j]%mod*qpow(i,j))%mod;
			ans=ans*tmp%mod;
		}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

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


int main(void){

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

	vector<int> p(N);
	REP(i,Q){
		int A; cin >> A;
		p[--A]++;
	}
	
	int ans = 0;
	REP(i,N){
		if(p[i] + K > Q) cout << "Yes" << endl;
		else cout << "No" << endl;
	}

	return 0;

}


Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdbool.h>
#include<math.h>
#include<sstream>
#include<math.h>
#include<vector>
#include<functional>
#include<queue>
#include<utility>
#include<bitset>
typedef long long ll;
#define N (1000000000+7)
#define INF 1e10
using namespace std;
typedef pair<ll, ll> P;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

ll west[300010], east[300010];

int main(void){
	ll n;
	string s;
	cin >> n >> s;
	if (s[0] == 'W')west[0]++;
	else east[0]++;
	for (ll i = 1;i < s.length();i++) {
		if (s[i] == 'W') {
			west[i] = west[i - 1] + 1;
			east[i] = east[i - 1];
		}
		else {
			west[i] = west[i - 1];
			east[i] = east[i - 1] + 1;
		}
	}
	ll ans = east[n - 1] - east[0];
	for (ll i = 1;i < s.length();i++) {
		ans = min(ans, west[i - 1] + east[n - 1] - east[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5380
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i <= (n); i++)
#define repi(i,a,b) for (int i = (a); i < (b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;

int main() {
  int A, B;
  cin >> A >> B;
  
  if (A+B <= 9) {
    cout << A+B << endl;
  }
  else {
    cout << "error" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main (){
	char huruf1[1000];
	char huruf2[1000];
	char huruf3[1000];
	scanf ("%[^,],%[^,],%[^\n]", huruf1, huruf2, huruf3); getchar();
	printf ("%s %s %s\n",huruf1,huruf2,huruf3);
}

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

using namespace std;

typedef long long ll;

#ifdef iq
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

int main() {
#ifdef iq
  freopen("a.in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int r = 0, g = 0, b = 0, rg = 0, rb = 0, gb = 0;
  ll ans = 1;
  for (int i = 0; i < (int) s.size(); i++) {
    if (s[i] == 'R') {
      if (gb) {
        ans *= gb;
        gb--;
      } else {
        if (g) {
          ans *= g;
          g--;
          rg++;
        } else if (b) {
          ans *= b;
          b--;
          rb++;
        } else {
          r++;
        }
      }
    } else if (s[i] == 'G') {
      if (rb) {
        ans *= rb;
        rb--;
      } else {
        if (b) {
          ans *= b;
          b--;
          gb++;
        } else if (r) {
          ans *= r;
          r--;
          rg++;
        } else {
          g++;
        }
      }
    } else {
      if (rg) {
        ans *= rg;
        rg--;
      } else {
        if (g) {
          ans *= g;
          g--;
          gb++;
        } else if (r) {
          ans *= r;
          r--;
          rb++;
        } else {
          b++;
        }
      }
    }
    ans %= 998244353;
  }
  for (int i = 1; i <= n; i++) {
    ans *= i;
    ans %= 998244353;
  }
  cout << ans << '\n';
}


Measured memory_bytes: 720
N = int(input())
L = input().split()
 
 
def mult():
    if "0" in L:
        return 0
    else:
        a = 1
        for i in L:
            a = a * int(i)
            if a > 1000000000000000000:
                return -1
        return a
 
print(mult())

Measured memory_bytes: 19156
#include <iostream>
#define MAX 7
using namespace std;

void copy_matrix(int m, int n, char src[][MAX], char dest[][MAX]) {
  	for(int i=0; i<m; ++i) {
      	for(int j=0; j<n; ++j) {
          	dest[i][j]=src[i][j];
        }
    }
}
void color_matrix(int r, int s, int m, int n, char matrix[][MAX]) {
  	for(int i=0; i<m; ++i) {
    	if(r&(1<<i)) {
          	for(int j=0; j<n; ++j) {
              	matrix[i][j] = '$';
            }
        }
    }
    for(int j=0; j<n; ++j) {
      if(s&(1<<j)) {
          	for(int i=0; i<m; ++i) {
              	matrix[i][j] = '$';
            }
        }
    }
}
bool check(int m, int n, int k, char matrix[][MAX]) {
  	int count=0;
  	for(int i=0; i<m; ++i) {
      	for(int j=0; j<n; ++j) {
          	if(matrix[i][j]=='#')
              	count++;
        }
    }
  	return count==k?true:false;
}
void print_matrix(char matrix[][MAX], int m, int n) {
  	for(int i=0; i<m; ++i) {
      	for(int j=0; j<n; ++j) {
          	cout<<matrix[i][j]<<" ";
        }
      	cout<<endl;
    }
}

int main() {
	int m, n, k, count=0;
  	char matrix[MAX][MAX];
  	char c_matrix[MAX][MAX];
  	cin>>m>>n>>k;
  	for(int i=0; i<m; ++i) {
      	for(int j=0; j<n; ++j) {
          	cin>>matrix[i][j];
        }
    }
  	for(int i=0; i<(1<<m); ++i) {
    	for(int j=0; j<(1<<n); ++j) {
        	copy_matrix(m,n,matrix,c_matrix);
          	//print_matrix(c_matrix,m,n);
          	//cout<<"********************"<<endl;
          	color_matrix(i,j,m,n,c_matrix);
          	//print_matrix(c_matrix,m,n);
          	//cout<<"********************"<<endl;
          	if(check(m,n,k,c_matrix)) {
              	count++;
              	//cout<<"count: "<<count<<endl;
            }
        }
    }
    cout<<count;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N; cin>>N;
  vi A(N);
  rep(i,0,N) cin>>A[i];
  vi B(N);
  rep(i,0,N) B[A[i]-1]=i;
  set<int> s;
  s.insert(N);
  s.insert(-1);
  int ans=0;
  REP(o,1,N){
    int i=N-o;
    int X=B[i];
    auto itr=s.lower_bound(X);
    int P=*itr;
    int Q;
    if(P==N) Q=N;
    else{
      itr++;
      Q=*itr;
      itr--;
    }
    itr--;
    int R=*itr;
    int S;
    if(R==-1) S=-1;
    else{
      itr--;
      S=*itr;
    }
    ans+=(i+1)*((Q-P)*(X-R)+(R-S)*(P-X));
    s.insert(X);
  }
  cout<<ans<<endl;
  }



Measured memory_bytes: 6528
from heapq import heappush, heappop
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
    N, T, R = map(int, readline().split())
    if N == T == R == 0:
        return False
    S = [None]*N
    TS = [None]*N
    for i in range(N):
        s = readline().strip()
        S[i] = s
        prv, x0, y0 = map(int, readline().split())
        r = []
        while prv != T:
            t, vx, vy = map(int, readline().split())
            r.append((prv, t, x0, y0, vx, vy))
            x0 += vx*(t - prv); y0 += vy*(t - prv)
            prv = t
        TS[i] = r
    INF = 10**18
    que = [(0, 0)]
    dist = [INF]*N
    dist[0] = 0
    while que:
        cost, v = heappop(que)
        if cost - dist[v] > 1e-6:
            continue
        k0 = 0
        T1 = TS[v]
        while 1:
            t0, t1, x0, y0, vx, vy = T1[k0]
            if t0 <= cost <= t1:
                break
            k0 += 1
        for w in range(N):
            if v == w or dist[w] < cost:
                continue
            k1 = k0
            k2 = 0
            T2 = TS[w]
            while 1:
                t0, t1, x0, y0, vx, vy = T2[k2]
                if t0 <= cost <= t1:
                    break
                k2 += 1
            while 1:
                p0, p1, x0, y0, vx0, vy0 = T1[k1]
                q0, q1, x1, y1, vx1, vy1 = T2[k2]
                t0 = max(p0, q0, cost); t1 = min(p1, q1)
                if dist[w] <= t0:
                    break
                a0 = (vx0 - vx1)
                a1 = (x0 - p0*vx0) - (x1 - q0*vx1)
                b0 = (vy0 - vy1)
                b1 = (y0 - p0*vy0) - (y1 - q0*vy1)
                A = a0**2 + b0**2
                B = 2*(a0*a1 + b0*b1)
                C = a1**2 + b1**2 - R**2
                if A == 0:
                    assert B == 0
                    if C <= 0:
                        e = t0
                        if e < dist[w]:
                            dist[w] = e
                            heappush(que, (e, w))
                        break
                else:
                    D = B**2 - 4*A*C
                    if D >= 0:
                        s0 = (-B - D**.5) / (2*A)
                        s1 = (-B + D**.5) / (2*A)
                        if t0 <= s1 and s0 <= t1:
                            e = max(t0, s0)
                            if e < dist[w]:
                                dist[w] = e
                                heappush(que, (e, w))
                            break
                if p1 < q1:
                    k1 += 1
                elif p1 > q1:
                    k2 += 1
                elif p1 == T:
                    break
                else:
                    k1 += 1; k2 += 1
    ans = []
    for i in range(N):
        if dist[i] < INF:
            ans.append(S[i])
    ans.sort()
    for e in ans:
        write("%s\n" % e)
    return True
while solve():
    ...


Measured memory_bytes: 6508
#include<iostream>
 #include<string>
 
 using namespace std;
 
 int expression();
 int term();
 int factor();
 
 string exp;
 int p;
 
 int expression(){
     int value = term();
     while( exp[p] == '+' || exp[p] == '-' ){
         if ( exp[p] == '+' ) { p++; value += term(); }
         else { p++; value -= term(); }
     }
     return value;
 }
 
 int term(){
     int value = factor();
     while( exp[p] == '*' || exp[p] == '/' ){
         if ( exp[p] == '*' ) { p++; value *= factor(); }
         else { p++; value /= factor(); }
     }
     return value;
 }
 
 int factor(){
     int value = 0;
     if ( exp[p] == '(' ){
         p++; value = expression(); p++;
     } else {
         while( isdigit(exp[p]) ) { value = value*10 + exp[p++] - '0';}
     }
     return value;
 }
 
 int main(){
     int tcase; cin >> tcase;
     for ( int i = 0; i < tcase; i++ ){
         cin >> exp;
         p = 0;
         cout << expression() << endl;
     }
     return 0;
 }

Measured memory_bytes: 0
///*
#include<iostream>
#include<algorithm>
using namespace std;

int main() {

	int *nx, *my;
	int n, m, x, y;
	cin >> n >> m >> x >> y;
	
	nx = new int[n + 1];
	my = new int[m + 1];


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

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

	nx[n] = x;
	my[m] = y;
	
	sort(nx, nx + n + 1);
	sort(my, my + m + 1);

	if (nx[n] < my[0]) {
		cout << "No War" << endl;
	}
	else {
		cout << "War" << endl;
	}

	delete nx;
	delete my;

	return 0;
}
//*/

Measured memory_bytes: 256
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;

void main() {
    int[] buf = readln.chomp.split.to!(int[]);
    int n = buf[0], k = buf[1];
    int[] arr = readln.chomp.split.to!(int[]);

    int ans = 0;
    n -= 1;
    while (n > 0) {
        n -= k - 1;
        ans++;
    }

    writeln(ans);
}

Measured memory_bytes: 4160
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>

using namespace std;

bool check_shit(long long a) {
    int flag_3 = 0, flag_5 = 0, flag_7 = 0;
    while (a) {
        if (a % 10 == 3)flag_3 = 1;
        else if (a % 10 == 5)flag_5 = 1;
        else if (a % 10 == 7)flag_7 = 1;
        a /= 10;
    }
    if (flag_3 && flag_5 && flag_7)
        return true;
    else
        return false;
}

void shigosan(long long &N, long long m,int &ans) {
    //cout << "m=" << m << endl;
    if (N >= m * 10 + 3) {
        if (check_shit(m * 10 + 3))
            ans++;
        shigosan(N, m * 10 + 3,ans);
    }
    if (N >= m * 10 + 5) {
        if (check_shit(m * 10 + 5))
            ans++;
        shigosan(N, m * 10 + 5,ans);
    }
    if (N >= m * 10 + 7) {
        if (check_shit(m * 10 + 7))
            ans++;
        shigosan(N, m * 10 + 7,ans);
    }
}



int main() {
    long long N;
    cin >> N ;
    
    int ans = 0;
    shigosan(N, 0,ans);
    cout << ans << endl;

}


Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int x = sc.nextInt();
      	int a = sc.nextInt();
      	
      	if(a > x){
        System.out.println("0");
        }
      	else{
        System.out.println("10");
        }
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


int main(){
    int n;
    cin>>n;
    int a[n];
    map<int,int> m;
    rep(i,n){
        cin>>a[i];
        m[a[i]]++;
    }
    for(const auto& x:m){
        if(n%2&&x.first==0){if(x.second!=1){cout<<0<<endl;return 0;}}
        else{if(x.second!=2){cout<<0<<endl;return 0;}}
    }
    ll ans=1;
    for(int i=0;i<(n/2);i++){
        ans=(ans*2)%mod;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3584
a1, b1 = list(map(int, input().split()))
a2, b2 = list(map(int, input().split()))
a3, b3 = list(map(int, input().split()))

freq_dict = {'1': 0, '2': 0, '3': 0, '4': 0}
for value in [a1, b1, a2, b2, a3, b3]:
    freq_dict[str(value)] += 1

# 登場回数が1の要素が2個あるか
# かつ、登場回数が2の要素が2個あるか
freq_2_count = 0
freq_1_count = 0
for value in freq_dict.values():
    if value == 2:
        freq_2_count += 1
    elif value == 1:
        freq_1_count += 1
if freq_1_count == 2 and freq_2_count == 2:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3064
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String Sa = sc.next();
		String Sb = sc.next();
		String Sc = sc.next();
		String flag = "A";
		String result = null;
		List<String> listA = new ArrayList<>(Arrays.asList(Sa.split("")));
		List<String> listB = new ArrayList<>(Arrays.asList(Sb.split("")));
		List<String> listC = new ArrayList<>(Arrays.asList(Sc.split("")));

		do {
			if("A".equals(flag)) {
				if(listA.size() == 0) {
					result = "A";
				} else {
					for(int i = 0; i < listA.size();) {
						if("a".equals(listA.get(i))){
							listA.remove(i);
							continue;
						} else if ("b".equals(listA.get(i))) {
							listA.remove(i);
							flag = "B";
							break;
						} else if ("c".equals(listA.get(i))) {
							listA.remove(i);
							flag = "C";
							break;
						}
					}
				}
			}
			if("B".equals(flag)) {
				if(listB.size() == 0) {
					result = "B";
				} else {
					for(int i = 0; i < listB.size();) {
						if("a".equals(listB.get(i))){
							listB.remove(i);
							flag ="A";
							break;
						} else if ("b".equals(listB.get(i))) {
							listB.remove(i);
							continue;
						} else if ("c".equals(listB.get(i))) {
							listB.remove(i);
							flag = "C";
							break;
						}
					}
				}
			}
			if("C".equals(flag)) {
				if(listC.size() == 0) {
					result = "C";
				} else {
					for(int i = 0; i < listC.size();) {
						if("a".equals(listC.get(i))){
							listC.remove(i);
							flag ="A";
							break;
						} else if ("b".equals(listC.get(i))) {
							listC.remove(i);
							flag = "B";
							break;
						} else if ("c".equals(listC.get(i))) {
							listC.remove(i);
							continue;
						}
					}
				}
			}
		} while(result == null);
		System.out.println(result);
	}
}

Measured memory_bytes: 27128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

VI G[100010];
int reached[100010];
int color[100010];


int main(){
    int n,k;cin>>n>>k;
    rep(i,n-1){
        int a,b;cin>>a>>b;
        --a;--b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    queue<int> Q;
    Q.push(0);
    reached[0]=1;
    color[0]=1;
    while(!Q.empty()){
        int t=Q.front();
        Q.pop();
        int ctr=0;
        rep(i,G[t].size()){
            ++ctr;
            int v=G[t][i];
            if(reached[v]){
                --ctr;continue;
            }
            reached[v]=1;
            color[v]=ctr+2;
            Q.push(v);
        }
    }
    for(auto v:G[0]){
        color[v]--;
    }
    rep(i,n){
        color[i]=k-color[i]+1;
        if(color[i]<0)color[i]=0;
    }
    ll ans=1;
    int m=1e9+7;
    rep(i,n){
        ans*=color[i];
        ans%=m;    
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 7288
from itertools import combinations as comb

z_list = []
for i in range(5):
    z = int(input())
    z_list.append(z)
k = int(input())

z_comb_list = list(comb(z_list, 2))

flag = True
for comb in z_comb_list:
    if abs(comb[0] - comb[1]) > k:
        print(":(")
        flag = False
        break

if flag:
    print("Yay!")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int x, a, b;
    cin >> x >> a >> b;
    if (b - a <= 0)
        cout << "delicious" << endl;
    else if (b - a <= x)
        cout << "safe" << endl;
    else
        cout << "dangerous" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#define MOD 1000000007
using namespace std;
using ull = unsigned long long;

ull fact(ull n){
    ull h[n+1];
    h[0] = 1;
    for(int i = 1; i <= n; ++i){
        h[i] = i * h[i-1] % MOD;
    }
    return h[n];
}

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

    if(N == M){
        ans = 2 * (fact(N) % MOD) * (fact(N) % MOD) % MOD;
    }else if(M - N == 1 || N - M == 1){
        ans = (fact(N) % MOD) * (fact(M) % MOD) % MOD; 
    }else{
        ans = 0;
    }
    
    cout << ans << endl;
    return 0;
}


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

using ll = long long;

void solve(long long N, long long K, std::vector<long long> p){
    sort(p.begin(), p.end());
    ll ans = accumulate(p.begin(), p.begin() + K, 0LL);
    cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> p(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&p[i]);
    }
    solve(N, K, std::move(p));
    return 0;
}


Measured memory_bytes: 3696
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}
ll f[200004];
int a[200000];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    memset(f, 0, sizeof(f));
    int n = gi();
    for (int i = 0; i < n; i++) {
        a[i] = gi();
        f[a[i]]++;
    }
    ll r = 0;
    for (int i = 1; i <= n; i++)
        r += f[i] * (f[i]-1) / 2LL;
    for (int i = 0; i < n; i++) {
        int x = a[i];
        ll s = r;
        s -= f[x] * (f[x]-1) / 2LL;
        s += (f[x]-1) * (f[x]-2) / 2LL;
        cout << s << endl;
    }

    return 0;
}


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

using namespace std;

int main() {
#ifndef ONLINE_JUDGE
    freopen("test.in", "r", stdin);
    freopen("test.out", "w", stdout);
#endif

    int n;
    scanf("%d", &n);
    int ans = n % 1000;
    if (ans) {
        printf("%d\n", 1000 - ans);
        return 0;
    }
    printf("0\n");

    return 0;
}

Measured memory_bytes: 3752
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int main(){
	long long int N, T;
	cin >> N >> T;
	vector<long long int> A(N);
	vector<long long int> D(N);
	for (int i = 0; i < N; i++){
		cin >> A[i];
	}
	long long int max = A[N - 1];
	long long int dmax = 0;
	long long int count = 0;
	for (int i = N - 1; 0 <= i; i--){
		D[i] = max - A[i];
		if (D[i]>dmax){
			dmax = D[i];
			count = 1;
		}
		else if (D[i]==dmax){
			count++;
		}
		if (A[i]>max){
			max = A[i];
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

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

    int N; cin >> N;
    int L; cin >> L;
    int best = 1000000; bool pos = true;
    int sum = 0;
    FOR(i, 1, N+1) {
    	int cur = L+i-1;
    	if (abs(cur) < best) {
    		best = abs(cur);
    		pos = (cur == best);
    	}
    	sum += cur;
    }

    if (!pos) best = -1 * best;
    sum -= best;
    cout << sum << endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by bqi343

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl "\n"
#define int long long
typedef vector<int> vi;
#define all(x) x.begin(),x.end()
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define OO 1e9
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
typedef long long ll;
#define in_range(x, y, r, c) ((x >= 0 && x < r && y >= 0 && y < c))

const double eps=1e-9;
const  int MOD=1e10;
const int N=1e5+9;
const int inf = 1LL<<32;

template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
template <typename T> T exp(T b, T p){T x = 1;while(p){if(p&1)x=(x*b);b=(b*b);p=p>>1;}return x;}
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
int sum[N];
int32_t main() {
    IOS;
string s;
int n,q;
cin>>n>>q;
cin>>s;
    for (int i = 0; i < n-1; ++i) {
      sum[i+1]=sum[i]+(s.substr(i,2)=="AC");
    }
;
    for (int i = 0; i < q; ++i) {
        int l,r;
        cin>>l>>r;
        l--,r--;
        cout<<sum[r]-sum[l]<<endl;
    }
}

Measured memory_bytes: 1872
#!/usr/bin/env python
# coding: utf-8

import math
def ri():
    return int(input())

def rl():
    return list(input().split())

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

def main():
    a, b, c = rli()
    if c - a - b < 0:
        print('No')
        return
    if 4*a*b < (c-a-b)*(c-a-b):
        print('Yes')
    else:
        print('No')



if __name__ == '__main__':
    main()


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

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end

bitset<101010> isp; vector<ll> ps;
void init(int n){
   rep(i,2,n)isp[i]=1; ps.clear();
   rep(i,2,n)if(isp[i]){
      ps.push_back(i);
      for(ll j=1LL*i*i;j<n;j+=i)isp[j]=0;
   }
}

ll calc(ll n){
   ll res=1,d=n;
   for(ll p:ps){
      if(p*p*p>n)break;
      if(n%(p*p)==0){
         res*=p; d/=(p*p);
      }
      else if(n%p==0){
         res*=(p*p); d/=p;
      }
   } return res*d*d;
}

int main(){
   int n; cin>>n; init(100000);
   map<ll,int> mp; int res=0;
   rep(i,0,n){
      ll x; cin>>x;
      for(ll p:ps){
         if(p*p*p>x)break;
         while(x%(p*p*p)==0)x/=(p*p*p);
      }
      if(x==1)res=1; else mp[x]++;
   }
   for(auto p:mp)if(p.second!=0){
      ll x=p.first,y=calc(x);
      if(mp.count(y)){
         res+=max(p.second,mp[y]);
         mp[x]=mp[y]=0;
      }
      else{
         res+=p.second; mp[x]=0;
      }
   }
   cout<<res<<endl;
   return 0;
}

Measured memory_bytes: 8064