akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"fmt"
)

func sortRune(list []rune, desc bool) {
	eNum := len(list)
	for i := eNum; i > 0; i-- {
		for j := 0; j < i-1; j++ {
			if desc {
				if list[j] < list[j+1] {
					list[j], list[j+1] = list[j+1], list[j]
				}
			} else {
				if list[j] > list[j+1] {
					list[j], list[j+1] = list[j+1], list[j]
				}
			}
		}
	}
}


func sort(s string, desc bool) string {
	r := []rune(s)
	sortRune(r, desc)
	return string(r)
}

func main() {
	var s, t string
	fmt.Scan(&s, &t)

	ss := sort(s, false)
	tt := sort(t, true)

	if ss < tt {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}

Measured memory_bytes: 512
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string.h>
#include <algorithm>
#include <map>
using namespace std;
const int maxn = 5e6;
int n = 0, q = 0;

struct Query{
	int id, l, r;
	bool operator< (Query a) const{
		return r < a.r;
	}
}query[maxn];



int v[maxn], sum[maxn], ans[maxn];

int lowbit(int x){
	return x & (-x);
}

void change(int i, int a){
	while(i <= n){
		sum[i] += a;
		i += lowbit(i);
	}
}

int getsum(int i){
	int sum_t = 0;
	while(i > 0){
		sum_t += sum[i];
		i -= lowbit(i);
	}
	return sum_t;
}

int main() {

#ifdef DEBUG
	freopen("C:/Users/Fish_Brother/Desktop/in", "r", stdin);
	//freopen("C:/Users/Fish_Brother/Desktop/out", "w", stdout);
#endif
	while(~scanf("%d", &n)){
		memset(v, 0, sizeof(v));
		memset(sum, 0, sizeof(sum));
		memset(ans, 0, sizeof(ans));
		
		int t = 0;
		scanf("%d", &q);
		for(int i = 1; i <= n; i++){
			scanf("%d", &v[i]);
		}
		
		for(int i = 1; i <= q; i++){
			scanf("%d%d", &query[i].l, &query[i].r);
			query[i].id = i;
		}
		sort(query + 1, query + q + 1);
		
		int pre = 1;
		map<int, int> mymap;
		for(int i = 1; i <= q; i++){
			for(int j = pre; j <= query[i].r; j++){
				//已存在 
				if(mymap[v[j]]){
					change(mymap[v[j]], -1);
				}
				mymap[v[j]] = j;
				change(j, 1);
			}
			pre = query[i].r + 1;
			ans[query[i].id] = getsum(query[i].r) - getsum(query[i].l - 1);
		}
		
		for(int i = 1; i <= q; i++){
			cout << ans[i] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 91756
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359
int N;
LL a[3000];
LL dp[3000][3000];
LL solve(int l, int r){
	if(l > r) return 0;
	if(dp[l][r] != -1) return dp[l][r];
	int now = l+(N-r+1);
	if(now%2 == 0) return dp[l][r] = max(a[l]+solve(l+1,r),a[r]+solve(l,r-1));
	else return dp[l][r] = min(-a[l]+solve(l+1,r),-a[r]+solve(l,r-1));
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << setprecision(9);

	cin >> N;
	for(int i=0; i<N; i++) cin >> a[i];
	for(int i=0; i<N; i++){
		for(int j=0; j<N; j++){
			dp[i][j] = -1;
		}
	}
	cout << solve(0,N-1) << endl;

	return 0;
}


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

int main() {
  int N; cin >> N;
  vector<long long> L(N+1);
  L[0] = 2; L[1] = 1;
  for (int i = 2; i <= N; i++) L[i] = L[i-1] + L[i-2];
  cout << L[N] << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int heap[251], n;
	scanf("%d", &n);
	for (int i=1 ; i<=n ; i++)
		scanf("%d", heap+i);
    
	for (int i=1 ; i<=n ; i++) {
		printf("node %d: key = %d, ", i, heap[i]);
		if (i/2 > 0)        printf("parent key = %d, ", heap[i/2]);
		if (2*i <= n)       printf("left key = %d, ", heap[2*i]);
		if (2*i+1 <= n)     printf("right key = %d, ", heap[2*i+1]);
        printf("\n");
	}
	return 0;
}



Measured memory_bytes: 2056
# import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10 ** 7)
enu = enumerate
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep="\n")

N = int(input())
A = list(map(int, input().split()))

d = defaultdict(int)
for a in A:
    d[a] += 1
cnt = 0
for key, val in d.items():
    if key <= val:
        cnt += val - key
    else:
        cnt += val
print(cnt)


Measured memory_bytes: 102012
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int count = sc.nextInt();

    float total = 0;
    for (int i = 0; i < count ; i++ ) {

      float money = sc.nextFloat();
      String type = sc.next();

      if (type.equals("JPY")) {
        total += money;
      } else if (type.equals("BTC")) {
        float bit = 380000.0f;
        total += money * bit;
      }
    }

    System.out.println(total);
  }
}


Measured memory_bytes: 23252
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		String s = r.readLine();
		String[] str = s.split(" ");
		int k = Integer.parseInt(str[0]);
		int x = Integer.parseInt(str[1]);

		if (500 * k >= x) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

		r.close();
	}
}

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

inline int read()
{
	int x=0,f=1;
	char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') {x=(x<<3)+(x<<1)+c-'0';c=getchar();}
	return x*f;
}

