akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
const int MAX = 100;
const int NIL = -1;

struct Node
{
	int pa;
	int left;
	int right;
};

Node Tree[MAX];
int root = 0;

void print_pre(int r);
void print_in(int r);
void print_post(int r);

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

	for (int i = 0; i < n; i++)
	{
		Tree[i].pa = Tree[i].left = Tree[i].right = NIL;
	}

	for (int i = 0; i < n; i++)
	{
		int num, l, r;
		cin >> num >> l >> r;
		Tree[num].left = l;
		Tree[num].right = r;
		if (l != NIL)
			Tree[l].pa = num;
		if (r != NIL)
			Tree[r].pa = num;
	}

	
	for (int i = 0; i < n; i++)
	{
		if (Tree[i].pa == NIL)
		{
			root = i;
			break;
		}
	}


	cout << "Preorder" << endl;
	print_pre(root);
	cout << endl;

	cout << "Inorder" << endl;
	print_in(root);
	cout << endl;

	cout << "Postorder" << endl;
	print_post(root);
	cout << endl;

// 	int junk;
// 	cin >> junk;
	return 0;
}

void print_pre(int r)
{
	cout << " " << r;
	if (Tree[r].left != NIL)
		print_pre(Tree[r].left);
	if (Tree[r].right != NIL)
		print_pre(Tree[r].right);
	return;
}

void print_in(int r)
{
	if (Tree[r].left != NIL)
		print_in(Tree[r].left);

	cout << " " << r;

	if (Tree[r].right != NIL)
		print_in(Tree[r].right);
	return;
}

void print_post(int r)
{
	if (Tree[r].left != NIL)
		print_post(Tree[r].left);
	if (Tree[r].right != NIL)
		print_post(Tree[r].right);

	cout << " " << r;
	return;
}

Measured memory_bytes: 3076
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstdio>

using namespace std;

const long long INF = 100000000000;
const long long MOD = 1000000007;

bool f(long long N){
  string s = to_string(N);
  long long slen = s.length();
  slen--;
  for (int i = 0; i < s.length(); i++)
  {
    if(s[i]!=s[slen-i])
      return false;
  }
  return true;
}

int main()
{
  long long A, B, C,K;
  cin >> A >> B >> C>>K;
  priority_queue<long long> que;
  que.push(A);
  que.push(B);
  que.push(C);

  for (int i = 0; i < K;i++){
    long long u = que.top();
    que.pop();
    u *= 2;
    que.push(u);
  }
  long long ans = 0;
  while (!que.empty())
  {
    long long u = que.top();
    que.pop();
    ans += u;
  }
  cout << ans << endl;
}


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

int main(){
	while(1){
		int n,m;
		cin>>n>>m;
		if(n==0&&m==0) break;
		tuple<int,int,int> li[20000];
		lp(i,m){
			int a,b,c;
			cin>>a>>b>>c;
			li[i]=make_tuple(a,b,c);
		}
		sort(li,li+m);
		set<int> inflist;
		inflist.clear();
		inflist.insert(1);
		int count=1;
		lp(i,m){
			int a,b;
			a=get<1>(li[i]);
			b=get<2>(li[i]);
			decltype(inflist)::iterator it=inflist.find(a);
			if(it!=inflist.end()){
				it=inflist.find(b);
				if(it==inflist.end()){
					inflist.insert(b);
					count++;
				}
			}
		}
		cout<<count<<endl;
	}
return 0;
}


Measured memory_bytes: 4200
K = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
i = int(input())
print(K[i-1])

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

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

int main() {
    int a, b;
    while (cin >> a >> b) {
        cout << gcd(a, b) << endl;
    }
    return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define mp make_pair
#define sqr(x) (x)*(x)
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int maxn=100007;
const ll inf=0x3f3f3f3f;
const int mod=998244353;
#define rep(i,x,y) for(auto i=(x);i<=(y);++i)
#define dep(i,x,y) for(auto i=(x);i>=(y);--i)
int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*f;
}
int a[maxn];
int main(){
    int n=read(),m=read();
    rep(i,1,m){
        int x=read();
        rep(k,1,x){
            int y=read();a[y]++;
        }
    }
    int ans=0;
    rep(i,1,n) ans+=!a[i];
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3636
N, Y=list(map(int, input().split()))
ans=[-1, -1, -1]
flag=False
for x in range(N, -1, -1):
    for y in range(N-x, -1, -1):
        if 10000*x+5000*y+1000*(N-x-y)==Y:
            ans=[x,y,N-x-y]
            flag=True
            break
        if flag==True:
            break
    if flag==True:
        break
print(ans[0],ans[1],ans[2])


Measured memory_bytes: 3060
/*
 * Created by Timothy Wang on 5/9/2020.
 * B - Iroha Loves Strings (ABC Edition)
 * https://atcoder.jp/contests/abc042/tasks/abc042_b
 */
#include<bits/stdc++.h>
using namespace std;

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int N, L; cin >> N >> L;
    string a[N];
    for(int i = 0; i < N; i++) {
        cin >> a[i];
    }
    sort(a, a+N);
    for(int i = 0; i < N; i++) {
        cout << a[i];
    }
    return 0;
}

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

