akhauriyash/Code-Regression huggingface dataset:
// AOJ Volume 1 Problem 0167 Bubble Sort

#include <stdio.h>

int num[1000000];

int main(void)
{
    int n;
    int i, j;
    int tmp;
    int cnt;
    
    while (1){
        scanf("%d", &n);

        if (n == 0){
            break;
        }
        
        for (i = 0; i < n; i++){
            scanf("%d", &num[i]);
        }

        cnt = 0;
        for (i = n - 1; i >= 0; i--){
            for (j = 0; j < i; j++){
                if (num[j] > num[j + 1]){
                    tmp = num[j];
                    num[j] = num[j + 1];
                    num[j + 1] = tmp;
                    cnt++;
                }
            }
        }
        
        printf("%d\n", cnt);
    }

    return (0);
}

Measured memory_bytes: 0
a,b = map(int,input().split())

if(a == 0 or b == 0):
  print("Zero")
elif(a<0 and b>0):
  print("Zero")
elif(a>0 and b>0):
  print("Positive")
elif(a<0 and b<0):
  if(b-a == 1):
    print("Positive")
  elif((b-a+1)%2 == 0):
    print("Positive")
  else:
    print("Negative")

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

int main() {

    ll n, l; cin >> n >> l;
    vector<ll> a(n); 
    for (ll i = 0; i < n; i++) cin >> a[i];

    vector<ll> rem(n, 0), r(n), s(n, 0x7FFFFFFF), t(n);
    for (ll i = 0; i < n; i++) {
        if (i && a[i] <= a[i-1]) rem[i]++;
        if (i < n-1 && a[i] <= a[i+1]) rem[i]++;
        r[i] = l - a[i];
        if (!rem[i]) {
            s[i] = 0;
            t[i] = s[i] + r[i];
        }
    }
    auto compf = [&](ll i, ll j) -> bool {
        return t[i] > t[j];
    };
    priority_queue<ll, vector<ll>, decltype(compf)> q(compf);

    for (ll i = 0; i < n; i++) {
        if (!rem[i]) {
            q.push(i);
        }
    }

    while (!q.empty()) {
        ll i = q.top(); q.pop();
        if (i-1 >= 0 && rem[i-1]) {
            rem[i-1]--;
            if (!rem[i-1]) {
                s[i-1] = t[i];
                t[i-1] = s[i-1] + r[i-1];
                q.push(i-1);
            }
        }
        if (i+1 < n && rem[i+1]) {
            rem[i+1]--;
            if (!rem[i+1]) {
                s[i+1] = t[i];
                t[i+1] = s[i+1] + r[i+1];
                q.push(i+1);
            }
        }
    }

    cout << *max_element(t.begin(), t.end()) << endl;

}


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

ll d[55][55];
int A, B, N, P;

