akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }

ll mpow(ll x, ll n){ //x^n(mod mo) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % mo;
        x = x*x % mo;
        n = n >> 1;
    }
    return ans;
}

ll combi(ll n, ll r) {
  if ( r * 2 > n ) r = n - r;
  ll dividend = 1;
  ll divisor  = 1;
  for ( ll i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    dividend %= mo;
    divisor  *= i;
    divisor %= mo;
  }
  return (dividend * mpow(divisor, mo-2)) % mo;
}

int main(){
    ll N, K;
    cin >> N >> K;
    for(ll i=1; i<=K; i++){
        if(i>N-K+1){
            cout << 0 << endl;
            continue;
        }
        cout << (combi(N-K+1, i)*combi(K-1,i-1)) % mo << endl;
    }

}


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

D=[K*10]*K
D[1]=1

import heapq

Q=[(1,1)]

while Q:
    c,x=heapq.heappop(Q)

    if D[x*10%K]>c:
        D[x*10%K]=c
        heapq.heappush(Q,(c,x*10%K))

    if D[(x+1)%K]>c+1:
        D[(x+1)%K]=c+1
        heapq.heappush(Q,(c+1,(x+1)%K))

print(D[0])

Measured memory_bytes: 8948
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;

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

    if (S.size() <= K) cout << S << endl;
    else {
        string ans = "";
        rep(i,K) {
            ans += S.at(i);
        }
        ans += "...";
        cout << ans << endl;
    }
}

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

struct st {
	int i, u, a, p;
};
st s[300];
int cnt[1001];
int main() {
	int n;
	while (scanf("%d", &n), n) {
		rep(j, n) {
			int i, u, a, p; scanf("%d%d%d%d", &i, &u, &a, &p);
			s[j] = { i,u,a,p };
		}
		sort(s, s + n, [](st a, st b) {
			if (a.a != b.a)return a.a > b.a;
			if (a.p != b.p)return a.p < b.p;
			return a.i < b.i;
		});
		memset(cnt, 0, sizeof(cnt));
		int k = 0;
		rep(i, n) {
			if (k < 10) {
				if (cnt[s[i].u] < 3) {
					cnt[s[i].u]++; k++;
					printf("%d\n", s[i].i);
				}
			}
			else if (k < 20) {
				if (cnt[s[i].u] < 2) {
					cnt[s[i].u]++; k++;
					printf("%d\n", s[i].i);
				}
			}
			else if (k < 26) {
				if (!cnt[s[i].u]) {
					cnt[s[i].u]++; k++;
					printf("%d\n", s[i].i);
				}
			}
			else break;
		}
	}
}

Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn=2e5+50;
const int mod=1e9+7;
int s[15][1050];
int mark[15];
int sum(int x1,int y1,int x2,int y2){
    return s[x2][y2]-s[x2][y1-1]-s[x1-1][y2]+s[x1-1][y1-1];
}
int main()
{
    memset(s,0,sizeof s);
    int h,w,k,mi=1000000000;
    scanf("%d%d%d",&h,&w,&k);
    for(int i=1;i<=h;i++){
        while(getchar()!='\n');
        for(int j=1;j<=w;j++){
            char x;
            scanf("%c",&x);
            s[i][j]=x-'0'+s[i][j-1]+s[i-1][j]-s[i-1][j-1];
        }
    }
    for(int i=0;i<1<<(h-1);i++){
        int cnt=i,y=1,ans=0;
        for(int j=1;j<h;j++){
            mark[j]=cnt%2;
            if(mark[j]==1)
                ans++;
            cnt/=2;
        }
        for(int j=1;j<=w;j++){
            int x=1;
            for(int c=1;c<=h;c++){
                if(sum(x,y,c,j)>k)
                    goto loop;
                if(mark[c]==1||c==h){
                    if(sum(x,y,c,j+1)>k){
                        y=j+1;
                        ans++;
                    }
                    x=c+1;
                }
           }
        }
        mi=min(mi,ans);
        loop:;
    }
    printf("%d",mi);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){

 int a,i,n;
 
 for (i=1;i<=9;i++){
 	
 	for(n=1;n<=9;n++){
 		
 		a = i*n;
 		
 		printf("%dx%d=%d\n",i,n,a);
 		
 	}
 
 }
 	
 
 
 return 0;
}

Measured memory_bytes: 524
import math

def calc(list,a,b):
    t = 0
    for k in range(len(list[a])):
        t += abs(list[a][k]-list[b][k])**2
    return math.sqrt(t)

n,d = map(int,input().split())
x = [list(map(int,input().split())) for _ in range(n)]
ans = 0

for j in range(n-1,-1,-1):
    for i in range(j-1,-1,-1):
        if calc(x,i,j).is_integer():
            ans += 1

print(ans)

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


