akhauriyash/Code-Regression huggingface dataset:
/**
*   @Author : MeGaCrazy
*   @InitTime : Fri Jan 04 16:39:37 2019
*   @Idea :
*
*
*
*
*
*  Happy Solving :)
**/
#include <bits/stdc++.h>
using namespace std;
int main(){
#ifndef ONLINE_JUDGE
   //freopen("in","r",stdin);
   //freopen("out","w",stdout);
#endif
    long long h,w;
    cin>>h>>w;
    // case 1
    long long ans=1e9;
    if(h%3==0|| w%3==0){
    	cout<<0<<endl;
    	return 0;
    }else{
      // split horiaztional
      ans=(h/3 +1)*w - (h/3)*w;

      // split vertical
      ans=min(ans,(w/3 +1)*h - (w/3)*h);
    }

    cerr<<ans<<endl;
    // case 3
    for(long long i=1;i<h;i++){
     	if(w%2==0){
     	 ans=min(ans,abs(i*w - (h-i)*(w/2)));
     	}else{
     	 long long a1=abs(i*w - (h-i)*(w/2));
     	 long long a2=abs(i*w - (h-i)*(w/2 +1 ));
     	 long long a3=abs((h-i)*(w/2 +1 ) - (h-i)*(w/2 ));
     	 ans=min(ans,max(a1,max(a2,a3)));
     	}
    }

    // case 4
   for(long long i=1;i<w;i++){
     	if(h%2==0){
     	 ans=min(ans,abs(i*h - (w-i)*(h/2)));
     	}else{
     	 long long a1=abs(i*h - (w-i)*(h/2));
     	 long long a2=abs(i*h - (w-i)*(h/2 +1 ));
     	 long long a3=abs((w-i)*(h/2 +1 ) - (w-i)*(h/2 ));
     	 ans=min(ans,max(a1,max(a2,a3)));
     	}
    }
    cout<<ans<<endl;


}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <cstring>
#include <algorithm>
using namespace std;

struct NODE{
	int x , y  , turn , cost;
	NODE(int x,int y,int turn,int cost) : x(x) , y(y) , turn(turn) , cost(cost) {}
};
bool operator < (const NODE &a,const NODE &b){
	return a.cost > b.cost;
}
bool memo[61][31][2];
int d[61][31];
int main(){
	int w,h;
	while(cin >> w >> h && w){
		priority_queue<NODE> Q;
		int goal[100][100]={0};
		for(int i = 0 ; i < h ; i++)
			for(int j = 0 ; j < w ; j++){
				char c;
				cin >> c;
				if(c == 'S'){
					d[i][j] = 0;
					Q.push(NODE(j,i,0,0));
					Q.push(NODE(j,i,1,0));
				}else if( c == 'T'){
					d[i][j] = 0;
					goal[i][j] = 1;
				}else if( c == 'X'){
					d[i][j] = -1;
				}else{
					d[i][j] = c - '0';
				}
			}
		memset(memo,0,sizeof(memo));
		while(Q.size()){
			NODE q = Q.top(); Q.pop();
			if(goal[q.y][q.x]){
				cout << q.cost << endl;
				goto exit;
			}
			if(memo[q.y][q.x][q.turn]) continue;
			else memo[q.y][q.x][q.turn] = true;
			
			for(int X = q.turn?1:-3 ; X <= (q.turn?3:-1) ; X++){
				for(int Y = -2 ; Y <= 2 ; Y++){
					if(abs(X)+abs(Y) <= 3){
						int tx = q.x + X , ty = q.y + Y;
						if(ty < 0 || tx < 0 || ty >= h || tx >= w || d[ty][tx] == -1) continue;
						Q.push(NODE(tx,ty,q.turn^1,q.cost+d[ty][tx]));
					}
				}
			}
		}
		cout << -1 << endl;
		exit:;
	}
}

Measured memory_bytes: 1060
import java.util.Scanner;

//Pi is Three
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			double R = sc.nextDouble();
			if(R==0)break;
			int n = 1, d = 1;
			double min = 1<<29;
			int an = 0, ad = 1<<29;
			while(d<=ad){
				double r = Math.PI-n*1.0/d;
				double e = Math.abs(r);
				if(e<R+1e-10&&e<min){
					min = e; an = n; ad = d;
				}
				if(r<0)d++;
				else n++;
			}
			System.out.println(an+"/"+ad);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

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

long long gcd(long long a, long long b){
	if(!(a % b))
		return b;
	return gcd(b, a % b);	
}

