akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ar array
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
const ll mod = 1000000007;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

const int mxN = 1e5;
ll dp[mxN + 1];
ll fac(ll n) {
	dp[0] = 1;
	for(int i = 1; i <= n; i++)
		dp[i] = (dp[i-1] * i) % mod;
	return dp[n];
}

int main() {
	ll n;
	cin >> n;
	cout << fac(n) << endl;
    return 0;
}



Measured memory_bytes: 4220
import java.util.LinkedHashMap;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String word = sc.next();
		char c;
		boolean isEven = true;

		LinkedHashMap<Character,Integer> countWord = new LinkedHashMap<Character,Integer>();

		for(int i = 0;i < word.length();i++) {
			c = word.charAt(i);
			if(countWord.containsKey(c)) {
				countWord.put(c, countWord.get(c)+1);
			} else {
				countWord.put(c,1);
			}
		}

		for(int num : countWord.values()){
			if(num!=2) {
				isEven = false;
			}
		}

		if(isEven) {
			System.out.println("Yes");
		} else {

			System.out.println("No");
		}
	}
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size() 

ll power(ll x,ll y,ll p) 
{ 
    ll res = 1;      
    x = x % p;  
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p;   
    } 
    return res; 
} 
ll a[10];
int main()
{
    ios_base::sync_with_stdio(false);
	ll n,i,j,k,x,y,t,m;

	for(i=1;i<=5;i++)
	cin >> a[i];

	for(i=1;i<=5;i++)
	if(a[i]==0)cout<<i<<endl;;	
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
using LL  = long long;
using VI  = vector<LL>;
using VVI = vector<VI>;
using VB  = vector<bool>;
using VS  = vector<string>;
using PII = pair<LL, LL>;
using VP  = vector<PII>;
#define PB           push_back
#define MP           make_pair
#define SZ(a)        LL((a).size())
#define EACH(x, c)   for (auto x : (c))
#define ALL(c)       (c).begin(), (c).end()
#define REVERSE(c)   reverse(ALL(c))
#define SORT(c)      stable_sort(ALL(c))
#define RSORT(c)     stable_sort((c).rbegin(), (c).rend())
#define FSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first < y.first;});
#define FRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first > y.first;});
#define SSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second < y.second;});
#define SRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second > y.second;});
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n)    FOR(i, 0, n)
#define DEBUG true
#define $(x) {if (DEBUG) {cout << #x << " = " << (x) << endl;}}


