akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
#define MOD (ll)(1e9 + 7)
using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    int dp[n + 5];
    map<int, bool> mp;
    rep(i, m)
    {
        int t;
        cin >> t;
        mp[t] = true;
    }
    if (mp[1] == true)
    {
        dp[1] = 0;
    }
    else
    {
        dp[1] = 1;
    }

    if (mp[2] == true)
    {
        dp[2] = 0;
    }
    else
    {
        dp[2] = 1 + dp[1];
    }
    rep(i, 3, n + 1)
    {
        if (mp[i] == true)
        {
            dp[i] = 0;
        }
        else
        {
            dp[i] = (dp[i - 1] + dp[i - 2]) % MOD;
        }
    }
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 5376
l=int(input())
n= list(map(int, input().split()))
ans=0
for i in range(l-2):
    for j in range(i+1,l-1):
        if n[i]==n[j]:
            pass
        else:
            for k in range(j+1,l):
                if n[i]==n[k] or n[j]==n[k]:
                    pass
                else:
                    z=max(n[i],n[j],n[k])
                    if n[i]+n[k]+n[j]-z>z:
                        ans+=1
print(ans)


Measured memory_bytes: 9140
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long LL;
const LL mo=1e9+7;
char s[300005];
int len;
LL ans=0,f[300005][6];
void Add(LL &x,LL y) {
    x=(x+y)%mo;
}
int main() {
    scanf("%s",s);
    len=strlen(s);
    f[0][0]=1;
    for (int i=0;i<len;i++) {
	if (s[i]=='?') ans=ans*2%mo;
	for (int j=0;j<6;j++) {
	    if (f[i][j]==0) continue;
	    if (s[i]=='0'||s[i]=='?') {
		if (j==0) Add(f[i+1][2],f[i][j]);
		if (j==1) Add(f[i+1][4],f[i][j]);
		if (j==2) Add(f[i+1][3],f[i][j]);
		if (j==3) Add(f[i+1][2],f[i][j]);
		if (j==4) Add(f[i+1][5],f[i][j]);
		if (j==5) Add(f[i+1][4],f[i][j]);
	    }
	    if (s[i]=='1'||s[i]=='?') {
		if (j==0) Add(f[i+1][1],f[i][j]);
		if (j==1) Add(ans,f[i][j]);
		if (j==2) Add(f[i+1][0],f[i][j]);
		if (j==3) Add(f[i+1][2],f[i][j]);
		if (j==4) Add(f[i+1][1],f[i][j]);
		if (j==5) Add(f[i+1][4],f[i][j]);
	    }
	}
    }
    Add(ans,f[len][1]);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 14592
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  int N;
  int A;
  int B;
  cin >> N >> A >> B;
  
  string S;
  cin >> S;
  
  int num = 0;
  int num2 = 0;
  
  for(int i = 0;i < N;++i){
    if(S[i] == 'a'){
      if(num < A + B){
        cout << "Yes" << endl;
        num++;
      }
      else{
        cout << "No" << endl;
      }
    }
    else if(S[i] == 'b'){
      if(num < A + B && num2 < B){
        cout << "Yes" << endl;
        num++;
        num2++;
      }
      else{
        cout << "No" << endl;
      }
    }
    else{
      cout << "No" << endl;
    }
  }
  
  
  
  
}

Measured memory_bytes: 896
using System;

class Program
    {
        static void Main(string[] args)
        {
            var test = Console.ReadLine();
            var first = test.Substring(0, 1);
            var second = test.Substring(1, 1);
            var third = test.Substring(2, 1);
            int cont = 0;
            if (first == "1") { cont++; }
            if (second == "1") { cont++; }
            if (third == "1") { cont++; }
            Console.WriteLine(cont);
        }
    }

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

// in-short-use macros

#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007

//container-use 

typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef pair< ll,ll > pll;
typedef vector<pair<ll,ll > > vpl;
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define rep(i,a,b) for (int i = a; i <= b; i++)

//main function here
ll l(ll i)
{
    while(i>=10)
        i=i/10;
    return i;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,sum=0;
    cin>>n;
    ll dp[1000];
    memset(dp,0,sizeof(dp));
    for(ll i=11;i<=99;i++)
    {
        ll rig=i%10;
        ll lef=i/10;
        ll ans=0;
        if(lef==0 || rig==0)
            continue;
        if(lef==rig)
        {
            for(int j=1;j<=n;j++)
            {
                if(j%10==lef && l(j)==rig)
                    ans++;
            }   
            dp[i]=ans;
        }
        else
        {
            for(ll j=1;j<=n;j++)
            {
                if(j%10==lef && l(j)==rig && i<=n)
                {
                    ans++;
                }
            }
            dp[i]=ans;
        }
    }
    for(ll i=11;i<=99;i++)
    {
        ll rig=i%10;
        ll lef=i/10;
        ll rev=rig*10+lef;
        sum=sum+dp[rev]*dp[i];
    }
    cout<<sum<<"\n";
  return 0;
 }

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

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int[] intArray = Console.ReadLine().Trim().Split(' ').Select(x => int.Parse(x)).ToArray();
                int h = intArray[0];
                int w = intArray[1];
                if (h == 0 && w == 0) break;
                int h_t = 1;
                int w_t = 1;

                while (true) 
                {
                    if (h_t == h + 1) 
                    {
                        Console.Write('\n');
                        break; 
                    }

                    if ((h_t + w_t) % 2 != 0)
                    {
                            Console.Write('.');
                    }

                    else
                    {
                            Console.Write('#');
                    }
                    w_t++;

                    if (w_t == w+1)
                    {
                        w_t = 1;
                        h_t++;
                        Console.Write('\n');
                    }
                }
            }
        }
    }
}



