akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    int A;
    double B;

    cin >> A >> B;
    int C = (int)(B * 100 + 0.5);
    int ans = A* C / 100;
    
    cout << ans << endl;
    return 0;
}


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

int main() {
    int d; cin >> d;
    int n = 26;
    vector<int> c(n);
    rep(i,n) cin >> c[i];
    vector<vector<int>> s(d,vector<int>(n));
    rep(i,d){
        rep(j,n){
            cin >> s[i][j];
        }
    }

    //
    /*srand(time(NULL));
    int d = 365;
    int n = 26;
    vector<int> c(n);
    rep(j,n) c[j] = rand()%101;
    vector<vector<int>> s(d,vector<int>(n));
    rep(i,d){
        rep(j,n){
            s[i][j] = rand()%20001;
        }
    }*/

    vector<int> t(d);

    vector<int> last(n,1);

    int64_t happy = 0;
    rep(i,d){
        int ti;
        int h;
        rep(j,n){
            int hj = c[j]*last[j]+s[i][j];
            if(j == 0) {
                h = hj;
                ti = j;
            }
            else if(h < hj){
                h = hj;
                ti = j;
            }
        }
        happy += h;
        rep(j,n){
            happy -= c[j]*last[j];
        }

        t[i] = ti+1;
        last[ti] = 1;
        rep(j,n){
            if(j != ti){
                last[j]++;
            }
        }
    }
    //cout << happy << endl;
    rep(i,d) cout << t[i] << endl;
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL read(){
	LL x=0;
	char ch=getchar();
	while (!isdigit(ch))
		ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x;
}
const int N=505;
int n,k;
int g[N][N];
int main(){
	k=read();
	n=min(k,500);
	for (int i=1;i<=n;i++){
		int x=1,y=i;
		for (int j=1;j<=n;j++){
			g[x][y]=i;
			x=x%n+1,y=y%n+1;
		}
	}
	for (int i=n+1;i<=k;i++){
		int x=1,y=i-n;
		for (int j=1;j<=n;j++){
			if (j&1)
				g[x][y]=i;
			x=x%n+1,y=y%n+1;
		}
	}
	printf("%d\n",n);
	for (int i=1;i<=n;i++,puts(""))
		for (int j=1;j<=n;j++)
			printf("%d ",g[i][j]);
	return 0;
}

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

int main(){
  long long int N,K;
  cin>>N>>K;
  vector<long long int>H(N);
  for(int i=0;i<N;i++){
    cin>>H.at(i);
  }
  sort(H.begin(),H.end(),greater<int>());
  long long int ans = 0;
  if(K>H.size()){ans=0;}
  else{
    for(int i = K ; i<H.size();i++){
      ans+=H.at(i);
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

using ll = long long;
ll mod = pow(10, 9) + 7;

template <typename T> void output(T, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
Bint comb(Bint, Bint);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    int n;
    cin >> n;
    int ans = 0;
    rep(i, n) {
        int r, l;
        cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << endl;
    return 0;
}

Bint comb(Bint a, Bint b) {
    Bint ans = 1;

    if (a < b) {
        return 0;
    }

    rep(i, b) {
        ans *= a - i;
        ans /= i + 1;
    }

    return ans;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T 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); }

void prime_map(map<ll, ll> &m, ll num) {

    if (num == 1) {
        return;
    }
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }
    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }

        return;
    }
    prime_map(m, num);
    return;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue> //C++
#include <string> //C++
#include <iostream> //C++
#include <vector> //C++
#include <algorithm> //C++
#include <map> //C++
using namespace std; //C++
#define rep(i, a, n) for (i = (a); i < (n); i++)


//C++で提出



// string s="AAA";    s.size() =3    (sのサイズ) ...1
// vector <int> a;    配列a(サイズは0) ...2
// a.push_back(10);   配列のサイズが一つ増えて一番後ろに10を代入 ...2
// A.pop_back();   最後の要素が消去される
// sort(A.begin(),A.end());   配列Aの最初の要素から最後の要素(/.)より前までを小さい順に並び替えてa[0]から代入していく...3
// reverse(A.begin(),A.end());   配列Aの最初の要素から最後の要素(/.)までを逆の順にしてa[0]から代入していく
// s.substr(3,2)   配列s[3]から2個の文字を抜き出した文字列 (s[3]とs[4]) ...4
// strcmp(s1,s2)  文字列が等しければ0を出力　s1>s2なら1 s1<s2なら-1を出力　C言語用なので配列は、s1[100]にする...5




/*
const int MAX = 100;
int main() {
	int N, M;
	string s, t;
	map<string, int> m;
	m["apple"] = 10;
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> s;
		m[s]++;
	}
	cin >> M;
	for (int i = 0; i < M; ++i) {
		cin >> t;
		m[t]--;
	}
	
	int max=0;

	for (map<string, int>::iterator i = m.begin(); i != m.end(); ++i) {
		if (max < (i->second)) max = i->second;
	}

	if (max < 0) cout << "0";
	else cout << max;

	return 0;
}

*/

int main() {

	int n;
	vector<long long int>a;
	int i;
	int x;

	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> x;
		a.push_back(x);
	}

	sort(a.begin(), a.end());

	for (i = 0; i < n - 1; i++) {
		if (a[i] == a[i + 1]) {
			cout << "NO";
			return 0;
		}
	}

	cout << "YES";

}

Measured memory_bytes: 2420
N=input()
A=map(int, raw_input().split())
B=range(1,N+1)
 
C=[]
for x,y in zip(A,B):
	C.append(x-y)

C.sort()

m=0
if len(C)%2==1:
	m=C[len(C)/2]
else:
	m=(C[len(C)/2-1]+C[len(C)/2])/2

	
ans=0
for x in C:
	ans+=abs(-1*m+x)
print ans


Measured memory_bytes: 68060
n = int(input())
p = list(map(int, input().split()))
def check(a, b, c):
  l = [a, b, c]
  l.sort()
  if l[1] == b:
    return True
  else:
    return False
cnt = 0
for i in range(n-2):
  if check(p[i], p[i+1], p[i+2]):
    cnt += 1
print(cnt)

Measured memory_bytes: 9044
#include<iostream>
#include<iomanip>
#include<cmath>

using namespace std;
double a1, b1, a2, b2;
int main(){
    cin >> a1 >> b1 >> a2 >> b2;
    cout << fixed << setprecision(8) << sqrt((a1 - a2) * (a1 - a2) + (b1 - b2) * (b1 - b2)) << endl;
    return 0;
}


Measured memory_bytes: 3288
// ModSum.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>

using namespace std;

long long n;

int main() {
	cin >> n;
	cout << (n - 1ll) * n / 2 << endl;
	return 0;
}

// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
// 调试程序: F5 或调试 >“开始调试”菜单

// 入门使用技巧: 
//   1. 使用解决方案资源管理器窗口添加/管理文件
//   2. 使用团队资源管理器窗口连接到源代码管理
//   3. 使用输出窗口查看生成输出和其他消息
//   4. 使用错误列表窗口查看错误
//   5. 转到“项目”>“添加新项”以创建新的代码文件，或转到“项目”>“添加现有项”以将现有代码文件添加到项目
//   6. 将来，若要再次打开此项目，请转到“文件”>“打开”>“项目”并选择 .sln 文件


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

#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a[3][3];
    bool ok[3][3] = {};
    rep(i,0,3)rep(j,0,3) cin >> a[i][j];
    int n;cin >> n;
    rep(i,0,n){
        int tmp;cin >> tmp;
        rep(i,0,3)rep(j,0,3) if(a[i][j] == tmp) ok[i][j] = true;
    }
    bool ans = false;
    rep(i,0,3){
        if(ok[i][0] && ok[i][1] && ok[i][2]) ans = true;
        if(ok[0][i] && ok[1][i] && ok[2][i]) ans = true;
    }
    if(ok[0][0] && ok[1][1] && ok[2][2]) ans = true;
    if(ok[0][2] && ok[1][1] && ok[2][0]) ans = true;
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
    

}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#include<string>
using namespace std;
int main()
{
  int a,b,c,d,e,k ;
  cin >> a >> b >>c >>d >>e>>k ;
  
  if((e-a)<=k){
    cout << "Yay!" << endl ;
    return 0 ;
  }else{
    cout << ":(" << endl ;
    return 0 ;
  }
}

