akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC optimize ("O3")
//#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	int N, K;
	cin >> N >> K;
	N++;

	int mod = 1e9 + 7;

	ll mae = 0;
	ll ato = 0;

	rep1(i, K - 1) {
		mae += i;
		ato += N - i + 1;
	}
	ll kotae = 0;
	for (int i = K; i <= N; i++) {
		mae += i;
		ato += N - i + 1;
		ll sa = ato - mae + 1;
		sa %= mod;
		kotae += sa;
	}
	co(kotae % mod);


	Would you please return 0;
}

Measured memory_bytes: 3652
#include "bits/stdc++.h"

using namespace std;

#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define se second
#define fi first

typedef long long int ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

const ll inf = 0x3f3f3f3f;
const ll mod = 1e9+7;

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  
    ll n,k; cin>>n>>k;
    vll l,r;
    l.pb(0); r.pb(0);
    for(int i=0;i<n;i++){
    	ll x; cin>>x;
    	if(x>=0) r.pb(x);
    	else l.pb(-1*x);
    }

    sort(all(l));
    sort(all(r));

    int s1=(int)l.size();
    int s2=(int)r.size();

    // for(int i=0;i<s1;i++) cout<<l[i]<<" ";
    // 	cout<<endl;
    // for(int i=0;i<s2;i++) cout<<r[i]<<" ";
    // 	cout<<endl;

    ll best=inf;
    
    for(int i=0;i<=k;i++){
    	if(i>=s1 or (k-i)>=s2) continue;
    	ll val = min( 2*l[i]+r[k-i] , 2*r[k-i]+l[i] );
    	// cout<<"i="<<i<<" val="<<val<<endl;
    	best = min(best,val);
    }

    cout<<best<<endl;

    return 0;
}

Measured memory_bytes: 1656
import re

wordlist = ['maerd', 'remaerd', 'esare', 'resare']

S = input()
Sr = ''
for i in range(len(S)):
    Sr += S[-(i+1)]

temp = ''
while Sr != '':
    if temp == Sr:
        print('NO')
        break
    temp = Sr
    
    for word in wordlist:
        if re.match(word, Sr):
            Sr = Sr[len(word):]
        
else:
    print('YES')

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define rep3(i, s, n) for (int i = s; i > (int)(n); i--)
#define all(obj) obj.begin(), obj.end()
#define db(x) cerr << #x << ":" << x << " "
#define dbl(x) cerr << #x << ":" << x << "\n"
#define dbv(vec) cerr << #vec << ":"; for (auto e : vec) cerr << e << " "; cout << "\n"
#define dbvv(vv) cerr << #vv << ":\n"; for (auto vec : vv) { for (auto e : vec) cerr << e << " "; cerr << endl; }
#define YN(f) cout << (f ? "YES" : "NO") << endl
#define Yn(f) cout << (f ? "Yes" : "No") << endl
#define yn(f) cout << (f ? "yes" : "no") << endl
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

int main() {
	ll a, b, c; cin >> a >> b >> c;
	bool f = (4 * a * b < (c - a - b) * (c - a - b) && c - a - b > 0);
	Yn(f);	
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static long gcd(long a, long b) {
    return b == 0 ? a: gcd(b, a % b);
  }
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = gcd(sc.nextLong(), sc.nextLong());
    int count = 1;
    for (int i = 2; i <= Math.sqrt(n); i++)
      if (n % i == 0) {
        while (n % i == 0)
          n /= i;
        count++;
      }
    System.out.println(count + (n == 1 ? 0 : 1));
  }
}

Measured memory_bytes: 23764
#include<algorithm>
#include<iostream>
#include<cstdio>
#define int long long

using namespace std;

int sum[300005],g1[300005],a[300005],q[300005],h=0,h1[300005];
int n,t1[300005],g[300005],d[300005],sum1[300005],w[300005];

int s(int o) {return o*(o+1)/2;}

bool calc(int o,int p,int q)
{
	return (d[o]-d[p])<q*(o-p);
}

bool calc1(int o,int p,int q)
{
	return (d[q]-d[o])*(o-p)>(d[o]-d[p])*(q-o);
}

void solve(int o,int p)
{
	if(o>p) return;
	if(o==p)
	{
		h1[o]=max(h1[o],g[o-1]+g1[o+1]+1-t1[o]);
		return;
	}
	int mid=(o+p)/2;
	h=0;
	for(int i=o-1;i<=mid;i++)
	{
		d[i]=g[i]+sum[i]+i*(i-1)/2;
		while((h>1)&&calc1(q[h],q[h-1],i)) h--;
		q[++h]=i;
	}
	for(int i=mid+1;i<=p;i++)
	{
		while((h>1)&&calc(q[h],q[h-1],i)) h--;
		w[i]=g1[i+1]+g[q[h]]+s(i-q[h])-sum[i]+sum[q[h]];
	}
	for(int i=p;i>mid;i--)
	{
		h1[i]=max(h1[i],w[i]);
		w[i-1]=max(w[i],w[i-1]);
	}
	h=0;
	for(int i=mid+1;i<=p+1;i++)
	{
		d[i]=g1[i]-sum[i-1]+i*(i+1)/2;
		while((h>1)&&calc1(q[h],q[h-1],i)) h--;
		q[++h]=i;
	}
	for(int i=o;i<=mid;i++)
	{
		while((h>1)&&calc(q[h],q[h-1],i)) h--;
		w[i]=g[i-1]+g1[q[h]]+s(q[h]-i)-sum[q[h]-1]+sum[i-1];
	}
	for(int i=o;i<=mid;i++)
	{
		h1[i]=max(h1[i],w[i]);
		w[i+1]=max(w[i],w[i+1]);
	}
	solve(o,mid);
	solve(mid+1,p);
}

