akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

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


// CHECK THE LIMITS
typedef long long ll;

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

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

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

    int n;
    cin >> n;
    vector<int> aux(n);
    for(int i = 0; i < n-1; ++i)
    {
	int x;
	cin >> x;
	x--;
	aux[x]++;
    }

    for(int i =0 ; i < n; ++i)
    {
	cout << aux[i] << '\n';
    }

    return 0;
}


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

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define rep(i,n) for(int i=0; i<(int)(n); i++)
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; }

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

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  string s; cin >> s;
  int n = s.size();

  vector<bool> used(26);
  int cnt = 0;
  int r = 1;
  map<int, int> mp;
  for(int i=n-1; i>=0; i--) {
    int p = s[i]-'a';
    if (!used[p]) {
      cnt++;
      used[p] = true;
    }
    if (cnt==26) {
      cnt=0;
      mp[r] = i;
      r++;
      rep(k, 26) used[k] = false;
    }
  }
  rep(k, 26) used[k] = false;

  r--;
  int start = 0;
  while(r>0) {
    priority_queue<P, vector<P>, greater<>> que;
    int med = mp[r];
    rep(k, 26) used[k] = false;
    cnt = 0;
    for(int i=start; i<n; i++) {
      int p = s[i]-'a';
      if (!used[p]) {
        cnt++;
        used[p] = true;
        if (i >= med) {
          que.emplace(p, i);
        }
      }
      if (cnt==26) {
        P pa = que.top();
        while(!que.empty()) {
          que.pop();
        }
        cout << (char)('a'+pa.first);
        start = pa.second+1;
        break;
      }
    }
    r--;
  }

  rep(k, 26) used[k] = false;
  for(int i=start; i<n; i++) {
    int p = s[i] - 'a';
    used[p] = true;
  }
  rep(i, 26) {
    if (!used[i]) {
      cout << (char)('a'+i);
      break;
    }
  }
  cout << endl;
}

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

using vi = vector<int>;
#define f(i,a,b) for (int i = a; i < b; i++)
#define fr(i,a,b) for (int i = b-1; i >= 0; i--)
#define pb push_back
#define IN(i,a,b) (a<=i&&i<=b)
#define Max(a,b) a=max(a,b)

const int mxn = 2e5+7;
int n;
int ans[mxn], subsz[mxn], h[mxn];
vi adj[mxn];

struct SegTree {
	int tree[4*mxn],lazy[4*mxn];
	SegTree() {f(i,0,4*mxn) tree[i] = lazy[i] = 0;}
	void update(int i, int lo, int hi) {
		if (lazy[i]) {
			if (lo != hi) tree[i<<1]=tree[i<<1|1] = 0,
				lazy[i<<1]=lazy[i<<1|1]=1;
			lazy[i] = tree[i] = 0;
		}
	}
	void add(int i, int lo, int hi, int j, int x) {
		if (lo>hi) return;
		update(i,lo,hi);
		if (IN(j,lo,hi)) {
			tree[i]+=x;
			if (lo!=hi) {
				int mid = (lo+hi)/2;
				add(i<<1,lo,mid,j,x);	
				add(i<<1|1,mid+1,hi,j,x);
			}
		}
	}
	void add(int j, int x) {
		if (j>=0) add(1,0,mxn-1,j,x);
	}
	int zero(int i, int lo, int hi, int j) {
		if (lo>hi) return 0;
		update(i,lo,hi);
		if (lo>j) return 0;
		if (hi<=j) {
			int res = tree[i];
			lazy[i] = 1, update(i,lo,hi);
			return res;
		} else {
			int mid = (lo+hi)/2;
			int res = zero(i<<1,lo,mid,j)+zero(i<<1|1,mid+1,hi,j);
			tree[i] = tree[i<<1]+tree[i<<1|1];
			return res;
		}
	}
	int zero(int j) {
		return zero(1,0,mxn-1,j);
	}
	int query(int i, int lo, int hi, int j) {
		if (lo>hi) return 0;
		update(i,lo,hi);
		if (lo>j) return 0;
		if (hi<=j) return tree[i];
		else {
			int mid = (lo+hi)/2;
			int res = query(i<<1,lo,mid,j)+query(i<<1|1,mid+1,hi,j);
			tree[i] = tree[i<<1]+tree[i<<1|1];
			return res;
		}
	}
	int query(int j) {
		return j>=0?query(1,0,mxn-1,j):0;
	}
};

SegTree ds;

int dfsSubsz(int v, int p) {
	subsz[v] = 1; h[v] = p==-1?0:max(h[p],p);
	for (int w : adj[v])
		if (w != p)
			subsz[v] += dfsSubsz(w,v);
	return subsz[v];
}

void dfsBrute(int v, int p, int c, int x) {
	Max(c,v); ds.add(c,x);						
	for (int w : adj[v]) if (w != p)
		dfsBrute(w,v,c,x);
}

