akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }


int main() {
    int n;
    string s;
    cin >> n >> s;
    
    int nn = sz(s);
    int l = 0, r = nn;
    while (1) {
        int mid = (l + r) / 2;
        // cout << l << " " << r << " " << mid << endl;
        
        vector<string> vs;
        vector<int> vc;
        
        int flg = 0;
        rep(i, nn) {
            string str;
            if (i + mid > nn) {
                break;
            }
            str = s.substr(i, mid);
            int it = lower_bound(all(vs), str) - vs.begin();
            // if (mid == 5 && i == 8) cout << it << endl;
            if (it == sz(vs) || vs[it] != str) { // 追加
                vs.insert(vs.begin() + it, str);
                vc.insert(vc.begin() + it, i);
            } else {
                if (vc[it] + mid <= i) {
                    flg = 1;
                    break;
                }
            }
        }
        
        // rep(i, sz(vs)) cout << vs[i] << " "; cout << endl;
        // rep(i, sz(vc)) cout << vc[i] << " "; cout << endl;
        // if (mid == 5) cout << flg << endl;
        if (flg == 0) {
            r = mid;
        } else {
            l = mid;
        }
        if (l + 1 == r) break;
    }
    // cout << l << " " << r << endl;
    cout << l << endl;
}


Measured memory_bytes: 6560
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
#include <list>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 10;

bool existPt[5001][5001];

bool validSuffix(int x) {
	return !(x < 0 || 5000 < x);
}

bool existPillar(pii a, pii b) {
	int dx = b.first - a.first, dy = b.second - a.second;
	if (validSuffix(a.first + dy) && validSuffix(a.second - dx) && validSuffix(b.first + dy) && validSuffix(b.second - dx)) {
		return existPt[a.first + dy][a.second - dx] && existPt[b.first + dy][b.second - dx];
	}
	else {
		return false;
	}
}

int area(pii a, pii b) {
	int dx = b.first - a.first, dy = b.second - a.second;
	return dx*dx + dy*dy;
}

int main() {
	int n;
	while (cin >> n, n) {
		memset(existPt, false, sizeof(existPt));
		int x, y;
		vector<pii> pts(n);
		REP(i, n) {
			cin >> x >> y;
			pts[i] = pii(x, y);
			existPt[x][y] = true;
		}

		int ans = 0;
		REP(i, n) {
			REP(j, n) {
				if (existPillar(pts[i], pts[j])) {
					ans = max(ans, area(pts[i], pts[j]));
				}
			}
		}

		cout << ans << endl;
	}
}

Measured memory_bytes: 25648
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int main(void) {
    Int N;

    cin>>N;

    cout<<((N-1)*(N))/2<<endl;

    return 0;
}





Measured memory_bytes: 384
N = int(input())
SP = [input().split() for _ in range(N)]

plist = []

spm = {}
for s, p in SP:
	plist += [int(p)]
	if not s in spm:
		spm[s] = [int(p)]
	else:
		spm[s] += [int(p)]

spl = []
for m in sorted(spm):
	for p in sorted(spm[m])[::-1]:
		spl += [p]

#print(spm)
#print(spl)
for p in spl:
	print(plist.index(p) + 1)


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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


int main()
{
  vector<string> s(3);
  rep(i, 3) cin >> s[i];
  string ans = "A";
  ans += s[1][0];
  ans += "C";
  cout << ans << endl;
}


Measured memory_bytes: 3604
#include <stdio.h>

int NumberOfAttacks(unsigned short H,unsigned short A)
{
    int number_of_attacks_required=0 ;
    
    if((H > 0) && (H <= 10000) && (A > 0) && (A <= 10000))
    {
        while((H > 0) && (H <= 10000))
        {
            H = H - A;
            number_of_attacks_required++;
        }
        return number_of_attacks_required;
    }
    else
    {
        return 0;
    }
}


