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

using namespace std;

typedef long long ll;

struct Node {
    int key;
    Node *p, *l, *r;
};

Node *root, *NIL;

Node* find(Node* u, int k) {
    while (u != NIL && k != u->key) {
        if (k < u->key)
            u = u->l;
        else
            u = u->r;
    }
    return u;
}

Node* treeMinimum(Node* x) {
    while (x->l != NIL)
        x = x->l;
    return x;
}

Node* treeSuccessor(Node* x) {
    if (x->r != NIL)
        return treeMinimum(x->r);
    Node *y = x->p;
    while (y != NIL && x == y->r) {
        x = y;
        y = y->p;
    }
    return y;
}

void treeDelete(Node *z) {
    Node *y; // delete node
    Node *x; // y's child

    if (z->l == NIL || z->r == NIL) y = z;
    else y = treeSuccessor(z);

    if (y->l != NIL) { x = y->l; }
    else { x = y->r; }

    if (x != NIL) { x->p = y->p; }

    if (y->p == NIL) {
        root = x;
    } else {
        if (y == y->p->l) {
            y->p->l = x;
        } else {
            y->p->r = x;
        }
    }

    if (y != z)
        z->key = y->key;

    free(y);
}


void insert(int k) {
    Node *y = NIL, *x = root, *z;
    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->l = NIL;
    z->r = NIL;

    while (x != NIL) {
        y = x;
        if (z->key < x->key)
            x = x->l;
        else
            x = x->r;
    }

    z->p = y;
    if (y == NIL) {
        root = z;
    } else {
        if (z->key < y->key) {
            y->l = z;
        } else {
            y->r = z;
        }
    }
}

void inorder(Node* u) {
    if (u == NIL) return;
    inorder(u->l);
    cout << " " << u->key;
    inorder(u->r);
}

void preorder(Node* u) {
    if (u == NIL) return;
    cout << " " << u->key;
    preorder(u->l);
    preorder(u->r);
}

int main() {
    int n; cin >> n;
    
    for (int i = 0; i < n; i++) {
        string com; cin >> com;

        if (com[0] == 'f') {
            int x; cin >> x;
            Node* t = find(root, x);
            if (t != NIL) cout << "yes" << endl;
            else cout << "no" << endl;
        } else if (com == "insert") {
            int x; cin >> x;
            insert(x);
        } else if (com == "print") {
            inorder(root);
            cout << endl;
            preorder(root);
            cout << endl;
        } else if (com == "delete") {
            int x; cin >> x;
            treeDelete(find(root, x));
        }
    }
}



