akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int a = scan.nextInt();
		String op = scan.next();
		int b = scan.nextInt();

		if (op.equals("+")) {
			System.out.println(a + b);

		} else if (op.equals("-")) {
			System.out.println(a - b);
		}

	}

}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  ll N,M,K,i,ans=0,a=0,b=0;
  cin>>N>>M>>K;ll A[N+1],B[M+1];
  A[0]=0;B[0]=0;
  REP(i,N){
    cin>>A[i+1];A[i+1]+=A[i];
  }
  REP(i,M){
    cin>>B[i+1];B[i+1]+=B[i];
  }
  REP(i,N+1){
    if(K<A[i])break;
    ans=max((long)ans,i+upper_bound(B,B+M+1,K-A[i])-B-1);
  }
  cout<<min(ans,M+N)<<endl;
  return 0;
}

Measured memory_bytes: 6756
import sys
#import numpy as np

sys.setrecursionlimit(10 ** 9)
#def input():
#    return sys.stdin.readline()[:-1]

#N = int(input())
N, M = map(int,input().split())
A = list(map(int,input().split()))

days = sum(A)

ans = N - days if N - days >= 0 else -1

print(ans)

Measured memory_bytes: 9856
#include <algorithm>
#include <iostream>
#include <vector>
#include <functional>
using namespace std;

template<typename Monoid>
struct SegmentTree {
    using F = function<Monoid(Monoid, Monoid)>;
    const F f;
    const Monoid M1;
    int sz;
    vector<Monoid> dat;
    SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
        sz = 1;
        while (sz < n) sz <<= 1;
        dat.assign(sz * 2, M1);
    }
    void set(int k, const Monoid &x) { dat[k + sz] = x; }
    void build() {
        for (int k = sz - 1; k > 0; k--) {
            dat[k] = f(dat[2 * k], dat[2 * k + 1]);
        }
    }
    void update(int k, const Monoid &x) {
        dat[k += sz] = x;
        while (k >>= 1) dat[k] = f(dat[2 * k], dat[2 * k + 1]);
    }
    Monoid get(int a, int b) {  // [a, b)
        Monoid L = M1, R = M1;
        for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
            if (a & 1) L = f(L, dat[a++]);
            if (b & 1) R = f(dat[--b], R);
        }
        return f(L, R);
    }
    Monoid operator[](const int &k) const { return dat[k + sz]; }
    friend ostream& operator<<(ostream& os, SegmentTree<Monoid> &seg) {
        for (int i = 0; i < seg.sz; i++) os << seg[i] << " ";
        return os;
    }
};

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

int main() {
    int n; cin >> n;
    SegmentTree<int> seg(n, [](int a, int b) { return gcd(a, b); }, 0);
    for (int i = 0; i < n; i++) {
        int a; cin >> a;
        seg.set(i, a);
    }
    seg.build();
    int ma = 0;
    for (int i = 0; i < n; i++) {
        int left = seg.get(0, i);
        int right = seg.get(i + 1, n);
        ma = max(ma, gcd(left, right));
    }
    cout << ma << endl;
    return 0;
}

Measured memory_bytes: 1280
arr = list(input())
down = list()
areas = list()

for i, el in enumerate(arr):
    if el == "\\":
        down.append(i)
    elif el == "/" and not len(down) == 0:
        start_ind = down.pop()
        area = i - start_ind
        while len(areas) > 0 and areas[-1][0] > start_ind:
            area += areas.pop()[1]
        areas.append((start_ind, area))

areas = [areas[i][1] for i in range(len(areas))]
print(sum(areas))
print(str(len(areas)) + " " + " ".join(map(str,areas)) if not len(areas) == 0  else "0")


Measured memory_bytes: 6392
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  vector<long> D(N);
  for(int i = 0; i < N; i++)cin >> D.at(i);
  sort(D.begin(), D.end());
  int M;
  cin >> M;
  vector<long> T(M);
  for(int i = 0; i < M; i++)cin >> T.at(i);
  sort(T.begin(), T.end());
  int pl = 0;
  int flag = 1;
  for(int i = 0; i < M; i++){
    while(D.at(pl) != T.at(i)){
      pl++;
      if(pl >= N){
        flag = 0;
        break;
      }
    }
    pl++;
    if(pl >= N)break;
  }
  cout << (flag?"YES":"NO") << endl;
  return 0;
}

Measured memory_bytes: 3328
package main

import (
	"fmt"
)

func main() {
	var c [3][3]int
	for i := 0; i < 3; i++ {
		fmt.Scan(&c[i][0], &c[i][1], &c[i][2])
	}

	var a [3]int
	var b [3]int
	a[0] = 0
	b[0] = c[0][0]
	b[1] = c[0][1]
	b[2] = c[0][2]
	a[1] = c[1][0] - b[0]
	a[2] = c[2][0] - b[0]

	for i := 0; i < 3; i++ {
		for j := 0; j < 3; j++ {
			if a[i]+b[j] != c[i][j] {
				fmt.Println("No")
				return
			}
		}
	}
	fmt.Println("Yes")
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  map<int,int>a;
  int tmp;
  for(int i=0;i<n;i++){
    cin>>tmp;
    if(a.count(tmp))a.at(tmp)++;
    else a[tmp]=1;
  }
  int ans=0;
  for(auto num:a){
    if(num.second!=num.first){
      if(num.second>num.first){
        ans+=num.second-num.first;
      }
      else ans+=num.second;
    }
  }
  cout <<ans<<endl;
}

Measured memory_bytes: 8104
#include <iostream>

