akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

const int INF = 1e9 + 10;

int H, W;
vector<string> S(25);
int res = 0;

vector<int> di = {1, 0, -1, 0};
vector<int> dj = {0, 1, 0, -1};

void bfs(int si, int sj, int ti, int tj) {
    int dist[25][25];
    rep(i,25) rep(j,25) dist[i][j] = -1;
    queue<P> q;
    q.push(P(si, sj));
    dist[si][sj] = 0;
    while(!q.empty()){
        P cur = q.front(); q.pop();
        int ci = cur.first, cj = cur.second;
        if (ci == ti && cj == tj) {
            chmax(res, dist[ci][cj]);
            return;
        }
        rep(k,4) {
            int ni = ci + di[k], nj = cj + dj[k];
            if (ni < 0 || ni > H || nj < 0 || nj > W) continue;
            if (S[ni][nj] == '.' && dist[ni][nj] == -1) {
                dist[ni][nj] = dist[ci][cj] + 1;
                q.push(P(ni, nj));
            } 
        }
    }
}

int main() {
    cin >> H >> W;
    rep(i,H) cin >> S[i];
    rep(si,H) rep(sj,W) rep(ti,H) rep(tj,W) {
        if (S[si][sj] == '.' && S[ti][tj] == '.') {
            bfs(si, sj, ti, tj);
        }
    }
    cout << res << endl;
}


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

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

ll lcm(ll a, ll b){
    ll g = gcd(a, b);
    return a / g * b;
}

