akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}

bool func(pair<ll,ll> a , pair<ll,ll> b){
	if(a.second > b.second) return true;
	else return false;
}

int main()
{
	ll N;
	cin >> N;
	N/=2;

	vector<ll> lsta,lstb;
	map<ll,ll> cnta,cntb;

	rep(i,N){
		ll a, b;
		cin >> a >> b ;
		lsta.pb(a);
		lstb.pb(b);
		cnta[a]++;
		cntb[b]++;
	}

	rmsame(lsta);
	rmsame(lstb);

	vector<pair<ll,ll> > resa, resb;
	rep(i,lsta.size()){
		resa.pb(mp(lsta[i], cnta[lsta[i]]));
	}
	rep(i,lstb.size()){
		resb.pb(mp(lstb[i], cntb[lstb[i]]));
	}
	sort(all(resa));
	sort(all(resb));

	for(ll i = resa.size()-1; i>= 0; i--){
		if(i >= 2){
			if(resa[i].second == resa[i-2].second){
				resa.erase(resa.begin() + i);
				continue;
			}
		}
	}
	for(ll i = resb.size()-1; i>= 0; i--){
		if(i >= 2){
			if(resb[i].second == resb[i-2].second){
				resb.erase(resb.begin() + i);
				continue;
			}
		}
	}

	ll ans = N*2-2;

	rep(i, resa.size()) rep(j, resb.size()){
		if(resa[i].first == resb[j].first){
			ans = min(ans,  N*2- max(resa[i].second, resb[j].second));
		}
		else{
			ans = min(ans, N*2 - resa[i].second - resb[j].second);
		}
	}
	cout << ans << endl;


	return 0;
}

/*
/^[\w!\x22\#$%&@\'() * +,-.\/;:]+$/
*/


Measured memory_bytes: 9580
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int rec1 = a*b;
		int rec2 = c*d;
		if (rec1 > rec2) {
			System.out.println(rec1);
		}else {
			System.out.println(rec2);
		}
	}
}


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

int main() {
    long int n, a;
    cin >> n;
    long int min = 10000000;
    long int max = -10000000;
    long long int sum = 0;
    for(int i=0; i<n; i++){
        cin >> a;
        if(a >= max){
            max = a;
        }
        if(a <= min){
            min = a;
        }
        sum += a;
    }
    cout << min << ' ' << max << ' ' << sum << endl;
}

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


typedef long long lli;
typedef unsigned long ul;
typedef pair<lli,lli> pll;
typedef vector<lli> vl;
#define rep(i,n) for(lli i=0; i<(n); ++i)
#define reps(i,n) for(lli i=1; i<n; ++i)
#define rrep(i,x) for(lli i=((n)-1); i>=0; --i)
#define rreps(i,x) for(lli i=((n)); i>0; --i)
#define REP(i,n) for(lli i=0; i<n; ++i)
#define REPS(i,n) for(lli i=1; i<n; ++i)
#define RREP(i,x) for(lli i=((n)-1); i>=0; --i)
#define RREPS(i,x) for(lli i=((n)); i>0; --i)
#define FOR(i,a,b) for (lli i=(a);i<(b);i++)
#define INF LONG_MAX/3
#define PB push_back
#define pb push_back
#define FT first
#define SD second
#define y0 y348
#define y1 y348
#define next asdnext
#define prev asdprev
#define all(a) (a).begin(),(a).end()
#define eps pow(10,-7)
#define SZ(x) ((int)(x).size())
#define fill(x,y) memset(x,y,sizeof(x))

lli gcd(lli a,lli b){return b?gcd(b,a%b):a;}
lli dx[4]={1,0,-1,0};
lli dy[4]={0,1,0,-1};

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


int main(){
  lli H,W;
  string str[100];
  bool f=true,ff;

  cin >>H>>W;
  rep(i,H)
    cin>>str[i];


  while(f){
    f=false;
    rep(i,H){
      if(str[i].find('#')==-1){
	FOR(j,i,H-1)
	  str[j]=str[j+1];
	H--;
	f=true;
      }
    }
    rep(i,W){
      ff=false;
      rep(j,H){
	if(str[j][i]=='#')ff=true;
      }

      if(!ff){
	f=true;
	rep(j,H)
	  str[j].erase(str[j].begin()+i);
	W--;
      }
    } 
  }
  
  rep(i,H)
    cout << str[i] << endl;
  return 0;
}


Measured memory_bytes: 256
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# 約数生成
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

n,k = lr()
a = lr()
dic = collections.Counter(a)
dic_list = list(dic.items())
dic_list.sort(key=lambda x:x[1], reverse=True)
ans = 0
if len(dic_list) <= k:
    print(ans)
else:
    for _,num in dic_list[k:]:
        ans+=num
    print(ans)


Measured memory_bytes: 133388
n = int(input())

if n >= 1800:
  print(1)
elif n >= 1600:
  print(2)
elif n >= 1400:
  print(3)
elif n >= 1200:
  print(4)
elif n >= 1000:
  print(5)
elif n >= 800:
  print(6)
elif n >= 600:
  print(7)
else:
  print(8)

Measured memory_bytes: 8952
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

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

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

template<class T>
bool umax(T &a, const T &b){
    if (a<b) {
        a=b; return 1;
    }
    return 0;
}

template<class T>
bool umin(T &a, const T &b) {
    if (b<a) {
        a=b; return 1;
    }
    return 0;
}

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};
// v.front() = -BOUND;
// v.back() = BOUND;
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }
    // 素数である
    return true;
}


