akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;
import java.math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        PrintWriter out = new PrintWriter(System.out);
        FastScanner fs = new FastScanner();

        n = fs.nextInt(); a = fs.nextInt(); b = fs.nextInt();
        dp = new int[500][500][40];
        for(int i = 0; i < dp.length; i++) {
            for(int j = 0; j < dp[0].length; j++) {
                Arrays.fill(dp[i][j], -1);
            }
        }
        c = new Pack[n];
        for(int i = 0; i < n; i++) c[i] = new Pack(fs.nextInt(), fs.nextInt(), fs.nextInt());
        int res = solve(0, 0, 0, 0);
        if(res == (int)1e9) out.println("-1");
        else out.println(res);

        out.close();
    }

    static class Pack {
        int a, b, c;
        public Pack(int A, int B, int C) {
            a = A; b = B; c = C;
        }
    }

    static int[][][] dp;
    static int n, a, b;
    static Pack[] c;

    static int solve(int at, int cost, int A, int B) {
        if(at == n) {
            double abc = A, bcd = B;
            if(abc / bcd != (double)a/b) {
                return (int)1e9;
            }
            return cost;
        }
        if((double)(A) / (double)B == (double)a / b) {
            if(dp[A][B][at] == -1) dp[A][B][at] = cost;
            else dp[A][B][at] = Math.min(cost, dp[A][B][at]);
            return cost;
        }
        if(dp[A][B][at] != -1) return dp[A][B][at];
        int res = (int)1e9;
        //include
        res = Math.min(res, solve(at+1, cost, A + c[at].a, B + c[at].b)  + c[at].c);
        //exclude
        res = Math.min(res, solve(at+1, cost, A, B));

        return dp[A][B][at] = res;
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try	{
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer("");
            } catch (Exception e){e.printStackTrace();}
        }

        public String next() {
            if (st.hasMoreTokens())	return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }

        public int nextInt() {return Integer.parseInt(next());}

        public long nextLong() {return Long.parseLong(next());}

        public double nextDouble() {return Double.parseDouble(next());}

        public String nextLine() {
            String line = "";
            try {line = br.readLine();}
            catch (Exception e) {e.printStackTrace();}
            return line;
        }

        public Integer[] nextIntegerArray(int n) {
            Integer[] a = new Integer[n];
            for(int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for(int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        public char[] nextCharArray() {
            return nextLine().toCharArray();
        }
    }
}

Measured memory_bytes: 83260
import sys
input = sys.stdin.readline

def main():
    n, k, q = map(int, input().split())
    a = list(map(int, input().split()))

    b = [[v, i]for i, v in enumerate(a)]
    b.sort()
    index = [0]*n
    for i in range(n):
        index[i] = b[i][1]

    judge = [[] for i in range(n)]
    already = [-1, n]

    for i in range(n):
        
        for j in range(len(already)-1):
            key = a[already[j]+1:already[j+1]]
            if len(key) >= k:
                judge[i].append(key)
        already.append(index[i])
        already.sort()

    ans = 1e9
    for i in range(n):
        if not judge[i]:
            break
        m = b[i][0]
        sub = []
        for values in judge[i]:
            values.sort()
            for j in range(len(values)-k+1):
                sub.append(values[j])
        sub.sort()
        if len(sub) < q:
            break
        M = sub[q-1]
        ans = min(ans, M-m)

    print(ans)


    
if __name__ == "__main__":
    main()



Measured memory_bytes: 111720
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <vector>
#include <utility>
#include <map>

using namespace std;

int main() {
  int64_t N, M;
  cin >> N >> M;
  map<int64_t, int64_t> card_map;
  for (int64_t n = 0; n < N; ++n) {
    int64_t A;
    cin >> A;
    ++card_map[A];
  }

  for (int64_t m = 0; m < M; ++m) {
    int64_t B, C;
    cin >> B >> C;
    card_map[C] += B;
  }
  vector<pair<int64_t, int64_t>> cards(card_map.begin(), card_map.end());
  sort(cards.begin(), cards.end(),
       [] (const auto& lhs, const auto& rhs) {
         return lhs.first > rhs.first;
       });
  int64_t cnt = 0;
  int64_t sum = 0;
  size_t idx = 0;
  while (cnt < N) {
    int64_t num = min(N-cnt, cards[idx].second);
    sum += cards[idx++].first * num;
    cnt += num;
  }
  cout << sum << endl;
  
  return 0;
}


Measured memory_bytes: 18836
n, a, b = map(int, input().split())
x = list(map(int, input().split()))
total = 0
for i in range(n-1):
    if a * (x[i+1] - x[i]) > b:
        total += b
    else:
        total += a * (x[i+1] - x[i])
print(total)

Measured memory_bytes: 15020
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            while (true)
            {
                int n = int.Parse(Console.ReadLine());

                if (n == 0) break;

                HashSet<int> hs = new HashSet<int>();

                for (int i = 1; i < n; i++)
                {
                    int temp = (i * i) % n;
                    hs.Add(temp);
                }

                var nums = hs.ToList();

                int m = (n - 1) / 2;

                int[] counts = new int[m + 1];

                for (int i = 0; i < nums.Count; i++)
                {
                    for (int j = i + 1; j < nums.Count; j++)
                    {
                        int a = nums[i];
                        int b = nums[j];

                        int temp = a - b;

                        if (a - b < 0) temp += n;

                        if (temp > m) temp = n - temp;

                        counts[temp]++;
                    }
                }

                for (int i = 1; i <= m; i++)
                {
                    sb.AppendLine((counts[i] * 2).ToString());
                }
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 10788
#include<stdio.h>
int main(void)
{
	int a,b;
	scanf("%d",&a);
	scanf("%d",&b);
	if(a*2-1>a+b)printf("%d",a*2-1);
	else if(b*2-1>a+b)printf("%d",b*2-1);
	else printf("%d",a+b);
}

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

int bubbleSort(int A[], int N){
	int sw= 0;
	bool flag = 1;
	for( int i = 0; flag; i++ ){
		flag = 0;
		for( int j = N - 1; j >= i + 1; j-- ){
			if( A[j] < A[j - 1] ){
				swap(A[j], A[j - 1]);
				flag = 1;
				sw++;
			}
		}
	}
	return sw;
}

int main(){
	int A[100], N, sw;
	cin >> N;
	for( int  i = 0; i < N; i++ ) cin >> A[i];
	sw = bubbleSort(A, N);
	for( int  i = 0; i < N; i++ ){
		if(i) cout << " ";
		cout << A[i];
	}
	cout << endl;
	cout << sw << endl;
	
	return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  int h1,m1,h2,m2,k;cin>>h1>>m1>>h2>>m2>>k;

  cout<<((h2*60+m2)-(h1*60+m1)-k)<<endl;

  return 0;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <string>
#include <deque>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <assert.h>
#include <sstream>
typedef long long ll;
#define vi vector<int>
using namespace std;

int dX[4] = { 0, 0, -1, 1 };
int dY[4] = { -1, 1, 0, 0 };


const int MOD = 998244353;
const int mxn = 500000;
int seg1[mxn], seg2[mxn];

void update(int seg[], int N, int l, int r, int val) {
	l += N;
	r += N;
	while (l < r) {
		if (l & 1) {
			seg[l] = min(seg[l], val);
			l++;
		}
		if (r & 1) {
			r--;
			seg[r] = min(seg[r], val);
		}
		l >>= 1;
		r >>= 1;
	}
}

int query(int seg[], int N, int idx) {
	idx += N;
	int ans = N;
	while (idx > 0) {
		ans = min(ans, seg[idx]);
		idx >>= 1;
	}
	return ans;
}


int main() {
	int N, Q;
	cin >> N >> Q;
	for (int i = 1; i <= 2 * N; i++) {
		seg1[i] = N;
		seg2[i] = N;
	}
	ll ans = (N - 2LL) * (N - 2LL);
	for (int i = 0; i < Q; i++) {
		int t, x;
		cin >> t >> x;
		x--;
		if (t == 1) {
			int lim = query(seg1, N, x);
			ans -= lim - 2LL;
			update(seg2, N, 0, lim, x + 1);
		}
		else {
			int lim = query(seg2, N, x);
			ans -= lim - 2LL;
			update(seg1, N, 0, lim, x + 1);
		}
	}
	cout << ans << '\n';
}

Measured memory_bytes: 6744
#include<iostream>
#include<vector>
#include<string>
#include<climits>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<queue>
#include<math.h>

int main(){
	int n;
	std::cin>>n;

	std::vector<double> aList(n);
	for(int i=0; i<n; i++)
		std::cin>>aList[i];

	double denom= 0;
	for(int i=0; i<n; i++)
		denom+= 1.0/aList[i];


	std::cout<<1.0/ denom<<std::endl;

	return 0;
}

Measured memory_bytes: 256
using System;

class D
{
	static void Main()
	{
		var h = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
		long n = h[0], k = h[1], m = n - k + 2;
		Console.WriteLine((-(n + 1) * m + (n + 3) * m * (m + 1) / 2 - m * (m + 1) * (2 * m + 1) / 6) % 1000000007);
	}
}


Measured memory_bytes: 27560
import sys
import collections
import bisect
readline = sys.stdin.readline


def main():
    n = int(readline().rstrip())
    aList = sorted(list(map(int, readline().rstrip().split())))
    z = [0] * n
    for a in aList:
        z[a-1] += 1

    for i in range(n):
        print(z[i])


if __name__ == '__main__':
    main()


Measured memory_bytes: 33652
#include<stdio.h>
int main(void)
{
  char str[3];
  int i;
  for(i=0;i<3;i++)
    scanf("%s",&str[i]);
  
  if(str[0]==str[1]&&str[1]==str[2])
    printf("No");
  else
    printf("Yes");
  
  return 0;
}

Measured memory_bytes: 128
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<double>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int a;
    while(cin>>a){
        vi range; range.push_back(a);
        ll sum=0; sum+=a;
        rep(i,10){if(i){int gotiusa; cin>>gotiusa; range.push_back(gotiusa);sum+=gotiusa;}char gomi; cin>>gomi;}
        double v; cin>>v; v/=10; char gomi; cin>>gomi;
        double u; cin>>u; u/=10;
        double tiya=u,rize=v;
        bool touch=false;
        for(int i=0;;i++){
            if(v+u-(double)sum>=0)touch=true;
            if(touch)break;
            v+=rize;u+=tiya;
        }
        rep(i,range.size()){
            v-=range[i];
            if(v<=0){cout<<i+1<<endl; break;}
        }
    }
}

Measured memory_bytes: 3024
#include<bits/stdc++.h>
using namespace std;
long long a[605];
vector<int> vv;
signed main(){
	long long n;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	for(int i=0;i<n;i++){
		for(int j=1;j<n;j++){
			vv.push_back(1);
			for(int k=1;k<n;k++){
				swap(a[k-1],a[k]);
			}
		
			if(a[0]<a[n-1]){
				vv.push_back(n-1);
				swap(a[0],a[n-1]);
			
			}
			
		}
		vv.push_back(1);
		for(int j=1;j<n;j++){
			swap(a[j],a[j-1]);
		}
	
	}
	cout << vv.size()<<endl;
	for(int i=0;i<vv.size();i++){
		cout <<vv[i]<<endl;
	}
}

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

int main(void){

    int sheep;
    int wolf;


    //入力部分
    scanf("%d%d",&sheep,&wolf);

    //計算部分

    //出力部分
    if(wolf>=sheep){
        printf("unsafe\n");
    }else{
        printf("safe\n");
    }
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;

int main(){
  int n;
  cin >> n;
  ll sum = 0;
  for(int i=1; i<=9; i++){
    for(int j=1; j<=9; j++){
      int a=0, b=0;
      if(i == j){
        if(i <= n){
          a++;
          b++;
        }
      }
      if(10*i+j <= n) a++;
      if(10*j+i <= n) b++;
      for(int k=1; k<=4; k++){
        for(int num=0; num<pow(10, k); num++){
          string numStr = "";
          int zeroNum = k-to_string(num).length();
          rep(m, zeroNum) numStr += "0";
          numStr += to_string(num);
          string str = "";
          str += to_string(i);
          str += numStr;
          str += to_string(j);
          if(stoi(str) <= n) a++;
          str = "";
          str += to_string(j);
          str += numStr;
          str += to_string(i);
          if(stoi(str) <= n) b++;
        }
      }
      sum += a*b;
    }
  }
  cout << sum << endl;
  return 0;
}         

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

vi inverse(vi p)
{
	int n=p.size();
	vi q(n);
	for(int i=0;i<n;i++)
	{
		q[p[i]]=i;
	}
	return q;
}

vi f(vi a, vi b)
{
	int n=a.size();
	vi p(n);
	for(int i=0;i<n;i++)
	{
		p[i]=a[b[i]];
	}
	return p;
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	int k; cin>>k;
	vi p,q;
	for(int i=0;i<n;i++)
	{
		int x; cin>>x; x--; p.pb(x);
	}
	for(int i=0;i<n;i++)
	{
		int x; cin>>x; x--; q.pb(x);
	}
	vi ip = inverse(p);
	vi iq = inverse(q);
	vi A = f(q, f(ip, f(iq, p)));
	vi iA = inverse(A);
	ll pp = (k-1)/6;
	vi r;
	vi ir;
	for(int i=0;i<n;i++)
	{
		r.pb(i); ir.pb(i);
	}
	while(pp)
	{
		if(pp&1) r=f(r,A);
		A=f(A,A);
		pp>>=1;
	}
	pp=(k-1)/6;
	while(pp)
	{
		if(pp&1) ir=f(ir,iA);
		iA=f(iA,iA);
		pp>>=1;
	}
	vi C[6];
	C[0]=p;
	C[1]=q;
	for(int i=2;i<6;i++)
	{
		C[i]=f(C[i-1],inverse(C[i-2]));
	}
	r=f(r,C[(k-1)%6]);
	r=f(r,ir);
	for(int i=0;i<n;i++)
	{
		cout<<r[i]+1;
		if(i+1<n) cout<<' ';
	}
	cout<<'\n';
}


Measured memory_bytes: 7632
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>
using namespace std;
// I hope you understand what i have coded :D , All the best
// shubhamk840@gmail.com
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define endl '\n'
#define stackofi stack<int>
#define queueofi queue<int>  
#define vectoriterator vector<int>::iterator
#define mapiterator map<int,int>::iterator
#define setiterator set<int>:: iterator
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define MOD 1000000007
// macros for inputting 1-D and 2-D array.
#define stringiterator string:: iterator
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ai(arr,n) for(int i=0;i<n;i++)cin>>arr[i];
#define ao(arr) for(auto wtf:arr) cout<<wtf<<" ";
#define mi(arr,m,n) for(int i=0;i<m;i++){ for(int j=0;j<n;j++) cin>>arr[i][j];}
#define mo(arr,m,n) for(int i=0;i<m;i++){ for(int j=0;j<n;j++) cout<<arr[i][j]<<" "; cout<<endl;}
#define countsetbits(x) __builtin_popcount(x)
#define ll long long
#define debugger cout<<"I AM EXECUTING"<<endl
#define debug(x) cout<<#x<<"->"<<x<<endl;
#define F first
#define S second
#define testcases int asdf; cin>>asdf; while(asdf--)
#define space cout<<endl
#define vi vector<int>
#define si set<int>
#define vc vector<char>
#define sc set<char>
#define vll vector<long long int>
#define vs vector<string>
#define vpp vector<pair<int,int>> 
#define mp make_pair
string sconvert(int n)
{
	stringstream ss;
	ss<<n;
	string str = ss.str();
	return str;
}
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second > b.second); 
}
template<typename KeyType, typename ValueType>  // for finding max element in the map.
std::pair<KeyType,ValueType> get_max( const std::map<KeyType,ValueType>& x ) {
  using pairtype=std::pair<KeyType,ValueType>; 
  return *std::max_element(x.begin(), x.end(), [] (const pairtype & p1, const pairtype & p2) {
        return p1.second < p2.second;
  }); 
}

int add(int a, int b, int mod = MOD) {
    if (a + b >= mod) {
        return a + b - mod;
    }
    return a + b;
}
 
int sub(int a, int b, int mod = MOD) {
    if (a - b < 0) {
        return a - b + mod;
    }
    return a - b;
}
 
int mul(int a, int b, int mod = MOD) {
    return (int)(1ll * a * b % mod);
}




ll int  single(ll int h,ll int k)
{
    if(h==1)
    return k;
    else
    return k+single(h/2,2*k);
}

int main()
{
  IOS;
  ll int h;
  cin>>h;
  cout<<single(h,1)<<endl;
  
  
}















Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
typedef long long ll;

using namespace std;

int main(){
	int n,k;
	cin >> n >> k;
	vector<int> h(n);
	for(int i = 0 ; i < n ; i++){
		cin >> h[i];
	}
	ll sum = 0;
	sort(h.rbegin(), h.rend());
	if(k >= n){
		cout<<"0";
		return 0;
	}
	for(int i = k ; i < n ; i++){
		sum += h[i];
	}
	cout << sum ;

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N, K = -1;
    cin >> N;
    repe(i, 2, N + 2) if (i * (i - 1) == N * 2) K = i;

    if(K == -1){
        cout << "No" << endl;
        return 0;
    }

    vvc<ll> ans(K);
    repe(k, 2, K + 1){
        ll pn = (k - 1) * (k - 2) / 2 + 1, tn = k * (k - 1) / 2;
        rep(i, k - 1) ans[i].eb(pn + i);
        repe(i, pn, tn + 1) ans[k - 1].eb(i);
    }
    cout << "Yes" << '\n'
         << K << '\n';
    rep(i, K){
        cout << K - 1 << " ";
        rep(j, K - 1) cout << ans[i][j] << " ";
        cout << '\n';
    }
}

Measured memory_bytes: 5008
import java.io.*;

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String l,s="";
		while ((l=br.readLine())!=null) s+=l;
		s=s.toLowerCase();
		char[] a={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
		int r;
        for(char c:a){
        	r=0;
        	for(int i=0;i<s.length();i++){
            	if(s.charAt(i)==c) r+=1; 
        	}
        	System.out.println(c+" : "+r);
        }
	}
}

