akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define si(X) scanf("%d", &(X))
#define sll(X) scanf("%lld",&(X))
#define INFL 0x3f3f3f3f3f3f3f3fLL

const int mod = 1e9+7;
ll gcd(ll a,ll b){
	if(b==0)
	return a;return gcd(b,a%b);
}
ll expo(ll base,ll pow){
    ll ans = 1;
    while(pow!=0){
        if(pow&1==1){
            ans = ans*base;
            ans = ans%mod;
        }
        base *= base;base%=mod;
        pow/=2;
    }return ans;
}
ll inv(ll x){
    return expo(x,mod-2);
}

double pi = 3.141592653589793238462643;
double error = 0.0000001;
int dx[8] = {1 , 0 , -1 , 0 , 1 , -1 , -1 , 1};    // last 4 diagonal
int dy[8] = {0 , 1 , 0 , -1 , 1 , 1 , -1 , -1};
/* -------Template ends here-------- */

const ll M = 2222;
const int M2 = 100011;
const ll lim = 1e12;

vector<ll> cubes , prime;

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


void sieve_type() {
    for (int i = 2; i < M; i++) {
        if (is_p(i)) cubes.push_back(1ll * i * i * i);
    }
    for (int i = 2; i < M2; i++) {
        if (is_p(i)) prime.push_back(i);
    }
}

ll divfac(ll x) {
    for (ll q : cubes) {
        if (q > x)break;
        while (x % q == 0) x /= q;
    }
    return x;
}

ll cal(ll a, ll b) {
    if (lim / b < a) return lim;
    return a * b;
}

ll complement(ll x) {
    ll y = 1;
    for (int p : prime) {
        if (1ll * p * p > x) break;
        if (x % p == 0) {
            if (((x / p) % p) == 0)
                y = cal(y, p), x /= p, x /= p;
            else
                y = cal(y, cal(p, p)), x /= p;
        }
    }
    if (x != 1) y = cal(y, cal(x, x));
    return y;
}
map<ll, int> look;
set<ll> done;
int main() {
    int n;
    scanf("%d", &n);
    sieve_type();

    for (int i = 1 ; i <= n ; i++) {
        ll x;
        scanf("%lld", &x);
        x = divfac(x);
        look[x]++;
    }
    ll ans = 0;

    for (auto pr : look) {
        ll x = pr.first;
        int c = pr.second;
        ll y = complement(x);

        if (done.count(x))continue;

        if (x == y) {
            ans++;
            continue;
        }
         if (look.count(y)) {
                ans += max(c, look[y]);
                done.insert(y);
                done.insert(x);
            } else {
                done.insert(x);
                ans += c;
            }
    }
    printf("%d\n", ans);
}





Measured memory_bytes: 11264
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
#include <bits/stdc++.h>
#define int long long
#define N 5005
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<22,stdin),p1 == p2)?EOF:*p1++)
using namespace std ;
//char buf[(1 << 22)] , *p1 = buf , *p2 = buf ;
inline int read ()
{
    char c = getchar () ; int x = 0 , f = 1 ;
    while (c < '0' || c > '9') { if (c == '-') f = -1 ; c = getchar () ; }
    while (c >= '0' && c <= '9'){ x = x * 10 + c - '0' ; c = getchar () ; }
    return x * f ;
}
int l[205][N] , r[205][N] , b[205][N] , n , m , c[N][N] , s[N] , ans , st[N] , w[N] , top ;
signed main ()
{
//	freopen (".in" , "r" , stdin) ; freopen (".out" , "w" , stdout) ;
	n = read () , m = read () ;
	for (int i = 2 ; i <= n ; i ++) s[i] = s[i - 1] + read () ;
	for (int i = 1 ; i <= n ; i ++)
		for (int j = 1 ; j <= m ; j ++)
			b[j][i] = read () ;
	for (int i = 1 ; i <= m ; i ++)
	{
		top = 0 ;
		for (int j = 1 ; j <= n ; j ++)
		{
			while (top && w[top] < b[i][j]) top -- ;
			l[i][j] = top ? st[top] + 1 : 1 ;
			st[++ top] = j ;
			w[top] = b[i][j] ;
		}
		top = 0 ;
		for (int j = n ; j >= 1 ; j --)
		{
			while (top && w[top] < b[i][j]) top -- ;
			r[i][j] = top ? st[top] - 1 : n ;
			st[++ top] = j ;
			w[top] = b[i][j] ;
		}
		for (int j = 1 ; j <= n ; j ++)
		{
			c[l[i][j]][j] += b[i][j] ;
			c[j + 1][r[i][j] + 1] += b[i][j] ;
			c[l[i][j]][r[i][j] + 1] -= b[i][j] ;
			c[j + 1][j] -= b[i][j] ;
		}
	}
	ans = 0 ;
	for (int i = 1 ; i <= n ; i ++)
	{
		for (int j = 1 ; j <= n ; j ++) c[i][j] += c[i][j - 1] ;
		for (int j = 1 ; j <= n ; j ++) c[i][j] += c[i - 1][j] ;
		for (int j = i ; j <= n ; j ++) ans = max (ans , c[i][j] - s[j] + s[i]) ;
	}
	cout << ans ;
}


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

int main() {
 int N,K;
 cin>>N>>K;
 int sum=0;
 for(int i=0; i<N; i++){
   int x;
   cin>>x;
   if(x>K/2){
     sum=sum+2*(K-x);
   }
   else{
     sum=sum+2*x;
   }
 }
 cout<<sum<<endl;
}  





Measured memory_bytes: 256
#include<iostream> 
#include<iomanip> 
#include<vector> 
#include<map> 
#include<set> 
#include<algorithm> 
#include<numeric> 
#include<limits> 
#include<bitset> 
#include<functional> 
#include<type_traits> 
#include<queue> 
#include<stack> 
#include<array> 
#include<random> 
#include<utility> 
#include<cstdlib> 
#include<ctime>
#define INT_MAX 2147483647
#define _LIBCPP_DEBUG 0
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (n); ++i)	
using namespace std;


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