Measured memory_bytes: 256
function Main(arg) {
 
    var M = arg.trim().split(" ")[0] - 0;
    var D = arg.trim().split(" ")[1] - 0;
    
    var ans = 0;

    for (var i = 1; i <= M; i++){
        for (var j = 22; j <= D; j++){
            var d0 = j.toString().split("")[1]-0;
            var d10 = j.toString().split("")[0] - 0;
            if (d0 >= 2 && d10 >= 2) {
                if (i === d0 * d10) {
                    ans++;   
                }                    
            }
        }
    }
    
    console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
typedef pair<ll, ll> P;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
const ll INF = 10e14;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

ll solve(vector<ll> &numbers, int n, int k, int q, ll target) {
    vector<vector<ll>> tmp(1);
    for (ll l : numbers) {
        if (l < target) tmp.push_back({});
        else tmp.back().push_back(l);
    }
    vector<ll> candidate;
    for (vector<ll> &v : tmp) {
        if (v.size() < k - 1) continue;
        sort(v.begin(), v.end());
        int c = v.size() - k + 1;
        rep(i, c) candidate.push_back(v[i]);
    }
    sort(candidate.begin(), candidate.end());
    if (candidate.size() < q) return INF;
    return candidate[q - 1] - target;
}

int main() {
    int n, k, q;
    cin >> n >> k >> q;
    vector<ll> numbers(n);
    rep(i, n)cin >> numbers[i];
    ll ans = INF;
    rep(i, n) cmin(ans, solve(numbers, n, k, q, numbers[i]));
    cout << ans << endl;
}





Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<map>

using namespace std;

int main(){
  int n, m;
  cin >> n >> m;
  map<int, int> mp;
  int q;
  vector<int> isac(n+1, 0);
  string result;
  int s = 0;
  for(int i = 0; i < m ; i++){
    cin >> q >> result;
    if(result == "AC"){
      if(!isac[q]){
        isac[q] = 1;
        s++;
      }
    }
    else{
      if(!isac[q]){
        mp[q]++;
      }
    }
  }
  int f = 0;
  for(int i = 0; i < n; i++){
    if(isac[i+1]){
      f += mp[i+1];
    }
  }
  cout << s << ' ' << f << endl;
}


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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef int64_t ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

int main(){
  int N;
  cin >> N;
  vector<int> t(N), v(N);
  REP(i, N) cin >> t[i];
  REP(i, N) cin >> v[i];

  vector<int> tcum(N + 1, 0);
  REP(i, N) tcum[i + 1] = tcum[i] + t[i];
  int T = tcum[N];

  vector<ld> vmax(2 * T + 1, INF);
  REP(i, 2 * T + 1) {
    ld time = 0.5 * i;
    vmax[i] = min(vmax[i], min(time, T - time));
  }
  REP(i, N) {
    REP(j, 2 * T + 1) {
      ld time = 0.5 * j;
      if(time > tcum[i + 1]) {
        vmax[j] = min(vmax[j], v[i] + time - tcum[i + 1]);
      }else if(time >= tcum[i]) {
        vmax[j] = min(vmax[j], (ld)v[i]);
      }else{
        vmax[j] = min(vmax[j], v[i] + tcum[i] - time);
      }
    }
  }

  ld ret = 0;
  REP(i, 2 * T) {
    ret += 0.25 * (vmax[i] + vmax[i + 1]);
  }

  cout << fixed << setprecision(10) << ret << endl;
  return 0;
}



Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin>>n;
    string str;
    map<string,int> Amap;
    map<string,int> Bmap;
    for(int i=0;i<n;i++){
        cin>>str;
        Amap[str]++;
    }
    cin>>m;
    for(int i=0;i<m;i++){
        cin>>str;
        Bmap[str]++;
    }
    map<string,int>::iterator iter;
    int ans=0;
    for(iter=Amap.begin();iter!=Amap.end();iter++){
        ans=max(ans,iter->second-Bmap[iter->first]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[])
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    ll max = 0;
    ll temp = 0;

    for (ll i = 0; i < n - 1; i++)
    {
        if (a[i + 1] <= a[i])
        {
            temp++;
        }
        else
        {
            if (temp > max)
            {
                max = temp;
            }
            temp = 0;
        }
    }
    if (temp > max)
    {
        max = temp;
    }

    cout << max << endl;
}

Measured memory_bytes: 1024
if __name__ == '__main__':
    N = int(input())
    S = input()
    tmpS = S
    for i in range(50):
        tmpS = tmpS.replace("()", "")

    # print(tmpS)
    left_parenthesis_count = 0
    right_parenthesis_count = 0
    for moji in tmpS:
        if moji == "(":
            left_parenthesis_count += 1
        elif moji == ")":
            right_parenthesis_count += 1

    ans = S
    for i in range(right_parenthesis_count):
        ans = "(" + ans

    for i in range(left_parenthesis_count):
        ans += ")"

    print(ans)


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

int main()
{
    ll c[3][3];
    rep(i, 3){
        rep(j, 3){
            cin >> c[i][j];
        }
    }

    ll a[3] = {0};
    ll b[3] = {0};
    b[0] = c[0][0] - a[0];
    b[1] = c[0][1] - a[0];
    b[2] = c[0][2] - a[0];
    a[1] = c[1][1] - b[1];
    a[2] = c[2][2] - b[2];

    rep(i, 3){
        rep(j, 3){
            if (c[i][j] != a[i] + b[j]){
                puts("No");
                return 0;
            }
        }
    }

    puts("Yes");

    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define int ll
 
int fact(int n); 
  
int nCr(int n, int r) {
    if (n < r) {
        return 0;
    }
    return fact(n) / (fact(r) * fact(n - r)); 
} 
  
// Returns factorial of n 
int fact(int n) { 
    int res = 1; 
    for (int i = 2; i <= n; i++) 
        res = res * i; 
    return res; 
} 
 
int32_t main () {
    int n; cin >> n;
    int a[n];
    map<int, int> m;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        m[a[i]] += 1;
    }
    int sum = 0;
    
    map<int, int>::iterator itr; 
    
    map<int, int> self;
 
    for (itr = m.begin(); itr != m.end(); ++itr) { 
        int key = itr -> first;
        int val = itr -> second;
        
        int x = (val * (val - 1)) / 2;
        
        sum += x;
        
        self.insert(pair<int, int> (key, x));
    } 
    
    map<int, int> ans;
    
    for (int i = 0; i < n; i ++) {
        int selph = self[a[i]];
        int ekum = m[a[i]] - 1;
        //int nc = nCr(ekum, 2);
        
      	int nc = (ekum * (ekum - 1)) / 2;
      
        int result = sum - selph + nc;
        
        ans[a[i]] = result;
    }
    
    // for (itr = ans.begin(); itr != ans.end(); ++itr) {
    //     cout << itr -> first << " " << itr -> second << endl;
    // }
    
    for (int i = 0; i < n; i++) {
        cout << ans[a[i]] << endl;
    }
}

Measured memory_bytes: 26880
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) rep(i,v.size())cout<<v[i]<<(i==v.size()-1?"\n":" ");
#define vout(v) VOUT(v,z);
#define vdbg(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL)
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
// template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
// template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
bool is_palindrome(string s){return s == string(s.rbegin(),s.rend());}
#define popcount __builtin_popcount
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) { a = b; return true; }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) { a = b; return true; }
    return false;
}

