akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))

using namespace std;

int main(void)
{
	int N, M; cin >> N >> M;
	lli sum = 0;
	rep(i, 0, M) {
		lli tmp; cin >> tmp;
		sum += tmp;
	}
	lli ans = N - sum;
	if (ans >= 0)cout << ans << endl;
	else cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 3636
#include <iostream>

using namespace std;

int main() {
    int N, ans = 0, x;
    scanf("%d", &N);
    for (int i  = 0; i < N; i++) {
        scanf("%d", &x);
        ans = ans + x - 1;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
(* 素集合データ構造 *)
module UnionFind = struct
  module Make (Set : sig
    type t
    val union : t -> t -> t
  end) : sig
    type t
    (* 与えられた集合から素集合データ構造を作る *)
    val make : Set.t -> t
    (* 与えられた素集合同士が同一かどうか判定する *)
    val equal : t -> t -> bool
    (* 与えられた素集合同士を合併する *)
    val unite : t -> t -> unit
    (* 与えられた素集合に属する要素を列挙する *)
    val elements : t -> Set.t
  end = struct
    type t = node ref
    and node =
      | Root of int * Set.t (* 木の高さと要素の集合の二つ組 *)
      | Link of t

    let make s = ref @@ Root (0, s)

    let rec find uf =
      match !uf with
      | Root _ -> uf
      | Link parent ->
          let root = find parent in
          uf := Link root; root

    let equal uf uf' = find uf == find uf'

    let unite uf uf' =
      let root = find uf in
      let root' = find uf' in
      if root != root' then begin
        let Root (rank, elts) = !root in
        let Root (rank', elts') = !root' in
        let root, root' =
          if rank <= rank'
          then root, root'
          else root', root in
        root := Link root';
        root' := Root (rank' + (if rank = rank' then 1 else 0), Set.union elts elts')
      end

    let elements uf =
      match find uf with
      | { contents = Root (_, elts) } -> elts
  end
end

module UF = UnionFind.Make (struct
  type t = unit
  let union = Fun.const
end)

let () = Scanf.scanf "%d %d\n" @@ fun n q ->
  let uf = Array.init n @@ fun _ -> UF.make () in
  for i = 0 to q - 1 do
    Scanf.scanf "%d %d %d\n" @@ fun t u v ->
      match t with
      | 0 -> UF.unite uf.(u) uf.(v)
      | 1 -> print_endline @@ if UF.equal uf.(u) uf.(v) then "1" else "0"
  done

Measured memory_bytes: 18160
h,w = map(int,input().split())
s = [str(input()) for i in range(h)]
num = [[-1] * w for i in range(h)]
num[0][0] = 0
now = {(0,0)}
for i in range(1,2501):
    tmp = set()
    for x,y in now:
        if x > 0:
            if s[x-1][y] == "." and num[x-1][y] == -1:
                num[x-1][y] = i
                tmp.add((x-1,y))
        if x < h-1:
            if s[x+1][y] == "." and num[x+1][y] == -1:
                num[x+1][y] = i
                tmp.add((x+1,y))
        if y > 0:
            if s[x][y-1] == "." and num[x][y-1] == -1:
                num[x][y-1] = i
                tmp.add((x,y-1))
        if y < w-1:
            if s[x][y+1] == "." and num[x][y+1] == -1:
                num[x][y+1] = i
                tmp.add((x,y+1))
    now = tmp
if num[-1][-1] == -1:
    print(-1)
else:
    print(h * w-num[-1][-1]-sum([s[i].count("#") for i in range(h)])-1)

Measured memory_bytes: 40940
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10000)

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]
        
def resolve():
    N, M, K = map(int, input().split())
    A = [0]*M
    B = [0]*M
    for i in range(M):
        A[i], B[i] = map(int, input().split())
    C = [0]*K
    D = [0]*K
    for i in range(K):
        C[i], D[i] = map(int, input().split())

    uf = UnionFind(N)
    for a, b in zip(A, B):
        uf.union(a-1, b-1)

    direct_friends_num = [0]*N
    for a, b in zip(A, B):
        direct_friends_num[a-1] += 1
        direct_friends_num[b-1] += 1
    blocked_num = [0]*N
    for c, d in zip(C, D):
        if uf.find(c-1) == uf.find(d-1):
            blocked_num[c-1] += 1
            blocked_num[d-1] += 1

    ans = [0]*N
    for i in range(N):
        ans[i] = uf.size(i) - direct_friends_num[i] - blocked_num[i] - 1
    print(*ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 30708
#include<iostream>
#include<vector>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
using ll = long long;
using namespace std;
ll gcd(ll a, ll b) {
	return a % b ? gcd(b, a%b) : b;
}
int main() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	ll divc = b / c - (a - 1) / c, divd = b / d - (a - 1) / d;
	ll lcm = c * d / gcd(c, d);
	ll divl = b / lcm - (a - 1) / lcm;
	cout << b - a + 1 - divc - divd + divl << endl;
	return 0;
}	

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/rope"
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
mt19937 rng(high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rngll(high_resolution_clock::now().time_since_epoch().count());
#define lambdify(x) [&](auto &&...args){ return x(forward<decltype(args)>(args)...); }
template<typename T, typename U> T &ctmax(T &x, const U &y){ return x = max<T>(x, y); }
template<typename T, typename U> T &ctmin(T &x, const U &y){ return x = min<T>(x, y); }
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



int main(){
	cin.tie(0)->sync_with_stdio(0);
	string s;
	cin >> s;
	int n = int(s.size());
	int l = (n - 1) / 2, r = n / 2;
	if(s[l] != s[r]){
		cout << n / 2 << "\n";
		return 0;
	}
	while(l && s[l - 1] == s[n / 2] && s[r + 1] == s[n / 2]){
		-- l, ++ r;
	}
	cout << r + 1 << "\n";
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

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

using namespace std;
 
const long long inf = 1e9;
#define ll long long
#define fr(i,a,n) for (int i=a;i<n;i++)
#define rfr(i,n,a) for (int i=n;i>=a;i--)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll> 
#define endl "\n"
typedef vector<int> VI;
typedef vector<ll> VL;
typedef priority_queue<int> Pqi;
typedef priority_queue<ll> Pql;

ll n, m, k;
ll arr[14][14];
ll dp[500000];
ll solv(ll mask) {
	if (dp[mask] != -1)
		return dp[mask];
	VL v(m+2);
	ll ret = 0;
	fr(i,0,n) {
		if (mask & (1 << i)) {
			ret += arr[i][0];
			fr(j,1,m+1) {
				v[j] += arr[i][j];
			}
		}
	}
	bool can = 0;
	fr(i,1,m+1) {
		if (v[i] < k){
			ret = 1e18;
			break;
		}
	}
	fr(i,0,n) {
		if (mask & (1LL << i))
			continue;
		ret = min(ret,solv(mask |(1 << i)));
	}
	return dp[mask] = ret;
}
int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m >> k;
	memset(dp,-1,sizeof dp);
	ll mask = (1 << 18);
	fr(i,0,n) {
		fr(j,0,m+1) {
			cin >> arr[i][j];
		}
	}
	ll ans = solv(mask);
	cout << (ans==1e18?-1:ans) << endl;
	return 0;
}

Measured memory_bytes: 7528
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    int dx = tx - sx, dy = ty - sy;
    for (int i = 0; i < dy; ++i) cout << 'U';
    for (int i = 0; i < dx; ++i) cout << 'R';
    for (int i = 0; i < dy; ++i) cout << 'D';
    for (int i = 0; i < dx; ++i) cout << 'L';
    cout << 'L';
    for (int i = 0; i < dy + 1; ++i) cout << 'U';
    for (int i = 0; i < dx + 1; ++i) cout << 'R';
    cout << 'D';
    cout << 'R';
    for (int i = 0; i < dy + 1; ++i) cout << 'D';
    for (int i = 0; i < dx + 1; ++i) cout << 'L';
    cout << 'U';
    cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  ll N,A,B;
  cin >> N >> A >> B;
  cout << max(0LL,(B * (N - 1) + A) - (A * (N - 1) + B) + 1) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <utility>
#include <stack>
#include <iomanip>  
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i ++)
using ll = long long;
int N;
int A[301];
double dp[301][301][301];

double solve(int x, int y, int z) {
    if (dp[x][y][z] >= 0) return dp[x][y][z];
    double ans = 0;
    double m = x + y + z;
    if (x > 0) ans += solve(x - 1, y, z) * x / m;
    if (y > 0) ans += solve(x + 1, y - 1, z) * y / m;
    if (z > 0) ans += solve(x, y + 1, z - 1) * z / m;
    ans += (double)N / m;
    return dp[x][y][z] = ans;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> N;
    rep(i, N) cin >> A[i];
    int x = 0, y = 0, z = 0;
    rep(i, N) {
        if (A[i] == 1) x ++;
        if (A[i] == 2) y ++;
        if (A[i] == 3) z ++;
    }
    rep(i, 301) rep(j, 301) rep(k, 301) dp[i][j][k] = -1;
    dp[0][0][0] = 0;
    cout << setprecision(15) << solve(x, y, z) << endl;
    return 0;
}

Measured memory_bytes: 216884
import java.io.File;
import java.io.IOException;
import java.util.*;
 
public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		int X = sc.nextInt();
		int t = sc.nextInt();
		System.out.println((X - t >= 0) ? (X - t) : 0);
	}
}