Measured memory_bytes: 21888
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(int argc, char const *argv[])
{
    int H, W;
    cin >> H >> W;
    vector<string> C;
    string tmp;
    for (int i = 0; i < H; i++)
    {
        cin >> tmp;
        C.emplace_back(tmp);
    }
    
    for (int i = 0; i < H; i++)
    {
        cout << C[i] << endl;
        cout << C[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 504
text = input()
n = int(input())

for i in range(n):
    order = input().split()
    a, b= map(int, order[1:3])
    if order[0] == "print":
        print(text[a:b+1])
    elif order[0] == "reverse":
        re_text = text[a:b+1]
        text = text[:a] + re_text[::-1] + text[b+1:]
    else :
        text = text[:a] + order[3] + text[b+1:]



Measured memory_bytes: 5612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=1e6+5;
int main() {
	int n,k;cin>>n>>k;
	std::vector<int> V(n+1);
	ll ans=0;
	for(int i=1;i<=n;i++) {
		cin>>V[i];if(V[i]>k) ans+=V[i]-k;
		V[i]=min(V[i],k);
	}    
	for(int i=2;i<=n;i++) {
		if(V[i]+V[i-1]>k) {
			ans+=V[i]+V[i-1]-k;
			V[i]-=V[i]+V[i-1]-k;
		}
	}cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3692
import java.util.Scanner;

public class Main
{
	public static void main(String arg[])
	{
		Scanner sc = new Scanner(System.in);

		char ch[][] = new char[8][8];
		char tmp[][] = new char[8][8];
		for(int i=0; i<8; i++)
			ch[i]=sc.next().toCharArray();

		System.out.println(90);
		for(int i=7; i>=0; i--)
			for(int j=0; j<8; j++)
				tmp[j][i]=ch[7-i][j];
		ch=tmp;
		for(int i=0; i<8; i++)
		{
			for(int j=0; j<8; j++)
				System.out.print(ch[i][j]);
			System.out.println();
		}
		
		System.out.println(180);
		char tmp2[][] = new char[8][8];
		for(int i=7; i>=0; i--)
			for(int j=0; j<8; j++)
				tmp2[j][i]=ch[7-i][j];
		ch=tmp2;
		for(int i=0; i<8; i++)
		{
			for(int j=0; j<8; j++)
				System.out.print(ch[i][j]);
			System.out.println();
		}
		System.out.println(270);
		char tmp3[][] = new char[8][8];
		for(int i=7; i>=0; i--)
			for(int j=0; j<8; j++)
				tmp3[j][i]=ch[7-i][j];
		ch=tmp3;
		for(int i=0; i<8; i++)
		{
			for(int j=0; j<8; j++)
				System.out.print(ch[i][j]);
			System.out.println();
		}
		
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <vector>

using namespace std;

const int MaxN = 1001;
const int MaxM = 10001;

int N, M;

int main() {
  int count[MaxM];

  while(cin>>N>>M && !(N==0 && M==0)) {
    vector < vector< pair<int,int> > > logg(MaxM);
    int r;
    cin>>r;
    int t,n,m,s;
    for(int i=0; i<MaxM; i++) { // 初期化
      count[i] = 0;
    }
    for(int i=0; i<r; i++) {
      cin>>t>>n>>m>>s;
      if(s == 1) { // login
	count[m]++;
	if(count[m] == 1) {
	  logg[m].push_back(make_pair(t,t));
	}
      }
      else { // logout
	count[m]--;
	if(count[m] == 0) {
	  logg[m].back().second = t;
	}
      }
    }
    int q;
    cin>>q;
    for(int i=0; i<q; i++) {
      int ts, te, m, ans = 0;
      cin>>ts>>te>>m;
      int ans1, ans2; // 4debug ans1は誤りらしい
      for(int j=0; j<logg[m].size(); j++) {
	if(logg[m][j].first <= te) {
	  ans1 = min(te, logg[m][j].second)-max(ts, logg[m][j].first);
	}
	ans2 = max(0, min(te,logg[m][j].second)-max(ts,logg[m][j].first));
	/*
        if(ans1!=ans2) {
	  cout<<"Q: "<<ts<<" "<<te<<endl;
	  cout<<"why: "<<min(te, logg[m][j].second)-max(ts, logg[m][j].first)<<endl;
	  cout<<"val: "<<logg[m][j].first<<" "<<logg[m][j].second<<endl;
	  cout<<"ans: "<<ans1<<" "<<ans2<<endl;
	}
	*/
        ans += ans2;
      }
      cout<<ans<<endl;
    }
  }
}

Measured memory_bytes: 1476
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define db(x) (cerr << #x << ": " << (x) << '\n')
#define cps CLOCKS_PER_SEC
#define tests(t) int t; cin >> t; while(t--)
#define iceil(n, x) (((n) + (x) - 1) / (x))
#define eb emplace_back
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)), (v).erase(unique(all(v)), (v).end())
#define fi first
#define se second
#define bitcount(x) __builtin_popcount(x)
#define bit(x) (1LL << x)
#define PI acos(-1.0)
#define EPS 1e-9

#define mod 1000000007
#define maxn 200005

using namespace std;

using namespace __gnu_pbds;
template<class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
///All indexing is 0-based
///methods: find_by_order(k); & order_of_key(k);
///To make it an ordered_multiset, use pairs of (value, time_of_insertion)
///to distinguish values which are similar

typedef long long ll;
typedef double ld;
typedef pair<ll, ll> par;

ll Dp[maxn],chij[maxn],a,b,f[maxn],N,sol[maxn];
vector<int> G[maxn];

ll pot(ll b, ll e)
{
    if(e==0)
        return 1;
    if(e & 1)
        return b*pot(b,e-1)%mod;
    ll ret= pot(b,e/2);
    return ret*ret%mod;
}

ll inv(ll a)
{
    return pot(a , mod - 2);
}

void prec(int nod,int pad)
{
    Dp[nod] = chij[nod] = 1;
    ll div = 1;
    for(auto ady:G[nod]){
        if(ady == pad)
            continue;
        prec(ady,nod);
        chij[nod]+=chij[ady];
        Dp[nod] = Dp[nod]*Dp[ady]%mod;
        div = div*f[chij[ady]]%mod;
    }
    Dp[nod] =Dp[nod]*f[ chij[nod]-1 ]%mod;
    Dp[nod] = Dp[nod]*inv(div) %mod;
}

void dfs(int nod,int pad)
{
    for(auto ady:G[nod]){
        if(ady == pad)
            continue;

        Dp[nod] = Dp[nod] * f[ chij[ ady ]] %mod;
        Dp[nod] = Dp[nod] * inv(Dp[ady]) % mod;

        Dp[nod] = Dp[nod] * inv(f[N - 1] ) % mod;
        Dp[nod] = Dp[nod] * (f[N - chij[ady] - 1] ) % mod;

        Dp[ady] = Dp[ady] * Dp[nod] % mod;
        Dp[ady] = Dp[ady] * inv(f[ chij[ ady ]-1 ] )%mod;
        Dp[ady] = Dp[ady] * f[N - 1] %mod;
        Dp[ady] = Dp[ady] * inv(f[N - chij[ady]]) %mod;


        sol[ady] = Dp[ady];
        dfs(ady,nod);

        Dp[ady] = Dp[ady] * (f[N-chij[ady]]) %mod;
        Dp[ady] = Dp[ady] * inv(f[N - 1]) %mod;
        Dp[ady] = Dp[ady] * (f[ chij[ ady ]-1] )%mod;
        Dp[ady] = Dp[ady] * inv(Dp[nod]) % mod;

        Dp[nod] = Dp[nod] * inv(f[N - chij[ady] - 1] ) % mod;
        Dp[nod] = Dp[nod] * (f[N - 1]) % mod;

        Dp[nod] = Dp[nod] * Dp[ady] % mod;
        Dp[nod] = Dp[nod] * inv( f[ chij[ady] ]) %mod;


    }
}

int main()
{
    #ifdef acm
    freopen("a.in","r",stdin);
    #endif // acm
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> N;

    f[0]=1;
    for(int i=1;i<N;i++){
        cin >> a >> b;
        G[a].pb(b);
        G[b].pb(a);
        f[i] = f[i-1]*i%mod;
    }

    prec(1,-1);

    sol[1] = Dp[1];

    dfs(1,-1);

    for(int i=1;i<=N;i++)
        cout << sol[i] << "\n";


}


Measured memory_bytes: 20212
#include <iostream>

using namespace std;

int main(){
int A, B, C;
    cin >> A >> B >> C;
    if (A + B < C) { cout << "No"; }
    else if (A + B >= C) {
        if (A + B == 1) { cout << "No"; }
        else
            cout << "Yes";
    }
    

    return 0;
}

Measured memory_bytes: 256
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = ReadLine();
            string t = ReadLine();

            bool flag = false;
            for (int i = 0; i < s.Length; i++)
            {
                string sFirst = s[0].ToString();
                s = s.Substring(1, s.Length - 1) + sFirst;
                if (s == t)
                {
                    flag = true;
                    break;
                }
            }
            WriteLine(flag ? "Yes" : "No");
        }

        static int InputNum()
        {
            return int.Parse(ReadLine());
        }
        static List<int> InputNumList()
        {
            return ReadLine().Split(' ').Select(int.Parse).ToList();
        }
    }
}

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

int main(){
	int W,H,x,y,r;
	cin>>W>>H>>x>>y>>r;

	if(r<=x&&x<=W-r&&r<=y&&y<=H-r){
		cout<<"Yes"<<endl;
	}
	else
		cout<<"No"<<endl;

	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 1e5
#define INF 1<<30
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S;
ll ans = 0;

int main() {
	cin >> S;
	int ans0 = 0, ans1 = 0;
	for (int i = 0; i < S.size(); i++) {
		if (i & 1) {
			if (S[i] == '1') {
				ans0++;
			}
			else {
				ans1++;
			}
		}
		else {
			if (S[i] == '1') {
				ans1++;
			}
			else {
				ans0++;
			}
		}
	}
	ans = min(ans0, ans1);
	cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define rusha scanf("%d",&n);rep(i,1,n)scanf("%d",&a[i]);
#define rushb scanf("%d",&t);while(t--)
#define debug(x) cout<<" L-B-W-- "<<x<<" --N-B\n"
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vii vector<int>
#define fi first
#define se second
#define mem(a,b) memset(a,b,sizeof a)
#define all(x) (x.begin(),x.end())
#define judgef printf("%s\n",f?"Yes":"No")
#define Judgef printf("%s\n",f?"YES":"NO")
#define sz(x) ((int)(x).size())
#define sf(x) (sizeof(x))
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
using namespace std;
typedef long long ll;
typedef double db;
const double pai = acos(-1.0);
const double eps = 1e-8;
//const int mod=998244353;
const int mod=1e9+7;
const int inf=1e9+7;
//const ll inf=0x7f7f7f7f1234abcd;
const int maxn=1e6+10;
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
inline ll ksm(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x%mod;x=x*x%mod;y>>=1;}return res;}
inline ll inv(ll a,ll p){if(a==1)return 1;return (p-p/a)*inv(p%a,p)%p;}
inline ll lcm(ll a,ll b){return a * b / __gcd(a, b);}
//int t,n,m,k;
//ll a[maxn];
inline __int128 read()
{
    __int128 x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}

inline void write(__int128 x)
{
    if(x<0)
    {
        putchar('-');
        x=-x;
    }
    if(x>9)
        write(x/10);
    putchar(x%10+'0');
}
int a[maxn];
int main()
{
    ll n;
    scanf("%lld",&n);
    if(n==1) {puts("0");return 0;}
    ll ss=sqrt(n+10);
    int sum=0;
    for(int i=2;i<=ss;i++){
        int s=0;
        ll p=n/i;
        while(n%i==0){
            n/=i;
            s++;
        }
        for(int i=1;i<=s;i++) if(i<=s) sum++,s-=i;
    }
    if(n!=1) sum++;
    printf("%d\n",sum);
    return 0;
}


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

#define mkp make_pair
#define mkt make_tuple

int N,M,P,A,B;
int t[10];

vector<pair<int,double>> g[50];

const double INF=1e9;

double dijkstra(){
    double dist[M+1][(1<<N)];
    for(int i=1;i<=M;i++){
        for(int j=0;j<(1<<N);j++){
            dist[i][j]=INF;
        }
    }

    dist[A][(1<<N)-1]=0;
    priority_queue<tuple<double,int,int>> PQ;
    PQ.push(mkt(0,A,(1<<N)-1));
    while(!PQ.empty()){
        double cost;
        int v,state;

        auto f=PQ.top();
        cost=get<0>(f);
        v=get<1>(f);
        state=get<2>(f);
        PQ.pop();

        cost*=(-1);

        if(dist[v][state]<cost) continue;
        if(v==B) return cost;

        for(auto nex:g[v]){
            for(int i=0;i<N;i++){
                if(state&(1<<i)){
                    double neco=nex.second/t[i];
                    if(dist[nex.first][state^(1<<i)]>cost+neco){
                        dist[nex.first][state^(1<<i)]=cost+neco;
                        PQ.push(mkt(-dist[nex.first][state^(1<<i)],nex.first,state^(1<<i)));
                    }
                }
            }
        } 
    }

    return -1;
}

void solve(){
    for(int i=0;i<N;i++) cin>>t[i];
    for(int i=0;i<=M;i++) g[i].clear();

    for(int i=0;i<P;i++){
        int x,y;
        double z;
        cin>>x>>y>>z;
        g[x].push_back(mkp(y,z));
        g[y].push_back(mkp(x,z));
    }

    double res=dijkstra();
    if(res==-1) cout<<"Impossible"<<endl;
    else cout<<fixed<<setprecision(10)<<res<<endl;
}

int main(){
  while(1){
      cin>>N>>M>>P>>A>>B;
      if(N==0&&M==0&&P==0&&A==0&&B==0) break;
      solve();
  }

  return 0;
}



Measured memory_bytes: 4624
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
#define pb push_back
#define mp make_pair;
  
int main(){
	int n;
	cin>>n;
	
	string s;
	cin>>s;
	int ans=0;
	for(int i=0;i<n;i++){
		if(i+2<n && s[i]=='A' && s[i+1]=='B' && s[i+2]=='C'){
			ans++;
		}
	}

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


Measured memory_bytes: 256
from fractions import gcd

def factorization(n):
    pf_cnt = {}
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i == 0:
            cnt = 0
            while temp%i == 0:
                cnt += 1
                temp //= i
            pf_cnt[i] = cnt

    if temp != 1: pf_cnt[temp] = 1
    if not pf_cnt: pf_cnt[n] = 1
    return pf_cnt


def main():
    n = int(input())
    al = list(map(int, input().split()))

    gcd_l = [1]*n
    gcd_r = [1]*n

    gcd_l[0] = al[0]
    gcd_r[-1] = al[-1]

    for i in range(1,n):
        next_l = al[i]
        gcd_l[i] = gcd(next_l, gcd_l[i-1])

        next_r = al[n-i-1]
        gcd_r[n-i-1] = gcd(next_r, gcd_r[n-i])


    ans = max(gcd_r[1], gcd_l[n-2])
    for i in range(1,n-1):
        curr_gcd = gcd(gcd_l[i-1], gcd_r[i+1])
        ans = max(ans, curr_gcd)

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 89580
#include <stdio.h>
#include <math.h>
int main(void){
	int i,j,p[8],m[8][8],sum,ans,sss;
	m[0][0]=1;m[0][1]=2;m[0][2]=1;m[0][3]=2;m[0][4]=1;m[0][5]=4;m[0][6]=1;m[0][7]=4;
	for(i=0;i<8;i++){
		m[1][(i+6)%8]=m[0][i];
		m[2][(i+2)%8]=m[0][i];
		m[3][(i+4)%8]=m[0][i];
		m[4][(i+7)%8]=m[0][i];
		m[5][(i+5)%8]=m[0][i];
		m[6][(i+1)%8]=m[0][i];
		m[7][(i+3)%8]=m[0][i];
	}
	while(scanf("%d %d %d %d %d %d %d %d",&p[0],&p[1],&p[2],&p[3],&p[4],&p[5],&p[6],&p[7])!=EOF){
		sss=9999999;
		for(i=0;i<8;i++){
			sum=0;
			for(j=0;j<8;j++){if(p[j]-m[i][j]>0)sum+=p[j]-m[i][j];}
			if(sum<sss){ans=i;sss=sum;}
		}
		for(i=0;i<8;i++){
			printf("%d",m[ans][i]);
			if(i<7)printf(" "); else printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 604
#include <iostream>
   
   using namespace std;
     
    int main()
  {
 	int A,B;
 	cin>>A>>B;
 	if(A<=9 && B<=9)
 	{
 		cout<<A*B<<endl;
	 }
	 else
	 {
	 	cout<<-1<<endl;
	 }
      return 0;
 }

Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))
f=0
 
for i in range(N-1, 1, -1):
    if H[i]-H[i-1] ==-1:
        H[i-1]-=1
    elif H[i]-H[i-1]>=0:
        continue
    else:
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 63856
'use strict'

const main = input => {
	const args = input.trim().split(' ')
	const a = parseInt(args[0], 10)
	const b = parseInt(args[1], 10)
	const k = parseInt(args[2], 10)
	let t1 = Math.max(a, b)
	const t2 = []
	
	for (let i = 0; i < t1; i++) {
		if (a % (t1 - i) === 0 && b % (t1 - i) === 0) t2.push(t1 - i)
	}

	console.log(t2[k - 1])
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7372
def bubble_sort(A, N):
    sw = 0
    flag = True
    while flag:
        flag = False
        for j in reversed(range(1, N)):
            if  A[j - 1] > A[j]:
                A[j - 1],   A[j] = A[j], A[j - 1]
                sw += 1
                flag = True
    return sw

def main():
    N = int(input().rstrip())
    A = list(map(int, input().rstrip().split()))
     
    sw = bubble_sort(A, N)                            

    print(' '.join(map(str, A)))
    print(sw)

if __name__ == '__main__':
    main()

Measured memory_bytes: 7744
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <map>

using namespace std;

int main(void)
{
    long long n;
    cin >> n;
    map<long long, long long> mpodd;
    map<long long, long long> mpeven;
    map<long long, long long> mpmaxnum;

    for (int i = 1; i <= n; i++)
    {
        long long tmp;
        cin >> tmp;
        if (i % 2 == 1)
        {
            mpodd[tmp] += 1;
        }
        else
        {
            mpeven[tmp] += 1;
        }
    }

    long long countodd = 0;
    for (auto i : mpodd)
    {
        countodd = max(countodd, i.second);
    }
    for (auto i : mpodd)
    {
        if (i.second == countodd)
        {
            mpmaxnum[i.first] += 1;
            mpodd[i.first] = -100;
        }
    }

    long long counteven = 0;
    for (auto i : mpeven)
    {
        counteven = max(counteven, i.second);
    }
    for (auto i : mpeven)
    {
        if (i.second == counteven)
        {
            mpmaxnum[i.first] += 1;
            mpeven[i.first] = -100;
        }
    }

    long long maxnum = 0;
    if (mpmaxnum.size() >= 2)
    {
        cout << n - countodd - counteven << endl;
        return 0;
    }

    long long countodd2 = -1, counteven2 = -1;
    for (auto i : mpodd)
    {
        countodd2 = max(countodd2, i.second);
    }

    for (auto i : mpeven)
    {
        counteven2 = max(counteven2, i.second);
    }

    if (countodd2 == -1)
        countodd2 = 0;
    if (counteven2 == -1)
        counteven2 = 0;

    long long sum;
    sum = max(countodd + counteven2, countodd2 + counteven);
    cout << n - sum << endl;

    return 0;
}

Measured memory_bytes: 12800
let lcs x y =
  let m = String.length x in
  let n = String.length y in
  let dp = Array.make ((m+1)*(n+1)) 0 in
  let rec duduwa i j =
    if j > n then doit (i + 1)
    else begin
      dp.(i*(n+1)+j) <- if x.[i-1] = y.[j-1] then dp.((i-1)*(n+1)+j-1) + 1 else if dp.((i-1)*(n+1)+j) > dp.(i*(n+1)+j-1) then dp.((i-1)*(n+1)+j) else dp.(i*(n+1)+j-1);
      duduwa i (j + 1)
    end
  and doit i =
    if i > m then dp.(m*(n+1)+n)
    else duduwa i 1
  in
  doit 1

let () =
  let q = read_int () in
  let rec doit i =
    if i < q then begin
      let x = read_line () in
      let y = read_line () in
      Printf.printf "%d\n" (lcs x y);
      doit (i + 1)
    end
  in
  doit 0

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

#define REP(i, s, n) for (ll i = s; i < n; i++)
#define setarr(arr, v) for (ll i = 0; i < sizeof(arr)/sizeof(arr[0]); ++i) {arr[i] = v;}
#define pvar(x) cout << #x << " = " << x << endl;
#define mset(x, v) memset(x, v, sizeof(x));
#define fi first
#define se second
#define pb push_back
#define be() begin()
#define en() end()
#define len() length()
#define mp(x, y) make_pair(x, y)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<pll> vpll;
typedef set<ll> sll;
typedef queue<ll> qll;

template<class U, class V>
ostream& operator<<(ostream& os, const pair<U, V>& p) {os << "(" << p.first << ", " << p.second << ")";return os;}

template<class U, class V>
istream& operator>>(istream& in, pair<U, V>& p) {in >> p.first >> p.second;return in;}

namespace cp {
    template <typename T>
    T min (T first) {return first;}
    template <typename T, typename... Args>
    T min (T first, Args... args) {return std::min (first, min (args...));}

    template <typename T>
    T max (T first) {return first;}
    template <typename T, typename... Args>
    T max (T first, Args... args) {return std::max (first, max (args...));}
};

using cp::min;
using cp::max;

int main ()
{
    ll h, a; cin >> h >> a;
    cout << int (ceil (double(h)/a)) << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;

namespace AtCoder
{
	public class Program
	{
		static void Main()
		{
			int n = int.Parse(Console.ReadLine());
			var a = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();

			var dict = new Dictionary<long, int>();
			for (int i = 0; i < n; i++) {
				if (dict.ContainsKey(a[i])) {
					dict[a[i]]++;
				} else {
					dict[a[i]] = 1;
				}
			}

			var a2 = new List<long>(n);
			var a4 = new List<long>(n);
			foreach (var key in dict.Keys) {
				if (dict[key] >= 2) {
					a2.Add(key);
				}

				if (dict[key] >= 4) {
					a4.Add(key);
				}
			}

			var as2 = a2.OrderByDescending(x => x).ToArray();
			var as4 = a4.OrderByDescending(x => x).ToArray();

			long ans1 = 0;
			if (as2.Length >= 2) {
				ans1 = as2[0] * as2[1];
			}

			long ans2 = 0;
			if (as4.Length >= 1) {
				ans2 = as4[0] * as4[0];
			}

			long ans = Math.Max(ans1, ans2);
			Console.WriteLine(ans);
		}
	}
}


Measured memory_bytes: 30176
n = int(input())
s = input()

ans = s.count('R') * s.count('G') * s.count('B')
for i in range(n-2):
    for j in range(i+1,n-1):
        k = 2*j -i
        if k <= n-1:
            if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
                ans -= 1

print(ans)


Measured memory_bytes: 9112
N, M = map(int, input().split())
seta = set()
setb = set()
for i in range(M):
    a, b, =map(int, input().split())
    if a == 1: setb.add(b)
    if b == N: seta.add(a)
if len(seta&setb) == 0: print("IMPOSSIBLE")
else:   print("POSSIBLE")


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

char fnc(int x) {
  if(x<400) return 'a';
  else if(x<800) return 'b';
  else if(x<1200) return 'c';
  else if(x<1600) return 'd';
  else if(x<2000) return 'e';
  else if(x<2400) return 'f';
  else if(x<2800) return 'g';
  else if(x<3200) return 'h';
}

int main() {
  int n;
  cin >> n;
  set<char> ans;
  int cnt = 0;
  rep(i,n) {
    int m;
    cin >> m;
    if(m>=3200) {
      cnt++;
      continue;
    }
    ans.insert(fnc(m));
  }
  int mi;
  int p = ans.size();
  if(p==0) mi=1;
  else mi=p;
  cout << mi << " " <<  p+cnt << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int):
    c = 0
    i = 1
    ans = []
    while c <= N:
        c += i
        ans.append(i)
        i += 1
    
    t = c-N

    if c == N:
        print(ans)

    else:
        for i in ans:
            if i != t:
                print(i)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int A, P;
  while (cin >> A >> P) {
    P += A * 3;
    int res = P / 2;
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <functional>
#include <set>
#define DB cerr<<"D"<<endl
#define pb push_back
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";}
using P=pair<double,int>;
const ll M = 998244353;
void add(ll& x, ll y) {x+=y; x%=M;}
void chmax(ll& x, ll y) {if (x<y) x=y;}

int main() {
  int n[4]; for(int i=0;i<4;i++) cin>>n[i];
  sort(n,n+4);
  if (n[0]==1&&n[1]==4&&n[2]==7&&n[3]==9) {
    cout<<"YES"<<endl;
  } else {
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 256
def answer(n)
	return 0 if n < 0 or 36 < n
	n = 36 - n if 18 < n
	return [1, 4, 10, 20, 35, 56, 84, 120, 165, 220, 282,
		348, 415, 480, 540, 592, 633, 660, 670][n]
end

$<.each_line do |line|
	p answer(line.to_i)
end

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

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.rbegin(), t.rend());
  bool ok = s < t;
  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}


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

void f(int n, map<int, int>& M) {
  int x = 2;
  for (int x = 2; x * x <= n; x++) {
    while (n % x == 0) {
      n /= x;
      M[x]++;
    }
  }
  if (n != 1) M[n]++;
}

int main() {
  int N, NN = 1000000007;
  cin >> N;
  map<int, int> M;
  for (int n = 2; n <= N; n++) {
    f(n, M);
  }
  long ans = 1;
  for (auto m : M) {
    ans = ans * (m.second+1) % NN;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#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))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int n;
vector<int> a;
int main(void){
	cin >> n;
	rep(i, n){
		int b; cin >> b;
		a.pb(b);
	}
	sort(all(a));
	printf("%d\n", a.back() - a.front());
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7;
const int MAX = 1e6+10;
ll n;
ll dp[MAX][2][2];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    dp[2][1][1]=2;
    dp[2][0][1]=17;
    dp[2][1][0]=17;
    dp[2][0][0]=64;
    for(int i=3;i<=n;i++){
        dp[i][0][0]+=(dp[i-1][0][0]*8)%MOD;
        dp[i][0][0]%=MOD;
        dp[i][1][0]+=(dp[i-1][1][0]*9+dp[i-1][0][0])%MOD;
        dp[i][1][0]%=MOD;
        dp[i][0][1]+=(dp[i-1][0][0]+dp[i-1][0][1]*9)%MOD;
        dp[i][0][1]%=MOD;
        dp[i][1][1]+=(dp[i-1][1][1]*10+dp[i-1][1][0]+dp[i-1][0][1])%MOD;
        dp[i][1][1]%=MOD;
    }
    cout<<dp[n][1][1]%MOD<<endl;
    return ~~(0^0);
}


Measured memory_bytes: 34780
#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using namespace std;
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
#define rreps(i, n) for(int i=((int)(n)); i>0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pl(s) cout << (s) << "\n";
#define pls(...) {bool space = false; for(auto i : __VA_ARGS__) (cout << (space?" ":"") << i), space = true; cout << "\n";}
#define plexit(s) {cout << (s) << "\n"; exit(0);}
#define yes(s) cout << ((s)?"Yes":"No") << "\n";
#ifdef __LOCAL
#include <dump.hpp>
#define dump(...) DUMPOUT << "  " << string(#__VA_ARGS__) << ": " << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl << "    ", dump_func(__VA_ARGS__)
#else
#define dump(...)
#endif
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
struct IOInit { IOInit() { cin.tie(nullptr); ios::sync_with_stdio(false); dump("READY"); /*cout << unitbuf;*/} } IO_INIT;
using ll = long long; using ull = unsigned long long; using ld = long double;
template<typename T = int> using V = vector<T>; template<typename T = int> using P = pair<T, T>;
using Vi = V<int>; using Vl = V<ll>; using Vd = V<ld>; using VVi = V<Vi>; using VVl = V<Vl>; using Pi = P<int>; using Pl = P<ll>; using Pd = P<ld>;
constexpr ll MOD = 1000000007; constexpr int INF = (1 << 30) - 1; constexpr ll INFL = 1LL << 60; constexpr ld EPS = 1e-12; constexpr ld PI = 3.141592653589793238462643383279;

using T = int;
T op(T a, T b) { return max(a, b); }
T e() { return 0; }

signed main(void) {
  const int MAX_A = 300005;
  int n, k; cin >> n >> k;
  segtree<T, op, e> seg(MAX_A);
  rep(i,n) {
    int a; cin >> a;
    int l = a - k, r = a + k + 1;
    l = max(l, 0);
    r = min(r, MAX_A);
    int now = seg.prod(l,r) + 1;
    seg.set(a, now);
  }
  pl(seg.prod(0, MAX_A))
  return 0;
}


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

const int maxn = 1e5;

int memo[maxn][2];

int n;
string s;

int dp(int pos,int prev){
    if(pos==n){
        return 0;
    }
    if(memo[pos][prev]!=-1) return memo[pos][prev];
    int ans=0;
    if(s[pos]-'0'==prev){
        ans=1+dp(pos+1,!prev);
    }
    else{
        ans=dp(pos+1,s[pos]-'0');
    }
    return memo[pos][prev]=ans;
}

int main(){

   
    cin>>s;
    n=s.size();
    memset(memo,-1,sizeof(memo));
    cout<<min(dp(0,1),dp(0,0));
    return 0;
}

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

long long gcd(long long A, long long B) {
    if (A < B) {
        swap(A, B);
    }
    if (A % B == 0) {
        return B;
    } else {
        return gcd(B, A % B);
    }
}
long long lcm(long long A, long long B) {
    return A * B / gcd(A, B);
}
long long ans(long long N, long long A, long long B) {
    return N - ((N / A) + (N / B) - (N / lcm(A, B)));
}

int main() {
    long long A, B, C, D;
    cin >> A >> B >> C >> D;
    cout << ans(B, C, D) - ans(A - 1, C, D) << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int N;
long long int A[100005];

int main(void){

	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
	}

	long long int ans = 0;

	for (int i = 1; i <= N - 1; i++) {
		ans += A[i] / 2;
		if (A[i] % 2 == 1 && A[i+1] !=0) { A[i + 1]--; ans++; }
	}

	ans += A[N] / 2;

	cout << ans << endl;

	//system("pause");
	return 0;
}

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

typedef long long LL;

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

    if(n < 1200){
        cout <<"ABC";
    }
    else if(n >= 1200 && n < 2800){
        cout <<"ARC";
    }
    else cout << "AGC";
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#define mod (int)(1e9 + 7)
#define pb push_back
#define ll long long int
#define int long long
using namespace std;
typedef pair<int,int> pii;

int dp[111111][22];

signed main(){

  string s;
  cin>>s;
  
  dp[0][0]=1;


  for(int i=0;i<s.size();i++){
    char c=s[i];
    if(c=='?'){
      for(int k=0;k<10;k++){
        for(int j=0;j<13;j++){
          dp[i+1][(k+j*10)%13]+=dp[i][j];
          dp[i+1][(k+j*10)%13]%=mod;
        }
      }
      
    }
    else{
      int k=c-'0';
      for(int j=0;j<13;j++){
        dp[i+1][(k+10*j)%13]+=dp[i][j];
        dp[i+1][(k+10*j)%13]%=mod;
      }
    }
  }
  
  cout<<dp[s.size()][5]<<endl;
  
  return 0;
}



Measured memory_bytes: 18944
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int n,k,sum=0;
	int a[51];
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a+1,a+n+1);
	for(int i=n;i>=n-k+1;i--)
	{
		sum+=a[i];
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
int n,a,b,i,k;
char s;
double c,d,e;
scanf("%d\n",&n);
for(i=0;i<n;i++){
scanf("%c",&s);
a=s-'0';
if(a==0){
scanf("%c",&s);
a=s-'0';
}
else{
scanf("%c",&s);
b=s-'0';
a=10+b;
}
scanf(":%c",&s);
b=s-'0';
if(b==0){
scanf("%c\n",&s);
b=s-'0';
}
else{
scanf("%c\n",&s);
k=s-'0';
b=10*b+k;
}
c=30*a+0.5*b;
d=6*b;
if(c>d){
e=c-d;
}
else{
e=d-c;
}
if(e>180){
e=360-e;
}
if(e>=0 && e<30){
printf("alert\n");
}
else if(e>=90 && e<=180){
printf("safe\n");
}
else{
printf("warning\n");
}
}
return 0;
}


Measured memory_bytes: 1984
character(3) S
read*,S
if(S=="SUN")print"(i0)",7
if(S=="MON")print"(i0)",6
if(S=="TUE")print"(i0)",5
if(S=="WED")print"(i0)",4
if(S=="THU")print"(i0)",3
if(S=="FRI")print"(i0)",2
if(S=="SAT")print"(i0)",1
end

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<=n;++i)
int rest=1000000007;
long kaijo(int a){
  long ans;
  ans=a;
  if(a==0) return 1;
  else{
  for(int i=1;i<a;i++){
    ans=ans*i;
    ans=ans%rest;
  }
  }
  return ans;
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int main(){
  int x,y;
  cin>>x>>y;
  int dist=x+y;
  int ans=0;
  int a,b;
  a=(2*x-y)/3;
  b=(2*y-x)/3;
  ans=kaijo(a+b)*modinv(kaijo(a),rest)%rest;
  ans=ans*modinv(kaijo(b),rest)%rest;
  if(a<0||b<0)ans=0;
  if(dist%3!=0)ans=0;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1e9+7;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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

struct BinaryIndexedTree{
    private:
    vector<int> dat;
    public:
    BinaryIndexedTree(int n_){
        dat.resize(++n_,0);
    }
    void add(int a,int w){
        for (int i=a;i<=dat.size();i+=i&-i) dat[i]+=w;
    }
    int sum(int a){
        int res=0;
        for (int i=a;i>0;i-=i&-i) res+=dat[i];
        return res;
    }
    int binarysearch(int w){
        if (w<=0) return 0;
        int x=0,n=dat.size();
        for (int k=n;k>0;k/=2){
            if (x+k<=n&&dat[x+k]<w){
                w-=dat[x+k];
                x+=k;
            }
        }
        return x;
    }
};

int main(){
    ll N,K;
    cin >> N >> K;
    vector<ll> a(N);
    rep(i,N){
        cin >> a[i];
        a[i]-=K;
    }
    vector<ll> sum(N+1);
    sum[0]=0;
    rep(i,N) sum[i+1]=sum[i]+a[i];
    vector<ll> compress=sum;
    sort(compress.begin(),compress.end());
    compress.erase(unique(compress.begin(),compress.end()),compress.end());
    rep(i,N+1) sum[i]=lower_bound(compress.begin(),compress.end(),sum[i])-compress.begin()+1;
    ll s=compress.size();
    BinaryIndexedTree BIT(++s);
    ll ans=0;
    rep(i,N+1){
        ans+=BIT.sum(sum[i]);
        BIT.add(sum[i],1);
    }
    cout << ans << endl;
}

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

void cout_vector(vector<int> a) {
  int a_size = (int)a.size();
  for (int i = 0; i < a_size; i++) {
    cout << a.at(i);
    if (i < a_size - 1) {
      cout << " ";
    }
  }
  cout << endl;
}

// 配列の対象のインデックス番号 (>=1) の値 x について、
// より若いインデックス番号の値 y と比較する。
//
// x < y を満たす場合、y の値をインデックス番号 +1 にコピーする。
// これを繰り返して、値を右に移動していくイメージ。
//
// インデックス番号 0 に到達する or x > y を満たす場合、
// その時点で左に自分自身 x より低い値がないため、移動を止めて、そこに x をセットする
//
// 例: [1, 3, 4, 2] という配列の場合
//
// step1: 1, 3, 4, 2 // 何もしない
// step2: 1, 3, 4, 4 // 2 < 4 のため、4 を右に代入して移動
// step3: 1, 3, 3, 4 // 2 < 3 のため、3 を右に代入して移動
// step4: 1, 2, 3, 4 // 2 > 1 のため、代入して移動はやらない
//                   // 代わりに移動して空いた穴に 2 をセットする
//
vector<int> insertion_sort(vector<int> a, int n) {
  // i = 1
  //   A[1]の2をA[0]の5と比較する
  //     A[1] < A[0] のため、A[1] = A[0] (2)
  //   A[0]に元のA[1]の値を代入する
  // i = 2
  //   A[2]の4をA[1]の5と比較する
  //     A[2] < A[1] のため、A[2] = A[1] (5)
  //   A[1]の5をA[0]の2と比較する
  //     A[1] > A[0] のため、代入はしない
  //   A[1]に元のA[2]の値を代入する
  for (int i = 1; i < n; i++) {
    int v = a.at(i);
    int j = i - 1;
    while (j >= 0 && a.at(j) > v) {
      a.at(j + 1) = a.at(j);
      j--;
    }
    a.at(j + 1) = v;

    cout_vector(a);
  }

  return a;
}

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

  cout_vector(a);
  vector<int> sorted = insertion_sort(a, n);
  return 0;
}



Measured memory_bytes: 3116
while True:
    inputs = input().split()
    a = int(inputs[0])
    op = inputs[1]
    b = int(inputs[2])

    if op is "?":
        break
    elif op is "+":
        print(a+b)
    elif op is "-":
        print(a-b)
    elif op is "*":
        print(a*b)
    else:
        print(a//b)

Measured memory_bytes: 7608
#2-2-3-1
S = input()
T = input()
S_rev = list(S[::-1])
T_rev = list(T[::-1])

def check(i,S,T):
    for k in range(len(T)):
        if (S[i+k] == "?" or S[i+k] == T[k]):
            continue
        else:
            return False
    for k in range(len(T)):
        S[i+k] = T[k]
    for j in range(len(S)):
        if S[j] == "?":
            S[j] = "a"
    return S[::-1]

count = 0
for i in range(len(S_rev) - len(T_rev) +1):
    a = check(i,S_rev,T_rev)
    if a:
        a = "".join(a)
        print(a)
        count = 1
        break

if count == 0:
    print("UNRESTORABLE")
        



Measured memory_bytes: 3064
import java.util.Scanner;
import java.util.Arrays;
public class Main {
    public static void main(String[] args){
        try(Scanner sc = new Scanner(System.in)){
            String[] nm = sc.nextLine().split(" ");
            int n = Integer.parseInt(nm[0]);
            int m = Integer.parseInt(nm[1]);
            
            String[] xlist = sc.nextLine().split(" ");
            int[] xary = new int[m];
            for(int i=0;i<m;i++){
                xary[i] = Integer.parseInt(xlist[i]);
            }
            Arrays.sort(xary);
            
            int[] lenary = new int[m-1];
            for(int i=0; i<m - 1; i++){
                lenary[i] = xary[i+1] - xary[i];
            }
            Arrays.sort(lenary);
            
            int result = 0;
            for(int i = 0; i < m-n; i++){
                result += lenary[i];
            }
            System.out.println(result);

		}
    }
}

Measured memory_bytes: 47092
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
int main()
{
    int a[4];
    std::cin>>a[1]>>a[2]>>a[3];
    
    std::sort(a+1,a+4);
    
    int gg=a[3]-a[2];
    gg+=(a[2]-a[1])/2;
    if((a[2]-a[1])%2)gg+=2;
    std::cout<<gg<<std::endl;
}

Measured memory_bytes: 256
/*
 * Author : Andrew J
*/
#include <bits/stdc++.h>
using namespace std;
#define rall(x) x.rbegin() , x.rend()
#define all(x) x.begin() , x.end()
#define fi first
#define se second
#define pb push_back
using ll = long long;
using ii = pair <int , int>;
void in(int &x);
const int N = 2e5 + 10;
#define singleCase
// #define multipleCase
int n,a,b,c,d;
char s[N];

void work() {
   scanf("%d%d%d%d%d" , &n , &a , &b , &c , &d);
   scanf("%s" , s + 1);
   bool pos = 1;
   for (int i = a ; i < c ; i++) {
      if (s[i] == '#' && s[i + 1] == '#') {
         pos = 0;
      }
   }
   for (int i = b ; i < d ; i++) {
      if (s[i] == '#' && s[i + 1] == '#') {
         pos = 0;
      }
   }
   if (!pos) {
      puts("No");
      return;
   }
   if (d > c) {
      puts("Yes");
   } else if (d < c) {
      pos = 0;
      for (int i = b ; i <= d ; i++) {
         if (i == d) {
            if (i + 1 > n) continue;
         }
         if (s[i - 1] == '.' && s[i + 1] == '.' && s[i] == '.') {
            pos = 1;
         }
      }
      puts(pos ? "Yes" : "No");
   } else {
      assert(0);
   }
   return;
}

int main() {
   #ifdef multipleCase
      int nQ; in(nQ);
      while (nQ--)
         work();
   #endif
   #ifdef singleCase
      work();
   #endif
   return 0;
}

void in(int &x) {
	bool neg = false;
	register int c;
	x = 0;
	c = getchar();
	if(c == '-') {
		neg = true;
		c = getchar();
	}
	for (; c > 47 && c < 58; c = getchar())
	  x = (x << 1) + (x << 3) + c - 48;
	if (neg) x *= -1;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.setf(ios::fixed); cout.precision(20);
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int n;
    cin >> n;
    string s;
    cin >> s;
    int c1 = 0, c2 = 0;
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'R') ++c1;
        else ++c2;
    }
    if (c1 > c2) {
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }
}

Measured memory_bytes: 256
n, m, q = gets.split.map!(&:to_i)

data = Array.new(q) { gets.split.map!(&:to_i) }

point = [*1..m].repeated_combination(n).map do |ary|
  ary.unshift(nil)
  data.sum { |a,b,c,d| ary[b] - ary[a] == c ? d : 0 }
end.max

puts point

load __FILE__ unless $stdin.eof?


Measured memory_bytes: 16804
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<(v)<<"\n";
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl "\n"
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;


signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> A(N,0);
    for(ll i=0;i<N;++i)cin>>A[i];
    ll ans=0;
    for(ll i=0;i<N;++i){
        while(A[i]%2==0){
            A[i]/=2;ans++;
        }
    }

    prt(ans)

    return 0;
}


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

int main(){
    long n,q,l,now,d,m,a,ans;
    string s;
    cin >> n;
    cin >> s;
    cin >> q;
    vector<int> k(q, 0);
    for (int i = 0;i<q;i++){
        cin >> k[i];
    }
    for (int qq = 0; qq < q;qq++){
        l=0;
        now=0;
        d=0;
        m=0;
        a=0;
        ans=0;
        vector<int> d_l, m_l;
        for (int i = 0; i < n;i++){
            char j = s[i];
            if (j == 'D')
            {
                d += 1;
                l += 1;
                d_l.push_back(i);
                m_l.push_back(0);
            }
            else if(j=='C'){
                ans += a;
            }
            if(l>now){
                if(j=='M'){
                    m += 1;
                    a+=d;
                    m_l[l - 1] += 1;
                }
                if(d_l[now]==i-k[qq]+1){
                    d -= 1;
                    a -= m;
                    m -= m_l[now];
                    now += 1;
                }
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 14536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

void solve(istream& cin, ostream& cout) {
  string s;
  cin >> s;
  vector<string> w = {"Sunny", "Cloudy", "Rainy"};
  REP(i, 3) {
    if (s == w[i]) {
      cout << w[(i + 1) % 3] << endl;
      return;
    }
  }
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif


Measured memory_bytes: 256
def main():
    N,K,Q = map(int,input().split())
    A = [int(input()) for _ in range(Q)]
    Ans = ["Yes"]*N
    scores = [K]*N
    for a in A:
        scores[a-1] += 1 
    for i in range(N):
        if scores[i] <= Q:
            Ans[i] = "No"
    print(*Ans,sep = "\n")
    return
main()

Measured memory_bytes: 12792