akhauriyash/Code-Regression huggingface dataset:
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

const ll INF = 1LL << 50;

const ll mod = 1000000007;

int main() {
  ll n, k;
  cin >> n >> k;

  vll a(n);
  rep(i, n) cin >> a[i];
  Sort(a);

  ll ans = 0;
  rep(i, n - k) ans += a[i];

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pa;
typedef unsigned int uint;
typedef unsigned long long ull;
#define w1 first
#define ls (x<<1)
#define w2 second
#define rs (x<<1|1)
#define mp make_pair
#define pb push_back
#define mid ((l+r)>>1)
#define SZ(x) (int((x).size()))
#define All(x) (x).begin(),(x).end()
#define dprintf(...) fprintf(stderr,__VA_ARGS__)
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)])
#define Rep2(p,x) for(int (p)=cur[(x)];(p);(p)=nxt[(p)])
template<class T>void read(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}
const int N=200005;
int head[N],nxt[N],to[N],e;
int sg[N];
void init(){
	memset(head,-1,sizeof(head));
	e=0;
}
void add_edge(int x,int y){
	to[e]=y;nxt[e]=head[x];head[x]=e++;
}
void dfs(int x,int f){
	sg[x]=0;
	for(int i=head[x];i+1;i=nxt[i])if(to[i]!=f){
		dfs(to[i],x);
		sg[x]^=(sg[to[i]]+1);
	}
}
int main(){
	int n;read(n);
	init();
	rep(i,1,n-1){
		int x,y;
		read(x);read(y);
		add_edge(x,y);
		add_edge(y,x);
	}
	dfs(1,0);
	if(sg[1])puts("Alice");
	else puts("Bob");
	return 0;
}

Measured memory_bytes: 7680
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

template <typename T>
void print_vec(const vector<T>& v, bool is_reverse=false, ll num=0){
  if(num == 0) num = (ll)v.size();
  cout << endl; cout << "i=  ";for(ll i=0; i<num; i++) cout << i << "   ";cout << endl;  
  cout << "    ";
  if(is_reverse) for(ll i=num-1; i>=0; i--){ cout<<v[i]; if(i!=0) cout<<"   ";}
  else for(ll i=0; i<num; i++){ cout<<v[i]; if(i!=num-1) cout<<"   ";}
  cout << endl;
}

// template <typename T>
// void print_pairvec(const vector<T> &v, ll num=0){
//   if(num == 0) num = (ll)v.size();
//   cout << endl; for(ll i=0; i<num; i++){ cout << v[i].first << " " << v[i].second << endl;}
// }
template <typename T>
void print_pairvec(const T &_pair, ll num=0){
  cout << endl; for(pair<ll, int> x: _pair){ cout << x.first << " " << x.second << endl;}
}

