akhauriyash/Code-Regression huggingface dataset:
import copy
n, m = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(n)]
b = [((i+1)*100*name[0] + name[1]) for i, name in enumerate(a)]

ans = []
pat = []
for i in range(2**n):
    pat_c = []
    sum1 = 0
    count1 = 0
    for j in range(n):
        t = (i // 2 ** j) % 2
        pat_c.append(t)
        if  t == 1:
            sum1 += b[j]
            count1 += a[j][0]

    if sum1 < m and 0 in pat_c:
        tyuu1_index = len(pat_c) - pat_c[::-1].index(0) - 1
        tyuu1 = a[tyuu1_index]
        if (tyuu1_index + 1)*100*tyuu1[0] < (m - sum1):
            continue
        else:
            count1 += (m-sum1) // ((tyuu1_index + 1)*100)
            if (m-sum1) % ((tyuu1_index + 1)*100) != 0:
                count1 += 1
        ans.append(count1)
        pat.append(pat_c)
    else:
        ans.append(count1)
        pat.append(pat_c)

print(min(ans))


Measured memory_bytes: 3700
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;

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

int main(){
	int n;
	cin >> n;
	string s;
	vector<string> S;
	rep(i, n) {
		cin >> s;
		sort(s.begin(), s.end());
		S.push_back(s);
	}
	
	sort(S.begin(), S.end());
	// rep(i, n) cout << S[i] << endl;
	string t = S[0];
	long int m = 1;
	long int ans = 0;
	for(int i = 1; i < n; i++){
		if(t == S[i]){
			m++;
		}else{
			if(m != 1){
				ans += (m * (m-1)) / 2;
			}
			m = 1;
			t = S[i];
		}
	}
	if(m != 1){
		ans += (m * (m-1)) / 2;
	}
	cout << ans << endl;
}

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

    int main()
    {
        ll t,n;
         cin>>t>>n;
   vector<string>v(t);
for(int i=0;i<t;i++){
            cin>>v[i];
        }
        sort(v.begin(),v.end());
        for(int i=0;i<t;i++){
            cout<<v[i];
        }
        return 0;
    }


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

def main():
    N, K = map(int, readline().rstrip().split())
    A = list(map(int, readline().rstrip().split()))
    d = {i+1: a for i, a in enumerate(A)}
    if K <= N:
        pre = 1
        for _ in range(K):
            pre = d[pre]
        print(pre)
        return

    pre = 1
    visited = set([1])
    visited_l = [1]
    for i in range(N):
        pre = d[pre]
        if pre in visited:
            break
        visited.add(pre)
        visited_l.append(pre)
    
    loop_start = visited_l.index(pre)
    loop = i - loop_start + 1

    num_loop = (K - loop_start) // loop
    now = loop_start + num_loop * loop
    for i in range(now+1, K+1):
        pre = d[pre]
    
    print(pre)

if __name__ == '__main__':
    main()

Measured memory_bytes: 49300
#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
  char a[6];
  int i;
  
  for (auto i = 0; i <= 5; i++) {
		cin >> a[i];
  }
  
  if(a[2] == a[3]){
    if(a[4] == a[5]){
      cout << "Yes";
    }else{
      cout << "No";
    }}else{
   cout << "No";}
  
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int unsigned long long
#define endl '\n'
using namespace std;
typedef long long ll;

signed main() 
{
	int n, k, cnt = 0;
	cin >> n >> k;
	int down = (n*(n - 1))/2;
	vector<pair <int, int>> l;
	
	if (k > ((n - 1)*(n - 2))/2) {cout << -1; return 0;}
	
	for (int i = 1; i <= n; i++)
	{
		for (int j = i + 1; j <= n; j++)
		{
			l.push_back({i, j});
			cnt++;
			down--;
			if (down == k) goto meow;
		}
	}
	
	meow:
	cout << cnt << endl;
	for (auto i: l) cout << i.first << " " << i.second << endl;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = Integer.parseInt(sc.nextLine());
			for (int i = 0; i < n; i++) {
				System.out.println( inning() );
			}

	}

	private static int inning() {
		int score = 0;
		boolean[] base = new boolean[4];
		int o = 0;
		String event = "";

			for (; o < 3 ;) {
				event = sc.nextLine();

				switch (event) {
					case "HIT":
						for (int i = 3; i > 0; i--) {
							if (base[i]) {

								if (i == 3) {
									score++;
								} else {
									base[i + 1] = true;
								}

								base[i] = false;
							}
						}
						base[1] = true;
						break;

					case "HOMERUN":
						for (int i = 1; i < 4; i++) {
							if (base[i]) {
								score++;
								base[i] = false;
							}
						}
						score++;
						break;

					case "OUT":
						o++;
						break;
				}
			}
		return score;
	}
}



Measured memory_bytes: 26360
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
#define P pair<int,int>
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
using namespace std;