using namespace std;

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

    int A[N];
    int diff = 0;
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        if (i > 0 && A[i] - A[i - 1] > diff) diff = A[i] - A[i - 1];
    }

    if (A[0] - 0 + K - A[N - 1] > diff) diff = A[0] - 0 + K - A[N - 1];
    cout << K - diff << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;

int main(){

  string p="IOI",str,oi="OI";
  int count,n,m,z,j;

  while(cin >> n, n){

    count = j = z = 0;
    p = "IOI";

    for(int i=1;i<n;i++) p += oi;
 
    z = p.size();

    cin >> m;
    cin >> str;

    for(int i=0;i<str.size()-z+1;i++){
      if(p == str.substr(j,i+z-j)) count++;
      j = i + 1;
    }

    cout << count << endl;

  }
}

Measured memory_bytes: 2160
import java.util.Scanner;

public class Main {

	public static void main(
			String[] args) {
		Scanner sc = new Scanner(System.in);
		double n = sc.nextDouble();
		if (n < 1 || n > 200) {
			return;
		}
		double[] a = new double[(int) n];

		for (int i = 0; i < n; i++) {
			a[i] = sc.nextDouble();
			if (n < 1 || n > 1000000000) {
				return;
			}
		}
		int two = 0;
		all: while (two < 100000) {
			for (int i = 0; i < n; i++) {
				if (a[i] % Math.pow(2, two + 1) != 0) {
					break all;
				}
			}
			two++;
		}
		System.out.println(two);
	}
}


Measured memory_bytes: 24532
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[20005];
ll exgcd(ll m,ll n,ll & x,ll & y)
{
    if (n==0)
    {
        x =1, y = 0;
        return m;
    }
    ll r=exgcd(n, m%n, y, x);
    y -=m/n*x;
    return r;
}
int main(){
    ll n,m;
    while(cin>>n>>m){
            int fa=0;
            if(n==1&&m==0){
                cout<<0<<endl;continue;
            }
        memset(a,-1,sizeof(a));
        for(int i=1;i<=m;i++){
            ll x,y;cin>>x>>y;
            if(a[x]!=-1&&a[x]!=y){
                fa=1;
            }
            a[x]=y;
        }
        if(a[1]==0&&n!=1) fa=1;
        if(n==1&&a[1]==-1) a[1]=0;
        if(a[1]==-1) a[1]=1;
        if(fa) cout<<-1<<endl;
        else{
            for(int i=1;i<=n;i++){
                if(a[i]!=-1) cout<<a[i];
                else cout<<0;
            }
            cout<<endl;
        }
    }
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_map>
#include<unordered_set>
using namespace std;
typedef long long ll;
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod;
#define mul(a,b) a=a*b%mod;
#define N 100010
ll n,m,a[N];
vector<ll> len[N];
int main(){
  cin>>n>>m;
  ll bot=-1;
  for(int i=0;i<n;i++){
      cin>>a[i];
      a[i]--;
      if(i==0)bot=a[0];
      a[i]-=bot;
      if(a[i]<0)a[i]+=m;
      //cout<<a[i]<<" ";
  }
  for(int i=0;i<n-2;i++){
      len[a[i+1]].push_back((a[i+1]-a[i]+m)%m);
  }
  ll base=0,score=0,cnt=1;
  for(int i=0;i<n-1;i++){
      base+=(a[i+1]-a[i]+m)%m;
      if(a[i+1]<a[i]){
	  score+=m-1-a[i]; //cout<<"#"<<i<<" "<<m-1-a[i]<<endl;
	  cnt++;
      }
  }//cout<<base<<" "<<cnt<<endl;
  ll ans=1e17;
  for(ll x=0;x<m;x++){
      chmin(ans,base-score);
      //cout<<score<<" "<<base-score<<endl;
      for(auto l:len[x]){
	  score-=l;
      }
      if(x==0)score--;
      if(x==a[n-1]){
	  score+=-((a[n-1]-a[n-2]+m)%m)+1;
	  cnt--;
      }
      score+=cnt;
  }
  cout<<ans<<endl;
  return 0;
}


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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<long long> a(n), b(n);
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
    long long sum = 0;
    for (int i = n-1; i >= 0; i--) {
        a[i] += sum;
        long long x = (b[i] - (a[i] % b[i]) % b[i]) % b[i];
        sum += x;
    }
    cout << sum << "\n";
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,count=1;
    int n;
    cin>>n;
    string s;
    cin>>s;

    for(i=1; i<n; i++)
    {
        if(s[i] != s[i-1])
        {
            count++;
        }
    }
    cout<<count;
return 0;
}

Measured memory_bytes: 512
X = [0] * 5
D = {"M": 0, "A": 1, "R": 2, "C": 3, "H": 4}
N = int(input())
for _ in range(N):
    s = input()[0]
    if s in D:
        X[D[s]] += 1

ans = 0
for i in range(3):
    for j in range(i+1, 4):
        for k in range(j+1, 5):
            ans += X[i] * X[j] * X[k]
print(ans)

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

