akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

signed main() {
  init();
  ll H, W;
  cin >> H >> W;
  vector<vector<char>> m(H, vector<char>(W));
  rep(i, H) rep(j, W) cin >> m[i][j];

  rep(i, H) {
    rep(j, W) {
      if (m[i][j] == '#') {
        bool ok = false;
        if (0 <= i - 1 && m[i - 1][j] == '#') ok = true;
        if (i + 1 < H && m[i + 1][j] == '#') ok = true;
        if (0 <= j - 1 && m[i][j - 1] == '#') ok = true;
        if (j + 1 < W && m[i][j + 1] == '#') ok = true;

        if (!ok) {
          COUT("No");
          return 0;
        }
      }
    }
  }
  COUT("Yes");
  return 0;
}

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

const int nm = 2e5;
int n, m;

//union-find
int par[nm], des[nm];
int root(int v) {
	if (par[v] == v)
		return v;
	return root(par[v]);
}
void unite(int x, int y) {
	int rx = root(x);
	int ry = root(y);
	if (rx == ry)
		return;
	if (des[ry] > des[rx])
		swap(rx, ry);
	par[ry] = rx;
	des[rx] += des[ry] + 1;
}
void initUF() {
	for (int i = 0; i < nm; i++)
		par[i] = i;
}

int main() {
	initUF();
	cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		unite(a - 1, b - 1);
	}

	int m = 0;
	for (int i = 0; i < n; ++i) {
		m = max(m, des[i]);
	}
	cout << m + 1 << endl;
}


Measured memory_bytes: 5152
#include <bits/stdc++.h>
using namespace std;
     
int main() {
    int  N, K; 
    cin >> N >> K;
    int num = 1;

    for (int i = 0; i < N; i++) {
        if (num < K) num *= 2;
        else num += K;
    }

    cout << num << endl;
}


Measured memory_bytes: 384
/*********************************************************************
* AUTHOR : ANSHU KUMAR                                               *
* ABOUT :  IT DOESN'T MATTER HOW SLOW I GO, AS LONG AS I NEVER STOP  *
* INSTITUTION : IEM KOLKATA                                          *
**********************************************************************/

//try to think at least 30min(with full concentration).

#include <bits/stdc++.h>

using namespace std;

#define int             long long
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)     __builtin_ctzll(x)
#define MOD             1000000007
#define INF             1e18
#define PI              3.1415926535897932384626433832795
#define sp(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define endl            '\n'
#define da(arr,type,n)  type *arr=new type[n];


/********** Euclidean Algorithm for GCD **********/
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }



/********** Fast Power Exponentiation ***********/
int power(int a, int b) {
	int res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res % MOD * a % MOD) % MOD;
		a = (a % MOD * a % MOD) % MOD;
		b >>= 1;
	}
	return res;
}



/********** FAST I/O ************/
void fastIO()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}



/********** PROGRAM START ***********/

int32_t main()
{
	fastIO();
	int A, B, C;
	cin >> A >> B >> C;
	if ((A == 5 && B == 5 && C == 7) || (A == 5 && B == 7 && C == 5) || (A == 7 && B == 5 && C == 5))
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
	return 0;
}

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

int main(){
   int N, Y;
   cin >> N >> Y;
   bool flag = false;
   int x, y, z;
   for (int i=0; i<=2000; i++){
      if ((Y - 1000*N - 9000*i) % 4000 == 0){
         y = (Y - 1000*N - 9000*i) / 4000;
         x = i;
         z = N - x - y;
         if ((y >= 0) && (z >= 0)){
            flag = true;
            break;
         }
      }
   }
   if (flag){
      cout << x << " " << y << " " << z << std::endl;
   } else{
      cout << -1 << " " << -1 << " " << -1 << std::endl;
   }

}



Measured memory_bytes: 3568
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var abc [3]int
	var num = 3
	tmp, _ := reader.ReadString('\n')
	tmp = strings.Trim(tmp, "\n")
	tmpslice := strings.Split(tmp, " ")
	for i := 0; i < num; i++ {
		abc[i], _ = strconv.Atoi(tmpslice[i])
	}

	T := float64(abc[2]) + 0.5
	b := abc[1]
	a := abc[0]

	var count int
	for i := 1; i < int(T)/a+1; i++ {
		if T > 0 && T < float64(a*(i+1)) {
			count = i
			break
		} else if T < 0 {
			count = i - 1
			break
		}
	}

	fmt.Println(b * count)
	return

}


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

using namespace std;

typedef long long int Int;

Int ans[10];

int main(void)
{
    map<pair<int,int>,int> m;
    Int h,w,n;
    cin>>h>>w>>n;
    
    for(int i = 0;i < n;i++)
    {
	int a,b;
	cin>>a>>b;
	a--;
	b--;

	int dx[9] = {-2,-1,0,-2,-1,0,-2,-1,0};
	int dy[9] = {-2,-2,-2,-1,-1,-1,0,0,0};
	for(int s = 0;s < 9;s++)
	{
	    if(a+dx[s] < 0 || b+dy[s] < 0 || a+dx[s] > h-3 || b+dy[s] > w - 3)
		continue;
	    
	    pair<int,int> p;
	    p.first = a+dx[s];
	    p.second = b+dy[s];

	    m[p]++;
	}
    }

    
    for(map<pair<int,int>,int>::iterator it = m.begin();it != m.end();it++)
    {
	ans[it->second]++;
    }

    ans[0] = (h-2)*(w-2) - m.size();

    for(int i = 0;i < 10;i++)
	cout<<ans[i]<<endl;

    return 0;
}



