akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define pb  					push_back
#define mp 						make_pair
#define all(v) 					((v).begin()) ,((v).end())
#define let(o,v)				memset(o,v,sizeof (o))
typedef long long 				ll;
typedef vector<int>				vi;
typedef vector<vi>				vvi;
typedef vector<string>			vs;

const int MOD = (int)1e9 + 7;
const int oo = (int)1e9;
const ll OO = (ll)1e18;
const double PI = acos(-1.0);
const int N = (int)1e6 + 9;

bool isprime(int n) {
	if (n <= 1)
		return 0;
	for (int i = 2; i*i <= n; i++)
		if (n%i == 0)
			return false;
}
ll intlog(ll base, ll x) {
	return (log(x) / log(base));
}
bool prime[N];
void primee()
{

	for (int p = 2; p*p <= N; p++)
	{

		if (prime[p] == true)
		{
			for (int i = p * 2; i < N; i += p)
				prime[i] = false;
		}
	}

}
string decToBinary(ll n)
{
	string z = "";
	int i = 0;
	while (n > 0) {

		z += (n % 2) + 48;
		n = n / 2;
		i++;
	}
	reverse(all(z));
	return z;
}

int main()
{
	int n, x;
	scanf("%d%d", &n,&x);
	vector<int> v(n);
	ll sum = 0;
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &v[i]);
		sum += v[i];
	}
	if (sum == (ll)x) printf("%d\n", n);
	else {
		sort(all(v));
		int ans = -1;
		for (int i = 0; i < n; i++)
		{
			
			x -= v[i];
			if (x >= 0) ans = i;
			else break;
		}
		if (x > 0) printf("%d\n", n - 1);
		else {
			printf("%d\n", ans + 1);
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>
#include <map>

template <class T>
struct fix_point: private T {
  explicit constexpr fix_point(T &&func): T(std::forward<T>(func)) { }
  template <class... Args>
  constexpr decltype(auto) operator () (Args &&... args) const {
    return T::operator()(*this, std::forward<Args>(args)...);
  }
};

template <class T>
constexpr decltype(auto) make_fix_point(T &&func) {
  return fix_point<T>(std::forward<T>(func));
}

constexpr int inf = 1000000000;

int main() {
  int N, M;
  std::cin >> N >> M;
  std::vector<int> D(N);
  for (auto &x: D) {
    std::cin >> x;
  }
  std::vector<std::vector<int>> graph(N);
  std::map<std::pair<int, int>, int> edge;
  for (int i = 0; i < M; ++i) {
    int u, v;
    std::cin >> u >> v;
    --u; --v;
    graph[u].push_back(v);
    graph[v].push_back(u);
    edge[std::minmax(u, v)] = i;
  }
  std::vector<std::vector<int>> forest(N);
  for (int i = 0; i < N; ++i) {
    int to = -1;
    for (auto j: graph[i]) {
      if (to == -1 || D[to] > D[j] || (D[to] == D[j] && to > j)) {
        to = j;
      }
    }
    if (to == -1 || D[to] > D[i]) {
      std::cout << "-1\n";
      return 0;
    }
    forest[i].push_back(to);
    forest[to].push_back(i);
  }
  std::vector<bool> done(N), color(N);
  std::vector<int> cost(M, inf);
  auto dfs = make_fix_point([&](auto dfs, int u, int p) -> void {
    if (done[u]) {
      return;
    }
    done[u] = true;
    if (p != -1) {
      color[u] = !color[p];
      cost[edge[std::minmax(u, p)]] = D[u];
    }
    for (auto v: forest[u]) {
      dfs(v, u);
    }
  });
  std::vector<int> order(N);
  std::iota(order.begin(), order.end(), 0);
  std::stable_sort(order.begin(), order.end(), [&](int i, int j) {
    return D[i] < D[j];
  });
  for (auto u: order) {
    dfs(u, -1);
    continue;
  }
  for (auto x: color) {
    std::cout << "BW"[x];
  }
  std::cout << '\n';
  for (auto x: cost) {
    std::cout << x << '\n';
  }
  return 0;
}


Measured memory_bytes: 28220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
const ll INF = (1ll << 60);
typedef pair<ll,ll> pii;
typedef pair<pii,pii> ppii;
pii operator*(pii p,ll i) {p.first*=i; p.second*=i; return p;}
pii operator*(ll i,pii p) {p.first*=i; p.second*=i; return p;}
pii operator+(pii p1,pii p2) {p1.first+=p2.first; p1.second+=p2.second; return p1;}
pii operator-(pii p1,pii p2) {p1.first-=p2.first; p1.second-=p2.second; return p1;}

pii extendedEuclid(ll a,ll b){
  bool swapped=false;
  if(a<b) {swap(a,b);swapped=true;}
  pii x={1,0},y={0,1};
  while(1){
    ll xv=a*x.first+b*x.second;
    ll yv=a*y.first+b*y.second;
    if(yv==0) if(swapped) return {x.second,x.first}; else return x;
    ll d=xv/yv;
    swap(x,y);
    y.first-=d*x.first;
    y.second-=d*x.second;
  }
}

int main(){
  ll a,b;cin>>a>>b;
  pii ans=extendedEuclid(a,b);
  cout<<ans.first<<' '<<ans.second<<endl;
}

Measured memory_bytes: 3120
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
	int w, d;

	while (cin >> w >> d && w != 0 || d != 0)
	{
		int ans = 0;
		int binw[21];
		int bind[21];
		for (int i = 0; i < 21; i++)binw[i] = 0;
		for (int i = 0; i < 21; i++)bind[i] = 0;
		int h;
		for (int i = 0; i < w; i++)
		{
			cin >> h;
			binw[h]++;
		}
		for (int i = 0; i < d; i++)
		{
			cin >> h;
			bind[h]++;
		}
		for (int i = 0; i < 21; i++)
		{
			int mi = min(binw[i], bind[i]);
			int ma = max(binw[i], bind[i]);
			int diff = ma - mi;
			ans += (diff + mi) * i;

		}
		cout << ans << endl;


	}
	return 0;
}

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

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);
}
long long com[51][51];

