akhauriyash/Code-Regression huggingface dataset:
#include <iostream> // プログラムの耳と口
#include <vector> // 超有能配列秘書
#include <algorithm> // みんな大好きソートと二分探索
#include <queue> // きゅーちゃん、だいすき
#include <string> // to_string
#include <functional> // 関数を変数に入れる子
#include <set> // 値の取得・挿入・削除を高速に
#include <map> // setの妹 これまた優秀
#include <random> // 乱択さん

#define DB cerr<<"D"<<endl
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";};
using P=pair<ll,ll>;
const ll M = 1e9+7;
ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}
ll adad(ll x) {return x*(x+1)/2;} // 1～xの総和
void add(ll& x, ll y) {x+=y; x%=M;}; void mul(ll& x, ll y) {x*=y; x%=M;}; template<typename T, typename U> void chmax(T& x, U y) {if (x<y) x=y;}; template<typename T, typename U> void chmin(T& x, U y) {if (x>y) x=y;}
bool vaild(int x, int y, int hh, int ww){return 0<=x&&x<hh&&0<=y&&y<ww;}

int main() {
  int n;cin>>n; int an=0;
  for(int i=0;i<n;i++) {
    int a; cin>>a;
    if (i%2 == 0 && a%2 == 1) an++;
  }
  cout<<an<<endl;
}


Measured memory_bytes: 3628
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;

struct cell {
	int money;
	int jump;
};

double solve(int money, int cur, int &x, int v[], int &y, cell c[])
{
	static double memo[4901][51];
	
	if(cur == 0)
		for(int i = 0; i <= (y - 1) * 100; ++i)
			for(int j = 0; j <= y; ++j)
				memo[i][j] = -1;

	double ret = 0;
	
	if(cur == y)
		return money;
		
	if(memo[money][cur] != -1)
		return memo[money][cur];
	
	for(int i = 0; i < x; ++i) {
		
		int nextCur = min(cur + v[i], y);
		int nextMoney = max(money + c[nextCur].money, 0);
				
		nextCur = min(nextCur + c[nextCur].jump, y);
		
		ret += solve(nextMoney, nextCur, x, v, y, c);
	}
	
	return memo[money][cur] = (ret / (double)x);
}

int main()
{
	while(true) {
		
		int x, y, z;
		int v[4];
		cell c[51];
		
		scanf("%d%d%d", &x, &y, &z);
		
		if(x == 0 && y == 0 && z == 0)
			break;
		
		for(int i = 0; i < x; ++i)
			scanf("%d", v + i);
			
		for(int i = 0; i <= y; ++i)
			c[i].jump = 0, c[i].money = 0;
		for(int i = 0; i < z; ++i) {
			int t1, t2, t3;
			scanf("%d%d%d", &t1, &t2, &t3);
			if(t2 == 1)
				c[t1].jump = t3;
			else
				c[t1].money = t2 == 2 ? t3 : -t3;
		}
		
		printf("%d\n", (int)solve(0, 0, x, v, y, c));
	}
	
	return 0;
}

Measured memory_bytes: 0
def yymm(x,y):
    if 1<=y and y<=12:
        return True
    else:
        return False

S = input()

x = int(S[:len(S)//2])
y = int(S[len(S)//2:])

if yymm(x,y) and yymm(y,x):
    print("AMBIGUOUS")
elif yymm(x,y):
    print("YYMM")
elif yymm(y,x):
    print("MMYY")
else:
    print("NA")

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

int main(){
  int N;
  cin >> N;
  string W[N],sub[N];
  for(int i=0;i<N;i++){
    cin >> W[i];
    sub[i] = W[i];
  }
  sort(sub,sub+N);
  int judge = 1;
  for(int i=0;i<N-1;i++){
    if(sub[i] == sub[i+1]){
      judge = 0;
    }
  }
  for(int i=0;i<N-1;i++){
    int iter = W[i].length() - 1;
    if(W[i][iter]!=W[i+1][0]){
      judge = 0;
    }
  }
  if(judge==1){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
//新幹線からAC

#include <bits/stdc++.h>
using namespace std;
    
#define int long long
#define pb push_back
#define ub upper_bound
#define lb upper_bound
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define rep(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
    
using ll = long long;
const ll INF = LLONG_MAX / 40 - 100;
ll mod = 1e9 + 7;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;
    
class fact {
public:
    int fmod = 1e9+7;
    vector<int> fac, inv;
    fact (int n, int Mod = 1e9+7) {
        fmod = Mod;
        fac = vector<int>(n + 1,0);
        inv = vector<int>(n + 1,0);
        fac[0] = 1; for (int i = 1; i < n + 1; i++) fac[i] = fac[i-1] * i % fmod;
        for (int i = 0;i < n + 1;i++) inv[i] = fact::POW(fac[i],fmod-2);
    }
    ll nCr(ll n, ll r) {if (n<r) return 0; return (fac[n] * inv[r] % fmod) * inv[n-r] % fmod;}
    ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%fmod;}a = a * a%fmod; b >>= 1;}return c;}
};
    
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;}
void EMP(int x) {cout<<"!!!"<<x<<"!!!"<<endl;}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return (a / GCD(a,b)) * b;}
ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%mod;}a = a * a%mod; b >>= 1;}return c;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}
bool isSqrt(ll a) {return pow(sqrt(a),2) == a ? 1 : 0;}
void YesNo(bool a) {if (a) cout << "Yes"; else cout << "No"; cout << endl;}
void yesno(bool a) {if (a) cout << "yes"; else cout << "no"; cout << endl;}
void YESNO(bool a) {if (a) cout << "YES"; else cout << "NO"; cout << endl;}