int main() {
	for(int i = 0; i < 55; i++) {
		for(int j = 0; j <= i; j++) {
			if(!j || i == j) d[i][j] = 1;
			else d[i][j] = d[i-1][j] + d[i-1][j-1];
		}
	}
	cin >> N >> P;
	for(int i = 0, c; i < N; i++) {
		cin >> c;
		((c&1) ? B : A)++;
	}
	swap(A, B);
	if(P) {
		ll Ans = 0;
		for(int i = 1; i <= A; i += 2) {
			Ans += (1ll << B) * d[A][i];
		}
		cout << Ans << endl;
	} else {
		ll Ans = 0;
		for(int i = 0; i <= A; i += 2) {
			Ans += (1ll << B) * d[A][i];
		}
		cout << Ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

int main() {
    int n; cin >> n;
    vector<int> arr(n);
    rep(i, n) cin >> arr[i];
    priority_queue<int, vector<int>, greater<int>> Q;

    int cnt = 0;
    for (auto p: arr) {
        Q.push(p);
        if (p <= Q.top()) {
            cnt++;
        }
        Q.push(p);
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3188
n = gets.to_i

a = [*1..9]
b = [*1..9]
sum = 0

a.each do |x|
  b.each do |y|
    if x * y == n
      sum += 1
    end
  end
end

if sum > 0
  puts "Yes"
else
  puts "No"
end

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

ll solve(ll h){
	if(h==1)return 1;
	return 2LL*solve(h/2)+1;
}

int main(void){
	ll h;
	scanf("%lld",&h);
	printf("%lld\n",solve(h));
	return 0;
}


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

int N,Q;
vector<int> v;
bool f(int a,int x){//青木ゾーンは長さがa以上か
  int A=v[N-a]-x;//高橋が伸ばした長さ
  if(A<0)return false;
  //高橋くんはa手かけてるわけで、青木くんがv[N-a-1]をa-1手以内にとるならfalse
  //値がx-A以上x+A未満の個数がa-2以下ならfalse
  if(v.begin()+N-a-lower_bound(v.begin(),v.end(),x-A)<a-1)return false;
  return true;
}

int w[123456],kougo[123456];
int g(int l){
  return w[l]+kougo[N-2*l+1];
}

signed main(){
  cin>>N>>Q;
  vector<int>q(Q);
  v.resize(N);
  for(int i=0;i<N;i++)cin>>v[i];
  for(int i=0;i<Q;i++)cin>>q[i];
  //各q[i]に対してのそれは 交互、高橋、青木　になるはずなので青木ゾーンがどこまでか求められればいい
  //これはにぶたんで求められる気がする
  for(int i=0;i<N;i++)w[i+1]=w[i]+v[N-i-1];
  for(int i=0;i<N;i++)kougo[i+2]=kougo[i]+v[i];
  //for(int i=0;i<10;i++)cout<<w[i]<<" ";cout<<endl;
  //for(int i=0;i<10;i++)cout<<kougo[i]<<" ";cout<<endl;
  for(int i=0;i<Q;i++){
    int l=0,r=N/2+2;//青木ゾーンの長さ
    while(r-l>1){
      int m=(r+l)>>1;
      if(f(m,q[i]))l=m;
      else r=m;
    }
    //cout<<i<<" "<<l<<endl;
    cout<<g(l)<<endl;
  }
}


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

using namespace std;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
    ifstream t("/proc/self/status");
    cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getchar());
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) - '0' + ch;
	return sum * fg;
}

typedef long long LL;
typedef long double LD;
typedef pair<int, int> pii;

const int MOD = (int) 1e9 + 7;
const int MAXN = (int) 1e5;

int n, m;

int a[MAXN + 5], b[MAXN + 5];

inline void input()
{
	n = read<int>(), m = read<int>();
	for(int i = 1; i <= n; ++i) a[i] = read<int>();
	for(int i = 1; i <= m; ++i) b[i] = read<int>();
}

int L;

vector<pii> p;

inline void discrete()
{
	static vector<int> tmp;

	tmp.clear();
	for(auto it : p) tmp.push_back(it.fst);
	sort(ALL(tmp)), tmp.erase(unique(ALL(tmp)), tmp.end());
	for(int i = 0; i < SZ(p); ++i) p[i].fst = lower_bound(ALL(tmp), p[i].fst) - tmp.begin() + 1;

	tmp.clear();
	for(auto it : p) tmp.push_back(it.snd);
	sort(ALL(tmp)), tmp.erase(unique(ALL(tmp)), tmp.end());
	for(int i = 0; i < SZ(p); ++i) p[i].snd = lower_bound(ALL(tmp), p[i].snd) - tmp.begin() + 1;
	L = SZ(tmp);
}

namespace BIT
{
	int c[MAXN + 5];

	inline void add(int p, int val) { while(p <= L) (c[p] += val) %= MOD, p += p & -p; }
	inline int prefix(int p) { int res = 0; while(p) (res += c[p]) %= MOD, p -= p & -p; return res; }
}

inline bool cmp(const pii &lhs, const pii &rhs) { return lhs.fst == rhs.fst ? lhs.snd > rhs.snd : lhs.fst < rhs.fst; }

inline void solve()
{
	static set<int> T;
	for(int i = 1; i <= m; ++i)
	{
		static set<int>::const_iterator lst = T.begin();
		lst = T.insert(lst, b[i]);
	}

	for(int i = 1; i <= n; ++i)
	{
		auto it = T.lower_bound(a[i]);
		if(it != T.begin() && it != T.end()) p.emplace_back(a[i] - *prev(it), *it - a[i]);
	}

	discrete();
	sort(ALL(p), cmp), p.erase(unique(ALL(p)), p.end());

	int ans = 0;
	for(auto it : p)
	{
		int res = BIT::prefix(it.snd - 1) + 1;
		BIT::add(it.snd, res), (ans += res) %= MOD;
	}
	printf("%d\n", (ans + 1) % MOD);
}

int main()
{
//#ifndef ONLINE_JUDGE
//	freopen("F.in", "r", stdin);
//	freopen("F.out", "w", stdout);
//#endif

	input();
	solve();

	return 0;
}



Measured memory_bytes: 7544
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,i,j;cin>>n;
 	int A[n];
  vector<int> dp(n,1000000007);
  for( i=0;i<n;i++)
    cin>>A[i];
  dp[0]=0;
  for(i=0;i<n;i++)
  {	
    for(j=i+1;j<=i+2;j++)
    {
     	if(j<n)
		dp[j]=min(dp[j],dp[i]+abs(A[j]-A[i]));
    }
  }
  cout<<dp[n-1];
}

  

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define INF 1e18
#define MOD 1000000007
#define PI M_PI
#define ll long long
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define REP(i, n) for (int i=0; i<n; i++)
#define REPD(i, n) for (int i=n-1; i>=0; i--)
#define print(x) cout << x << endl;
#define debug(x) cout << #x << " = " << endl;

using namespace std;

void solve()
{
    int N;
    cin >> N;
    vector<int> V(N), C(N);
    REP(i, N) cin >> V[i];
    REP(i, N) cin >> C[i];

    int ans = 0;
    REP(i, N) {
        int d = V[i] - C[i];
        if (d < 0) {
            continue;
        } else {
            ans += d;
        }
    }
    print(ans);
}

int main()
{
    solve();

    return 0;
}


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

using namespace std;

