akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int n,k,a[55],arr[55],pre,ans[5555],cnt;
priority_queue<pair<int,int> > pq;
pair<int,int> cur,curr;
int main()
{
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=n;i++)
	{
		pq.push(make_pair(-a[i],i)); 
	}
	for (int i=1;i<=k;i++)
	{
		cur=pq.top();pq.pop();
		if (cur.second==pre)
		{
			curr=pq.top();
			pq.pop();
			pq.push(cur);
			cur=curr; 
		}
		arr[i]=cur.second;
		cur.first--;
		pq.push(cur);
		pre=arr[i];
	}
	cur=pq.top();
	if (cur.first>-k-1) 
	{
		printf("-1\n");
		return 0;
	}
	for (int i=1;i<=k;i++)
	{
		for (int j=1;j<=n;j++)
		{
			if (j!=arr[i-1] && j!=arr[i]) ans[++cnt]=j;
		}
		ans[++cnt]=arr[i];
	}
	for (int i=1;i<=n;i++)
	{
		if (i!=arr[k]) ans[++cnt]=i;
	}
	printf("%d\n",cnt);
	for (int i=1;i<=cnt;i++) printf("%d ",ans[i]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <cstdio>
#include <deque>
#include <cmath>
#include <stack>
#include <ctime>
#include <queue>
#include <set>
#include <map>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
#define nl '\n'
 
#define y1 aza_ibagaliev
 
#define f first
#define s second
#define X first
#define Y second
#define MP make_pair
	
#define ed end()
#define bg begin()
#define rbg rbegin()
 
#define rv reverse
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define ppf pop_front
 
#define sz size()
#define all(x) x.bg, x.ed
 
#define pll pair < ll, ll >
#define pii pair < int, int >
 
#define sqr(x) ((x) * 1ll * (x))
#define sqrd(x) ((x) * 1.0 * (x))
 
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
 
#define rnl cout << "----------------------------------------" << nl
 
#define bit __builtin_popcount
 
inline ll bip(ll x, ll n, ll mod){ll res=1;while(n){if(n & 1){res=(res*x)%mod;}x=(x*x)%mod;n>>=1;}return res;}
 
const int ppr[] = {257, 263};
const ll INF = 2e18;
const int inf = 2e9;
const int mod[] = {int(1e9 + 7), int(1e9 + 9)};
const int N = 1e6 + 123;
const ld pi = 3.141592653589793238462643;
 
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

ll n, a, b, c, m, u[N], d[N], timer;

void upd(ll mask, ll x) {
	if(u[mask] == timer) return;
	u[mask] = timer;
	d[mask] = min(d[mask], x);
	for(ll i = 0; i < n; i++)
		if(mask & (1<<i))
			upd((mask^(1<<i)), x);
}

ll dp[N];

main() {             	
//  freopen(".in", "r", stdin);                          
//  freopen(".out", "w", stdout);
 
//	srand(time(NULL));
	
	speed;

	cin >> n >> m;

	for(ll i = 0; i < (1<<n); i++)
		d[i] = INF;
	d[0] = 0;

	for(ll i = 1; i <= m; i++) {
		ll mask = 0;
		cin >> a >> b;
		while(b--) {
			cin >> c;
			c--;
			mask ^= (1<<c);
		}
		timer++;
		upd(mask, a);
	}

	for(int i = 0; i < (1<<n); i++) {
		dp[i] = d[i];
	}

 	for(int i = 0; i < (1<<n); i++)
 		for(int j = 0; j < (1<<n); j++)
 			dp[(i | j)] = min(dp[(i | j)], dp[i] + dp[j]);

  	if(dp[(1<<n)-1]==INF) dp[(1<<n)-1] = -1;
	cout << dp[(1<<n)-1];
 	                              	
    return 0;
}  


Measured memory_bytes: 4352
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Math;
using static System.Console;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        solve();
    }
    static Scanner cin;
    static int N;
    static int[] A, B, C;

    static void input()
    {
        cin = new Scanner();
        N = cin.nextInt();
        A = ReadLine().Split(' ').Select(int.Parse).Select(x => x - 1).ToArray();
        B = cin.ArrayInt(N);
        C = cin.ArrayInt(N - 1);
    }
    static void solve()
    {
        input();

        int ans = 0;

        for (int i = 0; i < N - 1; i++)
        {
            ans += B[A[i]];
            if (A[i] == A[i + 1] - 1)
                ans += C[A[i]];
        }
        ans += B[A[N - 1]];
        WriteLine(ans);
    }
    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }
        
        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }

        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for(int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for(int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }

        public double[] ArrayDounble(int N, int add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
int main(){
    //write code  here

    long N,M;
    cin >> N >> M;
    vector<long>H(N);
    vector<bool>isGood(N);

    for (int i = 0; i < N; ++i) {
        cin >> H.at(i);
        isGood.at(i) = true;
    }

    for (int i = 0; i < M; ++i) {
        int a,b;
        cin >> a >> b;
        a--;b--;
        if(H.at(a) > H.at(b)){
            isGood.at(b) = false;
        }else if(H.at(a) < H.at(b)){
            isGood.at(a) = false;
        } else{
            isGood.at(a) = false;
            isGood.at(b) = false;
        }
    }
    sort(isGood.begin(),isGood.end(),greater<bool>());
    int i = 0;
    int ans = 0;
    while(isGood.at(i)){
        ans++;
        i++;
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 4056
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <deque>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()
#define INF 1000000000

struct edge { int to, cost; };
int K;

vector<edge> G[100000];
int d[100000];

void make_graph() {
    REP(i, K) {
        G[i].push_back({(i + 1) % K, 1});
        G[i].push_back({(i * 10) % K, 0});
    }
    fill(d, d + K, INF);
}

int main() {
    cin >> K;
    make_graph();

    deque<edge> q;
    q.push_back({1, 1});
    while (d[0] == INF) {
        int v = q.front().to, c = q.front().cost; q.pop_front();
        if (d[v] != INF) continue;
        for (edge e : G[v]) {
            if (e.cost == 0) q.push_front({e.to, c});
            else             q.push_back({e.to, c + 1});
        }
        d[v] = c;
    }
    cout << d[0] << endl;
    return 0;
}

Measured memory_bytes: 6912
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
#include <numeric>
using namespace std;

using Input = pair<int, int>;

int main()
{
	string result = "safe";
	long X, A, B;
	cin >> X >> A >> B;

	if ( X < B - A )
		result = "dangerous";
	else if (B <= A)
		result = "delicious"; 

	cout << result << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.PrintStream;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);




	public static void main(String[] args) throws Exception {

		String str=sc.nextLine();
		System.out.println(str.indexOf("AC")<0?"No":"Yes");

	}


}

Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

typedef unsigned long long ull;
typedef long long ll;
typedef double db;

#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define pi pair<int,int>
#define vi vector<int>
#define pL pair<ll,ll>
#define vL vector<ll>
#define vp vector<pi>
#define vpL vector<pL>

const int MX=2500000;
const ll inf=1e9;
const ll mod=1e9+7;

ll a[22][22];
ll dp[22][MX], n;

ll call(ll i, ll msk)
{
    if(msk==((1LL<<n)-1LL)) return 1;
    if(~dp[i][msk])   return dp[i][msk];
    ll sm=0;
    for(int j=0; j<n; j++)
    {
        if((msk&(1LL<<j))==0 && a[i][j])
        {
            sm=(call(i+1,msk|(1LL<<j))+sm)%mod;
        }
    }
    return dp[i][msk]=sm;
}
int main()
{
    FasterIO;

    cin>>n;
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
        {
            cin>>a[i][j];
        }
    }
    mem(dp, -1);
    ll r=call(0, 0);
    cout<<r<<endl;
    return 0;
}


Measured memory_bytes: 429952
#include<bits/stdc++.h>
#define F(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RF(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define MIN3(a,b,c) (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c))
#define MAX(a,b) (a)>(b)?(a):(b)
#define MIN2(a,b) (a)<(b)?(a):(b)
using namespace std;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
#define ull unsigned long long
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> lll;
#define deb(x )     cerr << #x << " here "<< x << endl;
#define endl    "\n"
#define printCase() "Case #" << caseNum << ": "
inline bool is_palindrome(const string& s){ return std::equal(s.begin(), s.end(), s.rbegin()); }
const ll MOD = 1000000007;
const ll INF = 1e9+5;
const double eps = 1e-7;
const double PI = acos(-1.0);
#define coud(a,d) cout << fixed << showpoint << setprecision(d) << a;
inline void debug_vi(vi a) {F(i, 0, a.size()) cout<<a[i]<<" ";}
inline void debug_vll(vll a) {F(i, 0, a.size()) cout<<a[i]<<" ";}
/*----------------------------------------------------------------------*/

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

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int a,b,k;
    cin>>a>>b>>k;

    vi divs;
    F(i, 1, min(a,b)+1) {
    	if(a % i == 0 && b % i == 0) {
    		divs.push_back(i);
    	}
    }

    reverse(divs.begin(), divs.end());
    cout<<divs[k-1];

    return 0;
}/*

*/

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

using namespace std;
using ll = long long;

int main(int argc, const char *argv[]) {
  ll n, m, k;
  cin >> n >> m >> k;

  vector<ll> va(n), vb(m);
  for (int i = 0; i < n; ++i) {
    cin >> va[i];
  }

  for (int i = 0; i < m; ++i) {
    cin >> vb[i];
  }

  vector<ll> csum_a{0}, csum_b;
  partial_sum(va.begin(), va.end(), back_inserter(csum_a));
  partial_sum(vb.begin(), vb.end(), back_inserter(csum_b));

  ll ans = 0;

  // aからi冊読む
  for (int i = 0; i <= va.size(); ++i) {
    ll a_sum = csum_a[i];
    if (a_sum > k) {
      break;
    }

    ll l_ans = i;
    ll remain = k - a_sum;
    auto it =
        lower_bound(csum_b.rbegin(), csum_b.rend(), remain, greater<ll>());
    ll dist = m - distance(csum_b.rbegin(), it);
    l_ans += dist;
    ans = max(ans, l_ans);
  }

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 11028
####### 二項係数 C(n,k) mod pの計算 #######

MOD=10**9+7

## a**b mod p by 繰り返し二乗法 ##
def pow(a,b)
  return 1 if b==0
  return a*pow(a,b-1)%MOD if b%2==1
  return pow(a**2%MOD,b/2)
end

## n! mod p ##
def fact(n)
  ret=1
  n.times do |i|
    ret=ret*(i+1)%MOD
  end
  ret
end

## a**(-1) mod p ##
def inv(n)
  pow(n,MOD-2)%MOD
end

## C(n,k) mod p ##
def com(n,k)
  (fact(n)*inv(fact(k)))%MOD*inv(fact(n-k))%MOD
end

## C(n,k) mod p (n>>>k version) ##
def frac(n,k)
  a=1
  b=1
  k.times do |i|
    b*=i+1
    b%=MOD
  end
  k.times do |i|
    j=i+1
    a*=n-i
    a%=MOD
  end
  a*inv(b)%MOD
end

##########################################

N,A,B=gets.split.map(&:to_i)
ans=pow(2,N)-1
ans+=MOD-frac(N,A)
ans+=MOD-frac(N,B)
puts ans%MOD

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

int a[1] = {1};
int b[6] = {6, 36, 216, 1296, 7776, 46656};
int c[5] = {9, 81, 729, 6561, 59049};

int main(){
  int n; cin >> n;
  vector<long long> v(n+1, 1e9); v[n] = 0;
  for (int i = n; i >= 0; i--) {
    if (i - 1 >= 0) v[i-1] = min(v[i] + 1, v[i-1]);
    for (int j = 0; j < 6; j++) {
      if (i - b[j] < 0) break;
      v[i-b[j]] = min(v[i]+1, v[i-b[j]]);
    }
    for (int j = 0; j < 5; j++) {
      if (i - c[j] < 0) break;
      v[i-c[j]] = min(v[i]+1, v[i-c[j]]);
    }
  }
  cout << v[0] << endl;
  return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int i,x,y;
	cin >> x;
	for(i=0; i<=x; ++i){
		y = i*108; y /= 100;
		if(x==y){
			cout << i << endl;
			return 0;
		}
	}
	cout << ":(" << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		List<Integer> list1 = new ArrayList<>();
		for(int i = 0; i<3; i++){
		    int a = sc.nextInt();
			list1.add(a);
		}
		Collections.sort(list1);
		System.out.println(list1.get(2)*10+list1.get(0)+list1.get(1));
	}
}

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

int check(int n){
  int sum=0;
  while(n>0){
    sum += n%10;
    n /= 10;
  }
  return sum;
}

int main(){
  int N,A,B,sum;
  cin >>N>>A>>B;
  sum = 0;
  
  int Ns[N];
  for(int i=0;i<N;i++){
    Ns[i] = i + 1;
  }
  for(int i=0;i<N;i++){
    int checkSum = 0;
    checkSum = check(Ns[i]);
    //cout<<Ns[i]<<":"<<checkSum<<endl;
    if(A<= checkSum && checkSum<=B){
      //cout<<Ns[i]<<endl;
      sum += Ns[i];
    }
  }
  cout<<sum;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)
 
#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>
 
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert
 
using namespace std;
 
int n,U,V;
vector<vi> adj;
 
vector<pi> save;
 
void dfs(int v, int par, int dist){
    if (adj[v].size()==1){
        save.emplace_back(v, dist);
    }
    for(auto u:adj[v]){
        if (par!=u){
            dfs(u, v, dist+1);
        }
    }
}
 
//-------------------------------------------------
 
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n>>U>>V;
    adj.resize(n+1);
    rep(i,n-1){
        int a,b; cin>>a>>b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    dfs(U,0,0);
    int sz = save.size();
 
    //青木くんからのbfs
    vi aDist(n+1,1000000);
    aDist[V] = 0;
    queue<int> Q;
    Q.push(V);
    while(Q.size()){
        int v = Q.front(); Q.pop();
        for(auto u:adj[v]){
            if (aDist[u]==1000000){
                aDist[u] = aDist[v]+1;
                Q.push(u);
            }
        }
    }
 
    int maxi=-1;
    rep(i,sz){
        int v, dist;
        tie(v,dist) = save[i];
        if (aDist[v]>dist && aDist[v]>maxi){
            maxi = aDist[v];
        }
    }
    cout<<maxi-1<<endl;
    return 0;
}

Measured memory_bytes: 9472
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {
            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }
        

        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
        
         
            var input =Reads();
            var n = input[0];
            var k = input[1];
            long anwer = k;
            int i = 1;
            while (i<n)
            {
                anwer *= k - 1;i++;
            }
            Console.WriteLine(anwer);
          
            

            Console.Out.Flush();
        }
    }
}


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