int main() {
	int n;
	cin >> n;
	int t, a;
	cin >> t >> a;

	vector<int> h(n);

	int INF = INT_MAX;
	double res = INF;
	int findID = -1;

	rep(i, n) {
		cin >> h[i];
		double temp = t - h[i] * 0.006;
		if (res > abs(temp-a)) {
			res = abs(temp-a);
			findID = i;
		}
	}

	cout << findID + 1 << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int h, w;
  cin >> h >> w;
  int sharp = 0;
  rep(i, h) rep(j, w) {
    char c;
    cin >> c;
    if(c == '#') sharp++;
  }
  cout << (sharp == h + w - 1 ? "Possible" : "Impossible") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}
ll lcm(ll x,ll y){
  ll g=gcd(x,y);
  return x/g*y;
}

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  int n;
  string s;
  cin >>n>>s;
  int a[26]={};
  ll ans=1;
  rep(i,n){
    a[s[i]-'a']++;
  }
  rep(i,26){
    a[i]++;
    a[i]%=MOD;
    ans*=a[i];
    ans%=MOD;
  }
  ans--;
  ans%=MOD;

  cout<<ans<<endl;
}


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

using namespace std;

bool match(char a,char b)
{
	return (a^1<<5)==b;
}

int solve(vector<string>& ps,vector<int>& perm,int cur)
{
	if(cur==9)
		return 1;
	
	int res=0;
	for(int k=cur;k<9;k++){
		swap(perm[cur],perm[k]);
		int i=cur/3,j=cur%3;
		for(int l=0;l<4;l++){
			bool flg=true;
			if(i>=1 && !match(ps[perm[cur]][0],ps[perm[(i-1)*3+j]][2]))
				flg=false;
			if(j>=1 && !match(ps[perm[cur]][3],ps[perm[i*3+(j-1)]][1]))
				flg=false;
			if(flg)
				res+=solve(ps,perm,cur+1);
			rotate(ps[perm[cur]].begin(),ps[perm[cur]].begin()+1,ps[perm[cur]].end());
		}
		swap(perm[cur],perm[k]);
	}
	return res;
}

int main()
{
	int tc; cin>>tc;
	while(tc--){
		vector<string> ps(9);
		for(int i=0;i<9;i++)
			cin>>ps[i];
		
		vector<int> perm(9);
		iota(perm.begin(),perm.end(),0);
		cout<<solve(ps,perm,0)<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1224
#include<stdio.h>
#define MATCH 1
#define NOT -1
int serch(int,int ,int);
int search(int *A,int n,int key)
{
  int i=0;
  A[n]=key;
  for(i=0;i<n;i++)
    {
      if(A[i]==key) return MATCH;
    }
    return NOT;
}

int main()
{
  int A[10001];
  int i,j,n,q,cnt=0;
  int key;

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

  scanf("%d",&q);
  for(i=0;i<q;i++)
    {
      scanf("%d",&key);
      if(search(A,n,key)==MATCH)cnt++;
    }
  printf("%d\n",cnt);
  return 0;
}
  

Measured memory_bytes: 636
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>
#include <iostream> // cout, endl, cin
#include <map>      // map
#include <math.h>
#include <numeric>
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
const int INF = 1001001001;
const int BG = 1000000007;

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

    int dp[N + 1][3];
    dp[0][0] = dp[0][1] = dp[0][2] = 0;
    for (int i = 1; i <= N; i++)
    {
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i - 1];
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i - 1];
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i - 1];
    }
    int maxi = max(max(dp[N][0], dp[N][1]), dp[N][2]);
    cout << maxi << endl;
}

Measured memory_bytes: 2560
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int i,j,n,ama[10000],amb[10000],p,x,ke[10000];
	while(1)	{
		scanf("%d",&n);
		if(n==0)	break;
		for(i=0;i<n;i++)	ama[i]=0;
		for(i=1;i<n;i++)	{
			x=(i*i)%n;
			ama[x]=1;
		}
		p=0;
		for(i=0;i<n;i++)	{
			if(ama[i]==1)	{
				amb[p]=i;
				p++;
			}
		}
		for(i=1;i<=(n-1)/2;i++)	ke[i]=0;
		for(i=0;i<p;i++)	{
			for(j=0;j<p;j++)	{
				if(i!=j)	{
					x=amb[i]-amb[j];
					if(x<0)	x+=n;
					if(x>(n-1)/2)	x=n-x;
					ke[x]++;
				}
			}
		}
		for(i=1;i<=(n-1)/2;i++)	{
			printf("%d\n",ke[i]);
		}
	}
	return 0;
}


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

int n, m, c, a[105][105], b[105][105];
int main()
{
	int i, j, k, t1, t2, t3;
	cin >> n >> m;
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= n; j++) {
			b[i][j] = 1e9;
		}
	}
	for (i = 0; i < m; i++) {
		scanf("%d %d %d", &t1, &t2, &t3);
		a[t1][t2] = a[t2][t1] = b[t1][t2] = b[t2][t1] = t3;
	}
	for (k = 1; k <= n; k++) {
		for (i = 1; i <= n; i++) {
			for (j = 1; j <= n; j++) {
				if (b[i][j] > b[i][k] + b[k][j]) {
					b[i][j] = b[i][k] + b[k][j];
				}
			}
		}
	}
	for (i = 1; i <= n; i++) {
		for (j = i + 1; j <= n; j++) {
			if (b[i][j] < a[i][j]) {
				c++;
			}
		}
	}
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	ll n;
	cin>>n;
	vector<ll> a(n);
	rep(i, n) cin>>a[i];
	ll pr = 0;
	rep(i, n) pr ^= (a[i]-1)%2;
	if(n%2==0 || pr==1) cout<<(pr?"First":"Second")<<endl;
	else {
		int turn = 0;
		while(true){
			rep(i, n){
				if(a[i]%2 && a[i]>1){
					a[i]--;
					break;
				}
			}
			ll g = a[0];
			rep(i, n) g = __gcd(g, a[i]);
			if(g%2) break;
			rep(i, n) a[i] /= g;
			pr = 0;
			rep(i, n) pr ^= (a[i])%2;
			if(pr==0) break;
			turn = !turn;
		}
		cout<<(turn?"First":"Second")<<endl;
	}
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>