// warshall_floyd
int N;
ll d[202][202];
void warshall_floyd(){
    for(int k=0; k<N; k++) {
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < N; ++j) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

int M,R;
vector<int>r(10);
ll res=INF;
bool used[9];
void dfs (int c, int las, ll dist)
{
    if (c==R+1){
        if ( res > dist ) res = dist ;
        return ;
    }
    for ( int i=0; i<R; i++) {
        if (!used[i]) {
            used[i] = true;
            if (las == -1) dfs(c+1,i,0);
            else dfs(c+1,i,dist+d[r[las]][r[i]]);
            used[i] = false;
        }
    }
}
int main() {
    cin >> N >> M >>R;
    Fill(d,INF);

    rep(i,R){
        cin >> r[i];
        r[i]--;
    }
    rep(i,M){
        int a,b,c;
        cin >> a >> b >> c;
        a--, b--;
        d[a][b]=d[b][a]=c;
    }

    warshall_floyd();
    dfs(1,-1,0);
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
int main(void)
{
	int a,b;
	int d;
	int r;
	double f;

	scanf("%d %d",&a,&b);

	d = a/b;
	r = a%b;
	f = (1.0*a)/b;

	printf("%d %d %f\n",d,r,f);

	return 0;
}

Measured memory_bytes: 632
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		int[] x= new int[n];
		double allx=0;
		double allx2=0;
		for(int i=0;i<n;i++){
			x[i] = sc.nextInt();
			allx+=x[i];
			allx2+=x[i]*x[i];
		}
		int p;
		if(allx/n-(int)(allx/n)<0.5){
			p=(int)(allx/n);
		}else{
			p=(int)(allx/n)+1;
		}
	System.out.println((int)(allx2-2*allx*p+n*p*p));
	}
}

Measured memory_bytes: 22740
def INT():
    return int(input())

def MI():
    return map(int, input().split())

def LI():
    return list(map(int, input().split()))

p = [INT() for i in range(5)]
k = INT()

p.sort()
flg = False

for i in range(5):
    for j in range(i, 5):
        if abs(p[j] - p[i]) > k:
            flg = True
            break
            
print(":(" if flg else "Yay!")

Measured memory_bytes: 61912
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  /* your code */
  NodePointer cur = nil->next;
  while(1){
    if( cur == nil ) return NULL;
    if( cur->key == key ) return cur;
    cur = cur->next;
  }
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  /* your code */
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  NodePointer t = nil->prev;
  if( t == nil ) return;
  deleteNode(t);
  /* your code */
}

void delete(int key){
  NodePointer t;
  t=listSearch(key);
  if(t==NULL) return;
  deleteNode(t);
  /* your code */
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;

  x->prev = nil;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;

  /* 

   your code 


  */

}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}

Measured memory_bytes: 31788
"use strict";

const input = require("fs").readFileSync("/dev/stdin", "utf8");
const inputs = input.split(" ");

const A = Number(inputs[0]);
const B = Number(inputs[1]);

const main = (A, B) => {
    let X;
    if ((A + B) % 2 === 0) {
        return Math.abs((A + B) / 2);
    } else {
        return "IMPOSSIBLE";
    }
};
console.log(main(A, B));

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

int main(){
  string s;
  cin >> s;
  s.replace(3,1,"8");
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#define int long long
using namespace std;
bool f(int q) {
	int p = 1, k = q;
	while (p * 10 <= k)p *= 10;
	while (p > 1) {
		if (k / p != k % 10)return 0;
		k /= 10; p /= 10; k %= p; p /= 10;
	}
	return 1;
}
signed main() {
	int n;
	cin >> n;
	int k = 0;
	while (1) {
		if (n - k >= 0 && f(n - k)) {
			cout << n - k << endl;
			return 0;
		}
		if (f(n + k)) { cout << n + k << endl; return 0; }
		k++;
	}
}


Measured memory_bytes: 3116
class UnionFind:
    def __init__(self, num):
        self.table = [-1 for _ in range(num)]

    def find(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self.find(self.table[x])
            return self.table[x]

    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)

        if s1 != s2:
            if self.table[s1] <= self.table[s2]:
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
            return True
        return False
N,M = map(int,input().split())
u = UnionFind(N)
for i in range(M):
    X,Y,Z = map(int,input().split())
    u.union(X-1,Y-1)
ans = []
for i in range(N):
    ans.append(u.find(i))
ans = len(set(ans))
print(ans)

Measured memory_bytes: 13984
using System;
using System.Collections.Generic;
class Solve{
    string s;
    string t;
    int N;
    public Solve(){}
    public static int Main(){
        new Solve().Calc();
        return 0;
    }
    void Calc(){
        getinput();
        for(int i=N;i<2*N+1;i++){
            bool c = true;
            for(int j=0;j<2*N-i;j++){
                c = c && (s[i-N+j] == t[j]);
            }
            if(c){
                Console.WriteLine(i);
                return;
            }
        }
    }
    void getinput(){
        N = int.Parse(Console.ReadLine());
        s = Console.ReadLine();
        t = Console.ReadLine();
    }    
}

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

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;

#define INF 1e9
#define MOD 1000000007
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define each(x, v) for (auto& x: (v))
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl

void solve();
void in(){} template<class T, class... U> void in(T &t, U &...u){ cin >> t; in(u...); }
int main() { cin.tie(0); ios::sync_with_stdio(0); solve(); }

void solve() {
  int N;
  in(N);
  priority_queue<double, vector<double>, greater<double>> v;
  rep(i, 0, N) {
    int vi;
    in(vi);
    v.push(vi);
  }
  while (v.size() > 1) {
    double a = v.top(); v.pop();
    double b = v.top(); v.pop();
    v.push((a + b) / 2);
  }
  print(v.top());
}


Measured memory_bytes: 256
#include<stdio.h>


int main(void)
{
    int a,b,c;

    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);

    if((b>=(c-a))&&((c-a)>=0))
        printf("YES\n");
    else
        printf("NO\n");

    return 0;
}


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