Measured memory_bytes: 24524
n = int(input())
p_l = list(map(int,input().split()))
p_sort = sorted(p_l)

cnt = 0
for i in range(n):
    if(p_l[i]!=p_sort[i]):
        cnt += 1
if(cnt <= 2):
    print('YES')
else:
    print('NO')


Measured memory_bytes: 2940
sub main {
    chomp(my $x = <STDIN>);
    print solve($x);
}
main() unless caller;

sub solve {
    my ($x) = @_;
    my $amari = $x % 11;
    my $ans = int($x / 11) * 2;
    if($amari > 0 && $amari < 7){
        $ans += 1;
    }
    elsif($amari > 6 && $amari < 12){
        $ans += 2;
    }
    return $ans;
}

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

int main(void){
 int N;
  cin >> N;
  string W;
  map<string,int> Wm;
  char last;
  cin >> W;
  last = W[W.length() - 1];
  Wm[W] = 1;
  for(int i = 1; i < N; i++){
    cin >> W;
    if(last != W[0] || Wm[W] == 1){
      cout << "No";
      return 0;
    }
    last = W[W.length() - 1];
    Wm[W] = 1;
  }
   cout << "Yes"; 
  
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include<unordered_set>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i+=1)
#define endl '\n'
#define all(x) x.begin(),x.end()
using namespace std;
inline int mex(unordered_set<int> st)
{
	int m = 0;
	while (st.find(m) != st.end())
	{
		m += 1;
	}
	return m;
}
inline int calculateGrundy(int n)
{
	if (n == 1)
		return 0;
	unordered_set<int> mexi;
	for (int i = 1; i <= sqrt(n); i += 1)
	{
		if (n % i == 0)
		{
			if(n/i!=n)
				mexi.insert(calculateGrundy(n/i));
			mexi.insert(calculateGrundy(i));
		}
	}
	return mex(mexi);
}
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll test;
	string s;
	cin >> s;
	set<char> st;
	st.insert(s[0]);
	st.insert(s[1]);
	st.insert(s[2]);
	if (st.size() == 1)
	{
		cout << "No";
	}
	else
		cout << "Yes";
	return 0;
}

