akhauriyash/Code-Regression huggingface dataset:
n, k = map(int, raw_input().split())
a = map(int, raw_input().split())
s = set(a)
if len(s) < k:
    print 0
    exit()
d = dict()
for i in a:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1
cnt = 0
for i in sorted(d.values())[:len(s) - k]:
    cnt += i
print cnt


Measured memory_bytes: 39672
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

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

#define QUEUE_SIZE 0x10000
typedef int Item;
Item queue[QUEUE_SIZE];
size_t queue_in = 0;
size_t queue_out = 0;
int queue_is_full = 0;

size_t inc_queue_index(size_t index)
{
  return (index + 1) % QUEUE_SIZE;
}

void queue_push(const Item* item)
{
  if(queue_is_full) {
    fputs("Queue is full.\n", stderr);
    exit(1);
  }
  memcpy(&queue[queue_in], item, sizeof(Item));
  queue_in = inc_queue_index(queue_in);
  queue_is_full = queue_in == queue_out;
}

void queue_pop(Item* result)
{
  if(queue_in == queue_out && !queue_is_full) {
    fputs("Queue is empty.\n", stderr);
    exit(1);
  }
  memcpy(result, &queue[queue_out], sizeof(Item));
  queue_out = inc_queue_index(queue_out);
  queue_is_full = 0;
}

void clear_queue()
{
  queue_in = 0;
  queue_out = 0;
  queue_is_full = 0;
}

int main()
{
  int a, b, c, d;
  scanf("%d%d%d%d", &a, &b, &c, &d);
  int train = min(a, b);
  int bus = min(c, d);
  printf("%d\n", train + bus);
  return 0;
}


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

struct edge{int to,cost;};
typedef pair<int,int> P;

int n;
vector<edge> g[300030];
int d[300030];
int inf = 2000000007;

void dijkstra(int s){
  priority_queue<P,vector<P>,greater<P>> que;
  for(int i = 0;i <= 3*n;i++){
    d[i] = inf;
  }
  d[s] = 0;
  que.push(P(0,s));
  
  while(!que.empty()){
    P p = que.top();
    que.pop();
    int v = p.second;
    if(d[v] < p.first) continue;
    for(int i = 0;i < g[v].size();i++){
      edge e = g[v][i];
      if(d[e.to] > d[v] + e.cost){
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to],e.to));
        //cout << 'v' << v << endl;
      }
    }
  }
}


int main(){
  int m;
  cin >> n >> m;
  for(int i = 0;i < m;i++){
    int u,v;
    cin >> u >> v;
    u--;v--;
    edge e;
    e.to = v+n;e.cost = 1;
    g[u].push_back(e);
    e.to = v+2*n;
    g[u+n].push_back(e);
    e.to = v;
    g[u+2*n].push_back(e);
  }
  int s,t;
  cin >> s >> t;
  s--;t--;
  dijkstra(s);
  if(d[t] == inf){
    cout << -1 << endl;
  }
  else{
    cout << d[t]/3 << endl;
  }
}

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

using ll = long long;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
void YES(bool f){cout<<(f?"YES":"NO")<<endl;}
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 

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

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

    bool match = true;
    int j = 0;
    rep(i, akb.size()) {
        if (akb[i] == 'A') {
            if (j < S.size()) {
                if (S[j] == 'A') {
                    j++;
                }
            }
        } else {
            if (j < S.size()) {
                if (akb[i] == S[j]) {
                    j++;
                } else {
                    match = false;
                    break;
                }
            } else {
                match = false;
                break;
            }
        }
    }
    if (match && j < S.size())
        match = false;

    YES(match);
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main()
    {
        var AB = ReadLine().Split().Select(int.Parse).ToArray();
        var A = AB[0];
        var B = AB[1];
        if (A == 1 && B <= 2)
        {
            if (B == 2)
            {
                WriteLine($"2 {B}");
                WriteLine("#.#");
            }
            else
            {
                WriteLine("1 2");
                WriteLine(".#");
            }
        }
        else
        {
            var map = new char[100, 100];
            for (int i = 0; i < 100; i++)
            {
                for (int j = 0; j < 100; j++)
                {
                    map[i, j] = '.';
                }
            }
            var px = 0;
            var py = 0;
            for (int i = 0; i < A - 1; i++)
            {
                map[px, py + 1] = '#';
                map[px + 1, py + 1] = '#';
                map[px + 1, py] = '#';

                if (py == 98)
                {
                    px += 2;
                    py = 0;
                }
                else
                {
                    py += 2;
                }
            }

            px += 3;
            py = 0;
            for (int i = 0; i < B - 1; i++)
            {
                map[px, py] = '#';
                if (py == 98)
                {
                    px += 2;
                    py = 0;
                }
                else
                {
                    py += 2;
                }
            }
            if (A == 1) map[99, 99] = '#';
            WriteLine("100 100");
            for (int i = 0; i < 100; i++)
            {
                for (int j = 0; j < 100; j++)
                {
                    Write(map[i, j]);
                }
                WriteLine();
            }
        }
    }
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,M;
int A[111111];

int acc[222222];