int main(){
	long long int a, b;
	if(a < b)
		swap(a, b);
 	cin >> a >> b;
  	cout << a * b / gcd(a, b); 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define nl '\n' 
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define pii pair <int,int>
ll mod=1000000007;
void factor(int n,map<int,int>&m)
{
	while(n%2==0)
	{
		n/=2;
		m[2]++;
	}
	for(int i=3;i<=sqrt(n);i+=2)
	{
		while(n%i==0)
		{
			n/=i;
			m[i]++;
		}
	}
	if(n>2){
		m[n]++;
	}
}
int main()
{
	int n;cin>>n;
	int count=0;
	for(int i=1;i<n;i++)
	{
		map<int,int>m;
		factor(i,m);
		ll ans=1;
		for(auto i:m)
		{
			ans=ans*(i.second+1);
		}
		count+=ans;
	}
	cout<<count;
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int n=s.size();
  int k=n/2;
  int x=0;
  for(int i=0;i<k;i++){
    if(s.at(i)!=s.at(n-1-i)) x++;
  }
  cout<<x<<endl;
}
      
 

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <string.h>
 
using namespace std;
typedef long long ll;

int main()
{
	int A, B, C;
	scanf("%d %d %d", &A, &B, &C);
	
	if((A == B && A != C) || (B == C && C != A) || (C == A && B != C)){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	
	return 0;
}

Measured memory_bytes: 128
/*
*	User: Isanchez_Aguilar
*	Problem: AtCoder ABC134B - Golden Apple
*/
#include <bits/stdc++.h>

using namespace std;

int main(void)
{
	int a, b;
	cin >> a >> b;
	
	cout << (a + b) % 24;

	return 0;
}


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

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

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

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

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

class Edge{
  public:
    int v, w, c;
    Edge(int v, int w, int c): v(v), w(w), c(c){}
};

vector< vector< Edge > > graph_a;
vector< vector< Edge > > graph_b;

void dijkstra(vector< vector< Edge > >& graph, int s, 
    vector< ll >& dist){
  fill(dist.begin(), dist.end(), INF_LONG);
  priority_queue< pli, vector< pli >, greater< pli >> pq;
  pq.push(make_pair(0, s));
  dist[s] = 0;
  while(!pq.empty()){
    pli p = pq.top(); pq.pop();
    int v = p.second;
    ll d = p.first;
    if(d > dist[v]) continue;
    for(Edge e: graph[v]){
      int w = e.w;
      if(d + e.c < dist[w]){
        dist[w] = d + e.c;
        pq.push(make_pair(d + e.c, w));
      }
    }
  }
}

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

  int n, m, s, t;
  cin >> n >> m >> s >> t;
  --s; --t;
  int u[m], v[m], a[m], b[m];
  for(int i = 0; i < m; i++){
    cin >> u[i] >> v[i] >> a[i] >> b[i];
    --u[i]; --v[i];
  }

  graph_a.resize(n);
  graph_b.resize(n);
  for(int i = 0; i < m; i++){
    graph_a[u[i]].push_back(Edge(u[i], v[i], a[i]));
    graph_a[v[i]].push_back(Edge(v[i], u[i], a[i]));
    graph_b[u[i]].push_back(Edge(u[i], v[i], b[i]));
    graph_b[v[i]].push_back(Edge(v[i], u[i], b[i]));
  }

  vector< ll > dist_a(n), dist_b(n);
  dijkstra(graph_a, s, dist_a);
  dijkstra(graph_b, t, dist_b);

  ll ans[n + 1];
  ans[n] = INF_LONG;
  for(int i = n - 1; i >= 0; i--){
    ans[i] = min(ans[i + 1], dist_a[i] + dist_b[i]);
  }

  string buf;
  for(int i = 0; i < n; i++){
    buf += to_string(1000000000000000l - ans[i]) + "\n";
  }

  cout << buf;

  return 0;
}


Measured memory_bytes: 21752
#include <iostream>
#include <math.h>

int main(void)
{
	int n, d, x;
  	std::cin >> n >> d >> x;
    int eat = 0;
    for (int i = 0; i < n; ++i)
    {
        int a;
        std::cin >> a;
        eat += ceilf(d / float(a));
    }
    std::cout << (x + eat);
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;

struct Node{
    int id,x,y;
}node[100000+10];
struct E{
    int v1,v2,w;
}e[2*100000+20];
int Fa[100000+10];
int cmpx(Node n1,Node n2){
    return n1.x < n2.x;
}
int cmpy(Node n1,Node n2){
    return n1.y < n2.y;
}
int cmp(E e1,E e2){
    return e1.w < e2.w;
}
int fi(int x) {
    if(Fa[x] == x)
        return x;
    return Fa[x] = fi(Fa[x]);
}
int main(){
    int n;
    scanf("%d",&n);
    for(int i = 1;i <= n;++i) {
        node[i].id = i;
        scanf("%d%d",&node[i].x,&node[i].y);
    }
    sort(node+1,node+1+n,cmpx);
    int tp = 0;
    for(int i = 2;i <= n;++i) {
        e[tp].v1 = node[i].id;
        e[tp].v2 = node[i-1].id;
        e[tp].w = node[i].x - node[i-1].x;
        tp ++;
    }
    sort(node+1,node+1+n,cmpy);
    for(int i = 2;i <= n;++i) {
        e[tp].v1 = node[i].id;
        e[tp].v2 = node[i-1].id;
        e[tp].w = node[i].y - node[i-1].y;
        tp ++;
    }
    sort(e,e+tp,cmp);
    ll ans = 0;
    for(int i = 1;i <= n;++i)
        Fa[i] = i;
    for(int i = 0;i < tp;++i){
        int v1 = e[i].v1;
        int v2 = e[i].v2;
        int t1 = fi(v1);
        int t2 = fi(v2);
        if(t1 != t2){
            //printf("# %d\n",e[i].w);
            ans += e[i].w;
            Fa[t1] = t2;
        }
    }
    /*for(int i = 0;i < tp;++i){
        printf("%d %d %d\n",e[i].v1,e[i].v2,e[i].w);
    }*/
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 4224
def solve(S):
    L = S[:2]
    R = S[2:]

    if 1 <= int(L) <= 12 and 1 <= int(R) <= 12:
        return "AMBIGUOUS"
    if 1 <= int(L) <= 12:
        return "MMYY"
    if 1 <= int(R) <= 12:
        return "YYMM"
    return "NA"


if __name__ == "__main__":
    S = input()
    print(solve(S))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll N,ans=0;
  cin>>N;
  vector<ll> h(N);
  for(ll i=0;i<N;i++){
    cin>>h.at(i);
    if(i==0){ans=h.at(i);}
    else if(h.at(i)>h.at(i-1)){ans+=h.at(i)-h.at(i-1);}
  }
  cout<<ans<<endl;
}

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

int main()
{
  int n,m;
  for(;cin>>n>>m,n||m;)
    {
      int data[m+n];
      for(int i=0;i<m+n;i++)
	cin>>data[i];
      sort(data,data+n+m);
      int ans=0;
      int now=0;
      for(int i=0;i<m+n;i++)
	{
	  ans=max(ans,data[i]-now);
	  now=data[i];
	}
      cout<<ans<<endl;
    }


}

Measured memory_bytes: 1256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll k;
    cin>>k;
    ll c=0;
    for(ll i=1;i<=k;i++)
    {
        c=(c*10+7)%k;
        if(c%k==0)
        {
            cout<<i<<"\n";
            return 0;
        }
    }
      cout<<-1<<"\n";
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,i,j,l=1;
  cin>>a>>b;
  j=a;
  if(b==1)
    l=0;
  else
  {
      while(j<b)
      {
           l++;
        j=j+a-1;
      }
  }
  cout<<l;
}

Measured memory_bytes: 256
import fractions

N = int(input())
A_list = list(map(int, input().split()))

mod = 10**9+7

R = 1 # 最小公倍数
# 最小公倍数を求める
for A in A_list:
    R *= A // fractions.gcd(R, A)

# Bの合計を求める
ans = 0
for A in A_list:
    ans = ans + R // A # 計算は小数として出してはダメだから//を使う

ans %= mod

print(ans)


Measured memory_bytes: 6200
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b) - 1; i >= (a); --i)
#define de(x) cout << #x << " = " << x << endl
#define dd(x) cout << #x << " = " << x << " "
#define pw(x) (1ll<<(x))
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef double db;
typedef vector<int> vi;