using namespace std;
typedef unsigned long long u64;

int main()
{
	u64 a, b, x;
	u64 ret = 0;
	cin >> a >> b >> x;
	if (x == 1)
		cout << b - a + 1 << endl;
	else if (a == b) {
		if (a % x == 0)
			cout << 1 << endl;
		else
			cout << 0 << endl;
	} else if (a == 0) {
		cout << 1 + (b) / x << endl;
	} else {
		cout << (b) / x - (a-1) / x << endl;
	}
	return 0;
}


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

int main() {
  int A, B;
  cin >> A >> B;
  if (A*B%2==0) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 3568
#include<cstdio>
#include<cstring>
#include<algorithm>
#define SF scanf
#define PF printf
#define MAXN 100010
using namespace std;
typedef long long ll;
ll a[MAXN];
int n,now,cnt0,cnt1;
ll gcd(ll x,ll y){
	if(y==0)
		return x;
	return gcd(y,x%y);	
}
bool solve(){
	int cnt0=0,cnt1=0,now=0;
	for(int i=1;i<=n;i++){
		if(a[i]%2ll==0)
			cnt0++;
		else{
			cnt1++;
			now=i;
		}
	}
	if(cnt1==1&&a[now]!=1){
		ll g=0;
		a[now]--;
		for(int i=1;i<=n;i++)
			g=gcd(g,a[i]);
		for(int i=1;i<=n;i++)
			a[i]/=g;
		if(solve()==0)
			return 1;
	}
	if(cnt0%2==1)
		return 1;
	else
		return 0;
}
int main(){
	//freopen("game.in","r",stdin);
	//freopen("game.out","w",stdout);
	SF("%d",&n);
	for(int i=1;i<=n;i++)
		SF("%lld",&a[i]);
	if(solve())
		PF("First");
	else
		PF("Second");
}

Measured memory_bytes: 896
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>

using namespace std;

#define ll long long
const int N = 1e4+5;

queue <int> q;
int n;
struct node{
	int from,to,next;
}f[2*N];
int head[N],tot;
int ans[N],vis[N],dis[N];

void add(int a,int b){
	f[++tot].from = a;
	f[tot].to = b;
	f[tot].next = head[a];
	head[a] = tot;
}

void clean(){
	memset(dis,0x7f,sizeof(dis));
	memset(vis,0,sizeof(vis));
}

void spfa(int s){
	dis[s] = 0;
	vis[s] = 1;
	q.push(s);
	while(!q.empty()){
		int now = q.front();
		q.pop();
		//cout << head[now];
		for(int i = head[now]; i != -1; i = f[i].next){
			int v = f[i].to;
			//cout << v;
			if(dis[v] > dis[now] + 1){
				dis[v] = dis[now] + 1;
				if(!vis[v]){
					vis[v] = 1;
					q.push(v);
				}
			}
		}
	}
}

int main(){
	int x,y;
	memset(head,-1,sizeof(head));
	cin >> n >> x >> y; 
	for(int i = 2; i <= n; i++) add(i-1,i),add(i,i-1);
	add(x,y),add(y,x);
	for(int i = 1; i <= n; i++){
		clean(); spfa(i);
		//cout << i << "GG ";
		for(int j = i+1; j <= n; j++) ans[dis[j]]++;//cout<<dis[j] << " ";
		//cout << endl;
	}
	for(int i = 1; i < n; i++)
		cout << ans[i] << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define N 45
using namespace std;
int pre[N], p = 0;
int in[N];
int n;
vector<int> post;
void rec(int l, int r){
    if (l >= r) return ;
    int c = pre[p++];
    int m;
    for(m = 0; m < n; m++){
        if(in[m] == c) break;
    }
    rec(l, m);
    rec(m+1, r);
    post.push_back(c);
}
int main() {
    scanf("%d", &n);
    for(int i = 0; i < n; i++) scanf("%d", &pre[i]);
    for(int i = 0; i < n; i++) scanf("%d", &in[i]);
    rec(0, n);
    for(int i = 0; i < post.size(); i++){
        printf("%d", post[i]);
        i == post.size()-1 ? printf("\n") : printf(" ");
    }
    return 0;
}


Measured memory_bytes: 3300
import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]

N,K = LI()
p = []
for i in range(N):
    a,b = LI()
    p.append((a,b,i))
sx = sorted(p)
ans = 10**50
for x,y,i in sx:
    for x2,y2,i2 in sx:
        if x2 <= x:
            continue
        points = sx.index((x2,y2,i2)) - sx.index((x,y,i)) + 1
        if points < K:
            continue
        sy = sorted(sx[sx.index((x,y,i)):sx.index((x2,y2,i2))+1],key=lambda sx: sx[1])
        for j in range(len(sy)-K+1):
            if sy[j][1] <= y and y2 <= sy[j+K-1][1]:
                ans = min(ans, (x2 - x) * (sy[j+K-1][1]-sy[j][1])) 
print(ans)


Measured memory_bytes: 3192
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

#define mod 1e9+7
#define ll long long int
#define epsilon 1e-7

ll mi(ll x, ll y){
    if(x<y)return x;
    return y;
}
int a[500][500];
int y[250000];
int x[250000];
int yy[250000];
int xx[250000];
int main(void){
    int h, w;
    scanf("%d %d", &h, &w);
    for(int i = 0;i < h;i++)for(int j = 0;j < w;j++)scanf("%d", &a[i][j]);
    int n = 0;
    for(int i = 0;i < h;i++)for(int j = 0;j < w;j++){
        if(a[i][j]%2){
            if(j != w-1){
                a[i][j+1]++;
                y[n] = i;
                x[n] = j;
                yy[n] = i;
                xx[n] = j+1;
                n++;
            }else if(i != h-1){
                a[i+1][j]++;
                y[n] = i;
                x[n] = j;
                yy[n] = i+1;
                xx[n] = j;
                n++;
            }
        }
    }
    printf("%d\n", n);
    for(int i = 0;i < n;i++)printf("%d %d %d %d\n", y[i]+1, x[i]+1, yy[i]+1, xx[i]+1);
    return 0;
}


Measured memory_bytes: 6016
#include <iostream>
#include <utility>
#include <algorithm>
#include<cmath>
#include<algorithm>
#include<vector>
#include<cstring>
#include <math.h>
#include <map>
#include <vector>
#include <iomanip>
#include <set>
#include <deque>
#define ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define ll long long
#define pb push_back
using namespace std;

const int N = 2e6, PI = 3.14159265359, M = 1e9 + 7;
typedef pair <ll, ll> pii;
map <ll, ll> dp;
ll a[N], ans = 0;
map <pii, ll> ma;

int main() {
	ll n, ans = 0;
	cin >> n;
	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;
	for(int i = 0; i < n; i++) {
		if(s1[i] == s2[i]) {
			if(s1[i] == s3[i]) 
				ans += 0;
			else
				ans += 1;
		}
		else {
			if(s1[i] == s3[i])
				ans += 1;
			else if(s2[i] == s3[i])
				ans += 1;
			else 
				ans += 2;
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back(a)
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 1e18;


void solve() {
	int A, B, Q; cin >> A >> B >> Q;
	vector<int>S, T;
	S.push_back(-INF);
	T.push_back(-INF);
	S.push_back(INF);
	T.push_back(INF);
	REP(i, A) {
		int s; cin >> s;
		S.push_back(s);
	}
	REP(i, B) {
		int t; cin >> t;
		T.push_back(t);
	}
	VSORT(S); VSORT(T);
	REP(_, Q) {
		int x; cin >> x;
		int rs, ls, rt, lt;
		rs = *lb(S, x);
		ls = *((ub(S, x) - 1));
		rt = *lb(T, x);
		lt = *(ub(T, x) - 1);
		ll res = 1e18;
		res = min(res, max(rs, rt) - x);
		res = min(res, x - min(ls, lt));
		res = min(res, rs - lt + min(rs - x, x - lt));
		res = min(res, rt - ls + min(rt - x, x - ls));
		print(res);
	}
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
inline int_fast64_t read(){int_fast64_t x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return x*f;}
inline string read_s(){string s="";char c=getchar();while(c<'!'||c>'~'){c=getchar();}while(c>='!'&&c<='~'){s+=c;c=getchar();}return s;}
void Main(){
    int N = read(), D = read();
    vector<vector<int> > X(N, vector<int>(D));
    for (int i = 0; i<N; i++) {
        for (int j = 0; j<D; j++) {
            X[i][j] = read();
        }
    }
    int ans = 0, tmp, kk;
    for (int i = 0; i<N-1; i++) {
        for (int j = i+1; j<N; j++) {
            tmp = 0;
            for (int k = 0; k<D; k++) {
                tmp += (X[i][k]-X[j][k]) * (X[i][k]-X[j][k]);
            }
            for (int k = 1;; k++) {
                kk = k * k;
                if (kk >= tmp){
                    if (kk == tmp) ans++;
                    break;
                }
            }
        }
    }
    printf("%d\n", ans);
}
int main(){cin.tie(nullptr);ios::sync_with_stdio(false);Main();return 0;}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void)
{
    int moneyX,moneyY,maxY,plusY,use;
    cin>>moneyX>>moneyY>>maxY>>plusY>>use;
    if(maxY<use)moneyY+=(use-maxY)*plusY;
    if(moneyX * use <=  moneyY)cout<<moneyX*use<<endl;
    else cout<<moneyY<<endl;
}

Measured memory_bytes: 1160
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node {
	int key;
	Node *next, *prev;
};

Node *nil;

void init() {
	nil = (Node *)malloc(sizeof(Node));
	nil->next = nil;
	nil->prev = nil;
}

void deleteNode(Node *n) {
	if (n == nil) return;
	n->prev->next = n->next;
	n->next->prev = n->prev;
	free(n);
}

void deleteFirst() {
	deleteNode(nil->next);
}

void deleteLast() {
	deleteNode(nil->prev);
}

Node *searchNode(int key) {
	Node *n;
	for (n = nil->next; n != nil; n = n->next) {
		if (n->key == key) {
			break;
		}
	}
	return n;
}

void deleteKey(int key) {
	deleteNode(searchNode(key));
}

void insert(int key) {
	Node *newNode = (Node *)malloc(sizeof(Node));

	newNode->key = key;

	nil->next->prev = newNode;
	newNode->next = nil->next;
	nil->next = newNode;
	newNode->prev = nil;
}

void printList() {
	bool isf = true;
	for (Node *n = nil->next;n != nil; n = n->next) {
		if (isf) {
			isf = false;
		}
		else {
			printf(" ");
		}
		printf("%d", n->key);
	}
	printf("\n");
}

int main() {
	int key, n, i;
	int size = 0;
	char com[30];
	scanf("%d", &n);
	init();

	for (i = 0; i < n; i++) {
		scanf("%s", com);
		if (com[0] == 'i') {
			scanf("%d", &key);
			insert(key);
		}
		else if (com[0] == 'd') {
			if (strlen(com) > 6) {
				if (com[6] == 'F') deleteFirst();
				else if (com[6] == 'L') deleteLast();
			}
			else {
				scanf("%d", &key);
				deleteKey(key);
			}
		}
	}
	printList();
	return 0;
}


Measured memory_bytes: 34004
import java.io.*;
import java.util.*;


public class Main{
	
	public static void main(String[] args){
	
	MyScanner sc = new MyScanner();
	out = new PrintWriter(new BufferedOutputStream(System.out));
	
	/**/
	
	int number = sc.nextInt();
	long counter = 0;	
		
		
	for(int a = 1; a < number; a++){
		
		for(int b = 1; b < number; b++){
			
			if(number - (a * b) > 0){
				counter++;
			}else{
				break;
			}
			
		}
		
	}	
		
		System.out.println(counter);
		
		
	


	
	
	
	/**/
	 
	 out.close();	
	}
	
	public static PrintWriter out;
	
	public static class MyScanner{
		
		BufferedReader br;
		StringTokenizer st;
		
		public MyScanner(){
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }
 
      int nextInt() {
          return Integer.parseInt(next());
      }
 
      long nextLong() {
          return Long.parseLong(next());
      }
 
      double nextDouble() {
          return Double.parseDouble(next());
      }
 
      String nextLine(){
          String str = "";
	  try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  }
	  return str;
      }

   }
	
}


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

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

typedef long long ll;
int main(int argc, char const *argv[])
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    double R; cin >> R;
    cout << std::fixed << std::setprecision(3) << 2*M_PI*R << endl;
    return 0;
}


Measured memory_bytes: 3756
x = input().split(' ')
y = 0
i = 0
ans = []
while y < int(x[0]) and y < int(x[1]):
    y += 1
    if int(x[0]) % y == 0 and int(x[1]) % y == 0:
        ans.append(y)
        i += 1
print(ans[len(ans) - int(x[2])])


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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define mp make_pair
#define ll long long
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 100010
#define inf 1e9

int main()
{

    ll n;
    vector<ll> p,q,v;
    cin >> n;
    for(ll i=0;i<n;i++)
    {

        ll x;
        cin >> x;
        p.pb(x);
    }
    for(ll i=0;i<n;i++)
    {

        ll y;
        cin>>y;
        q.pb(y);
    }
    for(ll i = 1; i<=n; i++) v.pb(i);
    ll s =0, a, b;
    do
    {

        bool tf=1;
        for(ll i = 0; i < v.size(); i++)
        {

            if(v[i]!=p[i]) tf=0;
        }
        if(tf) a=s;
        tf=1;
        for(ll i = 0; i < v.size(); i++)
        {

            if(v[i]!=q[i]) tf=0;
        }
        if(tf) b=s;
        s++;
    }while(next_permutation(v.begin(), v.end()));
    cout << abs(a-b);
}


Measured memory_bytes: 256
// AOJ 3030 Light
// 2018.4.14 bal4u
 
#include <stdio.h>
//#include <stdlib.h>
#include <string.h>
 
#define QMAX 100000
typedef struct { int t, s, c; } QUE;
QUE que[QMAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
	int l, r, min;
	QUE qt;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].t < que[i].t) min = l; else min = i;
	if (r < qsize && que[r].t < que[min].t) min = r;
	if (min != i) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		min_heapify(min);
	}
}