Measured memory_bytes: 18144
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <stdio.h>
#include <bits/stdc++.h>
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    int p[n] = {0};
    for(int i = 0; i < n; i++){
        cin >> p[i];
    }
    sort(p, p + SIZE_OF_ARRAY(p)); 
    int sum = 0;
    for(int i = 0; i < k; i++){
        sum += p[i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3652
import java.io.*;
import java.util.*;
import static java.lang.System.in;

public class Main {
    static long mod = 1000000000+7;
    static int maxn = 100005;
    static long[] dp = new long[maxn+1];
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        //BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        //String[] buf = reader.readLine().split(" ");
        String L = sc.next();
        String s = plusOne(L);
        int len = s.length();
        ArrayList<Integer> one = new ArrayList<>();
        for(int i=0;i<len;i++){
            if(s.charAt(i)=='1') one.add(i);
        }
        dp[0] = 1;
        dp[1] = 3;
        for(int i=2;i<=maxn;i++) dp[i] = 3*dp[i-1]%mod;
        long ans = solve(one,len);
        System.out.println(ans);
    }
    static long solve(ArrayList<Integer> ones,int len){
        // len is the length of L+1 in base-2
        if(ones.size()==1){
            return dp[len-1];
        }
        long ans = dp[len-1];
        for(int i=1;i<ones.size();i++){
            long cur = pow(2,i);
            int x = ones.get(i);
            int remain = len-1-x;
            cur = cur*dp[remain]%mod;
            ans = (ans+cur)%mod;
        }
        return ans;
    }
    static String plusOne(String L){
        int len = L.length();
        int idx = len-1;
        while(idx>=0){
            if(L.charAt(idx)=='0') break;
            idx--;
        }
        StringBuilder sb = new StringBuilder();
        if(idx==-1){
            sb.append(1);
            for(int j=0;j<len;j++) sb.append(0);
        } else{
            sb.append(L.substring(0,idx));
            sb.append(1);
            for(int j=idx+1;j<len;j++) sb.append(0);
        }
        return sb.toString();
    }
    static long pow(long base, long q){
        long ret = 1;
        while(q>0){
            if(q%2==1) ret = ret*base%mod;
            base = base*base%mod;
            q /= 2;
        }
        return ret;
    }
}



Measured memory_bytes: 28600
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n,i,j,count;
		boolean p[]=new boolean[10001];
		//
		Arrays.fill(p, true);
		p[0]=p[1]=false;
		for(i=2;i<=10000;i++){
			if(p[i])
				for(j=2;i*j<=10000;j++){
					p[i*j]=false;
				}
		}//
		while(sc.hasNext()){
			n=sc.nextInt();
			count=0;
			for(i=1;i<=n;i++){
				//System.out.println(i+""+p[i]+" "+(n-i+1)+""+p[n-i+1]);
				if(p[i] && p[n-i+1]) count++;
			}
			System.out.println(count);
		}//
	}
}

