akhauriyash/Code-Regression huggingface dataset:
/*辞書*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define M 10000000
#define L 14

void insert(char *);
int find(char *);
int getChar(char);
long long getKey(char *);

long long H[M]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int find(char str[]){
  if (H[getKey(str)])
    return 1;
  return 0;
}

void insert(char str[]){    
  H[getKey(str)] = 1;
}

int main(){
    int i, n, h;
    char str[L]; //文字をいれる
    char com[9]; //insert or find
    
    scanf("%d", &n);
    
    for ( i = 0; i < M; i++ ) H[i] = 0;
    
    for ( i = 0; i < n; i++ ){
      scanf("%s %s", com, str);
      
      if ( com[0] == 'i' ){
	insert(str);
      }
      else {
	if (find(str)){
	  printf("yes\n");
	}
	else {
	  printf("no\n");
	}
      }
    }
    
    return 0;
}



Measured memory_bytes: 79852
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=500005,mod=1e9+7;
int n,m,fact[N],infact[N];
int qmi(int a,int k,int p)
{
    int res=1;
    while(k)
    {
        if(k&1) res=1ll*res*a%p;
        k>>=1;
        a=1ll*a*a%p;
    }
    return res;
}
void init()
{
    fact[0]=infact[0]=1;
    for(int i=1;i<=m;i++)
    {
        fact[i]=1ll*fact[i-1]*i%mod;
        infact[i]=qmi(fact[i],mod-2,mod);
    }
}
int main()
{
    IO;
    cin>>n>>m;
    init();
    ll res=0;
    for(int i=0;i<=n;i++)   
    {
        if(i&1) res=(res-1ll*fact[n]*infact[i]%mod*infact[n-i]%mod*fact[m-i]%mod*infact[m-n]%mod)%mod;
        else res=(res+1ll*fact[n]*infact[i]%mod*infact[n-i]%mod*fact[m-i]%mod*infact[m-n]%mod)%mod;
    }
    for(int i=m-n+1;i<=m;i++) res=res*i%mod;
    res%=mod;
    cout<<(res+mod)%mod<<endl;
}

Measured memory_bytes: 7452
#include<stdio.h>
int main(){
  int a,b;
  char op;
  do{
    scanf("%d %c %d",&a,&op,&b);
    if(op != '+' && op != '-' && op != '*' && op != '/' )
      break;
    if(op == '+'){
      printf("%d\n",a+b);
    }else if(op == '-'){
      printf("%d\n",a-b);
    }else if(op == '*'){
      printf("%d\n",a*b);
    }else if(op == '/'){
      printf("%d\n",a/b);
    }
  }while(0 <= a,b <= 20000);
  return 0;
}

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

int main() {

	int N;
	cin >> N;
	vector<int> vec(N);

	for (int a = 0; a < N; a++) {

		cin >> vec.at(a);

	}

	sort(vec.begin(), vec.end());

	int Ans = 1;

	for (int b = 1; b < N; b++) {

		int c = b - 1;

		if (vec.at(c) < vec.at(b)) {

			Ans++;

		}

	}

	cout << Ans << endl;
}

Measured memory_bytes: 256
#-swank
(unless (member :child-sbcl *features*)
  (quit
   :unix-status
   (process-exit-code
    (run-program *runtime-pathname*
                 `("--control-stack-size" "128MB"
                   "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
                   "--eval" "(push :child-sbcl *features*)"
                   "--script" ,(namestring *load-pathname*))
                 :output t :error t :input t))))
(defmacro dp (name args memo-size &body body)
  (let ((memo (gensym)))
    `(let ((,memo (make-array ,memo-size :initial-element nil)))
       (defun ,name ,args
         (or (aref ,memo ,@args)
             (setf (aref ,memo ,@args)
                   ,@body))))))

(defun split (x str)
  (let ((pos (search x str))
        (size (length x)))
    (if pos
        (cons (subseq str 0 pos)
              (split x (subseq str (+ pos size))))
        (list str))))

(defmacro collect-times (time body)
  `(loop repeat ,time collect ,body))

(defun read-times (time)
  (collect-times time (read)))

(defmacro aif (expr then else)
  `(let ((it ,expr))
     (if it ,then ,else)))

(defmacro awhen (expr &rest then)
  `(aif ,expr (progn ,@then) nil))

(defun comulative (function list &key base)
  (if base
      (comulative function (cons base list))
      (do ((lst (cdr list) (cdr lst))
           (acc (list (car list))))
          ((null lst) (reverse acc))
        (push (funcall function (car acc) (car lst)) acc))))

(defun binary-search (function left right
                      &optional
                        (eps 1)
                        (average-function (lambda (x y) (ash (+ x y) -1))))
  (if (<= (abs (- left right)) eps)
      right
      (let ((mid (funcall average-function left right)))
        (if (funcall function mid)
            (binary-search function left mid eps average-function)
            (binary-search function mid right eps average-function)))))

(defun arithmetic-mean (&rest body)
  (/ (apply #'+ body) (length body)))

(defvar +MOD+ (+ (expt 10 9) 7))

(defun mapa-b (fn a b &optional (step 1))
  (do ((i a (+ i step))
       (result nil))
      ((> i b) (nreverse result))
    (push (funcall fn i) result)))

(defun map0-n (fn n)
  (mapa-b fn 0 n))

(defun map1-n (fn n)
  (mapa-b fn 1 n))

(defun read-string (&optional (stream *standard-input*))
  (labels ((is-empty (x)
             (or (char= x #\space) (char= x #\newline))))
    (loop for char = (read-char stream)
          with result
          when (is-empty char)
            do (return (concatenate 'string (nreverse result)))
          do (push char result))))

(defun main (lst)
  (- (reduce #'+ lst) (length lst)))

(princ (main (read-times (read))))


Measured memory_bytes: 15420
#include <iostream>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
//const int MAX=;

int dsum(int n){
	if(n<10) return n;
	return dsum(n/10)+n%10;
}

int main(){
	int N;
	cin>>N;
	int ans=N;
	rep1(i,N/2)ans=min(ans,dsum(i)+dsum(N-i));
	cout<<ans;
}

Measured memory_bytes: 256
def is_upper(c):
  return ord('A') <= ord(c) and ord(c) <= ord('Z')
def shift(c, k):
  if is_upper(c):
    return chr((ord(c) - ord('A') + k) % 26 + ord('A'))
  else:
    return c
def caesar(s, k):
  return "".join([shift(c, k) for c in s])
N = int(input())
S = input()
enc = caesar(S, N)
print(enc)

Measured memory_bytes: 3064
n = int(input())
ans = 0
if n==1 or n==2:
  print(0)
  exit()
elif n<6:
  print(n-1)
  exit()
for i in range(1, int(n**(1/2))+2):
  k = (n-i)//i
  if n%k == n//k:
    ans += k
print(ans)

Measured memory_bytes: 40204
using System;
using System.Collections.Generic;
using System.IO.Compression;
using System.Linq;
using System.Numerics;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var ab = ReadInts();
            var n = ReadInt();
            for (int i = 0; i < n; i++)
            {
                var sf = ReadInts();
                var start = sf[0];
                var finish = sf[1];

                if (ab[1] > start && ab[0] < finish)
                {
                    WriteLine(1);
                    return;
                }
            }
            WriteLine(0);
        }
        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}



Measured memory_bytes: 18016
def get_sieve_of_eratosthenes_new(n):
    import math
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = []
    limit = math.sqrt(n)
    data = [i + 1 for i in range(1, n)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]

def ord(N,n):#N,nは正の整数、Nで割り切れる回数、許容はN^1000
    if n%N!=0:
        return 0
    else:
        return 1+ord(N,n//N)

prime=get_sieve_of_eratosthenes_new(1000)

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

data=[[0 for i in range(0,len(prime))] for i in range(0,N)]
nokori=[1 for i in range(0,N)]
largeprime=set([])

import copy
sample=copy.copy(A)
for i in range(0,N):
    for j in range(0,len(prime)):
        a=ord(prime[j],A[i])
        data[i][j]=a
        A[i]=A[i]//(prime[j]**a)

    if A[i]!=1:
        largeprime.add(A[i])
    nokori[i]=A[i]

lcm=[max(data[i][j] for i in range(0,N)) for j in range(0,len(prime))]
largeprime=list(largeprime)

LCM=1
for i in range(0,len(lcm)):
    LCM=(LCM*pow(prime[i],lcm[i],mod))%mod

for i in range(0,len(largeprime)):
    LCM=(LCM*largeprime[i])%mod

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

print(ans)

Measured memory_bytes: 70876
N = int(input())
A = list(map(int, input().split()))

def partition(p, r):
    x = A[r]
    i = p - 1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i+1], A[r] = A[r], A[i+1]
    return i+1
        
r = partition(0, N-1)
print(" ".join(map(str, A[:r]))+" ["+str(A[r])+"] "+" ".join(map(str, A[r+1:N])))


Measured memory_bytes: 16388
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;
using ll = long long;

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

  vector<ll> a(n), tot(n,0);
  for (int i = 0; i != n; ++i) {
    cin >> a[i];
    ++tot[a[i]-1];
  }

  ll total = accumulate(tot.begin(),tot.end(), 0ll,
                        [](ll acc, ll x){
                          return acc + x*(x-1)/2;
                        });
  
  for (int i = 0; i != n; ++i) {
    cout << total-tot[a[i]-1]+1 << endl;
  }

  return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000
#define bpc(x) __builtin_parityll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

int main()
{
   FAST/**/
   
   string s;
   cin>>s;
   
   string s1 = "hi";
   ll n = s.length();
   if(n%2 == 1)
   {
       cout<<"No";
       return 0;
   }
   
   for(ll i=0;i<n;i+=2)
   {
       if(s[i] == 'h' && s[i+1] == 'i')
            continue;
       cout<<"No\n";
       return 0;
   }
   cout<<"Yes";
   
   
   return 0;        
}  
   

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n; cin>>n;
  vector<int> a(n),b(n),c(n);
  for(int i=0;i<n;i++) cin>>a[i]>>b[i]>>c[i]; 
  vector<int> aa(n,0), ab(n,0), ac(n,0);
  //cout<<"hello\n";
  for(int i=0;i<n;i++)
  {
    //cout<<"hello in\n";
    if(i==0) 
    {
      aa[0] = a[0]; ab[0] = b[0]; ac[0] = c[0];
    }
    else 
    {
      aa[i] = max(ab[i-1]+a[i], ac[i-1]+a[i]);
      ab[i] = max(aa[i-1]+b[i], ac[i-1]+b[i]);
      ac[i] = max(aa[i-1]+c[i], ab[i-1]+c[i]);
    }
  }
  cout<<max(aa[n-1], max(ab[n-1], ac[n-1]));
  return 0;
}