signed main(){
    cin>>N>>M;
    rep(i,N)cin>>A[i],A[i]--;

    int sum=0;
    rep(i,N-1){
        int a=A[i+1];
        if(A[i]>a)a+=M;
        acc[A[i]+2]++;
        acc[a+1]--;
        sum+=a-A[i];
    }

    rep(i,222222-1)acc[i+1]+=acc[i];

    rep(i,N-1){
        int a=A[i+1];
        if(A[i]>a)a+=M;
        acc[a+1]-=a-A[i]-1;
    }

    rep(i,222222-1)acc[i+1]+=acc[i];

    rep(i,M)acc[i]+=acc[i+M];
    cout<<sum-*max_element(acc,acc+M)<<endl;
    return 0;
}


Measured memory_bytes: 2816
c = [list(map(int, input().split())) for _ in range(3)]
ok = False
for a1 in range(101):
    for a2 in range(101):
        for a3 in range(101):
            b1 = c[0][0] - a1
            b2 = c[0][1] - a1
            b3 = c[0][2] - a1

            a = [a1, a2, a3]
            b = [b1, b2, b3]
            ok_sub = True
            for i in range(3):
                for j in range(3):
                    if a[i] + b[j] != c[i][j]:
                        ok_sub = False
            if ok_sub:
                ok = True

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


Measured memory_bytes: 46700
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

int main()
{
    int n, a, b, c;
    std::cin >> n >> a >> b >> c;

    std::vector<int> l(n);
    for (int i = 0; i < n; i++) {
        std::cin >> l[i];
    }

    auto dfs = [=](auto f, int idx, int a_, int b_, int c_) {
        if (idx == n) {
            return ((std::min({ a_, b_, c_ }) > 0) ? abs(a - a_) + abs(b - b_) + abs(c - c_) - 30 : 1e8);
        }

        return std::min({ f(f, idx + 1, a_, b_, c_), f(f, idx + 1, a_ + l[idx], b_, c_) + 10, f(f, idx + 1, a_, b_ + l[idx], c_) + 10, f(f, idx + 1, a_, b_, c_ + l[idx]) + 10 });
    };

    std::cout << dfs(dfs, 0, 0, 0, 0) << std::endl;
}


Measured memory_bytes: 888
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
 		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[][][] nums = new int[4][3][10];
		for (int i = 0; i < n; i++) {
			int b = sc.nextInt();
			int f = sc.nextInt();
			int r = sc.nextInt();
			int v = sc.nextInt();
			nums[b - 1][f - 1][r - 1] = nums[b - 1][f - 1][r - 1] + v;
		}
		for (int j = 0; j < 4; j++) {
			for (int k = 0; k < 3; k++) {
				for (int L = 0; L < 10; L++) {
					System.out.print(" ");
					System.out.print(nums[j][k][L]);
				}
				System.out.println();
			}
			if (j < 3) {
				System.out.println("####################");
			}
		}
    }
}



Measured memory_bytes: 29908
#include <bits/stdc++.h>
#define rep(i,n) for(ll i = 0; i < n; i++)
using namespace std;
typedef long long ll;
 
int main(){
  string S;
  cin >> S;
  int l = S.size();
  rep(i, l)cout << 'x';
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
// J'aime
// Chemise Blanche

#include <bits/stdc++.h>
using namespace std;

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int n; cin >> n;
  vector<int> a(n);
  for (auto &i : a) cin >> i;
  int ans = 0;
  for (int i = 1; i < n - 1; i++) {
    if (a[i - 1] < a[i] && a[i] < a[i + 1]) ans++;
    if (a[i - 1] > a[i] && a[i] > a[i + 1]) ans++;
  }
  cout << ans << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


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

int main() {
    int x;
    cin >> x;
    vector<int> vec{7, 5, 3};
    if (count(vec.begin(), vec.end(), x) > 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
# include <iostream>
using namespace std;
struct info
{
	int val;
	char c;
	int num;
};
int partition(info *a, int p, int r)
{
	int i = p - 1;
	int x = a[r].val;
	for (int j = p; j < r; j++) if (a[j].val <= x) swap(a[++i], a[j]);
	swap(a[i+1], a[r]);
	return i+1;
}

void quick_sort(info *a,int st,int ed)
{
	if(st >= ed) return ;
	else
	{
		int index = partition(a,st,ed);
		quick_sort(a,st,index-1);
		quick_sort(a,index+1,ed);
	}
}

int main()
{
	int n,k; info *a;
	scanf("%d%c",&n,&k); a = new info [n];
	for(int i = 0;i < n;i++) scanf("%c %d%c",&a[i].c,&a[i].val,&k);
	for(int i = 0;i < n;i++) a[i].num = i;
	quick_sort(a,0,n-1);
	bool f = true;
	for(int i = 1;i < n;i++)
	{
		if(a[i].val == a[i-1].val)
		{
			if(a[i].num < a[i-1].num)
			{
				f = false;
				break;
			}
		}
	}
	printf("%s\n",f?"Stable":"Not stable");
	for(int i = 0;i < n;i++) printf("%c %d\n",a[i].c,a[i].val);
	return 0;
}


Measured memory_bytes: 4356
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

int n;
int h[100010];
int dp[100010];

void chmin(int a, int *b)
{
	if (*b > a)
		*b = a;
}

int main(int argc, char const *argv[])
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		dp[i] = INT_MAX - 1;
		scanf("%d", h+i);
	}
	dp[0] = 0;

	for (int i = 0; i < n; i++)
	{
		if(i+1 < n) chmin(dp[i] + abs(h[i + 1] - h[i]), &dp[i + 1]);
		if(i+2 < n) chmin(dp[i] + abs(h[i + 2] - h[i]), &dp[i + 2]);
	}

	printf("%d", dp[n - 1]);
	return 0;
}


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

int main() {
  int W, a, b;
  cin >> W >> a >> b;
  
  int res = 0;
  
  if (a < b) {
    res = b - (a + W);
  }
  else {
    res = a - (b + W);
  }
  
  if (res < 0) res = 0;
  
  cout << res << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() /4;
const ll linf = numeric_limits<ll>::max() /4;
const ull ulinf = numeric_limits<ull>::max()/4;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

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

ll n,a,pos[200005] = {};
set<ll> s;

int main(){
    cin >> n;
    rep(i,1,n+1){
        cin >> a;
        pos[a] = i;
    }

    s.it(0);
    s.it(n+1);
   
    ll ans = 0;
	rep(i,1,n+1){
	    ll l,r;
	    
	    s.it(pos[i]);
	    auto ite = s.find(pos[i]);
	    
        l = *(--ite);
        ite++;
        r = *(++ite);
        
        ans += (pos[i] - l) * ( r - pos[i]) * i;
	}
	P(ans);

	return  0;
}


Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }


void solve();

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

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
    solve();
  }
}