signed main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++) 
	{
		scanf("%lld",&t1[i]);
		sum[i]=sum[i-1]+t1[i];
	}
	sum[n+1]=sum[n];
	q[1]=0;h=1;	
	for(int i=1;i<=n+1;i++)
	{
		while((h>1)&&(calc(q[h],q[h-1],i))) h--;
		g[i]=g[q[h]]+s(i-q[h]-1)+sum[q[h]]-sum[i-1];
		d[i]=g[i]+sum[i]+i*(i+1)/2;
		while((h>1)&&(calc1(q[h],q[h-1],i))) h--;
		q[++h]=i;
	}
	for(int i=1;i<=n/2;i++) swap(t1[i],t1[n-i+1]);
	for(int i=1;i<=n;i++) sum1[i]=sum1[i-1]+t1[i];
	sum1[n+1]=sum1[n];
	q[1]=0;h=1;
	for(int i=1;i<=n+1;i++)
	{
		while((h>1)&&(calc(q[h],q[h-1],i))) h--;
		g1[i]=g1[q[h]]+s(i-q[h]-1)+sum1[q[h]]-sum1[i-1];
		d[i]=g1[i]+sum1[i]+i*(i+1)/2;
		while((h>1)&&(calc1(q[h],q[h-1],i))) h--;
		q[++h]=i;
	}
	for(int i=0;i<=n/2;i++) 
	{
		swap(t1[i],t1[n-i+1]);
		swap(g1[i],g1[n-i+1]);
	}
	for(int i=1;i<=n;i++) h1[i]=-1000000000000000;
	solve(1,n);
	int T;cin>>T;
	while(T--)
	{
		int x,y;scanf("%lld%lld",&x,&y);
		printf("%lld\n",max(g[x]+g1[x],h1[x]+t1[x]-y));
	}
	return 0;
}

Measured memory_bytes: 21888
// Problem : A - ABC Swap
// Contest : AtCoder Beginner Contest 161
// URL : https://atcoder.jp/contests/abc161/tasks/abc161_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//QWsin
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define out(i,u) for(int i=first[u];i!=-1;i=nxt[i])
#define repvc(i,vc) for(int i=0,Sz=vc.size();i<Sz;++i)
using namespace std;
inline int read()
{
	char ch=getchar();int ret=0,f=1;
	while(ch<'0' || ch>'9') {if(ch=='-')f=-1;ch=getchar();}
	for(;ch>='0' && ch<='9';ch=getchar()) ret=ret*10+ch-'0';
	return ret*f;
}

typedef long long ll;
const int INF=1<<30;