# define ll long long

int main(){
 
  string S;
  cin >> S;
  vector<char> stack;
  
  for(int i=0; i<S.size(); i++){
    if(S[i] == 'S') stack.push_back(S[i]);
    else {
      if(!stack.empty() && stack.back() == 'S') stack.pop_back();
      else stack.push_back(S[i]);
    }
  }
  
  cout << stack.size() << endl;
  return 0;
} 



Measured memory_bytes: 3780
#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 x, n;
	cin >> x >> n;
	vector<int> a(n);
	rep(i, n){
		cin >> a[i];
	}
	int xl = x;
	int xr = x;
	int ansl = 1000000000;
	int ansr = 1000000000;
	int f = 0;
	sort(a.begin(), a.end());
	while(f == 0){
		if(!binary_search(a.begin(), a.end(), xl)){
			ansl = xl;
			f = 1;
		}
		if(!binary_search(a.begin(), a.end(), xr)){
			ansr = xr;
			f = 1;
		}
		xl--;
		xr++;
	}
	cout << min(ansl, ansr) << endl;
	return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

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

		int A = sc.nextInt();
		int B = sc.nextInt();
		int X = sc.nextInt();
		String ans = "";

		if ( A > X ) {
			ans = "NO" ;
		} else if (A <= X ) {
			if ( X-A <= B) {
			ans = "YES" ;
			} else if (B <X-A) {
				ans = "NO" ;
			}
		}

		System.out.println( ans );
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <cctype>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef string::const_iterator State;

map<char, int> op;

ll term1(State&);
ll term2(State&);
ll term3(State&);
ll factor(State&);
ll number(State&);

ll calc(ll x, char c, ll y){
    if (c == '+') x += y;
    if (c == '-') x -= y;
    if (c == '*') x *= y;
    return x;
}

ll term1(State &begin){
    ll ret = term2(begin);
    while (1){
        if (op[*begin] == 1){
            char c = *begin;
            begin++;
            ret = calc(ret, c, term2(begin));
        }else{
            break;
        }
    }
    return ret;
}

ll term2(State &begin){
    ll ret = term3(begin);
    while (1){
        if (op[*begin] == 2){
            char c = *begin;
            begin++;
            ret = calc(ret, c, term3(begin));
        }else{
            break;
        }
    }
    return ret;
}

ll term3(State &begin){
    ll ret = factor(begin);
    while (1){
        if (op[*begin] == 3){
            char c = *begin;
            begin++;
            ret = calc(ret, c, factor(begin));
        }else{
            break;
        }
    }
    return ret;
}

ll factor(State &begin){
    if (*begin == '('){
        begin++;
        ll ret = term1(begin);
        begin++;
        return ret;
    }else{
        return number(begin);
    }
}

ll number(State &begin){
    int ret = 0;
    while (isdigit(*begin)){
        ret *= 10;
        ret += *begin - '0';
        begin++;
    }
    return ret;
}

int main() {
    ll res = 0;
    bool f = 1;
    string s;
    cin >> s;
    REP(i,3) REP(j,3) REP(k,3){
        op['+'] = i+1;
        op['-'] = j+1;
        op['*'] = k+1;
        State begin = s.begin();
        if (f) res = term1(begin), f = 0;
        else res = max(res, term1(begin));
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3196
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	// Code for D - Dice in Line
	var N, K int
	fmt.Scan(&N, &K)

	sc.Split(bufio.ScanWords)
	p := make([]int, N)
	var temp int
	sum := make([]int, N)
	for i := 0; i < N; i++ {
		p[i] = nextInt()
		temp += p[i]
		sum[i] = temp
	}

	var max int
	var maxNum int
	var count int
	for i := 0; i < N-K+1; i++ {
		if i == 0 {
			count = sum[i+K-1]
		} else {
			count = sum[i+K-1] - sum[i-1]
		}

		if max < count {
			max = count
			maxNum = i
		}
	}

	var ans float64
	for i := 0; i < K; i++ {
		ans += (float64(p[maxNum+i]) + 1.0) / 2.0
	}
	fmt.Println(ans)
}


Measured memory_bytes: 5884
/*******Bismillahir-Rahmanir-Rahim**********/
/*
Name         : Abu Rifat Muhammed Al Hasib
Institution  : University of Barisal, Bangladesh
Github       : abu-rifat
Codeforces   : AbuRifatMuhammed
AtCoder      : aburifat
codechef     : aburifat
SPOJ         : abu_rifat
UvaOJ        : aburifat
DevSkill     : abu_rifat
lightoj      : Abu Rifat Muhammed Al Hasib
facebook     : https://www.facebook.com/a.r.m.al.hasib/
linkedin     : https://www.linkedin.com/in/abu-rifat-534258142/
Email        : rifat.cse4.bu@gmail.com, armalhasib@gmail.com
*/

/*
Contest         : Beginner Contest 158
Online Judge    : AtCoder
Solving Method  :
*/

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MX 250009
#define pb push_back

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll t;
    t=1;
    //cin>>t;
    for(ll T=1;T<=t;T++)
    {
        ll n, a, b;
        cin>>n>>a>>b;
        ll sum=(a+b);
        ll rem, rep;
        rem=n%sum;
        rep=n/sum;
        ll ans=(rep*a)+min(a,rem);
        cout<<ans<<endl;
    }
    return 0;
}