int main() {
  string ans = "APPROVED";
  int n,a;
  cin >> n;
  rep(i,n) {
    cin >> a;
    if (a%2 == 0) {
      if(a%3 != 0 && a%5 != 0)
        ans = "DENIED";
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    ll x, k, d; cin >> x >> k >> d;
    double y = (double)(k-(double)x/d)/2;
    ll k_ = ll(y);
    ll ans = inf_l;
    for (ll i = k_-100; i <= k_+100; i++) {
        ll z = i;
        z = max((ll)0,z);
        z = min(k,z);
        ans = min(ans,abs(x+z*d-(k-z)*d));
    }
    cout << ans << endl;
}

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

ll solve() {
    vector<ll> A(3);
    ll K;
    cin >> A[0] >> A[1] >> A[2] >> K;
    ll ans = (A[0]-A[1]) * (1-K%2*2);
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
input = Array.new(5){gets.to_i}
ans = []

def calc(w)
  tmp = w%10
  return tmp==0 ? 0 : (10-tmp)
end

input.permutation(5).to_a.each do |ary|
  ans << ary.inject([]) {|memo, w|
    memo + [w, calc(w)]
  }[0..-2]
end

p ans.map {|a| a.inject(:+)}.min

Measured memory_bytes: 1916
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<cmath>
#include<iomanip>
using namespace std;

int main(void){
	int d,b,t,a[200][200],c,q[200][200],hokan,ue,mae,m;
	cin>>m;
	for(c=0;c<m;c++){
	cin>>a[1][c]>>a[2][c]>>a[3][c]>>a[4][c]>>a[5][c]>>a[6][c];}
	for(c=0;c<m;c++){
	for(d=0;d<c;d++){
	for(int o=0;o<4;o++){
		for(t=0;t<4;t++){
			hokan=a[2][c];
			a[2][c]=a[3][c];
			a[3][c]=a[5][c];
			a[5][c]=a[4][c];
			a[4][c]=hokan;
			if(a[1][c]==a[1][d]&&a[2][c]==a[2][d]&&a[3][c]==a[3][d]&&a[4][c]==a[4][d]&&a[5][c]==a[5][d]&&a[6][c]==a[6][d]){
				cout<<"No"<<endl;
				return 0;
	}
		}
		hokan=a[1][c];
		a[1][c]=a[2][c];
		a[2][c]=a[6][c];
		a[6][c]=a[5][c];
		a[5][c]=hokan;
	}

	hokan=a[1][c];
	a[1][c]=a[3][c];
	a[3][c]=a[6][c];
	a[6][c]=a[4][c];
	a[4][c]=hokan;
	for(b=0;b<4;b++){
		hokan=a[2][c];
		a[2][c]=a[3][c];
		a[3][c]=a[5][c];
		a[5][c]=a[4][c];
		a[4][c]=hokan;if(a[1][c]==a[1][d]&&a[2][c]==a[2][d]&&a[3][c]==a[3][d]&&a[4][c]==a[4][d]&&a[5][c]==a[5][d]&&a[6][c]==a[6][d]){
			cout<<"No"<<endl;
			return 0;
}
	}
	hokan=a[1][c];
	a[1][c]=a[3][c];
	a[3][c]=a[6][c];
	a[6][c]=a[4][c];
	a[4][c]=hokan;
	hokan=a[1][c];
	a[1][c]=a[3][c];
	a[3][c]=a[6][c];
	a[6][c]=a[4][c];
	a[4][c]=hokan;
	for(b=0;b<4;b++){
			hokan=a[2][c];
			a[2][c]=a[3][c];
			a[3][c]=a[5][c];
			a[5][c]=a[4][c];
			a[4][c]=hokan;
			if(a[1][c]==a[1][d]&&a[2][c]==a[2][d]&&a[3][c]==a[3][d]&&a[4][c]==a[4][d]&&a[5][c]==a[5][d]&&a[6][c]==a[6][d]){
				cout<<"No"<<endl;
				return 0;
			}
	}}}
		cout<<"Yes"<<endl;
	return 0;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
int main() {
  int i,j,tmp;
  int N,M,X,ans=1200001,flag;
  cin>>N>>M>>X;
  vector<int> C(N);
  vector<vector<int>> A(N,vector<int>(M));
  for(i=0;i<N;i++){
    cin>>C[i];
    for(j=0;j<M;j++){
      cin>>A[i][j];
    }
  }
  for(tmp=0;tmp<(1<<N);tmp++){
    bitset<12> s(tmp);
    vector<int> Sum(N);
    for(i=0;i<N;i++){
      if(s[i]){
        for(j=0;j<M;j++){
          Sum[j]+=A[i][j];
        }
      }
    }
    flag=1;
    for(i=0;i<M;i++){
      if(Sum[i]<X){
        flag=0;
        break;
      }
    }
    if(flag){
      int price=0;
      for(i=0;i<N;i++){
        if(s[i])price+=C[i];
      }
      ans=min(ans,price);
    }
  }
  if(ans==1200001)cout<<-1<<endl;
  else cout<<ans<<endl;
}

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

int N;

main()
{
    cin >> N;
    for (int i = 0; i < N; i++) {
        char c;
        cin >> c;
        if (c == 'Y') {
            cout << "Four" << endl;
            return 0;
        }
    }
    cout << "Three" << endl;
    return 0;
}

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

constexpr int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
constexpr int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	REP(i, k) {
		int a, b;
		cin >> a >> b;
		int t = min(min(a, b) - 1, min(n - a, n - b)) % 3;
		cout << t + 1 << endl;
	}
}


Measured memory_bytes: 3204
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> 
#define ff first 
#define endl "\n"
#define ss second 
#define li list<int>
#define vi vector<int>
#define ll long long int
#define pii pair<int,int>
#define vii vector<pair<int,int> >
#define mp make_pair
#define pb push_back
#define setbits(x) __builtin_popcountll(x)
#define custom  pair<int,pair<int,int> >
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> pbds; 
#define mod 1000000007
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int h,w;
    cin>>h>>w;
    char input[h][w];
    ll arr[h][w];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>input[i][j];
        }
    }
    memset(arr,0,sizeof arr);
    for(int j=0;j<w;j++){
        if(input[0][j]=='#'){
            break;
        }
        else{
            arr[0][j]=1;
        }
    }
    for(int i=0;i<h;i++){
        if(input[i][0]=='#')
        break;
        else
        arr[i][0]=1;
    }
    for(int i=1;i<h;i++){
        for(int j=1;j<w;j++){
            if(input[i][j]=='.'){
                arr[i][j]=(arr[i-1][j]+arr[i][j-1])%mod;
            }
            else{
                continue;
            }
        }
    }
    cout<<arr[h-1][w-1];
    return 0;
}

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

