akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
using namespace std;

bool HA[4194304];
int T[256] = {0};

inline int get( unsigned char c ) {
    return T[c];
}

int main() {
    int n;
    register int sum, t, c;
    T['A'] = 1, T['C'] = 2, T['G'] = 3, T['T'] = 4;
    while ( scanf("%d", &n) != EOF ) {
        memset( HA, false, 4194304 );
        while ( getchar() != '\n' );
        for ( register int i = 0; i < n; ++ i ) {
            sum = 0;
            t = 1;
            bool flag = ( c = getchar() ) == 'i';
            while ( ( c = getchar() ) != ' ' );
            while ( ( c = T[getchar()] ) != 0 ) {
                sum += c * t;
                t *= 4;
            }
            if ( flag ) {
                HA[sum] = true;
            } else {
                puts( HA[sum] ? "yes" : "no" );
            }
        }
    }
    return 0;
}

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

using namespace std;

int main(){
    int n ,m ;
    cin >> n;
    cin >> m;
    int a;
    int b;
    int f[m];

    for(int i = 0; i < m; i++){
        f[i] = 0;
    }
    for(int i = 0; i < n; i++){
        cin >> a;
        for(int j = 0; j < a; j++){
            cin >> b;
            f[b-1] ++;
        }
    }

    int cnt = 0;

    for(int i = 0; i < m; i++){
        if(f[i] == n){
            cnt++;
        }
    }

    cout << cnt << endl;
}

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

ll solve() {
    ll N;
    cin >> N;
    string S;
    cin >> S;

    vector<int> rank(N+1), tmp(N+1);
    int n, k;

    auto cmp_sa = [&](int i, int j) {
        if ( rank[i] != rank[j] ) return rank[i] < rank[j];
        else {
            int ri = i + k <= n ? rank[i+k] : -1;
            int rj = j + k <= n ? rank[j+k] : -1;
            return ri < rj;
        }
    };

    auto get_sa = [&](string& s, vector<int>& sa) {
        n = s.size();
        for ( int i = 0; i <= n; i++ ) {
            sa[i] = i;
            rank[i] = i < n ? s[i] : -1;
        }
        for ( k = 1; k <= n; k *= 2 ) {
            sort(sa.begin(), sa.end(), cmp_sa);
            tmp[sa[0]] = 0;
            for ( int i = 1; i <= n; i++ ) {
                tmp[sa[i]] = tmp[sa[i-1]] + (cmp_sa(sa[i-1], sa[i]) ? 1 : 0);
            }
            for ( int i = 0; i <= n ; i++ ) {
                rank[i] = tmp[i];
            }
        }
    };


    auto get_lcp = [&](string& s, vector<int>& sa, vector<int>& lcp) {
        n = s.size();
        for ( int i = 0; i <= n; i++ ) {
            rank[sa[i]] = i;
        }
        int h = 0;
        lcp[0] = 0;
        for ( int i = 0; i < n; i++ ) {
            int j = sa[rank[i]-1];
            if ( h > 0 ) h--;
            for ( ; j + h < n && i + h < n; h++ ) {
                if ( s[j+h] != s[i+h] ) break;
            }
            lcp[rank[i]-1] = h;
        }
    };

    vector<int> sa(N+1), lcp(N+1);
    get_sa(S, sa);
    get_lcp(S, sa, lcp);

    ll ans = 0;
    for ( int i = 0; i < N; i++ ) {
        ll tmp = N+1;
        for ( int j = i+1; j <= N; j++ ) {
            if ( tmp > lcp[j-1] )tmp = lcp[j-1];
            if ( tmp <= ans ) break;
            ll x = tmp > abs(sa[j] - sa[i]) ? abs(sa[j] - sa[i]) : tmp;
            if ( ans < x ) ans = x;
        }
    }
    
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
#define PUTS(x) std::cout << (x) << endl;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)

int main() {
    int n, q;
    string s;
    cin >> n >> s >> q;
    auto a = vector<set<int>>(26, set<int>());
    rep(i, n) {
        a[s[i] - 'a'].insert(i);
    }
    rep(i, q) {
        int t, j;
        cin >> t;
        if (t == 1) {
            char c;
            cin >> j >> c;
            j--;
            rep(k, 26) {
                a[k].erase(j);
            }
            a[c - 'a'].insert(j);
        } else {
            int l, r;
            cin >> l >> r;
            l--;
            auto ans = 0;
            rep(k, 26) {
                auto x = a[k].lower_bound(l);
                auto y = a[k].lower_bound(r);
                if (x != y) ans++;
            }
            PUTS(ans)
        }
    }
}


Measured memory_bytes: 27264
#include <iostream>

using namespace std;

int main(){
  int n;
  int answer = 0;
  
  cin >> n;
  
  for(int i  = 1; i <= n; i++){
    int a;
    cin >> a;
    if(i % 2 == 0) continue;
    if(a % 2 == 1) answer++;
  }
  
  cout << answer << endl;
  return 0;
}

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

int main(void){
	int a,b,k;
	cin >> a >> b >> k;
	vector<int> v;
	for(int i = 1; i <= 100; i++){
		if(a%i==0&&b%i==0)
			v.push_back(i);
	}
	cout << v[v.size() - k] << endl;
	return 0;
}


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

using namespace std;

typedef long long ll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

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

	ll a;
	cin >> a;
	cout << a + a*a + a*a*a << endl;
}