/***********Alhamdulillah***********/



Measured memory_bytes: 256
#include <climits>
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
using int64    = long long;
using PII      = pair<int, int>;
const int MAXN = 200005;
const int INF  = 0x3f3f3f3f;

int64 a[MAXN], b[MAXN];
set<double> m;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
#endif
    int n;
    cin >> n;
    for(int i=0;i<n;i++) {
        cin >> a[i];
        cin >> b[i];
    }
    sort(a,a+n);
    sort(b,b+n);
    if(n&1) cout << b[(n-1)/2] - a[(n-1)/2] + 1 << endl;
    else cout << b[n/2]+b[(n-1)/2]-a[n/2]-a[(n-1)/2] + 1 << endl;
}


Measured memory_bytes: 6292
#include<stdio.h>
int main(){
  int w,n,i,j,t,b,c,tmp;
  scanf("%d",&w);
  scanf("%d",&n);
  int a[31];
  for(i=1;i<=w;i++){
    a[i]=i;
  }
  for(j=0;j<n;j++){
    scanf("%d,%d",&b,&c);
    tmp=a[b];
    a[b]=a[c];
    a[c]=tmp;
  }
  for(t=1;t<=w;t++){
    printf("%d\n",a[t]);
  }
  return (0);
}

Measured memory_bytes: 596
//もう一度

#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;
    cin>>n;
    map<string, int> mp;
    rep(i, n){
        string str;
        cin >> str;
        sort(str.begin(), str.end());
        mp[str]++;
    }
    ll ans = 0;
    for (auto itr: mp){
        int temp = itr.second;
        if (temp != 1) ans += (ll)temp * (temp-1) / 2;
    }
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;

