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

int n,opt,c[400001][2],sz[400001],f[400001],num[400001],root,len,v[400001];
int a[400001];
void add(int x,int fa)
{
    ++len;
    v[len]=x;
    sz[len]=1;
    num[len]=1;
    f[len]=fa;
    if(x<v[fa])
    c[fa][0]=len;
    else
    c[fa][1]=len;
    c[len][0]=c[len][1]=0;
}
void pushup(int x)
{
    sz[x]=sz[c[x][0]]+sz[c[x][1]]+num[x];	
}
int findip(int d)
{
    int x=root;	
    while(v[x]!=d)
    {
//		cout<<c[x][0]<<" "<<c[x][1]<<endl;
        if(d<v[x])
        {
            if(c[x][0]==0)
            break;
            else
            x=c[x][0];
        }
        else
        {
            if(c[x][1]==0)
            break;
            else
            x=c[x][1];
        }
    }
    return x;
}
void rotate(int x)
{
    int y=f[x],z=f[y],k=c[y][1]==x,w=c[x][!k];
    if(y!=root)
    c[z][c[z][1]==y]=x;
    c[x][!k]=y;
    c[y][k]=w;
    if(w)
    f[w]=y;
    f[y]=x;
    f[x]=z;
    pushup(y);
}
void splay(int x,int rt)
{
    while(f[x]!=rt)
    {
        int y=f[x],z=f[y];
        if(f[y]!=rt)
        {
            if(c[z][0]==y ^ c[y][0]==x)
            rotate(x);
            else
            rotate(y);
        }
        rotate(x);
        if(rt==0)
        root=x;
    }
    pushup(x);
}
void ins(int x)
{
    if(root==0)
    {
        add(x,0);
        root=len;
        return;
    }
    int y=findip(x);
    if(v[y]==x)
    {
        num[y]++;
        pushup(y);
        splay(y,0);
    }
    else
    {
        add(x,y);
        pushup(y);
        splay(len,0);
    }
}
void del(int x)
{
    int y=findip(x);
    splay(y,0);
    if(num[y]>1)
    {
        num[y]--;
        pushup(y);
        return;
    }
    if(c[y][0]==0&&c[y][1]==0)
    {
        root=0;
        len=0;
    }
    else if(c[y][0]==0&&c[y][1]!=0)
    {
        root=c[y][1];
        f[root]=0;
    }
    else if(c[y][0]!=0&&c[y][1]==0)
    {
        root=c[y][0];
        f[root]=0;
    }
    else
    {
        int z=c[y][0];
        while(c[z][1])
        z=c[z][1];
        splay(z,y);
        int r=c[y][1];
        c[z][1]=r;
        f[r]=z;
        root=z;
        f[root]=0;
        pushup(z);
    }
}
int findshuzi(int k)
{
    int x=root;
    while(1)
    {
        if(k<=sz[c[x][0]])
        x=c[x][0];
        else if(k>sz[c[x][0]]+num[x])
        {
            k-=sz[c[x][0]]+num[x];
            x=c[x][1];
        }
        else
        break;
//		cout<<x<<endl;
    }
    splay(x,0);
    return v[x];
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
    	scanf("%d",&a[i]);
    	ins(a[i]);
	}
    
    for(int i=1;i<=n;i++)
    {
    	del(a[i]);
    	printf("%d\n",findshuzi(n/2));
    	ins(a[i]);
	}
    return 0;
}

Measured memory_bytes: 12288
N = int(input())
ab = []
cd = []
for i in range(N):
    ab.append(list(map(int, input().split())))
for i in range(N):
    cd.append(list(map(int, input().split())))
    
ab.sort(key=lambda x:x[0],reverse=True)
cd.sort(key=lambda x:x[1])


ans = 0
for a,b in ab:
    for c,d in cd:
        if a<c and b<d:
            ans += 1
            cd.remove([c,d])
            break

print(ans)

Measured memory_bytes: 3064
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << '\n';
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

//------------------------- Libraries -------------------------//

vector<long long> enum_divisors(long long N) {
    vector<long long> res;
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // 重複しないならば i の相方である N/i も push
            if (N/i != i) res.push_back(N/i);
        }
    }
    // 小さい順に並び替える
    sort(res.begin(), res.end());
    return res;
}

//--------------------------- Solve ---------------------------//

void solve() {
    long long N; cin >> N;

    set<long long> ans;

    vector<long long> v0 = enum_divisors(N-1);
    for (auto K : v0) {
        if (K == 1) continue;
        ans.insert(K);
    }

    vector<long long> v = enum_divisors(N);
    for (auto K : v) {
        if (K == 1) continue;
        
        long long n = N;
        while (n % K == 0) {
            n /= K;
            if ((n-1) % K == 0) ans.insert(K);
        }

        n = N;
        while (n % K == 0) {
            n /= K;
            if (n == 1) ans.insert(K);
        }
    }

    cout << ans.size() << '\n';
}

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

    solve();

    return 0;
}

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

