akhauriyash/Code-Regression huggingface dataset:
// In the name of God

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int maxn=1e5+10,mod=1e9+7;
const ll inf=1e18;

vector<int>v;
vector<pii>ed;

int main(){
    string s;cin>>s;
    int n=sz(s);
    bool yp=s[n-1]=='0';
    yp&=s[0]=='1';
    for(int i=0;i<n-1;i++){
	yp&=(s[i]==s[n-i-2]);
    }
    if(!yp){
	return cout<<-1<<endl,0;
    }
    for(int i=1;i<n-1;i++){
	if(s[i]=='1')
	    v.PB(i+1);
    }
    v.PB(n);
    int nw=1,C=2,SZ=1;
    for(int x:v){
	SZ++;
	int r=C++;
	ed.PB({nw,r});
	nw=r;
	while(SZ<x){
	    ed.PB({nw,C++});
	    SZ++;
	}
    }
    for(pii p:ed){
	cout<<p.F<<" "<<p.S<<endl;
    }
    return 0;
}


Measured memory_bytes: 2868
S = input()
num_query = int(input())

rev_flag = False
head = []
tail = []
for i in range(num_query):
    query = input().split()
    if len(query) == 1:
        if rev_flag == True:
            rev_flag = False
        else:
            rev_flag = True
    else:
        if rev_flag == False:
            if query[1] == "1":
                head.append(query[2])
            else:
                tail.append(query[2])
        else:
            if query[1] == "1":
                tail.append(query[2])
            else:
                head.append(query[2])

head = "".join(head)
head = head[::-1]
tail = "".join(tail)
ans = head + S + tail

if rev_flag == True:
    ans = ans[::-1]

print(ans)


Measured memory_bytes: 4972
import math 
import fractions
import collections


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
A,B=map(int,input().split())
counter=0
gcd=fractions.gcd(A,B)
c = collections.Counter(prime_factorize(gcd))
print(len(c)+1)

Measured memory_bytes: 5052
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int n;
cin>>n;
int ar[n];
for(int i=0;i<n;i++)
{
cin>>ar[i];
  }
int dp[n+1];
dp[1]=0;
dp[0]=0;
dp[2]=abs(ar[1]-ar[0]);
for(int i=3;i<=n;i++)
 {
dp[i]=min(abs(ar[i-3]-ar[i-1])+dp[i-2],abs(ar[i-2]-ar[i-1])+dp[i-1]);
}
cout<<dp[n];
}


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

using namespace std;

int main() {
    int n ; cin>>n;
    vector<int>v(n + 1);
    for(int i = 1;  i <= n; ++i){
        int x; cin>>x;
        v[i] = x;
    }
    int cnt = 0;
    for(int i = 1 ; i <= n; ++i){
        if(i == v[v[i]])cnt++;
    }
    cout<<(cnt >> 1)<<"\n";
}

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

using namespace std;