Measured memory_bytes: 3648
#include<iostream>
using namespace std;
int main(){ 

  int s,m,h;

  cin >> s ;
  h=s/3600;
  s=s%3600;
  m=s/60;
  s=s%60;
  cout << h << ":" << m <<":"<<s<< endl;


  return 0;
}

Measured memory_bytes: 3072
#include <stdio.h>
#include <string.h>
#define lop(i, n) for(i=1; i<n; i++)

int main()
{
	int N, i, j;
	
	scanf("%d", &N);
	
	lop(i, 10){
		lop(j, 10){
			if(N==i*j){ printf("Yes"); return 0; }
		}
	}
	
	printf("No");
	
return 0;
}

Measured memory_bytes: 128
from sys import exit, setrecursionlimit
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

setrecursionlimit(1000000)

(x, y) = reads()

def Awin():
  print("Alice"); exit()

def Bwin():
  print("Brown"); exit()

if abs(x - y) <= 1:
  Bwin()
else:
  Awin()


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

using namespace std;

int N,c,m;

int main()
{
    cin >> N;
    m=0;
    for (int i=1; i<=N; i+=2)
    {
        c=0;
        for (int j=2; j<=sqrt(i); j++)
        {
            if (i%j==0)
            {
                //cout << "\t" << i << "\t" << j << endl;
                c++;
                //cout << c << endl;
            }
            if (c==3)
            {
                m++;
                break;
            }
        }
    }
    cout << m << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  vector<vector<char> >a(h, vector<char>(w));
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      cin >> a.at(i).at(j);
    }
  }
  for(int i=0; i<w+2; i++){
    cout << "#";
    if(i==w+1){
      cout << endl;
    }
  }
  for(int i=0; i<h; i++){
    cout << "#";
    for(int j=0; j<w; j++){
      cout << a.at(i).at(j);
    }
    cout << "#" << endl;
  }
  for(int i=0; i<w+2; i++){
    cout << "#";
    if(i==w+1){
      cout << endl;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  cin >> N >> K;
  if (N % 2 == 0){
    if (N/2 >= K){
      cout << "YES" << endl;
    }
    else {
      cout << "NO" << endl;
    }
  }
  else {
    if ((N+1)/2 >= K){
      cout << "YES" << endl;
    }
    else {
      cout << "NO" << endl;
    }
  }
}
    
  
    

Measured memory_bytes: 3648
import java.util.*;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int m,f,r;
		
		while(true) {
			m = sc.nextInt();
			f = sc.nextInt();
			r = sc.nextInt();
			
			if (m==-1 && f==-1 && r==-1) {
				break;
			}
			if (m==-1 || f==-1) {
				System.out.println("F");
			}else if(m+f < 30) {
				System.out.println("F");
			}else if(m+f < 50 && r < 50) {
				System.out.println("D");
			}else if(m+f < 65) {
				System.out.println("C");
			}else if(m+f < 80) {
				System.out.println("B");
			}else {
				System.out.println("A");
			}
			
		}
		
		
	}

}


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

int main()
{
   ll N,M;//n円をm種類で支払う！！
   cin >> N>>M;
   vector<vector<int>>dp(M,vector<int>(N+1,1e9));
   vector<int> list(M);
   rep(i,M)
   {cin>>list.at(i);
   }
   sort(list.begin(),list.end());

   rep(i,M)
   {    ll m=list.at(i);
       rep(j,N+1)
       {   if(i==0){dp[i][j]=j; continue;}
           if(j-m>=0)
           dp[i][j]=min(dp[i-1][j-m]+1,min(dp[i-1][j],dp[i][j-m]+1));
           else{ dp[i][j]=dp[i-1][j];}
       }
   }

    cout<<dp[M-1][N]<<endl;

    return 0;
}


Measured memory_bytes: 7080
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#include <bitset>
#define M 1000000007
#define M1 998244353

#define tr(container, it) \
for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define fast                        \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

ll power(ll x, ll n)
{
    ll result = 1;
    while (n)
    {
        if (n % 2 == 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}

ll gcd(ll a, ll b)
{
    if (!b)
        return a;
    return gcd(b, a % b);
}

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

inline ll mul(ll x, ll y, ll m)
{
    ll z = 1LL * x * y;
    if (z >= m)
    {
        z %= m;
    }
    return z;
}

ll powmod(ll x, ll y, ll m)
{
    ll r = 1;
    while (y)
    {
        if (y & 1)
        {
            r = mul(r, x, m);
        }
        y >>= 1;
        x = mul(x, x, m);
    }
    return r;
}



void start()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
/***********************************************************************************************************/

int main()
{
    start();
    int n;
    cin>>n;
    unordered_map<string, int> m;

    int mx=-1;

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

        m[s]++;
        mx=max(m[s], mx);
    }

    set<string> s;

    for (auto x:m)
    {
        if (x.second==mx)
        {
            s.insert(x.first);
        }
    }
    for (auto x:s)
    {
        cout<<x<<"\n";
    }
    return 0;
}

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

int main(){
    int N;cin>>N;
    vector<pair<int,int>> num(N);
    for(int i=0;i<N;i++){
        int a;cin>>a;
        num.at(i).first=a;
        num.at(i).second=i+1;
    }
    sort(num.begin(),num.end());
    for(int i=0;i<N;i++){
        if(i!=N-1)cout<<num.at(i).second<<" ";
        else cout<<num.at(i).second<<endl;
    }
}

Measured memory_bytes: 1664
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#define rep(i,n) for (int i= 0;i<(n);++i)
using namespace std;
typedef long long ll;
int main(){
    int n,m;
    cin>>n>>m;
    vector<string>vec(n);
    int s;
    string c;
    rep(i,m){
       cin>>s>>c;
       if(n!=1&&s==1&&c=="0"){
            cout<<-1<<endl;
             return 0;
        }
        if(vec.at(s-1)==""){
           vec.at(s-1)=c;
        }else if(vec.at(s-1)!=c){
           cout<<-1<<endl;
           return 0;
         }
      
   }
   string ans="";

   if(n!=1&&vec.at(0)==""){
       vec.at(0)="1";
   }
   rep(i,n){
       if(vec.at(i)==""){
           ans+="0";
       }else{
           ans+=vec.at(i);
       }
   }
   cout<<ans<<endl;

    
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

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

    double L;
    cin >> L;
    printf("%.10f\n", (L/3.0) * (L/3.0) * (L/3.0));
    return 0;
}

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

using namespace std;

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

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

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	int n, k;
	cin>>k>>n;
	vector<int> a(n);
	rep(i,n)cin>>a[i];

	int len = 0;
	rep(i,n){
		if(i==n-1){
			len = max(len, a[0]+(k-a[i]));
			continue;
		}
		len = max(len,a[i+1]-a[i]);
	}
	cout<<k-len<<endl;
	return 0;
}