void guni(int v, int p, bool keep) {
	if (p == -1) ans[v] = 1;
	int bigChild = -1;
	for (int w : adj[v]) if (w != p)
		if (bigChild == -1 || subsz[bigChild] < subsz[w])
			bigChild = w;
	for (int w : adj[v]) if (w != p && w != bigChild)
		guni(w,v,0);
	if (bigChild != -1) guni(bigChild,v,1);
	for (int w : adj[v]) if (w != p && w != bigChild)
		dfsBrute(w,v,0,1);
	if (!v) return;
	ds.add(v,1);
	if (v>h[v]) ans[v] = 1+ds.query(h[v]);
	ds.add(v,ds.zero(v));
	if (v<h[v]) ans[v] = ds.query(h[v])-ds.query(h[p]);
	if (!keep) ds.zero(n-1);
};

void finaldfs(int v, int p) {
	if (p!=-1) ans[v] += ans[p];		
	for (int w : adj[v]) if (w != p)
		finaldfs(w,v);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cin>>n;
	f(i,0,n-1) {
		int a,b; cin>>a>>b;
		adj[--a].pb(--b); adj[b].pb(a);
	}
	f(i,0,n) ans[i]=subsz[i]=0;
	dfsSubsz(0,-1);
	guni(0,-1,0);
	finaldfs(0,-1);
	stringstream ss;
	f(i,1,n) ss << ans[i]-1 << " ";
	cout << ss.str() << endl;

	return 0;
}



Measured memory_bytes: 58372
*card, K = map(int, input().split())

# print(card, K)
v = [1, 0, -1]

total = 0
for idx, c in enumerate(card):
    if K == 0:
        break
    if c <= K:
        K -= c
        total += v[idx] * c
    else:
        total += K * v[idx]
        K = 0
print(total)


Measured memory_bytes: 9064
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> v(n);
    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        v[i] = make_pair(x, y);
    }
    for (int i = 0; i < n; ++i) {
        vector<long double> arg;
        int x1, y1;
        tie(x1, y1) = v[i];
        for (int j = 0; j < n; ++j) {
            if(i != j){
                int x2, y2;
                tie(x2, y2) = v[j];
                arg.emplace_back(atan2(y2-y1, x2-x1));
            }
        }
        sort(arg.begin(), arg.end());
        long double maxt = 2*acos(-1)-arg[n-2]+arg[0];
        for (int j = 0; j < n-2; ++j) {
            maxt = max(maxt, arg[j+1]-arg[j]);
        }
        cout << setprecision(20) << max((maxt-acos(-1))/(2*acos(-1)), 0.0L) << "\n";
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <functional>
#include <algorithm>

int main() {
  int N;
  std::cin >> N;
  std::vector<int> a(N), b(N), c(N);
  for (auto &i : a) { std::cin >> i; }
  for (auto &i : b) { std::cin >> i; }
  for (auto &i : c) { std::cin >> i; }
  std::sort(a.begin(), a.end());
  std::sort(b.begin(), b.end());
  std::sort(c.begin(), c.end());
  std::vector<long long> cnt_a(N, 0), cnt_b(N, 0);
  int idx = 0;
  for (int i = 0; i < N; ++i) {
    while (idx < N && b[i] >= c[idx]) { ++idx; }
    cnt_b[i] = N - idx;
  }
  for (int i = N - 1; i > 0; --i) {
    cnt_b[i - 1] += cnt_b[i];
  }
  idx = 0;
  long long ans = 0;
  for (int i = 0; i < N; ++i) {
    while (idx < N && a[i] >= b[idx]) { ++idx; }
    ans += cnt_b[idx];
  }
  std::cout << ans << std::endl;
  return 0;
}

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

int main() {
    string s, t;
    cin >> s >> t;
    int ans = 0;
    if (s[0] == t[0]) ans += 1;
    if (s[1] == t[1]) ans += 1;
    if (s[2] == t[2]) ans += 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 764
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000009;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-10;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
int p[210000];
int q[210000];
pair<int,int>z[210000];
int segtree[524288];
int query(int a,int b,int c,int d,int e){
	if(d<a||b<c)return -mod;
	if(c<=a&&b<=d)return segtree[e];
	return max(query(a,(a+b)/2,c,d,e*2),query((a+b)/2+1,b,c,d,e*2+1));
}
void update(int a,int b){
	a+=262144;
	while(a){
		segtree[a]=max(segtree[a],b);
		a/=2;
	}
}
int main(){
	int X0,X1,Y0,Y1;
	scanf("%d%d%d%d",&X0,&Y0,&X1,&Y1);
	int a;scanf("%d",&a);
	int sz=0;
	for(int i=0;i<a;i++){
		int x,y;scanf("%d%d",&x,&y);
		if(x<min(X0,X1)||x>max(X0,X1)||y<min(Y0,Y1)||y>max(Y0,Y1))continue;
		z[sz]=make_pair(x,y);
		p[sz]=x;
		q[sz++]=y;
 
	}
	long double ret=0;
	std::sort(z,z+sz);
	if(X0==X1){
		 ret=100.0*ABS(Y0-Y1);
		ret+=sz*(10*PI-20);
	}else if(Y0==Y1){
		ret=100.0*ABS(X0-X1);
		ret+=sz*(10*PI-20);
	}else{
		if(X0>X1){
			swap(X0,X1);
			swap(Y0,Y1);
		}
		std::sort(q,q+sz);
		int val=0;
		if(Y0<Y1){
			for(int i=0;i<sz;i++){
				int at=lower_bound(q,q+sz,z[i].second)-q;
				int tmp=query(0,262143,0,at,1)+1;
				val=max(val,tmp);
				update(at,tmp);
			}
		}else{
			for(int i=0;i<sz;i++){
				int at=lower_bound(q,q+sz,z[i].second)-q;
				int tmp=query(0,262143,at,sz-1,1)+1;
				val=max(val,tmp);
				update(at,tmp);
			}
		}
		if(val>min(ABS(Y0-Y1),ABS(X0-X1))){
			ret+=(10*PI-20);val--;
		}
		ret+=100.0*(ABS(Y0-Y1)+ABS(X0-X1));
		ret-=val*20.0;
		ret+=val*5*PI;
	}
	printf("%.18Lf\n",ret);
}

Measured memory_bytes: 4992
N = input()
K = int(input())

dp = [[[0] * (K + 1) for _ in range(2)] for _ in range(len(N) + 1)]
dp[0][0][0] = 1

for i in range(len(N)):
    n = int(N[i])
    for j in range(2):
        for k in range(K + 1):
            for d in range((9 if j == 1 else n) + 1):
                if k + int(d != 0) <= K:
                    dp[i + 1][j | (d < n)][k + int(d != 0)] += dp[i][j][k]

cnt = len(N) - N.count("0")
print(dp[-1][-1][-1] + int(cnt == K))


Measured memory_bytes: 74036
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <iostream>
#include <math.h>
using namespace std;
int main ()
{
	long long a,b,c,x,y,r=0;
	long long optimal;
	scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&x,&y);
	if(2*c<=a+b)
	{
		optimal=2*c;
	}
	else optimal=a+b;
	if(x<=y)
	{
		r=optimal*x;
		if(b<=2*c)
		{
			r+=b*(y-x);
		}
		else
		{
			r+=2*c*(y-x);
		}
	}
	else if(x>y)
	{
		r=optimal*y;
		if(a<=2*c)
		{
			r+=a*(x-y);
		}
		else
		{
			r+=2*c*(x-y);
		}
	}
	printf("%lld",r);
	return 0;
}


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

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

    vector<int> A(100100);
    vector<int> absd(100100);//ai-ai+1のabs
    vector<int> dif(100100);//ai-ai+2のabs

    A[0]=0;
    for(int i=0;i<N;i++){
        cin >> A[i+1];
    }
    long long ans=0;
    for(int i=0;i<=N;i++){
        absd[i]=abs(A[i]-A[i+1]);
        dif[i]=abs(A[i]-A[i+2]);
        ans+=absd[i];
    }
    
    for(int j=0;j<N;j++){
        cout << ans-absd[j]-absd[j+1]+dif[j] << endl;
    }
    return 0;

}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define rng() (rand() >> 3)*rand()