long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a % b, y, x);
    y -= a / b * x;
    return d;
}

void solve() {
    int n; cin >> n;
    int dbl, l, r;
    vi pos(n, -1);
    vi a(n + 1); 
    rep (i, n + 1) {
        cin >> a[i]; a[i]--;
        if (pos[a[i]] != -1) r = i, dbl = a[i];
        else pos[a[i]] = i;
    }
    l = pos[dbl];
    fact fac(100005);
    FOR (i, 1, n + 2) {
        int tmp = fac.nCr(n + 1, i);
        int dec = fac.nCr(l + n - r, i - 1);
        // cout << tmp << " " << dec << endl;
        tmp = tmp - dec + mod; tmp %= mod;
        cout << tmp << endl;
    }
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();    
}


Measured memory_bytes: 4352
def calc(a, b):
    a, b = min(a, b), max(a, b)
    return (a * a - a + b * b + b) // 2

s = input()
ls = s.split('><')
if len(ls) == 1:
    g = ls[0].count('<')
    l = len(ls[0]) - g
    print(calc(l, g))
else:
    ans = 0
    g = ls[0].count('<')
    l = len(ls[0]) - g
    ans += calc(l + 1, g)
    for t in ls[1:-1]:
        g = t.count('<')
        l = len(t) - g
        ans += calc(l + 1, g + 1)
    g = ls[-1].count('<')
    l = len(ls[-1]) - g
    ans += calc(l, g + 1)
    print(ans)




Measured memory_bytes: 9756
#include<bits/stdc++.h>
 
using namespace std;
 
struct p{
    int l;
    int r;
}a[1000000];
 
bool cmp(p xx,p yy){
    return xx.l>yy.l;
}
 
int main(){
    int n,h;
    int c=0;
    scanf("%d%d",&n,&h);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[c++].l);
        a[c].r=1;
        scanf("%d",&a[c++].l);
    }
    sort(a,a+c,cmp);
    int sum=0;
    for(int i=0;i<c;i++)
    {
        if(a[i].r==1)
        {
            sum++;
            h-=a[i].l;
            if(h<=0)
            {
                printf("%d",sum);
                return 0;
            }
        }
        else if(a[i].r!=1)
        {
            if(h%a[i].l==0) sum+=h/a[i].l;
            else sum+=h/a[i].l+1;
            printf("%d",sum);
            return 0;
            
        }
    }
}

Measured memory_bytes: 1792
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
fn chmin<T>(x: &mut T, y: T) -> bool
where
    T: PartialOrd + Copy,
{
    *x > y && {
        *x = y;
        true
    }
}

#[allow(dead_code)]
fn chmax<T>(x: &mut T, y: T) -> bool
where
    T: PartialOrd + Copy,
{
    *x < y && {
        *x = y;
        true
    }
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, VecDeque};

fn main() {
    input!(n: usize, d: usize, xs: [[i64; d]; n]);

    let mut ans = 0;
    for i in 0..n {
        for j in 0..n {
            if i == j {
                continue;
            }
            let mut x1 = 0;
            for k in 0..d {
                let x = (xs[i][k] - xs[j][k]);
                x1 += x.pow(2);
            }
            let x1: f64 = x1 as f64;
            let mut sq = x1.sqrt();
            let sq = sq.floor();
            if sq * sq == x1 {
                ans += 1;
            }
        }
    }

    println!("{}", ans / 2);
}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
int k, s, br;