Measured memory_bytes: 20560
#include<algorithm>
#include<iostream>

using i64=long long;

int main(){
  i64 A,B,N;
  std::cin >> N >> A >> B;

  i64 placementsCompleted = N/(A+B);
  i64 remainder = N - placementsCompleted*(A+B);
  i64 blueBallsatEnd = (remainder > A)? A: remainder;
  i64 blueBalls = placementsCompleted*A + blueBallsatEnd;
  std::cout << blueBalls;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <unordered_set>
#include <cmath>
#define endl '\n'
#define ll unsigned long long
//#define mod 1000000007
#define NCONS 100001

using namespace std;
int N;
int F, S;
vector<int> adj[NCONS];
int df[NCONS];
int ds[NCONS];
bool visited[NCONS];
int length;

void set_distance(int cur, int* distance, int length)
{
	visited[cur] = true;
	distance[cur] = length;
	for (int i = 0; i < adj[cur].size(); i++)
	{
		auto next = adj[cur][i];
		if (visited[next]) continue;
		set_distance(next, distance, length + 1);
	}
}

int main(void)
{
	cin.tie(NULL); ios_base::sync_with_stdio(false);
	cin >> N;
	for (int i = 0; i < N-1; i++)
	{
		int a, b; cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	set_distance(1, df, 0);
	for (int i = 1; i <= N; i++) visited[i] = false;
	set_distance(N, ds, 0);

	for (int i = 1; i <= N; i++)
	{
		if (df[i] <= ds[i])
			F += 1;
		else
			S += 1;
	}

	if (F > S)
		cout << "Fennec";
	else
		cout << "Snuke";

	return 0;
}

Measured memory_bytes: 11264
using Asakatsu20200503.Questions;
using Asakatsu20200503.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Asakatsu20200503.Questions
{
    /// <summary>
    /// ABC128 A
    /// </summary>
    public class QuestionA : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var ap = inputStream.ReadIntArray();
            var a = ap[0];
            var p = ap[1];
            p += a * 3;
            yield return p / 2;
        }
    }
}