int main(){
    int n;
    cin >> n;
    vector<ll> T(n);
    rep(i, n) cin >> T[i];
    if(n==1){
        cout << T[0] << endl;
        return 0;
    }
    ll ans = lcm(T[0],T[1]);
    for (int i = 2; i < n; i++)
    {
        ans = lcm(ans, T[i]);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main() {
  long long n, q;
  long long k;
  cin >> n >> k >> q;
  long long p[100100] = {0};
  for(long long i=0; i < q; i++){
    long long a; cin >> a; a--;
    p[a]++;
  }
  for(long long i=0; i < n; i++) {
    if(k-(q-p[i]) <= 0) cout << "No" << endl;
    else cout << "Yes" << endl;
  }
}


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

int main()
{
	int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0,ans=0;
	string s;
	string x[10];
	cin >> s;
	for (b = 0; b < 5; b++)
	{


		for (a = 0; a < s.length(); a++)
		{
			x[b] += "z";
		}
	}
	cin >> a;
	for ( b = 0; b < s.length(); b++)
	{
		for ( c = 1; c <= s.length() -b; c++)
		{
			if (s.substr(b, c) >= x[4])
			{
				break;
			}
			if (s.substr(b, c)!=x[0]&& s.substr(b, c) != x[1] && s.substr(b, c) != x[2] && s.substr(b, c) != x[3] && s.substr(b, c) != x[4] )
			{


				if (s.substr(b, c) < x[0])
				{

					x[4] = x[3];
					x[3] = x[2];
					x[2] = x[1];
					x[1] = x[0];
					x[0] = s.substr(b, c);
				}
				else if (s.substr(b, c) < x[1])
				{
					x[4] = x[3];
					x[3] = x[2];
					x[2] = x[1];
					x[1] = s.substr(b, c);
				}
				else if (s.substr(b, c) < x[2])
				{
					x[4] = x[3];
					x[3] = x[2];
					x[2] = s.substr(b, c);
				}
				else if (s.substr(b, c) < x[3])
				{
					x[4] = x[3];
					x[3] = s.substr(b, c);
				}
				else if (s.substr(b, c) < x[4])
				{
					x[4] = s.substr(b, c);
				}
			}
		}
	}



	
	cout << x[a-1] << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

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

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

#define rep(i, s, n) for(int i = s; i < n; ++i)
#define rrep(i, n) for(int i = n - 1; i > -1; --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
const long long INF = 1000000000;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int a, b;
    cin >> a >> b;
    cout << max(max(a + b, a - b), a * b) << endl;
}

Measured memory_bytes: 256
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>
#include <functional>
#include <set>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))

using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;
const ll inf = (1LL << 60);
const ll mod = 1000000007;
ll max(ll a, ll b) {
	if (a < b)
		return b;
	else
		return a;

}
ll min(ll a, ll b) {
	if (a < b)
		return a;
	else
		return b;

}





int main() {

	ll r;
	cin >> r;

	cout << 3 * r * r << endl;



	return 0;
}

Measured memory_bytes: 256
n = int(input())
cnt = {'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0}
for _ in range(n):
    si = input()
    cnt[si] += 1

print(f'AC x {cnt["AC"]}')
print(f'WA x {cnt["WA"]}')
print(f'TLE x {cnt["TLE"]}')
print(f'RE x {cnt["RE"]}')


Measured memory_bytes: 9180
#include <iostream>
#include<iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define space ' '
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

const int maxn = 200000;

int main(){
    
    set<int> s;
    int d[maxn];
    vector<pair<int,int> > v;
    int n,q;
    
    scanf("%d""%d",&n,&q);
    
    rep(i,n){
        int s,t,x;
        scanf("%d""%d""%d",&s,&t,&x);
        v.push_back(make_pair(s-x,x));
        v.push_back(make_pair(t-x,-x));
    }
    
    rep(i,q){
        scanf("%d",&d[i]);
    }
    
    sort(d,d+q);
    sort(all(v));
    v.push_back(make_pair(INF,INF));
    
    int ite = 0;
    
    rep(i,q){
        int T = d[i];
        //cout << "T "<<d[i]<<endl;
        while(T>=v[ite].first){
            if(v[ite].second>0)s.insert(v[ite].second);
            else s.erase(-v[ite].second);
            ite++;
        }
        if(s.size()==0)printf("%d\n",-1);
        else printf("%d\n",*s.begin());
    }
    
    
    return 0;
}


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

char f,g;
bool flag;
string s;
vector < int > v,va,vb;
int arr[sz],brr[sz],crr[sz];



int main(){

    priority_queue< long long int > pq;
    long long int n,m, i,j,k, x,y,z;
    cin>>s>>k;
    for(i=0; i<s.size(); i++){
        if(i+1==k || s[i]!='1'){
            cout<<s[i]<<endl;
            break;}
    }


    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    int T;
    cin>>T;
    rep(query,T){
        int N;
        cin>>N;
        vector<pair<int,pair<ll,ll>>> camel(N),cameL(0),cameR(0);
        rep(i,N){
            cin>>camel.at(i).first>>camel.at(i).second.first>>camel.at(i).second.second;
        }
        int l=0,r=0;
        sort(camel.begin(),camel.end());
        priority_queue<ll, vector<ll>, greater<ll>> dl,dr;
        ll ans=0;
        rep(i,N){
            int K=camel.at(i).first;
            ll L=camel.at(i).second.first,R=camel.at(i).second.second;
            if(L==R){
                ans+=L;
            }
            if(L>R){
                ans+=L;
                l++;
                dl.push(L-R);
                if(l>K){
                    ll f=dl.top();dl.pop();
                    ans-=f;
                    l--;
                }
            }
            if(L<R){
                cameR.pb(camel.at(i));
            }
        }
        for(int i=cameR.size()-1;i>=0;i--){
            int K=cameR.at(i).first;
            ll L=cameR.at(i).second.first,R=cameR.at(i).second.second;
            ans+=R;
            r++;
            dr.push(R-L);
            if(r>N-K){
                ll f=dr.top();dr.pop();
                ans-=f;
                r--;
            }
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 13180
#include<bits/stdc++.h>
using namespace std;
long long d[100005];
int n,m;
bool vis[100005],use[100005];
vector<int>v[100005];
vector<int>e[100005];
bool dfs(int fa)
{
    vis[fa]=true;
    use[fa]=true;
    for(int i=0;i<v[fa].size();i++)
    {
        int y=v[fa][i];
        int z=e[fa][i];
        if(d[y]>d[fa]+z)
        {
            if(vis[y])return true;
            d[y]=d[fa]+z;
            if(dfs(y))return true;
        }
    }
    vis[fa]=false;
    return false;
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        d[i]=0x7fffffffffffffff;
    }
    for(int i=1;i<=m;i++)
    {
        int x,y,z;
        scanf("%d%d%d",&x,&y,&z);
        v[x].push_back(y);
        e[x].push_back(z);
        v[y].push_back(x);
        e[y].push_back(-z);
    }
    bool ok=false;
    for(int i=1;i<=n;i++)
    {
        if(!use[i])
        {
            d[i]=false;
            if(dfs(i))
            {
                ok=true;
            }
        }
    }
    if(ok)printf("No\n");
    else printf("Yes\n");
    return 0;
}

Measured memory_bytes: 17024
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef vector<ll> vi;
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << 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; }

int main(){
  double t, x;
  cin >> t >> x;
  print(t / x);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,y;
    cin>>a;
    if(a<15)
    {
        cout<<a*800;
    }
    else if(a==15)
    {
        cout<<(a*800)-200;
    }
    else if(a>15)
    {
        y=a/15;
        cout<<(a*800)-(y*200);
    }


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb push_back
#define ld long double
#define f first
#define s second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e18 + 5;
const int mod = 1e9 + 7;
const int  N = 2e5 + 314;
const long double pi = 3.1415926535897932384626433832795;
void solve(){
    char c;
    cin>>c;
    if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')cout<<"vowel";
    else cout<<"consonant";   
}
signed main(){
    speed;
    int t=1;
    //cin>>t;
    while(t--)solve();
}

Measured memory_bytes: 256
#!ruby -na
f=->n,m,a,b{a/m*n*~-n/2+(x=b-m*y=(b+n*a%=m)/m
y>0?f[y,a,m,x%a]+y*=n+x/a:0)}
p f[*$F.map(&:to_i)]if$.>1

Measured memory_bytes: 14300
import java.util.*;
import java.io.*;

public class Main {	
	private static void solve(){
		//Implement solution here.
		int[][] map = new int[3][3];
		for(int i = 0; i < 3; i++) {
			for(int j = 0; j < 3; j++) {
				map[i][j] = ni();
			}
		}
		int N = ni();
		for(int k = 0; k < N; k++) {
			int tmp = ni();
			for(int i = 0; i < 3; i++) {
				for(int j = 0; j < 3; j++) {
					if(map[i][j] == tmp)map[i][j] = 0;
				}
			}
		}
		
		//H
		for(int i = 0; i < 3; i++) {
			if(map[i][0] == 0 && map[i][1] == 0 && map[i][2] == 0) {
				System.out.println("Yes");
				return;
			}
		}
		//V
		for(int i = 0; i < 3; i++) {
			if(map[0][i] == 0 && map[1][i] == 0 && map[2][i] == 0) {
				System.out.println("Yes");
				return;
			}
		}
		//Slash
		if(map[0][0] == 0 && map[1][1] == 0 && map[2][2] == 0) {
			System.out.println("Yes");
			return;
		}
		if(map[0][2] == 0 && map[1][1] == 0 && map[2][0] == 0) {
			System.out.println("Yes");
			return;
		}
		
		System.out.println("No");
	}

	//Switch input source (stdin/file)
	private static BufferedReader br;
	public static void main(String[] args){
		br = new BufferedReader(new InputStreamReader(System.in));
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}


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

int main(){
    int h,w;
    cin >> h >> w;
    char in[h+2][w+2];
    for(int j=0;j<w+2;j++){
        in[0][j] = '.';
        in[h+1][j] = '.';
    }
    for(int i=1;i<h+1;i++){
        in[i][0] = '.';
        for(int j=1;j<w+1;j++){
            cin >> in[i][j];
        }
        in[i][w+1] = '.';
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(in[i][j] == '#'){
                if(in[i][j-1]=='.'&&in[i][j+1]=='.'&&in[i-1][j]=='.'&&in[i+1][j] == '.'){
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <numeric>
#include <map>   
#include <stdio.h>

#define FOR(i,a,b) for(i=(a);i<(b);++i) 
#define FORR(i,a,b) for(i=(a);i>(b);--i)
#define REP(i,n) for(i=0;i<(n);++i)
#define REPR(i,n) for(i=(n);i>0;--i)
#define PB push_back
#define ull unsigned long long
#define ll long long
#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807
#define sortR(a,b) sort(a, b, greater<int>())

using namespace std;

//最大公約数


int main() {
	ll N;
	cin >> N;
	cout << N/3 << endl;
	return 0;
}

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

int main(){
  int a, b, c;
  cin >> a >> b;
  
  if(b<10) a*=10;
  else if(b<100) a*=100;
  else a*=1000;

  c=a+b;
  bool flg=false;
  for(int i=1; i<=sqrt(c); i++){
    if(c%i==0 && c/i==i) flg=true;
  }

  if(flg) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
typedef long long ll;
ll a[100000];
map<ll,ll> mp;
int main(){
	while(true){
		ll N,S,W,Q;
		cin>>N>>S>>W>>Q;
		if(N==0) break;
		mp.clear();
		ll g=S;
		rep(i,N){
			a[N-1-i]=g/7%10;
			if(g%2==0) g=g/2;
			else g=(g/2)^W;
		}
		ll ans=0;
		if(Q==2||Q==5){
			int now=0;
			for(int i=N-1;i>=0;i--){
				if(a[i]!=0){
					now++;
				}
				if(a[i]%Q==0) ans+=now;
			}
			cout<<ans<<endl;
			continue;
		}
		ll now=0;
		ll p=1;
		mp[0]=1;
		rep(i,N){
			now=(now+a[i]*p)%Q;
			p=p*10%Q;
			if(a[i]!=0){
				if(mp.count(now)){
					ans+=mp[now];
				}
			}
			mp[now]++;
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 7596
from collections import deque

N,M,K = map(int,input().split())
friend = [list(map(int,input().split())) for _ in range(M)]
block = [list(map(int,input().split())) for _ in range(K)]

f = [set() for _ in range(N+1)]
b = [set() for _ in range(N+1)]

for i,j in friend:
    f[i].add(j)
    f[j].add(i)
for i,j in block:
    b[i].add(j)
    b[j].add(i)

stack=deque()
ans = [0]*(N+1)
visited = [0]*(N+1)

for i in range(1,N+1):
    if visited[i]:
        continue
    link = {i}
    visited[i] = 1 
    stack.append(i)
    while stack:
        n = stack.pop()
        for j in f[n]:
            if visited[j]==0:
                stack.append(j)
                visited[j] = 1
                link.add(j)
    for i in link:
        ans[i] = len(link) - len(link & f[i]) - len(link & b[i]) - 1
print(*ans[1:])

Measured memory_bytes: 116832
#include <cstdio>
#include <vector>
static const int MAXN = 1e5 + 4;
static const int LOGN = 18;

int n;
std::vector<int> e[MAXN];

int ans = 0;
int f[MAXN];
void dfs_dp(int u, int p = -1)
{
    int mask = 0, label = 0;
    for (int v : e[u]) if (v != p) {
        dfs_dp(v, u);
        for (int i = label + 1; i < LOGN; ++i)
            if ((f[v] & (1 << i)) && (mask & (1 << i))) label = i;
        mask |= f[v];
    }
    //int label = 8 * sizeof(int) - __builtin_clz(f[u]) - 1;
    while (mask & (1 << label)) ++label;
    f[u] = (1 << label);
    for (int i = label + 1; i < LOGN; ++i)
        if (mask & (1 << i)) f[u] |= (1 << i);
    if (ans < label) ans = label;
}

int main()
{
    scanf("%d", &n);
    int u, v;
    for (int i = 0; i < n - 1; ++i) {
        scanf("%d%d", &u, &v); --u, --v;
        e[u].push_back(v);
        e[v].push_back(u);
    }

    dfs_dp(0);
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 11776
#include<iostream>
#include<string>
using namespace std;
 
int main(){
	long long n;
	long long s[4] = {0, 0, 0, 0};
	
	cin >> n;

	for(long long i = 0; i < n; i++){
		string p;
		cin >> p;
		if(p == "AC"){
			s[0] += 1;
		}else if(p == "WA"){
			s[1] += 1;
		}else if(p == "TLE"){
			s[2] += 1;
		}else if(p == "RE"){
			s[3] += 1;
		}
	}

	cout << "AC x " << s[0] << endl;
	cout << "WA x " << s[1] << endl;
	cout << "TLE x " << s[2] << endl;
	cout << "RE x " << s[3] << endl;
}


Measured memory_bytes: 3624
import java.util.Scanner;
public class Main{
    public static void main(String[]args){
	int i,j,c,kazu,csosu=0;
	Scanner sc = new Scanner(System.in);
	    i=sc.nextInt();
	for(j=0;j<i;j++){
	    kazu=sc.nextInt();
	    for(c=(int)Math.sqrt(kazu);c>1;c--){
		if(kazu%c==0){
		    csosu+=1;
		    break;
		}
	    } 
	}
	csosu=i-csosu;
	System.out.println(csosu);
    }
}




Measured memory_bytes: 42696
n,d= input().split(" ")
n=int(n)
d=int(d) 
count=0
for i in range(n):
  x,y= input().split(" ")
  x=int(x)
  y=int(y) 
  dist=((x**2) + (y**2))**0.5
  if dist<=d:
    count+=1
print(count) 

Measured memory_bytes: 9648
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (int i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define fi first
#define se second
#define int long long
using namespace std;
using ll = long long;
using II = pair<int, int>; using VII = vector<II>; using VVII = vector<VII>;
using VI = vector<int>; using VVI = vector<VI>; using VVVI = vector<VVI>;
template <class T = int> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T = int> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <class T> ostream& operator<<(ostream &s, const vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream &s, const vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream &s, const pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, const map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
constexpr int MOD = 1e9 + 7;

signed main() {
  int n, W; cin >> n >> W;
  VI w(n), v(n);
  REP (i, n) cin >> w[i] >> v[i];
  const int V = 100000;
  VI dp(V + 1, 1e18);
  dp[0] = 0;
  REP (i, n) {
    for (int j = V - 1; j >= 0; j--) {
      if (v[i] + j > V) continue;
      dp[v[i] + j] = min(dp[v[i] + j], dp[j] + w[i]);
    }
  }
  int ans = 0;
  REP (i, V + 1) {
    if (dp[i] <= W) {
      ans = max(ans, i);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstdio>
using namespace std;
typedef long long ll;

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

	ll ans = a + b > a - b ? (a + b > a*b ? a + b : a*b) : (a - b > a*b ? a - b : a*b);

	cout << ans << endl;
}

Measured memory_bytes: 256
import math
def prime():
    i = 3
    while i <= math.sqrt(n):
        if n % i == 0:
            return False
        i += 2
    return True

cnt = 0
for i in range(int(input())):
    n = int(input())
    if n == 2:
        cnt += 1
        continue
    elif n % 2 == 0: continue
    judge = prime()
    if judge == True:
        cnt += 1
print(cnt)



Measured memory_bytes: 5676
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> h(N),ans(N);
  for(int i=0;i<N;i++){
    cin >> h[i];
  }
  ans[1]=abs(h[1]-h[0]);
  
  for(int i=2;i<N;i++){
    ans[i]=min(ans[i-2]+abs(h[i]-h[i-2]),ans[i-1]+abs(h[i]-h[i-1]));
  }
  cout << ans[N-1];
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()
int main(){
    int K,N;cin>>K>>N;
    for(int i=N-K+1;i<N+K;i++){
        cout<<i<<" ";
    }
}

Measured memory_bytes: 3632
using System;
using System.Linq;

namespace TestApp
{
    class Program
    {
        static void Main(string[] args)
        {
            //var lists = Console.ReadLine()
            //        .Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries)
            //        .Select(x => int.Parse(x))
            //        .ToList();
            //var a = lists[0];
            //var b = lists[1];
            var n = int.Parse(Console.ReadLine());
            var lists = Console.ReadLine()
                .Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries)
                .Select(x => int.Parse(x))
                .ToList();
            var tar = 0; var su = 0;
            for (int i = 0; i < n + 1; i++)
            {
                if (i > n - 1)
                    su += Math.Abs(tar);
                else
                {
                    su += Math.Abs(lists[i] - tar);
                    tar = lists[i];
                }
            }

            for (int i = 0; i < n; i++)
            {
                int a;
                if (i == 0)
                    a = 0;
                else
                    a = lists[i -1];
                int b = lists[i];
                int c;
                if (i + 1 == n)
                    c = 0;
                else
                    c = lists[i + 1];
                int ab = Math.Abs(a - b);
                int bc = Math.Abs(b - c);
                int ac = Math.Abs(a - c);
                Console.WriteLine(su - ab - bc + ac);
            }
            Console.ReadLine();

        }
    }
}


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
  string S, T; cin >> S >> T;

  int N = S.length(), M = T.length();

  for (int i = N - M; i >= 0; i--){
    bool flag = true;
    for (int j = 0; j < M; j++){
      if (T[j] != S[i+j] && S[i+j] != '?') flag = false;
    }
    if (!flag) continue;

    for (int j = 0; j < M; j++) S[i+j] = T[j];
    for (int j = 0; j < N; j++){
      if (S[j] == '?') S[j] = 'a';
    }
    cout << S << endl;
    return 0;
  }

  cout << "UNRESTORABLE" << endl;

  return 0;
}


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

using C = complex<double>;
double pi = acos(-1.0);

void FFT(vector<C>& A, bool inv) {
 int N=A.size();
 for(int i=0,j=0; j<N; j++){
  if(i<j) swap(A[i],A[j]);
  for(int k=N>>1; k>(i^=k); k>>=1);
 }
 for(int i=1; i<N; i<<=1){
  C q = C(cos(pi/i),sin(pi/i)*(inv?1.0:-1.0));
  C qj = C(1.0,0.0);
  rep(j,i){
   for(int k=j; k<N; k+=i*2){
    C l=A[k], r=A[k+i]*qj;
    A[k]=l+r;
    A[k+i]=l-r;
   }
   qj*=q;
  }
 }
 if(inv) rep(i,N) A[i]/=N;
}

vector<C> CONV(const vector<C>& A,const vector<C>& B) {
 int Z=1; while(Z<A.size()+B.size()) Z<<=1;
 vector<C> Ax(Z),Bx(Z);
 rep(i,Z) Ax[i]=Bx[i]=0;
 rep(i,A.size()) Ax[i]=A[i];
 rep(i,B.size()) Bx[i]=B[i];
 FFT(Ax,false);
 FFT(Bx,false);
 rep(i,Z) Ax[i]*=Bx[i];
 FFT(Ax,true);
 return move(Ax);
}

const ULL M=200003;
int N;
ULL I[M];
vector<C> A;
vector<C> V;

int main() {
 scanf("%d", &N);
 for (int i=0,j=1; i<M-1; i++,j=j*2%M) I[j]=i;
 A.resize(M-1);

 ULL sq=0;
 rep(i, N) {
  int a; scanf("%d",&a);
  if(a) A[I[a]] += C(1.0,0.0);
  sq += (ULL)a*a%M;
 }
 V = CONV(A,A);

 ULL ans=0;
 for (int i=0,j=1; i<V.size(); i++,j=j*2%M)
  ans += (ULL)(V[i].real()+0.5)*j;
 ans = (ans-sq)/2;

 cout<<ans<<endl;

 return 0;
}


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

#define ONLINE_JUDGE
#define pb(a) push_back(a)
#define ALL(a) (a.begin(), a.end())
#define FOR(x,to) for(x=0;x<(to);x++)

using ll = long long;

const int E5 = 1e5;

//////////// Solution /////////////////////////////////

ll A[2*E5+1],B[2*E5+1];
ll N;

ll f(ll b) {
	ll res = 0;
	for (int i = 1; i <= N; ++i) {
		res += abs(A[i]-b-i);
	}

	return res;
} 

void solve() {
	cin >> N;
	for (int i = 1; i <= N; ++i) {
		cin >> A[i];
		B[i] = A[i]-i;
	}
	sort(B+1,B+N+1);
	cout << f(B[(1+N)/2]) << '\n';
}	

/////////// End Solution ///////////////////////////////////////

//////// Initialization ////////////////////////////////////

int main() {

	#ifndef ONLINE_JUDGE
	FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
	clock_t time_start = clock();
	#endif

	ios::sync_with_stdio(false);
	cin.tie(NULL);

	solve();

	#ifndef ONLINE_JUDGE
	fclose(FIN);
	cerr << "\x1b[031m\n-----------------\nTime=" << (ll)((double)(clock()-time_start) / CLOCKS_PER_SEC * 1000) << "ms\n\x1b[0m";
	#endif

	return 0;
}

	//////// End Initialization ///////////////////////////////////////

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

using pqg = priority_queue<ll,vector<ll>, greater<ll> >; // 1,3,5..
using pql = priority_queue<ll,vector<ll> >; //5, 3, 1...

using pqg_p = priority_queue<P,vector<P>, greater<P> >; // 1,3,5..
using pql_p = priority_queue<P,vector<P> >; //5, 3, 1...

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n) for(auto i=s, i##_len=(n); i<i##_len; ++i)

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define ALL(a)  (a).begin(),(a).end()

vector<P> v;

int dist(int i,int j) {
  return  (v[i].F -v[j].F) * (v[i].F -v[j].F) +(v[i].S -v[j].S) *(v[i].S -v[j].S);
}

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

  ll N;

  cin >> N;
  vector<ll> a;
  vector<ll> b;
  vector<ll> c;


  REP(i,N) {
    ll t;
    cin >> t;
    a.PB(t);
  }
  a.PB(1000000001);

  REP(i,N) {
    ll t;
    cin >> t;
    b.PB(t);
  }
  b.PB(1000000001);

  REP(i,N) {
    ll t;
    cin >> t;
    c.PB(t);
  }
  c.PB(1000000001);

  sort(ALL(a));
  sort(ALL(b));
  sort(ALL(c));

  vector<ll> po(N);


  ll t = 0;
  REP1(i, N+1) {
    t += c.end() - upper_bound(ALL(c), b[N-i]) - 1;
    po[N-i] = t;
  }


  ll ans=0;
  REP(i,N) {
    auto u = upper_bound(ALL(b), a[i]);
    if(*u ==  1000000001) break;
    ans += po[u - b.begin()];
  }
  

  cout << ans << endl;

}


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

using Vertex = size_t;
using Graph = vector<vector<Vertex>>;
template<typename T> using PropMap = vector<T>;

inline void addEdge(Graph& g, Vertex u, Vertex v) {
    g[u].push_back(v);
    g[v].push_back(u);
}

int main() {
    size_t n, m, k;
    cin >> n >> m >> k;
    Graph frends(n);
    for (size_t i = 0; i < m; i++) {
        Vertex a, b;
        cin >> a >> b;
        addEdge(frends, a - 1, b - 1);
    }
    Graph blocks(n);
    for (size_t i = 0; i < k; i++) {
        Vertex a, b;
        cin >> a >> b;
        addEdge(blocks, a - 1, b - 1);
    }
    PropMap<int> candidateCount(n);
    for (Vertex u = 0; u < n; u++) {
        if (candidateCount[u] == 0) {
            unordered_set<Vertex> visitedVertices;
            queue<Vertex> q;
            q.push(u);
            while(!q.empty()) {
                Vertex v = q.front();
                q.pop();
                if (visitedVertices.count(v) == 0) {
                    visitedVertices.emplace(v);
                    for (auto w : frends[v]) {
                        q.push(w);
                    }
                }
            }
            for (Vertex v : visitedVertices) {
                int count = visitedVertices.size() - 1;
                for (auto w : frends[v]) {
                    if (visitedVertices.count(w) != 0) {
                        count--;
                    }
                }
                for (auto w : blocks[v]) {
                    if (visitedVertices.count(w) != 0) {
                        count--;
                    }
                }
                candidateCount[v] = count;
            }
        }
        if (u != 0) {
            cout << " ";
        }
        cout << candidateCount[u];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 17816
import java.util.Scanner;

//import jdk.internal.org.jline.utils.InputStreamReader;

import java.io.*;

public class Main{
        public static void main(final String[] args){
            Scanner scanner = new Scanner(System.in);
            while(true){
                String string = scanner.nextLine();
                int length = string.length();
                int s = 0;
                for(int i = 0; i < length; i++){
                    char charx = string.charAt(i);
                    int x = charx - '0';
                    s += x;
                }
                if(s == 0){
                    break;
                }
                System.out.println(s);
            }
            scanner.close();
        }
         

}


Measured memory_bytes: 26452
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n,m = readline() |> split |> parseMap
	lr = Array{Int}(2,m)
	for i in 1:m
		lr[:,i] = readline() |> split |> parseMap
	end
	println(max(minimum(lr[2,:])-maximum(lr[1,:])+1,0))
end

main()

Measured memory_bytes: 155496
#include<iostream>
#include<cmath>
#include<string>
#include<map>
#include<queue>

using namespace std;
#define N 3
#define N2 9

struct Puzzle{
  int f[N2];
  int space;
  string path;

  bool operator < (const Puzzle &p) const{

    for(int i=0; i<N2; i++){
      if(f[i] == p.f[i]) continue;
      return f[i] > p.f[i];
    }
    return false;
  }
};

static const int dx[4] = {-1,0,1,0};
static const int dy[4] = {0,-1,0,1};
static const char dir[4] = {'u','l','d','r'};

bool isTarget(Puzzle p){

  for(int i=0; i<N2; i++)
    if(p.f[i] != (i+1)) return false;
  return true;
}

string bfs(Puzzle s){
  queue<Puzzle> Q;
  map<Puzzle,bool> V;
  Puzzle u,v;
  s.path = "";
  Q.push(s);
  V[s] = true;

  while(!Q.empty()){

    u = Q.front();
    Q.pop();

    if(isTarget(u)) return u.path;
    int sx = u.space/N;
    int sy = u.space%N;
    for(int r=0; r<4; r++){
      int tx = sx+dx[r];
      int ty = sy+dy[r];
      if(tx<0 || ty<0 || tx>=N || ty>=N) continue;
      v = u;
      swap(v.f[u.space],v.f[tx*N+ty]);
      v.space=tx*N+ty;
      if(!V[v]){
        V[v] = true;
        v.path += dir[r];
        Q.push(v);
      }
    }
  }

  return "unsolvable";

}

int main(){

  Puzzle in;

  for(int i=0; i<N2; i++){
    cin >> in.f[i];
    if(in.f[i] == 0){
      in.f[i] = N2;
      in.space = i;
    }
  }
  string ans = bfs(in);
  cout << ans.size() << endl;

  return 0;

}


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

int main(){
    string S;
  	cin >> S;
  	string T;
  	cin >> T;
  	
  	if(S == T.substr(0, T.size()-1))
        cout << "Yes" <<endl;
  	else
        cout << "No" <<endl;
}

Measured memory_bytes: 3596
def sign(i)
  return 1 if i.positive? || i == 0
  -1
end

def sequence(n, arr)
  a = arr
  b = [ a[0] ]
  count = 0

  (n-1).times do |i|
    b[i+1] = b[i] + a[i+1]
    if b[i+1] == 0
      if b[i] > 0
        a[i+1] -= 1
        count += 1
      else
        a[i+1] += 1
        count += 1
      end
    elsif sign(b[i]) == sign(b[i+1])
      if b[i].positive?
        count += (a[i+1] - (-b[i] - 1)).abs
        a[i+1] = -b[i] - 1
        b[i+1] = b[i] + a[i+1]
      else
        count += (a[i+1] - (-b[i] + 1)).abs
        a[i+1] = -b[i] + 1
        b[i+1] = b[i] + a[i+1]
      end
    end
  end

  count
end

n = gets.chomp.to_i
a = gets.chomp.split.map { |item| item.to_i }
a2 = Marshal.load(Marshal.dump(a))
pn_count = 0

if a[0] > 0
  a2[0] = a[0] - a[0] - 1
  np_count = a[0].abs + 1
elsif a[0] < 0
  a2[0] = a[0] - a[0] + 1
  np_count = a[0].abs + 1
else
  a[0] = 1
  pn_count = 1
  a2[0] = -1
  np_count = 1
end

pn_count += sequence(n, a)
np_count += sequence(n, a2)

puts pn_count < np_count ? pn_count : np_count


Measured memory_bytes: 14684
#include <cstdio>
#include <iostream>

using namespace std;

int main(){
  while(true){
    int N, score[] = {0, 0};
    scanf("%d", &N);
    if(N == 0)
      return 0;

    for(int i = 0; i < N; i++){
      int a, b;
      cin >> a >> b;
      if(a > b)
        score[0] += a + b;
      else if(a < b)
        score[1] += a + b;
      else{
        score[0] += a;
        score[1] += b;
      }
    }
    printf("%d %d\n", score[0], score[1]);
  }
}

Measured memory_bytes: 1228
#include <algorithm>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, l; cin >> n >> l;
  vector<string> s(n); REP(i, n) cin >> s[i];
  sort(ALL(s));
  REP(i, n) cout << s[i];
  cout << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<cmath>
#include<string>

#define ls (t<<1)
#define rs ((t<<1)+1)
#define mid ((l+r)>>1)
#define fi first
#define se second
#define mk make_pair
#define pb push_back

#define N 100005
#define M 200005
#define seed 23333

using namespace std;
pair<int,int>F[N],T[N];
int i,j,m,n,p,k,root,fa[N],G[N],flag,x,y;
vector<int>v[N];
void dfs(int x,int l,int r)
{
		if (G[x]!=-1&&(G[x]<l||G[x]>r||((G[x]-l)&1))) flag=1;
		if (G[x]!=-1) l=G[x],r=G[x];
		F[x]=T[x]=mk(l,r);
		int i;
		for (i=0;i<(int)v[x].size();++i)
		{
				int p=v[x][i];
				if (fa[x]==p) continue;
				fa[p]=x;
				dfs(p,l-1,r+1);
				T[x].fi=max(T[x].fi,T[p].fi-1),T[x].se=min(T[x].se,T[p].se+1);
		}
}
void Dfs(int x,int r)
{
		G[x]=r;
		int i;
		for (i=0;i<(int)v[x].size();++i)
		{
				int p=v[x][i];
				if (fa[x]==p) continue;
				if (T[p].fi<=r-1&&r-1<=T[p].se) Dfs(p,r-1);
				else Dfs(p,r+1);
		}		
}
int main()
{
	scanf("%d",&n);
	memset(G,-1,sizeof(G));
	for (i=1;i<n;++i)
	{
			scanf("%d%d",&x,&y);
			v[x].pb(y); v[y].pb(x);
	}
	scanf("%d",&k);
	for (i=1;i<=k;++i)
	{
			scanf("%d%d",&x,&y);
			G[x]=y;
			root=x;
	}
	dfs(root,G[root],G[root]);
	if (flag) puts("No");
	else 
	{
			puts("Yes");
			Dfs(root,G[root]);
			for (i=1;i<=n;++i) printf("%d\n",G[i]);
	}
}


Measured memory_bytes: 16512
package main

import (
	"fmt"
)

func main() {

	var N int
	fmt.Scan(&N)

	x := make([]float64, N)
	u := make([]string, N)

	for i := 0; i < N; i++ {
		fmt.Scan(&x[i], &u[i])
	}

	total := 0.0

	for i := 0; i < N; i++ {
		if u[i] == "JPY" {
			total += x[i]
		} else if u[i] == "BTC" {
			total += x[i] * 380000.0
		}
	}

	fmt.Printf("%10.8f\n", total)

}


Measured memory_bytes: 512
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		String S = sc.next();

		sc.close();

		if (S.matches("A?KIHA?BA?RA?")) {
			out.println("YES");
		} else {
			out.println("NO");
		}

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

}


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

int main(void)
{
    int n;
    int score_taro = 0;
    int score_hanako = 0;

    scanf("%d", &n);

    for ( int i = 0; i < n; i++ ) {
        char str_taro[101] = {0};
        char str_hanako[101] = {0};
        scanf("%s %s", str_taro, str_hanako);
        if ( strcmp(str_taro, str_hanako) > 0 ) {
            score_taro += 3;
        } else if ( strcmp(str_taro, str_hanako) < 0 ) {
            score_hanako += 3;
        } else {
            score_taro++;
            score_hanako++;
        }
    }

    printf("%d %d\n", score_taro, score_hanako);

    return 0;
}


Measured memory_bytes: 2040
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const int MOD = 1000000007;
using namespace std;

int main(){
    int n, m; cin >> n >> m;
    cout << (n-1) * (m-1) << "\n";
    return 0;
}

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

#define rep(i, a, b) for (int i = (a); i < (b); i++)

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

  vector<bool> f(n);
  rep(i, 0, n)
  {
    int a, b;
    cin >> a >> b;
    f[i] = a == b;
  }

  rep(i, 2, n)
  {
    if (f[i] and f[i - 1] and f[i - 2])
    {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define mem(dp,a) memset(dp,a,sizeof(dp))
#define pb(x) push_back(x)
#define m_p(x,y) make_pair(x,y)
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repush_back(i,a,b) for(ll i=a;i>=b;i--)
#define f(n) for(ll i=0;i<n;i++)
#define r(n) for(ll j=0;j<n;j++)
#define F first
#define S second
#define pi 3.14159265359
#define hs ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
typedef long long int ll;
ll HRX=1e18;
ll INF=1e9+7;

int main()
{
 hs;
 ll n;
 cin>>n;
 ll a[n];
 ll pre[n];
 f(n)
 {
  cin>>a[i];
 }
 pre[n-1]=0;
 for(ll i=n-2;i>=0;i--)
 {
  if(a[i]>=a[i+1])
    pre[i]=pre[i+1]+1;
  else
  pre[i]=0;

 }
 sort(pre,pre+n);
 ll ans=pre[n-1];
 cout<<ans<<endl;
 return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h> 
using namespace std; 
typedef  pair<int, int> iPair; 
//#define mod 1000000007
#define pb push_back
typedef long long ll;
typedef long double ld;
#define FOR(i,n) for(i=0;i<n;i++)
#define FORE(i,n) for(i=0;i<=n;i++)
 
 
ll gcd(ll a , ll b)
{
   if(b==0) return a;
   a%=b;
   return gcd(b,a);
   
}
    
ll maxl(ll a,ll b){
    if(a>b)return a;
    return b;
}
 
ll minl(ll a,ll b){
    if(a>b)return b;
    return a;
}
 
ll mod = 998244353;
 
ll mulmod(ll a, ll b,ll c){ 
    ll res = 0; 
    a = a % c; 
    while (b > 0){ 
        if (b % 2 == 1){ 
            res = (res + a) % c;
        }
        a = (a * 2) % c; 
        b /= 2; 
    } 
    return res % c; 
}
 
int binarySearch(int arr[], int l, int r, int x) 
{ 
    if (r >= l) { 
        int mid = l + (r - l) / 2; 
        if (arr[mid] == x) 
            return mid; 
        if (arr[mid] > x) 
            return binarySearch(arr, l, mid - 1, x); 
        return binarySearch(arr, mid + 1, r, x); 
    } 
    return -1; 
} 
 
int a[100005];
int tree[200005];
 
void build(int st,int low,int high){
    if(low==high){
        tree[st] = a[high]%2;
        return;
    }
    int mid = low+(high-low)/2;
    build(2*st,low,mid);
    build(2*st+1,mid+1,high);
    tree[st] = tree[2*st]+tree[2*st+1];
}
 
void update(int st,int start,int end,int ind,int val){
    if(start==end){
        tree[st] = val%2;
        return;
    }
    int mid = start+(end-start)/2;
    if(ind<=mid){
        update(2*st,start,mid,ind,val);
    }
    else update(2*st+1,mid+1,end,ind,val);
    tree[st] = tree[2*st]+tree[2*st+1];
}
 
int query(int st,int start,int end,int low,int high){
    if(start>high || end<low)return 0;
    int mid = start + (end-start)/2;
    if(start==low && end==high){
        return tree[st];
    }
    if(low>mid)return query(2*st+1,mid+1,end,low,high);
    if(high<=mid)return query(2*st,start,mid,low,high);
    return query(2*st,start,mid,low,mid)+query(2*st+1,mid+1,end,mid+1,high);
}

int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL),cout.tie(NULL);
        string t,s;
        cin >> s >> t;
        int ans = 0;
        for(int i=0;i<s.length();i++){
            if(s[i]==t[i])ans++;
        }
        cout << ans << endl;
        return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    int X[100010];
    rep(i, M) cin >> X[i];
    int diff[100010];
    sort(X, X + M);
    rep(i, M - 1) diff[i] = X[i + 1] - X[i];
    int ans = 0;
    sort(diff, diff + M - 1);
    rep(i, M - N) ans += diff[i];
    cout << ans << endl;



    return 0;
}


Measured memory_bytes: 1792
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
typedef int64_t i64;
static inline void MAZ(int &a, int b) {if(a < b) a = b;}
static inline void MIZ(int &a, int b) {if(b < a) a = b;}

static const auto NMAX = 200000;

static int N, A[NMAX], P[NMAX];
static int boz[NMAX], siz[NMAX], lef[NMAX], rig[NMAX];

static int find(int x) {
	return boz[x] == x ? x : (boz[x] = find(boz[x]));
}

static void merge(int a, int b) {
	a = find(a);
	b = find(b);
	if(siz[a] < siz[b]) swap(a, b);
	boz[b] = a;
	siz[a] += siz[b];
	MIZ(lef[a], lef[b]);
	MAZ(rig[a], rig[b]);
}

int main() {
	scanf("%d", &N);
	for(auto i = 0; i < N; i++) {
		int x;
		scanf("%d", &x); x--;
		A[i] = x;
		P[x] = i;
	}
	for(auto i = 0; i < N; i++) boz[i] = i;
	for(auto i = 0; i < N; i++) siz[i] = 1;
	for(auto i = 0; i < N; i++) lef[i] = i;
	for(auto i = 0; i < N; i++) rig[i] = i;
	i64 ret = 0;
	for(auto i = N; --i >= 0; ) {
		auto p = P[i];
		if(p - 1 >= 0 && A[p - 1] > i) merge(p, p - 1);
		if(p + 1 <  N && A[p + 1] > i) merge(p, p + 1);
		auto q = find(p);
		ret += (i64)(i + 1) * (p - lef[q] + 1) * (rig[q] - p + 1);
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 114514
int main(){
    int h[MAX],n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++)cin>>h[i];
    sort(h,h+n);
    int ans=INT_MAX;
    for(int i=0;i<n-k+1;i++) ans=min(ans,h[i+k-1]-h[i]);
    cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = pow(10, 9) + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << endl; exit(0);}

int main()
{
  ll A, B;
  cin >> A >> B;
  vector<ll> P, Q;

  for (ll n = 2; n * n <= A; n++)
  {
    ll N = n;
    if (A % N == 0)
      P.push_back(N);
    while (A % N == 0)
    {
      A /= N;
    }
  }
  if (A != 1)
    P.push_back(A);

  for (ll n = 2; n * n <= B; n++)
  {
    ll N = n;
    if (B % N == 0)
      Q.push_back(N);
    while (B % N == 0)
    {
      B /= N;
    }
  }
  if (B != 1)
    Q.push_back(B);

  vector<ll> R;
  for (ll i = 0; i < P.size(); i++)
  {
    if (binary_search(Q.begin(), Q.end(), P.at(i)))
      R.push_back(P.at(i));
  }

  /*
  for (ll i = 0; i < R.size(); i++)
  {
    cerr << R.at(i) << endl;
  }
  */

  ll ans = 1 + R.size();
  cout << ans << endl;
}

Measured memory_bytes: 256