int main() {
  int n, a, b;
  cin>>n>>a>>b;
  long long v[n];
  for (int i=0; i<n; i++) cin>>v[i];
  sort(v, v + n);
  reverse(v, v + n);

  com[0][0] = 1;
  for (int i=1; i<51; i++) {
    com[0][i] = 0;
  }
  for (int i=1; i<51; i++) {
    com[i][0] = 1;
    for (int j=1; j<51; j++) {
      if (j > i) {
        com[i][j] = 0;
      } else {
        com[i][j] = com[i-1][j-1] + com[i-1][j];
      }
    }
  }
  pair<long long, int> max_sum;
  long long cnt;
  for (int m=a; m<=b; m++) {
    long long sum = 0;
    for (int i=0; i<m; i++) {
      sum += v[i];
    }
    int larger = 0;
    int equal = 0;
    for (int i=0; i<n; i++) {
      if (v[i] > v[m-1]) {
        ++larger;
      } else if (v[i] == v[m-1]) {
        ++equal;
      }
    }
    if (m == a) {
      max_sum = make_pair(sum, m);
      cnt = com[equal][m-larger];
      continue;
    }
    int l = lcm(max_sum.second, m);
    if (sum * (l / m) > max_sum.first * (l / max_sum.second)) {
      max_sum = make_pair(sum, m);
      cnt = com[equal][m-larger];
    } else if (sum * (l / m) == max_sum.first * (l / max_sum.second)) {
      cnt += com[equal][m-larger];
    }
  }
  printf("%.7lf\n", 1.0 * max_sum.first / max_sum.second);
  cout<<cnt<<endl;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)

input = sys.stdin.readline

h, w, k = map(int, input().split())
s = tuple(input() for _ in range(h))

ret = [[-1] * w for _ in range(h)]

curr = 1
for r, row in enumerate(s):
    left = 0
    right = 0
    while right >= 0:
        right = row.find('#', left)
        next_right = row.find('#', right + 1)
        if right == -1:
            # 完全空行なら何もしない
            break
        else:
            if next_right == -1:
                right = w - 1
            # ケーキが存在する場合は、端まで使う

            for idx in range(left, right + 1):
                ret[r][idx] = curr
            offset = -1
            while r + offset >= 0:
                if all(ret[r + offset][idx] == -1 for idx in range(left, right + 1)):
                    for idx in range(left, right + 1):
                        ret[r + offset][idx] = curr
                    offset -= 1
                else:
                    break

            curr += 1
            left = right + 1

for r, row in enumerate(ret):
    for c, cell in enumerate(row):
        if cell == -1:
            ret[r][c] = ret[r - 1][c]

for row in ret:
    print(*row)


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)

#define ALL(v) v.begin(), v.end()


int main() {
  
  int64_t N, M;
  cin >> N >> M;
  vector<vector<int64_t>>R(M,vector<int64_t>(2));

  REP(i,M) cin >> R[i][0] >> R[i][1];

  vector<vector<int64_t>>next(N,vector<int64_t>());

  REP(i,M){
    next[R[i][0]-1].push_back(R[i][1]-1);
    next[R[i][1]-1].push_back(R[i][0]-1);
  }

  //BFS
  vector<int64_t> dist(N,-1);
  queue<int64_t> que;
  vector<int64_t> ans(N,-1);
  dist[0] = 0;
  que.push(0);

  while(!que.empty()){
    int64_t v = que.front();
    que.pop();

    for(int i = 0; i < next[v].size(); i++){
      if(dist[next[v][i]] != -1) continue;
      dist[next[v][i]] = dist[v] + 1;
      ans[next[v][i]] = v;
      que.push(next[v][i]);
    }
  }

  cout << "Yes" << endl;

  FOR(i,1,N) cout << ans[i] + 1 << endl;
}


Measured memory_bytes: 24636
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define iii tuple<int, int, int>
#define ii pair<int, int>
#define fi first
#define se second

using namespace std;
using namespace __gnu_pbds;

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

void solve() {
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < n; ++i) cout << s[i] << t[i] << (i == n - 1 ? "\n" : "");
}

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    // freopen("in", "r", stdin);

    int t = 1;
    // cin >> t;
    while (t--) solve();

    return 0;
}

Measured memory_bytes: 256
///int ->(-2147483648<->2147483647)
///unsigned int(0<->4294967295)
///long long int (-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807)
///unsigned long long int (0 to 18,446,744,073,709,551,615)
//#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<queue>
#include<stdio.h>
#include<map>
#include<math.h>
#include<algorithm>
#include<string>
#include<utility>
#include<stack>
#include<cstring>
#include<iterator>
#include<unordered_map>
#include<unordered_set>
#include<set>
#include<iomanip> ///setprecision
using namespace std;
#define FIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define OPEN freopen("in.txt","r",stdin)
#define OUT freopen("out.txt","r",stdin)
#define INF 1000000000
#define ll long long
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pcc pair<char,char>
#define pdd pair<double,double>
#define vi vector<int>
#define vll vector<long long>
#define vc vector<char>
#define vd vector<double>
#define sci(value) scanf("%d%*c",&value)
#define scl(value) scanf("%lld%*c",&value)
#define pi  (2*acos(0))
#define pb push_back
#define valid(value123,value234,limitrow,limitcol) value123>=0&&value123<limitrow&&value234>=0&&value234<limitcol
//int fx[]= {0,0,1,-1,-1,1,-1,1};//kings move
//int fy[]= {1,-1,0,0,-1,1,1,-1};//kings move
//int fx[]={-2,-2,-1,-1, 1,1, 2,2};  // Knights Move
//int fy[]={-1, 1,-2, 2,-2,2,-1,1}; // Knights Move
//ll powFunction(ll a,ll b){if(b==0)return 1;ll re=powFunction(a,b/2);re=(re*re);if(b&1)re=(re*a);return re;}
///ll digitSum(ll a){ll ans=0;while(a){ans+=(a%10);a/=10;}return ans;}