namespace Asakatsu20200503
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionA();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace Asakatsu20200503.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace Asakatsu20200503.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define fore(i,a,b) for(int i=a,thxicesi=b; i<thxicesi;i++)
#define FIN ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
#define sz(s) int(s.size())
using namespace std;

int main()
{FIN;
    int a,b,c,d; cin>>a>>b>>c>>d;
    bool takaturn= true;
    while(a>0 && c>0){
        if(takaturn){
            c -= b;
        }else{
            a -= d;
        }
        takaturn = !takaturn;
    }
    if(a<=0) cout<<"No\n";
    else cout<<"Yes\n";
    return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	int i,t1,t2;
	
	t1=c;
	c=b;
	b=a;
	a=t1;
	
	cout<<a<<" "<<b<<" "<<c;
}


Measured memory_bytes: 256
//https://atcoder.jp/contests/abc150/tasks/abc150_a
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll k;
	cin>>k;
	ll x;
	cin>>x;
	if((k*500)>=x)
	{
		cout<<"Yes"<<"\n";
	}
	else
	{
		cout<<"No"<<"\n";
	}
	return 0;
}

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

typedef vector<int> vi;
typedef vector<vi> vvi;
// vvi data(N, vi(M));   N * M の2次元配列

typedef vector<long long> vl;
typedef vector<vl> vvl;


int main(){

	int N, M;
	cin >> N >> M;

	vvl data(8, vl(N));


	for(int i =0;i<N;i++){
		long long a, b, c;
		cin >> a >> b >> c;
		for (int bit = 0; bit < (1<<3); bit++){

			if (bit & (1<<0))	data.at(bit).at(i) += a;
			else	data.at(bit).at(i) -= a;

			if (bit & (1<<1))	data.at(bit).at(i) += b;
			else	data.at(bit).at(i) -= b;

			if (bit & (1<<2))	data.at(bit).at(i) += c;
			else	data.at(bit).at(i) -= c;
		}
	 }

	 long long ans=-1;


	 for(int i; i<8;i++){
		 sort(data.at(i).begin(), data.at(i).end());
		 reverse(data.at(i).begin(), data.at(i).end());
		 long long t = 0;
		 for(int j=0;j<M;j++)	t+= data.at(i).at(j);
		 if(ans<t)	ans = t;
	 }

	 cout << ans << endl;

}


Measured memory_bytes: 256
l,r=map(int, input().split())
if(r-l>=2019):
    print(0)