signed main(){
    int n;
    cin >> n;
    vec(a,n);
    REP(i,n){
        cin >> a[i];
    }
    int x=0,b=0,t=0;
    REP(i,n){
        t += a[i];
        if(i%2 == 0){
            if(t>=0){
                x += abs(t)+1;
                t = -1;
            }
        }
        else{
            if(t<=0){
                x += abs(t)+1;
                t = 1;
            }
        }
    }
    t=0;
    REP(i,n){
        t += a[i];
        if(i%2 == 0){
            if(t<=0){
                b += abs(t)+1;
                t = 1;
            }
        }
        else{
            if(t>=0){
                b += abs(t) +1;
                t = -1;
            }
        }
    }
    int ans=min(x,b);
    cout << ans;
    return 0;
}


Measured memory_bytes: 1024
while True:
    a,b=map(int,input().split())
    if a==0 and b==0: break
    s=[int(input()) for _ in range(a)]
    S=sum(s[0:b])
    ss=[S]
    for i in range(b,a):
        S=S+s[i]-s[i- b]
        ss.append(S)
    print(max(ss))


Measured memory_bytes: 11700
///
// File:  c.cpp
// Author: ymiyamoto
//
// Created on Sat Nov  4 02:11:18 2017
//

#include <cstdint>
#include <iostream>
#include <string>
using namespace std;

int32_t main()
{
  string S, T;
  cin >> S;
  cin >> T;

  int32_t index = -1;
  for (uint32_t i = 0; i < S.size(); i++) {
    uint32_t j;
    for (j = 0; j < T.size(); j++) {
      if (i + j < S.size() && (S[i + j] == '?' || S[i + j] == T[j])) {
      } else {
        break;
      }
    }

    if (j == T.size()) {
      index = i;
    }
  }

  if (index == -1) {
    cout << "UNRESTORABLE" << endl;
  } else {
    for (uint32_t j = 0; j < T.size(); j++) {
      S[index + j] = T[j];
    }

    for (uint32_t i = 0; i < S.size(); i++) {
      cout << (S[i] == '?' ? 'a' : S[i]);
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n=0;
    int x=0;
    cin>>n;
    for(int i=1;i<=9;i++)
    {
        if(x==1)
        {
            break;
        }
        for(int i2=1;i2<=9;i2++)
        {
            if(i*i2==n)
            {
               x++;
               break;
            }
            else
            {
                x=x;
            }
        }
    }
    if(x==1)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    return 0;
}


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

int main(){
        int n,i,A,B,tmp,ans=0;
        cin >> n;
        vector<int> a(n);
        vector<int> l(n);
        vector<int> r(n);
        for(i=0;i<n;++i) cin >> a.at(i);
        for(i=0;i<n-1;++i){
                B = max(a.at(i),l.at(i));
                A = min(a.at(i),l.at(i));
                while(A!=0){
                        tmp = B%A;
                        B = A;
                        A = tmp;
                }
                l.at(i+1) = B;
                B = max(a.at(n-1-i),r.at(n-1-i));
                A = min(a.at(n-1-i),r.at(n-1-i));
                while(A!=0){
                        tmp = B%A;
                        B = A;
                        A = tmp;
                }
                r.at(n-2-i) = B;
        }
        for(i=0;i<n;++i){
                B = max(l.at(i),r.at(i));
                A = min(l.at(i),r.at(i));
                while(A!=0){
                        tmp = B%A;
                        B = A;
                        A = tmp;
                }
                ans = max(ans, B);
        }
        cout << ans << endl;
        return 0;
}

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

int main() {
    int N , M ;
    cin >> N >> M ; // 0 ≤ N,M ≤ 100 2 ≤ N+M
    cout << (N*(N-1))/2 + (M*(M-1))/2 <<endl;
	return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcdEx(ll a, ll b, ll *x, ll *y) {
    if (!a) {*x = 0; *y = 1; return b;}
    ll x1, y1, gcd = gcdEx(b % a, a, &x1, &y1); *x = y1 - (b / a) * x1; *y = x1; return gcd;
}
ll modI(ll b, ll m)      {ll x, y; gcdEx(b, m, &x, &y); return (x % m + m) % m;}
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())

#define sum(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a)    (*min_element((a).begin(), (a).end()))
#define maxe(a)    (*max_element((a).begin(), (a).end()))
#define mini(a)    ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a)    ( max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define MOD                 1000000007
#define modA(a,b)           (((a%MOD)+(b%MOD))%MOD)
#define modS(a,b)           (((((a%MOD)-(b%MOD))%MOD)<0)?(ll)(MOD+((a%MOD)-(b%MOD))%MOD):(ll)(((a%MOD)-(b%MOD))%MOD))
#define modM(a,b)           (ll)((((ll)(a%MOD))*((ll)(b%MOD)))%MOD)
#define modD(a,b)           ((modI(b,MOD)*(a%MOD))%MOD)
ll modP(ll x, ll y)         {
    ll r = 1; x %= MOD; while (y > 0) {
        if (y & 1) {r = (r * x) % MOD;}
        y = y >> 1; x = (x * x) % MOD;
    } return r;
}
ll max(ll a, ll b) {return (a > b ? a : b);}
ll min(ll a, ll b) {return (a < b ? a : b);}
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " = " << arg1 << " | "; __f(comma + 1, args...);
}
ll gcd( ll a, ll b )
{
    if (b == 0)
    {
        return a;
    }
    else
    {
        return gcd( b, (a % b) );
    }
}
ll lcm (ll a, ll b)
{
    ll ans = (a  / gcd(a, b)) * b;
    return ans;
}
void solve()
{
    ll ans = 0;
    ll l, r, d;
    cin >> l >> r >> d;
    ans = (r / d) - (l - 1) / d;
    cout << ans << "\n";
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t ;
    t = 1;
  //  cin >> t;
    while (t--)
        solve();
    return 0;
}





Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
constexpr int INF = 1001001001;
constexpr long long INFL = (1LL<<60);
constexpr double eps = (1e-9);

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

  int n;
  cin >> n;
  ll sum = 0;
  map<ll, ll> mp;
  rep(i, n){
    ll a; cin >> a;
    mp[a]++;
    sum += a;
  }

  int q;
  cin >> q;
  rep(i, q) {
    ll b, c;
    cin >> b >> c;
    int num = mp[b];
    sum -= b * num;
    mp[b] = 0;
    mp[c] += num;
    sum += c * num;
    cout << sum << endl;
  }

  return 0;
}


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