int main(){
  int sum[4][2]={0};
  double left,right;
  int cnt=0;
  while(cin>>left>>right){
    if(left>=1.1)sum[0][0]++;
    else if(left>=0.6)sum[1][0]++;
    else if(left>=0.2)sum[2][0]++;
    else sum[3][0]++;
    cnt++;
    if(right>=1.1)sum[0][1]++;
    else if(right>=0.6)sum[1][1]++;
    else if(right>=0.2)sum[2][1]++;
    else sum[3][1]++;
  }
  for(int i=0;i<4;i++){
    cout<<sum[i][0]<<" "<<sum[i][1]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1224
n = int(input())
nt, nx, ny = 0, 0, 0
for i in range(n):
    t, x, y = map(int, input().split())
    now = t-nt
    location = abs(nx-x) + abs(ny-y)
    if location <= now and (now-location)%2 == 0:
        nt, nx, ny = t, x, y
    else:
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 9092
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[] a = new long[N];
		for (int i = 0; i < N; i++)
			a[i] = sc.nextLong() - i - 1;
		Arrays.sort(a);
		long[] s = new long[N + 1];
		for (int i = 0; i < N; i++)
			s[i] = i == 0 ? a[i] : s[i - 1] + a[i];
		long total = s[N - 1];
		long min = Long.MAX_VALUE;
		for (int i = 0; i < N; i++) {
			if (i > 0 && a[i] == a[i - 1])
				continue;
			long l = a[i] * (i + 1) - s[i];
			long h = (total - s[i]) - a[i] * (N - i - 1);
			min = Math.min(min, l + h);
		}
		System.out.println(min);
	}
}


Measured memory_bytes: 67664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} //配列vにn個の要素を入力する
#define rep(i, l, n) for (int i = l; i < (int)(n); i++)
#define repn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 

const int mod = 1000000007;
const int inf = 1e9;

float round_n(float number, double n)
{
    number = number * pow(10,n-1); 
    number = round(number); 
    number /= pow(10, n-1); 
    if(number == -0) number += 0;
    return number;
}

int main(){
    while(1){
        float a = inf,b,c,d,e,f;
        cin >> a >> b >> c >> d >> e >> f;
        if(a == inf){break;}
        float x = (c*e-b*f)/(a*e-d*b);
        float y = (c*d-a*f)/(b*d-a*e);
        cout << fixed<<setprecision(3) << round_n(x, 4) << " " << fixed<<setprecision(3) << round_n(y,4) << endl;
    }
}


Measured memory_bytes: 3460
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=200005,M=1000005;
int read(){
	int f=1,g=0;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int n,m,a[N][2],h[N*2];
int size,fir[N*2],cnt;
struct edge{int u,v,nex;}e[M];
void add(int u,int v){e[++size]=(edge){u,v,fir[u]};fir[u]=size;}
char col[N];
bool work(int x){
	if (h[x]==1) return true;
	else if (h[x]==2) return false;
	h[x]=1;
	for (int i=fir[x];i;i=e[i].nex)
	if (work(e[i].v)) return true;
	h[x]=2;
	return false;
}
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	scanf("%d %d",&n,&m);
	scanf(" %s",col+1);
	for (int i=1;i<=n;i++){
		a[i][0]=++cnt;
		a[i][1]=++cnt;
	}
	for (int i=1;i<=m;i++){
		int u,v;scanf("%d %d",&u,&v);
		if (col[u]==col[v]){
			add(a[u][0],a[v][1]);
			add(a[v][0],a[u][1]);
		}
		else {
			add(a[u][1],a[v][0]);
			add(a[v][1],a[u][0]);
		}
	}
	for (int i=1;i<=cnt;i++)
	if (!h[i]){
		if (work(i)) {puts("Yes");return 0;}
	}
	puts("No");
	return 0;
}

Measured memory_bytes: 15232
def main(n: int, m: int, p_s: list):
    bool_ac = [False for _ in range(n)]
    count_wa = [0 for _ in range(n)]
    ac, wa = 0, 0

    for p, s in p_s:
        p = int(p)

        if bool_ac[p - 1]:
            continue

        if s == "AC":
            bool_ac[p - 1] = True
            wa += count_wa[p - 1]
            ac += 1
        elif s == "WA":
            count_wa[p - 1] += 1

    print(ac, wa)


if __name__ == "__main__":
    n, m = map(int, input().split())
    p_s = [input().split() for _ in range(m)]

    main(n, m, p_s)


Measured memory_bytes: 33888
l = input().split()
A = int(l[0])
B = int(l[1])

cnt = 0
for i in range(A, B + 1):
	S = str(i)
	ok = True
	for j in range(0, 3):
		if S[j] != S[4 - j]:
			ok = False
			break

	if ok:
		cnt = cnt + 1

print(cnt)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int x=1,cn,n;

int main(){
	cin>>cn;
	while(cin>>n){
		cout<<"Case "<<x++<<":"<<endl;
		for(int i=0;i<10;i++){
			n*=n;
			n=(n/100)%10000;
			cout<<n<<endl;
		}
	}
}

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

#define f(i, q) for(int i = 0; i < q; i++)  

typedef long long ll;

