akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    int n;
    cin >> n >> s;
    int c0 = 0, c1 = 0;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'R') c0++;
        else c1++;
    }
    if (c0 > c1) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const int N = 100100;
int n, y, b, a[N];
vector <int> v[N];

int dfs(int node, int ant = -1) {
	int sum = 0, mx = 0;
	if(v[node].size() == 1 && ant != -1)
		return a[node];	

	for(auto i : v[node]) {
		if(i == ant) continue;
		int k = dfs(i, node);
		sum += k;
		mx = max(k, mx);
	}

	int nr = sum - a[node];
	// dbg(node, sum, nr, a[node]);
	if(nr < 0 || nr > sum - mx) throw 4;

	// sum -= 2 * nr;
	if(a[node] < nr) throw 4;
	
	if(v[node].size() == 1) 
		return a[node] - sum;

	return a[node] - nr;
}

int main() {
	ios_base::sync_with_stdio(false);

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

	for(int i = 1; i < n; i++) {
		cin >> y >> b;
		v[b].push_back(y);
		v[y].push_back(b);
	}

	try {
		int x = dfs(1);
		if(x == 0)
			cout << "YES\n";
		else cout << "NO\n";
	} catch(int x) {
		dbg(x);
		cout << "NO\n";
	}
}	

	

Measured memory_bytes: 12800
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

int main()
{
    std::string s, t;
    std::cin >> s >> t;

    int n = s.length(), m = t.length();

    std::vector< std::vector<int> > vec(30);
    for (int i = 0; i < n; ++i)
    {
        vec[s[i] - 'a'].push_back(i);
    }

    for (int j = 0; j < m; ++j)
    {
        if (vec[t[j] - 'a'].size() == 0)
        {
            std::cout << -1;
            return 0;
        }
    }

    int period = 0;
    int curPoint = -1;
    int c, lowerPoint;
    for (int j = 0; j < m; ++j)
    {
        c = t[j] - 'a';
        lowerPoint = std::upper_bound(vec[c].begin(), vec[c].end(), curPoint) - vec[c].begin();
        if (lowerPoint == vec[c].size())
        {
            ++period;
            curPoint = vec[c][0];
        }
        else
        {
            curPoint = vec[c][lowerPoint];
        }
    }

    std::cout << period * 1LL * n + curPoint + 1;
}


Measured memory_bytes: 1216
/*
M == 1
  10 -> START

  10 -> 10, 01
  01 -> 10, 01

  GOAL -> 01

M == 2
  100 -> START

  001 -> 001, 010, 100, 111L
  010 -> 001, 010, 100
  100 -> 001, 010, 100, 111R
  111L-> 100, 111L
  111R-> 001, 111R

  GOAL -> 001
*/

#include <iostream>

using namespace std;
const long MOD = 1000000;
enum SET {
  oox, oxo, xoo, xxxL, xxxR
};

bool canTravel[5][5] = {
  {true, true, true, true, false},
  {true, true, true, false, false},
  {true, true, true, false, true},
  {false, false, true, true, false},
  {true, false, false, false, true}
};

long solve1(int N);
long solve2(int N);

int main() {
  int N,M;
  cin >> N >> M;
  long ans;
  if (M==1) {
    ans = solve1(N);
  } else {
    ans = solve2(N);
  }
  cout << ans << endl;
  return 0;
}

long solve1(int N) {
  long ans = 1;
  for (int i=0; i<N; ++i) {
    ans *= 2;
    ans %= MOD;
  }
  return ans;
}
long solve2(int N) {
  long ans = 0;
  long dp[101][5] = {{0}};
  dp[0][(SET)xoo] = 1;
  for (int i=1; i<=N; ++i) {
    for (int jfrom=0; jfrom<5; ++jfrom) {
      for (int j2=0; j2<5; ++j2) {
        if (canTravel[jfrom][j2]) {
          dp[i][j2] += dp[i-1][jfrom];
          dp[i][j2] %= MOD;
        }
      }
    }
  }

  for (int jfrom=0; jfrom<5; ++jfrom) {
    SET j2 = oox;
    if (canTravel[jfrom][j2]) {
      ans += dp[N][jfrom];
      ans %= MOD;
    }
  }
  return ans;
}