A = N // 1000
B = (N - 1000 * A) // 100
C = (N - 1000 * A - 100 * B) // 10
D = N % 10

for i in range(2):
  for j in range(2):
    for k in range(2):
      ans = A
      if i==1:
        op1 = '+'
        ans += B
      else:
        op1 = '-'
        ans -= B
      if j==1:
        op2 = '+'
        ans += C
      else:
        op2 = '-'
        ans -= C
      if k==1:
        op3 = '+'
        ans += D
      else:
        op3 = '-'
        ans -= D
      if ans==7:
        print(str(A)+op1+str(B)+op2+str(C)+op3+str(D)+'=7')
        break
    else:
      continue
    break
  else:
    continue
  break


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

using namespace std;

int main()
{
   char ch[100000+5];
   cin>>ch;
   int len=strlen(ch);
   int ans[len];
   memset(ans,0,sizeof(ans));
   for(int i=0;i<len;i++)
   {
       if(ch[i]=='R')
       {

           for(int j=i+1;j<len;j++)
          {
              if(ch[j]=='L')
              {
                 if((j-i)%2==0)
                    {
                        ans[j]+=(j-i)/2;
                        ans[j-1]+=(j-i)/2;
                    }
                 else
                    {
                        ans[j]+=(j-i)/2;
                        ans[j-1]+=(j-i)/2+1;
                    }
                 i=j-1;
                 break;
              }
          }
       }
   }
   for(int i=len-1;i>=0;i--)
   {
       if(ch[i]=='L')
       {

           for(int j=i-1;j>=0;j--)
          {
              if(ch[j]=='R')
              {
                 if((i-j)%2==0)
                    {
                        ans[j]+=(i-j)/2;
                        ans[j+1]+=(i-j)/2;
                    }
                 else
                    {
                        ans[j]+=(i-j)/2;
                        ans[j+1]+=(i-j)/2+1;
                    }
                 i=j+1;
                 break;
              }
          }
       }
   }
   for(int i=0;i<len;i++)
    cout<<ans[i]<<" ";
}


Measured memory_bytes: 896
def main():
    buf = input()
    buflist = buf.split()
    N = int(buflist[0])
    P = int(buflist[1])
    factor = prime_factorization(P)
    max_gcd = 1
    for f, c in factor.items():
        while c >= N:
            max_gcd *= f
            c -= N
    print(max_gcd)

def prime_factorization(number):
    n = number
    i = 2
    factor = {}
    while i * i <= n:
        while n % i == 0:
            if i in factor:
                factor[i] += 1
            else:
                factor.update({i : 1})
            n //= i
        i += 1
    if n > 1 or not factor:
        if n in factor:
            factor[n] += 1
        else:
            factor.update({n : 1})
    return factor

if __name__ == '__main__':
    main()


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

void dfs(int v, int c, int root, vector<int> &color, vector<vector<int>> &vs, vector<vector<pair<int,int>>> &adj){
    if(color[v] != -1) return;
    color[v] = c;
    vs.back().push_back(v);
    for(auto next: adj[v]){
        int nv = next.first;
        int nc = (next.second == 0)? c: 1-c;
        dfs(nv, nc, root, color, vs, adj);
    }
}