int main() {
    string s;
    cin >> s;

    bool flg = true;
    for( int i = 1; i < s.size(); i++) {
        if (s.at(i - 1) == s.at(i)) {
            flg = false;
            break;
        }
    }

    if(flg) {
        puts("Good");
    } else {
        puts("Bad");
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;

int main() {
  
  int a,b,c,d,x;
  double da,db;
  string s,ss,sss;
  
  int ans = 0;
  string anss = "";
  
  cin >> x >> a >> b;
  
  int ab [] = {0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1};
  int result3 = std::max({a, b, c});
//--------------------------------------------------------------------------------

  if(b > a*x) ans = a*x;
  else ans = b;

  cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int D, T, S;

    cin >> D >> T >> S;

    double time = (double)D / S;
    if (time <= T) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}

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

int n, m;
class Edge{
	public:
		long long cost;
		int from, to;
		Edge(long long c, int f, int t){
			cost = c;
			from = f;
			to = t;
		}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void readGraph(Graph &g, int E, bool D, bool C){ // E:NumofEdges, D:Directed, C:Costed
	for(int i=0; i<E; ++i){
		Edge e(0, 0, 0);
		if(!C) cin >> e.from >> e.to;
		else cin >> e.from >> e.to >> e.cost;
		--e.from;
		--e.to;
		g[e.from].push_back(e);
		if(!D){
			swap(e.from, e.to);
			g[e.from].push_back(e);
		}
	}
}
int ans;
void dfs(Graph &g, int a, int b, vector<int> &c, int v, int p){
	for(int i=0; i<g[v].size(); ++i){
		if(g[v][i].to != p && !(v == a && g[v][i].to == b) && !(v == b && g[v][i].to == a) && c[g[v][i].to] == 0){
			c[g[v][i].to] = 1;
			dfs(g, a, b, c, g[v][i].to, v);
		}
	}
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n >> m;
	Graph g(n);
	readGraph(g, m, false, false);
	for(int i=0; i<n; ++i){
		for(int j=0; j<g[i].size(); ++j){
			int a = i;
			int b = g[i][j].to;
			vector<int> c(n, 0);
			c[0] = 1;
			dfs(g, a, b, c, 0, 0);
			int f = true;
			for(int k=0; k<n; ++k){
//				cout << k << " " << c[k] << "\n";
				if(c[k] == 0)
					f = false;
			}
			if(!f){
				++ans;
//				cout << "bridge\n";
			}
		}
	}
	cout << ans / 2 << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <unordered_set>
#include <numeric>
#include <iterator>
#include <unordered_map>
#include <array>
#include <map>
#include <cstring>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cmath>
#include <ctgmath>
#include <set>
#include <queue>

using namespace std;
#define int long long
struct point {
	int x;
	int y;
	int h;
};

bool valid(vector<point> &all, int x, int y, int h)
{
	for (auto i : all)
	{
		if (max(h - abs(i.x - x) - abs(i.y - y), (int)0) != i.h)
		{
			return false;
		}
	}
	return true;
}

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

	int n;
	cin >> n;

	vector<point> all;
	int maxheight = 0;

	for (int i = 0; i < n; i++)
	{
		int x, y, h;
		cin >> x >> y >> h;

		maxheight = max(maxheight, h);

		all.push_back({ x,y,h });
	}

	for (int i = maxheight; i <= 1000000101; i++)
	{
		for (int j = 0; j <= 100; j++)
		{
			for (int k = 0; k <= 100; k++)
			{
				if (valid(all, j, k, i))
				{
					cout << j << " " << k << " " << i << "\n";
					return 0;
				}
			}
		}
	}



}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

bool check(vector<int>& dp){
	rep(i,dp.size()){
		if(i == 0) continue;
		if((i bitand dp[i]) == dp[i]) return false;
	}
	return true;
}

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

		set<pair<int,int>> st;

		int bit = 0;
		rep(i,s.size() - 1){
			if(s[i] == 'u') bit = 0;
			else bit |= 1 << (s[i] - '0');

			//show(bitset<10>(bit))
			if(s[i + 1] != 'u' and bit != 0) st.emplace(bit, s[i + 1] - '0');
		}

		//for(auto i : st){
		//	cout << bitset<10>(i.first) << ' ' << i.second << endl;
		//}

		vector<int> dp(1 << 10, -1);
		dp[0] = 0;
		rep(s,1 << 10){
			if(dp[s] == -1) continue;
			for(auto p : st){
				bit = p.first;
				int nxt = p.second;

				if((bit bitand s) != 0) continue;

				int nbit = bit bitor s;
				if(dp[nbit] == -1) dp[nbit] = 1 << nxt;
				else dp[nbit] |= 1 << nxt;
			}
		}

		//rep(i,dp.size()){
		//	if(dp[i] != -1) cout << bitset<10>(i) << ' ' << bitset<10>(dp[i]) << endl;
		//}

		cout << (check(dp) ? "SAFE" : "UNSAFE") << endl;
	}
}



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

int main(){
    string s;
    cin>>s;
    long long int sm = 0 ;
    for(int  i= 0  ; i < s.length() ; i++)sm += s[i] - '0';
    (sm % 9 == 0) ? cout<<"Yes"<<endl : cout<<"No"<<endl;
}


Measured memory_bytes: 3728
import collections

def main():
    n,m = tuple([int(t)for t in input().split()])

    a = tuple([int(t)for t in input().split()])

    csum = list(map(lambda a: a%m,cumsum(a)))

    c = collections.Counter(csum)
    ans = 0
    for c_i in c.values():
        ans += c_i*(c_i-1)//2
    print(ans)

def cumsum(a):
    s = 0
    sums = [0]
    for a_i in a:
        s+=a_i
        sums.append(s)

    return sums

if __name__ == "__main__":
    main()

Measured memory_bytes: 17728
def max(arr):
    if len(arr) == 0:
        return 0
    max = arr[0]
    for i in range(len(arr)):
        if arr[i] > max:
            max = arr[i]
    return max

def calculate(arr,n):

    if len(arr) == 0:
        return []

    start = 0
    ret = []

    for i in range(n):
        if i == 0:
            continue
        else:
            if arr[i] > arr[i-1]:
                ret.append(i-1-start)
                start = i

            if i == (len(arr) - 1):
                ret.append(i - start)
    return ret

N = int(input())
S = input().split()
arr = list(map(int, list(S)))

ret = max(calculate(arr,N))
print(ret)

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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)