void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<vector<int> > v(3);
  rep(i, sz(s)) {
    if (s[i] == 'R') v[0].eb(i);
    else if (s[i] == 'G') v[1].eb(i);
    else v[2].eb(i);
  }
  ll ans = 0;
  rep(i, n) {
    rep3(j, i + 1, n) {
      if (s[i] == s[j]) continue;
      int k;
      if (s[i] != 'R' && s[j] != 'R') k = 0;
      else if (s[i] != 'G' && s[j] != 'G') k = 1;
      else k = 2;
      int it = ub(v[k], j);
      ans += sz(v[k]) - it;
      if (j + (j - i) < n && s[j + (j - i)] != s[i] && s[j + (j - i)] != s[j]) ans--;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3656
n = int(input())
value = list(map(int, input().split(' ')))
cost = list(map(int, input().split(' ')))
ans = 0
vc = []
for v,c in zip(value, cost):
  if v-c > 0:
    vc.append(v-c)
  else:
    pass
print(sum(vc))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int x=(c+b-1)/b;
  int y=(a+d-1)/d;
  if(x<=y)puts("Yes");
  else puts("No");
  return(0);
}


Measured memory_bytes: 3580
s = input()
ans = 0

for i in range(1 << len(s)-1):
    tmp = 0
    a = int(s[0])
    for j in range(len(s)-1):
        if(i & (1 << j)):
            tmp += a
            a = 0
        a = a * 10 + int(s[j+1])
    tmp += a
    ans += tmp
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <cstring>
#include <cctype>
#include <sstream>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <complex>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for(int i = a; i < (int)b; i++)
#define pb push_back
#define mp make_pair
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
const int INF = 1<<28;
const ll MOD = 1000000007;

int dice[6] = {1,5,4,3,2,6};
void swap(int i, int j, int k, int l) {
	int temp = dice[l];
	dice[l] = dice[k];
	dice[k] = dice[j];
	dice[j] = dice[i];
	dice[i] = temp;
}
int main() {
	int n;
	while(cin >> n, n) {
		dice[0] = 1;
		dice[1] = 5;
		dice[2] = 4;
		dice[3] = 3;
		dice[4] = 2;
		dice[5] = 6;
		REP(i, n) {
			string in; cin >> in;
			if(in == "north")
				swap(0,4,5,1);
			else if(in == "south")
				swap(0,1,5,4);
			else if(in == "west")
				swap(0,3,5,2);
			else if(in == "east")
				swap(0,2,5,3);
		}
		cout << dice[0] << endl;
	}
	return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define Liny "Yes\n"
#define Linn "No\n"

int main(){
  char s[4]; scanf("%s",s);
  sort(s,s+4);
  bool yes = false;
  if(s[0]==s[1] && s[1]!=s[2] && s[2]==s[3]) yes = true;
  cout << (yes?Liny:Linn);
}

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

#ifdef _LOCAL
  #include <utils/debug.hpp>
  #include <utils/random_generate.hpp>
  #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
  #define debug(...) 42
  #define generate_string(...) 42
  #define generate_array(...) 42
  #define generate_unique_array(...) 42
#endif

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vl2;
const bool multiple_queries = false;
#define rep(i, n) for(ll i = 0; i < (n) ; ++i)
#define For(i, a, b) for(ll i = (a); i < (b) ; ++i)
#define revrep(i, n) for(ll i = (n) - 1; i >= 0 ; --i)
#define revFor(i, b, a) for(ll i = (b) - 1; i >= (a) ; --i)
#define all(v) v.begin(), v.end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(i) __builtin_popcountl((i))
#define substring(s, start, end) s.substr((start), (end) - (start) + 1)

void scan(){}
template <class Head, class... Tail>
void scan(Head&& head, Tail&&... tail) {
  cin >> head;
  scan(forward<Tail>(tail)...);
}

void print(){}
void println(){cout << endl;}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T>& vs){
  for (auto v: vs){
    cout << v;
    if (&v != &vs.back()) cout << " ";
  }
  cout << endl;
}

template <class Head, class... Tail>
void println(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  println(forward<Tail>(tail)...);
}

template <class T>
void println(vector<T>& vs){for (auto v: vs) cout << v << endl;}

void solve(){
  ll n; ll cnt = 0; bool ok = false;
  scan(n);
  rep(i, n){
    ll a, b;
    scan(a, b);
    if (a == b) ++cnt;
    else cnt = 0;
    if (cnt == 3) ok = true;
  }
  if (ok)
  println("Yes");
  else println("No");
}

void test(ll num = 0, bool verbose = false){
  rep(i, max(1LL, num)){
    ll t = clock();
    if (verbose) cout << "\n#####" << " " << i + 1 << " " << "#####" << " " << "\n## Answer ##\n";
    solve();
    if (verbose) {cout << "\nElapsed Time:" << " " << 1000.0 * (clock() - t) / CLOCKS_PER_SEC << " " << "[ms]" << endl;}
  }
}

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(15);
  #ifdef _LOCAL
    test(6, true);
  #else
    ll t = 0;
    if (multiple_queries) cin >> t;
    test(t, false);
  #endif
  return 0;
}