using namespace std;
#define ll long long 
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

int main() {
  int N;
    string S;
    cin >> N >> S;
    
    int res = 0;
    for (int i = 0; i < N;) {
        int j = i;
        while (j < N && S[j] == S[i]) ++j;
        ++res;
        i = j;
    }
    cout << res << endl;
}


Measured memory_bytes: 512
S = int(input())
m = S // (10**9)
n = S % (10**9)

p,q = 0,0
r,s = 0,0
if(m == 10**9):
    p,q = 10**9,1
    r,s = 0,10**9
else:
    p,q = m+1,10**9-n
    r,s = 1,10**9
print(0,0,p,q,r,s)

Measured memory_bytes: 9192
def primes(max)
  nums = Array.new(max + 1, 1)
  nums[0] = nums[1] = 0

  (2..Math.sqrt(max)).each do |sieve|
    if nums[sieve] == 1
      (2 * sieve).step(max, sieve).each do |num|
        nums[num] = 0
      end
    end
  end

  nums
end

max = 50_000

primes = primes(max)

nums = (2..max).select { |num| primes[num] == 1 }

while line = gets
  n = line.chomp.to_i
  break if n == 0

  answer = 0

  for i in nums
    j = n - i
    break if i > j
    answer += 1 if primes[j] == 1
  end
  
  puts answer
end

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

int main() {
    string X;
    cin >> X;
    stack<char> st;
    for (int i = 0; i < X.size(); i++) {
        if (st.empty()) {
            st.push(X[i]);
        } else {
            if (st.top() == 'S' && X[i] == 'T') {
                st.pop();
            } else {
                st.push(X[i]);
            }
        }
    }
    cout << st.size() << endl;
    return 0;
}

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

#define INV '.'

void PropDistribute(char **map, int i, int j, char fruit){
	int di[] = {1,0,-1,0};
	int dj[] = {0,1,0,-1};

	if( map[i][j] != fruit ) return ;
	map[i][j] = INV;
	
	for(int u = 0; u < sizeof(di)/sizeof(*di); ++u){
		PropDistribute(map, i+di[u], j+dj[u], fruit);
	}

	return ;
}
int main(void){
	while( true ){
		int cnt = 0; // answer
		int H, W;
		char **map;
		
		cin >> H >> W;
		if( !H && !W ) break;

		map = new char*[H+2];
		for(int i = 0; i < H+2; ++i){
			map[i] = new char[W+2];
		}

		// init
		for(int i = 0; i < H+2; ++i){
			for(int j = 0; j < W+2; ++j){
				map[i][j] = INV;
			}
		}

		// input
		cin.ignore();
		for(int i = 1; i < H+1; ++i){
			for(int j = 1; j < W+1; ++j){
				cin >> map[i][j];
			}
			cin.ignore();
		}

		for(int i = 1; i < H+1; ++i){
			for(int j = 1; j < W+1; ++j){
				if( map[i][j] != INV ){
					cnt++;
					PropDistribute(map, i, j, map[i][j]);
				}
			}
		}

		cout << cnt << '\n';

		for(int i = 0; i < H+2; i++){
			delete [] map[i];
		}
		delete [] map;
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.*;
import java.lang.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] array = new int[n];
        for(int i=0;i<n;i++){
            array[i] = Integer.parseInt(sc.next());
        }
        sc.close();
        int minsub = 100000;
        for(int i=0;i<n-1;i++){
            int sumA = 0;
            int sumB = 0;
            for(int j=0;j<i+1;j++){
                sumA += array[j];
            }
            for(int j=i+1;j<n;j++){
                sumB += array[j];
            }
            int sub = (int)Math.abs(sumA - sumB);
            if(sub < minsub){
                minsub = sub;
            }
        }
        System.out.println(minsub);
    }
}

Measured memory_bytes: 21844
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size()) 
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 17;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

class Node {
public:
	int mn, v;
	Node() {
		*this = Node(0, 0);
	}
	Node(int mn, int v) : mn(mn), v(v) {}
};
Node indt[600000];
void propagate(int n) {
	int v = indt[n].v;
	indt[2 * n].mn += v;
	indt[2 * n].v += v;
	indt[2 * n + 1].mn += v;
	indt[2 * n + 1].v += v;
	indt[n].v = 0;
}
void update(int st, int en, int S, int E, int n, int v) {
	if (en < S || E < st) return;
	if (st <= S && E <= en) {
		indt[n].mn += v;
		indt[n].v += v;
		return;
	}
	propagate(n);
	int M = (S + E) / 2;
	update(st, en, S, M, 2 * n, v);
	update(st, en, M + 1, E, 2 * n + 1, v);
	indt[n].mn = min(indt[2 * n].mn, indt[2 * n + 1].mn);
}
int getmn(int st, int en, int S, int E, int n) {
	if (en < S || E < st) return INF;
	if (st <= S && E <= en) return indt[n].mn;
	propagate(n);

	int M = (S + E) / 2;
	return min(getmn(st, en, S, M, 2 * n), getmn(st, en, M + 1, E, 2 * n + 1));
}