int main() {
	std::ios::sync_with_stdio(0);
	std::cin.tie(0);
	ll n, x; cin >> n >> x;
	ll ans = n;
	ll y = n - x;
	while(1) {
		if(x > y) swap(x, y);
		if(x == 0) break;
		ll t = y / x;
		y %= x;
		ans += t * 2 * x;
	}
	cout << ans - x - y << endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
ll k, n;
//ld ;
//string s;

int main() {
    cin >> k >> n;
    ll minl = k;
    ll a0 = 0;
    ll abef = 0;
    for(ll i=0;i<n;i++){
        ll a;
        cin >> a;
        if(i==0){
            a0 = a;
        }else{
            minl = (minl>k-(a-abef))?k-(a-abef):minl;
        }
        abef = a;
    }
    minl = (minl>abef-a0)?abef-a0:minl;
    cout << minl << endl;
    return 0;
}

Measured memory_bytes: 384
# include<bits/stdc++.h>
using namespace std;
int s,e,n,mid;
map <int,int> mp;
int q(int x)
{
	if(mp.find(x)!=mp.end())  return mp[x];
	printf("%d\n",x);
	fflush(stdout);
	string s;
	cin>>s;
	if(s=="Vacant")  exit(0);
	return  mp[x]=(s=="Male");
}
int main()
{
	cin>>n;
	s=0;e=n-1;
	while(e-s>=2)
	{
		mid=(e+s)/2;
		if((q(mid)^(mid%2))!=(q(s)^(s%2)))
		  e=mid;
		else  s=mid;
	}
	for(int i=s;i<=e;i++)
	  q(i);
	return 0;
} 

Measured memory_bytes: 852
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;


const long long INFLL = 1LL << 60;
const int INFI = 1000000000;


int main(){
    int N,K; cin >> N >> K;
    vector<int> p(N);
    for(int i=0;i<N;i++){cin >> p[i];}
    long long SUM=0;
    for(int i=0;i<K;i++)SUM+=p[i];
    long long  M=SUM;

    for(int i=K;i<N;i++){
        SUM+=(p[i]-p[i-K]);
        if(M<SUM) M = SUM;
    }

    cout << fixed << setprecision(12)<< double((M+K)/2.0) << endl;
}


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

typedef long long ll;

const int Maxn = 200005;

int n, k;
int H[Maxn];
ll res;

int main()
{
    scanf("%d %d", &n, &k);
    if (k >= n) { printf("0\n"); return 0; }
    for (int i = 0; i < n; i++)
        scanf("%d", &H[i]);
    sort(H, H + n);
    for (int i = 0; i < n - k; i++)
        res += H[i];
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define p_b push_back
#define pll pair < ll , ll >
#define lt(v) v[v.size()-1]
#define fori(n) for( int i = 0; i < n; i++)
#define s second
#define f first
using namespace std;
ll M = 1000000007;

int main()
{
    int k,n;
    cin >> n >> k;
    vector < ll > a(n);
    ll ans = 0;
    fori(n)
    {
        cin >> a[i];
    }
    sort(all(a));
    fori(k)
    {
        ans+=a[i];
    }
    cout << ans;
}


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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

const lli e5 = 1 << 20;
const lli mod = 1000000007;

lli n;
lli a[e5];
lli b[e5];
lli ans;

lli powl(lli x,lli r,lli mod = 1000000007){
  lli ret = 1;
  for(;r != 0;r >>= 1){
    if(r&1 != 0) ret *= x,ret %= mod;
    x *= x,x %= mod;
  }
  return ret;
}

lli inverse(lli x,lli mod = 1000000007){
  return powl(x,mod-2,mod);
}

lli factorial(lli n,lli mod = 1000000007){
  static lli dp[100000];
  if(dp[n]) return dp[n];
  if(n == 0) return dp[n] = 1;
  return dp[n] = (n*factorial(n-1))%mod;
}


int main(){
	cin >> n;
	for(lli i = 1;i <= n;i++) cin >> a[i];
	for(lli i = 1;i <= n;i++){
		b[i] = inverse(i);
	}
	for(lli i = 0;i < n;i++){
		b[i+1] += b[i];
		b[i+1] %= mod;
	}
	for(lli i = 1;i <= n;i++){
		lli p = ((b[i]-b[0]+mod)+(b[n-i+1]-b[0]+mod)-b[1]+mod)%mod;
		ans += p*a[i]%mod;
		ans %= mod;
	}
	cout << (ans*factorial(n)%mod) << endl;
}


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

#define mod 1000000007

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

using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;
 
int main(void){
	
	int A, B;
	
	cin >> A >> B;
	
	if(A < 10 && B < 10)
		cout << A * B;
	else
		cout << -1;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Vector;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			Vector<Vector<Integer>> vec = new Vector<>();
			int n = sc.nextInt();
			int q = sc.nextInt();
			int i, j;
			for(i = 0; i < n; i++) {
				vec.add(new Vector<>());
			}
			for(i = 0; i < q; i++) {
				int order_number = sc.nextInt();
				int t = sc.nextInt();
				switch(order_number) {
				case 0 :
					vec.get(t).add(sc.nextInt());
					break;
				case 1 :
					for(j = 0; j < vec.get(t).size(); j++) {
						if(j == vec.get(t).size() - 1) {
							System.out.print(vec.get(t).get(j));
						}else{
						    System.out.print(vec.get(t).get(j) + " ");
						}
					}
					System.out.println();
					break;
				case 2 :
					vec.get(t).clear();
					break;
				}
			}

		}
	}
}