int n,w;
int weight[101];
int value[101];
ll dp[101][100001];

int main() {
    cin >> n >> w;
    for (int i=1;i<=n;i++) {
        cin >> weight[i];
        cin >> value[i];
    }

    for (int j=1;j<=100000;j++) {dp[0][j]=INT_MAX;}

    for (int i=1;i<=n;i++) {
        for (int j=1;j<=100000;j++) {
            dp[i][j]=dp[i-1][j];
            if (j>=value[i]) {
                dp[i][j]=min(dp[i][j],dp[i-1][j-value[i]]+weight[i]);
            }
        }
    }
    for (int j=100000;j>=0;j--) {
        if (dp[n][j]<=w) {
            cout << j << endl;
            return 0;
        }
    }
}


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

#define all(x) x.begin(), x.end()
#define lc (i << 1)
#define rc (i << 1 | 1)
// #define m ((l + r) >> 1)

using namespace std;

void setIO(string name) {
    freopen((name + ".in").c_str(), "r", stdin);
    freopen((name + ".out").c_str(), "w", stdout);
}

// using namespace __gnu_pbds;
// using mii = gp_hash_table<int, int>;
// typedef tree<pii, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int MN = 1 * 1e3 + 5, LN = 17, INF = 0x3f3f3f3f, MOD = 1e9 + 7;

map<string, int> mp;

int main() {
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    int N; cin >> N;
    for (int i = 0; i < N; i++) {
        string s; cin >> s;
        mp[s]++;
    }
    int mx = 0;
    vector<string> v;
    for (auto i : mp) {
        if (i.second > mx) {
            mx = i.second;
            v.clear();
            v.push_back(i.first);
        } else if (i.second == mx) {
            v.push_back(i.first);
        }
    }
    for (auto i : v) {
        cout << i << '\n';
    }
    return 0;
}


Measured memory_bytes: 26096
import itertools
import math
import fractions
import functools
n = int(input())
s = []
for i in range(n):
    string = sorted(input())
    s.append(''.join(string))

hist = {}
for i in range(n):
    current = hist.get(s[i],0)
    hist[s[i]] = current + 1

count = 0
for i in hist:
    count += (hist[i]*(hist[i]-1))//2

print(count)

Measured memory_bytes: 94164
//https://atcoder.jp/contests/abc124/tasks/abc124_c
#include<bits/stdc++.h>
using namespace std;
#define TEMPLATE
#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}}star;
#define DEBUG if(0)
#endif
#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}
class reverse_range {private:struct I {int x;int operator*() {return x-1;}bool operator!=(I& lhs) {return x>lhs.x;}void operator++() {--x;}};I i, n;public:reverse_range(int n) :i({ 0 }), n({ n }){}reverse_range(int i, int n) :i({ i }), n({ n }){}I& begin() {return n;}I& end() {return i;}};
class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }reverse_range operator!(){return reverse_range(*i,*n);}};
template<typename T>inline T& unused_var(T& v){return v;}
using LL = long long;
string s;
int f(int v){
    int ret=0;
    for(auto c:s){
        ret+=v^(c-'0');
        v=1-v;
    }
    return ret;
}
int main(){
    cin>>s;
    cout << min(f(0),f(1)) <<  endl;
    return 0;
}

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

int main() {
    int n = 0, index = 0;
    cin >> n;
    string s = "", all_alphabet = "";
    cin >> s;
    all_alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    
    for (int i = 0; i < s.size(); i++) {
        index = all_alphabet.find(s.at(i));
        cout << all_alphabet.at((index + n) % 26);
    }
    cout << endl;
}

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

using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i < (n); --i)
#define all(x) (x).begin(), (x).end()
#define gsort(x, n) sort((x), (x + n) greater<int>())
#define rv(s) reverse((s).begin(), (s).end())
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10);
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).flont_back(a)
#define eb(x, a) (x).emplaes_back(a)
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1e9 + 7;

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

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

   if (a == b && a != c)
   {
      cout << "Yes\n";
   }
   else if (b == c && a != b)
   {
      cout << "Yes\n";
   }
   else if (a == c && a != b)
   {
      cout << "Yes\n";
   }
   else
   {
      cout << "No\n";
   }
}

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

using namespace std;

using ll = long long;

struct Edge {
    int to;
    ll cost;
    Edge(int to, ll cost) : to(to), cost(cost) {}
};

typedef vector<vector<Edge> > AdjList; //隣接リスト

const ll INF = 1e15;
const int NONE = -1;

