akhauriyash/Code-Regression huggingface dataset:
from heapq import heappush, heappop
T = int(input())

def process(arr):
    arr.sort()
    baseS = 0
    diffS = 0
    q = []
    length = 0
    for K, L, R in arr:
        baseS += R
        diff = L - R
        heappush(q, diff)
        diffS += diff
        length += 1
        while length > K:
            d = heappop(q)
            diffS -= d
            length -= 1
    return baseS + diffS

for _ in range(T):
    N = int(input())
    arr1 = []
    arr2 = []
    for _ in range(N):
        K, L, R = list(map(int, input().split()))
        if L > R:
            arr1.append((K, L, R))
        else:
            arr2.append((N-K, R, L))
    print(process(arr1) + process(arr2))


Measured memory_bytes: 42532
#include<iostream>
#include<stdio.h>
#include<string>
using namespace std;

int main(){
    int alph[26];
    for (int i = 0; i < 26; i++)
    {
        alph[i] = 0;
    }
    
    char txt;
    while(cin >> txt)
    {
        if('A' <= txt && txt <= 'Z'){
            alph[txt - 'A']++;
        }else if('a' <= txt && txt <= 'z'){
            alph[txt - 'a']++;
        }
    }
    
    for (int i = 0; i < 26; i++)
    {
        printf("%c : %d\n", 'a'+i, alph[i]);
    }
    
    
    return 0;
}