int main(){
    
    std::string a, b, c;
    size_t i = 0, j = 0, k = 0, flag = 0;

    std::cin >> a >> b >> c;

    while(i <= a.size() && j <= b.size() && k <= c.size()){
        if(flag == 0){
            if(a[i] == 'a'){
                flag = 0;
            }else if(a[i] == 'b'){
                flag = 1;
            }else{
                flag = 2;
            }
            i++;
        }else if(flag == 1){
            if(b[j] == 'a'){
                flag = 0;
            }else if(b[j] == 'b'){
                flag = 1;
            }else{
                flag = 2;
            }
            j++;
        }else{
            if(c[k] == 'a'){
                flag = 0;
            }else if(c[k] == 'b'){
                flag = 1;
            }else{
                flag = 2;
            }
            k++;
        }
    }

    if(i > a.size()){
        std::cout << 'A' << std::endl;
    }else if(j > b.size()){
        std::cout << 'B' << std::endl;
    }else{
        std::cout << 'C' << std::endl;
    }
    
    return 0;
}


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

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

  set<int> st;
  st.insert(a);
  st.insert(b);
  st.insert(c);
  cout << st.size() << endl;
  return 0;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  
  int result = 1;
  for (int i = 0; i < n; i++) {
    if (result * 2 < result + k) {
      result *= 2;
    } else {
      result += k;
    }
  }

  cout << result << endl;
}


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

const int Mod = 1000000007;

