akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair <int , int> pii;
typedef long double ld;

const int N = 1e3+10 , mod = 1e9+7;

int dis[N][N] , n , m;
bool mark[N][N];
string s[N];

bool in(int x , int y){
   if(x >= n || y >= m || x < 0 || y < 0 || s[x][y] == '#')
      return false;
   return true;
}

void bfs(int sx , int sy){
   memset(dis , 63 , sizeof(dis));
   dis[sx][sy] = 0;
   queue <pii> q , hlp;
   q.push({sx , sy});
   while(q.size() || hlp.size()){
      if(q.empty()){
         swap(q , hlp);
      }
      pii x = q.front();
      q.pop();
      if(mark[x.first][x.second])
         continue;
      mark[x.first][x.second] = true;
      for(int i = -1 ; i <= 1 ; i++){
         for(int j = -1 ; j <= 1 ; j++){
            if(((i == 0 && j != 0) || (i != 0 && j == 0)) && in(x.first + i , x.second + j)){
               if(dis[x.first + i][x.second + j] > dis[x.first][x.second]){
                  dis[x.first + i][x.second + j] = dis[x.first][x.second];
                  q.push({x.first + i , x.second + j});
               }
            }
         }
      }
      for(int i = -2 ; i <= 2 ; i++){
         for(int j = -2 ; j <= 2 ; j++){
            if(in(x.first + i , x.second + j)){
               if(dis[x.first + i][x.second + j] > dis[x.first][x.second] + 1){
                  dis[x.first + i][x.second + j] = dis[x.first][x.second] + 1;
                  hlp.push({x.first + i , x.second + j});
               }
            }
         }
      }
   }
}

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   cin >> n >> m;
   int sx , sy;
   cin >> sx >> sy;
   sx--; sy--;
   int fx , fy;
   cin >> fx >> fy;
   fx--; fy--;
   for(int i = 0 ; i < n ; i++)
      cin >> s[i];
   bfs(sx , sy);
   if(dis[fx][fy] > mod)
      dis[fx][fy] = -1;
   cout << dis[fx][fy];
   return 0;
}


Measured memory_bytes: 9700
#include <iostream>

const int N = 100010;

int cnt[ N ];
int hasRed[ N ];
int n, m;

int main() {

	std::cin >> n >> m;
	for ( int i = 1 ; i <= n ; ++i ) {
		cnt[i] = 1;
		hasRed[i] = ( i == 1 );
	}

	for ( int i = 0 ; i < m ; ++i ) {
		int x, y;
		std::cin >> x >> y;
		if ( hasRed[ x ] ) hasRed[ y ] = 1;
		if ( cnt[x] == 1 ) {
			hasRed[ x ] = 0;
		}

		cnt[x]--;
		cnt[y]++;
	}

	int ans = 0;
	for ( int i = 1 ; i <= n ; ++i ) {
		ans += hasRed[ i ];
	}

	std::cout << ans << std::endl;
	
	return 0;
}

Measured memory_bytes: 1024
n=io.read("*n","*l")
s={}
max=0
for i=1,n do
    s[i]=io.read("*n")
    max=max+s[i]
end
table.sort(s)

for i=1,n do
    if max%10==0 and s[i]%10~=0 then
        max=max-s[i]
    elseif max%10~=0 then
        break
    end
end
if max%10==0 then
    print(0)
else
    print(max)
end

Measured memory_bytes: 760
mans, nums = map(int,input().split())
req_array  = sorted(list(map(int,input().split())))
count = 0

for i in range(mans):

    if ( i +1 ) == mans and nums == req_array[i]:
        count += 1
        nums -= req_array[i]
    elif ( i +1 ) == mans:
        break

    if nums >= req_array[i]:
        count += 1
        nums -= req_array[i]
    else:
        break
print(count)


Measured memory_bytes: 3060
n,m = map(int,input().split())
lis = list(map(int,input().split()))
li = [0 for i in range(n)]
for i in range(n):li[lis[i]-1] += 1
li.sort(reverse = True)
ans = 0
for k in range(m):
    ans += li[k]
print(n-ans)

Measured memory_bytes: 24996
n = int(raw_input())
for i in range(n):
    x0, y0, x1, y1, x2, y2, x3, y3 = map(float, raw_input().split(' '))
    if x0==x1 or x2==x3:
        if x0==x1 and x2==x3:
            print 'YES'
        else:
            print 'NO'
    elif abs(float(y1-y0)/(x1-x0) - float(y3-y2)/(x3-x2)) < 1e-10:
        print 'YES'
    else:
        print 'NO'

Measured memory_bytes: 6256
from collections import deque

n, x, y = map(int, input().split())

g = {}
for i in range(n - 1):
    g.setdefault(i, [])
    g.setdefault(i + 1, [])
    g[i].append(i + 1)
    g[i + 1].append(i)


g[x - 1].append(y - 1)

global_stat = [0] * n

def bfs(i, g):
    q = deque([(i, 0)])
    vis = [0] * len(g)
    vis[i] = 1
    stat = [0] * len(g)
    while q:
        cur_v, cur_dist = q.popleft()
        # print("%s->%s: %s" % (i + 1, cur_v + 1, cur_dist))
        if cur_v > i:
            stat[cur_dist] += 1
        for adj_v in g[cur_v]:
            if not vis[adj_v]:
                vis[adj_v] = 1
                q.append((adj_v, cur_dist + 1))
    # print(stat)
    return stat