const string YES = "Yes";
const string NO = "No";
#define judge(f) cout<<((f)?YES:NO)<<"\n";


int main(){
    long long D;
    scanf("%lld",&D);
    long long T;
    scanf("%lld",&T);
    long long S;
    scanf("%lld",&S);
    judge(((D*1.0)/S)<=T);
    return 0;
}


Measured memory_bytes: 3760
int main () {
    int N, M;
    int A[100];
    int next;
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }
    scanf("%d", &M);
    for (int j = 0; j < M; j++) {
        scanf("%d", &next);
        if ((next == 100) || A[next-1] + 1 != A[next]) {
            if (A[next-1] != 2019)
            A[next-1]++;
        } 
    }
    for (int i = 0; i < N; i++) {
        printf("%d\n", A[i]);
    }
}


Measured memory_bytes: 2112
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        String[] inputs = input.readLine().split(" ");
        int K = Integer.parseInt(inputs[0]);
        int S = Integer.parseInt(inputs[1]);

        int[] xPlusY = new int[2 * K + 1];
        for (int x = 0; x <= K; x++) {
            for (int y = 0; y <= K; y++) {
                xPlusY[x + y] += 1;
            }
        }

        int count = 0;
        for (int z = 0; z <= K; z++) {
            int sMinusZ = S - z;
            
            if (sMinusZ <= 2 * K && sMinusZ >= 0) {
                count += xPlusY[sMinusZ];
            }

        }

        System.out.println(count);
    }
}