Measured memory_bytes: 4032
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtcoderTemplateForCSharp
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var t = Console.ReadLine();

            var flag = false;

            for (int i = 0; i < s.Length; i++)
            {
                if (s == t)
                {
                    flag = true;
                    break;
                }
                else
                {
                    s = s.Last().ToString() + s.Substring(0, s.Length - 1);
                }
            }

            if (flag)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ull (i) = 0; (i) < (n); (i)++)
#define repe(i, n) for(ull (i) = 0; i <= (n); (i)++)
#define repr(i, n) for(ull (i) = (n); (i) > 0; --(i))
#define repre(i, n) for(ull (i) = (n); (i) >= 0; --(i))
typedef long long ll;
typedef unsigned long long ull;

const ull  MOD = 998244353;


ull modpow(ull x, ull y)
{
    if (x == 0)return 0;
    ull r = 1;
    rep(i, y){
        r *= x;
        r %= MOD;
    }
    return r;
}

int main()
{
    ull N;
    cin >> N;
    vector<ull> d(N+1, 0);
    ull a;
    ull max = 0;
    rep(i, N){
        cin >> a;
        d[a]++;
        //if(i == 0 && a != 0){cout << 0 << endl; return 0}
        if(max < a)max = a;
        if(i > 0 && a == 0){cout << 0 << endl; return 0;}
    }

    if(d[0] == 0){
        cout << "0" << endl;
        return 0;
    }
    ull ans = 1;
    for(ull i = 1; i <= max; i++){
        ans *= modpow(d[i-1], d[i]);
        ans %= MOD;
    }
    cout << ans << endl;


    return 0;

}


Measured memory_bytes: 1024
#include <stdio.h>
#include <malloc.h>
#include <string.h>

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

int main(void) {
  int k, n, i, j, tmp;

  scanf(" %d %d", &k, &n);

  int a[n];
  for(i=0; i < n; i++)
    scanf("%d", &a[i]);
  /*
   for(i=0; i < n; i++){
   for(j=i + 1; j < n; ++j){
   if(a[i] > a[j]){
   tmp=a[i];
   a[i]=a[j];
   a[j]=tmp;
   }
   }
   }*/
  qsort(a, n, sizeof(int), compare_int);

//    for(i=0; i < n; i++)
//     printf("%d ", a[i]);
//    printf("\n");
  int le=k - a[n - 1] + a[0];
  for(i=0; i < n - 1; i++){
    if(le < a[i + 1] - a[i]) le=a[i + 1] - a[i];
  }
  printf("%d", k-le);
  return 0;
}


Measured memory_bytes: 1276
import java.util.*;
public class Main {
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
	  int n = sc.nextInt();
      int x = sc.nextInt();
      int[] m = new int[n];
      int min=1000;;
	  for(int i=0;i<n;i++){
        m[i]=sc.nextInt();
        x-=m[i];
        min = Math.min(min,m[i]);
      } 
         System.out.println(n+x/min);
    }
}

Measured memory_bytes: 35664
N,M = map(int,input().split())
array = []
for i in range(M):
    a = list(map(int,input().split()))
    array.append(a)
maxa = max([i[1] for i in array])
array2 = [0 for i in range(maxa+2)]
for i in array:
    array2[i[0]] += 1
    array2[i[1]+1] -= 1
for i in range(len(array2)-1):
    array2[i+1] += array2[i]
print(array2.count(M))
    