#define MX 100005
#define mod 1000000007
ll dp[102][MX];
ll n,knapsack,a,b;
vector<pll>vec;
ll maximumValue(ll i,ll w)
{
    if(i==n)
        return 0;
    if(dp[i][w]!=-1)
        return dp[i][w];
    ll q1=0,q2=0;
    q1=maximumValue(i+1,w);
    if(w + vec[i].first <= knapsack)
    q2=maximumValue(i+1,w+vec[i].first)+vec[i].second;
    return dp[i][w]=max(q1,q2);
}
int main()
{
   memset(dp,-1,sizeof dp);
    scl(n),scl(knapsack);
    for(int i=0;i<n;i++)
    {
        scl(a),scl(b);
        vec.push_back({a,b});
    }
    printf("%lld\n",maximumValue(0,0));
}




Measured memory_bytes: 83472
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

vector<int> G[200010];
bool visited[200010];
int count_[200010];

void dfs(int now, int prev){
  int s = G[now].size();
  for(int i=0;i<s;i++){
    if(G[now][i]==prev)continue;
    count_[G[now][i]] += count_[now];
    dfs(G[now][i], now);
  }
  return;
}

int main(){
  
  int n,q;
  cin>>n>>q;
  int a,b;
  REP(i,n-1){
    cin>>a>>b;
    a--;b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  int p,x;
  REP(i,q){
    cin>>p>>x;
    p--;
    count_[p] += x;
  }
  
  dfs(0,-1);
  
  REP(i,n){
    cout<<count_[i]<<' ';
  }
  return 0;
}

Measured memory_bytes: 26624
n,q=map(int, input().split())
s=input()
lr=[list(map(int, input().split())) for _ in range(q)]
count=[0]*(n)
for i in range(1,n):
    if s[i-1]+s[i]=='AC':
        count[i]+=count[i-1]+1
    else:
        count[i]+=count[i-1]
for j in range(q):
    start=lr[j][0]-1
    end=lr[j][1]-1
    print(count[end]-count[start])

Measured memory_bytes: 32272
#include <iostream>
#include <string>
#include <cstdlib>
#include <stack>
#include <queue>

using namespace std;

struct pond{
	int size;
	int left;
	int right;
};

bool inside(pond* small, pond* large);
void printpond(pond* p);
void printstack(stack<pond*> s);
void printqueue(queue<pond*> q);
void printanswer(stack<pond*> s);
void aaa(queue<pond*> q);

int main(){
	string str;
	cin >> str;
	stack<int> s;
	queue<pond*> q;
	stack<pond*> pondstack;
	int ans = 0;
	pond* p;
	for (int i=0; i<str.length(); i++){
		if (str[i]=='\\'){
			s.push(i);
		}
		else if (str[i]=='/'){
			if (s.size() != 0){
				ans += i-s.top();
				p = new pond;
				p->size = i-s.top();	
				p->left = s.top();
				p->right = i;
				s.pop();
				q.push(p);
			}
		}
	}

	cout << ans << endl;

	aaa(q);

	return 0;
}

bool inside(stack<pond*> s, pond* large){
	if (s.empty()){
		return false;
	}
	pond* small;
	small = s.top();
	return ((large->left < small->left) && (small->right < large->right));
}

void printstack(stack<pond*> s){
	while (!s.empty()){
		printpond(s.top());
		s.pop();
	}	
}

void printqueue(queue<pond*> q){
	while(!q.empty()){
		printpond(q.front());
		q.pop();
	}
}

void printpond(pond* p){
	cout << "size: " << p->size << ", left: " << p->left << ", right" << p->right << endl;
}

void printanswer(stack<pond*> s){
	int size;
	size = s.size();
	int l[size];
	for (int i=0; i<size; i++){
		l[size-i-1] = s.top()->size;
		s.pop();
	}
	cout << size;
	for (int i=0; i<size; i++){
		cout << " " << l[i];
	}
	cout << endl;

}

void aaa(queue<pond*> q){
	stack<pond*> s;
	pond* tmp;
	while (!q.empty()){
		if (!s.empty()){
			while ((inside(s, q.front())) && (!s.empty())){
				q.front()->size += s.top()->size;
				s.pop();
			}
		}
		s.push(q.front());
		q.pop();
	}
	printanswer(s);
}














Measured memory_bytes: 3560
N = int(input())
T = list(map(int,input().split()))
M = int(input())
PX = [list(map(int,input().split())) for _ in range(M)]

for p,x in PX:
  t = T[p-1]
  T[p-1] = x
  print(sum(T))
  T[p-1] = t

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>

using namespace std;


int main()
{
	int A,B,K;
	int ans;

	cin >> A >> B >> K;

	int min_n = min(A, B);
	int ki = 0;
	for(int ni = min_n; ni > 0; ni--){
		if(A % ni == 0 && B % ni == 0){
			ki++;
			if (ki == K){
				ans = ni;
				break;
			}
		}
	}

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

	return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
#define MAXN 66010
#define LL long long 
using namespace std;

const LL P=998244353;

LL getPow(LL x,LL y){
	LL res=1;
	while(y){
		if(y&1) res=res*x%P;
		x=x*x%P;
		y>>=1;
	}
	return res;
}

int n,n1,n2,sizew;
LL fac[MAXN],invfac[MAXN];
LL *a[MAXN],b[MAXN];

void init(){
	static char s1[MAXN],s2[MAXN];
	scanf("%s",s1+1);
	scanf("%s",s2+1);
	int len=strlen(s1+1);
	for(int i=1;i<=len;i++)
		if(s1[i]=='1' && s2[i]=='1') n1++;
		else if(s1[i]=='1' || s2[i]=='1') n2++;
	n2/=2;
	n=n1+n2;
	fac[0]=1;
	for(int i=1;i<MAXN;i++) fac[i]=fac[i-1]*i%P;
	invfac[MAXN-1]=getPow(fac[MAXN-1],P-2);
	for(int i=MAXN-2;i>=0;i--) invfac[i]=invfac[i+1]*(i+1)%P;
}

void FFT(LL *a,int len,int flag){
	static int rev[MAXN];
	for(int i=1;i<len;i++){
		rev[i]=rev[i>>1]>>1|((i&1)?(len>>1):0);
		if(i<rev[i]) swap(a[i],a[rev[i]]);
	}
	for(int l=2;l<=len;l<<=1){
		LL w=getPow(3,(P-1)/l);
		int l2=l/2;
		for(int i=0;i<len;i+=l){
			LL temp=1;
			for(int j=0;j<l2;j++){
				LL t1=a[i+j],t2=a[i+j+l2]*temp;
				a[i+j]=(t1+t2)%P;
				a[i+j+l2]=(t1-t2)%P;
				temp=temp*w%P;
			}
		}
	}
	if(flag==-1){
		LL invn=getPow(len,P-2);
		for(int i=1;i<len;i++) if(i<len-i) swap(a[i],a[len-i]);
		for(int i=0;i<len;i++) a[i]=(a[i]*invn%P+P)%P;
	}
}

void mul(LL *a,LL *b,int len){
	static LL t1[MAXN],t2[MAXN];
	for(int i=0;i<len;i++) t1[i]=a[i],t2[i]=b[i],t1[i+len]=t2[i+len]=0;
	FFT(t1,len<<1,1); FFT(t2,len<<1,1);
	for(int i=0;i<(len<<1);i++) t1[i]=t1[i]*t2[i]%P;
	FFT(t1,len<<1,-1);
	for(int i=0;i<(len<<1);i++) a[i]=t1[i];
}

void getInv(LL *b,LL *a,int len){
	if(len==1){
		b[0]=1;
		return;
	}
	static LL t1[MAXN],t2[MAXN];
	getInv(t1,a,len>>1);
	for(int i=(len>>1);i<len;i++) t1[i]=0;
	for(int i=0;i<len;i++) t2[i]=a[i];
	FFT(t1,len<<1,1); FFT(t2,len<<1,1);
	for(int i=0;i<(len<<1);i++) t1[i]=(2*t1[i]-t2[i]*t1[i]%P*t1[i]%P+P)%P;
	FFT(t1,len<<1,-1);
	for(int i=0;i<len;i++) b[i]=t1[i];
}

LL getC(int x,int y){
	return fac[x]*invfac[y]%P*invfac[x-y]%P;
}

LL gao(){
	for(sizew=1;sizew<=n1 || sizew<=n2;sizew<<=1);
	static LL space[MAXN];
	for(int i=1;i<=sizew;i++){
		a[i]=space+(i-1)*2;
		a[i][0]=1;
		if(i<=n2) a[i][1]=-i;
	}
	for(int l=2;l<=sizew;l<<=1)
		for(int i=1;i<=sizew;i+=l)
			mul(a[i],a[i+l/2],l);
	getInv(b,a[1],sizew);
	assert(b[0]==1);
	LL ans=0;
	for(int i=0;i<=n1;i++){
		LL temp=getC(n1,i)*b[i]%P*fac[i]%P*fac[n2]%P*fac[n2]%P*fac[n1-i]%P*fac[n1-i]%P*getC(n1+n2,n1-i)%P;
		ans=(ans+temp)%P;
	}
	return ans;
}

int main(){
#ifdef DEBUG
	freopen("E.in","r",stdin);
#endif
	init();
	printf("%lld\n",gao());
}

Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
const int SIZE = 10000, MOD = 1000000007;
map<int, int> m[SIZE];

unsigned long long power(unsigned long long x,unsigned long long n){
    unsigned long long res = 1;
    if (n > 0)
    {
        res = power(x, n/2);
        if (n % 2 == 0)res = (res * res) % MOD;
        else res = (((res * res) % MOD) * x) % MOD;
    }
    return res;
}
vector<int> v;
int B[1001];
bool prime[1001];
int main(){
    int n, A[SIZE], C[SIZE];
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> A[i];
        C[i] = A[i];
    }
    for (int i = 0; i < 1001; i++)
    {
        prime[i] = true;
    }
    for (int i = 2; i < 1001; i++)
    {
        if (prime[i])
        {
            for (int j = 2*i; j < 1001; j+=i)
            {
                prime[j] = false;
            }
        }
    }
    
    for (int i = 2; i < 1001; i++)
    {
        if (prime[i])
        {
            v.push_back(i);
        }
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < v.size(); j++)
        {
            while(A[i] % v[j] == 0){
                A[i] /= v[j];
                ++m[i][v[j]];
            }
            
        }
    }
    set<int> dict;
    for (int i = 0; i < n; i++)
    {
        dict.insert(A[i]);
    }
    
    long long pi = 1;
    long long ans = 0;
    for (int i = 0; i < v.size(); i++)
    {
        for (int j = 0; j < n; j++)
        {
            B[i] = max(B[i], m[j][v[i]]);
        }
    }
    for (int i = 0; i <= v.size(); i++)
    {
        pi *= power(v[i], B[i]);
        pi %= MOD;
    }
    auto itr = dict.begin();
    for (int i = 0; i < dict.size(); i++)
    {
        pi *= *itr;
        pi %= MOD;
        itr++;
    }
    
    for (int i = 0; i < n; i++)
    {
        ans += pi * power(C[i], MOD-2) % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
}

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


int main() {
    
    int n, k;
    string s;

    cin >> n >> s >> k;
    
    string an = "";

    for (int i = 0; i < n; ++i) {
        if (s[i] != s[k - 1]) {
            an += '*';
        } else {
            an += s[i];
        }
    }

    cout << an;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int main(){
    int n,k;
    int s = 0;
    int a[100000] = {0};
    for(;;){
        scanf("%d%d",&n,&k);
        if(n == 0&&k == 0)break;
        for(int i = 0;i < n; i++){
            scanf("%d",&a[i]);
        }
        int x = 0;
        for(int i = 0;i < k; i++){
            x += a[i];
        }
        s = x;
        for(int i = 0;i < (n-k); i++){
            x -= a[i];
            x += a[i+k];
            if(s < x)s = x;
        }
        printf("%d\n",s);
    }
    return 0;
}

Measured memory_bytes: 1424
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define MOD 1000000007
#define MAXN 3003
#define endl "\n"
#define readln(x) getline(cin, x);
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
ll fpow(ll x, ll n, ll mod){if (n==0) return 1%mod; ll u = fpow(x, n/2, mod); u = (u*u)%mod; if (n%2==1)u = (u*x)%mod;return u;}
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
string s, t, X[MAXN], Y[MAXN];
int C [MAXN][MAXN];

string LCS(int i, int j){
    if (i==0||j==0)return "";
    if (X[i]==Y[j])return LCS(i-1,j-1)+X[i];
    if (C[i][j-1]>C[i-1][j])return LCS(i,j-1);
    return LCS(i-1,j);
}
int main(){
    //freopen("data.txt","r",stdin);
    cin >> s >> t;
    for (int i = 0; i<(int)s.length(); i++){
        X[i+1] = s[i];
    }
    for (int i = 0; i<(int)t.length(); i++){
        Y[i+1] = t[i];
    }
    for (int i = 1; i<=(int)s.length(); i++){
        for (int j =1; j<=(int)t.length(); j++){
            if (X[i]==Y[j]){
                C[i][j] = C[i-1][j-1]+1;
            }
            else{
                C[i][j] = max(C[i][j-1], C[i-1][j]);
            }
        }
    }
    cout << LCS((int)s.length(), (int)t.length()) << endl;
    return 0;
}

Measured memory_bytes: 36096
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 1e5+7;

LL a[MAXN];
LL dp[MAXN][2];

LL solve(int now, int connected) {
    if (now==0) {
        assert(connected==0);
        return 0;
    }

    if (dp[now][connected] != -1) return dp[now][connected];

    LL has = a[now]-connected;
    LL ans = solve(now-1, 0)+has/2;
    if (has > 0 && a[now-1] > 0) {
        LL tmp = 1 + solve(now-1, 1) + (has-1)/2;
        ans = max(ans, tmp);
    }
    return dp[now][connected] = ans;
}

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

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

    memset(dp, -1, sizeof dp);
    cout << solve(n, 0) << endl;


    return 0;
}


Measured memory_bytes: 7296
n = int(input())
a = [input().split(" ") for i in range(n)]
num = 0
nummax = 0
for i in range(n):
  if int(a[i][0])==int(a[i][1]):
    num+=1
  else:
    if num> nummax:
      nummax = num
    num=0
if num> nummax:
   nummax = num
if nummax>=3:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9192
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/


int main(){
int N,K;
cin>>N>>K;
ll ans=0;
if(K==0){
    rep3(b,N){
        ans+=N/b;
    }

}

rep4(b,K+1,N){
ans+=((b-max(K,1))*(N/b))+max(N%b-max(K,1)+1,(ll)0);

}


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

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
 
int W,H,N;
int ex,ey;
bool used[222][222][4];
bool fie[222][222];
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
 
 
int solve( int x, int y, int d ){
  if( used[x][y][d] ) return -(1<<29);
  used[x][y][d] = true;
  if( x == ex && y == ey ) return 1;  
  for(int i=0;i<4;i++){
    int nd = (d+i-1+4)%4;
    int nx = x + 2*dx[nd], ny = y + 2*dy[nd];
    int cx = x + dx[nd], cy = y + dy[nd];
    if( fie[cx][cy] ) continue;
    return solve( nx, ny, nd ) + 1;
  }
  return -(1<<29);  
}
 
void nuri(int x1,int y1,int x2,int y2 ){
  for(int x=x1;x<=x2;x++)
    for(int y=y1;y<=y2;y++)
      fie[x][y] = true;
}
 
int main(){
  while( cin >> W >> H >> N && (H||H||N) ){
    memset( used,0,sizeof( used ) );
    memset( fie,0,sizeof( fie ) );
    for(int i=0;i<=2*W;i++)
      fie[i][0] = fie[i][2*H] = true;
    for(int i=0;i<=2*H;i++)
      fie[0][i] = fie[2*W][i] = true;
 
    for(int i=0;i<N;i++){
      int x1,y1,x2,y2; cin >> x1 >> y1 >> x2 >> y2;
      if( x1 > x2 ) swap( x1, x2 );
      if( y1 > y2 ) swap( y1, y2 );
      x1*=2; y1*=2; x2*=2; y2*=2;
      nuri( x1,y1,x2,y2 );
    }
 
    int sa,sb,sc,sd;
    cin >> sa >> sb >> sc >> sd >> ex >> ey;
    if( sa > sc ) swap( sa,sc );
    if( sb > sd ) swap( sb,sd );
    sa *= 2; sb *=2; sc *=2; sd*=2;
    ex = 2*ex+1; ey = 2*ey+1;
 
    int res;
    if( sa == sc ){
      if( sa == 0 ) res = solve( 1, sb+1, 1 );
      else res = solve( 2*W-1, sb+1, 3 );
    } else {
      if( sb == 0 ) res = solve( sa+1, 1, 0 );
      else res = solve( sa+1, 2*H-1, 2 );
    }
    if( res < 0 ) cout << "Impossible" << endl;
    else cout << res << endl;
  }
}

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

vector<long long> factoring(long long N){
    long long a=2;
    int prime_count=1;
    vector<long long> prime{1};

    while(N>=a*a){
        if(N%a==0){
            if(prime_count==0 || prime[prime_count-1]!=a){
                prime.push_back(a);
                prime_count+=1;
            }
            N/=a;
        }else{
            a++;
        }
    }

    if(prime_count==0 || N!=prime[prime_count-1])prime.push_back(N);
    return prime;
}

int main(){
    long long A,B;
    int i,j;
    int result=0;
    int a_cursor=0;
    int b_cursor=0;
    vector<long long> A_factor,B_factor;
    cin>>A>>B;
    A_factor=factoring(A);
    B_factor=factoring(B);

    for(i=0;i<A_factor.size();i++){
        for(j=0;j<B_factor.size();j++){
            if(A_factor[i]==B_factor[j]){
                result++;
                break;
            }
        }
    }

    cout<<result<<endl;
    return 0;
}

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


int main()
{
    ll n,m,i,j;
    cin>>n>>m;
    char a[n+1][m+1];
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            cin>>a[i][j];
        }
    }
    ll dp[n+1][m+1];
    dp[1][1]=1;
    ll f=0;
    for(i=1;i<=m;i++)
    {
        if(a[1][i]=='#')
        {
            f=1;
        }
        if(f==0)
        {
            dp[1][i]=1;
        }
        else
        {
            dp[1][i]=0;
        }
    }
    f=0;
    for(i=1;i<=n;i++)
    {
        if(a[i][1]=='#')
        {
            f=1;
        }
        if(f==0)
        {
            dp[i][1]=1;
        }
        else
        {
            dp[i][1]=0;
        }
    }
    for(i=2;i<=n;i++)
    {
        for(j=2;j<=m;j++)
        {
            if(a[i][j]=='#')
            {
                dp[i][j]=0;
            }
            else
            {
            dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
            }
        }
    }
    cout<<dp[n][m]<<"\n";
}

