akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define MOD 1000000007
#define MAX 1000005
#define loop(i,a,b) for(long long int i=a;i<b;i++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
typedef long long int ll;

using namespace std;
//using namespace boost::multiprecision;

ll prime[MAX];

void sieve()
{
	for(ll i=2;i*i<MAX;i++)
	{
		if(prime[i]==0)
		for(ll j=i;j<MAX;j+=i)
		prime[j] = i;
	}
	prime[1] = 1;
}

ll modular_expo(ll x,ll n)
{
	ll ans = 1;
	while(n)
	{
		if(n&1)
		ans = (ans * x)%MOD;
		x = (x*x)%MOD;
		n = n>>1;
	}
	return ans%MOD;
}

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

//sieve();

ll k,n;
  cin>>k>>n;
  ll a[n];
  loop(i,0,n)
    cin>>a[i];
  ll ma = 0;
  loop(i,0,n)
  {
    ma = max(ma,min(abs(a[i]-a[(i+1)%n]),abs(k - (a[i]-a[(i+1)%n]))));
             }
             cout<<k-ma<<"\n";



return 0;
}


Measured memory_bytes: 1792
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("trapv")
#pragma GCC target("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define deb(x) cout << #x << " is " << x << "\n"
#define int long long
#define mod 1000000007LL
#define PI acosl(-1)

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve()
{
	int n, ans = 0;
	string s;
	cin >> n >> s;
	for (int i = 0; i < n; i++)
	{
		if (s[i] == 'R')
			ans++;
	}
	int temp = ans;
	for (int i = 0; i < temp; i++)
	{
		if (s[i] == 'R')
			ans--;
	}
	cout << ans;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt", "r", stdin);
	// 	freopen("output.txt", "w", stdout);
	// #endif
	solve();
	return 0;
}

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

int main(void)
{
	int m,n=0;
	int a,b,c,d;
	int sum;
	int tmp[4];
	int ans[4];
	
	while(++n)
	{
		sum = 0;
		scanf("%d",&m);
		if(m==0)break;
		if(n!=1)printf("\n");

		scanf("%d %d %d %d",&a,&b,&c,&d);
		
		sum += a*10+b*50+c*100+d*500;
		
		tmp[3] = (sum-m)/500;
		tmp[2] = (sum-m-tmp[3]*500)/100;
		tmp[1] = (sum-m-tmp[3]*500-tmp[2]*100)/50;
		tmp[0] = (sum-m-tmp[3]*500-tmp[2]*100-tmp[1]*50)/10;

		ans[0] = a - tmp[0];
		ans[1] = b - tmp[1];
		ans[2] = c - tmp[2];
		ans[3] = d - tmp[3];
		
			if(ans[0]>0){
			printf("10 %d\n",ans[0]);}
			if(ans[1]>0){
			printf("50 %d\n",ans[1]);}
			if(ans[2]>0){
			printf("100 %d\n",ans[2]);}
			if(ans[3]>0){
			printf("500 %d\n",ans[3]);}
	}
	return 0;
}
											

Measured memory_bytes: 0
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

vector<pair<int,int>> v[1010];
int cntx[1010],cnty[1010],n,k,ans,vx[100010],vy[100010],t[100010];

void solve(int tip)
{
    int sol=0;
    for(int i=1;i<=k;i++)
    {
        v[i].clear();
        cntx[i]=0;cnty[i]=0;
    }
    for(int i=1;i<=n;i++)
    {
        int a=vx[i]/k,b=vy[i]/k,p=0;
        int d1=(a+1)*k-vx[i],d2=(b+1)*k-vy[i];
        if(a%2==0 && b%2==0) {if(t[i]==tip) {sol++;p=1;}}
        else if(a%2==1 && b%2==1) {if(t[i]==tip) {sol++;p=1;}}
        else if(t[i]==1-tip) {sol++;p=1;}
        if(p==1) {cntx[d1]--;cnty[d2]--;v[d1].push_back({d2,2});}
        else {cntx[d1]++;cnty[d2]++;v[d1].push_back({d2,-2});}
    }
    for(int i=0;i<k;i++)
    {
        sol+=cntx[i];
        for(int j=0;j<v[i].size();j++) cnty[v[i][j].first]+=v[i][j].second;
        for(int j=0;j<k;j++)
        {
            sol+=cnty[j];
            ans=max(ans,sol);
        }
        for(int j=0;j<k;j++) sol-=cnty[j];
    }
}

int main()
{
    //freopen("file.in","r",stdin);
    //freopen("file.out","w",stdout);
    char c;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d %c\n",&vx[i],&vy[i],&c);
        if(c=='W') t[i]=0;
        else t[i]=1;
    }
    solve(0);
    solve(1);
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 2688
#include<stdio.h>
#include<math.h>
int isprime(int);
int main() {
	int A,i, n ,count = 0;
	scanf("%d", &n);
	for ( i = 0; i < n; i++)
	{
		scanf("%d", &A);
		count += isprime(A);
	}
	printf("%d", count);
	printf("\n");
	return 0;
}
int isprime(int x) {
	int i = 3;
	if (x % 2 == 0) {
		if (x == 2) {
			return 1;
		}
		return 0;
	}
	while (i <= sqrt(x))
	{
		if (x%i == 0)
		{
			return 0;
		}
		i += 2;
	}
	return 1;
}


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

