akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

class Rect{
public:  int w,d;
};

int n,w,d, p,s, size, loop, i;
vector<int> ss;
vector<Rect> v;
vector<int>::iterator it; //= ss.begin();
Rect r1,r2;

int main(void){
  while( cin>>n>>w>>d && (n || w ||d) ){
    v.clear();
    r1.w=w; r1.d=d;
    v.push_back( r1 );
    for( loop=0;loop<n;loop++ ){
      cin >> p >> s;
      --p;
      // newRect, v[p] ÌÔ(ÊÏÌ¬³¢)ÉÀÑÖ¦
      r1.d = v[p].d;   r1.w = v[p].w;
      r2=r1;
      v.erase( v.begin()+p );

      s = s%( r1.d + r1.w );
      if( s<r1.w ){
	r1.w=s; r2.w-=s;
      }else{ s-=r1.w;
	r1.d=s; r2.d-=s;
      }
      if( r1.w*r1.d < r2.w*r2.d ){
	v.push_back( r1 );
	v.push_back( r2 );
      } else {
	v.push_back( r2 );
	v.push_back( r1 );
      }
    } // loop
    size = v.size();
    //sort
    ss.clear();
    for( i=0;i<size;i++ )
      ss.push_back( v[i].w * v[i].d  );
    sort( ss.begin(), ss.end() );
    it= ss.begin();

    cout << *it ;
    while( ++it!=ss.end() )
      cout << " "<< *it ;
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 0
// 7/4
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> X(M), Y(M), Z(M);
    rep(i, M) cin >> X[i] >> Y[i] >> Z[i];

    // UnionFind uf(2*N);
    // rep(i, M) {
    //     int x = X[i];
    //     int y = Y[i];
    //     if (Z[i]%2) {
    //         // X, Yは偶奇が等しい
    //         uf.unite(x, y);
    //         uf.unite(x+N, y+N);
    //     } else {
    //         // X, Yは偶奇が異なる
    //         uf.unite(x, y+N);
    //         uf.unite(x+N, y);
    //     }
    // }

    // set<int> st;
    // rep(i, 2 * N) {
    //     st.insert(uf.find(i));
    // }
    // cout << st.size() / 2 << endl;

    UnionFind uf(N);
    rep(i, M) {
        uf.unite(X[i]-1, Y[i]-1);
    }
    set<int> st;
    rep(i, N) st.insert(uf.find(i));
    cout << st.size() << endl;
}

Measured memory_bytes: 9396
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ld long double
#define vec vector<ll>
#define ms multiset<ll>
#define f(i,x,n) for(int i=x;i<n;i++)
#define int long long
#define mod 1000000007
#define endl "\n" 
vector<pair<int,int>>vc;
int32_t main() 
{ 
    int n;
    cin>>n;
    int x[n],y[n];
    f(i,0,n)
    {
        cin>>x[i]>>y[i];
        vc.pb(mp(x[i],y[i]));
    }
    if(n==1||n==2)
    {
        cout<<1;
        return 0;
    }
    sort(vc.begin(),vc.end());
    int ans=n-1;
    f(i,0,n)
    {
        f(j,i+1,n)
        {
            int p,q;
            p=vc[j].first-vc[i].first;
            q=vc[j].second-vc[i].second;
            int cst=n;
            for(int k=n-1;k>=0;k--)
            {
                for(int l=k-1;l>=0;l--)
                {
                    if(vc[k].first-vc[l].first==p && vc[k].second-vc[l].second==q)
                    {
                        cst--;
                        break;
                    }
                }
            }
            if(cst<ans)
            {    
                ans=cst;
               // cout<<i<<" "<<j<<" ";
            }
        }
    }
    cout<<ans;
}


Measured memory_bytes: 256
//gcc -std=gnu11 -O2 -o a.out Main.c -lm

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

//#define	dbgPrint	printf
#define	dbgPrint	

int main(void)
{
	
	int i;
	char s[3][101];
	char *pS[3];
	char card;
	char jyun;
	int ret;
	
	for(i = 0 ; i < 3 ; i++){
		ret = scanf("%s", s[i]);
		pS[i] = &s[i][0];
	};
	
	jyun = 0;
	while(1){
dbgPrint("jyun=%d\n", jyun);
		card = *pS[jyun]++;
		if(card == 0){
			printf("%c\n", 'A' + jyun);
			break;
		}
		jyun = card - 'a';
	}
	
	return 0;
}


Measured memory_bytes: 128
N = int(input())
L = [0 for i in range(N)]
L = list(map(int,input().split()))


T = 0
M = 1000

I = 0
J = 0
while I < N-1:
    
    if I+J+1 > N or L[I+J] >= L[I+1+J]:
        M += (M//L[I]) * (L[I+J]-L[I])
        I += J+1
        J = 0
    else:
        if I+J+1 == N-1:
          M += (M//L[I]) * (L[I+J+1]-L[I])
          I += J+1
          J = 0
        else:J += 1

print(M)        


Measured memory_bytes: 61900
N, M = map(int, input().split())
countAC = 0
countPena = 0
if M:

    pS = [input().split() for _ in range(M)]
    p, S = [list(i) for i in zip(*pS)]

    dic = {}

    for i in range(M):
        if not p[i] in dic:
            dic[p[i]] = {
                'AC': 0,
                'WA': 0
            }

        if S[i] == 'AC':
            dic[p[i]]['AC'] += 1
        if S[i] == 'WA' and dic[p[i]]['AC'] == 0:
            dic[p[i]]['WA'] += 1

    for k, v in dic.items():
        if v['AC'] > 0:
            countAC += 1
            countPena += v['WA']

print(countAC, countPena)

Measured memory_bytes: 106456
#include <bits/stdc++.h>
#define PII pair<int, int>
#define LL long long
using namespace std;
const int MAXN = 1005;
const LL INF = (LL)1e9 + 5;
const LL MOD = 1000000007;

LL dp[MAXN][MAXN], inv[MAXN], c[MAXN][MAXN];

LL mod_inv(LL x) {
	LL pw = MOD - 2, res = 1;
	while (pw) {
		if (pw & 1) res = res * x % MOD;
		x = x * x % MOD;
		pw >>= 1;
	}
	return res;
}

LL solve(LL N, LL A, LL B, LL C, LL D) {
	dp[A - 1][0] = 1;
	fill(dp[A - 1] + 1, dp[A - 1] + MAXN, 0);
	for (int i = A; i <= B; i++) {
		for (int j = 0; j <= N; j++) {
			LL prod = 1;
			dp[i][j] = dp[i - 1][j];
			for (int k = 1; k <= D && k * i <= j; k++) {
				LL rem = j - k * i;
				prod = prod * inv[k] % MOD* c[rem + i][i] % MOD;
				if (k < C) continue;
				dp[i][j] = (dp[i][j] + prod * dp[i - 1][rem]) % MOD;
			}
		}
	}
	return dp[B][N];
}

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

	LL N, A, B, C, D;
	cin >> N >> A >> B >> C >> D;
	
	for (int i = 1; i <= N; i++) {
		inv[i] = mod_inv(i);
	}
	
	for (int n = 0; n <= N; n++) {
		for (int k = 0; k <= n; k++) {
			c[n][k] = (k == 0 || k == n ? 1 : (c[n - 1][k] + c[n - 1][k - 1]) % MOD);
		}
	}
	
	cout << solve(N, A, B, C, D) << '\n';

	return 0;
}

Measured memory_bytes: 15232
MOD = 10 ** 9 + 7

N, K = gets.split.map(&:to_i)
As = gets.split.map(&:to_i).sort

#N = 100
#K = 10 ** 5
#As = N.times.map{rand(0..(K-1))}

dp = Array.new(K+1, 0)
rui = Array.new(K+2, 0)

dp[0] = 1
As.each do |a|
  q = 0
  (K+1).times do |j|
    rui[j+1] = q += dp[j]
    
    m = 0 > j-a ? 0 : j-a
    dp[j] = (q - rui[m]) % MOD    
  end
end

p dp[K]


Measured memory_bytes: 3324
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define EPS (1e-10)
struct Point{
  double x,y;
  Point(){}
  Point(double x,double y):x(x),y(y){}
  Point operator+(Point a){return Point(x+a.x,y+a.y);}
  Point operator-(Point a){return Point(x-a.x,y-a.y);}
  Point operator*(double k){return Point(x*k,y*k);}
  Point operator/(double k){return Point(x/k,y/k);}
};
typedef Point Vector;
typedef vector<Point> Polygon;
struct Segment{
  Point p1,p2;
  Segment(){}
  Segment(Point p1,Point p2):p1(p1),p2(p2){}
};
typedef Segment Line;
double norm(Point a){
  return a.x*a.x+a.y*a.y;
}
double abs(Point a){
  return sqrt(norm(a));
}
double dot(Point a,Point b){
  return a.x*b.x+a.y*b.y;
}
double cross(Point a,Point b){
  return a.x*b.y-a.y*b.x;
}
const double PI=3.141592653589793238;
Point trans(double k){
  return Point(cos(k*2*PI),sin(k*2*PI));
}
int ccw(Point p0,Point p1,Point p2){
  Vector a=p1-p0;
  Vector b=p2-p0;
  if(cross(a,b)>EPS) return 1;
  if(cross(a,b)<-EPS) return -1;
  if(dot(a,b)<-EPS) return 2;
  if(norm(a)<norm(b)) return -2;
  return 0;
}
Point getCrossPointLL(Line l1,Line l2){
  double a=cross(l1.p2-l1.p1,l2.p2-l2.p1);
  double b=cross(l1.p2-l1.p1,l1.p2-l2.p1);
  if(abs(a)<EPS&&abs(b)<EPS) return l2.p1;
  return l2.p1+(l2.p2-l2.p1)*(b/a);
}
Polygon convexCut(Polygon p,Line l){
  Polygon q;
  for(int i=0;i<(int)p.size();i++){
    Point a=p[i],b=p[(i+1)%p.size()];
    if(ccw(l.p1,l.p2,a)!=-1) q.push_back(a);
    if(ccw(l.p1,l.p2,a)*ccw(l.p1,l.p2,b)<0)
      q.push_back(getCrossPointLL(Line(a,b),l));
  }
  return q;
}
double area(Polygon s){
  double res=0;
  for(int i=0;i<(int)s.size();i++){
    res+=cross(s[i],s[(i+1)%s.size()])/2.0;
  }
  return abs(res);
}
int n,m;
Polygon a,b,c,d;
signed main(){
  while(cin>>n,n){
    a.clear();
    b.clear();
    c.clear();
    d.clear();
    double k;
    a.push_back(Point(0,0));
    b.push_back(Point(0,1));
    c.push_back(Point(0,0));
    d.push_back(Point(1,0));
    for(int i=0;i<n&&cin>>k;i++) a.push_back(Point(k,0));
    for(int i=0;i<n&&cin>>k;i++) b.push_back(Point(k,1));
    for(int i=0;i<n&&cin>>k;i++) c.push_back(Point(0,k));
    for(int i=0;i<n&&cin>>k;i++) d.push_back(Point(1,k));
    a.push_back(Point(1,0));
    b.push_back(Point(1,1));
    c.push_back(Point(0,1));
    d.push_back(Point(1,1));
    double ans=0;
    Polygon ba(4);
    ba[0]=Point(0,0);
    ba[1]=Point(1,0);
    ba[2]=Point(1,1);
    ba[3]=Point(0,1);
    for(int i=0;i<n+1;i++){
      for(int j=0;j<n+1;j++){
	Polygon t(ba);
	t=convexCut(t,Line(b[i],a[i]));
	t=convexCut(t,Line(a[i+1],b[i+1]));
	t=convexCut(t,Line(c[j],d[j]));
	t=convexCut(t,Line(d[j+1],c[j+1]));
	ans=max(ans,area(t));
      }
    }  
    printf("%.6f\n",ans);
  }
  return 0;
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

struct Edge {
    int to, id;
};

bool dfs(int now, int to, int prev, vector<int> &routes, vector<vector<Edge>> &edges) {
    if (now == to) {
        return true;
    }
    for (Edge &next : edges[now]) {
        if (next.to == prev) continue;
        bool b = dfs(next.to, to, now, routes, edges);
        if (!b) continue;
        routes.push_back(next.id);
        return true;
    }
    return false;
}

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

    vector<vector<Edge>> edges(n);

    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;

        edges[a].push_back(Edge{b, i});
        edges[b].push_back(Edge{a, i});
    }

    int m;
    cin >> m;
    vector<ll> rs(m);

    rep(i, m) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;

        vector<int> routes;
        dfs(u, v, -1, routes, edges);

        ll route_bit = 0;
        for (int j : routes) route_bit |= (1ll << j);
        rs[i] = route_bit;
    }

    ll ans = 0;
    rep(i, 1 << m) {
        ll k = 0;
        rep (j, m) if ((i >> j) & 1) {
                k |= rs[j];
            }
        int white = __builtin_popcountll(k);
        ll now = 1ll << (n - 1 - white);
        if (__builtin_popcount(i) % 2 == 0) {
            ans += now;
        } else {
            ans -= now;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(x) x.begin(),x.end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

string s;
ll solve(){
   ll ans=0;
   

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

    cin>>s;
    cout<<s.substr(0,3)<<endl;
    //cout<<solve()<<endl;
    return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int Read() {
	int x = 0, f = 1; char ch = getchar();
	while(!isdigit(ch)) {if(ch == '-')  f = -1; ch = getchar();}
	while(isdigit(ch)) {x = (x << 3) + (x << 1) + ch - '0'; ch = getchar();}
	return x * f;
}
int n, k, f[600055], maxn[2400055], a[600055];
void modify(int o, int l, int r, int pos, int x) {
	if(l == r)  {maxn[o] = max(maxn[o], x); return ;}
	int mid = (l + r) >> 1;
	if(pos <= mid)  modify(o << 1, l, mid, pos, x);
	else  modify(o << 1 | 1, mid + 1, r, pos, x);
	maxn[o] = max(maxn[o << 1], maxn[o << 1 | 1]);
}
int query(int o, int l, int r, int nl, int nr) {
	if(nl <= l && r <= nr)  return maxn[o];
	int mid = (l + r) >> 1, ans = 0;
	if(nl <= mid)  ans = max(ans, query(o << 1, l, mid, nl, nr));
	if(mid < nr)  ans = max(ans, query(o << 1 | 1, mid + 1, r, nl, nr));
	return ans;
}
signed main() {
	n = Read(), k = Read();
	for(int i = 1; i <= n; i++)  a[i] = Read() + 1;
	int ans = 0;
	for(int i = 1; i <= n; i++) {
		f[i] = query(1, 1, 300001, max(a[i] - k, 1), min(a[i] + k, 300001)) + 1;
		modify(1, 1, 300001, a[i], f[i]);
		ans = max(ans, f[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 10096
class UnionFind :
    """
    Union Find木
    ---
    頂点のインデックスは0~

    Attributes
    ---
    parent : list<int>
        親のリスト．parent[頂点のインデックス] = 親のインデックス
    height : list<int>
        各木の高さ
    size : list<int>
        各木の頂点数
    component : int
        連結成分の数
    """

    def __init__(self, size) :
        """
        Parameters
        ---
        size : int
            頂点数
        """
        self.parent = list(range(size))
        self.height = [0] * size
        self.size = [1] * size
        self.component = size

    def root(self, index) :
        """
        親のインデックスの取得

        Parameters
        ---
        index : int
            取得する頂点のインデックス

        Returns
        ---
        rootIndex : int
            指定した頂点の根のインデックス
        """
        if self.parent[index] == index :  # 根の場合
            return index
        rootIndex = self.root(self.parent[index])  # 葉の場合親の根を取得
        self.parent[index] = rootIndex  # 親の付け直し
        return rootIndex

    def union(self, index1, index2) :  # 結合
        """
        木の結合

        Parameters
        ---
        index1 : int
        index2 : int
            結合する頂点のインデックス
        """
        root1 = self.root(index1)
        root2 = self.root(index2)

        if root1 == root2 :  # 連結されている場合
            return

        root1, root2 = min(root1, root2), max(root1, root2)
        self.parent[root2] = root1


    def isSameRoot(self, index1, index2) :
        """
        同じ木に属するかを判定する

        Parameters
        ---
        index1 : int
        index2 : int

        Returns
        ---
        boolean
        """
        return self.root(index1) == self.root(index2)

    def sizeOfSameRoot(self, index) :
        """
        指定した頂点の属する木の大きさを取得する
        """
        return self.size[self.root(index)]

    def getComponent(self) :
        """
        連結成分数を取得する
        """
        return self.component

from collections import Counter
N, K, L = map(int, input().split())

train = UnionFind(N)
road = UnionFind(N)

for _ in range(K):
    p, q = map(int, input().split())
    p -= 1
    q -= 1
    train.union(p, q)

for _ in range(L):
    r, s = map(int, input().split())
    r -= 1
    s -= 1
    road.union(r, s)

countList = []
for i in range(N):
    countList.append((train.root(i), road.root(i)))

count = Counter(countList)
ans = [count[(train.root(i), road.root(i))] for i in range(N)]
print(*ans)

Measured memory_bytes: 61928
#include <bits/stdc++.h>
using namespace std;
#define int long long

bool isprime(int n){
    double rootn = sqrt(n);
    if (n < 2){
        return false;
    }
    else if (n == 2){
        return true;
    }
    else if (n % 2 == 0){
        return false;
    }
    else{
        for(int i = 3; i <= rootn; i += 2){
            if(n % i == 0){
                return false;
            }
        }
        return true;
    }
}

// 空のベクトルを二つ渡す。N (>=2) 以下の素数を primes に順番に入れる。
void prime_vectors(int N, vector<int>& primes, vector<bool>& is_prime){
    primes = {};
    is_prime = {};
    for(int i=0; i<=N; i++){
        is_prime.push_back(true);
    }

    primes.push_back(2);
    for(int j=4; j<=N; j+=2){
        is_prime[j] = false;
    }

    int i;
    for(i=3; i*i<=N; i+=2){
        if(!is_prime[i]) continue;
        primes.push_back(i);
        for(int j=2*i; j<=N; j+=i){
            is_prime[j] = false;
        }
    }

    for(; i<=N; i+=2){
        if(is_prime[i]){
            primes.push_back(i);
        }
    }
}

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int n, m;
    cin >> n >> m;

    vector<vector<int>> s(m+1, vector<int>());
    vector<int> k(m+1);
    for(int i=1; i<=m; i++){
        cin >> k[i];
        for(int j=1; j<=k[i]; j++){
            int sij;
            cin >> sij;
            s[i].push_back(sij);
        }
    }
    vector<int> p(m+1);
    for(int i=1; i<=m; i++){
        cin >> p[i];
    }

    vector<int> sw(n+1, 0);
    int n_on = 0;
    for(int i=0; i<(1<<n); i++){
        int tempi = i;
        for(int j=1; j<=n; j++){
            sw[j] = tempi % 2;
            tempi /= 2;
        }
        int l;
        for(l=1; l<=m; l++){
            // 電球 l について
            int cond = 0;
            for(int u=0; u<k[l]; u++){
                cond += (sw[s[l][u]] == 1);
            }
            if(cond % 2 != p[l]){
                break;
            }
        }

        if(l == m+1){
            // 全部 on だった
            n_on++;
        }
    }
    cout << n_on << endl;
    return 0;
}

Measured memory_bytes: 3604
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<sys/time.h>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
inline int ri()
{
	register int x=0;register bool f=0;register char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();};
	return f?-x:x;
}
void wi(ll x)
{
	if(x<0)	x=-x,putchar('-');
	if(x>9)	wi(x/10);
	putchar('0'+x%10);
}
const int N=305*305;
struct data
{
	int n,x,y;
	bool operator <(const data &t)const
	{
		return n<t.n;
	}
}q[N];
ll f[N*3];
inline ll calc(int i,int j)
{
	return abs(q[i].x-q[j].x)+abs(q[i].y-q[j].y);
}
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	int n=ri(),m=ri(),d=ri(),i,j,cc=0,x,y;
	for(i=1;i<=n;i++)
		for(j=1;j<=m;j++)
		{
			q[++cc].n=ri();
			q[cc].x=i;q[cc].y=j;
		}
	sort(q+1,q+1+cc);
	for(i=cc-1;i>=1;i--)
		if(i+d<=cc)	f[i]=f[i+d]+calc(i,i+d);
	int t=ri();
	while(t--)
	{
		x=ri(),y=ri();
		wi(f[x]-f[y]);putchar('\n');
	}
	return 0;
}


Measured memory_bytes: 2816
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//



int main() {

    ll X, K, D; cin >> X >> K >> D;

    X = abs(X);
    ll ans;
    if (log(X) >= log(K) + log(D)) {
        ans = X - K*D;
    } else {
        ll pls = X%D;
        ll mns = X%D - D;
        if (X/D % 2 == 0) {
            if (K % 2 == 0) {
                ans = pls;
            } else {
                ans = mns;
            }
        } else {
            if (K % 2 == 1) {
                ans = pls;
            } else {
                ans = mns;
            }
        }
    }
    ans = abs(ans);

    cout << ans << endl;


    return 0;
}





Measured memory_bytes: 3832
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>

#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) v.erase(remove(v.begin(), v.end(), a), v.end())
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
using namespace std;

struct St
{
	int n;
	int len;
	St() {}
	St(int n, int len) { this->n = n; this->len = len; };
	bool operator < (const St &st) const
	{
		return (len > st.len);
	}
};

vector<St> table[100001];
int v[100001];

signed main()
{
	int N;
	cin >> N;
	REP(i, N - 1)
	{
		int a, b, c;
		cin >> a >> b >> c;
		table[a].push_back(St(b, c));
		table[b].push_back(St(a, c));
	}

	int Q, K;
	cin >> Q >> K;

	REP(i, N + 1)
	{
		v[i] = LLONG_MAX;
	}
	v[K] = 0;

	priority_queue<St> q;
	q.push(St(K, 0));
	while (q.size() > 0)
	{
		St st = q.top();
		q.pop();
		for (auto t : table[st.n])
		{
			int len = st.len + t.len;
			if (v[t.n] > len)
			{
				v[t.n] = len;
				q.push(St(t.n, len));
			}
		}
	}

	REP(i, Q)
	{
		int x, y;
		cin >> x >> y;
		int ans = v[x] + v[y];
		cout << ans << endl;
	}
}

Measured memory_bytes: 11120
#include<bits/stdc++.h>
#define LL long long
#define il inline
#define re register
#define db double
#define eps (1e-5)

using namespace std;
const int N=100000+10;
il LL rd()
{
    re LL x=0,w=1;re char ch=0;
    while(ch<'0'||ch>'9') {if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') {x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return x*w;
}
char cc[N];
int n,cnt;

int main()
{
  scanf("%s",cc+1);
  n=strlen(cc+1);
  for(int i=2;i<n;i++) cnt+=(cc[i-1]!=cc[i+1]);
  if(!cnt) puts("Second");
  else ((n-(cc[1]==cc[n]))&1)?puts("First"):puts("Second");
  return 0;
}

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

int main() {
    int n; cin >> n;
    int C[n][3];
    for (int i=0; i<n; i++) cin >> C[i][0] >> C[i][1] >> C[i][2];

    int S[n]; for (int i=0; i<n; i++) S[i] = 0;
    for (int j=0; j<3; j++)
        for (int i=0; i<n; i++) {
            bool flag = true;
            for (int ii=0; ii<n; ii++)
                if (ii!=i && C[ii][j] == C[i][j]) flag = false;
            if (flag) S[i] += C[i][j];
        }

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


Measured memory_bytes: 3088
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
    public static string ans;
    public static int[] a;
    public static int s;
    static void Main(string[] args)
    {
        a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        if (a[2] == 0) { ans = "YES"; goto answer;}
        for (int i = 1; i < 51; i++)
        {
            if (a[0] % i == 0 && a[1] % i == 0) { s = i; }
        }
        if (a[2] % s == 0) { ans = "YES"; }
        else { ans = "NO"; }
        answer:
        Console.WriteLine(ans);
    }
    
}


Measured memory_bytes: 13396
def add(a, b):
    mod = 1e9+7
    c = a + b
    if c >= mod:
        c -= mod
    return c

H, W = [int(x) for x in input().split()]

sl = [input() for _ in range(H)]

dp = [[0 for _ in range(W)] for _ in range(H)]

dp[0][0] = 1 

for i in range(H):
    for j in range(W):
        for frm in [[i-1, j], [i, j-1]]:
            r, c = frm
            if r >= 0 and c >= 0 and sl[r][c] != '#':
                dp[i][j] = add(dp[i][j], dp[r][c])

print(int(dp[H-1][W-1]))


"""
using ll = long long; 
int add(int a, int b) {
    int MOD = 1e9 + 7;
    return (a + b) % MOD;
}
int main() {
    int H;
    int W;
    scanf("%d%d\n", &H, &W);
    vector<vector<int>> dp(H, vector<int>(W));
    vector<vector<bool>> is_wall(H, vector<bool>(W));
    for (int i = 0; i < H; i++) {
        scanf("\n");
        for (int j = 0; j < W; j++) {
            char ch;
            scanf("%c", &ch);
            //cout << i << " " << j << " " << ch << endl;
            if (ch == '#') {
                is_wall[i][j] = true;
            }
        }
    }
    dp[0][0] = 1;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            //cout << i << " " << j << " " << is_wall[i][j] << endl;
            if (!is_wall[i][j]) {
                if (i - 1 >= 0) {
                    dp[i][j] = add(dp[i][j], dp[i-1][j]);
                }
                if (j - 1 >= 0) {
                    dp[i][j] = add(dp[i][j], dp[i][j-1]);
                }    
            }
        }
    }    
	printf("%d\n", dp[H-1][W-1]);
	return 0;
}



"""

Measured memory_bytes: 36720
local n, q = io.read("*n", "*n")
local edge = {}
local cost = {}
local visited = {}
for i = 1, n do
  edge[i] = {}
  cost[i] = 0
  visited[i] = false
end
for i = 1, n - 1 do
  local a, b = io.read("*n", "*n")
  edge[a][b] = true
  edge[b][a] = true
end
for i = 1, q do
  local p, x = io.read("*n", "*n")
  cost[p] = cost[p] + x
end


local taskstate = {}
for i = 1, n do taskstate[i] = false end
local tasks = {}
local tasknum = 0
local done = 0

local function addtask(idx)
  if not taskstate[idx] then
    taskstate[idx] = true
    tasknum = tasknum + 1
    tasks[tasknum] = idx
    visited[idx] = true
  end
end
addtask(1)

while done < tasknum do
  done = done + 1
  local src = tasks[done]
  taskstate[src] = false
  for dst, unused in pairs(edge[src]) do
    if not visited[dst] then
      cost[dst] = cost[dst] + cost[src]
      addtask(dst)
    end
  end
end
print(table.concat(cost, " "))


Measured memory_bytes: 52864
#include<bits/stdc++.h>
using namespace std;
#define N 1116
#define M 1111116

int n,m,x[M],y[M],h[N][N],ans;

int read(){
	int x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

int main(){
	n=read();m=read();
	for (int i=1;i<=m;i++) x[i]=read(),y[i]=read();
	for (int i=1;i<=n;i++){
		h[i][i]=1;
		for (int j=m;j>=1;j--){
			if (!h[i][x[j]]&&!h[i][y[j]]) continue;
			if (h[i][x[j]]&&h[i][y[j]]) {fill(h[i]+1,h[i]+n+1,1);break;}
			h[i][x[j]]=h[i][y[j]]=1;
		}
	}
	for (int i=1;i<=n;i++)
		for (int j=i+1;j<=n;j++)
			for (int k=1;k<=n;k++)
				if (h[i][k]&&h[j][k])
				{ans++;break;};
	printf("%d\n",n*(n-1)/2-ans);
	return 0;
}

Measured memory_bytes: 6144
#include "bits/stdc++.h"
#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##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;
constexpr int dy[4] = { 0,1,0,-1 }; constexpr int dx[4] = { 1,0,-1,0 };

int H, W, K;
vector<string> A;
vv<int> dist;

int main() {
    cin >> H >> W >> K;
    A.resize(H);
    rep(i, H) cin >> A[i];

    int sy, sx;
    rep(i, H) rep(j, W) if (A[i][j] == 'S') {
        sy = i;
        sx = j;
        break;
    }

    dist = vvec(H, W, INF);
    dist[sy][sx] = 0;
    queue<pair<int, int>> que;
    que.emplace(sy, sx);
    while (!que.empty()) {
        auto v = que.front();
        que.pop();
        if (dist[v.first][v.second] >= K) continue;
        rep(d, 4) {
            int ny = v.first + dy[d], nx = v.second + dx[d];
            if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
            if (A[ny][nx] == '.' && dist[ny][nx] == INF) {
                dist[ny][nx] = dist[v.first][v.second] + 1;
                que.emplace(ny, nx);
            }
        }
    }

    rep(i, H) rep(j, W) {
        if (dist[i][j] <= K) {
            if (i == 0 || i == H - 1 || j == 0 || j == W - 1) {
                write(1);
                return 0;
            }

            dist[i][j] = K;
            que.emplace(i, j);
        }
    }

    while (!que.empty()) {
        auto v = que.front();
        que.pop();
        rep(d, 4) {
            int ny = v.first + dy[d], nx = v.second + dx[d];
            if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
            if (dist[ny][nx] == INF) {
                dist[ny][nx] = dist[v.first][v.second] + 1;
                que.emplace(ny, nx);
            }
        }
    }

    int ans = INF;
    rep(j, W) ans = min(ans, (dist[0][j] + K - 1) / K);
    rep(j, W) ans = min(ans, (dist[H - 1][j] + K - 1) / K);
    rep(i, H) ans = min(ans, (dist[i][0] + K - 1) / K);
    rep(i, H) ans = min(ans, (dist[i][W - 1] + K - 1) / K);
    write(ans);
}

Measured memory_bytes: 3840
package main

import (
	"fmt"
)

func main() {
var a, b int
	for {
		fmt.Scanln(&a, &b)

		if (a == 0) && (b == 0) {
			break
		}
		if a < b {
		fmt.Println(a, b)
		} else{
		fmt.Println(b, a)
               }
	}

}




Measured memory_bytes: 1224
#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;
int main(int argc, const char * argv[]) {
  // insert code here...
  int H,W;
  cin>>H>>W;
  vector<vector<char>> record(H,vector<char>(W));
  unordered_map<char, int> mymap;
  int four = 0;
  int two = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      char tmp;
      cin>>tmp;
      record[i][j] = tmp;
      mymap[tmp]++;
    }
  }
  for (int i = 0; i < H/2; i++) {
    for (int j = 0; j < W/2; j++) {
      four++;
    }
  }
  if (W % 2 != 0) {
    for (int i = 0; i < H/2; i++) {
      two++;
    }
  }
  if (H % 2 != 0) {
    for (int j = 0; j < W/2; j++) {
      two++;
    }
  }
  for (auto it : mymap) {
    while (mymap[it.first] >= 4 && four > 0) {
      mymap[it.first] -= 4;
      four--;
    }
    if (four == 0) {
      break;
    }
  }
  if (four != 0) {cout<<"No"; return 0;}
  for (auto it : mymap) {
    while (mymap[it.first] >= 2 && two > 0) {
      mymap[it.first] -= 2;
      two--;
    }
    if (two == 0) {
      break;
    }
  }
  if (two != 0) {cout<<"No"; return 0;}

  cout<<"Yes";
    return 0;
}

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

int main(){
    int N, K;
    std::cin >> N >> K;

    std::vector<int> heights;

    for(int height; std::cin >> height;){
        heights.push_back(height);
    }

    std::vector<int> costs_min(1,0);

    for(int i = 1; i < std::min(K,N); ++i){
        costs_min.push_back( std::abs(heights.at(i) - heights.at(0)));
    } // K番目以下は1番目とK番目を結ぶ飛び方が少なくとも最適

    for(int i = K; i < N; ++i){
        std::vector<int> temps;

        for(int j = 1; j < K+1; ++j){
            // jは段差の数 i-j  -> iの飛び方を考える．
            temps.push_back( costs_min.at(i-j) + std::abs(heights.at(i) - heights.at(i-j)));
        }
        std::sort(temps.begin(), temps.end());
        costs_min.push_back(temps.at(0));
    }

    std::cout << costs_min.at(N-1) << std::endl;
}

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

int main(){
	int x;
	cin >> x;
	cout << 10 - x/200 << endl;
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)

using namespace std;

int main() {
    int N,M;
    cin >> N >> M;
    map<int, int, greater<int> > A;
    rep(i,N){
        int a;
        cin >> a;
        if(A.find(a)!=A.end()) A[a]++;
        else A[a]=1;
    }

    rep(i,M) {
        long long B,C;
        cin >> B >> C;
        if(A.find(C)!=A.end()) A[C]+=B;
        else A[C]=B;
    }
    // sort(A.begin(),A.end());
    // reverse(A.begin(),A.end());
    int rest = N;
    long long total = 0L;
    for(auto itr=A.begin();itr!=A.end();itr++){
        int use = min(itr->second,rest);
        rest-=use;
        total+=(long long)(itr->first)*(long long)use;
        if(rest==0) break;
    }
    cout << total << endl;
}


Measured memory_bytes: 9600
import java.util.*

fun main(args: Array<String>) {

    val sc = Scanner(System.`in`)
    val N = sc.nextInt()
    var M = sc.nextInt()
    val AB = Array(N){0L to 0}
    var ans = 0L

    for (i in 0 until N) {
        val A = sc.nextLong()
        val B = sc.nextInt()
        AB[i] = A to B
    }

    AB.sortBy { it.first }

    for ((a,b) in AB) {
        if (M < 0) break
        ans += Math.min(b,M)*a
        M -= b
    }

    //for (ab in AB) println(ab)
    println(ans)
}

Measured memory_bytes: 122208
n, a, b = map(int, input().split())
s=input()

tp=0
up=0

for i in range(n):
  if tp >= a+b:
    print('No')
  elif s[i]=='a':
    print('Yes')
    tp+=1
  elif s[i]=='b':
    if up < b:
      print('Yes')
      tp+=1
      up+=1
    else:
      print('No')
  else:
    print('No')

Measured memory_bytes: 4016
use std::io::{Read, Write};

fn run() {
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let mut cnt = vec![0; n + 1];
    for _ in 0..n {
        let a: usize = it.next().unwrap().parse().unwrap();
        cnt[a] += 1;
    }
    cnt.push(1_000_000_000);
    cnt.sort();
    cnt.reverse();
    let mut sum = cnt.clone();
    sum.push(0);
    for i in (0..cnt.len()).rev() {
        sum[i] += sum[i + 1];
    }
    let mut ans = vec![0; n + 1];
    let mut p = n;
    for i in (1..(n + 1)).rev() {
        p = std::cmp::min(i, p);
        while cnt[p - 1] * (i - p + 1) <= sum[p] {
            p -= 1;
        }
        ans[i] = sum[p] / (i - p + 1);
    }
    for a in &ans[1..] {
        writeln!(out, "{}", *a).ok();
    }
}

fn main() {
    run();
}


Measured memory_bytes: 18680
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			long[] num = new long[6];
			boolean flag = true;
			for (int i = 0; i < 6; i++) {
				num[i] = scanner.nextLong();
				if (num[i] != 0)
					flag = false;
			}
			if (flag)
				break;
			long[] a = new long[3];
			for (int i = 0; i < 3; i++) {
				a[i] = getA(num[i * 2], num[i * 2 + 1]);
			}
			long b = a[0] / getGCD(a[0], a[1]) * a[1];
			long c = b / getGCD(b, a[2]) * a[2];
			System.out.println(c);
		}
	}

	public static long getGCD(long a, long b) {
		long tmp;
		while (b != 0) {
			tmp = a;
			a = b;
			b = tmp % b;
		}
		return a;
	}

	private static long getA(long l, long m) {
		long count = 1;
		long b = 1;
		while (true) {
			b = b * l % m;
			if (b == 1) {
				break;
			}
			count++;
		}
		return count;
	}
}

Measured memory_bytes: 20380
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
using namespace std;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

int k,m,n;
int main(){
	n=read();
	printf("%d\n",n*n*n);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N; 
  int K = 1000000;
  for (int i = 0; i < N; i++) {
    int L = 0, x;
    cin >> x;
    while (x % 2 == 0) {
      x /= 2;
      L++;
    }
    if (L < K) {K = L;}
  }
  cout << K << endl;
}

Measured memory_bytes: 3628
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            Console.WriteLine(solver(S) ? "Yes" : "No");
        }
        static bool solver(string S)
        {
            for (int i = 1; i < S.Length + 1; i++)
            {
                if (i % 2 == 1)
                {
                    if (S[i - 1] == 'L') return false;
                }
                else
                {
                    if (S[i - 1] == 'R') return false;
                }
            }
            return true;
        }
    }
}


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