Measured memory_bytes: 312356
#include<bits/stdc++.h>
using namespace std;
const int mod=1000003;
typedef long long ll;
ll f[mod],invf[mod];
ll qpow(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans=ans*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return ans;
}
int main()
{
    f[0]=invf[0]=1;
    for(int i=1;i<mod;i++)
        f[i]=f[i-1]*i%mod,invf[i]=qpow(f[i],mod-2);
    int q;
    scanf("%d",&q);
    while(q--)
    {
        int x,d,n;
        scanf("%d%d%d",&x,&d,&n);
        if(d==0) printf("%lld\n",qpow(x,n));
        else
        {
            ll xx=x*qpow(d,mod-2)%mod;
            if(xx+n-1>=mod) printf("0\n");
            else printf("%lld\n",f[xx+n-1]*invf[xx-1]%mod*qpow(d,n)%mod);
        }
    }
}


Measured memory_bytes: 16512
#pragma gcc optimize("Ofast")

#include "bits/stdc++.h"
using namespace std;
typedef int64_t lld;
typedef pair<int,int> pii;
typedef pair<lld,lld> pll;
typedef pair<int,pll> pip;
typedef pair<pll,int> ppi;
typedef pair<lld,pll> plp;
typedef pair<pll,lld> ppl;
typedef pair<pll,pll> ppp;
template<typename T>
using maxHeap = priority_queue<T,vector<T>,less<T>>;
template<typename T>
using minHeap = priority_queue<T,vector<T>,greater<T>>;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define endl '\n'
#define jizz cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
inline void input(int &_x) {
    _x = 0;
    int _tmp = 1; char _tc = getchar();
    while((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar();
    if(_tc == '-') _tc = getchar(), _tmp = -1;
    while(_tc >= '0' && _tc <= '9') _x = _x*10+(_tc-48), _tc = getchar();
    _x *= _tmp;
}
inline void output(int _x) {
    char _buff[20]; int _f = 0;
    if(_x == 0)putchar('0');
    while(_x > 0)
    {
        _buff[_f++] = _x%10+'0';
        _x /= 10;
    }
    for(_f-=1; _f >= 0; _f--)
        putchar(_buff[_f]);
    putchar('\n');
}
template<typename Iter>
ostream& _out(ostream &s, Iter b, Iter e) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}
template<class T1,class T2>
ostream& operator<<(ostream& out, pair<T1,T2> p) {
    return out << '(' << p.first << ", " << p.second << ')';
}
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) {
     return _out(s,c.begin(),c.end());
 }
#ifdef erd1
    #define pprint(x) cerr<<__PRETTY_FUNCTION__<<":"<<__LINE__<<" - "<<(#x)<<"="<<(x)<<endl
#else
    #define pprint(x)
#endif