using ll = long long;

#define for_(i,a,b) for(int i = (a);i < (b);i++)
#define rfor_(i,a,b) for(int i = (b)-1;i >= (a);i--)
#define rep(i,n) for_(i,0,(n))
#define rrep(i,n) rfor_(i,0,(n))

const int mx = 100005;

int N, K;

int s, t, l, c;

int a[mx], b[mx];

int main(){
	cin.tie(0);
	
	cin>>N>>K;
	
	rep(i, N)cin>>a[i];
	
	l = N+1;
	
	while(s<N) {
		if(s>0) {
			if(a[s-1]<=K && --b[a[s-1]] == 0)c--;
		}
		while(t<N) {
			if(c==K)break;
			if(a[t]<=K && b[a[t]]++ == 0)c++;
			t++;
		}
		if(c<K)break;
		if(c==K && l>t-s)l = t-s;
		s++;
	}
	
	cout<<(l>N?0:l)<<endl;
	
	return 0;
}



Measured memory_bytes: 3868
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/






int D;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> D;

    printf("Christmas");
    int c = 25 - D;
    rep(i, 0, c) printf(" Eve");
    printf("\n");
}


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

l = list(map(int,input().split()))

dic = {}

for i in l:
    if not i in dic:
        dic[i] = 1
    
    else:
        dic[i] += 1

