akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h> 
#include<cmath>
#include<string>
#define pb push_back
#define x first
#define y second
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
//void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
// look for  all edge cases
//search for a pattern




signed main() {    
	ios::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);
	
	int d,s,t;
	cin >> d >> s >> t;
	
	int val = t*s;
	if(val >= d){
		cout<<"Yes\n";
	}
	else
		cout<<"No";
	
	 
	return 0;
}


Measured memory_bytes: 3636
n = int(input())
xyh = [list(map(int, input().split())) for _ in range(n)]

for x, y, h in xyh:
    if h > 0:
        x0, y0, h0 = x, y, h
        break

ans = [None] * 3
for cx in range(101):
    for cy in range(101):
        top = h0 + abs(x0 - cx) + abs(y0 - cy)
        bl = True
        for x, y, h in xyh[1:]:
            h_calc = max(top - abs(x - cx) - abs(y - cy), 0)
            if h_calc != h:
                bl = False
                break

        if bl:
            ans = [cx, cy, top]

print(*ans)


Measured memory_bytes: 9216
#include<cstdio>
#include<iostream>
#include<cstring>
#define maxn 100005
using namespace std;
char a[maxn],b[maxn];
char f[maxn];
int main(){
	f['b']='d';f['d']='b';
	f['p']='q';f['q']='p';
	cin>>a;int la=strlen(a);
	for(int i=la-1;i>=0;i--){
		b[i]=f[a[la-i-1]];
	}
	int tip=0;
	for(int i=0;i<=la-1;i++){
		if(b[i]!=a[i]){
			tip=1;break;
		}
	}
	if(tip==0) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 384
#include"iostream"
using namespace std;

int main()
{
	int h, w;
	cin >> h >> w;
	char a[110][110];
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			cin >> a[i][j];
		}
	}
	int check = 0;

	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			if (a[i][j] == '#')
			{
				check++;
				break;
			}
		}
		if (check == 0)
		{
			for (int i1 = i; i1 < h; i1++)
			{
				for (int j = 0; j < w; j++)
				{
					a[i1][j] = a[i1 + 1][j];
				}
			}
			i--;
			h--;
		}
		check = 0;
	}


	for (int j = 0; j < w; j++)
	{
		for (int i = 0; i < h; i++)
		{
			if (a[i][j] == '#')
			{
				check++;
				break;
			}
		}
		if (check == 0)
		{
			for (int j1 = j; j1 < w; j1++)
			{
				for (int i = 0; i < h; i++)
				{
					a[i][j1] = a[i][j1 + 1];
				}
			}
			j--;
			w--;
		}
		check = 0;
	}

	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			cout << a[i][j];
		}
		cout << endl;
	}
}

Measured memory_bytes: 384
#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 all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
  int n, k; cin >> n >> k;
  cout << n - (k -1) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#define int long long
#define endre getchar();getchar();return 0
using namespace std;
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return (y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int n) {
	if (n == 0)return 1;
	return kai(n - 1)*n;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int n, a, cnt, ans=100000;
signed main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a;
		cnt += a;
		ans = min(ans, cnt / i);
	}
	cout << ans << endl;
	endre;
}


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

using namespace std;