void deq()
{
	que[0] = que[--qsize];
	min_heapify(0);
}

void enq(int s, int t, int c)
{
	int i, min;
	QUE qt;

	i = qsize++;
	que[i].s = s, que[i].t = t, que[i].c = c;
	while (i > 0 && que[min = PARENT(i)].t > que[i].t) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		i = min;
	}
}

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

#define INF 0x10101010
#define ABS(a)   ((a)>=0?(a):-(a))
int x[102], y[102];
int dist[102][1002];

int dijkstra(int n)
{
	int s, e, t, nt, c;

	memset(dist, INF, sizeof(dist));
	qsize = 0;
	for (s = 0; s < n; s++) c = x[s]+y[s], enq(s, c, c), dist[s][c] = c;
	while (qsize) {
		s = que[0].s, t = que[0].t, c = que[0].c, deq();
//printf("s %d, t %d, c %d, N %d, qsize %d\n", s, t, c, n, qsize);
		if (s == n) break; 
		if (dist[s][c] < t) continue;
		for (e = 0; e < n; e++) if (e != s) {
			nt = ABS(x[e]-x[s])+ABS(y[e]-y[s])-c-1;
			if (nt < 0) nt = 0;
			if (dist[e][nt] > t+nt) dist[e][nt] = t+nt, enq(e, t+nt, nt);
		}
		nt = ABS(x[n]-x[s])+ABS(y[n]-y[s])-c;
		if (nt < 0) nt = 0;
		if (dist[n][nt] > t+nt) dist[n][nt] = t+nt, enq(n, t+nt, nt);
	}
	return t;
}