void merge_sort(long long x[], int n)
{
	static long long y[200001] = {};
	if (n <= 1) return;
	merge_sort(&(x[0]), n/2);
	merge_sort(&(x[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p] < x[q])? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

int main()
{
	int i, N, K;
	long long A[200001];
	scanf("%d %d", &N, &K);
	for (i = 0; i < N; i++) scanf("%lld\n", &(A[i]));
	merge_sort(A, N);
	A[N] = 0;
	
	int k, sgn = 0;
	long long ans;
	if (K == N) {
		for (i = 0, ans = 1; i < N; i++) {
			ans = ans * llabs(A[i]) % Mod;
			if (A[i] < 0) sgn ^= 1;
		}
		if (sgn == 1 && ans != 0) ans = Mod - ans;
	} else if (A[0] >= 0) {
		for (i = N - 1, ans = 1; i >= N - K; i--) ans = ans * A[i] % Mod;
	} else if (A[N-1] <= 0) {
		if (K % 2 == 1) {
			for (i = N - 1, ans = 1; i >= N - K; i--) ans = ans * llabs(A[i]) % Mod;
			if (ans != 0) ans = Mod - ans;
		} else {
			for (i = 0, ans = 1; i < K; i++) ans = ans * llabs(A[i]) % Mod;
		}
	} else {
		for (k = 0; k <= K && A[N-K+k] < 0; k += 2);
		if (k < K) {
			for (k += 2; k <= K && A[k-1] < 0 && A[k-2] * A[k-1] > A[N-K+k-2] * A[N-K+k-1]; k += 2);
			k -= 2;
		} else if (k > K) k -= 2;
		ans = 1;
		for (i = 0; i < k; i++) ans = ans * llabs(A[i]) % Mod;
		for (i = N - 1; i >= N - K + k; i--) ans = ans * A[i] % Mod;
	}
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 4848
#include <bits/stdc++.h>
	#include <set>
	#define ll long long 
	#include <string>
	#define pb push_back
	#define mp make_pair
	# define pi 3.14159265358979323846
	#define mod 1000000007
    #define rep(i,n) for(i=0;i<n;i++)
    #define rep1(i,n) for(i=1;i<n;i++)
	using namespace std;
	ll int multiply(ll int a,ll int b)
{
	ll int ans=(a%mod*b%mod)%mod;
	return ans;
}
ll int add(ll int a, ll int b)
{
	ll int ans=(a%mod+b%mod)% mod;	
	return ans;
}

	int power(ll int x,  ll int y, ll int p)  
{  
    ll int res = 1;     // Initialize result  
  
    x = x % p; // Update x if it is more than or  
                // equal to p 
   
    if (x == 0) return 0; // In case x is divisible by p; 
  
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}  
	void fastio()
	{					
		#ifndef ONLINE_JUDGE
	    // for getting input from input.txt
	    freopen("input.txt", "r", stdin);
	    // for writing output to output.txt
	    freopen("output.txt", "w", stdout);
	    #endif
	    ios_base::sync_with_stdio(false);
	    cin.tie(NULL);
	    cout.tie(NULL);

	}
	vector<ll int> adj[100001];
	ll int vis[100001]={0};
	ll int indegree[100001]={0};
	ll int dist[100001]={0};
	void dfs(ll int n)
	{
		vis[n]=1;
		for(auto node: adj[n])
		{
			dist[node]=max(dist[node],dist[n]+1);
			indegree[node]--;
			if (indegree[node]==0)
				dfs(node);
		}
	}
	ll int dp[100001]={0};
	void solve()
	{
		ll int n,k;
		cin>>n>>k;
		ll int a[n],i,j;
		rep(i,n)
		cin>>a[i];
		for(i=1;i<=k;i++)
		{
			rep(j,n)
			{
				if (i-a[j]>=0 && dp[i-a[j]]==0)
					dp[i]=1;
					
			}
		}
		// cout<<dp[0]<<endl;
		if (dp[k])
			cout<<"First"<<endl;
		else
			cout<<"Second"<<endl;

		
    }
	int main()
	{
		fastio();
		ll int t;
		t=1;
		// cin>>t;
		
		while(t--)
		{
			solve();
		}
			
	}
			

Measured memory_bytes: 6784
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<> v(n); for (auto&& e : v) cin >> e;
  V<> c(n); for (auto&& e : c) cin >> e;
  int res = 0;
  for (int i = 0; i < n; ++i) {
    res += max(v[i] - c[i], 0);
  }
  cout << res << '\n';
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int number_of_coin, money;
  scanf("%d", &money);
  scanf("%d", &number_of_coin);
  money %= 500;
  if(number_of_coin >= money) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>

int main() {
	double a, b, c, d, e, f;
	double x, y;
	while (scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)!=EOF) {
		
		x = ((c*(b*d - a*e)) - (b*(c*d - a*f))) / (a*(b*d - a*e));
		y = (c*d - a*f) / (b*d - a*e);
		
		if (x == 0) x = 0;
		if (y == 0) y = 0;
		//printf("%f %f %f %f %f %f\n", a, b, c, d, e, f);
		printf("%.3f %.3f\n",x,y);
	}
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define REP(i,x,n) for(int i = (x); i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);


int main(void)
{
    ll n,ans=INF; cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    ll mini=*min_element(all(a)),maxi=*max_element(all(a));
    for(int i=mini;i<=maxi;i++){
        ll tmp=0;
        rep(j,n){
            tmp += (a[j]-i)*(a[j]-i);
        }
        ans = min(ans,tmp);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3556
A = int(input())
if A == 2:
    print(2)
    exit()
sosu = [2] #素数が入る
sosu_2 = [4] #素数の2乗の数が入る
sosu_2_index = 1
for num in range(3, 100010, 2):
    if  num > sosu_2[sosu_2_index-1]:
        sosu_2_index += 1
    flag =  True
    for i in range(1,sosu_2_index):
        if num % sosu[i] == 0:
            flag = False
            break
    if flag:
        sosu.append(num)
        if num >= A:
            print(num)
            exit()
        sosu_2.append(num**2)


Measured memory_bytes: 41068
#include <bits/stdc++.h>
using namespace std;
long long n,z,x,c,s,a[100001],b[100001];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    b[0]=10000000001;
    b[1]=0;
    for(int i=2;i<=n;i++)
       b[i]=min(b[i-1]+(abs(a[i]-a[i-1])),b[i-2]+(abs(a[i]-a[i-2])));
    cout<<b[n]<<endl;
}


Measured memory_bytes: 1792
INF = 1<<29
N = 26
def check(bag, h, w)
  t = {}; b = {}; l = {}; r = {}; arr = []
  for y in (0...h)
    for x in (0...w)
      unless (c = bag[y][x]) == "."
        if arr.include?(c)
          t[c] = [t[c], y].min; b[c] = [b[c], y].max
          l[c] = [l[c], x].min; r[c] = [r[c], x].max
        else t[c] = y; b[c] = y; l[c] = x; r[c] = x; arr << c
        end
      end
    end
  end
  d = N.times.map{ [INF] * N }
  arr.each do |c|
    (t[c]..b[c]).each do |y|
      (l[c]..r[c]).each do |x|
        if bag[y][x] == "." then return false
        else 
          p = c.ord - "A".ord
          q = bag[y][x].ord - "A".ord
          d[p][q] = (c == bag[y][x]) ? 0 : -1
        end
      end
    end
  end
  (0...N).each do |i|
    (0...N).each do |j|
      (0...N).each do |k|
        d[j][k] = [d[j][k], d[j][i] + d[i][k]].min
      end
    end
  end
  (0...N).all?{|i| d[i][i] >= 0}
end
gets.to_i.times do
  h, w = gets.split.map(&:to_i)
  bag = h.times.map{ gets.chomp.split("") }
  if check(bag, h, w) then puts "SAFE"
  else puts "SUSPICIOUS"
  end
end

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


int main()
{
  
  int n;
  cin>>n;
  
   if(n&1)
   {
     float x=(n/2+1);
     printf("%.10f",x/(float) n);
   }
  else
  {
     printf("%.10f", 1/2.0);
  }
  
  
 return 0; 
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def existFalse(decr):
    for i in range(len(decr)):
        if i == False:
            return True
    return False

def checkNonDecr(H):
    for i in range(len(H) - 1):
        if H[i] > H[i+1]:
            return False
    return True

def solve(N: int, H: "List[int]"):
    decr = [False] * N
    isGood = False
    while existFalse(decr):
        changed = False
        for i in range(N-1):
            if H[i] > H[i+1]:
                if decr[i] == False:
                    H[i] -= 1
                    decr[i] = True
                    changed = True
        isGood = checkNonDecr(H)
        if isGood: 
            break
        if changed == False:
            break
    if isGood:
        print(YES)
    else:
        print(NO)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    H = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, H)

if __name__ == '__main__':
    main()


Measured memory_bytes: 16776
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(true) {
            int n = sc.nextInt();
            int k = sc.nextInt();
            if(n == 0 && k == 0) {
                break;
            }

            int[] a = new int[n];
            for(int i=0; i<n; i++) {
                a[i] = sc.nextInt();
            }

            int[] s = new int[n+1];
            for(int i=0; i<n; i++) {
                s[i+1] = s[i] + a[i];
            }

            int ans = 0;
            int tmp = 0;
            for(int i=0; i<=n-k; i++) {
                tmp = s[i+k] - s[i];
                if(ans < tmp) {
                    ans = tmp;
                }
            }
            System.out.println(ans);
        }
    }
}



Measured memory_bytes: 66404
A,B,C,X,Y = map(int,input().split())
if A+B <= 2*C:
    ans = A*X+B*Y
elif (A <= 2*C and X>=Y) or (B <= 2*C and X <= Y):
    minAB = min(X,Y)
    ans = 2*C*minAB+(X-minAB)*A+(Y-minAB)*B
else:
    ans = 2*C*max(X,Y)
print(ans)

Measured memory_bytes: 9076
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W


def solve(S):
    T = list("AKIHABARA")
    l = [0, 4, 6, 8]
    for i in range(len(l) + 1):
        for j in combinations(l, r=i):
            t = T[:]
            for x in j[::-1]:
                t.pop(x)
            if S == "".join(t):
                return True
    return False


def main():
    S = input()
    print("YES" if solve(S) else "NO")


if __name__ == '__main__':
    main()


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

using namespace std;

int main() {
    string str;
    cin >> str;

    int i, ccount=0;
    if(str[0]=='A') {
        for(i=1; i<str.length(); i++) {
            if((str[i]>='a')&&(str[i]<='z')) {
                continue;
            } else {
                if(str[i]=='C') {
                    if(i==1 || i>str.length()-2) {
                        cout << "WA" << endl;
                        return 0;
                    }
                    if(ccount==0) {
                        ccount += 1;
                    } else {
                        cout << "WA" << endl;
                        return 0;
                    }
                } else {
                    cout << "WA" << endl;
                    return 0;
                }
            }
        }
        if(ccount==1) {
            cout << "AC" << endl;
            return 0;
        }
    }

    cout << "WA" << endl;

    return 0;
    
}

Measured memory_bytes: 256
# 22:28
l,r = map(int,input().split())
if r-l > 2019:
    print(0)
    exit(0)
m = 2019
for i in range(l,r):
    for j in range(l,r+1):
        if i != j and (i*j)%2019 < m:
            m = (i*j)%2019
print(m)

Measured memory_bytes: 2940
#include<iostream>
#include<set>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i < (int)(n); i++)

#include <algorithm>
using namespace std;
#include <cmath>
#include <string>
#define elif else if
typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
int N;

int main(){
    cin >> N;
    int A[TENFIVE]={0};
    ll diff[TENFIVE]={0};
    ll sum=0;
    rep(i,N){
        cin>>A[i];
        if (i == 0)    
            diff[i] = abs(A[i]);
        else 
            diff[i] = abs(A[i]-A[i-1]);        
        sum += diff[i];
    }
    diff[N] = abs(A[N-1]);
    sum += diff[N];
    // cout<<sum;
    rep(i,N){ 
        ll show_sum = sum;   
        show_sum -= diff[i];
        if(i==0 ){
            show_sum -= diff[i+1];
            show_sum += abs(A[1]);
        }else {
            show_sum -= diff[i+1];

            show_sum += abs(A[i+1]-A[i-1]);
        }
        cout<<show_sum<<endl;
    }

    return 0;
}

Measured memory_bytes: 2432
//In the name of ALLAH the most merciful the most beneficial

#include<cstdio>
#include<cstring>
#include<bits/stdc++.h>
#include<iostream>
#include<math.h>
#include<fstream>
#define sc(x) scanf("%d",&x)
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORd(i,a,b) for(int i=a;i>b;i--)
#define ff first
#define ss second
#define sz(x) x.size()
#define pb push_back

using namespace std;

typedef pair<int,int> pii;
typedef vector<pii> vii;
const int con = 1e9;
static const int INF = 0x3f3f3f3f;
static const int MOD = 998244353;

int main(){

    int arr[3];
    cin >> arr[0] >> arr[1] >> arr[2];
    sort(arr,arr+3,greater<>());
    cout << arr[0]*10 + arr[1]+ arr[2];
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
char a[100010];
int n;
int dp[100010][2];

int main(){
	scanf("%s",a+1);
	n=strlen(a+1);
	dp[1][0]=1;
	dp[1][1]=2;
	for(int i=2;i<=n;i++){
		dp[i][0]=3LL*dp[i-1][0]%mod;
		if(a[i]-'0'>0){
			dp[i][0]+=dp[i-1][1],dp[i][0]%=mod;
			dp[i][1]=2LL*dp[i-1][1]%mod;
		}
		else{
			dp[i][1]=dp[i-1][1];
		}
	}
	printf("%d\n",(dp[n][0]+dp[n][1])%mod);
	
	return 0;	
}

Measured memory_bytes: 1152
import itertools
import math
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


# MOD = 998244353


def get_factors(n):
    """
    素因数分解
    :param int n:
    :rtype: list of int
    """
    if n <= 1:
        return []

    ret = []
    while n > 2 and n % 2 == 0:
        ret.append(2)
        n //= 2
    i = 3
    while i <= math.sqrt(n):
        if n % i == 0:
            ret.append(i)
            n //= i
        else:
            i += 2
    ret.append(n)
    return ret


N = int(sys.stdin.buffer.readline())

counts = [0] * 101
for n in range(1, N + 1):
    for f in get_factors(n):
        counts[f] += 1

t = []
for c in counts:
    if c >= 2:
        t.append(c)
counts = t

# 素因数の使い方のパターン数が
# 3, 25 と 3, 5, 5 と 15, 5 と 75 のとき約数が75個
ans = 0
for i, j, k in itertools.combinations(range(len(counts)), r=3):
    if counts[i] >= 2 and counts[j] >= 4 and counts[k] >= 4:
        ans += 1
    if counts[i] >= 4 and counts[j] >= 2 and counts[k] >= 4:
        ans += 1
    if counts[i] >= 4 and counts[j] >= 4 and counts[k] >= 2:
        ans += 1
for i, j in itertools.combinations(range(len(counts)), r=2):
    if counts[i] >= 2 and counts[j] >= 24:
        ans += 1
    if counts[i] >= 24 and counts[j] >= 2:
        ans += 1
    if counts[i] >= 4 and counts[j] >= 14:
        ans += 1
    if counts[i] >= 14 and counts[j] >= 4:
        ans += 1
for c in counts:
    if c >= 74:
        ans += 1
print(ans)


Measured memory_bytes: 3192
using System;
using System.Linq;
namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
    int N=int.Parse(Console.ReadLine());
     string[] str=Console.ReadLine().Split(' ');
      int[] arr=str.Select(int.Parse).ToArray();
      int sum=arr.Sum();
      int ans=sum-2*arr[0];
      for(int T=0;T<N;T++){
       // int[] c = (new ArraySegment<int>(arr, 0, T)).ToArray();
        int CS=0;
        for(int i=0;i<=T;i++){
         CS+=arr[i];
          
        }
        int dif=Math.Abs((sum-CS)-CS);
        if(dif<ans){
          ans=dif;
        }
      }
    Console.WriteLine(ans);
    }
    
  }

}