typedef long long int ll;
typedef pair<int,int> P;

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	int k;
	string s;
	cin>>k>>s;
	if(s.length() <= k)cout<<s<<endl;
	else{
		rep(i,k)cout<<s[i];
		cout<<"..."<<endl;
	}
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
int main()
{
	int n,tmp[4];
	while(true){
		cin>>n;
		int ans=0;
		if(n==0000)break;
		while(true){
			tmp[0]=n/1000;
			tmp[1]=(n/100)-10*tmp[0];
			tmp[2]=(n/10)-100*tmp[0]-10*tmp[1];
			tmp[3]=n%10;
			sort(tmp,tmp+4);
			int l=tmp[3]*1000+tmp[2]*100+tmp[1]*10+tmp[0];
			int s=tmp[0]*1000+tmp[1]*100+tmp[2]*10+tmp[3];
			if(tmp[0]==tmp[3]){
				ans=-1;
				break;
			}else if(n==6174){
				break;
			}else{
				n=l-s;
				ans++;
			}
		}
		if(ans<0)printf("NA\n");
		else printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1164
# coding: utf-8
# Here your code !
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

s = input().split(" ")
s = [int(i) for i in s]
x = s[0] * s[1]
if x % 2 == 0 : 
    print("Even")
else : 
    print("Odd")

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

int main() {
  string S;
  cin >> S;
  
  vector<int> moji(26, 0);
  
  for (int i = 0; i < S.size(); i++) {
    moji[S[i] - 'a']++;
  }
  
  for (int i = 0; i < 26; i++) {
    if (moji[i] != 0 && moji[i] != 1) {
      cout << "no" << endl;
      return 0;
    } 
  }
  
  cout << "yes" << endl;
  
}

Measured memory_bytes: 3556
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
using namespace std;

long long const mod = 1e9 + 7;

long long binpow (long long n) {
	long long a = 1;
    for(int i = 0; i < n - 1; ++i) a = (a * 4) % mod;
    return a;
}

int main(){
    long long n;
    cin >> n;
    vector<long long> a(n);
    for(int i = 0; i < n; ++i) cin >> a[i];
    long long st = binpow(n);
    sort(a.rbegin(), a.rend());

    long long ans = 0;
    for(int i = 0; i < n; ++i){
        ans = (ans + a[i] * (i + 2)) % mod;
    }
    cout << (ans * st) % mod;
}

Measured memory_bytes: 1792
// 残った素からコスト最小のドーナツをできる限り多く作る.
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
  int n,x,sum=0; cin >> n >> x;
  vector<int> v;
  for(int i=0;i<n;i++){
    int m; cin >> m; sum+=m;
    v.push_back(m);
  }
  sort(v.begin(), v.end());
  cout << n+(x-sum)/v[0] << endl;
  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N = int(input())
A = list(map(int, input().split()))


res = 0
i=0

while(i<N):    
    #same
    while(i+1 < N and A[i] == A[i+1]):
        i+=1
    
    #up
    if(i+1 < N and A[i] < A[i+1]):
        while(i+1 < N and A[i] <= A[i+1]):
            i+=1
    
    #down
    elif(i+1 < N and A[i] > A[i+1]):
        while(i+1 < N and A[i] >= A[i+1]):
            i+=1

    res+=1
    i+=1
   


print(res)


Measured memory_bytes: 20420
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  vector<int> h(N);
  REP(i,N) cin >> h[i];
  sort ALL(h);
  int M=INF;
  REP(i,N-K+1) {
    M=min(M,(h[i+K-1]-h[i]));
  }
  cout <<  M << endl;;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		int r = Integer.parseInt(std.next());
		int c = Integer.parseInt(std.next());
		int table[][] = new int[r+1][c+1];
		for(int i=0; i<=r-1; i++){
			int rsum = 0;
			for(int j=0; j<=c; j++){
				if(j<c){
					table[i][j] = Integer.parseInt(std.next());
					rsum += table[i][j];
				}else{
					table[i][j] = rsum;
				}
			}
		}
		for(int j=0; j<=c; j++){
			int csum = 0;
			for(int i=0; i<=r; i++){
				if(i<r){
					csum += table[i][j];
				}else{
					table[i][j] = csum;
				}
			}
		}
		for(int i=0; i<=r; i++){
			String line = String.valueOf(table[i][0]);
			for(int j=1; j<=c; j++){
				line += ( " "+ String.valueOf(table[i][j]));
			}
			System.out.println(line);
		}
	}
}

Measured memory_bytes: 50804
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define fo(i,n) for(ll i=0;i<n;i++)
#define fo1(i,n) for(ll i=1;i<=n;i++)
#define loop(i,a,b)for(ll i=a;i<=b;i++)
#define loopr(i,a,b)for(ll i=b;i>=a;i--)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define vll vector<ll>
#define vvl vector<vll>
#define pll pair<ll,ll>
#define F first
#define S second
#define MOD 1000000007
ll max(ll a,ll b){if (a>b) return a; else return b;}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll lcm(ll a, ll b){return a*b/gcd(a, b);}
ll fexp(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%MOD; b/=2;a=a*a%MOD;}return ans;}
ll inverse(ll a, ll p){return fexp(a, p-2);}
ll func(vvl mat,ll &ans){
    fo(i,3){
        fo(j,3){
            
        }
    }
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll T=1;
      // cin >> T;
	ll t=0;
	while(t++<T){
    ll N;
    cin >> N;
    vll v(N);
    fo(i,N) cin >> v[i];
    ll ans=0;
    sort(v.begin(),v.end());
    for(int i=0;i<=N-2;i++){
        for(int j=i+1;j<=N-2;j++){
            for(int z=j+1;z<=N-1;z++){
                if(v[i]!=v[j] && v[j]!=v[z] && v[i]!=v[z] && v[i]+v[j]>v[z] && v[i]+v[z]>v[j] && v[j]+v[z]>v[i]) ans++;
            }
        }
    }
    cout << ans << endl;
	}
return 0;
}

Measured memory_bytes: 3652
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   ff   first
#define   ss   second
#define   pii  pair<int,int>
using namespace std;

inline void solve(){
    int n,ans=0; cin>>n; 
    ld T,A; cin >> T >> A ; 
    ld  a[n], dif=10000 ; 
    for (int i=0;i<n;i++) { 
        cin >> a[i] ; 
        ld  h = T-(a[i]*0.006); 
        if (abs(A-h)<dif){
          dif = abs(A-h); 
          ans = i+1;
        }
    } 
    cout << ans << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x,ans=1; cin>>x;
  for(int b=2; b<=x; b++){
    int tmp=b*b;
    while(tmp<=x){
      ans=max(ans,tmp);
      tmp*=b;
    }
  }
  cout<<ans;
}

