akhauriyash/Code-Regression huggingface dataset:
import sys
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    MOD = 1000000007
    N, *AB = map(int, read().split())
    G = [[] for _ in range(N)]
    for a, b in zip(AB[::2], AB[1::2]):
        G[a - 1].append(b - 1)
        G[b - 1].append(a - 1)

    stack = deque([0])
    order = []
    prev = [0] * N
    prev[0] = -1
    while stack:
        v = stack.pop()
        order.append(v)
        for nv in G[v]:
            if nv != prev[v]:
                stack.append(nv)
                prev[nv] = v

    pow2 = [0] * (N + 1)
    pow2[0] = 1
    for i in range(N):
        pow2[i + 1] = pow2[i] * 2 % MOD

    nodes = [1] * N
    numer = 0

    for v in reversed(order):
        if prev[v] != -1:
            nodes[prev[v]] += nodes[v]
        numer = (numer + pow2[N - 1] - 1 - (pow2[N - nodes[v]] - 1)) % MOD
        for nv in G[v]:
            if nv != prev[v]:
                numer = (numer - (pow2[nodes[nv]] - 1)) % MOD

    denom = pow2[N]
    ans = (numer * pow(denom, MOD - 2, MOD)) % MOD
    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 128604
#ifdef OJ_MISC_OFFLINE

#include "prolog.h"

#else
#define PRINT
#define LCERR
#endif

#include <algorithm>
#include <array>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

namespace {

using namespace std;

class Solution {
public:
    int divide_the_problems(const vector<int>& tasks) {
        int N = tasks.size();
        int max_task = -1;
        for (int t : tasks) {
            max_task = max(max_task, t);
        }
        // find lower bound
        int lb = 0;
        int ub = max_task + 1;
        while(lb < ub) {
            int mid = lb + (ub - lb) / 2;
            int abc = num_abc(tasks, mid);
            if (abc >= N / 2) {
                ub = mid;
            } else {
                lb = mid + 1;
            }
        }
        int lower_bound_ = lb;
        PRINT("lowerb: {}\n", lower_bound_);

        // find upper bound
        lb = 0;
        ub = max_task + 1;
        while(lb < ub) {
            int mid = lb + (ub - lb) / 2;
            int abc = num_abc(tasks, mid);
            if (abc <= N / 2) {
                lb = mid + 1;
            } else {
                ub = mid;
            }
        }
        int upper_bound_ = lb;
        PRINT("upperb: {}\n", upper_bound_);
        return upper_bound_ - lower_bound_;
    }

private:
    int num_abc(const vector<int>& tasks, int k) {
        int result = 0;
        for (int t : tasks) {
            if (t < k) {
                result += 1;
            }
        }
        return result;
    }
};

int solve() {
    Solution solution;
    // handle IO here
    int N;
    cin >> N;
    vector<int> tasks;
    for (int i = 0; i < N; ++i) {
        tasks.emplace_back();
        cin >> tasks.back();
    }
    cout << solution.divide_the_problems(tasks) << endl;
    return 0;
}

} // anonymous namespace

#ifdef OJ_MISC_OFFLINE

#include "epilog.h"

#else

int main() {
    return solve();
}

#endif


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

int A[1000000], n;

int binarySearch(int key) {
  int left = 0;
  int right = n;
  int mid;

  while (left < right) {
    mid = (left + right) / 2;
    if (key == A[mid]) return 1;
    if (key > A[mid]) left = mid + 1;
    else if (key < A[mid]) right = mid;
  }

  return 0;

}


int main() {
  int q, k, sum = 0;

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

  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> k;
    if (binarySearch(k)) sum++;
  }

  cout << sum << endl;

  return 0;

}


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

string gyaku(string s){
  string n="";
  for(int i=0;i<s.size();i++){
    n=n+s[s.size()-i-1];
  }
  return n;
}


int main() {
  string S;cin>>S;
  int Q;cin>>Q;
  bool hanten=false;
  string B="",E="";
  for(int i=0;i<Q;i++){
    int T;cin>>T;
    if(T==1){
      hanten=!hanten;
    }else{
      int F;cin>>F;string C;cin>>C;
      if(F==1){
        if(hanten){
          E+=C;
        }else{
          B+=C;
        }
      }else{
        if(hanten){
          B+=C;
        }else{
          E+=C;
        }
      }
    }
  }
  if(hanten){
    S=gyaku(S);
    E=gyaku(E);
    S=E+S+B;
  }else{
    B=gyaku(B);
    S=B+S+E;
  }
  cout<<S<<endl;
}

Measured memory_bytes: 1688
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
    private static final PrintStream so = System.out;
    private static final Scanner     sc = new Scanner(System.in);

    public static void main(String[] args) {
        String s = sc.next();
        int len = s.length();
        long ans = 0;
        for (int i = 0; i < (1 << len-1); i++) { // (1 << 9) == 512
            ans += sumOf(s, i);
        }
        so.println(ans);
    }
    
    static long sumOf(String s, int bits) {
        long sum = 0;
        long temp = 0;
        for (int i = 0; i < s.length(); i++) {
            int digit = s.charAt(i) - '0';
            temp += digit;
            if (((bits >> i) & 1) == 1) {
                sum += temp;
                temp = 0;
            } else {
                if (i != s.length()-1) {
                    temp *= 10;
                }
            }
        }
        sum += temp;
        return sum;
    }
}