ll c=1, t, cnt[30];
string s;
int main(){
    cin >> s;
    fox(l, s.size()){
        c+=t-cnt[s[l]-'a'];
        cnt[s[l]-'a']++;
        t++;
    }
    cout << c;
    return 0;
}


Measured memory_bytes: 640
n = int(input())
s = []
for i in range(n):
  s.append(input())

judge = {'AC':0,'WA':0, 'TLE':0, 'RE':0}

for s1 in s:
  if s1 == 'AC':
    judge['AC']+=1
  elif s1 == 'WA':
    judge['WA']+=1
  elif s1 == 'TLE':
    judge['TLE']+=1
  else:
    judge['RE']+=1
print("AC x "f"{judge['AC']}")
print("WA x "f"{judge['WA']}")
print("TLE x "f"{judge['TLE']}")
print("RE x "f"{judge['RE']}")

Measured memory_bytes: 16272
from functools import reduce
import fractions
N, X = [int(i) for i in input().split()]
x = [int(x) for x in input().split()]
x.append(X)
x.sort()

distance = []
for i,xe in enumerate(x):
    if i is not 0:
        distance.append(xe - x[i-1])

print(reduce(fractions.gcd, distance))

Measured memory_bytes: 16204
n = int(input())
l = []
ll = []
for _ in range(n):
    x, y = map(int, input().split())
    l.append((x+y, x, y))
    ll.append((x-y, x, y))
l.sort()
ll.sort()
ans1 = 0
ans2 = 0
#print(l)
#print(ll)

cnt = 0
while True:
    a = l[n-1-cnt]
    b = l[cnt]
    #print(a, b)
    if a[1] >= b[1] and a[2] >= b[2]:
        ans1 = abs(b[0]-a[0])
        #print(ans1, a, b)
        break
    if cnt >= n-1:
        break
    cnt += 1

cnt = 0
while True:
    a = ll[n-1-cnt]
    b = ll[cnt]
    if a[1] >= b[1] and b[2] >= a[2]:
        ans2 = abs(b[0]-a[0])
        #print(ans2, a, b)
        break
    if cnt >= n-1:
        break
    cnt += 1

print(max(ans1, ans2))