int main(){
    cin >> k >> s;
    for(int x=0; x <= k; x++){
        for(int y=0; y<=k; y++){
            int z = s-(x+y);
            if(z >= 0 && z <= k) 
            br++; 
        }
    }
    cout << br;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
typedef long long int ll;
const ll maxn=1e6+8;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll d,t,s;
    cin>>d>>t>>s;
    if((s*t)>=d)
        cout<<"Yes";
    else
        cout<<"No";
    cerr<<"\nTime elapsed:"<< 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


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

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#ifdef BTK
#include<dvector.h>
#define DEBUG if(1)
#else
#define DEBUG if(0)
#endif

#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
    
int main(){
    int R,C,K;
    cin>>R>>C>>K;
    FOR(i,0,R+1)
        FOR(j,0,C+1){
        int num=i*C+j*R-i*j*2;
        if(num==K){
            cout<<"Yes"<<endl;
            return 0;
        }
        
    }
    cout<<"No"<<endl;
    return 0;
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

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

struct edge {
	int to, cost;
	edge(int t,int c):to(t),cost(c) {}
};
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};

//-----------------------------------------------------------------------------

int n;

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

	cin>>n;
	vector<int> d;
	REP(i,n) {
		int t;cin>>t;d.pb(t);
	}
	sort(ALL(d));
	d.erase(unique(ALL(d)),d.end());
	cout<<d.size()<<endl;

	return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<long long> l(n);
  for (int i = 0; i < n; i++) {
	cin >> l[i];
  }
  int total = 0;
  for (int i = 0; i < n-2; i++) {
    for (int j = i+1; j < n-1; j++) {
      for (int k = j+1; k < n; k++) {
        if (l[i] == l[j] || l[i] == l[k] || l[j] == l[k]) continue;
        if (l[i] >= l[j] && l[i] >= l[k]) {
          if (l[i] < l[j] + l[k]) total++;
        } else if (l[j] >= l[k]) {
          if (l[j] < l[i] + l[k]) total++;
        } else {
          if (l[k] < l[i] + l[j]) total++;
        }
      }
    }
  }
  cout << total << endl;
}

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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)
#define rep1(i,n) for(auto i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

using namespace std;


struct init{ init(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); }; }aaaaaaa;



int main(){
  ll x, a;
  cin >> x >> a;

  if(x < a) cout << 0 << endl;
  else      cout << 10 << endl;


  return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
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; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<int> a(n);
rep(i, n){
    cin >> a[i];
    a[i]--;
}
bool ok = false;
int ans = 1;
int idx = 0;
rep(i,n){
    if(a[idx]==1){
        ok = true;
        break;
    }
    idx = a[idx];
    ans++;
}
if(ok){
    cout << ans << endl;
}
else{
    cout << -1 << endl;
}
//system("pause");
return 0;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  string S;
  cin>>S;
  string s="AKIHABARA";

  if(S.size()>s.size()){
    cout<<"NO"<<endl;
    return 0;
  }

  ll bit=pow(2,S.size()+1);
  for(ll i=0;i<bit;i++){
    int memo=0;
    string s_=S;
    for(int j=0;j<=S.size();j++){
      if((i>>j)&1){
        s_.insert(j+memo,"A");
        memo++;
      }
    }
    if(s_==s){
      cout<<"YES"<<endl;
      return 0;
    }
  }
  cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    cin >> N;
    vector<ll> A(3 * N);
    rep(i, 3 * N) cin >> A[i];
    priority_queue<ll, vector<ll>, greater<ll>> pq;
    vector<ll> B(3 * N);
    
    ll sum = 0;
    rep(i, N) {
        pq.push(A[i]);
        sum += A[i];
    }
    B[N - 1] = sum;
    rep(i, N, 3 * N){
        pq.push(A[i]);
        ll t = pq.top();
        pq.pop();
        sum -= t;
        sum += A[i];
        B[i] = sum;
        
    }
    
    priority_queue<ll> pr;
    vector<ll> C(3 * N);
    sum = 0;
    for(int i = 3 * N - 1; i >= 2 * N; i--){
        pr.push(A[i]);
        sum += A[i];
    }
    C[2 * N] = sum;
    for(int i = 2 * N - 1; i >= 0; i--){
        pr.push(A[i]);
        ll t = pr.top();
        pr.pop();
        sum -= t;
        sum += A[i];
        C[i] = sum;
        
    }
    
    ll ans = -10000000000000000;
    
    rep(i, N - 1, 2 * N){
        ans = max(ans, B[i] - C[i + 1]);
    }
    output(ans);
    
    
    return 0;
}