Measured memory_bytes: 22996
N = int(input())
A = []
for card in input().split():
    A.append([card[0], int(card[1])])
B = A[:]
for i in range(N):
    for j in range(N-1, i, -1):
        if A[j][1] < A[j-1][1]:
            A[j-1], A[j] = A[j], A[j-1]
A = " ".join([i + str(j) for i, j in A])
print(A)   
print("Stable")
for i in range(N-1):
    minj = i
    for j in range(i, N):
        if B[minj][1] > B[j][1]:
            minj = j
    B[i], B[minj] = B[minj], B[i]
B = " ".join([i + str(j) for i, j in B])
print(B)

if B == A:
    print("Stable")
else:
    print("Not stable")


Measured memory_bytes: 5616
#include <iostream>
#include <map>
#include <queue>
#include <algorithm>
#include <vector>
#include <memory.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
typedef pair<int, int> P;
typedef pair<int, P> state;
const int INF = 1 << 28;

struct edge{
  int to;
  int cost;
  edge(){ };
  edge(int to, int cost){
    this->to = to;
    this->cost = cost;
  }
};
map<string, int> names;
int memo[4100][2100];
bool LPG[4100];
map<int, vector<edge> > G;

int main(){
  int cnt;
  int n, m, cap, d;
  string src, dst;
  string c1, c2, str;
  while(cin >> n >> m >> cap && (n || m || cap)){
    int res = INF;
    cnt = 1;
    cap *= 10;
    cin >> src >> dst;

    names.clear();
    G.clear();
    memset(LPG, 0, sizeof(LPG));
    fill(&memo[0][0], &memo[0][0] + 4100 * 2100, INF);
    
    rep(i, n){
      cin >> c1 >> c2 >> d;
      if(!names[c1]) names[c1] = cnt++;
      if(!names[c2]) names[c2] = cnt++;
      G[names[c1]].push_back(edge(names[c2], d));
      G[names[c2]].push_back(edge(names[c1], d));
    }
    rep(i, m){
      cin >> str;
      LPG[names[str]] = true;
    }
    int s = names[src];
    int t = names[dst];
    memo[s][cap] = 0;
    priority_queue<state, vector<state>, greater<state> > que;
    que.push(state(0, P(s, cap)));
    while(!que.empty()){
      state st = que.top(); que.pop();
      int cost = st.first;
      int pos = st.second.first;
      int tank = st.second.second;
      if(cost > memo[pos][tank]) continue;
      if(pos == t) res = min(res, cost);
      rep(i, (int)G[pos].size()){
	int need = G[pos][i].cost;
	int nxt = G[pos][i].to;
	
	if(tank - need >= 0){
	  int ntank = LPG[nxt] ? cap : tank - need;
	  if(memo[nxt][ntank] > cost + need){
	    memo[nxt][ntank] = cost + need;
	    que.push(state(cost + need, P(nxt, ntank)));
	  } 
	}
      }
    }
    if(res == INF) res = -1;
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 47000
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

int main(void){
	int n,x;
	cin >> n >> x;
	vector<int> delta;
	for(int i=0;i<n;++i){
		int xi;
		cin >> xi;
		delta.push_back(abs(xi-x));
	}
	sort(delta.begin(),delta.end());
	int res = delta[0];
	for(int i=1;i<n;++i){
		res = gcd(res,delta[i]);
	}
	cout << res << endl;
}

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)+1):((m)-(n)+1)),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

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