Measured memory_bytes: 256
import sys
from collections import Counter

N = int(input())
A = list(map(int, sys.stdin.readline().rsplit()))

C = list(Counter(A).items())
C.sort(reverse=True)

a = 0
b = 0
for c in C:
    if c[1] > 1 and a == 0 and b == 0:
        if c[1] > 3:
            a = b = c[0]
            break
        a = c[0]
    elif c[1] > 1 and a != 0 and b == 0:
        b = c[0]
        break

print(a * b)


Measured memory_bytes: 21540
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int max=0;
int map[2][110];
int N;
void dfs(int x,int y,int sum)
{
    ///printf("%d--%d ----%d\n",x,y,sum);
    int i,tx,ty;
    if(x==1&&y==N-1)
    {
       /// printf("**%d**\n",sum);
        if(sum>max)
            max=sum;
        return ;
    }
    int next[2][2]={{0,1},{1,0}};
    for(i=0;i<2;i++)
    {
        tx=x+next[i][0];
        ty=y+next[i][1];
        if(tx>=0&&tx<2&&ty>=0&&ty<N)
        {
            dfs(tx,ty,sum+map[tx][ty]);
        }
    }
}
int main()
{
    int i,j;
    scanf("%d",&N);
    for(i=0;i<2;i++)
    {
        for(j=0;j<N;j++)
        {
            scanf("%d",&map[i][j]);
        }
    }
    dfs(0,0,map[0][0]);
    printf("%d",max);
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; ++i)
    cin >> A[i];

  vector<int> b(N);
  for (int i = 0; i < N; ++i)
    ++b[A[i]];

  bool flag = true;
  for (int i = (N + 1) % 2; i < N; i += 2)
    if (!(i == 0 && b[i] == 1) && !(i != 0 && b[i] == 2))
      flag = false;

  long long ans = 1;
  for (int i = 0; i < N / 2; ++i)
    ans = (ans * 2) % 1000000007;

  if (flag)
    cout << ans << endl;
  else
    cout << 0 << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <complex>
	#include <chrono>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y) 
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define f first
	#define s second
	
	using namespace std;

	const int MX = 100010;			// maximum no. of nodes in graph
	vector<bool> visited(MX+1,0);

	int n;
	vector< vector<int> > G(MX+1);
	vector<int> dp(100005, 0);		// adjacency list, (edge,cost) pair
	//vector<int> pre(10005, 1);

	void dfs(int u){
		visited[u] = 1;
		
		for(int i : G[u]){
			
			if(!visited[i]) dfs(i);
			

			dp[u] = max(dp[u], 1+dp[i]);
		}
		
	}

	int main()
	{

		std::ios::sync_with_stdio(false);

		int T;
		//cin>>T;
		T = 1;
		while(T--)
		{

			for(int i=0; i<MX+1; i++)
			{
				G[i].clear();
			}
			fill(all(visited),0);

			int m;					// no. of edges
			cin>>n>>m;

			for(int i = 1 ; i <= m ; i++)
			{

				int u,v;
				ll c;
				cin>>u>>v;			// 1 based indexing of nodes
				
				G[u].eb(v);
				//G[v].eb(u);

			}
			for(int i=1; i<=n; i++){
				if(!visited[i]){
					dfs(i);
				}
			}

			cout<<*max_element(all(dp))<<endl;
		}
		return 0;
	}

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