int main()
{
    unsigned short a[2];
    scanf("%d %d", &a[0], &a[1]);
    printf("%d",NumberOfAttacks(a[0], a[1]));
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define repr(i,x,n) for(int i=x; i<(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define INF 1e9
typedef long long ll;
using VI = vector<int>;
using VB = vector<bool>;
using VS = vector<string>;
using graph = vector<vector<int>>;

int main()
{
VI ans(5);
for (int i = 0; i < 5; i++)
{
    cin>>ans.at(i);
    if (ans.at(i)==0)
    {
        cout<<i+1<<endl;
    }
    
}

    return 0;
}

Measured memory_bytes: 3628
H, W = map(int, input().split())
s = [input() for _ in range(H)]
case = [[1, 0], [-1, 0], [0, 1], [0, -1]]
flag = True

for i in range(H):
    for j in range(W):
        if s[i][j] == '#':
            flag = False
            for k in range(4):
                x, y = i+case[k][0], j+case[k][1]
                if x < 0 or x >= H or y < 0 or y >= W:
                    continue
                if s[x][y] == '#':
                    flag = True
                    break
            if not flag:
                break
    if not flag:
        break

print('Yes' if flag else 'No')


Measured memory_bytes: 3188
#include<iostream>
#include<cmath>
#include<map>

using namespace std;

int main(){

	string s;

	cin >> s;

	int y;

	y = 700;

	for(int i = 0;i < 3;i++){
		if(s[i] == 'o'){
			y += 100;
		}
	}

     cout << y;




    return 0;

}

Measured memory_bytes: 256
//Sinhov : "Hi stalker!"
#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>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mod 1000000007
int main() {
    ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
    ll n,m;
    cin>>n>>m;
    cout<<(n-1)*(m-1);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;
typedef long long ll;
int main()
{
   ll a ,b;
   cin>>a>>b;
   if((a*b)%2==0)
   	    puts("Even");
	else
		puts("Odd");
    return 0;
}

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

int d[6]={0};

int main(){
  int n;
  cin>>n;
  while(n--){
    double tmp;
    cin>>tmp;
    if(tmp<165.0)d[0]++;
    else if(tmp<170.0)d[1]++;
    else if(tmp<175.0)d[2]++;
    else if(tmp<180.0)d[3]++;
    else if(tmp<185.0)d[4]++;
    else d[5]++;
  }

  for(int i=0; i<6; i++){
    cout<<i+1<<":";
    for(int j=0; j<d[i]; j++)
      cout<<'*';
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1232
sa = list(input())
sb = list(input())
sc = list(input())

turn = "a"

while True:
    if turn == "a":
        if len(sa) == 0:
            ans = "A"
            break
        else:
            turn = sa.pop(0)
    elif turn == "b":
        if len(sb) == 0:
            ans = "B"
            break
        else:
            turn = sb.pop(0)
    elif turn == "c":
        if len(sc) == 0:
            ans = "C"
            break
        else:
            turn = sc.pop(0)

print(ans)

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

const int MAXN = 3010;
int A[MAXN], n;
int head[MAXN], nxt[MAXN << 1], to[MAXN << 1], tot;
void addedge(int b, int e) {
	nxt[++tot] = head[b]; to[head[b] = tot] = e;
	nxt[++tot] = head[e]; to[head[e] = tot] = b;
}
int dfs(int u, int fa = 0) {
	int f = 0;
	for (int i = head[u]; i; i = nxt[i])
		if (to[i] != fa && A[u] > A[to[i]])
			f |= dfs(to[i], u) == 0;
	return f;
}
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n;
	for (int i = 1; i <= n; ++i) std::cin >> A[i];
	for (int i = 1, t1, t2; i < n; ++i)
		std::cin >> t1 >> t2, addedge(t1, t2);
	int lst = false;
	for (int i = 1; i <= n; ++i) if (dfs(i)) {
		if (lst) std::cout << ' ';
		std::cout << i; lst = true;
	}
	std::cout << '\n';
	return 0;
}


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


using namespace std;

typedef long long ll;
const int MAXN = 2e5 + 5;
int tak,aok;
ll dt[MAXN],du[MAXN];
set<int> s;
vector<int> g[MAXN];
void bfs1(int u)
{
  queue<int> q;

  memset(dt,-1,sizeof(dt));
  q.push(u);
  dt[u] = 0;
  while(!q.empty())
  {
    int u = q.front();
    q.pop();
    for(auto &k : g[u])
       {
          if((s.find(k) == s.end()) and dt[k] == -1)
             {
                  q.push(k);
                  dt[k] = dt[u] + 1;
             }
       }
  }

}

void bfs2(int u)
{
  queue<int> q;

  memset(du,-1,sizeof(du));
  q.push(u);
  du[u] = 0;
  while(!q.empty())
  {
    int u = q.front();
    q.pop();
    for(auto &k : g[u])
       {
          if(du[k] == -1)
             {
                  q.push(k);
                  du[k] = du[u] + 1;
             }
       }
  }

}




int main()
{
  
int n;
cin >> n >> tak >> aok;
s.insert(aok);
for(int i = 0 ; i < n - 1 ; i++)
{
  int u,v;
  cin >> u >> v;
  if(v == aok)
      s.insert(u);
  if(u == aok)
      s.insert(v);

  g[u].push_back(v);
  g[v].push_back(u);
}
bfs1(tak);
bfs2(aok);
ll ans = 0;
int maxi = 1e9;
int eq = -1;

  for(int i = 1 ; i <= n ; i++)
  {
      if(dt[i] != -1 and dt[i] < du[i])
          {
             ans = max(ans , du[i]-1);
          }
  }

  cout << ans ;

}

Measured memory_bytes: 11392
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define all(cont) cont.begin(), cont.end()
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef set<int> si;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
 
ll gcd(ll a,ll b){if(a<0)a=-a;if(b<0)b=-b;while(b!=0){a%=b;if(a==0)return b;b%=a;}return a;}
int mpow(int x,unsigned int y,int p){int res=1;x%=p;if(x==0)return 0;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int fpow(int x,unsigned int y){int t;if(y==0){return 1;}t=fpow(x,y/2);if(y%2==0){return t*t;}else{return x*t*t;}}
void swap(int *arr, int i, int j){int temp=arr[i];arr[i]=arr[j];arr[j]=temp;}
int nCr(int n,int k){int C[k+1];memset(C,0,sizeof(C));C[0]=1;for(int i=1;i<=n;i++){for(int j=min(i,k);j>0;j--)C[j]=C[j]+C[j-1];}return C[k];}
//int mod(int a,int b){int m=a%b;if(m<0){m=(b<0)?m-b:m+b;}return m;}
 
const int INF = 1e9+1;
const int MAX_N = 101;
const int mod = 1000000007;

void solve(){
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	int sum = min(a, k);
	k-=min(a, k);
	if(k > 0) k-=min(b, k);
	if(k > 0) sum -= min(c, k);
	
	cout << sum;
}
 
int main(){
	//freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	
	
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}	
	return 0;
}

Measured memory_bytes: 3692
from collections import defaultdict as dd
from collections import deque
N, M = map(int, input().split())
e = dd(list)
inf = 10 ** 9
for _ in range(M):
  u, v = map(int, input().split())
  e[u].append(v + N)
  e[u + N].append(v + 2 * N)
  e[u + 2 * N].append(v)
S, T = map(int, input().split())
S += 2 * N
T += 2 * N
stopped = [inf] * (3 * (N + 1))
Q = deque()
Q.append(S)
stopped[S] = 0
while len(Q) != 0:
  p = Q.popleft()
  if stopped[p] >= stopped[T]:
    break
  for q in e[p]:
    if stopped[q] > stopped[p] + 1:
      Q.append(q)
      stopped[q] = stopped[p] + 1
if stopped[T] == inf:
  print(-1)
else:
  print(stopped[T] // 3)

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; ++i) cin >> a.at(i);
  
  int ans = a.at(0);
  for(int i = 1; i < n; ++i){
    int x = a.at(i);
    int y = ans;
    
    while(y){
      x %= y;
      swap(x, y);
    }
    
    ans = x;
  }
  
  cout << ans << endl;
}

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

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

    long long int sum = 0;

    for (int i = 1; i <= N; i++) {
        if (i % 3 != 0 && i % 5 != 0) {
            sum += i;
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define DEBUG(x) cout << #x << " = " << x << endl
#define pb push_back
using namespace std;
typedef long long ll;


const int MAXN = 100005;

ll x[MAXN];

int main()
{
    //freopen("input.txt", "r", stdin);
    int N;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> x[i];
    }

    sort(x, x + N);

    int i = N-1;
    while(i > 0 && x[i] != x[i-1]) i--;
    if (i == 0) {cout << "0"; return 0;}
    ll a = x[i];
    i -= 2;

    while(i > 0 && x[i] != x[i-1]) i--;
    if (i == 0) {cout << "0"; return 0;}

    ll b = x[i];

    cout << a * b;
    return 0;
}




Measured memory_bytes: 1024
n,m,v,p = map(int, input().split())
As = list(map(int, input().split()))
As.sort(reverse=True)
# print(As)
def f(x):
    # 判定基準
    if x < p:
        return True
    if As[x]+m < As[p-1]:
        return False
    cnt0 = (n-x)*m
    cnt1 = (p-1)*m
    cnt2 = 0
    for i in range(p-1, x):
        cnt2 += As[x]+m-As[i]
    return cnt0 + cnt1 + cnt2 >= m*v    


# 二部探索でOK/NG求める
ok = 0
ng = n
while ng - ok > 1:
    mid = (ok+ng)//2
    if f(mid):
        ok = mid
    else:
        ng = mid
print(ok+1)

Measured memory_bytes: 85512
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD = 1000000007;


     signed main(){
  
int a;long double b;
cin>>a>>b;
int ans=0;
int k=b*1000;
int a2=a/(MOD-7);
a%=(MOD-7);
ans=(a*k)/1000;
int u=a2*k*(1000000ll);
cout<<ans+u<<endl;








 }

 


 






    





      

        


Measured memory_bytes: 3748
fun main(args: Array<String>) {
    val (_, M) = readLine()!!.split(" ").map(String::toInt)
    val input = readLine()!!.split(" ").map(String::toDouble)

    val judge = input.sum() / (4.0 * M)
    val count = input.count { it >= judge }
    if (count >= M) println("Yes") else println("No")
}


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

using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

#define endl '\n'
#define MAX

typedef long long ll;
typedef pair<int,int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;


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

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int n,k;
	cin >> n >> k;
	vector<int> a(n);
	for(int i = 0 ; i < n; i++)
	    cin >> a[i];
	multiset<int> S;
	for(int i = 0; i < k; i++)
	    S.insert(a[i]);
	int lo = 0;
	for(int i = k; i < n; i++){
	    cout << *(S.begin()) << " ";
	    S.erase(S.find(a[lo]));
	    lo++;
	    S.insert(a[i]);
	}
	cout << *(S.begin()) << endl;
	
	return 0;
}


Measured memory_bytes: 11380
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    string s;
    cin >> s;
    string d = "/";
    int n = s.length();
    vector<int> ds;
    for (int i = 0; i < n; ++i) {
        auto j = s.find_first_of(d, i);
        if (j == string::npos) {
            j = n;
        }
        ds.push_back(stoi(s.substr(i, j - i)));
        i = j;
    }
    if (ds[0] <= 2019 && ds[1] <= 4 && ds[2] <= 31) {
        cout << "Heisei\n";
    } else {
        cout << "TBD\n";
    }

    return 0;
}

Measured memory_bytes: 256
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include<iomanip>

#define mod 1000000007
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)

using namespace std;

ll power(ll a, ll b, ll m)
{
	if (b == 0)
		return(1);
	ll sol = power(a, b / 2, m);
	sol = (sol * sol) % m;
	if (b % 2 == 1)
		sol = (sol * a) % m;
	return(sol);
}

ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	else
	{
		return gcd(b, a % b);
	}
}
void solve()
{
	ll a,b,ans=1;
	cin >> a >> b;
	ll g = gcd(a, b);
	for (ll i = 2; i <= 1000000; i++)
	{
		if (g % i)
			continue;
		ans++;
		while (g % i == 0)
		{
			g = g / i;
		}
	}
	if (g > 1)
		ans++;
	cout << ans;
}
int main()
{
	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}

// from #7786788


Measured memory_bytes: 256
import java.lang.Math.abs

fun main(args: Array<String>) = ABC166D.main()

object ABC166D {
    fun log(message: Any?) {
        println(message)// TODO: ←消す
    }

    fun Int.sqrt() = Math.sqrt(this.toDouble()).toInt()

    fun main() {
        val X = readInt()

        val (al, be) = (1..X.sqrt()).asSequence().mapNotNull { al ->
            val al2 = al * al
            val al4 = al2 * al2

            if (X % al != 0
                || ((X / al) - al4) % 5 != 0
            ) return@mapNotNull null

            if (al4 == X / al) return@mapNotNull al to 0


            val ga = ((X / al) - al4) / 5
            val s = abs(ga)
            val beta = (1..s.sqrt()).filter { ga % it == 0 }.asSequence()
                //.filter { b -> ga % b == 0 }
                .mapNotNull { pb ->
                    val pLeft = al2 + pb
                    val pRight = ga / pb

                    val mb = -pb
                    val mLeft = al2 + mb
                    val mRight = ga / mb
                    when {
                        (pLeft == pRight) -> pb
                        (mLeft == mRight) -> mb
                        else -> null
                    }
                }.firstOrNull()
            beta?.let { al to it }
        }.first()
        //////
        val D = Math.sqrt((al * al + 4 * be).toDouble()).toInt()
        val A1 = (al + D) / 2
        val A2 = (al - D) / 2
        val B1 = A1 - al
        val B2 = A2 - al
        val ans = when {
            check(A1, B1, X) -> A1 to B1
            check(A2, B2, X) -> A2 to B2
            else -> null
        }
        println("${ans?.first} ${ans?.second}")
    }

    fun check(A: Int, B: Int, X: Int) = (A * A * A * A * A - B * B * B * B * B) == X

    /*####################################################################################*/

    fun readString() = readLine()!!
    fun readStrings() = readLine()!!.split(" ")
    fun readInt() = readLine()!!.toInt()
    fun readInts() = readLine()!!.split(" ").map { it.toInt() }
    fun readLong() = readLine()!!.toLong()
    fun readLongs() = readLine()!!.split(" ").map { it.toLong() }
    fun readMatrixRows(height: Int) = (1..height).map { readLine()!!.toList() }

    fun Boolean.yesOrNo() = if (this) "Yes" else "No"
    fun Double.toNaturalExpr() = println("%f".format(this))
}

Measured memory_bytes: 36220
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
#include<deque>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int n;
	cin >> n;
	int i = 1;
	i64 ans = 1;
	while (1) {
		i++;
		if (i*i > n) {
			i--;
			ans = i * i;
			break;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
const int mod = 1000000007;
#define EPS (1e-10)

#define pb push_back
#define fir first
#define scn second
#define ednl endl

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")


P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}


int gcd(int a,int b){
  if(a%b)return gcd(b,a%b);
  else return b;
}
int main(){
  string s;cin>>s;
  bool MY = false;
  bool YM = false;
  if((s[0]-'0')*10+(s[1]-'0') && (s[0]-'0')*10+(s[1]-'0') <= 12){
    MY = true;
  }
  if((s[2]-'0')*10+(s[3]-'0') && (s[2]-'0')*10+(s[3]-'0') <= 12){
    YM = true;
  }
  if(MY && YM){
    cout << "AMBIGUOUS" << endl;
  }else if(MY){
    cout << "MMYY" << endl;
  }else if(YM){
    cout << "YYMM" << endl;
  }else{
    cout << "NA" << endl;
  }
  
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	for(int a,b,n;cin>>a>>b>>n;){
		int res=0;
		for(int i=0;i<n;i++){
			a%=b;
			a*=10;
			res+=a/b;
		}
		cout<<res<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
def resolve():
    N = int(input())

    P = []
    A = []
    B = []
    for i in range(N):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)
        P.append((a + b, i))

    P.sort(reverse=True)
    taka = 0
    aoki = 0
    for i, (diff, idx) in enumerate(P):
        if i % 2 == 0:
            taka += A[idx]
        else:
            aoki += B[idx]

    print(taka - aoki)


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 30848
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
void solve(){
	ll n,m,sum=0;
	cin>>n>>m;
	for(ll i=0;i<m;i++){
		ll x;
		cin>>x;
		sum+=x;
	}
	n-=sum;
	if(n<0)
	cout<<"-1";
	else
	cout<<n;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll qc=1;
    for(ll i=1;i<=qc;i++)
    solve();
}


Measured memory_bytes: 3656
a=[]
b={}
n,m = map(int,input().split())
for _ in range(m):
	i,j = map(int,input().split())
	if i==1:
		a.append(j)
	elif j==n:
		b[i]=1
for i in a:
	if i in b:
		print('POSSIBLE')
		break
else:
	print('IMPOSSIBLE')

Measured memory_bytes: 18420
# include <algorithm>
# include <cmath>
# include <iostream>
# include <map>
# include <queue>
# include <string>
# include <vector>

typedef long long ll;

using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q; cin >> n >> q;
    vector<int> tree[n];
    for (int i = 0; i < n - 1; i++) {
        int a, b; cin >> a >> b;
        a--;
        b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }

    vector<ll> ans(n, 0);
    for (int i = 0; i < q; i++) {
        ll p, x; cin >> p >> x;
        p--;
        ans[p] += x;
    }
    queue<pair<int, int>> que;
    que.push(make_pair(0, -1));
    while (que.size()) {
        pair<int, int> f = que.front();
        que.pop();
        int l = f.first;
        int p = f.second;
        if (p >= 0) ans[l] += ans[p];
        for (int& x : tree[l]) {
            if (x == p) continue;
            que.push(make_pair(x, l));
        }
    }
    for (int i = 0; i < n; i++) {
        if (i != n-1) cout << ans[i] << " ";
        else cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 17140
a, b, k= map(int, input().split())

for i in range(k):
    if i % 2 == 0:
        if a % 2 == 1:
            a -= 1
        a //= 2
        b += a
    else:
        if b % 2 == 1:
            b -= 1
        b //= 2
        a += b

print(a, b)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll INF = 1e14;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;

signed main() {
    int M,N;
    cin >> M >> N;
    vector<ll> vec(N + 1);
    for(int i = 0;i < N;i++) {
        cin >> vec.at(i);
    }
    vec.at(N) = M + 1;
    if(M == 2) {
        int ret1 = 0;
        int ret2 = 0;
        for(int i = 0;i < N;i++) {
            if(i % 2 == 0) {
                if(vec.at(i) == 1) {
                    ret1++;
                }
            }
            else {
                if(vec.at(i) == 2) {
                    ret1++;
                }
            }
        }
        for(int i = 0;i < N;i++) {
            if(i % 2 == 0) {
                if(vec.at(i) == 2) {
                    ret2++;
                }
            }
            else {
                if(vec.at(i) == 1) {
                    ret2++;
                }
            }
        }
        cout << min(ret1, ret2) << endl;
        return 0;
    }
    int ret = 0;
    for(int i = 0;i < N - 1;i++) {
        if(vec.at(i) == vec.at(i + 1)) {
            ret++;
            if(vec.at(i) != 1 && vec.at(i + 2) != 1) {
                vec.at(i + 1) = 1;
            }
            else if(vec.at(i) != 2 && vec.at(i + 2) != 2) {
                vec.at(i + 1) = 2;
            }
            else {
                vec.at(i + 1) = 3;
            }
        }
    }
    cout << ret << endl;
}


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

int main(void)
{
	char s[102], p[102], t[201];
	fgets(s, 102, stdin);
        s[strlen(s) - 1] = '\0';
        fgets(p, 102, stdin);
        p[strlen(p) - 1] = '\0';
	sprintf(t, "%s%s", s, s);
	if (strstr(t, p)) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}
}



Measured memory_bytes: 2132
#include <iostream>
using namespace std;
inline void chmax(int &a, int b) {if(a < b) a = b;}

string s; int k = 5;
int dp[200020][10]; // dp[i][j] := i番目まで見て、直前の文字列がj

int main() {
    cin >> s;
    int n = (int)s.size();
    for(int i = 0; i <= n; ++i)
        for(int j = 0; j <= k; ++j) dp[i][j] = -1;

    dp[0][0] = 0;
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j <= k; ++j) {
            if(dp[i][j] == -1) continue;
            // ~~ 更新用ループ ~~
            // iを起点に次の区切りの長さを決めて配る。
            // 次の区切りが前の区切りの長さと異なるか、
            // 同じならiよりj後ろの文字列 != iよりj後ろの文字列　なら区切りを増やせる

            for(int nxt = 1; nxt <= k && i + nxt <= n; ++nxt) {
                if(j != nxt || s.substr(i - j, j) != s.substr(i, j)) {
                    chmax(dp[i + nxt][nxt], dp[i][j] + 1);
                }
            }
        }
    }

    int ans = 0;
    for(int i = 0; i <= k; ++i) chmax(ans, dp[n][i]);
    cout << ans;
}

Measured memory_bytes: 8324
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int k;
    int n;
    int x;
    int kyori = 0;
  
    cin >> n >> k;
  
	for (int i=0; i<n; i++) {
        cin >> x;
        if(k - x < x) {
          kyori = kyori + (k - x) * 2;
        } else {
          kyori = kyori + x * 2;
        }
    }
  
   cout << kyori << endl;
  
}

