akhauriyash/Code-Regression huggingface dataset:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n,k=map(int, input().split())
    l=list(map(int,input().split()))
    from collections import Counter
    c=Counter(l)# ()にカウンターの対象のリストの変数名
    cntl=c.most_common()
    kosu=len(cntl)
    ans=0
    if kosu<=k:
        print(0)
    else:
        for i in range(k,kosu):
            ans+=cntl[i][1]
        print(ans)
resolve()

Measured memory_bytes: 96844
a = input()
b = input()

a_cache = dict()
b_cache = dict()

a_unique = 0
b_unique = 0
for n in range(len(a)):
    
    a_char = a[n]
    b_char = b[n]

    if a_char in a_cache:
        a_n_unique = a_cache[a_char]
    else:
        a_n_unique = a_unique
        a_cache[a_char] = a_unique
        a_unique += 1

    if b_char in b_cache:
        b_n_unique = b_cache[b_char]
    else:
        b_n_unique = b_unique
        b_cache[b_char] = b_unique
        b_unique += 1
    
    if a_n_unique != b_n_unique:
        print("No")
        exit(0)

print("Yes")

Measured memory_bytes: 3632
/*??????(Homework)*/
#include <stdio.h>
int main(){
  int x, y, z, A, B, C, D, L;
  scanf("%d %d %d %d %d", &L, &A, &B, &C, &D);
  if (A % C == 0) {
    x = A / C;
  } else {
    x = A / C + 1;
  }
  if (B % D == 0) {
    y = B / D;
  } else {
    y = B / D + 1;
  }
  if (x >= y){
    z = L - x;
  } else {
    z = L - y;
  }
  printf("%d\n", z);
  return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n,m) for (int i=n; i<m; i++)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
#define Size(n) (n).size()

array<int,3> ans;

void dfs(int i,array<int,4> n, array<int,3> a);
void ret_ans(array<int,4> n,array<int,3> ans);

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

	string s;
	cin >> s;
    array<int,4> n;
    array<int,3> a;

    REP(i,4){
       n[i]=(int)(s[i]-'0');
    }
    dfs(0,n,a);
    ret_ans(n,ans);
    return 0;
}

void dfs(int i,array<int,4> n, array<int,3> a){
    //REP(i,3){
    //    cout<<ans[i]<<endl;
    //}
    if (i==3){
        int calc=n[0];
        REP(j,3){
            calc += n[j+1]*a[j];
        }
        if (calc==7){
            //REP(k,3){
            //    cout<<a[k];
            //}
            ans = a;
        }
    }
    else{
        a[i]=1;
        dfs(i+1,n,a);
        a[i]=-1;
        dfs(i+1,n,a);

    }
}

 
void ret_ans(array<int,4> n,array<int,3> ans){
    cout << n[0];
    REP(i,3){
        cout << (ans[i]==1 ? "+" : "-") << n[i+1];
    }
    cout << "=7" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>

class dice {
public:
	int d1, d2, d3, d4, d5, d6, tmp;

	void set(int a1,int a2, int a3, int a4, int a5, int a6) {
		d1 = a1;
		d2 = a2;
		d3 = a3;
		d4 = a4;
		d5 = a5;
		d6 = a6;
	}
	void n(void) {
		tmp = d1;
		d1 = d2;
		d2 = d6;
		d6 = d5;
		d5 = tmp;
	}
	void s(void) {
		tmp = d1;
		d1 = d5;
		d5 = d6;
		d6 = d2;
		d2 = tmp;
	}
	void e(void) {
		tmp = d1;
		d1 = d4;
		d4 = d6;
		d6 = d3;
		d3 = tmp;
	}
	void w(void) {
		tmp = d1;
		d1 = d3;
		d3 = d6;
		d6 = d4;
		d4 = tmp;
	}
};


int main() {

	dice d;
	std::string c;
	int a[7], i,j,f,u,n;

		for (i = 1; i < 7; i++) {
			std::cin >> a[i];
		}
		d.set(a[1], a[2], a[3], a[4], a[5], a[6]);

		std::cin >> n;

		for (i = 0; i < n; i++) {
			std::cin >> u >> f;

			c = "NNNNENNNN";

			for (j = 0; j < c.size(); j++) {
				if (d.d2 == f)break;

				if (c[j] == 'N') d.n();
				else if (c[j] == 'S')d.s();
				else if (c[j] == 'E')d.e();
				else if (c[j] == 'W')d.w();
				else std::cout << "Error" << std::endl;
			}

			if (d.d2 != f)std::cout << "couldn't find front" << std::endl;

			c = "EEEE";

			for (j = 0; j < c.size(); j++) {
				if (d.d1 == u)break;

				if (c[j] == 'N') d.n();
				else if (c[j] == 'S')d.s();
				else if (c[j] == 'E')d.e();
				else if (c[j] == 'W')d.w();
				else std::cout << "Error" << std::endl;
			}


			std::cout << d.d3 << std::endl;
		}

	return 0;
}


Measured memory_bytes: 3172
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

const mod = 998244353
const facNum = 300001

func main() {
	sc := newScanner(os.Stdin)
	X := sc.i()
	X = X - 400
	X = X / 200
	fmt.Println(8 - X)
}

// fmt.Println("Yes")
// fmt.Println("No")

// I/O
type scanner struct {
	sc *bufio.Scanner
}

func newScanner(input io.Reader) *scanner {
	sc := bufio.NewScanner(input)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &scanner{sc}
}

func (s *scanner) s() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *scanner) i() int {
	i, e := strconv.Atoi(s.s())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *scanner) f() float64 {
	f, e := strconv.ParseFloat(s.s(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *scanner) bs() []byte {
	return []byte(s.s())
}

func (s *scanner) is(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.i()
	}
	return res
}

func (s *scanner) fs(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.f()
	}
	return res
}

//------------------------------