Measured memory_bytes: 9588
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    int n; cin >> n;
    vi a(n); for(auto& e : a) cin >> e;

    int nall = pow(3, n);
    int nodd = 1;
    for(auto& e : a){
        if(e % 2 == 0){
            nodd *= 2;
        }
    }

    cout << nall - nodd << endl;

    return 0;
}

Measured memory_bytes: 384
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
)

func main() {
	log.SetFlags(log.Lshortfile)
	sc := newScanner()
	N := sc.nextInt()
	a := make([]int, 3*N)
	for i := 0; i < N*3; i++ {
		a[i] = sc.nextInt()
	}
	h1 := &IntHeap{}
	h2 := &IntHeap{}
	firstSum := make([]int, 3*N)
	firstSum[N-1] += sum(a[:N])
	secondSum := make([]int, 3*N)
	secondSum[2*N] += sum(a[2*N:]) * -1
	// log.Println(firstSum, secondSum)
	for k := 0; k < N; k++ {
		heap.Push(h1, a[k])
		heap.Push(h2, a[3*N-k-1]*-1)
	}
	// log.Println(h1, h2)
	for k := N; k < 2*N; k++ {
		firstSum[k] = firstSum[k-1] + a[k]
		heap.Push(h1, a[k])
		firstSum[k] -= heap.Pop(h1).(int)
		j := 3*N - k - 1
		secondSum[j] = secondSum[j+1] + (a[j] * -1)
		heap.Push(h2, a[j]*-1)
		secondSum[j] -= heap.Pop(h2).(int)

		// log.Println(k, j)
		// log.Println(firstSum)
		// log.Println(secondSum)
		// log.Println(h1, h2)
	}
	ans := math.MinInt64
	for k := N - 1; k < 2*N; k++ {
		ans = max(ans, firstSum[k]+secondSum[k+1])
		// log.Println(ans)
	}
	fmt.Println(ans)
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

// An IntHeap is a min-heap of ints.
type IntHeap []int

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] < h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *IntHeap) Push(x interface{}) {
	// Push and Pop use pointer receivers because they modify the slice's length,
	// not just its contents.
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func push(heap []int, x, sz int) {
	i := sz
	sz++
	for i > 0 {
		p := (i - 1) / 2
		if heap[p] <= x {
			break
		}
		heap[i] = heap[p]
		i = p
	}
	// log.Println(heap, i)
	heap[i] = x
}

func pop(heap []int, sz int) (ret int) {
	ret = heap[0]
	sz--
	x := heap[sz]
	i := 0
	for i*2+1 < sz {
		a := i*2 + 1
		b := i*2 + 2
		if b < sz && heap[b] < heap[a] {
			a = b
		}
		if heap[a] >= x {
			break
		}
		heap[i] = heap[a]
		i = a
	}
	heap[i] = x
	return
}

func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return
}

type scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func newScanner() *scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &scanner{r: rdr}
}
func (s *scanner) next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *scanner) nextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *scanner) nextInt() int {
	v, _ := strconv.Atoi(s.next())
	return v
}