int main()
{
	int W, H, N, i;

	W = in(), H = in(), N = in();
	for (i = 0; i < N; i++) x[i] = in()-1, y[i] = in()-1;
	x[N] = W-1, y[N] = H-1;
	printf("%d\n", dijkstra(N));
	return 0;
}


Measured memory_bytes: 2852
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

char s[10];
int main() {
  scanf("%s", s);
  if (s[0] >= 'a' && s[0] <= 'z') {
    puts("a");
  } else {
    puts("A");
  }
  return 0;
}


Measured memory_bytes: 3160
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

from  collections import defaultdict
from collections import Counter
def main():
    ABC = LI()
    c = Counter(ABC)
    ans = len(c.values())

    if ans == 2:
        print('Yes')
    else:
        print('No')

if __name__ == "__main__":
    main()


Measured memory_bytes: 74396
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const int MAX_N = 100000;
ll fact[MAX_N + 1];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll ans;
    fact[0] = 0;
    fact[1] = 1;
    ll fs = 1;
    for (int i = 2; i < MAX_N + 1; i++){
        fs = (fs*i) % MOD;
        fact[i] = (fact[i-1] + fs) % MOD;
    }
    while (1){
        int N, R;
        cin >> N;
        if (N == 0) break;
        vector<int> word(N);
        for (int i = 0; i < N; i++) word[i] = i;
        word.push_back(0);
        ans = 0;
        cin >> R;
        vector<int> s(2*R+2, 0);
        s[2 * R + 1] = N;
        for (int i = 0; i < R; i++){
            cin >> s[i] >> s[i+R];
            s[i]--; s[i+R]--;
            s.push_back(s[i] + 1);
            s.push_back(s[i+R] + 1);
            swap(word[s[i]], word[s[i+R]]);
        }
        sort(s.begin(), s.end());
        s.erase(unique(s.begin(), s.end()), s.end());
        for (int i = 0, R = s.size() - 1; i < R; i++){
            ans =(ans + word[s[i]] * (fact[N - s[i] - 1] - fact[N - s[i+1] - 1] + MOD)) % MOD;
            for (int j = i + 1, dif = s[i+1] - s[i]; j < R; j++){
                word[s[j]] -= (word[s[j]] > word[s[i]] ? dif : 0);
            }
        }
        cout << ans % MOD << endl;
    }
    return 0;
}

