akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;

int main() {
    int n,q,t;
    string name;
    queue<pair<string,int>> Q;
    cin>>n>>q;
    for(int i=0;i<n;i++){
        cin>>name>>t;
        Q.push(make_pair(name,t));
    }
    pair<string,int> u;
    int elaps=0,a;
    while(!Q.empty()){
        u=Q.front();Q.pop();
        a=min(u.second,q);
        u.second-=a;
        elaps+=a;
        if(u.second>0){
            Q.push(u);
        }else{
            cout<<u.first<<" "<<elaps<<endl;
        }
    }
}


Measured memory_bytes: 6328
#include<iostream>
#include<queue>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define INF (1<<29)
using namespace std;

struct Node{
	int y,x,foot,cost;
	Node(){}
	Node(int a,int b,int c,int d):y(a),x(b),foot(c),cost(d){}
	bool operator <(const Node &a)const{return cost>a.cost;}
};

int main(){
	int w,h;
	char map[60][30];
	int dp[60][30][2];
	priority_queue<Node> pq;
	Node a,b;
	while(cin>>w>>h&&(w||h)){
		int ans = -1;
		while(!pq.empty())pq.pop();
		fill_n((int*)dp,sizeof(dp)/sizeof(int),INF);
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				cin>>map[i][j];
				if(map[i][j]=='S'){
					pq.push(Node(i,j,0,0));
					pq.push(Node(i,j,1,0));
					dp[i][j][0]=dp[i][j][1]=0;
				}
			}
		}
		while(!pq.empty()){
			int sx,ddx;
			a=pq.top();
			pq.pop();
			if(dp[a.y][a.x][a.foot] < a.cost)continue;
			if(map[a.y][a.x]=='T'){
				ans = a.cost;
				break;
			}
			if(a.foot==0){
				sx=ddx=1;
			}
			else{
				sx=ddx=-1;
			}
			for(int dx=sx;abs(dx)<=3;dx+=ddx){
				for(int dy=-2;dy<=2;dy++){
					if(3<abs(dy)+abs(dx))continue;
					int cost;
					b = Node(a.y+dy,a.x+dx,a.foot^1,a.cost);
					if(b.y<0||h<=b.y||b.x<0||w<=b.x||map[b.y][b.x]=='X')continue;
					if(map[b.y][b.x]=='S'||map[b.y][b.x]=='T')cost = 0;
					else cost = map[b.y][b.x]-'0';
					b.cost += cost;
					if(b.cost < dp[b.y][b.x][b.foot]){
						dp[b.y][b.x][b.foot] = b.cost;
						pq.push(b);
					}
				}
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 944
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ldb long double
#define ull unsigned long long

map<ull,int> mp,cnt,bo;

ull bin[10000010],hs[100010];
ll a[100010][60],num[100010],ans[233];
int n,tt,tot;

inline ll rd()
{
	ll x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

inline ll gcd(ll x,ll y) { return (!y)?x:gcd(y,x%y); }
 
inline ll tms(ll x,ll y,ll p)
{
	ll hh=(ldb)x/p*y+1e-3;
	return ((x*y-hh*p)%p+p)%p;
}

inline ll ksm(ll x,ll y,ll p)
{
	ll res=1;
	for (;y;y>>=1,x=tms(x,x,p)) if (y&1) res=tms(res,x,p);
	return res;
}

inline bool check(ll x,ll y,ll z,ll n)
{
	ll hh=ksm(x,y,n),now=hh;
	for (ll i=1;i<=z;i++)
	{
		hh=tms(hh,hh,n);
		if (hh==1&&now!=1&&now!=n-1) return true;
		now=hh;
	}
	if (hh!=1) return true;
	return false;
}

inline bool miller_rabin(ll n)
{
	if (n==4759123141LL) return false;
	if (n==2) return true;
	if (n==7) return true;
	if (n==61) return true;
	if (n%2==0) return false;
	ll hh=n-1,hhh=0;
	while (hh%2==0) hh>>=1,hhh++;
	if (check(7,hh,hhh,n)) return false;
	if (check(61,hh,hhh,n)) return false;
	return true;
}

inline ll pollard_rho(ll a,ll n)
{
	ll k=2,x=(ll)rand()*rand()%n,y=x,p=1;
	for (ll i=1;p==1;i++)
	{
		x=(tms(x,x,n)+a)%n;
		p=gcd(n,abs(x-y));
		if (i==k) y=x,k<<=1;
	}
	return p;
}
 
inline void find_fac(ll n)
{
	if (n==1) return;
	if (miller_rabin(n)) { ans[++tot]=n;return; }
	ll hh=n;
	while (hh==n) hh=pollard_rho((ll)rand()*rand()%(n-1)+1,n);
	find_fac(hh);find_fac(n/hh);
}

int main()
{
	srand(19260817);
	n=rd();tt=0;
	for (int i=1;i<=n;i++) num[i]=rd();
	bin[1]=1;
	for (int i=2;i<=10000000;i++) bin[i]=bin[i-1]*233ull;
	for (int i=1;i<=n;i++)
	{
		if (num[i]==1) { a[i][0]=0;continue; }
		tot=0;find_fac(num[i]);
		sort(ans+1,ans+tot+1);ans[tot+1]=-1;
		ull now=0;
		for (int j=1;j<=tot;)
		{
			int k=j;
			for (;ans[k]==ans[j];k++);k--;
			int hh=(k-j+1)%3;
			if (!mp[ans[j]]) mp[ans[j]]=++tt;
			now+=(ull)bin[mp[ans[j]]]*(ull)hh;
			j=k+1;
		}
		cnt[now]++;hs[i]=now;
		a[i][0]=tot;
		for (int j=1;j<=tot;j++) a[i][j]=ans[j];
	}
	int res=0;
	bool flag=false;
	for (int i=1;i<=n;i++)
	{
		if (bo[hs[i]]) continue;
		bo[hs[i]]=true;
		if (!hs[i]) { flag=true;continue; }
		tot=a[i][0];
		for (int j=1;j<=tot;j++) ans[j]=a[i][j];ans[tot+1]=-1;
		ull now=0;
		for (int j=1;j<=tot;)
		{
			int k=j;
			for (;ans[k]==ans[j];k++);k--;
			int hh=(k-j+1)%3;
			if (hh==0) hh=0;
			else if (hh==1) hh=2;
			else hh=1;
			now+=(ull)bin[mp[ans[j]]]*(ull)hh;
			j=k+1;
		}
		bo[now]=true;
		if (cnt[hs[i]]>cnt[now]) res+=cnt[hs[i]];
		else if (cnt[hs[i]]==cnt[now]) res+=cnt[hs[i]];
		else res+=cnt[now];
	}
	printf("%d\n",res+flag);
	return 0;
}

Measured memory_bytes: 156288
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); ++i)
#define outl(x) cout<< (x) << '\n'
using pii = pair<int,int>;
using ll = long long;

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

    int a, b;
    cin >> a >> b;
    outl(a*b - (a + b - 1));

    return 0;
}