Measured memory_bytes: 12000
#include<iostream>
#include<algorithm>
#include<string>
#define rep(i,s,n) for(int i=s;i<n;i++)
using namespace std;
int dp[4001][4001];
int main(){
	string a,b;
	while(cin>>a>>b){
	int h=a.size()+1,w=b.size()+1,ans=0;
	rep(i,0,h)rep(j,0,w)dp[i][j]=0;
	rep(i,1,h)rep(j,1,w)if(a[i-1]==b[j-1])dp[i][j]=dp[i-1][j-1]+1,ans=max(ans,dp[i][j]);
	cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 65684
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    int maxi = 0,cnt = 0;
    rep(i,0,N){
        int a;
        cin >> a;
        if(a >= maxi){
            maxi = a;
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); } 
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
#define forxr(i,n) for(int i = (n)-1; i >= 0; --i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll,ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second
#define all(c) c.begin(),c.end()

int main() {
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout << fixed << setprecision(12);
  // Emily <3
  int x = 0;
  for (int i = 0; i < 4; ++i) {
    char c; cin >> c;
    if (c == '+') {
      x ++;
    } else {
      x--;
    }
  }
  cout << x << nl;
  return 0;
}



Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
	"strings"
)

func main() {
	var N int
	fmt.Scan(&N)

	c := make(map[string]int)
	var s string
	for i := 0; i < N; i++ {
		fmt.Scan(&s)
		t := strings.Split(s, "")
		sort.Strings(t)
		s := strings.Join(t, "")
		c[s]++
	}

	ans := 0
	for _, s := range c {
		if s > 1 {
			v := 0.5 * float64((s-1)*s)
			ans += int(v)
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 12416
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false)
typedef long long ll;
const int maxn = 100005;
char s[maxn], t[maxn];
int main()
{
    ll n,m;
    cin >> n >> m;
    scanf("%s%s",s,t);

    if(s[0] != t[0])
    {
        printf("-1");
        return 0;
    }
    
    int g = __gcd(n,m);
    for(int i = 0; i < g; i++)
    {
        int x = n/g * i;
        int y = m/g * i;
        if(s[x] != t[y])
        {
            cout << "-1";
            return 0;
        }
    }
    cout << (ll)n*m/g ;
    return 0;
}


Measured memory_bytes: 384
package main

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

func main() {

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	line := scanner.Text()
	chars := strings.Split(line, " ")
	stack := []string{}
	// chars := []string{"34", "116", "+", "20", "5", "-", "5", "-", "1", "*", "+"}

	for _, char := range chars {
		_, err := strconv.Atoi(char)
		if err == nil {
			stack = push(stack, char)
		} else {
			switch char {
			case "+":
				var v string
				v, stack = pop(stack)
				first, _ := strconv.Atoi(v)

				var vv string
				vv, stack = pop(stack)
				second, _ := strconv.Atoi(vv)
				result := second + first
				stack = push(stack, strconv.Itoa(result))
			case "-":
				var v string
				v, stack = pop(stack)
				first, _ := strconv.Atoi(v)

				var vv string
				vv, stack = pop(stack)
				second, _ := strconv.Atoi(vv)
				result := second - first
				stack = push(stack, strconv.Itoa(result))
			case "*":
				var v string
				v, stack = pop(stack)
				first, _ := strconv.Atoi(v)

				var vv string
				vv, stack = pop(stack)
				second, _ := strconv.Atoi(vv)
				result := second * first
				stack = push(stack, strconv.Itoa(result))
			}
		}
	}
	fmt.Println(stack[0])
}

func push(stack []string, char string) []string {
	newStack := append(stack, char)

	return newStack
}

func pop(stack []string) (string, []string) {
	last := stack[len(stack)-1]

	stack = append(stack[:len(stack)-1])
	return last, stack
}



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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  string A; cin >> A;
  ll l = A.length();
  map<char,ll> count;
  rep(i,l) count[A[i]]++;
  ll result = l*(l-1)/2 + 1;
  for(auto x: count) result -= x.second*(x.second-1)/2;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<math.h>
#define ll long long
#define mod 1000000007 
using namespace std;
vector<int> v[100001];
int ar[100001];

void solve()
{
 int ans=0;
 double n , d ,x ,y;
 cin >> n >> d;
 while(n--)
 {
     cin >> x >> y;
   if(sqrt(x*x + y*y)<=d) ans++;
 }
cout << ans << endl;

}

int main()
{
  int t=1;
  //cin >> t;
  for(int i=0 ; i<100001 ; i++) ar[i]=0;
  while(t--)
    solve();
    return 0 ;
}
  

Measured memory_bytes: 6576
from collections import Counter
N=int(input())
listS=[]
for i in range(N):
  S=input()
  listS+=[S]
listS=Counter(listS)
listS=listS.most_common()
ans=[]
MAX=listS[0][1]
for i in range(len(listS)):
  if listS[i][1]==MAX:
    ans+=[listS[i][0]]
  else:
    break   
ans.sort()
for i in ans:
  print(i)

Measured memory_bytes: 43476
#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;

int a[11], x[11], y[11];

int main(void)
{
	double ans = 0.0;
	int n, i, cnt = 0;

	scanf("%d" ,&n);
	for (i = 1; i <= n; i++)
	{
		scanf("%d %d" ,&x[i], &y[i]);
		a[i] = i;
	}

	do{
		double dist = 0.0;
		for (i = 1; i < n; i++)
			dist += sqrt(pow(x[a[i + 1]] - x[a[i]], 2.0) + pow(y[a[i + 1]] - y[a[i]], 2.0));
		ans += dist;

		++cnt;
	} while (next_permutation(a + 1, a + n + 1));

	printf("%.6lf" ,ans / (double)cnt);
	return 0;
}

Measured memory_bytes: 128
/*
  Fuad Ashraful Mehmet
  University of Asia Pacific,Bangladesh
  Date:28 th March 2020
  TODO:
  https://codeforces.com/problemset/problem/482/B
  uva: 11695 Flight Planning
  https://onlinejudge.org/external/116/11621.pdf
*/
#include<bits/stdc++.h>
#define all(o) (o).begin(),(o).end()
using namespace std;
void scan(int &x)
{
  scanf("%d",&x);
}
const int N=1e5+5;
typedef long long ll;
void Dbug();


signed main()
{
  ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

 
   ll x;
   cin>>x;

   ll ans=0;

   ll div=x/500;
   x=x%500;

   ans=div*1000;

   div=x/5;
   ans+=div*5;
   cout<<ans<<endl;
 // Dbug();
  return 0;
}

void Dbug()
{
 
}

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

#include<string.h>
 
#define T int t, q; scanf("%d", &t); for(q=1; q<=t; q++)
 typedef long long int ll;

 int main(){
 	ll n,m,l,k;
 	double mm,kk,ll;
 	cin >> n ;
 	mm=n/1.08;
 	m=mm;

 	ll=m*1.08;
 	l=ll;
 	k=m+1;
 	kk=k*1.08;
 	k=kk;

 	//n=1.08*400;
 	if(l==n )
 	cout << m << endl;
 else if(k==n)
 	cout << m+1 << endl;
 else cout <<":(" <<endl;
 }

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int narabe_all;
int narabe[1001*1001];

/* syo-zyun */
int qsort_comp(const void* x,const void* y) {
	int* a=(int*)x;
	int* b=(int*)y;
	if(*a>*b)return 1;
	if(*a<*b)return -1;
	return 0;
}

int nibun_tansaku(int searchfor) {
	int left,right,mid;
	if(searchfor<0)return 0;
	left=0;right=narabe_all-1;
	while(left<=right) {
		mid=(left+right)/2;
		if(narabe[mid]==searchfor)return mid;
		else if(narabe[mid]<searchfor)left=mid+1;
		else right=mid-1;
	}
	return left-1;
}

int main(void) {
	int N,M;
	int i,j;
	int P[1001];
	int now,max;
	while(1) {
		scanf("%d%d",&N,&M);
		if(N==0 && M==0)break;
		P[0]=0;
		for(i=1;i<=N;i++)scanf("%d",&P[i]);
		narabe_all=0;
		for(i=0;i<=N;i++) {
			for(j=i;j<=N;j++) {
				narabe[narabe_all++]=P[i]+P[j];
			}
		}
		qsort(narabe,narabe_all,sizeof(int),qsort_comp);
		max=0;
		for(i=0;i<=N;i++) {
			for(j=i;j<=N;j++) {
				now=P[i]+P[j];
				now+=narabe[nibun_tansaku(M-now)];
				if(now<=M && now>max)max=now;
			}
		}
		printf("%d\n",max);
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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

	
	int K, S;
	cin >> K >> S;

	int goukei = 0;

	rep(i, K + 1) {
		rep(ii, K + 1) {
			int iii = S - i - ii;
			if (0 <= iii && iii <= K) goukei++;
		}
	}


	co(goukei);

	Would you please return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		long N=stdIn.nextLong();
		int ans=0;
		for(long i=2;i<Math.sqrt(N);i+=2){
			if(N%i==0){
				int a=0;
				while(N%i==0){
					N/=i;a++;
				}
				for(int j=1;a>=j;j++){
					a-=j;ans++;
				}
			}
			if(i==2)
				i--;
		}
		if(N!=1)
			ans++;
		System.out.println(ans);
	}
}


Measured memory_bytes: 35764
<?php
  while($line=trim(fgets(STDIN))){
    $ab=explode(" ",$line);
    $_1st=$ab;
    while(($amari=$ab[0]%$ab[1])!=0){
      $ab[0]=$ab[1];
      $ab[1]=$amari;
    }
    echo $ab[1]." ";
    echo $_1st[0]*$_1st[1]/$ab[1]."\n";
  }

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

ll A, B, C;

int main(int argc, char **argv)
{
	cin >> A >> B >> C;

	for (int i = 1; i < 100000000; ++i)
	{
		ll tmp_a = A * i;
		if (tmp_a % B == C)
		{
			std::cout << "YES"<< std::endl;
			return 0;
		}
	}
	std::cout << "NO"<< std::endl;
	
}


Measured memory_bytes: 256
N, K = map(int, input().split())
MOD = 10**9+7
ans = 0
s = pow(K, N, MOD)
cnt = [0]*(K+1)

for i in range(K, 0, -1):
    a = pow(K//i, N, MOD)
    c = 2
    
    while True:
        if c*i>K:
            break
        
        a -= cnt[c*i]
        a %= MOD
        c += 1
    
    cnt[i] = a
    ans += i*a
    ans %= MOD
    s -= a
    s %= MOD

ans += s

print(ans%MOD)

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

int main() {
 multimap<string,UL> S;
 UL Q; scanf("%u",&Q);
 rep(q,Q){
  UL c; scanf("%u",&c);
  if(c==0){
   char buf[21]; UL x; scanf("%s%u",buf,&x);
   S.emplace(buf,x);
  }
  if(c==1){
   char buf[21]; scanf("%s",buf);
   auto lb=S.lower_bound(buf);
   auto ub=S.upper_bound(buf);
   for(auto i=lb; i!=ub; i++){
    printf("%u\n",i->second);
   }
  }
  if(c==2){
   char buf[21]; scanf("%s",buf);
   S.erase(buf);
  }
  if(c==3){
   string L,R;
   char buf[21];
   scanf("%s",buf); L=string(buf);
   scanf("%s",buf); R=string(buf);
   auto f=S.lower_bound(L);
   for(;f!=S.end();f++){
    if(f->first>R) break;
    printf("%s %u\n",f->first.c_str(),f->second);
   }
  }
 }
 return 0;
}




Measured memory_bytes: 24860
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 9;
const LL LLINF = 1e18;

int main(void) {
	int A, B;
	string s;
	cin >> A >> s >> B;
	int ans = 0;
	if (s == "+") {
		ans=A+B;
	}else ans=A-B;
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
int c2i(char c)
{
    return c - '0';
}
int main(int argc, char const *argv[])
{
    string s;
    cin >> s;
    int k;
    cin >> k;
    int len = s.size();
    ll ans = 0;
    if (k == 1)
    {
        rep(i, len)
        {
            if (i == 0)
            {
                ans += c2i(s[i]);
            }
            else
            {
                ans += 9;
            }
        }
    }
    if (k == 2)
    {
        rep(i, len)
        {
            bool flag = false;
            rep(j, i + 1, len)
            {
                if (i == 0)
                {
                    if (flag)
                        ans += 1 * 9;
                    else
                    {
                        if (s[j] != '0')
                            ans += 1 * c2i(s[j]);
                    }
                    ans += (c2i(s[i]) - 1) * 9;
                }
                else
                {
                    ans += 81;
                }
                flag |= (s[j] != '0');
            }
        }
    }
    if (k == 3)
    {
        rep(i, len)
        {
            bool flag1 = false;
            rep(j, i + 1, len)
            {
                bool flag2 = false;

                rep(k, j + 1, len)
                {
                    if (i == 0)
                    {
                        if (flag1)
                        {
                            ans += 1 * 81;
                        }
                        else if ((!flag1) && flag2)
                        {
                            if (c2i(s[j]) != 0)
                            {
                                ans += 1 * (c2i(s[j]) - 1) * 9;
                                ans += 1 * 1 * 9;
                            }
                        }
                        else
                        {
                            if (c2i(s[j]) != 0 && c2i(s[k]) != 0)
                            {
                                ans += 1 * 1 * c2i(s[k]);
                                ans += 1 * (c2i(s[j]) - 1) * 9;
                            }
                        }
                        ans += (c2i(s[i]) - 1) * 81;
                    }
                    else
                    {
                        ans += 9 * 9 * 9;
                    }
                    flag2 |= (s[k] != '0');
                }
                flag1 |= (s[j] != '0');
            }
        }
    }
    cout << max(0ll, ans) << endl;
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9 + 7;
const int INF = 1<<29;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it:t)cout<<it<<" ";}
inline int powerexp(int a,int b,int m = MOD){int res=1;while(b){if(b&1)res=res*a%m;a=a*a%m,b>>=1;}return res%m;}
inline int modinv(int a){return powerexp(a,MOD-2,MOD);}
inline int lcm(int a,int b){int g=__gcd(a,b);return a/g*b;}

//-------------------< start here >-------------------------// 
int digit_sum(int n){
   if (n == 0) return 0;
   int ret = n % 10 + digit_sum(n/10);
   return ret;
}

void calc(int n){
   int val = digit_sum(n);
   if (n % val == 0) cout << "Yes" << endl;
   else cout <<"No" << endl;
}

void solve(){
  	int n;
  	cin >> n;
  	
  	calc(n);
}
//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
   #endif
}


Measured memory_bytes: 256
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    multiset<ld> kek;
    for (int i = 0; i < n; i++) {
        ld v;
        cin >> v;
        kek.insert(v);
    }
    while (kek.size() > 1) {
        auto it1 = kek.begin();
        auto it2 = it1++;
        ld m = (*it1 + *it2) / 2;
        kek.erase(it1);
        kek.erase(it2);
        kek.insert(m);
    }
    cout << fixed << setprecision(20) << *kek.begin();
    return 0;
}

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

typedef long long ll;
typedef unsigned long long int ull;
#define endl "\n"
#define pb push_back
#define sq(a) (a)*(a)
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define MOD 1000000007
#define PI 3.141592653589793238
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

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

ll exp(ll x,ll n,ll mod)
{
    ll result=1;
    while(n>0)
    {
        if(n & 1 ==1)
            result=(result * x)%mod;
        x=(x*x)%mod;
        n=n>>1;
    }
    return result;
}



int32_t main()
{
    IOS

    ll n,w;
    cin>>n>>w;

    ll v[n],wt[n];

    for(ll i=0;i<n;i++)
    {
    	cin>>wt[i]>>v[i];
    }

    ll dp[w+1][n+1];

    for(ll i=0;i<=w;i++)
    {
    	for(ll j=0;j<=n;j++)
    	{
    		if(i==0||j==0)
    			dp[i][j]=0;

    		else if(wt[j-1]>i)
    			dp[i][j]=dp[i][j-1];

    		else
    			dp[i][j]=max(v[j-1]+dp[i-wt[j-1]][j-1],dp[i][j-1]);
    	}
    }

    cout<<dp[w][n]<<endl;

    
    return 0;
}


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

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

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

Measured memory_bytes: 1792
from sys import stdin, setrecursionlimit, stdout
#setrecursionlimit(1000000) #use "python" instead of "pypy" to avoid MLE
#from collections import deque
#from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
#from heapq import heapify, heappop, heappush, heapreplace, heappushpop
def ii(): return int(stdin.readline())
def fi(): return float(stdin.readline())
def mi(): return map(int, stdin.readline().split())
def fmi(): return map(float, stdin.readline().split())
def li(): return list(mi())
def si(): return stdin.readline().rstrip()
def lsi(): return list(si())
#mod=1000000007
res=['YES', 'NO']





test_case=1
while test_case:
    test_case-=1

    n=ii()
    a=li()
    a.sort()
    s=a[-1]
    i=n-2
    x=-1
    for j in range(n-2):
        s+=a[i]
        x+=1
        if x:
            x=-1
            i-=1
    print(s)

Measured memory_bytes: 91908
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
    string a;
    string str[3] = {"Sunny", "Cloudy", "Rainy"};
    cin >> a;
    if (a == "Sunny") {
        cout << str[1] << endl;
    }
        
    if (a == "Cloudy") {
            cout << str[2] << endl;
    }
        
    if (a == "Rainy") {
            cout << str[0] << endl;
        }
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  while(cin>>s){
    int a[10][10];
    for(int i=0;i<10;i++)a[0][i]=s[i]-'0';
      for(int i=1;i<10;i++)
        for(int j=0;j<10-i;j++)
          a[i][j]=(a[i-1][j]+a[i-1][j+1])%10;
    cout<<a[9][0]<<endl;
  }
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

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

  int x, n;
  cin >> x >> n;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  std::sort(p.begin(), p.end());

  int min_value{x-0};
  int ans {0};
  int index = 0;
  for (auto i = 0;i <= 101;++i) {
    if (index < n && i == p[index]) {
      ++index;
    } else {
      if (min_value > std::abs(i-x)) {
        min_value = std::abs(i-x);
        ans = i;
      }
    }
  }
  cout << ans << '\n';
}


Measured memory_bytes: 3612
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long long int llint;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int,int>
#define pl pair<ll,ll>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912
const long double PI = acos(-1);
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int GCD(int x,int y){
    return y ? GCD(y,x%y) : x;
}
vector<int> g[100010];
int h[100010];
int m;
string s;
int main(){
    while(true){
        cin >> s;
        if(s == "-"){
            break;
        }
        cin >> m;
        int n = s.size();
        for(int i = 0; i < m; i++){
            int x; cin >> x;
            string tmp = s.substr(x,n-x);
            s = tmp + s.substr(0,x);
        }
        cout << s << endl;
    }
}





Measured memory_bytes: 5564
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		long[][] array = new long[N][2];
		int remain = M;
		long answer = 0;

		for (int i = 0; i < N; i++) {
			array[i][0] = sc.nextInt();
			array[i][1] = sc.nextInt();
		}

		Arrays.sort(array, (a, b) -> Long.compare(a[0], b[0]));

		for (int i = 0; i < N; i++) {
			if (remain < array[i][1]) {
				answer += array[i][0] * remain;
				break;
			} else {
				answer += array[i][0] * array[i][1];
				remain -= array[i][1];
			}
		}

		System.out.println(answer);
	}
}