int main(){
    int n,m;
    cin>>n>>m;
    std::vector<std::pair<int64_t,int>> ab(n);
    for(int i=0;i<n;i++){
        cin>>ab[i].first>>ab[i].second;
    }
    sort(ab.begin(),ab.end());
    int count=0;
    int64_t res=0;
    for(int i=0;i<n;i++){
        if(count+ab[i].second>=m){
            res+=(m-count)*ab[i].first;
            break;
        }
        else{
            res+=ab[i].first*ab[i].second;
            count+=ab[i].second;
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 1792
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int a = sc.nextInt();

        if(h%a != 0){
        System.out.println((h/a) + 1);
        }else{
            System.out.println(h/a);
        }
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace __gnu_pbds;
using namespace std;
/*
int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
*/
#define ull unsigned long long int
#define ll long long int
#define MAX 1000000007
//1e9+7
#define pll pair<ll,ll>
#define pii pair<int,int>
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FO ifstream fin("a.in");ofstream fout("a.out");
#define TEST int testcase;cin>>testcase;while(testcase--)
#define all(x) (x).begin(),(x).end()
#define mset0(x) memset((x), 0, sizeof((x)));
#define mset1(x) memset((x), -1, sizeof((x)));
#define endl "\n"
typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
void solve(){
    ll n,ans=0;
    cin>>n;
    map<ll,ll> mp;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0){
            while(n%i==0){
                n/=i;
                mp[i]++;
            }
        }
    }
    if(n>1) mp[n]++;
    for(auto p:mp){
        //cout<<p.first<<" "<<p.second<<endl;
        ll pp=p.second;
        ll com=0;
        while(com*(com+1)<pp*2) com++;
        if(com*(com+1)>pp*2) com--;
        //cout<<com<<endl;
        ans+=com;
    }
    cout<<ans;
    return;
}
int main(){
    IO
    //TEST
    solve();
    return(0);
}


Measured memory_bytes: 3648
n, k = map(int, input().split())
p = list(map(int, input().split()))
kitai = [0] * n
ans = 0
for i in range(n):
    kitai[i] += (p[i] + 1) / 2
ruiseki = [0] * (n + 1)
for i in range(1, n + 1):
    ruiseki[i] += ruiseki[i - 1] + kitai[i - 1]
for i in range(n - k + 1):
    ans = max(ans, ruiseki[k + i] - ruiseki[i])
print(ans)


Measured memory_bytes: 25060
s = input()

y = int(s[:4])
m = int(s[5:7])
d = int(s[8:])

yup = False
if y < 2019:
  yup = True
elif y == 2019:
  if m < 4:
    yup = True
  elif m == 4:
    if d <= 30:
      yup = True
    
      
      
if not yup:print('TBD')
else : print('Heisei')


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

unordered_set<int> primer;

bool divisor(int n){
  for(int i = 2; i * i <= n; i++){
    if(n % i == 0){
      if(primer.count(i)) return false;
      else primer.insert(i);
    }
    while(n % i == 0){
      n /= i;
    }
  }
  if(n != 1){
    if(primer.count(n)) return false;
    else primer.insert(n);
  }
  return true;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  long long N;
  cin >> N;
  bool setwise = false, pairwise = false;
  vector<int> A(N);
  bool allone = true;

  for(int i = 0; i < N; i++){
    cin >> A[i];
    if(A[i] != 1){
      allone = false;
    }
  }
  //gcd of all
  int Gcd = A[0];
  for(int i = 1; i < N; i++){
    Gcd = __gcd(A[i], Gcd);
  }
  if(Gcd == 1){
    setwise = true;
  }

  if(N <= 80000){
    int i = 0;
    while(i < N && divisor(A[i])){
      i++;
    }
    if(i == N){
      pairwise = true;
    }
  }
  if(allone){
    cout << "pairwise coprime" <<endl;
    return 0;
  }
  if(pairwise) cout << "pairwise coprime" <<endl;
  else if(setwise) cout << "setwise coprime" <<endl;
  else cout << "not coprime"<<endl;
}



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

const int MAX = 2000000;
const ll MOD = 1000000007;

ll 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(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll powmod(ll a, ll p){
  ll res = 1;
  while(p > 0){
    if(p & 1){
      res *= a;
      res %= MOD;
    }
    a *= a;
    a %= MOD;
    p >>= 1;
  }
  return res;
}

int main(){
  COMinit();
  ll k; cin >> k;
  string s; cin >> s;
  ll n = s.size() + k;
  ll ans = 0;
  for(ll i = s.size(); i <= n; i++){
    ans += powmod(25, i - (int)s.size())*powmod(26, n - i) % MOD * COM(i-1,(ll)s.size() - 1) % MOD;
  }
  ans %= MOD;
  cout << ans << endl;
}

Measured memory_bytes: 52124
import bisect

N=int(input())
NL=[0]+list(map(int,input().split()))+[10**9]
NL.sort()
M=int(input())
ML=list(map(int,input().split()))

ans=0
for i in ML:
    if NL[bisect.bisect_left(NL,i)]==i:
        ans+=1
print(ans)


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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)

void FIO()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int32_t main()
{
	FIO();
	int a, b, c, d; cin >> a >> b >> c >> d;
	int op1 = a * c;
	int op2 = a * d;
	int op3 = b * c;
	int op4 = b * d;

	cout << max({op1, op2, op3, op4}) << '\n';
	return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a;
  cin>>a;
  string s;
  cin>>s;
  vector<int> ans;
  for(int i=0;i<s.size()-1;i++){
    set<char> st;
    for(int k=0;k<=i;k++){
      st.insert(s[k]);
    }
    
    int cnt=0;
    set<char> st2;
    for(int j=i+1;j<s.size();j++){
      st2.insert(s[j]);
    }
    
    for(auto& e:st2){
      if(st.find(e)!=st.end()){
        cnt++;
      }
    }
    
    ans.push_back(cnt);
  }
  cout<<*max_element(ans.begin(),ans.end());
  
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <climits>

using namespace std;

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

typedef long long LL;
typedef vector<int> VI;

int gcd(LL m, LL n) {
  LL temp;
  while (m % n != 0) {
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

int main() {
  LL A, B;
  cin >> A >> B;
  cout << A*B / gcd(A, B) << endl;;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int m, d;
    std::cin >> m >> d;
    int ret = 0;
    for (int i = 1; i <= m; i++) for (int j = 22; j <= d; j++) {
        if (j % 10 < 2 || j / 10 < 2) continue;
        if (j % 10 * (j / 10) == i) {
            ret++;
        }
    }
    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){

    int a, b;

    scanf("%d %d", &a, &b);

    if (a < b){
    	printf("a < b\n");
    } else if (a == b){
    	printf("a == b\n");
    } else{
    	printf("a > b\n");
    }

    return 0;
}

Measured memory_bytes: 580
#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() {
  string n;
  cin >> n;

  // rep(i, 3) {
  //   if (n.at(i) == '7') {
  //     cout << "Yes" << endl;
  //     return 0;
  //     }
  //   }

  // 文字列検索
  if (n.find("7") != string::npos)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3600
import java.util.*;

public class Main {
	public static void main(String... args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		if (a + b > c * 2) {
			if (x - y > 0) {
				if (a > c * 2) {
					System.out.println(c * x * 2);
				} else {
					System.out.println(c * y * 2 + a * (x-y));
				}
			} else {
				if (b > c * 2) {
					System.out.println(c * y * 2);
				} else {
					System.out.println(c * x * 2 + b * (y-x));
				}
			}
		} else {
			System.out.println(a * x + b * y);
		}
	}
}


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

#ifdef LOCAL
#include "../debug.h"
#else
#define debug(x...) 141
#endif
#define forn(i,x,n) for(int i = x; i < n; ++i)
#define forit(it, m) for(auto it = m.begin(); it!=m.end(); ++it)
typedef long long ll;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    ll x=1,ai;
    bool zero=false,b=true;

    {
        cin>>n;

        forn(i,0,n){
        	cin>>ai;
        	// debug(log10(x)+log10(ai),x*ai-(ll)1e18);
        	if(ai==0)
        		zero=true;
        	else if(!zero && log10(x)+log10(ai)>18)
        		b=false;
        	else if(x*ai>(ll)1e18)
        		b=false;
        	else if(!zero)
        		x*=ai;
        }
        if(zero)
        	cout<<0<<'\n';
        else if(b)
        	cout<<x<<'\n';
        else
        	cout<<-1<<'\n';
    }
    return 0;
}

Measured memory_bytes: 3916
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#solve
def solve():
    n, M = LI()
    a = LI()
    a.sort()
    l = 2 * (10 ** 5) + 1
    r = 2
    def f(m):
        tmp = 0
        for i in range(n):
            tmp += bisect_left(a, m - a[i])

        return n ** 2 - tmp >= M
    while l - r > 1:
        m = (l + r) // 2
        if f(m):
            r = m
        else:
            l = m
    ans = 0
    tmp = 0
    for i in range(n):
        b = n - bisect_left(a, r + 1 - a[i])
        tmp += b
        ans += a[i] * b * 2
    tmp = M - tmp
    ans += tmp * r
    print(ans)
    return


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


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

a = list(map(int,input().split()))

cumsum_a = a.copy()

for i in range(n-1, -1, -1):
    cumsum_a[i] += cumsum_a[i+1]

ans = 0
childable_node = 1

for i in range(n + 1):
    if a[i] > childable_node:
        ans = -1
        break

    ans += childable_node

    if i < n:
        b_max1 = 2 * (childable_node - a[i])
        b_max2 = cumsum_a[i + 1]
        childable_node = min(b_max1, b_max2)

print(ans)

Measured memory_bytes: 20016
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(true) {
			int n = stdIn.nextInt();
			int m = stdIn.nextInt();
			int a = stdIn.nextInt();
			if(n == 0 && m == 0 && a == 0) break;
			Line[] line = new Line[m];
			for(int i = 0; i < m; i++) {
				int h = stdIn.nextInt();
				int p = stdIn.nextInt();
				int q = stdIn.nextInt();
				line[i] = new Line(h,p,q);
			}
			Arrays.sort(line,new MyComparator());
			int nowp = a;
			for(int i = 0; i < m; i++) {
				if(line[i].a == nowp) {
					nowp = line[i].b;
				}
				else if(line[i].b == nowp) {
					nowp = line[i].a;
				}
			}
			System.out.println(nowp);
			
		}
		
	}
}
class MyComparator implements Comparator<Line> {

	@Override
	public int compare(Line o1, Line o2) {
		if(o1.h > o2.h) {
			return -1;
		}
		if(o1.h < o2.h) {
			return 1;
		}
		return 0;
	}
	
}
class Line {
	int h;
	int a;
	int b;
	public Line(int h, int a, int b) {
		this.h = h;
		this.a = a;
		this.b = b;
	}
}

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

int main() {
  int a, b; cin >>a >>b;
  if (a%3==0 || b%3==0 || (a+b)%3==0){
    cout <<"Possible";
  }else{
    cout <<"Impossible";
  }
  cout <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n)cin >> a[i];
    if(a[0] != 0){
        cout << -1 << endl;
        return 0;
    }
    REP(i, n-1){
        if(a[i+1]-a[i] > 1){
            cout << -1 << endl;
            return 0;
        }
    }
    ll ans = 0;
    rep(i, n-1){
        if(a[i+1]-a[i] == 1)ans++;
        else ans += a[i+1];
    }
    cout << ans << endl;
}