template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}

signed main(){
  int a,b,c,d;cin>>a>>b>>c>>d;
  while(1){
    c-=b;if(c<=0)fin("Yes");
    a-=d;if(a<=0)fin("No");
  }
}


Measured memory_bytes: 3596
#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 solve() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    ll m = 0;
    ll ans = 0;
    rep(i, N) {
        ll a = A[i];
        if (a < m) {
            ans += m - a;
        }
        m = max(m, a);
    }
    cout << ans << '\n';
}

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


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

int main() {
	int rika[4], shakai[2], min, sum=0;
	for(int i=0; i<4; i++) cin >> rika[i];
	min = sum = rika[0];
	for(int j=0; j<2; j++) cin >> shakai[j];
	for(int k=1; k<4; k++){
		if(min>rika[k]) 
		min = rika[k];
		sum += rika[k];
	}
	sum -= min;
	if(shakai[0]>=shakai[1]) sum += shakai[0];
	else sum += shakai[1];
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 3080
#include<iostream>
#include<cstdio>
using namespace std;
#define ll long long
const ll p=924844033,g=5,gv=554906420,N=1e6+5;
ll qpow(ll a,int b)
{ll ret=1;while(b){if(b&1)ret=ret*a%p;a=a*a%p;b>>=1;}return ret;}
ll inv(ll a){return qpow(a,p-2);}
int rev[N];
void getrev(int len)
{for(int i=0;i<len;i++){rev[i]=rev[i>>1]>>1;if(i&1)rev[i]|=len>>1;}}
void ntt(ll x[],int len,int form)
{
	int i,j,k,step;ll s1,s2,w,wn,lv;
	for(i=0;i<len;i++)if(i<rev[i])swap(x[i],x[rev[i]]);
	for(i=2;i<=len;i<<=1)
	{
		step=i>>1;wn=qpow(form==1?g:gv,(p-1)/i);
		for(j=0;j<len;j+=i)
		{
			w=1;
			for(k=j;k<j+step;k++)
			{
				s1=x[k],s2=x[k+step]*w%p;
				x[k]=(s1+s2)%p,x[k+step]=(s1-s2+p)%p,w=w*wn%p;
			}
		}
	}
	if(form==-1){lv=inv(len);for(i=0;i<len;i++)x[i]=x[i]*lv%p;}
}
struct edge{int to,nxt;}e[N<<1];
int head[N],tot=1,sz[N],fa[N];
void adde(int x,int y){e[tot]=(edge){y,head[x]};head[x]=tot++;}
void dfs(int u,int f)
{
    sz[u]=1;fa[u]=f;
    for(int i=head[u];i;i=e[i].nxt)
        if(e[i].to^f)dfs(e[i].to,u),sz[u]+=sz[e[i].to];
}
ll a[N],b[N],fac[N],finv[N];
ll comb(int n,int m){return m>n?0:fac[n]*finv[n-m]%p*finv[m]%p;}
int tt=0;
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<n;i++)
        {int x,y;scanf("%d%d",&x,&y);adde(x,y),adde(y,x);}
    fac[0]=finv[0]=1;
    for(int i=1;i<=2*n+5;i++)fac[i]=fac[i-1]*i%p,finv[i]=inv(fac[i]);
    dfs(1,1);
    for(int i=1;i<=n;i++)
    {
        if(i!=1)a[n-sz[i]]++;
        for(int j=head[i];j;j=e[j].nxt)a[sz[e[j].to]]+=(fa[i]!=e[j].to);
    }
    for(int i=0;i<=n;i++)a[i]=a[i]*fac[i]%p,b[i]=finv[n-i];
    //for(int i=0;i<=n;i++)cout<<a[i]<<" "<<b[i]<<endl;
    int len=1;while(len<=(2*n))len<<=1;
    getrev(len);ntt(a,len,1),ntt(b,len,1);
    for(int i=0;i<len;i++)a[i]=a[i]*b[i]%p;
    ntt(a,len,-1);
    for(int k=1;k<=n;k++)
        printf("%lld\n",((n*comb(n,k)-finv[k]*a[n+k])%p+p)%p);
}