Measured memory_bytes: 256
#include <stdio.h>

int main (void)
{
	int d,t,s;
	double a;
	
	scanf("%d %d %d",&d,&t,&s);
	
	a=(double)d/(double)s;
	
	if(t>=a){
		printf("Yes");
		return 0;
	}
	printf("No");
	return 0;
}


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

const int N = 1e3;
const int INF = 1e8;

int h,n;
int a[N+5],b[N+5];

int memo[10*N+5][N+5];

int dp(int x, int id){
	if(x <= 0) return 0;
	if(id <= 0) return INF;
	int &ret = memo[x][id];
	if(ret != -1) return ret;
	ret = min(dp(x-a[id],id) + b[id] , dp(x , id-1));
	return ret;
}

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

Measured memory_bytes: 40064
#include <bits/stdc++.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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    cout << (b - a + 1) * (b - a) / 2 - b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
int main() {
  string s,t;
  cin>>s>>t;
  bool ex=true;
  rep(i,s.size()){
    if(s.at(i)!=t.at(i)){
      ex=false;
    }
  }
  if(ex){
    cout<<"Yes"<<endl;
  }
 
  else{
    cout<<"No"<<endl;
  }
}




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

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

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

void gen_sosuu(int sosuu[]){
  REP(i,100010){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(100000)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<=100000;j++){
      //printf("%d %d %d\n",i*j,i,j);
      sosuu[i*j] =false;
    }
  }
}

ll n,m;

int main(){
  scanf("%lld %lld",&n,&m);
  if(n>m/2){
    printf("%lld\n",m/2);
    return 0;
  }
  ll x = (m/2-n)/2;
  printf("%lld\n",n+x);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define MAX(a,b) a=a>b?a:b
#define MIN(a,b) a=a>b?a:b
#define REP(i,x,n) for(int i=x;i<n;i++)
#define REPR(i,x,n) for(int i=n-1;i>=x;i--)
#define pb  push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLr(obj) (obj).rbegin(), (obj).rend()
#define endl "\n"
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
class Combination
{
    vector<long long> fact;
    vector<long long> factinv;
    long long MOD = 1e9 + 7;
    long long modpow(long long a, long long n)
    {
        if (n == 0)
            return 1;
        if (n % 2 == 0)
        {
            long long t = modpow(a, n / 2);
            return t * t % MOD;
        }
        return a * modpow(a, n - 1) % MOD;
    }

    long long modinv(long long a)
    {
        // mod is prime
        return modpow(a, MOD - 2);
    }

public:
    Combination(int n) : fact(n), factinv(n)
    {
        fact[0] = 1;
        for (int i = 1; i < n; i++)
        {
            fact[i] = fact[i - 1] * i % MOD;
        }
        factinv[n - 1] = modinv(fact[n - 1]);
        for (int i = n - 2; i >= 0; i--)
        {
            factinv[i] = factinv[i + 1] * (i + 1) % MOD;
        }
    }

    long long ncr(long long n, long long r)
    {
        if (r < 0 || r > n)
            return 0;
        return fact[n] * factinv[r] % MOD * factinv[n - r] % MOD;
    }

    long long npr(long long n, long long r)
    {
        if (r < 0 || r > n)
            return 0;
        return fact[n] * factinv[n - r] % MOD;
    }

    long long nhr(long long n, long long r)
    {
        if (n == 0 && r == 0)
            return 1;
        return ncr(n + r - 1, r);
    }
};



int main(){
    ll n,c[202020];
    cin>>n;
    Combination co(n*2+10);
    ll ka=1;
    cin>>c[0];
    rep(i,n-1){cin>>c[i+1];ka*=4;ka%=MOD;}
    ll D=1,ans=0,no=1;
    sort(c,c+n);
    repr(i,n){
        ans+=((c[i])*(n-i+1))%MOD;
        ans%=MOD;
    }
    cout<<(ka*ans)%MOD<<endl;

}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

long long int n=1,cnt=0,ans=0,a[1000000],b,c,cmp,data,m,h,x,y,xcmp=0,ycmp=0,sum=0;

string s,w;

vector<int> z;

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

  
       cin >> n;
       ans=n;
       long long int up=0,down=0;
       rep(i,n){
           cin >> a[i];
           //Cout(a[i]);
       }
       rep(i,n-1){
           
            if(a[i]==a[i+1]){
            ans--;
        }
       else if(a[i]<a[i+1]){
            up=1;
            if(down==1){
                up=0;
                down=0;
            }
            else{
                ans--;
            }
        }
        else{
            down=1;
            if(up==1){
                up=0;
                down=0;
            }
            else{
                ans--;
            }
        }
        }
       Cout(ans);
return 0;
}


Measured memory_bytes: 1024
n,k = map(int,input().split())
L = []
for i in range(n):
    a,b = map(int,input().split())
    L.append([a,b])
L.sort()
#print(L)
ans = 0
sum1 = 0
for i in range(n):
    sum1 +=L[i][1]
    ans = L[i][0]
    if sum1 >=k:
        print(ans)
        exit()