Measured memory_bytes: 1152
#import sys
#input = sys.stdin.readline

h, n = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(n)]

inf = 10 ** 9
max_h = 2 * 10**4 + 10
dp = [inf] * max_h
dp[0] = 0
for a, b in ab:
    for i in range(max_h - a + 1):
        dp[i] = min(dp[i], dp[i - a] + b)

print(min(dp[h:]))

Measured memory_bytes: 42844
#include <iostream>
#include <algorithm>
#include <string.h>
#include <cstdio>
#include <string>

using namespace std;

#define MAX_INT 100000

int array_max(int* arr, int M){
    int max = 0;
    for(int i = 0; i < M; i++){
        // printf("%d ",arr[i]);
        if (max < arr[i]){
            max = arr[i];
        } 
    }
    // printf("max: %d, \r\n", max);
    return max;
}

int array_min(int* arr, int M){
    int min = MAX_INT;
    for(int i = 0; i < M; i++){
        // printf("%d ",arr[i]);
        if (min > arr[i]){
            min = arr[i];
        } 
    }
    // printf("min: %d \r\n", min);
    return min;
}

int main(){
    int N,M,L_e,R_e;
    int L[MAX_INT],R[MAX_INT];
    int ret;
    scanf("%d %d", &N, &M);
    for (int i = 0; i < M; i++){
        scanf("%d %d", &L_e, &R_e);
        L[i] = L_e, R[i] = R_e;
    }
    ret = array_min(R,M)-array_max(L,M) + 1;
    printf("%d\r\n", (ret>0)? ret: 0);
    fflush(stdout);
    return 0;
}