Measured memory_bytes: 2560
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(R, C, K, RCV):
    V = [[0] * C for _ in range(R)]
    for r, c, v in RCV:
        r, c = r - 1, c - 1
        V[r][c] = v
    dp = [[[0] * C for _ in range(R)] for __ in range(4)]
    dp[1][0][0] = V[0][0]
    for i in range(R):
        for j in range(C):
            for k in range(4):
                if j > 0:
                    dp[k][i][j] = max(dp[k][i][j], dp[k][i][j - 1])
                    if k > 0:
                        dp[k][i][j] = max(dp[k][i][j], dp[k - 1][i][j - 1] + V[i][j])
                if i > 0:
                    dp[0][i][j] = max(dp[0][i][j], dp[k][i - 1][j])
                    dp[1][i][j] = max(dp[1][i][j], dp[k][i - 1][j] + V[i][j])
    print(max(dp[k][R - 1][C - 1] for k in range(4)))

if __name__ == '__main__':
    input = sys.stdin.readline
    R, C, K = map(int, input().split())
    RCV = [list(map(int, input().split())) for _ in range(K)]
    main(R, C, K, RCV)


Measured memory_bytes: 450164
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long int
#define pb push_back

int MAX_n = 100001;
vector<bool> a(100001, true);
vector<bool> c(100001, false);
vector<int> b(100001, 0);