Measured memory_bytes: 28268
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int  A = sc.nextInt();
		int  B = sc.nextInt();

			if (B % A == 0) {

				System.out.println(A + B);
			}else {
				System.out.println(B - A);
			}

	}
}

Measured memory_bytes: 21844
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include<limits>
#include<iomanip>

using namespace std;

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

const long double pi = 3.141592653589793;

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define F first
#define S second

// #define COMMENT

/*

const int NN = 200090;
ll fact[NN];
ll finv[NN];
ll inv[NN];

void inverse_modulao() {
  fact[0] = fact[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;

  for(int i = 2;i < NN;i++) {
    fact[i] = fact[i-1]*i%mod;
    inv[i] = mod-mod/i*inv[mod%i]%mod;
    finv[i] = finv[i-1]*inv[i]%mod;
  }
}

ll nCr(int n, int r) {
  return fact[n]*finv[r]%mod*finv[n-r]%mod;
}

*/


int N;string s;
vector<int> g[4];
/*
0-R
1-G
2-B
*/

int ci(char ch) {
  if(ch == 'R') return 0;
  return ch == 'G'? 1 : 2;
}

int main() {

//  freopen("input.in","r",stdin);
//  freopen("output.out","w",stdout);

  cin >> N;
  cin >> s;
  rep(i, N) {
    g[ci(s[i])].pb(i);
  }
  //
  // rep(i, 3) {
  //   for(auto x: g[i]) cout << x << " ";cout << endl;
  // }

  if(1LL * g[0].size() * g[1].size()  * g[2].size() == 0) {
    cout << 0 << endl;
    return 0;
  }

  ll ans = 0;
  for(int i = 0;i < N;i++) {
    for(int j = i+1;j < N;j++) {
      if(s[i] == s[j]) continue;

      int k = 3 - ci(s[i]) - ci(s[j]);
      int ii = lower_bound(g[k].begin(), g[k].end(), j) - g[k].begin();
      int tans = 0;
      // debug(ii);
      if(ii != g[k].size()) {
        tans = (g[k].size()-ii);
      }
      // debug(tans);
      if(binary_search(g[k].begin(), g[k].end(), j + (j-i))) {
        tans--;
      }
      ans += tans;
    }
  }
  cout<<ans;


  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    ll n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    rep(i, n) {
        ll fv = a + i * d - (n - 1 - i) * c;
        ll sv = a + i * c - (n - 1 - i) * d;
        if ((b >= sv) && (b <= fv)) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <set>
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>

using namespace std;

const int MOD = 1e9 + 7;
const int N = 3005;

int n,m;
int dp[N][N][2];

int f(int i,int crv,int nula){
    if(dp[i][crv][nula] != -1) return dp[i][crv][nula];
    if(crv == 0) nula = 1;
	if(i == m) {
        return nula;
	}
	int plv = n - crv;
	int ret = 0;
	if(crv > 0){
		ret = (ret+ (f(i + 1,crv - 1, nula | (crv -1 == 0)) + f(i + 1,crv, nula | (crv - 1 == 0))) % MOD ) % MOD;
	}
	if(plv > 0){
		ret = (ret + (f(i + 1,crv + 1,  nula) + f(i + 1,crv,nula))% MOD ) % MOD;
	}
	return dp[i][crv][nula] = ret;
}

int main(){
    memset(dp,-1,sizeof(dp));
    scanf("%d%d",&n,&m);
    int sol = 0;
    for(int i = 0;i<=n;i++){
        sol = (sol + f(0,i,0)) % MOD;
    }
    printf("%d\n",sol);
}


Measured memory_bytes: 71040
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define rrep(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = int(s); i < int(n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    vi v(n,1);
    rep2(i,1,n) {
        int now = i;
        while(~now&1) {
            now /= 2;
            v[i]++;
        }
    }
    rep(i,n-1) rep2(j,i+1,n) cout << v[j-i] << (j == n-1 ? '\n' : ' ');
}


Measured memory_bytes: 3636
#!/usr/bin/env python3

import itertools
from collections import defaultdict
from heapq import heappush, heappop
import sys

sys.setrecursionlimit(10**6)
input = sys.stdin.buffer.readline
INF = 10 ** 9 + 1  # sys.maxsize # float("inf")


def debug(*x):
    print(*x, file=sys.stderr)


def blute_solve(N, AS):
    "void()"
    buf = []

    def blute(xs, buf):
        debug("blute: xs, buf", xs, buf)
        if not xs:
            return 0
        if not buf:
            # first player score 0
            return blute(xs[1:], [xs[0]])
        # insert
        candidate = []
        for i in range(len(buf)):
            s = min(buf[i - 1], buf[i])
            newBuf = buf[:]
            newBuf.insert(0, xs[0])
            candidate.append(blute(xs[1:], newBuf) + s)
        return max(candidate)

    candidate = []
    for xs in itertools.permutations(range(N)):
        candidate.append(blute(xs, buf))
    return max(candidate)


def solve(N, AS):
    "void()"
    buf = []
    AS.sort(reverse=True)
    ret = AS[0]
    for i in range(N - 2):
        ret += AS[1 + i // 2]
    return ret


def main():
    N = int(input())
    AS = list(map(int, input().split()))
    print(solve(N, AS))


T1 = """
4
2 2 1 3
"""


def test_T1():
    """
    >>> as_input(T1)
    >>> main()
    7
    """


T0 = """
3
3 2 1
"""


def test_T0():
    """
    >>> as_input(T0)
    >>> main()
    5
    """


T2 = """
7
1 1 1 1 1 1 1
"""


def test_T2():
    """
    >>> as_input(T2)
    >>> main()
    6
    """


def _test():
    import doctest
    doctest.testmod()


def as_input(s):
    "use in test, use given string as input file"
    import io
    global read, input
    f = io.StringIO(s.strip())

    def input():
        return bytes(f.readline(), "ascii")

    def read():
        return bytes(f.read(), "ascii")


USE_NUMBA = False
if (USE_NUMBA and sys.argv[-1] == 'ONLINE_JUDGE') or sys.argv[-1] == '-c':
    print("compiling")
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', solve.__doc__.strip().split()[0])(solve)
    cc.compile()
    exit()
else:
    input = sys.stdin.buffer.readline
    read = sys.stdin.buffer.read

    if (USE_NUMBA and sys.argv[-1] != '-p') or sys.argv[-1] == "--numba":
        # -p: pure python mode
        # if not -p, import compiled module
        from my_module import solve  # pylint: disable=all
    elif sys.argv[-1] == "-t":
        _test()
        sys.exit()
    elif sys.argv[-1] != '-p' and len(sys.argv) == 2:
        # input given as file
        input_as_file = open(sys.argv[1])
        input = input_as_file.buffer.readline
        read = input_as_file.buffer.read

    main()


Measured memory_bytes: 29520
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char a;
    cin>>a;
    if(a=='a'||a=='b'||a=='c'||a=='d'||a=='e'||a=='f'||a=='g'||a=='h'||
    a=='p'||a=='o'||a=='n'||a=='m'||a=='l'||a=='k'||a=='j'||a=='i'||
    a=='q'||a=='r'||a=='s'||a=='t'||a=='u'||a=='v'||a=='w'||a=='x'||a=='y'||a=='z')
cout<<"a"<<endl;
else
        cout<<"A"<<endl;
}


Measured memory_bytes: 3600
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define range_for(i, b, e) for(int i=(b), i##_len=(e); i<=i##_len; ++i)
# define step(n) rep(_, n)
# define ALL(x) (x).begin(), (x).end()
# define RALL(x) (x).rbegin(), (x).rend()
# define pb push_back
# define len(x) ((int)(x).size())
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define debug(x) std::cerr<<#x<<": "<<(x)<<endl;
# define LINT_MAX (LONG_LONG_MAX)
# define cauto const auto
using namespace std;
using lint = long long;
template <class Type> inline constexpr Type Square(Type x) { return x * x; }
template <class Type> inline constexpr bool InRange(const Type& x, const Type& i, const Type& a) { return (i <= x) && (x <= a); }
template<class Integer>bool chmax(Integer &a, const Integer &b) { if (a<b) { a=b; return 1; } return 0; }
template<class Integer>bool chmin(Integer &a, const Integer &b) { if (b<a) { a=b; return 1; } return 0; }
template<class Integer>bool IsOdd(Integer &n) { return n & 1; }
template<class Integer>bool IsEven(Integer &n) { return !(n & 1); }
int ctoi(const char c) { return ('0' <= c && c <= '9') ? (c - '0') : -1; }
string YesNo(bool b) { return b ? "Yes" : "No"; }
string YESNO(bool b) { return b ? "YES" : "NO"; }
string yesno(bool b) { return b ? "yes" : "no"; }
void Print() { cout << endl; }
template <class Head, class... Tail> void Print(Head&& head, Tail&&... tail) { cout << head; if (sizeof...(tail) != 0) cout << ""; Print(forward<Tail>(tail)...); }
template <class T> void Print(vector<T> &vec) { for (auto& a : vec) { cout << a; if (&a != &vec.back()) cout << " "; } cout << endl; }
template <class T> void Print(vector<vector<T>> &df) { for (auto& vec : df) { Print(vec); } }

// 整数の桁数を返す ( log(N) )
template <class Integer> Integer GetDigit(Integer n) {
    if (n == 0) return 1;
    Integer d = 0;
    while (n) {
        n /= 10;
        d++;
    }
    return d;
}

// 素数かどうかを返す ( O(sqrt(N)) )
template <class Integer>
constexpr bool IsPrime(const Integer n) noexcept {
    if (n < 4) return n == 2 || n == 3;
    if (n % 2 == 0 || n % 3 == 0 || (n % 6 != 1 && n % 6 != 5)) return false;
    for (Integer i = 5; i * i <= n; i += 6) if (n % i == 0 || n % (i + 2) == 0) return false;
    return true;
}


int main()
{
    int a, b; cin >> a >> b;
    Print(max({a+a-1, a+b, b+b-1}));
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int H,W,m,hmax=0,wmax=0;
  
  scanf("%d %d %d",&H,&W,&m);
  
  int hbomb[H+1],h[m+1],wbomb[W+1],w[m+1];
  
  for(int i=1;i<=H;i++){
    hbomb[i]=0;
  }
  
  for(int i=1;i<=W;i++){
    wbomb[i]=0;
  }
  
  for(int i=1;i<=m;i++){
    scanf("%d %d",&h[i],&w[i]);
    hbomb[h[i]]+=1;
    wbomb[w[i]]+=1;
  }
  
  for(int i=1;i<=H;i++){
    if(hmax<hbomb[i]){
      hmax=hbomb[i];
    }
  }
  
  for(int i=1;i<=W;i++){
    if(wmax<wbomb[i]){
      wmax=wbomb[i];
    }
  }
  
  int hbox[H+1],wbox[W+1];
  int hcount=0,wcount=0,count=0;
  
  for(int i=1;i<=H;i++){
    if(hbomb[i]==hmax){
      hbox[i]=1;
      hcount+=1;
    }
    else{hbox[i]=0;}
  }
  
  for(int i=1;i<=W;i++){
    if(wbomb[i]==wmax){
      wbox[i]=1;
      wcount+=1;
    }
    else{
      wbox[i]=0;
    }
  }
  
  for(int i=1;i<=m;i++){
    if(hbox[h[i]]==1 && wbox[w[i]]==1){
      count+=1;
    }
  }
  
  if(count==hcount*wcount){
    printf("%d",hmax+wmax-1);
    return 0;
  }
  else{
    printf("%d",hmax+wmax);
    return 0;
  }
}


Measured memory_bytes: 8756
#include<bits/stdc++.h>
#define MOD (long long)(1e9+7)
using namespace std;
int n,m;
int main()
{
	cin >> n >> m;
	if(n == 1 && m == 1) cout << 1;
	else if(n == 1 && m > 1) cout << m-2;
	else if(n > 1 && m == 1) cout << n-2;
	else cout << 1LL*(n-2)*(m-2);
	//ans;
	return 0;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
char a[101];
bool pd=false;
int main()
{
	scanf("%s",a);
	int len=strlen(a);
	for (int i=0;i<len-1;i++)
	  if (a[i]=='C')
	  {
	  	for (int j=i+1;j<len;j++)
	  	  if (a[j]=='F')
	  	  {
	  	  	pd=true;
	  	  	break;
		  }
		if (pd==true) break;
	  }
	if (pd==true) printf("Yes");
	else printf("No");
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{

  int n, h[100], i, j, s, c;
  scanf("%d",&n);
  s=0; c=0;
  for(i=0;i<n;i++){
        scanf("%d",&h[i]);
  }
  for(i=1;i<n;i++){
        s=0;
        if(h[i]>=h[0]){
                for(j=i-1;j>=0;j--){
                        if(h[i]>=h[j])
                                s++;
                        else break;
                }
                if(s==i)
                        c++;
        }
  }
  printf("%d\n",c+1);
  return 0;
}


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

int main()
{
  ll x,ans=0;
  cin >> x;
  ans = (x / 500) * 1000 + ((x - (x / 500) * 500) / 5) * 5;
  cout << ans << "\n";
  return 0;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)

int b;

using Int = long long;

Int sum(Int a) {
    return a * (a + 1) / 2;
}

// sum [a, b)
Int sum(Int a, Int b) {
    return sum(b) - sum(a) + a;
}

void solve() {
    int n = sqrt(b * 2);
    int x = 0, y = 0;
    rep(i, n + 1) {
        Int l = 0, r = b + 1;
        while (r - l > 1) {
            Int m = (l + r) / 2;
            Int tmp = sum(m, m + i);
            // cout << i << ", " << l << ", " << r << ", " << m << ", " << tmp << endl;
            if (tmp > b) r = m;
            else l = m;
            if (tmp == b) {
                // cout << "poyo" << endl;
                if (y <= i) {
                    y = i;
                    x = m;
                }
            }

        }
    } 
    cout << x << " " << y + 1 << endl;
}

int main() {
    while(cin >> b, b) {
        solve();
    }
}


Measured memory_bytes: 3088
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

// const int dx[4] = { 1, 0, -1, 0 };
// const int dy[4] = { 0, 1, 0, -1 };

// const int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1};
// const int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1};

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector<int> siz;
    UnionFind(int N) : par(N),siz(N,1) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        if(siz[rx] < siz[ry])swap(rx,ry);
        siz[rx] += siz[ry];
        par[ry] = rx; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int size(int x){
      return siz[root(x)];
    }
};

// TODO: write
int main() {   
  int n,m,k;cin>>n>>m>>k;
  
  auto tree = UnionFind(n);
  vector<vector<int>> ab(n);

  rep(i,m){
    int a,b;cin>>a>>b;
    a--;b--;
    ab[a].emplace_back(b);
    ab[b].emplace_back(a);
    tree.unite(a,b);
  }
  rep(i,k){
    int a,b;cin>>a>>b;
    a--;b--;
    if(!tree.same(a,b))continue;
    ab[a].emplace_back(b);
    ab[b].emplace_back(a);
  }
 
  rep(i,n){
    int ans = tree.size(i)-1;
    ans -= ab[i].size();
    cout<<ans<<" ";
    // print(tree.size(i));
  }
  cout<<endl;
  return 0;
}



Measured memory_bytes: 8320
#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define MOD 1000000007

using namespace std;
typedef long long int ll;

int main(void){
	// #ifndef ONLINE_JUDGE
	// freopen("in.txt", "r", stdin);
	// #endif
	fast;
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a+3);
	int ans = 1e9;
	do{
		int cur = 0 + abs(a[1]-a[0]) + abs(a[2]-a[1]);
		ans = min(cur, ans);
	}while(next_permutation(a, a+3));
	cout << ans;
}

Measured memory_bytes: 256