ll ans = 0;
void dodo(int st, int en) {
	if (st > en) return;
	int mn = getmn(st, en, 1, IT_MAX, 1);
	ans += mn;
	update(st, en, 1, IT_MAX, 1, -mn);

	while (st <= en) {
		int s = st, e = en, m, r = en + 1;
		while (s <= e) {
			m = (s + e) / 2;
			if (getmn(s, m, 1, IT_MAX, 1) == 0) {
				r = m;
				e = m - 1;
			}
			else s = m + 1;
		}
		dodo(st, r - 1);
		st = r + 1;
	}
}

pii in[100050];
bool chk[100050];
int main() {
	int N, i, j, k;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		int t;
		scanf("%d", &t);
		for (j = 0, k = 1; t >= (ll)2*k; j++, k *= 2);
		in[i].second = j;
		if (k == t) in[i].first = j;
		else in[i].first = j + 1;
	}
	for (i = 1; i <= N; i++) {
		chk[i] = true;
		if (in[i].first == in[i].second) chk[i] = false;
		if (i != 1 && in[i] < in[i - 1]) chk[i] = false;
		if (i != N && in[i] < in[i + 1]) chk[i] = false;
	}

	ll c = 0;
	for (i = 1; i <= N; i++) {
		if (!chk[i]) continue;
		c++;
		if (i == N || !chk[i + 1]) {
			ans += (c + 1) / 2;
			c = 0;
		}
	}

	for (i = 1; i <= N; i++) update(i, i, 1, IT_MAX, 1, in[i].second);
	dodo(1, N);
	return !printf("%lld\n", ans);
}

Measured memory_bytes: 5760
N, X = map(int,input().split())
x = list(map(int,input().split()))

import numpy as np
X_abs = abs(np.array(x)-X)
#最大公約数、最小公倍数
import fractions

gcd = X_abs[0]
for  i in range (1,N):
    gcd = fractions.gcd(gcd,X_abs[i])
    
print(gcd)

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

int main()
{
	int N, K;
	cin >> N >> K;
	vector<int> p( N );
	for( int i = 0; i < N; i++ ) {
		cin >> p[i];
	}

	double ans = 0;
	double s = 0;
	for( int i = 0; i < N; i++ ) {
		s += (double)(p[i] + 1) / 2;
		if( i >= K - 1 ) {
			ans = max( ans, s );
			s -= (double)(p[i - (K - 1)] + 1) / 2;
		}
	}

	cout << fixed << setprecision(12) << ans << endl;
}


Measured memory_bytes: 1024
slist=list(input())
k=int(input())
n=len(slist)
kaisu=0
i=1
shirushi=0
kotae=0
rouge=0
flag=0

for l in range(1,n):
	if slist[l]==slist[l-1]:
		rouge+=1
	else:
		break
		
if rouge==n-1:
	flag=1

if n>1 and flag==0:

	while 1<=i<=n-1:
		if slist[i]==slist[i-1]:
			kaisu+=1
			if i==n-1:
				shirushi=1
			i+=2
		else:
			i+=1
	
	if k>1:
		if shirushi==0 and slist[0]==slist[n-1]: #このとき二回目以降は初項書き換え
			if slist[0]==slist[1]: #やばいパターン
				yabaikaisu=1
				i=2
				shirushi=0
			
				while 1<=i<=n-1:
					if slist[i]==slist[i-1]:
						yabaikaisu+=1
						if i==n-1:
							shirushi=1
						i+=2
					else:
						i+=1
					
				kotae=kaisu+(k-1)*yabaikaisu
			else: #やばくはないパターン
				kotae=k+kaisu*k-1
	
		else: #楽勝パターン
			kotae=kaisu*k
			
	else: #k=1のとき
		kotae=kaisu

elif flag==1:
	kosuu=n*k
	if kosuu%2==0:
		kotae=kosuu/2
	else:
		kotae=(kosuu-1)/2

else: #n=1のとき
	if k%2==0:
		kotae=k/2
	else:
		kotae=(k-1)/2

print(int(kotae))

Measured memory_bytes: 3064
#include <stdio.h>
#include <ctype.h>

int main(){
  char ch;
  
  while(ch != '\n'){
    scanf("%c", &ch);
    if(isupper(ch))//if LARGE charactor
      ch = tolower(ch);
    else if(islower(ch))//if small charactor
      ch = toupper(ch);
    
    printf("%c", ch);
  }
  return 0;
}

Measured memory_bytes: 524
/*input
1 100000
1000000000
*/
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <string>
#include <set>
#include <stack>
#include <queue>
#include <iterator>
#include <limits>
#include <deque>
#include <algorithm>
#include <cmath>
#include <list>
#include <map>
#include <climits>
#define ff first
#define ss second
#define MAX 10005
#define endl "\n"
#define mp make_pair
#define pb push_back
#define int long long
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define vi vector<int>
#define mii map<int,int>
#define pii pair<int,int>
#define len(x) (x.size())
#define all(a) a.begin(),a.end()
#define f(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) for(int i=0;i<a;i++)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define T int tc;cin>>tc;for(int t=1;t<=tc;t++)
#define set_arr(arr,i) memset(arr,i,sizeof(arr))
#define trace1(x)							cerr << #x << ": " << x << endl;
#define trace2(x, y)						cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)						cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       			cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    			cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) 			cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
using namespace std;