comb = 0

for v in dic.values():
    comb += int(v*(v-1)/2)

for i in l:
    print(comb-dic[i]+1)


Measured memory_bytes: 26268
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;

int main(){
    int h, w;
    scanf("%d%d", &h, &w);
    char c[h][w];
    rep(i, h)rep(j, w) scanf(" %c", &c[i][j]);
    int d[h][w];
    rep(i, h)rep(j, w) d[i][j] = 1e7;
    int dx[4] = {0, 1, 0, -1};
    int dy[4] = {1, 0, -1, 0};
    queue<ppi> que;
    rep(i, h)rep(j, w)if(c[i][j] == '#'){
        d[i][j] = 0;
        que.push(ppi(pii(i, j), 0));
    }
    while(!que.empty()){
        ppi p = que.front(); que.pop();
        int x = p.fi.fi;
        int y = p.fi.se;
        int td = p.se;
        if(td > d[x][y]) continue;
        rep(i, 4){
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(0<=nx && nx<h && 0<=ny && ny<w && d[nx][ny]> d[x][y] + 1){
                d[nx][ny] = d[x][y] + 1;
                que.push(ppi(pii(nx, ny), d[nx][ny]));
            }
        }
    }
    int ans = 0;
    rep(i, h)rep(j, w) ans = max(ans, d[i][j]);
    printf("%d\n", ans);
}

