akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;



int main(){
    deque<char> q;
    string s;
    cin>>s;
    for(char ch:s)q.push_back(ch);
    int Q;
    cin>>Q;
    bool rev = false;
    while(Q--)
    {
        int T;
        cin>>T;
        if(T==1)
        {
            rev = !rev;
        }else
        {
            int F;
            char c;
            cin>>F>>c;
            F--;
            if(F ^ rev)
                q.push_back(c);
            else 
                q.push_front(c);
        }
    }
    string res;
    for(auto c:q)res += c;
    if(rev)reverse(res.begin(),res.end());
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 1412
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod = 1e9 + 7;

int main() {
  string s;
  cin >> s;
  if (s[2] == s[3] && s[4] == s[5])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

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

int main() {
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;

    vector<int64_t> p(a);
    vector<int64_t> q(b);
    vector<int64_t> r(c);

    for (int i = 0; i < a; i++){
        cin >> p.at(i);
    }

    for (int i = 0; i < b; i++){
        cin >> q.at(i);
    }

    for (int i = 0; i < c; i++){
        cin >> r.at(i);
    }

    sort(p.begin(), p.end(), greater<int64_t>());
    sort(q.begin(), q.end(), greater<int64_t>());
    sort(r.begin(), r.end(), greater<int64_t>());

    vector<int64_t> eat(x + y);

    for (int i = 0; i < x; i++){
        eat.at(i) = p.at(i);
    }

    for (int i = 0; i < y; i++){
        eat.at(i + x) = q.at(i);
    }

    sort(eat.begin(), eat.end());

    int index = 0;
    for (int i = 0; i < x + y; i++){
        if (index >= r.size()){
            break;
        }

        if (eat.at(i) < r.at(index)){
            eat.at(i) = r.at(index);
            index ++;
        }
    }

    int64_t sum = 0;
    for (int i = 0; i < x + y; i++){
        sum += eat.at(i);
    }

    cout << sum << endl;
}


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

int main() {
    string a, b;
    cin >> a;
    int l = a.size() - 1;
    if (a.substr(l) == "s") b = "es";
    else b = "s";
    string c = a + b;
    cout << c << endl;
    return 0;
}

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

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

    int ans = 0;
    int x = 0;
    rep(i, n) {
        if (s[i] == 'I')
            x++;
        else
            x--;
        ans = max(ans, x);
    }

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


Measured memory_bytes: 3576
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main(){
    string s,t;
    cin>>s>>t;
    
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    reverse(t.begin(),t.end());
    
    if(s.size()<t.size()){
        for(int i=0;i<t.size()-s.size();i++) s+="0";
    }else if(s.size()>t.size()){
        for(int i=0;i<s.size()-t.size();i++) t+="0";
    }
    
    if(s<t) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
    return 0;
}

Measured memory_bytes: 256
L = [ 1, 0, 0]

d = {}
for i in range(len("ABC")):
    d["ABC"[i]] = i

while True:
    try:
        s, t = input().split(",")
        L[d[s]], L[d[t]] = L[d[t]], L[d[s]]
        pass
    except EOFError:
        break
    
for i in range(len(L)):
    if L[i] > 0:
        print("ABC"[i])
    


Measured memory_bytes: 5560
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (long long int i = f; i < t; i++)
#define pr(i, f, t) for (long long int i = t - 1; i >= f; i--)
#define ca(n, a) rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define ia(n, a) rp(ia_i, 0, n) cin >> a[ia_i]
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
#define ce(a) cout << (a) << endl
int main()
{
    ll a;
    cin >> a;
    ce(a * (1 + a + a * a));
}

Measured memory_bytes: 3632
# B - Buildings are Colorful!

import sys
input = sys.stdin.buffer.readline

import itertools

N, K = map(int, input().split())
original_a = list(map(int, input().split()))

if K == 1:
    print(0)
    exit()

ans = float("inf")
for visible_building_indices in list(itertools.combinations(list(range(N)), K)):
    a = original_a.copy()
    tmp = 0

    for i in range(len(visible_building_indices)):
        try:
            h = max([a[i] for i in range(visible_building_indices[i])])
        except:
            h = 0
        if h >= a[visible_building_indices[i]]:
            tmp += h - a[visible_building_indices[i]] + 1
            a[visible_building_indices[i]] = h + 1

    ans = min(ans, tmp)

print(ans)

Measured memory_bytes: 3444
from collections import defaultdict

n = int(input())
fact = defaultdict(int)
fact[1] = 1
f = 2
k = n
while f * f <= min(k * k, n):
    if k % f == 0:
        fact[f] += 1
        k //= f
    else:
        f += 1
if k > 1:
    fact[k] += 1


def digits(n):
    ret = 0
    while n > 0:
        ret += 1
        n //= 10
    return ret


def dfs(index, mul, fact):
    if index >= len(fact):
        return max(digits(mul), digits(n // mul))
    k, v = fact[index]
    ret = 10
    for i in range(v + 1):
        ret = min(ret, dfs(index + 1, mul * pow(k, i), fact))
    return ret


print(dfs(0, 1, list(fact.items())))

Measured memory_bytes: 3316
#if defined(LOCAL)
const double _max_double_error = 1e-9;
#include "testutils.h"
#define L(x...) (debug(x, #x))
#define I(x, ...) (x)
#define C(x...) CHECK(x)
#else
#define L(x, ...) (x)
#define I(x, ...) (x)
#define C(x, ...) ;
#endif
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <numeric>
#include <queue>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ii = pair<int, int>;
using lu = unsigned long long;
using l = long long;
using vs = vector<string>;
using vii = vector<ii>;
using vl = vector<l>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using ll = pair<l, l>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vd = vector<double>;
using vvd = vector<vd>;
using mll = unordered_map<l, l>;
using sl = unordered_set<l>;
const l INF = numeric_limits<l>::max();
const double EPS = 1e-10;
const double PI = 3.14159265358979323846;
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 VVL(x, a, b, i) vvl x(a, vl(b, l(i)));
#define VVVL(x, a, b, c, i) vvvl x(a, vvl(b, vl(c, l(i))));

void solve(istream &in, ostream &out);
int main(int argc, char **argv) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
#if defined(LOCAL)
  tst::test_init(argc, argv);
  // _generate_random_test = generate_random;
  // _solve_brute = solve_brute;
  // _player_b = player_b;
  // _custom_solution_checker = solution_checker;
  tst::maybe_run_tests(cin, cout);
#else
  solve(cin, cout);
#endif
}
const l MOD = e9 + 7; // end of template

void solve(istream &in, ostream &out) {
  l n, k; in >> n >> k;
  // TODO: fix compilation of discrete.
  vl v(n); F(i, 0, n) in >> v[i];
  vl sums(n * (n + 1) / 2);
  l p = 0;
  l m = 0;
  F(i, 0, n) {
    l s = 0;
    F(j, i, n) {
      s += v[j];
      sums[p++] = s;
      m = max(m, s);
    }
  }
  C(p == sums.size());
  l d = 0;
  while ((l(1) << d) <= m) d++;
  l z = 0;
  B(i, 0, d) {
    l t = z + (l(1) << i);
    l c = 0;
    for (const l x : sums) {
      if ((x & t) == t) c++;
    }
    if (c >= k) z = t;
  }
  out << z << lf;
}


Measured memory_bytes: 4224
from fractions import gcd
def lcm(num1, num2):
    return (num1 * num2) // gcd(num1, num2)
A, B, C, D = map(int, input().split())
a = lcm(C, D)
print((B-A+1) - (B//C - (A-1)//C) - (B//D - (A-1)//D) + (B//a - (A-1)//a))

Measured memory_bytes: 5600
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    string s, t; cin >> s >> t;
    int n_s = s.size();
    int n_t = t.size();
    queue<char> q;
    rep(i,n_t) q.push(t[i]);
    vvint data(26);
    rep(i,2*n_s) {
        data[s[i%n_s]-'a'].push_back(i);
    }
    rep(i,n_t) {
        if (data[t[i]-'a'].size() == 0) {cout << -1 << endl; return 0;}
    }
    ll ans = 0;
    while (true) {
        int now = 0;
        while (!q.empty()) {
            now = *lower_bound(all(data[q.front()-'a']),now)+1;
            if (now > n_s) {ans += n_s; break;}
            q.pop();
        }
        if (q.empty()) {ans += now; break;}
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [int(input()) for _ in range(n)]

a,b,c = map(int, input().split())

if ( a+b >= c):
    print("Yes")
else:
    print("No")







Measured memory_bytes: 9104
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int n;
vector<vector<int>> to, timestamp;

void dfs(int v, int& t) {
    timestamp[v][0] = t++;
    for (int i = 0; i < to[v].size(); ++i) {
        int nv = to[v][i];
        if (timestamp[nv][0] > 0) continue;
        dfs(nv, t);
    }
    timestamp[v][1] = t++;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n;
    to.resize(n);
    rep(i, n) {
        int u, k;
        cin >> u >> k;
        u--;
        rep(j, k) {
            int v;
            cin >> v;
            v--;
            to[u].push_back(v);
        }
    }

    timestamp.resize(n, vector<int>(2, 0));
    int t = 1;
    rep(i, n) {
        if (timestamp[i][0] == 0) dfs(i, t);
    }

    rep(i, n) {
        cout << i+1 << " " << timestamp[i][0] << " " << timestamp[i][1] << endl;
    }
}


Measured memory_bytes: 3252
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    
    int abc = a + b + c;
    
    if (abc == 17) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
  }
}

Measured memory_bytes: 21844
#include <stdio.h>
struct point{
    double x;
    double y;
};
double abs(double a){
    if(a<0)return -a;
    return a;
}
double triangle(point a,point b,point c){
    return abs(a.x*b.y+b.x*c.y+c.x*a.y-a.y*b.x-b.y*c.x-c.y*a.x);
}
int main(){
    point a[4];
    while(scanf("%lf%lf",&a[0].x,&a[0].y)!=EOF){
        for(int i=1;i<4;i++)scanf("%lf%lf",&a[i].x,&a[i].y);
        if(triangle(a[0],a[1],a[2])==triangle(a[0],a[1],a[3])+triangle(a[0],a[2],a[3])+triangle(a[2],a[1],a[3])){
            printf("YES\n");
        }
        else printf("NO\n");
    }
}

Measured memory_bytes: 2576
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
typedef pair<P,int>P2;
struct Kruskal{

  struct UnionFind{
    int n;
    vector<int> r,p;
    UnionFind(){}
    UnionFind(int sz):n(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);}
    int find(int x){
      return (x==p[x]?x:p[x]=find(p[x]));
    }
    bool same(int x,int y){
      return find(x)==find(y);
    }
    void unite(int x,int y){
      x=find(x);y=find(y);
      if(x==y) return;
      if(r[x]<r[y]) swap(x,y);
      r[x]+=r[y];
      p[y]=x;
    }
  };
  
  struct edge{
    int from,to,cost,used;
    edge(){}
    edge(int from,int to,int cost):
      from(from),to(to),cost(cost),used(0){}
    bool operator<(const edge& e) const{
      return cost<e.cost;
    }
  };

  int n;
  vector<edge> edges;

  Kruskal(){}
  Kruskal(int sz):n(sz){}
  
  void add_edge(int u,int v,int c){
    edges.emplace_back(u,v,c);
  }

  void input(int m,int offset=0){
    int a,b,c;
    for(int i=0;i<m;i++){
      cin>>a>>b>>c;
      add_edge(a+offset,b+offset,c);
    }
  }
  
  int build(){
    sort(edges.begin(),edges.end());
    UnionFind uf(n+1);
    int res=0;
    for(auto &e:edges){
      if(!uf.same(e.from,e.to)){
  res+=e.cost;
  uf.unite(e.from,e.to);
  e.used=1;
      }
    }
    return res;
  }
};
vector<P2>v1,v2;
int x,y,n;

int main(){
  cin>>n;
  Kruskal K(n);
  rep(i,n){
    cin>>x>>y;
    v1.push_back(P2(P(x,y),i));
    v2.push_back(P2(P(y,x),i));
  }
  sort(v1.begin(),v1.end());
  sort(v2.begin(),v2.end());
  rep(i,n){
    if(i!=0)K.add_edge(v1[i].second,v1[i-1].second,v1[i].first.first-v1[i-1].first.first);
    if(i!=n-1)K.add_edge(v1[i].second,v1[i+1].second,v1[i+1].first.first-v1[i].first.first);
  }
  rep(i,n){
    if(i!=0)K.add_edge(v2[i].second,v2[i-1].second,v2[i].first.first-v2[i-1].first.first);
    if(i!=n-1)K.add_edge(v2[i].second,v2[i+1].second,v2[i+1].first.first-v2[i].first.first);
  }
  cout<<K.build()<<endl;
}

Measured memory_bytes: 13732
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s, t;
    cin >> n >> s >> t;
  	int p = -1;
    rep(i,n){
        bool ok = true;
        rep(j,n-i){
            if(s[i+j] != t[j]){
                ok = false;
                break;
            }
        }
        if(ok){
            p = i;
          	break;
        }
    }
    if(p != -1) cout << n + p << endl;
  	else cout << 2*n << endl;
    return 0;
}


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

bool solve() {
    string S, T;
    cin >> S >> T;
    T.pop_back();
    return S == T;
}

int main() {
    string ans = solve() ? "Yes" : "No";
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3556
#include <iostream>
#include <cstdio>
#include <bitset>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>

using namespace std;

#define ll long long
#define vec vector
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)

int main()
{
	ll n;
	bool flag = true;
	string s;

	cin >> s;

	forll(i, 0, s.size())
	{
		if (i % 2 == 0)
		{
			if (s[i] == 'L')
			{
				flag = false;
				break;
			}
		}
		else
		{
			if (s[i] == 'R')
			{
				flag = false;
				break;
			}
		}
	}

	if (flag)
		cout << "Yes";
	else
		cout << "No";

}

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

using namespace std;

const int N=500005;

int l,r,a[N],ans,R[N];

int main(){
	char c;
	for(c=getchar();c<'0'||c>'9';c=getchar());
	for(a[l=r=1]=c&15,c=getchar();c<='9'&&c>='0';c=getchar())a[++r]=c&15;
	a[r+1]=233;
	for(int i=r;i>=l;i--)R[i]=a[i]==a[i+1]?R[i+1]:i;
	while(l<=r){
		ans++;
		while(a[l]<=a[R[l]+1]&&l<r)a[l++]=0;
		a[r]++;a[l]=0;
		int p=r;
		for(int i=r;a[i]>=10;i--){
			a[i]-=10,a[i-1]++;
			R[i]=a[i]==a[i+1]?R[i+1]:i;
			p=i-1;
		}
		while(p--){
			int w=R[p];
			R[p]=a[p]==a[p+1]?R[p+1]:p;
			if(R[p]==w)break;
		}
		while(a[l]==0&&l<=r)l++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる
 
 
 
 
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
 
  ll n,d,a;
  cin>>n>>d>>a;
 
  map<ll,ll> mon;
  set<ll> za;
  rep(i,n){
    ll x,h;
    cin>>x>>h;
    ll kai=(h+a-1)/a;
    mon[x]=kai;
    za.insert(x);
    za.insert(x+2*d+1);
  }
 
  vector<ll> ba;
  for(auto z : za){
    ba.pb(z);
  }
  
  sort(all(ba));
 
  map<ll,ll> gen;
 
  ll ans=0;
  ll now=0;
  rep(i,ba.size()){
    if(gen.count(ba[i])) {
      now-=gen.at(ba[i]);
    }
    if(mon.count(ba[i])) {
      ll bom=max(0ll,mon.at(ba[i])-now);
      ans+=bom;
      gen[ba[i]+2*d+1]=bom;
      now+=bom;
    }
  }
 
  cout << ans << endl;
}

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

const int MAX_V=1050;
const int INF=1e9;

struct edge{
    int to,cap,rev;
    edge(int to=0,int cap=0,int rev=0)
        :to(to),cap(cap),rev(rev){}
};

vector<edge>G[MAX_V];
bool used[MAX_V];

void init(){
    for(int i=0;i<MAX_V;i++)G[i].clear();
}

void add_edge(int from,int to,int cap){
    G[from].push_back(edge(to,cap,G[to].size()));
    G[to].push_back(edge(from,0,G[from].size()-1));
}

int dfs(int v,int t,int f){
    if(v==t)return f;
    used[v]=true;

    for(int i=0;i<G[v].size();i++){
        edge &e=G[v][i];
        if(e.cap==0||used[e.to])continue;
        int d=dfs(e.to,t,min(f,e.cap));
        if(d){
            e.cap-=d;
            G[e.to][e.rev].cap+=d;
            return d;
        }
    }
    return 0;
}

int max_flow(int s,int t){
    int flow=0;
    while(true){
        fill_n(used,MAX_V,false);
        int f=dfs(s,t,INF);
        if(f)flow+=f;
        else return flow;
    }
}

int main(){
    int S=1000,T=1001;
    int n,m;
    while(cin>>n>>m,n||m){
        init();

        vector<int>a(n),b(m);
        for(int i=0;i<n;i++)cin>>a[i];
        for(int i=0;i<m;i++)cin>>b[i];

        for(int i=0;i<n;i++)add_edge(S,i,1);
        for(int i=0;i<m;i++)add_edge(i+n,T,1);

        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(__gcd(a[i],b[j])==1)continue;
                add_edge(i,j+n,1);
            }
        }

        cout<<max_flow(S,T)<<endl;
    }

    return 0;
}

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

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;


struct union_find{
  vector<int> par,r,size;

  union_find(int n) : par(n),r(n),size(n){init(n);}

  void init(int n){
    for(int i = 0; i < n; i++) par[i] = i;
    for(int i = 0; i < n; i++) r[i] = 0;
    for(int i = 0; i < n; i++) size[i] = 1;
  }

  int find(int x){
    if(par[x] == x) return x;
    else return find(par[x]);
  }

  void unite(int x,int y){
    x = find(x);
    y = find(y);
    if(x == y) return;
    if(r[x] < r[y]){
      par[x] = y;
      size[y] += size[x];
    }else{
      par[y] = x;
      size[x] += size[y];
      if(r[x] == r[y]) r[x]++;
    }
  }

  bool same(int x,int y){
    return find(x) == find(y);
  }
};

int main()
{
	ll n,m;
	cin>>n>>m;
	vector<pair<int,int> > edge(m);
	for(int i = 0; i < m; i++){
		int a,b;
		cin>>a>>b;
		a--;b--;
		edge[i] = pair<int,int>(a,b);
	}

	reverse(all(edge));
	vector<ll> ans;
	ans.push_back((n-1)*n/2);
	ll now = (n-1)*n/2;
	union_find uf(n);
	ll cnt = 0;
	// ll node=n;
	for(int i = 0; i < m; i++){
		int a = edge[i].first,b=edge[i].second;
		if(uf.same(a,b)) ans.push_back(now);
		else{
			// node += (uf.size[uf.find(a)]+uf.size[uf.find(b)]);



			// cnt += (uf.size[uf.find(a)]+uf.size[uf.find(b)]);
			cnt += uf.size[uf.find(a)]*uf.size[uf.find(b)];


			uf.unite(a,b);



			// cout << uf.find(a)+1 << " " << uf.size[uf.find(a)] << endl;
			// int k = uf.size[uf.find(a)];
			// cout << " k = " << k << endl;
			// cnt -= (k-1)*k/2;
			now = (n-1)*n/2-cnt;
			// if(k==n) now = 0;

			// cout << "now  = " << now << endl;
			ans.push_back(now);
		}
	}
	reverse(all(ans));
	for(int i = 1; i < ans.size(); i++){
		cout << ans[i] << endl;
	}

	return 0;
}

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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    for (;;) {
        c -= b;
        if (c <= 0) break;
        a -= d;
        if (a <= 0) break;
    }
    cout << (c <= 0 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3532
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<vector>
using namespace std;
int main()
{
    char s[4];
    scanf("%s",s);
    if(strcmp(s,"ABC")==0)
        cout<<"ARC";
    else
        cout<<"ABC";
    return 0;
}

Measured memory_bytes: 3656
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            String str = br.readLine();
            str = str.replace("2017/01", "2018/01");
            System.out.println(str);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}


Measured memory_bytes: 22484
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int h = Integer.parseInt(sc.next());
        int w = Integer.parseInt(sc.next());
        
        int[][] maze = new int[h+2][w+2];
        for(int i = 1; i <= h; i++){
            String s = sc.next();
            for(int j = 1; j <= w; j++){
                if(s.charAt(j-1) == '.'){
                    maze[i][j] = 1;
                }
            }
        }
        
        int max = 0;
        for(int i = 1; i <= h; i++){
            for(int j = 1; j <= w; j++){
                if(maze[i][j] == 0) continue;
                int[][] dist = new int[h+2][w+2];
                for(int k = 1; k <= h; k++){
                    Arrays.fill(dist[k], -1);
                }
                ArrayDeque<Integer> queue = new ArrayDeque();
                dist[i][j] = 0;
                queue.add(i*100 + j);
                while(!queue.isEmpty()){
                    int u = queue.poll();
                    int y = u/100;
                    int x = u%100;
                    if(maze[y-1][x] == 1 && dist[y-1][x] == -1){
                        dist[y-1][x] = dist[y][x] +1;
                        if(dist[y-1][x] > max) max = dist[y-1][x];
                        queue.add((y-1)*100 + x);
                    }
                    if(maze[y+1][x] == 1 && dist[y+1][x] == -1){
                        dist[y+1][x] = dist[y][x] +1;
                        if(dist[y+1][x] > max) max = dist[y+1][x];
                        queue.add((y+1)*100 + x);
                    }
                    if(maze[y][x-1] == 1 && dist[y][x-1] == -1){
                        dist[y][x-1] = dist[y][x] +1;
                        if(dist[y][x-1] > max) max = dist[y][x-1];
                        queue.add(y*100 + x-1);
                    }
                    if(maze[y][x+1] == 1 && dist[y][x+1] == -1){
                        dist[y][x+1] = dist[y][x] +1;
                        if(dist[y][x+1] > max) max = dist[y][x+1];
                        queue.add(y*100 + x+1);
                    }
                }
            }
        }
        
        System.out.println(max);
    }
}

