akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

vector<int> buf;
vector<bool> seen;
vector<string> ss;

void dfs(int i, const int size, const int range_start, const int range_end)
{
	if (i == size) {
		string str;
		// ここで所望の作業を行う
		for (int j = 0; j < buf.size(); j++) {
			//			cout << buf[j];
			str.push_back((char)(buf[j] + 48));
		}
		//		cout << endl;
		ss.push_back(str);
	}
	else {
		for (int j = range_start; j <= range_end; j++) {
			buf[i] = j;
			dfs(i + 1, size, range_start, range_end);
		}
	}
}

int main(void)
{
	int n;
	cin >> n;
	vector<int> a(3);
	cin >> a[0] >> a[1] >> a[2];
//	sort(a.begin(), a.end());
	

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

	//！！重複なし！！
	//range_start~~range_end、桁数sizeの組み合わせを作る
	//size：桁数
	//ss:組み合わせ結果の配列(string)

	int size = n;
	int range_start = 0;
	int range_end = 3;

	buf.resize(size);
	seen.resize(range_end + 1);

	dfs(0, size, range_start, range_end);

	int minn = 1000000;

	for (int i = 0; i < ss.size(); i++) {

		bool zeroflg = false;
		bool ichiflg = false;
		bool niflg = false;
		for (int j = 0; j < n; j++) {
			if (ss[i][j] == '0') { zeroflg = true; }
			else if (ss[i][j] == '1') { ichiflg = true; }
			else if (ss[i][j] == '2') { niflg = true; }
		}
		if (zeroflg == false || ichiflg == false || niflg == false) { continue; }

		int aa = 0;
		int bb = 0;
		int cc = 0;
		int mp = 0;

		for (int j = 0; j < n ; j++) {
			if (ss[i][j] == '0') {
				if (aa != 0) { mp += 10; }
				aa += l[j];
			}
			else if (ss[i][j] == '1') {
				if (bb != 0) { mp += 10; }
				bb += l[j];
			}
			else if (ss[i][j] == '2') {
				if (cc != 0) { mp += 10; }
				cc += l[j];
			}
		}
		mp += abs(a[0] - aa) + abs(a[1] - bb) + abs(a[2] - cc);

		minn = min(minn, mp);

//	cout << ss[i] << " " << aa << " " << bb << " " << cc << " " << mp << endl;
	}

	cout << minn << endl;

	return 0;
}

Measured memory_bytes: 3832
#include <iostream>
#include <list>
int main () {
    std::list<char> vowelList;
    vowelList.push_back('a');
    vowelList.push_back('i');
    vowelList.push_back('u');
    vowelList.push_back('e');
    vowelList.push_back('o');

    char c;

    std::cin >> c;

    for(auto x : vowelList) {
        if(c == x) {
            std::cout << "vowel" << std::endl;
            return 0;
        }
    }
    std::cout << "consonant" << std::endl;

}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
	long long n, a, b;

	scanf("%lld %lld %lld", &n, &a, &b);

	if (!(abs(a - b) % 2))
	{
		printf("%lld\n", abs(a - b) / 2);
	}

	else
	{
		long long cand, temp;

		if (a > b)
		{
			temp = a;
			a = b;
			b = temp;
		}

		cand = a + (b - a) / 2;

		if ((n - b + 1) + (b - a) / 2 < cand)
		{
			cand = (n - b + 1) + (b - a) / 2;
		}

		printf("%lld\n", cand);
	}

	return 0;
}

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

int main() {

    ll n; cin >> n;

    set<string> u;
    REP(i, n) {
        string ui; cin >> ui;
        u.insert(ui);
    }

    ll m; cin >> m;

    bool o = false;
    REP(i, m) {
        string ti; cin >> ti;
        bool found = u.find(ti) != u.end();
        if (found) {
            if (o) {
                cout << "Closed by " + ti << "\n";
            } else {
                cout << "Opened by " + ti << "\n";
            }
            o = !o;
        } else {
            cout << "Unknown " + ti << "\n";
        }
    }

}


Measured memory_bytes: 3204
N = int(input())
As = list(map(int, input().split()))

summary = {}
for a in As:
    if a in summary:
        summary[a] += 1
    else:
        summary[a] = 1

n_comb = {}
for k in summary:
    if 2<=summary[k]:
        n_comb[k] = summary[k]*(summary[k]-1)//2
    else:
        n_comb[k] = 0

x_comb = {}
total = sum([n_comb[k] for k in n_comb])        
for k in summary:
    if 3<=summary[k]:
        x_comb[k] = total - n_comb[k] + (summary[k]-1)*(summary[k]-2)//2
    else:
        x_comb[k] = total - n_comb[k]


for a in As:
    print(x_comb[a])