// code starts here
bitset<26> b;
vector<int> v;
signed main(){
    string s;
    cin >> s;
    int n = s.size(), c = 0;
    b.reset();
    v.pb(n);
    for(int i = n-1; i >= 0; i--){
        if(!b[s[i]-'a'])c++;
        b[s[i]-'a'] = 1;
        if(c == 26){
            c = 0;
            b.reset();
            v.pb(i);
        }
    }
    string ans;
    bool f = false;
    for(int i = 0; i <= n; i++){
        if(f){if(s[i-1]==ans.back())f = false;}
        else if(i)b[s[i-1]-'a'] = 1;
        if(i == v.back()){
            v.pop_back();
            for(int j = 0; j < 26; j++)if(!b[j]){ans+=j+'a'; break;}
            b.reset();
            f = true;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 644
#include <bits/stdc++.h>
using namespace std;
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; }

const long long INF = 1e18;
int n, m, r;
vector< vector<long long> > dp(220, vector<long long>(220, INF));

int main() {
    cin >> n >> m >> r;
    vector<int> R(r, 0);
    for(int i = 0; i < r; ++i) {
        cin >> R.at(i); R.at(i)--;
    }

    for(int i = 0; i < m; ++i) {
        int aa, bb; long long cc;
        cin >> aa >> bb >> cc;
        aa--; bb--;
        dp[aa][bb] = cc;
        dp[bb][aa] = cc;
    }

    for(int i = 0; i < n; ++i) dp[i][i] = 0;

    for(int k = 0; k < n; ++k) {
        for(int i = 0; i < n; ++i) {
            for(int j = 0; j < n; ++j) {
                chmin(dp[i][j], dp[i][k]+dp[k][j]);
            }
        }
    }

    long long ans = INF;
    sort(R.begin(), R.end());
    do {
        long long sum = 0;
        int pre = R.at(0);
        for(int i = 1; i < r; ++i) {
            // cout << "root " << pre << " " << R.at(i) << endl;
            sum += dp[pre][R.at(i)];
            pre = R.at(i);
        }
        chmin(ans, sum);
    }while(next_permutation(R.begin(), R.end()));

    cout << ans << endl;
}

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

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> a(N);
	vector<int> b(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> b[i];
	}

	int res = 0;
	for (int i = 0; i < N; i++) {
		int tmp = 0;
		for (int j = 0; j <= i; j++) {
			tmp += a[j];
		}
		for (int j = i; j < N; j++) {
			tmp += b[j];
		}

		res = max(res, tmp);
	}

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include<string>
#include<math.h>
#include <functional>
using namespace std;

int main(void) {
	int N;
	int t,bt=0;
	int x, bx = 0;
	int y, by = 0;

	cin >> N;
	for (int i = 0;i < N;i++) {
		cin >> t >> x >> y;
		int len = x - bx + y - by;
		int lim = t - bt;
		if (len > lim || (lim - len) % 2 == 1) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#![allow(non_snake_case,unused_imports,dead_code)]
use std::io::Read;
use std::cmp::max;
use std::cmp::min;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::BinaryHeap;

fn main() {

    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut buf_it = buf.split_whitespace();

    let N = buf_it.next().unwrap().parse::<usize>().unwrap();
    let mut A = (0..N).map(|_| buf_it.next().unwrap().parse::<usize>().unwrap()).collect::<Vec<_>>();

    let mut ans = 0;
    while *A.iter().max().unwrap() >= N{
        for i in 0..N{
            let k = A[i]/N;
            A[i] -= k*N;
            for j in 0..N{
                if j==i{continue;}
                A[j] += k;
            }
            ans += k;
        }
    }
    println!("{}",ans);
}

Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template <class S, class T>
ostream& operator<<(ostream& out, const pair<S, T>& o) {
    out << "(" << o.first << "," << o.second << ")";
    return out;
}
template <class T>
ostream& operator<<(ostream& out, const vector<T>& V) {
    for (int i = 0; i < V.size(); i++) {
        out << V[i];
        if (i != V.size() - 1) out << " ";
    }
    return out;
}
template <class T>
ostream& operator<<(ostream& out, const vector<vector<T> >& Mat) {
    for (int i = 0; i < Mat.size(); i++) {
        if (i != 0) out << endl;
        out << Mat[i];
    }
    return out;
}
template <class S, class T>
ostream& operator<<(ostream& out, const map<S, T>& mp) {
    out << "{ ";
    for (auto it = mp.begin(); it != mp.end(); it++) {
        out << it->first << ":" << it->second;
        if (mp.size() - 1 != distance(mp.begin(), it)) out << ", ";
    }
    out << " }";
    return out;
}
template <typename T>
vector<T> make_v(size_t a) {
    return vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) {
    for (auto& e : t) fill_v(e, v);
}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

/*
 * Σ_{i=0}^{n-1} floor((a*i + b)/m) を計算する
 * 0 <= n <= 1e9
 * 1 <= m <= 1e9
 * 0 <= a,b < m
 * O(log(n+m+a+b))
 */
ll floor_sum(ll n, ll m, ll a, ll b) {
    ll ans = 0;
    if (a >= m) {
        ans += (n - 1) * n * (a / m) / 2;
        a %= m;
    }
    if (b >= m) {
        ans += n * (b / m);
        b %= m;
    }

    ll y_max = (a * n + b) / m, x_max = (y_max * m - b);
    if (y_max == 0) return ans;
    ans += (n - (x_max + a - 1) / a) * y_max;
    ans += floor_sum(y_max, a, m, (a - x_max % a) % a);
    return ans;
}
template <class Type>
Type solve(Type res = Type()) {
    ll n, m, a, b;
    cin >> n >> m >> a >> b;
    return res = floor_sum(n, m, a, b);
}
int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // solve<ll>(0);
    int t;
    cin >> t;
    while (t--) cout << fixed << setprecision(12) << solve<ll>() << endl;
    return 0;
}

Measured memory_bytes: 3640
n, a, b = map(int, input().split())
m = str(n)
l = []
num = 0
for i in range(1, n+1):
        x = str(i)
        s = 0
        for j in range(len(x)):
                s += int(x[j])
        if a <= s and s <= b:
                l.append(i)
print(sum(l))

Measured memory_bytes: 3292
#include<stdio.h>
#include<stdlib.h>
int main() {
  int n,i,a[100],ire,k=0,j;
  
  scanf("%d",&n);
  if(n<1 || 100<n) exit(0);
  
  for(i=0;i<n;i++) {
    scanf("%d",&a[i]);
    if(a[i]<0 || 100<a[i]) exit(0);
  }

  for(i=0;i<n;i++) {
    for(j=n-1;j>=1;j--) {
    if(a[j]<a[j-1]){
      ire=a[j-1];
    a[j-1]=a[j];
    a[j]=ire;
    k++;
    }
    }
  }

  for(i=0;i<n;i++) {
    printf("%d",a[i]);
    if(i!=n-1) printf(" ");
  }
  printf("\n%d\n",k);
  return 0;
}



Measured memory_bytes: 2108
object Main{
  def main(args: Array[String]){
    if (sys.env.getOrElse("TEST", "")=="1"){
      println(test());
    }else{
      val input=io.Source.stdin.getLines().mkString("\n");
      println(solve(input).trim());
    }
  }

  def solve(input:String):String={
    if(input.split(" ").map(_.toInt).product % 2 == 0){"Even"}else{"Odd"}
  }

  val tests=List("""3 9""" -> """12""",
    """31 32""" -> """63""",
    """1 2""" -> """3""",
    """-1 2""" -> """1""",
    """10 1""" -> """11""");

  def test():String= {
    return tests.map{case (i,o)=>(i.trim(),o.trim())}
      .zipWithIndex.map{
      case ((input,outputExpect),i)=>{
        val output=solve(input).trim();
        s"test${i+1}:"+(if(output==outputExpect){
          "Passed"
        }else{
          s"Failed\nexpect:\n${outputExpect}\noutput:\n${output}"
        })
      }}
      .mkString("\n");
  }
}


Measured memory_bytes: 25376
import sys
readline = sys.stdin.readline

N = int(readline().strip())
A = list(map(int, readline().split()))

A.sort(reverse=True)

ans = 0
for i in range(N):
  if i == 0:
    ans += 0
  else:
    j = i//2
    ans += A[j]
print(ans)

Measured memory_bytes: 31608
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(a) (a).begin(), (a).end()
#define sz(a) (int) (a).size()
#define x first
#define y second

vector<int> a;
vector<pair<pair<int, int>, pair<int, int>>> s;
int n, m, q;
int ans = 0;

void gen() {
    if (sz(a) == n) {
        int res = 0;
        for (int i = 0; i < q; i++) {
            if (a[s[i].x.y] - a[s[i].x.x] == s[i].y.x) {
                res += s[i].y.y;
            }
        }
        ans = max(ans, res);
        return;
    } else if (sz(a) == 0) {
        for (int i = 1; i <= m; i++) {
            a.push_back(i);
            gen();
            a.pop_back();
        }
    } else {
        for (int i = a.back(); i <= m; i++) {
            a.push_back(i);
            gen();
            a.pop_back();
        }
    }
}

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

    cin >> n >> m >> q;
    s.resize(q);
    for (int i = 0; i < q; i++) {
        cin >> s[i].x.x >> s[i].x.y >> s[i].y.x >> s[i].y.y;
        s[i].x.x--;
        s[i].x.y--;
    }
    gen();
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 3664
#include <iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  long long a[n];
  long long sum = 0;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    sum+=a[i];
  }
  double Sum = 0;
  if(sum%2!=0)Sum=0.5;
  sum/=2;
  long long  sum2=0;
  long long sum3=0;
  for(int j = 0; j < n; j++){
    sum2+=a[j];
    if(sum2>sum+Sum)break;
    else if(sum2==sum+Sum){
      cout << 0 << endl;
      exit(0);
    }
    sum3=sum2;
  }
  sum=(sum+Sum)*2;
  cout << min(sum2-(sum-sum2), (sum-sum3)-sum3) << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <array>
#include <iostream>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#include <atcoder/math>

using namespace std;
using namespace atcoder;
#define rep(i,l,r) for(int i = l; i < r; ++i)

#define fir first
#define sec second

int main() {
    long long n, b, c, ans;
    pair<long long, long long> r;
    cin >> n;
    n *= 2;
    ans = n;

    for(b = 1; b * b < n; ++b) {
        if (n % b != 0) continue;
        c = n / b;

        r = crt({0, c - 1}, {b, c});
        if (r.fir > 0 && r.fir < ans) ans = r.fir;

        r = crt({0, b - 1}, {c, b});
        if (r.fir > 0 && r.fir < ans) ans = r.fir;
    }
    cout << ans << endl;
}
// k * (k + 1) = 2 * a * N (a >= 1 整数)
// 2N = b * c
// k = xb かつ k + 1 = yc (a = x * y, x > 0, y > 0 整数)
// k = 0 mod b
// k = c-1 mod c
// 
// k = s mod t (crt で求める)
// 全ての(b, c)でkを求めれば良い 
// ただし s > 0 かつ　t > 0

Measured memory_bytes: 3608
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <deque>
#include <numeric>
#include <sstream>
#include <iomanip>
using lint = long long;

int main()
{
    lint n;
    scanf("%lld", &n);

    std::vector<lint> a(n);
    std::vector<lint> b(n);
    std::vector<lint> c(n);

    for (int i = 0; i < n; ++i)
    {
        scanf("%lld", &a[i]);
    }
    for (int i = 0; i < n; ++i)
    {
        scanf("%lld", &b[i]);
    }
    for (int i = 0; i < n; ++i)
    {
        scanf("%lld", &c[i]);
    }

    std::sort(a.begin(), a.end());
    std::sort(b.begin(), b.end());
    std::sort(c.begin(), c.end());

    std::vector<lint> mid_larger(n);

    for (int i = 0; i < n; ++i)
    {
        auto iter = std::lower_bound(a.begin(), a.end(), b[i]);
        lint idx = iter - a.begin();

        mid_larger[i] = std::max(0ll, idx);
    }

    std::vector<lint> cumsum_mid(n);
    std::partial_sum(mid_larger.begin(), mid_larger.end(), cumsum_mid.begin());

    lint ans = 0;

    for (int i = 0; i < n; ++i)
    {
        auto iter = std::lower_bound(b.begin(), b.end(), c[i]);
        lint idx = iter - b.begin();
        if (idx == 0)
            continue;
        ans += cumsum_mid[idx - 1];
    }

    printf("%lld", ans);

    return 0;
}


Measured memory_bytes: 4856
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int i = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define MP make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int MOD = 1e9 + 7;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(N), B(N);
    vector<int> C(M), D(M);
    rep(i, N) { cin >> A[i] >> B[i]; }
    rep(i, M) { cin >> C[i] >> D[i]; }
    rep(i, N) {
        int dist = INF;
        int idx = 0;
        rep(j, M) {
            if(dist > abs(A[i] - C[j]) + abs(B[i] - D[j])) {
                idx = j + 1;
                dist = abs(A[i] - C[j]) + abs(B[i] - D[j]);
            }
        }
        cout << idx << endl;
    }
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  int panda[n];
  
  for(int i=0; i<n; i++){
    cin >> panda[i];
    
  }
  for(int j=n; j>0; j--){
    cout << panda[j-1];
    if(j!=1){
      cout << ' ';
    }
  }
  cout << endl;
}



Measured memory_bytes: 3088
program sample
    implicit none
    character(100)::s,t
    integer(8) :: i,j,m,n
    
  
    read(*,*) n
    read(*,*)s
    read(*,*)t
    
    do i=n,1,-1
        if(s(n+1-i:n) .eq. t(1:i))then
            m=2*n-i
            write(*,*) m
            stop
        end if
    enddo
    write(*,*) 2*n
  
    stop
end program sample
  



Measured memory_bytes: 2748
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
typedef long long ll;
typedef pair<int,int> PA;

const int MAX_N=3e5,MAX_M=1e5;

int N,M;
PA item[MAX_N];

int bit[MAX_M+1];

void add(int i,int x){
	while(i<=M){
		bit[i]+=x;
		i+=i&(-i);
	}
}

int query(int i){
	int res=0;
	while(i){
		res+=bit[i];
		i-=i&(-i);
	}
	return res;
}

int main(){
	scanf("%d %d",&N,&M);
	REP(i,N){
		int L,R;
		scanf("%d %d",&L,&R);
		item[i]=make_pair(L,R);
	}
	sort(item,item+N,[](const PA &a,const PA &b){
		return a.second-a.first<b.second-b.first;
	});
	auto ite=item;
	FOR(d,1,M+1){
		while(ite!=item+N && ite->second-ite->first+1<d){
			add(ite->first,1);
			add(ite->second+1,-1);
			ite++;
		}
		int ans=N-(ite-item);
		for(int x=d;x<=M;x+=d){
			ans+=query(x);
		}
		printf("%d\n",ans);
	}
	return 0;
}


Measured memory_bytes: 3712
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

S = input()

S = list(S)

maru = 0
batu = 0
for i in S:
	if i == "o":
		maru += 1
	else:
		batu += 1
# print(maru, batu)
nokori = 15 - len(S)
if maru + nokori >= 8:
	print("YES")
else:
	print("NO")


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

int main() {
	int n, t;
	int oper, choice, num;
	cin >> n >> t;
	vector<vector<int> > arr(n);
	for(int i = 0; i < t; i++) {
		cin >> oper;
		if(oper == 0) {
			cin >> choice >> num;
			arr[choice].push_back(num);
		}
		else if(oper == 1) {
			cin >> num;
			if(arr[num].size() == 0) cout << endl;
			else {
				for(int j = 0; j < arr[num].size(); j++) {
					if(j != 0) cout << ' ';
					cout << arr[num][j];
				}
				cout << endl;
			}
		}
		else {
			cin >> num;
			arr[num].clear();
		}
	}
	return 0;
}


Measured memory_bytes: 5720
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<cmath>
#include<cstdio>
#include<cassert>

using namespace std;

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aut(r,v) __typeof(v) r = (v)
#define each(it,o) for(aut(it,(o).begin()); it!=(o).end(); ++it)
#define reach(it,o) for(aut(it,(o).rbegin()); it!=(o).rend(); ++it)
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T1, typename T2> ostream& operator<<(ostream& o, const pair<T1, T2>& p)
{return o<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>string join(const vector<T>&v, string del=", ")
{stringstream s;rep(i,v.size())s<<del<<v[i];return s.str().substr(del.size());}
template<typename T>ostream& operator<<(ostream& o, const vector<T>&v)
{if(v.size())o<<"["<<join(v)<<"]";return o;}
template<typename T>ostream& operator<<(ostream& o, const vector<vector<T> >&vv)
{int l=vv.size();if(l){o<<endl;rep(i,l){o<<(i==0?"[ ":",\n  ")<<vv[i]<<(i==l-1?" ]":"");}}return o;}
template<typename T>ostream& operator<<(ostream& o, const set<T>& st)
{vector<T> v(st.begin(),st.end());o<<"{ "<<join(v)<<" }";return o;}
template<typename T1, typename T2>ostream& operator<<(ostream& o, const map<T1, T2>& m)
{each(p,m){o<<(p==m.begin()?"{ ":",\n  ")<<*p<<(p==--m.end()?" }":"");}return o;}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double INF = 0x3f3f3f3f;
const double INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const double mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int N, W;
ll dp[100010];

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    cin >> N >> W;
    rep(j,W+1) dp[j] = 0;
    rep(i,N){
        ll w, v;
        cin >> w >> v;
        rrep(j,W+1){
            if(j - w >= 0)
                dp[j] = max(dp[j], dp[j-w] + v);
        }
    }
    cout << dp[W] << endl;
    return 0;
}

Measured memory_bytes: 1024
/****Author: Barish Namazov****/
#include <bits/stdc++.h>

using namespace std;

/***TEMPLATE***/
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

#define F first
#define S second
#define pb push_back

#define endl '\n'

const int max4 = 10004;
const int maxx = 100005;
const int max6 = 1000006;
const int lg5 = 17;

const int INF = 2 * 1000000007;
const long long INFLL = 4LL * 1000000000 * 1000000000;

/***************/

int powmod (int a, int b, int mod) {
    int res = 1; a %= mod;
    for (; b; b >>= 1) {
        if (b & 1) {
            res = 1LL * res * a % mod;
        }
        a = 1LL * a * a % mod;
    }
    return res;
}
#define ll long long
ll gcd (ll a, ll b) {
    while (b > 0) {
        ll t = a % b;
        a = b, b = t;
    }
    return a;
}

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

int is_prime (int n) {
    if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0))
        return 0;
    for (int i = 5, t = 2; i * i <= n; i += t, t = 6 - t)
        if (n % i == 0)
            return 0;
    return 1;
}