Measured memory_bytes: 28744
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 998244353
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 1010
using namespace std;
ll n,m,c1,c2,d1,d2,dp[N][N];
char buf[N];
string s[N];
deque<pair<pair<ll,ll>,ll> > dq;
int main(){
	ll i,j,x,y,tx,ty;
	scanf("%lld%lld",&n,&m);
	scanf("%lld%lld",&c1,&c2);
	scanf("%lld%lld",&d1,&d2);
	c1--;
	c2--;
	d1--;
	d2--;
	for(i=0;i<n;i++)
	{
		scanf("%s",&buf);
		s[i]=buf;
	}
	memset(dp,127,sizeof(dp));
	dp[c1][c2]=0;
	dq.push_back(make_pair(make_pair(c1,c2),0));
	while(!dq.empty())
	{
		x=dq.front().F.F;
		y=dq.front().F.S;
		if(dq.front().S!=dp[x][y])
		{
			dq.pop_front();
			continue;
		}
		dq.pop_front();
		tx=x+1;
		ty=y;
		if(tx>=0&&tx<n&&ty>=0&&ty<m)
		{
			if(dp[tx][ty]>dp[x][y]&&s[tx][ty]=='.')
			{
				dp[tx][ty]=dp[x][y];
				dq.push_front(make_pair(make_pair(tx,ty),dp[tx][ty]));
			}
		}
		tx=x-1;
		ty-y;
		if(tx>=0&&tx<n&&ty>=0&&ty<m)
		{
			if(dp[tx][ty]>dp[x][y]&&s[tx][ty]=='.')
			{
				dp[tx][ty]=dp[x][y];
				dq.push_front(make_pair(make_pair(tx,ty),dp[tx][ty]));
			}
		}
		tx=x;
		ty=y+1;
		if(tx>=0&&tx<n&&ty>=0&&ty<m)
		{
			if(dp[tx][ty]>dp[x][y]&&s[tx][ty]=='.')
			{
				dp[tx][ty]=dp[x][y];
				dq.push_front(make_pair(make_pair(tx,ty),dp[tx][ty]));
			}
		}
		tx=x;
		ty=y-1;
		if(tx>=0&&tx<n&&ty>=0&&ty<m)
		{
			if(dp[tx][ty]>dp[x][y]&&s[tx][ty]=='.')
			{
				dp[tx][ty]=dp[x][y];
				dq.push_front(make_pair(make_pair(tx,ty),dp[tx][ty]));
			}
		}
		for(i=max((ll)0,x-2);i<min(n,x+3);i++)
		{
			for(j=max((ll)0,y-2);j<min(m,y+3);j++)
			{
				if(dp[i][j]>dp[x][y]+1&&s[i][j]=='.')
				{
					dp[i][j]=dp[x][y]+1;
					dq.push_back(make_pair(make_pair(i,j),dp[i][j]));
				}
			}
		}
	}
	if(dp[d1][d2]<LINF)
	{
		printf("%lld\n",dp[d1][d2]);
	}
	else
	{
		puts("-1");
	}
	return 0;
}