else:
    l%=2019
    r%=2019
    res = 10000000000

    for i in range(min(l,r),max(l,r)):
        for j in range(i+1, max(l,r)+1):
            res = min(res,(i*j)%2019)
    print(res)


Measured memory_bytes: 9024
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Markup;

namespace AlgoTest1
{

    class Program
    {
        static void Main(string[] args)
        {
             Int32 N = Int32.Parse(Console.ReadLine().Last().ToString());
            switch(N)
            {
                case 2:
                case 4:
                case 5:
                case 7:
                case 9:
                    Console.WriteLine("hon");
                    break;

                case 0:
                case 1:
                case 6:
                case 8:
                    Console.WriteLine("pon");
                    break;

                case 3:
                    Console.WriteLine("bon");
                    break;
            }
        }
    }
}

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

#define N (1000 + 10)

#define max(a, b) (a < b ? b : a)

int dp[N][N];
char a[N], b[N];

int LCS(void)
{
  const int a_size = strlen(a) - 1; // last one is '\n'
  const int b_size = strlen(b) - 1;
  int i, j;

  memset(dp, 0, sizeof(dp));

  for (i = 1; i < a_size + 1; ++i) {
    for (j = 1; j < b_size + 1; ++j) {
      int mx = max(dp[i][j - 1], dp[i - 1][j]);
      if (a[i - 1] == b[j - 1]) {
        mx = max(mx, dp[i - 1][j - 1] + 1);
      }
      dp[i][j] = mx;
    }
  }

  return dp[a_size][b_size];
}

int main(void)
{
  /*
  while (fgets(a, N, stdin) && fgets(b, N, stdin)) {
    printf("%d\n", LCS());
  }
  */
  int n, i;
  scanf("%d\n", &n);
  for ( i = 0; i < n; i++ ){
    fgets(a, N, stdin);
    fgets(b, N, stdin);
    printf("%d\n", LCS());
  }
  return 0;
}



Measured memory_bytes: 5752
n,m,l = map(int,input().split())

x = 0
A = [list(map(int,input().split(" "))) for i in range(n)]
B = [list(map(int,input().split(" "))) for j in range(m)]
AB = [[0 for i in range(l)] for j in range(n)]


for i in range(n):
    for j in range(l):
            for k in range(m):
                x += A[i][k] * B[k][j]
                AB[i][j] = x
            x = 0

for a in AB:
    print(*a)


Measured memory_bytes: 7064
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;
#define N 200001
int n,k;
int main(){
    while (scanf("%d",&n)!=EOF){
        k = 0;
        for (int i=0;i*4<=n&&!k;i++){
            if ((n-i*4)%7==0)
                k=1;
        }
        if (k)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

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


Measured memory_bytes: 256
#include <stdio.h>
 
using namespace std;
 
int main(){
    int n,m,l;
    scanf("%d %d %d",&n,&m,&l);
    int A[n][m],B[m][l];
    long long int C[n][l];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < l; j++){
            C[i][j] = 0;
        }
    }
 
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            scanf("%d",&A[i][j]);
        }
    }
    for(int i = 0; i < m; i++){
        for(int j = 0; j < l; j++){
            scanf("%d",&B[i][j]);
        }
    }
 
    for(int i = 0; i < n; i++){
        for(int k = 0; k < l; k++){
            for(int j = 0; j < m; j++){
                C[i][k] += A[i][j]*B[j][k];
            }
        }
    }
 
    for(int i = 0; i < n; i++){
        for(int j = 0; j < l-1; j++){
            printf("%lld ",C[i][j]);
        }
        printf("%lld\n",C[i][l-1]);
    }
}


Measured memory_bytes: 2892
import Control.Applicative ((<$>))
import Data.List ((\\))

allCards = [g ++ " " ++ (show v) | g <- ["S","H","C","D"] , v <- [1 .. 13]]

main = do
    _ <- getLine
    picked <- lines <$> getContents
    putStr . unlines $ allCards \\ picked

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}


const int mod = MOD;
const int max_n = 2000050;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
}comb(max_n);

int main(){
  ll h,w,k;cin >> h >> w >> k;
  mint ans=0;
  mint sum=0;
  rep(i,h){
    sum+=(w)*(w-1+2*i)/2;
  }
  //cout << sum <<endl;
  rep(i,h){
    mint tmp=sum;
    rep(j,w){
      ans+=tmp;
      tmp+=(j+1)*h;
      tmp-=(w-j-1)*h;
    }
    sum+=(i+1)*w;
    sum-=(h-i-1)*w;
  }
  ans/=2;
  ans*=comb(h*w-2,k-2);
  cout << ans <<endl;
}