Measured memory_bytes: 256
from collections import defaultdict

H,W = map(int, input().split())
cnt = defaultdict(int)
for _ in range(H):
    for a in list(input()):
        cnt[a] += 1
cnt = [c for c in cnt.values()]



for i in range((H + 2 - 1) // 2):
    for j in range((W + 2 - 1) // 2):
        need = [(i, j), (H - 1 - i, j), (i, W - 1 - j), (H - 1 - i, W - 1 - j)]
        need = set(need)

        cnt.sort()

        flag = False
        for k in range(len(cnt)):
            if len(need) <= cnt[k]:
                flag = True
                cnt[k] -= len(need)
                if cnt[k] == 0:
                    cnt.pop(k)
                break
                    
        if not flag:
            print("No")
            exit()

print("Yes")

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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

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

ll c[15];
ll a[15][15];

void solve()
{
  // ll n; cin >> n;
  ll n, m, x; cin >> n >> m >> x;
  REP(i, n) {
    cin >> c[i];
    REP(j, m) cin >> a[i][j];
  }
  ll ans = -1;
  bool ok = true;

  for(int bit = 0; bit < (1<<n); ++bit) {
    ll su[15];
    ll ps = 0;
    REP(k, m) su[k] = 0;
    for(int i = 0; i < n; i++) {
      if(bit & (1<<i)) {
	REP(k, m) {
	  su[k] += a[i][k];
	}
	ps += c[i];
      }
    }
    bool ok1 = true;
    REP(i, m) {
      if(su[i] < x) ok1 = false;
    }
    if(ok1) {
      if(ans > ps || ans < 0) ans = ps;
      ok = true;
    }
  }
  if(ok) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
  
}


int main(void)
{
  // ll t; cin >> t; REP(i, t)
  solve();
}


Measured memory_bytes: 3640
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;
ll N;
ll a[100010];
ll differ[100010];
bool Check(ll n){
	for(ll i=0;i<N;i++){
		if( (n-differ[i])%N !=0 ){
			return false;
		}
	}
	return true;
}
int main(){
    cin>>N;
	ll sum=0;
	for(ll i=0;i<N;i++){
		cin>>a[i];
		sum+=a[i];
	}
	for(ll i=0;i<N-1;i++){
		differ[i]=a[i+1]-a[i];
	}
	differ[N-1]=a[0]-a[N-1];

	ll sum1_N=N*(N+1)/2;
	if(sum%(sum1_N)!=0){
		cout<<"NO"<<endl;
		return 0;
	}
	ll cnt=0;
	for(ll i=0;i<N;i++){
		if(differ[i]-sum/sum1_N>0){
			cout<<"NO"<<endl;
			return 0;
		}
		if((sum/sum1_N-differ[i])%N==0){
			cnt+=(sum/sum1_N-differ[i])/N;
		}
		else{
			cout<<"NO"<<endl;
			return 0;
		}
	}
	if(cnt!=sum/sum1_N){
		cout<<"NO"<<endl;
		return 0;
	}
	cout<<"YES"<<endl;
    return 0;
}

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

int main() {
  int n, l;
  cin >> n >> l;
  vector<string> s(n);
  rep(i,n,0) cin >> s[i];
  sort(s.begin(),s.end());
  
  rep(i,n,0) cout << s[i];
  cout << endl;
}

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

const int32_t MAX_N = 1e5;

class Graph {
public:
	struct Node {
		bool isVisited;
		int32_t id, dp, inDegree;
		std::vector< Node* > v;
	};

	int32_t cntNodes;
	Node nodes[MAX_N + 5];

	void Init(int32_t pCntNodes) {
		cntNodes = pCntNodes;

		for(int32_t i = 1; i <= cntNodes; i++) {
			nodes[i].id = i;
		}
	}

	void AddEdge(Node *x, Node *y) {
		x->v.push_back(y);
		y->inDegree++;
	}

	int32_t Dfs(Node *nd) {
		nd->isVisited = true;

		for(auto &x : nd->v) {
			if(x->isVisited) {
				nd->dp = std::max(nd->dp, x->dp + 1);
			}
			else {
				nd->dp = std::max(nd->dp, Dfs(x) + 1);
			}
		}

		return nd->dp;
	}

	int32_t FindLongestPath() {
		int32_t ans = 0;

		for(int32_t i = 1; i <= cntNodes; i++) {
			if(nodes[i].inDegree == 0) {
				ans = std::max(ans, Dfs(&nodes[i]));
			}
		}

		return ans;
	}
};

Graph g;

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

	int32_t n, m;
	std::cin >> n >> m;

	g.Init(n);
	for(int32_t i = 0; i < m; i++) {
		int32_t x, y;
		std::cin >> x >> y;

		g.AddEdge(&g.nodes[x], &g.nodes[y]);
	}

	std::cout << g.FindLongestPath() << '\n';
}



Measured memory_bytes: 9856
N, X, M = map(int, input().split())
flag = [False for _ in range(M)]
record = list()
record.append(X)
flag[X] = 1

An = X

for i in range(M + 1):
    An = pow(An, 2, M)
    if flag[An]:
        start = flag[An]
        cnt = i + 2 - start
        cost = record[-1] - record[start - 2] if start > 1 else record[-1]
        break

    else:
        record.append(An + record[-1])
        flag[An] = i + 2

if start >= N:
    print(record[N - 1])
else:
    print(((N - start) // cnt) * cost
                + record[(N - start) % cnt + start - 1])


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

int main(){
   std::string S;
   std::cin >> S;
   size_t N = S.size();
   std::sort(S.begin(), S.end());
   S.erase(std::unique(S.begin(), S.end()), S.end());
   size_t newN = S.size();
   if (N == newN)
      std::cout << "yes" << std::endl;
   else
      std::cout << "no" << std::endl;
}



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

int main(){
    int N, T;
    std::cin >> N >> T;
    int minCost = 10000;
    for(int i = 0; i < N; i++){
        int c, t;
        std::cin >> c >> t;
        if(t <= T) minCost = std::min(minCost, c);
    }
    if(minCost == 10000){
        std::cout << "TLE" << std::endl;
    }else{
        std::cout << minCost << std::endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MOD 1000000007
#define MAXN 210000
#define Inv2 500000004
#define lowbit(x) (x)&(-x)
using namespace std;
template <typename T> inline void read(T &s)
{
	s = 0;char ch = getchar();
	while(!isdigit(ch)) ch = getchar();
	while(isdigit(ch)) s = ((s+(s<<2))<<1)+ch-'0',ch = getchar();
}
int n,A[MAXN],C[MAXN],S=1,tl,Ans,bel[MAXN];
vector <int> v[MAXN];
pair<int,int> T[MAXN];
inline int Mod(int u){return u < MOD?u:u-MOD;}
struct Bit
{
	int tmp[MAXN];
	Bit(){memset(tmp,0,sizeof(tmp));}
	inline void Insert(int x,int val){for(;x<=n;x+=lowbit(x)) tmp[x] = Mod(Mod(val+tmp[x])+MOD);}
	inline int Query(int x){int Sum = 0;for(;x;x-=lowbit(x)) Sum = Mod(tmp[x]+Sum);return Sum;}
}Sum1,cnt,Sum2;
inline int Fast_Power(int u,int k=MOD-2)
{
	int Sum = 1;
	while(k)
	{
		if(k&1) Sum = 1ll * Sum * u % MOD;
		u = 1ll * u * u % MOD,k >>= 1;
	}
	return Sum;
}
int main()
{
	read(n),T[0] = make_pair(1,0);
	for(int i = 1;i<=n;++i) read(A[i]),C[A[i]]++;
	for(int i = n;i;--i) C[i] += C[i+1];
	for(int i = 1;i<=n;++i) C[i] = C[i] - n + i,S = 1ll * S * C[i] % MOD;
	if(S <= 0) return puts("0"),0;
	for(int i = 1;i<=n;++i)
	{
		T[i] = T[i-1];
		if(C[i] == 1) T[i].second++,++tl,bel[i] = tl;
		else T[i].first = 1ll * T[i].first * (C[i]-1) % MOD * Fast_Power(C[i]) % MOD,bel[i] = tl;
	}
	for(int i = 1;i<=n;++i)
		Ans = Mod(Ans + 1ll * Mod(Mod(i - cnt.Query(A[i])+MOD) - 1 + MOD) * S % MOD),cnt.Insert(A[i],1),v[bel[A[i]]].push_back(i);
	for(int i = 0;i<=tl;++i)
	{
		for(auto x : v[i])
		{
			Ans = Mod(Ans + 1ll * (Sum2.Query(A[x])) * T[A[x]].first % MOD * S % MOD * Inv2 % MOD);
			Ans = Mod(Ans - 1ll * Mod(Sum1.Query(n) - Sum1.Query(A[x]) + MOD) * Fast_Power(T[A[x]].first) % MOD * S % MOD * Inv2 % MOD + MOD);
			Sum1.Insert(A[x],T[A[x]].first),Sum2.Insert(A[x],Fast_Power(T[A[x]].first));
		}
		for(auto x : v[i])
			Sum1.Insert(A[x],-T[A[x]].first),Sum2.Insert(A[x],-Fast_Power(T[A[x]].first));
	}
	printf("%d\n",Ans);
	return 0;
}

Measured memory_bytes: 17920
#include<iostream>
typedef struct{
  int p, l, r;
}tree;
void preorder(int);
void inorder(int);
void postorder(int);
tree *T;
int main(){
  int n, i, x, root=0;
  std::cin>>n;
  T=new tree[n];
  for(i=0; i<n; i++) T[i].p = -1;
  for(i=0; i<n; i++){
    std::cin>>x;
    std::cin>>T[x].l>>T[x].r;
    T[T[x].l].p = T[T[x].r].p = x;
  }
  for(i=0; i<n; i++){
    if(T[i].p == -1){
      root = i;
      break;
    }
  }
  std::cout<<"Preorder\n";
  preorder(root);
  std::cout<<"\nInorder\n";
  inorder(root);
  std::cout<<"\nPostorder\n";
  postorder(root);
  std::cout<<std::endl;
  delete T;
  return 0;
}
void preorder(int x){
  if(x == -1) return;
  std::cout<<" "<<x;
    preorder(T[x].l);
    preorder(T[x].r);
}
void inorder(int x){
  if(x == -1) return;
    inorder(T[x].l);
    std::cout<<" "<<x;
    inorder(T[x].r);
}
void postorder(int x){
  if(x == -1) return;
    postorder(T[x].l);
    postorder(T[x].r);
    std::cout<<" "<<x;
}

Measured memory_bytes: 3100
s = input()

# now = 0
left = 0
right = 0
ans = []
for i in range(len(s) + 1):
    if left == 0:
        # 左側
        for j in range(i - 1, -1, -1):
            if s[j] != '<':
                break
            else:
                left += 1
    else:
        if s[i - 1] == '<':
            left += 1
        else:
            left = 0
    # 右側
    if right == 0:
        for j in range(i, len(s)):
            if s[j] != '>':
                break
            else:
                right += 1
    else:
        if i == len(s):
            right = 0
        elif s[i] == '>':
            right -= 1
        else:
            right = 0
    ans.append(max(left, right))
# print(ans)
print(sum(ans))


Measured memory_bytes: 25216
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<sstream>
#include<string>
#include<string.h>
#include<cmath>
#include<stack>
#include<vector>
#include<map>
#define E (2.71828182)
#define PI (3.1415926535898)
#define	mem(a,b)	memset(a,b,sizeof(a))
#define	_max(a,b,c)	(max(a,b)>c?max(a,b):c)
#define mod	1000000007
#include<set>
#define gc getchar
#define debug(a) cout << "*" << a << "*" << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<float, int> P;
const int N = 1000000;
const long long  MAX_V = 5005, INF = 2147483647, MOD = 998244353;
#include <iostream>
using namespace std;
ll n, a, b; 
int main()
{
	while (~scanf("%lld%lld%lld", &n, &a, &b))
	{
		printf("%lld\n", n / (a + b) * a + min(n % (a + b), a));
	}
}

Measured memory_bytes: 256
n = int(input())
x_l = list(map(int,input().split()))
s_x_l = sorted(x_l)

med_idx = n//2
med_l = s_x_l[med_idx-1]
med_r = s_x_l[med_idx]

for i in range(n):
    if  x_l[i] <= med_l:
        print(med_r)
    else:
        print(med_l)

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

int main()
{
  int n, m;
  cin >> n >> m;
  vector<vector<int>> vec(n + 1, vector<int>(n + 1));
  rep(i, m)
  {
    int a, b;
    cin >> a >> b;
    vec[a][b] = 1;
    vec[b][a] = 1;
  }
  vector<int> v(n);
  rep(i, n) v[i] = i + 1;
  int ans = 0;
  sort(v.begin(), v.end());
  do
  {
    if (v[0] != 1)
      break;
    bool ok = true;
    rep(i, n - 1)
    {
      if (vec[v[i]][v[i + 1]] == 0)
        ok = false;
    }
    if (ok)
      ans++;
  } while (next_permutation(v.begin(), v.end()));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<cmath>
#include<vector>

using namespace std;

int main(){
int n;
int i,j,k;

cin >> j;
vector<int> V(j);          //???????????????????¢????

for(i=0;i<j;i++){
    cin >> V[i];              //????´?????????\???
}

for(i=j-1;i>=0;i--){
  cout << V[i];         //?????????????????????????????¨???
if(i>0){
  cout << ' ';
}
}
cout << endl;

return 0;

}

Measured memory_bytes: 1196
N, K = map(int, input().split())

items = set([N])

def check(x, K):
	if x == K:
		x = 0
	elif x < K:
		x = K - x
	else:
		x = x % K
	return x

x = N
while True:
	new_x = check(x, K)
	if new_x in items:
		break
	items.add(new_x)
	x = new_x


print(min(items))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#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())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
 
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;
 
ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
 
int main()
{
	IOS;
	ll k,a,b;
	cin>>k>>a>>b;
	b-=a;
	ll ans=1;
	if(b<=2) cout<<k+1<<'\n';
	else{
		ll tmp=min(k,a-1);
		ans+=tmp;
		k-=tmp;
 
		if(k%2) ans++,k--;
 
		ans+=k/2*(b);
		cout<<ans<<'\n';
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
long a[1<<17],n,k,i,j,x,c,r;
main(){
  cin>>n>>k;
  for(i=0;i<n;++i)cin>>a[i];
  for(i=40;i>=0;--i){
    c=0;
    for(j=0;j<n;++j)c+=(a[j]>>i)&1;
    if(2*c<n&&(x|(1L<<i))<=k)x|=1L<<i;
  }
  for(i=0;i<n;++i)r+=x^a[i];
  cout<<r<<endl;
}


Measured memory_bytes: 1024
s=input()
n=len(s)
mod=10**9+7
dp=[ [0]*3 for _ in range(n)]
#dp[i][0] count of A's in all possible strings u generate till i
#dp[i][1] count of AB's ''
#dp[i][2] count of ABC's ''
cnt=1
for i in range(n):
    if s[i]=='?':
        if i>0:
            dp[i][2]=dp[i-1][1]+3*dp[i-1][2]
            dp[i][2]%=mod
            dp[i][1]=dp[i-1][0]+3*dp[i-1][1]
            dp[i][1]%=mod
            dp[i][0]=3*dp[i-1][0]+1*cnt
            dp[i][0]%=mod
        else:
            dp[i][0]=1
        cnt*=3
        cnt%=mod
    elif s[i]=='C':
        if i>0:
            dp[i][2]=dp[i-1][1]+dp[i-1][2]
            dp[i][2]%=mod
            dp[i][1]=dp[i-1][1]
            dp[i][0]=dp[i-1][0]
    elif s[i]=='B':
        if i>0:
            dp[i][2]=dp[i-1][2]
            dp[i][1]=dp[i-1][0]+dp[i-1][1]
            dp[i][1]%=mod
            dp[i][0]=dp[i-1][0]
    elif s[i]=='A':
        if i>0:
            dp[i][2]=dp[i-1][2]
            dp[i][1]=dp[i-1][1]
            dp[i][0]=dp[i-1][0]+1*cnt
            dp[i][0]%=mod
        else:
            dp[0][0]=1

print(dp[-1][2]%mod)
            


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

#define forN(i, N) for (i = 0; i < N; i++)
#define MAXLEN 1000

int main(int argc, char *argv[]) {
  char str[MAXLEN];
  int num;

  scanf("%s", str);
  scanf("%d", &num);

  for (int i = 0; i < strlen(str); i += num) {
    putchar(str[i]);
  }

  return 0;
}


Measured memory_bytes: 128
n = int(input())
a = [int(i) for i in input().split()]
A=[]
for i in range(n):
    A.append(a[i])

flag = True
count = 0
while flag:
    flag = False
    for i in range(1, n):
        if A[i] < A[i-1]:
            A[i], A[i-1] = A[i-1], A[i]
            flag = True
            count += 1
print(*A)
print(count)


Measured memory_bytes: 5608