akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int h;
int w;
 
//to store matrix cell cordinates
struct Point
{
    int x;
    int y;
};
 
// An Data Structure for queue used in BFS
struct queueNode
{
    Point pt;  // The cordinates of a cell
    int dist;  // cell's distance of from the source
};
 
// check whether given cell (row, col) is a valid
// cell or not.
bool isValid(int row, int col)
{
    // return true if row number and column number
    // is in range
    return (row >= 0) && (row < h) &&
           (col >= 0) && (col < w);
}
 
// These arrays are used to get row and column
// numbers of 4 neighbours of a given cell
int rowNum[] = {-1, 0, 0, 1};
int colNum[] = {0, -1, 1, 0};
 
// function to find the shortest path between
// a given source cell to a destination cell.
int BFS(int mat[][50], Point src, Point dest)
{
    // check source and destination cell
    // of the matrix have value 1
    if (!mat[src.x][src.y] || !mat[dest.x][dest.y])
        return INT_MAX;
 
    bool visited[h][w];
    memset(visited, false, sizeof visited);
     
    // Mark the source cell as visited
    visited[src.x][src.y] = true;
 
    // Create a queue for BFS
    queue<queueNode> q;
     
    // distance of source cell is 0
    queueNode s = {src, 0};
    q.push(s);  // Enqueue source cell
 
    // Do a BFS starting from source cell
    while (!q.empty())
    {
        queueNode curr = q.front();
        Point pt = curr.pt;
 
        // If we have reached the destination cell,
        // we are done
        if (pt.x == dest.x && pt.y == dest.y)
            return curr.dist;
 
        // Otherwise dequeue the front cell in the queue
        // and enqueue its adjacent cells
        q.pop();
 
        for (int i = 0; i < 4; i++)
        {
            int row = pt.x + rowNum[i];
            int col = pt.y + colNum[i];
             
            // if adjacent cell is valid, has path and
            // not visited yet, enqueue it.
            if (isValid(row, col) && mat[row][col] && 
               !visited[row][col])
            {
                // mark cell as visited and enqueue it
                visited[row][col] = true;
                queueNode Adjcell = { {row, col},
                                      curr.dist + 1 };
                q.push(Adjcell);
            }
        }
    }
 
    //return -1 if destination cannot be reached
    return INT_MAX;
}
 
// Driver program to test above function
int main()
{
    cin>>h>>w;
    int a[50][50];
    string s[50];
    for(int i=0;i<h;i++)
        cin>>s[i];

    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            if(s[i][j]=='.')
                a[i][j]=1;
            else
                a[i][j]=0;
        }
    }
    int sum=0;
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            if(a[i][j]==1)
                sum+=1;
        }
    }
    Point source = {0, 0};
    Point dest = {h-1,w-1};
 
    int dist = BFS(a, source, dest);
 
    if (dist != INT_MAX)
        cout << sum-dist-1<<endl ;
    else
        cout <<-1<<endl;
 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;

int64_t mod = 998244353 ;

vector<int> getprime(int n){
    vector<int> p(0) ;
    vector<bool> table(n+1,0) ;
    for (int i = 2; i <= n; i++)
    {
        if (table.at(i) == 0)
        {
            p.push_back(i) ;
            for (size_t j = 2; j < n/i ; j++)
            {
                table.at(i*j) = 1 ;
            }
            
        }
        
    }
    return p ;
}

int main(){
    int h,w ;
    cin >> h >> w ;
    int ch,cw,dh,dw ;
    cin >> ch >> cw >> dh >> dw ;
    ch -- ; cw -- ; dh -- ; dw -- ;
    vector<vector<char> > maze(h,vector<char>(w)) ;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cin >> maze.at(i).at(j) ;
        }
        
    }
    int d[4][2] = {{0,1},{0,-1},{1,0},{-1,0}} ;

    vector<vector<int> > table(h,vector<int>(w,-1)) ;
    queue<pair<int,int> > wait ;
    queue<pair<int,int> > warpwait ;
    wait.push(make_pair(ch,cw)) ;
    table.at(ch).at(cw) = 0 ;
    pair<int,int> next ;
    while(!(wait.empty() & warpwait.empty()))
    {
        while(wait.empty() == 0){
            next =  wait.front() ;
            wait.pop() ;
            warpwait.push(next) ;
            pair<int,int> look ;
            for (int i = 0; i < 4; i++)
            {
                look.first = next.first + d[i][0] ;
                look.second = next.second + d[i][1] ;
                if (look.first >= 0 && look.first < h && look.second >= 0 && look.second < w)
                {
                    if (maze.at(look.first).at(look.second) == '.')
                    {
                        if (table.at(look.first).at(look.second) == -1)
                        {
                            table.at(look.first).at(look.second) =table.at(next.first).at(next.second) ;
                            wait.push(look) ;
                        }
                        
                    }
                    
                }
                
            }
        }
        while (warpwait.empty() == 0)
        {
            next =  warpwait.front() ;
            warpwait.pop() ;
            for (int i = max(next.first-2,0); i < min(next.first+3,h); i++)
            {
                for (int j = max(next.second-2,0); j < min(next.second+3,w); j++)
                {
                    if (maze.at(i).at(j) == '.')
                    {
                        if (table.at(i).at(j) == -1)
                        {
                            table.at(i).at(j) = table.at(next.first).at(next.second) +1 ;
                            wait.push(make_pair(i,j)) ;
                        }
                        
                    }
                    
                }
                
            }
            
        }
        
    }
    cout << table.at(dh).at(dw) << endl ;
}