Measured memory_bytes: 3604
use std::io::Read;

const MOD : u64 = 998_244_353;

fn pow(a: u64, p: u64) -> u64 {
    if p == 0 { 1 }
    else {
        let mut res = pow(a, p/2);
        res = (res * res) % MOD;
        if p%2 == 1 { res = (res * a) % MOD; }
        res
    }
}

fn solve(cnt: Vec<u64>, num: u64) -> u64 {
    if cnt[0] != 1 { return 0; }
    if num == 1 { return 1; }
    let mut res = 1;
    let mut sum = 1;
    for i in 1..cnt.len() {
        if cnt[i] == 0 { return 0; }
        res = res * pow(cnt[i-1], cnt[i]) % MOD;
        sum += cnt[i];
        if sum == num { break; }
    }
    res
}

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).ok();
    let mut it = buf.split_whitespace();
    let n = it.next().unwrap().parse::<usize>().unwrap();
    let mut cnt = vec![0; n];
    let mut valid = true;
    for i in 0..n {
        let idx = it.next().unwrap().parse::<usize>().unwrap();
        if (i == 0)^(idx == 0) { valid = false; }
        cnt[idx] += 1;
    }
    println!("{}", if valid { solve(cnt, n as u64) } else { 0 });
}


Measured memory_bytes: 6396
#include <iostream>
using namespace std;
using LL = long long;
using P = pair<int, LL>;

// dp[i][j]: 重さ j 以下かつ i 個以内で得られる最大の価値
// dp[0][_] = 0
// dp[_][0] = 0
// dp[i+1][j] = max(dp[i][j-w[i]], dp[i][j])

LL dp[101][100010];

P cost[1001];

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

    for(int i = 0; i < N; ++i) {
        int w, v;
        cin >> w >> v;
        cost[i] = {w, v};
    }

    for(int i = 0; i < W; ++i) {
        dp[0][i] = 0;
    }

    for(int i = 0; i < N; ++i) {
        for(int j = 0; j <= W; ++j) {
            if(j >= cost[i].first) dp[i+1][j] = max(dp[i][j], dp[i][j-cost[i].first] + cost[i].second);
            else dp[i+1][j] = dp[i][j];
        }
    }

    cout << dp[N][W] << endl;
}


Measured memory_bytes: 79104
#include<bits/stdc++.h>
using namespace std;
char fie[11][11];

void rotate(){
char buf[11][11];
for(int i=0;i<8;i++){
for(int j=0;j<8;j++){
buf[j][i] = fie[i][7-j];
}
}
for(int i=0;i<8;i++)
for(int j=0;j<8;j++)
fie[j][i] = buf[j][i];
}

void view(){
for(int i=0;i<8;i++){
for(int j=0;j<8;j++) cout << fie[j][i];
cout << endl;
}
}

int main(){

for(int i=0;i<8;i++)
for(int j=0;j<8;j++)
cin >> fie[j][i];

rotate();
cout << 90 << endl;
view();
rotate();
cout << 180 << endl;
view();
rotate();
cout << 270 << endl;
view();

}

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

int main(){
    int n;
    cin>>n;
    int a[110000][3];
    rep(i, n) cin>>a[i][0]>>a[i][1]>>a[i][2];
    ll dp[110000][3];
    rep(i, n){
        rep(j, 3){
            rep(k, 3){
                if(j==k) continue;
                dp[i+1][k]=max(dp[i+1][k], dp[i][j]+a[i][k]);
            }
        }
    }

    ll res = 0;
    rep(j, 3) res=max(res, dp[n][j]);
    cout<<res<<endl;
}