template <typename T>
T gcd( T a, T b )
{
    if( b == 0 ) return a;
    else return gcd( b, a % b );
}


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

    long long ans = 0;
    FOR(a, 1, K+1){
        FOR(b, 1, K+1){
            FOR(c, 1, K+1){
                int tmp = gcd(a, b);
                ans += gcd(tmp, c);
            }
        }
    }
    cout << ans << endl;

    

    return 0;
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;

int main(){
    ll n; cin >> n;
    ll ans = 0;
    if (n%2 == 1){
        cout << 0 << endl;
        return 0;
    }else{
        bool conti = true;
        ll dividing_num = 10;
        while(conti){
            if(n / dividing_num != 0){
                ans += n / dividing_num;
                dividing_num = dividing_num * 5;
            }else{
                conti = false;
            }
        }
        cout << ans << endl;
        return 0;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
long long N;
cin>>N;
long long counter=0;
long long a[N]={};
long long b[N]={};
long long c[N]={};
long long d[N]={};
long long countera=0;
for(long long i=0;i<N;i++){
cin>>a[i];}
for(long long i=0;i<N;i++){
cin>>b[i];}
for(long long i=0;i<N;i++){
counter+=a[i];
c[i]=counter;}
counter=0;
for(long long i=0;i<N;i++){
counter+=b[N-1-i];
d[N-1-i]=counter;}
counter=0;
for(long long i=0;i<N;i++){
counter=c[i]+d[i];
countera=max(counter,countera);
}
cout<<countera<<endl;}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace CsharpSpiral {
	partial class Program {
		//https://qiita.com/NotFounds/items/7b166af69a6f52a332de
		static void Main(string[] args) {
            var sw = new StreamWriter( Console.OpenStandardOutput() ) { AutoFlush = false };
            Console.SetOut( sw );
            new Program().Solve(new ConsoleInput(Console.In,' '));
            Console.Out.Flush();
        }
		public void Solve(ConsoleInput cin) {
            var N = cin.ReadInt;
            var A = cin.ReadIntArray( N );
            var flag = true;
            var count = 0;
            while (flag) {
                flag = false;
                for (int i = N - 2; i >= 0; i--) {
                    if (A[i] > A[i + 1]) {
                        A.Swap( i, i + 1 );
                        count++;
                        flag = true;
                    }
                }
            }
            Console.WriteLine(A.Join());
            Console.WriteLine(count);
		}
	}

    static class ExtendClass {
        public static void Swap<T>(this T[] X, int i, int j) {
            T tmp = X[i];
            X[i] = X[j];
            X[j] = tmp;
        }
        public static string Join<T> (this T[] X, string separator = " ") => string.Join( separator, X);
    }

    class ConsoleInput {
        private readonly TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(TextReader stream, char separator = ' ') {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read {
            get {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split( _separator );
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue( tmp[i] );
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse( Read ); } }
        public long ReadLong { get { return long.Parse( Read ); } }
        public double ReadDouble { get { return double.Parse( Read ); } }
        public string[] ReadStrArray(long N) {
            var ret = new string[N];
            for (long i = 0; i < N; ++i)
                ret[i] = Read;
            return ret;
        }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}



Measured memory_bytes: 18456
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n;
ll cl(ll n){
    ll ans=0;
    if(!(n&1)) n++,ans=n;
    ll num=(n+1ll)/2ll;
    if(num&1) ans^=1;
    return ans;
}
int main(){
    ll l,r;cin>>l>>r;
    cout<<(cl(l-1)^cl(r));
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
#define MAX 250
    int s; //学籍番号
    double w, h; //体重、身長

    while(scanf("%d, %lf, %lf", &s, &w, &h) != EOF){
        //int count = 0; //測定した人数
        /*for(int i = 0; i < 50; i++){
            scanf("%d, %lf, %lf", &s[i], &w[i], &h[i]);
            count++;
        }*/

    double bmi; //BMI
    bmi = w / pow(h, 2);
    if(bmi >= 25)
        cout << s << endl;
    }
}


Measured memory_bytes: 3104
#include <iostream>
#include <cmath>

using namespace std;

int main(int argc, char const *argv[])
{
    string s;
    string sample = "01";
    cin >> s;

    int counter1 = 0;
    int counter2 = 0;

    for(int i = 0; i < s.length(); i++){
        if(s[i] != sample[i%2]) counter1++;
        if(s[i] != sample[(i+1)%2]) counter2++;
    }

    int ans = (counter1 < counter2) ? counter1 : counter2;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

// ナップサックdp
int main() {
    int n;
    ll W;
    cin >> n >> W;
    vector<ll> weight(n+1);
    vector<ll> value(n+1);

    weight[0] = 0;
    value[0] = 0;

    for(int i=1; i<n+1; i++){
        cin >> weight[i] >> value[i];
    }

    vector<vector<ll> > dp(n+1, vector<ll>(W+1));
    for(int i=0; i<=W; i++){
        dp[0][i] = 0;
    }

    for(int i=0; i<n; i++){
        for(ll w=0; w<=W; w++){
            if(w >= weight[i+1]){
                dp[i+1][w] = max(dp[i][w-weight[i+1]] + value[i+1], dp[i][w]);
            }else{
                dp[i+1][w] = max(dp[i][w], dp[i+1][w]);
            }
        }
    }

    cout << dp[n][W] << endl;

    return 0;
}

Measured memory_bytes: 80256
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

fn main() {
    input! {
        n: usize,
    }
    let mut f = vec![0usize; n + 1];
    for i in 1..=n {
        for j in (i..=n).step_by(i) {
            f[j] += 1;
        }
    }
    let mut result = 0;
    for i in 1..=n {
        result += i * f[i];
    }
    println!("{}", result);
}


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

int main()
{
    int N, K;
    bool flag[10] = {};

    cin >> N >> K;

    for(int i = 0; i < K; i++) {
        int g;
        cin >> g;
        flag[g] = true;
    }

    for(int i = N; i <= 99999; i++) {
        int val = i;
        bool f = false;

        while(val) {
            if(flag[val % 10]) f = true;
            val /= 10;
        }

        if(!f) {
            cout << i << endl;
            break;
        }
    }

    return (0);
}


Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))
INF = 10^9

ans = [INF] * N
ans[0] = 0
ans[1] = abs(H[1] - H[0])

for i in range(2, N):
	ans[i] = min(ans[i-1] + abs(H[i] - H[i-1]), ans[i-2] + abs(H[i] - H[i-2]))

print(ans[N-1])

Measured memory_bytes: 13980
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+50;
int c[N][3];
int dp[N][3];
int main()
{
     int n;
     cin>>n;
     for(int i=0;i<n;i++){
        cin>>c[i][0]>>c[i][1]>>c[i][2];
     }
     int ans=max(c[0][0],max(c[0][1],c[0][2]));
     dp[0][0]=c[0][0],dp[0][1]=c[0][1],dp[0][2]=c[0][2];
     for(int i=1;i<n;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(j!=k){
                    dp[i][j]=max(dp[i-1][k]+c[i][j],dp[i][j]);
                }
            }
            ans=max(ans,dp[i][j]);
        }
     }
     cout<<ans;
}