for i in range(n):
    local_stat = bfs(i, g)
    for i, v in enumerate(local_stat):
        global_stat[i] += v

# global_stat = [v // 2 for v in global_stat]
# print(global_stat)

for v in global_stat[1:]:
    print(v)


Measured memory_bytes: 50268
#include<bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define FORR(i,a,b) for (int i = b - 1; i >= a; --i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,0,n)

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

	if (S == "ABC") cout << "ARC" << endl;
	else cout << "ABC" << endl;
	return 0;
}

Measured memory_bytes: 3576
#include<stdio.h>
int main(){
  long long int i,j,n,k;
  scanf("%lld%lld",&n,&k);
  if(k%2==1){
    printf("%lld\n",((n/k)*(n/k)*(n/k)));
  }else{
    k/=2; i=n/k; j=i/2;
    printf("%lld\n",((j*j*j)+((i-j)*(i-j)*(i-j))));
  }
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<functional>
#include<algorithm>
#include<vector>
#include<queue>
#define LL long long
#define PP std::pair<LL,LL>
#define TT std::tuple<LL,LL,LL>
std::vector<PP> x, y;
int par[100010];
int rank[100010];
int N;
LL ans;
void init(int N) {
	for (int i = 1; i <= N; i++) {
		par[i] = i;
		rank[i] = 0;
	}
}

int find(int x) {
	if (par[x] == x) {
		return x;
	}
	return par[x] = find(par[x]);
}

void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y) {
		return;
	}
	if (rank[x] < rank[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (rank[x] == rank[y])rank[x]++;
	}
}

bool same(int x, int y) {
	return find(x) == find(y);
}

