akhauriyash/Code-Regression huggingface dataset:
n = int(input())
point = [-1] * 394
for _ in range(n):
  s, l, p = map(int, input().split())
  for i in range(s, l + 1):
    point[i] = max(point[i], p)

for i in range(394):
  for j in range(i):
    point[i] = max(point[i], point[j] + point[i - j])

m = int(input())
ans = []
for _ in range(m):
  ans.append(point[int(input())])
if -1 in ans:print(-1)
else:print(*ans,sep="\n")


Measured memory_bytes: 5672
#include <iostream>
#include <vector>

int main() {
    int h, w;
    std::cin >> h >> w;
    std::vector<std::vector<char>> mine(h, std::vector<char>(w, ' '));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            std::cin >> mine[i][j];
        }
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (mine[i][j] == '#') {
                continue;
            }
            int cnt = 0;
            for (int k = -1; k <= 1; k++) {
                for (int l = -1; l <= 1; l++) {
                    if (((k == 0) && (l == 0)) ||
                        (i+k < 0) ||
                        (h <= i+k) ||
                        (j+l < 0) ||
                        (w <= j+l)
                    ) {
                        continue;
                    }
                    if (mine[i+k][j+l] == '#') {
                        cnt++;
                    }
                }
            }
            mine[i][j] = cnt + '0';
        }
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            std::cout << mine[i][j];
        }
        std::cout << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <math.h> // sqrt
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <iomanip> // setprecision
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;