Measured memory_bytes: 2796
#include<bits/stdc++.h>
#define rep(i,l,r) for (int i=l;i<=r;i++)
using namespace std;
const int maxn=20050;
/*int tot,last,k;
int go[maxn][30],fa[maxn],len[maxn],f[maxn],cc[maxn];
string ans;
char s[maxn];
void add(int c){
    int p,np,q,nq; 
    p=last; last=np=++tot; 
    for (;p&&!go[p][c];p=fa[p]) go[p][c]=np;
    if (!p) fa[np]=1;
    else {
        q=go[p][c]; 
        if (len[q]==len[p]+1) {
            fa[np]=q; return;
        }
        else {
            nq=++tot;
            len[nq]=len[p]+1; 
            memcpy(go[nq],go[q],sizeof(go[q]));
            fa[nq]=fa[q]; fa[q]=fa[np]=nq;
            for (;p&&go[p][c]==q;p=fa[p]) go[p][c]=nq;
        }
    }
    cc[last]=1;
}
void dfs(int u){
	f[u]=cc[u];
	rep(i,0,25) if (go[u][i]) dfs(go[u][i]),f[u]+=f[go[u][i]];
}
void bfs(int u,int k){
	rep(i,0,25) {
		if (go[u][i]&&f[go[u][i]]>=k){
			ans+='a'+i;
			bfs(go[u][i],k-cc[u]);
			return;
		}
		else k-=f[go[u][i]];
	}
}*/
priority_queue<string> q;
char s[10500];
int k;
map<string,int> mp;
int main(){
	/*scanf("%s",s+1);
	scanf("%d",&k);
	last=tot=1;
	int L=strlen(s+1);
	rep(i,1,L) add(s[i]-'a');
	//puts("ni");
	dfs(1);
//	puts("this");
	bfs(1,k);
	rep(i,1,tot) printf("%d %d\n",f[i],cc[i]);
	cout<<ans<<endl;*/
	string ss;
	scanf("%s",s+1);
	scanf("%d",&k);
	int n=strlen(s+1);
	rep(i,1,n) rep(j,1,k) if (i+j-1<=n) {
		ss="";
		rep(l,0,j-1) ss+=s[i+l];
		if (mp.count(ss)) continue;
		mp[ss]=1;
		q.push(ss);
		if (q.size()>k) q.pop(); 
	}
	cout<<q.top()<<endl;
	return 0;
}

Measured memory_bytes: 1920
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>

using namespace std;

typedef long long ll;

string S;
int main() {
	cin >> S;
	for (char c = 'a'; c <= 'z'; c++) {
		bool ok = true;
		for (int i = 0; i < S.size(); i++) {
			if (c == S[i]) {
				ok = false;
				break;
			}
		}
		if (ok) {
			S += c;
			cout << S << endl;
			return 0;
		}
	}
	string T = S;
	if (!next_permutation(T.begin(), T.end())) {
		cout << -1 << endl;
	} else {
		for (int i = 0; i < T.size(); i++) {
			if (T[i] != S[i]) {
				cout << T.substr(0, i + 1) << endl;
				break;
			}
		}
	}
	return 0;
}


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

# define Rep(i,a,b) for(int i=a;i<=b;i++)
# define _Rep(i,a,b) for(int i=a;i>=b;i--)
# define RepG(i,u) for(int i=head[u];~i;i=e[i].next)

typedef long long ll;

const int N=2e5+5;

template<typename T> void read(T &x){
   x=0;int f=1;
   char c=getchar();
   for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
   for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+c-'0';
    x*=f;
}

# define int long long

int n,d;
int ans;