/******Don't forget to use long long when needed!!******/

int main() {
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    ios_base :: sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n, p;
    cin >> n >> p;
    long long res = 1;
    for (int i = 1; i < n; i++) res = 2LL * res;
    int x, e = 0;
    for (int i = 1; i <= n; i++) {
        cin >> x;
        if (x % 2 == 0) e++;
    }
    if (e == n) {
        if (p == 0) res *= 2LL;
        else res = 0;
    }
    cout << res << endl;
    return 0;
}


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

using namespace std;
int main(void){

    string s;
    cin >> s;
    
    int result = 0;
    for(int i=0; i<s.size(); i++) {
        if(s.substr(i,1) == "1") result++;
    }
    
    cout << result << endl;

    return 0;
    
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

int n;
pair<int, int> x[510];
int cnt[510];
vector<int> ans;
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> que;

signed main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> x[i].first;
		x[i].second = i;
		if (1 < i)que.push(make_pair(x[i].first - 1, i));
	}
	sort(x + 1, x + n + 1);
	int k = 1;
	for (int i = 1; i <= n * n; i++) {
		if (i == x[k].first) {
			cnt[x[k].second]++;
			if (cnt[x[k].second] < x[k].second) {
				cout << "No" << endl;
				return 0;
			}
			ans.push_back(x[k].second);
			que.push(make_pair(n*n, x[k].second));
			k++;
		}
		else {
			if (que.empty()) {
				cout << "No" << endl;
				return 0;
			}
			pair<int, int> p = que.top();
			if (p.first < i) {
				cout << "No" << endl;
				return 0;
			}
			cnt[p.second]++;
			ans.push_back(p.second);
			if (cnt[p.second] == p.second - 1 || cnt[p.second] == n)que.pop();
		}
	}
	for (int i = 1; i <= n; i++)if (cnt[i] != n) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	for (int i = 0; i < (int)ans.size(); i++)cout << ans[i] << " ";
	cout << endl;
}