Measured memory_bytes: 2560
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 105;
const int mod = 1000000007;

int n,a[maxn], b[maxn];
int f[1<<18][51];

void pd(int&ret, int val){
  if(ret==-1||ret>val)ret=val;
}

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<n;i++)cin>>b[i];
  memset(f,-1,sizeof(f));
  f[0][0] = 0;
  for(int i=0;i<(1<<n)-1;i++){
    vector<int>tt;
    for(int j=0;j<n;j++)if(!(i&(1<<j)))tt.push_back(j);
    for(int j=0;j<51;j++){
      if(f[i][j]==-1)continue;
      int cnt = 0, pre = n;
      for(int k=tt.size()-1;k>=0;k--){
        cnt += pre - tt[k] - 1;
        pre = tt[k];
        int tmp = cnt + k;
        int val = (tmp&1)?b[tt[k]]:a[tt[k]];
        if(val>=j){
          pd(f[i|(1<<tt[k])][val],f[i][j]+k);
        }
      }
    }
  }
  int ret=-1;
  for(int i=1;i<=50;i++)if(f[(1<<n)-1][i]!=-1)pd(ret, f[(1<<n)-1][i]);
  cout<<ret<<endl;
  return 0;
}

Measured memory_bytes: 52608
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

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

ll modinv(ll x){
  return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
  if(was_output)cout << " ";
  cout << a;
  was_output = true;
}
void outendl(){
  was_output = false;
  cout << endl;
}
ll in(){
  ll res;
  scanf("%lld", &res);
  return res;
}

template<class t>
istream& operator>>(istream&is, vector<t>&x){
  for(auto &i:x)is >> i;
  return is;
}

template<class t, class u>
istream& operator>>(istream&is, pair<t, u>&x){
  is >> x.first >> x.second;
  return is;
}

template<class t>
void in(t&x){
  cin >> x;
}

template<class t>
void out(t x){
  cout << x;
}

int main(){
  double num = in();
  printf("%.20lf\n",pow(num/3,3));
  return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define mn(a, b) (a < b ? a : b)
#define mx(a, b) (a > b ? a : b)
#define f first
#define s second
#define all(v) (v).begin(), (v).end()
#define base 331

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int const MAXn = 1e5 + 2;

ll dp[MAXn];

int main(){

    //freopen(".in","r",stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, w;
    cin>>n>>w;
    for(int i = 1; i <= n; i++){
        ll p, b;
        cin>>p>>b;
        for(int i = w; i > p; i--){
            if(dp[i - p])
                dp[i] = mx(dp[i], dp[i - p] + b);
        }
        dp[p] = mx(dp[p], b);
    }
    ll sol = 0;
    for(int i = 1; i <= w; i++){
        sol = mx(dp[i], sol);
    }
    cout<<sol;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
char s[N] ;
int main() {
    scanf("%s", s + 1);
    int x1 = 0;
    for(int i = 1; i <= 2; i++) {
        x1 = x1 * 10 + (s[i] - '0') ;
    }
    int x2 = 0;
    for(int i = 3; i <= 4; i++) {
        x2 = x2 * 10 + (s[i] - '0') ;
    }
    if((x1 > 12 || x1 == 0) && x2 <= 12 && x2 > 0) puts("YYMM") ;
    else if(x1 <= 12 && x1 > 0 && (x2 > 12 || x2 == 0)) puts("MMYY") ;
    else if(x1 <= 12 && x2 <= 12 && x1 + x2 != 0) puts("AMBIGUOUS") ;
    else puts("NA");
    return 0;
}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    p = [0] * N
    for i in range(N):
        p[i] = int(input())

    p.sort()
    ans = sum(p[:-1]) + p[-1] // 2
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
 
  if (A + B > C + D) {
    cout << "Left" << endl;
  }
  else if(A + B == C + D){
      cout << "Balanced" << endl;
  }
  else cout << "Right" << endl;
}

Measured memory_bytes: 3572
N = int(input())
alp = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]