signed main()
{
    read(n),read(d);
    d=d*d;
    Rep(i,1,n){
        int x,y;
        read(x),read(y);
        if(x*x+y*y<=d)ans++;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 3696
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define FOR(i,n) for(int i=0;i<n;i++)
#define all(s) s.begin(),s.end()
#define lla(s) s.rbegin(),s.rend()
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const ll INF = 1e18;

int h,w;
int a[550][550];
bool in(int x,int y){
    return (0<=x&&x<h&&0<=y&&y<w);
}
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin>>h>>w;
    rep(i,0,h){
        rep(j,0,w){
            cin>>a[i][j];
        }
    }
    vector<pair<P,P>>ans;
    int x = 0,y = 0,dir = 1,cellcount = 0;
    while(cellcount<h*w){
        if(!in(x,y)){break;}
        int nx,ny;
        if((y==0&&dir==-1)||(y==w-1&&dir==1)){nx = x+1;ny = y;dir*=-1;}
        else{nx = x; ny = y + dir;}
        if(a[x][y]%2==1&&in(nx,ny)){
            ans.push_back({{x+1,y+1},{nx+1,ny+1}});
            a[nx][ny]++;
        }
        x = nx; y = ny;
        cellcount++;
    }
    cout<<(int)ans.size()<<"\n";
    rep(i,0,(int)ans.size()){
        cout<<ans[i].first.first<<' '<<ans[i].first.second<<' '<<ans[i].second.first<<' '<<ans[i].second.second<<"\n";
    }
}

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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

namespace std{
    template<>
    class hash<deque<int> >{
        public:
        size_t operator () ( const deque<int> &p ) const{ 
            size_t res = 0;
            for (int x : p) {
                res = res * 11 + x;
            }
            return res;
        }
    };
}

ll modpow(ll x, ll n, ll mod = MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

int check(const deque<int>& d, int x, int y, int z) {
    int v[] = {x, y, z};
    int cur = 0;
    int sum = 0;
    for (int val : d) {
        if (cur == 3) return 2;
        sum += val;
        if (sum > v[cur]) {
            return -1;
        }
        if (sum == v[cur]) {
            cur++;
            sum = 0;
        }
    }
    return (cur == 3);
}

void prune(deque<int>& tar, int lim, int& sum) {
    while (sum > lim) {
        int hoge = tar.front();
        tar.pop_front();
        sum -= hoge;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, x, y, z;
    cin >> n >> x >> y >> z;
    unordered_map<deque<int>, ll> dp;
    deque<int> empty;
    dp[empty] = 1;
    ll ans = 0;
    int lim = x + y + z;
    int maxv = max({x, y, z});
    vector<ll> mod10s(n + 1, 1);
    for (int i = 1; i <= n; i++) mod10s[i] = mod10s[i - 1] * 10 % MOD;
    for (int i = 0; i <= n; i++) {
        unordered_map<deque<int>, ll> ndp;
        //cerr << dp.size() << endl;
        ll foobar = 0;
        for (auto& p : dp) {
            deque<int> tar = p.first;
            if (check(tar, x, y, z) > 0) {
                (ans += p.second * mod10s[n - i] % MOD) %= MOD;
                continue;
            }
            if (i == n) continue;

            (foobar += p.second * (10 - maxv)) %= MOD;
            for (int j = 1; j <= maxv; j++) {
                tar.push_back(j);
                while (!tar.empty() && check(tar, x, y, z) < 0) {
                    tar.pop_front();
                }
                (ndp[tar] += p.second) %= MOD;
                if (!tar.empty()) {
                    tar.pop_back();
                }
            }
        }
        (ndp[empty] += foobar) %= MOD;
        if (i < n) dp = move(ndp);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 48712
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define mk make_pair
#define f first
#define s second 
using namespace std;
#define int long long
vector<int>v;
set<int>se;
map<int,int>m;
int ans=-1,n;
void dfs(int d,int s){
	if(d==18)return;
	if(d)v.push_back(s);
	dfs(d+1,s*10+2);
	dfs(d+1,s*10+8);
}
main(){
	cin>>n;
	m[1]=-1;
	dfs(0,0);
	sort(v.begin(),v.end());
	queue<pair<int,int> >q;
	q.push(mk(n,0));
	while(!q.empty()){
		pair<int,int>p=q.front();q.pop();
		r(i,v.size()){
			if(p.f<v[i])break;
			if(p.f%v[i]==0&&(!m[p.f/v[i]]||m[p.f/v[i]]<p.s+1)){
			  m[p.f/v[i]]=p.s+1;
			  q.push(mk(p.f/v[i],p.s+1));
		   }
		}
	}
	cout<<m[1]<<endl;
}

Measured memory_bytes: 4964
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int N;
long long X;
long long a[51],b[51];

long long f(int N,long long X){
	if(N == 0)return 1;
	else if(X == 1 ) return 0;
	else if(X == b[N])return a[N];

	else if(X <= 1+b[N-1])return f(N-1,X-1);

	else if(X == 2+b[N-1])return 1+f(N-1,X-2);
	
	else return 1+a[N-1]+f(N-1,X-2-b[N-1]);

}
int main(){
	cin >> N >> X;
	a[0]=1;
	b[0]=1;
	for(int i=1;i<51;i++)a[i]=1+2*a[i-1];
	for(int i=1;i<51;i++)b[i]=3+2*b[i-1];

	cout << f(N,X) << endl;
	return 0;
}

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

signed main(){
	ll N;
	cin>>N;
	ll h[N];
	ll DP[N];
	rep(i,N) cin>>h[i];
	DP[0]=0;
	DP[1]=abs(h[1]-h[0]);
	repx(2,i,N){
		DP[i]=min(DP[i-1]+abs(h[i]-h[i-1]),DP[i-2]+abs(h[i]-h[i-2]));
	}
	cout<<DP[N-1]<<endl;
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char a[111];
int main()
{
	cin>>a;
	for(int i=0;i<strlen(a);i++)
		if(a[i]=='C')
			for(int j=i+1;j<strlen(a);j++)
				if(a[j]=='F')
				{
					cout<<"Yes";
					return 0;
				}
				
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    int m;
    if(a>b)
        m=a;
    else
        m=b;
    if(c>m)
        m=c;
    printf("%d\n",a+b+c-m);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
std::array<int,32>ar{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
};
cout <<ar[n-1]<<endl;}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define sd(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define pd(n) printf("%d",n)
#define pl(n) printf("%lld",n)
#define sf(n) scanf("%f",&n)
#define pf(n) printf("%.12f",n)
#define psp printf(" ")
#define endc printf("\n")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pii;

const ll maxn = 204;
//const ll md = 1e9 + 7;
const ll inf = 2e9 + 7;

ll a[maxn][maxn];
int b[maxn];
ll r[maxn];
int R;

ll calc() {
	ll z = 0;
	for (ll i = 1; i < R; i++) z += a[r[b[i]]][r[b[i+1]]];
	return z;
}

int main() {
	int n,m; sd(n); sd(m); sd(R);
	for (ll i = 1; i <= R; i++) { sl(r[i]); b[i] = i; }
	for (ll i = 1; i <= n; i++) {
		for (ll j = 1; j <= n; j++) {
			a[i][j] = inf;
		}
		a[i][i] = 0;
	}
	for (ll i = 1; i <=m ;i++) {
		int x,y; ll c; sd(x); sd(y); sl(c);
		a[x][y] = a[y][x] = c;
	}
	for (ll k = 1; k <= n; k++) {
		for (ll i = 1; i <= n; i++) {
			for (ll j = 1; j <= n; j++) {
				if (a[i][k] + a[k][j] < a[i][j]) {
					a[i][j] = a[i][k] + a[k][j];
				}
			}
		}
	}
	ll ans = inf;
	ans = min(ans, calc());
	while (next_permutation(b+1,b+R+1))  ans = min(ans, calc());
	pl(ans); endc;
}

Measured memory_bytes: 512
#include <iostream>

#include <queue>
#include <string>
#include <tuple>

#include <cstring>

using std::cin;
using std::cout;
using std::endl;

using std::get;
using std::make_tuple;
using std::queue;
using std::string;
using std::tuple;

using std::memcpy;

using i3 = tuple<int, int, int>;

static int
distance(int H, int W, char mat[50][50])
{
  static int const dydx[][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
  char v[50][50];
  memcpy(v, mat, sizeof(v));
  queue<i3> q;
  q.push(make_tuple(0, 0, 0));
  while (!q.empty())
  {
    int y = get<0>(q.front());
    int x = get<1>(q.front());
    int d = get<2>(q.front());
    q.pop();
    if (y == H - 1 && x == W - 1)
    {
      return d;
    }
    for (int i = 0; i < 4; i++)
    {
      int yy = y + dydx[i][0];
      int xx = x + dydx[i][1];
      if (0 <= yy && yy < H && 0 <= xx && xx < W && v[yy][xx] != '#')
      {
        v[yy][xx] = '#';
        q.push(make_tuple(yy, xx, d + 1));
      }
    }
  }
  return -1;
}

static int
count_white(int H, int W, char mat[50][50])
{
  int ret = 0;
  for (int y = 0; y < H; y++)
  {
    for (int x = 0; x < W; x++)
    {
      if (mat[y][x] == '.')
      {
        ret++;
      }
    }
  }
  if (mat[0][0] == '.')
  {
    ret--;
  }
  if (mat[H - 1][W - 1] == '.')
  {
    ret--;
  }
  return ret;
}

static int
solve(int H, int W, char mat[50][50])
{
  int white = count_white(H, W, mat);
  int d = distance(H, W, mat);
  return d == -1 ? -1 : white - (d - 1);
}

int
main()
{
  int H, W;
  cin >> H >> W;
  char mat[50][50];
  string s;
  for (int y = 0; y < H; y++)
  {
    cin >> s;
    memcpy(mat[y], s.data(), s.size());
  }
  cout << solve(H, W, mat) << endl;
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES // for C++  
#include "bits/stdc++.h"
#define LL long long
#define NUM 1000000007

using namespace std;

int main()
{
    int n;
    cin >> n;
    if (n==9||n==19||n==29||n==39||n==49||n==59||n==69||n==79||n==89||n==99||n==90 || n == 91 || n == 92 || n == 93 || n == 94 || n == 95 || n == 96 || n == 97 || n == 98)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <algorithm>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define rep(i,n)	for(int i=0;i<n;i++)
#define srep(i,a,n)	for(int i=a;i<n;i++)
#define REP(i,n)	for(int i=0;i<=n;i++)
#define SREP(i,a,n)	for(int i=a;i<=n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define fst	first
#define scn second

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;
const ld eps = 1e-9;

int main() {
	int h = 0, w = 0;	cin >> h >> w;
	vector<vint> a(h, vint(w, 0));
	rep(i, h)	rep(j, w)	cin >> a[i][j];
	vint depth(w, 0);
	rep(i, w)	depth[i] = a[0][i]^1;
	int ret = 0;
	int tmp = 0;
	rep(i, w) {
		if (a[0][i] == 0)	tmp++;
		else {
			ret = max(ret, tmp);
			tmp = 0;
		}
	}
	ret = max(ret, tmp);
	srep(i, 1, h) {
		//depth?????´??°
		rep(j, w) {
			if (a[i][j] == 0)	depth[j]++;
			else	depth[j] = 0;
		}
		//????????????(??????????????£??????????????????)??§?????§?????¢???????????????
		stack<pii> s;
		s.push(mp(0, 0));
		rep(j, w) {
			int to = j;
			while (!s.empty()&&s.top().fst >= depth[j]) {
				ret = max(ret, (j - s.top().scn)*s.top().fst);
				to = s.top().scn;
				s.pop();
			}
			s.push(mp(depth[j], to));
		}
		while (!s.empty()) {
			ret = max(ret, (w - s.top().scn)*s.top().fst);
			s.pop();
		}
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 10428
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define f(i,a,b) for(i=a;i<b;i++)
#define fr(i,a,b) for(i=a;i>=b;i--)
#define endl '\n'
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mod 1000000007
using namespace std;

int n,i,j;
double p[3000],ans;
double dp[3000][3005];

int main()
{
    cin>>n;
    f(i,0,n)
    	cin>>p[i];
    memset(dp,0,sizeof dp);
    dp[0][0]=1-p[0];
    dp[0][1]=p[0];
    f(i,1,n)
    {
    	f(j,0,i+2)
    	{
    		dp[i][j]+=(1-p[i])*dp[i-1][j];
    		dp[i][j+1]+=p[i]*dp[i-1][j]; 		
    	}
    }
    /*f(i,0,n)
    {
    	f(j,0,i+2)
    		cout<<dp[i][j]<<' ';
    	cout<<endl;
    }*/
    f(i,n/2+1,3005)
    	ans+=dp[n-1][i];
    printf("%.10lf",ans);
  //cout<<ans;
}

Measured memory_bytes: 70656