// 素数配列を用意する
void init(){
  int p = 0;
  a[0] = false; a[1] = false;
  for(int i = 2; i < MAX_n; i++){
    if(a[i]){
      for(int j = i*2; j < MAX_n; j+=i){
        a[j] = false;
      }
    }
  }
  
  // 2017に似た和の累積和を求める
  for(int i = 2; i < MAX_n; i++){
    if(i%2==0) b[i] = b[i - 1];
    if(a[i] && a[(i+1)/2]) {
      b[i] = b[i - 1] + 1;
      c[i] = true;
    }
    else b[i] = b[i - 1];
  }
  
  // rep(i, 12){
  //   printf("%d %d %d %d\n", i, int(a[i]), b[i], int(c[i]));
  // }

}

int main() {
  int Q, l, r;
  
  cin >> Q;
  init();
  
  rep(i, Q){
    cin >> l >> r;
    cout << b[r] - b[l] + int(c[l]) << endl;
  }
  
}


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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

ll INF = 1ll << 60;

int main(){
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  
  rep(i, 0, k){
    if(a >= b){
      b *= 2;
      continue;
    }
    else if(b >= c)
      c*= 2;
  }
  
  if(a < b && b < c)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
  
}

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

// clang-format off
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define endl '\n'
#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

void solver() {
    int N = input();
    vector< int > cnt(N);
    range(i, 0, N - 1) {
        cnt[input() - 1]++;
    }
    
    for (auto &i: cnt) cout << i << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 3988
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 1024
#define mod 1000000007

ll aux[2][2];

struct matrix {
    ll data[2][2];
    int i, j, k;

    void operator*=(matrix who) {
        memcpy(aux, data, sizeof(data));

        for (i = 0; i < 2; i++) {
            for (j = 0; j < 2; j++) {
                data[i][j] = 0;

                for (k = 0; k < 2; k++)
                    data[i][j] += (aux[i][k] * who.data[k][j]) % mod;
                data[i][j] %= mod;
            }
        }
    }
};

int n, m, i, j;
ll k, cnt;
char s[maxN][maxN];

int hor, ver, link_hor, link_ver;
ll a, b, c;

matrix ini;

ll poww(ll a, ll b) {
    ll ans = 1;

    while (b > 0) {
        if (b & 1) ans = (ans * a) % mod;
        b >>= 1;
        a = (a * a) % mod;
    }

    return ans;
}

matrix poww(matrix a, ll b) {
    matrix ans = a; b--;

    while (b > 0) {
        if (b & 1) ans *= a;
        b >>= 1;
        a *= a;
    }

    return ans;
}

int main()
{
  //  freopen("test.in","r",stdin);

    scanf("%d%d%lld\n", &n, &m, &k);
    for (i = 1; i <= n; i++) scanf("%s", s[i] + 1);

    for (i = 1; i <= n; i++) {
        for (j = 1; j <= m; j++) {
            if (s[i][j] != '#') continue;
            cnt++;

            if (s[i + 1][j] == '#') ver++;
            if (s[i][j + 1] == '#') hor++;
        }
    }

    for (i = 1; i <= n; i++)
        if (s[i][1] == s[i][m] && s[i][1] == '#')
            link_hor++;

    for (i = 1; i <= m; i++)
        if (s[1][i] == s[n][i] && s[1][i] == '#')
            link_ver++;

    if (k == 0) {
        printf("1");
    }

    if (link_hor > 0 && link_ver > 0) {
        printf("1");
        return 0;
    }

    if (link_hor == 0 && link_ver == 0) {
        printf("%lld", poww(cnt, k - 1));
        return 0;
    }

    if (k == 1) {
        printf("1");
        return 0;
    }

    a = cnt;
    if (link_hor) {
        b = hor;
        c = link_hor;
    } else {
        b = ver;
        c = link_ver;
    }

    ini.data[0][0] = a; ini.data[0][1] = -b;
    ini.data[1][0] = 0; ini.data[1][1] = c;

    ini = poww(ini, k - 1);

    ll sol = (mod + ini.data[0][0] + ini.data[0][1]);
    printf("%lld", sol % mod);


    return 0;
}


Measured memory_bytes: 1280
from random import sample
n=int(input())
if n==3:
  print("2 5 63"); exit()
l=[i for i in range(6,30001)if i%2==0 or i%3==0]
while True:
  ans=[2,3,4]
  ans+=sample(l,n-3)
  if sum(ans)%6==0:
    break
print(*ans)

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

int main() {
  string s;
  cin >> s;
  int A = (s[0] - '0')*10 + (s[1] - '0');
  int B = (s[2] - '0')*10 + (s[3] - '0');
  bool YYMM = (1<= B && B <= 12);
  bool MMYY = (1<= A && A <= 12);
  if (YYMM) {
	if (MMYY) {
      cout << "AMBIGUOUS" << endl;
    } else {
      cout << "YYMM" << endl;
    }
  } else {
	if (MMYY) {
      cout << "MMYY" << endl;
    } else {
      cout << "NA" << endl;
    }
  }
    
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int a[20000]={},b[20000]={},i,j;
    char c[20000]={};
    i=0;
    while(1){
        scanf("%d %c %d",&a[i],&c[i],&b[i]);
        if(c=='?'||i==20000){
            break;
        }
        i++;
    }
    for(j=0;j<i;j++){
        if(c[j]=='+'){
            a[j]+=b[j];
        }
        else if(c[j]=='-'){
            a[j]-=b[j];
        }
        else if(c[j]=='*'){
            a[j]*=b[j];
        }
        else if(c[j]=='/'){
            a[j]/=b[j];
        }
        else{
            break;
        }
    printf("%d\n",a[j]);
    }
    return 0;
}


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

int main() {
  int n;
  cin>>n;
  vector<string> s(n);
  for(int i=0;i<n;i++){
    cin>>s[i];
    sort(s[i].begin(),s[i].end());
  }
  vector<vector<int>> data(n, vector<int>(26));
  for(int i=0;i<n;i++){
    for(int j=0;j<s[i].size();j++){
      int num=s[i][j]-'a';
      data[i][num]++;
    }
  }
  string ans="";
  for(int i=0;i<26;i++){
    int mini=12345;
    for(int j=0;j<n;j++){
      mini=min(data[j][i],mini);
    }
    for(int k=0;k<mini;k++){
      ans+=char(i+'a');
    }
  }
cout<<ans<<endl;
}


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

#define pb push_back
#define mp make_pair
#define all(n) (n).begin(),(n).end()
#define fi first
#define se second

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

const int MOD = 1e9+7;

ll s[200005],o[200005],n;

int main() {

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


	cin >> n;
	for (int i=0;i<n;i++) cin>>s[i],o[i]=s[i];
	for (int i=1;i<n;++i) s[i]+=s[i-1],s[i]%=MOD;
	ll tot = s[0]*((s[n-1]-s[0]+MOD)%MOD);
	for (int i=1;i<n;++i) {
		tot+=(o[i])*((s[n-1]-s[i]+MOD)%MOD);
		tot%=MOD;
	}
	cout << tot << "\n";
}

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

int main(){
    int n,ans;
    
    while(cin>>n){
        ans=0;
        for(int i=0; i<10; i++){
            for(int j=0; j<10; j++){
                for(int k=0; k<10; k++){
                    for(int l=0; l<10; l++){
                        if(n==i+j+k+l) ans++;
                    }
                }
            }
        }
        cout << ans << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

#define iter(i, n) for (int i = 1; i <= n; ++i)
#define iter0(i, n) for (int i = 0; i < n; ++i)
#define forw(i, a, b) for (int i = a; i <= b; ++i)
#define NR 1010

const int mod = 1e9 + 7;

typedef long long i64;
typedef pair<int, int> pii;

int n, m;
i64 K;
char s[NR][NR];
bool mp[NR][NR];
int col[NR][NR];
//nwes

/*bool in_grid(int x, int y) { return 1 <= x && x <= n && 1 <= y && y <= m; }

void dfs(int x, int y) {
	col[x][y] = csz;
	iter0(d, 4) {
		int _x = x + dx[d], _y = y + dy[d];
		if (!col[_x][_y]) {
			if (in_grid(_x, _y)) dfs(_x, _y);
			else {
				;
			}
		}
	}
}*/

struct Mat {
	int a[2][2];
	Mat() { memset(a, 0, sizeof(a)); }
	int* operator[](int index) { return a[index]; }
} g;

Mat operator*(Mat a, Mat b) {
	Mat c;
	iter0(i, 2) iter0(k, 2) iter0(j, 2) c[i][j] = (c[i][j] + 1ll * a[i][k] * b[k][j]) % mod;
	return c;
}

Mat pow(Mat a, i64 z) {
	Mat s; s[0][0] = s[1][1] = 1;
	while (z > 0) {
		if (z % 2 == 1) s = s * a;
		a = a * a;
		z /= 2;
	}
	return s;	
}

int pr(int a, i64 z) {
	int s = 1;
	while (z > 0) {
		if (z % 2 == 1) s = 1ll * s * a % mod;
		a = 1ll * a * a % mod;
		z /= 2;
	}
	return s;
}

int main() {
	scanf("%d%d%lld", &n, &m, &K);
	if (K == 1) { puts("1"); return 0; }
	--K;
	iter(i, n) {
		scanf("%s", s[i] + 1);
		iter(j, m) mp[i][j] = (s[i][j] == '#');
	}

//	iter(i, n) iter(j, m) if (!col[i][j]) { dfs(i, j); break; }

	int cx = 0, cy = 0;
	iter(i, n) if (mp[i][1] && mp[i][m]) ++cx;
	iter(i, m) if (mp[1][i] && mp[n][i]) ++cy;

	int c1 = 0;
	iter(i, n) iter(j, m) if (mp[i][j]) ++c1;

//	printf("%d %d\n", cx, cy);

	if (cx != 0 && cy != 0) puts("1");
	else if (cx == 0 && cy == 0) printf("%d\n", pr(c1, K));
	else {
		if (cy != 0) {
			iter(i, m) iter(j, n) mp[i][j] = (s[j][i] == '#');
			swap(n, m); swap(cx, cy);
		}
		int c2 = 0;
		iter(i, n) iter(j, m) {
			if (mp[i][j] && mp[i][j - 1]) ++c2;
		}
		Mat g; g[0][0] = c1, g[1][0] = mod - c2, g[1][1] = cx;
		//printf("%d %d\n", c1, c2);
		Mat res = pow(g, K);
		printf("%d\n", (res[0][0] + res[1][0]) % mod);
	}

	/*iter0(s, 4) {
		int _s = 0;
		int csz = 0;
		forw(i, 0, n + 1) forw(j, 0, m + 1) col[i][j] = 0;
		iter(sx, n) iter(sy, m) if (!col[sx][sy]) {
			int h, t;
			q[h = t = 1] = pii(sx, sy);
			++csz;
			bool vis[4];
			while (h <= t) {
				pii u = q[h++];
				int x = u.fi, y = u.se;
				iter0(d, 4) if (s >> (d % 2) & 1) {
					int _x = x + dx[d], _y = y + dy[d];
					if (col[_x][_y] == 0) {
						if (in_grid(_x, _y)) q[++t] = pii(_x, _y), col[_x][_y] = csz;
						else {
							if (_x < 1) vis[0] = true;
							if (_y < 1) vis[1] = true;
							if (_x > n) vis[2] = true;
							if (_y > m) vis[3] = true;
						}
					}
				}
			}


		}
	}*/

	//n * m * c1 - (n-1) * m * c2

	return 0;
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[n+1],arr[n+1];
	for(int i=0;i<n-1;i++) cin>>a[i];
	for(int i=0;i<n;i++) arr[i]=0;
	for(int i=0;i<n-1;i++) arr[a[i]-1]++;
	for(int i=0;i<n;i++) cout<<arr[i]<<endl;
	return 0;
}


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

using namespace std;
const int N = 1e5 + 10;

int a[N],b[N];
int main()
{
    int A,B,m;
    scanf("%d%d%d",&A,&B,&m);
    int minn1 = N,minn2 = N;
    for(int i = 1;i <= A;i++)   scanf("%d",&a[i]),minn1 = min(minn1,a[i]);
    for(int i = 1;i <= B;i++)   scanf("%d",&b[i]),minn2 = min(minn2,b[i]);
    int ans = minn1 + minn2;
    while(m--)
    {
        int x,y,c;
        scanf("%d%d%d",&x,&y,&c);
        ans = min(ans,a[x]+b[y]-c);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include<algorithm>
#include <vector>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<map>
#include<numeric>
#include<regex>
using namespace std;

typedef long long ll;
#define modulo 1000000007 // 10^9 + 7
#define MAX 1000000000 // 10^9



int main() {
	ll N, P; cin >> N >> P;
	ll ans = 1;

	// 素因数分解メソッド
	map<ll, int> mp;
	for (ll i = 2; i*i <= P; i++) {
		while (P%i == 0) {
			mp[i]++;
			P /= i;
		}
	}
	if (P != 1) mp[P]++;
	
	for (auto e : mp) {
		int k = e.second / N;
		for (int i = 0; i < k; i++) ans *= e.first;
	}

	cout << ans << endl;

	return 0;
}

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

#define ll long long
#define ld long double

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define repA(i,A)   for(auto i:A)

#define err() cout<<"=================================="<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl

#define mp make_pair
#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)	A.rbegin(),A.rend()
#define ft first
#define sd second

#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V> 
#define Vpll vector<pll>

#define endl "\n"

const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e12;
#define PI 3.14159265

const ll N = 100005;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n;
    cin>>n;
    ll ans=0;
    ll A[n];
    rep(i,0,n)	cin>>A[i];
    ll cnt=0;
    rep(i,1,n){
    	if(A[i]<=A[i-1]){
    		cnt++;
    	}
    	else cnt=0;
    	ans = max(ans, cnt);
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(){
	ll H;
	cin >> H;
	ll ans = 0;
	ll rest = H;
	ll cnt = 1;
	while(rest > 0) {
		ans += cnt;
		rest /= 2;
		cnt *= 2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

bool exist[244140625];

int getnum(char *s){
    int i = 0;
    while(s[i] != '\0')
        i++;

    i--;
    int j = 0,k = 1;
    while(i >= 0){
        if(s[i] == 'A')
            j += k;
        else if(s[i] == 'C')
            j += k * 2;
        else if(s[i] == 'G')
            j += k * 3;
        else if(s[i] == 'T')
            j += k * 4;
        i--;k *= 5;
    }
    return j;
}

int main(void){
    int n;
    scanf("%d",&n);

    char op[10],s[20];

    for(int i = 0;i < n;i++){
        scanf("%s%s",op,s);
        if(op[0] == 'i'){
            exist[getnum(s)] = true;
        }else
            if(exist[getnum(s)])
                printf("yes\n");
            else
                printf("no\n");
    }
    return 0;
}

Measured memory_bytes: 7900
n = int(input())
l = list(map(int,input().split()))
ans = 0
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if l[i] != l[j] and l[j] != l[k] and l[k] != l[i]:
                if l[i] + l[j] > l[k] and l[j] + l[k] > l[i] and l[k] + l[i] > l[j]:
                    ans += 1

print(ans)

Measured memory_bytes: 73900
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main(void){
    
    //標準入力を受ける文字列
    string s,t;

    //s'<t'の確認用、変数checkをおく
    int check=0;

    //標準入力を受け取る
    cin >> s >> t;
    
    //文字列s,tの長さlen_s,len_t
    int len_s=s.size();
    int len_t=t.size();

    //文字列s,tをソートする
    sort(s.begin(),s.end());
    sort(t.begin(),t.end(),std::greater<char>());

    //先頭からi文字目において
    //s[i]<t[i]であることを確認していく
    for (int i=0;i<min(len_s,len_t);i++){

        if (s[i]-t[i]==0)
        {
            continue;
        }
        else if (s[i]-t[i]>0)
        {
            check=-1;
            break;
        }
        else if (s[i]-t[i]<0)
        {
            check=1;
            break;
        }
        
        
    }
	
  	if ( (check==0 && len_s<len_t) || check==1)
    {
    	cout << "Yes"<<endl;
    }
  	else
    {
      	cout << "No"<<endl;
    }


    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

unsigned short scan_sentence(unsigned char * str, unsigned short length_max);
void count_alphabet(unsigned char * str, unsigned short * num_check, unsigned short length);

int main(){
	unsigned short usW_D_length;        	/* 文字列長格納の変数 */
	unsigned char ubW_D_str[1200];      	/* 文字列格納の配列 */
	unsigned short usW_D_num_check[26]; 	/* アルファベットの数を記録する配列 */
	unsigned short usW_C_i;             	/* ループ変数 */
	
	/* 文字列配列の初期化 */
	for(usW_C_i = 0;usW_C_i < 1200;usW_C_i++){
		ubW_D_str[usW_C_i] = 0;
	}
	/* アルファベットの数を記録する配列の初期化 */
	for(usW_C_i = 0;usW_C_i < 26;usW_C_i++){
		usW_D_num_check[usW_C_i] = 0;
	}
	
	/* 文字列入力 */
	usW_D_length = scan_sentence(ubW_D_str, 1200);
	
	/* アルファベットの数をカウント */
	count_alphabet(ubW_D_str, usW_D_num_check, usW_D_length);
	
	/* カウントした結果を出力 */
	for(usW_C_i = 0;usW_C_i < 26;usW_C_i++){
		/* a : (aの個数) の形式で出力 */
		printf("%c : %d\n", (usW_C_i + 97), *(usW_D_num_check + usW_C_i));
	}
	
	return 0;
}

/* 関数名：文字列入力 */
/* 概要：文字列を入力する。その長さを返す */
/* 引数：文字列を格納する配列の先頭アドレス、その配列の大きさ */
/* 戻り値：入力された文字列の長さ */
unsigned short scan_sentence(unsigned char * str, unsigned short length_max)
{
	unsigned short usW_C_count_text = 0;	/* 文字列長カウンタ */
	unsigned short usW_C_i;             	/* ループ変数 */

	/* 文字列の入力 */
	for(usW_C_i = 0;usW_C_i < length_max;usW_C_i++){
		scanf("%c", str + usW_C_i);
		/* 入力終了の処理 */
		if(*(str + usW_C_i) == EOF){
			break;
		}
		/* 文字数をカウント */
		usW_C_count_text++;
	}

	/* 文字列長を返す */
	return usW_C_count_text;
}

/* 関数名：アルファベットカウント */
/* 概要：渡された文字列に各アルファベットが何文字含まれるか調べる */
/* 引数：文字列が格納された配列の先頭アドレス、アルファベットの数を記録する配列の先頭アドレス、文字列の長さ */
/* 戻り値：なし */
void count_alphabet(unsigned char * str, unsigned short * num_check, unsigned short length)
{
	unsigned short usW_C_i;      	/* ループ変数 */
	unsigned char ubW_D_alphabet;	/* 計算用変数 */
	
	/* 文字列中に各アルファベットが何文字含まれるか調べる */
	for(usW_C_i = 0;usW_C_i < length;usW_C_i++){
		/* アルファベットの場合カウント */
		if(((65 <= *(str + usW_C_i)) && (*(str + usW_C_i) <= 90)) || ((97 <= *(str + usW_C_i)) && (*(str + usW_C_i) <= 122))){
			/* アルファベットを配列の添え字として使える形に加工 */
			ubW_D_alphabet = (*(str + usW_C_i) & 0x1F) - 1;
			/* 文字列中に含まれていたアルファベットをカウント */
			*(num_check + ubW_D_alphabet) += 1;
		}
	}
}




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

int main(){
    int64_t n, m;
    cin >> n >> m;

    vector<vector<int>> g(n, vector<int>(0));
    for (auto i = 0; i < m; i++) {
        int a, b; cin >> a >> b; a--; b--;
        g[a].push_back(b); g[b].push_back(a);
    }

    bool flg = false;
    vector<int> a(n, -1);
    queue<int> q; q.push(0); a[0] = 0;
    while(not q.empty()) {
        auto p = q.front(); q.pop();
        for (auto & elm : g[p]) {
            if(a[elm] == -1) a[elm] = not a[p];
            else {
                if(a[elm] == a[p]) {
                    flg = true; break;
                }
                continue;
            }
            q.push(elm);
        }
        if(flg) break;
    }

    if(flg) cout << n * (n - 1) / 2 - m << endl;
    else {
        int64_t a_cnt = 0, b_cnt = 0;
        for (auto & elm : a) {
            if(elm == 0) a_cnt++;
            else b_cnt++;
        }
        cout << a_cnt * b_cnt - m << endl;
    }

    return 0;
}

Measured memory_bytes: 9152
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <cmath>

#define mod 1000000007

using namespace std;
 
int main(void){
	
	int K, S, count=0;
	
	cin >> K >> S;
	
	for(int i=0; i<=K; i++){
		for(int j=0; j<=K; j++){
			if(i+j <= S && K+i+j >= S)
				count++;
		}
	}
	
	
	cout << count;
	
	return 0;
}

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

int main()
{
    vector<int> num(9, 0);

    int N;
    cin >> N;
    for (int i = 0, a; i < N; i++) {
        cin >> a;
        num[min(a / 400, 8)]++;
    }

    int mini = 0, maxi;
    for (int i = 0; i < 8; i++)
        if (num[i])
            mini++;
    if (mini == 0) {
        mini = 1;
        maxi = num[8];
    } else
        maxi = mini + num[8];

    cout << mini << " " << maxi << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <queue>
#include <stack>
#include <stdlib.h>
using namespace std;
#define rep(i,n) for (int i = 0; i <n; i++) 
 
int main(void){
    int n,s,min;s=0;;
    std::cin >> n;int sone=0;
    int w[n] ;
    for(int i=0;i<n;i++){
        cin>>w[i];s+=w[i];
    }
    min=abs(s-2*w[0]);
    //std::cout << min << std::endl;
    for(int i=0;i<n;i++){
        sone+=w[i];
        if(min>abs(s-sone*2))min=abs(s-sone*2);//std::cout <<sone<< min << std::endl;
    }
    std::cout << min<< std::endl;
    //std::cout << abs(s-(w[0]+w[1])*2) << std::endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
3 5
0 0 1
0 1 2
0 2 3
1 0 2
1 1 2

output:
1
2
"""

import math
import sys

INIT_MAX = pow(2, 31) - 1


class SegmentTree(object):
    __slots__ = ('dat', 'tree_range')

    def __init__(self, n):
        """
        Init a SegmentTree with update and find for range minimum queries.
        """
        self.tree_range = pow(2, math.ceil(math.log2(n)))
        self.dat = [INIT_MAX] * (2 * self.tree_range - 1)

    # let A[k]=a
    def update(self, k, a):
        k += self.tree_range - 1
        self.dat[k] = a
        while k > 0:
            k = (k - 1) // 2
            self.dat[k] = min(self.dat[k * 2 + 1], self.dat[k * 2 + 2])

    # get min(A[s] A[s+1] ... A[t])
    def find(self, s, t, k=0, left=0, right=float('inf')):
        if right <= s or t <= left:
            return INIT_MAX
        elif s <= left <= right <= t:
            return self.dat[k]
        else:
            vl = self.find(s, t, k * 2 + 1, left, (left + right) // 2)
            vr = self.find(s, t, k * 2 + 2, (left + right) // 2, right)
            return min(vl, vr)


def cmd_exec(cmd_list, n_num):
    case = SegmentTree(n_num)
    end = pow(2, math.ceil(math.log2(n_num)))

    for query in cmd_list:
        cmd, ele_1, ele_2 = map(int, query)
        if cmd == 0:
            case.update(ele_1, ele_2)
        elif cmd == 1:
            assert ele_1 <= ele_2
            res = case.find(s=ele_1, t=ele_2 + 1, right=end)
            print(res)

    return None


def solve():
    _input = sys.stdin.readlines()
    n_num, q_num = map(int, _input[0].split())
    q_list = map(lambda x: x.split(), _input[1:])

    cmd_exec(q_list, n_num)
    return None


if __name__ == '__main__':
    solve()

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

int main() {
    int N;
    cin >> N;
    vector<int> d(N);
    rep(i,0,N) cin >> d[i];
    sort(d.begin(), d.end());
    // map<int,int> counts;
    // rep(i,0,N) counts[d[i]]++;

    int k1,k2;
    bool isHalf = true;
    int idx = N/2-1;
    k1 = d[idx];
    k2 = d[idx+1];
    if(k2 == k1) isHalf = false;
    cout << (isHalf?k2-k1:0) << endl;
}

Measured memory_bytes: 640
#![allow(non_snake_case)]
#![allow(unused_imports)]
use proconio::input;
use std::collections::HashMap;
use std::collections::VecDeque;
use std::cmp::max;
use std::cmp::min;


fn main() {
    input! {
        N: usize,
        M: usize,
    }

    // i番目の食べ物が好きだと答えた人数
    let mut like_cnt = vec![0i64; M];

    for _ in 0..N {
        input! {
            K: usize,
            As: [usize; K],
        }

        for &a in As.iter() {
            like_cnt[a - 1] += 1;
        }
    }

    let ans = like_cnt.iter().filter(|&&cnt| cnt == N as i64).count();
    println!("{}", ans);
}


Measured memory_bytes: 2192
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<stack>
#include<cstring>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
typedef long long ll;
ll  a[1111111];
int main()
{
	ll n,k,q,x;
	cin>>n>>k>>q;
	for(int i =0;i<n;++i)
	{
		a[i] = k;
	 } 
	 
	 for(ll i =0;i<q;++i)
	 {
	 	
	 	scanf("%lld",&x);
	 	a[x-1]++;
	 }
	 
	 for(ll j=0;j<n;++j)
	 {
	 	if(a[j]-q>0)
	 		cout<<"Yes"<<endl;
	 	else	
		 	cout<<"No"<<endl; 
	 }
	 return 0;
 } 

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

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;


template <class D> struct MinDist {
    V<D> dist;
    V<int> from;
};

template <class D, class E, class PQ, class P>
MinDist<D> get_mindist(const VV<E>& g, int s, D inf) {
    int n = (int)g.size();
    V<D> dist = V<D>(n, inf);
    V<int> from = V<int>(n);
    PQ q;
    q.push(P{0, s});
    dist[s] = D(0);
    while (!q.empty()) {
        P p = q.top();
        q.pop();
        if (dist[p.to] < p.key) continue;
        for (E e : g[p.to]) {
            if (p.key + e.dist < dist[e.to]) {
                dist[e.to] = p.key + e.dist;
                from[e.to] = p.to;
                q.push(P{dist[e.to], e.to});
            }
        }
    }
    return MinDist<D>{dist, from};
}
template <class D, class E>
MinDist<D> get_mindist_pq(const VV<E>& g,
                          int s,
                          D inf = numeric_limits<D>::max()) {
    struct P {
        D key;
        int to;
        bool operator<(P r) const { return key > r.key; }
    };
    return get_mindist<D, E, priority_queue<P>, P>(g, s, inf);
}

const int MN = 100100;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20) << fixed;
    int n, m;
    cin >> n >> m;

    using P = pair<int, int>;
    V<set<int>> gc(n);
    VV<P> _g(n);
    for (int i = 0; i < m; i++) {
        int p, q, c;
        cin >> p >> q >> c; p--; q--;
        gc[p].insert(c);
        gc[q].insert(c);
        _g[p].push_back(P(q, c));
        _g[q].push_back(P(p, c));
    }

    int co = 0;
    map<P, int> p2id;
    for (int i = 0; i < n; i++) {
        gc[i].insert(0);
        for (int c: gc[i]) {
            p2id[P(i, c)] = co;
            co++;
        }
    }

    struct Edge {
        int to, dist;
    };
    VV<Edge> g(co);
    for (int i = 0; i < n; i++) {
        for (P p: _g[i]) {
            int j = p.first;
            int c = p.second;
            int mid = p2id[P(i, c)];
            int yid = p2id[P(j, c)];
            g[mid].push_back(Edge{yid, 0});
        }
        for (int c: gc[i]) {
            if (c == 0) continue;
            int mid = p2id[P(i, c)];
            int yid = p2id[P(i, 0)];
            g[mid].push_back(Edge{yid, 0});
            g[yid].push_back(Edge{mid, 1});
        }
    }
    int sid = p2id[P(0, 0)];
    int tid = p2id[P(n-1, 0)];
    int ans = get_mindist_pq<int>(g, sid).dist[tid];
    if (ans >= TEN(9)) ans = -1;
    cout << ans << endl;
    return 0;
}


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

class Solution
{
    static long almostSorted(int[] arr)
    {
        var minHeigth = 0l;
        var prevH = arr[0];
        for (var i = 1; i < arr.Length; i++)
        {
            if (arr[i] < prevH)
            {
                minHeigth += prevH - arr[i];
            }
            else 
            {
                prevH = arr[i];
            }
        }
        return minHeigth;
    }



    static void Main(string[] args)
    {
        var n = Console.ReadLine();
        var arr = Console.ReadLine().Split(' ').Select(x=> int.Parse(x)).ToArray();
        var result = almostSorted(arr);
        //var a = almostSorted(new[] { 10, 3 });
        Console.WriteLine(result);
    }
}

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

int main(){
  vector<char> s(4);
  for(int i=0;i<4;i++){
    cin >> s.at(i);
  }
  int count1=0;
  int count2=0;
   for(int i=0;i<4;i++){
     if(s.at(i)=='+'){
       count1++;
     }else{
       count2++;
     }}
     cout << count1-count2 << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>
#include <iostream>
#include <iomanip>
using namespace std;

int main() 
{
    
    int N;
    cin >> N;
    vector<double>V(N);
    for (int i = 0; i < N; i++) {
        cin >> V.at(i);
    }
    sort(V.begin(), V.end());
    
    double ans = 0;
    for (int i = 0; i < N-1; i++) {
        ans = max(ans, (V.at(i) + V.at(i+1)) / 2.0);
        V.at(i+1) = ans;
    }
    cout << fixed << setprecision(10);
    cout << ans << endl;
}

Measured memory_bytes: 256
n,k,*h=map(int,open(0).read().split())
dp=[0]+[10**18]*~-n
for i in range(1,n):
    for j in range(k):
        if i-k+j<0:continue
        dp[i]=min(dp[i],dp[i-k+j]+abs(h[i]-h[i-k+j]))
print(dp[-1])

Measured memory_bytes: 59948
#include <iostream>
using namespace std;
string s[5];
int p, x[5];
int main() {
	cin>>s[0]>>s[1]>>s[2];
	s[0]+='A', s[1]+='B', s[2]+='C';
	while(1) {
		p = s[p][x[p]++] -'a';
		if(s[p][x[p]]<'a') break;
	}
	cout<<s[p][x[p]];
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using p = pair<int, int>;
    
int main(){
    string s;
    cin >> s;
    if (s[2]==s[3] && s[4] == s[5]) cout << "Yes " << endl;
    else cout << "No" << endl;
    return 0;
}

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

typedef long long ll;

int main()
{
	string s;
	cin >> s;
	if (s[2] == s[3] && s[4] == s[5])
		cout << "Yes\n";
	else
		cout << "No\n";

}

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


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

    string s;
    cin>>s;
    int cnt[3]={};
    for(int i=0;i<s.size();i++){
        cnt[s[i]-'a']++;
    }
    sort(cnt,cnt+3);
    if(cnt[2]-cnt[0]>1){
        cout<<"NO"<<endl;
    }
    else cout<<"YES"<<endl;
    
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
struct edge{ll to, cost;};
typedef pair<ll,ll> P;
struct graph{
  ll V;
  vector<vector<edge> > G;
  vector<ll> d;

  graph(ll n){
    init(n);
  }

  void init(ll n){
    V = n;
    G.resize(V);
    d.resize(V);
    rep(i,V){
      d[i] = INF;
    }
  }

  void add_edge(ll s, ll t, ll cost){
    edge e;
    e.to = t, e.cost = cost;
    G[s].push_back(e);
  }

  void dijkstra(ll s){
    rep(i,V){
      d[i] = INF;
    }
    d[s] = 0;
    priority_queue<P,vector<P>, greater<P> > que;
    que.push(P(0,s));
    while(!que.empty()){
      P p = que.top(); que.pop();
      ll v = p.second;
      if(d[v]<p.first) continue;
      for(auto e : G[v]){
        if(d[e.to]>d[v]+e.cost){
          d[e.to] = d[v]+e.cost;
          que.push(P(d[e.to],e.to));
        }
      }
    }
  }
};
class UnionFind
{
public:
  int par[100005];
  int depth[100005];
  int nGroup[100005];
 
  UnionFind(int n) {
    init(n);
  }
 
  void init(int n) {
    for(int i=0; i<n; i++) {
      par[i] = i;
      depth[i] = 0;
      nGroup[i] = 1;
    }
  }
 
  int root(int x) {
    if(par[x] == x) {
      return x;
    } else {
      return par[x] = root(par[x]);
    }
  }
 
  bool same(int x, int y) {
    return root(x) == root(y);
  }
 
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if(x == y) return;
 
    if(depth[x] < depth[y]) {
      par[x] = y;
      nGroup[y] += nGroup[x];
      nGroup[x] = 0;
    } else {
      par[y] = x;
      nGroup[x] += nGroup[y];
      nGroup[y] = 0;
      if(depth[x] == depth[y])
        depth[x]++;
    }
  }
};
int main(){
ll n,m; cin>>n>>m;
ll a[n]={};
rep(i,n){
cin>>a[i];
}
UnionFind tree(n);
rep(i,m){
int x,y; cin>>x>>y;
tree.unite(x-1,y-1);}
ll ca = 0;
rep(i,n){
if(tree.same(a[i]-1,i)) ca++;
   }
cout << ca << endl;}


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

using namespace std;

int main() {
    int N;
    int x[100];
    int y[100];
    int h[100];
    int h_ans;

    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i] >> h[i];
    }

    for (int cx = 0; cx <= 100; cx++) {
        for (int cy = 0; cy <= 100; cy++) {
            bool enable = false;
            bool found  = true;
            for (int i = 0; i < N; i++) {
                if (h[i] > 0) {
                    int h_tmp = h[i] + abs(x[i] - cx) + abs(y[i] - cy);

                    if (enable) {
                        if (h_ans != h_tmp) {
                            found = false;
                            break;
                        }
                    } else {
                        h_ans = h_tmp;
                        enable = true;
                    }
                }
            }

            if (! (enable && found) ) {
                continue;
            }

            for (int i = 0; i < N; i++) {
                int dist = abs(x[i] - cx) + abs(y[i] - cy);
                if (h[i] == 0) {
                    if (dist < h_ans) {
                        found = false;
                    }
                }
            }

            if (found) {
                cout << cx << " " << cy << " " << h_ans << endl;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 256
def gcd(m, n):
    while n:
        m, n = n, m % n
    return m
a, b = map(int, input().split())
g = gcd(a, b)

ans = 1
x = 2
while x*x <= g:
    if g % x == 0:
        while g % x == 0:
            g //= x
        ans += 1
    x += 1
if g > 1:
    ans += 1
print(ans)

Measured memory_bytes: 3064