akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>

#define endl '\n'

using namespace std;

const int MAXN=1e5+5;
int mod,in[MAXN],out[MAXN],prefix[MAXN],suffix[MAXN];
vector<int> graph[MAXN];

int mul(int x, int y){
    return (long long) x*y%mod;
}

void dfs1(int currv, int parent){
    in[currv]=1;
    for(int nextv : graph[currv]){
        if(nextv!=parent){
            dfs1(nextv,currv);
            in[currv]=mul(in[currv],in[nextv]+1);
        }
    }
}

void dfs2(int currv, int parent){
    vector<int> children;
    for(int nextv : graph[currv]){
         if(nextv!=parent){
             children.push_back(nextv);
         }
    }
    vector<int> prefix(children.size()+2,0),suffix(children.size()+2,0);
    prefix[0]=1;
    suffix[children.size()+1]=1;
    for(int i=1;i<=children.size();++i){
        prefix[i]=mul(prefix[i-1],in[children[i-1]]+1);
    }
    for(int i=children.size();i>0;--i){
        suffix[i]=mul(suffix[i+1],in[children[i-1]]+1);
    }

    int counter=1;
    for(int nextv : graph[currv]){
        if(nextv!=parent){
            out[nextv]=(mul(mul(out[currv],prefix[counter-1]),suffix[counter+1])+1)%mod;
            ++counter;
            dfs2(nextv,currv);
        }
    }
}

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

    int n;
    cin>>n>>mod;
    for(int i=1;i<n;++i){
        int from,to;
        cin>>from>>to;
        --from;
        --to;
        graph[from].push_back(to);
        graph[to].push_back(from);
    }
    
    dfs1(0,-1);
    out[0]=1;
    dfs2(0,-1);

    for(int i=0;i<n;++i){
        int res=mul(in[i],out[i]);
        cout<<res<<endl;
    }
return 0;
}

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

using namespace std;

int main() {
    int h, w;
    cin >> h >> w;

    vector<vector<char>> maze(h, vector<char> (w));

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> maze[i][j];
        }
    }

    queue<pair<int, int>> que;
    vector<vector<int>> dist(h, vector<int> (w, -1));

    vector<int> addy = {-1,  0,  1,  0};
    vector<int> addx = { 0,  1,  0, -1};

    int longest = 0;
    int ans = 0;

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (maze[i][j] == '.') {
                que.push(make_pair(i, j));
                dist[i][j] = 0;

                while (!que.empty()) {
                    int y, x;
                    tie(y, x) = que.front();
                    que.pop();
                    for (int k = 0; k < 4; k++) {
                        int searchy = y + addy[k];
                        int searchx = x + addx[k];

                        if (0 <= searchy && searchy < h && 0 <= searchx && searchx < w) {
                            if (dist[searchy][searchx] == -1 && maze[searchy][searchx] == '.') {
                                que.push(make_pair(searchy, searchx));
                                longest = dist[y][x] + 1;
                                dist[searchy][searchx] = longest;
                            }
                        }
                    }
                }
                ans = max(ans, longest);
                for (int l = 0; l < h; l++) {
                    for (int m = 0; m < w; m++) {
                        dist[l][m] = -1;
                    }
                }
            }
        }
    }

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

Measured memory_bytes: 256
# A - Between Two Integers

# A B C の3つの整数が与えられる
#  整数 C が　A以上　かつ　B以下である時　Yes
# そうでないとき　No

# A B C を標準入力から得る
A, B, C = map(int, input().split(maxsplit=3))

if A <= C <= B:
    answer = "Yes"
else:
    answer = "No"

# 結果を出力
print(answer)


Measured memory_bytes: 9148
#include<iostream>
#include<cmath>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<cstdlib>
#include<queue>
#include<list>
using namespace std;

int main(){
    int a;
    cin>>a;
    if(a<1200)cout<<"ABC"<<endl;
    else cout<<"ARC"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) ((y)<0||(x)<0||(y)>=(h)||(x)>=(w))