//trueなら負の閉路を検出
bool bellman_ford(int n, int s, vector<ll>& minc, AdjList& graph) { //nは頂点数、sは始点
    minc.resize(n, INF);
    minc[s] = 0; //始点までの距離は0
    for (int i = 1; i < n; i++) {
        for (int from = 0; from < n; from++) {
            for (Edge& e : graph[from]) {
                if (minc[from] != INF && minc[e.to] > minc[from] + e.cost) {
                    minc[e.to] = minc[from] + e.cost;
                }
            }
        }
    }

    //負の閉路を検出
    for (int from = 0; from < n; from++) {
        for (Edge& e : graph[from]) {
            if (minc[from] != INF && minc[e.to] > minc[from] + e.cost) {
                return true;
            }
        }
    }
    return false;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    ll p;
    cin >> n >> m >> p;

    AdjList graph(n), graph_rev(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        ll c;
        cin >> a >> b >> c;
        a--; b--;
        graph[a].emplace_back(b, p - c);
        graph_rev[b].emplace_back(a, p - c);
    }

    vector<ll> minc_1;
    bellman_ford(n, 0, minc_1, graph);

    vector<ll> minc_n;
    bellman_ford(n, n - 1, minc_n, graph_rev);

    for (int i = 0; i < n; i++) {
        for (Edge& e : graph[i]) {
            if (minc_1[i] >= INF || minc_n[e.to] >= INF) continue;
            if (minc_1[n - 1] > minc_1[i] + minc_n[e.to] + e.cost) {
                cout << -1 << endl;
                return 0;
            }
        }
    }

    cout << max(-minc_1[n - 1], 0LL) << endl;
    return 0;
}

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

int main() {
    int e[12];
    for(int i=0;i<12;i++){
        cin >> e[i];
    }
    sort(e,e+12);
    if(e[0] == e[3] && e[4] == e[7] && e[8] == e[11]){
        cout << "yes" << endl;
    }
    else{
        cout << "no" << endl;
    }
    return 0;
}

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