Measured memory_bytes: 31336
#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+2; 
int H[maxn]; 
int main()
{
	int k,n;
	long long sum;
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{	
		cin>>H[i];	
	}
	sort(H,H+n);
	sum=0;
	if(k<n)
	{
		for(int i=0;i<(n-k);i++)
			sum+=H[i];
	}
	cout<<sum<<endl;

	return 0;
}


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

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;
//const long long int MOD = 998244353;

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


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
 
	while (cin >> N >> M >> L >> R, N) {
		vector<int>num(N, -1);
		vector<vector<int>>edge(2500);
		for (int i = 0; i < M; i++) {
			cin >> H >> W;
			string s;
			cin >> s;
			edge[H].push_back(num.size());
			for (int j = 1; j < s.size() ; j++) {
				edge[num.size() + j - 1].push_back(num.size() + j);
			}
			edge[num.size() + s.size() - 1].push_back(W);
			for (int j = 0; j < s.size(); j++) {
				num.push_back(s[j] - 'a');
			}
		}
		vector<vector<int>>dis(2500, vector<int>(2500, 10000));
		for (int i = 0; i < 2500; i++) {
			queue<int>Q;
			Q.push(i);
			dis[i][i] = 0;
			while (!Q.empty()) {
				int cn = Q.front();
				Q.pop();
				for (auto j : edge[cn]) {
					if (dis[i][j]) {
						dis[i][j] = 0;
						Q.push(j);
					}
				}
			}
		}
		if (dis[L][R]) {
			cout << "NO\n";
			continue;
		}
		string ans;
		set<int>s;
		int nx = MOD;
		for (auto i : edge[L]) {
			if (num[i] != -1 && !dis[i][R])nx = min(nx, num[i]);
			else {
				for (auto j : edge[i])if(!dis[j][R]) nx = min(nx, num[j]);
			}
		}
		for (auto i : edge[L]) {
			if (num[i] != -1) {
				if (num[i] == nx && !dis[i][R])s.insert(i);
			}
			else {
				for (auto j : edge[i]) {
					if (num[j] == nx&&!dis[j][R])s.insert(j);
				}
			}
		}
		while (ans.size() <= num.size()&&!s.empty()) {
			bool flag = false;
			ans.push_back('a' + nx);
			for (auto i : s) {
				for (auto j : edge[i]) {
					if (j == R) {
						flag = true;
					}
				}
			}
			if (flag)break;
			set<int>t;
			nx = MOD;
			for (auto i : s) {
				for (auto j : edge[i]) {
					if (num[j] != -1 && !dis[j][R])nx = min(nx, num[j]);
					else {
						for (auto k : edge[j])if (!dis[k][R]) nx = min(nx, num[k]);
					}
				}
			}
			for (auto k : s) {
				for (auto i : edge[k]) {
					if (num[i] != -1) {
						if (num[i] == nx && !dis[i][R])t.insert(i);
					}
					else {
						for (auto j : edge[i]) {
							if (num[j] == nx && !dis[j][R])t.insert(j);
						}
					}
				}
			}
			s = t;
		}
		if (ans.size() <= num.size()) {
			cout << ans << endl;
		}
		else{
			cout << "NO\n";
		}
	}
}


Measured memory_bytes: 27776
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

int main()
{
  int n, m;
  cin >> n >> m;
  vi cnt(n);
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    cnt[a]++;
    cnt[b]++;
  }
  for (int i = 0; i < n; ++i) {
    if (cnt[i] % 2) {
      cout << "NO\n";
      return 0;
    }
  }
  cout << "YES\n";
  return 0;
}


Measured memory_bytes: 640
function main(input) {
    const args = input.split(' ');
    const N = parseInt(args[0], 10),
          A = parseInt(args[1], 10),
          B = parseInt(args[2], 10);

    const nums = Array.from(new Array(N), (v, i) => ++i).filter((i) => {
        var n = i.toString().split('').reduce((p, c) => p + parseInt(c), 0);
        return (n >= A && n <= B);
    });

    console.log(nums.reduce((p, c) => p + c, 0));
}

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

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

#define DEBUG 0

int *a;

int findMin(int n)
{
	int i,min=1E9+1,minNum;
	for (i=0;i<n;i++) {
		if (min > a[i]) {
			min = a[i];
			minNum = i;
		}
	}
	return minNum;
}

int divide(int n,int m)
{
	int i,surp,min=1E9+1,minNum=-1;
	for (i=0;i<n;i++) {
		surp = a[i] % a[m];
		if (surp!=0 && min>surp) {
			min = surp;
			minNum = i;
		}
	}
	
	if (minNum>=0) {
		a[minNum] = a[minNum] % a[m];
		return minNum;
	} else {
		return -1;
	}
}

int main(void)
{
	int n,i,minNum,ans;
	scanf("%d",&n);
	a = (int *)malloc(sizeof(int) * n);
	if (a==NULL) {
		perror("a malloc");
		exit(1);
	}
	for (i=0;i<n;i++) scanf("%d",&a[i]);

	while (1) {
		minNum = findMin(n);
		if (DEBUG) printf("findMin : %d\n",a[minNum]);
		ans = minNum;
		minNum = divide(n,minNum);
		if (DEBUG) printf("divide : [%d]\n",minNum);
		if (minNum==-1) break;
		if (DEBUG) printf("next : %d\n",a[minNum]);
	}

	printf("%d\n",a[ans]);
	
	free(a);
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long int
#define booga cout << "booga" << endl
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;

void testcase(){

}

int main(int argc, char** argv){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a,b;
	cin >> a >> b;
	if((a+b)&1){
		cout << "IMPOSSIBLE \n";
	}
	else{
		cout << (a+b)/2 << "\n";
	}
	return 0;
}



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

vector<int> parent;
vector<int> L;
vector<int> R;

int n;

void pre(int u){
  if(u == -1) return;

  cout << " " << u;

  pre(L[u]);
  pre(R[u]);

}

void in(int u){
  if(u == -1) return;

  in(L[u]);

  cout << " " << u;

  in(R[u]);
  
}

void post(int u){
  if(u == -1) return;

  post(L[u]);
  post(R[u]);

  cout << " " << u;
  
}

int main()
{
  int v, l, r, root;

  cin >> n;

  L.resize(n+5);
  R.resize(n+5);
  parent.resize(n+5);

  for(int i = 0; i < n; i++) parent[i] = -1;

  for(int i = 0; i < n; i++){
    cin >> v >> l >> r;

    L[v] = l;
    R[v] = r;

    if(l != -1) parent[l] = v;
    if(r != -1) parent[r] = v;
    
  }

  for(int i = 0; i < n; i++){
    if(parent[i] == -1) root = i;
  }

  cout << "Preorder" << endl;
  pre(root);

  cout << "\n" << "Inorder" << endl;
  in(root);

  cout << "\n" << "Postorder" << endl;
  post(root);
  cout << endl;

  return 0;

}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n, a, k;
  in(n);
  vector<ll> c(n, 0);
  rep(i, n - 1){
    in(a);
    c[a - 1]++;
  }
  rep(i, n){
    out(c[i]);
    memi;
  }
}

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