Measured memory_bytes: 8640
#include <bits/stdc++.h>
using namespace std;
long long n,m,q,res=0,ans=0,p[11][11][51],a[11];
vector <int> f[11][11];
long long sol()
{
    long long s=0;
    //if (a[1]==1 && a[2]==3 && a[3]==4) cout<<f[1][2].size()<<endl;
    for (int i=1;i<=n;i++)
    for (int j=1;j<i;j++)
    for (int t=0;t<f[j][i].size();t++)
    if (a[i]-a[j]==f[j][i][t]) { s+=p[j][i][f[j][i][t]];  }
    return(s);
}
int dfs(int x, int y)
{
    for (int i=x;i<=m;i++)
    {
        a[y]=i;
        //if (a[i]==)
        if (y!=n) dfs(i,y+1);
        else
        { res=max(res,sol());  }
    }
    return(0);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
   
    cin>>n>>m>>q;
    for (int i=1;i<=q;i++) 
    {
        int a1,b,c,d;
        cin>>a1>>b>>c>>d;
        f[a1][b].push_back(c);
        p[a1][b][c]=d;
    }
    dfs(1,1);
    cout<<res;
}

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

int dp[1010][1010];

int main(){
    int q; cin >> q;
    rep(i,q){
        string x,y; cin >> x >> y;
        for(int i = 0; i < x.size(); i++){
            for(int j = 0; j < y.size(); j++){
                if(x[i]==y[j]) dp[i+1][j+1] = dp[i][j] + 1;
                else dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1]);
            }
        }
        cout << dp[x.size()][y.size()] << endl;
    } 
    return 0;
}


Measured memory_bytes: 7180
// 解き直し.
// https://img.atcoder.jp/arc065/editorial.pdf
// 以下のライブラリを使ってみる.
// 素集合データ構造(Union-Find)
// https://ei1333.github.io/luzhiled/snippets/structure/union-find.html
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define a first
#define b second
int ar[200001], br[200001];

struct UnionFind{

    vector<int> data;
    UnionFind(int sz){ data.assign(sz, -1); }
    