int main(void){
    int n;cin >> n;
    double v[n];
    for (int i=0;i<n;i++){
        cin >> v[i];
    }

    sort(v,v+n);

    double sum = 0;

    for (int i=0;i<n;i++){
        if (i ==0){
            continue;
        }

        v[i] = (v[i-1] + v [i]) / 2;

        if (i == n-1){
            sum = v[i];
        }
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<tuple>
#include<ctime>
#include<functional>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p; 
#define rep(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
    int K,X;
    cin>>K>>X;
    if(500*K>=X) p("Yes");
    else p("No");
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second

static const double PI=6*asin(0.5);
typedef pair<double,double> P;
typedef complex<double> CP;
typedef long long ll;

int a[110];

int main(){
	int n;
	while(cin>>n,n){
		rep(i,110) a[i]=0;
		rep(i,n){
			cin>>a[i];
		}
		ll res=0;
		for(int i=n;i>1;i--){
			for(int j=0;j<i-1;j++){
				if(a[j]>a[j+1]){
					int t;
					t=a[j+1];
					a[j+1]=a[j];
					a[j]=t;
					res++;
				}
			}
		}
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define sz(x)             (int)((x).size())
#define int               long long
#define M                 1000000007
#define MM                998244353
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount

template<typename T1,typename T2>
std::istream& operator>>(std::istream& in,pair<T1,T2> &a)
{
	in>>a.fr>>a.sc;
	return in;
}
template<typename T1,typename T2>
std::ostream& operator<<(std::ostream& out,pair<T1,T2> &a)
{
	out<<a.fr<<" "<<a.sc;
	return out;
}

int n,a[200005],h[200005],dp[200005];
#define SIZE   200005
#define LSB(i) ((i) & -(i)) // zeroes all the bits except the least significant one

int A[SIZE];

int query(int i) // Returns the sum from index 1 to i
{
	int sum = 0;
	while (i > 0) 
		sum = max(sum,A[i]), i -= LSB(i);
	return sum;
}
void update(int i, int k) // Adds k to element with index i
{
	while (i < SIZE) 
		A[i] = max(A[i],k), i += LSB(i);
}
void solve(){
	cin>>n;
	rep(i,1,n+1)cin>>h[i];
	rep(i,1,n+1)cin>>a[i];
	dp[1]=a[1];
	update(h[1],dp[1]);
	rep(i,2,n+1){
		dp[i]=a[i]+query(h[i]);
		update(h[i],dp[i]);
	}
	cout<<query(n);
}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	#ifdef SEIVE
		seive();
	#endif
	#ifdef NCR
		init();
	#endif
	#ifdef DSU
		cleardsu(MAXDSUSIZE);
	#endif
	int t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
}


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

using namespace std;

typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli>> mat;

lli n;
vll a;
mat ans;

int main(){
  cin >> n;
  a = vll(n+1);
  for(lli i = 1;i <= n;i++) cin >> a[i];
  auto max_elem = max_element(a.begin()+1,a.end());
  auto min_elem = min_element(a.begin()+1,a.end());
  cout << 2*n-1 << endl;
  if(*max_elem > -*min_elem){
    for(lli i = 1;i <= n;i++){
      cout << max_elem-a.begin() << " " << i << endl;
    }
    for(lli i = 1;i < n;i++){
      cout << i << " " << i+1 << endl;
    }
  }else{
    for(lli i = 1;i <= n;i++){
      cout << min_elem-a.begin() << " " << i << endl;
    }
    for(lli i = n;i > 1;i--){
      cout << i << " " << i-1 << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
out = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

k = gets.chomp.to_i
puts out[k-1]

Measured memory_bytes: 1788
#include<iostream>
#include<stdio.h>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
using namespace std;

int main(){
    int A, B, K;
    cin >> A >> B >> K;
    vector<int> vec;
    for(int i=1; i<=100; ++i){
        if(A%i==0 && B%i==0){
            vec.push_back(i);
        }
    }
    int size = vec.size();
    cout << vec[size-K];
    return 0;
}

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
template<typename V> constexpr typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  string s;
  int k;
  cin >> s >> k;
  int n = s.size();
  rep(i, n) if (s[i] != 'a') {
    if (s[i] + k > 'z') {
      k -= 'z' - s[i] + 1;
      s[i] = 'a';
    }
  }
  k %= 26;
  if (k > 0) s[n - 1] = (s[n - 1] - 'a' + k) % 26 + 'a';
  cout << s << endl;
}


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

using namespace std;

#define ll long long

//Tumhe kya laga me code nahi kar sakta, me sab kar sakta hai,
//kyunki hindustan ka yuva sirf hindustan ko nahi desh ko badal sakta hai

int main()
{
	ll n,k;
	cin>>n>>k;
	long double p[n];
	for(ll i = 0;i<n;i++)
	{
		long double t;
		cin>>t;
		p[i] = (t+1)/2;
	}
	long double ss[n+1];
	ss[0] = 0;
	for(ll i = 1;i<=n;i++)
	{
		ss[i] = ss[i-1]+p[i-1];
	}
	long double ans = 0.0;
	for(ll i = k;i<=n;i++)
	{
		ans = max(ans,ss[i]-ss[i-k]);
	}
	cout<<fixed<<setprecision(12)<<ans;
	return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST

bool isPrime(ll x){
    if(x < 2)return false;
    else if(x == 2) return true;
    if(x%2 == 0) return false;
    for(ll i = 3; i*i <= x; i += 2) if(x%i == 0) return false;
    return true;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long Q;
    cin >> Q;
    vector<ll> odd2017(100001);
    vector<ll> _odd2017;
    for(size_t i=1;i<100001; i++)
    {
        if(isPrime(i))
        {
            if(i*2>=100001) continue;
            if(isPrime(i*2 - 1))
            {
                //cerr << i << ":" << i*2-1 << endl;
                _odd2017.push_back(i*2-1);
            }
        }
    }
    //for(auto i:_odd2017) cerr << i << endl;
    ll idx=0;
    for(size_t i=1;i<100001; i++)
    {
        if(i == _odd2017[idx])
        {
            odd2017[i]=odd2017[i-1]+1;
            idx++;
        }
        else odd2017[i]=odd2017[i-1];
        //cerr << i << ":" << odd2017[i] << endl;
    }

    vector<ll> l(Q), r(Q);
    for(size_t i=0;i<Q; i++)
    {
        cin >> l[i] >> r[i];
        //cerr << odd2017[r] << ":" << odd2017[l-1] << endl;
    }
    for(size_t i=0;i<Q;  i++)
    {
        cout << odd2017[r[i]] - odd2017[l[i]-1] << endl;
    }
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 5536
#include <iostream>
#include <cmath>
#include <cstdio>
#include <stack>
#include <queue>
#include <vector>
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;

string s;
ll ans=0;

int main(){
    cin>>s;
    string t="CODEFESTIVAL2016";
    for(ll i=0;i<16;++i){
        if(s[i]!=t[i]){
            ans+=1;
        }
    }
    cout<<ans<<endl;
}

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

vector<vector<int> > edge;
bool visited[128];
int n;
int depth = 0;

int solve(int k) {
	if(visited[k])
		return -1;
	visited[k] = true;
	int res = -1;
	for(int i = 0; i < edge[k].size(); i++) {
		res = max(res, solve(edge[k][i]));
	}
	visited[k] = false;
	return res+1;
}

int main() {
	while(cin >> n, n) {
		for(int i = 0; i < 128; i++)
			visited[i] = false;
		edge.clear();
		edge.resize(100);
		for(int i = 0; i < n; i++) {
			int a, b;
			cin >> a >> b;
			a--; b--;
			edge[a].push_back(b);
			edge[b].push_back(a);
		}

		int res = 0;
		for(int i = 0; i < 100; i++) {
			res = max(res, solve(i) + 1);
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 1220
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <complex>


using namespace std;

int main(){
    long long int N,amari,sho= 0;
    cin >> N;
    sho = N/500;
    amari = N%500;
    cout << sho*1000 + amari/5 * 5 << endl;

    return 0;
}

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

int main(void){
    int a, b, c;
    
    cin >> a >> b >> c;
    
    int counter = 0;
    
    int total = a + b + c;
    int maximum = max({a, b, c});
    int total2 = 3 * maximum;
    int total3 = 3 * (maximum + 1);
    
    if((total % 2 == 0 && total2 % 2 == 0) || (total % 2 != 0 && total2 % 2 != 0)){
        counter = (total2 - total) / 2;
    } else if((total % 2 == 0 && total3 % 2 == 0) || (total % 2 != 0 && total3 % 2 != 0)){
        counter = (total3 - total) / 2;   
    }
    
    cout << counter << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i))
#define mat(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define each(x,y) for(auto &(x):(y))
#define var(type, ...)type __VA_ARGS__;Scan(__VA_ARGS__);
template<typename T> void Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void Scan(First& first, Rest&...rest) { cin >> first; Scan(rest...); }
#define vec(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define em emplace
#define pb pop_back
#define fi first
#define se second
#define get(a, i) get<i>(a)
#define mt make_tuple
inline string zero(int a,string s,char c='0'){return string(a-len(s),c)+s;}
inline string zero(int a,int t,char c='0'){return zero(a, to_string(t), c);}
inline string zero(int a,ll t,char c='0'){return zero(a, to_string(t), c);}
#define mini min_element
#define maxi max_element
#define sum accumulate
#define chmax(a,b) if(a<b)a=b
#define chmin(a,b) if(a>b)a=b
template <class T> inline void print(T t){cout << t << endl;}
template <class H, class... T> inline void print(H h, T... t){cout << h << " ";print(t...);}
int main() {
	var(ll, n, k);
	print(ll(pow(n / k, 3) + ((k & 1) ? 0 : pow((n + k / 2) / k, 3))));
	return 0;
}


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

typedef long long ll ; 
const int N = 405;
ll dp[N][N] , a[N]  , sum[N]; 

ll calc(int l , int r) {
	if (l >= r)
		return 0 ; 
	
	ll &ret = dp[l][r] ;  
	if (ret != -1)return ret ; 
	
	ret = 2e18 ; 
	
	for (int i = l ; i< r ; ++i) {
		ret =min(ret , calc(l , i)+calc(i+1 , r)+sum[r]-sum[l-1]) ; 
	}
	return ret ; 
}
int main() {
	int n  ;
	scanf("%d" , &n) ; 
	memset(dp ,-1 , sizeof dp) ; 
	for (int i =0 ; i<n ; ++i) 
		scanf("%d" , &a[i]) ; 
	
	for (int i =0 ; i<n ;++i) {
		if (!i)sum[i] = 0;
		else sum[i] = sum[i-1] ; 
		sum[i] += a[i];
	}
	
	ll ans = calc(0 , n-1) ; 
	printf("%lld" , ans) ; 
	return 0;
}

Measured memory_bytes: 1536
#include <cstdio>
#include <vector>
using namespace std;

typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);++i)
#define rep(i,n) FOR(i,0,n)

int main(){
    ll n;
    scanf("%lld", &n);
    vector<ll> a(n+2);
    ll tot = 0;
    rep(i,n) {
        scanf("%lld", &a[i]);
        tot += a[i];
    }
    
    ll sum = n * (n+1) / 2LL;
    if(tot % sum != 0) {
        puts("NO"); return 0;
    }

    vector<ll> d(n+2);
    ll cnt = 0;
    bool f = true;
    rep(i,n){
        d[i] = (a[(i+1) % n] - a[i]);
        d[i] -= tot / sum;
        if(d[i] > 0) f = false;
        if(d[i] % n == 0) cnt += -d[i] / n;
    }
    if(cnt != tot / sum) f = false;

    puts(f ? "YES" : "NO");

    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int temp,i,j,r=0,n,m,c;
  cin>>n;
  cin>>m;
  cin>>c;
  vector<int> b(m);
  vector<int> a(m);
  for(i=0;i<m;i++){
    cin>>b[i];
  }
  for(j=0;j<n;j++){
    temp=c;
    for(i=0;i<m;i++){
      cin>>a[i];
      temp+=a[i]*b[i];
    }
    if(temp>0) r++;
  }
  cout<<r<<endl;
  return 0;
    
}

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

int main(){
  int m[50],f[50],r[50];
  int n = 0;
  while(1){
    cin >> m[n] >> f[n] >> r[n];
    if(m[n] == -1 && f[n] == -1 && r[n] == -1)
      break;
    n++;
  }
  for(int i = 0; i < n; i++){
    if(m[i] == -1 || f[i] == -1)
      cout << "F" << endl;
    else if(m[i]+f[i]>=80)
      cout << "A" << endl;
    else if(m[i]+f[i]>=65)
      cout << "B" << endl;
    else if((m[i]+f[i]>=50)||r[i]>=50)
      cout << "C" << endl;
    else if(m[i]+f[i]>=30)
      cout << "D" << endl;
    else
      cout << "F" << endl;
  }
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<vector<ll>> adj;
vector<ll> du, dv, dw, dx;

void dfs(int n, int p, vector<ll> &d) {
  for (auto x: adj[n]) {
    if (x==p) continue;
    d[x] = d[n]+1;
    dfs(x,n,d);
  }
}


int main() {
  int N, u, v; cin >> N >> u >> v; u--; v--;
  adj.resize(N);
  rep(i,N-1) {
    int A, B; cin >> A >> B; A--; B--;
    adj[A].push_back(B);
    adj[B].push_back(A);
  }
  du.resize(N,0); dfs(u,-1,du);
  dv.resize(N,0); dfs(v,-1,dv);
  // debug(all(du)); debug(all(dv));

  int l = dv[u], w = 0, x = 0;
  rep(i,N) {
    if (du[i]==(l-1)/2&&dv[i]==l-(l-1)/2) w = i;
    if (du[i]==(l+1)/2&&dv[i]==l-(l+1)/2) x = i;
  }
  // cout << l << " " << w << " " << x << endl;
  dw.resize(N,0); dfs(w,-1,dw);
  dx.resize(N,0); dfs(x,-1,dx);
  // debug(all(dw)); debug(all(dx));
  
  ll result = 0;
  rep(i,N) {
    if (dx[i]-dw[i]==1) result = max(result, dw[i]);
  }
  result += l/2;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 14208
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"
#define fcout cout << fixed << setprecision(18)

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926535
/*
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
*/
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1
#define LINF 1000000000000000001 // 1e18+1

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  string s;cin>>s;
  if(s[0]=='A'){
    for(int i=2;i<=(int)s.size()-2;i++){
      if(s[i]=='C'){
        for(int j=1;j<(int)s.size();j++){
          if(j==i)continue;
          if(!(s[j] >= 'a' && s[j]<='z')){
            goto E;
          }
        }
        P("AC");
        return 0;
      }
    }
  }
  E:;
  P("WA");
  return 0;
}


Measured memory_bytes: 256
//------------------------------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//																				NEVER GIVE UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define mod 1000000007
 //----------------------------------------------------------------------------------------------------------------------------------------------------

int main()
{
	fast;
	string str;
	cin>>str;
	bool flag=true;
	for(int i=0;i<3;i++)
	{
		if(str[i]==str[i+1])
		{
			flag=false;
			break;
		}
	}
	if(!flag)
		cout<<"Bad";
	else
		cout<<"Good";
	return 0;
}

Measured memory_bytes: 256
S = input().split()
N = int(S[0])
M = int(S[1])
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A_MAX = max(A)
B_MAX = max(B)
MAX = A_MAX if (A_MAX > B_MAX) else B_MAX

mod = int(1e9 + 7)

A_F_cnt = 0
B_F_cnt = 0

sA = set(A)
sB = set(B)

result = 1

for i in range(MAX, 0, -1):
    in_A = (i in sA)
    in_B = (i in sB)
    if (in_A and in_B):
        A_F_cnt += 1
        B_F_cnt += 1
    elif (in_A):
        result *= B_F_cnt
        result %= mod
        A_F_cnt += 1 
    elif (in_B):
        result *= A_F_cnt
        result %= mod
        B_F_cnt += 1
    else:
        coef = ((A_F_cnt * B_F_cnt) % mod ) - (N*M - i)
        if coef < 0:
            coef += mod
        result *= coef
        result %= mod
    
    # print(in_A, in_B, A_F_cnt, B_F_cnt, result)

print(int(result % mod))

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

string s;

int main(){
  cin >> s;
  int n = s.size();
  string res = "NO";
  rep(i, n){
    rep(j, n + 1){
      if(j < i){
        continue;
      }
      string sub1 = s.substr(0, i);
      string sub2 = s.substr(j, n - j);
      string t = sub1 + sub2;
      //cerr << t << endl;
      if(t == "keyence"){
        res = "YES";
      }
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define IOS ios::sync_with_stdio(false); cin.tie(NULL);
#ifndef LOCAL
#define dbg(...) ;
#define endl '\n'
#endif

const int inf = 1e15;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;

char c[15][1005];
int pre[15][1005];
int n, m, K;

int check(int x) {
    for (int i = 0; i < (1 << (n-1)); i++) {
        vector<int> v;
        for (int j = 0; j < (n-1); j++) {
            // dbg(i, j)
            if (i & (1 << j)) v.push_back(j);
        }
        v.push_back(n-1);
        vector<int> v1;
        v1.resize(v.size());
        int ans = 0;
        dbg(x, i, v)
        int flag = 0;
        for (int j = 0; j < m; j++) {
            for (int k = 0; k < (int)v.size(); k++) {
                if (k == 0) v1[k] += pre[v[k]][j];
                else v1[k] += pre[v[k]][j] - pre[v[k-1]][j];
                dbg(v1[k])
                if (v1[k] > K) {
                    ans++;
                    for (int kk = 0; kk < (int)v.size(); kk++) {
                        if (kk == 0) v1[kk] = pre[v[kk]][j];
                        else v1[kk] = pre[v[kk]][j] - pre[v[kk-1]][j];
                        if (v1[kk] > K) flag = 1;
                    }
                    break;
                }
            }
        }
        if (flag) continue;
        if (ans + (int)v.size() - 1ll <= x) return 1;
    }
    return 0;
}

signed main(){
    IOS;
    cin >> n >> m >> K;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> c[i][j];
        }
    }
    int l = 0, r = n+m-2;
    int ans = r;
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < n; j++) {
            if (j == 0) {
                if (c[j][i]=='1') pre[j][i] = 1;
                else pre[j][i] = 0;
            }
            else {

                pre[j][i] = pre[j-1][i] + ((c[j][i] == '1') ? 1 : 0);
            }
        }
    }
    while (l <= r) {
        int mid = (l + r) / 2;
        if (check(mid)) ans = mid, r = mid - 1;
        else l = mid + 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
import java.util.*;
import java.util.Map.Entry;
 
class Main {
	 static int mod =  (int) (Math.pow(10,9)+7);
	 static List<ArrayList<Integer>> list= new ArrayList<ArrayList<Integer>>();
//	 static int mod = 998244353;
	 public static void main(String[] args) {
	        Scanner sc = new Scanner(System.in);
	        int N = sc.nextInt();	
	        int M = sc.nextInt();	
	        int ans=0;
	        for(int i=M/N;i>=0;i--) {
	        	int tmp=M;
	        	tmp=tmp-i*N;
	        	if(tmp%i==0) {
	        		ans=i;
	        		System.out.println(ans);
	        		return;
	        	}
	        }
	        
	        
	        
	 }

}

Measured memory_bytes: 23252
package main

import "fmt"

func main() {
	var n, a, b, c int
	fmt.Scan(&n)
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)

	m := a + b + c
	d := map[byte]int{'A': a, 'B': b, 'C': c}

	answers := make([]byte, n, n)

	if m == 0 {
		fmt.Println("No")
		return
	}

	s := make([]string, n, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&s[i])
	}

	for i := 0; i < n; i++ {
		c1 := s[i][0]
		c2 := s[i][1]

		if d[c1] == 0 && d[c2] == 0 {
			fmt.Println("No")
			return
		}

		if d[c1] == 1 && d[c2] == 1 && i < n-1 && s[i] != s[i+1] {
			c3 := map[string]byte{"AB": 'C', "AC": 'B', "BC": 'A'}[s[i+1]]
			var c4 byte
			if c3 == c1 {
				c4 = c2
			} else {
				c4 = c1
			}
			d[c3]--
			d[c4]++
			answers[i] = c4
		} else if d[c1] >= d[c2] {
			d[c1]--
			d[c2]++
			answers[i] = c2
		} else {
			d[c1]++
			d[c2]--
			answers[i] = c1
		}
	}

	fmt.Println("Yes")
	for i := 0; i < n; i++ {
		fmt.Println(string(answers[i]))
	}
}


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

//#define int long long
typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i=0;i<N;i++) cin >> A[i];
    sort(A.begin(),A.end());
    vector<int> plus;
    vector<int> minus;
    plus.push_back(A[N-1]);
    minus.push_back(A[0]);
    for (int i=1;i<N-1;i++){
        if (A[i] >= 0) plus.push_back(A[i]);
        else minus.push_back(A[i]);
    }
    vector<pair<int,int>> ans;
    for (int i=0;i<plus.size()-1;i++){
        int x, y;
        x = minus[minus.size()-1];
        y = plus[i];
        ans.emplace_back(x,y);
        minus[minus.size()-1] = x - y;
    }
    for (int i=0;i<minus.size();i++){
        int x, y;
        x = plus[plus.size()-1];
        y = minus[i];
        ans.emplace_back(x,y);
        plus[plus.size()-1] = x - y;
    }
    cout << plus[plus.size()-1] << "\n";
    for (int i=0;i<ans.size();i++){
        cout << ans[i].first << " " << ans[i].second << "\n";
    }
}

Measured memory_bytes: 5408
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

use std::cmp::{max, min};
use std::collections::HashMap;

fn main() {
  let a = read::<i64>();
  let b = read::<i64>();

  println!("{}", max(a + b, max(a - b, a * b)));
}



Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll n;
    cin >> n;
    ll a = 11;
    while (n > 0) {
        ll k = 0;
        for (int i = 2; i < sqrt(a)+1; i++) {
            if (a % i == 0)k = 1;
        }
        if (k == 0) {
            cout << a;
            n--;
            if (n == 0)break;
            cout << " ";
        }
        a += 5;
    }
    cout << endl;
}

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

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    string sa, sb, sc; cin >> sa >> sb >> sc;

    int a = 0, b = 0, c = 0;
    char turn = 'a';
    while (true) {
        if (turn == 'a') {
            if (a == sa.size()) break;
            turn = sa[a];
            a++;
        }
        else if (turn == 'b') {
            if (b == sb.size()) break;
            turn = sb[b];
            b++;
        }
        else if (turn == 'c') {
            if (c == sc.size()) break;
            turn = sc[c];
            c++;
        }
    }

    cout << (char)(turn - 'a' + 'A') << '\n';
}

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

    solve();

    return 0;
}


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

#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long
#define endl '\n'
#define eps  1e-9
const double pi=acos(-1);
const int mod=1e9+7;
//_______________________


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

  if(a<b)
    swap(a,b);

  cout<<max(a+b,2*a-1);

 return 0;
}

Measured memory_bytes: 256
n=int(input())
a=input()
b=input()
c=input()
ans=0
for i in range(n):
  if a[i]==b[i]==c[i]:
    ans+=0
  elif a[i]==b[i] or b[i]==c[i] or c[i]==a[i]:
    ans+=1
  else:
    ans+=2
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double h = sc.nextDouble();
        long ans = 1;
        int cnt = 1;
        while (h > 1) {
            h = Math.floor(h / 2);
            ans += Math.pow(2, cnt);
            cnt++;
        }
        System.out.println(ans);
    }

}


