akhauriyash/Code-Regression huggingface dataset:
module Main where

import Control.Applicative
import Control.Monad
import Data.List (sort, group)

f :: [[String]] -> [String] -> Int
f rss (b:bs) = len1 - len2
  where
    len1 = length (b:bs)
    len2 = case filter ((== b) . head) rss of
        []   -> 0
        [cs] -> length cs

main :: IO ()
main = do
    n <- readLn
    ss <- replicateM n getLine
    m <- readLn
    ts <- replicateM m getLine
    let blue = group . sort $ ss
    let red  = group . sort $ ts
    let ans  = maximum $ 0 : fmap (f red) blue
    print ans

Measured memory_bytes: 636
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N, K = list(map(int, sys.stdin.buffer.readline().split()))


def solve(n, k):
    n = n % k
    return min(n, k - n)
ans = solve(N, K)
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <math.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <map>
using namespace std;

int main() {
	int N, ans = 0;
	cin >> N;
	for (int i = 1; i <= N; i++)
	{
		if (i < 10 || (i < 1000 && i >= 100) || (i < 100000 && i >= 10000))ans++;
	}
	cout << ans;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, M: int):
    if N == M:
        print(YES)
    else:
        print(NO)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    solve(N, M)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define local
//if you find any bug in my code, please tell me.
int main()
{
#ifdef local
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
#endif
    int a,b;
    cin>>a>>b;
    cout<<(a+b)%24<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

class RMQ{
public:
	int n = 1;vector<P> seg;
	void init(int N){		//N要素のセグメントツリー作成
		while(n < N)n *= 2;seg.resize(2*n);
		fill(all(seg), P(INF, -1));
	}
	void update(int k, int x){
		k += n-1;seg[k] = P(x, k-(n-1));
		while(k > 0){k = (k-1)/2;seg[k] = min(seg[k*2+1], seg[k*2+2]);}
	}
	P calc(int a, int b, int k, int l, int r){
		if(b <= l || r <= a)return P(INF, -1);
		if(a <= l && r <= b)return seg[k];
		P vl = calc(a, b, k*2+1, l, (l+r)/2);
		P vr = calc(a, b, k*2+2, (l+r)/2, r);
		return min(vl, vr);
	}
	int get(int a, int b){return calc(a, b, 0, 0, n).se;}
};

class EulerTour{
public:
	vector<vector<int> > G;
	vector<int> vs, dep, idx;
	RMQ rmq;
	int n;
	void init(int N){
		n = N;
		G.resize(N);dep.resize(N);
		idx.resize(N);rmq.init(2*n-1);
	}
	void add_edge(int u, int v){
		G[u].pb(v);G[v].pb(u);
	}
	void dfs(int v, int par){
		idx[v] = vs.size();vs.pb(v);
		if(par != -1)dep[v] = dep[par]+1;
		rep(i,G[v].size())if(G[v][i] != par){
			dfs(G[v][i], v);vs.pb(v);
		}
	}
	void euler_tour(int root=0){
		dfs(root, -1);
		rep(i,2*n-1)rmq.update(i, dep[vs[i]]);
	}
	int lca(int u, int v){
		return vs[rmq.get(min(idx[u], idx[v]), max(idx[u], idx[v])+1)];
	}
	int distance(int u, int v){
		return dep[u]+dep[v]-2*dep[lca(u, v)];
	}
};

vector<P> edge;
int dis[2000][2000];
int n, k;
signed main(){
	scanf("%lld%lld", &n, &k);
	EulerTour tour;tour.init(n);
	rep(i,n-1){
		int x, y;
		scanf("%lld%lld", &x, &y);x--;y--;
		tour.add_edge(x, y);
		edge.pb(P(x, y));
	}
	tour.euler_tour();
	rep(i,n)rep(j,n)dis[i][j] = tour.distance(i, j);
	
	int ans = INF;
	if(k%2 == 1){
		rep(i,edge.size()){
			int u = edge[i].fi, v = edge[i].se, res = 0;
			rep(j,n)res += min(dis[u][j], dis[v][j]) > k/2;
			chmin(ans, res);
		}
	}else{
		rep(i,n){
			int res = 0;
			rep(j,n)if(dis[i][j] > k/2)res++;
			chmin(ans, res);
		}
	}
	
	printf("%lld\n", ans);
	return 0;
}







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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;


int main(){

    int x, t;
    cin >> x >> t;
    if(x < t) cout << 0 << endl;
    else cout << x - t << endl;
    
    return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0; i < n; i++)
#define repd(i, n) for (int i = n-1; i > -1; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;
using LP = pair<ll,ll>;
using P = pair<ll,int>;

int main()
{
    int n, m;
    cin >> n>> m;
    priority_queue<ll, vector<ll>> a;
    rep(i, n){
        ll x;cin >> x;
        a.push(x);
    }
    rep(i, m){
        ll u = a.top();a.pop();
        a.push(u/2);
    }
    ll ans = 0;
    rep(i, n) {
        ans += a.top();a.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 4312
#include<bits/stdc++.h>
using namespace std;
int mapp[4][4];
int visit[4][4];
int main()
{
	int n,pd=0,ii,i,j,x;
	for(i=1;i<=3;i++)
	for(j=1;j<=3;j++)
	{
		cin>>mapp[i][j];
	}
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>x;
		for(ii=1;ii<=3;ii++)
	    for(j=1;j<=3;j++)
	    {
	    	if(mapp[ii][j]==x)
	    	visit[ii][j]=1;
	    }
	    if(i>=3)
	    {
	    	if(visit[1][1]&&visit[1][2]&&visit[1][3]||
			visit[2][1]&&visit[2][2]&&visit[2][3]||
			visit[3][1]&&visit[3][2]&&visit[3][3]||
			visit[1][1]&&visit[2][2]&&visit[3][3]||
			visit[3][1]&&visit[2][2]&&visit[1][3]||
			visit[1][1]&&visit[2][1]&&visit[3][1]||
			visit[1][2]&&visit[2][2]&&visit[3][2]||
			visit[1][3]&&visit[2][3]&&visit[3][3])
			{
				cout<<"Yes";
				pd=1;
				break;
			}
	    }
	}
	if(pd==0)cout<<"No";
} 

Measured memory_bytes: 256
#include <cstdio>
#include <deque>
#include <utility>
#include <tuple>

using namespace std;

typedef tuple <int, int, char> iic;

#define INF 1000000005

int dirr[2] = {0, 1}, dirc[2] = {1, 0};

int H, W;
char grid[105][105];
int dist[105][105];
bool visited[105][105];
deque <iic> dq;

int main()
{
    scanf("%d%d", &H, &W);
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            scanf(" %c", &grid[i][j]);
            dist[i][j] = INF;
        }
    }
    dist[0][0] = grid[0][0] == '.' ? 0 : 1;
    dq.emplace_back(0, 0, grid[0][0]);
    while (!dq.empty())
    {
        int r, c; char prev; tie(r, c, prev) = dq.front(); dq.pop_front();
        if (visited[r][c]) continue;
        for (int i = 0; i < 2; i++)
        {
            int nr = r + dirr[i], nc = c + dirc[i];
            if (nr >= H || nc >= W) continue;
            if (grid[nr][nc] == '.' || grid[nr][nc] == prev)
            {
                dist[nr][nc] = min(dist[nr][nc], dist[r][c]);
                dq.emplace_front(nr, nc, grid[nr][nc]);
            }
            else
            {
                dist[nr][nc] = min(dist[nr][nc], dist[r][c] + 1);
                dq.emplace_back(nr, nc, grid[nr][nc]);
            }
        }
        //printf("(%d, %d): %d\n", r, c, dist[r][c]);
        visited[r][c] = true;
    }
    printf("%d\n", dist[H - 1][W - 1]);
    return 0;
}