def dfs(s, n):
    if len(s) == N:
        print(s)
        return
    for i in range(n+1):
        dfs(s+alp[i], max(n, i+1))

dfs("", 0)

Measured memory_bytes: 9044
#include<bits/stdc++.h>
#include<climits>
 
using namespace std;
 
#define debug(x,y) cout<<(#x)<<" " <<(#y)<<" is " << (x) <<" "<< (y) << endl
#define watch(x) cout<<(#x)<<" is " << (x) << endl
#define fast ios_base::sync_with_stdio(false)
#define fie(i,a,b) for(i=a;i<b;i++)
#define MOD 1000000007
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define ll long long
#define lld long long int
#define ALL(x) (x).begin(),(x).end()
 
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<pair<int,int>> vpi;
 
const long long OO = 2e18;
const double pi=2*acos(0.0);
 
bool isprime(long long int a){
    if(a==1){
        return false;
    }
    for(int i=2;i*i<=a;i++){
        if(a%i==0){
            return false;
        }
    }
    return true;
} 

bool iscoprime(int a,int b){
    int i;
    for(i=2;i<=min(a,b);i++){
        if(a%i==0 && b%i==0){
            return false;
        }
    }
    return true;
}

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

int maxA(vi a){
    int m=0;
    for(int i=0;i<a.size();i++){
        m=max(m,a[i]);
    }
    return m;
}

int minA(vi a){
    int m=100000;
    for(int i=0;i<a.size();i++){
        m=min(m,a[i]);
    }
    return m;
}

vi freqN(vi a, int n){
    vi f(n);
    f={0};
    for(int i=0;i<a.size();i++){
        f[a[i]]++;
    }
    return f;
}

vi freqA(vi a){
    vi f(26);
    f={0};
    for(int i=0;i<a.size();i++){
        f[a[i]-'0']++;
    }
    return f;
}

bool mycomp(const pair<long int,long int>&p1 , const pair<long int,long int>&p2){
    if(p1.second < p2.second) return true;
    else if(p1.second==p2.second) return p1.first<p2.first;
    else return false;
}

unsigned int rightmostsetbit(unsigned int n){
    return n & -n;
}

bool cmp(pair<string,int>&p1 , pair<string,int>&p2){
    if(p1.second==p2.second) return p1.first<p2.first;
    return p1.second>p2.second;
}

int main(){
fast;
cin.tie(0);
lld n;
cin>>n;
string s,t;
cin>>s>>t;
for(lld i=0;i<n;i++){
    cout<<s[i]<<t[i];
}
cout<<endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << endl;
#else
#define DBG(X)
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const ll mod = 1e9 + 7;
const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }

const int MAX_N = 107;
bool m[MAX_N][MAX_N];
int n, k;

void solve()
{
	cin >> n >> k;
	int cnt = ((n - 1) * (n - 2)) / 2;

	if(k > cnt)
	{
		cout << "-1" << endl;
		return;
	}

	for(int v = 1; v < n; ++v)
		m[0][v] = m[v][0] = true;

	for(int v = 1; v < n; ++v)
		for(int u = 1; u < v; ++u)
			if(k < cnt)
				m[v][u] = m[u][v] = true, --cnt;

	vector<pii> answ;

	for(int v = 0; v < n; ++v)
		for(int u = 0; u < v; ++u)
			if(m[v][u])
				answ.emplace_back(v + 1, u + 1);

	cout << len(answ) << endl;

	for(auto ed: answ)
		cout << ed.first << " " << ed.second << endl;
}

int main()
{
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define ZERO (1e-10)
#define INF int(1e9+1)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define DEB printf("DEB!\n");
#define D(X) cout<<"  "<<#X": "<<X<<endl;
#define EQ(A,B) (A+ZERO>B&&A-ZERO<B)
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
#define IN(n) int n;scanf("%d",&n);
#define FOR(i, m, n) for (int i(m); i < n; i++)
#define F(n) FOR(i,0,n)
#define FF(n) FOR(j,0,n)
#define FT(m, n) FOR(k, m, n)
#define aa first
#define bb second
void ga(int N,int *A){F(N)scanf("%d",A+i);}
ll lcm(ll a,ll b){return  a/__gcd(a,b)*b;}
ll A,B,C,D;
ll bw(ll a){return B/a-(A-1)/a;}
int main(void){
    scanf("%lld%lld%lld%lld",&A,&B,&C,&D);
    printf("%lld\n",B-A+1-bw(C)-bw(D)+bw(lcm(C,D)));
    return 0;
}


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

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;

#define INF 1000000000

int memo[21][11][156];

// try to use from bigger number
int search(int n, int k, int s){
  if(memo[n][k][s]!=-1) return memo[n][k][s];

  if(k==1){
    if(n>=s) return 1;
    else return 0;
  }
  int res=0;
  for(int i=min(n,s-1); i>1; i--){
    // use i
    res += search(i-1, k-1, s-i);
  }
  memo[n][k][s]=res;
  return res;
}

int main(){
  rep(i,21) rep(j,11) rep(k,156) memo[i][j][k]=-1;

  int n,k,s;
  while(scanf("%d %d %d", &n, &k, &s), n|k|s){
    cout<<search(n,k,s)<<endl;
  }
  return 0;
}

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

using namespace std;

const int N = 1005;

int n, a[N][N], ans = 0, nxt[N], ptr[N];

int readInt(){
    char c;
    int ans = 0;
    while (1) {
        c = getchar();
        if (c == ' ' || c == '\n') return ans;
        ans = (ans << 3) + (ans << 1) + (c - '0');
    }
}

int main(){
    int n;
    n = readInt();
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n - 1; j++) {
            a[i][j] = readInt();
        }

        ptr[i] = 1;
    }

    while (1) {
        bool ok = true;
        if (ans >= 50000) return !printf("%d", n * (n - 1) / 2);
        for (int i = 1; i <= n; i++) {
            if (ptr[i] <= n - 1) {
                ok = false;
                break;
            }
        }

        if (ok) break;
        ans++;
        memset(nxt, 0, sizeof(nxt));
        //for (int i = 1; i <= n; i++) ptr2[i] = ptr[i];

        ok = true;
        for (int i = 1; i <= n; i++) {
            if (ptr[i] >= n) continue;
            int cur = a[i][ptr[i]];

            //cout << i << " " << cur << " " << ans << "\n";
            //if (nxt[cur] && nxt[cur] != i) continue;
            //if (nxt[i]) continue;
            if (nxt[i] || nxt[cur]) {
                //ptr[cur]++;
                continue;
            }

            if (ptr[cur] >= n) continue;
            if (a[cur][ptr[cur]] != i) continue;
            nxt[cur] = i; nxt[i] = cur;
            ptr[i]++; ptr[cur]++;
            ok = false;
        }

        if (ok) return !printf("%d", -1);
    }

    printf("%d", ans);
    return 0;
}