Measured memory_bytes: 92588
import java.util.*;
class Main {

	public static void main(String[] args) {
		Scanner sc= new Scanner(System.in);
		double d=sc.nextDouble(),t=sc.nextDouble(),s=sc.nextDouble();
		if(d/s<=t)System.out.println("Yes");
		else System.out.println("No");

	}

}

Measured memory_bytes: 37256
#define _CRT_SECURE_NO_WARNINGS
#define REL
#include <algorithm>
#include <string>
#include <iostream>
#include <complex>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <stack>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <random>
#include <set>
#include <vector>
#include <unordered_map>
#include <bitset>
#include <unordered_set>
#include <array>
#include <forward_list>
#include <chrono>
#include <iomanip>
#include <utility>
#include <assert.h>

#pragma GCC optimize("Ofast")
#pragma target("sse", "sse1")

#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

mt19937 gen(34);

int n, p[10], q[10], ans[2];
vector <int> a;

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen("memory.in", "r", stdin);
	//freopen("memory.out", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> p[i];
	for (int i = 0; i < n; i++)
		cin >> q[i];
	int cnt = 1;
	for (int i = 0; i < n; i++)
	{
		cnt *= (i + 1);
		a.pb(i + 1);
	}
	for (int num = 1; num <= cnt; num++)
	{
		bool ch1 = true, ch2 = true;
		for(int i = 0; i < n; i++)
			ch1 &= (p[i] == a[i]);
		for (int i = 0; i < n; i++)
			ch2 &= (q[i] == a[i]);
		if (ch1)
			ans[0] = num;
		if (ch2)
			ans[1] = num;
		next_permutation(a.begin(), a.end());
	}
	cout << abs(ans[0] - ans[1]);
	return 0;
}