Measured memory_bytes: 17168
import math
def P(n, r):
    return math.factorial(n)//math.factorial(n-r)
def C(n, r):
    return P(n, r)//math.factorial(r)
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    def group_count(self):
        return len(self.roots())
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M = map(int, input().split())
uf = UnionFind(N)
query = [list(map(int, input().split())) for _ in range(M)]
ans = C(N,2)
ans_arr = [0]*M
ans_arr[M-1] = ans
for i in range(M-1):
    A, B = query[M-1-i][0]-1, query[M-1-i][1]-1
    if not uf.same(A,B):
        ans -= uf.size(A) * uf.size(B)
    ans_arr[M-2-i] = ans
    uf.union(A,B)
for i in ans_arr:
    print(i)

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

using namespace std;

#define endl '\n'
#define Opy ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)

typedef long long ll;

int main()
{
    //Opy;

/*-------------------------------------------------
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
-------------------------------------------------*/
    ll a, h = 0;

    cin>> a;

    h += (a - (a % 500)) * 2;

    a %= 500;

    h += a - (a % 5);

    cout<< h<< endl;

    return 0;
}



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


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    if (S.length() % 2 != (S[0] == S[S.length()-1])) {
        cout << "First" << endl;
    } else {
        cout << "Second" << endl;
    }

    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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;
}

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

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

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

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------
int main(){
string s;
cin>>s;
string t=s;
ll k;
cin>>k;
set<string>ans;
sort(t.begin(),t.end());
    for(int j=0;j<s.size();j++){
            for(int k=1;k<=5;k++){
                if(j+k<=s.size()){
                ans.insert(s.substr(j,k));
                }
            }
        }
auto itr=ans.begin();
for(int i=0;i<k-1;i++){
    itr++;
}
cout<<*itr<<endl;

}






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

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}