#define dump(...)
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
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(a>b){a=b;return 1;}return 0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    string s;
    cin>>s;
    vector<bool> ex(256);
    FORE(x,s) ex[x]=1;
    if(SZ(s)==26) {
        int idx=-1;
        REPR(i,SZ(s)) {
            if(i==0) break;
            if(s[i-1]<s[i]) {
                idx=i;
                break;
            }
        }
        if(idx==-1) {
            cout<<-1<<endl;
            return 0;
        }
        set<char> tmp;
        REPF(i,idx,SZ(s)) {
            tmp.insert(s[i]);
        }
        s[idx-1]=*(tmp.lower_bound(s[idx-1]));
        cout<<s.substr(0,idx)<<endl;
    } else {
        char nx;
        REPF(i,'a','z'+1) {
            if(!ex[i]) {
                nx=i;
                break;
            }
        }
        s+=nx;
        cout<<s<<endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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 MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

int main() {
   int n;
   cin >> n;
   int p[n];
   for (int i = 0; i < n; i++) cin >> p[i];

   int ans = 0;
   for (int i = 0; i < n - 2; i++) {
      if ((p[i] < p[i + 1] && p[i + 1] < p[i + 2]) || (p[i] > p[i + 1] && p[i + 1] > p[i + 2])) ans++;
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
class Item {
	int weight,val;
	public Item(int weight, int val) {
		this.weight = weight;
		this.val = val;
	}
}
public class Main {


	public static void main(String[] args) {
		Main ans = new Main();
		System.out.println(ans.solve());
	}

	private long solve() {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int maxWeight = sc.nextInt();
		Item [] array = new Item[N+1];
		for(int i=1;i<=N;i++) {
			array[i] = new Item(sc.nextInt(), sc.nextInt());
		}
		int maxValue = N*1000;
		int maxValueOfWeight = (int)(1e9);
		long [][] dp = new long[N+1][maxValue+1];

		for(int val=0;val<=maxValue;val++) { 
			dp[1][val] = maxValueOfWeight+1;
		}

		dp[1][array[1].val] = array[1].weight;
		dp[1][0] = 0;

		for(int i=2;i<=N;i++){
			for(int val=0;val<=maxValue;val++) {
				dp[i][val] = dp[i-1][val];

				if (val<array[i].val) continue;
				dp[i][val] = Math.min(dp[i-1][val], array[i].weight+ dp[i-1][val-array[i].val]);
			}
		}

		long bestTotalValue=0;
		for(int val=0;val<=maxValue;val++) {
			if (dp[N][val]<=maxWeight) {
				bestTotalValue = Math.max(bestTotalValue, val);
			}
		}
		return bestTotalValue;
	}

}

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

using namespace std;

int l;
string irekae(string s)
{
    char c=s[l-1];
    s.pop_back();
    s = c+s;
    return s;
    
}
int main()
{
    string s,t;
    cin>>s>>t;
    l=s.length();
    if(s==t){ cout << "Yes" << endl; return 0;}
    else {
        int flag=0;
        for(int i=0; i<s.length(); i++){
            s=irekae(s);
            if(s==t){ flag=1;}
        }
        if(flag==1) { cout << "Yes" << endl;}
        else { cout <<"No" << endl;}
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

const int maxn=100000;

int main(){
    
    string s;
    int n,k;
    cin >> n>>k;
    cin >> s;
    
    int c = int(s[k-1]);
    s[k-1]=char(97+c-65);
    cout << s<<endl;
    
    return 0;
}


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

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

    int taste = 0;
    int minTaste = 100;

    for (int i = 1; i <= N; i++)
    {
      taste += L+i-1;
      if(abs(minTaste) > abs(L+i-1))
        minTaste = L+i-1;
    }

    cout << taste - minTaste << endl; 
  

  return 0;
}

Measured memory_bytes: 256
a,b,x=map(int,input().split())
import math
p=2*(a*a*b-x)/a**3
q=(a*b*b)/(2*x)
y=math.atan(p)
u=math.atan(q)
if x>=a**2*b/2:
	print(math.degrees(y))
else:
	print(math.degrees(u))


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

using namespace std;

int main() {
	string A;
	int B, C;
	cin >> A;
	B = A.size() / 2;
	C = A.size();
	int G = 0;
		for (int i = 0; i < B; i++) {
			if (A.at(i) != A.at(C-1-i)) {
				G++;
			}
			else
				continue;
		}
	
	cout << G << endl;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

count = 0

for i in range(N):
    if A[i] < 0:
        A[i] *= -1
        count += 1

if count % 2 == 0:
    print(sum(A))
else:
    A.sort()
    print(sum(A) - 2 * A[0])

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

#define ll long long
#define ull unsigned long long

#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))

bool isPalindrome(string s) {
    string t(s.rbegin(), s.rend());
    return s == t;
}

int main(void) {
    ll N;
    string S;
    ll r = 0, g = 0, b = 0;
    ll count = 0;
    cin >> N;
    cin >> S;
    for(const char &c: S) {
        switch(c) {
            case 'R':
                r += 1;
                break;
            case 'G':
                g += 1;
                break;
            case 'B':
                b += 1;
                break;
        }
    }
    count = r * g * b;
    for(ll i = 0;i < N;i++) {
        for(ll j = i;j < N;j++) {
            char a = S[i];
            char b = S[j];
            ll cIndex = 2 * j - i;
            if(cIndex < N) {
                if(a != b && S[cIndex] != a && S[cIndex] != b) count -= 1;
            }
        }
    }
    cout << count << endl;
    return 0;
}


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

const int MAX = 510000;
 const int MOD = 1000000007;
 
 long long fac[MAX], finv[MAX], inv[MAX];
 
 // テーブルを作る前処理
 void COMinit() {
     fac[0] = fac[1] = 1;
     finv[0] = finv[1] = 1;
     inv[1] = 1;
     for (int i = 2; i < MAX; i++){
         fac[i] = fac[i - 1] * i % MOD;
         inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
         finv[i] = finv[i - 1] * inv[i] % MOD;
     }
 }
 
 // 二項係数計算
 long long COM(int n, int k){
     if (n < k) return 0;
     if (n < 0 || k < 0) return 0;
     return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
 }
 
  long long modpow(long long a, long long n) {
      long long res = 1;
      while (n > 0) {
          if (n & 1) res = res * a % MOD;
          a = a * a % MOD;
          n >>= 1;
      }
      return res;
  }

vector<bool> isprime;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n;
    std::cin >> n;
    vector<ll> a(n);
    ll g = 0;
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
        g = __gcd(g,a[i]);
    }
    vector<ll> l(n+1,0);
    vector<ll> r(n+1,0);
    
    for (int i = 0; i < n; i++) {
        l[i+1] = __gcd(l[i],a[i]);
        r[n-i-1]=__gcd(r[n-1-i+1],a[n-i-1]);
    }
    ll res = 0;
    for (int i = 0; i < n; i++) {
        res = max(res,__gcd(l[i],r[i+1]));
    }
    std::cout << res << std::endl;
}



Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_set>
#define lol(i,n) for(ll i=0;i<n;i++)
#define mod 1000000007
#define chmax(a,b) a=max(a,b);
#define chmin(a,b) a=min(a,b);
typedef long long ll;

using namespace std;
ll gcd(ll a,ll b){
  if(a<b)swap(a,b);
  if(b==0)return a;
  return gcd(a%b,b);
}
#define N 2010
ll b[N],a[N],n;
vector<ll> g[N];

class Aoki{
  public:
  ll nz[N];
  void buildg(){
    lol(i,n)g[i].clear();
    lol(i,n)lol(j,i){
      if(gcd(b[i],b[j])>1){
	g[j].push_back(i);
	nz[i]++;
      }
    }
  }
  void main(){
    lol(i,n)nz[i]=0;
    buildg();
    priority_queue<pair<ll,ll> >Q;
    lol(i,n)if(nz[i]==0)Q.push(make_pair(b[i],i));
    vector<ll> res;
    unordered_set<ll> vis;
    while(!Q.empty()){
      ll val=Q.top().first;
      ll x=Q.top().second;
      Q.pop();
      if(vis.find(x)!=vis.end())continue;
      vis.insert(x);
      res.push_back(val);
      for(auto y:g[x]){
	nz[y]--;
	if(nz[y]==0)Q.push(make_pair(b[y],y));
      }
    }
    lol(i,n){
      if(i)cout<<" ";
      cout<<res[i];
    }cout<<endl;
  }
};Aoki kensho;

class Takahashi{
  public:
  void buildg(){
    lol(i,n)lol(j,n){
      if(i!=j&&gcd(a[i],a[j])>1){
	g[i].push_back(j);
      }
    }
    lol(i,n)sort(g[i].begin(),g[i].end());
  }
  unordered_set<ll> vis;
  vector<ll> res;
  void dfs(ll x){
      if(vis.find(x)!=vis.end())return;
      vis.insert(x);
      res.push_back(x);
      for(auto y:g[x])dfs(y);
  }
  void main(){
    buildg();
    lol(i,n)dfs(i);
    lol(i,n)b[i]=a[res[i]];
  }
};Takahashi chokudai;

int main(){
    cin>>n;
    lol(i,n)cin>>a[i];
    sort(a,a+n);
    chokudai.main();
    kensho.main();
    return 0;
}


Measured memory_bytes: 28288
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

using namespace std;

int main(void){
    int t_hp,t_at,a_hp,a_at;
    cin>>t_hp>>t_at>>a_hp>>a_at;
    while(1){
        a_hp-=t_at;
        if(a_hp<=0){
            cout<<"Yes"<<endl;
            break;
        }
        t_hp-=a_at;
        if(t_hp<=0){
            cout<<"No"<<endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3624
#include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

// author:Swastik Banerjee

using namespace std;

typedef long long ll;
#define MOD 1000000007

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


  ll x;
  cin >> x;

  ll wow = log2(x);

  ll ans = pow(2, wow + 1);

  cout << ans - 1 << '\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <queue>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;
typedef long double ld;
#define INF 1e5
int main(){
    int h,w;
    cin>>h>>w;
    vector<vector<char>> maze(h+2,vector<char>(w+2));
    vector<vector<int>> dist(h+2, vector<int>(w+2, INF));
    int white=0;
    REP(i,h+2)REP(j,w+2){
        if(i*j==0||i==h+1||j==w+1)maze[i][j]='#';
        else{
            cin>>maze[i][j];
            if(maze[i][j]=='.')white++;
        }
    }
    vector<int> movel={1,-1,0,0}, movec={0,0,1,-1};
    queue<pair<int,int>> que;
    que.push(make_pair(1,1));
    dist[1][1]=0;
    while(!que.empty()){
        pair<int,int> now=que.front();
        que.pop();
        int l=now.first, c=now.second;
        REP(i,4){
            int nextl=l+movel[i], nextc=c+movec[i];
            if(maze[l][c]=='.'&&dist[nextl][nextc]>dist[l][c]+1){
                dist[nextl][nextc]=dist[l][c]+1;
                que.push(make_pair(nextl, nextc));
            }
        }
    }
    int ans;
    if(dist[h][w]!=INF){
        ans=white-dist[h][w]-1;
    }else{
        ans=-1;
    }
    cout<<ans<<endl;
    return 0;
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll N,M;
vector<pll> abv[55];
ll mk[55];
ll dp[55][1 << 21];
ll i, j, k;

bool dfs(ll a,ll p,ll g,ll l){
    if(g==a){
        return true;
    }
    ll i = 0,j=0;
    fornum(i,0,abv[a].size()){
        ll b = abv[a][i].first;
        if(b==p){
            continue;
        }
        if(dfs(b, a,g,l)){
            mk[l] |= (1ll << abv[a][i].second);
            return true;
        }
    }
    return false;
}
int main(){
    scanf("%lld",&N);
    fornum(i,1,N){
        ll a, b;
        scanf("%lld%lld", &a, &b);
        abv[a].push_back({b, i});
        abv[b].push_back({a, i});
    }
    scanf("%lld", &M);
    fornum(i,0,M){
        ll u, v;
        scanf("%lld%lld",&u,&v);
        dfs(u, 0, v, i);
    }
    /*
    fornum(i,0,M){
        printf("%lld\n", mk[i]);
    }*/
    dp[1][0] = 1;
    fornum(i,1,N){
        ll a = 0;
        fornum(j,0,M){
            if(mk[j]&(1ll<<i))
                a |= 1ll << j;
        }
        fornum(j,0,1<<M){
            //printf("%lld ", dp[i][j]);
            ll b = j | a;
            dp[i + 1][j] += dp[i][j];
            dp[i + 1][b] += dp[i][j];
        }
        //printf("\n");
    }
    printf("%lld", dp[N][(1ll << M) - 1]);
    return 0;
}

Measured memory_bytes: 504192
#include <iostream>

using namespace std;
typedef unsigned long long u64;

u64 n, x;
u64 a[102020];

int main()
{
	cin >> n >> x;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	u64 ans = 0;
	u64 sum = a[0];
	for (int i = 0; i < n - 1; ++i) {
		if (a[i] + a[i + 1] > x) {
			u64 to_reduce = a[i] + a[i + 1] - x;
			if (a[i + 1] >= to_reduce) {
				ans += to_reduce;
				a[i + 1] -= to_reduce;
			} else {
				ans += to_reduce;
				to_reduce -= a[i + 1];
				a[i + 1] = 0;
				a[i] -= to_reduce;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <deque>
#include <unordered_set>

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vii;
typedef vector<pair<int,int>> vip;

#define pb push_back
#define ZOOM ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define LOOP_IT(s) for(auto it=(s).begin();it!=(s).end();++it)
#define loop for(int i=0;i<n;++i)


int main(int argc,char* argv[])
{
    ZOOM


    string s;
    deque<char> q,q2;
    cin>>s;
    int n=s.size();
    for(int i=0;i<n;++i)
    {
        q.push_back(s[i]);
        q2.push_front(s[i]);
    }
    ll query;
    cin>>query;
    ll t,f;
    bool flag=1;
    char ch;
    while(query--)
    {
        cin>>t;
        if(t==1)
            flag=!flag;
        else if(t==2)
        {
            cin>>f>>ch;
            if(f==1)
            {
                if(flag){
                q.push_front(ch);
                q2.push_back(ch);}
                else
                {

                   q.push_back(ch);

                    q2.push_front(ch);
                }
            }
            else if(f==2)
            {
                if(flag)
                {

                q.push_back(ch);     //end

                q2.push_front(ch);
                }
                else{

                    q.push_front(ch);

                    q2.push_back(ch);
                }
            }

        }

    }
    //cout<<(flag?s:s2);
    if(flag)
    {
        LOOP_IT(q)
        {
            cout<<*it;
        }
    }
    else
    {
        LOOP_IT(q2)
        {
            cout<<*it;
        }
    }

    return 0;
}



Measured memory_bytes: 1232
/********************************
Auther: jianwei
blog  : http://blog.csdn.net/jianwei2016
********************************/

#include<bits/stdc++.h>
#define ll long long
#define PI acos(-1)
#define FILEIN freopen("in.txt","r",stdin)
#define FILEOUT freopen("out.txt","w",stdout)
#define CLR(x) memset(x,0,sizeof(x))
#define MEM(a,x) memset(a,x,sizeof(a))
#define PB(x) push_back(x)
#define PF(x) push_front(x)
#define For(x,a,b) for(int x=a;x<b;x++)
#define rFor(x,a,b) for(int x=a;x>b;x--)
#define FOR(x,a,b) for(int x=a;x<=b;x++)
#define rFOR(x,a,b) for(int x=a;x>=b;x--)
#define lowbit(x) (x&(-x))

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
using namespace std;

const double eps = 1e-6;
const ll mod = 1e9+7;
const int maxn = 100100;
const int maxe = 100100;

void Solve()
{
    int a,b,c;
    cin>>a>>b>>c;
    int cnt=0;
    a-=c;
    while(1){
        a-=(b+c);
        if(a<0){
            break;
        }
        else cnt++;
    }
    cout<<cnt<<endl;
}

int main()
{
    //FILEIN
    //FILEOUT
    std::ios::sync_with_stdio(false);
    ll Case=1,cases;
    //cin>>Case;cases=Case;
    while(Case--){
        //printf("Case #%d:",cases-Case);
        Solve();
    }
    return 0;
}


Measured memory_bytes: 256
/* maybemaybemaybeno */
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef long double lld ;
#define f(i,s,n) for(int i=s;i<n;i++) 
// const int MAXN = 2e5+5 ;
#define pb push_back 
#define X first 
#define Y second 
#define pii pair<int,int> 
#define pll pair<ll,ll> 
#define pli pair<ll,int> 
#define pil pair<int,ll> 
#define fio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<setprecision(10) ;
#define is(x) cout<<#x<<" : "<<x<<endl ;
// #define DEBUG

int main()
{
    fio ;
    /* ======================Start of code ================ */

    ll A;ll B ;
    cin>>A ;
    string s ;cin>>s ;
    // string s1(1,s[0]) ;
    // string s2(2,s[2]) ;
    string s1 = s.substr(0,1) ;
    string s2 = s.substr(2,4) ;
    #ifdef DEBUG 
    is(s) ;
    is(s1) ;is(s2) ;
    is(s[0]);is(s[1]);is(s[2]) ;is(s[3]) ;
    #endif 
    // B = stoi((string)s[0])*100+((string)(stoi(s[2]+s[3]))) ;
    B = stoi(s1)*100+stoi(s2) ;
    #ifdef DEBUG 
    is(A);is(B) ;
    #endif 
    cout<<(A*B)/100<<"\n" ;
    /* ======================End of code ================== */
}

Measured memory_bytes: 3652
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int mod = 1e9 + 7;
const int N = 200005;
const int K = 50;
set < int > g1[N], g2[N];
int  invf[N], s[N], dp[N], used[N];
int r, c, n;
bool in(int x, int y){
    if (x > 0 && x < r && y > 0 && y < c) return 1; else return 0;
}
int f(int x, int y){
    if (x == 0) return y;
    if (y == c){
        return c + x + 10;
    }
    if (x == r){
        return c + r + 100 + c - y;
    }
    if (y == 0){
        return c + r + c + 1000 + r - x;
    }
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    cin >> r >> c >> n;
    vector < pair < int, int > > a;
    for (int i = 1; i <= n; i++){
        int x11, y11, x12, y12;
        cin >> x11 >> y11 >> x12 >> y12;
        if (in(x11, y11) || in(x12, y12)) continue;
        a.pb({f(x11, y11), i});
        a.pb({f(x12, y12), i});
    }
    sort(a.begin(), a.end());
    for (int i = 1; i < a.size(); i++){
        if (a[i].S == a[0].S){
            int l = 1;
            int r = i - 1;
            if ((r - l + 1) % 2){
                cout << "NO";
                return 0;
            }
            stack < int > s;
            for (int j = l; j <= r; j++){
                if (!used[a[j].S]){
                    s.push(a[j].S);
                    used[a[j].S] = 1;
                } else{
                    if (s.top() == a[j].S){
                        s.pop();
                    } else{
                        cout << "NO";
                        return 0;
                    }
                }
            }
            r = a.size() - 1;
            l = i + 1;
            if ((r - l + 1) % 2){
                cout << "NO";
                return 0;
            }
            for (int j = l; j <= r; j++){
                if (!used[a[j].S]){
                    s.push(a[j].S);
                    used[a[j].S] = 1;
                } else{
                    if (s.top() == a[j].S){
                        s.pop();
                    } else{
                        cout << "NO";
                        return 0;
                    }
                }
            }
        }
    }
    cout << "YES";
}


Measured memory_bytes: 25200
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 60;

int main() {
  //
  ll n;
  cin >> n;
  vl a(n), b(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  vl a0(n), b0(n);
  ll ans = 0;
  rep(k, 29) {
    rep(i, n) {
      a0[i] = a[i] % (1 << (k + 1));
      b0[i] = b[i] % (1 << (k + 1));
    }
    sort(ALL(b0));
    ll t = (1 << k);
    ll cnt = 0;
    rep(i, n) {
      vl::iterator it1 = lower_bound(ALL(b0), t - a0[i]);
      vl::iterator it2 = lower_bound(ALL(b0), 2 * t - a0[i]);
      vl::iterator it3 = lower_bound(ALL(b0), 3 * t - a0[i]);
      vl::iterator it4 = lower_bound(ALL(b0), 4 * t - a0[i]);
      cnt += (it2 - it1) + (it4 - it3);
    }
    ans = ans + ((cnt & 1) << k);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6528
#include<stdio.h>
#include<algorithm>
int main(){
    int a[5];
    while(~scanf("%d%d%d%d%d",&a[0],&a[1],&a[2],&a[3],&a[4])){
        std::sort(a,a+5);
        for(int i=4;i>0;i--)printf("%d ",a[i]);
        printf("%d\n",a[0]);
    }
}

Measured memory_bytes: 1040
N,X = map(int, input().split())
def myabs(i):
    return abs(i-X)
xlis = list(map(myabs, map(int, input().split())))

from fractions import gcd

res = xlis[0]
for i in xlis:
    if i%res == 0:
        continue
    res = gcd(i,res)

print(res)

Measured memory_bytes: 14252
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
  string s;
  cin >> s;
  cout << (((s[0] == s[1] && s[1] == s[2]) || (s[1] == s[2] && s[2] == s[3])) ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
namespace ALDS1_1_D
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var Rt = new long[n];

            long minsa = long.MaxValue;
            Rt[0] = int.Parse(Console.ReadLine());
            for (int i = 1; i < n; ++i)
            {
                Rt[i] = int.Parse(Console.ReadLine());
            }
            var max = long.MinValue;
            var minv = Rt[0];
            for(int j=1;j<n;++j)
            {
                max = Math.Max(Rt[j] - minv, max);
                minv = Math.Min(minv, Rt[j]);
            }
            Console.WriteLine(max);
        }
    }
}


Measured memory_bytes: 23140
#include <stdio.h>
void maxHeapify(int[], int);
void buildMaxHeap(int[]);
int H;

int main()
{
  int i,A[500000];

  scanf("%d",&H);
  for(i=1;i<=H;i++) scanf("%d",&A[i]);
  maxHeapify(A, i);
  buildMaxHeap(A);

  for(i=1;i<=H;i++) printf(" %d",A[i]);
  //printf("%d\n",A[H]);
  printf("\n");
  return 0;
}

void maxHeapify(int A[],int i)
{
  int l,r,largest,temp;

  l = i*2;
  r = l+1;

  // ????????????????????????????????§???????????§????????????????????¶
  if(l <= H && A[l] > A[i]) largest = l;
  else largest = i;
  if( r <= H && A[r] > A[largest]) largest = r;
	       
  if(largest != i){  // i ???????????????????????§????????´???
    temp=A[i];
    A[i]=A[largest];
    A[largest]=temp;
    maxHeapify(A, largest); // ?????°??????????????????
  }	     
}

void buildMaxHeap(int A[])
{
  int i;
  for(i=H/2;i>=1;i--) maxHeapify(A, i);
}

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

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

	long long ans = 0;
	for( int x = 1; x <= N; x++ ) {
		if( x % 3 == 0 || x % 5 == 0 ) continue;
		ans += x;
	}

	cout << ans << endl;
}


Measured memory_bytes: 3624
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        new Program().Calc();
    }

    Scanner cin;

    public Program() { }

    bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; }

    void Calc()
    {
        cin = new Scanner();

        int A = cin.nextInt();
        int P = cin.nextInt();

        WriteLine(((A * 3) + P) / 2);
    }
}

public static class StringExtension
{
    public static char GetChar1(this string str, int indexOneBase)
    {
        return str[indexOneBase - 1];
    }
}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,q,a,b,c;
    scanf("%d %d",&n,&q);
    vector<int>v[n];
    while(q--)
    {
        scanf("%d %d",&a,&b);
        if(a==0)
        {
            scanf("%d",&c);
            v[b].push_back(c);
        }
        else if(a==1)
        {
            for(int i=0;i<v[b].size();i++)
            {
                if(i) printf(" ");
                printf("%d",v[b][i]);
            }
             printf("\n");
        }
        else v[b].clear();
    }

    return 0;
}



Measured memory_bytes: 5880
def main():
    n, *a = map(int, open(0).read().split())
    ans = 0
    t = 0
    for p, q in zip(a, a[1:]):
        p += t
        if p > q:
            ans += (p - q)
            t = (p - q)
        else:
            t = 0
    print(ans)


if __name__ == '__main__':
    main()


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


int main() {
  int a,b ;
  cin >>a >>b;
  
  string s=to_string(a);
  string t=to_string(b);
  string x,y;
    for(int i=0;i<b;i++){
      x+=s;
    }
    for(int i=0;i<a;i++){
      y+=t;
    }
  if(x<=y){
  cout << x << endl;
  }
  else{
    cout << y << endl;
  }
}
      

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String line;
		int H=0;
		int W=0;
		int resultW =0;
		int end = 0;
		boolean first = true;
		try{
			while(in.hasNext()){
				line = in.nextLine();
				if(first){
					String[] spStr = line.split(" ",0);
					 H = Integer.parseInt(spStr[0]);
					 W = Integer.parseInt(spStr[1]);
					resultW = W + 2;
					printSharp(resultW);
					System.out.println();
					first = false;
				}else{
					System.out.println("#"+line+"#");
					end++;
				}
				if(end == H){
					break;
				}
			}
			printSharp(resultW);
			System.out.println();
		}catch(Exception e){}

	}

	public static void printSharp(int count){
		for(int i=0;i<count;i++){
			System.out.print("#");
		}
	}

}


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

using namespace std;
            
long long a[100001];	
long long b[100001];
map <int, int> u;

int main () {
	int n;
	cin >> n;
	for (int i = 1;i <= n;i ++) {
		cin >> a[i];
		b[i] = a[i];
	}
	sort (b + 1, b + n + 1);
	for (int i = 1;i <= n;i ++) {
		u[b[i]] = i % 2;
	}
	int ans = 0;
	for (int i = 1;i <= n;i ++) {
		ans += abs ((i % 2) - u[a[i]]);
	}
	cout << ans / 2;
	return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main(){
	int x,y;
	char ch;
	multimap<int,int> a;
	while(1){
		cin >> x >> ch >> y;
		if(x==0 && y==0) break;
		a.insert( make_pair(30-y,x) );
	}
		
	for(;;){
		int n;
		if(! (cin >> n) ) return 0;
		int rank=0;
		int score=-1;
		multimap<int,int>::iterator it;
		for(it=a.begin();it!=a.end();it++){
			 if(it->first != score){
                		score = it->first;
               			 ++ rank;
           		 }
           		 if(it->second == n){
             			   cout << rank << endl;
             			   break;
           		 }   
		}	
	}
}

Measured memory_bytes: 1192
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N;

LL ans = 0;

priority_queue<LL> num753;
void generate_num753(LL num,LL digit){
	if(digit<1000000000LL){
		generate_num753(num + digit*7,digit*10LL);
		generate_num753(num + digit*5,digit*10LL);
		generate_num753(num + digit*3,digit*10LL);
	}
	if(digit>100LL) num753.push(-num);
}

void solve(){
	generate_num753(0,1);
	while(!num753.empty()){
		LL num = -num753.top();
		num753.pop();
		if(N>=num){
			bool a_3 = false,a_5 = false,a_7 = false;
			while(num>0){
				if(num%10==3) a_3 = true;
				if(num%10==5) a_5 = true;
				if(num%10==7) a_7 = true;
				num /= 10;
			}
			if(a_3 && a_5 && a_7)ans++;
		}
		else break;
	}
}
 
int main(){
    cin >> N;
 
    solve();

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

Measured memory_bytes: 640
MOD = 10 ** 9 + 7
n = int(input())
m = 65
a = list(map(int, input().split()))
b = [[0] * n for i in range(m)]

for i in range(n):
    for j in range(m):
        b[j][i] = (a[i] >> j) & 1

ans = 0
d = 1
for i in range(m):
    s = sum(b[i])
    ans += s * (n-s) * d
    ans %= MOD
    d *= 2

print(ans % MOD)


Measured memory_bytes: 197696
def chmin(a,b):
    if a > b:
        return b
    else:
        return a

def chmax(a,b):
    if a < b:
        return b
    else:
        return a

n = int(input())
hs = list(map(int, input().split()))

f_inf = float('inf')

dp = [f_inf] * (10**5+10)

dp[0] = 0

for ii in range(1, n):
    dp[ii] = chmin(dp[ii], dp[ii-1] + abs(hs[ii] - hs[ii-1]))
    if ii > 1:
        dp[ii] = chmin(dp[ii], dp[ii-2] + abs(hs[ii] - hs[ii-2]))

print(dp[n-1])

Measured memory_bytes: 13928
a,b,c=map(int,input().split())
if (a==b and b==c and a==c):
  print(1)
elif(a==b and b!=c):
  print(2)
elif(b==c and c!=a):
  print(2)
elif(c==a and a!=b):
  print(2)
else:
  print(3)

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

#define int long long

signed main()
{
    int n;
    cin >> n;
    vector<int> d(n);
    for(int i = 0; i < n; ++i)
    {
        cin >> d[i];
        d[i] *= 2;
    }

   
    int x = d[0] - d[1];
    int y = 0;

    for(int i = 2; i < n; ++i)
    {
        if(i&1)
        {
            y += d[i];
        }
        else
        {
            y -= d[i];
        }
    }

    x = x - y;
    x/=2;
    int z = x;
    cout << x << " ";
    for(int i = 0; i < n - 2; ++i)
    {
        cout << (d[i] - x) << " ";
        x = (d[i] - x);
    }
    
    cout << (d[n-1] - z);
    

    // for(int i = 0; i < n - 1; ++i)
    // {
    //     cout << (d[i] - x) << " ";
    // }
}

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

public class Main {
	private static void solve(){
		//Implement solution here.
		int N = ni();
		char[] c = next().toCharArray();
		int wcnt = 0;
		int result = 0;
		//int[] wcnt = new int[N];
		for(int i = 0; i < N; i++) {
			wcnt += c[i] == 'W' ? 1 : 0;
		}
		
		for(int i = N - 1; i >= N - wcnt; i--) {
			if(c[i] == 'R') {
				result ++;
			}
		}
		
		System.out.println(result);
	}


	//Switch input source (stdin/file)
	private static BufferedReader br;
	public static void main(String[] args){
		br = new BufferedReader(new InputStreamReader(System.in));
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		boolean hasNext = true;
		while(hasNext){
			solve();	
			try{
				br.mark(1);
				if(br.read() > 0){
					br.reset();			
					System.out.println("---");
				} else {
					hasNext = false;
				}
			}catch(Exception e){
				throw new RuntimeException(e);
			} 
		}
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}


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

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


a = make_divisors(n)

b = []
for i in a:
     if i-1 in a:
          b.append(i)

a = a[len(a)//2:]
if n//a[0] == a[0]:
     a = a[1:]

for i in b:
     if i in a:
          a.remove(i)

print(sum(a)-len(a))

Measured memory_bytes: 39024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd (ll a, ll b) { return b == 0 ? a : gcd (b, a % b); }

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a, b;
    cin >> a >> b;
    
    ll n = gcd(a, b);
    
    vector<ll> factor;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            factor.push_back(i);
            if(i * i != a) factor.push_back(n/i);
        }
    }
    sort(factor.begin(), factor.end());
    
    int len = factor.size();
    vector<int> used(len, 0);
    int ans = 0;
    for (int i = 0; i < len; i++) {
        if (used[i]) continue;
        if (factor[i] == 1) ans++;
        else {
            ans++;
            for (int j = i + 1; j < len; j++) {
                if (factor[j] % factor[i] == 0) {
                    used[j] = 1;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int (i)=(a);i<(b);i++)
#define INF 1000000000
using namespace std;
bool debug=false;

int main(){
  long long a,b,c;
  long long sum=0;
  cin>>a>>b>>c;
  bool ok=false;
  for(int i=1;i<=110;i++){
    sum+=a;
    if(sum%b==c)ok=true;
  }
  if(ok)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 256
def solve(n, m, list1):
    left = 0
    right = n
    for i in range(len(list1)):
        left = max(list1[i][0], left)
        right = min(list1[i][1], right)
    return max(right-left+1, 0)

n, m = map(int, input().split())
list1 = []
for _ in range(m):
    list1 += [list(map(int, input().split()))]
print(solve(n, m, list1))

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

int main()
{
    long long a, b, x;
    cin >> a >> b >> x;

    long long ans1, ans2;
    if (a == 0)
    {
        ans1 = 0;
    }
    else
    {
        ans1 = (a - 1) / x + 1;
    }

    if (b == 0)
    {
        ans2 = 1;
    }
    else
    {
        ans2 = b / x + 1;
    }

    cout << ans2 - ans1 << endl;

    return 0;
}

Measured memory_bytes: 256
//Wrong answer on test inf.
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define ll long long
#define inf 1000000001
#define y1 y1___
#define pss pair<string,string>
using namespace std;
ll read(){
	char ch=getchar();ll x=0;int op=1;
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') op=-1;
	for (;isdigit(ch);ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
	return x*op;
}
#define N 50
int n;char s[N];ll ans;
map<pss,int> mp;
void dfs(int k,string s1,string s2){
	if (k>n){
		// cerr<<s1<<' '<<s2<<'\n';
		mp[pss(s1,s2)]++;
		return;
	}
	dfs(k+1,s1+s[k],s2);
	dfs(k+1,s1,s2+s[k]);
}
void dfs2(int k,string s1,string s2){
	if (k>2*n){
		string s1_=s1;reverse(s1_.begin(),s1_.end());
		string s2_=s2;reverse(s2_.begin(),s2_.end());
		swap(s1_,s2_);
		ans+=mp[pss(s1_,s2_)];
		return;
	}
	dfs2(k+1,s1+s[k],s2);
	dfs2(k+1,s1,s2+s[k]);
}
int main(){
	n=read();scanf("%s",s+1);
	dfs(1,"","");
	dfs2(n+1,"","");
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 84992
from math import gcd

s = input()
x, y = s.split(".")
if "(" in s:
  da = y.index("(")
  db = y.index(")") - 1
  ya, b = y.split("(")
  lb = len(b) - 1
  a = int(x + ya)
  b = int(b[:-1])
  deco = a * (10 ** db - 10 ** (db - lb)) + b * 10 ** da
  nume = 10 ** da * (10 ** db - 10 ** (db - lb))
  div = gcd(deco, nume)
  print(deco // div, nume // div, sep="/")
else:
  da = len(y)
  a = int(x + y)
  deco = a
  nume = 10 ** da
  div = gcd(deco, nume)
  print(deco // div, nume // div, sep="/")


Measured memory_bytes: 5664
#include<stdio.h>
int main(){
  int prime[10001];
  int i, k, n, max = 0;
  for(i = 2; i <= 10000; i++){
    prime[i] = 1;
  }
  for(i = 2; i*i <= 10000; i++){
    if(prime[i]){
      for(k = 2 * i; k <= 10000; k += i){
        prime[k] = 0;
      }
    }
  }
  while(1){ 
    scanf("%d", &n);
    if(n == 0) break;
    for(i = 2; i <= n; i++){
      if(max < i && prime[i] == 1 && prime[i-2] == 1) max = i;
    }
    printf("%d %d\n", max-2, max);
    max = 0;
  }
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>                                                                          
using namespace std;
int main()
{
  string S;
  cin >> S;
  int count=0;
  if(S.at(0)=='A')
    count++;
  int C_count=0;
  for(int i=2; i<S.size()-1; i++){
    if(S.at(i)=='C')
      C_count++;
  }
  if(C_count==1)
    count++;
  int small_count=0;
  for(int i=0; i<S.size(); i++){
    if(S.at(i)!='A' && S.at(i)!='C'){
      if(S.at(i)>='a' && S.at(i)<='z')
        small_count++;
    }
  }
  if(small_count==S.size()-2)
    count++;
  if(count==3)
    cout << "AC" << endl;
  else
    cout << "WA" << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import deque
 
S = input().rstrip()
S = deque(S)
Q = int(input())
Que = (input().rstrip() for _ in range(Q))
 
flag = 0 #0:そのまま 1:反転
for elem in Que:
  if elem[0] == '1':
    flag ^= 1
  else:
    s = int(elem[2])
    if s == 1 and flag == 0:
      S.appendleft(elem[4])
    elif s == 2 and flag == 0:
      S.append(elem[4])
    elif s == 1 and flag == 1:
      S.append(elem[4])
    else:
      S.appendleft(elem[4])
 
if flag == 1:
  S.reverse()
print(''.join(S))

Measured memory_bytes: 8428
require 'prime'
loop do
  m, a, b = gets.split.map(&:to_i)
  break if m == 0
  ans = [0, 0]
  prod = 0
  prime = Prime.each.lazy.take_while{ |p| p < 100000 }.to_a
  prime.take_while{ |x| x * x <= m && x < Math.sqrt(100000) }.each do |p|
    q = prime.drop_while{ |x| x < p  }
             .take_while{ |x| a * x <= b * p && p * x <= m }.to_a.last
    if q && p * q > prod
      ans = [p, q]
      prod = p * q
    end
  end
  puts ans * ' '
end

Measured memory_bytes: 10016