Measured memory_bytes: 144556
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int n;
// dp[i][j][k]:=残り1/2/3個の皿がi/j/k枚
double dp[310][310][310];
double dfs(int i,int j,int k){
    if(i==0&&j==0&&k==0) return 0;
    if(dp[i][j][k]!=0) return dp[i][j][k];
    dp[i][j][k]+=1.0*n/(i+j+k);
    if(i-1>=0) dp[i][j][k]+=dfs(i-1,j,k)*1.0*i/(i+j+k);
    if(j-1>=0) dp[i][j][k]+=dfs(i+1,j-1,k)*1.0*j/(i+j+k);
    if(k-1>=0) dp[i][j][k]+=dfs(i,j+1,k-1)*1.0*k/(i+j+k);
    return dp[i][j][k];
}
int main(){
    cin>>n;
    int a[4]={};
    rep(i,n){
        int aa; cin>>aa;
        a[aa]++;
    }
    printf("%.10f\n",dfs(a[1],a[2],a[3]));
    return 0;
}


Measured memory_bytes: 225536
a, b, c, x, y = map(int, input().split())
ans = a * x + b * y
m = max(x, y)
for i in range(1, m+1):
  x -= 1
  y -= 1
  if x < 0:
    x = 0
  if y < 0:
    y = 0
  temp = c*(i*2) + x*a + y*b
  if temp < ans:
    ans = temp

print(ans)


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

using namespace std;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

typedef long long  ll;
#define endl '\n'




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


const int MOD = 1000000007;

//////////////////////////////////////////



string s;
int n;
void Input() {

    cin >> n;
    cin >> s;
}



void Solve() {


    int len = s.size();


    for(int i = 0; i < len; i++) {

        char ch = (s[i] + n) > 90 ? (s[i] + n) % 90 + 64 : (s[i] + n);
        cout <<  ch ;
    }


}

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);
  Input();
  Solve();


  return 0;

}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
const int INF= 1e9+5;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>>vvi;

int main(){
  int n;
  cin>>n;
  vector<int>a(n);
  
  for(int i=0;i<n;i++)cin>>a[i];
 
  int k;
  vector<int>copy=a;
  sort(copy.begin(),copy.end());
  vector<ll>sum(n);
  sum[0]=copy[0];
  for(int i=1;i<n;i++){
    sum[i]=sum[i-1]+copy[i];
   
  }
  int count=0;
  for(int i=n-1;i>=1;i--){
    if(2*sum[i-1]<copy[i]){
      k=i;
      break;
    }
  }
  cout<<n-k<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)