int main(){
    while(1){
        int n,a,b;
        cin >> n >> a >> b;
        if(n+a+b == 0) break;

        vector<vector<pair<int,int>>> adj(a+b);
        for(int i=0; i<n; i++){
            int x,y;
            string s;
            cin >> x >> y >> s;
            x--; y--;
            int c = (s=="yes")? 0: 1;
            adj[x].emplace_back(y, c);
            adj[y].emplace_back(x, c);
        }
        vector<int> color(a+b, -1);
        vector<vector<int>> vs;
        for(int i=0; i<a+b; i++){
            if(color[i] != -1) continue;
            vs.emplace_back();
            dfs(i, 0, i, color, vs, adj);
        }
        vector<vector<int>> nums;
        for(auto v: vs){
            nums.emplace_back(2, 0);
            for(auto i: v){
                nums.back()[color[i]]++;
            }
        }
        
        int m = vs.size();
        vector<vector<int>> dp(m+1, vector<int>(a+b+1, 0));
        dp[0][0] = 1;
        for(int i=0; i<m; i++){
            for(int j=0; j<a+b; j++){
                if(dp[i][j]==0) continue;
                dp[i+1][j+nums[i][0]] |= 1;
                dp[i+1][j+nums[i][1]] |= 2;
                if(dp[i][j] == 3){
                    dp[i+1][j+nums[i][0]] = 3;
                    dp[i+1][j+nums[i][1]] = 3;
                }
            }
        }
        if(dp[m][a]==1 or dp[m][a]==2){
            vector<int> ans;
            int curr = a;
            for(int i=m; i>0; i--){
                int state = dp[i][curr] -1;
                for(int v: vs[i-1]){
                    if(color[v] == state){
                        ans.push_back(v);
                    }
                }
                curr -= nums[i-1][state];
            }
            sort(ans.begin(), ans.end());
            for(int i: ans){
                cout << i+1 << endl;
            }
            cout << "end" << endl;
        }else{
            cout << "no" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    const int A = 26;
    const int M = 1e5;
    int D; cin >> D;
    vector<int> c(A);
    REP(i,A) cin >> c[i];
    vector<vector<int>> s(D,vector<int>(A));
    REP(i,D) REP(j,A) cin >> s[i][j];

    vector<int> last(A,-1);
    vector<int> ans(D);
    REP(i,D) {
        int mx = 0,a = -1;
        REP(j,A) {
            int tmp = (i-last[j])*c[j] + s[i][j];
            if (mx < tmp) {
                mx = tmp;
                a = j;
            }
        }
        ans[i]=a;
        last[a] = i;
    }
    auto calc = [&](const vector<int> &a){
        vector<int> l(A,-1);
        int score = 0;
        REP(i,D) {
            score += s[i][a[i]];
            l[a[i]] = i;
            REP(j,A) {
                score -= c[j]* (i-l[j]);
            }
        }
        return score;
    };

    int maxscore = calc(ans);

    random_device seed_gen;
    mt19937 engine(seed_gen());
    REP(_,M) {
        vector<int> a(ans);
        a[engine()%D] = engine() % A;
        int tmp = calc(a);
        if (maxscore < tmp) {
            swap(ans,a);
            maxscore = tmp;
        }
    }

    REP(i,D) OUT(ans[i]+1)

    return 0;
}

Measured memory_bytes: 3724
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<string>
#include<queue>
#include<utility>
#include<cmath>
#include<sstream>
#include<istream>

using namespace std;


int main()
{
  long long int A, B, r, x, tmp;

  cin >> A >> B;

  x = A * B;

  if(A<B){
    tmp = A;
    A = B;
    B = tmp;
  }

  r = A % B;
  while(r!=0){
    A = B;
    B = r;
    r = A % B;
  }

  cout << x/B << endl;


  return 0;
}


Measured memory_bytes: 256
from itertools import permutations
N=int(input())
P=list(map(int,input().split()))
Q=list(map(int,input().split()))
np,nq=0,0
for i,V in enumerate(permutations(range(1,N+1))):
    tmp=list(V)
    if all(p==v for p,v in zip(P,V)):
        np=i
    if all(q==v for q,v in zip(Q,V)):
        nq=i
print(abs(np-nq))

Measured memory_bytes: 3064
#include <stdio.h>

int main(){
  char num[4];
  if(scanf("%s",num)==1){}
  
  int i;
  int a=1;
  for(i=0;i<3;i++){

    if(num[i]==num[i+1]){
      printf("Bad");
      a=0;
      break;
    }
  }
  
  if(a==1)printf("Good");
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

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


template <typename T>
T amarinasi(T a,T b){
    if(a%b==0)
{
    return a/b;
}
else if(a%b>0)
{
    return a/b+1;
}
else
{
    return a/b-1;
}
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------

int main(){
string s;
cin>>s;
ll cnt=0;
cout<<s[0];
cout<<s.size()-2;
cout<<s[s.size()-1];
}












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

int64_t N;
int X, M;

int Acnt = 0;
int A[114514];
int64_t Asum[114514];

int deta[114514];

int main(void) {
	int i;
	if (scanf("%" SCNd64 "%d%d", &N, &X, &M) != 3) return 1;
	if (N == 1) {
		printf ("%d\n", X);
		return 0;
	}
	A[0] = X;
	Asum[0] = A[0];
	deta[X] = 1;
	Acnt = 1;
	for (;;) {
		int tugi = (int)(((int64_t)A[Acnt - 1] * A[Acnt - 1]) % M);
		if (deta[tugi]) {
			int end = Acnt;
			int start = deta[tugi] - 1;
			int count = end - start;
			int offset = start;
			int64_t lcount = N - offset;
			int64_t lnum = lcount / count;
			int lleft = (int)(lcount % count);
			int64_t lsum = Asum[end - 1] - (start > 0 ? Asum[start - 1] : 0);
			int64_t answer = start > 0 ? Asum[start - 1] : 0;
			answer += lsum * lnum;
			if (start + lleft - 1 > 0) {
				answer += Asum[start + lleft - 1] - (start > 0 ? Asum[start - 1] : 0);
			}
			printf("%" PRId64 "\n", answer);
			return 0;
		} else {
			A[Acnt] = tugi;
			Asum[Acnt] = Asum[Acnt - 1] + A[Acnt];
			Acnt++;
			deta[tugi] = Acnt;
			if (Acnt == N) {
				printf("%" PRId64 "\n", Asum[Acnt - 1]);
				return 0;
			}
		}
	}
}


Measured memory_bytes: 2712
#include<iostream>
#include<ctype.h>
#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
inline int read(){
	int x=0,f=0;char ch=getchar();
	while(!isdigit(ch))f|=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+(ch^48),ch=getchar();
	return f?-x:x;
}
int a[500007],maxn;
int main(){
    int n=read();
    while(n--){
        int x=read();a[x]++,a[x-1]++,a[x+1]++;
    }
    for(int i=0;i<=500000;i++)maxn=max(maxn,a[i]);
    cout<<maxn<<"\n";
    return 0;
 } 

Measured memory_bytes: 640
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>

using namespace std;

int main(){
  int N, a;
  cin >> N;
  int ans = 0;
  vector<int> vec(N);

  for (int i = 0; i < N; i++){
    cin >> a;
    vec.at(i) = a;
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());

  for (int i = 0; i < N; i++){
    if (i > 0){
      if (i % 2 == 0){
        ans = ans + vec.at(i);
      } else {
        ans = ans - vec.at(i);
      }
    } else {
      ans = vec.at(i);
    }
  }

  cout << ans << 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;
using ll = long long;

int main()
{
    ll n, ans = 0;
    cin >> n;
    rep(i, n - 1) ans += i + 1;
    cout << ans << endl;
    return 0;
}

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

using in = int64_t;

int main(){
in n,m;
  cin >>n>>m;
priority_queue<double> a;
  rep(i,n){ 
    double z;
    cin>>z;
    a.push(z);
  }//n
  //sort(a.begin(),a.end());
  
  rep(i,m){
    double x = a.top();
    a.pop();
    a.push(x/2);
    /*if(a.at(n-1)<a.at(n-3)){
      sort(a.begin(),a.end());
    }
    else if(a.at(n-1)<a.at(n-2)){
    double x,y;
      x= a.at(n-1);
      y = a.at(n-2);
      a.at(n-1) = y;
      a.at(n-2) = x;
    }*/
  }//mSORT
  
  in ans =0;
  rep(i,n){
  ans += (in)a.top();
    a.pop();
  }
  
  cout <<ans<<endl;
}


Measured memory_bytes: 1400
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

int main(void){
	ll n;
	cin >> n;

	ll ans = 0;
	repn(i, n){
		if(i % 3 && i % 5) ans += i;
	}
	co(ans);

	return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main (){
  int a,b[110],c;
  cin >> a;
  
  for(int i=0;i<a;i++)
    cin >> b[i];
  
  c =0;
  for(int i=1;i<a;i++){
    if(b[i] ==b[i-1]){
      b[i] = 0;
      c++;
    }
  }
  cout << c << endl;
  
  return 0;
}
  
    


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

int main()
{
 	int A,B,C,D;
  	cin >> A >> B >> C >> D;

  	int E,F;

  	E = C - B;
  	F = A - D;

  	if(C == A){
  		if(E > F){
        	cout << "No";
        }
      else{
      	cout << "Yes";
      }
    }

else{
    int a = 0;
    int b = 0;

  	while(E > 0){
      E = E - B;
        a++;
      }


  	while(F > 0){
      F = F - D;
		  b++;
	  }

   if(a > b){
    cout << "No";
  }

  else{
      cout << "Yes";
    }

  }

}

Measured memory_bytes: 3636
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <math.h>

using namespace std;




int main(int argc, char *argv[])
{
	string s, t;

	cin >> s;
	cin >> t;

	int length = s.length();

	string ans = "No";
	for (int i = 0; i < s.length(); i++){
		bool flag = true;
		for (int j = 0; j < s.length(); j++){
			if (s[j] == t[(j + i) % s.length()]){
				continue;
			}
			else{
				flag = false;
				break;
			}
		}

		if (flag){
			ans = "Yes";
			break;
		}
	}


	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
### SNIPPET
  # n = gets.split.map(&:to_i)
  # array = n.times.map { gets.split.map(&:to_i) }
  # [].all?(&:even?)
  # a = [*1..m].repeated_combination(n).to_a
  # [1,2,3,4,5].select { |num| num.even? }  # => [2, 4]
  # ["a","a","b"].group_by(&:itself).map{|k,v| [k, v.count]}.to_h #=> {"a"=>2, "b"=>1}
  # 切り捨て: .floor(2).to_f ,切り上げ： .ceil(2).to_f,四捨五入: round(2)
  # 3.upto(6) do |i|, 6.downto(3) do |i|
  # 公約数125.gcd(100)、公倍数125.lcm(100)
  # PI = Math::PI
  # 高さ = a * Math.sin(w / 180.0 * Math::PI), 底辺 = a * Math.cos(w / 180.0 * Math::PI)
  # def chmax(a, b) a > b ? a : b end
  # INF = Float::INFINITY
  # def chmin(a, b) a < b ? a : b end

d,t,s = gets.split.map(&:to_i)

puts d <= s * t ? "Yes" : "No" 

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

using namespace std;

long long a,b;

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

cin >> a >> b;

if (a%b == 0)
	cout << a/b;
else
	cout << (a/b)+1;


return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1 ; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1 ; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const bool debug = 0;
/***************************************/

int M, Nmi, Nma;
int P[200];

int main() {
  while (cin >> M >> Nmi >> Nma, M || Nmi || Nma) {
    REP(i, M) scanf("%d", P + i);
    if (debug) putchar('@');

    pii ans(0, 0); // ギャップ, 人数

    FOR(i, Nmi - 1, Nma) {
      chmax(ans, pii(P[i]-P[i+1], i + 1));
    }

    cout << ans.se << endl;
  }
  return 0;
}


Measured memory_bytes: 3128
#include<time.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
using namespace std;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

template<typename ...Ts>
void show(Ts... ts){
  cout<<"#:";
  auto print=[](auto v){cout<<v<<" ";};
  initializer_list<int>{(void(print(ts)),0)...};
  cout<<endl;
}

int main(void){
    int n;
    cin>>n;
    vi a(n);
    ll ans=0;
    
    rep(i,n){
        cin>>a[i];
        a[i]-=i;
        ans+=a[i];
    }
    
    sort(a.begin(),a.end());
    
    int m=(a[n/2]+a[n/2-1])/2;
    if (n%2==1)m=a[n/2];
    ans=0;
    rep(i,n){
        ans+=abs(a[i]-m);
    }
    if (n==1)ans=0;
    cout<<ans;
}






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

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> p(m);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    p[i] = make_pair(b, a);
  }
  sort(p.begin(), p.end());
  int res = 0;
  int end = 0;
  for (int i = 0; i < m; ++i) {
    if (end <= p[i].second) { 
      end = p[i].first;  
      res++;
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,ju;
	cin>>a>>b;
	ju=b-a+1;
	if(a>0)
	{
		cout<<"Positive"<<endl;
		return 0;
	}
	if(a<0&&b<0&&ju%2==1)
	{
		cout<<"Negative"<<endl;
		return 0;
	}
	if(a<=0&&b>=0)
	{
		cout<<"Zero"<<endl;
		return 0;
	}
	cout<<"Positive"<<endl;
	return 0;
 }


Measured memory_bytes: 256
#include <cstring>
#include <cstdio>
#include <algorithm>
const int MAXN = 105;
using namespace std;

int N, G[MAXN][MAXN], linky[MAXN], linkx[MAXN];
bool vis[MAXN];

inline bool match(int u) {
    int v;
    for(v = 1; v <= N; v++) if(G[u][v] && !vis[v]) {
        vis[v] = 1;
        if(!linky[v] || match(linky[v])) {
            linkx[u] = v;
            linky[v] = u;
            return 1;
        }
    }
    return 0;
}

int XA[MAXN], YA[MAXN], XB[MAXN], YB[MAXN];
int main() {
    int i, a, b;
    scanf("%d", &N);
    for(i = 1; i <= N; i++) scanf("%d%d", &XA[i], &YA[i]);
    for(i = 1; i <= N; i++) scanf("%d%d", &XB[i], &YB[i]);

    for(a = 1; a <= N; a++) for(b = 1; b <= N; b++) {
        G[a][b] = XA[a] < XB[b] && YA[a] < YB[b];
    }

    int Ans = 0;
    for(i = 1; i <= N; i++) if(!linkx[i]) {
        memset(vis, 0, sizeof(vis));
        Ans += match(i);
    }
    printf("%d", Ans);
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int[][] a = new int[10][10];
 
   int ans = 0;
   int tmpa=0;
   int tmpb=0;
   for(int i=1;i<=N;i++)
   {
     tmpa=i;
     tmpb=i;
     tmpa=tmpa%10;
     while(tmpb>=10)
     {
       tmpb/=10;
     }
     a[tmpa][tmpb]++;
   }
   
   for(int i =1; i<=9;i++)
   {
     for(int k =1;k<=9;k++) ans+= a[i][k]*a[k][i];
   }
   System.out.println(ans);
 }
}

Measured memory_bytes: 21972
#include<iostream>
#include<string>
#include<cmath>

using namespace std;


int main() {
	int N, a[100];
	int minCost = 100000000;
	int minA = 101 ,maxA = -101;

	cin >> N;
	for (int i = 0; i < N; i++) {
		int input;
		cin >> input;
		a[i] = input;
		if (input < minA) {
			minA = input;
		}
		if (input > maxA) {
			maxA = input;
		}
	}
	for (int j = minA; j <= maxA; j++) {
		int currentCost = 0;
		for (int i = 0; i < N; i++) {
			currentCost += pow(a[i] - j, 2.0);
		}
		if (currentCost < minCost) {
			minCost = currentCost;
		}
	}
	cout << minCost << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int inf = 1 << 20;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using namespace std;

int main()
{
    int n;
    cin >> n;
    int a[n],b[n];
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
    }
    ll ans = 0;
    for(int i = n-1; i >= 0; i--){
        if((a[i]+ans) % b[i] == 0) continue;
        else{
            ll m = (a[i]+ans) % b[i];
            ans += (b[i]-m);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
// ABC110_B
#include <iostream>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <tuple>  // std::tuple std::get
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;

#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define MIN(vec) min_element(vec.begin(), vec.end())  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(vec.begin(), vec.end())
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(vec.begin(), vec.end(), 0LL)  // 0 は初期値

int main() {
    // input
    ll N, M, X, Y;
    cin >> N >> M >> X >> Y;
    vector<ll> vec_X(N), vec_Y(M);
    REP(i, N) cin >> vec_X[i];
    REP(i, M) cin >> vec_Y[i];
    
    // calculation
    ll max_X = *MAX(vec_X);
    ll min_Y = *MIN(vec_Y);
    if (max_X < min_Y && X <= max_X && min_Y <= Y) {
        cout << "No War" << "\n";
    } else {
        cout << "War" << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){

  int n;
  cin>>n;

  int a[n][n];
  if(n%2==0){
  REP(i,n){
    REP(j,n){
      a[i][j] = 1;
      if(i==j||i==n-j-1){
        a[i][j] = 0;
      }
    }
  }
}else{
  REP(i,n){
    REP(j,n){
      a[i][j] = 1;
      if(i==j||i==n-j-2){
        a[i][j] = 0;
      }
    }
  }
}

  int m = 0;
  REP(i,n){
    REP(j,n){
      if(i==j)break;
      if(a[i][j]==1)m++;
    }
  }

  cout<<m<<endl;

  REP(i,n){
    REP(j,n){
      if(i==j)break;
      if(a[i][j]==1){
        cout<<i+1<<" "<<j+1<<endl;
      }
    }

  }
 

  return 0;
}

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

int main() {
  long long int n,a,b;
  cin >> n >> a >> b;
  if (n%(a+b)==0){
    long long int count1 = n/(a+b);
      cout << count1*a << endl;
  }
  else{
    long long int ans = 0;
    long long int count2 = n/(a+b);
    ans += count2*a;
      if (n-count2*(a+b) <= a){
        ans += n-count2*(a+b);
      }
      else{
        ans += a;
      }
      cout << ans << endl;
  }
}


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

// ABC121B - Can you solve this?
// https://atcoder.jp/contests/abc121/tasks/abc121_b
void ABC121B() {

	/*
		
	*/
	int N, M, C;
	cin >> N >> M >> C;

	vector<int> B(M);
	for (int i = 0; i < M; i++)
	{
		cin >> B[i];
	}

	int ans = 0;
	vector<vector<int>> A(N, vector<int>(M));
	for (int i = 0; i < N; i++)
	{
		int sum = 0;
		for (size_t j = 0; j < M; j++)
		{
			cin >> A[i][j];
			sum += A[i][j] * B[j];
		}

		if (sum + C > 0) {
			ans++;
		}
	}

	cout << ans << endl;
}

int main() {
	ABC121B();

	return 0;
}

Measured memory_bytes: 256
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    [N, K] = string_to_int(inputs[0])
    A = string_to_int(inputs[1])
    counter = collections.Counter(A)
    i = len(counter)
    values = counter.most_common()
    change_num = 0
    while i > K:
        change_num += (values[i-1][1])
        i -= 1
    return change_num


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(2))
    print(ret)


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    ll ans = 0;
    unordered_map<ll, ll> cnt;
    rep(i, N) {
        ll a = A[i];
        rep(j, 61) {
            if (a & (1LL << j)) {
                cnt[j]++;
            }
        }
    }
    rep(i, N) {
        ll a = A[i];
        rep(j, 61) {
            if (a & (1LL << j)) {
                cnt[j]--;
            }
        }
        rep(j, 61) {
            if (a & (1LL << j)) {
                ll tmp = 1LL << j;
                tmp %= MOD;
                ll mul = N - (i + 1) - cnt[j];
                ans += tmp * mul;
                ans %= MOD;
            } else {
                ll tmp = 1LL << j;
                tmp %= MOD;
                ll mul = cnt[j];
                ans += tmp * mul;
                ans %= MOD;
            }
        }
    }
    cout << ans % MOD << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 2560
N,Q=map(int,input().split())
S=list(input())
answers=[0 for _ in range(N)]
for n in range(1,N):
    if S[n]=='C':
        if S[n-1]=='A':
            answers[n]=answers[n-1]+1
        else:
            answers[n]=answers[n-1]
    else:
        answers[n]=answers[n-1]


for _ in range(Q):
    l,r=map(int,input().split())
    print(answers[r-1]-answers[l-1])


Measured memory_bytes: 83936
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long int;
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 (b<a) { a=b; return 1; } return 0; }
const ll INF = 1e11;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
int main(){
    ll n,k,t,d;
    P sushi[100005];
    bool neta[100005] = {0};
    cin >> n >> k;
    rep(i,n){
        cin >> t >> d;
        sushi[i] = P(d,t);
    }
    sort(sushi,sushi+n,greater<P>());
    priority_queue<P,vector<P>,greater<P>> q1;
    priority_queue<P> q2;
    ll ans[100005] = {0};
    ll x = 0,c = 0;
    rep(i,k){
        if (neta[sushi[i].second]) q1.push(sushi[i]);
        else{
            neta[sushi[i].second] = true;
            x++;
        }
        ans[0] += sushi[i].first;
    }
    rep(i,k,n){
        if (!neta[sushi[i].second]){
            q2.push(sushi[i]);
            neta[sushi[i].second] = true;
        }
    }
    while(!q2.empty() && !q1.empty()){
        ans[c+1] = ans[c]+q2.top().first-q1.top().first;
        q1.pop();q2.pop();
        c++;
    }
    ll a = 0;
    rep(i,c+1){
        chmax(a,ans[i]+(x+i)*(x+i));
    }
    PRINT(a);
}

Measured memory_bytes: 3960
#include<bits/stdc++.h>
using namespace std;
#define M 1000000000000;
int main()
{
    long long int n,W,i,j;
    cin>>n>>W;
    long long int w[n],v[n],sum=0;
    for(i=0;i<n;i++)
    {
        cin>>w[i]>>v[i];
        sum+=v[i];
    }

    long long int dp[n+1][sum+1];
    for(i=0;i<=sum;i++)
        dp[0][i]=1000000000000;
    for(i=0;i<=n;i++)
        dp[i][0]=0;
    for(i=1;i<=n;i++)
        for(j=1;j<=sum;j++)
            dp[i][j]=0;

    for(i=1;i<=n;i++)
    {
        for(j=1;j<=sum;j++)
        {
            if(v[i-1]>j)
                dp[i][j]=dp[i-1][j];
            else
                dp[i][j]=min(w[i-1]+dp[i-1][j-v[i-1]],dp[i-1][j]);
        }
    }

    for(i=sum;i>=0;i--)
    {
        if(dp[n][i]<=W && dp[n][i]!=1000000000000)
            break;
    }

    cout<<i<<endl;
    return 0;
}


Measured memory_bytes: 79104
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (int i = j; i < (n); i++)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define out(ans) cout << ans << endl
typedef pair<int,int>P;
const ll mod=1e9+7;

int N, A, B, H[101010];

bool check(ll x) {
  ll c = 0;
  rep(i, 0, N) {
      ll h = 1LL * H[i] - 1LL * x * B;
      if (h <= 0) continue;
      c += h / A;
      if (h % A) c++;
  }
  return c <= x;
}

int main() {
  cin >> N >> A >> B;
  A -= B;
  rep(i, 0, N) cin >> H[i];

  int ng = 0, ok = 1010101010;
  while (ng + 1 != ok) {
      int x = (ng + ok) / 2;
      if (check(x)) ok = x;
      else ng = x;
  }
  cout << ok << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
   int n,s,i,a,b,c;
   while(cin >> n) {
	   s=0;
	   i= n>2000 ? n-2000 : 0;
	   c= n<2001 ? n : 2000; 
	   for (i;i<=c;i++) {
		   a= i<1001 ? i+1 : 2000-i+1;
		   b= (n-i)<1001 ? n-i+1 : 2000-(n-i)+1;
           s=s+a*b;
	   }
	   cout << s << endl;
   }
   return 0;
}

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

int main() {

    int X;
    cin >> X;

    int coin500, coin5;

    coin500 = X / 500;

    coin5 = (X % 500) / 5;
    int sum = coin500 * 1000 + coin5 * 5;

    cout << sum << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iterator>
#include <cstdio>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <chrono>
#include <functional>

using namespace std;
using lli = long long int;
using ulli = unsigned long long int;

namespace atcoder {
	void judge_outer(bool judge_exp, string ok = "Yes", string ng = "No")
	{
		if (judge_exp) {
			cout << ok << endl;
		}
		else {
			cout << ng << endl;
		}
	}

	int ncr(int left, int right)
	{
		right = min(left - right, right);
		int ans = 1;
		for (int i = 1; i <= right; i++) {
			ans = ans * (left - right + i) / i;
		}
		return ans;
	}

	const int LIMIT = 1000000256;
	const int tenfive = 100100;
}

using namespace atcoder;

int main()
{
	string a;
	ulli b;
	cin >> a;
	cin >> b;
	ulli one_count = 0;
	for (int i = 0; i < a.size(); i++) {
		if (a[i] == '1') {
			one_count++;
		}
		else {
			break;
		}
	}
	if (one_count >= b) {
		cout << 1 << endl;
	}
	else {
		cout << a[one_count] << endl;
	}

	
	return 0;
}

Measured memory_bytes: 256