int main() {
	std::cin >> N;
	init(N);
	for (int i = 1; i <= N; i++) {
		LL a, b;
		std::cin >> a >> b;
		x.push_back({ a,i });
		y.push_back({ b,i });
	}
	std::sort(x.rbegin(), x.rend());
	std::sort(y.rbegin(), y.rend());
	std::priority_queue<TT, std::vector<TT>, std::greater<TT>> pq;
	for (int i = 1; i < N; i++) {
		pq.push(TT{ std::abs(x[i].first - x[i - 1].first),x[i].second,x[i - 1].second });
		pq.push(TT{ std::abs(y[i].first - y[i - 1].first),y[i].second,y[i - 1].second });
	}
	pq.push(TT{ std::abs(x[0].first - x[N - 1].first),x[0].second,x[N - 1].second });
	pq.push(TT{ std::abs(y[0].first - y[N - 1].first),y[0].second,y[N - 1].second });
	while (!pq.empty()) {
		TT t = pq.top();
		pq.pop();
		LL a, b, c;
		std::tie(a, b, c) = t;
		if (!same(b, c)) {
			ans += a;
			unite(b, c);
		}
	}
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 13664
#include <stdio.h>

int N,A,B,C;
int l[10];
int ans=114514;

int max(int a,int b){
if(a>b){return a;}
else{return b;}
}

void dfs(int pos,int box1,int box2,int box3,int add){
if(pos>=N){
if(box1!=0&&box2!=0&&box3!=0){
int mp=max(A-box1,box1-A)+max(B-box2,box2-B)+max(C-box3,box3-C)+add;
if(ans>mp){ans=mp;}
}
return;
}

if(box1==0){
dfs(pos+1,box1+l[pos],box2,box3,add);
}
else{
dfs(pos+1,box1+l[pos],box2,box3,add+10);
}
if(box2==0){
dfs(pos+1,box1,box2+l[pos],box3,add);
}
else{
dfs(pos+1,box1,box2+l[pos],box3,add+10);
}
if(box3==0){
dfs(pos+1,box1,box2,box3+l[pos],add);
}
else{
dfs(pos+1,box1,box2,box3+l[pos],add+10);
}
dfs(pos+1,box1,box2,box3,add);

}

int main(){

scanf("%d %d %d %d",&N,&A,&B,&C);

int i;

for(i=0;i<N;i++){
scanf("%d",&l[i]);
}

dfs(0,0,0,0,0);

printf("%d\n",ans);

return 0;
}

Measured memory_bytes: 128
n = int(input())
a = input().split()
ammount = 0
mini = int(a[0])
maxi = int(a[0])
for i in range(n):
	ammount += int(a[i])
	if mini > int(a[i]):
		mini = int(a[i])
	if maxi < int(a[i]):
		maxi = int(a[i])
print(mini, maxi, ammount)


Measured memory_bytes: 6328
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
typedef pair <int,int> ii ;
typedef vector < ii > vii ;
typedef vector < vii > viii ;
#define rep(i,n)                   for( ll i = 0 ; i < n ; i++)
#define repu(i,a,b)                for(int i = a ; i <= b ; i++) 
#define repd(i,b,a)                for(int i = b ; i >= a ; i--)
#define pb push_back
#define db double 
#define fi first
#define se second

void dfs(int u, vector<int> adj[], int dist[], bool vis[]) {
	vis[u]=true;
	rep(i,adj[u].size()) {
		if(!vis[adj[u][i]]) dfs(adj[u][i], adj, dist, vis);
		dist[u]=max(dist[u], 1+dist[adj[u][i]]);
	}
}

int longestPath(vector<int> adj[], int s, int n) {
	bool vis[n];
	int dist[n];
	memset(vis, false, sizeof vis);
	memset(dist, 0, sizeof dist);
	dist[s]=0;
	stack<int> stk;
	stk.push(s);
	rep(i,n) if(!vis[i]) dfs(i,adj,dist,vis);
	int ma=0;
	rep(i,n) ma=max(ma,dist[i]);
	return ma;

}

int main() {
   int n,m; cin>>n>>m;
   vector<int> adj[n];
   rep(i,m) {
   	int x,y; cin>>x>>y; x--, y--;
   	adj[x].pb(y);
   }
   cout<<longestPath(adj,0,n);
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
const int nax = 1e5;
const int mod = 1e9 + 7;
int main(int argc,char ** argv){
	int h , w; 
	cin >> h >> w;
	char a[h + 1][w ];
	for(int i = 0 ; i < h ; i++){
		for(int j = 0; j < w ; j++)
			cin >> a[i][j];
	}
	vector< vector< ll > > dp(h , vector< ll > (w , 0));
	dp[0][0] = 1;
	for(int i = 1 ; i < h;i++){
		if(a[i][0] == '#')
			break;
		dp[i][0] = 1;
	}
	for(int i = 1 ; i < w;i++){
		if(a[0][i] == '#')
			break;
		dp[0][i] = 1;
	}
	for(int i = 1 ; i < h ; i++){
		for(int j = 1 ; j < w ; j++){
			if(a[i][j] == '.'){
				int ans = 0;
				if(a[i][j - 1] == '.')
					ans += dp[i][j - 1];
				if(a[i - 1][j] == '.')
					ans += dp[i- 1][j];
				dp[i][j] = ans;
				if(dp[i][j] > mod)
					dp[i][j] -= mod;
			}
		}
	}
	cout << dp[h - 1][w - 1] << endl;
    return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;

ld dp[310][310][310];

ld solve(ld a, ld b, ld c, ld n) {
    if (a < 0 || b < 0 || c < 0) {
        return 0;
    }
    if (a == 0 && b == 0 && c == 0) {
        return 0;
    }
    if (dp[(int)a][(int)b][(int)c] != 0) {
        return dp[(int)a][(int)b][(int)c];
    }
    return dp[(int)a][(int)b][(int)c] = (a / (a + b + c)) * (n / (a + b + c) + solve(a - 1, b, c, n)) +
            (b / (a + b + c)) * (n / (a + b + c) + solve(a + 1, b - 1, c, n)) +
            (c / (a + b + c)) * (n / (a + b + c) + solve(a, b + 1, c - 1, n));
}

int main() {
    ios_base::sync_with_stdio(0);
    cout.tie(0); cin.tie(0);
    cout.precision(20); cout << fixed;
    int n;
    cin >> n;
    int a = 0, b = 0, c = 0;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (x == 1) a++;
        if (x == 2) b++;
        if (x == 3) c++;
    }
    cout << solve(a, b, c, n);
}


Measured memory_bytes: 450944
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://abc085.contest.atcoder.jp/tasks/abc085_c>
問題文============================================================
 日本でよく使われる紙幣は、10000 円札、5000 円札、1000 円札です。以下、「お札」とはこれらのみを指します。
 
 青橋くんが言うには、彼が祖父から受け取ったお年玉袋にはお札が N 枚入っていて、
 合計で Y 円だったそうですが、嘘かもしれません。
 このような状況がありうるか判定し、ありうる場合はお年玉袋の中身の候補を一つ見つけてください。
 なお、彼の祖父は十分裕福であり、お年玉袋は十分大きかったものとします。
=================================================================

解説=============================================================

================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll N,Y; cin >> N >> Y;
    Y /= 1000;
    for(int x = 0; x <=N;x++){
        for(int y = 0; y + x<=N;y++){
            if(x * 10 + y * 5 + (N - x - y) == Y){
                cout << x << " " << y << " " << (N - x - y) << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
	return 0;
}


Measured memory_bytes: 256
S=input()
Q=[s for s in S if s != 'A']
U=list('KIHBR')
import sys
if S.count('A')>4:
    print('NO')
    sys.exit()
elif len(Q)!=5:
    print('NO')
    sys.exit()
for i in range(len(S)):
    if S[i] not in list('AKIHABARA'):
        print('NO')
        sys.exit()
for i in range(len(S)-1):
    if S[i]==S[i+1]:
        print('NO')
        sys.exit()
    elif S[i]=='K' and S[i+1]!='I':
        print('NO')
        sys.exit()
    elif S[i]=='I' and S[i+1]!='H':
        print('NO')
        sys.exit()
for i in range(len(U)):
    if Q[i]==U[i]:
        pass
    else:
        print('NO')
        break
else:
    print('YES')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
string s;
int a,b,c,d;
int add[]={-1,1};
string ad="-+";
int main()
{
	cin>>s;
	a=s[0]-'0';
	b=s[1]-'0';
	c=s[2]-'0';
	d=s[3]-'0';
	for(int i=0;i<2;i++)
	{
		for(int j=0;j<2;j++)
		{
			for(int k=0;k<2;k++)
			{
				int num=a;
				num=num+add[i]*b+add[j]*c+add[k]*d;
				if(num!=7)
					continue;
				cout<<a<<ad[i]<<b<<ad[j]<<c<<ad[k]<<d<<"=7\n";
				return 0;
			}
		}
	}
	return 0;
}



Measured memory_bytes: 256
a1,a2 = map(int,input().split())
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
import collections
c1 = collections.Counter(prime_factorize(a1))
c1 = list(c1.keys())
c2 = collections.Counter(prime_factorize(a2))
c2 = list(c2.keys())
c = 1
for i in range(0,len(c1)):
    if c2.count(c1[i]) == 0:
        continue
    else:
        c = c+1
print(c)

Measured memory_bytes: 3316
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias sread = () => readln.chomp();

void main()
{
    auto n = lread();
    auto f = n.factorization();
    // f.writeln();
    long mincost = INF;
    foreach(i; iota(f.length))
    {
        long cost = f[i] + f[$ - 1 - i];
        mincost = min(cost, mincost);
    }
    writeln(mincost - 2);
}

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

auto factorization(long a)
{
    auto factor = new long[](0);
    auto limit = cast(long) sqrt(cast(float) a);
    foreach (i; iota(limit))
    {
        long tmp = i + 1;
        if (a % tmp == 0)
        {
            factor ~= tmp;
            if (tmp != a / tmp)
                factor ~= a / tmp;
        }
    }
    factor.sort();
    return factor;
}


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

using namespace std;

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define pb emplace_back
#define ll long long

const int INF = 2e9 + 1;
const ll INFLL = 1e18 + 1;
const ll mod = 1e9 + 7;

ll my_pow(ll n, ll m) {
    if (m == 0) return 1;
    ll now = my_pow(n, m / 2);
    if (m % 2 == 0) return (now * now) % mod;
    else return (((now * now) % mod) * n) % mod;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    ll ans = 1;
    ll C1u = 1, C1d = 1, C2u = 1, C2d = 1;
    for (int m = 1; m <= min(n - 1, k); m++) {
        C1u *= (n - m + 1);
        C1d *= m;
        C2u *= (n - m);
        C2d *= m;
        C1u %= mod;
        C1d %= mod;
        C2u %= mod;
        C2d %= mod;
        ans += (((C1u * my_pow(C1d, mod - 2)) % mod) * ((C2u * my_pow(C2d, mod - 2)) % mod)) % mod;
        ans %= mod;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,L,a[N],i,j;
int main(){
	scanf("%d%d",&n,&L);
	for(i=1;i<=n;i++)scanf("%d",&a[i]);
	for(i=1,j=1;i<n;i++)if(a[i]+a[i+1]>a[j]+a[j+1])j=i;
	if(a[j]+a[j+1]<L){puts("Impossible");return 0;}
	puts("Possible");
	for(i=n-1;i>j;i--)printf("%d\n",i);
	for(i=1;i<=j;i++)printf("%d\n",i);
	return 0;
}

Measured memory_bytes: 1152
import sys
n = int(input())
a = list(map(int, input().split()))

def prime_decomposition(n):
    i = 2
    table = []
    while i**2 <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1: table.append(n)
    return set(table)

pri_0 = prime_decomposition(a[0])
pri_1 = prime_decomposition(a[1])
ans = pri_0&pri_1

if len(ans):
    for i in range(2, n):
        res = prime_decomposition(a[i])
        ans &= res
        if not ans:
            print('setwise coprime')
            sys.exit()
    print('not coprime')

else:
    ans = pri_0 | pri_1
    for i in range(2, n):
        res = prime_decomposition(a[i])
        for i in res:
            if i in ans:
                print('setwise coprime')
                sys.exit()
        ans |= res
    print('pairwise coprime')

Measured memory_bytes: 181700
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=998244353,MAX=500005,INF=1<<30;
int dp[MAX][4];

int main(){
    
    int N;cin>>N;
    string S;cin>>S;
    vector<int> left(N),right(N);
    for(int i=0;i<N;i++){
        if(i==0) left[i]=S[i]-'0';
        else{
            if(S[i]=='1') left[i]=left[i-1]+1;
            else left[i]=0;
        }
    }
    
    reverse(all(S));
    
    for(int i=0;i<N;i++){
        if(i==0) right[i]=S[i]-'0';
        else{
            if(S[i]=='1') right[i]=right[i-1]+1;
            else right[i]=0;
        }
    }
    
    reverse(all(S));
    reverse(all(right));
    
    for(int i=1;i<=N;i++){
        if(S[i-1]=='1'&&S[i]=='0'&&S[i+1]=='1'){
            
            if(left[i-1]>=2) dp[i][0]=max(dp[i][0],dp[i-1][0]+left[i-1]-1);
            dp[i][0]=max(dp[i][0],dp[i-1][2]+1);
            dp[i][0]=max(dp[i][0],dp[i-1][3]+left[i-1]);
            
            if(left[i-1]>=2) dp[i][1]=max(dp[i][1],dp[i-1][0]+right[i+1]);
            dp[i][1]=max(dp[i][1],dp[i-1][2]+right[i+1]);
            dp[i][1]=max(dp[i][1],dp[i-1][3]+right[i+1]);
            
            if(left[i-1]>=2) dp[i][2]=max(dp[i][2],dp[i-1][0]+right[i+1]-1);
            dp[i][2]=max(dp[i][2],dp[i-1][2]+right[i+1]-1);
            dp[i][2]=max(dp[i][2],dp[i-1][3]+right[i+1]-1);
            
            for(int j=0;j<4;j++) dp[i][3]=max(dp[i][3],dp[i-1][j]);
            
        }else if(S[i-1]=='0'&&S[i]=='0'){
            for(int j=0;j<4;j++){
                for(int k=0;k<4;k++){
                    dp[i][j]=max(dp[i][j],dp[i-1][k]);
                }
            }
        }else{
            for(int j=0;j<4;j++){
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    
    int ans=0;
    
    for(int j=0;j<4;j++) ans=max(ans,dp[N][j]);
    
    cout<<ans<<endl;
    
    
    
}


Measured memory_bytes: 12548
/**   Created by: Marcos Portales
          Codeforces User: marcosportales
          Country: Cuba
          Copyright                    */
#include<bits/stdc++.h>
using namespace std;
/// Pragmas:
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2") //Enable AVX
/// Macros:
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define enl '\n'
#define vi vector<int>
#define sz(a) int((a).size())
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,n) for(int i=(1);i<=(n);i++)
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
/// Constraints:
const int maxn = 200005;
const int mod = 1000000007;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 2000000000000000000ll;
const ld pi = acos(-1);
/// Prime Numbers:
// 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089;
// 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081;
// 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099;
/// Functions:
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x,b) ( log(x) / log(b) )
/// Red-Black Tree Test.insert(x)late ---------------------------------
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
/// Quick Pow------------------------------------------------
int qpow(int b,int e){
    if( !e ) return 1;
    if( e & 1 ) return qpow(b,e-1) * b % mod;
    int pwur = qpow(b,e>>1);
    return (pwur * pwur) % mod;
}
int modinv(int x){
    return qpow(x,mod-2);
}

/// My Code -------------------------------------------------

bool can(int n){
    int num=n,s=0;
    for(;num>0;num/=10){
        s+=(num%10);
    }
    if(n%s==0)
    return true;
    else return false;
}

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);
    srand(time(NULL));
    //freopen("a.in","r",stdin);
    //freopen("a.in","w",stdout);
    int n;
    cin>>n;
    cout<<((can(n))?"Yes\n":"No\n");

    return 0;
}


Measured memory_bytes: 3612
marks='SHCD'
n=input()
card=[raw_input().split() for _ in range(n)]
m={}
for mk,rk in card:
    m.setdefault(mk,[0]*14)
    m[mk][int(rk)]=1
for i in range(len(m)):
    k=marks[i]
    v=m[k]
    for j in range(1,14):
        if not v[j]: print k,j

Measured memory_bytes: 6456
#include <iostream>

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

int main()
{
  int k, s, ans = 0;
  cin >> k >> s;
  for(int x = 0; x <= k; x++) {
    for(int y = 0; y <= k; y++) {
      int z = s - x - y;
      // cout << z << endl;
      if(x + y + z == s && z >= 0 && z <= k) ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cstdio>
#define int long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define MOD 1000000007
#define S second
using namespace std;
typedef pair<int,int>pii;
int n,k;
int f[2010][2010];
signed main(){
	cin>>n>>k;
	for(int i=0;i<=n+1;i++){
		f[i][0]=f[i][i]=1;
		for(int j=1;j<i;j++)
			f[i][j]=f[i-1][j]+f[i-1][j-1],f[i][j]%=MOD;
	}
	for(int i=1;i<=k;i++){
		cout<<(f[k-1][i-1]*f[n-k+1][i]%MOD)<<endl;
	}
	return 0;
}

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int N,A,B;
    Scd3(N,A,B);

    printf ("%d\n", min( N*A, B ));



    return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define int long long int
constexpr int INF = std::numeric_limits<int>::max();
constexpr int NINF = std::numeric_limits<int>::min();
using namespace std;

void solve() {
  int N;
  int ans = INF;
  cin >> N;
  while (N--) {
    int a;
    cin >> a;
    int x = 0;
    while (a%2 == 0) {
      a /= 2;
      x++;
    }

    ans = min(ans, x);
  }
  cout << ans << endl;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


Measured memory_bytes: 256
H, W, D = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]

d = {}
for y in range(H):
    for x in range(W):
        d[A[y][x]] = (y, x)

t = [[0] * (H * W // D + 1) for _ in range(D)]
for i in range(D):
    j = 0
    if i == 0:
        j = 1
    while i + (j + 1) * D <= H * W:
        y1, x1 = d[i + j * D]
        y2, x2 = d[i + (j + 1) * D]
        t[i][j + 1] = abs(y1 - y2) + abs(x1 - x2)
        j += 1
    for j in range(H * W // D):
        t[i][j + 1] += t[i][j]

Q = int(input())
result = []
for _ in range(Q):
    L, R = map(int, input().split())
    i = L % D
    result.append(t[i][(R - i) // D] - t[i][(L - i) // D])
print('\n'.join(str(i) for i in result))
#print(*result, sep='\n')


Measured memory_bytes: 40212
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>

using namespace std;

int main() 
{
  int a,b,c,x,ans = 0;
  cin >> a >> b >> c >> x;
  
  for(int i = 0; i <= a; i++)
  {
    for(int j = 0; j <= b; j++)
    {
      for(int k = 0; k <= c; k++)
      {
        if(500*i + 100*j + 50*k == x)
        {
          ans++;
          break;
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
char shift(char ch,int N){
    int d = ch-'A';
    int dn=0;
    if(N+d>25) dn = N+d-26;
    else dn = N+d;
    return (char)(dn+'A');
}
int main (){
    int N;cin >> N;
    string S;cin>>S;
    for(int i=0;i<S.size();i++){
        S[i]=shift(S[i],N);
    }
    cout<<S<<endl;
    return 0;
}


Measured memory_bytes: 256
#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))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr ll INFL = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

signed main() {
  ll N;
  cin >> N;

  map<string, ll> m;

  rep(i, N) {
    string s;
    cin >> s;
    SORT(s);
    m[s]++;
  }

  ll ans = 0;
  for (auto k : m) {
    debug(k.first);
    debug(k.second);

    ans += k.second * (k.second - 1) / 2;
  }
  COUT(ans);

  return 0;
}

Measured memory_bytes: 11136
H,W = map(int,input().split())

dp = [list(map(int,input().split())) for _ in range(10)]
A = [list(map(int,input().split())) for _ in range(H)]

"""
各数字から各数字への変更コストの最小値をわーシャルフロイドで計算する
"""

for i in range(10):
    for j in range(10):
        for k in range(9,-1,-1):
            dp[j][k] = min(dp[j][k],dp[j][i]+dp[i][k])

cost = 0
for i in range(H):
    for j in range(W):
        default = A[i][j]
        if default != -1:
            cost += dp[default][1]

print(cost)


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

using ll = long long;
#define mod 1000000007
#define init ios::sync_with_stdio(0), cin.tie(0);
typedef vector<int> vi;
typedef pair<int, int> pi;
#define MS(x, y) memset(x, y, sizeof(x))
#define F first
#define S second
#define PB push_back
#define MP make_pair
char mat[10][10];
int n,m,k;

bool col(int i,int j)
{
    int cnt=0;
    for(int z=0;z<n;z++)
        if((i&(1<<z))==0)
            for(int y=0;y<m;y++)
                if((j&(1<<y))==0)
                    if(mat[z][y]=='#')
                        cnt++;
    return cnt==k;
}

int main()
{
    init;
    cin>>n>>m>>k;

    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            cin>>mat[i][j];

    int cnt=0;
    for(int i=0;i<(1<<n);i++)
        for(int j=0;j<(1<<m);j++)
            if(col(i,j))
                cnt++;
    cout<<cnt;
}

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

class Vec
{
public:
	double x, y;
	Vec(double x, double y) : x(x), y(y){}
	Vec(){}

	Vec operator-(Vec v)
	{
		return Vec(x - v.x, y - v.y);
	}
	double GetCp(Vec v)
	{
		return (x * v.y - y * v.x);
	}
};

bool IsHit(Vec a, Vec b, Vec c, Vec p)
{
	double A = (b - a).GetCp(p - a);
	double B = (c - b).GetCp(p - b);
	double C = (a - c).GetCp(p - c);

	return (A >= 0 && B >= 0 && C >= 0) || (A <= 0 && B <= 0 && C <= 0);
}


int main()
{
	Vec v[4];
	while (true)
	{
		for (int i = 0; i < 4; i++)
		{
			if (scanf("%lf,", &(v[i].x)) == -1) return 0;
			if (scanf("%lf,", &(v[i].y)) == -1) return 0;
		}

		if (IsHit(v[0], v[1], v[2], v[3]) ||
			IsHit(v[3], v[0], v[1], v[2]) ||
			IsHit(v[2], v[3], v[0], v[1]) ||
			IsHit(v[1], v[2], v[3], v[0]))
		{
			cout << "NO" << endl;
		}
		else
		{
			cout << "YES" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(x,y) '(' << x << ',' << y << ')'
ll MOD = 1000000007;
ll INF = 214748364700000000;
double EPS = 1e-12;
double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<pair<ll,ll>>>;

ll H,W;
char field[30][30];
ll d[30][30];
ll dy[4]{-1,0,1,0};
ll dx[4]{0,-1,0,1};

ll bfs(ll sy,ll sx,ll gy,ll gx){
    rep(i,30) rep(j,30) d[i][j] = INF;
    queue<pair<ll,ll>> Q;
    d[sy][sx] = 0;
    Q.emplace(sy,sx);
    while(Q.size()){
        ll y,x;
        tie(y,x) = Q.front();
        Q.pop();
        if(y == gy && x == gx){
            break;
        }
        rep(i,4){
            ll ny = dy[i] + y,nx = dx[i] + x;
            if(0 <= ny && ny < H && 0 <= nx && nx < W){
                if(d[ny][nx] == INF && field[ny][nx] != '#'){
                    d[ny][nx] = d[y][x] + 1;
                    Q.emplace(ny,nx);
                }
            }
        }
    }
    return d[gy][gx];
}

int main(){
   cin >> H >> W;
   rep(i,H) rep(j,W){
       cin >> field[i][j];
   }
   ll ans = 0;
   rep(i,H) rep(j,W) rep(k,H) rep(l,W){
       if(i == k && j == l) continue;
       if(field[i][j] == '#' || field[k][l] == '#') continue;
       ll D = bfs(i,j,k,l);
       if(D != INF){
           ans = max(ans,D);
       }
   }
   cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<iii> viii;


#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REPR(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define FOR(i, n, m) for (ll i = (n); i < (m); ++i)
#define FORR(i, n, m) for (ll i = (m) - 1; i >= (n); --i) 
#define FORE(x, xs) for (auto &x: (xs))
#define ALL(v) v.begin(), v.end()
#define ZERO(a) memset(a,0,sizeof(a))
#define Miii(x, y, z) make_pair(x, make_pair(y, z))

const int INF = 1000000009;
const int MOD = 1000000007;
const double EPS = 1e-14;
const double PI = acos(-1);

const int MAX = 1e5;

int N;
viii A, B;
bool used[MAX];

int main() {

    cin >> N;
    REP (i, N) {
        int a, b;
        cin >> a >> b;
        A.push_back(Miii(-a-b, -a, i));
        B.push_back(Miii(-a-b, -b, i));
    }
    sort(ALL(A));
    sort(ALL(B));

    ll ans = 0;
    int ia = 0, ib = 0;
    REP (i, N) {
        if (i%2 == 0) {
            while (used[A[ia].second.second]) ia++;
            ans -= A[ia].second.first;
            used[A[ia].second.second] = true;
        } else {
            while (used[B[ib].second.second]) ib++;
            ans += B[ib].second.first;
            used[B[ib].second.second] = true;
        }
    }
    cout << ans << endl;

}

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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;

int main()
{
    speed;
    cout << fixed << setprecision(9);
    /*start*/
    int n, d;
    cin>>n>>d;
    int count=0;
    rep(i, n) {
        ll x, y;
        cin>>x>>y;
        if (d>=sqrt((x*x)+(y*y))) {
            count++;
        }
    }
    c(count);

}


Measured memory_bytes: 3672
/*
 * 	The way if it's all predetermined
 * 		And the way i should go all my life
 * 			I swear to go wherever will be
 * 				'Cause there'll be something to see and to find
 */
//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#ifdef rd
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
#else
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define fi first
#define se second
//#define int long long
typedef long long ll;
typedef long double f80;
#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
const ll infl=2e18;
const int infi=1e9;
//const int mod=998244353;
const int mod=1000000007;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}


void solve() {
	string s;
	cin>>s;
	int x=0;
	for(char te:s)
		if(te=='x')
			x++;
	if(x>=8)
		cout<<"NO"<<endl;
	else
		cout<<"YES"<<endl;
}

signed main() {
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	cout<<fixed<<setprecision(10);
	int t=1;
//	cin>>t;
	while(t--)
		solve();
#ifdef rd
	cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
	return 0;
}


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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = long long;
using P = pair<int, int>;

const int INF = 1 << 30;
//const ll INF = 1LL << 60;

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;
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i, n) cin >> h.at(i);
  vector<int> dp(n, INF);
  dp.at(0) = 0;
  for (int i = 1; i < n; i++) {
    for (int j = 1; j <= k; j++) {
      if (i - j >= 0) {
        chmin(dp.at(i), dp.at(i - j) + abs(h.at(i) - h.at(i - j)));
      }
    }
  }
  cout << dp.at(n - 1) << endl;
  return 0;
}


Measured memory_bytes: 4004
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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;
}

int main() {
  ll N, H;
  cin >> N >> H;
  vector<ll> a(N), b(N);
  rep(i, N) cin >> a[i] >> b[i];

  ll max_a = 0;
  rep(i, N) {
    chmax(max_a, a[i]);
  }

  sort(all(b), greater<ll>());
  ll ans = 0;
  rep(i, N) {
    if (b[i] <= max_a)
      break;
    ans++;
    H -= b[i];
    if (H <= 0) {
      cout << ans << endl;
      return 0;
    }
  }

  ans += (H + max_a - 1) / max_a;
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=305,INF=1<<30;

vector<int> rev(vector<int> &A){
    vector<int> res(si(A));
    
    for(int i=0;i<si(A);i++){
        res[A[i]]=i;
    }
    
    return res;
}

vector<int> mul(vector<int> &A,vector<int> &B){
    vector<int> res=A;
    
    for(int i=0;i<si(A);i++){
        res[i]=B[res[i]];
    }
    
    return res;
}//A→Bの順

vector<int> pow(vector<int> &A,ll n){
    vector<int> res(si(A));
    iota(all(res),0);
    
    while(n>0){
        if(n&1) res=mul(res,A);
        A=mul(A,A);
        n/=2;
    }
    
    return res;
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    random_device seed_gen;
    mt19937_64 rng(seed_gen());
    
    int N,K;cin>>N>>K;
    K--;
    vector<int> p(N),q(N);
    for(int i=0;i<N;i++){
        cin>>p[i];
        p[i]--;
    }
    for(int i=0;i<N;i++){
        cin>>q[i];
        q[i]--;
    }
    
    vector<int> pp=rev(p),qq=rev(q),r=mul(pp,q);
    
    if(K==0){
        for(int a:p) cout<<a+1<<" ";
        cout<<endl;
        return 0;
    }
    
    if(K==1){
        for(int a:q) cout<<a+1<<" ";
        cout<<endl;
        return 0;
    }
    
    if(K==2){
        for(int a:r) cout<<a+1<<" ";
        cout<<endl;
        return 0;
    }
    
    vector<int> A(N),B(N),res(N);
    iota(all(A),0);
    iota(all(B),0);
    iota(all(res),0);
    A=mul(A,p);
    A=mul(A,qq);
    A=mul(A,pp);
    A=mul(A,q);
    
    B=mul(B,qq);
    B=mul(B,p);
    B=mul(B,q);
    B=mul(B,pp);
    
    int x=(K-3)%6,y=(K-3)/6;
    
    A=pow(A,y);
    B=pow(B,y);
    
    p=q;
    q=r;
    
    for(int i=0;i<=x;i++){
        pp=rev(p);
        r=mul(pp,q);
        
        p=q;
        q=r;
    }
    
    res=mul(res,B);
    res=mul(res,q);
    res=mul(res,A);
    
    for(int a:res) cout<<a+1<<" ";
    cout<<endl;
}



Measured memory_bytes: 6972
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


// CHECK THE LIMITS
typedef long long ll;

const int MOD = 1000000007;
const ll INFLL = 1e18;
const int INF = 1e9;
const int NMAX = 1000001;

int gcd(int a, int b) {
  return b ? gcd(b, a%b) : a;
} 

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

	int n;
	cin >> n;

	map<string,int> my_map;
	for(int a = 1; a <= n; ++a)
	{
		string s = to_string(a);
		char first = s[0];
		char second = s.back();
		s.clear();
		s+=first;
		s+=second;

		++my_map[s];
	}

	ll answer = 0;
	for(auto &p : my_map)
	{
		string s = p.first;
		
		if(s[0] == s[1])
		{
			int x = p.second;
			answer += (ll) x * x;
		}
		else
		{
			swap(s[0],s[1]);
			answer += (ll) p.second *  my_map[s];
		}
		
		
	}

	cout << answer;
    return 0;
}

Measured memory_bytes: 256
N = gets.chomp.to_i
H = gets.split(' ')
h = H.map{|x| x.to_i}

i = 0
max = 0
count = 0
N.times do
    if h[i] >= max then
        max = h[i]
        count = count + 1
    end
    i = i + 1
end

print count

Measured memory_bytes: 1788
{-# LANGUAGE Strict #-}
import qualified Data.ByteString.Char8 as B
import           Data.Char             (digitToInt)
import qualified Data.Vector.Unboxed   as V


main :: IO ()
main = do
  s <- B.getLine
  print $ solve s

solve :: B.ByteString -> Int
solve s = V.sum $ V.map (\h -> h * (h - 1) `div` 2) hs
  where m = 2019
        hs = hist m $ subModNum s m

subModNum :: B.ByteString -> Int -> [Int]
subModNum s m = map fst $ scanr (\a (y, f) -> ((y + a * f) `mod` m, 10 * f `mod` m)) (0, 1) as
  where as = [digitToInt c | c <- B.unpack s]

hist :: Int -> [Int] -> V.Vector Int
hist n xs = V.accum (+) (V.replicate n 0) [(x, 1) | x <- xs]


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

using namespace std;
using ll=long long;
int main(){
    ll h;
    cin >> h;
    ll ans;
    vector<ll> b(60);
    ll beg=1;
    ll cnt;
    for(int i=0;i<60;i++){
        b[i]=beg;
        beg*=2;
        if(beg>h){
            cnt=i;
            break;
        }
        //cout << beg << endl;
    }
    ll i=0;
    while(true){
        if(h & (1LL << i)){
            ans=i+1;
        }
        i++;
        if(i>cnt+10){
            break;
        }
    }
    ll sum=0;
    for(int i=0;i<ans;i++){
        sum+=b[i];
    }
    cout << sum << endl;
    
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};

fn main() {
    input! {
        a:usize,mut b:usize,mut c:usize,
        mut k:usize
    }
    while k > 0 && a >= b {
        b *= 2;
        k -= 1;
    }
    while k > 0 && b >= c {
        c *= 2;
        k -= 1;
    }
    if a < b && b < c {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2176
import java.io.*;
import java.util.*;
public class Main {
    
    public static void main(String[] args) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer(br.readLine());
        int[] array=new int[3];
        array[0]=Integer.parseInt(st.nextToken());
        array[1]=Integer.parseInt(st.nextToken());
        array[2]=Integer.parseInt(st.nextToken());
        Arrays.sort(array);
        int count=1;
        for(int i=1;i<3;i++){
            if(array[i-1]!=array[i]){
                count++;
            }
        }System.out.println(count);
    }
}

Measured memory_bytes: 8148
#include<bits/stdc++.h>
#define mins(a,b) a=min(a,b)
#define maxs(a,b) a=max(a,b)
 template < typename T > std::string to_string( const T& n )
  {
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
  }
using namespace std;

const long long INF=9000000000000000;
int main(){
  int n,k;
  string s;
  cin>>n>>s>>k;
  for(int i=0;i<n;i++){
    if(s[i]==s[k-1])
      cout<<s[i];
    else
      cout<<'*';
  }
  cout<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

// (r - l, l)
using IN = tuple<int, int>;

int n;
vi used;

int calc(vector<string> & strs){
    vector<IN> a(n);

    rep(i, n){
        int l = 0, rew = 0;
        for(auto & c : strs[i]){
            if(c == ')'){
                rew--;
            }
            else {
                rew++;
            }
            chmin(l, rew);
        }
        l = -l; 

        if(rew < 0){
            l = 1 << 30;
        }
        a[i] = IN(rew, l);
    }

    int cur = 0;
    rep(loop, n){
        rep(i, n){
            if(used[i]) continue;

            int l, rew;
            tie(rew, l) = a[i];

            if(cur < l) continue;

            cur += rew;
            used[i] = true;
            break;
        }
    }

    return cur;
}

int main(void){
    cin >> n;
    vector<string> strs(n);
    for(auto & e : strs) cin >> e;

    used = vi(n);

    int res_l = calc(strs);
    for(auto & e : strs){
        for(auto & c : e){
            if(c == '(') c = ')';
            else         c = '(';
        }
        reverse(_all(e));
    }
    int res_r = calc(strs);

    for(auto & e : used){
        if(not e){
            cout << "No" << endl;
            return 0;
        }
    }
    if(res_l == res_r){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3228
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    int n;
    cin >> n;
    int a[n];
    rep(i,n)cin>>a[i];
    int up[n+1]={},down[n+1]={};
    rep(i,n)up[i+1]=max(up[i],a[i]);
    rep(i,n)down[n-i-1]=max(down[n-i],a[n-i-1]);
    rep(i,n){
        cout << max(up[i],down[i+1])<<endl;
    }
    return 0;
}


Measured memory_bytes: 3968