Measured memory_bytes: 3076
//Author: AnandRaj doubleux
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll; 

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test() int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define prinp(p) cout<<p.first<<" "<<p.second<<endl
#define prinv(V) for(auto v:V) cout<<v<<" ";cout<<endl
#define take(V,f,n) for(int in=f;in<f+n;in++) cin>>V[in]
#define what(x) cerr<<#x<<" = "<<x<<endl
#define KStest() int t,t1;cin>>t;t1=t;while(t--)
#define KScout cout<<"Case #"<<t1-t<<": "
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1e9+7,MAX = 1e6+5;
const ll INF = 1e18+5;
/////////////////FastExp///////////////////
ll powN(ll a,ll p)
{
	if(p==0) return 1;
	ll z=powN(a,p/2);
	z=(z*z)%MOD;
	if(p%2) z=(z*a)%MOD;
	return z;
}
/////////////////FastExp///////////////////
///////////////SegmentTree/////////////////
struct SegTree 
{
	int n;
	vector<ll> Tree;
	void init(int sz)
	{
		n = sz;
		Tree.resize(4*n);
	}
	void set(int k, ll x) 
	{
		k+=n;
		Tree[k]=x;
		for(k=k/2;k>=1;k/=2)
		{
			Tree[k]=Tree[2*k]+Tree[2*k+1];
		}
	}
	ll sum(int a, int b)
	{
		a+=n;b+=n;
		ll s=0;
		while(a<=b)
		{
			if(a%2==1) s+=Tree[a++];
			if(b%2==0) s+=Tree[b--];
			a/=2;b/=2;
		}
		return s;
	}
};
///////////////SegmentTree/////////////////
///////////////////PnC/////////////////////
struct PnC
{
	int n;
	vl F,I;
	void init(int n)
	{
		F.resize(n+1);
		I.resize(n+1);
		F[0]=I[0]=1;
		for(int i=1;i<=n;i++)
		{
			F[i]=(F[i-1]*i)%MOD;
			I[i]=powN(F[i],MOD-2);
		}
	}
	ll nCr(int n,int r)
	{
		if(r>n) return 0;
		return (((F[n]*I[r])%MOD)*I[n-r])%MOD;
	}
};
///////////////////PnC/////////////////////
//////////////////Sieve////////////////////
vector<bool> is_prime(MAX, true);
vi MinDiv(MAX);
void Sieve()
{
	is_prime[0] = is_prime[1] = false;
	int i,j;
	for (i = 2; i*i <= MAX; i++) 
	{
    	if (is_prime[i]) 
    	{
    		MinDiv[i]=i;
        	for (j = i * i; j <= MAX; j += i)
            {
				is_prime[j] = false;
				MinDiv[j]=i;
    		}
    	}
	}
	for(int i=2;i<=MAX;i++) if(is_prime[i]) MinDiv[i]=i;
}
//////////////////Sieve////////////////////

int main()
{
	string s;
	cin>>s;
	if(s[0]==s[1]&&s[1]==s[2])
	{
		if(s[0]=='R') cout<<3<<endl;
		else cout<<0<<endl;
	}
	else
	{
		if(s[0]==s[1]&&s[0]=='R') cout<<2<<endl;
		else if(s[1]==s[2]&&s[1]=='R') cout<<2<<endl;
		else cout<<1<<endl;
	}
}	

Measured memory_bytes: 7024
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <string>
#include <cctype>
#include <algorithm>
#include <climits>

using namespace std;