Measured memory_bytes: 12264
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define REP(i, n) for(int i=0;i<(n);++i)
typedef long long ll;

const int prime[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};

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

	// 75 = 3*5*5
	int N; cin >> N;
	vector<int> vec;
	REP(i, 25){
		if(prime[i] > N) break;
		int tmp = N, cnt = 0;
		while(tmp >= prime[i]){
			cnt += tmp/prime[i];
			tmp /= prime[i];
		}
		if(cnt > 0) vec.push_back(cnt);
	}

	/* 75 = 75
          = 3*25
          = 5*15
          = 3*5*5
    */

	int idx3=0, idx5=0, idx15=0, idx25=0, idx75=0;
    for(auto itr:vec){
    	cerr << itr << endl;
    	if(itr >= 2) idx3++;
    	if(itr >= 4) idx5++;
    	if(itr >= 14) idx15++;
    	if(itr >= 24) idx25++;
    	if(itr >= 74) idx75++;
    }

    if(idx5 >= 1 and idx3 >= 2) cout << idx75 + ((idx3-1)*idx25) + ((idx5-1)*idx15) + ((idx3-2)*idx5*(idx5-1)/2) << endl;
    else if(idx5 >= 1 and idx3 < 2) cout << idx75 + ((idx5-1)*idx15) << endl;
    else if(idx5 < 1 and idx3 >= 2) cout << idx75 + ((idx3-1)*idx25) << endl;
    else cout << idx75  << endl;

	return 0;
}


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