func (s *scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


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

int main(){

    string s = "YAKI";
    string t; cin >> t;
    t += "banhei";
    bool flag = true;
    for(int i = 0; i < 4; i++){
        if(s[i] != t[i]){
            flag = false;
        }
    }

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    char a[101], b[101], temp;
    scanf(" %s %s", &a, &b);
    int len=strlen(a), i, rotation=0, res=0;

    rotation=0;
    while(rotation<len)
    {
        i=len-1;
        temp = a[0];
        a[0]=a[i];
        while(i>1)
        {
            a[i] = a[i-1];
            i--;
        }
        a[i] = temp;
        if(strcmp(a, b)==0)
        {
            printf("Yes\n");
            res=1;
            break;
        }
        rotation++;
    }
    if(res!=1)
    {
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 1596
#include <iostream>
#include <bits/stdc++.h>
#define endl '\n'
#define MAXN 1000010
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    unsigned int n, m; cin >> n >> m;
    vi r(n), balls(n, 1);
    r[0] = 1;
    int temp = m;
    while (temp--) {
        int c1, c2; cin >> c1 >> c2;
        c1--;
        c2--;
        if(r[c1]){
            r[c2] = 1;
            if(balls[c1] == 1) r[c1] = 0;
        }

        --balls[c1];
        ++balls[c2];
    }
    int count = 0;
    for (int i = 0; i < n; ++i) {
        if(r[i]) ++count;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;


public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    String line = br.readLine();
	    //文字列に先頭又は最後に空白文字がくっ付いている場合、それらを全て取り除きます。
	    line = line.trim();
	    //半角スペースを区切り文字として扱う
	    String[] readLineArray = line.split("[\\s+]");
	    //変数に配列を代入
	    int a = Integer.parseInt(readLineArray[0]);
	    int b = Integer.parseInt(readLineArray[1]);
	 
	    int d = a/b;
	    int r = a%b;
	    double f = (double)a/(double)b;
	    System.out.printf("%d %d %.5f\n",d,r,f);
	}

}

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

using namespace std;

#define int ll
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pi> vp;
typedef vector<pl> vpl;

int dp[4000][4000];

signed main()
{
	ios_base::sync_with_stdio(false); 
	cin.tie(nullptr); 
	cout.tie(nullptr); 
	cerr.tie(nullptr);	

	int n;
	cin >> n;

	vi a(n);
	for (auto& i : a)
		cin >> i;

	for (int i = n - 1; i > -1; --i){
		for (int j = i; j < n; ++j){
			dp[i][j] = max(a[i] - dp[i + 1][j], a[j] - dp[i][j - 1]);
		}
	}

	cout << dp[0][n - 1] << '\n';
}

Measured memory_bytes: 94208
X,K,D = list(map(int,input().split()))
AX = abs(X)
M = AX//D
if M>=K:
    print(AX-D*K)
else:
    X1 = abs(AX - D*M)
    X2 = abs(AX - D*(M+1))
    if (K-M)%2==0:
        print(X1)
    else:
        print(X2)


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

int main() { int N; cin >> N;
vector<string> s(N);
for(int i = 0; i < N; i++) cin >> s.at(i);

vector<char> x;
x = {'M', 'A', 'R', 'C', 'H'};
vector<long> t;
t = {0, 0, 0, 0, 0};

for(int i = 0; i < 5; i++){
  for(int j = 0; j < N; j++){
    if(s.at(j).at(0) == x.at(i)) t.at(i)++;
  }
}
long ans = 0;
for(int j = 1; j < 4; j++){
  for(int i = 0; i < j; i++){
    for(int k = j + 1; k < 5; k++){
      ans += t.at(i) * t.at(j) * t.at(k);
    }
  }
}
// cout << t.at(4) << endl;
cout << ans << endl;
  return 0;
 
}

Measured memory_bytes: 6144
N_MAX = 10**6
MOD = 10**9 + 7
fac, finv, inv = [0]*N_MAX ,[0]*N_MAX, [0]*N_MAX
def com_init():
    fac[0], fac[1] = 1, 1
    finv[0], finv[1] = 1, 1
    inv[1] = 1
    for i in range(2, N_MAX):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD


def com(n, k):
    if n < k: return 0
    if n < 0 or k < 0: return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD


# 60 -> {2:2, 3:1, 5:1}
def factorization(n):
    pf_cnt = {}
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i == 0:
            cnt = 0
            while temp%i == 0:
                cnt += 1
                temp //= i
            pf_cnt[i] = cnt

    if temp != 1: pf_cnt[temp] = 1
    if not pf_cnt: pf_cnt[n] = 1

    return pf_cnt


def main():
    com_init()
    n, m = map(int, input().split())
    if m == 1:
        print(1)
        return
        
    fac = factorization(m)
    prime_combs = []
    for prime, cnt in fac.items():
        prime_combs.append(com(n-1+cnt, cnt))

    ans = 1
    for c in prime_combs:
        ans*=c
        ans%=MOD

    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 62320
n, a_start, b_start, a_goal, b_goal = gets.split(" ").map(&:to_i)
strings = gets.chomp.to_s
ans = "Yes"

# a_start・a_goal間に "##" があれば "No"
if strings[a_start - 1..a_goal - 1].include?("##")
  ans = "No"
# b_start・b_goal間に "##" があれば "No"
elsif strings[b_start - 1..b_goal - 1].include?("##")
  ans = "No"
# a_goal > b_goalの時、b_startの1歩手前・b_goalの1歩先の間に "..." がなければ "No"
# （a_goal > b_goalの場合、b_start・b_goal間でaがbを抜かす必要があるため）
elsif a_goal > b_goal && strings[b_start - 2..b_goal].include?("...") == false
  ans = "No"
end

puts ans

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

using namespace std;

int w[300005] = {};
int e[300005] = {};

int main()
{
    int n;
    char c;   
    int ans = 3000000;

    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> c;
        
        w[i] = w[i - 1];
        e[i] = e[i - 1];

        if (c == 'W') {
            w[i]++;
        } else {
            e[i]++;
        }
    }


    for (int i = 1; i <= n; i++) {
        int temp = w[i - 1] + (e[n] - e[i]);

        ans = (temp < ans ? temp : ans);
    }

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


Measured memory_bytes: 2560
#include <stdio.h>
#include <string.h>
#include <ctype.h>


int main(void)
{
    int i,j,k;
    int h,w,n;
    char a[10]={0};
    int last[8] = {0}, first[8] = {0},check;

    scanf("%d %d", &h, &w);

    for(i = 0; i <= h; i++)
    {
        scanf("%s", a);
        n = strlen(a);

        check = 0;

        for(j = 0  ; j <= n; j++)
        {
            if (check == 0 && a[j] =='#')
            {
               first[i] = j;
               check = 1;
            }
            if (a[j] == '#')
            {
                last[i] = j;
            }
        }
        //printf("f=%d l=%d\n", first[i],last[i]);
    }

    for(i = 1; i < h; i++)
    {
       if (last[i-1] != first[i])
       {
           printf("Impossible\n");
           return 0;
       }
    }

    printf("Possible\n");

    return 0;
}

Measured memory_bytes: 128
N, X = map(int, input().split())
ans = N
a, b = max(X, N-X), min(X, N-X)
while b:
    q, r = divmod(a, b)
    if r == 0:
        ans += b * (2 * q - 1)
    else:
        ans += b * 2 * q
    a, b = max(b, r), min(b, r)
print(ans)

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

#define forn(i,n) for(int i=0;i<n;i++)
#define pb push_back
typedef long long ll;
const long double pi=2*acos(0.0);

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int a,b,h,m;
	cin>>a>>b>>h>>m;
	int y=h*60 +m;
	long double omg=(2*pi)/(long double)(60*12);
	omg=11*omg;
	long double theta=omg*(long double)y;
	long double ans= (long double)a*a+(long double)b*b-(long double)(2*a*b*cos(theta));
	ans=sqrt(ans);
	printf("%0.15Lf",ans);
}


Measured memory_bytes: 4168
#include<iostream>
#include<cmath>
#define ll long long
using namespace std;

int main(){
  ll n,ans=0; cin>>n;
  for(ll i=1;i<=n;i++){
    ll li=floor((long double)n/i);
    ans+=i*li*(li+1)/2;
  }
  cout<<ans<<endl;
}

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


void solve()
{
    ll t,i,j,n;
    vector<ll> a,dp;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>t;
        a.pb(t);
        dp.pb(0);
    }
    //dp.pb(0);
    for(i=1;i<n;i++)
    {
        if(i==1)
        {
            dp[i]=dp[i-1]+abs(a[i]-a[i-1]);
        }
        else
        {
            dp[i] = min((dp[i-1]+abs(a[i]-a[i-1])),(dp[i-2]+abs(a[i]-a[i-2])));
        }
    }
    cout<<dp[n-1];
    return;
}



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    //cin>>t;
    t=1;

    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 2036
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <cmath>