int main() {
  int N;
  cin >> N;
  int c,t;
  c = 0;
  t = N;

  while(t > 0){
    c += t % 10;
    t /= 10;
  }
  
  //Nがcで割れるか判断
  if(N % c == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MOD = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime MOD
    mint inv() const { return pow(MOD-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination MOD prime
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < MOD);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
    mint p(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[n-k];
    }
} ; //comb(10000007);
// comb(5, 2) → 10, comb.p(5, 2) → 20
// comb.fact[4] → 24, 2のN乗 → mint(2).pow(N)

int main() {
    // dp, seine net algo
    string S;
    cin >> S;
    int M = 13;
    vector<mint> dp(M);
    dp[0] = 1;
    for (char c : S) {
        vector<mint> prev(M);
        swap(dp, prev);
        for (int i = 0; i < 10; i++) {
            if (c == i + '0' || c == '?'){
                for (int j = 0; j < M; j++) {
                    dp[(j*10 + i) % M] += prev[j];                    
                }
            }
        }
    }
    cout << dp[5] << '\n';
    return 0;
}

Measured memory_bytes: 3748
#include <unistd.h>
#include <cstdio>
#include <x86intrin.h>
#include <algorithm>

typedef long long ll;
int mat[375][3072 * 8] __attribute((aligned(32)));;
ll dp0[3008];

char buf[1048576];
int lim = 0;
int cur = 0;

void refill()
{
    lim = read(STDIN_FILENO, buf, sizeof buf);
    cur = 0;
}

int rd()
{
    while (true) {
        if (cur == lim) {
            refill();
            if (lim == 0) return -1;
        } else {
            if (buf[cur] >= '0' && buf[cur] <= '9') break;
            cur++;
        }
    }
    int acc = buf[cur++] - '0';
    while (true) {
        if (cur == lim) {
            refill();
            if (lim == 0) return acc;
        } else {
            if (buf[cur] < '0' || buf[cur] > '9') return acc;
            acc = acc * 10 + buf[cur++] - '0';
        }
    }
}

#pragma clang attribute push(__attribute__((target("avx512vl"))), apply_to=function)
int main(int argc, char **argv)
{   
    int rr = rd();
    int cc = rd();
    int k  = rd();
    
    for (int i = 1; i <= k; i++) {
        int r = rd() - 1;
        int c = rd() - 1;
        int v = rd(); 
        mat[r / 8][(c + (r & 7)) * 8 + (r & 7)] = v;
    }
    int rlim = (rr + 7) / 8;
    int clim = cc + 7;
    
    for (int y = 0; y < rlim; y++) {
        __m512i work0 = _mm512_setzero_si512();
        __m512i work1 = _mm512_setzero_si512();
        __m512i work2 = _mm512_setzero_si512();
        __m512i work3 = _mm512_setzero_si512();
        __m512i prev  = _mm512_setzero_si512();
        __m256i *p = (__m256i *)&mat[y];
        ll *q = dp0;
        
        for (int x = 0; x < clim; x++) {
            prev = _mm512_mask_set1_epi64(prev, 1, q[7]);
            work0 = _mm512_max_epi64(work0, prev);
            __m256i v0 = _mm256_load_si256(p);
            __m512i v = _mm512_cvtepi32_epi64(v0);
            __m512i tmp2 = _mm512_add_epi64(work2, v);
            work3 = _mm512_max_epi64(work3, tmp2); 
            __m512i tmp1 = _mm512_add_epi64(work1, v);
            work2 = _mm512_max_epi64(work2, tmp1); 
            __m512i tmp0 = _mm512_add_epi64(work0, v);
            work1 = _mm512_max_epi64(work1, tmp0);
            __m512i max32 = _mm512_max_epi64(work3, work2);
            __m512i max10 = _mm512_max_epi64(work1, work0);
            __m512i maxall = _mm512_max_epi64(max32, max10);
            prev = _mm512_alignr_epi64(maxall, maxall, 7);
            
            _mm512_mask_store_epi64(q, 1, prev);
            
            ++p;
            ++q;
        }
    }
    std::printf("%lld\n", dp0[clim - 1]);
    return 0;
}
#pragma clang attribute pop


Measured memory_bytes: 40176
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define boost() ios_base :: sync_with_stdio(0); cin.tie(); cout.tie(); cout << fixed; cout << setprecision(15); srand(time(NULL))
#define endl '\n'
typedef long long ll;
const int _N = 1e5 + 11;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll n;

int main() {
	boost();
//	freopen("in", "r", stdin);
	cin >> n;
	int sq = (int)sqrt(n);
	int res = INT_MAX;
	for (int i = sq; i >= 1; i--) {
		if (n % i == 0) {
			res = min(res, max((int)log10(i) + 1, (int)log10(n / i) + 1));
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using namespace std;
using P = pair<int,int>;
typedef long long ll;

int  main()
{
	int r,D;cin >> r >> D;
	int x0 ; cin >> x0;

	rep1(i, 10)
	{
		x0 = r*(x0) - D;
		cout <<  x0 << endl;
	}
	return (0);
}


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

typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++) // no semicoron
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>0;i--)
#define FORD(i,a,b) for(ll i=(a);i>(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
//#define PI 3.14159265359

using namespace std;

int main(){
    double R;

    cin >> R;

    double dist = 2.0 * M_PI * R;

    cout << setprecision(20) << dist << endl;
}

Measured memory_bytes: 3768
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9+5

int main()
{
    int n;               cin>>n;
    vector<int> a(n);    for(auto &i:a)   cin>>i;

    vector<int> dp(n,inf);
    dp[0] = 0;

    for(int i=0 ; i<n ; i++)
    {
        for(int j : {i+1 , i+2})
            {
                if(j<n)
                    dp[j] = min(dp[j] , dp[i]+abs(a[i] - a[j]));
            }
    }
cout<<dp[n-1];
}


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

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

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

    long long ans = 0;
    for(int i = 1; i < n; i++){
        int t = a[i - 1] + a[i];
        if(t <= x) continue;
        a[i] -= t - x;
        if(a[i] < 0){
            a[i - 1] += a[i];
            a[i] = 0;
        }
        ans += t - x;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  long double n,k;
  cin>>n>>k;
  long double sum=0;
  REP(i,1,n+1){
    long double count=0,a=i;
    while(k>a){
      a*=2;
      count++;
    }
    a=0.5;
    sum+=(long double)(1/n)*(long double)pow(a,count);
  }
  cout<<fixed<<setprecision(12)<<sum<<'\n';
  return(0);
}


Measured memory_bytes: 512
# solution
import io
import math

data=int(input())

array=list(map(int, input().split()))
array.sort()
tmp=[]
i=data-1
while i>0:
  if array[i]==array[i-1]:
    tmp.append(array[i])
    i-=2
  else:
    i-=1
if len(tmp)>=2:
  print(tmp[0]*tmp[1])
else:
  print(0)

Measured memory_bytes: 15020