int main()
{
	int a,b,c;cin>>a>>b>>c;
	swap(a,b);
	swap(a,c);
	printf("%d %d %d\n",a,b,c);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
int main()
{
	double N=1;
	std::cin >> N;
	double ans1 = 1;
    double ans2 = N;
	double sum = ans1 + ans2 - 2;
	double i = 1;
	double j = 1;

	for (i = 1; i <= sqrt(N); i++) {
		if (fmod(N,i) != 0)continue;
			j=N/i;
			sum = std::min(sum, i + j - 2);
	}

	std::string str;
   printf("%.0f", sum);

	return 0;
	}

Measured memory_bytes: 256
LR = input().split()
L = int(LR[0])
R = int(LR[1])
S = []

if R - L >= 2019:
    print("0")
else:
    for i in range(L,R):
        for j in range(i+1,R+1):
            S.append(i * j % 2019)
    print(min(S))




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

vector <vector <int>> op;
vector <vector <int>> r;
vector <int> h;

int n;

int main (){

	cin >> n;

	op.assign(3,vector <int> (n,0));
	r.assign(3,vector <int> (n,-1));
	h.assign(n,0);

	for (int i=0; i<n; i++) cin >> op[0][i] >> op[1][i] >> op[2][i];

	r[0][0]=op[0][0];
	r[1][0]=op[1][0];
	r[2][0]=op[2][0];

	for (int i=1; i<n; i++){

		r[0][i] = max( r[1][i-1] + op[0][i], r[2][i-1] + op[0][i] );
		r[1][i] = max( r[0][i-1] + op[1][i], r[2][i-1] + op[1][i] );
		r[2][i] = max( r[0][i-1] + op[2][i], r[1][i-1] + op[2][i] );
	}

	cout << max (r[0][n-1], max (r[1][n-1], r[2][n-1])) << endl;

	return 0;
}

Measured memory_bytes: 2940
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

map<ll, ll> nines;

ll calc_nines(ll base) {
  ll tmp = 111111111ll;
  tmp *= base;
  ll count = 0;
  while (true) {
    if (tmp == 9) return count;
    count++;
    ll foo = tmp % 100;
    ll bar = tmp / 100;
    ll foofoo = (foo / 10) + (foo % 10);
    if (foofoo < 10) tmp = bar * 10 + foofoo;
    else tmp = bar * 100 + foofoo;
  }
}

void solve() {
  for (ll i = 1; i <= 9; i++) nines[i] = calc_nines(i);
  ll M;
  cin >> M;
  vector<pair<ll, ll>> dc(M);;
  rep (m, M) {
    ll d, c;
    cin >> d >> c;
    dc[m] = make_pair(d, c);
  }
  ll ans = 0;
  ll current = 0;
  rep (m, M) {
    ll d = dc[m].first;
    ll c = dc[m].second;
    if (m == 0) {
      current = d;
      c--;
      if (c == 0) continue;
    }
    if (d == 0) {
      ans += c;
      continue;
    }
    ll nine_count = c / 9;
    ll nine_rest = c % 9;
    if (current == 0) {
      ans += nine_count * (nines[d] + 1);
    } else {
      ans += nine_count * (nines[d] + 2);
    }
    rep (n, nine_rest) {
      current += d;
      ans ++;
      if (current >= 10) {
        current = (current / 10) + (current % 10);
        ans ++;
      }
    }
  }
  ans = max(0ll, ans);
  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
#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;
 
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
 
    int n;
    cin >> n;
    vector <ll> a(n);
    for (int i=0;i<n;i++)
    cin >> a[i];
 
    ll ans[n];
    ans[0] = 0;
    for (int i=0;i<n;i++)
    {
        ans[0] += a[i];
        if (i % 2 == 1)
        ans[0] -= 2*a[i];
    }
 
    ans[0] = ans[0] / 2;
    for (int i=1;i<n;i++) {
        ans[i] = a[i-1] - ans[i-1];
    }
 
    for (int i=0;i<n;i++) {
        cout << ans[i] * 2 << " ";
    }
 

}

Measured memory_bytes: 2944
n = int(input())
A = list(map(int, input().split()))
cnt = 0
for a in A:
    if a%2 == 0:
        if a%3 == 0 or a%5 == 0:
            cnt = cnt
        else:
            cnt += 1
if cnt != 0:
    print("DENIED")
else:
    print("APPROVED")

Measured memory_bytes: 3060
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
t = 0
f = 0
for x in a:
  if x % 4 == 0: f += 1
  elif x % 2 == 0: t += 1
if N == 1:
  if f: print("Yes")
  else: print("No")
  exit(0)
if N == t:
  print("Yes")
  exit(0)
if -(-(N - max(0, t - 1) - 1) // 2) <= f: print("Yes")
else: print("No")

Measured memory_bytes: 58864
#include <iostream>
#include <string>
using std::cout;
using std::cin;

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


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>

#define FOR(idx, begin, end) for(int idx = (begin); idx < (end); ++idx)
#define DMP(x) cerr << #x << ": " << x << "\n"

using namespace std;
typedef long long lint;
const int MOD = 1000000007;

int main() {

	cin.tie(0);

	int N, M;
	cin >> N >> M;

	vector<bool> visited(N, false);

	vector<int> a(M), b(M);
	FOR(i, 0, M) cin >> a[i] >> b[i];

	vector<vector<bool>> path(N, vector<bool>(N, false));
	FOR(i, 0, M) {
		path[a[i] - 1][b[i] - 1] = true;
		path[b[i] - 1][a[i] - 1] = true;
	}

	int ans = 0;

	queue<pair<int, vector<bool>>> node;
	node.push({0, visited});

	while (!node.empty()) {
		
		auto now = node.front();
		now.second[now.first] = true;
		node.pop();

		FOR(i, 0, N) {
			if (now.second[i] == false && path[now.first][i] == true) {

				node.push({i, now.second});
			}
		}

		FOR(i, 0, N) {

			if (now.second[i] == false) break;
			if (i == N - 1) ans++;
		}
	
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 640
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

//みなさん天才すぎないすか

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline ll getint() {
	ll A = 0;
	if (ci - cn + 24 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}


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


	int N = getint();
	ll kazu[20] = {};
	const int mod = 1e9 + 7;
	const ll m = 1 + (1 << 20) + (1ll << 40);
	//???
	const int hatena = 8;
	rep(i, N / hatena) {
		ll a[hatena];
		rep(j, hatena) a[j] = getint();
		rep(j, 20) {
			rep(k, hatena) kazu[j] += a[k] >> j & m;
		}
	}
	rep(i, N % hatena) {
		ll a = getint();
		rep(j, 20) kazu[j] += a >> j & m;
	}

	ll kotae = 0;
	const ll m2 = (1 << 20) - 1;
	rep(j, 20) {
		ll tmp = (1ll << j) % mod;
		ll tmpk = (kazu[j] & m2);
		tmpk = tmpk * (N - tmpk) % mod;
		kotae += tmp * tmpk % mod;

		tmp = (1ll << (j + 20)) % mod;
		tmpk = (kazu[j] >> 20 & m2);
		tmpk = tmpk * (N - tmpk) % mod;
		kotae += tmp * tmpk % mod;

		tmp = (1ll << (j + 40)) % mod;
		tmpk = (kazu[j] >> 40 & m2);
		tmpk = tmpk * (N - tmpk) % mod;
		kotae += tmp * tmpk % mod;
	}

	printf("%lld", kotae% mod);

	Would you please return 0;
}

Measured memory_bytes: 256
#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 reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = int(1e9) + 7;

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  int diffcnt = 0;
  reps(i, 1, n) {
    int p;
    cin >> p;
    if (p != i) ++diffcnt;
  }

  if (!diffcnt || diffcnt == 2) cout << "YES" << "\n";
  else cout << "NO" << "\n";

  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	scanf("%d", &n);
	int sum = 0;
	for (int i = 0; i < n; i++) {
		int q;
		scanf("%d", &q);
		sum ^= q;
	}
	if (sum == 0)
		puts("Yes");
	else
		puts("No");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003,INF=1<<30;

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

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

int main(){
    
    int N;cin>>N;
    
    if(N==1) cout<<0<<endl;
    else{
        
        vector<pair<ll,ll>> S(N);
        for(int i=0;i<N;i++){
            ll a,b;cin>>a>>b;
            if(a>b) swap(a,b);
            S[i]=make_pair(a,b);
        }
        
        sort(all(S),compare1);
        ll a=S[0].first,b=S[N-1].first;
        
        sort(all(S),compare2);
        ll c=S[0].second,d=S[N-1].second;
        
        ll ans=(b-a)*(d-c);
        
        sort(S.begin(),S.end()-1,compare1);
        
        swap(S[N-1].first,S[N-1].second);
        
        /*for(int i=0;i<N;i++){
            cout<<S[i].first<<" "<<S[i].second<<endl;
        }*/
        
        ll x=S[1].first,y=S[N-2].first,maxi=max({S[0].second,S[N-1].second,y}),mini=min({S[0].second,S[N-1].second});
        ans=min(ans,(d-a)*(maxi-min(mini,x)));
        
        for(int i=1;i<N-1;i++){
            maxi=max(maxi,S[i].second);
            mini=min(mini,S[i].second);
            ans=min(ans,(d-a)*(maxi-min(mini,S[i+1].first)));
        }
        
        cout<<ans<<endl;
        
        
    }
    
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int n,a;
  cin>>n>>a;
  cout<<n*n-a<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
typedef long long ll;
using namespace std;

class Candle {
 public:
  ll value;
  int a_i, b_i, c_i;
  Candle(ll value,
         int a_i,int b_i,int c_i) :
    value(value),
    a_i(a_i),
    b_i(b_i),
    c_i(c_i) {};

  bool operator < (const Candle &c) const {
    return c.value > value;
  }
};

class CandleCompare {
public:
  bool operator()(const Candle &left,
                  const Candle &right) {
    return (left.a_i + left.b_i*1000 + left.c_i*1000000 <
            right.a_i + right.b_i*1000 + right.c_i*1000000);
  }
};


void add(int a_i, int b_i, int c_i,
         ll* A, ll* B, ll* C,
         priority_queue<Candle>& q,
         set<Candle, CandleCompare> &s) {
  Candle new_candle(A[a_i]+B[b_i]+C[c_i],
                    a_i, b_i, c_i);
  if (s.find(new_candle) == s.end()) {
    q.push(new_candle);
    s.insert(new_candle);
  }
}

int main() {
  int X,Y,Z;
  ll K;
  cin >> X >> Y >> Z >> K;
  ll A[X], B[Y], C[Z];

  for (int i = 0; i < X; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < Y; i++) {
    cin >> B[i];
  }
  for (int i = 0; i < Z; i++) {
    cin >> C[i];
  }
  sort(A, A+X, greater<ll>());
  sort(B, B+Y, greater<ll>());
  sort(C, C+Z, greater<ll>());
  priority_queue<Candle> q;
  Candle candle(A[0]+B[0]+C[0], 0, 0, 0);
  set<Candle, CandleCompare> s;
  q.push(candle);
  s.insert(candle);
  for (ll i = 0; i < K; i++) {
    Candle top_candle = q.top();
    q.pop();
    cout << top_candle.value << endl;
    int a_i = top_candle.a_i;
    int b_i = top_candle.b_i;
    int c_i = top_candle.c_i;
    if (a_i+1 < X) {
      add(a_i+1, b_i, c_i, A, B, C, q, s);
    }
    if (b_i+1 < Y) {
      add(a_i, b_i+1, c_i, A, B, C, q, s);
    }
    if (c_i+1 < Z) {
      add(a_i, b_i, c_i+1, A, B, C, q, s);
    }
  }
  return 0;
}


Measured memory_bytes: 896
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int X[5];
    for(int i=0;i<5;i++){
        cin>>X[i];
    }
    int ans=0;
    for(int i=0;i<5;i++){
        if(X[i]==0){
            ans=i;
        }
    }
    cout<<ans+1<<endl;
    return 0;
}


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


#include "boost/multiprecision/cpp_int.hpp"
#include "boost/multiprecision/cpp_dec_float.hpp"
namespace mp = boost::multiprecision;
typedef mp::cpp_int LL;
typedef mp::number<mp::cpp_dec_float<1024>> DD;// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)


typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

void mod_print(ll k){
    ll P=1000;
    rep(y,1,P){
        ll x=mod(y*k);
        if(x+P>=i_7){
            x-=i_7;
        }
        if(abs(x)<=P){
            cout<<x<<"/"<<y<<endl;
            return;
        }
    }
    cout<<"nun"<<endl;
}
//////////////////////////



ll po(ll i,ll p){
    if(p==0)return 1;
    else{
        i=mod(i);
        if(p==1)return i;
        if(p%2==0)return po(mod(i*i),p/2);
        return mod(i*po(i,p-1));
    }
}
ll bunbo(ll n){
    return po(n,i_5);
}


#define N 20004
ll kai[N];
ll kai2[N];
void calc(){
    kai[0]=1;
    kai2[0]=1;
    rep(i,1,N-1){
        kai[i]=mod(kai[i-1]*i);
    }
    kai2[N-1]=po(kai[N-1],i_5);
    for(ll i=N-2;i>=0;i--){
        kai2[i]=mod(kai2[i+1]*(i+1));
    }
}
ll comb(ll n,ll k){
    if(n<k)return 0;
    if(n==0)return 1;
    return mod(mod(kai[n]*kai2[n-k])*kai2[k]);
}



ll SOLVE(){
    calc();
    ll n,k;cin>>n>>k;
    rep(b,1,k){
        ll ans=comb(n-k+1,b);
        ll a2=comb(k-b+(b-1),b-1);
        cout<<mod(ans*a2)<<endl;
    }
    
    
    return 0;
}

int main(){fastio
    
    clock_t start = clock();
    SOLVE();
    clock_t end = clock();
    const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    cerr<<endl<<time<<"ms"<<endl;
    
    return 0;
}


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

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;

int main()
{
    string s, t;
    cin >> s >> t;
    int c = 0;
    for (int i = 0; i < 3; i++) {
        if (s[i] == t[i]) c++;
    }
    cout << c << endl;
    return 0;
}


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

int N, K, A, sum[200001];
int64_t ans;

int main() {
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        cin >> A;
        sum[i+1] = (sum[i] + A - 1) % K;
    }
    map<int, int> mp;
    mp[0] = 1;
    for (int i = 1; i <= N; i++) {
        if (i >= K) mp[sum[i-K]]--;
        ans += mp[sum[i]];
        mp[sum[i]]++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 10368
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>
#include <iomanip>
#include <set>
//#include <bits/stdc++.h>

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

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

using namespace std;
#define ALL(X) X.begin(),X.end()
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
const int MOD=1000000007;
//const int MOD=998244353;
const int INTMAX=2147483647;
const ll LLMAX=9223372036854775807;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N;
    string s;
    cin>>N>>s;
    
    //SW
    string S[4]={"SS","SW","WS","WW"};
    for(int i=0;i<4;i++){
        for(ll j=1;j<N-1;j++){
            if(S[i][j]=='S'){
                if(S[i][j-1]=='S'){//SS
                    if(s[j]=='o'){
                        S[i]=S[i]+'S';
                    }else{
                        S[i]=S[i]+'W';
                    }
                }else{//WS
                    if(s[j]=='o'){
                        S[i]=S[i]+'W';
                    }else{
                        S[i]=S[i]+'S';
                    }
                }
            }else{
                if(S[i][j-1]=='S'){//SW
                    if(s[j]=='o'){
                        S[i]=S[i]+'W';
                    }else{
                        S[i]=S[i]+'S';
                    }
                }else{//WW
                    if(s[j]=='o'){
                        S[i]=S[i]+'S';
                    }else{
                        S[i]=S[i]+'W';
                    }
                }
            }
        }
        bool ok=true;
        if(s[0]=='o'){
            if(S[i][0]=='S'){
                if(S[i][N-1]!=S[i][1])ok=false;
            }else{
                if(S[i][N-1]==S[i][1])ok=false;
            }
        }else{
            if(S[i][0]=='S'){
                if(S[i][N-1]==S[i][1])ok=false;
            }else{
                if(S[i][N-1]!=S[i][1])ok=false;
            }
        }
        if(s[N-1]=='o'){
            if(S[i][N-1]=='S'){
                if(S[i][N-2]!=S[i][0])ok=false;
            }else{
                if(S[i][N-2]==S[i][0])ok=false;
            }
        }else{
            if(S[i][N-1]=='S'){
                if(S[i][N-2]==S[i][0])ok=false;
            }else{
                if(S[i][N-2]!=S[i][0])ok=false;
            }
        }
        if(ok){
            cout<<S[i]<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    
    return 0;
}


Measured memory_bytes: 1312
#if defined(LOCAL)
#define PROBLEM_NAME "b"
const double _max_double_error = 1e-9;
#include "testutils.h"
#define L(x...) (debug(x, #x))
#define C(x...) CHECK(x)
#else
#define L(x, ...) (x)
#define C(x, ...) ;
#include <bits/stdc++.h>
#endif

using namespace std;
using vi = vector<int>; using vvi = vector<vi>;
using ii = pair<int,int>; using vii = vector<ii>;
using l = long long; using vl = vector<l>; using vvl = vector<vl>;
using ll = pair<l,l>; using vll = vector<ll>; using vvll = vector<vll>;
using lu = unsigned long long;
using vb = vector<bool>; using vvb = vector<vb>;
using vd = vector<double>; using vvd = vector<vd>;
using mll = unordered_map<l, l>;
const l INF = numeric_limits<l>::max();
const double EPS = 1e-10; static constexpr auto PI = acos(-1);
const l e0=1, e3=1000, e5=100000, e6=10*e5, e7=10*e6, e8=10*e7, e9=10*e8;
const char lf = '\n';
#define all(x) begin(x), end(x)
#define F(a,b,c) for (l a = l(b); a < l(c); a++)
#define B(a,b,c) for (l a = l(c) - 1; a >= l(b); a--)
#define MAX(a,b)({__typeof__(a)__x=(a);__typeof__(b)__y=(b);__x<__y?__y:__x;})
#define MIN(a,b)({__typeof__(a)__x=(a);__typeof__(b)__y=(b);__x<__y?__x:__y;})

void solve(istream& cin, ostream& cout) {
  l n, m; cin >> n >> m;
  vector<string> v(n);
  F(i, 0, n) cin >> v[i];
  F(i, 0, n) {
    F(j, 0, m) {
      if (v[i][j] == '#') continue;
      l k = 0;
      for (l di = -1; di < 2; di++) for (l dj = -1; dj < 2; dj++) {
          l x = i + di, y = j + dj;
          if (x < 0 or x >= n or y < 0 or y >= m) continue;
          if (v[x][y] == '#') k++;
      }
      v[i][j] = '0' + k;
    }
  }
  for (auto s : v) cout << s << lf;
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout << fixed << setprecision(15);
#if defined(LOCAL)
  // _generate_random_test = generate_random;
  // _solve_brute = solve_brute;
  // _player_b = player_b;
  // _custom_solution_checker = solution_checker;
  maybe_run_tests(cin, cout);
#else
  solve(cin, cout);
#endif
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
typedef long long lint;

lint gcd(lint a, lint b) { return b ? gcd(b, a%b) : a; }

int main() {

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

	int N;
	cin >> N;

	vector<lint> A(N), cusum_A_fw(N + 1), cusum_A_bk(N + 1);
	for (int i = 0; i < N; i++) cin >> A[i];
	for (int i = 1; i < N; i++) cusum_A_fw[i] = gcd(cusum_A_fw[i - 1], A[i - 1]);
	for (int i = N; i > 0; i--) cusum_A_bk[i - 1] = gcd(cusum_A_bk[i], A[i - 1]);

	lint ans = 0;
	for (int i = 0; i < N; i++) {

		lint A_gcd = 0;

		A_gcd = gcd(cusum_A_fw[i], cusum_A_bk[i + 1]);

		ans = max(ans, A_gcd);
	}

	cout << ans;

	return 0;
}


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

using namespace std;

unsigned gcd(unsigned a, unsigned b) {
  if(a < b) gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
int main(){
    int n,x;
    cin >> n >> x;
    int ans = 0;
    int a;
    cin >> a;
    ans = abs(x-a);
    for(int i = 1;i < n;i++){
        int a;
        cin >> a;
        ans = gcd(abs(x-a),ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
/*It is better to taste failure 
	  than to regret*/
		
            #include <algorithm>
        #include <bitset>
        #include <cassert>
        #include <chrono>
        #include <cmath>
        #include <complex>
        #include <cstdio>
        #include <cstdlib>
        #include <cstring>
        #include <ctime>
        #include <deque>
        #include <functional>
        #include <iomanip>
        #include <iostream>
        #include <iterator>
        #include <limits>
        #include <climits>
        #include <list>
        #include <map>
        #include <numeric>
        #include <queue>
        #include <random>
        #include <ratio>
        #include <set>
        #include <sstream>
        #include <stack>
        #include <string>
        #include <unordered_map>
        #include <unordered_set>
        #include <utility>
        #include <vector>
        using namespace std;
         
        typedef long long ll;
        typedef long double LD;
        #define int ll
        #define double LD
        #define pb push_back
        #define mp make_pair
        #define REP(i,n) for (int i = 0; i < n; i++)
        #define loop(i,n) for (int i = 0; i < n; i++)
        #define FOR(i,a,b) for (int i = a; i < b; i++)
        #define REPD(i,n) for (int i = n-1; i >= 0; i--)
        #define FORD(i,a,b) for (int i = a; i >= b; i--)
        #define remax(a,b) a = max(a,b)
        #define remin(a,b) a = min(a,b)
        #define mem(a, b) memset(a, b, sizeof a)
        #define append push_back
        #define all(v) v.begin(),v.end()
        #define F first
        #define S second
        #define print(x) cout << (x) << endl
        #define PRECISION(x) cout << fixed << setprecision(x)
        #define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
        #define Test(){int t;cin >> t;for(int i=1;i<=t;i++){cout << "Case #" << i << ": ";solve();}}
        #define test(){int t; cin>>t; for(int i=1;i<=t;i++){solve();}}
        #define vi vector<int>
        #define vii vector<pair<int,int> > 
        #define vci vector<pair<char,int> >
        #define vic vector<pair<int,char> > 
        #define N 200005
        #define pb push_back
        const double PI=acos(-1);
        const int MOD = 1000000007;
        const int FMOD = 998244353;
        
        void solve()
        {
        	int n;
        	cin>>n;
        	
        	int f=0,cnt=0;
        	loop(i,n)
        	{
        		int x,y;
        		cin>>x>>y;
        		if(x==y)
        		{
        			cnt++;
				}
				else
				{
					cnt=0;
				}
				if(cnt==3 && f==0)
				{
					cout<<"Yes"<<endl;
					f=1;
				}
			}
			if(f==0)
			cout<<"No"<<endl;
		}
        signed main()
        {
        	//test();
        	solve();
		}

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

int main()
{
    string s;
    cin >> s;

    int a[4];
    for (int i = 0; i < s.size(); i++) {
        a[i] = s[i] - '0';
    }

    for (int i = 0; i < 2 << 3; i++) {
        int t = a[0];
        string ans;
        ans += s[0];
        for (int j = 0; j < 3; j++) {
            if ((i >> j) & 1) {
                t += a[j + 1];
                ans = ans + "+" + s[j + 1];
            } else {
                t -= a[j + 1];
                ans = ans + "-" + s[j + 1];
            }
        }
        if (t == 7) {
            ans += "=7";
            return cout << ans << endl, 0;
        }
    }

    return 0;
}


Measured memory_bytes: 256
N = gets.to_i
$hash = {}
(1..N).each do |i|
  $hash[i] = []
  a = gets.to_i
  a.times { $hash[i] << gets.split.map(&:to_i) }
end
$counts = []

def dfs(array, num)
  if num == N
    possibility = true
    array.each_with_index do |honest_1, index|
      next if honest_1 == 0
      $hash[index + 1].each do |person, honest_2|
        if array[person - 1] != honest_2
          possibility = false
          break
        end
      end
      break if possibility == false
    end
    $counts << array.count(1) if possibility == true
    return
  end
  dfs(array + [1], num + 1)
  dfs(array + [0], num + 1)
end

dfs([], 0)
puts $counts.max


Measured memory_bytes: 2360
a, b = input().split()

if (a, b) == ('H', 'H'):
    print('H')
elif (a, b) == ('H', 'D'):
    print('D')
elif (a, b) == ('D', 'H'):
    print('D')
elif (a, b) == ('D', 'D'):
    print('H')
else:
    print('Something wrong.')

Measured memory_bytes: 3060
N = int(input())

pre_c = [0 for i in range(21)]
for i,n in enumerate(map(int,input().split())):
    if i == 0:
        pre_c[n] = 1
    elif i < N-1:
        next_c = [0 for i in range(21)]
        for j,p in enumerate(pre_c):
            if p > 0:
                if 0 <= j+n <= 20:
                    next_c[j+n] += p
                if 0 <= j-n <= 20:
                    next_c[j-n] += p

        pre_c = next_c
    else:
        print(pre_c[n])

Measured memory_bytes: 6724
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

int main(void) {
    Int n;
    cin >> n;
    cout << (n - 2) * 180 << endl;
    return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9+5;
const ll INFLL = 1e18l+5;

int main(){
    int N;
    cin>>N;
    long int ans=0;
    vector<int> a(N);
    for(int i=0; i<N; ++i){
        cin>>a[i];
    }

    int prev = 0;
    int curr;
    for(int i=1; i<N; ++i){
        if(a[i]>=prev+a[i-1]) prev=0;
        else prev = a[i-1]+prev-a[i];
        //cout<<prev;
        ans+=prev;
    }
    cout<<ans;
}

Measured memory_bytes: 4028
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int32_t main()
{
	//freopen("input.txt", "r", stdin);
	IOS;
	
	int n, k; cin >> n >> k;
	vector<int> a(n);
	for(auto &x: a) cin >> x;

	int j = 0, i = k;
	while(i < n) {
		// cout << a[i] << " " << a[j] << endl;
		if(a[i] > a[j]) cout << "Yes\n";
		else cout << "No\n";
		j++; i++;
	}
	return 0;
}

Measured memory_bytes: 4776
# C - Attack Survival
n,k,q= map(int, input().split())

list = [0] * n

for i in range(q):
    a = int(input())
    list[a - 1] = list[a - 1] + 1

for j in range(n):

    if(k - q + list[j] > 0):
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 4680
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <sstream>
#include <limits.h>
using namespace std;
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>
int main()
{
    int  n;
    cin >> n;
    std::string s;
    cin >> s;
    long long int sum = 0;
    
    std::vector<int> vr;
    std::vector<int> vg;
    std::vector<int> vb;
    for(int i=0; i<n; i++){
        if(s[i] == 'R') vr.push_back(i);
        else if(s[i] == 'G') vg.push_back(i);
        else vb.push_back(i);
    }
    //cout << vr.size() << vg.size() << vb.size() << endl;
    long long int cnt = vr.size()*vg.size()*vb.size();
    //cout << cnt << endl;
    std::vector<int>::iterator ritr = vr.begin();
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            int k = 2*j - i;
            
            if(k<0 || k>=n) continue;
            if(i!=j && i!=k && j!=k){
                //cout << i << "," << j << "," << k << endl;
                if(s[i]!=s[j] && s[i]!=s[k] && s[j]!=s[k]){
                    //cout << i << "," << j << "," << k << endl;
                    cnt--;
                }
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;typedef long long l;
#define r(i,n) for(int i=0;i<n;i++)
const l MN=2005;l md=1e9+7;l n,sz[MN],p[MN];vector<l>g[MN];l d[MN][MN][2];l f[MN];l a[MN][3],x[MN][3];
int main(){f[0]=1;for(l i=1;i<MN;i++)f[i]=f[i-1]*i%md;cin>>n;for(l i=2;i<=n;i++){cin>>p[i];g[p[i]].push_back(i);}for(l i=n;i;i--){memset(a,0,sizeof(a));a[0][0]=1;for(auto &j:g[i]){memset(x,0,sizeof(x));r(k,sz[j]+1)r(l,sz[i]+1)r(m,3){x[k+l][m]+=d[j][k][0]*a[l][m]%md;if(m<2) x[k+l+1][m+1]+=d[j][k][1]*a[l][m]%md;}sz[i]+=sz[j];r(j,sz[i]+1)r(k,3){a[j][k]=x[j][k]%md;}}r(j,sz[i]+1){d[i][j][0]=a[j][0]+a[j][1]*2+a[j][2]*2;d[i][j][1]=a[j][0]+a[j][1];d[i][j][0]%=md;d[i][j][1]%=md;}sz[i]++;}l rt=0;r(i,n+1){l cr=d[1][i][0]*f[n-i]%md;if(i&1) cr=md-cr;rt+=cr;}cout<<rt%md<<endl;}

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

int main()
{
    // 頂点数と辺数
    int N, X, Y;
    cin >> N >> X >> Y;

    // グラフ入力受取 (ここでは無向グラフを想定)
    vector<vector<int>> G(N + 1);
    for (int i = 1; i < N + 1; ++i) {
        if(i != N) G[i].push_back(i + 1);
        if(i != 1) G[i].push_back(i - 1);
    }
    G[X].push_back(Y);
    G[Y].push_back(X);

    vector<int> count(N + 1);

    rep2(i,1,N + 1){
        // BFS のためのデータ構造
        vector<int> dist(N+1, -1); // 全頂点を「未訪問」に初期化
        queue<int> que;        
        // 初期条件 (頂点 0 を初期ノードとする)
        dist[i] = 0;
        que.push(i); // 0 を橙色頂点にする

        // BFS 開始 (キューが空になるまで探索を行う)
        while (!que.empty()) {
            int v = que.front(); // キューから先頭頂点を取り出す
            que.pop();

            // v から辿れる頂点をすべて調べる
            for (int nv : G[v]) {
                if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

                // 新たな白色頂点 nv について距離情報を更新してキューに追加する
                dist[nv] = dist[v] + 1;
                que.push(nv);
                count[dist[nv]]++;
            }
        }
    }

    // 結果出力 (各頂点の頂点 0 からの距離を見る)
    rep2(i,1,N) cout << count[i]/2 << endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  char X,Y;
  cin>>X>>Y;
  if(X<Y)puts("<");
  else if(X>Y)puts(">");
  else puts("=");
  return 0;
}

Measured memory_bytes: 256
// https://github.com/atcoder-live/library
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,(e))
#define irp(i,s,e) for(int i=(s);i>(e);--i)
#define irpz(i,s) irp(i,(s),-1)
template<class T> T in(){T x;cin>>x;return x;}
// long long a = in<long long>();
template<class T> vector<T> inarr(int s,int e, T init=0){
	vector<T> v;T x;
	rp(i,0,s)v.push_back(init);
	rp(i,s,e){x=in<T>();v.push_back(x);}
	return v;
}
// vi P = inarr<int>(1,N+1,INT_MAX);
// vi P = inarr<int>(0,N);

// #define NMAX 1000000000
int N,K;
vi H;

ll solve(){
	sort(allr(H));
	ll ans=0;
	if(N<=K){
		ans = 0;
		return ans;
	}
	else{
		ans = 0;
		rp(i,K,N){
			ans += H[i];
		}
	}

	return ans;
}

int main(){
	cin>>N;
	cin>>K;
	H = inarr<int>(0,N);
	cout<< solve() <<endl;
}


Measured memory_bytes: 1400
using System;

namespace _0176
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string s = Console.ReadLine();
                if (s == "0") break;
                int a = Convert.ToInt32(s.Substring(1,2),16);
                int b = Convert.ToInt32(s.Substring(3,2),16);
                int c = Convert.ToInt32(s.Substring(5,2),16);
                int[] x = new int[] { 0,255 };
                string[] color = new string[] { "black","blue","lime","aqua","red","fuchsia","yellow","white" };
                double min = double.MaxValue; string ret = "";
                for (int i = 0; i < 2; i++)
                {
                    for (int j = 0; j < 2; j++)
                    {
                        for (int k = 0; k < 2; k++)
                        {
                            double d = Math.Pow(x[i] - a,2);
                            d += Math.Pow(x[j] - b,2);
                            d += Math.Pow(x[k] - c,2);
                            Math.Sqrt(d);
                            if (d < min)
                            {
                                min = d; ret = color[i * 4 + j * 2 + k];
                            }
                        }
                    }
                }
                Console.WriteLine(ret);
            }
        }
    }
}


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

using namespace std;
int main(){
  string N;
  cin >> N;
  int a=0;
  int c=N.size();
  
  for(int i=0;i<c;++i){
    if(i%2==0){
      if(N.at(i)!='L'){
       a++;
      }
    }else{
      if(N.at(i)!='R'){
        a++;
      }
    }
  }
   if(a==c){
     cout<<"Yes"<<endl;
   }else{
     cout<<"No"<<endl;
   }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define simplify ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define endl "\n"
using namespace std;

int binomialCoeff(int n,int r){
    int res=1;
    if(r>n-r)r=n-r;
    for(int i=0;i<r;i++){
        res*=(n-i);
        res/=(i+1);
    }
    return res;
}


int power(int x,int n,int mod){
    //(x^n)%mod
    int result=1;
    while(n){
        if(n%2)
            result=(result*x)%mod;
        x=(x*x)%mod;
        n/=2;
    }
    return result;
}

int inverseMod(int x,int mod){
    return power(x,mod-2,mod);
}


int32_t main() {

    simplify
    int t;
    cin>>t;
    map<string,int>mp;
    while(t--){
        string s;
        cin>>s;
        mp[s]++;
    }

    cout<<"AC x "<<mp["AC"]<<endl;
    cout<<"WA x "<<mp["WA"]<<endl;
    cout<<"TLE x "<<mp["TLE"]<<endl;
    cout<<"RE x "<<mp["RE"]<<endl;


    

    return 0;
}



Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define pb push_back

ll sol (string s , ll mod) {
    if (mod<=0) return 0 ;
    reverse(s.begin(),s.end()) ;
    ll    n = s.size() ;
    ll p = 1 ;
    ll rem = 0 ;

    for (ll i = 0; i< n;i++) {
        rem += (s[i]-'0')*p ;
        p*=2 ;
        rem%=mod ;
        p%=mod ;
    }

    return rem ;
}

ll bigMod(ll a, ll b , ll mod)
{
    if (mod==0) return 0;
    if(b==0) return 1;
    ll x=bigMod(a, b/2 , mod);
    if(b%2==0) return (x*x)%mod;
    x=(x*x)%mod;
    return (x*a)%mod;
}
ll solve(ll ans ,ll mod ) {
    ll res = 1 ;
    if (mod==0) return 0 ;
    while(ans) {
        ll cnt =  __builtin_popcount(ans) ;
        ans%=cnt ;
        res++ ;
    }

    return res ;
}
int main() {

    ll n , cnt = 0 , i ;
    string s ;
    cin >> n>> s ;

    for (i = 0; i< n; i++) cnt += (s[i]=='1') ;

    ll rem1 = sol(s, cnt+1 ) ;
    ll rem2 = sol(s, cnt-1 ) ;

    for (i = 0; i< n; i++) {
        ll ans ;
        ll modu ;
        if (s[i]=='0') {
            ll rem = bigMod(2,(n-i-1),cnt+1) ;
             ans = rem1 + rem ;
            ans= (ans)% (cnt+1) ;
            modu = cnt + 1 ;

        }
        else {
            modu = cnt-1 ;
            if (modu==0) {cout << 0 << endl ; continue ; }
            ll mod  = cnt-1 ;
            ll rem = bigMod(2,(n-i-1),cnt-1) ;
            ans = (((rem2-rem)%mod)+mod)%mod ;
            ans = ans%mod ;
        }
        cout << solve(ans,modu) << endl ;

    }

    return 0 ;
}


Measured memory_bytes: 3896
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

string n;

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	cout << ((n[0] == '9' || n[1] == '9') ? "Yes\n" : "No\n");
	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
abc = n.times.map { gets.chomp.split(" ").map(&:to_i) }
dp = Array.new(n) { Array.new(3) { 0 } }
3.times do |i|
  dp[0][i] += abc[0][i]
end
1.upto(n - 1) do |i|
  3.times do |j|
    max = 0
    2.times do |k|
      cost = dp[i - 1][j - k - 1] + abc[i][j]
      max = cost if max < cost
    end
    dp[i][j] = max
  end
end
puts dp[-1].max

Measured memory_bytes: 11900
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	string s; cin >> s;
	int K; cin >> K;
	set<string>st;
	rep(i, 0, (int)s.size()) {
		rep(j, 1, K + 1) {
			st.insert(s.substr(i, j));
		}
	}
	vector<string>str;
	for (auto itr = st.begin();itr != st.end();++itr) {
		str.push_back(*itr);
	}
	sort(all(str));
	cout << str[K - 1] << "\n";

	return 0;
}

Measured memory_bytes: 1920
package main

import "fmt"

type edge struct {
	from int
	to   int
}

func main() {
	var N, M int
	fmt.Scan(&N, &M)
	m := make(map[edge]bool, 2*N)
	var x, y int
	for i := 0; i < M; i++ {
		fmt.Scan(&x, &y)
		if x == 1 || y == N {
			m[edge{from: x, to: y}] = true
		}
	}

	found := false
	for i := 1; i <= N; i++ {
		if i == 1 {
			if m[edge{from: 1, to: N}] {
				found = true
				break
			}
		} else {
			if m[edge{from: 1, to: i}] && m[edge{from: i, to: N}] {
				found = true
				break
			}
		}
	}

	if found {
		fmt.Println("POSSIBLE")
	} else {
		fmt.Println("IMPOSSIBLE")
	}
}


Measured memory_bytes: 17280
#include <bits/stdc++.h>
using namespace std;
int d,dp[100001][101][2];
string k;

int add(int &a , int b){
    a += b;
    if(a >= 1000000007){
        a -= 1000000007;
    }
    return a;
}

int ans(int curr , int mod , int tag){
    if(curr == k.size()){
        if(mod == 0){
            return 1;
        }
        return 0;
    }
    if(dp[curr][mod][tag] != -1){
        return dp[curr][mod][tag];
    }
    int ret = 0;
    if(tag){
        for(int i = 0 ; i < k[curr]-'0' ; i += 1){
            int v = (mod+i)%d;
            add(ret,ans(curr+1,v,1-tag));
        }
        int v = mod+(k[curr]-'0');
        v %= d;
        add(ret,ans(curr+1,v,tag));
    }else{
        for(int i = 0 ; i <= 9 ; i += 1){
            int v = (mod+i)%d;
            add(ret,ans(curr+1,v,tag));
        }
    }
    return dp[curr][mod][tag] = ret;
}

int main(){
    memset(dp,-1,sizeof dp);
    cin >> k >> d;
    int ret = (ans(0,0,1)-1)%1000000007;
    if(ret < 0){
        ret += 1000000007;
    }
    cout << ret << endl;
}

Measured memory_bytes: 80128
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(I, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  
  while(1){
    c -= b;
    if(c <= 0){
      cout << "Yes" << endl;
      return 0;
    }
    a -= d;
    if(a <= 0){
      cout << "No" << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3620