Measured memory_bytes: 42004
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using Graph = vector<vector<int>>;
using P = pair<int,int>;
using ll =long long;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    ll n,m;
    cin >> n >> m;
    if(n>2 && m>2){
        cout << (n-2)*(m-2) << endl;
    }else{
        if(n==1 && m==1){
            cout << 1 << endl;
        }
        else if(n==1){
            cout << m-2 << endl;
        }else if(m==1){
            cout << n-2 << endl;
        }else if(n==2 || m==2){
            cout << 0 << endl;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <vector>
#include <bitset>
#include <cmath>
#include <utility>
#define Maxn 100005
#define Maxm 1000005
#define lowbit(x) x&(-x)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define PI acos(-1.0)
#define LL long long 
#define Inf (1LL<<62)
#define inf 0x3f3f3f3f
#define input freopen("input.txt","r",stdin)
#define output freopen("output.txt","w",stdout)
using namespace std;
int main()
{
	int arr[55];
	int n,p,sum;
	LL dp[5005][2];
	//input;output;
	while(~scanf("%d%d",&n,&p))
	{
		sum=0;
		memset(dp,0,sizeof(dp));
		for(int i=0;i<=5000;i++)
			dp[i][0]=1;
		for(int i=0;i<n;i++)
			scanf("%d",arr+i),sum+=arr[i];
		for(int i=0;i<n;i++)
			for(int j=5000;j>=arr[i];j--)
			{
				if(arr[i]&1)
				{
					dp[j][0]+=dp[j-arr[i]][1];
					dp[j][1]+=dp[j-arr[i]][0];
				}
				else
				{
					dp[j][0]+=dp[j-arr[i]][0];
					dp[j][1]+=dp[j-arr[i]][1];
				}
			}
		printf("%lld\n",dp[sum][p]);
	}
}

Measured memory_bytes: 384
nums = gets.strip.split(" ").map do |i|
  i.to_i
end
n=nums[0]
m=nums[1]

h = gets.strip.split(" ").map do |i|
  i.to_i
end

a = []
n.times { |i|
  a[i] =  []
}

m.times {
  way = gets.strip.split(" ").map do |i|
    i.to_i
  end
  a[way[0]-1].push(way[1]-1)
  a[way[1]-1].push(way[0]-1)
}

sum = n

n.times {|i|
  flag=true
  a[i].length.times{|j|
    if( h[i] <= h[a[i][j]])
      sum-=1 if flag
      flag=false
    end
  }
}

puts sum

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

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

    if (d == 25) cout << "Christmas" << endl;
    else if ( d == 24) cout << "Christmas Eve" << endl;
    else if (d == 23) cout << "Christmas Eve Eve" << endl;
    else if (d == 22) cout << "Christmas Eve Eve Eve" << endl;

    return 0;
}

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

int ans;
/*
int dp(int index,int arr[],int deja[])
{
    if(index>=n-1)
        return 0;

        if(deja[index])
            return deja[index];

        int choice1=INT_MAX,choice2=INT_MAX;
        if(index<n-1)
     choice1=dp(index+1,arr,deja)+abs(arr[index+1]-arr[index]);
     if(index<n-2)
     choice2= dp(index+2,arr,deja)+abs(arr[index+2]-arr[index]);
    //cout<<choice1<<" "<<choice2<<endl;
    deja[index] = min(choice1,choice2);
     return deja[index];

}*/
int main()
{

int n;
cin>>n;

int arr[n],dp[n+1];
for(int index=0;index<n;index++)
{
    cin>>arr[index];
    dp[index+1]=INT_MAX;
}
dp[0]=0;
for(int i=0;i<n;i++)
{

if(i>=1)
        dp[i]=min(dp[i-1]+abs(arr[i-1]-arr[i]),dp[i]);
if(i>=2)
        dp[i]=min(dp[i-2]+abs(arr[i-2]-arr[i]),dp[i]);

}
cout<<dp[n-1]<<endl;

    return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;


int n,k;
int ranks[200001];
int tmp[200001];
int lcp[200001];
int sa[200001];

bool compare_sa(int i,int j){
	if(ranks[i]!=ranks[j])return ranks[i]<ranks[j];
	else{
		int ri=(i+k<=n?ranks[i+k]:-1);
		int rj=(j+k<=n?ranks[j+k]:-1);
		return ri<rj;
	}
}

void construct_sa(string s){
	for(int i=0;i<=n;i++){
		sa[i]=i;
		ranks[i]=i<n?s[i]:-1;
	}
	for(k=1;k<=n;k*=2){
		sort(sa,sa+n+1,compare_sa);
		tmp[sa[0]]=0;
		for(int i=1;i<=n;i++){
			tmp[sa[i]]=tmp[sa[i-1]]+(compare_sa(sa[i-1],sa[i])?1:0);
		}
		for(int i=0;i<=n;i++){
			ranks[i]=tmp[i];
		}
	}
}

void construct_lcp(string s){
	for(int i=0;i<=n;i++){
		ranks[sa[i]]=i;
	}
	int h=0;
	lcp[0]=0;
	for(int i=0;i<n;i++){
		int j=sa[ranks[i]-1];
		if(h>0)h--;
		for(;j+h<n && i+h<n;h++){
			if(s[j+h]!=s[i+h])break;
		}
		lcp[ranks[i]-1]=h;
	}
}

int func(string s){
	construct_sa(s);
	construct_lcp(s);
	int res=0;
	for(int i=0;i<=n;i++){
		res=max(res,lcp[i]);
	}
	return res;
}

string t;

int main(void){
	cin >> t;
	n=t.size();
	printf("%d\n",n-func(t));
	return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <functional>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,f,t) for(int i=f;i<t;i++)
int main()
{
    int N; cin >> N;
    int sum = 0;
    int indiv10 = 100;
    REP(i, N) {
        int s; cin >> s;
        sum += s;
        if (s % 10 != 0) indiv10 = min(indiv10, s);
    }
    if (indiv10 == 100) cout << 0 << endl;
    else if (sum % 10 != 0) cout << sum << endl;
    else cout << sum - indiv10 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<stdio.h>
#include<math.h>
#include<string>
#include<map>
#include<vector>
#include<algorithm>
#include<cstring>
#include<queue>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
ll a,b;
int main()
{
    a=1;
    b=1;
    ll n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        ll t,v;
        cin>>t>>v;
        if(t>=a&&v>=b)
        {
            a=t;
            b=v;
        }
        ll j=a/t+(a%t==0?0:1);
        ll d=b/v+(b%v==0?0:1);
        ll x=max(j,d);
        a=x*t;
        b=x*v;
        //cout<<a<<"   "<<b<<endl;
    }
    cout<<a+b;
        return 0;
}


Measured memory_bytes: 256
//auto 関数名 = [(&:ラムダ外の引数をとる時))](引数の型1 引数名1, 引数の型2, 引数名2, ...) { 関数の処理 }; //inside main() define function. take care of };
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//   bitset<ビット数> s(tmp);
//   // (ビット列sに対する処理)
// }
// sort(配列変数.begin(), 配列変数.end());
// do {
//   // 順列に対する処理
// } while (next_permutation(配列変数.begin(), 配列変数.end()));
//const double PI = acos(-1); M_PI
// cout << fixed << setprecision(10);
// set<int>st{ 3,1,4,1,5,9,2,6,5,3,5 };
//     for (auto itr = st.begin(); itr != st.end(); ++itr) {
//         cout << *itr;
//     }
#include <bits/stdc++.h>
#include <regex>
using namespace std;
#define _GLIBCXX_DEBUG 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end() //sort(all(vec)); ,reverse(all(vec));etc
int main(){
  int n,m;
  cin>>n>>m;
  vector<vector<int>>vec(n,vector<int>(2));
  int p;
  string s;
  rep(i,m){
    cin>>p>>s;
    if(s=="AC"){
      vec.at(p-1).at(0)=1;
    }else{
      if(vec.at(p-1).at(0)==0){
         vec.at(p-1).at(1)+=1;
      }
      }
    }
  int ac,wa;
  ac=0;
  wa=0;
  rep(i,n){
   ac+=vec.at(i).at(0);
   if(vec.at(i).at(0)==1){
   wa+=vec.at(i).at(1);}
  }
  cout<<ac<<" "<<wa<<endl;
  }

Measured memory_bytes: 8800
#include <iostream>
#include <iomanip>
#include <climits>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <unordered_map>
#include <random>
#define _USE_MATH_DEFINES
#include <math.h>
#include <complex>

using namespace std;

#define INF (int)1e8
#define _INF (int)-1e8
#define INFLL (long long)1e15
#define _INFLL (long long)-1e15
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> P;

/*******************************************************/

int main() {
  ll q, h, s, d; cin >> q >> h >> s >> d;
  ll n; cin >> n;
  vll a = { q * 4, h * 2, s };
  sort(a.begin(), a.end());
  ll x = a[0];
  if (x * 2 <= d) cout << x * n << endl;
  else cout << n / 2 * d + (n % 2) * x << endl;
  return 0;
}

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

int main() {
  int32_t n;
  cin >> n;
  int32_t d[n + 1];
  for (int32_t i = 1; i <= n; i++) {
    int32_t p;
    cin >> p;
    d[i] = p == i ? 1 : 0;
  }
  int32_t i = 1;
  int32_t answer = 0;
  while (1) {
    if (d[i] == 1) {
      answer++;
      i += 2;
    } else {
      i++;
    }
    if (i > n) {
      break;
    }
  }
  cout << answer << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define fi first
#define se second
#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(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#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 pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define print(x) cout << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T> >
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

ll d[210][210];
int main() {
  int n, m, r;
  cin >> n >> m >> r;
  vi R(r);
  rep(i, r) {
    cin >> R[i];
    R[i]--;
  }
  rep(i, n) {
    rep(j, n) {
      if (i == j)
        d[i][j] = 0;
      else
        d[i][j] = 1LL << 60;
    }
  }
  rep(i, m) {
    int a, b;
    ll c;
    cin >> a >> b >> c;
    a--;
    b--;
    d[a][b] = c;
    d[b][a] = c;
  }

  rep(k, n) {
    rep(i, n) {
      rep(j, n) { d[i][j] = min(d[i][j], d[i][k] + d[k][j]); }
    }
  }
  ll ans = 1LL << 60;
  sort(rng(R));
  do {
    ll cost = 0;
    rep(i, r - 1) { cost += d[R[i]][R[i + 1]]; }
    mins(ans, cost);
  } while (next_permutation(R.begin(), R.end()));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<fstream>
#include<utility>
#include<bitset>
#include<map>
#include<deque>
#include<cmath>
#include<random>
#include<string.h>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007
#define re return 0

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("Yes");
	else say("No");
}

int main() {
	makei(A);
	makei(B);
	if ((A % 3 == 1 && B % 3 == 1) || (A % 3 == 2 && B % 3 == 2))say("Impossible");
	else say("Possible");
}

Measured memory_bytes: 256
import java.util.*;

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

	public Main() {
		new AOJ1030().doIt();
	}

	class AOJ1030{
		void doIt(){
			while(true){
				int n = in.nextInt();
				int h = in.nextInt();
				if(n+h==0)break;
				int sum = 0;
				boolean xy[][] = new boolean[n][n];
				boolean yz[][] = new boolean[n][n];
				boolean xz[][] = new boolean[n][n];
				for(int i=0;i<h;i++){
					String command = in.next();
					int a = in.nextInt()-1;
					int b = in.nextInt()-1;
					if(command.equals("xy")){
						xy[a][b] = true;
						for(int s=0;s<n;s++)if(!yz[b][s])if(!xz[a][s])sum++;
					}else if(command.equals("yz")){
						yz[a][b] = true;
						for(int s=0;s<n;s++)if(!xy[s][a])if(!xz[s][b])sum++;
					}else if(command.equals("xz")){
						xz[a][b] = true;
						for(int s=0;s<n;s++)if(!yz[s][b])if(!xy[a][s])sum++;
					}
				}
				System.out.println(n*n*n-sum);
			}
		}
	}
}

Measured memory_bytes: 37376
#include <iostream>
#include <string>

using namespace std;

int n;
int a, b, c, d;
string s;

int main(void)
{
	cin >> n;
	cin >> a >> b >> c >> d;
	cin >> s;
	s = "#" + s + "#";
	
	int p = b; bool flag = false;
	while(1){
		if(s[p-1] == '.' && s[p+1] == '.') flag = true;
		if(p == d) break;
		if(s[p+1] == '.') p++;
		else if(s[p+2] == '.') p+=2;
		else{
			cout << "No"<< endl;
			return 0;
		}
	}
	p = a;
	while(1){
		if(p == c) break;
		if(s[p+1] == '.') p++;
		else if(s[p+2] == '.') p+=2;
		else{
			cout << "No"<< endl;
			return 0;
		}
	}
	if(d < c && !flag) cout << "No" <<endl;
	else cout << "Yes" << endl;
	
	return 0;
}

Measured memory_bytes: 772
import java.util.Scanner;

public class Main {
	//java11

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int h1 = sc.nextInt();
		int m1 = sc.nextInt();
		int h2 = sc.nextInt();
		int m2 = sc.nextInt();
		int K = sc.nextInt();

		int hm1 = h1 * 60 + m1;
		int hm2 = h2 * 60 + m2;

		System.out.println(hm2-hm1-K);

	}

}


Measured memory_bytes: 35824
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
/////////////////// TYPES & MACROS ///////////////////////////////
#define INFLL 0x3fffffffffffffffLL
#define INF 0x3f3fffff
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(x) x.begin(),x.end()
#define exist(s,e) (s.find(e)!=s.end())
#define ff first
#define ss second
#define EPS 1e-8
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>ordered_set;
const ll MOD=1000000007;
/////////////////// DEBUG MODE ///////////////////////////////////
#define D(x) cerr<<"DEBUG: "<<#x<<" is: "<<x<<'\n'
#define error(args...) {string _s=#args; replace(all(_s),',',' ');\
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
void err(istream_iterator<string>) { cout<<endl;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
/////////////////// GLOBAL VARIABLES /////////////////////////////
vector<vector<int>> adj; vector<bool> vis;
/////////////////// FUNCTIONS ////////////////////////////////////
ll mexp(ll x, ll n, ll m){
  ll res=1;  while(n){if(n&1) res=(res*x)%m;n>>=1; x=((x%m)*(x%m))%m;}
  return res;
}
bool ispow2(ll x){ return x && (!(x&(x-1)));}
/////////////////// MAIN STARTS //////////////////////////////////
int main(){
  ios::sync_with_stdio(0);  cin.tie(0); cout<<fixed;   cerr<<fixed;
  cout<<setprecision(14); cerr<<setprecision(3);
  #ifdef DEBUG
  freopen("ip.txt","r",stdin); //freopen("op.txt","w",stdout);
  clock_t tStart = clock();
  #endif

	int a,b; cin>>a>>b;
	if(b<a) cout<<a-1<<'\n';
	else cout<<a<<'\n';

	#ifdef DEBUG
	cerr<<"\nExecution time: "<<(((double)clock() - tStart)/CLOCKS_PER_SEC)*1e3<<"ms.\n";
	#endif
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    if(0<n/10){
        n=n%10;
        if((n==2)||(n==4)||(n==5)||(n==7)||(n==9)){
            printf("hon\n");
        }else if((n==0)||(n==1)||(n==6)||(n==8)){
            printf("pon\n");
        }else if(n==3){
            printf("bon\n");
        }
    }else{
        if((n==2)||(n==4)||(n==5)||(n==7)||(n==9)){
            printf("hon\n");
        }else if((n==0)||(n==1)||(n==6)||(n==8)){
            printf("pon\n");
        }else if(n==3){
            printf("bon\n");
        }
    }
}

Measured memory_bytes: 1648
l=[]
for i in range(5):
    l.append(int(input()))
k = int(input())

l.sort()

is_ok = True
for i in range(5):
    for j in range(5):
        if abs(l[i] - l[j]) > k:
            is_ok = False 
            break
    if is_ok == False:
        break

if is_ok:
    print("Yay!")
else:
    print(":(")

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int h = sc.nextInt();
		int w = sc.nextInt();
		int k = sc.nextInt();
		String[] s = new String[h];
		for(int i = 0;i<h;i++) {
			s[i] = sc.next();
		}
		
		String[][] c = new String[h][w];
		for(int i = 0;i<h;i++) {
			for(int j = 0;j<w;j++) {
				c[i][j]=s[i].substring(j,j+1);
			}
		}
		int ans = 0;
		
		int hw = (int)Math.pow(2, h+w);
		for(int i = 0;i<=hw;i++) {
			String str = String.format("%0"+(h+w)+"d", Long.parseLong(Long.toBinaryString(i)));
			String[][] cc = new String[h][w];
			for(int j = 0;j<h;j++) {
				cc[j] = c[j].clone();
			}
			
			for(int j = 0;j<h;j++) {
				if(str.subSequence(j, j+1).equals("0")) {
					for(int l = 0;l<w;l++) {
						cc[j][l] = ".";
					}
				}
			}
			for(int j = h;j<h+w;j++) {
				if(str.subSequence(j, j+1).equals("0")) {
					for(int l = 0;l<h;l++) {
						cc[l][j-h] = ".";
					}
				}
			}
			
			int count = 0;
			for(int j = 0;j<h;j++) {
				for(int l = 0;l<w;l++) {
					if(cc[j][l].equals("#"))
						count++;
				}
			}
			if(count==k)
				ans++;
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 54020
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<queue>
#include<string>
#include<algorithm>
#include<set>
#include<map>
using namespace std;
using ll = long long;

int main(){
  ll x;
  cin >> x;
  for(ll a=-300;a<=300;a++){
    ll temp = sqrtl(sqrtl(abs((powl(a,5)-x))));
    //cout << temp << endl;
    for(ll b=temp*-1;b<=temp;b++){
      if(powl(a,5)-powl(b,5)==x){
            cout << a << " " << b;
            return 0;
          }
    }
  }
}

Measured memory_bytes: 3700
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
#pragma warning(disable : 4996)
using namespace std;
int N, M, a, b, imos[100009];
int main() {
	scanf("%d %d", &N, &M);
	for (int i = 0; i < M; i++) {
		scanf("%d %d", &a, &b); a--; b--;
		imos[a] ^= 1; imos[b] ^= 1;
	}
	for (int i = 0; i < N; i++) imos[i + 1] ^= imos[i];
	bool f = true;
	for (int i = 0; i < N; i++) {
		if (imos[i]) f = false;
	}
	printf(f ? "YES\n" : "NO\n");
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <regex>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include<tuple>

using namespace std;

const long long MOD = 1000000007;
const int MAX = 100010;

int main() {
	string S;
	long long dp[MAX][4] = { 0 };

	cin >> S;

	dp[0][0] = 1;

	for (int i = 0; i < S.length(); i++) {

		for (int j = 0; j < 4; j++) {
			if (S[i] == '?')dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) * 3 % MOD;
			else dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % MOD;
		}

		if (S[i] == 'A' || S[i] == '?') {
			dp[i + 1][1] = (dp[i + 1][1] + dp[i][0]) % MOD;
		}
		if (S[i] == 'B' || S[i] == '?') {
			dp[i + 1][2] = (dp[i + 1][2] + dp[i][1]) % MOD;
		}
		if (S[i] == 'C' || S[i] == '?') {
			dp[i + 1][3] = (dp[i + 1][3] + dp[i][2]) % MOD;
		}
	}

	cout << dp[S.length()][3] << endl;
	
	return 0;
}

Measured memory_bytes: 3584
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
#define WHITE 0
#define BLACK 1
typedef long long ll;
typedef pair<ll,ll> pl;
typedef pair<int,int> pi;
string s;
int k;
int INFi=1000000000;
ll INFl=1000000000000000;

struct UnionFind{
    vector<int> par;//初期化
    vector<int> rank;//高さ
    UnionFind(int n=0):par(n),rank(n,0){
        for(int i=0;i<n;i++) par[i]=i;
    }
    int root(int x){
        if(par[x]==x) return x;
        return par[x]=root(par[x]);//経路圧縮
    }
    void unite(int x,int y){
        int rx=root(x);
        int ry=root(y);
        if(rx==ry) return;
        if(rank[rx]<rank[ry]) rank[rx]=ry;
        else rank[ry]=rx;
        if(rank[rx]==rank[ry]) rank[rx]++;
    }
    bool same(int x,int y){
        return root(x)==root(y);
    }
};
struct edge{int from,to,cost;};
vector<edge> es(100); //辺の集合
vector<int> d(100,INFi);//最短距離
int V,E;//頂点数、辺数

int main(){
    int H,W;
    cin>>H>>W;
    string s[H];
    for(int i=0;i<H;i++) cin>>s[i];
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(s[i][j]=='.'){
                int count=0;
                for(int di=-1;di<=1;di++){
                    for(int dj=-1;dj<=1;dj++){
                        int ni=i+di;
                        int nj=j+dj;
                        if((ni>=0&&ni<H)&&(nj>=0&&nj<W)&&s[ni][nj]=='#'){
                            count++;
                        }
                    }
                }
                s[i][j]=(char)(count+'0');
            }
        }
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cout<<s[i][j];
        }
        cout<<endl;
    }
}