typedef long long ll;

using namespace std;

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    if(a+b+c >= 22) cout << "bust";
    else cout << "win";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
const ll MOD = 1e9+7;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
#define fs first
#define sc second


const int INF = 1e9;
const ll LLINF = 1e16;

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}
 
template<typename T>
T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T>
T ngcd(vector<T> a){
    T res;
    res = a[0];
    for(int i = 1; i < a.size() && res != 1; i++) {
        res = gcd(a[i], res);
    }
    return res;
}
 
template<typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

template<typename T>
T nlcm(vector<T> numbers) {
    T res;
    res = numbers[0];
    for (int i = 1; i < numbers.size(); i++) {
        res = lcm(res, numbers[i]);
    }
    return res;
}

// 約数列挙
template<typename T>
vector<T> calc_divisor(T n) {
   vector<T> res;
   for (T i = 1LL; i*i <= n; ++i) {
       if (n % i == 0) {
           res.push_back(i);
           T j = n / i;
           if (j != i) res.push_back(j);
       }
   }
   sort(res.begin(), res.end());
   return res;
}

// 素数判定
template<typename T>
bool isPrime(T x){
    T i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}


using pint = pair<int, int>;
using pll = pair<ll, ll>;


int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    int ans = 0;
    int count = 1;
    rep(i, n){
        int a;
        cin >> a;
        if(a == count) count++;
        else ans++;
    }
    if(ans == n) print(-1);
    else print(ans);
    
}


Measured memory_bytes: 256
#from collections import deque,defaultdict
from sys import stdin
input = stdin.readline
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