signed main(void)
{
	int n;
	string s;
	map<char, int> mp;
	cin >> n >> s;
	rep(i, n)
	{
		mp[s[i]]++;
	}
	if (mp['R'] > mp['B'])
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
vector<long long int> vc;
int main()
{

string s;
cin>>s;
if(s=="Sunny") cout<<"Cloudy";
else if(s=="Cloudy") cout<< "Rainy";
else cout<<"Sunny";

    return 0;
}


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

numss = [[0]*(10) for _ in range(10)]
for i in range(1, N+1):
    ss = str(i)
    hd = int(ss[0])
    tl = int(ss[-1])
    numss[hd][tl] += 1

ans = 0
for x in range(1, 10):
    for y in range(1, 10):
        ans += numss[x][y] * numss[y][x]

print(ans)


Measured memory_bytes: 9084
N=int(input())
s=[]
t=[]
for i in range(1,int(N**0.5)+1):
  if N%i==0:
    s.append(i)
    t.append(N//i)
minimum=N-1
for j in range(len(s)):
  minimum=min(minimum,s[j]+t[j]-2)
print(minimum)
  
      

Measured memory_bytes: 3312
#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;



char buf[105];
int table[26];

int main(){

	for(int i = 0; i < 26; i++){

		table[i] = 0;
	}

	scanf("%s",buf);

	for(int i = 0; buf[i] != '\0'; i++){

		table[buf[i]-'a']++;
	}

	for(int i = 0; i < 26; i++){

		if(table[i]%2 == 1){

			printf("No\n");
			return 0;
		}
	}

	printf("Yes\n");

	return 0;
}


Measured memory_bytes: 256
#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 REP(i,n) for(int i=0;i<(n);i++)
#define qwq(x) cerr<<" #"<<#x<<" = "<<x<<endl;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
 
template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=100005;
ll f[N][2],a[N];
int n;

int main(){
	read(n);
	rep(i,1,n)read(a[i]);
	memset(f,0xc0,sizeof f);
	f[0][0]=0;
	rep(i,1,n){
		ll bas=a[i]/2;
		a[i]%=2;
		f[i][a[i]]=max(f[i-1][0],f[i-1][1])+bas;
		if(a[i])f[i][0]=max(f[i][0],f[i-1][1]+bas+1);
		else if(bas)f[i][1]=max(f[i][1],f[i-1][1]+bas);
	}
	cout<<max(f[n][0],f[n][1])<<endl;
	return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;

int main(){
    int s;
    cin>>s;
    int c[10000001]={};
    int ans=0;
    c[s]=1;
    while(1){
        ans++;
        if(s%2==0){
            s=s/2;
        }else{
            s=3*s+1;
        }
        int temp=s;
        c[temp]++;
        if(c[temp]==2){
            break;
        }
    }
    cout<<ans+1;
    return 0;
}

Measured memory_bytes: 39296
#include <stdio.h>
#include <algorithm>
using namespace std;

const int MAXN = (int)1e5 + 5;
const int INF = (int)1e9;

int h[MAXN];
int dp[MAXN];

int main(void) {
    int n, k;

    scanf(" %d %d", &n, &k);
    for (int i = 1; i <= n; i++) {
        scanf(" %d", &h[i]);
    }

    dp[n] = 0;
    for (int i = n - 1; i >= 1; i--) {
        dp[i] = INF;
        for (int j = i + 1; j <= i + k; j++) {
            if (j <= n) {
                dp[i] = min(dp[i], abs(h[i] - h[j]) + dp[j]);
            }
        }
    }
    printf("%d\n", dp[1]);

    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define each(i, a) for(auto &i : a)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

int main() {
    init();

    int m; cin >> m;
    print(24 - m + 24);

    return 0;
}


Measured memory_bytes: 3504
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <fstream>
using namespace std;

int depth = 0;
int sum = 0;

int dfs (int currs, int currd, int j )
{
	int count = 0;
	int i;

	if (currd == depth ){
		if (currs ==  sum ){
			return 1;
		}else{
			return 0;
		} // end if
	} // end if
	
	for (i = min(j, sum ); i >= 0; --i ){
		count += dfs (currs + i, currd + 1, i - 1 );
	} // end for

	return count;
}

int main()
{
	string str = "";

	while (getline (cin, str ) ){
		int n, s;
		int res = 0;
		stringstream ss(str);
		ss >> n >> s;

		if (n == 0 && s == 0 ){
			break;
		} // end if
		
		depth = n;
		sum = s;

		res = dfs (0, 0, 9 );

		cout << res << endl;
	} // end while
	
	return 0;
}

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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	long long a,b;
	long long v,w;
	cin >> a >> v;
	cin >> b >> w;
	long long t;
	cin >> t;
	
	long long dif=abs(b-a);
	if(w>=v){
		cout << "NO\n";
		return 0;
	}
	
	long long tum=v-w;
	if(tum*t >=dif){
		cout << "YES\n";
	}else{
		cout << "NO\n";
	}
	return 0;
}

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

int main()
{
  string s;
  cin >> s;
  int i;
  int count = 0;
  for(i = 0; i < s.length(); i++)
  {
    if(s.at(i) == 'x')
    {
      count++;
    }
  }
  if(count < 8)
  {
    cout << "YES" << endl;
  }
  else
  {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
if __name__ == "__main__":
    n, k = map(lambda x: int(x), input().split())
    modulo = 10 ** 9 + 7
    dp = [[0] * (n + 1)] * (k + 1)
    dp[0][0] = 1
    for i in range(1, k + 1):
        for j in range(n + 1):
            if i <= j:
                dp[i][j] = dp[i - 1][j] + dp[i][j - i]
            else:
                dp[i][j] = dp[i - 1][j]
    ans = dp[k][n] % modulo

    print(ans)



Measured memory_bytes: 5604
#include <iostream>
#include <stdint.h>
#include <vector>

using namespace std;

#define GRAPH_MAX_SIZE 100000
#define WHITE -1

vector<uint32_t> vertexes[GRAPH_MAX_SIZE];
int32_t colors[GRAPH_MAX_SIZE];

void graph_connected_components_init()
{
  uint32_t i;
  for (i = 0; i < GRAPH_MAX_SIZE; i++) {
    vertexes[i].clear();
    colors[i] = WHITE;
  }
}

void graph_connected_components_add(uint32_t vertex, uint32_t connect_to)
{
  vertexes[vertex].push_back(connect_to);
  vertexes[connect_to].push_back(vertex);
}

uint32_t *graph_connected_components_connected_vertexes(uint32_t vertex)
{
  return &vertexes[vertex][0];
}

void colorize_connecting_vertex(vector<uint32_t> *connect_to, int32_t color)
{
  uint32_t i;
  for (i = 0; i < connect_to->size(); i++) {
    uint32_t index = (*connect_to)[i];
    if (colors[index] == WHITE) {
      colors[index] = color;
      colorize_connecting_vertex(&vertexes[index], color);
    }
  }
}

void graph_connected_components_colorize()
{
  int32_t i;
  for (i = 0; i < GRAPH_MAX_SIZE; i++) {
    if (colors[i] == WHITE) {
      colors[i] = i;
      vector<uint32_t> connect_to = vertexes[i];
      colorize_connecting_vertex(&connect_to, i);
    }
  }
}

bool graph_connected_components_is_connected(uint32_t index1, uint32_t index2)
{
  if (colors[index1] == colors[index2]) return true;
  return false;
}

#if !defined(TEST)
#include <iostream>
using namespace std;
int32_t main(void)
{
  graph_connected_components_init();

  int32_t users, connections;
  cin >> users >> connections;

  uint32_t i;
  for (i = 0; i < connections; i++) {
    uint32_t index, connection;
    cin >> index >> connection;
    graph_connected_components_add(index, connection);
  }
  graph_connected_components_colorize();

  int32_t questions;
  cin >> questions;
  for (i = 0; i < questions; i++) {
    uint32_t index1, index2;
    cin >> index1 >> index2;
    if (graph_connected_components_is_connected(index1, index2)) {
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }

  return 0;
}
#endif

Measured memory_bytes: 12060
import sys
sys.setrecursionlimit(10**6)

def dfs(prev, now, fromK, t, d):
  d[now] = fromK
  for nl in (t[now]):
    if nl[0] != prev:
      dfs(now, nl[0], fromK+nl[1], t, d)

N = int(input())
T  = [[] for _ in range(N+1)]
for _ in range(N-1):
  a, b, l = map(int, input().split())
  T[a].append([b,l])
  T[b].append([a, l])
Q, K = map(int, input().split())
D = [0] * (N+1)
dfs(-1, K, 0, T, D)
for _ in range(Q):
  x, y = map(int, input().split())
  print(D[x]+D[y])





Measured memory_bytes: 145052
import itertools

[H,W,K] = list(map(int,input().split()))
count=0

c = []
for i in range(H):
    c.append(list(input()))

# print('c',c)

ini=0
for i in range(H):
    for j in range(W):
        if c[i][j]=='#':
            ini+=1
# print('ini',ini)

#gyou=[0]*H
#retu=[0]*W
a = [0,1]
Gs = list(itertools.product(a, repeat=H))
Rs = list(itertools.product(a, repeat=W))

for G in Gs:
    for R in Rs:
        # print('G,R:', G,R)
        l=0
        gyo=0
        for i in G:
            if i==1:
                #行を潰す
                gyo+= c[l].count('#')
            l+=1
        # print('gyo:', gyo)

        #列を潰す
        r=0
        retu=0
        for j in R:
            if j==1:
                #retu=0
                for k in range(H):
                    #print('k,r,c[k][r]:',k,r,c[k][r] )
                    if c[k][r]=='#':
                        retu+=1
            r+=1
        # print('retu:', retu)

        #かぶるやつ
        iii=0
        hiku=0
        for ii in G:
            jjj=0
            for jj in R:
                if ii==1 and jj==1:
                    if c[iii][jjj]=='#':
                        hiku+=1
                jjj+=1
            iii+=1
        # print('hiku:', hiku)

        if ini - (gyo+retu-hiku)==K:
            count+=1
        # print('count:',count)

# print('ini:',ini)
print(count)


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

int main() {
  string number;
  int x;

  cin >> number;

  x = 0;

  for(int i = 0; i <= 2; i++){
     if(number[i] == number[i+1]){
         x++;
     }
  }

  if(x >= 1){
      cout << "Bad" << endl;
  }
  else{
      cout << "Good" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef unsigned long long ULL;
 
template<class T>
inline bool read(T &num)  
{
char in;bool IsN=false;while(in=getchar(),in!='-'&&(in<'0'||in>'9'))if(in==EOF)return false;in=='-'?(IsN=true,num=0):num=in-'0';while(in=getchar(),in>='0'&&in<='9')num=num*10+in-'0';return IsN?num=-num:num,true;
}

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define __m  int mid=l+(r-l)/1
 
const int maxn   = 1e4+7;
const int inf    = 2e9 + 7;
const int mod    = 1e9 + 7;

int road[maxn][maxn];
int main() {
#ifdef LOCAL
    freopen("sample.in", "r", stdin);
#endif
    int n;
    read(n);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            read(road[i][j]);
    bool find=false;
    for(int k=1;k<=n;k++)
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
                if(road[i][j]>road[i][k]+road[k][j])
                    find=true;
    if(find)
        return printf("-1\n"),0;
    LL ans1=0,ans2=0;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        {
            if(i==j)
                continue;
            int k;
            for(k=1;k<=n;k++)
            {
                if(k==i||k==j)
                    continue;
                if(road[i][j]==road[i][k]+road[k][j])
                    break;
            }
            if(k<=n)
                ans1+=road[i][j];
            ans2+=road[i][j];
        }
    printf("%lld\n",(ans2-ans1)/2);
    return 0;
}


Measured memory_bytes: 10752
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 10;

int main() {
	int n;
	while (cin >> n, n) {
		vs s(n);
		REP(i, n) {
			cin >> s[i];
		}

		vi depth(n);
		REP(i, n) {
			REP(j, s[i].size()) {
				if (s[i][j] == '.') {
					depth[i]++;
					s[i][j] = ' ';
				}
				else {
					break;
				}
			}
		}

		REP(i, n) {
			if (depth[i] != 0) {
				s[i][depth[i] - 1] = '+';
				FOR(j, i + 1, n - 1) {
					if (depth[i] > depth[j]) {
						break;
					}
					if (depth[i] == depth[j]) {
						FOR(k, i + 1, j - 1) {
							s[k][depth[i] - 1] = '|';
						}
					}
				}
			}
		}
		REP(i, n) {
			cout << s[i] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1996
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll A[26];
ll ans=1;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string str;
    cin >> str;
    int a=str.length();
for(int i=0;i<a;i++){
      ans+=i;
        A[str[i]-'a']++;}
for(int i=0;i<26;i++)
    ans-=((A[i]-1)*(A[i]))/2;


cout << ans << "\n";
    return 0;
}


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

char foo(char ch){
  if(ch >= 'a' && ch <= 'z')return ch -'a';
  else return ch - 'A'+26;
}

int main(){
  int n, k[200], si, i;
  char temp[200];
  string str;

  for(i =  0; i < 26; i++){temp[i+52] = temp[i] = 'a'+ i;}
  for(; i < 52; i++){ temp[i+52]=  temp[i] = 'A'+ i-26;}
  while(cin>>n && n){
    int now = 0;
    for(int i = 0; i < n; i++)cin>>k[i];
    cin>>str;
    si = str.size();
    for(int i = 0; i < si; i++){
      cout<<temp[foo(str[i])+52-k[now++]];
      if(now == n)now = 0;
    }
    cout<<endl;
  }
  return 0;
}



Measured memory_bytes: 3152
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i <= (int)(n); i++) 
#define dunk(n) cout << n << endl
#define all(a) (a).begin(),(a).end()
typedef pair<int,int> P;
typedef long long ll;

int main() {
   int a,b;
   cin >> a >> b;
   rep(i,10002){
       if(i*2/25 == a && i/10 == b){
           dunk(i);
           return 0;
       }
       if(i == 10001) dunk(-1);
   }
}

Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, A = map(int, read().split())

    print(N * N - A)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9176
a=int(input())

n=[]
for _ in range(a):
    o,q=map(str,input().split())
    n.append([o,int(q)])

m=sorted(n)
m.sort(key=lambda x: (x[0],-x[1]))

for i in m:
    print(n.index(i)+1)

    

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

#define V vector
typedef long long ll;
typedef unsigned long long ull;

typedef V<int> vi;
typedef V<ll> vll;
typedef V<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define f(i,a) for(int i = 0 ; i < a ; i++)
#define fll(i,a) for(ll i = 1 ; i <= a ;i++)
#define forab(i,a,b) for(int i = a ; i < b ; i++)
#define prec(x) cout<<fixed<<setprecision(x)
#define ff first
#define ss second
#define INF 1000000000

#define pb push_back
#define mp make_pair
#define numberofdigits(x) floor(log10(x)) + 1

long long binpow(long long a, long long b) {
	long long res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a;
		a = a * a;
		b >>= 1;
	}
	return res;
}
const int maxn = 1e6;
int fr[maxn + 1] , vis[maxn + 1];

void solve()
{

	int n , ans = 0;
	cin >> n;

	int a[n];
	f(i, n) cin >> a[i] , fr[a[i]]++;

	for (int i = 1 ; i <= maxn ; i++ )
	{
		if (vis[i] == 1 || fr[i] == 0)
			continue;
		if ((vis[i] == 0) && (fr[i] == 1))
			ans++;
		for (int j = i ; j <= maxn ; j += i)
			vis[j] = i;
	}

	cout << ans << "\n";

}



int main() {

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


	int t = 1;
	//cin >> t;


	while (t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 12196
#!/usr/bin/env python

def main():
    n = int(input())
    n %= 10
    h = [2, 4, 5, 7, 9]
    p = [0, 1, 6, 8]
    b = [3]

    if n in h:
        print("hon")
    elif n in p:
        print("pon")
    elif n in b:
        print("bon")


if __name__ == '__main__':
    main()


Measured memory_bytes: 9176
def main():
    N, K = (int(i) for i in input().split())
    V = [int(i) for i in input().split()]
    if 2*N <= K:
        ans = sum(v for v in V if v > 0)
        return print(ans)
    ans = 0
    for a in range(N+1):
        for b in range(N+1):
            if N < a+b:
                continue
            if K < a+b:
                continue
            rest = K - a - b
            cur_e = V[:a]
            if b > 0:
                cur_e += V[-b:]
            cur_e.sort(reverse=True)
            while cur_e and cur_e[-1] < 0 and 0 < rest:
                cur_e.pop()
                rest -= 1
            ans = max(ans, sum(cur_e))

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 39664
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
int calcBitLength(ll n) {
    ll x = n;
    ll ret = 0;
    while (x > 0) {
        ret++;
        x >>= 1;
    }
    return ret;
}
/* main */
int main(){
    int N;
    ll K;
    cin >> N >> K;
    vector<ll> a(N), b(N);
    for (int i = 0; i < N; i++) cin >> a[i] >> b[i];

    int L = calcBitLength(K);
    int upper = 1 << (L-1);

    ll mx = 0LL;
    for (int i = 0; i < N; i++) {
        if ((K | a[i]) == K) mx += b[i];
    }

    // ex)
    // K  = 101100
    // 候補
    // K0 = 011111
    // K[1] = 0 -> x
    // K2 = 100111
    // K3 = 101011
    // K[4] = 0 -> x
    // K[5] = 0 -> x
    int upperK = (1 << L) - 1;
    for (int l = 0; l < L; l++) {
        int d = 1 << (L-1 - l);
        if (K & d) {
            upperK -= d;
            ll sum = 0;
            for (int i = 0; i < N; i++) {
                if ((upperK | a[i]) == upperK) sum += b[i];
            }
            mx = max(mx, sum);
            upperK += d;
        }
        else upperK -= d;
    }

    cout << mx << '\n';
}


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

int max(int a,int b){
  if(a>b) return a;
  else return b;
}
int absolute(int a,int b){
  if(a-b<0) return -(a-b);
  else return a-b;
}
void Yes(){
  cout << "Yes" << endl;
}
void YES(){
  cout << "YES" << endl;
}
void No(){
  cout << "No" << endl;
}
void NO(){
  cout << "NO" << endl;
}
int main(){
  int i,j,N,M,C,number,count;
  count = 0;
  cin >> N >> M >> C;
  vector<int> B(M);
  vector<vector<int>> A(N,vector<int>(M));
  
  for(i=0;i<M;i++){
  	cin >> B.at(i);
  }
  for(i=0;i<N;i++){
  	for(j=0;j<M;j++){
      cin >> A.at(i).at(j);
    }
  }
  
  for(i=0;i<N;i++){
    number = 0;
  	for(j=0;j<M;j++){
      number += A.at(i).at(j) * B.at(j);
    }
    number += C;
    if(number > 0 ) count++;
  }
  
  cout << count << endl;
  
}

Measured memory_bytes: 256
N, M, C = gets.split(' ').map(&:to_i)
B = gets.split(' ').map(&:to_i)
count = 0

N.times do
  sum = 0
  a = gets.split(' ').map(&:to_i)

  M.times do |i|
    sum += a[i] * B[i]
  end

  count += 1 if sum + C > 0
end

puts count

Measured memory_bytes: 1788
# coding: utf-8

def binary_search(key, A):
    left = 0
    right = len(A)
    while left < right:
        mid = int((left + right) / 2)
        if A[mid] == key:
            return mid
        elif key < A[mid]:
            right = mid
        elif key > A[mid]:
            left = mid + 1
    return 'Not Found'

if __name__ == "__main__":
    # n = 5
    # S = list(map(int, '1 2 3 4 5'.split()))
    # q = 3
    # T = list(map(int, '3 4 1'.split()))
    n = int(input())
    S = list(map(int, input().strip().split()))
    q = int(input())
    T = list(map(int, input().strip().split()))

    c = 0
    for k in T:
        if binary_search(k, S) != 'Not Found':
            c += 1
    print(c)

        



Measured memory_bytes: 16716
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

int main(){
    int h,w,n;
    cin >> h >> w >> n;
    int mx = max(h,w);
    cout << (n+mx-1)/mx << endl;
    return 0;
}

Measured memory_bytes: 256