Measured memory_bytes: 256
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_6_D&lang=jp
#  Equal Range : python3
#  2018.11.26 yonezawa

import sys
input = sys.stdin.readline

def LowerBound(d,l):
    max = len(l) -1
    min = 0
    mid = max // 2
    while True:
        if (l[mid] > d ):
            max = mid
        elif (l[mid] == d ):
            while l[mid] == d and mid >= 0:
                mid -= 1
            return mid + 1
        else:
            min = mid
        mid =  (max + min ) // 2 

        if ( mid == max or mid == min ):
            if ( l[mid] == d or l[max] == d):
                while l[mid] == d and mid >= 0:
                    mid -= 1
                return mid+1
            if ( l[max] < d ):
                return len(l)
            if ( l[mid] > d):
                return min
            return max
def main():
    nl = int(input())
    l = list(map(int,input().split()))

    for i in range(int(input())):
        n = int(input())
        result1 = LowerBound(n,l)
        result2 = LowerBound(n+1,l)

        print (result1,result2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 16856
alf = 'abcdefghijklmnopqrstuvwxyz'
d = {c:i+1 for i,c in enumerate(alf)}
d['z']=25
def dfs(n):
    lst = []
    lst.append([['a'],0])
    while lst:
        a,mx = lst.pop()
        if len(a) == n:
            print(''.join(a))
            continue
        for i in range(min(mx+1,25)+1)[::-1]:
            lst.append([a + [alf[i]], max(i,mx)])

n= int(input())
dfs(n)


Measured memory_bytes: 4380
n, d = [ int(v) for v in input().split() ]
point_list = [  [ int(v) for v in input().split() ] for i in range(n) ]
square_list = [ i**2 for i in range(10**4+1) ]
ans = 0

for i in range(n):
    for j in range(i+1,n):
        d2 = 0
        for k in range(d):
            d2 += (point_list[i][k] - point_list[j][k])**2
        if d2 in square_list:
            ans += 1
print(ans)

Measured memory_bytes: 39280
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

vvl G;
vl ans;
vector<bool> B;
queue<P> q;

int main() {
  ll N,M;
  cin >> N >> M;
  G.resize(3*N);
  ans.assign(3*N,0);
  B.assign(3*N,false);
  rep(i,M){
    //移動回数をmod3でわける、0=>a,1=>n+a,2=>2n+a
    ll a,b;
    cin >> a >> b;
    a--;b--;
    G[a].push_back(N+b);
    G[a+N].push_back(2*N+b);
    G[a+2*N].push_back(b);
  }
  ll S,T;
  cin >> S >> T;
  S--;T--;
  q.push(make_pair(S,0));
  ans[S]=0;
  B[S]=true;
  while(!q.empty()){
    ll x=q.front().first;
    ll y=q.front().second;
    q.pop();
    ll k=G[x].size();
    rep(i,k){
      if(B[G[x][i]]==false){
        ans[G[x][i]]=y+1;
        q.push(make_pair(G[x][i],y+1));
        B[G[x][i]]=true;
      }
    }
  }
  
  if(ans[T]!=0){
    cout << ans[T]/3 << endl;
  }
  else{
    cout << -1 << endl;
  }
}

Measured memory_bytes: 19072
open Scanf;;
open Printf;;

let rint () = scanf " %d" (fun x -> x);;
let rpoint () = scanf " %f %f" (fun x y -> x, y);;

let () =
  let n = rint () in
  let ps = Array.init n (fun _ -> rpoint ()) in
  Array.sort (fun (a, b) (c, d) -> compare (atan2 b a) (atan2 d c)) ps;
  let ans = ref 0.0 in
  for i = 0 to n - 1 do
    let x = ref 0.0 in
    let y = ref 0.0 in
    for j = 0 to n - 1 do
      x := !x +. fst ps.((i + j) mod n);
      y := !y +. snd ps.((i + j) mod n);
      ans := max !ans (!x *. !x +. !y *. !y);
    done;
  done;
  printf "%.15f\n" (sqrt !ans);


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
ll inf = 1000000000;
typedef pair<ll, ll> P;
int main() {
	int n, m;
	cin >> n >> m;
	int sum = (n * (n - 1)) / 2;
	int ans = (m*(m-1))/ 2;
	cout << sum + ans << endl;
	return 0;
}

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

void solve(int H, int W, std::vector<string> a){
    for(int i = 0; i < W+2; ++i){
        cout << "#";
    }
    cout << endl;
    for(int i = 0; i < H; ++i){
        cout << "#";
        for(int j = 0; j < W; ++j){
            cout << a[i][j];
        }
        cout << "#" << endl;
    }
    for(int i = 0; i < W+2; ++i){
        cout << "#";
    }
    cout << endl;
}

int main(){
    int H, W;
    cin >> H >> W;
    //char a[W][H];
    vector<string> a(H);
    for(int h = 0; h < H; ++h){
        cin >> a[h];
    }
    solve(H, W, move(a));
    return 0;
}


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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p;

int n,k;
string s;

int main(){
  cin >> n >> k;
  cin >> s;
  char c = '1'; //1-0-1-0-1と言う感じの配列が欲しいので，1から比較する．
  vector<int> v;
  int tmp = 0;  
  for(int i=0;i<n;i++){
    if(c == s[i]){
      tmp++;
    }else{
      v.push_back(tmp);
      tmp = 1;
      c = s[i];
    }
  }
  if(tmp != 0)v.push_back(tmp);
  if(v.size()%2 == 0)v.push_back(0); //1-0-1-0で終わっていた時のために，0を追加


  vector<int> cumsum(v.size()+1); //累積和をとる.
  // cumsum.push_back(v[0]);
  for(int i=0;i<v.size();i++){
    cumsum[i+1] = cumsum[i] + v[i];
  }

  int add = 2*k+1;
  int ans = 0;
  for(int i=0;i<cumsum.size();i+=2){
    int left = i;
    int right = min(i+add, (int)v.size()); //v.sizeの理由？
    // cout << i+2*k+1<<" "<< (int)cumsum.size() << endl;
    int tmp = cumsum[right] - cumsum[left];
    ans = max(ans,tmp);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1272
package main
 
import (
  "fmt"
  "math"
)
 
func main() {
 
  var n, d int
  fmt.Scanln(&n, &d)
  
  matrix := make([][]int, 0)
  
  for i:=0; i<n; i++ {
    row := scanNums(d)
    matrix = append(matrix, row)
  } 
  
  count := 0
  for i:=0; i<n-1; i++ {
    for j:=i+1; j<n; j++ {
      distance := calcDistance(matrix[i], matrix[j])
      if math.Ceil(distance) == distance {
        count += 1
      }
    }
  }
 
  fmt.Print(count)
}
 
func scanNums(len int) (nums []int) {
    var num int
    for i := 0; i < len; i++ {
        fmt.Scan(&num)
        nums = append(nums, num)
    }
    return
}

func calcDistance(a []int, b []int)(result float64) {
  var total float64
  for i:=0; i<len(a); i++ {
    total += math.Pow(float64(a[i] - b[i]), 2)
  }
  
  return math.Sqrt(total)
}

Measured memory_bytes: 512
import heapq
n=int(input())
a=list(map(int,input().split()))
a=[-b for b in a]
heapq.heapify(a)
x=0
y=0
c=0
cnt=0
while len(a)>0:
    d=heapq.heappop(a)
    if c!=d:
        c=d
        cnt=1
    elif c==d:
        if x==0:
            x=d
            c=0
            continue
        elif x!=0 and y==0:
            y=d
            break
print(x*y)

Measured memory_bytes: 14372
# ABC155a


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと
    import collections

    if len(collections.Counter(list(map(int, input().split()))).most_common()) == 2:
        print('Yes')
        exit(0)
    print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 38512
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] x = new int[n];
    int[] y = new int[n];
    for(int i = 0; i < n; i++){
      x[i] = sc.nextInt();
      y[i] = sc.nextInt();
    }
    double sum = 0L;
    for(int i = 0; i < n; i++){
      for(int j = i + 1; j < n; j++){
        sum += Math.sqrt((double)(x[j] - x[i]) * (x[j] - x[i]) + (y[j] - y[i]) * (y[j] - y[i]));
      }
    }
    System.out.println(sum * 2 / n);
  }
}