Measured memory_bytes: 256
S = input()
T = input()

l1 = len(S)
l = len(T)

min_ = float('inf')

for i in range(l1 - l + 1):
    cnt = 0

    for j in range(l):
        if S[i + j] != T[j]:
            cnt += 1

    min_ = min(min_, cnt)

print(min_)


Measured memory_bytes: 9044
class Node():
    def __init__(self,key):
        self.key = key
        self.parent = None
        self.left = None
        self.right = None
    def __str__(self):
        return str(self.key)
def inorder(r): ##r:root
    if (r.left != None):
        inorder(r.left)
    print(' ' + str(r.key), end ='')
    if (r.right != None):
        inorder(r.right)
def preorder(r):  ##r:root 
    print(" "+str(r.key), end ='')  ##preorder은 루트 쪽부터 print
    if (r.left != None):  ##left쪽으로 쭉감
        preorder(r.left) ##ns[i].left를 root로써 재귀함수!
    if (r.right != None):
        preorder(r.right) ##left다했으면 right으로도 똑같이 해줌 
root = None
def insert(z,root):
    y = None
    x = root
    while x != None:
        y = x
        if z.key < x.key:
            x = x.left
        else:
            x = x.right
    z.parent = y
    
    if z.key < y.key:
        y.left = z
    else:
        y.right = z