Measured memory_bytes: 13036
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

#define INF 1000000010

int main(){
  int n,x;
  
  while(cin>>n>>x){
    if(n==0 && x==0) return 0;
  int cnt=0;
  
  for(int i=1;i<=n;i++){
    for(int j=i+1;j<=n;j++){
      for(int k=j+1;k<=n;k++){
        if(i+j+k==x) cnt++;
      }
    }
  }
  
  cout<<cnt<<endl;
  }
      
  return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cstdio>

using namespace std;

int main()
{
	string s;
	int q;
	cin >> s >> q;
	cin.ignore();
	
	string buf;
	while (q)
	{
		getline(cin, buf);
		
		//cout << "DEBUG:" << buf << endl;
		
		if (buf.find("replace ") != string::npos)
		{
			char cmd[10] = {0};
			int a1, a2;
			char a3[1001] = {0};
			sscanf(buf.c_str(), "%s %d %d %s", cmd, &a1, &a2, a3);
			s.replace(a1, (a2+1)-a1, string(a3));
			//cout << "DEBUG:replaced:" << s << endl;
		}
		else if (buf.find("reverse ") != string::npos)
		{
			char cmd[10] = {0};
			int a1, a2;
			sscanf(buf.c_str(), "%s %d %d", cmd, &a1, &a2);
			string sub = s.substr(a1, (a2+1)-a1);
			//cout << "DEBUG:sub( ):" << sub << endl;
			reverse(sub.begin(), sub.end());
			//cout << "DEBUG:sub(r):" << sub << endl;
			size_t subsize = sub.size();
			for (int i = a1, j = 0; i < a1 + subsize; i++, j++) {
				s[i] = sub[j];
			}
			//cout << "DEBUG:reversed:" << s << endl;
		}
		else if (buf.find("print ") != string::npos)
		{
			char cmd[10] = {0};
			int a1, a2;
			sscanf(buf.c_str(), "%s %d %d", cmd, &a1, &a2);
			cout << s.substr(a1, (a2+1)-a1) << endl;
		}
		q--;
	}
	
	return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<vector>

using namespace std;

inline int read()
{
   int x=0,f=1;char ch=getchar();
   while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
   while (isdigit(ch)){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
   return x*f;
}

int a,b;
int n;

int co(int x)
{
	int cnt=0;
	while (x)
	{
		cnt+=x%10;
		x/=10;
	}
	return cnt;
}

int main()
{
  cin>>n;
  int ans=2e9;
  for (int i=1;i<n;i++)
  {
  	 ans=min(ans,co(i)+co(n-i));
  }
  cout<<ans;
  return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long N;
	cin >> N;
	long long ans = 0;
	for(long long i=1;i<=N;i++){
		long long M = N / i;
		ans += i * M * (M + 1) / 2;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  string s;
  cin>>n>>k>>s;
  if(s.at(k-1)=='A'){s.at(k-1)='a';}
  else if (s.at(k-1)=='B'){s.at(k-1)='b';}
  else{s.at(k-1)='c';}
cout<<s<<endl;

}


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

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            string[] strs = line.Split(' ');
            int N = int.Parse(strs[0]);
            int M = int.Parse(strs[1]);
            line = Console.ReadLine();
            strs = line.Split(' ');
            int[] H = new int[N];
            for (int i = 0; i < N; i++) H[i] = int.Parse(strs[i]);

            List<Tuple<int, int>> tuples = new List<Tuple<int, int>>();

            bool[] yoi = new bool[N];
            for (int i = 0; i < N; i++) yoi[i] = true;
            for (int i = 0; i < M; i++)
            {
                line = Console.ReadLine();
                strs = line.Split(' ');
                var A = int.Parse(strs[0]) - 1;
                var B = int.Parse(strs[1]) - 1;
                if (H[A] < H[B])
                {
                    yoi[A] = false;
                }
                else if(H[A] > H[B])
                {
                    yoi[B] = false;
                }
                else
                {
                    yoi[A] = false;
                    yoi[B] = false;
                }
            }
            int count = 0;
            for(int i = 0; i < N; i++)
            {
                if (yoi[i]) count++; 
            }

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 48960
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t;
int cev;
string s;
vector<int> v;

int main(void){
	scanf("%d",&n);
	FOR{
		scanf("%d",&a[i]);
	}
	cev=1;
	FOR{
		if(a[i]==cev)cev++;
	}
	if(cev==1)cev=n+2;
	printf("%d\n",n-(cev-1));
	return 0;
}



Measured memory_bytes: 1024
# coding: utf-8
import math

A, B, C, X, Y = (int(x) for x in input().split())
ans = 0
if X > Y:
    MAX = X
else:
    MAX = Y

for c in range(MAX * 2 + 1):
    a = X - math.floor(c / 2)
    b = Y - math.floor(c / 2)
    if a < 0:
        a = 0
    if b < 0:
        b = 0
    fee = a * A + b * B + c * C
    if ans > fee or ans == 0:
         ans = fee

print(ans)

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

int main() {
	int N;
	cin >> N;
	vector<int> A(N), order(N);
	for (int i = 0; i < N; i++) {
		int tmp;
		cin >> tmp;
		A.at(i) = tmp;
		order.at(i) = tmp;
	}
	sort(order.begin(), order.end(), greater<int>());

	for (int i = 0; i < N; i++) {
		if (A.at(i) == order.at(0)) {
			cout << order.at(1) << endl;
		} else {
			cout << order.at(0) << endl;
		}
	}
}

Measured memory_bytes: 3200
n = int(input())
a = list(map(int, input().split()))
c4 = sum(1 for x in a if x % 4 == 0)
c1 = sum(1 for x in a if x % 2 == 1)
if c4 >= c1 or (c4 >= c1 - 1 and c4 + c1 == n):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 15020
#pragma GCC optimize("Ofast")
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<math.h>
#include<utility>
using namespace std;


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

    int counter = 0;
    int idx = 1;
    bool flag = false;
    for(int i=0;i<n;i++){
        if(a[i] == 1) flag = true;
    }

    if(flag){
        for(int i=0;i<n;i++){
            if(a[i] != idx){
                counter++;
            } else {
                idx++;
            }
        }
        cout << counter << endl;
    } else {
        cout << -1 << endl;
    }    
}

Measured memory_bytes: 1024
#include <iostream> 
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound

using namespace std;

int main() {
	int x, y;
	cin >> x >> y;

	if (x < y) swap(x, y);

	while (y > 0) {
		int r = x % y;
		x = y;
		y = r;
	}
	cout << x << endl;
	return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>    
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds; 
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long 
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 1000 * 100 + 10;
const ll N2      = 70;
const ld PI  = 3.141592653589793;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}

signed main()
{
    fastio();
    //cout<<fixed<<setprecision(20);
    //CHECK for LONG LONG and LONG DOUBLE
    /*comment for all except cc/cf    
    #ifndef ONLINE_JUDGE    
           freopen("input.txt","r",stdin);
           freopen("output.txt","w",stdout);
    #endif//*/
    int h1,m1,h2,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;
    h1*=60;
    h1+=m1;
    h2*=60;
    h2+=m2;
    h2-=k;
    cout<<h2-h1;

    printclock;
    return 0;
}


Measured memory_bytes: 3796
#include<stdio.h>
long long gcd,lcm;
void GCD(long long a,long long b){
	long long k;
	if(a<b){
		k=a;
		a=b;
		b=k;
	}
	if(a%b==0) gcd=b;
	else{
		k=a%b;
		GCD(b,k);
	}
}
int main(){
	int n,i;
	long long A[110];
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%lld",&A[i]);
	}
	lcm=A[1];
	for(i=2;i<=n;i++){
		GCD(lcm,A[i]);
		lcm=lcm/gcd*A[i];
	}
	printf("%lld\n",lcm);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define LL long long
using namespace std;
int main()
{
    LL a,b,x;
    LL term=0;
    cin>>a>>b>>x;
    term+=(b/x);
    term-=(a/x);
    if(a%x==0)
    {
        term++;
    }
    cout<<term<<endl;
    return 0;
}


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

using namespace std;

int main()
{
    string s;
    cin >> s;
    if(s.size()==2) {
        cout << s << endl;
    }
    else {
        if(s.size()==3) {
            reverse(s.begin(), s.end());
            cout << s << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<string>> vvstring;
typedef vector<vector<bool>> vvbool;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================



int main() {

	////==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	////==================================


	ll N, K;
	cin >> N >> K;

	if (K == 0)
	{
		cout << N * N << endl;
		return 0;
	}

	ll ans = 0;
	for (int b = 1; b <= N; b++)
	{

		ll set = N / b;
		ll last = N % b;

		ll adj = max(last - K + 1, (ll)0);

		ans += set * max(b - K, (ll)0) + adj;
	}

	cout << ans << endl;




}





Measured memory_bytes: 256
#include <stdio.h>

#define N 200000

int main() {
	static int aa[N], bb[N];
	int n, i, x, m;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	for (i = n - 1; i > 0; i--)
		if (aa[i] == 1)
			for (x = 1; x * x <= i + 1; x++)
				if ((i + 1) % x == 0) {
					aa[x - 1] = (aa[x - 1] + 1) % 2;
					if (x > 1 && x * x != i + 1)
						aa[(i + 1) / x - 1] = (aa[(i + 1) / x - 1] + 1) % 2;
				}
	m = 0;
	for (i = 0; i < n; i++)
		if (aa[i] == 1)
			bb[m++] = i;
	printf("%d\n", m);
	for (i = 0; i < m; i++)
		printf("%d ", bb[i] + 1);
	if (m > 0)
		printf("\n");
	return 0;
}


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

#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  string S;
  cin >> S;

  REP(i, 19) {
    if (S[i] == ',') {
      cout << " ";
    } else {
      cout << S[i];
    }
  }

  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
 
int main() {
  ll x,a;
  cin>>x>>a;
  if(x<a)cout << 0 << endl;
  else cout << 10 << endl;
}


Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <queue>
#include <stack>

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());
	int cnt=0;
	for(int i=0;i<N;i++){
		if(i!=N-1){
			cnt+=A[i];
		}
		else{
			if(A[i]<cnt){
				cout<<"Yes"<<endl;
			}
			else{
				cout<<"No"<<endl;
			}
		}
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

int main(){
    int N;
    cin >> N;
    int cnt=0;
    int ans=0;
    int tmp;
    cin >> tmp;
    for(int i=0; i<N-1; i++){
        int a;
        cin >> a;
        if(tmp>=a){
            cnt++;
            tmp=a;
        }else{
            ans=max(ans,cnt);
            tmp=a;
            cnt=0;
        }
    }
    cout << max(ans,cnt) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,l,sum=0;
    cin>>n>>l;
    std::deque<int> deq;
    for (int i=1;i<=n;i++) {
        deq.emplace_back(l+i-1);
        sum+=l+i-1;
    }
    if (find(deq.begin(),deq.end(),0)!=deq.end()) {
        cout<<sum<<endl;
    } else if (deq[n-1]>0) {
        cout<<sum-deq[0]<<endl;
    } else {
        cout<<sum-deq[n-1]<<endl;
    }
}


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

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

    sort(a.begin(), a.end());
    vector<int> b;
    int tmp=1;
    for(int i=0; i<N; i++){
	if(i == N-1){
	    b.push_back(tmp);
	    break;
	}
	if(a[i] != a[i+1]){
	    b.push_back(tmp);
	    tmp=1;
	}
	else
	    tmp++;
    }
    
    sort(b.begin(), b.end());
    
    for(int i=0; i<(int)b.size()-K; i++){
    	ans += b[i];
    }

    cout << ans << endl;
}



Measured memory_bytes: 2168
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

static const ll MAX = 100001;
ll a[MAX] = {};

int main() {
    

    ll n;
    cin >> n;
    for (ll i=1;i<=n;i++){
        ll p;
        cin >> p;
        a[p]++;
    }
    ll flag = 0;
    if(a[n-1] == n){
        cout << "Yes" << endl;
        flag = 1;
    }
    if(flag == 0) {
        ll cnt = 0;
        ll minidx = mop;
        ll maxidx = 0;
        for (ll i=1;i<=n;i++){
            if(a[i] != 0){
                if(minidx > i){
                    minidx = i;
                }
                if(maxidx < i){
                    maxidx = i;
                }
                cnt++;
            }
        }
        if(maxidx - minidx >= 2){
            cout << "No" << endl;
            flag = 1;
        }
        if(flag == 0) {
            ll numcolor = maxidx;
//        cout << numcolor << endl;
            ll numperson = n;
            ll numone, numtwo;
            numone = a[minidx];
            numtwo = a[maxidx];
            if (minidx != maxidx) {
                numcolor -= numone;
                numperson -= numone;
            }

            if (numcolor != 0 and numperson / numcolor >= 2) {
                cout << "Yes" << endl;
            } else {
                cout << "No" << endl;
            }
        }

    }
//    for (ll i = 1; i <= n; i++) {
//        cout << a[i] << " ";
//    }
//    cout << endl;


}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()
#define sz(x) ll(x.size())
const long long INF = 1e18;
using namespace std;
typedef long long ll;
int main() {
  string s;
  string t;
  cin >> s;
  cin >> t;
  ll n = sz(s);
  ll m = sz(t);

  vector<vector<ll>> ls(26);
  REP(i, n) { ls[s[i] - 'a'].push_back(i); }
  REP(i, n) { ls[s[i] - 'a'].push_back(i + n); }

  ll ans = 0;
  ll p = 0;
  REP(i, m) {
    ll c = t[i] - 'a';
    if (sz(ls[c]) == 0) {
      cout << -1;
      return 0;
    }
    p = *lower_bound(ALL(ls[c]), p) + 1;
    if (p >= n) {
      p -= n;
      ans += n;
    }
  }
  ans += p;
  cout << ans;

  return 0;
}

Measured memory_bytes: 2800
/**

    ___         ___           ____        __      __        ____         ___        _    _     ____
   / __ \      / __ \        / __ \       \ \    / /       / __ \       |  _ \     | |  | |  _/  _/
  | |  \ \    / /  | |      / /  \ \       \ \  / /       / /  \ \      | | \ \    | |  | |_/  _/
  | |   \ \  / /   | |     / /____\ \       \ \/ /       / /____\ \     | |  \ \   | |  |    _/
  | |    \ \/ /    | |    / /______\ \       \  /       / /______\ \    | |   \ \  | |  |  _ \__
  | |     \__/     | |   / /        \ \       | |      / /        \ \   | |    \ \_| |  | | \__ \__
  |_|              |_|  /_/          \_\  .   |_|     /_/          \_\  |_|     \ ___|  |_|    \___\


   ________         ____         _________   ___________    __________      ___________     _________
  |  ____  \       / __ \       | _______/  |____  _____|  /  ______  \    / _________/    |___   ___|
  | |____|  \     / /  \ \      | |______        | |      /  /       \ \   | /                 | |
  |    ____ /    / /____\ \     |______  |       | |     /  /         \ \  | |  _________      | |
  | |\_\        / /______\ \           | |       | |     \  \         / /  | | |_______  |     | |
  | |  \_\     / /        \ \   _______| |       | |      \  \_______/ /   | |_________| |  ___| |___
  |_|    \_\  /_/          \_\  \________|       |_|       \__________/    \_____________| |_________|


**/
#include<bits/stdc++.h>
using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n,k;
	cin>>k>>n;
	vector<int> a;
	for(int i=0,val;i<n;++i){
		cin>>val;
		a.push_back(val);
	}
	int ans = 0;
	sort(a.begin(),a.end());
	for(int i=1;i<n;++i){
		ans = max(ans,a[i]-a[i-1]);
	}
	cout<<min(k-ans,a[n-1]-a[0])<<'\n';
	return 0;
}

Measured memory_bytes: 1400