int main()
{
	int D, N, M;

	while (true)
	{
		cin >> D;

		if (D == 0) { break; }
		
		cin >> N >> M;

		vector<int> S(N + 1);
		vector<int> T(M);

		S[0] = 0;
		S[N] = D;

		for (int i = 1; i < N; i++) { cin >> S[i]; }
		for (int i = 0; i < M; i++) { cin >> T[i]; }

		sort(S.begin(), S.end());

		long long distance_ = 0;

		for (int i = 0; i < M; i++)
		{
			int l = *(upper_bound(S.begin(), S.end(), T[i]) - 1);
			int r = *lower_bound(S.begin(), S.end(), T[i]);

			distance_ += min(T[i] - l, r - T[i]);
		}

		cout << distance_ << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3364
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int N,M;
const int MN=100000;
vector<int> G[MN];
bool vis[MN];

vector<int> vc;

void dfs(int v){
	vis[v]=1;
	for(int u:G[v]) if(!vis[u]){
		vc.pb(u);
		dfs(u);
		break;
	}
}
int main(){
	cin>>N>>M;
	rep(i,M){
		int x,y;
		cin>>x>>y;
		x--,y--;
		G[x].pb(y);
		G[y].pb(x);
	}
	vector<int> ans;
	dfs(0);
	reverse(all(vc));
	for(int v:vc) ans.pb(v);
	vc.clear();
	dfs(0);
	ans.pb(0);
	for(int v:vc) ans.pb(v);
		cout<<ans.size()<<endl;
	for(int v:ans) cout<<v+1<<" ";
	puts("");

}


Measured memory_bytes: 10104
#a問題(できなかった)
s = input()
p=s[0]=='R'
q=s[1]=='R'
r=s[2]=='R'

if p and q and r==True:
    print(3)
elif (p and q)or(q and r)==True:
    print(2)
elif p or q or r ==True:
    print(1)
else:
    print(0)




Measured memory_bytes: 9112
#include <iostream>//数据输入输出流
#include <cstring>//字符串操作函数
#include <cstdio>//C的输入输出
#include <cstdlib>//定义杂项函数及内存分配函数
#include <cmath>//C中的数学函数
#include <string>//c++中的string类 他不能用strcpy等c函数去操作
#include <vector>//STL vetor
#include <list>//STL list
#include <map>// STL map
#include <set>
#include <queue>// STL queue
#include <stack>//sTL stack
#include <bitset>//bitset可按位定义串
//比如：bitset <1000> all;定义一个1000位的串
#include <algorithm>//STL各种算法 比如 swap sort merge max min 比较
#include <numeric>//常用数字操作 一般和algorithm搭配使用
#include <functional>//STL定义运算函数（代替运算符）
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
#define LOCAL
#define zeros(a,n) memset(a,0,(n)*sizeof(a[0]))
const int modn = 1e9+7;
int mod(int x) { return x<0?x+modn:x<modn?x:x-modn; }
//inv [ i ] = (modn - modn/i)*inv[ modn%i ] %modn;
string s;
int sum[4005][3];
int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    int n;
    cin>>n;
    cin>>s;
    LL ans = 0;
    for(int i = n - 1; i >=0; --i){
        sum[i][0] = sum[i+1][0];
        sum[i][1] = sum[i+1][1];
        sum[i][2] = sum[i+1][2];
        if(s[i] == 'R') sum[i][0] += 1;
        else if(s[i] == 'G') sum[i][1] += 1;
        else sum[i][2] += 1;
    }
    for(int i = 0;i  < n; ++i){
        for(int j = i + 1; j < n; ++j){
            int t = j - i;
            int k = j + t;
            if(s[j] == s[i]) continue;
            int res = 0;
            set<char>st;
            st.insert(s[i]); st.insert(s[j]);
            if(st.count('R')==0) res = 0;
            if(st.count('G') == 0) res = 1;
            if(st.count('B') == 0) res = 2;
            //cout << i << " " << j << " " << k << " " << res << endl;
            ans += sum[j][res];
            if(k >= n) continue;
            if(res == 0 && s[k] == 'R') ans -= 1;
            if(res == 1 && s[k] == 'G') ans -= 1;
            if(res == 2 && s[k] == 'B') ans -= 1;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3200
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
    n = int(input())

    a = [None] * n
    for i in range(n):
        a[i] = int(input())

    a_sorted = sorted(a, reverse=True)
    a_max = max(a)

    for i in a:
        if i != a_max:
            print(a_max)
            continue

        index = a_sorted.index(i)
        if index == 0:
            print(a_sorted[index + 1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 61756
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    def f(n):
        a = [F() for _ in range(n+3)]
        kd = {}
        for i in range(n+3):
            k = [i**c for c in range(n,-1,-1)]
            kd[(i,)] = [a[i], k]

        for _ in range(n):
            nd = {}
            kl = sorted(list(kd.keys()))
            for i in range(len(kl)):
                k1 = kl[i]
                t1 = kd[k1]
                if t1[-1][-1] == 0:
                    nd[k1] = [t1[0], t1[1][:-1]]
                    continue
                for j in range(i+1,len(kl)):
                    k2 = kl[j]
                    sf = 0
                    for c in k1:
                        if c not in k2:
                            sf += 1
                    if sf != 1:
                        continue
                    t2 = kd[k2]
                    if t2[-1][-1] == 0:
                        continue
                    w = t2[-1][-1] / t1[-1][-1]
                    mt = t2[0] - t1[0] * w
                    ma = [c2 - c1*w for c1,c2 in zip(t1[-1][:-1],t2[-1][:-1])]
                    mk = tuple(sorted(set(k1) | set(k2)))
                    nd[mk] = [mt, ma]
            kd = nd
        msa = inf
        msi = -1
        kl = sorted(list(kd.keys()))
        # for k in kl:
            # print(k, kd[k], kd[k][0] / kd[k][1][0] if abs(kd[k][1][0]) > eps else 'none')
        for i in range(n+3):
            mi = inf
            ma = -inf
            for k in kl:
                if i in k or abs(kd[k][1][0]) < eps:
                    # print('not int', i, k)
                    continue
                t = kd[k][0] / kd[k][1][0]
                # print('in', i,t,k)
                if mi > t:
                    mi = t
                if ma < t:
                    ma = t
            sa = ma - mi
            # print(i,ma,mi,sa)
            if msa > sa:
                msa = sa
                msi = i

        return msi


    while 1:
        n = I()
        if n == 0:
            break
        rr.append(f(n))
        # print('rr', rr[-1])

    return '\n'.join(map(str,rr))


print(main())



Measured memory_bytes: 9128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const string nl="\n";
const ll MOD=1000000007;

int main(){
    int a,b,c;cin>>a>>b>>c;
    cout<<max(b+c-a,0);
    return 0;
}

Measured memory_bytes: 256
function main(s) {
	v = s.split("\n");
	x = 0;
	for (i = 1; i <= Number(v[0]); i++) {
		x += Number(v[i].split(" ")[1] - v[i].split(" ")[0] + 1)
	}
	console.log(x);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));



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

namespace A
{
    class Program
    {
        /// <summary>
        ///   The main entry point for the application
        /// </summary>
        [STAThread]
        public static void Main(string[] args)
        {
            string str_s = Console.ReadLine();//2つ以上のスペース区切り入力の取得
            str_s.ToList();
            string str_t = Console.ReadLine();//2つ以上のスペース区切り入力の取得
            str_t.ToList();
            int c = 0;
            for (int i = 0; i < 3; i++) {
                if(str_s[i] == str_t[i]) {
                    c++;
                }
            }
            Console.Write("{0}", c);
        }
    }
}

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

using namespace std;


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

	vector<int> h(n);
	for (int i = 0; i < n; i++) cin >> h[i];

	vector<bool> p(n, true);


	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;

		if (h[a] <= h[b]) p[a] = false;
		if (h[b] <= h[a]) p[b] = false;
	}

	int answer = 0;
	for (int i = 0; i < n; i++) {
		if (p[i]) answer++;
	}

	cout << answer << endl;

}

Measured memory_bytes: 3788
#include "bits/stdc++.h"
using namespace std;

int n, k, a[100];
int ans[200][100][100];
bool found[200][100][100];

int dp(int rem, int l, int r){
	if(rem == 0)
		return 0;
	if(found[rem][l][r])
		return ans[rem][l][r];
	found[rem][l][r] = true;

	// Not take
	ans[rem][l][r] = 0;
	// Take from left/right
	if(l <= r){
		int tmpAns = max(dp(rem-1, l+1, r)+a[l], dp(rem-1, l, r-1)+a[r]);
		ans[rem][l][r] = max(ans[rem][l][r], tmpAns);
	}
	// Take and return later
	if(l <= r && rem > 1){
		int tmpAns = max(dp(rem-2, l+1, r), dp(rem-2, l, r-1));
		ans[rem][l][r] = max(ans[rem][l][r], tmpAns);
	}
	return ans[rem][l][r];
}

int main(){
	scanf("%d %d", &n, &k);
	for(int i = 0; i < n; ++i){
		scanf("%d", &a[i]);
	}
	printf("%d\n", dp(k, 0, n-1));
}

Measured memory_bytes: 5120
import java.util.*;


class Main {
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int b = sc.nextInt();
      int c = sc.nextInt();

      int[] array = {a, b, c};
      int[] anwer = {5, 5, 7};

      Arrays.sort(array);

      if (Arrays.equals(array, anwer))
        System.out.println("YES");
      else
        System.out.println("NO");
    }
}


Measured memory_bytes: 21844
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>

using namespace std;

int main(){
  char S;
  cin >> S;
  if(S=='A'){
    cout << "T" << endl;
  }
  else if(S=='T'){
    cout << "A" << endl;
  }
  else if(S=='C'){
    cout << "G" << endl;
  }
  else if(S=='G'){
    cout << "C" << endl;
  }
  return 0;
}


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

#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
#define MAX(X, Y) (((X) > (Y)) ? (X) : (Y))
#define ll long long

int main(void)
{
    int a1,a2,i;
    for(i=0;i<3000;i++)
    {
        scanf("%d%d",&a1,&a2);
        if(a1==0 && a2==0)
            return 0;
        printf("%d %d\n",MIN(a1,a2),MAX(a1,a2));
    }
    return 0;
}




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

#define INF (1<<30)

#define Rep0(i, n)  for (int i=0; i<n; i++)
#define Rep1(i, n)  for (int i=1; i<=n; i++)

struct  Item {
    int v=0;
    int w=0;
};

int F(const int &n, vector<Item> c, vector<int> &DP) {
    if (0<=DP.at(n))
        return DP.at(n);
    int S=0;
    Rep0(i, c.size())
        if (n>=c.at(i).w)
            S=max(S, F(n-c.at(i).w, c, DP)+c.at(i).v);
    DP.at(n)=S;
    return S;
}

int main() {
    int N, W;
    cin >>N >>W;
    vector<Item> I(N);
    Rep0(i, N)
        cin >>I.at(i).v >>I.at(i).w;
    vector<int> DP(W+1, -1);
    DP.at(0)=0;
    cout << F(W, I, DP) <<endl;
    return 0;
}



Measured memory_bytes: 12144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
const ll INF = 1LL<<60;
const ll M = 1000000007;
ll mpow(ll a,ll b){ll res=1;while(b!=0){if(b&1)res=res*a%M;a=a*a%M;b=b>>1;}return res;}
ll mcomb(ll n,ll k){if(k>n/2)return mcomb(n,n-k);ll res=1;for(ll i=0;i<k;i++){res=res*(n-i)%M;res=res*mpow(k-i,M-2)%M;}return res;}
/*template*/

int main()
{
  ll k,x;cin>>k>>x;
  string ans=500*k>=x?"Yes":"No";
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
def christmas_eve_eve(N: int, P: list) -> int:
    p_max = max(P)
    return sum(P) - (p_max // 2)


if __name__ == "__main__":
    N = int(input())
    P = [int(input()) for _ in range(N)]
    ans = christmas_eve_eve(N, P)
    print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n, m, t, a[100005];
vector< ll > adj[100005];
#define ari for( int i = 0 ; i < n ; i++ ) cin >> a[i];
#define ginp for( int i = 0 ; i < m ; i++ ){ int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u);}
#define pb push_back
#define ss second
#define ff first
#define fs first.second
#define fff first.first
#define sss second.second
#define sf second.first

int main(){
	cin >> n;
	ari;
	ll p = 2, ans = a[0] - 1, mini = 1000000009;
	for(int i = 1 ; i < n ; i++){
		if( a[i] == p )
			p++;
		ans += (a[i] - 1) / p;
	}
	cout << ans << endl;
	return(0);
}

Measured memory_bytes: 6728
def solve():
    from sys import stdin
    f_i = stdin
    
    mod = 10 ** 9 + 7
    N = int(f_i.readline())
    A = tuple(map(int, f_i.readline().split()))
    
    ans = 1
    xyz = [0, 0, 0]
    for A_i in A:
        cnt = xyz.count(A_i)
        if cnt == 0:
            print(0)
            break
        ans *= cnt
        ans %= mod
        xyz[xyz.index(A_i)] += 1
    else:
        print(ans)

solve()

Measured memory_bytes: 13432
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    map<string, int> mp;
    mp["SUN"] = 0;
    mp["MON"] = 1;
    mp["TUE"] = 2;
    mp["WED"] = 3;
    mp["THU"] = 4;
    mp["FRI"] = 5;
    mp["SAT"] = 6;
    string s;
    cin >>s;
    cout <<7 - mp[s];
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>

int main() {
	int n,m=0;
	std::cin >> n;
	std::vector<int> v(n);
	
	for (int &x : v) {
		std::cin >> x;
	}

	for (int i = 0; i < n; i++) {
		m += v[i];
	}

	std::cout<<m-n<<std::endl;
	return 0;
}

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

int main(){
	int n,k,sum=0;
	cin>>n>>k;
	int a[n+1];
	
	for(int i=1;i<=n;i++)
		cin>>a[i];
	sort(a+1,a+n+1);
	
	int i=1;
	while(k--){
		sum+=a[i];
		i++;
	}
	
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3612
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#define endl "\n";
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

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 = 100100100100100;
const int MOD = 1000000007;
const int inf = 1001001001;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

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

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

    int N;cin >> N;
    vector<vector<int>> triangle(505);
    int count = 0;
    int floor = 1;
    int index = 0;
    for(int i = 1;i<=N;i++){
        count++;
        if(count > floor){
            floor++;
            index++;
            triangle.at(index).push_back(i);
            count = 1;
        }
        else{
            triangle.at(index).push_back(i);
        }
    }

    bool ok = true;
    for(int i = 0;i<floor-1;i++){
        if(triangle.at(i+1).size()-triangle.at(i).size() != 1) ok = false;
    }

    if(!ok){
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
    cout << floor+1 << endl;

    //斜め
    cout << floor;
    for(int i = 0;i<floor;i++){
        cout << " " << triangle.at(i).back();
    }
    cout << endl;

    for(int i = 0;i<floor;i++){
        cout << floor;
        int h = i,w = 0;
        for(int j = 0;j<floor;j++){
            cout << " " << triangle.at(h).at(w);
            if(triangle.at(i).size()-1 == w){
                h++;
            }
            else{
                w++;
            }
        }
        cout << endl;
    }

}


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

int p[21];

int main() {
  int n, result;
  int i;
  scanf ("%d", &n);
  
  for (i=0;i<n;i++) {
      scanf("%d", &p[i]);
  }
  
  result = 0;
  for (i=1;i<n-1;i++) {
    if (p[i-1]<p[i] && p[i]<p[i+1]) result++;
    if (p[i-1]>p[i] && p[i]>p[i+1]) result++;
  }
  
  
  printf("%d", result);
  return 0;
}




Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 1000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
#define MAX_N 200000
int N,M,R;
vector<int> r;
int d[205][205];
int main(){
	scanf("%d %d %d",&N,&M,&R);
	r.resize(R);
	for(int i=0;i<R;i++){
		cin >> r[i];
		r[i]--;
	}
	sort(all(r));
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++)d[i][j]=INF;
	}
	for(int i=0;i<N;i++)d[i][i]=0;
	for(int i=0;i<M;i++){
		int a,b,c;
		cin >> a >> b >> c;
		a--;b--;
		d[a][b]=d[b][a]=c;
	}
	for(int k=0;k<N;k++){
		for(int i=0;i<N;i++){
			for(int j=0;j<N;j++){
				d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
			}
		}
	}
	int ans = INF;
	do{
		int ret = 0;
		for(int i=1;i<R;i++){
			ret+=d[r[i]][r[i-1]];
		}
		chmin(ans,ret);
	}while(next_permutation(r.begin(),r.end()));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
int A,B,X;
cin >> A >> B >> X;
bool b = true;
if(A > X) b = false;
else if (A + B < X)b = false;

if(b) cout << "YES" <<endl;
else cout << "NO" << endl;

}



Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
	int k=0,n,e=0,d=0,i; 
	string s;
	cin>>n;
	cin>>s;
	for(i=0;i<s.length();i++){
		if(s[i]=='I') e++;
		else d++;
		k=max(k,e-d);
	}
	cout<<k<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void){
    int n;
    cin>>n;
    int mod = n % 10;
    if(mod == 2 || mod == 4 || mod == 5 || mod == 7 || mod == 9)cout<<"hon"<<endl;
    else if(mod == 0 || mod == 1 || mod == 6 || mod == 8)cout<<"pon"<<endl;
    else cout<<"bon"<<endl;
    return 0;
}

Measured memory_bytes: 3100
#include <iostream>
using namespace std;
int main()
{
    int n,maxx=0,nr=0;
    int a[100005];
    cin >> n;
    for (int i=1;i<=n;i++)
    {
        cin >> a[i];
    }
    for (int i=2;i<=n;i++)
    {
        if (a[i]<=a[i-1]) nr++;
        else
        {
            if(nr>maxx) maxx=nr;
            nr=0;
        }
    }
    if (nr>maxx) maxx=nr;
    cout << maxx;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
int main()
{
    double a,b,c;
    std::cin >> a >> b >> c;
    double i = 0;
    double x = 0;
    int y = 0;
    std::vector<double> data;
    while(i < 10000000000)
    {
        i++;
        x = fmod((a * i), b);
        data.push_back(x);
        if(c == x)
        {
            std::cout << "YES" << std::endl;
            break;
        }
        y = std::count(data.begin(), data.end(), x);
        if(y != 1)
        {
            std::cout << "NO" << std::endl;
            break;
        }
    }
    return 0;
}

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

#define ll long long
#define ull unsigned long long
#define met(a, x) memset(a,x,sizeof(a));
#define inf 0x3f3f3f3f
#define mp make_pair;

using namespace std;
const int mod = 1e9 + 7;
const int N = 1e6 + 10;
const int M = 1e5 + 10;
int a[310][310];
bool vis[310];
int f[310], num[310];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    int ans = inf;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            cin >> a[i][j];
    for (int i = 1; i <= n; i++)
        num[i] = 1;
    int flag=0;
    for (int i = 1; i <= m; i++) {
        int maxn=0;
        met(f,0);
        for(int j=1;j<=n;j++){
            f[a[j][num[j]]]++;
            if(f[a[j][num[j]]]>maxn){
                maxn=f[a[j][num[j]]];
                flag=a[j][num[j]];
            }
        }
        vis[flag]=1;
        ans=min(ans,maxn);
        for(int j=1;j<=n;j++){
            while(vis[a[j][num[j]]]==1){
                num[j]++;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}



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

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

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<int> l(n);
    for(int i = 0; i < n; i++) {
        cin >> l[i];
    }
    sort(l.begin(),l.end());
    int cnt=0;
    for(int i = 0; i < n; i++) {
        for(int j = i+1; j < n; j++) {
            for(int k = j+1; k < n; k++) {
                if(l[i]!=l[j] && l[j]!=l[k] && l[k]!=l[i] && l[i]+l[j]>l[k]) cnt++;
            }
        }
    }
    cout << cnt << "\n";

    return 0;
}

Measured memory_bytes: 3560
N, K = map(int, input().split())
h_list = list(map(int, input().split()))
def chmin(a, b):
    if a > b:
        return b
    else:
        return a
dp_list = [1000000000] * N
dp_list[0] = 0
dp_list[1] = abs(h_list[1] - h_list[0])
for n in range(1, N):
    for k in range(1, K+1):
        dp_list[n] = chmin(dp_list[n], dp_list[n-k] + abs(h_list[n-k] - h_list[n]))
        if n-k == 0:
            break
print(dp_list[-1])

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

namespace _0622
{
	class Program
	{
		static long[] arr;
		static bool IsOK(int index, long key, bool findbig)
		{
			if (arr[index] > key == findbig) return true;
			else return false;
		}

		static int Binary_search(long key, bool findbig)
		{
			int ng = findbig ? -1 : arr.Count();
			int ok = findbig ? arr.Count() : -1;

			while (Math.Abs(ok - ng) > 1)
			{
				int mid = ng + (ok - ng) / 2;

				if (IsOK(mid, key, findbig)) ok = mid;
				else ng = mid;
			}

			return ok;
		}
		static void Main(string[] args)
		{
			long[] x = Console.ReadLine().Split().Select(long.Parse).ToArray();
			Tuple<long, long>[] people = new Tuple<long, long>[x[0]];
			List<long> stop = new List<long>();
			for (int i = 0; i < x[0]; i++)
			{
				long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();
				people[i] = new Tuple<long, long>(a[0], a[1]);
				if (i > 0 && people[i - 1].Item2 == 1 && people[i].Item2 == 2)
					stop.Add((people[i - 1].Item1 + people[i].Item1) / 2);
			}
			arr = stop.ToArray();
			for (int i = 0; i < x[2]; i++)
			{
				int n = int.Parse(Console.ReadLine());
				var now = people[n - 1];
				int key = Binary_search(now.Item1, now.Item2 == 1 ? true : false);
				if (key == -1 || key == arr.Count() || Math.Abs(arr[key] - now.Item1) > x[1])
					Console.WriteLine(now.Item1 + (now.Item2 == 1 ? x[1] : -x[1]));
				else Console.WriteLine(arr[key]);
			}
		}
	}
}


Measured memory_bytes: 26252
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
const int maxn = 2e6+100;
using namespace std;
typedef long long ll;
int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int a,b;
	cin>>a>>b;
	cout<<a*b; 
	
	return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int NMAX = 2005;
ll dp[NMAX][NMAX]; // = nCk

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

    rep(i, NMAX) dp[i][0] = dp[i][i] = 1;
    for (int i = 2; i < NMAX; i++) {
        for (int j = 1; j <= i-1; j++) {
            dp[i][j] = dp[i-1][j-1] + dp[i-1][j];
            // cout << dp[i][j] << endl;
            dp[i][j] %= MOD;
        }
    }
    cout << dp[n+k-1][k-1] << endl;
}



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

int main()
{
    ll n;
    cin >> n;
    ll sum = 26;
    ll cnt = 1;
    while (1)
    {
        if (n <= sum)
            break;
        sum = sum * 26 + 26;
        cnt++;
    }
    vector<string> res(cnt);
    rep(i, cnt)
    {
        n--;
        int ans = n % 26;
        res[cnt - i - 1] = (char)('a' + ans);
        n /= 26;
    }
    rep(i, res.size()) cout << res[i];
    cout << endl;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PDD pair<double, double>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 1, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 0) u += MOD;
    return u;

}

LL exp(LL a, LL b){
    LL res = 1;
    LL sum = a;
    while(b){
        if(b&1)res = (res * sum);
        sum = (sum * sum);
        b>>=1;
    }
    return res;
}

double exp(double a, LL b){
    double res = 1;
    double sum = a;
    while(b){
        if(b&1)res = (res * sum);
        sum = (sum * sum);
        b>>=1;
    }
    return res;
}

signed  main(){
    int line[3];
    REP(i, 3)cin>>line[i];
    sort(line, line+3);
    cout << line[0] * line[1] / 2 << endl;
    return 0;
}


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

int main(){
    int n,i,sum=0;
    int a[100],b[100];

    scanf("%d",&n);
    for(i=0;i<n-1;i++){
        scanf("%d",b+i);
    }


    a[0]=b[0];
    for(i=1;i<n-1;i++){
        if(b[i-1]<b[i]){    
            a[i]=b[i-1];
        }else{
            a[i]=b[i];
        }
    
    }
    a[n-1]=b[n-2];

    for(i=0;i<n;i++){
        sum+=a[i];
    }

    printf("%d\n",sum);
    return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int W = sc.nextInt();
        int[] w = new int[N];
        int[] v = new int[N];
        for (int i = 0; i < N; i++) {
            w[i] = sc.nextInt();
            v[i] = sc.nextInt();
        }

        long[][] dp = new long[N+1][W+1];
        for (int i = 1; i <= N; i++) {
            for (int j = 0; j <= W; j++) {
                if (j - w[i-1] >= 0) {
                    dp[i][j] = Math.max(dp[i-1][j - w[i-1]] + v[i-1], dp[i-1][j]);
                } else {
                    dp[i][j] = dp[i-1][j];
                }
            }
        }

        System.out.println(dp[N][W]);
    }
}


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

typedef long long ll;
const ll mod = 1000000007;

int main() {
    int n;
    cin >> n;
    ll ans = 0;
    ll vec[n];
    for (int i = 0; i < n; i++) {
        cin >> vec[i];
    }
    ll sum = 0;
    ll sumb = 0;
    for (int i = 0; i < n; i++) {
        sum += vec[i];
        if (i%2 == 0) {
            if (sum < 1) {
                sumb += 1-sum;
                sum = 1;
            }
        } else {
            if (sum > -1) {
                sumb += sum+1;
                sum = -1;
            }
        }
    }
    ans = sumb;
    sumb = 0;
    sum = 0;
    for (int i = 0; i < n; i++) {
        sum += vec[i];
        if (i%2 == 0) {
            if (sum > -1) {
                sumb += sum+1;
                sum = -1;
            }
        } else {
            if (sum < 1) {
                sumb += 1 - sum;
                sum = 1;
            }
        }
    }
    cout << min(ans, sumb) << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
	string s, t;
	cin >> s >> t;

	int size1 = s.size();
	int size2 = t.size();

	//DP遷移行列の作成
	vector<vector<int>> dp(size1+1, vector <int> (size2+1, 0));
	for (int ii = 0; ii < size1; ++ii){
		for (int jj = 0; jj < size2; ++jj){
			if (s[ii] == t[jj]){
				dp[ii+1][jj+1] = dp[ii][jj] + 1;
			} else {
				dp[ii+1][jj+1] = max(dp[ii+1][jj], dp[ii][jj+1]);
			}
		}
	}

	//復元
	string ans = "";
	int sidx = size1-1;
	int tidx = size2-1;
	while ( (sidx >= 0) && (tidx >= 0) ) {
		//上と左がどちらも小さい場合に追加
		if (dp[sidx+1][tidx+1] == dp[sidx][tidx+1]){
			sidx--;
		} else if (dp[sidx+1][tidx+1] == dp[sidx+1][tidx]) {
			tidx--;
		} else {
			ans = ans + s[sidx];
			sidx--;
			tidx--;			
		}
	}

	reverse(ans.begin(), ans.end());
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 35584
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
n=int(input())
A=[int(input())-1 for _ in range(n-1)]
C=[[] for _ in range(n)]
for i,a in enumerate(A):
    C[a].append(i+1)

def depth(k):
    l=len(C[k])
    if not l:
        return 0
    else:
        D=[]
        ret=-1
        for c in C[k]:
            D.append(depth(c))
        D.sort(reverse=True)
        for i,d in enumerate(D):
            ret=max(ret,d+i+1)
        return ret

print(depth(0))

Measured memory_bytes: 122928
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

alias Pair = Tuple!(string, "name", int, "score", int, "index");

void main() {
    int n;
    scan(n);
    auto rs = new Pair[](n);
    foreach (i ; 0 .. n) {
        string si;
        int pi;
        scan(si, pi);
        rs[i] = Pair(si, pi, i + 1);
    }
    rs.sort!"a.name != b.name ? a.name < b.name : a.score > b.score"();
    foreach (i ; 0 .. n) {
        writeln(rs[i].index);
    }
}



















int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new int[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v;
        scan(u, v);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= v;
        if (isUndirected) {
            adj[v] ~= u;
        }
    }

    return adj;
}

alias Edge = Tuple!(int, "to", int, "cost");

Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new Edge[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v, c;
        scan(u, v, c);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= Edge(v, c);
        if (isUndirected) {
            adj[v] ~= Edge(u, c);
        }
    }

    return adj;
}

