akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

int main(){
    int N,Q;
    string S;
    vector<set<int>> pls;
    cin>>N>>S>>Q;

    pls.assign(26,set<int>({INF}));
    rep(i,N) pls[S[i]-'a'].insert(i);

    while(Q--){
        int type;
        cin>>type;
        if(type==1){
            int ind;
            char nc;
            cin>>ind>>nc;
            ind--;
            auto pc=S[ind];
            S[ind]=nc;
            pls[pc-'a'].erase(ind);
            pls[nc-'a'].insert(ind);
        }
        else{
            int l,r;
            cin>>l>>r;
            l--;
            int res=0;
            for(int c=0;c<26;c++){
                if(pls[c].empty()) continue;
                int lid=*pls[c].lower_bound(l);
                int rid=*pls[c].lower_bound(r);
                if(rid>lid) res++;
            }

            cout<<res<<endl;
        }
    }
}

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

int main() {
  char s;
  cin >> s;
  if (s == 'a' || s == 'i' || s == 'u' || s == 'e' || s == 'o') {
    cout << "vowel" << endl;
  } else {
    cout << "consonant" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	nums := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&nums[i])
	}
	sort.Sort(sort.Reverse(sort.IntSlice(nums)))

	mothics := make([]int, 0)
	for _, num := range nums {
		if len(mothics) == 0 {
			mothics = append(mothics, num)
		} else if mochi := mothics[len(mothics)-1]; mochi > num {
			mothics = append(mothics, num)
		}
	}
	fmt.Println(len(mothics))
}


Measured memory_bytes: 512
# -*- coding: utf-8 -*-

def main():
    n = int(input())
    w = []
    for i in range(n):
        w.append(input())

    for i in range(n):
        for j in range(i + 1, n):
            if w[i] == w[j]:
                print("No")
                exit()

    for i in range(n - 1):
        if w[i][-1] != w[i + 1][0]:
            print("No")
            exit()

    print("Yes")

if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
def main():
  for _ in range(M):
      l,r,d = map(int,input().split())
      pl = find(l)
      pr = find(r)
      if pl==pr and x[r]-x[l]!=d:
          print('No')
          exit()
      else:
          p[pr] = pl
          x[pr] = x[l]+d-x[r]

def find(i):
    if p[i]==i:
        return i
    p[i],x[i] = find(p[i]),x[i]+x[p[i]]
    return p[i]


if __name__=="__main__":
    N, M = map(int, input().split())
    p = list(range(N + 1))
    x = [0] * (N + 1)
    main()
    print('Yes')

Measured memory_bytes: 10100
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
#define N 510000
#define md 1000000007
using namespace std;
ll ex[N],cnt,size,l[N],r[N],n,m,tmp,i,dp[N],q[N],head,tail,j,sum;
struct node 
{ll v,x;}a[N];
bool cmp(node x,node y)
{return x.x<y.x;}
void init()
{
	sort(ex+1,ex+1+cnt);//按速度排 
	size=unique(ex+1,ex+1+cnt)-ex-1;//去重，得到速度种类数 
	for (ll i=1;i<=n;i++)
	 l[i]=upper_bound(ex+1,ex+1+size,l[i])-ex-1,
	 //二分查找l[i]，将速度区间改为速度排名 
	 r[i]=upper_bound(ex+1,ex+1+size,r[i])-ex-1;
}
int main()
{
	scanf("%lld",&n);
	for (i=1;i<=n;i++)
	   scanf("%lld %lld",&a[i].x,&a[i].v);
	sort(a+1,a+1+n,cmp);
	for (i=1;i<=n;i++)
	 tmp=max(tmp,a[i].v),r[i]=tmp;
	tmp=100000000000ll;
	for (i=n;i>=1;i--) 
	  tmp=min(tmp,a[i].v),l[i]=tmp;
	for (i=1;i<=n;i++)
	 ex[++cnt]=a[i].v;//导出速度 
	init();
	dp[0]=1;
	n++;
	l[n]=r[n]=n;
	q[++tail]=0;
	sum=1;
	for (i=1;i<=n;i++) 
	{   //sum维护当前前缀和，
	    //-dp[q[head+1]]表示出队（从前缀和中去掉它） 
		while (head!=tail&&r[q[head+1]]<l[i]-1)
		sum=(sum-dp[q[head+1]]+md)%md,head++;//+md防负 
		dp[i]=sum;
		sum=(sum+dp[i])%md;
		//队列中加上dp[i]（实际上是前面队列的和） 
		q[++tail]=i;
	}
	printf("%lld\n",dp[n]%md);
}

Measured memory_bytes: 24960
#include <stdio.h>

int main(){
   int H, W, iH, iW;
   char symbol;
   while(scanf("%d %d\n",&H,&W)==2){
      if(H==0&&W==0) break;
      for(iH=0;iH<H;iH++){
         for(iW=0;iW<W;iW++){
            if(iH%2==iW%2) symbol='#';
            else symbol='.';
            printf("%c",symbol);
         }
         printf("\n");
      }
      printf("\n");
   }
   return 0;
}

Measured memory_bytes: 576
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)     for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = m; i <= (int)(n); i++)
#define Graph vector<vector<int>>
#define MOD 1000000007 
#define PMAX 1000000 