Measured memory_bytes: 256
str=input()
n=int(input())
for i in range(n):
    s=input().split()
    a=int(s[1])
    b=int(s[2])
    if s[0] == 'replace':
        str=str[:a]+s[3]+str[b+1:]
    elif s[0] == 'reverse':
        str=str[:a]+str[a:b+1][::-1]+str[b+1:]
    else:
        print(str[a:b+1])

Measured memory_bytes: 7708
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Solve s= new Solve();
		s.solve();
	}

}
class Solve{
	 Scanner sc = new Scanner(System.in) ;
	 void solve() {
		 int N=sc.nextInt();
		 int A=sc.nextInt();
		 int B = sc.nextInt();
		 int res;
		 if(N*A<B) {
			 res=N*A;
		 }else {
			 res=B;
		 }

		 System.out.println(res);
	 }
}

Measured memory_bytes: 23252
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define UNIQUE(v) v.erase(unique(all(v)),v.end());
#define fill(a,x) memset(a,x,sizeof(a))
#define zero(a) fill(a,0)
#define minus(a) fill(a,-1)
#define dbg(x) cout << #x"=" << x << endl

const int INF=INT_MAX/3;
const int LIMIT=9;

int dx[]={0,-1,0,1};
int dy[]={1,0,-1,0};

int h,w;
string s[LIMIT];

bool dfs(int y,int x){
  if(s[y][x]=='.')return false;
  if(y==h-1&&x==w-1)return true;
  if(y>=h)return false;
  if(x>=w)return false;
  if(dfs(y+1,x))return true;
  if(dfs(y,x+1))return true;
}

bool check(){
  rep(i,h){
    rep(j,w){
      if(i+1<h&&j+1<w&&s[i+1][j]=='#'&&s[i][j+1]=='#') return false;
    }
  }
  return true;
}

int main(){
  cin>>h>>w;
  rep(i,h)cin>>s[i];
  if(dfs(0,0)&&check())cout<<"Possible"<<endl;
  else cout<<"Impossible"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <string.h>

#include <algorithm>
#include <iostream>
#include <vector>

#define rep1(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define MOD 1000000007

using namespace std;
using ll = long long;

/****************************************************************************************
  Union-Find
  ****************************************************************************************/
struct UnionFind {
  vector<int> par;  // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

  UnionFind(int N) : par(N) {  //最初は全てが根であるとして初期化
    for (int i = 0; i < N; i++) par[i] = i;
  }

  int root(int x) {  // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  // xとyの木を統合. （x,yのそれぞれの根の内、値が小さいほうに統合される）
  // 例：root(x) = 1, root(y) == 5　なら root(y) = 1　になる
  bool unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) {
      return false;
    } else {
      if (rx > ry) swap(rx, ry);
      par[ry] = rx;
    }
    return true;
  }
  // 2つのデータx, yが属する木が同じならtrueを返す
  bool isSame(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }

  //根確認用
  // for (int i = 0; i < N; i++)
  // cout << "UF.par[" << i << "] = " << UF.par[i] << endl;
};