n = int(input())
command = str(input())
if command[0]=="i":
    root = Node(int(command[7:]))
else:
    print()
for i in range(n-1):
    com = str(input())
    if com[0] == "i":
        insert(Node(int(com[7:])),root)
    else:
        inorder(root)
        print()
        preorder(root)
        print()
    


Measured memory_bytes: 104972
x,y = map(int,input().split())
 
#print(x,y)
 
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)
    return divisors
x_li=(make_divisors(x))
y_li=(make_divisors(y))
z_li=(list(set(x_li)&set(y_li)))
#print(z_li)
 
import math
count=1

def is_prime(n):
    if n == 1: return False
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
 
    return True
for n in z_li:
  if(is_prime(n)==True):
    count=count+1
print(count)

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

int main(){
  string s;cin >> s;
  if(s == "Sunny")cout << "Cloudy" << endl;
  else if(s == "Cloudy")cout << "Rainy" << endl;
  else cout << "Sunny" << endl;
  return 0;
}


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

using namespace std;
using lli = long long int;

int main()
{
    int n;
    lli k;
    cin >> n >> k;
    vector<int> a(n+1);

    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }

    vector<int> idx;
    vector<int> vis(n+1, -1);
    int p = 1;
    while(vis[p] == -1) {
        vis[p] = idx.size();
        idx.push_back(p);
        p = a[p];
    }
    lli n_cycle = idx.size() - vis[p];
    lli n_non_cycle = vis[p];

    if(k < n_non_cycle) {
        cout << idx[k] << endl;
    } else {
        k -= n_non_cycle;
        k %= n_cycle;
        cout << idx[n_non_cycle+k] << endl;
    }

    return 0;
}

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