Measured memory_bytes: 34176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int N;
	cin >> N;
	int A[100000];
	rep(i, N) cin >> A[i];

	deque<int> D;
	D.push_front(-1);

	rep(i, N) {
		auto itr = lower_bound(D.begin(), D.end(), A[i]) - 1;
		*itr = A[i];
		if (itr == D.begin()) D.push_front(-1);
	}

	co(D.size() - 1);

	Would you please return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>

using namespace std;
typedef long long ll;

int main(){
  int N;
  cin >> N;
  vector<vector<int>> a(10,vector<int>(10));

  for(int i=1;i<=N;i++){
    int n=i%10;
    int m=i;
    while(10<=m) m/=10;
    a[n][m]++;
  }

  ll ans=0;
  for(int n=0;n<10;n++){
    for(int m=0;m<10;m++){
      ans+=a[n][m]*a[m][n];
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 380
url = "https://atcoder.jp//contests/abc116/tasks/abc116_c"

def main():
    input()
    h = list(map(int, input().split()))
    h.append(0)
    count = 0
    def start_end(h):
        s_e = [-1,-1]
        for i in range(len(h)):
            if h[i] != 0 and s_e[0] == -1:
                s_e[0] = i
            elif h[i] == 0 and s_e[0] != -1:
                s_e[1] = i
                break
        return s_e
    while True:
        s_e = start_end(h)
        if s_e[0] == -1 and s_e[1] == -1:
            print(count)
            exit()
        min_h = min(h[s_e[0]:s_e[1]])
        for i in range(s_e[0], s_e[1]):
            h[i] -= min_h
        count += min_h




if __name__ == '__main__':
    main()


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

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

    int w,h;
    while(cin>>h>>w){
        if(w==0) break;
        int ans=0;
        int a[h],b[w];
        map<int,int> mp;
        for(int i=0;i<h;i++){
            cin>>a[i];
            ans+=a[i];
            mp[a[i]]++;
        }
        for(int i=0;i<w;i++){
            cin>>b[i];
            if(mp[b[i]]==0){
                ans+=b[i];
            }
            else mp[b[i]]--;

            
       }
        cout<<ans<<endl;

    }
}


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


int main() {
    long long N;
    cin >> N;
    string res = "";
    while (N) {
        --N;
        res += (char)('a' + (N % 26));//char'a'+(n%26)って書き方で文字が出せるの意味わかんないけどそうなんだな
        N /= 26;
    }
    reverse(res.begin(), res.end());
    cout << res << endl;
}

Measured memory_bytes: 3648
#include<cstdio>
#include<algorithm>
char p[100], q[100] = "AKIHABARA";
int main() {
	int i, pv = 0;
	scanf("%s", p);
	for (i = 0; q[i]; i++) {
		if (q[i] == p[pv]) {
			pv++;
		}
		else if(q[i] != 'A'){
			puts("NO");
			return 0;
		}
	}
	if (!p[pv])puts("YES");
	else puts("NO");
}

Measured memory_bytes: 128
#include <iostream>//数据输入输出流
#include <cstring>//字符串操作函数
#include <cstdio>//C的输入输出
#include <cstdlib>//定义杂项函数及内存分配函数
#include <cmath>//C中的数学函数
#include <string>//c++中的string类 他不能用strcpy等c函数去操作
#include <vector>//STL vetor
#include <list>//STL list
#include <map>// STL map
#include <queue>// STL queue
#include <stack>//sTL stack
#include <bitset>//bitset可按位定义串
//比如：bitset <1000> all;定义一个1000位的串
#include <algorithm>//STL各种算法 比如 swap sort merge max min 比较
#include <numeric>//常用数字操作 一般和algorithm搭配使用
#include <functional>//STL定义运算函数（代替运算符）
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
#define LOCAL
#define zeros(a,n) memset(a,0,(n)*sizeof(a[0]))
const int modn = 1e9+7;
int mod(int x) { return x<0?x+modn:x<modn?x:x-modn; }
//inv [ i ] = (modn - modn/i)*inv[ modn%i ] %modn;

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    LL ans = 0,res = 0;
    int n;
    cin>>n;
    for(int i = 1; i <=n;++i){
        if(i%3==0 || i%5==0) ans += i;
        res += i;
    }
    cout<<res-ans<<endl;
    return 0;
}



Measured memory_bytes: 3192
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	string s;
	cin>>s;
	for(int i=0;i<a;i++){
		if(s[i]<'0'||s[i]>'9'){
			cout<<"No"<<endl;
			return 0;
		}
	}
	if(s[a]!='-'){
		cout<<"No"<<endl;
		return 0;
	}
	for(int i=a+1;i<=a+b;i++){
		if(s[i]<'0'||s[i]>'9'){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}


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

int main() {
  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 << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void){
    char a[20],b[20],c[20];
    int aa,bb,cc;
    scanf("%s",a);
    scanf("%s",b);
    scanf("%s",c);
    aa=strlen(a);
    bb=strlen(b);
    cc=strlen(c);
    if(a[aa-1]!=b[0]){printf("NO\n");return 0;}
    else if(b[bb-1]!=c[0]){printf("NO\n");return 0;}
    else {printf("YES");}
}

Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int MAXN = 500;
const ll INF = ll(1E18);
int A[MAXN + 5][MAXN + 5], B[MAXN + 5][MAXN + 5], n;
// A[i][j] -> (p[i] + p[i+1] + ... p[j] >= 1) (i <= j)
// B[i][j] -> (p[i] + p[i+1] + ... p[j] <= 1) (i <= j)
ll SA[MAXN + 5][MAXN + 5], SB[MAXN + 5][MAXN + 5];
// SA[i][j] -> A[1][j] + A[2][j] + ... + A[i][j]
// SB[i][j] -> B[1][j] + B[2][j] + ... + B[i][j]
ll dp[2][MAXN + 5][MAXN + 5], f[2][MAXN + 5], g[2];
int main() {
	scanf("%d", &n);
	for(int i=1;i<=n;i++) {
		for(int j=1;j<=i-1;j++) scanf("%d", &B[j][i-1]);
		for(int j=i+1;j<=n;j++) scanf("%d", &A[i][j-1]);
	}
	for(int j=1;j<=n;j++)
		for(int i=1;i<=n;i++)
			SA[i][j] = A[i][j] + SA[i-1][j], SB[i][j] = B[i][j] + SB[i-1][j];
	n--;
	for(int j=1;j<=n;j++) {
		for(int k=j+1;k<=n;k++)
			dp[0][j][k] = INF;
		f[0][j] = INF;
	}
	g[0] = 0;
	for(int i=1;i<=n;i++) {
		for(int j=1;j<i;j++) {
			for(int k=j+1;k<i;k++)
				dp[1][j][k] = dp[0][j][k], dp[0][j][k] = INF;
			f[1][j] = f[0][j], f[0][j] = INF;
		}
		g[1] = g[0], g[0] = INF;
		for(int j=1;j<i;j++) {
			for(int k=j+1;k<i;k++) {
				dp[0][j][k] = min(dp[0][j][k], dp[1][j][k] + SA[i][i] - SA[k][i] + SB[j][i]);
				dp[0][k][i] = min(dp[0][k][i], dp[1][j][k] + SB[k][i]);
			}
			f[0][j] = min(f[0][j], f[1][j] + SA[i][i] - SA[j][i]);
			dp[0][j][i] = min(dp[0][j][i], f[1][j] + SB[j][i]);
		}
		g[0] = min(g[0], g[1] + SA[i][i]);
		f[0][i] = min(f[0][i], g[1]);
	}
	ll mn = INF;
	for(int j=1;j<=n;j++) {
		for(int k=j+1;k<=n;k++)
			mn = min(mn, dp[0][j][k]);
		mn = min(mn, f[0][j]);
	}
	mn = min(mn, g[0]);
	printf("%lld\n", mn);
}

Measured memory_bytes: 10112
#include<iostream>
#include <algorithm>
#include <string>
#include<math.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
int main() {
    int a, b;
    cin >> a >> b;
    cout << (a - 1)*(b - 1) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define br break
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0, so x)
#define all(x) (x).be , (x).en
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;
vector<ll> v[200005] , vv[200005] ;
ll visited[200005] , a[200005] , b[200005];
void dfs(ll curr , ll nos)
{
    visited[curr] = 1 ;
    a[curr] = nos ;
    for(auto &x : v[curr]){
        if(visited[x] == 0){
            dfs(x, nos);
        }
    }
}
void dfss(ll curr , ll nos)
{
    visited[curr] = 1;
    b[curr] = nos;
    for(auto &x : vv[curr]){
        if(visited[x] == 0 ){
            dfss(x, nos) ;
        }
    }
}
int main()
{
    ios;
    ll n , k , l ;
    cin >> n >> k >> l ;
    forn(i , 1 , k ) {
       ll x , y ;
       cin >> x >> y;
       v[x].pb(y) ;
       v[y].pb(x) ;
    }
    forn(i , 1 , l ) {
       ll x , y ;
       cin >> x >>  y;
       vv[x].pb(y) ;
       vv[y].pb(x) ;
    }
    ll ccr = 0 , ccl = 0 ;
    forn(i , 1 , n ) {
       if(visited[i] == 0 ) {
            ++ccr;
           dfs(i , ccr);
       }
    }
    ms(visited) ;
    forn(i , 1 , n ) {
       if(visited[i] == 0){
        ++ccl;
        dfss(i , ccl) ;
       }
    }
    map< pair<ll , ll > , ll > mpp ;
    forn(i , 1 , n ) {
       pll foo = {a[i] , b[i]} ;
       mpp[foo]++;
    }
    vl ans ;
    forn(i , 1 , n ) {
       pll curr = {a[i] , b[i] } ;
       ll tot = mpp[curr] ;
       ans.pb(tot) ;
    }
    for(auto &x : ans) cout << x << " " ;
    cout << el ;
}


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

int main(){
  int i,j,a,counter;
  string line;

  int m,ii;
  cin >> m;
  for(ii=0; ii<m; ii++){
    counter=0;
    cin >> line;
    int len;
    len = line.size();
    map<string,bool> p;

    string A1,A2,B1,B2,C;
    for(a=1; a<len; a++){
      for(i=0;i<a;i++) A1+=line[i];
      for(i=a-1; i>=0; i--) A2+=line[i];

      for(i=a; i<len; i++) B1+=line[i];
      for(i=len-1; i>=a; i--) B2+=line[i];

      C=A1+B1;
	if(p[C]==false){
	  counter++;
	  p[C]=true;
	}

      C=A1+B2;
	if(p[C]==false){
	  counter++;
	  p[C]=true;
	}

      C=A2+B1;
	if(p[C]==false){
	  counter++;
	  p[C]=true;
	}

      C=A2+B2;
	if(p[C]==false){
	  counter++;
	  p[C]=true;
	}

      C=B1+A1;
	if(p[C]==false){
	  counter++;
	  p[C]=true;
	}

      C=B1+A2;
	if(p[C]==false){
	  counter++;
	  p[C]=true;
	}

      C=B2+A1;
	if(p[C]==false){
	  counter++;
	  p[C]=true;
	}

      C=B2+A2;
	if(p[C]==false){
	  counter++;
	  p[C]=true;
	}
	A1.clear();
	A2.clear();
	B1.clear();
	B2.clear();
    }


    cout << counter << endl; 
  }
 return 0;
}

Measured memory_bytes: 1004
N,T=map(int,input().split())
A=[int(x) for x in input().split()]

buy_min=10000000000
max_ben=0
ans=0

for i in range(N):
  if A[i]>buy_min and (A[i]-buy_min)>max_ben:
    ans=1
    max_ben=(A[i]-buy_min)
  elif A[i]>buy_min and (A[i]-buy_min)==max_ben:
    ans+=1
  if buy_min>A[i]:
    buy_min=A[i]
print(ans)

Measured memory_bytes: 15060
N, M = map(int, input().split())
F = [0] * M
for i in range(N):
  for a in [int(x) - 1 for x in input().split()][1:]:
    F[a] += 1
cnt = 0
for f in F:
  cnt += 1 if f == N else 0
print(cnt)

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

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

    vector<int> A(N);

    for (int i = 0; i < N; i++){
        A[i] = L + i;
    }

    int sum = 0;

    for (int i = 0; i < N; i++){
        sum += A[i];
    }

    if (L >= 0){
        sum -= A[0];
    }

    if (L < 0){
        if (find(A.begin(), A.end(), 0) != A.end()){
            
        } else {
            sum -= A[N-1];
        }
    }

    cout << sum << endl;
}


Measured memory_bytes: 256
var
    a,b,c,i,j,z:longint;
    s:array[1..10000]of string;
    k:array[1..10000]of longint;
    ans:qword;
begin
    read(a,b,c);
    for i:=1 to a do
    begin
        str(i,s[i]);
        for j:=1 to length(s[i]) do
        begin
            val(s[i][j],z);
            k[i]:=k[i]+z;
        end;
        if(k[i]>=b)and(k[i]<=c)then inc(ans,i);
    end;
    writeln(ans);
end.

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define debug(...) { printf("#  "); printf(__VA_ARGS__); puts(""); }
#define fi first
#define se second
#define endl "\n" 
using ll = long long;
using pII = pair <int, int>;
using pLL = pair <ll, ll>;
using VI = vector <int>;
using VL = vector <ll>;
constexpr int mod = 1e9 + 7;
template <class T1, class T2> inline void chadd(T1 &x, T2 y) { x += y; if (x >= mod) x -= mod; else if (x < 0) x += mod; } 
template <class T1, class T2> inline void chmax(T1 &x, T2 y) { if (x < y) x = y; }
template <class T1, class T2> inline void chmin(T1 &x, T2 y) { if (x > y) x = y; }
inline int rd() { int x; cin >> x; return x; }
template <class T> inline void rd(T &x) { cin >> x; }
template <class T> inline void rd(vector <T> &vec) { for (auto &it : vec) cin >> it; }
template <class T> inline void out(T s) { cout << s << "\n"; }
template <class T> inline void out(vector <T> &vec) { for (auto &it : vec) cout << it << " "; cout << endl; } 
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ll qpow(ll base, ll n) { ll res = 1; while (n) { if (n & 1) res = res * base % mod; base = base * base % mod; n >>= 1; } return res; }
constexpr int N = 1e5 + 10;
int n, a[N], b[N]; 
void run() {
	for (int i = 1; i < n; ++i) cin >> b[i];
	a[n] = b[n - 1];
	b[0] = mod;
	for (int i = n - 1; i >= 1; --i) a[i] = min(b[i], b[i - 1]);
	int res = 0;
	for (int i = 1; i <= n; ++i) res += a[i];
	cout << res << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	cout << fixed << setprecision(20);
	while (cin >> n) run();
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>  //sort
#include <iostream>
#include <regex>  //正規表現
#include <string>
#include <vector>

using namespace std;

int main() {
  int n;
  long long ans = 1;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    ans *= i;
    ans %= 1000000007;
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int n;

void solve(){
    int ans = 0;
    vector<string> vs(n);
    rep(i,n) cin >> vs[i];

    for(int i=0;i+1<n;i+=2){
        string s1 = vs[i];
        string s2 = vs[i+1];
        if(s1 == "lu" and s2 == "ru") ans++;
        else if(s1 == "ru" and s2 == "lu") ans++;
        else if(s1 == "ld" and s2 == "rd") ans++;
        else if(s1 == "rd" and s2 == "ld") ans++;
    }
    cout << ans << endl;
}

int main(){
    while(1){
        cin >> n;
        if(n==0) break;
        solve();
    }
}

Measured memory_bytes: 3168
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <stack>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void)
{
    int N;
    cin >> N;
    int ans = 1;
    while (ans <= N)
    {
        ans *= 2;
    }
    cout << ans / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#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>;


void Main()
{
  int n; cin >> n;
  if (n%1000 ==0) cout << 0 << endl;
  else cout << 1000-n%1000 << endl;
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx")
#define ll long long 
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define REP(i,n) for (int i=0; i<n; i++)
#define RREP(i,n) for (int i=(n-1); i>=0; i--)
#define ALL(x) x.begin(),x.end()
#define SZ(x) x.size()
#define MNTO(a,b) a = min(a,(__typeof__(a))(b))
#define MXTO(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define debug(x) cerr<<#x<<" is "<<x<<endl

using namespace std;

const int maxn = 505;
const int intinf = 1<<29;
const ll inf = 1ll<<60;


void GG(){cout<<"No\n"; exit(0);}

ll in[3][1005];

int main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    ll X, Y, Z, k; cin>>X>>Y>>Z>>k;
    REP(i,X) cin>>in[0][i]; 
    REP(i,Y) cin>>in[1][i];
    REP(i,Z) cin>>in[2][i];
    sort(in[0],in[0]+X,greater<ll>());
    sort(in[1],in[1]+Y,greater<ll>());
    sort(in[2],in[2]+Z,greater<ll>());
    vector<ll> re;
    REP(i,X)REP(j,Y)REP(kk,Z){
    	if ((i+1)*(j+1)*(kk+1)<=k){
    		re.pb(in[0][i]+in[1][j]+in[2][kk]);
    	}
    }
    sort(ALL(re),greater<ll>());
    REP(i,k) cout<<re[i]<<'\n';
}

Measured memory_bytes: 1400
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int a, b, t;
	cin >> a >> b >> t;
	
	cout << (t / a) * b << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.System.*;
import java.io.*;
import java.math.*;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		HashMap<Integer, Integer> map = new HashMap<>();
		int fir = 0, sec = 0;
		for(int i = 0; i < n; i++) {
			int num = sc.nextInt();
			if (!map.containsKey(num)) {
				map.put(num, 1);
			} else {
				int value = map.get(num);
				if (value == 1 || value == 3) {
					if (num >= fir) {
						sec = fir;  fir = num;
					} else if (num >= sec) {
						sec = num;
					}
				}
				map.put(num, value + 1);
			}
		}
		long ans =(long)fir * (long)sec;
		out.println(ans);

		out.close();
	}

static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}

Measured memory_bytes: 28332
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
ll a, b;
ll x[100100];

ll solve() {
    ll res = 0;
    for (int i = 1; i < n; i++) {
        res += min(a * (x[i]-x[i-1]), b);
    }
    return res;
}

void input() {
    cin >> n >> a >> b;
    for (int i = 0; i < n; i++) cin >> x[i];
}

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

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 1024