int main() {
    LL N;
    cin >> N;
    VI A(N);
    REP(i, N) {
        cin >> A[i];
        A[i] -= i + 1;
    }
    SORT(A);
    LL med = A[N / 2];
    LL ans = 0;
    REP(i, N) {
        ans += abs(A[i] - med);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2560
import math
a,b,x=map(int,input().split())
ans=0
flag=False
if x==a*a*b/2:
  ans=a/b
elif x<a*a*b/2:
  t=a-2*x/(a*b)
  ans=(a-t)/b
else:
  t=2*x/(a**2)-b
  if (b-t)!=0:
    ans=a/(b-t)
  else:
    flag=True
if flag==False:
  print(90-math.degrees(math.atan(ans)))
else:
  print(0)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define repi(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define SIZE_OF_ARRAY(array)    (sizeof(array)/sizeof(array[0]))
typedef long long ll;
using namespace std;
int main(){
  ll a,b,r,x,tmp;
  cin >> a >> b;
  x = a*b;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }

  cout << x/b << endl;
  return 0;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef complex<int> ci;
typedef complex<double> cd;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define pf push_front
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ge(a, b) get<(b)>((a))
#define SZ(x) (x).size()
#define ft front()
#define bk back()
#define ins insert
#define endl '\n'
#define FOR(a, b, c) for (auto(a) = (b); (a) < (c); ++(a))
#define ROF(a, b, c) for (auto(a) = (b); (a) > (c); --(a))
#define F0R(a, b) FOR ((a), 0, (b))
#define R0F(a, b) ROF ((a), (b), -1)
#define FORI(a, b) for (auto(a) = (b).begin(); (a) != (b).end(); ++(a))
#define ROFI(a, b) for (auto(a) = (b).rbegin(); (a) != (b).rend(); ++(a))
#define CEIL(a, b) ((a) + (b)-1) / (b)
const int xd[4] = {0, 1, 0, -1}, yd[4] = {1, 0, -1, 0};
template <typename t>
bool ckmin(t& a, const t& b) {
    return a > b ? a = b, true : false;
}
template <typename t>
bool ckmax(t& a, const t& b) {
    return a < b ? a = b, true : false;
}

const ll p = 1000000007;

vvi adj;
vector<ll> fac;
vector<ll> dp;
vector<ll> cnt;

ll binpow(ll a, ll b) {
    a %= p;
    ll res = 1;
    while (b > 0) {
        if (b & 1) res = res * a % p;
        a = a * a % p;
        b >>= 1;
    }
    return res;
}

void dfs(int v = 0, int parent = -1) {
    for (int u : adj[v]) {
        if (u != parent) {
            dfs(u, v);
            dp[v] = dp[v] * dp[u] % p;
            dp[v] = dp[v] * binpow(fac[cnt[u]], p - 2) % p;
            cnt[v] += cnt[u];
        }
    }
    dp[v] = dp[v] * fac[cnt[v] - 1] % p;
}

void dfs2(int v = 0, int parent = -1) {
    if (parent != -1) {
        ll tmp = dp[parent] * binpow(fac[cnt[parent] - 1], p - 2) % p;
        tmp = tmp * fac[cnt[v]] % p;
        tmp = tmp * binpow(dp[v], p - 2) % p;
        tmp = tmp * fac[cnt[parent] - cnt[v] - 1] % p;

        dp[v] = dp[v] * binpow(fac[cnt[v] - 1], p - 2) % p;
        dp[v] = dp[v] * binpow(fac[cnt[parent] - cnt[v]], p - 2) % p;
        dp[v] = dp[v] * tmp % p;
        cnt[v] = cnt[parent];
        dp[v] = dp[v] * fac[cnt[v] - 1] % p;
    }
    for (int u : adj[v])
        if (u != parent) dfs2(u, v);
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;
    adj.assign(n, vi());
    F0R (i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    fac.assign(n + 1, 1);
    FOR (i, 1, n + 1)
        fac[i] = i * fac[i - 1] % p;
    cnt.assign(n, 1);
    dp.assign(n, 1);
    dfs();
    // for (ll l : dp) cout << l << endl;
    dfs2();

    for (ll l : dp) cout << l << endl;

    return 0;
}


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

int main()
{
    string s;
    getline(cin, s);
    for (int i = 0; i < s.size(); i++)
    {
        if ('a' <= s[i] && s[i] <= 'z')
            cout << (char)(s[i] - ('a' - 'A'));
        else if ('A' <= s[i] && s[i] <= 'Z')
            cout << (char)(s[i] + ('a' - 'A'));
        else
            cout << s[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3172
#include <bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
typedef long long ll;
const ll mod = 1e9+7;
#define all(x) (x).begin(),(x).end()

// 深さ優先探索
int counte;
vector<bool> seen;
vector<bool> watch;
vector<int> member;
void dfs(const Graph &G, int v) {
    if(seen[v] == false){
        counte++;
        member.push_back(v);
    }
    seen[v] = true;
    watch[v] = true;
    for (auto next_v : G[v]) {
        if (seen[next_v]) continue;
        dfs(G, next_v); // 再帰的に探索
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    int N,M,K;
    cin >> N >> M >> K;
    watch.assign(N,false);
    vector<int> answer(N);
    Graph F(N),B(N);
    REP(i,M){
        int a,b;
        cin >> a >> b;
        F[a-1].push_back(b-1);
        F[b-1].push_back(a-1);
    }
    REP(i,K){
        int a,b;
        cin >> a >> b;
        B[a-1].push_back(b-1);
        B[b-1].push_back(a-1);
    }
    REP(i,N){
        if(watch[i] == 0){
            counte = 0;
            seen.assign(N,false);
            member.assign(0,0);
            dfs(F,i);
            REP(l,member.size()){
                int counter = 0;
                REP(k,B[member[l]].size()){
                    if(seen[B[member[l]][k]] == 1)counter++;
                }
                REP(k,F[member[l]].size()){
                    if(seen[F[member[l]][k]] == 1)counter++;
                }
                answer[member[l]] = counte - counter - 1;
            }
        }
    }
    REP(i,N)cout <<answer[i]<< "\n";
}

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

int_fast64_t n, ans, march[5];
char s[16];

int main(){
	scanf("%ld", &n);
	for(int i=0; i<n; i++){
		scanf("%s", s);
		if(s[0]=='M') march[0]++;
		if(s[0]=='A') march[1]++;
		if(s[0]=='R') march[2]++;
		if(s[0]=='C') march[3]++;
		if(s[0]=='H') march[4]++;
	}
	
	for(int i=0; i<5; i++) for(int j=i+1; j<5; j++) for(int k=j+1; k<5; k++){
		ans += march[i] * march[j] * march[k];
	}
	printf("%ld\n", ans);
}


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

int main() {
  
  int a,b,c;
  cin >> a >> b >> c;
  
  if(b-a == c-b) cout << "YES" << endl;
  else cout << "NO" << endl;
  
}


Measured memory_bytes: 256
/* be name khoda */

// #define long_enable
#include <iostream>
#include <algorithm>
#include <cstring>
#include <numeric>
#include <vector>
#include <fstream>
#include <set>
#include <map>
using namespace std;

#ifdef long_enable
typedef long long int ll;
#else
typedef int ll;
#endif

typedef pair<ll, ll> pii;
typedef pair<pii, ll> ppi;
typedef pair<ll, pii> pip;
typedef vector<ll> vi;
typedef vector<pii> vpii;

#define forifrom(i, s, n) for (ll i = s; i < n; ++i)
#define forirto(i, n, e) for (ll i = (n) - 1; i >= e; --i)
#define fori(i, n) forifrom (i, 0, n)
#define forir(i, n) forirto (i, n, 0)

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define smin(a, b) a = min(a, (b))
#define smax(a, b) a = max(a, (b))

#define debug(x) cout << #x << " -> " << (x) << endl
#define debug2(x, y) cout << #x << ' ' << #y << " -> " << (x) << ' ' << (y) << endl
#define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> " << (x) << ' ' << (y) << ' ' << (z) << endl
#define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> " << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << endl
#define debuga(x, n) cout << #x << " -> "; fori (i1_da, n) { cout << (x)[i1_da] << ' '; } cout << endl
#define debugaa(x, n, m) cout << #x << " ->\n"; fori (i1_daa, n) { fori (i2_daa, m) { cout << (x)[i1_daa][i2_daa] << ' '; } cout << '\n'; } cout << endl

const ll MOD = 998244353;
const ll INF = 2000000000;
const long long BIG = 1446803456761533460LL;

#define XL (x << 1)
#define XR (XL | 1)
#define MD ((l + r) >> 1)
#define Add(a, b) a = ((a) + (b)) % MOD
#define Mul(a, b) a = (1LL * (a) * (b)) % MOD

// -----------------------------------------------------------------------

const ll maxn = 310;

ll n, m, K, A[maxn];
string S;
ll dp[maxn][maxn][maxn];

/*
    partition string by zeros and start from end
    dp[i][j][k] first i parts, use k operations and remove j ones for next parts
    dp update in both directions
    dp[i][j][k] -> dp[i + 1][j + t][k + t] (remove t ones from i+1 's part) 1 < t < A[i + 1]
    dp[i][j][k] <- dp[i - 1][j + t][k] (add some ones from prev parts) 0 <= t <= inf
   */

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

    cin >> S >> K;
    n = S.size();
    reverse(all(S));
    ll i = 0;
    while (i < n) {
        ll j = i;
        while (j < n && S[j] == '1') ++j;
        A[m++] = j - i;
        i = j + 1;
    }
    if (S.back() == '0') A[m++];
    
    smin(K, n);

    dp[0][0][0] = 1;
    forifrom (i, 1, m + 1) {
        fori (k, K + 1) {
            forir (j, n + 1) {
                dp[i][k][j] = (dp[i][k][j + 1] + dp[i - 1][k][j]) % MOD;
            }
        }
        forifrom (t, 1, A[i - 1] + 1) {
            fori (k, K - t + 1) {
                fori (j, n - t + 1) {
                    Add(dp[i][k + t][j + t], dp[i - 1][k][j]);
                }
            }
        }
    }

    ll ans = 0;
    fori (i, K + 1) Add(ans, dp[m][i][0]);
    cout << ans << '\n';

}


Measured memory_bytes: 59048
//
// Created by moono on 2018/10/27.
//

#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;



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

    //
    int nums[N];
    fill(nums, nums+N, 0);

    //
    int c1, c2;
    for (int i = 0; i < M; ++i) {
        cin >> c1 >> c2;
        nums[c1-1]++;
        nums[c2-1]++;
    }

    //
    for (int j = 0; j < N; ++j) {
        cout << nums[j] << endl;
    }

    return 0;
}

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

int main() {
  int n;
  string str;
  cin >> n >> str;
  int count = 0;
  
  for(int i=0; i<n-2; i++){
    string testStr = str.substr(i,3);
    if(testStr == "ABC"){
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
#define ll long long int 
void solve()
{
	string s;
	cin>>s;
	cout<<s[0]<<s[1]<<s[2]<<endl;
	
}


int main()
{
	ll t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}


Measured memory_bytes: 3596
n,x,m=map(int,input().split())
A=dict()
i=0
y=x
while True:
    if not(y in A.keys()):
        A[y]=i
        i+=1
        y=(y**2)%m
    else:
        break
j=A[y]
#print(A)
#print(i)
#print(j)
A=list(sorted(A.items(),key=lambda x:x[1]))
#print(A)
s=0
for k in range(j):
    s+=A[k][0]
p=(n-j)//(i-j)
q=(n-j)%(i-j)
t=0
for k in range(j,i):
    t+=A[k][0]
u=0
if q!=0:
    for k in range(j,j+q):
        u+=A[k][0]
else:
    u=0
print(s+t*p+u)            

Measured memory_bytes: 75844
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

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

using namespace std;

bool solve(vector<int> X,int tar,bool first){
	bool dp[2][20000]={};
	int from=0,to=1;
	dp[from][10000]=true;
	for(int a:X){
		rep(i,20000) if(0<=i+a && i+a<20000 && dp[from][i]) dp[to][i+a]=true;
		if(!first){
			rep(i,20000) if(0<=i-a && i-a<20000 && dp[from][i]) dp[to][i-a]=true;
		}
		first=false;
		fill(dp[from],dp[from]+20000,false);
		swap(from,to);
	}
	return dp[from][tar+10000];
}

int main(){
	string s;
	int tx,ty;
	cin>>s>>tx>>ty;
	s+='T';
	int n=s.length();

	int pre=0;
	bool par=true;
	vector<int> X,Y;
	rep(i,n) if(s[i]=='T') {
		if(par) X.emplace_back(i-pre);
		else    Y.emplace_back(i-pre);
		pre=i+1;
		par=!par;
	}

	cout<<(solve(X,tx,s[0]=='F')&&solve(Y,ty,false)?"Yes":"No")<<endl;

	return 0;
}


Measured memory_bytes: 384
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int a, b, c; readV(a, b, c);
  writeln(a+b == c || b+c == a || c+a == b ? "Yes" : "No");
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
using namespace std;

int main()
{
	int N;
	cin >> N;

	auto sum = 0ull;
	for (auto i = 0; i < N; ++i)
	{
		auto a = 0ull;
		cin >> a;
		sum += a - 1;
	}

	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long int
#define INF INT_MAX
#define mod
#define chutiyaap ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
bool sortbysec(const pair<ll,ll> &a,const pair<ll,ll> &b){return (a.second < b.second);}
ll gcd(ll a, ll b){if(a==0)return b;return gcd(b % a, a);}
int main()
{
	chutiyaap;
	ll a,b,c;cin>>a>>b>>c;
	if(a%2==0)cout<<(a/2)*b;
	else cout<<(b/2)*a;
}


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

long long kMod = 1e9 + 7;

void prime_factorization(unordered_map<long long, long long>& tmp, long long val)
{
  long long x = val;
  for (long long i = 2; i * i <= val; i++) {
    while (x % i == 0) {
      tmp[i]++;
      x = x / i;
    }
  }
  if (x != 1) {
    tmp[x]++;
  }
}

long long modinv(long long a, long long m)
{
  long long b = m;
  long long x = 1;
  long long y = 0;
  while (b != 0) {
    long long t = a / b;
    a = a - t * b;
    x = x - t * y;
    swap(a, b);
    swap(x, y);
  }
  x %= m;
  if (x < 0) {
    x += m;
  }
  return x;
}

int main()
{
  long long n;
  cin >> n;
  vector<long long> v(n);
  for (long long i = 0; i < n; i++) {
    cin >> v.at(i);
  }
  unordered_map<long long, long long> m;
  for (long long i = 0; i < n; i++) {
    long long val = v.at(i);
    unordered_map<long long, long long> tmp;
    prime_factorization(tmp, val);
    for (const auto& p : tmp) {
      auto it = m.find(p.first);
      if (it == m.end() || it->second < p.second) {
        m[p.first] = p.second;
      }
    }
  }
  long long target = 1;
  for (const auto& p : m) {
    for (long long i = 0; i < p.second; i++) {
      target = target * p.first;
      target %= kMod;
    }
  }
  long long res = 0;
  for (auto x : v) {
    unordered_map<long long, long long> tmp;
    prime_factorization(tmp, x);
    long long t = target;
    for (auto& p : tmp) {
      for (long long i = 0; i < p.second; i++) {
        t = t * modinv(p.first, kMod);
        t %= kMod;
      }
    }
    res += t;
    res %= kMod;
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 768
/*
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XX   XXXXXXXXX  XXXXXXXXXXXXXXXX  XXXXXXXXXXXXXXXXXXXXXXXXX X
X XXX XX   XXXX XXXX    X XXX XXX XXXX   XXXX XXXX   XXXXXX X
X XXXXXXXXX XXX XXX XXXXX XXX XXX XXXXXXX XX   XX XXX XX    X
X XXXXX     XXX XXX XXXXX XXX XXX XXX     XXX XXX     X XXX X
X XXX X XXX XXX XXX XXXXX XXX XXX XXX XXX XXX XXX XXXXX XXX X
XX   XXX    XX   XXX    XX    XX   XXX    XXX  XXX    XX    X
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXX     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXX XXXXX   XXXX   XX  X XXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXX XXXX XXX XXXXXX X X X XXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXX XXXX     XX     X X X XXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXX XXXX XXXXXX XXX X XXX XXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXX XXXXX    XXX    X XXX XXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*/

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <iomanip>
#include <chrono>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <array>
#include <set>
#include <list>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <unordered_map>
#include <map>
#include <iterator>
#include <cstring>
using namespace std;

#define loop(i,start,end) for(auto i = start; i < end; i++)
#define loopi(end) loop(i,0,end)
#define loopj(end) loop(j,0,end)
#define loopk(end) loop(k,0,end)
#define get_i(n) int n; cin >> n;
#define get_ch(n) char x; cin >> x;
#define get_doub(n) double n; cin >> n;
#define pb push_back
#define ll long long 
#define pii pair<int,int>
#define pll pair<ll, ll>
#define vb vector<bool>
#define vi vector<int>
#define vpi vector<pii>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define clear(a) memset(a, 0, sizeof(a))
#define all(a) (a).begin(), (a).end()
const long long modulo = 1e18+3;
const ll INF = 1e18;
const int inf = 2e9;
const double PI = 3.141592653589793238463;

//#define FILE "substrcmp"
#define FAST_IO
#define FSOL

#ifdef FSOL
void solve() {
	get_i(n);
	vi a(n), b(n), c(n);
	loopi(n) cin >> a[i] >> b[i] >> c[i];
	vvi dp(3, vi(n));
	dp[0][0] = a[0];
	dp[1][0] = b[0];
	dp[2][0] = c[0];
	loop(i, 1, n) {
		dp[0][i] = max(dp[1][i - 1], dp[2][i - 1]) + a[i];
		dp[1][i] = max(dp[0][i - 1], dp[2][i - 1]) + b[i];
		dp[2][i] = max(dp[0][i - 1], dp[1][i - 1]) + c[i];
	}
	int ans = 0;
	loopi(3) ans = max(ans, dp[i][n - 1]);
	cout << ans;
}
#else 
void solve() {
	
}
#endif

int main() {
#ifdef FAST_IO
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
#endif
#ifdef DEBUG
	freopen("debug.in", "r", stdin);
	auto timestamp = std::chrono::system_clock::now();
#else 
#ifdef FILE
	freopen(FILE".in", "r", stdin);
	freopen(FILE".out", "w", stdout);
#endif
#endif
	solve();
#ifdef DEBUG 
	cout << endl << "Time elapsed: " << chrono::duration_cast<chrono::milliseconds>(std::chrono::system_clock::now() - timestamp).count() << " ms" << endl;
#endif
	return 0;
}

Measured memory_bytes: 2944
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;


long long int N, M, K, H, W, L, R;


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

	cin >> N >> M >> K;
	vector<int>v(N);
	set<int>s;
	for (int i = 0; i < N; i++) {
		cin >> v[i];
		s.insert(v[i]);
	}
	int ans = MOD;
	for (auto i : s) {
		vector<int>w(1, -1);
		for (int j = 0; j < N; j++) {
			if (v[j] < i)w.push_back(j);
		}
		w.push_back(N);
		int loop = w.size();
		vector<int>use;
		for (int j = 1; j < loop; j++) {
			if (w[j] - w[j - 1] > M) {
				vector<int>x;
				for (int k = w[j - 1] + 1; k < w[j]; k++) {
					x.push_back(v[k]);
				}
				sort(x.begin(), x.end());
				for (int k = 0; k < w[j] - w[j - 1] - M; k++) {
					use.push_back(x[k]);
				}
			}
		}
		sort(use.begin(), use.end());
		if (use.size() < K)continue;
		ans = min(ans, use[K - 1] - i);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
h, n = map(int, input().split())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())

dp = [[1e18] * (h + 1) for _ in range(n + 1)]
dp[0][0] = 0

for i in range(n):
    for j in range(h + 1):
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
        dp[i + 1][min(j + a[i], h)] = min(dp[i + 1][min(j + a[i], h)], dp[i + 1][j] + b[i])

print(dp[n][h])

Measured memory_bytes: 286856
use std::io::*;
fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let t: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<usize> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();

    let mut ans = 0;
    for i in 0..n - 1 {
        ans += std::cmp::min(a[i + 1] - a[i], t);
    }
    ans += t;
    println!("{}", ans);
}


Measured memory_bytes: 8444
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;

struct unionfind{
    vector<int> par,rank,nums;
    unionfind(int x){
        par.resize(x);
        rank.resize(x);
        nums.resize(x);
        for(int i=0; i<x; i++)par[i]=i,rank[i]=0,nums[i]=1;
    }
    int root(int x){
        if(par[x]==x)return x;
        return par[x]=root(par[x]);
    }
    void uni(int x,int y){
        x=root(x),y=root(y);
        if(x==y)return;
        if(rank[x]<rank[y]){
            par[x]=y;
            nums[y]+=nums[x];
        }
        else{
            par[y]=x;
            nums[x]+=nums[y];
            if(rank[x]==rank[y])rank[x]++;
        }
    }
    bool same(int x,int y){
        return root(x)==root(y);
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,m,k;cin>>n>>m>>k;
    vector<ll> edges(n,0);
    unionfind u(n);
    for(int i=0; i<m; i++){
        int a,b;cin>>a>>b;
        a--;b--;
        u.uni(a,b);
        edges[a]++;edges[b]++;
    }
    
    for(int i=0; i<k; i++){
        int c,d;cin>>c>>d;
        c--;d--;
        if(u.same(c,d)){edges[c]++;edges[d]++;}
    }
    for(int i=0; i<n; i++){
        cout<<u.nums[u.root(i)]-edges[i]-1<<" ";
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 2816
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools, bisect
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def S(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]

alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007

def main():
    N, K = LI()
    A = LI()

    maxA = max(A)
    ans = maxA

    left, right = 1, maxA
    mid = (left + right) / 2
    e = 0.000001

    while right - left > e:
        count = 0
        for ai in A:
            count += math.floor(ai / mid)
        if count <= K:
            right = mid
            ans = min(mid, ans)
        else:
            left = mid
        mid = (left + right) / 2

    if math.floor(ans) + e > ans:
        print(math.floor(ans))
    else:
        print(math.ceil(ans))

if __name__ == '__main__':
    main()

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

int main(void)
{
  string s;
  int k,i;
  cin>>k;
  cin>>s;
  
  if(s.size()<=k) cout<<s;
  else{
  	for(i=0;i<k;i++) cout<<s[i];
	cout<<"..."; 
  }  
}

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

#define fastIO ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define ld long double
#define ll long long
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define vi vector<ll>
#define min3(a, b, c) min(a,min(b, c))
#define min4(a, b, c, d) min(a, min(b, min(c, d)))
#define max3(a, b, c) max(a,max(b, c))
#define max4(a, b, c, d) max(a, max(b, max(c, d)))
#define INF (int)1e9

ll a[11];
string s="codeforces";


int main()
{
    fastIO
    char a;
    cin>>a;
    if(a>=97 && a<=122)
    {
        cout<<"a"<<endl;
    }
    else
    {
        cout<<"A"<<endl;
    }    
}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>

using namespace std;
typedef long long int ll;typedef pair<int, int> P;
const long long mod = 1e9 + 7;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define ALL(a) (a).begin(),(a).end()



int main(void) {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int x = c - a; int y = d - b;
	cout << c - y << " " << d + x << " " << a - y << " " << b + x << endl;

	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter

val br = BufferedReader(InputStreamReader(System.`in`))
val pw = PrintWriter(System.out)
fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    // 回答をここに書く
    val (a,b) = listOfInt()
    val c = a + b
    val d = a - b
    val e = a * b
    println(listOf(c,d,e).sortedDescending()[0])
}

// 入力取得
fun next() = br.readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() =listOfString().map { it.toInt() }
fun listOfLong() =listOfString().map { it.toLong() }
fun listOfDouble() =listOfString().map { it.toDouble() }

// 約数のList
fun divisor(value : Long) : List<Long> {
    val max = Math.sqrt(value.toDouble()).toLong()
    return (1..max)
            .filter { value % it == 0L }
            .map { listOf(it, value / it) }
            .flatten()
            .sorted()
}

// 範囲内の素数を取得
// fromだけ指定すると戻り値の個数で素数判定ができる
fun prime(from : Long, to : Long = from) : List<Long> {
    return (from..to).filter { i ->
        val max = Math.sqrt(i.toDouble()).toLong()
        (2..max).all { j ->  i % j != 0L }
    }
}

// 素因数分解
fun decom(value : Long) : List<Long>{
    if (value == 1L) return listOf(1)
    val max = Math.sqrt(value.toDouble()).toLong()
    return prime(2, max).filter { value % it == 0L }
}

// 最大公約数
fun gcd(a : Long, b : Long) : Long {
    return if (a % b == 0L) b else gcd(b, a % b)
}

// 文字列を入れ替え
fun swap(base : String, a : String, b : String) : String {
    return base.map {
        when (it) {
            a.toCharArray()[0] -> b
            b.toCharArray()[0] -> a
            else -> it.toString()
        }
    }.joinToString()
}

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 35796
#include<iostream>
#include<cstdio>
#include<utility>
#include<climits>
#include<cmath>
using namespace std;

int main()
{
	//ax + by = c
	//dx + ey = f

	double a, b, c, d, e, f;
	double x, y;

	while (cin >> a >> b >> c >> d >> e >> f)
	{
		y = (a * f - c * d) / (a * e - b * d);
		x = -b / a * y + c / a;
		printf("%.3lf %.3lf\n", x, y);
	}
	return 0;
}

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

s = ["" for i in range(N)]
B = 0
A = 0
BA = 0

score = 0
for i in range(N):
    s[i] = input()
    if s[i][0] == "B" and s[i][-1] != "A":
        B += 1
    if s[i][0] != "B" and s[i][-1] == "A":
        A += 1
    if s[i][0] == "B" and s[i][-1] == "A":
        BA += 1
    for j in range(len(s[i])-1):
        if s[i][j] == "A" and s[i][j+1] == "B":
            score += 1

if BA >= 1:
    score += BA - 1
    if A >= 1 and B >= 1:
        score += 2
        A -= 1
        B -= 1
    if A >= 1 and B == 0:
        score += 1
    if A == 0 and B >= 1:
        score += 1

print(score + min(A,B))

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

int main() {
   
 int S,W;
  cin>>S>>W;
  
  if(S>W){
    cout<<"safe"<<endl;
  }
  
  else{
    cout<<"unsafe"<<endl;
  }
 
 
  
 

       
       

  // ここにプログラムを追記
}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int,int> P;

int main(){
    int n;
    
    
    while(cin >> n,n){
        vector<P> v;
        int t,b;
        for(int i = 0 ; i < n ; i++){
            cin >> t >> b;
            v.push_back(P(b,t));
        }
        sort(v.begin(),v.end());
        
        bool flg = false;
        int sum = 0;
        for(int i = 0 ; i < n ; i++){
            sum += v[i].second;
            if(sum > v[i].first){
                flg = true;
                break;
            }
        }
        if(flg) cout << "No" << endl;
        else cout << "Yes" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1192
#include <cmath>
#include <chrono>
#include <random>
#include <ctime>
#include <algorithm>
#include <iosfwd>
#include <iostream>
#include <list>
#include <ostream>
#include <streambuf>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define fori(i, n) for(ll i = 0; i < (n); ++i)
#define forI(i, n) for(ll i = 1; i <= (n); ++i)
#define pll pair<ll, ll>
#define ff first
#define ss second

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")

#define pt pair<ll, ll>
#define x first
#define y second

pll operator+ (pll a, pll b){ return {a.x + b.x, a.y + b.y}; }

ll rand0m() {
    return (ull(rand()) << 15ull | ull(rand()));
}                   //[0 ... n)
ll rand0m(ll x) {
    return rand0m() % x;
}               //[0 ... n)
ll rand0m(ll minn, ll maxx) {
    return rand0m(maxx - minn + 1) + minn;
}   //[minn ... maxx]

const ll MAXN = 1e5 + 1;
const ll mod = 1e9 + 7;
const ll INF = 2e9 + 1000;

ll n, m;
ll a[3][MAXN];
ll dp[3][MAXN];

void solve() {
    cin >> n;
    forI(i, n) fori(j, 3) cin >> a[j][i];
    //fori(j, 3) forI(i, n) dp[j][i] = INF;
    forI(i, n){
        fori(j, 3){
            fori(k, 3){
                if(k == j) continue;
                dp[j][i] = max(dp[k][i - 1] + a[j][i], dp[j][i]);
            }
        }
    }
    cout << max(dp[0][n], max(dp[1][n], dp[2][n]));
}

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

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    solve();
}

Measured memory_bytes: 4992
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i =  0 ; i < n ; i++) a[i] = sc.nextInt();
		Arrays.sort(a);
		Map<Integer, Integer> map = new HashMap<Integer, Integer>();
		int x = -1;
		for(int i = n - 1 ; i >= 0; i--) {
			if(!map.containsKey(a[i])) {
				map.put(a[i], 1);
			}
			else {
				int j = i;
				for(j = i ; j >= 0 ; j--) {
					if(map.containsKey(a[j])) {
						map.put(a[j], map.get(a[j]) + 1);
					} else {
						break;
					}
				}
				if(x == -1 && map.get(a[i]) >= 4) {
					System.out.println(1L * a[i] * a[i]);
					return;
				} else if(x != -1 && x != a[i] && map.get(a[i]) >= 2) {
					System.out.println(1L * x * a[i]);
					return;
				} else if(map.get(a[i]) >= 2) {
					x = a[i];
				}
				i = j + 1;
			}
		}
		System.out.println(0);
	}
}

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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for(ll i = 0 ; i < n; i++)

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    string S;
    cin >> S;

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

    if( S[0] == S[1] && S[2] == S[3] && S[0] != S[2] ){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[]) {
  // read inputs
  int A, B, C;
  scanf("%d %d %d", &A, &B, &C);

  // solve
  if (C <= A + B + 1) {
    printf("%d\n", C + B);
  } else {
    printf("%d\n", (A + B + 1) + B);
  }

  return 0;
}


Measured memory_bytes: 128
//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 int lo;
typedef pair< int,int > 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(lo 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 = 200005; 
const lo mod = 1000000007; 

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

int main(void){
	scanf("%lld",&n);
	m=n;
	while(m>0){
		cev+=m%10;
		m/=10;
		//~ cout<<m<<endl;
	}
	if(n%cev==0){printf("Yes\n");return 0;}
	printf("No\n");
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc.Split(bufio.ScanWords)
	n, i := nextInt(), nextInt()
	puts(n - i + 1)
	wt.Flush()
}

var (
	sc  = bufio.NewScanner(os.Stdin)
	rdr = bufio.NewReaderSize(os.Stdin, 1000000)
	wt  = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func nextMega() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, _ := rdr.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


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

int bubble(int A[],int n){
    int cou = 0;
    bool flag = 1;
    for (int i =0;flag;i++){
        flag =0;
        for (int j = n-1; j>=i+1; j--){
            if(A[j]<A[j-1]){
                swap(A[j],A[j-1]);
                flag = 1;
                cou++;
            }
        }
    }
    return cou;
}

int main(){
    int n;
    int A[100];
    int cou;
    
    cin  >> n;
    for (int i = 0; i<n; i++) cin >> A[i];
    
    cou =bubble(A,n);
    
    for(int i =0; i <n;i++){
        if (i) cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << cou << endl;
    
    return 0;
}


Measured memory_bytes: 3104
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n, k = MAP()

for i in range(1, k+1):
    ans = comb(n-k+1,i)*comb(k-1,i-1) % (10**9+7)
    print(ans)

Measured memory_bytes: 10392
#include <iostream>
#include <string>

using namespace std;
int main(){
  string s;
  cin >> s;

  char c[] = "keyence";

  bool iCflg = false;
  bool iFlg = false;
  int j=0, k=0, l=0;

  for(int i=0;i<s.length();i++){
    if(s[i]==c[j]){
      j++;
      if(c[j]=='\0' && (i==s.length()-1 || k==0)){
        iFlg=true;
        break;
      }
      if(k>0){
        l++;
      }
    } else {
      if(k==0){
      } else {
        j-=l;
        l=0;
        if(s[i]==c[j])j++;
      }
      k++;
    }
  }

  if(iFlg){
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <sstream>
#include <set>
#include <string>
#include <math.h>
#include <map>
#include <climits>
#include <iomanip>


#define forn(i, n) for (int i = 0; i < int(n); i++)

#define ll long long

using namespace std;

void A();
void B();
void C();
void D();
void E();
void F();

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	F();


}

void A() {
	string s;
	cin >> s;

	cout << (s == "ABC" ? "ARC" : "ABC") << '\n';

}

void B() {
	int N, K;
	cin >> N >> K;

	set<int> have;

	forn(k, K) {

		int d;
		cin >> d;

		forn(dd, d) {

			int sn;
			cin >> sn;
			have.insert(sn);

		}
	}

	int c = 0;
	forn(i, N) {
		if (have.find(i+1) == have.end()) c++;
	}

	cout << c;

}

void C() {
	
	int N, M;
	cin >> N >> M;

	vector<int> h;
	forn(i, N) {
		int hh;
		cin >> hh;
		h.push_back(hh);
	}

	vector<vector<int>> adj(N);

	forn(m, M) {

		int a, b;
		cin >> a >> b;

		adj[a - 1].push_back(b - 1);
		adj[b - 1].push_back(a - 1);

	}
	
	int r = 0;
	forn(i, N) {

		bool good = true;
		for (int ind : adj[i]) {
			if (h[ind] >= h[i]) good = false;
		}

		if (good) r++;

	}

	cout << r;

}

void D() {
	int X;
	cin >> X;

	vector<ll> dp(1000);

	ll A, B;

	for (int i = -126; i < 126; i++) {

		if (dp[i + 130] == 0) {
			dp[i + 130] = pow(i, 5);
		}
		A = dp[i + 130];

		for (int j = -126; j < 126; j++) {

			if (dp[j + 130] == 0) {
				dp[j + 130] = pow(j, 5);
			}
			B = dp[j + 130];
			
			if (A - B == X) {
				cout << i << " " << j;
				return;
			}


		}
	}
}

void E() {
	int N;
	cin >> N;

	vector<int> e;
	map<int, int> m;
	//map<int, int> m2;
	forn(i, N) {
		int ee;
		cin >> ee;
		e.push_back(ee);
		int dif1 = (i + 1) - ee;
		//int dif2 = (i + 1) + ee;
		m[dif1]++;
		//m2[dif2]++;

	}


	ll count = 0;
	forn(i, N) {

		int ee = e[i];
		//int dif1 = (i + 1) - ee;
		int dif2 = (i + 1) + ee;

		//count += m2[dif1];
		count += m[dif2];

	}

	cout << count;



}

void F() {
	int N, A, B, C;
	cin >> N >> A >> B >> C;

	vector<string> R;

	forn(n, N) {

		string s;
		cin >> s;
		R.push_back(s);

	}

	vector<char> result;
	bool possible = true;

	forn(n, N) {

		int* l;
		int* r;
		char lc;
		char rc;

		string req = R[n];

		if (req == "AB") {
			l = &A;
			r = &B;
			lc = 'A';
			rc = 'B';
		}
		else if (req == "BC") {

			l = &B;
			r = &C;
			lc = 'B';
			rc = 'C';
		}
		else {

			l = &A;
			r = &C;
			lc = 'A';
			rc = 'C';
		}

		if (*l == 0 && *r == 0) {
			possible = false;
			break;
		}


		if (*l > *r) {
			(*l)--;
			(*r)++;
			result.push_back(rc);
		}
		else if (*r > *l) {
			(*r)--;
			(*l)++;
			result.push_back(lc);
		}
		else if (*l > 1) {
			(*l)--;
			(*r)++;
			result.push_back(rc);
		}
		else {
			//both 1
			if (n < N - 1) {
				string nxtReq = R[n + 1];
				if (nxtReq.find(lc) == -1) {
					(*l)--;
					(*r)++;
					result.push_back(rc);
					continue;
				}
			}

			(*r)--;
			(*l)++;
			result.push_back(lc);


		}

	}
	if (possible) {
		cout << "Yes" << '\n';
		for (char rr : result) {
			cout << rr << '\n';
		}
	}
	else {
		cout << "No";
	}
	




}

 

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

int main(){
  int K,N;
  cin>>K>>N;
  int a[N];
  int b[N];
    
  for (int i=0;i<N;i++){
    cin>>a[i];
  }
  sort(a,a+N);
  b[0]=K-a[N-1]+a[0];
  int maxB=b[0];
  for(int i=1;i<N;i++){
    b[i]=a[i]-a[i-1];
    maxB=max(maxB,b[i]);
  }
  
  cout<<K-maxB<<endl;
    
}





Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main() {
  int N; cin >> N;
  vector<long long> stock(0);
  map<long long, long long> m;
  long long A = 0;
  for(int i = 0; i< N; i++) {
    long long a; cin >> a;
    A += a;
    if(m.count(A)) {
      m.at(A)++;
      continue;
    }
    m[A] = 1;
    stock.push_back(A);
  }
  if(m.count(0)) m.at(0)++;
  long long count = 0;
  for(int i = 0; i < stock.size(); i++) {
    long long x = m.at(stock.at(i));
    count += x * (x - 1) / 2;
  }
  cout << count << endl;
}

Measured memory_bytes: 14320
a, b, c = *gets.split(" ").map(&:to_i)
k = gets.to_i

r = 'No'
(k + 1).times do
  if a < b && b < c
    r = 'Yes'
    break
  elsif a - b > b - c
    b = b * 2
  else
    c = c * 2
  end
end

puts r

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

using namespace std;

#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;

const string YES = "YES", NO = "NO";
string divide[4] = {"dream", "dreamer", "erase", "eraser"};

int main() {
    string S;
    cin >> S;
    reverse(all(S));
    rep(i, 4) { reverse(all(divide[i])); }
    bool canDivide = true;
    rep(i, S.size()) {
        bool canDivide4 = false;
        rep(j, 4) {
            string divstr = divide[j];
            if (S.substr(i, divstr.size()) == divstr) {
                canDivide4 = true;
                i += divstr.size()-1;
            }
        }
        if (!canDivide4) {
            canDivide = false;
            break;
        }
    }
    if (canDivide) {
        cout << YES << endl;
    } else {
        cout << NO << endl;
    }
    return 0;
}

Measured memory_bytes: 512
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    n,q = map(int, input().split())
    l = []
    for _ in range(n):
        s,t,x = map(int, input().split())
        l.append((s,t,x))
    l.sort(key=lambda a: a[2])
    start = [int(input()) for _ in range(q)]

    skip = [-1]*q
    res = [-1]*q

    for s,t,x in l:
        left = bisect_left(start, s-x)
        right = bisect_left(start, t-x)
        while left < right:
            if skip[left] == -1:
                res[left] = x
                skip[left] = right
                left += 1
            else:
                left = skip[left]
    
    for i in res:
        print(i)

if __name__ == '__main__':
    main()

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 2e5;

int n, a, b, c, d;
char s[MAXN+10];

int main()
{
    int i, j;
    scanf("%d%d%d%d%d%s", &n, &a, &b, &c, &d, s+1);

    if(c<d)
    {
        for(i=a; i<c; i++) if(s[i]=='#' && s[i+1]=='#') return !printf("No");
        for(i=b; i<d; i++) if(s[i]=='#' && s[i+1]=='#') return !printf("No");
        return !printf("Yes");
    }
    else
    {
        bool flag=false;
        for(i=a; i<c; i++) if(s[i]=='#' && s[i+1]=='#') return !printf("No");
        for(i=b; i<d; i++) if(s[i]=='#' && s[i+1]=='#') return !printf("No");
        for(i=b; i<=d; i++) if(s[i-1]=='.' && s[i]=='.' && s[i+1]=='.') flag=true;
        if(!flag) return !printf("No");
        return !printf("Yes");
    }
}


Measured memory_bytes: 384
/*
(1)for binary shift operator always use 'LL' 1LL<<63

*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set_pair tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
  const double  pi=3.1415926535; 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,m;cin>>n>>m;
	ll i,j;
	vector<vector<ll>> adj(n+1);
	queue<ll> q;
	//bool vis[n+1]={};
	ll par[n+1]={};
	for(i=0;i<m;i++){
		ll a,b;cin>>a>>b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	q.push(1);
	par[1]=1;
	while(!q.empty()){
		ll a=q.front();
		q.pop();
		for(auto it: adj[a]){
			if(par[it]==0){
				par[it]=a;
				q.push(it);
			}
		}
	}
	for(i=2;i<=n;i++){
		if(par[i]==0) break;
	}
	if(i==n+1){
		cout<<"Yes"<<endl;
		for(i=2;i<=n;i++) cout<<par[i]<<endl;
	}
else cout<<"No"<<endl;
	return 0;
} 

Measured memory_bytes: 12948