inline bool isD(string s) { return s.find('_') != string::npos; }
inline bool isL(string s) { return !isD(s) && islower(s[0]); }
inline bool isU(string s) { return !isD(s) && isupper(s[0]); }

vector<string>
splitL(string s) {
  vector<string> ret;
  int idx = 0;
  rep(i, s.size()) {
    if (isupper(s[i])) {
      string w = char(tolower(s[idx])) + s.substr(idx + 1, i - idx - 1);
      ret.push_back(w);
      idx = i;
    }
  }
  string w = char(tolower(s[idx])) + s.substr(idx + 1, s.size() - idx - 1);
  ret.push_back(w);
  return ret;
}

vector<string>
splitU(string s) {
  return splitL(char(tolower(s[0])) + s.substr(1, s.size() - 1));
}

vector<string>
splitD(string s) {
  vector<string> ret;
  int idx = 0;
  rep(i, s.size()) {
    if (s[i] == '_') {
      ret.push_back(s.substr(idx, i - idx));
      idx = i + 1;
    }
  }
  ret.push_back(s.substr(idx, s.size() - idx));
  return ret;
}

string toL(vector<string>&v) {
  string r = v[0];
  for (int i=1; i < v.size(); ++i) {
    r += char(toupper(v[i][0])) + v[i].substr(1, v[i].size() - 1);
  }
  return r;
}

string toU(vector<string>&v) {
  string r = "";
  for (int i=0; i < v.size(); ++i) {
    r += char(toupper(v[i][0])) + v[i].substr(1, v[i].size() - 1);
  }
  return r;
}

string toD(vector<string>&v) {
  string r = v[0];
  for (int i=1; i < v.size(); ++i) {
    r += "_" + v[i];
  }
  return r;
}

int main() {

more:
  string s, t;
  cin >> s >> t;
  
  if (t == "X") return 0;

  vector<string> v;
  if (isL(s)) {
    v = splitL(s);
  } else if (isU(s)) {
    v = splitU(s);
  } else if (isD(s)) {
    v = splitD(s);
  }

  if (t == "U") {
    cout << toU(v) << endl;
  } else if (t == "L") {
    cout << toL(v) << endl;
  } else if (t == "D") {
    cout << toD(v) << endl;
  }

  goto more;
}

Measured memory_bytes: 1208
N, W = map(int, input().split())
items = [tuple(map(int, input().split())) for _ in range(N)]
dp = [[0]*(W+1) for _ in range(N+1)]
for i in range(N):
    vv, ww = items[i]
    for w in range(W+1):
        if w >= ww:
            dp[i+1][w] = max(dp[i][w], dp[i][w-ww]+vv)
        else:
            dp[i+1][w] = dp[i][w]
print(dp[N][W])