template <typename T>
void print_vec2(const vector<vector<T>>& v){
  cout << endl; cout << "       ";
  for(ll i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(ll i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(ll j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

struct Eratosthenes{
  vector<ll> sieve;// sieve[i]: 数字iがエラトステネスで篩落とされた時の素数

  Eratosthenes(ll n): sieve(n+1){
    for(int i=0; i<=n; i++) sieve[i] = i;
    for(ll i=2; i*i<=n; i++){
      if(sieve[i] < i) continue;
      for(ll j=i*i; j<=n; j+=i) sieve[j] = min(sieve[j], i);
    } 
  }

  vector<ll> prime_divisors(ll x, bool tmp=false){
    vector<ll> res(1,1);//back()のところで ひっかかるので1を入れとかないとダメ
    while(x > 1){
      if(res.back() != sieve[x]) res.push_back(sieve[x]);
      x /= sieve[x];
    }
    return res;
  }

  map<ll, int> prime_divisors(ll x, int tmp=0){
    map<ll, int> mp;
    while(x > 1){
      mp[sieve[x]]++;
      x /= sieve[x];
    }
    return mp;
  }
};

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0; i<N; i++) cin >> A[i];

  sort(A.begin(), A.end());//82行目のbreakを入れないとTLEになるらしく，それならsortしないといけない
  const int INF  =1e6+1;// sortじゃなくてこっちがTLEの原因?// 81行目を追加して1e6+1でやってみる
  // const int INF = A.back()+1;
  vector<int> vec(INF, 0);
  for(int i=0; i<N; i++){
    if(vec[A[i]] >= 2) continue;// 84行目の代わり
    for(int j=1; j*A[i]<=INF; j++){
      vec[A[i]*j]++;
      // if(vec[A[i]*j] >= 2) break;// これいれたらWA?
    }
  }
  int ans = 0;
  for(ll i=0; i<N; i++){
    if(vec[A[i]] == 1) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 7948
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
int main() {int x,y,a;
  cin >>x>>y;
            a=0;
for(int i=0;i<100;i++){
for(int j=0;j<100;j++){
if(x==i+j&&y==2*i+4*j){ cout << "Yes" << endl;a++;}}
}  
 if(a==1){}
            else{cout << "No" << endl;}
           }

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

#define speed ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define test ll t; cin>>t; while(t--)
#define ll long long
#define endl "\n"
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define pb push_back
#define PI 3.1415926535897932384626
#define inf 1e18
#define vll vector<ll>
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define fl(i,a,b) for(ll i=a;i<b;i++)
#define flr(i,a,b) for(ll i=a;i>b;i--)
#define print(v) for(auto i=v.begin();i!=v.end();i++){cout<<*i<<" ";}cout<<"\n";
#define MOD 1000000007


int main()
{
    speed;
    long double l; cin>>l;
    long double ans = 0;
    cout.precision(12); cout<<fixed; 
    // if(l%3==0)
    // 	ans = (l*l*l)/27;
    // else{
    	long double a,b,c;
    	a = l/3;
    	b = a;
    	c = l-a-b;
    	ans = a*b*c;
    	//cout<<a<<" "<<b<<" "<<c;
    
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] len = new int[4];
		Arrays.setAll(len, i -> sc.nextInt());
		int max = Math.max(len[0] * len[1], len[2] * len[3]);
		System.out.println(max);
		sc.close();
	}
}



Measured memory_bytes: 32152
fun main(args : Array<String>) {
    val s = readLine()!!
    val t = readLine()!!

    val map = mutableMapOf<Char, MutableList<Long>>()

    s.forEachIndexed { index, c ->
        if (map.contains(c)) {
            map[c]!!.add(index.toLong())
        } else {
            map[c] = mutableListOf()
            map[c]!!.add(index.toLong())
        }
    }
    fun lowerBound(sortedList: List<Long>, key: Long) : Int {
        var ng = - 1 // left
        var ok = sortedList.size  // right

        fun isOk(mid: Int) : Boolean {
            return sortedList.get(mid) >= key
        }

        while (Math.abs(ok - ng) > 1) {
            var mid = (ok + ng) / 2
            if (isOk(mid)) {
                ok = mid
            } else {
                ng = mid
            }
        }
        return ok
    }

    // < O(logN)
    fun getNext(c: Char, current: Long) : Long {
        val indexes = map[c]
        if (indexes == null) {
            return -1
        }
        val key = current + 1
        val base = key / s.length
        val i = lowerBound(indexes, key)
        if (i >= indexes.size) {
            return indexes[0] + base * s.length.toLong() + s.length
        }
        return indexes[i] + base * s.length.toLong()
   }
   var current = 0L

    var ans = 0L
    var prev = -1L
   t.forEach {
       val indexes = map[it]
       if (indexes == null) {
           println(-1)
           return
       }
       val next = lowerBound(indexes, prev + 1)
       val nextIdx = if(next >= indexes.size) indexes.first() else indexes[next]
       ans += if(nextIdx > prev) nextIdx - prev else s.length - prev + nextIdx
       prev = nextIdx
   }
   println(ans)
}

Measured memory_bytes: 41724
#include<cstdio>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<sstream>

using namespace std;


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


int solve(string s){
	
	//cout<<s<<endl;
	
	s.erase(s.begin());
	s.erase(s.begin()+s.size()-1);
	
	int cnt = 0;
	rep(i,s.size()){
		if(s[i]=='[' || s[i]==']')cnt++;
	}
	
	if(cnt==0){
		
		stringstream sst;
		sst<<s;
		int ret;
		sst>>ret;
		return ret/2+1;
	}
	
	vector<int> cand;
	
	int st = 0;
	int ct = 0;
	rep(i,s.size()){
		if(s[i]=='[')ct++;
		if(s[i]==']')ct--;
		if(ct==0){
			cand.push_back(solve(s.substr(st, i-st+1)));
			st=i+1;
		}
	}
	
	
	sort(cand.begin(),cand.end());
	
	int ans = 0;
	rep(i,cand.size()/2+1){
		ans += cand[i];
	}
	
	return ans;
}


int main(){
	int n;
	cin>>n;
	
	rep(i,n){
		string s;
		cin>>s;
		
		cout<<solve(s)<<endl;
	}
}

Measured memory_bytes: 1304
import java.util.*;

public class Main{
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        if(a.equals(b)){
            System.out.println("H");
        }else{
            System.out.println("D");
        }
    }
}

Measured memory_bytes: 35528
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    string s;
    cin >> s;
    if(s.size() == 2)
    {
        cout << s << "\n";
    }
    else
    {
        for(int i = s.size() - 1;i >= 0;i--)
        {
            cout << s[i];
        }
        cout << "\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;

int main(void) {
	int n, m, ans;
	long long int a[50], b[50], c[50], d[50], dist, tmp;

	cin >> n >> m;

	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	for (int i = 0; i < m; i++) {
		cin >> c[i] >> d[i];
	}


	for (int i = 0; i < n; i++) {
		tmp = abs(a[i] - c[0]) + abs(b[i] - d[0]);
		ans = 0;
		for (int j = 0; j < m; j++) {
			dist = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			if (dist < tmp) {
				tmp = dist; 
				ans = j;
			}
		}
		cout << ans + 1 << endl;
	}


	return 0;
}

Measured memory_bytes: 256
import itertools as it
import collections
 
n, x, y = list(map(int, input().split(' ')))
 
dist_list = []
dist_a = dist_list.append
for i, j in it.combinations(list(range(n)), 2):
    warp_dist = abs(i - (x - 1)) + 1 + abs(j - (y - 1))
    if abs(j - i) < warp_dist:
        dist_a(abs(j - i))
    else:
        dist_a(warp_dist)
 
dist_c = collections.Counter(dist_list)
 
for i in range(1, n):
    print(dist_c[i])

Measured memory_bytes: 67724
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
#define EPS (1e-10)
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	string s; cin>>s;
	string t=""; t+=s[0];
	rep(i,s.size()-1){
		if(s[i]!=s[i+1]) t+=s[i+1];
	}
	int n=t.size();
	cerr<<t<<endl;
	cout<<n-1<<endl;
	return 0;
}


Measured memory_bytes: 592
import sys
import math
import copy
import queue
input = sys.stdin.readline
n,m,k = map(int,input().split())
f = [[] for _ in range(n+1)]
b = [[] for _ in range(n+1)]
for _ in range(m):
    x,y = map(int,input().split())
    f[x].append(y)
    f[y].append(x)
for _ in range(k):
    x,y = map(int, input().split())
    b[x].append(y)
    b[y].append(x)
g = [0 for _ in range(n+1)]
g_cnt = [0]
g_no = 0
for i in range(1,n+1):
    if g[i] > 0:
        continue

    g_no += 1
    q = queue.Queue()
    q.put(i)
    cnt = 0
    while not q.empty():
        g[i] = g_no
        node = q.get()
        cnt += 1
        for n_node in f[node]:
            if g[n_node] == 0:
                q.put(n_node)
                g[n_node] = g_no
    g_cnt.append(cnt)

for i in range(1,n+1):
    block = 0
    for x in b[i]:
        block += (g[i] == g[x])
    print (g_cnt[g[i]] - len(f[i]) - block - 1,end=' ')
print ()



Measured memory_bytes: 107180
def bisect_left(a, x, lo=0, hi=None):
    if hi is None:
        hi = len(a)
    while lo < hi:
        mid = (lo+hi)//2
        if a[mid] < x: lo = mid+1
        else: hi = mid
    return lo
n=int(input())
l=list(map(int,input().split()))
l.sort()
ans=0
for i in range(n):
    for j in range(i+1,n):
        tar=l[j]+l[i]
        temp=bisect_left(l,tar)
        ans+=temp-j-1
print(ans)
        

        

Measured memory_bytes: 74424
// 153

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

int main() {
    int n, k;
    cin >> n >> k;
    vector <int> h(n);

    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
    sort(h.rbegin(), h.rend());
    ll ans = 0;
    for (int i = k; i < n; i++) {
        ans = ans + h[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (long long  i=a;i<n;i++)
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;

void solve() {
	string s;
	cin >> s;
	ll sum = 0;
	rep(i, 0, sz(s))sum += (s[i] - '0');
	if (sum % 9 == 0)cout << "Yes"; else cout << "No";
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int T_ = 1;
	//cin >> T_;
	for (int i = 0; i < T_; i++)solve();
	return 0;
}



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

const int MAXN = 2e5;
int N;
int A[MAXN];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];

	vector<int> pref = {0};
	for (int i = 0; i < N; i++) {
		pref.push_back(__gcd(pref.back(), A[i]));
	}
	vector<int> suff = {0};
	for (int i = N-1; i >= 0; i--) {
		suff.push_back(__gcd(suff.back(), A[i]));
	}

	int ans = 0;
	for (int i = 0; i < N; i++) {
		ans = max(ans, __gcd(pref[i], suff[N-1-i]));
	}
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 1784
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
// const lint MOD = 998244353;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
char upper(char c){
	return c-0x20;
}
char lower(char c){
	return c+0x20;
}

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


int main(){
	int n; cin >> n;
	vector<int> v(n);
	cinv(n,v);
	int count = 0;
	rep(i,n){
		if (v[i]%2 == 0){
			while(v[i]%2 == 0){
				count++;
				v[i] /= 2;
			}
		}
	}
	cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define int long long  
#define INF 1145141919810893
signed main(){
    int N;
    int A[114514],B[114514];
    int Ans=0;
    cin >> N;
    REP(i,N){cin >> A[i] >> B[i];}
    for(int i=N-1;i>=0;i--){
        Ans+=(B[i] - ((A[i]+Ans)%B[i]))%B[i];
    }
    cout << Ans << endl;
	return 0;
}


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

int main(){
  int n,ans=0;
  string s;
  cin>>n>>s;
  for(int i=0;i<n-2;i++){
    if(s.at(i)=='A'&&s.at(i+1)=='B'&&s.at(i+2)=='C')ans++;
  }
  cout<<ans<<"\n";
  return 0;
}

Measured memory_bytes: 256
r = [0.0,48.0,51.0,54.0,57.0,60.0,64.0,69.0,75.0,81.0,91.0,1000.0]
s = ["light fly","fly","bantam","feather","light","light welter","welter","light middle","middle","light heavy","heavy"]
 
while True:
    try:
        w = float(input())
    except:break
    for i in range(12):
        if r[i] < w and w <= r[i+1]:
           print(s[i])
           break


Measured memory_bytes: 5576
//Har Har Mahadev
using namespace std;
#include <bits/stdc++.h>
#define booga cout << "booga" << endl
#define ll long long int
#define pb push_back
#define mp make_pair
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " -> " << a << endl;
	err(++it, args...);
}
int n,m;
vector<vector<int>> graph;
vector<bool> visited;
void bfs(int i, int &temp){
	if(visited[i]){
		return;
	}
	temp++;
	visited[i] = true;
	for(int node : graph[i])bfs(node,temp);
}
void testcase(){
	cin >> n >> m;
	graph.resize(n);
	visited.resize(n,false);
	set<pair<int,int>> yet;
	for(int i{0};i < m;i++){
		int u,v;
		cin >> u >> v;
		u--;v--;
		if(yet.count(mp(min(u,v),max(u,v))))continue;
		yet.insert(mp(min(u,v),max(u,v)));
		graph[u].pb(v);
		graph[v].pb(u);
	}
	int ans = -1;
	for(int i{0};i < n;i++){
		int temp = 0;
		bfs(i,temp);
		ans = max(ans,temp);
	}
	cout << ans;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	while(t--){
		testcase();
	}
	return 0;
}



Measured memory_bytes: 29676
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
	int n;
	cin >> n;
	vi a(n);
	rep(i, n) cin>>a[i];
	vi b(2);
	rep(i, n) b[a[i]%2]++;
	if(n == 2 && max(b[0], b[1]) == 2) {
		cout<<"YES"<<endl;
		return 0;
	}
	if(b[1] & 1) {
		cout<<"NO"<<endl;
		return 0;
	}
	cout<<"YES"<<endl;
}


Measured memory_bytes: 640
import itertools
import math
from functools import reduce


def gcd(*numbers):
    return reduce(math.gcd, numbers)


def gcd_list(numbers):
    return reduce(math.gcd, numbers)


K = int(input())

# 同じものが出てくるので、それを削減させる
# N^3の計算数が必要　1<=K<=200

# 1 + 3 + 3 + 1 = 8
permutaions = list(itertools.combinations_with_replacement(
    list(range(1, K + 1)), 3))
count = 0
for permutaion in permutaions:
    # print(permutaion, gcd(permutaion[0], permutaion[1], permutaion[2]))
    if permutaion[0] == permutaion[1] and permutaion[1] == permutaion[2]:
        count += gcd(permutaion[0], permutaion[1], permutaion[2])
    elif permutaion[0] != permutaion[1] and permutaion[1] != permutaion[2] and permutaion[0] != permutaion[2]:
        count += (6 * gcd(permutaion[0], permutaion[1], permutaion[2]))
    else:
        count += (3 * gcd(permutaion[0], permutaion[1], permutaion[2]))
print(count)


Measured memory_bytes: 192680
S = input()

L = ["eraser","erase","dreamer","dream"]
 
while len(S) > 0:
  for i in range(len(L)):
    if L[i] in S:
      S = S.replace(L[i],"")
  else:break
 
if len(S) == 0:
  print("YES")
else:print("NO")


Measured memory_bytes: 3188
from collections import deque

N, X, Y = map(int, input().split())
ans = [0] * N
for i in range(N-1):
    dist_list = [-1] * N
    d = deque([[i]])
    dist = 0
    while d[0]:
        tag = d.popleft()
        next_tag = []
        for t in tag:
            if dist_list[t] == -1:
                dist_list[t] = dist
            if t - 1 >= 0:
                if dist_list[t - 1] == -1:
                    next_tag.append(t-1)
            if t + 1 < N:
                if dist_list[t + 1] == -1:
                    next_tag.append(t + 1)
            if t == X-1:
                if dist_list[Y-1] == -1:
                    next_tag.append(Y-1)
            if t == Y-1:
                if dist_list[X-1] == -1:
                    next_tag.append(X-1)
        d.append(next_tag)
        dist += 1
    for j in range(i+1, N):
        ans[dist_list[j]] += 1

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

Measured memory_bytes: 76352
import sys
stdin=sys.stdin

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

A,B=nm()

print(((B-1)//(A-1)+((B-1)%(A-1)>0) if B>1 else 0))


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <time.h>

//     MLE,TLE魔
//↓↓↓↓↓↓↓↓↓↓↓↓
#define int long long
//↑↑↑↑↑↑↑↑↑↑↑↑
//     MLE,TLE魔
#define endre getchar();getchar();return 0
#define moder 1000000007
#define inf 5000000000000000000
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int kai(int x) {
	if (x == 0)return 1;
	return (kai(x - 1)*x) % moder;
}
int comb(int x, int y) {
	return kai(x)*mod_pow(kai(x - y), moder - 2, moder) % moder*mod_pow(kai(y), moder - 2, moder) % moder;
}
struct edge { int to, cost; };
int dx[5] = { 0,1,0,-1 }, dy[5] = { 1,0,-1,0 };
map<int, int>factor(int x) {
	map<int, int>res;
	for (int i = 2; i*i <= x; i++) {
		while (x%i == 0) {
			x /= i;
			res[i]++;
		}
	}
	if (x != 1)res[x]++;
	return res;
}
/*--------Library Zone!--------*/


signed main() {
	int a, b, c;
	cin >> a >> b >> c;
	int g = gcd(a, b);
	for (int i = g; i >= 1; i--) {
		if (g%i == 0) {
			c--;
			if (!c) {
				cout << i << endl;
				endre;
			}
		}
	}
	endre;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll h,w;
ll direction2[4][2]={{1,0},{0,1},{0,-1},{-1,0}};
bool valid(int a,int b)
{
    if(a>=1&&a<=h&&b>=1&&b<=w)return true;
    else return false;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x=1000000;
    cin>>n;map<ll,ll>nw,ne;
    string s;
    cin>>s;
    for(int i=0;i<n;i++){
        if(s[i]=='W')nw[i]=1+nw[i-1];
        else nw[i]=nw[i-1];
        if(s[n-i-1]=='E')ne[n-i-1]=1+ne[n-i];
        else ne[n-i-1]=ne[n-i];
    }
    for(int i=0;i<n;i++){
        x=min(x,(nw[i-1]+ne[i+1]));
        //cout<<nw[i-1]<<" "<<ne[i+1]<<endl;
    }
    cout<<x;
}


Measured memory_bytes: 41128
#include<bits/stdc++.h>
using namespace std;
int main() {
    int a,b,c;
    cin >> a >> b >> c;
    if (a > b) swap(a,b);
    if (b > c )swap(b,c);
    if (a > b) swap(a,b);
    cout << a << " " <<b <<  " " << c <<endl;
    return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
  public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

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

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

void solve(long long X, long long Y, long long Z, long long K, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C)
{
    RSORT(A);
    RSORT(B);
    RSORT(C);
    std::vector<ll> v(X*Y,0);
    vector<ll> ans(K*Z,0);
    for (int i = 0; i < X; i++)
    {
        for (int j = 0; j < Y; j++)
        {
            v.push_back(A[i] + B[j]);
        }
    }

    RSORT(v);

    for (int i = 0; i < K; i++)
    {
        for (int j = 0; j < Z; j++)
        {
            ans.push_back(v[i] + C[j]);
        }
    }

    RSORT(ans);

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

int main()
{
    long long X;
    scanf("%lld", &X);
    long long Y;
    scanf("%lld", &Y);
    long long Z;
    scanf("%lld", &Z);
    long long K;
    scanf("%lld", &K);
    std::vector<long long> A(X);
    for (int i = 0; i < X; i++)
    {
        scanf("%lld", &A[i]);
    }
    std::vector<long long> B(Y);
    for (int i = 0; i < Y; i++)
    {
        scanf("%lld", &B[i]);
    }
    std::vector<long long> C(Z);
    for (int i = 0; i < Z; i++)
    {
        scanf("%lld", &C[i]);
    }
    solve(X, Y, Z, K, std::move(A), std::move(B), std::move(C));
    return 0;
}


Measured memory_bytes: 64760
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()


int main(){
    string s;
    cin >> s;
    if(s.at(1) == 'B'){
        cout << "ARC" << endl;
    }else{
        cout << "ABC" << endl;
    }
    return 0;
}


Measured memory_bytes: 3636
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N;
    cin >> N;
    vector<string> s(N);
    for (ll i = 0; i < N; i++) {
        cin >> s[i];
    }

    ll a = 0, b = 0, c = 0;
    ll ans = 0;
    for (ll i = 0; i < N; i++) {
        if (s[i].front() == 'B' && s[i].back() == 'A') {
            c++;
        } else if (s[i].front() == 'B') {
            b++;
        } else if (s[i].back() == 'A') {
            a++;
        }

        for (ll j = 0; j < s[i].size() - 1; j++) {
            if (s[i][j] == 'A' && s[i][j + 1] == 'B') {
                ans++;
            }
        }
    }

    if (c > 0) {
        ans += c - 1;
        if (a > 0) {
            a--;
            ans++;
        }
        if (b > 0) {
            b--;
            ans++;
        }
    }
    ans += min(a, b);
    cout << ans << endl;
}

Measured memory_bytes: 768
#include <stdio.h>
#define N 10000

main(){
  int a, b, c, x, n, i, count, now;
  int data[N];

  while(1){
    scanf("%d %d %d %d %d", &n, &a, &b, &c, &x);
    if(n==0 && a==0 && b==0 && c==0 && x==0) break;

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

    now=0;
    for(count=0;;count++){
      if(count>N){
        count=-1;
        break;
      }

      if(data[now]==x){
        if(now==n-1) break;
        else now++;
      }

      x=(a*x+b)%c;
    }

    printf("%d\n", count);
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

int main()
{
	long long x, y, z, ans=0;
	cin >> x;	cin >> y;	cin >> z;

	if (x >= y+2*z) {
		ans++;
		x -= y + 2 * z;
	}
	else {
		cout << ans << endl;
		return 0;
	}

	while (x - z - y >= 0) {
		x = x - z - y;
		ans++;
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;

int main(){

    int N;
    cin >> N;

    vector <int> a(N);
    for (int i = 0; i < N; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());

    vector <int> b(N);
    for (int i = 0; i < N; i++){
        cin >> b[i];
    }
    sort(b.begin(), b.end());

    vector <int> c(N);
    for (int i = 0; i < N; i++){
        cin >> c[i];
    }
    sort(c.begin(), c.end());

    long long ab = 0, bc = 0;
    long long ans = 0;

    for (int i = 0; i < N; i++){
        
        int num1 = ab;
        for (int j = num1; j < N; j++){
            if (b[i] > a[j]){
                ab ++;
            }else{
                break;
            }
        }

        int num2 = bc;
        for (int j = num2; j < N; j++){
            if (b[i] >= c[j]){
                bc ++;
            }else{
                break;
            }
        }
        
        long long sum = ab * (N - bc);
        ans = ans + sum;

    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1408
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
using namespace std;
typedef long long ll;

int main(){
  ll N; cin >> N;
  if(N%2 == 0) cout << N << endl;
  else cout << 2 * N << endl;
  return 0;
}

Measured memory_bytes: 256
import itertools
import math
n = int(input())
x1 = []
y1 = []
for i in range(n):
    x, y = map(int, input().split())
    x1.append(x)
    y1.append(y)
l = [i for i in range(n)]
l = list(itertools.permutations(l))
ans = []
for i in l:
    c = 0
    for x in range(1, len(i)):
        x2 = i[x-1]
        x3 = i[x]
        c += math.sqrt((x1[x2] - x1[x3])**2 + (y1[x2] - y1[x3]) ** 2) 
    ans.append(c)
print(sum(ans)*2/(len(l)*2))

Measured memory_bytes: 9252
#include<stdio.h>

int main(){
  int a, b, c, d;
  scanf("%d %d %d %d", &a, &b, &c, &d);

  int p[4] = {1, 7, 9, 4};

  int i;

  int k = 0;

  for(i = 0; i < 4; i++){
    if(a == p[i]){
      k++;
      p[i] = -1;
    }
  }


  for(i = 0; i < 4; i++){
    if(b == p[i]){
      k++;
      p[i] = -1;
    }
  }
  for(i = 0; i < 4; i++){
    if(c == p[i]){
      k++;
      p[i] = -1;
    }
  }
  for(i = 0; i < 4; i++){
    if(d == p[i]){
      k++;
      p[i] = -1;
    }
  }

  if(k == 4) printf("YES\n");
  else printf("NO\n");

  return 0;
}



Measured memory_bytes: 128
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N, M = map(int, input().split())
    A = sorted(map(int, input().split()))[::-1]

    if A[M-1] * 4 * M >= sum(A):
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# define MOD 1000000000+7
# define INF 1000000000
using namespace std;

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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
const int INF = 1000000001;

int main(){
  char a, b;
  cin >> a >> b;
  if((a=='H' && b=='H')||(a=='D' && b=='D')){
    cout << 'H' <<endl;
  }else{
    cout << 'D' <<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> T gcd(T a, T b){return !b?a:gcd(b,a%b);}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 466666;
char s[N];int n;ll res;int c0;
int main() {
	int cnt=0;scanf("%s",s+1);n=strlen(s+1);
	rep(i,1,n)cnt+=s[i]=='0';
	rep(i,1,n-cnt)res+=i+1>>1;
	rep(i,1,n)if(s[i]=='0')c0++;
	else{
		int j=i;while(j+1<=n&&s[j+1]=='1')j++;
		res+=1ll*(j-i+1>>1)*cnt;
		if(j-i+1&1)res+=cnt-(i-1-c0&1?c0>>1:c0+1>>1);
		i=j;
	}
	cout<<res;
	return 0;
}


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

int main(){
    ll n,x,m;
    cin >> n >> x >> m;
    vll a(m*2);

    if(n<10000000){
        ll kani=0;
        vll b(n+2);
        b[0]=x;
        for(int i=0;i<n;i++){
            b[i+1]=b[i]*b[i]%m;
        }
        for(int i=0;i<n;i++){
            kani+=b[i];
        }
        cout << kani << endl;
        return 0;
    }

    a[0]=x;
    rep(i,m*2){
        a[i+1]=a[i]*a[i]%m;
    }

    map<ll,ll> mp;
    int loop_num;
    int loop_end;
    rep(i,m*2){
        if(mp[a[i]]==1){
            loop_num=a[i];
            loop_end=i;
        }
        mp[a[i]]++;
    }

    int loop_start;
    rep(i,m*2){
        if(a[i]==loop_num){
            loop_start=i;
            break;
        }
    }
    ll loop_sum=0;
    for(int i=loop_start;i<loop_end;i++){
        loop_sum+=a[i];
    }

    ll ans=0;
    for(int i=0;i<loop_start;i++){
        ans+=a[i];
    }

    int loop_cnt=loop_end-loop_start;

    ans+=loop_sum*((n-loop_start)/loop_cnt);

    int nokori=(n-loop_start)%loop_cnt;

    for(int i=0;i<nokori;i++){
        ans+=a[loop_start+i];
    }
    
    cout << ans << endl;
}

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

int main(){
	// sengen
	int n;
	// nyuryoku
	cin >> n;
	long long a[n],b[n],c[n];
	for(int i=0;i<n;i++) cin >> a[i];
	for(int i=0;i<n;i++) cin >> b[i];
	for(int i=0;i<n;i++) cin >> c[i];
	// keisan
	sort(a,a+n);
	sort(b,b+n);
	sort(c,c+n);
	long long sum = 0;
	long long s[n] = {};
	for(int i=0;i<n;i++){
		int min = lower_bound(a,a + n,b[i]) - a;
		if(i == 0){
			s[0] = min;
		}else{
			s[i] = s[i-1] + min;
		}
	}
	for(int i=0;i<n;i++){
		int iter = lower_bound(b,b+n,c[i]) - b;
		if(iter == 0){
			continue;
		}else{
			sum += s[iter -1];
		}
	}
	// syutsuryoku
	cout << sum;
}

Measured memory_bytes: 3328
#include <stdio.h>
#include <stdlib.h>

int main(){
	int A, B, i;
	scanf("%d%d", &A, &B);
	char *S = (char *)malloc(sizeof(char) * (A + B + 2));
	scanf("%s", S);
	for(i = 0; i <= A + B; i++){
		if(i == A){
			if(S[i] != '-'){
				printf("No\n");
				return 0;
			}
		}
		else{
			if(!((int)'0' <= (int)S[i] && (int)S[i] <= (int)'9')){
				printf("No\n");
				return 0;
			}
		}
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;

int main() {
	int A, B, C, K;
	int d;
	cin >> A >> B >> C >> K;
	
	if( A >= K ){
		cout << K;
	}
	else if(A < K && A + B >= K){
		cout << A;
	}
	else {
		cout << A - (K - A - B);
	}

	return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
signed main() {
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	if (a[0] == 5 && a[1] == 5 && a[2] == 7)puts("YES");
	else puts("NO");
	getchar(); getchar();
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;
ll dp[101][21];
ll a[101],n;
int main()
{
	scanf("%lld",&n);
	for(ll i=0;i<n;i++){
		scanf("%lld",&a[i]);
	}
	dp[0][a[0]]=1;
	for(ll i=1;i<n-1;i++){
		for(ll j=0;j<=20;j++){
			if(dp[i-1][j]){
				if(j+a[i]<=20){
					dp[i][j+a[i]]+=dp[i-1][j];
				}
				if(j-a[i]>=0){
					dp[i][j-a[i]]+=dp[i-1][j];
				}
			}
		}
	}
	printf("%lld\n",dp[n-2][a[n-1]]);
}

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

int main() {
   char s1[10];
   char s2[10];
   char s3[10];
scanf("%s%s%s",s1,s2,s3) ;   
   
   
      if((s1[0] >= 97 )&& (s1[0] <= 122)) {
         s1[0] = (s1[0] - 32);
      }
        printf("%c",s1[0])  ;         
      if(s2[0] >= 97 && s2[0] <= 122)
	  s2[0] = (s2[0] - 32); 
      	printf("%c",s2[0])  ; 
          
      
          
          if(s3[0] >= 97 && s3[0] <= 122) {
         s3[0] = (s3[0] - 32);
      }
         printf("%c",s3[0])  ; 
     }
        

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

template <std::uint_fast64_t Modulus> class modint {
    using u64 = std::uint_fast64_t;
    
public:
    u64 a;
    
    modint(const u64 x = 0) noexcept : a(x % Modulus) {}
    u64 &value() { return a; }
    const u64 &value() const { return a; }
    modint operator+(const modint rhs) const  {
        return modint(*this) += rhs;
    }
    modint operator-(const modint rhs) const {
        return modint(*this) -= rhs;
    }
    modint operator*(const modint rhs) const {
        return modint(*this) *= rhs;
    }
    modint operator/(const modint rhs) const {
        return modint(*this) /= rhs;
    }
    modint &operator+=(const modint rhs) {
        a += rhs.a;
        if (a >= Modulus) {
            a -= Modulus;
        }
        return *this;
    }
    modint &operator-=(const modint rhs) {
        if (a < rhs.a) {
            a += Modulus;
        }
        a -= rhs.a;
        return *this;
    }
    modint &operator*=(const modint rhs) {
        a = a * rhs.a % Modulus;
        return *this;
    }
    modint &operator/=(modint rhs) {
        u64 exp = Modulus - 2;
        while (exp) {
            if (exp % 2) {
                *this *= rhs;
            }
            rhs *= rhs;
            exp /= 2;
        }
        return *this;
    }
};


const int mx = 100005;
int c[3];

int main(){
    int n;
    cin >> n;
   
    long long ans = 1;
    
    for (int i=1; i<=n; i++) {
        long long a;
        cin >> a;
        int id = -1;
        int count = 0;
        if (a==c[0]) { count++; id = 0; }
        if (a==c[1]) { count++; id = 1; }
        if (a==c[2]) { count++; id = 2; }
        c[id]++;
        ans *= count;
        ans %= mod;
        if (id<0) {
            cout << "0" << endl;
            return 0;
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
 
int main() {
  int N;
  while(cin >>N && N){
    stringstream ss;
    while(N){
      int n = N % (-10);
      N /= (-10);
      if(n >= 0) ss << n;
      else {
        ss << (10 - abs(n));
        N++;
      }
    }
    string s = ss.str();
    REVERSE(s);
    cout <<s <<endl;
  }
  return 0;
}

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

#define ll          long long
#define pb          push_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
void solve(){
    ll n;
    cin>>n;
    ll ans=0;
    rep(i,1,n){
        if(i%3!=0 && i%5!=0) ans+=i;
    }
    cout<<ans;
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}


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

int main(){
  int a[4] = {};
  rep(i,3) {
    int u, v;
    cin >> u >> v;
    u--; v--;
    a[u]++; a[v]++;
  }
  int c = 0;
  rep(i,4) c = max(c,a[i]);
  cout << (c == 3? "NO" : "YES") << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define lb(s,x) (lower_bound(all(s),x)-s.begin())
#define ub(s,x) (upper_bound(all(s),x)-s.begin())
#define uniq(a) a.erase(unique(all(a)),a.end())
#define bit(k) (1LL<<(k))
#define INF int(1e9)

template<class T,class U> ostream& operator<<(ostream& ost, const pair<T,U> &p) { ost << "(" << p.first << ", " << p.second << ")"; return ost; }
#define ostream_container { ost << "{"; for(const auto &t : v) { if (&t != &*v.begin()) ost << ", "; ost << t; } ost << "}"; return ost; }
template<class T> ostream& operator<<(ostream &ost, const vector<T> &v) ostream_container
template<class T> ostream& operator<<(ostream &ost, const set<T> &v) ostream_container
template<class T,class U> ostream& operator<<(ostream &ost, const map<T,U> &v) ostream_container

template<class H> void recursive_debug(string s, H h) {
    cerr << "\033[33m" << s << " = " << h << endl << "\033[m";
}
template<class H,class... T> void recursive_debug(string s, H h, T... t) {
    int comma = s.find(',');
    cerr << "\033[33m" << s.substr(0,comma) << " = " << h << ", ";
    recursive_debug(s.substr(comma+1), t...);
}
#define debug(...) recursive_debug(#__VA_ARGS__, __VA_ARGS__)


struct Camel
{
    ll diff, small, pos;
    bool operator>(const Camel& rhs) const {
        return diff > rhs.diff;
    }
    bool operator<(const Camel& rhs) const {
        return diff < rhs.diff;
    }
};


int main(void) {
    int T;
    cin >> T;
    while(T--) {
        ll n;
        cin >> n;
        priority_queue<Camel> pqL, pqR;
        rep(i,n){
            ll k, l, r;
            cin >> k >> l >> r;
            if (l > r) {
                pqL.push({l-r, r, k-1});
            } else {
                pqR.push({r-l, l, k});
            }
        }
        ll score = 0;
        set<ll> stL;
        rep(i,n){
            stL.insert(-i);
        }
        while(pqL.size()){
            Camel top = pqL.top(); pqL.pop();
            if(stL.lower_bound(-top.pos) != stL.end()) {
                auto itr = stL.lower_bound(-top.pos);
                score += top.diff + top.small;
                stL.erase(itr);
            } else {
                score += top.small;
            }
        }
        set<ll> stR;
        rep(i,n){
            stR.insert(i);
        }
        while(pqR.size()){
            Camel top = pqR.top(); pqR.pop();
            if(stR.lower_bound(top.pos) != stR.end()) {
                auto itr = stR.lower_bound(top.pos);
                score += top.diff + top.small;
                stR.erase(itr);
            } else {
                score += top.small;
            }
        }
        cout << score << endl;
    }
    return 0;
}


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

int main() {
  string s; cin >> s;
  rep(i,3) {
    if(s[i]=='1') s[i]='9';
    else s[i]='1';
  }
  cout << s << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <math.h>
using namespace std;

int main() {
    long long A, B, C;
    cin >> A >> B >> C;

    if (A + B + C >= 22) {
        cout << "bust" << endl;
    } else {
        cout << "win" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
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;
}

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

    int N;
    cin >> N;
    vector<int> A(N);
    for (auto &&i : A) {
        cin >> i;
    }

    int ans = 0;
    multiset<int> st;
    REP(i, N) {
        if (st.empty()) {
            ans++;
            st.insert(A[i]);
        } else {
            auto stitr = st.lower_bound(A[i]);
            if (stitr == st.begin()) {
                ans++;
                st.emplace(A[i]);
            } else {
                stitr--;
                st.erase(stitr);
                st.emplace(A[i]);
            }
        }
    }

    std::cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 5376