int main(){
    int n;
    scanf("%d",&n);
    for (int i=1;i<=n;i++) {
        if (i%3==0) printf(" %d",i);
        else {
            int t=i;
            for (;;) {
                if (t%10==3) { printf(" %d",i);break; }
                else if (t<10) break;
                t/=10;
            }
        }
    }
    puts("");
    return 0;
}


Measured memory_bytes: 3196
from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return sorted([list(map(int, input().split())) for _ in range(n)])
def sortx(x,n,k):
    if k == 0:x.sort(key=lambda y:y[1,n])
    else:x.sort(reversed=True, key=lambda y:y[1,n])
def graph():
    n=inp()
    g=[[] for _ in range(n)]
    for i in range(n):
        a=inp()
        a-=1
        g[i].append(a)
        g[a].append(i)
    return n,g
def graphm():
    n,m=inpm()
    g=[[] for _ in range(n)]
    for _ in range(m):
        a,b,w=inpm()
        a-=1
        b-=1
        g[a].append((b,w))
        g[b].append((a,w))
    return n,m,g

def dijkstra(s,n,g): # sからの最短距離 頂点数n
    s -= 1
    que = []
    d = [10**15 for _ in range(n)]
    d[s] = 0
    heappush( que,(0,s) )
    while len(que)>0:
        p =  heappop(que)
        v = p[1]
        if d[v] < p[0]:
            continue
        for i in range(len(g[v])):
            edge = g[v][i]
            if d[edge[0]] > d[v] + edge[1]:
                d[edge[0]] = d[v] + edge[1]
                heappush( que,(d[edge[0]] , edge[0]) )
    return d

def main():
    r=inp()
    print(r**2)

      
      

if __name__ == "__main__":
    main()




Measured memory_bytes: 39020
#include<bits/stdc++.h>
#define int long long
#define f(i,n) for(int i=0;i<(n);i++)
using namespace std;
char x[200000],y[200000];
signed main(){
	int a,b,c,d;
	string s;
	cin>>a>>b>>s;
	c=-1,d=a;
	f(i,b){
		cin>>x[i]>>y[i];
	}
	for(int i=b-1;i>=0;i--){
		if(x[i]==s[c+1]&&y[i]=='L')c++;
		if(x[i]==s[d-1]&&y[i]=='R')d--;
		if(x[i]==s[c]&&y[i]=='R')c--;
		if(x[i]==s[d]&&y[i]=='L')d++;
	}
	cout<<max((int)(0),d-c-1)<<endl;
    return 0;
}