Measured memory_bytes: 21844
import sys

def solve():
    input = sys.stdin.readline
    H, W, K = map(int, input().split())
    S = tuple(tuple(input().strip("\n")) for _ in range(H))
    A = [[-1 for _ in range(W)] for i in range(H)]
    startR = 0
    line = 0
    endR = 0
    cakeN = 1
    for i in range(H):
        if "#" in S[i]:
            line = i
            endR = i + 1
            break
    while endR < H:
        if "#" in S[endR]: #切り分けの処理。列方向に走査
            startC = 0
            for j in range(W):
                if S[line][j] == "#":
                    endC = j + 1
                    break
            while endC < W:
                if S[line][endC] == "#":
                    for si in range(startR, endR):
                        for sj in range(startC, endC): A[si][sj] = cakeN
                    startC = endC
                    cakeN += 1
                endC += 1
            for si in range(startR, endR):
                for sj in range(startC, endC):
                    A[si][sj] = cakeN
            cakeN += 1
            startR = line = endR

        endR += 1

    startC = 0
    for j in range(W):
        if S[line][j] == "#":
            endC = j + 1
            break
    while endC < W:
        if S[line][endC] == "#":
            for si in range(startR, endR):
                for sj in range(startC, endC):
                    A[si][sj] = cakeN
            startC = endC
            cakeN += 1
        endC += 1
    for si in range(startR, endR):
        for sj in range(startC, endC):
            A[si][sj] = cakeN

    for i, a in enumerate(A): print(" ".join(map(str, a)))

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 7796
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
//using namespace __gnu_pbds;