using namespace std;

int main(){
  int N;
  int x;
  cin >> N;
  cin >> x;
  int a[102];
  for(int i=0;i!=N;i++){
    cin >> a[i];
  }
  sort(a,a+N);
  int ans=0;
  for(int i=0;i!=N;i++){
    if(x-a[i]>=0){
      ans++;
      x-=a[i];
    }
    else{
      break;
    }
  }
  if(x!=0&&ans!=0&&N==ans){
    ans--;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  string s;
  cin >> s;
  int k;
  cin >> k;
  ll ans = 0;
  char m = 0;
  int c = 0;
  vector<pair<char, int>> vp;
  rep(i, s.size()){
    if(m != s.at(i)){
      // cerr << c << " " << m << endl;
      if(i != 0) vp.push_back(make_pair(m, c));
      c = 1;
      m = s.at(i);
    }else c++;
  }
  vp.push_back(make_pair(m, c));
  rep2(i, 1, vp.size()-1){
    ans += vp.at(i).second/2;
  }
  if(vp.size() == 1){
    ll t = (ll)vp.front().second * k;
    ans = t/2;
  }else if(vp.front().first != vp.back().first){
    ans += vp.front().second/2;
    ans += vp.back().second/2;
    ans *= k;
  }else{
    ans *= k;
    ans += vp.front().second/2;
    ans += vp.back().second/2;
    ans += (ll)(vp.front().second+vp.back().second)/2*(k-1);
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
    int n,m;
    cin >> n >> m;
    vector<bool> problems(n, false);
    vector<int> was(n+1,0);
    int ac=0,wa=0;
    for(int i=0;i<m;i++){
        int num;
        string s;
        cin >> num >> s;
        
        if(problems[num] == true)
            continue;
        if (s=="AC"){
            ac++;
            wa+=was[num];
            problems[num]=true;
        } else if (s=="WA")
            was[num]++;
    }
    
    cout << ac << endl;
    cout<<wa<<endl;
}
    

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

int main(){
	
	int** arr=new int*[3];
	for(int i=0;i<3;i++){
		arr[i]=new int[3];
		for(int j=0;j<3;j++){
			cin>>arr[i][j];
		}
	}
	
	int t;
	cin>>t;
	while(t--){
		int x;
		cin>>x;
		for(int i=0;i<3;i++){
			for(int j=0;j<3;j++){
				if(arr[i][j]==x){
					arr[i][j]=INT_MAX;
				}
			}
		}
	}
	//row 
	bool ans=false;
	for(int i=0;i<3;i++){
		if(arr[i][1]==INT_MAX&&arr[i][0]==INT_MAX&&arr[i][2]==INT_MAX){
			ans=true;
		}
	}
		for(int i=0;i<3;i++){
		if(arr[1][i]==INT_MAX&&arr[2][i]==INT_MAX&&arr[0][i]==INT_MAX){
			ans=true;
		}
	}
		if(arr[0][0]==INT_MAX&&arr[1][1]==INT_MAX&&arr[2][2]==INT_MAX){
			ans=true;
		}
		if(arr[2][0]==INT_MAX&&arr[1][1]==INT_MAX&&arr[0][2]==INT_MAX){
			ans=true;
		}
		if(ans)cout<<"Yes";
		else cout<<"No";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep2(i,a,n) for(int i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> PLL;

int main() 
{
    string a,b,c;
    cin >> a >> b >> c;
    string z = a+b+c;
    sort(z.rbegin(), z.rend());
    
    //cout << atoi(z.c_str()) <<endl;
    cout << atoi(&z[2]) + atoi(z.substr(0,2).c_str()) <<endl;

    return 0;
}



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



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;


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



int main() {

  cout<<fixed<<setprecision(10);

  ll n,m,l;cin>>n>>m>>l;
  ll A[n][m], B[m][l];
  rep(i,n)rep(j,m)cin>>A[i][j];
  rep(i,m)rep(j,l)cin>>B[i][j];


  ll C[n][l];

  rep(i,n){
    rep(j,l){
      C[i][j] = 0;
      rep(k,m) C[i][j] += A[i][k]*B[k][j]; 
    }
  }

  rep(i,n){
    rep(j,l-1){
      cout<<C[i][j]<<" ";
    }
    cout<<C[i][l-1]<<endl;
  }

  
  return 0;

}




//




Measured memory_bytes: 3308
n,m=map(int,input().split())
l=[]
grp=[[] for i in range(n)]
for i in range(m):
    l.append(list(map(int,input().split())))
    grp[l[i][0]-1].append(l[i][1])
ydic={}
for i in range(n):
    grp[i].sort()
    for j in range(len(grp[i])):
        ydic[grp[i][j]]=j+1
for i in l:
    print(str(i[0]).zfill(6)+str(ydic[i[1]]).zfill(6))

Measured memory_bytes: 47340
n = int(input())
if n%2 == 1:
    a = n-1
else:
    a = n
ans = []
for i in range(a-1):
    for j in range(i+1,a):
        if i+j+2 == a+1:
            continue
        else:
            ans += [[i+1,j+1]]
            # print(i+1,j+1)
if n%2 == 1:
    for i in range(n-1):
        ans += [[i+1,n]]
        # print(i+1,n)
print(len(ans))
for i in ans:
    print(*i)

Measured memory_bytes: 4124
H, N = map(int, input().split())
attack = list(map(int, input().split()))

# モンスターの体力は H です。
# アライグマは N種類 の必殺技を使うことができ、i番目の必殺技を使うとモンスターの体力を Ai 減らすことができます。
# アライグマが同じ必殺技を2度以上使うことなくモンスターに勝つことができるなら Yes を、できないなら No を出力せよ。

if H - sum(attack) <= 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 20560
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int curr;
        boolean app = true;
        for(int i = 0; i < n; i++){
            curr = sc.nextInt();
            if(curr%2==0){
                if(curr%3!=0&&curr%5!=0){
                    app = false;
                    break;
                }

            }
        }
        if(app)
            System.out.println("APPROVED");
        else
            System.out.println("DENIED");
    }
}


Measured memory_bytes: 23252
//In The Name of Allah
#include <bits/stdc++.h>

using namespace std;

typedef long long            ll;
typedef long double          ld;
typedef string               str;
typedef pair < ll , ll >     pll;

#define X               first
#define Y               second
#define pb              push_back
#define sep             ' '
#define endl            '\n'
#define fast_io         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define dbl_io(x)       cout << fixed << setprecision(x);

const int N = 10;
const ll mod = 1e9 + 7;
const ll inf = 1e18 + 10;

ll a[N];

int main(){
    fast_io
    //dbl_io(10);
    ll n, m;
    cin >> n >> m;
    fill(a, a + N, -1);
    for (ll i = 0; i < m; i ++){
        ll p, x;
        cin >> p >> x;
        p --;
        if (a[p] != -1 && a[p] != x)
            return cout << -1, 0;
        a[p] = x;
    }
    if (a[0] == 0 && 1 < n)
        return cout << -1, 0;
    for (ll i = 0; i < n; i ++){
        if (a[i] != -1)
            cout << a[i];
        else{
            if (i == 0 && n != 1)
                cout << 1;
            else
                cout << 0;
        }
    }
    return 0;
}


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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    int x, n; cin >> x >> n;
    map<int, int>  mp;
    REP(i, 0, n){
        int a; cin >> a;
        mp[a]++;
    }
    int count = 0;
    while(1){
        if(mp[x-count] == 0){
            cout << x-count << endl;
            return 0;
        }else if(mp[x+count] == 0){
            cout << x+count << endl;
            return 0;
        }
        count++;
    }
}

Measured memory_bytes: 3620
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
typedef std::vector<int> vi;
typedef std::vector<std::vector<int>> vvi;
typedef std::vector<long long> vl;
typedef std::vector<std::vector<long long>> vvl;
#define out(x) cout<<x<<"\n";
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
    ll tmp;
    while (m!=0) {
        tmp = n % m;
        n = m;
        m = tmp;
    }
    return n;
}