typedef pair<int, int> PII;
typedef long long ll;


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

  vector<int> A(N+1);
  vector<bool> Boxin(N+1,false);
  A[0] = 0;
  rep(i,N) {
    cin >> A[i+1];
  }

  int ansM = 0;
  for(int i = N; i > 0;i--){
    int j = 1;
    int trueCnt = 0;
    while(j*i <= N){
      if(Boxin[j*i] == true) trueCnt++;
      j++;
    }
    
    int bCnt = trueCnt;
    if(A[i] != (bCnt % 2)){
      Boxin[i] = true;
      ansM++;
    }
  }
  
  cout << ansM << endl;
  rep(i,N){
    if(Boxin[i+1] == true) cout << i+1 << " ";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 1792
import math
from collections import Counter
N = int(input())

def factorize(n):
  cnt = Counter()

  for i in range(2, int(math.sqrt(n)) + 2):
    while n % i == 0:
      cnt[i] += 1
      n //= i

  if n > 1:
    cnt[n] += 1

  return cnt

cnts = []
for i in range(1, N+1):
  cnts.append(factorize(i))

base = Counter()
for c in cnts:
  for (key, value) in c.items():
    base[key] += value

ans = 1
for (key, value) in base.items():
  ans *= (1 + value)

mod = 10 ** 9 + 7
print(ans % mod)

Measured memory_bytes: 3692
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

int main() {
  string S;
  cin >> S;
  if (S[2]==S[3] && S[4]==S[5]) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
}


Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ALL(T) T.begin(), T.end()

using namespace std;

typedef pair<int, int> pii;
typedef unsigned long long ull;

const int L = -(int)1e6;

int main(void){
    for(int n, res, sum; cin >> n, n; cout << res << endl){
        sum = 0; res = L;
        while(n --){
            int a; cin >> a;

            sum += a;
            if(sum < 0){
                sum = 0;
                if(res < a) res = a;
            }
            else if(res < sum) res = sum;
        }
    }

    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N,M;
  cin >> N >> M;
  vector<int> a(M),b(M);
  vector<bitset<12>> c(M);
  for(int i=0;i<M;i++){
    cin >> a.at(i) >> b.at(i);
    for(int j=0;j<b.at(i);j++){
      int tmp;
      cin >> tmp;
      c.at(i).set(tmp-1);
    }
  }

  vector<int> dp((1<<N),1e9);
  for(int bit=0;bit<(1<<N);bit++){
    bitset<12> S(bit);
    for(int i=0;i<M;i++){
      if((S&c.at(i))==S)  dp.at(bit)=min(dp.at(bit),a.at(i));
    }
  }
  for(int bit=0;bit<(1<<N);bit++){
    for(int g=bit;g>0;g=(g-1)&bit){
      dp.at(bit)=min(dp.at(bit),dp.at(bit-g)+dp.at(g));
    }
  }
  if(dp.at((1<<N)-1)==1e9)  cout << -1 << endl;
  else  cout << dp.at((1<<N)-1) << endl;

  return 0;
}

Measured memory_bytes: 256
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, M, R;
int r[10];

int to[210][210];
int dp[1 << 8][8];

signed main() {
    rep(i,0,210) rep(j,0,210) to[i][j] = INF;
    cin >> N >> M >> R;
    rep(i,0,R) cin >> r[i], r[i]--;
    rep(i,0,M) {
        int a, b, c; cin >> a >> b >> c;
        a--; b--;
        to[a][b] = to[b][a] = c;
    }

    rep(k,0,N) rep(i,0,N) rep(j,0,N) chmin(to[i][j], to[i][k] + to[k][j]);

    rep(i,0,1<<R) rep(j,0,R) dp[i][j] = INF;
    rep(i,0,R) dp[1 << i][i] = 0;

    int ans = INF;
    priority_queue< pii, vector<pii>, greater<pii> > q;
    rep(i,0,R) q.push(pii(1 << i, i));
    while(!q.empty()) {
        pii cur = q.top(); q.pop();
        int bit = cur.first, point = cur.second;

        rep(i,0,R) {
            if(bit >> i & 1) continue;
            int next = r[i], nbit = bit | (1 << i);
            if(dp[nbit][i] > dp[bit][point] + to[ r[point] ][next]) {
                dp[nbit][i] = dp[bit][point] + to[ r[point] ][next];
                if(nbit == (1 << R) - 1) chmin(ans, dp[nbit][i]);
                q.push(pii(nbit, i));
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>

#define MAX 1000

int main()
{
	char s[MAX];
	int k;


	scanf("%s", s);

	k = strlen(s) - 1;

	k = s[k] - '0';

	if (k == 2 || k == 4 || k == 5 || k == 7 || k == 9)
		printf("hon\n");
	else if (k == 3)
		printf("bon\n");
	else
		printf("pon\n");

	return 0;
}

Measured memory_bytes: 1596
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

#define MAX_N 200000
#define MAX_M 200000
#define MOD 1000000007

#define INF 1 << 29

int N, M;
string S;

long long dp[MAX_N + 2], rdp[MAX_N + 2];

int all_color_is_same()
{
    long long rr = 1, bb = 1, rb = 0, br = 0;

    for ( int i = 1; i < N; i++ )
    {
        long long nrr = ( rr + rb ) % MOD;
        long long nbb = br;
        long long nrb = rr;
        long long nbr = ( bb + br ) % MOD;

        rr = nrr;
        bb = nbb;
        rb = nrb;
        br = nbr;
    }

    return ( rr + rb + br ) % MOD;
}

/* S
の先頭の文字の最小連続回数を求める。ただし連続回数が偶数のものは無視する。
*/
int min_freq()
{
    int l = 0;
    while ( l < M && S[0] == S[l] ) l++;

    int ans = ( l & 1 ) ? l : l + 1;

    l = 0;
    for ( int i = 0; i < M; i++ )
    {
        if ( S[0] == S[i] )
            l++;
        else
        {
            if ( l & 1 ) ans = min( ans, l );
            l = 0;
        }
    }
    return ans;
    // int l = 0;
    // while ( S[0] == S[l] ) l++;
    // if ( l % 2 == 0 ) l++;
    // int limit = l;
    // l = 0;
    // for ( int i = 0; i < M; i++ )
    // {
    //     if ( S[i] == S[0] )
    //         l++;
    //     else
    //     {
    //         if ( l % 2 == 1 ) limit = min( limit, l );
    //         l = 0;
    //     }
    // }
    // return limit;
}

int solve()
{
    // 一色
    if ( S.find( "R" ) == string::npos || S.find( "B" ) == string::npos )
        return all_color_is_same();

    // N が奇数
    if ( N & 1 ) return 0;

    int L = min_freq();

    L = ( L + 1 ) >> 1;
    N >>= 1;

    dp[0] = rdp[0] = 1;
    for ( int i = 1; i <= N + 1; i++ )
    {
        dp[i] = rdp[i - 1];
        if ( i - L - 1 >= 0 ) dp[i] = ( dp[i] - rdp[i - L - 1] ) % MOD;
        if ( dp[i] < 0 ) dp[i] += MOD;
        rdp[i] = ( rdp[i - 1] + dp[i] ) % MOD;
    }

    long long res = 0;
    for ( int i = 1; i <= L; i++ )
        if ( N >= i ) res = ( res + dp[N - i] * 2 * i ) % MOD;

    return res % MOD;
}

int main( int argc, char **argv )
{
    cin >> N >> M;
    cin >> S;

    int ans = solve();

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2180
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>

#define N 50

int max(int a, int b) { return a > b ? a : b; }

void srand_() {
	struct timeval tv;

	gettimeofday(&tv, NULL);
	srand(tv.tv_sec ^ tv.tv_usec);
}

int rand_(int n) {
	return (rand() * 76543LL + rand()) % n;
}

int compare(const void *a, const void *b) {
	int ia = *(int *) a;
	int ib = *(int *) b;

	return ia - ib;
}

void sort(int *aa, int n) {
	int i;

	srand_();
	for (i = 0; i < n; i++) {
		int j = rand_(i + 1), tmp;

		tmp = aa[i], aa[i] = aa[j], aa[j] = tmp;
	}
	qsort(aa, n, sizeof *aa, compare);
}

int main() {
	static int vv[N];
	int n, k, i, p, ans;

	scanf("%d%d", &n, &k);
	for (i = 0; i < n; i++)
		scanf("%d", &vv[i]);
	ans = 0;
	for (p = 0; p <= n && p <= k; p++) {
		int q;

		for (q = 0; p + q <= n && p + q <= k; q++) {
			static int vv_[N];
			int r = k - p - q;
			int cnt = 0;
			int h;
			int sum;

			for (i = 0; i < p; i++)
				vv_[cnt++] = vv[i];
			for (i = n - q; i < n; i++)
				vv_[cnt++] = vv[i];
			sort(vv_, cnt);
			sum = 0;
			for (h = 0; h < cnt; h++) {
				if (h < r && vv_[h] < 0)
					continue;
				sum += vv_[h];
			}
			ans = max(ans, sum);
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i, s, e) for (int i = s; i < e; i++)
#define endl '\n'
int main()
{
    lli a, b, c;
    cin >> a >> b >> c;
    if (c - a - b > 0 && 2 * a * b - a * a - b * b < c * c - 2 * c * (a + b))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  vector<int> B(N);
  for (int i = 0; i < N; i++) {
    cin >> B.at(i);
  }
  vector<int> C(N-1);
  for (int i = 0; i < N-1; i++) {
    cin >> C.at(i);
  }
  
  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans += B.at(A.at(i)-1);
  }
  for (int i = 1; i < N; i++) {
    if (A.at(i-1)+1 == A.at(i)) {
    ans += C.at(A.at(i-1)-1);
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
int main(){
  ll x;
  cin >> x;

  ll ans=0;
  ans+=(x/500)*1000;
  x%=500;

  ans+=(x/5)*5;
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define endl '\n';
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



int main() {
    
    int n;
    cin>>n;
    ll sum=0;
    ll minb=LLINF;
    bool issame=1;
    rep(i,n){
        ll a,b;
        cin>>a>>b;
        if(a!=b)issame=0;
        if(a>b)chmin(minb,b);
        sum+=a;
    }
    if(issame)fin(0);
    else fin(sum-minb);

}



Measured memory_bytes: 256
s = gets.chomp
k = gets.chomp.to_i
arr = s[0..k-1].split("").uniq 
if s.size == 1
    puts s
elsif s.size >= 2 && s[0] == "1" && k >= 2 && s[0..k-1].split("").uniq != ["1"]
    puts arr[1]
elsif s.size >= 2 && s[0] == "1" && k >= 2 && s[0..k-1].split("").uniq == ["1"]
    puts s[0]
elsif s.size >= 2 && s[0] == "1" && k < 2
    puts s[0]
elsif s.size >= 2 && s[0] != "1"
    puts s[0]
end

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

struct Entrant
{
  int num;
  int wakasagi;

  bool operator<(const Entrant& right) const
  {
    return wakasagi == right.wakasagi ? num > right.num : wakasagi < right.wakasagi;
  }
};

int main(void)
{
  int n;
  cin >> n;
  vector<Entrant> entrants(n);
  for (auto& e : entrants)
  {
    cin >> e.num >> e.wakasagi;
  }
  sort(entrants.begin(), entrants.end());
  cout << entrants.back().num << " " << entrants.back().wakasagi << endl;
  return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using Graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main(){
ll a,b,c,d;cin >> a >> b >> c >> d;
cout << max(a*b, c *d) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int K,T,a[105];
void Solve() {
    read(K);read(T);
    int m = 0;
    for(int i = 1 ; i <= T ; ++i) {
	read(a[i]);
	m = max(a[i],m);
    }
    if(K - m >= m) {puts("0");return;}
    else {out(m - (K - m) - 1);enter;}
    
}

int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


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

int main()
{
  int n, m;
  cin >> n >> m;
  long long ok = 0;
  long long pena = 0;
  
  vector<long long> wa(n, 0), ac(n, 0);
  for (int i = 0; i < m; i++)
  {
    int p;
    string s;
    cin >> p >> s;
    --p;
    if (s == "AC")
    {
      if (!ac[p])
      {
        ok++;
        pena += wa[p];
        ac[p] = true;
      }
    }
    else
      wa[p]++;
  }
  cout << ok << " " << pena << endl;
}
        

Measured memory_bytes: 1792
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define chmax(x, y) x = max(x,y);

int main(){
int n;
cin>>n;
vector <int> x(n+1);
for (int i=1; i<n+1; i++){
  cin>>x[i];
}
int ans=1000000;
for (int i=1; i<101; i++){
  int temp=0;
  for (int j=1; j<n+1; j++){
    temp+=(x[j]-i)*(x[j]-i);
  }
  ans=min(ans,temp);
}
cout<<ans;
}


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

int main(){
	ll M;
	cin >> M;
	ll temp = 0;
	ll digit = 0;
	rep(i,M){
		ll d,c;
		cin >> d >> c;
		temp += d*c;
		digit += c;
	}
	
	cout << (temp-1)/9 + digit - 1 << endl;
    return 0;
}



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

int main(void) {
    int N;cin>>N;
    int V[N],C[N];
    int ma = 0;
    for (int i = 0; i < N; i++) cin >> V[i];
    for (int i = 0; i < N; i++) cin >> C[i];
    for (int i = 0; i < N; i++) {
        if (V[i] >= C[i]) ma += V[i] - C[i];
    }
    cout << ma << endl;
    return 0;
}

Measured memory_bytes: 888
#include <cstdio>
#include <algorithm>
using namespace std;


int n, m;
char cv[256], ch, ch2;

int main(){
	while(scanf("%d\n", &n), n != 0) {
		fill(cv, cv + 256, 0);
		for (int i = 0; i < n; i++) {
			scanf("%c %c\n", &ch, &ch2);
			cv[ch] = ch2;
		}
		scanf("%d\n", &m);
		for (int i = 0; i < m; i++) {
			scanf("%c\n", &ch);
			printf("%c", cv[ch] == 0 ? ch : cv[ch]);
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 2608
# 初期入力
N,K = (int(x) for x in input().split(" "))

#
zeroika = 0
if K <N:
    zeroika = N//K
else:
    zeroika = 1
N1 =abs(N-K*zeroika) #N1がマイナスになって初めてABS、そこまではKの倍数単調に減る
while N1<N:
    N =N1
    N1 =abs(N-K)
    #print(N1,end=" ")
print(N)

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  string s, t;
  cin >> s >> t;
  s += s;
  cout << (s.find(t) == string::npos ? "No" : "Yes") << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

typedef long long ll;
const ll INF = 1e5;


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

	double odd=0;

	for (int i = 1; i <= N; i = i + 2) { odd++; }

	cout << odd / N;


	system("PAUSE");
}


Measured memory_bytes: 504
#include<bits/stdc++.h>
//#pragma GCC optimize ("-O3")

using namespace std;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//const long double PI = 3.14159265358979323846;


int main()
{
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    long long d, s, t;
    cin >> d >> t >> s;
    if (d <= t*s)
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}


Measured memory_bytes: 3644
//【ライブラリここから】
// 1. 入力の容易化（https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8）
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
//【ライブラリここまで】

fn main() {
    input! {s:String, t:String};
    let s_b: Vec<char> = s.chars().collect();
    let t_b: Vec<char> = t.chars().collect();
    let mut max_cnt = 0;
    for start in 0..(s_b.len() - t_b.len() + 1) {
        let mut cnt = 0;
        for p in 0..t_b.len() {
            if s_b[start + p] == t_b[p] {
                cnt += 1;
            }
        }
        if max_cnt < cnt {
            max_cnt = cnt;
        }
    }
    println!("{}", t_b.len() - max_cnt);
}


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

int main()
{
  int t, n, s, f, ans;
  while(true)
  {
    t = n = s = f = ans = 0;
    cin >> t;
    if(!t)
      break;

    cin >> n;
    for(int i = 0; i < n; i++)
    {
      cin >> s >> f;
      ans += f - s;
    }

    if(ans >= t)
      cout << "OK\n";
    else
      cout << t - ans << endl;
  }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sz(x) (int)x.size()
typedef pair<int,int>pii;
const int mxN=2e5,M=1e9+7;

int n,m;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>m;
    if(n==m)cout<<"Yes";
    else cout<<"No";
}

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

int main(){
    int  y,m,d;
    char c1,c2;
    cin >> y >> c1 >> m >> c2 >> d;

    if(m<=4){
        cout << "Heisei" << endl;
    }else{
        cout << "TBD" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <cmath>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

using ll = long long;
using ld = long double;
using vi = vector<int>;

int a;
int b;

void input() {
  cin >> a >> b;
}

void solve() {
  string ans = "unsafe";

  if (b < a)
    ans = "safe";

  cout << ans << '\n';
}

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

  cout.precision(16);
  cout << fixed;

  int _times = 1;

#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);

  _times = 3;
#endif

  // cin >> _times;

  while (_times--) {
    input();
    solve();
  }
}


Measured memory_bytes: 3600
n = int(input())
h = list(map(int, input().split()))
dp = [float('inf')] * n
dp[0] = 0
for i in range(n):
	if i + 1 < n:
		dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]))
	if i + 2 < n:
		dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]))
print(dp[-1])

Measured memory_bytes: 52552
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class BIncrementDecrement {
public:
	void solve(istream& in, ostream& out) {
        int n,x = 0,ans = 0; string s;
        in >> n >> s;
        rep(i,n) {
        if(s[i] == 'I') x++;
        else x--;
        ans = max(ans,x);
        }
        out << ans << endl;
	}
};

int main() {
	BIncrementDecrement solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
static const int MAX=10e9;
int main(void)
{
	int N,T,A;
		cin >> N >> T >> A;
	A*=1000;
	int sa=MAX,ans;
	for(int i=0;i<N;i++){
		int H;
			cin >> H;
		int to=T*1000-H*6;
		to=A-to;
		to=abs(to);
		if(sa>to){
			sa=to;
			ans=i+1;
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main()
{
    string s;
    cin >> s;
    if (s == "SUN")
        cout << 7 << endl;
    else if (s == "MON")
        cout << 6 << endl;
    else if (s == "TUE")
        cout << 5 << endl;
    else if (s == "WED")
        cout << 4 << endl;
    else if (s == "THU")
        cout << 3 << endl;
    else if (s == "FRI")
        cout << 2 << endl;
    else if (s == "SAT")
        cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int n;
	int a;
	int max,min;
	double sum=0.0;
	int i;
	double s;

	scanf("%d",&n);

	for(i = 0;i < n;i++){
		scanf("%d",&a);
		if(i == 0){
			min = a;
			max = a;
		}
		if(a > max){
			max = a;
		}else if(a < min){
			min = a;
		}
		sum+=(double)a;
	}
	printf("%d %d %.0f\n",min,max,sum);
	return 0;
}

Measured memory_bytes: 632
n, m = map(int, input().split())
ps = [list(input().split()) for i in range(m)]
ac = [0] * n
wa = [0] * n
for i in range(m):
    if ac[int(ps[i][0]) - 1] == 0:
        if ps[i][1] == "AC":
            ac[int(ps[i][0]) - 1] = 1
        else:
            wa[int(ps[i][0]) - 1] += 1
for i in range(n):
    if ac[i] == 0:
        wa[i] = 0
print(sum(ac), sum(wa))

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

const int maxn = 300005;
set<pair<int, int>> s;
int cntx[maxn], cnty[maxn];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int h, w, m, x, y, ma = 0, saved = 1, res = 0;
    cin >> h >> w >> m;
    for (int i = 1; i <= m; i++) {
        cin >> x >> y;
        cntx[x]++;
        cnty[y]++;
        s.insert({x, y});
    }
    for (int i = 1; i <= w; i++)
        if (cnty[i]>ma) {
            ma = cnty[i];
            saved = i;
        }
    for (int i = 1; i <= h; i++) {
        if (s.count({i, saved})) res = max(res, ma+cntx[i]-1);
        else res = max(res, ma+cntx[i]);
    }
    ma = 0, saved = 1;
    for (int i = 1; i <= h; i++) {
        if (cntx[i]>ma) {
            ma = cntx[i];
            saved = i;
        }
    }
    for (int i = 1; i <= w; i++) {
        if (s.count({saved, i})) res = max(res, ma+cnty[i]-1);
        else res = max(res, ma+cnty[i]);
    }
    cout << res;
}

Measured memory_bytes: 20028
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#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)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {

	string s; cin >> s;
	int k; cin >> k;
	int n = s.length();

	vector<string> a;

	for (int l = 0; l < n; l++) {
		for (int r = l + 1; r <= n &&r - l <= 5; r++) {
			a.push_back(s.substr(l, r - l));
		}
	}

	sort(ALL(a));
	a.erase(unique(ALL(a)), a.end());

	cout << a[k - 1] << endl;

	return 0;
}

Measured memory_bytes: 1660
N,Y = map(int,input().split(' '))
for x in range(N+1):
    for y in range(N-x+1):
        if 10000*x + 5000*y + 1000*(N-x-y) == Y:
            print(x,y,N-x-y)
            exit()
print(-1,-1,-1)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
main()
{
    long long a,b,c,x,y,t,g,h,k,l;
    scanf("%lld%lld%lld%lld%lld",&a,&b,&c,&x,&y);
    t=(a*x)+(b*y);
    if(x>y)
    {
        g=(2*x)*c;
        h=((2*y)*c)+((x-y)*a);
    }
    else
    {
        g=(2*y)*c;
        h=((2*x)*c)+((y-x)*b);

    }
    if(t<=g&&t<=h)
        printf("%lld\n",t);
    else if(g<=t&&g<=h)
        printf("%lld\n",g);
        else
            printf("%lld\n",h);
        return 0;



}



Measured memory_bytes: 256
program FizzBuzzSum;
var
    x, i : Longint;
    sum : int64;
begin
    readln(x);
    sum := 0;
    for i := 1 to x do begin
        if (((i mod 3) <> 0) and ((i mod 5) <> 0)) then begin
            sum += i;
        end;
    end;
    writeln(sum);
end.

Measured memory_bytes: 1384
n=int(input())
P=[int(x) for x in input().split()]
Q=[int(x) for x in input().split()]
p=tuple(P)
q=tuple(Q)
l=list(range(1,n+1))
L=[]
import itertools
for v in itertools.permutations(l):
  L.append(v)
a=L.index(p)
b=L.index(q)
print(abs(a-b))

Measured memory_bytes: 13852
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let x: isize = iterator.next().unwrap().parse().unwrap();

    if x >= 30 {
        "Yes".to_string()
    } else {
        "No".to_string()
    }
}


Measured memory_bytes: 2120
M, D=map(int, input().split())

counter=0

m=1
while m<=M:
  d=22
  while d<=D:
    d1=d%10
    d10=d//10
    if d1>1 and d10>1 and d1*d10==m:
      counter+=1
    
    d+=1
  
  m+=1
  
print(counter)

Measured memory_bytes: 38896
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-9;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int c[100010];
int main(){
	int n;cin>>n;
	int a[100010];
	for(int i=0;i<n;i++){
		cin>>a[i];
		c[a[i]]++;
	}
	bool f=true;
	if(n%2){
		for(int i=0;i<=n;i++){
			if(i==0){
				if(c[i]!=1){
					f=false;
				}
			}else if(i%2){
				if(c[i])f=false;
			}else{
				if(c[i]!=2)f=false;
			}
		}
	}else{
		for(int i=0;i<n;i++){
			if(i%2){
				if(c[i]!=2)f=false;
			}else{
				if(c[i])f=false;
			}
		}
	}
	if(f){
		ll ans=1;
		for(int i=0;i<n/2;i++){
			(ans*=2)%=MOD;
		}
		cout<<ans<<endl;
	}else{
		cout<<0<<endl;
	}
	return 0;
}


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

int sum(int x){
      int sum = 0;
      while(x > 0){
            sum += x % 10;
            x /= 10;
      }
      return sum;
}

int main(){
      int n;cin >> n;
      if(n % sum(n) == 0)cout << "Yes";
      else cout << "No";
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")

#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <random>
#include <set>
#include <ctime>
#include <cmath>

using namespace std;

const int KEK = 9;

int n, q;
vector<int> v, w;
vector<vector<int>> g;
vector<int> dep;
vector<vector<pair<int, int>>> vec;

vector<int> getp(int v) {
	v++;
	vector<int> p = { v - 1 };
	while (v > 1) {
		v >>= 1;
		p.push_back(v - 1);
	}
	reverse(p.begin(), p.end());
	return p;
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	v.resize(n);
	w.resize(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i] >> w[i];
	}
	g.resize(n);
	for (int u = 2; u <= n; u++) {
		g[u / 2 - 1].push_back(u - 1);
	}
	dep.resize(n);
	for (int u = 0; u < n; u++) {
		for (int to : g[u]) {
			dep[to] = dep[u] + 1;
		}
	}
	vec.resize(n);
	for (int u = 0; u < n; u++) {
		if (dep[u] == KEK) {
			vector<int> p = getp(u);
			int mup = (1 << p.size());
			for (int m = 0; m < mup; m++) {
				int _v = 0;
				int _w = 0;
				for (int i = 0; i < p.size(); i++) {
					if (m >> i & 1) {
						_v += v[p[i]];
						_w += w[p[i]];
					}
				}
				vec[u].emplace_back(_w, _v);
			}
			sort(vec[u].begin(), vec[u].end());
			for (int i = 1; i < vec[u].size(); i++) {
				vec[u][i].second = max(vec[u][i].second, vec[u][i - 1].second);
			}
		}
	}
	cin >> q;
	while (q--) {
		int u, l;
		cin >> u >> l;
		--u;
		vector<int> p = getp(u);
		if (dep[u] < KEK) {
			int ans = 0;
			int mup = (1 << p.size());
			for (int m = 0; m < mup; m++) {
				int _v = 0;
				int _w = 0;
				for (int i = 0; i < p.size() && _w <= l; i++) {
					if (m >> i & 1) {
						_v += v[p[i]];
						_w += w[p[i]];
					}
				}
				if (_w <= l) {
					ans = max(ans, _v);
				}
			}
			cout << ans << '\n';
			continue;
		}
		int pt = p.size() - 1;
		while (dep[p[pt]] != KEK) {
			pt--;
		}
		vector<int> s = vector<int>(p.begin() + pt + 1, p.end());
		const vector<pair<int, int>>& kek = vec[p[pt]];
		int ans = 0;
		int mup = (1 << s.size());
		for (int m = 0; m < mup; m++) {
			int _v = 0;
			int _w = 0;
			for (int i = 0; i < s.size() && _w <= l; i++) {
				if (m >> i & 1) {
					_v += v[s[i]];
					_w += w[s[i]];
				}
			}
			if (_w <= l) {
				int rem = l - _w;
				int pos = upper_bound(kek.begin(), kek.end(), pair<int, int>{ rem, 1000'000'000 + 228 }) - kek.begin() - 1;
				ans = max(ans, _v + kek[pos].second);
			}
		}
		cout << ans << '\n';
	}
}


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

const int ALPHA_LEN = 26;

void count_alpha(int alpha[], const string &line)
{
  for (char c : line)
  {
    if (isalpha(c))
    {
      c = tolower(c);
      alpha[c - 'a']++;
    }
  }
}

void print_alpha(int alpha[])
{
  for (int i = 0; i < ALPHA_LEN; i++)
  {
    cout << (char)('a' + i) << " : " << alpha[i] << endl;
  }
}

int main()
{
  int alpha[ALPHA_LEN] = {};
  string line;
  while (getline(cin, line))
  {
    count_alpha(alpha, line);
  }
  print_alpha(alpha);
}



Measured memory_bytes: 3164
n, m = map(int, input().split())
parent = [i for i in range(n)]

def get_par(x):
    if x == parent[x]:return x
    parent[x] = get_par(parent[x])
    return parent[x]

for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    pa, pb = get_par(a), get_par(b)
    parent[pb] = pa

city_dic = set()
village_cnt = 0
for i in range(n):
    pi = get_par(i)
    if i == pi:village_cnt += 1
    else:city_dic.add(pi)

print(abs(2 * len(city_dic) - village_cnt))


Measured memory_bytes: 5612
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template<class T> using vc = vector<T>;
template<class T> using vvc = vc<vc<T>>;
constexpr ll ten(int n){return (n==0) ? 1 : 10 * ten(n-1);}
#define rng(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,N) for(int i=0;i<(int)(N);i++)
#define gnr(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define per(i,b) gnr(i,0,b)
#define a first
#define b second
#define eb emplace_back
#define pb push_back
#define bg begin()
#define ed end()
#define all(x) x.begin(),x.end()
template<class T, class U> void chmin(T& t, const U& u){ if(t>u) t = u;}
template<class T, class U> void chmax(T& t, const U& u){ if(t<u) t = u;}

#ifdef LOCAL
#define show(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif

template<class T,class U>
ostream& operator<<(ostream& os, const pair<T,U>& p){
    return os << "P(" << p.fs << ", " << p.sc << ")";
}
template<class T> ostream& operator<<(ostream& os, const vc<T>& v){
    os << "[";
    for(auto d: v) os << d << ", ";
    return os << "]";
}

using vi=vector<int>;
using pi=pair<int,int>;

const int inf=INT_MAX/2-100;

template<class d>
struct maxflow{
	struct E{
		int to,rev;
		d cap;
	};
	vvc<E> g;
	vi itr,lv;
	maxflow(int n):g(n),itr(n),lv(n){}
	void ae(int s,int t,d c){
		g[s].pb({t,(int)g[t].size(),c});
		g[t].pb({s,(int)g[s].size()-1,0});
	}
	void bfs(int s){
		fill(all(lv),-1);
		lv[s]=0;
		queue<int> q;
		q.push(s);
		while(q.size()){
			int v=q.front();q.pop();
			for(auto e:g[v])if(e.cap>0&&lv[e.to]==-1){
				lv[e.to]=lv[v]+1;
				q.push(e.to);
			}
		}
	}
	d dfs(int v,int t,d f){
		if(v==t)return f;
		d res=0;
		for(int&i=itr[v];i<(int)g[v].size();i++){
			E& e=g[v][i];
			if(e.cap>0&&lv[e.to]==lv[v]+1){
				d a=dfs(e.to,t,min(f,e.cap));
				if(a>0){
					e.cap-=a;
					g[e.to][e.rev].cap+=a;
					res+=a;
					f-=a;
					if(f<=0)break;
				}
			}
		}
		return res;
	}
	d calc(int s,int t){
		d f=0;
		while(1){
			bfs(s);
			if(lv[t]==-1)return f;
			fill(all(itr),0);
			f+=dfs(s,t,inf);
		}
	}
};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int n,m,s,t,u,v;cin>>n>>m>>s>>t>>u>>v;
    s--;t--;u--;v--;
    vc<pi> es;
    rep(_,m){
		int a,b;cin>>a>>b;a--;b--;
		es.eb(a,b);
	}
	int ans=inf;
	
	rep(_,2){
		maxflow<int> mf(n+2);
		for(auto e:es){
			mf.ae(e.a,e.b,1);
			mf.ae(e.b,e.a,1);
		}
		mf.ae(n,s,inf);
		mf.ae(n,u,inf);
		mf.ae(t,n+1,inf);
		mf.ae(v,n+1,inf);
		chmin(ans,mf.calc(n,n+1));
		swap(s,t);
	}
	
	cout<<ans<<endl;
}



Measured memory_bytes: 12776
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

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

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

    int A, B;
    cin>>A>>B;
    int ans = -1;
    rep(i, 2000) {
        if ((int)(i * 0.08) == A && (int)(i * 0.10) == B) {
            ans = i;
            break;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define A 2000000
int main(void){
int n,i,j,k;
int R[A];
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&R[i]);
}
for(i=0;i<n-1;i++){
if(i==0 || j>R[i]){
j=R[i];
}
if(i==0 || k<R[i+1]-j){
k=R[i+1]-j;
}
}
printf("%d\n",k);
return 0;
}


Measured memory_bytes: 2524
#include <stdio.h>

int main(){
	char ch;
	while((ch = getchar()) != EOF){
			if(ch >= 97 && ch <= 122)
				printf("%c",ch-32);
			else if(ch >= 65 && ch <= 90)
				printf("%c",ch+32);
			else
				printf("%c",ch);
	}
}







Measured memory_bytes: 2636
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int main(void)
{
	int x;
	scanf("%d",&x);
	int res = 1, now = 7%x;
	int mx = 30000000;
	while(res <= mx)
	{
		if(!now){ printf("%d",res); return 0;}
		now = (now * 10 + 7) % x;
		++res;
	}
	printf("-1");
	return 0;
}

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

#define tt template<typename T> ostream& operator <<(ostream& os, const
#define tuv template<typename U, typename V> ostream& operator<<(ostream& os, const
tt vector<T>& v)            { os << "["; for(auto & x : v) os << " " << x; os << " ]"; return os; }
tt vector<vector<T> >& m)   { for(auto & x : m) { for(auto & y : x) os << y << " "; os << "\n"; } return os; }
tt set<T>& s)               { os << "{"; for(auto & x : s) os << " " << x; os << " }"; return os; }
tt unordered_set<T>& s)     { os << "{"; for(auto & x : s) os << " " << x; os << " }"; return os; }
tt queue<T>& q)             { queue<T> q2(q); while(!q2.empty()) { os << q2.front() << " "; q2.pop(); } return os; }
tt stack<T>& s)             { stack<T> s2(s); while(!s2.empty()) { os << s2.top() << " "; s2.pop(); } return os; }
tuv pair<U,V>& p)           { os << "(" << p.first << "," << p.second << ")"; return os; }
tuv map<U,V>& m)            { os << "{ "; for(auto & x : m) os << x.first << ":" << x.second << " "; os << "}"; return os; }
tuv unordered_map<U,V>& um) { os << "{ "; for(auto & x : um) os << x.first << ":" << x.second << " "; os << "}"; return os; }


int main(int argc, char * argv[])
{
    std::ios_base::sync_with_stdio(false);    
    std::cin.tie(NULL);

    int x;
    std::cin >> x;

    int happiness = 0;
    while(x > 0)
    {
	if(x >= 500)
	{
	    x -= 500;
	    happiness += 1000;
	}
	else if(x >= 5)
	{
	    x -= 5;
	    happiness += 5;
	}
	else
	{
	    break;
	}
    }
    std::cout << happiness << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
	int aiNumber[4];
	int iNumberKeep;
	//3つの整数を入力し3つ箱の中にそれぞれ入れる
	scanf("%d %d %d", &aiNumber[0], &aiNumber[1], &aiNumber[2]);
	//箱の中身を入れ替える(AとBの後AとC)
	iNumberKeep = aiNumber[0];
	aiNumber[0] = aiNumber[1];
	aiNumber[1] = iNumberKeep;

	iNumberKeep = aiNumber[0];
	aiNumber[0] = aiNumber[2];
	aiNumber[2] = iNumberKeep;
	//結果を出力する
	printf("\n%d %d %d\n", aiNumber[0], aiNumber[1], aiNumber[2]);

	return 0;
}

Measured memory_bytes: 2128
#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 ms(s,x) memset(s,x,sizeof(s))
#define pb push_back
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;

const double PI = acos(-1.0);
const double eps = 1e-8;
const ll MOD = 1e9+7;
const int MAXN = 1e5+5;

int main()
{
    map <string, int> mp;
    int n, maxi = 0;
    string s;
    cin >> n;
    while (n--)
    {
        cin >> s;
        mp[s]++;
        maxi = max(maxi, mp[s]);
    }
    for (auto it: mp)
    {
        if (it.second == maxi)
            cout << it.first << endl;
    }

    return 0;
}


Measured memory_bytes: 25600
N = int(input())
a = [int(i) for i in input().split()]
a_4 = [i for i in a if i%4 == 0]
a_2 = [i for i in a if i%2 == 0]
a_4_len = len(a_4)
a_2_not4_len = len(a_2) - a_4_len
if a_4_len >= N//2:
    print("Yes")
elif a_2_not4_len >= (N - a_4_len*2):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 63640
#include<iostream>
int main() {
	int a[31] = { 0 }, b;
	for (int i = 0; i < 28; i++) {
		std::cin >> b;
		a[b]++;
	}
	for (int i = 1; i <= 30; i++) {
		if (a[i] == 0) {
			std::cout <<i<< std::endl;
		}
	}
}

Measured memory_bytes: 3076
N, X = [int(nx) for nx in input().split()]
x = [abs(int(xx) - X) for xx in input().split()]

while len(x) > 1:
  x2 = []
  mn_x = min(x)
  for n in range(len(x)):
    mod = x[n] % mn_x
    if mod != 0:
      x2.append(mod)
  x2.append(mn_x)
  x = x2
  
ans = x[0]
print(ans)

Measured memory_bytes: 14252
n,w = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
b = [[] for _ in range(4)]
for i,j in a:
    b[i-a[0][0]].append(j)
for i in range(4):
    b[i].sort()
    b[i].reverse()
for i in range(4):
    for j in range(1,len(b[i])):
        b[i][j] += b[i][j-1]
    b[i].reverse()
    b[i].append(0)
    b[i].reverse()
#print(b)
ans = 0
for i in range(len(b[0])):
    for j in range(len(b[1])):
        for k in range(len(b[2])):
            for l in range(len(b[3])):
                #print(i,j,k,l)
                if a[0][0]*i+(a[0][0]+1)*j+(a[0][0]+2)*k+(a[0][0]+3)*l <= w:
                    #print(i,j,k,l)
                    ans = max(ans, b[0][i]+b[1][j]+b[2][k]+b[3][l])
print(ans)

Measured memory_bytes: 9296