    // 頂点 x, y の 結合.
    bool unite(int x, int y){
        x = find(x), y = find(y);
        if(x == y)            return false;
        if(data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }
    
    // 頂点 k を 探索.
    int find(int k){
        if(data[k] < 0) return k;
        return data[k] = find(data[k]);
    }
    
    // 頂点 k を含む集合 の 大きさ.
    int size(int k){ return (-data[find(k)]); }
};

int main(){
    
    // 1. 入力情報.
    int N, K, L;
    int p, q;
    scanf("%d %d %d", &N, &K, &L);
    UnionFind ufc(N); // 道路で連結.
    UnionFind uft(N); // 鉄道で連結.
    
    // 2. 道路で連結している都市.
    rep(i, K){
        scanf("%d %d", &p, &q);
        ufc.unite(--p, --q);
    }
    
    // 3. 鉄道で連結している都市.
    rep(i, L){
        scanf("%d %d", &p, &q);
        uft.unite(--p, --q);
    }
    
    // 4. 各都市に, Union-Findでの根の都市番号を保存(道路, 鉄道).
    rep(i, N){
        ar[i] = ufc.find(i);
        br[i] = uft.find(i);
    }
    
    // 5. (ar[i], br[i]) の 出現回数を集計.
    map<P, int> m;
    rep(i, N) m[{ar[i], br[i]}]++;
    
    // 6. 各都市について, 5. で確認した出現回数を出力.
    rep(i, N) printf("%d ", m[{ar[i], br[i]}]);
    return 0;
    
}

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

using namespace std;

int main() {
   
   long long a,b;
   cin>>a>>b;
   
   set<long long>s;
   
   
   for(long long i=2;i*i<=a;i++){
       
       if(a%i == 0){
           
           while(a%i == 0){
               a=a/i;
           }
           
           bool flag=false;
           
           while(b%i == 0){
               b=b/i;
               flag=true;
           }
           
           if(flag){
               s.insert(i);
           }
           
       }
       
   }
   
   if(__gcd(a,b) != 1)
   s.insert(b);
   
   cout<<1+s.size();
   
   
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
int a[200005];
bool compare(int a,int b){
    return a>b;
}
int main(){
    ios::sync_with_stdio(0);
    int n,k,x;
    cin>>n>>k;
    memset(a,0,sizeof(a));
    for(int i=0;i<n;i++){
        cin>>x;
        a[x]++;
    }
    int ans=0;
    sort(a,a+n,compare);
    for(int j=k;j<=n;j++){
        ans+=a[j];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
A, B, C, X, Y = map(int, input().split())

x = y = z = 0

if 2 * C >= A + B:
    x = min(X, Y)
    y = x
else:
    z = min(X, Y) * 2

if X > Y :
    if A > 2 * C :
        z += (X - Y) * 2
    else :
        x += X - Y

elif X < Y :
    if B > 2 * C :
        z += (Y - X) * 2
    else :
        y += Y - X

print(A*x + B*y + C*z)

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

int main(){
  int n;std::cin >> n;
  std::vector<int> a(n);
  for (int i = 0; i < n; i++) {
    /* code */
    std::cin >> a[i];
  }
  int ans=0,tmp=1;
  for (int i = 0; i < n; i++) {
    /* code */
    tmp = a[tmp-1];
    ans++;
    if (tmp == 1) {
      std::cout << -1 << '\n';
      break;
    }
    else if (tmp == 2) {
      std::cout << ans << '\n';
      break;
    }
    if (i==n-1) {
      std::cout << -1 << '\n';
    }
  }
}


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

int main(){
    const long long MODULO = (1e9) + 7;
    long long n;
    cin >> n;

    vector<long long> dp(n + 1, 0);
    if(n >= 3){
        dp[3] = 1;
        for(int i = 4; i <= n; ++i){
            dp[i] = 1;
            for(int j = 3; j + 3 <= i; ++j){
                dp[i] = (dp[i] + dp[j]) % MODULO;
            }
        }
    }

    cout << dp[n];
    
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <queue>

using namespace std;

int main(){

    int N, K;
    cin >> N >> K;
    vector<int> V(N);

    for(int i = 0; i < N; i++){
        cin >> V[i];
    }

    long long ans = -1e10;

    for(int ope = 0; ope <= K; ope++){
        for(int l = 0; l <= min(N, ope); l++){
            for(int r = 0; r <= min(N, ope); r++){
                if(l + r > min(N, ope)){
                    break;
                }

                int rest = ope - l - r;
                if(rest > l + r){
                    continue;
                }

                priority_queue<int> q;
                for(int i = 0; i < l; i++){
                    q.push(V[i]);
                }
                for(int i = 0; i < r; i++){
                    q.push(V[N - 1 - i]);
                }

                long long value = 0;
                int loop = l + r - rest;
                for(int i = 0; i < loop; i++){
                    value += q.top();
                    q.pop();
                }

                ans = max(ans, value);
            }
        }
    }

    cout << ans << endl;

    return 0;
}

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

typedef long long ll;

using namespace std;

int main() {
    int n;
    string target = "MARCH";
    vector<ll> p(5);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        for (int j = 0; j < 5; ++j) if (s.front() == target.at(j)) ++p.at(j);
    }
    ll ans = 0;
    for (int i = 0; i < 3; ++i) {
        for (int j = i + 1; j < 4; ++j) {
            for (int k = j + 1; k < 5; ++k) ans += p.at(i) * p.at(j) * p.at(k);
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main() {

  int N;
  cin >> N;
  
  vector<int> X(N);
  for(int i = 0; i < N; i++) {
    cin >> X.at(i);
  }
  
  sort(X.begin(), X.end());
  for(int i = 0; i < N; i++) {
  }

  int L, ans = 0;
  
  for(int i = X.at(0); i <= X.at(N-1); i++) {
    L = 0;
    
    for(int j = 0; j < N;j++) {
      L += (X.at(j)-i)*(X.at(j)-i);
    if(i == X.at(0) && j == N-1) ans = L; 
    }
    
    if(i > X.at(0) && L < ans) ans = L;
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ppb pop_back
#define eb emplace_back
typedef long double ld;

int N, M, S, P, A[105];

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N >> M;
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
		S += A[i];
	}
	for (int i = 1; i <= N; i++)
		if (A[i] * 4 * M >= S) P++;
	if (P >= M) cout << "Yes\n";
	else cout << "No\n";
}


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

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

   for(int i=0;i<s.length();i++){
      char a[1];
      if(s[i]+n <= 'Z') a[0]=s[i]+n;
      else a[0] =s[i]+n-26;
      cout << a[0];
   }
   cout << endl;
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int n,k;
    cin >> n >> k;
    vector<int> l(n);
    for(int i = 0; i < n; i++) cin >> l[i];
    sort(l.rbegin(), l.rend());
    int ans = 0;
    for(int i = 0; i < k; i++){
        ans += l[i];
    }
    cout << ans << endl;
    return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int maxn=1e6+5;
vector<ll> V;
int pre[maxn];
int has[maxn][10];
int main() {
	for(int i=1;i<maxn;i++)
		for(int j=0;j<10;j++)
			has[i][j]=has[i/10][j]|(i%10==j?1:0);
	int n,k;cin>>n>>k;
	for(int i=1;i<=k;i++) {
		int x;cin>>x;V.push_back(x);
	}
	for(int i=n;;i++) {
		bool ok=1;
		for(auto x:V) {
			if(has[i][x]) {ok=0;break;}
		}
		if(ok) return 0*printf("%d\n",i);
	}    
    return 0;
}

Measured memory_bytes: 42820
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define fore(x, a) for(auto &x : a)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};

string s, t;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> s >> t;
    int n = s.size(), m = t.size();
    eper(i, n-m, 0) {
      bool flag = true;
      rep(j, i, i+m) {
        if (s[j] == t[j-i] || s[j] == '?') continue;
        flag = false; 
        break;
      }
      if (flag) {
        rep(j, i, i+m) s[j] = t[j-i];
        rep(k, 0, n) {
          if (s[k] == '?') s[k] = 'a';
        }
        cout << s << endl;
        return 0;
      }
    }
    cout << "UNRESTORABLE" << endl;
    return 0;
}



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


class Main{

    public static void main(String args[])throws IOException{
    int i, j;
    int a;
    int n;
    int v;
    int count = 0;
    int nodeNum;
    int[][] G = new int[105][105];
    int[] mCost = new int[105];
    boolean[] u = new boolean[105];
    Scanner scan = new Scanner(System.in);

    n = scan.nextInt();
    for(i=0 ; i<n ; i++){
        for(j=0 ; j<n ; j++){
        G[i][j]=5000000;
        }
    }
    //BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    //String s;

    for(i=0 ; i<n ; i++){
        nodeNum = scan.nextInt();
        //s = bf.readLine();
        //nodeNum = Integer.parseInt(s);
        a = scan.nextInt();
        for(j=0 ; j<a ; j++){
          G[nodeNum][scan.nextInt()] = scan.nextInt();
        }
    }

    for(i=0 ; i<n ; i++){
        mCost[i] = 999999;
        u[i] = false;
    }

    mCost[0] = 0;

    while(true){
        v = -1;

        for(i=0 ; i<n ; i++){
          if( !u[i] && (v == -1 || mCost[i] < mCost[v]) ){
              v = i;
          }
        }

        if(v == -1){break;}
        u[v] = true;
        count += mCost[v];

        for(i=0 ; i<n ; i++){
          mCost[i] = Math.min(mCost[i], G[v][i] + mCost[v]);
        }
    }

    for(i=0 ; i<n ; i++){
      System.out.println(i + " " + mCost[i]);
    }
    }
}



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

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

    if (a == 0 && b == 0) {
        cout << a << " " << b << endl;
        return 0;
    }

    if (k > a)
        b = b - (k - a);

    if (k > a)
        a = 0;
    else
        a = a - k;

    if (a < 0) a = 0;
    if (b < 0) b = 0;

    cout << a << " " << b << endl;
    return 0;
}

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

int main(){
  long long S, a, r, mod = 1000000000;
  cin >> S;
  r = (mod - S % mod) % mod;
  a = (r + S) / 1000000000;

  cout << "0 0 1 1000000000 " << a << ' ' << r << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        int[] an = Console.ReadLine().Split(' ').Select(e => int.Parse(e)).ToArray();

        long sum = 0;
        long cs1 = 0;
        int t = 1;
        for (int i = 0; i < n; i++)
        {
            sum += an[i];
            if (sum * t <= 0)
            {
                long tmp = Math.Abs(sum - t);
                sum = t;
                cs1 += tmp;
            }
            t *= -1;
        }

        long cs2 = 0;
        t = -1;
        sum = 0;
        for (int i = 0; i < n; i++)
        {
            sum += an[i];
            if (sum * t <= 0)
            {
                long tmp = Math.Abs(sum - t);
                sum = t;
                cs2 += tmp;
            }
            t *= -1;
        }

        Console.WriteLine(Math.Min(cs1, cs2));
    }
}

Measured memory_bytes: 29916
#!/usr/bin/env python
from collections import defaultdict, deque
import math
from math import factorial
import fractions
import re

BIGNUM = 10 ** 9 + 7

def main():
    A, B = map(int, input().split())

    if A == B:
        print(1)
        return
    AB = A + B
    if AB % 2 == 0:
        print(AB // 2)
    else:
        print("IMPOSSIBLE")

if __name__ == '__main__':
    main()


Measured memory_bytes: 5228
s = input()
mmyy = (1 <= int(s[:2]) <= 12)
yymm = (1 <= int(s[2:]) <= 12)
if mmyy:
  if yymm:
    print('AMBIGUOUS')
  else:
    print('MMYY')
else:
  if yymm:
    print('YYMM')
  else:
    print('NA')

Measured memory_bytes: 9096
def resolve():
    s = input()
    dict = {}
    k = 0
    for i in s:
        if i in dict:
            dict[i].append(k)
        else:
            dict[i] =[k]
        k += 1

    ans = 10**3
    for i in dict:
        test = dict[i]
        ans1 = test[0]
        for j in range(1,len(test)):
            ans1 = max(ans1, test[j]-test[j-1]-1)
        ans1 = max(ans1, (len(s)-test[-1]-1))
        ans = min(ans1,ans)
    print(ans)
resolve()

Measured memory_bytes: 62020
####### 再起関数
def dfs(i, f):
    if i == n - 1:
        return sum(list(map(int, f.split("+"))))

    # 式 f の末尾に "+" を追加するかしないかして次の数字を追加
    return dfs(i + 1, f + s[i + 1]) + dfs(i + 1, f + "+" + s[i + 1])


s = input()
n = len(s)

print(dfs(0, s[0]))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<ll,ll>
#define poly vector<ll>
#define mem(a) memset((a),0,sizeof(a))
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x.size()))
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=505,X[4]={0,0,1,-1},Y[4]={1,-1,0,0};
int ans,a[N][N],b[N][N];
pair<int,int> p[N*N];
void dfs(int x,int y){
	a[x][y]--;
	//cout<<x<<" "<<y<<" "<<a[x][y]<<endl; if(x*y<=0||y>4)exit(0);
	For(i,0,3){
		int xx=x+X[i],yy=y+Y[i];
		if(a[xx][yy]==a[x][y]+b[xx][yy]+1)dfs(xx,yy);
	}
}
int main(){
	#ifdef Brollan
		freopen("1.in","r",stdin);
	#endif
	int n=read();
	For(i,1,n){
		For(j,1,n){
			a[i][j]=min(min(i,j),min(n-i,n-j)+1); b[i][j]=1;
		}
	}
	For(i,1,n*n){
		int p=read();
		int x=(p+n-1)/n,y=p-(x-1)*n;
		b[x][y]--;
		dfs(x,y);
		ans+=a[x][y];
		//puts("zhu");
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 24884
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,A,i;cin>>N;
  for(i=0;i<N;i++){
    cin>>A;if(A==1)break;
  }
  if(i==N)cout<<"-1"<<endl;
  else{
    int X=2;
    while(i<N){
      i++;cin>>A;
      if(A==X)X++;
    }
    cout<<N-X+1<<endl;
  }
}

Measured memory_bytes: 256
using System;
public class Hello{
    public static void Main(){
        int n = int.Parse(Console.ReadLine());
        string[] input = Console.ReadLine().Split(' ');
        int d = int.Parse(input[0]);
        int x = int.Parse(input[1]);
        int ans = 0;
        
        for(int i = 0;i < n;i++){
            int a = int.Parse(Console.ReadLine());
            if(d % a == 0){
                ans += d / a;
            }else{
                ans += d / a + 1;
            }
        }
        ans += x;
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define msg(a) cout << #a << "= " << a << " ";
typedef long long ll;
typedef vector<vector<ll>> vv;
typedef pair<ll, ll> P;

int main(){
	ll n,m;
	cin >> n >> m;
	vector<P> ab;
	rep(i,n){
		ll a,b;
		cin >> a >> b;
		ab.push_back(make_pair(a,b));
	}
	
	sort(ab.begin(), ab.end(), [&](P aa, P bb){return aa.first < bb.first;});
	
	ll res = 0;
	
	rep(i,ab.size()){
		ll a = ab[i].first;
		ll b = ab[i].second;
		if(b <= m){
			res += a*b;
			m -= b;
		}
		else{
			res += (m)*a;
			break;
		}
		
		if(m<=0) break;
	}
	
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
const int n_max = 1e5+10;
set<int> g[n_max];
set<int> used;
bool tot_ok = true;

void dfs(int cv, int pv){
  // cout << cv << " " << pv << endl;
  bool ok = false;
  for(auto &nv : g[cv]){
    if(nv == pv) continue;
    dfs(nv,cv);
    if(used.count(cv)==1){
      ok = true;
    }
  }
  if(!ok){
    if(used.count(pv)==0){
      ok = true;
      used.insert(cv);
      used.insert(pv);
    }
  }

  if(!ok){
    tot_ok = false;
  }

}


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

  int n;
  cin >> n;

  rep(i,n-1){
    int a,b;
    cin >> a >> b;
    --a;--b;
    g[a].insert(b);
    g[b].insert(a);
  }
  used.insert(-1);
  dfs(0,-1);

  if(!tot_ok){
    cout << "First" << endl;
    return 0;
  }

cout << "Second" << endl;

  return 0;
    

}


Measured memory_bytes: 19072
#include <stdio.h>
#include <string.h>

#define LEN 100000

typedef struct pp {
  char name[10];
  int ms;
} pc;

int head,tail,n;
pc Q[LEN];

void enqueue(pc x)
{
  Q[tail]=x;
  tail=(tail+1)%LEN;
}

pc dequeue()
{
  pc x=Q[head];
  head=(head+1)%LEN;
  return x;
}

int min(int a,int b)
{
  return (a<b?a:b);  //????°?????????????
    }

int main()
{
  int i,q,cms,elaps=0;
  pc a;

  scanf("%d %d",&n,&q);
  for(i=1;i<=n;i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].ms);
  }
  head=1;
  tail=n+1;

  while(head!=tail){
    a=dequeue();
    cms=min(q,a.ms);

    a.ms-=cms;  //??????????¨????
    elaps+=cms; //??????????¨????
    
    if(a.ms>0) enqueue(a);
    else{
      printf("%s %d\n",a.name,elaps);
    }
  }
  return 0;
}

Measured memory_bytes: 2160
#include <iostream>

using namespace std;

int main(int argc, char *argv[]) {
	long x;
	cin >> x;
	long ans = (x / 11) * 2;
	if (x % 11 > 0) ans++;
	if (x % 11 > 6) ans++;
	cout << ans << endl;
	return 0;
}


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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cout << #x << " = " << (x) << endl;
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

ll N,M,H,W,K,A,B;
string S;
//Write From this Line
int x[10], y[10];

double dist(int i, int j){
	double dx = x[i] - x[j];
	double dy = y[i] - y[j];
	return pow(dx*dx +dy*dy ,0.5);
}

int main()
{
	cout << setprecision(10);
	cin >> N;
	for(int i = 1 ; i<= N; i++) cin >> x[i] >> y[i];
	double ans = 0.0;
	for(int i = 1 ; i<= N; i++){
		for(int j = i + 1 ; j <= N ; j++) ans += dist(i,j) * 2 / N ;
	}
	cout << fixed << setprecision(10) << ans << endl;
	//まだ理解してない

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll x;
  ll a=100;
  cin>>x;
  int count=0;
  while(x>a){
    a=a+a*0.01;
    count++;
  }
  cout<<count<<'\n';
  return(0);
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define INF 10007

int main()
{
	//freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    int x;
    cin >> x;
    if(x==0)
    {
    	cout << 1 << "\n";
    }else
    {
    	cout << 0 << "\n";
    }
}


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

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



Measured memory_bytes: 3072
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <limits>

using namespace std;
typedef long long int ll;
void sayYes() { cout << "Yes" << endl; };
void sayNo() { cout << "No" << endl; };
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }                   // 最大公約数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); };                      // 最小公倍数
ll getDigit(ll num) { return log10(num) + 1; }                         // 桁数
ll digitSum(ll n) { return (n < 10) ? n : digitSum(n / 10) + n % 10; } // 各桁の和
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repn(i, n) for (ll i = 1; i <= n; i++)

void Main()
{
    // int n;
    // cin >> n;
    // vector<int> a(n);
    // rep(i, n)
    // {
    //     cin >> a[i];
    // }
    int n, k;
    cin >> n >> k;
    set<int> a;

    rep(i, k)
    {
        int d;
        cin >> d;

        rep(j, d)
        {
            int tmp;
            cin >> tmp;
            a.insert(tmp);
        }
    }

    cout << n - a.size() << endl;
    return;
}

signed main(void)
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

#define lld long long
#define pi pair<int,int>
#define pl pair<lld,lld>
#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())

int H,W,K;
char mas[10][10];
char mas_tmp[10][10];

bool check(int h,int w,char mas[10][10]){
    for (int i = 0; i < H; i++) {
        if(h&1){
            for (int j = 0; j < W; j++) {
                mas[i][j] = '.';
            }
        }
        h >>= 1;
    }
    for (int i = 0; i < W; i++) {
        if(w&1){
            for (int j = 0; j < H; j++) {
                mas[j][i] = '.';
            }
        }
        w >>= 1;
    }
    int cnt = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if(mas[i][j] == '#'){
                cnt++;
            }
        }
    }
    return (cnt == K);
}

int main() {
    cin >> H >> W >> K;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> mas[i][j];
        }
    }
    int ans = 0;
    for (int i = 0; i < (1<<H); i++) {
        for (int j = 0; j < (1<<W); j++) {
            for (int k = 0; k < H; k++) {
                for (int l = 0; l < W; l++) {
                    mas_tmp[k][l] = mas[k][l];
                }
            }
            if(check(i,j,mas_tmp)){
                ans++;
            }
        }
    }
    cout << ans << endl;
}

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