Measured memory_bytes: 25500
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
import sys,bisect,string,math,time,functools,random
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[];g=[[] for i in range(n)]
    for i in range(E):
        inp=LI();org_inp.append(inp)
        if index==0:inp[0]-=1;inp[1]-=1
        if len(inp)==2:
            a,b=inp;g[a].append(b)
            if not Directed:g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb)
            if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=[],replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[1]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[1]+[mp_def[j] for j in s]+[1]
    mp+=[1]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(k,n=2):return [[tb//(n**bt)%n for bt in range(k)] for tb in range(n**k)]
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

h,w=LI()
h,w,g,sg=GGI(h,w)
dp=[1e6]*(h*w)
dp[w+1]=g[w+1]

for j in range(h*w-w):
  for d in (1,w):
    dp[j+d]=min(dp[j]+1 if (g[j],g[j+d])==(0,1) else dp[j],dp[j+d])

print(dp[(h-2)*w+w-2])


Measured memory_bytes: 42732
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <list>
#include <queue>
#include <string>
#include <vector>
using namespace std;

#define ll long long

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

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

const ll INF = 1LL << 60;
const ll MAX = 100100;
const ll MAX_N = 100100;
const ll MAX_M = 100100;

void aprint(vector<int> &a, int N) {
    for(int i = 0; i < N; i++) {
        if(i)
            cout << " ";
        cout << a[i];
    }
    cout << endl;
}

void MergeCompare(vector<int> &a, int left, int mid, int right) {
    vector<int> buf;

    for(int i = left; i < mid; i++) {
        buf.push_back(a[i]);
    }
    for(int i = right - 1; i >= mid; i--) {
        buf.push_back(a[i]);
    }

    int iterator_left = 0;
    int iterator_right = (int)buf.size() - 1;
    for(int i = left; i < right; i++) {
        if(buf[iterator_left] <= buf[iterator_right]) {
            a[i] = buf[iterator_left];
            iterator_left++;
        } else {
            a[i] = buf[iterator_right];
            iterator_right--;
        }
    }
}

void MergeSort(vector<int> &a, int left, int right) {
    int N = a.size();
    if(right - left == 1) {
        return;
    }
    int mid = left + (right - left) / 2;
    // cout << "left: " << left << endl;
    // cout << "mid: " << mid << endl;
    // cout << "right: " << right << endl;
    MergeSort(a, left, mid);
    MergeSort(a, mid, right);

    MergeCompare(a, left, mid, right);
    aprint(a, N);
}

int main() {
    string s;
    int ans = 0;
    cin >> s;
    if(s == "SUN") {
        ans = 7;
    } else if(s == "MON") {
        ans = 6;
    } else if(s == "TUE") {
        ans = 5;
    } else if(s == "WED") {
        ans = 4;
    } else if(s == "THU") {
        ans = 3;
    } else if(s == "FRI") {
        ans = 2;
    } else if(s == "SAT") {
        ans = 1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import numpy as np
from copy import deepcopy

N = int(input())
A = list(map(int,input().split()))

## 一番小さい数のmodを取ることを繰り返す
## (一番体力の少ないものが可能な限り攻撃する)
## set使わなくても.indexは最初のインデックスを取得してくれるわ

def ABC118(lst):
  if len(lst) == 1:
    return lst[0]
  new_lst = deepcopy(list(set(lst)))
  min_idx = new_lst.index(min(new_lst))
  min_var = new_lst[min_idx]
  new_lst = [(new_lst[i] % min_var) for i in range(len(new_lst)) if i != min_idx]
  new_lst.append(min_var)
  new_lst = [x for x in new_lst if x != 0]
  return(ABC118(new_lst))
  
ans = ABC118(A)
print(ans)
  
  

Measured memory_bytes: 23288
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
int main(){
    int N;
    cin >> N;
    vector <int> H(N);
    for(int i = 0;i<N;i++){
        cin >> H[i];
    }
    for(int i = 0;i<N-1;i++){
        if(i>=1 && H[i]==H[i-1]){

        } 
        else{
            H[i]--;
        }
    }
    bool ans =true;
    for(int i = 0;i<N-1;i++){
        if(H[i]>H[i+1]){
            ans = false;
        }
    }
    if(ans){
        cout <<"Yes" << endl;
    }
    else{
        cout << "No" <<endl;
    }
    
   
}

Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
#define rep(i,q) for(int i = 0; q > i; i++)
int main(){
  int N;
  cin>>N;
  vector<int> s;
  rep(i,N){
    int tmp;cin>>tmp;
    s.push_back(tmp-1);
    s.push_back(tmp);
    s.push_back(tmp+1);
  }
  int kazu[100001];
  rep(i,100001)kazu[i] = 0;
  rep(i,s.size())kazu[s[i]]++;
  int mx = 0;
  rep(i,100001)mx = max(kazu[i],mx);
  cout << mx << endl;
}

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

int main() {
  int n;
  cin >> n;
  int num = n;
  int sum = 0;

  while (num) {
    sum += (num % 10);
    num /= 10;
  }
  if (n % sum == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import sys, math
from itertools import accumulate
sys.setrecursionlimit(10**9)

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

# unionfind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def main():
    N, M = mi()
    A, B = i2(M)
    
    uf = UnionFind(N)
    for i in range(M):
        uf.union(A[i]-1, B[i]-1)

    print(uf.group_count()-1)

if __name__ == "__main__":
    main()

Measured memory_bytes: 35924
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;

vector<int> adj[MAXN];
int dp[MAXN];
bool visited[MAXN];
// add dp optimization

int dfs(int s){
//	visited[s] = true;
	if(dp[s] != -1) return dp[s];
	int res = 0;	
	for(int u:adj[s]){
		res = max(res, dfs(u) + 1);
	}
	dp[s] = res;
	return dp[s];
}
int main(){
	int n,  m;
	cin>>n>>m;
	for(int i = 0;i<=n;i++){
		dp[i] = -1;
		visited[i] = false;
	}
	while(m--){
		int t1, t2;
		cin>>t1>>t2;
		adj[t1].push_back(t2);
	}
	int ans = 0;
	for(int i = 1;i<=n;i++){
		ans = max(ans, dfs(i));

	}
	cout<<ans<<endl;
	return 0;
}


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

int main() 
{
    long long int n,m,k,i,ans=0;
    cin>>n>>m>>k;
    long long int a[n+1],b[m+1];
    a[0]=0,b[0]=0;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
        a[i]+=a[i-1];
    }
    for(i=1;i<=m;i++)
    {
        cin>>b[i];
        b[i]+=b[i-1];
    }
    for(i=0;i<=n;i++)
    {
        if(a[i]<=k)
        ans=max(ans,i);
        long long int l=0,r=m,t1=-1;
        while(l<=r)
        {
            long long int mid=(l+r)/2;
            if(b[mid]+a[i]>k)
            {
                r=mid-1;
            }
            else
            {
                t1=max(t1,mid);
                l=mid+1;
            }
        }
        if(t1!=-1)
        ans=max(ans,i+t1);
    }
    cout<<ans;
	return 0;
}


Measured memory_bytes: 6744
H,W,M = gets.split.map(&:to_i)
m = $<.map{|ln| ln.split.map{|_|_.to_i-1} }

hx,hh = 0,[0]*H
wx,ww = 0,[0]*W
m.each{|h,w|
	hx = hh[h] if hx < hh[h]+=1
	wx = ww[w] if wx < ww[w]+=1
}

hxn = hh.count(hx)
wxn = ww.count(wx)
mxn = m.count{|h,w| hh[h]==hx && ww[w]==wx }

p hx+wx-(mxn==hxn*wxn ? 1 : 0)


Measured memory_bytes: 37832
#include <iostream>
#include <algorithm>
#include <limits>

int main()
{
    size_t N;
    std::cin >> N;
    size_t sum = 0;
    size_t s = 0;
    bool mins_found = false;
    size_t mins = std::numeric_limits<size_t>::max();
    for (size_t i = 0; i < N; i++) {
        std::cin >> s;
        sum += s;
        if (s % 10 != 0) {
            if (mins_found) {
                mins = std::min(mins, s);
            } else {
                mins_found = true;
                mins =  s;
            }
        }
    }

    if (!mins_found) {
        std::cout << 0 << std::endl;
    } else if (sum % 10 == 0) {
        std::cout << sum - mins << std::endl;
    } else {
        std::cout << sum << std::endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main() {
  int N;
  int p[10];
  int i; /* index */
  scanf("%d",&N);
  for (i = 0;i < N;++i) {
    scanf("%d",&p[i]);
  }
  int max = p[0];
  for (i = 0;i < N;++i) {
    if (max < p[i]) {
      max = p[i];
    }
  }
  int ans = 0;
  for (i = 0;i < N;++i) {
    ans	+= p[i];
  }
  ans =	ans - max + max	/ 2;
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using ll = long long;
using P = pair<ll,ll>;
using vec = vector<ll>;
using vecp = vector<P>;
using mat = vector<vec>;
using matp = vector<vecp>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define all(v) v.begin(), v.end()
 
ll modPow(ll a, ll n) {
  if (n == 0) return 1; // 0乗にも対応する場合
  if (n == 1) return a % MOD;
  if (n % 2 == 1) return (a * modPow(a, n - 1)) % MOD;
  ll t = modPow(a, n / 2);
  return (t * t) % MOD;
}

int main(){
  ll N;
  cin >> N;
  ll ans=modPow(10,N)-2*modPow(9,N)+modPow(8,N);
  ans+=2*MOD;
  ans%=MOD;
  cout << ans << endl;
}

Measured memory_bytes: 3640
/*
 *  Created on: 6-August-2019
 *      Author: ankur314
 */
#include<bits/stdc++.h>
#define lli long long int
#define li long int
#define db double
#define ldb long double
#define vr vector
#define it iterator
#define fi(i,a,n) for(int i=a;i<n;i++)
#define fli(i,a,n) for(long int i=a;i<n;i++)
#define flli(i,a,n) for(long long int i=a;i<n;i++)
#define pb(n) push_back(n)
#define ppf() pop_front()
#define pii pair<int,int>
#define MOD 1000000007

#define debug1(x) cout<<x<<"\n"
#define debug2(x,y) cout<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define debug4(x,y,z,w) cout<<x<<" "<<y<<" "<<z<<" "<<w<<"\n"

using namespace std;

int dp[3005][3005];

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    /*freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);*/
    string s,t;cin>>s>>t;
    int n=s.length();
    int m=t.length();
    fi(i,0,n+1)
    {
        fi(j,0,m+1)
        {
            if(i==0 || j==0)
            {
                dp[i][j]=0;
            }
            else if(s[i-1] == t[j-1])
            {
                dp[i][j] = 1 + dp[i-1][j-1];
            }
            else
            {
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }
    int i=n,j=m;
    string ans="";
    while(i>0 && j>0)
    {
        if(s[i-1] == t[j-1])
        {
            ans += s[i-1];
            i--;
            j--;
        }
        else if(dp[i-1][j] > dp[i][j-1])
        {
            i--;
        }
        else
        {
            j--;
        }
    }
    reverse(ans.begin(), ans.end());
    cout<<ans;
    return 0;
}


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

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

    if (s[0] == s[1] && s[1] == s[2])
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <cmath>
#include <string.h>
#include <cstring>
#include <vector>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <queue>
#include <stack>
#include <algorithm>
#define INF 1000000000
#define rep(i,n) for(int (i) = 0; (i) < (n); (i)++)
#define sove(v) sort((v).begin(),(v).end());
typedef long long int ll;
using namespace std;
int main(){

	int n; cin >> n;
	vector<int> x(n);
	int minn = INF, maxx = 0;
	rep(i, n) { 
		cin >> x[i];
		minn = min(minn, x[i]);
		maxx = max(maxx, x[i]);
	}
	int ans = INF;
	for (int i = minn; i <= maxx; i++) {
		int way = 0;
		rep(j, n) {
			way += (x[j] - i) * (x[j] - i);
		}
		ans = min(ans, way);
	}
	
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
//start of jonathanirvings' template v3.0.3 (BETA)

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

#ifdef TESTING
  #define DEBUG fprintf(stderr,"====TESTING====\n")
  #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
  #define debug(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DEBUG 
  #define VALUE(x)
  #define debug(...)
#endif

#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define REP(i,n) FOR(i,0,n)
#define REPN(i,n) FORN(i,1,n)
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)

inline string IntToString(LL a){
  char x[100];
  sprintf(x,"%lld",a); string s = x;
  return s;
}

inline LL StringToInt(string a){
  char x[100]; LL res;
  strcpy(x,a.c_str()); sscanf(x,"%lld",&res);
  return res;
}

inline string GetString(void){
  char x[1000005];
  scanf("%s",x); string s = x;
  return s;
}

inline string uppercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}

inline string lowercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}

inline void OPEN (string s) {
  #ifndef TESTING
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
  #endif
}

//end of jonathanirvings' template v3.0.3 (BETA)

int n;
LL data[200005];
LL now = 0;
LL risan = 0;

int main()
{
  scanf("%d",&n);
  REP(i,n) scanf("%lld",&data[i]);
  FORD(i,n-1,0)
  {
    if (data[i] < now)
    {
      puts("-1");
      return 0;
    }
    if (data[i] > now)
    {
      if (i - data[i] < 0)
      {
        puts("-1");
        return 0;
      }
      risan += data[i];
      now = data[i];
    }
    now = max(0LL,now-1);
  }  
  printf("%lld\n",risan);
  return 0;
}











Measured memory_bytes: 1792
import sys
def input():
    return sys.stdin.readline()[:-1]

N = int(input())
S = input()
ans = 0
for i in range(1000):
    num = str(i).zfill(3)
    _idx = 0
    flag = True
    for n in num:
        ind = S[_idx:].find(n)
        if ind==-1:
            flag = False
            break
        else:
            _idx = _idx + ind+1
    if flag:
        ans += 1
print(ans)

Measured memory_bytes: 41324
def main():
    N = int(input())
    A = sorted([int(a) for a in input().split()], reverse = True)
    Alice = 0
    for i in range(N):
        if i % 2 == 0:
            Alice += A[i]
    return 2*Alice - sum(A)

if __name__ == '__main__':
    print(main())


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

#define int long long
#define DEBUG 0
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) if(DEBUG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DEBUG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
using pii = pair<int, int>; using vi = vector<int>;
static const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
static const int MOD = (int)(1e9 + 7);

#define MAX_X 100010

signed main() {
	int N, M; cin >> N >> M;
	int cnt[MAX_X] = {};
	//vector<vector<int>> v(5, vector<int>());
	//rep(i, 0, N) {
	//	int X; cin >> X;
	//	v[X%M].emplace_back(X);
	//	cnt[X]++;
	//}
	//rep(i, 0, 5)sort(all(v[i]));

	vector<vector<int>> v(M, vector<int>());
	rep(i, 0, N) {
		int X; cin >> X;
		v[X%M].emplace_back(X);
		cnt[X]++;
	}
	vector<int> cntd(M, 0);
	rep(i, 0, MAX_X) {
		cntd[i%M] += cnt[i] / 2;
	}

	int ans = 0;
	ans += v[0].size() / 2;
	if (M % 2 == 0)ans += v[M / 2].size() / 2;
	rep(i, 1, M / 2 + 1) {
		if (M % 2 == 0 && i == M / 2)continue;
		int c = min(cntd[i], cntd[M - i]);
		//int add = c * 2;
		//cntd[i] -= c;
		//cntd[M - i] -= c;
		//dump(c);
		int add = 0;
		int add2 = min(v[i].size(), v[M - i].size());
		int add3 = 0;
		if (add2 == v[i].size()) {
			add3 += min(
				((int)v[M - i].size() - add2) / 2,
				cntd[M - i]
			);
		}
		else {
			add3 += min(
				((int)v[i].size() - add2) / 2,
				cntd[i]
			);
		}
		dump(add);
		dump(add2);
		dump(add3);
		ans += add+add2+add3;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 7296
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>

using namespace std;

int n,c,k,q,sm=0,z,st[100010],cud=0;
//vector<int> t;

int main(){
    scanf("%d %d %d",&n,&c,&k);
    for(int i=0;i<n;i++){
        scanf("%d",&st[i]);
    }
    sort(st,st+n);
    
    while(cud!=n){
        z=0;
        for(int i=cud;i<n;i++){
            if(st[i]<=st[cud]+k)z++;
            else break;
            if(z==c)break;
        }
        sm++;
        cud+=z;
    }
    
    printf("%d\n",sm);
    
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int N; cin>>N;
  vector<pii> A(N);
  rep(i,0,N) cin>>A[i].first>>A[i].second;
  vi X(N),Y(N);
  sort(ALL(A));
  rep(i,0,N){
    X[i]=A[i].first;
    Y[i]=A[i].second;
  }
  int ans=0;
  rep(i,0,N-1){
    rep(j,i+1,N){
      int P=X[j]-X[i],Q=Y[j]-Y[i];
      int count=0;
      rep(k,0,N-1){
        rep(l,i+1,N){
          if(X[l]-X[k]==P&&Y[l]-Y[k]==Q)
            count++;
        }
      }
      ans=max(ans,count);
    }
  }
  cout<<N-ans<<endl;
  }



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

using namespace std;

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

  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  int ans = 0;
  for (int k = 1; k <= 100000; k++) {
    int temp = lower_bound(v.begin(), v.end(), k) - v.begin();
    if (temp == n / 2) ++ans;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640