#define max_(x, y) (((x) > (y)) ? (x) : (y))
#define min_(x, y) (((x) < (y)) ? (x) : (y))
#define ___ ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
#define Mx 1000001   
#define inf 1e15
const int MOD = 1e9+7;
const double pi = 2 * acos (0.0);

/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/


typedef long long  L;
//typedef tree<L,null_type,less<L>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

L a1,a2,a3,b1,b2,b3,c,c1,c2,c3,d,d1,d2,d3,d4,d5,e1,e2,e3,f,h,k,l,m,n,m1,m2,n1,n2,o,p,p1,p2,p3,p4,q,q1,q2,q3,q4,s,t,
u,x,y,z,sum,mx=-inf,mn=inf,flg,flg1,flg2,id1,id2,id3,id4,lim;
map<string,L>Mp;
set<string>S;
vector<string>V,V1;
string str; 
void solve(){
    V.assign(S.begin(), S.end());
    lim=V.size();
    for(L i=0;i<lim;i++){
        if(Mp[V[i]]==mx){
            V1.push_back(V[i]);
        }
    }
    sort(V1.begin(), V1.end());
    lim=V1.size();//cout<<endl;
    for(L i=0;i<lim;i++)cout<<V1[i]<<endl;
}
int main()
{
    ___
    cin>>t;
    mx=0;
    while(t--){
        cin>>str;
        Mp[str]++;
        if(Mp[str]>mx){
            mx=Mp[str];
        }
        S.insert(str);
    }
    solve();
    return 0;
}
/// lld I64d push_back() top() pop() insert() upper_bound() lower_bound() memset() max() min() scanf continue