ll lcm(ll n, ll m) {
    return abs(n) / gcd(n, m)*abs(m);//gl=xy
}
 
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;
}
 
using namespace std;

void solve(){
    int x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    vector<ll>p(a),q(b),r(c);
    rep(i,a)cin>>p[i];
    rep(i,b)cin>>q[i];
    rep(i,c)cin>>r[i];
    sort(rall(p));
    sort(rall(q));
    vector<ll>v;
    rep(i,x)v.pb(p[i]);
    rep(i,y)v.pb(q[i]);
    rep(i,c)v.pb(r[i]);
    sort(rall(v));
    ll sum=0;
    rep(i,x+y)sum+=v[i];
    cout<<sum;
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 8688
// Problem : D - Equals
// Contest : AtCoder Regular Contest 097
// URL : https://atcoder.jp/contests/arc097/tasks/arc097_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include "bits/stdc++.h"
using ll = long long;
using namespace std;
#define cerr if(0)cerr
#define size(x) (int)x.size()
#define all(x) x.begin(), x.end()

const int N = 1e6 + 1, mod = 1e9 + 7;

bool vis[N];
vector<int> v[N];
int n, m, ans = 0, p[N];

struct dsu_orz {
	int up[N], sz[N];
	
	void init() {
		for (int i = 1; i <= n; i++) {
			up[i] = i;
			sz[i] = 1;
		}
	}
	
	int find(int v) {
		if (up[v] == v) {
			return v;
		}
		return find(up[v]);
	}
	 
	void merge(int u, int v) {	
		int uwu = find(u), ovo = find(v);
		if (sz[uwu] > sz[ovo]) {
			swap(uwu, ovo);
		}
		if (uwu != ovo) {
			up[uwu] = ovo;
			sz[ovo] += sz[uwu];
		}
	}
	
	int get_size(int v) {
		return sz[find(v)];
	}
	
} dsu;

int main() { cin.tie(0)->sync_with_stdio(0);
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> p[i];
	}
	dsu.init();
	for (int i = 1, x, y; i <= m; i++) {
		cin >> x >> y;
		dsu.merge(x, y);
	}
	for (int i = 1; i <= n; i++) {
		v[dsu.find(i)].push_back(i);
	}
	for (int i = 1; i <= n; i++) {
		int uwu = dsu.find(i);
		if (!vis[uwu]) {
			vis[uwu] = 1;
			sort(all(v[uwu]));
			for (auto pos : v[uwu]) {
				ans += binary_search(all(v[uwu]), p[pos]);
			}
			cerr << dsu.get_size(i) << '\n';
		}
	}
	cout << ans;
	cerr << dsu.get_size(1) << endl;
}


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