using namespace std;

int main()
{
  string s,t;
  cin >> s >> t;
  
  for(int i = 0; i < s.size();i++)
  {
    if(s[i] != t[i])
       {
         cout << "No";
         return 0;
       }
  }
       cout << "Yes";
       return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////



void fir(){
    cout<<"First"<<endl;
}
void sec(){
    cout<<"Second"<<endl;
}
 
ll gcd(ll a,ll b){
    if(a>b)swap(a,b);
    if(a==0)return b;
    return gcd(b%a,a);
}

int main(){fastio
    ll n;cin>>n;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    
    ll count=0;
    while(1){
        ll evc=0;
        bool one=false;
        rep(i,0,n-1){
            if(a[i]%2==0)evc++;
            if(a[i]==1)one=true;
        }
        if(one){
            ll sum=count;
            rep(i,0,n-1){
                sum+=a[i]-1;
            }
            if(sum%2==0)sec();
            else fir();
            return 0;
        }
        if(evc%2==1){
            if(count%2==0)fir();
            else sec();
            return 0;
        }else{
            if(n-evc>=2){
                if(count%2==0)sec();
                else fir();
                return 0;
            }
            count++;
            rep(i,0,n-1){
                if(a[i]%2==1)a[i]--;
            }
            ll g=a[0];
            rep(i,1,n-1)g=gcd(g,a[i]);
            rep(i,0,n-1)a[i]/=g;
        }
    }
    return 0;
}


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

using namespace std;

const int OO=INT_MAX;
int main()
{
    vector<int>v(12);
   int n,m,k,x,a[13][13],sum[15]={},cost=0,ans=OO;
   cin>>n>>m>>k;
   for(int i=0;i<n;i++)
   {
      cin>>v[i];
      for(int j=0;j<m;j++)
        cin>>a[i][j];
   }
        for(int i=0;i<(1<<n);i++)
        {
            memset(sum,0,sizeof(sum));
            cost=0;
            for(int j=0;j<n;j++)
            {
                if((i>>j) &1){
                    cost+=v[j];
                    for(int u=0;u<m;u++)
                        sum[u]+=a[j][u];
                }
            }
            bool C=true;
            for(int v=0;v<m;v++)
                if(sum[v]<k)
                    C=false;
            if(C)
                ans=min(ans,cost);
        }
        if(ans==OO)
            cout<<-1;
        else
        cout<<ans;
}


Measured memory_bytes: 3616
n, m = list(map(int, input().split()))
heights = list(map(int, input().split()))
roads = {}
for x in range(m):
    road = list(map(int, input().split()))
    if road[0] not in roads.keys():
        roads[road[0]] = []
    if road[1] not in roads.keys():
        roads[road[1]] = []
    roads[road[0]].append(road[1])
    roads[road[1]].append(road[0])
g = 0
flag = False
for y in range(1, n+1):
    if y not in roads.keys() or len(roads[y]) == 0:
        g += 1
        pass
    else:
        for z in roads[y]:
            if heights[z - 1] >= heights[y - 1]:
                flag = True
                break
        if flag:
            flag = False
            continue
        else:
            g += 1
print(g)


Measured memory_bytes: 31832
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A;
  int B;
  cin >> A >> B;
  int C = 0;
  C = A + B;
  if (C == 3) {
   cout << "3" << endl;
  } else if (C ==4) {
   cout << "2" << endl;
  } else {
   cout << "1" << endl;
  }
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;


void solve() {
    int X; cin >> X;
    int cnt = 0;
    int angle = 0;
    cnt++;
    angle += X;
    while (angle % 360 != 0) {
        angle += X;
        cnt++;
    }
    cout << cnt << endl;
}


int main() {
    solve();
    return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(void){
    string s;
    string keywords[4] = {"dream","dreamer","erase","eraser"};

    cin >> s;

    reverse(s.begin(),s.end());
    for (int i=0;i<4;i++){
        reverse(keywords[i].begin(),keywords[i].end());
    }

    int pos=0;
    bool isDivideAll = true;
    bool isDivide = false;
    while ( pos < s.size() ){
        bool isDivide = false;
        for (int i=0;i<4;i++){
            string keyword = keywords[i];
            if (s.substr(pos,keyword.size()) == keyword){
                // keywordとマッチ
                isDivide=true;
                pos += keyword.size();
            }
        }
        if (!isDivide){
            isDivideAll=false;
            break;
        }
    }
    if (isDivideAll){
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}


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

bool is_integer( double x ){
  return floor(x)==x;
}

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

    for(int i = 1; i <= N; i++){
       int sum = 0;
       for(int j = 1; j < sqrt(i); j++){
           for(int k = 1; k < sqrt((i - pow(j, 2) - j - 1)) ; k++){
               double sq = sqrt( pow((k+j), 2) + 4*(i - pow(j, 2) - pow(k, 2) - k*j) );
               if(!is_integer(sq)){
                  continue; 
               }
               int la = (-(k+j)+sq)/2, lb = (-(k+j)-sq)/2;
               if(j >= k && k >= la && la >= 1){
                   if(j == k && k == la && la == j){
                     sum += 1;
                   }else if(j == k || k == la || la == j){
                     sum += 3;
                   }else{
                     sum += 6;
                   }
                }
                if(j >= k && k >= lb && lb >= 1){
                   if(j == k && k == lb && lb == j){
                     sum += 1;
                   }else if(j == k || k == lb || lb == j){
                     sum += 3;
                   }else{
                     sum += 6;
                   }
                }
           }
       }
       cout << sum << endl;
    }
}


Measured memory_bytes: 3560
n = int(input())

a = []
b = []
for i in range(n):
    x,y = map(int,input().split())
    a.append(x)
    b.append(y)

ans = 0
for i in range(n-1,-1,-1):
    if (a[i]+ans)%b[i] == 0:
        pass
    elif a[i] + ans > b[i]:
        ans += b[i]-((a[i]+ans)%b[i])
    else:
        ans += b[i]-(a[i]+ans)  
print(ans)


Measured memory_bytes: 16964
import bisect
import sys

input = sys.stdin.readline
num2alpha = lambda c: chr(c + 97)
alpha2num = lambda c: ord(c) - ord("a")


class SegTreeMax:
    def __init__(self, l):
        self.N = 1
        while self.N < l:
            self.N *= 2
        self.L = [0 for _ in range(self.N * 2 - 1)]

    def append(self, k, v):
        k += self.N - 1
        self.L[k] += 2 ** v
        while k > 0:
            k = (k - 1) // 2
            self.L[k] = self.L[k * 2 + 1] | self.L[k * 2 + 2]

    def delete(self, k, v):
        k += self.N - 1
        self.L[k] -= 2 ** v
        while k > 0:
            k = (k - 1) // 2
            self.L[k] = self.L[k * 2 + 1] | self.L[k * 2 + 2]

    def query(self, a, b):
        return self.inquiry(0, self.N, 0, a, b)

    def inquiry(self, l, r, k, a, b):
        if r <= a or l >= b:
            return 0
        if a <= l and b >= r:
            return self.L[k]
        vl = self.inquiry(l, (l + r) // 2, k * 2 + 1, a, b)
        vr = self.inquiry((l + r) // 2, r, k * 2 + 2, a, b)
        return vl | vr


def main():
    N = int(input())
    S = input()
    L = []
    for c in S:
        L.append(c)
    Q = int(input())
    T = SegTreeMax(N)
    for i in range(N):
        T.append(i, alpha2num(L[i]))

    for _ in range(Q):
        a, b, c = input().split()
        if a == "1":
            i = int(b) - 1
            T.delete(i, alpha2num(L[i]))
            L[i] = c
            T.append(i, alpha2num(c))

        else:
            l = int(b) - 1
            r = int(c)
            res = T.query(l, r)
            p = 0
            for i in range(26):
                p += res & 1
                res >>= 1
            print(p)


main()


Measured memory_bytes: 117424
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N, K;
ll A[100010], B[100010];

bool contain(int a, int b) {
  for (int i = 0; i < 30; i++) {
    if (!(a >> i & 1) && (b >> i & 1)) return false;
  }
  return true;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
  }
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    if (contain(K, A[i])) ans += B[i];
  }
  for (int i = 0; i < 30; i++) {
    if (!(K >> i & 1)) continue;
    int K2 = (1 << i) - 1;
    for (int j = i+1; j < 30; j++) {
      K2 += ((K >> j & 1) << j);
    }
    ll sum = 0;
    for (int j = 0; j < N; j++) {
      if (contain(K2, A[j])) sum += B[j];
    }
    ans = max(ans, sum);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int x,y;
        
        while(true){
            x = scanner.nextInt();
            y = scanner.nextInt();
            
            if(x == 0 && y ==0){
                break;
            }
            if(x < y){
                System.out.println(x + " " + y);
            }else{
                System.out.println(y + " " + x);
            }
        }
    }
}


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

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

signed main(){
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    
    int lcm = C * D / gcd(C, D);
    cout << (B - A + 1) - (B / C - (A - 1) / C) - (B / D - (A - 1) / D) + (B / lcm - (A - 1) / lcm) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll LLINF = (ll)1e18;
const ll INTINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) { if (flg) { cout << hoge << endl; exit(0); } }
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) { o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o; }
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; }
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) { o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o; }
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) { o << "{" << obj.first << ", " << obj.second << "}"; return o; }
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; }
void print(void) { cout << endl; }
template <class Head> void print(Head&& head) { cout << head; print(); }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head << " "; print(forward<Tail>(tail)...); }
template <class T> void chmax(T& a, const T b) { a = max<T>(a, b); }
template <class T> void chmin(T& a, const T b) { a = min<T>(a, b); }
void YN(bool flg) { cout << ((flg) ? "YES" : "NO") << endl; }
void Yn(bool flg) { cout << ((flg) ? "Yes" : "No") << endl; }
void yn(bool flg) { cout << ((flg) ? "yes" : "no") << endl; }