int main(void) {
  int N, M;
  cin >> N >> M;

  UnionFind UF(N);  //都市集合を作成（最初はそれぞれの根は自分自身）
  int A, B;
  for (int i = 0; i < M; i++) {
    cin >> A >> B;
    UF.unite(A - 1, B - 1);  //都市は1~N, で配列は0~(N-1)なので-1して代入
  }

  int cnt = 0;

  // rootが自分自身の番号と同じデータの数だけ都市集合が存在する
  for (int i = 0; i < N; i++) {
    if (UF.root(UF.par[i]) == i) {
      cnt++;
    }
    // cout << "i:" << i << "     par[" << i << "]:" << UF.par[i]<< " root:" <<
    // UF.root(UF.par[i]) << "   cnt:" << cnt << endl;
  }

  int ans = (cnt - 1);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3788
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 303,mo=998244353;
bitset<N>a[N],s;bool vis[N];
int n,m;
inline int power(int a, int n) {
	int res=1;
	while (n) {
		if (n&1) res=1LL*res*a%mo;
		a=1LL*a*a%mo; n>>=1;
	}
	return res;
}
bool ins(bitset<N>s){
	rep(i,1,m)if(s[i])
		if(!vis[i]){a[i]=s;vis[i]=1;return 1;}
		else s^=a[i];
	return 0;
}
int main() {
	read(n);read(m);int tot=n;
	rep(i,1,n){
		s.reset();
		rep(j,1,m){int x;read(x);s[j]=x;}
		tot-=ins(s);
	}
	int res=(power(2,n+m-1)-power(2,m-1+tot)+mo)%mo;
	cout<<res;
	return 0;
}


Measured memory_bytes: 256
//ABC87A
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	int x, a, b;
	cin >> x >> a >> b;
	int ans = (x-a)%b;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
L=[]
X=[]
for i in range(N):
	L.append(input())
for i in range(M):
	X.append(input())
for i in range(N-M+1):
	for j in range(N-M+1):
		if L[i][j]==X[0][0]:
			ans=0
			for x in range(M):
				for y in range(M):
					if L[i+x][j+y]==X[x][y]:
						ans+=1
			if ans==(M**2):
				print("Yes")
				exit()
print("No")

Measured memory_bytes: 3064
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <math.h> // sqrt
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <iomanip> // setprecision
#include <bitset> // bitset
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;

ll mod = 1000000007;

ll modpow(ll x, ll n) {
    x %= mod;
    if (n == 0) {
        return 1;
    }
    if (n % 2 == 1) {
        return (x * modpow(x, n - 1)) % mod;
    }
    else {
        return modpow((x * x) % mod, n / 2) % mod;
    }
}

int main() {
    ll N;
    cin >> N;
    if (N == 1) {
        cout << 0 << endl;
        return 0;
    }
    else {
        ll sum = modpow(10, N);
        ll mi = (modpow(9, N) * 2) % mod;
        ll mi2 = modpow(8,N);
        if (mi < mi2) {
            mi += mod;
        }
        mi = (mi - mi2) % mod;
        if (sum < mi) {
            sum += mod;
        }
        ll ans = sum - mi;
        cout << ans<< endl;
    }
}


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

using namespace std;
#define ll long long int

int main()
{
    int A, B, C, X, Y;

    cin >> A >> B >> C >> X >> Y;
    int min = INT_MAX;
    int res;

    for (int i = 0; i <= 1e5; i++)
    {
        res = i * 2 * C + max(0, X - i) * A + max(0, Y - i) * B;
        if (min > res)
        {
            min = res;
        }
    }

    cout << min;
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <typeinfo>
#include <numeric>
#include "math.h"
#include <string>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <numeric>
using namespace std;

//Easy Linear Programming
int main() {
	int a, b, c, k,cnt=0;

	cin >> a >> b >> c >> k;

	for (int i = 0; i < k; i++) {
		if (a > 0) {
			cnt++;
			a--;
		}
		else if (b > 0) {
			b--;
		}
		else if (c>0) {
			cnt--;
			c--;
		}

	}
	cout << cnt;

	return 0;	
}

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

typedef long long ll;
#define rep(i, n) for(int i = 0; i < n; i++)

const int lim = 1000000007;

int main(){
    int x;
    cin >> x;
    if(x == 0) cout << 1 << endl;
    if(x == 1) cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 3632
# ????¨???§3????????£?????????????¢????
def completed_char(board)
  completed_line = board.find do |a, b, c|
    a != 's' && a == b && b == c
  end

  return completed_line.first if completed_line

  completed_line = board.transpose.find do |a, b, c|
    a != 's' && a == b && b == c
  end

  completed_line ? completed_line.first : nil
end

readlines.each do |line|
  board = line.chomp.chars.each_slice(3).map.to_a

  if char = completed_char(board)
    puts char
    next
  end

  # ????????§3????????£?????????????¢????
  unless board[1][1] == 's'
    if (board[0][0] == board[1][1] && board[1][1] == board[2][2]) or
       (board[2][0] == board[1][1] && board[1][1] == board[0][2])
      puts board[1][1]
      next
    end
  end

  puts 'd'
end

Measured memory_bytes: 8668
Module Module1

    Sub Main()

        Dim tmp As String() = Split(Console.ReadLine(), " ")
        Dim N As Integer = CInt(tmp(0)) ' 日数
        Dim M As Integer = CInt(tmp(1)) ' 宿題数
        Dim tmp2 As String() = Split(Console.ReadLine(), " ")

        Dim wd = 0
        For i As Integer = 0 To M - 1
            wd += CInt(tmp2(i))
        Next

        If N >= wd Then
            Console.WriteLine(N - wd)
        Else
            Console.WriteLine(-1)
        End If

        Console.ReadLine()

    End Sub

End Module


Measured memory_bytes: 46808
N = map(int, raw_input().split())[0]
A = map(int, raw_input().split())
kasanari = 1
c = 0
for i in range(0,N-1):
    if A[i]==A[i+1]:
        kasanari = kasanari + 1
    else:
        c = c + kasanari/2
        kasanari = 1
c = c + kasanari/2
print(c)

Measured memory_bytes: 2568
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
  }

#[fastout]
fn main() {
    input!{
        n: usize,
        s: Chars,
    }

    let mut ans = 0;
    for cut in 1..n {
        let mut alpha_front: Vec<usize> = vec![0;30];
        let mut alpha_back: Vec<usize> = vec![0;30];
        let mut cnt = 0;
        for i in 0..cut {
            alpha_front[(s[i] as usize) - ('a' as usize)] += 1;
        }
        for i in cut..n {
            alpha_back[(s[i] as usize) - ('a' as usize)] += 1;
        }
        for i in 0..30 {
            if alpha_front[i]!=0 && alpha_back[i]!=0 {
                cnt += 1;
            }
        }
        debug!(alpha_front);
        ans = max(ans, cnt);

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


Measured memory_bytes: 2156
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 10000000000
using namespace std;
using ll = long long;
int main()
{
    int n;
    cin >> n;
    vector<int> x(n),y(n);
    rep(i, n){
        cin >> x[i];
    }
    y = x;
    sort(x.begin(), x.end());
    int a1 = (n-1) / 2;
    int a2 = n / 2;
    rep(i,n){
        if(y[i] <= x[a1]){
            cout << x[a2] << endl;
        }else{
            cout << x[a1] << endl;
        }
    }
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,e) for (int i=s;i<e;i++)
#define FOE(i,s,e) for (int i=s;i<=e;i++)
#define FOD(i,s,e) for (int i=s;i>=e;i--)
#define SET(a,e) memset(a,e,sizeof(a))
#define LL long long
#define LD long double
#define pb push_back
#define x first
#define y second
#define PII pair<int,int>
#define PLI pair<LL,int>
#define PIL pair<int,LL>
#define PLL pair<LL,LL>
#define PDD pair<LD,LD>
#define eps 1e-9
#define HH1 402653189
#define HH2 1610612741

int n, a, b, h[100055];

int main () {
	
	scanf("%d%d%d", &n, &a, &b);
	
	FOR(i, 0, n) {
		scanf("%d", h + i);
	}
	
	int lo = 0, hi = 1e9 + 1;
	
	while (lo + 1 < hi) {
		
		LL cost = 0;
		
		int mid = (lo + hi) / 2;
		
		FOR(i, 0, n) if (h[i] > (LL)mid * b) cost += (h[i] - mid * b - 1) / (a - b) + 1;
		
		if (cost <= mid) hi = mid;
		else lo = mid;
	}
	
	printf("%d\n", hi);
	
	return 0;
	
}

Measured memory_bytes: 640
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

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

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

/*
ll fac[MAX], finv[MAX], inv[MAX];
void init_comb(){
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for(int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

ll comb(int n, int k){
  if(n < k) return 0;
  if(n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
*/

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

  int x, y, z, k;
  cin >> x >> y >> z >> k;
  ll a[x], b[y], c[z];
  for(int i = 0; i < x; i++){
    cin >> a[i];
  }
  for(int i = 0; i < y; i++){
    cin >> b[i];
  }
  for(int i = 0; i < z; i++){
    cin >> c[i];
  }

  ll d[x * y];
  for(int i = 0; i < x; i++){
    for(int j = 0; j < y; j++){
      d[i * x + j] = a[i] + b[j];
    }
  }
  sort(d, d + x * y);

  vector< ll > e;
  for(int i = x * y - 1; i >= max(0, x * y - k); i--){
    for(int j = 0; j < z; j++){
      e.push_back(d[i] + c[j]);
    }
  }
  sort(e.begin(), e.end());

  string buf;
  for(int i = 0; i < k; i++){
    buf += to_string(e[e.size() - i - 1]) + "\n";
  }
  cout << buf;

  return 0;
}


Measured memory_bytes: 42980
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")

//# include <x86intrin.h>
# include <bits/stdc++.h>

# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
 
template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define _USE_MATH_DEFINES_
#define ll unsigned long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
	// cin.exceptions(cin.failbit); 
	// throws exception when do smth illegal
	// ex. try to read letter into int
	if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 55;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
 
int rnd (int l, int r) {
	return uniform_int_distribution<int> (l, r)(gen);
}
 
int n, m, k;
ll C[N][N];
int a[N];
int dp[(1<<18)];
const int L = 18;

int main () {
	SpeedForce;
	setIO();
	
	int s, t;
	cin >> n >> k >> s >> t;
	for(int i = 1; i <= n; ++i) {
		cin >> a[i];
		if((s&a[i]) == s && (t|a[i]) == t) {
			continue;
		}
		--i, --n;
	}

	C[0][0] = 1;
	For (i, 1, n) {
		C[i][0] = 1;
		For (j, 1, i) {
			C[i][j] = C[i-1][j-1] + C[i-1][j];
		}
	}

	int goal = (~s)&t;
	ll ans = 0;
	For (i, 1, n) {
		memset(dp, 0, sizeof dp);
		For (j, i+1, n) {
			int msk = ((a[i] ^ a[j])&goal);
			dp[msk] ++;
		}
		for (int bit = 0; bit < L; ++bit) {
			for(int msk = 0; msk < (1<<L); ++msk) if(!(msk&(1<<bit))) {
				dp[msk^(1<<bit)] += dp[msk];
				
			}
		}

		for (int msk = goal; ; msk = (msk-1)&goal) {
			int tot = dp[msk];
			ll sum = 0; 
			for(int i = 0; i < k; ++i)
				sum += C[tot][i];

			if (__builtin_popcount(msk^goal)%2 == 0) ans += sum;
			else ans -= sum;

			if(!msk) break;
		}
	}

	cout << ans << endl;

	return Accepted;
}

// B...a

Measured memory_bytes: 4604
def include3?(x)
  if x % 10 == 3
    true
  elsif x != 0
    include3?(x / 10)
  else
    false
  end
end

n = gets.chomp.to_i

(1..n).each do |i|
  if i % 3 == 0 || include3?(i)
    print " #{i}"
  end
end
puts

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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t sx, sy, tx, ty;
  std::cin >> sx >> sy >> tx >> ty;
  for (int64_t i = 0; i < ty - sy; i++) {
    std::cout << 'U';
  }
  for (int64_t i = 0; i < tx - sx; i++) {
    std::cout << 'R';
  }
  for (int64_t i = 0; i < ty - sy; i++) {
    std::cout << 'D';
  }
  for (int64_t i = 0; i < tx - sx; i++) {
    std::cout << 'L';
  }

  std::cout << 'L';
  for (int64_t i = 0; i < ty - sy; i++) {
    std::cout << 'U';
  }
  std::cout << 'U';
  std::cout << 'R';
  for (int64_t i = 0; i < tx - sx; i++) {
    std::cout << 'R';
  }
  std::cout << 'D';

  std::cout << 'R';
  for (int64_t i = 0; i < ty - sy; i++) {
    std::cout << 'D';
  }
  std::cout << 'D';
  std::cout << 'L';
  for (int64_t i = 0; i < tx - sx; i++) {
    std::cout << 'L';
  }
  std::cout << 'U';
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int i;
	int a[25];
	int j;
	int ohajiki;
	int k;
	
	while (1){
		ohajiki = 32;
		scanf("%d", &i);
		if (i == 0){
			break;
		}
		
		for (j = 0;j < i; j++){
			scanf("%d", &a[j]);
		}
		
		for (j = 0, k = 0; ohajiki != 0; j++){
			if (j % 2 == 0){
				ohajiki -= (ohajiki - 1) % 5;
			}
			else {
				if (k == i){
					k = 0;
				}
				ohajiki -= a[k];
				k++;
			}
			if (ohajiki < 0){
				ohajiki = 0;
			}
			printf("%d\n", ohajiki);
		}
	}
	
	return (0);
}

Measured memory_bytes: 596
n = int(input())

for h in range(1,3501):
    for w in range(1,3501):
        if 4 * h * w - n * w - n * h != 0:
            N = (n * h * w) / (4 * h * w - n * w - n * h)
            if N.is_integer() and N > 0:
                print(h,w,int(N))
                exit()


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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;


int main() {

    ll n,MIN=inf;
    cin>>n;

    for(ll i=1;i*i<=n;i++){
        if(n%i==0&&n/i+i-2<MIN){
            MIN=n/i+i-2;
        }
    }
    cout<<MIN<<endl;
}


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

template <typename T>
class sparse_table {
	const int n;
	vector<vector<T>> t;
	T merge(const T& l, const T& r) const {
		return max(l, r);
	}
public:
	sparse_table(const vector<T>& b) : n(b.size()), t(1, b) {
		for (int i = 2, j = 1, p = 0; i <= n; i <<= 1, j++, p = 0) {
			t.emplace_back(n);
			for (int k = 0; k + i <= n; k++)
				t[j][p++] = merge(t[j - 1][k], t[j - 1][k + (i >> 1)]);
		}
	}
	T find(int l, int r) const { // [l, r)
		assert(0 <= l && l < r && r <= n);
		int i = 31 - __builtin_clz(r - l);
		return merge(t[i][l], t[i][r - (1 << i)]);
	}
};

int main()
{
	int N;
	cin >> N;
	vector<ll> P(N);
	for (int i = 0; i < N; i++) {
		cin >> P[i];
	}
	sparse_table<ll> st(P);
	vector<int> tor(N + 1), tol(N + 1);
	for (int i = 0; i < N; i++) {
		{
			int lb = -1, ub = i;
			while (ub - lb > 1) {
				int m = (lb + ub) / 2; 
				(st.find(m, i + 1) == P[i] ? ub : lb) = m;
			}
			tol[i] = lb;
		}
		{
			int lb = i + 1, ub = N + 1;
			while (ub - lb > 1) {
				int m = (lb + ub) / 2;
				(st.find(i, m) == P[i] ? lb : ub) = m;
			}
			tor[i] = lb;
		}
	}
	ll res = 0;
	for (int i = 0; i < N; i++) {
		ll val = 0;
		if (tor[i] < N) {
			int lb = tor[i] + 1, ub = N + 1;
			while (ub - lb > 1) {
				int m = (lb + ub) / 2;
				(st.find(tor[i] + 1, m) <= P[i] ? lb : ub) = m;
			}
			val += (i - tol[i]) * (lb - tor[i]);
		}
		if (0 <= tol[i]) {
			int lb = -1, ub = tol[i];
			while (ub - lb > 1) {
				int m = (lb + ub) / 2;
				(st.find(m, tol[i]) <= P[i] ? ub : lb) = m;
			}
			val += (tol[i] - lb) * (tor[i] - i);
		}
		res += val * P[i];
	}
	cout << res << endl;
	return 0;
}


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

int main() {
	string s;
	cin >> s;
	vector<int> ans;
	int cntr = 0, cntl = 0;
	int indr, indl;
	for (int i = 0; i < s.size(); i++) {
		ans.push_back(0);
		if (s[i] == 'R')
			cntr++;
		else if (s[i] == 'L')
			cntl++;
		if (s[i] == 'R' && s[i + 1] == 'L') {
			indr = i;
			indl = i + 1;
		} else if ((s[i] == 'L' && s[i + 1] == 'R') || i == s.size() - 1) {
			if (cntr % 2 == 0) {
				ans[indl] += cntr / 2;
				ans[indr] += cntr / 2;
			} else {
				ans[indl] += cntr / 2;
				ans[indr] += cntr / 2 + 1;
			}
			if (cntl % 2 == 0) {
				ans[indl] += cntl / 2;
				ans[indr] += cntl / 2;
			} else {
				ans[indl] += cntl / 2 + 1;
				ans[indr] += cntl / 2;
			}
			cntr = 0;
			cntl = 0;
		}
	}
	for (int i = 0; i < s.size(); i++) {
		cout << ans[i] << " ";
	}
	return 0;
}


Measured memory_bytes: 1144
#include<iostream>

using namespace std;

int main() {
    int m;
    cin >> m;
    for (; m>0; m--) {
        int init, years, n, cost, fund_max;
        double rate;
        bool is_compound;
        cin >> init >> years >> n;
        fund_max = init;
        for (; n>0; n--) {
            cin >> is_compound >> rate >> cost;
            int fund = init;
            if (is_compound) {
                for (int y=0; y<years; y++) {
                    fund = (int)(fund*rate+fund-cost);
                }
            }
            else {
                int interest = 0;
                for (int y=0; y<years; y++) {
                    interest += (int)(fund*rate);
                    fund = fund-cost;
                }
                fund += interest;
            }
            fund_max = fund_max>fund? fund_max: fund;
        }
        cout << fund_max << endl;
    }
    return 0;
}

Measured memory_bytes: 1232
#include <cstdio>
struct Istream {
	template <class T>
	Istream &operator >>(T &x) {
		static char ch;static bool neg;
		for(neg=0,ch=0;ch<'0' || '9'<ch;neg|=ch=='-',ch=getchar());
		for(x=0;'0'<=ch && ch<='9';(x*=10)+=ch-'0',ch=getchar());
		x=neg?-x:x;
		return *this;
	}
}is;
struct Ostream {
	template <class T>
	Ostream &operator <<(T x) {
		x<0 && (putchar('-'),x=-x);
		static char stack[233];static int top;
		for(top=0;x;stack[++top]=x%10+'0',x/=10);
		for(top==0 && (stack[top=1]='0');top;putchar(stack[top--]));
		return *this;
	}
	Ostream &operator <<(char ch) {
		putchar(ch);
		return *this;
	}
}os;
const int MAXN=100+11,INF=0x1f1f1f1f;
template <class T> inline
bool chkmn(T &a,T const &b) {
	return a>b?a=b,1:0;
}
int main() {
//	freopen("input","r",stdin);
	int n;is>>n;
	static int a[MAXN];
	int sum=0;
	for(int i=1;i<=n;++i) {
		is>>a[i];
		sum+=a[i];
	}
	if(sum%10==0) {
		int minv=INF;
		for(int i=1;i<=n;++i) {
			if(a[i]%10!=0) {
				chkmn(minv,a[i]);
			}
		}
		if(minv==INF) {
			sum=0;
		} else {
			sum-=minv;
		}
	}
	os<<sum<<'\n';
	return 0;
}




Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int,int>;
#define int long long
signed main()
{
    int a,b;cin >>a >> b;
    int ans = (a-1)*(b-1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
static const int INF (1<<30);

int main() {
  int P, Q, R;
  cin >> P >> Q >> R;

  int ans = min(P+Q, min(Q+R, P+R));

  cout << ans << endl;

  return 0;
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

map<int, int> mp;

void solve() {
  int n; scanf("%d", &n);
  for (int x, i = 0; i < n; ++i) {
    scanf("%d", &x);
    ++mp[x];
  }
  int m; scanf("%d", &m);
  for (int t, i = 0; i < m; ++i) {
    scanf("%d", &t);
    if (mp[t] > 0) {
      --mp[t];
    } else {
      puts("NO");
      return;
    }
  }
  puts("YES");
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


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

#define infile "../test/sample-1.in"
#define int long long
// #define INF 2147483647
#define INF 1000000000000000000LL
#define MOD 1000000007LL

// {{{ define basic macro
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) repi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)

#define foreach(x,a) for(auto& (x) : (a) )
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

#define all(x) (x).begin(),(x).end()
#define sum(v) accumulate(all(v), 0)
#define sz(x) ((int)(x).size())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
#define fill(x,y) memset(x,y,sizeof(x))
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)

template <class T = int>
T in() {T x; cin>>x; return (x);}

struct Fast {
  Fast(){
    std::cin.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;
// }}}
//{{{ dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}
//{{{ others
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
//}}}


int solve(){
  int n,m;cin>>n>>m;
  int a[n+1]={};
  rep(i, n){
    cin>>a[i+1];
  }

  rep(i, n){
    a[i+1] += a[i];
  }
  dump_1d(a, n+1);

  map<int, int> cnt;
  rep(i, n+1){
    a[i] %= m;
    cnt[a[i]%m]++;
  }

  dump_1d(a, n+1);

  int res = 0;
  foreach(x, cnt){
    int p = x.second;
    res += p*(p-1)/2;
  }
  cout << res << endl;

  return 0;
}

int test(){ //{{{
  return 0;
}
//}}}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
#ifdef PCM
  test();
#endif
  solve();
  return 0;
} //}}}


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

long long const MOD = 1000000007LL;
long long comb[2001][2001];

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

    for (int i = 0; i <= n; i++) {
        comb[i][0] = 1;
        for (int j = 1; j <= i; j++) {
            comb[i][j] = (comb[i - 1][j - 1] + comb[i - 1][j]) % MOD;
        }
    }

    for (int i = 1; i <= k; i++) {
        int res = (comb[n - k + 1][i] * comb[k - 1][i - 1]) % MOD;
        cout << res << endl;
    }
}

Measured memory_bytes: 30080
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
  
using namespace std;
using namespace __gnu_pbds;
 
#define ll long long
#define uint unsigned int
#define ull  unsigned long long
#define pb push_back
#define mk make_pair
#define ins insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define X first
#define Y second
#define umap unordered_map
#define speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define setvalue(d,s,e,n) for(int qwe = s; qwe < e; ++qwe) d[qwe] = n
#define mset multiset
#define pqueue priority_queue
   
template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
        
const int  N = 2e5 + 314;
const int INF = 1e9;
const double PI = acos(-1);
int MOD = 1e9 + 7;
const double eps = 1e-9;
const long long LINF = 1e18 + 3141;
ll bp(ll a, ll n){
    ll res = 1;
    while(n) {
        if(n & 1)
            res = (res * a) % MOD;
        a = (a * a) % MOD;
        n >>= 1;
    }
    return res;
}
ll get(ll n, vector <ll> &pf, vector <ll>& cyc) {
    ll ans = 0;
    ll pfsz = pf.size(), csz = cyc.size();
    // cout << pfsz << ' ' << csz << '\n';
    for(int i = 0; i < min(n, pfsz); ++i)
        ans += pf[i];
    if(n <= pfsz)
        return ans;
    n -= pf.size();
    ll sumcyc = accumulate(all(cyc), 0ll);
    ans += n / cyc.size() * sumcyc; 
    for(int i = 0; i < n % cyc.size(); ++i)
        ans += cyc[i];
    return ans; 
}
void solve(){
    ll n, x;
    cin >> n >> x >> MOD;
    vector <ll> t;
    t.pb(-1);
    t.pb(x);
    map <ll, int> fid;
    fid[x] = 1;
    ll e = n + 1, pv = x;
    for(int i = 2; i <= n; ++i) {
        ll cur = pv * pv % MOD;
        if(fid[cur]) {
            e = fid[cur];
            break;
        }
        fid[cur] = i;
        t.pb(cur);
        pv = cur;
    }
    vector <ll> pf, cyc;
    for(int i = 1; i < e; ++i) 
        pf.pb(t[i]);
    
    for(int i = e; i < t.size(); ++i) 
        cyc.pb(t[i]);
    
    cout << get(n, pf, cyc);
}
 
int main(){
    // speed();
    int t = 1;
    // cin >> t;
    while(t--)solve();
}

Measured memory_bytes: 7452
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <array>
#include <deque>
#include <bitset>
typedef long long ll;
using namespace std;
#define trace(x) cerr << #x << " is " << x << endl;




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

    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    ll res = 0;
    priority_queue<int> q;
    q.push(a[n - 1]);
    for (int i = n - 2; i >= 0; i--) {
        res += q.top();
        q.pop();
        q.push(a[i]);
        q.push(a[i]);
    }
    cout << res <<endl;
    return 0;
}


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

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

    vector<string> v;
    rep(i, n) {
        string s;
        cin >> s;
        v.pb(s);
    }
    sort(all(v));

    for(auto p : v) {
        cout << p;
    }

    cout << endl;
    re0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

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

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a*b/gcd(a,b);
}

signed main(){
  int a,b;
  cin >> a >> b;
  cout << a+ b/2 << endl;
}

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

int main() 
{
    int n, count=0;
    int A[201];

    cin >> n;
    for(int i=0; i<n; i++) cin >> A[i];

    while(true){
        for(int i=0; i<n; ++i){
            if(A[i]%2){
                cout << count << endl;
                return 0;
            }
        }    
        for(int i=0; i<n; ++i){
            A[i] /= 2; 
        }
        ++count;
    }
}

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

int main()
{
    string s,t,u;
    int a,b;
    cin>>s>>t;
    cin>>a>>b;
    cin>>u;
    if(u == s)
    {
        a = a - 1;
    }
    else
    {
        b = b - 1;
    }
    cout<<a<<" "<<b;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) REP(i, 0, n)
#define REP(i, l, r) for (int i = l; i < r; i++)
using namespace std;
typedef pair<int, int> P;
struct edge {
	int to, cost;
};
class dijkstra {
  private:
	int V;
	int d[100002];
	priority_queue<P, vector<P>, greater<>> que;

  public:
    dijkstra(int v, int s, vector<edge> G[]) {
        V = v;
        update(s, G);
    }

    void update(int s, vector<edge> G[]) {
        fill(d, d + V + 1, 100000000000ll);
        d[s] = 0;
        que.push(make_pair(0, s));
        while (!que.empty()) {
            P p = que.top();
            que.pop();
            int v = p.second;
            if (d[v] < p.first)
                continue;
            rep(i, G[v].size()) {
                edge e = G[v][i];
                if (d[e.to] > d[v] + e.cost) {
                    d[e.to] = d[v] + e.cost;
                    que.push(make_pair(d[e.to], e.to));
                }
            }
        }
    }

	int find(int e) {
		return d[e];
	}
};

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

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

bool prime(int a) {
	if (a == 1)
		return false;
	for (int i = 2; i * i <= a; i++) {
		if (a % i == 0)
			return false;
	}
	return true;
}

class Union_Find {
  private:
	vector<int> t, s;

  public:
	Union_Find(int max_length) {
		rep(i, max_length + 1) {
			t.push_back(i);
			s.push_back(1);
		}
	}

	void Union(int x, int y) {
		if (same(x, y))
			return;
		int tx = Find(x), ty = Find(y);
		if (s[tx] < s[ty]) {
			s[ty] += s[tx];
			t[tx] = ty;
		}
		else if (s[tx] > s[ty]) {
			s[tx] += s[ty];
			t[ty] = tx;
		}
		else if (tx > ty) {
			t[tx] = ty;
			s[ty] += s[tx];
		}
		else {
			t[ty] = tx;
			s[tx] += s[ty];
		}
	}

	int Find(int n) {
		if (t[n] == n)
			return n;
		else
			return t[n] = Find(t[n]);
	}

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

	int get_Size(int a) {
		return s[a];
	}
};

vector<int> primeFactorization(int n) {
	vector<int> re;
	int cnt = 2;
	while (n != 1) {
		if (n % cnt != 0) {
			cnt++;
			continue;
		}
		n /= cnt;
		re.push_back(cnt);
	}
	return re;
}

signed main() {
    int n,x;
    cin>>n>>x;
    int ans=1,cnt=0;
    rep(i,n){
        int l;
        cin>>l;
        cnt+=l;
        if(cnt<=x)ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;

const ll MOD = 1e9+7;
const int MAX_BIT = 62;

namespace mp = boost::multiprecision;


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

  ll A[N];
  rep(i, N)
    cin >> A[i];

  mp::cpp_int ans = 0;
  int bit[MAX_BIT];
  rep(i, MAX_BIT) bit[i] = 0;
  rep(i, N) {
    rep(j, MAX_BIT) {
      if (A[i] & (1LL << j))
        ++bit[j];
    }
  }
  rep(i, N-1) {
    mp::cpp_int tmp = 0;
    rep(j, MAX_BIT) {
      if (A[i] & (1LL << j))
        --bit[j];
    }
    rep(j, MAX_BIT) {
      int count = A[i] & (1LL << j) ? (N-i-1 - bit[j]) : bit[j];
      tmp += (mp::cpp_int)count * 1LL << j;
      tmp %= MOD;
    }
    ans += tmp;
    ans %= MOD;
  }
  cout << ans << "\n";

  return 0;
}


Measured memory_bytes: 2560
// C - Cat Snuke and a Voyage
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N,M; cin>>N>>M;
	vector<char> P(N);
	while(M--){
		int a,b; cin>>a>>b;
		if(a==1) P[b-1] |= 1;
		if(b==N) P[a-1] |= 2;
		if(P[a-1]==3 || P[b-1]==3) break;
	}
	puts(M<0?"IMPOSSIBLE":"POSSIBLE");
}

Measured memory_bytes: 384
N = int(input())
A = list(map(int,input().split()))
K = max(A)
ls = [0 for i in range(K+2)]
for i in range(N):
    if A[i] == 0:
        ls[A[i]] += 1
        ls[A[i]+1] += 1
    else:
        ls[A[i]-1] += 1
        ls[A[i]] += 1
        ls[A[i]+1] += 1
print(max(ls))

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int n, m;cin >> n >> m;
    map<int, int> mp;
    inc(i, 0, n){
        int k;cin >> k;
        inc(j, 0, k){
            int a;cin >> a;
            mp[a]++;
        }
    }
    int ans = 0;
    for(auto kv : mp){
        if(kv.se == n) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256