int main(){
    int a,b;
    string s;
    cin >> a >> b;
    if (a%3 == 0 || b%3 == 0 || (a+b)%3 == 0) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int n, k;
int d[101], a[101][101];
bool isHave[101];

int main(int argc, char const *argv[]) {
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        isHave[i] = false;
    }

    for (int i = 0; i < k; i++) {
        cin >> d[i];
        for (int j = 0; j < d[i]; j++) {
            cin >> a[i][j];
            if (!isHave[a[i][j]]) {
                isHave[a[i][j]] = true;
            }
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (!isHave[i]) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3200
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    h,w = LI()
    a = [input() for i in range(h)]
    r = [list("#"+"."*(w-1)) for i in range(h)]
    b = [list("."*(w-1)+"#") for i in range(h)]
    for i in range(h):
        if i&1:
            r[i] = list("#"*(w-1)+".")
        else:
            b[i] = list("."+"#"*(w-1))

    for i in range(h):
        for j in range(w):
            if a[i][j] == "#":
                r[i][j] = "#"
                b[i][j] = "#"
    for i in r:
        print(*i,sep = "")
    print()
    for i in b:
        print(*i,sep = "")
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 85596
#include<bits/stdc++.h>
using namespace std;
string a[30000];
bool my_cmp(string a,string b)
{
    return a<b;
}
int main()
{
    string s;
    int n,l,count=0,i,j;
    cin>>s;
    l=s.length();
    scanf("%d",&n);
    for(i=1;i<=5;i++)
    {
        for(j=0;j<l;j++)
        {
            a[count++]=s.substr(j,i);
        }
    }
    sort(a,a+count,my_cmp);
    unique(a,a+count);
    cout<<a[n-1]<<endl;
    return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

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

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    ll N; cin >> N;
    ll ans = 1;
    REP(i,N){
        ans = ans*(i+1)%MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back
#define M 1000000007
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
const int N = 2e5 + 1 , md = 998'244'353;
int n , q , seg[4*N] , lazy[4*N] , pw[N] , ones[N];
int mult(ll a , ll b){
	return (a*b)%md;
}
int ad(ll a , ll b){
	ll ret = a + b;
	if(ret >= md) ret -= md;
	return ret;
}
void build(int c , int l , int r){
	if(l == r){
		seg[c] = 1;
		return;
	}
	build(2*c+1 , l , (l+r)/2);
	build(2*c+2 , (l+r)/2+1 , r);
	seg[c] = ad(mult(seg[2*c+1] , pw[r - (l+r)/2]) , seg[2*c+2]);
}
void fix(int c , int l , int r){
	if(lazy[c] == -1)return;
	seg[c] = mult(lazy[c] , ones[r-l+1]);
	if(l == r)return;
	lazy[2*c+1] = lazy[2*c+2] = lazy[c];
	lazy[c] = -1;
}
void update(int c , int l , int r , int s , int e , int d){
	fix(c , l , r);
	if(e < l || s > r) return;
	if(s <= l && e >= r){
		lazy[c] = d;
		//cout << l << " " << r << " " << d << endl;
		fix(c , l , r);
		return;
	}
	update(2*c+1 , l , (l+r)/2 , s , e , d);
	update(2*c+2 , (l+r)/2+1 , r , s ,e , d);
	seg[c] = ad(mult(seg[2*c+1] , pw[r - (l+r)/2]) , seg[2*c+2]);
}
int main(){	
	pw[0] = 1;
	for (int i = 1; i < N; ++i){
		pw[i] = mult(pw[i-1] , 10);
		//cout << pw[i] << endl;
	}
	for (int i = 1 , tmp = 0; i < N; ++i){
		tmp = mult(tmp , 10);
		tmp = ad(tmp , 1);
		ones[i] = tmp;
		//cout << ones[i] << endl;
	}
	scanf("%d%d",&n,&q);
	build(0 , 0 , n-1);
	//cout << seg[0] << endl;
	memset(lazy , -1 , sizeof lazy);
	//q = 1;
	while(q--){
		int l , r , d;
		scanf("%d%d%d",&l,&r,&d);
		update(0 , 0 , n-1 , l-1 , r-1 , d);
		printf("%d\n",seg[0]);
	}

}	

Measured memory_bytes: 10452
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;

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

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

int main(){
	while(1){
		int n;
		cin >> n;
		if(n==0) break;

		vector<lli> d(n),v(n);
		for(int i=0; i<n; i++){
			cin >> d[i] >> v[i];
			lli GCD = gcd(d[i], v[i]);
			if(GCD!=1){
				d[i] /= GCD;
				v[i] /= GCD;
			}
		}
		lli LCM=1;
		for(int i=0; i<n; i++){
			LCM = lcm(LCM, d[i]);
		}
		for(int i=0; i<n; i++){
			v[i] *= LCM / d[i];
		}
		lli GCD = gcd(v[0], v[1]);
		for(int i=2; i<n; i++){
			GCD = gcd(GCD, v[i]);
		}
		for(int i=0; i<n; i++){
			cout << v[i]/GCD << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 3036
#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define ll long long
#define INF 1e9 + 1
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, n) for (int i = 0; i < n; i++)
using namespace std;

int n, S[100010], q, T[50010];

bool binarySearch(int key) {
    int left = 0, right = n;
    while (left < right) {
        int mid = (left + right) / 2;
        if (S[mid] == key) {
            return 1;
        } else if (key < S[mid]) {
            right = mid;
        } else {
            left = mid + 1;
        }
    }
    return 0;
}

int main() {
    cin >> n;
    REP(i, n) cin >> S[i];
    cin >> q;
    REP(i, q) cin >> T[i];
    int cnt = 0;

    REP(i, q) {
        if (binarySearch(T[i])) {
            cnt++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3556
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String[] arr = reader.readLine().split(" ");
        int A = Integer.parseInt(arr[0]);
        int B = Integer.parseInt(arr[1]);
        int C = Integer.parseInt(arr[2]);
        boolean flg = false;
        if (A == B && B != C)
            flg = true;
        if (B == C && C != A)
            flg = true;
        if (C == A && A != B)
            flg = true;
        System.out.println(flg ? "Yes" : "No");
    }
}


Measured memory_bytes: 21332
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    map<string, int> mp;
    int ma = 0;
    REP(i,N){
        string s;
        cin >> s;
        mp[s]++;
        chmax(ma, mp[s]);
    }
    vector<string> ans;
    for(auto x : mp){
        if(x.second == ma) ans.push_back(x.first);
    }
    sort(ans.begin(), ans.end());
    REP(i,ans.size()) cout << ans[i] << endl;
}


Measured memory_bytes: 27632
# -*- coding: utf-8 -*-
def main():
    N = int(input())
    SP=[list(map(str,input().split())) for i in range(N)]
    for k in range(len(SP)):
        SP[k].append(k)
    #print(SP)
    for i in range(len(SP)):
        SP[i][1] = int(SP[i][1])
    #print(N,SP)
    SP.sort(key=lambda x:(x[0],-x[1]))
    for j in range(len(SP)):
        print(SP[j][2]+1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k; cin >> n >> k;
    int sum = 0;
    vector<int> p(n);
    for(int i=0; i<n; i++){
        cin >> p[i];
    }
    sort(all(p));
    for(int i=0; i<k; i++){
        sum += p[i];
    }
    cout << sum;
    cout << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <queue>
#include<algorithm>
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1; i<=n;i++)
#define ALL(a) a.begin(),a.end()
#define B1 1000000007
#define B2 100000007
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
int dx[4] = { 0,0,1,-1 }, dy[4] = { 1,-1,0,0 }, w,n,r,l;
int main() {
    int n,a,b,c,m,o; 
    while (cin >> n, n) {
        m = 0;
        vector<vector<int>> G(10, vector<int>(10, 1e9));
        rep(i, 10) G[i][i] = 0;
        rep(i, n) {
            cin >> a >> b >> c;
            G[a][b] = G[b][a] = c;
            m = max(m, max(a, b));
        }m++;
        vector<vector<int>> dp;
        int ans = 1e9+7;
        rep(j, m) {
            rep(k, m) {
                rep(l, m) {
                    G[k][l] = min(G[k][l], G[k][j] + G[j][l]);
                }
            }
        }
        rep(i, m) {
            int sum = 0;
            rep(j, m) {
                sum += G[i][j];
            }
            if (sum < ans) {
                o = i; ans = sum;
            }
        }
        cout << o << " " << ans << endl;
    }
}


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

#define int long long
#define CASET int _T; cin >> _T; REP(caset, 0, _T)
#define REP(i, l, r) for (int i=(l); i<(r); ++i)
#define RREP(i, r, l) for (int i=(r); i>(l); --i)
#define sq(x) (x)*(x)
#define vi vector<int>
#define vb vector<bool>
#define pii pair<int,int>
#define t3i tuple<int,int,int>
#define t4i tuple<int,int,int,int>
#define mii map<int,int>

const int INF = 1LL<<60;
const int MOD = 998244353;

template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
string to_string(string s) {return s;}
string to_string(bool b) {return b?"true":"false";}
template <typename A, typename B>
string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> t) {return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ")";}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> t) { return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ", " + to_string(get<3>(t)) + ")";}
template <typename A>
string to_string(vector<A> v) {
    bool first = true;
    string result = "[";
    for (A i : v) {
        if (!first) result += ", ";
        first = false;
        result += to_string(i); 
    }
    return result + "]";
}
string bin_string(int x) {
    const int d = 32;
    string result(d, ' ');
    REP(i, 0, d) result[d-1-i] = '0'+(x>>i & 1LL);
    return result;
}

int powa(int base, int exp) {
    int res = 1;
    while (exp) {
        if (exp&1) res = res*base % MOD;
        base = base*base % MOD;
        exp >>= 1;
    }
    return res;
}

vector<vi> nodes;
vb seen;
void dfs(int u, int p=-1) {
    if (seen[u]) return;
    seen[u] = true;
    for (int v : nodes[u]) if (v!=p) {
        dfs(v, u);
    }
}

main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    
    int a,b,c;
    cin >> a >> b >> c;
    int t = min(a,c);
    a -= t;
    c -= t;
    t = min(b,c);
    b -= t;
    c -= t;
    cout << a << ' ' << b;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
import itertools

input = sys.stdin.readline

def main():
    N = int(input())
    S = [input().strip() for _ in range(N)]

    cnt = [0 for _ in range(5)]
    for s in S:
        if s[0] == "M":
            cnt[0] += 1
        if s[0] == "A":
            cnt[1] += 1
        if s[0] == "R":
            cnt[2] += 1
        if s[0] == "C":
            cnt[3] += 1
        if s[0] == "H":
            cnt[4] += 1

    p = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2]
    q = [1, 1, 1, 2, 2, 3, 2, 2, 3, 3]
    r = [2, 3, 4, 3, 4, 4, 3, 4, 4, 4]

    n = 0
    for i in range(10):
        n += cnt[p[i]] * cnt[q[i]] * cnt[r[i]]
    print(n)

main()


Measured memory_bytes: 9772
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        N: usize,
        A: u64,
        B: u64,
        X: [u64; N],
    }
    let mut ans:u64 = 0;
    for i in 0..N-1{
        ans += min(B, A*(X[i+1]-X[i]));
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <list>
#include <cstdint>
#include <bits/stdc++.h>
#include <queue>
#include <set>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for (int i = n - 1; i >= 0; i--)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

#define INF bit(60)
#define pb push_back
#define mod 1000000007

template <class T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
  if (b < a)
  {
    a = b;
    return 1;
  }
  return 0;
}

using namespace std;
using uif = uint_fast64_t;
using ll = long long int;

int qp(int a, ll b)
{
  int ans = 1;
  do
  {
    if (b & 1)
      ans = 1ll * ans * a % mod;
    a = 1ll * a * a % mod;
  } while (b >>= 1);
  return ans;
}
int qp(int a, ll b, int mo)
{
  int ans = 1;
  do
  {
    if (b & 1)
      ans = 1ll * ans * a % mo;
    a = 1ll * a * a % mo;
  } while (b >>= 1);
  return ans;
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

#define FACSIZE 2002

ll invfac[FACSIZE];
ll fac[FACSIZE];

ll mod_pow(ll, ll);
ll mod_add(ll, ll);
ll mod_mul(ll, ll);
ll mod_div(ll, ll);
void make_fact(ll);
void make_invfact(ll);

int main(void)
{

  ll n;
  cin >> n;

  for (ll i = 1; i <= 50000; i++)
  {
    if ((ll)(i * 1.08) == n)
    {
      cout << i << endl;
      return 0;
    }
  }

  cout << ":(" << endl;

  return 0;
}

ll mod_pow(ll x, ll r)
{
  if (r == 0)
    return 1;
  else if (r == 1)
    return x % mod;
  else if (r % 2 == 0)
  {
    ll t = mod_pow(x, r / 2) % mod;
    return t * t % mod;
  }
  else
  {
    ll t = mod_pow(x, r / 2) % mod;
    ll k = t * t % mod;
    return k * x % mod;
  }
}
ll mod_add(ll a, ll b)
{
  return (a + b) % mod;
}

ll mod_mul(ll a, ll b)
{
  return (a * b) % mod;
}

ll mod_div(ll a, ll b)
{
  return mod_mul(a, mod_pow(b, mod - 2));
}

void make_fact(ll n)
{
  fac[0] = 1;
  rep(i, n)
  {
    fac[i + 1] = mod_mul(fac[i], i + 1);
  }
}

void make_invfact(ll n)
{
  invfac[n] = mod_pow(fac[n], mod - 2);
  for (int i = n - 1; i >= 0; i--)
  {
    invfac[i] = mod_mul(invfac[i + 1], i + 1);
  }
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        String str[]=br.readLine().split(" ");
        long x=Long.parseLong(str[0]);
        long pow5[]=new long[6201];
        for(int i=0;i<=6200;i++)
        pow5[i]=(long)Math.pow(i,5);
        int a=-1,b=10000;
        for(int i=0;i<=6200;i++)
        {
            a=i;
            b=10000;
            for(int j=0;j<=6200;j++)
            {
                if(pow5[i]-pow5[j]==x)
                {
                    b=j;
                    break;
                }
                else if(pow5[i]+pow5[j]==x)
                {
                    b=-j;
                    break;
                }
            }
            if(b!=10000)
            break;
        }
        pw.println(a+" "+b);
        pw.flush();
        pw.close();
    }
}

Measured memory_bytes: 37024
#include<bits/stdc++.h>
using namespace std;
int main(){
long int m,n,i,x=1,s=1,t,u,v,w,y,r=1,k;
scanf("%ld %ld",&m,&n);
for(i=1; x<1000000007 && i<=n ;++i){
x=x*m;
 }
if(x<1000000007){
   cout<<x<<endl;
}else{
   t=n/(i-1);
   u=n%(i-1);
   v=x%1000000007;
   for(w=1;w<=t;++w){
       s=s*v%1000000007;
   }
   for(k=1;k<=u;++k){
       r=r*m;
}
   y=s*r;
   printf("%ld\n",y%1000000007);
}
return 0;
}


Measured memory_bytes: 3228
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

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

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

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

	bool con[8][8];
	memset(con, false, sizeof(con));
	rep(i, M) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		con[a][b] = true;
		con[b][a] = true;
	}

	vector<int> v;
	rep(i, N) v.push_back(i);

	int ret = 0;
	do {
		bool ok = true;
		rep(i, N - 1) {
			ok &= con[v[i]][v[i + 1]];
		}
		ret += ok;
	} while (next_permutation(v.begin() + 1, v.end()));

	cout << ret << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
 	int n;
  	cin>>n;
  	long long res = 0;
  	int max = -1;
  	while(n--){
     	int elem;
      cin>>elem;
      if(elem < max){
        res += max - elem;
      } else {
        max = elem;
      }
    }
  cout<<res<<endl;
  
}

Measured memory_bytes: 3596
using System;

namespace ABC100_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] array = Console.ReadLine().Split(' ');
            int a = int.Parse(array[0]);
            int b = int.Parse(array[1]);
            if((a <= 8) && (b <= 8))
            {
                Console.WriteLine("Yay!");
            }
            else
            {
                Console.WriteLine(":(");
            }
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, P;
    cin >> A >> P;
    cout << (A * 3 + P) / 2 << endl;

    return 0;
}


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