int h,w;
vector<vector<int>> maze;

//vector<vector<bool>> visited;
vector<vector<int>> dist;

vector<int> dx = {0,-1,1,0};
vector<int> dy = {-1,0,0,1};

void init(){
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      dist.at(i).at(j) = -1;
    }
  }
}

void bfs(int sx, int sy){
  init();
  dist.at(sx).at(sy) = 0;
  pair<int,int> s = make_pair(sx,sy);
  queue<pair<int,int>> q;
  q.push(s);
  while(!q.empty()){
    pair<int,int> p = q.front();
    q.pop();
    for(int i=0;i<4;i++){
      int x,y;
      tie(x,y) = p;
      int nx,ny;
      nx = x+dx.at(i);
      ny = y+dy.at(i);
      if(nx >= 0 && nx < h && ny >= 0 && ny < w){
        if(maze.at(nx).at(ny) == 0 && dist.at(nx).at(ny) == -1){
          dist.at(nx).at(ny) = dist.at(x).at(y) + 1;
          q.push(make_pair(nx,ny));
        }
      }
    }
  }  
}


int main() {
  cin >> h >> w;
  maze.resize(h);
  dist.resize(h);
  for(int i=0;i<h;i++){
    maze[i].resize(w);
    dist[i].resize(w);
  }
  for(int i=0;i<h;i++){
    string s;
    cin >> s;
    for(int j=0;j<w;j++){
      if((char)s.at(j) == '#'){
        maze.at(i).at(j) = 1;
      }else{
        maze.at(i).at(j) = 0;
      }
    }
  }
  
  int ans=0;
  
  for(int sx=0;sx<h;sx++){
    for(int sy=0;sy<w;sy++){
      if(maze.at(sx).at(sy)==1){
        continue;
      }
      bfs(sx,sy);
      for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
          ans = max(ans,dist.at(i).at(j));
        }
      }
    }
  }
  
  cout << ans << endl;

  return(0);
}