Measured memory_bytes: 1024
//Robs Code
/***********HEADER***************/
#include <iostream>
#include <bitset>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
/***********MACROS***************/
#define int long long int
#define fri(l,k) for (i=l;i<=k;i++)
#define frj(l,k) for (j=l;j>=k;j--)
#define fij(a,b,l,k) for(i=a;i<=b;i++) for(j=l;j<=k;j++)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define pii pair<int,int>
using namespace std;
int n,m,i,j,l,k,x,y,a,b,cnt[3],sum[3];
/***********MAIN**************/
double dp[3000][3000];
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin>>n;
	vector<double> v(n);
	for(auto &x : v){
		cin>>x;
	}
	dp[0][0] = (1 - v[0]);
	for(int i=1;i<n;i++){
		dp[i][0] = dp[i-1][0] * (1 - v[i]);
	}
	dp[0][1] = v[0];
	for(int i=1;i<n;i++){
		for(int j=1;j<=n;j++){
			dp[i][j] = dp[i-1][j-1]*v[i] + dp[i-1][j]*(1-v[i]);
		}
	}
	double ans = 0;
	for(int j=0;j<=n;j++){
		if(2*j >= n){
			ans += dp[n-1][j];
		}
	}
	cout<<fixed<<setprecision(10)<<ans;
	return 0;
}
//.........

Measured memory_bytes: 70528
#!/usr/bin/env pypy
from __future__ import division, print_function

import os
import sys
from __builtin__ import xrange as range
from cStringIO import StringIO
from future_builtins import ascii, filter, hex, map, oct, zip
from io import IOBase

import __pypy__


def main():
    n = int(input())
    a = [int(ai) for ai in input().split()]
    b = [int(bi) for bi in input().split()]

    cnt = 0
    while True:
        start_cnt = cnt
        for i in range(n):
            adj_sum = b[i - 1] + b[(i + 1) % n]
            k = (b[i] - a[i]) // adj_sum
            if k > 0:
                b[i] -= k * adj_sum
                cnt += k
            while b[i] - adj_sum >= a[i]:
                b[i] -= (b[i - 1] + b[(i + 1) % n])
                cnt += 1
        if cnt == start_cnt:
            break

    if all(a[i] == b[i] for i in range(n)):
        print(cnt)
    else:
        print(-1)


# region fastio

BUFSIZE = 8192


class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count("\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0,
                              2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()


class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)

    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()


def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


Measured memory_bytes: 73416
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main(){
  int m,n;
  while(cin>>m&&m){
    vector<int> sx(m),sy(m);
    for(int i=0;i<m;i++){
      cin>>sx[i]>>sy[i];
    }
    cin>>n;
    vector<int> fx(n),fy(n);
    for(int i=0;i<n;i++){
      cin>>fx[i]>>fy[i];
    }
    int ans[2];
    ans[0]=ans[1]=-1;
    for(int s=0;s<n;s++){
      bool ok=true;
      int dx=fx[s]-sx[0],dy=fy[s]-sy[0];
      for(int i=0;i<m;i++){
        bool f=false;
        int nx=dx+sx[i],ny=dy+sy[i];
        for(int j=0;j<n;j++){
          if(nx==fx[j]&&ny==fy[j])f=true;
        }
        if(!f){
          ok=false;
          break;
        }
      }
      if(ok){
        ans[0]=dx;
        ans[1]=dy;
        break;
      }
    }
    cout<<ans[0]<<" "<<ans[1]<<endl;
  }
}

Measured memory_bytes: 1208
def LI(): return list(map(int, input().split()))
def I(): return map(int, input().split())
mod = 10**9 + 7