void yes(bool b) {
    writeln(b ? "Yes" : "No");
}

void YES(bool b) {
    writeln(b ? "YES" : "NO");
}

T[] readArr(T)() {
    return readln.split.to!(T[]);
}

T[] readArrByLines(T)(int n) {
    return iota(n).map!(i => readln.chomp.to!T).array;
}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        long n = Long.parseLong(bf.readLine());
        long sq = (long)Math.ceil(Math.sqrt(n));
        long sq1 = sq*sq;
        long diff1 = sq1-n;
        long sq2 = sq*(sq-1);
        long diff2 = sq2 - n;
        if((diff2 >= 0) && (diff2 < diff1)) {
          out.println(sq + " " + diff2 + " " + 1 + " " + (sq-1) + " " + 0 + " " + 0);
        }
        else {
          out.println(sq + " " + diff1 + " " + 1 + " " + (sq) + " " + 0 + " " + 0);
        }

        // StringTokenizer st = new StringTokenizer(bf.readLine());
        // int[] a = new int[n]; for(int i=0; i<n; i++) a[i] = Integer.parseInt(st.nextToken());
        // int n = Integer.parseInt(st.nextToken());

        out.close(); System.exit(0);
    }
}


Measured memory_bytes: 22612
#include <iostream>
#include <vector>