Measured memory_bytes: 4224
def resolve():
    import copy
    D = int(input())
    cost = list(map(int, input().split()))
    sat = [list((map(int, input().split()))) for _ in range(D)]
    last = [0]*26
    printnum = 1
    for i in range(D):
        if i % 20 != 0:
            print(printnum)
            printnum += 1
            if printnum == 27:
                printnum = 1
        else:
            maxcost = -float("INF")
            ans = 0
            for j in range(26):
                nowlast = copy.deepcopy(last)
                nowlast[j] = i+1
                plussat = sat[i][j]
                minussat = 0
                for k in range(26):
                    minussat += (i + 1 - nowlast[k]) * (cost[k])
                cum = plussat-minussat

                if maxcost < cum:
                    ans = j
                    maxcost = cum
            last[j] = i+1
            print(ans+1)
            printnum = ans + 2
            if printnum == 27:
                printnum = 1
resolve()

Measured memory_bytes: 70736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
 
ll N;
string S;
int main() {
    cin >> N;
    cin >> S;

    ll count = 0;
    for(int i=0; i<=N-3; i++) {
        if (S.substr(i, 3).compare("ABC") == 0) {
            count++;            
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
PY = [tuple(map(int,input().split())) for i in range(M)]

PY_sort = sorted(PY)

tmp = dict()

before = 0
for py in PY_sort:
    if before != py[0]:
        before = py[0]
        count = 0
    count += 1
    tmp[py] = count

for py in PY:
    print("{:06}{:06}".format(py[0],tmp[py]))

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

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

fn main() {
    let n:usize = read();
    let arr :Vec<(i64, i64)> = (0..n).map(|_| (read(), read())).collect();
    let mut cnt = 0.0;
    for i in 0..n {
        for j in 0..n {
            cnt += ((arr[i].0 - arr[j].0).pow(2) as f64 + (arr[i].1 - arr[j].1).pow(2) as f64).sqrt();
        }
    }
    println!("{}", cnt/n as f64);
}


Measured memory_bytes: 4352
#from collections import deque,defaultdict
from sys import stdin
input = stdin.readline
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

a,v = inm()
b,w = inm()
t = inn()
if (v-w)*t>=abs(a-b):
    print('YES')
else:
    print('NO')


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

int main(){
    int n;
    cin >> n;
    int MAX = -1, id = -1;
    rep(i, 1, n + 1){
        int d;
        cout << "? " << 1 << " " << i << endl;
        cout.flush();
        cin >> d;
        if(MAX < d){
            MAX = d;
            id = i;
        }
    }
    vector<int> a(n + 1, -1);
    a[0] = id;
    rep(i, 1, n + 1){
        int d;
        cout << "? " << id << " " << i << endl;
        cout.flush();
        cin >> d;
        a[d] = i;
    }
    cout << "!";
    rep(i, 0, n){
        cout << " " << a[i];
    }
    cout << endl;
    cout.flush();
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
void solve() {
	int n; cin >> n;
	int ans = -1;
	int cnt = 0;
	for (int i = 1; i <= n; ++i) {
		int tmp = 0;
		int num = i;
		while(num % 2 == 0) {
			num /= 2;
			tmp++;
		}
		if (cnt <= tmp) {
			ans = max(ans, i);
			cnt = max(cnt, tmp);
		}
	}
	cout << ans << endl;
	return;
}
int main() {
	solve();
	return 0;
}

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

const int mod = 1e9 + 7;

signed main() {
  int n;
  cin >> n;
  string s1, s2;
  cin >> s1 >> s2;
  vector<int> v;
  for (int i = 0; i < n;) {
    if (s1[i] == s2[i]) {
      v.push_back(1);
      i++;
    } else {
      v.push_back(2);
      i += 2;
    }
  }
  int ans = (v[0] == 1) ? 3 : 6;

  for (int i = 1; i < v.size(); i++) {
    if (v[i - 1] == 1)
      (ans *=2) %= mod;
    else if (v[i - 1] == 2 && v[i] == 1)
      continue;
    else if (v[i - 1] == 2 && v[i] == 2)
      (ans *=3) %= mod;
  }
  cout << ans << endl;
//  for (auto&& w : v) cout << w << " ";
}


Measured memory_bytes: 256