Measured memory_bytes: 7148
#include <cstdio>
#include <cstdlib>
using namespace std;

int main()
{
  int N, L;
  scanf("%d %d", &N, &L);
  int azi_sum = 0;
  int azi_min = L * 100;
  for (int i = 1; i <= N; i++)
  {
    int azi = L + i - 1;
    azi_sum += azi;
    if (abs(azi_min) > abs(azi))
    {
      azi_min = azi;
    }
  }
  printf("%d\n", azi_sum - azi_min);

  return 0;
}

Measured memory_bytes: 888
N, K, Q = map(int, input().split())
# print(N, K, Q)
# N人、Kポイント、Q問
A = []

for i in range(Q):
	a = int(input())
	A.append(a)
# print(A)

result = [K - Q] * N

for a in A:
	result[a-1] += 1

for r in result:
	if r > 0:
		print('Yes')
	else:
		print('No')


Measured memory_bytes: 10452
line = gets.split(' ').map(&:to_i)

a = line[0]
b = line[1]
result = -1

for i in 1..1300
  tax8 = i * 8 / 100
  tax10 = i * 10 / 100
  if tax8 == a and tax10 == b then
    result = i
    break
  end
end
  
print result

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

using namespace std;

using ll = long long;

const ll MOD = 998244353;

ll modpow(ll x, ll n, ll mod = MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

constexpr int MAXV = 1000000;

ll sum[MAXV + 1];
bool is_comp[MAXV + 1];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    int maxv = 0;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        maxv = max(maxv, a[i]);
        (sum[a[i]] += a[i]) %= MOD;
        (ans += MOD - a[i]) %= MOD;
    }

    for (int i = 2; i <= maxv; i++) {
        if (is_comp[i]) continue;
        for (int j = maxv / i; j >= 1; j--) {
            if (j > 1) is_comp[j * i] = true;
            (sum[j] += sum[j * i]) %= MOD;
        }
    }

    for (int i = 1; i <= maxv; i++) {
        (sum[i] *= sum[i]) %= MOD;
    }

    for (int i = 2; i <= maxv; i++) {
        if (is_comp[i]) continue;
        for (int j = 1; j * i <= maxv; j++) {
            (sum[j] += MOD - sum[j * i]) %= MOD;
        }        
    }

    for (int i = 1; i <= maxv; i++) {
        (ans += sum[i] * modpow(i, MOD - 2) % MOD) %= MOD;
    }
    (ans *= (MOD + 1) / 2) %= MOD;
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 9856
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace AtCoder
{
    static class Program
    {
        static void Main()
        {
            //ここから

            int N = IO.ReadLineToInt();
            var H = IO.ReadLineToIntList();

            int max = 0;

            var ans = "Yes";
            for(var i = 0; i < N ; i++)
            {
                if (max - H[i] > 0) { ans = "No";break; }
                max = Math.Max(H[i] - 1, max);
            }

            //ここまで
            Console.WriteLine(ans);
            Console.ReadKey();
        }
    }

    static class Func
    {
        static long mod = 1000000007;
        static public void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; }
        static public long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; }
        static public long LCM(long a, long b) { return (long)a * b / GCD(a, b); }
        static public int Factorial(int a) { return a == 1 ? a : a * Factorial(a - 1); }


        public static double ToAngle(this double radian)
        {
            return (double)(radian * 180 / Math.PI);
        }

        public static double ToRadian(this double angle)
        {
            return (double)(angle * Math.PI / 180);
        }

        static public long Conbination(int n,int m)
        {
            if (m == 0) return 1;
            if (n == 0) return 0;
            return n * Conbination(n - 1, m - 1) / m;
        }

        static public void Factoring(long num, ref long[] vs)
        {
            if (num == 1)
            {
                vs[1]++;
            }
            for (long i = 2; i < Math.Sqrt(num); i++)
            {
                if (num % i == 0)
                {
                    vs[i]++;
                    Factoring(num / i, ref vs);
                }
            }
            vs[1]++;
        }
    }

    static class IO
    {
        static public string ReadLineToString() { return Console.ReadLine(); }
        static public int ReadLineToInt() { return int.Parse(Console.ReadLine()); }
        static public long ReadLineToLong() { return long.Parse(Console.ReadLine()); }
        static public List<string> ReadLineToStringList() { return Console.ReadLine().Split(' ').ToList(); }
        static public List<int> ReadLineToIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); }
        static public List<long> ReadLineToLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); }

        static public List<double> ReadLineToDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }

        static public void WriteStrings(object[] strings) { foreach (var o in strings) { Console.Write(o + " "); } }
    }
}

Measured memory_bytes: 27740
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


using i64 = ::std::int_fast64_t;
using u64 = ::std::uint_fast64_t;
using i32 = ::std::int_fast32_t;
using u32 = ::std::uint_fast32_t;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  i64 a, b, c, d;
  std::cin >> a >> b >> c >> d;
  std::cout << std::max({a * c, a * d, b * c, b * d}) << '\n';
  return 0;
}