Measured memory_bytes: 49024
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var inputs = ReadInts();
        var N = inputs[0];
        var M = inputs[1];

        var A = new int[M];

        for (var i = 0; i < N; i++)
        {
            var likes = ReadInts();
            likes.Skip(1).ToList().ForEach(_ => A[_ - 1] += 1);
        }


        Console.WriteLine(A.Count(_ => _ == N));
    }


    public static string Read() { return Console.ReadLine(); }
    public static int ReadInt() { return int.Parse(Read()); }
    public static long ReadLong() { return long.Parse(Read()); }
    public static double ReadDouble() { return double.Parse(Read()); }

    public static string[] Reads() { return Console.ReadLine().Split(' '); }
    public static int[] ReadInts() { return Reads().Select(_ => int.Parse(_)).ToArray(); }
    public static long[] ReadLongs() { return Reads().Select(_ => long.Parse(_)).ToArray(); }
    public static double[] ReadDoubles() { return Reads().Select(_ => double.Parse(_)).ToArray(); }
}


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

signed main(){

  cin.tie(0);
  ios::sync_with_stdio(false);

  int q;
  cin>>q;
  multimap<string,int> mp;
  while(q--){
    int com;
    cin>>com;
    if(com==0){
      string k;
      int x;
      cin>>k>>x;
      mp.emplace(k,x);
    }
    else if(com==1){
      string k;
      cin>>k;
      auto p = mp.equal_range(k);
      for(auto itr=p.first;itr!=p.second;++itr){
        cout<< (*itr).second <<"\n";
      }
    }
    else if(com==2){
      string k;
      cin>>k;
      mp.erase(k);
    }
    else if(com==3){
      string l,r;
      cin>>l>>r;
      auto itr = mp.lower_bound(l);
      auto end = mp.upper_bound(r);
      while(itr!=end){
        cout<< (*itr).first <<" "<< (*itr).second <<"\n";
        itr++;
      }
    }
  }

}


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