int main() {
    string S, T;
    cin >> S >> T;
    int N = S.size();
    for (int i = 0; i < N; i++) {
        bool check = true;
        int j = i;
        for (int k = 0; k < N; k++) {
            if (j == N) {
                j = 0;
            }
            if (S[j] != T[k]) {
                check = false;
                break;
            }
            j++;
        }
        if (check) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


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

int main() {
  string s;
  cin >> s;
  reverse(s.begin(),s.end());
  int n = s.size();
  ll sum = 0;
  for (int bit = 0; bit < (1<<n-1); ++bit){
    ll c = 1;
    rep(i,n-1){
      if(bit & (1<<i)){
        sum += c*(s[i]-'0');
        c = 1;
      }
      else{
        sum += c*(s[i]-'0');
        c *= 10;
      }
    }
    sum += c*(s[n-1]-'0');
  }
  cout << sum << endl;
}

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

#define int long long

using namespace std;

const int MAXN = 1e6 + 100;

int A[MAXN];

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int N;
    cin >> N;

    for(int i = 1 ; i < MAXN ; i++)
    {
    	for(int j = i ; j < MAXN ; j+=i)
    	{
    		A[j]++;
    	}
    }

    int res = 0;

    for(int i = 1 ; i < N ; i++)
    {
    	res += A[i];
    }

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 11468
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(int I = int((B)-1); I >= int(A); --I)

int main(){

	ll n;
	cin >> n;
	ll a[n+1]={} , dp[n+1][n+1] , sum[n+1]={};

	FOR(i,1,n+1){
		cin >> a[i];
		sum[i] = sum[i-1] + a[i];// 累積和を計算しておく -> 合体のコストを高速に計算するため
	}
	FOR(i,1,n+1){
		FOR(j,1,n+1){
			dp[i][j] = 1LL<<50;// 最小を求めたいので、初期値は大きい値にしておく
			if(i==j)dp[i][j] = 0;
			// i==jではスライムが1体しかいないので合体コストは0,この情報からどのようにループをすればいいか考える
			// 1体の次は2体の結合、次は3体の結合...と求められそう
		}
	}

	FOR(i,1,n+1){ // i := 幅 -> 区間の幅が小さいものから決まっていく
		FOR(j,1,n+1-i){ // j := 左端 -> [j,j+i]の区間を考える
			FOR(k,j,j+i){ // [j,k]と[k+1,j]の合体を考える , それぞれ今考えている区間の長さより短いので計算済みである
				dp[j][j+i] = min(dp[j][j+i] , dp[j][k] + dp[k+1][j+i] + sum[j+i] - sum[j-1]);
				// [i,j+i]のコストは[i,k],[k+1,j+i]にそれぞれかかったコストと今回かかるコストの和
				// それぞれのkでminを取る
			}
		}
	}
	cout << dp[1][n] << endl;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
    cin >> a;
    b = 0;
  b = b + a % 10;
  a = a / 10;
  b = b + a % 10;
  a = a / 10;
  b = b + a % 10;
  cout << b << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define pb push_back
#define pi pair<int, int>
#define l first
#define r second
#define all(x) x.begin(), x.end()
#define fori(a, b, step) for (int i = a; i < b; i += step)
#define forj(a, b, step) for (int j = a; j < b; j += step)
#define int long long

const int maxn = 2e5 + 1, mod = 200003;
const int cmaxn = (1 << 19);

using namespace std;

int nm[mod], rnm[mod], cnt[cmaxn], nc[cmaxn];

int bp(int x, int n) {
    if (!n) return 1;
    if (n % 2) return (x * bp(x, n - 1)) % mod;
    return bp((x * x) % mod, n / 2);
}

typedef complex<long double> cpl;
typedef int32_t i32;

cpl sang[cmaxn + 1], iang[cmaxn + 1];

void init() {
    double TH = 2 * acos(-1);
    for (int i = 1; i <= cmaxn; i *= 2) {
        sang[i] = cpl(cos(TH / i), sin(TH / i));
        iang[i] = cpl(cos(-TH / i), sin(-TH / i));
    }
}

inline void fft(vector<cpl> &a, vector<cpl> &ans, int cl, int l, int step, int n, bool inv) {
    if (n == 1) {
        ans[l] = a[cl];
        return;
    }
    fft(a, ans, cl, l, step * 2, n / 2, inv);
    fft(a, ans, cl + step, l + n / 2, step * 2, n / 2, inv);
    cpl w(1), cw = (!inv ? sang[n] : iang[n]);;
    for (int i = l; i < l + n / 2; i++) {
         cpl u1 = ans[i], tm = w * ans[i + n / 2];
         ans[i] = u1 + tm;
         ans[i + n / 2] = u1 - tm;
         if (inv) {
            ans[i] /= 2; ans[i + n / 2] /= 2;
         }
         w *= cw;
    }
}

int a[cmaxn];

void calc() {
    vector<cpl> gv(cmaxn, 0), ga(cmaxn, 0);
    for (int i = 0; i < cmaxn; i++)
        gv[i] = cnt[i];
    fft(gv, ga, 0, 0, 1, cmaxn, 0);
    for (int i = 0; i < cmaxn; i++) {
        ga[i] *= ga[i];
        gv[i] = 0;
    }
    fft(ga, gv, 0, 0, 1, cmaxn, 1);
    for (int i = 0; i < cmaxn; i++)
        nc[i] = (int)(gv[i].real() + 0.5);
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n; cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    int cx = mod - 1;
    vector<int> prs;
    for (int i = 2; i * i <= cx; i++) {
        if (i == 1 || cx % i) continue;
        prs.pb(i);
        while (cx % i == 0) cx /= i;
        i = 1;
    }
    int rt = 2, cr = 2;
    rnm[0] = 1;
    for (int i = 1; i < mod - 1; i++) {
        nm[cr] = i;
        rnm[i] = cr;
        cr = (cr * rt) % mod;
    }
    for (int i = 0; i < n; i++) {
        if (a[i] == 0) continue;
        ++cnt[nm[a[i]]];
    }
    init(); calc();
    int ans = 0;
    for (int i = 0; i < 2 * mod; i++) {
        int cn = nc[i];
        if (i % 2 == 0)
            cn -= cnt[i / 2];
        cn /= 2;
        nc[i] = cn;
        ans += rnm[i % (mod - 1)] * cn;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 46976
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <deque>
#include <queue>

#define pb push_back
#define mp make_pair
#define x first
#define y second
#define FOR(i, a, b) for(int i=a, loop=b; i<=loop; ++i)
#define REV(i, a, b) for(int i=a, loop=b; i>=loop; --i)
#define mize(a, b) a = min(a, b)
#define maxi(a, b) a = max(a, b)
#define shl(k) ((k) << 1)
using namespace std;

const int N = 1e5+5;
int n, m, q, a[N], b[N];
char s[N], t[N];

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

    cin >> (s+1) >> (t+1);
    n = strlen(s+1); m = strlen(t+1);

    FOR(i, 1, n) a[i] = a[i-1] + (s[i]=='A'?+1:-1);
    FOR(i, 1, m) b[i] = b[i-1] + (t[i]=='A'?+1:-1);

    cin >> q; while (q--) {
        int u, v ,l ,r, x, y;
        cin >> u >> v >> l >> r;
        x = ((a[v]-a[u-1]) % 3 + 3) % 3;
        y = ((b[r]-b[l-1]) % 3 + 3) % 3;
        if (x == y) cout << "YES\n"; else cout << "NO\n";
    }
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
//登録しよう！→ https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater //sortを降順にする
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示

void solve(long long A, long long B){
  vector<ll> a,b;
  set<ll> ans{1};
  for(auto p : prime_factor(A)) {
    while(p.second--)a.pb(p.first);
  }
  for(auto p : prime_factor(B)) {
    while(p.second--)b.pb(p.first);
  }
  for (int i = 0; i < a.size(); i++) {
    for (int l = 0; l < b.size(); l++) {
      if(a[i] == b[l]){
        ans.insert(a[i]);
      }
    }
  }
  cout << ans.size() << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
}


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

using namespace std;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

int W, H;
string s[51];
bool visited[51][51];
bool dfs(int y, int x, char c) {
    if (s[y][x] != '.' && s[y][x] != c) return false;
    if (s[y][x] == c) return true;
    bool ret = true;
    rep(k, 4) {
        int ny = y + dy[k];
        int nx = x + dx[k];
        if (ny < 0 || nx < 0) continue;
        if (H <= ny || W <= nx) continue;
        if (visited[ny][nx]) continue;
        if (s[y][x] != '.') continue;
        visited[ny][nx] = true;
        ret &= dfs(ny, nx, c);
    }
    return ret;
}
void solve() {
    int ans1 = 0, ans2 = 0;
    int cnt = 0;
    rep(i, H) rep(j, W) {
        if (s[i][j] == '.') cnt++;
        if (s[i][j] != '.') continue;
        if (dfs(i, j, 'B')) ans1++;
        memset(visited, 0, sizeof(visited));
        if (dfs(i, j, 'W')) ans2++;
        memset(visited, 0, sizeof(visited));
    }
    if (cnt == H * W) {
        cout << "0 0" << endl;
    } else {
        cout << ans1 << " " << ans2 << endl;
    }
}
int main() {
    while (cin >> W >> H, W) {
        rep(i, H) cin >> s[i];
        solve();
    }
    return 0;
}
/*
.....W....
....W.W...
...W...W..
....W...W.
.....W...W
......W.W.
BBB....W..
..B..BBBBB
..B..B....
..B..B..W.
*/

Measured memory_bytes: 3468
import sys
sys.setrecursionlimit(10**7)
from bisect import bisect_left
INF=10**18
def dfs(v,p,max_):
    b=bisect_left(dp,a[v])
    memo=(b,dp[b])
    dp[b]=a[v]
    if b>max_:
        max_=b
    ans[v]=max_
    for nv in G[v]:
        if nv==p:
            continue
        dfs(nv,v,max_)
    dp[memo[0]]=memo[1]

N=int(input())
a=list(map(int,input().split()))
G=[[] for i in range(N)]
for i in range(N-1):
    u,v=map(lambda x:int(x)-1,input().split())
    G[u].append(v)
    G[v].append(u)
dp=[INF]*(N+1)
dp[0]=-1
ans=[-1]*N
dfs(0,-1,0)
print(*ans,sep='\n')

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

using namespace std;

class Solution {
public:
	void solve() {
		int n, k, c;
		string s;
		cin >> n >> k >> c >> s;
		vector<bool> yes(n), ryes(n);
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			if (s[i] == 'o') {
				yes[i] = true;
				i += c;
				cnt++;
			}
		}
		if (cnt > k) return;
		for (int i = n - 1; i >= 0; i--) {
			if (s[i] == 'o') {
				ryes[i] = true;
				i -= c;
			}
		}
		for (int i = 0; i < n; i++) {
			if (yes[i] & ryes[i]) {
				cout << i + 1 << endl;
			}
		}
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

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

const int INF = 1000000007;
int dp[100010]; // 少し多めに確保

int main () {

    dp[0] = 0;

    for (int n = 1; n <= 100000; n++) {
        dp[n] = INF;
        int power = 1;
        while (power <= n) {
            dp[n] = min(dp[n], dp[n - power] + 1);
            power *= 6;
        }

        power = 1;
        while (power <= n) {
            dp[n] = min(dp[n], dp[n - power] + 1);
            power *= 9;
        }
    }

    int N;
    cin >> N;

    cout << dp[N] << endl;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>

using namespace std;

double dist(vector<int> &x, vector<int> &y, int i, int j)
{
    double dx = x[i] - x[j];
    double dy = y[i] - y[j];
    return pow(dx * dx + dy * dy, 0.5);
}

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

    double sum = 0.0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            sum += dist(x, y, i, j);
        }
    }
    cout << fixed << setprecision(10) << sum / N << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<list>
#include<map>
#include<vector>

using namespace std;


#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int main(){
    string S;
    cin >> S;
    rep(i, S.size()) cout << 'x';
    cout << endl;



	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int dp[3001][3001][2];
class solution {
private:
	char str[2][3001];
	int serc(int x, int y) {
		if (str[0][x] == '\0') return 0;
		if (str[1][y] == '\0') return 0;
		if (dp[x][y][0] != -1) return dp[x][y][0];
		dp[x][y][0] = 0;
		int tmp;
		if (str[0][x] == str[1][y]) {
			tmp = 1 + serc(x + 1, y + 1);
			if (tmp > dp[x][y][0]) {
				dp[x][y][0] = tmp;
				dp[x][y][1] = 1;
			}
		}
		tmp = serc(x + 1, y);
		if (tmp > dp[x][y][0]) {
			dp[x][y][0] = tmp;
			dp[x][y][1] = 2;
		}
		tmp = serc(x, y + 1);
		if (tmp > dp[x][y][0]) {
			dp[x][y][0] = tmp;
			dp[x][y][1] = 3;
		}
		return dp[x][y][0];
	}
public:
	solution() {
		scanf("%s %s", str[0], str[1]);
		for (int i = 0; i < 3001; i++) {
			for (int j = 0; j < 3001; j++) {
				dp[i][j][0] = -1;
			}
		}
		serc(0, 0);
		int x = 0, y = 0;
		while (str[0][x] != '\0' && str[1][y] != '\0') {
			if (dp[x][y][1] == 1) {
				printf("%c", str[0][x]);
				x++;
				y++;
			}
			else if (dp[x][y][1] == 2) x++;
			else y++;
		}
		printf("\n");
	}
};

#ifndef L0C4L
int main() {
	solution();
	return 0;
}
#endif

Measured memory_bytes: 70912
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(), v.end()
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define cc continue
#define bb break
#define rem 1000000007
#define PI 3.141592653589793238462643383279502
//fflush(stdin);
// do {
// // process permutation
// } while (next_permutation(permutation.begin(),permutation.end()));
//vector.assign (n,value)... for global vectors
class abc
{
    public:
    ll x,y;
};
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll n;
    cin>>n;
    set <ll> s1;
    rep (i,0,n)
    {
        ll a;
        cin>>a;
        s1.insert(a);
    }
    if (s1.size()==n)
    {
        cout<<"YES\n";
    }
    else
    {
        cout<<"NO\n";
    }
}


Measured memory_bytes: 9600
N=int(input())
X=list(map(int,input().split()))
m=10**10
ll=list(set(X))
for P in range(min(ll),max(ll)+1):
    ans=[(x-P)**2 for x in X]
    s=sum(ans)
    if m>s:
        m=s
print(m)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

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;
}

void calc(int n,VI s){
    if(n==0){
        for(int i=0;i<s.size();i++){
            if(i>0) cout<<" ";
            cout<<s[i];
        }
        cout<<endl;
        return;
    }
    for(int i=n;i>=1;i--){
        if(s.size()>=1&&i>s[s.size()-1]) continue;
        VI t=s;
        t.pb(i);
        calc(n-i,t);
    }
}

int main(){
    int i,j;
    int n;
    while(1){    
    cin>>n;
    if(n==0) break;
    VI s;
    calc(n,s);
    }
}


Measured memory_bytes: 3092
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
typedef pair<short int, short int> P;

#define left ___left
#define right __right

vector<P> edge[2000][2000];
short int right[2000][2000];
short int left[2000][2000];
short int up[2000][2000];
short int down[2000][2000];
int cnt[2000][2000];
char c;
bool field[2000][2000];
int x1, y1, x2, y2;
int n, m, q;
bool done[2000][2000];




void dfs(int x, int y, int lastx = -1, int lasty = -1){
  for(int i = 0;i < edge[x][y].size();i++){
    int nx = edge[x][y][i].first;
    int ny = edge[x][y][i].second;
    if(nx == lastx && ny == lasty)continue;
    if(nx > x)down[x][y]++;
    if(nx < x)up[x][y]++;
    if(ny < y)left[x][y]++;
    if(ny>y)right[x][y]++;
    dfs(nx,ny,x,y);
  }
}

int solve(int x1, int y1, int x2, int y2){
  x1--,y1--,x2--,y2--;
  int res = 0;
  res += cnt[x2][y2];
  if(x1)res -= cnt[x1-1][y2];
  if(y1)res -= cnt[x2][y1-1];
  if(x1 && y1)res += cnt[x1-1][y1-1];
  
  if(x1){
    res += down[x1-1][y2];
    if(y1)res -= down[x1-1][y1-1];
  }
  if(x2 + 1 < n){
    res += up[x2 + 1][y2];
    if(y1)res -= up[x2+1][y1-1];
  }
  if(y1){
    res += right[x2][y1-1];
    if(x1)res -= right[x1-1][y1-1];
  }
  if(y2 + 1 < m){
    res += left[x2][y2+1];
    if(x1)res -= left[x1-1][y2+1];
  }
  return res;    
}

int u[4000001];

int r(int x){
  if(u[x] == x)return x;
  return u[x] = r(u[x]);
}

void unite(int x, int y){
  x = r(x);
  y = r(y);
  if(x == y)return;
  u[x] = y;
}

int main(){
  cin >> n >> m >> q;
  for(int i = 0;i < 4000001;i++)u[i] = i;
  for(int i = 0;i < n;i++){
    for(int j = 0;j < m;j++){
      cin >> c;
      field[i][j] = (int)(c-'0');

      if(field[i][j] == 0)continue;
      if(i > 0 && field[i-1][j]){
	int from = i*m + j;
	int to = (i-1)*m+j;
	unite(from, to);
	edge[i][j].push_back(P(i-1,j));
	edge[i-1][j].push_back(P(i,j));
      }
      if(j > 0 && field[i][j-1]){
	edge[i][j].push_back(P(i,j-1));
	edge[i][j-1].push_back(P(i,j));
	int from = i*m + j;
	int to = i*m+j-1;
	unite(from, to);
      }
    }    
  }

  for(int i = 0;i < n;i++){
    for(int j = 0;j < m;j++){
      if(!field[i][j])continue;
      int tmp = r(i*m+j);
      int ti = tmp / m, tj = tmp % m;
      cnt[ti][tj] = 1;
      if(!done[ti][tj]){
	done[ti][tj] = true;
	dfs(ti, tj);
      }
    }
  }


  for(int i = 0;i < n;i++){
    for(int j = 0;j < m;j++){

      if(i > 0)cnt[i][j] += cnt[i-1][j];
      if(j > 0)cnt[i][j] += cnt[i][j-1];
      if(i > 0 && j > 0)cnt[i][j] -= cnt[i-1][j-1];
      if(i){
	left[i][j] += left[i-1][j];
	right[i][j] += right[i-1][j];
      }
      if(j){
	down[i][j] += down[i][j-1];
	up[i][j] += up[i][j-1];
      }
    }
  }

  
  for(int i = 0;i < q;i++){
    cin >> x1 >> y1 >> x2 >> y2;
    cout << solve(x1, y1, x2, y2) << endl;
  }
  return 0;
}

Measured memory_bytes: 248960
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<iomanip>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;

using namespace std;

int main()
{
    int N, K;   cin >> N >> K;
    int tmp, cnt;
    long double ans=0.0, t;
    for(int i=1; i<=N; i++){
        tmp = i;
        t = 1.0/N;
        while(tmp < K){
            tmp *= 2;
            t *= 0.5;
        }
        ans += t;
    }
    cout << std::fixed << std::setprecision(15) << ans;
}

Measured memory_bytes: 3756
open Scanf
open Printf

let read_int () = scanf " %d" (fun x -> x)

let rec read_ints n =
  if n = 0
  then []
  else scanf " %d" (fun x -> x) :: read_ints (n-1)

let () =
  let n = read_int () in
  let xs = List.sort (fun a b -> b - a) (read_ints n) in
  let _, ans = List.fold_left (fun (m, s) v -> (-m, s + v * m)) (1, 0) xs in
  printf "%d\n" ans


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

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

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) { return a * b / GCD(a, b); }


ll solve(int N, ll M, vector<ll> &a) {
    while(a.at(0) % 2 == 0) { // 先頭の要素が2で割れるなら他の要素も割れないとだめ。
        rep(i, N) {
            if (a.at(i) % 2 != 0) return 0;
            a.at(i) /= 2;
        }
        M /= 2;
    }
    rep(i, N) if (a.at(i) % 2 == 0) return 0; // 先頭の要素以外がさらに2で割れる場合はだめ。

    ll lcm = 1;
    rep(i, N) {
        lcm = LCM(lcm, a.at(i));
        if (lcm > M) return 0;
    }

    return ((M / lcm ) + 1) / 2;
}


int main(){
    int N;
    ll M;

    cin >> N >> M;

    vector<ll> a(N);
    rep(i, N) {
        cin >> a.at(i);
        a.at(i) /= 2;
    }

    cout << solve(N, M, a) << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(int argc, char const *argv[]) {
  int D, N;
  //入力
  scanf("%d %d", &D, &N );
  //計算
  int ans = 1;
  for (size_t i = 0; i <= D; i++) {
    ans = ans*100;
  }
  ans = (ans/100)*N;
  //例外処理
  if ( ans == 100 ) {
    ans = ans + 1;
  } else if ( ans == 10000 ) {
    ans = ans + 100;
  } else if ( ans == 1000000 ){
    ans = ans + 10000;
  }
  //出力
  printf("%d\n", ans );
  return 0;
}


Measured memory_bytes: 128
/*
 
Coded and Decoded by : Yash Kapoor
 
*/
#include <bits/stdc++.h>
using namespace std;
 
#define ll          long long
#define ld          long double
#define pb          push_back
#define pf          push_front
#define mp          make_pair
#define pll         pair<ll,ll>
#define vl          vector<ll>
#define sl          set<ll> 
#define vll         vector<pll>
#define ml          map<ll,ll>
#define mll         map<pll,ll>
#define all(a)      a.begin(),a.end()
#define x           first
#define y           second
#define sz(x)       (ll)x.size()
#define dl          '\n'
#define why         (ll)1000000007
//#define why         (ll)998244353
#define lp(i,a,b)   for(ll i=a;i<b;++i)
#define lpr(i,a,b)  for(ll i=a;i>=b;i--)
#define lpd(i,x)    for(auto i:x)
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll inf = 1e18;
ld pi = 3.141592653589;
ll mod = why;
ll fast_power(ll base,ll power,ll mod)
{
    ll result=1;
    while(power)
    {
        if(power%2)
        result=(result*base)%mod;
        base=(base*base)%mod;
        power/=2;
    }
    return result;
}
 
ll inverse(ll base,ll mod)
{
    return fast_power(base,mod-2,mod);
}

ll solve(){ 
    ld r; cin>>r;
    cout<<fixed<<setprecision(10)<<(2*pi*r);
    return 0;
}  

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

Measured memory_bytes: 3832
A,B,C=map(int,input().split())
ans=A*B*C

ans=min(ans,abs(A*B*C-2*(A//2)*B*C))
ans=min(ans,abs(A*B*C-2*(B//2)*A*C))
ans=min(ans,abs(A*B*C-2*(C//2)*B*A))
print(ans)

Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
using namespace std;
long long n,len,num,sum=1000,a[100],flag[100];
int main()
{
	ios_base::sync_with_stdio(false),cin.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	len=unique(a+1,a+n+1)-a;
	if(a[1]<a[2]) flag[1]=1;
	if(a[len-1]>a[len-2]) flag[len-1]=2;
	for(int i=2;i<len-1;i++)
		if(a[i]<a[i-1]&&a[i]<a[i+1]) flag[i]=1;
		else if(a[i]>a[i-1]&&a[i]>a[i+1]) flag[i]=2;
	for(int i=1;i<len;i++)
		if(flag[i]==1) num=sum/a[i],sum-=num*a[i];
		else if(flag[i]==2) sum+=num*a[i],num=0;
	cout<<sum<<endl;	
	return 0;
}

Measured memory_bytes: 3592
S=input()
A=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
B=[c for c in S]
C=list(set(A)^set(B))
A=sorted(set(C),key=A.index)
if len(A)==0:
    print("None")
else:
    print(A[0])

Measured memory_bytes: 4016
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int, int >
#define F first
#define S second
#define int long long int
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#define endl '\n'
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=2e3+10;
ll mod;
ll dp[N*3][N];
ll ent(ll k){
    return k*(k-1)/2%mod;
}
int32_t main(){
    sync;
    ll n;
    cin >> n;
    cin >> mod;
    ll a=3*n;
    dp[0][0]=1;
    dp[1][0]=1;
    dp[2][0]=1;
    dp[2][1]=1;
    for (int i=3;i<=a;i++){
        for (int j=0;j<N;j++){
            dp[i][j]+=dp[i-1][j];
            if (j>0){
                dp[i][j]+=dp[i-2][j-1]*(i-1)%mod;
                dp[i][j]%=mod;
                dp[i][j]+=2*dp[i-3][j-1]*ent(i-1)%mod;
                dp[i][j]%=mod;
            }
        }
    }
    ll ans=0;
    for (int i=0;i<=n;i++){
        ans+=dp[a][i];
    }
    cout << ans%mod;
}


Measured memory_bytes: 94464
import java.util.Scanner;

public class Main {
  static int a, b, c;
  static boolean[] check;

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

    a = sc.nextInt(); b = sc.nextInt(); c = sc.nextInt();

    check = new boolean[101];
    check[a] = check[b] = check[c] = true;

    int count = 0;
    for(int i = 1; i <= 100; i++){
      if(check[i]){
        ++count;
      }
    }


    System.out.println(count);
  }
}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)

const char VACANT = 'V';
const char MALE = 'M';
const char FEMALE = 'F';

int ask(int n) {
    cout << n << endl;
    string s;
    cin >> s;
    if (s[0] == VACANT) exit(0);
    if (s[0] == MALE) return 0;
    return 1;
}

int N;

int solve() {
    int edge_left, edge_right;
    edge_left = edge_right = ask(N-1);
    int left = 0, right = N-2;
    while (right - left > 1) {
        int mid = (left + right) / 2;
        int res = ask(mid);
        if (((edge_left^res)) ^ ((mid^left) & 1)) {
            left = mid+1;
            edge_left = res;
        } else {
            right = mid-1;
            edge_right = res;
        }
    }
    ask(left);
    ask(right);
    if (left > 0) ask(left-1);
    ask(right+1);
}

int main() {
    cin >> N;
    cout << solve();
}

Measured memory_bytes: 852
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>

using namespace std;

typedef long long ll;

ll x;

int main() {
	cin >> x;
	if (x >= 30) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;

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

    long X[N],Y[N];

    for(int i = 0;i < N;i++){
        cin >> X[i] >> Y[i];
    }

    int sum = 0;
    for(int i = 0;i < N;i++){
        double L = sqrt(X[i]*X[i] + Y[i]*Y[i]);
        if(L <= D){
            sum++;
        }
    }

    cout << sum << endl;
    
    return 0;
}

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

int n , a[100001] , ans;
multiset <int> ms;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++){
        auto u = ms.lower_bound(a[i]);
        if (u == ms.begin()){
            ms.insert(a[i]);
            ans++;
        }else{
            --u;
            ms.erase(u);
            ms.insert(a[i]);
        }
    }
    cout << ans;
}


Measured memory_bytes: 5376
#include<cstdio>
#include<cstring>
#include<vector>
using std::vector;
const int N=1e5+5;
int n,m;
vector<int> e[N];
int book[N],deg[N];
void dfs1(int x,int pre)
{
	book[x]=book[pre]+1;
	for(int y:e[x])
		if(y==pre)
			continue;
		else if(book[y])
		{
			if(book[y]<book[x])
				deg[y]^=1;
		}
		else
		{
			dfs1(y,x);
			if(deg[y])
				deg[y]^=1;
			else
				deg[x]^=1;
		}
	return;
}
void dfs(int x,int pre)
{
	book[x]=book[pre]+1;
	for(int y:e[x])
		if(y==pre)
			continue;
		else if(book[y])
		{
			if(book[y]<book[x])
				printf("%d %d\n",y,x),deg[y]^=1;
		}
		else
		{
			dfs(y,x);
			if(deg[y])
				printf("%d %d\n",y,x),deg[y]^=1;
			else
				printf("%d %d\n",x,y),deg[x]^=1;
		}
	return;
}
signed main()
{
	int x,y;
	register int i;
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;i++)
	{
		scanf("%d%d",&x,&y);
		e[x].push_back(y);
		e[y].push_back(x);
	}
	dfs1(1,0);
	if(deg[1])
		puts("-1");
	else
		memset(book,0,sizeof(book)),dfs(1,0);
	return 0;
}

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

int main(){

	int a, b, c;
	cin>>a>>b>>c;
	if( a > b) swap(a,b);
	if( b > c) swap(b,c);
	if( a > b) swap(a,b);
	cout<<a<<" "<<b<<" "<<c<<endl;

	return 0;
}


Measured memory_bytes: 3120
def unzip(n, a):
    even_pos = [elem for i, elem in enumerate(a) if i % 2 == 0]
    odd_pos = [elem for i, elem in enumerate(a) if i % 2 == 1]
    if n % 2 == 0:
        return odd_pos[::-1] + even_pos
    else:
        return even_pos[::-1] + odd_pos


if __name__ == '__main__':
    n = int(input())
    a = list(map(int, (input().split())))
    print(' '.join(map(str, unzip(n, a))))

Measured memory_bytes: 28096
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  string s;
  cin >> s;

  int ans = 0;
  if (s[0] == '1') ans++;
  if (s[1] == '1') ans++;
  if (s[2] == '1') ans++;

  // 解答
  cout << ans << endl;

  return 0;
}


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

const int N = 40;
const int MAXAB = 400;
const int INF = 1e9;

int a[N + 1], b[N + 1], c[N + 1];
int dp[N + 1][MAXAB + 1][MAXAB + 1];

int main() {
  int n, A, B;
  cin >> n >> A >> B;
  
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i] >> c[i];
  }
  
  
  for (int k = 0; k <= n; k++)
    for (int i = 0; i <= MAXAB; i++)
      for (int j = 0; j <= MAXAB; j++)
        dp[k][i][j] = INF;
  
  dp[0][0][0] = 0;
  
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= MAXAB; j++) {
      for (int k = 0; k <= MAXAB; k++) {
        if (dp[i][j][k] == INF) continue;
        dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
        if (a[i] +  j <= MAXAB && b[i] + k <= MAXAB) {
          dp[i + 1][j + a[i]][k + b[i]] = min(dp[i + 1][j + a[i]][k + b[i]], dp[i][j][k] + c[i]);
        }
      }
    }
  }
  
  int ans = INF;
  
  for (int i = 1; i <= MAXAB; i++) {
    for (int j = 1; j <= MAXAB; j++) {
      if (A * j == B * i) {
        ans = min(ans, dp[n][i][j]);
      }
    }
  }
  
  cout << (ans == INF ? -1 : ans) << endl;
  return 0;
}


Measured memory_bytes: 29420
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f3f
#define pi 3.1415926535898
using namespace std;
const ll mod=1e9+7;
const ll N=2e6+10;
ll fac[N];
ll invs[N];
ll pows(ll n,ll a)
{
    ll ans=1;
    while(a)
    {
        if(a&1)
        {
            ans=ans*n%mod;
        }
        n=n*n%mod;
        a>>=1;
    }
    return ans;
}
ll inv(int a)
{
    return pows(a,mod-2);
}

ll c(ll n,ll m)
{
    return fac[m]*inv(fac[n])%mod*inv(fac[m-n])%mod;
}
int main()
{
    fac[0]=1;
    for(int i=1;i<N;i++)
    {
        fac[i]=fac[i-1]*i%mod;

    }
    ll k;
    string s;
    cin>>k>>s;
    ll len=s.size();
    ll sum=k+len;
    ll ans=0;
    for(ll i=len;i<=sum;i++)
    {
        ans=(ans+c(i,sum)*pows(25,sum-i)%mod)%mod;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 20948
n = gets.to_i
a = readlines

left = []
right = []

a.each do |e|
  left << e.split[0].to_i
  right << e.split[1].to_i
end


def median(array)
  sa = array.sort
  if sa.size.even?
   (sa[sa.size/2] + sa[sa.size/2 - 1] )/ 2.0
  else
    sa[sa.size/2]
  end
end

if n.even?
  p (((median(right) - median(left)) * 2) + 1).to_i
else
  p median(right) - median(left) + 1
end

Measured memory_bytes: 39776
#include <bits/stdc++.h>
using namespace std;
#define sci1(a) scanf("%d",&a)
#define sci2(a,b) scanf("%d %d",&a,&b)
#define sci3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define scs(s) scanf("%s",s)
#ifndef GET_MACRO

#define GET_MACRO(__1,__2,__3,NAME,...) NAME

#endif // GET_MACRO
#define ll long long
#define sci(...) GET_MACRO(__VA_ARGS__,sci3,sci2,sci1)(__VA_ARGS__)
#define LSB(i) ((i)&(-i))
#define mp(a,b) make_pair(a,b)
#define bit_set0(m,i) (m&(~(1<<i)))

int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int a;
    char s[100];
    scanf("%d",&a);
    scs(s);
    if(a>=3200){
        printf("%s\n",s);
    }
    else{
        printf("red\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	char s[20];
	while(scanf("%s",s)!=EOF)
	{
		int ok=0,flag=0;
		int count=0,ans=0;
		int len=strlen(s);
		if(s[0]!='A'||s[1]=='C'||s[len-1]=='C')cout<<"WA"<<endl;
		else if(s[0]=='A'&&s[1]!='C'&&s[len-1]!='C')
		{
		    s[0]='a';
			for(int i=0;i<len;i++)
	     	{
		        if(s[i]>='A'&&s[i]<='Z')
		        ans++;
		        if(ans>1){ok=1;break;}
				else if(s[i]=='C')
		            count++;
		         
		    }
		    if(count>1||count==0||ok==1)cout<<"WA"<<endl;
		    else if(ok==0&&count==1)cout<<"AC"<<endl;
		} 
		
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
*A, = map(int, input().split())
a, b, c = A.count(1), A.count(2), A.count(3)
DP = [[[0.0 for k in range(n+1)] for j in range(n+1)] for i in range(n+1)]
for k in range(c+1):
    for j in range(b+c-k+1):
        for i in range(n-j-k+1):
            if i+j+k == 0:
                continue
            tmp = n
            if i > 0:
                tmp += DP[i-1][j][k]*i
            if j > 0:
                tmp += DP[i+1][j-1][k]*j
            if k > 0:
                tmp += DP[i][j+1][k-1]*k
            DP[i][j][k] = tmp/(i+j+k)
print(DP[a][b][c])


Measured memory_bytes: 258824
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b)-1);i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))

int main(void){
	int n;
	cin >> n;
	int a[n], sum = 0;
	rep(i, n){
		scanf("%d", &a[i]);
		sum += a[i];
	}
	sum /= n;
	
	int p  = 0, q = 0;
	
	rep(i, n){
		p += (a[i] - sum)*(a[i] - sum);
		q += (a[i] - sum - 1)*(a[i] - sum - 1);
	}
	
	cout << (p > q ? q : p) << endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		int i = 0, sum = 0;
		while ((line = br.readLine()) != null && !line.isEmpty()) {
			i++;
			sum += Integer.parseInt(line);
			if (i == 4) {
				System.out.print(sum / 60 + "\n" + sum % 60 + "\n");
				i = 0;
			}
		}
	}
}

Measured memory_bytes: 16864
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
/*#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")*/

using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
#define mp make_pair
#define what_is(x) cerr << #x << " is " << x << endl;

typedef tree<
        int,
        null_type,
        less<int>,
        rb_tree_tag,
        tree_order_statistics_node_update>
        ordered_set;


const int p = 1e9 + 7;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    s = s%p;
    if (s<0) s+=p;
    return s;
}

int sub(int a, int b) {
    int s = (a-b);
    s = s%p;
    if (s<0) s+=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}

vector<int> Z(vector<int> s)
{
    int n = s.size();
    vector<int> z(n);
    int L = 0, R = 0;
    for (int i = 1; i < n; i++) {
        if (i > R) {
            L = R = i;
            while (R < n && s[R-L] == s[R]) R++;
            z[i] = R-L; R--;
        } else {
            int k = i-L;
            if (z[k] < R-i+1) z[i] = z[k];
            else {
                L = i;
                while (R < n && s[R-L] == s[R]) R++;
                z[i] = R-L; R--;
            }
        }
    }
    return z;
}

mt19937 rnd(time(0));
/*
struct Line {
    mutable ll k, m, p;
    bool operator<(const Line& o) const { return k < o.k; }
    bool operator<(ll x) const { return p < x; }
};

struct CHT : multiset<Line, less<>> {
    // (for doubles, use inf = 1/.0, div(a,b) = a/b)
    const ll inf = LLONG_MAX;
    ll div(ll a, ll b) { // floored division
        return a / b - ((a ^ b) < 0 && a % b); }
    bool isect(iterator x, iterator y) {
        if (y == end()) { x->p = inf; return false; }
        if (x->k == y->k) x->p = x->m > y->m ? inf : -inf;
        else x->p = div(y->m - x->m, x->k - y->k);
        return x->p >= y->p;
    }
    void add(ll k, ll m) {
        auto z = insert({k, m, 0}), y = z++, x = y;
        while (isect(y, z)) z = erase(z);
        if (x != begin() && isect(--x, y)) isect(x, y = erase(y));
        while ((y = x) != begin() && (--x)->p >= y->p)
            isect(x, erase(y));
    }
    ll query(ll x) {
        assert(!empty());
        auto l = *lower_bound(x);
        return l.k * x + l.m;
    }
};
*/


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);

    ll n, k;
    cin>>n>>k;
    ll pairs = k*(k-1)/2;
    pairs%=p;
    vector<int> a(n);
    for (int i = 0; i<n; i++) cin>>a[i];
    int total = 0;
    for (int i = 0; i<n; i++)
        for (int j = i+1; j<n; j++)
        {
            if (a[i]>a[j]) total = add(total, k);
            if (a[i]!=a[j]) total = add(total, pairs);
        }
    cout<<total;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K=sc.nextInt();
		int X=sc.nextInt();
		if(500*K>=X) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 22868
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
#include <string.h>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <stdlib.h>
using namespace std;
typedef long long int lld;
typedef long double ld;
vector<int> v[222];
int dp[222][222],vis[222],ans=-1;
int main(void){
	memset(vis,-1,sizeof(vis));
	int n;
	scanf("%d",&n);
	for(int e=0;e<n;e++){
		string a;
		cin >> a;
		for(int p=0;p<n;p++){
			if(a[p]=='1') {
				dp[e][p] = 1;
				v[e].push_back(p);
			}
		}
	}
	for(int r=0;r<n;r++){
		memset(vis,-1,sizeof(vis));
		queue<int> q;
		q.push(r);
		vis[r] = 1;
		while(!q.empty()){
			int now = q.front();q.pop();
			for(int p=0;p<v[now].size();p++){
				int next = v[now][p];
				if(vis[next]==-1){
					vis[next] = vis[now]+1;
					q.push(next);
				}
			}
		}
		int sn = 0,err=0;
		for(int e=0;e<n;e++){
			if(vis[e]==-1){
				printf("-1");
				return 0;
			}
			sn = max(sn,vis[e]);
			for(int p=e+1;p<n;p++){
				if(dp[e][p]==1){
					if(abs(vis[e]-vis[p])!=1){
						err++;
					}
				}
			}
		}
		if(err) continue;
		ans = max(ans,sn);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
#define PI  acos(-1)
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fi first
#define se second
#define pb push_back
#define re return
#define br break

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;


signed main(){
  int N,L;cin>>N>>L;
  vector<string> array(N);
  REP(i,0,N)cin>>array[i];
  sort(ALL(array),[](auto a,auto b){
    return a<b;
  });
  each(s,array){
    cout<<s;
  }
  cout<<endl;
  

}


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

int n, m, q;
vector<int> a, b, c, d;
int ans;

void dfs(vector<int> A) {
  if (A.size() == n+1) {
    int now = 0;
    rep(i,q) {
      if (A[b[i]] - A[a[i]] == c[i]) now += d[i];
    }
    ans = max(ans, now);
    return;
  }

  A.push_back(A.back());
  while (A.back() <= m) {
    dfs(A);
    A.back()++;
  }
}

int main() {
  cin >> n >> m >> q;
  a = b = c = d = vector<int>(q);
  rep(i,q) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  dfs(vector<int>(1,1));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3544
#include <iostream>
#include<string>
#include<iomanip>


using namespace std;

int main(void) {
	int a, b;
	int k;
	int i;
	int j[101];
	int h = 0;
	
	

	cin >> a >> b >> k;


	for (i = 100; i >= 1; i--) {


		if ((a%i == 0) && (b%i == 0)) {
			h++;
			j[h] = i;
			if (k == h)
				break;
		}
	}

	cout << j[h];

	return 0;
}


Measured memory_bytes: 256
n=int(input())
P=[int(i) for i in input().split()]
nanko=0
for i in range(1,n-1):
    if(P[i-1]>=P[i]>P[i+1] or P[i-1]<P[i]<=P[i+1] or P[i-1]==P[i+1]<P[i]):
        nanko+=1

print(nanko)
        

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

#define N 1000001
int dp[N], dp_o[N];

int main(void) {
  for (int i = 0; i < N; i++) {
    dp[i] = i;
    dp_o[i] = i;
  }
  
  for (int i = 2; i < N; i++) {
    int p = i * (i + 1) * (i + 2) / 6;
    if (p > N) break;
    for (int j = 0; j < N - p; j++)
      dp[j+p] = min(dp[j+p], dp[j] + 1);
    if(p % 2 == 1) {
      for(int j = 0; j < N - p; j++) 
	dp_o[j + p] = min(dp_o[j + p], dp_o[j] + 1);
    }
  }

  int n;
  while(cin >> n, n) {
    cout << dp[n] << " " << dp_o[n] << endl;
  }
  return 0;
}


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

int main() {
    int e, y;
    cin >> e >> y;
    if (e == 0) {
        if (1989 <= y) cout << 'H' << y - 1989 + 1 << endl;
        else if (1926 <= y) cout << 'S' << y - 1926 + 1 << endl;
        else if (1912 <= y) cout << 'T' << y - 1912 + 1 << endl;
        else cout << 'M' << y - 1868 + 1 << endl;
    } else {
        if (e == 1) {
            cout << y + 1868 - 1 << endl;
        } else if (e == 2) {
            cout << y + 1912 - 1 << endl;
        } else if (e == 3) {
            cout << y + 1926 - 1 << endl;
        } else {
            cout << y + 1989 - 1 << endl;
        }
    }
}


Measured memory_bytes: 3104