Measured memory_bytes: 3640
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let mut a = read_vec::<i64>();
    a.sort();
    let mut sum = vec![0; n];
    sum[0] = a[0];
    for i in 1..n {
        sum[i] = sum[i - 1] + a[i];
    }
    let mut start = 0;
    let mut current_size = a[0];
    for i in 1..n {
        if 2 * current_size >= a[i] {
            current_size += a[i];
        } else {
            start = i;
            current_size = sum[i];
        }
    }
    println!("{}", n - start);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 8444
from collections import Counter
n = int(input())
A = sorted(list(map(int, input().split())))
A_c = Counter(A)
A_max = A[-1]

dp = [True] * (A_max + 1)
counter = 0
for i in range(len(A) - 1):
    p = A[i]
    if dp[p] == False:
        continue
    else:
        for q in range(A_max // p + 1):
            dp[p * q] = False
        if p != A[i+1]:
            counter += 1
if dp[A_max] == True:
    counter += 1
print(counter)

Measured memory_bytes: 134968
fun main(args: Array<String>) {
    val s = readLine()!!
    //val (n,x) = readLine()!!.split(" ").map { s -> s.toInt() }
    //val L = readLine()!!.split(" ").map { s -> s.toInt() }
    val result = if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) "Bad" else "Good"
    println(result)
}

Measured memory_bytes: 31736
#include<stdio.h>