Measured memory_bytes: 3592
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		System.out.println(Math.max(a * 2 - 1, Math.max(b * 2 - 1, a + b)));
	}
}

Measured memory_bytes: 21204
#include <iostream>
#include <stdlib.h>
#include <vector> //vector
#include <algorithm> //sort()

using namespace std;

//long a, b, c, d, i, j, k, n;


int main(){
//////////////////////////////////////////////////////

    string s(20, '\0');
    cin >> s;

    int k;
    unsigned int min = 999;
    for ( int i = 0 ; i < s.size() - 2 ; ++i )
    {
        //cout << s.substr(i , 3) << endl;
        k = stoi ( s.substr(i, 3) );
        //cout << k << endl;
        if ( abs( k - 753 ) < min )
        {
            min = abs(k - 753 );
        }
    }
    // cout << "n:" << n << endl;

    // vector<long> input(n);
    // for (int i = 0 ; i < n ; i ++ )
    // {
    //     cin >> input[i];
        // cout << "input[" << i << "]=" << input[i] << endl;
    // }

    // sort(input.begin() , input.end());

    // uint64_t max = numeric_limits<uint64_t>::max();




    // long sum = 0;
    // for ( int i = 0 ; i < n ; i ++ )
    // {
    //     sum += i;
    // }






    cout <<   min   << endl;

//////////////////////////////////////////////////////
// Ctrl + Opt + N to make
    return 0;
}




Measured memory_bytes: 256
#include<iostream>
using namespace std;
using uint = unsigned int;

int main() {

	uint X, Y;
	cin >> X >> Y;

	uint ansX = (X == 3) ? 100000 : (X == 2) ? 200000 : (X == 1) ? 300000 : 0;
	uint ansY = (Y == 3) ? 100000 : (Y == 2) ? 200000 : (Y == 1) ? 300000 : 0;
	uint ansB = (X == 1 && Y == 1) ? 400000 : 0;
	cout << ansX + ansY + ansB;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char alpha = sc.next().charAt(0);
        if(alpha >= 'A' && alpha <= 'Z'){
            System.out.println("A");
        } else {
            System.out.println("a");
        }
    }
}

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

using namespace std;

#define pb push_back
#define in insert
#define fs first
#define sc second
#define sz size
#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define forni(i, n) for (ll i = 1; i <= (ll) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using ll = long long;
const ll inf = 1e9+7; 
const double PI =  3.141592653589793;

int main(){
	IO;
	ll k,a,b;
	cin>>k>>a>>b;
	(((a+k-1)/k)*k>b)?cout<<"NG\n":cout<<"OK\n";
	return 0;
}

// _   .-')                .-. .-')                 .-')                                               
//( '.( OO )_              \  ( OO )               ( OO ).                                             
// ,--.   ,--.).-'),-----. ,--. ,--.  .-'),-----. (_)---\_) ,--. ,--.     .-----.  ,-.-')  .-'),-----. 
// |   `.'   |( OO'  .-.  '|  .'   / ( OO'  .-.  '/    _ |  |  | |  |    '  .--./  |  |OO)( OO'  .-.  '
// |         |/   |  | |  ||      /, /   |  | |  |\  :` `.  |  | | .-')  |  |('-.  |  |  \/   |  | |  |
// |  |'.'|  |\_) |  |\|  ||     ' _)\_) |  |\|  | '..`''.) |  |_|( OO )/_) |OO  ) |  |(_/\_) |  |\|  |
// |  |   |  |  \ |  | |  ||  .   \    \ |  | |  |.-._)   \ |  | | `-' /||  |`-'| ,|  |_.'  \ |  | |  |
// |  |   |  |   `'  '-'  '|  |\   \    `'  '-'  '\       /('  '-'(_.-'(_'  '--'\(_|  |      `'  '-'  '
// """    """     """""""" """  """"      """""""  """""""  """"""""      """"""   """         """""""


Measured memory_bytes: 3620