int main()
{
    init();
    int n,a=0,b=0,c=0,d=0;
    cin>>n;
    string s;
    for(int i=0 ;i<n ;i++){
        cin>>s;
        if(s=="AC") a++;
        else if(s=="WA") b++;
        else if(s=="TLE") c++;
        else if(s=="RE") d++;
    }
    cout<<"AC x "<<a<<endl;
    cout<<"WA x "<<b<<endl;
    cout<<"TLE x "<<c<<endl;
    cout<<"RE x "<<d<<endl;

}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
typedef long long int ll;
using namespace std;

int main()
{
  int n,x;
  cin >> n >> x;
  int cnt = 1;
  int d = 0;
  int l;
  REP(i,n){
    cin >> l;
    d += l;
    if(d<=x) cnt++;
    else break;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
//const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
//inline int in() { int x; scanf("%d",&x); return x;}
template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
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; }

int main () {
  string s;
  cin >> s;
  if (s == "AAA" || s == "BBB") cout << "No" << endl;
  else cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
n1 = input()
A = map(int, raw_input().split())

n2 = input()
q = map(int, raw_input().split())

list = set()

def solve(i,m):
 if m == 0:
  return True
 if i >= n1 or m > sum(A):
  return False
 res = solve(i+1,m) or solve(i+1,m-A[i])
 return res

for m in q:
 if solve(0,m):
  print "yes"
 else:
  print "no"

Measured memory_bytes: 6444
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
int A[MAX_N];
ll ans = 0;

void solve() {
	cin >> N;
	rep(i, 0, N) {
		cin >> A[i];
	}
	ans += A[0] - 1;
	A[0] = 1;
	int at = 1;
	rep(i, 0, N) {
		if(A[i] <= at) continue;
		if(A[i] == at + 1) {
			at++;
		}
		else {
			ans += (A[i] - 1) / (at + 1);
			// debug(i, at, A[i], (A[i] - at) / (at + 1));
		}
	}
	cout << ans << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 640
#pragma GCC optimize("O2")
#pragma G++ optimize("O2")
#include<cstdio>
#include<algorithm>
#include<map>
#define ll long long
#define For(i,x,y)  for(ll i=x;i<=y;++i)
#define FOr(i,x,y)  for(ll i=x;i>=y;--i)
#define lf else if
using namespace std;
inline ll read(){   ll x=0,f=1;char ch=getchar();   while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}  while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}  return x*f; } 
inline void write(ll x){    if (x<0) putchar('-'),x=-x; if (x>=10) write(x/10);   putchar(x%10+'0');  } 
inline void writeln(ll x){ write(x);   puts("");   }
map<ll,ll>mp;
ll n,ans;
int main(){
	n=read();
	For(i,1,n){
		ll x=read();
		if (mp[x])	mp[x]^=1,ans--;
		else	mp[x]^=1,ans++;
	}writeln(ans);
}

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

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

  if (N < 2) cout << 1 << endl;
  else if (N < 4) cout << 2 << endl;
  else if (N < 8) cout << 4 << endl;
  else if (N < 16) cout << 8 << endl;
  else if (N < 32) cout << 16 << endl;
  else if (N < 64) cout << 32 << endl;
  else cout << 64 << endl;
}