int main(){
    int N = 0;
    cin >> N;
    vector<int> a(N, 0);
    for(int i = 0; i < N; i++){
        cin >> a.at(i);
    }

    sort(a.begin(), a.end());
    int sum_A = 0;
    int sum_B = 0;

    for(int i = 0; i < N; i++){
        if(i % 2 == 0){
            sum_A += a.at(i);
        }
        else{
            sum_B += a.at(i);
        }
    }
    int ans = abs(sum_A - sum_B);
    cout << ans << endl;
}

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

int main(){
    int n, k, q;
    std::cin >> n >> k >> q;

    std::vector<int> reduction(n, 0);
    int val;
    while(std::cin >> val){
        ++reduction.at(val - 1);
    }

    for(int i = 0; i < n; ++i){
        if(k - q + reduction.at(i) <= 0){
            std::cout << "No" << std::endl;
        }else{
            std::cout << "Yes" << std::endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1024
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::cmp::max;

pub struct Comb {
    max: usize,
    m: i64,
    fac: Vec<i64>,
    finv: Vec<i64>,
}
impl Comb {
    /// initialize table
    /// max: maximum that n as nCk takes
    /// m: MOD, a prime number
    /// O(n)
    pub fn new(max: usize, m: i64) -> Comb {
        let n = max;
        let mut fac = Vec::with_capacity(n);
        fac.push(1);
        fac.push(1);
        let mut finv = Vec::with_capacity(n);
        finv.push(1);
        finv.push(1);
        let mut inv = Vec::with_capacity(n);
        inv.push(1);
        inv.push(1);
        for i in 2..n {
            let i = i as i64;
            let tmp = fac.last().unwrap() * i % m;
            fac.push(tmp);
            let tmp = m - inv[(m % i) as usize] * (m / i) % m;
            inv.push(tmp);
            let tmp = finv.last().unwrap() * inv.last().unwrap() % m;
            finv.push(tmp);
        }
        Comb {
            max: max,
            m: m,
            fac: fac,
            finv: finv,
        }
    }
    /// nCr
    pub fn ncr(&self, n: usize, k: usize) -> i64 {
        // since n, k are usize, do not need to check `n < 0 || k < 0`
        if n < k || n > self.max {
            panic!("Invalid query (n, k) = ({}, {})", n, k);
        } else {
            self.fac[n] * (self.finv[k] * self.finv[n - k] % self.m) % self.m
        }
    }
}

use std::cmp::min;

fn main() {
    let n: usize = read();
    let mut a: Vec<i64> = vec![];
    let mut maxv = 0;
    let mut ansx = 0;
    let mut ansy = 0;

    for i in 0..n {
        let ai = read();
        if maxv < ai {
            maxv = ai;
            ansx = ai;
        }
        a.push(ai);
    }

    let mut dist = std::i64::MAX;

    for i in 0..a.len() {
        let ai = a[i];
        if ai == maxv {
            continue;
        }
        let mut ad = 0;
        if maxv % 2 == 0 {
            ad = ((maxv / 2) - ai).abs();
        } else {
            ad = min(((maxv - 1) / 2 - ai).abs(), ((maxv + 1) / 2 - ai).abs());
        }
        if ad < dist {
            ansy = ai;
            dist = ad;
        }
    }
    println!("{} {}", ansx, ansy);

    // let mut ans = 0;
    //
    // for i in 0..n {
    //     let ai = a[i];
    //     println!("{} {}", ai, maxv);
    //     println!("result{}", result);
    //     ans = max(ans, result);
    // }
    // println!("{}", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;int64_t N,P,a,c[1<<20],i,j;string S;
main() {
	cin>>N>>P>>S;
	if (10%P){
		reverse(S.begin(),S.end()),c[0]=j=1;
		for (char v:S)i+=(v-48)*(j=j*10%P),a+=c[i%=P]++;
	} else for(;i<N;a+=(S[i++]-48)%P?0:i);
	cout<<a;
}

Measured memory_bytes: 644
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    int cnt = 0;
    for (int i = 0; i < N; i++) {
      if (K <= sc.nextInt()) {
        cnt++;
      }
    }
    System.out.println(cnt);
  }
}


Measured memory_bytes: 49204
def main():
    *a, = map(int, input().split())
    f = max(a) % 2 == 0
    g = sum(a) % 2 == 0
    if f == g:
        m = max(a)
    else:
        m = max(a) + 1

    ans = (3 * m - sum(a)) // 2
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>

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

int N;
string s;

int main() {
  cin >> N >> s;
  vector<bool> ans(N);
  for (int i=0; i<4; i++) {
    if (i == 0) {
      ans.at(0) = true;
      ans.at(1) = true;
    } else if (i == 1) {
      ans.at(0) = true;
      ans.at(1) = false;
    } else if (i == 2) {
      ans.at(0) = false;
      ans.at(1) = true;
    } else {
      ans.at(0) = false;
      ans.at(1) = false;
    }
    for (int j=2; j<N; j++) {
      if (s.at(j-1) == 'o') {
        ans.at(j) = !(ans.at(j-1) ^ ans.at(j-2));
      } else {
        ans.at(j) = ans.at(j-1) ^ ans.at(j-2);
      }
    }
    // s = N-1
    if ((s.at(N-1) == 'o') ^ ans.at(N-1)) {
      if (ans.at(N-2) == ans.at(0)) {
        continue;
      }
    } else {
      if (ans.at(N-2) != ans.at(0)) {
        continue;
      }
    }
    // s = 0
    if ((s.at(0) == 'o') ^ ans.at(0)) {
      if (ans.at(N-1) == ans.at(1)) {
        continue;
      }
    } else {
      if (ans.at(N-1) != ans.at(1)) {
        continue;
      }
    }
    rep(j,N) {
      char c;
      if (ans.at(j)) {
        c = 'S';
      } else {
        c = 'W';
      }
      cout << c;
    }
    cout << endl;
    return 0;
  }
  cout << -1 << endl;
}


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

int main() {
    int a, b;
    cin >> a >> b;

    int sum = 0;
    for (int i = 1; i < 1000; i++) {
        sum += i;
        if (i == b - a) {
            cout << sum - b << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main (void)
{
  string s;
  cin>>s;
  int n,i,j,k;
  n=s.size();
  for(i=0;i<n;i++)
  {
  if(i%2==0&&(s[i]=='R'||s[i]=='U'||s[i]=='D')){}
  else if(i%2==1&&(s[i]=='L'||s[i]=='U'||s[i]=='D')){}
  else {cout<<"No"<<endl;return 0;}
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 3572
import numpy as np

mod = 998244353
n, s = map(int, input().split())
dp = np.zeros(s+1, dtype=int)
dp[0] = 1
for a in map(int, input().split()):
  pre_dp = dp
  dp = pre_dp * 2 % mod
  dp[a:] = (dp[a:] + pre_dp[:-a]) % mod
print(dp[-1])

Measured memory_bytes: 27464