Measured memory_bytes: 56448
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	a, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	s := sc.Text()
	if a >= 3200 {
		fmt.Println(s)
	} else {
		fmt.Println("red")
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
template<class T> bool chmax(T& a,T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a,T b) { if (a > b) { a = b; return true; } return false; }

int main() {
    int n;
    cin >> n;
    vector<long long> a(n);
    for (auto &e : a) cin >> e;
    
    map<long long, long long> mp;
    long long ans = 0;
    
    for (int i = 0; i < n; i++) {
        long long res = (i + 1) - a[i];
        ans += mp[res];
        mp[a[i] + (i + 1)]++;
    }
    
    cout << ans << '\n';
    
    return 0;
}

Measured memory_bytes: 27492
import java.util.*;
public class Main{
	static int[] A =new int[100000];
	static int n;
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		for(int i=0;i<n;i++){
			A[i]=sc.nextInt();
		}
		/*
		for(int i=0;i<n;i++){
			System.out.print(A[i] +" ");
		}
		*/
		
		int q = partition(0, n-1);
		for(int i = 0;i<n;i++){
			if(i != q){
				System.out.print(A[i]);
			}else{
				System.out.print("[" + A[i] + "]");
			}
			
			if(i < n - 1){
				System.out.print(" ");
			}
		}
		
		System.out.println();
		return;
	}
	
	public static int partition(int p, int r){
		int x, i, j, t;
		x= A[r];
		i = p - 1;
		for(j = p; j < r;j++){
			if(A[j] <= x){
				i++;
				t = A[i];
				A[i] = A[j];
				A[j] = t;
			}
		}
		t = A[i + 1];
		A[i + 1] = A[r];
		A[r] = t;
		return i + 1;
	}
}

Measured memory_bytes: 72372
package main

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