def main():
  n = int(input())
  if n < 30:
    print('No')
  else:
    print('Yes')
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 9164
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<math.h>
#include<tuple>
#include<string.h>
#include <numeric> 
#include<unordered_map>
using namespace std; 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define pp(...) "\033[94m [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define pp1(...) "\033[1;47;35m" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define dg(x) debug() << pp1(x)
#define dg1(x) debug() << pp(x)
#define dg2(x,y) debug() << pp(x) pp(y)
#define dg3(x,y,z) debug() << pp(x) pp(y) pp(z)
#define dg4(w,x,y,z) debug() << pp(w) pp(x) pp(y) pp(z)
#define int long long
#define all(x) x.begin() , x.end()
#define clr(x) memset(x , 0 , sizeof x);
#define sz(x) (int)x.size()
template<typename T> void db(T x ){ debug() <<">>> " <<  x; }
template<typename T> void db(T x , T y){ debug() <<">>> " <<  x <<" , "<< y; }
template<typename T> void db(T x , T y , T z){ debug() <<">>> "<< x <<" , "<< y <<" , "<< z; }
template<typename T> void db(T x , T y , T z , T a){ debug() <<">>> "<< x <<" , " << y <<" , "<< z <<" , "<< a; }
const int xx = 2e5;
const int Mod = 1e9 + 7;
const int inf = 1e18;
const int Maxn = 20010;

signed main(){
  ios::sync_with_stdio(false);cin.tie(0);
  string s;
  cin >> s;
  int rev = 0;
  int q;
  cin >> q;
  deque<char>deq;
  for(char i : s) {
    deq.push_back(i);
  }
  while(q--) {
    int T ;
    cin >> T;
    if(T == 1) {
      rev++;
    } 
    else {
      int F; char ch;
      cin >> F >> ch;
      if(rev % 2 == 0) {
        if(F == 1) deq.push_front(ch);
        else deq.push_back(ch);
      } 
      else {
        if(F == 1) deq.push_back(ch);
        else deq.push_front(ch);
      }
    }
  }
  string ans = "";
  while(!deq.empty()) {
    ans += deq.front();
    deq.pop_front();
  }
  if(rev % 2) reverse(all(ans));
  cout << ans << '\n';
}

Measured memory_bytes: 4300
local read = io.read
local insert = table.insert
local max = math.max
local abs, floor = math.abs, math.floor

local N, M, K = read("*n", "*n", "*n")
local A, B = {}, {}
---indexが1多いことに注意
local sumed_A, sumed_B = {0}, {0}
for i = 1, N do
	A[i] = read("*n")
	insert(sumed_A, sumed_A[i] + A[i])
end
for i = 1, M do
	B[i] = read("*n")
	insert(sumed_B, sumed_B[i] + B[i])
end

---[[i,jは1多いことに注意
local ans, j = 0, M + 1
for i = 1, N + 1 do
	if sumed_A[i] > K then
		break
	end
	while sumed_B[j] > K - sumed_A[i] do
		j = j - 1
	end
	ans = max(ans, i + j - 2)
end
--]]

print(ans)


Measured memory_bytes: 10860
#include<stdio.h>
#include<stdlib.h>

int main()
{
	int n,k,x,y;
	scanf("%d %d %d %d",&n,&k,&x,&y);
	if(n>k)
		printf("%d\n",(n-k)*y+k*x);
	else
		printf("%d\n",n*x);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i < n; i++)
#define repv(i,n) for(int i = n-1; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
using namespace std;
typedef long long ll;

char BUF[3500000];
inline void I(int&a){scanf("%d",&a);}
inline void I(int&a,int&b){scanf("%d%d",&a,&b);}
inline void I(int&a,int&b,int&c){scanf("%d%d%d",&a,&b,&c);}
inline void I(int&a,int&b,int&c,int&d){scanf("%d%d%d%d",&a,&b,&c,&d);}
inline void L(ll&a){scanf("%lld",&a);}
inline void L(ll&a,ll&b){scanf("%lld%lld",&a,&b);}
inline void L(ll&a,ll&b,ll&c){scanf("%lld%lld%lld",&a,&b,&c);}
inline void L(ll&a,ll&b,ll&c,ll&d){scanf("%lld%lld%lld%lld",&a,&b,&c,&d);}
inline void S(string&str){str.clear();scanf("%s",BUF);int s=strlen(BUF);rep(i,s)str.pb(BUF[i]);}
inline void SV(vector<int>&v){v.clear();scanf("%s",BUF);int s=strlen(BUF);rep(i,s)if('a'<=BUF[i]&&BUF[i]<='z')v.pb(BUF[i]-'a');else v.pb(BUF[i]-'A');}

const auto EPS = 1e-10;
const auto INF = 100000000;
const auto MOD = 1000000007;
typedef pair<ll,ll> P;

ll n;
ll x[100000];
ll kai[100001];

int main(){
    kai[0] = 1;
    for(ll i = 1; i <= 100000; i++) kai[i] = kai[i-1]*i%MOD;
    L(n);
    rep(i,n) L(x[i]);
    rep(i,n) x[i]--;
    ll ans = 1;
    ll sum = 0;
    sum = 1;
    for(int i = 1; i < n; i++){
        if(sum*2 == x[i]+1){
            ans = ans*(sum+1)%MOD;
        } else if(sum > (x[i]+1)/2){
            ans = ans*sum%MOD;
        } else sum++;
    }
    ans = ans*kai[sum]%MOD;
    cout << ans << endl;
}
































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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

void Main(){
    string lower = "abcdefghijklmnopqrstuvwxyz";
    string ans = "";
    ll n;
    cin >> n;
    n--;
    while (true) {
        ans += lower[n % 26];
        if (n < 26) break;
        n /= 26;
        n--;
    }
    REVERSE(ans);
    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <queue>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <cassert>
#include <iomanip>

using namespace std;

#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;
typedef complex<int> P;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const double PI = acos(-1.0);


bool solve(){
	int n;
	cin>> n;
	if(!n) return false;

	int ans = 0;
	bool to_up = true;
	bool l = false, r = false;
	for(int i=0;i<n;i++){
		string str;
		cin>> str;
		if(str.front() == 'l') l ^= true;
		if(str.front() == 'r') r ^= true;
		if((str.back() == 'u' && l && r && to_up)
			|| (str.back() == 'd' && !l && !r && !to_up)){
			to_up ^= true;
			ans++;
		}
	}
	cout<< ans<< endl;
	return true;
}

int main(){
	cout.setf(ios::fixed); cout.precision(10);
	while(solve());
	return 0;
}

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

#define M 200005
#define MOD 1000000007
#define PI 3.14159265358979323846
#define ep emplace_back
#define mk make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> PII;
typedef pair<lli,lli> PLL;

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

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

    int l,r,d;
    cin>>l>>r>>d;
    
    int ans = 0;
    for(int i=l;i<=r;i++)
    {
        if(i%d==0)
            ans++;
    }
    
    cout<<ans<<"\n";
}


Measured memory_bytes: 3536
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define vint vector<int>
#define pri_que priority_queue
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    string s; cin >> s;
    rep(i,s.size()){
        if(s[i]=='C'){
            range(j,i+1,s.size()){
                if(s[j]=='F'){
                    couty;
                    return 0;
                }
            }
        }
    }
    coutn;
}

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