int main() {
    int a, b;
    char op;
    
    cin >> a;
    while (1) {
        cin >> op;
        if (op == '+') {
            cin >> b;
            a += b;
        } else if (op == '-') {
            cin >> b;
            a -= b;
        } else if (op == '*') {
            cin >> b;
            a *= b;
        } else if (op == '/') {
            cin >> b;
            a /= b;
        } else if (op == '=') {
            cout << a << endl;
            break;
        }
    }
}


Measured memory_bytes: 3076
#!/usr/bin/env python3


def main():
    k = int(input())
    num = 0
    soeji = 0
    ar = [0 for _ in range(k)]

    while True:
        # print(soeji)
        if ar[soeji] > 0:
            break
        ar[soeji] = num
        soeji = (soeji * 10 + 7) % k
        num += 1

    print(-1 if ar[0] == 0 else ar[0])


if __name__ == '__main__':
    main()


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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int WWW = 0;WWW < (n);WWW++)cerr << v[WWW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define MOD 1000000007

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

struct UF
{
	vector<int> par; // 親のインデックスを記憶する配列
	vector<int> sz; // サイズを記憶する。
	vector<int> rank;
	// 初期化
	UF(int n):par(n),sz(n),rank(n){
		for(int i = 0; i < n; i++){
			par[i] = i;sz[i] = 1;rank[i] = 0;
		}
	}
	// 親を求める
	int find(int x) {
		if (par[x] == x) return x;
		else return par[x] = find(par[x]);
	}
	// xとyの属する集合を併合
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		if(rank[x] < rank[y]){
			par[x] = y;
			sz[y] += sz[x];
		}
		else{
			par[y] = x;
			sz[x] += sz[y];
			if(rank[x] == rank[y])rank[x]++;
		}
	}
	// xとyが同じ集合ならtrue
	bool same(int x, int y) { return find(x) == find(y); }
	// 素の集合のサイズを求める
	int size(int n){return sz[find(n)];}
};

ll n,m,b_sum,cou;
ll a[111111];
ll b[111111];
ll c[111111];
ll dp[111111];
vector<pair<ll,pair<ll,ll>>> edge;
vector<vector<int>> v(111111);

ll dfs(ll node){
	cou++;
	if(dp[node] != -1)return dp[node];
	ll ret = 1000000000000000000LL;
	ll tmp_sum = b[node];
	vector<ll> seica(v[node].size());
	REP(i,v[node].size()){
		seica[i] = max(dfs(v[node][i]),c[node]);
		tmp_sum += b[v[node][i]];
	}
	REP(i,v[node].size()){
		ret = min(ret,seica[i]+tmp_sum-b[v[node][i]]);
	}
	
	ret = min(ret,c[node]+tmp_sum);
	
	b[node] = tmp_sum;
	return dp[node] = ret;
}

int main(){
	
	REP(i,111111)dp[i] = -1;
	
	cin >> n >> m;
	ll ma = -1;
	ll node;
	REP(i,n){
		cin >> a[i] >> b[i];
		b_sum += b[i];
		c[i] = max(0LL,a[i] - b[i]);
		if(ma < c[i]){ma = c[i],node = i;}
	}
	REP(i,m){
		int x,y;cin >> x >> y;
		x--;y--;
		edge.PB(MP(max(c[x],c[y]),MP(x,y)));
	}
	
	sort(ALL(edge));
	
	UF uf(n);
	
	REP(i,m){
		ll A = edge[i].SE.FI;
		ll B = edge[i].SE.SE;
		if(uf.same(A,B))continue;
		if(c[A] < c[B]){
			v[B].PB(uf.find(A));
			uf.par[uf.find(A)] = B;
		}
		else{
			v[A].PB(uf.find(B));
			uf.par[uf.find(B)] = A;
		}
		uf.unite(A,B);
	}
	
	cout << dfs(node) << endl;
	DBG(cout << "node is " << node << endl;)
	DBG(cout << "cou is " << cou << endl;)
	DBG(REP(i,n){cout << i << " : ";SHOW1d(v[i],v[i].size());})
		
	return 0;
}


Measured memory_bytes: 17904
#include <bits/stdc++.h>
using namespace std;
 