x,y = inm()
if y%2==0 and 2*x<=y<=4*x:
    print('Yes')
else:
    print('No')


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


using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll, ll> pll;
int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };

#define ARRAY_MAX 100005

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

int main() {

	int n, q;
	string s;
	cin >> n >> q;
	cin >> s;
	vector<int> cnt(n + 10, 0);

	int cnt_a = 0;

	for (int i = 0; i < s.length(); i++)
	{
		if (s[i] == 'C' && cnt_a == 1)
		{
			cnt[i + 1]++;
			cnt_a--;
		}
		else if (s[i] == 'A')
		{
			if (cnt_a == 0)
			{
				cnt_a = 1;
			}
		}
		else if (s[i] != 'A' && cnt_a == 1)
		{
			cnt_a = 0;
		}
	}

	
	for (int i = 0; i < s.length(); i++)
	{
		cnt[i + 1] += cnt[i];
	}

	for (int i = 0; i < q; i++)
	{
		int l, r;
		cin >> l >> r;
		cout << cnt[r] - cnt[l] << endl;
	}
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <set>
#include <queue>
using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main(){
    unsigned long long H, W, ans=0;
    cin >> H >> W;

    ans = (unsigned long long)(H*W/2);
    if(H%2 != 0 and W%2 != 0){
        ans++;
    }

    if(H == 1 || W == 1){
        ans = 1;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

long long int N, M, K, Q, W, H, L, R;
long long int ans;

using namespace std;


int main() {
	ios::sync_with_stdio(false);
	cin >> N;
	int num[100000] = {};
	for (int i = 0; i < N; i++) {
		cin >> num[i];
		ans += num[i];
	}
	cin >> M;
	for (int i = 0; i < M; i++) {
		cin >> K >> Q;
		cout << ans - num[K - 1] + Q << endl;
	}
	return 0;
}

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

#define PI 4*atan(1)
#define INF 1e8

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

int main(){
  int n;
  while(cin >> n, n){
    vector<string> f(n);
    for(int i = 0; i < n; i++){
      cin >> f[i];
    }
    int cnt = 0;
    bool l = false, r = false;
    int pos = -1;
    for(int i = 0; i < n; i++){
      if(f[i] == "lu")l = true;
      else if(f[i] == "ld")l = false;
      if(f[i] == "ru")r = true;
      else if(f[i] == "rd")r = false;

      if(pos == -1 && l && r){
        pos = 1;
        cnt++;
      }else if(pos == 1 && !l && !r){
        pos = -1;
        cnt++;
      }
    }
    cout << cnt << endl;
  }
}

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

using ll=long long;



void solve(){
    string s;
    cin>>s;
    if(s.size()==2)cout<<s<<endl;
    else{
        reverse(s.begin(),s.end());
        cout<<s<<endl;
    }
}

signed main(){
    //while(1)
    solve();
}

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


int main(){
    int n;
    cin>>n;
    map<string,int> mp;
    rep(i,n){
        string s;
        cin>>s;
        mp[s]++;
    }
    int mx=0;
    for(auto p: mp){
        mx=max(mx,p.second);
    }
    for(auto p: mp){
        if(mx==p.second){
            cout<<p.first<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 25344
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
int main(){
  vll a(4);
  
  cin>>a[0];
  a[3]=a[0]%10;
  a[0]/=10;
  a[2]=a[0]%10;
  a[0]/=10;
  a[1]=a[0]%10;
  a[0]/=10;
  for(int bit=0;bit<(1<<3);bit++){
    ll k=a[0];
    vector<char> y(3);
    for(int i=0;i<3;i++){
      if((1<<i)&bit){
        k+=a[i+1];
        y[i]='+';
      }
      else{
        k-=a[i+1];
        y[i]='-';
      }
    }
    if(k==7){
      cout<<a[0]<<y[0]<<a[1]<<y[1]<<a[2]<<y[2]<<a[3]<<"="<<7;
      return 0;
    }
  }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

//DPL Coin Changing Problem

const int INF = 1e8;
int n, m;
int c[21];
int memo[50010];

int dfs(int t){
	if (memo[t] == INF) {
		if (t == 0) {
			memo[0] = 0;
		}
		else {
			rep(i, 0, m) {
				if (t - c[i] >= 0) {
					memo[t] = min(memo[t], dfs(t - c[i]) + 1);
				}
			}
		}
	}
	return memo[t];
}

signed main(){
	cin >> n >> m;
	rep(i, 0, m) cin >> c[i];
	rep(i, 0, 50010) memo[i] = INF;
	cout << dfs(n) << endl;
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
const int MAXN = 305;
const int mod = 1e9 + 7;
#define sz(v) ((int)v.size())

lint dp[MAXN][MAXN][MAXN];
int n, m;

int main(){
	cin >> n >> m;
	dp[m][0][1] = 1;
	for(int i=m; i>=1; i--){
		for(int j=0; j<=n; j++){
			for(int k=0; k<=n; k++){
				dp[i][j][k] %= mod;
				dp[i-1][j+1][k] += dp[i][j][k] * (n - j - k);
				dp[i-1][j][k] += dp[i][j][k] * j;
				if(j + k < MAXN) dp[i-1][0][j+k] += dp[i][j][k] * k;
			}
		}
	}
	cout <<  dp[0][0][n] % mod << endl;
}


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



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	int N; cin >> N;
	// vector<int> A(N);
	set<int> st;
	REP(i,N){ 
		int A;
		cin >> A;
		if(st.count(A) == 0) st.insert(A);
		else st.erase(A);
	}

	// int ans = 0;
	// for(auto v:st){
	// 	cout << "v:" << v << endl;
	// 	cout << "count:" << st.count(v) << endl;
	// 	if(st.count(v)%2 == 1) ans++;
	// }
	
	int ans = st.size();

	cout << ans << endl;
	return 0;

}


Measured memory_bytes: 4864
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

int auau(int r, int D, int x){
  return (r * x - D);
}

int main() {

  int r, D, x;
  cin >> r >> D >> x;

  int tmp = x;
  REP(i, 10){
    tmp = auau(r, D, tmp);
    cout << tmp << endl;
  }
  return 0;
}


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

using namespace std;

int main() {
  int64_t N;
  cin >> N;
  int64_t p = numeric_limits<int64_t>::max();
  for (int i = 0; i < 5; i++) {
    int64_t k = 0;
    cin >> k;
    p = min(p, k);
  }
  cout << (N + p - 1) / p + 4 << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll A[55];
int main ()
{
    int N;cin >> N;
    ll pw=2LL;
    for(int i=1;i<=N;i++){
        cin >> A[i];
    }
    sort(A+1,A+1+N);
    ll sum=A[1]+A[2];
    for(int i=3;i<=N;i++){
            sum+= pw*A[i];
            pw*=2LL;
    }
    double ans = (double)sum/pw;
    cout<<setprecision(10)<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import collections


def main():
    N = int(input())
    A = list(map(int, input().split()))
    counter = collections.Counter(A)
    ans = 0
    for k, v in counter.items():
        if v > k:
            ans += v - k
        elif v < k:
            ans += v
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 22404
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n;
    cin >> n;
    for (int i = 1; i < 10; i++) {
        for (int j = 1; j < 10; j++) {
            if (i * j == n) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    if (d == 22) { cout << "Christmas Eve Eve Eve" << endl; }
    if (d == 23) { cout << "Christmas Eve Eve" << endl; }
    if (d == 24) { cout << "Christmas Eve" << endl; }
    if (d == 25) { cout << "Christmas" << endl; }
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main() {
	int n;
	cin >> n;
	vector<ll>x(n);
	rep(i, n){
		cin >> x[i];
	}
	sort(x.begin(), x.end(),greater<ll>());

	ll first = 0;
	ll second = 0;

	int flag = 1;

	for(int i = 0; i < n - 1; i++){
//		cout << x[i] << endl;
		if(x[i] == x[i+1]){
			flag++;
		}else{
//			cout << x[i] << endl;
			flag = 1;
			continue;
		}

//		cout << flag << endl;

		if(flag == 4){
			if(first == 0){
				first = x[i+1];
				second = x[i+1];
			}else{
				second = x[i+1];
			}
		}

		if(flag == 2){
			if(first == 0){
				first = x[i+1];
			}else{
				second = x[i+1];
			}
		}

		if(first != 0 && second != 0){
			cout << first * second << endl;
			return 0;
		}
	}
	cout << "0" << endl;
}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(x) x.begin(),x.end()
typedef long long ll;
ll mod = 1000000007;
ll inf = 1e18;
int main(){

    int n;
    cin >> n;
    vector<int> v(100010);
    int a;
    rep(i,n){
        cin >> a;
        v[a]++;
    }

    ll sum=0;
    rep(i,100010) sum+=i*v[i];

    int q;
    cin >> q;
    int b,c;
    rep(i,q){
        cin >> b >> c;
        v[c]+=v[b];
        sum+=(c-b)*v[b];
        cout << sum << endl;
        v[b]=0;
    }

    // cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 3792