signed main(){
 	ios_base::sync_with_stdio(false);	
 	cin.tie(0);
	cout.tie(0);
	int n,m,x;
	cin>>n>>m;
	priority_queue<int> pq;
	while(n--){
		cin>>x;
		pq.push(x);
	}	
	while(m--){
		int top = pq.top();
		pq.pop();
		pq.push(top/2);
	}
	int sum = 0;
	while(!pq.empty()){
		sum += pq.top();
		pq.pop();
	}
	cout<<sum;
 	return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
int m,n,i,j,x,y,g;
bool f[101];
int main()
{
	cin>>m>>n;
	for(i=1;i<=n;i++)
	{
		cin>>x;
		for(j=1;j<=x;j++)
		{
			cin>>y;
			f[y]=1;
		}
	}
	for(i=1;i<=m;i++)if(f[i]==0)g++;
	cout<<g;
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include<cstdio>
using namespace std;
int main()
{
      ios::sync_with_stdio(false),cin.tie(0), cout.tie(0);
      long long a, b, n;
      cin >> a >> b >> n;
      long long temp=(n/b)*b-1;
      cout << max(((a*n)/b-a*(n/b)), ((a*temp)/b-a*(temp/b))) << endl;
 	return 0;
}


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

int main(){
  int h,w;
  cin >> h >> w;

  char c[w+1][h+1];
  int bomb[w+2][h+2];

  for (int j=0; j<h+2; j++){
    for (int i=0; i<w+2; i++){
      bomb[i][j] = 0;
    }
  }

  for (int j=1; j<=h; j++){
    for (int i=1; i<=w; i++){
      cin >> c[i][j];
      if(c[i][j] == '#'){
        bomb[i-1][j-1]++;
        bomb[i-1][j]++;
        bomb[i-1][j+1]++;
        bomb[i][j-1]++;
        bomb[i][j+1]++;
        bomb[i+1][j-1]++;
        bomb[i+1][j]++;
        bomb[i+1][j+1]++;
      }
    }
  }

  for (int j=1; j<=h; j++){
    for (int i=1; i<=w; i++){
      if(c[i][j] == '#') cout << '#';
      else cout << bomb[i][j];

    }
    cout << endl;
  }

  return 0;
}

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

using namespace std;

int main(){
    int N,M; cin >> N >> M;
    vector<int> cnt(M, 0);
    for(int i=0;i<N;++i){
        int K; cin >> K;
        for(int j=0; j<K; ++j){
            int A; cin >> A; --A;
            ++cnt[A];
        }
    }
    int ans = 0;
    for(int i=0;i<M;i++){
        if(cnt[i] == N){
            ++ans;
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
from itertools import permutations
N = int(input())
P = input().replace(" ", "")
Q = input().replace(" ", "")

nums = []
for x in permutations(map(str, range(1, N + 1)), N):
    nums.append("".join(x))
nums.sort()
ans = abs(nums.index(Q) - nums.index(P))
print(ans)

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);


int main() {
	cin.sync_with_stdio(false);
	int N;
	cin >> N;
	cout << N / 3 << endl;
	return 0;
}


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

Q, H, S, D = [int(x) for x in input().split(" ")]
N = int(input())

if S > Q * 4:
    S = Q * 4
if S > H * 2:
    S = H * 2
if D > S * 2:
    D = S * 2
ans = (N // 2) * D + (N % 2) * S
print(ans)


Measured memory_bytes: 8984
sosuu=[1]*(10**5+1)
sosuu[0]=0
sosuu[1]=0
sosuu[2]=1
for i in range(2,318):
  for j in range(2*i,10**5+1,i):
    if sosuu[j]==1:
      sosuu[j]=0
nita=[]
for i in range(10**5+1):
  nita.append(sosuu[i])
nita[2]=0
for i in range(3,10**5+1,2):
  if sosuu[i]==1 and sosuu[(i+1)//2]!=1:
    nita[i]=0
c=[0]
for _ in range(1,10**5+1):
  c.append(c[-1]+nita[_])
q=int(input())
for _ in range(q):
  l,r=map(int,input().split())
  print(c[r]-c[l-1])


Measured memory_bytes: 13444
n, m = map(int, input().split())
x = list(map(int, input().split()))
d = []
if n >= m:
    print(0)

else:
    x.sort()
    for i in range(m-1):
        d.append(abs(x[i] - x[i + 1]))
    d.sort()
    print(sum(d[:m-n]))


Measured memory_bytes: 20464
#include <cmath>
#include <cstdio>
#include <set>
typedef long long lld;
lld N, Nsqrt, S;
std::set<lld> candid;
bool done;

lld f(lld b, lld n)
{	// TC: O(logN)
	if((b > n) || (b==1))
		return n;
	return f(b, n/b) + (n % b);
}
// Systems with Two Digits
// B*p + q = N
// p + q = S
int main()
{
	scanf(" %lld%lld", &N, &S);
	if(S >  N)
		return puts("-1"), 0;
	if(S == N)
		return printf("%lld\n", N+1) & 0;
	Nsqrt = sqrt(N);
	for(int B = 2; B <= Nsqrt; ++B)
		if(f(B, N) == S) candid.insert(B);
	for(lld P = 1; (P*P < N) && (P <= S); ++P)
	{
		lld Q = S - P;
		if((N >= Q) && !((N-Q) % P))
		{
			lld B = (N - Q) / P;
			if((B > P) && (B > Q))
				candid.insert(B);
		}
	}
	if(!candid.empty())
		printf("%lld\n", *candid.begin());
	else
		puts("-1");
	return 0;
}

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

using namespace std;

using ll = long long;
// const int mod = 1e9 + 7;

#define mem(a, b) memset(a, b, sizeof(a))
#define REP(i, a) for (int i = 0; i < a; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(a) a.begin(), a.end()

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout << fixed << setprecision(10);
}

inline void print_vector(vector<int> &A){
    for (auto&& x : A){
        cout << x << " ";
    }
    cout << endl;
}

inline void print_array(const int A[], int n) {
    REP(i, n) {
        if (i < n - 1) {
            cout << A[i] << " ";
        } else {
            cout << A[i] << endl;
        }
    }
}

inline void solve() {
    int n;
    cin >> n;

    int res = 0;

    for (int i = 1; i < n; ++i) {
        for (int j = 1; j < n; ++j) {
            if (i * j >= n) break;
            res++;
        }
    }

    cout << res << endl;
}

int main() {
    // freopen("input.txt", "r", stdin);
    quickread();
    int t = 1;
    // cin >> t;

    for (int _ = 0; _ < t; _++) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<cstring>
#include<queue>
using namespace std;

queue<int>Q;
int n, M[101][101], s[101];

void bfs()
{
	Q.push(1);
	s[1] = 0;

	int id = 1;

	while (true)
	{
		for (int pid = 1; pid <= n; pid++)
		{
			if (M[id][pid] == 1 && s[pid] == -1)
			{
				Q.push(pid);
				s[pid] = s[id] + 1;
			}
		}

		Q.pop();

		if (!Q.empty())
			id = Q.front();
		else
			break;
	}
}

int main()
{
	int id, pid, k;
	memset(M, 0, sizeof(M));
	memset(s, -1, sizeof(s));

	cin >> n;

	for (int i = 1; i <= n; i++)
	{
		cin >> id >> k;

		for (int j = 1; j <= k; j++)
		{
			cin >> pid;
			M[id][pid] = 1;
		}
	}

	bfs();

	for (int i = 1; i <= n; i++)
		cout << i << " " << s[i] << endl;

	return 0;
}


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

const ll INF = 1LL << 60;

ll ans[301][301];
ll dp[301][301];

int main() {
  int N, M;
  ll L;
  cin >> N >> M >> L;
  vector< vector< pair<int,int> > > to(N);

  REP(i, N) 
    REP(j, N)
      dp[i][j] = (i==j) ? 0 : INF;
  
  REP(i,M)  {
    int ai,bi;
    ll ci;
    cin >> ai >> bi >> ci;
    if ( ci > L ) continue;
    ai--; bi--;
    to[ai].emplace_back(bi, ci);
    to[bi].emplace_back(ai, ci);
    dp[ai][bi] = ci;
    dp[bi][ai] = ci;
  }
  // ワーシャルフロイド
  REP(k, N)
    REP(i, N)
      REP(j, N)
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);

  REP(i, N) 
    REP(j, N)
      dp[i][j] = (dp[i][j]<=L) ? 1 : INF;

  REP(k, N)
    REP(i, N)
      REP(j, N)
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);

  int Q;
  cin >> Q;
  REP(i, Q) {
    int s,e;
    cin >> s >> e;
    s--; e--;
    ll res = dp[s][e];
    if ( res == INF ) res = 0;
    cout << res-1 << endl;
  }

}


Measured memory_bytes: 2432
#include <iostream>
#include <string>
#include <cstring> // memset()
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include<cmath>

using namespace std;

#define ll long long
#define For(i, a, b) for (int i = (int)(a), sz = (int)(b); i < sz; i++)
#define rFor(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fill(a, b) memset(a, b, sizeof(a))
#define IO ios_base::sync_with_stdio(0), cin.tie(0)

const int MAX = 2e2 + 5;

int main() {
    IO;
    int n, cnt[4]{};
    string str, type[4]{"AC", "WA", "TLE", "RE"};
    cin >> n;
    For(i, 0, n) {
        cin >> str;
        For(j, 0, 4) if (str == type[j]) cnt[j]++;
    }
    For(i, 0, 4) printf("%s x %d\n", type[i].c_str(), cnt[i]);
    return 0;
}

Measured memory_bytes: 3728
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define endl "\n"

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define ford(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
 
using namespace std;

signed main()
{
    fast;
    int x,y,z;
    cin>>x>>y>>z;

    cout<<z<<" "<<x<<" "<<y<<endl;
    return 0;
}

Measured memory_bytes: 256
S = input()
n = len(S)

def dfs(i, f):
  if i == n - 1:
    return sum(list(map(int, f.split('+'))))

  return dfs(i+1, f+S[i+1]) + dfs(i+1, f+'+'+S[i+1])

print(dfs(0, S[0]))


Measured memory_bytes: 8864
n=int(input())
l=list(map(int,input().split()))
c=1
if not 0 in l:
    for li in l:
        c*=li
        if c > 10**18:
            
            break
    if c > 10**18:
        print('-1')
    else:
        print(c)
else:
    print(0)

Measured memory_bytes: 21768
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <queue>
#include <functional>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()

int a[300000];
ll sum_max[100001], sum_min[100001];

int main() {
    int N;
    priority_queue<int, vector<int>, greater<int>> first_q;
    priority_queue<int> last_q;
    cin >> N;
    REP(i, N * 3) cin >> a[i];
    REP(i, N) {
        sum_max[0] += a[i];
        sum_min[0] += a[N * 3 - i - 1];
        first_q.push(a[i]);
        last_q.push(a[N * 3 - i - 1]);
    }

    REP(i, N) {
        first_q.push(a[N + i]);
        int p = first_q.top(); first_q.pop();
        sum_max[i + 1] = sum_max[i] - p + a[N + i];
        last_q.push(a[2 * N - i - 1]);
        p = last_q.top(); last_q.pop();
        sum_min[i + 1] = sum_min[i] - p + a[2 * N - i - 1];
    }

    ll ans = sum_max[0] - sum_min[N];
    REP(i, N)
        ans = max(ans, sum_max[i + 1] - sum_min[N - i - 1]);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3956
function main(input: string) {
  const r = reader1(input)
  const s = r.ls().split('')
  const sl = s.length
  let p = ''
  let a = 0
  for (let i = 0; i < sl; i++) {
    const c = s[i]
    if (c === p) {
      if (i + 1 < sl) {
        p = c + s[i + 1]
        a++
        i++
      }
    } else {
      a++
      p = c
    }
    // console.log(p)
  }
  console.log(a)

  // console.log({ a, b, c })
}

// const values = obj => Object.keys(obj).map(e => obj[e]);

const reader1 = (s: string) => {
  const lns = s.trim().split('\n')
  const ls = () => lns.shift() || ''
  const as = () => ls().split(' ')
  const an = () => as().map(Number)
  return { lns, ls, as, an }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 13644
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<char,int> ii;
main(){
    string s;
    cin >> s;
    stack<ii> st1,st2;
    for (int i = s.length()-1; i >= 0; i--) st2.push(ii(s[i],1));
    int num = 0;
    while (st2.size()){
        ii cur = st2.top();
        st2.pop();
        if (st1.size() && st1.top().first == cur.first && cur.first == 'A'){
            st1.top().second += cur.second;
        }
        else st1.push(cur);
        if (st1.size() < 3) continue;
        ii s = st1.top();st1.pop();
        ii f = st1.top();st1.pop();
        if (s.first == 'C' && f.first == 'B'){
            ii a = st1.top();
            if (a.first == 'A'){
                st1.pop();
                num += a.second;
                st2.push(a);
            }
        }
        st1.push(f);
        st1.push(s);

    }
    cout << num;
}


Measured memory_bytes: 3844
N = int(input())
W = []
for i in range(N):
    w = input()
    W.append(w)

bag = set(W)
zipped = [(W[i-1], W[i]) for i in range(1, len(W))]
valid = len(bag) == len(W) and all(p[-1] == q[0] for p, q in zipped)

print('Yes' if valid else 'No')

Measured memory_bytes: 3064
N=int(input())
cher=[0]*26
ans_list=[]

for i,j in enumerate('zabcdefghijklmnopqrstuvwxy'):
    cher[i]=j

while N>26:
    ans_list.append(cher[N%26])
    if N%26==0:N-=1
    N=N//26

ans_list.append(cher[N%26])
print(''.join(ans_list)[::-1])

Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); --i)
#define all(c) c.begin(),c.end()
#define sz(x) ((int)x.size())
using pii = pair<int, int>;
using vvi = vector<vector<int>>;
using vi  = vector<int>;
constexpr int INF = 1001001001001001001LL;

struct RMQ {
    const int ident = (1LL << 31) - 1;
    vi data;
    int size;
    RMQ(int n) {
        size = 1;
        while (size < n) size *= 2;
        data.assign(size * 2, ident);
    }
    void update(int idx, int value) {
        idx += size - 1;
        data[idx] = value;
        while (idx) {
            idx = (idx - 1) / 2;
            data[idx] = min(data[idx * 2 + 1], data[idx * 2 + 2]);
        }
    }
    // [ql, qr)
    int query(int ql, int qr) {
        return query(ql, qr, 0, 0, size);
    }
    int query(int ql, int qr, int node, int nl, int nr) {
        if (qr <= nl || nr <= ql) return ident;
        if (ql <= nl && nr <= qr) return data[node];
        int nm = (nl + nr) / 2;
        return min(query(ql, qr, node * 2 + 1, nl, nm),
                   query(ql, qr, node * 2 + 2, nm, nr));
    }
};


signed main() {
    int N, Q;
    cin >> N >> Q;
    RMQ seg(N);
    rep(i, 0, Q) {
        int com;
        cin >> com;
        if (com == 0) {
            // update
            int X, Y;
            cin >> X >> Y;
            seg.update(X, Y);
        } else {
            // find
            int X, Y;
            cin >> X >> Y;
            cout << seg.query(X, Y + 1) << endl;
        }
    }
}



Measured memory_bytes: 4956
#include <iostream>

int main() {
  int c[3][3];
  for (int i = 0; i < 3; i++) {
    std::cin >> c[i][0] >> c[i][1] >> c[i][2];
  }
  int b1 = c[0][0], b2 = c[0][1], b3 = c[0][2];
  if (c[1][0] - b1 != c[1][1] - b2 || c[1][1] - b2 != c[1][2] - b3 || c[1][2] - b3 != c[1][0] - b1) {
    std::cout << "No" << "\n";
    return 0;
  }
  if (c[2][0] - b1 != c[2][1] - b2 || c[2][1] - b2 != c[2][2] - b3 || c[2][2] - b3 != c[2][0] - b1) {
    std::cout << "No" << "\n";
    return 0;
  }
  std::cout << "Yes" << "\n";
  return 0;
}

Measured memory_bytes: 256
x = int(input())
tmp = 0

if x == 2:
  print(2)
  exit()
for i in range(x,10**111):
  for j in range(2,(i//2)+2):
    tmp += 1
    if i%j == 0:
      break
    elif tmp == (i//2):
      print(i)
      exit()
      


Measured memory_bytes: 3060
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }
    

    Scanner cin;

    

    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        string S = cin.next();
        int ans = 0;
        int x = 0;
        foreach (var c in S)
        {
            if (c == 'I') x++;
            else x--;
            ans = Math.Max(ans, x);
        }
        Console.WriteLine(ans);
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 11092
#include "bits/stdc++.h"
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr_inv(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define rep(i,n) repr(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define MOD 1000000007
#define PI 3.1415926535
using namespace std;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	int a, b, c, x, ans=0;

	cin>>a>>b>>c>>x;

	rep(i, a+1){
		rep(j, b+1){
			rep(k, c+1){
				if(i*500+j*100+k*50==x) ans++;
			}
		}
	}
	cout<<ans<<endl;

}



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

template <typename T>
class node {
public:
	node<T> *l, *r;
	T val, add;
	node(T val_ = 0, node<T>* l_ = nullptr, node<T>* r_ = nullptr)
		: l(l_), r(r_), val(val_), add(0) {}
};

template <typename T>
class RARS {
	const ll n;
	node<T> *root;
	ll size(ll n) {
		ll res = 1;
		while (res < n) res <<= 1;
		return res;
	}
	T sub(ll l, ll r, node<T>* n, ll lb, ll ub) {
		if (!n || ub <= l || r <= lb) return 0;
		if (l <= lb && ub <= r) return n->val + n->add * (ub - lb);
		return sub(l, r, n->l, lb, (lb + ub) / 2) + sub(l, r, n->r, (lb + ub) / 2, ub) + n->add * (min(r, ub) - max(l, lb));
	}
	node<T>* suc(ll l, ll r, node<T>* n, ll lb, ll ub, T val) {
		if (ub <= l || r <= lb) return n;
		if (!n) n = new node<T>;
		if (l <= lb && ub <= r) {
			n->add += val;
			return n;
		}
		n->val += val * (min(r, ub) - max(l, lb));
		n->l = suc(l, r, n->l, lb, (lb + ub) / 2, val);
		n->r = suc(l, r, n->r, (lb + ub) / 2, ub, val);
		return n;
	}
public:
	RARS(ll n_) : n(size(n_)), root(nullptr) {}
	void add(ll l, ll r, T val) {
		root = suc(l, r + 1, root, 0, n, val);
	}
	T getSum(ll l, ll r) {
		return sub(l, r + 1, root, 0, n);
	}
};

template <typename T>
class node2 {
public:
	RARS<T> val, add;
	node2<T> *l, *r;
	node2(ll size) : val(size), add(size), l(nullptr), r(nullptr) {}
};

template <typename T>
class RARS2 {
	const ll h, w;
	node2<T> *root;
	ll size(ll n) {
		ll res = 1;
		while (res < n) res <<= 1ll;
		return res;
	}
	T sub(ll li, ll lj, ll ri, ll rj, node2<T>* n, ll lb, ll ub) {
		if (!n || ub <= li || ri <= lb) return 0;
		if (li <= lb && ub <= ri) return n->val.getSum(lj, rj) + n->add.getSum(lj, rj) * (ub - lb);
		return sub(li, lj, ri, rj, n->l, lb, (lb + ub) / 2) + sub(li, lj, ri, rj, n->r, (lb + ub) / 2, ub) + n->add.getSum(lj, rj) * (min(ri, ub) - max(li, lb));
	}
	node2<T>* suc(ll li, ll lj, ll ri, ll rj, node2<T>* n, ll lb, ll ub, T val) {
		if (ub <= li || ri <= lb) return n;
		if (!n) n = new node2<T>(w);
		if (li <= lb && ub <= ri) {
			n->add.add(lj, rj, val);
			return n;
		}
		n->val.add(lj, rj, val * (min(ri, ub) - max(li, lb)));
		n->l = suc(li, lj, ri, rj, n->l, lb, (lb + ub) / 2, val);
		n->r = suc(li, lj, ri, rj, n->r, (lb + ub) / 2, ub, val);
		return n;
	}
public:
	RARS2(ll h_, ll w_) : h(size(h_)), w(w_), root(nullptr) {}
	void add(ll li, ll lj, ll ri, ll rj, T val) {
		root = suc(li, lj, ri + 1, rj, root, 0, h, val);
	}
	T getSum(ll li, ll lj, ll ri, ll rj) {
		return sub(li, lj, ri + 1, rj, root, 0, h);
	}
};

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n, q;
	cin >> n >> q;
	RARS2<ll> lst(n, 1);
	for (int i = 0, type, s, t, x; i < q; i++) {
		cin >> type >> s >> t; s--; t--;
		if (type) {
			printf("%lld\n", lst.getSum(s, 0, t, 0));
		}
		else {
			cin >> x;
			lst.add(s, 0, t, 0, x);
		}
	}
	return 0;
}

Measured memory_bytes: 20796