Measured memory_bytes: 36464
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdio.h>
using namespace std;
#define ll long long
const int maxn = 200005;
int a[maxn];
int n;
inline ll f(int x) {
    ll ans = 0;
    for (int i = 0; i < n; i++) ans += abs(a[i]-x);
    return ans;
}
int main(int argc, char const *argv[])
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", a+i);
        a[i] -= i+1;
    }

    ll l  = -1e9, r = 1e9, mid, mmid;

    while (l < r-1) {
        mid = (l+r)>>1;
        mmid = (mid+r)>>1;
        if (f(mid) > f(mmid)) l = mid;
        else r = mmid;
    }
    printf("%lld\n", min(f(l), f(r)));

    
    return 0;
}

// 5 3 1 -1 -3 -5
// 0 -1 -2 -3 -3 -3 -3

Measured memory_bytes: 1024
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

enum MOD = (10 ^^ 9) + 7;

void main()
{
    long A, B, C;
    scan(A, B);
    long a, b;
    scan(a, b);
    writeln((A * B) - (a * B) - (A * b) + (a * b));

}


Measured memory_bytes: 256
a,b,c,x,y = map(int,input().split())

res = 0
res += min(a+b,2*c)*min(x,y)
if x >= y:
    res += min(2*c*(x-y),a*(x-y))