Measured memory_bytes: 21844
#include <iostream>
using namespace std;
int N, Q, S, T, L, R, X; long long d[200009], ret;
void change_d(int pos, int x) {
	if (pos < N) {
		if (d[pos] > 0) ret += 1LL * S * d[pos];
		if (d[pos] < 0) ret += 1LL * T * d[pos];
	}
	d[pos] += x;
	if (pos < N) {
		if (d[pos] > 0) ret -= 1LL * S * d[pos];
		if (d[pos] < 0) ret -= 1LL * T * d[pos];
	}
}
void change(int l, int r, int x) {
	change_d(l - 1, x);
	change_d(r - 1, -x);
}
int main() {
	ios::sync_with_stdio(false);
	cin >> N >> Q >> S >> T;
	for (int i = 0; i <= N; i++) {
		cin >> X;
		if (i >= 1) change(i, i + 1, X);
	}
	for (int i = 0; i < Q; i++) {
		cin >> L >> R >> X;
		change(L, R + 1, X);
		cout << ret << endl;
	}
	return 0;
}

Measured memory_bytes: 4764
#include<stdio.h>
int main(){
  int a,b,c,temp;
  scanf("%d%d",&a,&b);

  if(a < b){
    temp = a;
    a = b;
    b = temp;
}

  c = a % b;
  while(c != 0){
    a = b;
    b = c;
    c = a % b;
}
  printf("%d\n",b);
 
  return 0;
}

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

namespace ABC154
{
    class Program
    {
        // 1からnまでの期待値は中央値と同じになる
        static float CalcMedianValue(int maxValue)
        {
            return maxValue % 2 == 1 ? 
                        (float)(maxValue - (maxValue / 2)) :
                        (float)(maxValue - (maxValue / 2) + 0.5);
        }

        static void Main(string[] args)
        {
            var inputs = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var (n, k) = (inputs[0], inputs[1]);
            var maxValues = Console.ReadLine().Split(' ').Select(int.Parse);
            var expectedValues = maxValues.Select(CalcMedianValue).ToArray();

            double sum = Enumerable.Range(0, k).Sum(i => expectedValues[i]);
            var maxSumValue = sum;

            for (int i = 1; i <= n - k; i++) 
            {
                sum -= expectedValues[i - 1];
                sum += expectedValues[i + k - 1];
                if (maxSumValue < sum)
                {
                    maxSumValue = sum;
                }
            }

            Console.WriteLine($"{maxSumValue:F12}");
        }
    }
}


Measured memory_bytes: 41520
import java.util.Scanner;
public class Main{
    public static void main(String[]args){
        Scanner scan=new Scanner(System.in);
    int slotA=scan.nextInt();
    int slotB=scan.nextInt();
    int slotC=scan.nextInt();
    System.out.println(slotA*slotB/2);
    }
}


Measured memory_bytes: 27056
#include <iostream>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#define int long long
using namespace std;
signed main() {
    int W,a,b;
    cin>>W>>a>>b;

    if(a==b){
        cout<<0<<endl;
    }
    else if(a<b){
        if(b-a-W>=0){
            cout<<b-a-W<<endl;
        }
        else{
            cout<<0<<endl;
        }
    }
    if(a>b){
        if(b+W>=a){
            cout<<0<<endl;
        }
        else{
            cout<<a-(b+W)<<endl;
        }
    }
}


Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

#define INF 1e9
#define LLINF 1e18
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;


int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> sum(n + 1);
    ll allsum = 0;
    ll ans = LLINF;
    rep(i, n) {
        cin >> a.at(i);
        sum.at(i + 1) += sum.at(i) + a.at(i);
        allsum += a.at(i);
    }
    for (int i = 1; i < n; i++) {
        ans = min(ans, abs(allsum - sum.at(i) - sum.at(i)));
    }
    cout << ans << endl;
}

Measured memory_bytes: 3456
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
using ll = long long;