Measured memory_bytes: 3140
#include<stdio.h>
int main(void)
{
  char s[6];
  
  scanf("%s", s);

if(s[2] == s[3] && s[4] == s[5])
{
  printf("Yes\n");
}
  else
  {
      printf("No\n");
  }
  
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
public class Main
{
    public static void main (String args[]) throws Exception
    {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int prod = (a % 2) *  (b % 2);
        if (prod == 0){
            System.out.println("Even"); 
        }else{
            System.out.println("Odd");
        }
    }
}


Measured memory_bytes: 23124
#include<iostream>

using namespace std;

int w[100000];
int n, k;

int count(long long P)
{
	int count = 0, i;
	long long Pn;
	for (i = k; i > 0; i--)
	{
		Pn = P;
		while (Pn - w[count] >= 0)
		{
			Pn -= w[count];
			count++;
			if (count == n)return count;
		}
	}
	return count;
}

int main()
{
	int i;
	long long max = 0, right, left, mid;
	cin >> n >> k;
	for (i = 0; i < n; i++)
	{
		cin >> w[i];
		if (max < w[i])max = w[i];
	}
	max *= n / k + 1;
	left = 0;
	right = max + 1;
	while (left < right)
	{
		mid = (left + right) / 2;
		if (count(mid) == n)right = mid;
		else
		{
			if (count(mid + 1) == n)
			{
				mid++;
				break;
			}
			else left = mid + 1;
		}
	}
	cout << mid << endl;
    return 0;
}

Measured memory_bytes: 1548
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<malloc.h>

int my_gets(char *buf,int nBuf,FILE *fp){
    int ch;

    while(--nBuf >0){
        ch=getc(fp);
        if(ch==EOF || ch=='\n')
            break;
        *(buf++)=(char)ch;
    }
    *(buf)='\0';

    return nBuf;
}

int IsPrime(int n){
    for(int i=2;i*i<=n;i++){
        if(n%i == 0)
            return 0;
    }
    return 1;
}

int main(void){
    int n,primes[1000]={0},factors[1000]={0},nPrime=0;
    unsigned long long cnt=1;

    scanf("%d",&n);
    if(n==1){
        puts("1");
        return 0;
    }
    
    for(int i=2; i<=n; i++){
        if(IsPrime(i)){
            primes[nPrime++]=i;
        }
    }
    
    for(int i=2; i<=n; i++){
        int tmp=i;
        for(int j=0; primes[j]<=tmp && j<nPrime; j++){
            while(tmp%primes[j] == 0){
                //printf("tmp:%d p:%d\n",tmp,primes[j]);
                factors[j]++;
                tmp/=primes[j];
            }
        }
        //printf("%d\n",i);
    }
    for(int i=0;i<nPrime;i++){
        cnt *= factors[i]+1;
        cnt %= 1000000007ull;
    }
    printf("%llu\n",cnt);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend();
#define sz  size()
#define forr(i,a,b) for(int i=a ;i <= b ; i++ )
#define inp ios_base::sync_with_stdio(false);cin.tie(NULL);
#define PQ_INC vector<int>, greater<int> ;
using namespace std ;

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

const int N = 1e5+9 ,  mod = 1e7+9  , OO = 0x3f3f3f3f ;
int dX[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dY[] = {0, 0, 1, -1, 1, -1, 1, -1};
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
ll ok (ll n){
switch(n%4){
case 0: return n;
case 1: return 1;
case 2: return n+1;
default: return 0;
}
}
ll a , b ;
int main(){
  cin >> a >> b ;
 if (a> 1) cout <<(ok(b) ^ ok(a-1)) ;
 else cout  << ok(b) ;
}


Measured memory_bytes: 384
from sys import stdin
n = int(stdin.readline())
v = [[0] * (n + 1) for i in range(n + 1)]
for u in range(1, n + 1):
    U = [int(j) for j in stdin.readline().split()]
    for k in U[2:]:
        v[u][k] += 1
for i in range(1, n + 1):
    print(*v[i][1:])

Measured memory_bytes: 8524
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N, D;
  cin >> N >> D;
  vector<vector<int>> X(N, vector<int>(D));
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < D; ++j)
      cin >> X[i][j];

  int ans = 0;
  for (int i1 = 0; i1 < N; ++i1) {
    for (int i2 = i1 + 1; i2 < N; ++i2) {
      int dis = 0;
      for (int j = 0; j < D; ++j)
        dis += abs(X[i1][j] - X[i2][j]) * abs(X[i1][j] - X[i2][j]);

      for (int n = 0; n * n <= dis; ++n)
        if (n * n == dis)
          ++ans;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
{-# LANGUAGE FlexibleInstances    #-}
{-# LANGUAGE TypeSynonymInstances #-}

import           Control.Applicative
import           Control.DeepSeq
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                  as A
import qualified Data.Array.IArray           as IA
import qualified Data.Array.IO               as AI
import qualified Data.Array.MArray           as MA
import qualified Data.Array.ST               as STA
import qualified Data.Array.Unboxed          as AU
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import qualified Data.Graph                  as G
import           Data.Int
import qualified Data.IntMap                 as IM
import qualified Data.IntSet                 as IS
import           Data.List
import qualified Data.Map.Strict             as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Sequence               as SQ
import qualified Data.Set                    as S
import           Data.Time
import qualified Data.Tree                   as T
import qualified Data.Vector                 as V
import qualified Data.Vector.Mutable         as VM
import qualified Data.Vector.Unboxed         as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt :: IO [Int]
readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readInteger :: IO [Integer]
readInteger = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegers :: Int -> IO [[Integer]]
readIntegers n = replicateM n readInteger

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

count :: Eq a => a -> [a] -> Int
count a as = length $ filter (== a) as

put :: Show a => a -> IO ()
put = putStr . show

putLn :: Show a => a -> IO ()
putLn = print

putList :: Show a => [a] -> IO ()
putList [n] = put n
putList (n:ns) = do
  put n
  putStr " "
  putList ns

putStrList :: [String] -> IO ()
putStrList [n] = putStr n
putStrList (n:ns) = do
  putStr n
  putStr " "
  putStrList ns

main = do
  n <- readInt
  let m = maximum n
   in if m > 8
        then putStrLn ":("
        else putStrLn "Yay!"


Measured memory_bytes: 380
def main():
    from math import sqrt
    N = int(input())

    def prime_factorization(n):
        facts = []
        for i in range(2, int(sqrt(n)) + 5):
            while n % i == 0:
                n //= i
                facts.append(i)
        if n != 1:
            facts.append(n)
        return facts

    ans = 0
    facts = sorted(set(prime_factorization(N)))
    for f in facts:
        i = 1
        while N % (f**i) == 0:
            N //= f**i
            i += 1
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()


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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORTASC(c) sort((c).begin(),(c).end())
#define SORTDESC(c,t) sort((c).begin(),(c).end(), std::greater<t>());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define VMAX(a) *max_element(ALL(a))
#define VMIN(a) *min_element(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double PI  = acos(-1.0);

using ll = long long;
using namespace std;

int main() {
    ll n, a, b;
    ll base[10];
    ll p[10];
    ll q[10];
    
    cin >> n;

    REP(i, n){
        cin >> p[i];
        base[i] = i+1;
    }

    REP(i, n){
        cin >> q[i];
    }

    ll c = 1;
    do{
        ll isMatchP = 1;
        ll isMatchQ = 1;
        REP(i, n){
            if (base[i] != p[i]){
                isMatchP = 0;
            }
            if (base[i] != q[i]){
                isMatchQ = 0;
            }
        }

        if (isMatchP == 1){
            a = c;
        }
      	
      	if (isMatchQ == 1){
            b = c;
        }

        c++;
    } while (next_permutation(base, base+n));

    cout << abs(a-b) << endl;

    return 0;
}

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

using namespace std;

int main(void) {
    string s, t;
    cin >> s >> t;
    vector<vector<int>> dp (s.size() + 1, vector<int> (t.size() + 1, 0));
    
    for(int i = 1; i <= s.size(); ++i) {
        for(int j = 1; j <= t.size(); ++j) {
            if(s[i - 1] == t[j - 1]) {
                dp[i][j] = dp[i - 1][j - 1] + 1;
            } else {
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }
    int i = s.size();
    int j = t.size();
    if(dp[i][j] == 0) return 0;
    string r (dp[s.size()][t.size()], ' ');
    int on = r.size() - 1;
    while (on >= 0)
    {
        if(s[i - 1] == t[j - 1]) {
            r[on--] = s[i - 1];
            --i;
            --j;
        }
        else if(dp[i][j - 1] > dp[i - 1][j]) --j;
        else --i;
    }

    cout << r << '\n';
}

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

int		main(void)
{
	set<int> nums;
	int n;

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

		cin >> tmp;
		nums.insert(tmp);
	}
	cout << (*rbegin(nums) - *begin(nums)) << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
int main() {
  string s;
  int nq;
  cin >> s >> nq;
  string l = "";
  bool flg = 0;
  int cnt = 0;
  rep(i, nq) {
    int t;
    cin >> t;
    if(t == 1) {
      flg ^= 1;
    }
    if(t == 2) {
      int f;
      char c;
      cin >> f >> c;

      if(flg ^ (f % 2))
        l = c + l;
      else
        s = s + c;
    }
  }
  s = l + s;
  if(flg) reverse(all(s));
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 1488
n = int(input())
x = list(input() for i in range(n))
bw = 0
e = 'Yes'
for j in x:
    if bw == 0:
        bw = j
        if n != len(set(x)):
            e = 'No'
            break
    else:
        if bw[-1] != j[0]:
            e = 'No'
            break
        bw = j
print(e)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int n;
int main()
{
	scanf("%d",&n);
	int m=n;
	while(m%2==0)m/=2;
	if(m==1)
	{
		puts("No");
		return 0;
	}
	if(n%2==0)m=n-1;else m=n;
	puts("Yes");
	printf("%d %d\n",n+1,n+3);
	for(int i=2;i<=m;i+=2)
		printf("1 %d\n%d %d\n1 %d\n%d %d\n",i,i,i+n+1,i+1,i+n,i+1);
	if(n%2==0)
		for(int i=2;i<n;i++)
			if((n^i^1)<n&&(n^i^1)>1)
			{
				printf("%d %d\n%d %d\n",n,i,n*2,(n^i^1));
				break;
			}
	return 0;
}

Measured memory_bytes: 2304
import java.util.*;

public class Main {

    static int N;
    static long[] a;
    static long[][] dp;
    static long INF = Long.MAX_VALUE;

    static long dp(int left, int right) {
        if (dp[left][right]!=INF) return dp[left][right];
        int flag = 1;
        if ((N-left-right)%2==0) flag*=-1;

        if (left==right) {
            dp[left][right] = flag*a[left];
            return flag*a[left];
        }

        long tmp = -INF;
        if (flag==1) {
            tmp = Math.max(a[left]+dp(left+1, right), a[right]+dp(left, right-1));
        } else { // flag=-1
            tmp = Math.min(-a[left]+dp(left+1, right), -a[right]+dp(left, right-1));
        }
        dp[left][right] = tmp;
        return tmp;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        N = Integer.parseInt(sc.next());
        a = new long[N];
        dp = new long[N][N];
        for (int i=0;i<N;i++) {
            for (int j=0;j<N;j++) {
                dp[i][j] = INF;
            }
        }
        for (int i=0;i<N;i++) {
            a[i] = Integer.parseInt(sc.next());
        }
        System.out.println(dp(0, N-1));
    }
}

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

typedef struct
{
  char name[100];
  int number;
}quu;

  quu A[1000000];
  int tail=0,head=0;
  int n,q;

void enqueence(quu x)
{
  A[tail]=x;
  tail=(tail+1)%1000000;
}

quu dequeue()
{
  quu x=A[head];
  head=(head+1)%1000000;
  return x;
}

int min(int a,int b)
{
  if(a<b)return a;
  else return b;
}
  
int main()
{
  cin>>n>>q;
  tail=n;
  head=0;
  quu u;
  int time=0;
  int save;
  for(int i=0;i<n;i++)
  {
    cin>>A[i].name;
    cin>>A[i].number;
  }
  while(tail!=head)
  {
    u=dequeue();
    save=min(q,u.number);
    u.number-=save;
    time+=save;
    if(u.number>0)enqueence(u);
    else
    {
      cout<<u.name<<" "<<time<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 22312
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f3f3f3f3fLL
#define SIZE 8080
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD=1e9+7;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
int N,M;

int main(){
	string s;
	int K;
	cin>>s>>K;
	set<string> hoge;
	for(int j=1;j<=K;j++){
		for(int i=0;i<s.size()-j+1;i++){
			string fuga=s.substr(i,j);
			hoge.insert(fuga);
		}
	}
	set<string>::iterator itr=hoge.begin();
	for(int i=0;i<K-1;++i){++itr;}
	cout<<*itr<<endl;
}

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


int main() {
    int x;
    cin >> x;
    int ans;
    if (x >= 1800) ans = 1;
    else if (x >= 1600) ans = 2;
    else if (x >= 1400) ans = 3;
    else if (x >= 1200) ans = 4;
    else if (x >= 1000) ans = 5;
    else if (x >= 800) ans = 6;
    else if (x >= 600) ans = 7;
    else if (x >= 400) ans = 8;
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
import Control.Monad
import Data.List
import Data.Bits
import Debug.Trace
import Data.Maybe
import qualified Data.ByteString.Char8 as C

main :: IO ()
main = do
  [a, b, c] <- readInts
  print $ solve a b c

solve :: Int -> Int -> Int -> Int
solve a b c = min (b `div` a) c

-- 以下ライブラリ

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

readNInts :: Int -> IO [[Int]]
readNInts = flip replicateM readInts

readIntegers :: IO [Integer]
readIntegers = map (fst . fromJust . C.readInteger) . C.words <$> C.getLine

readNIntegers :: Int -> IO [[Integer]]
readNIntegers = flip replicateM readIntegers

getNLns :: Int -> IO [String]
getNLns = flip replicateM getLine

Measured memory_bytes: 380
import sys
import collections

input = sys.stdin.readline

N, K = map(int, input().split())
A = list(map(int, input().split()))
li = []
ans = 0

B = set(A)

cnt = len(B)

#for x in B:
#    a = A.count(x)
#    li.append(a)

li = list(collections.Counter(A).values())
li = sorted(li)

if cnt - K > 0:
    for x in range(cnt - K):
        ans += li[x]
    print(ans)

else :
    print(ans)

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

int main() {
	int n;
	scanf("%d", &n);
	int ans = 0;
	int k = 1;
	for(int i = 0; i < n; i++) {
		int a;
		scanf("%d", &a);
		if(a != k) {
			ans++;
		}else {
			k++;
		}
	}
	if(ans == n) {
		printf("%d\n", -1);
	}else {
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 256
N = int(input())
S = input()

S = list(S)
isA = False
isB = False
count = 0

for i in S:
    if i == 'A':
        isA = True
        isB = False
    elif i == 'B' and isA:
        isA = False
        isB = True
    elif i == 'C' and isB:
        count += 1
        isA = False
        isB = False
    else:
        isA = False
        isB = False
print(count)

Measured memory_bytes: 38256
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
char d[100][100],c;
int w,h;
void erase(int i,int j) {
  d[i][j]=' ';
  if (j>0) if (d[i][j-1]==c) erase(i,j-1);
  if (j<w-1) if (d[i][j+1]==c) erase(i,j+1);
  if (i>0) if (d[i-1][j]==c) erase(i-1,j);
  if (i<h-1) if (d[i+1][j]==c) erase(i+1,j);
  return;
}
int main() {
 int i,j,n;
 while (cin >> h >> w) {
	 if (w==0) break;
	 for (i=0;i<h;i++) cin >> d[i];
     n=0;
	 for (i=0;i<h;i++) for (j=0;j<w;j++) if (d[i][j]!=' ') { n++; c=d[i][j]; erase(i,j);}
	 cout << n << endl;
 }
 return 0;	
}

Measured memory_bytes: 1940
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep(i,n) FOR(i,0,n-1)
#define int long long
#define MOD 998244353
#define MAXN  100005
#define P pair<int,int>

int c[505],s[505],f[505];

signed main(){
	
	int n,y;cin>>n>>y;
		
	rep(i,n+1)rep(j,n-i+1) if(10000*i+5000*j+1000*(n-i-j) == y)
	{
		cout << i << " " << j << " " << n-i-j << endl;
		return 0;
	}
	
	
	cout << -1 << " " << -1<< " " << -1 << endl;
	
}
 

Measured memory_bytes: 256
import math
import sys

def p(n, r):
	if n < r:
		return 1
	return math.factorial(n) // math.factorial(n - r)

def main():
	input = sys.stdin.readline
	N,K = map(int,input().split())
	E = [[] for _ in range(N)]
	MOD = 10**9+7
	#辺の定義
	for _ in range(N-1):
	  u,v = map(int,input().split())
	  u -= 1
	  v -= 1
	  E[u].append(v)
	  E[v].append(u)

	if N == 1:
		print(K)
		sys.exit()
	#colorが塗られたかどうか
	color = [-1 for _ in range(N)]
	dp = [-1 for _ in range(N)]
	#dfsで色を塗っていく
	stack = []
	color[u] = 1
	ans = K
	for i,v in enumerate(E[u]):
		stack.append(v)
		ans *= (K-i-1)
		ans %= MOD

	while stack:
		u = stack.pop()
		color[u] = 1
		length = 0
		for v in E[u]:
			if color[v] == -1:
				stack.append(v)
				length += 1
		if dp[length] == -1:
			tmp = 1
			for i in range(K-1-length,K-1):
				tmp *= i
				tmp %= MOD
			#tmp = p(K-2,length) % MOD
			ans *= tmp
			dp[length] = tmp
		else:
			ans *= dp[length]
		ans %= MOD

	#各頂点の色を出力
	print(ans%MOD)

if __name__ == '__main__':
	main()

Measured memory_bytes: 24452
package main

import (
	"fmt"
)

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

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

func main() {
	var n, k int
	var s string
	fmt.Scan(&n, &k, &s)

	block := make([]int, 0, n)
	cnt := 0
	cur := 1
	for _, c := range s {
		if c == rune(cur)+'0' {
			cnt++
		} else {
			block = append(block, cnt)
			cur = 1 - cur
			cnt = 1
		}
	}
	if cnt > 0 {
		block = append(block, cnt)
	}
	if len(block)%2 > 0 {
		block = append(block, 0)
	}

	sum := make([]int, len(block)+1)
	sum[0] = 0
	for i := 0; i < len(block); i++ {
		sum[i+1] = sum[i] + block[i]
	}

	ans := 0
	length := 2*k + 1
	for i := 0; i < len(block); i += 2 {
		left := i
		right := min(i+length, len(block))
		ans = max(ans, sum[right]-sum[left])
	}
	fmt.Println(ans)
}


Measured memory_bytes: 2816
# -*- coding: utf-8 -*-
from itertools import product, combinations
from operator import itemgetter
def inpl(): return tuple(map(int, input().split()))

N, K = inpl()
X = []
Y = []
Px = []
Py = []

for i in range(N):
    x, y = inpl()
    X.append(x)
    Y.append(y)
    Px.append((x, i))
    Py.append((y, i))

X = sorted(X)
Y = sorted(Y)

dX = {x:i for i, x in enumerate(X)}
dY = {y:i for i, y in enumerate(Y)}
Px = sorted(Px)
Py = sorted(Py)

get = itemgetter(1)
res = 5 * 10**18

for (l, r), (d, u) in product(combinations(X, 2), combinations(Y, 2)):
    if (dX[r] - dX[l] < K-1) or (dY[u] - dY[d] < K-1):
        continue
    if res < (r-l)*(u-d):
        continue

    sx = set(map(get, Px[dX[l]:dX[r]+1]))
    sy = set(map(get, Py[dY[d]:dY[u]+1]))
    if len(sx.intersection(sy)) >= K:
        res = min(res, (r-l)*(u-d))

print(res)

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>

int main(void) {
    int v[3];
    std::cin >> v[0] >> v[1] >> v[2];
    std::sort(v, v+3);
    std::cout << v[0] << ' ' << v[1] << ' ' << v[2] << std::endl;
    return 0;
}



Measured memory_bytes: 3168
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)


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

	ll K, A, B;
	cin >> K >> A >> B;
	if (K <= A - 1)puts(A);
	else if (B <= A + 2)puts(K + 1);
	else {
		ll cnt = K - (A - 1);
		if (cnt % 2 == 0)puts(A + (B-A)*cnt/2);
		else puts(A + (B-A)*(cnt-1)/2 + 1);
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int a = x2 - x1, b = y2 - y1;
    cout << x2 - b << " " << y2 + a << " "
        << x1 - b << " " << y1 + a << endl;
}

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

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template <typename T> using pq = priority_queue<T>;
template <typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template <typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for (auto &i : mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template <class T> ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template <class T> istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template <class T> ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll n, k;
    cin >> n >> k;
    vl a(n);
    cin >> a;
    rep(i, n) {
        if (i + 1 - k <= 0) continue;
        if (a[i  - k] >= a[i])
            cout << "No" << '\n';
        else
            cout << "Yes" << '\n';
    }
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}


Measured memory_bytes: 4832
#include <bits/stdc++.h>
using namespace std;
 
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;
 
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;
 
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;
 
#define _  %  MOD
#define __ %= MOD
 
#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))
 
#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(ll i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(ll i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
#define fbo find_by_order
#define ook order_of_key
 
ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=(res*x)%INF;y=y>>1;x=(x*x)%INF;}return res%INF;} // modular exponent
const int maxn=3e5+5;
ll track[maxn][65];
ll n;
ll a[maxn];
ll f(ll bit,ll x,ll y)
{
	return track[y][bit]-track[x-1][bit];
}
int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
    cin>>n;
	repA(i,1,n)
	{
		cin>>a[i];
		ll idx=0;
		ll val=a[i];
		while(val)
		{
			track[i][idx++]=val%2;
			val/=2;
		}
	}
	repA(i,1,n)
	{
		rep(j,61)
		{
			track[i][j]+=track[i-1][j];
		}
	}
	ll ans=0;
	repA(i,1,n-1)
	{
		rep(j,61)
		{
			if(f(j,i,i)==0)
			{
				ll num=f(j,i+1,n);
				ans+=(num*power(2,j))%INF;
				ans%=INF;
			}
			else
			{
				ll num=f(j,i+1,n);
				num=(n-i)-num;
				ans+=(num*power(2,j))%INF;
				ans%=INF;
			}
		}
	}
	cout<<ans<<'\n';
	return 0;
}
// JUST ASK YOURSELF DID YOU GIVE YOUR BEST ? ISSE ZYADA
// KUCH KAR BHI NAHI SAKTE !! ENJOY AND GIVE YOUR BEST!!



Measured memory_bytes: 158292
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using VV = vector<vector<T>>;
using P = pair<int, int>;

int main() {
  int n, m, p;
  scanf("%d %d %d", &n, &m, &p);
  VV<P> e(n);
  VV<int> pr(2, vector<int>(n)), re(n);
  vector<int> a(m), b(m), c(m), r(n);
  for(int i = 0; i < m; i++) {
    scanf("%d %d %d", &a[i], &b[i], &c[i]);
    e[--a[i]].push_back(P(--b[i], 0));
    re[b[i]].push_back(a[i]);
  }
  queue<int> que;
  que.push(0);
  while(que.size()) {
    auto q = que.front();
    que.pop();
    if(pr[0][q]) continue;
    pr[0][q] = 1;
    for(auto x : e[q]) que.push(x.first);
  }
  que.push(n - 1);
  while(que.size()) {
    auto q = que.front();
    que.pop();
    if(pr[1][q]) continue;
    pr[1][q] = 1;
    for(auto x : re[q]) que.push(x);
  }
  for(int i = 0; i < n; i++) r[i] = pr[0][i] && pr[1][i];
  e = VV<P>(n);
  for(int i = 0; i < m; i++)
    if(r[a[i]] && r[b[i]]) e[a[i]].push_back(P(b[i], p - c[i]));
  VV<int> o(2);
  vector<int> cost(n, 1001001001);
  cost[0] = 0;
  for(int l = 0; l < 2; l++) {
    for(int j = 0; j < n; j++)
      for(int i = 0; i < n; i++)
        for(auto x : e[i])
          cost[x.first] = min(cost[x.first], cost[i] + x.second);
    o[l] = cost;
  }
  if(o[0] != o[1])
    printf("-1\n");
  else
    printf("%d\n", max(-o[0][n - 1], 0));
}

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

int main() {
  int N;
  cin >> N;
  vector<string> blue(N);
  for (int i = 0; i < N; i++) {
    string b;
    cin >> b;
    blue.at(i) = b;
  }
  
  int M;
  cin >> M;
  vector<string> red(M);
  for (int i = 0; i < M; i++) {
    string r;
    cin >> r;
    red.at(i) = r;
  }
  
  map<string, int> m;
  
  for (string x : blue) { 
    if (m.count(x)) m.at(x) += 1;
    else m[x] = 1;
  }
  
  for (string x : red) { 
    if (m.count(x)) m.at(x)--;
    else m[x] = -1;
  }

  int count = 0; 
  int max = 0;
  for (auto p : m) {
    count = p.second;
    if (count > max) max = count;
  }
  cout << max << endl;
}

Measured memory_bytes: 3612
n,m,l = map(int,input().split())
A = []
B = []
for i in range(n):
    A.append(list(map(int,input().split())))
for i in range(m):
    B.append(list(map(int,input().split())))

C = [[0 for i in range(l)] for j in range(n)]
for i in range(n):
    for j in range(l):
        for k in range(m):
            C[i][j] += A[i][k] * B[k][j]
for row in C:
    print(" ".join(map(str,row)))



Measured memory_bytes: 6884
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;


int main() {
  ll N, M, T;
  cin >> N >> M >> T;
  ll ans = 0;
  vector<ll> A(N);
  for(int i = 0; i < N; i++) cin >> A[i];
  ans += max(0LL, A[0] - M);
  for(int i = 1; i < N; i++) {
    ans += max(0LL, A[i] - A[i-1] - 2 * M);
  }
  ans += max(0LL, T - A[N-1] - M);
  cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3100
/*
 ____________________________________________________________
|                                                            |
|                   Author: ay2306                           |
|____________________________________________________________|

*/
#include <bits/stdc++.h>
//For ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define MOD 1000000007
#define test int t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define loop(i,a,b) for(int i=a;i<b;i++)
#define loopr(i,a,b) for(int i=a;i>=b;i--)
#define loops(i,a,b,step) for(int i=a;i<b;i+=step)
#define looprs(i,a,b,step) for(int i=a;i>=b;i-=step)
#define ull unsigned long long int
#define ll long long int
#define P pair
#define PLL pair<long long, long long>
#define PII pair<int, int>
#define PUU pair<unsigned long long int, unsigned long long int>
#define L list
#define V vector
#define D deque
#define ST set
#define MS multiset
#define M map
#define UM unordered_map
#define mp make_pair
#define pb push_back
#define pf push_front
#define MM multimap
#define F first
#define S second
#define IT iterator
#define RIT reverse_iterator
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define all(a) a.begin(),a.end()
#define ord_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
// For ordered_set
using namespace __gnu_pbds;
const ll maxn = 1e5;

int main(){
    int n;
    cin >> n;
    V<int> val(n+1,0);
    V<int> c(n+1,0);
    loop(i,1,n+1)cin >> val[i];
    loop(i,1,n+1)cin >> c[i];
    V<V<int>> dp(n+1,V<int>(60*60,0));
    int ans = 0;
    loop(i,1,n+1){
        loop(j,0,dp[i].size()){
            if(j-c[i] < 0)dp[i][j] = dp[i-1][j];
            else dp[i][j] = max(dp[i-1][j],dp[i-1][j-c[i]]+val[i]);
            ans = max(ans,dp[i][j]-j);
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;

void solve() {
  string s;
  cin >> s;
  for(int mask = 0; mask < 8; mask++) {
    int val = s[0] - '0';
    for(int i = 0; i < 3; i++) {
      if(mask&(1<<i)) {
        val += s[i+1] - '0';
      }
      else {
        val -= s[i+1] - '0';
      }
    }
    if(val == 7) {
      cout << s[0];
      for(int i = 0; i < 3; i++) {
        if(mask&(1<<i)) {
          cout << "+";
        }
        else {
          cout << "-";
        }
        cout << s[i+1];
      }
      cout << "=7\n";
      return;
    }
  }
  assert(false);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
using namespace std;
#define ll long long
int main(){
    int n, x;
    cin >> n;
    vector<int> v(n,0);
    for (int i=0; i<n-1; i++){
    	cin >>x;
    	v[x-1]++;
    }

    for (int i=0; i<n; i++){
    	cout << v[i] << endl;
    }

    return 0;
}







Measured memory_bytes: 4048
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int a[10]={};
    for(int i=0; i<10; i++){
        cin >> a[i];
    }
    sort(a,a+10);
    for(int i=9; i>6; i--){
        cout << a[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
using namespace std;
const int N = 2e4 + 5;
int a[N], b[N], P[N], id[N];
bool v[N];
bool cmp(int i, int j) {return a[i] + b[i] < a[j] + b[j];}
int main() {
	int n;
	scanf("%d", &n);
	//n = 20000;
	//for (int i = 1; i <= n; ++ i) P[i] = i;
	//random_shuffle(P + 1, P + 1 + n);
	for (int i = 1; i <= n; ++ i) a[i] = i * n;
	for (int j = 1; j <= n; ++ j) b[j] = (n - j + 1) * n;
	for (int i = 1; i <= n; ++ i) {
		int p;
		//id[i] = i;
		scanf("%d", &p);
		//printf("%d%c", P[i], " \n"[i == n]);
		//p = P[i];
		v[p] = 1;
		for (int j = 1; j < p; ++ j) if (!v[j]) b[j] ++;
		for (int j = p + 1; j <= n; ++ j) if (!v[j]) a[j] ++;
	}
	for (int i = 1; i <= n; ++ i) printf("%d%c", a[i], " \n"[i == n]);
	for (int i = 1; i <= n; ++ i) printf("%d%c", b[i], " \n"[i == n]);
	/*for (int i = 1; i < n; ++ i) assert(a[i] < a[i + 1]);
	for (int i = 1; i < n; ++ i) assert(b[i] > b[i + 1]);
	sort(id + 1, id + n + 1, cmp);
	for (int i = 1; i <= n; ++ i) assert(id[i] == P[i]);*/
}



Measured memory_bytes: 768
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    public static bool f = false, t = true;
    static void Main(string[] args)
    {
        int[] a = Read.ints();
        if (a[0] + a[1] == a[2] + a[3])
        {
            Console.WriteLine("Balanced");
        }
        else if (a[0] + a[1] > a[2] + a[3])
        {
            Console.WriteLine("Left");
        }
        else { Console.WriteLine("Right"); }
    }
    public static long gcd(long a, long b)
    {
        while (true)
        {
            if (a == 0) { return b; }
            if (b == 0) { return a; }
            if (a > b) { a -= b; }
            else { b -= a; }
        }
    }
    public static long lcm(long a, long b) { return a / gcd(a, b) * b; }
    public static bool IsPrime(int num)
    {
        if (num < 2) return false;
        else if (num == 2) return true;
        else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

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

        // 素数である
        return true;
    }
}
public static class Read
{
    public static void outl(string n = "") { Console.WriteLine(n); return; }
    public static long Long() { return long.Parse(Console.ReadLine()); }
    public static long[] longs() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); }
    public static int Int() { return int.Parse(Console.ReadLine()); }
    public static int[] ints() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
    public static string Str() { return Console.ReadLine(); }
    public static string[] Strs() { return Console.ReadLine().Split(); }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T> bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
    for (int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
    for (auto &e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    cout << max(0, c - (a - b)) << endl;
}


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

namespace CSharpSample01
{
    

    class Program
    {
        
        
        static void Main(string[] args)
        {

            while (true)
            {
                int n = int.Parse(Console.ReadLine());

                if(n == 0)
                {
                    break;
                }

                List<string> word_list = new List<string>();
                int[] order = new int[5];
                order[0] = 5;
                order[1] = 7;
                order[2] = 5;
                order[3] = 7;
                order[4] = 7;

                for(int i = 0; i < n; i++)
                {
                    word_list.Add(Console.ReadLine());
                }

                int ans = 0;
                bool find = false;

                for(int i = 0; i < n; i++)
                {
                    int cnt = 0;
                    int or = order[0];
                    for(int j = i; j < n; j++)
                    {
                        or -= word_list[j].Length;

                        if(or == 0)
                        {
                            if (cnt == 4)
                            {
                                ans = i + 1;
                                find = true;
                                break;
                            }
                            cnt++;
                            or = order[cnt];
                        }
                        else if(or < 0)
                        {
                            break;
                        }
                    }

                    if (find)
                    {
                        break;
                    }

                }

                Console.WriteLine(ans);

            }
            
        }
    }
}


Measured memory_bytes: 15960
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  int n;
  cin >> n;
  map<string, int> mp;
  rep(i,n) {
    string s;
    cin >> s;
    mp[s]++;
  }
  int mx = 0;
  for(auto p: mp) {
    mx = max(mx, p.second);
  }
  for(auto p: mp) {
    if (p.second == mx) cout << p.first << endl;
  }
}

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

Measured memory_bytes: 19212
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define For1(i, n) for(int i = 1; i <= (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

unordered_map<ll, int> factors(ll n){
    unordered_map<ll, int> d;
    for(ll i = 2; i*i <= n; i ++) while(n % i == 0) d[i] ++, n /= i;
    if(n > 1) d[n] ++;
    return d;
}

int main(void){
    Cin(ll, n, p);
    auto f = factors(p);
    ll ans = 1;
    for(auto &x : f) ans *= pow(x.first, x.second/n);
    Cout(ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int main() {
    int A, B, C; cin >> A >> B >> C;
    swap(A, B);
    swap(A, C);
    cout << A << ' ' << B << ' ' << C << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=3e5+5,Mod=1e9+7;
ll a[N];
int main (){
	int n;scanf ("%d",&n);
	for (int i=1;i<=n;i++) scanf ("%lld",&a[i]);
	ll ans=0;
	for (ll i=60;i>=0;i--){
		int c1=0,c2=0;
		for (int j=1;j<=n;j++)
			if (a[j]&(1ll<<i)) c1++;else c2++;
		ans+=1ll*(1ll<<i)%Mod*c1%Mod*c2%Mod;
		ans%=Mod;
	}
	printf ("%lld",ans);
	return 0;
}

Measured memory_bytes: 2560
n,u,v = list(map(int,input().split()))

graph = [[] for i in range(n)]

for i in range(n-1):
    a,b = list(map(int,input().split()))
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

stack = [u-1]
check = [False]*n
check[u-1] = True
check[v-1] = True
takahasi = [0]*n

while stack:
    now = stack.pop()
    for i in range(len(graph[now])):
        if check[graph[now][i]]:continue
        check[graph[now][i]] = True
        stack.append(graph[now][i])
        takahasi[graph[now][i]] = 1 + takahasi[now]

aoki = [0]*n
stack = [v-1]
check = [False]*n
check[v-1] = True
while stack:
    now = stack.pop()
    for i in range(len(graph[now])):
        if check[graph[now][i]]:continue
        check[graph[now][i]] = True
        stack.append(graph[now][i])
        aoki[graph[now][i]] = 1 + aoki[now]

#print(takahasi)
#print(aoki)

ans = 0
ans_= n+1
takahasi[u-1] = -1

henone = [0]*n
for i in range(n):
    if len(graph[i]) == 1:
        henone[i] = 1

for i in range(n):
    if henone[i] == 1 and takahasi[i] != 0 and takahasi[i] < aoki[i]:
        ans = max(aoki[i]-1,ans)
    """
    if takahasi[i] == 0:continue
    if takahasi[i] < aoki[i]:
        if (aoki[i] - takahasi[i]) % 2 == 1:
            ans = max(ans,aoki[i]-1)
        else:
            ans = max(ans,aoki[i])
    elif takahasi[i] == aoki[i]:
        ans_ = min(ans_,takahasi[i])
    """
print(ans)

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


using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    
    int a[2 * M], b[2 * M];
    for(int i = 0; i < M; ++i){
        cin >> a[i] >> b[i];
        a[i + M] = b[i];
        b[i + M] = a[i];
    }
    
    queue<vector<int>> que;
    que.push({1});
    int cnt = 0;
    
    while(que.size() > 0){
        vector<int> v = que.front();
        que.pop();
        
        if(v.size() == N){
            ++cnt; continue;
        }
        
        for(int i = 0; i < 2 * M; ++i){
            if(a[i] == v[v.size() - 1]){
                bool flag = 1;
                for(int j = 0; j < v.size(); ++j){
                    if(b[i] == v[j]){
                        flag = 0;
                        break;
                    }
                }
                if(flag){
                    vector<int> temp = v;
                    temp.push_back(b[i]);
                    que.push(temp);
                }
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 640