Measured memory_bytes: 20096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
const ll mod = 1e9+7;
ll fact[2002];
ll po(ll a, ll b){
    if(b==0)return 1;
    ll x = po(a,b/2);
    x = (x*x)%mod;
    if(b&1)x = (x*a)%mod;
    x%=mod;
    return x;
}
ll inv(ll x){
    return po(x,mod-2)%mod;
}
ll C(ll n,ll k){
    if(k<0)return 0;
    if(k>n)return 0;
    if(k==n)return 1;
    ll trt = fact[n];
    ll trt2 = inv(fact[k]);
    ll trt3 = trt2*inv(fact[n-k]);
    trt3%=mod;
    trt3*=trt;
    trt3%=mod;
    return trt3;
}
void solve(){
  ll n,k;
  cin>>n>>k;
  for(int i=1;i<=k;i++){
    ll ans = C(k-1,i-1)*C(n-k+1,i);
    ans%=mod;
    cout<<ans<<endl;
  }
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1;
	fact[0] = 1;
	for(int i=1;i<2002;i++){
        fact[i] = fact[i-1]*i;
        fact[i]%=mod;
	}
//	cin>> t;
	while(t--)solve();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

vector<int> enum_div(int n){
    vector<int> ret;
    for(int i = 1 ; i*i <= n ; ++i){
        if(n%i == 0){
            ret.push_back(i);
            if(i != 1 && i*i != n){
                ret.push_back(n/i);
            }
        }
    }
    return ret;
}

int main() {
    
    int n;
    cin>>n;
    vi a(n),b(n);
    rep(i,n)cin>>a[i];
    map<int,int> m;
    for(int i=n/2;i<n;i++){
        b[i]=a[i]%2;
        vi yakusu=enum_div(i+1);
        rep(j,yakusu.size())m[yakusu[j]]+=b[i];
    }
    for(int i=n/2-1;i>=0;i--){
        vi yakusu=enum_div(i+1);
        b[i]=1-(m[(i+1)]%2==a[i]);
        rep(j,yakusu.size())m[yakusu[j]]+=b[i];
    }
    int sum=0;
    rep(i,n-1)sum+=b[i+1];
    sum%=2;
    b[0]=1-(sum==a[0]);
    // rep(i,n){
    //     if(!i)cout<<b[0];
    //     else cout<<" "<<b[i];
    // }
    // cout<<endl;
    vi v;
    rep(i,n)if(b[i]>0)v.pb(i+1);
    //if(v.size()==0)fin(-1);
    {
        fin(v.size());
        rep(i,v.size()){
            if(!i)cout<<v[0];
            else cout<<" "<<v[i];
        }
    }
    if(v.size()>0)cout<<endl;
}


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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 210, M = 10, INF = 0x3f3f3f3f;

int n, m, k;
int r[M];
int f[N][N];

int main()
{
	cin >> n >> m >> k;
	for (int i = 0; i < k; i ++ ) cin >> r[i];
	sort(r, r + k);
	
	for (int i = 1; i <= n; i ++ )
		for (int j = 1; j <= n; j ++ )
			if (i == j) f[i][j] = 0;
			else f[i][j] = INF;
			
	for (int i = 0; i < m; i ++ )
	{
		int a, b, c;
		cin >> a >> b >> c;
		f[a][b] = f[b][a] = min(f[a][b], c);
	}
	
	for (int k = 1; k <= n; k ++ )
		for (int i = 1; i <= n; i ++ )
			for (int j = 1; j <= n; j ++ )
				f[i][j] = min(f[i][j], f[i][k] + f[k][j]);
				
	int res = INF;
	do
	{
		int sum = 0;
		for (int i = 0; i < k - 1; i ++ ) sum += f[r[i]][r[i + 1]];
		res = min(res, sum);
	}while (next_permutation(r, r + k));
	
	cout << res << endl;
	return 0;
}

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

int main()
{
	string input, search;
	cin >> input;
	cin >> search;
	int i = 0;
	int search_length = search.length();
	int input_length = input.length();
	bool isMake = false;
	for (int i = 0; i < input_length; i++)
	{
		string out = "";
		for (int j = 0; j < search_length; j++)
		{
			if (i + j < input_length)
				out += input[i + j];
			else
				out += input[i + j - input_length];
		}
		if (out == search) isMake = true;
	}
	if (isMake) cout << "Yes";
	else cout << "No";
	cout << endl;
}


Measured memory_bytes: 3224
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <numeric>
#include <string>
#include <bitset>
#include <functional>

using ld = long double;
using vld = std::vector<ld>;
using vvld = std::vector<vld>;
using vvvld = std::vector<vvld>;
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
using pll = std::pair<ll, ll>;
using vpll = std::vector<pll>;
using str = std::string;
using vstr = std::vector<str>;

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

constexpr ld PI = 3.141592653589793L;
constexpr ld EPS = std::numeric_limits<ld>::epsilon();

ll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }
bool isprime(ll n) {
    if (n == 1) return false;
    for (ll i = 2; i * i <= n; i++)
        if (n % i == 0) return false;
    return true;
}
ll rpow(ll x, ll n) {
    if (n == 0) return 1;
    ll k = 1;
    for (; n > 1; n /= 2) {
        if (n & 1) k *= x;
        x *= x;
    }
    return k * x;
}
ll modpow(ll x, ll n, ll mod) {
    if (n == 0) return 1;
    ll k = 1;
    for (; n > 1; n /= 2) {
        if (n & 1) (k *= x) %= mod;
        (x *= x) %= mod;
    }
    return k * x % mod;
}
ll modcomb(ll n, ll r, ll mod) {
    if (r < 0 || n < r) return 0;
    chmin(n - r, r);
    ll mul = 1, div = 1;
    for (ll i = 0; i < r; i++) {
        (mul *= n - i) %= mod;
        (div *= i + 1) %= mod;
    }
    return mul * modpow(div, mod - 2, mod) % mod;
}