int main(){
    ll n; std::cin >> n;
    std::cout << n*(n-1)/2;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iterator>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>

using namespace std;

#define dump(n) cerr<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int MOD=100000007;

int main()
{
	vi dp3(100001),dp5(100001);
	repi(i,1,dp3.size()){
		rep(j,3) if(i-1-j>=0) dp3[i]+=dp3[i-1-j];
		rep(j,5) if(i-1-j>=0) dp5[i]+=dp5[i-1-j];
		dp3[i]=(dp3[i]+1)%MOD;
		dp5[i]=(dp5[i]+1)%MOD;
	}
	for(string s;cin>>s,s!="#";){
		ll res=1;
		for(int i=0,j;i<s.size();i=j){
			for(j=i;j<s.size() && s[j]==s[i];j++)
				;
			if(s[i]=='0' || s[i]=='8')
				res=(res*dp3[j-i])%MOD;
			else
				res=(res*dp5[j-i])%MOD;
		}
		cout<<res<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
n = int(input())
xy = [[int(item) for item in input().split()] for _ in range(n)]

# If mod2 changes, there are no answer
mod2 = (xy[0][0] + xy[0][1]) % 2
for x, y in xy:
    if (x + y) % 2 != mod2:
        print(-1)
        exit()

if mod2 == 1:
    print(31)
    print(" ".join([str(2**item) for item in range(31)]))
else:
    print(32)
    print("1 " + " ".join([str(2**item) for item in range(31)]))

for x, y in xy:
    if mod2 == 0:
        x -= 1
        print("R", end="")
    u = x + y
    v = x - y
    bits = [[0] * 31 for _ in range(2)]
    if u < 0:
        bits[0] = [1] * 31
        bits[0][30] = 0
    else:
        bits[0][30] = 1
    if v < 0:
        bits[1] = [1] * 31
        bits[1][30] = 0
    else:
        bits[1][30] = 1
    for i in range(30):
        if u >= 0 and abs(u)//2>>i & 1:
            bits[0][i] = 1
        if u < 0 and abs(u)//2>>i & 1:
            bits[0][i] = 0
        if v >= 0 and abs(v)//2>>i & 1:
            bits[1][i] = 1
        if v < 0 and abs(v)//2>>i & 1:
            bits[1][i] = 0
    for u_b, v_b in zip(bits[0], bits[1]):
        if u_b == 1 and v_b == 1:
            print("R", end="")
        elif u_b == 0 and v_b == 0:
            print("L", end="")
        elif u_b == 1 and v_b == 0:
            print("U", end="")
        elif u_b == 0 and v_b == 1:
            print("D", end="")
    print("")


Measured memory_bytes: 4624
#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct Edge{ll from, to, cost;};
struct node{ll cost, to;
  bool friend operator>(node a, node b){
    return a.cost>b.cost;
  }
};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

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

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

ll N, M;
llvec p;
llvec cnt;
llvec a, b;

ll root(ll a){
  ll atmp = a;
  while(atmp!=p[atmp]){
    atmp = p[atmp];
  }
  return atmp;
}

bool con(ll a, ll b){
  ll ar = root(a);
  ll br = root(b);
  if(ar!=br){
    p[ar]=br;
    //cnt[br]+=cnt[ar];
  }
}

/**************************************
** A main function starts from here  **
***************************************/
int main(){
  cin >> N >> M;
  a = llvec(M);
  b = llvec(M);
  rep(i, M){
    cin >>a[i] >> b[i];
    a[i]--;b[i]--;
  }

  ll ans = 0;
  rep(i, M){
    p = llvec(N);
    rep(j, N)p[j]=j;
    rep(j, M){
      if(i==j)continue;
      con(a[j], b[j]);
    }
    if(root(a[i])!=root(b[i]))ans++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
main () {
    int n, a[200001], num = 1, count = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);

    for (int i = 0; i < n; i++)
    {
        if (a[i] == num) num++;
        else count++;
    }

    if (num == 1) puts("-1");
    else printf("%d\n", count);
}


Measured memory_bytes: 896
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

int main()
{
    int t[5];
    for (auto& ti : t)
        cin >> ti;

    auto total = 0;
    for (auto ti : t)
        total += (ti + 9) / 10 * 10;
    auto mx = 0;
    for (auto ti : t) {
        auto rem = (10 - ti % 10) % 10;
        mx = max(mx, rem);
    }
    cout << (total - mx) << endl;
    return 0;
}


Measured memory_bytes: 3584
from collections import Counter
from sys import stdin

n = int(stdin.readline())
a = sorted(map(int, stdin.readline().split()))

c = Counter(a)

to_remove = n - len(list(c.keys()))

if to_remove % 2 == 0:
    print(n - to_remove)
else:
    print(n - to_remove - 1)


Measured memory_bytes: 18720
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define pb push_back
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005
#define x1 nibab
#define y1 kebab

ll x,y,t;

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> x >> y;
    while(x<=y){
        t++;
        x*=2;
    }
    cout << t;
}


Measured memory_bytes: 764
from itertools import product

S=input()
x,y=map(int,input().split())
L=[len(i) for i in S.split("T")]

X={L[0]}
Y={0}
for i in L[2::2]:
    X={j+k for j,k in product(X,[-i,i])}
for i in L[1::2]:
    Y={j+k for j,k in product(Y,[-i,i])}

if x in X and y in Y:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 4056
// https://atcoder.jp/contests/abc177/tasks/abc177_e
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

const int SZ = 1e7;

// constexprな素数列挙(エラトステネスの篩)
// https://259-momone.hatenablog.com/entry/2018/05/06/015026
template <int N> struct Prime {
    bool b[N + 1]; // trueなら素数
    constexpr Prime() : b() {
        fill_n(b, N + 1, true);
        b[0] = b[1] = false;
        for (int i = 2; i <= N; ++i) {
            if (b[i]) {
                for (int j = i * i; j <= N; j += i) {
                    b[j] = false;
                }
            }
        }
    }
};
Prime<SZ> prime;

void solve() {
    int N;
    cin >> N;
    vector<int> A(N), D(SZ + 1);
    for (auto &x : A) {
        cin >> x;
        // 同じ数が重複するケースを考慮
        D[x]++;
    }
    // trueなら "pairwise coprime"
    bool pc = true;

    REP(i, SZ) {
        // 素数の場合
        if (prime.b[i]) {
            int cnt = 0;
            for (int now = i; now <= SZ; now += i) {
                cnt += D[now];
            }
            // 共通の素数を含むのでgcd(ALL) >= i
            if (cnt >= 2) {
                pc = false;
                break;
            }
        }
    }
    if (pc) {
        cout << "pairwise coprime" << endl;
    } else {
        int g = A[0];
        for (auto &x : A) {
            g = gcd(g, x);
        }
        if (g == 1)
            cout << "setwise coprime" << endl;
        else
            cout << "not coprime" << endl;
    }
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define el cout << "\n"
#define pb push_back
#define f first
#define s second
#define arrondi(a) (long long)floor(a+0.5);
#define NIL -1
ll N=500005;
ll MAX=9223372036854775807;
ll MOD=1000000007;
long double PI =4*atan(1);

int main()
{
	IOS;
    cout.precision(30);
    string s;
    int n; cin >> n;
    cin >> s;
    int W_tot=0,E_tot=0;
    for (int i=0;i<n;i++) W_tot+=(s[i]=='W'),E_tot+=(s[i]=='E');
    int W=0,E=0; int ans=1e6;
    for (int i=0;i<n;i++)
    {
        ans=min(ans,E_tot-E-(s[i]=='E')+W);
        W+=(s[i]=='W');
        E+=(s[i]=='E');
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 720
/*
 * Author : Andrew J
*/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
using ll = long long;
void in(ll &x);
typedef pair <ll , ll> ii;
// const ll N = ;
set <ll> s;
ll n;

bool valid(ll k) {
   ll tmp = n;
   while (tmp >= k) {
      if (tmp % k == 0) {
         tmp /= k;
      } else {
         tmp %= k;
      }
   }
   return tmp == 1;
}

void solve() {
   ll bf = n - 1;
   s.insert(bf);
   for (ll i = 2 ; i * i <= bf ; i++) {
      if (bf % i == 0) {
         if (bf / i == i) {
            if (valid(i)) s.insert(i);
         } else {
            if (valid(bf / i)) s.insert(bf / i);
            if (valid(i)) s.insert(i);
         }
      }
   }
   s.insert(n);
   for (ll i = 2 ; i * i <= n ; i++) {
      if (n % i == 0) {
         if (n / i == i) {
            if (valid(i)) s.insert(i);
         } else {
            if (valid(n / i)) s.insert(n / i);
            if (valid(i)) s.insert(i);
         }
      }
   }
}

int main() {
   in(n);
   if (n == 2) {
      puts("1");
      return 0;
   }
   solve();
   printf("%lu\n" , s.size());
   return 0;
}

void in(ll &x){
	bool neg = false;
	register ll c;
	x = 0;
	c = getchar();
	if(c == '-'){
		neg = true;
		c = getchar();
	}
	for (; c > 47 && c < 58; c = getchar())
	x = (x << 1) + (x << 3) + c - 48;
	if (neg) x *= -1;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    long a, b;
    scan(a, b);
    auto d = gcd(a, b);

    long[] divs;
    for (long i = 2; i * i < d; i++) {
        if (d % i == 0) {
            divs ~= i;
            while (d % i == 0) d /= i;
        }
    }
    if (d > 1) divs ~= d;

    auto ans = divs.length.to!int + 1;
    writeln(ans);
}






void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


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

const int MAXM = 1005;

int N, M, a[MAXM], b[MAXM], c[MAXM], ci, dp[1 << 12];
int main(){
	scanf("%d %d", &N, &M);
	
	for(int mask = 0; mask < (1 << N); mask++){
		if(mask == 0)dp[mask] = 0;
		else dp[mask] = 1 << 25;
	}
	
	for(int i = 0; i < M; i++){
		scanf("%d %d", &a[i], &b[i]);
		
		for(int j = 0; j < b[i]; j++){
			scanf("%d", &ci);
			c[i] |= 1 << (ci - 1);
		}
		
		for(int mask = (1 << N) - 1; mask >= 0; mask--)
			dp[mask] = min(dp[mask], dp[mask & (~c[i])] + a[i]);
	}
	
	if(dp[(1 << N) - 1] == (1 << 25))printf("-1\n");
	else printf("%d\n", dp[(1 << N) - 1]);
	
	return 0;
}


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

int main() {
  int n, t, a, ans = 0;
  cin >> n >> t >> a;
  double tmp = 1e9;
  for (int i = 0; i < n; i++) {
    double h;
    cin >> h;
    if (abs(t - h * 0.006 - a) < tmp) {
      ans = i + 1;
      tmp = abs(t - h * 0.006 - a);
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
  int a,b,c,d,e;
  cin>>a>>b>>c>>d>>e;
 if(a <= 40) a=40;
 if(b <= 40) b=40;
 if(c <= 40) c=40;
 if(d <= 40) d=40;
 if(e <= 40) e=40;
  cout<<(a+b+c+d+e)/5<<endl;
  return 0;
 }



Measured memory_bytes: 3096
from sys import stdin
input = stdin.readline


def main():
  S = input()[:-1]
  pre = 'R'
  r_cnt = 1
  l_cnt = 0
  l_pre = -1
  C = [0]*(len(S))
  for i in range(1, len(S)):
    now = S[i]
    if pre == 'R' and now == 'R':
      r_cnt += 1
    elif pre == 'R' and now == 'L':
      C[i-1] = r_cnt
      r_cnt = 0
      l_pre = i
      l_cnt = 1
    elif pre == 'L' and now == 'L':
      l_cnt += 1

    if (pre == 'L' and now == 'R') or (i == len(S)-1):
      C[l_pre] = l_cnt
      l_cnt = 0
      r_cnt = 1
      ave = int((C[l_pre] + C[l_pre-1]) / 2)
      if (C[l_pre] + C[l_pre-1]) % 2 == 0:
        C[l_pre-1], C[l_pre] = ave, ave
      else:
        n_move = max(C[l_pre-1], C[l_pre]) - 1
        if n_move % 2 == 0:
          if C[l_pre-1] > C[l_pre]:
            C[l_pre-1], C[l_pre] = ave+1, ave
          else:
            C[l_pre-1], C[l_pre] = ave, ave+1
        else:
          if C[l_pre-1] > C[l_pre]:
            C[l_pre-1], C[l_pre] = ave, ave+1
          else:
            C[l_pre-1], C[l_pre] = ave+1, ave

    pre = now

  print(*C, sep=' ')


if(__name__ == '__main__'):
  main()


Measured memory_bytes: 73284
E, Y = map(int, input().split())
R = ''
if E==0:
	if 1868<=Y<=1911:
		R = 'M'+str(Y-1868+1)
	elif 1912<=Y<=1925:
		R = 'T'+str(Y-1912+1)
	elif 1926<=Y<=1988:
		R = 'S'+str(Y-1926+1)
	elif 1989<=Y<=2016:
		R = 'H'+str(Y-1989+1)
elif E==1:
	R = str(1868+Y-1)
elif E==2:
	R = str(1912+Y-1)
elif E==3:
	R = str(1926+Y-1)
elif E==4:
	R = str(1989+Y-1)
print(R)



Measured memory_bytes: 5596
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
    int n;
    int ac = 0;
    int wa = 0;
    int tle = 0;
    int re = 0;
    char s[100002][3];
    
    scanf("%d",&n);
    for(int i = 0; i < n; i++){
        scanf("%s",s[i]);
    }
    
    for(int i = 0; i < n; i++){
        if(s[i][0] == 'A') ac++;
        if(s[i][0] == 'W') wa++;
        if(s[i][0] == 'T') tle++;
        if(s[i][0] == 'R') re++;
    }
    
    printf("AC x %d\n",ac);
    printf("WA x %d\n",wa);
    printf("TLE x %d\n",tle);
    printf("RE x %d\n",re);
    return 0;
}


Measured memory_bytes: 2024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS                     \
    ios::sync_with_stdio(false);\
    cin.tie(0)

// *start on @date: 2020-08-02 16:20 

int main() 
{
    IOS;
    int x;
    cin>>x;
    if(x>=30)
    cout<<"Yes";
    else
    cout<<"No";
    return 0;
}

Measured memory_bytes: 3648
import sys
from operator import itemgetter

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    n = int(input())
    aa = list(map(int, input().split()))
    bb = list(map(int, input().split()))
    aaii = [[a, i] for i, a in enumerate(aa)]
    bbii = [[b, i] for i, b in enumerate(bb)]
    aaii.sort()
    bbii.sort()
    #print(aaii)
    #print(bbii)
    aibi = []
    swap = False
    for i in range(n):
        a, ai = aaii[i]
        b, bi = bbii[i]
        aibi.append([ai, bi])
        if a > b:
            print("No")
            exit()
        if swap: continue
        if i + 1 < n and aaii[i + 1][0] <= b:
            swap = True
    aibi.sort(key=itemgetter(1))
    #print(aibi)
    if swap:
        print("Yes")
        exit()
    now = 0
    cnt = 0
    while 1:
        now = aibi[now][0]
        cnt += 1
        if now == 0:
            if cnt == n:
                print("No")
            else:
                print("Yes")
            break

main()


Measured memory_bytes: 49524
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;

typedef long long int ll;
typedef pair<int,int> P;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
	char b;
	cin>>b;
	char ans;
	if(b=='A') ans = 'T';
	if(b=='T') ans = 'A';
	if(b=='C') ans = 'G';
	if(b=='G') ans = 'C';
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
package main
 
import (
  "fmt"
  "os"
  "bufio"
  "strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
    sc.Scan()
    i, e := strconv.Atoi(sc.Text())
    if e != nil {
        panic(e)
    }
    return i
}

func expectedValue(k int, sum int) float64 {
  var exp float64 = (float64(k) + float64(sum)) / 2.0
  return exp
}

func main() {
  sc.Split(bufio.ScanWords)
  n := nextInt()
  k := nextInt()
  a := make([]int, n)
  for i := range a {
    a[i] = nextInt()
  }
  
  sum, max := 0, 0
  for i := 0; i < k; i++ {
    sum += a[i]
  }
  max = sum
  
  //隣接するk個のサイコロの目が最大の時に期待値も最大となる
  for i := k; i < n; i++ {
    sum = sum - a[i-k] + a[i]
    if sum > max {
      max = sum
    }
  }
  fmt.Printf("%.12f\n", expectedValue(k, max))
}


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

int main()
{
	string s;
	cin >> s;
	int N = s.size();
	vector<int> used(26), mini(26, N);
	for (int i = 0; i < N; i++) {
		used[s[i] - 'a']++;
	}
	for (int i = 0; i < 26; i++) {
		if (used[i]) {
			int ma = 0;
			for (int j = N - 1, tmp = 1; j >= 0; j--, tmp++) {
				if (s[j] - 'a' == i) {
					tmp = 0;
				}
				ma = max(ma, tmp);
			}
			mini[i] = ma;
		}
	}
	int res = N;
	for (int i = 0; i < 26; i++) {
		res = min(res, mini[i]);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
n, s, q = int(input()), input(), int(input())

class SegmentTree:
    def __init__(self, n, func=lambda x, y: min(x, y), ide=float("inf")):
        self.n = 2 ** (n-1).bit_length()
        self.data = [ide] * (self.n*2)
        self.func, self.ide = func, ide
    
    def build(self, data):
        for i, x in enumerate(data):
            self.data[self.n+i] = x
        for i in range(self.n-1, 0, -1):
            self.data[i] = self.func(self.data[i*2], self.data[i*2+1])

    def update(self, i, x):
        i += self.n
        self.data[i] = x
        while i > 1:
            i //= 2
            self.data[i] = self.func(self.data[i*2], self.data[i*2+1])

    def query(self, l, r):
        l += self.n; r += self.n 
        res = self.ide
        while l < r:
            if l & 1:
                res = self.func(res, self.data[l])
                l += 1
            if r & 1:
                res = self.func(res, self.data[r-1])
            l //= 2; r //= 2
        return res
    
    def get(self, i):
        return self.data[self.n + i]

st = [SegmentTree(n, lambda x, y: x+y, 0) for _ in range(26)]
for i, c in enumerate(s): st[ord(c)-97].update(i, 1)

for _ in range(q):
    a, b, c = input().split()
    if a == "1":
        idx = int(b)-1
        for i in range(26):
            st[i].update(idx, 0)
        st[ord(c)-97].update(idx, 1)
    else:
        l, r = int(b)-1, int(c)
        res = 0
        for i in range(26):
            res += bool(st[i].query(l, r))
        print(res)


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

   typedef long long ll;
   typedef pair<ll, ll> Pii;
   typedef vector<ll> Vi;
   typedef vector<Vi> VVi;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define RSORT(x) sort((x).rbegin(), (x).rend())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   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; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}
   ll pow(ll a, ll b, ll m){if (b == 0) return 1; else if (a == 0) return 0; else if (b % 2 == 0) return (pow((a * a) % m, b / 2, m) % m); else return (pow((a * a) % m, b / 2, m) * a) % m;}
   ll residue(ll a, ll m){return ((a % m) + m) % m;};

   ll dx[4]={1,0,-1,0};
   ll dy[4]={0,1,0,-1};

int main(){
  ll n; cin >> n;
  Vi w(n); REP(i, n) cin >> w[i];
  Vi s(n + 1, 0); REP(i, n) s[i + 1] = s[i] + w[i];
  ll ans = INF;
  REP(i, n){
    chmin(ans, abs(s[i + 1] - (s[n] - s[i + 1])));
  }
  cout << ans << endl;
}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 100005;
int N, K;
int X[MAX_N];

signed main()
{
  cin >> N >> K;
  REP(i, N) {
    cin >> X[i];
  }

  int ans = INF_LL_MAX;
  REP(l, N-K+1) {
    int r = l+K-1;
    if(X[l] <= 0 && 0 <= X[r]) {
      ans = min(ans, min(abs(X[l])*2 + abs(X[r]), abs(X[l]) + abs(X[r])*2));
    } else {
      ans = min(ans, max(abs(X[l]), abs(X[r])));
    }
    // cerr << l << ": " << ans << endl;
  }

  cout << ans << endl;
}

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

int main(void)
{
	char str1[64], str2[64];
	int i,j=0;
	
	scanf("%s", str1);
	
	for (i = strlen(str1) - 1; i >= 0; i--){
		
		str2[j] = str1[i];
		
		j++;
	}
	str2[j] = '\0';
	
	printf("%s\n", str2);
	
	return (0);
}

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

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

    long long count = 0;
    while (true) {
        bool breakFlag = false;
        for (int i = 0; i < N; ++i) {
            if (a[i] % 2 == 0) {
                a[i] = a[i] / 2;
                ++count;
                break;
            }
            if (i == (N - 1)) breakFlag = true;
        }
        if (breakFlag) {
            break;
        }
    }
    

    cout << count << endl;
}


Measured memory_bytes: 384
/*input 
15 7
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9
*/ 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
#define ld double
#define pii pair<int,int>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=2e5+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e16;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
ll mult(ll a,ll b){
    return ((a%MOD)*(b%MOD))%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
int arr[maxn];
int32_t main(){
    ios::sync_with_stdio(false),cin.tie(0);
    int n,k;
    cin>>n>>k;
    REP(i,n) cin>>arr[i];
    for(int i=k;i<n;i++){
        if(arr[i]>arr[i-k]) cout<<"Yes\n";
        else cout<<"No\n";
    }
}


Measured memory_bytes: 4432
<?php
$input = STDIN;

$d = array();
foreach (range(1, 4) as $b) {
    foreach (range(1, 3) as $f) {
        $d[$b][$f] = array_fill(1, 10, 0);
    }
}

$n = (int) trim(fgets($input));

for ($i = 0; $i < $n; $i++) {
    list($b, $f, $r, $v) = array_map("intval", explode(' ', trim(fgets($input))));
    $d[$b][$f][$r] += $v;
}

$dlm = str_repeat('#', 20) . "\n";
foreach (array_slice($d, 0, 3) as $bldg) {
    foreach ($bldg as $flr) {
        print(' ' . implode(' ', $flr) . "\n");
    }
    print($dlm);
}

// last building
foreach ($d[4] as $flr) print(' ' . implode(' ', $flr) . "\n");



Measured memory_bytes: 9360
#include <bits/stdc++.h>
#define ll long long
#define p pair<int, int>
using namespace std;

int main() {
    int n;
    ll h;
    cin >> n >> h;
    vector<p> v;
    int ma = -1;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        v.push_back(p(b, a));
        ma = max(ma, a);
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (ma <= v[i].first) {
            h -= v[i].first;
            ans++;
        }
        if (ma > v[i].first || h <= 0) break;
    }
    if (h > 0) {
        ans += h / ma;
        if (h % ma != 0) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

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

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(mp(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define mp make_pair
#define pb push_back
#define INF (1 << 29)
const int mod = 1000000007;

int main() {
    ll N, cnt, maxv;
    string s;
    map<string, ll> m;
    cin >> N;
    for(ll i = 0; i < N; i++) {
        cin >> s;
        m[s] += 1;
    }

    maxv = 0;
    for(auto &x : m) {
        ll v = x.second;
        if(v > maxv)
            maxv = v;
    }

    for(auto it = m.begin(); it != m.end(); it++) {
        if(it->second == maxv) {
            cout << it->first << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 25216
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int MOD = 1e9 + 7;
using namespace std;

int fun(int idx,int n,string& s,string& t)
{
    int j = 0,cnt = 0;
    for(int i = idx;cnt < n;i++,cnt++)
    {
        //cout << i << ' ' <<idx <<'\n';
        if(s[i] != t[j++]) return 0;
        if(i+1 >= n) i = -1;
    }
    return 1;
}

int main()
{
    IOS
    string s,t;
    cin >> s >> t;
    int n = s.length();
    for(int i = 0;i<n;i++)
    {
        if(fun(i,n,s,t))
        {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

ll l[100];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    l[0] = 2;
    l[1] = 1;
    for (int i = 2; i <= n; ++i)
        l[i] = l[i - 1] + l[i - 2];
    cout << l[n];
}


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

typedef long long ll;
const int NMAX = 2e5 + 10;
const int MOD = 1e9 + 7;
ll a[NMAX],b[NMAX];
int main(int argc, char const *argv[])
{
	int n,m;
	ll k;
	scanf("%d%d%lld",&n,&m,&k);
	for(register int i = 1;i <= n;i++)
		scanf("%lld",a+i),a[i] += a[i-1];
	a[n+1] = 1e16;
	for(register int i = 1;i <= m;i++)
		scanf("%lld",b+i),b[i] += b[i-1];
	int ans = upper_bound(a+1,a+2+n,k) - a - 1;
	for(register int i = 1;i <= m && b[i] <= k;i++)
	{
		int now = upper_bound(a+1,a+2+n,k - b[i]) - a - 1;
		ans = max(ans,i + now);
	}
	printf("%d\n",ans );
	return 0;
}

Measured memory_bytes: 6968
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll a, b;
  cin >> a >> b;
  if (b % a == 0) cout << a + b << endl;
  else cout << b - a << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  int q;
  cin>>s>>q;
  deque<char> ans;
  for(auto tmp:s){
    ans.push_back(tmp);
  }
    int cnt=0;
  int left=0;
  int right=1;
  for(int i=0;i<q;i++){
    int x;
    cin>>x;
  
    if(x==1){
      swap(left,right);
      cnt++;
    }else{
      int y;
      char moji;
      cin>>y>>moji;
      if(y==1){
        if(left==0) ans.push_front(moji);
        else ans.push_back(moji);
      }else{
        if(right==1)ans.push_back(moji);
        else ans.push_front(moji);
      }
    }
  }
  if(cnt%2==0){
    while(!ans.empty()){
    cout<<ans.front();
    ans.pop_front();
    }
  }else{
    while(!ans.empty()){
    cout<<ans.back();
    ans.pop_back();
    }
  }

cout<<endl;
}

Measured memory_bytes: 896
// https://atcoder.jp/contests/dp/tasks/dp_b
#include <bits/stdc++.h>
using namespace std;

#define ALL(a)  (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 rrep(i,n)   for(int i=n-1;i<=0;--i)
#define repeq(i,n)   for(int i=0;i<=(n);++i)
#define loop        while(true)
typedef long long ll;
const ll INF = 1LL<<60;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll max_v = 100100;
const ll max_n = 110;
vector<ll> weight(max_n);
vector<ll> value(max_n);
vector<vector<ll>> dp(max_n,vector<ll>(max_v,INF));

int main() {
    // 入力
    ll N,W;cin>>N>>W;
    rep(i,N) cin >> weight.at(i) >> value.at(i);

    dp.at(0).at(0) = 0;
    rep(i,N) {
        rep(sum_v,max_v)
        {
            if( sum_v - value[i] >= 0) {
                chmin(dp.at(i+1).at(sum_v),dp.at(i).at(sum_v - value.at(i))+weight.at(i));
            }
            chmin(dp.at(i+1).at(sum_v),dp.at(i).at(sum_v));
        }
    }
    ll ans = 0;
    rep(v,max_v) {
        if( dp.at(N).at(v) <= W) ans = v;
    }
    cout << ans << endl;

    return 0;
}



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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descsort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int main(void)
{
    int x,y;
    cin>>x>>y;
    if(x==1&&y==1)cout<<1000000<<endl;
    else{
        int ans=0;
        if(x==3)ans+=100000;
        else if(x==2)ans+=200000;
        else if(x==1)ans+=300000;
        
        if(y==3)ans+=100000;
        else if(y==2)ans+=200000;
        else if(y==1)ans+=300000;
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 3608
#include <array>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <vector>
using namespace std;

template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }

constexpr int SIZE = 3;
enum {B, W, R, E};
const string str = "BWRE";

typedef pair<int, int> cube;
#define top first
#define south second

typedef array<array<cube, SIZE>, SIZE> state;

inline bool out(int x, int y) {
	return x < 0 || y < 0 || x >= SIZE || y >= SIZE;
}

inline unsigned long long encode(const state &s) {
	unsigned long long res = 0;
	for(int y = 0; y < SIZE; ++y) {
		for(int x = 0; x < SIZE; ++x) {
			res = (res << 4) | (s[y][x].top << 2) | s[y][x].south;
		}
	}
	return res;
}

inline state decode(unsigned long long code) {
	constexpr unsigned long long mask = 0x3;
	state res;

	for(int y = SIZE - 1; y >= 0; --y) {
		for(int x = SIZE - 1; x >= 0; --x) {
			res[y][x].south = (code & mask);
			code >>= 2;
			res[y][x].top = (code & mask);
			code >>= 2;
		}
	}

	return res;
}

inline int match(const state &a, const state &b) {
	int res = 0;

	for(int y = 0; y < SIZE; ++y) {
		for(int x = 0; x < SIZE; ++x) {
			if(a[y][x].top == b[y][x].top) ++res;
		}
	}

	return res;
}

int bfs(const state &start, const state &goal) {
	constexpr int dx[] = {-1, 0, 1, 0};
	constexpr int dy[] = {0, -1, 0, 1};

	queue<unsigned long long> que;
	unordered_map<unsigned long long, int> dist;

	const auto s_code = encode(start);

	que.push(s_code);
	dist[s_code] =  0;

	while(!que.empty()) {
		const auto code = que.front();
		que.pop();

		const state current = decode(code);
		const int c_dist = dist[code];

		const int rest = 9 - match(current, goal);
		if(rest == 0) return c_dist;
		if(c_dist + rest - 1 > 30) continue;

		int ex = -1, ey = -1;
		for(int y = 0; y < SIZE; ++y) {
			for(int x = 0; x < SIZE; ++x) {
				if(current[y][x].top == E) {
					ex = x;
					ey = y;
					goto unloop;
				}
			}
		}

	unloop:;

		for(int d = 0; d < 4; ++d) {
			const int nex = ex + dx[d];
			const int ney = ey + dy[d];

			if(out(nex, ney)) continue;

			state next(current);
			swap(next[ey][ex], next[ney][nex]);

			if(d & 1) { // vertical
				swap(next[ey][ex].top, next[ey][ex].south);
			}
			else { // horizontal
				next[ey][ex].top = B + W + R - next[ey][ex].top - next[ey][ex].south;
			}

			const auto n_code = encode(next);
			if(!dist.count(n_code)) {
				dist.insert({n_code, c_dist + 1});
				que.push(n_code);
			}
		}
	}

	return -1;
}

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

	int value[128];

	for(int i = 0; i < static_cast<int>(str.size()); ++i) {
		value[str[i]] = i;
	}

	for(int ex, ey; cin >> ex >> ey && ex;) {
		state start;
		for(int y = 0; y < SIZE; ++y) {
			for(int x = 0; x < SIZE; ++x) {
				start[y][x] = cube(W, R);
			}
		}
		start[ey - 1][ex - 1] = cube(E, E);

		state goal;
		for(auto &row : goal) {
			for(auto &e : row) {
				char c;
				cin >> c;
				e.top = value[c];
			}
		}

		cout << bfs(start, goal) << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 61000
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'


long long isprime(int x){

if(x==1){return false;}
if(x<2 ||x%2==0){return false;}

ll sqrtx = sqrt(x);
ll i = 3;



while(sqrtx<=x){
if(x%i==0) {return false;}
i+=2;
}
return true;
}



int main(){

ll n ;
cin>>n ;
ll m  = n ;
if(isprime(n)){
    cout<<1<<endl;
    return 0 ;
}

vector<pair<ll , int>> vi ;
for(ll i = 2 ; i*i<=m ; i++){
     int x = 0 ;
     while(n%i==0){
        n/=i ;
        x++;
     }
    vi.emplace_back(i , x);

}
if(n!=1)vi.emplace_back(n, 1);

 ll ans = 0 ;

 for(auto p : vi){
  int a = p.second ;
  int b = 1;
   while(b<=a){

      a-=b;
      b++;
      ans++;


   }
 }
 cout<<ans<<endl;
}


Measured memory_bytes: 19840
#include <stdio.h>
 
int main(){
    int n,x,count;
    while(true){
        scanf("%d %d",&n,&x);
        if(n == 0 && x == 0) break;
        count = 0;
        for(int min = 1; min < x/3 && min <= n-2;min++){
            for(int middle = min+1;middle < x - (min+middle) && middle <= n-1; middle++){
                if(x-(min+middle) <= n) count++;
            }
        }
        printf("%d\n",count);
    }
 
}


Measured memory_bytes: 2764