int main()
{
	int t,x;double ans;
	t=read();x=read();
	ans=1.0*t/x;
	printf("%.4lf\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fr first
#define sc second
const int mod = 1e9+7;
const int N = 1e6+6;
vector<pair<int,int> > v[N];
bool vis[N];
int ans[N],mx;
void dfs(int x, int cl){
    vis[x] = true;
    mx = max(mx,cl);
    int clr = 1;
    for(auto p:v[x]){
        int y = p.fr;
        int id = p.sc;
        if(vis[y])continue;
        if(clr==cl)clr++;
        ans[id] = clr;
        dfs(y,clr);
        clr++;
    }
}
int main(){
    int n;
    cin>>n;
    int a,b;
    for(int i=1;i<n;i++){
        cin>>a>>b;
        v[a].pb({b,i});
        v[b].pb({a,i});
    }
    dfs(1,0);
    cout<<mx<<endl;
    for(int i=1;i<n;i++){
        cout<<ans[i]<<endl;
    }
}


Measured memory_bytes: 33520
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


s = input().replace('BC', 'D')

cnt = 0
res = 0
for i in range(len(s)):
    if s[i] == 'A':
        cnt += 1
    elif s[i] == 'D':
        res += cnt
    else:
        cnt = 0
print(res)


Measured memory_bytes: 3500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    //freopen("in.txt","r",stdin);
    int n,k;
    cin >> n >> k;
    vector< int > dice(n);
    for(int i=0;i<n;i++){
        cin >> dice[i];
    }
    double sum=0,max_sum = 0;
    for(int i=0;i<n;i++){
        sum += (dice[i]+1)*1.0/2;
        if(i>=k){
            sum -= (dice[i-k]+1)*1.0/2;
        }
        max_sum = max(max_sum,sum);
    }
    cout.precision(10);
    cout << fixed << max_sum << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (int i=0; i<n; ++i)
#define all(c) begin(c),end(c)
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
/*
全部の数の約数とりたい


各桁毎の素数の数一覧
範囲	0の数	素数の個数
10まで	10^1	1	4
100まで	10^2	2	25
1000まで	10^3	3	168
1万まで	10^4	4	1229
10万まで	10^5	5	9592
100万まで	10^6	6	78498
1000*10^6まで

1000までの素数とってそれで探索。
*/
vector<int> prime(0, 0);

void eratos(int n){
  vector<bool> N(n+10,true);
  N[0] = false;
  N[1] = false;
  for(int i=2; i<=n; i++){
    if (N[i])
      prime.push_back(i);
    int j=2;
    while (i*j <= n)
      N[i*j++] = false;
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  eratos(1100);//nまでの素数を抽出
  
  int N; cin>>N;
  vector<int> A(N,0), B(1000010, 0);
  int ans = 2;
  rep(k,N){
    int a;
    cin >> a;
    for(int i=0; prime[i]*prime[i] <= a; i++){
      int p = prime[i];
      if (a%p == 0){
        if (B[p] > 0)
          ans = 1;
        B[p]++;
        while (a%p == 0)
          a /= p;
      }
    }
    if (a > 1){
      if (B[a] > 0)
        ans = 1;
      B[a]++;
    }
  }
  if (ans == 2){
    cout << "pairwise coprime" <<endl;
    return 0;
  }
  for(int i=2; i<=1000000; i++){
    if (B[i] == N){
      cout << "not coprime" <<endl;
      return 0;
    }
  }
  cout << "setwise coprime" << endl;
}

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

using namespace std;

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

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
  each(x,vec) is >> x;
  return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
  rep(i,vec.size()) {
    if (i) os << " ";
    os << vec[i];
  }
  return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
  rep(i,vec.size()) {
    if (i) os << endl;
    os << vec[i];
  }
  return os;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, h, w; cin >> h >> w >> n;
  const ll base = 2 * (w + h);
  map<ll, vector<ll>> m;
  auto f = [&](ll x, ll y) {
    if (y == 0) return x;
    if (x == w) return w + y;
    if (y == h) return w + h + (w - x);
    if (x == 0) return w + h + w + (h - y);
    return -1LL;
  };
  rep(i, n) {
    ll y1, x1, y2, x2; cin >> y1 >> x1 >> y2 >> x2;
    if (f(x1, y1) >= 0 && f(x2, y2) >= 0) {
      ll l = f(x1, y1), r = f(x2, y2);
      if (r < l) swap(l, r);
      // cout << l << " " << r << endl;
      m[l].pb(r);
      m[base + l].pb(base + r);
    }
  }
  bool ans = true;
  stack<ll> R; R.push(linf);
  each(p, m) {
    while (R.top() < p.first) R.pop();
    assert(p.second.size() == 1);
    each(r, p.second) {
      if (r > R.top()) ans = false;
      R.push(r);
    }
  }
  if (ans) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 22608
n, k, q = map(int,input().split())
List = [k for i in range(n)]
counter = 0
for _ in range(q):
  a = int(input())
  List[a-1] += 1
  counter -= 1

List = [s+counter for s in List]

for t in range(n):
  if List[t] >=1:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 9884
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
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(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K; cin >> N >> K;
  vector<int> p(N);
  REP(i, N){
    cin >> p[i];
  }
  sort(p.begin(), p.end());
  int ans = 0;
  REP(i, K){
    ans += p[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 3656
N = int(input())
P = [int(x) - 1 for x in input().split()]
now = 0
ans = 0
while now < N:
    if P[now] == now:
        start = now
        while now < N and P[now] == now:
            now += 1
        ans += (now - start) // 2 + (now - start) % 2
    else:
        now += 1
print(ans)


Measured memory_bytes: 13880
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;
bool ac[1001001]={false};
int main(){
    fast_io

    int n, m;
    cin>>n>>m;
    vector<int> p(m);
    vector<string> S(m);
    int ans=0;
    int pena=0;
    rep(i,m) {
        cin>>p[i]>>S[i];
        if(S[i]=="WA" && ac[p[i]-1]==false){
            pena++;
        }else if(S[i]=="AC" && ac[p[i]-1]==false){
            ac[p[i]-1]=true;
            ans++;
        }
    }
    rep(i,m){
        if(ac[p[i]-1]==false) pena--;
    }
    cout<<ans<<" "<<pena<<endl;
    return 0;

}


Measured memory_bytes: 6272
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define inf 500000000
#define IOS ios_base::sync_with_stdio(0)
#define meM(y,a) memset(y,a,sizeof y)
#define sC(a) scanf("%d",&a)
#define alL(a) a.begin(),a.end()
#define prinT(a,sz)  cout<<a[0];for(int i=1;i<sz;i++)cout<<" "<<a[i];cout<<endl
#define ranD srand(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int>pi;
typedef pair<ll,ll>pll;
//int fx[]={0,0,1,-1};
//int fy[]={1,-1,0,0};
//int gx[]={0,0,1,1,1,-1,-1,-1};
//int gy[]={1,-1,0,1,-1,0,1,-1};
bool check(int n,int p){return (1<<p)&n;}
const int N=100010;
pi pos[N];
int pre[N];
int main()
{
    IOS;
    int n,m,k;cin>>n>>m>>k;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            int a;cin>>a;
            pos[a]={i,j};
        }
    }
    int mx=n*m;
    for(int i=1;i<=k;i++)
    {
        int d=0;
        for(int j=i+k;j<=mx;j+=k)
            {
                d+=abs(pos[j].ff-pos[j-k].ff)+abs(pos[j].ss-pos[j-k].ss);
                pre[j]=d;
//                cout<<"distance of "<<j<<" = "<<d<<endl;
            }
    }
    int q;cin>>q;
    while(q--)
    {
        int l,r;cin>>l>>r;
        cout<<pre[r]-pre[l]<<endl;
    }
}








Measured memory_bytes: 2176
n = int(input())
a = [int(i) for i in input().split()]
even_number = [i for i in a if i % 2 == 0]

answer = 0
while len([i for i in even_number if i % 2 == 0]) > 0:
  even_number = [i / 2 for i in even_number if i % 2 == 0]
  answer += len(even_number)

print(answer)

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

const int N = 100000;
char a[N];
char b[N];
int main()
{
	int i, n, index = 0;
	scanf("%s", a);
	n = strlen(a);
	for (i = 0; i < n; i++)
	{
		if (a[i] == 'B'&&index > 0)
		{
			index--;
			b[index] = 0;
		}
		else if (a[i] != 'B')
			b[index++] = a[i];
	}
	printf(b);
	return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python3
import sys


def solve(N: int, K: int):
    if N % K == 0:
        print(0)
    else:
        print(1)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
using lint = long long;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (int i = 0; i < (int)vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}

#ifdef _DEBUG
template <class Head>
void dump(const char* str, Head &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + 1, t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

template<class T = lint>
struct Edge {
	int to;
	T cost;
	Edge() {}
	Edge(int to, T cost) : to(to), cost(cost) {}
	bool operator>(const Edge &r) const { return this->cost > r.cost; }
};

template<class T>
vector<T> Dijkstra(vector<vector<Edge<T>>> &edges, int st) {

	int V = (int)edges.size();
	const T INF = numeric_limits<T>::max();
	vector<T> cost(V, INF);
	cost[st] = 0;

	priority_queue<Edge<T>, vector<Edge<T>>, greater<Edge<T>>> p_que;
	p_que.emplace(st, cost[st]);

	while (!p_que.empty()) {

		Edge<T> now(p_que.top().to, p_que.top().cost);
		p_que.pop();

		if (cost[now.to] < now.cost) continue;
		for (const Edge<T> &e : edges[now.to]) {
			T tmp_cost = now.cost + e.cost;
			if (cost[e.to] > tmp_cost) {
				cost[e.to] = tmp_cost;
				p_que.emplace(e.to, cost[e.to]);
			}
		}
	}

	return cost; // min cost to vertex idx from st
}


int main() {

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

	int N;
	cin >> N;
	
	vector<vector<Edge<lint>>> edges(N);
	for (int i = 0; i < N - 1; i++) {
		int a, b;
		lint c;
		cin >> a >> b >> c;
		a--, b--;
		edges[a].emplace_back(b, c);
		edges[b].emplace_back(a, c);
	}

	int Q, K;
	cin >> Q >> K;
	auto distK = Dijkstra(edges, K - 1);

	for (int i = 0; i < Q; i++) {
		int x, y;
		cin >> x >> y;
		x--, y--;
		cout << distK[x] + distK[y] << "\n";
	}
	
	return 0;
}

Measured memory_bytes: 11120
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<string>;
using P =pair<int,int>;

const ll mod=1000000007;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

int main(){
    int n;
    cin>>n;
    vector<int> x(n),y(n);
    vector<ll> h(n);
    rep(i,n)cin>>x[i]>>y[i]>>h[i];
    rep(j,101){
        rep(k,101){
            ll H=-1;
            rep(i,n){
                if(h[i]>0){
                    if(H==-1){
                        H=h[i]+abs(x[i]-j)+abs(y[i]-k);
                    }else{
                        ll tempH=h[i]+abs(x[i]-j)+abs(y[i]-k);
                        if(H!=tempH){
                            H=-2;
                            break;
                        }
                    }
                }
            }
            if(H==-2)continue;
            rep(i,n){
                if(h[i]==0){
                    ll tmpH=H-abs(x[i]-j)-abs(y[i]-k);
                    if(tmpH>0){
                        H=-2;
                        break;
                    }
                }
            }
            if(H==-2)continue;
            cout<<j<<" "<<k<<" "<<H<<endl;
            return 0;
        }
    }

}

Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
/*
[l,r]
if l!=r
in [l+1,r] increment by x-(l+1)
 */
VI ntx;
VI nta;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  in n,m;
  cin>>m>>n;
  ntx.resize(n+1);
  nta.resize(n+1);
  in pv=-1;
  in a;
  in ttl=0;
  forn(z,m){
    cin>>a;
    --a;
    if(pv==-1 || pv==a){
      pv=a;
      continue;
    }
    ttl+=(a-pv);
    if(a<pv)
      ttl+=n;
    if(pv<a){
      ntx[pv+1]+=1;
      nta[pv+1]-=pv+1;
      ntx[a+1]-=1;
      nta[a+1]+=pv+1;
    }
    else{
      ntx[pv+1]+=1;
      nta[pv+1]-=pv+1;
      ntx[n]-=1;
      nta[n]+=pv+1;
      ntx[0]+=1;
      nta[0]-=pv+1;
      nta[0]+=n;
      ntx[a+1]-=1;
      nta[a+1]+=pv+1;
      nta[a+1]-=n;
    }
    pv=a;
  }
  in mx=-1e18;
  in crx=0;
  in cra=0;
  forn(i,n){
    crx+=ntx[i];
    cra+=nta[i];
    mx=max(mx,crx*i+cra);
  }
  cout<<ttl-mx<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <functional>
#include <vector>
#include <algorithm>

struct Closed_Section {
    bool valid;
    int64_t begin;
    int64_t end;
    Closed_Section(bool _valid, int64_t _begin, int64_t _end) {
        valid = _valid; begin = _begin; end = _end;
    }
    Closed_Section() {
        valid = false, begin = 0; end = -1; //配列を定義するためにデフォルトコンストラクタが必要。
    }
    int64_t size() { return valid ? end - begin + 1 : 0; }
    void dump() { std::cout << "valid:" << valid << " begin:" << begin << " end:" << end << std::endl; }
};

Closed_Section binary_search(const int64_t L, const int64_t R, std::function<bool(int64_t)> func) {
    if (R < L) { return Closed_Section(false, L, R); }
    const bool res_L = func(L);
    const bool res_R = func(R);
    if (res_L && res_R) {
        return Closed_Section(true, L, R);
    } else if (!res_L && !res_R) {
        return Closed_Section(false, 0, -1);
    } else {
        int64_t lb = L;
        int64_t ub = R;
        while (lb + 1 < ub) {
            int64_t mid = (lb + ub) / 2;
            if (res_L == func(mid)) {
                lb = mid;
            } else {
                ub = mid;
            }
        }
        return res_L ? Closed_Section(true, L, lb) : Closed_Section(true, ub, R);
    }
}

Closed_Section binary_search(const Closed_Section& cs, std::function<bool(int64_t)> func) {
    return cs.valid ? binary_search(cs.begin, cs.end, func) : cs;
}

// end of template

int64_t N;
const int64_t MAX_N = 3e5 + 10;

int64_t A[MAX_N];
int64_t cnt[MAX_N] = {};
std::vector<int64_t> V, Vac;

bool check(int64_t K, int64_t X) {
    auto cs = binary_search(0, V.size()-1, [&](int64_t i){
        return V[i] < X;
    });
    int64_t num = 0;
    if (cs.valid) {
        num = Vac[cs.end] + X * (V.size() - cs.size());
    } else {
        num = X * V.size();
    }
    return K*X <= num;
}

int main(int argc, char **argv) {
    std::cin >> N;
    for (int64_t i = 1; i <= N; i++) {
        std::cin >> A[i];
        cnt[A[i]]++;
    }
    for (int64_t i = 1; i <= N; i++) {
        if (0 < cnt[i]) {
            V.push_back(cnt[i]);
        }
    }
    std::sort(V.begin(), V.end());
    for (int64_t i = 0; i < V.size(); i++) {
        Vac.push_back(V[i]);
        if (i != 0) {
            Vac[i] += Vac[i-1];
        }
    }
    for (int64_t k = 1; k <= N; k++) {
        auto cs = binary_search(0, N/k, [&](int64_t x){
            return check(k, x);
        });
        std::cout << cs.end << std::endl;
    }
}

Measured memory_bytes: 13676
#include <cstdio>

int n;
int card[52];
char c;
int a;

int main(){
	scanf("%d", &n);
	for(int i=0; i<n; ++i){
		scanf(" %c%d", &c, &a);
		if(c=='S'){
			card[a-1]=1;
		}else if(c=='H'){
			card[a-1+13]=1;
		}else if(c=='C'){
			card[a-1+26]=1;
		}else if(c=='D'){
			card[a-1+39]=1;	
		}
	}
	
	for(int i=0; i<52; ++i){
		if(card[i]==0){
			if(i<13){
				printf("S ");
			}else if(i<26){
				printf("H ");
			}else if(i<39){
				printf("C ");
			}else if(i<52){
				printf("D ");
			}
			printf("%d\n", i%13+1);
		}
	}
}


Measured memory_bytes: 2696
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

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

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    int K;
    cin>>K;
    string ans = "";
    REP(i, 0, K) ans += "ACL";
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  if(s=="Sunny"){
    cout<<"Cloudy"<<endl;
  }
  else if(s=="Cloudy"){
    cout<<"Rainy"<<endl;
  }
  else{
    cout<<"Sunny"<<endl;
  }
}


Measured memory_bytes: 3520
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[11];
	int max=-1;
	for(int i=0;i<n;i++)
		{
			cin>>a[i];
			if(max<a[i])
				max=a[i];
	     }
	int sum=0;
	int c=0;
	for(int i=0;i<n;i++)
	{
		if(a[i]==max && c<1) 
		{
			sum+=a[i]/2;
			c=1;
		}
		else
			sum+=a[i];
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
#include <tuple>
#include <string>
#include <algorithm>

 
using namespace std;

typedef long long ll;
typedef long double ld;
#define L(ID) ((ID*2)+1)
#define R(ID) ((ID*2)+2)
#define M(L,R) ((L+R)/2)
#define forr(start,end) for(int i = start; i < end; i++)
#define gap ' '
 
const int MAXN = 2 * 1e5 + 5;
int n, a[MAXN];

ll largest(ll a, ll b){
	return (a<b)?b:a;
}
ll smallest(ll a, ll b){
	if(a < b)return a;
	return b;
}
struct triple
{
	int x,y,z;
};

int main(){
	int r;
	cin >> r;
	cout << 3 * (r*r) << endl;

    return 0;
}

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

int main() {
 
  int n, l;
  cin >> n >> l;
  
  vector<string> s(n);
  REP(i,n) cin >> s[i];
  
  sort(s.begin(), s.end());
  
  REP(i,n) cout << s[i];
 
}

Measured memory_bytes: 3600
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n;
  while(cin>>n,n!=0){
    vector<int>num(n);
    for(int i=0;i<n;i++)
      cin>>num[i];
    sort(num.begin(),num.end(),greater<int>());
    int min=1000000000;
    for(int i=1;i<n;i++){
      if(min>num[i-1]-num[i])
	min=num[i-1]-num[i];
    }
    cout<<min<<endl;
  }
  return 0;
}

Measured memory_bytes: 3096
#include<cstdio>
#include<cstdlib>
int F[500005],A[500005];
int n,i;
int main(){
	scanf("%d%d",&n,A);
	for(i=1;i<=n;++i)scanf("%d",A+i);
	F[n]=A[n]==1;
	for(i=n-1;i;--i)F[i]=F[i+1]*2+1>=A[i]?F[i+1]+A[i]:F[i+1];
	for(i=1;i<=n;++i)A[i]=abs(A[i-1]-A[i])<A[i-1]?abs(A[i-1]-A[i]):A[i-1];
	scanf("%d",&n);
	while(n--)scanf("%d",&i),puts(A[i-1]>F[i+1]?"YES":"NO");
	return 0;
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define debug(x) cout << #x << " = " << x << '\n'
#define debug_arr(a , n) for(int i = 0 ; i < n ; i++)cout << a[i] << " "
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define vll vector<ll> 
#define inf 1000000000
#define mod 1000000007

const int max_n = 1e5 + 9;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a , ll b)
{
    ll prod = 1;
    while(b)
    {
        if(b&1)
        prod = (prod*a)%mod;
        a = (a*a)%mod;
        b >>= 1;
    }
    return prod;
}
int main()
{
    int n;
    cin >> n;
    set<string> s;
    for(int i = 0 ; i < n ; i++){
        string str;
        cin >> str;
        s.insert(str);
    }
    cout << s.size() << endl;
    return 0;
}

Measured memory_bytes: 19224
import numpy as np
N = input()
list = list(map(int,input().split(' ')))

list = np.array(list)
A = np.unique(list[list%2 == 0])
B = np.unique(np.append(list[list%6 == 0],(list[list%10 == 0])))

if len(A) ==0:
        print('APPROVED')
elif len(B) ==0:
    print('DENIED')
else:
    if len(A) == len(B) :
        print('APPROVED')
    else:
        print('DENIED')


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(auto& e : a) cin >> e;
    sort(begin(a), end(a));
    string res = "YES";
    for(int i = 0; i < n - 1; i++){
        if(a[i] == a[i+1]){
            res = "NO";
            break;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
//	C++ (Clang3.8.0)
#include <iostream>
#include <string>
#include <map>
#include <cmath>

using namespace std;

int main(){
	long double a, b, c;
	long double ab;
	long double cab;
	
	cin >> a >> b >> c;
	ab = a*b;
	cab = pow((c-a-b)/2.0,2);
	
	if(ab < cab && c-a-b>0){
		cout << "Yes";
	}else {
		cout << "No";
	}
	
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7

from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)

a = 1
for i in range(N):
    a = lcm(a, A[i])

ans = 0
for i in range(N):
    ans += a * pow(A[i], mod-2, mod)

print(ans % mod)

Measured memory_bytes: 68184
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  REP(i, n) cin >> p[i];
  int ret = 0;
  REP(i, n-2) {
    int mx = max({p[i], p[i+1], p[i+2]});
    int mn = min({p[i], p[i+1], p[i+2]});
    if (p[i+1] != mx and p[i+1] != mn) ret++;
  }
  cout << ret << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int u[10]={0},dp[11][333]={{0}},j,k;

void f(int p,int r)
{
	int i;
	dp[p][r]++;
	for(i=0;i<10;i++)
		if(!u[i])
		{
			u[i]=1;
			f(p+1,r+i*(p+1));
			u[i]=0;
		}
}

int main()
{
	f(0,0);
	for(;~scanf("%d%d",&j,&k);)
		printf("%d\n",(j>10||k>330)?0:dp[j][k]);
	return 0;
}

Measured memory_bytes: 612
#!/usr/local/bin/ruby
while line=gets
   rec=line.split(" ").map(&:to_i)
   x,y=rec[0],rec[1]
   s=x*y
   while true
      k = x % y
      x = y
      y = k
      break if k==0
   end
   lcm = s/x
   puts "#{x} #{lcm}"
end

Measured memory_bytes: 6096
from bisect import bisect_left
n, q = map(int, input().split())
s = list(input())
L = []
for i in range(n - 1):
    if s[i] == "A" and s[i + 1] == "C":
        L.append(i)
ans = []
for i in range(q):
    l, r = map(int, input().split())
    l, r = l - 1, r - 1
    st = bisect_left(L, l)
    fi = bisect_left(L, r)
    ans.append(fi - st)

for i in ans:
    print(i)

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

int main(){
  int n;
  cin >> n;
  bool flag = false;
  for(int i=1; i<10; ++i){
    for(int j=1; j<10; ++j){
      if(i*j==n) flag=true;
    }
  }
  if(flag){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

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

using namespace std;

#define rep(i, x)   for (__typeof(x) i = 0; i < x; i++)
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define all(x)         (x).begin(), (x).end()
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define debug(x)       { cerr << #x << " = " << x << endl; }
#define repi(i, x)  for (__typeof(x) i = x-1; i >= 0; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;
typedef vector<vector<int> > vvi;
typedef pair<ll, ll>   pairl;
typedef vector<ll>     vl;
typedef vector<ll>     vll;
typedef vector<vector<ll> > vvl;
const   int            infi = numeric_limits<int>::max();
const   ll             infl = numeric_limits<ll>::max();
const   double         eps = 0;
const   int            ms  = 0;



int main()
{
    ios::sync_with_stdio(false);//endl->"\n"
    cin.tie(0);
    int N;
    cin >> N;
    int K;
    cin >> K;
    int ans = 0;
    rep(i, N){
        int h;
        cin >> h;
        if(h >= K)ans++;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int N;
  cin >> N;
  cout << N * N * N << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>



using namespace std;
typedef long long ll;
int gcd( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	// ユークリッドの方法
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}//gcd
int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm
int input(){
  int x;
  cin>>x;
  return x;
}
int abs(int x){
  if(x>=0){
    return x;
  }else{
    return -x;
  }
}

int moji(char in)
{
    int ans = (int)in-(int)'a'+1;
    if((in < 1) || (in > 26)){
        ans = 100;
    }
    return ans;
}
const int VV=10;//場合に応じてVVの値のみ変更する必要あり
//dijkstra(s)sがスタート地点でそこからの最短距離を配列dで表す。正の重みのみ使用可能
int cost[VV][VV];
int d[VV];
bool used[VV];
void dijkstra(int s){
  fill(d,d+VV,100000);
  fill(used,used+VV,false);
  d[s]=0;
  while(true){
    int v=-1;
    for(int u=0;u<VV;u++){
      if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
    }
    if(v==-1)break;
    used[v]=true;
    for(int u=0;u<VV;u++){
      d[u]=min(d[u],d[v]+cost[v][u]);
    }
  }

}

int compare_int(const void *a, const void *b)//qsort(quick sort利用時に使用)
{
    return *(int*)a - *(int*)b;
}









int main() {
  int N,K;
  cin>>N>>K;
  int A[N];
  int count[200001];
  for(int i=0;i<200001;i++){
    count[i]=2000000;
  }
  int sousuu=0;
  for(int i=0;i<N;i++){
    cin>>A[i];
    if(count[A[i]]==2000000){
      count[A[i]]=1;
      sousuu++;

    }else{
    count[A[i]]++;}
  }
  sort(count,count+200001);
  int i=sousuu-K;
  int sum=0;
  for(int k=0;k<i;k++){
    sum+=count[k];
  }
  cout<<sum<<endl;

  

  




    




  

  


  

    


  

  
  
  
  
}


  
  

  

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

int main(void)
{
    constexpr int MOD = 1e5;
    IOS
    ll N; cin >> N;
    ll X,M; cin >> X >> M;
    vector<int> loop(MOD);
    vector<int> f(1);
    int count = 1;
    while(loop[X] == 0 && X != 0 && count <= N) {
        // cerr << X << endl;
        loop[X] = count;
        count++;
        f.push_back(X);
        X *= X;
        X %= M;
    }
    if (X == 0 || loop[X] == 0) OUT(accumulate(ALL(f),0LL))
    else {
        // cerr << X << endl;
        ll loopsize = count - loop[X];
        ll lcount = (N-loop[X]+1) / loopsize;
        ll lmod = (N-loop[X]+1) % loopsize;
        // cerr << loopsize << " " << lcount << " " << lmod << endl;
        ll loopsum = 0;
        REP(i,loopsize) loopsum += f[loop[X]+i];
        ll ans = 0;
        FOR(i,1,loop[X]) ans += f[i];
        ans += loopsum * lcount;
        REP(i,lmod) ans += f[loop[X]+i];
        OUT(ans)
    }




    return 0;
}

Measured memory_bytes: 4016
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long  ll;
struct Node
{
	ll a,b;
	double l;
};
Node p[5];
ll Q, H, S, D, N;

bool cmp(Node a, Node b)
{
	if (a.b == b.b) return a.a < b.a;
	return a.b < b.b;
}

int main()
{
	while (cin>>Q>>H>>S>>D>>N)
	{
		p[0].l = 0.25, p[1].l = 0.5, p[2].l = 1, p[3].l = 2;
		p[0].a = Q, p[1].a = H, p[2].a = S, p[3].a = D;
		p[0].b = Q * 8, p[1].b = H * 4, p[2].b = S * 2, p[3].b = D;
		sort(p, p + 4, cmp);
		ll ans = 0;
		ll mi;
		mi = min(p[0].a, p[1].a);
		mi = min(p[2].a, mi); mi = min(mi, p[3].a);
		ll t = (ll)(N*(1.0) / p[0].l); N = N - t*p[0].l;
		ans = t*p[0].a;
		if (N > 0) {
			t = (ll)(N*(1.0) / p[1].l); N = N - t*p[1].l;
			ans += t*p[1].a;
		}
		if (N > 0) {
			t = (ll)(N*(1.0) / p[2].l); N = N - t*p[2].l;
			ans += t*p[2].a;
		}
		if (N > 0) {
			t = (ll)(N*(1.0) / p[3].l); N = N - t*p[3].l;
			ans += t*p[3].a;
		}
		cout << ans << endl;
	}
}

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

const int MAXN = 15;
const int MAXQ = 55;
int a[MAXQ],b[MAXQ],c[MAXQ],d[MAXQ];
vector<int> A[MAXN];
int N,M,Q; 
int ans = 0;

void dfs(vector<int> &A) {
    // 数列の長さが N に達したら打ち切り
    if (A.size() == N+1) {
        int now = 0;
        // 処理
        for(int i=0; i<Q; i++) {
            if(A[b[i]]-A[a[i]] == c[i]) {
                now += d[i]; 
            }
        }
        ans = std::max(ans,now);
        return;
    }
    int prev_last = (A.empty() ? 1 : A.back());
    for (int v = prev_last; v <= M; ++v) {
        A.push_back(v);
        dfs(A);
        A.pop_back();
    }
}


int main(void){
    // Your code here!
    cin >> N >> M >> Q;
    
    for(int i=0; i<Q; i++) cin >> a[i] >> b[i] >> c[i] >> d[i];
    
    vector<int> A;
    dfs(A);
    cout << ans << endl;
}

Measured memory_bytes: 3184
#![allow(non_snake_case, unused_imports, deprecated, dead_code)]

// Input macros
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, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,VecDeque,BinaryHeap};
// Module for v1.15.1
use std::ascii::AsciiExt; // deprecated since 1.26.0: use inherent method instead

// Functions
struct UnionFind {
    par  : Vec<usize>,
    rank : Vec<usize>,
}

impl UnionFind {
    fn new(n: usize) -> UnionFind {
        let mut vec = vec![0; n];
        for i in 0..n{
            vec[i] = i;
        }
        UnionFind{
            par  : vec,
            rank : vec![0; n]
        }
    }

    fn find(&mut self, x:usize) -> usize {
        if x == self.par[x] {
            return x;
        }else{
            let par = self.par[x];
            let res = self.find(par);
            self.par[x] = res;
            return res;
        }
    }

    fn same(&mut self, x:usize, y:usize) -> bool {
        return self.find(x) == self.find(y);
    }

    fn unite(&mut self, x:usize, y:usize) {
        let x_par = self.find(x);
        let y_par = self.find(y);
        if self.rank[x_par] > self.rank[y_par] {
            self.par[y_par] = x_par;
        }else{
            self.par[x_par] = y_par;
            if self.rank[x_par] == self.rank[y_par] {
                self.rank[y_par] += 1;
            }
        }
    }

}

// Main
fn main() {

    input! {
        N: usize,
        M: usize,
        XYZ: [(usize,usize,usize); M]
    }

    let mut uf = UnionFind::new(N);
    for &(x,y,_z) in XYZ.iter() {
        uf.unite(x-1,y-1);
    }

    let mut ans = vec![];
    for i in 0..N {
        ans.push(uf.find(i));
    }

    ans.sort();
    ans.dedup();

    println!("{}", ans.len());
}

Measured memory_bytes: 12540
package main

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

func main() {

	oneInt()
	alp := oneStr()
	var slimes []rune
	for _, r := range alp {
		slimes = append(slimes, r)
	}

	var pV rune
	var count int
	for _, v := range slimes {
		if v != pV {
			count++
		}
		pV = v
	}
	fmt.Print(count)

}

var sc = bufio.NewScanner(os.Stdin)

func oneInt() int {
	var a int
	fmt.Scan(&a)
	return a
}
func oneStr() string {
	var a string
	fmt.Scan(&a)
	return a
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func scanNums() (nums []int) {
	s := nextLine()
	numStr := strings.Split(s, " ")

	for _, n := range numStr {
		i, _ := strconv.Atoi(n)
		nums = append(nums, i)
	}
	return nums
}

func scanStrings() (strs []string) {
	s := nextLine()
	list := strings.Split(s, " ")
	strs = append(strs, list...)
	return strs
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func sortAsc(a []int) []int {
	sort.Ints(a)
	return a
}

func sortDesc(a []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	return a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	if a == 0 && b == 0 {
		return 0
	}
	return a * b / gcd(a, b)
}


Measured memory_bytes: 3584
import sys
from collections import deque, OrderedDict
sys.setrecursionlimit(10 ** 7)

N = int(input())
count = [[] for _ in range(N)]
inputs = OrderedDict()

for _ in range(N - 1):
    a, b = map(int, input().split())
    count[a - 1].append(b - 1)
    count[b - 1].append(a - 1)
    inputs["-".join(list(map(str, sorted([a - 1, b - 1]))))] = 0

K = 0
for c in count:
    K = max(K, len(c))
print(K)

def dfs(root, count, inputs):
    done = [-1 for _ in range(N)]
    done[root] = 0
    d = deque([root])
    r = d.pop()
    childs = count[r]
    tmp = 1
    for c in childs:
        if done[c] == -1:
            d.append([c, r, tmp])
            tmp += 1
            done[c] += 1
    while d:
        data = d.pop()
        inputs["-".join(list(map(str, sorted(data[:2]))))] = data[2]
        childs = count[data[0]]
        tmp = 1
        for c in childs:
            if done[c] == -1:
                if tmp != data[2]:
                    d.append([c, data[0], tmp])
                else:
                    tmp += 1
                    d.append([c, data[0], tmp])
                tmp += 1
                done[c] += 1
    
    return inputs

inputs = dfs(0, count, inputs)

for i in inputs.values():
    print(i)

Measured memory_bytes: 59896
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
	char ch;

	cin >> ch;

	if (ch == 'A')
		cout << 'T';
	if (ch == 'T')
		cout << 'A';
	if (ch == 'C')
		cout << 'G';
	if (ch == 'G')
		cout << 'C';
	
	return 0;
}



Measured memory_bytes: 256
# coding:UTF-8
import sys


def resultSur97(x):
    return x % (1000000000 + 7)


if __name__ == '__main__':
    # ------ 入力 ------#
    # 1行入力
    n = int(input())    # 数字
    # a = input()     # 文字列
    # aList = list(map(int, input().split()))     # スペース区切り連続数字
    # aList = input().split()     # スペース区切り連続文字列
    # aList = [int(c) for c in input()]   # 数字→単数字リスト変換

    # 定数行入力
    x = n
    # aList = [int(input()) for _ in range(x)] # 数字
    # aList = [input() for _ in range(x)] # 文字
    aList = [list(map(int, input().split())) for _ in range(x)]     # スペース区切り連続数字(行列)
    # aList = [input().split() for _ in range(x)]     # スペース区切り連続文字
    # aList = [[int(c) for c in input()] for _ in range(x)]   # 数字→単数字リスト変換(行列)

    # スペース区切り連続 数字、文字列複合
    # aList = []
    # for _ in range(x):
    #     aa, bb = input().split()
    #     a.append((int(aa), bb))

    # ------ 処理 ------#
    zmin = aList[0][0] + aList[0][1]
    zmax = aList[0][0] + aList[0][1]
    wmin = aList[0][0] - aList[0][1]
    wmax = aList[0][0] - aList[0][1]

    for i in range(len(aList)):
        x = aList[i][0]
        y = aList[i][1]

        z = x + y
        w = x - y

        if z < zmin:
            zmin = z
        if z > zmax:
            zmax = z
        if w < wmin:
            wmin = w
        if w > wmax:
            wmax = w

    disMax = max(zmax-zmin, wmax-wmin)
    # ------ 出力 ------#
    print("{}".format(disMax))
    # if flg == 0:
    #     print("YES")
    # else:
    #     print("NO")


Measured memory_bytes: 45408
n = int(input())
inp = list(map(int,input().split()))

tmp = []

for i, num in enumerate(inp, 1):
    tmp.append(list((i,num)))

tmp.sort(key=lambda x: x[1])

ans = []
for i in range(n):
    ans.append(str(tmp[i][0]))
    
print(" ".join(ans))

Measured memory_bytes: 30244
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#include <cstring>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-10;
#define equals(a,b) (fabs((a) - (b)) < EPS)

using namespace std;

map<int,double> mp;
int r,n;

bool inshadow(double y){
    REP(i,r){
        if(sqrt(r*r-i*i) > mp[i] - y)return false;
        if(sqrt(r*r-i*i) > mp[-i-1] - y)return false;
    }
    return true;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin>>r>>n,r){
        mp.clear();
        FOR(i,-r,r)mp[i] = 0.0;
        REP(i,n){
            int x1,x2;
            double h;
            cin>>x1>>x2>>h;
            for(int j = max(x1,-r);j < min(x2,r);j++){
                mp[j] = max(h,mp[j]);
            }
        }
        double lb=-r,rb=20.0;
        for(int i = 0;i<100;i++){
            double mid = (lb+rb)/2;
            if(inshadow(mid))lb = mid;
            else rb = mid;
        }
        cout << fixed << setprecision(4) << lb + r << endl;
    }
    return 0;
}

Measured memory_bytes: 3144
#include<iostream>
#include<string>
using namespace std;
int main(){
	string s;
  int ans=0,len;
    cin>>s;
  	len=s.length();
    for(int i=0;i<len/2;i++){
    	if(s[i]!=s[len-i-1])ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 256