int main()
{
	string W, str;
	int cnt = 0;
	cin >> W;
	transform(W.begin(), W.end(), W.begin(), ::tolower);
	while(cin >> str) {
		if (str == "END_OF_TEXT") break;
		transform(str.begin(), str.end(), str.begin(), ::tolower);
		if (W == str) cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;



vector<int> ip(mx,0);
 
bool isprime(int x){
  if(x==2 || x==3){ return true; }
  if(x<2 || x%2==0){ return false; }
  
  int sqrtx = ceil(sqrt(x));
  for(int i=3; i<=sqrtx; i+=2){ if(x%i==0){ return false; } }
  return true;
}
 
void ipset(int x){                                        //x miman prime set
  for(int i=2; i<x; i++){ ip[i]=(int)isprime(i);}
}

int calc(int n, int x){
  int k=0;
  while(n/1){
    k += n/x;
    n /= x;
  }
  return k;
}

int main(){
  ipset(110);
  int n;
  cin >> n;
  vector<int> p; //n! yakusu
  rep(i,n){
    if(ip[i]){
      p.push_back(calc(n,i));
    }
  }

  vector<vector<int>> dp(110, vector<int>(80,0));
  vector<int> con={1,3,5,15,25,75};
  dp[0][1]=1;
  int sz=p.size();
  rep(i,sz){for(auto a:con){ for(auto b:con){
    if(a*b<=75 && b<=p[i]+1){
      dp[i+1][a*b]+=dp[i][a];
    }
  }}}
  ll ans=dp[sz][75];
  cout << ans << endl; 
  return 0;
}


Measured memory_bytes: 640
n = gets.to_i
reds = []
blues = []
n.times { reds << gets.split.map(&:to_i) }
n.times { blues << gets.split.map(&:to_i) }
reds.sort! { |a, b| b[0] <=> a[0] }
# blue の y が小さい順に見る
blues.sort! { |a, b| a[1] <=> b[1] }
blues.each do |blue_x, blue_y|
  # red の x が大きい順に見て、条件に合致したら削除
  # この時、y の値は条件に合致すれば何でも良い
  # （blue の y は小さい順に見ているため）
  if index = reds.find_index { |red_x, red_y| red_x < blue_x && red_y < blue_y }
    reds.delete_at(index)
  end
end
puts n - reds.size


Measured memory_bytes: 1788
#include<stdio.h>
#include<math.h>
int main() {

	int N, i, count = 0, x, y, z;

	scanf("%d", &N);

	for (i = 1; i <= N; i++) {
		for (x = 1; x <= i; x++) {
			for (y = 1; y <= i; y++) {
				for (z = 1; z <= i; z++) {
					if (x * x + y * y + z * z + x * y + y * z + z * x == i)
						count++;
					if (x * x + y * y + z * z + x * y + y * z + z * x > i)
						break;
				}
				if (x * x + y * y + x * y > i)
					break;
			}
			if (x * x > i)
				break;
		}
		printf("%d\n", count);
		count = 0;
	}

	return 0;
}

Measured memory_bytes: 2096
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define reps(i, n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define repi(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int MOD=1000000007;
using namespace std;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main(){
    int n;
    cin>>n;
    auto dp = make_vec<int>(n+10,4,4,4); //0->T,1->A,2->G,3->C
    dp[0][0][0][0]=1;
    rep(i,n){
        rep(p,4){
            rep(q,4){
                rep(r,4){
                    rep(s,4){
                        if(q==1&&r==2&&s==3) continue;
                        if(q==1&&r==3&&s==2) continue;
                        if(q==2&&r==1&&s==3) continue;
                        if(p==1&&q==2&&s==3) continue;
                        if(p==1&&r==2&&s==3) continue;
                        dp[i+1][q][r][s]+=dp[i][p][q][r];
                        dp[i+1][q][r][s]%=MOD;
                    }
                }
            }
        }
    }
    
    int ans=0;
    rep(p,4){
        rep(q,4){
            rep(r,4){
                ans+=dp[n][p][q][r];
                ans%=MOD;
            }
        }
    }
    
    cout<<ans<<endl;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define ifaxb(a, x, b) if (a < x && x < b)  // 比較は昇順
#define vi vector<int>
#define vii vector<vi>
#define vs vector<string>
#define vss vector<vs>
#define all(x) x.begin(), x.end()
#define pi 3.1415926536
#define ff first
#define ss second
#define pq priority_queue
#define ipair pair<int, int>
#define spair pair<string, string>
#define lpair pair<LL, LL>
#define MP make_pair
#define INF 2147483647
#define _INF -2147483647
#define MM multimap
#define PB push_back
#define MAXN 100004
using namespace std;
typedef long long ll;

int main() {
    int N;
    cin >> N;
    vi V(N);
    vi C(N);

    rep(i, 0, N) {
        cin >> V[i];
    }
    rep(i, 0, N) {
        cin >> C[i];
    }

    // X-YはVi-Ciだけ変化することから
    // コストよりも価値が高いような宝石のみを手に入れるのが最適
    int ans = 0;
    rep(i, 0, N) {
        if (V[i] > C[i]) {
            ans += V[i] - C[i];
        }
    }

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


Measured memory_bytes: 764
using System;
using System.Collections.Generic;
using System.Text;

class TEST{
	static void Main(){
		while(true){
			var s=Console.ReadLine();
			if(s==null)break;
			var d=s.Split(' ');
			Console.WriteLine(int.Parse(d[0])+int.Parse(d[1]));
		}
	}
}

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }


int dp[100010];

int main() {
    ll n,k,q; cin >> n >> k >> q;
    vector<ll> a(q);
    rep(i, q) cin >> a[i];

    vector<ll> ans(n, k-q);
    rep(i, q) ans[a[i]-1]++;

    rep(i, n) {
        if(ans[i] > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;
}



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

using namespace std;

#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)
#define endl "\n"
#define dump(x) cerr << "~ " << #x << " = " << x << endl

long long mod = 998244353;
long long inv = 499122177;

long long dp[3003];

int main() {

	fast_cin;
	
	int n,s,x;
	cin >> n >> s;


	long long two = 1;
	for(int i = 1; i <= n-1; i++) two = (two * 2LL) % mod;

	for(int i = 1; i <= n; i++) {
		
		cin >> x;
		
		//for(int j = 1; j <= s-x; j++)
		for(int j = s-x; j >= 1; j--) {
			dp[j+x] += ( dp[j] * inv ) % mod;
			if(dp[j+x] >= mod) dp[j+x] -= mod; 
		}

		dp[x] = (dp[x] + two) % mod;
	}


	cout << dp[s] << endl;
	
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<long long int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  long long int L = -1, S = -1;
  for (int i = 0; i < N - 1; i++) {
    if (A.at(i) == A.at(i + 1) && L == -1) {
      L = A.at(i);
      i++;
    }
    else if (A.at(i) == A.at(i + 1)) {
      S = A.at(i);
      break;
    }
  }
  if (S == -1) cout << 0 << endl;
  else cout << L * S << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> p(n);
  vector<int> p2(n);
  for(int i=0;i<n;i++){
    cin>>p[i];
    p2[i]=p[i];
  }
  sort(p2.begin(),p2.end());
  int ans=0;
  for(int i=0;i<n;i++){
    if(p2[i]!=p[i]){
      ans++;
    }
  }
  if(ans==2||ans==0){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
open System
let R T = stdin.ReadLine()|> T
let RS T = stdin.ReadLine().Split()|>Array.map T
let R2 T U = RS string|>fun c-> (c.[0]|>T),(c.[1]|>U)
let R3 T U V = RS string|>fun c-> (c.[0]|>T),(c.[1]|>U),(c.[2]|>V)
let R4 T U V W = RS string|>fun c-> (c.[0]|>T),(c.[1]|>U),(c.[2]|>V),(c.[3]|>W)
let R5 T U V W X = RS string|>fun c-> (c.[0]|>T),(c.[1]|>U),(c.[2]|>V),(c.[3]|>W),(c.[4]|>X)
let outl s = stdout.WriteLine(s|>string)
let outsep ls = stdout.WriteLine(String.concat " " (ls|>List.map string))
let outsepl ls = stdout.WriteLine(String.concat "\n" (ls|>List.map string))
let Mod = (1e9|>int64)+7L
[<EntryPoint>]
let main argv =
    let N,M =R2 int int
    let A = RS int
    let S = Array.sum A
    A
    |>Seq.sumBy(fun c -> if 4*M*c>= S then 1 else 0)
    |>fun c -> if c>=M then "Yes" else "No"
    |>outl
    0


Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
const int N=205;
int n,tot,head[N],nex[N*N*2],to[N*N*2];
void add(int u,int v){to[++tot]=v;nex[tot]=head[u];head[u]=tot;}
char s[N][N];
int vis[N];
int bfs(int s)
{
    memset(vis,0,sizeof(vis));
    queue<int>q;
    q.push(s);
    vis[s]=1;
    int res=0;
    while(!q.empty())
    {
        int u=q.front();q.pop();
        res=max(res,vis[u]);
        for(int i=head[u];i;i=nex[i])
        {
            int v=to[i];
            if(!vis[v]) vis[v]=vis[u]+1,q.push(v);
            else if(abs(vis[v]-vis[u])!=1) return -1;
        }
    }
    return res;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%s",s[i]+1);
    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
        if(s[i][j]=='1') add(i,j),add(j,i);
    int ans=0;
    for(int i=1;i<=n;i++)
        ans=max(ans,bfs(i));
    if(ans==0) ans=-1;
    printf("%d\n",ans);
}


Measured memory_bytes: 640
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

N,M = map(int,input().split())
uf = UnionFind(N)

for i in range(M):
  A,B = map(int,input().split())
  uf.union(A-1,B-1)

print(uf.group_count()-1)

Measured memory_bytes: 12756
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin>>N;
  
  vector<int> vec(3*N);
  for(int i=0;i<3*N;i++){
    cin>>vec.at(i);
  }
  
  sort(vec.begin(),vec.end());
  
  int64_t sum=0;
  for(int i=0;i<N;i++){
    sum+=vec.at(N+2*i);
  }
  cout<<sum<<endl;
}
  

Measured memory_bytes: 1408
#include<stdio.h>
#include<math.h>
int main () {
	int width , height;
	int i , s;
	while(1) {
		scanf("%d %d" , &height , &width);
		if (height == 0 && width == 0) break;
		for(i = 0; i < height; i++) {
			for(s = 0; s < width; s++) {
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
N, A, B = map(int, input().split())

if A==0:
    print(0)
    exit()

if A>=N:
    print(N)
else:
    if A+B>=N:
        print(A)
    else:
        s, a = divmod(N, A+B)
        print(s*A+min(A, a))


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

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

int main()
{
	for(int n;cin>>n && n;){
		vector<int> a(n);
		rep(i,n) cin>>a[i];

		vector<int> b=a;
		sort(all(b));

		int res=0;
		rep(i,n){
			int j=lower_bound(all(b),a[i])-begin(b);
			res+=i&1^j&1;
		}

		cout<<res/2<<endl;
	}
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
// cout << fixed << setprecision(10) << ans << endl; 有効桁数指定
// *min_element(c + l, c + r) *max_element(c + l, c + r) 配列の中のmin-max
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// ~ は、-1の時だけfalse

ll dp[100010][13];

int main () {

    string s;cin>>s;

    int n = s.size();

    // cout<<s[n-1]<<endl;

    if (s[n-1]=='?') {
        rep(i,10) {
            dp[0][i]=1;
        }
    } else {
        dp[0][s[n-1]-'0']=1;
    }

    int num = 1;

    rep(i,n-1) {
        num*=10;num%=13;
        if (s[n-2-i]=='?') {
            rep(j,13) {
                rep(k,10) {
                    dp[i+1][(j+num*k)%13]=(dp[i+1][(j+num*k)%13]+dp[i][j])%MOD;
                }
            }
        } else {
            rep(j,13) {
                dp[i+1][(j+num*(s[n-2-i]-'0'))%13]+=dp[i][j];
                dp[i+1][(j+num*(s[n-2-i]-'0'))%13]%=MOD;
            }
        }
    }

    cout<<dp[n-1][5]%MOD<<endl;

}

Measured memory_bytes: 10624
#include <iostream>
#include <cstring>
using namespace std;
using ld = long double;
#define MXN 302
ld dp[MXN][MXN][MXN];
int sushi[MXN], N;

ld calc(int i, int j, int k)
{
	if(!i and !j and !k) return 0.0;
	if(i<0 or j<0 or k<0) return 0.0;
	if(dp[i][j][k]!=0.0) return dp[i][j][k];
	ld sum = (ld) i+j+k, N0 = (ld) N;
	ld i0 = (ld) i, j0 = (ld) j, k0 = (ld) k;
	dp[i][j][k] = N0/sum+i0/sum*calc(i-1, j, k)+j0/sum*calc(i+1, j-1, k)+k0/sum*calc(i, j+1, k-1);
	return dp[i][j][k];
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
	cin>>N;
	for(int i=1; i<=N; i++) cin>>sushi[i];

	int ones = 0, twos = 0, threes = 0;
	for(int i=1; i<=N; i++) 
		if(sushi[i]==1) ones++;
		else if(sushi[i]==2) twos++;
		else threes++;
	cout.precision(15);
	cout <<fixed<< calc(ones, twos, threes) << '\n';
	return 0;
}

Measured memory_bytes: 428416
S=input()
N=len(S)
x=dict()
for i in range(N):
    s = S[i]
    x[s]=s

if "N" in x:
    if "S" in x:
        pass
    else:
        print("No")
        exit()

if "S" in x:
    if "N" in x:
        pass
    else:
        print("No")
        exit()

if "W" in x:
    if "E" in x:
        pass
    else:
        print("No")
        exit()

if "E" in x:
    if "W" in x:
        pass
    else:
        print("No")
        exit()

print("Yes")

Measured memory_bytes: 3064
N = int(input())
T = [int(a) * 2 for a in input().split()]
V = [int(a) * 2 for a in input().split()]
MA = [0] * (sum(T) + 1)
a = 0
for i in range(N):
    for j in range(T[i]):
        a += 1
        MA[a] = min(MA[a-1] + 1, V[i])
MA[a] = 0
for i in range(N)[::-1]:
    for j in range(T[i]):
        a -= 1
        MA[a] = min(MA[a], MA[a+1] + 1, V[i])

print((sum(MA[1:]) + sum(MA[:-1])) / 8)


Measured memory_bytes: 3700
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define all(obj) (obj).begin(), (obj).end()
#define lpair pair<ll, ll>
#define vint vector<ll>
#define vinput(name) for(int i=0; i<(int)(name.size()); i++) cin >> name[i];
#define voutput(name) for(int i=0; i<(int)(name.size()); i++) cout << name[i] << endl;
typedef long long ll;

using namespace std;

ll ans = 0;

int main(void){
	int a, b; cin >> a >> b;
	if(a == b) cout << "Yes";
	else cout << "No";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
long long N; 
int p[200], q[200], cnt = 1;
void solve(long long n) {
	if (!n) return;
   	if (~n & 1) 
		q[++q[0]] = cnt++, solve(n - 1); 
   	else
   		p[++p[0]] = cnt++, solve(n >> 1); 
} 
int main () { 
#ifndef ONLINE_JUDGE 
    freopen("cpp.in", "r", stdin); 
#endif 
	cin >> N; 
	solve(N); 
	printf("%d\n", cnt + 100 - 1);
	for (int i = 1; i <= q[0]; i++) printf("%d ", cnt - q[i]); 
	for (int i = p[0]; i; i--) printf("%d ", cnt - p[i]); 
	for (int i = 1; i <= 100; i++) printf("%d ", i); 
	putchar('\n'); 
    return 0; 
} 

Measured memory_bytes: 3760
import scala.math.abs

object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt
  val list: Array[Array[Int]] = Array.fill[Int](n, 3)(sc.nextInt)
  //  val b = Breaks

  var before = Array[Int](0, 0, 0)
  val canTravel = list.forall {
    target =>
      val step = target(0) - before(0)
      val distance = abs(target(1) - before(1)) + abs(target(2) - before(2))
      before = target
      if (step < distance || step % 2 != distance % 2) {
        false
      } else {
        true
      }
  }


  //  b.breakable {
  //    for (i <- 1 until list.length) {
  //      val step = list(i)(0) - list(i - 1)(0)
  //      val distance = abs(list(i)(1) - list(i - 1)(1)) + abs(list(i)(2) - list(i - 1)(2))
  //
  //      if (step < distance || step % 2 != distance % 2) {
  //        canTravel = false
  //        b.break
  //      }
  //    }
  //  }

  println(if (canTravel) "Yes" else "No")
}


Measured memory_bytes: 98620
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
#define P pair<int,int>

int main() {
	int a;
	while (cin >> a,a) {
		vector<vector<int>>b(a, vector<int>(2));
		for (int c = 0; c < a; c++)cin >> b[c][0] >> b[c][1];
		bool d[21][21]{};
		int e;
		cin >> e;
		int x = 10, y = 10;
		for (int f = 0; f < e; f++) {
			char g; int h;
			cin >> g >> h;
			for (int i = 0; i < h; i++) {
				switch (g) {
				case 'N':y++; break;
				case 'S':y--; break;
				case 'E':x++; break;
				case 'W':x--; break;
				}
				d[x][y] = true;
			}
		}
		bool s = false;
		for (int k = 0; k < a; k++) {
			if (!d[b[k][0]][b[k][1]])break;
			if (a - 1 == k)s = true;
		}
		(s) ? (cout<<"Yes"<<endl) : (cout << "No" << endl);
	}
}

Measured memory_bytes: 3100
#include <stdio.h>
#include <math.h>
int main(void){
    double deg, a,b, S, L, h;
    double rad;
    double PI = acos(-1);
    
    scanf("%lf %lf %lf", &a, &b, &deg);
    rad=deg*PI/180;
    S=a*b*sin(rad)/2;
    L=a+b+sqrt(a*a+b*b-2*a*b*cos(rad));
    h=2*S/a;
    
    printf("%lf\n%lf\n%lf\n", S, L, h);

    return 0;
}



Measured memory_bytes: 2128
#include<stdio.h>
int main(void){
    int N, c = 0, ans = 0;
    scanf("%d", &N);
    int D[N][2];
    for(int i = 0; i < N; i++){
        for(int j = 0; j < 2; j++){
            scanf("%d", &D[i][j]);
        }
        if(D[i][0] == D[i][1]) c += 1;
        else c = 0;
        if (c == 3) ans += 1;
        
    }
    if(ans > 0) printf("Yes");
    else printf("No");
    
    return 0;
}

Measured memory_bytes: 1732
[H,W] = list(map(int,input().split()))
A = [input() for i in range(H)]
row = []
col = []
for i in range(H):
  all_white = True
  for j in range(W):
    if A[i][j] == "#":
      all_white = False
  if all_white:
    row.append(i)
for j in range(W):
  all_white = True
  for i in range(H):
    if A[i][j] == "#":
      all_white = False
  if all_white:
    col.append(j)
for i in range(H):
  if i in row:
    continue
  for j in range(W):
    if j in col:
      continue
    print(A[i][j],end="")
  print()


Measured memory_bytes: 4468
#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int a, b, c;

int main()
{
	in >> a >> b >> c;
	if (b - a == c - b) { out << "YES" << std::endl; }
	else { out << "NO" << std::endl; }
	return 0;
}

Measured memory_bytes: 764
#include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <numeric>
#include <math.h>
#define ll long long 
#define PI 3.14159265358979323846
#define INF 10000000000
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
using namespace std;

int main() {
	ll N;
	cin >> N;
	vector<ll> X(N);
	rep(i, N) cin >> X[i];
	ll ans = INF;
	for (ll i = 1; i <= 100; i++) {
		ll nans = 0;
		rep(j, N) nans += pow(i - X[j], 2);
		ans = min(ans, nans);
	}
	cout << ans << endl;
return 0;
}


Measured memory_bytes: 3592
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long m = sc.nextLong();
        String s = sc.next();
        String t = sc.next();

        long l = lcm(n, m);
        Map<Long, Character> x = new HashMap<>();
        boolean ok = true;
        for (long i = 0; i < n; i++) {
            if (!x.containsKey(i * l / n)) {
                x.put(i * l / n, s.charAt((int) i));
            }
        }

        for (long i = 0; i < m; i++) {
            if (!x.containsKey(i * l / m)) {
                x.put(i * l / m, t.charAt((int) i));
                continue;
            }
            if (x.get(i * l / m) != t.charAt((int) i)) {
                ok = false;
                break;
            }
        }
        if (!ok) {
            System.out.println(-1);
            return;
        }
        System.out.println(l);
    }

    public static long lcm(long a, long b) {
        return a / gcd(a, b) * b;
    }

    public static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }
}


Measured memory_bytes: 49072
// Author: Shusuke Ueda
// AtCoder Beginner Contest 136 - Problem B

#include <iostream>

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

    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (std::to_string(i).length() % 2 == 1) {
            ans++;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define PI acos(-1)
#define Mod (int)1000000007
#define INFTY (int)INT_MAX
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Part(vec, b, e) vec.begin() + b, vec.begin() + e
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Count(vec, x) count(vec.begin(), vec.end(), x)
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define Find(S, s) S.find(s) != string::npos

struct Edge {
	int to, weight;
	Edge(int t, int d) : to(t), weight(d) {}
};

int main() {
	int n;
	cin >> n;
	vector<vector<Edge>> graph(n);
	Rep(i, n - 1) {
		int s, t, d;
		cin >> s >> t >> d;
		graph[s].push_back(Edge(t, d));
		graph[t].push_back(Edge(s, d));
	}
	vector<int> cost(n, INFTY);
	queue<int> Q;
	cost[0] = 0;
	Q.push(0);
	while (!Q.empty()) {
		int v = Q.front();
		Q.pop();
		Rep(i, graph[v].size()) {
			if (cost[graph[v][i].to] == INFTY) {
				cost[graph[v][i].to] = cost[v] + graph[v][i].weight;
				Q.push(graph[v][i].to);
			}
		}
	}
	int tgt = 0, c = 0;
	Rep(i, n) {
		if (cost[i] > c) {
			tgt = i;
			c = cost[i];
		}
	}
	fill(All(cost), INFTY);
	cost[tgt] = 0;
	Q.push(tgt);
	while (!Q.empty()) {
		int v = Q.front();
		Q.pop();
		Rep(i, graph[v].size()) {
			if (cost[graph[v][i].to] == INFTY) {
				cost[graph[v][i].to] = cost[v] + graph[v][i].weight;
				Q.push(graph[v][i].to);
			}
		}
	}
	int ans = 0;
	Rep(i, n) {
		if (cost[i] > ans) {
			ans = cost[i];
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 9660
#include <cstdio>
#include <cstdlib>

const int MAX = 500000;

int GetParentIdx(int idx)
{
    return idx / 2;
}

int GetLeftIdx(int idx)
{
    return 2 * idx;
}
int GetRightIdx(int idx)
{
    return 2 * idx + 1;
}

void MaxHeapify(int *A, int i, int n)
{
    int l_i = GetLeftIdx(i);
    int r_i = GetRightIdx(i);

    int largest = i;

    if (l_i <= n && A[l_i] > A[i]) {
        largest = l_i;
    }
    if (r_i <= n && A[r_i] > A[largest]) {
        largest = r_i;
    }

    if (largest != i) {
        int tmp_val = A[i];
        A[i] = A[largest];
        A[largest] = tmp_val;
        MaxHeapify(A, largest, n);
    }
}

void BuildMaxHeap(int *A, int n)
{
    for (int i = n/2; i >= 1; i--) {
        MaxHeapify(A, i, n);
    }
}

int main(int argc, char *argv[])
{
    int n;
    int H[MAX + 1];
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &H[i]);
    }
    BuildMaxHeap(H, n);
    for (int i = 1; i <= n; i++) {
        fprintf(stdout, " %d", H[i]);
    }
    fprintf(stdout, "\n");
}


Measured memory_bytes: 4640
from collections import Counter
n = int(input())
d = Counter(list(map(int, input().split())))
if len(d) == 1:
    if d[0] == n:
        print("Yes")
        exit()
elif len(d) == 2:
    if n%3 == 0 and d[0] == n//3:
        print("Yes")
        exit()
elif len(d) == 3:
    k = list(d.keys())
    if n%3 == 0 and k[0] ^ k[1] ^ k[2] == 0 and d[k[0]] == d[k[1]] == d[k[2]]:
        print("Yes")
        exit()
print("No")

Measured memory_bytes: 20872
#include <fstream>
#include <iostream>
#include <vector>
#include <cstring>
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define Nmax 1000005
#define INF 1000000000
#define MOD 1000000007
 
using namespace std;

int main()
{
    
    // #ifndef ONLINE_JUDGE
    //     freopen ("data.in","r",stdin);
    //     freopen ("E.out","w",stdout);
    // #endif
    cin.sync_with_stdio( false );

    int tests=1;
    // cin>>tests;
    while(tests--)
    {
    	ll a,b,c,k,ans=0;
    	cin>>a>>b>>c>>k;
    	ans+=min(a,k);
    	k-=a;
    	if(k>0)
    	{
    		k-=b;
    	}
    	if(k>0)
    	{
    		ans-=min(c,k);
    	}
    	cout<<ans;

   	}
    	return 0;
    
}

Measured memory_bytes: 3652
# coding: utf-8
# Your code here!
n,m=map(int,input().split(" "))
mae=0
usiro=100000
for i in range(m):
    s,t=map(int,input().split(" "))
    if(mae<=s):
        mae=s
    if(usiro>=t):
        usiro=t
#print(mae,usiro)
ans=usiro-mae+1
if(ans<0):
    ans=0
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ALL(v) std::begin(v), std::end(v)
#define ALLR(v) std::rbegin(v), std::rend(v)
using ll = std::int64_t;
using ull = std::uint64_t;
using pll = std::pair<ll, ll>;
using tll = std::tuple<ll, ll, ll>;
template <typename T> using vec = std::vector<T>;
template <typename T> using vvec = vec<vec<T>>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return vec<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec

int main() {
    std::string s;
    std::cin >> s;
    std::deque<char> deq;
    bool ord = true;
    for (char c : s) deq.push_back(c);
    ll q;
    std::cin >> q;
    while (q--) {
        ll t;
        std::cin >> t;
        if (t == 1) {
            ord = !ord;
        } else {
            ll f;
            char c;
            std::cin >> f >> c;
            bool fr = (f == 1);
            if (ord == fr) deq.push_front(c);
            else deq.push_back(c);
        }
    }

    while (deq.size()) {
        if (ord) {
            std::cout << deq.front();
            deq.pop_front();
        } else {
            std::cout << deq.back();
            deq.pop_back();
        }
    }

    std::cout << '\n';
    return 0;
}


Measured memory_bytes: 976
program prob3
    implicit none
    integer::N,i,j,l,tmp,ans
    integer,allocatable::a(:)
    character(len=200005)::S
    read(*,*) N, S
    l = len_trim(S)
    allocate(a(l))
    if(S(1:1) .eq. ".") then
        a(1) = 0
    else
        a(1) = 1
    end if
    do i = 2, l
        if(S(i:i) .eq. ".") then
            a(i) = a(i-1)
        else
            a(i) = a(i-1) + 1
        end if
    end do

    ans = l
    do i = 1, l-1
        tmp = a(i) + (N - i) - (a(N) - a(i+1))
        if(S(i+1:i+1) .eq. "#") then
            tmp = tmp - 1
        end if
        ans = min(tmp,ans)
    end do
    ans = min(a(l),ans)
    ans = min(l-a(l),ans)
    write(*,*) ans
    stop
end program

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


int main(){
  int64_t X;
  cin >> X;
  for(int64_t i=-120;i<=120;i++){
    for(int64_t j=-120;j<=i;j++){
      int64_t A=i*i*i*i*i;
      int64_t B=j*j*j*j*j;
      if(X==A-B){
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }
  
}


Measured memory_bytes: 3604
#include <iostream>
#include <cstdio>
#include <cctype>
using namespace std;
const int f=500;
int a, n;
int main() {
	ios::sync_with_stdio(false);
	cin >> n >> a;
	if((a>=n&&n!=0)||(n%500<=a)) {
		cout << "Yes\n";
		return 0;
	}
	if(n==0) {
		cout << "No\n";
		return 0;
	}
	if(n%500>a) {
		cout << "No\n";
		return 0;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define rep(i, a, b) for(int i = a; i < b; ++i)

int debug = 0;

const int N = 5e5;
int p[N], n, x, m, a, i, ind, lencyc, cycle, ans;

main() {
    cin >> n >> x >> m;
    a = x;
    for (i = 1; p[a] == 0; ++i) {
        p[a] = i;
        a = a * a % m;
    }
    ind = p[a];
    lencyc = i - ind;
    if (n <= ind) {
        a = x;
        rep(i, 0, n) {
            ans += a;
            a = a * a % m;
        }
    } else {
        n -= ind;
        a = x;
        rep(i, 1, ind + 1) {
            ans += a;
            a = a * a % m;
        }
        cycle = 0;
        rep(i, ind + 1, ind + lencyc + 1) {
            cycle += a;
            a = a * a % m;
        }
        ans += cycle * (n / lencyc);
        n %= lencyc;
        rep(i, 0, n) {
            ans += a;
            a = a * a % m;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4312
using System;
using System.Text;

class CF2016RB
{
	static public void Main(string[] vals)
	{
		string S = Console.ReadLine();
		StringBuilder sb = new StringBuilder(S);

		for(int i=0; i<S.Length; i++)
		{
			int j = S.Length - i - 1;
			switch(S[i])
			{
				case 'b':
					sb[j] = 'd';
					break;
				case 'd':
					sb[j] = 'b';
					break;
				case 'p':
					sb[j] = 'q';
					break;
				case 'q':
					sb[j] = 'p';
					break;
			}
		}

		if(sb.ToString() == S)
		{
			Console.WriteLine("Yes");
		}
		else
		{
			Console.WriteLine("No");
		}
	}
}


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


int main(){
	int n;
	scanf("%d", &n);
	int a[n];
	for(int i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}
	sort(a, a+n);
	int i;
	long w = 0, h = 0;
	for(i = n - 1; i > 0; i--){
		if(a[i] == a[i-1]){
			w = a[i];
			i = i-2;
			break;
		}
	}
	for( ; i > 0; i--){
		if(a[i] == a[i-1]){
			h = a[i];
			break;
		}
	}
	printf("%ld\n", h*w);
	return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

LL gcd(LL c,LL d){
  while(c%d){
    LL tmp = c%d;
    c=d;
    d=tmp;
  }
  return d;
}

LL lcm(LL c,LL d){
  return c*d/gcd(c,d);
}

LL kosu(LL x, LL c, LL d){
  return x-((x/c)+(x/d)-(x/lcm(c,d)));
}

int main(){
  LL a,b,c,d;
  cin >> a >> b >> c >> d;
  cout << kosu(b,c,d)-kosu(a-1,c,d) << endl;
  return 0;
}


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

int main()
{
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;

  rep(i, n){
    cout << s.at(i) << t.at(i);
  }
  // cout << st;
}


Measured memory_bytes: 3656
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
//#define int long long int
using namespace std;

signed main(){
    int x,a; cin>>x>>a;
    if(x < a) cout<<0<<endl;
    else cout<<10<<endl;

    return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

def tarou(n,a,b,c):
	manzoku = b[a[0]-1]
	for i in range (1,n):
		manzoku += b[a[i]-1]
		if a[i]-a[i-1] == 1:
				manzoku += c[a[i]-2]
	print (manzoku)
tarou (n,a,b,c)

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

int main(){
  string str;
  cin >>str;
  
  int ans=0;
  int cnt=0;
  for(int i=0; i<str.size(); i++){
    if(str[i]=='A' || str[i]=='C' || str[i]=='G' || str[i]=='T'){
      cnt++;
      ans=max(ans,cnt);
    }
    else cnt=0;
  }
  cout <<ans<<endl;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0)
#define mapmax(v) v.rbegin()->first
#define mapmin(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const int mod=1000000007;
const int mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

void YES(bool b) {cout << (b?"YES\n":"NO\n");}
void Yes(bool b) {cout << (b?"Yes\n":"No\n");}
void yes(bool b) {cout << (b?"yes\n":"no\n");}
void Yay(bool b) {cout << (b?"Yay!\n":":(\n");}

long long powmod(long long a,long long b){
    long long c=1;
    while(b>0){
        if(b&1) c=a*c%mod;
        a=a*a%mod;
        b>>=1;
    }
    return c;
}

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

int main()
{
	ll n,k;
	double ans=0.0;
	cin >> n >> k;
	vd a(n+1);
	rep(i,n){
		cin >> a[i+1];
		a[i+1]=(a[i+1]+1)/2;
	}
	cerr << a;
	rep(i,n-1){
		a[i+2]+=a[i+1];
	}
	cerr << a;
	rep(i,n-k+1){
		chmax(ans,a[i+k]-a[i]);
	}
	cout << DOUBLE << ans << endl;
	return 0;
}


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int MC = 100010;
int N;
tuple<LL,int,int> e[MC];
LL ans[MC];
LL potential[MC];
int group[MC];
vector<int> G[MC];

void uni(int a , int b){
	int x = group[a] , y = group[b];
	if(G[x].size() < G[y].size()) swap(x,y);
	for(auto u : G[y]){
		ans[u] += potential[y] - potential[x];
		G[x].PB(u);
		group[u] = x;
	}
}

int main(){
	cin >> N;
	repp(i,1,N+1){
		G[i].PB(i);
		group[i] = i;
	}
	repp(i,1,N){
		int a,b,c;
		cin >> a >> b >> c;
		e[i-1] = make_tuple(c,a,b);
	}
	sort(e,e+N-1);
	repm(i,N-2,-1){
		int a = get<1>(e[i]) , b = get<2>(e[i]) , c = get<0>(e[i]);
		potential[group[a]] += c * G[group[b]].size();
		potential[group[b]] += c * G[group[a]].size();
		uni(a,b);
	}
	repp(i,1,N+1) cout << ans[i] + potential[group[i]] << endl;
	return 0;
}


Measured memory_bytes: 13944
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i = 0; i < (ll) n; i++)
#define xrep(i,x,n) for(ll i = (ll) x; i < (ll) n; i++)
#define vl vector<long long>
#define vs vector<string>

int main() {
    ll N; cin >> N;
    string S,T,U; cin >> S >> T;

    rep(i,N){
        U = U + S[i] + T[i];
    }
    cout << U << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
const int MOD=1e9+7;


int main() {
    int n;
    cin >> n;
    bool flag=0;
    while (n>0) {
        if (n%10==7) flag=1;
        n/=10;
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

int main(){
	int N;
	cin >> N;
	vector<ll> a(N);
	REP(i, N) cin >> a[i];
	sort(a.begin(), a.end());
	int target = -1;
	ll res = 0;
	REP(i, N){
		if(target==a[i]) continue;
		target = a[i];
		int num = upper_bound(a.begin(), a.end(), target) - lower_bound(a.begin(), a.end(), target);
		if (num>=target){
			res += (num - target);
		}else{
			res += num;
		}
	}
	cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif

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

    const ll MOD = (ll)1e9 + 7;
    int N, M; cin >> N >> M;
    vl A(M); REP(i, M) cin >> A[i];

    set<ll> st;
    REP(i, M) st.insert(A[i]);

    vl dp(N + MGN, 0);
    dp[0] = 1;
    if (st.count(1)==0) dp[1] = 1;

    FOR(i,0,N+1) {            
        if (st.count(i) == 0 && st.count(i+1) ==0) {
            dp[i + 2] = dp[i]%MOD + dp[i + 1]%MOD;
        } else if (st.count(i) == 0) {
            dp[i + 2] = dp[i]%MOD;
        } else if (st.count(i + 1) == 0) {
            dp[i + 2] = dp[i + 1]%MOD;
        }
        dp[i + 2] %= MOD;
    }

    ll ans = dp[N];
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6528