/*------------------------------------------------------------------------*/

void solve();

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15);

    solve();
}
void solve() {
    ll l, r, d;
    std::cin >> l >> r >> d;

    ll ans = r / d - (l - 1) / d;

    std::cout << ans << '\n';
}


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

int main()
{
    int n;
    std::cin >> n;
    int cnt = 0;
    for (int i = 0; i < n; ++i)
    {
        int a, b;
        std::cin >> a >> b;
        if (a == b)
            cnt++;
        else
            cnt = 0;
        if (cnt == 3)
        {
            std::cout << "Yes" << std::endl;
            return 0;
        }
    }
    std::cout << "No" << std::endl;
    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main(){
 int h,w;
 cin>>h>>w;
 vector<string> vec;
 for(int i=0;i<h;i++){
  string t;
  cin>>t;
  vec.push_back(t);
 }
 int ans=0;
 for(int i=0;i<h;i++){
  for(int j=0;j<w;j++){
   if(vec[i][j]=='#'){
    ans++;
   }
  }
 }
 if(ans==h+w-1){
  cout<<"Possible"<<endl;
 }else{
  cout<<"Impossible"<<endl;
 }
 return 0;
}
 

Measured memory_bytes: 256
n = int(input())
dat_s = []
for i in range(n):
    dat_s.append(int(input()))

# 0個選択したときのスコア(重複は意味がないのでset)
scores = set([0])

# 1～n問まで回す
for i in range(n):
    # ここまでで可能性のあるスコアをbufferにいれて
    b = set(scores)
    while len(b) != 0:
        # いまのn問目のスコアをこのスコアに足していく
        scores.add(dat_s[i] + b.pop())

# 可能性のあるスコアの中から10で割り切れるスコアは消す(=0にする)
scores = map(lambda x: 0 if x % 10 == 0 else x, scores)
print(max(scores))


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

#define FI(i,a,b) for(int i=(a);i<=(b);i++)
#define FD(i,a,b) for(int i=(a);i>=(b);i--)

#define LL long long
#define Ldouble long double
#define PI 3.1415926535897932384626

#define PII pair<int,int>
#define PLL pair<LL,LL>
#define mp make_pair
#define fi first
#define se second

using namespace std;

int n, s[100005], hl, pv;
LL cumu, val, ans[100005];

struct item{
	int id, star, cnt;
	bool operator<(const item &k) const{
		if(cnt != k.cnt) return cnt < k.cnt;
		else return id < k.id;
	}
};

item u[100005];

int main(){
	scanf("%d", &n);
	u[0] = (item){0, 1, 0};
	FI(i, 1, n){
		scanf("%d", &s[i]);
		if(s[i] > s[pv]){
			pv = i;
			hl = true;
		}
		else hl = false;
		u[i] = (item){i, hl, s[i]};
	}
	
	sort(u, u + n + 1);
	pv = -1;
	
	FD(i, n, 0){
		cumu += u[i].cnt;
		if(u[i].star){
			if(pv != -1){
				ans[pv] = cumu - 1LL * (n + 1 - i) * u[i].cnt - val;
				val = cumu - 1LL * (n + 1 - i) * u[i].cnt;
			}
			pv = u[i].id;
		}
	}
	FI(i, 1, n) printf("%lld\n", ans[i]);
	return 0;
}


Measured memory_bytes: 3456
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		String out = "";
		Scanner scan = new Scanner(System.in);
		scan.useDelimiter(",|\n");
		out = out +  scan.next() + " ";
		out = out +  scan.next() + " ";
		out = out +  scan.next();
		System.out.println(out);
		scan.close();
	}
}

Measured memory_bytes: 9556
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int[][] c = new int[3][3];
		int[] a = new int[3];
		int[] b = new int[3];
		boolean flag = false;

		for(int i = 0; i < 3; i++) {
			for(int j = 0; j < 3; j++) {
				c[i][j] = sc.nextInt();
			}
		}

		for(int i = 0; i <= 100; i++) {
			a[0] = i;
			b[0] = c[0][0] - i;
			b[1] = c[0][1] - i;
			b[2] = c[0][2] - i;
			a[1] = c[1][0] - b[0];
			a[2] = c[2][0] - b[0];
			flag = true;
			for(int m = 0; m < 3; m++) {
				for(int k = 0; k < 3; k++) {
					if(c[m][k] != (a[m] + b[k])) flag = false;
				}
			}
			if(flag) break;
		}

		System.out.println(flag ? "Yes" : "No");
		sc.close();
	}
}

Measured memory_bytes: 21844
#include <iostream>
 
using namespace std;
int main() {
  int N; cin>>N;
  int K; cin>>K;
  char S[N];
    for(int x=0; x<N ; x++){
      char a; cin>>a;
      S[x]= a;
    }
  S[K-1]+=32;
  for(int b=0; b<N ;b++){
    cout<< S[b];
  }
  return 0;
}

Measured memory_bytes: 888
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
int main(){
  ll k;
  cin>>k;
  int n=50;
  ll array[50];
  for(int i=0;i<50;i++) array[i]=49+(k/n);
  for(int i=0;i<(k%n);i++){
    array[i]+=n;
    for(int j=0;j<n;j++){
      if(i!=j) array[j]--;
    }
  }
  cout<<n<<endl;
  for(int i=0;i<n-1;i++) cout<<array[i]<<" ";
  cout<<array[n-1]<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
using vint = vector<int>;
using ll = long long;
using vll = vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }
void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }

int main() {
    string a, b; cin >> a >> b;
    cout << b << a << endl;
    return 0;
}