int main(){
	int b,r,g,c,s,t;
	int ans;
	while(1){
		ans=100;
		scanf("%d %d %d %d %d %d",&b,&r,&g,&c,&s,&t);
		if(t==0)return 0;
		t-=b*5+r*3+s;	
		ans-=t*3;
		ans+=(b*5+r*3)*13+g*7+c*2+b*15+r*15;
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 600
#include <stdio.h>

int main()
{
	long long h, w, t, temp[2], min;
	scanf("%lld %lld", &h, &w);

	if (h % 3 == 0 || w % 3 == 0) {
		printf("0");
	}
	else {
		for (int i = 0; i < 2; i++) {
			if (h % 3 == 1) {
				if (w % 2 == 0) {
					temp[i] = (h - (h / 3)) * (w / 2) - (h / 3) * w;
				}
				else {
					temp[i] = (h - (h / 3)) * ((w / 2) + 1) - (h / 3) * w;
				}
			}
			else {
				temp[i] = ((h / 3) + 1) * w - (h - ((h / 3) + 1)) * (w / 2);
			}

			t = h;
			h = w;
			w = t;
		}
		min = (temp[0] < temp[1]) ? temp[0] : temp[1];
		min = (min < h) ? min : h;
		min = (min < w) ? min : w;

		printf("%lld", min);
	}

	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
using namespace std;
const long long int INF = 1L<<60;

int main(){
    int H, W;
    cin >> H >> W;

    int N = H * W;

    vector<string> S(H);
    for (int i=0; i<H; i++){
        cin >> S[i];
    }

    long long int n;
    vector<vector<long long> > dp(N, vector<long long>(N, INF));
    for (int i=0; i<H; i++){
        for (int j=0; j<W; j++){
            n = W * i + j;
            dp[n][n] = INF;

            if (j < W-1 && S[i][j]=='.' && S[i][j+1]=='.'){
                dp[n][n+1] = dp[n+1][n] = 1;
            }
            if (i < H-1 && S[i][j]=='.' && S[i+1][j]=='.'){
                dp[n][n+W] = dp[n+W][n] = 1;
            }
        }
    }
    for (int i=0; i<N; i++){
        dp[i][i]=0;
    }

    for (int k=0; k<N; k++){
        for (int i=0; i<N; i++){
            for (int j=0; j<N; j++){
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
            }
        }
    }

    int answer = 0;
    for (int i=0; i<N; i++){
        for (int j=0; j<N; j++){
            if (answer < dp[i][j] && dp[i][j] != INF){
                answer = dp[i][j];
            }
        }
    }
    cout << answer << endl;

}

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

#define ll long long

using namespace std;

ll a[1000],b[1000],c[1000];
ll sumAB[1000000];
ll sumABC[3000001];
int main(){

 ll x,y,z,k;
 cin>>x>>y>>z>>k;
 for(int i=0;i<x;++i) cin>>a[i];
 
 int s=0;
 for(int i=0;i<y;++i) {
     cin>>b[i];
     for(int j=0;j<x;++j) sumAB[s++]=a[j]+b[i];
 }
 
 sort(sumAB,sumAB+x*y);
 
 
 for(int i=0;i<z;++i) cin>>c[i];

 sort(c,c+z);

int t=0;
for(int i=0;i<z;++i){
  for(int j=0;j<min((ll)3000,x*y);++j){
     sumABC[t++]=sumAB[x*y-1-j]+c[z-1-i];
  }
}
 
 sort(sumABC,sumABC+t);

 for(int i=0;i<k;++i){
     cout<<sumABC[t-1-i]<<endl;
 }

 return 0;
}


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

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  if( a * b * c == 5 * 7 * 5 ){
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
  return 0;
}


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

int main(){
  string sear;
  int rings,sum=0;
  cin >> sear >> rings;
  for(int i=0;i<rings;i++){
    string ring;
    cin >> ring;
    ring += ring;
    if(ring.find(sear)!=string::npos)
     sum++;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3140
let content = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', buf => {
  content += buf;
});

process.stdin.on('end', () => {
  let [, ...nums] = content
    .trim()
    .split('\n')
    .map(n => +n);
  shellSort(nums, nums.length);
});

const insertionSort = (A, n, g) => {
  for (let i = g; i < n; i++) {
    const v = A[i];
    let j = i - g;
    while (j >= 0 && A[j] > v) {
      A[j + g] = A[j];
      j = j - g;
      cnt++;
    }
    A[j + g] = v;
  }
};

let cnt = 0;
const shellSort = (A, n) => {
  const G = [];
  for (let i = 1; Math.pow(2, i) - 1 <= n; i++) {
    G.push(Math.pow(2, i) - 1);
  }
  G.reverse();

  for (let i = 0; i < G.length; i++) {
    insertionSort(A, n, G[i]);
  }

  console.log(G.length);
  console.log(G.join(' '));
  console.log(cnt);
  console.log(A.join('\n'));
};


Measured memory_bytes: 234804
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>

#include <inttypes.h>
using namespace std;

class Combination
{
private:
	int32_t N;
	vector<vector<int64_t>> comb;

public:
	void init(int32_t n)
	{
		N = n;
		comb.resize(N + 1);
		comb[0].resize(N + 1);
		comb[0][0] = 1;
		for (int i = 1; i <= N; i++) {
			comb[i].resize(N + 1);
			comb[i][0] = comb[i][i] = 1;
			for (int j = 1; j < i; j++)
				comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
		}
	}

	int64_t get(int32_t n, int32_t r)
	{
		if (n < 0 || r < 0 || n < r)
			return 0;

		return comb[n][r];
	}
};

int main()
{
	int32_t N, A, B;
	scanf("%d%d%d", &N, &A, &B);

	int64_t v[50];
	for (int32_t i = 0; i < N; i++)
		scanf("%" PRId64, &v[i]);
	sort(v, v + N, greater<int64_t>());

	int64_t sum = 0;
	double ave[50];
	memset(ave, 0, sizeof(ave));
	for (int32_t i = 0; i < N; i++) {
		sum += v[i];
		ave[i] = (double)sum / (i + 1);
	}
	printf("%.17f\n", ave[A - 1]);

	int64_t res;
	Combination c;
	if (v[0] == v[A - 1]) {
		int32_t n = 0;
		for (int32_t i = 0; i < N; i++)
			if (v[i] == v[0])
				n++;

		c.init(N);
		res = 0;
		for (int32_t r = A; r <= B; r++)
			res += c.get(n, r);
	} else {
		int32_t n = 0;
		for (int32_t i = 0; i < N; i++)
			if (v[i] == v[A - 1])
				n++;
		int32_t r = 0;
		for (int32_t i = 0; i < A; i++)
			if (v[i] == v[A - 1])
				r++;

		c.init(n);
		res = c.get(n, r);
	}
	printf("%" PRId64 "\n", res);

	return 0;
}

Measured memory_bytes: 256
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
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 long long INF=1LL << 60;
long long a,b;
long long dp[110][100100]={0};
long long w[110],v[110];



int main() {
   long long a;
   cin>>a;
   vector<long long> vec(a);
   rep(i,a){
       cin>>vec.at(i);
   }
   long long cou=0;
   int flag=0;
   for(long long i=1;i<a;i++){
       if(flag==0){
        if(vec.at(i-1)<vec.at(i)){
            flag=1;
        }
        if(vec.at(i-1)>vec.at(i)){
            flag=2;
        }
       }
       if(flag==1){
           if(vec.at(i-1)>vec.at(i)){
               flag=0;
               cou++;
           }
       }
       if(flag==2){
           if(vec.at(i-1)<vec.at(i)){
               flag=0;
               cou++;
           }
       }
   }

   cout<<cou+1<<endl;
}


Measured memory_bytes: 1024
/***************************************** 
****       Solution by SlavicG        ****
*****************************************/
 
#include<bits/stdc++.h>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm> 
#include <set>
#include <utility>
#include <queue>
#include <map>
#include <assert.h>
#include <stack>
using namespace std;
#define ll long long
#define forn(i,n) for(int i=0;i<n;++i)
#define MX 10000000001
#define pow2(a) ((a)*(a))
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define endl "\n"
#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 int longestIncreasingSubsequenceLenghtDP(int a[],int n){
    int dp[n],ans=0;
    for(int k = 0;k<n;k++){
        dp[k] = 1;
        for(int i = 0;i<k;i++){
            if(a[i] <= a[k]){
                dp[k] = max(dp[k],dp[i] + 1);
                ans = max(dp[k],ans);
            }
        }
    }
    return ans;
 }
int result[1000] = {0};
int factDP(int n) 
{
   if (n >= 0) {
      result[0] = 1;
      for (int i = 1; i <= n; ++i) {
         result[i] = i * result[i - 1];
      }
      return result[n];
   }
}
bool checkPrime(int n)
{
    if(n<2) return false;
    for(int x = 2;x*x <=n;x++)
    {
        if(n%x == 0)return false;
    }
    return true;
}
vector<int> primeFactors(int n){
    vector<int> f;
    for(int x = 2;x*x<=n;x++){
        while(n%x==0){
            f.push_back(x);
            n/=x;
        }
    }
    if(n>1)f.push_back(n);
    return f;
}
int binary_Search_Classic(int n, int arr[],int target){
	int l,r,mid;
	l=0;
	r=n-1;
	while(l<=r){
		mid= l+(r-l)/2;
		if(arr[mid] == target){
			return mid;
		}
		if(arr[mid] < target){
			l=mid+1;
		}else{
			r=mid-1;
		}
	}
	return -1;
	
}
int binary_Search_First_Greater(int n, int arr[],int target){
	int l,r,ans,mid;
	l = 0;
	r = n-1;
	ans=-1;
	while(l<=r){
		mid = l + (r-l)/2;
		if(arr[mid] > target){
			ans=mid;
			r=mid-1;
		}else{
			l = mid+1;
		}
	}
	return ans;
}
int countDistinctCharsString(string s) {
    unordered_map<char, int> m; 
    for (int i = 0; i < s.length(); i++) { 
        m[s[i]]++; 
    }
    return m.size(); 
} 
int main()
{
	ll x;
	cin >> x;
	int ans;
	for(int i = x;i<=1000000;i++)
	{
		if(checkPrime(i))
		{
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3580
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - Two Rectangles
            var line = ReadLine();
            int a = line[0];
            int b = line[1];
            int c = line[2];
            int d = line[3];

            if (a * b > c * d)
            {
                Console.WriteLine(a * b);
            }
            else
            {
                Console.WriteLine(c * d);
            }
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 13268
n = gets.to_i
numbers = []
n.times do |num|
  numbers << [gets.to_i, num]
end

numbers.sort!.reverse!

biggest_1 = numbers[0]
biggest_2 = numbers[1]

n.times do |num|
  if num == biggest_1[1]
    puts biggest_2[0]
  else
    puts biggest_1[0]
  end
end

Measured memory_bytes: 19816
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    ll n;cin>>n;

    ll ans=0;
    n--;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            ll x=i,y=n/i;
            ans+=2;
            if(x==y)ans--;
        }
    }

    n++;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0){
            ll num=n;
            while(num%i==0){
                num/=i;
            }
            if(num%i==1) ans++;
        }
    }

    cout<<ans<<endl;

    // ll ans=0;
    // for(ll i=2;i<=n;i++){
    //     ll num=n;
    //     while(num%i==0) num/=i;
    //     num%=i;
    //     if(num==1){
    //         cout<<i<<endl;
    //         ans++;
    //     }
    // }
    // cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    int count=1;
    for(int i=0;i<N-1; i++){
        if(S[i]!=S[i+1]) count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 512
//In the name of GOD
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const ll maxn = 2e5 + 100;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt" , "r+" , stdin) ; freopen("output.txt" , "w+" , stdout);
#define pb push_back
#define Mp make_pair
#define pll pair<ll, ll>
#define F first
#define S second

ll h, w, n, c[20];
map<pll, ll> a;

int main(){
	fast_io;
	ll x, y;
	cin >> h >> w >> n;
	c[0] = (h - 2) * (w - 2);
	for(ll i = 0; i < n; i++){
		cin >> x >> y;
		for(ll j = 0; j < 3; j++){
			for(ll k = 0; k < 3; k++){
				if(x - j < 1 || y - k < 1 || x - j + 2 > h || y - k + 2 > w) continue;
				c[a[Mp(x - j, y - k)]++]--;
				c[a[Mp(x - j, y - k)]]++;
			}
		}
	}
	for(ll i = 0; i < 10; i++){
		cout << c[i] << '\n';
	}
	
	
	return 0;
}

Measured memory_bytes: 56576
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
#include <stack>
#include <functional>
using ll = long long;
using namespace std;
int main() {
	ll n, m, ans = 0, A[10101];
	cin >> n;
	for (int i = 1; i < 10000; i++)
		if (i*i <= n)
			m = i * i;
		else
			break;

	for (int i = 1; i < 10000; i++)
		if (i*i*i <= n && m < i*i*i)
			m = i * i*i;
		else if (i*i*i >= n)
			break;

	for (int i = 1; i < 10000; i++)
		if (i*i*i*i <= n && m < i*i*i*i)
			m = i * i*i*i;
		else if (i*i*i*i >= n)
			break;
	for (int i = 1; i < 10000; i++)
		if (i*i*i*i*i <= n && m < i*i*i*i*i)
			m = i * i * i*i*i;
		else if (i*i*i*i*i >= n)
			break;
	for (int i = 1; i < 10000; i++)
		if (i*i*i*i*i*i <= n && m < i*i*i*i*i*i)
			m = i*i*i*i*i*i;
		else if (i*i*i*i*i*i >= n)
			break;
	cout << m << endl;
	return 0;
}

Measured memory_bytes: 256