int main(){
  int n;
  string s[155];
  while(1){
    cin>>n;
    if(n==0)break;
    bool left=false,right=false;
    int cnt=0;
    for(int i=0;i<n;i++) cin>>s[i];
    for(int i=0;i<n-1;i++){
      if((s[i+1]=="lu"&&s[i]=="ru")||(s[i]=="lu"&&s[i+1]=="ru")){
	i++;
	cnt++;
      }else if((s[i+1]=="ld"&&s[i]=="rd")||(s[i]=="ld"&&s[i+1]=="rd")){
	i++;
	cnt++;
      }
    }
    cout<<cnt<<endl;
  }
  return 0;
}

Measured memory_bytes: 2992
#include <iostream>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;

int n;
string first, sorted;
map<int,int> closed, closed2;

int toInt(const string &s){
  int res = 0;

  for(int i = 1; i < n; i++){
    res *= 10;
    res += s[i] - '0';
  }

  return res;
}

typedef pair<string,int> P;

void bfs(){
  queue<P> open;
  open.push(P(first, 0));

  closed.clear();
  closed[toInt(first)] = 0;

  while(!open.empty()){
    P p = open.front(); open.pop();

    for(int from = 0; from < n - 1; from++){
      for(int to = from + 1; to < n; to++){
        string ns = p.first;
        reverse(ns.begin() + from, ns.begin() + to + 1);

        int x = toInt(ns);

        if(closed.find(x) == closed.end()){
          closed[x] = p.second + 1;

          if(p.second + 1 < 4){
            open.push(P(ns, p.second + 1));
          }
        }
      }
    }
  }
}

void solve(){
  int ans = n - 1;
  queue<P> open;
  open.push(P(sorted, 0));

  int x = toInt(sorted);

  closed2.clear();
  closed2[x] = 0;

  if(closed.find(x) != closed.end()){
    ans = min(ans, closed[x]);
  }

  while(!open.empty()){
    P p = open.front(); open.pop();

    for(int from = 0; from < n - 1; from++){
      for(int to = from + 1; to < n; to++){
        string ns = p.first;
        reverse(ns.begin() + from, ns.begin() + to + 1);

        int x = toInt(ns);

        if(closed.find(x) != closed.end()){
          ans = min(ans, p.second + closed[x] + 1);
        }
        else if(closed2.find(x) == closed2.end()){
          closed2[x] = p.second + 1;

          if(p.second + 1 < 4){
            open.push(P(ns, p.second + 1));
          }
        }
      }
    }
  }

  cout << ans << endl;
}

int main(){
  while(cin >> n){
    first = "";
    sorted = "";

    for(int i = 0; i < n; i++){
      int x;
      cin >> x;
      first += '0' + (char)(x - 1);
      sorted += '0' + (char)i;
    }

    bfs();
    solve();
  }
}

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

string S, T;
bool solve(int i){
  for(int j = 0; j < S.size(); j++){
    if(S[j] != T[(i+j)%S.size()]){
      return false;
    }
  }
  return true;
}

int main(void){
  cin >> S >> T;
  for(int i = 0; i < S.size(); i++){
    if(solve(i)){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,q;
char s[300000];
char t[300000];
char d[300000];
int pos(int u) {
	int i=0;
	while(u>=0 && u<n && i<q) {
		if(s[u]==t[i]) {
			if(d[i]=='L') u--;
			else u++;
		}
		i++;
	}
	if(u==-1) return -1;
	if(u==n) return 1;
	return 0;
}
int main()
{
	scanf("%d %d",&n,&q);
	scanf("%s",s);
	char ch[2][2];
	for(int i=0;i<q;i++) {
		scanf("%s %s",ch[0],ch[1]);
		t[i]=ch[0][0];
		d[i]=ch[1][0];
	}
	/*pos(1);
	return 0;*/
	int l=0;
	int r=n-1;
	int ans=n;
	while(l<r) {
		int mid=(l+r+1)>>1;
		if(pos(mid)==-1) l=mid;
		else r=mid-1;
	}
	while(l>=0 && pos(l)>=0) l--;
	//printf("%d\n",l);
	ans-=(l+1);
	l=0;
	r=n-1;
	while(l<r) {
		int mid=(l+r)>>1;
		if(pos(mid)==1) r=mid;
		else l=mid+1;
	}
	while(r<n && pos(r)<=0) r++;
	//printf("%d\n",pos(r));
	ans-=(n-r);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 896