using namespace std;

int main() {
    while(true) {
        int N;
        cin >> N;
        if(!N) break;

        char table[256];
        for(int i = 0; i < 256; ++i) {
            table[i] = i;
        }
        for(int i = 0; i < N; ++i) {
            char c, d;
            cin >> c >> d;
            table[c] = d;
        }
        int M;
        cin >> M;
        while(M--) {
            char c;
            cin >> c;
            cout << table[c];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 852
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <numeric>
using namespace std;


int main(){    
    int64_t x ;
    cin >> x ;
    int64_t m = 100 ;
    int i = 0 ;
    while (m < x)
    {
       i ++ ;
       m = floor(m*1.01) ;        
    }
    cout << i << endl ;
}


Measured memory_bytes: 3716
N, K = map(int, input().split())
S = input()

str_list = list(S)

if str_list[K-1] == 'A':
    str_list[K-1] = 'a'
elif str_list[K-1] == 'B':
    str_list[K-1] = 'b'
elif str_list[K-1] == 'C':
    str_list[K-1] = 'c'

s = ''

for x in str_list:
    s += x

print(s)


Measured memory_bytes: 3060
def main():
    h, w = map(int, input().split())
    px = [input() for i in range(h)]

    for row in range(h):
        print(px[row], px[row], sep='\n')

    # px = [[0 for j in range(w)] for i in range(h)]
    # px_stretch = [[0 for j in range(w)] for i in range(2 * h)]
    # 
    # for row in range(h):
    #     px[row] = list(input())
    # 
    # for row in range(2 * h):
    #     px_stretch[row] = [px[row // 2][i] for i in range(w)]
    #     print(''.join(px_stretch[row]))


if __name__ == "__main__":

    main()


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

template<class T> T lcm(T a,T b){
	return a/__gcd(a,b)*b;
}

int main(){
	int s;
	cin >> s;
	int m=s%10;
	if(m==3){
		cout << "bon";
	}else if(m==0 || m==1 || m==6 || m==8){
		cout << "pon";
	}else{
		cout << "hon";
	}
	return 0;
}


Measured memory_bytes: 3620
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
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;
}
 
using namespace std;
//ここから
void solve(){
  int a,b;
  cin>>a>>b;
  cout<<(a-1)*(b-1);
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define con continue
#define bk break
#define LL long long
#define db double
#define pt cout<<'\n'
#define ms(a, b) memset((a), (b), sizeof(a))
#define mp make_pair
#define endl '\n'
int inf=2147483647;const long long ll =9223372036854775807,ninf=1000000000;const double eps = 1e-6; const long long nll =223372036854775807;
#define sz size()
#define len(X) strlen(X)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ULL unsigned long long
#define de cout<<"test"<<endl;
#define st system("pause");
#define M_PI 3.1415926
int A[200005]={};
int vis[200005]={};
int main()
{
    int a;
    while(cin>>a){
        for(int i=0;i<a;i++)
            cin>>A[i];
        for(int i=a-1;i>=0;i-=2){
            cout<<A[i]<<" ";
            vis[i]=1;
        }
        for(int i=0;i<a;i++){
            if(!vis[i])
            cout<<A[i]<<" ";
        }
        pt;
    }

    return 0;
}


Measured memory_bytes: 3712
import java.util.Scanner;

public class Main {

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

		int N = sc.nextInt();

		double firstCalc = 0.0;
		for(int i = 0; i < N; i++)
		{
			firstCalc += reverseNumber(sc.nextInt());
		}

		System.out.println(String.format("%f", 1/firstCalc));

		sc.close();
	}

	private static double reverseNumber(int i) {
		return 1 / (double)i;
	}

}


Measured memory_bytes: 21844
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main(void){

  int i,r,D,x,k;
  scanf("%d%d%d",&r,&D,&x);
   for(i=0;i<10;i++){
     x=r*x-D;
     printf("%d\n",x);
   }
}

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

int h, w;

int main() {
  cin >> h >> w;
  vector<string> a(h);
  rep (i, h) {
    cin >> a[i];
  }
  vector<vector<ll>> dp(h, vector<ll>(w, 0));
  dp[0][0] = 1;
  rep (i, h) {
    rep (j, w) {
      if (a[i][j] == '.') {
        if (i > 0) dp[i][j] += dp[i-1][j];
        if (j > 0) dp[i][j] += dp[i][j-1];
        dp[i][j] %= 1000000007;
      }
    }
  }
  cout << dp[h-1][w-1] << endl;
  return 0;
}


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

using namespace std;
typedef         long long int   ll;

#define         input           freopen("input.txt","r",stdin)
#define         output          freopen("output.txt","w",stdout)
#define         si(a)           scanf("%d",&a)
#define         sii(a,b)        scanf("%d%d",&a,&b)
#define         siii(a,b,c)     scanf("%d%d%d",&a,&b,&c)
#define         pi(a)           printf("%d",a)
#define         spc             printf(" ")
#define         bl              printf("\n")
#define         here(a)         printf("#### %d ####",a)
#define         pii             pair<int,int>
#define         fr(i,n)         for(int i=0;i<n;i++)
#define         case(num)       printf("Case %d:",num)
#define         inf             1000000050
#define         MAX             10010
#define         MOD             1000000007

vector<int>edge;
vector<vector<int> >triangle;
void npr(vector<int>v, int p){

    if(v.size()==3){
        triangle.push_back(v);
        //for(int i=0;i<v.size();i++) cout<<v[i]<<" ";
        //cout<<endl;
        return;
    }
    if(p>=edge.size()) return;
    npr(v,p+1);
    v.push_back(edge[p]);
    npr(v,p+1);
    v.pop_back();
}


int main(){

    //input;
    //output;

    int n,tmp;
    cin>>n;

    for(int i=0;i<n;i++){
        cin>>tmp;
        edge.push_back(tmp);
    }

    vector<int>v;

    npr(v,0);
    int a,b,c;
    int cnt = 0;

    for(int i=0;i<triangle.size();i++){
        sort(triangle[i].begin(),triangle[i].end());
        a = triangle[i][0];
        b = triangle[i][1];
        c = triangle[i][2];
        if(a!=b && a!=c && b!=c){
            if(a+b>c) cnt++;
        }
    }


    cout<<cnt<<endl;




    return 0;
}
/**
*/


Measured memory_bytes: 13564
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <math.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <queue>
#include <sstream>
#include <deque>
#include <memory.h>
#include <cassert>
#include <ctime>
#include <time.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define mp make_pair
#define FILE "file"
#define lc v << 1
#define rc (v << 1) + 1
const int inf = 1e+9+10;
const ll linf = 1e+18;

void solve()
{
    ll a, b;
    char c;
    cin >> a >> c >> b;
    if(c == '+')
    {
        cout << a + b;
    }
    else
    {
        cout << a - b;
    }
}

int main()
{
    //ios_base::sync_with_stdio(false);cin.tie(0), cout.tie(0);
    //freopen(FILE ".in", "r", stdin);freopen(FILE ".out", "w", stdout);
    int t = 1;
    //cin >> t;
    
    while(t--)
    {
        solve();
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
// std::cout << std::setprecision(2) << 3.141; // "3.1"
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
// #include <bits/stdc++.h> all

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

static const int giga = pow(10,9);
// double pi = 3.141592653589793238463;

int main(void){
  vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

  int n; cin >> n;
  cout << a[n-1] << endl;

  return 0;
}

Measured memory_bytes: 256