Measured memory_bytes: 256
//
// Created by Myabu on 2020/01/20.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <numeric>
#include <iomanip>

using namespace std;


int main(void){
    string S;
    cin>>S;

    if((S[0]==S[1] && S[1] == S[2] ) || (S[1] == S[2] && S[2] ==S[3])){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(int x, int y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(int x, int y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
pair<string, int>A[101];
signed main() {
  int N; cin>>N;
  vector<int>H(N);
  rep(i,N)cin>>H[i];
  int count=H[0];
  int ans=1;
  REP(i,N){
    if(H[i]>=count){
      count=H[i];
      ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3632
#python3.4
def inpul(): return list(map(int, input().split()))

N, M = inpul()
X = inpul()

if(N >= M):
    print(0)
else:
  new_list = sorted(X)
  diff_list = [new_list[i+1] - new_list[i] for i in range(M-1)]
  new_dif_list = sorted(diff_list, reverse = True)

  if(N  >= 2):
    for i in range(N-1):
        new_dif_list.pop(0)

  print(sum(new_dif_list))


Measured memory_bytes: 13968
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
typedef pair<int, int> p;
#define modulo 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9

bool graph[9][9];
int N, M;

void input() {
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		int v1, v2;
		cin >> v1 >> v2;
		graph[v1][v2] = true;
		graph[v2][v1] = true;
	}
}

bool check_pass(vector<int> v) {
	bool flag = true;
	for (int i = 0; i < v.size() - 1 && flag == true; i++) flag = graph[v[i]][v[i + 1]];
	return flag;
}

void solve() {
	int ans = 0;
	vector<int> v;
	for (int i = 1; i <= N; i++) v.push_back(i);
	do {
		ans += check_pass(v);
	} while (next_permutation(v.begin() + 1, v.end()));
	cout << ans << endl;
}


int main() {
	input();
	solve();

	return 0;
}

Measured memory_bytes: 256
s = list(input())
l = ['K','I','H','B','R',-1]
j = 0

for i in range(len(s)):
    if s[i] == 'A':
        if i == 0:
            pass
        elif s[i-1] == 'A':
            print('NO')
            exit(0)
        elif j == 1 or j == 2:
            print('NO')
            exit(0)
        else:
            pass
    elif s[i] != l[j]:
        print('NO')
        exit(0)
    elif j > 4 and s[i] != 'A':
        print('NO')
        exit(0)
    else:
        j += 1

if j == 5:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3064
import math


def solve(e):
    k = 2 ** 32
    for z in range(100, -1, -1):
        z3 = z * z * z
        if z3 > e:
            continue
        e2 = e - z3

        ylm = int(math.sqrt(e2))

        for y in range(ylm, -1, -1):
            y2 = y * y
            if e2 > (y + 1) * (y + 1):
                break
            e3 = e2 - y2

            x = e3
            k = min(k, x + y + z)
    return k


def main():
    while True:
        a = int(input())

        if a == 0:
            break

        print(solve(a))


if __name__ == '__main__':
    main()



Measured memory_bytes: 5676
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define ull unsigned long long
#define M 1000000007

using namespace std;
int main(){
    //int t;cin>>t;
    //while(t--){
    int x;cin>>x;
    int t=x;
    for(int i=1;i<=190;i++){
        if((360*i)%t==0) {cout<<(360*i)/t;break;}
        else continue;
    }
    cout<<endl;
    //}
    
    
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
ll factorial(int i) {       //階乗
    if (i == 0) return 1;
    return (factorial(i - 1)) * i;
}

int main() {
    ll mod = 1000000007;
    int n, m;
    cin >> n >> m;
    vector<bool> bre(n, false);
    rep(i, m) {
        int a;
        cin >> a;
        a--;
        bre[a] = true;
        if(i > 0) {
            if(bre[a - 1] == true) {
                cout << 0 << endl;
                return 0;
            }
        }
    }
    vector<ll> fib(n);
    rep(i, n) {
        if(bre[i]) {
            fib[i] = 0;
            continue;
        }
        if(i == 0) {
            fib[i] = 1;
            continue;
        }
        if(i == 1) {
            fib[i] = fib[i - 1] + 1;
            continue;
        }
        fib[i] = fib[i - 1] + fib[i - 2];
        if(fib[i - 2] > mod) {
            fib[i] %= mod;
            fib[i - 1] %= mod;
            fib[i - 2] %= mod;
        }
    }
    cout << fib[n - 1] % mod << endl;
}

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

#define mp make_pair
#define sz(x) (int)((x).size())
#define all(x) (x).begin(),(x).end()
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define eb emplace_back

typedef pair< int, int > pii;
typedef pair< long long, long long > pll;
typedef long long ll;
typedef unsigned long long ull;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vll;
typedef vector< vll > vvll;
typedef vector< pii > vpii;
typedef vector< vpii > vvpii;
typedef vector< pll > vpll;
typedef long double ld;
typedef vector< ld > vld;
typedef unsigned int uint;
 
template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    const bool operator<(const M& o) const {return v < o.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
 
using Mint = ModInt<(int)998244353>;
 
int main() { 
    #ifdef BLAT
        freopen("stdin", "r", stdin);
        freopen("stderr", "w", stderr);
    #endif
 
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(12);
    srand(time(NULL));

    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;

    cout << (h2-h1)*60-m1+m2-k;
    return 0;
}

Measured memory_bytes: 3644
n = int(input())
word_list = [input() for _ in range(n)]
flag_count = 0
for word in word_list:
    count = 0
    count = word_list.count(word)
    if count == 1:
        if word_list.index(word) != 0:
            if word[0] == last_string:
                flag_count += 1
    last_string = word[-1]
if flag_count == n-1:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using std::cerr;using std::cin;using std::cout;using std::abs;using std::min;using std::max;using std::swap;using std::map;using std::unordered_map;using std::unordered_set;using std::bitset;using std::pair;using std::set;using std::string;using std::vector;using std::sort;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);std::iostream::sync_with_stdio(0);cout<<std::fixed<<std::setprecision(10);cerr<<std::fixed<<std::setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}
const int N=2e5+5,A=26;
int go[N][A];

int32_t main(){

    string s,t;
    cin>>s>>t;
    int n=s.size();
    s="#"+s+s;
    forn(j,A)go[n+n+1][j]=-1;
    for(int i=n+n+1;i>0;--i){
        forn(j,A)go[i-1][j]=go[i][j];
        go[i-1][s[i]-'a']=i;
    }
    int pos=0,loop=0;
    for(char c:t){
        int to=go[pos][c-'a'];
        if(to==-1){
            cout<<"-1\n";
            return 0;
        }
        if(to>n){
            loop++;
            to-=n;
        }
        pos=to;
    }
    cout<<loop*n+pos<<'\n';

    return 0;
}


Measured memory_bytes: 41324
#include <iostream>
#define N 15
using namespace std;
void func(int,int);
int jump(int,int);
int X,Y,data[N][N],memo[N][N];
int main(){
  while(1){
    cin >> X >> Y;
    if(X==0&&Y==0) break;
    for(int i=0;i<Y;i++)
      for(int j=0;j<X;j++) cin >> data[i][j],memo[i][j]=0;
    for(int i=0;i<X;i++)
      if(data[0][i]==0) func(0,i);
    int cnt=0;
    for(int i=0;i<X;i++) cnt+=memo[0][i];
    cout << cnt << endl;
  }
  return 0;
}
void func(int y,int x){
  if(y==Y-1){
    memo[Y-1][x]=1;
    return ;
  }
  if(0<=x-1&&data[y+1][x-1]==0){
    if(memo[y+1][x-1]==0) func(y+1,x-1);
    memo[y][x]+=memo[y+1][x-1];
  }
  if(x+1<X&&data[y+1][x+1]==0){
    if(memo[y+1][x+1]==0) func(y+1,x+1);
    memo[y][x]+=memo[y+1][x+1];
  }
  if(data[y+1][x]==0){
    if(memo[y+1][x]==0) func(y+1,x);
    memo[y][x]+=memo[y+1][x];
  }
  if(data[y+1][x]==2){
    int r=jump(y+1,x);
    if(r==-2) memo[y][x]+=1;
    else if(r!=-1){
      if(memo[r][x]==0) func(r,x);
      memo[y][x]+=memo[r][x];
    }
  }
  if(memo[y][x]==0) data[y][x]=1;
}
int jump(int y,int x){
  while(1){
    y+=2;
    if(y<=Y-1&&data[y][x]==1) break;
    if(y>=Y-1) return -2;
    if(data[y][x]==0) return y;
  }
  return -1;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  string s;
  cin >> s;
  int n = s.size();
  reverse(all(s));
  vector<vi> dp(n + 1, vi(2, 1e8));
  dp[0][0] = 0;
  rep(i, n) {
    int d = s[i] - '0';
    int ni = i + 1;
    dp[ni][0] = min(dp[ni][0], dp[i][0] + d);
    dp[ni][1] = min(dp[ni][1], dp[i][0] + 10 - d);
    dp[ni][0] = min(dp[ni][0], dp[i][1] + d + 1);
    dp[ni][1] = min(dp[ni][1], dp[i][1] + 9 - d);
  }
  cout << min(dp[n][0], dp[n][1] + 1) << endl;
}

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

using namespace std;
 
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
 
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<bool> VB;

int main() {
    int a,b;
    cin >> a;
    cin >> b;
    if(a<10 && b<10) {
        cout << a*b;
    } else {
        cout << -1;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

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


class QuickFind{

private:
    vector<int> i2g;          // i2g[i] := アイテム i の所属するグループの番号
    vector<vector<int> > g2i;  // g2i[g] := グループ g に所属するアイテムたち

public:
    QuickFind(){};
    QuickFind(int size){
        i2g.resize(size);
        g2i.resize(size);
        for (int i = 0; i < size; i++) {
        // 最初はアイテム i はグループ i に所属
            i2g[i] = i;
            g2i[i].assign(1, i);
        }
    }

    // アイテム ia の所属するグループとアイテム ib の所属するグループを 1 つにする
    void merge(int ia, int ib) {
        if(same(ia,ib))return;
        // ia の所属するグループが ib の所属するグループより小さくならないようにする
        if (g2i[i2g[ia]].size() < g2i[i2g[ib]].size()) {
            swap(ia, ib);
        }
        int ga = i2g[ia], gb = i2g[ib];
        // グループ gb に所属する全てのアイテムをグループ ga に移す
        for (int i = 0; i < g2i[gb].size(); i++) i2g[g2i[gb][i]] = ga;
        g2i[ga].insert(g2i[ga].end(), g2i[gb].begin(), g2i[gb].end());
        g2i[gb].clear();
    }

    // アイテム id と同じグループに所属しているアイテムを取得
    vector<int> get_group(int id){
        vector<int> ret;
        id = i2g[id];
        for(int i = 0; i < g2i[id].size(); i++)ret.push_back(g2i[id][i]);
        return ret;
    }

    // アイテム ia とアイテム ib は同じグループに所属しているか？
    bool same(int ia, int ib) {
        return i2g[ia] == i2g[ib];
    }
};

signed main(void) {
    int n;
    cin >> n;
    int ma = 100005;
    QuickFind qf(ma*2);
    rep(i,n){
        int a,b;
        cin >> a >> b;
        a--,b--;
        qf.merge(a,ma+b);
    }
    int ans = 0;
    vi used(2*ma,0);
    rep(i,2*ma)if(used[i] == 0){
        int x = 0, y = 0;
        vi t = qf.get_group(i);
        rep(i,t.size()){
            used[t[i]]++;
            if(t[i] < ma)x++;
            else y++;
        }
        ans += x*y;
    }
    cout << ans - n << endl;
}


Measured memory_bytes: 22696
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <complex>
#include <numeric>
#include <string.h>
#include <random>
#include <cmath>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.141592653589793238462643383279;
const double EPS = 1e-9;
const ll MOD = 1000000007;
//const ll MOD = 998244353
const int inf = 1 << 30;
const ll linf = 1LL << 60;

int N;
char ans[300];
char ho, ge;
int er = -1;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    char now;
    int stage = 0, target = 0;
    int cnt = 0;
    cout << "?";
    rep(j,N) {
        cout << " " << j%(2*N)+1;
    }
    cout << endl;
    string tmp; cin >> tmp;
    now = tmp[0];
    ho = now;
    ge = ho=='R'?'B':'R';
    int st = N-1, en = 2*N-1;
    for (int i = 0; ; i++) {
        if (stage == 0) {
            int mid = (st+en)/2;
            cout << "?";
            rep(j,N) {
                cout << " " << (mid-j)%(2*N)+1;
            }
            cout << endl;
            string s; cin >> s;
            if (s[0] != now) {
                en = mid;
            } else {
                st = mid;
            }
            if (en-st <= 1) {
                stage++;
                target = en;
            }
        } else if (stage == 1) {
            if (cnt < N) {
                cout << "?";
                for (int j = target-N+1; j < target; j++) {
                    cout << " " << j+1;
                }
                cnt++;
                cout << " " << (target+cnt)%(2*N)+1 << endl;
                string s; cin >> s;
                if (s[0] == ho) { ans[(target+cnt)%(2*N)] = ho; er = (target+cnt)%(2*N); }
                else ans[(target+cnt)%(2*N)] = ge;
            } else {
                cout << "?";
                rep(j,N) {
                    if ((target+1+j)%(2*N) == er) continue;
                    cout << " " << (target+1+j)%(2*N)+1;
                }
                cnt++;
                cout << " " << (target+cnt)%(2*N)+1 << endl;
                string s; cin >> s;
                if (s[0] == ho) ans[(target+cnt)%(2*N)] = ho;
                else ans[(target+cnt)%(2*N)] = ge;
            }
            if (cnt == 2*N) break;
        }
    }
    cout << "! ";
    rep(i,2*N) cout << ans[i]; 
    cout << endl;
}

Measured memory_bytes: 724
#include <bits/stdc++.h>
#define int int64_t
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define REPR(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i=(m)-1; i>=(n); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<int>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define pa cout << ans << endl
#define p(x) cout << x << endl
#define pall(x) for(auto iter : x) p(iter)
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define yn(x) cout << (x ? "Yes" : "No") << endl
using namespace std;
using Graph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
typedef long double LD;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const int INF = 2000000000;
const long double PI = acosl(-1);
const int MOD = 1000000007;
void print() {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> &vec) {for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " ";} cout << endl;}
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec);}}


signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int ans = 0;
    
    string N;
    cin >> N;

    if (N[0] == '7' || N[1] == '7' || N[2] == '7') yes;
    else no;
    
    
    
    return 0;
}

/*
cd ~/Desktop/Programming/AtCoder/contest/abc162/abc162_a && sh shellscripts/test_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc162/abc162_a && sh shellscripts/etest_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc162/abc162_a && sh shellscripts/submit_cpp.sh
*/


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define TRACE
#ifndef TRACE
#define tcout 0 && cout
#else
#define tcout cout << "Debug: "
#endif
#define in inline
#define reg register
#define int long long
#define MAX 20030813
using namespace std;
namespace qwq{
	in int read()
	{
		int o=0;
		int w=1;
		char c=getchar();
		while(c<'0'||c>'9')
		{
			if(c=='-')w=-1;
			c=getchar();
		}
		while(c>='0'&&c<='9')
		{
			o=(o<<3)+(o<<1)+(c^48);
			c=getchar();
		}
		return o*w;
	}
	in void write(int x)
	{
    	if(x>9)write(x/10);
    	putchar(x%10+48);
	}
	in int max(int x,int y)
	{
		return x>y?x:y;
	}
	in int min(int x,int y)
	{
		return x<y?x:y;
	}
}
using namespace qwq;
int n,p;
signed main()
{
	n=read(),p=read();
	printf("%lld",(n*3+p)/2);
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


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

    int ans = 0;
    vvint c(10, vint(10, 0));
    rep2(i, n) {
        int a = i%10;
        int b; 
        int tmp = i;
        while(tmp!=0) {
            if (tmp < 10) {
                b = tmp;
                break;
            }
            tmp /= 10;
        }

        if (a == 0 || b == 0) continue;

        if (c[b][a] != 0) ans += c[b][a];
        else {
            if (a == b && a <= n) c[b][a]++;

            rep(i, 5) {
                int num = a;
                int mul = pow(10, i);
                rep(j, mul) {
                    int tmp = (num*mul*10 + j*10) + b;
                    if (tmp <= n) c[b][a]++;
                }
            }

            ans += c[b][a];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Diagnostics;

namespace Multiple
{
    class Program
    {
        static void Main(string[] args)
        {
            long N;

            string inD0 = Console.ReadLine();


            long Res = 0;

            long CharLeng = inD0.Length;
            string GetChar;

            for (int i = 0;i < CharLeng; i++)
            {

            GetChar = inD0.Substring(i, 1);

             N = long.Parse(GetChar);
                Res += N;
            }

             if(Res % 9 == 0) Console.WriteLine("Yes");
            else Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 32772
#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 n;cin >> n;
  vl v(n);rep(i,n)cin >> v[i];
  mint ans=1;
  ll cnt=0;
  ll last=n;
  rep(i,n){
    cnt++;
    if((v[i]+1)/2<cnt){
      ans*=cnt;
      last--;
      cnt--;
    }
  }
  rep(i,last)ans*=i+1;
  cout << ans <<endl;
}

Measured memory_bytes: 35204
#include <atcoder/dsu>
#include <iostream>
int main(){
  using namespace std;
  using namespace atcoder;

  int n,m;
  cin >> n >> m;
  dsu d(n);
  for (int i=0; i<m; i++) {
    int a,b;
	cin >> a >> b;
    d.merge(a-1, b-1);
  }
  size_t ans = d.groups().size() - 1;
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 8832
/*
 * Author:  heyuhhh
 * Created Time:  2020/5/6 8:30:43
 */
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <assert.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << std::endl; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
  template <template<typename...> class T, typename t, typename... A> 
  void err(const T <t> &arg, const A&... args) {
  for (auto &v : arg) std::cout << v << ' '; err(args...); }
#else
  #define dbg(...)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 1e5 + 5;

void run() {
    ll a, b, n; cin >> a >> b >> n;
    ll x = min(b - 1, n);
    ll ans = a * x / b - a * (x / b);
    cout << ans << '\n';
}

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

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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
const int N=1e5 + 5;

string s;

string substr(int i, int j)
{
	string str ="";
	int k;
	for(k=i;k<=j;k++)
	{
		str += s[k];
	}
	return str;
}

bool ok(string x){
    map<char,int> cnt;
    for(ll i : x)
        cnt[i - 'a']++;
    for(ll i : x){
        if(cnt[i - 'a'] > (ll)x.size() / 2)
            return 1;
    }
    return 0;
}
 

int32_t main()
{
	IOS;
	cin >> s;
	int n=s.size();
	int cur=2;
	int i=0;
	int j=0;
	int k=0;
	for(cur=2;cur<=min(n,5ll);cur++)
	{
		for(j=cur-1;j<n;j++)
		{
			string str= substr(j-cur+1,j);
			if(ok(str)==1)
			{
				cout << j-cur+2 << " " << j+1 << endl;
				return 0;	
			}	
		}	
	}
	cout << "-1 -1 " << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()); //sort
// char '' str ""
int main(void)
{
    int N,M;cin>>N>>M;
    int a,b;
    int c[52];
    for(int j=1; j<=N;j++) c[j]=0;

    for(int i=0; i<M;i++){
      cin>>a>>b;
      for(int j=1; j<=N;j++){
        if(a==j){
          c[j]++;
        }else if(b==j){
          c[j]++;
        }
      }
    }

    for(int j=1; j<=N;j++){
      cout<<c[j]<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int num(int p,int q){
	double n=p/q;
	if(abs((double)p/(double)q-p/q)>0.5)return p/q+1;
	else return p/q;
}

int main(){
	int n,sum=0,x;
	cin>>n;
	int a[n];
	rep(i,n){
		cin>>a[i];
		sum+=a[i];
	}
	x=num(sum,n);
	int cost=0;
	rep(i,n)cost+=(a[i]-x)*(a[i]-x);
	cout<<cost<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	if(b==100) b+=1;
	if(a==0) printf("%d\n",b);
	if(a==1) printf("%d\n",b*100);
	if(a==2) printf("%d\n",b*100*100);
	return 0;
}


Measured memory_bytes: 1692
#include <stdio.h>
 
int main(){
    int countTable[256] = {0};
    char ch;
 
    while((ch = getchar()) != EOF){
                countTable[ch]++;
    }
    for(int i = 97; i <=122;i++)printf("%c : %d\n",i,countTable[i]+countTable[i-32]);
}


Measured memory_bytes: 2588
c=0
d=0
h,w=gets.split.map &:to_i
a=[]
f=0
h.times do
  a<< g=gets.chomp.split("")
  f+=g.count(?#)
end
j=true
loop do
  f-=1
  if c==h-1 && d==w-1
    break
  elsif c!=h-1 && a[c+1][d]==?#
    if d!=w-1 && a[c][d+1]==?#
      j=false
      break
    end
    c+=1
  elsif d!=w-1 && a[c][d+1]==?#
    d+=1
  else
    j=false
    break
  end
end
puts j&&f==0 ? :Possible : :Impossible

Measured memory_bytes: 1788
#include<iostream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
using namespace std;
#define mp(a,b) make_pair(a,b)
#define pb push_back

int main(){
    long long n;
    cin>>n;
    char ans[1000];
    int cnt = 0;
    long long prell = 0;
    while (n > 0){
        long long ll = n%26;
        n/=26;
        if (ll == 0){
            n--;
        }
        cnt++;
        if (ll == 0){
            ans[cnt] = 'z';
        }else{
            ans[cnt] = char('a' + ll -1);
        }
    }
    for (int i=cnt;i>=1;i--){
        cout<<ans[i];
    }


    //system("pause");
}


Measured memory_bytes: 3608
#include <stdio.h>

int main(void)
{
    int n, m;

    while (scanf("%d", &n) * n){
        int map[32][32] = {0};
        int m;
        int x, y;
        int i;

        for (i = 0; i < n; i++){
            int xi, yi;
            scanf("%d %d", &xi, &yi);
            map[yi][xi] = 1;
        }

        scanf("%d", &m);
        x = y = 10;
        n -= map[y][x];
        map[y][x] = 0;
        while (m-- > 0){
            char d;
            int l;

            scanf(" %c %d", &d, &l);
            while (l--){
                switch (d){
                    case 'N': y++; break;
                    case 'S': y--; break;
                    case 'E': x++; break;
                    case 'W': x--; break;
                }
                n -= map[y][x];
                map[y][x] = 0;
            }
        }

        puts(n ? "No" : "Yes");
    }

    return 0;
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  
  string s;
  cin >> s;
  int n = 3, ans;

  if (s == "RRR") {
    ans = 3;
  } else if (s == "RRS" || s == "SRR") {
    ans = 2;
  } else if (s == "SSS") {
    ans = 0;
  } else {
    ans = 1;
  }

  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int LLI;
int main()
{
	int n;
	cin >> n;
	int arr[n], sum = 0, count = 0;
	for(int i = 0; i < n; i++)
    {
    	cin >> arr[i];
    	if( arr[i] % 10 == 0)
    		count++;
    	sum += arr[i];
    }
    if( count == n )
    	cout << 0;
	else if( sum % 10 == 0 )
    {
    	sort(arr,arr+n);
    	for(int i = 0; i < n; i++)
        	if( arr[i] % 10 != 0 )
            {
            	cout << sum - arr[i];
            	break;
            }
    }else
    	cout << sum;
  	
	return 0;
}

Measured memory_bytes: 3572
import sys

input = sys.stdin.readline


def main():
    s = input().strip()
    k = int(input())
    l = []
    text = s[0]
    for c in s[1:]:
        if text[-1] == c:
            text += c
        else:
            l.append(text)
            text = c
    l.append(text)
    cnt = 0
    if len(l) == 1:
        cnt = len(l[0]) * k // 2
    elif l[0][0] == l[-1][0]:
        cnt += len(l[0]) // 2 + len(l[-1]) // 2
        l[-1] += l[0]
        cnt += sum([len(t) // 2 for t in l[1:-1]]) * k
        cnt += len(l[-1]) // 2 * (k - 1)
    else:
        cnt = sum([len(t) // 2 for t in l]) * k
    print(cnt)
    # len(t) if i else i for i, j in enumerate(l)])


if __name__ == "__main__":
    main()


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

func = [0]*n

for x in range(1,100):
    for y in range(x, 100):
        for z in range(y,100):
            temp = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if temp <= n:
                if x == y and y == z :
                    func[temp-1] += 1
                elif x == y or y == z:
                    func[temp-1] += 3
                else:
                    func[temp-1] += 6

for i in range(n):
    print(func[i])

Measured memory_bytes: 9140
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    long long int k;
    long long int sum=100;
    long long int count=1;
    cin >> k;
    sum=100*1.01;
    while(sum<k)
    {
        sum=sum*1.01;
        count++;
        
    }
    cout << count << endl;
    return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define dbg(x) cout<<#x" = "<<(x)<<ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

ll n, x;

int main() {
	cin >> n >> x;
	cout << 3*(n-__gcd(n,x)) << ln;
}

Measured memory_bytes: 256
/*
   Creator - Glitched
   Yeet!!
*/
#include "bits/stdc++.h"

using namespace std;

#define testcases ll T;cin>>T;while(T--)
#define ll long long
#define loop(i,x,n) for(ll i=x;i<n;i++)
#define loopr(i,x,n) for(ll i=n-1;i>=x;i--)
#define ff first
#define ss second
#define pb push_back
#define elif else if
#define flush cout<<"\n"
#define mod 1000000007
#define L LONG_MAX
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
const string yes = "YES", no = "NO";
// vector<bad()ool> v(1E5, false);




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

    cout<<(n%2==0?n/2:n/2 + 1);
}

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

int main() {
  int a,b;
  cin >> a;
  cin >> b;
   if (a<=b) {
       for (int i=0; i<b-1; i++) {
           cout << a;
       }
       cout << a << endl;
   }
   else {
       for (int j=0; j<a-1; j++) {
           cout << b;
       }
       cout << b << endl;
   }
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
using ll = long long;
ll num = 1000000007;

int main() {
	ll n, m;
	cin >> n >> m;
	ll N = 1, M = 1;
	for (int i = 1;i <= n;i++) {
		N *= i;
		N %= num;
	}
	for (int i = 1;i <= m;i++) {
		M *= i;
		M %= num;
	}
	if (n == m)cout << N * M * 2 % num<< endl;
	else if (abs(n - m) <= 1)cout << N * M % num<< endl;
	else cout << 0 << endl;
}

Measured memory_bytes: 256
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <iostream>
#include <string>
#include<algorithm>
#include <vector>
#include <cassert>
#include<cmath>
using namespace std;
int main() {
	long long i, j;
	long long A;
	long long B;
	long long K;

	cin >> A >> B >> K;

	if (K<=A) {
		cout << A-K<<" " << B << endl;
	}
	else if (K<=A+B) {
		cout << 0 << " " << B-(K-A) << endl;
	}
	else {
		cout << 0 << " " << 0 << endl;
	}


}


Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        var sc = new Scanner(System.in);
    
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        var a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = Integer.parseInt(sc.next());
        }
        
        var pw = new PrintWriter(System.out);
        for(int i = k; i < n; i++){
            if(a[i] > a[i-k]){
                pw.println("Yes");
            }else{
                pw.println("No");
            }
        }
        pw.flush();
    }
}

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

int main() {
    string s;
    cin >> s;
    for (int i = 1; i < 4; i++) {
        if (s[i] == s[i - 1]) {
            cout << "Bad" << endl;
            return 0;
        }
    }
    cout << "Good" << endl;
}

Measured memory_bytes: 764
N,M=map(int,input().split())
A=list(map(int,input().split()))
for i in range(len(A)):
  A[i]=A[i]*(-1)

import heapq
heapq.heapify(A)
for i in range(M):
  price=heapq.heappop(A)*(-1)
  heapq.heappush(A,(price//2)*(-1))
  
print(sum(A)*(-1))

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

int main() {

	ll n; cin >> n;
	vector<ll> x(n);
	for (ll i = 0; i < n; i++) {
		cin >> x[i];
	}
	ll ans = 1000000000;
	for (ll j = -100; j <= 100; j++) {
		ll d = 0;
		for (ll i = 0; i < n; i++) {
			d += (j - x[i]) * (j - x[i]);
		}
		ans = min(ans, d);
	}
	cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

#define eps 1e-9
#define all(a)   a.begin(),a.end()
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define sz size()
#define sl(inp) scanf("%lld",&inp)
#define sd(inp) scanf("%d",&inp)

const long long linf = 1e18+5;
const int mod = (int) 1e9 + 7;
const int inf = 1e9;

ll fpow(ll base,ll power){
  ll result = 1;
  while (power > 0){
    if (power%2 == 1) result=(result*base);
  	base = (base*base);
  	power /= 2;
  }
	return result;
}

int main(){
    ll a, b;
    cin >> a >> b;
    if ( a == 0 || b == 0 ){
    	cout << "Zero\n";
    	return 0;
    }
    if ( a > 0 && b < 0 ){
		cout << "Zero\n";
		return 0;    	
    }
    if ( b > 0 && a < 0 ){
    	cout << "Zero\n";
    	return 0;
    }
    if ( a < 0 && b < 0 ){
    	ll cnt = abs(b) - abs(a) + 1;
    	if ( cnt % 2 == 0 ){
    		cout << "Positive\n";
    		return 0;
    	}
    	else{
    		cout << "Negative\n";
    		return 0;
    	}
    }
    if ( a > 0 && b > 0 ){
    	cout << "Positive\n";
    	return 0;
    }

    return 0;
}

Measured memory_bytes: 256