//const factorial = new
func Pow(a, n int) int {
	ans := 1
	for n > 0 {
		if (n & 1) == 1 {
			ans = ans * a % mod
		}
		a = a * a % mod
		n = n >> 1
	}
	return ans
}

// a^{-1} (mod) を計算
func Inv(a int) int {
	return Pow(a, mod-2)
}

func Gcd(a, b int) int {
	if a < b {
		return Gcd(b, a)
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func combination(n, k int, fac, ifac []int) int {
	if n < k || n < 0 {
		return 0
	}
	if k == 0 {
		return 1
	}
	//while n != 0
	ans := ifac[k] * ifac[n-k] % mod
	return ans * fac[n] % mod
}

func abs(i int) int {
	if i < 0 {
		return -i
	}
	return i
}

// 階乗: factorial
// コンビネーションを計算する際に前もって計算しておく
// fac[k] => k! (mod M)
// ifac[k] => k!^(M-2) (mod M)
// n: ex. 2 * 10^5 => 200001
// fac, ifac := factorial()
func factorial() (fac []int, ifac []int) {
	fac = make([]int, facNum)
	fac[0] = 1
	ifac = make([]int, facNum)
	ifac[0] = 1
	for i := 1; i < facNum; i++ {
		fac[i] = fac[i-1] * i % mod
		ifac[i] = ifac[i-1] * Pow(i, mod-2) % mod
	}
	return
}

// vs: sorted slice int value
func lowerBound(vs []int, v int) (index int) {
	n := len(vs) / 2
	m := len(vs)
	for m != n {
		if vs[n] < v {
			n = (m-n+1)/2 + n
			//m = m
		} else {
			m = n
			n = n / 2
		}
	}
	return n
}

func IntSlice(n, init int) []int {
	r := make([]int, n)
	for i := range r {
		r[i] = init
	}
	return r
}


Measured memory_bytes: 1772
import math

def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

# n = int(input())
# a, b = list(map(int, input().split()))
# s = input()

a, b, c = list(map(int, input().split()))
if a +b+c <= 21:
    print("win")
else:
    print("bust")


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

int main(){
    int a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    // 2*a + c >= 2*x
    // 2*b + c >= 2*y
    int max_c = max(x, y)*2;
    int ret = 1000000000;
    for(int i = 0; i <= max_c; i+=2)
    {
        int temp = c * i;
        if (x-i/2 > 0)
            temp += (x-i/2) * a;
        if (y-i/2 > 0) {
            temp += (y-i/2) * b;
        }
        if (temp < ret)
            ret = temp;
    }
    
    cout << ret << endl;
    return 0;
}

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

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(v) reverse((v).begin(),(v).end())
#define ANS(ans) cout<<(ans)<<endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  for (int i = 0; i < (n); ++i)


int main() {

	string s;
	cin >> s;
	int n = s.size();
	int num,temp;
	int m = 1000;
	FOR(i, 0, n - 3) {
		num = (s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + (s[i + 2] - '0');
		temp = abs(num - 753);
		m = min(temp, m);
	}
	ANS(m);

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int N;
int A[1010][1010];

vector<pair<int,int>> g[1000010];
int in[1010][1010];

int main(){
  cin>>N;
  for(int i=1;i<=N;i++){
    for(int j=1;j<=N-1;j++){
      cin>>A[i][j];
    }
  }

  int cnt=1;
  map<pair<int,int>,int> mp;
  for(int i=1;i<=N;i++){
    for(int j=i+1;j<=N;j++){
      mp[mkp(i,j)]=cnt;
      cnt++;
    }
  }

  for(int i=1;i<=N;i++){
    for(int j=1;j+1<=N-1;j++){
      int a=i,b=A[i][j],c=i,d=A[i][j+1];
      if(a>b) swap(a,b);
      if(c>d) swap(c,d);
      g[mp[mkp(a,b)]].push_back(mkp(c,d));
      in[c][d]++;
    }
  }

  queue<pair<int,int>> Q;
  for(int i=1;i<=N;i++){
    for(int j=i+1;j<=N;j++){
      if(in[i][j]==0) Q.push(mkp(i,j));
    }
  }

  
  ll ans=1;
  map<int,int> p;
  while(!Q.empty()){
    int a,b;
    tie(a,b)=Q.front();
    Q.pop();

    if(p[a]||p[b]){
      ans++;
      p.clear();
    }
    p[a]=1;
    p[b]=1;
    int now=mp[mkp(a,b)];
    for(int i=0;i<g[now].size();i++){
      int c,d;
      tie(c,d)=g[now][i];
      in[c][d]--;
      if(in[c][d]==0){
        Q.push(mkp(c,d));
      }
    }
  }

  for(int i=1;i<=N;i++){
    for(int j=i+1;j<=N;j++){
      if(in[i][j]>0){
        cout<<-1<<endl;
        return 0;
      }
    }
  }

  cout<<ans<<endl;



  return 0;
}


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

int main(){
   int a,b;
   cin >> a >> b;
   if(a%3 == 0 || b%3 == 0 || (a+b)%3 == 0){
      cout << "Possible";
   }else{
      cout << "Impossible";
   }
   return 0;
}

Measured memory_bytes: 256
#include <utility>
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>


using namespace std;

int N;
int D[100+10] = {};
int U = 0;
int K[100+10] = {0};
int V = -1;
int G[100+10][100+10] = {0};
int curtime_st[100+10] = {0};
int curtime_en[100+10] = {0};



//stack dst   queue bfs


int time_ = 1;
int prev1 = 0;
int prev_b = 0;
void dfs(int cur){
  if (cur == -1)return;//??¢??±
  if (curtime_st[cur] == 0)curtime_st[cur] = time_;

  D[cur] = 0;
  time_ += 1;
  //
  //cerr << "visiting " << cur << " " << time_ - 1  << endl;
  
  for(int dst=1;dst<=N;++dst){
    if(D[dst] == -1 && G[cur][dst] == 1){
      dfs(dst);
	}
  }
  if(curtime_en[cur] == 0 || curtime_en[cur] == curtime_st[cur])curtime_en[cur] = time_;
  time_ += 1;
  return;
}







int main(){
  cin >> N;

  for(int i=0;i<101;++i){
    D[i] = -1;//?????????
  }

  for(int i=0;i<N;++i){
    cin >> U;
    cin >> K[U];
    for(int j=0;j<K[U];++j){
      cin >> V;
      G[U][V] = 1;
    }
  }

  for(int j=1;j<=N;++j){
    for(int i=1;i<=N;++i){
      //cout << G[i][j] << " ";
    }
    //cout << endl;
  }

  dfs(1);
  for(int i=2;i<=N;++i){
    if(D[i] == -1)dfs(i);
  }

  for(int i=1;i<=N;++i){
    cout << i << " " << curtime_st[i] << " " << curtime_en[i] << endl; 
  }
}

Measured memory_bytes: 3160
use std::io::prelude::BufRead;
use std::io::StdinLock;

pub fn read_line(locked_stdin: &mut StdinLock) -> std::io::Result<String> {
    let mut buf = String::new();
    locked_stdin.read_line(&mut buf).map(|_| buf)
}

pub fn read_to_vec<T: std::str::FromStr>(locked_stdin: &mut StdinLock) -> Vec<T> {
    read_line(locked_stdin).unwrap()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let n;
    let a;

    {
        let stdin = std::io::stdin();
        let mut lkin = stdin.lock();
        let mut input = read_to_vec::<usize>(&mut lkin).into_iter();
        n = input.next().unwrap();
        a = read_to_vec::<usize>(&mut lkin);
    }

    let mut left_min = Vec::new();
    let mut right_max = Vec::new();
    left_min.push(0);
    right_max.push(n-1);

    for i in 1..n {
        let mem = left_min[i-1];
        left_min.push(if a[mem] >= a[i] {i} else {mem});
        let mem = right_max[i-1];
        right_max.push(if a[mem] <= a[n-1-i] {n-1-i} else {mem});
    }
    right_max.reverse();

    let data: Vec<_> = (0..n).map(|i|
        ( i, (left_min[i], right_max[i]), a[right_max[i]] - a[left_min[i]] )).collect();
    let &(_, _, max) = data.iter().max_by_key(|d| d.2).unwrap();
    let data: Vec<_> = data.iter().filter_map(|d|
        if max == d.2 {Some((d.0, d.1))} else {None}).collect();

    let mut ans = 0;
    let mut last_max = n;
    let mut last_min = n;
    for d in data.iter() {
        if last_min == (d.1).0 || last_max == (d.1).1 { continue; }
        last_min = (d.1).0;
        last_max = (d.1).1;
        ans += std::cmp::min(
            a[last_min..(last_max+1)].into_iter().filter(|&&apple| apple == a[last_min]).count(),
            a[last_min..(last_max+1)].into_iter().filter(|&&apple| apple == a[last_max]).count()
        )
    }

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


Measured memory_bytes: 16676
N,A,B=map(int,input().split())
a=0
i=1
while i<=N:
    b=list(str(i))
    for j in range(len(b)):
        b[j]=int(b[j])
    if A<=sum(b) and sum(b)<=B:
        a+=i
    i+=1
print(a)

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

long long N,Q,arr[100001],A,B,C,total=0;

int main(){
	cin>>N;
	for(int i=0; i<N; i++){
		cin>>A;
		arr[A]++;
		total+=A;
	}
	cin>>Q;
	for(int i=0; i<Q; i++){
		cin>>B>>C;
		long long diff=C-B;
		long long curr=arr[B];
		total+=curr*diff;
		arr[C]+=arr[B];
		arr[B]=0;
		cout<<total<<'\n';
	}
}

Measured memory_bytes: 4376
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A; cin>>A;
  vector<int> S={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout<<S.at(A-1)<<endl;
}


Measured memory_bytes: 3636
class Dice():
    def __init__(self):
        self.face = [i for i in range(6)]
        self.memo = [i for i in range(6)]

    def setface(self,initface):
        for i in range(6):
            self.face[i] = initface[i]

    def roll(self,direction):
        for i in range(6):
            self.memo[i] = self.face[i]
        index = {'E':(3,1,0,5,4,2),'N':(1,5,2,3,0,4),'S':(4,0,2,3,5,1),'W':(2,1,5,0,4,3)}
        for i in range(6):
            self.face[i] = self.memo[index[direction][i]]

    def top(self):
        return self.face[0]

dice = Dice()
initface = list(map(int,input().split()))
dice.setface(initface)
route = input()
for direction in route:
    dice.roll(direction)
print(dice.top())


Measured memory_bytes: 5604
/*
* じょえチャンネル
* 高評価・チャンネル登録よろしくおねがいします！
* https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
*/

#include <bits/stdc++.h>


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


#define inf (int)(3e18)
#define int long long
#define mod (int)(1000000007)

#define intt long long
#define P pair<int,int>

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

using namespace std;

//Library
//モッドパウ
int modpow(int x, int y, int m = mod) {
    int res = 1;
    while (y) {
        if (y % 2) {
            res *= x;
            res %= m;
        }
        x = x * x % mod;
        y /= 2;
    }
    return res;
}

int mypow(int x, int y) {
    int res = 1;
    while (y) {
        if (y % 2) {
            res *= x;
        }
        x = x * x;
        y /= 2;
    }
    return res;
}
//is the number (x) a prime number?
bool prime(int x) {
    for (int i = 2; i * i <= x; i++) {
        if (!(x % i)) {
            return false;
        }
    }
    return true;
}


//saidai-kouyakusuu
inline int gcd(int x, int y) {
    if (!y) {
        return x;
    }
    return gcd(y, x % y);
}


//number of keta
int keta(int x) {
    int ans = 0;
    while (x) {
        x /= 10;
        ans++;
    }
    return ans;
}

//sum of keta
int ketasum(int x) {
    int ans = 0;
    while (x) {
        ans += x % 10;
        x /= 10;
    }
    return ans;
}

inline int lcm(int x, int y) {
    int ans = x / gcd(x, y) * y;
    return ans;
}
int twobeki(int x) {
    int ans = 0;
    while (1) {
        if (!(x & 1)) {
            ans++;
            x /= 2;
        }
        else {
            break;
        }
    }
    return ans;
}


template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
    if (lhs < rhs) {
        lhs = rhs;
        return 1;
    }
    return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
    if (lhs > rhs) {
        lhs = rhs;
        return 1;
    }
    return 0;
}
void Yes(){
    cout<<"Yes"<<endl;
}
void No(){
    cout<<"No"<<endl;
}
void YES(){
    cout<<"YES"<<endl;
}
void NO(){
    cout<<"NO"<<endl;
}


#define fin(i) scanf("%lld",&i)
#define fout(i) printf("%lld\n",i)
#define fendl printf("\n")
//Library-End


string s;

int n,f[104][10],cnt[14],p[104][15],ans;
signed main() {
    cin>>n;
    rep(i,n){
        rep(j,10){
            cin>>f[i][j];
        }
    }
    rep(i,n){
        rep(j,11){
            cin>>p[i][j];
        }
    }
    rep(i,n){
        rep(j,10){
            if (f[i][j]) {
                cnt[j]+=f[i][j];
            }
        }
    }
    ans=0-inf;
    REP(i,mypow(2, 10)-1){
        bitset<20> bits(i);
        int cn[104]={0};
        int kans=0;
        rep(j,n){
            rep(k,10){
                if (bits[k]&&f[j][k]) {
                    cn[j]++;
                }
            }
            kans+=p[j][cn[j]];
        }
        
        chmax(ans, kans);
        if(ans==0){
            
            ;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
class Simple {
    int N, K;
    int[] X;
    void Solve() {
        //input
        N = io.Int;
        K = io.Int;
        X = new int[N];
        for (int i = 0; i < N; ++i)
            X[i] = io.Int;
        //cal
        var ans = 0;
        for(int i = 0; i < N; ++i) 
            ans += Math.Min(X[i], K - X[i]) * 2;
        //ret
        Console.WriteLine(ans);
    }    
    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) { new Simple().Stream(); }
    void Stream() {
        Solve();
        io.writeFlush();
    }
}
class SimpleIO {
    string[] nextBuffer;
    int BufferCnt;
    char[] cs = new char[] { ' ' };
    StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    public SimpleIO() {
        nextBuffer = new string[0];
        BufferCnt = 0;
        Console.SetOut(sw);
    }
    public string Next() {
        if (BufferCnt < nextBuffer.Length)
            return nextBuffer[BufferCnt++];

        string st = Console.ReadLine();
        while (st == "")
            st = Console.ReadLine();
        nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        BufferCnt = 0;
        return nextBuffer[BufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void writeFlush() { Console.Out.Flush(); }
}


Measured memory_bytes: 11092
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int diviser(int n) {
    int res = 0;
    for (int i=1; i*i<=n; i++) {
        if (n%i == 0) {
            res++;
            if (n/i != i) res++;
        }
    }
    return res;
}

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

    int ans = 0;
    for (int i=1; i<=n; i+=2) {
        if (diviser(i) == 8) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

struct Solver {
	void solve() {
		string T;
		cin >> T;
		replace( T.begin(), T.end(), '?', 'D' );
		cout << T << endl;
	}
};

int main() {
	ios::sync_with_stdio( false );
	cout << fixed << setprecision( 10 );
	Solver().solve();
	return 0;
}


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

int main(){
  int X,N;
  cin>>X>>N;
  int p[N];
  rep(i, N) cin>>p[i];

  vector<bool> a(100, false);
  rep(i, N){
    a[p[i]-1] = true;
  }

  int min = 101;
  for(int i=X-1; i<100; i++){
    if(!a[i]){
      min = i+1;
      break;
    }
  }

  for(int i=X-1; i>=0; i--){
    if(!a[i]){
      if(abs(X-(i+1)) <= abs(X-min)){
        min = i+1;
        break;
      }
    }
  }

  if(min == 101){
    if(X < 51) min = 0;
  }

  if(X==1 && min == 2){
    min = 0;
  }

  cout << min << endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
vector<long> fact_inv, inv, Com;
void init_nCk(int n,int k){
  fact_inv.resize(k+5);
  inv.resize(k+5);
  fact_inv[0]=fact_inv[1]=1;
  inv[1]=1;
  for(int i=2;i< k+5;i++){
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    fact_inv[i]=fact_inv[i-1]*inv[i]%MOD;
  }
  Com.resize(k+5);
  Com[0]=1;
  for(int i=1;i<k+5;i++){
    Com[i]=Com[i-1]*((n-i+1)*inv[i]%MOD)%MOD;
  }
}
int K,i,a;
long x=1,ans=0;
int nCk(int k){
    assert(!(k<0));
    return Com[k];
}
int main(){
  string S;
  cin>>K>>S;
  a=K+S.size();
  init_nCk(a,K);
  for(i=0;i<=K;i++){
    ans+=x*nCk(i);
    ans%=MOD;
    x=x*25%MOD;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 27672
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=100010;
const ll mod=1e9+7;



int main(){
  int n;
  cin >> n;
  map<int,int> mp1,mp2;
  rep(i,n){
    int a;
    cin >> a;
    if(i%2){
      mp1[a]++;
    } else {
      mp2[a]++;
    }
  }
  vector<P> a,b;
  for(auto it:mp1){
    a.emplace_back(it.S,it.F);
  }
  for(auto it:mp2){
    b.emplace_back(it.S,it.F);
  }
  sort(a.rbegin(),a.rend());
  sort(b.rbegin(),b.rend());
  if(a[0].S!=b[0].S){
    cout << n-a[0].F-b[0].F << endl;
  } else {
    cout << n-max(a[0].F+b[1].F,a[1].F+b[0].F) << endl;
  }
  return 0;
}

Measured memory_bytes: 6136
N = int(input())
song = []
for i in range(N):
    s, t = map(str, input().split())
    song.append([s, int(t)])
X = input()
start = False
sleep = 0
for i in song:
    if start:
        sleep = sleep + i[1]
    if i[0] == X:
        start = True
print(sleep)

Measured memory_bytes: 3064
'use strict'

const main = (INPUT) => {
  const S = INPUT.split('\n')[0]
  const ary = S.split('')
  if (ary.length == [...new Set(ary)].length) {
    console.log('yes')
  } else {
    console.log('no')
  }
}

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


Measured memory_bytes: 29516
//SkGeN
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstring>
#include<climits>
#include<deque>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> p64;
typedef vector<ll> v64;
const int N = 2 * 1e5 + 10;
const ll inf = 1e18 + 100;
const ll mod = 1e9 + 7;
 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,s,e) for(long long i=s;i<=e;i++)
#define brep(i,s,e) for(long long i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define DANGER std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
 
void solve() {
	string s , t;
	cin>>s>>t;
	map<ll,vector<ll>> mp;
	ll len = s.size();
	for(int i = 0  ; i < s.size() ; i++) {
		mp[s[i]].pb(i);
	}

	ll val = 0 , ch = 0;
	if(mp.count(t[0]) == 0) {
		cout<<-1;
		return;
	} else {
		ch = mp[t[0]][0];
	}
	for(int i = 1; i < t.size() ; i++) {
		if(mp.count(t[i]) == 0) {
			cout<<"-1\n";
			return;
		} else {
			ll xx = upper_bound(mp[t[i]].begin() , mp[t[i]].end() , ch) - mp[t[i]].begin();
			//cout<<xx<<"\n";
			if(xx < mp[t[i]].size()) {
				ch = mp[t[i]][xx];
			} else {
				val += len;
				ch = mp[t[i]][0];
			}
		}
	}

	cout<<val + ch + 1<<"\n";
}
int main()
{
	DANGER;
	ll t = 1;
	//cin>>t;
	while(t--) {
		solve();
	}
return 0;
}
//---->O ,,

Measured memory_bytes: 1736
while True:
    try:
        n,m = map(int, input().split())
        b = []
        for j in range(n):
            a = list(map(int,input().split()))
            b.append(a)    
            S = sum(a)
            c = list(zip(*b))
            D = [sum(x)for x in c]
            X = sum(D)
            print(*a,S)
        print(*D,X)
    except:
        break


Measured memory_bytes: 6120
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

int main() {
    int n;
    cin >> n;
    for (int i=0, ai; i<n; i++) {
        cin >> ai;
        if (ai%2 == 0 && ai%3 && ai%5) {
            cout << "DENIED" << '\n';
            return 0;
        }
    }
    cout << "APPROVED" << '\n';
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i, a, n) for(int i=a; i<n; i++)
#define ll long long
#define all(x) begin(x), end(x)
#define toInt(x) (x - '0')
#define pll pair<ll, ll>
#define pli pair<ll, int>
// #define int long long
const int inf = 1 << 30;
#define INF 1e+9
#define MAX_V 100008


signed main(){
  int n;
  cin >> n;
  if(n >= 30){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 3628
#include <iostream>

using namespace std;

void solve()
{
	int q1, b, c1, c2, q2;
	while(cin >> q1, q1)
	{
		cin >> b >> c1 >> c2 >> q2;
		if((b - c1) / c2 < q1 - 1)
		{
			cout << "NA" << endl;
			continue;
		}
		int aizuChicken = min(b / c1, q2);
		while(aizuChicken + (b - (aizuChicken * c1)) / c2 < q1)
		{
			--aizuChicken;
		}
		cout << aizuChicken << " " << (b - (aizuChicken * c1)) / c2 << endl;
	}
}

int main()
{
	solve();
	return(0);
}

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

#define I inline
#define fi first
#define se second
#define R register
#define LL long long
#define mp make_pair
#define reg register int
#define pii pair<int,int>
#define fo(i, a, b) for(reg i = a; i <= b; i++)
#define fd(i, a, b) for(reg i = a; i >= b; i--)
#define cr const reg&
using namespace std;
const int inf = 2147483647;

I int _max(cr x, cr y) {return x > y ? x : y;}
I int _min(cr x, cr y) {return x < y ? x : y;}
I int read() {
	reg x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
	return x * f;
}
I void ptt(cr x) {if(x >= 10) ptt(x / 10); putchar(x % 10 + '0');}
I void put(cr x) {x < 0 ? putchar('-'), ptt(-x) : ptt(x);}
I void pr1(cr x) {put(x), putchar(' ');}
I void pr2(cr x) {put(x), puts("");}

int main() {
	char ch = getchar();
	putchar(ch + 1);
	return 0;
}



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

int main(){
	ll n, k;
	cin >> n >> k;
	ll r, s, p;
	cin >> r >> s >> p;
	vector<char> t(n);
	rep(i, n) cin >> t[i];
	
	ll score = 0;
	vector<bool> through(n, false);
	rep(i, k) {
		if (t[i] == 'r') score += p;
		if (t[i] == 's') score += r;
		if (t[i] == 'p') score += s;
		through[i] = true;
	}
	for (int i = k; i < n; i++) {
		if (t[i] == t[i-k] && through[i-k]) continue;
		
		if (t[i] == 'r') score += p;
		if (t[i] == 's') score += r;
		if (t[i] == 'p') score += s;
		through[i] = true;
	}
	
	cout << score << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(pos,mp) for(ll pos=mp.begin();pos!=mp.end();pos -++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

//MODでべき乗が計算できる
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

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

    ll ans = modpow(10, n, MOD);

    ll exp1and9 = modpow(8, n, MOD);
    ll exp1or9 = modpow(9, n, MOD) - exp1and9; 

    ans -= exp1and9 + 2 * exp1or9;
    ans += 10*MOD;
    ans %= MOD;

    cout << ans << endl;
}

Measured memory_bytes: 3636
N = int(input())
As = list(map(int,input().split(' ')))

dic = {}

for A in As:
	if A not in dic.keys():
		dic[A] = 1
	else:
		dic[A] = dic[A] + 1

cnt = 0

for v in dic.values():
	cnt = cnt + v*(v-1)//2

for A in As:
	print(cnt - (dic[A]-1) )


Measured memory_bytes: 24748
#include <stdio.h>

int main()
{
    short n, x;

    fscanf(stdin, "%hd %hd", &n, &x);

    short i, j, k, cnt = 0;

    while (n != 0 || x != 0) {
        for (i = 1; i <= n - 2 && i < x; i++) {
            for (j = i + 1; j <= n - 1 && i + j <= x; j++) {
                for (k = j + 1; k <= n && i + j + k <= x; k++) {
                    if (i + j + k == x) {
                        cnt++;
                    }
                }
            }
        }
        fprintf(stdout, "%hd\n", cnt);
        fscanf(stdin, "%hd %hd", &n, &x);
        cnt = 0;
        }

    return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <set>
using namespace std;
typedef long long ll;
int main(void){
    int a, b, q;
    ll x, y;
    set<ll> s, t;
    s.insert(-1e12);
    s.insert(1e12);
    t.insert(-1e12);
    t.insert(1e12);
    
    cin>>a>>b>>q;
    for(int i=0;i<a;i++){
        cin>>x;
        s.insert(x);
    }
    for(int i=0;i<b;i++){
        cin>>x;
        t.insert(x);
    }
    for(int i=0;i<q;i++){
        cin>>x;
        auto v=s.lower_bound(x), w=t.lower_bound(x);
        y=max((*v), (*w))-x;
        v--;
        y=min(y, (*w)-(*v)+min((*w)-x, x-(*v)));
        v++;
        w--;
        y=min(y, (*v)-(*w)+min((*v)-x, x-(*w)));
        v--;
        y=min(y, x-min((*v), (*w)));
        cout<<y<<endl;
    }
    
}


Measured memory_bytes: 10752
#include <cstdio>
using namespace std;

int min(int a,int b){return a<b?a:b;}
int max(int a,int b){return a>b?a:b;}
int x,y,s;
int main(){
    while(scanf("%d%d%d",&x,&y,&s),x*y*s){
        int ans=0;
        double rate1=(100+x)/100.0+0.000001,rate2=(100+y)/100.0+0.0000001;
        for(int i=1;i<s;i++){
            if(i*rate1>=s)break;
            int j=(s-i*rate1)/rate1;
            while(((int)(i*rate1))+((int)(j*rate1))<s)j++;
            if(((int)(i*rate1))+((int)(j*rate1))!=s)continue;
            ans=max(ans,((int)(i*rate2)+(int)(j*rate2)));
            //printf("%d %d %d\n",(int)(i*rate2),(int)(j*rate2),ans);
        }
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
#define N 100009
using namespace std;
char s[3][11];

int main()
{
    while(scanf("%s%s%s",s[0],s[1],s[2])!=-1)
    {
        for(int i=0;i<3;i++)
        {
            printf("%c", toupper(s[i][0]));
        }
        puts("");
    }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (1E9+7)
#define PI 3.1415926535897932384

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

int check(int a) {
	if (a == 2)return 0;
	else if (a == 4 || a == 6 || a == 9 || a == 11)return 1;
	return 2;
}

int main() {
	int a, b;
	cin >> a >> b;
	a = check(a);
	b = check(b);
	cout << (a == b ? "Yes" : "No") << endl;
}


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

using namespace std;
int main()
{
  int a[8], b, c;
  a[7] = 1;
  a[5] = 2;
  for(int i = 0, x; i < 3; i++)
    cin >> x, a[x]--;
  if(a[7] >= 0 && a[5] >= 0) cout << "YES";
  else cout << "NO";
}


Measured memory_bytes: 256
def make_divisors(n):
  divisors = []
  for i in range(int(n ** 0.5), 0, -1):
    if n % i == 0:
      divisors.append(i)
#      if i != n // i:
#        divisors.append(n // i)
      divisors.append(n // i)
      break
  return divisors

N = int(input())
l = make_divisors(N)
a = l[0]
b = l[1]
print(a + b - 2)

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

struct edge {long cost; int from, to; };
bool comp(edge &e1, edge &e2) {
  return e1.cost < e2.cost;
}

int main() {
  int n;
  cin>>n;
  long a[n][n];
  for (int i=0; i<n; i++) {
    for (int j=0; j<n; j++) cin>>a[i][j];
  }
  long d[n][n];
  for (int i=0; i<n; i++) {
    for (int j=0; j<n; j++) d[i][j] = a[i][j];
  }
  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][k] + d[k][j], d[i][j]);
      }
    }
  }
  for (int i=0; i<n; i++) {
    for (int j=0; j<n; j++) {
      if (a[i][j] != d[i][j]) {
        cout<<-1<<endl;
        return 0;
      }
    }
  }
  bool e[n][n];
  for (int i=0; i<n; i++) {
    for (int j=0; j<n; j++) {
      e[i][j] = true;
    }
    e[i][i] = false;
  }

  for (int k=0; k<n; k++) {
    for (int i=0; i<n; i++) {
      for (int j=0; j<n; j++) {
        if (!e[i][j]) {
          continue;
        }
        if (i ==k || j == k) {
          continue;
        }
        if (d[i][j] == d[i][k] + d[k][j]) {
          e[i][j] = false;
          e[j][i] = false;
        }
      }
    }
  }
  long long ans = 0;
  for (int i=0; i<n; i++) {
    for (int j=i+1; j<n; j++) {
      if (e[i][j]) {
        ans += d[i][j];
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#pragma warning(disable : 4996)
char s[1000009], t[10009];
int main() {
	int sl = 0, tl = 0;
	while ((s[sl++] = getchar()) != '\n'); sl--;
	while ((t[tl++] = getchar()) != '\n'); tl--;
	unsigned long long hs = 0, ht = 0, pw = 1;
	for (int i = 0; i < tl; i++) {
		hs = (hs << 8) + hs + s[i];
		ht = (ht << 8) + ht + t[i];
		pw = (pw << 8) + pw;
	}
	for (int i = tl; i <= sl; i++) {
		if (hs == ht) printf("%d\n", i - tl);
		hs = (hs << 8) + hs + s[i] - s[i - tl] * pw;
	}
	return 0;
}

Measured memory_bytes: 3656
n, m = map(int, input().split())
minmax = [n, m]
result = abs(n-m)
limit = 10**9+7

def lp(animal):
    row = 1
    for i in range(2, animal+1):
        row = row % limit * i 
    return row

if result >= 2:
    print(0)
    exit()

row = lp(min(minmax))
if n == m:
    print(row * row * 2 % limit)
else:
    print(row * row * max(minmax) % limit)



Measured memory_bytes: 3064
s=input()
n=len(s)
def pal(x):
    for i in range(len(x)//2):
        if x[i]!=x[-1-i]:
            return False
    return True
if pal(s[:n//2]) and pal(s[n//2+1:]) and pal(s):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const int MAX = 100000;
static const int NIL = -1;
using namespace std;

ll gcd(ll a, ll b){
    if(a%b == 0){
        return b;
    }else{
        return gcd(b, a%b);
    }
}

ll lcm(ll a, ll b){
    return a*b / gcd(a, b);
}


int main() {

    ll n,m; cin >> n >> m;
    vector<ll> np,mp;
    string s,t; cin >> s >> t;
    ll g = lcm(n,m);
    ll nPos = 0,mPos = 0;

    for(int i = 0; i < n; i ++){
        np.push_back(1+i*(g/n));
    }
    for(int i = 0; i < m; i ++){
        mp.push_back(1+i*(g/m));
    }



    while(nPos != np.size() && mPos != mp.size()){
        if(np[nPos] == mp[mPos]){
            if(s[nPos] != t[mPos])
            {
                cout << -1;
                return 0;
            }
            nPos ++;
            mPos ++;
        }else if(np[nPos] > mp[mPos]) mPos ++;
        else nPos ++;
    }

    cout << g;


    return 0;
}


Measured memory_bytes: 5580
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
	int n = Integer.parseInt(sc.next());
    int a = Integer.parseInt(sc.next());
    int b = Integer.parseInt(sc.next());
    
    int tr = n * a;
    int tx = b;

    if (tr > tx) {
	  System.out.println(tx);
    } else {
      System.out.println(tr);
    }
    
  }
}


Measured memory_bytes: 24148
# -*- coding: utf-8 -*-
a,b,c = map(int,input().split())

"""
if a == b and a != c or a == c and a != b or b == c and b != a:
    print("Yes")
else:
    print("No")
"""

tmp = [a, b, c]
if len(set(tmp)) == 2:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
#include<iostream>
#include<iomanip>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i, a, b) for(int i = (a);i < (b);++i)
#define FORR(i, b, a) for (int i = (b) - 1;i >= 0;--i)
#define REP(i, n) for(int i = 0;i < (n);++i)
#define REPR(i, n) for(int i = (n) - 1;i >= 0;--i)
#define ITER(itr, v) for(auto itr = v.begin();itr != v.end();++itr)
#define SORT(v) sort(v.begin(), v.end())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	string S;
	int Q;
	cin >> S >> Q;
	deque<char> dq;
	REP(i, S.size()) dq.emplace_back(S[i]);
	bool rev = false;
	REP(i, Q) {
		int T;
		cin >> T;
		if (T == 1) {
			rev = !rev;
		}
		else {
			int F;
			char C;
			cin >> F >> C;
			if (F == 1) {
				if (rev) dq.emplace_back(C);
				else dq.emplace_front(C);
			}
			else {
				if (rev) dq.emplace_front(C);
				else dq.emplace_back(C);
			}
		}
	}
	if (rev) {
		while (!dq.empty()) {
			char c = dq.back();
			dq.pop_back();
			cout << c;
		}
	}
	else {
		while (!dq.empty()) {
			char c = dq.front();
			dq.pop_front();
			cout << c;
		}
	}

	return 0;
}

Measured memory_bytes: 976
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**10
mod = 10**9 + 7


def f():
    n,m = list(map(int, input().split()))
    fs = [0] * (n+1)
    fs[1] = 1
    a = [1] * (n+1)
    for _ in range(m):
        x,y = list(map(int, input().split()))
        a[x] -= 1
        a[y] += 1
        if fs[x]:
            fs[y] = 1
        if a[x] < 1:
            fs[x] = 0
    return sum(fs)

print(f())


Measured memory_bytes: 8352
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    if(a+b <= 2*c) {
        out(a*x + b*y);
        re0;
    }

    ll p = min(x, y);
    ll q = max(x, y);

    ll ans;
    if(x <= y) {
        if(2*c <= b) {
            ans = 2*c*y;
        }
        else {
            ans = 2*c*x + b*(y - x);
        }
    }
    else {
        if(2*c <= a) {
            ans = 2*c*x;
        }
        else {
            ans = 2*c*y + a*(x - y);
        }
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 256
n = int(input())
li = list(map(int, input().split()))
num = list(set(li))
num.sort()
ans = 0
sums = 0
for index, i in enumerate(num):
    if i > n - sums:
        ans += n-sums
        break
    count = li.count(i) 
    ans += count
    if count >= i:
        ans -= i
    sums += count
print(ans)

Measured memory_bytes: 14236
import numpy as np

def input_numbers():
    temp = list(map(int, input().split()))
    return temp

temp = input_numbers()

n = temp[0]
m = temp[1]

like = []
for i in range(n):
    like += [input_numbers()]

ls = []
for i in range(m + 1):
    ls += [0]

for i in range(n):
    for j in range(1, like[i][0] + 1):
        ls[like[i][j]] += 1

count = 0

for i in ls:
    if(i == n):
        count += 1

print(count)

Measured memory_bytes: 12388
from collections import Counter
N, K = map(int, input().split())
A = Counter(list(map(int, input().split()))).most_common()
l = len(A)
ans = 0
for _ in range(N):
	if l > K:
		ans += A[-1][1]
		del A[-1]
		l = len(A)
	else:
		print(ans)
		exit()


Measured memory_bytes: 37780
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <array>
#include <climits>
#include <bitset>
#include <cassert>
#include <ctime>
#include <list>
#ifdef _MSC_VER
#include <agents.h>
#endif

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define UNIQUE(v) (v).erase(unique(ALL(v)), (v).end())
#define MP make_pair
#define MT make_tuple

using namespace std;

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

int f(int a, int b){
	return a || !b;
}

bool check(vector<int> v){
	if (v.empty()) return true;
	for (int i = v.size() - 2; i >= 0; --i){
		v[i] = f(v[i], v[i + 1]);
	}
	return v[0];
}

double calc(vector<int> v){
	double res = 1;
	reverse(ALL(v));
	rep(i, v.size()){
		res = pow(v[i], res);
	}
	return res;
}

vector<int> naive(vector<int> v){
	sort(ALL(v));
	double Max = -1;
	vector<int> res = vector<int>(REV(v));
	do{
		double x = calc(v);
		if (Max < x || abs(Max - x) < 1e-8 && v < res){
			Max = x, res = v;
		}
	} while (next_permutation(ALL(v)));
	return res;
}

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

	int n;
	cin >> n;
	vector<int> a, b;
	rep(i, n){
		int x;
		cin >> x;
		if (x < 2) a.push_back(x);
		else b.push_back(x);
	}
	sort(ALL(a));
	rep(i, a.size()){
		if (a[i] && i % 2){
			swap(a[i - 1], a[i]);
			break;
		}
	}
	sort(ALL(b));

	if (b.size() && !check(a)){
		int tmp = a.back();
		a.pop_back();
		a.push_back(b[0]);
		a.push_back(tmp);
		b.erase(b.begin());
	}

	int k = b.size();
	if (k > 1 && b[k - 1] == 3 && b[k - 2] == 2) swap(b[k - 1], b[k - 2]);

	for (auto x : a) b.push_back(x);

	rep(i, n) cout << b[i] << endl;

	//auto bb = naive(b);
	//rep(i, n) cout << bb[i] << endl;

	return 0;
}

Measured memory_bytes: 1224
n = gets.to_i
btn = []
n.times do |i|
  btn << gets.to_i
end
res = -1
idx = 0
0.upto(n) do |i|
  if btn[idx] == 2 then
    res = i + 1
    break
  else
    idx = btn[idx] - 1
  end
end
puts res


Measured memory_bytes: 2996
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		long n = sc.nextLong();

		int k = 1;
		long z = 26L;
		long d = 0L;
		while ( z < n ) {
			d = z;
			k++;
			z += (long)Math.pow(26, k);
		}

		long y = n - d - 1L;
		String alp = "abcdefghijklmnopqrstuvwxyz";

		String[] s = new String[k];
		for ( int i=k-1; i>=0; i-- ) {
			int c = (int)(y%26L);
			s[i] = alp.substring(c, c+1);

			y = y/26L;
		}
		System.out.println(String.join("", s));

	}
}


Measured memory_bytes: 35896
#include <cstdio>

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

const int maxn=2000;
const int mod=924844033;

int n,k,t,vis[maxn+10][2],a[maxn*2+10],f[maxn*2+10][maxn+10][2],g[maxn+10],ans,fac[maxn+10];

int main()
{
  n=read();
  k=read();
  for(int i=1; i<=n; ++i)
    {
      for(int j=0; j<2; ++j)
        {
          if(!vis[i][j])
            {
              int len=0;
              for(int x=i,y=j; x<=n; x+=k,y^=1)
                {
                  vis[x][y]=1;
                  ++len;
                }
              t+=len;
              a[t+1]=1;
            }
        }
    }
  f[1][0][0]=1;
  for(int i=2; i<=t; ++i)
    {
      f[i][0][0]=f[i-1][0][0]+f[i-1][0][1];
      if(f[i][0][0]>=mod)
        {
          f[i][0][0]-=mod;
        }
      for(int j=1; j<=n; ++j)
        {
          f[i][j][0]=f[i-1][j][0]+f[i-1][j][1];
          if(f[i][j][0]>=mod)
            {
              f[i][j][0]-=mod;
            }
          if(!a[i])
            {
              f[i][j][1]=f[i-1][j-1][0];
            }
        }
    }
  for(int i=0; i<=n; ++i)
    {
      g[i]=f[t][i][0]+f[t][i][1];
      if(g[i]>=mod)
        {
          g[i]-=mod;
        }
    }
  fac[0]=1;
  for(int i=1; i<=n; ++i)
    {
      fac[i]=1ll*fac[i-1]*i%mod;
    }
  for(int i=0; i<=n; ++i)
    {
      ans=(ans+1ll*((i&1)?(mod-1):1)*g[i]%mod*fac[n-i])%mod;
    }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 62976
#include <bits/stdc++.h>
using namespace std;
long long N;
long long tmp=0;
long long jum[200001];
int main(){
	cin>>N;
	long long arr[N+1];
	for(long long i=1; i<=N; i++){
		cin>>arr[i];
		jum[arr[i]]++;
	}
for(long long i=1; i<=N; i++){
		tmp=tmp+jum[i]*(jum[i]-1)/2;
	}
	for(long long x=1; x<=N; x++){
		tmp=tmp-jum[arr[x]]+1;
		cout<<tmp<<'\n';
		tmp=tmp+jum[arr[x]]-1;
	}
}

Measured memory_bytes: 4736