int main() {
	ll N, K; cin >> N >> K;
	V<ll> A(N); REP(i, N) cin >> A[i];
	V<ll> bit(60,0),bitK(60,0);
	REP(i, N) REP(j, 60) if (A[i] & (1LL << j)) bit[j]++;

	
	ll ans = 0;
	REP(j, N) ans += (K^A[j]);

	for (ll i = 59; 0 <= i; --i) {
		if (!(K&(1LL << i))) continue;
		ll X = K;
		X ^= (1LL << i);
		for(ll j = i - 1; 0 <= j; --j){
			if (X & (1LL << j)) X ^= (1LL << j);
			if (bit[j] < N - bit[j]) X ^= (1LL << j);
		}
		ll sum = 0;
		REP(j, N) sum += (X^A[j]);
		chmax(ans, sum);
	}
	cout << ans << endl;

	return 0;
}


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


int main()
{
	int i, x;
	
	for (i = 1; i < 10001; i++)
	{

		cin >> x;
		if (x == 0)break;
		cout << "Case " << i << ": " << x << "\n";
		
	
	
	}
    return 0;
}




Measured memory_bytes: 3080
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn main() {
    let r: i32 = read();
    let g: i32 = read();

    println!("{}", 2 * g - r)
}


Measured memory_bytes: 4352
n = int(raw_input())
dp = {}