Measured memory_bytes: 256
//ios::sync_with_stdio(false);
#include<bits/stdc++.h>
#define LL long long
#define F(x,y,z) for(int x=y;x<=z;++x)
#define D(x,y,z) for(int x=y;x>=z;--x)
#define ckmax(a,b) (a)=max(a,b)
#define ckmin(a,b) (a)=min(a,b)
#define pb push_back
using namespace std;
LL R(){
    LL ans=0,f=1;char c=getchar();
    for(;c<'0'||c>'9';c=getchar()) if (c=='-') f=-1;
    for(;c>='0'&&c<='9';c=getchar()) ans=ans*10+c-'0';
    return ans*f;
}
const int N=10010;
int n,cnt;
vector<int> v[N];
int main(){
	//freopen("1.in","r",stdin);freopen("1.out","w",stdout);
	n=R();
	if(n&1){
		v[1].pb(n);
		--n;
		++cnt;
	}
	F(i,1,n/2){
		++cnt;
		v[cnt].pb(i);
		v[cnt].pb(n-i+1);
	}
	int s=0;
	F(i,1,cnt)
		F(j,i+1,cnt)s+=v[i].size()*v[j].size();
	printf("%d\n",s);
	F(i,1,cnt)
		F(j,i+1,cnt)
			for(auto x:v[i])
				for(auto y:v[j])
					printf("%d %d\n",x,y);
    return 0;
}

Measured memory_bytes: 512
S=input()
T=input()

#alp={"a":0,"b":0,"c":0,"d":0,"e":0,"f":0,"g":0,"h":0,"i":0,"j":0,"k":0,"l":0,"m":0,"n":0,"o":0,"p":0,"q":0,"r":0,"s":0,"t":0,"u":0,"v":0,"w":0,"x":0,"y":0,"z":0}
#bet={"a":0,"b":0,"c":0,"d":0,"e":0,"f":0,"g":0,"h":0,"i":0,"j":0,"k":0,"l":0,"m":0,"n":0,"o":0,"p":0,"q":0,"r":0,"s":0,"t":0,"u":0,"v":0,"w":0,"x":0,"y":0,"z":0}

sd={}
td={}
cond=True
for i in range(len(S)):
    if S[i] not in sd:
        sd[S[i]]=T[i]
    else:
        if sd[S[i]]!=T[i]:
            cond=False
            break
    if T[i] not in td:
        td[T[i]]=S[i]
    else:
        if td[T[i]]!=S[i]:
            cond=False
            break

if cond:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3632
HN= input().split()
H= int(HN[0])
N= int(HN[1])
move=input().split()
dam=0
flag=False
for i in range (N):
    dam= dam+int(move[i])
    if (dam>=H):
        flag=True
        break
    else:
        flag=False
    