Measured memory_bytes: 4312
N=int(input())
A=list(map(int,input().split()))
mod=10**9+7

FACT=[1]
SUM=[0]
for i in range(1,2*10**5+1):
    FACT.append(FACT[-1]*i%mod)
    SUM.append((SUM[-1]+pow(i,mod-2,mod))%mod)

ANS=0
for i in range(N):
    ANS=(ANS+(SUM[i+1]+SUM[N-i]-1)*A[i])%mod

print(ANS*FACT[N]%mod)

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUG_VEC(v)                               \
  cerr << #v << ": ";                              \
  REP(__i, (v).size()) cerr << ((v)[__i]) << ", "; \
  cerr << endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(), x.end()

#include <iostream>
using namespace std;

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

  while (true) {
    if (a <= 0) {
      cout << "No" << endl;
      return 0;
    }  //高橋のステータスチェック

    c -= b;
    if (c <= 0) {
      cout << "Yes" << endl;
      return 0;
    }

    a -= d;
  }
  return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
using namespace std;
using ll = long long;
vector<int> ad[8];
vector<bool> visited(8,0);
int answer;
void dfs(int i,int n){
    visited[i]=true;
    bool all_visited = true;
    REP(i,n){
        if(!visited[i]){
            all_visited = false;
        }
    }
    if(all_visited){
        answer++;
    }
    for(int v:ad[i]){
        if(visited[v])continue;
        dfs(v,n);
    }
    visited[i]=false;
}
int main(){
    int n,m;
    cin >> n >> m;
    REP(i,m){
        int a,b;
        cin >> a >> b;
        ad[a-1].push_back(b-1);
        ad[b-1].push_back(a-1);
    }
    dfs(0,n);
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var nm = Console.ReadLine().Split(' ');
        var n = int.Parse(nm[0]);
        var m = int.Parse(nm[1]);

        var set = new HashSet<long>();
        for (int i = 0; i < m; i++)
        {
            var ab = Console.ReadLine().Split(' ');
            var a = long.Parse(ab[0]);
            var b = long.Parse(ab[1]);
            set.Add((a << 32) + b);
        }

        for (long i = 2; i < n; i++)
        {
            if (set.Contains((1L << 32) + i) && set.Contains((i << 32) + n))
            {
                Console.WriteLine("POSSIBLE");
                return;
            }
        }

        Console.WriteLine("IMPOSSIBLE");
    }
}


Measured memory_bytes: 30776
a,b=map(int,input().split())
s = list(map(int, input().split()))
t = 0
h = 0
if b ==0:
    print(a)
else:
    for i in range(a,a+2+b):
        if not i in s:
            t = i
            break
    for i in range(a-1,a-2-b,-1):
        if not i in s:
            h = i
            break
    if abs(t-a)>=abs(h-a):
        print (h)
    else:
        print(t)
    


Measured memory_bytes: 9200
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        String s = scan.next();
        char[] s_d = s.toCharArray();
        String t = scan.next();
        char[] t_d = t.toCharArray();
        StringBuilder ans = new StringBuilder();
        for (int i = 0; i < N; i++) {
            ans.append(s_d[i]);
            ans.append(t_d[i]);
        }
        System.out.println(ans.toString());
    }
}


Measured memory_bytes: 22740