def fib(n):
    if n in dp: return dp[n]
    if n == 0:
        dp[n] = 1
        return 1
    elif n == 1:
        dp[n] = 1
        return 1
    else:
        dp[n] = fib(n-1)+fib(n-2)
        return dp[n]

print fib(n)

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

using namespace std;
const int mx = 64;
const int inf = 0x3f3f3f3f;

int l[mx*mx*mx];

int e(int a, int b, int c){
    return a << 12 | b << 6 | c;
}
int e(int a[3]){
    return e(a[0], a[1], a[2]);
}
void d(int x, int a[3]){
    a[0] = x & 63;
    a[1] = x >> 6 & 63;
    a[2] = x >> 12;
}
bool same(int x){
    int b[3];
    d(x, b);
    return b[0] == b[1] && b[1] == b[2];
}



int a[3];
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> a[0] >> a[1] >> a[2];
    sort(a,a+3);
    for(int i = 3; i--; ) a[i] -= a[0];
    memset(l,inf,sizeof(l));
    l[e(a)] = 0;
    queue<int> Q;
    Q.push(e(a));
    while(!Q.empty()){
        int f = Q.front(); Q.pop();
        if(same(f)){
            cout << l[f] << '\n';
            return 0;
        }
        d(f, a);
        int b[3];
        for(int i = 0; i < 3; i++){
            int flag = 0;
            for(int j = 0; j < 3; j++){
                b[j] = a[j] + 2 * (i == j);
                if(b[j] >= mx){
                    flag = 1;
                    break;
                }
            }
            if(flag) continue;
            int g = e(b);
            if(l[g] == inf){
                l[g] = l[f] + 1;
                Q.push(g);
            }
        }
        for(int i = 0; i < 3; i++){
            int flag = 0;
            for(int j = 0; j < 3; j++){
                b[j] = a[j] + (i != j);
                if(b[j] >= mx){
                    flag = 1;
                    break;
                }
            }
            if(flag) continue;
            int g = e(b);
            if(l[g] == inf){
                l[g] = l[f] + 1;
                Q.push(g);
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1280