Measured memory_bytes: 23764
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        long[] a = new long[n];
        long sum = 0;
        for(int i=0; i<n; i++) {
            a[i] = Long.parseLong(sc.next());
            sum += a[i];
            sum %= 1000000007;
        }
        
        long ans = 0;
        for(int i=0; i<n; i++) {
            sum = sum-a[i];
            if(sum < 0) sum += 1000000007;
            ans += a[i]*sum;
            ans %= 1000000007;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 62100
#line 2 "header.hpp"

//%snippet.set('header')%
//%snippet.fold()%
#ifndef HEADER_H
#define HEADER_H

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

// varibable settings
const long long INF = 1e18;
template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (ll i = (ll)((b)-1); i >= (ll)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
template <class T> inline void chmax(T &a, const T &b) { if ((a) < (b)) (a) = (b); }
template <class T> inline void chmin(T &a, const T &b) { if ((a) > (b)) (a) = (b); }
template <typename X, typename T> auto make_table(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto make_table(X x, Y y, Z z, Zs... zs) { auto cont = make_table(y, z, zs...); return vector<decltype(cont)>(x, cont); }

#define cdiv(a, b) (((a) + (b)-1) / (b))
#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x) sort(all(x)); x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)

typedef long long ll;
typedef long double ld;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;

template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
void check_input() { assert(cin.eof() == 0); int tmp; cin >> tmp; assert(cin.eof() == 1); }

#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif

#endif /* HEADER_H */
//%snippet.end()%
#line 2 "solve.cpp"
template<class T=ll> using vec = vector<T>;
struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast;


int solve() {
    ll n;cin>>n;

    vector<ll> a(n);
    rep(i, n) {
        cin>>a[i];
    }
    dump(a);

    ll x = 1000;
    ll y = 0;
    rep(i, n-1){
        if (a[i] < a[i+1]){
            x += y * a[i];
            y = 0;

            ll c = x / a[i];
            y += c;
            x -= c * a[i];
        }
        else{
            x += y * a[i];
            y = 0;
        }
        dump(x, y);
    }
    x += a[n-1] * y;
    cout << x << endl;

    return 0; 
}


int main(){/*{{{*/
    solve();
    check_input();
    return 0;
}/*}}}*/


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

// main
int main(){
    int N, Y;
    cin >> N >> Y;
    for(int i = 0; i <= N; ++i){
        for(int j = 0; j <= N-i; ++j){
            int k = N - i - j;
            int total = 10000*i + 5000*j + 1000*k;
            if(total == Y){
                cout << i << " " << j << " " << k << "\n";
                return 0;
            }
        }
    }


    cout << -1 << " " << -1 << " " << -1 << "\n";

    return 0;
}

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

long long x[100010];

int main(){
  int n; long long k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int a; long long b;
    cin >> a >> b;
    x[a] += b;
  }
  for (int i = 0; i < 100010; i++) {
    k -= x[i];
    if (k <= 0) {
      printf("%d\n", i);
      return 0;
    }
  }
  return 0;
}


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

#define ll long long

int main(void){

    int h,w;
    cin>>h>>w;
    char c[h][w];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>c[i][j];
        }
    }

    for(int i=0;i<h;i++){
        for(int k=0;k<2;k++){
            for(int j=0;j<w;j++){
                cout<<c[i][j];
            }
            cout<<endl;
        }
    }


    return 0;
}

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

int N[1000010];

int compare_int(const void *a,const void *b){
	return *(int*)a-*(int*)b;
}

int main(){
	int n,i,ans=0,a[200000];
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&a[i]);
	qsort(a,n,sizeof(int),compare_int);
	for(i=0;i<n;i++){
		if(N[a[i]]==0){
			ans++;
			int j;
			for(j=1;j*a[i]<=1000000;j++){
				N[j*a[i]]=1;
			}
			if(i<n-1){
				if(a[i]==a[i+1])ans--;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 6396
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI = 3.1415926535897932;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

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

	vector<int> Li(N, 0);
	rep(i, N) cin >> Li.at(i);
	
	sort(Li.begin(), Li.end());
	reverse(Li.begin(), Li.end());

	int ans = 0;
	rep(i, K)
	{
		ans += Li.at(i);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3556