Measured memory_bytes: 256
a,b,c,x = 4.times.map{ gets.to_i }

cnt = 0

(0..a).each do |i|
  (0..b).each do |m|
    (0..c).each do |n|
      cnt += 1 if i * 500 + m * 100 + n * 50 == x
    end
  end
end

puts cnt

Measured memory_bytes: 3836
n = int(input())
array = []
for i in range(n):
    a, b = map(int, input().split())
    array.append((a, b))
array = sorted(array, key=lambda b: b)
#print(array)

prev = 0
num_person = 0
for a in array:
    num_person += (a[0] - prev)
    prev = a[0]

if n > 0:
    num_person += array[len(array) - 1][1]

print(num_person)


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmin(x, y) x = min(x, y)
using namespace std;

const int MAX = 310;
const long long INF = 1LL << 50;

long long G[MAX][MAX];
long long G2[MAX][MAX];

int main(void) {
    int N, M;
    long long L;
    cin >> N >> M >> L;

    rep(i, N) {
        rep(j, N) {
            G[i][j] = INF;
            G2[i][j] = INF;
        }
        G[i][i] = 0;
        G2[i][i] = 0;
    }

    rep(i, M) {
        int a, b;
        long long c;
        cin >> a >> b >> c;
        --a;
        --b;
        G[a][b] = G[b][a] = c;
    }

    rep(k, N) rep(i, N) rep(j, N) chmin(G[i][j], G[i][k] + G[k][j]);

    rep(i, N) rep(j, N) if (G[i][j] <= L) G2[i][j] = 1;

    rep(k, N) rep(i, N) rep(j, N) chmin(G2[i][j], G2[i][k] + G2[k][j]);


    int Q;
    cin >> Q;
    rep(i, Q) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;

        long long res = G2[a][b] - 1;
        if (G2[a][b] == INF) res = -1;

        cout << res << endl;
    }
}