var sc *bufio.Scanner = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}()

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}
func main() {
	a := nextInt()
	s := nextString()
	if a < 3200 {
		s = "red"
	}
	fmt.Println(s)
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main() {
    string s,t;
    cin >> s >> t;
    bool Can = true;
    for(int i = 0; i < s.length(); ++i)
        if(s[i] != t[i]) {
            Can = false;
            break;
        }
    if(!Can) cout << "No\n";
    else {
        cout << "Yes\n";
    }
return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <cstdio>
#include <map>
#include <functional>
#include <algorithm>
#include <string.h>
#include <string>
#include <queue>
using namespace std;

typedef pair<int, int> P;
const int INF = 1<<29;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};

int w, h, ans, gx, gy;
int maze[32][32];

bool check(int x, int y){
	return x >= 0 && x < w && y >= 0 && y < h && maze[y][x] != 1;
}

void dfs(int n, int x, int y){
	if(n > 10)
		return;
	if(ans <= n)
		return;
	if(x == gx && y == gy){
		ans = n;
		return;
	}

	//cout << n << " " << x << " " << y << endl;
	for(int i = 0; i < 4; ++i){
		int nx = x + dx[i];
		int ny = y + dy[i];
		if(maze[ny][nx] == 1)
			continue;
		while(check(nx, ny) && !(gx == nx && gy == ny)){
			nx += dx[i];
			ny += dy[i];
		}
		if(gx == nx && gy == ny)
			dfs(n + 1, nx, ny);
		else if(nx < 0 || nx >= w || ny < 0 || ny >= h)
			continue;
		else{
			maze[ny][nx] = 0;
			dfs(n + 1, nx - dx[i], ny - dy[i]);
			maze[ny][nx] = 1;
		}
		
	}
}
int main() {
	
	while(cin >> w >> h && (w || h)){
		ans = INF;
		for(int i = 0; i < 32; ++i)
			for(int j = 0; j < 32; ++j)
				maze[i][j] = 1;
			
		for(int i = 0; i < h; ++i)
			for(int j = 0; j < w; ++j)
				cin >> maze[i][j];
		
		int sx, sy;
		for(int i = 0; i < h; ++i){
			for(int j = 0; j < w; ++j){
				if(maze[i][j] == 2){
					sx = j;
					sy = i;
				}
				else if(maze[i][j] == 3){
					gx = j;
					gy = i;
				}
			}
		}
		dfs(0, sx, sy);
		
		if(ans == INF)
			cout << "-1" << endl;
		else
			cout << ans << endl;
	}
    return 0;
}

Measured memory_bytes: 1164
#!/usr/bin/env pypy3

import sys
import math
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from fractions import gcd                    # for Python3.4.3


def main():
    mod = 1000000007                  # 10^9+7
    inf = float('inf')
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    n = ii()
    a = lmi()
    m = max(a)
    # corner case: all numbers are equal to zero
    if m == 0:
        print(0)
        exit(0)

    ans = 0
    for shift in range(int(math.log(m, 2)+1)):    # log2 は PyPy2.4.0 で使えない
        mask = 0b1 << shift
        # print(tuple(map(lambda x: (x&mask)>>shift, a)))
        count_one = tuple(map(lambda x: (x&mask)>>shift, a)).count(1)
        ans = (ans + int(pow(2, shift, mod)) * count_one * (n - count_one)) % mod
        # print(ans)
    print(ans)
    # TLE -> random_31 to random_35 system test cases


if __name__ == "__main__":
    main()

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

int main(){
		int n;
		int a[1000];
		int v;
		int c=0;

		scanf("%d",&n);
		for(int i=0 ; i<n ; i++) scanf("%d",&a[i]);

		for(int i=0 ; i<n ; i++){
				for(int j=n-1 ; j>i ; j--){
						if(a[j] < a[j-1]){
								v = a[j];
								a[j] = a[j-1];
								a[j-1] = v;
								c++;
						}
				}
		}
		for(int j=0 ; j<n-1 ; j++) printf("%d ",a[j]);
		printf("%d\n",a[n-1]);
		printf("%d\n",c);
		return 0;
}



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

int main(void)
{
    char ans[120],str[120],ring[220];
    
    scanf("%s%s",ring,str);
    
    strcpy(ans,ring);
    strcat(ring,ans);
    
    if(strstr(ring,str)!=NULL)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


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

using namespace std;

bool checkMonth (int a)
{
        if ((a >= 1) && (a <= 12))
        {
                return true;
        }
        return false;
}

bool checkYear (int a)
{
        if ((a >= 0) && (a <= 99))
        {
                return true;
        }
        return false;
}


int main()
{
        string s;
        cin >> s;

        string first = s.substr(0,2);
        string second = s.substr(2,3);

        int a = atoi(first.c_str());
        int b = atoi(second.c_str());

        if ((checkMonth(a) && checkYear(b)) && (checkMonth(b) && checkYear(a)))
        {
                cout << "AMBIGUOUS" << endl;
        }

        else if ((checkMonth(a) && checkYear(b)))
                {
                        cout << "MMYY" << endl;
                }
        else if ((checkMonth(b) && checkYear(a)))
                {
                        cout << "YYMM" << endl;
                }
        else
        {
                cout << "NA" << endl;
        }


        return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#define rep_r(i,s,n)for(ll i=n-1;i>=s;i--)

#define repe_r(i,s,n)for(ll i=s;i<=n;i++)
static const ll MOD = 1e9 + 7;
static const ll MAX_L = 1e9 + 7;

int main() {
	ll N; cin >> N;
	repe(h, 1, 3500) {
		repe(n, 1, 3500) {
			ll up = N * h*n;
			ll ud = 4 * h*n - N * n - N * h;

			if (ud != 0 && up % ud == 0 && up / ud > 0) {
				cout << h << " " << n << " " << up / ud << endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=2000+5;
int n,cnt;
long long sum;
int ans[N*N],num[N];
bitset<N*N> bt;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&num[i]),sum+=num[i];
	bt[0]=1;
	for(int i=1;i<=n;i++) bt=bt|bt<<num[i];
	for(int i=1;i<=sum;i++)
		if(bt[i]) ans[++cnt]=i;
	if(cnt%2==1) printf("%d",ans[(cnt+1)/2]);
	else printf("%d",ans[cnt/2]);
	return 0;
}

Measured memory_bytes: 11904
#include <algorithm>
#include <iostream>
#include <vector>

int main()
{
    int a, b, k;
    std::cin >> a >> b >> k;

    for (int i = a; i <= b; i++) {
        if (i - a + 1 <= k || b - i + 1 <= k) {
            std::cout << i << std::endl;
        }
    }
}


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

template<typename T, typename U> bool chmin(T &a, const U &b) {
	return (a > b ? a = b, true : false);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
	return (a < b ? a = b, true : false);
}

typedef long long ll;

#define writeln(n) cout<<n<<"\n";

typedef pair<int, int> P;
typedef pair<string, int> Psi;

ll numct[210000];
ll k[210000];
ll cnb[210000];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int a,b;
	cin>>a>>b;

	for(int i=1; i<=1250; i++){
		if(int(i*0.08) == a && int(i*0.1) == b ){
			writeln(i);
			return 0;
		}
	}

	writeln(-1);
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<iomanip>
using namespace std;
//int father[100001];
/*int cmp(wo a,wo b)
return a.   <b.   ;
*/
/*
void unionn (int x,int y){
x=find(x);y=find(y);
father[y]=x;
}
int find(int x)
{
if(father[x]!=x)father[x]=find(father[x]);
return father[x];
}
int judge(int a,int b){
if(find(a)!=find(b))return 0;
else return 1;
}
*/
/*
int dij(){
for(int i=1;i<=n;i++){
	for(int j=i+1;j<=n;j++){
		t++;
		dis[t].distance=0;
	   for(int k=0;k<7;k++){
	   	if(car[i][k]!=car[j][k]){
	   		dis[t].distance++;
		   }
	   }
	   dis[t].x=i;dis[t].y=j;
	}
}
for(int i=1;i<=n;i++){
	father[i]=i;
}
sort(dis+1,dis+t+1,cmp);
for(int i=1;i<=t;i++){
	if(find(dis[i].x)!=find(dis[i].y)){
		unionn(dis[i].x,dis[i].y);
		ans+=dis[i].distance;
	}
}
}
?
*/
int main(){
long long a[101111]={0},ans,n;
//char b[100001];
cin>>n;
/*for(int i=1;i<=n;i++){
cin>>a[i];
}*/
/*
if()cout<<"No";
else cout<<"Yes";
*/
cout<</*fixed<<setprecision()*/"ABC"<<n<<endl;
return 0;
}

Measured memory_bytes: 256
# coding: utf-8
import os
from sys import stdin

# __dirname = os.path.dirname(__file__)
# __basename = os.path.splitext(os.path.basename(__file__))[0]
# __targetname = './input/' + __basename + '.txt'
# target_path = os.path.join(__dirname, __targetname)
# stdin = open(target_path)

def main():
    input_line = stdin.readline().rstrip().split(' ')
    H,W = map(int, input_line)
    # data = [stdin.readline().rstrip().split(' ') for _ in range(N)]
    input_line = stdin.readline().rstrip().split(' ')
    h,w = map(int, input_line)
    print((H-h)*(W-w))

if __name__ == "__main__":
    main()
    

Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<math.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define N (1000000000+7)
#define INF (ll)1e16
typedef long long ll;
ll n,k;
vector<ll>g[100010];
ll node[100010]={0};

void dfs(ll now,ll root){
    if(root==0){
        if((ll)g[now].size()==1){
            node[g[now][0]]=k-1;
            dfs(g[now][0],now);
        }
        else{
            for(ll i=0;i<(ll)g[now].size();i++){
                ll next=g[now][i];
                if(k-i-1>0){
                    node[next]=k-i-1;
                    dfs(next,now);
                }
                else {
                    node[next]=0;
                    return;
                }
            }
        }
    }
    else{
        if((ll)g[now].size()==2){
            ll next = (g[now][0]==root)?g[now][1]:g[now][0];
            if(k-2>0){
                node[next]=k-2;
                dfs(next,now);
            }
            else {
                node[next]=0;
                return;
            }
        }
        else{
            if((ll)g[now].size()==1) {
                return;
            }
            else{
                ll num=0;
                for(ll i=0;i<(ll)g[now].size();i++){
                    ll next=g[now][i];
                    if(next==root)continue;
                    if(k-2+num>0){
                        ll x=k-2-num;
                        num++;
                        node[next]=x;
                        dfs(next,now);
                    }
                    else {
                        node[next]=0;
                        return;
                    }
                }
            }
        }
    }
}

int main(void){
    ll a,b,ans=1;
    cin>>n>>k;
    node[1]=k;
    for(int i=1;i<n;i++){
        cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(1,0);
    for(ll i=1;i<=n;i++){
        //cout<<node[i]<<endl;
        ans=(ans*node[i])%N;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 7284
#include "bits/stdc++.h"
using namespace std;

int main() {
	char forecast[3], wether[3];
	int result = 0;
	for (int i = 0; i < 3; i++) {
		cin >> forecast[i];
	}
	for (int i = 0; i < 3; i++) {
		cin >> wether[i];
		if (forecast[i] == wether[i]) {
			result++;
		}
	}
	cout << result << endl;
}

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

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

C1 = gets.chomp.split('')
C2 = gets.chomp.split('')
C3 = gets.chomp.split('')

puts C1[0] + C2[1] + C3[2]


Measured memory_bytes: 14304
import java.io.*;

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] f=br.readLine().split(" ");
        int n=Integer.parseInt(f[0]);
        int m=Integer.parseInt(f[1]);
        int l=Integer.parseInt(f[2]);
        int[][] A=new int[n][m];
        int[][] B=new int[m][l];
        for(int i=0;i<n;i++){
        	String[] s=br.readLine().split(" ");
        	for(int j=0;j<m;j++) A[i][j]=Integer.parseInt(s[j]);
        }
        for(int i=0;i<m;i++){
        	String[] t=br.readLine().split(" ");
        	for(int j=0;j<l;j++) B[i][j]=Integer.parseInt(t[j]);
        }
    	StringBuilder sb = new StringBuilder();
        for(int ni=0;ni<n;ni++){
        	for(int li=0;li<l;li++){
        		long b=0;
            	for(int mi=0;mi<m;mi++) b+=A[ni][mi]*B[mi][li];
            	sb.append(b);
            	if(li!=l-1) sb.append(" ");
        	}
        	sb.append("\n");
        }
    	System.out.print(sb);
	}
}

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

int main()
{
	char A;
	cin >> A;
	if (A == 'a' || A == 'i' || A == 'u' || A == 'e' || A == 'o') {
		cout << "vowel" << endl;
	}
	else {
		cout << "consonant" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}




// combination mod prime
// mintが必要
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main(){
    int n,k;
    cin >> n >> k;
    combination c(n);
    for(int i=1;i<=k;i++){
        mint a = c(n-k+1,i);
        mint b = c(k-1,i-1);
        mint ans = a*b;
        cout << ans << endl;
    }
    return 0;
}


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

using namespace std;

void solveA()
{
    int x;
    cin >> x;
    if (x == 7|| x == 5|| x == 3)
        cout << "YES\n";
    else
        cout << "NO\n";
}

void solveB()
{
    int a, b, c;
    cin >> a >> b >> c;

    int hp = max(a, b);
    hp = max(hp, c);

    int area;

    if (a == hp)
        area = (b * c) / 2;
    if (b == hp)
        area = (a * c) / 2;
    if (c == hp)
        area = (a * b) / 2;

    cout << area;
}

void solveC()
{
    int a, b;
    cin >> a >> b;
    if ((a*b) % 2 == 0)
        cout << "No\n";
    else
        cout << "Yes\n";
}

void solveD()
{
    int n, s=0, cp;

    cin >> n;
    cp = n;

    while (cp){
        s += cp%10;
        cp /= 10;
    }
    if (n % s == 0)
        cout << "Yes\n";
    else
        cout << "No\n";
}

void solveE()
{
    int n, t;

    cin >> n >> t;

    int rotas[n][2];

    int coast = INT_MAX;

    for (int i = 0; i < n; i++){

        cin >> rotas[i][0] >> rotas[i][1];

        if (rotas[i][1] < t){
            coast = min(coast, rotas[i][0]);
        }
    }
    if (coast == INT_MAX)
        cout << "TLE\n";
    else
        cout << coast << "\n";
}

void solveF()
{
    int k;
    cin >> k;
    int par = 0, impar = 0;
    for (int i = 1; i <= k ; i++){
        if (i % 2 == 0)
            par++;
        else
            impar++;
    }
    cout << par * impar << endl;
}

int main(int qtd, char* nome[])
{
    ios::sync_with_stdio(false);

    solveC();

    return 0;
}


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

int main() {
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    priority_queue<ll> pq;
    ll a[100001];
    int n, m; cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        pq.push(a[i]);
    }

    for (int i = 0; i < m; i++) {
        ll x = pq.top(); pq.pop();
        pq.push(x / 2);
    }

    ll sum = 0;
    while (!pq.empty()) {
        sum += pq.top(); pq.pop();
    }
    cout << sum << '\n';

    return 0;
}


Measured memory_bytes: 1912
#include <iostream>
using namespace std;
int main(void){
    int n;
    cin >> n;
    string s[n];
    for(int i=0;i<n;i++){
        cin >> s[i];
        if(i>0 && s[i][0]!=s[i-1].back()){
            cout << "No" << endl;
            return 0;
        }
        for(int j=i-1;j>=0;j--){
            if(s[i]==s[j]){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
signed main(){
  init_io();
  ll n,k;
  cin >> n >> k;
  vector<ll> d(k);
  vector<bool> check(n);
  ll ans = 0;
  for(int i=0;i<k;i++){
    cin >> d[i];
    ll v;
    for(int j=0;j<d[i];j++){
      cin >>v;
      v--;
      check[v] = true;
    }
  }
  for(int i=0;i<n;i++){
    if(!check[i]) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
#define INF (1e9)

int main() {
    ll A, B, C, D, ans = 0;
    cin >> A >> B >> C >> D;
    while (true) {
        C -= B;
        if (C <= 0) {
            cout << "Yes" << endl;
            return 0;
        }
        A -= D;
        if (A <= 0) {
            cout << "No" << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3640
using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharpSample01
{


    class Program
    {


        static long Knapsack(int N, int W, int[] value, int[] weight)
        {
            long[,] dp = new long[N + 1, W + 1];

            for (int w = 0; w <= W; w++)
            {
                dp[0, w] = 0;
            }

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

                for (int w = 0; w <= W; w++)
                {                    
                    if(w - weight[i] < 0)
                    {
                        dp[i, w] = dp[i - 1, w];
                    }                    
                    else
                    {
                        dp[i, w] = Math.Max(dp[i - 1, w], dp[i - 1, w - weight[i]] + value[i]);
                    }
                }

            }

            return dp[N, W];
        }


        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]);
            int W = int.Parse(input[1]);

            int[] v = new int[N + 1];
            int[] w = new int[N + 1];

            for (int i = 1; i <= N; i++)
            {
                input = Console.ReadLine().Split(' ');
                w[i] = int.Parse(input[0]);
                v[i] = int.Parse(input[1]);
            }

            Console.WriteLine(Knapsack(N, W, v, w));
        }
    }
}

Measured memory_bytes: 89440
S=input()
mod=10**9+7
dp=[0]*13
dp[0]=1
for i in range(len(S)):
  if S[i]=='?':
    dp=[sum(dp[4*(j-k)%13] for k in range(10))%mod for j in range(13)]
  else:
    a=int(S[i])
    dp=[dp[4*(j-a)%13]%mod for j in range(13)]
print(dp[5])

Measured memory_bytes: 9148
/*
─────────────────────
───────────████████──
──────────███▄███████
──────────███████████
──────────███████████
──────────██████─────
──────────█████████──
█───────███████──────
██────████████████───
███──██████████──█───
███████████████──────
███████████████──────
─█████████████───────
──███████████────────
────████████─────────
─────███──██─────────
─────██────█─────────
─────█─────█─────────
─────██────██────────
─────────────────────
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define int long long
#define read(a) int a; cin >> a;
#define readarr(a, n) int a[(n) + 1] = {}; fori(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; fori(i, 1, n) {fori(j, 1, m) cin >> a[i][j];}
#define pb push_back
#define fi first
#define se second
#define rz resize
#define fori(i, a, b) for(int i = a; i <= b; i++)
#define ford(i, a, b) for(int i = a; i >= b; i--)
#define sort1(v) sort(v.begin(), v.end()) 
#define endl '\n'

using namespace std;
using namespace __gnu_pbds; 

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair <int, int>> vpi;
typedef vector < vector <int> > vvi;

const long long inf2 = (long long)1e18;
const long long mod = (long long)(1e9+7);
const long long inf1 =(long long)(1e6+1);

int power(int x, int y, int p) 
{ 
    int res = 1;
    x = x % p; 
  
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p;   
    } 
    return res; 
}
 
signed main() 
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    read(n); readarr(a, n);
    int temp[n+1];
    fori(i, 1, n) temp[i] = a[i];

    int cnt[60] = {};

    fori(i, 1, n)
    {
        fori(j, 0, 59) 
        {
            if(temp[i]%2 == 1) cnt[j]++;
            temp[i] /= 2;
        }
    }

    int ans = 0;

    fori(i, 1, n-1)
    {
        fori(j, 0, 59)
        {
            int bit = a[i]%2;
            if(bit == 1) 
            {   
                cnt[j]--;
                ans = (ans+(power(2, j, mod)*((n-i-cnt[j])%mod))%mod)%mod;
            }
            else ans = (ans+(power(2, j, mod)*(cnt[j]%mod))%mod)%mod;
            a[i] /= 2;
        }
    }

    cout << ans;
    return 0;
}

Measured memory_bytes: 4992
N,K=map(int,input().split())

td=sorted([tuple(map(int,input().split())) for _ in range(N)],key=lambda x:-x[1])
answer=0
number=set()
afterpop=[]

for i in range(K):
  answer+=td[i][1]
  if td[i][0] not in number:
    number.add(td[i][0])
  else:
    afterpop.append(td[i][1])

answer+=(len(number))**2
    
index=K
tempanswer=answer
while index<N and afterpop:
  if td[index][0] not in number:
    number.add(td[index][0])
    tempanswer=tempanswer+td[index][1]-afterpop.pop()-(len(number)-1)**2+(len(number))**2
    answer=max(tempanswer,answer)
  index+=1
                  
print(answer)

Measured memory_bytes: 22160
#include <bits/stdc++.h>
using namespace std;
#define fastt ios_base::sync_with_stdio(false);cin.tie(NULL);
#define enl "\n"
#define ll long long
#define pb push_back
#define fi first
#define se second
#define vvi vector<vector<ll>> 
#define vi vector<ll> 
#define vpii vector<pair<ll,ll>>
#define all(x) x.begin(),x.end()
#define ffor(i,n) for(ll i = 0; i < n; ++i)
#define PI 3.14159265 

int main() {
    fastt;
    double a,h,v;
    cin>>a>>h>>v;
    double i,j;
    j=a*a*h;
    if(j>2*v){
        i=a*h*h/(2*v);
    }
    else{
    v=j-v;
    i=2*v/(a*a*a);
    }
     i = atan(i); 
     i = (i * 180) / PI; 
    cout << fixed << setprecision(7)<<i<<enl;
    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <numeric>
#include <map>   
#include <stdio.h>
#include <queue>

#define FOR(i,a,b) for(i=(a);i<(b);++i) 
#define FORR(i,a,b) for(i=(a);i>(b);--i)
#define REP(i,n) for(i=0;i<(n);++i)
#define REPR(i,n) for(i=(n);i>0;--i)
#define PB push_back
#define ull unsigned long long
#define ll long long
#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807
#define sortR(a,b) sort(a, b, greater<int>())

using namespace std;


int main() {
	vector<vector<pair<int, int>>> adjlist(100000, vector < pair<int, int>>());
	int N, M, i, l, r, lmax = 0, rmin = 100001;
	cin >> N >> M;
	REP(i, M) {
		cin >> l >> r;
		lmax = max(lmax, l);
		rmin = min(rmin, r);
	}
	cout << max(0, (rmin - lmax + 1)) << endl;
	return 0;

}



Measured memory_bytes: 2560
//control+option+n to run!
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define NEGFOR(i, a, b) for (ll i = (a); i > (b); i--)
#define vll vector<long long>
#define sll set<long long>
#define ld long double
#define inf 1000000000000000000;
#define mll multiset<long long>
#define nn << "\n"
#define F(i, b) for (ll i = 0; i < b; i++)
ll numbers[100005][3];

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin >> n;

  FOR(i, 0, n)
  {
    FOR(j, 0, 3)
    {
      cin >> numbers[i][j];
    }
  }

  ll dp[n][3];
  FOR(i, 0, n)
  {
    dp[i][0] = -inf;
    dp[i][1] = -inf;
    dp[i][2] = -inf;
  }
  dp[0][0] = numbers[0][0];
  dp[0][1] = numbers[0][1];
  dp[0][2] = numbers[0][2];

  FOR(i, 1, n)
  {
    FOR(j, 0, 3)
    {

      FOR(k, 0, 3)
      {
        if (k!=j){
          dp[i][j]=max(dp[i-1][k],dp[i][j]);
        }
      }
      dp[i][j]+=numbers[i][j];
    }
  }

  cout << max(max(dp[n - 1][0], dp[n - 1][1]), dp[n - 1][2]);

  cout << "\n"; //GET RID OF THIS FOR THE ACTUAL PROGRAM!!!!
}


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

int main() {
    int N,Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    vector<int> pos(N-1);
    for ( int i = 0; i < N-1; ++i){
        if ( S[i] == 'A' and S[i+1] == 'C' ){
            pos[i] = 1;
        }
    }
    vector<int> sum(N,0);
    sum[0] = 0;
    for ( int i = 1; i < N; ++i){
        sum[i] = sum[i-1] + pos[i-1];
    }
    
    for ( int i = 0; i < Q; ++i){
        int l,r;
        cin >> l >> r;
        --l; --r;
        int num;
        if ( l == 0 ) {
            num = sum[r];
        } else {
            num = sum[r] - sum[l-1];
            if ( S[l] == 'C' and S[l-1] == 'A' ) --num;
        }
        
        cout << num << endl;
    }
    
    return 0;
}


Measured memory_bytes: 4232
#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;

int main() {
	int len, ans = 0, temp;
	char s[15];
	scanf("%s", s);
	len = strlen(s);
	for (int i = 0; i < len; i++) {
		temp = 0;
		while ((i < len) && ((s[i] == 'A') || (s[i] == 'C') || (s[i] == 'G') || (s[i] == 'T'))) {
			i++;
			temp++;
		}
		ans = max(ans, temp);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdint.h>
#define MOD 1000000007

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

  int64_t POW = 1;
  for(int i = 1; i <= N; i++) {
    POW = POW * i % MOD;
  }
  printf("%ld\n", POW);
  return 0;
}


Measured memory_bytes: 128
/*
	Copyright: razouq (c)
	Author: Anass BENDARSI
	Date: 04/11/2018 13:02:35
	flamers will **** you
*/
//#include<flamers.h>

#include "bits/stdc++.h"
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#define ll long long
#define ull unsigned long long
#define F first
#define S second
#define PB push_back
#define POB pop_back

using namespace std;


int main(){
//	freopen("input.in", "r", stdin);
//	freopen("output.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie();
	int a, b;
	cin>>a>>b;
	cout<<a + b / 2<<endl;
	return 0;
}


Measured memory_bytes: 256
// i hope i get better                                                           
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int sz=1e5+9;
int n,m,k;
int a,b;
int loved[sz];
vector<pii> bk;
int p[sz],s[sz];
int ans[sz];

int findp(int a){
    return (a==p[a]?a:(p[a]=findp(p[a])));  // note that this is faster than the iterative method as this one assigns findp(p[a]) to p[a] directly
}

bool same(int a,int b){
    a=findp(a);
    b=findp(b);
    return a==b;
}


void unite(int a,int b){
    a=findp(a);
    b=findp(b);
    p[b]=a;
    s[a]+=s[b];
    return;
}

int main(){
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++) {p[i]=i;s[i]=1;}
    for(int i=0;i<m;i++){
        cin>>a>>b;
        if(!same(a,b)) unite(a,b);
        loved[a]++;
        loved[b]++;
    }
    for(int i=0;i<k;i++){
        cin>>a>>b;
        bk.pb(mp(a,b));
    }
    for(int i=1;i<=n;i++) ans[i]=s[findp(i)]-loved[i];
    for(auto u:bk){
        if(same(u.f,u.s)){
            ans[u.f]--;
            ans[u.s]--;
        }
    }
    for(int i=1;i<=n;i++) cout<<ans[i]-1<< " ";
    return 0;
}

Measured memory_bytes: 3956
#include <cstdio>
#include <cstdlib>
int main()
{
//    freopen("Product.in","r",stdin);
//    freopen("Product.out","w",stdout);
    
    int a,b;
    scanf("%d%d",&a,&b);
    if((a*b)%2==0) printf("Even");
    else printf("Odd");
    
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int inf = 1 << 20;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using namespace std;


int main()
{
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    string k = "000";
    set<string> x;
    for(int i = 0; i < 1000; i++){
        k[0] += (i/100);
        k[1] += (i%100)/10;
        k[2] += (i%10);


        int cnt1 = 0,cnt2 = 0,cnt3 = 0;
        bool f1 = false,f2 = false, f3 = false;

        for(int j = 0; j < s.size(); j++){
            if(s[j] == k[0] && !f1 && !f2 && !f3){
                f1 = true;
                continue;
            }
            if(s[j] == k[1] && f1 && !f2 && !f3){
                f2 = true;
                continue;
            }
            if(s[j] == k[2] && f1 && f2){
                f3 = true;
                ans++;
                break;
            }
            
        }
        k = "000";
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
typedef long long ll;
#define fr first
#define sc second
#define int ll

using namespace std;
const int MN = 1e4+7;
const int MK = 1e2+7;
const int MOD = 1e9+7;

int d, dp[MN][MK];

signed main(){
    string s;
    cin >> s;
    cin >> d;
    /*if(d == 1){
        ll w = 0, x = 1;
        for(int i = s.size()-1; i >= 0; i--){
            w = (w + (s[i]-'0') * x) % MOD;
            x = (x * 10) % MOD;
        }
        cout << w;
        return 0;
    }*/
    dp[0][0] = 1;
    for(int j = 0; j < 10; j++){
        dp[1][j%d]++;
    }
    for(int i = 2; i < s.size()+3; i++){
        for(int j = 0; j < d; j++){
            for(int z = 0; z < 10; z++){
                dp[i][j] = (dp[i][j] + dp[i-1][(j-z+20*d)%d]) % MOD;
            }
        }
    }
    ll re = 0, f = 0;
    for(int i = 0; i < s.size(); i++){
        //cout << i << " :\n";
        for(int z = 0; z < s[i]-'0'; z++){
            //cout << z << ' ' << dp[s.size()-i-1][(d*20 - (f+z))%d] << " \n";
            re = (re + dp[s.size()-i-1][(d*20 - (f+z))%d]) % MOD;
        }
        f = (f + s[i]-'0') % d;
    }
    //cout << f << endl;
    if(f % d == 0)re++;
    cout << (re-1+MOD) % MOD;
}


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

using namespace std;
typedef long long ll;

void solve(){
    int n;
    cin >> n;
    vector<ll> f(n + 1, 1);
    if(n < 3){
        cout << "0\n";
        return;
    }
    const ll M = 1e9 + 7;
    for(int i = 6; i <= n; ++i)
        for(int j = i - 3; j >= 3; --j)
            f[i] = (f[i] + f[j]) % M;
    cout << f[n] << "\n";
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T = 1;
    //cin >> T;
    while(T--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3620
import std.array, std.stdio, std.conv, std.string, std.math, std.random, std.range,std.functional;
import std.algorithm.searching, std.algorithm.sorting, std.algorithm.iteration, std.algorithm.comparison;
 
long count;
 
void main()
{
    readln();
    int[] list = readln().split.to!(int[]);
    auto sortedList = list.dup.sort();

    bool[] bList;
    long[][] cycleList;
    bList.length = list.length;

    foreach(i; 0..list.length)
    {
        if(bList[i])
            continue;
        long nextIndex = i;
        long[] cycle;
        while(true)
        {
            bList[nextIndex] = true;
            cycle ~= list[nextIndex];
            nextIndex = sortedList.countUntil(list[nextIndex]);
            if(i == nextIndex)
                break;
        }
        cycleList ~= cycle;
    }
    long min = sortedList[0];
    foreach(c; cycleList)
    {
        long cMin = c.reduce!"a<b?a:b";
        long a = cMin * (c.length - 2) + c.sum();
        long b = min * (c.length - 1) + c.sum() - cMin + (min+cMin)*2;
        count += a<b?a:b;
    }
    writeln(count);
}
 
sizediff_t minIndex(alias pred="a<b", R) (R list)
    if(isForwardRange!R && !isInfinite!R && is(typeof(binaryFun!pred(list.front, list.front))))
{
    assert(!list.empty);
    typeof(list.front) min = list.front;
    sizediff_t minPos;
    sizediff_t curPos;
    for(list.popFront(); !list.empty; list.popFront())
    {
        curPos++;
 
        if(binaryFun!pred(list.front, min))
        {
            min = list.front;
            minPos = curPos;
        }
    }
    return minPos;
}



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

int main(void)
{
   int a, b, c;
   int min;
   cin >> a >> b >> c;
   min = a + b;
   if(min > a+c){
       min = a+c;
   }
   if(min > b+c){
       min = b+c;
   }

   cout << min << endl;

   return 0;
}

Measured memory_bytes: 256
extern "C"{
int printf (const char *__restrict __format, ...);
int scanf (const char *__restrict __format, ...) ;
}
int max(int a,int b){
	return a>b?a:b;
}
int x[100000],y[100000],x_mod_k[100000],x_div_k[100000];
char s[100000][2];
int n,k;
 
void add(int*cnt,int x,int t){
	if((x_div_k[x]&1)==0){
		if(t==0){
			cnt[0]++;
			cnt[k-x_mod_k[x]]--;
		}
		else{
			cnt[k-x_mod_k[x]]++;
		}
	}
	else{
		if(t==0){
			cnt[k-x_mod_k[x]]++;
		}
		else{
			cnt[0]++;
			cnt[k-x_mod_k[x]]--;
		}
	}
}
int ans[2000];
int main(){
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%d%d%s",&x[i],&y[i],s[i]);
		x_mod_k[i]=y[i]%k;
		x_div_k[i]=y[i]/k;
	}
	int Max=0;
	//~ #pragma omp parallel for num_threads(2)
	for(int i=0;i<k;i++){
		int d=max(n,k);
		int cnt[d];
		for(int j=0;j<d;j++)cnt[j]=0;
		for(int j=0;j<n;j++){
			if(s[j][0]=='B'){
				if(((x[j]+i)/k)%2==0){
					add(cnt,j,0);
				}
				else{
					add(cnt,j,1);
				}
			}
			else{
				if(((x[j]+i)/k)%2==0){
					add(cnt,j,1);
				}
				else{
					add(cnt,j,0);
				}
			}
		}
		for(int j=0;j<k;j++){
			if(j)cnt[j]+=cnt[j-1];
			ans[i]=max(ans[i],max(cnt[j],n-cnt[j]));
		}
	}
	for(int i=0;i<k;i++)Max=max(Max,ans[i]);
	printf("%d\n",Max);
}

Measured memory_bytes: 2432
N = int(input())
S = [input() for i in range(N)]
s = sorted(S)
import collections
c = collections.Counter(s)
C = c.most_common()
 
a = C[0][1]
b = []
for i in range(len(C)):
  if a == C[i][1]:
    b.append(C[i][0])
  else:
    break
B = sorted(b)
 
for i in B:
  print(i)

Measured memory_bytes: 50772
import collections
import itertools
N=int(input())
di = dict()
l = list()
for i in range(N):
    l.append( input())

c = collections.Counter(l)
ct = c.most_common()
m = ct[0][1]
li = list()
for t in ct:
    if m == t[1]:
        li.append(t[0]) 
    else:
        break
lis = sorted(li)
for s in lis:
    print(s)


Measured memory_bytes: 49204
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;
const int INF= 1e9+5;
typedef long long ll;

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a+b>=c)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

int main(){
    int N;
    cin >> N;
    int x[N];
    int y[N];
    for(int i =0; i < N; i++){
        cin >> x[i] >> y[i];
    }
    double sum = 0;
    vector<double> disitance;
    for(int i =0; i < N-1; i++){
        for(int j = i + 1; j < N; j++){
            double d = sqrt((x[i]-x[j])*(x[i]-x[j])+ (y[i]-y[j])*(y[i]-y[j]));
            disitance.push_back(d);
        }
    }
    //sort(disitance.begin(), disitance.end());
    for(int i =0; i < disitance.size(); i++){
        sum += disitance.at(i);
    }
    cout << fixed << setprecision(10) << 2*sum/N << endl;
}

Measured memory_bytes: 256