akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main(int argc, const char * argv[])
{
    int ans=0,diff;
    string s;
    cin>>s;
    for(int i=0;i<s.size()-2;i++)
    {
        int t=(s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0');
        if(t>753)
            diff=t-753;
        else
            diff=753-t;
        if(i==0 || ans>diff) ans=diff;
        if(ans==0) break;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<map>
#include<queue>
#include<ostream>
#include<cstring>
using namespace std;
int main(){
	string n,m;
	cin>>n>>m;
	cout<<m<<n<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<set>
#include<sstream>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<deque>
#include<map>
using namespace std;


int abs(int x){
    return x>0?x:-x;
}

int M,N;









int main()
{   

    int a[100001]={1};
    int isRed[100001]={0};
    for(int i=0;i<100001;i++){
        a[i]=1;
        isRed[i]=0;
    }
    isRed[1]++;

    int red=1;
    int in,out;
    int res = 1;
    scanf("%d %d",&N,&M);
    for(int i=0;i<M;i++){
        scanf("%d %d",&out,&in);
        if (isRed[out]>0){
            isRed[in]=1;
            if (a[out]==1){
                isRed[out]--;
            }
        }
        a[out]--;
        a[in]++;
    }
    res = 0;
    for(int i=1;i<=N;i++){
        if(isRed[i]>0){
            res++;
        }
    }
    printf("%d",res);
  


}



Measured memory_bytes: 1024
import sys
li  =   lambda : [int(x) for x in sys.stdin.readline().strip().split()]
rw  =   lambda : sys.stdin.readline().strip().split()
ni  =   lambda : int(sys.stdin.readline().strip())
nsi =   lambda : sys.stdin.readline().strip()

from collections import defaultdict as df
import math
s=input()
sum=0
for i in s:
    sum+=int(i)

if(sum%9==0):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9588
#include<iostream>
using namespace std;
#define MAX 100000

int parent(int i) {  return i / 2 ;}
int left(int i) { return 2 * i; }
int right(int i) { return 2 * i + 1 ;}

int main() {
  int H;
  int A[MAX+1]; 
  cin >> H;
  for ( int i = 1; i <= H; i++ ) cin >> A[i];
  
  for ( int i = 1; i <= H; i++ ) {
    cout << "node " << i << ": key = " << A[i] << ", ";
    if ( parent(i) >= 1) cout << "parent key = " << A[parent(i)] << ", ";
    if ( left(i) <= H ) cout << "left key = " << A[left(i)] << ", " ;
    if ( right(i) <= H ) cout << "right key = " << A[right(i)] << ", "; 
    cout << endl;
  }
  return 0;
}




Measured memory_bytes: 3096
// Problem : A - Not
// Contest : AtCoder - AtCoder Beginner Contest 178
// URL : https://atcoder.jp/contests/abc178/tasks/abc178_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

#include <bits/stdc++.h>
using namespace std;

#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define endl '\n'
#define vi vector<ll>
#define mii map<ll, ll>
#define pii pair<ll, ll>
#define pb push_back
#define fi first
#define se second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()

const ll inf=0x3f3f3f3f3f3f3f3f;

int main() {
    SPEED;
    ll x;
    cin>>x;
    x = (!x);
    cout<<x;
    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>


void solve(int n, int m) {
    int a,sum=0;
    while(m--) {
        scanf("%d",&a);
        sum+=a;
    }
    n-=sum;
    if(n<0) printf("-1");
    else printf("%d",n);
}

int main () {
    int n,m;
    scanf("%d%d",&n,&m);
    solve(n,m);
}


Measured memory_bytes: 1732
S = input()
def solve(S):
    if int(S[0])*1000+int(S[1])*100+int(S[2])*10+int(S[3]) > 2019:
        return 'TBD'
    if int(S[0])*1000+int(S[1])*100+int(S[2])*10+int(S[3]) < 2019:
        return 'Heisei'
    if int(S[5])*10+int(S[6]) > 4:
        return 'TBD'
    if int(S[5])*10+int(S[6]) < 4:
        return 'Heisei'
    return 'Heisei'
print(solve(S))

Measured memory_bytes: 3064
# include<iostream>
# include<cstring>
# include<cstdio>
# include<cstdlib>
# include<algorithm>
# define LL long long
using namespace std;
int n,tot;
int a[300001],f[300001],g[300001];
int main()
{
	cin>>n;
	tot=1<<n;
	for(int i=0;i<tot;++i)
	  cin>>a[i];
	int ans=0;
	for(int i=1;i<tot;++i)
	  {
	  	for(int j=i;j>=0 ;j=(j-1)&i)
	  	  {
	  	  	if(f[i]<=a[j]) g[i]=f[i],f[i]=a[j];
	  	    else if(g[i]<a[j]) g[i]=a[j];
	  	    if(!j) break;
		  }
		ans=max(ans,f[i]+g[i]);
	  	printf("%d\n",ans);
	  }
}

Measured memory_bytes: 6144
# Aizu Problem 0108: Operation of Frequency of Appearance

#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def operation_of_frequency_of_appearance(S):
    S_old = S[:]
    steps = 0
    while True:
        unique = list(set(S))
        counts = {u: S.count(u) for u in unique}
        S = [counts[s] for s in S]
        if S == S_old:
            return steps, S
        S_old = S[:]
        steps += 1

    
while True:
    N = int(input())
    if N == 0:
        break
    steps, S = operation_of_frequency_of_appearance([int(_) for _ in input().split()])
    print(steps)
    print(' '.join([str(s) for s in S]))
    

Measured memory_bytes: 7784
from collections import defaultdict
N=int(input())
S={}
S_counter = defaultdict(int)
count=0
for i in range(N):
  s="".join(sorted(input()))
  if s in S:
    count += S[s]
    S[s] += 1
  else:
    dict={s:1}
    S.update(dict)
print(count)  

Measured memory_bytes: 18236
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define OUTPUT(x) (output(x), output("\n"))
#else
#define OUTPUT(x) (void)0
#endif

ll modpow(ll x, ll b){
    ll res = 1;
    while(b){
        if(b&1)res = res * x % MOD;
        x = x * x % MOD;
        b>>=1;
    }
    return res;
}

ll modinv(ll x){
    return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
    if(was_output)cout << " ";
    cout << a;
    was_output = true;
}
void outendl(){
    was_output = false;
    cout << endl;
}
ll in(){
    ll res;
    (void)scanf("%lld", &res);
    return res;
}

int char_code(char x){
    return x - 'a';
}

int inc(){
    char res;
    cin >> res;
    return char_code(res);
}

vector<int> ins(){
    string str;
    cin >> str;
    vector<int> res;
    foreach(i,str)res.push_back(char_code(i));
    return res;
}

template<class t>
istream& operator>>(istream& is, vector<t> &x){
    for(auto &i:x)is >> i;
    return is;
}

template<class t, class u>
istream& operator>>(istream& is, pair<t, u> x){
    is >> x.first >> x.second;
    return is;
}

int main(){
    int n = in();
    vector<int> base = ins();
    set<int> ss[26];

    rep(i,n){
        ss[base[i]].insert(i);
    }

    int q = in();

    rep(query,q){
        int kind = in();
        if(kind==1){
            int p = in()-1;
            char c = inc();
            ss[base[p]].erase(p);
            ss[c].insert(p);
            base[p] = c;
        }else{
            int ans = 0;
            int l = in()-1;
            int r = in();
            rep(i,26){
                auto p = ss[i].lower_bound(l);
                if(p==ss[i].end())continue;
                if(*p<r)++ans;
            }
            cout << ans << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 25740
// Date: 2020-03-28

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define IO freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout)
#define FIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define D(x) cout << #x << " = " << x << endl;
#define SZ(x) ((int)x.size())
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

int a[N], b[N], c[N];
int n, m, q, w, e;
int main() {
    FIO;
    cin >> n >> m >> q >> w >> e;
    LL ans = 0;
    rep(i, 1, q) cin >> a[i];
    rep(i, 1, w) cin >> b[i];
    rep(i, 1, e) cin >> c[i];
    sort(a+1, a+1+q);
    sort(b+1, b+1+w);
    sort(c+1, c+1+e);
    rep(i, 1, n) ans += a[q-i+1];
    rep(i, 1, m) ans += b[w-i+1];
    a[q+1] = b[w+1] = inf;
    int ql = q-n+1, wl = w-m+1, ce = e;
    while(ce) {
        if(min(a[ql], b[wl]) > c[ce]) break;
        if(a[ql] < b[wl]) ans += c[ce]-a[ql], ce--, ql++;
        else ans += c[ce]-b[wl], ce--, wl++;
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 1408
n, k = map(int, input().split())
mod = 10**9+7
A = {}
ans = 0
for i in range(k, 0, -1):
    A[i] = pow(k//i, n, mod)
    j = 2 * i
    while j <= k:
        A[i] -= A[j]
        j += i
    ans = (ans + A[i] * i) % mod
print(ans)


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

void main_()
{
    ll N, W;
    cin >> N >> W;
    vector<vector<ll>> dp(N + 1, vector<ll>(1000 * N + 1, W * N + 1));

    dp[0][0] = 0;

    for (ll i = 0; i < N; ++i) {
        ll w, v;
        cin >> w >> v;
        for (ll sum_v = 0; sum_v <= 1000 * N; ++sum_v) {
            if (sum_v - v >= 0) {
                dp[i + 1][sum_v] = min(dp[i + 1][sum_v], dp[i][sum_v - v] + w);
            }

            dp[i + 1][sum_v] = min(dp[i + 1][sum_v], dp[i][sum_v]);
        }
    }

    auto it = find_if(rbegin(dp[N]), rend(dp[N]),
        [W](auto a) { return a <= W; });
    cout << distance((++it), rend(dp[N])) << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 80256
#include<stdio.h>
int main(void){
  int x,y,z;
  while(1){
    scanf("%d %d",&x,&y);
    if(x==0&&y==0)return(0);
    if(y<x){
      z = x;
      x = y;
      y = z;
    }
    printf("%d %d\n",x,y);
  }
  return(0);
}

Measured memory_bytes: 1816
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include<queue>
#define R(i, n) for(int i = 0;i < n;i++)
#define S(a) scanf("%d", &a)
#define S2(a, b) scanf("%d%d", &a, &b)
#define S3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define P(a) printf("%d", a)
#define INF 1000000000
using namespace std;
using ll = long long;
using IR = pair<int, int>;

int N;
string S;

int main() {
	S(N);
	cin >> S;
	int ans = 1;
	for(int i = 1; i < N; i++) if (S[i] != S[i - 1]) ans++;
	P(ans);
}



Measured memory_bytes: 512
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define MAX_V 100005

struct sushi{ll t, d;};
bool CMP(sushi a,sushi b){
	return a.d>b.d;
}

int main(void){
	ll n,k,t,d;
	cin>>n>>k;
	vector<sushi> SUSHI;
	rep(i,n){
		cin>>t>>d;
		sushi inp;
		inp.t = t;
		inp.d = d;
		SUSHI.push_back(inp);
	}
	sort(SUSHI.begin(),SUSHI.end(),CMP);
	ll sumD = 0;
	ll kind = 0;
	vector<int> used;
	rep(i,n+1){
		used.push_back(0);
	}
	rep(i,k){
		sumD += SUSHI[i].d;
		if(used[SUSHI[i].t] == 0){
			kind++;
		}
		used[SUSHI[i].t]++;
	}
	ll ans = kind * kind + sumD;
	int l = k - 1;
	int r = k;

	while(l >= 0){
		if(used[SUSHI[l].t] >= 2){
			used[SUSHI[l].t]--;
			sumD -= SUSHI[l].d;
			while(r < n){
				if(used[SUSHI[r].t] == 0){
					used[SUSHI[r].t]++;
					kind++;
					sumD += SUSHI[r].d;
					ans = max(ans, kind*kind+sumD);
					r++;
					break;
				}
				r++;
			}
			if(r >= n){
				cout<<ans<<endl;
				return 0;
			}
		}
		l--;
	}

	cout<<ans<<endl;
	return 0;

}

Measured memory_bytes: 2672
def main():
    n = int(input())
    x = input()
    
    val = 0
    rui = 1
    mod = 0
    
    nagasa = 2*10**5+1
    #nagasa = 5
    d_li = [0]*(nagasa)
    
    for i in range(1,nagasa):
        t_v = i
        t_m = bin(t_v).count("1")
        ans = 0
        while t_v != 0:
            if d_li[t_v] != 0:
                ans += d_li[t_v]
                break
            ans += 1
            t_v %= t_m
            #t_m = bin(t_v).count("1")
        d_li[i] = ans
    
    #print(d_li)
    #exit()
    """
    for i in range(n):
        val += int(x[n-1-i])*rui
        rui *= 2
    """
    val = int(x, 2)
    #print(val)
    #exit()
    
    mod = bin(val).count("1")
    
    rui = pow(2,(n-1))
    
    t_v_p = val % (mod+1)
    if mod == 1:
        t_v_m = 0
    else:
        t_v_m = val % (mod-1)
        
    for i in range(n):
        ans = 0
        #t_v = val
        #t_m = mod
        if int(x[i]) == 1:
            if mod == 1:
                t_v = 0
            else:
                t_v = t_v_m
                t_v -= pow(2,(n-1-i),mod-1)
                #t_v -= rui % (mod-1)
                t_v %= (mod-1)
                ans += 1
                #t_m -= 1
        else:
            t_v = t_v_p
            t_v += pow(2,(n-1-i),mod+1)
            #print(t_v,rui)
            #t_v += rui % (mod+1)
            t_v %= (mod+1)
            ans += 1
            #t_m += 1
        rui //= 2
        #print(t_v,mod)
        #while t_v != 0:
        """
        if t_v != 0:
            if int(x[i]) == 1:
                if mod == 1:
                    t_v = 0
                else:
                    t_v %= mod-1
            else:
                t_v %= mod + 1
            #t_v %= t_m
            ans += 1
        """
        ans += d_li[t_v]
        #t_m = bin(t_v).count("1")
        #ans_li.append(ans)
        print(ans)
        #print(ans_li)
        
if __name__ == '__main__':
    main()
"""
#print(ans_li)
for i in range(n):
    print(ans_li[n-1-i])
"""

Measured memory_bytes: 94256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <cmath>
#include <cctype>
#include <stack>
#include <map>
#include <cstring>
#include <sstream>
#include <set>
#include <list>
#include <fstream>
#include <iomanip>
#include <assert.h>

#define ll long long
#define ull unsigned long long
#define pii std::pair<int, int>
#define op                            \
    std::ios::sync_with_stdio(false); \
    std::cin.tie(0);

const int INF = 0x3f3f3f3f;
const int maxn = (100000 + 10);
const int mod = (1e9 + 7);

int fac[] = {1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880};

int cantor(int s[], int l) {
    int sum = 0;
    for (int i = 0; i < l; ++i) {
        int num = 0;
        for (int j = i + 1; j < l; ++j)
            if (s[j] < s[i]) num++;
        sum += (num * fac[l - i - 1]);
    }
    return sum;
}

int main()
{
    int n, p[maxn], q[maxn];
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",&p[i]);
    for(int i=0;i<n;i++)
        scanf("%d",&q[i]);
    int ans=fabs(cantor(p,n)-cantor(q,n));
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	var line = input.split("\n");
	var tmp = line[0].split(" ");
	var str1 = tmp[0] + "";
	var str2 = tmp[1] + "";
	var str = str1 + str2;
	var num = Number(str);
	var sq = Math.sqrt(num);
	var sqint = Math.floor(sq);
	if(sq === sqint) console.log("Yes");
	else console.log("No");
	return false;
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
n = int(input())
x = tuple(map(int,input().split()))
x_sort = sorted(x,reverse=True)
x_median = x_sort[n//2-1]
x_median2 = x_sort[n//2]
for i in range(n):
    print(x_median2 if x[i] > x_median2 else x_median)

Measured memory_bytes: 26308
# 整数 a と、英小文字からなる文字列s が入力されます。
# a が3200 以上ならs と出力し、a が3200 未満なら red と出力するプログラムを書いてください。

#入力する整数を入力
a = int(input())
#整数が3200以上の時に出力する文字を入力
s = input()

if a >= 3200:
    print(s)
else:
    print("red")

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

int main()
{
string s ;
cin >> s ;
ll q ;
cin >> q ;
bool mae=1;
deque<char> d; 
rep(i,s.size()){
  d.push_back(s[i]);
}
rep(i,q){
  ll a ;
  cin >> a ;
  if(a==1){
  mae=!mae;
  }
  else{
    ll f ;
    char c ;
    cin >> f >> c ;
    if(f==1&&mae)d.push_front(c);
    else if(f==2&&!mae)d.push_front(c);
    else d.push_back(c);
  }
}
if(mae){
  rep(i,d.size()){
    cout <<d[i];
  }
  cout << endl;
}
else{
  rep(i,d.size()){
    cout <<d[d.size()-i-1];
  }
  cout << endl;
}
return 0;
}

Measured memory_bytes: 896
using System;

class Program {
  static void Main(){
    long n = int.Parse(Console.ReadLine());
    string[] s = Console.ReadLine().Split(' ');
    long i=0;
    long[] a = new long[n];
    for(i=0;i<n;i++){
      a[i] = int.Parse(s[i]);
    }
    long max = a[0],min = a[0],sum = a[0];
    for(i=1;i<a.Length;i++){
      if(a[i] < min){
        min = a[i];
      }
      if(a[i] > max){
        max = a[i];
      }
      sum += a[i];
    }
    Console.WriteLine("{0} {1} {2}",min,max,sum);
  }
}




Measured memory_bytes: 18028
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
typedef long long ll;

int main( void ) {
    char ch;
     do{
        ch = getchar();
        if( ch >= 'A' && ch <= 'Z' ) cout << char(ch + 32);
        else if( ch >= 'a' && ch <= 'z' ) cout << char(ch - 32);
        else cout << ch;
    } while( ch != '\n' );
    return 0;
}



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

using namespace std;

const int inf = 1e9;
int n, ans = inf, i; vector<int> v[30];
char ch; string s;

int solve(int p)
{
    if(v[p].empty()) return inf;

    int ans = max(v[p].front(), n - v[p].back() + 1);
    for(int i=0; i<v[p].size()-1; ++i)
        ans = max(ans, v[p][i+1] - v[p][i]);
    return ans;
}

int main()
{
    //freopen("input", "r", stdin);
    cin.sync_with_stdio(false);

    cin >> s;
    n = s.size();
    for(i=0; i<n; ++i)
        v[s[i]-'a'].push_back(i+1);

    for(i=0; i<26; ++i)
        ans = min(ans, solve(i));
    cout << ans - 1 << '\n';

    return 0;
}


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

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

//container util
//------------------------------------------
#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

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



ll mod = 1e9+7;

int main(){
    ll n,k,ans=0;
    cin>>n >>k;
    vector<ll> a(n),r(n,0),l(n,0);
    rep(i,n)cin>>a[i];
    
    rep(i, n){
        rep(j, n){
            if(i==j)continue;
            if(i<j&&a[i]>a[j])r[i]++;
            else if(i>j&&a[i]>a[j])l[i]++;
        }
    }
    
    rep(i, n){
        if(r[i]==0&&l[i]==0)continue;
        ans+=k*(k+1)/2%mod*r[i];
        ans%=mod;
        ans+=k*(k-1)/2%mod*l[i];
        ans%=mod;
    }
    
    cout<<ans<<endl;
}

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

const int MAX_N = 103;
vector<int> E[MAX_N];


int solve(int s, int d, int v) {
  int vis[MAX_N];
  queue<int> que;
  fill(vis, vis+MAX_N, -1);
  vis[s] = 1;
  que.push(s);
  while(!que.empty()) {
    int p = que.front();
    que.pop();
    for(int i = 0; i < E[p].size(); ++i) {
      int np = E[p][i];
      if(vis[np] != -1) continue;
      vis[np] = vis[p] + 1;
      if(np == d) {
	if(v >= vis[np]) return vis[np];
	else return -1;
      }
      que.push(np);
    }
  }
  return -1;
}

int main() {
  int n;
  while(cin >> n && n) {
    for(int i = 0; i < MAX_N; ++i) E[i].clear();
    for(int i = 0; i < n; ++i) {
      int r, k;
      cin >> r >> k;
      for(int j = 0; j < k; ++j) {
	int t;
	cin >> t;
	E[r].push_back(t);
      }
    }
    int p;
    cin >> p;
    for(int i = 0; i < p; ++i) {
      int s, d, v;
      cin >> s >> d >> v;
      int ans = solve(s,d,v);
      if(ans == -1) cout << "NA" << endl;
      else cout << ans << endl;
    }
  }
  return 0;
}

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

//                                1   2   3   4   5   6   7   8   9  10  11  12
int normal_days_of_month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

bool is_uruu(int year) {
    if (year % 400 == 0) {
        return true;
    }
    if (year % 4 == 0 && year % 100 != 0) {
        return true;
    }
    return false;
}

int all_days_of_ym(int year, int month) {
    if (month == 2 && is_uruu(year)) {
        return 29;
    }
    return normal_days_of_month[month];
}

int imamade_days_of_ymd(int year, int month, int day) {
    int result = 0;
    for (int im=1; im<month; im++) {
        result += all_days_of_ym(year, im);
    }
    result += day;
    return result;
}

int all_days_of_year(int year) {
    return imamade_days_of_ymd(year, 12, 31);
}

int nokori_days_of_ymd(int year, int month, int day) {
    return all_days_of_year(year) - imamade_days_of_ymd(year, month, day);
}

int minus_days_ymd(int y1, int m1, int d1, int y2, int m2, int d2) {
    if (y1 == y2) {
        return imamade_days_of_ymd(y2, m2, d2) - imamade_days_of_ymd(y1, m1, d1);
    }
    int result=0;
    result += nokori_days_of_ymd(y1, m1, d1);
    int iy;
    for (iy=y1+1; iy<y2; iy++) {
       result += all_days_of_year(iy);
    }
    result += imamade_days_of_ymd(y2, m2, d2);
    return result;
}

int main(void){
    int y1, m1, d1, y2, m2, d2;
    while (1) {
        cin >> y1 >> m1 >> d1 >> y2 >> m2 >> d2;
        if (y1<0 || m1<0 || d1<0 || y2<0 || m2<0 || d2<0) {
            break;
        }
        cout << minus_days_ymd(y1, m1, d1, y2, m2, d2) << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;
using namespace std;
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
//     tree_order_statistics_node_update>;
 
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
typedef long long int ll;
typedef long double ld;
const ll N = 1e5+9;
// const ll m = 1e9 + 7;
// const ll inf= 1e14;
const ll mod =998244353;
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define pld pair<ld,ld>
ll powm(ll a, ll b) { a = a%mod;ll res = 1; while (b) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b >>= 1; } return res; }
ll a[N];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout); 
    #endif  
    int t = 1;
    // cin>>t;
    while(t--){
        ll n,k;cin>>n>>k;
        ll ps[n],ps1[n];

        for(int i = 0;i<n;i++){
            cin>>a[i];
            ps[i] = max(0ll,a[i]);
            ps1[i] = a[i];
        }
        for(int i = 1;i<n;i++){
            ps[i]+=ps[i-1];
            ps1[i]+=ps1[i-1];
        }
        // for(int i = 0;i<n;i++){
        //     cout<<ps[i]<<" ";
        // }
        // cout<<'\n';
        // for(int i = 0;i<n;i++){
        //     cout<<ps1[i]<<" ";
        // }
        // cout<<'\n';
        ll ans = 0;
        for(int i = 0;i<n-k+1;i++){
            ll te =0;
            if(i==0){
                te = ps[n-1]-ps[i+k-1] +max(ps1[i+k-1],0ll);
            }
            else{
                te = ps[n-1] -ps[i+k-1]+ps[i-1]+max(ps1[i+k-1]-ps1[i-1],0ll);
            }
            ans = max(ans,te);

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

Measured memory_bytes: 5968
#include<bits/stdc++.h>
using namespace std;
int n,a[50];
int solve(int i,int m){
  if(m==0)return 1;
  if(i>=n)return 0;
  int re = solve(i+1,m)||solve(i+1,m-a[i]);
  return re;
}
int main(){
  int m,x;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  cin >> m;
  for(int i=0;i<m;i++){
    cin >> x;
    if(solve(0,x))cout << "yes" << endl;
    else cout << "no" << endl;
  }
  return 0;
}

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

template<typename T>
istream &operator>>(istream &is, vector<T> &v) {
	for (auto &x : v) is >> x;
	return is;
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, m, v, p; cin >> n >> m >> v >> p;
	vector<int> a(n); cin >> a;
	sort(a.rbegin(), a.rend());
	int l = p, r = n;
	while (l < r) {
		int mid = (l + r + 1) / 2;
		long long sum = 0;
		for (int i = 0; i < n; i++) {
			if (i < p - 1 || i >= mid - 1) {
				sum += m;
			} else {
				if (a[i] > a[mid - 1] + m) {
					sum = -1;
					break;
				}
				sum += (a[mid - 1] + m) - a[i];
			}
		}
		if (sum >= (long long) m * v) {
			l = mid;
		} else {
			r = mid - 1;
		}
	}
	cout << l << '\n';
	return 0;        
}


Measured memory_bytes: 3688
import java.util.Scanner;

class Main {
  public static void main(String args[]) {
        Scanner scanner1 = new Scanner(System.in);
        //System.out.println("数値を入力してください。");
        //Scanner scanner2 = new Scanner(System.in);
        //System.out.println("数値を入力してください。");
        double n = scanner1.nextInt();
        double m = scanner1.nextInt();
        double l;
        l = n/m;
        System.out.println(l);
  }
}

Measured memory_bytes: 20948
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <sstream>
#include <limits.h>
using namespace std;
 
int main()
{
    int a,b,c,kk;
    cin >> a >> b >> c;
    cin >> kk;

    for(int i=0; i<=kk; i++){ //a 
        int aa = a; if(i!=0) for(int t=0; t<i; t++) aa = aa*2; else aa = a;
        for(int j=0; j<=kk; j++){ //b
            int bb = b; if(j!=0) for(int t=0; t<j; t++) bb = bb*2; else bb = b;
            for(int k=0; k<=kk; k++){ //c
                int cc = c;  if(k!=0) for(int t=0; t<k; t++) cc =cc*2; else cc = c;
                if(i+j+k > kk) break;
                //cout << aa  << "," << bb << "," << cc << endl;
                //cout << i<< "," << j<< "," << k << endl;
                if(aa < bb && bb < cc){
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }

    cout << "No"<< endl;
    return 0;
}

Measured memory_bytes: 3628
import sys
sys.setrecursionlimit(10**7)

def saiki(s):
    global cnt,n
    L = ["3","5","7"]
    if eval(s) <= n:
        if len(set(s)) == 3:
            cnt += 1
        for i in L:
            saiki(s+i)

n = int(input())
cnt = 0
for i in ["3","5","7"]:
    saiki(i)
print(cnt)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=605;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int n,x,y,cnt;
bool h[N][N];
void paint(int x){
	int k=0,fl;
	while (x%4==0){x/=4;k++;}
	fl=x&1;
	for (int i=0;i<n;i++)
	for (int j=0;j<n;j++)
	if (((i>>k)&1)^((j>>k)&fl)) h[i][j]=1;
}
int main(){
	n=read()*2;x=read();y=read();cnt=n*n/4;
	paint(x);paint(y);
	for (int i=0;i<n;i++)
	for (int j=0;j<n;j++)
	if (!h[i][j]){
		printf("%d %d\n",i,j);
		if (!(--cnt)) return 0;
	}
	return 0;
}

Measured memory_bytes: 1280
H, W, K = gets.split.map(&:to_i)
X1, Y1, X2, Y2 = gets.split.map(&:to_i)
Cs = [[false]*(W + 2)] + readlines.map{|l| [false] + l.chomp.chars.map{_1 == '.'} + [false]} + [[false]*(W + 2)]
@q = [[X1, Y1, 0]]
@cs = Array.new(H + 2){Array.new(W + 2, 10**10)}
@cs[X1][Y1] = 0
f = ->(x, y, c){(@q << [x, y, c]; @cs[x][y] = c) if c < @cs[x][y]}
while !@q.empty?
  x, y, c = @q.shift
  (puts c; exit) if [x, y] == [X2, Y2]
  d = c + 1
  a = x - 1
  while Cs[a][y] && @cs[a][y] > c && x - a <= K
    f[a, y, d]
    a -= 1
  end
  a = x + 1
  while Cs[a][y] && @cs[a][y] > c && a - x <= K
    f[a, y, d]
    a += 1
  end
  b = y - 1
  while Cs[x][b] && @cs[x][b] > c && y - b <= K
    f[x, b, d]
    b -= 1
  end
  b = y + 1
  while Cs[x][b] && @cs[x][b] > c && b - y <= K
    f[x, b, d]
    b += 1
  end
end
puts -1

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

#define debug(var)  do{ std::cout << #var << " : "; view(var); }while(0)
using ll = long long;
using ld = long double;
inline int num (const std::string& S, int idx) noexcept { return S.at(idx) - '0'; }
inline int ctoi(char c) noexcept { return c - '0'; }
inline bool isNumber(char c) noexcept { return ('0'<=c && c<='9'? true : false); }
inline int safeCtoi(char c) { if(isNumber(c)) { return ctoi(c); } else { throw 1; } }
inline char itoc(int i) noexcept { return i + '0'; }
inline unsigned int bitMask(int i) noexcept { return (1 << i); }
inline bool isTrue(unsigned int bit, int i) noexcept { return bit & bitMask(i); }
inline bool isEven(int num) noexcept { return !num%2; }
inline bool isOdd(int num) noexcept { return num%2; }
template<typename T> inline short sgn(T num) noexcept { return (num==0? 0 : (num>0? 1 : -1) ); }
template<typename T> inline bool isZero(T num) noexcept { return (num==0? true : false); }
template<typename T> inline bool isPositive(T num) noexcept { return (num>0? true : false); }
template<typename T> inline bool isNegative(T num) noexcept { return (num<0? true : false); }
template<typename T> void view(T e) noexcept { cout << e; }
template<typename T> void view(std::vector<T> v) noexcept { for(const auto& e : v) cout << e << " "; }
template<typename T> void view(std::vector<std::vector<T>> vv) noexcept { for(const auto& v : vv) view(v); }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a;
	cin >> a;
	for (int i=0; i<a; ++i) {
		std::cout << "ACL";
	}
	std::cout << endl;
	return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()
#define chmax(x,y) x=max(x,y)




int main(){
    int n; cin>>n;
    vector<int> p(n);
    rep(i,n) cin>>p[i];
    int ma=0, mi=0;
    rep(i,n){
        if(p[i]>p[ma]) ma=i;
        if(p[i]<p[mi]) mi=i;
    }
    if(p[mi]>=0){
        cout<<2*n<<endl;
        rep(ii,2){
            cout<<ma+1<<" "<<1<<endl;
        }
        rep(i,n-1){
            rep(jj,2){
                cout<<1+i<<" "<<2+i<<endl;
            }
        }
    }else{
        if(p[ma]<=0){
            cout<<2*n<<endl;
            rep(ii,2){
                cout<<mi+1<<" "<<n<<endl;
            }
            rep(i,n-1){
                rep(jj,2){
                    cout<<n-i<<" "<<n-1-i<<endl;
                }
            }
        }else{
            if(p[ma]>=abs(p[mi])){
                cout<<2*n<<endl;
                rep(ii,2){
                    cout<<ma+1<<" "<<1<<endl;
                }
                rep(i,n-1){
                    rep(jj,2){
                        cout<<1+i<<" "<<2+i<<endl;
                    }
                }
            }else{
                cout<<2*n<<endl;
                rep(ii,2){
                    cout<<mi+1<<" "<<n<<endl;
                }
                rep(i,n-1){
                    rep(jj,2){
                        cout<<n-i<<" "<<n-1-i<<endl;
                    }
                }
            }
        }
    }
}

Measured memory_bytes: 3612
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-5;
const ld pi = acos(-1.0);

int n;
void solve() {
	cin >> n;
	int l[3]; rep(i, 3)cin >> l[i];
	vector<int> a(n);
	rep(i, n) {
		cin >> a[i];
	}

	int t = 1;
	rep(i, n) {
		t *= 4;
	}
	int ans = mod;
	rep(i, t) {
		vector<int> b[4];
		int cop = i;
		rep(j, n) {
			b[cop % 4].push_back(j);
			cop /= 4;
		}
		if (b[0].empty() || b[1].empty() || b[2].empty())continue;
		//cout << "hello" << endl;
		int cost = 0;
		rep(j, 3) {
			int len = b[j].size();
			int sum = 0;
			cost += 10 * (len - 1);
			rep(k, len) {
				sum += a[b[j][k]];
			}
			cost += abs(sum - l[j]);
		}
		//cout << cost << endl;
		ans = min(ans, cost);
	}
	cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(50);
	//init();
	solve();

	//cout << "finish" << endl;
	//stop
		return 0;
}


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

using namespace std;

typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef pair<uint, uint> puu;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<uint> vu;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;
typedef vector<puu> vpuu;
typedef vector<pll> vpll;
typedef vector<pull> vpull;
typedef vector<string> vstr;
typedef vector<double> vdbl;
typedef vector<ldbl> vldbl;
#define pb push_back
#define ppb pop_back
#define pfr push_front
#define ppfr pop_front
#define emp emplace
#define empb emplace_back
#define be begin
#define rbe rbegin
#define all(x) (x).be(), (x).end()
#define rall(x) (x).rbe(), (x).rend()
#define fir first
#define sec second
#define mkp make_pair
#define brif(cond) if (cond) break
#define ctif(cond) if (cond) continue
#define retif(cond) if (cond) return
void canhazfast() {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a%b) : a;}
template<typename T> T extgcd(T a, T b, T &x, T &y)
{
    T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
    while (b) {
        T q = a/b; a %= b; swap(a, b);
        x0 -= q*x1; swap(x0, x1);
        y0 -= q*y1; swap(y0, y1);
    }
    x = x0; y = y0; return a;
}
int ctz(uint x) {return __builtin_ctz(x);}
int ctzll(ull x) {return __builtin_ctzll(x);}
int clz(uint x) {return __builtin_clz(x);}
int clzll(ull x) {return __builtin_clzll(x);}
int popcnt(uint x) {return __builtin_popcount(x);}
int popcntll(ull x) {return __builtin_popcountll(x);}
int bsr(uint x) {return 31^clz(x);}
int bsrll(ull x) {return 63^clzll(x);}

int main()
{
    canhazfast();

    int n, k;

    cin >> n >> k;
    cout << (k > 1 ? n-k : 0) << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>
#include<iso646.h>
#include<bitset>

#ifndef M_PI
#define M_PI 3.14159265358979
#endif
#define deg_to_rad(deg) (((deg)/360)*2*M_PI)
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main() {
	ll i, j;
	ll N;
	cin >> N;
	vll P(N);
	for (auto& e : P)cin >> e;
	ll m = N + 1;
	ll ans = 0;
	for (i = 0; i < N; i++) {
		if (m > P[i]) {
			m = P[i];
			ans++;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1792
l=[int(input()) for i in range(3)]
x=int(input())
ans=0
count=0
for i in range(1+l[0]):
    for j in range(1+l[1]):
        for k in range(1+l[2]):
            ans=500*i+100*j+50*k
            if ans==x:
                count+=1
print(count)

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

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

    std::map<char, int> m;
    for (int i = 0; i < s.length(); i++)
    {
        m[s[i]]++;
    }

    for (char c = 'a'; c <= 'z'; c++)
    {
        if (m[c] == 0)
        {
            cout << c << endl;
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}


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


int main(void){
int e=0,y=0;
cin>>e>>y;
if(e == 0){
if(y >= 1868&& y <= 1911){
cout << "M" << y - 1867<<endl;
}
else if(y>=1912&&y<=1925)
{
cout<<"T"<<y-1911<<endl;
}
else if(y>=1926&&y<=1988)
{cout<<"S"<<y-1925<<endl;
}
else {
cout<<"H"<<y-1988<<endl;
}
}
else{switch (e)
{

case 1:cout<<y+1867<<endl;  break;
case 2:cout<<y+1911<<endl;  break;
case 3:cout<<y+1925<<endl;  break;
case 4:cout<<y+1988<<endl;  break;
}
}



return 0;
}

Measured memory_bytes: 3100
n=int(input())
a=list(map(int,input().split()))
b=[]

suc=0
for i in range(n-1):
  if a[i] >= a[i+1]:
    suc += 1
  else:
    b.append(suc)
    suc=0
b.append(suc)
print(max(b))


Measured memory_bytes: 14224
N, K = map(int, input().split())
H = list(map(int, input().split()))

N += 1
H = [0] + H

DP = [[float('inf')] * N for _ in range(N)]
DP[0][0] = 0
for i in range(1, N):
  DP[i][1] = H[i]
  for j in range(2, i + 1): 
    for k in range(1, i):
      DP[i][j] = min(DP[i][j], DP[k][j - 1] + max(0, H[i] - H[k]))

ans = float('inf')
for i in range(N):
    ans = min(ans, DP[i][N - K - 1])

print(ans)


Measured memory_bytes: 46172
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    bool flag=false;
    for(int i=1;i<=n;i++)
    {
        int x;scanf("%d",&x);
        if(x&1) flag=true;
    }
    printf(flag?"first":"second");
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int, int> P;
signed main() {
	int n, k; cin >> n >> k;
	string s; cin >> s;
	string t = s;
	string inf;
	rep(i, 10000)inf.push_back('z');
	reverse(t.begin(), t.end());
	rep(z, k - 1) {
		string s1 = s + t;
		string maxs = inf;
		rep(i, n) {
			string now;
			for (int j = i; j < i + n; j++)now.push_back(s1[j]);
			if (maxs > now)maxs = now;
		}
		s = maxs;
		t = maxs;
		reverse(s.begin(), s.end());
		int cnt = 0;
		rep(i, n)if (s1[i] == s1[0])cnt++;
		if (cnt == n)break;
		//cout << s << endl;
	}
	string s1 = s + t;
	string ans = inf;

	rep(i, n) {
		string now;
		for (int j = i; j < i + n; j++) {
			now.push_back(s1[j]);
		}
		if (now < ans)ans = now;
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	int N;
	cin >> N;
	int A[100010];
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	int ans = 0;
	A[N] = 0;
	for (int i = 0; i < N; i++) {
		if (A[i] == i + 1) {
			ans++;
			swap(A[i], A[i + 1]);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

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

using namespace std;

int main() {
  while(1) {
    int n,t,l,b;
    cin>>n>>t>>l>>b;
    if(!n)break;
    vector<bool> isl(n+1,false);
    vector<bool> isb(n+1,false);
    REP(i,l) {
      int li;
      cin>>li;
      isl[li] = true;
    }
    REP(i,b) {
      int bi;
      cin>>bi;
      isb[bi] = true;
    }
    vector<double> prob(n+1);
    vector<double> prob_l(n+1);
    prob[0] = 1.0;
    REP(i,t) {
      vector<double> nprob(n+1);
      REP(j,n) {
        if(!isl[j] && !isb[j]) {
          REP(k,6) {
            int ind = (j+k+1>n)?(2*n-(j+k+1)):(j+k+1);
            nprob[ind] += prob[j]/6.0;
          }
        } else if(isl[j]) {
          REP(k,6) {
            int ind = (j+k+1>n)?(2*n-(j+k+1)):(j+k+1);
            nprob[ind] += prob_l[j]/6.0;
          }
        }
      }
      REP(j,n) {
        if (isb[j]) {
          nprob[0] += nprob[j];
          nprob[j] = 0;
        }
      }
      nprob[n] += prob[n];
      prob_l = prob;
      prob = nprob;
    }
    cout <<setprecision(10) << fixed << prob[n] << endl;
  }
  return 0;
}

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

int main(){
string S, T;
cin >> S >> T;
    
int ans = 0;
for (int i = 0; i < 3; i++){
  if (S.at(i) == T.at(i)){
   ans++;  

}
}
  cout << ans << endl;
}

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

const int END = -1;
struct StNod
{
  int m_nDept;
  int m_nParnt;
  int m_nLChd;
  int m_nRSib;

  StNod() :
    m_nDept(END), m_nParnt(END), m_nLChd(END), m_nRSib(END)
  { }
};

void fnInput(vector<StNod> &rvoNod)
{
  StNod oNod;
  int nMaxSiz;

  cin >> nMaxSiz;
  rvoNod.resize(nMaxSiz, oNod);

  for (int i = 0; i < nMaxSiz; i++)
  {
    int nParnt, nCCnt, nChd, nBChd = END;
    cin >> nParnt >> nCCnt;
    for (int j = 0; j < nCCnt; j++)
    {
      cin >> nChd;
      rvoNod[nChd].m_nParnt = nParnt;
      if (nBChd != END) rvoNod[nBChd].m_nRSib = nChd;
      if (!j)          rvoNod[nParnt].m_nLChd = nChd;
      nBChd = nChd;
    }
  }
}

void fnSetDepth(vector<StNod> &rvoNod, int nx, int nDept)
{
  rvoNod[nx].m_nDept = nDept;
  
  if (rvoNod[nx].m_nRSib != END)
    fnSetDepth(rvoNod, rvoNod[nx].m_nRSib, nDept);

  if (rvoNod[nx].m_nLChd != END)
    fnSetDepth(rvoNod, rvoNod[nx].m_nLChd, nDept + 1);
}

void fnRtdTree(vector<StNod> &rvoNod)
{
  int nx = 0, nDept = 0;
  while (rvoNod[nx].m_nParnt != END)
    nx = rvoNod[nx].m_nParnt;

  fnSetDepth(rvoNod, nx, nDept);
}

void fnResult(const vector<StNod> &cnrvoNod)
{
  for (int i = 0; i < cnrvoNod.size(); i++)
  {
    if (cnrvoNod[i].m_nDept == END)  break;
    cout << "node " << i << ": parent = " << cnrvoNod[i].m_nParnt << ", depth = " << cnrvoNod[i].m_nDept;

    if (!cnrvoNod[i].m_nDept)            cout << ", root, ";
    else if (cnrvoNod[i].m_nLChd == END) cout << ", leaf, ";
    else                                 cout << ", internal node, ";

    cout << "[";
    if (cnrvoNod[i].m_nLChd != END)
    {
      int nx = cnrvoNod[i].m_nLChd;
      cout << nx;
      while (cnrvoNod[nx].m_nRSib != END)
      {
        cout << ", " << cnrvoNod[nx].m_nRSib;
        nx = cnrvoNod[nx].m_nRSib;
      }
    }
    cout << "]" << endl;
  }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<StNod> voNod;

  fnInput(voNod);
  fnRtdTree(voNod);
  fnResult(voNod);
  return 0;
}

Measured memory_bytes: 5752
def atc_142b(NK_input: str, hi_input: str) -> int:
    N, K = map(int, NK_input.split(" "))
    hi = [int(i) for i in hi_input.split(" ")]
    hi = sorted(hi)
    for i in range(0, len(hi)):
        if hi[i] >= K:
            return len(hi) - i
    return 0


NK_input_value = input()
hi_input_value = input()
print(atc_142b(NK_input_value, hi_input_value))


Measured memory_bytes: 18952
N = int(input())
s = ["".join(sorted(input())) for _ in range(N)]

s_dic = {}
ans = 0

for si in range(N):
    if s[si] in s_dic.keys():
        ans += s_dic[s[si]]
        s_dic[s[si]] += 1
    else:
        s_dic[s[si]] = 1
print(ans) 

Measured memory_bytes: 19504
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        a: usize,
        b: usize,
        t: usize
    }
    println!("{}", t / a * b);
}


Measured memory_bytes: 4352
#include <iostream>

using namespace std;

int main()
{
    string str;
    for(int i=0;i<4;i++){
        cin>>str[i];
    }
    if((str[0]==str[1])||(str[1]==str[2])||(str[2]==str[3])){
        cout<<"Bad";
    }
    else
        cout<<"Good";
}

Measured memory_bytes: 384