int main(void){
    int a,b,c,d,e=0,f=0;
    cin >> a >> b >> c >> d;
    while (1){
        c = c-b;
        if (c <= 0){
            e++;
            break;
        }
        a = a - d;
        if (a <= 0){
            f++;
            break;
        }
    }   
    
    if (e==1){
        cout << "Yes" << endl;
    }
    if (f==1){
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3620
#[allow(unused_imports)] use proconio::{input, marker::{Bytes, Chars, Usize1, Isize1}};
#[allow(unused_imports)] use std::cmp::{min, max};
#[allow(unused_imports)] use superslice::Ext as _;

#[proconio::fastout]
fn main() {
	input! {
		n: usize,
		k: usize,
		a: [usize; n],
	}

	if n == k {
		println!("1");
		return;
	}

	let mut one = 0;
	for i in 0..n {
		if a[i] == 1 {
			one = i;
		}
	}

	let mut l = one;
	let mut r = n-l-1;

	if k-1 <= l {
		l -= k-1;
	}
	else {
		r -= k-1-l;
		l = 0;
	}
	// lとr両方が奇数なら
	if l % 2 == 1 && r % 2 == 1 {
		l -= 1;
		r += 1;
	}

	println!("{}", (l+k-2)/(k-1) + (r+k-2)/(k-1) + 1);
}


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


signed main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    cout << fixed << setprecision(20);

    string s;
    cin>>s;
    int n = s.size();
    int cnt = 0;
    int last = 0;
    int q = 0;
    bool end = true;
    reverse(s.begin(),s.end());
    for(int i=0;i<n;i++){
        if(s[i] == '?'){
            if(i!=0) end = false;
            q = i;
        }
        else{
            if(i <= 6 && i>=1){
                cnt += (s[i] - '0') * (i+1);
                cnt %= 11;
            }
            else if(i >=7 && i <= 11){
                cnt += (i-5) * (s[i] - '0');
                cnt %= 11;
            }
            else last = s[i] - '0';
        }
    }
    if(end){
        if(cnt <=1){
            cout << 0 << endl;
        }
        else cout << 11 - cnt << endl;
        return 0;
    }
    int ans = -1;
    if(last == 0){
        for(int i=0;i<10;i++){
            bool ok = false;
            if(q <= 6 && q>=1){
                if((cnt + i*(q+1))%11 <= 1) ok = 1;
            }
            else {
                if((cnt + i*(q-5))%11 <= 1) ok = 1;
            }
            if(ok){
                if(ans != -1){
                    cout << "MULTIPLE" << endl;
                    return 0;
                }
                ans = i;
            }
        }
    }
    else{
        for(int i=0;i<10;i++){
            bool ok = false;
            if(q<=6){
                if(11-(cnt + i*(q+1))%11 == last) ok = 1;
            }
            else {
                //cerr << q << endl;
                //cerr << i << " " << (cnt + i*(q-5))%11 << " " << last << endl;
                if(11-(cnt + i*(q-5))%11 == last) ok = 1;
            }
            if(ok){
                if(ans != -1){
                    cout << "MULTIPLE" << endl;
                    return 0;
                }
                ans = i;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]){
	int n;
	cin >> n;
	map <string, vector <pair<int, int> > > city;
	for(int i = 0; i < n; i++){
		string name; int foo;
		cin >> name >> foo;
		city[name].push_back(make_pair(foo, i + 1));
	}
	for(auto it: city){
		sort(it.second.begin(), it.second.end());
		for(int i = it.second.size() - 1; i >= 0; i--){
			cout << it.second[i].second << "\n";
		}
	}
	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var k int
	a := make([]int, 5)
	for i := range a {
		fmt.Scan(&a[i])
	}
	fmt.Scan(&k)
	f := a[0]
	for i := 1; i < 5; i++ {
		if a[i]-f > k {
			fmt.Println(":(")
			return
		}
	}
	fmt.Println("Yay!")
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
const int mod = 1e9 + 7;
typedef long long LL;
char s[N];
int n, k;
int main() {
#ifdef TEST
	freopen("input.txt", "r", stdin);
#endif
	scanf("%s%d", s, &k);
	n = strlen(s);
	if (s[0] != s[n - 1]) {
		int ans = 0;
		for (int i = 0; i < n;) {
			int j = i;
			while (s[i] == s[j]) j++;
			ans += (j - i) >> 1;
			i = j;
		}
		printf("%lld\n", 1LL * ans * k);
	} else {
		bool flag = true;
		for (int i = 1; i < n; ++i) {
			flag &= (s[i] == s[i - 1]);
		}
		if (flag) {
			printf("%lld\n", (1LL * n * k) >> 1);
			return 0;
		}
		long long ans = 0;
		int ed = n;
		for (int i = 0; i < ed;) {
			int j = i;
			while (s[i] == s[j]) j++;
			if (i == 0) {
				while (s[ed - 1] == s[i]) ed--;
				ans += 1LL * (n - ed + j) / 2 * (k - 1);
				ans += (n - ed) / 2 + j / 2;
			} else {
				ans += 1LL * (j - i) / 2 * k;
			}
			i = j;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import heapq
lens = int(input())
vals = [int(x) for x in input().split()]
heapq.heapify(vals)

while len(vals) > 1:
    curr = heapq.heappop(vals)
    curr += heapq.heappop(vals)
    curr /= 2
    heapq.heappush(vals, curr)
    #print(vals)
print(vals[0])

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

int main()
{
    string s;
    int ans = 0;

    cin >> s;

    for (int i = 1; i < s.size(); i++) {
        if (s[i] != s[i - 1]) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
// if文による条件分岐　比較演算子
#include <stdio.h>
int main(void){
    char buf[100];
    int a;
    fgets(buf,sizeof(buf),stdin);
    sscanf(buf,"%d",&a);
    if (a<=999) {
        printf("ABC");
    } else {
        printf("ABD");
    }
}

Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)

func main() {
	var n, k int
	fmt.Scanf("%d %d", &n, &k)

	sc := bufio.NewScanner(os.Stdin)
	hs := make([]int, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		hs[i], _ = strconv.Atoi(sc.Text())
	}

	sort.Sort(sort.IntSlice(hs))

	min := math.MaxInt64

	for i := 0; i < n-k+1; i++ {
		h := hs[i+k-1] - hs[i]
		if min > h {
			min = h
		}
	}

	fmt.Println(min)
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll max(ll a, ll b){ 
	if(a >= b) return a;
	else if(a < b) return b;
}

int main(){
	vector<int> c(3);
	cin >> c[0] >> c[1] >> c[2];
	sort(c.begin(), c.end());
	int ans = 0;
	if(c[0] == c[1] && c[1] == c[2]) ans = 1;
	else if((c[0] == c[1]&&c[1] != c[2])||(c[0] != c[1]&&c[1] == c[2])) ans = 2;
	else if(c[0] != c[1] && c[1] != c[2])ans = 3;
	cout << ans << endl;
}   



Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  vector<string> s(n); REP(i, n) cin >> s[i];
  vector<vector<int> > graph(n);
  REP(i, n) REP(j, n) {
    if (s[i][j] == '1') graph[i].emplace_back(j);
  }
  int ans = -1;
  REP(i, n) {
    int tmp = 0;
    queue<int> que;
    que.emplace(i);
    vector<int> idx(n, -1);
    idx[i] = 0;
    while (!que.empty()) {
      ++tmp;
      vector<int> now;
      while (!que.empty()) {
        now.emplace_back(que.front());
        que.pop();
      }
      for (int ver : now) {
        for (int e : graph[ver]) {
          if (idx[e] == -1) {
            idx[e] = tmp;
            que.emplace(e);
          }
        }
      }
    }
    bool ok = true;
    REP(i, n) REP(j, n) {
      if (s[i][j] == '1') {
        int u = idx[i], v = idx[j];
        if (abs(u - v) != 1) ok = false;
      }
    }
    if (ok) ans = max(ans, tmp);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <bitset>
#include <queue>
#include <iostream>

using namespace std;

#define MAXN 510
#define INF 0x3f3f3f3f
typedef long long LL;

int main()
{
    int n, a[MAXN];
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i){
        scanf("%d", a + i);
    }
    sort(a + 1, a + 1 + n);
    printf("%d\n", a[n] - a[1]);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  static Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {
    char[] A = sc.next().toCharArray();
    int N = A.length;
    int[] count = new int[26];
    for (int i = 0; i < N; i++) {
      count[A[i] - 'a']++;
    }
    long ans = 1;
    for (int i = 0; i < N; i++) {
      count[A[i] - 'a']--;
      ans += N - i - 1 - count[A[i] - 'a'];
    }
    System.out.println(ans);
  }

}


Measured memory_bytes: 26688
fun main() {
    val (n, m) = readLine()!!.split(" ").map(String::toInt)

    val map = Array(n) { mutableListOf<Int>() }

    repeat(m) {
        val (a, b) = readLine()!!.split(" ").map { it.toInt() - 1 }
        map[a].add(b)
        map[b].add(a)
    }

    val dist = Array(n) { -1 }
    dist[0] = 0

    val que = mutableListOf<Int>()
    que.push(0)

    while (que.isNotEmpty()) {
        val v = que.pop()

        map[v].forEach {
            if (dist[it] != -1) return@forEach

            dist[it] = v + 1
            que.push(it)
        }
    }

    println("Yes")
    dist.takeLast(n - 1).forEach {
        println(it)
    }
}

private fun <T> MutableList<T>.push(e: T) = add(e)
private fun <T> MutableList<T>.pop() = removeAt(0)

Measured memory_bytes: 86604
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    for (int i = 1; i < n; ++i)
        if (s[i] == s[i - 1])
            return cout << i << ' ' << i + 1, 0;

    for (int i = 1; i < n - 1; ++i)
        if (s[i - 1] == s[i + 1])
            return cout << i << ' ' << i + 2, 0;

    cout << "-1 -1";
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#include<cctype>
#include<string>
using namespace std;
int main() {
    int n,k;
    cin >>n>>k;
   vector<int> h(n);
   for(int i=0;i<n;i++){
      cin>>h[i];
    }
    sort(h.begin(),h.end(),greater<int>());
    int ans=1000000000;
    for(int i=0;i<n-k+1;i++){
        if(ans>h[i]-h[i+k-1])ans=h[i]-h[i+k-1];
    }
     
    cout << ans<<endl;
}

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

using namespace std;

int main(void){
    string s;
    cin>>s;
    int count_0=0;
    int count_1=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='0') count_0++;
        if(s[i]=='1') count_1++;
    }
    cout<<min(count_0,count_1)*2<<endl;
    return 0;
}


Measured memory_bytes: 512
n=int(input())
a=list(map(int,input().split()))
s=0
o=0
for i in range(n):
    if a[i]%4==0:
        s+=1
    elif a[i]%2==1:
        o+=1
#print(s,o)
if n%2==0:
    if o-s<=0:
        print("Yes")
    else:
        print("No")
else:
    if o-s<=1:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<#x<<" " <<x<<endl;
const long long  N=2e5+10,big=1e18,mod=1e9+7;
const double pi=acos(-1);

long long n,m,k,mini=N,maxi=-N;

int main()
{
    long long a,b;

        cin>>a>>b;
        cout<<max(max(a-b,a+b),a*b);
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

	int a[M], b[M];
	for(int i = 0; i < M; i++){
		cin >> a[i] >> b[i];
	}

	int count[N] = {0};
	for(int i = 0; i < M; i++){
		count[a[i] - 1]++;
		count[b[i] - 1]++;
	}

	for(int i = 0; i < N; i++){
		cout << count[i] << endl;
	}

	return 0;
}




Measured memory_bytes: 256
n, m = gets.chomp.split.map(&:to_i)
ans = 0
if n < 2 && m < 2
  puts "0"
  exit
end

ans += (1..n).to_a.combination(2).to_a.length if n >= 2
ans += (1..m).to_a.combination(2).to_a.length if m >= 2
puts ans


Measured memory_bytes: 2172