Measured memory_bytes: 2048
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.close();
		
		int ans = 1;
		while(true) {
			if(ans * 2 > N)break;
			ans *= 2;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 24020
while 1:

    # input を分割する
    input_list = input().split()

    # input をそれぞれの変数に格納する
    a = int(input_list[0])
    op = input_list[1]
    b = int(input_list[2])
    
    if op == "?":
        break
    elif op == "+":
        print("%d"%(a+b))
    elif op == "-":
        print("%d"%(a-b))
    elif op == "*":
        print("%d"%(a*b))
    elif op == "/":
        print("%d"%(a/b))


Measured memory_bytes: 5592
n = int(input())
*x, = map(int, input().split())
x.sort()
mid = (x[0] + x[n-1]) // 2
ans = float('inf')

for i in range(x[0], x[n-1]+1):
    tmp = 0
    for j in x:
        tmp += (j - i)*(j - i)
    ans = min(ans, tmp)
print(ans)

Measured memory_bytes: 3064
import sys
input = sys.stdin.buffer.readline

def main():
    N, K = map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()
    l, r = 0, N-1
    MOD = 10**9+7
    if K == N:
        ans = 1
        for num in A:
            ans *= num
            ans = (ans+MOD)%MOD
        print((ans+MOD)%MOD)
        exit()
    elif A[-1] < 0 and K%2 == 1:
        ans = 1
        for i in range(K):
            ans *= A[-i-1]
            ans = (ans+MOD)%MOD
        print(ans)
        exit()
    ans = 1
    if K%2 == 1:
        ans *= A[-1]
        r -= 1
    for _ in range(K//2):
        nl = A[l]*A[l+1]
        nr = A[r]*A[r-1]
        if nl > nr:
            ans *= nl
            l += 2
        else:
            ans *= nr
            r -= 2
        ans = (ans+MOD)%MOD
    print(ans)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 100712
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
//#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF (1<<31)-1;
#define mem(a) (memset(a,0,sizeof(a)))
struct P{
    int x,y;
}H[200000];
vector<int>G[200000];
int POS(int k,int value){
    int mid;
    int left = 0;
    int len = G[k].size();
    int right = len - 1;
    //cout<<" "<<k<<"A"<<value<<endl;
    while(left <= right)
	{
        mid = left + (right-left)/2;
        if(G[k][mid] == value) return mid;
        else if(G[k][mid] > value) right = mid;
        else left = mid + 1;
    }
    return -1;
}
set<int>::iterator it;
int main()
{
    set<int>s;
    int N,M;
    int x,y;
    cin>>N>>M;
    for(int i=1;i<=M;i++){
        cin>>x>>y;
        H[i].x = x;
        H[i].y = y;
        G[x].push_back(y);
        s.insert(x);
    }
    for(int i=1;i<=N;i++){
        sort(G[i].begin(),G[i].end());
    }
 
 
    for(int i=1;i<=M;i++){
        cout<<setw(6)<<setfill('0')<<H[i].x;
        cout<<setw(6)<<setfill('0')<<POS(H[i].x,H[i].y)+1<<endl;
    }
    return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vst = vector<st>;
using vchar = vector<char>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007;

int main(){
  ll n, y;
  cin >> n >> y;
  rep(i, 0, n + 1)rep(j, 0, n - i + 1) if(10000 * i + 5000 * j + 1000 * (n - i - j) == y){
    cout << i << " " << j << " " << n - i - j << endl;
    return 0;
  }
  cout << "-1 -1 -1" << endl;
}

Measured memory_bytes: 256
N, A, B, C, D = map(int,input().split())
st = input()
if C == D :
  print("No")
elif C < D:#連続で岩が置かれていなければおっけー
  flag = 0
  st1 = st[A-1:C]
  for i in range(len(st1)-1):
    if st1[i:i+2] == "##":
      flag = 1
      
  st1 = st[B-1:D]
  for i in range(len(st1)-1):
    if st1[i:i+2] == "##":
      flag = 1
  if flag :
    print("No")
  else:
    print("Yes")
    
else:#入れ替わりを行う必要がある
  flag = 0
  irekaeble = 0
  st1 = st[A-1:C]
  for i in range(len(st1)-1):
    if st1[i:i+2] == "##":
      flag = 1
      
  st1 = st[B-1:D]
  for i in range(len(st1)-1):
    if st1[i:i+2] == "##":
      flag = 1
      
  st1 = st[B-2:D+1]
  for i in range(len(st1)-2):
    if st1[i:i+3] == "...":
      irekaeble = 1
  
  if flag or irekaeble == 0:
    print("No")
  else:
    print("Yes")

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int main()
{
    int i=0;
    char s[19];
    cin >> s;
    while(i<5)
{
        cout << s[i];
        i++;
}
i++;
cout<<" ";
    while(i<13)
{
        cout << s[i];
        i++;
}
i++;
cout<<" ";
    while(i<19)
{
        cout << s[i];
        i++;
}
    return 0;
}

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

#define MAX(p,q) ((p>q)?(p):(q))
#define MIN(p,q) ((p<q)?(p):(q))

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

int gcd(int a,int b);

int main(void)
{
  int n;
  scanf("%d",&n);
  int ans;
  ans = (n%2==0)? n:n*2;
  printf("%d",ans);
  return 0;
}

int gcd(int a,int b)
{
  int max,min,tmp;
  max = MAX(a,b);
  min = MIN(a,b);
  if(max%min==0) return min;
  else
  {
    tmp = min;
    min = max%min;
    max = tmp;
    return gcd(max,min);
  }
}


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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  while(1){
    int n;
    cin >> n;
    if(n==0) return 0;
    vector<int> a(n);
    for(int i=0;i<n;i++){
      cin >> a[i];
    }
    sort(all(a));
    int ans=1000000000;
    for(int i=0;i<n-1;i++){
      ans=min(ans,a[i+1]-a[i]);
    }
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3172
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;




int main(){

	int A,B,C;

	scanf("%d %d %d",&A,&B,&C);

	int ans = C,left = 0,right= C,mid = (left+right)/2;

	while(left <= right){

		if(mid*A+mid/7*B >= C){

			ans = mid;
			right = mid-1;

		}else{

			left = mid+1;
		}
		mid = (left+right)/2;
	}

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

	return 0;
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+10 , OO = 0x3f3f3f3f;

#define clr(arr,val) memset(arr , val , sizeof (arr))
#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n)-1;i >= 0;i--)
#define xloop(i,a,b) for(int i = int(a);i <= int(b);i++)
#define range(n) for(int &x : n) cin >> x;
#define ALL(v) ((v).begin()) , ((v).end())
#define SZ(v)  ((int)((v).size()))
typedef pair <int,int> pii ;
typedef vector < pii > vii ;
typedef vector < int > vi;
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);


int n,x;
vector < int > perm ,a,b;
vector < pair < vector<int> , int > > ans;
void calc(int x){
      for(int i = 1 ; i <= x ; ++i)
            perm.push_back(i);
      int cnt = 1;
      do{
            ans.push_back({perm , cnt});
            cnt++;
      }while (next_permutation(ALL(perm)));
      

}


int main()
{   

      ios_base::sync_with_stdio(0) , cin.tie(0);cout.tie(0);


      cin >> n;
      calc(n);
      loop(i,n){
            cin >> x;
            a.push_back(x);
      }
      loop(i,n){
            cin >> x;
            b.push_back(x);
      }
      int sz = SZ(ans);
      bool ok1 = 0 , ok2 = 0;
      int pos1 = 0 , pos2 = 0;
      for(int i = 0 ; i < sz; ++i){
            if(ans[i].first == a && !ok1)
                  pos1 = ans[i].second , ok1 = 1;
            if(ans[i].first == b && !ok2)
                  pos2 = ans[i].second , ok2 = 1;
      }
      cout << abs(pos1-pos2) << "\n";

      return 0;
}

Measured memory_bytes: 3828
#include <iostream>
#define __ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;

long long a[100050],b[100050];

int main()
{
	long long i,j,n,k,ans=0,tmp,test;
	cin >> n >> k;
	for(i=0;i<n;i++)
		cin >> a[i] >> b[i],ans+=((a[i]|k)==k) ? b[i] : 0;
	//cout << ans << "\n";
	for(i=1;i<30;i++) 
	{
		if(!(k>>i&1)) continue;
		tmp=0,test=(k>>i<<i)-1;
		for(j=0;j<n;j++) tmp+=((a[j]|test)==test) ? b[j] : 0;
		//cout << i << " " << test << " " << tmp << "\n";
		ans=max(ans,tmp); 
	}
	cout << ans << "\n";
}

Measured memory_bytes: 1920
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int x,y,s;
	while(cin>>x>>y>>s&&x&&y&&s){
		int p1,p2,maxx,maxy=0,maxz;
		for(p1=1;p1<s;p1++){
		   for(p2=p1;p2<s;p2++){
		       maxx=p1*(100+x)/100+p2*(100+x)/100;
		       if(maxx==s){
		          maxz=p1*(100+y)/100+p2*(100+y)/100;
		          maxy=max(maxy,maxz);
             }
	       }
		}
	   cout<<maxy<<endl;
	}
}

Measured memory_bytes: 1160