int main()
{

    int X, Y;
    cin >> X >> Y;

    int sum;
    int flag = 0;

    for (int t = 0; t <= X; t++)
    {
        sum = t * 2 + (X - t) * 4;
        if (sum == Y)
        {
            cout << "Yes";
            flag = 1;
        }
    }
    if (flag == 0)
    {
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 3636
while True:
    n,L=raw_input().split()
    if n==L=="0":break
    S=set()
    dic={}
    i=0
    while n not in dic:
        dic[n]=i
        n="0"*(int(L)-len(n))+n
        a="".join(sorted(n,reverse=True))
        b="".join(sorted(n))
        n=str(int(a)-int(b))
        i+=1
    print dic[n],n,i-dic[n]

Measured memory_bytes: 4240
#include <bits/stdc++.h>
using namespace std;
const int maxn=500005;
int n,dp[maxn],pre;
char s[maxn];
int main()
{
    scanf("%d%s",&n,s+1);
    for (int i=2;i<n;++i) {
        dp[i+1]=dp[i];
        if (s[i]=='0'&&s[i-1]=='1'&&s[i+1]=='1') {
            pre=i+1;
            for (int j=i-1;j>=1&&s[j]=='1';--j)
                dp[i+1]=max(dp[i+1],dp[j-1]+i-j);
        }
        if (s[i+1]=='0')
            pre=0;
        if (pre)
            dp[i+1]=max(dp[i+1],dp[pre-3]+i-pre+2);
    }
    printf("%d\n",dp[n]);
    return 0;
}


Measured memory_bytes: 2688
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;


namespace StartFinish
{
    class Program
    {

        static double Average(double[] data)
        {
            double sum = 0;
            for(int i = 0; i < data.Length; i++)
            {
                sum += data[i];
            }
            return sum / data.Length;
        }

        static void Main(string[] args)
        {
            while (true)
            {
                double n = double.Parse(Console.ReadLine());
                if (n == 0)
                {
                    break;
                }
                double[] data = Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
                double bunnsann = 0;
                double average = Program.Average(data);
                for(int i = 0; i < n; i++)
                {
                    bunnsann+=(data[i]-average)*(data[i]-average);
                }
                Console.WriteLine(Math.Sqrt(bunnsann/data.Length));
            }
        }
    }
}

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

int main() {
  vector<int> a(3);
  for(int i=0; i<3; i++){
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  if (a.at(2) == a.at(1) + a.at(0)) {
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int in(){int a;cin>>a;return a;}
int main()
{
    int t=in();
    while(t--)
    {
        int a=in(),b=in(),c=in();
        if(a<b+c)
        {
            cout<<"No\n";
            return 0;
        }
        if(a%2!=(b+c)%2)
        {
            cout<<"No\n";
            return 0;
        }
    }
    cout<<"Yes\n";
    return 0;
}

Measured memory_bytes: 256
from itertools import permutations

a1, a2, a3 = map(int, input().split())
ans = 1e9
for a in permutations([a1, a2, a3]):
    tmp = abs(a[0] - a[1]) + abs(a[1] - a[2])
    ans = min(ans, tmp)
print(ans)


Measured memory_bytes: 3188
#coding:utf-8
n = int(input())
Q = [1]
M = [[False for i in range(n)] for j in range(n)]
dataList = []
for i in range(n):
    data = list(map(int,input().split()))
    dataList.append(data)
    for j in range(data[1]):
        v = data[j+2] - 1
        M[i][v] = True
color = ["white" for i in range(n)]
d = [-1 for i in range(n)]
d[0] = 0
while Q != []:
    u = Q.pop(0) - 1
    color[u] = "gray"
    data = dataList[u]
    for i in range(data[1]):
        v = data[i+2] - 1
        if M[u][v] == True and color[v] == "white":
            color[v] = "gray"
            d[v] = d[u] + 1
            Q.append(v+1)
    color[u] = "black"

for i,j in enumerate(d,1):
    print(i,j)
    


Measured memory_bytes: 5736
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define lamsort(v,p) sort(v.begin(),v.end(),[](p a, p b){return a.num < b.num;});
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
const long long INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s,t; cin >> s >> t;
    int n = (int)s.size(), m = (int)t.size();
    vector<vector<int>> is(26);
    rep(i,n) is[s[i]-'a'].push_back(i);
    rep(i,n) is[s[i]-'a'].push_back(i+n);
    ll ans = 0;
    int p = 0;
    rep(i,m) {
        int c = t[i]-'a';
        if((int)is[c].size()==0) {
            cout << -1 << endl;
            return 0;
        }
        p = *lower_bound(is[c].begin(), is[c].end(), p) + 1;
        if(p >= n) {
            p -= n;
            ans += n;
        }
    }ans += p;
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[1010][1010], b[1010][1010];
bool l[1010][1010];
int main(){
    int n;
    while(cin>>n){
        ll ans=0;
        for(int i=1; i<=n; ++i){
            for(int j=0; j<n-1; ++j){
                scanf("%d",&a[i][j]);
                b[i][a[i][j]]=j;
            }
            l[i][a[i][0]]=1;
        }
        vector<pair<pair<int,int>,pair<int,int>>> s, st;
        for(int i=1; i<=n; ++i){
            if(l[a[i][0]][i]&&a[i][0]>i){
                s.push_back(mk(mk(a[i][0], 0), mk(i, 0)));
            }
        }
        pair<int, int> tmp;
        while(s.size()>0){
            ++ans;
            for(auto it:s){
//                cout<<it.fs.fs<<" "<<it.fs.sc<<" "<<it.sc.fs<<" "<<it.sc.sc<<endl;
                tmp=it.fs;
                if(tmp.sc+1<n-1){
                    l[tmp.fs][a[tmp.fs][tmp.sc+1]]=1;
                    if(l[a[tmp.fs][tmp.sc+1]][tmp.fs]){
                        st.push_back(mk(mk(tmp.fs, tmp.sc+1), mk(a[tmp.fs][tmp.sc+1], b[a[tmp.fs][tmp.sc+1]][tmp.fs])));
                    }
                }
                tmp=it.sc;
                if(tmp.sc+1<n-1){
                    l[tmp.fs][a[tmp.fs][tmp.sc+1]]=1;
                    if(l[a[tmp.fs][tmp.sc+1]][tmp.fs]){
                        st.push_back(mk(mk(tmp.fs, tmp.sc+1), mk(a[tmp.fs][tmp.sc+1], b[a[tmp.fs][tmp.sc+1]][tmp.fs])));
                    }
                }
//                cout<<"&"<<endl;
            }
            s.clear();
            s=st;
            st.clear();
        }
        bool f=1;
        for(int i=1; i<=n; ++i){
            for(int j=0; j<n-1; ++j){
                if(!l[i][a[i][j]]){
                    f=0;
                }
            }
        }
        if(f)
            cout<<ans<<endl;
        else
            cout<<-1<<endl;
    }
  return 0;
}




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

using namespace std;

int main()
{
	int i, j, n, m;
	//int ok = 1;
	char a[50][51];
	char b[50][51];
	
	cin >> n;
	cin >> m;
	for (i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (j = 0; j < m; j++) {
		cin >> b[j];
	}
	for (i = 0; i <= n - m; i++) {
		for (j = 0; j <= n - m; j++) {
			int ok = 1;
			for (int k = 0; k < m; k++) {
				string stra(a[i + k] + j, a[i + k] + j + m);
				string strb(b[k]);
				if (stra != strb) {
					ok = 0;
					break;
				}
			}
			if (ok == 1) {
				cout << "Yes" << endl;
				return (0);
			}
		}
	}
	cout << "No" << endl;
	return (0);
}


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

using namespace std;

typedef long long I64;

const int NMAX = 100;

string a,p,rez;
vector<string> meh;

int main() {
    cin >> a >> p;
    int N = a.size();
    int M = p.size();
    for( int i = 0;  i + M - 1 < a.size();  ++i ) {
        rez = a;
        for( int j = 0;  j < a.size();  ++j ) {
            if ( i <= j && j < i + M ) {
                rez[j] = p[j - i];
            }
        }
        bool ok = 1;
        for( int j = 0;  j < a.size();  ++j ) {
            if( rez[j] != a[j] && a[j] != '?' ) ok = 0;
            if(rez[j] =='?')
                rez[j] = 'a';
        }
        if(ok)
            meh.push_back(rez);
    }
    sort(meh.begin(), meh.end());
    if( meh.size() < 1 )
        cout << "UNRESTORABLE\n";
    else cout << meh[0] << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9 + 7;

vector<long long> fact, fact_inv, inv;

template< typename T >
void init_combi(size_t size, const T mod) {
    size += 1;
    fact.resize(size);
    fact_inv.resize(size);
    inv.resize(size);
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 1; i < size-1; i++) {
        fact[i+1] = fact[i] * (i + 1) % mod;
        inv[i+1] = mod - inv[mod % (i+1)] * (mod / (i+1)) % mod;
        fact_inv[i+1] = fact_inv[i] * inv[i+1] % mod;
    }
}

template< typename T >
T mod_combi(T n, T k, T mod) {
    // return kCn % mod
    return fact[n] * (fact_inv[k] * fact_inv[n - k] % mod) % mod;
}

int main() {
    int X, Y;
    cin >> X >> Y;
    if ((X + Y) % 3 != 0) {
        cout << 0 << endl;
        return 0;
    }
    // X = a + 2b
    // Y = 2a + b
    // A = a + b = (X + Y) / 3
    int A = (X + Y) / 3;
    // B = a - b = (Y - X)
    int B = Y - X;
    if ((A + B) % 2 != 0) {
        cout << 0 << endl;
        return 0;
    }
    ll a = (A + B) / 2;
    if ((A - B) % 2 != 0) {
        cout << 0 << endl;
        return 0;
    }
    ll b = (A - B) / 2;
    if (a < 0 || b < 0) {
        cout << 0 << endl;
        return 0;
    }
    init_combi((size_t)a+b, MOD);
    cout << mod_combi(a+b, a, MOD) << endl;
}


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

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

using ll = long long;
using namespace std;

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

    s = "0" + s;
    reverse(s.begin(), s.end());
    auto len = s.length();

    int answer = 0;
    rep (len, i) {
      switch (s[i]) {
        case '0': answer += 0; break;
        case '1': answer += 1; break;
        case '2': answer += 2; break;
        case '3': answer += 3; break;
        case '4': answer += 4; break;
        case '5': answer += 5; if (s[i+1] >= '5') s[i+1] += 1; break;
        case '6': answer += 4; s[i+1] += 1; break;
        case '7': answer += 3; s[i+1] += 1; break;
        case '8': answer += 2; s[i+1] += 1; break;
        case '9': answer += 1; s[i+1] += 1; break;
        default:  answer += 0; s[i+1] += 1; break;
      }
    }

    cout << answer << endl;
}


Measured memory_bytes: 2308
# -*- coding utf-8 -*-
from collections import defaultdict
MOD = 10 ** 9 + 7

N = int(input())

ans = 0
sdic = defaultdict(int)
for i in range(N):
    s = input()
    s = str(sorted(s))
    sdic[s] += 1

for s in sdic:
    ans += sdic[s] * (sdic[s] - 1) // 2

print(ans)


Measured memory_bytes: 22372
#include <bits/stdc++.h>
#include <iostream>
#include<map>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a + b > c + d) cout << "Left" << endl;
    else if (a + b == c + d) cout << "Balanced" << endl;
    else cout << "Right" << endl;
    return 0;
}



Measured memory_bytes: 256
# 乗法のmod逆元（mod-2乗）
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

# nCr mod m
# modinvが必要
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n-i) * modinv(i+1, mod) % mod
    return res

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

n, a, b = map(int, input().split())
mod = 10**9+7

ans = ((2**n - 1) % mod) - (combination(n, a) % mod) - (combination(n, b) % mod)
print(ans % mod)


Measured memory_bytes: 281244
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007
#define INF 1000000000
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

// まずは全探索，次にDP
// 偶奇，逆から，ソート，出現回数，出現位置，DP
// 余事象，包除
// データ構造
// 問題の特徴量
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 小数のときは，精度の設定する．
int main() {
cin.tie(0);
ios::sync_with_stdio(false);

string S; cin >> S;
vector<bool> cnt(26, false);


if (S.size() == 26){
    if (S == "zyxwvutsrqponmlkjihgfedcba"){ cout << "-1\n"; return 0;}
    string s = S;
    next_permutation(ALL(S));
    rep(i, 0, 26){
        cout << S[i];
        if (s[i] != S[i]) break;
    }
    cout << "\n"; 
} 
else {
    for (char c:S) cnt[c-'a'] = true;
    rep(i, 0, 26){
        if (cnt[i] == false){
            S += (char)(i + 'a');
            break;
        }
    }
    cout << S << "\n";
}

}

// 境界，出力文字列 チェック



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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)


int main(void){

	char c; cin >> c;
	cout << (char)(c + 1) << endl;


	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF 100000000
#define EPS 1e-10
#define MOD 1000000007
#define MAX_V 100000
#define MAX_LOG_V 20
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> PP;

vector<int> G[MAX_V];
int root;

int parent[MAX_LOG_V][MAX_V];
int depth[MAX_V];

void dfs(int v, int p, int d){
	parent[0][v] = p;
	depth[v] = d;
	for(int i = 0; i < G[v].size(); i++){
		if(G[v][i] != p) dfs(G[v][i], v, d+1);
	}
}

void init(int V){
	dfs(root, -1, 0);
	for(int k = 0; k+1 < MAX_LOG_V; k++){
		for(int v = 0; v < V; v++){
			if(parent[k][v] < 0) parent[k+1][v] = -1;
			else parent[k+1][v] = parent[k][parent[k][v]];
		}
	}
}

int lca(int u, int v){
	if(depth[u] > depth[v]) swap(u,v);
	for(int k = 0; k < MAX_LOG_V; k++){
		if((depth[v]-depth[u]) >> k & 1){
			v = parent[k][v];
		}
	}
	if(u == v) return u;
	for(int k = MAX_LOG_V - 1; k >= 0; k--){
		if(parent[k][u] != parent[k][v]){
			u = parent[k][u];
			v = parent[k][v];
		}
	}
	return parent[0][u];
}

int n;
vector<P> vec;
int par[100000];
int pri[100000];
int ppri[100000];
vector<int> ve[100000];

int main(){
	cin >> n;
	par[0] = 0;
	for(int i = 1; i < n; i++){
		int tmp; cin >> tmp;
		tmp--;
		par[i] = tmp;
		G[tmp].push_back(i);
		G[i].push_back(tmp);
	}
	init(n);
	rep(i,n) ve[depth[i]].push_back(i);
	pri[0] = 0;
	ppri[0] = 0;
	int cnt = 1;
	for(int i = 1; i < 100000; i++){
		if(ve[i].size() == 0) break;
		vec.clear();
		rep(j,ve[i].size()){
			vec.push_back(P(ppri[par[ve[i][j]]],ve[i][j]));
		}
		sort(vec.begin(),vec.end());
		rep(j,vec.size()){
			pri[cnt] = vec[j].second;
			ppri[vec[j].second] = cnt;
			cnt++;
		}
	}
	
	long long sum = 0;
	for(int i = 1; i < n; i++){
		int t1 = pri[i-1], t2 = pri[i];
		int pa = lca(t1,t2);
		sum += depth[t1]-depth[pa]+depth[t2]-depth[pa];
	}
	cout << sum << endl;
}

Measured memory_bytes: 26200
str1 = input()
lst1 = str1.split()
x = int(lst1[0])
n = int(lst1[1])

string = input()
list = string.split()
p = []
for num in list:
    p.append(int(num))

for i in range(100):
    if (x - i) not in p:
        print(x - i)
        break
    elif (x + i) not in p:
        print(x + i)
        break
    else:
        continue

Measured memory_bytes: 61948
using System;

namespace Csharp_practice{
    class Program{
        static void Main(string[] args){
            string hoge = Console.ReadLine();
            if (hoge[0] == hoge[1] && hoge[2] == hoge[3] ||
                hoge[0] == hoge[2] && hoge[1] == hoge[3] ||
                hoge[0] == hoge[3] && hoge[2] == hoge[1] ){
                if (hoge[0] == hoge[1] && hoge[1] == hoge[2]) {
                    Console.WriteLine("No");
                }
                else
                {
                    Console.WriteLine("Yes");
                }
            }
            else
            {
                Console.WriteLine("No");
            }

        }

        
    }
}


Measured memory_bytes: 11092
S = input()
L = len(S)

cur = 0
P = [0]*6
def expr():
    global cur
    op = "+"
    while 1:
        term(op)
        if cur == L:
            break
        op = S[cur]
        cur += 1 # "+"/"-"

def num():
    global cur
    v = 0
    while cur < L and S[cur] in "0123456789":
        v = 10*v + int(S[cur])
        cur += 1
    return v

def term(op):
    global cur
    k = 1
    if S[cur] != 'x':
        k = num()
    d = 0
    if cur < L and S[cur] == "x":
        cur += 1 # "x"
        d = 1
        if cur < L and S[cur] == '^':
            cur += 1 # "^"
            d = num()
    P[d] = k if op == '+' else -k
expr()

def f(P, x):
    res = 0
    for i in range(6):
        res += P[i]*(x**i)
    return res

d = 5
while P[d] == 0:
    d -= 1

R = []
for x in range(2000, -2001, -1):
    if f(P, x) == 0:
        R.append(x)

print("".join("(x%+d)" % -x for x in R))



Measured memory_bytes: 5612
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repA(i,a,b) for(int i=a;i<=b;i++)
#define repD(i,b,a) for(int i=b;i>=a;i--)
#define mset(a,val) memset(a,val,sizeof(a))
#define f first
#define s second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main()
{
    ll n;
    cin>>n;
    ll a[n];
    rep(i,0,n)
    cin>>a[i];
    sort(a,a+n,greater<ll>());
    ll res=0;
    ll cnt=0;
    int j=1;
    if(n==1)
    {
        cout<<0<<endl;
        return 0;
    }
    res+=a[0];
    rep(i,2,n)
    {
        res+=a[j];
        cnt++;
        if(cnt==2)
        {
            cnt=0;
            j++;
        }

    }
    cout<<res<<endl;
}


Measured memory_bytes: 5164
#include <stdio.h>
int A[2000],n,flag;
int solve(int p,int t){
  int ans1,ans2;
  if (p<=n){
      solve(p+1,t-A[p]);
      solve(p+1,t);
  } else {
    if(t==0){
      flag=1;
    }
  }
}

int main(){
  int q,M[2000],i;
  scanf("%d",&n);
  for (i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for (i=0;i<q;i++){
    scanf("%d",&M[i]);
  }
  for (i=0;i<q;i++){
    flag=0;
    solve(0,M[i]);
    if(flag==1){
      printf("yes\n");
    } else {
      printf("no\n");
    }
  }
  return 0;
}

Measured memory_bytes: 588
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



struct A{
	A(ll arg_value){

		value = arg_value;
	}
	bool operator<(const struct A &arg) const{

		return value < arg.value; //降順(PQ)
	}

	ll value;
};

struct B{
	B(ll arg_value){

		value = arg_value;
	}
	bool operator<(const struct B &arg) const{

		return value > arg.value; //降順(PQ)
	}

	ll value;
};



int main(){

	int num_query;
	scanf("%d",&num_query);

	priority_queue<A> L;
	priority_queue<B> R;

	int command;
	ll a,b;

	ll add = 0;
	ll sum_L = 0,sum_R = 0;



	for(int loop = 0; loop < num_query; loop++){

		scanf("%d",&command);

		if(command == 1){

			scanf("%lld %lld",&a,&b);

			add += b;

			if(L.size() > R.size()){

				ll tmp = L.top().value;
				if(a >= tmp){ //なるべく均衡させるのでaをRに入れる

					R.push(B(a));
					sum_R += a;

				}else{ //tmpをRに入れて、aをLに入れる

					L.pop();
					sum_L -= tmp;
					L.push(A(a));
					sum_L += a;
					R.push(B(tmp));
					sum_R += tmp;
				}

			}else{ //L.size() <= R.size()

				if(L.empty()){

					L.push(A(a));
					sum_L += a;

				}else{

					ll tmp = R.top().value;

					if(a <= tmp){ //なるべく均衡させるのでLにaを入れる

						L.push(A(a));
						sum_L += a;

					}else{ //tmpをLに移し、aをRに入れる

						R.pop();
						sum_R -= tmp;
						R.push(B(a));
						sum_R += a;
						L.push(A(tmp));
						sum_L += tmp;
					}
				}
			}

		}else{

			//xを直線状の点と見た時、各拠点からの距離の総和を取る
			ll x = L.top().value;
			ll num = (x*L.size()-sum_L)+(sum_R-x*R.size())+add;

			printf("%lld %lld\n",x,num);
		}
	}

	return 0;
}


Measured memory_bytes: 3828
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program 
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            var a = cin.ReadInt;
            var b = cin.ReadInt;

            var repeatedA = string.Concat(Enumerable.Repeat(a.ToString(), b).ToArray());
            var repeatedB = string.Concat(Enumerable.Repeat(b.ToString(), a).ToArray());

            if (a<b) WriteLine(repeatedA);
            else WriteLine(repeatedB);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}

Measured memory_bytes: 11348
#include<bits/stdc++.h>
using namespace std;
#define int int64_t
#define MOD 1000000007
int f(const vector<int>& xs) {
  int n=xs.size(),sum=0;
  for(int k=1;k<=n;++k){
    sum+=(k-1)*xs[k-1]-(n-k)*xs[k-1];
    sum%=MOD;
  }
  return sum;
}
main(){
  int n,m;
  cin>>n>>m;
  vector<int> xs(n);
  for(auto&x:xs)cin>>x;
  vector<int> ys(m);
  for(auto&y:ys)cin>>y;
  int sum=f(xs)*f(ys)%MOD;
  cout<<sum<<endl;
}


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

vector<long long> X;

class union_find {
public:
    union_find(int n): par(vector<int>(n, -1)), ec(vector<int>(n, 0)), components(n) {
        W.resize(n);
        for(int i=0; i<n; ++i) W[i] = X[i];
    }

    bool unite(int x, int y) {
        if((x = find(x)) == (y = find(y))) {
            return false;
        } else {
            if(par[x] < par[y]) swap(x, y);
            par[y] += par[x];
            par[x] = y;
            W[y] += W[x];
            ec[y] += ec[x];
            --components;
            return true;
        }
    }

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

    int size(int x) {
        return -par[find(x)];
    }

    long long weight(int x) {
        return W[find(x)];
    }

    void addedge(int x) {
        ec[find(x)] += 1;
    }

    int edgenum(int x) {
        x = find(x);
        int ret = ec[x];
        ec[x] = 0;
        return ret;
    }

    int cnt() {
        return components;
    }

private:
    vector<int> par, ec;
    vector<long long> W;
    int components;
};

int main() {
    int N, M; cin >> N >> M;
    X.resize(N);
    for(int i=0; i<N; ++i) cin >> X[i];
    vector<int> A(M), B(M);
    vector<long long> Y(M);
    for(int j=0; j<M; ++j) {
        cin >> A[j] >> B[j] >> Y[j];
        --A[j]; --B[j];
    }

    vector<int> order;
    for(int j=0; j<M; ++j) order.push_back(j);
    sort(begin(order), end(order), [&](int a, int b){return Y[a] < Y[b];});

    int ans = 0;
    union_find uf(N);
    for(int i : order) {
        uf.unite(A[i], B[i]);
        uf.addedge(A[i]);
        if(Y[i] <= uf.weight(A[i])) ans += uf.edgenum(A[i]);
    }
    cout << M - ans << endl;
}

Measured memory_bytes: 4728
#include <stdio.h>

int main(){
	int n,a[10];
	int b[10],c[10];
	int bn=0,cn=0;
	int i,j;
	int ans;

	scanf("%d",&n);
	//printf("n:%d\n",n);
	for(i=0; i<n; i++){
		//printf("i:%d\n",i);
		for(j=0; j<10; j++)scanf("%d",&a[j]);
		ans=0;
		cn=0;
		bn=0;
		for(j=0; j<10; j++)b[j]=0;
		for(j=0; j<10; j++){
			if(bn==0){
				b[bn]=a[j];
				bn++;
			}
			else{
				if(b[bn-1]<a[j]){
					b[bn]=a[j];
					bn++;
				}else if(cn==0){
					c[cn]=a[j];
					cn++;
				}else if(c[cn-1]<a[j]){
					c[cn]=a[j];
					cn++;
				}else{
					//printf("j:%d\n",j);
					break;
				}
			}
			if(j==9)ans=1;
		}
		if(ans)printf("YES\n");
		else printf("NO\n");
	}

	return 0;
}

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

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

    vector<double> p(N);
    vector<vector<double>> dp(N+1, vector<double>(N+1, 0));

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

    dp[0][0] = 1;
    for(int i=1; i<N+1; i++){
        for(int j=0; j<N+1; j++){
            
            dp[i][j] += dp[i-1][j]*(1-p[i-1]);
            dp[i][j+1] += dp[i-1][j]*p[i-1];
 
        }
    }
/*
    for(int i=0; i<N+1; i++){
        for(int j=0; j<N+1; j++){
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }
*/
    double ans=0;
    for(int j=N/2+1; j<N+1; j++){
        ans+=dp[N][j];
    }

    printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 73688
s = input()
t = input()
ans = 'UNRESTORABLE'
for i in range(len(s)-len(t), -1, -1):
    valid = True
    for j in range(len(t)):
        if s[i+j] != '?' and s[i+j] != t[j]:
            break
    else:
        ans = (s[:i] + t + s[i+len(t):]).replace('?', 'a')
        break
print(ans)

Measured memory_bytes: 3064
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	
	x := make([]int,n)
	
	for i,_ := range x {
		fmt.Scan(&x[i])
	}
	
	sort.Ints(x)
	

	minSums := 1000000
	for p := x[0]; p <= x[n-1]; p++ {
		sums := 0
		for i := 0; i < n; i++ {
			sums += square(x[i] - p)
		}
		if minSums > sums {
			minSums = sums
		}
	}
	fmt.Println(minSums)	
}

func square(x int) int {
	return x * x
}

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

int N;
char buf[114514];
map<char, int> cnt;

int main() {
  scanf("%s", buf);
  N = strlen(buf);
  bool second = true;
  for (int i=0; i<N-2; i+=2) {
    second &= buf[i] == buf[i+2];
  }

  for (int i=1; i<N-2; i+=2) {
    second &= buf[i] == buf[i+2];
  }

  if (second) {
    puts("Second");
    return 0;
  }

  for (int i=0; i<N; i++) {
    cnt[buf[i]]++;
  }

  char ok = 0;
  for (auto &itr : cnt) {
    if (itr.first == buf[0]) continue; 
    if (itr.first == buf[N-1]) continue; 
    if (itr.second == 1) ok = itr.first;
  }

  if (buf[0] != buf[N-1] && cnt.size() == 3 && ok) {
    for (int i=0; i<N; i++) {
      if (buf[i] == ok) {
        if (buf[i-1] != buf[i+1]) {
          puts("First");
          return 0;
        } else {
          puts("Second");
          return 0;
        }
      }
    }
  }

  if ((buf[0] == buf[N-1]) ^ N%2) puts("First");
  else puts("Second");
}


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

typedef long long ll;

#define F first 
#define S second 
#define PB push_back
#define MP make_pair 
#define rep(i,a,b) for (ll i=a;i<b;i++)

typedef vector<int> vi;
typedef pair<int,int> pi;

ll lcm(ll a,ll b)
{
    return (a*b)/__gcd(a,b); 
}

int main()
{
    ll a,b;
    cin>>a>>b;

    cout<<lcm(a,b)<<endl; 

    return 0; 
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	long long n, q, s, t;
	cin >> n >> q >> s >> t;
	long long pl = 0;
	long long mi = 0;
	vector<long long> a(n+1);
	vector<long long> d(n);
	for (int i = 0; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		d[i] = a[i + 1] - a[i];
	}
	for (int i = 0; i < n; i++) {
		if (d[i] >= 0) {
			pl += d[i];
		}
		else {
			mi -= d[i];
		}
	}
	vector<long long> ans(q);
	for (int i = 0; i < q; i++) {
		int l, r, x;
		cin >> l >> r >> x;
		l--;
		if (d[l] >= 0) {
			pl -= d[l];
		}
		else {
			mi += d[l];
		}
		d[l] += x;
		if (d[l] >= 0) {
			pl += d[l];
		}
		else {
			mi -= d[l];
		}
		if (r < n) {
			l = r;
			if (d[l] >= 0) {
				pl -= d[l];
			}
			else {
				mi += d[l];
			}
			d[l] -= x;
			if (d[l] >= 0) {
				pl += d[l];
			}
			else {
				mi -= d[l];
			}
		}
		ans[i]=mi * t - pl * s;
	}
	for (int i = 0; i < q; i++) {
		cout << ans[i] << endl;
	}
}



Measured memory_bytes: 7600
#include<iostream>
using namespace std;
#define ll long long int
int main()
{
    int t;
    //cin>>t;
    //while(t--)
    //{
    ll a,b,i,j,mx=0,cn=0;
    string s,ss;
    cin>>s;
    for(auto i:s)
    {
        if(i=='R')cn++;
        else mx=max(cn,mx),cn=0;
    }
    if(cn>0)mx=max(cn,mx);
    cout<<mx<<endl;
    // }
    return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef vector<int> vi;
typedef vector<pair<int,int> > vii;
#define pb push_back
#define INF 1e5
#define REP(i,a,b) for(int i=a;i<b;++i)
#define REPN(i,a,b) for(int i=a;i<=b;++i)

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);   
   
       int h,n;
       cin>>h>>n;
       ll A[n],sum=0;
       REP(i,0,n) cin>>A[i],sum+=A[i];
       if(sum>=h) cout<<"Yes"<<"\n";
       else cout<<"No"<<"\n";
       
       
       
	return 0;
    
}

Measured memory_bytes: 1024
# AGC014B - Unplanned Queries
from collections import Counter


def main():
    # all vertices need to appear even times in A
    *A, = map(int, open(0).read().split())
    T = Counter(A[2:]).values()
    flg = any(i % 2 for i in T)
    print("NO" if flg else "YES")


if __name__ == "__main__":
    main()

Measured memory_bytes: 25972
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<string>
using namespace std;
typedef long long lng;
#define UP(i,a,b) for(int i=(a); i<=(b); ++i)
#define DOWN(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) UP(i,0,(n)-1)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) //NOTE: <a> must be sorted in advance

lng power(lng b, int n) {lng sol=1; while(n>0) {if(n&1) {sol=sol*b;} n>>=1; b*= b;} return sol;} //calculate b^n in O(log(n)) time

const int MOD = 1000000007; //10^9+7
const double PI = 3.1415926535897932384626;

/*********** variables ************/
string S, T;
/**********************************/


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> S >> T;
    int len = (int)S.size();
    if(S == T) {
        cout << "Yes" << endl;
        return 0;
    }
    REP(i, len) {
        S = S[len-1] + S.substr(0, len-1);
        if(S == T) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


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

bool check(char word, char mid, char l, char r){
	if(word == 'o' && mid == 'S'){
		return (l == r);
	}else if(word == 'o' && mid == 'W'){
		return !(l == r);
	}else if(word == 'x' && mid == 'S'){
		return !(l == r);
	}else if(word == 'x' && mid == 'W'){
		return (l == r);

	}
}

int main(void){
	int n,i,r,l,k;
	string s;
	bool flag=false;
	char c[100100],ani[2]={'W','S'};
	cin >> n;
	cin >> s;
	for(k=0; k<4; k++){
		c[0] = ani[k/2];
		c[1] = ani[k%2];
		for(i=2; i<n; i++){
			if(s[i-1] == 'o' && c[i-1] == 'S'){
				c[i] = (c[i-2]=='S')?'S':'W';
			}else if(s[i-1] == 'o' && c[i-1] == 'W'){
				c[i] = (c[i-2]=='S')?'W':'S';
			}else if(s[i-1] == 'x' && c[i-1] == 'S'){
				c[i] = (c[i-2]=='S')?'W':'S';
			}else if(s[i-1] == 'x' && c[i-1] == 'W'){
				c[i] = (c[i-2]=='S')?'S':'W';
			}
		}
		if(check(s[0],c[0],c[n-1],c[1]) && check(s[n-1],c[n-1],c[n-2],c[0])){
			flag = true;
			break;
		}
	}
	if(flag){
		for(i=0; i<n; i++){
			cout << c[i];
		}
		cout << endl;
	}else{
		cout << "-1" << endl;
	}
	return 0;
}


Measured memory_bytes: 640
S=input()
a=int(S[:2])#前半
b=int(S[2:4])
cYYMM=b>0 and b<13
cMMYY=a>0 and a<13
#print(a,b)
#print(["NO","YES"][1-cond])
print([["NA","YYMM"],["MMYY","AMBIGUOUS"]][cMMYY][cYYMM])



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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

int A[300];

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

    std::string S;
    std::cin >> S;

    for(char c : S){
        ++A[c - 'a'];
    }

    int mn = *min_element(A, A+3),
        mx = *max_element(A, A+3);
    if(mx - mn <= 1){
        std::cout << "YES" << std::endl;
    }else{
        std::cout << "NO" << std::endl;
    }
}


Measured memory_bytes: 512
#include<stdio.h>

int distanceMeasurement(int x, int y);

int main( void ){
  int a,b,c,d,e,k;
  int distance[11];
  int i;
  int flag;
  const int true=1;
  const int false=0;

  scanf("%d", &a);
  scanf("%d", &b);
  scanf("%d", &c);
  scanf("%d", &d);
  scanf("%d", &e);
  scanf("%d", &k);

  flag = true;
  distance[0] = distanceMeasurement(a, b);
  distance[1] = distanceMeasurement(a, c);
  distance[2] = distanceMeasurement(a, d);
  distance[3] = distanceMeasurement(a, e);
  distance[4] = distanceMeasurement(b, c);
  distance[5] = distanceMeasurement(b, d);
  distance[6] = distanceMeasurement(b, e);
  distance[7] = distanceMeasurement(c, d);
  distance[8] = distanceMeasurement(c, e);
  distance[9] = distanceMeasurement(d, e);

  for(i=0;i<10;i++){
    if(distance[i]>k){
      flag = false;
    }
  }
  if(flag==false){
    printf(":(\n");
  }else{
    printf("Yay!\n");
  }
  return 0;
}

int distanceMeasurement(int x, int y){
  int r = 0;

  r = y - x;
  return r;
}


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

int main() {
	string s,t;
	int f=0;
	cin>>s>>t;
	for(ll i=0;s[i]!='\0';i++)
	{
	    if(s[i]!=t[i])
	    f=1;
	}
	if(f==1)
	cout<<"No";
	else
	cout<<"Yes";
	return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cassert>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <fstream>
#include <cmath>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define ITER(c) __typeof((c).begin())
#define PB(e) push_back(e)
#define FOREACH(i, c) for(ITER(c) i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define PARITY(n) ((n) & 1)



const int h = 4;
const int w = 8;
typedef vector<int> vec;
typedef vector<vec> mat;

bool done(const mat &board){
  REP(i, h)REP(j, w - 1){
    if(board[i][j] != i * 10 + j + 1) return false;
  }
  return true;
}


int main(){
  int T;
  cin >> T;
  
  while(T--){
    mat board(h, vec(w, 0));
    
    REP(i, h)REP2(j, 1, w){
      cin >> board[i][j];
      board[i][j] -= 10;
      int &b = board[i][j];
      if(b % 10 == 1) swap(board[b / 10][0], b);
    }

    int ans = -1;
    set<mat> memo;
    queue<pair<int, mat> > que;
    memo.insert(board);
    que.push(MP(0, board));
    
    while(!que.empty()){
      int d = que.front().first;
      mat board = que.front().second;
      que.pop();

      if(done(board)){
        ans = d;
        break;
      }
      
      REP(r, h)REP2(c, 1, w){
        int b = board[r][c-1];
        if(board[r][c] == 0 && b > 0 && b % 10 < 7){
          int n = b + 1;
          REP(i, h)REP2(j, 1, w){
            if(board[i][j] == n){
              swap(board[i][j], board[r][c]);
              if(memo.count(board) == 0){
                memo.insert(board);
                que.push(MP(d + 1, board));
              }
              swap(board[i][j], board[r][c]);
            }
          }
        }
      }
    }
    cout << ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 24828
#include<bits/stdc++.h>
// #include <boost/lexical_cast.hpp>
using namespace std;


#define ll long long int
#define vll vector<ll>
#define vllv vector<vector<ll>> 
#define sz size()
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

ll ceil1(ll n,ll m){if(n%m==0){return n/m;}return n/m +1;}
vll factor(ll n){
    vll ans;
    if(n>0)ans.pb(1);if(n==2)ans.pb(2);
    for(ll i=2;i*i<=n;i++){if(n%i==0){ans.pb(i);if(n/i!=i)ans.pb(n/i);}}if(n>2)ans.pb(n);
    return ans;
}
ll fact(ll n){
	
    ll res = 1; 
    for (ll i = 2; i <= n; i++) 
        res = res * i; 
    return res; 
} 
  
int nCr(ll n, ll r) 
{ 
    return fact(n) / (fact(r) * fact(n - r)); 
} 
  
void dfs(vllv &v,ll k,vll &par,vll &dis,ll p)
{
 
    par[k]=p;
    dis[k]=dis[p]+1;
    for(ll i=0;i<v[k].sz;i++){
        if(v[k][i]!=p){
            dfs(v,v[k][i],par,dis,k);
        }
    }
}
bool sortbysec(const pair<string,int> &a,const pair<string,int> &b){return (a.second<b.second);} 


ll ston(string s) 
{ 
    stringstream geek(s); 
    ll x = 0; 
    geek >> x; 
    
  
    return x; 
}
ll pow2(ll n,ll k){ll ans=1;
    while(k>0){
        if(k%2==1)ans=ans*n;n=n*n;k/=2;
    }return ans;}
bool prime(int n){
    int i,j;
    for(i=2;i<=sqrt(n);i++){
        if(n%i==0){
            return false;
        }
    }
    return true;
}
bool bserch(vector<string> a, string s){
	
	ll l=0,r=a.sz-1,mid;
	while(l<=r){
		mid=(l+r)/2;
		if(a[mid]==s)return true;
		if(a[mid]<s){
			l=mid+1;
		}else{
			r=mid-1;
		}
	}
	return false;
}

bool sortcol( const vector<int>& v1, 
               const vector<int>& v2 ) { 
 return v1[0] < v2[0]; 
} 

 ll degit(ll n)
 {
 	ll t=0;
 	while(n>0)
 	{
 		t++;
 		n/=10; 	}
 		return t;
 }

void solve()
{
	ll n;
	cin>>n;
	ll ans=degit(n);
	
	
		for(ll i=1;i*i<=n;i++)
		{
			if(n%i==0)
			{
				ans=min(ans,(degit(i),degit(n/i)));
				// return;
			}
		}
		cout<<ans;
	
	// ;
	
	return;
}

int main()
{
	fast;
    ll q;
    q=1;
    // cin>>q;
    while(q--)
    {
        solve();
    }
    return 0;
}

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

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define INF 1e9

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int n;
	cin >> n;
	int ans = 0;
	if (n % 10 != 0) {
		string a = to_string(n);
		rep(i, 0, a.size()) {
			string b;
			b = a[i];
			ans += stoi(b);
		}
	}
	else {
		ans = 10;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MAX=1e5+4;
LL a[MAX];
LL root[MAX];




int main(){
        int n;
        cin>>n;
        int cnt=0;
        while(n>0)
        {
               int x=n%10;
                if(x==2) cnt++;
                n/=10;
        }
        cout<<cnt<<endl;
}

Measured memory_bytes: 256
lst = []
while True:
    a = list(map(int, input().split()))
    if a[0] == a[1] == 0:
        break
    else:
        lst.append(a)
for nx in lst:
    con = 0
    for i in range(1, nx[0]-1):
        for j in range(i+1, nx[0]):
            for k in range(j+1, nx[0]+1):
                if i + j + k == nx[1]:
                    con += 1
    print(con)


Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  string s,t,u;
  int a,b;
  cin>>s>>t>>a>>b>>u;
  if(s==u) a--;
  else b--;
  cout<<a<<" "<<b;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <chrono>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <unordered_set>
#include <vector>
#include <queue>
#include <math.h>
#include <unordered_map>
#include <fstream>
#include <functional>
#include <map>
#include <deque>
#include <string.h>
#include <set>

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? (-a) : (a))
#define YesNo(flag) ((flag) ? "Yes\n" : "No\n")
#define YESNO(flag) ((flag) ? "YES\n" : "NO\n")

constexpr auto NMAX = (int)2e3 + 20;
constexpr auto INF_ULL = 18446744073709551615;
constexpr auto INF_INT = 2147483647;
constexpr auto PI = 3.14159265359;
constexpr auto MOD = 1000000007;

using namespace std;

typedef unsigned long long ull;

int n, k;
vector<int> v;

int main()
{
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		int aux;
		cin >> aux;
		v.push_back(aux);
	}

	sort(v.begin(), v.end());
	int ans = 0;
	for (int i = 0; i < k; i++) {
		ans += v[i];
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3628