else:
    res += min(2*c*(y-x),b*(y-x))

print(res)

Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define PRN(n) printf("%d\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c\n",c)
int main(void){
  int a,b,c,t;
  scanf("%d %d %d",&a,&b,&c);
  if(a>b){
    t=a;
    a=b;
    b=t;
  }
  if(b>c){
    t=b;
    b=c;
    c=t;
  }
  PRN(a+b);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
typedef pair<pll, pll> P;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

ll N;
ll a[50];

int main() {
	cin >> N;
	REP(i, N) cin >> a[i];
	
	ll ans = 0;
	
	while (true) {
		ll cnt = 0;
		REP(i, N) cnt += a[i] / N;
		
		REP(i, N) {
			ll now = cnt - a[i] / N;
			
			ll c = a[i] / N;
			
			a[i] -= c * N;
			a[i] += now;
			
			ans += c;
		}
		
		if (cnt == 0) break;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <sys/time.h>
using namespace std;
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; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


int main() {
    int K;
    while (cin >> K) {
        priority_queue<long long, vector<long long>, 
        greater<long long> > que;
        for (int i = 1; i < 10; ++i) que.push(i);
        for (int i = 0; i < K-1; ++i) {
            long long s = que.top();
            que.pop();
            for (int j = -1; j <= 1; ++j) {
                long long add = (s % 10) + j;
                if (add >= 0 && add <= 9) que.push(s * 10 + add);
            }

            //cout << i << ": " << s << endl;
        }
        cout << que.top() << endl;
    }
}

















Measured memory_bytes: 2420
#[allow(unused_imports)]
use {
    proconio::{fastout, input, marker::*},
    std::cmp::*,
    std::collections::*,
    std::ops::*,
};

#[allow(unused_macros)]
macro_rules !max {($a :expr $(,) *) =>{{$a } } ;($a :expr ,$b :expr $(,) *) =>{{std ::cmp ::max ($a ,$b ) } } ;($a :expr ,$($rest :expr ) ,+$(,) *) =>{{std ::cmp ::max ($a ,max !($($rest ) ,+) ) } } ;}
#[allow(unused_macros)]
macro_rules !chmax {($base :expr ,$($cmps :expr ) ,+$(,) *) =>{{let cmp_max =max !($($cmps ) ,+) ;if $base <cmp_max {$base =cmp_max ;true } else {false } } } ;}

#[fastout]
fn main() {
    input! {
        h: usize,
        w: usize,
        ab: [(Usize1, usize); h]
    }

    let mut s = (0..w).map(|i| (i, i)).collect::<BTreeSet<(usize, usize)>>();
    let mut v = (0..w).map(|i| (0, i)).collect::<BTreeSet<(usize, usize)>>();

    for (i, &(a, b)) in ab.iter().enumerate() {
        let update = s
            .range((a, 0)..=(b, b))
            .map(|&(i, j)| (i, j))
            .collect::<Vec<(usize, usize)>>(); // total: O(w)log w
        if !update.is_empty() {
            let mut x = 0;
            for (end, start) in update {
                chmax!(x, start);
                s.remove(&(end, start));
                v.remove(&(end - start, start));
            }
            if b != w {
                s.insert((b, x));
                v.insert((b - x, x));
            }
        }
        if let Some((m, _)) = v.iter().next() {
            println!("{}", m + i + 1);
        } else {
            println!("-1");
        }
    }
}


Measured memory_bytes: 22296
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

const int maxn=2e5+10;
const int mod=1000000000+7;
const double eps=1e-6;

int n;
ll m[maxn],a[maxn];

int main() {
   // freopen("test.txt","r",stdin);
    cin>>n;
    for(int i=1;i<=n;i++) {
        cin>>a[i];
        m[a[i]]++;
    }
    ll sum=0;
    for(int i=1;i<=n;i++) {
        sum+=m[i]*(m[i]-1)/2;
    }
    for(int i=1;i<=n;i++) {
        ll t=m[a[i]];
        cout<<sum-t*(t-1)/2+(t-1)*(t-2)/2<<endl;
    }
    return 0;
}
/*

*/


Measured memory_bytes: 4736
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int a,b,K;
  cin >> a >> b >> K;
  int s = a + K - 1;
  int t = b - K + 1;

  if(t <= s){
    for(int i=a;i<=b;i++) cout << i << endl;
  } else {
    for(int i=a;i<=s;i++) cout << i << endl;
    for(int i=t;i<=b;i++) cout << i << endl;
  }

  return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (n, x) = readLine()!!.split(' ').map(String::toInt)
    val m = IntArray(n) { readLine()!!.toInt() }.sortedDescending()
    val ans = n - 1 + (x - m.subList(0, n - 1).sum()) / m.last()
    println(ans)
}


Measured memory_bytes: 38248
from math import floor, ceil

n = int(input())
a = list(map(int, input().split()))

target_f = floor(sum(a)/n)
target_c = ceil(sum(a)/n)

ans_f = sum([(ai - target_f)**2 for ai in a])
ans_c = sum([(ai - target_c)**2 for ai in a])


print(min(ans_f, ans_c))

Measured memory_bytes: 3188
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
from itertools import permutations
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    P = tuple(map(int, readline().split()))
    Q = tuple(map(int, readline().split()))


    for i, A in enumerate(permutations(range(1,N+1))):
        if A == P:
            p = i
        if A == Q:
            q = i

    print(abs(p-q))




if __name__ == '__main__':
    main()


Measured memory_bytes: 9024
#include <stdio.h>

int main(void) {
  char s[5];
  scanf("%s", s);

  int ans = 0;
  for (int i = 0; i < sizeof(s); i++) {
    if (s[i] == '7') {
      ans = 1;
    }
  }

  if (ans) {
    printf("Yes\n");
  }
  else {
    printf("No\n");
  }

  return 0;
}


Measured memory_bytes: 1648