Measured memory_bytes: 900
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef double db;
const int maxn = 1e6 + 10;
int a,b,k;
int main()
{
    cin>>a>>b>>k;
    for(int i=a;i<a+k&&i<=b;i++)
        cout<<i<<endl;
    for(int i=b-k+1;i<=b;i++)
    {   
        if(i<a+k)continue;
        cout<<i<<endl;
    }
    return 0;
}


Measured memory_bytes: 384
import math
import numpy as np


def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def main():
    h, w, k = map(int, input().split())
    css = np.array([list(input()) for _ in range(h)])

    ans = 0
    for paint_h in range(2 ** h):
        for paint_w in range(2 ** w):
            cnt = 0
            for i in range(h):
                for j in range(w):
                    if (paint_h >> i) & 1 == 0 and (paint_w >> j) & 1 == 0:
                        if css[i][j] == '#':
                            cnt += 1
            if cnt == k:
                ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 27136
h, n = map(int, input().split())
a, b = [], []
for _ in range(n):
    A, B = map(int, input().split())
    a.append(A)
    b.append(B)

a_max = max(a)
dp = [0]*(h+a_max)

for i in range(h+a_max):
    dp[i] = min(dp[i-a] + b for a, b in zip(a, b))

print(min(dp[h-1:]))

Measured memory_bytes: 9552
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
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 (a > b){ a = b; return 1;}return 0;}
template <class T>
void printv(vector<T> v) {for (T t : v) {cout << t << " ";}cout << '\n';}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" <<endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int main()
{
    int n;
    cin >> n;
    vector<vector<pii>> l;

    REP(i,n) {
        int a;
        cin >> a;
        vector<pii> xy;
        REP(j,a) {
            int x, y;
            cin >> x >> y;
            x--;
            xy.emplace_back(pii(x,y));
        }
        l.emplace_back(xy);
    }

    // {0, 1, ..., n-1} の部分集合の全探索
    int ans = 0;
    for (int bit = 0; bit < (1<<n); ++bit)
    {
        vi trust(n, 0);
        vi test(n, -1);
        for (int i = 0; i < n; ++i) {
            if (bit & (1<<i)) { // i が bit に入るかどうか
                trust[i] = 1;
                for (pii ts : l[i]) if (ts.second == 1) trust[ts.first] = 1;
            }
        }

        bool ok = true;
        
        REP(i, n) {
            if (trust[i] != 1) continue;

            for (pii ts : l[i]) {
                if (test[ts.first] == -1) test[ts.first] = ts.second;
                else {
                    if (test[ts.first] != ts.second) ok = false;
                }
            }
            if(!ok) break;
        }

        REP(i, n) {
            if (trust[i] == 1 and test[i] == 0) ok = false;
            if (trust[i] == 0 and test[i] == 1) ok = false;
        }

        if(ok) {
            int tmp = 0;
            for (int p : trust) if (p == 1) tmp++;
            ans = max(ans, tmp);
        }

    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<random>
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
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; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e16;

lint K;
string s;
int main() {
	cin >> s >> K;
	REP(i, SZ(s)) {
		if (s[i] != 'a' && K >= 26 - (s[i] - 'a')) {
			K -= 26 - (s[i] - 'a');
			s[i] = 'a';
		}
	}
	s[SZ(s) - 1] = (s[SZ(s) - 1] + K % 26);
	cout << s << endl;
}


Measured memory_bytes: 3748
#include <iostream>
#include <algorithm>
using namespace std;
using ll = long long int;

ll X[100010];

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

    ll ans = 1LL << 60;
    for(int i=0; i<N-K+1; i++) {
        int l = i, r = i + K - 1;
        if(X[l] * X[r] >= 0) {
            ans = min(ans, max(abs(X[l]), abs(X[r])));
        }
        else {
            ll dist = max(X[l], X[r]) - min(X[l], X[r]);
            ans = min(ans, dist + abs(X[l]));
            ans = min(ans, dist + abs(X[r]));
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int[] a = new int[n];
      int[] b = new int[n];
      int count = 0;
      for(int i = 0;i < n;i++){
      	a[i] = sc.nextInt();
      }
      for(int i = 0;i < n;i++){
      	while(a[i]/2 == (double)a[i]/2){
          b[i]++;
          a[i] = a[i]/2;
        }
      }
      for(int i = 1;i < n;i++){
      	b[i] = Math.min(b[i],b[i-1]);
      }
      System.out.println(b[n-1]);
    }
}


Measured memory_bytes: 21716
# -*- coding: utf-8 -*-
 
nk = list(map(int,input().split()))

A = [0]*nk[0]

for i in range(nk[1]):
  d = int(input())
  #print(d)
  add_A = list(map(int,input().split()))
  #print(add_A)
  
  for j in range(d):
    A[ add_A[j]-1 ] += 1

#print(A)

ans = 0
for i in range(nk[0]):
  if( A[i]==0 ):
    ans += 1

print(ans)

Measured memory_bytes: 9200