if (flag==True):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 10420
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


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

	vector<ll> a(n);
	map<ll, ll> s;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		
		s[a[i]]++;
	}

	ull sum = 0;
	for (auto p : s)
	{
		sum += p.second * (p.second - 1) / 2;
	}

	for (int i = 0; i < n; i++)
	{
		ll v = s[a[i]];
		ll before = v * (v - 1) / 2;
		ll after = (v - 1) * (v - 2) / 2;
		println(sum + after - before);
	}
}


Measured memory_bytes: 11008
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
typedef tuple<ll,ll,ll> Tu;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const double PI=3.14151926535;
const ll INFl=(ll)9223372036854775807/2;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
const ll tMOD=(ll)998244353;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n;
string s;
int main(){
	cin>>n>>s;
	REP(i,s.size()){
		s[i]=(s[i]-'A'+n)%26+'A';
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 long long L,R;
  cin >> L;
  cin >> R;
  long A;
  A=2019;
  
  for(long i=L ; i < min(L+2019,R) ; i++){
    for(long j=L+1 ; j< min(L+2020,R+1); j++){
      if(i != j){
      A = min(A, i % 2019 * j % 2019);
      }
    }
  }
  
  cout << A ;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int baris, kolom;
	for(int i=0; ; i++){
		scanf("%d %d", &baris, &kolom);
		if(baris==0 && kolom == 0){
			break;
		}
		else{
			for(int j=0; j<baris; j++){
				for(int k=0; k<kolom; k++){
					if(j==0||j==baris-1||k==0||k==kolom-1)printf("#");
					else printf(".");
				}
				printf("\n");
			}
			printf("\n");
		}
	}
}


Measured memory_bytes: 2608
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>

using namespace std;

int data[10000];

main(){
  int n;
  while(cin >> n && n){
    for(int i=0;i<n;i++) cin >> data[i];
    int ans = n;
    for(int i=0;i<n;i++){
      for(int j=1;j<=3;j++){
        if(data[i] == j) continue;
        int c = j, l = i, r = i, cnt = 0, tmp = data[i];
        data[i] = j;
        while(0<=l&&l<n&&0<=r&&r<n){
          if(data[l] != data[r]) break;
          c = data[l];
          for(;0<=l-1 && data[l-1] == c;l--);
          for(;r+1<n && data[r+1] == c;r++);
          int num = r - l - cnt + 1;
          if(num < 4) break;
          cnt += num;
          l--;
          r++;
        }
        data[i] = tmp;
        ans = min(ans, n-cnt);
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 0
/*
  Contest 106
  A - Garden
  Rakesh Kumar --> 27/09/2020
 */

#include <bits/stdc++.h>

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0); std::cout.tie(0);

    int a = 0, b = 0;
    std::cin >> a >> b;
    std::cout << (a - 1) * (b - 1) << std::endl;

    return 0;
}


Measured memory_bytes: 3612
/**
 *     author: qodjf
 *     created: 04.22.2020 22:29:01
 */
#include <bits/stdc++.h>
using namespace std;

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

  int N;
  cin >> N;
  vector<int> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p[i];
    p[i]--;
  }

  vector<int> a(N), b(N);
  b[N - 1] = 1;
  for (int i = N - 2; i >= 0; i--) {
    b[i] = b[i + 1] + N + 10;
  }

  a[p[0]] = 0;
  for (int i = 1; i < N; i++) {
    a[p[i]] = a[p[i - 1]] + 1 + b[p[i - 1]] - b[p[i]];
  }

  int minVal = *min_element(a.begin(), a.end());
  if (minVal <= 0) {
    for (int i = 0; i < N; i++) {
      a[i] += 1 - minVal;
    }
  }

  for (int i = 0; i < N; i++) {
    printf("%d%c", a[i], i == N - 1 ? '\n' : ' ');
  }
  for (int i = 0; i < N; i++) {
    printf("%d%c", b[i], i == N - 1 ? '\n' : ' ');
  }
}


Measured memory_bytes: 896
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main()
{
    int n; cin >> n;
    int result;
    if(n%1000==0)
      result = 0;
    else
    result = abs((n%1000)-1000);
    cout << result << endl;
}


Measured memory_bytes: 3160
import java.io.*;
import java.util.*;
public class Main implements Runnable {
    public void solve() throws Exception {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int k = sc.nextInt();
        if (a>=k){
            out.println(k);
        }else if(a+b>=k){
            out.println(a);
        }else
            out.println(a+(k-(a+b))*-1);
    }

    //main function//
    public static PrintWriter out;
    public static void main(String[] args) throws Exception {
        new Thread(null, new Main(), "", 1 << 26).start();
    }
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
    public void run() {
        try {
           solve();
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        } finally {
            out.close();
        }
    }
}


Measured memory_bytes: 32764
#    !/usr/bin/env python3
#    encoding: UTF-8
#    Modified: <07/Jul/2019 06:03:34 PM>


#    ✪ H4WK3yE乡
#    Mohd. Farhan Tahir
#    Indian Institute Of Information Technology (IIIT), Gwalior


import sys
import os
from io import IOBase, BytesIO


def main():
    n = int(input())
    arr = get_array()
    f = 0
    ans = [0] * n
    for i in range(n):
        if f == 0:
            ans[0] += arr[i]
        else:
            ans[0] -= arr[i]
        f = 1 - f
    for i in range(1, n):
        ans[i] = (arr[i - 1] - (ans[i - 1] // 2)) * 2
    print(*ans)


BUFSIZE = 8192


class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill():
            pass
        return super(FastIO, self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill()
            self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        py2 = round(0.5)
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2 == 1:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s: self.buffer.write(s.encode("ascii"))
            self.read = lambda: self.buffer.read().decode("ascii")
            self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)


def get_array(): return list(map(int, sys.stdin.readline().split()))


def get_ints(): return map(int, sys.stdin.readline().split())


def input(): return sys.stdin.readline().strip()


if __name__ == "__main__":
    main()


Measured memory_bytes: 67248
from collections import defaultdict
from copy import deepcopy

def main():
    N = int(input())
    A = tuple(map(int, input().split()))


    ans = 0
    left = defaultdict(int)
    for i, h in enumerate(A):
        ans += left[i-h]
        left[i+h] += 1

    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 62056
#include<map>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
typedef long long ll;
using namespace std;
struct str {
	string s1; string s2;
	bool operator<(const str& rhs) const {
		if (s1 != rhs.s1) {
			return  s1 > rhs.s1;
		}
		else {
			return s2 > rhs.s2;
		}
	}
};
ll n;
string s;
string t;
map<str, ll> mp;
int main() {
	cin >> n >> s;
	t = s;
	REP(i, 0, n - 1) {
		t[i] = s[n*2 - 1 - i];
	}
	ll p = (1 << n);
	REP(i, 0, p - 1) {
		string t1, t2;
		t1 = t2 = "111111111111111111";
		ll cnt1, cnt2;
		cnt1 = cnt2 = 0;
		REP(j, 0, n - 1) {
			if ((i >> j) & 1 == 1) {
				t1[cnt1] = s[j];
				cnt1++;
			}
			else {
				t2[cnt2] = s[j];
				cnt2++;
			}
		}
		t1 = t1.substr(0, cnt1);
		t2 = t2.substr(0, cnt2);
		//cout << t1<< " " << t2 << endl;
		str k = { t1,t2 };
		//cout << mp[k] << endl;
		mp[k]++;
	}
	ll ans = 0;
	REP(i, 0, p - 1) {
		string t1, t2;
		t1 = t2 = "111111111111111111";
		ll cnt1, cnt2;
		cnt1 = cnt2 = 0;
		REP(j, 0, n - 1) {
			if ((i >> j) & 1 == 1) {
				t1[cnt1] = t[j];
				cnt1++;
			}
			else {
				t2[cnt2] = t[j];
				cnt2++;
			}
		}
		t1 = t1.substr(0, cnt1);
		t2 = t2.substr(0, cnt2);

		str k = { t1,t2 };
		//cout << t1 << " "<<t2 << " " << mp[k] << endl;
		ans += mp[k];
	}
	cout << ans << endl;

}

Measured memory_bytes: 82176
#include<stdio.h>
int main(){
    int a,b,c,i,d=0,count=0,e;
    scanf("%d%d%d",&a,&b,&c);

    for(i=0;;i++){
            d=d+a;
            count++;
        if(d>c){
                break;
        }
    }
      e=b*(count-1);
      printf("%d\n",e);

return 0;
}


Measured memory_bytes: 128