int main() {
    int a[3],ans=0;
    for(int i=0;i<3;++i)
        cin>>a[i];
    while(true) {
        //333/334/355/335/344/345
        stable_sort(a,a+3);
        if(a[2]-a[0]>2)
            a[0]+=2,++ans;
        else{
            if(a[0]==a[1]&&a[1]==a[2]) {
                ans+=0;
                break;
            }
            else if(a[0]==a[1]&&a[1]+1==a[2]) {
                ans+=1;
                break;
            }
            else if(a[0]+2<=a[1]&&a[1]==a[2]) {
                ans+=1;
                break;
            }
            else if(a[0]==a[1]&&a[1]+2==a[2]) {
                ans+=2;
                break;
            }
            else if(a[0]+1==a[1]&&a[1]==a[2]) {
                ans+=2;
                break;
            }
            else if(a[0]+1==a[1]&&a[1]+1==a[2]) {
                ans+=3;
                break;
            }
        }
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
/*
	a,b,c
偶数のとき: 
max: 2a+2b+2c	b+c, a+c, a+b
max: 4a+4b+4c	2a+b+c, a+2b+c, a+b+2c
max: 8a+8b+8c	2a+3b+3c, 3a+2b+3c, 3a+3b+2c
max: 16a+16b+16c	6a+5b+5c, 5a+6b+5c, 5a+5b+6c

k: 偶数
b-a
a-b
b-a


*/

int main(){
	ll a,b,c,k;
	cin >> a >> b >> c >> k;
	if(k%2==0) cout << (a-b) << endl;
	else cout << (b-a) << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pi = pair<int, int>;
using vpi = vector<pi>;
using ld = long double;
const int maxn = 3e5 + 10, mlg = 20, mod = 1e9 + 7;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, k;
	cin >> n >> k;
	int len = 0;
	while(n) n/=k, len++;
	cout << len;
	return 0;
}


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

using namespace std;
signed main(){
     int n,a;
     cin>>n>>a;
     if(n%500<=a)cout<<"Yes"<<endl;
     else cout<<"No"<<endl;
}



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

#define F first
#define S second
#define pii pair<int, int>
#define pb push_back

using namespace std;

typedef long long ll;
typedef long double ld;

const int maxN = 1e5 + 10, oo = 1e9 + 5, mod = 1e9 + 7;

int x[maxN], y[maxN], fen[maxN];
vector <pii> p;
vector <int> ys;

void upd(int q, int val){for(q++; q<maxN; q +=q&-q) fen[q] += val, fen[q] %= mod;}
int get(int q){int res = 0; for(; q>0; q-=q&-q) res += fen[q], res %= mod; return res;}

void UPD(int L, int R, int v)
{
	v %= mod;
	upd(L, +v);
	upd(R, mod - v);
}

int GET(int q)
{
	return get(q + 1);
}

bool cmp(pii A, pii B)
{
	return make_pair(A.F, -A.S) < make_pair(B.F, -B.S);
}


int main()
{
	int n, m; cin >> n >> m;
	for (int i=0; i<n; i++)
		cin >> x[i];
	for (int i=0; i<m; i++)
		cin >> y[i];

	sort(x, x + n);
	sort(y, y + m);

	for (int i=0; i<n; i++)
		if(x[i] > y[0] && x[i] < y[m - 1])
		{
			int u = upper_bound(y, y + m, x[i]) - y;
			p.push_back({x[i] - y[u - 1], y[u] - x[i]});
		}

	sort(p.begin(), p.end(), cmp);
	p.resize(unique(p.begin(), p.end()) - p.begin());
	
	n = p.size();
	for (int i=0; i<n; i++) ys.pb(p[i].S);

	sort(ys.begin(), ys.end()); ys.pb(oo);
	ys.resize(unique(ys.begin(), ys.end()) - ys.begin());

	int k = ys.size();

	for (int i=0; i<n; i++)
		p[i].S = lower_bound(ys.begin(), ys.end(), p[i].S) - ys.begin();

	UPD(0, k, +1);

	for (int i=1; i<=n; i++)
	{
		int yp = p[i - 1].S;
		int r = GET(yp);
		UPD(yp + 1, k, r);
	}

	cout << GET(k - 1) << endl;

}

Measured memory_bytes: 2804
//** aman**/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b) for(int i=a;i<b;i++)
#define lb lower_bound
#define ub upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
int dp[105][100005];
int main(){
	int n,w;cin>>n>>w;
	int we[n+1],val[n+1];
	for(int i=1;i<=n;i++){
		cin>>we[i]>>val[i];
	}
	// dp[number][val]=min(weight);

	for(int i=0;i<n+1;i++){
		for(int j=0;j<100005;j++){
			dp[i][j]=hell;
			if(j==0)dp[i][j]=0;
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<100005;j++){
			dp[i][j]=dp[i-1][j];
			if(j>=val[i])
			dp[i][j]=min(dp[i][j],dp[i-1][j-val[i]]+we[i]);
		}
	}

	int ans=0;
	for(int i=1;i<100005;i++){
		if(dp[n][i]<=w)ans=i;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 41216
#include <bits/stdc++.h>
#define rep(i,n) for ((i)=1;(i)<=(n);(i)++)
using namespace std;
int n,m,i,j,a[200005],l,r,mid,ans,res;
bool check(int x){
	int i,j;
	for(i=2*x+1,j=n*2;i<=j;i++,j--){
		if(a[i]+a[j]<m) return 0;
	}
	return 1;
}
int main(){
	cin>>n>>m;
	rep(i,n+n)cin>>a[i];
	sort(a+1,a+n+n+1);
	l=-1;r=n;ans=n+1;
	while(l<r){
		mid=(l+r+1)/2;
		if(check(mid)){
			r=mid-1;ans=mid;
		}
		else{
			l=mid;
		}
	}
	for(i=1,j=ans*2;i<=j;i++,j--){
		res=max(res,a[i]+a[j]);
	}
	for(i=ans*2+1,j=n*2;i<=j;i++,j--){
		res=max(res,a[i]+a[j]-m);
	}
	cout<<res<<endl; 
	return 0;
}

Measured memory_bytes: 4384
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T>
bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for(int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T>
vector<T> make_v(size_t a) {
    return vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) {
    for(auto& e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    --a;
    ll s = b - b / c - b / d + b / ((c * d) / __gcd(c, d));
    ll t = a - a / c - a / d + a / ((c * d) / __gcd(c, d));
    cout << s - t << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if((a-b>=-d&&a-b<=d&&b-c>=-d&&b-c<=d)||(c-a>=-d&&c-a<=d))cout<<"Yes"<<endl;
  else cout << "No" <<endl;
}

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

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

#define pb push_back
#define F first
#define S second
#define mp make_pair
#define vsort(x) sort(x.begin(), x.end())
#define out(x) cout << x << "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define FOR(a, b, c) for(int a = b; a < c; a++)
typedef long long int ll;

int main(){
    IOS;
    ll n,i;
    cin>>n;
    vector<ll>a(n+1),dp(n+1);
    for(i=1;i<=n;i++){
        cin>>a[i];
    }
    dp[1] = 0;
    dp[2] = abs(a[2] - a[1]);
    for(i=3;i<=n;i++){
        dp[i] = min((dp[i-1] + abs(a[i]-a[i-1])),(dp[i-2] + abs(a[i]-a[i-2])));
    }
    cout<<dp[n]<<endl;
    return 0;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        // 解
        int ans = 0;

        // 入力
        int[] inp = CSRD.RI(' ');

        // 処理
        int n = inp[0];
        int max = inp[1];
        int[] counter = new int[31];

        for (int i = 0; i < n; i++)
        {
            int[] inp2 = CSRD.RI(' ');
            for (int j = 1; j < inp2.Length; j++)
            {
                counter[inp2[j]]++;
            }
        }

        for (int i = 0; i < counter.Length; i++)
        {
            if (counter[i] == n)
            {
                ans++;
            }
        }
        
        //出力
        CSWT.WS(ans);
        CSRD.RS();
    }
}

class CSRD
{
    // 文字列または数値の入力
    public static string RS() { return Console.ReadLine(); }
    public static int RI() { return int.Parse(Console.ReadLine()); }
    public static string[] RS(char sep) { return Console.ReadLine().Split(sep); }
    public static int[] RI(char sep) { return Console.ReadLine().Split(sep).Select(x => int.Parse(x)).ToArray(); }
}

class CSWT
{
    public static void WS(object param) { Console.WriteLine(param); }
}

Measured memory_bytes: 13268
def main():
    while True:
        H, W = map(int, input().split())
        if H == 0 and W == 0:
            break
        for i in range(H):
            for j in range(W):
                if i == 0 or i == H-1 or j == 0 or j == W-1:
                    print("#", end="")
                else:
                    print(".", end="")
            print()
        print()
    return 0


if __name__ == "__main__":
    main()



Measured memory_bytes: 7008
#include<stdio.h>
int main(void)
{
	int a,b;
	scanf("%d %d",&a,&b);
	if(a<b){
		printf("a < b\n");
	}
	else if(a>b){
		printf("a > b\n");
	}
	else{
		printf("a == b\n");
	}
	return 0;
}



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

int main() {
  int N;
  cin >> N;
  
  int count=0;

  for (int i=0; i<N; i++){
    
    int a;
    cin >> a;
    
    int j=0;
    while ((a % 2)==0){
      a=a/2;
      j++;
    }
    if (i==0)
      count = j;
    else if(count>j)
      count = j;

  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi atan(1.0)*4
#define pb(x) push_back(x)
#define in(x) insert(x)
#define fl(x,y) for(ll i=x;i<y;i++)
#define vi vector<long long>
#define vs  vector<string>
#define vp(vi,x) cin>>x; vi.pb(x);
string en="\n";
string t="hello";
string Y="YES\n";
string N="NO\n";
#define E end()
#define B begin()
#define sz size()
#define EM empty()
#define fi first
#define se second
#define clr clear()
#define sqr(a) (a*a)
#define mk make_pair
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
/*bool isprm(LL a){for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool palin(string a){for(int i=0;i<a.sz;i++){if(a.at(i)!=a.at(a.sz-i-1))return 0;} return 1;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
LL bpow(LL a,LL b){if(b==0)return 1;LL r=bpow(a,b/2);if(b%2)return r*r*a;else return r*r;}
LL binpow(LL a,LL b){LL r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
LL binpow(LL a,LL b,LL m){a%=m;LL r=1;while(b>0){if(b&1) r=r*a%m;a=a*a%m; b>>=1;}return r;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
*/
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int main()
{
    ll a,b,c,t,n,k,p,q,r,y,yy,sum,ct=0,flag=0;
    string s,s1,s2,s3;
    set<ll>st;
    char ch;
    map<ll,ll>mp;
    vector<ll>v,vv,vz;

      cin>>s1>>s>>s2;
       cout<<"A"<<s[0]<<"C"<<endl;
}





Measured memory_bytes: 3608
// Aizu Vol-5 0521: Change
// 2017.8.30 bal4u@uu

#include <stdio.h>
#include <string.h>

int c[] = { 500, 100, 50, 10, 5, 1, 0 };

int main()
{
	int m, ans, i;

	while (scanf("%d", &m) && m) {
		m = 1000 - m;
		ans = m / c[0];
		for (i = 1; c[i] > 0; i++) {
			m %= c[i-1];
			ans += m / c[i];
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=3*100005;
LL dp1[N],dp2[N],a[N];
priority_queue<LL,vector<LL>,greater<LL> >q1;
priority_queue<LL>q2;
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1; i<=3*n; i++)
    {
        scanf("%d",&a[i]);
    }
 
    LL sum=0;
    for(int i=1; i<=3*n; i++)
    {
        sum+=a[i];
        q1.push(a[i]);
        dp1[i]=sum;
        if(q1.size()>n)
        {
            sum-=q1.top();
            q1.pop();
            dp1[i]=sum;
        }
    }
 
    sum=0;
    for(int i=3*n; i>=1; i--)
    {
        sum+=a[i];
        q2.push(a[i]);
        dp2[i]=sum;
        if(q2.size()>n)
        {
            sum-=q2.top();
            q2.pop();
            dp2[i]=sum;
        }
 
    }
    
    LL  ans=-1e18;
    for(int i=n;i<=2*n;i++)
	{
		ans=max(dp1[i]-dp2[i+1],ans);
	}
	cout<<ans<<endl;
    return 0;
 
}

Measured memory_bytes: 9588
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define deb(x) cout<<#x<<" "<<x<<endl;
#define deb2(x, y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define deb3(x, y, z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define all(x) x.begin(), x.end()
#define sz(a) int((a).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

template <typename T>void print(T v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<v.size(); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto i= v.begin(); i!=v.end(); i++)cout<<setw(w)<<*i<<" ";cout<<endl;}
template <typename T>void print_vv(T v){if(v.size()==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<v[0].size(); j++)cout<<setw(w)<<j<<" ";cout<<endl;for(auto i= 0; i<v.size(); i++){cout<<i<<" {";for(auto j = 0; j!=v[i].size(); j++){cout<<setw(w)<<v[i][j]<<",";}cout<<"},"<<endl;}cout<<endl;}
template <class T, class U> void print_m(map<T,U> m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}

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

        while(a>0 && c>0){
            c-=b;
            if(c<=0) break;
            a-=d;
        }
        string out = a>0 ? "Yes" : "No";
        cout<<out<<endl;
    }
    return 0;
}

Measured memory_bytes: 3640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DModSum solver = new DModSum();
        solver.solve(1, in, out);
        out.close();
    }

    static class DModSum {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long n = in.nextInt();
            out.println((n * (n - 1)) / 2);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



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

int N, Q;
vector<vector<int>> G;
vector<int> p, x;
vector<int> ans;
map<int,int> MP;


void dfs(int v, int p = -1){
    ans[v] += MP[v];

    for(auto u: G[v]){
        if(u == p) continue;

        ans[u] += ans[v];
        dfs(u, v);
    }
}

void solve(){

    for(int i = 0; i < Q; i++){
        MP[p[i]] += x[i];
    }
    ans.assign(N,0);
    dfs(0);

    for(auto e: ans) cout << e << endl;
}

int main(){
    cin >> N >> Q;
    G.assign(N,vector<int>());
    for(int i = 0; i < N - 1; i++){
        int a, b; cin >> a >> b;
        a--,b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    p.assign(Q,0), x.assign(Q,0); 
    for(int i = 0; i < Q; i++){
        cin >> p[i] >> x[i];
        p[i]--;
    }
    solve();
}

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

using namespace std;

int main()
{
	int A, B;
	cin >> A >> B;
	if (A >= 13) {
		cout << B << endl;
	} else if (6 <= A && A <= 12) {
		cout << B / 2 << endl;
	} else {
		cout << 0 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
<?php

fscanf(STDIN, '%d', $N);
$line = trim(fgets(STDIN));
$arr = explode(' ', $line);
for ($i = 0, $len = count($arr), $cnt = 0; $i < $len; $i++) {
    $key = $i;
    for ($j = $i; $j < $len; $j++) {
        if ($arr[$j] < $arr[$key]) {
            $key = $j;
        }
    }

    if ($key !== $i) {
        $tmp = $arr[$i];
        $arr[$i] = $arr[$key];
        $arr[$key] = $tmp;
        $cnt++;
    }
}
echo implode(' ', $arr), PHP_EOL, $cnt, PHP_EOL;

Measured memory_bytes: 6600
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <queue>
#include <deque>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <random>
#include <ctime>
#include <utility>
#include <fstream>

#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("fast-math")
#pragma comment(linker, "/STACK:256000000")
#pragma warning(disable:4996)

using namespace std;

typedef long long ll;
typedef long double ld;

const char el = '\n';
const int inf = 1e9;
const ll llinf = 1e18, mod = 1000'000'007ll;
const ld pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825;

#define forn(i, n) for (int i = 0; i < (int)n; ++i)
#define firn(i, n) for (int i = 1; i < (int)n; ++i)
#define alls(v) v.begin(), v.end()
#define x first
#define y second

template<typename T> bool uin(T &a, T b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T> bool uax(T &a, T b) { if (b > a) { a = b; return 1; } return 0; }
template<class iterator> void output(iterator begin, iterator end, char p = ' ', ostream & out = cout) { while (begin != end) { out << (*begin) << p; begin++; } out << el; }
template<class T> void output(T x, char p = ' ', ostream & out = cout) { output(all(x), p, out); }

mt19937 rnd(time(NULL));

int n, m;
int a[500000];
int v[10] = {0,2,5,5,4,5,6,3,7,6};
int b[10];

vector<int> ans1, ans2;
vector<int> cur;

void gen(int x, int st)
{
    if (x == 0)
    {
        if (cur.size() > ans2.size() || (cur.size() == ans2.size() && cur > ans2))
        {
            ans2 = cur;
        }
        return;
    }
    for (int d = st; d >= 0; d--)
    {
        if (b[d] && x - v[d] >= 0)
        {
            cur.push_back(d);
            gen(x - v[d], d);
            cur.pop_back();
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m;
    for (int i = 0; i < m; i++) cin >> a[i];
    for (int i = 0; i < m; i++) b[a[i]]++;

    int opt = -1;
    for (int i = 0; i < 10; i++)
    {
        if (b[i])
        {
            if (opt == -1) opt = i;
            if (v[i] <= v[opt]) opt = i;
        }
    }
    while (n > 60)
    {
        n -= v[opt];
        ans1.push_back(opt);
    }
    gen(n, 9);
    for (int i = 0; i < ans2.size(); i++)
    {
        ans1.push_back(ans2[i]);
    }
    sort(ans1.begin(), ans1.end());
    for (int i = 0; i < ans1.size(); i++) cout << ans1[ans1.size() - 1 - i];
    return 0;
}


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

typedef long long ll;
typedef double db;

#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const ll LINF = LLONG_MAX, MOD = 1e9 + 7, N = 1e5 + 5, LG = 20;
const int INF = INT_MAX;
const db PI = acos(-1), EPS = 1 / db(1e6);

void test() {
    map<string, int> mp;
    int n; cin >> n;
    for (int i = 0; i  < n; ++i) {
        string s; cin >> s;
        ++mp[s];
    }
    cout << "AC x " << mp["AC"] << "\n";
    cout << "WA x " << mp["WA"] << "\n";
    cout << "TLE x " << mp["TLE"] << "\n";
    cout << "RE x " << mp["RE"] << "\n";
}

int main() {
      fast_io();
      #ifdef HOME
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
      #endif
      cout << fixed << setprecision(15);
      int t = 1;
      // cin >> t;
      for (int i = 1; i <= t; ++i) {
          test();
      }
      #ifdef HOME
          cout << "Time: " << (int)(clock() * 1000. / CLOCKS_PER_SEC) << "ms";
      #endif
      return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    string s;
    cin >> s;
    ll n = s.size();
    ll res = 0, i = 0, j = n - 1;
    while(1){
        if(i >= j) break;
        if(s[j] != s[i]){
            if(s[j] != 'x' && s[i] != 'x'){
                cout << -1 << endl;
                return 0;
            }
            else if(s[j] == 'x'){
                j--;
                res++;
            }
            else{
                i++;
                res++;
            }
        }
        else{
            i++;
            j--;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using namespace boost;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;


bool is_able(ll sum, vector<ll> v){
    constexpr ll l = 8000 * 4 + 1;
    bitset<l> b(0); // b[i] = (i-8000)が作れるかどうか
    b[(l-1)/2] = true; // 初期状態
    for (auto &&i: v){
        bitset<l> b_new(0);
        for (auto &&j: boost::irange(0LL, l)){
            if (b[j]){
                if (j-i >= 0) b_new[j-i] = true;
                if (j+i <= l - 1) b_new[j+i] = true;
            }
        }
        b = b_new;
    }
    return b[sum+(l-1)/2];
}



int main() {
    string s;
    cin >> s;
    deque<char> d(s.begin(), s.end());
    ll x, y;
    cin >> x >> y;
    while (!d.empty()){
        if (d.front() == 'F'){
            x--;
            d.pop_front();
        } else {
            break;
        }
    }
    vector<ll> xs{};
    vector<ll> ys{};
    ll count{0};
    bool is_x(true);
    d.emplace_back('T');
    while (!d.empty()){
        if (d.front() == 'T'){
            if (count != 0) {
                if (is_x) {
                    xs.emplace_back(count);
                } else {
                    ys.emplace_back(count);
                }
            }
            is_x = !is_x;
            count = 0;
        } else {
            count++;
        }
        d.pop_front();
    }
//    これで，xsに入ってる数の+-和でxが作れるか，ysに入ってる数の+-和でyが作れるかというゲームにおちる
//    cout << "size: " << xs.size() << " sum: " << accumulate(xs.begin(), xs.end(), 0) << endl;
//    cout << "size: " << ys.size() << " sum: " << accumulate(ys.begin(), ys.end(), 0) << endl;
//    cout << is_able(x, xs) << is_able(y, ys) << endl;
    if (is_able(y, ys) && is_able(x, xs)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

struct Problem {

	void Solve() {
		ULL N, K;
		cin >> N >> K;
		vector<LL> A(N);
		rep(i, N) cin >> A[i];
		sort(A.begin(), A.end());
		LL L, R; L = -LL(1e18) - 1; R = LL(1e18) + 1;
		while (L + 1 < R) {
			LL M = L + R;
			if (M % 2) M = (M + 1) / 2; else M /= 2;
			ULL k = 0;
			rep(i, N) {
				LL p = A[i];
				if (p == 0) {
					if (M > 0) k += (N - 1);
				}
				if (p > 0) {
					UL l = 0, r = N + 1;
					while (l + 1 < r) {
						UL m = (l + r) / 2;
						if (p * A[m - 1] < M) l = m; else r = m;
					}
					//cout << "l=" << l << " ";
					k += l;
					if (p * p < M) k--;
				}
				if (p < 0) {
					UL l = 0, r = N + 1;
					while (l + 1 < r) {
						UL m = (l + r) / 2;
						if (p * A[m - 1] >= M) l = m; else r = m;
					}
					//cout << "N-l=" << (N-l) << " ";
					k += N - l;
					if (p * p < M) k--;
				}
			}
			//cout << "M = " << M << "; k = " << k << endl;

			if (k < K * 2) L = M; else R = M;
		}
		cout << L << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


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

int main(){
	long long ans=1;
	int n;
	cin>>n;
	char s[n];
	cin>>s;
	int a[26]={};
	for(int i=0;i<n;i++){
		a[(int)s[i]-'a']++;
	}
	for(int i=0;i<26;i++){
		ans*=(a[i]+1);
		ans%=1000000007;
	}
	cout<<ans-1<<endl;
	return 0;
}


Measured memory_bytes: 384
#include <cstdio>

#include <string>
#include <iostream>
using namespace std;
#include <algorithm>
#include <vector>

#include <cmath>

int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int i, j;
    int N;
    int ans;
    string S;
    cin >> N;
    cin >> S;

    int count=0;
    string find_str="ABC";
    int pos=S.find(find_str);

    while(pos!=string::npos){
        pos=S.find(find_str, pos+find_str.size());
        count++;
    }
    ans=count;

    cout<<ans<<"\n";

    return 0;
}

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

int main(){
  
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if(a + b > c + d)
    cout << "Left" << endl;
  if(a + b < c + d)
    cout << "Right" << endl;
  if(a + b == c + d)
    cout << "Balanced" << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

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

	vector<int> A,B;
	for(int i = 0;i < N;i++){
		int a;
		cin >> a;
		A.push_back(a);
		B.push_back(a);
	}

	sort(A.begin(),A.end(), greater<int>());
	if(A[0] == A[1]){
		for(int i = 0;i < N;i++)
			cout << A[0]<<endl;
	}
	else{
		for(int i = 0;i < N;i++)
			if(B[i] == A[0]) cout << A[1]<<endl;
			else cout << A[0]<<endl;
	}

}


Measured memory_bytes: 3436
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    for (auto& x : a) cin >> x;

    int max = *max_element(a.begin(), a.end());
    int min = *min_element(a.begin(), a.end());
    cout << max - min << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	int x,y,a,b;
	cin >> x >> y;
	
	if(x == 2)
	{
		a = 1;
	}
	else if(x == 4 || x == 6 || x == 9 || x == 11)
	{
		a = 2;
	}
	else
	{
		a = 3;
	}
	
	if(y == 2)
	{
		b = 1;
	}
	else if(y == 4 || y == 6 || y == 9 || y == 11)
	{
		b = 2;
	}
	else
	{
		b = 3;
	}
	
	if(a == b)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	ll n,w;
	cin>>n>>w;
	pair<ll,ll> p[n];
	for(int i=0;i<n;i++)
	{
		cin>>p[i].first>>p[i].second;
	}
	ll a[n][w+1];
	for(ll i=0;i<n;i++)
	{ 	
		a[i][0]=0;
	}
	for(ll i=1;i<=w;i++)
	{
		if(i<p[0].first)
			a[0][i]=0;
		else{
			a[0][i]=p[0].second;
		}
	}
	
	for(int i=1;i<n;i++)
	{
		for(int j=1;j<=w;j++)
		{
			if(j<p[i].first)
			{
				a[i][j]=a[i-1][j];
			}
			else{
				a[i][j]=max(a[i-1][j],p[i].second+a[i-1][j-p[i].first]);
			}
		}
	}
	cout<<a[n-1][w]<<endl;
	

}

Measured memory_bytes: 78336
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int obs = 2*d+1;
        int ans = 0;
        while(n > 0){
            n -= obs;
            ans++;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 25044
N, M = map(int, input().split())
pref = [1] * (N + 1)
iPY = []
for i in range(M):
    p, y = map(int, input().split())
    iPY.append([i, p, y])

iPY.sort(key=lambda x: x[2])
ans = []
for i, p, y in iPY:
    name = str(p).zfill(6) + str(pref[p]).zfill(6)
    ans.append((i, name))
    pref[p] += 1

ans.sort(key=lambda x: x[0])
for _, name in ans:
    print(name)


Measured memory_bytes: 38604
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;

ll dp[101][5][5][5];


int main(){
	int n;
	cin >> n;
	dp[0][0][0][0] = 1;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < 5; j++){
			for (int k = 0; k < 5; k++){
				for (int l = 0; l < 5; l++){
					for (int m = 1; m < 5; m++){
						if (k == 1 && l == 3 && m == 2) continue;
						if (j == 1 && l == 3 && m == 2) continue;
						if (k == 3 && l == 1 && m == 2) continue;
						if (k == 1 && l == 2 && m == 3) continue;
						if (j == 1 && k == 3 && m == 2) continue;
						dp[i+1][k][l][m] += dp[i][j][k][l];
						dp[i+1][k][l][m] %= MOD;
					}
				}
			}
		}
	}
	ll ans = 0;
	for (int i = 1; i < 5; i++){
		for (int j = 1; j < 5; j++){
			for (int k = 1; k < 5; k++){
				ans += dp[n][i][j][k];
				ans %= MOD;
			}
		}
	}
	cout << ans << endl;
	return 0;
 }



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace::std;
using lint=long long;
#define rep(i,n) for(lint i=0;i<(lint)(n);++i)
constexpr lint INF=1LL<<60;

template<typename T>
class skew_heap{
	struct node;
	using np=node*;
	struct node{
		np ch[2]={nullptr,nullptr};
		T val;
        lint lazy=0;
		node(T val):val(val){}
	};
	np root=nullptr;
    void eval(np t){
        if(!t)return;
        t->val=make_pair(t->val.first+t->lazy,t->val.second);
        if(t->ch[0])t->ch[0]->lazy+=t->lazy;
        if(t->ch[1])t->ch[1]->lazy+=t->lazy;
        t->lazy=0;
    }
	np meld(np a,np b) {
        eval(a);eval(b);
		if(!a||!b)return a?a:b;
		if(a->val>b->val)swap(a,b);
		a->ch[1]=meld(a->ch[1],b);
		swap(a->ch[0],a->ch[1]);
		return a;
	}
	public:
	skew_heap(np root=nullptr):root(root){}
    void add(lint val){if(root)root->lazy+=val;}
    bool empty(){return !root;}
	void insert(T val){root=meld(root,new node(val));}
	void pop(){eval(root);root=meld(root->ch[0],root->ch[1]);}
	T top(){eval(root);return root->val;}
	void meld(skew_heap t){root=meld(root,t.root);}
};

int main(){
    lint n,m,r;
    cin>>n>>m>>r;
    vector<skew_heap<pair<lint,lint>>>v(n);
    rep(i,m){
        lint s,t,x;
        cin>>s>>t>>x;
        v[s].insert(make_pair(x,t));
    }
    vector<lint>diff(n,INF);
    skew_heap<pair<lint,lint>>que;
    que.meld(v[r]);
    diff[r]=0;
    while(!que.empty()){
        lint c,e;
        tie(c,e)=que.top();
        que.pop();
        if(diff[e]>c){
            diff[e]=c;
            v[e].add(c);
            que.meld(v[e]);
        }
    }
    rep(i,n){
        if(diff[i]==INF)cout<<"INF"<<endl;
        else cout<<diff[i]<<endl;
    }
}


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

int main(){
  int n;
  cin>>n;
  int a[n];
  int sum = 0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    sum += a[i];
  }
  sort(a,a+n);
  int cost = 1e9;
  for(int j = -100; j<=100;j++){
    int c = 0;
    for(int i=0;i<n;i++)
      c += (a[i]-j)*(a[i]-j);
    cost = min(c,cost);
  }
  cout<<cost;
  return 0;
}

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

vector<int> X[100005];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);

    int N, M;
    cin >> N >> M;

    for(int i=1; i<=M; i++)
    {
        int p;
        string s;
        cin >> p >> s;

        if(s == "AC")
            X[p].push_back(1);
        else
            X[p].push_back(0);
    }

    long long ans = 0, penalty = 0;

    for(int i=1; i<=N; i++)
    {
        int s = 0;
        
        for(auto x : X[i])
            s += x;
        
        if(s)
        {
            ans++;

            for(auto x : X[i])
            {
                if(x == 1)
                    break;
                
                penalty++;
            }
        }
    }

    cout << ans << " " << penalty << "\n";
    return 0;
}


Measured memory_bytes: 5760
# -*- coding: utf-8 -*-
N = int(raw_input())
a = map(int, raw_input().split()) 

over = 0
color = set()
for ai in a:
    if ai/400 >= 8:
        over += 1
    else:
        color.add(ai/400)

print max(1, len(color)), len(color) + over


Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define vmax 10000
constexpr ll inf = 1e18+7;
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/

int n;
vector<int> a;

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

bool check(int mid){
  
  return false;
}

ll serch(ll ok,ll ng){
	while (abs(ok-ng) > 1) {
		ll mid = (ok + ng) / 2;
		if (check(mid))ok = mid;
		else ng = mid;
	}
	return ok;
}

int main(){
  cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int x,y;
  int ans=1;
  priority_queue<P> l;
  rep(i,n){
    cin>>x>>y;
    l.push(make_pair(x-y,x+y));
  }
  int tmp=l.top().first;
  while(!l.empty()){
    if(l.top().second<=tmp){
      tmp=l.top().first;
      ans++;
    }
    l.pop();
  }
  cout<<ans<<endl;
  return 0;
}


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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()

// output
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
  cout << a;
  ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
  cout << a << ' ';
}

int ans = 0;
bool check = 0;
string s;
int N = 0;
vector<int> v(N);
int a, b;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

int main()
{
  int x;
  cin >> x >> a >> b;
  if (abs(x - a) > abs(x - b))
    pr('B');
  else
    pr('A');
  return 0;
}

Measured memory_bytes: 3632
l,r=map(int,input().split())
n=r-l if r-l < 2019 else 2019
ans=(r*l)%2019
for i in range(l, l+n+1):
  for j in range(i+1, l+n+1):
    ans=min(ans, (i*j)%2019)
print(ans)

Measured memory_bytes: 3060
while True:
    n=int(input())
    if n==0:break
    _in=input().split(' ')
    f_stat=[False,False] #[left,right]
    state=False
    cnt=0
    for i in range(n):
        com=_in[i]
        if com=="lu":f_stat[0]=True
        elif com=="ru":f_stat[1]=True
        elif com=="ld":f_stat[0]=False
        else:f_stat[1]=False
        #
        if state==False:
            if f_stat[0] and f_stat[1]:
                cnt+=1
                state=True
        else:
            if not f_stat[0] and not f_stat[1]:
                cnt+=1
                state=False
    print(cnt)

Measured memory_bytes: 7616
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    ll q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;
    ll q1 = q * 4LL;
    ll h1 = h * 2LL;
    ll cost = 0;
    cost = n / 2LL * min({q1*2, h1*2, s*2, d});
    n -= n / 2LL * 2LL;
    if (n) cost += min({q1, h1, s});
    cout << cost << endl;
    return 0;
}


Measured memory_bytes: 3620
from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))
a = [0] + a

ans = 0
d = defaultdict(int)
d[0] += 1

for i in range(n):
    #累積和をとる
    a[i + 1] += a[i]
    #nC2を求める
    ans += d[a[i + 1]]
    #登場した回数を数える
    d[a[i + 1]] += 1

print(ans)

Measured memory_bytes: 39208
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 10000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

P G[10];

int H,W,ans;
char C[60][60];
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
int d[60][60];

void bfs(){
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++) d[i][j]=INF;
  }
  queue<P> que;

  que.push(P(0,0));
  d[0][0]=0;
  while(que.size()){
    P p=que.front(); que.pop();
    //cout<<p.first<<" "<<p.second<<" "<<d[p.first][p.second]<<endl;
    if(p.first==H-1 && p.second==W-1) break;
    for(int i=0;i<4;i++){
      int ny=p.first+dy[i],nx=p.second+dx[i];

      if(0<=nx && nx<W && ny>=0 && ny<H && C[ny][nx]=='.' && d[ny][nx]==INF){
        que.push(P(ny,nx));
        d[ny][nx]=d[p.first][p.second]+1;
      }
    }
  }
}

int main(){
  int count=0;
  cin>>H>>W;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>C[i][j];
      if(C[i][j]=='.') count++;
    }
  }
  bfs();
  if(d[H-1][W-1]==INF) cout<<-1<<endl;
  else cout<<count-d[H-1][W-1]-1<<endl;
}


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

string s;
int n;
int cnt;

int main(){
    cin >> n >> s;
    
    cnt = 0;
    //暗証番号は, 000 ~999まで
    for (int i = 0; i < 1000; i++){
        
        // c = {100の位, 10の位, 1の位}
        vector<int> c = {i/100, (i/10)%10, i%10};
        int f = 0;

        //文字列sの前方から, 現在の暗証番号を作れるかどうかを調べる
        for (int j = 0; j < n; j++){
            if (s[j] == ('0' + c[f])) f++;
            if (f == 3) break; //f==3ならば, 文字列sの前方から数字を選び, 現在の暗証番号を作れる
        }
        if (f == 3) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256